# HG changeset patch # User John Tsiombikas # Date 1453266800 -7200 # Node ID f975431190f6963e7bbf2b7ff1ec03f6bc254eb5 # Parent 04fc17db12e6a2ed0411184c0ef51813c8cb272c moving ship diff -r 04fc17db12e6 -r f975431190f6 test.asm --- a/test.asm Tue Jan 19 03:29:23 2016 +0200 +++ b/test.asm Wed Jan 20 07:13:20 2016 +0200 @@ -9,21 +9,194 @@ ld a, 2 out (254), a + call clear_scr + drawloop: - call clear_scr + ld b, 0 + ld a, (py) + ld c, a + push bc + ld a, (px) + ld c, a + push bc + call erase_blk + pop bc + pop bc + + ld hl, sprite + push hl + ld b, 0 + ld a, (ny) + ld (py), a + ld c, a + push bc + ld a, (nx) + ld (px), a + ld c, a + push bc + call draw_sprite + pop bc + pop bc + pop bc + +_endfrm: + ld a, 2 + out (254), a + + halt jp drawloop +px defb 16 +py defb 12 +nx defb 16 +ny defb 12 + +inp_left: + ld a, (px) + cp 0 + ret z + dec a + ld (nx), a + ret + +inp_right: + ld a, (px) + cp 31 + ret z + inc a + ld (nx), a + ret + +inp_up: + ld a, (py) + cp 0 + ret z + dec a + ld (ny), a + ret + +inp_down: + ld a, (py) + cp 23 + ret z + inc a + ld (ny), a + ret + +inp_fire: ; TODO + ret + clear_scr: ld a, $ff ld hl, fb_addr ld b, 192 -_LY: ld c, 32 -_LX: ld (hl), a +_ly: ld c, 32 +_lx: ld (hl), a inc hl dec c - jr nz, _LX + jr nz, _lx dec b - jr nz, _LY + jr nz, _ly + ret + +erase_blk: + ld ix, 2 + add ix, sp + ld c, (ix) + ld b, (ix + 2) + + call calc_blk_addr + + ld c, 8 + ld a, $ff +_loop: ld (de), a + inc d + dec c + jr nz, _loop + ret + + +draw_sprite: + ld ix, 2 + add ix, sp ; skip ret addr + ld c, (ix) ; c <- x + ld b, (ix + 2) ; b <- y + ld l, (ix + 4) ; hl <- sprite address + ld h, (ix + 5) + + call calc_blk_addr + + ld c, 8 +_loop: ld a, (hl) + ld (de), a + inc hl + inc d + dec c + jr nz, _loop + ret + +; expects X -> c, Y -> b, returns in de +calc_blk_addr: + push af + sla b + sla b ; change from blocks to pixels + sla b + ; construct low address byte -> e + ld a, b ; start with Y + sla a + sla a + and $e0 ; keep top 3 bits + ld e, a ; move into e + ld a, c ; a <- X + and $1f ; keep low 5 bits + or e ; combine with Y bits + ld e, a ; move the result back to e + ; construct high address byte -> d + ld a, b ; start with Y again + sra a + sra a + sra a + and $18 ; keep bits 3 and 4 + ld d, a ; keep it in d + ld a, b ; grap Y one more time + and $7 ; keep low 3 bits of Y in a + or d ; combine with Y6-Y7 + ld bc, fb_addr + or b ; combine with high byte of fb address + ld d, a ; move result back to d + pop af + ret + + +; port | keys +; ------+-------------------------- +; 32766 | B, N, M, SymbShift, Space +; 64510 | T, R, E, W, Q +; 65022 | G, F, D, S, A +scan_keys: + ld bc, 65022 ; check ASD + in a, (c) + rra + push af + call nc, inp_left + pop af + rra + push af + call nc, inp_down + pop af + rra + call nc, inp_right + + ld bc, 64510 ; check W + in a, (c) + rra ; skip Q + rra + call nc, inp_up + + ld bc, 32766 ; check space + in a, (c) + rra + call nc, inp_fire ret ; ------ setup interrupt handler ------ @@ -33,12 +206,12 @@ ; - data bus has the vector index (low byte for the jump) ; (1) IVT must be 256-byte aligned (addr: xx00h) ; also the IVT should not be in ULA-contended memory -; (2) IVT should be above 4000h +; (2) IVT should be above 8000h ; also it would be a good idea to avoid putting the IVT somewhere which can be ; paged out on 128k models ; (3) IVT shouldn't extend beyond c000h (?) -; finally, and this is the awesome bit, the data bus of the spectrum is -; floating during the interrupt request... which leads us to +; finally, and this is the awesome bit, the data bus of the spectrum contains +; garbage during the interrupt request... which leads us to ; (4) we must populate the entire IVT with the same interrupt address ; (5) we must use an interrupt address with identical low and high bytes ; (6) we need 257 bytes for the IVT @@ -63,10 +236,10 @@ ld hl, intr_tramp_addr push hl pop af ; a contains high byte of the trampoline address -_Livt: ld (ix), a +_livt: ld (ix), a inc ix dec c - jr nz, _Livt + jr nz, _livt ld (ix), a ; final odd high byte of the address ; at $bdbd setup the jump to our interrupt routine ld ix, $bdbd @@ -80,16 +253,28 @@ ret intr: - push af - ld a, (border) - inc a + exx + ex af, af' + + ld a, 1 out (254), a - ld (border), a - pop af + + call scan_keys + ex af, af' + exx ei reti border defb 1 nframe defw 0 +sprite defb %11100111 + defb %10000001 + defb %11000011 + defb %10000001 + defb %00000000 + defb %00011000 + defb %00111100 + defb %01111110 + end prog_test