=========================================
   EZXMB.KCL
   eLeMeNt ZX CONTROL FOR KAMASOFT C'
=========================================

The library is loaded in the
compilation phase (ExT, G) to the upper
part of memory. Declare it once with
extern "ezxmb.kcl"; and each function
with extern NAME(); then call it like an
ordinary function.

These functions are for the eLeMeNt ZX
only. They use the eLeMeNt eZXi port
pair 783Bh (select) and 793Bh (data):
OUT the register index to 783Bh, then
read or write the value at 793Bh.

FUNCTION LIST
-------------------------

name     bytes  input  output
-------  -----  -----  ------
SETSPEED    36      2       0
GETSPEED    14      0       1
EMACHINE    22      1       0

PARAMETER PASSING
--------------------------
- the last (or only) argument is in
  register HL
- all arguments are also in the
  parameter block, pointed to by the
  system variable 5CB0h. Each takes 2
  bytes (low byte first):
     arg1 = (5CB0)+0 and +1
     arg2 = (5CB0)+2 and +3   etc.
- a return value comes back in HL (H is
  0 for a byte result)

=========================================
 SETSPEED - set CPU clock and overclock
=========================================

INPUT : 2 - arg1 overclock enable (0/1)
            arg2 speed
OUTPUT: 0

Sets the eLeMeNt Z80 clock. arg2 picks
the speed (register e_zxi_030):

  0 - 3.5 MHz
  1 - 7 MHz
  2 - 14 MHz
  3 - 20 MHz
  4 - overclock 22 MHz
  5 - overclock 28 MHz (ROM, 1T delay)
  6 - overclock 28 MHz (RAM only)
  7 - overclock 30 MHz (RAM only)

arg1 is the safety switch: it writes
bit0 of e_zxi_031 (CPU OverClock mode).
Pass 1 to allow the overclock speeds
(4-7), pass 0 for the normal speeds
(0-3). The enable is written first, then
the speed. Overclock is experimental -
do NOT use it while writing to an SD
card, the data may be lost.

USAGE:
  extern "ezxmb.kcl";
  {
  setspeed(0,1);  /* 7 MHz */
  setspeed(1,5);  /* overclock 28 MHz */
  }

=========================================
 GETSPEED - read the current CPU speed
=========================================

INPUT : 0
OUTPUT: 1 - the speed code (HL)

Reads register e_zxi_030 and returns the
current speed code (0-7, same meaning as
in SETSPEED). It does not change the
speed. Pair it with SETSPEED to save and
restore the clock.

USAGE:
  declare int s;
  extern "ezxmb.kcl";
  {
  s = getspeed();     /* save */
  setspeed(1,5);      /* overclock */
  setspeed(0,s);      /* restore */
  }

=========================================
 EMACHINE - select machine (mem/timing)
=========================================

INPUT : 1 - arg1 machine
OUTPUT: 0

Selects the machine - memory plus
timing - via register e_zxi_000:

  0 - ZX Spectrum 48
  1 - ZX Spectrum 128 / +2
  3 - ZX Spectrum +2A
  5 - Pentagon 128
  6 - Pentagon 512
  7 - Pentagon 1024 v2.2
  8 - Pentagon 4096
  9 - Didaktik Gama 80
  (2 and 4 are reserved)

Each machine uses its own ROM area;
switching re-maps memory and timing, so
call it from code that stays mapped and
expect a reset-like change of state.

USAGE:
  extern "ezxmb.kcl";
  {
  emachine(5);  /* Pentagon 128 */
  }

=========================================
 End
