6502 emulation on Gigatron
Re: 6502 emulation on Gigatron
Hmm, it doesn't seem to like line 50. I entered it, it lists as blank, and I can't add line 60 either.
Re: 6502 emulation on Gigatron
I'll have to call Bill Gates for advice
Re: 6502 emulation on Gigatron
After a lengthy phone conversation, the line 50 issue is found. However, Bill noted that "DIV" and "VDU7" are still "?SYNTAX ERROR's" [his words].
Edit: And so are "FOR J%" and "FOR I%". I tried to fix the program, but the interpreter then crashes. So another debugging session is called for.
Edit: And so are "FOR J%" and "FOR I%". I tried to fix the program, but the interpreter then crashes. So another debugging session is called for.
Re: 6502 emulation on Gigatron
Thanks for the fix! I do believe I've read somewhere that MS Basic doesn't allow loop variables to be integers, so that's most likely as expected. VDU 7 is just a beep, and in this case DIV is rather like divide, possibly with an INT, so we should be good to go.
Re: 6502 emulation on Gigatron
Right - DIV is provided in floating-point BASICs to explicitly perform an integer division, usually accompanied by a MOD keyword to provide the corresponding remainder. In an integer BASIC there is no need for them.
Re: 6502 emulation on Gigatron
Hmm, next obstacle with the Pi spigot, I get an out of memory error at line 90. Is the expression too complex? I'd only entered up to line 110 and ran with an input of 9.
Re: 6502 emulation on Gigatron
As said:
Regarding out of memory: It should be able to do two FOR levels. (Three levels is still too much.)
mvk wrote:
I tried to fix the program, but the interpreter then crashes. So another debugging session is called for.
Last edited by mvk on Thu Oct 24, 2019 11:33 am, edited 2 times in total.
Re: 6502 emulation on Gigatron
Chromatix wrote:
Right - DIV is provided in floating-point BASICs to explicitly perform an integer division, usually accompanied by a MOD keyword to provide the corresponding remainder. In an integer BASIC there is no need for them.
Re: 6502 emulation on Gigatron
Oh, sorry, I missed that there was still work in progress.
(In this case, / will work just as well as DIV - the change from / to DIV was purely for performance on a Beeb.)
(In this case, / will work just as well as DIV - the change from / to DIV was purely for performance on a Beeb.)
Re: 6502 emulation on Gigatron
I wonder if all that %-fuss really makes much of a difference. All calculations are done as floating point anyway. Even the "bytes free" message is printed by the floating point routine.
Re: 6502 emulation on Gigatron
It certainly helps in BBC Basic, and I think I've seen it help in MS Basic in the past. That's when I would have come across the oddity that loop variables must be floats.
Re: 6502 emulation on Gigatron
All these back-and-forth conversions make integer variables slower in MS BASIC. I can only see their point in large arrays. This is easy to test:
Result in video mode 3: This is not a completely fair comparison because the GOTO20 is a bit faster than the GOTO50. But if you remove line 10-40, the integer loop still runs slower (3337 ticks).
This now also gives us our apples-to-apples benchmark reference, without having to port another Pi program (we already have one for TinyBASIC of course).
Hmm, I wonder how we can compute their ratio? Oh wait, there's only one way that's appropriate:
Wow: non-trivial machine code v6502 is only 5.7 times slower than the real thing?! Perhaps that's too good to be true, Edit: but confirmed by a stopwatch. This debunks the "v6502 is 10 times slower than the original 6502"-myth, and refines our earlier "8x slowdown" guesstimate. In reality we're running very close to 75 KIPS, or 3 instructions per scanline. Sweet
Result in video mode 3: This is not a completely fair comparison because the GOTO20 is a bit faster than the GOTO50. But if you remove line 10-40, the integer loop still runs slower (3337 ticks).
This now also gives us our apples-to-apples benchmark reference, without having to port another Pi program (we already have one for TinyBASIC of course).
Hmm, I wonder how we can compute their ratio? Oh wait, there's only one way that's appropriate:
Wow: non-trivial machine code v6502 is only 5.7 times slower than the real thing?! Perhaps that's too good to be true, Edit: but confirmed by a stopwatch. This debunks the "v6502 is 10 times slower than the original 6502"-myth, and refines our earlier "8x slowdown" guesstimate. In reality we're running very close to 75 KIPS, or 3 instructions per scanline. Sweet
Re: 6502 emulation on Gigatron
BigEd wrote:
Hmm, next obstacle with the Pi spigot, I get an out of memory error at line 90. Is the expression too complex? I'd only entered up to line 110 and ran with an input of 9.
Re: 6502 emulation on Gigatron
I hacked CHRGET such that it doesn't need to be copied to the zero page. It means there's a 3.5% speed penalty, as a proper solution is way too much work. But it appears to give your program just enough stack space to run to completion. From the commit notes:
Updated MSBASIC.gt1 binary is in GitHub as well.
Code: Select all
commit f87436760c751280d22ad3586ea0ea55e01bbad2 (HEAD -> master, master/master)
Date: Tue Oct 29 11:35:16 2019 +0100
MSBASIC: Don't copy CHRGET/CHRGET to zero page
To free up more zero page and allow for a deeper stack. TXTPTR is
still in zero page, so the program doesn't grow a lot. We now do:
sty SCRATCH
ldy #0
lda (TXTPTR),y
ldy SCRATCH
instead of:
TXTPTR=*+1
lda 60000 ; Self modifying operand
All this incurs a slow down of 3.5% in benchmarks. This speed might
be won back if we put the responsibility of saving Y to the caller
(as must have been done in CBM-128 BASIC 7.0). But there are so many
calling sites, this can be too much work.
This benchmark now works:
10 INPUT"HOW MANY DIGITS";N
20 T=TIME
30 L=INT(10*N/3)+1:DIM A(L)
40 Z$="000000":T$="999999"
50 FOR I=1TOL:A(I)=2:NEXT
60 M=0:P=0
70 FOR J=1TON:Q=0:K=2*L+1
80 FOR I=L TO 1 STEP -1
90 K=K-2:X=10*A(I)+Q*I
100 Q=INT(X/K):A(I)=X-Q*K
110 NEXT
120 Y=INT(Q/10):A(1)=Q-10*Y:Q=Y
130 IF Q=9 THEN M=M+1:GOTO170
140 IF Q>9 THEN PRINT CHR$(49+P);LEFT$(Z$,M);:GOTO170
150 PRINT CHR$(48+P);LEFT$(T$,M);
160 P=Q:M=0
170 NEXT
180 PRINT CHR$(48+P)
190 PRINT (TIME-T)/60
Results:
Micro-Soft BASIC 28 digits 510 s (radix 10)
Micro-Soft BASIC 14 digits 130 s (radix 10)
For reference:
10 REM 28 digits of pi
20 M=94:FOR I=0 TO M-1
30 Z(I)=20:NEXTI:?"PI=";
40 E=D%100:D=0:FORI=1TOM
50 J=M-I:D=D+D*J+Z(J)*100
60 A=J+J+1:Z(J)=D%A:D=D/A
70 NEXTI:M=M-6:E=E+D/100
80 ?E/10;:IF M=88 ?".";
90 ?E%10;:IF M>10 GOTO 40
Result:
Tiny BASIC 28 digits 65 s (radix 100)
Re: 6502 emulation on Gigatron
Hurrah! Well done.