forked from viridia/faery-tale-amiga
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhdrive.c
178 lines (151 loc) · 4.24 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "ftale.h" // Xark: Added to verify headers in sync
extern UWORD openflags;
// static BOOL hdrive = FALSE;
static FILE * filep;
/* 9 diskreqs: 5 landscape, 2 Terrain, 1 map, 1 sector, 1 monster */
// struct MsgPort * diskport;
// struct IOExtTD * diskreq1, diskreqs[10], *lastreq;
int AllocDiskIO()
{
// int16_t i;
// BPTR lock;
// if ((lock = Lock("image", ACCESS_READ)))
// {
// hdrive = TRUE;
// UnLock(lock);
//
// if ((file = Open("image", MODE_OLDFILE)) == 0)
// return 30; // Xark: NULL -> 0 (since BPTR)
// }
// 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;
// }
// }
// Xark: hdrive = TRUE;
if ((filep = fopen("game/image", "r")) == NULL)
{
printf("\nCan't open game data: \"game/image\"\n\n");
return 30;
}
return 0;
}
void FreeDiskIO()
{
if (filep)
{
fclose(filep);
filep = NULL;
}
// if (TSTFN(AL_TDISK))
// CloseDevice((struct IORequest *)diskreq1);
// if (TSTFN(AL_IOREQ))
// DeleteExtIO((struct IORequest *)diskreq1);
// if (TSTFN(AL_PORT))
// DeletePort(diskport);
}
void WaitDiskIO(int num)
{
(void)num;
// if (hdrive == FALSE)
// WaitIO((struct IORequest *)&diskreqs[num]);
}
void InvalidDiskIO(int num)
{
(void)num;
// if (hdrive == FALSE)
// diskreqs[num].iotd_Req.io_Command = CMD_INVALID;
}
int CheckDiskIO(int num)
{
(void)num;
// if (hdrive == FALSE)
// return (CheckIO((struct IORequest *)&diskreqs[num]) == NULL)
// ? FALSE
// : TRUE; // Xark: Converting ptr to int, test added
return TRUE;
}
int IsReadDiskIO(int num)
{
(void)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) == NULL) ? FALSE : TRUE;
return TRUE;
}
int IsReadLastDiskIO()
{
// if (hdrive == FALSE)
// return (lastreq->iotd_Req.io_Command == CMD_READ);
return FALSE;
}
void load_track_range(int16_t f_block, int16_t b_count, APTR buffer, int16_t dr)
{
// Xark: unused: int16_t error;
(void)dr;
// 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
{
RUNLOGF("<= load_track_range(%d, %d, %p) [@0x%x, 0x%x bytes/%.2f KB]",
f_block,
b_count,
buffer,
f_block * 512,
b_count * 512,
(b_count * 512) / 1024.0);
CHECK(0 == fseek(filep, f_block * 512, SEEK_SET));
CHECK(1 == fread(buffer, b_count * 512, 1, filep));
}
}
void motor_off(void)
{
// 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;
// }