Advertisement
Redxone

[6502] Simple moving sprite.

Jan 19th, 2019
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. define NULL $00
  2. define BUFFMAX $FF
  3. define CPOSL $DD
  4. define CPOSH $DE
  5. define SPRX  $A0
  6. define SPRY  $B0
  7.  
  8. ; Code
  9.  
  10. START:  LDA #00     ; Entry point
  11.     STA SPRX
  12.     LDA #02
  13.     STA SPRY
  14. DRAWL:  LDA SPRX    ; Load sprite coords
  15.     PHA     ;
  16.     LDA SPRY    ;
  17.     PHA
  18.     JSR spSTART ; Draw sprite
  19.     JSR CLRSCR
  20.     INC SPRX
  21.     JMP DRAWL
  22.  
  23. spSTART:PLA      ; Setup for RTS
  24.     TAX    
  25.     PLA
  26.     TAY
  27.     PLA      ; Cursor pos MSB
  28.     STA CPOSH    ; Write MSB
  29.     PLA      ; Cursor pos LSB
  30.     STA CPOSL    ; Write LSB
  31.     TYA      ; Load return address
  32.     PHA
  33.     TXA
  34.     PHA
  35.     LDA #00      ; Initalize Registers
  36.     LDX #00    
  37.     LDY #00      
  38. spLOOP: LDA spr_arrow, X ; Load pixel
  39.     CMP #BUFFMAX     ; Is last byte?
  40.     BEQ spSPREND     ; Exit routine
  41.     STA (CPOSL),Y    ; Write pixel to screen
  42.     INX      ; Next pixel
  43.     INY      ; Move cursor right
  44.     CMP #NULL    ; Is last pixel in row?
  45.     BNE spLOOP   ; Read next pixel in row
  46. spLINE: LDA CPOSL    ; Load cursor pos LSB
  47.     LDY #00      ; Reset cursor X
  48.     CLC      ; AdjustAfterAddition?
  49.     ADC #32          ; New line
  50.     STA CPOSL    ; Write cursor pos LSB
  51.     BCS spLINE16     ; Check if adjust
  52.     JMP spLOOP   ; Next pixel
  53. spLINE16: LDA CPOSH  ; Load cursor pos MSB
  54.       INC A      ; Add one
  55.       STA CPOSH  ; Write cursor pos MSB
  56.       JMP spLOOP     ; Next pixel
  57.  
  58.  
  59. spSPREND: RTS ; Breakpoint
  60.  
  61. CLRSCR:  LDX #00
  62.      LDA #00
  63. clrLOOP: STA $0200,X
  64.      INX
  65.      CPX #$FF
  66.      BNE clrLOOP
  67.      RTS
  68.  
  69. ; Data
  70. spr_arrow:
  71.     DCB $11,$11,$11,$11,$11,$00
  72.     DCB $11,$05,$05,$05,$05,$11,$00
  73.     DCB $11,$05,$05,$05,$05,$05,$11,$00
  74.     DCB $11,$05,$05,$05,$05,$05,$05,$11,$00
  75.     DCB $11,$05,$05,$05,$05,$05,$11,$00
  76.     DCB $11,$05,$05,$05,$05,$11,$00
  77.     DCB $11,$11,$11,$11,$11,$00,$FF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement