snake6502/src/intro1.asm

659 lines
12 KiB
NASM
Raw Normal View History

2020-09-15 12:57:10 +00:00
#if VERBOSE = 1
LASTINIT SET .
#endif
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 dstPointer
ldy #$04
sty dstPointer + 1
; 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+19
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
lda introYscroll
.enter:
2021-04-14 09:24:36 +00:00
inc moustacheLine
2021-04-13 21:19:47 +00:00
lda $d011
and #$07
cmp #$07
beq .nextline
inc $d011
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 21:19:47 +00:00
rts
.nextline:
lda $d011
and #$f8
sta $d011
ldy #0
lda #$80
.clearLineLoop:
sta (dstPointer),y
iny
cpy #40
bne .clearLineLoop
clc
lda dstPointer
adc #40
sta dstPointer
lda dstPointer + 1
adc #0
sta dstPointer + 1
ldy #$00
.glgLoop:
lda GLGProgramsText,y
sta (dstPointer),y
iny
cpy #200
bne .glgLoop
dec introYscroll
beq .next
2021-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
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-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-04-13 21:19:47 +00:00
adc #23
sta $d012
jmp $ea31
2021-04-14 07:50:46 +00:00
.moustacheInterruptL:
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
ldx #<irq
ldy #>irq
stx $314
sty $315
lda #$00
sta $d012
jmp $ea31
GLGProgramsText:
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
lda $d011
and #$07
cmp #$04
beq .next
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-04-14 07:50:46 +00:00
jsr setupMoustacheInterrupt
2021-04-13 21:19:47 +00:00
lda counter
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
lda #$80
ldy #$0
.loop:
sta $540,y
iny
cpy #200
bne .loop
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-04-15 12:33:29 +00:00
; Print Game Title
lda #$00
sta dstPointer
lda #$04
sta dstPointer + 1
; Print big "SNAKE"
ldx #<SnakeText
ldy #>SnakeText
stx srcPointer
sty srcPointer + 1
ldy #$00
.SnakeTitleLoop:
lda (srcPointer),y
sta (dstPointer),y
inc srcPointer
bne .noinc1
inc srcPointer + 1
.noinc1:
inc dstPointer
bne .noinc2
inc dstPointer + 1
.noinc2:
lda dstPointer
cmp #$18
bne .SnakeTitleLoop
lda dstPointer + 1
cmp #$05
bne .SnakeTitleLoop
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-04-15 12:33:29 +00:00
lda #$f2
sta $540
lda #$f3
sta $567
ldy #$1
lda #$f4
.cancelPresent:
sta $540,y
iny
cpy #39
bne .cancelPresent
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
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
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
lda XCharOffset
cmp #9
bcs .isEdge
cmp #2
bcc .isEdge
jmp .enter
.isEdge:
lda counter
and #$01
beq .enter ; ah, some good spaghetti code to accomodate for far branch
jmp .next ; bounce slower
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
2020-09-15 12:57:10 +00:00
#if VERBOSE = 1
ECHO "intro1.asm @ ",LASTINIT,"len:",(. - LASTINIT)
#endif