~crc_/retroforth

8f5241bd015c7a0ce33f59be318ec87bd15568a4 — crc 5 days ago 51ec526
more work on supporting unsigned numbers in retro-unix/nga-c

FossilOrigin-Name: 79af4af61d2a866e3fe0c4c57aa9f8c1a3ef09b672f8b66909ad9a06ae5d20ff
2 files changed, 75 insertions(+), 20 deletions(-)

M vm/nga-c/image.c
M vm/nga-c/retro.c
M vm/nga-c/image.c => vm/nga-c/image.c +21 -6
@@ 10,8 10,8 @@
#define CELL_MAX LLONG_MAX - 1
#endif
#endif
CELL ngaImageCells = 16713;
CELL ngaImage[] = { 1793,16082,16669,16712,202110,405,377,1150,1535,0,10,1,10,2,10,3,10,4,10,
CELL ngaImageCells = 17005;
CELL ngaImage[] = { 1793,16082,16961,17004,202110,405,377,1150,1535,0,10,1,10,2,10,3,10,4,10,
                       5,10,6,10,7,10,8,10,11,10,12,10,13,10,14,10,15,10,16,10,
                       17,10,18,10,19,10,20,10,21,10,22,10,23,10,24,10,25,68223234,1,2575,
                       85000450,1,656912,161,178,268505089,63,62,285281281,0,63,2063,10,101384453,0,9,10,68485378,255,18350338,


@@ 20,7 20,7 @@ CELL ngaImage[] = { 1793,16082,16669,16712,202110,405,377,1150,1535,0,10,1,10,2,
                       101777669,1,17565186,107,524545,111,64,167838467,-1,134287105,3,59,659457,3,459023,128,2049,56,25,2049,
                       128,1793,135,2049,135,117506307,0,128,0,524545,26,133,168820993,0,147,1642241,147,134283523,11,133,
                       1793,128,524545,2049,128,1793,128,16846593,147,161,178,1793,64,16846593,147,133,178,1793,64,7,
                       10,659713,1,659713,2,659713,3,659713,4,1793,16422,17108737,3,2,524559,128,2049,128,2049,128,
                       10,659713,1,659713,2,659713,3,659713,4,1793,16714,17108737,3,2,524559,128,2049,128,2049,128,
                       524545,0,128,2049,142,168820998,2,15345,1150,167841793,206,9,17826049,0,206,2,15,25,524546,186,
                       134287105,207,116,2305,208,459023,216,134287361,207,211,659201,206,10,659969,7,2049,56,25,17694978,58,
                       232,9,84152833,48,319750404,231,117507601,234,184618754,45,25,16974851,-1,168886532,1,134284289,1,247,134284289,0,


@@ 171,7 171,7 @@ CELL ngaImage[] = { 1793,16082,16669,16712,202110,405,377,1150,1535,0,10,1,10,2,
                       0,659713,1,10,3130,3153,166,14919,110,58,100,101,99,0,659969,1,10,3143,3171,166,
                       14919,110,58,98,101,116,119,101,101,110,63,0,67503109,1793,3179,67503109,67503109,2049,3122,10,
                       1,3174,2049,2203,11,10,3156,3199,166,14919,83,99,111,112,101,76,105,115,116,0,
                       16523,16601,10,3185,3209,166,14919,123,123,0,2049,1573,2,1,3199,2049,59,16,10,3202,
                       16815,16893,10,3185,3209,166,14919,123,123,0,2049,1573,2,1,3199,2049,59,16,10,3202,
                       3235,166,14919,45,45,45,114,101,118,101,97,108,45,45,45,0,2049,1573,1,3199,
                       2049,3140,16,10,3218,3250,166,14919,125,125,0,1,3199,2049,56,4,15,11,1793,3264,
                       3841,3199,4097,2,10,1,3259,1793,3290,3841,3199,1793,3285,1,2,983567,1,3199,2049,3140,


@@ 219,7 219,7 @@ CELL ngaImage[] = { 1793,16082,16669,16712,202110,405,377,1150,1535,0,10,1,10,2,
                       4114,154,14919,84,101,109,112,83,116,114,105,110,103,115,0,32,4098,4133,154,14919,
                       84,101,109,112,83,116,114,105,110,103,77,97,120,0,512,4115,4146,166,14919,83,
                       84,82,73,78,71,83,0,2049,1544,3841,4114,3841,4133,19,18,10,4134,4167,154,0,
                       67,117,114,114,101,110,116,0,14,10,4155,4183,166,0,115,58,112,111,105,110,
                       67,117,114,114,101,110,116,0,26,10,4155,4183,166,0,115,58,112,111,105,110,
                       116,101,114,0,3841,4167,3841,4133,19,2049,4146,17,10,4169,4203,166,0,115,58,110,
                       101,120,116,0,1,4167,2049,3701,3841,4167,3841,4114,11,1793,4219,1,0,4097,4167,10,
                       1,4214,9,10,4134,4234,166,14919,115,58,116,101,109,112,0,2,2049,102,2049,3140,


@@ 846,4 846,19 @@ CELL ngaImage[] = { 1793,16082,16669,16712,202110,405,377,1150,1535,0,10,1,10,2,
                       1,16637,2049,64,10,100,105,99,116,45,119,111,114,100,115,45,108,105,115,116,
                       105,110,103,46,102,111,114,116,104,0,16523,16696,166,16644,100,58,119,111,114,100,
                       115,45,98,101,103,105,110,110,105,110,103,45,119,105,116,104,0,2049,1953,2049,
                       5346,1793,16707,2049,186,2049,16621,10,1,16702,2049,8364,10,0 };
                       5346,1793,16707,2049,186,2049,16621,10,1,16702,2049,8364,10,1793,16737,2049,14765,2049,4308,1793,
                       16727,1,188,1,2,17,8,10,1,16720,2049,2192,2049,1573,2049,184,16,10,1,16714,
                       100,105,99,116,45,119,111,114,100,115,45,108,105,115,116,105,110,103,46,102,
                       111,114,116,104,0,16669,16776,166,16739,100,58,119,111,114,100,115,0,1793,16785,2049,
                       186,2049,10213,2049,10185,10,1,16778,2049,8364,10,100,105,99,116,45,119,111,114,100,
                       115,45,108,105,115,116,105,110,103,46,102,111,114,116,104,0,16764,16832,166,16790,
                       100,58,119,111,114,100,115,45,119,105,116,104,0,2049,1953,2049,5346,1793,16863,2049,
                       186,2,2049,1953,2049,4849,1793,16852,2049,10213,2049,10185,10,1,16847,1793,16858,3,10,1,
                       16856,2049,64,10,1,16838,2049,8364,10,100,105,99,116,45,119,111,114,100,115,45,
                       108,105,115,116,105,110,103,46,102,111,114,116,104,0,16815,16913,166,16868,100,105,
                       115,112,108,97,121,45,105,102,45,108,101,102,116,0,2,2049,1953,2049,5294,1793,
                       16925,2049,10213,2049,10185,10,1,16920,1793,16931,3,10,1,16929,2049,64,10,100,105,99,
                       116,45,119,111,114,100,115,45,108,105,115,116,105,110,103,46,102,111,114,116,
                       104,0,16815,16988,166,16936,100,58,119,111,114,100,115,45,98,101,103,105,110,110,
                       105,110,103,45,119,105,116,104,0,2049,1953,2049,5346,1793,16999,2049,186,2049,16913,10,
                       1,16994,2049,8364,10,0 };

M vm/nga-c/retro.c => vm/nga-c/retro.c +54 -14
@@ 1983,7 1983,7 @@ CELL load_image(char *imageFile) {

void prepare_vm() {
  active = 0;
  cpu[active].ip = cpu[active].sp = cpu[active].rp = 0;
  cpu[active].ip = cpu[active].sp = cpu[active].rp = cpu[active].u = 0;
  cpu[active].active = -1;
  for (cpu[active].ip = 0; cpu[active].ip < IMAGE_SIZE; cpu[active].ip++)
    memory[cpu[active].ip] = 0; /* NO - nop instruction */


@@ 2060,22 2060,38 @@ void inst_re() {
}

void inst_eq() {
  NOS = (NOS == TOS) ? -1 : 0;
  if (cpu[active].u != 0) {
    NOS = ((unsigned)NOS == (unsigned)TOS) ? -1 : 0;
  } else {
    NOS = (NOS == TOS) ? -1 : 0;
  }
  inst_dr();
}

void inst_ne() {
  NOS = (NOS != TOS) ? -1 : 0;
  if (cpu[active].u != 0) {
    NOS = ((unsigned)NOS != (unsigned)TOS) ? -1 : 0;
  } else {
    NOS = (NOS != TOS) ? -1 : 0;
  }
  inst_dr();
}

void inst_lt() {
  NOS = (NOS < TOS) ? -1 : 0;
  if (cpu[active].u != 0) {
    NOS = ((unsigned)NOS < (unsigned)TOS) ? -1 : 0;
  } else {
    NOS = (NOS < TOS) ? -1 : 0;
  }
  inst_dr();
}

void inst_gt() {
  NOS = (NOS > TOS) ? -1 : 0;
  if (cpu[active].u != 0) {
    NOS = ((unsigned)NOS > (unsigned)TOS) ? -1 : 0;
  } else {
    NOS = (NOS > TOS) ? -1 : 0;
  }
  inst_dr();
}



@@ 2097,17 2113,29 @@ void inst_st() {
}

void inst_ad() {
  NOS += TOS;
  if (cpu[active].u != 0) {
    NOS = (unsigned)NOS + (unsigned)TOS;
  } else {
    NOS += TOS;
  }
  inst_dr();
}

void inst_su() {
  NOS -= TOS;
  if (cpu[active].u != 0) {
    NOS = (unsigned)NOS - (unsigned)TOS;
  } else {
    NOS -= TOS;
  }
  inst_dr();
}

void inst_mu() {
  NOS *= TOS;
  if (cpu[active].u != 0) {
    NOS = (unsigned)NOS * (unsigned)TOS;
  } else {
    NOS *= TOS;
  }
  inst_dr();
}



@@ 2115,8 2143,13 @@ void inst_di() {
  CELL a, b;
  a = TOS;
  b = NOS;
  TOS = b / a;
  NOS = b % a;
  if (cpu[active].u != 0) {
    TOS = (unsigned)b / (unsigned)a;
    NOS = (unsigned)b % (unsigned)a;
  } else {
    TOS = b / a;
    NOS = b % a;
  }
}

void inst_an() {


@@ 2140,10 2173,17 @@ void inst_sh() {
  if (TOS < 0)
    NOS = NOS << (0 - TOS);
  else {
    if (x < 0 && y > 0)
      NOS = x >> y | ~(~0U >> y);
    else
      NOS = x >> y;
    if (cpu[active].u != 0) {
      if (x < 0 && y > 0)
        NOS = (unsigned)x >> (unsigned)y | ~(~0U >> (unsigned)y);
      else
        NOS = (unsigned)x >> (unsigned)y;
    } else {
      if (x < 0 && y > 0)
        NOS = x >> y | ~(~0U >> y);
      else
        NOS = x >> y;
    }
  }
  inst_dr();
}