1 /**
2  * DCPU-16 computer
3  *
4  * See_Also:
5  *  http://pastebin.com/raw.php?i=Q4JvQvnM
6  */
7 module dcpu.machine;
8 
9 /+
10 public import dcpu.hardware, dcpu.cpu;
11 import std.range, std.parallelism;
12 
13 // It contains:
14 //  -DCPU-16 CPU
15 //  -0x10000 words of 16 bit of RAM
16 //  -Some quanty of hardware attached
17 final class Machine {
18   ushort[0x10000] ram;
19 
20 package:
21   Hardware[ushort] dev;
22   DCpu cpu;
23 
24 public:
25   /**
26    * Inits the DCPU machine
27    */
28   void init() {
29     cpu = new DCpu(this);
30     foreach(ref d; dev) // taskPool.parallel(dev)
31       d.init();
32   }
33 
34   // Emulation *****************************************************************
35   /**
36    * Do a clock tick to the whole machine
37    * Returns TRUE if a instruccion has executed
38    */
39   bool tick() {
40     foreach(ref d; dev) {
41       d.bus_clock_tick(cpu.state, cpu, ram);
42     }
43     return cpu.step();
44   }
45 
46   /**
47    * Returns the actual status of cpu registers
48    */
49   @property auto cpu_info() {
50     return cpu.actual_state;
51   }
52 
53   /**
54    * Set a breakpoint in an address
55    * Params:
56    *    addr    = Address where set a breakpoint
57    * Returns if previusly these adress had a breakpoint
58    */
59   bool set_breakpoint (ushort addr) {
60     // TODO
61     return false;
62   }
63 
64   /**
65    * There is a breakpoint in an address
66    * Params:
67    *    addr    = Address where see if there is a breakpoint
68    * Returns TRUE if there is a breakpoint in addr
69    */
70   bool is_breakpoint (ushort addr) {
71     // TODO
72     return false;
73   }
74 
75   // Device handling ***********************************************************
76   /**
77    * Returns the device number I
78    */
79   ref Hardware opIndex (size_t index) {
80     return dev[cast(ushort)index];
81   }
82 
83   /**
84    * Asigns the device number I
85    */
86   void opIndexAssign (Hardware val, size_t index) {
87     dev[cast(ushort)index] = val;
88   }
89 
90   /**
91    * How many devices are inside the machine
92    */
93   @property size_t length() {
94     return dev.length;
95   }
96 
97   
98   
99 }
100 
101 +/
102