Permalink
Browse files

Add reset method to IHardware.

  • Loading branch information...
1 parent 588288d commit e48fdfa9b0ddff0e047079ee594e71f43e339ec1 @bhelyer committed Apr 29, 2012
Showing with 39 additions and 5 deletions.
  1. +10 −0 DDCPU-16/clock.d
  2. +3 −0 DDCPU-16/dcpu16/hardware.d
  3. +10 −1 DDCPU-16/display.d
  4. +7 −4 DDCPU-16/floppy.d
  5. +9 −0 DDCPU-16/keyboard.d
View
@@ -24,6 +24,16 @@ class Clock : IHardware
this.cpu = cpu;
}
+ void reset() @safe
+ {
+ enabled = false;
+ interruptsEnabled = false;
+ imessage = 0;
+ framesPerTick = 0;
+ tickCounter = 0;
+ frameCounter = 0;
+ }
+
/// Called by the CPU when this hardware is the target of an HWQ op.
void query() @safe
{
@@ -8,6 +8,9 @@ interface IHardware
/// Called by the CPU when this hardware device is registered.
void attach(CPU cpu) @safe;
+ /// Reset the hardware to an initial state.
+ void reset() @safe;
+
/// Called by the CPU when this hardware is the target of an HWQ op.
void query() @safe;
View
@@ -51,11 +51,20 @@ class Display : IHardware
}
+ void reset() @safe
+ {
+ texture[] = 0xFF1F1F1F;
+ background = 0;
+ vramBase = 0;
+ userFont = font.ptr;
+ userPalette = 0;
+ blink = false;
+ }
+
/// Called by the CPU when this hardware device is registered.
void attach(CPU cpu) @safe
{
this.cpu = cpu;
-
}
/// Called by the CPU when this hardware is the target of an HWQ op.
View
@@ -143,10 +143,13 @@ public:
}
}
- bool pendingInterrupt(out ushort message) @safe
- {
- return false;
- }
+ void reset() @safe
+ {
+ flags = 0;
+ intMessage = 0xFFFF;
+ geom = DiskGeometry(80, 18, 1440, 512);
+ track = 0;
+ }
private:
/// The CPU we're attached to.
View
@@ -25,6 +25,15 @@ class Keyboard : Entity, IHardware
this.cpu = cpu;
}
+ void reset() @safe
+ {
+ buffer.length = 0;
+ interruptsEnabled = false;
+ imessage = 0;
+ foreach (k, v; pressedKeys) pressedKeys.remove(k);
+ foreach (k, v; pressedChars) pressedChars.remove(k);
+ }
+
/// Called by the CPU when this hardware is the target of an HWQ op.
void query() @safe
{

0 comments on commit e48fdfa

Please sign in to comment.