Practical 2068 Bank-Switching

Authors

Publication

Pub Details

Date

Pages

BASIC Terms

Although some bank-switching applications might encompass seemingly insurmountable programming obstacles…there are many others that can be accomplished with ease! I’d like to present three bank-switching examples/applications that can be adapted and expanded on for a wide variety of uses.

Bank Switching Theory — From a Layman’s Perspective

What is bank switching? In very simple terms, it is a way to direct the computer to switch between different “banks” of memory circuits. This is accomplished in a program with the OUT 244,VALUE command, where VALUE defines which memory “banks” are being used. Although the computer can only talk to 64K of memory (8 banks of 8K each) at any given time, BANK-SWITCHING can switch in/out different banks of memory…and make it appear like more memory. One little detail that makes this all possible, is that when you swtich out one memory bank for another, the memory in that bank remains just the way you left it…so when you return to it, you can continue on just as before!

Another important detail is that we will only be working with memory above location 32768. By doing this, we will not interfere with the computer operating system and greatly simplify our work. This means that we will only have an additional 32K of RAM to work with, but that almost doubles the memory capacity we are currently working with after subtracting that used by the operating system!

Memory is “bank-switched” in 8K chunks using the OUT 244,VALUE command. VALUE determines which chunks are being used. The following table defines VALUE and the “DOCK” memory addresses that are used.

ValueDock Memory Addressed
10 – 8191
28192 – 16383
416384 – 24575
824576 – 32767
1632768 – 40959
3240960 – 49151
6449152 – 57343
12857344 – 65535

Now, by adding various values, one can activate multiple banks of dock memory (i.e., VALUE = 64+128 = 192 operates on addresses 49152 — 65535). To reset all banks to the standard memory, use VALUE = 0. NOTE: We will only be activating chunks with addresses above 32768 (VALUE = 16 and above). AERCO FD-68 Users: The AERCO disk system requires that chunk 1 be active to utilize the disk, therefore, add 1 to your VALUE to keep the disk active.

Bank-Switching RAM (where to get it)

Add-on bank switchable RAM can be obtained from a variety of sources. The AERCO disk interface comes with 64K of additional bank-switchable RAM built right in. Another source is RAM cartridges that plug into the 2068 cartridge dock such as the one designed by Tom Bent (Quantum Levels), and once marketed by Thomas B. Woods, or the one available from Lem Software (see the ad on the back cover of this magazine for a 32K RAM cartridge). Other sources of RAM are available, like the new RAMdisk from LARKEN, and there are probably others that I am not aware of.

What Can We Do With It?

OK, what can we do with this add-on memory? What is the #1 complaint about 64K computers? They have so little memory to work with! There is always more data than memory to hold it! The #1 use for more memory will be to store more data. So, my first example is a short data transfer program.

XFER_1 (Listing A)

XFER_1 is a ZEUS assembler source listing, ready to be assembled. LINE 270 is set to assemble this routine starting at 39000 (RANDOMIZE USR 39000). Following the source file is a dis-assembly of the routine identifying the memory address, the value at that address, and the assembler instruction associated with that address. I would like to thank AL SCHREMMER, an active member of the Kansas Area TS User Group for writing this very helpful and unique dis-assembler!

XFER_1 is a simple program that will transfer (COPY) data from one bank to another bank. As written, 24064 bytes of data are copied from standard memory starting at address 41300 to the dock bank, also starting at address 41300. The “source” bank is the source of the data to be copied…and could be the dock bank. The “destination” bank is where you are copying data to, and could be regular memory (with a little modification). Also, this example copies data to the same address in the dock bank, but you can see that this also can be changed easily.

The way it works is this: after assigning the destination and source addresses, and the number of bytes to be copied (LINES 290 to 310), the source bank is activated (LINES 430 and 440) and 1 byte is copied into the accumulator and saved by pushing it onto the stack (LINES 450 and 460). Then the destination bank is activated (LINES 570 and 580) and the saved byte is recalled and stored at it’s destination address (LINES 590 and 600). The destination and source addresses are incremented (LINES 670 and 680) while the number of bytes that are to be copied is decremented (LINE 690). The number of bytes remaining is checked to see if it is zero (LINES 700 and 720), and if not, the process is repeated. When complete, the source bank is activated (LINES 730 and 740), and the program ends with a RETURN.

Listing A — XFER_1 source

00010 ;         XFER_1
00020 ;-----------------------
00030 ; PRACTICAL
00040 ; BANK-SWITCHING
00050 ;
00060 ; ++++++++++++++++++++
00070 ; + THIS SAMPLE PROG. +
00080 ; + WILL COPY 24064 +
00090 ; + BYTES FROM MEMORY +
00100 ; + ADDRESS 41300 OF +
00110 ; + STD. RAM TO 41300 +
00120 ; + OF THE DOCK BANK. +
00130 ; ++++++++++++++++++++
00140 ;
00150 ; (c) S D LEMKE 1988
00160 ;
00170 ; LEMKE SOFTWARE DEVELOP.
00180 ; 2144 WHITE OAK
00190 ; WICHITA, KS. 67207
00200 ;-----------------------
00210 ;-----------------------
00220 ;
00230 ; GETTING STARTED...
00240 ; SET SOURCE, DEST, AND
00250 ; NUMBER OF BYTES
00260 ;
00270 ORG 39000 ; CODE ADD.
00280 ;
00290 LD HL,41300 ; DEST. ADD.
00300 LD DE,41300 ; SOURCE ADD.
00310 LD BC,24064 ; LENGTH
00320 ;
00330 ;-----------------------
00340 ;
00350 ; BEGIN BY ENABLING THE
00360 ; SOURCE BANK AND SAVING
00370 ; THE SOURCE BYTE
00380 ;
00390 ; SOURCE BANK = 1 (AERCO)
00400 ; SOURCE BANK = 0 (OTHER)
00410 ;
00420 ;
00430 XFER1 LD A,1 ; SOURCE BNK
00440 OUT (244),A ; ENABLE IT
00450 LD A,(DE) ; LOAD S. VALUE
00460 PUSH AF ; SAVE IT
00470 ;
00480 ;-----------------------
00490 ;
00500 ; NEXT, ENABLE THE DEST.
00510 ; BANK, AND STORE THE
00520 ; SOURCE BYTE THERE
00530 ;
00540 ; DEST BANK = 225 (AERCO)
00550 ; DEST BANK = 224 (OTHER)
00560 ;
00570 LD A,225 ; DESTINATION
00580 OUT (244),A ; ENABLE IT
00590 POP AF ; RECALL S. VALUE
00600 LD (HL),A ; STORE IT
00610 ;-----------------------
00620 ;
00630 ; INCREMENT THE SOURCE
00640 ; AND DEST. ADDRESSES.
00650 ; CHECK TO SEE IF DONE.
00660 ;
00670 INC DE ; SOURCE + 1
00680 INC HL ; DEST. + 1
00690 DEC BC ; LENGTH - 1
00700 LD A,B ; "B" INTO ACC.
00710 OR C ; SUM WITH "C"
00720 JR NZ,XFER1 ; "BC" = 0 ?
00730 LD A,1 ; RESTORE S. BANK
00740 OUT (244),A ; ENABLE IT
00750 RET ; ALL DONE
; XFER_1 disassembly
ORG $9858

LD HL,$A154 ; DEST. ADD.
LD DE,$A154 ; SOURCE ADD.
LD BC,$5E00 ; LENGTH
XFER1: LD A,$01 ; SOURCE BNK
OUT ($F4),A ; ENABLE IT
LD A,(DE) ; LOAD S. VALUE
PUSH AF ; SAVE IT
LD A,$E1 ; DESTINATION
OUT ($F4),A ; ENABLE IT
POP AF ; RECALL S. VALUE
LD (HL),A ; STORE IT
INC DE ; SOURCE + 1
INC HL ; DEST. + 1
DEC BC ; LENGTH - 1
LD A,B ; "B" INTO ACC.
OR C ; SUM WITH "C"
JR NZ,XFER1 ; "BC" = 0 ?
LD A,$01 ; RESTORE S. BANK
OUT ($F4),A ; ENABLE IT
RET ; ALL DONE

XFER_2 (Listing B)

A second form of data transfer useful in bank-switching is the ability to “swap” data between banks. This is the function of routine XFER_2. Where XFER_1 merely copied data from one bank/address to another, XFER_2 performs a swap function, copying the data from the source into the destination, and then placing the destination byte back into the source! This routine works much like XFER_1 above. The key to this program is the use of the AF and alternate AF registers, and exchanging these to easily allow the exchange of the source/destination values.

Listing B — XFER_2 source

00010 ;         XFER_2
00020 ;-----------------------
00030 ; PRACTICAL
00040 ; BANK-SWITCHING
00050 ;
00060 ; ++++++++++++++++++++
00070 ; + THIS SAMPLE PROG. +
00080 ; + WILL SWAP 24064 +
00090 ; + BYTES FROM MEMORY +
00100 ; + ADDRESS 41300 OF +
00110 ; + STD RAM AND 41300 +
00120 ; + OF THE DOCK BANK. +
00130 ; ++++++++++++++++++++
00140 ;
00150 ; (c) S D LEMKE 1988
00160 ;
00170 ; LEMKE SOFTWARE DEVELOP.
00180 ; 2144 WHITE OAK
00190 ; WICHITA, KS. 67207
00200 ;-----------------------
00210 ;-----------------------
00220 ;
00230 ; GETTING STARTED...
00240 ; SET SOURCE, DEST, AND
00250 ; NUMBER OF BYTES
00260 ;
00270 ORG 39000 ; CODE ADD.
00280 ;
00290 LD HL,41300 ; DEST. ADD.
00300 LD DE,41300 ; SOURCE ADD.
00310 LD BC,24064 ; LENGTH
00320 ;
00330 ;-----------------------
00340 ;
00350 ; BEGIN BY ENABLING THE
00360 ; SOURCE BANK AND SAVING
00370 ; THE SOURCE BYTE
00380 ;
00390 ; SOURCE BANK = 1 (AERCO)
00400 ; SOURCE BANK = 0 (OTHER)
00410 ;
00420 ;
00430 XFER2 LD A,1 ; SOURCE BNK
00440 OUT (244),A ; ENABLE IT
00450 LD A,(DE) ; LOAD S. VALUE
00460 EX AF,AF' ; SAVE IT
00470 ;
00480 ;-----------------------
00490 ;
00500 ; NEXT, ENABLE THE DEST.
00510 ; BANK, AND STORE THE
00520 ; SOURCE BYTE THERE
00530 ;
00540 ; DEST BANK = 225 (AERCO)
00550 ; DEST BANK = 224 (OTHER)
00560 ;
00570 LD A,225 ; DESTINATION
00580 OUT (244),A ; ENABLE IT
00590 LD A,(HL) ; LOAD D. VALUE
00600 EX AF,AF' ; SWAP VALUES
00610 LD (HL),A ; STORE DEST.
00620 ;
00630 ; ..... ENABLE THE SOURCE
00640 ; BANK, AND STORE THE
00650 ; DEST. BYTE THERE
00660 ;
00670 LD A,1 ; SOURCE BANK
00680 OUT (244),A ; ENABLE IT
00690 EX AF,AF' ; SWAP VALUES
00700 LD (DE),A ; STORE S. BYTE
00710 EX AF,AF' ; RESTORE AF
00720 ;-----------------------
00730 ;
00740 ; INCREMENT THE SOURCE
00750 ; AND DEST. ADDRESSES.
00760 ; CHECK TO SEE IF DONE.
00770 ;
00780 INC DE ; SOURCE + 1
00790 INC HL ; DEST. + 1
00800 DEC BC ; LENGTH - 1
00810 LD A,B ; "B" INTO ACC.
00820 OR C ; SUM WITH "C"
00830 JR NZ,XFER2 ; "BC" = 0 ?
00840 LD A,1 ; RESTORE S. BANK
00850 OUT (244),A ; ENABLE IT
00860 RET ; ALL DONE
; XFER_2 disassembly
ORG $9858

LD HL,$A154 ; DEST. ADD.
LD DE,$A154 ; SOURCE ADD.
LD BC,$5E00 ; LENGTH
XFER2: LD A,$01 ; SOURCE BNK
OUT ($F4),A ; ENABLE IT
LD A,(DE) ; LOAD S. VALUE
EX AF,AF' ; SAVE IT
LD A,$E1 ; DESTINATION
OUT ($F4),A ; ENABLE IT
LD A,(HL) ; LOAD D. VALUE
EX AF,AF' ; SWAP VALUES
LD (HL),A ; STORE DEST.
LD A,$01 ; SOURCE BANK
OUT ($F4),A ; ENABLE IT
EX AF,AF' ; SWAP VALUES
LD (DE),A ; STORE S. BYTE
EX AF,AF' ; RESTORE AF
INC DE ; SOURCE + 1
INC HL ; DEST. + 1
DEC BC ; LENGTH - 1
LD A,B ; "B" INTO ACC.
OR C ; SUM WITH "C"
JR NZ,XFER2 ; "BC" = 0 ?
LD A,$01 ; RESTORE S. BANK
OUT ($F4),A ; ENABLE IT
RET ; ALL DONE

XFER_3 (Listing C)

The third example is a merging of the source/destination data. This application superimposes the source data on the destination data using the “OR” function, and is equivalent of overlaying two pictures on a light board…ending up with one. I’ve used this function with my PIXEL PRINT PROFESSIONAL (desktop publisher) program, to combine (or merge) two PIXEL PRINT files. As you can see, the operation of the program is quite similar to the two above with a simple modification for the “OR” function. NOTE: both the source and destination addresses contain the merged data.

Listing C — XFER_3 source

00010 ;         XFER_3
00020 ;-----------------------
00030 ; PRACTICAL
00040 ; BANK-SWITCHING
00050 ;
00060 ; ++++++++++++++++++++
00070 ; + THIS SAMPLE PROG. +
00080 ; + WILL MERGE 24064 +
00090 ; + BYTES FROM MEMORY +
00100 ; + ADDRESS 41300 OF +
00110 ; + STD RAM AND 41300 +
00120 ; + OF THE DOCK BANK. +
00130 ; ++++++++++++++++++++
00140 ;
00150 ; (c) S D LEMKE 1988
00160 ;
00170 ; LEMKE SOFTWARE DEVELOP.
00180 ; 2144 WHITE OAK
00190 ; WICHITA, KS. 67207
00200 ;-----------------------
00210 ;-----------------------
00220 ;
00230 ; GETTING STARTED...
00240 ; SET SOURCE, DEST, AND
00250 ; NUMBER OF BYTES
00260 ;
00270 ORG 39000 ; CODE ADD.
00280 ;
00290 LD HL,41300 ; DEST. ADD.
00300 LD DE,41300 ; SOURCE ADD.
00310 LD BC,24064 ; LENGTH
00320 ;
00330 ;-----------------------
00340 ;
00350 ; BEGIN BY ENABLING THE
00360 ; SOURCE BANK AND SAVING
00370 ; THE SOURCE BYTE
00380 ;
00390 ; SOURCE BANK = 1 (AERCO)
00400 ; SOURCE BANK = 0 (OTHER)
00410 ;
00420 ;
00430 XFER3 LD A,1 ; SOURCE BNK
00440 OUT (244),A ; ENABLE IT
00450 LD A,(DE) ; LOAD S. VALUE
00460 PUSH AF ; SAVE IT
00470 ;
00480 ;-----------------------
00490 ;
00500 ; NEXT, ENABLE THE DEST.
00510 ; BANK, AND STORE THE
00520 ; SOURCE BYTE THERE
00530 ;
00540 ; DEST BANK = 225 (AERCO)
00550 ; DEST BANK = 224 (OTHER)
00560 ;
00570 LD A,225 ; DESTINATION
00580 OUT (244),A ; ENABLE IT
00590 POP AF ; RECALL S VALUE
00600 OR (HL) ; "OR" DEST VALUE
00610 LD (HL),A ; STORE DEST.
00620 PUSH AF ; SAVE SUM VALUE
00630 ;
00640 ; ..... ENABLE THE SOURCE
00650 ; BANK, AND STORE THE
00660 ; "SUM" THERE
00670 ;
00680 LD A,1 ; SOURCE BANK
00690 OUT (244),A ; ENABLE IT
00700 POP AF ; RECALL "SUM"
00710 LD (DE),A ; STORE S. BYTE
00720 ;-----------------------
00730 ;
00740 ; INCREMENT THE SOURCE
00750 ; AND DEST. ADDRESSES.
00760 ; CHECK TO SEE IF DONE.
00770 ;
00780 INC DE ; SOURCE + 1
00790 INC HL ; DEST. + 1
00800 DEC BC ; LENGTH - 1
00810 LD A,B ; "B" INTO ACC.
00820 OR C ; SUM WITH "C"
00830 JR NZ,XFER3 ; "BC" = 0 ?
00840 LD A,1 ; RESTORE S. BANK
00850 OUT (244),A ; ENABLE IT
00860 RET ; ALL DONE
; XFER_3 disassembly
ORG $9858

LD HL,$A154 ; DEST. ADD.
LD DE,$A154 ; SOURCE ADD.
LD BC,$5E00 ; LENGTH
XFER3: LD A,$01 ; SOURCE BNK
OUT ($F4),A ; ENABLE IT
LD A,(DE) ; LOAD S. VALUE
PUSH AF ; SAVE IT
LD A,$E1 ; DESTINATION
OUT ($F4),A ; ENABLE IT
POP AF ; RECALL S VALUE
OR (HL) ; "OR" DEST VALUE
LD (HL),A ; STORE DEST.
PUSH AF ; SAVE SUM VALUE
LD A,$01 ; SOURCE BANK
OUT ($F4),A ; ENABLE IT
POP AF ; RECALL "SUM"
LD (DE),A ; STORE S. BYTE
INC DE ; SOURCE + 1
INC HL ; DEST. + 1
DEC BC ; LENGTH - 1
LD A,B ; "B" INTO ACC.
OR C ; SUM WITH "C"
JR NZ,XFER3 ; "BC" = 0 ?
LD A,$01 ; RESTORE S. BANK
OUT ($F4),A ; ENABLE IT
RET ; ALL DONE

Now, I don’t pretend to be a very good assembly programmer, so I am sure there are many other ways to do these jobs. But, if I have been able to show you enough to get your interest peaked, and convinced you that BANK-SWITCHING is not an impossible task, then I’ve accomplished my goal!

Keep TS2068-ing, and start taking advantage of 2068 BANK-SWITCHING.

Products

 

Media

 

Image Gallery

Source Code

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

Scroll to Top