diff options
-rw-r--r-- | asmmon.c | 159 | ||||
-rw-r--r-- | opcode.h | 12 | ||||
-rw-r--r-- | sux.c | 36 | ||||
-rw-r--r-- | test/reg-transfer.s | 23 |
4 files changed, 151 insertions, 79 deletions
@@ -3,6 +3,7 @@ #define debug 1 +#define OPNUM 85 #define SETOP(num, _mne, _IMM, _ZM, _ZMX, _ZMY, _ABS, _IMPL) \ {opcodes[num].mnemonic[3] = '\0'; strncpy(opcodes[num].mnemonic, _mne, 3); \ opcodes[num].imm = _IMM; \ @@ -10,87 +11,93 @@ opcodes[num].zm = _ZM; opcodes[num].zmx = _ZMX; opcodes[num].zmy = _ZMY; \ opcodes[num].abs = _ABS; opcodes[num].impl = _IMPL;} int asmmon() { - opent opcodes[79]; + opent opcodes[OPNUM]; /* mne IMM ZM ZMX ZMY ABS IMPL*/ SETOP(0, "CPS", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); SETOP(1, "ADC", 0x01, 0x05, 0x00, 0x00, 0x03, 0x00); SETOP(2, "PHP", 0x08, 0x00, 0x00, 0x00, 0x00, 0x00); SETOP(3, "PHA", 0x09, 0x00, 0x00, 0x00, 0x00, 0x00); SETOP(4, "PHY", 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(5, "PHX", 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(6, "JMP", 0x00, 0xD0, 0x00, 0x00, 0x10, 0x00); - SETOP(7, "SBC", 0x11, 0x15, 0x00, 0x00, 0x13, 0x00); - SETOP(8, "PLP", 0x18, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(9, "PLA", 0x19, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(10, "PLY", 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(11, "PLX", 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(12, "JSR", 0x00, 0x20, 0x00, 0x00, 0x00, 0x00); - SETOP(13, "AND", 0x21, 0x2B, 0x00, 0x00, 0x29, 0x00); - SETOP(14, "ANY", 0x22, 0x82, 0x00, 0x00, 0x52, 0x00); - SETOP(15, "AAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x23); - SETOP(16, "ANX", 0x24, 0x84, 0x00, 0x00, 0x54, 0x00); - SETOP(17, "AAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x25); - SETOP(18, "STT", 0x28, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(19, "BPO", 0x00, 0x00, 0x00, 0x00, 0x30, 0x00); - SETOP(20, "ORA", 0x31, 0x3B, 0x00, 0x00, 0x39, 0x00); - SETOP(21, "ORY", 0x32, 0x00, 0x00, 0x00, 0x62, 0x00); - SETOP(22, "OAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x33); - SETOP(23, "ORX", 0x34, 0x94, 0x00, 0x00, 0x64, 0x00); - SETOP(24, "OAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x35); - SETOP(25, "SEI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x38); - SETOP(26, "BNG", 0x00, 0x00, 0x00, 0x00, 0x40, 0x00); - SETOP(27, "XOR", 0x41, 0x4B, 0x00, 0x00, 0x49, 0x00); - SETOP(28, "XRY", 0x42, 0xA2, 0x00, 0x00, 0x72, 0x00); - SETOP(29, "XAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x43); - SETOP(30, "XRX", 0x44, 0xA4, 0x00, 0x00, 0x74, 0x00); - SETOP(31, "XAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x45); - SETOP(32, "CLI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x48); - SETOP(33, "BCS", 0x00, 0x00, 0x00, 0x00, 0x50, 0x00); - SETOP(34, "LSL", 0x51, 0x55, 0x00, 0x00, 0x53, 0x00); - SETOP(35, "SEC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x58); - SETOP(36, "STA", 0x00, 0x7B, 0x8B, 0x9B, 0x5B, 0x00); - SETOP(37, "STY", 0x00, 0x7D, 0x8D, 0x00, 0x5D, 0x00); - SETOP(38, "STX", 0x00, 0x7E, 0x00, 0x9E, 0x5E, 0x00); - SETOP(39, "BCC", 0x00, 0x00, 0x00, 0x00, 0x60, 0x00); - SETOP(40, "LSR", 0x61, 0x65, 0x00, 0x00, 0x63, 0x00); - SETOP(41, "CLC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x68); - SETOP(42, "LDA", 0x69, 0x79, 0x89, 0x99, 0x59, 0x00); - SETOP(43, "LDY", 0x6A, 0x7A, 0x8A, 0x00, 0x5A, 0x00); - SETOP(44, "LDX", 0x6C, 0x7C, 0x00, 0x9C, 0x5C, 0x00); - SETOP(45, "BEQ", 0x00, 0x00, 0x00, 0x00, 0x70, 0x00); - SETOP(46, "ROL", 0x71, 0x75, 0x00, 0x00, 0x73, 0x00); - SETOP(47, "SSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x78); - SETOP(48, "BNE", 0x00, 0x00, 0x00, 0x00, 0x80, 0x00); - SETOP(49, "ROR", 0x81, 0x85, 0x00, 0x00, 0x83, 0x00); - SETOP(50, "CSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x88); - SETOP(51, "BVS", 0x00, 0x00, 0x00, 0x00, 0x90, 0x00); - SETOP(52, "MUL", 0x91, 0x95, 0x00, 0x00, 0x93, 0x00); - SETOP(53, "SEV", 0x00, 0x00, 0x00, 0x00, 0x00, 0x98); - SETOP(54, "BVC", 0x00, 0x00, 0x00, 0x00, 0xA0, 0x00); - SETOP(55, "DIV", 0xA1, 0xA5, 0x00, 0x00, 0xA3, 0x00); - SETOP(56, "CLV", 0x00, 0x00, 0x00, 0x00, 0x00, 0xA8); - SETOP(57, "RTS", 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0); - SETOP(58, "CMP", 0xB1, 0xF5, 0x00, 0x00, 0xE5, 0x00); - SETOP(59, "CPY", 0xB2, 0xF2, 0x00, 0x00, 0xE2, 0x00); - SETOP(60, "CAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xB3); - SETOP(61, "CPX", 0xB4, 0xF4, 0x00, 0x00, 0xE4, 0x00); - SETOP(62, "CAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xB5); - SETOP(63, "ENT", 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(64, "RTI", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0); - SETOP(65, "INC", 0x00, 0xE3, 0x00, 0x00, 0xE1, 0xC1); - SETOP(66, "INY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2); - SETOP(67, "IAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3); - SETOP(68, "INX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC4); - SETOP(69, "IAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5); - SETOP(70, "DEC", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD1); - SETOP(71, "DEY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD2); - SETOP(72, "DAY", 0x00, 0xF3, 0x00, 0x00, 0xF1, 0xD3); - SETOP(73, "DEX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD4); - SETOP(74, "DAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD5); - SETOP(75, "JSL", 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00); - SETOP(76, "NOP", 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8); - SETOP(77, "RTL", 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0); - SETOP(78, "BRK", 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8); + SETOP(5, "TAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B); + SETOP(6, "PHX", 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(7, "TAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D); + SETOP(8, "TYX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E); + SETOP(9, "JMP", 0x00, 0xD0, 0x00, 0x00, 0x10, 0x00); + SETOP(10, "SBC", 0x11, 0x15, 0x00, 0x00, 0x13, 0x00); + SETOP(11, "PLP", 0x18, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(12, "PLA", 0x19, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(13, "PLY", 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(14, "TYA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B); + SETOP(15, "PLX", 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(16, "TXA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D); + SETOP(17, "TXY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E); + SETOP(18, "JSR", 0x00, 0x20, 0x00, 0x00, 0x00, 0x00); + SETOP(19, "AND", 0x21, 0x2B, 0x00, 0x00, 0x29, 0x00); + SETOP(20, "ANY", 0x22, 0x82, 0x00, 0x00, 0x52, 0x00); + SETOP(21, "AAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x23); + SETOP(22, "ANX", 0x24, 0x84, 0x00, 0x00, 0x54, 0x00); + SETOP(23, "AAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x25); + SETOP(24, "STT", 0x28, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(25, "BPO", 0x00, 0x00, 0x00, 0x00, 0x30, 0x00); + SETOP(26, "ORA", 0x31, 0x3B, 0x00, 0x00, 0x39, 0x00); + SETOP(27, "ORY", 0x32, 0x00, 0x00, 0x00, 0x62, 0x00); + SETOP(28, "OAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x33); + SETOP(29, "ORX", 0x34, 0x94, 0x00, 0x00, 0x64, 0x00); + SETOP(30, "OAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x35); + SETOP(31, "SEI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x38); + SETOP(32, "BNG", 0x00, 0x00, 0x00, 0x00, 0x40, 0x00); + SETOP(33, "XOR", 0x41, 0x4B, 0x00, 0x00, 0x49, 0x00); + SETOP(34, "XRY", 0x42, 0xA2, 0x00, 0x00, 0x72, 0x00); + SETOP(35, "XAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x43); + SETOP(36, "XRX", 0x44, 0xA4, 0x00, 0x00, 0x74, 0x00); + SETOP(37, "XAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x45); + SETOP(38, "CLI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x48); + SETOP(39, "BCS", 0x00, 0x00, 0x00, 0x00, 0x50, 0x00); + SETOP(40, "LSL", 0x51, 0x55, 0x00, 0x00, 0x53, 0x00); + SETOP(41, "SEC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x58); + SETOP(42, "STA", 0x00, 0x7B, 0x8B, 0x9B, 0x5B, 0x00); + SETOP(43, "STY", 0x00, 0x7D, 0x8D, 0x00, 0x5D, 0x00); + SETOP(44, "STX", 0x00, 0x7E, 0x00, 0x9E, 0x5E, 0x00); + SETOP(45, "BCC", 0x00, 0x00, 0x00, 0x00, 0x60, 0x00); + SETOP(46, "LSR", 0x61, 0x65, 0x00, 0x00, 0x63, 0x00); + SETOP(47, "CLC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x68); + SETOP(48, "LDA", 0x69, 0x79, 0x89, 0x99, 0x59, 0x00); + SETOP(49, "LDY", 0x6A, 0x7A, 0x8A, 0x00, 0x5A, 0x00); + SETOP(50, "LDX", 0x6C, 0x7C, 0x00, 0x9C, 0x5C, 0x00); + SETOP(51, "BEQ", 0x00, 0x00, 0x00, 0x00, 0x70, 0x00); + SETOP(52, "ROL", 0x71, 0x75, 0x00, 0x00, 0x73, 0x00); + SETOP(53, "SSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x78); + SETOP(54, "BNE", 0x00, 0x00, 0x00, 0x00, 0x80, 0x00); + SETOP(55, "ROR", 0x81, 0x85, 0x00, 0x00, 0x83, 0x00); + SETOP(56, "CSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x88); + SETOP(57, "BVS", 0x00, 0x00, 0x00, 0x00, 0x90, 0x00); + SETOP(58, "MUL", 0x91, 0x95, 0x00, 0x00, 0x93, 0x00); + SETOP(59, "SEV", 0x00, 0x00, 0x00, 0x00, 0x00, 0x98); + SETOP(60, "BVC", 0x00, 0x00, 0x00, 0x00, 0xA0, 0x00); + SETOP(61, "DIV", 0xA1, 0xA5, 0x00, 0x00, 0xA3, 0x00); + SETOP(62, "CLV", 0x00, 0x00, 0x00, 0x00, 0x00, 0xA8); + SETOP(63, "RTS", 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0); + SETOP(64, "CMP", 0xB1, 0xF5, 0x00, 0x00, 0xE5, 0x00); + SETOP(65, "CPY", 0xB2, 0xF2, 0x00, 0x00, 0xE2, 0x00); + SETOP(66, "CAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xB3); + SETOP(67, "CPX", 0xB4, 0xF4, 0x00, 0x00, 0xE4, 0x00); + SETOP(68, "CAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xB5); + SETOP(69, "ENT", 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(70, "RTI", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0); + SETOP(71, "INC", 0x00, 0xE3, 0x00, 0x00, 0xE1, 0xC1); + SETOP(72, "INY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2); + SETOP(73, "IAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3); + SETOP(74, "INX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC4); + SETOP(75, "IAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5); + SETOP(76, "DEC", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD1); + SETOP(77, "DEY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD2); + SETOP(78, "DAY", 0x00, 0xF3, 0x00, 0x00, 0xF1, 0xD3); + SETOP(79, "DEX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD4); + SETOP(80, "DAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD5); + SETOP(81, "JSL", 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00); + SETOP(82, "NOP", 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8); + SETOP(83, "RTL", 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0); + SETOP(84, "BRK", 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8); uint8_t done = 0; uint64_t address = 0x0000; while (!(done & 1)) { @@ -228,7 +235,7 @@ int asmmon() { } if (ins != NULL && !(done & 6)) { uint8_t i; - for (i = 0; i < 77; i++) { + for (i = 0; i < OPNUM; i++) { if (strcasecmp(opcodes[i].mnemonic, ins) == 0) { if (addrmode == 0 && (opcodes[i].impl || opcodes[i].impl == CPS)) { done |= 8; @@ -9,13 +9,19 @@ #define PHP 0x08 /* PusH Processor status to stack. */ #define PHA 0x09 /* PusH Accumulator to stack. */ #define PHY 0x0A /* PusH Y register to stack. */ +#define TAY 0x0B /* Transfer Accumulator to Y. */ #define PHX 0x0C /* PusH X register to stack. */ +#define TAX 0x0D /* Transfer Accumulator to X. */ +#define TYX 0x0E /* Transfer Y to X. */ #define JMP 0x10 /* JuMP to memory location. */ #define SBC 0x11 /* SuBtract with Carry. */ #define PLP 0x18 /* PuLl Processor status from stack. */ #define PLA 0x19 /* PuLl Accumulator from stack. */ #define PLY 0x1A /* PuLl Y register from stack. */ +#define TYA 0x1B /* Transfer Y to Accumulator. */ #define PLX 0x1C /* PuLl X register from stack. */ +#define TXA 0x1D /* Transfer X to Accumulator. */ +#define TXY 0x1E /* Transfer X to Y. */ #define JSR 0x20 /* Jump to SubRoutine. */ #define AND 0x21 /* bitwise AND with accumulator. */ #define ANY 0x22 /* bitwise ANd with Y register.*/ @@ -126,7 +132,10 @@ static const char *opname[0x100] = { OPNAME(PHP), OPNAME(PHA), OPNAME(PHY), + OPNAME(TAY), OPNAME(PHX), + OPNAME(TAX), + OPNAME(TYX), OPNAME(JMP), [SBC] = "SBC #", [0x13] = "SBC a", @@ -134,7 +143,10 @@ static const char *opname[0x100] = { OPNAME(PLP), OPNAME(PLA), OPNAME(PLY), + OPNAME(TYA), OPNAME(PLX), + OPNAME(TXA), + OPNAME(TXY), OPNAME(JSR), [AND] = "AND #", [ANY] = "ANY #", @@ -17,7 +17,6 @@ uint8_t threads_done = 0; uint8_t lines[THREADS]; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -pthread_barrier_t bar; struct suxthr { struct sux sx; uint8_t th; @@ -175,6 +174,39 @@ void *run(void *args) { addr[0xFF91] = cpu->sp >> 8; } break; + case TAY: /* Transfer Accumulator to Y. */ + case TAX: /* Transfer Accumulator to Y. */ + case TYX: /* Transfer Y to X. */ + case TYA: /* Transfer Y to Accumulator. */ + case TXA: /* Transfer X to Accumulator. */ + case TXY: /* Transfer X to Y. */ + if (opcode == TAY) + cpu->y[thread] = cpu->a[thread]; + if (opcode == TAX) + cpu->x[thread] = cpu->a[thread]; + if (opcode == TYX) + cpu->x[thread] = cpu->y[thread]; + if (opcode == TYA) + cpu->a[thread] = cpu->y[thread]; + if (opcode == TXA) + cpu->a[thread] = cpu->x[thread]; + if (opcode == TXY) + cpu->y[thread] = cpu->x[thread]; + if (opcode == TYA || opcode == TXA) { + cpu->z[thread] = (cpu->a[thread] == 0); + cpu->n[thread] = (cpu->a[thread] >> 63); + } + if (opcode == TAY || opcode == TXY) { + cpu->z[thread] = (cpu->y[thread] == 0); + cpu->n[thread] = (cpu->y[thread] >> 63); + } + if (opcode == TAX || opcode == TYX) { + cpu->z[thread] = (cpu->x[thread] == 0); + cpu->n[thread] = (cpu->x[thread] >> 63); + } + (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); + (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); + break; case PHX: /* PusH X register to stack. */ tmp = addr[cpu->pc[thread]++]; if (tmp > 7) @@ -1413,7 +1445,6 @@ int main(int argc, char **argv) { inst[i] = 0; } pthread_t therads[THREADS]; - pthread_barrier_init(&bar, NULL, THREADS); int result; puts("\033[2J\033[H"); for (int i = 0; i < THREADS; i++) { @@ -1425,7 +1456,6 @@ int main(int argc, char **argv) { pthread_cond_wait(&cond, &mutex); } pthread_mutex_unlock(&mutex); - pthread_barrier_destroy(&bar); #if bench if (threads_done == THREADS) { double tm_sec, tm_usec, tm[THREADS], ttm; diff --git a/test/reg-transfer.s b/test/reg-transfer.s new file mode 100644 index 0000000..580020c --- /dev/null +++ b/test/reg-transfer.s @@ -0,0 +1,23 @@ +; Test register transfer instructions. +; +; by mr b0nk 500 <b0nk @b0nk.xyz> + +cps +inc ; Increment the accumulator. +tay ; Transfer the accumulator to the y register. +tax ; Do the same thing, but with the x register. +jmp $1 ; Loop forever. + +.org $8000 +cps +inc ; Increment the accumulator. +tay ; Transfer the accumulator to the y register. +tax ; Do the same thing, but with the x register. +jmp $1 ; Loop forever. + +.org $FF50 +.qword $8000 + +; Execute the program. +done + |