# Video, sound and the disk-speed buffer ## Video - **Timing**: pixel clock 15.6672 MHz; a line is 512 shown + 192 blanked pixels (32.68 + 12.25 µs = 44.93 µs, 22.25 kHz); a frame is 342 shown + 28 blanked lines (15,367.65 + 1,258.17 µs = 16,625.8 µs, 60.15 Hz) (DOC: IM3 III-18..19; GMFH p. 400). In CPU clocks (C8M): 352 a line (256 shown, 96 blanked), 130,240 a frame. - **Bitmap**: 512 x 342 x 1 bit = 21,888 bytes; 32 words a line, bit 15 leftmost, 1 = black, 0 = white; lines are contiguous (DOC: IM3 III-19). - **Two screen buffers**, chosen by VIA PA6 (vPage2, 0 = alternate). Main/alternate: 128K $1A700/$12700; 512K add $60000 ($7A700/$72700); Plus 1 MB $FA700/$F2700, 2 MB $1FA700/$1F2700, 2.5 MB $27A700/$272700, 4 MB $3FA700/$3F2700 (DOC: IM3 III-19; IM4 IV-247). The rule: main = top of RAM - $5900, alternate = main - $8000 (GMFH p. 401: the alternate is "ScrnBase - $8000"). The address arithmetic follows from the RAM size: a machine-row function, not a table. - **Fetch**: during a video access the glue disables the CPU's RAM data buffers, puts the video address on the RAM address multiplexers, and loads the word into the video shift register (DOC: GMFH p. 401). One word per 16 pixels on the 128K/512K/Plus, two consecutive words per access on the SE (ibid.). - **Signals software sees**: VIA PB6 (vH4) is 1 during horizontal blanking (DOC: IM3 III-40; GMFH Table 4-11: "0 = video beam in display portion of line") on the 128K/512K/Plus (the SE reuses PB6 as the SCSI IRQ mask: DOC GMFH Table 4-12). The VIA's CA1 receives the vertical-blanking pulse: "at the beginning of the vertical blanking interval, the VIA generates a vertical blanking interrupt" (DOC: IM3 III-18; PCR bit 0 is its edge control, III-40). Where in the line and frame the VBL edge and the H4 edges fall, in CPU clocks, is U4. - **Output contract (proposed)**: a 512 x 342 1-bit frame per 130,240 CPU clocks, with every word fetched at the clock it was fetched, so a write behind the beam is not seen until the next frame (DOC: IM3 III-20: "changes you make in the memory already passed over by the scan spot won't appear until the next frame"). No palette, no TV decoding: black and white. ## Sound (PWM) - **Buffer**: 370 words, one word fetched per line including the 28 "virtual" lines of vertical blanking, so 370 x 60.15 = **22,255 samples a second**; the **high byte** is the sound sample, the **low byte** the disk-speed value (DOC: IM3 III-21). Main/alternate: 128K $1FD00/$1A100, 512K add $60000, Plus 1 MB $FFD00/$FA100 ... 4 MB $3FFD00/$3FA100; main = top of RAM - $300 (DOC: IM3 III-21; IM4 IV-247). Chosen by VIA PA3 (vSndPg2, 0 = alternate). - **Generation**: the high byte sets the width of a pulse ("a pulse of electricity whose duration (width) is proportional to the value in the byte"); another circuit turns it into a voltage attenuated by the 3-bit volume in VIA PA0-PA2 (111 loudest); VIA PB7 (vSndEnb) is 0 to enable (DOC: IM3 III-21; GMFH Table 4-2). Where in the line the pulse starts, its width per count and the filter that follows are U8 (sound may be less exact than pictures: the family's "sound: good enough" rule). - **Square waves from VIA timer 1**: with the buffer filled with a constant and ACR bits 7-6 set for timer 1's free-running PB7 output, the VIA toggles vSndEnb itself; one count is 1.2766 µs (one E-clock period), period = 2 x 1.2766 µs x latch (DOC: IM3 III-22). So the VIA's PB7 output path and the sound enable are the same wire: the board's sound model must take PB7 as the VIA drives it, not only as software writes it. - **External jack** disables the internal speaker; output drives 600 ohms or more (DOC: IM3 III-21). A host matter. ## The disk-speed buffer (128K and 512K with the 400K drive) - The low bytes of the sound buffer are read by the **ASG** (Analog Signal Generator), which "generates a pulse-width modulated signal that's used to control the speed of the disk motor" (DOC: IM3 III-33); the main disk-speed buffer is soundLow + 1 (pwmBuffer = $7FD01 on a 512K, IM3 III-45). Switching to the alternate sound buffer breaks disk speed ("be sure to switch back to the main sound buffer before doing a disk access", IM3 III-22). - The 400K drive's /PWM input: "a fixed pulse rate of from 20 KHz to 40 KHz"; duty = fraction of time low; correct speed for duties of 10% to 90%; at 9.4% duty 305-380 rpm, at 91% duty 625-780 rpm; Apple's implementation runs 22 kHz and dithers the duty over 10 successive pulses for 10x resolution, so the effective control signal is 2.2 kHz; speed group to speed group settling is at most 150 ms (DOC: DRV400 §2.17.1, §3.2.12, and its sector-format appendix). 22.25 kHz line rate = one PWM pulse per line: consistent with "one byte per line" (the match is our inference, HYPOTHESIS until the ASG's behaviour is found in a document). - The **drive model** (open decision 5): speed = f(average duty over the last N lines), filtered by a first-order motor response settling within 150 ms, clamped to the specified range; tagged FITTED/HYPOTHESIS. The Mac's driver checks the speed through the drive's TACH output (60 pulses a revolution, DOC: IM3 III-36; DRV400 §3.2.4) and adjusts the buffer, so the closed loop matters more than the open-loop constants. - The 800K drive ignores /PWM and runs its own zones: 394, 429, 472, 525, 590 rpm for tracks 0-15, 16-31, 32-47, 48-63, 64-79 (DOC: DRV800, its speed table; IM4 IV-251). ## Seeded-fault candidates The video fetch one slot early or late; the alternate buffer bit read with the wrong polarity; the sound byte taken from the low byte; the sound fetch counted on 342 lines instead of 370; H4 with the wrong polarity; timer 1's PB7 toggle not reaching the sound enable; the 400K drive's speed not following the PWM.