📄 debug.cpp
字号:
DPrint (String); } if (Line[0] == 'u') { if (Debug.Unassemble.Bank != 0 || Debug.Unassemble.Address != 0) { Bank = Debug.Unassemble.Bank; Address = Debug.Unassemble.Address; } ErrorCode = GetStartAddress (Line, &Bank, &Address); for (short Counter = 0; Counter != 10; Counter++) { Address += S9xOPrint (String, Bank, Address); DPrint (String); } Debug.Unassemble.Bank = Bank; Debug.Unassemble.Address = Address; } DPrint (""); return;}static void PrintWindow (uint8 * a){ for (int i = 0; i < 6; i++) if (a[i]) switch (i) { case 0: printf ("Background 0, "); break; case 1: printf ("Background 1, "); break; case 2: printf ("Background 2, "); break; case 3: printf ("Background 3, "); break; case 4: printf ("Objects, "); break; case 5: printf ("Colour window, "); break; }}static char *ClipFn (int logic){ switch (logic) { case CLIP_OR: return ("OR"); case CLIP_AND: return ("AND"); case CLIP_XOR: return ("XOR"); case CLIP_XNOR: return ("XNOR"); default: return ("???"); }}static void WhatsUsed (){ printf ("V-line: %ld, H-Pos: %ld\n", CPU.V_Counter, CPU.Cycles); printf ("Screen mode: %d, ", PPU.BGMode); if (PPU.BGMode <= 1 && (Memory.FillRAM [0x2105] & 8)) printf ("(BG#2 Priority)"); printf ("Brightness: %d", PPU.Brightness); if (Memory.FillRAM[0x2100] & 0x80) printf (" (screen blanked)"); printf ("\n"); if (Memory.FillRAM[0x2133] & 1) printf ("Interlace, "); if (Memory.FillRAM[0x2133] & 4) printf ("240 line visible, "); if (Memory.FillRAM[0x2133] & 8) printf ("Pseudo 512 pixels horizontal resolution, "); if (Memory.FillRAM[0x2133] & 0x40) printf ("Mode 7 priority per pixel, "); printf ("\n"); if (PPU.BGMode == 7 && (Memory.FillRAM[0x211a] & 3)) printf ("Mode 7 flipping, "); if (PPU.BGMode == 7) printf ("Mode 7 screen repeat: %d,", (Memory.FillRAM[0x211a] & 0xc0) >> 6); if (Memory.FillRAM[0x2130] & 1) printf ("32K colour mode, "); if (PPU.BGMode == 7) { // Sign extend 13 bit values to 16 bit values... if (PPU.CentreX & (1 << 12)) PPU.CentreX |= 0xe000; if (PPU.CentreY & (1 << 12)) PPU.CentreY |= 0xe000; printf ("\nMatrix A: %.3f, B: %.3f, C: %.3f, D: %.3f, Centre X: %d Y:%d\n", (double) PPU.MatrixA / 256, (double) PPU.MatrixB / 256, (double) PPU.MatrixC / 256, (double) PPU.MatrixD / 256, PPU.CentreX, PPU.CentreY); } if ((Memory.FillRAM[0x2106] & 0xf0) && (Memory.FillRAM[0x2106] & 0x0f)) { printf ("\nMosaic effect(%d) on ", PPU.Mosaic); for (int i = 0; i < 4; i++) if (Memory.FillRAM[0x2106] & (1 << i)) printf ("BG%d,", i); printf (","); } if (PPU.HVBeamCounterLatched) printf ("V and H beam pos latched, "); if (Memory.FillRAM[0x4200] & 0x20) printf ("V-IRQ enabled at %d\n", PPU.IRQVBeamPos); if (Memory.FillRAM[0x4200] & 0x10) printf ("H-IRQ enabled at %d\n", PPU.IRQHBeamPos); if (Memory.FillRAM[0x4200] & 0x80) printf ("V-blank NMI enabled\n"); int i; for (i = 0; i < 8; i++) { if (missing.hdma_this_frame & (1 << i)) { printf ("H-DMA %d [%d] 0x%02X%04X->0x21%02X %s %s 0x%02X%04X %s addressing\n", i, DMA[i].TransferMode, DMA[i].ABank, DMA[i].AAddress, DMA[i].BAddress, DMA[i].AAddressDecrement ? "dec" : "inc", DMA[i].Repeat ? "repeat" : "continue", DMA[i].IndirectBank, DMA[i].IndirectAddress, DMA[i].HDMAIndirectAddressing ? "indirect" : "absolute"); } } for (i = 0; i < 8; i++) { if (missing.dma_this_frame & (1 << i)) { printf ("DMA %d %d 0x%02X%04X->0x21%02X Num: %d %s\n", i, DMA[i].TransferMode, DMA[i].ABank, DMA[i].AAddress, DMA[i].BAddress, DMA[i].TransferBytes, DMA[i].AAddressFixed ? "fixed" : (DMA[i].AAddressDecrement ? "dec" : "inc")); } } printf ("VRAM write address: 0x%04x(%s), Full Graphic: %d, Address inc: %d\n", PPU.VMA.Address, PPU.VMA.High ? "Byte" : "Word", PPU.VMA.FullGraphicCount, PPU.VMA.Increment); for (i = 0; i < 4; i++) { printf ("BG%d: VOffset:%d, HOffset:%d, W:%d, H:%d, TS:%d, BA:0x%04x, TA:0x%04X\n", i, PPU.BG[i].VOffset, PPU.BG[i].HOffset, (PPU.BG[i].SCSize & 1) * 32 + 32, (PPU.BG[i].SCSize & 2) * 16 + 32, PPU.BG[i].BGSize * 8 + 8, PPU.BG[i].SCBase, PPU.BG[i].NameBase); } char *s = ""; switch ((Memory.FillRAM [0x2130] & 0xc0) >> 6) { case 0: s = "always on"; break; case 1: s = "inside"; break; case 2: s = "outside"; break; case 3: s = "always off"; break; } printf ("Main screen (%s): ", s); for (i = 0; i < 5; i++) if (Memory.FillRAM[0x212c] & (1 << i)) switch (i) { case 0: printf ("BG0,"); break; case 1: printf ("BG1,"); break; case 2: printf ("BG2,"); break; case 3: printf ("BG3,"); break; case 4: printf ("OBJ,"); break; } switch ((Memory.FillRAM [0x2130] & 0x30) >> 4) { case 0: s = "always on"; break; case 1: s = "inside"; break; case 2: s = "outside"; break; case 3: s = "always off"; break; } printf ("\nSub-screen (%s): ", s); for (i = 0; i < 5; i++) if (Memory.FillRAM[0x212d] & (1 << i)) switch (i) { case 0: printf ("BG0,"); break; case 1: printf ("BG1,"); break; case 2: printf ("BG2,"); break; case 3: printf ("BG3,"); break; case 4: printf ("OBJ,"); break; } printf ("\n"); if ((Memory.FillRAM[0x2131] & 0x3f)) { if (Memory.FillRAM[0x2131] & 0x80) { if (Memory.FillRAM[0x2130] & 0x02) printf ("Subscreen subtract"); else printf ("Fixed colour subtract"); } else { if (Memory.FillRAM[0x2130] & 0x02) printf ("Subscreen addition"); else printf ("Fixed colour addition"); } if (Memory.FillRAM [0x2131] & 0x40) printf ("(half):"); else printf (":"); for (i = 0; i < 6; i++) if (Memory.FillRAM[0x2131] & (1 << i)) { switch (i) { case 0: printf ("BG0,"); break; case 1: printf ("BG1,"); break; case 2: printf ("BG2,"); break; case 3: printf ("BG3,"); break; case 4: printf ("OBJ,"); break; case 5: printf ("BACK,"); break; } } printf ("\n"); } printf ("\nWindow 1 (%d, %d, %02x, %02x): ", PPU.Window1Left, PPU.Window1Right, Memory.FillRAM [0x212e], Memory.FillRAM [0x212f]); for (i = 0; i < 6; i++) if (PPU.ClipWindow1Enable [i]) switch (i) { case 0: printf ("BG0(%s-%s),", PPU.ClipWindow1Inside [i] ? "I" : "O", ClipFn (PPU.ClipWindowOverlapLogic[0])); break; case 1: printf ("BG1(%s-%s),", PPU.ClipWindow1Inside [i] ? "I" : "O", ClipFn (PPU.ClipWindowOverlapLogic[1])); break; case 2: printf ("BG2(%s-%s),", PPU.ClipWindow1Inside [i] ? "I" : "O", ClipFn (PPU.ClipWindowOverlapLogic[2])); break; case 3: printf ("BG3(%s-%s),", PPU.ClipWindow1Inside [i] ? "I" : "O", ClipFn (PPU.ClipWindowOverlapLogic[3])); break; case 4: printf ("OBJ(%s-%s),", PPU.ClipWindow1Inside [i] ? "I" : "O", ClipFn (PPU.ClipWindowOverlapLogic[4])); break; case 5: printf ("COL(%s-%s)", PPU.ClipWindow1Inside [i] ? "I" : "O", ClipFn (PPU.ClipWindowOverlapLogic[5])); break; } printf ("\nWindow 2 (%d, %d): ", PPU.Window2Left, PPU.Window2Right); for (i = 0; i < 6; i++) if (PPU.ClipWindow2Enable [i]) switch (i) { case 0: printf ("BG0(%s),", PPU.ClipWindow2Inside [i] ? "I" : "O"); break; case 1: printf ("BG1(%s),", PPU.ClipWindow2Inside [i] ? "I" : "O"); break; case 2: printf ("BG2(%s),", PPU.ClipWindow2Inside [i] ? "I" : "O"); break; case 3: printf ("BG3(%s),", PPU.ClipWindow2Inside [i] ? "I" : "O"); break; case 4: printf ("OBJ(%s),", PPU.ClipWindow2Inside [i] ? "I" : "O"); break; case 5: printf ("COL(%s)", PPU.ClipWindow2Inside [i] ? "I" : "O"); break; } printf ("\nFixed colour: %02x%02x%02x\n", PPU.FixedColourRed, PPU.FixedColourGreen, PPU.FixedColourBlue);}static void WhatsMissing (){ printf ("Processor: "); if (missing.emulate6502) printf ("emulation mode, "); if (missing.decimal_mode) printf ("decimal mode,"); if (missing.mv_8bit_index) printf ("MVP/MVN with 8bit index registers and XH or YH > 0,"); if (missing.mv_8bit_acc) printf ("MVP/MVN with 8bit accumulator > 255"); printf ("\nScreen modes used:"); int i; for (i = 0; i < 8; i++) if (missing.modes[i]) printf (" %d,", i); printf ("\n"); if (missing.interlace) printf ("Interlace, "); if (missing.pseudo_512) printf ("Pseudo 512 pixels horizontal resolution, "); if (missing.lines_239) printf ("240 lines visible,"); if (missing.sprite_double_height) printf ("double-hight sprites,"); printf ("\n"); if (missing.mode7_fx) printf ("Mode 7 rotation/scaling, "); if (missing.matrix_read) printf ("Mode 7 read matrix registers, "); if (missing.mode7_flip) printf ("Mode 7 flipping, "); if (missing.mode7_bgmode) printf ("Mode 7 priority per pixel, "); if (missing.direct) printf ("Direct 32000 colour mode"); printf ("\n"); if (missing.mosaic) printf ("Mosaic effect, "); if (missing.subscreen) printf ("Subscreen enabled, "); if (missing.subscreen_add) printf ("Subscreen colour add, "); if (missing.subscreen_sub) printf ("Subscreen colour subtract, "); if (missing.fixed_colour_add) printf ("Fixed colour add, "); if (missing.fixed_colour_sub) printf ("Fixed colour subtract"); printf ("\n"); printf ("Window 1 enabled on:"); PrintWindow (missing.window1); printf ("\nWindow 2 enabled on:"); PrintWindow (missing.window2); printf ("\n"); if (missing.bg_offset_read) printf ("BG offset read, "); if (missing.oam_address_read) printf ("OAM address read,"); if (missing.sprite_priority_rotation) printf ("Sprite priority rotation, "); if (missing.fast_rom) printf ("Fast 3.58MHz ROM access enabled, "); if (missing.matrix_multiply) printf ("Matrix multiply 16bit by 8bit used"); printf ("\n"); if (missing.virq) printf ("V-position IRQ used at line %d, ", missing.virq_pos); if (missing.hirq) printf ("H-position IRQ used at position %d, ", missing.hirq_pos); printf ("\n"); if (missing.h_v_latch) printf ("H and V-Pos latched, "); if (missing.h_counter_read) printf ("H-Pos read, "); if (missing.v_counter_read) printf ("V-Pos read"); printf ("\n"); if (missing.oam_read) printf ("OAM read, "); if (missing.vram_read) printf ("VRAM read, "); if (missing.cgram_read) printf ("CG-RAM read, "); if (missing.wram_read) printf ("WRAM read, "); if (missing.dma_read) printf ("DMA read,"); if (missing.vram_inc) printf ("VRAM inc: %d,", missing.vram_inc); if (missing.vram_full_graphic_inc) printf ("VRAM full graphic inc: %d,", missing.vram_full_graphic_inc); printf ("\n"); for (i = 0; i < 8; i++) { if (missing.hdma[i].used) { printf ("HDMA %d, 0x%02X%04X->0x21%02X %s ", i, missing.hdma[i].abus_bank, missing.hdma[i].abus_address, missing.hdma[i].bbus_address, missing.hdma[i].indirect_address ? "indirect" : "absolute"); if (missing.hdma[i].force_table_address_write) printf ("Forced address write, "); if (missing.hdma[i].force_table_address_read) printf ("Current address read, "); if (missing.hdma[i].line_count_write) printf ("Line count write, "); if (missing.hdma[i].line_count_read) printf ("Line count read"); printf ("\n"); } } for (i = 0; i < 8; i++) { if (missing.dma_channels & (1 << i)) { printf ("DMA %d %d 0x%02X%04X->0x21%02X Num: %d %s\n", i, DMA[i].TransferMode, DMA[i].ABank, DMA[i].AAddress, DMA[i].BAddress, DMA[i].TransferBytes, DMA[i].AAddressFixed ? "fixed" : (DMA[i].AAddressDecrement ? "dec" : "inc")); } } if (missing.unknownppu_read) printf ("Read from unknown PPU register: $%04X\n", missing.unknownppu_read); if (missing.unknownppu_write) printf ("Write to unknown PPU register: $%04X\n", missing.unknownppu_write); if (missing.unknowncpu_read) printf ("Read from unknown CPU register: $%04X\n", missing.unknowncpu_read); if (missing.unknowncpu_write) printf ("Write to unknown CPU register: $%04X\n", missing.unknowncpu_write); if (missing.unknowndsp_read) printf ("Read from unknown DSP register: $%04X\n", missing.unknowndsp_read); if (missing.unknowndsp_write) printf ("Write to unknown DSP register: $%04X\n", missing.unknowndsp_write);}void S9xDoDebug (){ char Line[513]; Debug.Dump.Bank = 0; Debug.Dump.Address = 0; Debug.Unassemble.Bank = 0; Debug.Unassemble.Address = 0; S9xTextMode (); ProcessDebugCommand ("r"); while (CPU.Flags & DEBUG_MODE_FLAG) { printf ("> "); fflush (stdout); fgets (Line, sizeof (Line) - 1, stdin); Line [strlen (Line) - 1] = 0; ProcessDebugCommand (Line); } if (!(CPU.Flags & SINGLE_STEP_FLAG)) S9xGraphicsMode ();}void S9xTrace (){ if(!trace) trace=fopen("trace.log", "a"); char String [512]; S9xOPrint (String, Registers.PB, CPU.PC - CPU.PCBase); fprintf (trace, "%s\n", String);}void S9xSA1Trace (){ char String [512]; S9xSA1OPrint (String, SA1Registers.PB, SA1.PC - SA1.PCBase); fprintf (trace2, "%s\n", String); fflush (trace2);}void S9xTraceMessage (const char *s){ if(s) { if (trace) fprintf (trace, "%s\n", s); else if (trace2) fprintf (trace2, "%s\n", s); }}extern "C" void TraceSA1 (){ SA1.Flags ^= TRACE_FLAG; if (SA1.Flags & TRACE_FLAG) { printf ("SA1 CPU instruction tracing enabled.\n"); if (trace2 == NULL) trace2 = fopen ("trace_sa1.log", "wb"); } else { printf ("SA1 CPU instruction tracing disabled.\n"); fclose (trace2); trace2 = NULL; }}extern "C" void Trace (){ CPU.Flags ^= TRACE_FLAG; if (CPU.Flags & TRACE_FLAG) { if (trace == NULL) trace = fopen ("trace.log", "wb"); printf ("CPU instruction tracing enabled.\n"); } else { printf ("CPU instruction tracing disabled.\n"); fclose (trace); trace = NULL; }}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -