APRICOT – A PRogrammable Interactive Calculate O Tron

What a weird name, but I wanted something with calculate and tron it it, so there you go…

What is it?

APRICOT is a programmable calculator. A very simple one but it’s quite effective and Turing Complete if you want that sort of thing.

Why?

Many years back I wrote what I considered my ideal BASIC – I wrote it in C and have enjoyed using it over the years. I’ve shared it and there are a few active users out there too.

I did feel that while it was a good, full-featured modern implementation of a traditional BASIC that it was a bit big. I could not even think about running it on an old (or retro) 8-bit CPU so have looked at various “Tiny” BASICs and other languages, etc. (Except Forth or Forth-like languages. I am simply not interested in these). One that caught my eye was VTL and VTL-2 which can run on a 6502 CPU in under 1KB of RAM.

Trying to port VTL-2 to my own Ruby 6502 system proved to be a little problematic – mostly due to the amount of Zero-Page required, so in the best traditions of time, ie. How Hard Can It Be? I decided I’d write my own little language.

Inspiration?

So VTL-2 may have been an inspiration, but my thoughts went back to my first programmable calculator the Casio FX-502P. Also my favourite behemoth of a calculator; The Harwell Computer, or WITCH.

What to write it in?

My initial thoughts were to write it in 65C02 assembly language – that might make it accessible to most folks who have 65C02 SBCs or older systems with a 65C02 CPU.

That hasn’t happened – yet.

I started in BCPL because I have a 65C816 system that can run BCPL (and edit and compile BCPL directly on-board) I thought it might be quicker to get the ideas and basics flashed out in a higher level language then hand-translate it into 6502 code.

It was quicker to get going and I had the basics going in a few hours, but being one of 2 or maybe 3 other BCPL programmers in the world, it’s not that accessible, so to make it a little more accessible, I re-wrote it in C. Currently I’m keeping the BCPL and C versions in-step with each other.

What’s in a number?

I decided that to keep things simple and in the traditions of VTL-2 and various Tiny BASICs that I’d stick to integers – specifically 32 bit signed integers. Apple Integer BASIC was only 16-bits and good enough at the time but the BBC Micro supports 32-bit integers so 32-bit it was.

Interactively it works just like an old-school calculator. There is no operator precedence as such and operators are actioned when they are entered. So 1+2*3 is 9 and not 7 as some people might expect.

How to get it?

Head over to the downloads page to get the manual and the C source code along with some examples and even a couple of games…

You will need to know how to unpack a .TGZ file and compile a C program to use it. There is a short README file there but not a lot else…

tl;dr:

cd /tmp
mkdir apricot
cd apricot
wget https://project-downloads.drogon.net/apricot/apricot.tgz
tar xfz apricot.tgz
cd apricot-c
make
cd ../examples
../apricot-c/apricot
--- then load an example or 2
--- see the apricot.pdf for full documentation.

A short example

This is a recursive factorial function..

"Number? " ? ;F
"Factorial is: " . #
_

`Factorial
(F
  = T - 1 [ T \ T ) 1] ` If T is 1 then return
  , - 1 ;F = T ' * T )

and this is integer square root:

` Integer Square root
` Herons Method
` Uses S
` Uses but preserves X and Y.

(Q
  = S
  > 2 [ \ S ) ]
  X,Y,
  S / 2 = X
  S / X + X / 2 = Y
  1[
    Y = X
    S / X + X / 2 = Y
    Y < X ]
  X = S
  '=Y '=X S
)

Is an esoteric language? I don’t know, but it is quite usable though. At least I think so!

Comments are closed.