Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Commit 26c024a

Browse files
committed
Get keyboard emulation working.
1 parent 8b620b1 commit 26c024a

File tree

2 files changed

+66
-9
lines changed

2 files changed

+66
-9
lines changed

software/src/e2/dxforth/dxforth.asm.m4

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,12 +1196,11 @@ _type_1:
11961196
align 4
11971197
key = _key - _start
11981198
_key: jal W,_docol
1199-
hword lit16, 122, emit
1200-
hword lit16, 122, emit
1201-
hword lit16, 122, emit
1202-
hword lit16, 122, emit
1203-
hword lit16, 122, emit, cr, cr
1204-
hword wedge ; deadlock until we figure out the input side of the SIA.
1199+
_key_0:
1200+
hword lit16, -4095, cfetch
1201+
hword lit16, 1, _and, zgo, _key_0
1202+
hword lit16, -4094, cfetch
1203+
hword exit
12051204

12061205
align 4
12071206
_ntib: jal W,_dovar

software/src/e2/main.c

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#include <string.h>
22
#include <stdlib.h>
33
#include <stdio.h>
4+
#include <errno.h>
5+
#include <termios.h>
46

57
#include "processor.h"
68

@@ -24,8 +26,50 @@ struct RootAS {
2426

2527
uint8_t
2628
sia1_fetch_byte(AddressSpace *as, uint64_t addr) {
27-
/* Emulator has no read registers yet. */
28-
return 0xCC;
29+
int erc;
30+
fd_set rfds;
31+
struct timeval tv;
32+
uint8_t b;
33+
34+
/*
35+
* Input registers:
36+
*
37+
* $001 STATUS
38+
* .... ...1 Character available
39+
*
40+
* $002 INPUT
41+
* xxxx xxxx Next Character in FIFO
42+
*/
43+
44+
switch(addr & 0xFFF) {
45+
case 1:
46+
b = 0;
47+
48+
FD_ZERO(&rfds);
49+
FD_SET(0, &rfds);
50+
51+
tv.tv_sec = 0;
52+
tv.tv_usec = 1;
53+
54+
erc = EAGAIN;
55+
while(erc == EAGAIN) {
56+
erc = select(1, &rfds, NULL, NULL, &tv);
57+
if(erc < 0) {
58+
erc = errno;
59+
continue;
60+
}
61+
}
62+
if(FD_ISSET(0, &rfds)) b |= 1;
63+
break;
64+
65+
case 2:
66+
b = (uint8_t)getchar();
67+
break;
68+
69+
default:
70+
b = 0xCC;
71+
}
72+
return b;
2973
}
3074

3175
uint16_t
@@ -535,12 +579,20 @@ new_root_address_space(void) {
535579

536580
ras->sia1.as.i = &sia1_interface;
537581
ras->sia1.bottom = 0xFFFFFFFFFFFFF000;
538-
ras->sia1.top = 0xFFFFFFFFFFFFF001;
582+
ras->sia1.top = 0xFFFFFFFFFFFFF004;
539583
}
540584
return ras;
541585
}
542586

543587

588+
struct termios orig_termios;
589+
struct termios new_termios;
590+
591+
void
592+
reset_terminal() {
593+
tcsetattr(0, TCSANOW, &orig_termios);
594+
}
595+
544596
int
545597
main(int argc, char *argv[]) {
546598
Processor *p;
@@ -558,6 +610,12 @@ main(int argc, char *argv[]) {
558610
exit(1);
559611
}
560612

613+
tcgetattr(0, &orig_termios);
614+
tcgetattr(0, &new_termios);
615+
atexit(reset_terminal);
616+
cfmakeraw(&new_termios);
617+
tcsetattr(0, TCSANOW, &new_termios);
618+
561619
p->pc = 0; // KCP53000B cold-starts at address 0.
562620
p->mtvec = 0x100; // KCP53000B traps by default to 0x100.
563621

0 commit comments

Comments
 (0)