Re-reading the recent thread on B: B -- A Simple Interpreter Compiler I noticed a Mandelbrot program written in B and I thought it might be nice to translate (back-port?) to BCPL - it’s virtually line for line with a few syntax changes:
GET "libhdr"
LET start() = VALOF
{
LET cx,cy,x,y,x2,y2 = ?,?,?,?,?,?
LET iter = ?
LET xmin,xmax,ymin,ymax,maxiter,dx,dy = ?,?,?,?,?,?,?
xmin := -8601
xmax := 2867
ymin := -4915
ymax := 4915
maxiter := 32
dx := (xmax-xmin)/79
dy := (ymax-ymin)/30
cy := ymin
WHILE cy <= ymax DO
{
cx := xmin
WHILE cx <= xmax DO
{
x := 0
y := 0
x2 := 0
y2 := 0
iter:=0
WHILE iter < maxiter DO
{
IF x2+y2 > 16384 THEN
BREAK
y := ((x*y)/2048)+cy
x := x2-y2+cx
x2 := (x*x)/4096
y2 := (y*y)/4096
iter := iter + 1
}
sawrch (' '+iter)
cx := cx + dx
}
sawrch ('*n')
cy := cy + dy
}
sys (Sys_quit, 0)
RESULTIS 0
}
and of-course it produces the same result:
!!!!!!!!!!!!!!!"""""""""""""####################################""""""""""""""""
!!!!!!!!!!!!!""""""""""########################$$$$$%(&&%%$$$$$######"""""""""""
!!!!!!!!!!!!"""""""#######################$$$$$$$$%%%&)@(&&'%$$$$$######""""""""
!!!!!!!!!!""""""#######################$$$$$$$$$%%%%&'(*00*'&%%$$$$$$######"""""
!!!!!!!!!"""""######################$$$$$$$$$$%%%%&')*[email protected]@,)(&%%%$$$$$$#######""
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''),@@@@@@@,'&%%%%%$$$$########
!!!!!!!"""#####################$$$$$$$$$%%&''''''()*,@@@@@@@*(('&&&&&&%$$$######
!!!!!!"""###################$$$$$$$%%%%&&'*34.,[email protected]@[email protected]@@@@@@@@;@[email protected])(()0)'%$$#####
!!!!!!"##################$$$$%%%%%%%%&&&'()@@@@@@@@@@@@@@@@@@@@@@@@@@@,(%%$$####
!!!!!"###############$$$%%%%%%%%%%%&&&'([email protected]@@@@@@@@@@@@@@@@@@@@@@@@@=+('&%%$$###
!!!!"##########$$$$$%%&(.'''''''''''''(*,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@+)-&%$$###
!!!!"####$$$$$$$$%%%%&&(.2,.*+10++*)))*.>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2+&%$$$##
!!!!##$$$$$$$$$%%%%%&''()[email protected]@@@@@@@@,,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@-*&%$$$##
!!!!#$$$$$$$$%%%%%&,(()[email protected]@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@79'%%$$$$#
!!!#$%%$$$%&&&&&''().1?2<@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*'&%%$$$$#
!!!()**,+9652/1//35>@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@4+)'&&%%$$$$#
!!!#$%%%$%&&&&&'''()[email protected][email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@)'&%%$$$$#
!!!"$$$$$$$$%%%%%%&+())[email protected]@@@@@@@@@@@@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2&%%$$$$#
!!!!##$$$$$$$$$%%%%%&''()=<@@@@@@@@@.,[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/0&%$$$##
!!!!"####$$$$$$$$%%%%&&(,419*+/@+.*)))*.;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@5)&%$$$##
!!!!"#########$$$$$$%%&(-(''''(''''''((*[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@@4+)-&%$$###
!!!!!"###############$$$%%%%%%%%%%&&&&'(,@[email protected]@@@@@@@@@@@@@@@@@@@@@@@@1+('&%%$$###
!!!!!!"##################$$$$%%%%%%%%&&&'()[email protected]@@@@@@@@@@@@@@@@@@@@@@@@@+'%%$$####
!!!!!!""####################$$$$$$%%%%%&&'+94/[email protected]@@@@@@@@@@@[email protected]@))))-*'%$$#####
!!!!!!!"""#####################$$$$$$$$%%%&''''''()*,@@@@@@@*)('&&&&&&%$$$######
!!!!!!!!""""#####################$$$$$$$$$$%%%&&&''(,@@@@@@@+'&&%%%%%$$$########
!!!!!!!!!"""""######################$$$$$$$$$$%%%%&'*[email protected]@,))&%%%$$$$$$#######""
!!!!!!!!!!""""""#######################$$$$$$$$$%%%%&'(*..*'&%%$$$$$$######"""""
!!!!!!!!!!!""""""""#######################$$$$$$$$%%&&)@(''(%$$$$$$#####""""""""
!!!!!!!!!!!!!""""""""""#######################$$$$$$%+'&%%$$$$$######"""""""""""
!!!!!!!!!!!!!!!""""""""""""#####################################""""""""""""""""
It does, however take some 25 seconds to print that using my own BCPL system which I’ve yet to optimise, so I know it can go a lot faster. Still, good (lock down!) retro fun.
Cheers,
-Gordon
Ps. Just an edit to say that my BCPL system is running on WDC 65c816 processor running at 16Mhz and it’s a 32-bit BCPL system. This code is really designed for a 16-bit system and I imagine it would be faster on such a system, clock for clock. On my Linux desktop it runs in about 15mS. It compiles to about 160 bytes of cintcode.