64tass Branch Instructions are Suddenly Short by Two Bytes?!
Posted: Tue Nov 17, 2020 6:27 pm
I'm using 64tass as my assembler. I'm running unexpectedly into a situation where my labeled branches are getting treated as TARGET_OFFSET -2. I could swear I have run into some version of this issue before and got things working. I've checked my notes and forum post history. If it's there, I can't seem to find it.
I've been very slowly reverse engineering a cartridge game. I've successfully build cartridge files up to this point using a Makefile. Things "just work." The cartconv tool provided by VICE isn't quite what I need. So, for now I'm just using a macro that generates a bunch of .byte directives. Maybe it's the purist in me but I want to fully separate concerns between the file type header (required by the C64 emulator) and the underlying code.
Well, this issue has come to the forefront a bit more quickly than I expected.
There is a chunk of code in the game I'm working on that I don't fully understand. I decided the best way to understand the code is to copy it out of the main file, get it to assemble in isolation, and try different combinations of inputs until I think I have it. You know, the tried and true "poke at it with a stick until it gives up its secrets" approach.
Since I'm now building a PRG file instead of a cartridge I need a BASIC loader. No problem, if I build one by hand using .byte directives and build the file I get what I expect. Everything works. Then I thought, "hey, let's experiment with building headers outside of the assembler — this will come in handy later."
I thought it would be easy and take all of 5 minutes consisting of the following steps in a Makefile:
EDIT: Updated subject to include 64tass.
I've been very slowly reverse engineering a cartridge game. I've successfully build cartridge files up to this point using a Makefile. Things "just work." The cartconv tool provided by VICE isn't quite what I need. So, for now I'm just using a macro that generates a bunch of .byte directives. Maybe it's the purist in me but I want to fully separate concerns between the file type header (required by the C64 emulator) and the underlying code.
Well, this issue has come to the forefront a bit more quickly than I expected.
There is a chunk of code in the game I'm working on that I don't fully understand. I decided the best way to understand the code is to copy it out of the main file, get it to assemble in isolation, and try different combinations of inputs until I think I have it. You know, the tried and true "poke at it with a stick until it gives up its secrets" approach.
Since I'm now building a PRG file instead of a cartridge I need a BASIC loader. No problem, if I build one by hand using .byte directives and build the file I get what I expect. Everything works. Then I thought, "hey, let's experiment with building headers outside of the assembler — this will come in handy later."
I thought it would be easy and take all of 5 minutes consisting of the following steps in a Makefile:
- Have petcat tokenize the BASIC loader: the result is a two byte PRG header followed by "10 sys 2062" correctly tokenized.
- Have 64tass process the assembly code. The -b option has been passed to ensure no two-byte header is generated.
- Have cat merge the files with $ cat basic_loader.bin raw_program.bin > program.prg.
- The resulting file should "just work" identically to a file with the load address and tokenized BASIC spelled out in .byte directives.
EDIT: Updated subject to include 64tass.