
Apple 1 ROM disassembly - janvdberg
https://gist.github.com/robey/1bb6a99cd19e95c81979b1828ad70612
======
jacquesm
I've been working on an annotated disassembly of the Yamaha DX7 ROM, it's been
quite a trip so far. Figuring out all the hardware, how the operators and the
envelope generators work by looking at the code, the midi implementation and
so on.

I work a little bit on it every week on Saturday evening, it's my way of
winding down from a busy week. Other people play Sudoku ;)

In case you're wondering why: I'd like to de-solder the CPU from a broken
motherboard that I have (besides two working ones) to see how hard it is to
take over the hardware by simulating the CPU with a RasPi, but for that I have
to know exactly how the bloody thing works in the first place and it is quite
a complex beast. The ROM is 16K.

~~~
thement
I did similar synth reverse-engineering of DS-10 synth from Korg for Nintendo
DS, so not much desoldering involved :-) The goal was to get it running as a
VST plugin, but ARM emulation wasn't fast enough, so I wrote a static-JIT
decompiler and decompiled the synth portion of the code into C instructions
(see "c-code.h").

The result is here:
[https://github.com/thement/ds10-vst](https://github.com/thement/ds10-vst)

And the project log here:
[http://ibawizard.net/~thement/ds10rev.html](http://ibawizard.net/~thement/ds10rev.html)
(sorry for the missing pictures, they got lost when I moved servers)

~~~
jacquesm
That's a very cool project, kudos on the stamina, that must have taken you a
really long time. And thanks for the reminder the fix the pictures on my own
blog, exact same story.

------
monocasa
The Apple I actually shipped with a full disassembly of the ROM, with Woz's
comments.

[http://s3data.computerhistory.org/brochures/apple.applei.197...](http://s3data.computerhistory.org/brochures/apple.applei.1976.102646518.pdf)

~~~
pvg
Yeah, odd for someone to redo it. So did the Apple ][, with lots more
commented ROM.

~~~
monocasa
I don't want to shit on him though. It's a great exercise. It's only 256
bytes, and you can compare to the original's comments when you're done to see
if you were on the right track.

~~~
pvg
Oh, absolutely. It is in no way bad, I'm just wondering how one gets this far
down the retro rabbit hole (An Apple I is a pretty obscure piece of hardware)
and misses a thing it was well-known for. Obviously, it happens.

~~~
SmellyGeekBoy
Perhaps just a learning exercise in preparation for something much bigger.
Seems like a fun project!

------
tom_
There's a wasted byte in prnybble :( - you should do it like this instead:

    
    
        and #$0f
        sed
        clc
        adc #$90
        adc #$40
        cld

~~~
Cyberdog
Please, reach out to Woz and let him know you found a tiny mistake in his
forty-year-old work. Let me know what he says.

~~~
tom_
Why do you think Wozniak would care? Man is a multi-milionaire on account of
his Apple shares, and has better things to do these days than bum single bytes
out of 6502 code ;)

My post is made for the benefit of current and future 6502 programmers.

I guess you must not be a 6502 programmer, because if you were, your response
would be, like, "dude, _fuck_ , that's awesome, holy shit, let me take some
notes". Because that was what my response was the first time I saw this code.
And that's why I'm passing it on.

~~~
saagarjha
> Why do you think Wozniak would care?

From the little I know about him, this seems like _exactly_ the thing he would
care about.

~~~
jackhack
You are correct.

in 2014 he woke up in a hotel in equador with an idea for saving a few chips
(and add two grey-levels) in the Apple ][ design.

[https://www.cultofmac.com/302087/38-years-later-woz-still-
th...](https://www.cultofmac.com/302087/38-years-later-woz-still-thinks-ways-
improve-apple-ii/)

So yes, he would care.

------
userbinator
256 bytes is a reasonable amount for a "first stage bootstrap"; in other
words, it's useful enough to enter a bigger program such as an assembler,
through which you could eventually write a compiler...
[https://news.ycombinator.com/item?id=17851311](https://news.ycombinator.com/item?id=17851311)

I wonder how big implementing the equivalent functionality with an x86 PC
would be --- my guess is somewhat shorter, because the x86 ISA is denser than
6502.

 _the constrained space means woz used a lot of tricks, like having a routine
"fall thru" to another instead of calling it explicitly_

Basically tail-call optimisation with jump elimination. Nearly all compilers
can do it too if you have the optimisation settings right.

~~~
wk_end
> I wonder how big implementing the equivalent functionality with an x86 PC
> would be --- my guess is somewhat shorter, because the x86 ISA is denser
> than 6502.

(grain of salt alert: I don't know a ton about modern PCs at this low a level)

Eh, maybe if a modern PC were just an Apple I with an x86 chip dropped into it
- although even then, don't underestimate the 6502 for code density (or
overestimate x86) when it comes to simple bit-banging and byte-bashing. And
remember, your x86-64 CPU when it starts up isn't much more than a hot-rodded
8086, so we're comparing the 6502 to _that_ \- real mode x86 with 16-bit
registers and all - rather than something more modern.

But my guess is that the complexity of modern IO would absolutely crush you in
terms of complexity. For keyboard and video alone, the absolute bare minimum,
you need to speak to the USB controller and across the PCI-E bus to the
graphics card, and my intuition tells me this hardware wasn't designed to be
easily programmable in a microscopic number of bytes.

(I also don't know how much stuff you strictly _need_ to do to get a stable
system, but looking through the pages of Advanced Options in my BIOS
concerning things like memory timing and who knows what else makes me think
the motherboard itself needs a fair amount of configuration on start up...)

~~~
pjc50
Yes, it all depends where you start; a similar program written as a boot
sector would be quite short, but by the time you've got there a lot of BIOS
and ACPI code has already run.

If you want to start from the very beginning of bootup, you do indeed have to
start by turning the RAM on. See [http://www.drdobbs.com/parallel/booting-an-
intel-architectur...](http://www.drdobbs.com/parallel/booting-an-intel-
architecture-system-par/232300699?pgno=2) which I found for answering
[https://electronics.stackexchange.com/questions/311832/can-a...](https://electronics.stackexchange.com/questions/311832/can-
a-cpu-function-with-nothing-more-than-a-power-supply-and-a-rom-using-
only-t/311839#311839)

------
scarface74
This really takes me back. I loved programming in 65C02 assembly. It was
simple but complex enough to understand how computers worked.

Random aside.

One thing I miss is that I never had an assembler for my Apple //e. The small
assembly programs I wrote, I had to write using the bare bones mini-assembler
that you got by doing

call -151

and then

!

~~~
coldcode
6502 was an amazing assembly language. I wrote a VT-100 terminal emulator from
scratch in a week or so way back then. Thankfully I had an Apple III with an
assembler to build it in. The syntax was so simple to learn, but you could
build interesting and sophisticated code by taking advantage of the quirks and
tricks in the design. Of course I remember none of it any more. I am still in
awe of Woz building the Apple I ROM without any tools at all.

~~~
cgh
This got me thinking about my time as a teenager teaching myself assembly on
my C64 (which of course used the 6502 instruction set). I was trying to recall
the assembler I used and I finally dredged it out of my memory: Develop-64 by
French Silk Software, a now-forgotten program that I used a lot. My mom
ordered it for me (her credit card) and she mentioned that the person on the
phone wondered how in the hell some kid in northern Canada had ever heard of
them. Good times.

~~~
exikyut
Awesome.

Just did some idle digging out of curiosity, and stumbled on something that
may be of interest:
[http://iancoog.altervista.org/HF/develop64_hf.rar](http://iancoog.altervista.org/HF/develop64_hf.rar)

It was hiding in here:
[http://comp.sys.cbm.narkive.com/YJAWnSun/develop-64](http://comp.sys.cbm.narkive.com/YJAWnSun/develop-64)

There are references to a "develop64_cracked" on a retro FTP server that's
404ing for that file; this RAR seems to contain the file was was on the FTP
server.

Also, backspacing the file off the path in the first URL gives a listing of
some other releases, but this file isn't listed. Woot.

Here are the other tabs that ended up open:

\-
[https://www.google.com/search?q=%22develop-64%22](https://www.google.com/search?q=%22develop-64%22)

\- [interesting]
[https://www.lemon64.com/forum/viewtopic.php?t=24254](https://www.lemon64.com/forum/viewtopic.php?t=24254)
(unfortunately the embedded photos seem definitively dead; I checked IA.)

Interstitial: the forum post above mentions has a link to
[http://www.radiks.net/~jimbo/art/int7.htm](http://www.radiks.net/~jimbo/art/int7.htm).
IA had captures of this just fine, but fiddling around with the dates caused
me to stumble on the specific capture
[http://web.archive.org/web/20110724025913/http://www.radiks....](http://web.archive.org/web/20110724025913/http://www.radiks.net/~jimbo/art/int7.htm),
which contains a "page moved" update pointing to
[http://web.archive.org/web/20110813050154/http://www.mailsen...](http://web.archive.org/web/20110813050154/http://www.mailsend-
online.com/blog/?p=93;) after stripping the IA prefix off that to see if it
was still live, it transparently redirected me to...

\- [interesting] [https://lawlessguy.wordpress.com/2016/12/04/an-interview-
wit...](https://lawlessguy.wordpress.com/2016/12/04/an-interview-with-the-
author-of-the-french-silk-assembler/)

I wish I could use bold for this line - THIS is how you keep data alive,
people!! :D

Also for reference, the reocities link in the above URL is dead, but
oocities.com works. Unfortunately the geocities paths are not in oocities'
archive.

And these links were near the top of Google's results.

\- [uninteresting]
[https://www.lemon64.com/forum/viewtopic.php?t=40768](https://www.lemon64.com/forum/viewtopic.php?t=40768)

\- [uninteresting] [http://sleepingelephant.com/ipw-
web/bulletin/bb/viewtopic.ph...](http://sleepingelephant.com/ipw-
web/bulletin/bb/viewtopic.php?t=2135)

------
ConcernedCoder
Learning 6502 assembly, and subsequently implementing worm, and then tetris on
an apple ][ from scratch, were the single greatest things I've ever done to
advance my understanding of computer programming and computing architecture in
general.

------
solomondrix
Oh man, assembly. Brings back memories of reverse engineering, OlyDbg, and
stuff.

