Zeda

gfx example

Jan 17th, 2022 (edited)
429
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. plotSScreen = 9340h         ; a.k.a. the graph screen
  10. gbuf        = plotSScreen   ; using plotSScreen as our gbuf
  11. #define spritetmp   8000h   ; needed for the bigsprite routine. 8000h has 256 bytes of scrap ram, we use 4
  12. #define db .db              ; syntax comaptibility
  13. #define dw .dw              ; syntax comaptibility
  14.  
  15. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  16. ; TI Program header
  17. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  18. .db $BB, $6D
  19. .org $9D95
  20.  
  21. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  22. ; clear the gbuf
  23. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  24.     ld hl,gbuf
  25.     xor a       ; shortcut to set A to 0
  26.     ld b,a      ; now B is 0, but because we are DJNZing, this is basically 256
  27. clr_loop:
  28.     ld (hl),a
  29.     inc hl
  30.     ld (hl),a
  31.     inc hl
  32.     ld (hl),a
  33.     inc hl
  34.     djnz clr_loop
  35.  
  36.  
  37. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  38. ; Loop and draw pixels from (32,32), (31,31) ... (1,1)
  39. ; Note: this doesn't draw at (0,0)
  40. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  41.     ld b,32
  42. pix_loop:
  43.     push bc
  44.     ld c,b
  45.     call pixelOn
  46.     pop bc
  47.     djnz pix_loop
  48.  
  49. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  50. ; now draw an XORed sprite at (x,y) = (11, 22) and (90, 47)
  51. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  52.     ld bc,11*256 + 22
  53.     call putsprite
  54.     ld bc,90*256 + 47
  55.     call putsprite
  56.  
  57. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  58. ; finally, copy the gbuf to the LCD
  59. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  60.     jp gbuf_to_lcd_6MHz
  61.  
  62. putsprite:
  63. ; (B,C) is the (X,Y) coordinate of the sprite
  64.     ld hl, 0808h    ; (H,L) = (height, width)
  65.     ld de,sprite    ; pointer to the sprite
  66.     jp bigsprite_XOR
  67.  
  68. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  69. ; This is a common subroutine that is required for the bigsprite routines.
  70. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  71. call_ix:
  72.     jp (ix)
  73.  
  74. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  75. ; Our sprite data
  76. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  77. sprite:
  78.     .db %00111100
  79.     .db %01000010
  80.     .db %10000001
  81.     .db %10000001
  82.     .db %10000001
  83.     .db %10000001
  84.     .db %01000010
  85.     .db %00111100
  86.  
  87. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  88. ; Includes
  89. ;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;:;;
  90. #include "ti8x/gfx/getpixelloc_0x9340.z80"
  91. #include "ti8x/gfx/pixelOn.z80"
  92. ;#include "ti8x/gfx/pixelOff.z80"
  93. ;#include "ti8x/gfx/pixelToggle.z80"
  94. #include "ti8x/gfx/bigsprite_XOR.z80"
  95. #include "ti8x/gfx/gbuf_to_lcd_6MHz.z80"
Add Comment
Please, Sign In to add comment