Back to BASIC
I’ve just converted a load of my old BBC BASIC V and ARM Assembler programs from tokenised to ASCII files using Brandy.
Most of my old ASM programs are graphical so don’t work under Brandy, but I guess would under ArcEm, Arculator, or if VirtualAcorn ever do a Linux port.
Here’s one of my favourites – a screensaver I wrote that uses chaos theory to make a “life” simulation. It was so fast I had to slow it down a bit for StrongARM usage….
REM >ChaosARM
REM Uses 264 bytes and no MULs
REM rnd% is a 32-bit RND routine
REM mov% starts with a 1-bit RND routine and ends with a POINT plotter and...
REM ...ESCAPE checker.
:
DIM code% 300
FOR pass%=0 TO 2 STEP 2
P%=code%
[OPT pass%
.rnd%
LDR R0,seed%
LDR R1,c1%
LDR R2,c2%
MLA R0,R1,R0,R2
MLA R3,R1,R0,R2
STR R3,seed%
EOR R0,R0,R3,ROR#16
AND R0,R0,#255
MOV R0,R0,LSL#2
STR R0,x%
LDR R0,seed%
LDR R1,c1%
LDR R2,c2%
MLA R0,R1,R0,R2
MLA R3,R1,R0,R2
STR R3,seed%
EOR R0,R0,R3,ROR#16
AND R0,R0,#255
MOV R0,R0,LSL#2
STR R0,y%
.mov%
LDR R0,seed%
LDR R1,c1%
MOVS R0,R0,LSL#1
EOR CS R0,R0,R1
STR R0,seed%
MOVCC R3,#0
MOVCC R3,R3,LSL#1
MOVCS R3,#1
MOVCS R3,R3,LSL#1
LDR R0,seed%
LDR R1,c1%
MOVS R0,R0,LSL#1
EOR CS R0,R0,R1
STR R0,seed%
OR RCC R3,R3,#0
OR RCS R3,R3,#1
LDR R1,x%
LDR R2,y%
CMP R3,#0
SUBEQ R1,R1,#1
CMP R3,#1
SUBEQ R2,R2,#1
CMP R3,#2
ADDEQ R2,R2,#1
CMP R3,#3
ADDEQ R1,R1,#1
STR R1,x%
STR R2,y%
CMP R1,#1280
BGE rnd%
CMP R2,#1024
BGE rnd%
CMP R1,#0
BLE rnd%
CMP R2,#0
BLE rnd%
MOV R0,#69
SWI"OS_Plot"
SWI"XOS_ReadEscapeState"
BCC mov%
MOV R15,R14
.x% EQUD 0
.y% EQUD 0
.c1% EQUD 1664525
.c2% EQUD 907633393
.seed% EQUD TIME
]NEXT
:
MODE 8
OFF
GCOL 1
CALL code%
Here’s an old standard distribution test from my high school maths days!
REM >RND Procedure Test v2 (SMP)
MODE 0
CLEAR
n_zero%=0
n_one%=0
n_two%=0
n_three%=0
n_four%=0
n_five%=0
n_six%=0
n_seven%=0
n_eight%=0
n_nine%=0
n_ten%=0
:
REPEAT
:
trials%=trials%+1
:
o_count%=0
:
a%=RND(2)-1
b%=RND(2)-1
c%=RND(2)-1
d%=RND(2)-1
e%=RND(2)-1
f%=RND(2)-1
g%=RND(2)-1
h%=RND(2)-1
i%=RND(2)-1
j%=RND(2)-1
:
IF a%=0 o_count%=o_count%+1
IF b%=0 o_count%=o_count%+1
IF c%=0 o_count%=o_count%+1
IF d%=0 o_count%=o_count%+1
IF e%=0 o_count%=o_count%+1
IF f%=0 o_count%=o_count%+1
IF g%=0 o_count%=o_count%+1
IF h%=0 o_count%=o_count%+1
IF i%=0 o_count%=o_count%+1
IF j%=0 o_count%=o_count%+1
:
IF o_count%=0 n_zero%=n_zero%+1
IF o_count%=1 n_one%=n_one%+1
IF o_count%=2 n_two%=n_two%+1
IF o_count%=3 n_three%=n_three%+1
IF o_count%=4 n_four%=n_four%+1
IF o_count%=5 n_five%=n_five%+1
IF o_count%=6 n_six%=n_six%+1
IF o_count%=7 n_seven%=n_seven%+1
IF o_count%=8 n_eight%=n_eight%+1
IF o_count%=9 n_nine%=n_nine%+1
IF o_count%=10 n_ten%=n_ten%+1
:
UNTIL trials%=1000
:
PRINT"0s (N) ";"Freq."
PRINT
PRINT" 0",n_zero%
PRINT" 1",n_one%
PRINT" 2",n_two%
PRINT" 3",n_three%
PRINT" 4",n_four%
PRINT" 5",n_five%
PRINT" 6",n_six%
PRINT" 7",n_seven%
PRINT" 8",n_eight%
PRINT" 9",n_nine%
PRINT"10",n_ten%