Skip to content

Commit 91fafb6

Browse files
committed
Merge pull request #38 from dbent/version/0.5.0
Version/0.5.0
2 parents b70b173 + 36c98f6 commit 91fafb6

File tree

18 files changed

+1595
-106
lines changed

18 files changed

+1595
-106
lines changed
34.3 KB
Loading
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
; Move the firmware to 0xFDFF to free up space for the boot sector
2+
:init
3+
SET I, firmware
4+
SET J, 0xFDFF
5+
:move
6+
IFE I, 0xFDFF
7+
SET PC, load
8+
STI [J], [I]
9+
SET PC, move
10+
11+
:firmware
12+
.org 0xFDFF
13+
:load
14+
; Enumerate devices
15+
HWN I
16+
:device_loop
17+
SUB I, 1
18+
IFE I, 0xFFFF
19+
SET PC, device_loop_complete
20+
; Query selected device and see if it's a hard disk or LEM-1802
21+
HWQ I
22+
IFE A, 0x24c5
23+
IFE B, 0x4fd5
24+
SET [io_m35fd], I
25+
IFE A, 0xF615
26+
IFE B, 0x7349
27+
SET [io_lem1802], I
28+
SET PC, device_loop
29+
:device_loop_complete
30+
; Check for error conditions
31+
IFE [io_m35fd], 0xFFFF
32+
SET PC, error_nodrive
33+
; Check for disk
34+
SET A, 0 ; Poll device
35+
HWI [io_m35fd]
36+
IFE B, 0 ; STATE_NO_MEDIA
37+
SET PC, error_nodisk
38+
:copy_disk
39+
; Copy the first 127 sectors from the disk to memory
40+
SET A, 2 ; Read sector
41+
SET X, 0 ; sector
42+
SET Y, 0 ; memory address
43+
:copy_loop
44+
HWI [io_m35fd]
45+
IFN B, 1
46+
SET PC, error_readerror
47+
:wait_for_completion
48+
SET A, 0
49+
HWI [io_m35fd]
50+
IFE B, 1 ; Device ready
51+
SET PC, copy_next_sector
52+
SET PC, wait_for_completion
53+
54+
:copy_next_sector
55+
IFE X, 127 ; copied last sector
56+
SET PC, boot ; Launch boot sector (DONE)
57+
SET A, 2
58+
ADD X, 1
59+
ADD Y, 512
60+
SET PC, copy_loop
61+
62+
:error_nodrive
63+
IFE [io_lem1802], 0xFFFF
64+
SET PC, end ; Hang forever if there is no screen
65+
JSR map_screen
66+
SET I, msg_nodrive
67+
SET PC, print_err
68+
69+
:error_nodisk
70+
IFE [io_lem1802], 0xFFFF
71+
SET PC, end ; Hang forever if there is no screen
72+
JSR map_screen
73+
SET I, msg_nodisk
74+
SET PC, print_err
75+
76+
:error_readerror
77+
IFE [io_lem1802], 0xFFFF
78+
SUB PC, 1 ; Hang forever if there is no screen
79+
JSR map_screen
80+
SET I, msg_readerror
81+
SET PC, print_err
82+
83+
:map_screen
84+
SET A, 0
85+
SET B, 0x8000
86+
HWI [io_lem1802]
87+
SET PC, POP
88+
89+
:print_err
90+
SET J, 0x8000
91+
:print_loop
92+
IFE [I], 0
93+
SET PC, end ; Hang
94+
SET C, [I]
95+
BOR C, 0xF000
96+
STI [J], C
97+
SET PC, print_loop
98+
99+
:end
100+
SET PC, end
101+
102+
:boot
103+
; Zero registers
104+
SET A, 0
105+
SET B, 0
106+
SET C, 0
107+
SET X, 0
108+
SET Y, 0
109+
SET I, 0
110+
SET J, 0
111+
SET SP, 0
112+
SET PC, 0
113+
114+
:msg_nodrive
115+
dat "ATTACH M35FD AND REBOOT", 0
116+
:msg_nodisk
117+
dat "INSERT DISK AND REBOOT", 0
118+
:msg_readerror
119+
dat "DRIVE READ ERROR", 0
120+
121+
:io_m35fd
122+
dat 0xFFFF
123+
:io_lem1802
124+
dat 0xFFFF

GameData/Ketchup/Parts/Dcpu16ComputerStackLarge/part.cfg

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ MODULE
5959
RESOURCE
6060
{
6161
name = ElectricCharge
62-
rate = 0.02
62+
rate = 0.01
6363
}
6464
}
6565

66+
MODULE
67+
{
68+
name = Firmware
69+
}
70+
6671
MODULE
6772
{
6873
name = Lem1802
@@ -96,6 +101,17 @@ MODULE
96101
}
97102
}
98103

104+
MODULE
105+
{
106+
name = M35Fd
107+
108+
RESOURCE
109+
{
110+
name = ElectricCharge
111+
rate = 0.01
112+
}
113+
}
114+
99115
RESOURCE
100116
{
101117
name = ElectricCharge

GameData/Ketchup/Parts/Dcpu16ComputerStackSmall/part.cfg

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,15 @@ MODULE
5959
RESOURCE
6060
{
6161
name = ElectricCharge
62-
rate = 0.02
62+
rate = 0.01
6363
}
6464
}
6565

66+
MODULE
67+
{
68+
name = Firmware
69+
}
70+
6671
MODULE
6772
{
6873
name = Lem1802
@@ -96,6 +101,17 @@ MODULE
96101
}
97102
}
98103

104+
MODULE
105+
{
106+
name = M35Fd
107+
108+
RESOURCE
109+
{
110+
name = ElectricCharge
111+
rate = 0.01
112+
}
113+
}
114+
99115
RESOURCE
100116
{
101117
name = ElectricCharge
-154 Bytes
Binary file not shown.

README.md

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
Ketchup
22
===========
33

4-
*Ketchup* is a mod for [Kerbal Space Program][ksp] which implements a programmable CPU.
4+
**Ketchup** is a mod for [Kerbal Space Program][ksp] which implements a programmable CPU and associated devices.
55

66
Description
77
---------------
88
The CPU is an implementation of the [DCPU-16][dcpu] [spec][dcpu-spec], originally designed by
99
[Markus "Notch" Persson][notch] for the game [0x10c][0x10c]. Emulation of the CPU is provided by the
10-
[Tomato][tomato] library. Implementations of the [monitor][monitor-spec], [keyboard][keyboard-spec], and
11-
[clock][clock-spec] devices are also dervied from Tomato.
10+
[Tomato][tomato] library. Implementations of the [monitor][monitor-spec], [keyboard][keyboard-spec],
11+
[clock][clock-spec], and [floppy drive][floppy-spec] deivces are also provided.
1212

13-
*Ketchup* is currently at the proof-of-concept stage, with *many* features and improvements to be made. Most
14-
notably, there currently exist no devices capable of interacting with the vessel, so using the CPU for flight
15-
control is not currently possible. However, any program written for the DCPU-16 should be able to run within
16-
Kerbal Space Program.
13+
Ketchup is currently in the alpha stage, with *many* features and improvements to be made. Most notably, there
14+
currently exist no devices capable of interacting with the vessel, so using the CPU for flight control is not
15+
currently possible. However, any program written for the DCPU-16 should be able to run within Kerbal Space
16+
Program.
1717

18-
Downloads
18+
Releases
1919
------------
2020
Release information and downloads may be found on the GitHub [releases][releases] page.
2121

2222
Building
2323
------------
24-
In order to build *Ketchup* two assemblies are required from your Kerbal Space Program installation. Because
25-
there are no obvious distribution licenses for these libraries, they cannot be commited to source control.
24+
In order to build Ketchup two assemblies are required from your Kerbal Space Program installation. Because there
25+
are no obvious distribution licenses for these libraries, they cannot be commited to source control.
2626

2727
1. Make a `KSP` directory under the `Dependencies` directory.
2828
2. From the `KSP_Data/Managed` directory under your Kerbal Space Program installation, copy the following files to
@@ -43,20 +43,66 @@ directory in your Kerbal Space Program installation.
4343

4444
Usage
4545
---------
46-
Two new parts will appear in game under the "Pods" section of the craft editor: the **ENIAK-16S Computer** and
47-
the **ENIAK-16L Computer**, these "Mechanical Kerbal Brains" replace the **RC-001S Remote Guidance Unit** and the
48-
**RC-L01 Remote Guidance Unit** respectively. The computers will consume twice as much electricity as a remote
46+
Two new parts will appear in game under the "Pods" section of the craft editor: the *ENIAK-16S Computer* and the
47+
*ENIAK-16L Computer*, these "Mechanical Kerbal Brains" replace the *RC-001S Remote Guidance Unit* and the
48+
*RC-L01 Remote Guidance Unit* respectively. The computers will consume twice as much electricity as a remote
4949
guidance unit however. Construct a rocket normally with one of the new parts.
5050

51-
When you're ready to launch you should see a new window with the name of the computer you added. In the text
52-
field labelled "Memory Image" enter `helloworld.bin` and then click the **PWR** button. You should now see
53-
`Hello, world!` displayed on the monitor. You can write custom programs in DCPU-16 assembly and build them with an
54-
assembler, such as [Organic][organic]. Copy the built binary to the `GameData/Ketchup/Plugins/PluginData/Ketchup`
55-
directory, and you should be able to run it like `helloworld.bin`.
51+
When you're reading to launch, right click on the computer part to bring up its context menu. Among the usual
52+
options will be several options to toggle the interface of several devices. Toggle each of them on.
53+
54+
![Ketchup Windows](Documentation/Images/ketchup-0.5.0.png)
55+
56+
### Computer
57+
The computer window allows you to control power to the computer via the **PWR** button, it also displays if the
58+
computer is powered off, is halted, or is running by showing the average clock speed.
59+
60+
### Firmware
61+
The firmware window allows you to flash the built-in firmware/bios. The firmware contains the first code that is
62+
executed by the CPU when it powers on an is usually used to bootstrap the computer from other media. The firmware
63+
device comes preloaded with a default firmware which will search for a floppy drive and load the first sector
64+
(512 words) from the floppy into memory and execute it. If the program on the floppy disk is longer than 512 words
65+
additional bootstrap code would be required to load additonal sectors into memory. Alternatively, a custom
66+
firmware may be used to load additional sectors into memory. One such firmware, `firmware_127sectors_v1.dasm`, is
67+
provided in the `Contrib/Firmware` directory of the distribution. As its name suggests, it automatically reads the
68+
first 127 sectors (65024 words) from the floppy disk into memory. This actually, takes some time, so do not be
69+
alarmed if your program takes some time to load. To use this firmware, first assemble it into a big-endian binary
70+
image using a DCPU-16 assembler, such as [Organic][organic]. Then create a directory:
71+
`Kerbal Space Program/saves/<profilename>/Ketchup/Firmware` under your Kerbal Space Program installation path.
72+
Now, when you press the **Flash** button in the firmware window, you should be given the option to use the
73+
custom firmware.
74+
75+
### Keyboard
76+
The keyboard window contains a single button, **Attach**, which when enabled sends your keyboard input to the
77+
computer.
78+
79+
### LEM-1802
80+
The LEM-1802 window displays the standard monitor. The monitor's resolution of 128x96 pixels might be very small,
81+
so the buttons at the bottom allow you to change the scaling of the display.
82+
83+
### M35FD
84+
The M35FD window allows you to interact with the M35FD floppy drive. Each vessels maintains its own copies of
85+
floppy disks, but you may retrieve standard floppy disks via the **Get Disk** button. The **Get Disk** button will
86+
always give you the option to retrieve a blank disk, but it will also list any floppy disk images you have in
87+
`Kerbal Space Program/saves/<profilename>/Ketchup/FloppyDisks`. Image files may end in `.bin` or `.img`. Standard
88+
object code generated by a DCPU-16 assembler may be used as a floppy disk image. See the previous discussion under
89+
*Firmware* for how to load programs larger than a single sector.
90+
91+
Once you have retrieved a list, it will be listed under the vessel's available disks. At this point you have three
92+
options to manipulate the disk, you can use the **Label** button to change the label of the disk, the **Protect**
93+
button to enable write protection on the disk, and **Destroy** to destroy the disk forever. If the M35FD is empty
94+
you may press the **Insert** button, at which point you may select an available disk to insert into the drive.
95+
When inserted, the disk's label will be displayed and you then have the option to press the **Eject** button to
96+
eject it.
97+
98+
### Time Warp Note
5699

57100
When a computer is powered on on a vessel, time warp is limited to 4x. Computers have a clock speed of 100KHz,
58-
relative to game time (up to 400KHz relative to real time). Please check the GitHub [issue tracker][issues] for a
59-
list of all current issues.
101+
relative to game time (up to 400KHz relative to real time).
102+
103+
Issues
104+
----------
105+
Please check the GitHub [issue tracker][issues] for a list of all current issues (bugs or enhancements).
60106

61107
Name
62108
--------
@@ -66,6 +112,7 @@ Name
66112
[clock-spec]: http://dcpu.com/clock/
67113
[dcpu]: http://dcpu.com/
68114
[dcpu-spec]: http://dcpu.com/dcpu-16/
115+
[floppy-spec]: http://dcpu.com/floppy-drive/
69116
[issues]: https://github.com/dbent/Ketchup/issues
70117
[keyboard-spec]: http://dcpu.com/keyboard/
71118
[ksp]: https://kerbalspaceprogram.com/

0 commit comments

Comments
 (0)