drfloyd Posted May 10 Share Posted May 10 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) ? Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/ Share on other sites More sharing options...
+nanochess Posted May 10 Share Posted May 10 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 Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/#findComment-5463973 Share on other sites More sharing options...
Pixelboy Posted May 10 Share Posted May 10 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? Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/#findComment-5463985 Share on other sites More sharing options...
+nanochess Posted May 10 Share Posted May 10 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 Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/#findComment-5464016 Share on other sites More sharing options...
Pixelboy Posted May 10 Share Posted May 10 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? Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/#findComment-5464080 Share on other sites More sharing options...
+nanochess Posted May 10 Share Posted May 10 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. Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/#findComment-5464090 Share on other sites More sharing options...
Pixelboy Posted May 10 Share Posted May 10 Good to know. Thanks. Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/#findComment-5464117 Share on other sites More sharing options...
drfloyd Posted May 11 Author Share Posted May 11 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. Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/#findComment-5464385 Share on other sites More sharing options...
Pixelboy Posted May 11 Share Posted May 11 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. 1 Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/#findComment-5464463 Share on other sites More sharing options...
+nanochess Posted May 11 Share Posted May 11 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. 1 Quote Link to comment https://forums.atariage.com/topic/366243-need-to-understand-bank-select-with-cvbasic/#findComment-5464597 Share on other sites More sharing options...
Recommended Posts
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.