diff --git a/console/curses/console.py b/console/curses/console.py index 8bada4f..b8f7a12 100755 --- a/console/curses/console.py +++ b/console/curses/console.py @@ -137,13 +137,14 @@ def statusbar(st): def CPU_read_status(buf): global LP_RO, LP_SO, LP_SA - global LP_ADD_REG, LP_OP_REG, LP_ALERTS + global LP_ADD_REG, LP_OP_REG, LP_ALERTS, BUTTONS_VAL statusbar('msg') if (len(buf) != 19): statusbar('protocol error') return LP_RO, LP_SO, LP_SA = struct.unpack("HHH", buf[0:6]) LP_ADD_REG, LP_OP_REG, LP_ALERTS = struct.unpack("HHH", buf[6:12]) + BUTTONS_VAL ^= struct.unpack("H", buf[16:18])[0] statusbar('CPU Synchronized') def switch_screen(): @@ -522,8 +523,6 @@ def main(stdscr): if k == curses.KEY_MOUSE: (m_id, mx, my, mz, bstat) = curses.getmouse() parse_mouse(m_id, my, mx) - # Test - LP_ALERTS += 1; scr.clear() diff --git a/console_socket.c b/console_socket.c index abe1f6b..2cfdae1 100644 --- a/console_socket.c +++ b/console_socket.c @@ -2,6 +2,7 @@ #include "ge.h" #include #include +#include static const char socket_path[] = "/tmp/gemu.console"; @@ -21,6 +22,7 @@ int console_socket_init(void) close(sd); return -1; } + printf("Console socket initialized, sd: %d\n", sd); return sd; } @@ -30,22 +32,29 @@ int console_socket_check(struct ge *ge) char buf[1024]; struct sockaddr_un dst; int ret; + struct ge_console temp; socklen_t ssz = sizeof(struct sockaddr_un); if (ge->ge_console_socket < 0) { return -1; } - ge->console.lamps.RO = ge->rRO; - ge->console.lamps.SO = ge->rSO; - ge->console.lamps.SA = ge->rSA; - ge->console.lamps.FA = ge->rFA & 0x0F; - ret = recvfrom(ge->ge_console_socket, buf, 1024, 0, - (struct sockaddr *)&dst, &ssz); - if (ret > 0) { - sendto(ge->ge_console_socket, (unsigned char *)(&ge->console), sizeof(struct ge_console), 0, - (struct sockaddr *)&dst, ssz); - } + do { + ret = recvfrom(ge->ge_console_socket, &temp, sizeof(struct ge_console), 0, + (struct sockaddr *)&dst, &ssz); + if (ret == sizeof(struct ge_console)) { + memcpy(&ge->console, &temp, sizeof(struct ge_console)); + memset(&ge->console.lamps, 0, sizeof(struct console_lamp)); + ge->console.lamps.LP_POWER_ON = 1; + ge->console.lamps.LP_HALT = ge->halted; + ge->console.lamps.RO = ge->rRO; + ge->console.lamps.SO = ge->rSO; + ge->console.lamps.SA = ge->rSA; + ge->console.lamps.FA = ge->rFA & 0x0F; + } + } while (ret != -1); + sendto(ge->ge_console_socket, (unsigned char *)(&ge->console), sizeof(struct ge_console), 0, + (struct sockaddr *)&dst, ssz); return 0; } diff --git a/ge.c b/ge.c index 7a9b26c..b53d2c5 100644 --- a/ge.c +++ b/ge.c @@ -22,28 +22,38 @@ int ge_init(struct ge *ge) printf("Console socket created (fd = %d)\n", ge->ge_console_socket); } ge->halted = 1; - ge->console.lamps.LP_POWER_ON = 1; - ge->console.lamps.LP_HALT = 1; ge->ticks = 0; return 0; } +int ge_halt(struct ge *ge) +{ + if ((ge->halted == 0) && (ge->console.buttons.B_HALT_START)) { + ge->halted = 1; + printf("HALTED\n"); + } +} + /// Emulate the press of the "clear" button in the console void ge_clear(struct ge *ge) { - // From 14023130-0, sheet 5: - // The pressure of the "CLEAR" push button only determines the continuos - // performance of the "00" status - ge->rSO = 0; + if (ge->console.buttons.B_CLEAR) { + // From 14023130-0, sheet 5: + // The pressure of the "CLEAR" push button only determines the continuos + // performance of the "00" status + ge->rSO = 0; - /* From 30004122 o/A, sheet 31: - * The light is switched off by tle LOFF instruction or by the CLEAR key */ - ge->operator_call = 0; + /* From 30004122 o/A, sheet 31: + * The light is switched off by tle LOFF instruction or by the CLEAR key */ + ge->operator_call = 0; - // Also clear the emulated memory... what else?! - memset(ge->mem, 0, sizeof(ge->mem)); + // Also clear the emulated memory... what else?! + memset(ge->mem, 0, sizeof(ge->mem)); - ge->AINI = 0; + ge->AINI = 0; + + printf("CLEAR\n"); + } } /// Emulate the press of the "load" button in the console @@ -52,38 +62,44 @@ int ge_load(struct ge *ge, uint8_t *program, uint8_t size) if (program == NULL && size != 0) return -1; - /* When pressing LOAD button, AINI is set. If AINI is set, the state 80 - * (initialitiation) goes to state c8, starting the loading of the program - * (of max 129 words) from one of the peripherc unit. */ + if (ge->console.buttons.B_LOAD) { - /* set AINI FF to 1 (pag. 96)*/ - ge->AINI = 1; - if (program != NULL) { - if (size > MAX_PROGRAM_STORAGE_WORDS) - size = MAX_PROGRAM_STORAGE_WORDS; + /* When pressing LOAD button, AINI is set. If AINI is set, the state 80 + * (initialitiation) goes to state c8, starting the loading of the program + * (of max 129 words) from one of the peripherc unit. */ - /* simulate the loading for now */ - memcpy(ge->mem, program, size); + /* set AINI FF to 1 (pag. 96)*/ + ge->AINI = 1; + if (program != NULL) { + if (size > MAX_PROGRAM_STORAGE_WORDS) + size = MAX_PROGRAM_STORAGE_WORDS; - /* I'm supposing that the AINI signal is resetted after loading */ - ge->AINI = 0; - } + /* simulate the loading for now */ + memcpy(ge->mem, program, size); + /* I'm supposing that the AINI signal is resetted after loading */ + ge->AINI = 0; + } + printf("LOAD\n"); + } return 0; } /// Emulate the press of the "start" button in the console int ge_start(struct ge *ge) { - // From 14023130-0, sheet 5: - // With the rotating switch in "NORM" position, after the operation - // "CLEAR-LOAD-START" or "CLEAR-START", the 80 status is performed. - ge->rSO = 0x80; - ge->console.rotary = RS_NORM; - - ge->halted = 0; - ge->console.lamps.LP_HALT = 0; - + if ((ge->console.buttons.B_HALT_START) && (ge->halted)) { + // From 14023130-0, sheet 5: + // With the rotating switch in "NORM" position, after the operation + // "CLEAR-LOAD-START" or "CLEAR-START", the 80 status is performed. + if (ge->console.rotary != RS_NORM) { + printf("Console switch not in NORM position.\n"); + return 0; + } + ge->rSO = 0x80; + + ge->halted = 0; + } return 0; } diff --git a/ge.h b/ge.h index fcbfd1b..511e6d5 100644 --- a/ge.h +++ b/ge.h @@ -242,7 +242,6 @@ struct ge { /* Faults: TODO (pp. 139-141) */ uint8_t rFA; - struct ge_console console; int ge_console_socket; struct ge_counting_network counting_network; @@ -262,6 +261,8 @@ struct ge { int PUC3:1; /* Channel 3 busy */ int URPE:1; /* */ + + struct ge_console console; }; /// Initialize the emulator @@ -281,6 +282,7 @@ int ge_load(struct ge * ge, uint8_t *program, uint8_t size); /// Emulate the press of the "start" button in the console int ge_start(struct ge * ge); +int ge_halt(struct ge *ge); typedef int (*on_pulse_cb)(struct ge *); diff --git a/main.c b/main.c index 01d81fc..a1c79e3 100644 --- a/main.c +++ b/main.c @@ -1,6 +1,7 @@ #include "ge.h" #include #include +#include "console_socket.h" int main(int argc, char *argv[]) { @@ -15,14 +16,17 @@ int main(int argc, char *argv[]) /* load with memory / and or setup peripherics */ while(1) { + console_socket_check(&ge130); ge_clear(&ge130); ge_load(&ge130, &test_program, 1); ge_start(&ge130); - ret = ge_run(&ge130); + if (!ge130.halted) + ret = ge_run(&ge130); + ge_halt(&ge130); sleep(1); - printf(" *** RESTART *** "); + printf(" *** RESTART *** \n"); } return ret; }