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

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

Added include files for global functions and variables.

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