BigEd wrote:like BBC BASIC's MANDEL command

Did I miss a trick here?
Code: Select all
>10 MANDEL -2,1,1,-1
>RUN

BigEd wrote:like BBC BASIC's MANDEL command
Code: Select all
>10 MANDEL -2,1,1,-1
>RUN
Definitely - just let the native ARM core do all the work and fill up the VDU FIFO.Rich Talbot-Watkins wrote:This being the case, you wouldn't even want to try to share the computation work - just have the co-pro doing the calculations, and host doing the plotting (via a custom WRCH implementation). I suspect the host might even still be the bottleneck in this case!
For reference, this is the usage of the Mandel command that I'm familiar with:BigEd wrote:Oh hang on, that does rather more work than I thought!
Code: Select all
10 MODE 2
20 D% = 16
30 FOR X% = 0 TO 1023 STEP 4
40 FOR Y% = 0 TO 1023 STEP 8
50 MANDEL X% / 1024 * 4 - 2, Y% / 1024 * 4 - 2
60 GCOL C% AND 7
70 POINT Y%, X%
80 NEXT
90 NEXT
No idea why it was included. Because there was the space?Rich Talbot-Watkins wrote: Now I guess I have to ask - why was that ever included in any version of BBC BASIC? And how was it tokenised?!
Code: Select all
Undefined instruction at 80008058
Register dump (stored at &E40) is:
R0 = 00000F00 R1 = 00000001 R2 = 03001570 R3 = 0300156C
R4 = 00000F01 R5 = 00000041 R6 = 83000F04 R7 = 00008000
R8 = 00000F06 R9 = 03001A94 R10 = 00000F06 R11 = 000000C0
R12 = 01000000 R13 = 01000000 R14 = 83000F08 R15 = 80008058
Mode USR flags set: Nzcvif
Finished after 0.14 sec.
Code: Select all
80008050 SWINE WriteI+":"
80008054 2-STLS C0,[R4],#-624
80008058 SWINV WriteI+3
8000805C BEQ &02890E7C
80008060 BGT &001082A0
You need to use the disc that includes Arm BASIC (*AB).Rich Talbot-Watkins wrote:Just tried to run B-Em in "ARM evaluation system" mode to see if it worked, but when I try *BASIC, I get:
Code: Select all
Undefined instruction at 80008058 Register dump (stored at &E40) is: R0 = 00000F00 R1 = 00000001 R2 = 03001570 R3 = 0300156C R4 = 00000F01 R5 = 00000041 R6 = 83000F04 R7 = 00008000 R8 = 00000F06 R9 = 03001A94 R10 = 00000F06 R11 = 000000C0 R12 = 01000000 R13 = 01000000 R14 = 83000F08 R15 = 80008058 Mode USR flags set: Nzcvif Finished after 0.14 sec.
MANDEL was included in ARM BASIC 1.00 (assembled 14th April 1986)Rich Talbot-Watkins wrote:It is indeed! Thanks!
Just out of interest, I powered up my Arthur 0.3 A310 today and had a look for the MANDEL keyword in it's ARM BASIC v1.00, but it's not present.
Interestingly I tried that in Brandy BASIC and it complains that the NEXT s% on line 28 isn't incrementing the current loop control variable.litwr wrote: ↑Sat Oct 29, 2016 3:15 pmThe converted programCode: Select all
10 x=0:y=0:x2=0:y2=0:xy=0:r=0:j=0 11 DIM d(2,319),r(319),j(199):a=0:b=1:c=2 12 r0=-1.9:r1=.5:dr=(r1-r0)/320:FOR s%=0 TO 319:r(s%)=r0+dr*s%:NEXT 13 j0=-0.10:j1=.95:dj=(j1-j0)/200:FOR t%=0 TO 199:j(199-t%)=j0+dj*t%:NEXT 14 n=30 15 MODE 4:TIME=0 16 FOR t%=0 TO 199:j=j(t%):FOR s%=0 TO 319:r=r(s%):x=r:y=j 17 FOR i=1 TO n:x2=x*x:y2=y*y:IF x2+y2<4 THEN xy=x*y:x=x2-y2+r:y=2*xy+j:NEXT 18 d(c,s%)=i:IF i<=n THEN:PLOT 69,4*s%,800-4*t% 19 IF s%<2 OR t%<2 THEN 28 20 IF POINT(4*s%-4,804-4*t%)=0 THEN 28 21 m=d(b,s%-1) 22 IF d(b,s%-2)<m AND d(b,s%)<m THEN 27 23 IF d(a,s%-2)<m AND d(c,s%)<m THEN 27 24 IF d(c,s%-2)<m AND d(a,s%)<m THEN 27 25 IF d(a,s%-1)<m AND d(c,s%-1)<m THEN 27 26 GOTO 28 27 PLOT 70,4*s%-4,804-4*t% 28 NEXT s%:z=a:a=b:b=c:c=z:NEXT:clk=TIME/100:hours=INT(clk/3600):mins=INT(clk/60-hours*60) 29 REM a$=GET$:IF a$="" THEN 29 30 PRINT hours;":";mins;"-";INT(clk-hours*3600-mins*60)
I am not sure about under a minute but that is probably somewhere close. As this is using the proper VDU calls I thought I'd run it in B-Em in Master Turbo mode but with the 2nd proc running much faster and capture the VDU codes being output to a file with *SPOOL. Then I I timed doing a *PRINT of the resulting file. In order to avoid the filing system activity having much effect on the output I used VDFS in B-Em which traps to the host very quickly into the filing system call and makes no attempt to slow things down to 8bit speeds - it executes the I/O operation at host speed. The resulted in a time of 2m28s.
Code: Select all
.chrlp JSR OSWRCH
JSR OSBGET
BCS eof
.found BIT &FF
BPL chrlp
.gotesc LDA #&7E
JSR OSWRCH
.eof LDA #&00
JMP OSFIND
Code: Select all
FF51: 48 PHA
FF52: 48 PHA
FF53: 48 PHA
FF54: 48 PHA
FF55: 48 PHA
FF56: 08 PHP
FF57: 48 PHA
FF58: 8A TXA
FF59: 48 PHA
FF5A: 98 TYA
FF5B: 48 PHA
FF5C: BA TSX
FF5D: A9 FF LDA #FF
FF5F: 9D 08 01 STA 0108,X
FF62: A9 88 LDA #88
FF64: 9D 07 01 STA 0107,X
FF67: BC 0A 01 LDY 010A,X
FF6A: B9 9D 0D LDA 0D9D,Y
FF6D: 9D 05 01 STA 0105,X
FF70: B9 9E 0D LDA 0D9E,Y
FF73: 9D 06 01 STA 0106,X
FF76: A5 F4 LDA F4
FF78: 9D 09 01 STA 0109,X
FF7B: B9 9F 0D LDA 0D9F,Y
FF7E: 85 F4 STA F4
FF80: 8D 30 FE STA FE30
FF83: 68 PLA
FF84: A8 TAY
FF85: 68 PLA
FF86: AA TAX
FF87: 68 PLA
FF88: 40 RTI
Code: Select all
8C07: 8D 5F FC STA FC5F
8C0A: A9 04 LDA #04
8C0C: 8D 5E FC STA FC5E
8C0F: 60 RTS
Code: Select all
FF89: 08 PHP
FF8A: 48 PHA
FF8B: 8A TXA
FF8C: 48 PHA
FF8D: BA TSX
FF8E: BD 02 01 LDA 0102,X
FF91: 9D 05 01 STA 0105,X
FF94: BD 03 01 LDA 0103,X
FF97: 9D 06 01 STA 0106,X
FF9A: 68 PLA
FF9B: AA TAX
FF9C: 68 PLA
FF9D: 68 PLA
FF9E: 68 PLA
FF9F: 85 F4 STA F4
FFA1: 8D 30 FE STA FE30
FFA4: 68 PLA
FFA5: 28 PLP
FFA6: 60 RTS
8A96: B0 09 BCS 8AA1
Basic interpreters allow to have several NEXT for one FOR. This feature is too difficult to support in the modern world of fast compilers...
The 45s was not using a 2nd processor to do the calculations "live" at all.
Code: Select all
static uint MAX = 256;
static uint Calculate(double x, double y)
{
uint n = 0;
double r = x;
double i = y;
double sqi, sqr;
// calculate in chunks
const uint CHUNK = 9;
double tr = r, ti = i;
do
{
if ((n += CHUNK) >= MAX)
return MAX;
sqi = i * i; i = 2d * i * r + y; r = r * r - sqi + x;
sqi = i * i; i = 2d * i * r + y; r = r * r - sqi + x;
sqi = i * i; i = 2d * i * r + y; r = r * r - sqi + x;
sqi = i * i; i = 2d * i * r + y; r = r * r - sqi + x;
sqi = i * i; i = 2d * i * r + y; r = r * r - sqi + x;
sqi = i * i; i = 2d * i * r + y; r = r * r - sqi + x;
sqi = i * i; i = 2d * i * r + y; r = r * r - sqi + x;
sqi = i * i; i = 2d * i * r + y; r = r * r - sqi + x;
sqr = r * r; sqi = i * i;
if (sqi + sqr >= 4d)
break;
i = 2d * i * r + y;
r = sqr - sqi + x;
tr = r; ti = i;
}
while (true);
// overshot, so rewind to start of chunk & reach limit properly
n -= CHUNK;
r = tr; i = ti;
do
{
sqr = r * r; sqi = i * i;
if (sqi + sqr >= 4d)
return n;
i = 2d * i * r + y;
r = sqr - sqi + x;
++n;
}
while (true);
}
I unrolled the iteration loop for my fast 8088 Mandelbrot program, but only for the purpose of getting rid of the final loop branch - I'm still doing the bailout check each iteration (and hence decrementing the iteration counter each time). I haven't measured, but I suspect that the cost of redoing iterations would exceed the cost of the bailout test (especially given the clever optimizations I'm using to reuse work from the bailout test in the actual iterations).
I've got a different mandelbrot that is using nested FOR loops working fine in Brandy. I think the problem stems from line 17, that the NEXT for the FOR i will only be executed if the IF is true - I separated that out to its own line, so it no longer failed with that error, only problem then is it doean't actually do anything, I am not sure where that problem lies.
It would be interesting to see that to compare. Brandy can obviously do nested for loops but its setting an extra constraint compared to Acorn BASICs that the next needs to match the most recent FOR.
The problem is that doing that breaks the algorithm. That bit of basic is equivalent to this in C:Soruk wrote: ↑Mon Jul 09, 2018 5:56 pmI think the problem stems from line 17, that the NEXT for the FOR i will only be executed if the IF is true - I separated that out to its own line, so it no longer failed with that error, only problem then is it doean't actually do anything, I am not sure where that problem lies.
Code: Select all
for (i = 1; i < n; i++) {
x2 = x * x;
y2 = y * y;
if ((x2 + y2) >= 4)
break;
xy = x * y;
x = x2 - y2 + r;
y = 2 * xy + j;
}
Code: Select all
d(c,s%)=i:IF i<=n THEN:PLOT 69,4*s%,800-4*t%