Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: connecting button signals #16

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
32 changes: 19 additions & 13 deletions console_socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,35 @@ static int console_socket_init(struct ge *ge, void *ctx)
}


static int console_socket_check(struct ge *ge, void *ctx)
int console_socket_check(struct ge *ge, void *ctx)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using some console_socket functions is a good way to interact with the console when ge isn't running.

{
char buf[1024];
struct sockaddr_un dst;
int ret;
int sd = console_socket_fd;
struct ge_console temp;
socklen_t ssz = sizeof(struct sockaddr_un);
(void)ctx;
if (console_socket_fd < 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(console_socket_fd, buf, 1024, 0,
(struct sockaddr *)&dst, &ssz);
if (ret > 0) {
printf("DEBUG: doing check\n");
sendto(console_socket_fd, (unsigned char *)(&ge->console), sizeof(struct ge_console), 0,
(struct sockaddr *)&dst, ssz);
}

do {
ret = recvfrom(sd, &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(sd, (unsigned char *)(&ge->console), sizeof(struct ge_console), 0,
(struct sockaddr *)&dst, ssz);
return 0;
}

Expand Down
84 changes: 50 additions & 34 deletions ge.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,38 @@ int ge_init(struct ge *ge)
{
memset(ge, 0, sizeof(*ge));
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 @@ -49,38 +59,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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if checking the buttons here is the right approach.
Should this function in toto be called when the button is pressed? (or reproduce the side effects of pressing the button)


/* 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)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above, should this function be invoked if the button is pressed?

// 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
3 changes: 2 additions & 1 deletion ge.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ struct ge {
int PUC3:1; /* Channel 3 busy */

int URPE:1; /* */

struct ge_peri *peri;

};

/// Initialize the emulator
Expand All @@ -296,6 +296,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
7 changes: 5 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ int main(int argc, char *argv[])
/* load with memory / and or setup peripherics */

while(1) {
console_socket_check(&ge130);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have something like:

ge_init();
while(1) {
    while(ge->halted)
       console_check_wait_signals();
    ge_run_cycle() // <- this optional if console_check_wait_signal call ge_run()
}

ge_clear(&ge130);
ge_load(&ge130, &test_program, 1);
ge_start(&ge130);
Comment on lines +23 to 26
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should separate these two ways of running the emulator, I think we can have an option to enable the console, and in this case, clear/load/start are only managed through the console, otherwise, a simpler clear/load/start like the one we have now is used.


ret = ge_run(&ge130);
if (!ge130.halted)
ret = ge_run(&ge130);

ge_halt(&ge130);
sleep(1);
printf(" *** RESTART *** ");
printf(" *** RESTART *** \n");
}
ge_deinit(&ge130);
return ret;
Expand Down