ys2-intro/loader/samples/minexample/minexample.s

346 lines
4.3 KiB
ArmAsm
Raw Normal View History

2025-11-13 11:07:39 -05:00
.feature c_comments
.include "../../build/loadersymbols-c64.inc"
.ZEROPAGE
.org $10
bmp_delay: .res 1
bmp_addr: .res 2
bmp_ptr: .res 2
scr_ptr_lo: .res 1
scr_ptr: .res 2
cram_ptr: .res 2
chr_count: .res 1
vbl: .res 1
frame: .res 1
cur_frame: .res 1
frame_delay: .res 1
frame_until: .res 1
.segment "CODE"
ZP=$e0
offset = ZP+0
ZX0_src = ZP+2
ZX0_dst = ZP+4
bitr = ZP+6
pntr = ZP+7
.org $080d
jsr install
sei
lda #$35
sta $01
lda #0
sta ZX0_dst+0
ldx #<badguy
ldy #>badguy
jsr loadraw
lda #0
sta ZX0_src
lda #$e0
sta ZX0_src+1
lda #0
sta ZX0_dst
lda #$20
jsr zx02
lda #127
sta $dc0d
and $d011
sta $d011
lda $dc0d
lda $dd0d
lda #<irq_badguy
sta $fffe
lda #>irq_badguy
sta $ffff
lda #$1b
sta $d011
lda #$80
sta $d012
lda #1
sta $d01a
sta bmp_delay
jsr init_bmp
lda #0
sta vbl
cli
lda #7
sta frame_until
jsr wait_frame_until
lda #50*5
sta frame_delay
jsr wait_loop
lda #$0d
sta frame_until
jsr wait_frame_until
lda #50*5
sta frame_delay
jsr wait_loop
lda #50*5
sta frame_delay
jsr wait_loop
lda #26
sta frame_until
jsr wait_frame_until
jmp *
wait_loop:
loop2:
lda vbl
beq loop2
lda #0
sta vbl
jsr sfx_play
dec frame_delay
lda frame_delay
beq :+
jmp loop2
:
rts
wait_frame_until:
loop:
lda vbl
beq loop
lda #0
sta vbl
lda cur_frame
cmp #2
bcc :+
jsr sfx_play
:
dec bmp_delay
bpl :+
jsr update_bmp
:
lda cur_frame
cmp frame_until
beq :+
jmp loop
:
rts
init_bmp:
lda #$3b
sta $d011
lda #$19
sta $d018
lda #$d8
sta $d016
lda $4710
lsr
lsr
lsr
lsr
sta $d020
lda $4710
and #$0f
sta $d021
lda #0
sta cur_frame
sta bmp_delay
lda #$11
sta bmp_addr
lda #$47
sta bmp_addr+1
ldx #0
:
.repeat 4, I
lda $3f40+(I*250), x
sta $400+(I*250), x
lda $4328+(I*250), x
sta $d800+(I*250), x
.endrepeat
inx
cpx #250
bne :-
rts
inc_bmp_addr:
inc bmp_addr
bne :+
inc bmp_addr+1
:
rts
update_bmp:
ldy #0
sty scr_ptr
sty cram_ptr
lda (bmp_addr), y
jsr inc_bmp_addr
sta chr_count
cmp #0 ; tfw flags update in inc_bmp_addr
bne @skip_frame_end
lda (bmp_addr), y
jsr inc_bmp_addr
sta bmp_delay
inc cur_frame
lda cur_frame
cmp #2
bne :+
lda #0
jsr sfx_init
:
rts
@skip_frame_end:
lda (bmp_addr), y
sta bmp_ptr
iny
lda (bmp_addr), y
clc
adc #$20
sta bmp_ptr+1
iny
lda (bmp_addr), y
sta scr_ptr_lo
iny
lda (bmp_addr), y
clc
adc #$04
sta scr_ptr+1
clc
adc #$d8-$04
sta cram_ptr+1
ldy #0
lda bmp_addr
clc
adc #4
sta bmp_addr
bcc :+
inc bmp_addr+1
:
ldx #0
@loop:
ldy #0
lda (bmp_addr), y
sta (bmp_ptr), y
iny
lda (bmp_addr), y
sta (bmp_ptr), y
iny
lda (bmp_addr), y
sta (bmp_ptr), y
iny
lda (bmp_addr), y
sta (bmp_ptr), y
iny
lda (bmp_addr), y
sta (bmp_ptr), y
iny
lda (bmp_addr), y
sta (bmp_ptr), y
iny
lda (bmp_addr), y
sta (bmp_ptr), y
iny
lda (bmp_addr), y
sta (bmp_ptr), y
lda bmp_ptr
clc
adc #8
sta bmp_ptr
bcc :+
inc bmp_ptr+1
:
lda bmp_addr
clc
adc #8
sta bmp_addr
bcc :+
inc bmp_addr+1
:
ldy #0
lda (bmp_addr), y
ldy scr_ptr_lo
sta (scr_ptr), y
ldy #1
lda (bmp_addr), y
ldy scr_ptr_lo
sta (cram_ptr), y
inc scr_ptr_lo
bne :+
inc scr_ptr+1
inc cram_ptr+1
:
lda bmp_addr
clc
adc #2
sta bmp_addr
bcc :+
inc bmp_addr+1
:
dec chr_count
ldx chr_count
bne @loop
jmp update_bmp
irq_badguy:
pha
txa
pha
tya
pha
inc vbl
asl $d019
pla
tay
pla
tax
pla
rti
badguy: .byte "badguy",0
.include "sfx.asm"
.include "zx02.asm"
.res loadraw - *
.incbin "../../build/loader-c64.prg", 2
.res install - *
.incbin "../../build/install-c64.prg", 2