Skip to content

Instantly share code, notes, and snippets.

@cbrwn
Created December 18, 2018 16:39
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 cbrwn/c2bcf199a2e838d63905f6ccec1d09d2 to your computer and use it in GitHub Desktop.
Save cbrwn/c2bcf199a2e838d63905f6ccec1d09d2 to your computer and use it in GitHub Desktop.
; line of basic to call my program
; 10 SYS (2304)
*=$0801
BYTE $0E, $08, $0A, $00, $9E, $20, $28, $32
BYTE $33, $30, $34, $29, $00, $00, $00
; start my program at $0900
; BASIC programs memory starts at $0800,
; so I'll use that for my variables and stuff
*=$0900
; player related addresses (system)
PLAYER_X = $d000 ; sprite position x
PLAYER_Y = $d001 ; sprite position y
PLAYER_INPUT = $dc01 ; joystick 1 input
; player related addresses (basic ram)
PLAYER_SPEED_X = $0810
PLAYER_SPEED_Y = $0811
; routine to clear the screen
CLEARSCREEN
lda #$02 ; colour we want to clear to
sta $d020 ; border colour address
sta $d021 ; screen colour address
lda #$20 ; character to put into memory (space)
ldx #$00 ; start x at 0 for loopyloops
_loop
sta $0400,x ; 1st quarter of screen
sta $0500,x ; 2nd quarter of screen
sta $0600,x ; 3rd quarter of screen
sta $0700,x ; 4th quarter of screen
inx
bne _loop ; loop until x is 0 again
SPRITEINIT
; point sprite 1 to $2000, where we load it
lda #$80 ; 0x80 * 64 bytes (1 sprite) = $2000
sta $07f8 ; address of sprite 1 pointer
; enable sprite 1
lda #%00000001
sta $d015 ; address of enabled sprites byte
; set default position
lda #$80
sta PLAYER_X
sta PLAYER_Y
; main loopyloop
GAMELOOP
jsr PROCESS_INPUT
jmp GAMELOOP
; routine for moving the player around
PROCESS_INPUT
_checkup
; check if up is pressed on joystick
lda PLAYER_INPUT
and #%00000001
bne _checkdown
; up was pressed!
; to control the speed of the moving, I increment a 'speed' variable
; each frame the button is pressed, and only when that variable
; overflows, we move the sprite
; so this is essentially moving at 1 pixel every 256 frames??!?!
inc PLAYER_SPEED_Y
bne _checkdown
; we can move up one pixel :D
dec PLAYER_Y
_checkdown
; check if down is pressed on joystick
lda PLAYER_INPUT
and #%00000010
bne _checkleft
; down was pressed!
inc PLAYER_SPEED_Y
bne _checkleft
; we can move down
inc PLAYER_Y
_checkleft
lda PLAYER_INPUT
and #%00000100
bne _checkright
; left was pressed!
inc PLAYER_SPEED_X
bne _checkright
; we can move left
dec PLAYER_X
_checkright
lda PLAYER_INPUT
and #%00001000
bne _inputend
; right was pressed!
inc PLAYER_SPEED_X
bne _inputend
inc PLAYER_X
_inputend
rts
; load my sprite into $2000 so we know where it is :D
*=$2000
incbin "sprite1.bin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment