; DSP matrix-water + voxel routine, by earx 2001/2002. ; Accuracy of 'crosshair' filter is high enough for this voxel. ; Now uses prerendering of column, to parallelise. ; Correct clipping. HSR: = $FFE9 HTX: = $FFEB ; basin dimensions: be sure not to make them too big! ; This might overflow the DSP RAM! WIDTH: = 150 HEIGHT: = 78 TOTALWIDTH: = WIDTH+1 TOTALHEIGHT: = HEIGHT+1 BASINSIZE: = TOTALWIDTH*TOTALHEIGHT get: MACRO jclr #0,x:<BASINSIZE,x0 clr a #<0,r0 do x0,<_end_loop _loop: move a,l:(r0)+ _end_loop: rts sendYVoxel: move #>TOTALWIDTH*HEIGHT,r0 move #pal+TOTALHEIGHT,r5 move #>100,y0 ; y0=max y move #<$10,x1 ; x1=scalar (anti-noise!) do #WIDTH,_columnloop ; We render the column to dsp mem.. move #columnTable,r6 move r0,r2 ; b=top=0 move #<1,r1 ; r1=depth=0 clr a y:(r2)-n2,x0 ; x0=1st raw height clr b r1,a do #HEIGHT,_zloop macr x1,x0,a (r1)+ ; a=height, y1=depth cmp y0,a r1,y1 ; Test if height is beyond screen, r1=depth+1 jlt <_go_on enddo move y0,a _go_on: sub b,a ; a=segheight jle <_next add a,b a,n1 move x0,a ; b=new top, a=raw height sub y1,a ; a=shade=raw height - depth, n1=segheight asr a asr a rep n1 ; Render #segheight pixels. move a,x:(r6)+ _next: tfr y1,a y:(r2)-n2,x0 ; a=depth+1, x0=next raw height _zloop: ; We send the column to host. move #columnTable,n6 move #columnTable,r4 move (r6)-n6 ; r6=columnheight send r6 ; Send columnheight. do r6,_send_loop move x:(r4)+,n5 ; n5=shade send y:(r5+n5) ; Send pixel. _send_loop: move (r0)+ ; Next column.. _columnloop: rts sendXVoxel: move #>TOTALWIDTH*HEIGHT,r0 move #pal+TOTALHEIGHT,r5 move #>100,y0 ; y0=max y move #<$10,x1 ; x1=scalar (anti-noise!) do #WIDTH,_columnloop move #columnTable,r6 move r0,r2 ; b=top=0 move #<1,r1 ; r1=depth=0 move x:(r2)-n2,x0 ; x0=1st raw height clr b r1,a do #HEIGHT,_zloop macr x1,x0,a (r1)+ ; a=height, y1=depth cmp y0,a r1,y1 ; Test if height is beyond screen, r1=depth+1 jlt <_go_on enddo move y0,a _go_on: sub b,a ; a=segheight jle <_next move a,n1 add a,b x0,a ; b=new top, a=raw height sub y1,a ; a=shade=raw height - depth, n1=segheight asr a asr a rep n1 move a,x:(r6)+ _next: tfr y1,a x:(r2)-n2,x0 ; a=depth+1, x0=next raw height _zloop: ; We send the column to host. move #columnTable,n6 move #columnTable,r4 move (r6)-n6 ; r6=columnheight send r6 ; Send columnheight. do r6,_send_loop move x:(r4)+,n5 ; n5=shade send y:(r5+n5) ; Send pixel. _send_loop: move (r0)+ ; Next column.. _columnloop: rts updateX:move #<0,r0 ;top move #ybuf+TOTALWIDTH,r3 ;bottom move #xbuf+TOTALWIDTH,r3 ;bottom move #TOTALWIDTH,x1 mpy x1,y0,a #>HTX,r1 asr a ; a0=ty*TOTALWIDTH move a0,a ; a=ty*TOTALWIDTH add x0,a ; a=ty*TOTALWIDTH+lx=offset move a,n0 ; n0=offset move x1,a ; a=TOTALWIDTH get x1 ; x1=width get y1 ; y1=height get y0 ; y0=amp move (r0)+n0 ; a=TOTALWIDTH-width=offset to next line, r0=start in buffer move r0,r2 move #>TOTALWIDTH,n2 ; n2=offset to next line do y1,_yloop clr b ; b=pixelcount=0 _block_loop: jclr #0,x:<TOTALWIDTH,x1 mpy x1,y0,a #>HTX,r1 asr a ; a0=ty*TOTALWIDTH move a0,a ; a=ty*TOTALWIDTH add x0,a ; a=ty*TOTALWIDTH+lx=offset move a,n0 ; n0=offset get x1 ; x1=width get y1 ; y1=height get y0 ; y0=amp move (r0)+n0 ; a=TOTALWIDTH-width=offset to next line, r0=start in buffer move r0,r2 move #>TOTALWIDTH,n2 ; n2=offset to next line do y1,_yloop clr b ; b=pixelcount=0 _block_loop: jclr #0,x:<