-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLOADERS.C
167 lines (137 loc) · 3.96 KB
/
LOADERS.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
#include <stdio.h>
#include <stdlib.h>
#include <types.h>
#include "wicked.h"
#define NR_LOADERS 2 /* MOD, S3M */
WMOD Mod;
udword GUSPos = 0;
/* funny feature: recognizing the most known polish composers */
static char *PolishComposers[] =
{"XTD", "FALCON", "KEYG", "BARTESEK", "ROBO", "RAIDEN", "SCORPIK",
"LSD", "DAN", "CIELIK", "DAVE", "SNOOPY", "NORVEG"
};
static ubyte NrPLComposers = sizeof(PolishComposers)/sizeof(char *);
LOADER *UsedLdr;
//ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
/* does exactly what the name says */
/* BTW, i'm 99% sure that there's built-in C function which does the same */
/* what this routine, but i dunno its name :) you know, i've learnt C */
/* from other people's codes, not from boox, so i don't know all nice */
/* intructions. ok, let's stop it, coz otherwise this comment will be */
/* longer then the function itself. hmm, in fact it already is... */
static char ChrUpr(char ch)
{
if (ch >= 'a' && ch <= 'z')
ch -= ('a' - 'A');
return ch;
}
/*
=================
Ldr_SafeMalloc
=================
*/
static void *Ldr_SafeMalloc(udword ile)
{
void *temp;
temp = malloc(ile);
if (!temp)
shutUp("Cannot allocate memory! I need %lu bytes!", ile);
return temp;
}
/*
=====================
LDR_Search4Poland
=====================
*/
bool LDR_Search4Poland(void)
{
int i, j, z, x;
bool found = 0;
/* first, let's check some famous Polish trademarks */
if (!memcmp(Mod.WModName, "##", 2)) /* XTD */
return 1;
if (Mod.WModName[strlen(Mod.WModName)-1] == '_') /* Falcon */
return 1;
if (Mod.WModName[0] == '>') /* KeyG (new) */
return 1;
if (!memcmp(Mod.WModName, "<<<", 3)) /* KeyG (old) */
return 1;
if (!memcmp(&Mod.WModName[strlen(Mod.WModName)-4], "RDN!", 4))/* Raiden */
return 1;
if (!memcmp(Mod.WModName, "++", 2)) /* Robo */
return 1;
/* i am not sure why this works, but hey, don't look a gift horse
in the mouth, rite? */
for (i = 0; i < NrPLComposers; i++)
{
for (j = 0; j < 4; j++)
{
z = 0;
/* let's search for the first char */
while (z < strlen(Mod.Samples[j].Name))
{
if (ChrUpr(Mod.Samples[j].Name[z]) == PolishComposers[i][0])
{
x = 1;
while (ChrUpr(Mod.Samples[j].Name[x+z]) == PolishComposers[i][x] &&
x < strlen(Mod.Samples[j].Name) && x < strlen(PolishComposers[i]))
x++;
if (x == strlen(PolishComposers[i]))
{
found = 1;
break;
}
else
z++;
}
else
z++;
}
if (found)
break;
}
if (found)
break;
}
return found;
}
/*
=================
LDR_LoadSample
Load samples from file and kick 'em to GUS memory
=================
*/
void LDR_LoadSample(int i, FILE *f, ubyte type)
{
udword Len;
char *Buf;
Len = Mod.Samples[i].Len;
if (Len)
{
GUSPos += 31;
GUSPos &= -32; /* GUS address tricks */
if (GUSPos + Len > UsedDrv->DeviceMem)
shutUp("ML_LoadSample(): Not Enough GUS Mem! GUSPos: %d, Sample Len: %d!",
GUSPos, Len);
Buf = (char *)Ldr_SafeMalloc(Len+1);
SafeFRead(Buf, Len, f);
GUSDumpSample(GUSPos, Buf, Len, type);
free(Buf);
Mod.GUSMemUsed += Len;
}
// trick against the nasty GUS clicks
if (Mod.Samples[i].Loop)
{
/* if loop than copy the first byte in the loop
one place beyond the end of the loop */
GUSPoke(GUSPos + Mod.Samples[i].LoopEnd, GUSPeek(GUSPos + Mod.Samples[i].LoopStart));
}
else
{
/* no loop: zero the byte beyond the end of sample */
GUSPoke(GUSPos + Len, 0);
}
Mod.Samples[i].GUSPos = GUSPos;
if (Len)
GUSPos += (Len+1);
}