Jump to content
IGNORED

A2600 bankswitching question


vdub_bobby

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...