Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Commit 3a5fbd3

Browse files
committed
Add KIM-1 functions to write to the 7-segment LED display and get
keypresses from the keypad. Includes sample program illustrating how to use them. Tested on real KIM-1 hardware.
1 parent d69117c commit 3a5fbd3

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

asminc/kim1.inc

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ INTCHR := $1E5A ; Input character without case conversion
1616
DUMPT := $1800 ; Dump memory to tape
1717
LOADT := $1873 ; Load memory from tape
1818
START := $1C4F ; Enter KIM-1 monitor
19+
SCANDS := $1F1F ; Scan 7-segment display
20+
KEYIN := $1F40 ; Open up keyboard channel
21+
GETKEY := $1F6A ; Return key from keyboard
22+
1923

2024
; ---------------------------------------------------------------------------
2125
; System Memory

include/kim1.h

+13
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,18 @@ int __fastcall__ loadt (unsigned char);
5656
/* Write to tape */
5757
int __fastcall__ dumpt (unsigned char, const void*, const void*);
5858

59+
60+
/* Write to 7-segment LED display. Due to hardware limitations it only
61+
** displays briefly, so must be called repeatedly to update the
62+
** display.
63+
**/
64+
void __fastcall__ scandisplay(unsigned char left, unsigned char middle, unsigned char right);
65+
66+
/*
67+
** Get a keypress from the keypad. Returns $00-$0F(0-F), $10(AD), $11(DA), $12(+),
68+
** $13(GO), $14(PC) or $15 for no keypress.
69+
**/
70+
int __fastcall__ getkey();
71+
5972
/* End of sym1.h */
6073
#endif

libsrc/kim1/getkey.s

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
;
2+
; int __fastcall__ getkey();
3+
;
4+
5+
.include "kim1.inc"
6+
7+
.import popa
8+
9+
.export _getkey
10+
11+
.proc _getkey
12+
13+
jsr KEYIN ; Open up keyboard channel
14+
jsr GETKEY ; Get key code
15+
ldx #0 ; MSB of return value is zero
16+
rts
17+
18+
.endproc

libsrc/kim1/scandisplay.s

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
;
2+
; void __fastcall__ scandisplay(unsigned char left, unsigned char middle, unsigned char right);
3+
;
4+
5+
.include "kim1.inc"
6+
7+
.import popa
8+
9+
.export _scandisplay
10+
11+
.proc _scandisplay
12+
13+
sta $F9 ; Rightmost display data
14+
jsr popa
15+
sta $FA ; Middle display data
16+
jsr popa
17+
sta $FB ; Leftmost display data
18+
jsr SCANDS
19+
rts
20+
21+
.endproc

samples/kim1/kimKeyDisp.c

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/* Example illustrating scandisplay() and getkey() functions. */
2+
3+
#include <stdio.h>
4+
#include <kim1.h>
5+
6+
int main (void)
7+
{
8+
int i, j, k, l;
9+
int last = 15;
10+
11+
printf("\nKIM-1 Demo\n");
12+
13+
for (i = 0; i < 16; i++) {
14+
for (j = 0; j < 16; j++) {
15+
for (k = 0; k < 16; k++) {
16+
scandisplay(i, j, k);
17+
18+
l = getkey();
19+
20+
if (l != last) {
21+
switch (l) {
22+
case 0x0: case 0x1: case 0x2: case 0x3:
23+
case 0x4: case 0x5: case 0x6: case 0x7:
24+
case 0x8: case 0x9: case 0xa: case 0xb:
25+
case 0xc: case 0xd: case 0xe: case 0xf:
26+
printf("Key pressed: %X\n", l);
27+
break;
28+
case 0x10:
29+
printf("Key pressed: AD\n");
30+
break;
31+
case 0x11:
32+
printf("Key pressed: DA\n");
33+
break;
34+
case 0x12:
35+
printf("Key pressed: +\n");
36+
break;
37+
case 0x13:
38+
printf("Key pressed: GO\n");
39+
break;
40+
case 0x14:
41+
printf("Key pressed: PC\n");
42+
break;
43+
}
44+
45+
last = l;
46+
}
47+
}
48+
}
49+
}
50+
51+
return 0;
52+
}

0 commit comments

Comments
 (0)