source: buchla-68k/orig/RAM/DFORMAT.C@ 4f508e6

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

Imported original source code.

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