home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / forth / compiler / fpc / source / p4_13dc.seq < prev    next >
Text File  |  1990-04-15  |  2KB  |  43 lines

  1. \ Problem 4.13   04/15/90 17:50:45.80
  2.  
  3.  
  4. CREATE TABLE 12 ALLOT   \ Here space is alloted but not initialized.
  5. TABLE 12 ERASE          \ Here the 12 bytes or 6 16-bit numbers are
  6.                         \ set to zero.
  7.  
  8.  VARIABLE MODE
  9.  
  10.  
  11.  0 CONSTANT RED         2 CONSTANT BLUE     4 CONSTANT YELLOW
  12.  6 CONSTANT BLACK       8 CONSTANT WHITE   10 CONSTANT GREEN
  13.  
  14. : LESS -1  MODE !  ;     \ Subtract top of stack from current position.
  15. : SHOW  0  MODE !  ;     \ Display current array position.
  16. : MORE  1  MODE !  ;     \ Add top of stack to current position.
  17. : ONLY  2  MODE !  ;     \ Store top of stack to current array position.
  18.  
  19. : LESS?  MODE @ -1 = ;
  20. : SHOW?  MODE @  0=  ;
  21. : MORE?  MODE @  1 = ;
  22. : ONLY?  MODE @  2 = ;
  23.  
  24. : MARBLES  ( {n} color   -- )   \ There may be 1 or 2 numbers on stack.
  25.         TABLE  +                        \ Add colour offset to TABLE
  26.         DEPTH 1 =                       \ Check for {n} present.
  27.         IF SHOW THEN                    \ Set display mode if no {n}
  28.         LESS? IF   SWAP NEGATE SWAP +!  \ Do the subtract function.
  29.               ELSE SHOW?
  30.                    IF   @ .             \ Do the display function.
  31.                    ELSE MORE?
  32.                         IF   +!         \ Do the add function.
  33.                         ELSE ONLY?
  34.                               IF !       \ Do the reset function.
  35.                               ELSE ." Invalid mode!!! Try again."
  36.                               THEN
  37.                         THEN
  38.               THEN
  39.        THEN
  40.        ONLY ;     \ Set the default mode to the reset function.
  41.  
  42.  
  43.