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

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

Added missing includes and declarations.

  • Property mode set to 100644
File size: 3.1 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#include "memory.h"
12
13#define DF_FREC 6 /* first sector of primary FAT */
14
15#define DF_FSIZ 5 /* FAT size */
16#define DF_DSIZ 7 /* directory size */
17
18extern int16_t defect; /* defect code */
19extern int16_t dferror; /* error code from BIOS or XBIOS */
20
21extern int16_t dftype; /* disk type code */
22extern int16_t dfsides; /* number of sides */
23
24extern uint16_t dfbuf[4096]; /* track formatting buffer */
25
26/*
27
28*/
29
30/*
31 =============================================================================
32 dformat() -- format a disk for the Bucla 700
33
34 entry: dt = zero for single sided disk,
35 non-zero for double sided disk
36
37 returns: SUCCESS or FAILURE and:
38
39 defect = formatting error code:
40
41 0 no errors
42 1 unable to format 1st side
43 2 unable to format 2nd side
44 3 unable to write boot sector
45 4 unable to write primary FAT
46 5 unable to write secondary FAT
47 6 unable to write directory
48
49 dferror = BIOS or XBIOS error code if an error occurred
50 =============================================================================
51*/
52
53int16_t dformat(int16_t dt)
54{
55 register int16_t 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 = (int16_t)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 = (int16_t)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 = (int16_t)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 = (int16_t)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 = (int16_t)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 = (int16_t)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.