-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.c
359 lines (303 loc) · 10.2 KB
/
hello.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
// "hello. my name is DOS!"
// Code by shock and easy.
// Graphics by darkowl
// Music by ctrix
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <conio.h>
#include <wildfile.h>
#include <mikmod.h>
#define M_PI 3.141592654
static const char *modfile = "hello.mod";
void vmode(unsigned short);
#pragma aux vmode =\
"int 10h",\
parm [ax] modify [ax];
#if 0
void waitvr (void) {
/* source: http://www.delorie.com/djgpp/doc/ug/graphics/vga.html */
/* wait until any previous retrace has ended */
while (inp(0x3da) & 8) {};
/* wait until a new retrace has just begun */
while (!(inp(0x3da) & 8)) {};
}
#else
void waitvr(void);
#pragma aux waitvr =\
"mov dx,3dah",\
"wait1:",\
"in al,dx",\
"test al,8",\
"jz wait1",\
modify [al dx];
#endif
char scrolltext[] = "IN:TYPICAL:LAST:MINUTE:STYLE:A:PARTY:SCROLLER:IS:BORN:FOR:SYNTAX2014:BY:DISASTER:AREA:AND:EXTRA:FRIENDS::::TO:KEEP:THIS:SHORT:GREETS:OUT:TO:THE:FOLLOWING::::::DEFAME::::::ONSLAUGHT::::::A:LIFE:IN:HELL::::::RESET64::::::HELLFIRE64::::::MUDLORD::::::SYNTAX:PARTYGOERS::::::RETROGAMERS:EVERYWHERE::::::ALL:THOSE:WE:FORGOT::::::CODE::SH0CK::EASY::::GFX::DARKOWL::::MUSIC::CTRIX::::::PEACE:OUT:::AND:REPEATING:NOW";
extern unsigned char landscape_map[];
extern unsigned char diagonal_image[];
extern unsigned char title_palette[];
extern unsigned char title[];
extern unsigned char rotozoomer_palette[];
extern unsigned char rotozoomer[];
extern unsigned char letters_palette[];
extern unsigned char letters[];
void draw_wavey(int t, char *vidmem, int *sineLookup, char *image,
unsigned char *map) {
int v, l, offsetX, y, x, i, colour;
v = l = offsetX = y = x = colour = 0;
for (y = 0; y < 200; y ++) {
for (x = 96; x < 128; x ++) {
offsetX = (x + t) % 0xff;
v = map[offsetX + (y << 8)];
l = sineLookup[x + (v << 8)];
colour = image[offsetX + (y << 8)];
for (i = (160 - l); i < 160; i ++) {
vidmem[i + (y << 8) + (y << 6)] = colour;
}
}
for (x = 163; x >= 128; x --) {
offsetX = (x + t) % 0xff;
v = map[offsetX + (y << 8)];
l = sineLookup[x + (v << 8)];
colour = image[offsetX + (y << 8)];
for (i = 160; i < (160 + l + 1); i ++) {
vidmem[i + (y << 8) + (y << 6)] = colour;
}
}
}
}
void draw_zoomer(int t, char *vidmem, unsigned char *image, int *sintab) {
int m, dy, dx, sv, cv, y, x, ddx, ddy;
m = (int)t;
dy = sintab[(m/3)&0xFF] << 8;
dx = sintab[(m/2)&0xFF] << 8;
sv = sintab[m&0xFF];
cv = sintab[(m+64)&0xFF];
for (y=0; y<200; y++) {
ddx = dx;
ddy = dy;
for (x=0; x<320; x++) {
vidmem[x + (y << 8) + (y << 6)] = image[(ddx >> 8 & 0xff) + ((ddy >> 8 & 0xff) << 8)];
ddx += cv;
ddy += sv;
}
dx -= sv;
dy += cv;
}
}
void set129pal(unsigned char colour) {
outp (0x3c8, 129);
outp (0x3c9, colour);
outp (0x3c9, colour);
outp (0x3c9, colour);
}
void setpal(unsigned char palp[]) {
int pcount;
outp (0x3c8, 0);
for (pcount=0; pcount<768; pcount+=3)
{
outp (0x3c9, palp[pcount]);
outp (0x3c9, palp[pcount+1]);
outp (0x3c9, palp[pcount+2]);
}
}
void drawchar(char letter, int x, int y, unsigned char *letters,
unsigned char *buffer) {
// 32x, 50y
int start_x, len_x, start_y, len_y, offset, offset_x, offset_y, i, j;
unsigned char colour;
if (x + 32 < 0) return;
if (y + 50 < 0) return;
if (x > 320) return;
if (y > 200) return;
start_x = ((x < 0)?0:x);
start_y = ((y < 0)?0:y);
offset_x = ((x < 0)?abs(x):0);
offset_y = ((y < 0)?abs(y):0);
len_x = ((x+32) > 319?32 - ((x+32) - 319):32 - offset_x);
len_y = ((y+50) > 199?50 - ((y+50) - 199):50 - offset_y);
offset = (letter - 48) * 32;
for (i = offset_x; i < offset_x + len_x; i ++) {
for (j = offset_y; j < len_y; j ++) {
colour = letters[offset + i + ((49 - j) * 1376)];
if (colour != 255) {
buffer[start_x + i - offset_x + ((start_y + j - offset_y) << 8) +
((start_y + j - offset_y) << 6)] = colour;
}
}
}
}
void drawstring(char *words, int x, int y, int c, unsigned char *letters,
unsigned char *buffer, int *sineRoto) {
int i;
for(i = 0; i < strlen(words); i ++) {
drawchar(words[i], x + (i * 32) + (i * 2),
y + (sineRoto[(c + (i * 10)) % 0xff] >> 4), letters, buffer);
}
}
void tickhandler(void)
{
MP_HandleTick(); /* play 1 tick of the module */
MD_SetBPM(mp_bpm);
}
int main ()
{
UNIMOD *mf;
static char pal[768];
static int sineLookup[256*256];
static int sineRoto[256];
static unsigned char bitmap[256*256];
static unsigned char map[256*256];
unsigned char framebuffer[320*200];
int v, x, y, counter, slide, bounce;
char z;
char *vidmem = (char *)0xA0000;
int textlen = strlen(scrolltext);
/*
Initialize soundcard parameters.. you _have_ to do this
before calling MD_Init(), and it's illegal to change them
after you've called MD_Init()
*/
md_mixfreq =44100; /* standard mixing freq */
md_dmabufsize =10000; /* standard dma buf size */
md_mode =DMODE_16BITS|DMODE_STEREO; /* standard mixing mode */
md_device =0; /* standard device: autodetect */
/*
Register the loaders we want to use..
*/
//ML_RegisterLoader(&load_m15); /* if you use m15load, register it as first! */
ML_RegisterLoader(&load_mod);
MD_RegisterDriver(&drv_nos);
MD_RegisterDriver(&drv_sb);
MD_RegisterPlayer(MP_HandleTick);
if(!MD_Init()){
printf("MikMod driver error: %s\n",myerr);
return 0;
}
/*
printf("Using %s for %d bit %s %s sound at %u Hz\n",
md_driver->Name,
(md_mode&DMODE_16BITS) ? 16:8,
(md_mode&DMODE_INTERP) ? "interpolated":"normal",
(md_mode&DMODE_STEREO) ? "stereo":"mono",
md_mixfreq);
*/ /* load the module */
mf=ML_LoadFN(modfile);
/* didn't work -> exit with errormsg. */
if(mf==NULL){
printf("MikMod Error: %s\n",myerr);
return 0;
}
MP_Init(mf);
/*
printf( "Songname: %s\n"
"Modtype : %s\n"
"Periods : %s,%s\n",
mf->songname,
mf->modtype,
(mf->flags&UF_XMPERIODS) ? "XM type" : "mod type",
(mf->flags&UF_LINEAR) ? "Linear" : "Log");
*/
md_numchn=mf->numchn;
MD_PlayStart();
for (x=0, y=0; x<64*3; x+=3, y++)
pal[x] = y;
for (x=64*3, y=63; x<128*3; x+=3, y--)
pal[x] = y;
for (x=128*3, y=0; x<192*3; x+=3, y++)
pal[x+2] = y;
for (x=192*3, y=63; x<256*3; x+=3, y--)
pal[x+2] = y;
// Landscape palette
pal[(255 * 3) + 2] = 54;
pal[(255 * 3) + 1] = 67;
pal[(255 * 3) + 0] = 244;
pal[(254 * 3) + 2] = 243;
pal[(254 * 3) + 1] = 149;
pal[(254 * 3) + 0] = 32;
pal[(253 * 3) + 2] = 181;
pal[(253 * 3) + 1] = 81;
pal[(253 * 3) + 0] = 62;
pal[(252 * 3) + 2] = 183;
pal[(252 * 3) + 1] = 57;
pal[(252 * 3) + 0] = 103;
pal[(251 * 3) + 2] = 175;
pal[(251 * 3) + 1] = 39;
pal[(251 * 3) + 0] = 156;
pal[(250 * 3) + 2] = 98;
pal[(250 * 3) + 1] = 30;
pal[(250 * 3) + 0] = 233;
// Rotozoomer palette is first 128 colours
for (x = 0; x < 128 * 3; x += 3) {
pal[x + 0] = rotozoomer_palette[x + 2] >> 2;
pal[x + 1] = rotozoomer_palette[x + 1] >> 2;
pal[x + 2] = rotozoomer_palette[x + 0] >> 2;
}
// Title palette is next 2 colours
for (x = 0; x < 2 * 3; x += 3) {
pal[x + (128 * 3) + 0] = title_palette[x + 2] >> 2;
pal[x + (128 * 3) + 1] = title_palette[x + 1] >> 2;
pal[x + (128 * 3) + 2] = title_palette[x + 0] >> 2;
}
// Letters palette is the last 32 colours
for (x = 0; x < 32 * 3; x += 3) {
pal[x + (224 * 3) + 0] = letters_palette[x + 2] >> 2;
pal[x + (224 * 3) + 1] = letters_palette[x + 1] >> 2;
pal[x + (224 * 3) + 2] = letters_palette[x + 0] >> 2;
}
for (x = 0; x < 256; x ++) {
for (y = 0; y < 256; y ++) {
if (x >= 128) {
sineLookup[x + (y << 8)] = floor(y * (-sin(x / 128.0f * M_PI)) / 4);
} else {
sineLookup[x + (y << 8)] = floor(y * (sin(x / 128.0f * M_PI)) / 4);
}
}
}
for (x = 0; x < 256; x ++) {
sineRoto[x] = (int)(sin(x/256.0*M_PI*2)*127+127)*2;
}
for (x = 0; x < 256*256; x ++) {
bitmap[x] = rand() % 256;
}
for (x = 0; x < 256*256; x ++) {
map[x] = 128;
}
vmode (0x13);
setpal (pal);
slide = 320;
counter = 0;
while (!kbhit ())
{
memset(framebuffer, 0, 320*200);
if (counter >= 0 && counter < 64) {
set129pal(counter);
memcpy(framebuffer, title, 320*200);
} else if (counter >= 64 && counter < 256) {
memcpy(framebuffer, title, 320*200);
} else if (counter >= 256 && counter < 320) {
set129pal(63 - (counter - 256));
memcpy(framebuffer, title, 320*200);
} else {
draw_zoomer(counter, framebuffer, rotozoomer, sineRoto);
draw_wavey(counter, framebuffer, sineLookup, rotozoomer, landscape_map);
drawstring(scrolltext, slide, 100, counter, letters, framebuffer, sineRoto);
slide -= 2;
if (slide < -(textlen*34)) {
slide = 320;
}
}
counter ++;
waitvr ();
memcpy(vidmem, framebuffer, 320*200);
MD_Update();
}
getch ();
vmode (3);
MD_PlayStop(); /* stop playing */
ML_Free(mf); /* and free the module */
MD_Exit();
printf("Hello, my name was DOS!\n");
return 0;
}