forked from redcode/SpecEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DebugCommandParser.asm
1764 lines (1353 loc) · 88.9 KB
/
DebugCommandParser.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
CmdParserEdit_SubclassProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
CmdParser_Execute PROTO
Cmd_Fetch_String PROTO
Cmd_Fetch_Numeric_Val PROTO
Cmd_Fetch_Numeric PROTO
Cmd_Fetch_Numerics PROTO :DWORD
Cmd_AddHistoryBox PROTO :DWORD
CmdParser_SetEditText PROTO :DWORD
CopySpecMemToTemp PROTO :DWORD,:DWORD
CountByteRepeats PROTO :DWORD,:DWORD
CountZeroBits PROTO :DWORD,:DWORD
CreateXORData PROTO :DWORD,:DWORD
Encode PROTO :DWORD,:DWORD,:DWORD
Calc_CRC16_Byte PROTO :BYTE
Calc_CRC16_Data PROTO :DWORD,:DWORD
Init_CRC16 PROTO
.data?
align 4
OrigCmdParserEditWndProc DWORD ?
CmdParserEdit_Handle DWORD ?
cmd_parser_buffer BYTE 255 DUP (?)
.code
DebugCmdParserDlgProc proc uses ebx esi edi,
hWndDlg :DWORD,
uMsg :DWORD,
wParam :DWORD,
lParam :DWORD
invoke HandleCustomWindowMessages, addr CommandParserDLG, hWndDlg, uMsg, wParam, lParam
.if eax == TRUE
return TRUE
.endif
RESETMSG
OnInitDialog
; set menu ID on main debugger window's menu
mov CommandParserDLG.Menu_ID, IDM_VIEW_COMMAND_PARSER
invoke SendDlgItemMessage, hWndDlg, IDC_COMMANDEDT, EM_SETLIMITTEXT, sizeof cmd_parser_buffer, 0
mov CmdParserEdit_Handle, $fnc (GetDlgItem, hWndDlg, IDC_COMMANDEDT) ; window handle of query text edit box
invoke SetWindowLong, CmdParserEdit_Handle, GWL_WNDPROC, addr CmdParserEdit_SubclassProc
mov OrigCmdParserEditWndProc, eax
return TRUE
OnShowWindow
return TRUE
OnClose
return TRUE
OnDestroy
invoke SetWindowLong, CmdParserEdit_Handle, GWL_WNDPROC, OrigCmdParserEditWndProc
return NULL
OnCommand
switch wParam
case $WPARAM (RTN_DBLCLK, IDC_COMMAND_HISTORY)
invoke SendDlgItemMessage, CommandParserDLG.hWnd, IDC_COMMAND_HISTORY, RT_GETCURSELTEXT, 0, addr cmd_parser_buffer
.if eax != RT_ERR
invoke CmdParser_SetEditText, addr cmd_parser_buffer
.endif
endsw
return TRUE
OnDefault
return FALSE
DOMSG
DebugCmdParserDlgProc endp
CmdParser_SetEditText proc uses ebx,
lpText: DWORD
mov ebx, $fnc (GetDlgItem, CommandParserDLG.hWnd, IDC_COMMANDEDT)
invoke SendMessage, ebx, WM_SETTEXT, 0, lpText
invoke SendMessage, ebx, WM_KEYDOWN, VK_END, 0
invoke SendMessage, ebx, WM_KEYUP, VK_END, 0
invoke SetFocus, ebx
ret
CmdParser_SetEditText endp
CmdParserEdit_SubclassProc proc uses ebx esi edi,
hWin: DWORD,
uMsg: DWORD,
wParam: DWORD,
lParam: DWORD
switch uMsg
case WM_GETDLGCODE
return DLGC_WANTALLKEYS
case WM_CHAR
switch wParam
case VK_RETURN
mov wParam, 0 ; prevent Beep
invoke SendMessage, hWin, WM_GETTEXT, sizeof cmd_parser_buffer, addr cmd_parser_buffer
invoke SendMessage, hWin, WM_SETTEXT, 0, addr NULL_String
invoke CmdParser_Execute
return 0
endsw
case WM_KEYDOWN
switch wParam
case VK_UP
mov ebx, $fnc (GetDlgItem, CommandParserDLG.hWnd, IDC_COMMAND_HISTORY)
mov esi, $fnc (SendMessage, ebx, RT_GETCURSEL, 0, 0)
.if esi == -1
mov esi, $fnc (SendMessage, ebx, RT_GETCOUNT, 0, 0)
.else
ifc esi gt 0 then dec esi
.endif
invoke SendMessage, ebx, RT_SETCURSEL, esi, 0
invoke SendMessage, CommandParserDLG.hWnd, WM_COMMAND, $WPARAM (RTN_DBLCLK, IDC_COMMAND_HISTORY), 0
return 0
case VK_DOWN
mov ebx, $fnc (GetDlgItem, CommandParserDLG.hWnd, IDC_COMMAND_HISTORY)
mov esi, $fnc (SendMessage, ebx, RT_GETCURSEL, 0, 0)
.if esi == -1
xor esi, esi
.else
mov ecx, $fnc (SendMessage, ebx, RT_GETCOUNT, 0, 0)
ifc esi lt ecx then inc esi
.endif
invoke SendMessage, ebx, RT_SETCURSEL, esi, 0
invoke SendMessage, CommandParserDLG.hWnd, WM_COMMAND, $WPARAM (RTN_DBLCLK, IDC_COMMAND_HISTORY), 0
return 0
endsw
endsw
invoke CallWindowProc, OrigCmdParserEditWndProc, hWin, uMsg, wParam, lParam
ret
CmdParserEdit_SubclassProc endp
.data?
align 4
cmd_arg_num dd ?
cmd_arg_ptr dd ?
CMD_ARG_SIZE equ MAX_PATH
cmd_arg_cmd equ DummyMem
cmd_arg_1 equ cmd_arg_cmd + CMD_ARG_SIZE
cmd_arg_2 equ cmd_arg_1 + CMD_ARG_SIZE
cmd_arg_3 equ cmd_arg_2 + CMD_ARG_SIZE
cmd_arg_4 equ cmd_arg_3 + CMD_ARG_SIZE
cmd_arg_5 equ cmd_arg_4 + CMD_ARG_SIZE
align 4
mastertap_ofn OPENFILENAME <?>
.data
szMasterTapFilter db "TAP file (*.tap)", 0, "*.tap", 0,
0
.code
CmdParser_Execute proc uses esi edi ebx
local textstring: TEXTSTRING,
pTEXTSTRING: DWORD
local is_128K: DWORD,
testcount1: DWORD,
testcount2: DWORD
local temp1, temp2: DWORD,
temp3, temp4: DWORD,
temp5, temp6: DWORD
local lpUserAsmSrc: DWORD ; ptr to asm source line in "asm" command
local sa: SECURITY_ATTRIBUTES
local buffer1 [128]: BYTE
local tempfilepath [1024]: BYTE
local tempcurdir [MAX_PATH]: BYTE
local asmsourcefile [MAX_PATH]: BYTE ; path/filename
local asmsourcefilePath [MAX_PATH]: BYTE ; file path only
local asmsourcefileName [MAX_PATH]: BYTE ; file name only
local asmsourcefileBin [MAX_PATH]: BYTE ; asm Bin file name
local asmsourcefileSymbol [MAX_PATH]: BYTE ; asm Symbol file name
local asmsourcefileErr [MAX_PATH]: BYTE ; asm Error file name
local assemblersourcecode [1024]: BYTE
mov cmd_arg_num, 0
mov cmd_arg_ptr, offset cmd_arg_cmd
invoke Cmd_Fetch_String
jz CmdParser_Error
invoke szLower, addr cmd_arg_cmd
switch$ addr cmd_arg_cmd
; ============================
IFDEF PACMAN
PACARG macro
local @exit
invoke Cmd_Fetch_Numeric ; cmd_arg_1 = start level
mov cl, 0
jz @exit ; no arg given, use default 0
mov cl, al ; use given arg (0-255)
@exit:
endm
; ============================
case$ "pac"
PACARG
invoke Enable_Pacmode, PACMODE_FREEPLAY, cl
case$ "pacrecord"
PACARG
invoke Enable_Pacmode, PACMODE_RECORD, cl
case$ "pacplayback"
PACARG
invoke Enable_Pacmode, PACMODE_PLAYBACK, cl
case$ "!p"
PACARG
invoke Enable_Pacmode, PACMODE_RECORD, cl
ENDIF
; ============================
case$ "basic"
;zxamdpoke(23635,23755)
;zxamsetreg(pc,4770)
;zxamsetreg(iy,23610)
;zxamsetreg(im,1)
;zxamsetreg(int,1)
;zxamsetreg(sp,65352)
mov bx, 23635
mov ax, 23755
call MemPokeWord
mov bx, 23606
mov ax, 15360
call MemPokeWord
mov zPC, 4770
mov z80registers.iy.w, 23610
mov z80registers.intmode, 1
ENABLEINTS
mov z80registers._sp, 65352
; ============================
case$ "new"
invoke Cmd_Fetch_Numeric ; cmd_arg_1 = NEW address
jz CmdParser_Error
DISABLEINTS
mov z80registers.af.hi, 0
mov eax, dword ptr cmd_arg_1
mov z80registers.de.w, ax
mov zPC, 4555
; ============================
case$ "copymem"
invoke Cmd_Fetch_Numerics, 3 ; cmd_arg_1 = src; cmd_arg_2 = dest; cmd_arg_3 = size
jz CmdParser_Error
; attempt to allocate buffer memory
mov esi, $fnc (CopySpecMemToTemp, dword ptr cmd_arg_1, dword ptr cmd_arg_3)
test esi, esi
je CmdParser_Error
push esi
mov ebx, dword ptr cmd_arg_2 ; dest
.while dword ptr cmd_arg_3 > 0 ; size
mov al, [esi]
inc esi
call MemPokeByte
inc bx
dec dword ptr cmd_arg_3
.endw
pop esi
FreeMem (esi)
; ============================
case$ "fillmem"
invoke Cmd_Fetch_Numerics, 3 ; cmd_arg_1 = start; cmd_arg_2 = size; cmd_arg_3 = byte
jz CmdParser_Error
mov ebx, dword ptr cmd_arg_1 ; start
.while dword ptr cmd_arg_2 > 0 ; size
mov eax, dword ptr cmd_arg_3 ; byte
call MemPokeByte
inc bx
dec dword ptr cmd_arg_2
.endw
; ============================
case$ "out"
invoke Cmd_Fetch_Numerics, 2
jz CmdParser_Error
mov ebx, dword ptr cmd_arg_1
mov eax, dword ptr cmd_arg_2
push totaltstates
lea esi, RegisterBase
call OutPort
pop totaltstates
; ============================
case$ "hz"
invoke INITTEXTSTRING, addr textstring, addr pTEXTSTRING
ADDTEXTDECIMAL pTEXTSTRING, MACHINE.FramesPerSecond
ADDDIRECTTEXTSTRING pTEXTSTRING, " Hz"
invoke Cmd_AddHistoryBox, addr textstring
; ============================
case$ "z80v1"
mov save_z80_as_v1_enabled, TRUE
invoke Cmd_AddHistoryBox, SADD ("Saving 48K .z80 as v1")
; ============================
case$ "z80v3"
mov save_z80_as_v1_enabled, FALSE
invoke Cmd_AddHistoryBox, SADD ("Saving 48K .z80 as v3")
; ============================
case$ "bdr"
invoke INITTEXTSTRING, addr textstring, addr pTEXTSTRING
ADDDIRECTTEXTSTRING pTEXTSTRING, "Port $FE: $"
ADDTEXTHEX pTEXTSTRING, Last_FE_Write
ADDCHAR pTEXTSTRING, " "
ADDCHAR pTEXTSTRING, "("
ADDTEXTDECIMAL pTEXTSTRING, Last_FE_Write
ADDCHAR pTEXTSTRING, ")"
invoke Cmd_AddHistoryBox, addr textstring
; ============================
case$ "tk"
invoke INITTEXTSTRING, addr textstring, addr pTEXTSTRING
ADDDIRECTTEXTSTRING pTEXTSTRING, "Port $FC: $"
ADDTEXTHEX pTEXTSTRING, CBI_Port_252
ADDCHAR pTEXTSTRING, " "
ADDCHAR pTEXTSTRING, "("
ADDTEXTDECIMAL pTEXTSTRING, CBI_Port_252
ADDCHAR pTEXTSTRING, ")"
invoke Cmd_AddHistoryBox, addr textstring
invoke INITTEXTSTRING, addr textstring, addr pTEXTSTRING
ADDDIRECTTEXTSTRING pTEXTSTRING, "Port $FF: $"
ADDTEXTHEX pTEXTSTRING, CBI_Port_255
ADDCHAR pTEXTSTRING, " "
ADDCHAR pTEXTSTRING, "("
ADDTEXTDECIMAL pTEXTSTRING, CBI_Port_255
ADDCHAR pTEXTSTRING, ")"
invoke Cmd_AddHistoryBox, addr textstring
; ============================
case$ "tapeinvert"
xor EarXor, 64
movzx ebx, EarXor
mov byte ptr textstring, 0
invoke szMultiCat, 2, addr textstring, SADD ("Ear XOR: "), str$ (ebx)
invoke Cmd_AddHistoryBox, addr textstring
; ============================
case$ "set"
invoke Cmd_Fetch_String
jz CmdParser_Error
invoke szLower, addr cmd_arg_1
switch$ addr cmd_arg_1
case$ "tstates"
invoke Cmd_Fetch_Numeric_Val ; cmd_arg_2 = tstate value
jz CmdParser_Error
; mov eax, dword ptr cmd_arg_2
.while eax >= MACHINE.FrameCycles
sub eax, MACHINE.FrameCycles
.endw
mov totaltstates, eax
case$ "intlen"
invoke Cmd_Fetch_Numeric_Val ; cmd_arg_2 = tstate value
jz CmdParser_Error
.while eax >= MACHINE.FrameCycles
sub eax, MACHINE.FrameCycles
.endw
mov MACHINE.InterruptCycles, eax
else$
jmp CmdParser_Error ; unknown command
endsw$
; ============================
case$ "master"
invoke Cmd_AddHistoryBox, addr cmd_parser_buffer ; this command is echoed to the output window
invoke Cmd_Fetch_String ; fetch Program name into cmd_arg_1
jz CmdParser_Error
invoke Cmd_Fetch_Numeric_Val ; cmd_arg_2 = 48 or 128
jz CmdParser_Error
invoke Cmd_Fetch_String ; do we have cmd_arg_3 ?
.if ZERO?
; no filename given
invoke EnableDebugWindows, FALSE
invoke SaveFileName, Debugger_hWnd, SADD ("Master Tape"), addr szMasterTapFilter, addr mastertap_ofn, addr masterTapFilename, NULL, 0
push eax
invoke EnableDebugWindows, TRUE
pop eax
ifc eax eq 0 then jmp CmdParser_Error
.else
; a filename was given
strncpy addr cmd_arg_3, addr masterTapFilename, sizeof masterTapFilename
.endif
ADDEXTENSION offset masterTapFilename, offset TAPExt
invoke EnableDebugWindows, FALSE
invoke AskOverwriteFile, addr masterTapFilename, Debugger_hWnd, addr szWindowName
push eax
invoke EnableDebugWindows, TRUE
pop eax
ifc eax == FALSE then jmp CmdParser_Error
switch cmd_arg_2
case 48
mov is_128K, FALSE
case 128
mov is_128K, TRUE
.else
jmp CmdParser_Error
endsw
xor esi, esi ; zero = mastering allowed
movzx eax, z80registers._sp
ifc eax eq 0 then mov eax, 65536
.if eax < 24064
mov esi, CTXT ("SP must be !>= 24064 (#5E00).")
.endif
movzx eax, zPC
movzx ecx, z80registers._sp
ifc ecx eq 0 then mov ecx, 65536
mov edx, ecx
sub edx, 256
.if (eax >= edx) && (eax < ecx) ; PC cannot be between (SP-256) and SP
mov esi, CTXT ("Working stack space will overwrite Program Counter.")
.endif
.if esi == 0
invoke EnableDebugWindows, FALSE
invoke ShowMessageBox, Debugger_hWnd, SADD ("Do you want anti-merge for this tape?"), addr szWindowName, MB_YESNO or MB_ICONQUESTION or MB_DEFBUTTON2
ifc eax eq IDYES then mov antimerge_specified, TRUE else mov antimerge_specified, FALSE
invoke EnableDebugWindows, TRUE
invoke Cmd_AddHistoryBox, SADD ("Mastering tape image, please wait...")
invoke Master_Tape, addr cmd_arg_1, is_128K, addr masterTapFilename
invoke Cmd_AddHistoryBox, SADD ("Mastering finished.")
mov byte ptr textstring, 0
invoke szMultiCat, 5, addr textstring,
SADD ("Loading time: "),
str$ (loadtime_minutes), SADD ("m "),
str$ (loadtime_seconds), SADD ("s")
invoke Cmd_AddHistoryBox, addr textstring
.else
invoke Cmd_AddHistoryBox, esi
invoke Cmd_AddHistoryBox, SADD ("Mastering aborted.")
.endif
; ============================
case$ "ay"
dsText ayreg_txt, "AY register: "
dsText ayopbr_txt, " ("
dsText ayclbr_txt, " )"
movzx ebx, SCSelectReg
mov byte ptr textstring, 0
invoke szMultiCat, 2, addr textstring, SADD ("AY selected register: "), str$ (ebx)
invoke Cmd_AddHistoryBox, addr textstring
ForLp ebx, 0, 15
mov byte ptr textstring, 0
movzx edi, byte ptr [SCRegister0+ebx]
switch ebx
case 7
push edi
mov ecx, edi ; ecx = AY reg value
lea edi, buffer1
mov eax, "x x "
stosd
shl cl, 2
SETLOOP 6
shl cl, 1
mov ah, "0"
adc ah, 0
stosw
ENDLOOP
xor al, al
stosb ; terminate string
pop edi
invoke szMultiCat, 7, addr textstring, addr ayreg_txt, str$ (ebx), SADD (": "), str$ (edi), addr ayopbr_txt, addr buffer1, addr ayclbr_txt
.else
invoke szMultiCat, 4, addr textstring, addr ayreg_txt, str$ (ebx), SADD (": "), str$ (edi)
endsw
invoke Cmd_AddHistoryBox, addr textstring
Next ebx
; ============================
case$ "keyb"
invoke Cmd_AddHistoryBox, SADD ("F7FE: 1 2 3 4 5")
invoke Cmd_AddHistoryBox, SADD ("EFFE: 6 7 8 9 0")
invoke Cmd_AddHistoryBox, SADD ("FBFE: Q W E R T")
invoke Cmd_AddHistoryBox, SADD ("DFFE: Y U I O P")
invoke Cmd_AddHistoryBox, SADD ("FDFE: A S D F G")
invoke Cmd_AddHistoryBox, SADD ("BFFE: H J K L Enter")
invoke Cmd_AddHistoryBox, SADD ("FEFE: Caps Z X C V")
invoke Cmd_AddHistoryBox, SADD ("7FFE: B N M Sym Space")
; ============================
case$ "scpp"
mov ebx, $fnc (speccpp_myfunc, currentMachine.bank5)
invoke Cmd_AddHistoryBox, str$ (ebx)
RENDERFRAME
; ============================
case$ "mag"
; cache: C:\Users\woody\AppData\Roaming\ZXiSeek
mov byte ptr tempfilepath, 0
invoke szMultiCat, 2, addr tempfilepath, offset appPath, SADD ("ZXiSeek\ZXiSeek.exe")
memclr addr StartupInfo, sizeof StartupInfo
mov StartupInfo.cb, sizeof STARTUPINFO
mov StartupInfo.wShowWindow, SW_SHOWDEFAULT
.if $fnc (CreateProcess, NULL, addr tempfilepath, NULL, NULL, FALSE, DETACHED_PROCESS, NULL, NULL, addr StartupInfo, addr ProcessInfo) != 0
; wait for ZXiSeek to finish
; invoke WaitForSingleObject, ProcessInfo.hProcess, INFINITE
; close handles to the child process and its primary thread
invoke CloseHandle, ProcessInfo.hProcess
invoke CloseHandle, ProcessInfo.hThread
invoke PostMessage, Debugger_hWnd, WM_CLOSE, 0, 0 ; close debugger after opening magazine viewer
.else
invoke ShowMessageBox, hWnd, SADD ("CreateProcess failed"), addr szWindowName, MB_OK or MB_ICONINFORMATION
.endif
; ============================
case$ "mod"
SETLOOP 1000000
mov temp1, $fnc (nrandom, 10000000)
mov temp2, $fnc (nrandom, 10000000)
inc temp2 ; ensure non-zero (div by zero error)
mov temp1, @EVAL (temp1 ~ temp2)
mov temp2, $fnc (Mod2Int, temp1, temp2)
mov eax, temp1
.if eax != temp2
invoke Cmd_AddHistoryBox, hex$ (temp1)
invoke Cmd_AddHistoryBox, hex$ (temp2)
.endif
ENDLOOP
invoke Cmd_AddHistoryBox, str$ (@EVAL (65540 ~ 65536))
invoke Cmd_AddHistoryBox, str$ (@EVAL (15 ~ 9))
invoke Cmd_AddHistoryBox, str$ (@EVAL (15 ~ 2048))
invoke Cmd_AddHistoryBox, str$ (@EVAL (2100 ~ 2048))
mov eax, 5
ABS eax
invoke Cmd_AddHistoryBox, str$ (eax)
mov eax, -5
ABS eax
invoke Cmd_AddHistoryBox, str$ (eax)
xor eax, eax
ABS eax
invoke Cmd_AddHistoryBox, str$ (eax)
mov eax, -1
ABS eax
invoke Cmd_AddHistoryBox, str$ (eax)
mov eax, 1
ABS eax
invoke Cmd_AddHistoryBox, str$ (eax)
invoke Cmd_AddHistoryBox, SADD ("Done!")
; ============================
case$ "stop"
; move to first char after "stop" command
lea esi, cmd_parser_buffer-1
mov eax, "pots"
@@: inc esi
cmp eax, [esi]
jne @B
add esi, 4
@@: lodsb
cmp al, " "
je @B
cmp al, 9
je @B
dec esi
or al, al
je CmdParser_Error
IFDEF DEBUGBUILD
ADDMESSAGE_DBG "Writing Stop command to:"
ADDMESSAGE_DBG "C:\ProgramData\specemustopcmd.txt"
mov eax, len (esi)
.if $fnc (WriteMemoryToFile, SADD ("C:\ProgramData\specemustopcmd.txt"), esi, len (esi)) == 0
ADDMESSAGE_DBG "Error writing Stop command file"
.endif
ENDIF
.if $fnc (CompileBreakpointCode, esi)
; invoke Cmd_AddHistoryBox, addr cmd_parser_buffer
invoke Set_RunTo_Condition, RUN_TO_USER_CONDITION
invoke PostMessage, Debugger_hWnd, WM_CLOSE, 0, 0 ; close debugger for run-to execution
.else
ADDMESSAGE_DBG "Stop Command Error"
jmp CmdParser_Error
.endif
; ============================
.data
dump_banks_0_7 db 0, 1, 2, 3, 4, 5, 6, 7, -1
dump_banks_5_2_0 db 5, 2, 0, -1
dump_banks_5 db 5, -1
.code
case$ "dump"
invoke Cmd_Fetch_String ; fetch path/filename into cmd_arg_1
jz CmdParser_Error
switch HardwareMode
case HW_16
lea esi, dump_banks_5
mov eax, True
case HW_48, HW_TC2048, HW_TK90X
lea esi, dump_banks_5_2_0
mov eax, True
case HW_128, HW_PLUS2, HW_PLUS2A, HW_PLUS3, HW_PENTAGON128
lea esi, dump_banks_0_7
mov eax, True
.else
mov eax, False
endsw
.if eax == True
.while byte ptr [esi] != -1
movzx ebx, byte ptr [esi]
invoke Calc_CRC16_Data, [currentMachine.bank_ptrs+ebx*4], 16384
mov di, ax
invoke INITTEXTSTRING, addr textstring, addr pTEXTSTRING
ADDTEXTSTRING pTEXTSTRING, addr cmd_arg_1
ADDDIRECTTEXTSTRING pTEXTSTRING, ".bank"
ADDTEXTDECIMAL pTEXTSTRING, ebx
ADDCHAR pTEXTSTRING, "."
ADDTEXTHEX pTEXTSTRING, di
invoke WriteMemoryToFile, addr textstring, [currentMachine.bank_ptrs+ebx*4], 16384
inc esi
.endw
.endif
; ============================
case$ "snowfloat"
xor snow_float, TRUE
.if !ZERO?
invoke Cmd_AddHistoryBox, SADD ("Snow float: Enabled")
.else
invoke Cmd_AddHistoryBox, SADD ("Snow float: Disabled")
.endif
; ============================
IFDEF DEBUGBUILD
case$ "test"
.data?
lptestmem DWORD ?
testlen DWORD ?
.code
mov lptestmem, AllocMem (65536+65536)
.if lptestmem == 0
invoke Cmd_AddHistoryBox, SADD ("Out of memory.")
.else
; memcpy addr Bank5, lptestmem, 49152
mov testcount1, $fnc (zx7_compress, currentMachine.bank2, 32768, lptestmem)
invoke Cmd_AddHistoryBox, str$ (testcount1)
mov esi, lptestmem
add esi, 65536
mov testcount2, $fnc (Encode, lptestmem, testcount1, esi)
invoke Cmd_AddHistoryBox, str$ (testcount2)
mov testcount2, $fnc (Encode, currentMachine.bank2, 32768, esi)
invoke WriteMemoryToFile, SADD ("E:\zEncoded.bin"), esi, testcount2
; mov testcount1, $fnc (CountZeroBits, lptestmem, testlen)
; invoke INITTEXTSTRING, addr textstring, addr pTEXTSTRING
; ADDDIRECTTEXTSTRING pTEXTSTRING, "No filter 0-bit count: "
; ADDTEXTDECIMAL pTEXTSTRING, testcount1
; invoke Cmd_AddHistoryBox, addr textstring
FreeMem lptestmem
.endif
ENDIF
; ============================
case$ "asm"
ifc have_pasmo eq 0 then jmp CmdParser_Error
.if $fnc (CreateTempFilename, addr asmsourcefile, SADD ("asmsrcline"), SADD ("asm")) == FALSE
invoke ShowMessageBox, hWnd, SADD ("CreateTempFilename failed"), addr szWindowName, MB_OK or MB_ICONINFORMATION
jmp @@asmcmdexit
.endif
;ADDMESSAGEPTR_DBG addr asmsourcefile ; adds asm source path/name message
; generate an initial ORG directive source line so relative jumps work
movzx ebx, Z80PC
mov assemblersourcecode, 0
invoke szMultiCat, 3, addr assemblersourcecode, CTXT (" org "), str$ (ebx), addr chars_newline
; move to first char after "asm" command
lea esi, cmd_parser_buffer-1
mov al, "m"
@@: inc esi
cmp al, [esi]
jne @B
inc esi
@@: lodsb
cmp al, " "
je @B
cmp al, 9
je @B
dec esi
or al, al
je CmdParser_Error
mov lpUserAsmSrc, esi ; ptr to asm source line in "asm" command
; now write the user's source line to our file for assembling
invoke szMultiCat, 3, addr assemblersourcecode, addr char_space, esi, addr chars_newline
;invoke WriteMemoryToFile, SADD ("E:\zzz.txt"), addr assemblersourcecode, len (addr assemblersourcecode) ; when we want to see generated source
.if $fnc (WriteMemoryToFile, addr asmsourcefile, addr assemblersourcecode, len (addr assemblersourcecode)) == 0
ADDMESSAGE_DBG "Error writing assembler source file"
jmp @@asmcmdexit
.endif
hPasmoStdOut equ <temp1>
invoke GetCurrentDirectory, sizeof tempcurdir, addr tempcurdir ; preserve current currdir
invoke ExtractFilePath, addr asmsourcefile, addr asmsourcefilePath
invoke ExtractFileName, addr asmsourcefile, addr asmsourcefileName
strncpy addr asmsourcefileName, addr asmsourcefileBin, sizeof asmsourcefileBin
strncpy addr asmsourcefileName, addr asmsourcefileSymbol, sizeof asmsourcefileSymbol
strncpy addr asmsourcefileName, addr asmsourcefileErr, sizeof asmsourcefileErr
invoke @@AddExtension, addr asmsourcefileBin, CTXT ("bin")
invoke @@AddExtension, addr asmsourcefileSymbol, CTXT ("symbol")
invoke @@AddExtension, addr asmsourcefileErr, CTXT ("err")
.if $fnc (SetCurrentDirectory, addr asmsourcefilePath) == 0
invoke ShowMessageBox, hWnd, SADD ("SetCurrentDirectory failed"), addr szWindowName, MB_OK or MB_ICONINFORMATION
jmp @@asmcmdexit
.endif
mov byte ptr tempfilepath, 0
invoke szMultiCat, 3, addr tempfilepath, addr char_quote, offset appPath, SADD ("pasmo.exe", 34, " --alocal --err --name code ")
invoke szMultiCat, 3, addr tempfilepath, addr char_quote, addr asmsourcefileName, addr char_quote_space ; "<srcfile>.asm" + " "
invoke szMultiCat, 3, addr tempfilepath, addr char_quote, addr asmsourcefileBin, addr char_quote_space ; "<srcfile>.bin" + " "
invoke szMultiCat, 3, addr tempfilepath, addr char_quote, addr asmsourcefileSymbol, addr char_quote ; "<srcfile>.symbol"
ifdef DEBUGBUILD
;invoke Cmd_AddHistoryBox, addr tempfilepath
endif
;mov DummyMem, 0
;invoke szMultiCat, 2, addr DummyMem, CTXT ("Assembling: "), addr asmsourcefileName
;invoke Cmd_AddHistoryBox, addr DummyMem
memclr addr sa, sizeof sa
mov sa.nLength, sizeof sa
mov sa.bInheritHandle, TRUE
mov hPasmoStdOut, $fnc (CreateFile, addr asmsourcefileErr, FILE_ALL_ACCESS, FILE_SHARE_READ, addr sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)
.if hPasmoStdOut != INVALID_HANDLE_VALUE
memclr addr ProcessInfo, sizeof ProcessInfo
memclr addr StartupInfo, sizeof StartupInfo
mov StartupInfo.cb, sizeof STARTUPINFO
mov StartupInfo.dwFlags, STARTF_USESTDHANDLES
mov StartupInfo.hStdInput, $fnc (GetStdHandle, STD_INPUT_HANDLE)
m2m StartupInfo.hStdOutput, hPasmoStdOut
mov StartupInfo.hStdError, $fnc (GetStdHandle, STD_ERROR_HANDLE)
.if $fnc (CreateProcess, NULL, addr tempfilepath, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS or CREATE_NO_WINDOW, NULL, NULL, addr StartupInfo, addr ProcessInfo) != 0
; wait for Pasmo to finish
invoke WaitForSingleObject, ProcessInfo.hProcess, INFINITE
; close handles to the child process and its primary thread
invoke CloseHandle, ProcessInfo.hProcess
invoke CloseHandle, ProcessInfo.hThread
.else
invoke ShowMessageBox, hWnd, SADD ("CreateProcess failed"), addr szWindowName, MB_OK or MB_ICONINFORMATION
.endif
invoke CloseHandle, hPasmoStdOut
hStdOutFileMem equ <temp2>
hStdOutFileLen equ <temp3>
.if $fnc (ReadFileToMemory, addr asmsourcefileErr, addr hStdOutFileMem, addr hStdOutFileLen) != 0
.if hStdOutFileLen > 0
; we have assembly errors
textlineptr equ temp4
; output the user source line with error
invoke Cmd_AddHistoryBox, lpUserAsmSrc
m2m textlineptr, hStdOutFileMem
.while TRUE
.if $fnc (ReadTextLine, addr textlineptr, addr DummyMem) != 0
; don't output error lines referencing our temp source file (error in line x of file:"name")
.if $fnc (InString, 1, addr DummyMem, SADD ("asmsrcline")) == 0
invoke Cmd_AddHistoryBox, addr DummyMem
.endif
.else
.break
.endif
.endw
.else
; assembled without errors
invoke Cmd_AddHistoryBox, CTXT ("Assembled: No Errors")
asmBinMem equ <temp4>
asmBinLen equ <temp5>
.if $fnc (ReadFileToMemory, addr asmsourcefileBin, addr asmBinMem, addr asmBinLen) != 0
mov esi, asmBinMem
mov bx, Z80PC
.while asmBinLen > 0
invoke WriteZ80Byte, bx, byte ptr [esi]
inc bx
inc esi
dec asmBinLen
.endw
invoke GlobalFree, asmBinMem
invoke UpdateDisassembly
.else
invoke ShowMessageBox, hWnd, SADD ("Error reading assembled binary file"), addr szWindowName, MB_OK or MB_ICONINFORMATION
.endif
.endif
invoke GlobalFree, hStdOutFileMem
invoke DeleteFile, addr asmsourcefileErr
invoke DeleteFile, addr asmsourcefileName
invoke DeleteFile, addr asmsourcefileSymbol
invoke DeleteFile, addr asmsourcefileBin
.endif
.else
invoke ShowMessageBox, hWnd, SADD ("CreateFile failed"), addr szWindowName, MB_OK or MB_ICONINFORMATION
.endif
invoke SetCurrentDirectory, addr tempcurdir ; restore current currdir on exit
@@asmcmdexit:
; ============================
case$ "asmcontend"
passes = 3
pass = 1
repeat passes
z80_assembler offset DummyMem
im2table equ 0be00h
z80 org 32768
z80 di
z80 ld (oldsp+1),sp
z80 fillmem im2table,257,0bfh
z80 ld sp,0be00h
z80 ld hl,0E9FDh ; jp (iy)
z80 ld (0bfbfh),hl
z80 call 3435
z80 opencrt 2
z80 for w, 0, 7
z80 ld a,(w)
z80 call page_ram
z80 call swap_bank_code
z80 ld hl,0c000h
z80 ld d,h
z80 ld e,l
; z80 breakpoint
z80 ld a,high im2table
z80 ld bc,0
z80 ei
z80 halt
z80 ld i,a
z80 im 2
z80 ld iy,im2_pre
z80 halt
z80 ld iy,im2_main
z80 call -bank_code_sizeof
z80 call set_im1
z80 call swap_bank_code
z80 xor a
z80 call page_ram
z80 crt "RAM "
z80 ld a,(w)
z80 crt a, ": ", bc, " loops - "
z80 ld h,b
z80 ld l,c
z80 ld de,1655
z80 or a
z80 sbc hl,de
z80 jr c,@F
z80 crt "un"
z80 @@: crt "contended"
z80 crt 13
z80 next w
z80 oldsp: ld sp,0