// SDB-CGEN V2.6.2
#include <ctype.h>
#include <stdio.h>
#include <string.h>

struct kv { const char *name; const char *value; };
static const struct kv kvs[] = {
// gcc -DMAIN=1 cosmac.c ; ./a.out > cosmac.h
	{"adc", "Add with carry"},
	{"adci", "Add with carry immediate"},
	{"add", "Add D: D,DF= D+(R(X))"},
	{"adi", "Add D,DF with value"},
	{"and", "Logical AND: D with (R(X))"},
	{"ani", "Logical AND D with value"},
	{"b1", "Short branch on EF1=1"},
	{"b2", "Short branch on EF2=1"},
	{"b3", "Short branch on EF3=1"},
	{"b4", "Short branch on EF4=1"},
	{"bci", "short branch on counter interrupt"},
	{"bdf", "Short branch on DF=1"},
	{"bn1", "Short branch on EF1=0"},
	{"bn2", "Short branch on EF2=0"},
	{"bn3", "Short branch on EF3=0"},
	{"bn4", "Short branch on EF4=0"},
	{"bnf", "Short branch on DF=0"},
	{"bnq", "Short branch on Q=0"},
	{"bnz", "Short branch on D!=0"},
	{"bq", "Short branch on Q=1"},
	{"br", "Short branch"},
	{"bxi", "short branch on external interrupt"},
	{"bz", "Short branch on D=0"},
	{"cid", "counter interrupt disable"},
	{"cie", "counter interrupt enable"},
	{"daci", "decimal add with carry immediate"},
	{"dadc", "decimal add with carry"},
	{"dadd", "decimal add"},
	{"dadi", "decimal add immediate"},
	{"dbnz", "decrement R and long branch if not 0"},
	{"dec", "Decrement (R)"},
	{"dis", "Disable. Return from interrupt, set IE=0"},
	{"doublefetch", "Opcode for double fetched instructions"},
	{"dsav", "save T,D,DF"},
	{"dsbi", "decimal subtract memory with borrow, immediate"},
	{"dsm", "decimal subtract memory"},
	{"dsmb", "decimal subtract memory with borrow"},
	{"dsmi", "decimal subtract memory, immediate"},
	{"dtc", "decrement timer/counter"},
	{"etq", "enable toggle Q"},
	{"gec", "get counter"},
	{"ghi", "Get high register R"},
	{"glo", "Get low register R"},
	{"idl", "Idle or wait for interrupt or DMA request"},
	{"inc", "Increment (R)"},
	{"inp", "Input to (R(X)) and D, N="},
	{"invalid", "INVALID INSTRUCTION"},
	{"irx", "Increment register X"},
	{"lbdf", "Long branch on DF=1"},
	{"lbnf", "Long branch on DF=0"},
	{"lbnq", "Long branch on Q=0"},
	{"lbnz", "Long branch on D!=0"},
	{"lbq", "Long branch on Q=1"},
	{"lbr", "Long branch"},
	{"lbz", "Long branch on D=0"},
	{"lda", "Load D from (R), increment R"},
	{"ldc", "load counter"},
	{"ldi", "Load D immediate"},
	{"ldn", "Load D with (R)"},
	{"ldx", "Pop stack. Place value in D register"},
	{"ldxa", "Load via X and advance"},
	{"lsdf", "Long skip on DF=1"},
	{"lsie", "Long skip on IE=1"},
	{"lskp", "Long skip"},
	{"lsnf", "Long skip on DF=0"},
	{"lsnq", "Long skip on Q=0"},
	{"lsnz", "Long skip on D!=0"},
	{"lsq", "Long skip on Q=1"},
	{"lsz", "Long skip on D=0"},
	{"mark", "Push X,P; mark subroutine call"},
	{"nop", "No operation"},
	{"or", "Logical OR D with (R(X))"},
	{"ori", "Logical OR D with value"},
	{"out", "Output (R(X)); Increment R(X), N="},
	{"phi", "Put high register R"},
	{"plo", "Put low register R"},
	{"req", "Reset Q=0"},
	{"ret", "Return from interrupt, set IE=1"},
	{"rldi", "register load immediate R"},
	{"rlxa", "load memory to R"},
	{"rnx", "copy register R to R(X)"},
	{"rsxd", "store register R in memory"},
	{"sav", "Save"},
	{"scal", "standard call to (R)"},
	{"scm1", "set counter mode 1 and start"},
	{"scm2", "set counter mode 2 and start"},
	{"sd", "Subtract D: D,DF=(R(X))-D"},
	{"sdb", "Subtract D with borrow"},
	{"sdbi", "Subtract D with borrow immediate"},
	{"sdi", "Subtract D,DF from value"},
	{"sep", "Set P=R as program counter"},
	{"seq", "Set Q=1"},
	{"sex", "Set P=R as datapointer"},
	{"shl", "Shift left D"},
	{"shlc", "Shift left with carry"},
	{"shr", "Shift right D"},
	{"shrc", "Shift right with carry"},
	{"skp", "Skip next byte"},
	{"sm", "Subtract memory: DF,D=D-(R(X))"},
	{"smb", "Subtract memory with borrow"},
	{"smbi", "Subtract memory with borrow, immediate"},
	{"smi", "Subtract D,DF to value"},
	{"spm1", "set pulse width mode 1 and start"},
	{"spm2", "set pulse width mode 2 and start"},
	{"sret", "standard return to (R)"},
	{"stm", "set timer mode and start"},
	{"stpc", "stop counter"},
	{"str", "Store D to (R)"},
	{"stxd", "Store via X and decrement"},
	{"xid", "external interrupt disable"},
	{"xie", "external interrupt enable"},
	{"xor", "Logical exclusive OR D with (R(X))"},
	{"xri", "Logical XOR D with value"},
  {NULL, NULL}
};
typedef int (*GperfForeachCallback)(void *user, const char *k, const char *v);
int gperf_cosmac_foreach(GperfForeachCallback cb, void *user) {
  int i = 0; while (kvs[i].name) {
  cb (user, kvs[i].name, kvs[i].value);
  i++;}
  return 0;
}
const char *gperf_cosmac_get(const char *s) {
  int i = 0; while (kvs[i].name) {
  if (!strcmp (s, kvs[i].name)) return kvs[i].value;
  i++;}
  return NULL;
}
#define sdb_hash_c_cosmac(x,y) gperf_cosmac_hash(x)
const unsigned int gperf_cosmac_hash(const char *s) {
  int sum = strlen (s);
  while (*s) { sum += *s; s++; }
  return sum;
}
struct {const char *name;void *get;void *hash;void *foreach;} gperf_cosmac = {
  .name = "cosmac",
  .get = &gperf_cosmac_get,
  .hash = &gperf_cosmac_hash,
  .foreach = &gperf_cosmac_foreach
};

#if MAIN
int main () {
	const char *s = ((char*(*)(char*))gperf_cosmac.get)("foo");
	printf ("%s\n", s);
}
#endif
