+SvOlli Posted December 20, 2013 Author Share Posted December 20, 2013 To save space you could use BRK instead of JSR. Also the target address could be stored in the two bytes following the BRK. You just have to slightly adjust the return address then. I now share the code for the JSR/JMP and the RTS. I was pondering around with any other options like BRK, and adding the address after the JSR/BRK, but the code always got to complex and long, and even though not finished I needed to make dozens of call to get the benefit again. Right now the math for "my" bankswitching is: 17 bytes per bank for the JSR/JMP/RTS code (for F4), 7 (+4) bytes per JSR/JMP and 3 (+2) per RTS, A and X registers are destroyed, Y is unchanged. Feels not too bad for a really generic approach. Best of all it blends beautifully in with another part of my code, all demoparts are called like this in 4k: ldx demopartno lda demopartshi,x pha lda demopartslo,x pha rts This can be changed to: ldx demopartno lda demopartshi,x pha lda demopartslo,x jmp bankrtscode-1 Costing just one byte extra. Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted December 21, 2013 Share Posted December 21, 2013 I have had a go at implementing bank switching and this is what I came up with (currently only in F8). I have the following code at the bottom of my banks. MAC F8_BANK_HOTSPOT .setbank SET F8_SET_BANK1 ; switch bank 1 IF F8_BANK_ORIGIN < $F000 .setbank SET F8_SET_BANK2 ; switch bank 2 ENDIF ORG F8_BANK_ORIGIN + $FE7 RORG $FFE7 sta .setbank jmp ({1}) pla tsx dec $01,x dec $01,x sta .setbank rts ENDM I have setup the break vector to point at this routine. I use the following code to perform the bank switch jsr MAC JSR_F8_BANKSWITCH ; address, pointer lda #<{1} sta {2} lda #>{1} sta {2}+1 brk ENDM This seems fairly easy to extend to F6 too i will just need to load x with the appropriate bank index and do a sta $1FF6,x. I could work out x at compilation time too by looking at the target address. Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted December 21, 2013 Share Posted December 21, 2013 Also to return from a bank switch jsr I need to use this MAC F8_RETURN jmp $FFED END Quote Link to comment Share on other sites More sharing options...
+SvOlli Posted December 21, 2013 Author Share Posted December 21, 2013 I was working on something similar as well, but the two "dec $01,x" won't work, if the return address is pushed as $xx00 or $xx01, because decrementing the hibyte on underflow is missing. Catching that corner-case blows up the code, and so I kept sticking with my approach. Quote Link to comment Share on other sites More sharing options...
Mikes360 Posted December 22, 2013 Share Posted December 22, 2013 I think rather than coding around the high byte issue it would be nice to add a compilation check to ensure it won't assemble if the high byte is < 2. MAC JSR_F8_BANKSWITCH IF <. < $02 echo "jsr bankswitch location is ", ., " high byte must be > $01" ERR ENDIF lda #<{1} sta {2} lda #>{1} sta {2}+1 brk ENDM Quote Link to comment Share on other sites More sharing options...
Kylearan Posted January 14, 2014 Share Posted January 14, 2014 For the sake of completeness, while digging around in this forum I found this set of bankswitching macros, by Robert M: http://atariage.com/forums/topic/180561-atari-rapid-programming-modules/ It's not optimal speed- or sizewise, but it's *very* easy to use, provides nice source readability and has some nice compile-time convenience macros for debugging. As long as I won't need to optimize my code for every byte to spare (unlikely when you do bank-switching in the first place), I go with this. Quote Link to comment Share on other sites More sharing options...
+SpiceWare Posted January 14, 2014 Share Posted January 14, 2014 As long as I won't need to optimize my code for every byte to spare (unlikely when you do bank-switching in the first place), I go with this. Not true - I, along with a number of others, spent a lot of time optimizing code for Space Rocks and Stay Frosty 2. I used the freed up space to add new features, levels, music, etc. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted January 14, 2014 Share Posted January 14, 2014 Same here. And if you have a lot of free space, often you find yourself having it at the wrong place. Then you have to optimize too. Quote Link to comment Share on other sites More sharing options...
Kylearan Posted January 14, 2014 Share Posted January 14, 2014 SpiceWare, Thomas - point taken. I didn't want to generalize my statement, and should have phrased that better. In *my* current case, I prefer the ease of use of these macros over size and speed, but I definitely see the need for other cases. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.