Advertisement
Zeda

sprite_move_keyport

Jan 18th, 2022
1,008
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 interrupts interfere
  24.  
  25. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  26. ; set up the key port. Reset the low bit to poll for arrows and next bit for
  27. ; Enter through Clear
  28. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  29.     ld a,%11111100
  30.     out (1),a
  31.  
  32. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  33. ; clear the gbuf
  34. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  35.     ld hl,gbuf
  36.     xor a       ; shortcut to set A to 0
  37.     ld b,a      ; now B is 0, but because we are DJNZing, this is basically 256
  38. clr_loop:
  39.     ld (hl),a
  40.     inc hl
  41.     ld (hl),a
  42.     inc hl
  43.     ld (hl),a
  44.     inc hl
  45.     djnz clr_loop
  46.  
  47.     ; init our coords
  48.     ; note that B is already 0
  49.     ld c,b
  50.  
  51. draw_sprite:
  52.     ld (coords),bc
  53.     ; we'll draw the sprite XORed, copy the buffer to the LCD, then re-XOR it
  54.     ; XORing twice basically does nothing to the screen, but by displaying
  55.     ; after the first XOR, the LCD shows the sprite.
  56.     ld hl, 0808h    ; (H,L) = (height, width)
  57.     ld de,sprite    ; pointer to the sprite
  58.     call bigsprite_XOR
  59.  
  60.     call gbuf_to_lcd_6MHz   ; show the screen before we remove the sprite
  61.  
  62.     ld bc,(coords)
  63.     ld hl, 0808h    ; (H,L) = (height, width)
  64.     ld de,sprite    ; pointer to the sprite
  65.     call bigsprite_XOR
  66.  
  67. main_loop:
  68.     ; read from the key port
  69.     in a,(1)
  70.     inc a   ; no key presses ==> 0xFF, adding 1 makes it 0 and sets the z flag
  71.     jr z,main_loop
  72.     dec a
  73.  
  74.     bit 6,a ; check if clear is pressed
  75.     ret z
  76.  
  77.     ld bc,(coords)
  78.  
  79.     ; We'll need A, so store it in H
  80.     rra
  81.     ld h,a
  82.     call nc,move_down
  83.     rr h
  84.     call nc,move_left
  85.     rr h
  86.     call nc,move_right
  87.     rr h
  88.     call nc,move_up
  89.     jr draw_sprite
  90.  
  91. move_up:
  92.     ld a,c
  93.     or a    ; make sure C isn't 0
  94.     ret z
  95.     dec c
  96.     ret
  97.  
  98. move_down:
  99.     ld a,c
  100.     cp 56
  101.     ret z
  102.     inc c
  103.     ret
  104.  
  105. move_right:
  106.     ld a,b
  107.     cp 88
  108.     ret z
  109.     inc b
  110.     ret
  111.  
  112. move_left:
  113.     ld a,b
  114.     or b
  115.     ret z
  116.     dec b
  117.     ret
  118.  
  119. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  120. ; This is a common subroutine that is required for the bigsprite routines.
  121. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  122. call_ix:
  123.     jp (ix)
  124.  
  125. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  126. ; Our sprite data
  127. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  128. sprite:
  129.     .db %00111100
  130.     .db %01000010
  131.     .db %10000001
  132.     .db %10000001
  133.     .db %10000001
  134.     .db %10000001
  135.     .db %01000010
  136.     .db %00111100
  137.  
  138. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  139. ; Includes
  140. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  141. #include "ti8x/gfx/bigsprite_XOR.z80"
  142. #include "ti8x/gfx/gbuf_to_lcd_6MHz.z80"
  143. #include "ti8x/utility/getKey.z80"
  144.  
  145.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement