From e48b834f720b4edcfac4eb3a7886ddd06d171ff4 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Mon, 29 Jan 2001 13:36:14 +0000 Subject: [PATCH] Removed duplicate files --- arch/dos/Makefile.am | 5 +- arch/dos/cdrom.c | 77 ---- arch/dos/digi.c | 810 ------------------------------------ arch/dos/dosgr.c | 724 -------------------------------- arch/dos/dpmi.c | 398 ------------------ arch/dos/findfile.c | 95 ----- arch/dos/init.c | 369 ----------------- arch/dos/ipx.c | 908 ----------------------------------------- arch/dos/joy2.asm | 471 --------------------- arch/dos/joyc.c | 802 ------------------------------------ arch/dos/joydefs.c | 673 ------------------------------ arch/dos/key.c | 709 -------------------------------- arch/dos/modex.asm | 829 ------------------------------------- arch/dos/mouse.c | 655 ----------------------------- arch/dos/timer.asm | 496 ---------------------- arch/dos/tweak.inc | 258 ------------ arch/dos/vesa.c | 140 ------- arch/dos/vgaregs.inc | 62 --- arch/include/joy.h | 8 +- arch/linux/Makefile.am | 4 +- arch/linux/findfile.c | 58 --- arch/linux/init.c | 51 --- arch/linux/ipx_bsd.c | 230 ----------- arch/linux/ipx_lin.c | 218 ---------- arch/linux/ipx_udp.c | 593 --------------------------- arch/linux/linuxnet.c | 368 ----------------- arch/sdl/Makefile.am | 2 - arch/sdl/init.c | 29 -- arch/sdl/timer.c | 13 - 29 files changed, 7 insertions(+), 10048 deletions(-) delete mode 100644 arch/dos/cdrom.c delete mode 100644 arch/dos/digi.c delete mode 100644 arch/dos/dosgr.c delete mode 100644 arch/dos/dpmi.c delete mode 100644 arch/dos/findfile.c delete mode 100644 arch/dos/init.c delete mode 100644 arch/dos/ipx.c delete mode 100644 arch/dos/joy2.asm delete mode 100644 arch/dos/joyc.c delete mode 100644 arch/dos/joydefs.c delete mode 100644 arch/dos/key.c delete mode 100644 arch/dos/modex.asm delete mode 100644 arch/dos/mouse.c delete mode 100644 arch/dos/timer.asm delete mode 100644 arch/dos/tweak.inc delete mode 100644 arch/dos/vesa.c delete mode 100644 arch/dos/vgaregs.inc delete mode 100644 arch/linux/findfile.c delete mode 100644 arch/linux/init.c delete mode 100644 arch/linux/ipx_bsd.c delete mode 100644 arch/linux/ipx_lin.c delete mode 100644 arch/linux/ipx_udp.c delete mode 100644 arch/linux/linuxnet.c delete mode 100644 arch/sdl/Makefile.am delete mode 100644 arch/sdl/init.c delete mode 100644 arch/sdl/timer.c diff --git a/arch/dos/Makefile.am b/arch/dos/Makefile.am index e1000169..a2d4309d 100644 --- a/arch/dos/Makefile.am +++ b/arch/dos/Makefile.am @@ -1,8 +1,5 @@ SUBDIRS = allg_snd bak comm include mm_snd EXTRA_DIST = \ -joy2.asm modex.asm timer.asm \ -tweak.inc vgaregs.inc \ ipx.h mono.h \ -bcd.c cdrom.c digi.c digiallg.c digimm.c disk.c dosgr.c dpmi.c findfile.c \ -init.c ipx.c joyc.c joydefs.c key.c midiallg.c mono.c mouse.c serial.c vesa.c +bcd.c digiallg.c digimm.c disk.c midiallg.c mono.c serial.c diff --git a/arch/dos/cdrom.c b/arch/dos/cdrom.c deleted file mode 100644 index 7d92839a..00000000 --- a/arch/dos/cdrom.c +++ /dev/null @@ -1,77 +0,0 @@ -/* DPH: This is the file where all the stub functions go. The aim is to have nothing in here ,eventually */ -#include -#include -#include -#include "pstypes.h" -#include "error.h" -#include "args.h" - - -extern int Redbook_playing; -static int initialised = 0; - -void RBAExit() -{ -} - -void RBAInit() -{ - -} - -int RBAEnabled() -{ - return 1; -} - -void RBARegisterCD() -{ - -} - -int RBAPlayTrack(int a) -{ -return 0; -} - -void RBAStop() -{ -} - -void RBASetVolume(int a) -{ - -} - -void RBAPause() -{ -} - -void RBAResume() -{ -} - -int RBAGetNumberOfTracks() -{ -return 0; -} - -int RBAPlayTracks(int tracknum,int something) -{ -return -1; -} - -int RBAGetTrackNum() -{ -return -1; -} - -int RBAPeekPlayStatus() -{ - return -1; -} - -int CD_blast_mixer() -{ - return 0; -} diff --git a/arch/dos/digi.c b/arch/dos/digi.c deleted file mode 100644 index d224d970..00000000 --- a/arch/dos/digi.c +++ /dev/null @@ -1,810 +0,0 @@ -// SDL digital audio support - -#include -#include -#include -#include - -#include "pstypes.h" -#include "error.h" -#include "mono.h" -#include "fix.h" -#include "vecmat.h" -#include "gr.h" // needed for piggy.h -#include "piggy.h" -#include "digi.h" -#include "sounds.h" -#include "wall.h" -#include "newdemo.h" -#include "kconfig.h" - -int digi_sample_rate=11025; -int digi_timer_rate = 9943; // rate for the timer to go off to handle the driver system (120 Hz) - -//edited 05/17/99 Matt Mueller - added ifndef NO_ASM -//added on 980905 by adb to add inline fixmul for mixer on i386 -#ifndef NO_ASM -#ifdef __i386__ -#define do_fixmul(x,y) \ -({ \ - int _ax, _dx; \ - asm("imull %2\n\tshrdl %3,%1,%0" \ - : "=a"(_ax), "=d"(_dx) \ - : "rm"(y), "i"(16), "0"(x)); \ - _ax; \ -}) -extern inline fix fixmul(fix x, fix y) { return do_fixmul(x,y); } -#endif -#endif -//end edit by adb -//end edit -MM - -//changed on 980905 by adb to increase number of concurrent sounds -#define MAX_SOUND_SLOTS 32 -//end changes by adb -#define SOUND_BUFFER_SIZE 512 - -#define MIN_VOLUME 10 - -/* This table is used to add two sound values together and pin - * the value to avoid overflow. (used with permission from ARDI) - * DPH: Taken from SDL/src/SDL_mixer.c. - */ -static const unsigned char mix8[] = -{ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, - 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, - 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, - 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, - 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, - 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, - 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, - 0x5C, 0x5D, 0x5E, 0x5F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, - 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, - 0x7D, 0x7E, 0x7F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, - 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0x90, 0x91, 0x92, - 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, - 0x9E, 0x9F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, - 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xB0, 0xB1, 0xB2, 0xB3, - 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, - 0xBF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, - 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, - 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF, - 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, - 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, - 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, -}; - -#define SOF_USED 1 // Set if this sample is used -#define SOF_PLAYING 2 // Set if this sample is playing on a channel -#define SOF_LINK_TO_OBJ 4 // Sound is linked to a moving object. If object dies, then finishes play and quits. -#define SOF_LINK_TO_POS 8 // Sound is linked to segment, pos -#define SOF_PLAY_FOREVER 16 // Play forever (or until level is stopped), otherwise plays once - -typedef struct sound_object { - short signature; // A unique signature to this sound - ubyte flags; // Used to tell if this slot is used and/or currently playing, and how long. - fix max_volume; // Max volume that this sound is playing at - fix max_distance; // The max distance that this sound can be heard at... - int volume; // Volume that this sound is playing at - int pan; // Pan value that this sound is playing at - int handle; // What handle this sound is playing on. Valid only if SOF_PLAYING is set. - short soundnum; // The sound number that is playing - union { - struct { - short segnum; // Used if SOF_LINK_TO_POS field is used - short sidenum; - vms_vector position; - }pos; - struct { - short objnum; // Used if SOF_LINK_TO_OBJ field is used - short objsignature; - }obj; - }link; -} sound_object; -#define lp_segnum link.pos.segnum -#define lp_sidenum link.pos.sidenum -#define lp_position link.pos.position - -#define lo_objnum link.obj.objnum -#define lo_objsignature link.obj.objsignature - -#define MAX_SOUND_OBJECTS 16 -sound_object SoundObjects[MAX_SOUND_OBJECTS]; -short next_signature=0; - -//added/changed on 980905 by adb to make sfx volume work, on 990221 by adb changed F1_0 to F1_0 / 2 -#define SOUND_MAX_VOLUME (F1_0 / 2) - -int digi_volume = SOUND_MAX_VOLUME; -//end edit by adb - -int digi_lomem = 0; - -static int digi_initialised = 0; - -struct sound_slot { - int soundno; - int playing; // Is there a sample playing on this channel? - int looped; // Play this sample looped? - fix pan; // 0 = far left, 1 = far right - fix volume; // 0 = nothing, 1 = fully on - //changed on 980905 by adb from char * to unsigned char * - unsigned char *samples; - //end changes by adb - unsigned int length; // Length of the sample - unsigned int position; // Position we are at at the moment. -} SoundSlots[MAX_SOUND_SLOTS]; - -static int digi_sounds_initialized = 0; - -//added on 980905 by adb to add rotating/volume based sound kill system -static int digi_max_channels = 16; -static int next_handle = 0; -int SampleHandles[32]; -void reset_sounds_on_channel(int channel); -//end edit by adb - -void digi_reset_digi_sounds(void); - -/* Audio mixing callback */ -//changed on 980905 by adb to cleanup, add pan support and optimize mixer -static void audio_mixcallback(void *userdata, unsigned char *stream, int len) -{ - unsigned char *streamend = stream + len; - struct sound_slot *sl; - - for (sl = SoundSlots; sl < SoundSlots + MAX_SOUND_SLOTS; sl++) - { - if (sl->playing) - { - unsigned char *sldata = sl->samples + sl->position, *slend = sl->samples + sl->length; - unsigned char *sp = stream; - signed char v; - fix vl, vr; - int x; - - if ((x = sl->pan) & 0x8000) - { - vl = 0x20000 - x * 2; - vr = 0x10000; - } - else - { - vl = 0x10000; - vr = x * 2; - } - vl = fixmul(vl, (x = sl->volume)); - vr = fixmul(vr, x); - while (sp < streamend) - { - if (sldata == slend) - { - if (!sl->looped) - { - sl->playing = 0; - break; - } - sldata = sl->samples; - } - v = *(sldata++) - 0x80; - *(sp++) = mix8[ *sp + fixmul(v, vl) + 0x80 ]; - *(sp++) = mix8[ *sp + fixmul(v, vr) + 0x80 ]; - } - sl->position = sldata - sl->samples; - } - } -} -//end changes by adb - -/* Initialise audio devices. */ -int digi_init() -{ - - return 1; -} - -/* Toggle audio */ -void digi_reset() { } - -/* Shut down audio */ -void digi_close() -{ - if (!digi_initialised) return; - digi_initialised = 0; -} - -/* Find the sound which actually equates to a sound number */ -int digi_xlat_sound(int soundno) -{ - if ( soundno < 0 ) return -1; - - if ( digi_lomem ) { - soundno = AltSounds[soundno]; - if ( soundno == 255 ) return -1; - } - return Sounds[soundno]; -} - -static int get_free_slot() -{ - int i; - for (i=0; i= 0) && (SoundSlots[SampleHandles[next_handle]].playing) ) - { - if ( (SoundSlots[SampleHandles[next_handle]].volume > digi_volume) && (ntries= digi_max_channels ) - next_handle = 0; - ntries++; - goto TryNextChannel; - } - //mprintf(( 0, "[SS:%d]", next_handle )); - SoundSlots[SampleHandles[next_handle]].playing = 0; - SampleHandles[next_handle] = -1; - } - //end edit by adb - - slot = get_free_slot(); - if (slot<0) return -1; - - SoundSlots[slot].soundno = soundnum; - SoundSlots[slot].samples = GameSounds[soundnum].data; - SoundSlots[slot].length = GameSounds[soundnum].length; - SoundSlots[slot].volume = fixmul(digi_volume, volume); - SoundSlots[slot].pan = pan; - SoundSlots[slot].position = 0; - SoundSlots[slot].looped = 0; - SoundSlots[slot].playing = 1; - - //added on 980905 by adb to add sound kill system from original sos digi.c - reset_sounds_on_channel(slot); - SampleHandles[next_handle] = slot; - next_handle++; - if ( next_handle >= digi_max_channels ) - next_handle = 0; - //end edit by adb - - return slot; -} - - //added on 980905 by adb to add sound kill system from original sos digi.c -void reset_sounds_on_channel( int channel ) -{ - int i; - - for (i=0; i -1 ) { - *volume = max_volume - fixdiv(path_distance,max_distance); - //mprintf( (0, "Sound path distance %.2f, volume is %d / %d\n", f2fl(distance), *volume, max_volume )); - if (*volume > 0 ) { - angle_from_ear = vm_vec_delta_ang_norm(&listener->rvec,&vector_to_sound,&listener->uvec); - fix_sincos(angle_from_ear,&sinang,&cosang); - //mprintf( (0, "volume is %.2f\n", f2fl(*volume) )); - if (Config_channels_reversed) cosang *= -1; - *pan = (cosang + F1_0)/2; - } else { - *volume = 0; - } - } - } -} - -int digi_link_sound_to_object2( int org_soundnum, short objnum, int forever, fix max_volume, fix max_distance ) -{ - int i,volume,pan; - object * objp; - int soundnum; - - soundnum = digi_xlat_sound(org_soundnum); - - if ( max_volume < 0 ) return -1; -// if ( max_volume > F1_0 ) max_volume = F1_0; - - if (!digi_initialised) return -1; - if (soundnum < 0 ) return -1; - if (GameSounds[soundnum].data==NULL) { - Int3(); - return -1; - } - if ((objnum<0)||(objnum>Highest_object_index)) - return -1; - - if ( !forever ) { - // Hack to keep sounds from building up... - digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, &Objects[objnum].pos, Objects[objnum].segnum, max_volume,&volume, &pan, max_distance ); - digi_play_sample_3d( org_soundnum, pan, volume, 0 ); - return -1; - } - - for (i=0; iorient, &Viewer->pos, Viewer->segnum, - &objp->pos, objp->segnum, SoundObjects[i].max_volume, - &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance ); - - if (!forever || SoundObjects[i].volume >= MIN_VOLUME) - digi_start_sound_object(i); - - return SoundObjects[i].signature; -} - -int digi_link_sound_to_object( int soundnum, short objnum, int forever, fix max_volume ) -{ return digi_link_sound_to_object2( soundnum, objnum, forever, max_volume, 256*F1_0); } - -int digi_link_sound_to_pos2( int org_soundnum, short segnum, short sidenum, vms_vector * pos, int forever, fix max_volume, fix max_distance ) -{ - int i, volume, pan; - int soundnum; - - soundnum = digi_xlat_sound(org_soundnum); - - if ( max_volume < 0 ) return -1; -// if ( max_volume > F1_0 ) max_volume = F1_0; - - if (!digi_initialised) return -1; - if (soundnum < 0 ) return -1; - if (GameSounds[soundnum].data==NULL) { - Int3(); - return -1; - } - - if ((segnum<0)||(segnum>Highest_segment_index)) - return -1; - - if ( !forever ) { - // Hack to keep sounds from building up... - digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, pos, segnum, max_volume, &volume, &pan, max_distance ); - digi_play_sample_3d( org_soundnum, pan, volume, 0 ); - return -1; - } - - for (i=0; iorient, &Viewer->pos, Viewer->segnum, - &SoundObjects[i].lp_position, SoundObjects[i].lp_segnum, - SoundObjects[i].max_volume, - &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance ); - - if (!forever || SoundObjects[i].volume >= MIN_VOLUME) - digi_start_sound_object(i); - - return SoundObjects[i].signature; -} - -int digi_link_sound_to_pos( int soundnum, short segnum, short sidenum, vms_vector * pos, int forever, fix max_volume ) -{ - return digi_link_sound_to_pos2( soundnum, segnum, sidenum, pos, forever, max_volume, F1_0 * 256 ); -} - -void digi_kill_sound_linked_to_segment( int segnum, int sidenum, int soundnum ) -{ - int i,killed; - - soundnum = digi_xlat_sound(soundnum); - - if (!digi_initialised) return; - - killed = 0; - - for (i=0; i 1 ) { - mprintf( (1, "ERROR: More than 1 sounds were deleted from seg %d\n", segnum )); - } -} - -void digi_kill_sound_linked_to_object( int objnum ) -{ - int i,killed; - - if (!digi_initialised) return; - - killed = 0; - - for (i=0; i 1 ) { - mprintf( (1, "ERROR: More than 1 sounds were deleted from object %d\n", objnum )); - } -} - -void digi_sync_sounds() -{ - int i; - int oldvolume, oldpan; - - if (!digi_initialised) return; - - for (i=0; iorient, &Viewer->pos, Viewer->segnum, - &SoundObjects[i].lp_position, SoundObjects[i].lp_segnum, - SoundObjects[i].max_volume, - &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance ); - - } else if ( SoundObjects[i].flags & SOF_LINK_TO_OBJ ) { - object * objp; - - objp = &Objects[SoundObjects[i].lo_objnum]; - - if ((objp->type==OBJ_NONE) || (objp->signature!=SoundObjects[i].lo_objsignature)) { - // The object that this is linked to is dead, so just end this sound if it is looping. - if ( (SoundObjects[i].flags & SOF_PLAYING) && (SoundObjects[i].flags & SOF_PLAY_FOREVER)) { - SoundSlots[SoundObjects[i].handle].playing = 0; - } - SoundObjects[i].flags = 0; // Mark as dead, so some other sound can use this sound - continue; // Go on to next sound... - } else { - digi_get_sound_loc( &Viewer->orient, &Viewer->pos, Viewer->segnum, - &objp->pos, objp->segnum, SoundObjects[i].max_volume, - &SoundObjects[i].volume, &SoundObjects[i].pan, SoundObjects[i].max_distance ); - } - } - - if (oldvolume != SoundObjects[i].volume) { - if ( SoundObjects[i].volume < MIN_VOLUME ) { - // Sound is too far away, so stop it from playing. - if ((SoundObjects[i].flags & SOF_PLAYING)&&(SoundObjects[i].flags & SOF_PLAY_FOREVER)) { - SoundSlots[SoundObjects[i].handle].playing = 0; - SoundObjects[i].flags &= ~SOF_PLAYING; // Mark sound as not playing - } - } else { - if (!(SoundObjects[i].flags & SOF_PLAYING)) { - digi_start_sound_object(i); - } else { - SoundSlots[SoundObjects[i].handle].volume = fixmuldiv(SoundObjects[i].volume,digi_volume,F1_0); - } - } - } - - if (oldpan != SoundObjects[i].pan) { - if (SoundObjects[i].flags & SOF_PLAYING) - SoundSlots[SoundObjects[i].handle].pan = SoundObjects[i].pan; - } - } - } -} - -void digi_init_sounds() -{ - int i; - - if (!digi_initialised) return; - - digi_reset_digi_sounds(); - - for (i=0; i SOUND_MAX_VOLUME ) - digi_volume = SOUND_MAX_VOLUME; - else if ( dvolume < 0 ) - digi_volume = 0; - else - digi_volume = dvolume; - - if ( !digi_initialised ) return; - - digi_sync_sounds(); -} -//end edit by adb - -void digi_set_volume( int dvolume, int mvolume ) { } - -int digi_is_sound_playing(int soundno) -{ - int i; - - soundno = digi_xlat_sound(soundno); - - for (i = 0; i < MAX_SOUND_SLOTS; i++) - //changed on 980905 by adb: added SoundSlots[i].playing && - if (SoundSlots[i].playing && SoundSlots[i].soundno == soundno) - //end changes by adb - return 1; - return 0; -} - - -void digi_pause_all() { } -void digi_resume_all() { } -void digi_stop_all() { } - - //added on 980905 by adb to make sound channel setting work -void digi_set_max_channels(int n) { - digi_max_channels = n; - - if ( digi_max_channels < 1 ) - digi_max_channels = 1; - if ( digi_max_channels > (MAX_SOUND_SLOTS-MAX_SOUND_OBJECTS) ) - digi_max_channels = (MAX_SOUND_SLOTS-MAX_SOUND_OBJECTS); - - if ( !digi_initialised ) return; - - digi_reset_digi_sounds(); -} - -int digi_get_max_channels() { - return digi_max_channels; -} -// end edit by adb - -void digi_reset_digi_sounds() { - int i; - - for (i=0; i< MAX_SOUND_SLOTS; i++) - SoundSlots[i].playing=0; - - //added on 980905 by adb to reset sound kill system - memset(SampleHandles, 255, sizeof(SampleHandles)); - next_handle = 0; - //end edit by adb -} - - -// MIDI stuff follows. -//added/killed on 11/25/98 by Matthew Mueller -//void digi_set_midi_volume( int mvolume ) { } -//void digi_play_midi_song( char * filename, char * melodic_bank, char * drum_bank, int loop ) {} -//void digi_stop_current_song() -//{ -//#ifdef HMIPLAY -// char buf[10]; -// -// sprintf(buf,"s"); -// send_ipc(buf); -//#endif -//} -//end this section kill - MM diff --git a/arch/dos/dosgr.c b/arch/dos/dosgr.c deleted file mode 100644 index 24724d68..00000000 --- a/arch/dos/dosgr.c +++ /dev/null @@ -1,724 +0,0 @@ -// Graphics functions for DOS. - -#include - -#include -#include -#include -#include -#include -#include "gr.h" -#include "grdef.h" -#include "palette.h" -#include "maths.h" -#include "u_mem.h" -#include "u_dpmi.h" -#include "vesa.h" -#include "modex.h" -#include "error.h" - -#ifdef __DJGPP__ -#include -#endif - -static int last_r=0, last_g=0, last_b=0; - -/* old gr.c stuff */ -unsigned char * gr_video_memory = (unsigned char *)0xa0000; - -char gr_pal_default[768]; - -int gr_installed = 0; - -volatile ubyte * pVideoMode = (volatile ubyte *)0x449; -volatile ushort * pNumColumns = (volatile ushort *)0x44a; -volatile ubyte * pNumRows = (volatile ubyte *)0x484; -volatile ushort * pCharHeight = (volatile ushort *)0x485; -volatile ushort * pCursorPos = (volatile ushort *)0x450; -volatile ushort * pCursorType = (volatile ushort *)0x460; -volatile ushort * pTextMemory = (volatile ushort *)0xb8000; - -typedef struct screen_save { - ubyte video_mode; - ubyte is_graphics; - ushort char_height; - ubyte width; - ubyte height; - ubyte cursor_x, cursor_y; - ubyte cursor_sline, cursor_eline; - ushort * video_memory; -} screen_save; - -screen_save gr_saved_screen; - -int gr_show_screen_info = 0; -extern int VGA_current_mode; - -void gr_set_cellheight( ubyte height ) -{ - ubyte temp; - - outp( 0x3d4, 9 ); - temp = inp( 0x3d5 ); - temp &= 0xE0; - temp |= height; - outp( 0x3d5, temp ); -} - -void gr_set_linear() -{ - outpw( 0x3c4, 0xE04 ); // enable chain4 mode - outpw( 0x3d4, 0x4014 ); // turn on dword mode - outpw( 0x3d4, 0xa317 ); // turn off byte mode -} - -void gr_16_to_256() -{ - outpw( 0x3ce, 0x4005 ); // set Shift reg to 1 - - inp( 0x3da ); // dummy input - - outp( 0x3c0, 0x30 ); - outp( 0x3c0, 0x61 ); // turns on PCS & PCC - - inp( 0x3da ); // dummy input - - outp( 0x3c0, 0x33 ); - outp( 0x3c0, 0 ); -} - -void gr_turn_screen_off() -{ - ubyte temp; - temp = inp( 0x3da ); - outp( 0x3c0, 0 ); -} - -void gr_turn_screen_on() -{ - ubyte temp; - temp = inp( 0x3da ); - outp( 0x3c0, 0x20 ); -} - -void gr_set_misc_mode( uint mode ) -{ - union REGS regs; - - memset( ®s, 0, sizeof(regs) ); - regs.w.ax = mode; - int386( 0x10, ®s, ®s ); - -} - -void gr_set_3dbios_mode( uint mode ) -{ - union REGS regs; - memset( ®s, 0, sizeof(regs) ); - regs.w.ax = 0x4fd0; - regs.w.bx = 0x3d00 | (mode & 0xff); - int386( 0x10, ®s, ®s ); -} - - - -void gr_set_text_25() -{ - union REGS regs; - - regs.w.ax = 3; - int386( 0x10, ®s, ®s ); - -} - -void gr_set_text_43() -{ - union REGS regs; - - regs.w.ax = 0x1201; - regs.w.bx = 0x30; - int386( 0x10, ®s, ®s ); - - regs.w.ax = 3; - int386( 0x10, ®s, ®s ); - - regs.w.ax = 0x1112; - regs.w.bx = 0x0; - int386( 0x10, ®s, ®s ); -} - -void gr_set_text_50() -{ - union REGS regs; - - regs.w.ax = 0x1202; - regs.w.bx = 0x30; - int386( 0x10, ®s, ®s ); - - regs.w.ax = 3; - int386( 0x10, ®s, ®s ); - - regs.w.ax = 0x1112; - regs.w.bx = 0x0; - int386( 0x10, ®s, ®s ); -} - -ubyte is_graphics_mode() -{ - byte tmp; - tmp = inp( 0x3DA ); // Reset flip-flip - outp( 0x3C0, 0x30 ); // Select attr register 10 - tmp = inp( 0x3C1 ); // Get graphics/text bit - return tmp & 1; -} - -void gr_setcursor(ubyte x, ubyte y, ubyte sline, ubyte eline) -{ - union REGS regs; - - memset( ®s, 0, sizeof(regs) ); - regs.w.ax = 0x0200; - regs.w.bx = 0; - regs.h.dh = y; - regs.h.dl = x; - int386( 0x10, ®s, ®s ); - - memset( ®s, 0, sizeof(regs) ); - regs.w.ax = 0x0100; - regs.h.ch = sline & 0xf; - regs.h.cl = eline & 0xf; - int386( 0x10, ®s, ®s ); -} - -void gr_getcursor(ubyte *x, ubyte *y, ubyte * sline, ubyte * eline) -{ - union REGS regs; - - memset( ®s, 0, sizeof(regs) ); - regs.w.ax = 0x0300; - regs.w.bx = 0; - int386( 0x10, ®s, ®s ); - *y = regs.h.dh; - *x = regs.h.dl; - *sline = regs.h.ch; - *eline = regs.h.cl; -} - - -int gr_save_mode() -{ - int i; - - gr_saved_screen.is_graphics = is_graphics_mode(); - gr_saved_screen.video_mode = *pVideoMode; - - if (!gr_saved_screen.is_graphics) { - gr_saved_screen.width = *pNumColumns; - gr_saved_screen.height = *pNumRows+1; - gr_saved_screen.char_height = *pCharHeight; - gr_getcursor(&gr_saved_screen.cursor_x, &gr_saved_screen.cursor_y, &gr_saved_screen.cursor_sline, &gr_saved_screen.cursor_eline ); - MALLOC(gr_saved_screen.video_memory,ushort, gr_saved_screen.width*gr_saved_screen.height ); - for (i=0; i < gr_saved_screen.width*gr_saved_screen.height; i++ ) - gr_saved_screen.video_memory[i] = pTextMemory[i]; - } - - if (gr_show_screen_info ) { - printf( "Current video mode 0x%x:\n", gr_saved_screen.video_mode ); - if (gr_saved_screen.is_graphics) - printf( "Graphics mode\n" ); - else { - printf( "Text mode\n" ); - printf( "( %d columns by %d rows)\n", gr_saved_screen.width, gr_saved_screen.height ); - printf( "Char height is %d pixel rows\n", gr_saved_screen.char_height ); - printf( "Cursor of type 0x%x,0x%x is at (%d, %d)\n", gr_saved_screen.cursor_sline, gr_saved_screen.cursor_eline,gr_saved_screen.cursor_x, gr_saved_screen.cursor_y ); - } - } - - return 0; -} - -int isvga() -{ - union REGS regs; - - memset( ®s, 0, sizeof(regs) ); - regs.w.ax = 0x1a00; - int386( 0x10, ®s, ®s ); - - if ( regs.h.al == 0x1a ) - return 1; - - return 0; -} - -void gr_restore_mode() -{ - int i; - - //gr_set_text_25(); - -#ifndef NOGRAPH - gr_palette_fade_out( gr_palette, 32, 0 ); - gr_palette_set_gamma(0); - if ( gr_saved_screen.video_mode == 3 ) { - switch( gr_saved_screen.height ) { - case 43: gr_set_text_43(); break; - case 50: gr_set_text_50(); break; - default: gr_set_text_25(); break; - } - } else { - gr_set_misc_mode(gr_saved_screen.video_mode); - } - if (gr_saved_screen.is_graphics==0) { - gr_sync_display(); - gr_sync_display(); - gr_palette_read( gr_pal_default ); - gr_palette_clear(); - for (i=0; i < gr_saved_screen.width*gr_saved_screen.height; i++ ) - pTextMemory[i]=gr_saved_screen.video_memory[i]; - gr_setcursor( gr_saved_screen.cursor_x, gr_saved_screen.cursor_y, gr_saved_screen.cursor_sline, gr_saved_screen.cursor_eline ); - gr_palette_faded_out = 1; - gr_palette_fade_in( gr_pal_default, 32, 0 ); - } -#endif - -} - -void gr_close() -{ - if (gr_installed==1) - { - gr_installed = 0; - gr_restore_mode(); - free(grd_curscreen); - if( gr_saved_screen.video_memory ) { - free(gr_saved_screen.video_memory); - gr_saved_screen.video_memory = NULL; - } - } -} - -#ifndef __DJGPP__ -int gr_vesa_setmode( int mode ) -{ - int retcode; - - retcode=gr_vesa_checkmode( mode ); - if ( retcode ) return retcode; - - return gr_vesa_setmodea( mode ); -} -#endif - - -int gr_set_mode(u_int32_t mode) -{ - int retcode; - unsigned int w,h,t,data, r; - - //JOHNgr_disable_default_palette_loading(); -#ifdef NOGRAPH -return 0; -#endif - switch(mode) - { - case SM_ORIGINAL: - return 0; - case SM(320,200)://0: - if (!isvga()) return 1; - gr_set_misc_mode(0x13); - w = 320; r = 320; h = 200; t=BM_LINEAR; data = (int)gr_video_memory; - break; - case SM(640,400)://SM_640x400V: - retcode = gr_vesa_setmode( 0x100 ); - if (retcode !=0 ) return retcode; - w = 640; r = 640; h = 400; t=BM_SVGA; data = 0; - break; - case SM(640,480)://SM_640x480V: - retcode = gr_vesa_setmode( 0x101 ); - if (retcode !=0 ) return retcode; - w = 640; r = 640; h = 480; t=BM_SVGA; data = 0; - break; - case SM(800,600)://SM_800x600V: - retcode = gr_vesa_setmode( 0x103 ); - if (retcode !=0 ) return retcode; - w = 800; r = 800; h = 600; t=BM_SVGA; data = 0; - break; - case SM(1024,768)://SM_1024x768V: - retcode = gr_vesa_setmode( 0x105 ); - if (retcode !=0 ) return retcode; - w = 1024; r = 1024; h = 768; t=BM_SVGA; data = 0; - break; -/* case SM_640x480V15: - retcode = gr_vesa_setmode( 0x110 ); - if (retcode !=0 ) return retcode; - w = 640; r = 640*2; h=480; t=BM_SVGA15; data = 0; - break; - case SM_800x600V15: - retcode = gr_vesa_setmode( 0x113 ); - if (retcode !=0 ) return retcode; - w = 800; r = 800*2; h=600; t=BM_SVGA15; data = 0; - break;*/ -// case 19: - case SM(320,100): - if (!isvga()) return 1; - gr_set_misc_mode(0x13); -// { -// ubyte x; -// x = inp( 0x3c5 ); -// x |= 8; -// outp( 0x3c5, x ); -// } - gr_set_cellheight( 3 ); - - w = 320; r = 320; h = 100; t=BM_LINEAR; data = (int)gr_video_memory; - break; -/* case 20: - retcode = gr_vesa_setmode( 0x102 ); - //gr_enable_default_palette_loading(); - if (retcode !=0 ) return retcode; - gr_16_to_256(); - gr_set_linear(); - //gr_set_cellheight( 1 ); - gr_vesa_setlogical( 400 ); - w = 400; r = 400; h = 600; t=BM_SVGA; data = 0; - break; - case 21: - if (!isvga()) return 1; - gr_set_misc_mode(0xd); - gr_16_to_256(); - gr_set_linear(); - gr_set_cellheight( 3 ); - w = 160; r = 160; h = 100; t=BM_LINEAR; data = (int)gr_video_memory; - break; - case //22: // 3dmax 320x400 - if (!isvga()) return 1; - gr_set_3dbios_mode(0x31); - //w = 320; r = 320/4; h = 400; t=BM_MODEX; data = 0; - w = 320; r = 320; h = 400; t=BM_SVGA; data = 0; - break;*/ - default: - if (!isvga()) return 1; - if (mode==SM(320,240)) - w = gr_modex_setmode( 2 ); - else if (mode==SM(320,400)) - w = gr_modex_setmode( 6 ); - else - Error("unhandled vid mode\n"); - //gr_enable_default_palette_loading(); - h = w & 0xffff; w = w >> 16; r = w / 4;t = BM_MODEX; data = 0; - break; - } - gr_palette_clear(); - - memset( grd_curscreen, 0, sizeof(grs_screen)); - grd_curscreen->sc_mode = mode; - grd_curscreen->sc_w = w; - grd_curscreen->sc_h = h; - grd_curscreen->sc_aspect = fixdiv(grd_curscreen->sc_w*3,grd_curscreen->sc_h*4); - grd_curscreen->sc_canvas.cv_bitmap.bm_x = 0; - grd_curscreen->sc_canvas.cv_bitmap.bm_y = 0; - grd_curscreen->sc_canvas.cv_bitmap.bm_w = w; - grd_curscreen->sc_canvas.cv_bitmap.bm_h = h; - grd_curscreen->sc_canvas.cv_bitmap.bm_rowsize = r; - grd_curscreen->sc_canvas.cv_bitmap.bm_type = t; - grd_curscreen->sc_canvas.cv_bitmap.bm_data = (unsigned char *)data; - VGA_current_mode = mode; - gr_set_current_canvas(NULL); - - //gr_enable_default_palette_loading(); -// gamefont_choose_game_font(w,h); - - return 0; -} - -int gr_init(void) -{ - int org_gamma; - int retcode; - int mode = SM(320,200); - - // Only do this function once! - if (gr_installed==1) - return 3; - -#ifdef __DJGPP__ - if (!__djgpp_nearptr_enable()) { - printf("nearptr enable=%x\n", __dpmi_error); - return 10; - } -#ifndef SAVEGR - gr_video_memory = (unsigned char *)(__djgpp_conventional_base + 0xa0000); -#else - gr_video_memory=(unsigned char *)-1; -#endif - pVideoMode = (volatile ubyte *)(__djgpp_conventional_base+0x449); - pNumColumns = (volatile ushort *)(__djgpp_conventional_base+0x44a); - pNumRows = (volatile ubyte *)(__djgpp_conventional_base+0x484); - pCharHeight = (volatile ushort *)(__djgpp_conventional_base+0x485); - pCursorPos = (volatile ushort *)(__djgpp_conventional_base+0x450); - pCursorType = (volatile ushort *)(__djgpp_conventional_base+0x460); - pTextMemory = (volatile ushort *)(__djgpp_conventional_base+0xb8000); -#endif -#ifndef __DJGPP__ - if (gr_init_A0000()) - return 10; -#endif - - // Save the current text screen mode - if (gr_save_mode()==1) - return 2; - -#ifndef NOGRAPH - // Save the current palette, and fade it out to black. - gr_palette_read( gr_pal_default ); - gr_palette_faded_out = 0; - org_gamma = gr_palette_get_gamma(); - gr_palette_set_gamma( 0 ); - gr_palette_fade_out( gr_pal_default, 32, 0 ); - gr_palette_clear(); - gr_palette_set_gamma( org_gamma ); - gr_sync_display(); - gr_sync_display(); -#endif - -#ifdef __DJGPP__ -#ifdef SAVEGR - __djgpp_nearptr_disable(); -#endif -#endif - - MALLOC( grd_curscreen,grs_screen,1 ); - memset( grd_curscreen, 0, sizeof(grs_screen)); - - // Set the mode. - if ((retcode=gr_set_mode(mode))) - { - gr_restore_mode(); - return retcode; - } - //JOHNgr_disable_default_palette_loading(); - - // Set all the screen, canvas, and bitmap variables that - // aren't set by the gr_set_mode call: - grd_curscreen->sc_canvas.cv_color = 0; - grd_curscreen->sc_canvas.cv_drawmode = 0; - grd_curscreen->sc_canvas.cv_font = NULL; - grd_curscreen->sc_canvas.cv_font_fg_color = 0; - grd_curscreen->sc_canvas.cv_font_bg_color = 0; - gr_set_current_canvas( &grd_curscreen->sc_canvas ); - -#if 0 - if (!dpmi_allocate_selector( &gr_fade_table, 256*GR_FADE_LEVELS, &gr_fade_table_selector )) - Error( "Error allocating fade table selector!" ); - - if (!dpmi_allocate_selector( &gr_palette, 256*3, &gr_palette_selector )) - Error( "Error allocating palette selector!" ); -#endif - -// if (!dpmi_allocate_selector( &gr_inverse_table, 32*32*32, &gr_inverse_table_selector )) -// Error( "Error allocating inverse table selector!" ); - - - // Set flags indicating that this is installed. - gr_installed = 1; -#ifdef __GNUC__ - - atexit((void (*)) gr_close); -#else - atexit(gr_close); -#endif - return 0; -} - -int gr_mode13_checkmode() -{ - if (isvga()) - return 0; - else - return 1; -} - -// 0=Mode set OK -// 1=No VGA adapter installed -// 2=Program doesn't support this VESA granularity -// 3=Monitor doesn't support that VESA mode.: -// 4=Video card doesn't support that VESA mode. -// 5=No VESA driver found. -// 6=Bad Status after VESA call/ -// 7=Not enough DOS memory to call VESA functions. -// 8=Error using DPMI. -// 9=Error setting logical line width. -// 10=Error allocating selector for A0000h -// 11=Not a valid mode support by gr.lib - -int gr_check_mode(u_int32_t mode) -{ - switch(mode) - { - case SM(320,100)://19: - case SM(320,200): - case SM(320,240): - case SM(360,200): - case SM(360,240): - case SM(376,282): - case SM(320,400): - case SM(320,480): - case SM(360,400): - case SM(360,480): - case SM(360,360): - case SM(376,308): - case SM(376,564): return gr_mode13_checkmode(); - case SM(640,400): return gr_vesa_checkmode( 0x100 ); - case SM(640,480): return gr_vesa_checkmode( 0x101 ); - case SM(800,600): return gr_vesa_checkmode( 0x103 ); - case SM(1024,768): return gr_vesa_setmode( 0x105 ); -// case SM_640x480V15: return gr_vesa_setmode( 0x110 ); -// case SM_800x600V15: return gr_vesa_setmode( 0x113 ); - } - return 11; -} - -/* Palette Stuff Starts Here... */ - -void gr_palette_step_up( int r, int g, int b ) -{ - int i; - ubyte *p; - int temp; - - if (gr_palette_faded_out) return; - - if ( (r==last_r) && (g==last_g) && (b==last_b) ) return; - - last_r = r; last_g = g; last_b = b; - - outp( 0x3c6, 0xff ); - outp( 0x3c8, 0 ); - p=gr_palette; - - for (i=0; i<256; i++ ) { - temp = (int)(*p++) + r + gr_palette_gamma; - if (temp<0) temp=0; - else if (temp>63) temp=63; - outp( 0x3c9, temp ); - temp = (int)(*p++) + g + gr_palette_gamma; - if (temp<0) temp=0; - else if (temp>63) temp=63; - outp( 0x3c9, temp ); - temp = (int)(*p++) + b + gr_palette_gamma; - if (temp<0) temp=0; - else if (temp>63) temp=63; - outp( 0x3c9, temp ); - } -} - - -void gr_palette_clear() -{ - int i; - outp( 0x3c6, 0xff ); - outp( 0x3c8, 0 ); - for (i=0; i<768; i++ ) { - outp( 0x3c9, 0 ); - } - gr_palette_faded_out = 1; -} - -void gr_palette_load( ubyte * pal ) -{ - int i; - ubyte c; - outp( 0x3c6, 0xff ); - outp( 0x3c8, 0 ); - for (i=0; i<768; i++ ) { - c = pal[i] + gr_palette_gamma; - if ( c > 63 ) c = 63; - outp( 0x3c9,c); - gr_current_pal[i] = pal[i]; - } - gr_palette_faded_out = 0; - - init_computed_colors(); -} - - -int gr_palette_fade_out(ubyte *pal, int nsteps, int allow_keys ) -{ - ubyte c; - int i,j; - fix fade_palette[768]; - fix fade_palette_delta[768]; - - if (gr_palette_faded_out) return 0; - - if (!pal) - pal = gr_current_pal; - - for (i=0; i<768; i++ ) { - fade_palette[i] = i2f(pal[i]+gr_palette_gamma); - fade_palette_delta[i] = fade_palette[i] / nsteps; - } - - for (j=0; j 63 ) c = 63; - outp( 0x3c9, c ); - } - } - gr_palette_faded_out = 1; - return 0; -} - -int gr_palette_fade_in(ubyte *pal, int nsteps, int allow_keys) -{ - int i,j; - ubyte c; - fix fade_palette[768]; - fix fade_palette_delta[768]; - - - if (!gr_palette_faded_out) return 0; - - for (i=0; i<768; i++ ) { - gr_current_pal[i] = pal[i]; - fade_palette[i] = 0; - fade_palette_delta[i] = i2f(pal[i]+gr_palette_gamma) / nsteps; - } - - for (j=0; j i2f(pal[i]+gr_palette_gamma) ) - fade_palette[i] = i2f(pal[i]+gr_palette_gamma); - c = f2i(fade_palette[i]); - if ( c > 63 ) c = 63; - outp( 0x3c9, c ); - } - } - gr_palette_faded_out = 0; - return 0; -} - -void gr_palette_read(ubyte * palette) -{ - int i; - outp( 0x3c6, 0xff ); - outp( 0x3c7, 0 ); - for (i=0; i<768; i++ ) { - *palette++ = inp( 0x3c9 ); - } -} - -void gr_update(void) -{ } diff --git a/arch/dos/dpmi.c b/arch/dos/dpmi.c deleted file mode 100644 index 9bd503c4..00000000 --- a/arch/dos/dpmi.c +++ /dev/null @@ -1,398 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ - - -#include -#ifdef __ENV_DJGPP__ - -#ifdef __DJGPP__ -#define _BORLAND_DOS_REGS 1 -#define far -#include -#include -#include -#define FP_SEG(p) _my_ds() -#define FP_OFF(p) (int)p - int _crt0_startup_flags=_CRT0_FLAG_NONMOVE_SBRK+_CRT0_FLAG_FILL_SBRK_MEMORY+_CRT0_FLAG_FILL_DEADBEEF+_CRT0_FLAG_NEARPTR+_CRT0_FLAG_NO_LFN; -#endif - -#include -#include -#include -#include -#include - -#include "pstypes.h" -#include "mono.h" -#include "error.h" -#include "u_dpmi.h" - -int dpmi_find_dos_memory() -{ - union REGS r; - - memset(&r,0,sizeof(r)); - r.x.eax = 0x0100; // DPMI allocate DOS memory - r.x.ebx = 0xffff; // Number of paragraphs requested - int386 (0x31, &r, &r); - //if ( (r.x.eax & 0xffff) == 0x08 ) - //if ( (r.x.eax & 0xffff) == 0x08 ) - if ( r.x.cflag ) - return ((r.x.ebx & 0xffff)*16); - else - return 640*1024; -} - -void *dpmi_real_malloc( int size, ushort *selector ) -{ - union REGS r; - - memset(&r,0,sizeof(r)); - r.x.eax = 0x0100; // DPMI allocate DOS memory - r.x.ebx = (size + 15) >> 4; // Number of paragraphs requested - int386 (0x31, &r, &r); - - if (r.x.cflag) // Failed - return ((uint) 0); - - if(selector!=NULL) - *selector = r.x.edx & 0xFFFF; - -#ifdef __DJGPP__ - return (void *) ((r.x.eax & 0xFFFF) << 4)+__djgpp_conventional_base; -#else - return (void *) ((r.x.eax & 0xFFFF) << 4); -#endif -} - -void dpmi_real_free( ushort selector ) -{ - union REGS r; - - memset(&r,0,sizeof(r)); - r.x.eax = 0x0101; // DPMI free DOS memory - r.x.ebx = selector; // Selector to free - int386 (0x31, &r, &r); -} - -int dos_stack_initialized = 0; -ubyte * dos_stack = NULL; -ubyte * dos_stack_top = NULL; -#define DOS_STACK_SIZE (4*1024) // A big ol' 4K stack!!! - -static void dpmi_setup_stack(dpmi_real_regs *rregs) { - ushort temp_selector; - - if ( !dos_stack_initialized ) { - dos_stack_initialized = 1; - dos_stack = dpmi_real_malloc( DOS_STACK_SIZE, &temp_selector ); - if ( dos_stack == NULL ) { - printf( "Error allocating real mode stack!\n" ); - dos_stack_top = NULL; - } else { - dos_stack_top = &dos_stack[DOS_STACK_SIZE]; - } - } - - // Give this puppy a stack!!! - if ( dos_stack_top ) { - rregs->ss = DPMI_real_segment(dos_stack_top); - rregs->sp = DPMI_real_offset(dos_stack_top); - } -} - - -void dpmi_real_int386x( ubyte intno, dpmi_real_regs * rregs ) -{ - union REGS regs; - struct SREGS sregs; - - /* Use DMPI call 300h to issue the DOS interrupt */ - - dpmi_setup_stack(rregs); - memset(®s,0,sizeof(regs)); - memset(&sregs,0,sizeof(sregs)); - regs.w.ax = 0x0300; - regs.h.bl = intno; - regs.h.bh = 0; - regs.w.cx = 0; - sregs.es = FP_SEG(rregs); - regs.x.edi = FP_OFF(rregs); - int386x( 0x31, ®s, ®s, &sregs ); -} - -void dpmi_real_call(dpmi_real_regs * rregs) -{ - union REGS regs; - struct SREGS sregs; - - dpmi_setup_stack(rregs); - - /* Use DMPI call 301h to call real mode procedure */ - memset(®s,0,sizeof(regs)); - memset(&sregs,0,sizeof(sregs)); - regs.w.ax = 0x0301; - regs.h.bh = 0; - regs.w.cx = 0; - sregs.es = FP_SEG(rregs); - regs.x.edi = FP_OFF(rregs); - int386x( 0x31, ®s, ®s, &sregs ); - if ( regs.x.cflag ) - exit(regs.w.ax); -} - -int total_bytes = 0; - -int dpmi_unlock_region(void *address, unsigned length) -{ - union REGS regs; - unsigned int linear; - - linear = (unsigned int) address; -#ifdef __DJGPP__ - linear += __djgpp_base_address; -#endif - - total_bytes -= length; - //mprintf( 1, "DPMI unlocked %d bytes\n", total_bytes ); - - memset(®s,0,sizeof(regs)); - regs.w.ax = 0x601; // DPMI Unlock Linear Region - regs.w.bx = (linear >> 16); // Linear address in BX:CX - regs.w.cx = (linear & 0xFFFF); - - regs.w.si = (length >> 16); // Length in SI:DI - regs.w.di = (length & 0xFFFF); - int386 (0x31, ®s, ®s); - return (! regs.w.cflag); // Return 0 if can't lock -} - -int dpmi_lock_region(void *address, unsigned length) -{ - union REGS regs; - unsigned int linear; - - linear = (unsigned int) address; -#ifdef __DJGPP__ - linear += __djgpp_base_address; -#endif - - total_bytes += length; - //mprintf( 1, "DPMI Locked down %d bytes\n", total_bytes ); - - memset(®s,0,sizeof(regs)); - regs.w.ax = 0x600; // DPMI Lock Linear Region - regs.w.bx = (linear >> 16); // Linear address in BX:CX - regs.w.cx = (linear & 0xFFFF); - - regs.w.si = (length >> 16); // Length in SI:DI - regs.w.di = (length & 0xFFFF); - int386 (0x31, ®s, ®s); - return (! regs.w.cflag); // Return 0 if can't lock -} - - -int dpmi_modify_selector_base( ushort selector, void * address ) -{ - union REGS regs; - unsigned int linear; - - linear = (unsigned int)address; -#ifdef __DJGPP__ - linear += __djgpp_base_address; -#endif - - memset(®s,0,sizeof(regs)); - regs.w.ax = 0x0007; // DPMI Change Selector Base Addres - regs.w.bx = selector; // Selector to change - regs.w.cx = (linear >> 16); // Base address - regs.w.dx = (linear & 0xFFFF); - int386 (0x31, ®s, ®s); // call dpmi - if (regs.w.cflag) - return 0; // Return 0 if error - - return 1; -} - - -int dpmi_modify_selector_limit( ushort selector, int size ) -{ - union REGS regs; - unsigned int segment_limit; - - segment_limit = (unsigned int) size; - - memset(®s,0,sizeof(regs)); - regs.w.ax = 0x0008; // DPMI Change Selector Limit - regs.w.bx = selector; // Selector to change - regs.w.cx = (segment_limit >> 16); // Size of selector - regs.w.dx = (segment_limit & 0xFFFF); - int386 (0x31, ®s, ®s); // call dpmi - if (regs.w.cflag) - return 0; // Return 0 if error - - return 1; -} - - -int dpmi_allocate_selector( void * address, int size, ushort * selector ) -{ - union REGS regs; - - - memset(®s,0,sizeof(regs)); - regs.w.ax = 0; // DPMI Allocate Selector - regs.w.cx = 1; // Allocate 1 selector - int386 (0x31, ®s, ®s); // call dpmi - if (regs.w.cflag) - return 0; // Return 0 if error - *selector = regs.w.ax; - - if ( !dpmi_modify_selector_base( *selector, address ) ) - return 0; - - if ( !dpmi_modify_selector_limit( *selector, size ) ) - return 0; - -// mprintf( 0, "Selector 0x%4x has base of 0x%8x, size %d bytes\n", *selector, linear,segment_limit); - - return 1; -} - -static void * dpmi_dos_buffer = NULL; -static ushort dpmi_dos_selector = 0; - -void dpmi_close() -{ - if (dpmi_dos_selector!=0) { - dpmi_dos_buffer = NULL; - dpmi_dos_selector = 0; - } -} - -typedef struct mem_data { - int largest_block_bytes; - int max_unlocked_page_allocation; - int largest_lockable_pages; - int total_pages; - int unlocked_pages; - int unused_physical_pages; - int total_physical_pages; - int free_linear_pages; - int paging_size_pages; - int reserved[3]; -} mem_data; - -unsigned int dpmi_virtual_memory=0; -unsigned int dpmi_available_memory=0; -unsigned int dpmi_physical_memory=0; -unsigned int dpmi_dos_memory = 0; - -#ifdef __WATCOMC__ -extern void cdecl _GETDS(); -extern void cdecl cstart_(); -#endif - -int dpmi_init(int verbose) -{ - union REGS regs; - struct SREGS sregs; - mem_data mi; - - dpmi_dos_memory = dpmi_find_dos_memory(); - - dpmi_dos_buffer = dpmi_real_malloc( 1024, &dpmi_dos_selector); - if (!dpmi_dos_buffer) { - dpmi_dos_selector = 0; - printf( "Error allocating 1K of DOS memory\n" ); - exit(1); - } - atexit(dpmi_close); - - // Check dpmi - memset(®s,0,sizeof(regs)); - regs.x.eax = 0x400; // DPMI Get Memory Info - int386( 0x31, ®s, ®s ); - if (!regs.w.cflag) { - if (verbose) printf( "V%d.%d, CPU:%d, VMM:", regs.h.ah, regs.h.al, regs.h.cl ); - if (regs.w.bx & 4) { - if (verbose) printf( "1" ); - dpmi_virtual_memory = 1; - } else { - if (verbose) printf( "0" ); - } - } - - //--------- Find available memory - memset(®s,0,sizeof(regs)); - memset(&sregs,0,sizeof(sregs)); - regs.x.eax = 0x500; // DPMI Get Memory Info - sregs.es = FP_SEG(&mi); - regs.x.edi = FP_OFF(&mi); - int386x( 0x31, ®s, ®s, &sregs ); - if (!regs.w.cflag) { - if (verbose) printf( ", P:%dK", mi.largest_lockable_pages*4 ); - if (dpmi_virtual_memory) - if (verbose) printf( ", A:%dK", mi.largest_block_bytes/1024 ); - //dpmi_physical_memory = mi.largest_lockable_pages*4096; - //dpmi_available_memory = mi.largest_block_bytes; - dpmi_physical_memory = mi.total_physical_pages*4096; - dpmi_available_memory = mi.total_pages * 4096; - } else { - if (verbose) printf( "MemInfo failed!" ); - dpmi_physical_memory = 16*1024*1024; // Assume 16 MB - dpmi_available_memory = 16*1024*1024; // Assume 16 MB - } - -#ifdef __WATCOMC__ - if (!dpmi_lock_region( _GETDS, 4096 )) { - printf( "Error locking _GETDS" ); - exit(1); - } - if (!dpmi_lock_region( cstart_, 4096 )) { - printf( "Error locking cstart" ); - exit(1); - } - if (!dpmi_lock_region( _chain_intr, 4096 )) { - printf( "Error locking _chain_intr" ); - exit(1); - } -#endif - return 1; -} - -void *dpmi_get_temp_low_buffer( int size ) -{ - if ( dpmi_dos_buffer == NULL ) return NULL; - if ( size > 1024 ) return NULL; - - return dpmi_dos_buffer; -} - -int dpmi_set_pm_handler(unsigned intnum, void far * isr ) -{ - union REGS regs; - - /* Use DMPI call 204h to get pm interrrupt */ - memset(®s,0,sizeof(regs)); - regs.w.ax = 0x0205; - regs.h.bl = intnum; - regs.w.cx = FP_SEG(isr); - regs.x.edx = FP_OFF(isr); - int386( 0x31, ®s, ®s ); - if (!regs.w.cflag) - return 0; - return 1; -} - -#endif // __ENV_DJGPP__ diff --git a/arch/dos/findfile.c b/arch/dos/findfile.c deleted file mode 100644 index 4db5c8cb..00000000 --- a/arch/dos/findfile.c +++ /dev/null @@ -1,95 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ - - -#include -#ifdef __ENV_DJGPP__ - -#include -#include - -#include "findfile.h" - - -// Global Variables ---------------------------------------------------------- - -static int _FileFindFlag = 0; -static struct find_t _FileFindStruct; - - - -// Functions - -int FileFindFirst(char *search_str, FILEFINDSTRUCT *ffstruct) -{ - unsigned retval; - - if (_FileFindFlag) return -1; - - retval = _dos_findfirst(search_str, 0, &_FileFindStruct); - if (retval) return (int)retval; - else { - ffstruct->size = _FileFindStruct.size; - strcpy(ffstruct->name, _FileFindStruct.name); - _FileFindFlag = 1; - return (int)retval; - } -} - - -int FileFindNext(FILEFINDSTRUCT *ffstruct) -{ - unsigned retval; - - if (!_FileFindFlag) return -1; - - retval = _dos_findnext(&_FileFindStruct); - if (retval) return (int)retval; - else { - ffstruct->size = _FileFindStruct.size; - strcpy(ffstruct->name, _FileFindStruct.name); - return (int)retval; - } -} - - -int FileFindClose(void) -{ - unsigned retval = 0; - - if (!_FileFindFlag) return -1; - - if (retval) return (int)retval; - else { - _FileFindFlag = 0; - return (int)retval; - } -} - - -//returns 0 if no error -int GetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct) -{ - return _dos_getftime(filehandle, &ftstruct->date, &ftstruct->time); - -} - - -//returns 0 if no error -int SetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct) -{ - return _dos_setftime(filehandle, ftstruct->date, ftstruct->time); -} - - -#endif //__ENV_DJGPP__ diff --git a/arch/dos/init.c b/arch/dos/init.c deleted file mode 100644 index 27217a0e..00000000 --- a/arch/dos/init.c +++ /dev/null @@ -1,369 +0,0 @@ -#include -#ifdef __ENV_DJGPP__ - -#include -#include -#ifdef __DJGPP__ -#define _BORLAND_DOS_REGS 1 -#endif -#include - -#include "../../main/inferno.h" -#include "../../main/text.h" -#include "console.h" -#include "args.h" -#include "error.h" - -#include "joy.h" -#include "timer.h" -#include "key.h" -#include "mono.h" -#include "u_dpmi.h" -#include "mouse.h" - -//added on 9/15/98 by Victor Rachels to add cd controls -//#include "bcd.h" -//end this section addition - Victor Rachels - - -void install_int3_handler(void); - -#ifdef __WATCOMC__ -int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned far * devhdr ); -#endif - -#ifndef NDEBUG -#ifdef __WATCOMC__ -void do_heap_check() -{ - int heap_status; - - heap_status = _heapset( 0xFF ); - switch( heap_status ) - { - case _HEAPBADBEGIN: - mprintf((1, "ERROR - heap is damaged\n")); - Int3(); - break; - case _HEAPBADNODE: - mprintf((1, "ERROR - bad node in heap\n" )); - Int3(); - break; - } -} -#endif -#endif - - - -#ifdef VR_DEVICES -int is_3dbios_installed() -{ - dpmi_real_regs rregs; - memset(&rregs,0,sizeof(dpmi_real_regs)); - rregs.eax = 0x4ed0; - //rregs.ebx = 0x3d10; - dpmi_real_int386x( 0x10, &rregs ); - if ( (rregs.edx & 0xFFFF) != 0x3344 ) - return 0; - else - return 1; -} -#endif - -// Returns 1 if ok, 0 if failed... -int init_gameport() -{ - union REGS regs; - - memset(®s,0,sizeof(regs)); - regs.x.eax = 0x8400; - regs.x.edx = 0xF0; - int386( 0x15, ®s, ®s ); - if ( ( regs.x.eax & 0xFFFF ) == 0x4753 /*'SG'*/ ) - return 1; - else - return 0; -} - -void check_dos_version() -{ - int major, minor; - union REGS regs; - - memset(®s,0,sizeof(regs)); - regs.x.eax = 0x3000; // Get MS-DOS Version Number - int386( 0x21, ®s, ®s ); - - major = regs.h.al; - minor = regs.h.ah; - - if ( major < 5 ) { - printf( "Using MS-DOS version %d.%d\nThis is not compatable with Descent.", major, minor); - exit(1); - } - //printf( "\nUsing MS-DOS %d.%d...\n", major, minor ); -} - -void dos_check_file_handles(int num_required) -{ - int i, n; - FILE * fp[16]; - - if ( num_required > 16 ) - num_required = 16; - - n = 0; - for (i=0; i<16; i++ ) - fp[i] = NULL; - for (i=0; i<16; i++ ) { - fp[i] = fopen( "nul", "wb" ); - if ( !fp[i] ) break; - } - n = i; - for (i=0; i<16; i++ ) { - if (fp[i]) - fclose(fp[i]); - } - if ( n < num_required ) { - printf( "\n%s\n", TXT_NOT_ENOUGH_HANDLES ); - printf( "------------------------\n" ); - printf( "%d/%d %s\n", n, num_required, TXT_HANDLES_1 ); - printf( "%s\n", TXT_HANDLES_2); - printf( "%s\n", TXT_HANDLES_3); - exit(1); - } -} - -#define NEEDED_DOS_MEMORY ( 300*1024) // 300 K -#define NEEDED_LINEAR_MEMORY (7680*1024) // 7.5 MB -#define LOW_PHYSICAL_MEMORY_CUTOFF (5*1024*1024) // 5.0 MB -#define NEEDED_PHYSICAL_MEMORY (2000*1024) // 2000 KB - -extern int piggy_low_memory; - -void mem_int_to_string( int number, char *dest ) -{ - int i,l,c; - char buffer[20],*p; - - sprintf( buffer, "%d", number ); - - l = strlen(buffer); - if (l<=3) { - // Don't bother with less than 3 digits - sprintf( dest, "%d", number ); - return; - } - - c = l % 3; - p=dest; - for (i=0; i dpmi_physical_memory ) { - mem_int_to_string( (dpmi_available_memory-dpmi_physical_memory)/1024, text ); - } else { - mem_int_to_string( 0, text ); - } - printf( "Virtual: %7s KB\n", text ); - printf( "\n" ); - - if ( dpmi_dos_memory < NEEDED_DOS_MEMORY ) { - printf( "%d %s\n", NEEDED_DOS_MEMORY - dpmi_dos_memory, TXT_MEMORY_CONFIG ); - exit(1); - } - - if ( dpmi_available_memory < NEEDED_LINEAR_MEMORY ) { - if ( dpmi_virtual_memory ) { - printf( "%d %s\n", NEEDED_LINEAR_MEMORY - dpmi_available_memory, TXT_RECONFIGURE_VMM ); - } else { - printf( "%d %s\n", NEEDED_LINEAR_MEMORY - dpmi_available_memory, TXT_MORE_MEMORY ); - printf( "%s\n", TXT_MORE_MEMORY_2); - } - exit(1); - } - - if ( dpmi_physical_memory < NEEDED_PHYSICAL_MEMORY ) { - printf( "%d %s\n", NEEDED_PHYSICAL_MEMORY - dpmi_physical_memory, TXT_PHYSICAL_MEMORY ); - if ( dpmi_virtual_memory ) { - printf( "%s\n", TXT_PHYSICAL_MEMORY_2); - } - exit(1); - } - - if ( dpmi_physical_memory < LOW_PHYSICAL_MEMORY_CUTOFF ) { - piggy_low_memory = 1; - } -} - -//NO_STACK_SIZE_CHECK uint * stack, *stack_ptr; -//NO_STACK_SIZE_CHECK int stack_size, unused_stack_space; -//NO_STACK_SIZE_CHECK int sil; -//NO_STACK_SIZE_CHECK -//NO_STACK_SIZE_CHECK int main(int argc,char **argv) -//NO_STACK_SIZE_CHECK { -//NO_STACK_SIZE_CHECK uint ret_value; -//NO_STACK_SIZE_CHECK -//NO_STACK_SIZE_CHECK unused_stack_space = 0; -//NO_STACK_SIZE_CHECK stack = &ret_value; -//NO_STACK_SIZE_CHECK stack_size = stackavail()/4; -//NO_STACK_SIZE_CHECK -//NO_STACK_SIZE_CHECK for ( sil=0; sil -#include -#include -#include -#include -#include -#include -#include - -#include "types.h" -#include "timer.h" -#include "ipx.h" -#include "error.h" -#include "u_dpmi.h" -#include "key.h" - -typedef unsigned char BYTE; -typedef unsigned short WORD; -typedef unsigned long DWORD; - -typedef struct local_address { - ubyte address[6]; -} __pack__ local_address; - -typedef struct net_address { - BYTE network_id[4]; - local_address node_id; - WORD socket_id; -} __pack__ net_address; - -typedef struct ipx_header { - WORD checksum; - WORD length; - BYTE transport_control; - BYTE packet_type; - net_address destination; - net_address source; -} __pack__ ipx_header; - -typedef struct ecb_header { - WORD link[2]; - WORD esr_address[2]; - BYTE in_use; - BYTE completion_code; - WORD socket_id; - BYTE ipx_reserved[14]; - WORD connection_id; - local_address immediate_address; - WORD fragment_count; - WORD fragment_pointer[2]; - WORD fragment_size; -} __pack__ ecb_header; - -typedef struct packet_data { - int packetnum; - byte data[IPX_MAX_DATA_SIZE]; -} __pack__ packet_data; - -typedef struct ipx_packet { - ecb_header ecb; - ipx_header ipx; - packet_data pd; -} __pack__ ipx_packet; - -typedef struct user_address { - ubyte network[4]; - ubyte node[6]; - ubyte address[6]; -} __pack__ user_address; - -#define MAX_USERS 64 -int Ipx_num_users = 0; -user_address Ipx_users[MAX_USERS]; - -#define MAX_NETWORKS 64 -int Ipx_num_networks = 0; -uint Ipx_networks[MAX_NETWORKS]; - -int ipx_packetnum = 0; - -#define MAX_PACKETS 64 - -static packet_data packet_buffers[MAX_PACKETS]; -static short packet_free_list[MAX_PACKETS]; -static int num_packets = 0; -static int largest_packet_index = 0; -static short packet_size[MAX_PACKETS]; - -WORD ipx_socket=0; -ubyte ipx_installed=0; -WORD ipx_vector_segment; -WORD ipx_vector_offset; -ubyte ipx_socket_life = 0; // 0=closed at prog termination, 0xff=closed when requested. -DWORD ipx_network = 0; -local_address ipx_my_node; -WORD ipx_num_packets=32; // 32 Ipx packets -ipx_packet * packets; -int neterrors = 0; -ushort ipx_packets_selector; - -ecb_header * last_ecb=NULL; -int lastlen=0; - -void got_new_packet( ecb_header * ecb ); -void ipx_listen_for_packet(ecb_header * ecb ); - -void free_packet( int id ) -{ - packet_buffers[id].packetnum = -1; - packet_free_list[ --num_packets ] = id; - if (largest_packet_index==id) - while ((--largest_packet_index>0) && (packet_buffers[largest_packet_index].packetnum == -1 )); -} - -int ipx_get_packet_data( ubyte * data ) -{ - int i, n, best, best_id, size; - - for (i=1; i -1 ) { - n++; - if ( best == -1 || (packet_buffers[i].packetnum ", neterrors )); - - if ( best_id < 0 ) return 0; - - size = packet_size[best_id]; - memcpy( data, packet_buffers[best_id].data, size ); - free_packet(best_id); - - return size; -} - -#ifndef __GNUC__ -unsigned int swap_short( unsigned int short ) -#pragma aux swap_short parm [eax] = "xchg al,ah"; -#else -static inline unsigned int swap_short( unsigned int sshort ) { - int __retval; - asm("xchg %%ah,%%al" : "=a" (__retval) : "a" (sshort)); - return __retval; -} -#endif - -void got_new_packet( ecb_header * ecb ) -{ - ipx_packet * p; - int id; - unsigned short datasize; - - datasize = 0; - last_ecb = ecb; - p = (ipx_packet *)ecb; - - if ( p->ecb.in_use ) { neterrors++; return; } - if ( p->ecb.completion_code ) { neterrors++; return; } - - // Error( "Recieve error %d for completion code", p->ecb.completion_code ); - - if ( memcmp( &p->ipx.source.node_id, &ipx_my_node, 6 ) ) { - datasize=swap_short(p->ipx.length); - lastlen=datasize; - datasize -= sizeof(ipx_header); - // Find slot to put packet in... - if ( datasize > 0 && datasize <= sizeof(packet_data) ) { - if ( num_packets >= MAX_PACKETS ) { - //printf( 1, "IPX: Packet buffer overrun!!!\n" ); - neterrors++; - return; - } - id = packet_free_list[ num_packets++ ]; - if (id > largest_packet_index ) largest_packet_index = id; - packet_size[id] = datasize-sizeof(int); - packet_buffers[id].packetnum = p->pd.packetnum; - if ( packet_buffers[id].packetnum < 0 ) { neterrors++; return; } - memcpy( packet_buffers[id].data, p->pd.data, packet_size[id] ); - } else { - neterrors++; return; - } - } - // Repost the ecb - p->ecb.in_use = 0; - //ipx_listen_for_packet(&p->ecb); -} - -ubyte * ipx_get_my_local_address() -{ - return ipx_my_node.address; -} - -ubyte * ipx_get_my_server_address() -{ - return (ubyte *)&ipx_network; -} - -void ipx_listen_for_packet(ecb_header * ecb ) -{ - dpmi_real_regs rregs; - ecb->in_use = 0x1d; - memset(&rregs,0,sizeof(dpmi_real_regs)); - rregs.ebx = 4; // Listen For Packet function - rregs.esi = DPMI_real_offset(ecb); - rregs.es = DPMI_real_segment(ecb); - dpmi_real_int386x( 0x7A, &rregs ); -} - -void ipx_cancel_listen_for_packet(ecb_header * ecb ) -{ - dpmi_real_regs rregs; - memset(&rregs,0,sizeof(dpmi_real_regs)); - rregs.ebx = 6; // IPX Cancel event - rregs.esi = DPMI_real_offset(ecb); - rregs.es = DPMI_real_segment(ecb); - dpmi_real_int386x( 0x7A, &rregs ); -} - - -void ipx_send_packet(ecb_header * ecb ) -{ - dpmi_real_regs rregs; - memset(&rregs,0,sizeof(dpmi_real_regs)); - rregs.ebx = 3; // Send Packet function - rregs.esi = DPMI_real_offset(ecb); - rregs.es = DPMI_real_segment(ecb); - dpmi_real_int386x( 0x7A, &rregs ); -} - -typedef struct { - ubyte network[4]; - ubyte node[6]; - ubyte local_target[6]; -} __pack__ net_xlat_info; - -void ipx_get_local_target( ubyte * server, ubyte * node, ubyte * local_target ) -{ - net_xlat_info * info; - dpmi_real_regs rregs; - - // Get dos memory for call... - info = (net_xlat_info *)dpmi_get_temp_low_buffer( sizeof(net_xlat_info) ); - assert( info != NULL ); - memcpy( info->network, server, 4 ); - memcpy( info->node, node, 6 ); - - memset(&rregs,0,sizeof(dpmi_real_regs)); - - rregs.ebx = 2; // Get Local Target - rregs.es = DPMI_real_segment(info); - rregs.esi = DPMI_real_offset(info->network); - rregs.edi = DPMI_real_offset(info->local_target); - - dpmi_real_int386x( 0x7A, &rregs ); - - // Save the local target... - memcpy( local_target, info->local_target, 6 ); -} - -void ipx_close() -{ - dpmi_real_regs rregs; - if ( ipx_installed ) { - // When using VLM's instead of NETX, the sockets don't - // seem to automatically get closed, so we must explicitly - // close them at program termination. - ipx_installed = 0; - memset(&rregs,0,sizeof(dpmi_real_regs)); - rregs.edx = ipx_socket; - rregs.ebx = 1; // Close socket - dpmi_real_int386x( 0x7A, &rregs ); - } -} - - -//--------------------------------------------------------------- -// Initializes all IPX internals. -// If socket_number==0, then opens next available socket. -// Returns: 0 if successful. -// -1 if socket already open. -// -2 if socket table full. -// -3 if IPX not installed. -// -4 if couldn't allocate low dos memory -// -5 if error with getting internetwork address - -int ipx_init( int socket_number, int show_address ) -{ - dpmi_real_regs rregs; - ubyte *ipx_real_buffer; - int i; - - atexit(ipx_close); - - ipx_packetnum = 0; - - // init packet buffers. - for (i=0; i= IPX_MAX_DATA_SIZE ) { - printf( "Data too big\n" ); -//added/replaced on 11/8/98 by Victor Rachels to stop crappage - return; -// exit(1); -//end this section replacement - VR - } - - // Make sure no one is already sending something - while( packets[0].ecb.in_use ) - { - } - - if (packets[0].ecb.completion_code) { -// printf( "Send error %d for completion code\n", packets[0].ecb.completion_code ); -//added/replaced on 11/8/98 by Victor Rachels to stop crappage - return; - // exit(1); -//end this section replacement - VR - - } - - // Fill in destination address - if ( memcmp( network, &ipx_network, 4 ) ) - memcpy( packets[0].ipx.destination.network_id, network, 4 ); - else - memset( packets[0].ipx.destination.network_id, 0, 4 ); - memcpy( packets[0].ipx.destination.node_id.address, address, 6 ); - memcpy( packets[0].ecb.immediate_address.address, immediate_address, 6 ); - packets[0].pd.packetnum = ipx_packetnum++; - - // Fill in data to send - packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(int) + datasize; - - assert( datasize > 1 ); - assert( packets[0].ecb.fragment_size <= 576 ); - - memcpy( packets[0].pd.data, data, datasize ); - - // Send it - ipx_send_packet( &packets[0].ecb ); - -} - -void ipx_send_broadcast_packet_data( ubyte * data, int datasize ) -{ - int i, j; - ubyte broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - ubyte local_address[6]; - - // Set to all networks besides mine - for (i=0; i= Ipx_num_networks ) { - memcpy( &Ipx_networks[Ipx_num_networks++], tmp.network, 4 ); - printf(" %02x%02x%02x%02x\n", tmp.network[0], tmp.network[1], tmp.network[2], tmp.network[3] ); - } - } else { - printf( "Too many networks in %s! (Limit of %d)\n", filename, MAX_NETWORKS ); - fclose(fp); - return; - } - } - fclose(fp); - -} - -//---typedef struct rip_entry { -//--- uint network; -//--- ushort nhops; -//--- ushort nticks; -//---} rip_entry; -//--- -//---typedef struct rip_packet { -//--- ushort operation; //1=request, 2=response -//--- rip_entry rip[50]; -//---} rip_packet; -//--- -//--- -//---void ipx_find_all_servers() -//---{ -//--- int i; -//--- rip_packet * rp; -//--- assert(ipx_installed); -//--- -//--- ipx_change_default_socket( 0x0453 ); -//--- // ipx_change_default_socket( 0x5304 ); -//--- -//--- // Make sure no one is already sending something -//--- while( packets[0].ecb.in_use ) -//--- { -//--- } -//--- -//--- if (packets[0].ecb.completion_code) { -//--- printf( "AAAA:Send error %d for completion code\n", packets[0].ecb.completion_code ); -//--- //exit(1); -//--- } -//--- -//--- rp = (rip_packet *)&packets[0].pd; -//--- -//--- // Fill in destination address -//--- { -//--- char mzero1[] = {0,0,0,1}; -//--- char mzero[] = {0,0,0,0,0,1}; -//--- char immediate[6]; -//--- //memcpy( packets[0].ipx.destination.network_id, &ipx_network, 4 ); -//--- //memcpy( packets[0].ipx.destination.node_id.address, ipx_my_node.address, 6 ); -//--- -//--- memcpy( packets[0].ipx.destination.network_id, mzero1, 4 ); -//--- memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 ); -//--- -//--- memcpy( packets[0].ipx.destination.socket_id, &ipx_socket, 2 ); -//--- memcpy( packets[0].ipx.source.network_id, &ipx_network, 4 ); -//--- memcpy( packets[0].ipx.source.node_id.address, ipx_my_node.address, 6 ); -//--- memcpy( packets[0].ipx.source.socket_id, &ipx_socket, 2 ); -//--- //memcpy( packets[0].ecb.immediate_address.address, ipx_my_node.address, 6 ); -//--- //mzero1[3] = 1; -//--- //memcpy( packets[0].ipx.destination.network_id, mzero1, 4 ); -//--- //mzero[5] = 1; -//--- //memcpy( packets[0].ipx.destination.node_id.address, mzero, 6 ); -//--- //ipx_get_local_target( mzero1, mzero, immediate ); -//--- //memcpy( packets[0].ecb.immediate_address.address, mzero, 6 ); -//--- //memcpy( packets[0].ecb.immediate_address.address, immediate, 6 ); -//--- //mzero[5] = 0; -//--- } -//--- -//--- packets[0].ipx.packet_type = 1; // RIP packet -//--- -//--- // Fill in data to send -//--- packets[0].ecb.fragment_size = sizeof(ipx_header) + sizeof(rip_packet); -//--- assert( packets[0].ecb.fragment_size <= 576 ); -//--- -//--- rp->operation = 0; // Request -//--- for (i=0;i<50; i++) { -//--- rp->rip[i].network = 0xFFFFFFFF; -//--- rp->rip[i].nhops = 0; -//--- rp->rip[i].nticks = 0; -//--- } -//--- -//--- // Send it -//--- ipx_send_packet( &packets[0].ecb ); -//--- -//--- for (i=0;i<50; i++) { -//--- if ( rp->rip[i].network != 0xFFFFFFFF ) -//--- printf( "Network = %8x, Hops=%d, Ticks=%d\n", rp->rip[i].network, rp->rip[i].nhops, rp->rip[i].nticks ); -//--- } -//---} -//--- -//--- diff --git a/arch/dos/joy2.asm b/arch/dos/joy2.asm deleted file mode 100644 index 69d22c56..00000000 --- a/arch/dos/joy2.asm +++ /dev/null @@ -1,471 +0,0 @@ -;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -; -; $Source: /cvs/cvsroot/d2x/arch/dos/joy2.asm,v $ -; $Revision: 1.1.1.1 $ -; $Author: bradleyb $ -; $Date: 2001-01-19 03:30:15 $ -; -; Contains routines for joystick interface. -; -; $Log: not supported by cvs2svn $ -; Revision 1.1.1.1 1999/06/14 21:57:53 donut -; Import of d1x 1.37 source. -; -; Revision 1.17 1995/10/07 13:22:11 john -; Added new method of reading joystick that allows higher-priority -; interrupts to go off. -; -; Revision 1.16 1995/03/30 11:03:30 john -; Made -JoyBios read buttons using BIOS. -; -; Revision 1.15 1995/02/14 11:39:36 john -; Added polled/bios joystick readers.. -; -; Revision 1.14 1995/01/29 18:36:00 john -; Made timer count in mode 2 instead of mode 3. -; -; Revision 1.13 1994/12/28 15:32:21 john -; Added code to read joystick axis not all at one time. -; -; Revision 1.12 1994/12/27 15:44:59 john -; Made the joystick timeout be at 1/100th of a second, -; regardless of CPU speed. -; -; Revision 1.11 1994/11/15 12:04:40 john -; Cleaned up timer code a bit... took out unused functions -; like timer_get_milliseconds, etc. -; -; Revision 1.10 1994/07/01 10:55:54 john -; Fixed some bugs... added support for 4 axis. -; -; Revision 1.9 1994/06/30 20:36:54 john -; Revamped joystick code. -; -; Revision 1.8 1994/04/22 12:52:06 john - -[BITS 32] - -[SECTION .data] - - LastTick dd 0 - TotalTicks dd 0 - - global _joy_bogus_reading - global _joy_retries - extern _JOY_PORT - _joy_bogus_reading dd 0 - _joy_retries dd 0 - RetryCount dd 0 - - -[SECTION .text] - -; JOY_PORT EQU 0209h - TDATA EQU 40h - TCOMMAND EQU 43h - -joy_get_timer: - xor al, al ; Latch timer 0 command - out TCOMMAND, al ; Latch timer - in al, TDATA ; Read lo byte - mov ah, al - in al, TDATA ; Read hi byte - xchg ah, al - and eax, 0ffffh - ret - - - - -global _joy_read_stick_friendly2 -_joy_read_stick_friendly2: - push ebx - push edi - - mov ebx,[esp+12] - mov edi,[esp+16] - mov ecx,[esp+20] - - ; ebx = read mask - ; edi = pointer to event buffer - ; ecx = timeout value - ; returns in eax the number of events - - mov dword [RetryCount], 0 - mov dword [_joy_bogus_reading], 0 - -_joy_read_stick_friendly_retry: - inc dword [RetryCount] - cmp dword [RetryCount], 3 - jbe @@f1 - mov dword [_joy_bogus_reading], 1 - inc dword [_joy_retries] - mov eax, 0 - pop edi - pop ebx - ret - -@@f1: - push ecx - push ebx - push edi - - and ebx, 01111b ; Make sure we only check the right values - ; number of events we found will be in bh, so this also clears it to zero. - - mov dx, [_JOY_PORT] - - cli ; disable interrupts while reading time... - call joy_get_timer ; Returns counter in EAX - sti ; enable interrupts after reading time... - mov dword [LastTick], eax - -waitforstable_f: in al, dx - and al, bl - jz ready_f ; Wait for the port in question to be done reading... - - cli ; disable interrupts while reading time... - call joy_get_timer ; Returns counter in EAX - sti ; enable interrupts after reading time... - xchg eax, dword [LastTick] - cmp eax, dword [LastTick] - jb @@f2 - sub eax, dword [LastTick] -@@f2: ; Higher... - add dword [TotalTicks], eax - cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second - jae ready_f - jmp waitforstable_f - -ready_f: - cli - mov al, 0ffh - out dx, al ; Start joystick a readin' - - call joy_get_timer ; Returns counter in EAX - mov dword [LastTick], eax - mov dword [TotalTicks], 0 - - mov [edi], eax ; Store initial count - add edi, 4 - -again_f: in al, dx ; Read Joystick port - not al - and al, bl ; Mask off channels we don't want to read - jnz flip_f ; See if any of the channels flipped - - ; none flipped -- check any interrupts... - mov al, 0Ah - out 20h, al - in al, 20h ; Get interrupts pending - cmp al, 0 - je NoInts - - ; Need to do an interrupt - sti - nop ; let the interrupt go on... - cli - - ; See if any axis turned - in al, dx - not al - and al, bl - jz NoInts - - ; At this point, an interrupt occured, making one or more - ; of the axis values bogus. So, we will restart this process... - - pop edi - pop ebx - pop ecx - - jmp _joy_read_stick_friendly_retry - -NoInts: - call joy_get_timer ; Returns counter in EAX - - xchg eax, dword [LastTick] - cmp eax, dword [LastTick] - jb @@f3 - sub eax, dword [LastTick] -@@f3: ; Higher... - add dword [TotalTicks], eax - cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second - jae timed_out_f - jmp again_f - - flip_f: and eax, 01111b ; Only care about axis values - mov [edi], eax ; Record what channel(s) flipped - add edi, 4 - xor bl, al ; Unmark the channels that just tripped - - call joy_get_timer ; Returns counter in EAX - mov [edi], eax ; Record the time this channel flipped - add edi, 4 - inc bh ; Increment number of events - - cmp bl, 0 - jne again_f ; If there are more channels to read, keep looping - - timed_out_f: - sti - - movzx eax, bh ; Return number of events - - pop edi - pop ebx - pop ecx - - pop edi - pop ebx - ret - - - -global _joy_read_stick_asm2 - -_joy_read_stick_asm2: - push ebx - push edi - - mov ebx,[esp+12] - mov edi,[esp+16] - mov ecx,[esp+20] - - ; ebx = read mask - ; edi = pointer to event buffer - ; ecx = timeout value - ; returns in eax the number of events - mov dword [_joy_bogus_reading], 0 - - and ebx, 01111b ; Make sure we only check the right values - ; number of events we found will be in bh, so this also clears it to zero. - - mov dx, [_JOY_PORT] - - cli ; disable interrupts while reading time... - call joy_get_timer ; Returns counter in EAX - sti ; enable interrupts after reading time... - mov dword [LastTick], eax - -waitforstable: in al, dx - and al, bl - jz ready ; Wait for the port in question to be done reading... - - cli ; disable interrupts while reading time... - call joy_get_timer ; Returns counter in EAX - sti ; enable interrupts after reading time... - xchg eax, dword [LastTick] - cmp eax, dword [LastTick] - jb @@f4 - sub eax, dword [LastTick] -@@f4: ; Higher... - add dword [TotalTicks], eax - cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second - jae ready - jmp waitforstable - -ready: - cli - mov al, 0ffh - out dx, al ; Start joystick a readin' - - call joy_get_timer ; Returns counter in EAX - mov dword [LastTick], eax - mov dword [TotalTicks], 0 - - mov [edi], eax ; Store initial count - add edi, 4 - - again: in al, dx ; Read Joystick port - not al - and al, bl ; Mask off channels we don't want to read - jnz flip ; See if any of the channels flipped - - call joy_get_timer ; Returns counter in EAX - - xchg eax, dword [LastTick] - cmp eax, dword [LastTick] - jb @@f5 - sub eax, dword [LastTick] -@@f5: ; Higher... - add dword [TotalTicks], eax - cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second - jae timedout - jmp again - - flip: and eax, 01111b ; Only care about axis values - mov [edi], eax ; Record what channel(s) flipped - add edi, 4 - xor bl, al ; Unmark the channels that just tripped - - call joy_get_timer ; Returns counter in EAX - mov [edi], eax ; Record the time this channel flipped - add edi, 4 - inc bh ; Increment number of events - - cmp bl, 0 - jne again ; If there are more channels to read, keep looping - - timedout: - movzx eax, bh ; Return number of events - - sti - pop edi - pop ebx - ret - - -global _joy_read_stick_polled2 - -_joy_read_stick_polled2: - push ebx - push edi - - mov ebx,[esp+12] - mov edi,[esp+16] - mov ecx,[esp+20] - - ; ebx = read mask - ; edi = pointer to event buffer - ; ecx = timeout value - ; returns in eax the number of events - mov dword [_joy_bogus_reading], 0 - - and ebx, 01111b ; Make sure we only check the right values - ; number of events we found will be in bh, so this also clears it to zero. - - mov dx, [_JOY_PORT] - - mov dword [TotalTicks], 0 - -waitforstable1: in al, dx - and al, bl - jz ready1 ; Wait for the port in question to be done reading... - - inc dword [TotalTicks] - cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second - jae ready1 - jmp waitforstable1 -ready1: - cli - mov al, 0ffh - out dx, al ; Start joystick a readin' - - mov dword [TotalTicks], 0 - - mov dword [edi], 0 ; Store initial count - add edi, 4 - - again1: in al, dx ; Read Joystick port - not al - and al, bl ; Mask off channels we don't want to read - jnz flip1 ; See if any of the channels flipped - - inc dword [TotalTicks] - cmp dword [TotalTicks], ecx ; Timeout at 1/200'th of a second - jae timedout1 - jmp again1 - - flip1: and eax, 01111b ; Only care about axis values - mov [edi], eax ; Record what channel(s) flipped - add edi, 4 - xor bl, al ; Unmark the channels that just tripped - - mov eax, dword [TotalTicks] - mov [edi], eax ; Record the time this channel flipped - add edi, 4 - inc bh ; Increment number of events - - cmp bl, 0 - jne again1 ; If there are more channels to read, keep looping - - timedout1: - movzx eax, bh ; Return number of events - - sti - pop edi - pop ebx - ret - -global _joy_read_stick_bios2 - -_joy_read_stick_bios2: - push ebx - push edi - - mov ebx,[esp+12] - mov edi,[esp+16] - mov ecx,[esp+20] - ; ebx = read mask - ; edi = pointer to event buffer - ; ecx = timeout value - ; returns in eax the number of events - - mov dword [_joy_bogus_reading], 0 - - pusha - - mov dword [edi], 0 - - mov eax, 08400h - mov edx, 1 - cli - int 15h - sti - - mov dword [edi+4], 1 ; Axis 1 - and eax, 0ffffh - mov [edi+8], eax ; Axis 1 value - - mov dword [edi+12], 2 ; Axis 2 - and ebx, 0ffffh - mov [edi+16], ebx ; Axis 2 value - - mov dword [edi+20], 4 ; Axis 3 - and ecx, 0ffffh - mov [edi+24], ecx ; Axis 3 value - - mov dword [edi+28], 8 ; Axis 3 - and edx, 0ffffh - mov [edi+32], edx ; Axis 3 value - - popa - mov eax, 4 ; 4 events - - pop edi - pop ebx - ret - - -global _joy_read_buttons_bios2 - -_joy_read_buttons_bios2: - ; returns in eax the button settings - - push ebx - push ecx - push edx - mov eax, 08400h - mov edx, 0 ; Read switches - int 15h - pop edx - pop ecx - pop ebx - - shr eax, 4 - not eax - and eax, 01111b - ret -global _joy_read_buttons_bios_end2 -_joy_read_buttons_bios_end2: ; to calculate _joy_read_buttons_bios size - diff --git a/arch/dos/joyc.c b/arch/dos/joyc.c deleted file mode 100644 index d17fb78b..00000000 --- a/arch/dos/joyc.c +++ /dev/null @@ -1,802 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ -/* - * $Source: /cvs/cvsroot/d2x/arch/dos/joyc.c,v $ - * $Revision: 1.2 $ - * $Author: bradleyb $ - * $Date: 2001-01-24 04:29:45 $ - * - * Routines for joystick reading. - * - * $Log: not supported by cvs2svn $ - * Revision 1.1.1.2 2001/01/19 03:33:52 bradleyb - * Import of d2x-0.0.9-pre1 - * - * Revision 1.1.1.1 1999/06/14 21:58:26 donut - * Import of d1x 1.37 source. - * - * Revision 1.37 1995/10/07 13:22:31 john - * Added new method of reading joystick that allows higher-priority - * interrupts to go off. - * - * Revision 1.36 1995/03/30 11:03:40 john - * Made -JoyBios read buttons using BIOS. - * - * Revision 1.35 1995/02/14 11:39:25 john - * Added polled/bios joystick readers.. - * - * Revision 1.34 1995/02/10 17:06:12 john - * Fixed bug with plugging in a joystick not getting detected. - * - * Revision 1.33 1995/01/27 16:39:42 john - * Made so that if no joystick detected, it wont't - * read buttons. - * - * Revision 1.32 1995/01/12 13:16:40 john - * Made it so that joystick can't lose an axis - * by 1 weird reading. Reading has to occurr during - * calibration for this to happen. - * - * Revision 1.31 1994/12/28 15:56:03 john - * Fixed bug that refused to read joysticks whose - * min,cen,max were less than 100 apart. - * - * Revision 1.30 1994/12/28 15:31:53 john - * Added code to read joystick axis not all at one time. - * - * Revision 1.29 1994/12/27 15:44:36 john - * Made the joystick timeout be at 1/100th of a second, - * regardless of CPU speed. - * - * Revision 1.28 1994/12/04 11:54:54 john - * Made stick read at whatever rate the clock is at, not - * at 18.2 times/second. - * - * Revision 1.27 1994/11/29 02:25:40 john - * Made it so that the scaled reading returns 0 - * if the calibration factors look funny.. - * - * Revision 1.26 1994/11/22 11:08:07 john - * Commented out the ARCADE joystick. - * - * Revision 1.25 1994/11/14 19:40:26 john - * Fixed bug with no joystick being detected. - * - * Revision 1.24 1994/11/14 19:36:40 john - * Took out initial cheapy calibration. - * - * Revision 1.23 1994/11/14 19:13:27 john - * Took out the calibration in joy_init - * - * Revision 1.22 1994/10/17 10:09:57 john - * Made the state look at last_State, so that a joy_flush - * doesn't cause a new down state to be added next reading. - * - * Revision 1.21 1994/10/13 11:36:23 john - * Made joy_down_time be kept track of in fixed seconds, - * not ticks. - * - * Revision 1.20 1994/10/12 16:58:50 john - * Fixed bug w/ previous comment. - * - * Revision 1.19 1994/10/12 16:57:44 john - * Added function to set a joystick button's state. - * - * Revision 1.18 1994/10/11 10:20:13 john - * Fixed Flightstick Pro/ - * .. - * - * Revision 1.17 1994/09/29 18:29:20 john - * *** empty log message *** - * - * Revision 1.16 1994/09/27 19:17:23 john - * Added code so that is joy_init is never called, joystick is not - * used at all. - * - * Revision 1.15 1994/09/22 16:09:23 john - * Fixed some virtual memory lockdown problems with timer and - * joystick. - * - * Revision 1.14 1994/09/16 11:44:42 john - * Fixed bug with slow joystick. - * - * Revision 1.13 1994/09/16 11:36:15 john - * Fixed bug with reading non-present channels. - * - * Revision 1.12 1994/09/15 20:52:48 john - * rme john - * Added support for the Arcade style joystick. - * - * Revision 1.11 1994/09/13 20:04:49 john - * Fixed bug with joystick button down_time. - * - * Revision 1.10 1994/09/10 13:48:07 john - * Made all 20 buttons read. - * - * Revision 1.9 1994/08/31 09:55:02 john - * *** empty log message *** - * - * Revision 1.8 1994/08/29 21:02:14 john - * Added joy_set_cal_values... - * - * Revision 1.7 1994/08/29 20:52:17 john - * Added better cyberman support; also, joystick calibration - * value return funcctiionn, - * - * Revision 1.6 1994/08/24 18:53:12 john - * Made Cyberman read like normal mouse; added dpmi module; moved - * mouse from assembly to c. Made mouse buttons return time_down. - * - * Revision 1.5 1994/07/14 22:12:23 john - * Used intrinsic forms of outp to fix vmm error. - * - * Revision 1.4 1994/07/07 19:52:59 matt - * Made joy_init() return success/fail flag - * Made joy_init() properly detect a stick if one is plugged in after joy_init() - * was called the first time. - * - * Revision 1.3 1994/07/01 10:55:55 john - * Fixed some bugs... added support for 4 axis. - * - * Revision 1.2 1994/06/30 20:36:55 john - * Revamped joystick code. - * - * Revision 1.1 1994/06/30 15:42:15 john - * Initial revision - * - * - */ - - -#include - -#include -#include -#include - -//#define ARCADE 1 - -#include "pstypes.h" -#include "mono.h" -#include "joy.h" -#include "u_dpmi.h" -#include "timer.h" - -#include "args.h" - -extern int joy_bogus_reading; -int JOY_PORT = 513; //201h; -int joy_deadzone = 0; - -int joy_read_stick_asm2( int read_masks, int * event_buffer, int timeout ); -int joy_read_stick_friendly2( int read_masks, int * event_buffer, int timeout ); -int joy_read_stick_polled2( int read_masks, int * event_buffer, int timeout ); -int joy_read_stick_bios2( int read_masks, int * event_buffer, int timeout ); -int joy_read_buttons_bios2(); -void joy_read_buttons_bios_end2(); - - -//In key.c -// ebx = read mask -// edi = pointer to buffer -// returns number of events - -char joy_installed = 0; -char joy_present = 0; - -typedef struct Button_info { - ubyte ignore; - ubyte state; - ubyte last_state; - int timedown; - ubyte downcount; - ubyte upcount; -} Button_info; - -typedef struct Joy_info { - ubyte present_mask; - ubyte slow_read; - int max_timer; - int read_count; - ubyte last_value; - Button_info buttons[MAX_BUTTONS]; - int axis_min[4]; - int axis_center[4]; - int axis_max[4]; -} Joy_info; - -Joy_info joystick; - -ubyte joy_read_buttons() -{ - return ((~(inp(JOY_PORT) >> 4))&0xf); -} - -void joy_get_cal_vals(int *axis_min, int *axis_center, int *axis_max) -{ - int i; - - for (i=0; i<4; i++) { - axis_min[i] = joystick.axis_min[i]; - axis_center[i] = joystick.axis_center[i]; - axis_max[i] = joystick.axis_max[i]; - } -} - -void joy_set_cal_vals(int *axis_min, int *axis_center, int *axis_max) -{ - int i; - - for (i=0; i<4; i++) { - joystick.axis_min[i] = axis_min[i]; - joystick.axis_center[i] = axis_center[i]; - joystick.axis_max[i] = axis_max[i]; - } -} - - -ubyte joy_get_present_mask() { - return joystick.present_mask; -} - -void joy_set_timer_rate(int max_value ) { - _disable(); - joystick.max_timer = max_value; - _enable(); -} - -int joy_get_timer_rate() { - return joystick.max_timer; -} - - -void joy_flush() { - int i; - - if (!joy_installed) return; - - _disable(); - for (i=0; i 7 ) { - joystick.read_count = 0; - value = joy_read_buttons_bios2(); - joystick.last_value = value; - } else { - value = joystick.last_value; - } - } else { - value = joy_read_buttons(); //JOY_READ_BUTTONS; - } - - for (i=0; iignore) { - if ( i < 5 ) - state = (value >> i) & 1; - else if (i==(value+4)) - state = 1; - else - state = 0; - - if ( button->last_state == state ) { - if (state) button->timedown += ticks_this_time; - } else { - if (state) { - button->downcount += state; - button->state = 1; - } else { - button->upcount += button->state; - button->state = 0; - } - button->last_state = state; - } - } - } -} - -void joy_handler_end() { // Dummy function to help calculate size of joystick handler function -} - -#pragma off (check_stack) - -ubyte joy_read_raw_buttons() { - if ( joystick.slow_read & JOY_BIOS_READINGS ) - return joy_read_buttons_bios2(); - else - return joy_read_buttons(); //JOY_READ_BUTTONS; -} - -void joy_set_slow_reading(int flag) -{ - joystick.slow_read |= flag; - joy_set_cen(); -} - -ubyte joystick_read_raw_axis( ubyte mask, int * axis ) -{ - ubyte read_masks, org_masks; - int t, t1, t2, buffer[4*2+2]; - int e, i, num_channels, c; - - axis[0] = 0; axis[1] = 0; - axis[2] = 0; axis[3] = 0; - - if (!joy_installed) return 0; - - read_masks = 0; - org_masks = mask; - - mask &= joystick.present_mask; // Don't read non-present channels - if ( mask==0 ) { - return 0; // Don't read if no stick connected. - } - - if ( joystick.slow_read & JOY_SLOW_READINGS ) { - for (c=0; c<4; c++ ) { - if ( mask & (1 << c)) { - // Time out at (1/100th of a second) - - if ( joystick.slow_read & JOY_POLLED_READINGS ) - num_channels = joy_read_stick_polled2( (1 << c), buffer, 65536 ); - else if ( joystick.slow_read & JOY_BIOS_READINGS ) - num_channels = joy_read_stick_bios2( (1 << c), buffer, 65536 ); - else if ( joystick.slow_read & JOY_FRIENDLY_READINGS ) - num_channels = joy_read_stick_friendly2( (1 << c), buffer, (1193180/100) ); - else - num_channels = joy_read_stick_asm2( (1 << c), buffer, (1193180/100) ); - - if ( num_channels > 0 ) { - t1 = buffer[0]; - e = buffer[1]; - t2 = buffer[2]; - if ( joystick.slow_read & (JOY_POLLED_READINGS|JOY_BIOS_READINGS) ) { - t = t2 - t1; - } else { - if ( t1 > t2 ) - t = t1 - t2; - else { - t = t1 + joystick.max_timer - t2; - //mprintf( 0, "%d, %d, %d, %d\n", t1, t2, joystick.max_timer, t ); - } - } - - if ( e & 1 ) { axis[0] = t; read_masks |= 1; } - if ( e & 2 ) { axis[1] = t; read_masks |= 2; } - if ( e & 4 ) { axis[2] = t; read_masks |= 4; } - if ( e & 8 ) { axis[3] = t; read_masks |= 8; } - } - } - } - } else { - // Time out at (1/100th of a second) - if ( joystick.slow_read & JOY_POLLED_READINGS ) - num_channels = joy_read_stick_polled2( mask, buffer, 65536 ); - else if ( joystick.slow_read & JOY_BIOS_READINGS ) - num_channels = joy_read_stick_bios2( mask, buffer, 65536 ); - else if ( joystick.slow_read & JOY_FRIENDLY_READINGS ) - num_channels = joy_read_stick_friendly2( mask, buffer, (1193180/100) ); - else - num_channels = joy_read_stick_asm2( mask, buffer, (1193180/100) ); - //mprintf(( 0, "(%d)\n", num_channels )); - - for (i=0; i t2 ) - t = t1 - t2; - else { - t = t1 + joystick.max_timer - t2; - //mprintf(( 0, "%d, %d, %d, %d\n", t1, t2, joystick.max_timer, t )); - } - } - e = buffer[i*2+1]; - - if ( e & 1 ) { axis[0] = t; read_masks |= 1; } - if ( e & 2 ) { axis[1] = t; read_masks |= 2; } - if ( e & 4 ) { axis[2] = t; read_masks |= 4; } - if ( e & 8 ) { axis[3] = t; read_masks |= 8; } - } - - } - - return read_masks; -} - -#ifdef __GNUC__ -#define near -#endif - -int joy_init() -{ - int i; - int temp_axis[4]; - -// if(FindArg("-joy209")) -// use_alt_joyport=1; - if(FindArg("-joy209")) - JOY_PORT = 521; //209h; - - joy_flush(); - - _disable(); - for (i=0; i 127 ) - x = 127; - -//added on 4/13/99 by Victor Rachels to add deadzone control - dz = (joy_deadzone) * 6; - if ((x > (-1*dz)) && (x < dz)) - x = 0; -//end this section addition -VR - - return x; -} - -int last_reading[4] = { 0, 0, 0, 0 }; - -void joy_get_pos( int *x, int *y ) -{ - ubyte flags; - int axis[4]; - - if ((!joy_installed)||(!joy_present)) { *x=*y=0; return; } - - flags=joystick_read_raw_axis( JOY_1_X_AXIS+JOY_1_Y_AXIS, axis ); - - if ( joy_bogus_reading ) { - axis[0] = last_reading[0]; - axis[1] = last_reading[1]; - flags = JOY_1_X_AXIS+JOY_1_Y_AXIS; - } else { - last_reading[0] = axis[0]; - last_reading[1] = axis[1]; - } - - if ( flags & JOY_1_X_AXIS ) - *x = joy_get_scaled_reading( axis[0], 0 ); - else - *x = 0; - - if ( flags & JOY_1_Y_AXIS ) - *y = joy_get_scaled_reading( axis[1], 1 ); - else - *y = 0; -} - -ubyte joy_read_stick( ubyte masks, int *axis ) -{ - ubyte flags; - int raw_axis[4]; - - if ((!joy_installed)||(!joy_present)) { - axis[0] = 0; axis[1] = 0; - axis[2] = 0; axis[3] = 0; - return 0; - } - - flags=joystick_read_raw_axis( masks, raw_axis ); - - if ( joy_bogus_reading ) { - axis[0] = last_reading[0]; - axis[1] = last_reading[1]; - axis[2] = last_reading[2]; - axis[3] = last_reading[3]; - flags = masks; - } else { - last_reading[0] = axis[0]; - last_reading[1] = axis[1]; - last_reading[2] = axis[2]; - last_reading[3] = axis[3]; - } - - if ( flags & JOY_1_X_AXIS ) - axis[0] = joy_get_scaled_reading( raw_axis[0], 0 ); - else - axis[0] = 0; - - if ( flags & JOY_1_Y_AXIS ) - axis[1] = joy_get_scaled_reading( raw_axis[1], 1 ); - else - axis[1] = 0; - - if ( flags & JOY_2_X_AXIS ) - axis[2] = joy_get_scaled_reading( raw_axis[2], 2 ); - else - axis[2] = 0; - - if ( flags & JOY_2_Y_AXIS ) - axis[3] = joy_get_scaled_reading( raw_axis[3], 3 ); - else - axis[3] = 0; - - return flags; -} - - -int joy_get_btns() -{ - if ((!joy_installed)||(!joy_present)) return 0; - - return joy_read_raw_buttons(); -} - -void joy_get_btn_down_cnt( int *btn0, int *btn1 ) -{ - if ((!joy_installed)||(!joy_present)) { *btn0=*btn1=0; return; } - - _disable(); - *btn0 = joystick.buttons[0].downcount; - joystick.buttons[0].downcount = 0; - *btn1 = joystick.buttons[1].downcount; - joystick.buttons[1].downcount = 0; - _enable(); -} - -int joy_get_button_state( int btn ) -{ - int count; - - if ((!joy_installed)||(!joy_present)) return 0; - - if ( btn >= MAX_BUTTONS ) return 0; - - _disable(); - count = joystick.buttons[btn].state; - _enable(); - - return count; -} - -int joy_get_button_up_cnt( int btn ) -{ - int count; - - if ((!joy_installed)||(!joy_present)) return 0; - - if ( btn >= MAX_BUTTONS ) return 0; - - _disable(); - count = joystick.buttons[btn].upcount; - joystick.buttons[btn].upcount = 0; - _enable(); - - return count; -} - -int joy_get_button_down_cnt( int btn ) -{ - int count; - - if ((!joy_installed)||(!joy_present)) return 0; - if ( btn >= MAX_BUTTONS ) return 0; - - _disable(); - count = joystick.buttons[btn].downcount; - joystick.buttons[btn].downcount = 0; - _enable(); - - return count; -} - - -fix joy_get_button_down_time( int btn ) -{ - fix count; - - if ((!joy_installed)||(!joy_present)) return 0; - if ( btn >= MAX_BUTTONS ) return 0; - - _disable(); - count = joystick.buttons[btn].timedown; - joystick.buttons[btn].timedown = 0; - _enable(); - - return fixmuldiv(count, 65536, 1193180 ); -} - -void joy_get_btn_up_cnt( int *btn0, int *btn1 ) -{ - if ((!joy_installed)||(!joy_present)) { *btn0=*btn1=0; return; } - - _disable(); - *btn0 = joystick.buttons[0].upcount; - joystick.buttons[0].upcount = 0; - *btn1 = joystick.buttons[1].upcount; - joystick.buttons[1].upcount = 0; - _enable(); -} - -void joy_set_btn_values( int btn, int state, fix timedown, int downcount, int upcount ) -{ - _disable(); - joystick.buttons[btn].ignore = 1; - joystick.buttons[btn].state = state; - joystick.buttons[btn].timedown = fixmuldiv( timedown, 1193180, 65536 ); - joystick.buttons[btn].downcount = downcount; - joystick.buttons[btn].upcount = upcount; - _enable(); -} - -void joy_poll() -{ - if ( joystick.slow_read & JOY_BIOS_READINGS ) - joystick.last_value = joy_read_buttons_bios2(); -} diff --git a/arch/dos/joydefs.c b/arch/dos/joydefs.c deleted file mode 100644 index 4444f148..00000000 --- a/arch/dos/joydefs.c +++ /dev/null @@ -1,673 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ -/* - * $Source: /cvs/cvsroot/d2x/arch/dos/joydefs.c,v $ - * $Revision: 1.1.1.2 $ - * $Author: bradleyb $ - * $Date: 2001-01-19 03:33:52 $ - * - * . - * - * $Log: not supported by cvs2svn $ - * Revision 1.1.1.1 1999/06/14 21:58:29 donut - * Import of d1x 1.37 source. - * - * Revision 2.2 1995/06/30 12:30:22 john - * Added -Xname command line. - * - * Revision 2.1 1995/04/06 12:13:20 john - * Made so you can calibrate Gravis Gamepad. - * - * Revision 2.0 1995/02/27 11:30:27 john - * New version 2.0, which has no anonymous unions, builds with - * Watcom 10.0, and doesn't require parsing BITMAPS.TBL. - * - * Revision 1.71 1995/02/12 02:06:10 john - * Fixed bug with joystick incorrectly asking for - * calibration. - * - * Revision 1.70 1995/01/28 15:58:07 john - * Made joystick calibration be only when wrong detected in - * menu or joystick axis changed. - * - * Revision 1.69 1995/01/25 14:37:55 john - * Made joystick only prompt for calibration once... - * - * Revision 1.68 1995/01/24 16:34:29 john - * Made so that if you reconfigure joystick and - * add or subtract an axis, it asks for a recalibration - * upon leaving. - * - * Revision 1.67 1994/12/29 11:08:51 john - * Fixed Thrustmaster and Logitech Wingman extreme - * Hat by reading the y2 axis during the center stage - * of the calibration, and using 75, 50, 27, and 3 % - * as values for the 4 positions. - * - * Revision 1.66 1994/12/15 18:17:39 john - * Fixed warning with previous. - * - * Revision 1.65 1994/12/15 18:15:48 john - * Made the joy cal only write the .cfg file, not - * the player file. - * - * Revision 1.64 1994/12/13 14:43:35 john - * Took out the code in kconfig to build direction array. - * Called kc_set_controls after selecting a new control type. - * - * Revision 1.63 1994/12/10 12:08:47 john - * Changed some delays to use TICKER instead of timer_get_fixed_seconds. - * - * Revision 1.62 1994/12/09 11:01:07 mike - * force calibration of joystick on joystick selection from Controls... menu. - * - * Revision 1.61 1994/12/07 21:50:27 john - * Put stop/start time around joystick delay. - * - * Revision 1.60 1994/12/07 19:34:39 john - * Added delay. - * - * Revision 1.59 1994/12/07 18:12:14 john - * NEatened up joy cal., - * - * Revision 1.58 1994/12/07 17:07:51 john - * Fixed up joy cal. - * - * Revision 1.57 1994/12/07 16:48:53 yuan - * localization - * - * Revision 1.56 1994/12/07 16:05:55 john - * Changed the way joystick calibration works. - * - * Revision 1.55 1994/12/06 20:15:22 john - * Took out code that unpauses songs that were never paused. - * - * Revision 1.54 1994/12/06 15:14:09 yuan - * Localization - * - * Revision 1.53 1994/12/05 16:29:16 john - * Took out music pause around the cheat menu. - * - * Revision 1.52 1994/12/04 12:39:10 john - * MAde so that FCS calibration doesn't ask for axis #2. - * - * Revision 1.51 1994/12/03 15:14:59 john - * Took out the delay mentioned previosuly cause it would - * cause bigger problems than it helps, especially with netgames. - * - * Revision 1.50 1994/12/03 14:16:14 john - * Put a delay between screens in joy cal to keep Yuan from - * double hitting. - * - * Revision 1.49 1994/12/03 11:04:06 john - * Changed newmenu code a bit to fix bug with bogus - * backgrounds occcasionally. - * - * Revision 1.48 1994/12/02 11:03:44 yuan - * Localization. - * - * Revision 1.47 1994/12/02 10:50:33 yuan - * Localization - * - * Revision 1.46 1994/12/01 12:21:59 john - * Added code to calibrate 2 joysticks separately. - * - * Revision 1.45 1994/12/01 11:52:31 john - * Added message when you select FCS to say that if - * you have WCS, see manuel. - * - * Revision 1.44 1994/11/29 02:26:28 john - * Made the prompts for upper-left, lower right for joy - * calibration more obvious. - * - * Revision 1.43 1994/11/26 13:13:59 matt - * Changed "none" option to "keyboard only" - * - * Revision 1.42 1994/11/21 19:35:13 john - * Replaced calls to joy_init with if (joy_present) - * - * Revision 1.41 1994/11/21 19:28:34 john - * Changed warning for no joystick to use nm_messagebox.. - * - * Revision 1.40 1994/11/21 19:06:25 john - * Made it so that it only stops sound when your in game mode. - * - * Revision 1.39 1994/11/21 11:47:18 john - * Made sound pause during joystick calibration. - * - * Revision 1.38 1994/11/10 20:34:18 rob - * Removed menu-specific network mode support in favor in new stuff - * in newmenu.c - * - * Revision 1.37 1994/11/08 21:21:38 john - * Made Esc exit joystick calibration. - * - * Revision 1.36 1994/11/08 15:14:42 john - * Added more calls so net doesn't die in net game. - * - * Revision 1.35 1994/11/08 14:59:12 john - * Added code to respond to network while in menus. - * - * Revision 1.34 1994/10/24 19:56:32 john - * Made the new user setup prompt for config options. - * - * Revision 1.33 1994/10/22 14:11:52 mike - * Suppress compiler warning message. - * - * Revision 1.32 1994/10/19 12:44:24 john - * Added hours field to player structure. - * - * Revision 1.31 1994/10/17 13:07:13 john - * Moved the descent.cfg info into the player config file. - * - * Revision 1.30 1994/10/13 21:41:12 john - * MAde Esc exit out of joystick calibration. - * - * Revision 1.29 1994/10/13 19:22:27 john - * Added separate config saves for different devices. - * Made all the devices work together better, such as mice won't - * get read when you're playing with the joystick. - * - * Revision 1.28 1994/10/13 11:40:18 john - * Took out warnings. - * - * Revision 1.27 1994/10/13 11:35:23 john - * Made Thrustmaster FCS Hat work. Put a background behind the - * keyboard configure. Took out turn_sensitivity. Changed sound/config - * menu to new menu. Made F6 be calibrate joystick. - * - * Revision 1.26 1994/10/11 21:29:03 matt - * Made a bunch of menus have good initial selected values - * - * Revision 1.25 1994/10/11 17:08:39 john - * Added sliders for volume controls. - * - * Revision 1.24 1994/10/10 17:59:21 john - * Neatend previous. - * - * Revision 1.23 1994/10/10 17:57:59 john - * Neatend previous. - * - * Revision 1.22 1994/10/10 17:56:11 john - * Added messagebox that tells that config has been saved. - * - * Revision 1.21 1994/09/30 12:37:26 john - * Added midi,digi volume to configuration. - * - * Revision 1.20 1994/09/22 16:14:14 john - * Redid intro sequecing. - * - * Revision 1.19 1994/09/19 18:50:15 john - * Added switch to disable joystick. - * - * Revision 1.18 1994/09/12 11:47:36 john - * Made stupid cruise work better. Make kconfig values get - * read/written to disk. - * - * Revision 1.17 1994/09/10 15:46:47 john - * First version of new keyboard configuration. - * - * Revision 1.16 1994/09/06 19:35:44 john - * Fixed bug that didn';t load new size .cal file. - * - * Revision 1.15 1994/09/06 14:51:58 john - * Added sensitivity adjustment, fixed bug with joystick button not - * staying down. - * - * Revision 1.14 1994/09/02 16:13:47 john - * Made keys fill in position. - * - * Revision 1.13 1994/08/31 17:58:50 john - * Made a bit simpler. - * - * Revision 1.12 1994/08/31 14:17:54 john - * *** empty log message *** - * - * Revision 1.11 1994/08/31 14:10:56 john - * Made keys not work when KEY_DELETE pressed. - * - * Revision 1.10 1994/08/31 13:40:47 mike - * Change constant - * - * Revision 1.9 1994/08/31 12:56:27 john - * *** empty log message *** - * - * Revision 1.8 1994/08/30 20:38:29 john - * Add more config stuff.. - * - * Revision 1.7 1994/08/30 16:37:25 john - * Added menu options to set controls. - * - * Revision 1.6 1994/08/30 09:27:18 john - * *** empty log message *** - * - * Revision 1.5 1994/08/30 09:12:01 john - * *** empty log message *** - * - * Revision 1.4 1994/08/29 21:18:32 john - * First version of new keyboard/oystick remapping stuff. - * - * Revision 1.3 1994/08/24 19:00:29 john - * Changed key_down_time to return fixed seconds instead of - * milliseconds. - * - * Revision 1.2 1994/08/17 16:50:37 john - * Added damaging fireballs, missiles. - * - * Revision 1.1 1994/08/17 10:07:12 john - * Initial revision - * - * - */ - -#include - -#include -#include -#include - -#include "mono.h" -#include "key.h" -#include "joy.h" -#include "timer.h" -#include "error.h" - -#include "inferno.h" -#include "game.h" -#include "object.h" -#include "player.h" - -#include "controls.h" -#include "joydefs.h" -#include "render.h" -#include "palette.h" -#include "newmenu.h" -#include "args.h" -#include "text.h" -#include "kconfig.h" -#include "digi.h" -#include "playsave.h" - -int joydefs_calibrate_flag = 0; - -int Joy_is_Sidewinder = 0; - -void joy_delay() -{ -#ifdef __MSDOS__ - int t1 = TICKER + 19/4; // Wait 1/4 second... - stop_time(); - while( TICKER < t1 ); - joy_flush(); - start_time(); -#endif -} - - -int joycal_message( char * title, char * text ) -{ - int i; - newmenu_item m[2]; - m[0].type = NM_TYPE_TEXT; m[0].text = text; - m[1].type = NM_TYPE_MENU; m[1].text = TXT_OK; - i = newmenu_do( title, NULL, 2, m, NULL ); - if ( i < 0 ) - return 1; - return 0; -} - -extern int WriteConfigFile(); - -void joydefs_calibrate() -{ - ubyte masks; - int org_axis_min[4]; - int org_axis_center[4]; - int org_axis_max[4]; - - int axis_min[4] = { 0, 0, 0, 0 }; - int axis_cen[4] = { 0, 0, 0, 0 }; - int axis_max[4] = { 0, 0, 0, 0 }; - - int temp_values[4]; - char title[50]; - char text[50]; - int nsticks = 0; - - joydefs_calibrate_flag = 0; - - if ( (Config_control_type!=CONTROL_JOYSTICK) && (Config_control_type!=CONTROL_FLIGHTSTICK_PRO) && (Config_control_type!=CONTROL_THRUSTMASTER_FCS) && (Config_control_type!=CONTROL_GRAVIS_GAMEPAD) ) - return; - - joy_get_cal_vals(org_axis_min, org_axis_center, org_axis_max); - - joy_set_cen(); - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - - if (!joy_present) { - nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK ); - return; - } - - masks = joy_get_present_mask(); - - if ( masks == JOY_ALL_AXIS ) - nsticks = 2; - else - nsticks = 1; - - if ( nsticks == 2 && !Joy_is_Sidewinder) { - sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT); - sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL); - } else { - sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT); - sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_UL); - } - if (joycal_message( title, text )) { - joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); - return; - } - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - axis_min[0] = temp_values[0]; - axis_min[1] = temp_values[1]; - joy_delay(); - - if ( nsticks == 2 && !Joy_is_Sidewinder) { - sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT); - sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR); - } else { - sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT); - sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_LR); - } - if (joycal_message( title, text)) { - joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); - return; - } - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - axis_max[0] = temp_values[0]; - axis_max[1] = temp_values[1]; - joy_delay(); - - if ( nsticks == 2 && !Joy_is_Sidewinder) { - sprintf( title, "%s #1\n%s", TXT_JOYSTICK, TXT_CENTER); - sprintf( text, "%s #1 %s", TXT_MOVE_JOYSTICK, TXT_TO_C); - } else { - sprintf( title, "%s\n%s", TXT_JOYSTICK, TXT_CENTER); - sprintf( text, "%s %s", TXT_MOVE_JOYSTICK, TXT_TO_C); - } - if (joycal_message( title, text)) { - joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); - return; - } - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - axis_cen[0] = temp_values[0]; - axis_cen[1] = temp_values[1]; - joy_delay(); - - // The fcs uses axes 3 for hat, so don't calibrate it. - if (Config_control_type == CONTROL_THRUSTMASTER_FCS) { - axis_min[3] = 0; - axis_cen[3] = temp_values[3]/2; - axis_max[3] = temp_values[3]; - joy_delay(); - } - - if (Joy_is_Sidewinder || Config_control_type != CONTROL_THRUSTMASTER_FCS) { - // masks = joy_get_present_mask(); - - if ( nsticks == 2 ) { - if ( kconfig_is_axes_used(2) || kconfig_is_axes_used(3) ) { - if(Joy_is_Sidewinder) - { - sprintf( title, "%s\nTWIST-LEFT", TXT_JOYSTICK); - sprintf( text, "Twist Joystick to \nthe left side"); - } - else - { - sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_UPPER_LEFT); - sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_UL); - } - if (joycal_message( title, text )) { - joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); - return; - } - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - axis_min[2] = temp_values[2]; - axis_min[3] = temp_values[3]; - joy_delay(); - - if(Joy_is_Sidewinder) - { - sprintf( title, "%s\nTWIST-RIGHT", TXT_JOYSTICK); - sprintf( text, "Twist Joystick to \nthe right side"); - } - else - { - sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_LOWER_RIGHT); - sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_LR); - } - if (joycal_message( title, text )) { - joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); - return; - } - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - axis_max[2] = temp_values[2]; - axis_max[3] = temp_values[3]; - joy_delay(); - - - if(Joy_is_Sidewinder) - { - sprintf( title, "%s\nCENTER", TXT_JOYSTICK); - sprintf( text, "%s %s",TXT_MOVE_JOYSTICK, TXT_TO_C); - } - else - { - sprintf( title, "%s #2\n%s", TXT_JOYSTICK, TXT_CENTER); - sprintf( text, "%s #2 %s", TXT_MOVE_JOYSTICK, TXT_TO_C); - } - - if (joycal_message( title, text )) { - joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); - return; - } - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - axis_cen[2] = temp_values[2]; - axis_cen[3] = temp_values[3]; - joy_delay(); - } - } else if ( (!(masks & JOY_2_X_AXIS)) && (masks & JOY_2_Y_AXIS) ) { - if ( kconfig_is_axes_used(3) ) { - // A throttle axis!!!!! - sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_FORWARD); - if (joycal_message( title, TXT_MOVE_THROTTLE_F)) { - joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); - return; - } - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - axis_min[3] = temp_values[3]; - joy_delay(); - - sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_REVERSE); - if (joycal_message( title, TXT_MOVE_THROTTLE_R)) { - joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); - return; - } - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - axis_max[3] = temp_values[3]; - joy_delay(); - - sprintf( title, "%s\n%s", TXT_THROTTLE, TXT_CENTER); - if (joycal_message( title, TXT_MOVE_THROTTLE_C)) { - joy_set_cal_vals(org_axis_min, org_axis_center, org_axis_max); - return; - } - joystick_read_raw_axis( JOY_ALL_AXIS, temp_values ); - axis_cen[3] = temp_values[3]; - joy_delay(); - } - } - } - joy_set_cal_vals(axis_min, axis_cen, axis_max); - - -//added 9/1/98 by Victor Rachels to make sidewinder calibratable -/* if(Joy_is_Sidewinder) - Config_control_type=tempstick; */ -//end this section addition - Victor Rachels - - - WriteConfigFile(); -} - - -//char *control_text[CONTROL_MAX_TYPES] = { "Keyboard only", "Joystick", "Flightstick Pro", "Thrustmaster FCS", "Gravis Gamepad", "Mouse", "Cyberman" }; - -void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem ) -{ - int i; - int oc_type = Config_control_type; - - nitems = nitems; - last_key = last_key; - citem = citem; - - for (i=0; i-1); - - switch (Config_control_type) { - case CONTROL_JOYSTICK: - case CONTROL_FLIGHTSTICK_PRO: - case CONTROL_THRUSTMASTER_FCS: - case CONTROL_GRAVIS_GAMEPAD: - if ( joydefs_calibrate_flag ) - joydefs_calibrate(); - break; - } - -} - diff --git a/arch/dos/key.c b/arch/dos/key.c deleted file mode 100644 index 36882000..00000000 --- a/arch/dos/key.c +++ /dev/null @@ -1,709 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ -/* - * $Source: /cvs/cvsroot/d2x/arch/dos/key.c,v $ - * $Revision: 1.1.1.2 $ - * $Author: bradleyb $ - * $Date: 2001-01-19 03:33:52 $ - * - * Functions for keyboard handler. - * - * $Log: not supported by cvs2svn $ - * Revision 1.1.1.1 1999/06/14 21:58:32 donut - * Import of d1x 1.37 source. - * - * Revision 1.35 1995/01/25 20:13:30 john - * Took out not passing keys to debugger if w10. - * - * Revision 1.34 1995/01/14 19:19:31 john - * Made so when you press Shift+Baskspace, it release keys autmatically. - * - * Revision 1.33 1994/12/13 09:21:48 john - * Took out keyd_editor_mode, and KEY_DEBUGGED stuff for NDEBUG versions. - * - * Revision 1.32 1994/11/12 13:52:01 john - * Fixed bug with code that cleared bios buffer. - * - * Revision 1.31 1994/10/24 15:16:16 john - * Added code to detect KEY_PAUSE. - * - * Revision 1.30 1994/10/24 13:57:53 john - * Hacked in support for pause key onto code 0x61. - * - * Revision 1.29 1994/10/21 15:18:13 john - * *** empty log message *** - * - * Revision 1.28 1994/10/21 15:17:24 john - * Made LSHIFT+BACKSPACE do what PrtScr used to. - * - * Revision 1.27 1994/09/22 16:09:18 john - * Fixed some virtual memory lockdown problems with timer and - * joystick. - * - * Revision 1.26 1994/09/15 21:32:47 john - * Added bounds checking for down_count scancode - * parameter. - * - * Revision 1.25 1994/08/31 12:22:20 john - * Added KEY_DEBUGGED - * - * Revision 1.24 1994/08/24 18:53:48 john - * Made Cyberman read like normal mouse; added dpmi module; moved - * mouse from assembly to c. Made mouse buttons return time_down. - * - * Revision 1.23 1994/08/18 15:17:51 john - * *** empty log message *** - * - * Revision 1.22 1994/08/18 15:16:38 john - * fixed some bugs with clear_key_times and then - * removed it because i fixed key_flush to do the - * same. - * - * Revision 1.21 1994/08/17 19:01:25 john - * Attempted to fix a bug with a key being held down - * key_flush called, then the key released having too - * long of a time. - * - * Revision 1.20 1994/08/08 10:43:48 john - * Recorded when a key was pressed for key_inkey_time. - * - * Revision 1.19 1994/06/22 15:00:03 john - * Made keyboard close automatically on exit. - * - * Revision 1.18 1994/06/21 09:16:29 john - * *** empty log message *** - * - * Revision 1.17 1994/06/21 09:08:23 john - * *** empty log message *** - * - * Revision 1.16 1994/06/21 09:05:01 john - * *** empty log message *** - * - * Revision 1.15 1994/06/21 09:04:24 john - * Made PrtScreen do an int5 - * - * Revision 1.14 1994/06/17 17:17:06 john - * Added keyd_time_last_key_was_pressed or something like that. - * - * Revision 1.13 1994/05/14 13:55:16 matt - * Added #define to control key passing to bios - * - * Revision 1.12 1994/05/05 18:09:39 john - * Took out BIOS to prevent stuck keys. - * - * Revision 1.11 1994/05/03 17:39:12 john - * *** empty log message *** - * - * Revision 1.10 1994/04/29 12:14:20 john - * Locked all memory used during interrupts so that program - * won't hang when using virtual memory. - * - * Revision 1.9 1994/04/28 23:49:41 john - * Made key_flush flush more keys and also did something else but i forget what. - * - * Revision 1.8 1994/04/22 12:52:12 john - * *** empty log message *** - * - * Revision 1.7 1994/04/01 10:44:59 mike - * Change key_getch() to call getch() if our interrupt hasn't been installed. - * - * Revision 1.6 1994/03/09 10:45:48 john - * Neatend code a bit. - * - * Revision 1.5 1994/02/17 17:24:16 john - * Neatened up a bit. - * - * Revision 1.4 1994/02/17 16:30:29 john - * Put in code to pass keys when in debugger. - * - * Revision 1.3 1994/02/17 15:57:59 john - * Made handler not chain to BIOS handler. - * - * Revision 1.2 1994/02/17 15:56:06 john - * Initial version. - * - * Revision 1.1 1994/02/17 15:54:07 john - * Initial revision - * - * - */ - -//#define PASS_KEYS_TO_BIOS 1 //if set, bios gets keys - -#include -#include -#include -#include - -//#define WATCOM_10 -#ifdef __DJGPP__ -#include -#define _far -#define __far -#define __interrupt -#define near -_go32_dpmi_seginfo kbd_hand_info; -#endif -#include "error.h" -#include "key.h" -#include "timer.h" -#include "u_dpmi.h" - -#define KEY_BUFFER_SIZE 16 - - -//-------- Variable accessed by outside functions --------- -unsigned char keyd_buffer_type; // 0=No buffer, 1=buffer ASCII, 2=buffer scans -unsigned char keyd_repeat; -unsigned char keyd_editor_mode; -volatile unsigned char keyd_last_pressed; -volatile unsigned char keyd_last_released; -volatile unsigned char keyd_pressed[256]; -volatile int keyd_time_when_last_pressed; - -typedef struct keyboard { - unsigned short keybuffer[KEY_BUFFER_SIZE]; - fix time_pressed[KEY_BUFFER_SIZE]; - fix TimeKeyWentDown[256]; - fix TimeKeyHeldDown[256]; - unsigned int NumDowns[256]; - unsigned int NumUps[256]; - unsigned int keyhead, keytail; - unsigned char E0Flag; - unsigned char E1Flag; - int in_key_handler; -#ifdef __DJGPP__ - _go32_dpmi_seginfo prev_int_9; -#else - void (__interrupt __far *prev_int_9)(); -#endif -} keyboard; - -static volatile keyboard key_data; - -static unsigned char Installed=0; - -unsigned char ascii_table[128] = -{ 255, 255, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',255,255, - 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', 255, 255, - 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 39, '`', - 255, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 255,'*', - 255, ' ', 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,255,255, - 255, 255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255 }; - -unsigned char shifted_ascii_table[128] = -{ 255, 255, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+',255,255, - 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', 255, 255, - 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', - 255, '|', 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?', 255,255, - 255, ' ', 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,255,255, - 255, 255, 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, - 255,255,255,255,255,255,255,255 }; -/* -char * key_text[256] = { -"","ESC","1","2","3","4","5","6","7","8","9","0","-", -"=","BSPC","TAB","Q","W","E","R","T","Y","U","I","O", -"P","[","]","ƒ","LCTRL","A","S","D","F", -"G","H","J","K","L",";","'","`", -"LSHFT","\\","Z","X","C","V","B","N","M",",", -".","/","RSHFT","PAD*","LALT","SPC", -"CPSLK","F1","F2","F3","F4","F5","F6","F7","F8","F9", -"F10","NMLCK","SCLK","PAD7","PAD8","PAD9","PAD-", -"PAD4","PAD5","PAD6","PAD+","PAD1","PAD2","PAD3","PAD0", -"PAD.","","","","F11","F12","","","","","","","","","", -"","","","","","","","","","","","","","","","","","","","", -"","","","","","","","","","","","","","","","","","","","", -"","","","","","","","","","","","","","","","","","", -"PADƒ","RCTRL","","","","","","","","","","","","","", -"","","","","","","","","","","PAD/","","","RALT","", -"","","","","","","","","","","","","","HOME","‚","PGUP", -"","","","","","END","€","PGDN","INS", -"DEL","","","","","","","","","","","","","","","","","", -"","","","","","","","","","","","","","","","","","","","", -"","","","","","","" }; -*/ -unsigned char key_to_ascii(int keycode ) -{ - int shifted; - - shifted = keycode & KEY_SHIFTED; - keycode &= 0xFF; - - if ( keycode>=127 ) - return 255; - - if (shifted) - return shifted_ascii_table[keycode]; - else - return ascii_table[keycode]; -} - -void key_clear_bios_buffer_all() -{ -#ifdef __WATCOMC__ - // Clear keyboard buffer... - *(ushort *)0x41a=*(ushort *)0x41c; - // Clear the status bits... - *(ubyte *)0x417 = 0; - *(ubyte *)0x418 = 0; -#else - _farpokew(_dos_ds,0x41a, _farpeekw(_dos_ds, 0x41c)); - _farpokeb(_dos_ds,0x417, 0); - _farpokeb(_dos_ds,0x418, 0); -#endif -} - -void key_clear_bios_buffer() -{ -#ifdef __WATCOMC__ - // Clear keyboard buffer... - *(ushort *)0x41a=*(ushort *)0x41c; -#else - _farpokew(_dos_ds,0x41a, _farpeekw(_dos_ds, 0x41c)); -#endif -} - -void key_flush() -{ - int i; - fix CurTime; - - _disable(); - - // Clear the BIOS buffer - key_clear_bios_buffer(); - - key_data.keyhead = key_data.keytail = 0; - - //Clear the keyboard buffer - for (i=0; i= KEY_BUFFER_SIZE ) n=0; - return n; -} - -// Returns 1 if character waiting... 0 otherwise -int key_checkch() -{ - int is_one_waiting = 0; - - _disable(); - - key_clear_bios_buffer(); - - if (key_data.keytail!=key_data.keyhead) - is_one_waiting = 1; - _enable(); - return is_one_waiting; -} - -int key_inkey() -{ - int key = 0; - - _disable(); - - key_clear_bios_buffer(); - - if (key_data.keytail!=key_data.keyhead) { - key = key_data.keybuffer[key_data.keyhead]; - key_data.keyhead = add_one(key_data.keyhead); - } - _enable(); - return key; -} - -int key_inkey_time(fix * time) -{ - int key = 0; - - _disable(); - - key_clear_bios_buffer(); - - if (key_data.keytail!=key_data.keyhead) { - key = key_data.keybuffer[key_data.keyhead]; - *time = key_data.time_pressed[key_data.keyhead]; - key_data.keyhead = add_one(key_data.keyhead); - } - _enable(); - return key; -} - - - -int key_peekkey() -{ - int key = 0; - - _disable(); - - key_clear_bios_buffer(); - - if (key_data.keytail!=key_data.keyhead) { - key = key_data.keybuffer[key_data.keyhead]; - } - _enable(); - return key; -} - -// If not installed, uses BIOS and returns getch(); -// Else returns pending key (or waits for one if none waiting). -int key_getch() -{ - int dummy=0; - - if (!Installed) - return getch(); - - while (!key_checkch()) - dummy++; - return key_inkey(); -} - -unsigned int key_get_shift_status() -{ - unsigned int shift_status = 0; - - _disable(); - - key_clear_bios_buffer(); - - if ( keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT] ) - shift_status |= KEY_SHIFTED; - - if ( keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] ) - shift_status |= KEY_ALTED; - - if ( keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL] ) - shift_status |= KEY_CTRLED; - -#ifndef NDEBUG - if (keyd_pressed[KEY_DELETE]) - shift_status |=KEY_DEBUGGED; -#endif - - _enable(); - - return shift_status; -} - -// Returns the number of seconds this key has been down since last call. -fix key_down_time(int scancode) { - fix time_down, time; - - if ((scancode<0)|| (scancode>255)) return 0; - -#ifndef NDEBUG - if (keyd_editor_mode && key_get_shift_status() ) - return 0; -#endif - - _disable(); - - if ( !keyd_pressed[scancode] ) { - time_down = key_data.TimeKeyHeldDown[scancode]; - key_data.TimeKeyHeldDown[scancode] = 0; - } else { - time = timer_get_fixed_secondsX(); - time_down = time - key_data.TimeKeyWentDown[scancode]; - key_data.TimeKeyWentDown[scancode] = time; - } - _enable(); - - return time_down; -} - -// Returns number of times key has went from up to down since last call. -unsigned int key_down_count(int scancode) { - int n; - - if ((scancode<0)|| (scancode>255)) return 0; - - _disable(); - n = key_data.NumDowns[scancode]; - key_data.NumDowns[scancode] = 0; - _enable(); - - return n; -} - - -// Returns number of times key has went from down to up since last call. -unsigned int key_up_count(int scancode) { - int n; - - if ((scancode<0)|| (scancode>255)) return 0; - - _disable(); - n = key_data.NumUps[scancode]; - key_data.NumUps[scancode] = 0; - _enable(); - - return n; -} - -// Use intrinsic forms so that we stay in the locked interrup code. - -#ifdef __WATCOMC__ -void Int5(); -#pragma aux Int5 = "int 5"; -#else -#ifdef __GNUC__ -#define Int5() asm volatile("int $5") -#endif -#endif - -#pragma off (check_stack) -void __interrupt __far key_handler() -{ - unsigned char scancode, breakbit, temp; - unsigned short keycode; - -#ifndef WATCOM_10 -#ifndef NDEBUG -#ifdef __WATCOMC__ /* must have _chain_intr */ - ubyte * MONO = (ubyte *)(0x0b0000+24*80*2); - if ( ((MONO[0]=='D') && (MONO[2]=='B') && (MONO[4]=='G') && (MONO[6]=='>')) || - ((MONO[14]=='<') && (MONO[16]=='i') && (MONO[18]=='>') && (MONO[20]==' ') && (MONO[22]=='-')) || - ((MONO[0]==200 ) && (MONO[2]==27) && (MONO[4]==17) ) - ) - _chain_intr( key_data.prev_int_9 ); -#endif -#endif -#endif - - // Read in scancode - scancode = inp( 0x60 ); - - switch( scancode ) { - case 0xE0: - key_data.E0Flag = 0x80; - break; - default: - // Parse scancode and break bit - if (key_data.E1Flag > 0 ) { // Special code for Pause, which is E1 1D 45 E1 9D C5 - key_data.E1Flag--; - if ( scancode == 0x1D ) { - scancode = KEY_PAUSE; - breakbit = 0; - } else if ( scancode == 0x9d ) { - scancode = KEY_PAUSE; - breakbit = 1; - } else { - break; // skip this keycode - } - } else if ( scancode==0xE1 ) { - key_data.E1Flag = 2; - break; - } else { - breakbit = scancode & 0x80; // Get make/break bit - scancode &= 0x7f; // Strip make/break bit off of scancode - scancode |= key_data.E0Flag; // Add in extended key code - } - key_data.E0Flag = 0; // Clear extended key code - - if (breakbit) { - // Key going up - keyd_last_released = scancode; - keyd_pressed[scancode] = 0; - key_data.NumUps[scancode]++; - temp = 0; - temp |= keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]; - temp |= keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT]; - temp |= keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL]; -#ifndef NDEBUG - temp |= keyd_pressed[KEY_DELETE]; - if ( !(keyd_editor_mode && temp) ) -#endif // NOTICE LINK TO ABOVE IF!!!! - key_data.TimeKeyHeldDown[scancode] += timer_get_fixed_secondsX() - key_data.TimeKeyWentDown[scancode]; - } else { - // Key going down - keyd_last_pressed = scancode; - keyd_time_when_last_pressed = timer_get_fixed_secondsX(); - if (!keyd_pressed[scancode]) { - // First time down - key_data.TimeKeyWentDown[scancode] = timer_get_fixed_secondsX(); - keyd_pressed[scancode] = 1; - key_data.NumDowns[scancode]++; -#ifndef NDEBUG - if ( (keyd_pressed[KEY_LSHIFT]) && (scancode == KEY_BACKSP) ) { - keyd_pressed[KEY_LSHIFT] = 0; - Int5(); - } -#endif - } else if (!keyd_repeat) { - // Don't buffer repeating key if repeat mode is off - scancode = 0xAA; - } - - if ( scancode!=0xAA ) { - keycode = scancode; - - if ( keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT] ) - keycode |= KEY_SHIFTED; - - if ( keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT] ) - keycode |= KEY_ALTED; - - if ( keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL] ) - keycode |= KEY_CTRLED; - -#ifndef NDEBUG - if ( keyd_pressed[KEY_DELETE] ) - keycode |= KEY_DEBUGGED; -#endif - - temp = key_data.keytail+1; - if ( temp >= KEY_BUFFER_SIZE ) temp=0; - - if (temp!=key_data.keyhead) { - key_data.keybuffer[key_data.keytail] = keycode; - key_data.time_pressed[key_data.keytail] = keyd_time_when_last_pressed; - key_data.keytail = temp; - } - } - } - } - -#ifndef NDEBUG -#ifdef PASS_KEYS_TO_BIOS - _chain_intr( key_data.prev_int_9 ); -#endif -#endif - - temp = inp(0x61); // Get current port 61h state - temp |= 0x80; // Turn on bit 7 to signal clear keybrd - outp( 0x61, temp ); // Send to port - temp &= 0x7f; // Turn off bit 7 to signal break - outp( 0x61, temp ); // Send to port - outp( 0x20, 0x20 ); // Reset interrupt controller -} - -#pragma on (check_stack) - -void key_handler_end() { // Dummy function to help calculate size of keyboard handler function -} - -void key_init() -{ - // Initialize queue - - keyd_time_when_last_pressed = timer_get_fixed_seconds(); - keyd_buffer_type = 1; - keyd_repeat = 1; - key_data.in_key_handler = 0; - key_data.E0Flag = 0; - key_data.E1Flag = 0; - - // Clear the keyboard array - key_flush(); - - if (Installed) return; - Installed = 1; - - //--------------- lock everything for the virtal memory ---------------------------------- - if (!dpmi_lock_region ((void near *)key_handler, (char *)key_handler_end - (char near *)key_handler)) { - printf( "Error locking keyboard handler!\n" ); - exit(1); - } - if (!dpmi_lock_region ((void *)&key_data, sizeof(keyboard))) { - printf( "Error locking keyboard handler's data1!\n" ); - exit(1); - } - if (!dpmi_lock_region (&keyd_buffer_type, sizeof(char))) { - printf( "Error locking keyboard handler's data2!\n" ); - exit(1); - } - if (!dpmi_lock_region (&keyd_repeat, sizeof(char))) { - printf( "Error locking keyboard handler's data3!\n" ); - exit(1); - } - if (!dpmi_lock_region (&keyd_editor_mode, sizeof(char))) { - printf( "Error locking keyboard handler's data4!\n" ); - exit(1); - } - if (!dpmi_lock_region ((void *)&keyd_last_pressed, sizeof(char))) { - printf( "Error locking keyboard handler's data5!\n" ); - exit(1); - } - if (!dpmi_lock_region ((void *)&keyd_last_released, sizeof(char))) { - printf( "Error locking keyboard handler's data6!\n" ); - exit(1); - } - if (!dpmi_lock_region ((void *)&keyd_pressed, sizeof(char)*256)) { - printf( "Error locking keyboard handler's data7!\n" ); - exit(1); - } - if (!dpmi_lock_region ((void *)&keyd_time_when_last_pressed, sizeof(int))) { - printf( "Error locking keyboard handler's data8!\n" ); - exit(1); - } - -#ifndef __DJGPP__ - key_data.prev_int_9 = (void *)_dos_getvect( 9 ); - _dos_setvect( 9, key_handler ); -#else - _go32_dpmi_get_protected_mode_interrupt_vector(9, - (_go32_dpmi_seginfo *)&key_data.prev_int_9); - kbd_hand_info.pm_offset = (int)key_handler; - kbd_hand_info.pm_selector = _my_cs(); - _go32_dpmi_allocate_iret_wrapper(&kbd_hand_info); - _go32_dpmi_set_protected_mode_interrupt_vector(9, &kbd_hand_info); -#endif - - atexit( key_close ); -} - -void key_close() -{ - if (!Installed) return; - Installed = 0; - -#ifndef __DJGPP__ - _dos_setvect( 9, key_data.prev_int_9 ); -#else - _go32_dpmi_set_protected_mode_interrupt_vector(9, - (_go32_dpmi_seginfo *)&key_data.prev_int_9); -#endif - - _disable(); - key_clear_bios_buffer_all(); - _enable(); - -} diff --git a/arch/dos/modex.asm b/arch/dos/modex.asm deleted file mode 100644 index 1f149eb7..00000000 --- a/arch/dos/modex.asm +++ /dev/null @@ -1,829 +0,0 @@ -;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -; -; $Source: /cvs/cvsroot/d2x/arch/dos/modex.asm,v $ -; $Revision: 1.1.1.1 $ -; $Author: bradleyb $ -; $Date: 2001-01-19 03:30:15 $ -; -; Routines to access ModeX VGA memory -; -; $Log: not supported by cvs2svn $ -; Revision 1.1.1.1 1999/06/14 21:57:56 donut -; Import of d1x 1.37 source. -; -; Revision 1.19 1995/03/01 15:37:46 john -; Better ModeX support. -; -; Revision 1.18 1994/11/24 13:24:20 john -; Made sure that some rep movs had the cld set first. -; Took some unused functions out. -; -; Revision 1.17 1994/09/22 18:15:02 john -; Made flip page wait for retrace. -; -; Revision 1.16 1994/09/22 16:08:27 john -; Fixed some palette stuff. -; -; Revision 1.15 1994/07/13 12:03:05 john -; Added assembly modex line-drawer. -; -; Revision 1.14 1994/05/06 12:50:34 john -; Added supertransparency; neatend things up; took out warnings. -; -; Revision 1.13 1994/05/03 19:39:04 john -; *** empty log message *** -; -; Revision 1.12 1994/02/18 15:32:32 john -; *** empty log message *** -; -; Revision 1.11 1993/12/21 11:40:36 john -; *** empty log message *** -; -; Revision 1.10 1993/12/09 15:02:26 john -; Changed palette stuff majorly -; -; Revision 1.9 1993/12/03 12:11:32 john -; fixed cx/ecx loop bugs. -; -; Revision 1.8 1993/11/16 11:28:18 john -; *** empty log message *** -; -; Revision 1.7 1993/10/15 16:23:23 john -; y -; -; Revision 1.6 1993/09/28 19:07:19 john -; stripped the waitforretrace out of fade to speed things up. -; -; Revision 1.5 1993/09/26 18:58:58 john -; fade stuff -; -; Revision 1.4 1993/09/21 14:01:15 john -; turned off video before mode set to reduce flicker. -; -; Revision 1.3 1993/09/08 11:38:36 john -; changed rcs stuff at beginning. -; -; -; - - -[BITS 32] - -section .data -%include "vgaregs.inc" -%include "tweak.inc" - -extern _gr_var_bwidth -extern _gr_video_memory - -global _modex_line_vertincr -global _modex_line_incr1 -global _modex_line_incr2 -global _modex_line_x1 -global _modex_line_x2 -global _modex_line_y1 -global _modex_line_y2 -global _modex_line_Color - -_modex_line_vertincr dd 0 -_modex_line_incr1 dd 0 -_modex_line_incr2 dd 0 -_modex_line_x1 dd 0 -_modex_line_y1 dd 0 -_modex_line_x2 dd 0 -_modex_line_y2 dd 0 -_modex_line_Color db 0 - - -_modex_line_routine dd 0 -SavedColor db 0 - -%define LEFT_MASK1 1000b -%define LEFT_MASK2 1100b -%define LEFT_MASK3 1110b -%define RIGHT_MASK1 0001b -%define RIGHT_MASK2 0011b -%define RIGHT_MASK3 0111b -%define ALL_MASK 1111b - -tmppal times 768 db 0 -fb_pal dd 0 -fb_add dw 0 -fb_count dd 0 - -MaskTable1 db ALL_MASK & RIGHT_MASK1 - db ALL_MASK & RIGHT_MASK2 - db ALL_MASK & RIGHT_MASK3 - db ALL_MASK - db LEFT_MASK3 & RIGHT_MASK1 - db LEFT_MASK3 & RIGHT_MASK2 - db LEFT_MASK3 & RIGHT_MASK3 - db LEFT_MASK3 - db LEFT_MASK2 & RIGHT_MASK1 - db LEFT_MASK2 & RIGHT_MASK2 - db LEFT_MASK2 & RIGHT_MASK3 - db LEFT_MASK2 - db LEFT_MASK1 & RIGHT_MASK1 - db LEFT_MASK1 & RIGHT_MASK2 - db LEFT_MASK1 & RIGHT_MASK3 - db LEFT_MASK1 - -MaskTable2 db ALL_MASK,RIGHT_MASK1 - db ALL_MASK,RIGHT_MASK2 - db ALL_MASK,RIGHT_MASK3 - db ALL_MASK,ALL_MASK - db LEFT_MASK3,RIGHT_MASK1 - db LEFT_MASK3,RIGHT_MASK2 - db LEFT_MASK3,RIGHT_MASK3 - db LEFT_MASK3,ALL_MASK - db LEFT_MASK2,RIGHT_MASK1 - db LEFT_MASK2,RIGHT_MASK2 - db LEFT_MASK2,RIGHT_MASK3 - db LEFT_MASK2,ALL_MASK - db LEFT_MASK1,RIGHT_MASK1 - db LEFT_MASK1,RIGHT_MASK2 - db LEFT_MASK1,RIGHT_MASK3 - db LEFT_MASK1,ALL_MASK - -DrawTable dd DrawMR - dd DrawMR - dd DrawMR - dd DrawM - dd DrawLMR - dd DrawLMR - dd DrawLMR - dd DrawLM - dd DrawLMR - dd DrawLMR - dd DrawLMR - dd DrawLM - dd DrawLMR - dd DrawLMR - dd DrawLMR - dd DrawLM - -section .text - -global _gr_sync_display - -_gr_sync_display: - mov dx, VERT_RESCAN -VS2A: in al, dx - and al, 08h - jnz VS2A ; Loop until not in vertical retrace -VS2B: in al, dx - and al, 08h - jz VS2B ; Loop until in vertical retrace - ret - - -; gr_modex_uscanline(int x1,int x2,int y,int color); -global _gr_modex_uscanline - -_gr_modex_uscanline: - push ebx - mov eax,[esp+8];x1 - mov edx,[esp+12];x2 - mov ebx,[esp+16];y - mov ecx,[esp+20];color - push edi - - ; EAX = X1 (X1 and X2 don't need to be sorted) - ; EDX = X2 - ; EBX = Y - ; ECX = Color - - mov [SavedColor], cl - - ;mov ebx, _RowOffset[ebx*4] - mov edi, [_gr_var_bwidth] - imul edi, ebx - add edi, [_gr_video_memory] - cmp eax, edx - jle @@f1 - xchg eax, edx -@@f1: mov bl, al - shl bl, 2 - mov bh, dl - and bh, 011b - or bl, bh - and ebx, 0fh - ; BX = LeftRight switch command. (4bit) - shr eax, 2 - shr edx, 2 - add edi, eax - ; EDI = Offset into video memory - mov ecx, edx - sub ecx, eax - ; ECX = X2/4 - X1/4 - 1 - jnz LargerThan4 - -;======================= ONE GROUP OF 4 OR LESS TO DRAW ==================== - - mov dx, SC_INDEX - mov al, SC_MAP_MASK - out dx, al - inc dx - mov al, [MaskTable1+ebx] - out dx, al - mov al, [SavedColor] - mov [edi], al ; Write the one pixel - pop edi - pop ebx - ret - -LargerThan4: - dec ecx - jnz LargerThan8 - -;===================== TWO GROUPS OF 4 OR LESS TO DRAW ==================== - - mov cx, word [MaskTable2+ebx*2] - mov bl, [SavedColor] - mov dx, SC_INDEX - mov al, SC_MAP_MASK - out dx, al - inc dx - mov al, cl - out dx, al - mov [edi], bl ; Write the left pixel - mov al, ch - out dx, al - mov [edi+1], bl ; Write the right pixel - pop edi - pop ebx - ret - -;========================= MANY GROUPS OF 4 TO DRAW ====================== -LargerThan8: - mov dx, SC_INDEX - mov al, SC_MAP_MASK - out dx, al - inc dx - ; DX = SC_INDEX - mov al, [SavedColor] - mov ah, al - ; AL,AH = color of pixel - jmp dword [DrawTable+ebx*4] - - -DrawM: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index - mov al, ALL_MASK - out dx, al - mov al, ah - cld - add ecx, 2 - shr ecx, 1 - rep stosw ; Write the middle pixels - jnc @@f2 - stosb ; Write the middle odd pixel -@@f2: pop edi - pop ebx - ret - -DrawLM: - ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index - mov al, byte [MaskTable2+ebx*2] - out dx, al - mov [edi], ah ; Write leftmost pixels - inc edi - mov al, ALL_MASK - out dx, al - mov al, ah - cld - inc ecx - shr ecx, 1 - rep stosw ; Write the middle pixels - jnc @@f3 - stosb ; Write the middle odd pixel -@@f3: pop edi - pop ebx - ret - - -DrawLMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index - mov bx, word [MaskTable2+ebx*2] - mov al, bl - out dx, al - mov [edi], ah ; Write leftmost pixels - inc edi - mov al, ALL_MASK - out dx, al - mov al, ah - cld - shr ecx, 1 - rep stosw ; Write the middle pixels - jnc @@f4 - stosb ; Write the middle odd pixel -@@f4: mov al, bh - out dx, al - mov [edi], ah ; Write the rightmost pixels - pop edi - pop ebx - ret - -DrawMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index - mov bx, word [MaskTable2+ebx*2] - mov al, ALL_MASK - out dx, al - mov al, ah - cld - inc ecx - shr ecx, 1 - rep stosw ; Write the middle pixels - jnc @@f5 - stosb ; Write the middle odd pixel -@@f5: mov al, bh - out dx, al - mov [edi], ah ; Write the rightmost pixels - pop edi - pop ebx - ret - - -global _gr_modex_setmode - -_gr_modex_setmode: - mov eax,[esp+4] - push ecx - push edx - push esi - push edi - - mov ecx, eax - dec ecx - - cmp ecx, LAST_X_MODE - jbe @@f6 - mov ecx, 0 -@@f6: - - ;call turn_screen_off - - push ecx ; some bios's dont preserve cx - - ;mov ax, 1201h - ;mov bl, 31h ; disable palette loading at mode switch - ;int 10h - mov ax,13h ; let the BIOS set standard 256-color - int 10h ; mode (320x200 linear) - ;mov ax, 1200h - ;mov bl, 31h ; enable palette loading at mode switch - ;int 10h - - pop ecx - - mov dx,SC_INDEX - mov ax,0604h - out dx,ax ; disable chain4 mode - - mov dx,SC_INDEX - mov ax,0100h - out dx,ax ; synchronous reset while setting Misc - ; Output for safety, even though clock - ; unchanged - - mov esi, dword [ModeTable+ecx*4] - lodsb - - or al,al - jz DontSetDot - - mov dx,MISC_OUTPUT - out dx,al ; select the dot clock and Horiz - ; scanning rate - - ;mov dx,SC_INDEX - ;mov al,01h - ;out dx,al - ;inc dx - ;in al, dx - ;or al, 1000b - ;out dx, al - -DontSetDot: - mov dx,SC_INDEX - mov ax,0300h - out dx,ax ; undo reset (restart sequencer) - - mov dx,CRTC_INDEX ; reprogram the CRT Controller - mov al,11h ; VSync End reg contains register write - out dx,al ; protect bit - inc dx ; CRT Controller Data register - in al,dx ; get current VSync End register setting - and al,07fh ; remove write protect on various - out dx,al ; CRTC registers - dec dx ; CRT Controller Index - cld - xor ecx,ecx - lodsb - mov cl,al - -SetCRTParmsLoop: - lodsw ; get the next CRT Index/Data pair - out dx,ax ; set the next CRT Index/Data pair - loop SetCRTParmsLoop - - mov dx,SC_INDEX - mov ax,0f02h - out dx,ax ; enable writes to all four planes - mov edi, [_gr_video_memory] ; point ES:DI to display memory - xor eax,eax ; clear to zero-value pixels - mov ecx,4000h ; # of dwords in display memory - rep stosd ; clear all of display memory - - ; Set pysical screen dimensions - - xor eax, eax - lodsw ; Load scrn pixel width - mov cx, ax - shl eax, 16 - - mov dx,CRTC_INDEX - mov al,CRTC_OFFSET - out dx,al - inc dx - mov ax,cx - shr ax,3 - out dx,al - - ;mov si, 360 - ;@@: - ;mov ax, 04f06h - ;mov bl, 0 - ;mov cx, si - ;int 10h - ;cmp cx, si - ;je @f - ;inc si - ;jmp @B - ;@@: - ;movzx eax, si - - lodsw ; Load Screen Phys. Height - - ;call turn_screen_on - - pop edi - pop esi - pop edx - pop ecx - - ret - -global _gr_modex_setplane - -_gr_modex_setplane: - mov eax,[esp+4] - - mov cl, al - - ; SELECT WRITE PLANE - and cl,011b ;CL = plane - mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg - shl ah,cl ;set only the bit for the required - ; plane to 1 - mov dx,SC_INDEX ;set the Map Mask to enable only the - out dx,ax ; pixel's plane - - ; SELECT READ PLANE - mov ah,cl ;AH = plane - mov al,READ_MAP ;AL = index in GC of the Read Map reg - mov dx,GC_INDEX ;set the Read Map to read the pixel's - out dx,ax ; plane - ret - -global _gr_modex_setstart - -_gr_modex_setstart: - push ebx - mov eax,[esp+8] - mov edx,[esp+12] - mov ebx,[esp+16] - push ebx - - ; EAX = X - ; EDX = Y - ; EBX = Wait for retrace - - mov ecx, [_gr_var_bwidth] - imul ecx, edx - - shr eax, 2 - add eax, ecx - - mov ch, ah - mov bh, al - - mov bl, CC_START_LO - mov cl, CC_START_HI - - cli - mov dx, VERT_RESCAN -WaitDE: in al, dx - test al, 01h - jnz WaitDE - - mov dx, CRTC_INDEX - mov ax, bx - out dx, ax ; Start address low - mov ax, cx - out dx, ax ; Start address high - sti - - pop ebx - cmp ebx, 0 - je NoWaitVS - mov dx, VERT_RESCAN -WaitVS: in al, dx - test al, 08h - jz WaitVS ; Loop until in vertical retrace -NoWaitVS: - - pop ebx - - ret - - - - -%macro ModeXAddr 0 -; given: ebx=x, eax=y, return cl=plane mask, ebx=address, trash eax - mov cl, bl - and cl, 3 - shr ebx, 2 - imul eax, [_gr_var_bwidth] - add ebx, eax - add ebx, [_gr_video_memory] -%endmacro - - -;----------------------------------------------------------------------- -; -; Line drawing function for all MODE X 256 Color resolutions -; Based on code from "PC and PS/2 Video Systems" by Richard Wilton. - -global _gr_modex_line - -_gr_modex_line: - pusha - - mov dx,SC_INDEX ; setup for plane mask access - -; check for vertical line - - mov esi,[_gr_var_bwidth] - mov ecx,[_modex_line_x2] - sub ecx,[_modex_line_x1] - jz near VertLine - -; force x1 < x2 - - jns L01 - - neg ecx - - mov ebx,[_modex_line_x2] - xchg ebx,[_modex_line_x1] - mov [_modex_line_x2],ebx - - mov ebx,[_modex_line_y2] - xchg ebx,[_modex_line_y1] - mov [_modex_line_y2],ebx - -; calc dy = abs(y2 - y1) - -L01: - mov ebx,[_modex_line_y2] - sub ebx,[_modex_line_y1] - jnz short skip - jmp HorizLine -skip: jns L03 - - neg ebx - neg esi - -; select appropriate routine for slope of line - -L03: - mov [_modex_line_vertincr],esi - mov dword [_modex_line_routine],LoSlopeLine - cmp ebx,ecx - jle L04 - mov dword [_modex_line_routine],HiSlopeLine - xchg ebx,ecx - -; calc initial decision variable and increments - -L04: - shl ebx,1 - mov [_modex_line_incr1],ebx - sub ebx,ecx - mov esi,ebx - sub ebx,ecx - mov [_modex_line_incr2],ebx - -; calc first pixel address - - push ecx - mov eax,[_modex_line_y1] - mov ebx,[_modex_line_x1] - ModeXAddr - mov edi,ebx - mov al,1 - shl al,cl - mov ah,al ; duplicate nybble - shl al,4 - add ah,al - mov bl,ah - pop ecx - inc ecx - jmp near dword [_modex_line_routine] - -; routine for verticle lines - -VertLine: - mov eax,[_modex_line_y1] - mov ebx,[_modex_line_y2] - mov ecx,ebx - sub ecx,eax - jge L31 - neg ecx - mov eax,ebx - -L31: - inc ecx - mov ebx,[_modex_line_x1] - push ecx - ModeXAddr - - mov ah,1 - shl ah,cl - mov al,MAP_MASK - out dx,ax - pop ecx - mov ax, word [_modex_line_Color] - -; draw the line - -L32: - mov [ebx],al - add ebx,esi - loop L32 - jmp Lexit - -; routine for horizontal line - -HorizLine: - - mov eax,[_modex_line_y1] - mov ebx,[_modex_line_x1] - ModeXAddr - - mov edi,ebx ; set dl = first byte mask - mov dl,00fh - shl dl,cl - - mov ecx,[_modex_line_x2] ; set dh = last byte mask - and cl,3 - mov dh,00eh - shl dh,cl - not dh - -; determine byte offset of first and last pixel in line - - mov eax,[_modex_line_x2] - mov ebx,[_modex_line_x1] - - shr eax,2 ; set ax = last byte column - shr ebx,2 ; set bx = first byte column - mov ecx,eax ; cx = ax - bx - sub ecx,ebx - - mov eax,edx ; mov end byte masks to ax - mov dx,SC_INDEX ; setup dx for VGA outs - mov bl,[_modex_line_Color] - -; set pixels in leftmost byte of line - - or ecx,ecx ; is start and end pt in same byte - jnz L42 ; no ! - and ah,al ; combine start and end masks - jmp short L44 - -L42: push eax - mov ah,al - mov al,MAP_MASK - out dx,ax - mov al,bl - stosb - dec ecx - -; draw remainder of the line - -L43: - mov ah,0Fh - mov al,MAP_MASK - out dx,ax - mov al,bl - rep stosb - pop eax - -; set pixels in rightmost byte of line - -L44: - mov al,MAP_MASK - out dx, ax - mov [edi],bl - jmp Lexit - - -; routine for dy >= dx (slope <= 1) - -LoSlopeLine: - mov al,MAP_MASK - mov bh,byte [_modex_line_Color] -L10: - mov ah,bl - -L11: - or ah,bl - rol bl,1 - jc L14 - -; bit mask not shifted out - - or esi,esi - jns L12 - add esi,[_modex_line_incr1] - loop L11 - - out dx,ax - mov [edi],bh - jmp short Lexit - -L12: - add esi,[_modex_line_incr2] - out dx,ax - mov [edi],bh - add edi,[_modex_line_vertincr] - loop L10 - jmp short Lexit - -; bit mask shifted out - -L14: out dx,ax - mov [edi],bh - inc edi - or esi,esi - jns L15 - add esi,[_modex_line_incr1] - loop L10 - jmp short Lexit - -L15: - add esi,[_modex_line_incr2] - add edi,[_modex_line_vertincr] - loop L10 - jmp short Lexit - -; routine for dy > dx (slope > 1) - -HiSlopeLine: - mov ebx,[_modex_line_vertincr] - mov al,MAP_MASK -L21: out dx,ax - push eax - mov al,[_modex_line_Color] - mov [edi],al - pop eax - add edi,ebx - -L22: - or esi,esi - jns L23 - - add esi,[_modex_line_incr1] - loop L21 - jmp short Lexit - -L23: - add esi,[_modex_line_incr2] - rol ah,1 - adc edi,0 -lx21: loop L21 - -; return to caller - -Lexit: - popa - ret diff --git a/arch/dos/mouse.c b/arch/dos/mouse.c deleted file mode 100644 index da635a02..00000000 --- a/arch/dos/mouse.c +++ /dev/null @@ -1,655 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ -/* - * $Source: /cvs/cvsroot/d2x/arch/dos/mouse.c,v $ - * $Revision: 1.1.1.2 $ - * $Author: bradleyb $ - * $Date: 2001-01-19 03:33:52 $ - * - * Functions to access Mouse and Cyberman... - * - * $Log: not supported by cvs2svn $ - * Revision 1.1.1.1 1999/06/14 21:58:38 donut - * Import of d1x 1.37 source. - * - * Revision 1.11 1995/02/10 18:52:17 john - * Fixed bug with mouse not getting closed. - * - * Revision 1.10 1995/02/02 11:10:33 john - * Changed a bunch of mouse stuff around to maybe get - * around PS/2 mouse hang. - * - * Revision 1.9 1995/01/14 19:19:52 john - * Fixed signed short error cmp with -1 that caused mouse - * to break under Watcom 10.0 - * - * Revision 1.8 1994/12/27 12:38:23 john - * Made mouse use temporary dos buffer instead of - * - * allocating its own. - * - * - * Revision 1.7 1994/12/05 23:54:53 john - * Fixed bug with mouse_get_delta only returning positive numbers.. - * - * Revision 1.6 1994/11/18 23:18:18 john - * Changed some shorts to ints. - * - * Revision 1.5 1994/09/13 12:34:02 john - * Added functions to get down count and state. - * - * Revision 1.4 1994/08/29 20:52:19 john - * Added better cyberman support; also, joystick calibration - * value return funcctiionn, - * - * Revision 1.3 1994/08/24 18:54:32 john - * *** empty log message *** - * - * Revision 1.2 1994/08/24 18:53:46 john - * Made Cyberman read like normal mouse; added dpmi module; moved - * mouse from assembly to c. Made mouse buttons return time_down. - * - * Revision 1.1 1994/08/24 13:56:37 john - * Initial revision - * - * - */ - -#include - -#ifdef __DJGPP__ -#include -#define _BORLAND_DOS_REGS 1 -#define near -_go32_dpmi_registers handler_regs; -#endif - -#include - -#include -#include -//#include -#include -//#include -#include - -#include "error.h" -#include "fix.h" -#include "u_dpmi.h" -#include "mouse.h" -#include "timer.h" - -#define ME_CURSOR_MOVED (1<<0) -#define ME_LB_P (1<<1) -#define ME_LB_R (1<<2) -#define ME_RB_P (1<<3) -#define ME_RB_R (1<<4) -#define ME_MB_P (1<<5) -#define ME_MB_R (1<<6) -#define ME_OB_P (1<<7) -#define ME_OB_R (1<<8) -#define ME_X_C (1<<9) -#define ME_Y_C (1<<10) -#define ME_Z_C (1<<11) -#define ME_P_C (1<<12) -#define ME_B_C (1<<13) -#define ME_H_C (1<<14) -#define ME_O_C (1<<15) - -#define MOUSE_MAX_BUTTONS 11 - -typedef struct event_info { - short x; - short y; - short z; - short pitch; - short bank; - short heading; - ushort button_status; - ushort device_dependant; -} event_info; - -typedef struct mouse_info { - fix ctime; - ubyte cyberman; - int num_buttons; - ubyte pressed[MOUSE_MAX_BUTTONS]; - fix time_went_down[MOUSE_MAX_BUTTONS]; - fix time_held_down[MOUSE_MAX_BUTTONS]; - uint num_downs[MOUSE_MAX_BUTTONS]; - uint num_ups[MOUSE_MAX_BUTTONS]; - event_info *x_info; - ushort button_status; -} mouse_info; - -typedef struct cyberman_info { - ubyte device_type; - ubyte major_version; - ubyte minor_version; - ubyte x_descriptor; - ubyte y_descriptor; - ubyte z_descriptor; - ubyte pitch_descriptor; - ubyte roll_descriptor; - ubyte yaw_descriptor; - ubyte reserved; -} cyberman_info; - -static mouse_info Mouse; - -static int Mouse_installed = 0; - -#ifdef __DJGPP__ -#define m_ax r->d.eax -#define mbx r->d.ebx -#define mcx r->d.ecx -#define mdx r->d.edx -#define msi r->d.esi -#define mdi r->d.edi -void mouse_handler (_go32_dpmi_registers *r) -{ -#else -#pragma off (check_stack) -void _loadds far mouse_handler (int m_ax, int mbx, int mcx, int mdx, int msi, int mdi) -{ -#pragma aux mouse_handler parm [EAX] [EBX] [ECX] [EDX] [ESI] [EDI] -#endif - Mouse.ctime = timer_get_fixed_secondsX(); - - if (m_ax & ME_LB_P) { // left button pressed - if (!Mouse.pressed[MB_LEFT]) { - Mouse.pressed[MB_LEFT] = 1; - Mouse.time_went_down[MB_LEFT] = Mouse.ctime; - } - Mouse.num_downs[MB_LEFT]++; - } else if (m_ax & ME_LB_R ) { // left button released - if (Mouse.pressed[MB_LEFT]) { - Mouse.pressed[MB_LEFT] = 0; - Mouse.time_held_down[MB_LEFT] += Mouse.ctime-Mouse.time_went_down[MB_LEFT]; - } - Mouse.num_ups[MB_LEFT]++; - } - - if (m_ax & ME_RB_P ) { // right button pressed - if (!Mouse.pressed[MB_RIGHT]) { - Mouse.pressed[MB_RIGHT] = 1; - Mouse.time_went_down[MB_RIGHT] = Mouse.ctime; - } - Mouse.num_downs[MB_RIGHT]++; - } else if (m_ax & ME_RB_R ) {// right button released - if (Mouse.pressed[MB_RIGHT]) { - Mouse.pressed[MB_RIGHT] = 0; - Mouse.time_held_down[MB_RIGHT] += Mouse.ctime-Mouse.time_went_down[MB_RIGHT]; - } - Mouse.num_ups[MB_RIGHT]++; - } - - if (m_ax & ME_MB_P ) { // middle button pressed - if (!Mouse.pressed[MB_MIDDLE]) { - Mouse.pressed[MB_MIDDLE] = 1; - Mouse.time_went_down[MB_MIDDLE] = Mouse.ctime; - } - Mouse.num_downs[MB_MIDDLE]++; - } else if (m_ax & ME_MB_R ) { // middle button released - if (Mouse.pressed[MB_MIDDLE]) { - Mouse.pressed[MB_MIDDLE] = 0; - Mouse.time_held_down[MB_MIDDLE] += Mouse.ctime-Mouse.time_went_down[MB_MIDDLE]; - } - Mouse.num_ups[MB_MIDDLE]++; - } - - if (Mouse.cyberman && (m_ax & (ME_Z_C|ME_P_C|ME_B_C|ME_H_C))) { - Mouse.x_info = (event_info *)((msi & 0xFFFF) << 4); - - if (m_ax & ME_Z_C ) { // z axis changed - if (Mouse.pressed[MB_Z_UP]) { - // z up released - Mouse.pressed[MB_Z_UP] = 0; - Mouse.time_held_down[MB_Z_UP] += Mouse.ctime-Mouse.time_went_down[MB_Z_UP]; - Mouse.num_ups[MB_Z_UP]++; - } else if ( Mouse.x_info->z>0 ) { - // z up pressed - Mouse.pressed[MB_Z_UP] = 1; - Mouse.time_went_down[MB_Z_UP]=Mouse.ctime; - Mouse.num_downs[MB_Z_UP]++; - } - if (Mouse.pressed[MB_Z_DOWN]) { - // z down released - Mouse.pressed[MB_Z_DOWN] = 0; - Mouse.time_held_down[MB_Z_DOWN] += Mouse.ctime-Mouse.time_went_down[MB_Z_DOWN]; - Mouse.num_ups[MB_Z_DOWN]++; - } else if ( Mouse.x_info->z<0 ) { - // z down pressed - Mouse.pressed[MB_Z_DOWN] = 1; - Mouse.time_went_down[MB_Z_DOWN]=Mouse.ctime; - Mouse.num_downs[MB_Z_DOWN]++; - } - } - if (m_ax & ME_P_C ) { // pitch changed - if (Mouse.pressed[MB_PITCH_BACKWARD]) { - // pitch backward released - Mouse.pressed[MB_PITCH_BACKWARD] = 0; - Mouse.time_held_down[MB_PITCH_BACKWARD] += Mouse.ctime-Mouse.time_went_down[MB_PITCH_BACKWARD]; - Mouse.num_ups[MB_PITCH_BACKWARD]++; - } else if ( Mouse.x_info->pitch>0 ) { - // pitch backward pressed - Mouse.pressed[MB_PITCH_BACKWARD] = 1; - Mouse.time_went_down[MB_PITCH_BACKWARD]=Mouse.ctime; - Mouse.num_downs[MB_PITCH_BACKWARD]++; - } - if (Mouse.pressed[MB_PITCH_FORWARD]) { - // pitch forward released - Mouse.pressed[MB_PITCH_FORWARD] = 0; - Mouse.time_held_down[MB_PITCH_FORWARD] += Mouse.ctime-Mouse.time_went_down[MB_PITCH_FORWARD]; - Mouse.num_ups[MB_PITCH_FORWARD]++; - } else if ( Mouse.x_info->pitch<0 ) { - // pitch forward pressed - Mouse.pressed[MB_PITCH_FORWARD] = 1; - Mouse.time_went_down[MB_PITCH_FORWARD]=Mouse.ctime; - Mouse.num_downs[MB_PITCH_FORWARD]++; - } - } - - if (m_ax & ME_B_C ) { // bank changed - if (Mouse.pressed[MB_BANK_LEFT]) { - // bank left released - Mouse.pressed[MB_BANK_LEFT] = 0; - Mouse.time_held_down[MB_BANK_LEFT] += Mouse.ctime-Mouse.time_went_down[MB_BANK_LEFT]; - Mouse.num_ups[MB_BANK_LEFT]++; - } else if ( Mouse.x_info->bank>0 ) { - // bank left pressed - Mouse.pressed[MB_BANK_LEFT] = 1; - Mouse.time_went_down[MB_BANK_LEFT]=Mouse.ctime; - Mouse.num_downs[MB_BANK_LEFT]++; - } - if (Mouse.pressed[MB_BANK_RIGHT]) { - // bank right released - Mouse.pressed[MB_BANK_RIGHT] = 0; - Mouse.time_held_down[MB_BANK_RIGHT] += Mouse.ctime-Mouse.time_went_down[MB_BANK_RIGHT]; - Mouse.num_ups[MB_BANK_RIGHT]++; - } else if ( Mouse.x_info->bank<0 ) { - // bank right pressed - Mouse.pressed[MB_BANK_RIGHT] = 1; - Mouse.time_went_down[MB_BANK_RIGHT]=Mouse.ctime; - Mouse.num_downs[MB_BANK_RIGHT]++; - } - } - - if (m_ax & ME_H_C ) { // heading changed - if (Mouse.pressed[MB_HEAD_LEFT]) { - // head left released - Mouse.pressed[MB_HEAD_LEFT] = 0; - Mouse.time_held_down[MB_HEAD_LEFT] += Mouse.ctime-Mouse.time_went_down[MB_HEAD_LEFT]; - Mouse.num_ups[MB_HEAD_LEFT]++; - } else if ( Mouse.x_info->heading>0 ) { - // head left pressed - Mouse.pressed[MB_HEAD_LEFT] = 1; - Mouse.time_went_down[MB_HEAD_LEFT]=Mouse.ctime; - Mouse.num_downs[MB_HEAD_LEFT]++; - } - if (Mouse.pressed[MB_HEAD_RIGHT]) { - // head right released - Mouse.pressed[MB_HEAD_RIGHT] = 0; - Mouse.time_held_down[MB_HEAD_RIGHT] += Mouse.ctime-Mouse.time_went_down[MB_HEAD_RIGHT]; - Mouse.num_ups[MB_HEAD_RIGHT]++; - } else if ( Mouse.x_info->heading<0 ) { - // head right pressed - Mouse.pressed[MB_HEAD_RIGHT] = 1; - Mouse.time_went_down[MB_HEAD_RIGHT]=Mouse.ctime; - Mouse.num_downs[MB_HEAD_RIGHT]++; - } - } - } - -} - - - - -void mouse_handler_end (void) // dummy functions -{ -} -#pragma on (check_stack) - -//-------------------------------------------------------- -// returns 0 if no mouse -// else number of buttons -int mouse_init(int enable_cyberman) -{ - dpmi_real_regs rr; - cyberman_info *ci; -#ifndef __DJGPP__ - struct SREGS sregs; -#endif - union REGS inregs, outregs; - ubyte *Mouse_dos_mem; - - if (Mouse_installed) - return Mouse.num_buttons; - -#ifdef __DJGPP__ - if (_farpeekl(_dos_ds, 0x33 * 4) == 0) { -#else - if (_dos_getvect(0x33) == NULL) { -#endif - // No mouse driver loaded - return 0; - } - - // Reset the mouse driver - memset( &inregs, 0, sizeof(inregs) ); - inregs.w.ax = 0; - int386(0x33, &inregs, &outregs); - if (outregs.w.ax != 0xffff) - return 0; - - Mouse.num_buttons = outregs.w.bx; - Mouse.cyberman = 0; - - // Enable mouse driver - memset( &inregs, 0, sizeof(inregs) ); - inregs.w.ax = 0x0020; - int386(0x33, &inregs, &outregs); - if (outregs.w.ax != 0xffff ) - return 0; - - if ( enable_cyberman ) { - Mouse_dos_mem = dpmi_get_temp_low_buffer( 64 ); - if (Mouse_dos_mem==NULL) { - printf( "Unable to allocate DOS buffer in mouse.c\n" ); - } else { - // Check for Cyberman... - memset( &rr, 0, sizeof(dpmi_real_regs) ); - rr.es = DPMI_real_segment(Mouse_dos_mem); - rr.edx = DPMI_real_offset(Mouse_dos_mem); - rr.eax = 0x53c1; - dpmi_real_int386x( 0x33, &rr ); - if (rr.eax==1) { - // SWIFT functions supported - ci = (cyberman_info *)Mouse_dos_mem; - if (ci->device_type==1) { // Cyberman - Mouse.cyberman = 1; - //printf( "Cyberman mouse detected\n" ); - Mouse.num_buttons = 11; - } - } - } - } - - if (!dpmi_lock_region(&Mouse,sizeof(mouse_info))) { - printf( "Unable to lock mouse data region" ); - exit(1); - } - if (!dpmi_lock_region((void near *)mouse_handler,(char *)mouse_handler_end - (char near *)mouse_handler)) { - printf( "Unable to lock mouse handler" ); - exit(1); - } - - // Install mouse handler -#ifdef __DJGPP__ - { - dpmi_real_regs rregs; - _go32_dpmi_seginfo info; - memset(&rregs, 0, sizeof(rregs)); - info.pm_offset = (unsigned int)&mouse_handler; - if (_go32_dpmi_allocate_real_mode_callback_retf(&info, &handler_regs)) { - printf( "Unable allocate mouse handler callback" ); - exit(1); - } - rregs.eax = 0xC; - rregs.ecx = ME_LB_P|ME_LB_R|ME_RB_P|ME_RB_R|ME_MB_P|ME_MB_R; // watch all 3 button ups/downs - if (Mouse.cyberman) - rregs.ecx |= ME_Z_C| ME_P_C| ME_B_C| ME_H_C; // if using a cyberman, also watch z, pitch, bank, heading. - rregs.edx = info.rm_offset; - rregs.es = info.rm_segment; - dpmi_real_int386x( 0x33, &rregs ); - } -#else - memset( &inregs, 0, sizeof(inregs)); - memset( &sregs, 0, sizeof(sregs)); - inregs.w.ax = 0xC; - inregs.w.cx = ME_LB_P|ME_LB_R|ME_RB_P|ME_RB_R|ME_MB_P|ME_MB_R; // watch all 3 button ups/downs - if (Mouse.cyberman) - inregs.w.cx |= ME_Z_C| ME_P_C| ME_B_C| ME_H_C; // if using a cyberman, also watch z, pitch, bank, heading. - inregs.x.edx = FP_OFF(mouse_handler); - sregs.es = FP_SEG(mouse_handler); - int386x(0x33, &inregs, &outregs, &sregs); -#endif - - Mouse_installed = 1; - - atexit( mouse_close ); - - mouse_flush(); - - return Mouse.num_buttons; -} - - - -void mouse_close() -{ - struct SREGS sregs; - union REGS inregs, outregs; - - if (Mouse_installed) { - Mouse_installed = 0; - // clear mouse handler by setting flags to 0. - memset( &inregs, 0, sizeof(inregs)); - memset( &sregs, 0, sizeof(sregs)); - inregs.w.ax = 0xC; - inregs.w.cx = 0; // disable event handler by setting to zero. - inregs.x.edx = 0; - sregs.es = 0; - int386x(0x33, &inregs, &outregs, &sregs); - } -} - - -void mouse_set_limits( int x1, int y1, int x2, int y2 ) -{ - union REGS inregs, outregs; - - if (!Mouse_installed) return; - - memset( &inregs, 0, sizeof(inregs)); - inregs.w.ax = 0x7; // Set Horizontal Limits for Pointer - inregs.w.cx = x1; - inregs.w.dx = x2; - int386(0x33, &inregs, &outregs); - - memset( &inregs, 0, sizeof(inregs)); - inregs.w.ax = 0x8; // Set Vertical Limits for Pointer - inregs.w.cx = y1; - inregs.w.dx = y2; - int386(0x33, &inregs, &outregs); -} - -void mouse_get_pos( int *x, int *y) -{ - union REGS inregs, outregs; - - if (!Mouse_installed) { - *x = *y = 0; - return; - } - memset( &inregs, 0, sizeof(inregs)); - inregs.w.ax = 0x3; // Get Mouse Position and Button Status - int386(0x33, &inregs, &outregs); - *x = (short)outregs.w.cx; - *y = (short)outregs.w.dx; -} - -void mouse_get_delta( int *dx, int *dy ) -{ - union REGS inregs, outregs; - - if (!Mouse_installed) { - *dx = *dy = 0; - return; - } - - memset( &inregs, 0, sizeof(inregs)); - inregs.w.ax = 0xb; // Read Mouse motion counters - int386(0x33, &inregs, &outregs); - *dx = (short)outregs.w.cx; - *dy = (short)outregs.w.dx; -} - -int mouse_get_btns() -{ - int i; - uint flag=1; - int status = 0; - - if (!Mouse_installed) - return 0; - - for (i=0; ix+8128)*256)/(8064+8128+1)) - 127; - *y = (((ei->y+8128)*256)/(8064+8128+1)) - 127; -} - diff --git a/arch/dos/timer.asm b/arch/dos/timer.asm deleted file mode 100644 index e738fe61..00000000 --- a/arch/dos/timer.asm +++ /dev/null @@ -1,496 +0,0 @@ -[BITS 32] - -[EXTERN _atexit] -[EXTERN ___djgpp_base_address] - -[GLOBAL _timer_get_fixed_seconds] -[GLOBAL _timer_get_fixed_secondsX] -[GLOBAL _timer_get_approx_seconds] -[GLOBAL _timer_set_rate] -[GLOBAL _timer_set_function] -[GLOBAL _timer_set_joyhandler] -[GLOBAL _timer_init] -[GLOBAL _timer_close] - - -[SECTION .data] -TDATA EQU 40h -TCOMMAND EQU 43h -PIC EQU 020h -STACK_SIZE EQU 4096 - -%define df times 3 dw - -TimerData db 0 - dd 0 - dd 65536 - dd 0 - dd 0 - df 0 - df 0 - df 0 - df 0 - dd 0 - db 0 -times STACK_SIZE db 0 - -td_in_timer equ TimerData -td_nested_counter equ td_in_timer+1 -td__timer_cnt equ td_nested_counter+4 -td_dos_timer equ td__timer_cnt+4 -td_joystick_poller equ td_dos_timer+4 -td_user_function equ td_joystick_poller+4 -td_org_interrupt equ td_user_function+6 -td_saved_stack equ td_org_interrupt+6 -td_new_stack equ td_saved_stack+6 -td_tick_count equ td_new_stack+6 -td_Installed equ td_tick_count+4 -td_TimerStack equ td_Installed+1 - - -[SECTION .text] - -TIMER_LOCKED_CODE_START: - -__my_ds dw 0 - -timer_get_stamp64: -; Return a 64-bit stamp that is the number of 1.19Mhz pulses -; since the time was initialized. Returns in EDX:EAX. -; Also, interrupts must be disabled. - - xor eax, eax ; Clear all of EAX - out TCOMMAND, al ; Tell timer to latch - - mov al, 0ah ; Find if interrupt pending - out PIC, al - jmp @ - @: - in al, PIC - and eax, 01b - jz NoInterrupt - - in al, TDATA ; Read in lo byte - mov dl, al - in al, TDATA ; Read in hi byte - mov dh, al - and edx, 0ffffh - mov eax, [td__timer_cnt] - shl eax, 1 - sub eax, edx - - push ebx - mov ebx, eax - mov eax, [td_tick_count] - imul dword [td__timer_cnt] ; edx:eax = Number of 1.19 MHz ticks elapsed... - add eax, ebx - adc edx, 0 - pop ebx - - ret - -NoInterrupt: - in al, TDATA ; Read in lo byte - mov ah, al - in al, TDATA ; Read in hi byte - xchg ah, al ; arrange em correctly - mov edx, [td__timer_cnt] - sub dx, ax ; BX = timer ticks - mov ax, dx - - push ebx - mov ebx, eax - mov eax, [td_tick_count] - imul dword [td__timer_cnt] ; edx:eax = Number of 1.19 MHz ticks elapsed... - add eax, ebx - adc edx, 0 - pop ebx - - ret - - -_timer_get_fixed_seconds: - push ebx - push edx - - cli - call timer_get_stamp64 - sti - -; Timing in fixed point (16.16) seconds. -; Can be used for up to 1000 hours - shld edx, eax, 16 ; Keep 32+11 bits - shl eax, 16 -; edx:eax = number of 1.19Mhz pulses elapsed. - mov ebx, 1193180 - -; Make sure we won't divide overflow. Make time wrap at about 9 hours -sub_again: - sub edx, ebx ; subtract until negative... - jns sub_again ; ...to prevent divide overflow... - add edx, ebx ; ...then add in to get correct value. - div ebx -; eax = fixed point seconds elapsed... - - pop edx - pop ebx - - ret - - -_timer_get_fixed_secondsX: - push ebx - push edx - - call timer_get_stamp64 - -; Timing in fixed point (16.16) seconds. -; Can be used for up to 1000 hours - shld edx, eax, 16 ; Keep 32+11 bits - shl eax, 16 -; edx:eax = number of 1.19Mhz pulses elapsed. - mov ebx, 1193180 - -xsub_again: - sub edx, ebx ; subtract until negative... - jns xsub_again ; ...to prevent divide overflow... - add edx, ebx ; ...then add in to get correct value. - - div ebx -; eax = fixed point seconds elapsed... - - pop edx - pop ebx - - ret - -_timer_get_approx_seconds: - push ebx - push edx - - mov eax, [td_tick_count] - imul dword [td__timer_cnt] ; edx:eax = Number of 1.19 MHz ticks elapsed... - shld edx, eax, 16 ; Keep 32+16 bits, for conversion to fixed point - shl eax, 16 -; edx:eax = number of 1.19Mhz pulses elapsed. - mov ebx, 1193180 - -approx_sub_again: - sub edx, ebx ; subtract until negative... - jns approx_sub_again ; ...to prevent divide overflow... - add edx, ebx ; ...then add in to get correct value. - - div ebx -; eax = fixed point seconds elapsed... - - pop edx - pop ebx - ret - -;---------------------------------------------------------------------------- -;Prototype: extern void timer_set_rate(int count_val); -;---------------------------------------------------------------------------- -_timer_set_rate: - mov eax,[esp+4] -; eax = rate - pushad - -; Make sure eax below or equal to 65535 and above 0 -; if its not, make it be 65536 which is normal dos -; timing. - cmp eax, 65535 - jbe @@ - mov eax, 65536 -@@: - cmp eax, 0 - jne @@@ - mov eax, 65536 -@@@: ; Set the timer rate to eax - cli - mov dword [td_tick_count], 0 - mov [td__timer_cnt], eax - mov al, 34h ; count in binary, mode 2, load low byte then hi byte, counter 0: 00 11 010 0 - out TCOMMAND, al ; Reset PIT channel 0 - mov eax, [td__timer_cnt] - out TDATA, al - mov al, ah - out TDATA, al - sti - popad - ret - -;---------------------------------------------------------------------------- -;Prototype: extern void timer_set_function( void * function ); -;---------------------------------------------------------------------------- -_timer_set_function: -; arg1 = near pointer to user function - push eax - mov eax, [esp+8] ; arg 1 - cli - mov dword [td_user_function+0], eax ; offset - mov word [td_user_function+4], cs ; selector - sti - pop eax - ret - -_timer_set_joyhandler: - mov eax, [esp+4] - cli - mov dword [td_joystick_poller], eax - sti - ret - -;************************************************************************ -;************************************************************************ -;***** ***** -;***** T I M E R _ H A N D L E R ***** -;***** ***** -;************************************************************************ -;************************************************************************ - -timer_handler: - push ds - push es - push eax - - mov ax, [cs:__my_ds] ; Interrupt, so point to our data segment - mov ds, ax - mov es, ax - -; Increment time counter... - inc dword [td_tick_count] - - mov eax, [td__timer_cnt] - add dword [td_dos_timer], eax ; Increment DOS timer - cmp dword [td_dos_timer], 65536 - jb NoChainToOld ; See if we need to chain to DOS 18.2 - and dword [td_dos_timer], 0ffffh - -; -; Call the original DOS handler.... -; - pushfd - call far dword [td_org_interrupt] - - jmp NoReset ;old handler has reset, so we don't - -NoChainToOld: -; Reset controller - mov al, 20h ; Reset interrupt controller - out 20h, al - -NoReset: - cmp byte [td_in_timer], 0 - jne ExitInterrupt - - mov byte [td_in_timer], 1 ; Mark that we're in a timer interrupt... - - ; Reenable interrupts - sti ; Reenable interrupts - - cmp word [td_user_function+4], 0 ; Check the selector... - je NoUserFunction - -; Switch stacks while calling the user-definable function... - pushad - push fs - push gs - mov dword [td_saved_stack+0], esp - mov word [td_saved_stack+4], ss - lss esp, [td_new_stack] ; Switch to new stack - call far dword [td_user_function] ; Call new function - lss esp, [td_saved_stack] ; Switch back to original stack - pop gs - pop fs - popad - -NoUserFunction: - cmp dword [td_joystick_poller], 0 - je NoJoyPolling - mov eax, [td__timer_cnt] - mov dword [td_saved_stack+0], esp - mov word [td_saved_stack+4], ss - lss esp, [td_new_stack] ; Switch to new stack - pusha - push eax - call dword [td_joystick_poller] - pop eax - popa - lss esp, [td_saved_stack] ; Switch back to original stack - -NoJoyPolling: - cli - mov byte [td_in_timer], 0 - -ExitInterrupt: -;;mov al, 20h ; Reset interrupt controller -;;out 20h, al - pop eax - pop es - pop ds - iretd ; Return from timer interrupt - -TIMER_LOCKED_CODE_STOP: - -;************************************************************************ -;************************************************************************ -;***** ***** -;***** T I M E R _ I N I T ***** -;***** ***** -;************************************************************************ -;************************************************************************ - -_timer_init: - pushad - push ds - push es - - cmp byte [td_Installed], 1 - je NEAR AlreadyInstalled - - mov [__my_ds],ds - - mov dword [td__timer_cnt], 65536 ; Set to BIOS's normal 18.2 Hz - mov dword [td_dos_timer], 0 ; clear DOS Interrupt counter - mov dword [td_user_function+0], 0 ; offset of user function - mov word [td_user_function+4], 0 ; selector of user function - - lea eax, [ds:td_TimerStack] ; Use EAX as temp stack pointer - add eax, STACK_SIZE ; Top of stack minus space for saving old ss:esp - mov dword [td_new_stack+0], eax - mov word [td_new_stack+4], ds - - ;--------------- lock data used in interrupt - mov eax, (td_TimerStack-TimerData)+STACK_SIZE ;sizeof timer_data - mov esi, eax - shr esi, 16 - mov edi, eax - and edi, 0ffffh ; si:di = length of region to lock in bytes - mov ebx, TimerData - add ebx, [___djgpp_base_address] - mov ecx, ebx - shr ebx, 16 - and ecx, 0ffffh ; bx:cx = start of linear address to lock - mov eax, 0600h ; DPMI lock address function - int 31h ; call dpmi - jnc @@@@ - int 3 ; LOCK FAILED!! -@@@@: - ;--------------- lock code used in interrupt - mov eax, TIMER_LOCKED_CODE_STOP - sub eax, TIMER_LOCKED_CODE_START - inc eax ; EAX = size of timer interrupt handler - mov esi, eax - shr esi, 16 - mov edi, eax - and edi, 0ffffh ; si:di = length of region to lock in bytes - mov ebx, TIMER_LOCKED_CODE_START - add ebx, [___djgpp_base_address] - mov ecx, ebx - shr ebx, 16 - and ecx, 0ffffh ; bx:cx = start of linear address to lock - mov eax, 0600h ; DPMI lock address function - int 31h ; call dpmi - jnc @@@@@ ;This is getting fun - int 3 ; LOCK FAILED!! -@@@@@: - -;************************************************************** -;******************* SAVE OLD INT8 HANDLER ******************** -;************************************************************** - mov ax,0204h - mov bl,8 - int 31h - mov dword [td_org_interrupt+0],edx - mov word [td_org_interrupt+4],cx - -;************************************************************** -;***************** INSTALL NEW INT8 HANDLER ******************* -;************************************************************** - - cli - - mov al, 34h ; count in binary, mode 2, load low byte then hi byte, counter 0: 00 11 010 0 - out TCOMMAND, al ; Reset PIT channel 0 - mov eax, [td__timer_cnt] - out TDATA, al - mov al, ah - out TDATA, al - - mov dword [td_tick_count], 0 - mov byte [td_Installed],1 - - mov ax,0205h - mov bl,8 - mov edx,timer_handler - mov cx,cs - int 31h - - - sti - push dword _timer_close - call _atexit - add esp,4 - -AlreadyInstalled: - - pop es - pop ds - popad - - ret - -;************************************************************************ -;************************************************************************ -;***** ***** -;***** T I M E R _ C L O S E _ ***** -;***** ***** -;************************************************************************ -;************************************************************************ - -_timer_close: - push eax - push ebx - push ecx - push edx - - cmp byte [td_Installed], 0 - je NotInstalled - mov byte [td_Installed], 0 - -;************************************************************** -;***************** RESTORE OLD INT8 HANDLER ******************* -;************************************************************** - - cli - mov al, 36h ; count in binary, mode 3, load low byte then hi byte, counter 0: 00 11 011 0 - out TCOMMAND, al ; Reser PIT channel 0 - mov ax, 0h - out TDATA, al - mov al, ah - out TDATA, al - - mov ax,0205h - mov bl,8 - mov edx,dword [td_org_interrupt+0] - mov cx,word [td_org_interrupt+4] - int 31h - - sti - - cmp dword [td_nested_counter], 0 - je NoNestedInterrupts - mov eax, [td_nested_counter] - ;int 3 ; Get John!! - -NoNestedInterrupts: - - -NotInstalled: - pop edx - pop ecx - pop ebx - pop eax - - ret - diff --git a/arch/dos/tweak.inc b/arch/dos/tweak.inc deleted file mode 100644 index 4c7222dc..00000000 --- a/arch/dos/tweak.inc +++ /dev/null @@ -1,258 +0,0 @@ -;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -; -; $Source: /cvs/cvsroot/d2x/arch/dos/tweak.inc,v $ -; $Revision: 1.1.1.1 $ -; $Author: bradleyb $ -; $Date: 2001-01-19 03:30:15 $ -; -; Parameters used by modex.asm to set various modex resolutions. -; -; $Log: not supported by cvs2svn $ -; Revision 1.1.1.1 1999/06/14 21:58:45 donut -; Import of d1x 1.37 source. -; -; Revision 1.3 1993/11/16 11:28:09 john -; *** empty log message *** -; -; Revision 1.2 1993/10/15 16:23:18 john -; y -; -; Revision 1.1 1993/09/08 11:41:09 john -; Initial revision -; -; -; - - -; Mode X CRTC register tweaks for various resolutions - -X320Y200 db 00 ; 0e3h ; dot clock - db 02 ; Number of CRTC Registers to update - dw 00014h ; turn off dword mode - dw 0e317h ; turn on byte mode - dw 320 ; width - dw 200 ; height - -X320Y240 db 0e3h ; dot clock - db 10 ; Number of CRTC Registers to update - dw 00d06h ; vertical total - dw 03e07h ; overflow (bit 8 of vertical counts) - dw 04109h ; cell height (2 to double-scan) - dw 0ea10h ; v sync start - dw 0ac11h ; v sync end and protect cr0-cr7 - dw 0df12h ; vertical displayed - dw 00014h ; turn off dword mode - dw 0e715h ; v blank start - dw 00616h ; v blank end - dw 0e317h ; turn on byte mode - dw 320 ; width - dw 240 ; height - -X360Y200 db 0e7h ; dot clock - db 08 ; Number of CRTC Registers to update - dw 06b00h ; horz total - dw 05901h ; horz displayed - dw 05a02h ; start horz blanking - dw 08e03h ; end horz blanking - dw 05e04h ; start h sync - dw 08a05h ; end h sync - dw 00014h ; turn off dword mode - dw 0e317h ; turn on byte mode - dw 360 ; width - dw 200 ; height - - -X360Y240 db 0e7h ; dot clock - db 17 ; Number of CRTC Registers to update - dw 06b00h ; horz total - dw 05901h ; horz displayed - dw 05a02h ; start horz blanking - dw 08e03h ; end horz blanking - dw 05e04h ; start h sync - dw 08a05h ; end h sync - dw 00d06h ; vertical total - dw 03e07h ; overflow (bit 8 of vertical counts) - dw 04109h ; cell height (2 to double-scan) - dw 0ea10h ; v sync start - dw 0ac11h ; v sync end and protect cr0-cr7 - dw 0df12h ; vertical displayed - dw 02d13h ; offset; - dw 00014h ; turn off dword mode - dw 0e715h ; v blank start - dw 00616h ; v blank end - dw 0e317h ; turn on byte mode - dw 360 - dw 240 - -X376Y282 db 0e7h - db 18 - dw 06e00h ; horz total - dw 05d01h ; horz displayed - dw 05e02h ; start horz blanking - dw 09103h ; end horz blanking - dw 06204h ; start h sync - dw 08f05h ; end h sync - dw 06206h ; vertical total - dw 0f007h ; overflow - dw 06109h ; cell height - dw 0310fh ; - dw 03710h ; v sync start - dw 08911h ; v sync end and protect cr0-cr7 - dw 03312h ; vertical displayed - dw 02f13h ; offset - dw 00014h ; turn off dword mode - dw 03c15h ; v blank start - dw 05c16h ; v blank end - dw 0eb17h ; turn on byte mode - dw 376 - dw 282 - - -X320Y400 db 0h ; dot clock - db 03 ; Number of CRTC Registers to update - dw 04009h ; cell height - dw 00014h ; turn off dword mode - dw 0e317h ; turn on byte mode - dw 320 ; width - dw 400 ; height - -X320Y480 db 0e3h ; dotclock - db 10 ; Number of CRTC Registers to update - dw 00d06h ; vertical total - dw 03e07h ; overflow (bit 8 of vertical counts) - dw 04009h ; cell height (2 to double-scan) - dw 0ea10h ; v sync start - dw 0ac11h ; v sync end and protect cr0-cr7 - dw 0df12h ; vertical displayed - dw 00014h ; turn off dword mode - dw 0e715h ; v blank start - dw 00616h ; v blank end - dw 0e317h ; turn on byte mode - dw 320 ; width - dw 480 ; height - -X360Y400 db 0e7h ; dot clock - db 09 ; Number of CRTC Registers to update - dw 06b00h ; horz total - dw 05901h ; horz displayed - dw 05a02h ; start horz blanking - dw 08e03h ; end horz blanking - dw 05e04h ; start h sync - dw 08a05h ; end h sync - dw 04009h ; cell height - dw 00014h ; turn off dword mode - dw 0e317h ; turn on byte mode - dw 360 ; width - dw 400 ; height - -X360Y480 db 0e7h - db 17 - dw 06b00h ; horz total - dw 05901h ; horz displayed - dw 05a02h ; start horz blanking - dw 08e03h ; end horz blanking - dw 05e04h ; start h sync - dw 08a05h ; end h sync - dw 00d06h ; vertical total - dw 03e07h ; overflow - dw 04009h ; cell height - dw 0ea10h ; v sync start - dw 0ac11h ; v sync end and protect cr0-cr7 - dw 0df12h ; vertical displayed - dw 02d13h ; offset - dw 00014h ; turn off dword mode - dw 0e715h ; v blank start - dw 00616h ; v blank end - dw 0e317h ; turn on byte mode - dw 360 - dw 480 - -X360Y360 db 0e7h - db 15 - dw 06b00h ; horz total - dw 05901h ; horz displayed - dw 05a02h ; start horz blanking - dw 08e03h ; end horz blanking - dw 05e04h ; start h sync - dw 08a05h ; end h sync - dw 04009h ; cell height - dw 08810h ; v sync start - dw 08511h ; v sync end and protect cr0-cr7 - dw 06712h ; vertical displayed - dw 02d13h ; offset - dw 00014h ; turn off dword mode - dw 06d15h ; v blank start - dw 0ba16h ; v blank end - dw 0e317h ; turn on byte mode - dw 360 - dw 360 - -X376Y308 db 0e7h - db 18 - dw 06e00h ; horz total - dw 05d01h ; horz displayed - dw 05e02h ; start horz blanking - dw 09103h ; end horz blanking - dw 06204h ; start h sync - dw 08f05h ; end h sync - dw 06206h ; vertical total - dw 00f07h ; overflow - dw 04009h ; - dw 0310fh ; - dw 03710h ; v sync start - dw 08911h ; v sync end and protect cr0-cr7 - dw 03312h ; vertical displayed - dw 02f13h ; offset - dw 00014h ; turn off dword mode - dw 03c15h ; v blank start - dw 05c16h ; v blank end - dw 0e317h ; turn on byte mode - dw 376 - dw 308 - -X376Y564 db 0e7h - db 18 - dw 06e00h ; horz total - dw 05d01h ; horz displayed - dw 05e02h ; start horz blanking - dw 09103h ; end horz blanking - dw 06204h ; start h sync - dw 08f05h ; end h sync - dw 06206h ; vertical total - dw 0f007h ; overflow - dw 06009h ; - dw 0310fh ; - dw 03710h ; v sync start - dw 08911h ; v sync end and protect cr0-cr7 - dw 03312h ; vertical displayed - dw 02f13h ; offset - dw 00014h ; turn off dword mode - dw 03c15h ; v blank start - dw 05c16h ; v blank end - dw 0e317h ; turn on byte mode - dw 376 - dw 564 - -%define LAST_X_MODE 11 - -ModeTable dd X320Y200 - dd X320Y240 - dd X360Y200 - dd X360Y240 - dd X376Y282 - dd X320Y400 - dd X320Y480 - dd X360Y400 - dd X360Y480 - dd X360Y360 - dd X376Y308 - dd X376Y564 diff --git a/arch/dos/vesa.c b/arch/dos/vesa.c deleted file mode 100644 index fd965b50..00000000 --- a/arch/dos/vesa.c +++ /dev/null @@ -1,140 +0,0 @@ -#include -#ifdef __ENV_DJGPP__ - - -#include -#include "gr.h" -#include "grdef.h" -#include "u_dpmi.h" -#include "vesa.h" - -#define SC_INDEX 0x3c4 -#define CRTC_INDEX 0x3d4 -#define CRTC_DATA 0x3d5 - -static int bankshift; -static int lastbank; - -/* this comes from Allegro */ -typedef struct vesa_mode_info -{ - unsigned short ModeAttributes; - unsigned char WinAAttributes; - unsigned char WinBAttributes; - unsigned short WinGranularity; - unsigned short WinSize; - unsigned short WinASegment; - unsigned short WinBSegment; - unsigned long WinFuncPtr; - unsigned short BytesPerScanLine; - unsigned short XResolution; - unsigned short YResolution; - unsigned char XCharSize; - unsigned char YCharSize; - unsigned char NumberOfPlanes; - unsigned char BitsPerPixel; - unsigned char NumberOfBanks; - unsigned char MemoryModel; - unsigned char BankSize; - unsigned char NumberOfImagePages; - unsigned char Reserved_page; - unsigned char RedMaskSize; - unsigned char RedMaskPos; - unsigned char GreenMaskSize; - unsigned char GreenMaskPos; - unsigned char BlueMaskSize; - unsigned char BlueMaskPos; - unsigned char ReservedMaskSize; - unsigned char ReservedMaskPos; - unsigned char DirectColorModeInfo; - unsigned long PhysBasePtr; - unsigned long OffScreenMemOffset; - unsigned short OffScreenMemSize; - unsigned char Reserved[206]; -} __attribute__ ((packed)) vesa_mode_info; - - -int gr_vesa_checkmode(int mode) { - int i; - dpmi_real_regs rregs; - vesa_mode_info *mode_info; - - if (!(mode_info = dpmi_get_temp_low_buffer( 1024 ))) - return 7; - rregs.eax = 0x4f01; - rregs.ecx = mode; - rregs.edi = DPMI_real_offset(mode_info); - rregs.es = DPMI_real_segment(mode_info); - dpmi_real_int386x( 0x10, &rregs ); - if (rregs.eax != 0x4f) - return 5; /* no vesa */ - if (!(mode_info->ModeAttributes & 1)) - return 4; /* unsupported mode */ - - bankshift = 0; - i = mode_info->WinGranularity; - while (i < 64) { - i <<= 1; - bankshift++; - } - if (i != 64) - return 2; /* incompatible window granularity */ - return 0; -} - -int gr_vesa_setmode(int mode) { - int ret; - lastbank = -1; - if ((ret = gr_vesa_checkmode(mode))) - return ret; - asm volatile("int $0x10" : "=a" (ret) : "a" (0x4f02), "b" (mode)); - return (ret == 0x4f) ? 0 : 4; -} - -inline void gr_vesa_setpage(int bank) { - if (bank != lastbank) - asm volatile("int $0x10" - : : "a" (0x4f05), "b" (0), "d" ((lastbank = bank) << bankshift)); -} - -void gr_vesa_incpage() { - gr_vesa_setpage(lastbank + 1); -} - -void gr_vesa_setstart(int col, int row) { - asm volatile("int $0x10" - : : "a" (0x4f07), "b" (0), "c" (col), "d" (row)); -} - -int gr_vesa_setlogical(int line_width) { - int ret; - asm volatile("int $0x10" - : "=c" (ret) : "a" (0x4f07), "b" (0), "c" (line_width)); - return ret; -} - -void gr_vesa_scanline(int x1, int x2, int y, unsigned char color) { - int addr = (y * gr_var_bwidth) + x1; - int left = x2 - x1 + 1; - gr_vesa_setpage(addr >> 16); - addr &= 0xffff; - while (left) { - if (left > (65536 - addr)) { - left -= (65536 - addr); - memset(gr_video_memory + addr, color, 65536 - addr); - addr = 0; - gr_vesa_incpage(); - } else { - memset(gr_video_memory + addr, color, left); - left = 0; - } - } -} - -void gr_vesa_pixel(unsigned char color, unsigned int addr) { - gr_vesa_setpage(addr >> 16); - gr_video_memory[addr & 0xffff] = color; -} - - -#endif // __ENV_DJGPP__ diff --git a/arch/dos/vgaregs.inc b/arch/dos/vgaregs.inc deleted file mode 100644 index fd9f66e4..00000000 --- a/arch/dos/vgaregs.inc +++ /dev/null @@ -1,62 +0,0 @@ -;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -; -; $Source: /cvs/cvsroot/d2x/arch/dos/vgaregs.inc,v $ -; $Revision: 1.1.1.1 $ -; $Author: bradleyb $ -; $Date: 2001-01-19 03:30:15 $ -; -; Readable descriptions of VGA ports. -; -; $Log: not supported by cvs2svn $ -; Revision 1.1.1.1 1999/06/14 21:58:45 donut -; Import of d1x 1.37 source. -; -; Revision 1.2 1993/10/15 16:22:45 john -; *** empty log message *** -; -; Revision 1.1 1993/09/08 11:41:00 john -; Initial revision -; -; -; - - -%define MISC_OUTPUT 03c2h ;Miscellaneous Output register -%define MAP_MASK 02h ;index in SC of Map Mask register -%define READ_MAP 04h ;index in GC of the Read Map register -%define BIT_MASK 08h ;index in GC of Bit Mask register - -%define SC_INDEX 3c4h ;Index register for sequencer ctrl. -%define SC_MAP_MASK 2 ;Number of map mask register - -%define SC_INDEX 3c4h ;Index register for sequencer ctrl. -%define SC_MAP_MASK 2 ;Number of map mask register -%define SC_MEM_MODE 4 ;Number of memory mode register - -%define GC_INDEX 3ceh ;Index register for graphics ctrl. -%define GC_READ_MAP 4 ;Number of read map register -%define GC_GRAPH_MODE 5 ;Number of graphics mode register -%define GC_MISCELL 6 ;Number of miscellaneous register - -%define CRTC_INDEX 3d4h ;Index register for CRT controller -%define CC_MAX_SCAN 9 ;Number of maximum scan line reg. -%define CC_START_HI 0Ch ;Number of start address high register -%define CC_START_LO 0Dh ;Number of start address low register -%define CC_UNDERLINE 14h ;Number of underline register -%define CC_MODE_CTRL 17h ;Number of mode control register -%define CRTC_OFFSET 13h ; CRTC offset register index - -%define DAC_WRITE_ADR 3C8h ;DAC write address -%define DAC_READ_ADR 3C7h ;DAC read address -%define DAC_DATA 3C9h ;DAC data register - -%define VERT_RESCAN 3DAh ;Input status register #1 diff --git a/arch/include/joy.h b/arch/include/joy.h index 58c41d65..c7489665 100644 --- a/arch/include/joy.h +++ b/arch/include/joy.h @@ -13,13 +13,16 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. /* * $Source: /cvs/cvsroot/d2x/arch/include/joy.h,v $ - * $Revision: 1.1 $ + * $Revision: 1.2 $ * $Author: bradleyb $ - * $Date: 2001-01-28 16:10:57 $ + * $Date: 2001-01-29 13:36:14 $ * * Header for joystick functions * * $Log: not supported by cvs2svn $ + * Revision 1.1 2001/01/28 16:10:57 bradleyb + * unified input headers. + * */ #ifndef _JOY_H @@ -44,7 +47,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #if defined WINDOWS #define JOY_NUM_AXES 7 #elif defined __ENV_LINUX__ -#define MAX_AXES 32 #define JOY_NUM_AXES 5 #else #define JOY_NUM_AXES 4 diff --git a/arch/linux/Makefile.am b/arch/linux/Makefile.am index f0c6d1a1..78ac4cf1 100644 --- a/arch/linux/Makefile.am +++ b/arch/linux/Makefile.am @@ -1,6 +1,4 @@ SUBDIRS = include EXTRA_DIST = \ -alsadigi.c findfile.c hmiplay.c hmistub.c init.c \ -ipx_bsd.c ipx_kali.c ipx_lin.c ipx_udp.c \ -linuxnet.c mono.c serial.c timer.c ukali.c +alsadigi.c hmiplay.c hmistub.c ipx_kali.c mono.c serial.c timer.c ukali.c diff --git a/arch/linux/findfile.c b/arch/linux/findfile.c deleted file mode 100644 index 6fcb350f..00000000 --- a/arch/linux/findfile.c +++ /dev/null @@ -1,58 +0,0 @@ -#include -#ifdef __ENV_LINUX__ - -#include -#include -#include -#include "findfile.h" -#include "u_mem.h" -#include "error.h" - -/* KLUDGE ALERT: evil globals */ -static glob_t glob_a; -static int glob_whichfile; - -int FileFindFirst(char *search_str, FILEFINDSTRUCT *ffstruct) -{ - int r; - char *t; - - Assert(search_str != NULL); - Assert(ffstruct != NULL); - - r = glob(search_str, 0, NULL, &glob_a); - if (r == GLOB_NOMATCH) return -1; - - glob_whichfile = 0; - - t = strrchr(glob_a.gl_pathv[glob_whichfile], '/'); - if (t == NULL) t = glob_a.gl_pathv[glob_whichfile]; else t++; - strncpy(ffstruct->name, t, 255); - ffstruct->size = strlen(ffstruct->name); - - return 0; -} - -int FileFindNext(FILEFINDSTRUCT *ffstruct) -{ - char *t; - - glob_whichfile++; - - if (glob_whichfile >= glob_a.gl_pathc) return -1; - - t = strrchr(glob_a.gl_pathv[glob_whichfile], '/'); - if (t == NULL) t = glob_a.gl_pathv[glob_whichfile]; else t++; - strncpy(ffstruct->name, t, 255); - ffstruct->size = strlen(ffstruct->name); - return 0; -} - -int FileFindClose(void) -{ - globfree(&glob_a); - return 0; -} - - -#endif // __ENV_LINUX__ diff --git a/arch/linux/init.c b/arch/linux/init.c deleted file mode 100644 index bdd9122f..00000000 --- a/arch/linux/init.c +++ /dev/null @@ -1,51 +0,0 @@ -// linux init.c - added Matt Mueller 9/6/98 -#include -#ifdef __ENV_LINUX__ - -#include -#include -#include "pstypes.h" -#include "console.h" -#include "text.h" -#include "event.h" -#include "error.h" -#include "joy.h" -#include "args.h" - -extern void arch_sdl_init(); -extern void arch_svgalib_init(); -extern void key_init(); -extern int com_init(); -extern void timer_init(); - -void arch_init_start() -{ - -} - -void arch_init() -{ - // Initialise the library - arch_sdl_init(); -#ifdef __SVGALIB__ - arch_svgalib_init(); -#endif - if (!FindArg( "-nojoystick" )) { - con_printf(CON_VERBOSE, "\n%s", TXT_VERBOSE_6); - joy_init(); - } - //added 06/09/99 Matt Mueller - fix nonetwork compile -#ifdef NETWORK - //end addition -MM -//added on 10/19/98 by Victor Rachels to add serial support (from DPH) - if(!(FindArg("-noserial"))) - com_init(); -//end this section addition - Victor - //added 06/09/99 Matt Mueller - fix nonetwork compile -#endif - //end addition -MM - key_init(); -} - - -#endif // __ENV_LINUX__ diff --git a/arch/linux/ipx_bsd.c b/arch/linux/ipx_bsd.c deleted file mode 100644 index de7f6710..00000000 --- a/arch/linux/ipx_bsd.c +++ /dev/null @@ -1,230 +0,0 @@ -/* IPX driver using BSD style sockets */ -/* Mostly taken from dosemu */ -#include -#ifdef __ENV_LINUX__ -#ifdef NETWORK - -#include -#include -#include -#include - -#ifdef HAVE_NETIPX_IPX_H -#include -#else -# include -# ifndef IPX_TYPE -# define IPX_TYPE 1 -# endif -#endif - -#include -#include -#include - -#include "pstypes.h" -#include "ipx_drv.h" -#include "ipx_bsd.h" - -#ifndef DOSEMU -#include "mono.h" -#define n_printf(format, args...) mprintf((1, format, ## args)) -#define enter_priv_on() -#define leave_priv_setting() -#endif - -static int ipx_bsd_GetMyAddress( void ) -{ - int sock; - struct sockaddr_ipx ipxs; - struct sockaddr_ipx ipxs2; - int len; - int i; - - sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX); - if(sock==-1) - { - n_printf("IPX: could not open socket in GetMyAddress\n"); - return(-1); - } - - /* bind this socket to network 0 */ - ipxs.sipx_family=AF_IPX; -#ifdef IPX_MANUAL_ADDRESS - memcpy(&ipxs.sipx_network, ipx_MyAddress, 4); -#else - ipxs.sipx_network=0; -#endif - ipxs.sipx_port=0; - - if(bind(sock,(struct sockaddr *)&ipxs,sizeof(ipxs))==-1) - { - n_printf("IPX: could bind to network 0 in GetMyAddress\n"); - close( sock ); - return(-1); - } - - len = sizeof(ipxs2); - if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { - n_printf("IPX: could not get socket name in GetMyAddress\n"); - close( sock ); - return(-1); - } - - memcpy(ipx_MyAddress, &ipxs2.sipx_network, 4); - for (i = 0; i < 6; i++) { - ipx_MyAddress[4+i] = ipxs2.sipx_node[i]; - } - close( sock ); - return(0); -} - -static int ipx_bsd_OpenSocket(ipx_socket_t *sk, int port) -{ - int sock; /* sock here means Linux socket handle */ - int opt; - struct sockaddr_ipx ipxs; - int len; - struct sockaddr_ipx ipxs2; - - /* DANG_FIXTHIS - kludge to support broken linux IPX stack */ - /* need to convert dynamic socket open into a real socket number */ -/* if (port == 0) { - n_printf("IPX: using socket %x\n", nextDynamicSocket); - port = nextDynamicSocket++; - } -*/ - /* do a socket call, then bind to this port */ - sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX); - if (sock == -1) { - n_printf("IPX: could not open IPX socket.\n"); - return -1; - } - -#ifdef DOSEMU - opt = 1; - /* turn on socket debugging */ - if (d.network) { - enter_priv_on(); - if (setsockopt(sock, SOL_SOCKET, SO_DEBUG, &opt, sizeof(opt)) == -1) { - leave_priv_setting(); - n_printf("IPX: could not set socket option for debugging.\n"); - return -1; - } - leave_priv_setting(); - } -#endif - opt = 1; - /* Permit broadcast output */ - enter_priv_on(); - if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, - &opt, sizeof(opt)) == -1) { - leave_priv_setting(); - n_printf("IPX: could not set socket option for broadcast.\n"); - return -1; - } -#ifdef DOSEMU - /* allow setting the type field in the IPX header */ - opt = 1; -#if 0 /* this seems to be wrong: IPX_TYPE can only be set on level SOL_IPX */ - if (setsockopt(sock, SOL_SOCKET, IPX_TYPE, &opt, sizeof(opt)) == -1) { -#else - /* the socket _is_ an IPX socket, hence it first passes ipx_setsockopt() - * in file linux/net/ipx/af_ipx.c. This one handles SOL_IPX itself and - * passes SOL_SOCKET-levels down to sock_setsockopt(). - * Hence I guess the below is correct (can somebody please verify this?) - * -- Hans, June 14 1997 - */ - if (setsockopt(sock, SOL_IPX, IPX_TYPE, &opt, sizeof(opt)) == -1) { -#endif - leave_priv_setting(); - n_printf("IPX: could not set socket option for type.\n"); - return -1; - } -#endif - ipxs.sipx_family = AF_IPX; - ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); -/* ipxs.sipx_network = htonl(MyNetwork); */ - bzero(ipxs.sipx_node, 6); /* Please fill in my node name */ - ipxs.sipx_port = htons(port); - - /* now bind to this port */ - if (bind(sock, (struct sockaddr *) &ipxs, sizeof(ipxs)) == -1) { - n_printf("IPX: could not bind socket to address\n"); - close( sock ); - leave_priv_setting(); - return -1; - } - - if( port==0 ) { - len = sizeof(ipxs2); - if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { - n_printf("IPX: could not get socket name in IPXOpenSocket\n"); - close( sock ); - leave_priv_setting(); - return -1; - } else { - port = htons(ipxs2.sipx_port); - n_printf("IPX: opened dynamic socket %04x\n", port); - } - } - leave_priv_setting(); - sk->fd = sock; - sk->socket = port; - return 0; -} - -static void ipx_bsd_CloseSocket(ipx_socket_t *mysock) { - /* now close the file descriptor for the socket, and free it */ - n_printf("IPX: closing file descriptor on socket %x\n", mysock->socket); - close(mysock->fd); -} - -static int ipx_bsd_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader, - u_char *data, int dataLen) { - struct sockaddr_ipx ipxs; - - ipxs.sipx_family = AF_IPX; - /* get destination address from IPX packet header */ - memcpy(&ipxs.sipx_network, IPXHeader->Destination.Network, 4); - /* if destination address is 0, then send to my net */ - if (ipxs.sipx_network == 0) { - ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); -/* ipxs.sipx_network = htonl(MyNetwork); */ - } - memcpy(&ipxs.sipx_node, IPXHeader->Destination.Node, 6); - memcpy(&ipxs.sipx_port, IPXHeader->Destination.Socket, 2); - ipxs.sipx_type = IPXHeader->PacketType; - /* ipxs.sipx_port=htons(0x452); */ - return sendto(mysock->fd, data, dataLen, 0, - (struct sockaddr *) &ipxs, sizeof(ipxs)); -} - -static int ipx_bsd_ReceivePacket(ipx_socket_t *s, char *buffer, int bufsize, - struct ipx_recv_data *rd) { - int sz, size; - struct sockaddr_ipx ipxs; - - sz = sizeof(ipxs); - if ((size = recvfrom(s->fd, buffer, bufsize, 0, - (struct sockaddr *) &ipxs, &sz)) <= 0) - return size; - memcpy(rd->src_network, &ipxs.sipx_network, 4); - memcpy(rd->src_node, ipxs.sipx_node, 6); - rd->src_socket = ipxs.sipx_port; - rd->dst_socket = s->socket; - rd->pkt_type = ipxs.sipx_type; - - return size; -} - -struct ipx_driver ipx_bsd = { - ipx_bsd_GetMyAddress, - ipx_bsd_OpenSocket, - ipx_bsd_CloseSocket, - ipx_bsd_SendPacket, - ipx_bsd_ReceivePacket, - ipx_general_PacketReady -}; -#endif // NETWORK -#endif // __ENV_LINUX__ diff --git a/arch/linux/ipx_lin.c b/arch/linux/ipx_lin.c deleted file mode 100644 index 459d4204..00000000 --- a/arch/linux/ipx_lin.c +++ /dev/null @@ -1,218 +0,0 @@ -#include - -#ifdef __ENV_LINUX__ - -#ifdef NETWORK -#include -#include -#include -#include - -#ifdef HAVE_NETIPX_IPX_H -#include -#else -# include -# ifndef IPX_TYPE -# define IPX_TYPE 1 -# endif -#endif - -#include -#include -#include -#include "pstypes.h" - -#include "ipx_ld.h" -#include "ipx_hlpr.h" -#include "ipx_lin.h" - -extern unsigned char ipx_MyAddress[10]; - -int -ipx_linux_GetMyAddress( void ) -{ - int sock; - struct sockaddr_ipx ipxs; - struct sockaddr_ipx ipxs2; - int len; - int i; - - sock=socket(AF_IPX,SOCK_DGRAM,PF_IPX); - if(sock==-1) - { - n_printf("IPX: could not open socket in GetMyAddress\n"); - return(-1); - } - - /* bind this socket to network 0 */ - ipxs.sipx_family=AF_IPX; -#ifdef IPX_MANUAL_ADDRESS - memcpy(&ipxs.sipx_network, ipx_MyAddress, 4); -#else - ipxs.sipx_network=0; -#endif - ipxs.sipx_port=0; - - if(bind(sock,(struct sockaddr *)&ipxs,sizeof(ipxs))==-1) - { - n_printf("IPX: could bind to network 0 in GetMyAddress\n"); - close( sock ); - return(-1); - } - - len = sizeof(ipxs2); - if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { - n_printf("IPX: could not get socket name in GetMyAddress\n"); - close( sock ); - return(-1); - } - - memcpy(ipx_MyAddress, &ipxs2.sipx_network, 4); - for (i = 0; i < 6; i++) { - ipx_MyAddress[4+i] = ipxs2.sipx_node[i]; - } - close( sock ); - return(0); -} - -int -ipx_linux_OpenSocket(ipx_socket_t *sk, int port) -{ - int sock; /* sock here means Linux socket handle */ - int opt; - struct sockaddr_ipx ipxs; - int len; - struct sockaddr_ipx ipxs2; - - /* DANG_FIXTHIS - kludge to support broken linux IPX stack */ - /* need to convert dynamic socket open into a real socket number */ -/* if (port == 0) { - n_printf("IPX: using socket %x\n", nextDynamicSocket); - port = nextDynamicSocket++; - } -*/ - /* do a socket call, then bind to this port */ - sock = socket(AF_IPX, SOCK_DGRAM, PF_IPX); - if (sock == -1) { - n_printf("IPX: could not open IPX socket.\n"); - return -1; - } - -#ifdef DOSEMU - opt = 1; - /* turn on socket debugging */ - if (d.network) { - enter_priv_on(); - if (setsockopt(sock, SOL_SOCKET, SO_DEBUG, &opt, sizeof(opt)) == -1) { - leave_priv_setting(); - n_printf("IPX: could not set socket option for debugging.\n"); - return -1; - } - leave_priv_setting(); - } -#endif - opt = 1; - /* Permit broadcast output */ - enter_priv_on(); - if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, - &opt, sizeof(opt)) == -1) { - leave_priv_setting(); - n_printf("IPX: could not set socket option for broadcast.\n"); - return -1; - } -#ifdef DOSEMU - /* allow setting the type field in the IPX header */ - opt = 1; -#if 0 /* this seems to be wrong: IPX_TYPE can only be set on level SOL_IPX */ - if (setsockopt(sock, SOL_SOCKET, IPX_TYPE, &opt, sizeof(opt)) == -1) { -#else - /* the socket _is_ an IPX socket, hence it first passes ipx_setsockopt() - * in file linux/net/ipx/af_ipx.c. This one handles SOL_IPX itself and - * passes SOL_SOCKET-levels down to sock_setsockopt(). - * Hence I guess the below is correct (can somebody please verify this?) - * -- Hans, June 14 1997 - */ - if (setsockopt(sock, SOL_IPX, IPX_TYPE, &opt, sizeof(opt)) == -1) { -#endif - leave_priv_setting(); - n_printf("IPX: could not set socket option for type.\n"); - return -1; - } -#endif - ipxs.sipx_family = AF_IPX; - ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); -/* ipxs.sipx_network = htonl(MyNetwork); */ - bzero(ipxs.sipx_node, 6); /* Please fill in my node name */ - ipxs.sipx_port = htons(port); - - /* now bind to this port */ - if (bind(sock, (struct sockaddr *) &ipxs, sizeof(ipxs)) == -1) { - n_printf("IPX: could not bind socket to address\n"); - close( sock ); - leave_priv_setting(); - return -1; - } - - if( port==0 ) { - len = sizeof(ipxs2); - if (getsockname(sock,(struct sockaddr *)&ipxs2,&len) < 0) { - n_printf("IPX: could not get socket name in IPXOpenSocket\n"); - close( sock ); - leave_priv_setting(); - return -1; - } else { - port = htons(ipxs2.sipx_port); - n_printf("IPX: opened dynamic socket %04x\n", port); - } - } - leave_priv_setting(); - sk->fd = sock; - sk->socket = port; - return 0; -} - -void ipx_linux_CloseSocket(ipx_socket_t *mysock) { - /* now close the file descriptor for the socket, and free it */ - n_printf("IPX: closing file descriptor on socket %x\n", mysock->socket); - close(mysock->fd); -} - -int ipx_linux_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader, - u_char *data, int dataLen) { - struct sockaddr_ipx ipxs; - - ipxs.sipx_family = AF_IPX; - /* get destination address from IPX packet header */ - memcpy(&ipxs.sipx_network, IPXHeader->Destination.Network, 4); - /* if destination address is 0, then send to my net */ - if (ipxs.sipx_network == 0) { - ipxs.sipx_network = *((unsigned int *)&ipx_MyAddress[0]); -/* ipxs.sipx_network = htonl(MyNetwork); */ - } - memcpy(&ipxs.sipx_node, IPXHeader->Destination.Node, 6); - memcpy(&ipxs.sipx_port, IPXHeader->Destination.Socket, 2); - ipxs.sipx_type = IPXHeader->PacketType; - /* ipxs.sipx_port=htons(0x452); */ - return sendto(mysock->fd, data, dataLen, 0, - (struct sockaddr *) &ipxs, sizeof(ipxs)); -} - -int ipx_linux_ReceivePacket(ipx_socket_t *s, char *buffer, int bufsize, - struct ipx_recv_data *rd) { - int sz, size; - struct sockaddr_ipx ipxs; - - sz = sizeof(ipxs); - if ((size = recvfrom(s->fd, buffer, bufsize, 0, - (struct sockaddr *) &ipxs, &sz)) <= 0) - return size; - memcpy(rd->src_network, &ipxs.sipx_network, 4); - memcpy(rd->src_node, ipxs.sipx_node, 6); - rd->src_socket = ipxs.sipx_port; - rd->dst_socket = s->socket; - rd->pkt_type = ipxs.sipx_type; - - return size; -} -#endif // NETWORK -#endif // __ENV_LINUX__ diff --git a/arch/linux/ipx_udp.c b/arch/linux/ipx_udp.c deleted file mode 100644 index bef92c31..00000000 --- a/arch/linux/ipx_udp.c +++ /dev/null @@ -1,593 +0,0 @@ -/* IPX driver for native Linux TCP/IP networking (UDP implementation) - * Version 0.99.2 - * Contact Jan [Lace] Kratochvil for assistance - * (no "It somehow doesn't work! What should I do?" complaints, please) - * Special thanks to Vojtech Pavlik for testing. - * - * Also you may see KIX - KIX kix out KaliNix (in Linux-Linux only): - * http://atrey.karlin.mff.cuni.cz/~short/sw/kix.c.gz - * - * Primarily based on ipx_kali.c - "IPX driver for KaliNix interface" - * which is probably mostly by Jay Cotton . - * Parts shamelessly stolen from my KIX v0.99.2 and GGN v0.100 - * - * Changes: - * -------- - * 0.99.1 - now the default broadcast list also contains all point-to-point - * links with their destination peer addresses - * 0.99.2 - commented a bit :-) - * - now adds to broadcast list each host it gets some packet from - * which is already not covered by local physical ethernet broadcast - * - implemented short-signature packet format - * - compatibility mode for old D1X releases due to the previous bullet - * - * Configuration: - * -------------- - * No network server software is needed, neither KIX nor KaliNIX. - * - * Add command line argument "-udp". In default operation D1X will send - * broadcasts too all the local interfaces found. But you may also use - * additional parameter specified after "-udp" to modify the default - * broadcasting style and UDP port numbers binding: - * - * ./d1x -udp [@SHIFT]=HOST_LIST Broadcast ONLY to HOST_LIST - * ./d1x -udp [@SHIFT]+HOST_LIST Broadcast both to local ifaces & to HOST_LIST - * - * HOST_LIST is a comma (',') separated list of HOSTs: - * HOST is an IPv4 address (so-called quad like 192.168.1.2) or regular hostname - * HOST can also be in form 'address:SHIFT' - * SHIFT sets the UDP port base offset (e.g. +2), can be used to run multiple - * clients on one host simultaneously. This SHIFT has nothing to do - * with the dynamic-sockets (PgUP/PgDOWN) option in Descent, it's another - * higher-level differentiation option. - * - * Examples: - * --------- - * ./d1x -udp - * - Run D1X to participate in normal local network (Linux only, of course) - * - * ./d1x -udp @1=localhost:2 & ./d1x -udp @2=localhost:1 - * - Run two clients simultaneously fighting each other (only each other) - * - * ./d1x -udp =192.168.4.255 - * - Run distant Descent which will participate with remote network - * 192.168.4.0 with netmask 255.255.255.0 (broadcast has 192.168.4.255) - * - You'll have to also setup hosts in that network accordingly: - * ./d1x -udp +UPPER_DISTANT_MACHINE_NAME - * - * Have fun! - */ - -#include -#ifdef __ENV_LINUX__ -#ifdef NETWORK -#include -#include -#include /* for htons & co. */ -#include -#include -#include -#include -#include -#include -#include - -#include "ipx_drv.h" -#include "args.h" - -extern unsigned char ipx_MyAddress[10]; - -// #define UDPDEBUG - -#define UDP_BASEPORT 28342 -#define PORTSHIFT_TOLERANCE 0x100 -#define MAX_PACKETSIZE 8192 - -/* Packet format: first is the signature { 0xD1,'X' } which can be also - * { 'D','1','X','u','d','p'} for old-fashioned packets. - * Then follows virtual socket number (as changed during PgDOWN/PgUP) - * in network-byte-order as 2 bytes (u_short). After such 4/8 byte header - * follows raw data as communicated with D1X network core functions. - */ - -// Length HAS TO BE 6! -#define D1Xudp "D1Xudp" -// Length HAS TO BE 2! -#define D1Xid "\xD1X" - -static int open_sockets = 0; -static int dynamic_socket = 0x401; -static const int val_one=1; - -/* OUR port. Can be changed by "@X[+=]..." argument (X is the shift value) - */ - -static int baseport=UDP_BASEPORT; - -/* Have we some old D1X in network and have we to maintain compatibility? - * FIXME: Following scenario is braindead: - * A (NEW) , B (OLD) , C (NEW) - * host A) We start new D1X. A-newcomm, B-none , C-none - * host B) We start OLD D1X. A-newcomm, B-oldcomm, C-none - * Now host A hears host B and switches: A-oldcomm, B-oldcomm, C-none - * host C) We start new D1X. A-oldcomm, B-oldcomm, C-newcomm - * Now host C hears host A/B and switches: A-oldcomm, B-oldcomm, C-oldcomm - * Now host B finishes: A-oldcomm, B-none , C-oldcomm - * - * But right now we have hosts A and C, both new code equipped but - * communicating wastefully by the OLD protocol! Bummer. - */ - -static char compatibility=0; - -static int have_empty_address() { - int i; - for (i = 0; i < 10 && !ipx_MyAddress[i]; i++) ; - return i == 10; -} - -#define MSGHDR "IPX_udp: " - -static void msg(const char *fmt,...) -{ -va_list ap; - fputs(MSGHDR,stdout); - va_start(ap,fmt); - vprintf(fmt,ap); - va_end(ap); - putchar('\n'); -} - -static void chk(void *p) -{ - if (p) return; - msg("FATAL: Virtual memory exhausted!"); - exit(EXIT_FAILURE); -} - -#define FAIL(m...) do { msg(#m); return -1; } while (0) - -/* Find as much as MAX_BRDINTERFACES during local iface autoconfiguration. - * Note that more interfaces can be added during manual configuration - * or host-received-packet autoconfiguration - */ - -#define MAX_BRDINTERFACES 16 - -/* We require the interface to be UP and RUNNING to accept it. - */ - -#define IF_REQFLAGS (IFF_UP|IFF_RUNNING) - -/* We reject any interfaces declared as LOOPBACK type. - */ -#define IF_NOTFLAGS (IFF_LOOPBACK) - -static struct sockaddr_in *broads,broadmasks[MAX_BRDINTERFACES]; -static int broadnum,masksnum,broadsize; - -/* We'll check whether the "broads" array of destination addresses is now - * full and so needs expanding. - */ - -static void chkbroadsize(void) -{ - if (broadnumsin_family!=AF_INET || sinmp->sin_family!=AF_INET) continue; - broads[j]=*sinp; - broads[j].sin_port=UDP_BASEPORT; //FIXME: No possibility to override from cmdline - broadmasks[j]=*sinmp; - j++; - } - broadnum=j; - masksnum=j; - return(0); -} - -#define addreq(a,b) ((a).sin_port==(b).sin_port&&(a).sin_addr.s_addr==(b).sin_addr.s_addr) - -/* Previous function addiflist() can (and probably will) report multiple - * same addresses. On some Linux boxes is present both device "eth0" and - * "dummy0" with the same IP addreesses - we'll filter it here. - */ - -static void unifyiflist(void) -{ -int d=0,s,i; - - for (s=0;s=s) broads[d++]=broads[s]; - } - broadnum=d; -} - -static unsigned char qhbuf[6]; - -/* Parse PORTSHIFT numeric parameter - */ - -static void portshift(const char *cs) -{ -long port; -unsigned short ports=0; - - port=atol(cs); - if (port<-PORTSHIFT_TOLERANCE || port>+PORTSHIFT_TOLERANCE) - msg("Invalid portshift in \"%s\", tolerance is +/-%d",cs,PORTSHIFT_TOLERANCE); - else ports=htons(port); - memcpy(qhbuf+4,&ports,2); -} - -/* Do hostname resolve on name "buf" and return the address in buffer "qhbuf". - */ -static unsigned char *queryhost(char *buf) -{ -struct hostent *he; -char *s; -char c=0; - - if ((s=strrchr(buf,':'))) { - c=*s; - *s='\0'; - portshift(s+1); - } - else memset(qhbuf+4,0,2); - he=gethostbyname((char *)buf); - if (s) *s=c; - if (!he) { - msg("Error resolving my hostname \"%s\"",buf); - return(NULL); - } - if (he->h_addrtype!=AF_INET || he->h_length!=4) { - msg("Error parsing resolved my hostname \"%s\"",buf); - return(NULL); - } - if (!*he->h_addr_list) { - msg("My resolved hostname \"%s\" address list empty",buf); - return(NULL); - } - memcpy(qhbuf,(*he->h_addr_list),4); - return(qhbuf); -} - -/* Dump raw form of IP address/port by fancy output to user - */ -static void dumpraddr(unsigned char *a) -{ -short port; - printf("[%u.%u.%u.%u]",a[0],a[1],a[2],a[3]); - port=(signed short)ntohs(*(unsigned short *)(a+4)); - if (port) printf(":%+d",port); -} - -/* Like dumpraddr() but for structure "sockaddr_in" - */ - -static void dumpaddr(struct sockaddr_in *sin) -{ -unsigned short ports; - - memcpy(qhbuf+0,&sin->sin_addr,4); - ports=htons(((short)ntohs(sin->sin_port))-UDP_BASEPORT); - memcpy(qhbuf+4,&ports,2); - dumpraddr(qhbuf); -} - -/* Startup... Uninteresting parsing... - */ - -static int ipx_udp_GetMyAddress(void) { - -char buf[256]; -int i; -char *s,*s2,*ns; - - if (!have_empty_address()) - return 0; - - if (!((i=FindArg("-udp")) && (s=Args[i+1]) && (*s=='=' || *s=='+' || *s=='@'))) s=NULL; - - if (gethostname(buf,sizeof(buf))) FAIL("Error getting my hostname"); - if (!(queryhost(buf))) FAIL("Querying my own hostname \"%s\"",buf); - - if (s) while (*s=='@') { - portshift(++s); - while (isdigit(*s)) s++; - } - - memset(ipx_MyAddress+0,0,4); - memcpy(ipx_MyAddress+4,qhbuf,6); - baseport+=(short)ntohs(*(unsigned short *)(qhbuf+4)); - - if (!s || (s && !*s)) addiflist(); - else { - if (*s=='+') addiflist(); - s++; - for (;;) { -struct sockaddr_in *sin; - while (isspace(*s)) s++; - if (!*s) break; - for (s2=s;*s2 && *s2!=',';s2++); - chk(ns=malloc(s2-s+1)); - memcpy(ns,s,s2-s); - ns[s2-s]='\0'; - if (!queryhost(ns)) msg("Ignored broadcast-destination \"%s\" as being invalid",ns); - free(ns); - chkbroadsize(); - sin=broads+(broadnum++); - sin->sin_family=AF_INET; - memcpy(&sin->sin_addr,qhbuf+0,4); - sin->sin_port=htons(((short)ntohs(*(unsigned short *)(qhbuf+4)))+UDP_BASEPORT); - s=s2+(*s2==','); - } - } - - unifyiflist(); - - printf(MSGHDR "Using TCP/IP address "); - dumpraddr(ipx_MyAddress+4); - putchar('\n'); - if (broadnum) { - printf(MSGHDR "Using %u broadcast-dest%s:",broadnum,(broadnum==1?"":"s")); - for (i=0;ifd = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP)) < 0) { - sk->fd = -1; - FAIL("socket() creation failed on port %d: %m",port); - } - if (setsockopt(sk->fd,SOL_SOCKET,SO_BROADCAST,&val_one,sizeof(val_one))) { - if (close(sk->fd)) msg("close() failed during error recovery: %m"); - sk->fd=-1; - FAIL("setsockopt(SO_BROADCAST) failed: %m"); - } - sin.sin_family=AF_INET; - sin.sin_addr.s_addr=htonl(INADDR_ANY); - sin.sin_port=htons(baseport); - if (bind(sk->fd,(struct sockaddr *)&sin,sizeof(sin))) { - if (close(sk->fd)) msg("close() failed during error recovery: %m"); - sk->fd=-1; - FAIL("bind() to UDP port %d failed: %m",baseport); - } - - open_sockets++; - sk->socket = port; - return 0; -} - -/* The same comment as in previous "ipx_udp_OpenSocket"... - */ - -static void ipx_udp_CloseSocket(ipx_socket_t *mysock) { - if (!open_sockets) { - msg("close w/o open"); - return; - } - msg("CloseSocket on D1X socket port %d",mysock->socket); - if (close(mysock->fd)) - msg("close() failed on CloseSocket D1X socket port %d: %m",mysock->socket); - mysock->fd=-1; - if (--open_sockets) { - msg("(closesocket) %d sockets left", open_sockets); - return; - } -} - -/* Here we'll send the packet to our host. If it is unicast packet, send - * it to IP address/port as retrieved from IPX address. Otherwise (broadcast) - * we'll repeat the same data to each host in our broadcasting list. - */ - -static int ipx_udp_SendPacket(ipx_socket_t *mysock, IPXPacket_t *IPXHeader, - u_char *data, int dataLen) { - struct sockaddr_in toaddr,*dest; - int i=dataLen; - int bcast; - char *buf; - -#ifdef UDPDEBUG - msg("SendPacket enter, dataLen=%d",dataLen); -#endif - if (dataLen<0 || dataLen>MAX_PACKETSIZE) return -1; - chk(buf=alloca(8+dataLen)); - if (compatibility) memcpy(buf+0,D1Xudp,6),buf+=6; - else memcpy(buf+0,D1Xid ,2),buf+=2; - memcpy(buf+0,IPXHeader->Destination.Socket,2); - memcpy(buf+2,data,dataLen); - - toaddr.sin_family=AF_INET; - memcpy(&toaddr.sin_addr,IPXHeader->Destination.Node+0,4); - toaddr.sin_port=htons(((short)ntohs(*(unsigned short *)(IPXHeader->Destination.Node+4)))+UDP_BASEPORT); - - for (bcast=(toaddr.sin_addr.s_addr==htonl(INADDR_BROADCAST)?0:-1);bcast=0) dest=broads+bcast; - else dest=&toaddr; - -#ifdef UDPDEBUG - printf(MSGHDR "sendto((%d),Node=[4] %02X %02X,Socket=%02X %02X,s_port=%u,", - dataLen, - IPXHeader->Destination.Node [4],IPXHeader->Destination.Node [5], - IPXHeader->Destination.Socket[0],IPXHeader->Destination.Socket[1], - ntohs(dest->sin_port)); - dumpaddr(dest); - puts(")."); -#endif - i=sendto(mysock->fd,buf-(compatibility?6:2),(compatibility?8:4)+dataLen, - 0,(struct sockaddr *)dest,sizeof(*dest)); - if (bcast==-1) return (i<8?-1:i-8); - } - return(dataLen); -} - -/* Here we will receive new packet to the given buffer. Both formats of packets - * are supported, we fallback to old format when first obsolete packet is seen. - * If the (valid) packet is received from unknown host, we will add it to our - * broadcasting list. FIXME: For now such autoconfigured hosts are NEVER removed. - */ - -static int ipx_udp_ReceivePacket(ipx_socket_t *s, char *outbuf, int outbufsize, - struct ipx_recv_data *rd) { - int size; - struct sockaddr_in fromaddr; - int fromaddrsize=sizeof(fromaddr); - unsigned short ports; - size_t offs; - int i; - - if ((size=recvfrom(s->fd,outbuf,outbufsize,0,(struct sockaddr *)&fromaddr,&fromaddrsize))<0) - return -1; -#ifdef UDPDEBUG - printf(MSGHDR "recvfrom((%d-8=%d),",size,size-8); - dumpaddr(&fromaddr); - puts(")."); -#endif - if (fromaddr.sin_family!=AF_INET) return -1; - if (size<4) return -1; - if (memcmp(outbuf+0,D1Xid,2)) { - if (size<8 || memcmp(outbuf+0,D1Xudp,6)) return -1; - if (!compatibility) { - compatibility=1; - fputs(MSGHDR "Received obsolete packet from ",stdout); - dumpaddr(&fromaddr); - puts(", upgrade that machine.\n" MSGHDR "Turning on compatibility mode..."); - } - offs=6; - } - else offs=2; - - /* Lace: (dst_socket & src_socket) should be network-byte-order by comment in include/ipx_drv.h */ - /* This behaviour presented here is broken. It is not used anywhere, so why bother? */ - rd->src_socket = ntohs(*(unsigned short *)(outbuf+offs)); - if (rd->src_socket != s->socket) { -#ifdef UDPDEBUG - msg(" - pkt was dropped (dst=%d,my=%d)",rd->src_socket,s->socket); -#endif - return -1; - } - rd->dst_socket = s->socket; - - for (i=0;i=masksnum) { - if (addreq(fromaddr,broads[i])) break; - } - else { - if (fromaddr.sin_port==broads[i].sin_port - &&( fromaddr.sin_addr.s_addr & broadmasks[i].sin_addr.s_addr) - ==(broads[i].sin_addr.s_addr & broadmasks[i].sin_addr.s_addr)) break; - } - } - if (i>=broadnum) { - chkbroadsize(); - broads[broadnum++]=fromaddr; - fputs(MSGHDR "Adding host ",stdout); - dumpaddr(&fromaddr); - puts(" to broadcasting address list"); - } - - memmove(outbuf,outbuf+offs+2,size-(offs+2)); - size-=offs+2; - - memcpy(rd->src_node+0,&fromaddr.sin_addr,4); - ports=htons(ntohs(fromaddr.sin_port)-UDP_BASEPORT); - memcpy(rd->src_node+4,&ports,2); - memset(rd->src_network, 0, 4); - rd->pkt_type = 0; -#ifdef UDPDEBUG - printf(MSGHDR "ReceivePacket: size=%d,from=",size); - dumpraddr(rd->src_node); - putchar('\n'); -#endif - - return size; -} - -struct ipx_driver ipx_udp = { - ipx_udp_GetMyAddress, - ipx_udp_OpenSocket, - ipx_udp_CloseSocket, - ipx_udp_SendPacket, - ipx_udp_ReceivePacket, - ipx_general_PacketReady -}; -#endif // NETWORK -#endif // __ENV_LINUX__ diff --git a/arch/linux/linuxnet.c b/arch/linux/linuxnet.c deleted file mode 100644 index 36a13ff8..00000000 --- a/arch/linux/linuxnet.c +++ /dev/null @@ -1,368 +0,0 @@ -/* -THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX -SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO -END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A -ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS -IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS -SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE -FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE -CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS -AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. -COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. -*/ -#include - -#ifdef __ENV_LINUX__ -#ifdef NETWORK -#include -#include -#include -#include -#include -#include /* for htons & co. */ - -#include "pstypes.h" -#include "config.h" -#include "args.h" - -#include "ipx_drv.h" -#include "ipx_bsd.h" -#include "ipx_kali.h" -#include "ipx_udp.h" -//added 05/17/99 Matt Mueller - needed to redefine FD_* so that no asm is used -//#include "checker.h" -//end addition -MM -#define MAX_IPX_DATA 576 - -int ipx_fd; -ipx_socket_t ipx_socket_data; -ubyte ipx_installed=0; -ushort ipx_socket = 0; -uint ipx_network = 0; -ubyte ipx_MyAddress[10]; -int ipx_packetnum = 0; /* Sequence number */ -//int ipx_packettotal=0,ipx_lastspeed=0; - -/* User defined routing stuff */ -typedef struct user_address { - ubyte network[4]; - ubyte node[6]; - ubyte address[6]; -} user_address; -#define MAX_USERS 64 -int Ipx_num_users = 0; -user_address Ipx_users[MAX_USERS]; - -#define MAX_NETWORKS 64 -int Ipx_num_networks = 0; -uint Ipx_networks[MAX_NETWORKS]; - -void ipx_close(void); - -int ipx_general_PacketReady(ipx_socket_t *s) { - fd_set set; - struct timeval tv; - - FD_ZERO(&set); - FD_SET(s->fd, &set); - tv.tv_sec = tv.tv_usec = 0; - if (select(s->fd + 1, &set, NULL, NULL, &tv) > 0) - return 1; - else - return 0; -} - -struct ipx_driver *driver = &ipx_bsd; - -ubyte * ipx_get_my_server_address() -{ - return (ubyte *)&ipx_network; -} - -ubyte * ipx_get_my_local_address() -{ - return (ubyte *)(ipx_MyAddress + 4); -} - -//--------------------------------------------------------------- -// Initializes all IPX internals. -// If socket_number==0, then opens next available socket. -// Returns: 0 if successful. -// -1 if socket already open. -// -2 if socket table full. -// -3 if IPX not installed. -// -4 if couldn't allocate low dos memory -// -5 if error with getting internetwork address -int ipx_init( int socket_number, int show_address ) -{ - int i; - -/* DPH: killed kali for now - if (FindArg("-kali")) { - printf("Using Kali for network games\n"); - driver = &ipx_kali; -//added on 12/20/98 by Jan Kratochvil for direct TCP/IP games - } else*/ if (FindArg("-udp")) { - printf("Using native TCP/IP (UDP) for network games\n"); - driver = &ipx_udp; -//end this section addition - JK - } else { - printf("Using real IPX for network games\n"); - driver = &ipx_bsd; - } - if ((i = FindArg("-ipxnetwork")) && Args[i + 1]) { - unsigned long n = strtol(Args[i + 1], NULL, 16); - ipx_MyAddress[0] = n >> 24; ipx_MyAddress[1] = (n >> 16) & 255; - ipx_MyAddress[2] = (n >> 8) & 255; ipx_MyAddress[3] = n & 255; - printf("IPX: Using network %08x\n", (unsigned int)n); - } - if (driver->OpenSocket(&ipx_socket_data, socket_number)) { - return -3; - } - driver->GetMyAddress(); - memcpy(&ipx_network, ipx_MyAddress, 4); - Ipx_num_networks = 0; - memcpy( &Ipx_networks[Ipx_num_networks++], &ipx_network, 4 ); - ipx_installed = 1; - atexit(ipx_close); - return 0; -} - -void ipx_close() -{ - if (ipx_installed) - driver->CloseSocket(&ipx_socket_data); - ipx_installed = 0; -} - -int ipx_get_packet_data( ubyte * data ) -{ - struct ipx_recv_data rd; - char buf[MAX_IPX_DATA]; -//killed 6-15-99 to get rid of compile warnings - OE -// uint best_id = 0; -// uint pkt_num; -//end kill - OE - int size; - int best_size = 0; -//edited 04/12/99 Matt Mueller - duh, we don't want to throw all that data away! - //--killed-- Like the original, only take latest packet, throw away rest - //do _NOT_ throw them away! - while (driver->PacketReady(&ipx_socket_data)) { - if ((size = - driver->ReceivePacket(&ipx_socket_data, buf, - sizeof(buf), &rd)) > 4) { - if (!memcmp(rd.src_network, ipx_MyAddress, 10)) - continue; /* don't get own pkts */ -//--killed-- pkt_num = *(uint *)buf; -//--killed-- if (pkt_num >= best_id) { - memcpy(data, buf + 4, size - 4); - return size-4; -//--killed-- best_id = pkt_num; -//--killed-- best_size = size - 4; -//--killed-- } -//end edit -MM - } - } - return best_size; -} - -void ipx_send_packet_data( ubyte * data, int datasize, ubyte *network, ubyte *address, ubyte *immediate_address ) -{ - u_char buf[MAX_IPX_DATA]; - IPXPacket_t ipx_header; - - memcpy(ipx_header.Destination.Network, network, 4); - memcpy(ipx_header.Destination.Node, immediate_address, 6); - *(u_short *)ipx_header.Destination.Socket = htons(ipx_socket_data.socket); - ipx_header.PacketType = 4; /* Packet Exchange */ - *(uint *)buf = ipx_packetnum++; - //ipx_packettotal+=datasize+4; - //if (f2i(Players[Player_num].time_level) && (f2i(Players[Player_num].time_level)%10!=ipx_lastspeed)) - //{ - // ipx_lastspeed=f2i(Players[Player_num].time_level)%10; - // printf("tot=%i,t2=%i,time=%i,avg=%i,a2=%i\n",ipx_packetnum,ipx_packettotal,(int)f2i(Players[Player_num].time_level), - // ipx_packetnum/(int)f2i(Players[Player_num].time_level), - // ipx_packettotal/(int)f2i(Players[Player_num].time_level)); - //} - memcpy(buf + 4, data, datasize); - driver->SendPacket(&ipx_socket_data, &ipx_header, buf, datasize + 4); -} - -void ipx_get_local_target( ubyte * server, ubyte * node, ubyte * local_target ) -{ - // let's hope Linux knows how to route it - memcpy( local_target, node, 6 ); -} - -void ipx_send_broadcast_packet_data( ubyte * data, int datasize ) -{ - int i, j; - ubyte broadcast[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - ubyte local_address[6]; - - // Set to all networks besides mine - for (i=0; iCloseSocket(&ipx_socket_data); - if (driver->OpenSocket(&ipx_socket_data, socket_number)) { - return -3; - } - return 0; -} - -void ipx_read_user_file(char * filename) -{ - FILE * fp; - user_address tmp; - char temp_line[132], *p1; - int n, ln=0, x; - - if (!filename) return; - - Ipx_num_users = 0; - - fp = fopen( filename, "rt" ); - if ( !fp ) return; - - printf( "Broadcast Users:\n" ); - - while (fgets(temp_line, 132, fp)) { - ln++; - p1 = strchr(temp_line,'\n'); if (p1) *p1 = '\0'; - p1 = strchr(temp_line,';'); if (p1) *p1 = '\0'; -#if 1 // adb: replaced sscanf(..., "%2x...", (char *)...) with better, but longer code - if (strlen(temp_line) >= 21 && temp_line[8] == '/') { - for (n = 0; n < 4; n++) { - if (sscanf(temp_line + n * 2, "%2x", &x) != 1) - break; - tmp.network[n] = x; - } - if (n != 4) - continue; - for (n = 0; n < 6; n++) { - if (sscanf(temp_line + 9 + n * 2, "%2x", &x) != 1) - break; - tmp.node[n] = x; - } - if (n != 6) - continue; - } else - continue; -#else - n = sscanf( temp_line, "%2x%2x%2x%2x/%2x%2x%2x%2x%2x%2x", &tmp.network[0], &tmp.network[1], &tmp.network[2], &tmp.network[3], &tmp.node[0], &tmp.node[1], &tmp.node[2],&tmp.node[3], &tmp.node[4], &tmp.node[5] ); - if ( n != 10 ) continue; -#endif - if ( Ipx_num_users < MAX_USERS ) { - ubyte * ipx_real_buffer = (ubyte *)&tmp; - ipx_get_local_target( tmp.network, tmp.node, tmp.address ); - Ipx_users[Ipx_num_users++] = tmp; - printf( "%02X%02X%02X%02X/", ipx_real_buffer[0],ipx_real_buffer[1],ipx_real_buffer[2],ipx_real_buffer[3] ); - printf( "%02X%02X%02X%02X%02X%02X\n", ipx_real_buffer[4],ipx_real_buffer[5],ipx_real_buffer[6],ipx_real_buffer[7],ipx_real_buffer[8],ipx_real_buffer[9] ); - } else { - printf( "Too many addresses in %s! (Limit of %d)\n", filename, MAX_USERS ); - fclose(fp); - return; - } - } - fclose(fp); -} - - -void ipx_read_network_file(char * filename) -{ - FILE * fp; - user_address tmp; - char temp_line[132], *p1; - int i, n, ln=0, x; - - if (!filename) return; - - fp = fopen( filename, "rt" ); - if ( !fp ) return; - - printf( "Using Networks:\n" ); - for (i=0; i= 8) { - for (n = 0; n < 4; n++) { - if (sscanf(temp_line + n * 2, "%2x", &x) != 1) - break; - tmp.network[n] = x; - } - if (n != 4) - continue; - } else - continue; -#else - n = sscanf( temp_line, "%2x%2x%2x%2x", &tmp.network[0], &tmp.network[1], &tmp.network[2], &tmp.network[3] ); - if ( n != 4 ) continue; -#endif - if ( Ipx_num_networks < MAX_NETWORKS ) { - int j; - for (j=0; j= Ipx_num_networks ) { - memcpy( &Ipx_networks[Ipx_num_networks++], tmp.network, 4 ); - printf(" %02x%02x%02x%02x\n", tmp.network[0], tmp.network[1], tmp.network[2], tmp.network[3] ); - } - } else { - printf( "Too many networks in %s! (Limit of %d)\n", filename, MAX_NETWORKS ); - fclose(fp); - return; - } - } - fclose(fp); -} -#endif //NETWORK -#endif // __ENV_LINUX__ diff --git a/arch/sdl/Makefile.am b/arch/sdl/Makefile.am deleted file mode 100644 index ae50d58e..00000000 --- a/arch/sdl/Makefile.am +++ /dev/null @@ -1,2 +0,0 @@ -EXTRA_DIST = \ -init.c timer.c diff --git a/arch/sdl/init.c b/arch/sdl/init.c deleted file mode 100644 index 29d33bf5..00000000 --- a/arch/sdl/init.c +++ /dev/null @@ -1,29 +0,0 @@ -// SDL architecture support -#include -#include -#include -#include -#include "text.h" -#include "event.h" -#include "error.h" -#include "args.h" - -extern void d_mouse_init(); - -void sdl_close() -{ - SDL_Quit(); -} - -void arch_sdl_init() -{ - // Initialise the library -//edited on 01/03/99 by Matt Mueller - if we use SDL_INIT_EVERYTHING, cdrom is initialized even if -nocdaudio is used -#ifdef SDL_INPUT - if (!FindArg("-nomouse")) - d_mouse_init(); -#endif - if (!FindArg("-nosound")) - digi_init(); - atexit(sdl_close); -} diff --git a/arch/sdl/timer.c b/arch/sdl/timer.c deleted file mode 100644 index 715bcb28..00000000 --- a/arch/sdl/timer.c +++ /dev/null @@ -1,13 +0,0 @@ -// SDL library timer functions - -#include -#include -#include "maths.h" - -fix timer_get_fixed_seconds(void) { - fix x; - unsigned long tv_now = SDL_GetTicks(); - x=i2f(tv_now/1000) | fixdiv(i2f(tv_now % 1000),i2f(1000)); - return x; -} - -- 2.39.2