Skip to content

Instantly share code, notes, and snippets.

@alannakelly
Last active June 30, 2021 15:25
Show Gist options
  • Save alannakelly/32aca06b0be59acc742e5192a81a61c0 to your computer and use it in GitHub Desktop.
Save alannakelly/32aca06b0be59acc742e5192a81a61c0 to your computer and use it in GitHub Desktop.
Player 59 - Commodore 64 Moveable Sprite in 59 bytes
; Player 59
;
; Commodore 64 Moveable Sprite in 59b
;
; 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
; - Resorted to an illegal instruction
; Roel Nieskens
; - Shorter sprite loader
; - Suggestions to avoid reg loads
; 0xC0DE
; - Saved a byte on vsync
; Monsters Go
; - Working CHROUT highjack
;
; Date: 2021-06-30
!cpu 6510
!to "player59.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
; Highjack CHROUT after loading
* = $326
!16 setup ; Entry point
; Make sure we don't overwrite STOP
!16 $f6ed
; Setup screen and sprites
setup:
; LAX - a useful illegal instruction
lax $91 ; A, X = 255
; Make a Square Player Sprite
; Using 132 because Y will be 132
; after calling INIT_SCREEN
-
sta $20ff,x
dex
bne -
; Clear Screen
jsr INIT_SCREEN
; Setup Player - Y = 132 here
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
; Main 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 -> C
; If C==0 U or L is pushed
bcs down_or_right
dec pl_x - 1,x ; pl_y or pl_x --
down_or_right:
lsr ; D or R -> C
; If C==0 D or R is pushed
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