Source

prom / prom.c

Diff from to
 #include "usb_serial.h"
 #include "xmodem.h"
 #include "bits.h"
+#include "chips.h"
 
 void send_str(const char *s);
 uint8_t recv_str(char *buf, uint8_t size);
 	[40]	= 0xB7,
 };
 
-#define OPTIONS_PULLUPS 0x01
-#define OPTIONS_LATCH   0x02
-
-typedef struct
-{
-	/** Name of the chip type */
-	char name[16];
-
-	/** Options for chip, including pullup */
-	uint8_t options;
-
-	/** Total number of pins on the chip */
-	uint8_t pins;
-
-	/** Total number of address pins.
-	 * The download will retrieve 2^addr_width bytes.
- 	 */
-	uint8_t addr_width;
-
-	/** Total number of data pins.
-	 * If data_pins == 0, the chip is assumed to be in AVR ISP mode.
-	 */
-	uint8_t data_width;
-
-	/** Address pins.
-	 * An array of up to 24 pins in package numbering.
-	 * Any that are 0 will be ignored.  Other than ISP mode chips,
-	 * there should be addr_width pins defined here.
-	 * These will be configured as outputs from the reader
-	 * and initially driven low.
-	 */
-	uint8_t addr_pins[24];
-
-	/** Data pins.
-	 * An array of up to 24 pins in package numbering.
-	 * Any that are 0 will be ignored.  Other than ISP mode chips,
-	 * there should be data_width pins defined here.
-	 * These will be configured as inputs from the reader,
-	 * with no pull ups.
-	 */
-	uint8_t data_pins[24];
-
-	/** Pins to be driven high at all times.
-	 * These will be configured as outputs and drive hi.
-	 * Typical power limits are sourcing 50 mA per pin.
-	 */
-	uint8_t hi_pins[8];
-
-	/** Pins to be driven low at all times.
-	 * These will be configured as outputs and driven low.
-	 * Typical power limits are sinking 50 mA per pin.
-	 */
-	uint8_t lo_pins[8];
-} prom_t;
-
-#define LATCH_PIN 0
-
-static const prom_t proms[] = {
-{
-	// Default is to leave everything in tristate mode
-	.name		= "NONE",
-	.pins		= 28,
-
-	.addr_width	= 0,
-	.addr_pins	= {
-	},
-
-	.data_width	= 0,
-	.data_pins	= {
-	},
-
-	.hi_pins	= { },
-	.lo_pins	= { },
-},
-{
-	.name		= "M27C512",
-	.pins		= 28,
-
-	.addr_width	= 16,
-	.addr_pins	= {
-		10, 9, 8, 7, 6, 5, 4, 3, 25, 24, 21, 23, 2, 26, 27, 1,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		11, 12, 13, 15, 16, 17, 18, 19,
-	},
-
-	.hi_pins	= { 28, },
-	.lo_pins	= { 22, 20, 14, },
-},
-{
-	.name		= "M27C256",
-	.pins		= 28,
-	.addr_width	= 15,
-	.addr_pins	= {
-		10, 9, 8, 7, 6, 5, 4, 3, 25, 24, 21, 23, 2, 26, 27,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		11, 12, 13, 15, 16, 17, 18, 19,
-	},
-	.hi_pins	= { 28, 1 },
-	.lo_pins	= { 22, 20, 14, },
-},
-{
-	.name		= "M27C128",
-	.pins		= 28,
-	.addr_width	= 14,
-	.addr_pins	= {
-		10, 9, 8, 7, 6, 5, 4, 3, 25, 24, 21, 23, 2, 26,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		11, 12, 13, 15, 16, 17, 18, 19,
-	},
-	.hi_pins	= { 28, 1, 27, },
-	.lo_pins	= { 22, 20, 14, },
-},
-{
-	.name		= "LH-535618",
-    .options 	= OPTIONS_PULLUPS | OPTIONS_LATCH,
-	.pins		= 28,
-	.addr_width	= 15,
-	.addr_pins	= {
-    10, 9, 8, 7, 6, 5, 4, 3, 26, 25, 2, 20, 24, 22, 28,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		11, 12, 13, 15, 16, 17, 18, 19,
-	},
-	.hi_pins	= { 1, },
-	.lo_pins	= { 
-    [LATCH_PIN] = 23,
-    21, 27, 14, },
-},
-{
-	.name		= "M27C64",
-	.pins		= 28,
-	.addr_width	= 13,
-	.addr_pins	= {
-		10, 9, 8, 7, 6, 5, 4, 3, 25, 24, 21, 23, 2,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		11, 12, 13, 15, 16, 17, 18, 19,
-	},
-	.hi_pins	= { 28, 1, 27 },
-	.lo_pins	= { 22, 20, 14, },
-},
-{
-	.name		= "87C64",
-	.options 	= OPTIONS_PULLUPS | OPTIONS_LATCH,
-	.pins		= 28,
-	.addr_width	= 13,
-	.addr_pins	= {
-		10, 9, 8, 7, 6, 5, 4, 3, 25, 24, 21, 23, 2,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		11, 12, 13, 15, 16, 17, 18, 19,
-	},
-	.hi_pins	= { 28, 1, 27 },
-	.lo_pins	= { 
-		[LATCH_PIN] = 20,
-		22, 14, 
-	},
-},
-{
-	.name		= "C64-2732",
-	.pins		= 24,
-	.addr_width	= 12,
-	.addr_pins	= {
-		8, 7, 6, 5, 4, 3, 2, 1, 23, 22, 19, 18,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		9, 10, 11, 13, 14, 15, 16, 17,
-	},
-	.hi_pins	= { 24, 21 },
-	.lo_pins	= { 12, 20, },
-},
-{
-	/** 512x8 PROM -- UNTESTED */	
-	.name		= "TBP28S42",
-	.pins		= 20,
-	.addr_width	= 9,
-	.addr_pins	= {
-		1, 2, 3, 4, 5, 16, 17, 18, 19,
-	},
-	.data_width	= 8,
-	.data_pins	= {
-		6, 7, 8, 9, 11, 12, 13, 14,
-	},
-	.hi_pins	= { 20 },
-	.lo_pins	= { 10, 15 },
-},
-
-{
-	/** 8192x8 UV EEPROM, found in DX synth */
-	.name		= "MBM2764-30",
-	.pins		= 28,
-	.addr_width	= 13,
-	.addr_pins	= {
-		10, 9, 8, 7, 6, 5, 4, 3, 25, 24, 21, 23, 2,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		11, 12, 13, 15, 16, 17, 18, 19,
-	},
-	.hi_pins	= {
-		//28, // vdd, disabled since external power must be used
-		27, // pgm
-		1,  // vpp
-	},
-	.lo_pins	= { 22, 20, 14, }, // !oe, !cs, gnd
-},
-{
-	// C64 kernel and basic ROMs
-	.name		= "27C210",
-	.pins		= 40,
-	.addr_width	= 16,
-	.addr_pins	= {
-    21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37,
-	},
-	.data_width	= 16,
-	.data_pins	= {
-    19, 18, 17, 16, 15, 14, 13, 12, 10,  9,  8,  7,  6,  5,  4,  3,
-	},
-	.hi_pins	= {
-    40, // VCC
-    1,  // VPP
-    39, // PGM'
-	},
-	.lo_pins	= {
-    2, // E'
-    11, 30, // GND
-    20, // G'
-	},
-},
-{
-	/** Apple Mac SE PROM chips
-	 * Similar to a M27C512, but with the 17th address line
-	 * on 22 instead of Vpp, allowing 128 KB of data.
-	 */
-	.name		= "APPLE PROM",
-	.pins		= 28,
-	.addr_width	= 17,
-	.addr_pins	= {
-		10, 9, 8, 7, 6, 5, 4, 3, 25, 24, 21, 23, 2, 26, 27, 1, 22
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		11, 12, 13, 15, 16, 17, 18, 19,
-	},
-	.hi_pins	= { 28, },
-	.lo_pins	= { 20, 14, },
-},
-{
-	.name		= "28F512 (untstd)",
-	.pins		= 32,
-	.addr_width	= 16,
-	.addr_pins	= {
-		12, 11, 10, 9, 8, 7, 6, 5, 27, 26, 23, 25, 4, 28, 29, 15
-	},
-	.data_width	= 8,
-	.data_pins	= {
-		13, 14, 15, 17, 18, 19, 20, 21,
-	},
-	.hi_pins	= {
-		32, // vcc
-		31, // !we
-		1, // Vpp
-	},
-	.lo_pins	= {
-		16, // gnd
-		24, // !oe
-		22, // !ce
-	},
-},
-{
-	// C64 kernel and basic ROMs
-	.name		= "2364A",
-	.pins		= 24,
-	.addr_width	= 13,
-	.addr_pins	= {
-		8, 7, 6, 5, 4, 3, 2, 1, 23, 22, 19, 18, 21,
-	},
-	.data_width	= 8,
-	.data_pins	= {
-		9, 10, 11, 13, 14, 15, 16, 17,
-	},
-	.hi_pins	= {
-		24,
-	},
-	.lo_pins	= {
-		12, // gnd
-		20, // !cs
-	},
-},
-{
-	/** 2716 mask ROM used in video games.
-	 * \note: Not tested yet.
-	 */
-	.name		= "2716 (untested)",
-	.pins		= 24,
-	.addr_width	= 11,
-	.addr_pins	= {
-		8, 7, 6, 5, 4, 3, 2, 1, 23, 22, 19,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		9, 10, 11, 13, 14, 15, 16, 17
-	},
-
-	.hi_pins	= { 24, 21, },
-	.lo_pins	= { 12, 20, 18 },
-},
-{
-	/** 9316 mask ROM used in video games.
-	 * \note: Not tested yet.
-	 */
-	.name		= "9316 (untested)",
-	.pins		= 24,
-	.addr_width	= 11,
-	.addr_pins	= {
-		8, 7, 6, 5, 4, 3, 2, 1, 23, 22, 19,
-	},
-
-	.data_width	= 8,
-	.data_pins	= {
-		9, 10, 11, 13, 14, 15, 16, 17
-	},
-
-	.hi_pins	= { 24, 18, },
-	.lo_pins	= { 12, 21, 20 },
-},
-{
-	.name		= "HN462732",
-	.pins		= 24,
-	.addr_width	= 12,
-	.addr_pins	= {
-		8, 7, 6, 5, 4, 3, 2, 1, 23, 22, 19, 21,
-	},
-	.data_width	= 8,
-	.data_pins	= {
-		9, 10, 11, 13, 14, 15, 16, 17,
-	},
-	.hi_pins	= {
-		24, // vcc
-	},
-	.lo_pins	= {
-		12, // gnd
-		20, // !oe
-		18, // !ce
-	},
-},
-{
-	/** atmega8.
-	 * Not an EEPROM, but a chip to read via ISP.
-	 * data_width / addr_width == 0 to indicate that this is not eeprom
-	 */
-#define ISP_MOSI 0
-#define ISP_MISO 0
-#define ISP_SCK 1
-#define ISP_RESET 2
-#define ISP_XTAL 3
-	.name		= "ATMega8",
-	.pins		= 28,
-	.addr_width	= 13,
-	.addr_pins	= {
-		[ISP_MOSI] = 17, // from the reader to the chip
-		[ISP_SCK] = 19, // SCK,
-		[ISP_RESET] = 1, // reset
-		[ISP_XTAL] = 9, // xtal
-	},
-	.data_pins	= {
-		[ISP_MISO] = 18, // from the chip back to the reader
-	},
-	.lo_pins	= {
-		8, // gnd
-		22, // gnd
-	},
-	.hi_pins	= {
-		7, // vcc
-		20, // avcc
-	},
-},
-};
-
 /** Select one of the chips */
 static const prom_t * prom = &proms[0];
 
 prom_list(void)
 {
 	send_str(PSTR("\r\n"));
-	for (int i = 0 ; i < array_count(proms) ; i++)
+	for (int i = 0 ; i < proms_count ; i++)
 	{
 		const prom_t * const p = &proms[i];
 		prom_list_send(i, p, p == prom );
 	}
 
 	uint8_t mode = c - '0';
-	if (mode >= array_count(proms))
+	if (mode >= proms_count)
 	{
 		send_str(PSTR("?\r\n"));
 		return;