Good Morning Readership,
Todays topic is how microsoft Basic V1 loads and saves on the KIM-1 microcomputer.
Imagine you typed in your basic program and want to save it on cassette tape. (the only storage the KIM-1 had beside papertapes).
You simply type in
SAVE
and loading works exactly as expected too.
Behind the scenes Basic sets the importants bytes in memory, which are
$17F5 startadress lowbyte
$17F6 startadress highbyte
$17F7 endadress lowbyte
$17F8 endadress highbyte
and $17F9 name of the program (*)
and calls the 'magic' ROM routines for loading and saving which are $1873 and $1800.
Dave McMurtrie came up with a implementation of the C64's 1541 loading and saving routines for the KIM-1 and I thought why not patch MS Basic to load and save from and to disk.
Spoiler: I've done it and it was not hard at all, as the sources for Microsoft Basic are free available and well documented by MiSt64 ( https://github.com/mist64/msbasic ) and even n00bs like me can compile it with Hans Otten's cookbook "How to compile your KIM Basic"
The KIM1541 routines needed to be patched also, as they make heavily use of the Zeropage, which conflicts with Basic. So I analyzed the basic sources and found that The KIM-1 version uses the following four ZP areas:
ZP_START1 = $00
ZP_START2 = $15
ZP_START3 = $0A
ZP_START4 = $63
where the 2rd area from $15 to $63 is the input buffer.
I chose to reuse this area while loading and saving and also needed to keep the distances of the ZP loactions in the 1541 routine. A try and error process, but in the end loading and saving worked.
What works? You can load and save in Microsoft Basic from and to Disk.
What does not work? Giving the Program a name. Bummer
Why?
Lil'Bill completely ignored the namegiving part of the KIM-1. Programs are always being saved as "$FE" and if you type LOAD the next available program on tape will be loaded, no matter how it's called. This may be OK for cassette tapes, where you can write down the tapecounter and fastforward or rewind the tape, but it's utterly shit for our diskdrive.... Let's look at the sources:
.segment "CODE"
SAVE:
tsx
stx INPUTFLG
lda #$37
sta $F2
lda #$FE
sta $17F9
( blabla)
You see that always if SAVE is called, $FE is loaded into the Accumulator and stored in $17F9.
But how can I store more than one Basic program on a disk?
Dave Hassler helped me out here: You can easily poke the name of the program direct in the RAM. In other words, you modify the program itself everytime you load or save.
POKE 9900,1 (whereas numbers from 1-254 are allowed)
changes the above shown assembler code to lda #$01 and now the program with the name 01 is being loaded. (POKE 9817,xxx for changing the name to be saved)
So we finally can load and save to disk on a 40 year old computer.
There remain bigger issues than thought.... PLZ be patient for a release
What do you need?
- place the 1541 routines at memory location $A000 (I'll give you a $E000 version later)
- load Basic from disk (name $01)
- start Basic at $3D64
So long for now. I'll try making a video tomorrow,
cu
Webdoktor
Leave a Reply