Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@RoelN
Created June 30, 2021 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoelN/5d81fc3b93ac69b1774bc521f5016c05 to your computer and use it in GitHub Desktop.
Save RoelN/5d81fc3b93ac69b1774bc521f5016c05 to your computer and use it in GitHub Desktop.
Shaving off more bytes...
// Kernal CLS Routine
.label INIT_SCREEN = $e544
// Variables
.label player_x = $d000
.label player_y = $d001
.label player_c = $d027
.file [name="spritemove.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:
// Setup screen and sprites
// X = ff here
// Make a Square Player Sprite
txa // A = 255
!:
sta $2100,x //132*64,x
inx
bpl !-
// X = 80 here, which is good enough to turn the screen black
// Set Background to Black
stx $d020
stx $d021
// 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:
cpx $d012
bne vsync
beq main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment