source: buchla-68k/ram/dformat.c@ b28a12e

Last change on this file since b28a12e was b28a12e, checked in by Thomas Lopatic <thomas@…>, 7 years ago

Zero redundant declarations.

  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 =============================================================================
3 dformat.c -- format a disk for the Buchla 700
4 Version 2 -- 1988-03-28 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "ram.h"
9
10#define DF_FREC 6 /* first sector of primary FAT */
11
12#define DF_FSIZ 5 /* FAT size */
13#define DF_DSIZ 7 /* directory size */
14
15/*
16
17*/
18
19/*
20 =============================================================================
21 dformat() -- format a disk for the Bucla 700
22
23 entry: dt = zero for single sided disk,
24 non-zero for double sided disk
25
26 returns: SUCCESS or FAILURE and:
27
28 defect = formatting error code:
29
30 0 no errors
31 1 unable to format 1st side
32 2 unable to format 2nd side
33 3 unable to write boot sector
34 4 unable to write primary FAT
35 5 unable to write secondary FAT
36 6 unable to write directory
37
38 dferror = BIOS or XBIOS error code if an error occurred
39 =============================================================================
40*/
41
42int16_t dformat(int16_t dt)
43{
44 register int16_t trk;
45
46 if (dt) { /* setup for double sided disk */
47
48 dftype = 3; /* 80 tracks, double sided */
49 dfsides = 2; /* 2 sides */
50
51 } else { /* setup for single sided disk */
52
53 dftype = 2; /* 80 tracks, single sided */
54 dfsides = 1; /* 1 side */
55 }
56
57 /* format each side of each track */
58
59 for (trk = 0; trk < 80; trk++) {
60
61 if (dferror = (int16_t)XBIOS(X_FORMAT, dfbuf, 0L, 0, 9,
62 trk, 0, 1, 0x87654321L, 0xE5E5)) {
63
64 defect = 1; /* unable to format 1st side */
65 return(FAILURE);
66 }
67
68 if (dfsides EQ 2) { /* format second side */
69
70 if (dferror = (int16_t)XBIOS(X_FORMAT, dfbuf, 0L, 0, 9,
71 trk, 1, 1, 0x87654321L, 0xE5E5)) {
72
73 defect = 2; /* unable to format 2nd side */
74 return(FAILURE);
75 }
76 }
77 }
78
79 /* create boot sector */
80
81 memsetw(dfbuf, 0, 4096);
82 XBIOS(X_PRBOOT, dfbuf, 0x01000000L, dftype, 0);
83
84 /* write boot sector to disk */
85
86 if (dferror = (int16_t)XBIOS(X_FLOPWR, dfbuf, 0L, 0, 1, 0, 0, 1)) {
87
88 defect = 3; /* unable to write boot sector */
89 return(FAILURE);
90 }
91
92 /* clear the FATs */
93
94 memsetw(dfbuf, 0, 4096);
95
96 if (dfsides EQ 2) {
97
98 dfbuf[0] = 0xFDFF;
99 dfbuf[1] = 0xFF00;
100
101 } else {
102
103 dfbuf[0] = 0xFCFF;
104 dfbuf[1] = 0xFF00;
105 }
106
107 if (dferror = (int16_t)BIOS(B_RDWR, 3, dfbuf,
108 DF_FSIZ, DF_FREC, 0)) {
109
110 defect = 4; /* unable to write primary FAT */
111 return(FAILURE);
112 }
113
114 if (dferror = (int16_t)BIOS(B_RDWR, 3, dfbuf,
115 DF_FSIZ, DF_FREC-DF_FSIZ, 0)) {
116
117 defect = 5; /* unable to write secondary FAT */
118 return(FAILURE);
119 }
120
121 /* clear the directory */
122
123 memsetw(dfbuf, 0, 4096);
124
125 if (dferror = (int16_t)BIOS(B_RDWR, 3, dfbuf,
126 DF_DSIZ, DF_FREC+DF_FSIZ, 0)) {
127
128 defect = 6; /* unable to write directory */
129 return(FAILURE);
130 }
131
132 defect = 0; /* no errors */
133 return(SUCCESS);
134}
135
Note: See TracBrowser for help on using the repository browser.