COMPUTE II ISSUE 3 / AUGUST/SEPTEMBER 1980 / PAGE 22
KIM-1 TIDBITS
Harvey B. Herman
Chemistry Department
University of North Carolina at Greensboro
Greensboro, NC 27412
This article is the second in what I hope is a continuing series on the KIM. My intension is to share with others programs which should make KIM easier to use. The reader will please note the machine language programs have been documented with the excellent Macro Assembler and Text Editor (ASSM/TED) from Eastern House software (see my review in COMPUTE #1, p100). When I started messing with KIM several years ago, my programs were mostly hand assembled. This task has been made much easier by using ASSM/TED.
The first program is an implementation of a KIM real-time clock (sometimes called a tick counter). I have whimsically referred to it as a 'Jeffrey counter' after a former student of mine. Every 100 milliseconds a location in page zero is incremented. By peeking at this location one can time external events up to about 25 seconds. We have used it to tell when to take readings from an analog-to-digital converter. The clock can be started, stopped or read under program control. A source listing of the program is shown in figure 1. An example of a BASIC program which uses the tick counter is shown in figure 2.
In order for this program to work one external connection needs to be made. The counter is interrupt driven and requires PB7 on the application connector (A-15) to be connected directly to IRQ (E-4). The program sets PB7 as an input line and initializes the IRQ vectors at $17FE/ $17FF to point to the clock service routine. For convenience I have modified KIM Microsoft BASIC to execute a preamble which, among other things, sets up these vectors before jumping to the normal start of BASIC.
The second program is an enhancement to KIM Microsoft BASIC. Support is added for a terminal (e.g. ASR 33 Teletype) which used the X-ON/X-OFF protocol to start and stop a paper tape reader. Over the years I had accumulated a number of programs on paper tape which I wanted to use with KIM BASIC. As supplied the BASIC software did not read paper tapes reliably and I had no desire to key in long programs again. I waded through a disassembly of BASIC and found two calls to a subroutine which could be called “input a line.”
The change I made was to send out an X-ON character (with added code in page 2 - Listing 3) before jumping to this subroutine. My paper tape reader will begin reading upon receipt of this character.
It was necessary to make one further change in order for KIM to punch BASIC program tapes that would read back properly. The tape reader must stop after carriage return while BASIC “digests” a line. Therefore the X-OFF character (stop reading) must be included in the data stream. I found a call to BASIC's output routine immediately after loading the accumulator with “CR” (hex 0D). I changed this to a jump to code, again in page 2, which outputs X-OFF and CR before continuing as before. Later when the teletype reads the X-OFF character on tape it shuts off but does not stop immediately and reads one additional character (CR). Return sets the BASIC interpreter off and running. In a short time, after digesting the line, BASIC sends the X-ON character asking for more data. Only one caveat – remember to type Control/0 before and after reading tapes so the teletype will only single space.
I hope these additional programs will be found useful. As always, if you have any questions I will be happy to respond if you include a SASE.
Listing 1
0100 ; 0110 ; INTERRUPT SERVICE ROUTINE FOR REAL-TIME CLOCK 0120 ; (TICK COUNTER). ENHANCEMENT TO KIM MICROSOFT 0130 ; BASIC. 1/10 SEC PER TICK 0140 ; 0150 ; HARVEY B. HERMAN 0160 ; 0170 ; REQUIRES CONNECTION OF IRQ TO PB7. 0180 ; SET ALL PB PINS AS INPUT. SET ORIGINAL COUNT 0190 ; AND DIVIDE RATE(/1024) OF 6530 TIMER. 0200 ; START TICKING - POKE 5891,0:POKE 5903,98 0210 ; DISABLE IRQ (OTHER WAYS POSSIBLE). 0220 ; STOP TICKING - POKE 5894,98 0230 ; READ TICK COUNTER - PEEK(224) 0240 ; RESET STOPS CLOCK. 0250 ; 0260 TICK .DE $E0 ;FREE LOCATION PAGE ZERO 0270 COUNT .DE $62 ;1/10 SEC. 0280 CLKKTE .DE $170F ;DIVIDE BY 1024(INT. EN.) 0290 IRQL .DE $17FE ;KIM IRQ INTERRUPT 0300 IRQH .DE $17FF ; VECTORS 0310 ; 0320 ; INITIALIZATION ROUTINE 0330 ; SET UP VECTORS AND ZERO TICK COUNTER 0340 ; LOCATE ANYWHERE CONVENIENT 0350 .BA $4368 0360 ; OTHER CODE ABOVE IN MY VERSION 4368- A9 DA 0370 LDA #INTER 436A- 8D FE 17 0380 STA IRQL 436D- A9 02 0390 LDA #H,INTER 436F- 8D FF 17 0400 STA IRQH 4372- A9 00 0410 LDA #00 4374- 85 E0 0420 STA *TICK 0430 ; OTHER CODE BELOW IN MY VERSION 0440 ; 0450 ; INTERRUPT HERE ON TIMEOUT 0460 .BA $2DA 02DA- 48 0470 INTER PHA 02DB- EA 0480 NOP ;HIDE MY IGNORANCE 02DC- E6 E0 0490 INC *TICK 02DE- A9 62 0500 LDA #COUNT 02E0- 8D 0F 17 0510 STA CLKKTE 02E3- 68 0520 PLA 02E4- 40 0530 RTI 0540 .EN
Listing 2
10 REM EXAMPLE PROGRAM TO PRINT A NUMBER
20 REM ONCE EVERY 10 SECONDS
30 POKE 5903, 98: REM START CLOCK
40 FOR I = 1 TO 10
50 POKE 224,0: REM ZERO CLOCK
60 IF PEEK (224) < 100 THEN 60
70 PRINT I;
80 NEXT I
90 POKE 5894, 98: REM STOP CLOCK
100 END
Listing 3
0100 ; 0110 ; X-ON/X-OFF ENHANCEMENT TO 0120 ; KIM MICROSOFT BASIC 0130 ; SERIAL NUMBER 9011 0140 ; 0150 ; HARVEY B. HERMAN 0160 ; 0170 ; SENDS X-ON (HEX 11) TO TERMINAL BEFORE JUMPING TO 0180 ; "INPUT A LINE". TERMINALS WITH THIS FEATURE WILL 0190 ; AUTOMATICALLY START READING PAPER TAPE. WHEN AN 0200 ; X-OFF (HEX 13) IS READ, THE TAPE READER CONTROL 0210 ; WILL TURN OFF AND THE READER WILL COAST AND 0220 ; TRANSMIT ONE EXTRA CHARACTER. 0230 ; 0240 ; PUNCHES PAPER TAPE (BY LIST) WITH X-OFF/CR/LF/ 0250 ; NULL(S) AS END OF LINE FORMAT. 0260 ; 0270 ; NULL(S) CORRECTION (NECESSARY FOR EARLY VERSIONS 0280 ; OF BASIC). 0290 ; 0300 OUTCH .DE $1EA0 ;KIM OUTPUT ROUTINE 0310 INPUT .DE $2426 ;BASIC "INPUT A LINE" 0320 OUTPUT .DE $2A3A ;BASIC OUTPUT ROUTINE 0330 LDA0 .DE $29D1 ;INSTRUTION LDA #00 0340 ; 0350 ; INTERCEPT CALLS TO "INPUT A LINE" 0360 .BA $2351 2351- 20 C8 02 0370 JSR XON 0380 .BA $2AB6 2AB6- 4C C8 02 0390 JMP XON 0400 ; OUTPUT X-ON CHARACTER 0410 .BA $2C8 02C8- A9 11 0420 XON LDA #$11 ;X-ON 02CA- 20 A0 1E 0430 JSR OUTCH ;OUT TO TERMINAL 02CD- 4C 26 24 0440 JMP INPUT ;INPUT A LINE 0450 ; INTERCEPT CALLS TO OUTPUT CR 0460 .BA $29C3 29C3- 20 D0 02 0470 JSR XOFF 0480 ; OUTPUT X-OFF/CR CHARACTERS 0490 .BA $2D0 02D0- A9 13 0500 XOFF LDA #$13 ;X-OFF 02D2- 20 3A 2A 0510 JSR OUTPUT ;BASIC OUTPUT ROUTINE 02D5- A9 0D 0520 LDA #$0D ;CR 02D7- 4C 3A 2A 0530 JMP OUTPUT 0540 ; CORRECT NULL(S) ERROR IN EARLY VERSION 0550 ; OF BASIC. A WAS DESTROYED BY OUTPUT AND MUST 0560 ; BE LOADED AGAIN WITH ZERO. 0570 .BA $29D7 29D7- D0 F8 0580 BNE LDA0 0590 .EN