← a2cogs.com COGS WEB OverviewGuideHow it works

How CoGS Web works

A 2.8 MHz 65816 with a megabyte or two of memory can't read a modern web page by itself. A front page today is a few megabytes of HTML and style sheets over an encrypted connection, with photographs that take a lot of arithmetic to decode.

CoGS Web does that work on the CoGS card, which is already in the IIGS's slot. No other computer takes part. The card opens the connection to the site itself.

Who does what

The card (a Raspberry Pi Pico 2 W on the CoGS board):

The IIGS (the CoGS.Web program, about 200 KB):

The card never sees the IIGS's screen memory, and the IIGS never sees HTML.

Wikipedia's article on the IIGS. This screen comes out of 390 KB of HTML and 230 KB of style sheets.
Wikipedia's article on the IIGS. This screen comes out of 390 KB of HTML and 230 KB of style sheets.

A key press

When you press Space, the program sends one small request to the card and gets back a reply that says which rows of the screen changed. If the page moved over plain text, the reply also says how far the rows already on screen can be moved, so the IIGS moves them itself and only the new rows cross the bus. Picking the next link is two or three text lines' worth of rows.

Rows are packed before they are sent, and a row that is the same as the one above it is sent as one byte saying so. A row of text is mostly white, so a screen of text is a few kilobytes.

Memory on the card

The card's engine works inside 96 KB, and no single block is over 16 KB. That limit is why the design looks the way it does:

Fonts

The page is set in the IIGS's fonts at the sizes the 640-wide screens use, with Shaston 8 (the system font, which is in the ROM) for the browser's own text. Bold and italic are made the way QuickDraw II makes them, so the text on a page matches text anywhere else on the desktop.

Pictures and color

A 640-mode line has four colors and a 320-mode line sixteen, from one of sixteen palettes. The card cuts white edges off a picture, scales it by area to its place on the page, then fits a palette to each band of the picture with median cut and dithers within the band. Different bands of one photograph use different palettes, which is where the extra color comes from.

A photograph on the 640 x 200 screen.
A photograph on the 640 x 200 screen.

On an AppleSqueezer GS Turbo the 320 x 240 screen has 256 colors, and the card gives each picture colors of its own out of those. The 640 x 400 and 640 x 480 screens give the page twice the rows or more.

The same photograph in 256 colors on a GS Turbo.
The same photograph in 256 colors on a GS Turbo.

The Apple IIe

The card draws the same page for an Apple IIe's double hi-res screen, 560 dots by 192. The IIe's program is about 11 KB of plain 6502 code. Every request it sends names that screen, and the card answers with rows of 80 bytes, 40 for auxiliary memory and 40 for main memory, packed the same way as the IIGS's rows. The IIe copies them to the screen and sends keys back. The rest is the same engine in the same 96 KB.

Text can be laid out two ways. At 560 across every dot is used, which a monochrome monitor shows cleanly. A color monitor turns single dots into colors, so the wide layout sets the page 280 across and draws every pixel two dots wide.

This screen has no palettes. A picture is one bit a dot, 560 across, on either monitor. For a color monitor the card chooses each dot on its own. It works out the color a composite monitor would show for that dot given the dots around it, tries the next six dots both ways, and keeps the choice that comes out nearest the picture in linear light. For a monochrome monitor it sharpens the picture and dithers it with Atkinson's pattern.

NASA's Astronomy Picture of the Day in the 16 double hi-res colors.
NASA's Astronomy Picture of the Day in the 16 double hi-res colors.

Style sheets

The card reads a page's style sheets for the things this screen can act on. Those are what is hidden and shown, bold and italic, a monospace family, small text, alignment, capitals, and lists without markers. Selectors made of tags, classes and ids are followed, and the cascade is applied in its real order. Colors, floats, widths and positions are not used. The card does not try to reproduce a desktop layout at 640 pixels. The aim is that the page's words and pictures come out in reading order with their headings and emphasis intact.

Tables of up to eight columns are set as tables, with columns sized to what is in them. Wider tables and tables used only for layout are read as ordinary lines.

If a page's style sheets hide nearly everything, the card reads the page again without them.

Downloads

A file that is not a page is streamed to the IIGS in pieces and written with GS/OS, so it can go to any volume. For a zip the card inflates the members itself. For a ProDOS disk image it walks the directory and sends each file with its type, auxiliary type, dates and resource fork.

What is left out, and why