Skip to content
Snippets Groups Projects
Commit 8cadf885 authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Implement the remote programming protocol.

I don't expect anything actually uses this...
parent e4504028
No related branches found
No related tags found
No related merge requests found
Pipeline #7014 passed
...@@ -4917,6 +4917,13 @@ struct cterminal* cterm_init(int height, int width, int xpos, int ypos, int back ...@@ -4917,6 +4917,13 @@ struct cterminal* cterm_init(int height, int width, int xpos, int ypos, int back
if (cterm->emulation == CTERM_EMULATION_PRESTEL) { if (cterm->emulation == CTERM_EMULATION_PRESTEL) {
cterm->cursor = _NOCURSOR; cterm->cursor = _NOCURSOR;
SETCURSORTYPE(cterm->cursor); SETCURSORTYPE(cterm->cursor);
memcpy(cterm->prestel_data[0], "0000000000??????", PRESTEL_MEM_SLOT_SIZE);
memcpy(cterm->prestel_data[1], ":2:?4967?89:1???", PRESTEL_MEM_SLOT_SIZE);
memcpy(cterm->prestel_data[2], ":1632?123?456???", PRESTEL_MEM_SLOT_SIZE);
memcpy(cterm->prestel_data[3], ";???????????????", PRESTEL_MEM_SLOT_SIZE);
memcpy(cterm->prestel_data[4], ";???????????????", PRESTEL_MEM_SLOT_SIZE);
memcpy(cterm->prestel_data[5], ";???????????????", PRESTEL_MEM_SLOT_SIZE);
memcpy(cterm->prestel_data[6], ";???????????????", PRESTEL_MEM_SLOT_SIZE);
} }
return cterm; return cterm;
...@@ -5430,6 +5437,20 @@ prestel_move(struct cterminal *cterm, int xadj, int yadj) ...@@ -5430,6 +5437,20 @@ prestel_move(struct cterminal *cterm, int xadj, int yadj)
prestel_get_state(cterm); prestel_get_state(cterm);
} }
static void
prestel_send_memory(struct cterminal *cterm, uint8_t mem, char *retbuf, size_t retsize)
{
char app[2] = {0,0};
for (int x = 0; x < PRESTEL_MEM_SLOT_SIZE; x++) {
if (cterm->prestel_data[mem][x] != '?') {
app[0] = cterm->prestel_data[mem][x];
if(strlen(retbuf) + 1 < retsize)
strcat(retbuf, app);
}
}
}
CIOLIBEXPORT char* cterm_write(struct cterminal * cterm, const void *vbuf, int buflen, char *retbuf, size_t retsize, int *speed) CIOLIBEXPORT char* cterm_write(struct cterminal * cterm, const void *vbuf, int buflen, char *retbuf, size_t retsize, int *speed)
{ {
const unsigned char *buf = (unsigned char *)vbuf; const unsigned char *buf = (unsigned char *)vbuf;
...@@ -5635,35 +5656,139 @@ CIOLIBEXPORT char* cterm_write(struct cterminal * cterm, const void *vbuf, int b ...@@ -5635,35 +5656,139 @@ CIOLIBEXPORT char* cterm_write(struct cterminal * cterm, const void *vbuf, int b
} }
} }
else if(cterm->sequence) { else if(cterm->sequence) {
ustrcat(cterm->escbuf,ch);
if (cterm->emulation == CTERM_EMULATION_PRESTEL) { if (cterm->emulation == CTERM_EMULATION_PRESTEL) {
prestel_apply_ctrl_before(cterm, ch[0]); if (cterm->prestel_prog_state == PRESTEL_PROG_NONE) {
TEXTATTR(cterm->attr); if (ch[0] == '1')
setcolour(cterm->fg_color, cterm->bg_color); cterm->prestel_prog_state = PRESTEL_PROG_1;
cterm->escbuf[0]=0; else {
cterm->sequence=0; prestel_apply_ctrl_before(cterm, ch[0]);
if (cterm->extattr & CTERM_EXTATTR_PRESTEL_HOLD) { TEXTATTR(cterm->attr);
tmpvc[0].ch = cterm->prestel_last_mosaic; setcolour(cterm->fg_color, cterm->bg_color);
if ((tmpvc[0].ch >= 128) && (cterm->extattr & CTERM_EXTATTR_PRESTEL_SEPARATED)) cterm->escbuf[0]=0;
tmpvc[0].ch += 64; cterm->sequence=0;
if (cterm->extattr & CTERM_EXTATTR_PRESTEL_HOLD) {
tmpvc[0].ch = cterm->prestel_last_mosaic;
if ((tmpvc[0].ch >= 128) && (cterm->extattr & CTERM_EXTATTR_PRESTEL_SEPARATED))
tmpvc[0].ch += 64;
}
else {
tmpvc[0].ch = ch[0] - 64;
}
tmpvc[0].legacy_attr=cterm->attr;
tmpvc[0].fg = cterm->fg_color | (ch[0] << 24);
tmpvc[0].bg = cterm->bg_color;
tmpvc[0].font = ciolib_attrfont(cterm->attr);
SCR_XY(&sx, &sy);
vmem_puttext(sx, sy, sx, sy, tmpvc);
ch[1]=0;
CURR_XY(&x, &y);
prestel_apply_ctrl_after(cterm, ch[0]);
TEXTATTR(cterm->attr);
setcolour(cterm->fg_color, cterm->bg_color);
advance_char(cterm, &x, &y, 1);
}
} }
else { else {
tmpvc[0].ch = ch[0] - 64; if (ch[0] == 0)
break;
switch (cterm->prestel_prog_state) {
case PRESTEL_PROG_1:
if (ch[0] == 0x1b)
cterm->prestel_prog_state = PRESTEL_PROG_1_ESC;
else {
cterm->prestel_prog_state = PRESTEL_PROG_NONE;
cterm->escbuf[0]=0;
cterm->sequence=0;
}
break;
case PRESTEL_PROG_1_ESC:
if (ch[0] == '2') {
cterm->prestel_prog_state = PRESTEL_PROG_2;
cterm->prestel_mem = 0;
}
else {
cterm->prestel_prog_state = PRESTEL_PROG_NONE;
cterm->escbuf[0]=0;
cterm->sequence=0;
}
break;
case PRESTEL_PROG_2:
if (ch[0] == 5) {
prestel_send_memory(cterm, cterm->prestel_mem, retbuf, retsize);
cterm->prestel_prog_state = PRESTEL_PROG_NONE;
cterm->escbuf[0]=0;
cterm->sequence=0;
}
else if (ch[0] == 0x1b) {
cterm->prestel_prog_state = PRESTEL_PROG_2_ESC;
}
else {
cterm->prestel_prog_state = PRESTEL_PROG_NONE;
cterm->escbuf[0]=0;
cterm->sequence=0;
}
break;
case PRESTEL_PROG_2_ESC:
if (ch[0] == '3') {
cterm->prestel_mem++;
if (cterm->prestel_mem >= PRESTEL_MEM_SLOTS) {
cterm->prestel_prog_state = PRESTEL_PROG_NONE;
cterm->escbuf[0]=0;
cterm->sequence=0;
}
else
cterm->prestel_prog_state = PRESTEL_PROG_2;
}
else if (ch[0] == '4') {
cterm->prestel_prog_state = PRESTEL_PROG_PROGRAM_BLOCK;
}
else {
cterm->prestel_prog_state = PRESTEL_PROG_NONE;
cterm->escbuf[0]=0;
cterm->sequence=0;
}
break;
case PRESTEL_PROG_PROGRAM_BLOCK:
ch[1] = 0;
switch(ch[0]) {
case ':':
ch[0] = '0';
/* Fall-through */
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case ';':
case '?':
ustrcat(cterm->escbuf, ch);
if (strlen(cterm->escbuf) >= PRESTEL_MEM_SLOT_SIZE) {
memcpy(cterm->prestel_data[cterm->prestel_mem], cterm->escbuf, PRESTEL_MEM_SLOT_SIZE);
prestel_send_memory(cterm, cterm->prestel_mem, retbuf, retsize);
cterm->prestel_prog_state = PRESTEL_PROG_NONE;
cterm->escbuf[0]=0;
cterm->sequence=0;
}
break;
default:
cterm->prestel_prog_state = PRESTEL_PROG_NONE;
cterm->escbuf[0]=0;
cterm->sequence=0;
break;
}
break;
default:
cterm->prestel_prog_state = PRESTEL_PROG_NONE;
break;
}
} }
tmpvc[0].legacy_attr=cterm->attr;
tmpvc[0].fg = cterm->fg_color | (ch[0] << 24);
tmpvc[0].bg = cterm->bg_color;
tmpvc[0].font = ciolib_attrfont(cterm->attr);
SCR_XY(&sx, &sy);
vmem_puttext(sx, sy, sx, sy, tmpvc);
ch[1]=0;
CURR_XY(&x, &y);
prestel_apply_ctrl_after(cterm, ch[0]);
TEXTATTR(cterm->attr);
setcolour(cterm->fg_color, cterm->bg_color);
advance_char(cterm, &x, &y, 1);
} }
else { else {
ustrcat(cterm->escbuf,ch);
switch(legal_sequence(cterm->escbuf, sizeof(cterm->escbuf)-1)) { switch(legal_sequence(cterm->escbuf, sizeof(cterm->escbuf)-1)) {
case SEQ_BROKEN: case SEQ_BROKEN:
/* Broken sequence detected */ /* Broken sequence detected */
...@@ -6165,10 +6290,7 @@ CIOLIBEXPORT char* cterm_write(struct cterminal * cterm, const void *vbuf, int b ...@@ -6165,10 +6290,7 @@ CIOLIBEXPORT char* cterm_write(struct cterminal * cterm, const void *vbuf, int b
prn[0]=0; prn[0]=0;
break; break;
case 5: // ENQ case 5: // ENQ
// Send memory 1 prestel_send_memory(cterm, 0, retbuf, retsize);
if(strlen(retbuf) + 10 < retsize)
// TODO: Use the memories...
strcat(retbuf, "0000000000");
break; break;
case 8: // APB (Active Position Packward) case 8: // APB (Active Position Packward)
lastch = 0; lastch = 0;
......
...@@ -70,6 +70,18 @@ typedef enum { ...@@ -70,6 +70,18 @@ typedef enum {
#define CTERM_NO_SETFONT_REQUESTED 99 #define CTERM_NO_SETFONT_REQUESTED 99
enum prestel_prog_states {
PRESTEL_PROG_NONE = 0,
PRESTEL_PROG_1,
PRESTEL_PROG_1_ESC,
PRESTEL_PROG_2,
PRESTEL_PROG_2_ESC,
PRESTEL_PROG_PROGRAM_BLOCK,
};
#define PRESTEL_MEM_SLOTS 7
#define PRESTEL_MEM_SLOT_SIZE 16
struct cterminal { struct cterminal {
/* conio stuff */ /* conio stuff */
int x; // X position of the left side on the screen int x; // X position of the left side on the screen
...@@ -235,6 +247,11 @@ struct cterminal { ...@@ -235,6 +247,11 @@ struct cterminal {
int skypix; int skypix;
uint8_t prestel_last_mosaic; uint8_t prestel_last_mosaic;
/* Prestel data */
char prestel_data[PRESTEL_MEM_SLOTS][PRESTEL_MEM_SLOT_SIZE];
enum prestel_prog_states prestel_prog_state;
uint8_t prestel_mem;
/* conio function pointers */ /* conio function pointers */
#ifdef CTERM_WITHOUT_CONIO #ifdef CTERM_WITHOUT_CONIO
void (*ciolib_gotoxy) (struct cterminal *,int,int); void (*ciolib_gotoxy) (struct cterminal *,int,int);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment