It is only natural for people to think with nostalgia about the good 'ol days: "oh man, back in the day things were so simple!" Objectively speaking, obviously, the "good 'ol days" sucked: that simplicity is only skin deep.
Yes, a telephone was much easier to use in the 70s, but then again it didn't do that much, did it? Could you imagine having to memorize the phone numbers of everyone you need to text or call? Right, that would have sucked. How about having to fast forward in order to get to the next song on a compact cassette? Ouch.
Yet, some things from the past are worth admiring. To me, a steam engine is prettier than the most advanced internal combustion engines of today. Not really practical, yet pretty.
But I'm a programmer, and a lot of the old stuff I admire is software. And while I have (if only once) programmed a computer with punchcards, those were already antiques when I was in school; the computer I grew up programming was the Apple ][.
Actually, not quite: I grew up in Bulgaria which was a member of COMECON, an economic organization of the communist states. According to Wikipedia, at its peak Bulgaria produced 40% of the computers in COMECON. Some of what we did was what China does today: copying and mass-producing western technology. So I grew up programming the Pravetz-82, which was an Apple ][ clone built with Bulgarian-made clone of the 6502 CPU. :)
So here we go: at the risk of wasting my time raving about something most programmers today can't appreciate, I'll try to explain but just a tiny bit of Wozniak's brilliancy:
The Apple ][ floppy disk controller bootstrapping routine
Some background: on physical magnetic media, you can't "just record data". Instead, 1 is encoded as a magnetic polarity transition (also known as flux reversal), and 0 is encoded as, well, lack of transition. Basically, for each bit there is a limited time window in which flux reversal is expected to occur. If it occurs, the bit is 1, otherwise it's 0. The problem is that the time window is so small that there is a limit on the accuracy with which the data window length can be measured. So, while detecting a series of ones is not a problem, it's difficult to know how many zeroes are encoded in a measured period of lack of flux reversal.
Wozniak's original hardware design imposed two constraints on the raw data:
- between any two 1-bits, there can be no more than one 0-bit, and
- each 8-bit byte must start with a 1-bit
However, using simple FM encoding "wastes" 4 bits per raw byte, which would allow only 10 256-byte sectors per track to be recorded. Instead, he devised a more complex encoding scheme that was based on the fact that there are 34 8-bit numbers which have the top bit set and no two 0-bits in a row. That way, 13 sectors per track could be recorded. Later on the hardware design of the floppy disk controller was modified to allow no more than one occurrence of two consecutive 0-bits in a byte, which lead to different encoding called 6&2; it allowed 16 sectors per track.
A conventional floppy disk controller design would put all this bit twiddling in silicone which just DMAs the decoded bytes in memory -- but it would cost more in hardware. So what is a Wozniak to do? Obviously: screw hardware, do everything in software.
That would have been impressive enough on a 6502 CPU, but even more impressive is what is required of the bootstrapping routine. It must:
- generate the 6&2 decoding table in RAM
- seek the disk drive to track zero
- look for the beginning marker of sector zero and read the raw data in RAM
- decode the data and jump into it
...all in no more than 256 bytes of code, which is the addressing limit for the ROM on Apple ][ expansion cards.
By the way, there are no timers on the Apple ][, all timing is based on the CPU clock, e.g. you'd know that an INX instruction takes 2 microseconds to execute. The 6502 has three 8-bit registers: an accumulator A which can add, subtract, shift, rotate, and, or, xor, etc., and two 8-bit index registers X and Y which can do none of those operations. :)
]CALL-151
*C600L
C600- A2 20 LDX #$20
C602- A0 00 LDY #$00
C604- A2 03 LDX #$03
C606- 86 3C STX $3C
C608- 8A TXA
C609- 0A ASL
C60A- 24 3C BIT $3C
C60C- F0 10 BEQ $C61E
C60E- 05 3C ORA $3C
C610- 49 FF EOR #$FF
C612- 29 7E AND #$7E
C614- B0 08 BCS $C61E
C616- 4A LSR
C617- D0 FB BNE $C614
C619- 98 TYA
C61A- 9D 56 03 STA $0356,X
C61D- C8 INY
C61E- E8 INX
C61F- 10 E5 BPL $C606
C621- 20 58 FF JSR $FF58
C624- BA TSX
C625- BD 00 01 LDA $0100,X
C628- 0A ASL
C629- 0A ASL
C62A- 0A ASL
C62B- 0A ASL
C62C- 85 2B STA $2B
C62E- AA TAX
C62F- BD 8E C0 LDA $C08E,X
C632- BD 8C C0 LDA $C08C,X
C635- BD 8A C0 LDA $C08A,X
C638- BD 89 C0 LDA $C089,X
C63B- A0 50 LDY #$50
C63D- BD 80 C0 LDA $C080,X
C640- 98 TYA
C641- 29 03 AND #$03
C643- 0A ASL
C644- 05 2B ORA $2B
C646- AA TAX
C647- BD 81 C0 LDA $C081,X
C64A- A9 56 LDA #$56
C64C- 20 A8 FC JSR $FCA8
C64F- 88 DEY
C650- 10 EB BPL $C63D
C652- 85 26 STA $26
C654- 85 3D STA $3D
C656- 85 41 STA $41
C658- A9 08 LDA #$08
C65A- 85 27 STA $27
C65C- 18 CLC
C65D- 08 PHP
C65E- BD 8C C0 LDA $C08C,X
C661- 10 FB BPL $C65E
C663- 49 D5 EOR #$D5
C665- D0 F7 BNE $C65E
C667- BD 8C C0 LDA $C08C,X
C66A- 10 FB BPL $C667
C66C- C9 AA CMP #$AA
C66E- D0 F3 BNE $C663
C670- EA NOP
C671- BD 8C C0 LDA $C08C,X
C674- 10 FB BPL $C671
C676- C9 96 CMP #$96
C678- F0 09 BEQ $C683
C67A- 28 PLP
C67B- 90 DF BCC $C65C
C67D- 49 AD EOR #$AD
C67F- F0 25 BEQ $C6A6
C681- D0 D9 BNE $C65C
C683- A0 03 LDY #$03
C685- 85 40 STA $40
C687- BD 8C C0 LDA $C08C,X
C68A- 10 FB BPL $C687
C68C- 2A ROL
C68D- 85 3C STA $3C
C68F- BD 8C C0 LDA $C08C,X
C692- 10 FB BPL $C68F
C694- 25 3C AND $3C
C696- 88 DEY
C697- D0 EC BNE $C685
C699- 28 PLP
C69A- C5 3D CMP $3D
C69C- D0 BE BNE $C65C
C69E- A5 40 LDA $40
C6A0- C5 41 CMP $41
C6A2- D0 B8 BNE $C65C
C6A4- B0 B7 BCS $C65D
C6A6- A0 56 LDY #$56
C6A8- 84 3C STY $3C
C6AA- BC 8C C0 LDY $C08C,X
C6AD- 10 FB BPL $C6AA
C6AF- 59 D6 02 EOR $02D6,Y
C6B2- A4 3C LDY $3C
C6B4- 88 DEY
C6B5- 99 00 03 STA $0300,Y
C6B8- D0 EE BNE $C6A8
C6BA- 84 3C STY $3C
C6BC- BC 8C C0 LDY $C08C,X
C6BF- 10 FB BPL $C6BC
C6C1- 59 D6 02 EOR $02D6,Y
C6C4- A4 3C LDY $3C
C6C6- 91 26 STA ($26),Y
C6C8- C8 INY
C6C9- D0 EF BNE $C6BA
C6CB- BC 8C C0 LDY $C08C,X
C6CE- 10 FB BPL $C6CB
C6D0- 59 D6 02 EOR $02D6,Y
C6D3- D0 87 BNE $C65C
C6D5- A0 00 LDY #$00
C6D7- A2 56 LDX #$56
C6D9- CA DEX
C6DA- 30 FB BMI $C6D7
C6DC- B1 26 LDA ($26),Y
C6DE- 5E 00 03 LSR $0300,X
C6E1- 2A ROL
C6E2- 5E 00 03 LSR $0300,X
C6E5- 2A ROL
C6E6- 91 26 STA ($26),Y
C6E8- C8 INY
C6E9- D0 EE BNE $C6D9
C6EB- E6 27 INC $27
C6ED- E6 3D INC $3D
C6EF- A5 3D LDA $3D
C6F1- CD 00 08 CMP $0800
C6F4- A6 2B LDX $2B
C6F6- 90 DB BCC $C6D3
C6F8- 4C 01 08 JMP $0801
C6FB- 00 BRK
C6FC- 00 BRK
C6FD- 00 BRK
C6FE- 00 BRK
C6FF- 00 BRK
Christer Ericson — 15 September 2009, 11:33
The Apple II disk controller and associated hardware is probably the most impressive design I know.
You forgot to mention there's a second 256 byte "program" which is the controller state machine for shifting bits in (and out) of the memory mapped register(s) that the boot ROM addresses (the $C08C,X location, etc).
Changing both programs is what allowed the transition from DOS 3.2 to DOS 3.3 (13 to 16 sectors per track).
Vladimir Strinski — 15 September 2009, 14:40
To add on top of that - he not only coded everything within the 256 bytes, he had a few bytes at the end to spare!
AND on top of that - the first two bytes are a reserved value so the BIOS would recognize the controller, so you can't really use them.
Emil — 15 September 2009, 15:29
Here are some pictures I found of Bulgarian-made Apple ][ clones: the first two are of Pravetz-82 from the late 70s/early 80s, the third picture is of Pravetz-8C from the late 80s/early 90s. These Bulgarian computers were compatible with Apple ][, but their evolution didn't entirely follow the evolution of Apple ][, e.g. some models didn't have an exact original.
Brad Snickenberg — 19 April 2010, 19:03
Back in the '70s you didn't memorize everyone's #, you had them written in your address book (an actual book) and if they weren't in there you looked them up in the phone book which had everyone in town's names and phone #'s listed. OMG privacy!
yo! http://www.appleIIe.com
Ivailo Colov — 08 January 2011, 11:12
The original cpu used in Pravetz 82,8M was a Synertek SY6502 , the bulgarian cpu clone ( CM630) came later with the 8A,8C and 8s Models. Some 82s and 8Ms were with Rockwell R6502 chip.NIce memories ,thankyou :)
Formatting hint: when posting comments, surround code blocks in [@ and @].