
The Apple II Source Code for the LOGO Language Found - mmastrac
https://blog.adafruit.com/2018/10/04/the-apple-ii-source-code-for-the-logo-language-found/
======
DonHopkins
This is wonderful!

My first paid programming job was writing a Logo Adventure program for C64
Terrapin Logo. They wanted a simple non-graphical game that showed off Logo's
list processing capabilities, and I just used Logo's top level interpreter as
the parser! That saved a lot of coding, but it did let you cheat (aka "learn
to understand and program and debug Logo").

[https://medium.com/@donhopkins/logo-adventure-
for-c64-terrap...](https://medium.com/@donhopkins/logo-adventure-
for-c64-terrapin-logo-4c684a240b53)

Here is the source code to LLogo in MACLISP, which I stashed from the MIT-AI
ITS system. It's a fascinating historical document, 12,480 lines of beautiful
practical lisp code, defining where the rubber meets the road, with drivers
for hardware like pots, plotters, robotic turtles, TV turtles, graphical
displays, XGP laser printers, music devices, and lots of other interesting
code and comments.

[http://donhopkins.com/home/archive/lisp/llogo.lisp](http://donhopkins.com/home/archive/lisp/llogo.lisp)

~~~
derefr
Diving into that MACLISP file, I found this variable and explanatory comment:

> SYNSTAX ... A STACK OF SYNTAX PROPERTIES

If there were a "stupid-clever variable names" hall of fame, that one would
certainly make the cut.

~~~
DonHopkins
It also mentions BIBOP LISP: BIg Bag Of Pages

    
    
        (OR (BOUNDP 'BIBOP) (SETQ BIBOP ITS)) 
    
        ;;THE TURTLE PACKAGE IS GOING TO EAT LOTS OF FLONUM SPACE, SO IN BIBOP LISP, ASSURE
        ;;THAT ENOUGH WILL BE AVAILABLE.
    
        (AND (MEMQ 'BIBOP (STATUS FEATURES))
             (ALLOC '(FLONUM (2000. 4000. NIL) FLPDL 2000.))) 
    

[https://www.saildart.org/BIBOP.RPG[UP,DOC]4](https://www.saildart.org/BIBOP.RPG\[UP,DOC\]4)

BIBOP is the dynamically expandable version of MACLISP, the SAIL standard
MACLISP. Essentially, the main advantage of BIBOP is that whenever one of the
expandable spaces runs out of space, BIBOP requests a larger core allocation
from the monitor and the delinquent space grows in the allocated memory.

December 1973; updated March 1974

The (in)famous "Bibop" (pronounced "bee-bop") LISP scheme has been available
for some time now and seems to be more or less reliable. Bibop means "BIg Bag
Of Pages", a reference to the method of memory management used to take
advantage of the memory paging features of ITS. The average LISP user should
not be greatly affected in converting to this new LISP (which very eventually
will become the standard LISP, say in a few months).

[https://ml.cddddr.org/lispnews/lispnews-19740213.html](https://ml.cddddr.org/lispnews/lispnews-19740213.html)

WEDNESDAY FEB 13,1974 FM+7D.3H.28M.38S. LISP 746 - GLS -

AS OF VERSION 746, LISP SYSTEMS OF THE SAME VERSION WILL SHARE PAGES AMONG
THEMSELVES; I.E. A LISP, MACSYMA, AND CONNIVER CAN ALL SHARE PAGES COMMON TO
THE LISP SYSTEM. BIBOP LISP HAS BEEN GREATLY RESTRUCTURED; I WILL RE-EDIT THE
BIBOP DOCUMENT AS SOON AS I CAN (SAY WITHIN THE NEXT WEEK). -- GLS

[https://github.com/PDP-10/its/search?q=BIBOP&unscoped_q=BIBO...](https://github.com/PDP-10/its/search?q=BIBOP&unscoped_q=BIBOP)

There's nothing easier on the eyes than some good old fashioned PDP-10 Midas
assembler MacLisp source code!

~~~
rjsw
Franz Lisp used BiBOP too, but not in any way that worked with the paging
system of the host machine, it was just for determining the type of an object.

~~~
DonHopkins
And Hanson Lisp uses MMMBOP.

------
jepler
I looked into this a bit and zeroed in on the implementation of sine/cosine
computation, which is pretty critical for turtle graphics.

I didn't follow every last instruction, but it looks like it used a 91 (or
maybe 92)-element LUT of 4-byte floats, split into 2 halves. This allows
direct look-up of the SIN of every angle in the first quadrant, that is 0 to
90 degrees, plus the value for the next 1-degree angle.

It looks like after looking up the two precalculated values, linear
interpolation is then performed between them.

(Also, the FP numbers are in a format that must have been easy to do software
arithmetic on. Leading byte is exponent, with bias of 126; next 3 bytes are
sign and mantissa, with no implied 1-bit. This has just a hair less precision
than a modern 32-bit 'float'. 7A 47 7C 2D is the entry for SIN(1), and is
equal to 0.017452407... while double precision SIN(1) is
0.0174524064372835...)

Next, I bodged together a version of what I assume the linear interpolation
step does. In both double precision and simulated LOGO precision, the maximum
relative error is about .00005 and the maximum absolute error is about
.000045, which would be awful hard to detect when plotting to an entire
display with about as many pixels as an application icon on your modern high-
dpi telephone. On the other hand, that's only 4 correct digits.

This is an interesting contrast to the Commodore BASIC implementation of
sin/cos that I'm familiar with. It used a fairly high degree polynomial, which
might have gotten a few more accurate digits (5 digits for sin(1.5 degrees)!)
but is sure to be quite a bit slower than 2 table lookups, a multiply, and a
few add/subtracts. (plus range reduction)

    
    
        0.0261759515         Estimated Apple LOGO SIN(1.5 degrees)
               ^
        0.026176948307873153 Modern Double Precision SIN(1.5 degrees)
        0.0261769483         Commodore 64 BASIC SIN(1.5 degrees)
                    ^

~~~
effish
The only time anyone would notice slight errors in turtle position was trying
to do animation by drawing over a previous drawing with an XOR or ERASE or
background color pen. It might be necessary to explicitly reset the turtle
position to the original start. I do remember having to be careful with the
anti-aliasing so that when pointing in any random direction FD 100 RT 180 FD
100 would draw the same pixels in either direction.

------
WJW
I remember my very first program, from the book "Programmeren voor kinderen"
("Programming for kids" in Dutch)

    
    
        repeat 4
          forward 100
          right 90
    

It drew a square on the screen and my mind was blown. I haven't recovered yet
:)

~~~
jake-low
If you don't mind me asking, did the book do any explaining of why the magic
computer words were in a foreign language (English)? Had you been exposed to
much English already when you picked up the book?

As a native English speaker I feel fairly ignorant of how programming is
taught in other (human) languages. I recall a quote [1] by Eric S. Raymond
commenting (or perhaps speculating?) that Linus commented his kernel code in
English because it never occurred to him to do otherwise. But I'm curious for
your perspective as I imagine the experience of a child learning from a book
is quite different from that of an adult who is immersed in the English-
dominated "hacker culture" on the internet.

[1]: [http://www.catb.org/~esr/faqs/hacker-
howto.html#skills4](http://www.catb.org/~esr/faqs/hacker-howto.html#skills4)

~~~
crescentfresh
I always wondered how non-english speaking developers from other countries who
were first adopters of HTTP (or any new tech) reacted to words like "GET" and
"Content-Type" and other things that were clearly invented by westerners. What
would we think if we had to implement something new and use words we didn't
understand?

~~~
TeMPOraL
The way I learned programming as a kid, while also simultaneously learning
English, involved looking at the new weird term, grabbing a dictionary, and
trying to figure out why it's named the way it is. Sometimes it was obvious,
sometimes it wasn't, but generally it wasn't difficult - after all, this is
just vocabulary. Single words. Pretty much the easiest part of learning a
language.

------
jrd259
Note there were two versions of Logo for the Apple II. The other was developed
by Logo Computer Systems Inc. (I was one of the staff). Our version was
written first in Lisp (on Lisp Machines) then manually compiled to assembler.
The Lisp development environment included a full 6502 emulator, allowing the
developers to execute Logo either at the Lisp level (fast) or to drop down
into the instruction level (slow). The emulator also emulated the Apple II's
graphics.

~~~
jackpirate
What does "manually compiled to assembler" even mean? How is that different
from "rewriting it in assembler"?

~~~
effish
There is a gray area there. But we are talking about translating an existing
model program and algorithms, not looking at the program as a black box and
recreating its behavior.

As the person who translated the Pascal Logo model to TI9900 assembler it was
definitely the case that at the beginning of the project I translated every
line of Pascal to a few instructions of assembler. By the end I was just
looking at the gist of what a routine would do (its “contract” as they say)
and writing it in assembler as you would new code.

It’s much like translating a literary work. There’s a famous quotation (which
I’m not comfortable relating in full) about translations being either faithful
or beautiful but not both.

Essentially maybe I became a fluent native speaker of 9900 assembler.

------
MicahKV
Wow, what a blast from the past. My introduction to programming was on an old
Apple II with BASIC and LOGO. I was in the 6th grade at the time, and never
did anything as complex as looping to draw spirals - I basically used LOGO
like an etch-a-sketch.

~~~
acomjean
Me too. I really liked Logo. I worked as "child volunteer" at and art museums
"festival of the future" making logo spirographs for interested visitors. It
was the early 80s and the apple ][+ 's 7 colors (2 white and 2 black..) was
pretty bad compared till today, but we didn't care because not much was
better.

Basic was built in so I ended up going back to that. I learned logo, pascal
and basic, but being built in and not having access to pascal at home made my
choice.

I did return to logo in high school on macs for some neat fractal and equation
graphing programs.

~~~
apricot
Hey! Hey! Stop bad-mouthing the Apple II's graphics capabilities. I'll have
you know the computer has not 7 but 8 high-resolution colors (of which two are
white and two are black, but who cares about being a little wasteful when you
have so many colors to choose from?).

------
thought_alarm
The source code is 213 KB of ASCII, assembled on 1980-8-6.

A souped-up Apple II at that time would have had 64 KB of RAM, and 140 KB of
storage per floppy disk.

I guess you needed a PDP-11 to do any real work in those days.

~~~
ajross
A PDP-11/45 or 11/70 would have much more memory, but being a 16 bit machine
would still have been unable to handle this file in a conventional editor.
Honestly I don't know if there were paging editors available for common
environments. Certainly nothing on Unix would have worked.

Per the link, the file was editted and built on a PDP-10 running ITS, which
was a 36 bit machine with an 18 bit address space.

Interestingly, almost everything else I've seen from ITS uses the 6 bit upper-
case-only encoding. This is pretty clearly ASCII.

~~~
larsbrinkhoff
ITS text files use 7-bit ASCII. Five characters packed per word. Some things
like file names use a 6-bit ASCII subset (the range 32-95).

What have you seen from ITS?

------
bradfitz
To save others time who want to actually use this,

Here's the disk image:
[https://github.com/pneubauer/ptp2bin/raw/master/LOGO.dsk](https://github.com/pneubauer/ptp2bin/raw/master/LOGO.dsk)

Here's a web-based emulator to run said disk image:
[https://www.scullinsteel.com/apple2/](https://www.scullinsteel.com/apple2/)

Here's the manual:
[https://archive.org/details/Apple_Logo_II_Reference_Manual/p...](https://archive.org/details/Apple_Logo_II_Reference_Manual/page/n0)

~~~
larsbrinkhoff
That's the manual for LCSI Logo.

------
pq0ak2nnd
Summer 1981, 11 years old, learning logo on a ][. It sure beat the hell out of
trying to draw a straight line in HIRES mode in assembly: goddamn skipping
every six horizontal lines made no sense to my pre-teen brain that couldn't
grok modulus.

~~~
dekhn
TBH that HIRES mode still bothers me.

------
coldcode
6502 assembly is so nice, I wrote some apps in the early 80's. You can learn
the language in a few minutes. But all sorts of interesting clever things were
possible.

~~~
mmusson
6502 assembler on C64 is basically what taught me how to program. It was just
as important to learn the memory map so that you could access low-level
features by reading and writing at special memory addresses. The Compute!
books were especially useful.

------
Latteland
It's so cool to look at that 6502 assembly. I had an atari 400 computer, and I
had this cool book that taught assembler for 6502 and I hand compiled my
programs into bytes and put them in a data program and I could call them from
basic. I had this great book called "De Re Atari". Those were fun times. I was
in high school and the future was unlimited!

------
ur-whale
Oh, it is so nice to see this again.

This is the tool that introduced me to the notions of recursion and fractals
when I was 11.

I remember spending two weeks cobbling up a Logo program to draw the dragon
curve on my Apple IIe

[https://en.wikipedia.org/wiki/Dragon_curve](https://en.wikipedia.org/wiki/Dragon_curve)

------
MisterOctober
Hot diggity dog! Like lots of folks, LOGO on the Apple II was my first
exposure to computer -- thanks to one Mr. Milligan in Westbrook, ME -- some of
the other kids in my class did some pretty amazing graphics with it -- the one
that is particularly clear in my mind was a well-proportioned and '3D-type'
rendering of the brandmark of the band 'Foreigner' \-- I had no idea at the
time how to even pronounce that word, but the fact he'd done it with the
turtle sure made an impression on me

------
peterburkimsher
Logo was my first programming language! I recently rewrote my own version of
it so that I could draw a time-proportional train map. I wrote "fd 5" for 5
minutes, for example.

[http://peterburk.github.io/tra/](http://peterburk.github.io/tra/)

The version I wrote can read values from a spreadsheet, so could be used in
other applications too. I think this kind of thing could be a great way for a
young person to go from a homework project to the front of Hacker News. If any
of you have kids, I'd be happy to help gather the data for some other subway
networks!

Also, where should I contribute old Apple II software? I recently used ADTPro
to copy a lot of old programs onto my MacBook Pro as DSK images.

5.25 floppies:

[https://mega.nz/#!yDITXIZC!8fREZdAruk2yYLv859jKABGSWeG4UkRoC...](https://mega.nz/#!yDITXIZC!8fREZdAruk2yYLv859jKABGSWeG4UkRoCN4_feKnmIM)

[https://www.flickr.com/photos/150180606@N08/sets/72157672562...](https://www.flickr.com/photos/150180606@N08/sets/72157672562505858)

[https://www.flickr.com/photos/150180606@N08/sets/72157672589...](https://www.flickr.com/photos/150180606@N08/sets/72157672589613188)

I've also got a larger selection of DD floppies, HD floppies, JAZ disks, SCSI
disks, IDE disks, MacFormat and other CDs. Please tell me if you want the
links!

------
dekhn
I remember (quite clearly) the day I was introduced to the Apple II+ and shown
Logo. It was way over my (middle school) head- functions? recursion? so I went
with BASIC and later Machine Language, but the ideas stuck and percolated and
later helped me understand Emacs LISP and functional programming. I thought
the integration with the turtle so that you could make graphics really was
slick (compared to direct explicit mode in BASIC).

I'd love to get my hands on an actual physical Logo turtle.

------
Vogtinator
I wonder what they mean by this:

    
    
        APOUT:      AND #$7F	;eat Apple idiot char codes, type Ascii
                    JMP COUT
    

did the Apple II not use ASCII?

~~~
tomtomtom777
Apple II did use ASCII. But ASCII defines 128 code-points. The other 128 code-
points are specific to the character encoding or "codepage".

They don't like Apple's "idiot" character encoding (which is custom, Apple II
specific), so they throw away the top bit with the AND leaving only ASCII
characters.

~~~
dragonwriter
> But ASCII defines 128 code-points. The other 128 code-points are specific to
> the character encoding or "codepage".

ASCII is a character encoding, and it's a 7-bit encoding. It has no code
pages.

There are many 8-bit encodings / code pages that are ASCII supersets
(including the Apple II one), however.

~~~
tomtomtom777
Yes. I meant to the "8-bit character encoding" but I think it's clear from the
context.

------
sigmaprimus
Logo was critical in my understanding of sub routines and got me away from the
dreaded GOTO command in BASIC, can't say I did much more than use it as an
expensive Spirograph but it is certainly responsible for my ability to
understand function calls and libraries and how use them in modern object
orientated laguages. Just instinct for new programmers now a days, but in the
80s and early 90s it was a difficult concept for many to grasp.

------
spsrich
I love 6502 - so clean and simple. Even after 35 years I still remember the
opcodes in hex.

~~~
Graham24
A9418D0004

------
tom_
Never seen anybody initialize the stack pointer to $00 before. The 6502's
stack pointer is postdecrement, so an initial value of $ff is more usual.

~~~
rpiguy
Could this be a trick to use the top of stack like another register and use
all of the one byte stack instructions on it? If it is using the top of stack
as a register, where then would be the real stack?

------
DonHopkins
Terrapin Logo for the Apple ][ and C64 came with a 6502 assembler written in
Logo by Leigh Klotz, that they used to write Logo primitives (for controlling
the turtle, etc).

It would be ambitious to make a self hosting 6502 Logo meta assembler, by
porting the entire 6502 assembly language Logo source code to the 6502 Logo
Assembler!

------
Lord_Nightmare
Before today, was this version of MIT Logo for the Apple II _EVER_ released?

I'm asking because of reaperducer's comment from just a week ago:
[https://news.ycombinator.com/item?id=18086566](https://news.ycombinator.com/item?id=18086566)

~~~
larsbrinkhoff
No, this version was never released. People with fond memories of Logo on an
Apple II would probably have used a later version licensed to Terrapin. Or the
Krell version. Or the completely separately implemented LCSI Logo mentioned
elsewhere in this thread.

------
jacquesm
Good old 6 character identifier names. That really required some creativity,
both to keep some descriptive value as well as to not generate identical
identifiers by accident.

------
brynet
I remember "programming" (copying from graph paper) in LOGO on
Unisys/Burroughs ICON computers back in school in Ontario, Canada.

------
executesorder66
Does anyone know where/how the guy found it?

~~~
larsbrinkhoff
I found it in backups from ITS. ITS is the MIT operating system for the
PDP-10, which was the workhorse around the AI Lab, Logo Lab, Lab for Computer
Science, Mathlab, Dynamic Modeling group, etc.

~~~
effish
Hmmm, I’m vaguely remembering uploading the TI-Logo source to the MIT ITS
PDP-10 for backup purposes too. If so it might be there also. You’d want to be
careful about the copyright on that. Though I’d love to see it again

~~~
larsbrinkhoff
That's why I try to run most of the finds by the original authors. I sent you
an email with some more details; or at least I tried and it didn't bounce.

------
jeremiemv
That Turtle!

~~~
larsbrinkhoff
General Turtle, anyone?

