Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save RenatoExpert/98cffaa3ca2ce54ad01fdbfcdebc7901 to your computer and use it in GitHub Desktop.

Select an option

Save RenatoExpert/98cffaa3ca2ce54ad01fdbfcdebc7901 to your computer and use it in GitHub Desktop.
; Written by Renato Araujo, 2023
; renatorraraujo@gmail.com
; @renatoexpert
; Assembly demo for 6502
; I am playing this at the following app
; https://play.google.com/store/apps/details?id=com.redlee90.learn6502assembly
; Addresses may vary from device to device,
; eg. atari, nes, motorola...
define input_addr $ff
define random_addr $fe
define black $00
define white $01
define blue $03
JSR init
JSR loop
init:
LDA #$11
STA $00
LDA #$03
STA $01
RTS
loop:
JSR clear
JSR getkey
JSR draw
JSR sleep
JMP loop
clear: ; clear current position
LDY #$00
LDA random_addr
STA ($00),y
RTS
getkey:
CLC
LDA input_addr
CMP #$77
BEQ upkey
CMP #$64
BEQ rightkey
CMP #$73
BEQ downkey
CMP #$61
BEQ leftkey
RTS
rightkey:
CLC
LDA $00
ADC #$01
AND #$1F
CMP #$00
BNE goright
RTS
goright:
INC $00
RTS
leftkey:
CLC
LDA $00
AND #$1F
CMP #$00
BNE goleft
RTS
goleft:
DEC $00
RTS
upkey:
LDA $00
AND #$E0
CMP #$00
BNE goup
LDA $01
CMP #$02
BNE goup
RTS
goup:
LDA $00
SBC #$20
STA $00
BCC dec_area
RTS
downkey:
LDA $00
AND #$E0
CMP #$E0
BNE godown
LDA $01
CMP #$05
BNE godown
RTS
godown:
CLC
LDA $00
ADC #$20
STA $00
BCS pre_inc_area
RTS
pre_inc_area:
LDA $01
CMP #$05
BNE inc_area
RTS
inc_area:
INC $01
RTS
dec_area:
DEC $01
RTS
draw:
LDY #$00
LDA #$01
STA ($00),y
RTS
sleep:
LDX #$00
LDY #$00
JSR sleepcycle
RTS
sleepcycle:
NOP
NOP
DEX
BNE sleepcycle
DEY
BNE sleepcycle
RTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment