mirror of
https://codeberg.org/sethm/symon.git
synced 2026-11-09 03:22:24 +00:00
Added stack functions.
This commit is contained in:
1 parent
6915331cca
commit
7e36444193
2 files changed
+45
-14
No files matched your search
@@ -621,8 +621,11 @@ public class Cpu implements InstructionTable {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String statusString() {
|
/**
|
||||||
|
* Returns a string representing the CPU state.
|
||||||
|
*/
|
||||||
|
public String toString() {
|
||||||
String opcode = CpuUtils.opcode(ir, operands[0], operands[1]);
|
String opcode = CpuUtils.opcode(ir, operands[0], operands[1]);
|
||||||
StringBuffer sb = new StringBuffer(String.format("$%04X", addr) + " ");
|
StringBuffer sb = new StringBuffer(String.format("$%04X", addr) + " ");
|
||||||
sb.append(String.format("%-12s", opcode));
|
sb.append(String.format("%-12s", opcode));
|
||||||
@@ -633,10 +636,31 @@ public class Cpu implements InstructionTable {
|
|||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Push an item onto the stack, and decrement the stack counter.
|
||||||
|
* Silently fails to push onto the stack if SP is
|
||||||
|
* TODO: Unit tests.
|
||||||
|
*/
|
||||||
|
protected void push(int data) {
|
||||||
|
bus.write(sp, data);
|
||||||
|
if (sp > 0x100) { sp--; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Pop a byte off the user stack, and increment the stack counter.
|
||||||
|
* TODO: Unit tests.
|
||||||
|
*/
|
||||||
|
protected int pop() {
|
||||||
|
int data = bus.read(sp);
|
||||||
|
if (sp < 0x1ff) { sp++; }
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Increment the PC, rolling over if necessary.
|
* Increment the PC, rolling over if necessary.
|
||||||
*/
|
*/
|
||||||
private void incProgramCounter() {
|
protected void incProgramCounter() {
|
||||||
if (pc == 0xffff) {
|
if (pc == 0xffff) {
|
||||||
pc = 0;
|
pc = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -61,22 +61,29 @@ public class Simulator {
|
|||||||
bus.write(0x0302, 0xea); // NOP
|
bus.write(0x0302, 0xea); // NOP
|
||||||
bus.write(0x0303, 0xea); // NOP
|
bus.write(0x0303, 0xea); // NOP
|
||||||
bus.write(0x0304, 0xea); // NOP
|
bus.write(0x0304, 0xea); // NOP
|
||||||
bus.write(0x0305, 0xea); // NOP
|
bus.write(0x0305, 0xa0); // LDY #$1A
|
||||||
bus.write(0x0306, 0xa9); // LDA #$1A
|
bus.write(0x0306, 0x1a);
|
||||||
bus.write(0x0307, 0x1a);
|
bus.write(0x0307, 0xea); // NOP
|
||||||
bus.write(0x0308, 0xea); // NOP
|
bus.write(0x0308, 0xea); // NOP
|
||||||
bus.write(0x0309, 0xea); // NOP
|
bus.write(0x0309, 0xa2); // LDX #$03
|
||||||
bus.write(0x030a, 0xa9); // LDA #$03
|
bus.write(0x030a, 0x03);
|
||||||
bus.write(0x030b, 0x03);
|
|
||||||
bus.write(0x030c, 0x4c); // JMP #$0300
|
bus.write(0x030b, 0xa9); // LDA #$00
|
||||||
bus.write(0x030d, 0x00);
|
bus.write(0x030c, 0x00);
|
||||||
bus.write(0x030e, 0x03);
|
bus.write(0x030d, 0xa2); // LDX #$00
|
||||||
|
bus.write(0x030e, 0x00);
|
||||||
|
bus.write(0x030f, 0xa0); // LDY #$00
|
||||||
|
bus.write(0x0310, 0x00);
|
||||||
|
|
||||||
|
bus.write(0x0311, 0x4c); // JMP #$0300
|
||||||
|
bus.write(0x0312, 0x00);
|
||||||
|
bus.write(0x0313, 0x03);
|
||||||
|
|
||||||
cpu.reset();
|
cpu.reset();
|
||||||
|
|
||||||
for (int i = 0; i < 60; i++) {
|
for (int i = 0; i <= 23; i++) {
|
||||||
cpu.step();
|
cpu.step();
|
||||||
System.out.println(cpu.statusString());
|
System.out.println(cpu.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user