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
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment