BEDINTRO.C
C source for Bedlam, 100 lines. Raw file
#include <dos.h>
#include <math.h>
#include <stdio.h>
// But heaven still howls from the smallest sounds to the cries of the stormtops.
// Every whispered secret, every muffled sigh, every half-truth that was added to a lie.
union REGS regs;
unsigned char (far *screen)[320] = MK_FP(0xA000, 0);
unsigned long (far *lscreen)[80] = MK_FP(0xA000, 0);
struct _pal {
char r, g, b;
} p[256];
void main(void)
{
FILE *in, *out, *out2;
int i, j, k, l, m, q, r, s;
in = fopen("bedintro.bmp", "rb");
out = fopen("bedintro.inc", "wt");
regs.x.ax = 0x13;
int86(0x10, ®s, ®s);
fseek(in, 0x36, SEEK_SET);
for(i = 0; i < 256; i ++)
{
p[i].b = fgetc(in) >> 2;
p[i].g = fgetc(in) >> 2;
p[i].r = fgetc(in) >> 2;
fgetc(in);
}
regs.x.ax = 0x1012;
regs.x.bx = 0;
regs.x.cx = 256;
regs.x.dx = FP_OFF(p);
_ES = FP_SEG(p);
int86(0x10, ®s, ®s);
fseek(in, 0x436, SEEK_SET);
for(j = 199; j >= 0; j --)
for(i = 0; i < 320; i ++)
screen[j][i] = fgetc(in);
fprintf(out, "\n* BACK *\n");
for(j = 0; j < 100; j ++)
{
fprintf(out, "\n db");
for(i = 0; i < 100; i += 4)
{
k = (screen[j][i+96]-0x19) & 3;
screen[j][i+96] ^= 255;
k += ((screen[j][i+97]-0x19) & 3) << 2;
screen[j][i+97] ^= 255;
k += ((screen[j][i+98]-0x19) & 3) << 4;
screen[j][i+98] ^= 255;
k += ((screen[j][i+99]-0x19) & 3) << 6;
screen[j][i+99] ^= 255;
fprintf(out, " %d", k);
if (i<96) fprintf(out, ",");
}
}
fprintf(out, "\n\n* BLOCKS *\n");
for(l = 0; l < 8*16; l += 16)
for(k = 0; k < 6*4; k += 4)
for(j = 0; j < 16; j ++)
{
fprintf(out, " dd 0%lXh, 0%lXh, 0%lXh, 0%lXh\n",
lscreen[j+l][k],
lscreen[j+l][k+1],
lscreen[j+l][k+2],
lscreen[j+l][k+3]);
lscreen[j+l][k] ^=-1;
lscreen[j+l][k+1] ^=-1;
lscreen[j+l][k+2] ^=-1;
lscreen[j+l][k+3] ^=-1;
}
fprintf(out, "\n\n* SINE *\n");
for(i = 0; i < 157; i ++)
fprintf(out, " dw %d\n", 320*((int)(26+20*sin(2*i*M_PI/157))));
}