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

  1. /* LIBT.C
  2.  
  3.     Vrsn  Date   Comment
  4.     ----|-------|---------------------------------------------------------------
  5.     0.00 25nov94 Test LIB routines BL and CR.
  6.     0.01 26nov94 Also test EMIT and KEY.
  7.     0.02 28nov94 Changed reference to b_mem to one to M0. Added C code so that
  8.                  bForth program to test KEY and EMIT is exercised, and debugged
  9.                  the bForth test program.
  10.     0.03 30nov94 Modified so that testing is automatic, and can run with or
  11.                  without debugging information. Modified to give a return value
  12.                  from main.
  13.     0.04 17feb95 Modified to work with new version of storage.c, and use
  14.                  btests.h rather than bintern.h.
  15.     0.05 28feb95 Removed printf format error.
  16.     0.06 02apr95 Changed instructions in debug mode to work interactively with
  17.                  GETCH and with input from file.
  18.  
  19.     Reuben Thomas
  20.  
  21.  
  22.     Also uses instructions with lower opcodes. The value of BL is printed, a
  23.     number of CRs are printed, and some text is accepted by KEY and then
  24.     EMITted. This test program is interdependent with test/doloop.c.
  25.  
  26. */
  27.  
  28.  
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include "beetle.h"     /* main header */
  32. #include "btests.h"    /* Beetle tests header */
  33. #include "opcodes.h"    /* opcode enumeration */
  34. #include "debug.h"      /* debugging functions */
  35.  
  36.  
  37. int main(void)
  38. {
  39.     int i;
  40.  
  41.     init_beetle((BYTE *)malloc(1024), 256, 16);
  42.     here = EP;
  43.     S0 = SP;    /* save base of stack */
  44.     R0 = RP;    /* save base of return stack */
  45.  
  46.     start_ass();
  47.     ass(O_ZERO); ass(O_LIB); ass(O_ONE); ass(O_LIB);
  48.     ass(O_ONE); ass(O_LIB); ass(O_ONE); ass(O_LIB);
  49.     ass(O_LITERALI); ilit(3);
  50.     ass(O_LIB); ass(O_DUP); ass(O_LITERALI); ilit(10);
  51.     ass(O_EQUAL); ass(O_QBRANCHI); ilit(-3);
  52.     ass(O_DROP); ass(O_SPFETCH); ass(O_LITERAL); lit((CELL)((BYTE *)S0 - M0));
  53.         ass(O_SWAPMINUS);
  54.     ass(O_CELL); ass(O_SLASH); ass(O_MONE); ass(O_DO);
  55.     ass(O_ZERO); ilit(0);   /* pad out instruction word with NEXT */
  56.     ass(O_LITERALI); ilit(2);
  57.     ass(O_LIB); ass(O_LOOPI); ilit(-2);
  58.     ass(O_ONE); ass(O_LIB);
  59.     end_ass();
  60.  
  61.     NEXT;   /* load first instruction word */
  62.  
  63.     single_step();  single_step();
  64. #ifdef B_DEBUG
  65.     printf("BL should be 32, and is %d\n\n", *SP);
  66. #endif
  67.     if (*SP++ != 32) {
  68.         printf("Error in LibT: EP = %ld\n", val_EP());
  69.         exit(1);
  70.     }
  71.  
  72.     for (i = 0; i < 3; i++) {
  73.         printf("%d", i);
  74.         single_step();  single_step();
  75.         if (i == 0) single_step();
  76.     }
  77.     printf("\n0 1 2 should be at the start of separate lines.\n"
  78.         "N.B. this is NOT automatically checked!\n\n");
  79.  
  80. #ifdef B_DEBUG
  81.     printf("Type some text (not echoed) terminated with a linefeed. It should "
  82.         "be\ndisplayed with the characters in reverse order.\n\n");
  83. #else
  84.     printf("\"txet emos si sihT\" should be displayed below.\n"
  85.         "N.B. this is NOT automatically checked!\n\n");
  86. #endif
  87.     while (val_EP() < 68) single_step();
  88.  
  89.     printf("\nLibT ran OK (unless one of the unchecked tests failed - see "
  90.         "above)\n");
  91.     return 0;
  92. }
  93.