/* take string cmd_line, parse the line and call the alu function corresponding to alu-opcodes.h */ void alu_parse_line(char *cmd_line) { char opcode[100]; char operand1[100]; char operand2[100]; int nargs = 0; nargs = sscanf(cmd_line, "%s %s %s", opcode, operand1, operand2); switch (nargs) { case 3: ldhex2register(operand1, rega); ldhex2register(operand2, regb); if (!strcmp(opcode, "add")) alu(ALU_OP_ADD, rega, regb, accumulator, flags); if (!strcmp(opcode, "sub")) alu(ALU_OP_SUB, rega, regb, accumulator, flags); if (!strcmp(opcode, "and")) alu(ALU_OP_AND, rega, regb, accumulator, flags); if (!strcmp(opcode, "or")) alu(ALU_OP_OR, rega, regb, accumulator, flags); if (!strcmp(opcode, "xor")) alu(ALU_OP_XOR, rega, regb, accumulator, flags); printf("%s %s %s\n", opcode, operand1, operand2); break; case 2: ldhex2register(operand1, rega); if (!strcmp(opcode, "neg_a")) alu(ALU_OP_NEG_A, rega, regb, accumulator, flags); if (!strcmp(opcode, "neg_b")) alu(ALU_OP_NEG_B, rega, rega, accumulator, flags); if (!strcmp(opcode, "not_a")) alu(ALU_OP_NOT_A, rega, regb, accumulator, flags); if (!strcmp(opcode, "not_b")) alu(ALU_OP_NOT_B, rega, rega, accumulator, flags); printf("%s %s\n", opcode, operand1); break; case 1: if (!strcmp(opcode, "reset")) { alu_main_reset(rega, regb, accumulator, flags); printf("%s %s\n", opcode, operand1); break; } break; } }
/* file format: <name> <hex-value> */ void cpu_6502_register_dump(char* fname){ char register_name_buffer[9]; char hex_buffer[9]; FILE *stream; hex_buffer[9] = '\0'; register_name_buffer[9] = '\0'; if(!strcmp("-", fname)){ stream = stdin; } else if ((stream = fopen( fname,"r")) == NULL){ printf("Can't open %s\n", fname); exit(1); } while(!feof(stream)){ //format string is: <any space, including 0><three chars><any space, including 0><value> fscanf(stream, " %3c %4c ", register_name_buffer, hex_buffer); // todo: check for interity // printf("Illegal value %i\nSkipping line ..\n", adr); ldhex2register(hex_buffer, parse_6502_register_name(register_name_buffer)); } }