-
Notifications
You must be signed in to change notification settings - Fork 1
/
BD.C
245 lines (215 loc) · 5.46 KB
/
BD.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
/*
* UZIX - UNIX Implementation for MSX
* (c) 1997-2001 Arcady Schekochikhin
* Adriano C. R. da Cunha
*
* UZIX is based on UZI (UNIX Zilog Implementation)
* UZI is a UNIX kernel clone written for Z-80 systems.
* All code is public domain, not being based on any AT&T code.
*
* The author, Douglas Braun, can be reached at:
* 7696 West Zayante Rd.
* Felton, CA 95018
* oliveb!intelca!mipos3!cadev4!dbraun
*
* This program is under GNU GPL, read COPYING for details
*
*/
/**********************************************************
UZIX utilities:
Block dump: to examine disk.
Usage: bd d: blkstart [blkend]
**********************************************************/
/* The device is given as drive letter.
* Major device is always 0 (FDD), minor device is 0..7 (drives A..H)
*/
#define __MAIN__COMPILATION
#define NEED__DEVIO
#define NEED__SCALL
#define XFS
/*#include "utildos.h"*/
#include "uzix.h"
#ifdef SEPH
#include "types.h"
#include "signal.h"
#include "errno.h"
/* #error sdsdsd */
#endif
#include "unix.h"
#ifdef SEPH
#include "sys\ioctl.h"
#endif
#ifdef _MSX_DOS
#include "..\include\stdio.h"
#include "..\include\stdlib.h"
#include "..\include\ctype.h"
#else
#include "dsk.h"
#include "orion.h"
extern void bufinit(void);
extern void *bread(dev_t dev, blkno_t blk, uchar rewrite);
#define d_open(dev) d_openclose(dev, 1)
#define d_close(dev) d_openclose(dev, 0)
extern int d_openclose(dev_t dev, uchar open);
extern int d_init(void);
extern blkbuf_t bufpool[NBUFS];
extern int printf(char *, ...);
extern long atol(char *);
extern void exit(int);
extern char bios(int, ...);
#define xexit(n) exit(n)
extern unsigned char TotalDrives;
extern PARTITION Drives[];
/*char TEMPDBUF[BUFSIZE];*/
void list_drives()
{
int i;
printf("\n%d total drives. Partitions:\n\nDev\tDrive#\tPart#\tSize,kb\tOffset Checksum Type\n", TotalDrives);
for (i=0; i<MAXDRIV; i++) {
printf("fd%d\t%d\t%d\t%lu\t%lu\t%d\t%s (%d)\n", i,
(int)(Drives[i].pd), /* Get physical drive# */
(Drives[i].pt), /* Get partition# */
(Drives[i].size/2), /* Get partition size */
(Drives[i].po), /* Get partition offset */
(int)(Drives[i].pc), /* Get partition record checksumm */
(Drives[i].ptype==82 ? "CP/M" : (Drives[i].ptype==33 ? "UZIX" : (Drives[i].ptype==-1 ? "PHISICAL" : (!Drives[i].ptype ? "" : "OTHER")))),
(int)Drives[i].ptype); /* Get partition type */
}
}
#endif
char buf[BUFSIZE];
void dread(int dev, uint blk, char *addr) {
char *buf = bread(dev, blk, 0);
if (buf == NULL) {
printf("bd: device or drive error\n");
xexit(1);
}
/*
printf("\ndread(dev=%d, blk=%d, buf=%04x, addr=%04x); TEMPDBUF=%04x\n",
dev, blk, (unsigned int)&buf[0], (unsigned int)&addr[0], (unsigned int)&TEMPDBUF[0]);
*/
bcopy(buf, addr, BUFSIZE);
bfree((bufptr)buf, 0);
}
int isdig(char cc) {
if ((cc>='0') && (cc<='9')) return 1; else return 0;
}
#ifdef ORI_UTIL
void c_hex(unsigned char cc) {
cc<10 ? bios(4,cc+'0') : bios(4,cc+'A'-10);
}
void pr_hex(unsigned char ch) {
c_hex(ch >> 4);
c_hex(ch & 15);
}
void bc_hexdump(unsigned char *buf, int count) {
int c;
register int bc=0;
char txt[17];
for (c = 0; c < count; c++) {
if (!bc) {
pr_hex(((unsigned int)&buf[c])>>8);
pr_hex((unsigned char)&buf[c]);
bios(4,' ');
}
pr_hex(buf[c]);
bios(4,' ');
if (buf[c]>' ')
txt[bc]=buf[c];
else
txt[bc]='.';
bc++;
if (bc == 16) {
txt[16]=0;
bc=0;
printf(" %s\n", txt);
}
}
if (bc) {
for (c = bc; c < 16; c++) printf(" ");
printf(" %s\n", txt);
}
printf("\n");
}
#endif
void main(argc, argv)
int argc;
char *argv[];
{
#ifdef _MSX_DOS
int i, j, k, dev;
long addr;
#else
int dev;
#endif
unsigned blkno, blkend;
#ifdef _MSX_DOS
initenv();
#endif
if (argc < 3 || !isdig(argv[1][0]) || (argv[1][1] != ':')) {
printf("usage: bd d: blkstart [blkend|-blkno]\n");
xexit(1);
}
dev = argv[1][0] - '0';
blkno = (unsigned)atol(argv[2]);
if (argc < 4)
blkend = blkno;
else {
if (argv[3][0] == '-')
blkend = blkno + (unsigned)atol(argv[3]+1) - 1;
else blkend = (unsigned)atol(argv[3]);
}
#ifdef _MSX_DOS
printf("Insert disk and press RETURN: ");
while (getchar() != '\n')
;
cursor(0);
#endif
bufinit();
d_init();
#ifdef ORI_UTIL
if (!TotalDrives) { /* IDEBDOS check and devices fd0..fd9 configuring */
printf("\nNo drives or IDEBDOS v2.x not installed\n");
xexit(1);
}
#endif
list_drives();
d_open(dev);
printf("\nDevice %x, blocks %u..%u\n", dev, blkno, blkend);
#ifdef _MSX_DOS
addr = (long)blkno * BUFSIZE; /* starting address */
#endif
while (blkno <= blkend) {
printf("\nBlock %u = 0x", blkno);
pr_hex(blkno>>8);
pr_hex((unsigned char)blkno);
printf("\n");
dread(dev, blkno++, buf);
#ifdef ORI_UTIL
bc_hexdump((void*)buf, BUFSIZE);
#else
for (i = 0; i < BUFSIZE / 16; ++i, addr += 16) {
printf("%02x%04x\t", (uint)(addr >> 16), (uint)addr);
for (j = 0; j < 16; ++j) {
k = buf[(i<<4)+j] & 0xFF;
printf("%02X ", k);
}
printf(" |");
for (j = 0; j < 16; ++j) {
k = buf[(i<<4)+j] & 0xFF;
if (k < ' ' || k == 0177 || k == 0377)
k = '.';
printf("%c", k);
}
printf("|\n");
}
printf("\n");
fflush(stdout);
#endif
}
#ifdef _MSX_DOS
cursor(255);
#endif
exit(0);
}