aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2018-09-28 22:14:51 -0700
committerH. Peter Anvin <hpa@zytor.com>2018-09-28 22:14:51 -0700
commit71b6ca4729c24f3279eb9e043b9a8d46b1eae2c0 (patch)
tree6e282b1cead5f8613287885135b8b9f8f9eb496c
parent6dd50938bda8d128b9126676cb7268921c09b3d0 (diff)
downloadabc80sim-71b6ca4729c24f3279eb9e043b9a8d46b1eae2c0.tar.gz
abc80sim-71b6ca4729c24f3279eb9e043b9a8d46b1eae2c0.tar.xz
abc80sim-71b6ca4729c24f3279eb9e043b9a8d46b1eae2c0.zip
Hook abcprint up to the ABC800 PR: port
Hook the abcprint up to the ABC800 PR: port. This is a quite vestigial DART (SIO) model; it would be good to unify this with the keyboard model and provide a more complete DART model. Note that ABC802 uses the RI# input on the PR: port to detect 40 or 80 character startup.
-rw-r--r--abc80.c42
-rw-r--r--abcio.c10
-rw-r--r--abcio.h4
-rw-r--r--abcprint.c70
-rw-r--r--hostfile.h5
-rw-r--r--print.c7
6 files changed, 117 insertions, 21 deletions
diff --git a/abc80.c b/abc80.c
index 0abdb06..98465ff 100644
--- a/abc80.c
+++ b/abc80.c
@@ -21,6 +21,9 @@ FILE *tracef;
int events_in_queue = 1;
volatile int event_pending = 1;
+/* This reflects the screen width at system boot; e.g. ABC802 jumper setting */
+bool startup_width40 = false;
+
/*
* Read a two digit hex number from a string
* and return its numeric value.
@@ -214,7 +217,6 @@ static char *long_arg(bool enable, const char *opt, char *arg)
int main(int argc, char **argv)
{
unsigned int memflags = 0;
- bool width40 = false;
char **option;
const char *optstr;
char optchr;
@@ -253,9 +255,9 @@ int main(int argc, char **argv)
} else if (!strcmp(optstr, "abc802")) {
model = MODEL_ABC802;
} else if (!strcmp(optstr, "40")) {
- width40 = enable;
+ startup_width40 = enable;
} else if (!strcmp(optstr, "80")) {
- width40 = !enable;
+ startup_width40 = !enable;
} else if (!strcmp(optstr, "basic")) {
memflags &= ~MEMFL_NOBASIC;
memflags |= (enable ? 0 : MEMFL_NOBASIC);
@@ -337,10 +339,10 @@ int main(int argc, char **argv)
memflags &= ~MEMFL_NODEV;
break;
case '4':
- width40 = true;
+ startup_width40 = true;
break;
case '8':
- width40 = false;
+ startup_width40 = false;
break;
case 'k':
kilobytes = strtoul(SHORT_ARG(), NULL, 0);
@@ -362,9 +364,15 @@ int main(int argc, char **argv)
}
}
+ hostfile_init();
+
+ if (memfile && model != MODEL_ABC802) {
+ fprintf(stderr, "WARNING: --memfile specified for a system "
+ "other than ABC802 - not possible\n");
+ }
+
if (traceflags) {
- if (!tracefile || !tracefile[0] ||
- (tracefile[0] == '-' && !tracefile[1])) {
+ if (is_stdio(tracefile)) {
tracef = stdout;
} else {
tracef = fopen(tracefile, "wt");
@@ -376,24 +384,22 @@ int main(int argc, char **argv)
}
}
- if (memfile && model != MODEL_ABC802) {
- fprintf(stderr, "WARNING: --memfile specified for a system which is not ABC802\n");
- }
-
- if (detach)
- detach_console();
-
if (console) {
- if (!console[0] || (console[0] == '-' && !console[1])) {
- console_file = detach ? NULL : stdout;
+ if (is_stdio(console)) {
+ console_file = stdout;
} else {
console_file = fopen(console, "wt");
+ if (!console_file) {
+ fprintf(stderr, "%s: Unable to open console file %s: %s\n",
+ program_name, console, strerror(errno));
+ }
}
}
- hostfile_init();
+ if (detach)
+ detach_console();
- screen_init(width40);
+ screen_init(startup_width40);
mem_init(memflags, memfile);
io_init();
diff --git a/abcio.c b/abcio.c
index 642ae3d..e389862 100644
--- a/abcio.c
+++ b/abcio.c
@@ -221,6 +221,11 @@ static void abc802_out(uint8_t port, uint8_t value)
abcbus_out(port, value);
break;
+ case 32:
+ case 33:
+ dart_pr_out(port, value);
+ break;
+
case 34:
case 35:
dart_keyb_out(port, value);
@@ -343,6 +348,11 @@ static uint8_t abc802_in(uint8_t port)
v = abcbus_in(port);
break;
+ case 32:
+ case 33:
+ v = dart_pr_in(port);
+ break;
+
case 34:
case 35:
v = dart_keyb_in(port);
diff --git a/abcio.h b/abcio.h
index 64babc1..e3e57ef 100644
--- a/abcio.h
+++ b/abcio.h
@@ -14,6 +14,7 @@ enum model {
extern enum model model;
extern unsigned int kilobytes;
extern bool old_basic;
+extern bool startup_width40;
extern void abc80_mem_mode40(bool);
extern void abc80_mem_setmap(unsigned int);
@@ -31,6 +32,9 @@ extern uint8_t abc800_ctc_in(uint8_t);
extern void printer_reset(void);
extern void printer_out(int sel, int port, int value);
extern int printer_in(int sel, int port);
+extern void dart_pr_out(uint8_t port, uint8_t v);
+extern uint8_t dart_pr_in(uint8_t port);
+
extern void keyboard_down(int sym);
extern void keyboard_up(void);
diff --git a/abcprint.c b/abcprint.c
index af3e8ac..bf1299b 100644
--- a/abcprint.c
+++ b/abcprint.c
@@ -35,7 +35,7 @@ static int abcprint_read(void)
}
}
-static int abcprint_poll(void)
+static bool abcprint_poll(void)
{
return output_head != output_tail;
}
@@ -92,3 +92,71 @@ int printer_in(int sel, int port)
return v;
}
+
+/* Hardware-like interface via the ABC800 PR: port */
+static uint8_t dart_pr_ctl[8];
+
+void dart_pr_out(uint8_t port, uint8_t v)
+{
+ uint8_t r;
+
+ switch (port & 1) {
+ case 0: /* Data port */
+ if (dart_pr_ctl[5] & 0x08)
+ abcprint_recv(&v, 1);
+ break;
+
+ case 1: /* Control port */
+ r = dart_pr_ctl[0] & 7;
+ dart_pr_ctl[0] &= ~7;
+ dart_pr_ctl[r] = v;
+ /* Should to things like supporting interrupts here */
+ break;
+ }
+}
+
+uint8_t dart_pr_in(uint8_t port)
+{
+ uint8_t r, v = 0;
+
+ switch (port & 1) {
+ case 0: /* Data port */
+ if (dart_pr_ctl[3] & 1)
+ v = abcprint_read();
+ break;
+
+ case 1:
+ r = dart_pr_ctl[0] & 7;
+ dart_pr_ctl[0] &= ~7;
+
+ switch (r) {
+ case 0: /* RR0 primary status */
+ /*
+ * 7 - 0 - No break
+ * 6 - 0 - No transmit underrun
+ * 5 - 1 - CTS# asserted
+ * 4 - x - RI# asserted if 80 columns on boot
+ * 3 - 1 - DCD# asserted
+ * 2 - 1 - Transmit buffer empty
+ * 1 - 0 - Interrupt not pending
+ * 0 - x - Receive character available
+ */
+ v = 0x2c | (!startup_width40 << 4) | (dart_pr_ctl[3] & abcprint_poll());
+ break;
+
+ case 1: /* RR1 Rx special modes */
+ /*
+ * 5 - 0 - No receiver overrun
+ * 4 - 0 - No parity error
+ * 0 - 1 - All sent
+ */
+ v = 0x01;
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ return v;
+}
diff --git a/hostfile.h b/hostfile.h
index cf78721..64f78c9 100644
--- a/hostfile.h
+++ b/hostfile.h
@@ -3,6 +3,11 @@
#include "compiler.h"
+static inline bool is_stdio(const char *filename)
+{
+ return !filename || !filename[0] || (filename[0] == '-' && !filename[1]);
+}
+
enum host_file_mode {
HF_BINARY = 0, /* Raw binary */
HF_TEXT = 1, /* Text mode compatible with ASCII */
diff --git a/print.c b/print.c
index ea60d42..4bf4b9d 100644
--- a/print.c
+++ b/print.c
@@ -153,10 +153,13 @@ void abcprint_recv(const void *data, size_t len)
break;
case is_console:
- if (c == 0)
+ if (c == 0) {
is = is_normal;
- else if (console_file)
+ if (console_file)
+ fflush(console_file);
+ } else if (console_file) {
fputc(c, console_file);
+ }
break;
}
}