KIM-1 programming help needed

Talk about your Micro-KIM

KIM-1 programming help needed

Postby Paul Förster » May Sat 10, 2014 10:44 am


I need a little help from the KIM-1 experts here:

The following routine is the GETCH routine from the KIM-1 ROM. It waits for a character coming over the serial line and returns it in A.

Code: Select all
 725  1E5A  86 FD     GETCH   STX   TMPX      SAVE X REG     1E5A
 726  1E5C  A2 08             LDX   #$08      SET UP 8-BIT COUNT
 727  1E5E  A9 01             LDA   #$01
 728  1E60  2C 40 17  GET1    BIT   SAD
 729  1E63  D0 22             BNE   GET6
 730  1E65  30 F9             BMI   GET1      WAIT FOR START BIT
 731  1E67  20 D4 1E          JSR   DELAY     DELAY 1 BIT
 732  1E6A  20 EB 1E  GET5    JSR   DEHALF    DELAY 1/2 BIT TIME
 733  1E6D  AD 40 17  GET2    LDA   SAD       GET 8 BITS
 734  1E70  29 80             AND   #$80      MASK OFF LOW ORDER BITS
 735  1E72  46 FE             LSR   CHAR      SHIFT RIGHT CHAR
 736  1E74  05 FE             ORA   CHAR
 737  1E76  85 FE             STA   CHAR
 738  1E78  20 D4 1E          JSR   DELAY     DELAY 1 BIT TIME
 739  1E7B  CA                DEX 
 740  1E7C  D0 EF             BNE   GET2      GET NEXT CHAR
 741  1E7E  20 EB 1E          JSR   DEHALF    EXIT THIS ROUTINE
 742  1E81  A6 FD             LDX   TMPX
 743  1E83  A5 FE             LDA   CHAR
 744  1E85  2A                ROL   A SHIFT OFF PARITY
 745  1E86  4A                LSR   A
 746  1E87  60        GET6    RTS   

So far, so good and easy to use. My problem is that it behaves like the Commodore BASIC equivalent:
Code: Select all
10 geta$
20 ifa$=""goto10

This means it waits for input. What I need is the same without waiting, i.e. in analogy, only the geta$, not the ifa$=""... I tried to play around with the BNE and BMI commands after the GET1 label to make that work but it just doesn't.

Is there any way to get a signal on the KIM-1 if one character is waiting on the serial line and do nothing if not, otherwise return the corresponding character? I'm trying this now for two days and just can't get it to work.

I managed to temporarily have a solution that worked nicely on Cameron Kaiser's KIMplement, but when I took it to the real thing, it failed miserably.

Any help would be appreciated.


User avatar
Paul Förster
Posts: 17
Joined: Mar Wed 19, 2014 11:35 am
Location: Switzerland

Re: KIM-1 programming help needed

Postby jac_goudsmit » May Mon 12, 2014 7:43 pm

The quick-and-dirty answer is: as long as the baud rate is low, you may be able to get away with just testing if bit 7 of SAD ($1740) is set. Example:

Code: Select all
       BIT   $1740
       BMI   NORX
       JSR   GETCH     Got a start bit, call kernel to get byte
       ...             Process received byte in A whichever way you want

NORX   ...             No incoming data, do some processing
       JMP   CHKSER    Check for start bit again

The caveat is that this will only work if the baud rate is not too high and the terminal is not sending characters too fast and your code at the NORX label which distracts your program from checking for a start bit isn't too long. For example, if your terminal emulator is set to 2400bps, the time for one serial bit is only about 416 microseconds, so you will want the delay between two executions of this loop to be less than 200 microseconds or so. This becomes less critical for slower baud rates, obviously.

User avatar
Posts: 74
Joined: Jun Mon 14, 2010 3:22 pm
Location: Rancho Cucamonga, California

Re: KIM-1 programming help needed

Postby Paul Förster » May Tue 13, 2014 3:45 am

Hi Jac,

I will try this. But it would be ok, even if I missed getting the actual character. I originally wanted it to get any key on the TTY to pause a loop running and ctrl-c ($03) to break. But if I missed the actual key code then there would be no way to tell one function from another. So in this case, I would have to resort to having a break function only and no pause. But I could live with that. The loop is probably longer than 200 microseconds so the likelihood to be back at GETCH right in time to get the right key code is very small unless I maybe put the check for the key at several places inside the loop.

Anyway, I will try this out. Thanks very much for the hint.


User avatar
Paul Förster
Posts: 17
Joined: Mar Wed 19, 2014 11:35 am
Location: Switzerland

Return to Micro-KIM General Discussion

Who is online

Users browsing this forum: No registered users and 2 guests