www.jupiter-ace.co.uk

Previous Page > Listings Index > Ace Graphics


Ace Graphics listing from Personal Computing World September 1983
Personal Computing World September 1983 page 164


ACE GRAPHICS
The Jupiter Ace, like the ZX81, has pixel graphics, and an instruction PLOT which allows a program to set or clear any pixel on the screen. It would be useful, especially for games, to have some command which would test to see if a pixel is black or white. This is what this command
?PLOT does.

  The command uses assembler code and, if the defining word CODE has been defined as described in the manual, can be used in the same way as a normal Forth word would be used.
  The input parameters are: x-coordinate, y-coordinate, and the command returns
TRUE (1) if the pixel at that position is white, and FALSE (0) if the pixel is black.
  Note: any assembler code entered via CALL on the Ace enters with HL pointing at the first instruction. (CALL uses JP (HL).) This is used to construct an address in the middle of the code. This address is put into IY. so that a piece of ROM code, which exits with JP (IY), can be entered. The ROM code is part of the code for the PLOT command. It is entered with BC containing the plot type word, 0 for unplot. The coordinates are still on the stack, but PLOT will take them off the stack and use them.
 On return, the following
registers are useful:
  A   New screen char-
       acter code.
  E   Old screen character
        code.
HL    Screen address.
  If the pixel was already black, it cannot be unplotted, and so both codes will be the same. If you want the command to leave the screen unchanged, you can put the old character back onto the screen; if you want the command to leave the pixel black, this instruction can be omitted.

  Finally, the command exits via part of the ROM code for 0=. It enters with the A register zero or non-zero, and a flag value is put on the stack.

  The first version of the command is the smallest possible, but it is dangerous! If you call it with incorrect co-ordinates, you get the system into such a state that the only thing you can do is switch off! You should only use this version when you are trying to squeeze a program into the available space, and you can guarantee correct parameters every time. The second version is only eight bytes longer, but less dangerous. It will still do funny things after incorrect parameters, but it will then recover. You will find that the first thing you type in after 'ERROR will do something funny, but after that, type ABORT to make sure, then you can continue as normal, and can try and
CODE ?PLOT ( assembly code routine to test
            the state of a pixel
            input: x-coord y-coord
            returns: flag
            0: pixel was black
            1: pixel was white
            uses ROM PLOT code)
 1 C,  11,       (LD BC,0011)(NB entered with HL)
 9 C,            (ADD HL,BC )( = entry address)
E5 C,            (PUSH HL   )
FD C, E3 C,      (EX [SP],IY)(IY points into code)
DI C,            (POP DE    )
23 C,            (INC HL    )
23 C,            (INC HL)   )
73 C,            (LD (HL],E )
23 C,            (INC HL    )(save IY for later)
72 C,            (LD (HL),D )
48 C,            (LD C,B    )(BC = 0 meaning unplot)
C3 C, B4F ,      (JP B4F    )(enter ROM - will return
                              by JP [IY])
FD C, 21 C, 0 ,  (LD IY,0   )(restore original IY)
73 C,            (LD [HL],E )(put original value back)
                           (THIS INSTRUCTION OPTIONAL)
AB C,            (XOR E     )(A = 0 if no change)
C3 C, C1F ,      (JP C1F    )(sets flag and returns )

Version 2 (Larger but less dangerous)

CODE ?PLOT ( assembly code routine to test
            the state of a pixel
            input: x-coord y-coord
            returns: flag
            0: pixel was black
            1: pixel was white
            uses ROM PLOT code)
 1 C,  B,        (LD BC,000B)(NB entered with HL)
 9 C,            (ADD HL,BC )( = entry address)
E5 C,            (PUSH HL   )
FD C, E3 C,      (EX [SP],IY)(IY points into code)
48 C,            (LD C,B    )(BC = 0 meaning unplot)
C3 C, B4F ,      (JP B4F    )(enter ROM - will return
                              by JP [IY])
FD C, E1 C,      (POP IY    )(restore original IY)
73 C,            (LD [HL],E )(put original value back)
                           (THIS INSTRUCTION OPTIONAL)
AB C,            (XOR E     )(A = 0 if no change)
C3 C, C1F ,      (JP C1F    )(sets flag and returns )

Version 1 (Small but dangerous)
correct your incorrect values. Both versions are listed with a lot of comments, which should be omitted when typing in. All numbers are hex-
a decimal, which means that you should have typed in the line:
16 BASE C!
before starting to enter the command.