Skip to content

Commit 59623e8

Browse files
committed
Modified text output from "RUNV" to
1. Dump register values changed in hex (X2) format 2. Use the layout for the commands similar to the "D"-Dissasemble command. Remember, command "!" turns on and off listing of memory and instruction details
1 parent 0622722 commit 59623e8

File tree

4 files changed

+98
-43
lines changed

4 files changed

+98
-43
lines changed

Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,10 @@ static void Main(string[] args)
169169

170170
case "R":
171171
case "RUN":
172-
currentAddress = s8d.Run();
172+
currentAddress = s8d.Run(true, false,showAddress);
173173
break;
174174
case "RUNV":
175-
currentAddress = s8d.Run(true, true);
175+
currentAddress = s8d.Run(true, true, showAddress);
176176
break;
177177

178178
case "REGS":

S8CPU.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,13 @@ public void ResetRegs()
174174
state.stdout = "";
175175
}
176176

177-
public void Run(bool verbose = false)
177+
public void Run(bool verbose = false,bool showaddress=false)
178178
{
179179
ResetRegs();
180-
RunUntil(state.memoryUsed, verbose);
180+
RunUntil(state.memoryUsed, verbose, showaddress);
181181
}
182182

183-
internal bool RunUntil(int stop_pc_at, bool verbose = false)
183+
internal bool RunUntil(int stop_pc_at, bool verbose = false, bool showaddress=false)
184184
{
185185

186186
if (state.memoryUsed == 0)
@@ -208,7 +208,7 @@ internal bool RunUntil(int stop_pc_at, bool verbose = false)
208208
S8Instruction s8 = new S8Instruction(opcode, param);
209209
state.pc += 2;
210210

211-
if (!ExecuteInstruction(s8, verbose))
211+
if (!ExecuteInstruction(s8, verbose, showaddress))
212212
{
213213
state.crashed = true;
214214
}
@@ -226,9 +226,9 @@ public bool Step(int steps=1)
226226
}
227227

228228

229-
public bool ExecuteInstruction(S8Instruction instr, bool verbose = false)
229+
public bool ExecuteInstruction(S8Instruction instr, bool verbose = false, bool showaddress=false)
230230
{
231-
if (verbose) VerboseLogLine(instr);
231+
if (verbose) VerboseLogLine(instr, showaddress);
232232
// HALT
233233
if (instr.operationClass == 0x0) return false;
234234

@@ -379,12 +379,12 @@ public bool ExecuteInstruction(S8Instruction instr, bool verbose = false)
379379
}
380380

381381
public byte[] prevRegs = new byte[16];
382-
private void VerboseLogLine(S8Instruction instr)
382+
private void VerboseLogLine(S8Instruction instr, bool showaddress)
383383
{
384384
var regs = GetChangedRegs();
385385
if (!string.IsNullOrEmpty(regs)) Console.WriteLine(regs);
386-
instr.DecodeInstruction();
387-
Console.WriteLine(instr.DecodedInstruction);
386+
instr.DecodeInstruction();
387+
Console.WriteLine(instr.Instruction2Text(state.pc, showaddress));
388388
prevRegs = (byte[])state.regs.Clone();
389389
}
390390

@@ -394,7 +394,7 @@ private string GetChangedRegs()
394394
for (int i = 0; i < 15; i++)
395395
{
396396
if (prevRegs[i] != state.regs[i])
397-
changed += $"[r{i}: {prevRegs[i]} -> {state.regs[i]}]";
397+
changed += $"[r{i}: 0x{prevRegs[i]:X2} -> 0x{state.regs[i]:X2}]"; // #TODO Make it hex -> "X2"
398398
}
399399
return changed;
400400
}

S8Dissasembler.cs

Lines changed: 40 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -146,49 +146,58 @@ public int Dissasemble(int start, int length, bool showAddress = false, bool all
146146
}
147147

148148
while (currentAddress < endAddress)
149-
{
150-
string sHexAddress = currentAddress.ToString("X3");
149+
{
151150

152151
byte opcode = bytes[currentAddress++];
153152
byte param = bytes[currentAddress++];
154153

155-
s8i = new S8Instruction(opcode, param);
154+
s8i = new S8Instruction(opcode, param);
156155
s8i.DecodeInstruction();
157156

158-
if (s8i.ValidInstruction)
159-
{
160-
if (!showAddress)
161-
Console.WriteLine("a" + sHexAddress + ":");
162-
}
163-
else
164-
{
165-
if (!showAddress)
166-
Console.WriteLine("m" + sHexAddress + ":");
167-
}
168157

169-
if (showAddress)
170-
{
171-
string sOpcode = opcode.ToString("X2");
172-
string sParam = param.ToString("X2");
173-
Console.Write("A[" + sHexAddress + "] | I[" + sOpcode + " " + sParam + "] ");
174-
}
158+
Console.WriteLine(s8i.Instruction2Text(currentAddress, showAddress));
175159

176160

161+
}
162+
return currentAddress;
177163

164+
}
178165

179-
if (s8i.ValidInstruction)
180-
{
181-
Console.WriteLine(s8i.DecodedInstruction);
182-
}
183-
else
184-
{
185-
string data = ".DATA 0x" + opcode.ToString("X2");
186-
Console.WriteLine(data + " ; " + s8i.ErrorMessage);
187-
}
166+
/*
167+
internal void PrettyPrintInstruction(S8Instruction s8i, int currentAddress,bool showAddress)
168+
{
169+
string sHexAddress = currentAddress.ToString("X3");
170+
171+
if (s8i.ValidInstruction)
172+
{
173+
if (!showAddress)
174+
Console.WriteLine("a" + sHexAddress + ":");
175+
}
176+
else
177+
{
178+
if (!showAddress)
179+
Console.WriteLine("m" + sHexAddress + ":");
188180
}
189-
return currentAddress;
190181
182+
if (showAddress)
183+
{
184+
string sOpcode = s8i.Opcode.ToString("X2");
185+
string sParam = s8i.Param.ToString("X2");
186+
Console.Write("A[" + sHexAddress + "] | I[" + sOpcode + " " + sParam + "] ");
187+
}
188+
189+
190+
if (s8i.ValidInstruction)
191+
{
192+
Console.WriteLine(s8i.DecodedInstruction);
193+
}
194+
else
195+
{
196+
string data = ".DATA 0x" + s8i.Opcode.ToString("X2");
197+
Console.WriteLine(data + " ; " + s8i.ErrorMessage);
198+
}
191199
}
200+
*/
192201

193202
internal int SetPC(int start, bool allowOutsideLoadedMemory = false)
194203
{
@@ -244,12 +253,12 @@ public int GetMaxTicks()
244253

245254

246255

247-
public int Run(bool ShowOppgulp = true, bool verbose = false)
256+
public int Run(bool ShowOppgulp = true, bool verbose = false, bool showaddress=false)
248257
{
249258
var stopwatch = new Stopwatch();
250259
stopwatch.Start();
251260

252-
cpu.Run(verbose);
261+
cpu.Run(verbose, showaddress);
253262

254263
stopwatch.Stop();
255264
var elapsed_time = stopwatch.ElapsedMilliseconds;

S8Instruction.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ namespace S8Debugger
1010
{
1111
public class S8Instruction
1212
{
13+
14+
// Helper bytes to keep the original values that created the Instruction
15+
public byte Opcode;
16+
public byte Param;
17+
18+
// decoded fields from opcode + param
1319
public int operationClass;
1420
public int operation;
1521
public int address;
@@ -29,6 +35,10 @@ public void init(byte opcode, byte param)
2935
{
3036
ValidInstruction = false;
3137

38+
Opcode = opcode;
39+
Param = param;
40+
41+
3242
int instruction = opcode | (param << 8);
3343

3444
operationClass = instruction & 0xf;
@@ -242,9 +252,45 @@ public void DecodeInstruction()
242252

243253
}
244254

255+
245256
}
246257

258+
public string Instruction2Text(int currentAddress, bool showAddress)
259+
{
260+
string sHexAddress = currentAddress.ToString("X3");
261+
string outStr = string.Empty;
262+
263+
if (ValidInstruction)
264+
{
265+
if (!showAddress)
266+
outStr += "a" + sHexAddress + ": \r\n";
267+
}
268+
else
269+
{
270+
if (!showAddress)
271+
outStr += "m" + sHexAddress + ": \r\n";
272+
}
273+
274+
if (showAddress)
275+
{
276+
string sOpcode = Opcode.ToString("X2");
277+
string sParam = Param.ToString("X2");
278+
outStr += "A[" + sHexAddress + "] | I[" + sOpcode + " " + sParam + "] ";
279+
}
280+
281+
282+
if (ValidInstruction)
283+
{
284+
outStr += DecodedInstruction;
285+
}
286+
else
287+
{
288+
string data = ".DATA 0x" + Opcode.ToString("X2");
289+
outStr += data + " ; " + ErrorMessage;
290+
}
247291

292+
return outStr;
293+
}
248294

249295
};
250296
}

0 commit comments

Comments
 (0)