Wednesday, October 19, 2022

Fedora 3D Plot Update

Just updating some code I wrote in 2015 to add support for the 6309 native mode control.
It runs in just over 11.7 minutes on the CoCo 3. 
The Apple II version took around 32 minutes to complete, and 22 minutes after it was compiled with the Einstein BASIC compiler.

Here is a comparison of without vs with the hardware multiply patch, and 6309 native mode.  I'm still not sure the timing of this emulator is accurate, so YMMV.





0 TIMER=0:POKE 65497,0

REM GET BASIC TOPRAM POINTER, SUBTRACT SIZE OF USER CODE
1 AD=PEEK(116)*256+PEEK(117)-24

REM RESERVE MEMORY FOR USR CODE
2 CLEAR 100,AD

REM VARIABLES ERASED BY CLEAR, SO REDO AD, POKE USR CODE INTO RAM
3 AD=PEEK(116)*256+PEEK(117):FOR I=0 TO 23:READ B$:A=VAL("&H"+B$):POKE AD+I,A:NEXT

REM DEFINE USR ROUTINES
4 DEFUSR0=AD:DEFUSR1=AD+12

REM ENABLE 6309 NATIVE MODE
5 A=USR0(0)

10 GOSUB 10000


100 SX=144:SY=56:SZ=64:CX=320:CY=192
110 C1=2.2*SY:C2=1.6*SY
120 DIM RR(CX)
130 FOR I=0 TO CX:RR(I)=CY:NEXT I
140 HSCREEN 2
150 CX=CX*0.5:CY=CY*0.46875:FX=SX/64:FZ=SZ/64
160 XF=4.71238905/SX
170 FOR ZI=64 TO -64 STEP -1
180   ZT=ZI*FX:ZS=ZT*ZT
190   XL=INT(SQR(SX*SX-ZS)+0.5)
200   ZX=ZI*FZ+CX:ZY=CY+ZI*FZ
210   FOR XI=0 TO XL
220     A=SIN(SQR(XI*XI+ZS)*XF)
230     Y1=ZY-A*(C1-C2*A*A)
240     X1=XI+ZX
250     IF RR(X1)>Y1 THEN RR(X1)=Y1:HSET(X1,Y1)
260     X1=ZX-XI
270     IF RR(X1)>Y1 THEN RR(X1)=Y1:HSET(X1,Y1)
280   NEXT XI
290 NEXT ZI
300 PRINT"TIME",TIMER/60

310 A=USR1(0):END


REM USR functions to enable/disable 6309 native mode
9000 DATA CC,FF,FF,10,4F,5D,26,03,11,3D,01,39,CC,FF,FF,10,4F,5D,26,03,11,3D,00,39

REM COCO3 HARDWARE MULTIPLY PATCH.
REM JUST ADD A GOSUB 10000 AT THE TOP OF YOUR CODE TO ADD IT

REM ADDRESS WE ARE STORING THE MULTIPLY PATCH IN RAM
10000 AD=VAL("&HFA0C")

REM POKE THE MULTIPLY PATCH INTO RAM.
10001 FORI=0 TO 64:READ B$:A=VAL("&H"+B$):POKE AD+I,A:NEXT

REM MAKE BASIC JUMP TO OUR MULTIPY INSTEAD OF USING IT'S CODE. $BB00 JMP $FA0C
10002 POKE VAL("&HBB02"),VAL("&H7E"):POKE VAL("&HBB03"),VAL("&HFA"):POKE VAL("&HBB04"),VAL("&H0C")

10003 RETURN

10005 DATA 32,79,E7,60,96,60,3D,ED,63,E6,60,96,5E,3D,ED,61,E6,60,96,5D
10006 DATA 3D,ED,65,E6,60,96,5F,3D,E3,62,ED,62,EC,65,E9,61,89,00,ED,60
10007 DATA EC,63,D3,15,97,16,D7,63,EC,61,D9,14,99,13,DD,14,A6,60,89,00
10008 DATA 97,13,32,67,39

1 comment:

  1. Change these lines for 640x192

    100 SX=288:SY=56:SZ=64:CX=640:CY=192
    140 HSCREEN 3



    Change these lines for 256x192

    0 TIMER=0:POKE 65495,0
    100 SX=110:SY=56:SZ=64:CX=256:CY=192
    140 PMODE4,1:PCLS:SCREEN1,1
    250 IF RR(X1)>Y1 THEN RR(X1)=Y1:PSET(X1,Y1)
    270 IF RR(X1)>Y1 THEN RR(X1)=Y1:PSET(X1,Y1)

    REM THIS LINE FOR COCO1/2
    10

    ReplyDelete