215 lines
3.3 KiB
NASM
215 lines
3.3 KiB
NASM
;;; -*- Mode: asm; indent-tabs-mode: t; tab-width: 8 -*-
|
|
|
|
init:
|
|
;; Set our custom NMI vector so that pressing restore quits
|
|
lda #<nmi
|
|
sta $0318
|
|
lda #>nmi
|
|
sta $0319
|
|
|
|
;; Reset gamemode
|
|
lda #mode::StartScreen
|
|
sta gamemode
|
|
|
|
;; Reset variables
|
|
lda #0
|
|
sta p1score
|
|
sta p2score
|
|
sta p1y
|
|
sta p2y
|
|
sta exit
|
|
lda #64
|
|
sta ball_x
|
|
sta ball_y
|
|
|
|
|
|
sei ;turn off IRQ while setting up
|
|
|
|
lda #$7f
|
|
sta CIA_ICR ;disable CIA IRQ
|
|
bit CIA_ICR ;acknowledge it
|
|
|
|
;; Set up our graphics
|
|
ldx #$00
|
|
stx BGCOL0 ;black background, appropriate for pong
|
|
stx BORDER
|
|
|
|
jsr loadtitlescreen
|
|
|
|
lda #%00000111
|
|
sta SPRITE_ENABLE ;enable sprite 0,1,2
|
|
sta SSCOL
|
|
sta SPRITE_BG_PRIO
|
|
lda #%00000011
|
|
sta SPRITE_XPAND_Y
|
|
lda #$01
|
|
sta SPRITE_0C
|
|
sta SPRITE_1C
|
|
sta SPRITE_2C
|
|
|
|
lda #%00000010
|
|
sta SPRITE_X_MSB
|
|
lda #$18
|
|
sta SPRITE_0X
|
|
lda #$50
|
|
sta SPRITE_1X
|
|
|
|
lda #$32
|
|
sta SPRITE_0Y
|
|
sta SPRITE_1Y
|
|
|
|
lda #$64
|
|
sta SPRITE_2X
|
|
sta SPRITE_2Y
|
|
|
|
;; Load sprites
|
|
;; Note: breaks if we have more than 255 bytes of sprite gfx
|
|
ldx #(sprite_data_end - sprite_data) ;DANGER
|
|
ldy #$00
|
|
@loadloop:
|
|
lda sprite_data,y
|
|
sta SPRITEBASE,y
|
|
iny
|
|
dex
|
|
bne @loadloop
|
|
;; done when X is zero
|
|
|
|
;; lda #<scorestr
|
|
;; sta z:zscratch0
|
|
;; lda #>scorestr
|
|
;; sta z:zscratch1
|
|
;; ldx #4
|
|
;; jsr printstr
|
|
|
|
;; Set up our own IRQ routine
|
|
lda #<irq
|
|
sta CINV
|
|
lda #>irq
|
|
sta CINV+1
|
|
|
|
ldx #$0
|
|
stx RASTER ;trigger IRQ on scanline 0 (vblank)
|
|
ldx #%00000101 ;raster & sprite-sprite col IRQs
|
|
stx VICINTMASK ;enable VIC IRQ
|
|
|
|
cli ;turn IRQ back on, we're ready
|
|
idle:
|
|
jmp idle ;do nothing forever, game is driven by IRQ
|
|
|
|
nmi:
|
|
brk
|
|
|
|
clearscreen:
|
|
;; Let's clear the background
|
|
lda #<VMBASE
|
|
sta z:zscratch0
|
|
lda #>VMBASE
|
|
sta z:zscratch1
|
|
lda #<COLORMEM
|
|
sta z:zscratch2
|
|
lda #>COLORMEM
|
|
sta z:zscratch3
|
|
ldx #$04
|
|
@loopouter:
|
|
ldy #$00
|
|
@loopinner:
|
|
lda #$20
|
|
sta (zscratch0),y
|
|
lda #$01 ;write the color white
|
|
sta (zscratch2),y ;to every part of color RAM
|
|
iny
|
|
bne @loopinner
|
|
inc z:zscratch1 ;increment page
|
|
inc z:zscratch3
|
|
dex
|
|
bne @loopouter
|
|
|
|
;; Set up sprites
|
|
;; sprite ptr $d0 = memory location $3400
|
|
ldx #$d0
|
|
stx VMBASE+($400 - 8)
|
|
stx VMBASE+($400 - 7)
|
|
inx
|
|
stx VMBASE+($400 - 6)
|
|
|
|
rts
|
|
|
|
loadtitlescreen:
|
|
jsr clearscreen
|
|
|
|
lda #<title
|
|
sta z:zscratch0
|
|
lda #>title
|
|
sta z:zscratch1
|
|
|
|
ldx #$0a
|
|
ldy #$0b
|
|
jsr printstr
|
|
|
|
lda #<credits
|
|
sta z:zscratch0
|
|
lda #>credits
|
|
sta z:zscratch1
|
|
|
|
ldx #$0c
|
|
ldy #$0e
|
|
jsr printstr
|
|
|
|
lda #<tutorial2
|
|
sta z:zscratch0
|
|
lda #>tutorial2
|
|
sta z:zscratch1
|
|
|
|
ldx #$09
|
|
ldy #$15
|
|
jsr printstr
|
|
|
|
lda #<tutorial1
|
|
sta z:zscratch0
|
|
lda #>tutorial1
|
|
sta z:zscratch1
|
|
|
|
ldx #$0a
|
|
ldy #$17
|
|
jsr printstr
|
|
|
|
rts
|
|
|
|
title:
|
|
.byte $10, $0F, $0E, $07, $2C, $20, $0D, $0F, $12, $05, $20, $0F, $12, $20, $0C, $05, $13, $13, 0
|
|
|
|
credits:
|
|
.byte $0D, $01, $04, $05, $20, $02, $19, $20, $04, $15, $15, $11, $0E, $04, 0
|
|
|
|
tutorial1:
|
|
.byte $03, $0F, $0E, $14, $12, $0F, $0C, $20, $17, $09, $14, $08, $20, $11, $01, $20, $0F, $0C, 0
|
|
|
|
tutorial2:
|
|
.byte $10, $12, $05, $13, $13, $20, $13, $10, $01, $03, $05, $20, $14, $0F, $20, $13, $14, $01, $12, $14, 0
|
|
|
|
loadgamefield:
|
|
jsr clearscreen
|
|
|
|
;; now we'll draw the center column
|
|
ldx #$25
|
|
@lineloop:
|
|
lda scrlinelo,x
|
|
sta z:zscratch0
|
|
lda scrlinehi,x
|
|
sta z:zscratch1
|
|
txa
|
|
and #%00000001
|
|
bne @skipdot
|
|
lda #103
|
|
ldy #20
|
|
sta (zscratch0),y
|
|
jmp @next
|
|
@skipdot:
|
|
lda #116
|
|
ldy #19
|
|
sta (zscratch0),y
|
|
@next:
|
|
dex
|
|
bpl @lineloop
|
|
|
|
rts
|