aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--console.go6
-rw-r--r--eval.go4
-rw-r--r--j1eforth/j1.c28
3 files changed, 33 insertions, 5 deletions
diff --git a/console.go b/console.go
index a29c4ad..388b207 100644
--- a/console.go
+++ b/console.go
@@ -18,7 +18,11 @@ func NewConsole() *Console {
}
func (c *Console) Read(p []byte) (int, error) {
- return c.r.Read(p)
+ n, err := c.r.Read(p)
+ if n > 0 && p[0] == 10 {
+ p[0] = 13
+ }
+ return n, err
}
func (c *Console) Write(p []byte) (int, error) {
diff --git a/eval.go b/eval.go
index 363f3f2..2b41f6e 100644
--- a/eval.go
+++ b/eval.go
@@ -55,14 +55,14 @@ func (j1 *J1) Eval() {
return
}
j1.eval(ins)
- //fmt.Printf("%4d %v %v\n", n, ins, j1)
+ //fmt.Printf("%4d %v\n%v", n, ins, j1)
}
}
func (j1 *J1) String() string {
s := fmt.Sprintf("\tPC=%0.4X ST=%0.4X\n", j1.pc, j1.st0)
s += fmt.Sprintf("\tD=%0.4X\n", j1.dstack[:j1.dsp+1])
- s += fmt.Sprintf("\tR=%0.4X", j1.rstack[:j1.rsp+1])
+ s += fmt.Sprintf("\tR=%0.4X\n", j1.rstack[:j1.rsp+1])
return s
}
diff --git a/j1eforth/j1.c b/j1eforth/j1.c
index 461e899..c62938f 100644
--- a/j1eforth/j1.c
+++ b/j1eforth/j1.c
@@ -53,6 +53,8 @@ static int pop(void) // pop value from the data stack and return it
static void execute(int entrypoint)
{
+ int i = 0;
+ int j = 0;
int _pc, _t;
int insn = 0x4000 | entrypoint; // first insn: "call entrypoint"
do {
@@ -92,7 +94,12 @@ static void execute(int entrypoint)
case 9: _t = s>>t; break; /* rshift */
case 0xa: _t = t-1; break; /* 1- */
case 0xb: _t = r[rsp]; break; /* r@ */
- case 0xc: _t = (t==0xf001)?1:(t==0xf000)?getch():memory[t>>1]; break; /* @ */
+ case 0xc: switch (t) {
+ case 0xf001: _t = 1; break;
+ case 0xf000: _t = getch(); break;
+ default: _t = memory[t>>1]; break;
+ }
+ break; /* @ */
case 0xd: _t = s<<t; break; /* lshift */
case 0xe: _t = (rsp<<8) + dsp; break; /* dsp */
case 0xf: _t = -(s<t); break; /* u< */
@@ -104,13 +111,30 @@ static void execute(int entrypoint)
if (insn & 0x40) /* t->r */
r[rsp] = t;
if (insn & 0x20) /* s->[t] */
- (t==0xf002)?(rsp=0):(t==0xf000)?putch(s):(memory[t>>1]=s); /* ! */
+ switch (t) {
+ case 0xf002: rsp = 0; break;
+ case 0xf000: putch(s); break;
+ default: memory[t>>1]=s; break; /* ! */
+ }
t = _t;
break;
}
}
pc = _pc;
insn = memory[pc];
+#if DEBUG
+ printf("%d: pc: %0.4x; sp: %0.4x\n", i, pc, t);
+ printf("\td:");
+ for (j = 0; j < dsp; j++) {
+ printf(" %0.4x", d[j]);
+ }
+ printf("\n\tr:");
+ for (j = 0; j < rsp; j++) {
+ printf(" %0.4x", r[j]);
+ }
+ printf("\n");
+#endif
+ i++;
} while (1);
}
/* end of cpu */