1 /** 2 Copyright: Copyright (c) 2013-2014 Andrey Penechko. 3 License: a$(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 7 8 module emulator.dcpu.devices.idevice; 9 10 //import dcpu.dcpu; 11 import emulator.dcpu.emulator; 12 13 @trusted nothrow: 14 15 abstract class IDevice(Cpu) : IUndoable 16 { 17 /// Saves dcpu reference internally for future use. 18 void attachEmulator(Emulator!Cpu emulator); 19 20 /// Handles hardware interrupt and returns a number of cycles. 21 uint handleInterrupt(); 22 23 /// Called every application frame. 24 /// Can be used to update screens. 25 void updateFrame(); 26 27 /// Must handle previosly posted update query. 28 /// If next updates is not needed must set delay to zero. 29 /// If set to non-zero will be called after delay cycles elapsed with provided message. 30 void handleUpdateQuery(ref ulong delay) 31 {} 32 33 /// Returns: 32 bit word identifying the hardware id. 34 uint hardwareId() @property; 35 36 /// Returns: 16 bit word identifying the hardware version. 37 ushort hardwareVersion() @property; 38 39 /// Returns: 32 bit word identifying the manufacturer 40 uint manufacturer() @property; 41 42 abstract void commitFrame(ulong frameNumber); 43 abstract void discardFrame(); 44 abstract void undoFrames(ulong numFrames); 45 abstract void discardUndoStack(); 46 abstract size_t undoStackSize() @property; 47 } 48 49 interface IUndoable 50 { 51 void commitFrame(ulong frameNumber); 52 void discardFrame(); 53 void undoFrames(ulong numFrames); 54 void discardUndoStack(); 55 size_t undoStackSize() @property; 56 }