-
Notifications
You must be signed in to change notification settings - Fork 157
/
Debug.cpp
9502 lines (7925 loc) · 233 KB
/
Debug.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
AppleWin : An Apple //e emulator for Windows
Copyright (C) 1994-1996, Michael O'Brien
Copyright (C) 1999-2001, Oliver Schmidt
Copyright (C) 2002-2005, Tom Charlesworth
Copyright (C) 2006-2014, Tom Charlesworth, Michael Pohoreski
AppleWin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
AppleWin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with AppleWin; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* Description: Debugger
*
* Author: Copyright (C) 2006-2010 Michael Pohoreski
*/
// disable warning C4786: symbol greater than 255 character:
//#pragma warning(disable: 4786)
#include "StdAfx.h"
#include "Debug.h"
#include "DebugDefs.h"
#include "Debugger_Win32.h"
#include "../Windows/AppleWin.h"
#include "../Core.h"
#include "../Interface.h"
#include "../CardManager.h"
#include "../CPU.h"
#include "../Disk.h"
#include "../Keyboard.h"
#include "../Memory.h"
#include "../NTSC.h"
#include "../SoundCore.h" // SoundCore_SetFade()
// #define DEBUG_COMMAND_HELP 1
// #define DEBUG_ASM_HASH 1
#define ALLOW_INPUT_LOWERCASE 1
#define MAKE_VERSION(a,b,c,d) ((a<<24) | (b<<16) | (c<<8) | (d))
// See /docs/Debugger_Changelog.txt for full details
const int DEBUGGER_VERSION = MAKE_VERSION(2,9,1,14);
// Public _________________________________________________________________________________________
// All (Global)
bool g_bDebuggerEatKey = false;
// Bookmarks __________________________________________________________________
int g_nBookmarks = 0;
Bookmark_t g_aBookmarks[ MAX_BOOKMARKS ];
// Breakpoints ________________________________________________________________
// Any Speed Breakpoints
int g_nDebugBreakOnInvalid = 0; // Bit Flags of Invalid Opcode to break on: // iOpcodeType = AM_IMPLIED (BRK), AM_1, AM_2, AM_3
int g_iDebugBreakOnOpcode = 0;
bool g_bDebugBreakOnInterrupt = false;
struct DebugBreakOnDMA
{
DebugBreakOnDMA() : isToOrFromMemory(0), memoryAddr(0), memoryAddrEnd(0), BPid(0) {}
int isToOrFromMemory;
WORD memoryAddr;
WORD memoryAddrEnd;
int BPid;
};
static const uint32_t NUM_BREAK_ON_DMA = 3; // A 512-byte block misaligned touching 3 pages
static DebugBreakOnDMA g_DebugBreakOnDMA[NUM_BREAK_ON_DMA];
static DebugBreakOnDMA g_DebugBreakOnDMAIO;
int g_bDebugBreakpointHit = 0; // See: BreakpointHit_t
int g_nBreakpoints = 0;
Breakpoint_t g_aBreakpoints[ MAX_BREAKPOINTS ];
// NOTE: BreakpointSource_t and g_aBreakpointSource must match!
const char *g_aBreakpointSource[ NUM_BREAKPOINT_SOURCES ] =
{ // Used to be one char, since ArgsCook also uses // TODO/FIXME: Parser use Param[] ?
// Used for both Input & Output!
// Regs
"A", // Reg A
"X", // Reg X
"Y", // Reg Y
// Special
"PC", // Program Counter -- could use "$"
"S" , // Stack Pointer
// Flags -- .8 Moved: Flag names from g_aFlagNames[] to "inlined" g_aBreakpointSource[]
"P", // Processor Status
"C", // ---- ---1 Carry
"Z", // ---- --1- Zero
"I", // ---- -1-- Interrupt
"D", // ---- 1--- Decimal
"B", // ---1 ---- Break
"R", // --1- ---- Reserved
"V", // -1-- ---- Overflow
"N", // 1--- ---- Sign
// Misc
"OP", // Opcode/Instruction/Mnemonic
"M", // Mem RW
"M", // Mem READ_ONLY
"M", // Mem WRITE_ONLY
"V", // Video Scanner
// TODO: M0 ram bank 0, M1 aux ram ?
};
// Note: BreakpointOperator_t, _PARAM_BREAKPOINT_, and g_aBreakpointSymbols must match!
const char *g_aBreakpointSymbols[ NUM_BREAKPOINT_OPERATORS ] =
{ // Output: Must be 2 chars!
"<=", // LESS_EQUAL
"< ", // LESS_THAN
"= ", // EQUAL
"!=", // NOT_EQUAL
// "! ", // NOT_EQUAL_1
"> ", // GREATER_THAN
">=", // GREATER_EQUAL
"? ", // READ // Q. IO Read use 'I'? A. No, since I=Interrupt // Also can't use: 'r' reserver
"@ ", // WRITE // Q. IO Write use 'O'? A. No, since O=Opcode // This is free: 'w'
"* ", // Read/Write
};
static WORD g_uBreakMemoryAddress = 0;
// Commands _______________________________________________________________________________________
int g_iCommand; // last command (enum) // used for consecutive commands
std::vector<int> g_vPotentialCommands; // global, since TAB-completion also needs
std::vector<Command_t> g_vSortedCommands;
// static const char g_aFlagNames[_6502_NUM_FLAGS+1] = TEXT("CZIDBRVN");// Reversed since arrays are from left-to-right
// Cursor (Console Input) _____________________________________________________
// char g_aInputCursor[] = "\|/-";
enum InputCursor
{
CURSOR_INSERT,
CURSOR_OVERSTRIKE,
NUM_INPUT_CURSORS
};
const char g_aInputCursor[] = "_\x7F"; // insert over-write
bool g_bInputCursor = false;
int g_iInputCursor = CURSOR_OVERSTRIKE; // which cursor to use
const int g_nInputCursor = sizeof( g_aInputCursor );
void DebuggerCursorUpdate();
char DebuggerCursorGet();
// Cursor (Disasm) ____________________________________________________________
WORD g_nDisasmTopAddress = 0;
WORD g_nDisasmBotAddress = 0;
WORD g_nDisasmCurAddress = 0;
bool g_bDisasmCurBad = false;
int g_nDisasmCurLine = 0; // Aligned to Top or Center
int g_iDisasmCurState = CURSOR_NORMAL;
int g_nDisasmWinHeight = 0;
// char g_aConfigDisasmAddressColon[] = TEXT(" :");
extern const int WINDOW_DATA_BYTES_PER_LINE = 8;
#if OLD_FONT
// Font
TCHAR g_sFontNameDefault[ MAX_FONT_NAME ] = TEXT("Courier New");
TCHAR g_sFontNameConsole[ MAX_FONT_NAME ] = TEXT("Courier New");
TCHAR g_sFontNameDisasm [ MAX_FONT_NAME ] = TEXT("Courier New");
TCHAR g_sFontNameInfo [ MAX_FONT_NAME ] = TEXT("Courier New");
TCHAR g_sFontNameBranch [ MAX_FONT_NAME ] = TEXT("Webdings");
HFONT g_hFontWebDings = (HFONT)0;
#endif
int g_iFontSpacing = FONT_SPACING_CLEAN;
// TODO: This really needs to be phased out, and use the ConfigFont[] settings
#if USE_APPLE_FONT
int g_nFontHeight = CONSOLE_FONT_HEIGHT; // 13 -> 12 Lucida Console is readable
#else
int g_nFontHeight = 15; // 13 -> 12 Lucida Console is readable
#endif
const int MIN_DISPLAY_CONSOLE_LINES = 5; // doesn't include ConsoleInput
int g_nDisasmDisplayLines = 0;
// Config _____________________________________________________________________
// Config - Disassembly
bool g_bConfigDisasmAddressView = true;
int g_bConfigDisasmClick = 4; // GH#462 alt=1, ctrl=2, shift=4 bitmask (default to Shift-Click)
bool g_bConfigDisasmAddressColon = true;
bool g_bConfigDisasmOpcodesView = true;
bool g_bConfigDisasmOpcodeSpaces = true;
int g_iConfigDisasmTargets = DISASM_TARGET_BOTH;
int g_iConfigDisasmBranchType = DISASM_BRANCH_FANCY;
int g_bConfigDisasmImmediateChar = DISASM_IMMED_BOTH;
int g_iConfigDisasmScroll = 3; // favor 3 byte opcodes
// Config - Info
bool g_bConfigInfoTargetPointer = false;
MemoryTextFile_t g_ConfigState;
static bool g_bDebugFullSpeed = false;
static bool g_bLastGoCmdWasFullSpeed = false;
static bool g_bGoCmd_ReinitFlag = false;
// Display ____________________________________________________________________
void UpdateDisplay( Update_t bUpdate );
// Memory _____________________________________________________________________
MemoryDump_t g_aMemDump[ NUM_MEM_DUMPS ];
// Made global so operator @# can be used with other commands.
MemorySearchResults_t g_vMemorySearchResults;
// Profile
const int NUM_PROFILE_LINES = NUM_OPCODES + NUM_OPMODES + 16;
ProfileOpcode_t g_aProfileOpcodes[ NUM_OPCODES ];
ProfileOpmode_t g_aProfileOpmodes[ NUM_OPMODES ];
unsigned __int64 g_nProfileBeginCycles = 0; // g_nCumulativeCycles // PROFILE RESET
const std::string g_FileNameProfile = TEXT("Profile.txt"); // changed from .csv to .txt since Excel doesn't give import options.
int g_nProfileLine = 0;
char g_aProfileLine[ NUM_PROFILE_LINES ][ CONSOLE_WIDTH ];
void ProfileReset ();
bool ProfileSave ();
void ProfileFormat( bool bSeperateColumns, ProfileFormat_e eFormatMode );
// TODO: Things would be much simpler if g_aProfileLine is just a container of std::string.
struct ProfileLine_t
{
ProfileLine_t() : buf(NULL), bufsz(0) {}
ProfileLine_t(char* _buf, size_t _bufsz) : buf(_buf), bufsz(_bufsz) {}
void Assign(std::string const& str)
{
if (!buf || bufsz <= 0) return;
strncpy_s(buf, bufsz, str.c_str(), _TRUNCATE);
}
ATTRIBUTE_FORMAT_PRINTF(2, 3) /* 1 is "this" */
void Format(const char* fmt, ...)
{
if (!buf || bufsz <= 0) return;
va_list va;
va_start(va, fmt);
Assign(StrFormatV(fmt, va));
va_end(va);
}
char* buf;
size_t bufsz;
};
ProfileLine_t ProfileLinePeek ( int iLine );
ProfileLine_t ProfileLinePush ();
void ProfileLineReset ();
// Soft-switches __________________________________________________________________________________
// Source Level Debugging _________________________________________________________________________
bool g_bSourceLevelDebugging = false;
bool g_bSourceAddSymbols = false;
bool g_bSourceAddMemory = false;
std::string g_aSourceFileName;
MemoryTextFile_t g_AssemblerSourceBuffer;
int g_iSourceDisplayStart = 0;
int g_nSourceAssembleBytes = 0;
int g_nSourceAssemblySymbols = 0;
// TODO: Support multiple source filenames
SourceAssembly_t g_aSourceDebug;
// Watches ________________________________________________________________________________________
int g_nWatches = 0;
Watches_t g_aWatches[ MAX_WATCHES ]; // TODO: use vector<Watch_t> ??
// Window _________________________________________________________________________________________
int g_iWindowLast = WINDOW_CODE; // TODO: FIXME! should be offset into WindowConfig!!!
// Who has active focus
int g_iWindowThis = WINDOW_CODE; // TODO: FIXME! should be offset into WindowConfig!!!
WindowSplit_t g_aWindowConfig[ NUM_WINDOWS ];
// Zero Page Pointers _____________________________________________________________________________
int g_nZeroPagePointers = 0;
ZeroPagePointers_t g_aZeroPagePointers[ MAX_ZEROPAGE_POINTERS ]; // TODO: use vector<> ?
// TODO: // CONFIG SAVE --> VERSION #
enum DebugConfigVersion_e
{
VERSION_0,
CURRENT_VERSION = VERSION_0
};
// Misc. __________________________________________________________________________________________
std::string g_sFileNameConfig =
#ifdef MSDOS
"AWDEBUGR.CFG";
#else
"AppleWinDebugger.cfg";
#endif
static char g_sFileNameTrace [] = "Trace.txt";
static bool g_bBenchmarking = false;
static BOOL g_bProfiling = 0;
static int g_nDebugSteps = 0;
static DWORD g_nDebugStepCycles = 0;
static int g_nDebugStepStart = 0;
static int g_nDebugStepUntil = -1; // HACK: MAGIC #
static int g_nDebugSkipStart = 0;
static int g_nDebugSkipLen = 0;
static FILE *g_hTraceFile = NULL;
static bool g_bTraceHeader = false; // semaphore, flag header to be printed
static bool g_bTraceFileWithVideoScanner = false;
DWORD extbench = 0;
static bool g_bIgnoreNextKey = false;
const UINT LBR_UNDEFINED = -1;
static UINT g_LBR = LBR_UNDEFINED; // Last Branch Record
static bool g_bScriptReadOk = false;
// Private ________________________________________________________________________________________
// Prototypes _______________________________________________________________
static void DebugEnd ();
static int ParseInput ( LPTSTR pConsoleInput, bool bCook = true );
static Update_t ExecuteCommand ( int nArgs );
// Breakpoints
void _BWZ_List ( const Breakpoint_t * aBreakWatchZero, const int iBWZ ); // bool bZeroBased = true );
void _BWZ_ListAll ( const Breakpoint_t * aBreakWatchZero, const int nMax );
// bool CheckBreakpoint (WORD address, BOOL memory);
bool _CmdBreakpointAddReg ( Breakpoint_t *pBP, BreakpointSource_t iSrc, BreakpointOperator_t iCmp, WORD nAddress, int nLen, bool bIsTempBreakpoint );
int _CmdBreakpointAddCommonArg ( int iArg, int nArg, BreakpointSource_t iSrc, BreakpointOperator_t iCmp, bool bIsTempBreakpoint=false );
void _BWZ_RemoveOne( Breakpoint_t *aBreakWatchZero, const int iSlot, int & nTotal );
// Config - Save
bool ConfigSave_BufferToDisk ( const char *pFileName, ConfigSave_t eConfigSave );
void ConfigSave_PrepareHeader ( const Parameters_e eCategory, const Commands_e eCommandClear );
// Drawing
static void _CmdColorGet ( const int iScheme, const int iColor );
// Source Level Debugging
static bool BufferAssemblyListing ( const std::string & pFileName );
static bool ParseAssemblyListing ( bool bBytesToMemory, bool bAddSymbols );
// Window
void _WindowJoin ();
void _WindowSplit (Window_e eNewBottomWindow );
void _WindowLast ();
void _WindowSwitch ( int eNewWindow );
int WindowGetHeight ( int iWindow );
void WindowUpdateDisasmSize ();
void WindowUpdateConsoleDisplayedSize ();
void WindowUpdateSizes ();
Update_t _CmdWindowViewFull (int iNewWindow);
Update_t _CmdWindowViewCommon (int iNewWindow);
// Utility
void _CursorMoveDownAligned( int nDelta );
void _CursorMoveUpAligned( int nDelta );
// DebugVideoMode _____________________________________________________________
// Fix for GH#345
// Wrap & protect the debugger's video mode in its own class:
// . This may seem like overkill but it stops the video mode being (erroneously) additionally used as a flag.
// . VideoMode is a bitmap of video flags and a VideoMode value of zero is a valid video mode (GR,PAGE1,non-mixed).
class DebugVideoMode // NB. Implemented as a singleton
{
protected:
DebugVideoMode()
{
Reset();
}
public:
~DebugVideoMode(){}
static DebugVideoMode& Instance()
{
return m_Instance;
}
void Reset(void)
{
m_bIsVideoModeValid = false;
m_uVideoMode = 0;
}
bool IsSet(void)
{
return m_bIsVideoModeValid;
}
bool Get(UINT* pVideoMode)
{
if (pVideoMode)
*pVideoMode = m_bIsVideoModeValid ? m_uVideoMode : 0;
return m_bIsVideoModeValid;
}
void Set(UINT videoMode)
{
m_bIsVideoModeValid = true;
m_uVideoMode = videoMode;
}
private:
bool m_bIsVideoModeValid;
uint32_t m_uVideoMode;
static DebugVideoMode m_Instance;
};
DebugVideoMode DebugVideoMode::m_Instance;
bool DebugGetVideoMode(UINT* pVideoMode)
{
return DebugVideoMode::Instance().Get(pVideoMode);
}
// File _______________________________________________________________________
size_t _GetFileSize( FILE *hFile )
{
fseek( hFile, 0, SEEK_END );
size_t nFileBytes = ftell( hFile );
fseek( hFile, 0, SEEK_SET );
return nFileBytes;
}
// Bookmarks __________________________________________________________________
//===========================================================================
bool _Bookmark_Add( const int iBookmark, const WORD nAddress )
{
if (iBookmark < MAX_BOOKMARKS)
{
// g_aBookmarks.push_back( nAddress );
// g_aBookmarks.at( iBookmark ) = nAddress;
g_aBookmarks[ iBookmark ].nAddress = nAddress;
g_aBookmarks[ iBookmark ].bSet = true;
g_nBookmarks++;
return true;
}
return false;
}
//===========================================================================
bool _Bookmark_Del( const WORD nAddress )
{
bool bDeleted = false;
// int nSize = g_aBookmarks.size();
int iBookmark;
for (iBookmark = 0; iBookmark < MAX_BOOKMARKS; iBookmark++ )
{
if (g_aBookmarks[ iBookmark ].nAddress == nAddress)
{
// g_aBookmarks.at( iBookmark ) = NO_6502_TARGET;
g_aBookmarks[ iBookmark ].bSet = false;
g_nBookmarks--;
bDeleted = true;
}
}
return bDeleted;
}
// Returns:
// 0 if address does not have a bookmark set
// N+1 if there is an existing bookmark that has this address
int Bookmark_Find( const WORD nAddress )
{
// Ugh, linear search
// int nSize = g_aBookmarks.size();
int iBookmark;
for (iBookmark = 0; iBookmark < MAX_BOOKMARKS; iBookmark++ )
{
if (g_aBookmarks[ iBookmark ].nAddress == nAddress)
{
if (g_aBookmarks[ iBookmark ].bSet)
return iBookmark + 1;
}
}
return 0;
}
//===========================================================================
bool _Bookmark_Get( const int iBookmark, WORD & nAddress )
{
// int nSize = g_aBookmarks.size();
if (iBookmark >= MAX_BOOKMARKS)
return false;
if (g_aBookmarks[ iBookmark ].bSet)
{
nAddress = g_aBookmarks[ iBookmark ].nAddress;
return true;
}
return false;
}
//===========================================================================
void _Bookmark_Reset()
{
// g_aBookmarks.reserve( MAX_BOOKMARKS );
// g_aBookmarks.insert( g_aBookma int iBookmark = 0;
int iBookmark = 0;
for (iBookmark = 0; iBookmark < MAX_BOOKMARKS; iBookmark++ )
{
g_aBookmarks[ iBookmark ].bSet = false;
}
g_nBookmarks = 0;
}
//===========================================================================
int _Bookmark_Size()
{
g_nBookmarks = 0;
int iBookmark;
for (iBookmark = 0; iBookmark < MAX_BOOKMARKS; iBookmark++ )
{
if (g_aBookmarks[ iBookmark ].bSet)
g_nBookmarks++;
}
return g_nBookmarks;
}
//===========================================================================
Update_t CmdBookmark (int nArgs)
{
return CmdBookmarkAdd( nArgs );
}
//===========================================================================
Update_t CmdBookmarkAdd (int nArgs )
{
// BMA address
// BMA # address ; where # is [0...9]
if (! nArgs)
{
return CmdBookmarkList( 0 );
}
int iBookmark = 0;
int iArg = 1;
if (nArgs > 1)
{
iBookmark = g_aArgs[ iArg ].nValue;
iArg++;
}
else
{
while ((iBookmark < MAX_BOOKMARKS) && g_aBookmarks[iBookmark].bSet)
iBookmark++;
}
WORD nAddress = g_aArgs[ iArg ].nValue;
if (iBookmark >= MAX_BOOKMARKS)
{
ConsoleDisplayPushFormat( "All bookmarks are currently in use. (Max: %d)", MAX_BOOKMARKS );
return ConsoleUpdate();
}
if (Bookmark_Find( nAddress ))
_Bookmark_Del( nAddress );
bool bAdded = _Bookmark_Add( iBookmark, nAddress );
if (!bAdded)
return Help_Arg_1( CMD_BOOKMARK_ADD );
return UPDATE_DISASM | ConsoleUpdate();
}
//===========================================================================
Update_t CmdBookmarkClear (int nArgs)
{
int iBookmark = 0;
int iArg;
for (iArg = 1; iArg <= nArgs; iArg++ )
{
if (! _tcscmp(g_aArgs[nArgs].sArg, g_aParameters[ PARAM_WILDSTAR ].m_sName))
{
_Bookmark_Reset();
break;
}
iBookmark = g_aArgs[ iArg ].nValue;
if (g_aBookmarks[ iBookmark ].bSet)
_Bookmark_Del(g_aBookmarks[ iBookmark ].nAddress);
}
return UPDATE_DISASM;
}
//===========================================================================
Update_t CmdBookmarkGoto ( int nArgs )
{
if (! nArgs)
return Help_Arg_1( CMD_BOOKMARK_GOTO );
int iBookmark = g_aArgs[ 1 ].nValue;
WORD nAddress;
if (_Bookmark_Get( iBookmark, nAddress ))
{
g_nDisasmCurAddress = nAddress;
g_nDisasmCurLine = 0;
DisasmCalcTopBotAddress();
}
return UPDATE_DISASM;
}
//===========================================================================
Update_t CmdBookmarkList (int nArgs)
{
if (! g_nBookmarks)
{
ConsoleBufferPushFormat( " There are no current bookmarks. (Max: %d)", MAX_BOOKMARKS );
}
else
{
_BWZ_ListAll( g_aBookmarks, MAX_BOOKMARKS );
}
return ConsoleUpdate();
}
//===========================================================================
Update_t CmdBookmarkLoad (int nArgs)
{
if (nArgs == 1)
{
// strcpy( sMiniFileName, pFileName );
// strcat( sMiniFileName, ".aws" ); // HACK: MAGIC STRING
// _tcscpy(sFileName, g_sCurrentDir); //
// strcat(sFileName, sMiniFileName);
}
return UPDATE_CONSOLE_DISPLAY;
}
//===========================================================================
Update_t CmdBookmarkSave (int nArgs)
{
g_ConfigState.Reset();
ConfigSave_PrepareHeader( PARAM_CAT_BOOKMARKS, CMD_BOOKMARK_CLEAR );
int iBookmark = 0;
while (iBookmark < MAX_BOOKMARKS)
{
if (g_aBookmarks[ iBookmark ].bSet)
{
g_ConfigState.PushLineFormat( "%s %x %04X\n"
, g_aCommands[ CMD_BOOKMARK_ADD ].m_sName
, iBookmark
, g_aBookmarks[ iBookmark ].nAddress
);
}
iBookmark++;
}
if (nArgs)
{
if (! (g_aArgs[ 1 ].bType & TYPE_QUOTED_2))
return Help_Arg_1( CMD_BOOKMARK_SAVE );
if (ConfigSave_BufferToDisk( g_aArgs[ 1 ].sArg, CONFIG_SAVE_FILE_CREATE ))
{
ConsoleBufferPush( TEXT( "Saved." ) );
return ConsoleUpdate();
}
}
return UPDATE_CONSOLE_DISPLAY;
}
// Benchmark ______________________________________________________________________________________
//===========================================================================
Update_t CmdBenchmark (int nArgs)
{
if (g_bBenchmarking)
CmdBenchmarkStart(0);
else
CmdBenchmarkStop(0);
return UPDATE_ALL; // TODO/FIXME Verify
}
//===========================================================================
Update_t CmdBenchmarkStart (int nArgs)
{
CpuSetupBenchmark();
g_nDisasmCurAddress = regs.pc;
DisasmCalcTopBotAddress();
g_bBenchmarking = true;
return UPDATE_ALL; // 1;
}
//===========================================================================
Update_t CmdBenchmarkStop (int nArgs)
{
g_bBenchmarking = false;
DebugEnd();
GetFrame().FrameRefreshStatus(DRAW_TITLE | DRAW_DISK_STATUS);
GetFrame().VideoRedrawScreen();
DWORD currtime = GetTickCount();
while ((extbench = GetTickCount()) != currtime)
; // intentional busy-waiting
KeybQueueKeypress(TEXT(' ') ,ASCII);
return UPDATE_ALL; // 0;
}
//===========================================================================
Update_t CmdProfile (int nArgs)
{
if (! nArgs)
{
strncpy_s( g_aArgs[ 1 ].sArg, g_aParameters[ PARAM_RESET ].m_sName, _TRUNCATE );
nArgs = 1;
}
if (nArgs == 1)
{
int iParam;
int nFound = FindParam( g_aArgs[ 1 ].sArg, MATCH_EXACT, iParam, _PARAM_GENERAL_BEGIN, _PARAM_GENERAL_END );
if (! nFound)
goto _Help;
if (iParam == PARAM_RESET)
{
ProfileReset();
g_bProfiling = 1;
ConsoleBufferPush( TEXT(" Resetting profile data." ) );
}
else
{
if ((iParam != PARAM_SAVE) && (iParam != PARAM_LIST))
goto _Help;
bool bExport = true;
if (iParam == PARAM_LIST)
bExport = false;
// .csv (Comma Seperated Value)
// ProfileFormat( bExport, bExport ? PROFILE_FORMAT_COMMA : PROFILE_FORMAT_SPACE );
// .txt (Tab Seperated Value)
ProfileFormat( bExport, bExport ? PROFILE_FORMAT_TAB : PROFILE_FORMAT_SPACE );
// Dump to console
if (iParam == PARAM_LIST)
{
const int nLine = g_nProfileLine;
for ( int iLine = 0; iLine < nLine; iLine++ )
{
ProfileLine_t prfline = ProfileLinePeek( iLine );
if (prfline.buf)
{
char sText[ CONSOLE_WIDTH ];
TextConvertTabsToSpaces( sText, prfline.buf, CONSOLE_WIDTH, 4 );
// ConsoleBufferPush( sText );
ConsolePrint( sText );
}
}
}
if (iParam == PARAM_SAVE)
{
if (ProfileSave())
{
ConsoleBufferPushFormat( " Saved: %s", g_FileNameProfile.c_str() );
}
else
ConsoleBufferPush( " ERROR: Couldn't save file. (In use?)" );
}
}
}
else
goto _Help;
return ConsoleUpdate(); // UPDATE_CONSOLE_DISPLAY;
_Help:
return Help_Arg_1( CMD_PROFILE );
}
// Breakpoints ____________________________________________________________________________________
//===========================================================================
// iOpcodeType = AM_IMPLIED (BRK), AM_1, AM_2, AM_3
static bool IsDebugBreakOnInvalid(int iOpcodeType)
{
return ((g_nDebugBreakOnInvalid >> iOpcodeType) & 1) ? true : false;
}
// iOpcodeType = AM_IMPLIED (BRK), AM_1, AM_2, AM_3
static void SetDebugBreakOnInvalid( int iOpcodeType, int nValue )
{
if (iOpcodeType <= AM_3)
{
g_nDebugBreakOnInvalid &= ~ ( 1 << iOpcodeType);
g_nDebugBreakOnInvalid |= ((nValue & 1) << iOpcodeType);
}
}
Update_t CmdBreakInvalid (int nArgs) // Breakpoint IFF Full-speed!
{
if (nArgs > 2) // || (nArgs == 0))
return HelpLastCommand();
int iType = AM_IMPLIED; // default to BRK
int nActive = 0;
if (nArgs == 0)
{
nArgs = 1;
g_aArgs[ 1 ].nValue = AM_IMPLIED;
g_aArgs[ 1 ].sArg[0] = 0;
}
iType = g_aArgs[ 1 ].nValue;
// Cases:
// 0. CMD // display
// 1a. CMD # // display
// 1b. CMD ON | OFF // set
// 1c. CMD ? // error
// 2a. CMD # ON | OFF // set
// 2b. CMD ALL ON | OFF // set all
// 2c. CMD # ? // error
bool bValidParam = true;
int iParamArg = nArgs; // last arg is the 'ON' / 'OFF' param
int iParam;
int nFound = FindParam( g_aArgs[ iParamArg ].sArg, MATCH_EXACT, iParam, _PARAM_GENERAL_BEGIN, _PARAM_GENERAL_END );
if (nFound)
{
if (iParam == PARAM_ON)
nActive = 1;
else
if (iParam == PARAM_OFF)
nActive = 0;
else
{
bValidParam = false;
nFound = 0;
}
}
else
bValidParam = false;
if (nArgs == 1)
{
if (! nFound)
{
if ((iType < AM_IMPLIED) || (iType > AM_3))
goto _Help;
if ( IsDebugBreakOnInvalid( iType ) )
iParam = PARAM_ON;
else
iParam = PARAM_OFF;
}
else // case 1b
{
SetDebugBreakOnInvalid( iType, nActive );
}
if (iType == 0)
ConsoleBufferPushFormat( "Enter debugger on BRK opcode: %s", g_aParameters[ iParam ].m_sName );
else
ConsoleBufferPushFormat( "Enter debugger on INVALID %1X opcode: %s", iType, g_aParameters[ iParam ].m_sName );
return ConsoleUpdate();
}
else
if (nArgs == 2)
{
int iParam1;
if (FindParam(g_aArgs[1].sArg, MATCH_EXACT, iParam1, PARAM_ALL, PARAM_ALL)) // case 2b
{
for (iType = 0; iType <= AM_3; iType++)
SetDebugBreakOnInvalid(iType, nActive);
ConsoleBufferPushFormat("Enter debugger on BRK opcode and INVALID opcodes: %s", g_aParameters[iParam].m_sName);
return ConsoleUpdate();
}
else if (! bValidParam) // case 2c
{
goto _Help;
}
else // case 2a
{
if ((iType < 0) || (iType > AM_3))
goto _Help;
SetDebugBreakOnInvalid( iType, nActive );
if (iType == 0)
ConsoleBufferPushFormat( "Enter debugger on BRK opcode: %s", g_aParameters[ iParam ].m_sName );
else
ConsoleBufferPushFormat( "Enter debugger on INVALID %1X opcode: %s", iType, g_aParameters[ iParam ].m_sName );
return ConsoleUpdate();
}
}
return UPDATE_CONSOLE_DISPLAY;
_Help:
return HelpLastCommand();
}
//===========================================================================
Update_t CmdBreakOpcode (int nArgs) // Breakpoint IFF Full-speed!
{
if (nArgs > 1)
return HelpLastCommand();
TCHAR sAction[ CONSOLE_WIDTH ] = TEXT("Current"); // default to display