Personal Computer News


Genie MERGE, CLOSE and KEY BEEP

 
Author: Keith Hook
Published in Personal Computer News #074

Three commands - MERGE, CLOSE and KEY BLEEP - are introduced by Keith Hook for the Colour Genie.

Genie Supplement

Three commands - MERGE, CLOSE and KEY BLEEP - are introduced by Keith Hook for the Colour Genie

No matter how many Basic commands a manufacturer builds into a computer, you can always find other operations you wish they'd incorporated. This was my experience with the Colour Genie.

For the money, the Colour Genie is a very good machine, but I wish its designers had included a keyboard bleep which would give an audible signal that a key had been pressed instead of having to keep looking up at the screen.

Secondly, the designers have gone to the trouble of programming the ROM to execute a renumber routine, but omitted to add a utility to allow the end user to merge one program onto another. This is essential if, like myself, you keep a library of commonly used subroutines.

The listing provides you with these commands. The program can reside in memory just as long as you are not using the FGR screen. If you need to use the FGR screen, you can relocate the program to high memory, but you will have to save memory on power-up.

To write the routine, I had first to get the computer to recognise when I was requesting a CLOSE or OPEN command. As the two commands are used only in the direct input state - not as part of a Basic program statement - this didn't pose any problem.

Program Overview

The keyboard data control block (DCB) is located in RAM at address 4015Hex. Addresses 4016 and 4017H contain the address of the keyboard driver which, in turn, is located at 03E3H in ROM. The keyboard driver continuously scans the keyboard and converts the bit pattern of any key that is pressed into ASCII, and stores the result in the A register.

By re-vectoring the jump address at 4016H to the address of the new routine, the program listed on these pages can intercept the scanning cycle of the computer. The program then looks at the value held in the A register and acts accordingly.

  • If the value of the byte in the A register is greater than zero, the routine issues an audible bleep to signal that a key has been pressed, and then jumps to the next section of code which checks for a value of 0DH (carriage return).
  • If the A register contains a 'carriage return', it means that the user has requested the entry into memory of the data just typed.
  • If the Return key has not pressed, the program returns control to the computer and the scanning continues to look for further entries.
  • When the value of the byte is 0DH, the program checks address 40A7H, which holds the address of the buffer area used for storing characters typed in from the keyboard. The HL register pair is then loaded with this address and decremented by 1 byte - the next instruction RST10 increments the HL registers before testing each character ointed to by the HL registers. RST10 skips over tabs and line feeds and on its return the HL registers are pointing to the first non-blank character. The program then loads this character into the A register and tests for a "/". If the character is not "/", it places a carriage return instruction (0DH) back in the A register and returns to the main computer input phase.

When the character returned in the A register is equal to "/", the routine looks at the following byte for a "0" or a "C", which should follow the "/" if the user is requesting a marge.

The 'C' command causes the program to look for the end address of the Basic program. This information is held in address 40F9H and also includes the end of the simple variable list. The routine then decrements the vaue of the two bytes to allow for the 00 bytes that Basic puts at the end of a program to signal this fact - (EOP) the End Of Program pointer (see issues 27 & 32).

This new address is then saved in 40A4H, which is the Start Of Basic pointer - get the picture? The program then calls ROM routine 1B4DH which executes a NEW command. New programs can now be added without disturbing programs already in memory.

When the 'O' command is detected, the program gets the start of Basic address from 4056H, which was loaded at the beginning of the utility [line 13]. This address is re-loaded into 40A4H (start of Basic pointer), and the programs are now merged, and can be listed as a whole.

Using The Program

To close off a program, type: /C [RET]
To merge the programs type: /O [RET]

When you have closed off a program, you can use the computer as though there was no program in memory, i.e. you can CLOAD:CSAVE:EDIT and so on without spoiling the program in memory. You can also close off as many times as you like - within the capabilities of available memory - but you can only merge once. This is because the program merges right back to the start of Basic.

Before merging, each program that follows the one already in memory must have higher line numbers. You can do this by executing a renumber as this will not affect any closed program.

To test the program, type in the following:

1 CLS
2 PRINT "THIS IS THE FIRST PROGRAM"

Now type:
/C [RET]

If you now LIST, you should be faced with a blank screen. Now type:

3 PRINT "THIS IS THE SECOND PROGRAM"
4 END

Now type: /O [RET]

If you now list the program, you should find both programs merged as one on your Colour Genie.

To alter the pitch of the keyboard bleep, POKE a value between 0-255 into location &H4927.

To turn the bleep off, POKE 255 into &H4917.

You can use this method of calling useful subroutines by adding new commands at the bottom of the listing, starting after byte 4953H e.g. /K [RET] could be used for a routine that changes all PRINT statements to LPRINT commands.

The merge and close part of the program will also work on a TRS80 or a Genie 1 if the start of Basic is altered to 42R9H [line 15].

Keith Hook

This article was converted to a web page from the following pages of Personal Computer News #074.

Personal Computer News #074 scan of page 20

Page 20

Personal Computer News #074 scan of page 21

Page 21