chipty5/chipty5-plus4.asm

231 lines
7.0 KiB
NASM

C8RAMSIZE = 4096
.virtual $3000
C8RAM .fill C8START
C8ENTRY .fill C8RAMSIZE - C8START
c8ramend = *-1
.endvirtual
ZP_START = $d0
.BasicStub MainEntry, 2021
.section code
MainEntry .proc
;lda #EF_REGS
lda #0
sta eflags
jsr InitRandom
jsr VideoInit
jsr SoundInit
jsr ClearScreen
jsr ShowTitle
jsr C8Reset
jsr SetupIRQ
jsr C8Run
rts
.endproc
SetupIRQ .proc
lda #64
sta prevkey
sei
lda CINV
sta sysirq
lda CINV+1
sta sysirq+1
lda #<handler
sta CINV
lda #>handler
sta CINV+1
cli
rts
handler
lda SFDX
tax
cmp prevkey
beq dotick
cmp #0 ; backspace: power cycle (reset) the vm
bne +
lda #EF_RESET
ora eflags
sta eflags
jmp done
+ txa
cmp #41 ; P: Pause
bne +
lda #EF_PAUSE
eor eflags
sta eflags
jmp done
+ txa
cmp #53 ; =: Registers
bne +
lda #EF_REGS
eor eflags
sta eflags
jmp done
+ txa
cmp #55 ; /: Shift behaviour
bne +
lda #EF_SHIFTX
eor eflags
sta eflags
jmp done
+ txa
cmp #42 ; L: Load program
bne +
lda #EF_LOAD
ora eflags
sta eflags
; jmp done
+
done stx prevkey
dotick jsr Tick
jmp (sysirq)
.section bss
sysirq .word ?
prevkey .byte ?
.endsection bss
.endproc
RestoreIRQ .proc
sei
lda SetupIRQ.sysirq
sta CINV
lda SetupIRQ.sysirq+1
sta CINV+1
cli
rts
.endproc
InitRandom .proc
ldx #0
- lda TIME, x
sta rngst, x
inx
cpx #3
bne -
lda io.ted.rasterline_lo
sta rngst+3
lda io.ted.rastercolumn
eor rngst+1
sta rngst+1
rts
.endproc
ClearScreen .proc
lda #0
sta io.ted.bgcolor
sta io.ted.bordercolor
lda #'{green}'
jsr CHROUT
lda #'{clear}'
jsr CHROUT
rts
.endproc
ReadKeyboard .proc
lda SFDX
cmp #64
bne +
nokey
lda #$ff
rts
+ ldy #0
- cmp kbdcodes, y
beq +
cpy #size(kbdcodes)
beq nokey
iny
bne -
+ tya
rts
.endproc
GetVBlank .proc
sec
lda #200
cmp io.ted.rasterline_lo
rts
.endproc
SoundInit .proc
FREQ = io.ted_freq(880)
lda #$0f
sta io.ted.snd_ctrl
lda #<FREQ
sta io.ted.freq1
; lda #>FREQ
; ora io.ted.misc
; sta io.ted.misc
lda io.ted.misc
and #%1111_1100
ora #>FREQ
sta io.ted.misc
rts
.endproc
SoundOn .proc
lda #$10
ora io.ted.snd_ctrl
sta io.ted.snd_ctrl
rts
.endproc
SoundOff .proc
lda #~$10
and io.ted.snd_ctrl
sta io.ted.snd_ctrl
rts
.endproc
InputFileName .proc
jsr RestoreIRQ
ldx #ROW_FILENAME
ldy #0
sty ch8filenamelen
sty NDX
clc
jsr myPLOT
lda #<prompt
ldy #>prompt
jsr mySTROUT
ldx #ROW_FILENAME
ldy #size(prompt)
clc
jsr PLOT
ldy #0
- lda #0
sta ch8filename, y
jsr CHRIN
cmp #13
beq +
sta ch8filename, y
iny
jmp -
+ sty ch8filenamelen
ldx #ROW_FILENAME
jsr ClearLine
jsr SetupIRQ
rts
.section data
.enc "screen"
prompt .null "file name: "
.enc "none"
.endsection data
.endproc
.endsection code
.section data
kbdcodes .byte 56, 59, 8, 11, 62, 9, 14, 17, 10, 13, 18, 21, 12, 23, 20, 31
.endsection data
; vim: syntax=64tass