Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; Zniggy the Znig
- ; Copyright 2019 anonymous
- ; 4chan /vr/ board
- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
- ; ZX Spectrum Memory Map
- ; 0x0000 - 0x3FFF RESERVED: basic ROM
- ; 0x4000 - 0x57FF RAM: Screen 256x192 1bpp
- ; 0x5800 - 0x5AFF RAM: 8x8 color cells 32x24
- ; 0x5B00 - 0x5BFF RESERVED: Printer Buffer (?)
- ; 0x5C00 - 0x5CBF RESERVED: System variables (?)
- ; 0x5CC0 - 0x5CCA RESERVED: ???
- ; 0x5CCB - 0xFF57 FREE RAM OUR GAME
- ; 0xFF58 - 0xFFFF RESERVED: ???
- org $8000
- ;==============================================================
- ; Defines
- ;==============================================================
- SCREEN_MEMORY equ $4000
- COLOR_MEMORY equ $5800
- ;==============================================================
- ; Utility Data
- ;==============================================================
- data_pixel_bit_table:
- db 128, 64, 32, 16, 8, 4, 2, 1
- ;==============================================================
- ; Utility Functions
- ;==============================================================
- ;--------------------------------------------------------------
- func_set_cell_attribute:
- ;--------------------------------------------------------------
- ; IN: bc = cell index, a = attribute
- ; OUT: none
- ; SIDE-EFFECTS: stack-overflow
- push bc
- push af
- ; add color memory address to bc
- ld a, b
- add a, $58
- ld b, a
- ; write attribute
- pop af
- ld (bc), a
- pop bc
- ret
- ;--------------------------------------------------------------
- func_set_pixel:
- ;--------------------------------------------------------------
- ; IN: b = y coord (0-192), c = x coord (0-256), a: off/on
- ; OUT: none
- ; SIDE-EFFECTS: stack-overflow
- ; At the end we want hl to look like this
- ; 0 1 0 y7 y6 y2 y1 y0 y5 y4 y3 x7 x6 x5 x4 x3
- ; ---------h---------- -----------l-----------
- ; c = x7 x6 x5 x4 x3 x2 x1 x0
- ; b = y7 y6 y5 y4 y3 y2 y1 y0
- ; Back-up registers
- push hl
- push af
- ; Task 1: Put c[7:3] in register l[4:0]
- ; destroys content of l!
- ld a, c
- srl a
- srl a
- srl a
- ld l, a
- ; Task 2: Put b[5:3] in register l[7:5]
- ; do not affect bits l[4:0]
- ld a, b
- sla a
- sla a
- and $e0
- add a, l
- ld l, a
- ; Task 3: Put b[2:0] in register h[2:0]
- ; destroys contents of h!
- ld a, b
- and $07
- ld h, a
- ; Task 4: put b[7:6] in register h[4:3]
- ; do not affect bits h[7:5] and h[2:0]
- ld a, b
- srl a
- srl a
- srl a
- and $18
- add a, h
- ld h, a
- ; Task 5: set bits h[7:5] to 010
- ; only the 1 is required, the 0s are already there
- set 6, h
- ; Task 6: calculate bit offset in byte for correct pixel
- ; each byte contains 8 pixels, we have so far only
- ; calculated the address of this byte
- ; if c[3:0] = 0 a = 1000 0000
- ; if c[3:0] = 1 a = 0100 0000
- ; if c[3:0] = 2 a = 0010 0000
- ; etc...
- ; assembly cant shift by variable
- ; use some shitty table
- push bc
- push hl
- ld hl, data_pixel_bit_table
- ld b, 0
- ld a, c
- and $07
- ld c, a
- add hl, bc
- ld a, (hl)
- pop hl
- pop bc
- ; Task 7: actually put down the pixel
- ; We now need to check the on/off value
- ; then set/unset the pixel, xor would be useful
- ; TO-DO: finish this
- xor (hl)
- ld (hl), a
- pop af
- pop hl
- ret
- ;==============================================================
- ; Initialization
- ;==============================================================
- start:
- ld bc, 255
- loop:
- ld a, $07
- call func_set_cell_attribute
- ld a, b
- or c
- dec bc
- jr nz, loop
- ld c, 255
- ld b, 192
- loop_forever:
- dec c
- jr nz, continue
- dec b
- jp nz, continue
- ld b, 192
- continue:
- call func_set_pixel
- jr loop_forever
- ret
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement