2018-07-18 13:27:26 +00:00
|
|
|
; Kansasfest HackFest Entry
|
|
|
|
|
2018-07-19 00:01:06 +00:00
|
|
|
; Zero Page
|
|
|
|
DRAW_PAGE = $EE
|
2018-07-19 01:39:36 +00:00
|
|
|
CURRENT_OFFSET = $EF
|
2018-07-19 00:01:06 +00:00
|
|
|
|
2018-07-18 21:13:33 +00:00
|
|
|
; Soft Switches
|
|
|
|
|
|
|
|
SET_GR = $C050 ; Enable graphics
|
|
|
|
FULLGR = $C052 ; Full screen, no text
|
2018-07-19 20:48:59 +00:00
|
|
|
PAGE0 = $C054 ; Page0
|
|
|
|
PAGE1 = $C055 ; Page1
|
2018-07-18 21:13:33 +00:00
|
|
|
LORES = $C056 ; Enable LORES graphics
|
|
|
|
|
|
|
|
|
|
|
|
; ROM routines
|
|
|
|
|
2018-07-18 13:40:37 +00:00
|
|
|
TEXT = $FB36 ;; Set text mode
|
|
|
|
HOME = $FC58 ;; Clear the text screen
|
2018-07-19 01:39:36 +00:00
|
|
|
WAIT = $FCA8 ;; delay 1/2(26+27A+5A^2) us
|
2018-07-18 13:27:26 +00:00
|
|
|
|
2018-07-18 21:13:33 +00:00
|
|
|
|
2018-07-18 13:27:26 +00:00
|
|
|
;===================
|
|
|
|
; init screen
|
|
|
|
|
2018-07-18 13:40:37 +00:00
|
|
|
jsr TEXT
|
|
|
|
jsr HOME
|
2018-07-18 13:27:26 +00:00
|
|
|
|
2018-07-19 00:01:06 +00:00
|
|
|
lda #0
|
|
|
|
sta DRAW_PAGE
|
2018-07-19 01:39:36 +00:00
|
|
|
sta CURRENT_OFFSET
|
2018-07-19 00:01:06 +00:00
|
|
|
|
|
|
|
; Clear Page0
|
|
|
|
lda #$00
|
2018-07-19 00:09:23 +00:00
|
|
|
sta DRAW_PAGE
|
|
|
|
jsr clear_gr
|
2018-07-19 00:01:06 +00:00
|
|
|
|
2018-07-19 00:09:23 +00:00
|
|
|
; draw border line
|
2018-07-19 00:01:06 +00:00
|
|
|
|
|
|
|
lda #$55
|
|
|
|
ldy #38
|
|
|
|
jsr hline
|
|
|
|
|
2018-07-19 00:09:23 +00:00
|
|
|
; Clear Page1
|
|
|
|
lda #$4
|
|
|
|
sta DRAW_PAGE
|
2018-07-20 00:04:32 +00:00
|
|
|
lda #$44
|
2018-07-19 00:09:23 +00:00
|
|
|
jsr clear_gr
|
2018-07-18 21:13:33 +00:00
|
|
|
|
2018-07-19 00:09:23 +00:00
|
|
|
; draw border line
|
2018-07-18 21:13:33 +00:00
|
|
|
|
2018-07-19 00:09:23 +00:00
|
|
|
lda #$55
|
|
|
|
ldy #38
|
|
|
|
jsr hline
|
2018-07-18 21:13:33 +00:00
|
|
|
|
2018-07-20 00:04:32 +00:00
|
|
|
; temporarily draw HELLO
|
|
|
|
|
|
|
|
ldy CURRENT_OFFSET
|
|
|
|
ldx #0
|
|
|
|
data_loop2:
|
|
|
|
lda words,Y
|
|
|
|
sta $6d0,X
|
|
|
|
|
|
|
|
lda words2,Y
|
|
|
|
sta $750,X
|
|
|
|
|
|
|
|
lda words3,Y
|
|
|
|
sta $ad0,X
|
|
|
|
|
|
|
|
lda words4,Y
|
|
|
|
sta $b50,X
|
|
|
|
|
|
|
|
iny
|
|
|
|
inx
|
|
|
|
cpx #40
|
|
|
|
bne data_loop2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-19 01:01:58 +00:00
|
|
|
;=====================================================
|
|
|
|
; 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 #$00
|
|
|
|
zxloop:
|
|
|
|
LDX #$04
|
|
|
|
wiloop:
|
|
|
|
CMP $C051
|
|
|
|
BNE zxloop
|
|
|
|
DEX
|
|
|
|
BNE wiloop
|
|
|
|
|
|
|
|
LDA #$55 ; now look for four all grey
|
|
|
|
zloop:
|
|
|
|
LDX #$04
|
|
|
|
qloop:
|
|
|
|
CMP $C051
|
|
|
|
BNE zloop
|
|
|
|
DEX
|
|
|
|
BNE qloop
|
|
|
|
|
|
|
|
; found first line of low-res grey, need to kill time
|
|
|
|
; until we can enter at top of screen
|
|
|
|
; so we want roughly 5200+4550 - 65 (for the scanline we missed)
|
|
|
|
|
|
|
|
|
|
|
|
; GR part
|
|
|
|
bit LORES
|
|
|
|
bit SET_GR
|
|
|
|
bit FULLGR
|
|
|
|
|
|
|
|
|
|
|
|
; want 9685
|
|
|
|
; Try X=34 Y=55 cycles=9681
|
|
|
|
|
|
|
|
lda #0 ; 2
|
|
|
|
lda #0 ; 2
|
|
|
|
|
|
|
|
ldy #55 ; 2
|
|
|
|
loopA:
|
|
|
|
ldx #34 ; 2
|
|
|
|
loopB:
|
|
|
|
dex ; 2
|
|
|
|
bne loopB ; 2nt/3
|
|
|
|
|
|
|
|
dey ; 2
|
|
|
|
bne loopA ; 2nt/3
|
|
|
|
|
|
|
|
jmp display_loop
|
|
|
|
.align $100
|
|
|
|
|
|
|
|
|
2018-07-19 20:48:59 +00:00
|
|
|
;================================================
|
|
|
|
; 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
|
2018-07-19 01:01:58 +00:00
|
|
|
|
2018-07-20 00:04:32 +00:00
|
|
|
|
|
|
|
; 2 + 48*( (4+2+25*(2+3)) + (4+2+23*(2+3)+4+5)) + 9)
|
|
|
|
; 48*[(6+125)-1] + [(6+115+10)-1]
|
|
|
|
|
2018-07-19 01:01:58 +00:00
|
|
|
display_loop:
|
2018-07-19 01:39:36 +00:00
|
|
|
|
2018-07-20 00:04:32 +00:00
|
|
|
ldy #48 ; 2
|
2018-07-19 20:48:59 +00:00
|
|
|
|
|
|
|
outer_loop:
|
|
|
|
|
2018-07-20 00:04:32 +00:00
|
|
|
bit PAGE0 ; 4
|
2018-07-19 20:48:59 +00:00
|
|
|
ldx #25 ; 130 cycles with PAGE0 ; 2
|
2018-07-20 00:04:32 +00:00
|
|
|
page0_loop: ; delay 126+bit
|
2018-07-19 20:48:59 +00:00
|
|
|
dex ; 2
|
|
|
|
bne page0_loop ; 2/3
|
|
|
|
|
2018-07-20 00:04:32 +00:00
|
|
|
|
|
|
|
bit PAGE1 ; 4
|
|
|
|
ldx #23 ; 130 cycles with PAGE1 ; 2
|
|
|
|
page1_loop: ; delay 115+(7 loop)+4 (bit)+4(extra)
|
2018-07-19 20:48:59 +00:00
|
|
|
dex ; 2
|
|
|
|
bne page1_loop ; 2/3
|
2018-07-20 00:04:32 +00:00
|
|
|
|
|
|
|
nop ; 2
|
|
|
|
lda DRAW_PAGE ; 3
|
2018-07-19 20:48:59 +00:00
|
|
|
|
|
|
|
dey ; 2
|
|
|
|
bne outer_loop ; 2/3
|
|
|
|
|
2018-07-20 00:04:32 +00:00
|
|
|
|
2018-07-19 20:48:59 +00:00
|
|
|
|
|
|
|
; We have 4550 cycles in the vblank, use them wisely
|
|
|
|
|
2018-07-20 00:04:32 +00:00
|
|
|
; delay 4546 (+1 from loop falltrough, -2 for loadup, -3 for jmp)
|
|
|
|
|
|
|
|
; 4540 = x=9,y=89
|
|
|
|
|
|
|
|
; kill 3 cycles
|
|
|
|
lda DRAW_PAGE ; 3
|
|
|
|
lda DRAW_PAGE ; 3
|
|
|
|
|
|
|
|
ldy #89 ; 2
|
|
|
|
loop5:
|
|
|
|
ldx #9 ; 2
|
|
|
|
loop6:
|
|
|
|
dex ; 2
|
|
|
|
bne loop6 ; 2nt/3
|
|
|
|
|
|
|
|
dey ; 2
|
|
|
|
bne loop5 ; 2nt/3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jmp display_loop ; 3
|
|
|
|
|
2018-07-19 20:48:59 +00:00
|
|
|
|
2018-07-19 01:39:36 +00:00
|
|
|
ldy CURRENT_OFFSET
|
|
|
|
ldx #0
|
|
|
|
data_loop:
|
|
|
|
lda words,Y
|
|
|
|
sta $6d0,X
|
|
|
|
|
|
|
|
lda words2,Y
|
|
|
|
sta $750,X
|
|
|
|
|
|
|
|
lda words3,Y
|
|
|
|
sta $ad0,X
|
|
|
|
|
|
|
|
lda words4,Y
|
|
|
|
sta $b50,X
|
|
|
|
|
|
|
|
iny
|
|
|
|
inx
|
|
|
|
cpx #40
|
|
|
|
bne data_loop
|
|
|
|
|
|
|
|
inc CURRENT_OFFSET
|
|
|
|
|
|
|
|
lda #128
|
|
|
|
jsr WAIT
|
|
|
|
|
|
|
|
jmp display_loop
|
2018-07-18 21:13:33 +00:00
|
|
|
|
2018-07-18 13:27:26 +00:00
|
|
|
|
2018-07-19 00:01:06 +00:00
|
|
|
;==================================
|
|
|
|
; HLINE
|
|
|
|
;==================================
|
|
|
|
|
|
|
|
; Color in A
|
2018-07-19 01:39:36 +00:00
|
|
|
; Y has which line
|
2018-07-19 00:01:06 +00:00
|
|
|
hline:
|
2018-07-19 00:09:23 +00:00
|
|
|
pha ; 3
|
2018-07-19 00:01:06 +00:00
|
|
|
ldx gr_offsets,y ; 4+
|
|
|
|
stx hline_loop+1 ; 4
|
2018-07-19 00:09:23 +00:00
|
|
|
lda gr_offsets+1,y ; 4+
|
|
|
|
clc ; 2
|
|
|
|
adc DRAW_PAGE ; 3
|
|
|
|
sta hline_loop+2 ; 4
|
|
|
|
pla ; 4
|
2018-07-19 00:01:06 +00:00
|
|
|
ldx #39 ; 2
|
|
|
|
hline_loop:
|
|
|
|
sta $5d0,X ; 38 ; 5
|
|
|
|
dex ; 2
|
|
|
|
bpl hline_loop ; 2nt/3
|
|
|
|
rts ; 6
|
|
|
|
|
2018-07-19 00:09:23 +00:00
|
|
|
;==========================
|
|
|
|
; Clear gr screen
|
|
|
|
;==========================
|
|
|
|
; Color in A
|
|
|
|
clear_gr:
|
|
|
|
ldy #46
|
|
|
|
clear_page_loop:
|
|
|
|
jsr hline
|
|
|
|
dey
|
|
|
|
dey
|
|
|
|
bpl clear_page_loop
|
|
|
|
rts
|
2018-07-19 00:01:06 +00:00
|
|
|
|
2018-07-19 01:39:36 +00:00
|
|
|
.align $100
|
|
|
|
words:
|
2018-07-18 21:13:33 +00:00
|
|
|
; H E L L O
|
2018-07-20 00:53:04 +00:00
|
|
|
.byte $D1,$00,$D1,$00, $D1,$01,$00, $D1,$00,$00, $D1,$00,$00, $D0,$01,$D0,$00, $00, $00
|
|
|
|
; K F E S T
|
|
|
|
.byte $D1,$00,$D1,$00, $D1,$01,$00, $D1,$01,$00, $D1,$D1,$00, $01,$D1,$01,$00
|
|
|
|
; 1 8 . . .
|
|
|
|
.byte $00,$D1,$00, $D0,$01,$D0,$00, $00,$00,$00, $00,$00,$00, $00,$00,$00, $00,$00
|
|
|
|
|
|
|
|
.repeat 202
|
2018-07-19 01:39:36 +00:00
|
|
|
.byte $0
|
|
|
|
.endrep
|
|
|
|
words2:
|
2018-07-20 00:53:04 +00:00
|
|
|
.byte $24,$04,$24,$00, $24,$20,$00, $24,$20,$00, $24,$20,$00, $04,$20,$04,$00, $00,$00
|
|
|
|
.byte $24,$04,$20,$00, $24,$00,$00, $24,$20,$00, $20,$24,$00, $00,$24,$00,$00
|
|
|
|
.byte $00,$24,$00, $04,$20,$04,$00, $20,$20,$00, $20,$20,$00, $20,$20,$00, $00,$00
|
|
|
|
.repeat 202
|
2018-07-19 01:39:36 +00:00
|
|
|
.byte $0
|
|
|
|
.endrep
|
|
|
|
words3:
|
2018-07-20 00:53:04 +00:00
|
|
|
.byte $C9,$C0,$C9,$00, $C9,$C0,$00, $C9,$00,$00, $C9,$00,$00, $C9,$00,$C9,$00, $00,$00
|
|
|
|
.byte $C9,$C0,$09,$00, $C9,$C0,$00, $C9,$C0,$00, $C9,$C0,$00, $00,$C9,$00,$00
|
|
|
|
.byte $09,$C9,$00, $09,$C0,$09,$00, $00,$00,$00, $00,$00,$00, $00,$00,$00, $00,$00
|
|
|
|
.repeat 202
|
2018-07-19 01:39:36 +00:00
|
|
|
.byte $0
|
|
|
|
.endrep
|
|
|
|
words4:
|
2018-07-20 00:53:04 +00:00
|
|
|
.byte $06,$00,$06,$00, $06,$00,$00, $06,$00,$00, $06,$00,$00, $06,$00,$06,$00, $00,$00
|
|
|
|
.byte $06,$00,$06,$00, $06,$00,$00, $06,$00,$00, $00,$06,$00, $00,$06,$00,$00
|
|
|
|
.byte $00,$06,$00, $06,$00,$06,$00, $06,$06,$00, $06,$06,$00, $06,$06,$00, $00,$00
|
|
|
|
.repeat 202
|
2018-07-19 01:39:36 +00:00
|
|
|
.byte $0
|
|
|
|
.endrep
|
|
|
|
|
2018-07-19 00:01:06 +00:00
|
|
|
|
2018-07-20 00:53:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-07-19 00:01:06 +00:00
|
|
|
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
|