c64-livecoding/host/src/mainloop.s

106 lines
1.3 KiB
ArmAsm

;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
.scope mainsetup
.ifdef EMULATOR_PREVIEW
USERPROG = $C000
.repeat 4, I
ldy #$00
:
lda batch_userprog+(I*256),Y
sta USERPROG+(I*256),Y
dey
bne :-
.endrep
.endif
.ifndef EMULATOR_PREVIEW
@waitstart: ;; Wait until joystick 2 has been pulled down to start the program
dec $d020
lda $dc00
and #$02
bne @waitstart
jsr setup_loader
pha
@trying:
pla
tax
inx
stx $d020
txa
pha
jsr maybe_download_userprog
beq @trying
.endif
.endscope
lda #$0d
sta $d020
.scope mainloop
ldx #$00
stx FRAMECOUNT
inx
sta FIRSTTIME
ml:
USERPROG = $C000
RASTER = $D012
;; Bank out character ROM, I/O in
lda #%00000100
ora $01
sta $01
.ifndef EMULATOR_PREVIEW
jsr maybe_download_userprog
beq @nochange
ldx #$00
stx FRAMECOUNT
inx
sta FIRSTTIME
@nochange:
.endif
jsr USERPROG
;; Bank out character ROM, I/O in
lda #%00000100
ora $01
sta $01
@framewait:
ldy RASTER
cpy #$66
beq @framewait
inc FRAMECOUNT
lda #$00
sta FIRSTTIME
jmp ml
.endscope
.proc time ; user-procedure
lda FRAMECOUNT
rts
.endproc
.proc first ; user-procedure
lda FIRSTTIME
rts
.endproc
.proc bitand ; user-procedure
lda ARGVEC+0
and ARGVEC+1
rts
.endproc
.proc bitxor ; user-procedure
lda ARGVEC+0
eor ARGVEC+1
rts
.endproc
FRAMECOUNT: .byte 0
FIRSTTIME: .byte 1