This is what I came up with for controlling 6309 native mode via USR commands.
First, the results. Left is without 6309 native mode, right is with native mode.
Not a huge difference but when run at regular speed that would still save quite a bit of time on the render.
This is the assembly.
Enable:
LDD #$FFFF ; set all bits
CLRD ; 6309 opcode that runs as 8 bit on 6809
TSTB ; did it clear B (16 bit)?
BNE skip ; if not... not a 6309
LDMD #1 ; enable native mode
skip:
RTS
Disable:
LDD #$FFFF ; set all bits
CLRD ; 6309 opcode that runs as 8 bit on 6809
TSTB ; did it clear B (16 bit)?
BNE skip2 ; if not... not a 6309
LDMD #0 ; disable native mode
skip2:
RTS
The BASIC ray tracing code used for the test.
USR0 is used to enable native mode, USR1 is used to disable native mode.
If there wasn't a zero in the code, I could embed it in a string, and use VARPTR to find the address of the string.
0 POKE65495,0:PMODE 4,1:PCLS:SCREEN1,1
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 NATIVE MODE
5 A=USR0(0)
10 SP = 2:O = 0:P = 0.5: DIM C(SP,3),R(SP),Q(SP)
20 FOR K = 1 TO SP: READ C(K,1),C(K,2),C(K,3),T:R(K) = T:Q(K) = T * T: NEXT K
50 FOR I = 0 TO 191: FOR J = 0 TO 255
70 X = 0.3:Y = - 0.5:Z = 0:DX = J - 128:DY = I - 96
72 DZ = 300:DD = DX * DX + DY * DY + DZ * DZ
100 N = - 1: IF Y < = O AND DY > O THEN N = 0:S = - Y / DY
110 FOR K = 1 TO SP:PX = C(K,1) - X:PY = C(K,2) - Y:PZ = C(K,3) - Z
140 SC = PX * DX + PY * DY + PZ * DZ
150 IF SC < = O GOTO 200
155 PP = PX * PX + PY * PY + PZ * PZ
160 BB = SC * SC / DD:AA = Q(K) - PP + BB
180 IF AA < = O GOTO 200
190 SC = ( SQR (BB) - SQR (AA)) / SQR (DD): IF SC < S OR N < O THEN N = K:S = SC
200 NEXT K: IF N < 0 GOTO 350
220 DX = DX * S:DY = DY * S:DZ = DZ * S:DD = DD * S * S:X = X + DX:Y = Y + DY:Z = Z + DZ
240 IF N = O GOTO 300
250 NX = X - C(N,1):NY = Y - C(N,2):NZ = Z - C(N,3)
270 L = 2 * (DX * NX + DY * NY + DZ * NZ) / Q(N)
280 DX = DX - NX * L:DY = DY - NY * L:DZ = DZ - NZ * L: GOTO 100
300 FOR K = 1 TO SP:U = C(K,1) - X:V = C(K,3) - Z: IF U * U + V * V < = Q(K) GOTO 350
320 NEXT K
330 IF ((X - INT (X)) > P) < > ((Z - INT (Z)) > P) THEN PSET(J,I)
350 NEXT J,I
REM DISABLE NATIVE MODE
355 A=USR1(0)
360 GOTO 360
REM USR FUNCTION CODE
11000 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 PROGRAM DATA
12000 DATA -0.3,-0.8,3,0.6
12001 DATA 0.9,-1.1,2,0.2
My on again off again blog about whatever computer related hobby projects I happen to be working on at the moment.
Monday, October 3, 2022
6309 Native Mode USR control
Updated BASIC hardware multiply patch to enable 6309 native mode
I updated my BASIC multiply patch to enable 6309 native mode during the first call to the multiply code. The picture below shows a head to head comparison in the speed difference between the standard ROM code, and with this patch.
Just remember, DO NOT USE DISK COMMANDS WHEN 6309 NATIVE MODE IS ENABLED!
It will cause bad things to happen since the fast interrupt is different in native mode.
I may create a USR function to enable/disable it so native mode is under program control, but for now this will do.
Thanks to L. Curtis Boyle and William Astle for answering questions, and suggestions for 6309 addition.
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. THE +17 ON THE FOR LOOP IS TO ADD THE 6309 SUPPORT
REM REMOVE THAT AND LINE 10004 TO GET RID OF 6309 SUPPORT
REM DO NOT USE DISK ACCESS ONCE NATIVE MODE IS ENABLED!
10001 FORI=0 TO 64+17: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
REM THE FOLLOWING LINE ADDS CODE TO CHECK FOR 6309 DURING FIRST CALL TO MULTIPLY
REM IF 6309 IS FOUND, IT TURNS ON NATIVE MODE. DO NOT DO DISK ACCESS IN NATIVE MODE. PRESS RESET WILL TO TURN IT OFF
10004 DATA CC,FF,FF,10,4F,5D,26,03,11,3D,01,30,8C,03,BF,BB,03
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