void CU() { trace; int tick_ignore; int current_instruction; int memory_contents; sc_instGet(¤t_instruction); log_debug(sformat("current_instruction %d", current_instruction)); sc_memoryGet(current_instruction, &memory_contents); int command; int operand; if (sc_commandDecode(memory_contents, &command, &operand)) { sc_regSet(FLAG_WRONG_COMMAND, 1); sc_regSet(FLAG_TICK_IGNORE, 1); trace; return; } ALU(command, operand); int had_overflow; sc_regGet(FLAG_OVERFLOW, &had_overflow); if (had_overflow) { trace; sc_regSet(FLAG_TICK_IGNORE, 1); return; } sc_regGet(FLAG_TICK_IGNORE, &tick_ignore); if (tick_ignore) { trace; return; } int new_instruction; sc_instGet(&new_instruction); if (new_instruction != current_instruction) { trace; return; } current_instruction++; if (current_instruction < 0 || current_instruction > 99) { trace; sc_regSet(FLAG_TICK_IGNORE, 1); return; } sc_instSet(current_instruction); }
void check_reg() { printf("\n--REGISTER CHECK--\n"); sc_regInit(); int tmp = 0; printf("test regSet()\n"); if (!sc_regSet(FLAG_OVERFLOW, 1)) { printf("passed:\n"); printf("%d\n", sc_register.flag); printf("test sc_regGet()\n"); if (!sc_regGet(FLAG_OVERFLOW, &tmp) && tmp == 1) { printf("%d\n", tmp); printf("passed\n"); printf("test accumulating flags:\n"); sc_regSet(FLAG_MEMORY_ERROR, 1); if (sc_register.flag == (FLAG_OVERFLOW | FLAG_MEMORY_ERROR)) { printf("flags accumulated true"); printf("**REGISTER OK\n"); return; } } } printf("REGISTER FAILED\n"); return; }
int main() { signal (SIGALRM, signalhandler); signal (SIGUSR1, reset); nval.it_interval.tv_sec = 1; nval.it_interval.tv_usec = 0; nval.it_value.tv_sec = 1; nval.it_value.tv_usec = 0; sc_regInit(); termInit(); ax = 0x0; ip = 0x0; enum Keys key = K_UNKNOWN; displayBorders(); displayUI(); f_key = 0; f_ign = 0; while (key != K_Q) { readKey (&key); if (key == K_T) { sc_regSet(IR, 0); alarm(0); f_key = 0; cu(); } if (!f_key) { if (key == K_R ) { sc_regSet(IR, 1); sc_regSet(IF, 0); } sc_regGet(IR, &f_key); if (f_key) { timerStart(); } if (key == K_F5 ) user_input_ax(); if (key == K_F6 ) user_input_ip(); if (key == K_RIGHT) if (mem_ptr < 99) ++mem_ptr; if (key == K_LEFT ) if (mem_ptr > 0) --mem_ptr; if (key == K_UP ) if (mem_ptr - 10 >= 0) mem_ptr -= 10; if (key == K_DOWN ) if (mem_ptr + 10 < 100) mem_ptr += 10; if (key == K_L ) sc_memoryLoad("memory.o"); if (key == K_S ) sc_memorySave("memory.o"); if (key == K_E ) user_input_mem(); if (key == K_I) { displayBorders(); displayUI(); sc_memoryInit(); sc_regInit(); } displayUI (); } } return 0; }