6. Using machine code with the unit
This section is intended to set out guidelines for writing machine code programs for the unit. It must be stressed that the MicroSpeech was primarily designed to be used with BASIC for wider popular appeal, and as the operating software is necessarily complex only the experienced programmer should attempt writing machine code for the unit.
In the following examples, the 48K version memory address will be used - simply subtract 32768 to convert to the 16K machine. Decimal is used for all numbers unless otherwise stated.
At the top of the speech buffer is the six-byte "header" - information which controls the action of the buffer and the speech system. This comprises:
ADDRESS (48K) |
FUNCTION |
|---|---|
65367 |
Flag byte |
65366 |
Spare byte |
65365 |
Hi byte of buffer pointer |
65364 |
Lo byte of buffer pointer |
65363 |
Spare |
65362 |
Spare |
65361 |
Next allophone to be voiced |
The Buffer Pointer keeps a pointer to ONE BELOW the last item in the buffer which was voiced. It is incremented by one every time an allophone byte is outputted to the speech chip from the top of the buffer and the entire contents of the buffer is moved up by one ready for the next byte to leave. If this pointer points to 65361, as it does at startup, then the buffer is deemed empty and no allophone is issued.
The Spare bytes are initialised to zero (00h) at startup and serve as safe locations for you to store vital data in - you may want to experiment with a dual buffer, for instance, and switch between the two by swapping pointers.
The Flag Byte contains various flags for system use.
The function of each bit is as follows:
BIT |
FUNCTION |
|---|---|
7 |
Copyright message flag - reset after issuing message |
6 |
Spare |
5 |
Spare |
4 |
Used in keyboard scan - unlikely to be useful |
3 |
Spare |
2 |
Used in keyboard scan - unlikely to be useful |
1 |
Key voice enabled (set at first) |
0 |
Spare |
None of the flag bits will cause a crash if you alter them although the copyright message will appear if you set bit 7.
The important thing NOT to corrupt is the buffer pointer - if you make this point below the current RAMTOP you will crash the system.
If you would like to input speech data directly into the buffer rather than go via the BASIC variable s$ you must first fill the buffer with the allophones you want.
Each allophone in the buffer is represented by a byte; six bits of each byte are devoted to the allophone code, one bit is for intonation, and bit 7 is always zero.
BIT: 7 6 5 4 3 2 1 0 FUNCTION: zero intonation allophone (1 for up)
The decimal and hexadecimal codes for the allophones are given in appendix I. As an example of machine code programming, let us suppose that you wanted to make the unit say "hello". First of all, you must work out the codes for "he(ll)(oo)" - they are 27, 7, 62 and 53.
Let us also suppose you wanted the "e" to be intoned up. Simply add 64 to the basic code (7) to give 71. Now that you have your data, you have to load it into the buffer in the right order (top down) and then update the buffer pointer to point to ONE BELOW the last allophone you wish to be voiced. Here is a suggested program which would do this, written as an assembly language subroutine:
Start: ld hl, Data
ld de, 65361
ld b, 4 ; load count with 4
Loop: ld a, (hl)
ld (de), a ; load allophone in buffer
inc hl
dec de
djnz Loop ; loop to load four bytes
ex de, hl ; point hl to 1 below the last byte in buffer
ld (65364), hl ; update pointer
ret
Data: Defb 27, 71, 62, 53 ; the four bytes data