// Generator for the data which goes into the three JPEG EEPROMs.

// "Standard" quantization and Huffman tables ripped from
// source code to libjpeg.a by Thomas G. Lane and the 
// Independent JPEG group. Header comment from that code follows.

/*
 * Copyright (C) 1991-1996, Thomas G. Lane.
 * This file is part of the Independent JPEG Group's software.
 * For conditions of distribution and use, see the accompanying README file.
 *
 */

#include <stdio.h>

typedef struct {
  int address;
  int data;
} Datum;

Datum jpegRegs[] = {
		/* Control Registers */
{0x0,		0x0},	/* Empty entry for "GO" command */
{0x1,		0x0},	/* Required "zero" register */
{0x2,		0xA0},	/* HARDWARE register: 16-bit DMA (0b10100000) */
{0x3,		0xA0},	/* MODE register: baseline comp. (0b10100000) */
{0x4,		0xC0},	/* OPTIONS register: 4 scans (0b01100000) */
{0x6,		0x1B},	/* MARKERS_EN: preload/include (0b00011011) */
			/* quant, Huff tables */
{0x7,		0x00},	/* INT_REQ_0 (no interrupts) (0b00000000) */
{0x8,		0x00},	/* INT_REQ_1 (no interrupts) (0b00000000) */
{0x9,		0x00},	/* This and next three bytes are Target Net */
{0xA,		0x1C},	/* Code volume. Aiming for factor of 20 */
{0xB,		0x20},	/* compression ratio, which is */
{0xC,		0x00},	/* 160*240*4*30/20*8 bits (in hex) */
			/* Note this value only works with these */
			/* dimensions (which need to be set in */
			/* pc_const.inc) */
{0x11,		0x14},	/* This is intended to represent a factor of */
{0x12,		0x00},	/* 20 compression, but I don't know if it'll work */
		
		/* Data for marker segments for ZR36050. */
			/*              */
			/* SOFO Segment */
			/*              */
{0x040,		0xFF},
{0x041,		0xC0},
			/* Length of SOF0 segment: 2 bytes. */
			/* Length includes the length measurement but not the previous */
			/* 2-byte header. There are 17 (0x11) bytes of SOF0 data below. */
{0x042,		0x00},
{0x043,		0x11},
{0x044,		0x8},	/* Precision */
			/* Number of lines: 2 bytes. Value is 240*30 = 7200 (0x1C20) */
{0x045,		0x1C},
{0x046,		0x20},
			/* Number of columns in the frame's internal representation: 320 (0x0140) */
{0x047,		0x01},
{0x048,		0x40},
{0x049,		0x03},	/* 3 components per frame: Y, U, V (2 samples of Y) */
			/* Data for the first (luminance) component */
{0x04A,		0x00},  /* ID = 0 */
{0x04B,		0x21},  /* 2 samples horizontally */
{0x04C,		0x00},  /* Use quantization table 0 */
			/* Data for the second component (U) */
{0x04D,		0x01},	/* ID = 1 */
{0x04E,		0x11},	/* 1 sample horizontally and vertically */
{0x04F,		0x01},	/* Use quantization table 1 */
			/* Data for the third component (V) */
{0x050,		0x02},	/* ID = 2 */
{0x051,		0x11},	/* 1 sample horizontally and vertically */
{0x052,		0x01},	/* Use quantization table 1 */
			/*             */
			/* SOS Segment */
			/*             */
{0x07A,		0xFF},
{0x07B,		0xDA},
			/* Length: 2 bytes */
{0x07C,		0x00},
{0x07D,		0x0E},  /* 14 (0x0E) bytes long */
{0x07E,		0x03},	/* 3 components */
{0x07F,		0x00},	/* ID = 0 */
{0x080,		0x00},	/* Huffman table components = ID 0 for DC and AC */
{0x081,		0x01},	/* ID = 1 */
{0x082,		0x11},	/* Huffman table components = ID 1 for DC and AC */
{0x083,		0x02},	/* ID = 2 */
{0x084,		0x11},	/* Huffman table components = ID 1 for DC and AC */
			/* Addresses 085 and 086 ignored */
			/* End of segment has bytes 00 3F 00 */ 
{0x087,		0x00},
{0x088,		0x3F},
{0x089,		0x00},
			/*             */
			/* DQT Segment */
			/*             */
{0x0CC,		0xFF},
{0x0CD,		0xDB},
			/* Length: 2 bytes. */
{0x0CE,		0x00},
{0x0CF,		0x84},	/* 2 tables: first is luminance, second is chrominance */
{0x0D0,		0x00},	/* First table: hi 0 = 8 bits precision, lo 0 = ID 0 */
			/* NOTE: These values are specified in DECIMAL form. */
{0x0D1,		16},
{0x0D2,		11},
{0x0D3,		10},
{0x0D4,		16},
{0x0D5,		24},
{0x0D6,		40},
{0x0D7,		51},
{0x0D8,		61},
{0x0D9,		12},
{0x0DA,		12},
{0x0DB,		14},
{0x0DC,		19},
{0x0DD,		26},
{0x0DE,		58},
{0x0DF,		60},
{0x0E0,		55},
{0x0E1,		14},
{0x0E2,		13},
{0x0E3,		16},
{0x0E4,		24},
{0x0E5,		40},
{0x0E6,		57},
{0x0E7,		69},
{0x0E8,		56},
{0x0E9,		14},
{0x0EA,		17},
{0x0EB,		22},
{0x0EC,		29},
{0x0ED,		51},
{0x0EE,		87},
{0x0EF,		80},
{0x0F0,		62},
{0x0F1,		18},
{0x0F2,		22},
{0x0F3,		37},
{0x0F4,		56},
{0x0F5,		68},
{0x0F6,		109},
{0x0F7,		103},
{0x0F8,		77},
{0x0F9,		24},
{0x0FA,		35},
{0x0FB,		55},
{0x0FC,		64},
{0x0FD,		81},
{0x0FE,		104},
{0x0FF,		113},
{0x100,		92},
{0x101,		49},
{0x102,		64},
{0x103,		78},
{0x104,		87},
{0x105,		103},
{0x106,		121},
{0x107,		120},
{0x108,		101},
{0x109,		72},
{0x10A,		92},
{0x10B,		95},
{0x10C,		98},
{0x10D,		112},
{0x10E,		100},
{0x10F,		103},
{0x110,		99},
{0x111,		0x01},	/* Second table: hi 0 = 8 bits precision, lo 1 = ID 1 */
{0x112,		17},
{0x113,		18},
{0x114,		24},
{0x115,		47},
{0x116,		99},
{0x117,		99},
{0x118,		99},
{0x119,		99},
{0x11A,		18},
{0x11B,		21},
{0x11C,		26},
{0x11D,		66},
{0x11E,		99},
{0x11F,		99},
{0x120,		99},
{0x121,		99},
{0x122,		24},
{0x123,		26},
{0x124,		56},
{0x125,		99},
{0x126,		99},
{0x127,		99},
{0x128,		99},
{0x129,		99},
{0x12A,		47},
{0x12B,		66},
{0x12C,		99},
{0x12D,		99},
{0x12E,		99},
{0x12F,		99},
{0x130,		99},
{0x131,		99},
{0x132,		99},
{0x133,		99},
{0x134,		99},
{0x135,		99},
{0x136,		99},
{0x137,		99},
{0x138,		99},
{0x139,		99},
{0x13A,		99},
{0x13B,		99},
{0x13C,		99},
{0x13D,		99},
{0x13E,		99},
{0x13F,		99},
{0x140,		99},
{0x141,		99},
{0x142,		99},
{0x143,		99},
{0x144,		99},
{0x145,		99},
{0x146,		99},
{0x147,		99},
{0x148,		99},
{0x149,		99},
{0x14A,		99},
{0x14B,		99},
{0x14C,		99},
{0x14D,		99},
{0x14E,		99},
{0x14F,		99},
{0x150,		99},
{0x151,		99},
			/*             */
			/* DHT Segment */
			/*             */
{0x1D4,		0xFF},
{0x1D5,		0xC4},
			/* Length: 2 bytes */
{0x1D6,		0x01},
{0x1D7,		0xA2},	/* 418 (0x1A2) bytes in this segment */

{0x1D8,		0x00},	/* Start definition of first (luminance) DC Huffman table */
{0x1D9,		0},  /* Bits */
{0x1DA,		1},
{0x1DB,		5},
{0x1DC,		1},
{0x1DD,		1},
{0x1DE,		1},
{0x1DF,		1},
{0x1E0,		1},
{0x1E1,		1},
{0x1E2,		0},
{0x1E3,		0},
{0x1E4,		0},
{0x1E5,		0},
{0x1E6,		0},
{0x1E7,		0},
{0x1E8,		0},
{0x1E9,		0}, /* Values */
{0x1EA,		1},
{0x1EB,		2},
{0x1EC,		3},
{0x1ED,		4},
{0x1EE,		5},
{0x1EF,		6},
{0x1F0,		7},
{0x1F1,		8},
{0x1F2,		9},
{0x1F3,		10},
{0x1F4,		11},
{0x1F5,		0x01},	/* Start definition of second (chrominance) DC Huffman table */
{0x1F6,		0},   /* Bits */
{0x1F7,		3},
{0x1F8,		1},
{0x1F9,		1},
{0x1FA,		1},
{0x1FB,		1},
{0x1FC,		1},
{0x1FD,		1},
{0x1FE,		1},
{0x1FF,		1},
{0x200,		1},
{0x201,		0},
{0x202,		0},
{0x203,		0},
{0x204,		0},
{0x205,		0},
{0x206,		0},  /* Values */
{0x207,		1},
{0x208,		2},
{0x209,		3},
{0x20A,		4},
{0x20B,		5},
{0x20C,		6},
{0x20D,		7},
{0x20E,		8},
{0x20F,		9},
{0x210,		10},
{0x211,		11},
{0x212,		0x10},	/* Start definition of the first (luminance) AC Huffman table */
{0x213,		0},   /* Bits */
{0x214,		2},
{0x215,		1},
{0x216,		3},
{0x217,		3},
{0x218,		2},
{0x219,		4},
{0x21A,		3},
{0x21B,		5},
{0x21C,		5},
{0x21D,		4},
{0x21E,		4},
{0x21F,		0},
{0x220,		0},
{0x221,		1},
{0x222,		0x7D},
{0x223,		0x01},	/* Values */
{0x224,		0x02},
{0x225,		0x03},
{0x226,		0x00},
{0x227,		0x04},
{0x228,		0x11},
{0x229,		0x05},
{0x22A,		0x12},
{0x22B,		0x21},
{0x22C,		0x31},
{0x22D,		0x41},
{0x22E,		0x06},
{0x22F,		0x13},
{0x230,		0x51},
{0x231,		0x61},
{0x232,		0x07},
{0x233,		0x22},
{0x234,		0x71},
{0x235,		0x14},
{0x236,		0x32},
{0x237,		0x81},
{0x238,		0x91},
{0x239,		0xA1},
{0x23A,		0x08},
{0x23B,		0x23},
{0x23C,		0x42},
{0x23D,		0xB1},
{0x23E,		0xC1},
{0x23F,		0x15},
{0x240,		0x52},
{0x241,		0xD1},
{0x242,		0xF0},
{0x243,		0x24},
{0x244,		0x33},
{0x245,		0x62},
{0x246,		0x72},
{0x247,		0x82},
{0x248,		0x09},
{0x249,		0x0A},
{0x24A,		0x16},
{0x24B,		0x17},
{0x24C,		0x18},
{0x24D,		0x19},
{0x24E,		0x1A},
{0x24F,		0x25},
{0x250,		0x26},
{0x251,		0x27},
{0x252,		0x28},
{0x253,		0x29},
{0x254,		0x2A},
{0x255,		0x34},
{0x256,		0x35},
{0x257,		0x36},
{0x258,		0x37},
{0x259,		0x38},
{0x25A,		0x39},
{0x25B,		0x3A},
{0x25C,		0x43},
{0x25D,		0x44},
{0x25E,		0x45},
{0x25F,		0x46},
{0x260,		0x47},
{0x261,		0x48},
{0x262,		0x49},
{0x263,		0x4A},
{0x264,		0x53},
{0x265,		0x54},
{0x266,		0x55},
{0x267,		0x56},
{0x268,		0x57},
{0x269,		0x58},
{0x26A,		0x59},
{0x26B,		0x5A},
{0x26C,		0x63},
{0x26D,		0x64},
{0x26E,		0x65},
{0x26F,		0x66},
{0x270,		0x67},
{0x271,		0x68},
{0x272,		0x69},
{0x273,		0x6A},
{0x274,		0x73},
{0x275,		0x74},
{0x276,		0x75},
{0x277,		0x76},
{0x278,		0x77},
{0x279,		0x78},
{0x27A,		0x79},
{0x27B,		0x7A},
{0x27C,		0x83},
{0x27D,		0x84},
{0x27E,		0x85},
{0x27F,		0x86},
{0x280,		0x87},
{0x281,		0x88},
{0x282,		0x89},
{0x283,		0x8A},
{0x284,		0x92},
{0x285,		0x93},
{0x286,		0x94},
{0x287,		0x95},
{0x288,		0x96},
{0x289,		0x97},
{0x28A,		0x98},
{0x28B,		0x99},
{0x28C,		0x9A},
{0x28D,		0xA2},
{0x28E,		0xA3},
{0x28F,		0xA4},
{0x290,		0xA5},
{0x291,		0xA6},
{0x292,		0xA7},
{0x293,		0xA8},
{0x294,		0xA9},
{0x295,		0xAA},
{0x296,		0xB2},
{0x297,		0xB3},
{0x298,		0xB4},
{0x299,		0xB5},
{0x29A,		0xB6},
{0x29B,		0xB7},
{0x29C,		0xB8},
{0x29D,		0xB9},
{0x29E,		0xBA},
{0x29F,		0xC2},
{0x2A0,		0xC3},
{0x2A1,		0xC4},
{0x2A2,		0xC5},
{0x2A3,		0xC6},
{0x2A4,		0xC7},
{0x2A5,		0xC8},
{0x2A6,		0xC9},
{0x2A7,		0xCA},
{0x2A8,		0xD2},
{0x2A9,		0xD3},
{0x2AA,		0xD4},
{0x2AB,		0xD5},
{0x2AC,		0xD6},
{0x2AD,		0xD7},
{0x2AE,		0xD8},
{0x2AF,		0xD9},
{0x2B0,		0xDA},
{0x2B1,		0xE1},
{0x2B2,		0xE2},
{0x2B3,		0xE3},
{0x2B4,		0xE4},
{0x2B5,		0xE5},
{0x2B6,		0xE6},
{0x2B7,		0xE7},
{0x2B8,		0xE8},
{0x2B9,		0xE9},
{0x2BA,		0xEA},
{0x2BB,		0xF1},
{0x2BC,		0xF2},
{0x2BD,		0xF3},
{0x2BE,		0xF4},
{0x2BF,		0xF5},
{0x2C0,		0xF6},
{0x2C1,		0xF7},
{0x2C2,		0xF8},
{0x2C3,		0xF9},
{0x2C4,		0xFA},
{0x2C5,		0x11},	/* Start definition of the second (chrominance) AC Huffman table */
{0x2C6,		0},  /* Bits */
{0x2C7,		2},
{0x2C8,		1},
{0x2C9,		2},
{0x2CA,		4},
{0x2CB,		4},
{0x2CC,		3},
{0x2CD,		4},
{0x2CE,		7},
{0x2CF,		5},
{0x2D0,		4},
{0x2D1,		4},
{0x2D2,		0},
{0x2D3,		1},
{0x2D4,		2},
{0x2D5,		0x77},
{0x2D6,		0x00},	/* Values */
{0x2D7,		0x01},
{0x2D8,		0x02},
{0x2D9,		0x03},
{0x2DA,		0x11},
{0x2DB,		0x04},
{0x2DC,		0x05},
{0x2DD,		0x21},
{0x2DE,		0x31},
{0x2DF,		0x06},
{0x2E0,		0x12},
{0x2E1,		0x41},
{0x2E2,		0x51},
{0x2E3,		0x07},
{0x2E4,		0x61},
{0x2E5,		0x71},
{0x2E6,		0x13},
{0x2E7,		0x22},
{0x2E8,		0x32},
{0x2E9,		0x81},
{0x2EA,		0x08},
{0x2EB,		0x14},
{0x2EC,		0x42},
{0x2ED,		0x91},
{0x2EE,		0xA1},
{0x2EF,		0xB1},
{0x2F0,		0xC1},
{0x2F1,		0x09},
{0x2F2,		0x23},
{0x2F3,		0x33},
{0x2F4,		0x52},
{0x2F5,		0xF0},
{0x2F6,		0x15},
{0x2F7,		0x62},
{0x2F8,		0x72},
{0x2F9,		0xD1},
{0x2FA,		0x0A},
{0x2FB,		0x16},
{0x2FC,		0x24},
{0x2FD,		0x34},
{0x2FE,		0xE1},
{0x2FF,		0x25},
{0x300,		0xF1},
{0x301,		0x17},
{0x302,		0x18},
{0x303,		0x19},
{0x304,		0x1A},
{0x305,		0x26},
{0x306,		0x27},
{0x307,		0x28},
{0x308,		0x29},
{0x309,		0x2A},
{0x30A,		0x35},
{0x30B,		0x36},
{0x30C,		0x37},
{0x30D,		0x38},
{0x30E,		0x39},
{0x30F,		0x3A},
{0x310,		0x43},
{0x311,		0x44},
{0x312,		0x45},
{0x313,		0x46},
{0x314,		0x47},
{0x315,		0x48},
{0x316,		0x49},
{0x317,		0x4A},
{0x318,		0x53},
{0x319,		0x54},
{0x31A,		0x55},
{0x31B,		0x56},
{0x31C,		0x57},
{0x31D,		0x58},
{0x31E,		0x59},
{0x31F,		0x5A},
{0x320,		0x63},
{0x321,		0x64},
{0x322,		0x65},
{0x323,		0x66},
{0x324,		0x67},
{0x325,		0x68},
{0x326,		0x69},
{0x327,		0x6A},
{0x328,		0x73},
{0x329,		0x74},
{0x32A,		0x75},
{0x32B,		0x76},
{0x32C,		0x77},
{0x32D,		0x78},
{0x32E,		0x79},
{0x32F,		0x7A},
{0x330,		0x82},
{0x331,		0x83},
{0x332,		0x84},
{0x333,		0x85},
{0x334,		0x86},
{0x335,		0x87},
{0x336,		0x88},
{0x337,		0x89},
{0x338,		0x8A},
{0x339,		0x92},
{0x33A,		0x93},
{0x33B,		0x94},
{0x33C,		0x95},
{0x33D,		0x96},
{0x33E,		0x97},
{0x33F,		0x98},
{0x340,		0x99},
{0x341,		0x9A},
{0x342,		0xA2},
{0x343,		0xA3},
{0x344,		0xA4},
{0x345,		0xA5},
{0x346,		0xA6},
{0x347,		0xA7},
{0x348,		0xA8},
{0x349,		0xA9},
{0x34A,		0xAA},
{0x34B,		0xB2},
{0x34C,		0xB3},
{0x34D,		0xB4},
{0x34E,		0xB5},
{0x34F,		0xB6},
{0x350,		0xB7},
{0x351,		0xB8},
{0x352,		0xB9},
{0x353,		0xBA},
{0x354,		0xC2},
{0x355,		0xC3},
{0x356,		0xC4},
{0x357,		0xC5},
{0x358,		0xC6},
{0x359,		0xC7},
{0x35A,		0xC8},
{0x35B,		0xC9},
{0x35C,		0xCA},
{0x35D,		0xD2},
{0x35E,		0xD3},
{0x35F,		0xD4},
{0x360,		0xD5},
{0x361,		0xD6},
{0x362,		0xD7},
{0x363,		0xD8},
{0x364,		0xD9},
{0x365,		0xDA},
{0x366,		0xE2},
{0x367,		0xE3},
{0x368,		0xE4},
{0x369,		0xE5},
{0x36A,		0xE6},
{0x36B,		0xE7},
{0x36C,		0xE8},
{0x36D,		0xE9},
{0x36E,		0xEA},
{0x36F,		0xF2},
{0x370,		0xF3},
{0x371,		0xF4},
{0x372,		0xF5},
{0x373,		0xF6},
{0x374,		0xF7},
{0x375,		0xF8},
{0x376,		0xF9},
{0x377,		0xFA},
{-1, -1}  /* Terminator */
};

int
main()
{
  FILE *zhfp, *zlfp, *zdfp;  // ZADRHI, ZADRLO, ZDATA
  int c1 = 0;
  int fc = 0;

  zhfp = fopen("zadrhi.dat", "w");
  zlfp = fopen("zadrlo.dat", "w");
  zdfp = fopen("zdata.dat", "w");

  fprintf(zhfp, "# SET_ADDRESS = 0;\n");
  fprintf(zlfp, "# SET_ADDRESS = 0;\n");
  fprintf(zdfp, "# SET_ADDRESS = 0;\n");

  while (jpegRegs[c1].address != -1)
    {
      fprintf(zhfp, "%.2x ", ((jpegRegs[c1].address & 0x300) >> 8));
      fprintf(zlfp, "%.2x ", (jpegRegs[c1].address & 0xFF));
      fprintf(zdfp, "%.2x ", jpegRegs[c1].data);
      c1++;
      fc++;
      if (fc == 8)
	{
	  fprintf(zhfp, "\n");
	  fprintf(zlfp, "\n");
	  fprintf(zdfp, "\n");
	  fc = 0;
	}
      
    }
  
  fclose(zhfp);
  fclose(zlfp);
  fclose(zdfp);
}