home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Format (Spanish) 4
/
GOLF_CHLNGR.iso
/
setup.new
< prev
next >
Wrap
Text File
|
1995-04-12
|
12KB
|
555 lines
//╔══════════════════════════════════════════════════════════════════════════╗
//║ UPDATE LOG: SETUP.C ║
//║ ║
//║ date update by description ║
//║ ──── ───────── ─────────── ║
//║ ║
//║ ║
//║ ║
//║ ║
//╚══════════════════════════════════════════════════════════════════════════╝
#include <dos.h>
#include <malloc.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include "basics.h"
static int dispinfo_membase = -1;
static int display_mode = -1;
static uchar dispinfo[64];
extern char *block_addr;
extern char *map_addr;
extern int test_cnt;
extern int chk_cnt;
unsigned int joy_xmin = 1024;
unsigned int joy_xmax = 0;
unsigned int joy_ymin = 1024;
unsigned int joy_ymax = 0;
int joy1_x = 0;
int joy1_y = 0;
static short int scrsetup_data2[8] = {
0x0d06, 0x3e07, 0x4109, 0xea10,
0xac11, 0xbf12,
0xe715, 0x0616
};
/****************************************************************************/
void
getout(int error)
{
int n;
remove_midi();
sync();
init_midi();
init_digi(0);
sync();
remove_digi(0);
sync();
remove_midi();
handler(REMOVE, H_TOD);
reset_tod(); // reset the DOS clock to normal speed
handler(REMOVE, H_KEYBOARD);
handler(REMOVE, H_CRITICAL);
handler(REMOVE, H_CTRL_C);
if (display_mode >= 0)
set_display(display_mode);
if (error)
{ // print error if there was one
printf("Error: %s\n", error_txt[(-error)-1]);
if (n = errno)
{
if (n > MAX_DOSERROR)
n = 0;
printf("DOS error: %s\n", dos_error[n]);
}
switch (error)
{
case E_OPEN:
printf("\tFile: %s\n", last_fname);
break;
case E_MEMORY:
case E_DOSMEM:
case E_MEMLUMPS:
printf("Tried to allocate %d bytes\n", last_memsize);
printf("%d other memory chunk%s allocated:-\n",
memlumps, memlumps==1 ? "" : "s");
for (n = 0; n < memlumps; n++)
printf("\tSize:\t%d\tAddr: %d\n", memdata[n][1], memdata[n][0]);
break;
case E_IO:
printf("\tFile: %s\n",
file_names[last_handle]);
break;
case E_CREATE:
printf("\tFile: %s\n",
last_fname);
break;
case E_TOOMANY:
printf("\tFiles:-\n");
for (n = 0; n < MAX_FILES; n++)
if (file_names[n])
printf("\t\t%s\n", file_names[n]);
break;
break;
}
printf("\n");
}
for (n = 0; n < MAX_FILES; n++)
if (file_names[n])
{
printf("Closing file %s\n", file_names[n]);
close(n);
}
freemem(); // free all memory allocated
reset_clock();
exit(0); // goodbye
}
/****************************************************************************/
void
save_display()
{
union REGS regs;
uint size;
dispinfo_membase = memlumps;
regs.w.ax = 0x1c00;
regs.w.cx = 7;
int386(0x10, ®s, ®s);
size = (uint) (regs.w.bx << 6);
if ((regs.x.ebx = (uint) getmem(size)) == (uint) NULL)
getout(E_MEMORY);
regs.w.ax = 0x1c01;
regs.w.cx = 7;
int386(0x10, ®s, ®s);
}
/****************************************************************************/
void
restore_display()
{
union REGS regs;
regs.w.ax = 0x1c02;
regs.w.cx = 7;
regs.x.ebx = (uint) memdata[dispinfo_membase][0];
int386(0x10, ®s, ®s);
}
/****************************************************************************/
void
get_dispmode()
{
union REGS regs;
regs.h.ah = 0x0f;
int386(0x10, ®s, ®s);
display_mode = regs.h.al;
}
/****************************************************************************/
void
set_display(int mode)
{
union REGS regs;
regs.w.ax = mode;
int386(0x10, ®s, ®s);
}
/****************************************************************************/
void
get_dispinfo()
{
union REGS regs;
regs.w.ax = 0x1b00;
regs.w.bx = 0;
regs.x.edi = (uint) dispinfo;
int386(0x10, ®s, ®s);
}
/****************************************************************************/
void
set_palette()
{
fade_to_pal(60, game_palette);
}
/****************************************************************************/
void
wipe_palette()
{
fade_to_col(1, 0);
}
/****************************************************************************/
/* // the setup for strange screen mode goes like this:-
; sequencer register
set no odd/even, set extended mem
do synchrous reset
; misc. output register
set 480 lines, set no odd/even, set 640 columns, enable display ram, color IO
; sequencer register
clear synchrous reset
; CRT controller register
clear write protect on regs 0-7
vertical total = 0d
overflow = 3e
max. scan line = 41
vert. retrace start = ea
vert. retrace end = ac
vert. display end = df
vert. display end = df
clear doubleword mode and count by 4
vert. blank start = e7
vert. blank end = 06
enable retrace, set byte mode and address wrap, clear CGA&Hercules compatible
; sequencer register
enable write to plane 1
*/
void ext_screen()
{
int n;
outp(0x3d4,0x10);
outp(0x3d5, (inp(0x3d5))|128);
outp(0x3c2, 0xe3);
outp(0x3d4, 0x11);
outp(0x3d5, inp(0x3d5)&0x7f);
for (n=0; n<8; n++)
outpw(0x3d4, scrsetup_data2[n]);
outp(0x3d4, 0x11);
outp(0x3d5, inp(0x3d5)&0x7f);
outp(0x3d4, 0);
outp(0x3d5, 95);
outp(0x3d4, 1);
outp(0x3d5, 79-8);
outp(0x3d4, 2);
outp(0x3d5, 80-8);
outp(0x3d4, 3);
outp(0x3d5, 130+0);
outp(0x3d4, 4);
outp(0x3d5, 84-4);
outp(0x3d4, 5);
outp(0x3d5, 128+0);
outp(0x3d4, 0x13);
outp(0x3d5, 36);
inp(0x3da); /* initialize attribute controller */
}
/****************************************************************************/
/*void calibrate_joysticks(void)
{
int left, right, up, down;
int joy;
int jx, jy;
int time = 0;
sword *ptr = &joy1_lscale;
sword *ptr2 = &joy1_lthresh;
int n, totx, toty;
joy_timeout = 10000; // large timeout value
joy_mask = 15; // read both joysticks
joy_check = 1; // indicate joystick calibration in progress
for (joy=0; joy<2; joy++)
{ // do both joysticks
keydata->keymap[K_ESC] = 0; // debounce escape key
left = 20000; // impossible start values
right = 0;
up = 20000;
down = 0;
for (;;)
{
sync();
read_joy();
#if DEBUGGING==1
keydata->last_key = get_key();
clear_keyb();
#endif
if (joy==0)
{ // get current joystick x and y counts
jx = joy1_xc;
jy = joy1_yc;
}
else
{
jx = joy2_xc;
jy = joy2_yc;
}
if (jx==0) // if reader can't read joystick, quit loop
break;
ifkey(K_ESC) // quit on escape key
break;
if (jx < left) // detemine any new min or max values
left = jx;
if (jx > right)
right = jx;
if (jy < up)
up = jy;
if (jy > down)
down = jy;
copysource = backscr; // copy screen over
copydest = (char *)MCGA_RAM;
dump_screen();
copydest = backscr; // clear back screen
clr_screen();
print(0, 0, "Joystick Calibration");
print(0, 20, "Move joystick %d to all extents, then release to centre", joy+1);
print(0, 32, "Left:%d\nUp:%d\nRight:%d\nDown:%d",
left, up, right, down);
print(0, 80, "Press Esc when finished");
}
if (jx)
{ // if joystick is present
n = right > down ? right : down; // set n to largest count
if (n > time)
time = n; // set timeout value;
totx = 0;
toty = 0;
for (n = 1; n <= 256; n++) { // read centre counts lots of times
read_joy();
if (joy)
{
totx += joy2_xc;
toty += joy2_yc;
}
else
{
totx += joy1_xc;
toty += joy1_yc;
}
}
jx = totx >> 8; // calculate average centre counts;
jy = toty >> 8;
n = jx-left;
*ptr++ = (16*1024)/n; // set left scaling value
*ptr2++ = -n/6; // set left threshold
n = right-jx;
*ptr2++ = n/4; // set right threshold
n -= n>>3;
*ptr++ = (16*1024)/n; // set right scaling value
n = jy-up;
*ptr++ = (16*1024)/n; // set up scaling value
*ptr2++ = -n/6; // set up threshold
n = down-jy;
*ptr2++ = n/5; // set down threshold
n -= n>>3;
*ptr++ = (16*1024)/n; // set down scaling value
*ptr++ = jx; // set x-centre
*ptr++ = jy; // set y-centre
ptr = &joy2_lscale; // point to joy2 scaling data
ptr2 = &joy2_lthresh; // point to joy2 threshold data
}
}
joy_check = 0; // finished joystick calibration
joy_timeout = time+(time>>3); // set maximum timeout value needed
copydest = (char *)MCGA_RAM;
clr_screen();
} */
/****************************************************************************/
void init_vbl(void) // synchronises the dos clock with the vertical retrace
{
if(scrxsize == 320)
{
toddata->clk_splits[0] = (calc_vbltimer()-400);
}
else
{
toddata->clk_splits[0] = (calc_vbltimer()-300);
}
toddata->no_splits = 1;
init_tod();
}
/****************************************************************************/
int setup(void)
{
int i;
get_dispmode(); // remember current state of display
get_dispinfo();
set_display(0x13); // MCGA mode please
if(scrxsize == 288)
{
ext_screen(); // set strange screen mode
}
txt_screen = (char *)MCGA_RAM; // set vars for text print routine
txt_linewid = scrxsize;
txt_linewid8 = scrxsize*8;
txt_col = 1;
handler(INSTALL, H_CTRL_C); // program break interrup -> iret
handler(INSTALL, H_CRITICAL); // critical error handler
handler(INSTALL, H_KEYBOARD); // keyboard handler
handler(INSTALL, H_TOD); // dos clock handler (pretend vbl)
init_vbl(); // synchronise with vbl
sync();
sync();
chk_cnt = test_cnt * 4; //setup fall through counter
if ((backscr = (char *) getmem((uint) 65536)) == (char *) NULL)
getout(E_MEMORY);
copydest = backscr;
clr_screen();
game_palette[1][0] = 0;
game_palette[1][1] = 63;
game_palette[1][2] = 63;
set_palette();
txt_screen = backscr;
txt_col = 1;
/* calibrate_joysticks();*/
// mouse_buttons = init_mouse();
if (!(mouse_buttons = init_mouse()))
return E_NOMOUSE; // return error if no mouse installed
return 0; // return no error
}
/****************************************************************************/
void
_waitvbl(int i)
{
while(i > 0)
{
sync();
i--;
}
return;
}
/****************************************************************************/
void
read_joy(void)
{
int x_scale, y_scale, x_size, y_size;
if(joy_flag != NULL)
{
if(joy_x < joy_xmin) //if calibrated wrong,
joy_xmin = joy_x; //re-calib during game
if(joy_x > joy_xmax)
joy_xmax = joy_x;
if(joy_y < joy_ymin)
joy_ymin = joy_y;
if(joy_y > joy_ymax)
joy_ymax = joy_y;
x_size = joy_xmax - joy_xmin;
y_size = joy_ymax - joy_ymin;
x_scale = x_size >> 5; // div 16
y_scale = y_size >> 5;
if(x_scale != NULL)
joy1_x = joy_x / x_scale;
if(y_scale != NULL)
joy1_y = joy_y / y_scale;
joy1_x -= 16; // -16 to +16
joy1_y -= 16;
if(joy1_x < -16) //fix boundaries
joy1_x = -16;
if(joy1_x > 16)
joy1_x = 16;
if(joy1_y < -16)
joy1_y = -16;
if(joy1_y > 16)
joy1_y = 16;
}
joy_flag = 1; //turn joy back on if got turned off
//ie not in or pulled out of port
return;
}
/****************************************************************************/