MaxZ80 - Chapter 6

We talked a couple of Chapters ago about a compiler for programs written in
BASIC. I'd like to talk here about another compiler, one for Pascal programs.
The first example Pascal program will be CHICKEN.PAS.

I've put the compiler and some sample programs in EBC (A6). Log into EBC and get
a directory.

8:46 A0:MOUSE>>EBC:
8:46 A6:EBC>>DIR

         Drive A6 [EBC]        Files: 53/764k   Free: 4704k
-       .106   0k : CPY     .PAS   8k : HELP    .COM   4k : PDTINS  .DTA   4k
ASCII   .ASC   8k : EBC-1   .LBR  28k : MOUSE   .DEF   4k : QUATRIS .FOR   4k
ASCII   .COM   8k : EBC-10  .LBR  28k : MOUSE   .HIS   4k : QUATRIS2.LBR  28k
ASCII   .LTR   4k : EBC-11  .LBR  28k : MOUSE   .INT   8k : RAD     .COM  12k
AUTHORS .EBC   4k : EBC-12  .LBR  24k : MOUSE   .PAS   8k : RAD     .PAS   4k
BOX     .COM  12k : EBC-2   .LBR  44k : MOUSE-PS.FOR   4k : TURBO   .COM  32k
BOX     .PAS   4k : EBC-3   .LBR  52k : NZ-TOOL .BOX   4k : TURBO   .MSG   4k
CHICKEN .COM  16k : EBC-4   .LBR  52k : NZ-TOOL .DEF   8k : TURBO   .OVR   4k
CHICKEN .LBR  12k : EBC-5   .LBR  36k : NZ-TOOL .FOR   4k : TURBOMSG.OVR   4k
CHICKEN .PAS   8k : EBC-6   .LBR  16k : NZ-TOOL .NOT   4k : Z3INTP24.COM   4k
CHOP18A .COM  12k : EBC-7   .LBR  36k : NZ-TOOL6.LBR  44k : Z3INTP24.LBR  16k
CHOP18A .LBR  20k : EBC-8   .LBR  20k : PARAMSTR.INC   4k :
CHOP18A .PAS  12k : EBC-9   .LBR  24k : PD      .PAS   4k :
CPY     .ART   8k : HARDHACK.ART   8k : PDTINS  .COM  12k :

8:46 A6:EBC>>

To compile Pascal programs, type TURBO.

Say Y to the Include error messages (Y/N)? question. You'll be presented with a
menu and a simple prompt (>).

Type O (the letter) (for compiler Options), then C (for Com-file) then Q (to
Quit the Options menu and get back to Turbo's main menu).

Type C (to compile) and then, when asked for a Work file name, type CHICKEN.
Quit TURBO by typing Q.

TURBO goes back to drive A user area 0 when you quit it, so, log back into EBC.

Turbo Pascal is what is known as an IDE, or Integrated Development Environment.
This means you may Run, Edit, Compile etc. The editor is very much like WordStar
but with a few important differences. When you are done editing, to get out of
the editor, type Ctrl-K followed by D. If you made changes, the S command in the
main menu is the way you Save your changes. Also, the editor assumes your
terminal has 24 lines. This is not the default here (which is 25) so you must
run the MYZ80 TERMINAL utility as follows:

TERMINAL LINES=24 

To play CHICKEN, decide who will use the ESDX keys, who will use the IJKM keys
and then duke it out by running the .COM you just created by typing CHICKEN.



I find the speed setting of 8 is pretty good. Your computer might be faster than
mine so 8 will be too fast.

I had to add code to slow CHICKEN down to make it usable on my 400 MHz PC.
Here's the code.

gotoxy(1,1); for i:=1 to delay do begin
 j:=delay div 100; repeat j:=j-1; until j=0;
 end;

Might there be a way we could make it so that, no matter how fast or slow the
computer is, CHICKEN would run at a reasonable speed?

There's an important page in the upper memory of computers running Z-System
called the Z3 Environment. Here's a small section of it.

 C0/SIL:Z3ENV.Z80 /N                   Ln 94   Cl 1    INS       AI
I.......I.......I.......I.......I.......I.......I.......I.......I.......I.
;
; Offset 28h - Quiet flag
;
QUIET:  DB      00      ; 0 - Not quiet
;                       ; 1 - Quiet
;
; Offset 29h - Wheel byte
;
Z3WHL:  DW      0F77FH  ; Address
;
; Offset 2Bh - Processor speed
;
SPEED:  DB      160     ; MHZ
;
; Offset 2Ch - Maximum drive/user accepted
;
MAXDRV: DB      'D'-40H ; Max drive letter
MAXUSR: DB      15      ; Max user number
DUOK:   DB      1       ; 0 - Don't accept DU:
;                       ; 1 - Accept DU:
;
; Offset 2Fh - CRT and printer selection

It's that SPEED byte that's got our attention. It holds the speed, in MHz, of
the computer (since we are running under a Z80 emulator, the real speed of the
computer had to be adjusted down before it was recorded in this byte). If we
could code CHICKEN to read this byte and do something like

delay:=delay*Somefunction(speed);

which would force the loop to have more / fewer steps for a faster / slower PC,
then we wouldn't have to change the source code's value for the delay variable
every time we changed computers.