Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- * = $0801 ; Start program at address $0801 (BASIC start)
- ; Standard BASIC header
- .word $080b ; Next line
- .word $000a ; Line number 10
- .byte $9e ; BASIC token for SYS
- .byte "2064",0 ; SYS 8292 to start the game
- .word $0000 ; End of BASIC program
- ; Start of Assembly code
- .org $2064 ; Start our assembly program at $2064
- ; Initialize the screen
- START:
- lda #$00 ; Set background to black
- sta $d020 ; Write to border color register
- sta $d021 ; Write to background color register
- jsr CLEAR_SCREEN ; Clear the screen
- ; Initial player setup
- lda #20 ; Initial player X position
- sta PLAYER_X ; Store in player X position
- MAIN_LOOP:
- jsr DRAW_PLAYER ; Draw the player plane
- ; Get joystick input for left/right movement
- lda $dc00 ; Read joystick
- and #%00000001 ; Check for left (bit 0)
- beq MOVE_LEFT
- lda $dc00
- and #%00000010 ; Check for right (bit 1)
- beq MOVE_RIGHT
- jmp MAIN_LOOP
- MOVE_LEFT:
- lda PLAYER_X
- cmp #1 ; Don't move off screen to the left
- beq MAIN_LOOP
- dec PLAYER_X ; Move player left
- jmp MAIN_LOOP
- MOVE_RIGHT:
- lda PLAYER_X
- cmp #39 ; Don't move off screen to the right (40 columns)
- beq MAIN_LOOP
- inc PLAYER_X ; Move player right
- jmp MAIN_LOOP
- DRAW_PLAYER:
- lda PLAYER_X
- sta TEMP ; Store X position in TEMP
- lda #$20 ; ASCII code for space (clear the old position)
- sta $0400 + 23*40 + TEMP ; Clear old position at row 23
- lda PLAYER_X ; Reload player X
- lda #$41 ; ASCII code for 'A' (player airplane)
- sta $0400 + 23*40 + PLAYER_X ; Draw player airplane
- rts
- CLEAR_SCREEN:
- ldx #0
- CLEAR_LOOP:
- lda #$20 ; Fill screen with spaces
- sta $0400,x
- sta $0428,x
- sta $0450,x
- sta $0478,x
- sta $04a0,x
- sta $04c8,x
- sta $04f0,x
- sta $0518,x
- inx
- bne CLEAR_LOOP ; Loop until all screen is cleared
- rts
- ; Variables
- PLAYER_X:
- .byte 0 ; Player X position (column)
- TEMP:
- .byte 0 ; Temporary storage
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement