;z80 ;zx-spectrum ;assembler ; haiku (c) Gasman 2005 ; sphere.asm: generate spherical coordinate table mksphere ld ix,sphere_table ; go down the sphere, forming rings ld hl,sine + 126 ; use the first half of the sine wave to generate radii, counting backwards to 0 nextring ld a,(hl) sub 0x40 ; raw sinewave has range 0x40 - 0x7f; transform this into a scale factor from 0 - 0xff add a,a add a,a ld e,a ; e = radius of ring push hl ; get y coord of ring = cosine ld a,l add a,64 ld l,a ld a,(hl) inc a ; some ellipses dip one pixel below the origin ld (centrey+1),a ld hl,sine ringpt ld a,(hl) sub 64 ld d,a call fmult add a,128 ld c,a push hl ld a,l add a,64 ld l,a ld a,(hl) sub 64 ld d,a pop hl call fmult sra a sra a ; sra a centrey add a,0 push hl push de push ix ld l,a call xy2screen ld (ix),l ; write address lo byte inc ixh inc ixh inc ixh inc ixh ld (ix),h inc ixh inc ixh inc ixh inc ixh ld (ix),a pop ix pop de pop hl inc ix ld a,l add a,8 ; 32 points on each ring ld l,a jr nc, ringpt pop hl ld a,l sub 4 ld l,a ; 32 rings jr nc,nextring ret ; fractional multiply: multiply d (2s complement) by e/256, return result in a; preserve e, lose d fmult xor a sra d rlc e jr nc,fmult1 add a,d fmult1 sra d rlc e jr nc,fmult2 add a,d fmult2 sra d rlc e jr nc,fmult3 add a,d fmult3 sra d rlc e jr nc,fmult4 add a,d fmult4 sra d rlc e jr nc,fmult5 add a,d fmult5 sra d rlc e jr nc,fmult6 add a,d fmult6 sra d rlc e jr nc,fmult7 add a,d fmult7 sra d rlc e jr nc,fmult8 add a,d fmult8 ret ; translate coords to screen address: l = y, c = x; return with hl = addr, a = bitmap xy2screen ld h,ylo / 256 ld e,(hl) inc h ld d,(hl) ld a,c and 7 ld l,a ld h,screenbits / 256 ld a,(hl) srl c srl c srl c ld b,0 ex de,hl add hl,bc ret