How do you define multiple banks in CA65?
I was thinking of splitting each bank into it's own .asm file, and then compiling them individually with a batch file. After that I was going to "glue" them together with a big "copy /b header.bin+file1.bin+file2.bin+file3.bin".
(I've done 6502 assembly before, but never across multiple source code files. I've always kept the code in one file, and then included things like constants and register addresses from another file)
However, I have discovered that that this was not going to work out. I can't seem to keep tack of everything between all the banks.
On the last bank, for example, I hard-coded a .org at $C000 and then hard-coded the vectors at the bottom. So far so good. However, I didn't know how to call other functions outside that bank without hard-coding their locations. I thought I can use the "Final Fantasy 1" way by making a jump table at the top of each bank with a list of known functions at the top, but there really wasn't a way to do this elegantly, for example, I would like to switch a bank and then call a subroutine without needing to jump to a table first. I want the compiler to "fill in" the addresses so I didn't have to keep track of them in a jump table.
I then found out that the linker can keep track of everything with symbols, and even "glue" all my banks together too. I experimented with ".segment" commands and that ended in failure. Then I found This post (ca65_duped_bank_data.zip) that seemed to solve it, but I'm so lost with the code I don't understand what it's doing. I don't see any bank switching code in there at all, or any vectors, or anything. The command "macros" seem to just share the zero page, I don't see how you can share things like work ram. Can someone break it down for me, or offer a better solution so I can just make everything compile and "glue together" in one pass and the last bank is made "aware" of the locations of the subroutines in all the banks? Also, make all the banks "aware" of the variables in WRAM?
I was thinking of splitting each bank into it's own .asm file, and then compiling them individually with a batch file. After that I was going to "glue" them together with a big "copy /b header.bin+file1.bin+file2.bin+file3.bin".
(I've done 6502 assembly before, but never across multiple source code files. I've always kept the code in one file, and then included things like constants and register addresses from another file)
However, I have discovered that that this was not going to work out. I can't seem to keep tack of everything between all the banks.
On the last bank, for example, I hard-coded a .org at $C000 and then hard-coded the vectors at the bottom. So far so good. However, I didn't know how to call other functions outside that bank without hard-coding their locations. I thought I can use the "Final Fantasy 1" way by making a jump table at the top of each bank with a list of known functions at the top, but there really wasn't a way to do this elegantly, for example, I would like to switch a bank and then call a subroutine without needing to jump to a table first. I want the compiler to "fill in" the addresses so I didn't have to keep track of them in a jump table.
I then found out that the linker can keep track of everything with symbols, and even "glue" all my banks together too. I experimented with ".segment" commands and that ended in failure. Then I found This post (ca65_duped_bank_data.zip) that seemed to solve it, but I'm so lost with the code I don't understand what it's doing. I don't see any bank switching code in there at all, or any vectors, or anything. The command "macros" seem to just share the zero page, I don't see how you can share things like work ram. Can someone break it down for me, or offer a better solution so I can just make everything compile and "glue together" in one pass and the last bank is made "aware" of the locations of the subroutines in all the banks? Also, make all the banks "aware" of the variables in WRAM?