Jump to content
IGNORED

Atari Bank Switching for Dummies


Thomas Jentzsch

Recommended Posts

So, I've got this overkill bank switching code that looks like this:

image.png.9a1c07d1c9bcb383180fe8c7300cd087.png

I'm using the BRK vector to switch banks.  Since I only have two banks, using the top 3 bits of the address to dynamically switch banks is overkill, so I replaced the indexed write (NOP $1FF8,X) with a static write (NOP $1FF8).  That fixed it in Stella.  If I switch that last one there back it breaks.  I've attached the code.  What's weird is that this all was working no problem until I moved a big chunk of code (the kernel) and corresponding gfx data from bank 1 to bank 2.

TankMaze.asm

Link to comment
Share on other sites

Using 6.6

 

The version I posted above does work, it's if I replace all the NOP $1FF8 and NOP $1FF9 with NOP $1FF8,X it doesn't work.

 

I'll post an updated, non-working version in a sec.

 

EDIT: This will break when it tries to jump to a non-code location, but if you start it in the debugger you can see that is is RORGing both banks to $3000

image.png.fb5f1a96385bd4e1457c5ab5bb572d58.png

and then -

image.png.1a6a2262943ba28ad5ab9221595194eb.png

 

EDIT EDIT: I see I am a version behind (current is 6.7).  I'll download that and give it a try.  

 

EDIT EDIT EDIT: Saw same behavior in Stella 6.7

TankMaze.asm

Edited by vdub_bobby
Link to comment
Share on other sites

There is some weirdness going on. E.g. 

100e		       20 60 11 	      jsr	InitialSetupSubroutine

So clearly a subroutine in $1xxx. However, in Stella I see:

image.png.e4d8eaeb212ca7d28dd460446e07dad2.png

As if the high byte of the address has been changed. And this only happens in Stella, and only after disassembling the code.

 

The problem is, that the disassembler is based on the old DiStella code, which was only meant for 4K. Over the years, I have tried to add better multibank support, but the code base has its limits and has become fragile too. Until 6.4. the code did not do that, since 6.5 it does. 

 

That code is overdue for a major rewrite.

  • Like 2
Link to comment
Share on other sites

After further thinking about this, I think we got irritated by Stella's debugger. 

 

The problem is this: The game starts in bank 1, with PC = $3xxx. First it switches to bank 0 (which skips JMP *+3), PC is still $3xxx. Then it executes no code which could correct the PC to $1xxx (no JMPs) before it hits the first BRK. Which means the return address points to $3xxx. And then the return from bank 1 fails.

 

So if you add a jump before the 1st break (or change the start vector in the 2nd bank), the problem is fixed.

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