08-21-2003, 11:24 AM
Let's all try to optimize this piece of code I made.
Rules:
1. No rules. Just make it faster!!!
Yeah, no call absolute. *;*)
Rules:
1. No rules. Just make it faster!!!
Yeah, no call absolute. *;*)
Code:
'Okay I was bored ;*)
'SetVideoSeg by Plasma357(Jon Petrosky)
'Happy coding Relsoft
'Yes, unoptimized code. ;*)
DECLARE SUB WuPixel (x!, y!, col%)
DECLARE SUB SetVideoSeg (Segment%)
DEFINT A-Z
DIM coords%(5, 1)
'$DYNAMIC
DIM SHARED Vpage(32009) 'an extra 16 bytes are needed so that the image
Vpage(6) = 2560 'can be aligned evenly on a segment (the 4 bytes for
Vpage(7) = 200 'the x and y sprite size normally throw this off, so
Layer = VARSEG(Vpage(0)) + 1 'we have to shift everything over 12 bytes
PI! = 3.141593
Radius = 40 'Radius of the circle
TiltMag = 2
CLS
SCREEN 13
FOR I = 0 TO 255
OUT &H3C8, I
OUT &H3C9, I \ 4
OUT &H3C9, I \ 4
OUT &H3C9, I \ 4
NEXT I
SetVideoSeg Layer 'Set the Drawing to the buffer
DO
LINE (0, 0)-(319, 199), 0, BF
F& = (F& + 1) AND &H7FFFFFFF
x% = SIN(F& / 120) * 160
y% = COS(F& / 150) * 100
xlis% = x% + 160
ylis% = y% + 100
xlis2% = 320 - xlis%
ylis2% = 200 - ylis%
I = (I + TiltMag) MOD 360
aa2! = I * PI! / 180
FOR angle = 0 TO 359 STEP 5
a! = angle * PI! / 180
a2! = a! - aa2!
a2! = a! + I * 3.14153 / 180
x! = COS(angle * 3.141593 / 180 + a!) * Radius
y! = SIN((x!) * 3.141593 / 180 + a2!) * Radius
x! = COS(y! * 3.141593 / 180 + a!) * Radius
y! = SIN((x!) * 3.141593 / 180 + a2!) * Radius
x2! = -y!
y2! = x!
WuPixel xlis% + x!, ylis% + y!, 255
WuPixel xlis% + x2!, ylis% + y2!, 255
'''2nd
WuPixel xlis2% + x!, ylis2% + y!, 255
WuPixel xlis2% + x2!, ylis2% + y2!, 255
NEXT angle
SetVideoSeg &HA000 'Set draw to Screen
'WAIT &H3DA, 8
PUT (0, 0), Vpage(6), PSET 'Blit Dbuffer
SetVideoSeg Layer 'Restore Draw to buffer
LOOP UNTIL INKEY$ <> ""
END
REM $STATIC
SUB SetVideoSeg (Segment) STATIC
DEF SEG
IF VideoAddrOff& = 0 THEN ' First time the sub is called
' We need to find the location of b$AddrC, which holds the graphics
' offset (b$OffC) and segment (b$SegC). Since b$AddrC is in the default
' segment, we can find it by setting it to a certain value, and then
' searching for that value.
SCREEN 13 ' Set b$SegC to A000 (00A0 in memory)
PSET (160, 100), 0 ' Set b$OffC to 7DA0 (not needed in the IDE)
FOR Offset& = 0 TO 32764 ' Search for b$AddrC, which is
IF PEEK(Offset&) = &HA0 THEN ' in the default segment and
IF PEEK(Offset& + 1) = &H7D THEN ' should have a value of
IF PEEK(Offset& + 2) = &H0 THEN ' A0 7D 00 A0.
IF PEEK(Offset& + 3) = &HA0 THEN
VideoAddrOff& = Offset& + 2 ' If we found it, record the
EXIT FOR ' offset of b$SegC and quit
END IF ' looking. (Oddly, changing
END IF ' the b$OffC doesn't seem to
END IF ' do anything, so this is why
END IF ' this sub only changes b$SegC)
NEXT
END IF
' Change b$SegC to the specified Segment
POKE VideoAddrOff&, Segment AND &HFF
POKE VideoAddrOff& + 1, (Segment AND &HFF00&) \ &H100
END SUB
SUB WuPixel (x!, y!, col)
x1 = FIX(x!)
y1 = FIX(y!)
x2 = x1 + 1
y2 = y1 + 1
xm! = x! - x1
ym! = y! - y1
xm2! = (1 - xm!)
ym2! = (1 - ym!)
c1 = xm2! * ym2! * col
c2 = xm! * ym2! * col
c3 = xm2! * ym! * col
c4 = xm! * ym! * col
PSET (x1, y1), c1
PSET (x2, y1), c2
PSET (x1, y2), c3
PSET (x2, y2), c4
END SUB