www.jupiter-ace.co.uk
 
Previous Page > Listings Index > Board Game.
Personal Computing June 1983 'User-define graphics & Board Game', page 187
JUPITER ACE
User-defined graphics
THE ACE MANUAL gives a method of defining graphics characters, observes William Kirby of Tarporley, Cheshire. It also explains that the character RAM cannot be read from without the data being corrupted since the data is logically ORed with the ASCII code. Character definitions cannot therefore be directly stored on tape. It is necessary to duplicate the eight bytes needed for each character in another area of memory.
The Forth words defined in listing 1 simplify editing the definitions of any of the 128 characters, and allow redefined characters to be saved on cassette files.
CArray creates an array of n*8 bytes, where n is the number of characters for which you wish to store data. A word defined by CArray, given the element number on the stack, returns the address of the required element.
Element 0 holds the size of the array in bytes; it is used by Inchars, which expects an address on the stack. Inchars fetches the size of the array and allows data to be input from the keyboard in hexadecimal, until the array
is full, listing the data on the screen. CMove copies n bytes, starting at address a1 to n addresses starting at a2.
It is a good idea to Save these three words for future use before going any further. The example in listing 2 defines the characters for a game.
You can now see the characters by entering 1 Emit, 2 Emit, etc. or by using Graphics mode. In Graphics mode the A key gives ASCII code 1 , the B key ASCII code 2 and so on. If you have made a mistake entering the data it can be corrected by changing individual elements of Chars. For example, to set byte 3 of character code 5 to A0 hex you must change element (5 — l)*8 + 3 = 27 of Chars, with
160 27 CHARS C! (enter)
You will not see the effect until you copy the data across again with CMove. When you have set up the data correctly, it can be stored on tape with
1 CHARS 120 BSAVE PIECES (enter)
Using BLoad, the data can be read back from tape into any memory location. To retrieve a file of graphics characters, load them straight into the character RAM with
11272 0 BLOAD filename (enter)
(continued on next page)
(continued from previous page)
For this example, Filename would be replaced by Pieces. If you want to verify a tape file, this has to be done against the data in the array rather than the character RAM.
The remaining Forth words, shown in listing 3, enable the Ace to act as an Othello-type board game called Counters. They only just fit in the unexpanded Ace, so Forget anything in the dictionary before typing them in. The graphics characters used are shown in figure 1.
If you now type in HERE . and press Enter the result should be 16297. If not, you may well have missed something out. Before playing the game save the game words, just in case.
The rules of tile game are as follows:
• The game is for two players. One plays with black counters, the other with white. Black always starts.
• To play, you place a counter on an empty square so as to capture at least one of your opponent's counters.
• To capture a counter, the counter you put down must complete a line of counters in any direction, with a counter of your colour at the far end, trapping at least one counter of the opposite colour in between. All counters so trapped are taken.
• If you canot make a valid move you must forfeit your move.
• To start the game, enter GO
• Enter your move with a letter A to H or a to h, followed by a number 1-8 and press Enter. On each move, the computer    will   check   if  the
Graphics — figure 1.
┌ Graphics C     └ Graphics I
┬ Graphics D     ┴ Graphics J
┐ Graphics E     ┘ Graphics K
├ Graphics F     │ Graphics N
┼ Graphics G     ─ Graphics O
  ┤ Graphics H
move is valid. If so, it will convert all the appropriate counters.
If not valid, it will ignore the move and you can try again. To concede your turn in the event of there being no valid move, enter an x or X.
• The game ends either when the board is full, or when both players have conceded a turn. On this computer version. you must both concede even when the board is full to finish the game. The player with the most counters on the board at the end of the game is the winner.
Graphics — listings 1.
DEFINER CARRAY
  NUMBER DROP 8 * DUP
  C, 0
  DO
   0 C,
  LOOP
DOES>
  DUP C@ ROT SWAP OVER
  < OVER 0 < OR
  IF    ." SUBSCRIPT OUT OF RANGE"
   CR ABORT
  THEN
  +
;


: INCHARS
  ( Address - )
  INVIS 16 BASE C! 22
  0 AT DUP C@ 8
  / 1+ 1
  DO
   CR I . 9 1
   DO
    BEGIN
      QUERY NUMBER
    UNTIL
    DUP . SWAP 1+ DUP
    ROT SWAP C!
    LOOP
  LOOP
  DECIMAL VIS
;

: CMOVE
  ( a1,a2,n )
  SWAP 3 PICK - ROT
  ROT 0
  DO
   OVER OVER DUP C@ ROT
   ROT + C! 1+
  LOOP
  DROP DROP
;
listings 2.
CARRAY CHARS 15 (enter)
0 CHARSS INCHARS (enter)
3C 42 81 81 81 81 42 3C
3C 7E FF FF FF FF 7E 3C
 0  0  0 1F 10 10 10 10
 0  0  0 FF 10 10 10 10
0 0 0 F0 10 10 10 10
10 10 10 1F 10 10 10 10
10 10 10 FF 10 10 10 10
10 10 10 F0 10 10 10 10
10 10 10 1F 0 0 0 0
10 10 10 FF 0 0 0 0
10 10 10 F0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
10 10 10 10 10 10 10 10
0 0 0 FF 0 0 0 0
1 CHARS 11272 120 CMOVE (enter)



listings 3.
: BOARD
 CLS 1 8 AT ." ┌─┬─┬─┬─┬─┬─┬─┬─┐"
 9 1
 DO
   I DUP + DUP 6
   AT i . ." │ │ │ │ │ │ │ │ │"
   1+ 8 AT ." ├─┼─┼─┼─┼─┼─┼─┼─┤
   LOOP
   17 8 AT ." └─┴─┴─┴─┴─┴─┴─┴─┘"
   0 0 AT ." A B C D E F G H"
   2 DUP 9487 C! 9553 C!
    1 DUP 9489 C! 9551 C!
    22 3 AT . " to play"
;
  0 VARIABLE X
  0 VARIABLE Y
  0 VARIABLE DX
  0 VARIABLE DV
  0 VARIABLE COL
: PCE
  DUP + 7 + SWAP
  DUP + SWAP AT COL
  @ EMIT
;

: ?C
  DUP + SWAP 64 *
  + 9223 + C@
;

: ENTER
  QUERY 32 WORD 1+ DUP
  C@ 64 - DUP 8
  >
 IF
    32 -
  THEN
  SWAP 1+ C@ 48 -
  SWAP OVER OVER Y !
  X !
;
: ?CH
  0 X @ Y @
  BEGIN
    DY @ + SWAP DX
    @ + SWAP OVER OVER
    ?C 3 COL @ -
    =
  WHILE
    ROT 1+ ROT ROT
  REPEAT
  OVER OVER ?C COL @
  =
  IF
    ROT 0
  DO
    DY @ - SWAP DX
      @ - SWAP OVER OVER
      PCE
    LOOP
    DROP DROP 1
  ELSE
    DROP DROP DROP 0
  THEN
;
: TEST
  ?C 2- 0> 0 SWAP
  IF
    2 - 1
    DO
      2 -1
      DO
        X @ I DUP DX
        ! + Y @ J
        DUP DY ! + ?C
        3 COL @ - =
        IF
          ?CH +
        THEN
      LOOP
    LOOP
  THEN
;
: GO
  INVIS BOARD 2 COL ! 0
  BEGIN
    3 COL @ - DUP
    9921 C! COL !
    BEGIN
      ENTER TEST Y @ 24
      = OR
    UNTIL
    Y @ 24 =
    IF
      1+
    ELSE
      DROP 0 X @ Y
      @ PCE
    THEN
    DUP 1- 0>
  UNTIL
  22 1 AT " GAME OVER"
;