Home > Listings Index > Ace Can Go Faster
Archive Search  
Aces Can Go Faster From Your Computer, May, 1983, Page 87
FILL BACKGROUND
( ASCII CODE-)
RST 24		223
LD HL,9216	33 0 36
LD B,23		6 23
PUSH BC		197
LD B,32		6 32
LD A,(HL)	126
CP 32		254 32
JR NZ +2	32 2
LD A,E		123
LD (HL),A	119
INC HL          35
DJNZ -10	16 246
POP BC		193
DJNZ -16	16 240
JP (IY)		253 233

FILL FOREGROUND
( ASCII CODE- )
RST 24		223
LD HL,9216	33 0 36
LD B,23		6 23
PUSH BC		197
LD B,32		6 32
LD A,(HL)	126
CP 32		254 32
JR Z +2		40 2
LD A,E		123
LD (HL),A	119
INC HL          35
DJNZ -10	16 246
POP BC		193
DJNZ -16	16 240
JP (IY)		253 233

SEARCH & REPLACE
( ASCII CODE SEARCH, 
ASCII CODE REPLACE - )
RST 24		223
LD C,E		75
RST 24		223
LD HL,9216	33 0 36
LD B,23		6 23
PUSH BC		197
LD B,32		6 32
LD A,(HL)	126
CP E		187
JR NZ +2	32 2
LD A,C		121
LD (HL),A	119
INC HL		35
DJNZ -9		16 247
POP BC		193
DJNZ -15	16 241
JP (IY)		253 233

INVERT
( - )
LD HL,9216	33 0 36
LD B,23		6 23
PUSH BC		197
LD B,32		6 32
LD A,(HL)	126
ADD A,128	198 128
LD (HL),A	119
INC HL		35
DJNZ -7		16 249
POP BC		193
DJNZ -13	16 243
JP (IY)		253 233
ACES  CAN
GO FASTER
Forth is fast, but a little bit of machine code will take you through the light barrier. Simon Cross shows you how to accelerate your Jupiter Ace with this handy kit of 10 screen-handling routines for those situations where Forth is still not quite fast enough and the ultimate speed of machine code is what you require.


  THE JUPITER ACE offers an alternative for those who wish to write fast arcade games but cannot face the sometimes daunting challenge presented by machine code. The speed advantage that Forth has over Basic enables the games programmer to write "space- invader" type programs without reaching for an assembler. However, there are still some situations where Forth is not quite fast enough and the ultimate speed of machine code is required.

  One such situation is writing screen- handling routines such as scrolling. Try this Forth word which fills the screen with a character specified by an ASCII code taken from the top of the stack:

	: FILL
	  9952 9216
	  DO


	  DUP I C!
	  LOOP
	  DROP
	 ;
  Execute this word by typing an ASCII code followed by "fill", for example "42 fill" will produce a screenful of stars. It can be seen that although the screen is filled quite rapidly, the process of printing is visible passing in a wave from the top to the bottom of the screen. When this routine is written in machine code the process appears to be instantaneous; this is useful for creating explosion effects and the like. The difference in speed between Forth and machine code becomes more marked with more complex routines such as scrolling.   Even when routines have to be written in machine code the Forth environment still has


Aces Can Go Faster From Your Computer, May, 1983, Page 89

some advantages. The routine can initially be written in Forth to test its function in the context of the complete program, particularly its effects on the stack. If the routine works it can be translated into machine code without any alterations to the rest of the program. The routine is called by its name which is more convenient than Rand Usr followed by the address, the technique some Basics use. The main advantage is that since Forth words can be moved around the dictionary by Redefine and Load the machine code must be relocat- able.
  This article describes 10 screen-handling words written in machine code for the Jupiter Ace. Any combination of them may be included in ordinary Forth programs where speed is important. No knowledge of machine code is required to use them since once they have been entered they act like any other words in the Forth dictionary. The simplest way to enter the code is by using the defining word "Code" described on page 147 of the Jupiter Ace manual:

	DEFINER CODE
	DOES>
	 CALL
	;

  The machine code is entered by typing Code then the name of the word followed by the decimal code, each byte being separated by C,. For example the Scrollup routine would be entered by typing:
CODE SCROLLUP 33 C, 32 C, 36 C, 
17 C, 0 C, etc.
On pressing Enter the whole typed section will be copied to the upper screen and OK will appear after it. The word can then be executed by typing its name, for example:
	SCROLLUP
  Code is not a very user-friendly word but, since it is not possible to delete it from the dictionary when the code has been entered, it is important that it should not take up much memory space.
  The 10 words will fit into the unexpanded 3K Jupiter Ace, but this does not leave much memory space in which to write programs to utilise the routines. It is better to only enter the words necessary for a specific program.
  Here is a description of the individual words: Scrollup scrolls the entire screen one line up and blanks the bottom line; Scrolldown scrolls the entire screen one line down and blanks the top line; Scrollright scrolls the entire screen one column to the right and blanks the left-hand column; and Scrollleft scrolls the entire screen one column to the left and blanks the right-hand column.
  Fillscreen fills the screen with a character specified by an ASCII code which should be put on the stack before the word is executed. Fillscreen uses the RST 24 routine in the ROM which takes off the top of the Forth stack and puts it in the DE register pair. Fill- foreground fills all the non-blank areas of the screen with a character specified by an ASCII code on the stack. Fillbackground fills all the blank areas of the screen with a character specified by an ASCII code on the stack.
  Search & replace takes two numbers from the stack. The first number is the ASCII code of the character to be searched for on the screen. Any occurrence of this character is replaced by another character whose ASCII code is given by the second number. This word is useful to selectively "flash" parts of the screen for explosions or countdowns.

  Invert turns all the characters on the screen into their inverse forms. It is useful for explosion
effects when used in loops such as this:
: BANG 
  21 1
  DO
   INVERT I 10 * 60 BEEP 
  LOOP
;
  Border prints a border round the edge of the screen using the character specified by an ASCII code on the stack.
SCROLLUP
( - )
LD HL,9248	33 32 36
LD DE,9216	17 0 36
LD B,22		6 22
PUSH BC		197
LD B,32		6 32
LD A,(HL)	119
EX DE,HL	235
LD (HL),A	119
INC HL		35
EX DE,HL	235
DJNZ -8		16 248
POP BC		193
DJNZ -14	16 242
DEC HL		43
LD A,32		62 32
LD B,A		71
LD (HL),A	119
DEC HL		43
DJNZ -4		16 252
JP (IY)		253 233



SCROLLDOWN
( - )
LD HL,9919	33 191 38
LD DE,9951	17 223 38
LD B,22		6 22
PUSH BC		197
LD B,32		6 32
LD A,(HL)	126
EX DE,HL	235
LD (HL),A	119
INC HL		35
EX DE,HL	235
DJNZ -8		16 248
POP BC		193
DJNZ -14	16 242
INC HL		35
LD A,32		62 32
LD B,A		71
LD (HL),A	119
DEC HL		35
DJNZ -4		16 252
JP (IY)		253 233



SCROLRIGHT
( - )
LD HL,9950	33 222 38
LD DE,9951	33 223 38
LD B,23		6 23
PUSH BC		197
LD B,31		6 31
LD A,(HL)	126
EX DE,HL	235
LD (HL),A	119
DEC HL		43
EX DE,HL	235
DEC HL		43
DJNZ -8		16 248
EX DE,HL	235
LD A,32		62 32
LD (HL),A	119
DEC HL		43
EX DE,HL	235
DEC HL		43
POP BC		193
DJNZ -21	16 235
JP (IY)		253 233
SCROLLLEFT
( - )
LD HL,9217	33 1 36
LD DE,9216	33 0 36
LD B,23		6 23
PUSH BC		197
LD B,31		6 31
LD A,(HL)	126
EX DE,HL	235
LD (HL),A	119
INC HL		35
EX DE,HL	235
INC HL		35
DJNZ -8		16 248
EX DE,HL	235
LD A,32		62 32
LD (HL),A	119
INC HL		35
EX DE,HL	235
INC HL		35
POP BC		193
DJNZ -21	16 235
JP (IY)		253 233
 
 






FILLSCREEN
( ASCII CODE- )
RST 24		223
LD A,E		123
LD HL,9216	33 0 36
LD B,23		6 23
PUSH BC		197
LD B,32		6 32
LD (HL),A	119
INC HL		35
DJNZ -4		16 252
POP BC		193
DJNZ -10	16 246
JP (IY)		253 233

  




BORDER
( ASCII CODE- )
RST 24		223
LD A,E		123
LD HL,9216	33 0 36
LD B,32		6 32
LD (HL),A	119
INC HL		35
DJNZ -4		16 252
LD DE,31	17 31 0
LD B,21		6 21
LD (HL),A	119
ADD HL,DE	25
LD (HL),A	119
INC HL		35
DJNZ -6		16 250
LD B,32		6 32
LD (HL),A	119
INC HL		35
DJNZ -4		16 252
JP (IY)		253 233