text_dos.c

Go to the documentation of this file.
00001 /* --
00002 OpenFX version 1.0 - Modelling, Animation and Rendering Package
00003 Copyright (C) 2000 OpenFX Development Team
00004 
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009 
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 
00019 You may contact the OpenFX development team via elecronic mail
00020 at core@openfx.org, or visit our website at http://openfx.org for
00021 further information and support details.
00022 -- */
00023 
00024 /* text_dos  a TSR to return an external texture.c  */
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <int.h>
00030 #include <dos.h>
00031 #include <math.h>
00032 
00033 #define double float
00034 #define INTNO 0x60
00035 #define _FAR _far
00036 
00037 typedef struct tfxinfo_tag{
00038  long tid;       /* the id of the texture starts at 16        */
00039  long frame;     /* the frame of the animation                */
00040  double alpha,   /* position of surface point relative to the */
00041         beta,    /* shader axes alpha/beta in plane of axes   */
00042         gamma;   /* gamma at right angles to plane            */
00043  double x,y;     /* the surface mapping coords - if available */
00044  double   R,G,B; /* returned RGB colours on scale if 0-255.0  */
00045  unsigned char fc[3], /* original colour of face              */
00046                sc[3]; /* secondary (shader) colour for face   */
00047  unsigned char pad1,pad2;
00048 } tfxinfo;
00049 
00050 ExternalTextureProcedure(unsigned short tid, tfxinfo _FAR *TFXinfo);
00051 
00052 int cdecl tsr_install (void);
00053 int cdecl tsr_uninstall ( void );
00054 
00055 main(int argc, char **argv){
00056 int i;
00057  if((strncmp(argv[1],"/R",2) ==0)  || (strncmp(argv[1],"/r",2)==0)){
00058    i=tsr_uninstall();
00059    if(i==0)printf("Program removed\n");
00060    if(i==2)printf("Can not remove, Program not loaded!\n");
00061    if(i==3)printf("Can not remove, Another program loaded above\n");
00062    exit(0);
00063  }
00064  i=tsr_install();
00065  /* if it returns, error has occured       */
00066  if(i==1)printf("Can not load, program already loaded!\n");
00067  else    printf("Failed to install, error %i\n",i);
00068 }
00069 
00070 extern int cdecl _datapar;
00071 extern int cdecl _progpar;
00072 
00073 int cdecl tsr_test_vect ( unsigned vno , unsigned dataseg );
00074 int cdecl tsr_already_in ( void );
00075 int cdecl tsr_new_interrupt ( struct INT_DATA* );
00076 
00077 char tsr_fprint[20] = "tsrclock.v1";  /* unique string*/
00078 volatile int cdecl tsr_running;
00079 volatile char cdecl oldinterrupt[4];
00080 volatile int cdecl oldpsp;
00081 int cdecl tsr_vect_changed;
00082 unsigned cdecl tsr_codeseg;
00083 struct SREGS segregs;
00084 union REGS regs;
00085 
00086 tsr_install(void){
00087  unsigned code,data,stack,extra;
00088  if(tsr_already_in() !=0)return 1;
00089  oldpsp=_psp;
00090  peek(0x0,INTNO*4,&oldinterrupt,4);
00091  int_intercept(INTNO,tsr_new_interrupt,1500);
00092  regs.x.dx=_datapar;
00093  regs.x.dx=regs.x.dx+_progpar;
00094  regs.h.ah=0x31;
00095  intdos(&regs,&regs);
00096 }
00097 
00098 tsr_uninstall(void){
00099  char near *np, far *fp;
00100  int near *inp,far *ifp;
00101  unsigned cseg,pid,mlen;
00102  char mz;
00103  unsigned tsr_ds,tsr_off;
00104  if(tsr_running==0){
00105     tsr_ds=tsr_already_in();
00106     if(tsr_ds == 0)return 2;
00107  }
00108  else tsr_ds=getDS();
00109  tsr_vect_changed=0;
00110  tsr_test_vect(INTNO,tsr_ds);
00111  if(tsr_vect_changed!=0)return 3;
00112  if(tsr_running==0){
00113    np=&tsr_fprint[0];
00114    *np=0;
00115    fp=MK_FP(getDS(),(unsigned) np);
00116    tsr_off=FP_OFF(fp);
00117    poke(tsr_ds,tsr_off,&tsr_fprint,1);
00118    np=&oldinterrupt[0];
00119    fp=MK_FP(getDS(),(unsigned) np);
00120    tsr_off=FP_OFF(fp);
00121    peek(tsr_ds,tsr_off,&oldinterrupt,4);
00122    inp=&oldpsp;
00123    ifp=MK_FP(getDS(),(unsigned) inp);
00124    tsr_off=FP_OFF(ifp);
00125    peek(tsr_ds,tsr_off,&oldpsp,2);
00126  }
00127  int_off();
00128  poke(0x0,INTNO*4,&oldinterrupt,4);
00129  int_on();
00130  peek(0,0x00ba,&cseg,2);
00131  cseg-=1;
00132 un1:
00133  peek(cseg,0,&mz,1);
00134  if(mz != 0x4d)goto un9;
00135  peek(cseg,1,&pid,2);
00136  peek(cseg,3,&mlen,2);
00137  cseg+=1;
00138  if(pid == oldpsp){
00139    segregs.es=cseg;
00140    regs.h.ah=0x49;
00141    intdosx(&regs,&regs,&segregs);
00142  }
00143  cseg+=mlen;
00144  goto un1;
00145 un9:
00146  return 0;
00147 }
00148 
00149 tsr_test_vect(vno,dataseg) unsigned vno,dataseg; {
00150 unsigned lseg,loff;
00151  segread(&segregs);
00152  tsr_codeseg=dataseg-(segregs.ds-segregs.cs);
00153  int_getvector(vno,&loff,&lseg);
00154  if((lseg == tsr_codeseg) || (lseg == dataseg)) return;
00155  else  tsr_vect_changed+=1;
00156 }
00157 
00158 tsr_already_in(void){
00159  int tsr_hit;
00160  char near *np, far *fp;
00161  char tsr_match[20];
00162  unsigned tsr_seg,tsr_off,tsr_ds;
00163  tsr_hit=0;
00164  np=&tsr_fprint[0];
00165  *np=1;
00166  fp=MK_FP(getDS(),(unsigned) np);
00167  tsr_seg=FP_SEG(fp);
00168  tsr_off=FP_OFF(fp);
00169  tsr_ds=0x600;
00170  while((tsr_ds < tsr_seg) && tsr_hit==0) {
00171    peek(tsr_ds,tsr_off,&tsr_match,19);
00172    if(strcmp(tsr_fprint,tsr_match) == 0)tsr_hit=1;
00173    else                                 tsr_ds+=1;
00174  }
00175  if(tsr_hit==1)return(tsr_ds);
00176  else          return 0;
00177 }
00178 
00179 tsr_new_interrupt(struct INT_DATA *p){
00180  tfxinfo _FAR *TFXinfo;
00181  unsigned short off,seg,tid;
00182  if(tsr_running)return 0;
00183  tsr_running=1;
00184  off=(unsigned short)p->regs.x.ax;
00185  seg=(unsigned short)p->regs.x.bx;
00186  tid=(unsigned short)p->regs.x.cx;
00187  TFXinfo=MK_FP(seg,off);
00188  ExternalTextureProcedure(tid,TFXinfo);
00189  tsr_running=0;
00190  return 1;
00191 }
00192 
00193 
00194 ExternalTextureProcedure(unsigned short tid, tfxinfo _FAR *TFXinfo){
00195  TFXinfo->R=255.0;
00196  TFXinfo->G=255.0;
00197  TFXinfo->B=0.0;
00198 }
Generated on Tue Jan 28 06:18:32 2014 for OpenFX by  doxygen 1.6.3