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

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

Removed form-feed comments.

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