chipty5/chipty5-64.asm

231 lines
7.1 KiB
NASM

C8RAMSIZE = 4096
.virtual $c000
C8RAM .fill C8START
C8ENTRY .fill C8RAMSIZE - C8START
c8ramend = *-1
.endvirtual
ZP_START = $61
.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
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.vic2.raster
sta rngst+3
rts
.endproc
ClearScreen .proc
lda #0
sta io.vic2.ec
sta io.vic2.b0c
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
; Clear carry flag if retracing
lda #200
cmp io.vic2.raster
rts
.endproc
SoundInit .proc
FREQ = io.sid_freq(880)
DUTY = io.sid_duty(0.5)
lda #0
sta io.sid.voice1.ctrl
sta io.sid.voice2.ctrl
sta io.sid.voice3.ctrl
sta io.sid.voice1.ad
lda #$f0
sta io.sid.voice1.sr
lda #$0f
sta io.sid.volume
lda #<DUTY
sta io.sid.voice1.duty
lda #>DUTY
sta io.sid.voice1.duty+1
lda #<FREQ
sta io.sid.voice1.freq
lda #>FREQ
sta io.sid.voice1.freq+1
lda #io.SID_CTRL_PULSE
sta io.sid.voice1.ctrl
rts
.endproc
SoundOn .proc
lda #io.SID_CTRL_PULSE|io.SID_CTRL_GATE
sta io.sid.voice1.ctrl
rts
.endproc
SoundOff .proc
lda #io.SID_CTRL_PULSE
sta io.sid.voice1.ctrl
rts
.endproc
InputFileName .proc
jsr RestoreIRQ
ldx #ROW_FILENAME
ldy #0
sty ch8filenamelen
sty NDX
clc
jsr PLOT
lda #<prompt
ldy #>prompt
jsr STROUT
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
prompt .null "file name: "
.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