-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbg.c
1681 lines (1540 loc) · 48.2 KB
/
dbg.c
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
/* :ts=4 dbg.c
*
* cp4 - Commodore C+4 emulator
* Copyright (C) 1998 Gáti Gergely
*
* This program 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.
*
* This program 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 this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* e-mail: [email protected]
*/
#include <exec/types.h>
#include <proto/asl.h>
#include <stdio.h>
#include "common.h"
#include "prefs.h"
#include "cp4_loc.h"
/*
* from preferencesgui.c
*/
extern prefsgui(void);
#ifdef __GCC__
extern const char *_ctype_;
#define _L 0x02
#define mislower(c) ((_ctype_ + 1)[c] & _L)
#else
#include <ctype.h>
#define mislower(c) (islower(c))
#endif
char mtoupper(char c) {
char rt;
rt=(mislower(c) ? c-'a'+'A' : c);
return(rt);
}
/*
* változók a ted-bõl
*/
extern void reset(void);
extern int doframe(void);
extern u_byte userblank;
extern struct Screen *cp4Scr;
extern struct Window *cp4Window;
extern struct FileRequester *frq;
extern char *makefilename(struct FileRequester *f);
extern unsigned char *chunky;
/*
* változók a cp4-bõl
*/
extern int opt_direct; // 1-direct mode
extern char *opt_p4dir; // default dir
extern int opt_withdata;
extern char *linedisasm(u_word adr,u_word *next,int *operand,int mode);
extern u_word wheretogo(u_word adr,int flag); // flag==0-trace, 1-step
extern int disgetlen(int pc,int mode);
extern u_byte *p4ram;
extern u_byte *p4rom;
extern u_byte *hiram;
extern u_byte r_a;
extern u_byte r_x;
extern u_byte r_y;
extern u_byte r_sp;
extern u_word r_pc;
extern u_byte r_p;
#define flag_n 128 // negative
#define flag_v 64 // overflow
#define flag__ 32 // nem használt (1)
#define flag_b 16 // break
#define flag_d 8 // decimal
#define flag_i 4 // interrupt
#define flag_z 2 // zero
#define flag_c 1 // carry
/*
* valódi globálisok
*/
int DefDisMode=0; // 0-normal, 1-illegal disasm
int DefMonTop=-1,DefMonLeft=112;
int DefDbgTop=-1,DefDbgLeft=86;
char DefMonSea[128];
int DefMonCyc=0; // 0-ascii !0-scrcode
int DefMonitor=0; // 0-closed, !0-opened
int DefMonStart=0; // ~*8 == cím a topon
int DefStayFront=0; // lapozza vissza a cp4-et? (igen)
int DefFollow=0; // default: off
int DefBrkEnable=0; // 0-nem
int DefStkLeft=66,DefStkTop=-1;
// ezekbe ír a 7501.asm
u_byte dbgmodeflag;
unsigned long dbgamiras;
u_word dbgrasreq;
u_word dbgvideo;
u_word dbggfxbase;
u_byte dbgeirq;
u_word dbgp4ras;
/*
* közös a debug.c-vel
*/
static int dbginput=0;
static char catab[]=\
"................................ !\"#$%&'()*+,-./0123456789:;<=>?" \
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[£]^_@abcdefghijklmnopqrstuvwxyz....." \
"................................................................" \
"................................................................";
static char cstab[]=\
"@abcdefghijklmnopqrstuvwxyz[£]^_ !\"#$%&'()*+,-./0123456789:;<=>?" \
"@ABCDEFGHIJKLMNOPQRSTUVWXYZ..... ..............................." \
"................................................................" \
"................................................................";
static char *ctab=catab;
// common funcs
static void setcheckmark(int menunum,int itemnum,int state);
static int getcheckmark(int menunum,int itemnum);
#include "debug.c"
#include "modetxt.c"
// bitek
#define B0 1
#define B1 2
#define B2 4
#define B3 8
#define B4 16
#define B5 32
#define B6 64
#define B7 128
int exitcode=0;
#define EXIT_STAY 0
#define EXIT_BACK 1
#define EXIT_QUIT 2
#define EXIT_STEP 3
#define EXIT_TRACE 4
#define EXIT_RUN 5
#define EXIT_RESET 6
// 21,21 -> text base koord
static int ret=0;
static int DefDbgStart=0;
static int DefDbgEnd=0;
static int DbgSizes[28];
static int textbasex=20+DX;
static int textbasey=21+DY;
static int dbgactive=0;
static int dragdebug=0; // 1==dragging mouse on listview
static int debugscroll=0;
#define MYFRONTPEN drawinfo->dri_Pens[TEXTPEN]
#define MYBACKPEN drawinfo->dri_Pens[BACKGROUNDPEN]
#define MYSELECTEDPEN drawinfo->dri_Pens[FILLPEN]
static struct IntuiText dbtxt[28];
static struct TextAttr myTextAttr;
static int monbasex=9;
static int monbasey=29;
static struct IntuiText montxt[27];
static struct IntuiText monactive; // egy kétkarakteres stringre mutat, ami aktív
static char monactivetxt[]=" ";
static int monactline=0, monactcol=0; // line(0-26) col(0-7)
static int moninput=0;
static int dragmonitor=0; // 1==dragging mouse on listview
static monitorscroll=0; // épp scrolloz?
static char hexkeys[]="0123456789abcdef";
#define BACKSEE 60
static int adrs[BACKSEE]; // ebbe jönnek a címek (debug win)
static char wintitle[32];
#define BREAKPOINT (0x02) // breakpoint opcode
#define INTERNAL 0 // saját breakpoint number
static int brkstore[]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; // itt tároljuk az eredetit (-1 invalid)
static u_byte *brkaddr[12];
static int brkreq[]={-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}; // user req brkpnts
static char *brkcyc[]={
"1: ",
"2: ",
"3: ",
"4: ",
"5: ",
"6: ",
"7: ",
"8: ",
"9: ",
NULL
};
static char *montxts[]={
" a | ",
" b | ",
" c | ",
" d | ",
" e | ",
" f | ",
" g | ",
" h | ",
" i | ",
" j | ",
" k | ",
" l | ",
" m | ",
" n | ",
" o | ",
" p | ",
" q | ",
" r | ",
" s | ",
" t | ",
" u | ",
" v | ",
" w | ",
" x | ",
" y | ",
" z | ",
" 0 | ",
NULL
};
static char *txts[]={
"a ",
"b ",
"c ",
"d ",
"e ",
"f ",
"g ",
"h ",
"j ",
"k ",
"l ",
"m ",
"n ",
"o ",
"p ",
"q ",
"r ",
"s ",
"t ",
"u ",
"v ",
"w ",
"x ",
"y ",
"z ",
"0 ",
"1 ",
"2 ",
NULL
};
int dodebug_out(int flag); // MAIN func
static void setcheckmark(int menunum,int itemnum,int state) {
struct MenuItem *n;
if(NULL==(n=ItemAddress(dbgwinMenus,FULLMENUNUM(menunum,itemnum,0)))) return;
ClearMenuStrip(dbgwinWnd);
if(monitormenu!=0) ClearMenuStrip(monwinWnd);
if(state==TRUE) n->Flags|=CHECKED;
else n->Flags&=~CHECKED;
ResetMenuStrip(dbgwinWnd,dbgwinMenus);
if(monitormenu!=0) ResetMenuStrip(monwinWnd,dbgwinMenus);
} // setcheckmark
static int getcheckmark(int menunum,int itemnum) {
struct MenuItem *n;
if(NULL==(n=ItemAddress(dbgwinMenus,FULLMENUNUM(menunum,itemnum,0)))) return(-1);
if((n->Flags&CHECKED)!=0) return(TRUE);
return(FALSE);
} // getcheckmark
/*
static void disableitem(int menunum,int itemnum,int state) {
if(state==TRUE) OffMenu(dbgwinWnd,FULLMENUNUM(menunum,itemnum,0));
else OnMenu(dbgwinWnd,FULLMENUNUM(menunum,itemnum,0));
} // setcheckmark
*/
static u_byte memread(u_word addr) { // general read
if(addr<0x8000) return(p4ram[addr]);
return(hiram[addr]);
} // memread
static void memwrite(u_word addr,u_byte data) {
if(addr<0x8000) p4ram[addr]=data;
else hiram[addr]=data;
} // memwrite
static u_byte *memaddr(u_word addr) {
if(addr<0x8000) return(&p4ram[addr]);
return(&hiram[addr]);
} // memaddr
static void mystrcpy(char *to,char *from) {
while(*from!='\0') *to++=*from++;
}
// törli a breakpointokat
static void clearbrk(void) {
int i;
for(i=0;i<12;i++) {
if(brkstore[i]!=-1) {
*brkaddr[i]=(u_byte)brkstore[i];
brkstore[i]=-1;
}
}
} // clearbrk
// törli a breakpoint requesteket
static void clearbrkreq(void) {
static char spc[]=" ";
int i;
for(i=0;i<12;i++) brkreq[i]=-1;
for(i=0;i<9;i++) {
mystrcpy(&brkcyc[i][3],spc);
}
GT_SetGadgetAttrs(dbgwinGadgets[GD_dbrkpntcyc],dbgwinWnd,NULL,GTCY_Labels,(ULONG)&brkcyc,TAG_DONE);
} // clearbrkreq
static void updatedbg(void) {
if(dbgwinWnd) {
dbtxt[dbgactive].BackPen=MYSELECTEDPEN;
PrintIText(dbgwinWnd->RPort,dbtxt,textbasex+sx,textbasey+sy);
dbtxt[dbgactive].BackPen=MYBACKPEN;
}
}
static void updatemon(void) {
char *act;
if(monwinWnd) {
PrintIText(monwinWnd->RPort,montxt,monbasex+sx-2,monbasey+sy-2);
if(monactline>=0) {
act=(montxts[monactline])+(monactcol*3)+7;
monactivetxt[0]=*act++;
monactivetxt[1]=*act;
monactive.LeftEdge=(7*8)+(3*8*monactcol);
monactive.TopEdge=8*monactline;
PrintIText(monwinWnd->RPort,&monactive,monbasex+sx-2,monbasey+sy-2);
}
}
}
static void calcmon(void) {
static char s[8];
int st=DefMonStart*8;
int i,j;
char *a,*l;
unsigned char d;
for(i=0;i<27;i++) {
l=montxts[i]+1;
sprintf(s,"%04X",st);
mystrcpy(l,s);
a=l+6+26;
l+=6;
for(j=0;j<8;j++,l+=3,a++) {
d=p4ram[st++];
sprintf(s,"%02X",d);
mystrcpy(l,s);
*a=ctab[d];
}
}
GT_SetGadgetAttrs(monwinGadgets[GD_monscroll],monwinWnd,NULL,GTSC_Top,DefMonStart,TAG_DONE,0L);
updatemon();
} // calcmon
/*
* kiszámítja a cuccokat a veremablakba
*/
static int calcstk(int flag) {
static struct Node nd[256];
static char item[256][12];
static u_word ad[256];
static int firstrun=0;
int i,sp=r_sp+0x100,adr,dat;
if(!stkwinWnd) return(0);
if(flag!=0) return(ad[flag-1]);
GT_SetGadgetAttrs(stkwinGadgets[GD_swinlst],stkwinWnd,NULL,GTLV_Labels,~0,TAG_DONE);
if(firstrun==0) {
firstrun=1;
for(i=0;i<256;i++) {
nd[i].ln_Name=item[i];
}
}
swinlst0List.lh_Head=&nd[0];
for(i=0;sp<0x200;i++,sp++) {
dat=memread(sp+1);
adr=((memread(sp+2)<<8)+dat)-2;
if(memread(adr)!=0x20) {
// data
sprintf(item[i]," $%02X DATA",dat);
ad[i]=0;
} else {
// jsr
sp++;
sprintf(item[i],"$%04X JSR",adr);
ad[i]=(u_word)adr;
}
if(i>0) {
nd[i].ln_Pred=&nd[i-1];
nd[i-1].ln_Succ=&nd[i];
nd[i].ln_Succ=(struct Node *)&swinlst0List.lh_Tail;
swinlst0List.lh_TailPred=&nd[i];
} else {
nd[0].ln_Pred=(struct Node *)&swinlst0List.lh_Head;
}
}
GT_SetGadgetAttrs(stkwinGadgets[GD_swinlst],stkwinWnd,NULL,GTLV_Labels,(ULONG)&swinlst0List,TAG_DONE);
return(0);
} // calcstk
static void calcdbg(int flag) {
static char spc[]=" ";
static char a[8];
u_word adr=DefDbgStart,next=0;
int operand,i,sum=0,vanpc=0;
char *line,*l;
for(i=0;i<28;i++) {
adrs[i]=adr;
l=txts[i];
mystrcpy(l,spc);
line=linedisasm(adr,&next,&operand,DefDisMode);
if(adr==r_pc) {
if(flag!=0) dbgactive=i;
*l='>';
vanpc=1;
} else if(adr>r_pc&&vanpc==0) {
vanpc=1;
if(i>0) txts[i-1][0]='-';
if(flag!=0) dbgactive=i-1;
}
l++;
sum+=(next-adr);
DbgSizes[i]=sum;
sprintf(a,"%04X",adr);
mystrcpy(l,a);
l+=5;
mystrcpy(l,line);
adr=next;
}
DefDbgEnd=next;
GT_SetGadgetAttrs(dbgwinGadgets[GD_dbgscroll],dbgwinWnd,NULL,GTSC_Top,DefDbgStart>>2,TAG_DONE,0L);
updatedbg();
}
/*
* a follow-hoz beállítja a monitort egy pozícióba
*/
static void setmon(int adr) {
if(adr<0) return;
DefMonStart=(adr/8)-10;
if(DefMonStart<0) {
monactline=DefMonStart+10;
DefMonStart=0;
} else monactline=10;
monactcol=adr%8;
}
/*
* beállítja a checkmarkokat a menüben
*/
static void setmenu(void) {
return;
}
static void initregs(void) {
static int mask[]={128,64,32,16,8,4,2,1};
static char s[20];
char *t;
int i;
sprintf(s,"%02X",r_a);
GT_SetGadgetAttrs(dbgwinGadgets[GD_daccu],dbgwinWnd,NULL,GTST_String,(ULONG)s,TAG_DONE,0L);
sprintf(s,"%02X",r_x);
GT_SetGadgetAttrs(dbgwinGadgets[GD_dxreg],dbgwinWnd,NULL,GTST_String,(ULONG)s,TAG_DONE,0L);
sprintf(s,"%02X",r_y);
GT_SetGadgetAttrs(dbgwinGadgets[GD_dyreg],dbgwinWnd,NULL,GTST_String,(ULONG)s,TAG_DONE,0L);
sprintf(s,"%02X",r_sp);
GT_SetGadgetAttrs(dbgwinGadgets[GD_dsp],dbgwinWnd,NULL,GTST_String,(ULONG)s,TAG_DONE,0L);
sprintf(s,"%04X",r_pc);
GT_SetGadgetAttrs(dbgwinGadgets[GD_dpc],dbgwinWnd,NULL,GTST_String,(ULONG)s,TAG_DONE,0L);
s[0]=' ';
t=&s[1];
for(i=0;i<8;i++) {
if(i!=2) {
if((mask[i]&r_p)==0) *t++='-';
else *t++='1';
*t++=' ';
}
}
*t='\0';
GT_SetGadgetAttrs(dbgwinGadgets[GD_bflags],dbgwinWnd,NULL,GTTX_Text,(ULONG)s,TAG_DONE,0L);
}
/*
* intui events
*/
static int monwinMouseMove(struct IntuiMessage *imsg) {
int newline,newcol;
int scroll;
long top;
if(dragmonitor!=0) {
newline=((imsg->MouseY-13)/8)-2;
newcol=((imsg->MouseX-(7*8)-4)/24);
if(newcol<0) newcol=0;
else if(newcol>7) newcol=7;
if(newline<0) {
scroll=(-newline);
top=DefMonStart-scroll;
if(top<0) top=0;
if(DefMonStart!=top) {
DefMonStart=top;
calcmon();
}
newline=0;
} else if(newline>26) {
scroll=newline-26;
top=DefMonStart+scroll;
if(top>(8192-27)) top=8192-27;
if(DefMonStart!=top) {
DefMonStart=top;
calcmon();
}
newline=26;
}
if(newline!=monactline||newcol!=monactcol) {
monactline=newline;
monactcol=newcol;
updatemon();
}
} else if(monitorscroll!=0) {
GT_GetGadgetAttrs(monwinGadgets[GD_monscroll],monwinWnd,NULL,GTSC_Top,(ULONG)&top,TAG_DONE,0L);
if(DefMonStart!=top) {
DefMonStart=top;
calcmon();
}
}
return(0);
}
static int dbgwinMouseMove(struct IntuiMessage *imsg) {
int newactive,scroll;
long top;
if(dragdebug!=0) {
newactive=(((imsg->MouseY-DY)-13)/8)-1;
if(newactive<0) {
scroll=(-newactive);
DefDbgStart-=scroll;
if(DefDbgStart<0) DefDbgStart=0;
calcdbg(0);
newactive=0;
} else if(newactive>27) {
scroll=(newactive-27);
DefDbgStart+=DbgSizes[scroll];
if(DefDbgStart>DBGREALMAX) DefDbgStart=DBGREALMAX;
calcdbg(0);
newactive=27;
}
if(newactive!=dbgactive) {
dbgactive=newactive;
updatedbg();
}
} else if(debugscroll!=0) {
GT_GetGadgetAttrs(dbgwinGadgets[GD_dbgscroll],dbgwinWnd,NULL,GTSC_Top,(ULONG)&top,TAG_DONE,0L);
top<<=2;
if(DefDbgStart!=top) {
DefDbgStart=top;
calcdbg(0);
}
}
return(0);
}
static int monwinMouseButton(struct IntuiMessage *imsg) {
moninput=0;
switch(imsg->Code) {
case SELECTDOWN :
if(imsg->MouseX>(7+(7*8))&&imsg->MouseY>28&&imsg->MouseX<252&&imsg->MouseY<245) {
monactline=((imsg->MouseY-13)/8)-2;
monactcol=((imsg->MouseX-(7*8)-4)/24);
updatemon();
dragmonitor=1;
}
break;
case SELECTUP:
if(dragmonitor!=0) dragmonitor=0;
break;
}
return(0);
}
static int dbgwinMouseButton(struct IntuiMessage *imsg) {
int mX,mY;
switch(imsg->Code) {
case SELECTDOWN :
mX=imsg->MouseX-DX;
mY=imsg->MouseY-DY;
if(mX>17&&mY>20&&mX<206&&mY<245) {
dbgactive=((mY-13)/8)-1;
updatedbg();
dragdebug=1;
}
break;
case SELECTUP:
if(dragdebug!=0) dragdebug=0;
break;
}
return(0);
}
static int dpcClicked(struct IntuiMessage *imsg) {
/* routine when gadget "PC" is clicked. */
char *s;
int newpc,v;
GT_GetGadgetAttrs(dbgwinGadgets[GD_dpc],dbgwinWnd,NULL,GTST_String,(ULONG)&s,TAG_DONE,0L);
sscanf(s,"%x",&v);
r_pc=v;
initregs();
newpc=r_pc-26;
if(DefDbgStart!=newpc) {
DefDbgStart=newpc;
calcdbg(1);
}
return(TRUE);
}
static int daccuClicked(struct IntuiMessage *imsg) {
/* routine when gadget "A" is clicked. */
char *s;
int v;
GT_GetGadgetAttrs(dbgwinGadgets[GD_daccu],dbgwinWnd,NULL,GTST_String,(ULONG)&s,TAG_DONE,0L);
sscanf(s,"%x",&v);
r_a=v;
initregs();
return(TRUE);
}
static int dxregClicked(struct IntuiMessage *imsg) {
/* routine when gadget "X" is clicked. */
char *s;
int v;
GT_GetGadgetAttrs(dbgwinGadgets[GD_dxreg],dbgwinWnd,NULL,GTST_String,(ULONG)&s,TAG_DONE,0L);
sscanf(s,"%x",&v);
r_x=v;
initregs();
return(TRUE);
}
static int dyregClicked(struct IntuiMessage *imsg) {
/* routine when gadget "Y" is clicked. */
char *s;
int v;
GT_GetGadgetAttrs(dbgwinGadgets[GD_dyreg],dbgwinWnd,NULL,GTST_String,(ULONG)&s,TAG_DONE,0L);
sscanf(s,"%x",&v);
r_y=v;
initregs();
return(TRUE);
}
static int dspClicked(struct IntuiMessage *imsg) {
/* routine when gadget "SP" is clicked. */
char *s;
int v;
GT_GetGadgetAttrs(dbgwinGadgets[GD_dsp],dbgwinWnd,NULL,GTST_String,(ULONG)&s,TAG_DONE,0L);
sscanf(s,"%x",&v);
r_sp=v;
initregs();
return(TRUE);
}
static int drunClicked(struct IntuiMessage *imsg) {
/* routine when gadget "_Run" is clicked. */
exitcode=EXIT_RUN;
return(FALSE);
}
static int dtraceClicked(struct IntuiMessage *imsg) {
/* routine when gadget "_Trace" is clicked. */
u_word adr;
exitcode=EXIT_TRACE;
adr=wheretogo(r_pc,0);
brkstore[INTERNAL]=memread(adr);
brkaddr[INTERNAL]=memaddr(adr);
memwrite(adr,BREAKPOINT);
return(FALSE);
}
static int dstepClicked(struct IntuiMessage *imsg) {
/* routine when gadget "_Step" is clicked. */
u_word adr;
exitcode=EXIT_STEP;
adr=wheretogo(r_pc,1);
brkstore[INTERNAL]=memread(adr);
brkaddr[INTERNAL]=memaddr(adr);
memwrite(adr,BREAKPOINT);
return(FALSE);
}
static int dbrkpntcycClicked(struct IntuiMessage *imsg) {
/* routine when gadget "" is clicked. */
return(TRUE);
}
static int donoffbrkpntClicked(struct IntuiMessage *imsg) {
/* routine when gadget "BreakPoints" is clicked. */
long checked;
GT_GetGadgetAttrs(dbgwinGadgets[GD_donoffbrkpnt],dbgwinWnd,NULL,GTCB_Checked,(ULONG)&checked,TAG_DONE);
if(checked==TRUE) {
setcheckmark(M_DEBUG,MD_BREAKPOINTS,TRUE);
DefBrkEnable=1;
} else {
setcheckmark(M_DEBUG,MD_BREAKPOINTS,FALSE);
DefBrkEnable=0;
}
return(TRUE);
}
static int dclearClicked(struct IntuiMessage *imsg) {
/* routine when gadget "Clear" is clicked. */
clearbrkreq();
GT_SetGadgetAttrs(dbgwinGadgets[GD_donoffbrkpnt],dbgwinWnd,NULL,GTCB_Checked,FALSE,TAG_DONE);
return(TRUE);
}
static int baddClicked(struct IntuiMessage *imsg) {
/* routine when gadget "Add" is clicked. */
static char str[6];
long active;
GT_GetGadgetAttrs(dbgwinGadgets[GD_dbrkpntcyc],dbgwinWnd,NULL,GTCY_Active,(ULONG)&active,TAG_DONE);
brkreq[active+1]=adrs[dbgactive];
sprintf(str,"$%04X",adrs[dbgactive]);
mystrcpy(&brkcyc[active][3],str);
GT_SetGadgetAttrs(dbgwinGadgets[GD_dbrkpntcyc],dbgwinWnd,NULL,GTCY_Labels,(ULONG)&brkcyc,TAG_DONE);
GT_SetGadgetAttrs(dbgwinGadgets[GD_donoffbrkpnt],dbgwinWnd,NULL,GTCB_Checked,TRUE,TAG_DONE);
setcheckmark(M_DEBUG,MD_BREAKPOINTS,TRUE);
DefBrkEnable=1;
return(TRUE);
}
static int dbgscrollClicked(struct IntuiMessage *imsg) {
/* routine when gadget "" is clicked. */
DefDbgStart=imsg->Code<<2;
calcdbg(0);
if(imsg->Class==IDCMP_GADGETDOWN) {
ReportMouse(TRUE,dbgwinWnd);
debugscroll=1;
} else {
ReportMouse(FALSE,dbgwinWnd);
debugscroll=0;
}
return(TRUE);
}
static int moncycClicked(struct IntuiMessage *imsg) {
/* routine when gadget "" is clicked. */
ULONG act;
moninput=0;
GT_GetGadgetAttrs(monwinGadgets[GD_moncyc],monwinWnd,NULL,GTCY_Active,(ULONG)&act,TAG_DONE);
if(act==0) {
ctab=catab;
setcheckmark(M_MONITOR,MM_ASCII,TRUE);
setcheckmark(M_MONITOR,MM_SCRCODE,FALSE);
} else {
ctab=cstab;
setcheckmark(M_MONITOR,MM_ASCII,FALSE);
setcheckmark(M_MONITOR,MM_SCRCODE,TRUE);
}
calcmon();
return(TRUE);
}
static int monstrClicked(struct IntuiMessage *imsg) {
/* routine when gadget "" is clicked. */
char *str;
moninput=0;
GT_GetGadgetAttrs(monwinGadgets[GD_monstr],monwinWnd,NULL,GTST_String,(ULONG)&str,TAG_DONE);
strcpy(DefMonSea,str);
return(TRUE);
}
static int monseaClicked(struct IntuiMessage *imsg) {
/* routine when gadget "Search" is clicked. */
static int dat[128];
int h1;
char *str,c;
int adr,oadr,find=0,i,j,mx;
moninput=0;
GT_SetGadgetAttrs(monwinGadgets[GD_monsea],monwinWnd,NULL,GA_Disabled,TRUE,TAG_DONE);
GT_GetGadgetAttrs(monwinGadgets[GD_monstr],monwinWnd,NULL,GTST_String,(ULONG)&str,TAG_DONE);
adr=((monactline+DefMonStart)*8)+monactcol+1;
if(*str=='$') {
// HEX search
mx=strlen(str)-1;
for(i=1,j=0;i<mx;i+=2,j++) {
c=str[i+2];
str[i+2]='\0';
sscanf(&str[i],"%x",&h1);
str[i+2]=c;
dat[j]=(u_byte)h1;
dat[j+1]=-1;
}
while(find==0&&adr<0x10000) {
if(p4ram[adr]==dat[0]) {
oadr=adr;
for(i=0;dat[++i]==p4ram[++adr];);
if(dat[i]==-1) {
// megvan, urás oda
DefMonStart=oadr/8;
monactcol=oadr%8;
monactline=0;
if(DefMonStart>(8192-27)) {
j=DefMonStart-(8192-27);
DefMonStart=(8192-27);
monactline=j;
}
find=1;
calcmon();
} else adr=oadr;
}
adr++;
}
} else {
// STRING search
if(strlen(str)>0) {
mx=strlen(str);
for(i=0;i<mx;i++) {
dat[i]=mtoupper(str[i]);
dat[i+1]=-1;
}
while(find==0&&adr<0x10000) {
if(dat[0]==mtoupper(p4ram[adr])) {
oadr=adr;
for(i=0;dat[++i]==mtoupper(p4ram[++adr]););
if(dat[i]==-1) {
// megvan, urás oda
DefMonStart=oadr/8;
monactcol=oadr%8;
monactline=0;
if(DefMonStart>(8192-27)) {
j=DefMonStart-(8192-27);
DefMonStart=(8192-27);
monactline=j;
}
find=1;
calcmon();
} else adr=oadr;
}
adr++;
}
}
}
GT_SetGadgetAttrs(monwinGadgets[GD_monsea],monwinWnd,NULL,GA_Disabled,FALSE,TAG_DONE);
return(TRUE);
}
static int monscrollClicked(struct IntuiMessage *imsg) {
/* routine when gadget "" is clicked. */
moninput=0;
DefMonStart=imsg->Code;
calcmon();
if(imsg->Class==IDCMP_GADGETDOWN) {
ReportMouse(TRUE,monwinWnd);
monitorscroll=1;
} else {
ReportMouse(FALSE,monwinWnd);
monitorscroll=0;
}
return(TRUE);
}
static int dbgwinmpprefs(struct IntuiMessage *imsg) {
/* routine when (sub)item "Prefs" is selected. */
int r=TRUE,rt;
SleepWindows();
rt=prefsgui();
if(rt!=0) {
exitcode=EXIT_BACK;
if((rt&1)!=0) exitcode=EXIT_RESET;
if((rt&2)!=0) exitcode=EXIT_QUIT;
r=FALSE;
}
ret|=B6; // prefs is kell!
ScreenToFront(Scr);
AwakeWindows();
ActivateWindow(imsg->IDCMPWindow);
WindowToFront(imsg->IDCMPWindow);
return(r);
}
void savemem(char *filename,int from,int to) {
FILE *f;
int lo,hi,i;
if(filename==NULL) return;
if(from<0||from>0xffff||to>0xffff) return;
if(to<=from) return;
f=fopen(filename,"wb");
if(f==NULL) return;
lo=from&0xff;
hi=from>>8;
fputc(lo,f);
fputc(hi,f);
for(i=from;i<to;i++) fputc((int)p4ram[i],f);
fclose(f);
} // savemem
static int dbgwinmpsave(struct IntuiMessage *imsg) {
/* routine when (sub)item "Save mem" is selected. */
int exit=0,from,to;
char str[10];
char *filename,*s;
SleepWindows();
if(0==OpensvmwinWindow(imsg->MouseX,imsg->MouseY,Scr)) {
from=(memread(0x2c)<<8)+memread(0x2b);
to=(memread(0x2e)<<8)+memread(0x2d);
sprintf(str,"%04X",from);
GT_SetGadgetAttrs(svmwinGadgets[GD_sfromstr],svmwinWnd,NULL,GTST_String,(ULONG)str,TAG_DONE);
sprintf(str,"%04X",to);
GT_SetGadgetAttrs(svmwinGadgets[GD_stostr],svmwinWnd,NULL,GTST_String,(ULONG)str,TAG_DONE);
while(!exit) {
WaitPort(svmwinWnd->UserPort);
exit=HandlesvmwinIDCMP();
}
if(exit==1) {
// save it, filereq, save, ha nem cancel
GT_GetGadgetAttrs(svmwinGadgets[GD_sfromstr],svmwinWnd,NULL,GTST_String,(ULONG)&s,TAG_DONE);
sscanf(s,"%x",&from);
GT_GetGadgetAttrs(svmwinGadgets[GD_stostr],svmwinWnd,NULL,GTST_String,(ULONG)&s,TAG_DONE);
sscanf(s,"%x",&to);
if(AslRequestTags(frq,
ASLFR_TitleText,(ULONG)GetStr(MSG_00FE),
ASLFR_Window, NULL,
ASLFR_SleepWindow, FALSE,
ASLFR_DoSaveMode,TRUE,
ASLFR_RejectIcons, TRUE,
ASLFR_InitialDrawer, (ULONG)opt_p4dir,
ASLFR_Screen, (ULONG)Scr,
TAG_DONE,0L)) {
filename=makefilename(frq);
savemem(filename,from,to);
}
}
ClosesvmwinWindow();
}
AwakeWindows();
return(TRUE);
}
static int dbgwinmpreset(struct IntuiMessage *imsg) {
/* routine when (sub)item "Reset" is selected. */
exitcode=EXIT_RESET;
return(FALSE);
}
static int dbgwinmpback(struct IntuiMessage *imsg) {
/* routine when (sub)item "Back" is selected. */
exitcode=EXIT_BACK;
return(FALSE);
}
static int dbgwinmpquit(struct IntuiMessage *imsg) {
/* routine when (sub)item "Quit" is selected. */
exitcode=EXIT_QUIT;
return(FALSE);
}
static int dbgwinmdtrace(struct IntuiMessage *imsg) {
/* routine when (sub)item "Trace" is selected. */
return(dtraceClicked(imsg));