Skip to content

Instantly share code, notes, and snippets.

@RoelN
Created June 30, 2021 09:11
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/f306af0b1d058b377673d4ba80dcc9fd to your computer and use it in GitHub Desktop.
Save RoelN/f306af0b1d058b377673d4ba80dcc9fd to your computer and use it in GitHub Desktop.
Player 79 - Commodore 64 Moveable Sprite in 79 bytes
// Player 79
//
// Commodore 64 Moveable Sprite in 84b
//
// Joystick in Port 2 to move sprite.
// Purely for fun to see how few bytes it
// can be done in. Public Domain, do what
// you want with the code but credit is
// always appreciated.
//
// Original 84 bytes by: https://github.com/alannakelly
// Date: 2021-06-30
//
// 79 bytes version by Roel in KickAssembler syntax
// Kernal CLS Routine
.var INIT_SCREEN = $e544
// Variables
.var player_x = $d000
.var player_y = $d001
.var player_c = $d027
*=$0801
.byte $0b, $08, $0a, $00, $9e // 10 SYS
.byte $32, $30, $36, $31 // 2061
.byte $00, $00, $00 // End
start:
// 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
inx
bne vsync
beq main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment