MSX2-Technical-Handbook

CHAPTER 5 - ACCESS TO PERIPHERALS THROUGH BIOS (Sections 1 to 6)

The basic philosophy of MSX is to have a standard interface, independent of machines or versions, to access peripherals through BIOS. Thus, the user should get to know about using BIOS first. In chapter 5, accessing peripherals using BIOS and the structure used for each peripheral are described.

Index

1. PSG AND SOUND OUTPUT

1.1. PSG functions

1.2 Access to the PSG

1.3 Tone Generation by 1-bit Sound Port

1.4 Access to 1-bit Sound Port

2. CASSETTE INTERFACE

2.1 Baud Rate

2.2 One bit composition

2.3 One byte composition

2.4 Header Composition

2.5 File Formats

2.6 Access to cassette files

3. KEYBOARD INTERFACE

3.1 Key Scanning

3.2 Character Input

3.3 Function Keys

3.4 STOP Key During Interrupts

4. PRINTER INTERFACE

4.1 Print Interface Overview

4.2 Output to the MSX Standard Printer

4.3 Access to the printer

5. UNIVERSAL I/O INTERFACE

5.1 Functions of the Ports

5.2 Joystick Use

5.3 Paddle Use

5.4 Use of Touch Panel, Light Pen, Mouse, and Track Ball

6. CLOCK AND BATTERY-POWERED MEMORY

6.1 CLOCK-IC Functions

6.2 Structure of the CLOCK-IC

6.3 MODE Register Functions

6.4 TEST Register functions

6.5 RESET Register Functions

6.6 Setting the Clock and Alarm

6.7 Contents of the Battery-powered Memory

6.8 Access to the CLOCK-IC

Changes from the original

 

1. PSG AND SOUND OUTPUT

MSX has the following three kinds of sound output functions, but function (3) is not installed in the standard MSX, so it is not described in this manual. This section describes functions (1) and (2).

(1) PSG sound output (3 channels, 8 octaves)

(2) Sound output by 1 bit I/O port

(3) Sound output by MSX-AUDIO (FM sound generator) - not described in this manual

 

1.1. PSG functions

An AY-3-8910 compatible LSI is used for the MSX music play function and for BEEP tone generation. This LSI is referred to as the PSG (Programmable Sound Generator), and can generate complex music and varios tones. It has the following features:

Figure 5.1 PSG block diagram
 R0, R1                     R7                  R8
--------------------     -------------         ------------------------------
| Tone generator A | --> |           | ------> | Volume control amplifier A |
--------------------     |           |    +--> ---------------------------+--
                         |           |    |           Channel A output <--+
 R2, R3                  |  Three    |    |     R9
--------------------     |           |    |    ------------------------------
| Tone generator B | --> |  Channel  | ---:--> | Volume control amplifier B |
--------------------     |           |    +--> ---------------------------+--
                         |  Mixer    |    |           Channel B output <--+
 R4, R5                  |           |    |     R9
--------------------     |           |    |    ------------------------------
| Tone generator C | --> |           | ---:--> | Volume control amplifier C |
--------------------     -------------    +--> ---------------------------+--
                                 ^        |           Channel C output <--+
                                 |        |
                    R6           |        |  R11, R12, R13
                 ---------------------   ------------------------
                 |  Noise generator  |   |  Envelope generator  |
                 ---------------------   ------------------------

The PSG has two additional I/O (input/output) ports used for other than tone generating functions, which are omitted in the block diagram above. MSX uses them as general-purpose I/O ports to connect to I/O devices such as joystick, a touch pad, a paddle, or a mouse. These general-purpose I/O ports are described in section 5.

PSG registers

Since the PSG generates tones, the CPU simply notifies PSG when the tone is to be changed. This is done by writing values in 16 8-bit registers inside the PSG as shown in Figure 5.2.

Roles and uses of these registers are described below.

Setting the tone frequency (R0 to R5)

Each tone frequency of channel A, B, and C is set by R0 to R5. The input clock frequency (fc = 1.7897725 MHz) is divided by 16 and the result is the standard frequency. Each channel divides the standard frequency by the 12-bit data assigned for each, and the objective pitch is obtained. The following relation exists between 12-bit data (TP) and the tone frequency to be generated (ft).

    ft = fc/(16 * TP)
       = 0.11186078125/TP [MHz]
       = 111860.78125/TP [Hz]

A 12-bit data TP is specified for each channel by 4 high order bit coarse tune CT and 8 low order bit fine tune value FT, as shown in Figure 5.3. Table 5.1 shows the register settings to make the scales.

Figure 5.2 PSG register structure
-----------------------------------------------------------------------------
|                       Bit |     |     |     |     |     |     |     |     |
|                           | B7  | B6  | B5  | B4  | B3  | B2  | B1  | B0  |
| Register                  |     |     |     |     |     |     |     |     |
|---------------------------+-----------------------------------------------|
|    R0    | Channel A note |                8 low order bits               |
|----------|                |-----------------------------------------------|
|    R1    | Dividing rate  |  x     x     x     x  |   4 high order bits   |
|----------+----------------+-----------------------------------------------|
|    R2    | Channel B note |                8 low order bits               |
|----------|                |-----------------------------------------------|
|    R3    | Dividing rate  |  x     x     x     x  |   4 high order bits   |
|----------+----------------+-----------------------------------------------|
|    R4    | Channel C note |                8 low order bits               |
|----------|                |-----------------------------------------------|
|    R5    | Dividing rate  |  x     x     x     x  |   4 high order bits   |
|----------+----------------+-----------------------------------------------|
|    R6    | Noise div. rate|  x     x     x  |                             |
|----------+----------------+-----------------------------------------------|
|          |                |  IN*/OUT  |      NOISE*     |      TONE*      |
|    R7    | Enable*        |-----------+-----------------+-----------------|
|          |                | IOB | IOA |  C  |  B  |  A  |  C  |  B  |  A  |
|----------+----------------+-----------------+-----+-----------------------|
|    R8    | Chan. A volume |  x     x     x  |  M  |                       |
|----------+----------------+-----------------+-----+-----------------------|
|    R9    | Chan. B volume |  x     x     x  |  M  |                       |
|----------+----------------+-----------------+-----+-----------------------|
|    R10   | Chan. C volume |  x     x     x  |  M  |                       |
|----------+----------------+-----------------------------------------------|
|    R11   |                |                8 low order bits               |
|----------| Envelope Cycle |-----------------------------------------------|
|    R12   |                |                8 high order bits              |
|----------+----------------+-----------------------------------------------|
|    R13   | Env. wave shape|  x     x     x     x  |                       |
|----------+----------------+-----------------------------------------------|
|    R14   | I/O port A     |                                               |
|----------+----------------+-----------------------------------------------|
|    R15   | I/O port B     |                                               |
-----------------------------------------------------------------------------

NOTE:   x = unused bit
        * = inverted signal
Figure 5.3 Setting the pitch
                -------------------------------------------------
R0, R2, R4      |                    8  bits                    | --+
                -------------------------------------------------   |
                -------------------------------------------------   |
R0, R2, R4      |  x     x     x     x  |        4 bits         |   |
                -------------------------------------------------   |
                                                    |               |
            ----------------------------------------+               |
            |                                                       |
            V                                                       V
-----------------------------------------------------------------------
|   Coarse Tune (CT)    |                Fine Tune (FT)               |
-----------------------------------------------------------------------
|                                                                     |
+-------------------------------- TP ---------------------------------+

                                                   [ Channel A - R0, R1 ]
                                                   [ Channel B - R2, R3 ]
                                                   [ Channel C - R4, R5 ]
Table 5.1 Setting the tone frequency (scale data)
----------------------------------------------------------------
|       Octave |     |     |     |     |     |     |     |     |
|              |  1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |
| Note         |     |     |     |     |     |     |     |     |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      C       | D5D | 6AF | 357 | 1AC |  D6 |  6B |  35 |  1B |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      C#      | C9C | 64E | 327 | 194 |  CA |  65 |  32 |  19 |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      D       | BE7 | 5F4 | 2FA | 17D |  BE |  5F |  30 |  18 |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      D#      | B3C | 59E | 2CF | 168 |  B4 |  5A |  2D |  16 |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      E       | A9B | 54E | 2A7 | 153 |  AA |  55 |  2A |  15 |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      F       | A02 | 501 | 281 | 140 |  A0 |  50 |  28 |  14 |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      F#      | 973 | 4BA | 25D | 12E |  97 |  4C |  26 |  13 |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      G       | 8EB | 476 | 23B | 11D |  8F |  47 |  24 |  12 |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      G#      | 88B | 436 | 21B | 10D |  87 |  43 |  22 |  11 |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      A       | 7F2 | 3F9 | 1FD |  FE |  7F |  40 |  20 |  10 |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      A#      | 780 | 3C0 | 1E0 |  F0 |  78 |  3C |  1E |   F |
|--------------+-----+-----+-----+-----+-----+-----+-----+-----|
|      B       | 714 | 38A | 1C5 |  E3 |  71 |  39 |  1C |   E |
----------------------------------------------------------------

Setting the noise frequency (R6)

The noise generator is used for synthesizing explosion sounds or wave sounds. The PSG can send the noise output by the noise generator to channels A to C. Since there is only one noise generator, the same noise is sent to all channels. By changing the average frequency, various noise effects can be obtained and this is done by R6 register settings. The 5 low order bit data (NP) of this register is divides into the standard frequency (fc/16) and this determines the average frequency of the noise (fn).

Figure 5.4 Setting the noise frequency
      -------------------------------------------------
R6    |  x     x     x  |                             |
      -------------------------------------------------
                        |                             |
                        +------------- NP ------------+

The following relation exists between NP and fn.

    fn = fc/(16 * NP)
       = 0.11186078125/NP [MHz]
       = 111860.78125/NP [Hz]

Since the value of NP is from 1 to 31, the average frequency of the noise can be set from 3.6kHz to 111.9kHz.

Mixing the sound (R7)

R7 is used to select the output of the tone and noise generator, or a mixture of both. As shown in Figure 5.5, the 3 low order bits (B0 to B2) of R7 control the tone output and the next 3 bits (B3 to B5) control the noise output. In both cases, when the corresponding bit is 0, the output is ON and, when 1, it is OFF.

Figure 5.5 Output selection for each channel
      -------------------------------------------------
R7    | B7  | B6  | B5  | B4  | B3  | B2  | B1  | B0  |
      -------------------------------------------------
                              |
                              |
                              V

    B7     B6             B5      B4      B3            B2      B1      B0
-----------------     -------------------------     -------------------------
| Input enable* |     |     Noise enable*     |     |     Tone enable*      |
|---------------|     |-----------------------|     |-----------------------|
|   B   |   A   |     |   C   |   B   |   A   |     |   C   |   B   |   A   |
-----------------     -------------------------     -------------------------
 I/O port              Noise output                  Tone output
   Input - 0             ON - 0                        ON - 0
   Output - 1            OFF - 1                       OFF - 1

The 2 high order bits of R7 do not affect sound output. These are used to determine the direction of the data of two I/O ports which PSG has. When the corresponding bit is 0, the input mode is selected and, when 0, the output mode is selected. In MSX, port A is used for the input and port B for the output, so it should always be set so that bit 6 = “0” and bit 7 = “1”.

Setting the volume (R8 to R10)

R8 to R10 are used to specify the volume of each channel. Two ways can be selected by these registers: specifying the fixed volume by 4-bit data (0 to 15) and generating sound effects such as vibrato or fade-out by using the envelope.

Figure 5.6 Setting the volume
               -------------------------------------------------
R8, R9, R10    |  x     x     x  | B4  | B3  | B2  | B1  | B0  |
               -------------------------------------------------
                                    |  |                       |
                                    |  +---------- L ----------+
                                    |
                                    V
                                  Use envelope:
                                    No  - 0 (set volume by the value of L)
                                    Yes - 1 (ignore the value of L)

When bit 4 of these registers is “0”, the envelope is not used and the 4 low order bit value L (0 to 15) of the registers specify the volume. When bit 4 is “1”, the volume depends on the envelope signals and the value L is ignored.

Setting the envelope cycle (R11, R12)

R11 and R12 specify the envelope cycle in 16-bit data. The 8 high order bits are set in R12 and the 8 low order bits are set in R11.

Figure 5.7 Setting the envelope cycle
           -------------------------------------------------
R11        |                                               | --+
           -------------------------------------------------   |
           -------------------------------------------------   |
R12        |                                               |   |
           -------------------------------------------------   |
                                               |               |
              ---------------------------------+               |
              |                                                |
              V                                                V
-----------------------------------------------------------------------------
|          Coarse Tune (CT)          |            Fine Tune (FT)            |
-----------------------------------------------------------------------------
|                                                                           |
+----------------------------------- EP ------------------------------------+

The following relation exists between the envelope cycle T and 16-bit data EP.

    T = (256 * EP) / fc
      = (256 * EP) / 1.787725 [MHz]
      = 143.03493  * EP [micro second]

Setting the envelope pattern (R13)

R13 sets the envelope pattern by the 4 low order bit data as shown in Figure 5.8. The intervals of T specified in the figure correspond to the envelope cycle specified by R11 and R12.

Figure 5.8 Setting the wave forms of the envelopes
            -------------------------------------------------
R13         |  x     x     x     x  | B3  | B2  | B1  | B0  |
            -------------------------------------------------
                                                |
            ------------------------------------+
            |
            V
---------------------------------------------------------
|                      |    :\                          |
|   0    0    x    x   |  __:  \______________________  |
|                      |                                |
|                      |      /:                        |
|   0    1    x    x   |  __/  :______________________  |
|                      |                                |
|                      |    :\  :\  :\  :\  :\  :\  :\  |
|   1    0    0    0   |  __:  \:  \:  \:  \:  \:  \:_  |
|                      |                                |
|                      |    :\                          |
|   1    0    0    1   |  __:  \______________________  |
|                      |                                |
|                      |    :\     / \     / \     / \  |
|   1    0    1    0   |  __:  \ /     \ /     \ /      |
|                      |         _____________________  |
|                      |    :\  :                       |
|   1    0    1    1   |  __:  \:                       |
|                      |                                |
|                      |      /:  /:  /:  /:  /:  /:    |
|   1    1    0    0   |  __/  :/  :/  :/  :/  :/  :/   |
|                      |        ______________________  |
|                      |      /                         |
|   1    1    0    1   |  __/                           |
|                      |                                |
|                      |      / \     / \     / \       |
|   1    1    1    0   |  __/     \ /     \ /     \ /   |
|                      |                                |
|                      |      /:                        |
|   1    1    1    1   |  __/  :______________________  |
|                      |                                |
---------------------------------------------------------
                           |   |
                           +---+
                             T

I/O port (R14, R15)

R14 and R15 are the ports to send and receive 8-bit data in parallel. MSX uses these as the general-purpose I/O interface. For more information, see section 5.

 

1.2 Access to the PSG

For access the PSG from assembly language programs, several BIOS routines described below are available.

 

GICINI (0090H/MAIN) - PSG initialization

Figure 5.9 Initial values of PSG registers
-----------------------------------------------------------------------------
|                       Bit |     |     |     |     |     |     |     |     |
|                           |  7  |  6  |  5  |  4  |  3  |  2  |  1  |  0  |
| Register                  |     |     |     |     |     |     |     |     |
|---------------------------+-----------------------------------------------|
|    R0    | Channel A      |  0     1     0     1     0     1     0     1  |
|----------|                |-----------------------------------------------|
|    R1    | frequency      |  0     0     0     0     0     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R2    | Channel B      |  0     0     0     0     0     0     0     0  |
|----------|                |-----------------------------------------------|
|    R3    | frequency      |  0     0     0     0     0     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R4    | Channel C      |  0     0     0     0     0     0     0     0  |
|----------|                |-----------------------------------------------|
|    R5    | frequency      |  0     0     0     0     0     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R6    | Noise frequency|  0     0     0     0     0     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R7    | Channel setting|  1     0     1     1     1     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R8    | Chan. A volume |  0     0     0     0     0     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R9    | Chan. B volume |  0     0     0     0     0     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R10   | Chan. C volume |  0     0     0     0     0     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R11   |                |  0     0     0     0     1     0     1     1  |
|----------| Envelope Cycle |-----------------------------------------------|
|    R12   |                |  0     0     0     0     0     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R13   | Env. pattern   |  0     0     0     0     0     0     0     0  |
|----------+----------------+-----------------------------------------------|
|    R14   | I/O port A     |                                               |
|----------+----------------+-----------------------------------------------|
|    R15   | I/O port B     |                                               |
-----------------------------------------------------------------------------

 

WRTPSG (0093H/MAIN) - writing data in PSG registers

 

RDPSG (0096H/MAIN) - reading PSG register data

 

STRTMS (0099H/MAIN) - starting the music

List 5.1 Single tone generation

;************************************************
;
;   List 5.1   440 Hz tone
;
;************************************************
;
WRTPSG  EQU     0093H

        ORG     0B000H

;----- program start -----

        LD      A,7             ;Select Channel
        LD      E,00111110B     ;Channel A Tone := On
        CALL    WRTPSG

        LD      A,8             ;Set Volume
        LD      E,10
        CALL    WRTPSG

        LD      A,0             ;Set Fine Tune Channel A
        LD      E,0FEH          ;Data 0FEH
        CALL    WRTPSG

        LD      A,1             ;Set Coarse Tune Channel A
        LD      E,0             ;Data 0H
        CALL    WRTPSG

        RET

        END

 

1.3 Tone Generation by 1-bit Sound Port

MSX has another sound generator in addition to the PSG. This is a simple one that generates sound by turning ON/OFF the 1-bit I/O port output repeatedly using software.

Figure 5.10 1-bit sound port
                bit    7    6    5    4    3    2    1    0
                     -----------------------------------------
                     | .  |    |    |    |    |    |    |    |
                     --+--------------------------------------
                       |    PPI port C (I/O address 0AAH)
                       |
                       |
::::::::::::           V
:   PSG    :       ---------
:  output  :::::::>|  MIX  |
::::::::::::       ---------
                       |
                       V
                     -----
                    /     \   Speaker
                   ---------
                     / : \

 

1.4 Access to 1-bit Sound Port

To access to the 1-bit sound port, the following BIOS routine is offered.

CHGSND (0135H/MAIN)

List 5.2 Reading from cassette tape
;********************************************************
;
;  List 5.2   Read from cassette tape
;
;            Set music tape into tape-recorder
;            and run this program.
;            Then your MSX will replay it.
;
;********************************************************
;
CHGSNG  EQU     0135H
STMOTR  EQU     00F3H
RDPSG   EQU     0096H
BREAKX  EQU     00B7H

        ORG     0B000H

;----- program start -----      Note:  Play tape using 1-bit sound port.

START:  LD      A,1             ;motor on
        CALL    STMOTR

LBL01:  LD      A,14            ;register 14
        CALL    RDPSG           ;read PSG

        AND     80H             ;check CSAR
        CALL    CHGSNG          ;change SOUND PORT

        CALL    BREAKX          ;check Ctrl-STOP
        JR      NC,LBL01

        XOR     A               ;stop cassette motor
        CALL    STMOTR
        RET

        END

 

2. CASSETTE INTERFACE

Cassette tape recorders are the least expensive external storage devices available for the MSX. Knowledge of the cassette interface is required to treat information in cassette tapes within assembly language programs. This section offers the necessary information.

 

2.1 Baud Rate

The following two baud rates can be used by the MSX cassette interface (see Table 5.2). When BASIC is invoked, 1200bps is set by default.

Table 5.2 MSX baud rate
------------------------------------------------
|  Baud rate  |        Characteristics         |
|-------------+--------------------------------|
|  1200 bps   |  Low speed / high reliability  |
|-------------+--------------------------------|
|  2400 bps   |  High speed / low reliability  |
------------------------------------------------

The baud rate is specified by the fourth parameter of the SCREEN instruction or the second parameter of the CSAVE instruction. Once the baud rate is set, it stays at that value.

SCREEN          ,,,<baud rate>
CSAVE           "filename",<baud rate>
                (<baud rate> is 1 for 1200bps, 2 for 2400 bps)

 

2.2 One bit composition

One bit data, the basis of I/O, is recorded as shown in Figure 5.11. The pulse width is determined by counting the T-STATE of the CPU, so, while the cassette interface is active, any interrupt is inhibited.

The bit data from the cassette can be read through the seventh bit of port B of the general-purpose I/O interface (register 15 of the PSG). This function was used in the program example of List 5.3, section 1 of chapter 5.

Figure 5.11 One bit composition
--------------------------------------------------------------
| Baud rate |  Bit  |                Wave form               |
|-----------+-------+----------------------------------------|
|           |       |  :         -----------                 |
|           |   0   |  :         |         |   (1200Hz x 1)  |
|    1200   |       |  :_________|         |                 |
|           |-------+--:-------------------------------------|
|    baud   |       |  :    ------    ------                 |
|           |   1   |  :    |    |    |    |   (2400Hz x 2)  |
|           |       |  :____|    |____|    |                 |
|-----------+-------+--:-------------------------------------|
|           |       |  :    ------         :                 |
|           |   0   |  :    |    |         :   (2400Hz x 1)  |
|    2400   |       |  :____|    |         :                 |
|           |-------+--:-------------------:-----------------|
|    baud   |       |  :  ---  ---         :                 |
|           |   1   |  :  | |  | |         :   (4800Hz x 2)  |
|           |       |  :__| |__| |         :                 |
-----------------------:--:-:----:---------:------------------
                       |  : :    :         |  2963 T-states (833 micro-sec)
                       +--:-:----:---------+
                       |  : :    |  1491 T-states (417 micro-sec)
                       +--:-:----+
                       |  : |  746 T-states (208 micro-sec)
                       +--:-+
                       |  |  373 T-states (104 micro-sec)
                       +--+

 

2.3 One byte composition

One byte data is recorded in the array of bits as shown in Figure 5.12. There is one “0” bit as the start bit, followed by the 8-bit data body from LSB to MSX and by two “1” bit as the stop bits, so 11 bits are used.

Figure 5.12 One byte composition
             LSB                                       MSB
  -------------------------------------------------------------------------
     |  0  |  X  |  X  |  X  |  X  |  X  |  X  |  X  |  X  |  1  :  1  |
  -------------------------------------------------------------------------
     |     |                                               |           |
     +-----+-----------------------------------------------+-----------+
    Start bit                     Data                        Stop bit

 

2.4 Header Composition

The header is the portion where the signal of the specific frequency is recorded on the tape for a certain period. This allows the cassette tape speed to stabilize after it is started, or divides two files. There is a long header and a short header. The long header is used to wait until the motor is stabilized. The baud rate at reading the tape is determined by reading the long header. The short header is used to divide file bodies. Table 5.3 shows the compositions of both.

Table 5.3 Header composition
------------------------------------------------------------------
|  Baud rate  |    Header    |        Header composition         |
|-------------+--------------+-----------------------------------|
|             | Long header  |  2400 Hz x 16000 (about 6.7 sec)  |
|  1200 baud  |--------------+-----------------------------------|
|             | Short header |  2400 Hz x  4000 (about 1.7 sec)  |
|-------------+--------------+-----------------------------------|
|             | Long header  |  4800 Hz x 32000 (about 6.7 sec)  |
|  2400 baud  |--------------+-----------------------------------|
|             | Short header |  4800 Hz x  8000 (about 1.7 sec)  |
------------------------------------------------------------------

 

2.5 File Formats

MSX BASIC supports the following three kinds of cassette format files.

(1) BASIC text file

BASIC programs saved with the CSAVE command are recorded in this format. The file is divided into the preceding file header and the succeeding the body.

Figure 5.13 Binary file format

          6.7 sec                10 bytes                 6 bytes
  -------------------------------------------------------------------------
     |               |                              |                  |
     |  Long header  |          0D3H x 10           |    File name     |
     |               |                              |                  |
  -------------------------------------------------------------------------
     |                                                                 |
     +----------+                 +------------------------------------+
                |                 |
-----------------------------------------------------------------------------
|               |   File header   |  |        File body         |           |
-----------------------------------------------------------------------------
                                     |                          |
     +-------------------------------+                          +------+
     |                                                                 |
  -------------------------------------\  \--------------------------------
     |  Short   |                      /  /      |                     |
     |  header  |     BASIC program    \  \      |       00H x 7       |
     |          |                      /  /      |                     |
  -------------------------------------\  \--------------------------------
       1.7 sec             Any length                    7 bytes

In the file header, ten bytes each of the value 0D3H follow after the long header and six bytes containing the file name are placed after them. In the file body, program body follows the short header and the end of the file is indicated by seven bytes of 00H.

(2) ASCII text file

BASIC programs saved in ASCII format by the SAVE command and data files created by the OPEN command are recorded in this format.

Figure 5.14 ASCII file format

          6.7 sec                10 bytes                 6 bytes
  -------------------------------------------------------------------------
     |               |                              |                  |
     |  Long header  |          0EAH x 10           |    File name     |
     |               |                              |                  |
  -------------------------------------------------------------------------
     |                                                                 |
     +----------+                 +------------------------------------+
                |                 |
-----------------------------------------------------------------------------
|               |   File header   |  |        File body         |           |
-----------------------------------------------------------------------------
                                     |                          |
     +-------------------------------+                          +------+
     |                                                                 |
  -----------------------------------------------\  \----------------------
     |           |           |           |       /  /      |   Last    |
     |  Block 1  |  Block 2  |  Block 3  | ..... \  \ .... |   block   |
     |           |           |           |       /  /      |     .     |
  -----------------------------------------------\  \------------+---------
                 |           |                                   |
     +-----------+           +-----------+                  CTRL+Z (EOF)
     |                                   |              is included in data
  ------------------------------------------------
     |  Short   |                        |
     |  header  |          Data          | .....
     |          |                        |
  ------------------------------------------------
       1.7 sec         256 bytes

(3) Machine code file

Machine code files saved by the BSAVE command are recorded in the following format. In the file header, 10 bytes each of the value 0D0H follow after the long header and 6 bytes containing the file name are placed after them.

In the file body, the starting address, the end address, and the entry address are recorded in order after the short header, and the machine codes follow after them. Since the amount of data can be calculated from the starting and ending addresses, there is no special mark for the end of the file. The entry address is the address where the program is executed when the R option of the BLOAD command is used.

Figure 5.15 Machine code file format
          6.7 sec                10 bytes                 6 bytes
  -------------------------------------------------------------------------
     |               |                              |                  |
     |  Long header  |          0D0H x 10           |    File name     |
     |               |                              |                  |
  -------------------------------------------------------------------------
     |                                                                 |
     +----------+                 +------------------------------------+
                |                 |
-----------------------------------------------------------------------------
|               |   File header   |  |        File body         |           |
-----------------------------------------------------------------------------
                                     |                          |
     +-------------------------------+                          +------+
     |                                                                 |
  -------------------------------------------------------------------------
     |  Short   |   Top    |   End    | Starting |                     |
     |  header  | address  | address  | address  |    Program body     |
     |          |          |          |          |                     |
  -------------------------------------------------------------------------
       1.7 sec    2 bytes    2 bytes    2 bytes

 

2.6 Access to cassette files

The following BIOS routines are offered to access cassette files.

 

TAPION (00E1H/MAIN) - OPEN for read

 

TAPIN (00E4H/MAIN) - read one byte

 

TAPIOF (00E7H/MAIN) - CLOSE for read

 

TAPOON (00EAH/MAIN) - OPEN for write

 

TAPOUT (00EDH/MAIN) - write one byte

 

TAPOOF (00F0H/MAIN) - CLOSE writing

 

STMOTR (00F3/MAIN) - specify the actions of the motor

When READ/WRITE routines for the cassette files are created using these BIOS calls, only READ or WRITE, without any other action, should be done. For example, reading data from the tape and displaying it on the CRT might cause a READ error.

List 5.3 is a sample program which uses BIOS routines.

List 5.3 Listing names of files saved in the cassette
;************************************************************
;
;  List 5.3      Cassette files
;
;       Set cassette tape into recorder and run this program.
;       Then all the names and attributes of the programs
;       in that tape will be listed.
;
;************************************************************
;
CHPUT   EQU     00A2H
TAPION  EQU     00E1H
TAPIN   EQU     00E4H
TAPIOF  EQU     00E7H

        ORG     0C000H

;----- program start -----      Note:  View program names on cassette tape.

START:  CALL    TAPION          ;motor on and read header

        LD      B,16
        LD      HL,WORK         ;work area address
LBL01:  PUSH    HL
        PUSH    BC
        CALL    TAPIN           ;read a byte of data from tape
        POP     BC
        POP     HL
        JR      C,ERROR         ;set carry flag if read error
        LD      (HL),A
        INC     HL
        DJNZ    LBL01

        LD      HL,FILNAM       ;write file name
        CALL    PUTSTR
        LD      HL,WORK+10
        CALL    PUTSTR
        CALL    CRLF

        LD      A,(WORK)        ;check file attributes

        LD      HL,BINFIL
        CP      0D3H            ;check binary file
        JR      Z,LBL03

        LD      HL,ASCFIL
        CP      0EAH            ;check ascii file
        JR      Z,LBL03

        LD      HL,MACFIL
        CP      0D0H            ;check machine code file
        JR      Z,LBL03

ERROR:  LD      HL,ERRSTR

LBL03:  CALL    PUTSTR
        CALL    TAPIOF
        RET

;----- put CRLF -----

CRLF:   LD      HL,STCRLF
        CALL    PUTSTR
        RET

;----- put string -----

PUTSTR: LD      A,(HL)          ;get a character from strings
        CP      '$'             ;check end of strings
        RET     Z
        CALL    CHPUT           ;write a character to CRT
        INC     HL
        JR      PUTSTR

;----- strings data -----

FILNAM: DB      'FILE NAME :$'
ASCFIL: DB      'ASCII FILE',0DH,0AH,'$'
BINFIL: DB      'BINARY FILE',0DH,0Ah,'$'
MACFIL: DB      'BSAVE FILE',0DH,0AH,'$'
ERRSTR: DB      'TAPE READ ERROR',0DH,0AH,'$'
STCRLF: DB      0DH,0AH,'$'

;----- WORK AREA -----

WORK:   DS      16,0
        DB      '$'             ;end of strings

        END

 

3. KEYBOARD INTERFACE

Altough the MSX2 keyboard has the same design as that of the MSX1, it is more convenient to use because of the Romand-to-kana translation available for kana input. This section describes the keyboard interface of the MSX2.

Descriptions of the key aarangement are based on the Japanese keyboard standard; note that data is slightly different for the international MSX versions.

 

3.1 Key Scanning

MSX uses the key matrices as shown in Figure 5.16, Figure 5.17 and Figure 5.17B. The key status can be obtained in real time by examining this key matrix and is available for reading input.

Scanning the key matrix is done by the following BIOS routine.

SNSMAT (0141H/MAIN) - reads the specified line of the key matrix

Figure 5.16 MSX USA version key matrix
MSB                                                                    LSB
        7       6       5       4       3       2       1       0
    -----------------------------------------------------------------
 0  |   B   |   L   |       |   /   |   1   |   S   |   X   |   ,   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 1  |   V   |   J   |   =   |   `   |   Q   |   A   |   C   |   N   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 2  |   G   |   8   |   0   |   ]   |   W   |   F   |   Z   |   M   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 3  |   T   |   I   |   ~   |   ;   |   2   |   D   |   U   |   \   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 4  |   6   |   K   |   P   |   '   |   3   |   R   |   7   |   H   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 5  |   5   |   0   |   9   |   [   |   4   |   E   |   Y   |   .   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 6  |   F3  |   F2  |   F1  | CODE  | CAPS  | GRAPH | CTRL  | SHIFT |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 7  | RETURN| SELECT|   BS  | STOP  |  TAB  |  ESC  |   F5  |   F4  |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 8  | RIGHT | DOWN  |   UP  | LEFT  |  DEL  |  INS  | HOME  | SPACE |
    -----------------------------------------------------------------

    [TEN KEY]
    -----------------------------------------------------------------
 9  |   4   |   3   |   2   |   1   |   0   | option| option| option|
    |-------+-------+-------+-------+-------+-------+-------+-------|
10  |   .   |   ,   |   -   |   9   |   8   |   7   |   6   |   5   |
    -----------------------------------------------------------------
Figure 5.17 MSX International version key matrix
MSB                                                                    LSB
        7       6       5       4       3       2       1       0
    -----------------------------------------------------------------
 0  |   B   |   L   |deadkey|   /   |   1   |   S   |   X   |   ,   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 1  |   V   |   J   |   ^   |   ]   |   Q   |   A   |   C   |   N   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 2  |   G   |   8   |   0   |   [   |   W   |   F   |   Z   |   M   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 3  |   T   |   I   |   ~   |   ;   |   2   |   D   |   U   |   \   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 4  |   6   |   K   |   P   |   :   |   3   |   R   |   7   |   H   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 5  |   5   |   0   |   9   |   @   |   4   |   E   |   Y   |   .   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 6  |   F3  |   F2  |   F1  | CODE  | CAPS  | GRAPH | CTRL  | SHIFT |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 7  | RETURN| SELECT|   BS  | STOP  |  TAB  |  ESC  |   F5  |   F4  |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 8  | RIGHT | DOWN  |   UP  | LEFT  |  DEL  |  INS  | HOME  | SPACE |
    -----------------------------------------------------------------

    [TEN KEY]
    -----------------------------------------------------------------
 9  |   4   |   3   |   2   |   1   |   0   | option| option| option|
    |-------+-------+-------+-------+-------+-------+-------+-------|
10  |   .   |   ,   |   -   |   9   |   8   |   7   |   6   |   5   |
    -----------------------------------------------------------------
Figure 5.17B MSX European version key matrix
MSB                                                                    LSB
        7       6       5       4       3       2       1       0
    -----------------------------------------------------------------
 0  |   7   |   6   |   5   |   4   |   3   |   2   |   1   |   0   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 1  |   ;   |   ]   |   [   |   \   |   =   |   -   |   9   |   8   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 2  |   B   |   A   | accent|   /   |   .   |   ,   |   `   |   '   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 3  |   J   |   I   |   H   |   G   |   F   |   E   |   D   |   C   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 4  |   R   |   Q   |   P   |   O   |   N   |   M   |   L   |   K   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 5  |   Z   |   Y   |   X   |   W   |   V   |   U   |   T   |   S   |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 6  |   F3  |   F2  |   F1  | CODE  | CAPS  | GRAPH | CTRL  | SHIFT |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 7  | RETURN| SELECT|   BS  | STOP  |  TAB  |  ESC  |   F5  |   F4  |
    |-------+-------+-------+-------+-------+-------+-------+-------|
 8  | RIGHT | DOWN  |   UP  | LEFT  |  DEL  |  INS  | HOME  | SPACE |
    -----------------------------------------------------------------

    [TEN KEY]
    -----------------------------------------------------------------
 9  |   4   |   3   |   2   |   1   |   0   | option| option| option|
    |-------+-------+-------+-------+-------+-------+-------+-------|
10  |   .   |   ,   |   -   |   9   |   8   |   7   |   6   |   5   |
    -----------------------------------------------------------------
List 5.4 Use of the key scanning routine
;********************************************************
;
;  List 5.4   scan key-matrix and display it
;
;********************************************************
;
CHPUT   EQU     00A2H
BREAKX  EQU     00B7H
POSIT   EQU     00C6H
SNSMAT  EQU     0141H

        ORG     0B000H

;----- program start -----      Note:  read key matrix and display key
                                       pattern.

SCAN:   LD      C,0             ;C := line of key matrix

SC1:    LD      A,C
        CALL    SNSMAT          ;Read key matrix

        LD      B,8
        LD      HL,BUF          ;HL : = buffer address
SC2:    LD      D,'.'
        RLA                     ;Check bit
        JR      C,SC3
        LD      D,'#'

SC3:    LD      (HL),D          ;store '.' or '#' to buffer
        INC     HL
        DJNZ    SC2

        LD      H,05H           ;x := 5
        LD      L,C             ;y := C+1
        INC     L
        CALL    POSIT           ;set cursor position

        LD      B,8             ;put out bit patterns to CRT
        LD      HL,BUF
SC4:    LD      A,(HL)
        CALL    CHPUT
        INC     HL
        DJNZ    SC4

        CALL    BREAKX          ;check Ctrl-STOP
        RET     C

        INC     C               ;line No. increment
        LD      A,C
        CP      09
        JR      NZ,SC1
        JR      SCAN

;----- work area -----

BUF:    DS      8

        END

 

3.2 Character Input

MSX scans the key matrix every 1/60 second using the timer interrupt and, when a key is pressed, stores the character code in the keyboard buffer as shown in Figure 5.18. Key input to MSX is generally done by reading this keyboard buffer.

Figure 5.18 Keyboard ring buffer
+----------------------------------<----------------------------------------+
|                             KEYBUF (FBF0H, 40)                            |
| --------------------------------------/ /-------------------------------- |
+>|  D  |  E  |  F  |  G  |     |     | \ \ |     |     |  A  |  B  |  C  |-+
  --------------------------------------/ /--------------------------------
                             ^                             ^
                             |                             |
                          [PUTPNT]                      [GETPNT]

GETPNT (F3FAH, 2) points to the next character to be obtained in CHGET routine.

PUTPNT (F3F8H, 2) points to the next location for the character to be put when the keyboard is pressed next time.

BIOS routines having functions for key input using this keyboard buffer and functions related to it are described below. Inhibiting the timer interrupt renders them useless, of course.

 

CHSNS (009CH/MAIN) - checks the keyboard buffer

 

CHGET (009FH/MAIN) - one character input from the keyboard buffer

Work area:

 

KILBUF (0156H/MAIN) - empty the keyboard buffer

List 5.5 Use of one character input routine
;********************************************************
;
;   List 5.5    get key code
;
;               this routine doesn't wait for key hit
;
;********************************************************
;
CHSNS   EQU     009CH           ;check keyboard buffer
CHGET   EQU     009FH           ;get a character from buffer
CHPUT   EQU     00A2H           ;put a character to screen
BREAKX  EQU     00B7H           ;check Ctrl-STOP
KILBUF  EQU     0156H           ;clear keyboard buffer
REPCNT  EQU     0F3F7H          ;time interval until key-repeat
KEYBUF  EQU     0FBF0H          ;keyboard buffer address

        ORG     0B000H

;----- prgram start -----       Note:  Real-time input using CHGET

KEY:    CALL    CHSNS           ;check keyboard buffer
        JR      C,KEY1

        LD      A,1
        LD      (REPCNT),A      ;not to wait until repeat
        CALL    CHGET           ;get a character (if exists)
        JR      KEY2

KEY1:   LD      A,'-'           ;A := '-'

KEY2:   CALL    CHPUT           ;put the character
        CALL    KILBUF          ;clear keyboard buffer
        CALL    BREAKX          ;check Ctrl-STOP
        JR      NC,KEY

        END

 

CNVRCHR (00AB/MAIN) - graphic character operation

Figure 5.19 Graphic character translation chart
-------------------------------------------------------------
|    Before    |    After     |    Before    |    After     |
|  conversion  |  conversion  |  conversion  |  conversion  |
|-----------------------------+-----------------------------|
|                             |    0150H    -->     50H     |
|    0141H    -->     41H     |    0151H    -->     51H     |
|    0142H    -->     42H     |    0152H    -->     52H     |
|    0143H    -->     43H     |    0153H    -->     53H     |
|    0144H    -->     44H     |    0154H    -->     54H     |
|    0145H    -->     45H     |    0155H    -->     55H     |
|    0146H    -->     46H     |    0156H    -->     56H     |
|    0147H    -->     47H     |    0157H    -->     57H     |
|    0148H    -->     48H     |    0158H    -->     58H     |
|    0149H    -->     49H     |    0159H    -->     59H     |
|    014AH    -->     4AH     |    015AH    -->     5AH     |
|    014BH    -->     4BH     |    015BH    -->     5BH     |
|    014CH    -->     4CH     |    015CH    -->     5CH     |
|    014DH    -->     4DH     |    015DH    -->     5DH     |
|    014EH    -->     4EH     |    015EH    -->     5EH     |
|    014FH    -->     4FH     |    015FH    -->     5FH     |
-------------------------------------------------------------

 

PINLIN (00AEH/MAIN) - one line input

Work area:

 

INLIN (00B1H/MAIN) - one line input (prompt available)

List 5.6 Difference between INLIN and PINLIN
;************************************************
;
;  List 5.6   INLIN and PINLIN
;
;************************************************
;
CHPUT   EQU     00A2H
INLIN   EQU     00B1H
PINLIN  EQU     00AEH
KILBUF  EQU     0156H

BUF     EQU     F55EH

        ORG     0B000H

;----- program start -----

        LD      HL,PRMPT1
        CALL    PUTMSG          ;put prompt message
        CALL    INLIN           ;use INLIN routine
        LD      HL,BUF
        CALL    PUTMSG

        LD      HL,PRMPT2
        CALL    PUTMSG          ;put prompt message
        CALL    PINLIN          ;use PINLIN routine
        LD      HL,BUF
        CALL    PUTMSG

        RET

;----- put a string -----

PUTMSG: LD      A,(HL)
        CP      '$'
        RET     Z
        CALL    CHPUT
        INC     HL
        JR      PUTMSG

;----- string data -----

PRMPT1: DB      0DH,0AH,'INLIN:$'
PRMPT2: DB      0DH,0AH,'PINLIN:$'

        END

 

3.3 Function Keys

MSX has ten function keys, which can be defined by the user at will. A 16 byte work area is allocated for the definition of each key. The following list shows their addresses.

Pressing a function key causes the string defined in that key to be stored in [KEYBUF]. The end of the string is indicated by 00H and a maximum of 15 keystrokes can be defined for one function key (definitions longer than 16 keystrokes are defined over more than one function key definition area). To restore the initial settings of the function keys, use the following BIOS routine.

INIFNK (003EH/MAIN) - initialize function keys

 

3.4 STOP Key During Interrupts

CHGET, the one-character input routine described in 3.3, determines the pressed key in the timer interrupt routine. Thus, when the timer interrupt is inhibited, such as during cassette data I/O, pressed keys cannot be detected. By using the BIOS routine described below, the CTRL key + STOP key combination can be detected even when interrupts are inhibited.

BREAKX (00B7H/MAIN) - CTRL + STOP detection

 

4. PRINTER INTERFACE

This section describes how to access the MSX printer interface from assembly language. The information described here is helpful if the printer is going to be used to print bit image graphics.

 

4.1 Print Interface Overview

The printer interface is supported by BIOS and BASIC. MSX drives the printer through an 8-bit parallel output port and uses a handshaking method with BUSY and STROBE signals. The standard connector is also defined (Amphenol 14-pin, female side to the machine). Figure 5.20 shows the signal lines.

Figure 5.20 Printer interface
                 Printer interface pin connections

-------------------------------------------------------------------
 \          -------------------------------------------          /
  \         | (7) | (6) | (5) | (4) | (3) | (2) | (1) |         /
   \    ---------------------------------------------------    /
    \   |                                                 |   /
     \  ---------------------------------------------------  /
      \     | (14)| (13)| (12)| (11)| (11)| (10)| (9) |     /
       \    -------------------------------------------    /
        ---------------------------------------------------

(1) ........... STROBE*
(2) to (9) .... Data (b0 to b7)
(11) .......... BUSY
(14) .......... BGND

                            -------------------------------------------------
I/O port (91H)              |  X  |  X  |  X  |  X  |  X  |  X  |  X  |  X  |
                            -------------------------------------------------
                                                   Data

                            -------------------------------------------------
I/O port (90H; at WRITE)    |  .  |  .  |  .  |  .  |  .  |  .  |  .  |  X  |
                            -------------------------------------------------
                                                                         ^
                                                                         |
                                        STROBE* (send data when "0") ----+

                            -------------------------------------------------
I/O port (90H; at READ)     |  .  |  .  |  .  |  .  |  .  |  .  |  X  |  .  |
                            -------------------------------------------------
                                                                   ^
                                               0: Printer READY    |
                                                                ---+
                                               1: Printer BUSY

 

4.2 Output to the MSX Standard Printer

If data is sent from MSX to the printer, the action depends on whether the printer receiving the data is of the MSX standard. The use of MSX standard printers is described in this section. Descriptions about other printers are in the next section.

An MSX standard printer can print any character that can be displayed on the screen. Special graphic characters corresponding to character codes n = 01H to 1FH can be also printed by sending the code 40H + n after the graphic character header (01H). In addition to these, the control codes shown in Table 5.4 can be used with MSX standard printers (see the manual of the printer for controlling a printer which has other functions such as printing Chinese characters).

To feed lines in MSX standard printers, send 0DH and 0AH successively. To print the bit image, send nnnn bytes data, where nnnn means four decimal figures, after the escape sequence ESC + “Snnnn”. Note that, MSX has a function to transform the tab code (09H) to the adequate number of space codes (20H) for printers not having a tab function. This transformation is normally done. To print a bit image which includes the value 09H correctly, change the following work area.

Table 5.4 Control codes of the printer
-----------------------------------------------------------------------------
|      code       |                        function                         |
|-----------------+---------------------------------------------------------|
| 0AH             |  line feed                                              |
|-----------------+---------------------------------------------------------|
| 0CH             |  form feed                                              |
|-----------------+---------------------------------------------------------|
| 0DH             |  carriage return                                        |
|-----------------+---------------------------------------------------------|
| ESC + "A"       |  normal line spacing                                    |
|                 |  (spaces between lines; characters are read easily)     |
|-----------------+---------------------------------------------------------|
| ESC + "B"       |  line spacing for graphics (no space between lines)     |
|-----------------+---------------------------------------------------------|
| ESC + "Snnnn"   |  bit image printing                                     |
-----------------------------------------------------------------------------

 

4.3 Access to the printer

To send output to the printer, the following BIOS routines are offered.

 

LPTOUT (00A5H/MAIN)

 

LPTSTT (00A8/MAIN)

 

OUTDLP (014DH,MAIN)

 

5. UNIVERSAL I/O INTERFACE

As described in section 1, the PSG used by MSX has two 8-bit I/O ports, port A and port B, in addition to the sound output function. In MSX, these two ports are connected to the universal I/O interface (joystick port) and are used to exchange data with the joystick or the paddle (see Figure 5.21). Various devices to be connected to this universal I/O interface have the necessary BIOS routine in ROM, so they are easily accessbile.

In this section, the funtion of each I/O device and the method for accessing with BIOS routines are described.

Figure 5.21 Universal I/O interface
   Universal input/output interface -1
-----------------------------------------
|                                       |
|  (1)     (2)     (3)     (4)     (5) -+- +5V         Switching signal <---+
|   |  (6)  |  (7)  |  (8)  |  (9) -----+- GND          (to port B:b6)      |
|   |   |   |   |   |   |   |           |                                   |
----:---:---:---:---:---:---:------------                                   |
    |   |   |   |   |   |   |                                               |
    |   |   |   |   |   +---:--> To port B:b4    -------------------------  |
    |   |   |   |   |       |                    |                       |  |
    +---+---+---+---+-------+--------------------|                       |  |
                                                 |       Switcher        |--+
    +---+---+---+---+-------+--------------------|                       |
    |   |   |   |   |       |                    |                       |
    |   |   |   |   |   +---:--> To port B:b5    -------------------------
    |   |   |   |   |   |   |                      |   |   |   |   |   |
----:---:---:---:---:---:---:------------         (1) (2) (3) (4) (6) (7)
|   |   |   |   |   |   |   |           |       |  |   |   |   |   |   |  |
|  (1)     (2)     (3)     (4)     (5) -+- +5V  +-------------------------+
|      (6)     (7)     (8)     (9) -----+- GND               |
|                                       |                    V
-----------------------------------------            To port A:b0 to b5
   Universal input/output interface -2

 

5.1 Functions of the Ports

Two I/O ports of PSG are used as shown in Figure 5.22.

Figure 5.22 (A) Functions of PSG port A
Port A (PSG#14)
-------------------------------------------------
| b7  |  .  | b5  : b4  : b3  : b2  : b1  : b0  |
-------------------------------------------------
   |           |     |     |     |     |     |                 --+
   |           |     |     |     |     |     +--> 1st terminal   | connected
   |           |     |     |     |     +--------> 2nd terminal   |    to
   |           |     |     |     +--------------> 3rd terminal   | universal
   |           |     |     +--------------------> 4th terminal   |    I/O
   |           |     +--------------------------> 6th terminal   | interface
   |           +--------------------------------> 7th terminal   |
   |                                                           --+
   +-----------------------------------> Data input from the cassette tape
Figure 5.22 (B) Functions of PSG port B
Port B (PSG#15)
-------------------------------------------------
| b7  | b6  | b5  | b4  | b3  | b2  | b1  | b0  |
-------------------------------------------------
   |     |     |     |     |     |     |     |
   |     |     |     |     +-----+-----+-----+--> Unused
   |     |     |     |
   |     |     |     +---> Connected to 8th terminal of univ. I/O interface 1
   |     |     +---------> Connected to 8th terminal of univ. I/O interface 2
   |     |
   |     +---> 0: b0-b5 of port A to be connected to univ. I/O interface 1
   |           1: b0-b5 of port A to be connected to univ. I/O interface 2
   |
   +---------> 0: Arabic or kana mode display lamp on
               1: Arabic or kana mode display lamp off

 

5.2 Joystick Use

Figure 5.23 shows the joystick circuit. As the circuit shows, sending “0” to the 8th terminal and reading the 1st to 4th and 6th to 7th terminals enable information about the stick and the trigger buttons to be obtained. However, it is advisable to use BIOS for accessing the joystick, in order to give portability to the program.

Figure 5.23 Joystick circuit
                          \
(1)     O---------------o  o------------+ ............. Front
                                        |
                          \             |
(2)     O---------------o  o------------+ ............. Back
                                        |
                          \             |
(3)     O---------------o  o------------+ ............. Left
                                        |
                          \             |
(4)     O---------------o  o------------+ ............. Right
                                        |
                                        |
                          \             |
(6)     O---------------o  o------------+ ............. Trigger A
                                        |
                          \             |
(7)     O---------------o  o------------+ ............. Trigger B
                                        |
                                        |
(8)     O-------------------------------+

The following BIOS routines are offered for accessing the joystick. These routines have similar functions to the STICK function and STRIG function of BASIC. The status of the cursor keys or the space bar, in addition to the joystick, can be read in real time.

 

GTSTCK (00D5H/MAIN) - read joystick

 

GTTRIG (00D8H/MAIN) - read trigger button

List 5.7 Joystick use
;************************************************
;
; List 5.7  Joystick and trigger access
;
;************************************************
;
CHPUT   EQU     00A2H
BREAKX  EQU     00B7H
GTSTCK  EQU     00D5H
GTTRIG  EQU     00D8H

        ORG     0D00H

;----- program start -----      Note: display joystick status

STICK:  LD      A,1             ;choose joystick 1
        CALL    GTSTCK          ;read joystick status
        LD      (WK1),A
        LD      A,1             ;choose joystick 1
        CALL    GTTRIG          ;read trigger status

        OR      A
        JR      Z,STCK1
        LD      HL,WDON         ;trigger ON
        JR      STCK2
STCK1:  LD      HL,WDOFF        ;trigger OFF
STCK2:  CALL    PUTSTR
        LD      A,(WK1)

        OR      A
        JR      Z,BRKCH0        ;do not use joystick
        LD      C,0
STCK3:  DEC     A
        JR      NZ,STCK4
        INC     C
        JR      STCK3

STCK4:  SLA     C               ;C := C*16
        SLA     C
        SLA     C
        SLA     C
        LD      B,0             ;Accounting Strings data address
        LD      HL,WDSTK
        ADD     HL,BC
        CALL    PUTSTR

BRKCH0: LD      A,0DH           ;put carriage return
        CALL    CHPUT           ;code := 0DH

BRKCHK: CALL    BREAKX          ;break check
        RET     C
        JR      STICK

;----- put strings to screen -----

PUTSTR: LD      A,(HL)
        CP      '$'
        RET     Z
        INC     HL
        CALL    CHPUT
        JR      PUTSTR

;----- string area -----

WDON:   DB      'Trigger ON:  $'
WDOFF:  DB      'Trigger OFF: $'
WDSTK:  DB      'UP only      ',0DH,0AH,'$'
        DB      'Up and Right ',0DH,0AH,'$'
        DB      'Right only   ',0DH,0AH,'$'
        DB      'Right & Down ',0DH,0AH,'$'
        DB      'Down only    ',0DH,0AH,'$'
        DB      'Down and Left',0DH,0AH,'$'
        DB      'Left only    ',0DH,0AH,'$'
        DB      'Left and Up  ',0DH,0AH,'$'

WK1:    DW      0

        END

 

5.3 Paddle Use

Figure 5.24 shows the paddle circuit. Sending a pulse to the 8th terminal causes the single stable multi-vibrator to generate a pulse with a specified interval. This interval depends on the value of the variable register which can range from 10 to 3000 microseconds (0.01 to 3.00 ms). Measuring the pulse length enables the value in the variable register and the turning angle to be obtained.

Figure 5.24 Paddle circuit
                              --+--
                                |
                               <_
                                _>  150KOhm Variable Resistor
                               <
                                |
                      0.04 uF   |
                       +--| |---+
                       |        |
                    ---+--------+---
                    |              |
         |\         |              |
         |  \       |              |
(8) -----|   >O----O| A          Q |------------- (1)  (For 2, 3, 4, 6, or 7,
         |  /       |              |                    a similar circuit
         |/         |              |                    would apply)
                    |              |
                    |              |
         +----------| B            |
         |          |              |
         |          |              | (One-shot trigger IC, LS123 compatible)
         |          |              |
 +5V     |          ----------------
 --+--   |                 O
   |     |                 |
   +-----+-----------------+

                        ____
                        :  :
Input to 8      ________:  :_____________________________________

                        _________________________________
                        :                               :
Output to 1     ________:                               :________
                        |<------- 10 us to 3 ms ------->|

BIOS routines for accessing the paddle are described below.

GTPDL (00DEH/MAIN) - read paddle information

 

5.4 Use of Touch Panel, Light Pen, Mouse, and Track Ball

The touch panel, light pen, mouse, and track ball (cat) are accessible using the same BIOS routine. This routine is described below.

GTPAD (00DBH/MAIN) - access to various I/O devices

Table 5.5 GTPAD BIOS Function
--------------------------------------------------------------------------
|  Device ID  |  Device specified  |         Information returned        |
--------------+--------------------+-------------------------------------|
|      0      |                    |  0FFH when touching panel surface,  |
|             |                    |  00H when not                       |
|-------------|                    |-------------------------------------|
|      1      |                    |  X-coordinate (0 to 255)            |
|-------------|   Touch panel 1    |-------------------------------------|
|      2      |                    |  Y-coordinate (0 to 255)            |
|-------------|                    |-------------------------------------|
|      3      |                    |  0FFH when button is pressed,       |
|             |                    |  00H when not                       |
|-------------+--------------------+-------------------------------------|
|      4      |                    |                                     |
|-------------|                    |                                     |
|      5      |                    |                                     |
|-------------|   Touch panel 2    |  Same as above                      |
|      6      |                    |                                     |
|-------------|                    |                                     |
|      7      |                    |                                     |
|-------------+--------------------+-------------------------------------|
|      8      |                    |  0FFH: valid data,                  |
|             |                    |  00H: invalid data                  |
|-------------|                    |-------------------------------------|
|      9      |                    |  X-coordinate (0 to 255)            |
|-------------|   Light pen        |-------------------------------------|
|     10      |                    |  Y-coordinate (0 to 255)            |
|-------------|                    |-------------------------------------|
|     11      |                    |  0FFH when switch is pressed,       |
|             |                    |  00H when not                       |
|-------------+--------------------+-------------------------------------|
|     12      |                    |  Always 0FFH                        |
|             |                    |  (used to request for input)        |
|-------------|                    |-------------------------------------|
|     13      |   Mouse 1 or       |  X-coordinate (0 to 255)            |
|-------------|   track ball 1     |-------------------------------------|
|     14      |                    |  Y-coordinate (0 to 255)            |
|-------------|                    |-------------------------------------|
|     15      |                    |  Always 00H                         |
|             |                    |  (no meaning)                       |
|-------------+--------------------+-------------------------------------|
|     16      |                    |                                     |
|-------------|                    |                                     |
|     17      |   Mouse 2 or       |                                     |
|-------------|   track ball 2     |  Same as above                      |
|     18      |                    |                                     |
|-------------|                    |                                     |
|     19      |                    |                                     |
--------------------------------------------------------------------------

Note 1: Though information of the coordinate of the light pen (A = 9, 10) and the switch (A = 11) are read at the same time when BIOS is called with A = 8, other values are valid only when the result is 0FFH. In the case that the result of BIOS which is called with A = 8 is 00H, the coordinate values and the status of the switch contained after that are meaningless.

Note 2: Mouse and track ball are automatically distinguished.

Note 3: To obtain the coordinate value of the mouse or the track ball, do the input request call (A = 12 or A = 16), then execute the call to obtain the coordinate value actually. In this case, the interval of these two calls must be minimized as possible. Too much interval between the input request and the coordinate input causes the obtained data to be unreliable.

Note 4: To obtain the status of the trigger button of the mouse or the trigger button of the track ball, use GTTRIG (00D8H/MAIN), not GTPAD routine.

List 5.8 Touch panel use
;************************************************
;
;  List 5.8   touch pad access
;
;************************************************
;
BREAKX  EQU     00B7H
GTPAD   EQU     00D8H
WRTVRM  EQU     004DH

        ORG     0B000H

;----- program start -----      Note:  Displays "*" at position specified
                                       by touch pad.

PAD:    XOR     A               ;check sense
        CALL    GTPAD
        OR      A
        JR      NZ,PAD1
        LD      A,3
        CALL    GTPAD           ;break check
        OR      A
        RET     NZ
        JR      PAD

PAD1:   LD      A,1             ;get X axis
        CALL    GTPAD
        SRL     A               ;A := A/8
        SRL     A
        SRL     A
        LD      (WORK),A        ;reserve X axis
        LD      A,2             ;get Y axis
        CALL    GTPAD
        LD      L,A             ;HL := Y data (0-255)
        LD      H,0
        LD      C,A
        LD      B,0
        ADD     HL,BC           ;HL := HL*3 (HL := 0-767)
        ADD     HL,BC
        LD      A,L
        AND     11100000B
        LD      L,A
        LD      A,(WORK)
        ADD     A,L
        LD      L,A
        LD      BC,1800H        ;VRAM start address
        ADD     HL,BC
        LD      A,2AH
        CALL    WRTVRM          ;write VRAM
        LD      A,3
        CALL    GTPAD           ;break check
        OR      A
        RET     NZ
        JR      PAD

;----- work area -----

WORK:   DW      0               ;work

        END
List 5.9 Mouse and track ball use
;************************************************
;
;  List 5.9   mouse and track ball access
;
;************************************************
;
GTPAD   EQU     00DBH
WRTVRM  EQU     004DH
RDVRM   EQU     004AH
BREAKX  EQU     00B7H

        ORG     0D000H

;----- program start -----      Note:  Displays "*" at position specified
                                       by mouse or track ball.

TEST:   CALL    VADR            ;Put old data
        LD      A,(WKOLD)
        CALL    WRTVRM
        LD      A,12
        CALL    GTPAD           ;Request mouse/track ball data
        LD      A,13
        CALL    GTPAD           ;Read X val.
        LD      (WKXVAL),A
        LD      A,14
        CALL    GTPAD           ;Read Y val.
        LD      (WKYVAL),A

        LD      A,(WKX)
        LD      B,A
        LD      A,(WKXVAL)
        ADD     A,B
        CP      245             ;X<0?
        JR      C,TEST01
        XOR     A               ;X=0
        JR      TEST02

TEST01: CP      32              ;X>31?
        JR      C,TEST02
        LD      A,31

TEST02: LD      (WKX),A

        LD      A,(WKY)
        LD      B,A
        LD      A,(WKYVAL)
        ADD     A,B
        CP      245             ;Y<0?
        JR      C,TEST03
        XOR     A               ;Y=0
        JR      TEST04

TEST03: CP      24              ;Y>23?
        JR      C,TEST04
        LD      A,23

TEST04: LD      (WKY),A

        CALL    VADR
        CALL    RDVRM           ;Read old data
        LD      (WKOLD),A

        CALL    VADR
        LD      A,2AH
        CALL    WRTVRM          ;Put cursor ("*").

        CALL    BREAKX          ;Break check
        RET     C

        CALL    WAIT

        JR      TEST

VADR:   LD      A,(WKY)         ;Make SCREEN Address:
        LD      H,A             ;  From X,Y axis on WORK AREA
        LD      L,0             ;  To Hl reg.
        SRL     H
        RR      L
        SRL     H
        RR      L
        SRL     H
        RR      L
        LD      A,(WKX)
        ADD     A,L             ;  Y=32+X
        LD      L,A
        LD      BC,1800H        ;  VRAM start address
        ADD     HL,BC
        RET

WAIT:   LD      A,0             ;WAIT routine
WLP1:   INC     A
        LD      B,(IX+0)
        LD      B,(IX+0)
        LD      B,(IX+0)
        JR      NZ,WLP1
        RET

;----- data -----

WKX:    DB      10              ;X axis
WKY:    DB      10              ;Y axis
WKOLD:  DB      0               ;Character code on (X,Y)
WKXVAL: DB      0               ;X variable
WKYVAL: DB      0               ;Y variable

        END

 

6. CLOCK AND BATTERY-POWERED MEMORY

MSX2 uses a CLOCK-IC to for its timer function. Since this IC is battery-powered, it remains active even after MSX2 is turned off. MSX2 uses a small amount of RAM inside to set the PASSWORD or to set the screen mode at startup automatically, in addition to the CLOCK functions.

 

6.1 CLOCK-IC Functions

This IC has the following three functions:

CLOCK function

Alarm function

Battery-powered memory function

  1. adjustment value of CRT display width and height
  2. initial values of SCREEN, WIDTH, colour
  3. BEEP tone and volume
  4. title screen colour
  5. country code
  6. password *
  7. BASIC prompt *
  8. title caption *

* (one of 6 to 8)

 

6.2 Structure of the CLOCK-IC

The CLOCK-IC has four blocks inside as shown in Figure 5.25. Each block consists of 13 sets of 4-bit registers, which are specified by addresses from 0 to 12. In addition, it has three 4-bit registers for selecting the block or controlling functions; they are specified by the addresses from 13 to 15.

The registers inside the block (#0 to #12) and the MODE register (#13) can be read from and written to. The TEST register (#14) and RESET register (#15) can only be written to.

Figure 5.25 Clock IC structure
       BLOCK 0            BLOCK 1            BLOCK 2            BLOCK 2
       (CLOCK)            (ALARM)            (RAM-1)            (RAM-2)
   ----------------   ----------------   ----------------   ----------------
   | Seconds (the |   |              |   |              |   |              |
 0 | 1st decimal  |   |   ________   |   |              |   |              |
   | place)       |   |              |   |              |   |              |
   |--------------|   |--------------|   |-            -|   |-            -|
   | Seconds (the |   |              |   |              |   |              |
 1 | 2nd decimal  |   |   ________   |   |              |   |              |
   | place)       |   |              |   |              |   |              |
   |--------------|   |--------------|   |-            -|   |-            -|
 . |      .       |   |      .       |   |   Any data   |   |   Any data   |
 . |      .       |   |      .       |   |              |   |              |
 . |      .       |   |      .       |   |              |   |              |
 . |      .       |   |      .       |   |              |   |              |
 . |      .       |   |      .       |   |              |   |              |
   |--------------|   |--------------|   |-            -|   |-            -|
   | Year (the    |   |              |   |              |   |              |
 12| 2nd decimal  |   |   ________   |   |              |   |              |
   | place)       |   |              |   |              |   |              |
   ----------------   ----------------   ----------------   ----------------
   :<-- 4 bits -->:   :<-- 4 bits -->:   :<-- 4 bits -->:   :<-- 4 bits -->:


   ----------------
13 |     MODE     |
   |--------------| --+
14 |     TEST     |   |
   |--------------|   |-- Write only
15 |     RESET    |   |
   ---------------- --+
   :<-- 4 bits -->:

 

6.3 MODE Register Functions

The MODE register has the following 3 functions:

Selecting block

To read from or write to registers from #0 to #12, select the block to be used and then access the objective address. The 2 low order bits of the MODE register are used to select the block.

Registers from #13 to #15 are accessible whichever block is selected.

Alarm output ON/OFF

To switch the alarm input ON/OFF, use bit 2 of the MODE register. Since the standard MSX2 does not support the alarm, modifying this bit causes nothing to happen in general.

Terminating CLOCK count

By writing “0” in bit 3 of the MODE register, the count in seconds is stopped (the stages before the seconds are not stopped) and the clock function is terminated. By writing “1” in bit 3, the count is resumed.

Figure 5.26 MODE register functions
  B3   B2   B1   B0
---------------------
| TE | AE | M1 : M0 |  MODE register (#13)
---------------------
  |    |       |       00: select block 0
  |    |       |       01: select block 1
  |    |       +---->  10: select block 2
  |    |               11: select block 3
  |    |
  |    +------------>  0:  alarm output OFF
  |                    1:  alarm output ON
  |
  +----------------->  0:  CLOCK count stop (in seconds)
                       1:  CLOCK count start

 

6.4 TEST Register functions

The TEST register (#14) is used to increment the upper counter quickly and to confirm that date and time carries are done correctly. Setting “1” in each bit of the register, the pulse of 2^14 (=16384)[Hz] is directly set in day, hour, minute, and second counters.

Figure 5.27 TEST register functions
  B3   B2   B1   B0
---------------------
| T3 | T2 | T1 | T0 |  TEST register (#14)
---------------------
  |    |    |    |
  |  Hours  |  Seconds ........ the location for the pulse to be placed
 Day      Minutes

 

6.5 RESET Register Functions

The RESET register (#15) has the following functions:

Resetting the alarm

Setting “1” in bit 0 causes all alarm registers to be reset to 0.

Setting the seconds

Setting “1” in bit 1 causes the stage before the seconds to be reset. Use this function to set the seconds correctly.

Clock pulse ON/OFF

Setting “1” in bit 2 turns the 16Hz clock pulse output ON, and setting “0” in bit 3 turns the 1Hz clock pulse output ON. Note that both are not supported by the MSX2 standard.

Figure 5.28 RESET register function
  B3   B2   B1   B0
---------------------
| C1 | C16| CR | AR |  RESET register (#15)
---------------------
  |    |    |    |
  |    |    |    +-->  When "1", all alarm registers are reset
  |    |    +------->  When "1", fractions smaller than a second are reset
  |    +------------>  When "0", 16[Hz] clock pulse is ON
  +----------------->  When "0", 1[Hz] clock pulse is ON

 

6.6 Setting the Clock and Alarm

Setting date and time

Block 0 is used to set the clock. Selecting block 0 in the MODE register and writing data in the objective register causes the date and the time to be set. The current time is acquired by reading the contents of the register. See Figure 5.29 for the meaning of the register and its address.

Block 1 is used to set the alarm. Note that the time of the alarm can be set only in days, hours, and minutes. Nothing happens, in general, when the time of the clock meets the time of the alarm.

In the clock, the year is represented by 2 digits (registers #11 and #12). In MSX-BASIC, the 2 low order digits of the year is represented by adding the offset 80 to this value. For example, after setting register #11 to 0 and register #12 to 0, the year would be 80, as “80/XX/XX”, when the date is read by using the GET DATE instruction of BASIC.

The day of the week is represented by 0 to 6. This is only a mod 7 counter which is renewed alomg with the date, and the correspondence between the actual day of the week and the number value 0 to 6 is not defined.

Figure 5.29 Setting the CLOCK and ALARM
                       block 0 : CLOCK
   ---------------------------------------------------------
   |                           |  B3  |  B2  |  B1  |  B0  |
   |---------------------------+---------------------------|
 0 |  Seconds                  |                           |
   |  (the 1st decimal place)  |  X      X      X      X   |
   |---------------------------+---------------------------|
 1 |  Seconds                  |                           |
   |  (the 2nd decimal place)  |  .      X      X      X   |
   |---------------------------+---------------------------|
 2 |  Minutes                  |                           |
   |  (the 1st decimal place)  |  X      X      X      X   |
   |---------------------------+---------------------------|
 3 |  Minutes                  |                           |
   |  (the 2nd decimal place)  |  .      X      X      X   |
   |---------------------------+---------------------------|
 4 |  Hours                    |                           |
   |  (the 1st decimal place)  |  X      X      X      X   |
   |---------------------------+---------------------------|
 5 |  Hours                    |                           |
   |  (the 2nd decimal place)  |  .      .      X      X   |
   |---------------------------+---------------------------|
 6 |  Day of                   |                           |
   |  the week                 |  .      X      X      X   |
   |---------------------------+---------------------------|
 7 |  Day                      |                           |
   |  (the 1st decimal place)  |  X      X      X      X   |
   |---------------------------+---------------------------|
 8 |  Day                      |                           |
   |  (the 2nd decimal place)  |  .      .      X      X   |
   |---------------------------+---------------------------|
 9 |  Month                    |                           |
   |  (the 1st decimal place)  |  X      X      X      X   |
   |---------------------------+---------------------------|
10 |  Month                    |                           |
   |  (the 2nd decimal place)  |  .      .      .      X   |
   |---------------------------+---------------------------|
11 |  Year                     |                           |
   |  (the 1st decimal place)  |  X      X      X      X   |
   |---------------------------+---------------------------|
12 |  Year                     |                           |
   |  (the 2nd decimal place)  |  X      X      X      X   |
   ---------------------------------------------------------

                       block 1 : ALARM
   ---------------------------------------------------------
   |                           |  B3  |  B2  |  B1  |  B0  |
   |---------------------------+---------------------------|
 0 |     _________________     |                           |
   |                           |  .      .      .      .   |
   |---------------------------+---------------------------|
 1 |     _________________     |                           |
   |                           |  .      .      .      .   |
   |---------------------------+---------------------------|
 2 |  Minutes                  |                           |
   |  (the 1st decimal place)  |  X      X      X      X   |
   |---------------------------+---------------------------|
 3 |  Minutes                  |                           |
   |  (the 2nd decimal place)  |  .      X      X      X   |
   |---------------------------+---------------------------|
 4 |  Hours                    |                           |
   |  (the 1st decimal place)  |  X      X      X      X   |
   |---------------------------+---------------------------|
 5 |  Hours                    |                           |
   |  (the 2nd decimal place)  |  .      .      X      X   |
   |---------------------------+---------------------------|
 6 |  Day of                   |                           |
   |  the week                 |  .      X      X      X   |
   |---------------------------+---------------------------|
 7 |  Day                      |                           |
   |  (the 1st decimal place)  |  X      X      X      X   |
   |---------------------------+---------------------------|
 8 |  Day                      |                           |
   |  (the 2nd decimal place)  |  .      .      X      X   |
   |---------------------------+---------------------------|
 9 |     _________________     |                           |
   |                           |  .      .      .      .   |
   |---------------------------+---------------------------|
10 |  12 or                    |                           |
   |  24 hours                 |  .      .      .      X   |
   |---------------------------+---------------------------|
11 |  Leap year                |                           |
   |  counter                  |  .      .      X      X   |
   |---------------------------+---------------------------|
12 |     _________________     |                           |
   |                           |  .      .      .      .   |
   ---------------------------------------------------------

Bits indicated by an “.” are always 0 and cannot be modified.

Selecting 12-hour clock/24-hour clock

Two clocks can be selected; one is a 24-hour clock which represents one o’clock in the afternoon as 13 o’clock, and the other is a 12-hour clock which represents it as 1 p.m. Register #10 is used to select between them. As shown in Figure 5.30, the 12-hour clock is selected when B0 is “0” and the 24-hour clock when B0 is “1”.

Figure 5.30 Selecting 12-hour clock/24-hour clock
  B3   B2   B1   B0
---------------------
|  . |  . |  . | B0 |  Register #10 (block 1)
---------------------
                 |
                 +-->  0: 12-hour clock
                       1: 24-hour clock
Figure 5.31 Morning/afternoon flag for 12-hour clock
  B3   B2   B1   B0
---------------------
|  . |  . | B1 |  X |  register #5 (block 0)
---------------------
            |
            +------->  0: before noon
                       1: after noon

Leap year counter

Register #11 of block 1 is a mod 4 counter which is renewed along with the count of the year. When the 2 low order bits of this register are 00H, that is considered as a leap year and 29 days are counted in February.

Figure 5.32 Leap year determination
  B3   B2   B1   B0
---------------------
|  . |  . | B1 | B0 |  Register #11 (block 1)
---------------------
            |    |
            +----+-->  Both bits 0 represents leap year.

 

6.7 Contents of the Battery-powered Memory

Blocks 2 and 3 of the CLOCK-IC are used as the battery-powered 4-bit x 13 memory blocks. MSX2 uses this area as shown below.

Contents of block 2

Figure 5.33 Contents of block 2
   |       B3       |       B2       |       B1       |       B0       |
   |-------------------------------------------------------------------|
 0 |                                 ID                                |
   |-------------------------------------------------------------------|
 1 |                        Adjust X (-8 to +7)                        |
   |-------------------------------------------------------------------|
 2 |                        Adjust Y (-8 to +7)                        |
   |-------------------------------------------------------------------|
 3 |   __________   |   __________   | Interlace mode |  Screen mode   |
   |-------------------------------------------------------------------|
 4 |                         WIDTH value (Lo)                          |
   |-------------------------------------------------------------------|
 5 |                         WIDTH value (Hi)                          |
   |-------------------------------------------------------------------|
 6 |                         Foreground color                          |
   |-------------------------------------------------------------------|
 7 |                         Background color                          |
   |-------------------------------------------------------------------|
 8 |                           Border color                            |
   |-------------------------------------------------------------------|
 9 | Cassette speed |  Printer mode  |   Key click    |   Key ON/OFF   |
   |---------------------------------+---------------------------------|
10 |            BEEP tone            |           BEEP volume           |
   |---------------------------------+---------------------------------|
11 |   __________   |   __________   |           Title colour          |
   |-------------------------------------------------------------------|
12 |                            Native code                            |
   ---------------------------------------------------------------------

Contents of block 3

Block 3 has three functions, depending on the contents of the ID value (register #0). Figure 5.34 shows the functions.

Figure 5.34 Contents of block 3
ID=0: displays the title (within 6 characters) on the initial screen
   ------------------------------------------------------
 0 |  0                                                 |
   |----------------------------------------------------| --+
 1 |  Lo 1 --+--- 1st character of the title            |   |
   |         |                                          |   |
 2 |  Hi 1 --+                                          |   |
   |----------------------------------------------------|   |
 . |       .                                            |   |
 . |       .                                            |   | 6 characters
 . |       .                                            |   |
   |----------------------------------------------------|   |
11 |  Lo 6 --+--- 6th character of the title            |   |
   |         |                                          |   |
12 |  Hi 6 --+                                          |   |
   ------------------------------------------------------ --+

ID=1: sets the password
   ------------------------------------------------------
 0 |  1                                                 |
   |----------------------------------------------------|
 1 |  Usage ID=1                                        |
   |                                                    |
 2 |  Usage ID=2                                        |
   |                                                    |
 3 |  Usage ID=3                                        |
   |----------------------------------------------------|
 4 |  Password  --+                                     |
   |              |                                     |
 5 |  Password    |   Password data is stored           |
   |              |-- compressed in 4bits x 4 bits      |
 6 |  Password    |                                     |
   |              |                                     |
 7 |  Password  --+                                     |
   |----------------------------------------------------|
 8 |  Key cartridge flag                                |
   |----------------------------------------------------|
 9 |  Key cartridge value                               |
   |                                                    |
10 |  Key cartridge value                               |
   |                                                    |
11 |  Key cartridge value                               |
   |                                                    |
12 |  Key cartridge value                               |
   ------------------------------------------------------

ID=2: sets the prompt on BASIC
   ------------------------------------------------------
 0 |  2                                                 |
   |----------------------------------------------------| --+
 1 |  Lo 1 --+--- 1st character of the prompt           |   |
   |         |                                          |   |
 2 |  Hi 1 --+                                          |   |
   |----------------------------------------------------|   |
 . |       .                                            |   |
 . |       .                                            |   | 6 characters
 . |       .                                            |   |
   |----------------------------------------------------|   |
11 |  Lo 6 --+--- 6th character of the prompt           |   |
   |         |                                          |   |
12 |  Hi 6 --+                                          |   |
   ------------------------------------------------------ --+

 

6.8 Access to the CLOCK-IC

The following BIOS routines are offered to access the clock and the battery-powered memory. Since these routines reside in SUB-ROM, they are called by using the inter-slot call.

 

REDCLK (015FH/SUB) - read CLOCK-IC data

Figure 5.35 CLOCK-IC register specification method
                -----------------------------------------
C register      |  . |  . | M1 : M0 | A3 : A2 : A1 : A0 |
                -----------------------------------------
                          |         |                   |
                          +---------+-------------------+
                          Block to be       Register
                          selected          address

 

WRTCLK (01F9H/SUB) - write CLOCK-IC data

List 5.10 shows an example of this BIOS routine.

List 5.10 Setting the prompt
;************************************************
;
;  List 5.10  set prompt message
;
;************************************************
;
WRTCLK: EQU     01F9H
EXTROM: EQU     015FH

        ORG     0B000H

;----- program start -----      ;Note:  Set prompt message for BASIC.

START:  LD      C,00110000B     ;address data
        LD      A,2             ;ID := prompt mode
        CALL    WRTRAM          ;write to back-up RAM

        LD      B,6             ;loop counter
        LD      HL,STRING       ;prompt data
L01:    LD      A,(HL)          ;read string data
        AND     0FH             ;A := hi 4 bit
        INC     C               ;increment address
        CALL    WRTRAM          ;write data to back-up RAM
        LD      A,(HL)
        RRCA
        RRCA
        RRCA
        RRCA
        AND     0FH
        INC     C               ;increment address
        CALL    WRTRAM          ;write low 4 bits
        INC     HL
        DJNZ    L01
        RET

;----- write data to back-up RAM -----

WRTRAM: PUSH    HL
        PUSH    BC
        LD      IX,WRTCLK
        CALL    EXTROM          ;use interslot call
        POP     BC
        POP     HL
        RET

;----- string data -----

STRING: DB      'Ready?'

        END

Changes from the original: