Jump to content

Photo

bank switching issue


15 replies to this topic

#1 easmith OFFLINE  

easmith

    Moonsweeper

  • 270 posts
  • Location:Alexandria, VA

Posted Fri Mar 8, 2019 8:22 PM

i ordered a few carts from AA for the game attached.

 

I am employing f8 bankswitching.    I have always felt a little shaky on this , but  thought I had found a workable scheme online .  I used the same code on a previous game for which the carts function on real hardware just fine.

 

The game works in Stella, and works on Harmony Cart on my 2600 Jr .  When Albert was making  the carts, he said it did not load properly on his  light-sixer 2600, but worked on a 7800.

 

I wonder if anyone could look at stella disassembly and spot any problem with the approach.  I would rather not share source code if possible.??

 

 

 

 

 

 

 

 

 

 

Attached Files



#2 Karl G ONLINE  

Karl G

    Dragonstomper

  • 827 posts

Posted Fri Mar 8, 2019 8:42 PM

If you don't want to share source, then perhaps you could make a simple example that includes your bankswitching code, and not much else?

#3 azure OFFLINE  

azure

    Star Raider

  • 70 posts
  • Busy.
  • Location:Seattle, WA

Posted Fri Mar 8, 2019 8:54 PM

When it starts up in bank 0, I get a black screen. The code zeros out memory and then calls brk. Your brk handler ($10fe - $10ff) is pointing to $1000, which runs your initialization again, so it enters an infinite loop.

 

When the code starts up in bank 1, it seems to work correctly. You have to assume the bank you start in will be random or indeterminate, so if you want your game to always start in bank 1, you need to make bank 0's initialization switch to bank 1.

 

 



#4 SpiceWare OFFLINE  

SpiceWare

    Draconian

  • 12,758 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Fri Mar 8, 2019 8:54 PM

When you're a developer you want to use the Developer settings in Stella. When using that, your game fails to run half the time.
  • hit TAB to bring up the Options menu
  • Click Developer...
  • Select Developer settings
Key thing for your game is the Random startup bank.  If the cartridge starts up in bank 0 your game fails to run. You need to have a startup routine in all banks.  The startup routine in bank 0 should switch to bank 1 and jump to the real startup routine.

Screen Shot 2019-03-08 at 9.02.08 PM.png

#5 SpiceWare OFFLINE  

SpiceWare

    Draconian

  • 12,758 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Fri Mar 8, 2019 9:00 PM

Steps to test startup sequence in a specific bank:
  • Hit ` to enter the debugger
  • type reset in the prompt
  • Select the CartridgeF8 tab
  • Change Set bank to the one you want to test for startup
  • Click Exit
When you do this for bank 0 the game doesn't work. When done for bank 1 it works.

Screen Shot 2019-03-08 at 8.57.23 PM.png

#6 SpiceWare OFFLINE  

SpiceWare

    Draconian

  • 12,758 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Sat Mar 9, 2019 9:34 AM

Forgot to mention that depending upon how the bankswitching was implemented, real hardware could start up in a random bank. Stella by default will start up in bank 1, as seen in CartF8.cxx. I suspect Harmony uses same logic.
void CartridgeF8::reset()
{
  initializeStartBank(1);

  // Upon reset we switch to the reset bank
  bank(startBank());
}
 
There are some exceptions to it starting up in bank 1. If you look at Stella.pro you'll find a few games that override StartBank, such as Private Eye:
"Cartridge.MD5" "bc24440b59092559a1ec26055fd1270e"
"Cartridge.Name" "Private Eye (1984) (Activision) [a]"
"Cartridge.StartBank" "0"
""
 

#7 easmith OFFLINE  

easmith

    Moonsweeper

  • Topic Starter
  • 270 posts
  • Location:Alexandria, VA

Posted Sat Mar 9, 2019 9:35 AM

Ok , I see this now .    I  think it works now . However now there is a new mystery. 

 

I am pretty much doing the same thing in One on One, but now when One On One starts up in bank 0 ,  it appears that none of the ram is being initialized or accessed correctly, so that none of the graphics show and the logic does not register in Ram .   The ram does not change either when players move , etc.

 

Man this 2600 specific stuff is kicking my butt.

 

 

 

 

 

 

 

Attached Files



#8 SpiceWare OFFLINE  

SpiceWare

    Draconian

  • 12,758 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Sat Mar 9, 2019 9:51 AM

About to head out so can't check out your ROMs at the moment. However, this is how I did it in Medieval Mayhem (which is a 32K game using F4 bankswitching):

At F000 for every single bank is this bit of code:
InitSystem
        cmp SelectBank5   ; inits system then goes to the menu
        jmp InitSystemCode
 
In bank 5 is this:
InitSystemCode
        CLEAN_START
 
reset vectors for every bank are:
;       .word InitSystem ; 7 and 8 overlap NMI
        .word InitSystem ; RESET
        .word InitSystem ; IRQ
 

#9 Omegamatrix OFFLINE  

Omegamatrix

    Quadrunner

  • 6,240 posts
  • Location:Canada

Posted Sat Mar 9, 2019 11:26 AM

I didn't look at what you're doing, but consider this:

 

- You will have a certain bank that has your initialization code, whether it be bank 0, bank1, etc...

- Don't count on your game starting in the same bank each time. Instead plan on it starting in a bank that is randomly selected.

- The first thing your game must do is bankswitch to the bank that holds your initialization code. Every bank that does not hold the initialization code must do this.

- Once you have bankswitched to the correct bank you must get to that code.



#10 Mr SQL OFFLINE  

Mr SQL

    River Patroller

  • 2,101 posts

Posted Sat Mar 9, 2019 12:04 PM

i ordered a few carts from AA for the game attached.

 

I am employing f8 bankswitching.    I have always felt a little shaky on this , but  thought I had found a workable scheme online .  I used the same code on a previous game for which the carts function on real hardware just fine.

 

The game works in Stella, and works on Harmony Cart on my 2600 Jr .  When Albert was making  the carts, he said it did not load properly on his  light-sixer 2600, but worked on a 7800.

 

Did you set the decimal flag? Differrent variants of the 6502 will intialize the flag differently and could account for that if the 7800 is consistently running the game.



#11 easmith OFFLINE  

easmith

    Moonsweeper

  • Topic Starter
  • 270 posts
  • Location:Alexandria, VA

Posted Sat Mar 9, 2019 4:40 PM

Yes I had done that . I think  I got it working now. Thanks everyone for the help

Attached Files


Edited by easmith, Sat Mar 9, 2019 10:12 PM.


#12 easmith OFFLINE  

easmith

    Moonsweeper

  • Topic Starter
  • 270 posts
  • Location:Alexandria, VA

Posted Sun Mar 17, 2019 10:11 AM

attempting to extend F8 method to F6 .

 

Here is my outline.  It is not working.   I suspect maybe I need to alter the reset vectors but not sure how

 

 
bank 0  (startup)
 
               processor 6502
     include "vcs.h"
     include "macro.h"
     seg.u Variables
              org $80
 ram definition
           
          seg.code
          org $1000
 
Graphics and PF data
CLEAN_START
Ram Inititalization
Vblank
 Vblank Logic
Kernel
Overscan
 OverScan Logic
     jsr callbank1
     jsr callbank2
     jsr callbank3
 
        org $1FC0
callbank1
       ldx $1FF7                             
      nop                          ; $1FC3  in bank 1
      nop
      nop
      nop
      nop
      nop
     rts
 
      org $1FD0
callbank2
       ldx $1FF8
      nop                                ; $1FD3 in bank 2
     nop
      nop
     nop
     nop
     nop
     rts
 
      org $1FE0
callbank3
       ldx $1FF9
      nop                     ; $1FE3 in bank 3
     nop
      nop
     nop
     nop
     nop
     rts
 
reset
       
 
 
       ORG $1FF6
       JMP CLEAN_START
    .byte 0,0,0,$F6,$FF,0,0
     ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; end bank0
;;;;;;bank1
    org $2000
    rorg $1000
 
bank1logic
     rts
 
     Org $2FC3
     rorg  $1FC3
     jsr bank1logic
      ldx $1FF6    ; return to bank0
 
      ORG $2FF6
       rorg $1FF6
     JMP CLEAN_START
    .byte 0,0,0,$F6,$FF,0,0
 
 
;;;;;;bank 2
    org $3000
    rorg $1000
 
bank2logic
    rts
     Org $3FD3
     rorg  $1FD3
     jsr bank2logic     
     ldx $1FF6              ; return to bank0
 
     ORG $3FF6
     rorg $1FF6
     JMP CLEAN_START
    .byte 0,0,0,$F6,$FF,0,0
 
;;;;;;bank 3
    org $4000
    rorg $1000
 
bank3logic              
          rts
         Org $4FE3
         rorg  $1FE3
         jsr bank3logic
        ldx $1FF6              ; return to bank 0
 
      ORG $4FF6
     rorg $1FF6
     JMP CLEAN_START
    .byte 0,0,0,$F6,$FF,0,0

Edited by easmith, Sun Mar 17, 2019 10:24 AM.


#13 Omegamatrix OFFLINE  

Omegamatrix

    Quadrunner

  • 6,240 posts
  • Location:Canada

Posted Sun Mar 17, 2019 3:31 PM

Don't put code in the hotspots. In this case the hotspots ar $FFF6-$FFF9, so JMP CLEAN_START will trigger an unintentional bankswitch.

 

Also, you can have data before the hotspots ($FFF5) and it can be read and used as normal. However If you had code in $FFF5 then you have to be wary that as soon as the instruction is read the PC has incremented so that would trigger $FFF6. This is non-impacting if you are already in bank 0, but would of course be a bug if you were in other banks. I often just leave a buffer byte before the hotspot or just have data there.

 

Example:

     rts     ; $FFF5    will switch to bank 0 as PC increments to $FFF6 triggering the hotspot
     
     .byte 0 ; $FFF6    bank 0 hotspot
     .byte 0 ; $FFF7    bank 1 hotspot
     .byte 0 ; $FFF8    bank 2 hotspot
     .byte 0 ; $FFF9    bank 3 hotspot


#14 easmith OFFLINE  

easmith

    Moonsweeper

  • Topic Starter
  • 270 posts
  • Location:Alexandria, VA

Posted Sun Mar 17, 2019 4:07 PM

 

Don't put code in the hotspots. In this case the hotspots ar $FFF6-$FFF9, so JMP CLEAN_START will trigger an unintentional bankswitch.

 

Also, you can have data before the hotspots ($FFF5) and it can be read and used as normal. However If you had code in $FFF5 then you have to be wary that as soon as the instruction is read the PC has incremented so that would trigger $FFF6. This is non-impacting if you are already in bank 0, but would of course be a bug if you were in other banks. I often just leave a buffer byte before the hotspot or just have data there.

 

Example:

     rts     ; $FFF5    will switch to bank 0 as PC increments to $FFF6 triggering the hotspot
     
     .byte 0 ; $FFF6    bank 0 hotspot
     .byte 0 ; $FFF7    bank 1 hotspot
     .byte 0 ; $FFF8    bank 2 hotspot
     .byte 0 ; $FFF9    bank 3 hotspot

Thanks . If I change the $fff6 tp $fffc and take away the other .byte 0 etc info  it seems to work . I think I understand now what  the 

 

      ORG $1FF6
   
     JMP CLEAN_START
    .byte 0,0,0,$F6,$FF,0,0
 
    was doing and that there were 0's in the hotspots ( I think) 


#15 easmith OFFLINE  

easmith

    Moonsweeper

  • Topic Starter
  • 270 posts
  • Location:Alexandria, VA

Posted Sun Mar 17, 2019 4:28 PM

I take that back . Now it is only registering as 4K .   Isn't $fffc read upon startup? 



#16 easmith OFFLINE  

easmith

    Moonsweeper

  • Topic Starter
  • 270 posts
  • Location:Alexandria, VA

Posted Sun Mar 17, 2019 4:55 PM

never mind, I think I got it now .......thanks!






0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users