Skip to content

Commit

Permalink
Merge pull request #84 from robots/master
Browse files Browse the repository at this point in the history
More features for 8018x platform
  • Loading branch information
mfld-fr authored Dec 3, 2023
2 parents 16dfcf0 + 41ce930 commit 77c7ac0
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 18 deletions.
25 changes: 23 additions & 2 deletions emu-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ static int debug_proc ()
con_normal();
serial_normal ();

char command [8];
char command [100];
if (!_flag_trace) putchar ('\n');
putchar ('>');
fflush (stdout);
char * res = fgets (command, 8, stdin);
char * res = fgets (command, sizeof(command), stdin);
if (!res) {
err = -1;
_flag_exec = 0;
_flag_exit = 1;
break;
}

Expand Down Expand Up @@ -200,6 +202,25 @@ static int debug_proc ()
if (err) puts ("error: timer interrupt");
break;

// read memory address

case 'R':
{
word_t seg,off;
if (sscanf (&command[1], "%hx:%hx", &seg, &off) != 2)
{
puts ("error: bad read address");
}
else
{
addr_t a = addr_seg_off(seg, off);
byte_t b = mem_stat [a];
printf ("info: Address %02x:%02x %5lx = %02x\n",seg,off, a, b);
}
}
break;


} // command switch
} // _flag_prompt

Expand Down
177 changes: 164 additions & 13 deletions int-8018x.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,89 @@

#define INT_REG_EOI 0
#define INT_REG_MASK 3
#define INT_REG_PRIMSK 4
#define INT_REG_REQST 6
#define INT_REG_TCUCON 8
#define INT_REG_SCUCON 9

#define INT_REG_I4CON 10
#define INT_REG_I0CON 11
#define INT_REG_I1CON 12
#define INT_REG_I2CON 13
#define INT_REG_I3CON 14

int _int_line_max = INT_LINE_MAX;
int _int_prio_max = INT_PRIO_MAX;

// Timer & serial are edge triggered

int _pri_mask = 7;

int _int_mode [INT_LINE_MAX] =
{ 1, 0, 1, 0, 0, 0, 0, 0};
{ 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1};

int _int_prio [INT_LINE_MAX] =
{ 0, 1, 2, 3, 4, 5, 6, 7};
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

int _int_vect [INT_LINE_MAX] =
{ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
{ 8, 0, 20, 17, 12, 13, 14, 15, 21, 18, 19 };

int _int_mask [INT_LINE_MAX] =
{ 1, 1, 1, 1, 1, 1, 1, 1};
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

int _int_req [INT_LINE_MAX] =
{ 0, 0, 0, 0, 0, 0, 0, 0};
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

int _int_serv [INT_LINE_MAX] =
{ 0, 0, 0, 0, 0, 0, 0, 0};
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

word_t imask;


// PIC I/O write
int int_io_read (word_t p, word_t * w)
{
int err = 0;

int r = p >> 1;

if (r == INT_REG_REQST)
{
word_t out = 0;
for (size_t i = 0; i < 8; i++) {
if (i == 0) {
if (_int_req[i] || _int_req[INT_LINE_TIMER1] || _int_req[INT_LINE_TIMER2]) {
out |= 1 << i;
}
} else if (i == 2) {
if (_int_req[i] || _int_req[INT_LINE_SERIALTX]) {
out |= 1 << i;
}
} else if (_int_req[i]) {
out |= 1 << i;
}
}
*w = out;
}
else if (r == INT_REG_MASK)
{
word_t out = 0;
for (size_t i = 0; i < 8; i++) {
if (_int_mask[i]) {
out |= 1 << i;
}
}
// printf("int read IMASK: %08x\n", out);
*w = out;
}
else
{
printf ("\nerror: read from int register %02x %i", p+INT_REG_BASE, r);
err = -1;
}

return err;
}

int int_io_write (word_t p, word_t w)
{
Expand All @@ -46,26 +103,120 @@ int int_io_write (word_t p, word_t w)

if (r == INT_REG_EOI)
{
// printf("EOI %d\n", w);
if (w == 0x8000)
{
int_end_prio ();
}
else
{
if ((w & 0x001F) == 0x0008) int_end_line (INT_LINE_TIMER0);
if ((w & 0x001F) == 0x0014) int_end_line (INT_LINE_SERIAL);
switch (w & 0x001F)
{
case 8:
int_end_line (INT_LINE_TIMER0);
int_end_line (INT_LINE_TIMER1);
int_end_line (INT_LINE_TIMER2);
break;
case 12:
int_end_line (INT_LINE_INT0);
break;
case 13:
int_end_line (INT_LINE_INT1);
break;
case 14:
int_end_line (INT_LINE_INT2);
break;
case 15:
int_end_line (INT_LINE_INT3);
break;
case 17:
int_end_line (INT_LINE_INT4);
break;
case 20:
int_end_line (INT_LINE_SERIAL);
int_end_line (INT_LINE_SERIALTX);
break;
default:
printf("nemam %d\n", w & 0x1f);
}
}
}

else if (r == INT_REG_MASK)
{
_int_mask [INT_LINE_TIMER0] = w & 0x0001;
_int_mask [INT_LINE_SERIAL] = w & 0x0004;
for (int i = 8-1; i >= 0; i--) {
int mask = (w & 0x80) ? 1 : 0;
_int_mask[i] = mask;

if (i == INT_LINE_SERIAL) {
_int_mask[INT_LINE_SERIALTX] = mask;
}
if (i == INT_LINE_TIMER0) {
_int_mask[INT_LINE_TIMER1] = mask;
_int_mask[INT_LINE_TIMER2] = mask;
}
w <<= 1;
}
}

else if (r == INT_REG_PRIMSK)
{
// printf("int primask %d\n", w & 7);
_pri_mask = w & 7;
}
else if (r == INT_REG_TCUCON)
{
// TODO: level ?
_int_mask[INT_LINE_TIMER0] = (p >> 3) & 1;
_int_prio[INT_LINE_TIMER0] = p & 7;
_int_mask[INT_LINE_TIMER1] = (p >> 3) & 1;
_int_prio[INT_LINE_TIMER1] = p & 7;
_int_mask[INT_LINE_TIMER2] = (p >> 3) & 1;
_int_prio[INT_LINE_TIMER2] = p & 7;
// printf("int tcu pri %d mask %d\n", p & 7, (p >> 3) & 1);
}
else if (r == INT_REG_SCUCON)
{
// TODO: level ?
_int_mask[INT_LINE_SERIAL] = (p >> 3) & 1;
_int_mask[INT_LINE_SERIALTX] = (p >> 3) & 1;
_int_prio[INT_LINE_SERIAL] = p & 7;
_int_prio[INT_LINE_SERIALTX] = p & 7;
// printf("int scu pri %d mask %d\n", p & 7, (p >> 3) & 1);
}
else if (r == INT_REG_I4CON)
{
// TODO: level ?
_int_mask[INT_LINE_INT4] = (p >> 3) & 1;
_int_prio[INT_LINE_INT4] = p & 7;
// printf("int int4 pri %d mask %d\n", p & 7, (p >> 3) & 1);
}
else if (r == INT_REG_I0CON)
{
// TODO: level ?
_int_mask[INT_LINE_INT0] = (p >> 3) & 1;
_int_prio[INT_LINE_INT0] = p & 7;
// printf("int int0 pri %d mask %d\n", p & 7, (p >> 3) & 1);
}
else if (r == INT_REG_I1CON)
{
_int_mask[INT_LINE_INT1] = (p >> 3) & 1;
_int_prio[INT_LINE_INT1] = p & 7;
// printf("int int1 pri %d mask %d\n", p & 7, (p >> 3) & 1);
}
else if (r == INT_REG_I2CON)
{
_int_mask[INT_LINE_INT2] = (p >> 3) & 1;
_int_prio[INT_LINE_INT2] = p & 7;
// printf("int int2 pri %d mask %d\n", p & 7, (p >> 3) & 1);
}
else if (r == INT_REG_I3CON)
{
_int_mask[INT_LINE_INT3] = (p >> 3) & 1;
_int_prio[INT_LINE_INT3] = p & 7;
// printf("int int3 pri %d mask %d\n", p & 7, (p >> 3) & 1);
}
else
{
printf ("\nerror: write %hXh to int register %i", w, r);
printf ("\nerror: write %hXh to int register %02x %i", w, p+INT_REG_BASE, r);
err = -1;
}

Expand Down
7 changes: 6 additions & 1 deletion int-8018x.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
#define INT_LINE_INT2 6
#define INT_LINE_INT3 7

#define INT_LINE_MAX 8
#define INT_LINE_TIMER1 8
#define INT_LINE_TIMER2 9
#define INT_LINE_SERIALTX 10

#define INT_LINE_MAX (8+3)

// Interrupt controller

Expand All @@ -28,4 +32,5 @@
#define INT_REG_COUNT 15
#define INT_REG_SIZE (INT_REG_COUNT * 2)

int int_io_read (word_t p, word_t * w);
int int_io_write (word_t p, word_t w);
21 changes: 20 additions & 1 deletion op-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,26 @@ static int op_adjust2 (op_desc_t * op_desc)

static int op_calc_3 (op_desc_t * op_desc)
{
return -1;
assert (op_desc->var_count == 3);
op_var_t * to = &op_desc->var_to;
op_var_t * from = &op_desc->var_from;
op_var_t * from2 = &op_desc->var_from2;
assert (from->type == VT_REG);
assert (from2->type == VT_IMM);
assert (to->type == VT_REG);

op_var_t temp1;
op_var_t temp2;
memset (&temp1, 0, sizeof (op_var_t));
memset (&temp2, 0, sizeof (op_var_t));

val_get (from, &temp1);
val_get (from2, &temp2);

word_t w = (temp1.val.w * temp2.val.w) & 0xffff;

reg16_set (to->val.r, w);
return 0;
}


Expand Down
Loading

0 comments on commit 77c7ac0

Please sign in to comment.