# The LCD controller Sources: KH "LCD", "LCD controller", "VRAM Mapping", "Windowing" (measured with a logic analyser on the LCD connector, tier 3); CC65 `gamate.h` (PeT's readings, tier 3 toolchain view); MAME `-listxml` (tier 5). ## Frame buffer - Two 8 KB SRAMs (U2, U3 on the board) form one 16-bit-wide, 8 K-deep VRAM: two **bitplanes** of 8 KB, each a 256 x 256 1-bit map (32 bytes a row, MSB = leftmost pixel) (KH). DOC. - A pixel's two bits (plane 0, plane 1) give four greys by **triple scanning**: each scanline is refreshed three times a frame, plane 0 once with the LCD's bias "level" high and plane 1 twice with it low, so a pixel sees 0-3 refreshes (00b none ... 11b three) (KH). The grey a pixel shows is the panel's analogue response: the board outputs 2-bit pixels; the greys are the host's (decision 3). ## Timing (KH, MEASURED) | Quantity | Value | | --- | --- | | Crystal | 4.433 MHz (KH; MAME's CPU clock 2,216,500 Hz x 2 = 4,433,000) | | Pixel shift | 4 pixels per pixel-clock pulse, 4 crystal clocks apart; 161 pixels emitted per row, one not latched; 2 extra clocks at the row's start/end | | Row | 162 crystal clocks between row-latch pulses | | Frame | 150 scanlines x 3 refreshes x 162 = **72,900 crystal clocks** (36,450 CPU cycles); 4,433,000 / 72,900 = **60.8093 Hz** (MAME's screen rate is the same figure) | | Frame pulse | about 3 row latches long, once a frame | | Invert | toggles every 2 row latches, free-running | KH does not give where in the frame the CPU's VRAM accesses may collide with the refresh fetches, or whether they stall (U6). He reports no stall. ## Registers 5000-5007 (mirrored through 5000-53FF) | Addr | KH | CC65 (PeT) | Agree? | | --- | --- | --- | --- | | 5000 | not used | (base) | - | | 5001 LCDcon | bit 7 N: blank the data (refresh continues); bit 6 X: VRAM address +32 per access (else +1); bit 5 W: window (top 16 rows from VRAM rows D0-DF, X scroll 0); bit 4 S: swap planes; bits 3-1 unknown; bit 0 E: stop refreshing the LCD (can damage the panel) | bit 7 "? lcd flickering"; bit 6 "y auto increment (else x)"; bit 5 "? display effect"; bit 4 "swaps plane intensity"; bit 0 "no normal screen display" | bits 6, 4, 0 agree; KH names 7 and 5 | | 5002 Xscroll | 8-bit X scroll, clean wrap at 256 | "smooth scrolling X" | yes | | 5003 Yscroll | 8-bit Y scroll; the counter wraps at 199 (C7h): a 200-row scroll area; values C8h-FFh select window effects (below) | "smooth scrolling until $c8 with 200 limit"; above it "chaos lines" | yes, in outline | | 5004 Xpos | bit 7 B: plane (0 lower, 1 upper); bits 4-0: low 5 bits of the 13-bit VRAM address | bit 7 plane; bits 5, 6 no effect | yes | | 5005 Ypos | high 8 bits of the VRAM address | "y-addr" | yes | | 5006 Rdat | read VRAM at the address, then increment it by 1 or 32 | "read from RAM (no auto inc?)" | **C3** | | 5007 Wdat | write VRAM (plane by 5004 bit 7), then increment by 1 or 32 | "write to RAM" | yes | All registers except 5006 read as open bus (KH). ## Scrolling and windows (KH) - Visible window 160 x 150 at (Xscroll, Yscroll) in the 256 x 200 scroll area; VRAM 0000-18FF is all that is normally visible. - Yscroll C8-CF, D8-DF, E8-EF, F8-FF behave as 00. D0-D7, E0-E7, F0-F7: the top 1-8 scanlines come from VRAM rows F8-FF (1F00-1FFF), not scrolled by X; "I don't think any games actually used it". - 5001 W: the top 16 rows show VRAM rows D0-DF, unscrolled. - KH's address figures repeat "[0022][0023]" at the right end of rows 2-4 and "[0023][0024]" in the scrolled figure where the pattern gives 0033/0053/0073: typing slips in the figure, not a behaviour (C4, recorded so nobody builds them). ## C2: the visible height KH (measured: 150 scanlines emitted, all with pixel data) and MAME (160 x 150) say 150 rows; CC65's header says "resolution 160x152". KH wins (he counted row latches). ## Unknowns U6 CPU/refresh contention; U7 5001 bits 3-1 and the effect of E and N on frame timing; U8 whether 5006 returns the byte at the address or a prefetched one (as some VRAM ports do); U9 the exact window-mode row selection for each Yscroll value beyond KH's summary; U10 what VRAM holds at power-on (the BIOS clears it, so only the BIOS-less path cares).