Commit fbdea29f authored by Florian Schulze's avatar Florian Schulze

Initial revision

parents
File added
File added
File added
File added
File added
File added
File added
File added
1110000000000000000000
1000000000001000011000
1000111100001100000000
1000000000011110000011
1100000000111000000001
1110001111110000000001
1000000000000011110001
1000000000000000000011
1110011100000000000111
1000000000002200000001
1000000000022220000001
1044440000222222222001
1000000000000000000001
1100000000000000000011
2222222214000001333111
1111111111111111111111
\ No newline at end of file
File added
File added
File added
File added
File added
File added
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <pc.h>
#include <dpmi.h>
#include <go32.h>
#include <sys/nearptr.h>
#define DJ_SD_TYPE_NOSOUND 0
#define DJ_SD_TYPE_SBLASTER 1
#define DJ_SFX_TYPE_SSS 0
#define DJ_SFX_TYPE_WAV 1
#define DJ_SFX_TYPE_SMP 2
typedef struct dj_hardware_info {
char sd_type;
short sd_version;
short port;
char irq;
char dma;
} dj_hardware_info;
typedef struct dj_mixing_info {
char sfx_volume, num_sfx_channels;
char mod_volume, num_mod_channels;
char stereo_mix, auto_mix;
unsigned short mixing_freq;
unsigned short dma_time, dmabuf_len;
char cur_dmabuf;
unsigned long dmabuf_address[2];
char *mixed_buf;
} dj_mixing_info;
typedef struct sfx_data {
char priority;
unsigned short default_freq;
char default_volume;
unsigned long length;
char loop;
unsigned long loop_start, loop_length;
char *buf;
} sfx_data;
typedef struct dj_mod_info {
char num_channels;
char speed;
short bpm;
char order_pos;
char pat_pos;
char name[20];
struct {
char name[22];
unsigned short length;
char finetune;
char volume;
unsigned short loop_start;
unsigned short loop_length;
char *buf;
} samples[31];
char song_length;
char num_pat;
char pat_order[128];
char *pat[128];
} dj_mod_info;
extern char dj_init(void);
extern void dj_deinit(void);
extern void dj_start(void);
extern void dj_stop(void);
extern void dj_set_nosound(char flag);
extern char dj_set_sd(char sd_type, short port, char irq, char dma);
extern char dj_autodetect_sd(void);
extern void dj_get_sd_string(char *strbuf);
extern char dj_set_stereo(char flag);
extern void dj_reverse_stereo(char flag);
extern void dj_set_auto_mix(char flag);
extern unsigned short dj_set_mixing_freq(unsigned short freq);
extern void dj_set_dma_time(unsigned short time);
extern char dj_get_hardware_info(dj_hardware_info *ptr);
extern char dj_get_mixing_info(dj_mixing_info *ptr);
extern char dj_get_mod_info(char mod_num, dj_mod_info *ptr);
extern void dj_set_fake_vu_speed(unsigned char speed);
extern unsigned char dj_get_fake_vu(char channel);
extern char dj_reset_sd(void);
extern char dj_mix_needed(void);
extern void dj_mix(void);
extern char dj_set_num_sfx_channels(char num_channels);
extern void dj_set_sfx_volume(char volume);
extern char dj_get_sfx_volume(void);
extern void dj_play_sfx(unsigned char sfx_num, unsigned short freq, char volume, char panning, unsigned short delay, char channel);
extern char dj_get_sfx_settings(unsigned char sfx_num, sfx_data *data);
extern char dj_set_sfx_settings(unsigned char sfx_num, sfx_data *data);
extern void dj_set_sfx_channel_volume(char channel_num, char volume);
extern void dj_stop_sfx_channel(char channel_num);
extern char dj_load_sfx(FILE *file_handle, char *filename, int file_length, char sfx_type, unsigned char sfx_num);
extern void dj_free_sfx(unsigned char sfx_num);
extern char dj_ready_mod(char mod_num);
extern char dj_start_mod(void);
extern void dj_stop_mod(void);
extern void dj_set_mod_volume(char volume);
extern char dj_get_mod_volume(void);
extern char dj_load_mod(FILE *file_handle, char *filename, char mod_num);
extern void dj_free_mod(char mod_num);
[GLOBAL _get_block]
[GLOBAL _put_block]
[EXTERN ___djgpp_base_address]
[SECTION .text]
; void get_block(char page, long x, long y, long width, long height, char *buffer);
_get_block
push ebp
mov ebp,esp
pusha
mov eax,[ebp+12]
mov [.x],eax
mov eax,[ebp+16]
mov [.y],eax
mov eax,[ebp+20]
mov [.draw_width],eax
mov eax,[ebp+24]
mov [.draw_height],eax
mov eax,[ebp+28]
mov [.buf_ptr],eax
mov eax,[.x]
or eax,eax
jns .11
neg eax
cmp eax,[ebp+20]
jge near .exit
mov dword [.x],0
sub [.draw_width],eax
add [.buf_ptr],eax
.11
cmp dword [.x],400
jge near .exit
mov eax,[.y]
or eax,eax
jns .12
neg eax
cmp eax,[ebp+24]
jge near .exit
mov dword [.y],0
sub [.draw_height],eax
imul dword [ebp+20]
add [.buf_ptr],eax
.12
cmp eax,256
jge near .exit
mov edi,0xa0000
sub edi,[___djgpp_base_address]
xor eax,eax
mov al,[ebp+8]
shl eax,15
add edi,eax
mov eax,100
imul dword [.y]
add edi,eax
mov [.vga_ptr],edi
mov dword [.c1],0
.1
mov edx,0x3ce
mov eax,[.x]
add eax,[.c1]
shl eax,8
and ah,3
mov al,4
out dx,ax
mov esi,[.vga_ptr]
mov eax,[.x]
add eax,[.c1]
sar eax,2
add esi,eax
mov edi,[.buf_ptr]
add edi,[.c1]
mov ebx,[.draw_height]
.2
mov ecx,[.draw_width]
add ecx,3
sub ecx,[.c1]
shr ecx,2
mov edx,ecx
cmp ecx,0
jle .4
.3
mov al,[esi]
mov [edi],al
inc esi
add edi,4
dec cx
jnz .3
.4
add esi,100
sub esi,edx
add edi,[ebp+20]
mov eax,edx
shl eax,2
sub edi,eax
dec ebx
jnz .2
inc byte [.c1]
cmp byte [.c1],4
jl near .1
.exit
popa
pop ebp
ret
.c1 dd 0
.vga_ptr dd 0
.x dd 0
.y dd 0
.draw_width dd 0
.draw_height dd 0
.buf_ptr dd 0
; void put_block(char page, long x, long y, long width, long height, char *buffer);
_put_block
push ebp
mov ebp,esp
pusha
mov eax,[ebp+12]
mov [.x],eax
mov eax,[ebp+16]
mov [.y],eax
mov eax,[ebp+20]
mov [.draw_width],eax
mov eax,[ebp+24]
mov [.draw_height],eax
mov eax,[ebp+28]
mov [.buf_ptr],eax
mov eax,[.x]
or eax,eax
jns .11
neg eax
cmp eax,[ebp+20]
jge near .exit
mov dword [.x],0
sub [.draw_width],eax
add [.buf_ptr],eax
.11
cmp dword [.x],400
jge near .exit
mov eax,[.y]
or eax,eax
jns .12
neg eax
cmp eax,[ebp+24]
jge near .exit
mov dword [.y],0
sub [.draw_height],eax
imul dword [ebp+20]
add [.buf_ptr],eax
.12
cmp eax,256
jge near .exit
mov edi,0xa0000
sub edi,[___djgpp_base_address]
xor eax,eax
mov al,[ebp+8]
shl eax,15
add edi,eax
mov eax,100
imul dword [.y]
add edi,eax
mov [.vga_ptr],edi
mov dword [.c1],0
.1
mov edx,0x3c4
mov eax,0x100
mov ecx,[.x]
add ecx,[.c1]
and ecx,3
shl eax,cl
mov al,2
out dx,ax
mov esi,[.buf_ptr]
add esi,[.c1]
mov edi,[.vga_ptr]
mov eax,[.x]
add eax,[.c1]
sar eax,2
add edi,eax
mov ebx,[.draw_height]
.2
mov ecx,[.draw_width]
add ecx,3
sub ecx,[.c1]
shr ecx,2
mov edx,ecx
cmp ecx,0
jle .4
.3
mov al,[esi]
mov [edi],al
add esi,4
inc edi
dec ecx
jnz .3
.4
add esi,[ebp+20]
mov eax,edx
shl eax,2
sub esi,eax
add edi,100
sub edi,edx
dec ebx
jnz .2
inc byte [.c1]
cmp byte [.c1],4
jl near .1
.exit
popa
pop ebp
ret
.c1 dd 0
.vga_ptr dd 0
.x dd 0
.y dd 0
.draw_width dd 0
.draw_height dd 0
.buf_ptr dd 0
#include "globals.h"
void open_screen(void) {
__dpmi_regs regs;
char *ptr1;
regs.x.ax = 0x13;
__dpmi_int(0x10, &regs);
outportw(0x3c4, 0x0604);
outportw(0x3c4, 0x0100);
outportb(0x3c2, 0xe7);
outportw(0x3c4, 0x0300);
outportb(0x3d4, 0x11);
outportb(0x3d5, inportb(0x3d5) & 0x7f);
outportw(0x3d4, 0x7100);
outportw(0x3d4, 0x6301);
outportw(0x3d4, 0x6402);
outportw(0x3d4, 0x9203);
outportw(0x3d4, 0x6604);
outportw(0x3d4, 0x8205);
outportw(0x3d4, 0x2b06);
outportw(0x3d4, 0xb207);
outportw(0x3d4, 0x0008);
outportw(0x3d4, 0x6109);
outportw(0x3d4, 0x1310);
outportw(0x3d4, 0xac11);
outportw(0x3d4, 0xff12);
outportw(0x3d4, 0x3213);
outportw(0x3d4, 0x0014);
outportw(0x3d4, 0x0715);
outportw(0x3d4, 0x1a16);
outportw(0x3d4, 0xe317);
outportw(0x3d4, 0x3213);
ptr1 = (char *)(0xa0000 + __djgpp_conventional_base);
outportw(0x3c4, 0x0f02);
memset(ptr1, 0, 65535);
}
void wait_vrt(void) {
while( (inportb(0x3da) & 8) == 0);
while( (inportb(0x3da) & 8) == 8);
}
/*void get_block(char page, short x, short y, short width, short height, char *buffer) {
short c1, c2, c3;
char *buffer_ptr, *vga_ptr;
for (c3 = 0; c3 < 4; c3++) {
outportw(0x3ce, ( ( (x + c3) & 3) << 8) + 0x04);
for (c1 = 0; (c1 + c3) < width; c1 += 4) {
buffer_ptr = &buffer[(c1 + c3) * height];
vga_ptr = (char *)(0xa0000 + ( (long)page << 15) + (long)y * 100 + ( (x + c1 + c3) >> 2) + __djgpp_conventional_base);
for (c2 = 0; c2 < height; c2++) {
*buffer_ptr = *vga_ptr;
buffer_ptr++;
vga_ptr += 100;
}
}
}
}*/
/*void put_block(char page, short x, short y, short width, short height, char *buffer) {
short c1, c2, c3;
char *vga_ptr, *buffer_ptr;
for (c3 = 0; c3 < 4; c3++) {
outportw(0x3c4, ( (1 << ( (x + c3) & 3) ) << 8) + 0x02);
for (c1 = 0; (c1 + c3) < width; c1 += 4) {
vga_ptr = (char *)(0xa0000 + ( (long)page << 15) + (long)y * 100 + ( (x + c1 + c3) >> 2) + __djgpp_conventional_base);
buffer_ptr = &buffer[(c1 + c3) * height];
for (c2 = 0; c2 < height; c2++) {
*vga_ptr = *buffer_ptr;
vga_ptr += 100;
buffer_ptr++;
}
}
}
}*/
void put_text(char page, int x, int y, char *text, char align) {
int c1;
int t1;
int width;
int cur_x;
int image;
if (text == NULL || strlen(text) == 0)
return;
if (font_gobs == NULL)
return;
width = 0;
c1 = 0;
while (text[c1] != 0) {
t1 = text[c1];
c1++;
if (t1 == ' ') {
width += 5;
continue;
}
if (t1 >= 33 && t1 <= 34)
image = t1 - 33;
else if (t1 >= 39 && t1 <= 41)
image = t1 - 37;
else if (t1 >= 44 && t1 <= 59)
image = t1 - 39;
else if (t1 >= 64 && t1 <= 90)
image = t1 - 43;
else if (t1 >= 97 && t1 <= 122)
image = t1 - 49;
else if (t1 == '~')
image = 74;
else if (t1 == '')
image = 75;
else if (t1 == '')
image = 76;
else if (t1 == '')
image = 77;
else if (t1 == '')
image = 78;
else if (t1 == '')
image = 79;
else if (t1 == '')
image = 80;
else
continue;
width += pob_width(image, font_gobs) + 1;
}
switch (align) {
case 0:
cur_x = x;
break;
case 1:
cur_x = x - width;
break;
case 2:
cur_x = x - width / 2;
break;
}
c1 = 0;
while (text[c1] != 0) {
t1 = text[c1];
c1++;
if (t1 == ' ') {
cur_x += 5;
continue;
}
if (t1 >= 33 && t1 <= 34)
image = t1 - 33;
else if (t1 >= 39 && t1 <= 41)
image = t1 - 37;
else if (t1 >= 44 && t1 <= 59)
image = t1 - 39;
else if (t1 >= 64 && t1 <= 90)
image = t1 - 43;
else if (t1 >= 97 && t1 <= 122)
image = t1 - 49;
else if (t1 == '~')
image = 74;
else if (t1 == '')
image = 75;
else if (t1 == '')
image = 76;
else if (t1 == '')
image = 77;
else if (t1 == '')
image = 78;
else if (t1 == '')
image = 79;
else if (t1 == '')
image = 80;
else
continue;
put_pob(page, cur_x, y, image, font_gobs, 1, mask_pic);
cur_x += pob_width(image, font_gobs) + 1;
}
}
void put_pob(char page, short x, short y, short image, char *pob_data, char mask, char *mask_pic) {
long c1, c2, c3;
long pob_offset;
char *pob_ptr, *vga_ptr, *mask_ptr;
long width, height;
long draw_width, draw_height;
char colour;
if (image < 0 || image >= *(short *)(pob_data) )
return;
pob_offset = *(long *)(pob_data + image * 4 + 2);
width = draw_width = *(short *)(pob_data + pob_offset);
height = draw_height = *(short *)(pob_data + pob_offset + 2);
x -= *(short *)(pob_data + pob_offset + 4);
y -= *(short *)(pob_data + pob_offset + 6);
pob_offset += 8;
if ( (x + width) <= 0 || x >= 400)
return;
if ( (y + height) <= 0 || y >= 256)
return;
if (x < 0) {
pob_offset -= x;
draw_width += x;
x = 0;
}
if ( (x + width) > 400)
draw_width -= x + width - 400;
if (y < 0) {
pob_offset += -y * width;
draw_height -= -y;
y = 0;
}
if ( (y + height) > 256)
draw_height -= y + height - 256;
for (c3 = 0; c3 < 4; c3++) {
outportw(0x3c4, ( (1 << ( (x + c3) & 3) ) << 8) + 0x02);
pob_ptr = &pob_data[pob_offset + c3];
vga_ptr = (char *)(0xa0000 + (long)(page << 15) + (long)y * 100L + ( (x + c3) >> 2) + __djgpp_conventional_base);
mask_ptr = (char *)(mask_pic + (long)y * 400L + x + c3);
for (c1 = 0; c1 < draw_height; c1++) {
for (c2 = c3; c2 < draw_width; c2 += 4) {
colour = *mask_ptr;
if (mask == 0 || (mask == 1 && colour == 0) ) {
colour = *pob_ptr;
if (colour != 0)
*vga_ptr = colour;
}
pob_ptr += 4;
vga_ptr++;
mask_ptr += 4;
}
pob_ptr += width - c2 + c3;
vga_ptr += (400 - c2 + c3) >> 2;
mask_ptr += 400 - c2 + c3;
}
}
}
char pob_col(short x1, short y1, short image1, char *pob_data1, short x2, short y2, short image2, char *pob_data2) {
short c1, c2;
long pob_offset1, pob_offset2;
short width1, width2;
short height1, height2;
short check_width, check_height;
char *pob_ptr1, *pob_ptr2;
pob_offset1 = *(long *)(pob_data1 + image1 * 4 + 2);
width1 = *(short *)(pob_data1 + pob_offset1);
height1 = *(short *)(pob_data1 + pob_offset1 + 2);
x1 -= *(short *)(pob_data1 + pob_offset1 + 4);
y1 -= *(short *)(pob_data1 + pob_offset1 + 6);
pob_offset1 += 8;
pob_offset2 = *(long *)(pob_data2 + image2 * 4 + 2);
width2 = *(short *)(pob_data2 + pob_offset2);
height2 = *(short *)(pob_data2 + pob_offset2 + 2);
x2 -= *(short *)(pob_data2 + pob_offset2 + 4);
y2 -= *(short *)(pob_data2 + pob_offset2 + 6);
pob_offset2 += 8;
if (x1 < x2) {
if ( (x1 + width1) <= x2)
return 0;
else if ( (x1 + width1) <= (x2 + width2) ) {
pob_offset1 += x2 - x1;
check_width = x1 + width1 - x2;
}
else {
pob_offset1 += x2 - x1;
check_width = width2;
}
}
else {
if ( (x2 + width2) <= x1)
return 0;
else if ( (x2 + width2) <= (x1 + width1) ) {
pob_offset2 += x1 - x2;
check_width = x2 + width2 - x1;
}
else {
pob_offset2 += x1 - x2;
check_width = width1;
}
}
if (y1 < y2) {
if ( (y1 + height1) <= y2)
return 0;
else if ( (y1 + height1) <= (y2 + height2) ) {
pob_offset1 += (y2 - y1) * width1;
check_height = y1 + height1 - y2;
}
else {
pob_offset1 += (y2 - y1) * width1;
check_height = height2;
}
}