home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / RiscOS / APP / DEVS / FORTH / BEETLE / BEETLE.ZIP / Beetle / storage.c < prev    next >
C/C++ Source or Header  |  1997-04-22  |  2KB  |  71 lines

  1. /* STORAGE.C
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|---------------------------------------------------------------
  5.     0.00 09nov94
  6.     0.01 11nov94 SP and RP changed to pointers; definition of memory vector
  7.                  changed to ensure it is aligned on a 4-byte boundary.
  8.     0.02 22nov94 b_mem is now initialised explicitly to zero (unnecessary,
  9.                  but helpful).
  10.     0.03 23nov94 Changed THROW to a pointer, so that it is phyiscally held
  11.                  in Beetle's address space as required. Made init_regs copy
  12.                  registers to memory as specified, and changed scope of cast
  13.                  in assignments to SP and RP to make them correct.
  14.     0.04 28nov94 Removed b_mem, which was identical with M0.
  15.     0.05 19jan95 Added compiler tests from tests.c to init_regs.
  16.     0.06 17feb95 Parametrised init_regs (now init_beetle), and removed
  17.                  allocation of memory array and now unnecessary reference to
  18.                  bintern.h. init_beetle made to return a value (1 if e0 is not
  19.                  aligned, 0 if it's OK).
  20.     0.07 24feb95 Added code to init_beetle to initialise 'THROW.
  21.     0.08 23mar95 Added code to init_beetle to check whether e0 is in range (and
  22.                  return 1 if not), and changed e0 to type UCELL.
  23.  
  24.     Reuben Thomas
  25.  
  26.  
  27.     Allocate storage for the registers and memory.
  28.  
  29. */
  30.  
  31.  
  32. #include "beetle.h"     /* main header */
  33. #include "tests.h"      /* compiler tests */
  34.  
  35.  
  36. /* Beetle's registers */
  37.  
  38. CELL *EP;
  39. BYTE I;
  40. CELL A;
  41. BYTE *M0;
  42. CELL MEMORY;
  43. CELL *SP, *RP;
  44. CELL *THROW;      /* 'THROW is not a valid C identifier */
  45. CELL BAD;        /* 'BAD is not a valid C identifier */
  46. CELL ADDRESS;    /* -ADDRESS is not a valid C identifier */
  47.  
  48.  
  49. /* Initialise registers that are not fixed */
  50.  
  51. int init_beetle(BYTE *b_array, long size, UCELL e0)
  52. {
  53.     if (tests()) exit(1);   /* ensure Beetle was compiled properly */
  54.     if (e0 & 3 || e0 >= size * CELL_W) return 1;
  55.  
  56.     M0 = (BYTE *)b_array;
  57.     EP = (CELL *)(M0 + e0);
  58.     MEMORY = size * CELL_W;
  59.     SP = (CELL *)(M0 + (MEMORY - 0x100));
  60.     RP = (CELL *)(M0 + MEMORY);
  61.     THROW = (CELL *)M0;
  62.     BAD = 0xFFFFFFFF;
  63.     ADDRESS = 0xFFFFFFFF;
  64.  
  65.     *((CELL *)M0 + 1) = MEMORY;
  66.     *((CELL *)M0 + 2) = BAD;
  67.     *((CELL *)M0 + 3) = ADDRESS;
  68.  
  69.     return 0;
  70. }
  71.