Skip to content

Instantly share code, notes, and snippets.

@ssilva ssilva/disassembler.c
Last active Jul 17, 2018

Embed
What would you like to do?
8080 emulation
#include <stdlib.h>
#include <stdio.h>
// Started from http://emulator101.com/
int disassemble_op(unsigned char *codebuffer, int pc)
{
unsigned char *code = &codebuffer[pc];
int opbytes = 1;
printf ("%04x ", pc);
switch(*code) {
case 0x00: printf("NOP"); break;
case 0x01: printf("LXI B,#$%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0x02: printf("STAX B"); break;
case 0x03: printf("INX B"); break;
case 0x04: printf("INR B"); break;
case 0x05: printf("DCR B"); break;
case 0x06: printf("MVI B,#$%02x", code[1]); opbytes=2; break;
case 0x07: printf("RLC"); break;
case 0x08: printf("NOP"); break;
case 0x09: printf("DAB B"); break;
case 0x0a: printf("LDAX B"); break;
case 0x0b: printf("DCX B"); break;
case 0x0c: printf("INR C"); break;
case 0x0d: printf("DCR C"); break;
case 0x0e: printf("MVI C,#$%02x", code[1]); opbytes=2; break;
case 0x0f: printf("RRC"); break;
case 0x10: printf("NOP"); break;
case 0x11: printf("LXI D,#$%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0x12: printf("STAX D"); break;
case 0x13: printf("INX D"); break;
case 0x14: printf("INR D"); break;
case 0x15: printf("DCR D"); break;
case 0x16: printf("MVI D,#$%02x", code[1]); opbytes=2; break;
case 0x17: printf("RAL"); break;
case 0x18: printf("NOP"); break;
case 0x19: printf("DAD D"); break;
case 0x1a: printf("LDAX D"); break;
case 0x1b: printf("DCX D"); break;
case 0x1c: printf("INR E"); break;
case 0x1d: printf("DCR E"); break;
case 0x1e: printf("MVI E,#$%02x", code[1]); opbytes=2; break;
case 0x1f: printf("RAR"); break;
case 0x20: printf("NOP"); break;
case 0x21: printf("LXI H,#$%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0x22: printf("SHLD $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0x23: printf("INX H"); break;
case 0x24: printf("INR H"); break;
case 0x25: printf("DCR H"); break;
case 0x26: printf("MVI H,#$%02x", code[1]); opbytes=2; break;
case 0x27: printf("DAA"); break;
case 0x28: printf("NOP"); break;
case 0x29: printf("DAD H"); break;
case 0x2a: printf("LHLD $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0x2b: printf("DCX H"); break;
case 0x2c: printf("INR L"); break;
case 0x2d: printf("DCR L"); break;
case 0x2e: printf("MVI L,#$%02x", code[1]); opbytes=2; break;
case 0x2f: printf("CMA"); break;
case 0x30: printf("NOP"); break;
case 0x31: printf("LXI SP,#$%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0x32: printf("STA $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0x33: printf("INX SP"); break;
case 0x34: printf("INR M"); break;
case 0x35: printf("DCR M"); break;
case 0x36: printf("MVI M,#$%02x", code[1]); opbytes = 2; break;
case 0x37: printf("STC"); break;
case 0x38: printf("NOP"); break;
case 0x39: printf("DAD SP"); break;
case 0x3a: printf("LDA $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0x3b: printf("DCX SP"); break;
case 0x3c: printf("INR A"); break;
case 0x3d: printf("DCR A"); break;
case 0x3e: printf("MVI A,#$%02x", code[1]); opbytes = 2; break;
case 0x3f: printf("CMC"); break;
case 0x40: printf("MOV B,B"); break;
case 0x41: printf("MOV B,C"); break;
case 0x42: printf("MOV B,D"); break;
case 0x43: printf("MOV B,E"); break;
case 0x44: printf("MOV B,H"); break;
case 0x45: printf("MOV B,L"); break;
case 0x46: printf("MOV B,M"); break;
case 0x47: printf("MOV B,A"); break;
case 0x48: printf("MOV C,B"); break;
case 0x49: printf("MOV C,C"); break;
case 0x4a: printf("MOV C,D"); break;
case 0x4b: printf("MOV C,E"); break;
case 0x4c: printf("MOV C,H"); break;
case 0x4d: printf("MOV C,L"); break;
case 0x4e: printf("MOV C,M"); break;
case 0x4f: printf("MOV C,A"); break;
case 0x50: printf("MOV D,B"); break;
case 0x51: printf("MOV D,C"); break;
case 0x52: printf("MOV D,D"); break;
case 0x53: printf("MOV D,E"); break;
case 0x54: printf("MOV D,H"); break;
case 0x55: printf("MOV D,L"); break;
case 0x56: printf("MOV D,M"); break;
case 0x57: printf("MOV D,A"); break;
case 0x58: printf("MOV E,B"); break;
case 0x59: printf("MOV E,C"); break;
case 0x5a: printf("MOV E,D"); break;
case 0x5b: printf("MOV E,E"); break;
case 0x5c: printf("MOV E,H"); break;
case 0x5d: printf("MOV E,L"); break;
case 0x5e: printf("MOV E,M"); break;
case 0x5f: printf("MOV E,A"); break;
case 0x60: printf("MOV H,B"); break;
case 0x61: printf("MOV H,C"); break;
case 0x62: printf("MOV H,D"); break;
case 0x63: printf("MOV H,E"); break;
case 0x64: printf("MOV H,H"); break;
case 0x65: printf("MOV H,L"); break;
case 0x66: printf("MOV H,M"); break;
case 0x67: printf("MOV H,A"); break;
case 0x68: printf("MOV L,B"); break;
case 0x69: printf("MOV L,C"); break;
case 0x6a: printf("MOV L,D"); break;
case 0x6b: printf("MOV L,E"); break;
case 0x6c: printf("MOV L,H"); break;
case 0x6d: printf("MOV L,L"); break;
case 0x6e: printf("MOV L,M"); break;
case 0x6f: printf("MOV L,A"); break;
case 0x70: printf("MOV M,B"); break;
case 0x71: printf("MOV M,C"); break;
case 0x72: printf("MOV M,D"); break;
case 0x73: printf("MOV M,E"); break;
case 0x74: printf("MOV M,H"); break;
case 0x75: printf("MOV M,L"); break;
case 0x76: printf("HLT"); break;
case 0x77: printf("MOV M,A"); break;
case 0x78: printf("MOV A,B"); break;
case 0x79: printf("MOV A,C"); break;
case 0x7a: printf("MOV A,D"); break;
case 0x7b: printf("MOV A,E"); break;
case 0x7c: printf("MOV A,H"); break;
case 0x7d: printf("MOV A,L"); break;
case 0x7e: printf("MOV A,M"); break;
case 0x7f: printf("MOV A,A"); break;
case 0x80: printf("ADD B"); break;
case 0x81: printf("ADD C"); break;
case 0x82: printf("ADD D"); break;
case 0x83: printf("ADD E"); break;
case 0x84: printf("ADD H"); break;
case 0x85: printf("ADD L"); break;
case 0x86: printf("ADD M"); break;
case 0x87: printf("ADD A"); break;
case 0x88: printf("ADC B"); break;
case 0x89: printf("ADC C"); break;
case 0x8a: printf("ADC D"); break;
case 0x8b: printf("ADC E"); break;
case 0x8c: printf("ADC H"); break;
case 0x8d: printf("ADC L"); break;
case 0x8e: printf("ADC M"); break;
case 0x8f: printf("ADC A"); break;
case 0x90: printf("SUB B"); break;
case 0x91: printf("SUB C"); break;
case 0x92: printf("SUB D"); break;
case 0x93: printf("SUB E"); break;
case 0x94: printf("SUB H"); break;
case 0x95: printf("SUB L"); break;
case 0x96: printf("SUB M"); break;
case 0x97: printf("SUB A"); break;
case 0x98: printf("SBB B"); break;
case 0x99: printf("SBB C"); break;
case 0x9a: printf("SBB D"); break;
case 0x9b: printf("SBB E"); break;
case 0x9c: printf("SBB H"); break;
case 0x9d: printf("SBB L"); break;
case 0x9e: printf("SBB M"); break;
case 0x9f: printf("SBB A"); break;
case 0xa0: printf("ANA B"); break;
case 0xa1: printf("ANA C"); break;
case 0xa2: printf("ANA D"); break;
case 0xa3: printf("ANA E"); break;
case 0xa4: printf("ANA H"); break;
case 0xa5: printf("ANA L"); break;
case 0xa6: printf("ANA M"); break;
case 0xa7: printf("ANA A"); break;
case 0xa8: printf("XRA B"); break;
case 0xa9: printf("XRA C"); break;
case 0xaa: printf("XRA D"); break;
case 0xab: printf("XRA E"); break;
case 0xac: printf("XRA H"); break;
case 0xad: printf("XRA L"); break;
case 0xae: printf("XRA M"); break;
case 0xaf: printf("XRA A"); break;
case 0xb0: printf("ORA B"); break;
case 0xb1: printf("ORA C"); break;
case 0xb2: printf("ORA D"); break;
case 0xb3: printf("ORA E"); break;
case 0xb4: printf("ORA H"); break;
case 0xb5: printf("ORA L"); break;
case 0xb6: printf("ORA M"); break;
case 0xb7: printf("ORA A"); break;
case 0xb8: printf("CMP B"); break;
case 0xb9: printf("CMP C"); break;
case 0xba: printf("CMP D"); break;
case 0xbb: printf("CMP E"); break;
case 0xbc: printf("CMP H"); break;
case 0xbd: printf("CMP L"); break;
case 0xbe: printf("CMP M"); break;
case 0xbf: printf("CMP A"); break;
case 0xc0: printf("RNZ"); break;
case 0xc1: printf("POP B"); break;
case 0xc2: printf("JNZ $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xc3: printf("JMP $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xc4: printf("CNZ $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xc5: printf("PUSH B"); break;
case 0xc6: printf("ADI #$%02x", code[1]); opbytes = 2; break;
case 0xc7: printf("RST 0"); break;
case 0xc8: printf("RZ"); break;
case 0xc9: printf("RET"); break;
case 0xca: printf("JZ $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xcb: printf("JMP $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xcc: printf("CZ $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xcd: printf("CALL $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xce: printf("ACI #$%02x", code[1]); opbytes = 2; break;
case 0xcf: printf("RST 1"); break;
case 0xd0: printf("RNC"); break;
case 0xd1: printf("POP D"); break;
case 0xd2: printf("JNC $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xd3: printf("OUT #$%02x", code[1]); opbytes = 2; break;
case 0xd4: printf("CNC $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xd5: printf("PUSH D"); break;
case 0xd6: printf("SUI #$%02x", code[1]); opbytes = 2; break;
case 0xd7: printf("RST 2"); break;
case 0xd8: printf("RC"); break;
case 0xd9: printf("RET"); break;
case 0xda: printf("JC $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xdb: printf("IN #%02x", code[1]); opbytes = 2; break;
case 0xdc: printf("CC $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xdd: printf("CALL $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xde: printf("SBI #$%02x", code[1]); opbytes = 2; break;
case 0xdf: printf("RST 3"); break;
case 0xe0: printf("RPO"); break;
case 0xe1: printf("POP H"); break;
case 0xe2: printf("JPO $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xe3: printf("XTHL"); break;
case 0xe4: printf("CPO $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xe5: printf("PUSH H"); break;
case 0xe6: printf("ANI #$%02x", code[1]); opbytes = 2; break;
case 0xe7: printf("RST 4"); break;
case 0xe8: printf("RPE"); break;
case 0xe9: printf("PCHL"); break;
case 0xea: printf("JPE $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xeb: printf("XCHG"); break;
case 0xec: printf("CPE $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xed: printf("CALL $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xee: printf("XRI #$%02x", code[1]); opbytes = 2; break;
case 0xef: printf("RST 5"); break;
case 0xf0: printf("RP"); break;
case 0xf1: printf("POP PSW"); break;
case 0xf2: printf("JP $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xf3: printf("DI"); break;
case 0xf4: printf("CP $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xf5: printf("PUSH PSW"); break;
case 0xf6: printf("ORI #$%02x", code[1]); opbytes = 2; break;
case 0xf7: printf("RST 6"); break;
case 0xf8: printf("RM"); break;
case 0xf9: printf("SPHL"); break;
case 0xfa: printf("JM $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xfb: printf("EI"); break;
case 0xfc: printf("CM $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xfd: printf("CALL $%02x%02x", code[2], code[1]); opbytes = 3; break;
case 0xfe: printf("CPI #$%02x", code[1]); opbytes = 2; break;
case 0xff: printf("RST 7"); break;
}
printf("\n");
return opbytes;
}
int main(int argc, char **argv)
{
FILE *f = fopen(argv[1], "rb");
if (f == NULL) {
printf("error: Couldn't open %s\n", argv[1]);
exit(1);
}
fseek(f, 0L, SEEK_END);
int fsize = ftell(f);
fseek(f, 0L, SEEK_SET);
unsigned char *buffer = malloc(fsize);
fread(buffer, fsize, 1, f);
fclose(f);
// char buffer[] = {0x01, 0x02, 0x03};
int pc = 0;
while (pc < fsize) {
pc += disassemble_op(buffer, pc);
}
return 0;
}
/*
*
* gcc -o build/emu8080 emu8080.c
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h> // uint8_t
struct Flags {
uint8_t z: 1; // Zero
uint8_t s: 1; // Sign
uint8_t p: 1; // Parity
uint8_t cy: 1; // Carry
uint8_t ac: 1; // Auxiliary carry
uint8_t pad: 3;
};
struct State {
uint8_t a;
uint8_t b;
uint8_t c;
uint8_t d;
uint8_t e;
uint8_t h;
uint8_t l;
uint16_t sp;
uint16_t pc;
uint8_t *memory;
uint8_t int_enable;
struct Flags flags;
};
void unimpl_instruction(struct State *state)
{
printf("Error: Unimplemented instruction 0x%02x\n", state->memory[state->pc]);
exit(1);
}
int emulate_op(struct State *state)
{
unsigned char *instr = &state->memory[state->pc];
switch(instr[0]) {
case 0x00: break; // NOP
case 0x01: state->b = instr[2]; state->c = instr[1]; break; // LXI B,word
case 0x02: unimpl_instruction(state); break;
case 0x03: unimpl_instruction(state); break;
case 0x04: unimpl_instruction(state); break;
case 0x05: unimpl_instruction(state); break;
case 0x06: unimpl_instruction(state); break;
case 0x07: unimpl_instruction(state); break;
case 0x08: unimpl_instruction(state); break;
case 0x09: unimpl_instruction(state); break;
case 0x0a: unimpl_instruction(state); break;
case 0x0b: unimpl_instruction(state); break;
case 0x0c: unimpl_instruction(state); break;
case 0x0d: unimpl_instruction(state); break;
case 0x0e: unimpl_instruction(state); break;
case 0x0f: unimpl_instruction(state); break;
case 0x10: unimpl_instruction(state); break;
case 0x11: unimpl_instruction(state); break;
case 0x12: unimpl_instruction(state); break;
case 0x13: unimpl_instruction(state); break;
case 0x14: unimpl_instruction(state); break;
case 0x15: unimpl_instruction(state); break;
case 0x16: unimpl_instruction(state); break;
case 0x17: unimpl_instruction(state); break;
case 0x18: unimpl_instruction(state); break;
case 0x19: unimpl_instruction(state); break;
case 0x1a: unimpl_instruction(state); break;
case 0x1b: unimpl_instruction(state); break;
case 0x1c: unimpl_instruction(state); break;
case 0x1d: unimpl_instruction(state); break;
case 0x1e: unimpl_instruction(state); break;
case 0x1f: unimpl_instruction(state); break;
case 0x20: unimpl_instruction(state); break;
case 0x21: unimpl_instruction(state); break;
case 0x22: unimpl_instruction(state); break;
case 0x23: unimpl_instruction(state); break;
case 0x24: unimpl_instruction(state); break;
case 0x25: unimpl_instruction(state); break;
case 0x26: unimpl_instruction(state); break;
case 0x27: unimpl_instruction(state); break;
case 0x28: unimpl_instruction(state); break;
case 0x29: unimpl_instruction(state); break;
case 0x2a: unimpl_instruction(state); break;
case 0x2b: unimpl_instruction(state); break;
case 0x2c: unimpl_instruction(state); break;
case 0x2d: unimpl_instruction(state); break;
case 0x2e: unimpl_instruction(state); break;
case 0x2f: unimpl_instruction(state); break;
case 0x30: unimpl_instruction(state); break;
case 0x31: unimpl_instruction(state); break;
case 0x32: unimpl_instruction(state); break;
case 0x33: unimpl_instruction(state); break;
case 0x34: unimpl_instruction(state); break;
case 0x35: unimpl_instruction(state); break;
case 0x36: unimpl_instruction(state); break;
case 0x37: unimpl_instruction(state); break;
case 0x38: unimpl_instruction(state); break;
case 0x39: unimpl_instruction(state); break;
case 0x3a: unimpl_instruction(state); break;
case 0x3b: unimpl_instruction(state); break;
case 0x3c: unimpl_instruction(state); break;
case 0x3d: unimpl_instruction(state); break;
case 0x3e: unimpl_instruction(state); break;
case 0x3f: unimpl_instruction(state); break;
case 0x40: unimpl_instruction(state); break;
case 0x41: unimpl_instruction(state); break;
case 0x42: unimpl_instruction(state); break;
case 0x43: unimpl_instruction(state); break;
case 0x44: unimpl_instruction(state); break;
case 0x45: unimpl_instruction(state); break;
case 0x46: unimpl_instruction(state); break;
case 0x47: unimpl_instruction(state); break;
case 0x48: unimpl_instruction(state); break;
case 0x49: unimpl_instruction(state); break;
case 0x4a: unimpl_instruction(state); break;
case 0x4b: unimpl_instruction(state); break;
case 0x4c: unimpl_instruction(state); break;
case 0x4d: unimpl_instruction(state); break;
case 0x4e: unimpl_instruction(state); break;
case 0x4f: unimpl_instruction(state); break;
case 0x50: unimpl_instruction(state); break;
case 0x51: unimpl_instruction(state); break;
case 0x52: unimpl_instruction(state); break;
case 0x53: unimpl_instruction(state); break;
case 0x54: unimpl_instruction(state); break;
case 0x55: unimpl_instruction(state); break;
case 0x56: unimpl_instruction(state); break;
case 0x57: unimpl_instruction(state); break;
case 0x58: unimpl_instruction(state); break;
case 0x59: unimpl_instruction(state); break;
case 0x5a: unimpl_instruction(state); break;
case 0x5b: unimpl_instruction(state); break;
case 0x5c: unimpl_instruction(state); break;
case 0x5d: unimpl_instruction(state); break;
case 0x5e: unimpl_instruction(state); break;
case 0x5f: unimpl_instruction(state); break;
case 0x60: unimpl_instruction(state); break;
case 0x61: unimpl_instruction(state); break;
case 0x62: unimpl_instruction(state); break;
case 0x63: unimpl_instruction(state); break;
case 0x64: unimpl_instruction(state); break;
case 0x65: unimpl_instruction(state); break;
case 0x66: unimpl_instruction(state); break;
case 0x67: unimpl_instruction(state); break;
case 0x68: unimpl_instruction(state); break;
case 0x69: unimpl_instruction(state); break;
case 0x6a: unimpl_instruction(state); break;
case 0x6b: unimpl_instruction(state); break;
case 0x6c: unimpl_instruction(state); break;
case 0x6d: unimpl_instruction(state); break;
case 0x6e: unimpl_instruction(state); break;
case 0x6f: unimpl_instruction(state); break;
case 0x70: unimpl_instruction(state); break;
case 0x71: unimpl_instruction(state); break;
case 0x72: unimpl_instruction(state); break;
case 0x73: unimpl_instruction(state); break;
case 0x74: unimpl_instruction(state); break;
case 0x75: unimpl_instruction(state); break;
case 0x76: unimpl_instruction(state); break;
case 0x77: unimpl_instruction(state); break;
case 0x78: unimpl_instruction(state); break;
case 0x79: unimpl_instruction(state); break;
case 0x7a: unimpl_instruction(state); break;
case 0x7b: unimpl_instruction(state); break;
case 0x7c: unimpl_instruction(state); break;
case 0x7d: unimpl_instruction(state); break;
case 0x7e: unimpl_instruction(state); break;
case 0x7f: unimpl_instruction(state); break;
case 0x80: unimpl_instruction(state); break;
case 0x81: unimpl_instruction(state); break;
case 0x82: unimpl_instruction(state); break;
case 0x83: unimpl_instruction(state); break;
case 0x84: unimpl_instruction(state); break;
case 0x85: unimpl_instruction(state); break;
case 0x86: unimpl_instruction(state); break;
case 0x87: unimpl_instruction(state); break;
case 0x88: unimpl_instruction(state); break;
case 0x89: unimpl_instruction(state); break;
case 0x8a: unimpl_instruction(state); break;
case 0x8b: unimpl_instruction(state); break;
case 0x8c: unimpl_instruction(state); break;
case 0x8d: unimpl_instruction(state); break;
case 0x8e: unimpl_instruction(state); break;
case 0x8f: unimpl_instruction(state); break;
case 0x90: unimpl_instruction(state); break;
case 0x91: unimpl_instruction(state); break;
case 0x92: unimpl_instruction(state); break;
case 0x93: unimpl_instruction(state); break;
case 0x94: unimpl_instruction(state); break;
case 0x95: unimpl_instruction(state); break;
case 0x96: unimpl_instruction(state); break;
case 0x97: unimpl_instruction(state); break;
case 0x98: unimpl_instruction(state); break;
case 0x99: unimpl_instruction(state); break;
case 0x9a: unimpl_instruction(state); break;
case 0x9b: unimpl_instruction(state); break;
case 0x9c: unimpl_instruction(state); break;
case 0x9d: unimpl_instruction(state); break;
case 0x9e: unimpl_instruction(state); break;
case 0x9f: unimpl_instruction(state); break;
case 0xa0: unimpl_instruction(state); break;
case 0xa1: unimpl_instruction(state); break;
case 0xa2: unimpl_instruction(state); break;
case 0xa3: unimpl_instruction(state); break;
case 0xa4: unimpl_instruction(state); break;
case 0xa5: unimpl_instruction(state); break;
case 0xa6: unimpl_instruction(state); break;
case 0xa7: unimpl_instruction(state); break;
case 0xa8: unimpl_instruction(state); break;
case 0xa9: unimpl_instruction(state); break;
case 0xaa: unimpl_instruction(state); break;
case 0xab: unimpl_instruction(state); break;
case 0xac: unimpl_instruction(state); break;
case 0xad: unimpl_instruction(state); break;
case 0xae: unimpl_instruction(state); break;
case 0xaf: unimpl_instruction(state); break;
case 0xb0: unimpl_instruction(state); break;
case 0xb1: unimpl_instruction(state); break;
case 0xb2: unimpl_instruction(state); break;
case 0xb3: unimpl_instruction(state); break;
case 0xb4: unimpl_instruction(state); break;
case 0xb5: unimpl_instruction(state); break;
case 0xb6: unimpl_instruction(state); break;
case 0xb7: unimpl_instruction(state); break;
case 0xb8: unimpl_instruction(state); break;
case 0xb9: unimpl_instruction(state); break;
case 0xba: unimpl_instruction(state); break;
case 0xbb: unimpl_instruction(state); break;
case 0xbc: unimpl_instruction(state); break;
case 0xbd: unimpl_instruction(state); break;
case 0xbe: unimpl_instruction(state); break;
case 0xbf: unimpl_instruction(state); break;
case 0xc0: unimpl_instruction(state); break;
case 0xc1: unimpl_instruction(state); break;
case 0xc2: unimpl_instruction(state); break;
case 0xc3: unimpl_instruction(state); break;
case 0xc4: unimpl_instruction(state); break;
case 0xc5: unimpl_instruction(state); break;
case 0xc6: unimpl_instruction(state); break;
case 0xc7: unimpl_instruction(state); break;
case 0xc8: unimpl_instruction(state); break;
case 0xc9: unimpl_instruction(state); break;
case 0xca: unimpl_instruction(state); break;
case 0xcb: unimpl_instruction(state); break;
case 0xcc: unimpl_instruction(state); break;
case 0xcd: unimpl_instruction(state); break;
case 0xce: unimpl_instruction(state); break;
case 0xcf: unimpl_instruction(state); break;
case 0xd0: unimpl_instruction(state); break;
case 0xd1: unimpl_instruction(state); break;
case 0xd2: unimpl_instruction(state); break;
case 0xd3: unimpl_instruction(state); break;
case 0xd4: unimpl_instruction(state); break;
case 0xd5: unimpl_instruction(state); break;
case 0xd6: unimpl_instruction(state); break;
case 0xd7: unimpl_instruction(state); break;
case 0xd8: unimpl_instruction(state); break;
case 0xd9: unimpl_instruction(state); break;
case 0xda: unimpl_instruction(state); break;
case 0xdb: unimpl_instruction(state); break;
case 0xdc: unimpl_instruction(state); break;
case 0xdd: unimpl_instruction(state); break;
case 0xde: unimpl_instruction(state); break;
case 0xdf: unimpl_instruction(state); break;
case 0xe0: unimpl_instruction(state); break;
case 0xe1: unimpl_instruction(state); break;
case 0xe2: unimpl_instruction(state); break;
case 0xe3: unimpl_instruction(state); break;
case 0xe4: unimpl_instruction(state); break;
case 0xe5: unimpl_instruction(state); break;
case 0xe6: unimpl_instruction(state); break;
case 0xe7: unimpl_instruction(state); break;
case 0xe8: unimpl_instruction(state); break;
case 0xe9: unimpl_instruction(state); break;
case 0xea: unimpl_instruction(state); break;
case 0xeb: unimpl_instruction(state); break;
case 0xec: unimpl_instruction(state); break;
case 0xed: unimpl_instruction(state); break;
case 0xee: unimpl_instruction(state); break;
case 0xef: unimpl_instruction(state); break;
case 0xf0: unimpl_instruction(state); break;
case 0xf1: unimpl_instruction(state); break;
case 0xf2: unimpl_instruction(state); break;
case 0xf3: unimpl_instruction(state); break;
case 0xf4: unimpl_instruction(state); break;
case 0xf5: unimpl_instruction(state); break;
case 0xf6: unimpl_instruction(state); break;
case 0xf7: unimpl_instruction(state); break;
case 0xf8: unimpl_instruction(state); break;
case 0xf9: unimpl_instruction(state); break;
case 0xfa: unimpl_instruction(state); break;
case 0xfb: unimpl_instruction(state); break;
case 0xfc: unimpl_instruction(state); break;
case 0xfd: unimpl_instruction(state); break;
case 0xfe: unimpl_instruction(state); break;
case 0xff: unimpl_instruction(state); break;
default: unimpl_instruction(state); break;
}
state->pc++;
return 0;
}
int main(int argc, char **argv)
{
struct State *state = calloc(1, sizeof(struct State));
//state->memory = malloc(0x10000); // 16K
uint8_t instr[] = { 0x01, 0x03, 0x02 };
state->memory = instr;
emulate_op(state);
printf("A $%02x B $%02x C $%02x D $%02x E $%02x H $%02x L $%02x SP %04x\n",
state->a, state->b, state->c, state->d, state->e, state->h, state->l, state->sp);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.