I've encountered a problem a second time around now where I believe I've run into a bug in ca65. I have a macro with 13 parameters. In some situations, CA65 will say "unexpected trailing garbage characters." In another situation, it will not.
This does NOT say "unexpected trailing garbage characters"
This DOES say "unexpected trailing garbage characters"
Here is the macro definition itself:
All I've done is replace three parameters, sfx_door, 3, and soundeffect_one (an address, a constant, and an equate), with 0, 0, 0 (three constants). I can juggle the results (whether I get the error) by using \ with .linecont + and other things which don't actually affect the parameter list itself.
The nonsense earlier where I surround a bunch of OR'ed equates with { } was what I thought, previously, to be a workaround for the same problem.
I'm going down the path of building Ca65 to try to learn what the heck is going on, but now I'm running into that whole kerfuffle with what to do with truncating negative values listed after .byte or .word. I thought I saw a thread here discussing said kerfuffle, but I couldn't find it just now. (I had been using a much older build of ca65 without that problem). I'm considering updating my whole codebase to just work with that change, and see if this bug I've run into was fixed in the interim.
I could of course come up with a workaround, or write my own preprocessor to just spit out my locations into binary files instead of these huge macro definitions, but, I'd like to be able to rely on the assembler to assemble code that appears to be correct, even if my usage of it is quirky.
This does NOT say "unexpected trailing garbage characters"
Code:
define_location {(LOCATION_FLAGS_CAMERA_X_SCROLLING_DISABLED_SET | LOCATION_FLAGS_CAMERA_Y_SCROLLING_DISABLED_SET | LOCATION_BRIGHTNESS_LEVEL_4)}, area_index_dungeon, dungeon_entity_set, dungeon_0_0_entity_instances, dungeon_palette, 0, 0, 11, 5, sfx_door, 3, soundeffect_one, HERO_DIRECTION_UP
This DOES say "unexpected trailing garbage characters"
Code:
define_location {(LOCATION_FLAGS_CAMERA_X_SCROLLING_DISABLED_SET | LOCATION_FLAGS_CAMERA_Y_SCROLLING_DISABLED_SET | LOCATION_BRIGHTNESS_LEVEL_4)}, area_index_dungeon, dungeon_entity_set, dungeon_0_0_entity_instances, dungeon_palette, 0, 0, 11, 5, 0, 0, 0, HERO_DIRECTION_UP
Here is the macro definition itself:
Code:
.macro define_location flags, area_index, entity_set_address, entity_instances_address, palette_address, camera_start_x, camera_start_y, hero_start_x, hero_start_y, sfx_address, sfx_channel, sfx_stream, hero_direction
.byte flags ;flags .byte
.byte area_index ;area_index .byte
.word entity_set_address ;entity_set_address .word
.word entity_instances_address ;entity_instances_address .word
.word palette_address ;palette_address .word
.byte $20 | ((>(16*camera_start_x) & 1) << 2) ;nametable_start_hibyte .byte
.word (16*camera_start_x) ;camera_start_x .word
.word (16*camera_start_y) ;camera_start_y .word
.byte <(16*camera_start_x) ;camera_start_scroll_x .byte
.byte (224 + (16*camera_start_y)) .MOD 240 ;camera_start_scroll_y .byte
.word (hero_start_x*16) ;hero_start_x .word
.word (hero_start_y*16) ;hero_start_y .word
.word sfx_address ;on_enter_sfx_address .word
.byte sfx_channel ;on_enter_sfx_channel .byte
.byte sfx_stream ;on_enter_sfx_stream .byte
.byte hero_direction ;hero_direction .byte
.endmacro
.byte flags ;flags .byte
.byte area_index ;area_index .byte
.word entity_set_address ;entity_set_address .word
.word entity_instances_address ;entity_instances_address .word
.word palette_address ;palette_address .word
.byte $20 | ((>(16*camera_start_x) & 1) << 2) ;nametable_start_hibyte .byte
.word (16*camera_start_x) ;camera_start_x .word
.word (16*camera_start_y) ;camera_start_y .word
.byte <(16*camera_start_x) ;camera_start_scroll_x .byte
.byte (224 + (16*camera_start_y)) .MOD 240 ;camera_start_scroll_y .byte
.word (hero_start_x*16) ;hero_start_x .word
.word (hero_start_y*16) ;hero_start_y .word
.word sfx_address ;on_enter_sfx_address .word
.byte sfx_channel ;on_enter_sfx_channel .byte
.byte sfx_stream ;on_enter_sfx_stream .byte
.byte hero_direction ;hero_direction .byte
.endmacro
All I've done is replace three parameters, sfx_door, 3, and soundeffect_one (an address, a constant, and an equate), with 0, 0, 0 (three constants). I can juggle the results (whether I get the error) by using \ with .linecont + and other things which don't actually affect the parameter list itself.
The nonsense earlier where I surround a bunch of OR'ed equates with { } was what I thought, previously, to be a workaround for the same problem.
I'm going down the path of building Ca65 to try to learn what the heck is going on, but now I'm running into that whole kerfuffle with what to do with truncating negative values listed after .byte or .word. I thought I saw a thread here discussing said kerfuffle, but I couldn't find it just now. (I had been using a much older build of ca65 without that problem). I'm considering updating my whole codebase to just work with that change, and see if this bug I've run into was fixed in the interim.
I could of course come up with a workaround, or write my own preprocessor to just spit out my locations into binary files instead of these huge macro definitions, but, I'd like to be able to rely on the assembler to assemble code that appears to be correct, even if my usage of it is quirky.