Skip to content

Commit

Permalink
Merge pull request #19 from dbent/version/0.2.0
Browse files Browse the repository at this point in the history
Version/0.2.0
  • Loading branch information
dbent committed Jul 21, 2013
2 parents 2bcba1d + 92e39e4 commit a9ce580
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
26 changes: 22 additions & 4 deletions Ketchup/Dcpu16Computer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class Dcpu16Computer : PartModule
private static bool _hasInitPosition;
private static bool _hasInitStyles;

private static double _monitorImageScale = 1;

#endregion

#region Devices
Expand Down Expand Up @@ -177,7 +179,7 @@ private void OnWindow(int windowId)
}
}

var monitorImage = _lem1802.GetScreenImage(scale: 4);
var monitorImage = _lem1802.GetScreenImage();

var pressedStyle = new GUIStyle(_styleButton) { normal = _styleButton.active };

Expand All @@ -190,18 +192,28 @@ private void OnWindow(int windowId)
var kbdButtonPressed = GUILayout.Button("KBD", _isKeyboardAttached ? pressedStyle : _styleButton, GUILayout.ExpandWidth(false));
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label("Memory Image:", _styleLabel, GUILayout.Width(100));
GUILayout.Label("Memory Image:", new GUIStyle(_styleLabel) { stretchWidth = true });
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (_isPowerOn)
{
GUILayout.Label(_program, _styleLabel, GUILayout.Width(400));
GUILayout.Label(_program, new GUIStyle(_styleLabel) { stretchWidth = true });
}
else
{
_program = GUILayout.TextField(_program, _styleTextField);
}
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Box(monitorImage, _styleBox, GUILayout.Width(monitorImage.width + 8), GUILayout.Height(monitorImage.height + 8));
GUILayout.Box(String.Empty, _styleBox, GUILayout.Width((int)(monitorImage.width * _monitorImageScale)), GUILayout.Height((int)(monitorImage.height * _monitorImageScale)));
var imageRect = GUILayoutUtility.GetLastRect();
GUI.DrawTexture(imageRect, monitorImage, ScaleMode.ScaleToFit);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
if (GUILayout.Button("1x", _styleButton)) { SetMonitorScale(1); }
if (GUILayout.Button("2x", _styleButton)) { SetMonitorScale(2); }
if (GUILayout.Button("3x", _styleButton)) { SetMonitorScale(3); }
if (GUILayout.Button("4x", _styleButton)) { SetMonitorScale(4); }
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Label(actualClockSpeedFormatted, _styleLabel);
Expand Down Expand Up @@ -277,5 +289,11 @@ private void OnPowerButtonPressed()
_isPowerOn = true;
}
}

private void SetMonitorScale(double scale)
{
_monitorImageScale = scale;
_windowPosition = new Rect(_windowPosition) { width = 0, height = 0 };
}
}
}
21 changes: 5 additions & 16 deletions Ketchup/Devices/Lem1802.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public override ushort Version

public Lem1802()
{
_screenTexture = new Texture2D(Width, Height);
_screenTexture = new Texture2D(Width, Height) { filterMode = FilterMode.Point };
_blinkTimer = new Timer(ToggleBlinker, null, BlinkRate, BlinkRate);
}

Expand Down Expand Up @@ -138,13 +138,8 @@ public override void Reset()
_borderColorValue = 0;
}

public Texture2D GetScreenImage(int scale = 1)
public Texture2D GetScreenImage()
{
if (_screenTexture.width != Width * scale || _screenTexture.height != Height * scale)
{
_screenTexture = new Texture2D(Width * scale, Height * scale);
}

if (_screenMap == 0)
{
for (var x = 0; x < _screenTexture.width; x++)
Expand Down Expand Up @@ -177,21 +172,15 @@ public Texture2D GetScreenImage(int scale = 1)
{
Color color;

var tx = (i / 8 + (x * CharWidth)) * scale;
var ty = Math.Abs((i % 8 + (y * CharHeight)) - (Height - 1)) * scale;
var tx = (i / 8 + (x * CharWidth));
var ty = Math.Abs((i % 8 + (y * CharHeight)) - (Height - 1));

if ((fontValue & 1) == 0 || (((value & 0x80) == 0x80) && !_blinkOn))
color = background;
else
color = foreground;

for (var j = 0; j < scale; j++)
{
for (var k = 0; k < scale; k++)
{
_screenTexture.SetPixel(tx + j, ty + k, color);
}
}
_screenTexture.SetPixel(tx, ty, color);

fontValue >>= 1;
}
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ notably, there currently exist no devices capable of interacting with the vessel
control is not currently possible. However, any program written for the DCPU-16 should be able to run within
Kerbal Space Program.

Downloads
------------
Release information and downloads may be found on the GitHub [releases][releases] page.

Building
------------
In order to build *Ketchup* two assemblies are required from your Kerbal Space Program installation. Because
Expand Down Expand Up @@ -45,7 +49,7 @@ the **ENIAK-16L Computer**, these "Mechanical Kerbal Brains" replace the **RC-00
guidance unit however. Construct a rocket normally with one of the new parts.

When you're ready to launch you should see a new window with the name of the computer you added. In the text
field labelled "Memory Image" enter `helloworld.bin` and then click the **PWR** button. You should know see
field labelled "Memory Image" enter `helloworld.bin` and then click the **PWR** button. You should now see
`Hello, world!` displayed on the monitor. You can write custom programs in DCPU-16 assembly and build them with an
assembler, such as [Organic][organic]. Copy the built binary to the `GameData/Ketchup/Plugins/PluginData/Ketchup`
directory, and you should be able to run it like `helloworld.bin`.
Expand All @@ -68,5 +72,6 @@ Name
[monitor-spec]: http://dcpu.com/monitor/
[notch]: https://mojang.com/notch/
[organic]: https://github.com/SirCmpwn/organic
[releases]: https://github.com/dbent/Ketchup/releases
[tomato]: https://github.com/SirCmpwn/Tomato
[tomato-ksp-compat]: https://github.com/dbent/Tomato/tree/ksp-compat

0 comments on commit a9ce580

Please sign in to comment.