/* Drive the Virtual AGC CPU (yaAGC agc_engine) through the real Luminary099 SPSIN / SPCOS routines for every 15-bit input word. Output: one line per input: input_octal sin_octal cos_octal sin_mcts cos_mcts */ #include #include #include "yaAGC.h" #include "agc_engine.h" #define SENTINEL 07776 /* return address we stop at; never executed */ static int run(agc_t *st, int entry, int input, int *out, long *mcts) { int16_t a = (input & 040000) ? (input | 0100000) : input; /* sign-extend into 16-bit A */ st->Erasable[0][RegA] = a; st->Erasable[0][RegQ] = SENTINEL; st->Erasable[0][RegZ] = entry; st->NextZ = 0; st->ExtraCode = 0; st->IndexValue = 0; st->SubstituteInstruction = 0; st->ExtraDelay = 0; st->PendFlag = 0; st->PendDelay = 0; st->AllowInterrupt = 0; st->InIsr = 0; /* Reset the hardware watchdogs (Night Watchman, rupt lock, TC trap) so a long sweep of short calls never trips a restart that a real mission's executive would have kept quiet. */ st->NightWatchman = 0; st->NightWatchmanTripped = 0; st->RuptLock = 0; st->NoRupt = 0; st->TCTrap = 0; st->NoTC = 0; st->ScalerCounter = 0; st->ParityFail = 0; for (int i = 0; i < 1 + NUM_INTERRUPT_TYPES; i++) st->InterruptRequests[i] = 0; uint64_t c0 = st->CycleCounter; for (int steps = 0; steps < 10000; steps++) { agc_engine(st); if ((st->Erasable[0][RegZ] & 07777) == SENTINEL && st->ExtraDelay == 0 && !st->PendFlag) { *out = st->Erasable[0][RegA] & 0177777; *mcts = (long)(st->CycleCounter - c0); return 0; } } return 1; } int main(int argc, char **argv) { if (argc < 4) { fprintf(stderr, "usage: run_sp rope.bin spsin_addr spcos_addr\n"); return 2; } static agc_t st; if (agc_engine_init(&st, argv[1], NULL, 0)) { fprintf(stderr, "init failed\n"); return 1; } int spsin = (int)strtol(argv[2], NULL, 8), spcos = (int)strtol(argv[3], NULL, 8); for (int v = 0; v < 0100000; v++) { int s, c; long ms, mc; if (run(&st, spsin, v, &s, &ms) || run(&st, spcos, v, &c, &mc)) { fprintf(stderr, "no return for %05o\n", v); return 1; } printf("%05o %06o %06o %ld %ld\n", v, s, c, ms, mc); } return 0; }