Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.35 KB | None | 0 0
  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ; Zniggy the Znig
  3. ; Copyright 2019 anonymous
  4. ; 4chan /vr/ board
  5. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  6.  
  7. ; ZX Spectrum Memory Map
  8. ; 0x0000 - 0x3FFF RESERVED: basic ROM
  9. ; 0x4000 - 0x57FF RAM: Screen 256x192 1bpp
  10. ; 0x5800 - 0x5AFF RAM: 8x8 color cells 32x24
  11. ; 0x5B00 - 0x5BFF RESERVED: Printer Buffer (?)
  12. ; 0x5C00 - 0x5CBF RESERVED: System variables (?)
  13. ; 0x5CC0 - 0x5CCA RESERVED: ???
  14. ; 0x5CCB - 0xFF57 FREE RAM OUR GAME
  15. ; 0xFF58 - 0xFFFF RESERVED: ???
  16.  
  17. org $8000
  18.  
  19. ;==============================================================
  20. ; Defines
  21. ;==============================================================
  22.  
  23. SCREEN_PIXEL_START equ $4000
  24. SCREEN_PIXEL_SIZE equ $1800
  25.  
  26. SCREEN_ATTRIBUTE_START equ $5800
  27. SCREEN_ATTRIBUTE_SIZE equ $0300
  28.  
  29. BLACK_INK equ $00
  30. BLUE_INK equ $01
  31. RED_INK equ $02
  32. PURPLE_INK equ $03
  33. GREEN_INK equ $04
  34. CYAN_INK equ $05
  35. YELLOW_INK equ $06
  36. WHITE_INK equ $07
  37.  
  38. BLACK_PAPER equ BLACK_INK << 3
  39. BLUE_PAPER equ BLUE_INK << 3
  40. RED_PAPER equ RED_INK << 3
  41. PURPLE_PAPER equ PURPLE_INK << 3
  42. GREEN_PAPER equ GREEN_INK << 3
  43. CYAN_PAPER equ CYAN_INK << 3
  44. YELLOW_PAPER equ YELLOW_INK << 3
  45. WHITE_PAPER equ WHITE_INK << 3
  46.  
  47. FLASH equ $80
  48. BRIGHT equ $40
  49.  
  50.  
  51.  
  52.  
  53. ;==============================================================
  54. ; Data
  55. ;==============================================================
  56. DATA_TILE_PIXELS:
  57. ; ziggy_head
  58. db %00011000
  59. db %00111100
  60. db %01111110
  61. db %11101011
  62. db %10111111
  63. db %01000010
  64. db %00111100
  65. db %00011000
  66.  
  67. DATA_TILE_ATTRIBUTES:
  68. db BLACK_PAPER | PURPLE_INK
  69.  
  70. ;==============================================================
  71. ; Utility Functions
  72. ;==============================================================
  73.  
  74. ;--------------------------------------------------------------
  75. PROC
  76. proc_clear_screen_pixels
  77. ;--------------------------------------------------------------
  78. ; IN: -
  79. ; OUT: -
  80. ; Affects hl, de, bc
  81.  
  82. ld hl, SCREEN_PIXEL_START
  83. ld de, SCREEN_PIXEL_START + 1
  84. ld bc, SCREEN_PIXEL_SIZE - 1
  85. ld (hl), 0
  86. ldir
  87. ret
  88. ENDP
  89.  
  90. ;--------------------------------------------------------------
  91. PROC
  92. proc_fill_screen_attribute:
  93. ;--------------------------------------------------------------
  94. ; IN: a = attribute
  95. ; OUT: -
  96. ; AFFECTS: hl, de, bc
  97.  
  98. ld hl, SCREEN_ATTRIBUTE_START
  99. ld de, SCREEN_ATTRIBUTE_START + 1
  100. ld bc, SCREEN_ATTRIBUTE_SIZE - 1
  101. ld (hl), a
  102. ldir
  103. ret
  104. ENDP
  105.  
  106. ;-------------------------------------------------------------
  107. PROC
  108. proc_get_screen_attribute_address:
  109. ;-------------------------------------------------------------
  110. ; IN: b = y-cell coord (0..23), c: x-cell coord (0..31)
  111. ; OUT: hl = attribute address
  112. ; AFFECTS: hl, de, a
  113.  
  114. ; Explanation
  115. ; b = -- -- -- y4 y3 y2 y1 y0
  116. ; c = -- -- -- x4 x3 x2 x1 x0
  117. ; hl = addr + y * 32 + x = addr + de
  118. ; y7 y6 y5 and x7 x6 x5 are all zero since x,y<32
  119. ; de = -- -- -- -- -- -- y4 y3|y2 y1 y0 x4 x3 x2 x1 x0
  120. ; -----------d-----------|------------e----------
  121.  
  122. ; put y4 y3 into lower two bits in d
  123. ld a, b
  124. and $18
  125. sra a
  126. sra a
  127. sra a
  128. ld d, a
  129.  
  130. ; put y2..y0 in upper bits of e
  131. ld a, b
  132. sla a
  133. sla a
  134. sla a
  135. sla a
  136. sla a
  137.  
  138. ; put x4...x0 in lower bits of e
  139. add a, c
  140. ld e, a
  141.  
  142. ld hl, SCREEN_ATTRIBUTE_START
  143. add hl, de
  144. ret
  145. ENDP
  146.  
  147. ;-------------------------------------------------------------
  148. PROC
  149. proc_get_screen_pixel_address:
  150. ;-------------------------------------------------------------
  151. ; IN: b = y-pixel coord (0..191), c: x-cell coord (0..31)
  152. ; OUT: hl = screen address
  153. ; AFFECTS: hl, de, a
  154.  
  155. ld a, b ; Work on the upper byte of the address
  156. and %00000111 ; a = Y2 Y1 y0
  157. or %01000000 ; first three bits are always 010
  158. ld h,a ; store in h
  159. ld a,b ; get bits Y7, Y6
  160. rra ; move them into place
  161. rra ;
  162. rra ;
  163. and %00011000 ; mask off
  164. or h ; a = 0 1 0 Y7 Y6 Y2 Y1 Y0
  165. ld h,a ; calculation of h is now complete
  166. ld a,b ; get y
  167. rla ;
  168. rla ;
  169. and %11100000 ; a = y5 y4 y3 0 0 0 0 0
  170. ld l,a ; store in l
  171. ld a,c ;
  172. and %00011111 ; a = X4 X3 X2 X1
  173. or l ; a = Y5 Y4 Y3 X4 X3 X2 X1
  174. ld l,a ; calculation of l is complete
  175. ret
  176. ENDP
  177.  
  178. ;==============================================================
  179. ; Initialization
  180. ;==============================================================
  181. start:
  182. call proc_clear_screen_pixels
  183.  
  184. ld a, BLACK_PAPER | WHITE_INK
  185. call proc_fill_screen_attribute
  186.  
  187. ld b, 21
  188. ld c, 31
  189. call proc_get_screen_attribute_address
  190. ld (hl), RED_INK | BLACK_PAPER | FLASH
  191.  
  192. ld b, 21*8
  193. ld c, 31
  194. call proc_get_screen_pixel_address
  195. ld (hl), 255
  196.  
  197. ; have no idea how to set border
  198. ; or why the two bottom rows are ignored
  199. ret
  200. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement