Advertisement
EdmundC

Untitled

Sep 8th, 2024
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     * = $0801       ; Start program at address $0801 (BASIC start)
  2.  
  3.     ; Standard BASIC header
  4.     .word $080b     ; Next line
  5.     .word $000a     ; Line number 10
  6.     .byte $9e       ; BASIC token for SYS
  7.     .byte "2064",0  ; SYS 8292 to start the game
  8.     .word $0000     ; End of BASIC program
  9.  
  10.     ; Start of Assembly code
  11.     .org $2064      ; Start our assembly program at $2064
  12.  
  13.     ; Initialize the screen
  14. START:
  15.     lda #$00        ; Set background to black
  16.     sta $d020       ; Write to border color register
  17.     sta $d021       ; Write to background color register
  18.  
  19.     jsr CLEAR_SCREEN  ; Clear the screen
  20.  
  21.     ; Initial player setup
  22.     lda #20         ; Initial player X position
  23.     sta PLAYER_X    ; Store in player X position
  24.  
  25. MAIN_LOOP:
  26.     jsr DRAW_PLAYER ; Draw the player plane
  27.  
  28.     ; Get joystick input for left/right movement
  29.     lda $dc00       ; Read joystick
  30.     and #%00000001  ; Check for left (bit 0)
  31.     beq MOVE_LEFT
  32.     lda $dc00
  33.     and #%00000010  ; Check for right (bit 1)
  34.     beq MOVE_RIGHT
  35.  
  36.     jmp MAIN_LOOP
  37.  
  38. MOVE_LEFT:
  39.     lda PLAYER_X
  40.     cmp #1          ; Don't move off screen to the left
  41.     beq MAIN_LOOP
  42.     dec PLAYER_X    ; Move player left
  43.     jmp MAIN_LOOP
  44.  
  45. MOVE_RIGHT:
  46.     lda PLAYER_X
  47.     cmp #39         ; Don't move off screen to the right (40 columns)
  48.     beq MAIN_LOOP
  49.     inc PLAYER_X    ; Move player right
  50.     jmp MAIN_LOOP
  51.  
  52. DRAW_PLAYER:
  53.     lda PLAYER_X
  54.     sta TEMP        ; Store X position in TEMP
  55.     lda #$20        ; ASCII code for space (clear the old position)
  56.     sta $0400 + 23*40 + TEMP ; Clear old position at row 23
  57.  
  58.     lda PLAYER_X    ; Reload player X
  59.     lda #$41        ; ASCII code for 'A' (player airplane)
  60.     sta $0400 + 23*40 + PLAYER_X ; Draw player airplane
  61.  
  62.     rts
  63.  
  64. CLEAR_SCREEN:
  65.     ldx #0
  66. CLEAR_LOOP:
  67.     lda #$20        ; Fill screen with spaces
  68.     sta $0400,x
  69.     sta $0428,x
  70.     sta $0450,x
  71.     sta $0478,x
  72.     sta $04a0,x
  73.     sta $04c8,x
  74.     sta $04f0,x
  75.     sta $0518,x
  76.     inx
  77.     bne CLEAR_LOOP  ; Loop until all screen is cleared
  78.     rts
  79.  
  80.     ; Variables
  81. PLAYER_X:
  82.     .byte 0         ; Player X position (column)
  83. TEMP:
  84.     .byte 0         ; Temporary storage
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement