Skip to content

Instantly share code, notes, and snippets.

@JettMonstersGoBoom
Created June 30, 2021 13:25
Show Gist options
  • Save JettMonstersGoBoom/d261e9a73d71f706213da67356750efb to your computer and use it in GitHub Desktop.
Save JettMonstersGoBoom/d261e9a73d71f706213da67356750efb to your computer and use it in GitHub Desktop.
// Kernal CLS Routine
.label INIT_SCREEN = $e544
// Variables
.label player_x = $d000
.label player_y = $d001
.label player_c = $d027
.file [name="small.prg", segments="CODE"]
.segment CODE [start=$0326,max=$1000]
* = $326 "Code"
// hijack the kernal routines
// this is the pointer to CHROUT routine that's called by the kernal after loading to print "READY"
.word setup
// don't change this value
.word $f6ed
setup:
ldx #$00
// Setup screen and sprites
// X = 0
// Set Background to Black
stx $d020
stx $d021
dex // X = 255
// Make a Square Player Sprite
txa // A = 255
!:
sta $2100,x //132*64,x
inx
bpl !-
// Clear Screen
jsr INIT_SCREEN
// X = 1 after INIT_SCREEN
// Y = 132 after INIT_SCREEN
// Setup Player
sty $07f8 // Set sprite pointer
sty player_x // Set player x
sty player_y // Set player y
stx player_c // set color to white
stx $d015 // enable sprite 1
// Program loop
main:
// Read Joystick Port 2
lda $dc00
// Read Up
lsr // Up -> Carry
bcs down // If C==0 up is pushed
dec player_y // player_y--
down: // Read Down
lsr
bcs left
inc player_y // player_y++
left: // Read Left
lsr
bcs right
dec player_x // player_x--
right: // Read Right
lsr
bcs vsync
inc player_x // player_x++
// Wait for next frame
vsync:
ldx $d012
cpx #$f3
bne vsync
beq main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment