Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. SCREEN_MEMORY   equ $4000
  23. COLOR_MEMORY    equ $5800
  24.  
  25. ;==============================================================
  26. ; Utility Data
  27. ;==============================================================
  28. data_pixel_bit_table:
  29. db 128, 64, 32, 16, 8, 4, 2, 1
  30.  
  31. ;==============================================================
  32. ; Utility Functions
  33. ;==============================================================
  34. ;--------------------------------------------------------------
  35. func_set_cell_attribute:
  36. ;--------------------------------------------------------------
  37.     ; IN: bc = cell index, a = attribute
  38.     ; OUT: none
  39.     ; SIDE-EFFECTS: stack-overflow
  40.  
  41.     push bc
  42.     push af
  43.  
  44.     ; add color memory address to bc
  45.     ld a, b
  46.     add a, $58
  47.     ld b, a
  48.  
  49.     ; write attribute
  50.     pop af
  51.     ld (bc), a
  52.  
  53.     pop bc
  54. ret
  55.  
  56. ;--------------------------------------------------------------
  57. func_set_pixel:
  58. ;--------------------------------------------------------------
  59.     ; IN: b = y coord (0-192), c = x coord (0-256), a: off/on
  60.     ; OUT: none
  61.     ; SIDE-EFFECTS: stack-overflow
  62.  
  63.     ; At the end we want hl to look like this
  64.     ; 0 1 0 y7 y6 y2 y1 y0  y5 y4 y3 x7 x6 x5 x4 x3
  65.     ; ---------h----------  -----------l-----------
  66.     ; c = x7 x6 x5 x4 x3 x2 x1 x0
  67.     ; b = y7 y6 y5 y4 y3 y2 y1 y0
  68.  
  69.     ; Back-up registers
  70.     push hl
  71.         push af
  72.             ; Task 1: Put c[7:3] in register l[4:0]
  73.             ; destroys content of l!
  74.             ld a, c
  75.             srl a
  76.             srl a
  77.             srl a
  78.             ld l, a
  79.  
  80.             ; Task 2: Put b[5:3] in register l[7:5]
  81.             ; do not affect bits l[4:0]
  82.             ld a, b
  83.             sla a
  84.             sla a
  85.             and $e0
  86.             add a, l
  87.             ld l, a
  88.  
  89.             ; Task 3: Put b[2:0] in register h[2:0]
  90.             ; destroys contents of h!
  91.             ld a, b
  92.             and $07
  93.             ld h, a
  94.  
  95.             ; Task 4: put b[7:6] in register h[4:3]
  96.             ; do not affect bits h[7:5] and h[2:0]
  97.             ld a, b
  98.             srl a
  99.             srl a
  100.             srl a
  101.             and $18
  102.             add a, h
  103.             ld h, a
  104.  
  105.             ; Task 5: set bits h[7:5] to 010
  106.             ; only the 1 is required, the 0s are already there
  107.             set 6, h
  108.  
  109.             ; Task 6: calculate bit offset in byte for correct pixel
  110.             ; each byte contains 8 pixels, we have so far only
  111.             ; calculated the address of this byte
  112.             ; if c[3:0] = 0  a = 1000 0000
  113.             ; if c[3:0] = 1  a = 0100 0000
  114.             ; if c[3:0] = 2  a = 0010 0000
  115.             ; etc...
  116.             ; assembly cant shift by variable
  117.             ; use some shitty table
  118.             push bc
  119.                 push hl
  120.                     ld hl, data_pixel_bit_table
  121.                     ld b, 0
  122.                     ld a, c
  123.                     and $07
  124.                     ld c, a
  125.                     add hl, bc
  126.                     ld a, (hl)
  127.                 pop hl
  128.             pop bc
  129.  
  130.             ; Task 7: actually put down the pixel
  131.             ; We now need to check the on/off value
  132.             ; then set/unset the pixel, xor would be useful
  133.             ; TO-DO: finish this
  134.             xor (hl)
  135.             ld (hl), a
  136.  
  137.         pop af
  138.     pop hl
  139. ret
  140.  
  141.  
  142. ;==============================================================
  143. ; Initialization
  144. ;==============================================================
  145. start:
  146.     ld bc, 255
  147.     loop:
  148.         ld a, $07
  149.         call func_set_cell_attribute
  150.         ld a, b
  151.         or c
  152.         dec bc
  153.         jr nz, loop
  154.  
  155.     ld c, 255
  156.     ld b, 192
  157.     loop_forever:
  158.         dec c
  159.         jr nz, continue
  160.             dec b
  161.             jp nz, continue
  162.             ld b, 192
  163.         continue:
  164.         call func_set_pixel
  165.         jr loop_forever
  166. ret
  167. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement