Permalink
Browse files

Breakpoints added, plus r\n -> run forever

  • Loading branch information...
1 parent cd5628c commit 524c239a9232135f9c378acb637d0c6d05b3eaf8 @Zardoz89 committed Apr 13, 2012
Showing with 51 additions and 6 deletions.
  1. +2 −1 README.md
  2. +47 −4 dedcpu.d
  3. +2 −1 help.txt
View
@@ -21,7 +21,8 @@ The notch.bin file was made with interfect dcpu-emu assembler
## Commands: ##
* __q__ -> End emulation
* __s__ or Enter key -> Step one instruction
-* __r__ *number* -> Runs number instructions without stop. 0 for running forever (Ctrl+C to abort)
+* __r__ *number* -> Runs number instructions without stop. Nothing or 0 for running forever (Ctrl+C to abort)
+* __b__ *address* -> Toggle breakpoint at address. Only works if is the begin of a valid instruction.
* __m__ *begin[-end]* -> Display a chunk of RAM from begin to end address of RAM (address in hex). If end it's omitted, only show RAM value at begin address.
* __d__ *begin[-end]* -> Dumps a chunk of RAM to a __dump.bin__ file in little endian raw binary. Same semantics that __'m'__
* __i__ *text* -> Sends text to keyboard input buffer in emulated machine
View
@@ -15,7 +15,7 @@ enum TypeHexFile {lraw, braw, ahex, hex8}; /// Type of machine code file
* f = CPU Frequency
*/
struct DCpu16(double f) {
- enum double Frequency = f; /// In Herts
+ enum double Frequency = f; /// In Hertzs
enum long Period = cast(long) (1000000.0 / Frequency); /// In microseconds
private :
@@ -50,6 +50,9 @@ private :
return ++_pc;
}
+ @property ushort PC() {
+ return _pc;
+ }
/**
* Decode paramaters from a o b parameter
* Params:
@@ -610,26 +613,61 @@ int main (string[] args) {
bool step = true;
ulong count, stop = ulong.max;
+ bool[ushort] breakpoint; // Sets breakpoints
+
while(1) {
if (step) {
auto c = fgetc(stdin);
switch (c) {
case 'q':
case 'Q': // Quit
return(0);
+
+ case 'b':
+ case 'B': // Break point
+ tcsetattr(fileno(stdin), TCSADRAIN, &ostate); // original mode
+ auto input = strip(readln());
+ tcsetattr(fileno(stdin), TCSADRAIN, &nstate);
+ ushort pos;
+ try {
+ pos = parse!ushort(input, 16); // PC value
+ } catch (ConvException e) {
+ writeln("Invalid value");
+ continue;
+ }
+ if ( pos in breakpoint) {
+ writefln("Erasing breakpoint at 0x%04X", pos);
+ breakpoint.remove(pos);
+ } else {
+ writefln("Enabling breakpoint at 0x%04X", pos);
+ breakpoint[pos] = true;
+ }
+
+ continue;
case 'v':
case 'V': // Print info head
writeln("Cycles PC SP O A B C X Y Z I J Instruction");
writeln("------ ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- -----------");
continue;
case 'r':
case 'R':
- tcsetattr(fileno(stdin), TCSADRAIN, &ostate); // original mode
count = 0;
+ tcsetattr(fileno(stdin), TCSADRAIN, &ostate); // original mode
auto input = strip(readln());
- stop = parse!ushort(input, 10); // How many cycles
- step = false;
tcsetattr(fileno(stdin), TCSADRAIN, &nstate);
+ if (input== "") { // r0 or r means run forever
+ stop = 0;
+ step = false;
+ continue;
+ }
+
+ try {
+ stop = parse!ushort(input, 10); // How many cycles
+ } catch (ConvException e) {
+ writeln("Invalid value");
+ continue;
+ }
+ step = false;
continue;
case 'd':
case 'D': // Memory dump
@@ -695,6 +733,11 @@ int main (string[] args) {
}
} else if (stop == 0 || count < stop) {
write(cpu.show_state, " ", cpu.actual_instruction, " ");
+ if (cpu.PC in breakpoint) {
+ writeln("Breakpoint reached");
+ step = true;
+ continue;
+ }
try {
cpu.run_instruction();
writeln(cpu.diassembled);
View
@@ -10,7 +10,8 @@ Parameters:
Commands:
quit q End emulation
step s or Enter key Step one instruction
- run r number Runs number instructions without stop. 0 for running forever (Ctrl+C to abort)
+ run r number Runs number instructions without stop. Nothing or 0 for running forever (Ctrl+C to abort)
+ breakpoint b address Toggle breakpoint at address. Only works if is the begin of a valid instruction.
memory display m begin[-end] Display a chunk of RAM from begin to end address of RAM (address in hex). If end it's omitted, only show RAM value at begin address.
memory dump d begin[-end] Dumps a chunk of RAM to a dump.bin file in little endian raw binary. Same semantics that 'm'
input i text Sends text to keyboard input buffer in emulated machine

0 comments on commit 524c239

Please sign in to comment.