In case you couldn't tell, I was on a BASIC kick recently. Another port I posted to facebook.
"This BASIC code represents the Lorentz attractor for Commodore 64."
Here is a port of one I got from a Commodore group. The original C64 code is there but with REM in front of the lines that changed. Delete lines 1-4, lines 1000 on, and change the POKE to 65495 to run this on a CoCo 1/2.
Another port I recently posted on facebook. It's a fractal program in BASIC I ported to the Color Computer. Stuff like this doesn't take long to port and it's kinda fun to play with.
REM SET COCO3 TO HIGH SPEED MODE, SET UP A PMODE4 SCREEN, AND INSTALL THE MULTIPLY PATCH
The header on this was left intact to give credit to the original author Hal Chamberlin, and Allen Murphey who ported it to the Tandy Color Computer. I made significant optimizations to the code such as putting constants in variables, only printing the minimum text needed, adding the hardware multiply patch, math logic optimizations, etc... which lets the code run in about half the original time. I also added an improved graph of the data that simply draws lines between the data points to make the waveform look better. The original version is posted on facebook in the 'I'm a CoCO Nut' group about a year ago (April 2021).
The code looks a bit cryptic after the optimizations, but converting constants from ASCII to floating point is time consuming, and the interpreter has to do it every time a constant is used.
This update flips the graph to account for the difference between the standard X/Y coordinate layout which starts in the lower left corner with Y increasing as it goes up, and the screen layout where coordinates start in the upper left corner with Y increasing as it goes down the screen. The multiply patch code is now grouped with the data to make it easier to add to other programs.
This is the video I made last year that compared the original code to the optimized code. It does not show the flip in the Y axes.
100 REM FIG. 13-7 PROGRAM TO OPTIMALLY FILL WAVEFORM TABLES 110 REM MUSICAL APPLICATIONS OF MICROPROCESSORS 120 REM COPYRIGHT 1985 BY HAL CHAMBERLIN AND HAYDEN BOOKS 130 REM SEE TABLE FILLING BY FOURIER SERIES, PAGE 432 140 REM HTTPS://ARCHIVE.ORG/DETAILS/MUSICALAPPLICATI00CHAM 150 REM COCO EXTENDED COLOR BASIC MODIFICATIONS 160 REM BY R. ALLEN MURPHEY 170 REM FOR HTTP://DISCORD.COCOTALK.LIVE #ORCH90-COCODAC-16 CHANNEL 180 REM YOU PROBABLY WANT THIS POKE &HFFD9,0 1000 REM PROGRAM TO UTILIZE THE FOURIER SERIES TO FILL A WAVEFORM TABLE 1010 REM ARRAY A HOLDS THE AMPLITUDES OF THE HARMONICS 1020 REM ARRAY P HOLDS THE PHASES OF THE HARMONICS 1030 REM THE ZEROTH ELEMENT OF A AND P CORRESPONDS TO THE DC COMPONENT 1040 REM VARIABLE N HOLDS THE NUMBER OF THE HIGHEST HARMONIC TO PROCESS 1050 REM VARIABLE M HOLDS THE SIZE OF THE TABLE TO GENERATE 1060 REM VARIABLE Q IF 0 SELECTS RANDOM PHASES, IF 1 USES ARRAY P 1070 REM ARRAY T IS THE GENERATED TABLE WITH ALL ENTRIES BETWEEN BUT NOT 1080 REM INCLUDING -1 AND +1
REM 1090 DIM T(256):I=10:J=I
1090 I=10:J=I 1140 N=I 1150 M=256 1160 Q=1 2 Z=0:O=1:J=Z:I=Z:DIM T(256):A1=Z:A2=Z:S=6.28318:G=.99999:V=96:H=32:P=13 1200 REM SET UP THE AMPLITUDE AND PHASE ARRAYS
1210 FOR I=Z TO N:READ A(I):NEXT
1240 FOR I=Z TO N 1250 IF Q=Z THEN P(O)=RND(O):NEXT:GOTO 1300 1260 READ P(I) 1280 NEXT
1300 REM MAIN LOOP TO COMPUTE PRELIMINARY TABLE CONTENTS 1301 REM AND SCAN RESULTING TABLE FOR MAXIMUM ABSOLUTE VALUE
1305 F=S/M 1306 PRINT@Z,"SIN GEN STEP: OF 255"; 1310 FOR I=Z TO M-O 1315 PRINT@P,I;:T(I)=Z:A1=I*F 1340 FOR J=Z TO N:T(I)=T(I)+A(J)*COS(J*A1+S*P(J)):NEXT 1365 E=ABS(T(I)):IF E > A2 THEN A2=E 1370 NEXT
1500 REM NORMALIZE THE TABLE 1505 F=O/A2*G:FOR I=Z TO M-O:T(I)=T(I)*F:NEXT
1600 REM ADD CODE HERE TO OUTPUT THE TABLE IN SUITABLE FORM 1700 PMODE 4,1:PCLS:SCREEN 1,1 REM A2-# CONVERTS FROM STANDARD COORDINATE LAYOUT TO SCREEN LAYOUT 1730 FOR I=O TO M-O:LINE(I,V+INT(A2-T(I-O)*H))-(I,V+INT(A2-T(I)*H)),PSET:NEXT
1760 A$=INKEY$ 1770 IF A$="" THEN 1760 1800 END
REM COCO3 HARDWARE MULTIPLY PATCH BY JAMES DIFFENDAFFER. 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
0 POKE 65497,0:CLS:GOSUB10000
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 10004 DATA 32,79,E7,60,96,60,3D,ED,63,E6,60,96,5E,3D,ED,61,E6,60,96,5D 10005 DATA 3D,ED,65,E6,60,96,5F,3D,E3,62,ED,62,EC,65,E9,61,89,00,ED,60 10006 DATA EC,63,D3,15,97,16,D7,63,EC,61,D9,14,99,13,DD,14,A6,60,89,00 10007 DATA 97,13,32,67,39
REM ORIGINAL DATA FROM THE TOP OF THE CODE MOVED REM TO ACCOUNT FOR THE MULTIPLY PATCH DATA
11000 REM AMPLITUDE DATA 11010 DATA 0,.8,.6,.2,.55,1.0,.7,.3,.2,.1,.05 11020 REM PHASE DATA 11030 DATA 0,0,.2,.4,.7,.45,.1,.5,.85,.9,0
This code is from an article in COMPUTE! magazine I was pointed to when I tried porting some BASIC raytracing code to the Apple II. It's not quite what I needed for that, but it does support some things I added to the latest MC-10 ROM I've been working on. It took a couple hours to reverse engineer it back to source code. I didn't look up the ROM calls or BASIC tokens, but for the most part I thought that was obvious. Since I haven't used the 6502 in a while there may be a couple syntax issues, but it should be easy to fix if there are.
One possible change is the comment related to P.PWR. That may be the current DATA pointer.
Apple enhancer file maker
10 FOR I = 768 TO 887: READ A : POKE I,A:CK = CK + A: NEXT 20 IF CK < > 14482 THEN PRINT"ERROR IN DATA STATEMENTS.": STOP 30 PRINT CHR$ (4)"BSAVE APPLE.ENHANCER,A$300,L$77" 40 DATA 169,76,141,245,3,169,16,141 50 DATA 246,3,169,3,141,247,3,96 60 DATA 160,0,177,184,217,115,3,240 70 DATA 11,200,192,3,240,3,76,20 80 DATA 3,32,201,222,140,118,3,230 90 DATA 184,208,2,230,185,32,103,221 100 DATA 172,118,3,192,1,240,10,192 110 DATA 2,240,35,32,82,231,76,65 120 DATA 217,169,3,32,214,211,165,185 130 DATA 72,165,184,72,165,118,72,165 140 DATA 117,72,169,176,72,32,82,231 150 DATA 32,65,217,76,210,215,32,82 160 DATA 231,32,26,214,56,165,155,233 170 DATA 1,164,156,176,1,136,133,125 180 DATA 132,126,96,171,176,174,0,0
;****************************************** ;* Program: ;* APPLE.ENHANCER ;* COMPUTE! ISSUE 72 / MAY 1986 / PAGE 75 ;****************************************** ;* Author: ;* Mark Russinovich ;* ;* Disassembly: ;* James Diffendaffer ;****************************************** ;* Expands Applesoft BASIC to use a variable containing a line number as a parameter for the following keywords: ;* & GOTO ;* & GOSUB ;* & RESTORE ;******************************************
; code start org $0300
; change the BASIC RAM hook to JMP to our patch lda #$4c ; opcode for jmp sta $3f5 lda #<L0310 ; LSB of the patch entry point sta $03f6 lda #>L0310 ; MSB of the patch entry point sta $03f7 rts ; return after patching BASIC
; entry point for expanded BASIC functions L0310: ldy #$00 ; clear Y for no offset from pointer lda (TXTPTRL),y ; get current character pointed to by BASIC parser
; is it one of the tokens? L0314: cmp L0373,y beq L0324 ; branch if it is iny ; next address cpy #$03 ; only loop 2 times beq L0321 ; branch to Syntax Error jmp L0314 ; loop
; bne L0314 ; loop (replaces previous 2 lines)
L0321: jsr SYNERR ; exit with Syntax Error? $DEC9 sty L0376 ; save inc <TXTPTR ; increment LSB of current program execution pointer bne L032D inc >TXTPTR ; increment MSB of current program execution pointer L032D: jsr FRMNUM ; jump to format number $DD67 ldy L0376 ; load TOKEN from temp cpy #$01 ; GOSUB? beq L0341 ; cpy #$02 ; RESTORE? beq L035e jsr GETADR ; get address from variable jmp $d941 ; call to ROM GOTO code following line # parse ?
; & GOSUB variable L0341: lda #$03 ; how much space we need on the stack jsr CHKMEM ; is there enough memory?
; Does CHKMEM give an error or did this code just ignore it?
; push info for BASIC's RETURN from GOSUB on to stack ; ; push the current program parse pointer onto the stack lda >TXTPTR ; MSB pha lda <TXTPTR ; LSB pha ; push the current line number onto the stack lda >CURLIN pha lda <CURLIN pha ; push type of stack frame onto stack lda #$b0 ; GOSUB token pha
L0355: ; get address from variable jsr GETADR jsr $D941 ;?? jmp NEWSTT ; jump to new start address GOTO GOSUB
; & RESTORE variable or # L035e: jsr GETADR ; get address jsr FNDLIN ; find the line sec lda LOWTR
sbc #$01 ; decrement LOWTR ldy EXPSGN ; put EXPSGN bcs L036e ; dey ; save address returned in A & Y L036e: sta P.PWR sty P.PWR+1 rts L0373: dcb $AB ; Applesoft GOTO token L0374: dcb $B0 ; Applesoft GOSUB token L0375: dcb $AE ; Applesoft RESTORE token L0376: $00,$00 ; variables
This article pretty much confirms what I suspected, but the author explains it pretty well. The only thing really missing is how the "magic number" was derived to minimize the error. This is just speculation on my part, but I see two potential approaches. The first would be to pick some mid point value that reduces the maximum error for any legal number (within the range of floating point numbers). The second would be to pick a value that is the mid point for the most common values a program uses, thus minimizing the error for that program more than for any value. The first would be easy to calculate, the 2nd would require a lot of number logging & crunching. https://betterexplained.com/articles/understanding-quakes-fast-inverse-square-root/
Back in the 80s I was a partner in and vice president of a software business called Designing Minds, Inc.
Here are a few of the programs we produced. All of these are based on my runtime library, as was the Talking Storybook series, yet I somehow didn't get my name on any of the Copyrights. Gee, why did I ever leave? Link
I was also president, and a partner in an Amiga hardware company.
Here is one of the Amiga drives we made: Link
This is the MC-10 memory map copied from the service manual, but with a few minor changes.
The address decoding inside the MC-10 is "minimal", so the Keyboard/VDG I/O responds over a full 16K area, but internal address decoding can be disabled by external expansion devices.
Programmer's should only use the top of that address range to access that hardware.
The MC-10 only includes 4K of RAM internally, but hi-res 256x192 2 color (RG6), and 128x192 4 color (CG6) modes require 6K. The 6847 VDG's buss is isolated from the expansion connector on the back of the machine, and the top address line isn't even connected, so you can't just plug in a RAM expansion to use hi-res modes. The hardware mod was published in a CoCo magazine shortly after the machine was released, but I'll have to look up what magazine. (Color Computer Magazine maybe?)
Making matters worse, the ROM places BASIC system variables, and interrupt vectors in the upper part of the internal 4K of RAM, so to use hi-res graphics you need a new BASIC, or to disable the ROMs. I've been working on a new ROM, so this is trivial for emulators.
MC-10 Memory map from the service manual
Hex Address
C000 - FFFF 16K ROM (only upper 8K used)
9000 - BFFF 16K I/O Slot (Keyboard, VDG control, and sound)
4000 - 8FFF 16K RAM (4K - 20K used) (video starts at $4000)
0100 - 3FFF Not Used
0080 - 00FF RAM internal to the 6803
0015 - 007F Not Used
0014 RAM Control Register
0013 Not Used
0012 Not Used
0011 Not Used
0010 Not Used
000F Port 3 Control and Status Register
000E Input Capture Register (low byte)
000D Input Capture Register (high byte)
000C Output Compare Register (low byte)
000B Output Compare Register (high byte)
000A Counter (low byte)
0009 Counter (high byte)
0008 Timer Control and Status Register
0007 Not Used
0006 Not Used
0005 Not Used
0004 Not Used
0003 Miscellaneous I/O Data Register
0002 Keyboard Output Lines
0001 Data Direction Register for miscellaneous I/O
0000 Data Direction Register for keyboard lines