/* Process line from color file. May modify the data pointed to by the buffer paremeter */ static int process_color(char *buffer, int line) { char rule[10], pat[256], f[256], b[256]; uint32_t i, fg, bg; int ret; while(isspace(*buffer)) buffer++; if(buffer[0] == '#' || buffer[0] == '\0') return 0; ret = sscanf(buffer, "%8s %255s = %255s %255s", rule, pat, f, b); if (ret == 4) { if (find_mnemonic(f, &fg) == 0 && find_mnemonic(b, &bg) == 0) for (i = 0; i < N_COLOR; i++) if (!strcmp(rule, rules[i])) return add_secolor(i, pat, fg, bg); } else if (ret == 3) { if (!strcmp(rule, AUX_RULE_COLOR)) { if (sscanf(f, "#%x", &fg) == 1) return add_mnemonic(pat, fg); } } syslog(LOG_WARNING, "Line %d of secolors file is invalid.", line); return 0; }
static void assemble(void) { bool done = false; char c1, c2, c3; char mnem, mode; uint8 opcode; uint16 arg; int16 rel; // Read parameters if (!address_args()) return; do { fprintf(fout, "%04lx> ", address); fflush(ferr); read_line(); c1 = get_char(); c2 = get_char(); c3 = get_char(); if (c1 != '\n') { if ((mnem = find_mnemonic(c1, c2, c3)) != M_ILLEGAL) { get_token(); if (instr_args(&arg, &mode)) { // Convert A_IMPL -> A_ACCU if necessary if ((mode == A_IMPL) && find_opcode(mnem, A_ACCU, &opcode)) mode = A_ACCU; // Handle relative addressing seperately if (((mode == A_ABS) || (mode == A_ZERO)) && find_opcode(mnem, A_REL, &opcode)) { mode = A_REL; rel = arg - (address + 2) & 0xffff; if ((rel < -128) || (rel > 127)) { error("Branch too long"); continue; } else arg = rel & 0xff; } if (find_opcode(mnem, mode, &opcode)) { // Print disassembled line fprintf(fout, "\v%04lx:", address); disass_line(address, opcode, arg & 0xff, arg >> 8); switch (adr_length[mode]) { case 1: SAMWriteByte(address++, opcode); break; case 2: SAMWriteByte(address++, opcode); SAMWriteByte(address++, arg); break; case 3: SAMWriteByte(address++, opcode); SAMWriteByte(address++, arg & 0xff); SAMWriteByte(address++, arg >> 8); break; default: error("Internal error"); break; } } else error("Addressing mode not supported by instruction"); } else error("Unrecognized addressing mode"); } else