#import "@preview/tablex:0.0.6": tablex, cellx, colspanx, rowspanx

= Kinnow Framebuffer
== Introduction

The Kinnow framebuffer card provides a very simple linear 1024x768 framebuffer with 8-bit pixels. The slot space is laid out as follows:

#tablex(
  columns: (1fr, 5fr),

  cellx([
    #set text(fill: white)
    #set align(center)
    *Offset*
  ], fill: rgb(0,0,0,255)),
  cellx([
    #set text(fill: white)
    #set align(center)
    *Purpose*
  ], fill: rgb(0,0,0,255)),
  [+0x000000], [SlotInfo],
  [+0x003000], [Kinnow Registers],
  [+0x100000], [Framebuffer Memory]
)

There are two 32-bit read-only device registers:

#tablex(
  columns: (1fr, 5fr),

  cellx([
    #set text(fill: white)
    #set align(center)
    *Offset*
  ], fill: rgb(0,0,0,255)),
  cellx([
    #set text(fill: white)
    #set align(center)
    *Purpose*
  ], fill: rgb(0,0,0,255)),
  [+0x0], [Display Size],
  [+0x4], [Framebuffer Memory Size],
)

The display size register contains two 12-bit fields. The low 12 bits [0:11] contain the width of the display in pixels, and the next 12 bits [12:23] contain the height of the display in pixels. The framebuffer memory size register contains the size in bytes of the framebuffer memory. It will always be at least large enough to contain the display pixel data, calculated by a simple multiplication of width by height as each pixel occupies only 1 byte.

The framebuffer memory is laid out in row-major order. That is, the first row of a 1024 pixel wide display is stored as a contiguous sequence of 1024 bytes, the next row is the next 1024 bytes, and so on. Therefore, the offset for a particular (X,Y) pair can be calculated by:

```
Offset := (y * Width) + x
```

And, likewise, an offset can be converted to an (X,Y) pair by:

```
Y = Floor(Offset / Width)
X = Offset % Width
```

#box([

== Palette

The pixel color is computed by looking up the 8-bit pixel value in a hardwired palette of 256 colors:

#set align(center)
#image("palette.png", width: 50%)
#set align(left)

])

The RGB values are reproduced below:

	000000
	220022
	000044
	220066
	000088
	2200aa
	0000cc
	2200ee
	440000
	660022
	440044
	660066
	440088
	6600aa
	4400cc
	6600ee
	880000
	aa0022
	880044
	aa0066
	880088
	aa00aa
	8800cc
	aa00ee
	cc0000
	ee0022
	cc0044
	ee0066
	cc0088
	ee00aa
	cc00cc
	ee00ee
	002200
	222222
	002244
	222266
	002288
	2222aa
	0022cc
	2222ee
	442200
	662222
	442244
	662266
	442288
	6622aa
	4422cc
	6622ee
	882200
	aa2222
	882244
	aa2266
	882288
	aa22aa
	8822cc
	aa22ee
	cc2200
	ee2222
	cc2244
	ee2266
	cc2288
	ee22aa
	cc22cc
	ee22ee
	004400
	224422
	004444
	224466
	004488
	2244aa
	0044cc
	2244ee
	444400
	664422
	444444
	664466
	444488
	6644aa
	4444cc
	6644ee
	884400
	aa4422
	884444
	aa4466
	884488
	aa44aa
	8844cc
	aa44ee
	cc4400
	ee4422
	cc4444
	ee4466
	cc4488
	ee44aa
	cc44cc
	ee44ee
	006600
	226622
	006644
	226666
	006688
	2266aa
	0066cc
	2266ee
	446600
	666622
	446644
	666666
	446688
	6666aa
	4466cc
	6666ee
	886600
	aa6622
	886644
	aa6666
	886688
	aa66aa
	8866cc
	aa66ee
	cc6600
	ee6622
	cc6644
	ee6666
	cc6688
	ee66aa
	cc66cc
	ee66ee
	008800
	228822
	008844
	228866
	008888
	2288aa
	0088cc
	2288ee
	448800
	668822
	448844
	668866
	448888
	6688aa
	4488cc
	6688ee
	888800
	aa8822
	888844
	aa8866
	888888
	aa88aa
	8888cc
	aa88ee
	cc8800
	ee8822
	cc8844
	ee8866
	cc8888
	ee88aa
	cc88cc
	ee88ee
	00aa00
	22aa22
	00aa44
	22aa66
	00aa88
	22aaaa
	00aacc
	22aaee
	44aa00
	66aa22
	44aa44
	66aa66
	44aa88
	66aaaa
	44aacc
	66aaee
	88aa00
	aaaa22
	88aa44
	aaaa66
	88aa88
	aaaaaa
	88aacc
	aaaaee
	ccaa00
	eeaa22
	ccaa44
	eeaa66
	ccaa88
	eeaaaa
	ccaacc
	eeaaee
	00cc00
	22cc22
	00cc44
	22cc66
	00cc88
	22ccaa
	00cccc
	22ccee
	44cc00
	66cc22
	44cc44
	66cc66
	44cc88
	66ccaa
	44cccc
	66ccee
	88cc00
	aacc22
	88cc44
	aacc66
	88cc88
	aaccaa
	88cccc
	aaccee
	cccc00
	eecc22
	cccc44
	eecc66
	cccc88
	eeccaa
	cccccc
	eeccee
	00ee00
	22ee22
	00ee44
	22ee66
	00ee88
	22eeaa
	00eecc
	22eeee
	44ee00
	66ee22
	44ee44
	66ee66
	44ee88
	66eeaa
	44eecc
	66eeee
	88ee00
	aaee22
	88ee44
	aaee66
	88ee88
	aaeeaa
	88eecc
	aaeeee
	ccee00
	eeee22
	ccee44
	eeee66
	ccee88
	eeeeaa
	cceecc
	ffffff