forked from redcode/SpecEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Debugger.asm
3220 lines (2594 loc) · 140 KB
/
Debugger.asm
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
AddDebuggerToolBar PROTO :DWORD,:HWND
SetDebugReadWriteButtonStates PROTO :DWORD
EnableDumpControls PROTO :DWORD
EnableDebugWindows PROTO :DWORD
DestroyDebugWindows PROTO
DecodeSearchBytes PROTO :DWORD
DISLST_SubclassProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
DebuggerDlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
Single_Step PROTO
Remote_Single_Step PROTO
InitCursorStack PROTO
PushCursorStack PROTO
PopCursorStack PROTO
SetProfileCycles PROTO
GetDialogPlacement PROTO
SaveDialogPlacement PROTO
SetDebugMenuCheck PROTO :DWORD,:BYTE
SetDisassemblyFontSize PROTO :BYTE
Run_DebugFrame PROTO
ToggleBreakpoint PROTO :WORD
AddBreakpoint PROTO :WORD
RemoveBreakpoint PROTO :WORD
ClearBreakpoints PROTO
SortBreakpoints PROTO
UpdateDebugger PROTO
UpdateDebugDisplay PROTO
GetSelectedLine PROTO
SetSelectedLine PROTO :DWORD
Cursor_Up PROTO
Cursor_Down PROTO
FollowReference PROTO
RetraceReference PROTO
SetNewZ80PC PROTO :WORD
ParseRegText PROTO :DWORD
SaveLoadFwdRefs PROTO :BYTE
CreateDISTooltip PROTO :HWND
DestroyDISTooltip PROTO
BuildDissTooltipText PROTO
.data?
align 4
DISASSEMBLYhWnd DWORD ?
DISLST_Handle DWORD ?
OrigDISLSTWndProc DWORD ?
DISASSEMBLYOldFont DWORD ?
StackPtr DWORD ?
StackTopLim DWORD ?
StackRoot DWORD 256 DUP(?)
StackBotLim DWORD ?
Debugger_hWnd DWORD ?
DebugMenuHandle DWORD ?
DissMenuHandle DWORD ?
LastDebugFrameCounter DWORD ?
LastDebugCycleCounter DWORD ?
PCTable WORD 60 DUP (?)
lpFwdRefTextOffsetTable DWORD ?
FwdRefTextOffsetTable DWORD 60 DUP (?)
savelpFwdRefTextOffsetTable DWORD ?
saveFwdRefTextOffsetTable DWORD 60 DUP (?)
Z80PC WORD ?
oldZ80PC WORD ?
FwdAddr WORD ?
ForwardAddr WORD ?
FwdAddrValid BYTE ?
FwdAddrRST BYTE ?
ForwardAddrValid BYTE ?
DissLineLength BYTE ?
GotOffset BYTE ?
DissOffset BYTE ?
WantBlankLine BYTE ?
ViewAsDump BYTE ?
DebugSHIFTKeyDown BYTE ?
DebugCTRLKeyDown BYTE ?
DisassemblyUpdated BYTE ?
in_single_step byte ?
snow_float byte ? ; (bool) does floating bus allow for snow effect data bus reads?
align 4
DissScrollBarhWnd dd ?
DissScrollBarInfo SCROLLINFO <?>
DebugWindowRect RECT <?>
MAXBREAKPOINTS equ 32
TBREAKPOINT STRUCT
PC DWORD ? ; PC address in lower 16 bits, upper = 0 for in use, $FFFF not in use
Enabled BYTE ? ; is breakpoint currently enabled; a breakpoint can be in use but not currently active
_pad BYTE 3 dup (?)
TBREAKPOINT ENDS
.data
align 16
RunDebugFrame1 LABEL DWORD ; 4 bytes, any of which cause the debug frame to run
Check_Breakpoints db FALSE
Check_RunTo db FALSE
Check_LeaveROMSpace db FALSE
Check_TraceHook db FALSE
RunDebugFrame2 LABEL DWORD ; 4 bytes, any of which cause the debug frame to run
Check_ExitSub db FALSE
FDCBreakEnabled db FALSE
Check_EnterROMSpace db FALSE
db FALSE ; spare trap conditions
BreakPoints db (MAXBREAKPOINTS * sizeof TBREAKPOINT) dup (-1) ; list of breakpoint addresses
TraceHook dd 0
TraceStopFlag db 0
BreakPointCnt db 0 ; number of active breakpoints
ShowHex db TRUE
ShowOpsAsAscii db FALSE
GotWindowPlacement db FALSE
RasterUpdateDisplay db FALSE
DebuggerActive db FALSE
MaxDisassemblyLines db 27
MaxDumpAsHexDec db 8
MaxDumpAsAscii db 16
RESETENUM
ENUM diss_large_font, diss_small_font
disassemblyfontsize db diss_large_font ; defaults to large font
DebuggerError db "Debugger error", 0
szToolBarClass db "ToolbarWindow32", 0
.data?
align 4
hDbgToolBar HWND ?
TempMemoryAddress WORD ?
.code
include DockWindow.asm
include CustomWindowMessages.asm
include SourceRipper.asm
include DebugFind.asm
include Registers.asm
include DebugPlus3.asm
include DebugIDE.asm
include DebugRunTo.asm
include DebugMemory.asm
include DebugPCHistory.asm
include DebugBreakpoints.asm
include DebugCommandParser.asm
align 16
UpdateDebugDisplay proc
.if RasterUpdateDisplay == FALSE
; to get the correct +3 floating bus value in the debugger,
; we render to the current tstate and then preserve the +3 floating value while the full frame is rendered
RENDERCYCLES
movzx eax, SPGfx.plus3_float_byte
push eax
RENDERFRAME
pop eax
mov SPGfx.plus3_float_byte, al
.else
RENDERCYCLES
invoke SetDirtyLines
UPDATEWINDOW
.endif
ret
UpdateDebugDisplay endp
;UpdateDebugDisplay proc
; .if RasterUpdateDisplay == FALSE
; RENDERFRAME
; .else
; RENDERCYCLES
; invoke SetDirtyLines
; UPDATEWINDOW
; .endif
; ret
;UpdateDebugDisplay endp
; used at runtime, this checks for an enabled breakpoint at the specified address
ISBREAKPOINT MACRO Address ; word
local @exit
movzx eax, Address
lea esi, BreakPoints
mov ecx, MAXBREAKPOINTS
@@: cmp eax, [esi].TBREAKPOINT.PC
je @F ; zero set if breakpoint hit
jc @exit ; early exit; breakpoints are sorted in ascending order so Carry indicates we're beyond this BP value or hit end marker
add esi, sizeof TBREAKPOINT
dec ecx
jnz @B
inc ecx ; zero clear if no breakpoint hit
jmp @exit
; come here if we've hit this breakpoint address
; set zero flag based on if this BP is currently enabled
@@: cmp [esi].TBREAKPOINT.Enabled, TRUE
@exit:
ENDM
; search for a breakpoint at the specified address only, irrespective of enabled state
ISBREAKPOINTDEFINED MACRO Address ; word
local @exit
movzx eax, Address
lea esi, BreakPoints
mov ecx, MAXBREAKPOINTS
@@: cmp eax, [esi].TBREAKPOINT.PC
je @exit ; zero set if breakpoint address matches
jc @exit ; early exit; breakpoints are sorted in ascending order so Carry indicates we're beyond this BL value or hit end marker
add esi, sizeof TBREAKPOINT
dec ecx
jnz @B
inc ecx ; zero clear if no breakpoint hit
jmp @exit
@exit:
ENDM
HASLEFTROMSPACE MACRO
; exit if execution address leaves ROM space
; Note: range changed to above 128K paging routines
; and to ignore returning from ROM ISR
.if Check_LeaveROMSpace == TRUE
mov ax, MACHINE.RomSpaceUpperCheck
.if (zPC >= ax) && (PrevzPC < ax)
.if (PrevzPC < 38h) || (PrevzPC > 52h)
jmp DebugFrame_Trap
.endif
.endif
.endif
ENDM
HASENTEREDROMSPACE MACRO
; exit if execution address enters ROM space
; Note: range changed to above 128K paging routines
; and to ignore entering the ROM ISR
.if Check_EnterROMSpace == TRUE
mov ax, MACHINE.RomSpaceUpperCheck
.if (zPC < ax) && (PrevzPC >= ax)
.if (zPC < 38h) || (zPC > 52h)
jmp DebugFrame_Trap
.endif
.endif
.endif
ENDM
align 16
HandleDebuggerDialog:
CLEARSOUNDBUFFERS
.if FullScreenMode == TRUE
invoke FlipDisplayMode
invoke AttachMenu, hWnd
.endif
mov MenuNoUnattach, TRUE
mov Check_RunTo, FALSE
mov Check_ExitSub, FALSE
invoke DialogBoxParam, [GlobalhInst], IDD_DEBUGGER, [hWnd], addr DebuggerDlgProc, NULL
mov MenuNoUnattach, FALSE
ret
align 16
SetDebugMenuCheck proc MenuItemID:DWORD, Value:BYTE
.if Value == 0
mov eax, MF_UNCHECKED or MF_BYCOMMAND
.else
mov eax, MF_CHECKED or MF_BYCOMMAND
.endif
invoke CheckMenuItem, DebugMenuHandle, MenuItemID, eax
ret
SetDebugMenuCheck endp
CLOSE_DEBUGGER macro
jmp Close_Debugger
endm
align 16
DebuggerDlgProc proc uses ebx esi edi,
hWndDlg: DWORD,
uMsg: DWORD,
wParam: DWORD,
lParam: DWORD
LOCAL BreakControl: DWORD,
wParamLow: WORD,
wParamHigh: WORD,
CurrentZ80PC: WORD,
SearchWrapped: BOOL,
tempDissString[300]:BYTE
local textstring: TEXTSTRING,
pTEXTSTRING: DWORD
RESETMSG
OnInitDialog
mov DebuggerActive, TRUE
ifc MAXIMUMSPEED eq TRUE then call SetNormalSpeed ; restore to normal speed
; create global window handle
m2m Debugger_hWnd, hWndDlg
mov DebugSHIFTKeyDown, FALSE
mov DebugCTRLKeyDown, FALSE
mov DebugMenuHandle, $fnc (GetMenu, Debugger_hWnd)
; create each debugger dialog window
mov FindDLG.hWnd, $fnc (CreateDialogParam, GlobalhInst, IDD_DEBUGFINDDLG, hWndDlg, addr DebugFindDlgProc, NULL)
mov SourceRipperDLG.hWnd, $fnc (CreateDialogParam, GlobalhInst, IDD_VIEWDISASSEMBLYDLG, hWndDlg, addr SourceRipperDlgProc, NULL)
mov RegistersDLG.hWnd, $fnc (CreateDialogParam, GlobalhInst, IDD_DEBUGREGISTERSDLG, hWndDlg, addr RegistersDlgProc, NULL)
mov Plus3DLG.hWnd, $fnc (CreateDialogParam, GlobalhInst, IDD_DEBUGPLUS3DLG, hWndDlg, addr DebugPlus3DlgProc, NULL)
mov IDEDLG.hWnd, $fnc (CreateDialogParam, GlobalhInst, IDD_DEBUGIDEDLG, hWndDlg, addr DebugIDEDlgProc, NULL)
mov MemoryDLG.hWnd, $fnc (CreateDialogParam, GlobalhInst, IDD_DEBUGMEMORYDLG, hWndDlg, addr DebugMemoryDlgProc, NULL)
mov PCHistoryDLG.hWnd, $fnc (CreateDialogParam, GlobalhInst, IDD_DEBUGPCHISTORYDLG, hWndDlg, addr DebugPCHistoryDlgProc, NULL)
mov BreakpointsDLG.hWnd, $fnc (CreateDialogParam, GlobalhInst, IDD_DEBUGBREAKPOINTSDLG,hWndDlg, addr DebugBreakpointsDlgProc, NULL)
mov CommandParserDLG.hWnd,$fnc (CreateDialogParam, GlobalhInst, IDD_COMMANDPARSERDLG, hWndDlg, addr DebugCmdParserDlgProc, NULL)
mov FindDLG.lpName, CTXT ("DebugFind")
mov SourceRipperDLG.lpName, CTXT ("DebugSourceRipper")
mov RegistersDLG.lpName, CTXT ("DebugRegisters")
mov Plus3DLG.lpName, CTXT ("DebugPlus3")
mov IDEDLG.lpName, CTXT ("DebugIDE")
mov MemoryDLG.lpName, CTXT ("DebugMemory")
mov PCHistoryDLG.lpName, CTXT ("DebugPCHistory")
mov BreakpointsDLG.lpName, CTXT ("DebugBreakpoints")
mov CommandParserDLG.lpName,CTXT ("DebugCommandParser")
; send each debugger dialog window their LP_LOADSTATE message
invoke SendMessage, FindDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_LOADSTATE
invoke SendMessage, SourceRipperDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_LOADSTATE
invoke SendMessage, RegistersDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_LOADSTATE
invoke SendMessage, Plus3DLG.hWnd, WM_COMMAND, WPARAM_USER, LP_LOADSTATE
invoke SendMessage, IDEDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_LOADSTATE
invoke SendMessage, MemoryDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_LOADSTATE
invoke SendMessage, PCHistoryDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_LOADSTATE
invoke SendMessage, BreakpointsDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_LOADSTATE
invoke SendMessage, CommandParserDLG.hWnd,WM_COMMAND, WPARAM_USER, LP_LOADSTATE
; send each debugger dialog window their LP_SETSHOWSTATE message
invoke SendMessage, FindDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_SETSHOWSTATE
invoke SendMessage, SourceRipperDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_SETSHOWSTATE
invoke SendMessage, RegistersDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_SETSHOWSTATE
invoke SendMessage, Plus3DLG.hWnd, WM_COMMAND, WPARAM_USER, LP_SETSHOWSTATE
invoke SendMessage, IDEDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_SETSHOWSTATE
invoke SendMessage, MemoryDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_SETSHOWSTATE
invoke SendMessage, PCHistoryDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_SETSHOWSTATE
invoke SendMessage, BreakpointsDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_SETSHOWSTATE
invoke SendMessage, CommandParserDLG.hWnd,WM_COMMAND, WPARAM_USER, LP_SETSHOWSTATE
; handle debugger specific menu items
.if HardwareMode == HW_PENTAGON128
invoke EnableMenuItem, DebugMenuHandle, IDM_TRDOS_ENABLEREADPORTS, MF_ENABLED or MF_BYCOMMAND
invoke EnableMenuItem, DebugMenuHandle, IDM_TRDOS_ENABLEWRITEPORTS, MF_ENABLED or MF_BYCOMMAND
.endif
mov DISASSEMBLYhWnd, $fnc (GetDlgItem, hWndDlg, IDC_DISASSEMBLYLST)
mov DissScrollBarhWnd, $fnc (GetDlgItem, hWndDlg, IDC_DISASSEMBLYSCB)
mov DissScrollBarInfo.SCROLLINFO.cbSize, sizeof SCROLLINFO
mov DissScrollBarInfo.SCROLLINFO.fMask, SIF_POS or SIF_RANGE
mov DissScrollBarInfo.SCROLLINFO.nPage, 1
mov DissScrollBarInfo.SCROLLINFO.nMin, 0
mov DissScrollBarInfo.SCROLLINFO.nMax, 65535
mov DissScrollBarInfo.SCROLLINFO.nPos, 0
invoke SetScrollInfo, DissScrollBarhWnd, SB_CTL, addr DissScrollBarInfo, TRUE
; preserve the disassembly window's original font which is restored on the OnClose event
mov DISASSEMBLYOldFont, $fnc (SendMessage, DISASSEMBLYhWnd, WM_GETFONT, 0, 0)
invoke SetDisassemblyFontSize, disassemblyfontsize
; set the required menuitem checkbox states
invoke SetDebugMenuCheck, IDM_BREAKLEAVINGROMSPACE, Check_LeaveROMSpace
invoke SetDebugMenuCheck, IDM_BREAKENTERINGROMSPACE, Check_EnterROMSpace
invoke SetDebugMenuCheck, IDM_RASTERUPDATE, RasterUpdateDisplay
; restore last dialog location if available
invoke GetDialogPlacement
; window handle of disassembly control
mov hwndDissTT, 0 ; allows for recreation of disassembly control's tooltip control
mov DISLST_Handle, $fnc (GetDlgItem, Debugger_hWnd, IDC_DISASSEMBLYLST)
mov OrigDISLSTWndProc, $fnc (SetWindowLong, DISLST_Handle, GWL_WNDPROC, addr DISLST_SubclassProc)
invoke InitCursorStack
; we must clear MAXIMUMAUTOLOADTYPE to turn off max speed emulation if the tape autoload typer was active
; else it would remain active if we hit a breakpoint en-route
mov MAXIMUMAUTOLOADTYPE, FALSE
; clear the RAM-only flag for RunTo_PortRead condition
mov RunToPortRAMOnly, FALSE
; setup starting disassembly address
mov ax, zPC
mov Z80PC, ax
.if UsePrevzPC == TRUE ; set if trapped on memory breakpoint, etc.
mov UsePrevzPC, FALSE
mov ax, PrevzPC
mov Z80PC, ax
.endif
invoke SetProfileCycles
invoke SetDebugReadWriteButtonStates, hWndDlg
invoke CheckDlgButton, hWndDlg, IDC_DUMPCHK, ZeroExt (ViewAsDump)
invoke EnableDumpControls, hWndDlg
invoke UpdateDebugger
invoke SetDebuggerLogButtonState ; start/stop PC logging button state + text
invoke AddDebuggerToolBar, GlobalhInst, Debugger_hWnd
movzx eax, EmuRunning
xor eax, TRUE
invoke SendMessage, hDbgToolBar, TB_CHECKBUTTON, IDM_PAUSE, eax
; attach menus to debugger controls
mov DissMenuHandle, $fnc (LoadMenu, GlobalhInst, IDR_DISASSEMBLYMENU)
invoke SendDlgItemMessage, Debugger_hWnd, IDC_DISASSEMBLYLST, RT_SETMENU, 0, $fnc (GetSubMenu, DissMenuHandle, 0)
; set Debug->Run To Tape Starts/Stops menu items
.if TapePlaying == TRUE
mov esi, MF_GRAYED or MF_BYCOMMAND
mov edi, MF_ENABLED or MF_BYCOMMAND
.else
mov esi, MF_ENABLED or MF_BYCOMMAND
mov edi, MF_GRAYED or MF_BYCOMMAND
.endif
invoke EnableMenuItem, DebugMenuHandle, IDM_RUNTOTAPESTARTS, esi
invoke EnableMenuItem, DebugMenuHandle, IDM_RUNTOTAPESTOPS, edi
invoke UpdateDebugDisplay
invoke PopulateExecCmd
invoke PopulateIDEDlg
invoke PopulateMemoryDlg
invoke PopulatePCHistoryDlg
invoke SetPagingInfo
invoke SendMessage, hWndDlg, WM_SETICON, ICON_SMALL, $fnc (LoadIcon, hInstance, IDI_DEBUGGERICON)
; we're setting initial debugger control focus to our hidden rawtext control
; to prevent keyboard input from initially activating any debugger controls (this was auto-stepping on space bar in certain circumstances)
invoke SetFocus, $fnc (GetDlgItem, Debugger_hWnd, IDC_DEBUGGERDEFAULTRAW)
.if eax == NULL
ADDMESSAGE "Debugger SetFocus () failed!"
.endif
return FALSE ; overrides dialog's default control activation
OnSysColorChange
invoke SendMessage, $fnc (GetDlgItem, Debugger_hWnd, IDT_DEBUGTOOLBAR), uMsg, wParam, lParam
invoke InvalidateRect, $fnc (GetDlgItem, Debugger_hWnd, IDT_DEBUGTOOLBAR), NULL, TRUE
invoke UpdateWindow, $fnc (GetDlgItem, Debugger_hWnd, IDT_DEBUGTOOLBAR)
OnNotify
ASSUME EBX: PTR NMHDR
mov ebx, lParam
.if [ebx].NMHDR.code == TTN_NEEDTEXT
ASSUME EBX: PTR TOOLTIPTEXT
mov [ebx].hInst, NULL
switch [ebx].hdr.idFrom
case IDM_DBGLOADSNAPSHOT
mov [ebx].lpszText, CTXT ("Load Snapshot")
return 0
case IDM_DBGSAVESNAPSHOT
mov [ebx].lpszText, CTXT ("Save Snapshot")
return 0
case IDM_PAUSE
mov [ebx].lpszText, CTXT ("Pause")
return 0
case IDM_GOTOADDRESS
mov [ebx].lpszText, CTXT ("Go To")
return 0
.else
mov [ebx].lpszText, NULL
return 0
endsw
.endif
return TRUE
ASSUME EBX: NOTHING
OnCommand
mov eax, wParam
mov wParamLow, ax
shr eax, 16
mov wParamHigh, ax
.if wParam == WPARAM_USER
switch lParam
case LP_USERFIND
.if SearchByteCount > 0
.if SearchInDisassembly == TRUE
mov bx, Z80PC
mov SearchWrapped, FALSE
invoke INITTEXTSTRING, addr textstring, addr pTEXTSTRING
invoke DisassembleLine, pTEXTSTRING
.while SearchWrapped == FALSE
mov ax, Z80PC
mov CurrentZ80PC, ax
invoke INITTEXTSTRING, addr textstring, addr pTEXTSTRING
invoke DisassembleLine, pTEXTSTRING
mov ax, Z80PC
.if ax < CurrentZ80PC
mov SearchWrapped, TRUE
.endif
lea esi, textstring
lea edi, tempDissString
.while TRUE
lodsb
.break .if al == 0
.if al == " "
stosb
.while al == " "
lodsb
.endw
dec esi
.else
stosb
.endif
.endw
mov al, " "
stosb ; main string must be longer than substring
xor al, al
stosb ; null-terminate main string
invoke InString, 1, ADDR tempDissString, ADDR SearchParam
test eax, eax
.if (!SIGN?) && (eax > 0)
; found a match
mov ax, CurrentZ80PC
mov Z80PC, ax
invoke UpdateDisassembly
return TRUE
.endif
.endw
mov Z80PC, bx
jmp SearchMatchFail
.endif
mov cx, Z80PC
inc cx
SearchAgain:
mov bx, cx
lea esi, SearchParam
mov edx, SearchByteCount
@@: call MemGetByte
cmp al, [esi]
jne NoSearchMatch
inc esi
inc bx
dec edx
jnz @B
mov Z80PC, cx
invoke UpdateDisassembly
return TRUE
NoSearchMatch:
inc cx
jnz SearchAgain
SearchMatchFail:
invoke EnableDebugWindows, FALSE
invoke ShowMessageBox, [hWndDlg], SADD("No Match Found"), ADDR szWindowName, MB_OK or MB_ICONSTOP
invoke EnableDebugWindows, TRUE
.endif
; Find dialog was active when "Find" option was clicked
invoke SetFocus, FindDLG.hWnd
return TRUE
endsw
return TRUE
.endif
.if wParamLow == IDC_DISASSEMBLYLST
.if wParamHigh == RTN_SELCHANGE
invoke GetSelectedLine
mov ax, [PCTable+eax*2] ; get the PC value for the selected line
mov Z80PC, ax
invoke UpdateDisassembly ; updates display and sets index to 0
UPDATEWINDOW
return TRUE
.elseif wParamHigh == RTN_ENTERMENULOOP
mov ebx, $fnc (GetSubMenu, DissMenuHandle, 0)
switch disassemblyfontsize
case diss_large_font
invoke CheckMenuItem, ebx, IDM_DISS_LARGE_FONT, MF_BYCOMMAND or MF_CHECKED
invoke CheckMenuItem, ebx, IDM_DISS_SMALL_FONT, MF_BYCOMMAND or MF_UNCHECKED
case diss_small_font
invoke CheckMenuItem, ebx, IDM_DISS_LARGE_FONT, MF_BYCOMMAND or MF_UNCHECKED
invoke CheckMenuItem, ebx, IDM_DISS_SMALL_FONT, MF_BYCOMMAND or MF_CHECKED
endsw
return TRUE
.elseif wParamHigh == RTN_EXITMENULOOP
return TRUE
.elseif wParamHigh == RTN_MENUITEM
switch lParam
case IDM_DISS_BACK
invoke RetraceReference
return TRUE
case IDM_DISS_SHOWNEXTINSTRUCTION
invoke SetNewZ80PC, zPC
return TRUE
case IDM_DISS_RUNTOSELECTED
invoke GetSelectedLine
mov ax, [PCTable+eax*2] ; get the PC value for the selected line
mov RunToPC, ax
invoke Set_RunTo_Condition, RUN_TO_PC
CLOSE_DEBUGGER
case IDM_DISS_TOGGLEBREAKPOINT
invoke GetSelectedLine
mov ax, [PCTable+eax*2] ; get the PC value for the selected line
invoke ToggleBreakpoint, ax
invoke UpdateDebugger
return TRUE
case IDM_DISS_LARGE_FONT
mov disassemblyfontsize, diss_large_font
invoke SetDisassemblyFontSize, disassemblyfontsize
invoke UpdateDisassembly
case IDM_DISS_SMALL_FONT
mov disassemblyfontsize, diss_small_font
invoke SetDisassemblyFontSize, disassemblyfontsize
invoke UpdateDisassembly
endsw
.endif
.endif
.if wParam == IDCANCEL
CLOSE_DEBUGGER
.endif
.if wParamHigh == BN_CLICKED
.if (wParamLow == IDC_DISSBREAKONREAD) || (wParamLow == IDC_DISSBREAKONWRITE) || (wParamLow == IDC_DISSBREAKONACCESS)
movzx eax, wParamLow
mov BreakControl, eax
invoke SendDlgItemMessage, hWndDlg, BreakControl, BM_GETSTATE, 0, 0
and eax, BST_CHECKED
.if eax != 0
invoke SendDlgItemMessage, hWndDlg, IDC_COMPDISPLAYLST, LB_GETCURSEL, 0, 0
.if eax != LB_ERR
; Stop hook procs use value in Z80PC, which is correct here
.if BreakControl == IDC_DISSBREAKONREAD
call StopatMemRead
.elseif BreakControl == IDC_DISSBREAKONWRITE
call StopatMemWrite
.elseif BreakControl == IDC_DISSBREAKONACCESS
call StopatMemAccess
.endif
.endif
.else
mov Check_TraceHook, FALSE
.endif
invoke SetDebugReadWriteButtonStates, hWndDlg
invoke UpdateDebugger
return TRUE
.elseif wParamLow == IDC_STEP ; single step
invoke Single_Step
invoke UpdateDebugDisplay
invoke UpdateDebugger
invoke SetProfileCycles
invoke PopulateExecCmd
invoke PopulateIDEDlg
invoke PopulateMemoryDlg
invoke PopulatePCHistoryDlg
invoke SetPagingInfo
return TRUE
.elseif wParamLow == IDC_HEXDEC ; flip hex/dec
xor ShowHex, TRUE
invoke UpdateDebugger
invoke PopulateExecCmd
invoke PopulateIDEDlg
invoke PopulateMemoryDlg
invoke PopulatePCHistoryDlg
invoke PopulateBrkListbox
return TRUE
.elseif wParamLow == IDC_HEXASCII ; flip hex/ascii
xor ShowOpsAsAscii, TRUE
invoke UpdateDebugger
invoke PopulateMemoryDlg
return TRUE
.elseif wParamLow == IDC_DUMPCHK ; flip mem dump/disassembly
xor ViewAsDump, TRUE
invoke EnableDumpControls, hWndDlg
invoke UpdateDebugger
return TRUE
.elseif wParamLow == IDC_START_STOP_LOGGING_CHK ; start/stop PC logging
.if DoLogging == FALSE
invoke Start_PC_Logging, NULL
.else
invoke Stop_PC_Logging
.endif
return TRUE
.elseif wParamLow == IDC_RUNTO ; run to selected address
invoke Set_RunTo_Condition, RUN_TO_PC
mov ax, Z80PC
mov RunToPC, ax
CLOSE_DEBUGGER
.elseif wParamLow == IDC_EXITSUB ; exit subroutine
mov Check_ExitSub, TRUE
mov RETCounter, 0
CLOSE_DEBUGGER
.elseif wParamLow == IDC_STEPOVER ; run to the following opcode
invoke Set_RunTo_Condition, RUN_TO_PC
mov ax, [PCTable+2] ; address of next opcode
mov RunToPC, ax
CLOSE_DEBUGGER
.elseif wParamLow == IDC_TOGGLEBREAKPOINT ; toggle breakpoint at this address
invoke ToggleBreakpoint, Z80PC
invoke UpdateDebugger
return TRUE
.elseif wParamLow == IDC_CLEARBREAKPOINTS ; clear all breakpoints
invoke ClearBreakpoints
invoke UpdateDebugger
return TRUE
.elseif wParamLow == IDC_FOLLOWREF ; follow a forward reference
invoke FollowReference
return TRUE
.elseif wParamLow == IDC_BACKREF ; retrace from cursor stack
invoke RetraceReference
return TRUE
.elseif wParamLow == IDC_POKEMEM ; poke memory
movzx ebx, Z80PC
mov PokeAddressInit, ebx
call MemGetByte
and eax, 255
mov PokeValueInit, eax
mov PokeUpdatesDebugger, TRUE ; disassembly updates as pokes are made
; bring up the normal Poke dialog with the debugger as the owner window
invoke DialogBoxParam, GlobalhInst, IDD_POKE, [Debugger_hWnd], addr PokeDlgProc, NULL
return TRUE
.elseif wParamLow == IDC_PREV_PC_STC ; go to previous PC location
invoke SetNewZ80PC, PrevzPC
return TRUE
.endif
.endif
; menu commands
.if wParamHigh == 0
.if wParamLow == IDM_VIEW_REGISTERS ; registers dialog
invoke SendMessage, RegistersDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_TOGGLESHOWSTATE
invoke UpdateAllRegisters
return TRUE
.elseif wParamLow == IDM_VIEW_FIND ; find dialog
invoke SendMessage, FindDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_TOGGLESHOWSTATE
return TRUE
.elseif wParamLow == IDM_VIEW_SOURCECODE_RIPPER ; disassembly viewer/ripper dialog
invoke SendMessage, SourceRipperDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_TOGGLESHOWSTATE
return TRUE
.elseif wParamLow == IDM_VIEW_PLUS3 ; plus 3 dialog
invoke SendMessage, Plus3DLG.hWnd, WM_COMMAND, WPARAM_USER, LP_TOGGLESHOWSTATE
return TRUE
.elseif wParamLow == IDM_VIEW_IDE ; IDE dialog
invoke SendMessage, IDEDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_TOGGLESHOWSTATE
return TRUE
.elseif wParamLow == IDM_VIEW_MEMORY ; Memory dialog
invoke SendMessage, MemoryDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_TOGGLESHOWSTATE
.elseif wParamLow == IDM_VIEW_PC_HISTORY ; PC History dialog
invoke SendMessage, PCHistoryDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_TOGGLESHOWSTATE
.elseif wParamLow == IDM_VIEW_BREAKPOINTS ; Breakpoints dialog
invoke SendMessage, BreakpointsDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_TOGGLESHOWSTATE
.elseif wParamLow == IDM_VIEW_COMMAND_PARSER ; Command Parser dialog
invoke SendMessage, CommandParserDLG.hWnd, WM_COMMAND, WPARAM_USER, LP_TOGGLESHOWSTATE
.elseif wParamLow == IDM_RUNTOFRAMESTART ; run to start of frame
mov RunTo_Cycle, 1000
invoke Set_RunTo_Condition, RUN_TO_CYCLE
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTOFRAMEEND ; run to end of frame
mov RunTo_Cycle, @EVAL (MACHINE.FrameCycles - 1000)
invoke Set_RunTo_Condition, RUN_TO_CYCLE
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTOINTERRUPT ; run to interrupt
invoke Set_RunTo_Condition, RUN_TO_INTERRUPT
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTOINTERRUPTRETRIGGER ; run to retriggered interrupt
invoke Set_RunTo_Condition, RUN_TO_INTERRUPT_RETRIGGER
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTOSPECIFIEDCYCLE ; run to specified cycle
.if $fnc (GetNumericInput, hWndDlg, hInstance, hIcon, SADD ("Run To Specified Cycle"), SADD ("Cycle:")) == TRUE
.if ecx < MACHINE.FrameCycles
mov RunTo_Cycle, ecx
invoke Set_RunTo_Condition, RUN_TO_CYCLE
CLOSE_DEBUGGER
.endif
.endif
return TRUE
.elseif wParamLow == IDM_RUNTOHALTED ; run until CPU is HALTed
invoke Set_RunTo_Condition, RUN_TO_HALTED
CLOSE_DEBUGGER
.elseif (wParamLow >= IDM_KEYROW_1_5) && (wParamLow <= IDM_KEYROW_B_SPACE) ; keyboard half-row scans
movzx eax, wParamLow
sub eax, IDM_KEYROW_1_5
mov ax, [Run_KeyHalfRowMasks+eax*2]
mov RunToPortMask, ax
mov RunToPortReadAddr, 0
mov RunToPortRAMOnly, TRUE ; only break for keyscans when in RAM code
invoke Set_RunTo_Condition, RUN_TO_PORT_READ
CLOSE_DEBUGGER
.elseif wParamLow == IDM_KEYROW_ANY_KEY ; any keyboard half-row scan
mov RunToPortMask, 0001h
mov RunToPortReadAddr, 0
mov RunToPortRAMOnly, TRUE ; only break for any keyscan when in RAM code
invoke Set_RunTo_Condition, RUN_TO_PORT_READ
CLOSE_DEBUGGER
.elseif (wParamLow >= IDM_TRDOS_READSYSTEMREGISTER) && (wParamLow <= IDM_TRDOS_READDATAREGISTER) ; TR_DOS port reads
switch wParamLow
case IDM_TRDOS_READSYSTEMREGISTER
mov RunToDevicePort, TRDOS_SYSTEM_REGISTER
case IDM_TRDOS_READSTATUSREGISTER
mov RunToDevicePort, TRDOS_STATUS_REGISTER
case IDM_TRDOS_READTRACKREGISTER
mov RunToDevicePort, TRDOS_TRACK_REGISTER
case IDM_TRDOS_READSECTORREGISTER
mov RunToDevicePort, TRDOS_SECTOR_REGISTER
case IDM_TRDOS_READDATAREGISTER
mov RunToDevicePort, TRDOS_DATA_REGISTER
endsw
invoke Set_RunTo_Condition, RUN_TO_DEVICE_PORT_READ
CLOSE_DEBUGGER
.elseif wParamLow == IDM_FLOATINGBUSREAD ; run until port read from the floaing bus
invoke Set_RunTo_Condition, RUN_TO_FLOATING_BUS_PORT_READ
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTOSPECIFIEDPORTREAD ; run until port read from specified port
.if $fnc (GetNumericInput, hWndDlg, hInstance, hIcon, SADD ("Run until read from specified port"), SADD ("Port Address:")) == TRUE
.if ecx <= 65535
ifc ecx ge 256 then mov RunToPortMask, 65535 else mov RunToPortMask, 255
mov RunToPortReadAddr, cx
invoke Set_RunTo_Condition, RUN_TO_PORT_READ
CLOSE_DEBUGGER
.endif
.endif
return TRUE
.elseif (wParamLow >= IDM_TRDOS_WRITESYSTEMREGISTER) && (wParamLow <= IDM_TRDOS_WRITEDATAREGISTER) ; TR_DOS port writes
switch wParamLow
case IDM_TRDOS_WRITESYSTEMREGISTER
mov RunToDevicePort, TRDOS_SYSTEM_REGISTER
case IDM_TRDOS_WRITECOMMANDREGISTER
mov RunToDevicePort, TRDOS_COMMAND_REGISTER
case IDM_TRDOS_WRITETRACKREGISTER
mov RunToDevicePort, TRDOS_TRACK_REGISTER
case IDM_TRDOS_WRITESECTORREGISTER
mov RunToDevicePort, TRDOS_SECTOR_REGISTER
case IDM_TRDOS_WRITEDATAREGISTER
mov RunToDevicePort, TRDOS_DATA_REGISTER
endsw
invoke Set_RunTo_Condition, RUN_TO_DEVICE_PORT_WRITE
CLOSE_DEBUGGER
.elseif wParamLow == IDM_ULA_FE ; ULA Port
mov RunToDevicePort, ULA_FE
invoke Set_RunTo_Condition, RUN_TO_DEVICE_PORT_WRITE
CLOSE_DEBUGGER
.elseif wParamLow == IDM_PAGING_7FFD ; 128K Paging Port
mov RunToDevicePort, PAGING_7FFD
invoke Set_RunTo_Condition, RUN_TO_DEVICE_PORT_WRITE
CLOSE_DEBUGGER
.elseif wParamLow == IDM_PAGING_1FFD ; +3 Paging Port
mov RunToDevicePort, PAGING_1FFD
invoke Set_RunTo_Condition, RUN_TO_DEVICE_PORT_WRITE
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTOSPECIFIEDPORTWRITE ; run until port write to specified port
.if $fnc (GetNumericInput, hWndDlg, hInstance, hIcon, SADD ("Run until write to specified port"), SADD ("Port Address:")) == TRUE
.if ecx <= 65535
ifc ecx ge 256 then mov RunToPortMask, 65535 else mov RunToPortMask, 255
mov RunToPortWriteAddr, cx
invoke Set_RunTo_Condition, RUN_TO_PORT_WRITE
CLOSE_DEBUGGER
.endif
.endif
return TRUE
.elseif wParamLow == IDM_RUNTOTAPESTARTS ; run until tape starts
invoke Set_RunTo_Condition, RUN_TO_TAPE_STARTS
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTOTAPESTOPS ; run until tape stops
invoke Set_RunTo_Condition, RUN_TO_TAPE_STOPS
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTODISKMOTORON ; run until disk motor turns on
invoke Set_RunTo_Condition, RUN_TO_DISK_MOTOR_ON
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTODISKMOTOROFF ; run until disk motor turns off
invoke Set_RunTo_Condition, RUN_TO_DISK_MOTOR_OFF
CLOSE_DEBUGGER
; run to z80 opcode menu items
.elseif wParamLow == IDM_RUNTOIM1 ; run until IM 1
invoke Set_RunTo_Condition, RUN_TO_OPCODE
mov RunToOpcode, 0ED56h
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTOIM2 ; run until IM 2
invoke Set_RunTo_Condition, RUN_TO_OPCODE
mov RunToOpcode, 0ED5Eh
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTODI ; run until DI
invoke Set_RunTo_Condition, RUN_TO_OPCODE
mov RunToOpcode, 0F3h
CLOSE_DEBUGGER
.elseif wParamLow == IDM_RUNTOEI ; run until EI
invoke Set_RunTo_Condition, RUN_TO_OPCODE