zx_asmtest

changeset 2:f975431190f6

moving ship
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 20 Jan 2016 07:13:20 +0200
parents 04fc17db12e6
children 6da763b8592c
files test.asm
diffstat 1 files changed, 200 insertions(+), 15 deletions(-) [+]
line diff
     1.1 --- a/test.asm	Tue Jan 19 03:29:23 2016 +0200
     1.2 +++ b/test.asm	Wed Jan 20 07:13:20 2016 +0200
     1.3 @@ -9,21 +9,194 @@
     1.4  	ld a, 2
     1.5  	out (254), a
     1.6  
     1.7 +	call clear_scr
     1.8 +
     1.9  drawloop:
    1.10 -	call clear_scr
    1.11 +	ld b, 0
    1.12 +	ld a, (py)
    1.13 +	ld c, a
    1.14 +	push bc
    1.15 +	ld a, (px)
    1.16 +	ld c, a
    1.17 +	push bc
    1.18 +	call erase_blk
    1.19 +	pop bc
    1.20 +	pop bc
    1.21 +
    1.22 +	ld hl, sprite
    1.23 +	push hl
    1.24 +	ld b, 0
    1.25 +	ld a, (ny)
    1.26 +	ld (py), a
    1.27 +	ld c, a
    1.28 +	push bc
    1.29 +	ld a, (nx)
    1.30 +	ld (px), a
    1.31 +	ld c, a
    1.32 +	push bc
    1.33 +	call draw_sprite
    1.34 +	pop bc
    1.35 +	pop bc
    1.36 +	pop bc
    1.37 +
    1.38 +_endfrm:
    1.39 +	ld a, 2
    1.40 +	out (254), a
    1.41 +
    1.42 +	halt
    1.43  	jp drawloop
    1.44  
    1.45 +px defb 16
    1.46 +py defb 12
    1.47 +nx defb 16
    1.48 +ny defb 12
    1.49 +
    1.50 +inp_left:
    1.51 +	ld a, (px)
    1.52 +	cp 0
    1.53 +	ret z
    1.54 +	dec a
    1.55 +	ld (nx), a
    1.56 +	ret
    1.57 +
    1.58 +inp_right:
    1.59 +	ld a, (px)
    1.60 +	cp 31
    1.61 +	ret z
    1.62 +	inc a
    1.63 +	ld (nx), a
    1.64 +	ret
    1.65 +
    1.66 +inp_up:
    1.67 +	ld a, (py)
    1.68 +	cp 0
    1.69 +	ret z
    1.70 +	dec a
    1.71 +	ld (ny), a
    1.72 +	ret
    1.73 +
    1.74 +inp_down:
    1.75 +	ld a, (py)
    1.76 +	cp 23
    1.77 +	ret z
    1.78 +	inc a
    1.79 +	ld (ny), a
    1.80 +	ret
    1.81 +
    1.82 +inp_fire:	; TODO
    1.83 +	ret
    1.84 +
    1.85  clear_scr:
    1.86  	ld a, $ff
    1.87  	ld hl, fb_addr
    1.88  	ld b, 192
    1.89 -_LY:	ld c, 32
    1.90 -_LX:	ld (hl), a
    1.91 +_ly:	ld c, 32
    1.92 +_lx:	ld (hl), a
    1.93  	inc hl
    1.94  	dec c
    1.95 -	jr nz, _LX
    1.96 +	jr nz, _lx
    1.97  	dec b
    1.98 -	jr nz, _LY
    1.99 +	jr nz, _ly
   1.100 +	ret
   1.101 +
   1.102 +erase_blk:
   1.103 +	ld ix, 2
   1.104 +	add ix, sp
   1.105 +	ld c, (ix)
   1.106 +	ld b, (ix + 2)
   1.107 +
   1.108 +	call calc_blk_addr
   1.109 +
   1.110 +	ld c, 8
   1.111 +	ld a, $ff
   1.112 +_loop:	ld (de), a
   1.113 +	inc d
   1.114 +	dec c
   1.115 +	jr nz, _loop
   1.116 +	ret
   1.117 +	
   1.118 +
   1.119 +draw_sprite:
   1.120 +	ld ix, 2
   1.121 +	add ix, sp	; skip ret addr
   1.122 +	ld c, (ix)	; c <- x
   1.123 +	ld b, (ix + 2)	; b <- y
   1.124 +	ld l, (ix + 4)	; hl <- sprite address
   1.125 +	ld h, (ix + 5)
   1.126 +
   1.127 +	call calc_blk_addr
   1.128 +
   1.129 +	ld c, 8
   1.130 +_loop:	ld a, (hl)
   1.131 +	ld (de), a
   1.132 +	inc hl
   1.133 +	inc d
   1.134 +	dec c
   1.135 +	jr nz, _loop
   1.136 +	ret
   1.137 +
   1.138 +; expects X -> c, Y -> b, returns in de
   1.139 +calc_blk_addr:
   1.140 +	push af
   1.141 +	sla b
   1.142 +	sla b		; change from blocks to pixels
   1.143 +	sla b
   1.144 +	; construct low address byte -> e
   1.145 +	ld a, b		; start with Y
   1.146 +	sla a
   1.147 +	sla a
   1.148 +	and $e0		; keep top 3 bits
   1.149 +	ld e, a		; move into e
   1.150 +	ld a, c		; a <- X
   1.151 +	and $1f		; keep low 5 bits
   1.152 +	or e		; combine with Y bits
   1.153 +	ld e, a		; move the result back to e
   1.154 +	; construct high address byte -> d
   1.155 +	ld a, b		; start with Y again
   1.156 +	sra a
   1.157 +	sra a
   1.158 +	sra a
   1.159 +	and $18		; keep bits 3 and 4
   1.160 +	ld d, a		; keep it in d
   1.161 +	ld a, b		; grap Y one more time
   1.162 +	and $7		; keep low 3 bits of Y in a
   1.163 +	or d		; combine with Y6-Y7
   1.164 +	ld bc, fb_addr
   1.165 +	or b		; combine with high byte of fb address
   1.166 +	ld d, a		; move result back to d
   1.167 +	pop af
   1.168 +	ret
   1.169 +
   1.170 +
   1.171 +; port  | keys
   1.172 +; ------+--------------------------
   1.173 +; 32766 | B, N, M, SymbShift, Space
   1.174 +; 64510 | T, R, E, W, Q
   1.175 +; 65022 | G, F, D, S, A
   1.176 +scan_keys:
   1.177 +	ld bc, 65022	; check ASD
   1.178 +	in a, (c)
   1.179 +	rra
   1.180 +	push af
   1.181 +	call nc, inp_left
   1.182 +	pop af
   1.183 +	rra
   1.184 +	push af
   1.185 +	call nc, inp_down
   1.186 +	pop af
   1.187 +	rra
   1.188 +	call nc, inp_right
   1.189 +
   1.190 +	ld bc, 64510	; check W
   1.191 +	in a, (c)
   1.192 +	rra	; skip Q
   1.193 +	rra
   1.194 +	call nc, inp_up
   1.195 +
   1.196 +	ld bc, 32766	; check space
   1.197 +	in a, (c)
   1.198 +	rra
   1.199 +	call nc, inp_fire
   1.200  	ret
   1.201  
   1.202  ; ------ setup interrupt handler ------
   1.203 @@ -33,12 +206,12 @@
   1.204  ;  - data bus has the vector index (low byte for the jump)
   1.205  ; (1) IVT must be 256-byte aligned (addr: xx00h)
   1.206  ; also the IVT should not be in ULA-contended memory
   1.207 -; (2) IVT should be above 4000h
   1.208 +; (2) IVT should be above 8000h
   1.209  ; also it would be a good idea to avoid putting the IVT somewhere which can be
   1.210  ; paged out on 128k models
   1.211  ; (3) IVT shouldn't extend beyond c000h (?)
   1.212 -; finally, and this is the awesome bit, the data bus of the spectrum is
   1.213 -; floating during the interrupt request... which leads us to
   1.214 +; finally, and this is the awesome bit, the data bus of the spectrum contains
   1.215 +; garbage during the interrupt request... which leads us to
   1.216  ; (4) we must populate the entire IVT with the same interrupt address
   1.217  ; (5) we must use an interrupt address with identical low and high bytes
   1.218  ; (6) we need 257 bytes for the IVT
   1.219 @@ -63,10 +236,10 @@
   1.220  	ld hl, intr_tramp_addr
   1.221  	push hl
   1.222  	pop af	; a contains high byte of the trampoline address
   1.223 -_Livt:	ld (ix), a
   1.224 +_livt:	ld (ix), a
   1.225  	inc ix
   1.226  	dec c
   1.227 -	jr nz, _Livt
   1.228 +	jr nz, _livt
   1.229  	ld (ix), a	; final odd high byte of the address
   1.230  	; at $bdbd setup the jump to our interrupt routine
   1.231  	ld ix, $bdbd
   1.232 @@ -80,16 +253,28 @@
   1.233  	ret
   1.234  
   1.235  intr:
   1.236 -	push af
   1.237 -	ld a, (border)
   1.238 -	inc a
   1.239 +	exx
   1.240 +	ex af, af'
   1.241 +
   1.242 +	ld a, 1
   1.243  	out (254), a
   1.244 -	ld (border), a
   1.245 -	pop af
   1.246 +
   1.247 +	call scan_keys
   1.248 +	ex af, af'
   1.249 +	exx
   1.250  	ei
   1.251  	reti
   1.252  
   1.253  border defb 1
   1.254  nframe defw 0
   1.255  
   1.256 +sprite	defb %11100111
   1.257 +	defb %10000001
   1.258 +	defb %11000011
   1.259 +	defb %10000001
   1.260 +	defb %00000000
   1.261 +	defb %00011000
   1.262 +	defb %00111100
   1.263 +	defb %01111110
   1.264 +
   1.265  end prog_test