It is currently Mon Oct 23, 2017 1:16 am

All times are UTC - 7 hours

Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Thu Jan 19, 2017 3:23 am 
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10067
Location: Rio de Janeiro - Brazil
You got everything right. Indeed, only the .promote macro is relevant to the topic of variable-length parameters, but I wanted to put it into context.

koitsu wrote:
I cannot imagine trying to debug this if something went awry with either an address the linker generated

The good thing is that since the macros are fairly small, straightforward and stored together in a single file, it's really easy to fix any bugs they might have and instantly fix the whole program. That doesn't happen often, though. You can certainly break the macros of you try, but they work very well if used as designed. I could certainly make them more robust and check for every little thing that could go wrong, but that could easily duplicate the size of the macro definitions, and I'm trying to keep things simple.

(it almost looks like a kind of half-ass implementation of a C++ class?)

I envisioned the blocks similar to simple functions in procedural languages (.block is practically a variant of the built-in .proc, but with a configurable entry point), the similarity to OO languages probably comes from separating scopes with "_", but that's mostly artificial. I can pretend FunctionB is inside FunctionA by calling it FunctionA_FunctionB, but there's no real connection. Anyway, I was indeed trying to give ASM more form, and standardize most common programming patterns.

The only case I can work out is .promote being relevant to that subject?

Yeah, sorry if the rest of the code is not relevant, I just wanted to give ".promote" some context.

There is no .block/.endblock in ca65 (that I know of), so these too are macros, but they don't appear to have argument lists

Correct, .block takes the name of the block (which is used to create a reference to it in the global scope, and an optional parameter specifying what's the entry point to that block. In a sense the argument count is variable, since the second argument is optional.

(re: jsr Add_WithoutCarry is not a macro call, it's a subroutine)?

Yeah, that's pure ASM.

Iinstead it looks like {blockname}_{labelname} is the syntax you use...

Yes, to make the hierarchy of the labels clear and avoid collisions.

so is the point that you want to be able to do something like nested blocks, ex. end result of jsr Add_WithoutCarry_OtherBlock_LabelName_Block3_MoreStuff_HowLong_CanThisGet

I don't intend to have nested blocks, I've not had the need for that so far. The longest labels I have so far are of the form Module_Function_Label, such as Video_DrawSprite_Relative.

or does it pertain to .promote specifically? If the latter: I now understand (and sympathise) with your concern/want.

The main purpose of .promote is to allow external code to pass parameters to subroutines, but it's also useful for providing extra entry points in the case of subroutines that perform different tasks, and to provide access to the individual arrays of a structure of arrays, such as this:

   .block HitBoxes


   .byte $10, $12, $08, $10


   .byte $10, $00, $04, $00


   .byte $04, $08, $08, $0f


   .byte $04, $08, $08, $0f

   .promote Top, Bottom, Left, Right


Apologies if my question isn't clear enough. Ask and I can probably reword it.

I'm not sure I understood all the questions, so let me know if I failed to address something.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page Previous  1, 2

All times are UTC - 7 hours

Who is online

Users browsing this forum: No registered users and 7 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group