Advertisement
Zeda

sprite_move

Jan 17th, 2022
2,868
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Compile this with:
  2. ;       spasm <blah>.z80 <blah>.8xp -I path/to/Z80-Optimized-Routines
  3. ; Z80-Optimized-Routines can be found at https://github.com/Zeda/Z80-Optimized-Routines
  4. ;
  5.  
  6. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  7. ; Define some vars
  8. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  9. #define spritetmp   8000h   ; needed for the bigsprite routine. 8000h has 256 bytes of scrap ram, we use 4
  10. #define db .db              ; syntax comaptibility
  11. #define dw .dw              ; syntax comaptibility
  12. plotSScreen = 9340h         ; a.k.a. the graph screen
  13. gbuf        = plotSScreen   ; using plotSScreen as our gbuf
  14. _GetCSC     = 4018h         ; TI-OS bcall
  15. coords      = 8004h         ;we'll store our coords here
  16.  
  17. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  18. ; TI Program header
  19. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  20. .db $BB, $6D
  21. .org $9D95
  22.  
  23.     di      ; don't let the OS interfere
  24.  
  25. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  26. ; clear the gbuf
  27. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  28.     ld hl,gbuf
  29.     xor a       ; shortcut to set A to 0
  30.     ld b,a      ; now B is 0, but because we are DJNZing, this is basically 256
  31. clr_loop:
  32.     ld (hl),a
  33.     inc hl
  34.     ld (hl),a
  35.     inc hl
  36.     ld (hl),a
  37.     inc hl
  38.     djnz clr_loop
  39.  
  40.     ; init our coords
  41.     ; note that B is already 0
  42.     ld c,b
  43.  
  44. draw_sprite:
  45.     ld (coords),bc
  46.     ; we'll draw the sprite XORed, copy the buffer to the LCD, then re-XOR it
  47.     ; XORing twice basically does nothing to the screen, but by displaying
  48.     ; after the first XOR, the LCD shows the sprite.
  49.     ld hl, 0808h    ; (H,L) = (height, width)
  50.     ld de,sprite    ; pointer to the sprite
  51.     call bigsprite_XOR
  52.  
  53.     call gbuf_to_lcd_6MHz   ; show the screen before we remove the sprite
  54.  
  55.     ld bc,(coords)
  56.     ld hl, 0808h    ; (H,L) = (height, width)
  57.     ld de,sprite    ; pointer to the sprite
  58.     call bigsprite_XOR
  59.  
  60. main_loop:
  61.     call getKey
  62.     or a    ; shortcut to check if A is 0
  63.     jr z,main_loop
  64.     cp 15   ; clear button
  65.     ret z
  66.     cp 5    ; arrows are 1-4, so make sure it isn't bigger then 4
  67.     jr nc,main_loop
  68.  
  69.     ld bc,(coords)  ; restore coords
  70.  
  71.     dec a   ; down = 1, so this would set it to 0
  72.     jr z,move_down
  73.     dec a   ; left = 2, so this would set it to 0
  74.     jr z,move_left
  75.     dec a   ; right = 3, so this would set it to 0
  76.     jr z,move_right
  77.     dec a   ; up = 0, so this would set it to 0
  78.     ; jr z,move_right
  79. move_up:
  80.     or c    ; make sure C isn't 0. A is already 0, so this is a cheat
  81.     jr z,main_loop
  82.     dec c
  83.     jr draw_sprite
  84.  
  85. move_down:
  86.     ld a,c
  87.     cp 56
  88.     jr z,main_loop
  89.     inc c
  90.     jr draw_sprite
  91.  
  92. move_right:
  93.     ld a,b
  94.     cp 88
  95.     jr z,main_loop
  96.     inc b
  97.     jr draw_sprite
  98.  
  99. move_left:
  100.     or b    ; make sure B isn't 0. A is already 0, so this is a cheat
  101.     jr z,main_loop
  102.     dec b
  103.     jr draw_sprite
  104.  
  105. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  106. ; This is a common subroutine that is required for the bigsprite routines.
  107. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  108. call_ix:
  109.     jp (ix)
  110.  
  111. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  112. ; Our sprite data
  113. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  114. sprite:
  115.     .db %00111100
  116.     .db %01000010
  117.     .db %10000001
  118.     .db %10000001
  119.     .db %10000001
  120.     .db %10000001
  121.     .db %01000010
  122.     .db %00111100
  123.  
  124. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  125. ; Includes
  126. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  127. #include "ti8x/gfx/bigsprite_XOR.z80"
  128. #include "ti8x/gfx/gbuf_to_lcd_6MHz.z80"
  129. #include "ti8x/utility/getKey.z80"
  130.  
  131.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement