snake6502/src/intro1.asm

657 lines
14 KiB
NASM
Raw Permalink Normal View History

2021-11-07 17:14:59 +00:00
SEG zeropageSegment
introDestPtr WORD
2021-11-07 17:14:59 +00:00
SEG programSegment
2021-04-14 07:50:46 +00:00
introreset SUBROUTINE
jsr multicolorOff
jsr clearScreen
; Set screen colors
lda #0
sta $d020 ; overscan
sta $d021 ; center
lda #14
sta introYscroll
; for "GLGPROGRAMS" at the beginning
ldx #$78
stx introDestPtr
2021-04-14 07:50:46 +00:00
ldy #$04
sty introDestPtr + 1
2021-04-14 07:50:46 +00:00
; GLGPROGRAMS color
ldy #$00
lda #$02
.colorLoop:
sta $d800,y
sta $d900,y
sta $da00,y
sta $db00,y
dey
bne .colorLoop
; first raster interrupt line, for moustaches
lda #68+18
2021-04-14 09:24:36 +00:00
sta moustacheLine
2021-04-14 07:50:46 +00:00
rts
2021-04-13 21:19:47 +00:00
statusIntro0 SUBROUTINE
2021-11-07 15:10:02 +00:00
; arrives raster interrupt, move moustache one line below
2021-04-14 09:24:36 +00:00
inc moustacheLine
2021-04-13 21:19:47 +00:00
2021-11-07 15:10:02 +00:00
lda $d011 ; load current vertical offset from VIC-II
2021-04-13 21:19:47 +00:00
and #$07
cmp #$07
2021-11-07 15:10:02 +00:00
beq .nextline ; if 7, then it is next text line
inc $d011 ; else setup moustache interrupt to trigger next raster line...
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-11-07 15:10:02 +00:00
rts ; ...and return: my job here is done
2021-04-13 21:19:47 +00:00
.nextline:
2021-11-07 15:10:02 +00:00
lda $d011 ; reset raster offset to 0...
2021-04-13 21:19:47 +00:00
and #$f8
sta $d011
MOV_WORD_MEM dstPointer, introDestPtr
MEMSET "D", #$80, #40
2021-04-13 21:19:47 +00:00
clc ; ... move introDestPtr to next text line ...
lda introDestPtr
2021-04-13 21:19:47 +00:00
adc #40
sta introDestPtr
lda introDestPtr + 1
2021-04-13 21:19:47 +00:00
adc #0
sta introDestPtr + 1
2021-04-13 21:19:47 +00:00
MOV_WORD_MEM dstPointer, introDestPtr
MEMCPY "D", #GLGProgramsText, #200 ; ... and copy "GLG Programs" text to next text line
2021-04-13 21:19:47 +00:00
2021-11-07 15:10:02 +00:00
dec introYscroll ; remember that we are one line below
beq .next ; if we reached the end of the vertical scroll, advance status
2021-04-13 21:19:47 +00:00
2021-11-07 15:10:02 +00:00
jsr setupMoustacheInterrupt ; else just continue with the moustache
2021-04-13 21:19:47 +00:00
rts
.next:
lda #ST_INTRO1
sta status
rts
2021-04-14 07:50:46 +00:00
setupMoustacheInterrupt SUBROUTINE
2021-04-13 21:19:47 +00:00
; Store in $314 address of our custom interrupt handler
2021-04-14 07:50:46 +00:00
ldx #<.moustacheInterruptH
ldy #>.moustacheInterruptH
2021-04-13 21:19:47 +00:00
stx $314
sty $315
; Set raster beam to trigger interrupt at row
2021-04-14 09:24:36 +00:00
lda moustacheLine
2021-04-13 21:19:47 +00:00
sta $d012
rts
2021-04-14 07:50:46 +00:00
.moustacheInterruptH:
2021-11-07 15:10:02 +00:00
; "higher" moustache interrupt (on the right of the screen)
2021-04-13 21:19:47 +00:00
; +36
dec $d019 ; +42, EOI
2021-04-14 07:50:46 +00:00
lda #$02 ; +44, color
sta $d020 ; +48, color
nop ; +50, timing
nop ; +52, timing
nop ; +54, timing
bit $02 ; +57, timing
lda #$00 ; +59, color
sta $d020 ; +63, color
2021-04-13 21:19:47 +00:00
; second line, +0
inc $0800 ; + 6, timing
inc $0800 ; +12, timing
inc $0800 ; +18, timing
inc $0800 ; +24, timing
inc $0800 ; +30, timing
inc $0800 ; +36, timing
inc $0800 ; +42, timing
2021-04-14 07:50:46 +00:00
lda #$02 ; +44, color
sta $d020 ; +48, color
inc $0800 ; +54, timing
bit $02 ; +57, timing
lda #$00 ; +59, color
sta $d020 ; +63, color
2021-04-13 21:19:47 +00:00
; set raster beam low
2021-04-14 07:50:46 +00:00
ldx #<.moustacheInterruptL
ldy #>.moustacheInterruptL
2021-04-13 21:19:47 +00:00
stx $314
sty $315
clc
2021-04-14 09:24:36 +00:00
lda moustacheLine
2021-11-07 15:10:02 +00:00
adc #23 ; "lower" moustache is 23 raster lines below higher one
2021-04-13 21:19:47 +00:00
sta $d012
jmp $ea31
2021-04-14 07:50:46 +00:00
.moustacheInterruptL:
2021-11-07 15:10:02 +00:00
; "lower" moustache interrupt (on the left of the screen)
2021-04-13 21:19:47 +00:00
; +36
dec $d019 ; +42, EOI
inc $0800 ; +48, timing
inc $0800 ; +54, timing
2021-04-14 07:50:46 +00:00
lda #$02 ; +56, color
bit $0800 ; +60, timing
2021-04-13 21:19:47 +00:00
bit $02 ; +63, timing
; newline
2021-04-14 07:50:46 +00:00
sta $d020 ; + 4, color
lda #$00 ; + 6, timing
2021-04-13 21:19:47 +00:00
inc $0800 ; +12, timing
inc $0800 ; +18, timing
2021-04-14 07:50:46 +00:00
nop ; +20, timing
sta $d020 ; +24, color
lda #$02 ; +26, color
bit $0800 ; +30, timing
2021-04-13 21:19:47 +00:00
inc $0800 ; +36, timing
inc $0800 ; +42, timing
inc $0800 ; +48, timing
inc $0800 ; +54, timing
inc $0800 ; +60, timing
bit $02 ; +63, timing
; newline
2021-04-14 07:50:46 +00:00
sta $d020 ; + 4, color
lda #$00 ; + 6, color
2021-04-13 21:19:47 +00:00
inc $0800 ; +12, timing
inc $0800 ; +18, timing
2021-04-14 07:50:46 +00:00
sta $d020 ; +22, color
2021-04-13 21:19:47 +00:00
2021-11-07 15:10:02 +00:00
ldx #<irq ; restore main raster interrupt handler
2021-04-13 21:19:47 +00:00
ldy #>irq
stx $314
sty $315
lda #$00
sta $d012
jmp $ea31
2021-11-07 15:10:02 +00:00
GLGProgramsText: ; fancy PETSCII-looking brand name
2021-04-13 21:19:47 +00:00
BYTE #$80,#$80,#$80,#$80,#$80,#$80,#$80,#$f0,#$f4,#$80,#$80,#$80,#$f0,#$f4,#$80,#$80,#$f0,#$f4,#$f1,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80
BYTE #$80,#$80,#$80,#$80,#$80,#$80,#$80,#$f5,#$80,#$80,#$f5,#$80,#$f5,#$80,#$80,#$80,#$f5,#$80,#$f5,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$f1,#$80,#$80,#$80,#$f0,#$f4,#$f4,#$f4,#$f4,#$f4,#$f4,#$f4,#$f4,#$f4
BYTE #$80,#$80,#$80,#$80,#$80,#$80,#$80,#$f5,#$80,#$f5,#$f5,#$80,#$f5,#$80,#$f5,#$80,#$fd,#$f4,#$f3,#$f0,#$f0,#$f1,#$f0,#$f1,#$f0,#$f0,#$fc,#$f0,#$fb,#$f1,#$f2,#$f1,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80
BYTE #$80,#$80,#$80,#$80,#$80,#$80,#$80,#$f2,#$f4,#$fc,#$f2,#$f4,#$f2,#$f4,#$fc,#$80,#$f5,#$80,#$80,#$f5,#$f2,#$f3,#$f2,#$fc,#$f5,#$f2,#$f3,#$f5,#$f5,#$f5,#$f4,#$f3,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80
BYTE #$f4,#$f4,#$f4,#$f4,#$f4,#$f4,#$f4,#$f4,#$f4,#$fa,#$f4,#$f4,#$f4,#$f4,#$f3,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$f3,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80,#$80
statusIntro1 SUBROUTINE
2021-11-07 15:10:02 +00:00
; continue moving moustaches down, up to 4 raster lines (middle of text)
lda $d011
2021-04-13 21:19:47 +00:00
and #$07
cmp #$04
2021-11-07 15:10:02 +00:00
beq .next ; if interrupt is in the middle, don't move it anymore, and...
2021-04-13 21:19:47 +00:00
inc $d011
2021-04-14 09:24:36 +00:00
inc moustacheLine
2021-04-13 21:19:47 +00:00
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 21:19:47 +00:00
rts
.next:
2021-11-07 15:10:02 +00:00
jsr setupMoustacheInterrupt ; ... always remember to display moustache, anyhow ...
2021-04-13 21:19:47 +00:00
2021-11-07 15:10:02 +00:00
lda counter ; wait for song synchronization up to interrupt $0080
2021-04-13 21:19:47 +00:00
cmp #$80
bne .end
lda counter + 1
cmp #$00
bne .end
2021-04-14 07:50:46 +00:00
ldy #$0
lda #$07
.colorLoop:
sta $d940,y
iny
cpy #200
bne .colorLoop
2021-04-13 21:19:47 +00:00
lda #ST_INTRO2
sta status
.end:
rts
statusIntro2 SUBROUTINE
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 21:19:47 +00:00
; "RETROFFICINA"
lda #<introStringA1
sta srcStringPointer
lda #>introStringA1
sta srcStringPointer + 1
2021-04-14 07:50:46 +00:00
lda #$48
2021-04-13 21:19:47 +00:00
sta dstScreenPointer
lda #$05
sta dstScreenPointer + 1
jsr printString
lda counter
cmp #$08
bne .end
lda counter + 1
cmp #$01
bne .end
lda #ST_INTRO3
sta status
.end:
rts
statusIntro3 SUBROUTINE
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 21:19:47 +00:00
; "AND"
lda #<introStringA2
sta srcStringPointer
lda #>introStringA2
sta srcStringPointer + 1
2021-04-14 07:50:46 +00:00
lda #$a5
2021-04-13 21:19:47 +00:00
sta dstScreenPointer
lda #$05
sta dstScreenPointer + 1
jsr printString
lda counter
cmp #$86
bne .end
lda counter + 1
cmp #$01
bne .end
lda #ST_INTRO4
sta status
.end:
rts
statusIntro4 SUBROUTINE
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 21:19:47 +00:00
; "GIOMBA"
lda #<introStringA3
sta srcStringPointer
lda #>introStringA3
sta srcStringPointer + 1
2021-04-14 07:50:46 +00:00
lda #$f9
2021-04-13 21:19:47 +00:00
sta dstScreenPointer
lda #$05
sta dstScreenPointer + 1
jsr printString
lda counter
2021-04-13 22:30:42 +00:00
cmp #$08
2021-04-13 21:19:47 +00:00
bne .end
lda counter + 1
2021-04-13 22:30:42 +00:00
cmp #$02
2021-04-13 21:19:47 +00:00
bne .end
2021-04-13 22:30:42 +00:00
MEMSET #$540, #$80, #200
2021-04-13 22:30:42 +00:00
lda #ST_INTRO5
sta status
.end:
rts
statusIntro5 SUBROUTINE
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 22:30:42 +00:00
; "PRESENT"
lda #<introStringA4
sta srcStringPointer
lda #>introStringA4
sta srcStringPointer + 1
lda #$50
sta dstScreenPointer
lda #$05
sta dstScreenPointer + 1
jsr printString
lda counter
cmp #$80
bne .end
lda counter + 1
cmp #$02
bne .end
lda #ST_INTRO6
sta status
.end:
rts
statusIntro6 SUBROUTINE
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 22:30:42 +00:00
; "A COMMODORE 64"
lda #<introStringA5
sta srcStringPointer
lda #>introStringA5
sta srcStringPointer + 1
lda #$9d
sta dstScreenPointer
lda #$05
sta dstScreenPointer + 1
jsr printString
lda counter
cmp #$08
bne .end
lda counter + 1
cmp #$03
bne .end
lda #ST_INTRO7
sta status
.end:
rts
statusIntro7 SUBROUTINE
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 22:30:42 +00:00
; "VIDEOGAME"
lda #<introStringA6
sta srcStringPointer
lda #>introStringA6
sta srcStringPointer + 1
lda #$ef
sta dstScreenPointer
lda #$05
sta dstScreenPointer + 1
jsr printString
lda counter
cmp #$80
bne .end
lda counter + 1
cmp #$03
bne .end
lda #ST_INTRO8
sta status
.end:
rts
statusIntro8 SUBROUTINE
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 22:30:42 +00:00
; blank wait
lda counter
cmp #$16
bne .end
lda counter + 1
cmp #$04
bne .end
lda #ST_MENURESET
2021-04-13 21:19:47 +00:00
sta status
.end:
rts
statusMenuReset SUBROUTINE
2021-04-13 22:30:42 +00:00
lda #$05
ldy #$0
.lastlineColorLoop:
sta $db98,y
iny
cpy #80
bne .lastlineColorLoop
2021-11-07 15:10:02 +00:00
; Print Game Title: big "SNAKE"
MEMSET #$d800, #$02, #280 ; color
MEMCPY #$400, #SnakeText, #280 ; text
2021-04-15 12:33:29 +00:00
; Print PETSCII GLG Programs
MEMSET #($6a8 + $d800 - $400), #$02, #200 ; color
MEMCPY #$6a8, #GLGProgramsText, #200 ; text
2021-04-13 21:19:47 +00:00
; Print website
lda #<intro2string ; lsb of string address
sta srcStringPointer ; put into lsb of source pointer
lda #>intro2string ; do the same for msb of string address
sta srcStringPointer + 1 ; put into msb of source pointer
lda #$9e ; this is lsb of address of 23th line
sta dstScreenPointer ; put into lsb of dest pointer
lda #$07 ; do the same for msb of adress of 20th line
sta dstScreenPointer + 1 ; put into msb of dest pointer
2021-04-15 12:33:29 +00:00
jsr printString ; print
2021-04-13 21:19:47 +00:00
; Print Copyright
lda #<intro3string ; the assembly is the same as above,
sta srcStringPointer ; just change string to be printed
lda #>intro3string ; and line (24th line)
sta srcStringPointer + 1
lda #$ce
sta dstScreenPointer
lda #$07
sta dstScreenPointer + 1
jsr printString
2021-11-07 15:10:02 +00:00
; boat-shaped horizontal line (rounded edges toward the top)
; this overwrites the "present" word from the intro
lda #$f2 ; 3rd quadrant
2021-04-15 12:33:29 +00:00
sta $540
2021-11-07 15:10:02 +00:00
lda #$f3 ; 4th quadrant
2021-04-15 12:33:29 +00:00
sta $567
2021-11-07 15:10:02 +00:00
lda #$07 ; color for edges
sta $540+$d800-$400
sta $567+$d800-$400
2021-04-15 12:33:29 +00:00
ldy #$1
2021-11-07 15:10:02 +00:00
.boatLineLoop:
lda #$f4 ; horizontal line
2021-04-15 12:33:29 +00:00
sta $540,y
2021-11-07 15:10:02 +00:00
lda #$07
sta $540+$d800-$400,y
2021-04-15 12:33:29 +00:00
iny
cpy #39
2021-11-07 15:10:02 +00:00
bne .boatLineLoop
2021-04-15 12:33:29 +00:00
lda #$05
sta XCharOffset
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt ; never forget the magic moustaches
2021-04-13 21:19:47 +00:00
lda #ST_MENU
sta status
rts
2021-04-15 12:33:29 +00:00
SnakeText:
HEX 80 80 80 80 80 80 80 80 f6 a0 a0 f9 80 f7 80 80 f6 80 f6 a0 a0 f7 80 f7 80 80 80 f6 a0 a0 f9 80 80 80 80 80 80 80 80 80
HEX 80 80 80 80 80 80 80 80 a0 80 80 80 80 a0 f7 80 a0 80 a0 80 80 a0 80 a0 f6 f7 80 a0 80 80 80 80 80 80 80 80 80 80 80 80
HEX 80 80 80 80 80 80 80 80 a0 80 80 80 80 a0 a0 f7 a0 80 a0 80 80 a0 80 a0 a0 f9 80 a0 80 80 80 80 80 80 80 80 80 80 80 80
HEX 80 80 80 80 80 80 80 80 f8 a0 a0 f7 80 a0 f8 a0 a0 80 a0 a0 a0 a0 80 a0 f9 80 80 a0 a0 80 80 80 80 80 80 80 80 80 80 80
HEX 80 80 80 80 80 80 80 80 80 80 80 a0 80 a0 80 f8 a0 80 a0 80 80 a0 80 a0 f7 80 80 a0 80 80 80 80 80 80 80 80 80 80 80 80
HEX 80 80 80 80 80 80 80 80 80 80 80 a0 80 a0 80 80 a0 80 a0 80 80 a0 80 a0 a0 f7 80 a0 80 80 80 80 80 80 80 80 80 80 80 80
HEX 80 80 80 80 80 80 80 80 f6 a0 a0 f9 80 f8 80 80 f8 80 f9 80 80 f8 80 a0 f8 f9 80 f8 a0 a0 f7 80 80 80 80 80 80 80 80 80
2021-11-07 17:14:59 +00:00
;ParabolicSpaceChars:
; HEX 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 00 01 00 00 00 00 01 00 00 00 00 00 01 00 00 00 00 00 01 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
;ParabolicSpaceScroll:
; HEX 00 01 01 01 01 01 01 01 02 02 02 03 03 04 04 05 06 06 07 00 00 01 02 03 04 05 06 07 00 01 02 04 05 06 00 01 02 04 05 07 00 02 04 05 07 00 01 03 04 06 00 01 03 04 06 07 00 02 03 04 06 07 00 01 02 03 04 05 06 07 00 01 02 02 03 04 04 05 05 06 06 06 07 06 07 07 07 07 07 07 07
2021-04-15 12:33:29 +00:00
setupXScrollInterrupt SUBROUTINE
ldx #<XScrollInterruptH
ldy #>XScrollInterruptH
stx $314
sty $315
2021-04-15 12:33:29 +00:00
; Set raster beam to trigger interrupt at row
lda #42
sta $d012
rts
XScrollInterruptH SUBROUTINE
2021-11-07 15:10:02 +00:00
2021-04-15 12:33:29 +00:00
lda $d016
and #$f8
ora XScrollOffset
sta $d016
dec $d019
ldx #<XScrollInterruptL
ldy #>XScrollInterruptL
stx $314
sty $315
lda #110
sta $d012
jmp $ea31
XScrollInterruptL SUBROUTINE
lda $d016
and #$f8
sta $d016
dec $d019
ldx #<XScrollInterruptMoveAll
ldy #>XScrollInterruptMoveAll
stx $314
sty $315
lda #120
sta $d012
jmp $ea31
XScrollInterruptMoveAll SUBROUTINE
dec $d019 ; EOI
tsx
dex
2021-04-15 12:33:29 +00:00
lda XCharOffset
asl
asl
asl
sta $100,x
lda $d016
and #$07
ora $100,x
inx
txs
cmp #78
2021-04-15 12:33:29 +00:00
bcs .isEdge
cmp #3
2021-04-15 12:33:29 +00:00
bcc .isEdge
cmp #70
bcs .isMiddle
cmp #10
bcc .isMiddle
2021-04-15 12:33:29 +00:00
jmp .enter
.isMiddle:
2021-04-15 12:33:29 +00:00
lda counter
and #$01
beq .enter
jmp .next
.isEdge:
lda counter
and #$03
2021-04-15 12:33:29 +00:00
beq .enter ; ah, some good spaghetti code to accomodate for far branch
jmp .next ; bounce slower
.isCenter:
2021-04-15 12:33:29 +00:00
.enter:
lda XScrollDirection
and #$01
bne .goRight
.goLeft:
dec XScrollOffset
lda XScrollOffset
and #$07
cmp #$07
beq .continue1
jmp .next
.continue1:
lda #$07
sta XScrollOffset
.moveEverythingLeft:
dec XCharOffset
ldy #0
.loop1:
lda $401,y
sta $400,y
lda $429,y
sta $428,y
lda $451,y
sta $450,y
lda $479,y
sta $478,y
lda $4a1,y
sta $4a0,y
lda $4c9,y
sta $4c8,y
lda $4f1,y
sta $4f0,y
iny
cpy #38
bne .loop1
lda XCharOffset
cmp #0
bne .next
lda #$01
sta XScrollDirection
jmp .next
.goRight:
inc XScrollOffset
lda XScrollOffset
and #$07
cmp #$00
bne .next
lda #$00
sta XScrollOffset
.moveEverythingRight:
inc XCharOffset
ldy #38
.loop2:
lda $400,y
sta $401,y
lda $428,y
sta $429,y
lda $450,y
sta $451,y
lda $478,y
sta $479,y
lda $4a0,y
sta $4a1,y
lda $4c8,y
sta $4c9,y
lda $4f0,y
sta $4f1,y
dey
bne .loop2
lda XCharOffset
cmp #10
bne .next
lda #$00
sta XScrollOffset
lda #$00
sta XScrollDirection
.next:
jsr setupMoustacheInterrupt
jmp $ea31
statusMenu SUBROUTINE
jsr setupXScrollInterrupt
rts