Skip to content

Instantly share code, notes, and snippets.

@aap
Created December 6, 2022 14:19
Show Gist options
  • Save aap/3b55bf5c87c7d06595d88cf9e3c8eb77 to your computer and use it in GitHub Desktop.
Save aap/3b55bf5c87c7d06595d88cf9e3c8eb77 to your computer and use it in GitHub Desktop.
.cpu "6502"
; move word
movw .macro
lda \2
sta \1
lda \2+1
sta \1+1
.endm
; move immediate word
movwi .macro
lda #<\2
sta \1
lda #>\2
sta \1+1
.endm
phx .macro
txa
pha
.endm
plx .macro
pla
tax
.endm
phy .macro
tya
pha
.endm
ply .macro
pla
tay
.endm
;; Zero page definitions
*=$30
pstr: .word ?
ballx: .byte ?
bally: .byte ?
vx: .byte ?
vy: .byte ?
p1: .byte ?
p2: .byte ?
src: .word ?
dst: .word ?
*=$0400
start:
movwi pstr,vt52
jsr putstr
lda #1
sta vx
sta vy
lda #2
sta p1
lda #10
sta p2
restart:
lda #40
sta ballx
lda #12
sta bally
loop:
movwi pstr,clr
jsr putstr
;; input
input: jsr rchr
bcs update
cmp #$1B ; ESC
beq stop
cmp #$77 ; w
bne in1
dec p1
jmp clp1
in1: cmp #$73 ; s
bne in2
inc p1
clp1: ldx #p1
jmp clamp
in2: cmp #$65 ; e
bne in3
dec p2
jmp clp2
in3: cmp #$64 ; d
bne update
inc p2
clp2: ldx #p2
jmp clamp
lda p2
cmp #19
bcc update
lda #19
sta p2
clamp: lda 0,x
bpl clamp1
lda #0
jmp clamp2
clamp1: cmp #19
bmi update
lda #19
clamp2: sta 0,x
update: clc
lda ballx
adc vx
sta ballx
clc
lda bally
adc vy
sta bally
colly: ;lda bally
bne y0
flipy: sec
lda #0
sbc vy
sta vy
jmp collx
y0: cmp #23
beq flipy
collx: lda ballx
beq restart2
cmp #79
beq restart2
cmp #2
bne bp2
ldx #p1
jmp bounce
stop: jmp ($FFFC) ; reset vector
restart2: jmp restart
bp2: cmp #77
bne draw
ldx #p2
bounce: sec
lda bally
sbc 0,x
bmi draw
sec
cmp #5
bpl draw
sec
lda #0
sbc vx
sta vx
draw:
clc
lda bally
adc #32
sta ball+2
clc
lda ballx
adc #32
sta ball+3
movwi pstr,ball
jsr putstr
clc
lda p1
adc #32
sta paddle1+2
movwi pstr,paddle1
jsr putstr
clc
lda p2
adc #32
sta paddle2+2
movwi pstr,paddle2
jsr putstr
movwi pstr,setcur
jsr putstr
ldx #6 ; #1 for ardino emulator
- phx
ldx #2
jsr ndelay ; exponential delay
plx
dex
bne -
jmp loop
putstr: ldy #0
- lda (pstr),y
beq return
jsr wchr
iny
jmp -
ndelay: dex
beq return
ldy #0
dlylp: iny
beq return
phx
phy
jsr ndelay
ply
plx
jmp dlylp
return: rts
wchr = $E003
rchr = $E006
.edef "\b", $08
.edef "\n", $0A
.edef "{ESC}", $1B
vt52: .null "{ESC}[?2l{ESC}Y {ESC}J"
clr: .null "{ESC}Y {ESC}J"
setcur: .null "{ESC}Y H"
ball: .null "{ESC}YxxO"
paddle1: .null "{ESC}Yx!|{ESC}B\b|{ESC}B\b|{ESC}B\b|{ESC}B\b|"
paddle2: .null "{ESC}Yxn|{ESC}B\b|{ESC}B\b|{ESC}B\b|{ESC}B\b|"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment