Re: 720 bank switching (was: Pascal compiler)

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2002-10-07 18:20:53

On Mon, Oct 07, 2002 at 05:53:05PM +0300, Marko Mäkelä wrote:
> A while back, when Per Olofsson was visiting Finland, I tried to
> entertain us by quickly hacking something that plays C64 music on the
> 720.  I tried everything (except the emulator VICE), but I could not
> figure out how to write a BASIC program that starts a machine language
> routine in bank 1 (right after the BASIC program text).  Is the only way
> by POKEing or BLOADing some bootstrap code to bank 15?  The ROM routines
> are quite complicated, and I could not fully follow them, not even from the
> disassembled listing made by you.

Unfortunately, the ROM routines are of no help for this. What I'm doing in the
cc65 startup routines for the B machines is the following:

BASIC programs are loaded into bank 1, so this is just what we want for our C
program. The C program has the startup code linked in as first file. This
startup code has a small BASIC header. BASIC programs are loaded to address
$02 in bank 1. The BASIC program reads like this:

        10 for i=0 to 4
        20 read j
        30 poke 256+i,j
        40 next i
        50 sys 256
        60 data 120,169,1,133,0

The BASIC program shown above pokes the following code into the system bank
(bank 15) at the bottom of the stack ($100):

        sei
        lda     #$01
        sta     $00	       	<-- Switch to bank 1 after this command

This machine language sequence is then started from the BASIC program by a SYS
call. It disables interrupts (which would be disastreous since nothing is
setup in the target bank), and switches to bank 1. The remainder of the
program is laid out so that it starts at address $105 in bank 1. This makes a
lot of sense, because the C startup code can place initialization code here
which is later overwritten by the stack.

One of the bigger problems is, that there is no kernal in the RAM banks, and
the bank switching routines suggested by Commodore are slow like hell. So
programs generated by cc65 carry those kernal routines with them that are
needed, and these kernal routines are rewritten to access the I/O chips in
bank 15. Not all kernal routines are available, I'm more or less rewriting
them whenever they are needed for a special function. Fortunately the more
important kernal routines are quite similar in the CBM 6/700 family and the
P500, so I can reuse a lot of code with none or only minor changes.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz@musoftware.de

       Message was sent through the cbm-hackers mailing list

Archive generated by hypermail 2.1.4.