| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| DebugInst |
|
| 2.0;2 |
| 1 | /* |
|
| 2 | * DebugInst.java |
|
| 3 | * |
|
| 4 | * This file is part of JavaGear. |
|
| 5 | * |
|
| 6 | * JavaGear is free software; you can redistribute it and/or modify |
|
| 7 | * it under the terms of the GNU General Public License as published by |
|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|
| 9 | * (at your option) any later version. |
|
| 10 | * |
|
| 11 | * JavaGear is distributed in the hope that it will be useful, |
|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 14 | * GNU General Public License for more details. |
|
| 15 | * |
|
| 16 | * You should have received a copy of the GNU General Public License |
|
| 17 | * along with JavaGear; if not, write to the Free Software |
|
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
| 19 | */ |
|
| 20 | ||
| 21 | package uk.co.javagear; |
|
| 22 | ||
| 23 | import javax.swing.JTable; |
|
| 24 | ||
| 25 | /** |
|
| 26 | * JavaGear Debugger. |
|
| 27 | * |
|
| 28 | * @author Copyright (C) 2002 Chris White |
|
| 29 | * @version 16th March 2002 |
|
| 30 | * @see "JavaGear Final Project Report" |
|
| 31 | */ |
|
| 32 | public final class DebugInst { |
|
| 33 | ||
| 34 | /** |
|
| 35 | * Pointer to Z80 CPU. |
|
| 36 | */ |
|
| 37 | private Z80 cpu; |
|
| 38 | ||
| 39 | /** |
|
| 40 | * Pointer to VDP. |
|
| 41 | */ |
|
| 42 | private Vdp vdp; |
|
| 43 | ||
| 44 | /** |
|
| 45 | * Pointer to Java Screenpanel. |
|
| 46 | */ |
|
| 47 | private Screen screenpanel; |
|
| 48 | ||
| 49 | /** |
|
| 50 | * Pointer to Registers Table. |
|
| 51 | */ |
|
| 52 | private JTable regTable; |
|
| 53 | ||
| 54 | /** |
|
| 55 | * Pointer to Flag Table. |
|
| 56 | */ |
|
| 57 | private JTable flagTable; |
|
| 58 | ||
| 59 | /** |
|
| 60 | * Pointer to Debug Table. |
|
| 61 | */ |
|
| 62 | private JTable debugTable; |
|
| 63 | ||
| 64 | /** |
|
| 65 | * Current Line Number. |
|
| 66 | */ |
|
| 67 | private int lineno; |
|
| 68 | ||
| 69 | /** |
|
| 70 | * EmulateLoop Constructor. |
|
| 71 | * |
|
| 72 | * @param z Z80 |
|
| 73 | * @param v Vdp |
|
| 74 | * @param s ScreenPanel |
|
| 75 | * @param regt Register Table |
|
| 76 | * @param flagt Flag Table |
|
| 77 | * @param debugt Debug Table |
|
| 78 | */ |
|
| 79 | 0 | public DebugInst(Z80 z, Vdp v, Screen s, JTable regt, JTable flagt, JTable debugt) { |
| 80 | 0 | lineno = 0; |
| 81 | 0 | cpu = z; |
| 82 | 0 | vdp = v; |
| 83 | 0 | screenpanel = s; |
| 84 | 0 | regTable = regt; |
| 85 | 0 | flagTable = flagt; |
| 86 | 0 | debugTable = debugt; |
| 87 | 0 | } |
| 88 | ||
| 89 | ||
| 90 | /** |
|
| 91 | * Execute a specific number of Z80 instructions. |
|
| 92 | * |
|
| 93 | * @param count number of instructions to execute. |
|
| 94 | */ |
|
| 95 | public void execute(int count) { |
|
| 96 | 0 | for (int x = count; x > 0; x--) { |
| 97 | // If this is the last instruction |
|
| 98 | 0 | if (x == 1) { |
| 99 | // Update Last column of tables |
|
| 100 | 0 | updateRegisters(1); |
| 101 | 0 | updateFlags(1); |
| 102 | 0 | updateDebug(); |
| 103 | 0 | } else if (x <= 10) { |
| 104 | 0 | updateDebug(); // Necessary to get correct previous instructions |
| 105 | } |
|
| 106 | ||
| 107 | // If cycle count has been reached |
|
| 108 | 0 | if (cpu.debug(227)) { |
| 109 | 0 | vdp.interrupts(lineno); |
| 110 | 0 | vdp.drawLine(lineno); |
| 111 | 0 | lineno++; // Increment line number |
| 112 | ||
| 113 | 0 | if (lineno == 261) { |
| 114 | 0 | lineno = 0; // Reset line number |
| 115 | 0 | screenpanel.refresh(); |
| 116 | } |
|
| 117 | } |
|
| 118 | } |
|
| 119 | ||
| 120 | // Update Column 0 |
|
| 121 | 0 | updateRegisters(0); |
| 122 | 0 | updateFlags(0); |
| 123 | 0 | } |
| 124 | ||
| 125 | /** |
|
| 126 | * Update register table. |
|
| 127 | * |
|
| 128 | * @param row the tables's row. |
|
| 129 | */ |
|
| 130 | private void updateRegisters(int row) { |
|
| 131 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getA()), row, 0); |
| 132 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getF()), row, 1); |
| 133 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getB()), row, 2); |
| 134 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getC()), row, 3); |
| 135 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getD()), row, 4); |
| 136 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getE()), row, 5); |
| 137 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getH()), row, 6); |
| 138 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getL()), row, 7); |
| 139 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getIX()), row, 8); |
| 140 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getIY()), row, 9); |
| 141 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getR()), row, 10); |
| 142 | 0 | regTable.setValueAt(Integer.toHexString(cpu.getSP()), row, 11); |
| 143 | 0 | } |
| 144 | ||
| 145 | /** |
|
| 146 | * Update flag table. |
|
| 147 | * |
|
| 148 | * @param row the table's row. |
|
| 149 | */ |
|
| 150 | private void updateFlags(int row) { |
|
| 151 | 0 | flagTable.setValueAt(new Boolean(cpu.getSign()), row, 0); |
| 152 | 0 | flagTable.setValueAt(new Boolean(cpu.getZero()), row, 1); |
| 153 | 0 | flagTable.setValueAt(new Boolean(cpu.getBit5()), row, 2); |
| 154 | 0 | flagTable.setValueAt(new Boolean(cpu.getHc()), row, 3); |
| 155 | 0 | flagTable.setValueAt(new Boolean(cpu.getBit3()), row, 4); |
| 156 | 0 | flagTable.setValueAt(new Boolean(cpu.getParity()), row, 5); |
| 157 | 0 | flagTable.setValueAt(new Boolean(cpu.getNegative()), row, 6); |
| 158 | 0 | flagTable.setValueAt(new Boolean(cpu.getCarry()), row, 7); |
| 159 | 0 | } |
| 160 | ||
| 161 | /** |
|
| 162 | * Update debug table. |
|
| 163 | */ |
|
| 164 | private void updateDebug() { |
|
| 165 | 0 | scrollDebug(0); scrollDebug(1); scrollDebug(2); |
| 166 | 0 | debugTable.setValueAt(new String(cpu.getMnu()), 9, 2); |
| 167 | 0 | debugTable.setValueAt("0x" + Integer.toHexString(cpu.getPC()), 9, 0); |
| 168 | 0 | debugTable.setValueAt(new String(cpu.getOp()), 9, 1); |
| 169 | 0 | } |
| 170 | ||
| 171 | /** |
|
| 172 | * Scroll the debug table upwards. |
|
| 173 | * |
|
| 174 | * @param column the column to scroll upwards. |
|
| 175 | */ |
|
| 176 | private void scrollDebug(int column) { |
|
| 177 | 0 | for (int x = 0; x < 9; x++) { |
| 178 | 0 | debugTable.setValueAt(debugTable.getValueAt(x + 1, column), x, column); |
| 179 | } |
|
| 180 | 0 | } |
| 181 | ||
| 182 | } |