Skip to content

Instantly share code, notes, and snippets.

@alannakelly
Last active June 30, 2021 11:48
Show Gist options
  • Save alannakelly/08fb10739e4f50a8e62a755754706c96 to your computer and use it in GitHub Desktop.
Save alannakelly/08fb10739e4f50a8e62a755754706c96 to your computer and use it in GitHub Desktop.
Player 73 - Commodore 64 Moveable Sprite in 73 bytes
; Player 73
;
; Commodore 64 Moveable Sprite in 73b
;
; 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.
;
; Authors and Contributors:
; Alanna Kelly
; - Original 84 byte version
; - Looped joystick read
; Roel Nieskens
; - Shorter sprite loader
; - Suggestions to avoid reg loads
; 0xC0DE
; - Saved a byte on vsync
;
; Date: 2021-06-30
!to "player73.prg",cbm
; Kernal CLS Routine
INIT_SCREEN = $e544
; Variables
pl_x = $d000 ; Player x position
pl_y = $d001 ; Player y position
pl_c = $d027 ; Player color
; Start at BASIC
* = $801
; BASIC Launcher
!08 $0b, $08, $0a, $00, $9e ; 10 SYS
!08 $32, $30, $36, $31 ; 2061
!08 $00, $00, $00 ; End
; 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
; Using 132 because the Y will be 132
; after calling INIT_SCREEN
; Shorter sprite load suggested by Roel Nieskens
-
sta 132*64,x
inx
bpl -
; Clear Screen
jsr INIT_SCREEN
; Setup Player
sty $07f8 ; Set sprite pointer
sty pl_x ; Set player x
sty pl_y ; Set player y
;X = 1 after INIT_SCREEN
; Set player color to white
stx pl_c
stx $d015 ; enable sprite 1
; Program loop
main:
inx ; X = 2
; Loop joystick read code
; Read Joystick Port 2
lda $dc00
; Joystick read loop. First iteration
; checks up and down. Second iteration
; checks left and right.
joy_read_loop:
lsr ; U or L to -> Carry
; If C==0 up is pushed
bcs down_or_right
dec pl_x - 1,x ; pl_y or pl_x --
; Read Down or Right
down_or_right:
lsr
bcs next
inc pl_x - 1,x ; pl_y or pl_x ++
next:
dex ; X--
; Exit loop if X == 0
bne joy_read_loop
; Wait for next frame
inx ; X = 1
vsync:
cpx $d012
bne vsync
; Loop
beq main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment