Jump to content
  • entries
    43
  • comments
    34
  • views
    65,165

Conquering Bankswitching in 7800Basic


frankodragon

1,915 views

If you read my last blog, you know how much I had trouble dealing with bankswitching in 7800 Basic. I couldn't grasp the concept; it takes me a while to figure out something. Before I go any further, let me tell you a story. Way back in grade school, I was a slow learner. In fact, when I first started school, the teachers thought I was stupid. I was put in a slow reading group with two girls. It took me a while, slower than other students, to understand something like reading comprehension or division. Boy, did I have trouble with division. Then later, it suddenly clicked in.

 

The same thing was with algebra. My biggest mistake was that I gave up too soon, figuring if I couldn't understand it, why bother? When I took a class in basic mathematics in college, algrebra was easier to understand. Could it be from how the teacher taught it? Could be. Anyway, 7800 Basic was something I wanted to learn as I enjoy making things, like video games.

 

Now the same thing has happened when working with 7800 Basic. The bankswitching which I had so much trouble with, finally has clicked into my brain. At times, I would blame my brain for not understanding sooner. There were even times I wanted to take out my brain and stomp on it. So this is my guide for anyone who wants to try bankswitching in Atari 7800 Basic but has been scratching their heads in doing so.

 

The first thing to understand about bankswitching is each bank is 16K in size. So if you want a game to be 128K, for example, there will be 8 banks (128*8=16). Now the biggest problem I've had was all the graphics stored, colors, dim values, etc. would be placed in the first bank. This would cause an error: too much in 16K. So the best thing to do is to move most of the graphics (not the plotsprites, but where the graphics are stored) to the last bank. The only graphics you may want to keep in bank 1 are title graphics and maybe the game over graphics. Otherwise, having all the graphics stored (think of a vault) in bank 1 would take up space and there won't be any room for other code. Make sure to leave all your dim values, color codes, romsize, etc. in bank 1.

 

So if you have a 128K game, the majority of your graphics should be stored in bank 8. The game I'm working on is using the engine from Atarius Maximus' Zelda example. What I've learned is to divide areas of the game, such as the overworld, dungeon, cave, etc. into banks. For example, the game starts in the overworld in bank 2. Now how could you start a game in bank 2 instead of the default bank 1? You need to tell 7800 Basic to goto a Label and its bank number in bank 1 if a certain condition, like the fire button pressed, is met:

  (bank1:  7800 already knows this is the first bank and doesn't need to told.)    if joy0fire then  goto __mainloop bank2  bank 2__mainloopIn this example, I'm telling 7800basic to go right to the overworld in bank 2 when the joystick button is pressed.   Keep in mind there is another label called "mainloop" so I labeled this one "__mainloop" to prevent errors.  You can name any label you want just as long as there isn't another label with the same name.  Also helpful is to use "rem -----------------------------------------------------------" to help divide up banks, and even sections within banks, to find them easier.  Just make sure there is a space between "rem" and the hyphens otherwise 7800 Basic will call out an error.Here's an example of what could a game could look like coded in 128K: (bank 1- we don't need  a label since 7800basic already knows it's bank 1)         [dim values]         [color values]__title (Labels must NOT be indented)         [title graphics]              if joy0fire then goto __overworld bank2 else goto _title (notice there's no space between bank and 2.)__skip_title__game_over    [game over graphics]   if joy0fire then goto __title else goto __game_over__skip_game_over       rem -------------------------------------------------------------------------------------------------------------------          bank 2      (notice the space between "bank" and "2"  with indentation.  Also notice the "bank 2" comes BEFORE the label.)__overworld           [coding]                               if boxcollision (herox,heroy,16,16,dungeonx,dungeony,16,16)then gosub __dungeon    bank3    (notice if you want to return to the overworld, you need a gosub and return.)          if boxcollision (herox,heroy,16,16,cavex,cavey,16,16)then gosub __cave bank4       return     [data statements,etc.]       rem ----------------------------------------------------------------------------------------------------------------           bank 3__dungeon        [more coding]         if boxcollision (herox,heroy,16,16,exitx,exity,16,16)then gosub __overworld bank2        return       [data statements,etc]     rem --------------------------------------------------------------------------------------------------------------------     bank 4  __cave         [more coding]         if boxcollision (herox,heroy,16,16,caveexitx,caveexity,16,16)then gosub __overworld bank2        return       [data statements,etc]      rem -----------------------------------------------------------------------------------------------------------------   bank 5   (reserved)   bank 6    (reserved)    bank 7   (reserved)          bank 8 (most of your graphics go into this bank.  Again, think of this as a vault.)     incgraphic gfx/hero.png     incgraphic gfx/titleblanks.png    incgraphic gfx/alphabet_8_wide.png

You may want to use a separate bank for the game over graphics, codes, etc. if you don't have room in bank 1 but usually, there will be. You just need to tell it where to go if your character loses its HP. Let's say if you wanted to go back to the title screen, and if that's located in bank 1, then you'll need to add a label and tell it to go to bank 1:

 

 if joy0fire then goto __title bank1

If you were to do a 256K game, it's the same concept, only you'll be using 16 banks instead of 8.

 

Hopefully, this might help anyone who has been having trouble with bankswitching.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • Like 1

0 Comments


Recommended Comments

There are no comments to display.

Guest
Add a comment...

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