Videopac / Odyssey2 forum

Programming the Videopac / Odyssey2 => Programming => Topic started by: Chris! on January 02, 2021, 02:44:17 AM



Title: Banks in a 4k game
Post by: Chris! on January 02, 2021, 02:44:17 AM
I was having trouble with programming a 4k game. As it turned out, I was jumping to the wrong bank. I know that it starts at bank 3 on reset, so why would I need to jump to bank 2 in a 4k game? What are banks 1 and 0 then? How big is a bank?


Title: Re: Banks in a 4k game
Post by: TedFoolery on January 03, 2021, 03:52:02 PM
"Bank" can refer to two things, which may be part of your confusion.

A standard game ROM can be 2k, 4k or 8k (1 bank, 2 banks, 4 banks). That makes each bank 2k. When coding, however, each 2k bank is divided into 2 halves (also called banks). When jumping or calling into the low bank, preface the call with a sel mb0, and for the high bank use sel mb1.

Yes, all games start in bank 3. You can use any, all, or none of the other banks to do whatever you wish. It's just more programming space. Switching between banks can be tricky. There are built-in routines to do this, but they always put you at 'start'.

It is possible to create 3k, 6k, or 12k games. The extra 1k in each bank can be used for solely for data storage, which can be retrieved with a mov3p a,@a command. These games, however, do not work with the Voice.



Title: Re: Banks in a 4k game
Post by: Chris! on January 03, 2021, 04:38:43 PM
Switching between banks can be tricky. There are built-in routines to do this, but they always put you at 'start'.
Thanks for the reply, Ted. This answers another question I had, about switching between each 2k bank. So I guess it's not possible to, say, jump to the middle of bank 3 when you're in bank 2. I thought of a solution though when I'm programming my Xybort game. I put in a variable and then check it to see if it's 1 at 'start' and if so, don't start it at the beginning. And the only way I plan to make it be 1 is if it goes to the other 2k bank.


Title: Re: Banks in a 4k game
Post by: TedFoolery on January 04, 2021, 03:33:34 AM
You certainly can change banks in the middle of code, you just need to align the jumps precisely because the program counter (the address of the code) needs to be taken into account.

Example below. It starts in bank3, does some commands, jumps to bank0, does more commands, then jumps back to bank3:

bank 3 code:
Code:
;just some code
    org #0500h

    mov a,r1
    mov r2,a
jumptobank0:
    anl p1,#0fch  ;this code is at #0502h and takes 2 bytes, so the next instruction read will be at #504h in bank0
;this is #0504h and continues from bank3

    mov a,r3  ;this is at #0504h and takes place when returned from bank0
    mov r4,a

bank 0 code:
Code:
    org #0500h

    nop
    nop
jumpbacktobank3
    orl p1,#03h  ;this code is at #0502h and takes 2 bytes, so the next instruction read will be at #504h in bank3

;this is #0504h and continues from bank3
    cpl a
    mov r3,a
    jmp jumpbacktobank3