vdub_bobby Posted March 17, 2005 Share Posted March 17, 2005 8K ROM. Can I do this? This first code snip is in bank 2 of an 8K ROM: RORG $F000 StartBank2 ldx #$FF txs lda #>StartBank1-1 pha lda #<StartBank1-1 pha jmp SwitchToBank1Subroutine ;----- rorg $FFF0 SwitchToBank1Subroutine sta $1FF8 Then in bank 1 I've got this: rorg $FFF0 sta $1FF9 rts Where StartBank1 = $F000. Does that make sense? In other words, can I push $EFFF onto the stack and then rts to $F000? It works in z26, but I'm not sure if z26 starts in a random bank. Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted March 17, 2005 Share Posted March 17, 2005 Hi there! In Star Fire I solved the "random starting bank" thing like this: Bank 1: FirstInit BIT $1FF9 NOP ; dummy .word $FFFF, $FFFF ; bank-switching hotspots .word FirstInit .word FirstInit .word FirstInit Bank 2: BRK ; coming from the other bank .word $FFFF, $FFFF ; bank-switching hotspots .word start .word start .word start Essentially the "BRK" alone does everything for me what your code does, ie. loading the "start" pointer and jumping to it Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted March 17, 2005 Author Share Posted March 17, 2005 Essentially the "BRK" alone does everything for me what your code does, ie. loading the "start" pointer and jumping to it Thanks...pretty slick! Quote Link to comment Share on other sites More sharing options...
+batari Posted March 17, 2005 Share Posted March 17, 2005 I think this would work too, but it's not been tested. bank 0 and 1: ORG $FFF8 BRK BRK .word start .word $FFF8 .word start When you power up, both banks will jump to the BRK at FFF8, and a BRK does a dummy fetch of FFF9, switching to bank 1, then loading the start vector and jumping to .start in bank 1. whatever is at .start in bank 0 doesn't matter, so you can put whatever code there that you want.[/code] Quote Link to comment Share on other sites More sharing options...
Tom Posted March 17, 2005 Share Posted March 17, 2005 Afaik z26 doesn't start in random banks. Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted March 17, 2005 Share Posted March 17, 2005 Afaik z26 doesn't start in random banks. There should be a switch for us developers (start in bank x or start at random bank). Quote Link to comment Share on other sites More sharing options...
Tom Posted March 17, 2005 Share Posted March 17, 2005 With the bankswitching experiments I had done in the past I simply reorganized the different bank images in the rom itself for testing purposes, but this is awkward. And you always have to remember wether z26 starts in the first or the last bank. A start in bank x switch would be very useful (so you can test wether your rom starts correctly from every bank), but i don't think there's much use for a random switch. Well, probably this isn't going to be implemented anytime soon unless somebody who really wants it implements it himself Quote Link to comment Share on other sites More sharing options...
Thomas Jentzsch Posted March 17, 2005 Share Posted March 17, 2005 ... but i don't think there's much use for a random switch. Sure it is useful (as a default). Because then sooner or later you automatically would notice a mistake there. And then you can start debugging and test starting at selected banks. Quote Link to comment Share on other sites More sharing options...
Tom Posted March 17, 2005 Share Posted March 17, 2005 Question of taste Personally I'd prefer testing all banks extensively, before I even suspect there's an error (or the other way around, I assume I did a mistake). I wouldn't want to wait until the random number generator picks by chance the faulty bank. The sooner you can find and fix a bug, the less trouble it causes you. Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted March 17, 2005 Share Posted March 17, 2005 Hi there! Just had a thought about the BRK technique: Is it using the stack? If so, what'd happen if the stack pointer was pointing to $01 on powerup? Or, here on the VCS, if it was pointing into the non-RAM area? Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
DEBRO Posted March 17, 2005 Share Posted March 17, 2005 Is it using the stack? If so, what'd happen if the stack pointer was pointing to $01 on powerup? Would it matter? The RAM state of the VCS is unknown at startup so some registers could already be set. Generally at startup you'd clear out all RAM anyway. Or, here on the VCS, if it was pointing into the non-RAM area? Unless I'm missing something this isn't possible. The stack has full range of ZP, right? Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted March 17, 2005 Share Posted March 17, 2005 Hi there! Is it using the stack? If so, what'd happen if the stack pointer was pointing to $01 on powerup? Would it matter? The RAM state of the VCS is unknown at startup so some registers could already be set. Generally at startup you'd clear out all RAM anyway. Sure, but the BRK to switch to the starting bank would happen _before_ any startup code. Or, here on the VCS, if it was pointing into the non-RAM area? Unless I'm missing something this isn't possible. The stack has full range of ZP, right? Uhm... what isn't possible? You certainly can set the stack pointer to something Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
DEBRO Posted March 17, 2005 Share Posted March 17, 2005 Sure, but the BRK to switch to the starting bank would happen _before_ any startup code. Maybe I still don't get what you're saying. My question is if the RAM is in an known state on the VCS at startup, what difference does it make if BRK alters a register? We're not checking the BRK flag are we? The BRK would push the return address on the stack and jump to the BRK register which would do your start up routine (clearing RAM and reseting the stack). What harm could BRK altering RAM cause here? Uhm... what isn't possible? You certainly can set the stack pointer to something < $80, so the question was "What will happen if that is the case on powerup and you start your code execution with a BRK?" Again, maybe I'm missing it, here. The stack has full range of ZP. Sure the pointer could be less the $80 which would point to the TIA. I still don't see the problem of altering a TIA register at start up when the start up code would clear them out anyway (assuming you do a RAM clear in startup). Now I don't know what values $2D - $3F map to so maybe that could be a problem but $40 - $6C are TIA mirrors. Quote Link to comment Share on other sites More sharing options...
Cybergoth Posted March 17, 2005 Share Posted March 17, 2005 Hi there! Hm... Ok, I read some docs and see my mistake now. I thought BRK would jump to the BRK adress via the stack, but instead it gets moved straight to the program counter. Ok, then the startup value of the stack pointer or the RAM content don't matter at all. Fine! Greetings, Manuel Quote Link to comment Share on other sites More sharing options...
DEBRO Posted March 17, 2005 Share Posted March 17, 2005 Would do this affect the bankswitching routine mentioned here since BRK is at $FFF8 and $FFF9? Quote Link to comment Share on other sites More sharing options...
+batari Posted March 18, 2005 Share Posted March 18, 2005 Yes, I hadn't thought of that. Maybe a solution if you want to support both the RTS trick and the BRK startup trick would be to move the BRK up to $FFF9: bank 0 and 1: ORG $FFF7 RTS RTS BRK .word start .word $FFF9 .word start If we go to the BRK at $FFF9, accessing this byte will switch right away, at least in theory, and the dummy fetch will access $FFFA and do nothing, but we'd already be in bank 2 by then. Actually, if you wanted to leave the BRK open for other uses, like a subroutine trick or something you could also do this: bank 0 and 1: ORG $FFF7 RTS RTS .byte $4C .word start .word mysubroutine .word start The 4C is the opcode for JMP, so fetching the opcode should switch, then JMP .start in bank 1... Quote Link to comment Share on other sites More sharing options...
+batari Posted March 18, 2005 Share Posted March 18, 2005 Oops, my mistake, that should be: bank 0 and 1: ORG $FFF7 RTS RTS .byte $4C .word start .word $FFF9 .word mysubroutine Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted March 18, 2005 Author Share Posted March 18, 2005 This is all very interesting But does anybody know if, indeed, pushing $EFFF onto the stack and then 'rts'ing will work fine? I don't see why it shouldn't, I guess, but I just want to be sure. Quote Link to comment Share on other sites More sharing options...
+batari Posted March 18, 2005 Share Posted March 18, 2005 I would say yes, because an RTS pulls the low and high byte of the return address from the stack and writes them into the program counter register, then increments the PC. As I understand, there are no page boundary issues with incrementing the PC. Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted March 18, 2005 Author Share Posted March 18, 2005 Thanks 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.