processor 6502 srcPointer = $b5 dstPointer = $b7 dstPointerEnd = $b9 fake_current_byte = $126 count = $128 loading_bar = $130 org $a000 ; autostart cartridge magic number WORD coldstart WORD coldstart BYTE #$41, #$30, #$c3, #$c2, #$cd coldstart SUBROUTINE 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 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 ; copy BASIC demo code in BASIC memory jsr copycode ; set current BASIC line number lda #$ff sta $3a lda #0 sta $3b ; set start of BASIC variables lda #<($1001 + demo_end - demo_start) sta $2d lda #>($1001 + demo_end - demo_start) sta $2e lda #$02 jsr clear_color_ram ; print informative message for user lda #message jsr $cb1e ; print null terminated string ; install fake chrin to hijack custom commands lda #0 sta fake_current_byte sei lda #fake_chrin sta $325 cli jmp $c483 ; BASIC ; custom hijacked command line fake_input_line: BYTE "RUN",#$0d,#0,#0,#0 fake_chrin SUBROUTINE ldy fake_current_byte lda fake_input_line,y iny sty fake_current_byte cpy #5 bne .end_fake_chrin dey sty fake_current_byte .end_fake_chrin: clc rts ; Put color in A clear_color_ram SUBROUTINE ldx #$00 .loop: sta $9600,x sta $9700,x dex bne .loop rts ; 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 + 1 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: ; lenght of program to copy lda count cmp #DEMO_LEN bne copyloop cli .finito: rts loading_feedback SUBROUTINE ldx loading_bar lda #$79 sta 7988,x cpx #21 beq .start_button rts .start_button: ; print lda #start_button_message jsr $cb1e ; use system CHRIN lda #$e0 sta $324 lda #$f2 sta $325 ; wait for SPACE .chrin: jsr $ffe4 cmp #$20 bne .chrin jsr copytree rts ; draws a Christmas tree shamelessly copied from another demo copytree SUBROUTINE ; all this is just a memcpy 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 ; 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 rts message: BYTE #$0d,#$0d,"PLEASE WAIT 20 SEC",#$0d,"I'M JUST",#$0d,"AN OLD COMPUTER",#$0d,#0 start_button_message: BYTE "PRESS SPACE TO START",#$0 ; 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 tree_start: .incbin "res/tree.bin" tree_end: ECHO "cartridge usage",. . = $bff9 jmp loading_feedback . = $bffc jmp coldstart . = $bfff BYTE #$ff