Skip to content

Instantly share code, notes, and snippets.

@object-Object
Created February 5, 2020 04:13
Show Gist options
  • Save object-Object/23641a5f55ad81b0c6618e3e0ddc598d to your computer and use it in GitHub Desktop.
Save object-Object/23641a5f55ad81b0c6618e3e0ddc598d to your computer and use it in GitHub Desktop.
Program for the 6502 processor to run a reaction game
.org $8000
reset:
lda #$ff ; set all of A register of 6522 to output
sta $6003
lda #$7f ; set all but last pin of B register of 6522 to output
sta $6002
lda #$01 ; initial value of output: 1 0 0 0 0 0 0
sta $6000
ldx #$00 ; set X and Y registers to 0 because we're using them later
ldy #$00
loop1:
cmp #$40 ; if at end of row, go the other direction
beq loop2
clc ; change the lit LED (going left, displayed as right)
rol
sta $6000
ldy $6000 ; check for button press
cpy #$80
bcc skip1
clc
jmp pressed1
skip1:
jmp loop1
loop2:
cmp #$01 ; if at end of row, go the other direction
beq loop1
clc ; change the lit LED (going right, displayed as left)
ror
sta $6000
ldy $6000 ; check for button press
cpy #$80
bcc skip2
clc
jmp pressed2
skip2:
jmp loop2
pressed1:
ldy #$00 ; wait a bit to make it obvious which led was picked
wait1:
iny
cpy #$18
bcc wait1
cmp #$08 ; check if they got the middle LED
clc
bne notcorrect1
correct1:
inx ; increment wins
stx $6001
tay ; exit if wins==15
txa
rol
rol
rol
rol
cmp #$f0
bcc correct1_nobrk
brk
correct1_nobrk:
tya
jmp skip1
notcorrect1:
tay ; increment losses by temporarily moving A to Y and X to A so we can add #$10, then moving everything back
txa
clc
adc #$10
tax
stx $6001
tya
cpx #$f0 ; exit if losses==15
bcc skip1
lda #$77
sta $6000
brk
; this is all the same as the previous section of code, but for when it's moving right
; because I couldn't make subroutines work
pressed2:
ldy #$00
wait2:
iny
cpy #$18
bcc wait2
cmp #$08
clc
bne notcorrect2
correct2:
inx
stx $6001
tay
txa
rol
rol
rol
rol
cmp #$f0
bcc correct2_nobrk
brk
correct2_nobrk:
tya
jmp skip2
notcorrect2:
tay
txa
clc
adc #$10
tax
stx $6001
tya
cpx #$f0
bcc skip2
lda #$77
sta $6000
brk
.org $fffc ; set starting address
.word reset
.word $0000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment