BASIC Bank Switching

Publication: SyncWare News
Pub Details: SyncWare News v3 n4 (Volume 3, Issue 4)
Date: Mar-Apr 1986
Pages: 5-6

We have received several letters regarding bank switching on the 2068. SWN 2/3 addresses this prospect from the formal machine code side of the fence, with all of the necessary pushes and calls required to write an independent program. (The only real AROS machine code program is still HOT Z.)

However, you can bootleg around the Exrom code and bank switch from Basic quite easily. Before you bank switch though, you should consider having something to bank switch to. There are a variety of ways to fill extra memory banks on the 2068. The Aerco Disk Interface comes with 64K of RAM located in the dock (cartridge) bank. This is expandable to 256K set up as 4-64K dock banks that are paged in and out by setting the value in an OUT call from machine code to port F4DF and toggling bits 0 and 3.

Another way to add memory (again to the dock bank) would be to convert a 1000 64K rampack (SWN 2/3). You could also add an extra chip to your 2068 and put 56K additional ram in the Exrom Bank (SWN 2/3). With some modifications you can add static ram to a cartridge board, but it will only function as dynamic (it goes away even if you flick off the power) ram due to some quirks in the 2068 hardware.

The last way to add memory to your computer is non-volatile ram. This board is available from several distributors now. This board can run AROS programs from the Exrom bank as well as the dock bank and won’t go away if you crash (even in the write mode).

Anyway, now that there are so many ways to add memory, let’s discuss the basics of bank switching. There are two ports that you need to remember. These are 244 and 255. Port 255 handles various aspects of the operating system, such as, 32/64 column video and dock/Exrom enable. You must take care when toggling this port. Port 244 handles which part of memory that you would like to have in different banks.

The top bit of port 255 is our Ex/dock toggle. This is 80h or 128d. This means that any number greater than 127 (to 255) will mean that if you do any bank switching, it will all be in the Exrom bank. Numbers less than 128 means that any bank switching will be done in the dock bank. Two convenient values to use here are 0 for dock and 128 for Exrom banks. To use these numbers in Basic, just use the out command:

OUT 255,0              ;ENABLE DOCK BANK
OUT 255,128 ;ENABLE EXROM BANK

The default on power up is having the dock enabled. The computer will automatically run properly coded AROS and LROS programs. However, if you are running a 64 column operating system and you wish to change banks, then you must becareful not to upset the video control flags. In this case you should PRINT IN 255. If this number is less than 128 the dock is enabled, equal or greater means the Exrom bank is enabled. Toggle between banks like this:

LET X=IN 255
OUT 255,X+128

If you are running LROS software, such as OS64 or a Spectrum emulator other than a Romswitch, you must take care to not use basic to bank switch, because when you change banks, you disable your LROS program and enable the Exrom itself and goodby!

Unfortunately, you can access only two banks at a time (don’t forget the HOME bank–the one that your ram occupies). You cannot have Exrom and dock banks enabled at the same time.

So far, we have just changed the bank that we can enable. We have not actually enabled anything other than our home ram yet. The port that does the turning on of the extra ram is the other port (244). This port is arranged such that each of the 8 bits in the byte turn on a different 8K byte CHUNK. Since there is a BIN function on the 2068, you don’t have to remember all of the bits and nibbles etc., just use BIN to send your bits out.

The BIN function translates the numbers you type in such that the first number sets the highest RAM section. The next number sets the next lower 8K chunk, and so on. For example, OUT 244, BIN 11110000 would turn on the four highest chunks in another bank and leave the four bottom chunks in home RAM (and ROM). Remember to type in all 8 ones and zeros when using BIN or you may not set all 8 chunks properly. You can type in less than 8 digits though. Here are some key numbers that you want to remember:

OUT 244,BIN 11 (00000011)     SPECTRUM ROM
OUT 244,BIN 10000             AROS BOOT (32 TO 40K)
OUT 244,BIN 110000            AROS BOOT (32 TO 48K)
OUT 244,BIN 1110000           AROS BOOT (32 TO 56K)
OUT 244,BIN 11110000          AROS BOOT (32 TO 64K)
OUT 244,BIN 11110011          AROS AND SPECTRUM

You can print those BIN numbers to see them in decimal. We have now enabled all kinds of banks and RAM and not even used one hex number conversion! Practically painless, isn’t it?

When you turn on your computer and have an emulator (other the a straight Spectrum Rom) or Aros cartridge plugged in, it autostarts. However, if you have the 32K Non Volatile Ram, Aros programs in the Exrom bank will not auto start. To enable them, just OUT 244,BIN 11110000 (or 240d); OUT 255,128 and RAND USR 32776. Presto! Aros from the Exrom bank.

You should always set your chunks in port 244 before you change banks in port 255. For example, if you have the Aerco Disk interface or emulator, chunk 0 (0 to 8K) is already on in port 244. OUT 255,128 will turn on the Exrom (and turn off your Basic operating system). One problem with crashing in other banks is that there is no cold boot to get you back to basic! Your reset switch will not help you recover. You must pull the plug. This is still another reason to have non volatile ram in your machine.

It is also possible to write, run and EDIT Basic programs that are 100% AROS! The only stipulation is that you must be able to turn off your computer and turn it on without losing your memory contents. Get used to bank switching: It’s here to stay! We will discuss bank switching more in the next issue. Have fun!