At the heart of this application is the routine, PRMPT. Quite short in itself, PRMPT depends on many of the other routines covered so far, as shown in the documentation. Because of this, we will just run through the general system requirements that have to be met, in addition to those specific to PRMPT, for the routine to be run successfully:
(1) Addresses of the user stack, RAM reserved for strings and RAM reserved for display area parameters must have been set in page zero locations USPL-H, STRL-H and DAPL-H.
(2) The factor which gives a delay of 1 hundredth of a second on your system should have been set in page zero location DELH, as described in Chapter 4.
(3) The number of hundredths of a second delay you want between the display of each character of the prompt message must be set in DELN. $0A (decimal 10) is about right for this.
The prompt is a revolving message on one line, usually the bottom, of the screen. This looks interesting and allows messages of any size to be displayed in the same small area. The message is displayed until a character is given from the keyboard. Then the start address of the message, its last character index and current character index are left in the prompt information page zero locations. By this means, the message display can be resumed where
Prompting 57
it left off, if another character is expected in reply to the prompt.
PR MPT uses the current display area, to which appropriate parameters have to be moved before the routine is entered. To get a single row scrolling left, display area parameters have to be set correctly for your particular system. To the ten sets of display area parameters defined in Chapter 5, for a 40 column by 25 row screen, the addition of this next set of parameters would scroll a circular message on the bottom line.
Address Contents
2350 CO 63 00 27 28 00 01 00
This defines a home address at the bottom left screen character position, a character (in place of line) high index of 0, a line (in place of character) high index of 39 ($27), a character byte difference of 40 ($0028) and a line byte difference of 1 ($0001).
With a suitable prompt message string set in RAM, the routine can be entered:
PRMPT - Print a circular message until a character is given from the keyboard
Subroutines - PSHZM, STRNG, TFRZZ, 1NKD, PSLCT, PULZM, PARAM, STTMP, LDTMP, GETCH, ADCZI, AUTOP, HOME, CFC, CBC, CFL, CBL, CR, CRFL, CLCDA, PCHAR, CADDR, ADCZZ, SBCZZ, FILL, SCROL.
Length -51.
Stack - 16 + any stack in excess of 14 bytes required by GETCH.
User Stack - 17.
Input - A = prompt message string number. The carry is set for the prompt to start from the beginning of the message or reset for the message to be continued from where it previously left off.
Output - The character keyed in is in page zero location KCH. The prompt message string address, last character index and current character index are in page zero locations PRAL-H, PRT and PRF.
Registers changed None.
Method - If the carry was set on entry, string information is set in prompt information locations PRAL-H, PRT and PRF via user A and B registers, from labels PRNEW to PRK.RQ. This is also done at every end of the prompt message. From label PRKRQ to
58 6502 Machine Code for Humans
PRND, input is sought from the keyboard, for the number of hundredths of a second given in page zero location DELN. If a character has been given, there is a return from the routine with the output specified. Otherwise a character from the prompt message (at the address in PRAL-H indexed by Y) is put into page zero location PCH and displayed on the screen by PSLCT, with scrolling to the left at the end of the line. This display of prompt message characters continues until a character is given from the keyboard.
Here is a bit of code to look at PRMPT with. It assumes that the parameters for a bottom line, left scrolling message are in display area table 10, the whole screen parameters in table 0 and the screen window parameters (as defined in Chapter 5) still in table 1. In addition to the requirements of PRMPT, the routines CLRDA, RDAP and DL1S will be needed as well as an extra 16 bytes of the processor’s stack.
Character string 0, to be used later, will be a dummy 12-character string to take keyboard input for matching with an array. Character string 1 will hold the prompt message. In this example, the actual
Prompting 59
characters of the message string are shown, with % used to denote a space, rather than their ASCII codes. The string numbers (in the left-hand column) and string lengths are given in hexadecimal:
00 0C(string of 12 characters reserved for input)
01 2 F K E Y%I N%T H E%FI RST%T H R E E% L ETTE R S%0 F%T H E% MONTH %%%%
The base address of RAM you have reserved for strings must be set in page zero locations STRL-H.
When entered at EXP2A, this code will print the circular prompt message, until 3 characters have been input. In this case we will simply display the input on the screen. To do this, we will have to have two display areas in use concurrently, since the prompt message needs its own special display area:
EXP2A:
60 6502 Machine Code for Humans
CPX #14 ;from the EO 0E
BNE EXP2D ;processor stack. DO F8 LDA KCH ;move input char to A5 10 STA PCH print location and 85 11 JSR PSLCT ;display it on screen. 20 lo
DEX ;makes X = 13 CA
LDA CCN,X ;to store the B5 22
PHA ;updated display 48
DEX ;area I on the CA
BPL EXP2E ;processor stack. 10 FA CLC ;to continue prompting. 18 DEY ;adjust the count and 88 BNE EXP2C ;get next input char. DO CB
CLD ;restore D8
TSX ;processor BA
TXA ;stack by 8A
ADC #14 ;adding 14 to 69 0E
TAX ;the stack AA
TXS ;pointer. 9A
JSR ADCZI ;add 14 to the user 20 lo EQB USPL,$0E ;stack pointer. 00 0E JSR DL1S ;delay 1 second. 20 lo JMP ($FFFC) ;jump to restart. 6C FC Note how we do not have to bother saving registers in this main code, because we can rely on our utility routines returning them to us unchanged.