aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-02-11 12:00:26 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-02-11 12:00:26 +0100
commitb0338898e59cb90ea82c4cacd3dc9ec2db5a5486 (patch)
tree0eebe02bf385ad086385e66bdac44a598ebbd486
parent0fc9b7afd59a453fe08b7b0c93f11d234500a0be (diff)
implemnt i/o mask
-rw-r--r--core.go12
1 files changed, 8 insertions, 4 deletions
diff --git a/core.go b/core.go
index 795ccd3..2c262b8 100644
--- a/core.go
+++ b/core.go
@@ -18,8 +18,10 @@ type Console interface {
}
// Core of J1 Forth CPU
+//
+// memory: 0x2000 words (16k) addressed by byte
type Core struct {
- memory [0x4000]uint16 // 0..0x3fff main memory, 0x4000 .. 0x7fff mem-mapped i/o
+ memory [0x2000]uint16 // 0..0x3fff main memory, 0x4000 .. 0xffff mem-mapped i/o
pc uint16 // 13 bit
st0 uint16 // top of data stack
d, r stack // data and return stacks
@@ -61,8 +63,10 @@ func (c *Core) String() string {
return s
}
+const ioMask = 3 << 14
+
func (c *Core) writeAt(addr, value uint16) error {
- if off := int(addr >> 1); off < len(c.memory) {
+ if addr&ioMask == 0 {
c.memory[addr>>1] = value
}
switch addr {
@@ -75,8 +79,8 @@ func (c *Core) writeAt(addr, value uint16) error {
}
func (c *Core) readAt(addr uint16) uint16 {
- if off := int(addr >> 1); off < len(c.memory) {
- return c.memory[off]
+ if addr&ioMask == 0 {
+ return c.memory[addr>>1]
}
switch addr {
case 0xf000: // tx!