Hacker news

  • Top
  • New
  • Past
  • Ask
  • Show
  • Jobs

How did Woz write the Apple 1 BASIC before building the computer? (2021) (https://retrocomputing.stackexchange.com)

323 points by Skyfall106 5 days ago | 178 comments | View on ycombinator

femto 5 days ago |

What Woz did was the default way of writing assembly language programs for owners of 8-bit computers (mostly hobbyists). You didn't have money for a second machine, so you wrote your program on paper, you entered it then tested it in situ. Mostly you got it right, as doing it on paper was slow and meant you had the opportunity to put lots of thought into it. 8-bit instruction sets were simple enough that you eventually learned the most common instructions by heart. There was a point where I could mostly translate a Z80 program from assembly to machine code from (my) memory.

Maybe that is part of the nostalgia for the 8-bit days: the practice of "slow programming"? It was relaxing, sort of like those "slow tv" shows.

runjake 5 days ago |

I don’t know about other people, but back in the early 80s, I spent a lot of time writing code (mostly assembler, some BASIC and other dead languages) with pencil on paper for various reasons: sometimes I preferred it, sometimes I was writing code for computers I only had access to in labs or at school.

There were even pre-made paper forms for writing code, like the IBM COBOL program sheets and similar for assembler.

Even now, if I’m working on a tough issue, I still print out code sections on paper and hash it out with a pencil.

david-gpu 5 days ago |

I only had to assemble instructions by hand three times in my career. It is not difficult if you are already familiar with the ISA of that particular processor, but it is tedious.

The first time was in my first job writing OpenGL ES 2.0 blending operations for the Imagination Technologies SGX 535, which was a remarkably advanced little GPU for its time. Alpha blending happened through special instructions in the fragment/pixel shader. We did have a compiler, but it didn't handle blending, for whatever reason.

Through testing I noticed that NVidia GPUs performed blending incorrectly, according to the specification, which was a big surprise. Only years later I figured out that the specification had some errors; I now would bet that NVidia was doing the correct thing.

The second time I had to assemble instructions by hand happened while working on a stripped down version of the Radeon 7xxx series that shipped on some mobile phones. I don't recall what the problem was, whether we were adding a feature or optimizing the microcode generated for a particular OpenGL operation, but it involved a rarely-used feature called user-defined clipping planes. We didn't have an assembler for that GPU; all microcode was assembled by hand.

The third time happened at NVidia, and I will be vague, as not enough time has passed for me to be comfortable going into any detail. I had an idea for how to provide hardware acceleration for persistent CUDA kernels, which eventually was marketed as Cluster Launch Control (CLC). In order to quantify the benefit of adding some hardware, when it was possible to approximate that functionality in software, I needed to test the most efficient software implementation that was possible, and the compiler wasn't quite giving the assembly I wanted, so I had to manually patch some instructions post-compilation. Why did I not use the assembler that was available? I couldn't, because the assembly language did not provide a way to express the exact feature I had to patch.

kamma4434 5 days ago |

For what it’s worth: when I used to do assembly on the commodore 64, after a while, your eyes are so used to seeing A9 close to LDA let you start knowing them by heart without even thinking. Of course this is possible on 6502 and will be way harder on modern CPUs. In the end of the number of common opcodes might have been 30-50, and you can always look up the rest from a one-page table.

I remember that was a book that went on to say that you should learn machine code (that is, raw opcodes), not assembly, to program the c-64. Not sure I would agree, but it’s definitely feasible.

The only thing that is strange in the Woz story is that you would usually start by creating a dirt-poor monitor/assembler so that you would have a sane environment to do further development in. That was the approach manuals from the era suggested for new hardware (eg Rodnay Zack’s)

mrandish 5 days ago |

I got my first computer in 1981, a 4K Radio Shack Color Computer for $500 (a huge purchase decision at the time). So I missed hand assembling for bare metal and Altair-type toggles.

However, there was an interesting period of a few years where assembler tools were either unavailable or fairly expensive, so it was common to use the computer's BASIC to write an assembly language monitor program. Such program listings were pretty common in early hobbyist 'zines. It was also pretty common to use BASIC to POKE in a quick bootstrap program to load a value in a register and jump to an address, which I could usually do from memory. After 40 years I still remember the 6809 RTS was $39 and NOP was $12, two very handy instructions to POKE a quick mod into a program.

II2II 5 days ago |

Follow-up question: how did Woz get BASIC into ROM?

The handwritten interpreter is fairly common knowledge since Woz has told that story many times, but I don't recall any accounts of how he bridged the gap from paper to silicon. All of the discussion about the machine language monitor doesn't really address the question. At best, it moves the question from programming a ROM for BASIC to programming a ROM with the machine language monitor. Even with the monitor, additional hardware would be required to program a ROM. At the very least, a latch would be required to hold the address and data. Of course, it is possible that he did it without the computer (using a rig that let him "toggle" the pins). It is also possible that he used another computer to program the ROM, but, as he said, he didn't have the money to program BASIC on a computer so why would that be different for a ROM?

asdefghyk 5 days ago |

I would say bit by bit, I mean "small part" and then keep making small extensions to the program(s)

First for new hardware would be a monitor program. Either write one, or port one from other hardware. A monitor program allows the inspection and edit of memory data and also to run programs in such memory. The monitor program often placed in ROM for convenance. A 6502 cross assembler, could be used to avoid the need for hand assembly the program to 6502 machine code.

Probably where WOZMON came from.

Then using WOZMON start writing a VERY simple basic interpreter.

Maybe the monitor program was borrowed from other hardware that used a 6502 ( would need slight mods for the Apple 1 ) NOTE This is just a possibility - I actually have NO idea I suspect WOZ would have invented his own in any case ...

(OFF TOPIC - I messed around with a 68008 chip in mid 1980s?? and I recall I found a book with a complete montor program in for this chip - I can not recall the name of the book. )

iberator 5 days ago |

It's easy to relearn those skills:

Just design and build a virtual CPU architecture in the language of your choice:) (not verilog but php, c, rust, zig or whatever)

You create architecture, then OPCODES, then you can write simple programs in machine code.

Then its SUPER EASY to write an assembler and disassembler.

Then forth compiler.

I did it all once as I was homeless on my phone in the mall .

Fun and educational, even if you don't know assembly prior.

sam345 5 days ago |

I've never "assembled by hand" but I can believe it and imagine it. As a kid I did write basic code by hand and would type it into my Timex Sinclair with no ability to save it because we could not get the tape cassette to work to save it. So for the first few weeks it would all disappear when you turned the computer off. What a blessing it was to get that cassette to work and be able to save and load our programs back! The next thrill was finally getting a disk drive for a later acquired Commodore 64 and ditching the tapes. Not only storage but random disk access what a concept.

le-mark 5 days ago |

And then he wrote SWEET16 which was also amazing. Him and Niklaus Wirth are two people I truly admire; they knew so much and shared so freely.

euroderf 5 days ago |

Just having an assembler - the first and fundamental productivity tool for whatever chunk of hardware it was that you had on your table - was an incredible step upward. That and persistent storage, even if it was Mom & Dad's cassette recorder.

WillAdams 5 days ago |

For the sequel to this, see:

https://www.folklore.org/MacBasic.html

jgrahamc 5 days ago |

I was assembling by hand as late as 1985 because I didn't have access to an assembler and writing out the code wasn't that hard. And it made you think about what you were doing! https://blog.jgc.org/2013/04/how-i-coded-in-1985.html

And we had/have people at Cloudflare hand writing assembly to get specific performance out of our systems.

not2b 5 days ago |

Back in the 80s I wrote an assembler and a simulator for a custom DSP before the board was manufactured (it was the 80s so several chips were required), and our team wrote and tested code for it before the board was ready. When the board was ready, we wound up having to modify the assembler and simulator because some control signals were wired backwards and it was easier to just change the instruction coding than to redo the layout. The tools ran on a Vax. Worse, it was Eunice, a Unix-on-top-of-VMS atrocity that we were stuck with because of code that needed VMS and other code that wanted a Unix-like system.

dboreham 5 days ago |

Paper! That would have been a luxury. I could write machine code in my head. Including negative branch offsets.

Having established my chops though, I'll say that contrary to the comments on this thread that's not "how people did it back then". The typical tool chain for professionals was to run an assembler (and often an emulator too) on some larger computer such as a pdp-11 or a dec-10. Anyone interested in this particular period should read billg's latest book "Source Code". It's very detailed on this subject and tells how he and Paul Allen were able to write an 8080 BASIC interpreter despite never having seen or used an 8080. He does describe writing portions of what was to become the interpreter while on a hiking trip (as in, while actually hiking), so he could do my thing of writing code in his head.

wewewedxfgdf 5 days ago |

It's taken me more than 40 years to learn a fraction of a % of what Woz knew in 1975.

RicoElectrico 5 days ago |

The clarifications OP needed to put so people don't answer a question that wasn't asked are an indication of how point farming tryhards ruined Stack Overflow and the sister sites.

ianberdin 5 days ago |

If all the people who wrote comments here gone, and at the same time we lose all the source code and AI, then it's the end of civilization.

undefined 5 days ago |

undefined

rootedbox 5 days ago |

Ada Lovelace.. wrote the first language before any physical computer.

xgkickt 5 days ago |

Simple answer: Because Woz is the wiz that was.

glum64 5 days ago |

Pen and paper assembly? Kids these days... Try going mental!

Real story: sometime in 80s I was in bed with a nasty flu. Pain-in-the-eyeballs flu, 40°C body temp. Could not read, coult not watch TV, could not stand any light lit near me, radio caused booming in me poor head.

So I started programming, mentally, in BASIC. One of the outcomes of this activity was an algorithm that compressed any text to mere three bytes, but that is another story...

heisenbit 5 days ago |

Did he really write the BASIC before he wrote the monitor program which sits at the top of the address space? The monitor was documented as part of the systems manual of the Apple ][ and contained a small disassembler which helped a lot when coding some instructions or jumps wrong. I learned a lot from that code.

NorrisFByrd 5 days ago |

The part that stuck with me is femto's 'slow programming' line. I never hand-assembled anything, I came up too late for that, but I still write the tricky parts of a program on paper first. Last month it was a little state machine for a game I'm tinkering with. Two pages of boxes and arrows, and I caught three logic errors before I ever opened an editor. I think the paper forced a kind of discipline that's easy to lose now, when the cost of trying something is one keystroke. The flip side is that Woz had to be right before he ran anything, and that's a brutal way to learn. I'm not sure I would trade the fast feedback loop we have now for it, even if the paper habit is worth keeping.

undefined 4 days ago |

undefined

Grimeton 5 days ago |

>How did Woz write the Apple 1 BASIC before building the computer?

Time travel!

MumminTODAY 5 days ago |

[flagged]