diff --git a/README.md b/README.md index 51367c3..e742914 100644 --- a/README.md +++ b/README.md @@ -529,7 +529,7 @@ which is the one combination none of those keyboards could produce. | `alt+shift+1` / `alt+shift+2` | put a new blank formatted disk straight in | | `alt+g` | write a picture of the screen | | `alt+x` | switch between the machine's character generator and the terminal's own letters | -| `alt+m` | switch between a monochrome monitor and a colour one | +| `alt+m` | go round the three displays: a monochrome monitor, a colour one, and the IIc's flat panel | | `alt+q` | quit, whatever else is on screen | A II Plus keyboard could not produce lowercase and its model folds it away, @@ -3228,6 +3228,35 @@ else to start with, and `alt+m` and `alt+x` change either of them while the machine runs. `line.dots` is the monochrome monitor, and it has been in the renderer since it was written — it just had nothing asking for it. +**There is a third display, and it is the Apple IIc's Flat Panel Display**: +`--monitor flat-panel`, or `flat`, or `lcd`. A seven-inch liquid crystal panel +of 1984 that clipped onto the machine and gave it a screen without a monitor, +$595 and about ten thousand made. Five hundred and sixty by a hundred and +ninety-two, one bit deep — which is *exactly* the dot stream, eighty columns of +seven dots and the same hundred and ninety-two lines, so it shows one panel +pixel per dot and no composite artefact colour at all, there being no composite +signal for artefacts to happen in. + +It is a **monitor** here and not hardware, because that is all it is. It hung +off the IIc's DB-15 video expansion connector, which carries timing and video +signals and no registers whatever — `TEXT`, `14M`, `SYNC*`, `LDPS*`, `CREF`, +`PRAS`, `SEROUT*`, `VIDD7`. There is no soft switch for it, no firmware, and +nothing a program can ask about it: software on a IIc with a flat panel and +software on a IIc with a television are the same software doing the same +thing. So the whole of modelling it is deciding what the dots look like. + +And **what they look like is a choice, not a fact**, in exactly the way the +sixteen colours are a choice. Apple's service manual for the panel describes it +as modules, connectors and screws and never says what it looked like; the +Technical Reference describes the connector rather than the display on the end +of it. So there is no document to be faithful to, and what is here is a passive +liquid crystal panel of 1984 as such panels were: dark segments on a pale +ground. That polarity is the point — it is the one thing that makes it look +unlike a monitor rather than merely dimmer than one. Two screenshots off the +same machine a moment apart have the same 1,080 lit dots and the same 213,960 +of ground; the monitor draws them `#ffffff` on `#000000` and the panel +`#1a2226` on `#a8b8a4`. + ### Booting GS/OS GS/OS boots, and most of what goes wrong on the way to it is configuration @@ -7140,8 +7169,14 @@ this does not model. The service manual for the IIc's optional liquid crystal display: what its modules are, how they fail, how the case comes apart, and the part numbers. It describes the panel as hardware and says nothing about what software sees - of it, so it settles questions about the product and none about the machine. - Here because the flat panel is a part of the IIc this does not model. + of it, so it settles questions about the product and none about the machine — + which turns out to be the whole story rather than a shortcoming, because + there is nothing about the panel for software to see. It hangs off the video + expansion connector, which carries video and timing signals and no registers, + so `--monitor flat-panel` is a monitor and not a device. Here rather than in + the reference list because nothing in the source cites it: what it would have + settled — what the panel looked like — is the one thing it does not say, so + the two colours in `picture.Monitor.ink` are a choice and say so. - Apple Computer, Inc. (1985–1986). *Cortland documentation set*. diff --git a/completions/zig65.fish b/completions/zig65.fish index 1a90865..8f655ae 100644 --- a/completions/zig65.fish +++ b/completions/zig65.fish @@ -85,9 +85,9 @@ complete -c zig65 -l memory -x -a '4K 8K 12K 12K-hires 16K 20K 24K 32K 36K 48K 2 complete -c zig65 -l revision -x -a '0 1' \ -n 'not __fish_seen_argument -l revision' \ -d "Which Apple II board: 0 for the first ones, without the colour-burst killer, the Hi-Res delay or the power-up reset" -complete -c zig65 -l monitor -x -a 'monochrome colour' \ +complete -c zig65 -l monitor -x -a 'monochrome colour flat-panel' \ -n 'not __fish_seen_argument -l monitor' \ - -d 'Which monitor the machine is looked at on. alt+m changes it' + -d "Which display the machine is looked at on, the IIc's flat panel among them. alt+m changes it" complete -c zig65 -l text -x -a 'pixels terminal' \ -n 'not __fish_seen_argument -l text' \ -d "Whether the machine's character generator draws the text. alt+x changes it" diff --git a/src/gs.zig b/src/gs.zig index 9e79dac..56159b7 100644 --- a/src/gs.zig +++ b/src/gs.zig @@ -425,14 +425,13 @@ const App = struct { const which: picture.Display = if (super) .super_hires else .apple2; // What is on the screen, including which monitor it is being looked // at on. - const mono = self.monitor.isMonochrome(); picture.write( self.session.io, self.session.gpa, which, &self.session.cpu.memory.mega2, self.screenshot, - .{ .monochrome = mono }, + .{ .monitor = self.monitor }, ) catch |err| { self.session.say("could not write {s}: {s}", .{ self.screenshot, @errorName(err) }); return; @@ -526,7 +525,7 @@ const App = struct { mega2, if (super) .super_hires else .apple2, lines, - self.monitor.isMonochrome(), + self.monitor, hash, )) |_| { drawn = true; diff --git a/src/main.zig b/src/main.zig index f98ddd1..a769704 100644 --- a/src/main.zig +++ b/src/main.zig @@ -380,11 +380,14 @@ const usage = \\ 3.5-inch drives off the cable, since those sit in \\ front of it and the startup stops at the first device \\ it finds. - \\ --monitor NAME monochrome, which is the default, or colour. Which - \\ monitor the machine is being looked at on: monochrome - \\ ignores the colour the dots make, which is sharper - \\ and is the only way eighty column text is readable. - \\ alt+m changes it while it runs. + \\ --monitor NAME monochrome, which is the default, colour, or + \\ flat-panel. Which display the machine is being looked + \\ at on: monochrome ignores the colour the dots make, + \\ which is sharper and is the only way eighty column + \\ text is readable. flat-panel is the Apple IIc's Flat + \\ Panel Display of 1984, a liquid crystal panel of the + \\ same 560 by 192 dots, dark on a pale ground. alt+m + \\ goes round the three while it runs. \\ --text NAME pixels, which is the default, or terminal. Whether \\ the machine's own character generator draws the text \\ or the terminal's letters do. A terminal that cannot @@ -872,7 +875,7 @@ fn applyConfig(options: *Options, rom: *?[]const u8, file: config.Config) void { if (file.appletalk) |yes| options.appletalk = yes; if (file.battery_ram) |path| options.battery_ram = path; if (file.monitor) |name| options.monitor = terminal.Monitor.parse(name) orelse { - std.debug.print("zig65: monitor wants monochrome or colour, not '{s}'\n", .{name}); + std.debug.print("zig65: monitor wants monochrome, colour or flat-panel, not '{s}'\n", .{name}); std.process.exit(2); }; if (file.text) |name| options.text = terminal.TextDrawing.parse(name) orelse { @@ -1007,7 +1010,7 @@ fn parseArgs(args: std.process.Args, io: std.Io, gpa: std.mem.Allocator) ?Option } else if (std.mem.eql(u8, arg, "--monitor")) { const name = wants.path(&it, "--monitor"); options.monitor = terminal.Monitor.parse(name) orelse { - std.debug.print("zig65: --monitor wants monochrome or colour, not '{s}'\n", .{name}); + std.debug.print("zig65: --monitor wants monochrome, colour or flat-panel, not '{s}'\n", .{name}); std.process.exit(2); }; } else if (std.mem.eql(u8, arg, "--text")) { @@ -2155,9 +2158,8 @@ fn Debugger(comptime machine: Machine, comptime processor: Processor) type { } // What is on the screen, including which monitor it is being looked at // on. - const mono = self.monitor.isMonochrome(); try picture.write(self.io, self.alloc, .apple2, &self.session.cpu.memory, self.screenshot, .{ - .monochrome = mono, + .monitor = self.monitor, }); } @@ -2519,7 +2521,7 @@ fn Debugger(comptime machine: Machine, comptime processor: Processor) type { &self.session.cpu.memory, .apple2, lines, - self.monitor.isMonochrome(), + self.monitor, terminal.videoHash(&self.session.cpu.memory, showing, self.session.flash), )) |_| return else |_| {} } diff --git a/src/picture.zig b/src/picture.zig index 6dcaa75..0a4be5c 100644 --- a/src/picture.zig +++ b/src/picture.zig @@ -89,11 +89,98 @@ pub const Options = struct { /// why it repeats. across: u3 = 1, down: u3 = 2, - /// Whether to draw the black and white a monochrome monitor shows rather - /// than the colour a composite one makes of it. Text is much easier to - /// read this way, and it is how text was usually looked at. It means - /// nothing to Super Hi-Res, which has no composite artefacts to drop. - monochrome: bool = false, + /// Which display the dot stream is being looked at on. + monitor: Monitor = .colour, +}; + +/// The three displays an Apple II's dot stream could be looked at on. +/// +/// This is a property of the *screen*, not of the machine: what comes out of +/// an Apple II is a stream of dots and a set of timing signals, and what those +/// become depends entirely on what is plugged in. All three see the same +/// stream. +pub const Monitor = enum { + /// A composite colour monitor, which turns the dot stream into colour by + /// the rule in `video.zig`. + colour, + /// A monochrome monitor, which shows the dots as dots. Text is much easier + /// to read this way and it is how text was usually looked at. + monochrome, + /// The Apple IIc's Flat Panel Display, 1984: a seven-inch liquid crystal + /// panel of 560 by 192 pixels, one bit deep, that clipped onto the machine + /// and gave it a screen without a monitor. + /// + /// It is here as a *monitor* and not as hardware because that is all it + /// is. It hung off the IIc's DB-15 video expansion connector, which + /// carries timing and video signals and no registers at all -- `TEXT`, + /// `14M`, `SYNC*`, `LDPS*`, `CREF`, `PRAS`, `SEROUT*` and `VIDD7` (Apple + /// Computer, Inc., 1989b, Table 11-32, p. 376). There is no soft switch + /// for it, no firmware, and nothing a program can ask about it: software + /// on a IIc with a flat panel and software on a IIc with a television are + /// the same software doing the same thing. + /// + /// Five hundred and sixty by a hundred and ninety-two is exactly the dot + /// stream: eighty columns of seven dots, and the same hundred and + /// ninety-two lines. So this is the most literal of the three -- one panel + /// pixel per dot, no composite rule and no artefact colour, because there + /// is no composite signal for artefacts to happen in. + flat_panel, + + pub fn other(self: Monitor) Monitor { + return switch (self) { + .monochrome => .colour, + .colour => .flat_panel, + .flat_panel => .monochrome, + }; + } + + /// Whether the dots are drawn as dots rather than run through the colour + /// rule, which both of the non-composite displays do. + pub fn isMonochrome(self: Monitor) bool { + return self != .colour; + } + + pub fn describe(self: Monitor) []const u8 { + return switch (self) { + .monochrome => "a monochrome monitor", + .colour => "a colour monitor", + .flat_panel => "the flat panel", + }; + } + + pub fn parse(name: []const u8) ?Monitor { + if (std.mem.eql(u8, name, "monochrome") or std.mem.eql(u8, name, "mono")) return .monochrome; + if (std.mem.eql(u8, name, "colour") or std.mem.eql(u8, name, "color")) return .colour; + if (std.mem.eql(u8, name, "flat-panel") or std.mem.eql(u8, name, "flat") or + std.mem.eql(u8, name, "lcd")) return .flat_panel; + return null; + } + + /// What a dot looks like on it: the ink first, then the ground. + /// + /// **The flat panel's two colours are a choice and not a fact**, in + /// exactly the way `video.palette` is a choice: Apple's service manual for + /// the panel describes it as modules, connectors and screws and never says + /// what it looked like, and the Technical Reference describes the + /// connector rather than the display on the end of it. So there is no + /// document to be faithful to here. What is here is a passive liquid + /// crystal panel of 1984 as such panels were -- dark segments on a pale + /// ground, which is the one thing that makes it look unlike a monitor + /// rather than merely dimmer than one. Replace it if you have a panel in + /// mind. + pub fn ink(self: Monitor) [2]video.Rgb { + return switch (self) { + .flat_panel => .{ + .{ .r = 0x1a, .g = 0x22, .b = 0x26 }, + .{ .r = 0xa8, .g = 0xb8, .b = 0xa4 }, + }, + // A monitor is a dark tube with a lit phosphor on it. + else => .{ + video.palette[@intFromEnum(video.Colour.white)], + video.palette[@intFromEnum(video.Colour.black)], + }, + }; + } }; /// How big a surface is, in pixels. @@ -155,8 +242,9 @@ fn paintVideo(machine: anytype, surface: *z2d.Surface, options: Options) void { for (0..video.height) |y| { _ = video.scanLine(machine, @intCast(y), &line); for (0..video.width) |x| { - const colour = if (options.monochrome) - video.palette[if (line.dots[x]) @intFromEnum(video.Colour.white) else 0] + const shown = options.monitor.ink(); + const colour = if (options.monitor.isMonochrome()) + shown[if (line.dots[x]) 0 else 1] else video.palette[line.colours[x]]; put(surface, x, y, colour, options); @@ -194,7 +282,7 @@ fn paintVideoterm(machine: anytype, surface: *z2d.Surface, options: Options) voi const square: Options = .{ .across = options.across, .down = @max(1, options.across), - .monochrome = true, + .monitor = .monochrome, }; const tall = videx.pictureHeight(card); const wide = videx.pictureWidth(card); @@ -488,7 +576,7 @@ test "monochrome is the dots rather than what four of them come to" { machine.* = .{ .showing = .text }; for (0..40) |c| machine.text(c, 0xcc); // a row of Ls - const options: Options = .{ .across = 1, .down = 1, .monochrome = true }; + const options: Options = .{ .across = 1, .down = 1, .monitor = .monochrome }; const wanted = size(.apple2, options); var surface: z2d.Surface = try .init(.image_surface_rgb, gpa, wanted.width, wanted.height); defer surface.deinit(gpa); @@ -539,3 +627,52 @@ test "Super Hi-Res comes out of its own palettes" { try testing.expectEqual(@as(u8, 0xff), got.g); } } + +test "the three displays paint the same dot stream three ways" { + // What comes out of an Apple II is a stream of dots and some timing + // signals. All three of these see exactly that stream; the difference is + // entirely in what they make of it, which is why this is a property of the + // screen and not of the machine. + try testing.expect(!Monitor.colour.isMonochrome()); + try testing.expect(Monitor.monochrome.isMonochrome()); + // The flat panel is not a composite display at all -- it takes the dots + // off the video expansion connector -- so there are no artefact colours + // for it to show, and it draws the dots as dots like the monitor does. + try testing.expect(Monitor.flat_panel.isMonochrome()); +} + +test "a monitor is light on dark and the panel is dark on light" { + // The one thing that makes a liquid crystal panel look unlike a monitor + // rather than merely dimmer than one. Both colours are a choice -- see + // `Monitor.ink` -- but which way round they go is the point of having it. + const tube = Monitor.monochrome.ink(); + const panel = Monitor.flat_panel.ink(); + const brightness = struct { + fn of(c: video.Rgb) u32 { + return @as(u32, c.r) + c.g + c.b; + } + }; + try testing.expect(brightness.of(tube[0]) > brightness.of(tube[1])); + try testing.expect(brightness.of(panel[0]) < brightness.of(panel[1])); +} + +test "alt+m goes round all three rather than between two" { + var at: Monitor = .monochrome; + var seen: [3]bool = @splat(false); + for (0..3) |_| { + seen[@intFromEnum(at)] = true; + at = at.other(); + } + for (seen) |was| try testing.expect(was); + // And it comes back to where it started, so the cycle is a cycle. + try testing.expectEqual(Monitor.monochrome, at); +} + +test "the flat panel is named by more than one thing somebody might type" { + try testing.expectEqual(Monitor.flat_panel, Monitor.parse("flat-panel").?); + try testing.expectEqual(Monitor.flat_panel, Monitor.parse("flat").?); + try testing.expectEqual(Monitor.flat_panel, Monitor.parse("lcd").?); + try testing.expectEqual(Monitor.monochrome, Monitor.parse("mono").?); + try testing.expectEqual(Monitor.colour, Monitor.parse("color").?); + try testing.expect(Monitor.parse("plasma") == null); +} diff --git a/tools/terminal.zig b/tools/terminal.zig index 658e1a1..dd32169 100644 --- a/tools/terminal.zig +++ b/tools/terminal.zig @@ -162,8 +162,9 @@ pub const Display = struct { /// /// `lines` is how many of the display's lines to show, which is fewer than /// all of them for a mixed screen whose bottom rows a terminal draws - /// better as text. `monochrome` draws the dots rather than the colour four - /// of them at a time come to, which is what a monochrome monitor showed. + /// better as text. `monitor` says which display the dots are being looked + /// at on: a composite colour one, a monochrome one, or the IIc's flat + /// panel, which are three different things to paint the same stream as. pub fn draw( self: *Display, gpa: std.mem.Allocator, @@ -175,7 +176,7 @@ pub const Display = struct { machine: anytype, which: picture.Display, lines: u16, - monochrome: bool, + monitor: picture.Monitor, hash: u64, ) !void { // A buffer is thrown away and built again when the display changes, @@ -203,8 +204,8 @@ pub const Display = struct { // Changing monitors means everything on the screen is different, so // the picture goes again whatever the hash says. - if (self.buffer.?.options.monochrome != monochrome) { - self.buffer.?.options.monochrome = monochrome; + if (self.buffer.?.options.monitor != monitor) { + self.buffer.?.options.monitor = monitor; self.image = null; } @@ -496,34 +497,10 @@ fn hashRange(machine: anytype, hash: *std.hash.Wyhash, base: u16, length: u17, h } } -pub const Monitor = enum { - monochrome, - colour, - - pub fn other(self: Monitor) Monitor { - return switch (self) { - .monochrome => .colour, - .colour => .monochrome, - }; - } - - pub fn isMonochrome(self: Monitor) bool { - return self == .monochrome; - } - - pub fn describe(self: Monitor) []const u8 { - return switch (self) { - .monochrome => "a monochrome monitor", - .colour => "a colour monitor", - }; - } - - pub fn parse(name: []const u8) ?Monitor { - if (std.mem.eql(u8, name, "monochrome") or std.mem.eql(u8, name, "mono")) return .monochrome; - if (std.mem.eql(u8, name, "colour") or std.mem.eql(u8, name, "color")) return .colour; - return null; - } -}; +/// Which display the machine is being looked at on, which is the library's: +/// the difference between the three is what the dots are painted as, so the +/// choice belongs beside the painting. See `picture.Monitor`. +pub const Monitor = picture.Monitor; /// Who draws the text: the terminal, or the machine. ///