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_PIXEL_START equ $4000
- SCREEN_PIXEL_SIZE equ $1800
- SCREEN_ATTRIBUTE_START equ $5800
- SCREEN_ATTRIBUTE_SIZE equ $0300
- BLACK_INK equ $00
- BLUE_INK equ $01
- RED_INK equ $02
- PURPLE_INK equ $03
- GREEN_INK equ $04
- CYAN_INK equ $05
- YELLOW_INK equ $06
- WHITE_INK equ $07
- BLACK_PAPER equ BLACK_INK << 3
- BLUE_PAPER equ BLUE_INK << 3
- RED_PAPER equ RED_INK << 3
- PURPLE_PAPER equ PURPLE_INK << 3
- GREEN_PAPER equ GREEN_INK << 3
- CYAN_PAPER equ CYAN_INK << 3
- YELLOW_PAPER equ YELLOW_INK << 3
- WHITE_PAPER equ WHITE_INK << 3
- FLASH equ $80
- BRIGHT equ $40
- ;==============================================================
- ; Data
- ;==============================================================
- DATA_TILE_PIXELS:
- ; ziggy_head
- db %00011000
- db %00111100
- db %01111110
- db %11101011
- db %10111111
- db %01000010
- db %00111100
- db %00011000
- DATA_TILE_ATTRIBUTES:
- db BLACK_PAPER | PURPLE_INK
- ;==============================================================
- ; Utility Functions
- ;==============================================================
- ;--------------------------------------------------------------
- PROC
- proc_clear_screen_pixels
- ;--------------------------------------------------------------
- ; IN: -
- ; OUT: -
- ; Affects hl, de, bc
- ld hl, SCREEN_PIXEL_START
- ld de, SCREEN_PIXEL_START + 1
- ld bc, SCREEN_PIXEL_SIZE - 1
- ld (hl), 0
- ldir
- ret
- ENDP
- ;--------------------------------------------------------------
- PROC
- proc_fill_screen_attribute:
- ;--------------------------------------------------------------
- ; IN: a = attribute
- ; OUT: -
- ; AFFECTS: hl, de, bc
- ld hl, SCREEN_ATTRIBUTE_START
- ld de, SCREEN_ATTRIBUTE_START + 1
- ld bc, SCREEN_ATTRIBUTE_SIZE - 1
- ld (hl), a
- ldir
- ret
- ENDP
- ;-------------------------------------------------------------
- PROC
- proc_get_screen_attribute_address:
- ;-------------------------------------------------------------
- ; IN: b = y-cell coord (0..23), c: x-cell coord (0..31)
- ; OUT: hl = attribute address
- ; AFFECTS: hl, de, a
- ; Explanation
- ; b = -- -- -- y4 y3 y2 y1 y0
- ; c = -- -- -- x4 x3 x2 x1 x0
- ; hl = addr + y * 32 + x = addr + de
- ; y7 y6 y5 and x7 x6 x5 are all zero since x,y<32
- ; de = -- -- -- -- -- -- y4 y3|y2 y1 y0 x4 x3 x2 x1 x0
- ; -----------d-----------|------------e----------
- ; put y4 y3 into lower two bits in d
- ld a, b
- and $18
- sra a
- sra a
- sra a
- ld d, a
- ; put y2..y0 in upper bits of e
- ld a, b
- sla a
- sla a
- sla a
- sla a
- sla a
- ; put x4...x0 in lower bits of e
- add a, c
- ld e, a
- ld hl, SCREEN_ATTRIBUTE_START
- add hl, de
- ret
- ENDP
- ;-------------------------------------------------------------
- PROC
- proc_get_screen_pixel_address:
- ;-------------------------------------------------------------
- ; IN: b = y-pixel coord (0..191), c: x-cell coord (0..31)
- ; OUT: hl = screen address
- ; AFFECTS: hl, de, a
- ld a, b ; Work on the upper byte of the address
- and %00000111 ; a = Y2 Y1 y0
- or %01000000 ; first three bits are always 010
- ld h,a ; store in h
- ld a,b ; get bits Y7, Y6
- rra ; move them into place
- rra ;
- rra ;
- and %00011000 ; mask off
- or h ; a = 0 1 0 Y7 Y6 Y2 Y1 Y0
- ld h,a ; calculation of h is now complete
- ld a,b ; get y
- rla ;
- rla ;
- and %11100000 ; a = y5 y4 y3 0 0 0 0 0
- ld l,a ; store in l
- ld a,c ;
- and %00011111 ; a = X4 X3 X2 X1
- or l ; a = Y5 Y4 Y3 X4 X3 X2 X1
- ld l,a ; calculation of l is complete
- ret
- ENDP
- ;==============================================================
- ; Initialization
- ;==============================================================
- start:
- call proc_clear_screen_pixels
- ld a, BLACK_PAPER | WHITE_INK
- call proc_fill_screen_attribute
- ld b, 21
- ld c, 31
- call proc_get_screen_attribute_address
- ld (hl), RED_INK | BLACK_PAPER | FLASH
- ld b, 21*8
- ld c, 31
- call proc_get_screen_pixel_address
- ld (hl), 255
- ; have no idea how to set border
- ; or why the two bottom rows are ignored
- ret
- end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement