-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedisasm.c
1770 lines (1606 loc) · 39.9 KB
/
edisasm.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
/*******************************************************************************
***
*** Filename : edisasm.c
*** Purpose : An EPOC16 disassembler
*** Author : Matt J. Gumbley
*** Further work : Alex Brown
*** Created : 31/07/98
***
********************************************************************************
***
*** Modification Record
***
*******************************************************************************/
#include "dis.h"
#include "machine.h"
#include "edisasm.rsg"
GLREF_D UWORD _UseFullScreen;
LOCAL_D UINT MainWid; /* ID of main window */
#define VERTICAL_LEADING 1
LOCAL_D TEXT szUnused[] = "(unused)";
LOCAL_D TEXT *isrnames[] = {
"Divide by zero",
"Single step",
"Non-Masked Interrupt",
"Break",
"Overflow",
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
"IRQ0",
"IRQ1",
"IRQ2",
"IRQ3",
"IRQ4",
"IRQ5",
"IRQ6",
"IRQ7",
"SegManager",
"HeapManager",
"SemManager",
"MessManager",
"LibManager",
"DevManager",
"IoManager",
"FilManager",
"ProcManager",
"TimManager",
"ConvManager",
"GenManager",
"FloatManager",
"WServOpcodes",
"HardwareManager",
"GenDataSegment",
"ProcPanic",
"ProcCopyFromById",
"ProcCopyToById",
"CharIsDigit",
"CharIsHexDigit",
"CharIsPrintable",
"CharIsAlphabetic",
"CharIsAlphaNumeric",
"CharIsUpperCase",
"CharIsLowerCase",
"CharIsSpace",
"CharIsPunctuation",
"CharIsGraphic",
"CharIsControl",
"CharToUpperChar",
"CharToLowerChar",
"CharToFoldedChar",
"BufferCopy",
"BufferSwap",
"BufferCompare",
"BufferCompareFolded",
"BufferMatch",
"BufferMatchFolded",
"BufferLocate",
"BufferLocateFolded",
"BufferSubBuffer",
"BufferSubBufferFolded",
"BufferJustify",
"StringCopy",
"StringCopyFolded",
"StringConvertToFolded",
"StringCompare",
"StringCompareFolded",
"StringMatch",
"StringMatchFolded",
"StringLocate",
"StringLocateFolded",
"StringLocateInReverse",
"StringLocateInReverseFolded",
"StringSubString",
"StringSubStringFolded",
"StringLength",
"StringValidateName",
"LongIntCompare",
"LongIntMultiply",
"LongIntDivide",
"LongUnsignedIntCompare",
"LongUnsignedIntMultiply",
"LongUnsignedIntDivide",
"FloatAdd",
"FloatSubtract",
"FloatMultiply",
"FloatDivide",
"FloatCompare",
"FloatNegate",
"FloatToInt",
"FloatToUnsignedInt",
"FloatToLong",
"FloatToUnsignedLong",
"IntToFloat",
"UnsignedIntToFloat",
"LongToFloat",
"UnsignedLongToFloat",
"LibSend",
"LibSendSuper",
"LibSendExact",
"LibEnter",
"LibLeave",
"Dummy",
"GenIntByNumber",
"WservFunctions",
"LibSendExit",
"DbfManager",
"LibEnterSend",
"IoKeyAndMouseStatus",
"StringCapitalise",
"ProcIndStringCopyFromById",
"IoNextHalfSecondStatus",
"IoSerManager",
"HwSetRomBank",
"HwGetRomBank",
"IoActivity",
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused,
szUnused};
LOCAL_D INT text_height = 0; /* Height of the current font */
LOCAL_D INT text_width = 0; /* Width of the current font */
LOCAL_D INT text_ascent = 0; /* Ascent of the current font */
LOCAL_D INT text_descent = 0; /* Descent of the current font */
LOCAL_D INT rows; //=16; /* how many rows available, minus edit box? */
LOCAL_D INT cols; //=79; /* how many columns available? */
LOCAL_D TEXT *maladdr = "malformed address";
/* Keyboard stuff */
LOCAL_D WORD key_stat;
LOCAL_D WMSG_KEY key;
LOCAL_D WORD key_active = FALSE;
#define EDITLEN 80
#define FONT (WS_FONT_BASE + 8)
LOCAL_D P_SCR_SET_FONT Font;
P_RECT rect;
/* Editor stuff */
LOCAL_D VOID *ebH;
/* Cursor positioning stuff */
LOCAL_D INT cx = 0, cy = 0;
/* Address holders */
LOCAL_D UWORD seg = 0, off = 0, intno = 0, bankno = 0;
LOCAL_D UWORD psel0, psel1, psel2, psel3;
/* Disassembler stuff */
INT objflg = 0; /* Flag: output object bytes */
INT force = 0; /* Flag: override some checks */
INT linesout = 0; /* Num of lines displayed so far */
GLDEF_D char hexdig[] = "0123456789ABCDEF";
LOCAL_D TEXT LINE[80];
/* prototypes for assembler routines in access.asm */
GLREF_C VOID SETPSEL0(UWORD);
GLREF_C UBYTE GETPSEL0(void);
GLREF_C VOID SETPSEL1(UWORD);
GLREF_C UBYTE GETPSEL1(void);
GLREF_C VOID SETPSEL2(UWORD);
GLREF_C UBYTE GETPSEL2(void);
GLREF_C UBYTE ACCESS(UWORD, UWORD);
GLREF_C VOID MEMCPY(UWORD segdiv4, UWORD offset, UWORD count, UBYTE *buf);
GLREF_C VOID MEMCPYPSEL0(UWORD psel0, UWORD offsetseg6000, UWORD count, UBYTE *buf);
GLREF_C VOID MEMCPYPSEL1(UWORD psel0, UWORD offsetseg7000, UWORD count, UBYTE *buf);
GLREF_C VOID MEMCPYPSEL2(UWORD psel2, UWORD offsetseg8000, UWORD count, UBYTE *buf);
GLREF_C UWORD GETCS(void);
GLREF_C UWORD GETDS(void);
GLREF_C UWORD GETA9RCTRL(void);
GLREF_C UWORD GETA9RSTAT(void);
LOCAL_C VOID cls(VOID)
{
cx = cy = 0;
gClrRect(&rect, G_TRMODE_CLR);
}
GLDEF_C UBYTE getchar(VOID)
{
UWORD seg, off;
seg = (PC & 0xf0000L) >> 4;
off = (PC & 0x0ffffL);
return ACCESS(seg, off);
}
GLDEF_C VOID disassemble(VOID)
{
// char *c;
UBYTE b;
register void (*f)();
segflg = 0;
linesout = 0;
for (PC = (seg << 4) + off; linesout < rows; ++PC)
{
b = getchar();
f = optab[b].func;
(*f)(b);
}
}
GLDEF_C UBYTE Fetch(VOID)
{
UBYTE b;
++PC;
b = getchar();
objbuf[objptr++] = b;
return b;
}
LOCAL_C INT printAt(INT x, INT y, TEXT *str, INT len)
{
gPrintText(x * text_width + 2, y * text_height + 2 + text_ascent, str, len);
return len;
}
LOCAL_C VOID rackup(VOID)
{
P_RECT p;
P_POINT pp;
p.tl.x = 2;
p.tl.y = 2 + text_height;
p.br.x = rect.br.x;
p.br.y = rect.br.y;
pp.x = 0;
pp.y = -text_height;
wScrollRect(MainWid, &p, &pp);
p.tl.y = p.br.y - text_height;
gClrRect(&p, G_TRMODE_CLR);
}
LOCAL_C VOID println(TEXT *str)
{
if (cy == rows)
{
rackup();
cy--;
}
cx = 0; // just in case
printAt(cx, cy, str, p_slen(str));
if (cy < rows)
{
cy++;
}
}
LOCAL_C VOID printlnc(TEXT *str)
{
if (cy == rows)
{
rackup();
cy--;
}
cx = (cols / 2) - (p_slen(str) / 2); // roughly centre?
printAt(cx, cy, str, p_slen(str));
cx = 0; // clean things up
if (cy < rows)
{
cy++;
}
}
LOCAL_C VOID niceerror_E_FILE(INT err)
{
switch (err)
{
case E_FILE_DEVICE:
println("E_FILE_DEVICE: Invalid or non-existent device specified.");
return;
case E_FILE_NOTREADY:
println("E_FILE_NOTREADY: Nothing in drive.");
return;
case E_FILE_CORRUPT:
println("E_FILE_CORRUPT: No valid boot record found - unformatted?");
return;
case E_FILE_UNKNOWN:
println("E_FILE_UNKNOWN: No idea what the medium is!");
return;
}
}
LOCAL_C VOID gotoxy(INT x, INT y)
{
cx = x;
cy = y;
}
LOCAL_C INT parse_bankno(TEXT *addr)
{
UWORD tbankno;
/* Skip WS until hex digit */
while (*addr && !p_isxdigit(*addr))
addr++;
/* EOL? Use last address */
if (!*addr)
return TRUE;
if (p_stog(&addr, &tbankno, 16) != 0)
{
wInfoMsg(maladdr);
return FALSE;
}
bankno = tbankno;
return TRUE;
}
LOCAL_C INT parse_intno(TEXT *addr)
{
UWORD tintno;
/* Skip WS until hex digit */
while (*addr && !p_isxdigit(*addr))
addr++;
/* EOL? Use last address */
if (!*addr)
return TRUE;
if (p_stog(&addr, &tintno, 16) != 0)
{
wInfoMsg(maladdr);
return FALSE;
}
intno = tintno;
return TRUE;
}
LOCAL_C INT parse_address(TEXT *addr)
{
UWORD tseg, toff;
/* Skip WS until hex digit */
while (*addr && !p_isxdigit(*addr))
addr++;
/* EOL? Use last address */
if (!*addr)
return TRUE;
if (p_stog(&addr, &tseg, 16) != 0)
{
wInfoMsg(maladdr);
return FALSE;
}
if (*addr == ':')
{
addr++;
if (p_stog(&addr, &toff, 16) != 0)
{
wInfoMsg(maladdr);
return FALSE;
}
seg = tseg;
off = toff;
}
else
{
off = tseg;
}
return TRUE;
}
LOCAL_C VOID dump_bytes(VOID)
{
INT y, x;
UBYTE b[16];
UWORD prevbank = p_getrombank();
cls();
for (y = 0; y < rows; y++)
{
p_bfil(LINE, 79, ' ');
p_atos(LINE, "%04x:%04x", seg, off);
LINE[9] = ' ';
LINE[10] = LINE[60] = '\263';
p_setrombank(bankno);
MEMCPY(seg >> 4, off, 16, b);
p_setrombank(prevbank);
for (x = 0; x < 16; x++)
{
off++;
if (!off)
seg += 0x1000;
LINE[12 + (3 * x)] = hexdig[(b[x] & 0xf0) >> 4];
LINE[13 + (3 * x)] = hexdig[b[x] & 0x0f];
LINE[62 + x] = b[x];
}
printAt(0, y, LINE, 78);
}
cy = rows; // otherwise any regular println() will start at the top of the screen
}
LOCAL_C VOID dump_words(VOID)
{
INT y, x;
UBYTE h, l;
UWORD prevbank = p_getrombank();
cls();
for (y = 0; y < rows; y++)
{
p_bfil(LINE, 79, ' ');
p_atos(LINE, "%04x:%04x", seg, off);
LINE[9] = ' ';
LINE[10] = LINE[60] = '\263';
for (x = 0; x < 8; x++)
{
p_setrombank(bankno);
l = ACCESS(seg, off);
p_setrombank(prevbank);
LINE[62 + (x << 1)] = l;
off++;
if (!off)
seg += 0x1000;
p_setrombank(bankno);
h = ACCESS(seg, off);
p_setrombank(prevbank);
LINE[63 + (x << 1)] = h;
off++;
if (!off)
seg += 0x1000;
LINE[12 + (5 * x)] = hexdig[(h & 0xf0) >> 4];
LINE[13 + (5 * x)] = hexdig[h & 0x0f];
LINE[14 + (5 * x)] = hexdig[(l & 0xf0) >> 4];
LINE[15 + (5 * x)] = hexdig[l & 0x0f];
}
printAt(0, y, LINE, 78);
}
cy = rows; // otherwise any regular println() will start at the top of the screen
}
LOCAL_C VOID ivt(VOID)
{
INT y, x;
UBYTE b[4];
/*
0 1 2 3 4 5 6 7
01234567890123456789012345678901234567890123456789012345678901234567890
INT 00=0000:0000 INT 01=0000:0000 INT 02=0000:0000 INT 03=0000:0000
*/
cls();
for (y = 0; y < rows; y++)
{
p_bfil(LINE, 70, ' ');
LINE[0] = '\0';
for (x = 0; x < 4; x++)
{
MEMCPY(0, (intno << 2), 4, b);
p_atos(LINE + (x * 18), "INT %02x=%c%c%c%c:%c%c%c%c ", intno,
hexdig[(b[3] & 0xf0) >> 4],
hexdig[b[3] & 0x0f],
hexdig[(b[2] & 0xf0) >> 4],
hexdig[b[2] & 0x0f],
hexdig[(b[1] & 0xf0) >> 4],
hexdig[b[1] & 0x0f],
hexdig[(b[0] & 0xf0) >> 4],
hexdig[b[0] & 0x0f]);
intno++;
if (intno == 0x100)
intno = 0;
}
printAt(0, y, LINE, 70);
}
}
LOCAL_C VOID ivtlong(VOID)
{
INT y; //, x;
UBYTE b[4];
cls();
for (y = 0; y < rows; y++)
{
p_bfil(LINE, 70, ' ');
LINE[0] = '\0';
MEMCPY(0, (intno << 2), 4, b);
p_atos(LINE, "INT %02x=%c%c%c%c:%c%c%c%c %s\0", intno,
hexdig[(b[3] & 0xf0) >> 4],
hexdig[b[3] & 0x0f],
hexdig[(b[2] & 0xf0) >> 4],
hexdig[b[2] & 0x0f],
hexdig[(b[1] & 0xf0) >> 4],
hexdig[b[1] & 0x0f],
hexdig[(b[0] & 0xf0) >> 4],
hexdig[b[0] & 0x0f],
isrnames[intno]);
intno++;
if (intno == 0x100)
intno = 0;
printAt(0, y, LINE, 70);
}
}
LOCAL_C VOID send_ivt(VOID)
{
VOID *fd;
INT i;
static TEXT *head = "Listing of interrupts";
UBYTE b[4];
static TEXT LINE[80];
static TEXT *fname = "REM::C:\\IVT.LST";
if (p_open(&fd, fname, P_FTEXT | P_FREPLACE | P_FUPDATE) != 0)
println("Can't create interrupt listing file");
else
{
println("Creating...");
println(fname);
p_write(fd, head, p_slen(head));
for (i = 0; i < 0x100; i++)
{
MEMCPY(0, (i << 2), 4, b);
p_atos(LINE, "INT %02x=%c%c%c%c:%c%c%c%c %s", i,
hexdig[(b[3] & 0xf0) >> 4],
hexdig[b[3] & 0x0f],
hexdig[(b[2] & 0xf0) >> 4],
hexdig[b[2] & 0x0f],
hexdig[(b[1] & 0xf0) >> 4],
hexdig[b[1] & 0x0f],
hexdig[(b[0] & 0xf0) >> 4],
hexdig[b[0] & 0x0f],
isrnames[i]);
p_write(fd, LINE, p_slen(LINE));
}
println("done.");
p_close(fd);
}
}
/* I noted on the mailing list that:
EPOC p_setrombank() and p_getrombank() set and get the value
of PSEL3. The parameter of p_setrombank() ranges from 0x00 to 0xff. Values
< 0x80 cause the address decoder to select no memory, and so nothing is
accessible, apart from a series of increasing numbers in the
0x9000:0000-FFFF bank. Values of 0x80 to 0x9F cause one of the 0x20 64KB
banks to be selected. Values from 0xA0 to 0xBF and 0xC0 to 0xFF produce
identical banks to those selected for values 0x80 to 0x9F.
*/
LOCAL_C VOID banktest(VOID)
{
VOID *fd;
INT i, x;
static TEXT *head = "Which banks get switched?\r\n";
#define BTLEN 2048
UBYTE b[BTLEN];
UWORD tot6000, tot7000, tot8000, tot9000;
static TEXT buf[80];
static TEXT LINE[80];
static TEXT *fname = "REM::C:\\BANKS.LST";
UWORD prevbank = p_getrombank();
if (p_open(&fd, fname, P_FSTREAM | P_FREPLACE | P_FUPDATE) != 0)
println("Can't create bank listing file");
else
{
println("Creating...");
println(fname);
p_write(fd, head, p_slen(head));
for (i = 0; i < 0x100; i++)
{
p_atos(buf, "Checksumming bank %02x", i);
wInfoMsg(buf);
/* Do banks at 6000 */
MEMCPYPSEL0(i, 0x0000, BTLEN, b);
tot6000 = 0;
p_crc(&tot6000, b, BTLEN);
p_atos(LINE, "Seg 6000 Bank %02x:\r\n", i);
p_write(fd, LINE, p_slen(LINE));
for (x = 0; x < 16; x++)
{
p_atos(LINE, "%02x ", b[x]);
p_write(fd, LINE, p_slen(LINE));
}
p_write(fd, ": ", 2);
for (x = 0; x < 16; x++)
{
LINE[0] = p_isprint(b[x]) ? b[x] : '.';
p_write(fd, LINE, 1);
}
p_write(fd, "\r\n", 2);
/* Do banks at 7000 */
MEMCPYPSEL1(i, 0x0000, BTLEN, b);
tot7000 = 0;
p_crc(&tot7000, b, BTLEN);
p_atos(LINE, "Seg 7000 Bank %02x:\r\n", i);
p_write(fd, LINE, p_slen(LINE));
for (x = 0; x < 16; x++)
{
p_atos(LINE, "%02x ", b[x]);
p_write(fd, LINE, p_slen(LINE));
}
p_write(fd, ": ", 2);
for (x = 0; x < 16; x++)
{
LINE[0] = p_isprint(b[x]) ? b[x] : '.';
p_write(fd, LINE, 1);
}
p_write(fd, "\r\n", 2);
/* Do banks at 8000 */
MEMCPYPSEL2(i, 0x0000, BTLEN, b);
tot8000 = 0;
p_crc(&tot8000, b, BTLEN);
p_atos(LINE, "Seg 8000 Bank %02x:\r\n", i);
p_write(fd, LINE, p_slen(LINE));
for (x = 0; x < 16; x++)
{
p_atos(LINE, "%02x ", b[x]);
p_write(fd, LINE, p_slen(LINE));
}
p_write(fd, ": ", 2);
for (x = 0; x < 16; x++)
{
LINE[0] = p_isprint(b[x]) ? b[x] : '.';
p_write(fd, LINE, 1);
}
p_write(fd, "\r\n", 2);
/* Do banks at 9000 */
p_setrombank(i);
MEMCPY(0x0900, 0x0000, BTLEN, b);
p_setrombank(prevbank);
tot9000 = 0;
p_crc(&tot9000, b, BTLEN);
p_atos(LINE, "Seg 9000 Bank %02x:\r\n", i);
p_write(fd, LINE, p_slen(LINE));
for (x = 0; x < 16; x++)
{
p_atos(LINE, "%02x ", b[x]);
p_write(fd, LINE, p_slen(LINE));
}
p_write(fd, ": ", 2);
for (x = 0; x < 16; x++)
{
LINE[0] = p_isprint(b[x]) ? b[x] : '.';
p_write(fd, LINE, 1);
}
p_write(fd, "\r\n", 2);
p_atos(LINE, "BANK %02x 6000=%04x 7000=%04x 8000=%04x 9000=%04x\r\n", i, tot6000, tot7000, tot8000, tot9000);
p_write(fd, LINE, p_slen(LINE));
}
println("done.");
p_close(fd);
}
}
LOCAL_C VOID send(UINT seg, UINT off, UINT lastseg, TEXT *fname)
{
VOID *fd;
#define BUFFERSIZE 1024
static UBYTE buf[BUFFERSIZE];
UINT tseg;
TEXT szbuf[40];
UWORD prevbank = p_getrombank();
p_atos(szbuf, "REM::C:\\%s.MEM", fname);
if (p_open(&fd, szbuf, P_FSTREAM | P_FREPLACE | P_FUPDATE) != 0)
{
println("Can't create output file");
println(szbuf);
}
else
{
println("Creating...");
println(szbuf);
println("To stop, kill EDisAsm from System Screen");
while (seg < lastseg)
{
tseg = seg << 4;
p_atos(szbuf, "Writing data from %04x:%04x", tseg, off);
wInfoMsg(szbuf);
p_setrombank(bankno);
MEMCPY(seg, off, BUFFERSIZE, buf);
p_setrombank(prevbank);
p_write(fd, buf, BUFFERSIZE);
off += BUFFERSIZE;
if (off == 0)
seg += 0x100;
}
println("done.");
p_close(fd);
}
}
LOCAL_C VOID sendbank(UWORD bank)
{
TEXT buf[40];
p_atos(buf, "ROM2%02x", bank);
bankno = bank;
send(0x0900, 0x0000, 0x0A00, buf);
}
LOCAL_C VOID sendbanks9000()
{
INT b;
for (b = 0x80; b < 0xA0; b++)
sendbank(b);
}
/**
Extracts two hex numbers from a string, separated by spaces.
It's used with the sendbanksX000() functions to pick which banks to send
across a PLP link. It calls p_stoa() to extract the two numbers, then does
some processing. Returns a status as an INT.
*/
LOCAL_C INT banknums(TEXT **bankargsptr, UINT *firstbankptr, UINT *lastbankptr)
{
INT ret;
ret = p_stoa(bankargsptr, "%x %x", firstbankptr, lastbankptr);
switch (ret)
{
case 0: // Got two arguments, everything's fine
break;
case E_GEN_ARG: // Not enough arguments, so there's only one
*lastbankptr = *firstbankptr;
break;
default: // Any other error, we leave now
return -1; // miscellaneous bad arguments from p_stoa()
}
if (*firstbankptr > *lastbankptr)
{
return -2; // First bank can't be bigger than the last bank
}
if (*firstbankptr > 0xFF || *lastbankptr > 0xFF || *firstbankptr < 0 || *lastbankptr < 0)
{
return -3; // invalid number
}
return 0;
}
LOCAL_C VOID sendbanks9000selection(TEXT *bankargs)
{
UINT firstbank = 0, lastbank = 0;
INT ret;
TEXT szbuf[80];
INT b;
ret = banknums(&bankargs, &firstbank, &lastbank);
switch (ret)
{
case 0:
break;
case -1:
println("Bad arguments.");
return;
case -2:
p_atos(szbuf, "First bank can't be bigger than the last bank! (%02x>%02x)", firstbank, lastbank);
println(szbuf);
return;
case -3:
println("Bank must be between 00 and FF!");
return;
default:
println("Unhandled error from banknums()");
return;
}
if (firstbank == lastbank)
{
p_atos(szbuf, "Sending bank %02x...", firstbank);
}
else
{
p_atos(szbuf, "Sending banks %02x to %02x...", firstbank, lastbank);
}
println(szbuf);
for (b = firstbank; b <= lastbank; b++)
sendbank(b);
}
/* Versions of the above that use direct OUTs to PSEL2 to access the banks at
* 80000
*/
LOCAL_C VOID sendPSEL2(UINT seg, UINT off, UINT lastseg, TEXT *fname)
{
VOID *fd;
#define BUFFERSIZE 1024
static UBYTE buf[BUFFERSIZE];
UINT tseg;
TEXT szbuf[80];
UBYTE prevbank = GETPSEL2();
#if 0
p_atos(szbuf,"PSEL2=0x%02x", prevbank);
println(szbuf);
p_atos(szbuf,"bankno=0x%02x", bankno);
println(szbuf);
return;
#endif
p_atos(szbuf, "REM::C:\\%s.MEM", fname);
if (p_open(&fd, szbuf, P_FSTREAM | P_FREPLACE | P_FUPDATE) != 0)
{
println("Can't create output file");
println(szbuf);
}
else
{
println("Creating...");
println(szbuf);
println("To stop, kill EDisAsm from System Screen");
while (seg < lastseg)
{
tseg = seg << 4;
p_atos(szbuf, "Writing data from %04x:%04x", tseg, off);
wInfoMsg(szbuf);
SETPSEL2(bankno);
MEMCPY(seg, off, BUFFERSIZE, buf);
SETPSEL2(prevbank);
p_write(fd, buf, BUFFERSIZE);
off += BUFFERSIZE;
if (off == 0)
seg += 0x100;
}
println("done.");