Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Jessica Hawkwell
/
kcpu
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit eb9f4a4c
authored
Sep 28, 2017
by
Jessica Hawkwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new ops, cleanup
1 parent
0ce4a166
Pipeline
#207
passed
in 1 minute 4 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
55 deletions
src/main/java/me/felinewith/kcpu/KBoard.java
src/main/java/me/felinewith/kcpu/Kcpu.java
src/main/java/me/felinewith/kcpu/memory/BootRom.java
src/main/java/me/felinewith/kcpu/opcodes/BasicMath.java
src/main/java/me/felinewith/kcpu/opcodes/OpDirector.java
src/main/java/me/felinewith/kcpu/util/BaseMemory.java
src/main/java/me/felinewith/kcpu/KBoard.java
View file @
eb9f4a4
...
...
@@ -26,9 +26,9 @@ import me.felinewith.kcpu.util.HardwareMemIrq;
*/
public
class
KBoard
extends
BaseDevice
implements
IMemory
{
private
final
ThreadPoolExecutor
tpe
;
private
TimerTask
tt
;
private
Timer
t
;
final
ThreadPoolExecutor
tpe
;
TimerTask
tt
;
Timer
t
;
private
final
IDevice
[]
devices
;
private
final
KMemoryRange
[]
deviceMaps
;
...
...
@@ -115,7 +115,7 @@ public class KBoard extends BaseDevice implements IMemory {
short
devAddr
=
(
short
)(
addr
-
devOff
);
return
memDevs
[
rdev
].
read
(
devAddr
);
}
return
memory
[
addr
];
return
memory
[
0xffff
&
addr
];
}
@Override
public
void
write
(
short
addr
,
byte
data
)
{
...
...
@@ -130,9 +130,13 @@ public class KBoard extends BaseDevice implements IMemory {
short
devOff
=
memDevMaps
[
rdev
].
getOffset
();
short
devAddr
=
(
short
)(
addr
-
devOff
);
memDevs
[
rdev
].
write
(
devAddr
,
data
);
if
(
rdev
==
0
)
{
try
{
bufout
.
write
(
0xff
&
data
);
}
catch
(
IOException
x
)
{}
}
}
memory
[
addr
]
=
data
;
memory
[
0xffff
&
addr
]
=
data
;
}
public
void
attachDevice
(
int
port
,
int
offset
,
IDevice
device
)
{
...
...
@@ -186,6 +190,39 @@ public class KBoard extends BaseDevice implements IMemory {
return
0x7f
;
}
public
void
detachDevice
(
short
port
)
{
if
(
port
>=
0x20
)
{
return
;
}
if
(
port
<=
0x0f
)
{
deviceMaps
[
port
]
=
null
;
}
else
{
memDevMaps
[(
short
)(
0x0f
&
port
)]
=
null
;
}
}
public
KMemoryRange
getDeviceRange
(
short
port
)
{
if
(
port
>=
0x20
)
{
return
new
KMemoryRange
((
short
)
0
,
(
short
)
0
);
}
KMemoryRange
kmr
;
if
(
port
<=
0x0f
)
{
kmr
=
deviceMaps
[
port
];
}
else
{
kmr
=
memDevMaps
[(
short
)(
0x0f
&
port
)];
}
return
new
KMemoryRange
(
kmr
.
getOffset
(),
kmr
.
getLength
());
}
public
void
setDeviceRange
(
short
device
,
short
addr
)
{
if
(
device
>=
0x20
)
{
return
;
}
short
dev
=
(
short
)(
0x0f
&
device
);
if
(
device
<=
0x0f
)
{
if
(
devices
[
dev
]
==
null
)
{
}
else
if
(
deviceMaps
[
dev
]
==
null
)
{
deviceMaps
[
dev
]
=
new
KMemoryRange
(
addr
,
devices
[
dev
].
length
());
}
else
{
deviceMaps
[
dev
].
offset
=
addr
;
}
}
else
{
if
(
memDevs
[
dev
]
==
null
)
{
}
else
if
(
memDevMaps
[
dev
]
==
null
)
{
memDevMaps
[
dev
]
=
new
KMemoryRange
(
addr
,
memDevs
[
dev
].
length
());
}
else
{
memDevMaps
[
dev
].
offset
=
addr
;
}
}
}
@Override
public
void
exec
()
{
try
{
if
(
bufin
.
ready
()
)
{
...
...
src/main/java/me/felinewith/kcpu/Kcpu.java
View file @
eb9f4a4
...
...
@@ -40,7 +40,7 @@ public class Kcpu extends TimerTask implements IDevice {
@Override
public
byte
read
(
short
addr
)
{
if
(
(
0xffff
&
addr
)
>
length
()
)
{
return
(
byte
)
0xff
;
}
return
memory
[
addr
];
return
memory
[
0xffff
&
addr
];
}
@Override
public
void
write
(
short
offset
,
byte
data
)
{
}
...
...
@@ -56,6 +56,7 @@ public class Kcpu extends TimerTask implements IDevice {
@Override
public
void
sendIrq
(
byte
irq
)
{
board
.
sendIrq
(
irq
);
}
private
void
workCycle
()
{
if
(
pc
>=
0xfff0
)
{
pc
=
0
;
}
short
inst
=
MemHelper
.
readShort
(
pc
,
board
);
short
ref
=
MemHelper
.
readShort
(
pc
+
2
,
board
);
short
[]
values
=
new
short
[
4
];
...
...
@@ -72,45 +73,43 @@ public class Kcpu extends TimerTask implements IDevice {
}
}
if
(
od
==
null
)
{
pc
+=
2
;
return
;
}
// inc 2 if nop
if
(
od
==
null
)
{
pc
+=
1
2
;
return
;
}
// inc 2 if nop
if
(
od
.
hasHandler
()
)
{
registers
=
od
.
call
(
pc
,
ref
,
registers
,
values
,
board
);
int
vt
=
od
.
getArgs
();
pc
+=
2
;
if
(
vt
!=
0
)
{
pc
+=
2
+
(
vt
*
2
);
}
pc
+=
12
;
return
;
}
pc
+=
12
;
short
data
;
data
=
ValueHelper
.
readValue
(
0
,
ref
,
registers
,
values
,
board
);
switch
(
od
)
{
// ask what device is using which address
case
ASK:
data
=
board
.
checkDevice
((
short
)(
0x000f
&
data
));
registers
=
ValueHelper
.
writeValue
(
1
,
ref
,
registers
,
values
,
board
,
data
);
// device management
case
DEVA:
registers
[
0
]
=
board
.
checkDevice
(
data
);
return
;
case
DEVD:
board
.
detachDevice
(
data
);
return
;
case
DEVM:
short
d2
=
ValueHelper
.
readValue
(
1
,
ref
,
registers
,
values
,
board
);
board
.
setDeviceRange
(
data
,
d2
);
return
;
// interrupt to port
case
IRQD:
board
.
sendIrq
((
byte
)(
0x000f
&
data
)
);
case
DEVP:
KMemoryRange
kmr
=
board
.
getDeviceRange
(
data
);
registers
[
0
]
=
kmr
.
getOffset
();
registers
[
1
]
=
kmr
.
getLength
(
);
return
;
// interrupt to memory address
case
IRQM:
board
.
memIrq
(
data
);
return
;
// interrupts
case
IRQD:
board
.
sendIrq
((
byte
)(
0x000f
&
data
));
return
;
case
IRQM:
board
.
memIrq
(
data
);
return
;
// jump absolute
// jumps
case
JMP:
pc
=
(
short
)(
pc
+
(
0xffff
&
data
));
return
;
case
JMPA:
pc
=
data
;
return
;
// jump down
case
JMPD:
pc
=
(
short
)(
pc
-
(
0xffff
&
data
));
return
;
// jump up
case
JMP:
pc
=
(
short
)(
pc
+
(
0xffff
&
data
));
return
;
case
ZPWR:
board
.
t
.
cancel
()
;
}
}
}
src/main/java/me/felinewith/kcpu/memory/BootRom.java
View file @
eb9f4a4
...
...
@@ -11,7 +11,15 @@ public class BootRom extends BaseMemory {
public
BootRom
()
{
memory
=
new
byte
[
0x1000
];
Arrays
.
fill
(
memory
,
(
byte
)
0x75
);
Arrays
.
fill
(
memory
,
(
byte
)
0xff
);
// hardcoding some bootrom
memory
[
0
]
=
0x11
;
memory
[
1
]
=
0x00
;
memory
[
2
]
=
0x01
;
memory
[
3
]
=
0x00
;
memory
[
4
]
=
0x61
;
memory
[
5
]
=
0x41
;
}
@Override
public
void
write
(
short
offset
,
byte
data
)
{
}
...
...
src/main/java/me/felinewith/kcpu/opcodes/BasicMath.java
View file @
eb9f4a4
...
...
@@ -15,17 +15,14 @@ public class BasicMath implements IHandler {
short
vb
=
ValueHelper
.
readValue
(
1
,
ref
,
output
,
values
,
memory
);
switch
(
opcode
)
{
case
ADD:
va
+=
vb
;
break
;
case
ADD:
output
[
0
]
=
(
short
)(
va
+
vb
)
;
break
;
case
DIV:
short
rem
=
(
short
)(
va
%
vb
);
va
/=
vb
;
vb
=
rem
;
output
[
0
]
=
(
short
)(
va
/
vb
);
output
[
1
]
=
(
short
)(
va
%
vb
);
break
;
case
MUL:
va
*=
vb
;
break
;
case
SUB:
va
-=
vb
;
break
;
case
MUL:
output
[
0
]
=
(
short
)(
va
*
vb
)
;
break
;
case
SUB:
output
[
0
]
=
(
short
)(
va
-
vb
)
;
break
;
}
output
=
ValueHelper
.
writeValue
(
0
,
ref
,
output
,
values
,
memory
,
va
);
output
=
ValueHelper
.
writeValue
(
1
,
ref
,
output
,
values
,
memory
,
vb
);
return
output
;
}
...
...
src/main/java/me/felinewith/kcpu/opcodes/OpDirector.java
View file @
eb9f4a4
...
...
@@ -18,14 +18,19 @@ public enum OpDirector {
MOV
(
0x0011
,
Memory
.
class
),
// cpu stuffies
ASK
(
0x1000
,
null
),
DEVA
(
0xff00
,
null
),
// get device port from address
DEVD
(
0xff01
,
null
),
// detach device
DEVM
(
0xff02
,
null
),
// relocate device
DEVP
(
0x1003
,
null
),
// get device address from port
IRQ
M
(
0x8f00
,
null
),
IRQ
D
(
0x8f10
,
null
),
IRQ
D
(
0xff10
,
null
),
// interrupt to port
IRQ
M
(
0xff11
,
null
),
// interrupt to memory
JMP
(
0x8f08
,
null
),
JMPA
(
0x8f0c
,
null
),
JMPD
(
0x8f18
,
null
),
JMP
(
0xff18
,
null
),
// jump up
JMPA
(
0xff19
,
null
),
// jump absolute addr
JMPD
(
0xff1a
,
null
),
// jump down
ZPWR
(
0xffff
,
null
),
// power off
;
...
...
@@ -51,14 +56,4 @@ public enum OpDirector {
catch
(
IllegalAccessException
|
InstantiationException
e
)
{}
return
regs
;
}
public
int
getArgs
()
{
try
{
if
(
c
==
null
)
{
return
0
;
}
IHandler
ih
=
c
.
newInstance
();
return
ih
.
getArgs
(
this
);
}
catch
(
IllegalAccessException
|
InstantiationException
e
)
{}
return
0
;
}
}
src/main/java/me/felinewith/kcpu/util/BaseMemory.java
View file @
eb9f4a4
...
...
@@ -17,13 +17,13 @@ public abstract class BaseMemory implements IMemory {
public
final
byte
read
(
int
addr
)
{
return
read
((
short
)
addr
);
}
@Override
public
byte
read
(
short
addr
)
{
if
(
(
0xffff
&
addr
)
>
length
()
)
{
return
(
byte
)
0xff
;
}
return
memory
[
addr
];
return
memory
[
0xffff
&
addr
];
}
public
final
void
write
(
int
addr
,
byte
data
)
{
write
((
short
)
addr
,
data
);
}
@Override
public
void
write
(
short
addr
,
byte
data
)
{
if
(
(
0xffff
&
addr
)
>
length
()
)
{
return
;
}
memory
[
addr
]
=
data
;
memory
[
0xffff
&
addr
]
=
data
;
}
public
final
void
copy
(
int
addrSrc
,
int
addrDest
,
IMemory
dest
)
{
copy
((
short
)
addrSrc
,
(
short
)
addrDest
,
dest
);
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment