forked from viridia/faery-tale-amiga
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hdrive.c
155 lines (127 loc) · 3.04 KB
/
hdrive.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#define SETFN(n) openflags |= n
#define TSTFN(n) openflags & n
#define AL_BMAP 0x0001
#define AL_GBASE 0x0002
#define AL_HANDLE 0x0004
#define AL_MUSIC 0x0008
#define AL_IMAGE 0x0010
#define AL_SECTOR 0x0020
#define AL_MASK 0x0040
#define AL_SHAPE 0x0080
#define AL_SHADOW 0x0100
#define AL_FONT 0x0200
#define AL_SAMPLE 0x0400
#define AL_PORT 0x0800
#define AL_IOREQ 0x1000
#define AL_TDISK 0x2000
#define AL_TERR 0x4000
extern UWORD openflags;
static BOOL hdrive = FALSE;
static BPTR file;
/* 9 diskreqs: 5 landscape, 2 Terrain, 1 map, 1 sector, 1 monster */
struct MsgPort *diskport;
struct IOExtTD *diskreq1, diskreqs[10], *lastreq;
int AllocDiskIO()
{ short i;
BPTR lock;
if (lock = Lock("image",ACCESS_READ))
{
hdrive = TRUE;
UnLock(lock);
if ( (file = Open("image",MODE_OLDFILE)) == NULL ) return 30;
}
else
{
if ((diskport = CreatePort(0,0))==0) return 30;
SETFN(AL_PORT);
if ((diskreq1=(struct IOExtTD *)CreateExtIO(diskport,sizeof(struct IOExtTD)))==0) return 31;
SETFN(AL_IOREQ);
if (OpenDevice(TD_NAME,0,(struct IORequest *)diskreq1,0)) return 32;
SETFN(AL_TDISK);
for (i=0; i<9; i++)
{ diskreqs[i] = *diskreq1;
}
}
return 0;
}
void FreeDiskIO()
{
if (file) Close(file);
if (TSTFN(AL_TDISK)) CloseDevice((struct IORequest *)diskreq1);
if (TSTFN(AL_IOREQ)) DeleteExtIO((struct IORequest *)diskreq1);
if (TSTFN(AL_PORT)) DeletePort(diskport);
}
void WaitDiskIO(num) int num;
{
if (hdrive == FALSE)
WaitIO((struct IORequest *)&diskreqs[num]);
}
void InvalidDiskIO(num) int num;
{
if (hdrive == FALSE)
diskreqs[num].iotd_Req.io_Command = CMD_INVALID;
}
int CheckDiskIO(num) int num;
{
if (hdrive == FALSE) return CheckIO((struct IORequest *)&diskreqs[num]);
return TRUE;
}
int IsReadDiskIO(num) int num;
{
if (hdrive == FALSE) return (diskreqs[num].iotd_Req.io_Command == CMD_READ);
return FALSE;
}
void WaitLastDiskIO()
{
if (hdrive == FALSE)
WaitIO((struct IORequest *)lastreq);
}
void InvalidLastDiskIO()
{
if (hdrive == FALSE)
lastreq->iotd_Req.io_Command = CMD_INVALID;
}
int CheckLastDiskIO()
{
if (hdrive == FALSE) return CheckIO((struct IORequest *)lastreq);
return TRUE;
}
int IsReadLastDiskIO()
{
if (hdrive == FALSE) return (lastreq->iotd_Req.io_Command == CMD_READ);
return FALSE;
}
load_track_range(f_block,b_count,buffer,dr)
short f_block, b_count, dr; APTR buffer;
{ short error;
if (hdrive == FALSE)
{
lastreq = &(diskreqs[dr]);
if (lastreq->iotd_Req.io_Command == CMD_READ) WaitIO((struct IORequest *)lastreq);
*lastreq = *diskreq1;
lastreq->iotd_Req.io_Length = b_count * 512;
lastreq->iotd_Req.io_Data = buffer;
lastreq->iotd_Req.io_Command = CMD_READ;
lastreq->iotd_Req.io_Offset = f_block * 512;
SendIO((struct IORequest *)lastreq);
}
else
{
Seek(file,f_block * 512,OFFSET_BEGINNING);
Read(file,buffer,b_count * 512);
}
}
motor_off()
{
if (hdrive == FALSE)
{
diskreqs[9] = *diskreq1;
diskreqs[9].iotd_Req.io_Length = 0;
diskreqs[9].iotd_Req.io_Command = TD_MOTOR;
DoIO((struct IORequest *)&diskreqs[9]);
}
}
BOOL IsHardDrive(void)
{
return hdrive;
}