vic20-xmas-demo/src/main.asm

281 lines
4.7 KiB
NASM
Raw Permalink Normal View History

2022-12-04 00:00:17 +00:00
processor 6502
srcPointer = $b5
dstPointer = $b7
dstPointerEnd = $b9
fake_current_byte = $126
count = $128
2022-12-04 20:22:59 +00:00
loading_bar = $130
2022-12-04 00:00:17 +00:00
org $a000
; autostart cartridge magic number
WORD coldstart
2022-12-04 18:52:57 +00:00
WORD coldstart
2022-12-04 00:00:17 +00:00
BYTE #$41, #$30, #$c3, #$c2, #$cd
coldstart SUBROUTINE
2022-12-04 00:00:17 +00:00
cld
sei
jsr $fd8d ; initialize and test RAM
jsr $fd52 ; restore default I/O vectors
jsr $fdf9 ; initialize I/O registers
jsr $e518 ; initialize hardware
cli ; enable interrupts
2022-12-04 00:00:17 +00:00
lda $0288
sta $0294
jsr $e45b ; initialize BASIC vector table
jsr $e3a4 ; initialize BASIC RAM locations
jsr $e404 ; print startup message and initialize memory pointers
ldx #$fb ; value for stack start
txs ; set stack pointer
lda #$76 ; set "READY." pointer
ldy #$c3
jsr $cb1e ; print null terminated string
lda #$80 ; set for control messages only
jsr $ff90 ; control kernal messages
2022-12-04 20:22:59 +00:00
; copy BASIC demo code in BASIC memory
jsr copycode
; set current BASIC line number
lda #$ff
sta $3a
lda #0
sta $3b
2022-12-04 20:22:59 +00:00
; set start of BASIC variables
lda #<($1001 + demo_end - demo_start)
sta $2d
lda #>($1001 + demo_end - demo_start)
sta $2e
2022-12-04 21:22:03 +00:00
lda #$02
2022-12-04 18:52:57 +00:00
jsr clear_color_ram
2022-12-04 18:54:14 +00:00
; print informative message for user
2022-12-04 18:52:57 +00:00
lda #<message
ldy #>message
2022-12-04 18:54:14 +00:00
jsr $cb1e ; print null terminated string
2022-12-04 19:12:19 +00:00
; install fake chrin to hijack custom commands
2022-12-04 19:53:52 +00:00
lda #0
sta fake_current_byte
2022-12-04 19:12:19 +00:00
sei
lda #<fake_chrin
sta $324
lda #>fake_chrin
sta $325
cli
jmp $c483 ; BASIC
; custom hijacked command line
fake_input_line:
2022-12-04 19:12:19 +00:00
BYTE "RUN",#$0d,#0,#0,#0
fake_chrin SUBROUTINE
ldy fake_current_byte
lda fake_input_line,y
iny
sty fake_current_byte
2022-12-04 19:12:19 +00:00
cpy #5
bne .end_fake_chrin
2022-12-04 19:12:19 +00:00
dey
sty fake_current_byte
.end_fake_chrin:
clc
rts
2022-12-04 21:22:03 +00:00
; Put color in A
2022-12-04 18:52:57 +00:00
clear_color_ram SUBROUTINE
2022-12-04 00:00:17 +00:00
ldx #$00
2022-12-04 18:52:57 +00:00
.loop:
2022-12-04 00:00:17 +00:00
sta $9600,x
sta $9700,x
dex
2022-12-04 18:52:57 +00:00
bne .loop
rts
2022-12-04 00:00:17 +00:00
; This routine does a lot of unnecessary things,
; but I added a lot of garbage things to debug it,
; because it did not work as intended.
; In the end, the problem was elsewhere, as usual.
copycode SUBROUTINE
sei
lda #0
sta count
sta count + 1
lda #<demo_start
sta srcPointer
lda #>demo_start
sta srcPointer + 1
2022-12-04 00:00:17 +00:00
lda #$01
sta dstPointer
lda #$10
sta dstPointer + 1
ldy #0
copyloop:
lda (srcPointer),y
sta (dstPointer),y
inc srcPointer
bne .noinc1
inc srcPointer + 1
.noinc1:
inc dstPointer
bne .noinc2
inc dstPointer + 1
.noinc2:
inc count
bne .noinc3
inc count + 1
.noinc3:
2022-12-04 18:54:14 +00:00
; lenght of program to copy
lda count
cmp #<DEMO_LEN
bne copyloop
lda count + 1
cmp #>DEMO_LEN
bne copyloop
cli
.finito:
rts
2022-12-04 20:22:59 +00:00
loading_feedback SUBROUTINE
ldx loading_bar
lda #$79
sta 7988,x
2022-12-04 20:41:57 +00:00
cpx #21
beq .start_button
rts
.start_button:
; print
lda #<start_button_message
ldy #>start_button_message
jsr $cb1e
; use system CHRIN
lda #$e0
sta $324
lda #$f2
sta $325
2022-12-04 20:54:19 +00:00
; wait for SPACE
2022-12-04 20:41:57 +00:00
.chrin:
jsr $ffe4
cmp #$20
bne .chrin
2022-12-04 20:54:19 +00:00
jsr copytree
2022-12-04 20:22:59 +00:00
rts
2022-12-04 20:54:19 +00:00
; draws a Christmas tree shamelessly copied from another demo
copytree SUBROUTINE
2022-12-04 21:22:03 +00:00
; all this is just a memcpy
2022-12-04 20:54:19 +00:00
lda #<tree_start
sta srcPointer
lda #>tree_start
sta srcPointer + 1
lda #$00
sta dstPointer
lda #$1e
sta dstPointer + 1
ldy #0
.loop:
lda (srcPointer),y
sta (dstPointer),y
inc srcPointer
bne .noinc1
inc srcPointer + 1
.noinc1:
inc dstPointer
bne .noinc2
inc dstPointer + 1
.noinc2:
lda srcPointer
cmp #<tree_end
bne .loop
lda srcPointer + 1
cmp #>tree_end
bne .loop
2022-12-04 21:22:03 +00:00
; colors
lda #$08
sta $900f
lda #$05
jsr clear_color_ram
; balls
lda #$02
sta $96a3
sta $96a6
lda #$06
sta $96ce
sta $96d3
lda #$04
sta $96f9
sta $9700
lda #$03
sta $9724
sta $972d
; ì puntale di' monni
; (can't translate)
lda #$07
sta $9678
sta $9679
; gambo
lda #$02
sta $973e
sta $973f
2022-12-04 20:54:19 +00:00
rts
2022-12-04 00:00:17 +00:00
message:
2022-12-04 19:12:19 +00:00
BYTE #$0d,#$0d,"PLEASE WAIT 20 SEC",#$0d,"I'M JUST",#$0d,"AN OLD COMPUTER",#$0d,#0
2022-12-04 20:41:57 +00:00
start_button_message:
BYTE "PRESS SPACE TO START",#$0
2022-12-04 00:00:17 +00:00
2022-12-04 19:12:19 +00:00
; https://www.commodore.ca/manuals/funet/cbm/vic20/demos.basic/unexpanded/Stillenacht.prg
demo_start:
.incbin "build/demo.raw"
demo_end:
DEMO_LEN SET demo_end - demo_start
2022-12-04 20:54:19 +00:00
tree_start:
.incbin "res/tree.bin"
tree_end:
2022-12-04 21:36:31 +00:00
BYTE "THIS DEMO HAS BEEN PATCHED BY GIOMBA FOR HIS COLLEAGUES -- DECEMBER 2022"
2022-12-04 20:55:25 +00:00
ECHO "cartridge usage",.
2022-12-04 20:22:59 +00:00
. = $bff9
jmp loading_feedback
2022-12-04 19:12:19 +00:00
. = $bffc
jmp coldstart
2022-12-04 00:00:17 +00:00
. = $bfff
BYTE #$ff