Jump to content
IGNORED

need to understand BANK SELECT with CVBASIC


Recommended Posts

Hi,

I need to unterstand the concept of BANKs

It is only to stock DATA, or it possible to jump from a bank to another (like GOTO) with several codes and "mini games" with no link between them (except Variables, like score, lifes) ?

Link to comment
Share on other sites

You can put both code and data inside a BANK.

 

The only constraint is that BANK SELECT can only appear in the global bank 0 (the default after you set BANK ROM)

 

There is an example included with CVBasic called bank.bas

 

Link to comment
Share on other sites

13 minutes ago, nanochess said:

You can put both code and data inside a BANK.

 

The only constraint is that BANK SELECT can only appear in the global bank 0 (the default after you set BANK ROM)

 

There is an example included with CVBasic called bank.bas

Alright, but if you put a routine in the bankswitchable area of the cartridge, that routine has to appear in all banks (or at least the banks that can be active when the routine is called) otherwise you'll call garbage data if you call the routine in a bank where the routine is not present. How does your compiler deal with this?  :)

 

Link to comment
Share on other sites

51 minutes ago, Pixelboy said:

Alright, but if you put a routine in the bankswitchable area of the cartridge, that routine has to appear in all banks (or at least the banks that can be active when the routine is called) otherwise you'll call garbage data if you call the routine in a bank where the routine is not present. How does your compiler deal with this?  :)

 

If you need a global routine, you should put it in the global bank.

 

To call a subroutine in another bank you use:

	BANK SELECT 1
	GOSUB routine_in_bank_1

	WHILE 1: WEND

	BANK 1

routine_in_bank_1:	PROCEDURE
	[...code...]
	END

 

Link to comment
Share on other sites

I see... So if I want to have the same routine in multiple banks, I have to copy the routine's code in each bank within the source code.

 

I'm guessing it doesn't matter if the routine isn't in the exact same spot within every bank in the cartridge? Or does your compiler make an effort to place the routine at the same starting address in every bank?

 

Link to comment
Share on other sites

If you need the same routine in multiple banks, it is better to have it in the global bank.

 

If for some reason you want to repeat a subroutine in multiple banks, you would need to have a different name for the subroutine in each bank.

 

The compiler doesn't keep track of the bank of each subroutine.

Link to comment
Share on other sites

Thanks nano, i use BANKS with succes (for now)

But I don't understand some things in your BANK.ROM example

In my mind each BANK is totally independant (except for variables),

 

So why it is possible to play music and display graphics in BANK 0 from informations coming from BANK1 code.

 

Sorry to ask some stupid questions :) I suppose I have not yet unterstood the concept.

Link to comment
Share on other sites

Technically, at any moment, you're working with only two 16K banks. One bank is fixed and is called "Bank 0". The other bank is switchable, if you're using a bankswitchable cartridge configuration. If there's no bankswitching involved, then your cartridge is 32K, and you only have "Bank 1" to work with.

 

Because Bank 0 is fixed, any code or data in Bank 0 is accessible at all times by code in any of the other banks.

 

  • Like 1
Link to comment
Share on other sites

10 hours ago, drfloyd said:

Thanks nano, i use BANKS with succes (for now)

But I don't understand some things in your BANK.ROM example

In my mind each BANK is totally independant (except for variables),

 

So why it is possible to play music and display graphics in BANK 0 from informations coming from BANK1 code.

 

Sorry to ask some stupid questions :) I suppose I have not yet unterstood the concept.

 

@Pixelboy is right.

 

Technically we have two 16K banks sitting together in the 32K cartridge area ($8000-$ffff). The $8000-$bfff area is always BANK 0, while the $c000-$ffff area can be any bank, and that's the cause you can only select banks when you are running at the global bank ($8000-$bfff can change the bank at $c000-$ffff, but you cannot execute at $c000-$ffff and change the bank at $c000-$ffff because it would disrupt execution).

 

Also, there are two tricks inside CVBasic to ease the programmer's life.

 

One, the ON FRAME GOSUB subroutine must be at bank 0, but inside that subroutine, you can switch to any bank. This is because the video interrupt subroutine saves the current bank, and restores it in exit. Totally transparent for the user, and allows you to make for very complex handling on interruption.

 

Two, the PLAY statement saves the bank number of the melody you want to play. This is because the music player is called in the video interrupt subroutine, so the music tracker can play melodies from anywhere the 1MB of ROM. Otherwise, you would be limited to putting melodies in the global bank, and melodies can "eat" a lot of ROM space.

 

  • Like 1
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...