File: rm.c

package info (click to toggle)
ts10 0.8.021004-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 3,572 kB
  • ctags: 11,742
  • sloc: ansic: 68,289; makefile: 466
file content (391 lines) | stat: -rwxr-xr-x 10,434 bytes parent folder | download | duplicates (2)
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
// rm.c - RM MASSBUS-based disk drive routines
//
// Written by
//  Timothy Stark <sword7@speakeasy.org>
//
// This file is part of the TS10 Emulator.
// See ReadMe for copyright notice.
//
//  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

#include "emu/defs.h"
#include "dev/rh.h"
#include "dev/rm.h"
#include "dev/proto.h"

// This controller supports many different disk drive types:
//
// Type     # Sectors/  # Surfaces/  # Cyclinders/    Total
//           Surface     Cyclinder       Drive
//
// RM02/03     32            5            823      =  67 MB
// RM80        31           14            559      = 124 MB
// RM05        32           19            823      = 256 MB

DTYPE rm_dTypes[] = {
	{
		"RM02",          // Device Name
		"RM02 - 67MB Disk Pack Drive",
		UNIT_REMOVABLE|UNIT_ATTABLE|UNIT_DISABLE,
		32,              // Number of Sectors
		5,               // Number of Surfaces
		823,             // Number of Cylinders
		(32 * 5 * 823),  // Total Blocks
		020023,          // Device Type
		NULL,            // Not Used

		RH11_PACK,       // RH11 Flags - Disk Pack Type
		NULL,            // Not Used

		disk_Open,       // Low-level Open Routine 
		disk_Close,      // Low-level Close Routine
		disk_Read,       // Low-level Read Routine
		disk_Write,      // Low-level Write Routine
		NULL,            // Low-level Mark Routine
		NULL,            // Low-level Rewind Routine
		NULL,            // Low-level Skip Routine
		disk_Seek,       // Low-level Seek Routine
		disk_GetDiskAddr // Low-level GetDiskAddr Routine
	},

	{
		"RM03",          // Device Name
		"RM03 - 67MB Disk Pack Drive",
		UNIT_REMOVABLE|UNIT_ATTABLE|UNIT_DISABLE,
		32,              // Number of Sectors
		5,               // Number of Surfaces
		823,             // Number of Cylinders
		(32 * 5 * 823),  // Total Blocks
		020024,          // Device Type
		NULL,            // Not Used

		RH11_PACK,       // RH11 Flags - Disk Pack Type
		NULL,            // Not Used

		disk_Open,       // Low-level Open Routine 
		disk_Close,      // Low-level Close Routine
		disk_Read,       // Low-level Read Routine
		disk_Write,      // Low-level Write Routine
		NULL,            // Low-level Mark Routine
		NULL,            // Low-level Rewind Routine
		NULL,            // Low-level Skip Routine
		disk_Seek,       // Low-level Seek Routine
		disk_GetDiskAddr // Low-level GetDiskAddr Routine
	},

	{
		"RM80",          // Device Name
		"RM80 - 124MB Disk Pack Drive",
		UNIT_REMOVABLE|UNIT_ATTABLE|UNIT_DISABLE,
		31,              // Number of Sectors
		19,              // Number of Surfaces
		559,             // Number of Cylinders
		(31 * 19 * 559), // Total Blocks
		020026,          // Device Type
		NULL,            // Not Used

		RH11_PACK,       // RH11 Flags - Disk Pack Type
		NULL,            // Not Used

		disk_Open,       // Low-level Open Routine 
		disk_Close,      // Low-level Close Routine
		disk_Read,       // Low-level Read Routine
		disk_Write,      // Low-level Write Routine
		NULL,            // Low-level Mark Routine
		NULL,            // Low-level Rewind Routine
		NULL,            // Low-level Skip Routine
		disk_Seek,       // Low-level Seek Routine
		disk_GetDiskAddr // Low-level GetDiskAddr Routine
	},

	{
		"RM05",          // Device Name
		"RM05 - 256MB Disk Pack Drive",
		UNIT_REMOVABLE|UNIT_ATTABLE|UNIT_DISABLE,
		32,              // Number of Sectors
		19,              // Number of Surfaces
		823,             // Number of Cylinders
		(32 * 19 * 823), // Total Blocks
		020027,          // Device Type
		NULL,            // Not Used

		RH11_PACK,       // RH11 Flags - Disk Pack Type
		NULL,            // Not Used

		disk_Open,       // Low-level Open Routine 
		disk_Close,      // Low-level Close Routine
		disk_Read,       // Low-level Read Routine
		disk_Write,      // Low-level Write Routine
		NULL,            // Low-level Mark Routine
		NULL,            // Low-level Rewind Routine
		NULL,            // Low-level Skip Routine
		disk_Seek,       // Low-level Seek Routine
		disk_GetDiskAddr // Low-level GetDiskAddr Routine
	},

	{ NULL },
};

DEVICE rm_Device =
{
	"RM",          // Device Name
	"MASSBUS Disk Pack Drives",
	"v0.0 (Alpha)",// Version
	rm_dTypes,     // Listing of RM devices
	NULL,          // Listing of Units
	NULL,          // Listing of Slave Devices - Not used
	NULL,          // Listing of Commands
	NULL,          // Listing of Set Commands
	NULL,          // Listing of Show Commands

	0,             // Number of Devices
	RM_MAXUNITS,   // Number of Units

	rm_Initialize, // Initialize Routine
	rm_Reset,      // Reset Routine
	rm_Create,     // Create Routine
	rm_Delete,     // Delete Routine
	NULL,          // Configure Routine - Not Used
	rm_Enable,     // Enable Routine
	rm_Disable,    // Disable Routine
	rm_Attach,     // Attach Routine
	rm_Detach,     // Detach Routine
	NULL,          // Format Routine - Not Used
	rm_ReadIO,     // Read I/O Routine
	rm_WriteIO,    // Write I/O Routine
	rm_Process,    // Process Routine
	rm_Boot,       // Boot Routine
	NULL,          // Execute Routine - Not Used

	rm_SetUnit,    // SetUnit Routine
	rm_SetATA,     // SetATA Routine
	rm_ClearATA    // ClearATA Routine
};

#ifdef DEBUG
// Listing of name of the registers for debug facility
// Note: ^ = Mixed, * = Drive Register, space = Controller Register

char *rm_RegNames[] =
{
	"RMCS1", // (R/W) ^Control and Status Register #1
	"RMWC",  // (R/W)  Word Count Register
	"RMBA",  // (R/W)  Bus Address Register
	"RMDA",  // (R/W) *Desired Sector/Track Address Register
	"RMCS2", // (R/W)  Control and Status Register #2
	"RMDS",  // (R)   *Drive Status Register
	"RMER1", // (R)   *Error Register #1
	"RMAS",  // (R/W) *Attention Summary Register
	"RMLA",  // (R)   *Look-Ahead Register
	"RMDB",  // (R/W)  Data Buffer Register
	"RMMR1", // (R/W)  Maintenance Register #1
	"RMDT",  // (R)   *Drive Type Register
	"RMSN",  // (R)   *Serial Number Register
	"RMOF",  // (R/W) *Offset Register
	"RMDC",  // (R/W) *Desired Cylinder Address Register
	"RMHR",  // (R/W) *Holding Register (Not Used)
	"RMMR2", // (R)   *Maintenance Register #2
	"RMER2", // (R/W) *Error Register #2
	"RMEC1", // (R)   *ECC Position Register
	"RMEC2", // (R)   *ECC Pattern Register
	"RMBAE", // (R/W)  Bus Address Extension Register  (RH70 Only)
	"RMCS3"  // (R/W)  Control and Status Register #3  (RH70 Only)
};
#endif /* DEBUG */

// Power Up Initialization
void rm_Initialize(UNIT *rmUnit)
{
	RMUNIT *rmData = (RMUNIT *)rmUnit->uData;
}

void rm_Reset(UNIT *rmUnit)
{
	RMUNIT *rmData  = (RMUNIT *)rmUnit->uData;
}

// Create the desired RM disk drive
int rm_Create(UNIT *uptr, char *devName, int argc, char **argv)
{
	if (!(uptr->Flags & UNIT_PRESENT)) {
		RMUNIT *rmData = (RMUNIT *)calloc(sizeof(RMUNIT), 1);

		if (rmData) {
			int idx;
			int st;

			for (idx = 0; rm_dTypes[idx].Name; idx++) {
				if (!strcasecmp(argv[0], rm_dTypes[idx].Name)) {
					printf("Found %s\n", rm_dTypes[idx].Name);
					break;
				}
			}

			if (!rm_dTypes[idx].Name) {
				free(rmData);
				return EMU_ARG;
			}

			*strchr(argv[1], ':') = '\0';
//			if (st = unit_mapCreateDevice(argv[1], uptr)) {
//				free(rmData);
//				return st;
//			}

			uptr->dType  = &rm_dTypes[idx];
			uptr->Device = &rm_Device;
			uptr->Flags  = rm_dTypes[idx].Flags | UNIT_PRESENT;
			uptr->uData  = (void *)rmData;
		} else
			return EMU_MEMERR;
	} else
		return EMU_ARG;
	return EMU_OK;
}

// Delete the desired RM disk drive
int rm_Delete(UNIT *rmUnit)
{
	if (rmUnit->Flags & UNIT_PRESENT) {
		free(rmUnit->uData);
		rmUnit->Flags &= ~UNIT_PRESENT;

		return EMU_OK;
	}
	return EMU_NPRESENT;
}

int rm_Enable(UNIT *rmUnit)
{
	return EMU_OK;
}

int rm_Disable(UNIT *rmUnit)
{
	return EMU_OK;
}

int rm_Attach(UNIT *rmUnit, char *fileName)
{
	RMUNIT *rmData = (RMUNIT *)rmUnit->pUnit->uData;
	int    st;

	if (rmUnit->Flags & UNIT_DISABLED)
		return EMU_DISABLED;

	if (rmUnit->Flags & UNIT_ATTACHED)
		return EMU_ATTACHED;

	// Attach a file to that unit
	st = disk_Open(&rmUnit->FileRef, fileName, 0,
		rmUnit->szBlock, rmUnit->Blocks);
	if (st) return st;

	rmUnit->Flags |= UNIT_ATTACHED|UNIT_WRLOCKED;

	// Now let's set some registers for medium on-line
	rmData->rmds |= 0;
	rm_SetATA(rmUnit->pUnit);

	return EMU_OK;
}

int rm_Detach(UNIT *rmUnit)
{
	RMUNIT *rmData = (RMUNIT *)rmUnit->pUnit->uData;
	int st;

	if (rmUnit->Flags & UNIT_DISABLED)
		return EMU_DISABLED;

	if (!(rmUnit->Flags & UNIT_ATTACHED))
		return EMU_ARG;

	// Detach a file from that unit.
	if (st = disk_Close(&rmUnit->FileRef))
		return st;

	rmUnit->Flags &= ~(UNIT_ATTACHED|UNIT_WRLOCKED);

	// Now let's set some registers for medium off-line
	rmData->rmds &= ~0;

	return EMU_OK;
}

UNIT *rm_SetUnit(UNIT *rmUnit)
{
	return rmUnit;
}

void rm_SetATA(UNIT *rmUnit)
{
	RMUNIT *rmData  = (RMUNIT *)rmUnit->uData;
	UNIT   *pUnit   = rmUnit->pUnit;
	DEVICE *pDevice = pUnit->Device;

	rmData->rmds |= RMDS_ATA;
	pDevice->SetATA(pUnit, rmUnit->idUnit);
}

void rm_ClearATA(UNIT *rmUnit)
{
	RMUNIT *rmData  = (RMUNIT *)rmUnit->uData;
	UNIT   *pUnit   = rmUnit->pUnit;
	DEVICE *pDevice = pUnit->Device;

	rmData->rmds &= ~RMDS_ATA;
	pDevice->ClearATA(pUnit, rmUnit->idUnit);
}

void rm_Ready(UNIT *rmUnit)
{
	UNIT   *pUnit   = rmUnit->pUnit;
	DEVICE *pDevice = pUnit->Device;

	pDevice->Ready(pUnit);
}

void rm_WriteData(UNIT *rmUnit)
{
}

int32 rm_ReadIO(UNIT *rmUnit, int32 reg)
{
	RMUNIT *rmData = (RMUNIT *)rmUnit->uData;
	int32  data    = 0;

	return data;
}

void rm_WriteIO(UNIT *rmUnit, int32 reg, int32 data)
{
	RMUNIT *rmData = (RMUNIT *)rmUnit->uData;
}

void rm_Go(UNIT *rmUnit)
{
}

int rm_Process(UNIT *rmUnit)
{
	return EMU_OK;
}

int rm_Boot(UNIT *rmUnit, int argc, char **argv)
{
	printf("Not supported yet.\n");
	return EMU_NOTSUPPORTED;
}