Hi there, the next stage of my little Orwell computer is getting BASIC running on it. After reading the
Pagetable blog post on it I decided to go with Microsoft BASIC. It is also in keeping with my whole 80s computer theme.
In addition to the code there I found
Grant Searle's version of it he used on his simple 6502 machine. His code is all the relevant bits of the OSI version of BASIC in one file with macros and unnecessary ifdefs removed. I took this code as my start point.
I added in my own IO routines and after a few minor bugs got it working. I can get past the Cold/Warm restart page but then it all goes wonky at the Memory Size prompt. The symptom is odd behaviour in the key values I get returned. For example I can return an 'a' but 'A' comes through as garbage. No matter what I enter here I get a syntax error and the prompt repeats. I think somehow something is getting corrupted. In order to understand what I have been trying to understand the code but something is confusing me.
I believe things are going wrong in the COLD_START code.
Code:
lda #<QT_MEMORY_SIZE
ldy #>QT_MEMORY_SIZE
jsr STROUT
jsr NXIN
stx TXTPTR
sty TXTPTR+1
JSR CHRGET
cmp #$41
beq PR_WRITTEN_BY
tay
bne L40EE
lda #<RAMSTART2
ldy #>RAMSTART2
sta LINNUM
sty LINNUM+1
ldy #$00
L40D7:
inc LINNUM
bne L40DD
inc LINNUM+1
L40DD:
lda #$92 ; 10010010 / 00100100
sta (LINNUM),y
cmp (LINNUM),y
bne L40FA
asl a
sta (LINNUM),y
cmp (LINNUM),y
beq L40D7; old: faster
bne L40FA
L40EE:
jsr CHRGOT
jsr LINGET
tay
beq L40FA
jmp SYNERR
L40FA:
lda LINNUM
ldy LINNUM+1
sta MEMSIZ
sty MEMSIZ+1
sta FRETOP
sty FRETOP+1
That cmp #$41 is actually a kind of easter egg. An 'A' typed here is supposed to show who wrote the code. But I get garbage not an 'A' at this point.
I have been trying to understand how the jsr CHRGET works. But I don't see how CHRGET is a subroutine? In code it is declared like this:
Code:
CHRGET:
TXTPTR = <(GENERIC_TXTPTR-GENERIC_CHRGET + CHRGET)
CHRGOT = <(GENERIC_CHRGOT-GENERIC_CHRGET + CHRGET)
CHRGOT2 = <(GENERIC_CHRGOT2-GENERIC_CHRGET + CHRGET)
RNDSEED = <(GENERIC_RNDSEED-GENERIC_CHRGET + CHRGET)
That's actually in the zeropage (at $BC).
Later in the actual code there is this:
Code:
GENERIC_CHRGET:
inc TXTPTR
bne GENERIC_CHRGOT
inc TXTPTR+1
GENERIC_CHRGOT:
GENERIC_TXTPTR = GENERIC_CHRGOT + 1
lda $EA60
cmp #$3A
bcs L4058
GENERIC_CHRGOT2:
cmp #$20
beq GENERIC_CHRGET
sec
sbc #$30
sec
sbc #$D0
L4058:
rts
GENERIC_RNDSEED:
; random number seed
.byte $80,$4F,$C7,$52
GENERIC_CHRGET_END:
I don't understand how this works? How doe we get into that code? I guess TXTPTR is a buffer for the value entered from the keyboard but how does all this get called exactly?
All my code is too big to post and I don't have it online yet but Grant's version
is here.
My next thing to try is take all my code out and just hard code things just so I can see if I can get past the memory size/check stage with the standard OSI code. I don't know if any of the above is part of my problem but it would be nice to understand how it works!
Simon