SCREEN 13: DEF SEG = &HA000 OUT &H3C4, &H4: OUT &H3C5, INP(&H3C5) AND 247 'CHAIN 4 OFF OUT &H3D4, &H17: OUT &H3D5, INP(&H3D5) OR 64 'WORD MODE OUT &H3D4, &H14: OUT &H3D5, INP(&H3D5) AND 191 '2-WORD MODE numlines% = 25 DIM pt%(numlines%), sp%(numlines%), m2&(numlines%), c2&(numlines%) DIM ki%(numlines%), wal%(numlines%) DIM sintable&(2048), tantable&(1024), mask%(4) DIM height%(320), linum%(320), pic%(16384), radarang(320), kind%(320) mask%(0) = 1: mask%(1) = 2: mask%(2) = 4: mask%(3) = 8 FOR z% = 0 TO 1023 sintable&(z%) = 32000 * SIN(z% * 3.141592 / 1024) IF z% <> 512 THEN tantable&(z%) = 65536 * TAN(z% * 3.141592 / 1024) NEXT z% FOR z% = 1024 TO 2047 sintable&(z%) = -sintable&(z% - 1024) NEXT z% FOR z% = 0 TO 159 radarang(z%) = (ATN((z% - 160) / 160) * 1024 / 3.141592) + 1 NEXT z% FOR z% = 160 TO 319 radarang(z%) = -radarang(319 - z%) NEXT z% FOR z% = 0 TO 4095 pic%(z%) = ((z% AND 63) + (z% \ 64)) AND 255 pic%(z% + 4096) = pic%(z%) \ 16 + 16 pic%(z% + 8192) = ((SQR((z% AND 63) ^ 2 + (z% \ 64) ^ 2) / 4) AND 255) + 32 pic%(z% + 12288) = (140 + 18 * COS((z% AND 63) / 5) + 18 * SIN((z% \ 64) / 5)) AND 255 NEXT z% FOR z% = 0 TO numlines% - 1 READ x1, y1, x2, y2, wal%(z%) IF ABS(x1 - x2) >= ABS(y1 - y2) THEN IF x1 > x2 THEN SWAP x1, x2: SWAP y1, y2 m2&(z%) = (65536 * (y2 - y1)) / (x2 - x1) c2&(z%) = (x1 * m2&(z%)) \ 65536 - y1 ki%(z%) = 0 pt%(z%) = x1 sp%(z%) = x2 - x1 ELSE IF y1 > y2 THEN SWAP x1, x2: SWAP y1, y2 m2&(z%) = (65536 * (x2 - x1)) / (y2 - y1) c2&(z%) = (y1 * m2&(z%)) \ 65536 - x1 ki%(z%) = 1 pt%(z%) = y1 sp%(z%) = y2 - y1 END IF NEXT z% posx% = 700 posy% = 200 ang% = 1024 DO FOR count% = 0 TO 320 kind%(count%) = -1 NEXT count% FOR count% = 0 TO 320 STEP 8 GOSUB raytrace NEXT count% FOR count% = 4 TO 320 STEP 8 IF kind%(count% - 4) = kind%(count% + 4) THEN height%(count%) = (height%(count% - 4) + height%(count% + 4)) \ 2 linum%(count%) = ((linum%(count% - 4) + linum%(count% + 4)) \ 2) AND &HFFC0 kind%(count%) = kind%(count% - 4) ELSE GOSUB raytrace END IF NEXT count% FOR count% = 2 TO 320 STEP 4 IF kind%(count% - 2) = kind%(count% + 2) THEN height%(count%) = (height%(count% - 2) + height%(count% + 2)) \ 2 linum%(count%) = ((linum%(count% - 2) + linum%(count% + 2)) \ 2) AND &HFFC0 kind%(count%) = kind%(count% - 2) ELSE GOSUB raytrace END IF NEXT count% FOR count% = 1 TO 320 STEP 2 IF kind%(count% - 1) = kind%(count% + 1) THEN height%(count%) = (height%(count% - 1) + height%(count% + 1)) \ 2 linum%(count%) = ((linum%(count% - 1) + linum%(count% + 1)) \ 2) AND &HFFC0 kind%(count%) = kind%(count% - 1) ELSE GOSUB raytrace END IF NEXT count% count% = 0 WHILE count% < 320 picplc% = linum%(count%) linesatonce% = 1 OUT &H3C4, 2: OUT &H3C5, mask%(count% AND 3) IF linum%(count%) = linum%(count%) + 1 AND (count% AND 3) < 3 THEN linesatonce% = 2 OUT &H3C4, 2: OUT &H3C5, 3 * mask%(count% AND 3) IF linum%(count%) = linum%(count%) + 1 AND (count% AND 3) < 2 THEN linesatonce% = 2 OUT &H3C4, 2: OUT &H3C5, 7 * mask%(count% AND 3) IF linum%(count%) = linum%(count%) + 1 AND (count% AND 3) = 0 THEN linesatonce% = 3 OUT &H3C4, 2: OUT &H3C5, 15 END IF END IF END IF yf0% = height%(count%) IF yf0% > 4096 THEN yf0% = 0 zz% = 0 FOR zx% = 1 TO 100 - yf0% \ 2 POKE zz% + (count% \ 4), 6 POKE (15920 - zz%) + (count% \ 4), 8 zz% = zz% + 80 NEXT zx% zz% = 80& * (100 - yf0% \ 2) + (count% \ 4) IF yf0% < 64 AND yf0% > 0 THEN yf0% = yf0% + yf0% yf0% = yf0% + yf0% FOR zx% = picplc% TO picplc% + 63 POKE zz%, pic%(zx%) yc0% = (yc0% + yf0%) AND 255: IF yc0% < yf0% THEN zz% = zz% + 80 NEXT zx% yf0% = 0 END IF IF yf0% >= 64 THEN yc0% = 32 FOR zx% = 1 TO yf0% IF zz% >= 0 AND zz% <= 63999 THEN POKE zz%, pic%(picplc%) zz% = zz% + 80 yc0% = yc0% + 64: IF yc0% >= yf0% THEN yc0% = yc0% - yf0%: picplc% = picplc% + 1 NEXT zx% END IF count% = count% + linesatonce% WEND DO z$ = INKEY$ LOOP WHILE z$ = "" IF z$ = CHR$(0) + CHR$(75) THEN ang% = ((ang% - 32) + 2048) AND 2047 IF z$ = CHR$(0) + CHR$(77) THEN ang% = ((ang% + 32) + 2048) AND 2047 IF z$ = CHR$(0) + CHR$(72) THEN posx% = posx% + 16 * COS(ang% * 3.141592 / 1024): posy% = posy% + 16 * SIN(ang% * 3.141592 / 1024) IF z$ = CHR$(0) + CHR$(80) THEN posx% = posx% - 16 * COS(ang% * 3.141592 / 1024): posy% = posy% - 16 * SIN(ang% * 3.141592 / 1024) LOOP WHILE z$ <> CHR$(27) END raytrace: angle% = ang% + radarang(count%) quad% = (((angle% + 2048) AND 2047) \ 512) m0& = tantable&(angle% AND 1023) m1& = tantable&((2560 - angle%) AND 1023) x = 65535: y = 65535 c0& = posy% - posx% * (m0& / 65536) c1& = posx% - posy% * (m1& / 65536) FOR z% = 0 TO numlines% - 1 IF ki%(z%) = 0 THEN divit& = (m2&(z%) - m0&) \ 2& IF divit& <> 0 THEN newx = ((c0& + c2&(z%)) * 32768) / divit& newy = ((m0& \ 256) * (newx - posx%)) \ 256 + posy% IF newx >= pt%(z%) AND newx <= pt%(z%) + sp%(z%) THEN IF ABS(newx - posx%) + ABS(newy - posy%) < ABS(x - posx%) + ABS(y - posy%) THEN IF ((quad% AND 2) = 0) = (newy > posy%) THEN IF (((quad% + 1) AND 2) = 0) = (newx > posx%) THEN x = newx: y = newy linum%(count%) = wal%(z%) + INT(((x - pt%(z%)) * 64) / sp%(z%)) * 64 kind%(count%) = z% END IF END IF END IF END IF END IF ELSE divit& = (m2&(z%) - m1&) \ 2& IF divit& <> 0 THEN newy = ((c1& + c2&(z%)) * 32768) / divit& newx = ((m1& \ 256) * (newy - posy%)) \ 256 + posx% IF newy >= pt%(z%) AND newy <= pt%(z%) + sp%(z%) THEN IF ABS(newx - posx%) + ABS(newy - posy%) < ABS(x - posx%) + ABS(y - posy%) THEN IF ((quad% AND 2) = 0) = (newy > posy%) THEN IF (((quad% + 1) AND 2) = 0) = (newx > posx%) THEN x = newx: y = newy linum%(count%) = wal%(z%) + INT(((y - pt%(z%)) * 64) / sp%(z%)) * 64 kind%(count%) = z% END IF END IF END IF END IF END IF END IF NEXT z% height%(count%) = 0 IF x <> 65535 THEN yf0% = ((x - posx%) * sintable&((2560 - ang%) AND 2047) + (y - posy%) * sintable&(ang%)) \ 8192 IF yf0% <> 0 THEN height%(count%) = 40960 \ yf0% END IF RETURN DATA 285,040,360,140,0 DATA 360,140,410,140,0 DATA 410,140,470,040,0 DATA 470,040,360,040,0 DATA 360,040,285,040,12288 DATA 285,040,215,070,12288 DATA 215,070,170,110,12288 DATA 170,110,140,170,12288 DATA 140,170,140,230,12288 DATA 140,230,170,290,12288 DATA 170,290,215,330,12288 DATA 215,330,285,360,12288 DATA 285,360,360,360,12288 DATA 360,360,470,360,8192 DATA 470,360,410,260,8192 DATA 410,260,360,260,8192 DATA 360,260,285,360,8192 DATA 240,240,240,260,4096 DATA 240,260,260,260,4096 DATA 260,260,260,240,4096 DATA 260,240,240,240,4096 DATA 240,140,240,160,4096 DATA 240,160,260,160,4096 DATA 260,160,260,140,4096 DATA 260,140,240,140,4096