Skip to content

Commit

Permalink
draft: connecting button signals
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinux committed Sep 24, 2022
1 parent 6c6ed56 commit 787af20
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 50 deletions.
5 changes: 2 additions & 3 deletions console/curses/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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()


Expand Down
29 changes: 19 additions & 10 deletions console_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "ge.h"
#include <fcntl.h>
#include <string.h>
#include <stdio.h>

static const char socket_path[] = "/tmp/gemu.console";

Expand All @@ -21,6 +22,7 @@ int console_socket_init(void)
close(sd);
return -1;
}
printf("Console socket initialized, sd: %d\n", sd);
return sd;
}

Expand All @@ -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;
}

84 changes: 50 additions & 34 deletions ge.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
4 changes: 3 additions & 1 deletion ge.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -262,6 +261,8 @@ struct ge {
int PUC3:1; /* Channel 3 busy */

int URPE:1; /* */

struct ge_console console;
};

/// Initialize the emulator
Expand All @@ -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 *);
Expand Down
8 changes: 6 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ge.h"
#include <stdio.h>
#include <unistd.h>
#include "console_socket.h"

int main(int argc, char *argv[])
{
Expand All @@ -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;
}

0 comments on commit 787af20

Please sign in to comment.