megdemo: have simple case working

This commit is contained in:
Vince Weaver 2018-09-17 00:44:32 -04:00
parent 452b891f55
commit 1a40b7de36
5 changed files with 535 additions and 4 deletions

View File

@ -2,6 +2,8 @@ include ../Makefile.inc
DOS33 = ../dos33fs-utils/dos33
B2D = ../bmp2dhr/b2d
PNG_TO_40x96 = ../gr-utils/png_to_40x96
all: megademo.dsk
@ -19,12 +21,18 @@ MEGADEMO: megademo.o
megademo.o: megademo.s \
zp.inc hardware.inc \
c64_opener.s c64.img.lz4
c64_opener.s c64.img.lz4 \
falling_apple.s apple_40_96.inc
ca65 -o megademo.o megademo.s -l megademo.lst
####
apple_40_96.inc: ./images/apple_40_96.png
$(PNG_TO_40x96) asm ./images/apple_40_96.png apple > apple_40_96.inc
####
c64.img.lz4: c64.img
lz4 -f -16 c64.img

177
megademo/apple_40_96.inc Normal file
View File

@ -0,0 +1,177 @@
apple_low: .byte $28 ; ysize=48
.byte $A8,$FF, $5F, $5A, $55, $98, $55, $D8
.byte $55, $58, $55,$55, $58, $95, $85, $58
.byte $55, $95, $A3,$55, $85, $5A, $A0,$12,$FF, $BF
.byte $5F, $DD, $5B, $5F, $5D, $DF, $5D
.byte $5F,$5F, $8F, $5D, $5F, $5D, $5B, $5D
.byte $FF, $D5, $59, $95, $58, $55, $A0,$13,$FF
.byte $55, $08, $55, $05, $50, $A3,$55, $58
.byte $0A, $5D, $05, $0A,$0A, $58, $DF, $BD
.byte $DA, $5A, $59, $85, $5A, $A0,$12,$FF, $55
.byte $08, $50, $05, $55, $A4,$5A, $55,$55, $00
.byte $50, $05, $D5, $FA, $FF, $DA, $B5
.byte $88, $5A, $5D, $A0,$12,$FF, $55,$55, $50, $55
.byte $05, $65, $5A,$5A, $55,$55, $45, $55,$55, $05
.byte $D5, $FA, $DD, $BF, $D5, $98, $55,$55
.byte $DF, $A0,$11,$FF, $A3,$55, $50, $54, $55,$55, $05
.byte $65, $55, $45, $55, $50, $05, $D5
.byte $BD, $DF, $FD, $95, $58, $8B, $58
.byte $5F, $A0,$11,$FF, $55, $05, $54, $00, $56
.byte $A3,$55, $45, $05, $50, $55,$55, $00, $55
.byte $DD, $FF, $5D, $55, $89, $95, $58
.byte $5A, $A0,$11,$FF, $5D, $00, $55, $00, $A3,$55
.byte $00, $56, $00, $55, $54, $00, $55
.byte $85, $5D, $FA, $DD, $55, $88, $55
.byte $90, $5F, $A0,$11,$FF, $DD, $50, $05, $50
.byte $05, $40, $55, $05, $60, $05, $40
.byte $05, $50, $05, $55, $DD, $BA, $DF
.byte $55, $88, $55, $90, $5D, $5A,$5A, $5F
.byte $DA, $5F,$5F, $DF, $5F, $A9,$FF, $5D, $50
.byte $05, $50, $55, $00, $54, $05, $50
.byte $05, $45, $00, $55, $50, $55, $DD
.byte $5F, $FF, $55, $89, $55,$55, $F5, $5A
.byte $FA, $DD, $B5, $D9, $5A, $5D, $5A
.byte $A9,$FF, $5A, $55, $05, $55, $00, $05
.byte $40, $05, $50, $05, $50, $04, $50
.byte $05, $D5, $5D, $DF, $FD, $5B, $5D
.byte $5B, $5D, $5B, $5A, $DD, $BB, $5D
.byte $5A,$5A, $55,$55, $FA, $A8,$FF, $FA, $5A, $DA
.byte $5D, $85, $A4,$55, $D8, $55,$55, $58, $55
.byte $D5, $59, $DF, $FD, $55, $00, $55
.byte $00, $50, $05, $50, $00, $55, $5A,$5A
.byte $5B, $55, $DD, $A8,$FF, $5A, $DF, $BD
.byte $8F, $5D,$5D, $5B, $5D, $5B, $5D, $FB
.byte $D5, $F5, $D8, $F5,$F5, $FD, $5B, $55
.byte $50, $00, $05, $00, $55, $00,$00, $55,$55
.byte $5A, $DD, $55, $FA, $A7,$FF, $5A, $DD
.byte $BB, $DD, $BA, $DD, $5F, $9D, $5A,$5A
.byte $DD, $55, $D5, $55, $D8, $BB, $D5
.byte $5B, $5D, $55, $00, $52, $00, $55
.byte $00, $55, $52, $05, $55, $5A, $DD
.byte $55, $FA, $A5,$FF, $5F,$5F, $DF, $FA, $FF
.byte $FA, $FB, $FD, $DB, $F5, $50, $D5
.byte $59, $D5, $FD, $D9, $BF, $FA, $DB
.byte $BD, $DF, $A3,$55, $50, $06, $50, $55
.byte $59, $05, $55, $DA, $5D, $DA, $5F
.byte $A3,$FF, $5F, $FF, $DF, $5D, $05, $5A,$5A
.byte $8F, $5D, $5A, $5D, $5B, $5D, $DF
.byte $BF, $5D, $FF, $DF, $5D, $FB, $DF
.byte $FD, $55,$55, $00, $50, $05, $75, $05
.byte $55, $05, $55,$55, $DD, $BA, $DD, $5A
.byte $FF,$FF, $DF, $BF, $DA, $5D, $80, $55,$55
.byte $85, $58, $05, $10, $05, $55, $51
.byte $55, $00, $55, $05, $FD, $DF, $FD
.byte $DD, $5B, $58, $55, $00,$00, $50, $02
.byte $20, $05, $00, $55, $5A,$5A, $DF, $5A
.byte $5D, $FF,$FF, $FA, $5F, $FD, $D5, $F5
.byte $58, $5B, $55,$55, $15, $80, $58, $51
.byte $55, $58, $85, $B0, $5A, $FF, $FD
.byte $DF, $5D, $55, $58, $55, $50, $05
.byte $50, $05, $00, $50, $05, $50, $5F
.byte $DD, $5A, $F5, $FF,$FF, $5F,$5F, $A4,$FF, $FA
.byte $FD, $FA,$FA, $F5, $FD, $FB, $55, $D5
.byte $F5, $F8, $FB, $DD, $FF, $DD, $5A
.byte $59, $A3,$55, $00, $55, $00, $55, $00
.byte $55, $15, $00, $FD, $5A, $FA, $A4,$FF
.byte $F5,$F5, $A4,$5A, $5F, $BF, $A3,$5F, $A5,$FF, $FD
.byte $FF, $DF, $5D, $55, $DA, $55, $B8
.byte $FA,$FA, $F5,$F5, $F7, $55,$55, $50, $55,$55, $AC,$FF
.byte $FA,$FA, $A3,$F5, $B5, $A4,$5A, $A3,$5F, $FA, $DD
.byte $5A, $F5, $A0,$12,$FF, $CF, $AF,$FF, $FA, $F5
.byte $F0, $F5, $AF,$FF, $CF, $FF, $9F, $A3,$9C
.byte $FC, $FF,$FF, $C9, $CF, $C9, $FF, $C9
.byte $CF, $C9, $FF, $C9, $CF, $C9, $FF
.byte $C9, $A3,$FF, $C9, $CF, $A4,$FF, $C9, $FF
.byte $C9, $A3,$FF, $9F, $A3,$9C, $FC, $A5,$F2, $FF,$FF
.byte $F6, $FF, $F6, $FF, $F6, $A3,$FF, $F6
.byte $A3,$FF, $F6, $A3,$FF, $F6, $A5,$FF, $F6, $FF
.byte $F6, $A3,$FF, $A5,$F2
.byte $A1
apple_high: .byte $28 ; ysize=48
.byte $A8,$FF, $5F, $8F, $5F, $A5,$5A, $8F, $BA
.byte $8F, $5A, $A3,$5F, $8F, $5F, $8F, $5F
.byte $DF, $5F, $A0,$12,$FF, $DD, $5F, $5D, $5F
.byte $9D, $5A, $5D, $5B, $9D, $FA, $5D
.byte $FA,$FA, $D5, $FD, $D5, $55, $DD, $5A
.byte $55,$55, $85, $A0,$12,$FF, $5D, $55, $95, $0D
.byte $0A,$0A, $5A, $5D, $5A,$5A, $5B, $55, $05
.byte $5A, $59, $B5, $DF, $FF, $DF, $58
.byte $85, $58, $A0,$12,$FF, $5D, $55,$55, $50, $00
.byte $55, $7A, $A3,$5A, $A4,$55, $00, $55, $DF
.byte $DD, $5F, $D9, $55, $5A,$5A, $A0,$11,$FF, $DF
.byte $5D, $00, $45, $05, $55, $A3,$5A, $55,$55
.byte $05, $55, $05, $50, $55, $5D, $FF
.byte $DA, $59, $55, $88, $5A, $A0,$11,$FF, $5F
.byte $DD, $00, $50, $05, $55, $05, $65
.byte $55,$55, $05, $50, $55, $05, $50, $55
.byte $5F, $FD, $5A, $55, $85, $58, $55
.byte $A0,$11,$FF, $DF, $5D, $50, $00, $55, $00
.byte $45, $55, $05, $50, $55,$55, $00, $85
.byte $55,$55, $5F, $FD, $DA, $55,$55, $58, $55
.byte $A0,$12,$FF, $5A, $54, $40, $05, $40, $05
.byte $50, $A3,$55, $05, $50, $55, $05, $B5
.byte $DA, $FF, $FD, $15, $55, $88, $55
.byte $5F, $A0,$11,$FF, $FA, $05, $50, $06, $60
.byte $04, $55, $50, $05, $54, $55, $50
.byte $85, $05, $BA, $DA, $FF, $DD, $55
.byte $B5, $88, $55, $5F,$5F, $DF, $5F, $DF
.byte $5F, $DF, $5F,$5F, $A8,$FF, $FA, $F5, $05
.byte $40, $05, $50, $55, $05, $50, $45
.byte $00, $55, $00, $55, $05, $55, $BA
.byte $DD, $FF, $85, $58, $80, $B5, $DD
.byte $9A, $5D, $5B, $DA, $5F, $5A, $DA
.byte $5A, $A9,$FF, $5D, $85, $50, $00, $55
.byte $56, $50, $05, $40, $05, $50, $05
.byte $50, $00, $55, $BA, $DF, $5D, $D5
.byte $5A,$5A, $DD, $5A, $FD, $5A,$5A, $DD, $5B
.byte $9A, $DD, $55, $A9,$FF, $DD, $5A, $5D
.byte $A3,$55, $D5, $50, $55, $50, $55, $50,$50
.byte $85, $5A,$5A, $FF, $FD, $55, $50, $00
.byte $55, $00, $05, $55, $05, $5D, $5A
.byte $DA, $58, $55, $A8,$FF, $DF, $5D, $5B
.byte $5D, $5B, $5D, $5B, $FD, $D5, $F8
.byte $D5,$D5, $B8, $D5, $BB, $D8, $5B, $DD
.byte $DF, $55, $00,$00, $55, $20, $00, $55
.byte $00, $85, $5A, $59, $5A, $55, $A7,$FF
.byte $BF, $DD, $FB, $5D, $FA, $DF, $59
.byte $F5, $55, $D9, $55, $B5, $D5, $B5
.byte $5D, $5B, $8D, $5F, $5D, $5A, $A3,$55
.byte $05, $50, $00, $55, $00, $55, $D9
.byte $5A, $55,$55, $A6,$FF, $DF, $FD, $FB, $FD
.byte $DA, $FF, $DD, $5A, $B5, $D8, $A4,$55
.byte $FF, $5A, $DF, $DD, $5F, $DD, $5A
.byte $55,$55, $07, $50, $25, $50, $05, $BD
.byte $55, $5D, $5A,$5A, $55, $A5,$FF, $DF, $BD
.byte $FA, $5F, $8A, $1D, $5A, $5F,$5F, $FF
.byte $DF, $FF, $5F, $FF, $DA, $FB, $FD
.byte $FA, $FF, $FD, $FA, $55,$55, $A6,$05, $55,$55
.byte $5A, $5B, $5A,$5A, $A4,$FF, $FD, $FB, $5D
.byte $5B, $08, $15, $00, $55, $50, $89
.byte $50, $85, $08, $55, $85, $5D, $5B
.byte $DD, $BA, $FF, $5A,$5A, $55,$55, $50, $02
.byte $00, $55, $00, $55, $00, $55, $BA
.byte $DD, $5A,$5A, $5F, $FF, $BF, $DD, $FF
.byte $DA, $BB, $55, $8A, $50, $0B, $88
.byte $A4,$55, $00, $55,$55, $59, $D5, $BB, $DD
.byte $BB, $A4,$55, $A3,$00, $25, $50, $05, $50
.byte $00, $FA, $5F, $5A, $5F, $FA, $FF,$FF
.byte $FD, $FF,$FF, $FA, $FF, $F9, $F5, $D5
.byte $F5, $55,$55, $80, $58, $51, $F5, $55
.byte $DA, $BF, $FD, $FB, $5A, $55, $85
.byte $55,$55, $57, $70, $00, $27, $00, $55
.byte $90, $55, $FB, $5A, $55, $A4,$FF, $55,$55
.byte $5A,$5A, $A5,$5F, $FD, $A3,$FF, $FB, $FD, $FF,$FF
.byte $FB, $FD, $5B, $9A, $5D, $55,$55, $A3,$F5
.byte $55, $50,$50, $55, $5A, $55, $5A, $FA
.byte $A9,$FF, $FA, $A3,$F5, $FA, $5A, $55,$55, $A3,$5A
.byte $A3,$5F, $DF, $BA, $5A,$5A, $55, $A9,$FF, $FA
.byte $A0,$15,$FF, $FA,$FA, $F0, $F5,$F5, $A3,$FA, $A0,$10,$FF, $DF,$DF
.byte $DC, $DF, $A3,$FF, $DF, $F1, $DF, $FF
.byte $D1, $F1, $D1, $FF, $D1, $F1, $D1
.byte $FF, $D1, $A3,$FF, $D1, $F1,$F1, $FF,$FF, $F1
.byte $D1, $FF, $D1, $F1, $FF,$FF, $DF,$DF, $DC
.byte $DF, $FF, $F1, $A3,$61, $F1, $FF,$FF, $24
.byte $FF, $24, $FF, $24, $A3,$FF, $24, $A3,$FF
.byte $24, $2F,$2F, $FF, $24, $2F,$2F, $FF,$FF, $2F
.byte $24, $FF, $24, $2F, $FF,$FF, $F1, $A3,$61, $F1
.byte $A1

287
megademo/falling_apple.s Normal file
View File

@ -0,0 +1,287 @@
; Display Falling Apple II and message
falling_apple:
;===================
; init screen
jsr TEXT
jsr HOME
bit KEYRESET
;===================
; init vars
lda #0
sta DRAW_PAGE
;=============================
; Load graphic page0
lda #$0c
sta BASH
lda #$00
sta BASL ; load image to $c00
lda #<apple_low
sta GBASL
lda #>apple_low
sta GBASH
jsr load_rle_gr
lda #4
sta DRAW_PAGE
jsr gr_copy_to_current ; copy to page1
; GR part
bit PAGE1
bit LORES ; 4
bit SET_GR ; 4
bit FULLGR ; 4
; jsr wait_until_keypressed
;=============================
; Load graphic page1
lda #$0c
sta BASH
lda #$00
sta BASL ; load image to $c00
lda #<apple_high
sta GBASL
lda #>apple_high
sta GBASH
jsr load_rle_gr
lda #0
sta DRAW_PAGE
jsr gr_copy_to_current
; GR part
bit PAGE0
; jsr wait_until_keypressed
;==============================
; setup graphics for vapor lock
;==============================
; Clear Page0
lda #$0
sta DRAW_PAGE
lda #$44
jsr clear_gr
; Make screen half green
lda #$11
ldy #24
jsr clear_page_loop
;=====================================================
; attempt vapor lock
; by reading the "floating bus" we can see most recently
; written value of the display
; we look for $55 (which is the grey line)
;=====================================================
; See:
; Have an Apple Split by Bob Bishop
; Softalk, October 1982
; Challenges: each scan line scans 40 bytes.
; The blanking happens at the *beginning*
; So 65 bytes are scanned, starting at adress of the line - 25
; the scan takes 8 cycles, look for 4 repeats of the value
; to avoid false positive found if the horiz blanking is mirroring
; the line (max 3 repeats in that case)
vapor_lock_loop: ; first make sure we have all zeroes
LDA #$11
zxloop:
LDX #$04
wiloop:
CMP $C051
BNE zxloop
DEX
BNE wiloop
LDA #$44 ; now look for our border color (4 times)
zloop:
LDX #$04
qloop:
CMP $C051
BNE zloop
DEX
BNE qloop
; found first line of black after green, at up to line 26 on screen
; so we want roughly 22 lines * 4 = 88*65 = 5720 + 4550 = 10270
; - 65 (for the scanline we missed) = 10205 - 12 = 10193
jsr gr_copy_to_current ; 6+ 9292
; 10193 - 9298 = 895
; Fudge factor (unknown) -30 = 865
; GR part
bit LORES ; 4
bit SET_GR ; 4
bit FULLGR ; 4
; Try X=88 Y=2 cycles=893 R2
nop
ldy #2 ; 2
loopA:
ldx #88 ; 2
loopB:
dex ; 2
bne loopB ; 2nt/3
dey ; 2
bne loopA ; 2nt/3
jmp display_loop
.align $100
;================================================
; Display Loop
;================================================
; each scan line 65 cycles
; 1 cycle each byte (40cycles) + 25 for horizontal
; Total of 12480 cycles to draw screen
; Vertical blank = 4550 cycles (70 scan lines)
; Total of 17030 cycles to get back to where was
; We want to alternate between page1 and page2 every 65 cycles
; vblank = 4550 cycles to do scrolling
; 2 + 48*( (4+2+25*(2+3)) + (4+2+23*(2+3)+4+5)) + 9)
; 48*[(6+125)-1] + [(6+115+10)-1]
display_loop:
ldy #48 ; 2
outer_loop:
bit PAGE0 ; 4
ldx #25 ; 130 cycles with PAGE0 ; 2
page0_loop: ; delay 126+bit
dex ; 2
bne page0_loop ; 2/3
bit PAGE1 ; 4
ldx #23 ; 130 cycles with PAGE1 ; 2
page1_loop: ; delay 115+(7 loop)+4 (bit)+4(extra)
dex ; 2
bne page1_loop ; 2/3
nop ; 2
lda DRAW_PAGE ; 3
dey ; 2
bne outer_loop ; 2/3
;======================================================
; We have 4550 cycles in the vblank, use them wisely
;======================================================
; do_nothing should be 4550+1 -2-9 -7= 4533
jsr do_nothing ; 6
lda KEYPRESS ; 4
bpl no_keypress ; 3
jmp start_over
no_keypress:
jmp display_loop ; 3
start_over:
rts
;=================================
; do nothing
;=================================
; and take 4533-6 = 4527 cycles to do it
do_nothing:
; Try X=4 Y=174 cycles=4525 R2
nop ; 2
ldy #174 ; 2
loop1:
ldx #4 ; 2
loop2:
dex ; 2
bne loop2 ; 2nt/3
dey ; 2
bne loop1 ; 2nt/3
rts ; 6
;==================================
; HLINE
;==================================
; Color in A
; Y has which line
hline:
pha ; 3
ldx gr_offsets,y ; 4+
stx hline_loop+1 ; 4
lda gr_offsets+1,y ; 4+
clc ; 2
adc DRAW_PAGE ; 3
sta hline_loop+2 ; 4
pla ; 4
ldx #39 ; 2
hline_loop:
sta $5d0,X ; 38 ; 5
dex ; 2
bpl hline_loop ; 2nt/3
rts ; 6
;==========================
; Clear gr screen
;==========================
; Color in A
clear_gr:
ldy #46
clear_page_loop:
jsr hline
dey
dey
bpl clear_page_loop
rts
gr_offsets:
.word $400,$480,$500,$580,$600,$680,$700,$780
.word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8
.word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0
.include "../asm_routines/gr_unrle.s"
.include "gr_copy.s"
.include "apple_40_96.inc"

58
megademo/gr_copy.s Normal file
View File

@ -0,0 +1,58 @@
;=========================================================
; gr_copy_to_current, 40x48 version
;=========================================================
; copy 0xc00 to DRAW_PAGE
;
; 45 + 2 + 120*(8*9 + 5) -1 + 6 = 9292
gr_copy_to_current:
lda DRAW_PAGE ; 3
clc ; 2
adc #$4 ; 2
sta gr_copy_line+5 ; 4
sta gr_copy_line+11 ; 4
adc #$1 ; 2
sta gr_copy_line+17 ; 4
sta gr_copy_line+23 ; 4
adc #$1 ; 2
sta gr_copy_line+29 ; 4
sta gr_copy_line+35 ; 4
adc #$1 ; 2
sta gr_copy_line+41 ; 4
sta gr_copy_line+47 ; 4
;===========
; 45
ldy #119 ; for early ones, copy 120 bytes ; 2
gr_copy_line:
lda $C00,Y ; load a byte (self modified) ; 4
sta $400,Y ; store a byte (self modified) ; 5
lda $C80,Y ; load a byte (self modified) ; 4
sta $480,Y ; store a byte (self modified) ; 5
lda $D00,Y ; load a byte (self modified) ; 4
sta $500,Y ; store a byte (self modified) ; 5
lda $D80,Y ; load a byte (self modified) ; 4
sta $580,Y ; store a byte (self modified) ; 5
lda $E00,Y ; load a byte (self modified) ; 4
sta $600,Y ; store a byte (self modified) ; 5
lda $E80,Y ; load a byte (self modified) ; 4
sta $680,Y ; store a byte (self modified) ; 5
lda $F00,Y ; load a byte (self modified) ; 4
sta $700,Y ; store a byte (self modified) ; 5
lda $F80,Y ; load a byte (self modified) ; 4
sta $780,Y ; store a byte (self modified) ; 5
dey ; decrement pointer ; 2
bpl gr_copy_line ; ; 2nt/3
rts ; 6

View File

@ -26,12 +26,13 @@
;===================
; do nothing
; Loop Forever
;===================
do_nothing:
jmp do_nothing
loop_forever:
jmp loop_forever
.include "lz4_decode.s"
.include "c64_opener.s"
.include "falling_apple.s"