Browse Source

psy-q-sdk bindings

Kirill Kranz 9 months ago
parent
commit
ccc6fa0ec6

+ 34 - 2
rtl/ps1/Makefile

@@ -923,7 +923,7 @@ ifdef NO_EXCEPTIONS_IN_SYSTEM
 override FPCOPT+=-dNO_EXCEPTIONS_IN_SYSTEM
 endif
 ifeq ($(CPU_OS_TARGET),mipsel-ps1)
-override TARGET_UNITS+=$(SYSTEMUNIT) $(OBJPASUNIT) $(FPINTRESUNIT) $(ISO7185UNIT) $(CTYPESUNIT) $(SYSCONSTUNIT) $(UUCHARUNIT) $(STRINGSUNIT) libstd libetc libgpu libgte
+override TARGET_UNITS+=$(SYSTEMUNIT) $(OBJPASUNIT) $(FPINTRESUNIT) $(ISO7185UNIT) $(CTYPESUNIT) $(SYSCONSTUNIT) $(UUCHARUNIT) $(STRINGSUNIT) libstd libetc libgpu libgte libapi libcd libcomb libgs libsnd libspu libds libgun libmcrd libtap libpad libmcx libpress libsn libmcgui libhmd
 endif
 override INSTALL_FPCPACKAGE=y y
 ifeq ($(CPU_OS_TARGET),mipsel-ps1)
@@ -2926,7 +2926,39 @@ libstd$(PPUEXT) : psy-q-sdk/libstd.pas $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
 libetc$(PPUEXT) : psy-q-sdk/libetc.pas $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
-libgpu$(PPUEXT) : psy-q-sdk/libgpu.pas libgte$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+libgpu$(PPUEXT) : psy-q-sdk/libgpu.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
 libgte$(PPUEXT) : psy-q-sdk/libgte.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
 	$(COMPILER) $<
+libapi$(PPUEXT) : psy-q-sdk/libapi.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libcd$(PPUEXT) : psy-q-sdk/libcd.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libcomb$(PPUEXT) : psy-q-sdk/libcomb.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libgs$(PPUEXT) : psy-q-sdk/libgs.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libsnd$(PPUEXT) : psy-q-sdk/libsnd.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libspu$(PPUEXT) : psy-q-sdk/libspu.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libds$(PPUEXT) : psy-q-sdk/libds.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libgun$(PPUEXT) : psy-q-sdk/libgun.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libmcrd$(PPUEXT) : psy-q-sdk/libmcrd.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libtap$(PPUEXT) : psy-q-sdk/libtap.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libpad$(PPUEXT) : psy-q-sdk/libpad.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libmcx$(PPUEXT) : psy-q-sdk/libmcx.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libpress$(PPUEXT) : psy-q-sdk/libpress.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libsn$(PPUEXT) : psy-q-sdk/libsn.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libmcgui$(PPUEXT) : psy-q-sdk/libmcgui.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<
+libhmd$(PPUEXT) : psy-q-sdk/libhmd.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+	$(COMPILER) $<

+ 49 - 2
rtl/ps1/Makefile.fpc

@@ -7,7 +7,7 @@ main=rtl
 loaders=
 units=$(SYSTEMUNIT) $(OBJPASUNIT) $(FPINTRESUNIT) $(ISO7185UNIT) $(CTYPESUNIT) \
   $(SYSCONSTUNIT) $(UUCHARUNIT) $(STRINGSUNIT) \
-  libstd libetc libgpu libgte
+  libstd libetc libgpu libgte libapi libcd libcomb libgs libsnd libspu libds libgun libmcrd libtap libpad libmcx libpress libsn libmcgui libhmd
 
 [require]
 nortl=y
@@ -57,12 +57,59 @@ libstd$(PPUEXT) : psy-q-sdk/libstd.pas $(SYSTEMUNIT)$(PPUEXT)
 libetc$(PPUEXT) : psy-q-sdk/libetc.pas $(SYSTEMUNIT)$(PPUEXT)
         $(COMPILER) $<
 
-libgpu$(PPUEXT) : psy-q-sdk/libgpu.pas libgte$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+libgpu$(PPUEXT) : psy-q-sdk/libgpu.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
         $(COMPILER) $<
 
 libgte$(PPUEXT) : psy-q-sdk/libgte.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
         $(COMPILER) $<
 
+libapi$(PPUEXT) : psy-q-sdk/libapi.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libcd$(PPUEXT) : psy-q-sdk/libcd.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libcomb$(PPUEXT) : psy-q-sdk/libcomb.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libgs$(PPUEXT) : psy-q-sdk/libgs.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libsnd$(PPUEXT) : psy-q-sdk/libsnd.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libspu$(PPUEXT) : psy-q-sdk/libspu.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libds$(PPUEXT) : psy-q-sdk/libds.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libgun$(PPUEXT) : psy-q-sdk/libgun.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libmcrd$(PPUEXT) : psy-q-sdk/libmcrd.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libtap$(PPUEXT) : psy-q-sdk/libtap.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libpad$(PPUEXT) : psy-q-sdk/libpad.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libmcx$(PPUEXT) : psy-q-sdk/libmcx.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libpress$(PPUEXT) : psy-q-sdk/libpress.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libsn$(PPUEXT) : psy-q-sdk/libsn.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libmcgui$(PPUEXT) : psy-q-sdk/libmcgui.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
+
+libhmd$(PPUEXT) : psy-q-sdk/libhmd.pas $(OBJPASUNIT)$(PPUEXT) $(SYSTEMUNIT)$(PPUEXT)
+        $(COMPILER) $<
 #
 # Loaders
 #

+ 0 - 5
rtl/ps1/buildrtl.pp

@@ -1,5 +0,0 @@
-{$MODE OBJFPC}
-unit buildrtl;
-interface
-implementation
-end.

+ 0 - 7
rtl/ps1/psy-q-sdk/libabs.pas

@@ -1,7 +0,0 @@
-// $PSLibId: Run-time Library Release 4.6
-unit libabs;
-interface
-	function abs(num: longint): longint; stdcall; external;
-implementation
-begin
-end.

+ 27 - 27
rtl/ps1/psy-q-sdk/libcd.pas

@@ -233,44 +233,44 @@ function StNextStatus(addr: pointer; header: pointer): u_short; stdcall external
 procedure StRingStatus(free_sectors: Pshort; over_sectors: Pshort); stdcall external;
 procedure StSetMask(mask: u_long; start, _end: u_long); stdcall external;
 procedure StCdInterrupt; stdcall external;
-function StGetBackloc(loc: PCdlLOC): integer; stdcall external;
-function StSetChannel(channel: u_long): integer; stdcall external;
+function StGetBackloc(loc: PCdlLOC): longint; stdcall external;
+function StSetChannel(channel: u_long): longint; stdcall external;
 
 // Prototypes
 procedure CdFlush; stdcall external;
 function CdSearchFile(fp: PCdlFILE; name: pchar): PCdlFILE; stdcall external;
-function CdIntToPos(i: integer; p: PCdlLOC): PCdlLOC; stdcall external;
+function CdIntToPos(i: longint; p: PCdlLOC): PCdlLOC; stdcall external;
 function CdComstr(com: byte): pchar; stdcall external;
 function CdIntstr(intr: byte): pchar; stdcall external;
-function CdControl(com: byte; param: Pbyte; result: Pbyte): integer; stdcall external;
-function CdControlB(com: byte; param: Pbyte; result: Pbyte): integer; stdcall external;
-function CdControlF(com: byte; param: Pbyte): integer; stdcall external;
-function CdGetSector(madr: pointer; size: integer): integer; stdcall external;
-function CdGetSector2(madr: pointer; size: integer): integer; stdcall external;
-function CdDataSync(mode: integer): integer; stdcall external;
-function CdGetToc(loc: PCdlLOC): integer; stdcall external;
-function CdPlay(mode: integer; track: Pinteger; offset: integer): integer; stdcall external;
-function CdMix(vol: PCdlATV): integer; stdcall external;
-function CdPosToInt(p: PCdlLOC): integer; stdcall external;
-function CdRead(sectors: integer; buf: pointer; mode: integer): integer; stdcall external;
-function CdRead2(mode: longint): integer; stdcall external;
-function CdReadFile(_file: pchar; addr: pointer; nbyte: integer): integer; stdcall external;
-function CdReadSync(mode: integer; res: pointer): integer; stdcall external;
-function CdReady(mode: integer; res: pointer): integer; stdcall external;
-function CdSetDebug(level: integer): integer; stdcall external;
-procedure CdSync(mode: integer; res: pointer); stdcall external;
+function CdControl(com: byte; param: Pbyte; result: Pbyte): longint; stdcall external;
+function CdControlB(com: byte; param: Pbyte; result: Pbyte): longint; stdcall external;
+function CdControlF(com: byte; param: Pbyte): longint; stdcall external;
+function CdGetSector(madr: pointer; size: longint): longint; stdcall external;
+function CdGetSector2(madr: pointer; size: longint): longint; stdcall external;
+function CdDataSync(mode: longint): longint; stdcall external;
+function CdGetToc(loc: PCdlLOC): longint; stdcall external;
+function CdPlay(mode: longint; track: Plongint; offset: longint): longint; stdcall external;
+function CdMix(vol: PCdlATV): longint; stdcall external;
+function CdPosToInt(p: PCdlLOC): longint; stdcall external;
+function CdRead(sectors: longint; buf: pointer; mode: longint): longint; stdcall external;
+function CdRead2(mode: longint): longint; stdcall external;
+function CdReadFile(_file: pchar; addr: pointer; nbyte: longint): longint; stdcall external;
+function CdReadSync(mode: longint; res: pointer): longint; stdcall external;
+function CdReady(mode: longint; res: pointer): longint; stdcall external;
+function CdSetDebug(level: longint): longint; stdcall external;
+procedure CdSync(mode: longint; res: pointer); stdcall external;
 function CdDataCallback(func: pointer): pointer; stdcall external;
 function CdReadCallback(func: CdlCB): CdlCB; stdcall external;
 function CdReadyCallback(func: CdlCB): CdlCB; stdcall external;
 function CdSyncCallback(func: CdlCB): CdlCB; stdcall external;
-function CdInit: integer; stdcall external;
-function CdReset(mode: integer): integer; stdcall external;
-function CdStatus: integer; stdcall external;
-function CdLastCom: integer; stdcall external;
+function CdInit: longint; stdcall external;
+function CdReset(mode: longint): longint; stdcall external;
+function CdStatus: longint; stdcall external;
+function CdLastCom: longint; stdcall external;
 function CdLastPos: PCdlLOC; stdcall external;
-function CdMode: integer; stdcall external;
-function CdDiskReady(mode: integer): integer; stdcall external;
-function CdGetDiskType: integer; stdcall external;
+function CdMode: longint; stdcall external;
+function CdDiskReady(mode: longint): longint; stdcall external;
+function CdGetDiskType: longint; stdcall external;
 // CdReadExec(char *file): EXEC;
 procedure CdReadBreak; stdcall external;
 

+ 29 - 29
rtl/ps1/psy-q-sdk/libds.pas

@@ -130,56 +130,56 @@ const
 // maximum number of command execution results
 	DslMaxRESULTS	=	8;
 
-function DsInit: integer; stdcall external;
-function DsReset: integer; stdcall external;
+function DsInit: longint; stdcall external;
+function DsReset: longint; stdcall external;
 procedure DsClose; stdcall external;
-function DsCommand(com: byte; param: pchar; cbsync: DslCB; count: integer ): integer; stdcall external;
-function DsPacket(mode: byte; pos:PDslLOC; com: byte; func: DslCB; count: integer): integer; stdcall external;
+function DsCommand(com: byte; param: pchar; cbsync: DslCB; count: longint ): longint; stdcall external;
+function DsPacket(mode: byte; pos:PDslLOC; com: byte; func: DslCB; count: longint): longint; stdcall external;
 function DsSyncCallback(func: DslCB): DslCB; stdcall external;
 function DsReadyCallback(func: DslCB): DslCB; stdcall external;
-function DsSync(id: integer; res: pointer): integer; stdcall external;
-function DsReady(res: pointer): integer; stdcall external;
+function DsSync(id: longint; res: pointer): longint; stdcall external;
+function DsReady(res: pointer): longint; stdcall external;
 procedure DsFlush; stdcall external;
-function DsSystemStatus: integer; stdcall external;
-function DsQueueLen: integer; stdcall external;
+function DsSystemStatus: longint; stdcall external;
+function DsQueueLen: longint; stdcall external;
 function DsStatus: byte; stdcall external;
-function DsShellOpen: integer; stdcall external;
+function DsShellOpen: longint; stdcall external;
 
-function DsMix(vol: PDslATV): integer; stdcall external;
-function DsGetSector(madr: pointer; size: integer): integer; stdcall external;
-function DsGetSector2(madr: pointer; size: integer): integer; stdcall external;
-function DsGetToc(loc: PDslLOC): integer; stdcall external;
+function DsMix(vol: PDslATV): longint; stdcall external;
+function DsGetSector(madr: pointer; size: longint): longint; stdcall external;
+function DsGetSector2(madr: pointer; size: longint): longint; stdcall external;
+function DsGetToc(loc: PDslLOC): longint; stdcall external;
 procedure DsDataCallback(func: pointer); stdcall external;
-function DsDataSync(mode: integer): integer; stdcall external;
-function DsIntToPos(i: integer; p: PDslLOC): PDslLOC; stdcall external;
-function DsPosToInt(p: PDslLOC): integer; stdcall external;
-function DsSetDebug(level: integer ): integer; stdcall external;
+function DsDataSync(mode: longint): longint; stdcall external;
+function DsIntToPos(i: longint; p: PDslLOC): PDslLOC; stdcall external;
+function DsPosToInt(p: PDslLOC): longint; stdcall external;
+function DsSetDebug(level: longint ): longint; stdcall external;
 function DsLastPos(p: PDslLOC): PDslLOC; stdcall external;
 function DsLastCom: byte; stdcall external;
 
 function DsComstr(com: byte): pchar; stdcall external;
 function DsIntstr(intr: byte): pchar; stdcall external;
 
-function DsStartReadySystem(func: DslRCB; count: integer): integer; stdcall external;
+function DsStartReadySystem(func: DslRCB; count: longint): longint; stdcall external;
 procedure DsEndReadySystem; stdcall external;
-function DsReadySystemMode(mode: integer): integer; stdcall external;
+function DsReadySystemMode(mode: longint): longint; stdcall external;
 
-function DsControlF(com: byte; param: pchar): integer; stdcall external;
-function DsControl(com: byte; param: pchar; res: pointer): integer; stdcall external;
-function DsControlB(com: byte; param: pchar; res: pointer): integer; stdcall external;
+function DsControlF(com: byte; param: pchar): longint; stdcall external;
+function DsControl(com: byte; param: pchar; res: pointer): longint; stdcall external;
+function DsControlB(com: byte; param: pchar; res: pointer): longint; stdcall external;
 
-function DsRead(pos: PDslLOC; sectors: integer; buf: Plongint; mode: integer): integer; stdcall external;
-function DsReadSync(res: pointer): integer; stdcall external;
+function DsRead(pos: PDslLOC; sectors: longint; buf: Plongint; mode: longint): longint; stdcall external;
+function DsReadSync(res: pointer): longint; stdcall external;
 function DsReadCallback(func: DslCB): DslCB; stdcall external;
 procedure DsReadBreak; stdcall external;
-function DsRead2(pos: PDslLOC; mode: integer): integer; stdcall external;
+function DsRead2(pos: PDslLOC; mode: longint): longint; stdcall external;
 
 function DsSearchFile(fp: PDslFILE; name: pchar ): PDslFILE; stdcall external;
-function DsReadFile(_file: pchar; addr: Plongint; nbyte: integer): integer; stdcall external;
-//struct EXEC* DsReadExec( char* file ); stdcall external;
-function DsPlay(mode: integer; tracks: Pinteger; offset: integer): integer; stdcall external;
+function DsReadFile(_file: pchar; addr: Plongint; nbyte: longint): longint; stdcall external;
+function DsReadExec(name: pchar): PEXEC; stdcall external;
+function DsPlay(mode: longint; tracks: Plongint; offset: longint): longint; stdcall external;
 
-procedure DsGetDiskType; stdcall external;
+function DsGetDiskType: longint; stdcall external;
 
 implementation
 

+ 9 - 9
rtl/ps1/psy-q-sdk/libetc.pas

@@ -4,7 +4,7 @@ unit libetc;
 interface 
 
 var
- 	PadIdentifier: integer; external;
+ 	PadIdentifier: longint; external;
 // PAD I/O (SIO Pad)
 const
 	PADLup     = 1 shl 12;
@@ -50,16 +50,16 @@ const
 	MODE_NTSC = 0;
 	MODE_PAL  = 1;
 
-function CheckCallback: integer; stdcall; external;
-procedure PadInit(mode: integer); stdcall; external;
-function ResetCallback: integer; stdcall; external;
-function RestartCallback: integer; stdcall; external;
-function StopCallback: integer; stdcall; external;
-function VSync(mode: integer): integer; stdcall; external;
-function VSyncCallback(f: pointer): integer; stdcall; external;
+function CheckCallback: longint; stdcall; external;
+procedure PadInit(mode: longint); stdcall; external;
+function ResetCallback: longint; stdcall; external;
+function RestartCallback: longint; stdcall; external;
+function StopCallback: longint; stdcall; external;
+function VSync(mode: longint): longint; stdcall; external;
+function VSyncCallback(f: pointer): longint; stdcall; external;
 function GetVideoMode: longint; stdcall; external;
 function SetVideoMode(mode: longint): longint; stdcall; external;
-function PadRead(id: integer): dword; stdcall; external;
+function PadRead(id: longint): dword; stdcall; external;
 procedure PadStop; stdcall; external;
 
 

File diff suppressed because it is too large
+ 1587 - 254
rtl/ps1/psy-q-sdk/libgpu.pas


+ 689 - 1123
rtl/ps1/psy-q-sdk/libgs.pas

@@ -1,9 +1,11 @@
 // libgs.h: Graphic Library Header 
 unit libgs;
 interface
+uses libgte, libgpu;
 
 type
 		PACKET = byte;						// packet peripheral pointer
+		PPACKET = ^PACKET;
 
 const
 		PSBANK 			= $80000000;
@@ -20,7 +22,7 @@ type
 							rotate : SVECTOR;
 							trans : VECTOR;
 		end;
-		GsCOORD2PARAM = ^GsCOORD2PARAM;
+		PGsCOORD2PARAM = ^GsCOORD2PARAM;
 
 		PGsCOORDINATE2 = ^GsCOORDINATE2;
 		GsCOORDINATE2 = packed record
@@ -44,21 +46,23 @@ type
 							rz : longint;
 							super : PGsCOORDINATE2;
 		end;
+		PGsRVIEW2 = ^GsRVIEW2;
        
 		GsF_LIGHT = packed record
 							vx, vy, vz : longint;
 							r, g, b : byte;
 		end;
+		PGsF_LIGHT = ^GsF_LIGHT;
        
 
 
 		GsOT_TAG = packed record
-							p:0..16777215
-							num:0..255;
+							p : 0..16777215;
+							num : 0..255;
 		end;
+		PGsOT_TAG = ^GsOT_TAG;
 
 
-		PGsOT_TAG = ^GsOT_TAG;
 		GsOT = packed record
 							len : dword;
 							org : PGsOT_TAG;
@@ -66,6 +70,7 @@ type
 							point : dword;
 							tag : PGsOT_TAG;
 		end;
+		PGsOT = ^GsOT;
 
 		GsDOBJ2 = packed record
 							attr : dword;					// pers,trans,rotate,disp
@@ -73,6 +78,7 @@ type
 							tmd : pdword;
 							id : dword;
 		end;
+		PGsDOBJ2 = ^GsDOBJ2;
 
 		GsDOBJ3 = packed record
 							attr : dword;					// pers,trans,rotate,disp
@@ -82,6 +88,7 @@ type
 							sv : pdword;					// shared vertex base
 							id : dword;
 		end;
+		PGsDOBJ3 = ^GsDOBJ3;
 
 		GsDOBJ4 = packed record
 							attr : dword; 					// pers,trans,rotate,disp
@@ -97,6 +104,7 @@ type
 							packet : pdword;
 							id : dword;
 		end;
+		PGsDOBJ5 = ^GsDOBJ5;
 
 
 		GsSPRITE = packed record
@@ -111,6 +119,7 @@ type
 							scalex, scaley : smallint;
 							rotate : longint;
 		end;
+		PGsSPRITE = ^GsSPRITE;
 
 
 		GsCELL = packed record
@@ -141,6 +150,7 @@ type
 							scalex, scaley : smallint;
 							rotate : longint;
 		end;
+		PGsBG = ^GsBG;
 
 
 		GsLINE = packed record
@@ -149,6 +159,7 @@ type
 							x1, y1 : smallint;
 							r, g, b : byte;
 		end;
+		PGsLINE = ^GsLINE;
 
 		GsGLINE = packed record
 							attr : dword;
@@ -164,12 +175,14 @@ type
 							w, h : word;
 							r, g, b : byte;
        	end;
+       	PGsBOXF = ^GsBOXF;
 
        	GsFOGPARAM = packed record
 							dqa : smallint;
 							dqb : longint;
 							rfc, gfc, bfc : byte;
        	end;
+       	PGsFOGPARAM = ^GsFOGPARAM;
 
 
        	GsIMAGE = packed record
@@ -181,6 +194,7 @@ type
 							cw, ch : word;
 							clut : pointer;
 		end;
+		PGsIMAGE = ^GsIMAGE;
 
 
 		_GsPOSITION = packed record
@@ -194,50 +208,50 @@ type
 							maxobj : longint;
 		end;
 
-(*
-typedef struct {
-	PACKET
-	* (*f3[2][3]) ();
-	PACKET
-	* (*nf3[2]) ();
-	PACKET
-	* (*g3[2][3]) ();
-	PACKET
-	* (*ng3[2]) ();
-	PACKET
-	* (*tf3[2][3]) ();
-	PACKET
-	* (*ntf3[2]) ();
-	PACKET
-	* (*tg3[2][3]) ();
-	PACKET
-	* (*ntg3[2]) ();
-	PACKET
-	* (*f4[2][3]) ();
-	PACKET
-	* (*nf4[2]) ();
-	PACKET
-	* (*g4[2][3]) ();
-	PACKET
-	* (*ng4[2]) ();
-	PACKET
-	* (*tf4[2][3]) ();
-	PACKET
-	* (*ntf4[2]) ();
-	PACKET
-	* (*tg4[2][3]) ();
-	PACKET
-	* (*ntg4[2]) ();
-	PACKET
-	* (*f3g[3])();
-	PACKET
-	* (*g3g[3])();
-	PACKET
-	* (*f4g[3])();
-	PACKET
-	* (*g4g[3])();
-}       _GsFCALL;
-*)
+
+//typedef struct {
+//	PACKET
+//	* (*f3[2][3]) ();
+//	PACKET
+//	* (*nf3[2]) ();
+//	PACKET
+//	* (*g3[2][3]) ();
+//	PACKET
+//	* (*ng3[2]) ();
+//	PACKET
+//	* (*tf3[2][3]) ();
+//	PACKET
+//	* (*ntf3[2]) ();
+//	PACKET
+//	* (*tg3[2][3]) ();
+//	PACKET
+//	* (*ntg3[2]) ();
+//	PACKET
+//	* (*f4[2][3]) ();
+//	PACKET
+//	* (*nf4[2]) ();
+//	PACKET
+//	* (*g4[2][3]) ();
+//	PACKET
+//	* (*ng4[2]) ();
+//	PACKET
+//	* (*tf4[2][3]) ();
+//	PACKET
+//	* (*ntf4[2]) ();
+//	PACKET
+//	* (*tg4[2][3]) ();
+//	PACKET
+//	* (*ntg4[2]) ();
+//	PACKET
+//	* (*f3g[3])();
+//	PACKET
+//	* (*g3g[3])();
+//	PACKET
+//	* (*f4g[3])();
+//	PACKET
+//	* (*g4g[3])();
+//       _GsFCALL;
+
 
 
 const
@@ -287,14 +301,7 @@ const
 
 		GsPERS   		= 1 shl 26;
 		GsROTOFF 		= 1 shl 27;
-{
-#define GsIncFrame()  (PSDCNT++, PSDCNT= PSDCNT?PSDCNT:1, \
-                      (PSDIDX= (PSDIDX==0?1:0)))
-
-#define GsUpdateCoord()  (PSDCNT++, PSDCNT= PSDCNT?PSDCNT:1)
 
-#define GsSetAzwh(z,w,h)    GsADIVZ = (z),GsADIVW = (w),GsADIVH = (h);
-}
 
 		GsTMDFlagGRD	= $04;
 
@@ -325,7 +332,7 @@ const
 		GPU_COM_NG4   	= $39;
 		GPU_COM_NTG4  	= $3d;
 
-
+type
 // TMD structure
 		TMD_P_F3 = packed record
 						out, _in, dummy, cd : byte;
@@ -333,6 +340,7 @@ const
 						n0, v0 : word;
 						v1, v2 : word;
 		end;
+		PTMD_P_F3 = ^TMD_P_F3;
 
 		TMD_P_G3 = packed record
 						out, _in, dummy, cd : byte;
@@ -341,6 +349,7 @@ const
 						n1, v1 : word;
 						n2, v2 : word;
 		end;
+		PTMD_P_G3 = ^TMD_P_G3;
 
 
 		TMD_P_F3G = packed record
@@ -351,6 +360,7 @@ const
 						n0, v0 : word;
 						v1, v2 : word;
 		end;
+		PTMD_P_F3G = ^TMD_P_F3G;
 
 
 		TMD_P_G3G = packed record
@@ -362,6 +372,7 @@ const
 						n1, v1 : word;
 						n2, v2 : word;
 		end;
+		PTMD_P_G3G = ^TMD_P_G3G;
 
 		TMD_P_NF3 = packed record
 						out, _in, dummy, cd : byte;
@@ -369,6 +380,7 @@ const
 						v0, v1 : word;
 						v2, p : word;
 		end;
+		PTMD_P_NF3 = ^TMD_P_NF3;
 
 
 		TMD_P_NG3 = packed record
@@ -379,6 +391,7 @@ const
 						v0, v1 : word;
 						v2, p : word;
 		end;
+		PTMD_P_NG3 = ^TMD_P_NG3;
 
 		TMD_P_F4 = packed record
 						out, _in, dummy, cd : byte;
@@ -387,6 +400,7 @@ const
 						v1, v2 : word;
 						v3, p : word;
 		end;
+		PTMD_P_F4 = ^TMD_P_F4;
 
 		TMD_P_G4 = packed record
 						out, _in, dummy, cd : byte;
@@ -396,1071 +410,623 @@ const
 						n2, v2 : word;
 						n3, v3 : word;
 		end;
+		PTMD_P_G4 = ^TMD_P_G4;
+
+		TMD_P_F4G = packed record
+						_out, _in, dummy, cd : byte;
+						r0, g0, b0, code : byte;
+						r1, g1, b1, dummy1 : byte;
+						r2, g2, b2, dummy2 : byte;
+						r3, g3, b3, dummy3 : byte;
+						n0, v0 : word;
+						v1, v2 : word;
+						v3, dummy4 : word;
+		end;
+		PTMD_P_F4G = ^TMD_P_F4G;
+
+		TMD_P_G4G = packed record
+						_out, _in, dummy, cd : byte;
+						r0, g0, b0, code : byte;
+						r1, g1, b1, dummy1 : byte;
+						r2, g2, b2, dummy2 : byte;
+						r3, g3, b3, dummy3 : byte;
+						n0, v0 : word;
+						n1, v1 : word;
+						n2, v2 : word;
+						n3, v3 : word;
+		end;
+		PTMD_P_G4G = ^TMD_P_G4G;
+
+		TMD_P_NF4 = packed record
+						_out, _in, dummy, cd : byte;
+						r0, g0, b0, code : byte;
+						v0, v1 : word;
+						v2, v3 : word;
+		end;
+		PTMD_P_NF4 = ^TMD_P_NF4;
+
+		TMD_P_NG4 = packed record
+						_out, _in, dummy, cd : byte;
+						r0, g0, b0, code : byte;
+						r1, g1, b1, p1 : byte;
+						r2, g2, b2, p2 : byte;
+						r3, g3, b3, p3 : byte;
+						v0, v1 : word;
+						v2, v3 : word;
+		end;
+		PTMD_P_NG4 = ^TMD_P_NG4;
+
+		TMD_P_TF3 = packed record
+						_out, _in, dummy, cd : byte;
+						tu0, tv0 : byte;
+						clut : word;
+						tu1, tv1 : byte;
+						tpage : word;
+						tu2, tv2 : byte;
+						p : word;
+						n0, v0 : word;
+						v1, v2 : word;
+		end;
+		PTMD_P_TF3 = ^TMD_P_TF3;
+
+		TMD_P_TG3 = packed record
+						_out, _in, dummy, cd : byte;
+						tu0, tv0 : byte;
+						clut : word;
+						tu1, tv1 : byte;
+						tpage : word;
+						tu2, tv2 : byte;
+						p : word;
+						u0, v0 : word;
+						n1, v1 : word;
+						n2, v2 : word;
+		end;
+		PTMD_P_TG3 = ^TMD_P_TG3;
+
+
+		TMD_P_TNF3 = packed record
+						_out, _in, dummy, cd : byte;
+						tu0, tv0 : byte;
+						clut : word;
+						tu1, tv1 : byte;
+						tpage : word;
+						tu2, tv2 : byte;
+						p0 : word;
+						r0, g0, b0, p1 : byte;
+						v0, v1 : word;
+						v2, p2 : word;
+		end;
+		PTMD_P_TNF3 = ^TMD_P_TNF3;
+
+
+		TMD_P_TNG3 = packed record
+						_out, _in, dummy, cd : byte;
+						tu0, tv0 : byte;
+						clut : word;
+						tu1, tv1 : byte;
+						tpage : word;
+						tu2, tv2 : byte;
+						p0 : word;
+						r0, g0, b0, p1 : byte;
+						r1, g1, b1, p2 : byte;
+						r2, g2, b2, p3 : byte;
+						v0, v1 : word;
+						v2, p4 : word;
+		end;
+		PTMD_P_TNG3 = ^TMD_P_TNG3;
+
+		TMD_P_TF4 = packed record
+						_out, _in, dummy, cd : byte;
+						tu0, tv0 : byte;
+						clut : word;
+						tu1, tv1 : byte;
+						tpage : word;
+						tu2, tv2 : byte;
+						p0 : word;
+						tu3, tv3 : byte;
+						p1 : word;
+						n0, v0 : word;
+						v1, v2 : word;
+						v3, p2 : word;
+		end;
+		PTMD_P_TF4 = ^TMD_P_TF4;
+
+		TMD_P_TG4 = packed record
+						_out, _in, dummy, cd : byte;
+						tu0, tv0 : byte;
+						clut : word;
+						tu1, tv1 : byte;
+						tpage : word;
+						tu2, tv2 : byte;
+						p0 : word;
+						tu3, tv3 : byte;
+						p1 : word;
+						n0, v0 : word;
+						n1, v1 : word;
+						n2, v2 : word;
+						n3, v3 : word;
+		end;
+		PTMD_P_TG4 = ^TMD_P_TG4;
+
+		TMD_P_TNF4 = packed record
+						_out, _in, dummy, cd : byte;
+						tu0, tv0 : byte;
+						clut : word;
+						tu1, tv1 : byte;
+						tpage : word;
+						tu2, tv2 : byte;
+						p0 : word;
+						tu3, tv3 : byte;
+						p1 : word;
+						r0, g0, b0, p2 : byte;
+						v0, v1 : word;
+						v2, v3 : word;
+		end;
+		PTMD_P_TNF4 = ^TMD_P_TNF4;
+
+		TMD_P_TNG4 = packed record
+						_out, _in, dummy, cd : byte;
+						tu0, tv0 : byte;
+						clut : word;
+						tu1, tv1 : byte;
+						tpage : word;
+						tu2, tv2 : byte;
+						p0 : word;
+						tu3, tv3 : byte;
+						p1 : word;
+						r0, g0, b0, p2 : byte;
+						r1, g1, b1, p3 : byte;
+						r2, g2, b2, p4 : byte;
+						r3, g3, b3, p5 : byte;
+						v0, v1 : word;
+						v2, v3 : word;
+		end;
+		PTMD_P_TNG4 = ^TMD_P_TNG4;
+
+		TMD_STRUCT = packed record
+						vertop : pdword;        // vertex top address of TMD format
+						vern : dword;           // the number of vertex of TMD format
+						nortop : pdword;        // normal top address of TMD format
+						norn : dword;           // the number of normal of TMD format
+						primtop : pdword;       // primitive top address of TMD format
+						primn : dword;          // the number of primitives of TMD format
+						scale : dword;          // the scale factor of TMD format
+		end;
+
+
+
+		VERT = packed record
+						vx, vy, vz : smallint;
+						tu, tv : byte;
+		end;
+		PVERT = ^VERT;
+
+		VERTC = packed record
+						vx, vy, vz : smallint;
+						tu, tv : byte;
+						col : CVECTOR;
+		end;
+
+
+		GsADIV_FT4 = packed record
+						limit : dword;						// divide limit
+						hwd, vwd : longint;					// dummy
+						shift : longint;					// OT shift
+						org : pdword;						// OT org
+						pk : pdword;						// packet base
+						otz : longint;						// gte otz
+						adivz : longint;					// active divide codition z
+						adivw, adivh : smallint;			// active divide condition w,h
+						flg0 : longint;						// gte flag
+						flg : longint;						// gte flag
+						minx, miny, maxx, maxy : smallint;	// polygon min-max
+						hwd0, vwd0 : smallint;				// resolution of screen
+						tag : pdword;						// work temprly for addPrim
+						si : POLY_FT4;						// work packet
+		end;
+
+
+		GsADIV_P_FT4 = packed record
+						vt : array [0..3] of VERT;
+		end;
+
+
+		GsADIV_GT4 = packed record
+						limit : dword;						// divide limit
+						hwd, vwd : longint;					// dummy
+						shift : longint;					// OT shift
+						org : pdword;						// OT org
+						pk : pdword;						// packet base
+						otz : longint;						// gte otz
+						adivz : longint;					// active divide codition z
+						adivw, adivh : smallint;			// active divide condition w,h
+						flg0 : longint;						// gte flag
+						flg : longint;						// gte flag
+						minx, miny, maxx, maxy : smallint;	// polygon min-max
+						hwd0, vwd0 : smallint;				// resolution of screen
+						tag : pdword;						// work temprly for addPrim
+						si : POLY_GT4;						// work packet
+		end;
+
+		GsADIV_P_GT4 = packed record
+						vt : array [0..3] of VERTC;
+		end;
+
+
+		GsADIV_G4 = packed record
+						limit : dword;						// divide limit
+						hwd, vwd : longint;					// dummy
+						shift : longint;					// OT shift
+						org : pdword;						// OT org
+						pk : pdword;						// packet base
+						otz : longint;						// gte otz
+						adivz : longint;					// active divide codition z
+						adivw, adivh : smallint;			// active divide condition w,h
+						flg0 : longint;						// gte flag
+						flg : longint;						// gte flag
+						minx, miny, maxx, maxy : smallint;	// polygon min-max
+						hwd0, vwd0: smallint;				// resolution of screen
+						tag : pdword;						// work temprly for addPrim
+						si : POLY_G4;						// work packet
+		end;
+
+		GsADIV_P_G4 = packed record
+						vt : array [0..3] of VERTC;
+		end;
+
+		GsADIV_F4 = packed record
+						limit : dword;				// divide limit
+						hwd, vwd : longint;					// dummy
+						shift : longint;					// OT shift
+						org : pdword;						// OT org
+						pk : pdword;						// packet base
+						otz : longint;						// gte otz
+						adivz : longint;					// active divide codition z
+						adivw, adivh : smallint;			// active divide condition w,h
+						flg0 : longint;						// gte flag
+						flg : longint;						// gte flag
+						minx, miny, maxx, maxy : smallint;	// polygon min-max
+						hwd0, vwd0 : smallint;				// resolution of screen
+						tag : pdword;						// work temprly for addPrim
+						si : POLY_F4;						// work packet
+	end;
+
+	GsADIV_P_F4 = packed record
+						vt : array [0..3] of VERT;
+	end;
+
+
+	GsADIV_FT3 = packed record
+						limit : dword;						// divide limit
+						hwd, vwd : longint;					// dummy
+						shift : longint;					// OT shift
+						org : pdword;						// OT org
+						pk : pdword;						// packet base
+						otz : longint;						// gte otz
+						adivz : longint;					// active divide codition z
+						adivw, adivh : smallint;			// active divide condition w,h
+						flg : longint;						// gte flag
+						minx, miny, maxx, maxy : smallint;	// polygon min-max
+						hwd0, vwd0 : smallint;				// resolution of screen
+						tag : pdword;						// work temprly for addPrim
+						si : POLY_FT3;						// work packet
+	end;
+
+	GsADIV_P_FT3 = packed record
+						vt : array [0..2] of VERT;
+	end;
+
+
+	GsADIV_GT3 = packed record
+						limit : dword;						// divide limit
+						hwd, vwd : longint;					// dummy
+						shift : longint;					// OT shift
+						org : pdword;						// OT org
+						pk : pdword;						// packet base
+						otz : longint;						// gte otz
+						adivz : longint;					// active divide codition z
+						adivw, adivh : smallint;			// active divide condition w,h
+						flg : longint;						// gte flag
+						minx, miny, maxx, maxy : smallint;	// polygon min-max
+						hwd0, vwd0 : smallint;				// resolution of screen
+						tag : pdword;						// work temprly for addPrim
+						si : POLY_GT3;						// work packet
+	end;
+
+	GsADIV_P_GT3 = packed record
+						vt : array [0..2] of VERTC;
+	end;
+
+	GsADIV_G3 = packed record
+						limit : dword;						// divide limit
+						hwd, vwd : longint;					// dummy
+						shift : longint;					// OT shift
+						org : pdword;						// OT org
+						pk : pdword;						// packet base
+						otz : longint;						// gte otz
+						adivz : longint;					// active divide codition z
+						adivw, adivh : smallint;			// active divide condition w,h
+						flg : longint;						// gte flag
+						minx, miny, maxx, maxy : smallint;	// polygon min-max
+						hwd0, vwd0 : smallint;				// resolution of screen
+						tag : pdword;						// work temprly for addPrim
+						si : POLY_G3;						// work packet
+	end;
+
+	GsADIV_P_G3 = packed record
+						vt : array [0..2] of VERTC;
+	end;
+
+	GsADIV_F3 = packed record
+						limit : dword;						// divide limit
+						hwd, vwd : longint;					// dummy
+						shift : longint;					// OT shift
+						org : pdword;						// OT org
+						pk : pdword;						// packet base
+						otz : longint;						// gte otz
+						adivz : longint;					// active divide codition z
+						adivw, adivh : smallint;			// active divide condition w,h
+						flg : longint;						// gte flag
+						minx, miny, maxx, maxy : smallint;	// polygon min-max
+						hwd0, vwd0 : smallint;				// resolution of screen
+						tag : pdword;						// work temprly for addPrim
+						si : POLY_F3;						// work packet
+	end;
+
+	GsADIV_P_F3 = packed record
+						vt : array [0..2] of VERT;
+	end;
+
+
+	procedure GsInitGraph(x, y: word; intmode: word; dith: word; varmmode: word); external;
+	procedure GsInit3D; external;
+	procedure GsMapModelingData(p: dword); external;
+
+	procedure GsSetProjection(h: longint); external;
+	function GsSetFlatLight(id: longint; lt: PGsF_LIGHT): longint; external;
+	procedure GsSetLightMode(mode: longint); external;
+	procedure GsSetFogParam(fogparm: PGsFOGPARAM); external;
+	procedure GsSetAmbient(r, g, b: longint); external;
+	procedure GsDrawOt(ot: PGsOT); external;
+	procedure GsSetWorkBase(outpacketp: PPACKET); external;
+
+	procedure GsSortObject3(objp: PGsDOBJ3; ot: PGsOT; shift: longint); external;
+	procedure GsSortObject4(objp: PGsDOBJ2; ot: PGsOT; shift: longint; scratch: pdword); external;
+	procedure GsSortObject5(objp: PGsDOBJ5; ot: PGsOT; shift: longint; scratch: pdword); external;
+	procedure GsSortObject5J(objp: PGsDOBJ5; ot: PGsOT; shift: longint; scratch: pdword); external;
+
+	procedure GsSortSprite(sp: PGsSPRITE; ot: PGsOT; pri: word); external;
+	procedure GsSortSpriteB(sp: PGsSPRITE; ot: PGsOT; pri: word; flip: word); external;
+	procedure GsSortFastSprite(sp: PGsSPRITE; ot: PGsOT; pri: word); external;
+	procedure GsSortFastSpriteB(sp: PGsSPRITE; ot: PGsOT; pri: word; flip: word); external;
+	procedure GsSortFlipSprite(sp: PGsSPRITE; ot: PGsOT; pri: word); external;
+	procedure GsSortBg(bg: PGsBG; ot: PGsOT; pri: word); external;
+	procedure GsSortFastBg(bg: PGsBG; ot: PGsOT; pri: word); external;
+	procedure GsInitFixBg16(bg: PGsBG; work: pdword); external;
+	procedure GsSortFixBg16(bg: PGsBG; work: pdword; otp: PGsOT; pri: word); external;
+	procedure GsInitFixBg32(bg: PGsBG; work: pdword); external;
+	procedure GsSortFixBg32(bg: PGsBG; work: pdword; otp: PGsOT; pri: word); external;
+	procedure GsSortLine(lp: PGsLINE; ot: PGsOT; pri: word); external;
+	procedure GsSortGLine(lp: PGsLINE; ot: PGsOT; pri: word); external;
+	procedure GsSortBoxFill(bp: PGsBOXF; ot: PGsOT; pri: word); external;
+	procedure GsSortPoly(pp: pointer; ot: PGsOT; pri: word); external;
+
+	procedure GsClearOt(offs: dword; point: word; otp: PGsOT); external;
+	function GsSortOt(ot_src: PGsOT; ot_dest: PGsOT): PGsOT; external;
+	function GsCutOt(ot_src: PGsOT; ot_dest: PGsOT): PGsOT; external;
+	procedure GsDefDispBuff(x0, y0, x1, y1: word); external;
+	procedure GsSortClear(r, g, b: byte; otp: PGsOT); external;
+	procedure GsGetTimInfo(im: pdword; tim: PGsIMAGE); external;
+	procedure GsSwapDispBuff; external;
+	function GsGetActiveBuff: longint; external;
+	procedure GsSetDrawBuffClip; external;
+	procedure GsSetDrawBuffOffset; external;
+	procedure GsSetClip(clip: PRECT); external;
+	function GsSetClip2(clip: PRECT): PDRAWENV; external;
+	procedure GsSetOffset(x, y: longint); external;
+	procedure GsSetOrign(x, y: longint); external;
+
+	procedure GsInitCoordinate2(super: PGsCOORDINATE2; base: PGsCOORDINATE2); external;
+	procedure GsMulCoord0(m1, m2, m3: PMATRIX); external;
+	procedure GsMulCoord2(m1, m2: PMATRIX); external;
+	procedure GsMulCoord3(m1, m2: PMATRIX); external;
+	procedure GsGetLw(m: PGsCOORDINATE2; out: PMATRIX); external;
+	procedure GsGetLs(m: PGsCOORDINATE2; out: PMATRIX); external;
+	procedure GsGetLws(m: PGsCOORDINATE2; outw, outs: PMATRIX); external;
+
+	function GsLinkObject3(pmd_base: dword; objp: PGsDOBJ3): dword; external;
+	procedure GsLinkObject4(tmd_base: dword; objp: PGsDOBJ2; n: longint); external;
+	procedure GsLinkObject5(tmd_base: dword; objp: PGsDOBJ5; n: longint); external;
+
+	procedure GsSetLightMatrix(mp: PMATRIX); external;
+	procedure GsSetLightMatrix2(mp: PMATRIX); external;
+	function GsSetRefView2(pv: PGsRVIEW2): longint; external;
+	function GsSetRefView2L(pv: PGsRVIEW2): longint; external;
+	function GsSetView2(pv: PGsRVIEW2): longint; external;
+	procedure GsSetLsMatrix(mp: PMATRIX); external;
+	procedure GsSetClip2D(rectp: PRECT); external;
+	procedure GsInitVcount; external;
+	procedure GsGetVcount; external;
+	procedure GsClearVcount; external;
+	procedure GsDefDispBuff2(x0, y0, x1, y1: word); external;
+	procedure GsDrawOtIO(ot: PGsOT); external;
+	function GsGetWorkBase: PPACKET; external;
+	procedure GsInitGraph2(x, y: word; intmode: word; dith: word; vrammode: word); external;
+	procedure GsSortObject4J(objp: PGsDOBJ2; otp: PGsOT; shift: longint; scratch: pdword); external;
+	procedure GsClearDispArea(r, g, b: byte); external;
+
+	function GsPresetObject(objp: PGsDOBJ5; base_addr: pdword): pdword; external;
+	procedure GsScaleScreen(scale: PSVECTOR); external;
+
+	function GsA4divF3L(op: PTMD_P_F3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divF3LFG(op: PTMD_P_F3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divF3NL(op: PTMD_P_F3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divNF3(op: PTMD_P_NF3; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divF4L(op: PTMD_P_F4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divF4LFG(op: PTMD_P_F4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divF4NL(op: PTMD_P_F4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divNF4(op: PTMD_P_NF4; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divG3L(op: PTMD_P_G3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divG3LFG(op: PTMD_P_G3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divG3NL(op: PTMD_P_G3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divNG3(op: PTMD_P_NG3; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divG4L(op: PTMD_P_G4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divG4LFG(op: PTMD_P_G4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divG4NL(op: PTMD_P_G4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divNG4(op: PTMD_P_NG4; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTF3L(op: PTMD_P_TF3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTF3LFG(op: PTMD_P_TF3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTF3NL(op: PTMD_P_TF3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTNF3(op: PTMD_P_TNF3; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTF4L(op: PTMD_P_TF4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTF4LFG(op: PTMD_P_TF4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTF4NL(op: PTMD_P_TF4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTNF4(op: PTMD_P_TNF4; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTF4LM(op: PTMD_P_TF4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTF4LFGM(op: PTMD_P_TF4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTF4NLM(op: PTMD_P_TF4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTNF4M(op: PTMD_P_TNF4; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTG3L(op: PTMD_P_TG3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTG3LFG(op: PTMD_P_TG3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTG3NL(op: PTMD_P_TG3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTNG3(op: PTMD_P_TNG3; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTG4L(op: PTMD_P_TG4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTG4LFG(op: PTMD_P_TG4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTG4NL(op: PTMD_P_TG4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTNG4(op: PTMD_P_TNG4; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTG4LM(op: PTMD_P_TG4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTG4LFGM(op: PTMD_P_TG4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTG4NLM(op: PTMD_P_TG4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsA4divTNG4M(op: PTMD_P_TNG4; vp: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF3GL(op: PTMD_P_F3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF3GLFG(op: PTMD_P_F3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF3GNL(op: PTMD_P_F3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG3GL(op: PTMD_P_G3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG3GLFG(op: PTMD_P_G3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG3GNL(op: PTMD_P_G3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsPrstF3GL(op: PTMD_P_F3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsPrstF3GLFG(op: PTMD_P_F3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsPrstF3GNL(op: PTMD_P_F3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsPrstG3GL(op: PTMD_P_G3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsPrstG3GLFG(op: PTMD_P_G3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsPrstG3GNL(op: PTMD_P_G3G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG3M(op: PTMD_P_G3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG3MFG(op: PTMD_P_G3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastTG3M(op: PTMD_P_TG3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastTG3MFG(op: PTMD_P_TG3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF4GL(op: PTMD_P_F4G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF4GLFG(op: PTMD_P_F4G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF4GNL(op: PTMD_P_F4G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG4GL(op: PTMD_P_G4G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG4GLFG(op: PTMD_P_G4G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG4GNL(op: PTMD_P_G4G; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG4M(op: PTMD_P_G4; vp, np: PVERT; pk: PPACKET;  n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastG4MFG(op: PTMD_P_G4; vp, np: PVERT; pk: PPACKET;  n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastTG4M(op: PTMD_P_TG4; vp, np: PVERT; pk: PPACKET;  n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastTG4MFG(op: PTMD_P_TG4; vp, np: PVERT; pk: PPACKET;  n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF3M(op: PTMD_P_F3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF3MFG(op: PTMD_P_F3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastTF3M(op: PTMD_P_TF3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastTF3MFG(op: PTMD_P_TF3; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF4M(op: PTMD_P_F4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastF4MFG(op: PTMD_P_F4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastTF4M(op: PTMD_P_TF4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+	function GsTMDfastTF4MFG(op: PTMD_P_TF4; vp, np: PVERT; pk: PPACKET; n, shift: longint; ot: PGsOT; scratch: pdword): PPACKET; external;
+
+
+
+var
+	CLIP2 : RECT; external;									// clipping area
+	PSDBASEX : array [0..1] of smallint; external;			// double buffer base
+	PSDBASEY : array [0..1] of smallint; external;	
+	PSDIDX : smallint; external;							// double buffer index
+	PSDCNT : dword; external;								// frame counter for using matrix cache
+	POSITION : _GsPOSITION; external;						// 2d offset
+	GsDRAWENV : DRAWENV; external;							// DRAWENV of Gs
+	GsDISPENV : DISPENV; external;							// DISPENV of Gs
+	GsWSMATRIX : MATRIX; external; 							// Current World-Screen Matrix of Gs
+	GsWSMATRIX_ORG : MATRIX; external; 						// Original World-Screen Matrix of Gs
+	HWD0 : longint; external;
+	VWD0 : longint; external;							// rezolution of Holyzontal and Vertical
+	GsLIGHTWSMATRIX : MATRIX; external;						// World-Screen Light Matrix of Gs
+	GsIDMATRIX : MATRIX; external;							// Unit Matrix
+	GsIDMATRIX2 : MATRIX; external;							// Unit Matrix including Aspect retio
+	GsOUT_PACKET_P : PPACKET; external;						// Work Base pointer
+	GsADIVZ : longint; external;							// Active sub divide condition (z)
+	GsADIVW : smallint; external;
+	GsADIVH : smallint; external; 					// Active sub divide condition (w,h)
+	GsLIGHT_MODE : longint; external;						// lighting mode global
+	GsMATE_C : dword; external; 
+	GsLMODE : dword; external;
+	GsLIGNR : dword; external;
+	GsLIOFF : dword; external;
+	GsZOVER : dword; external;
+	GsBACKC : dword; external;
+	GsNDIV : dword; external;
+	GsTRATE : dword; external;
+	GsTON : dword; external;
+	GsDISPON : dword; external;
+
+
+procedure GsIncFrame;
+procedure GsUpdateCoord;
+procedure GsSetAzwh(z: longint; w, h: smallint);
+
+procedure minmax4(var x1,x2,x3,x4,x5,x6: longint);
+procedure minmax3(var x1,x2,x3,x4,x5: longint);
+
+
+implementation
+
+
+procedure GsIncFrame;
+begin
+
+	inc(PSDCNT);
+                      
+ 	if PSDCNT > 0 then PSDCNT:= PSDCNT else PSDCNT:= 1;
+ 	if PSDIDX = 0 then PSDIDX:=1 else PSDIDX:= 0;
+
+end;
+
+
+procedure GsUpdateCoord;
+begin
+	
+	inc(PSDCNT);
+	if PSDCNT > 0 then PSDCNT:= PSDCNT else PSDCNT:= 1;
+
+end;
+
+
+procedure GsSetAzwh(z: longint; w, h: smallint);
+begin
+
+  GsADIVZ:= z;
+  GsADIVW:= w;
+  GsADIVH:= h;
+
+end;
+
+
+procedure minmax4(var x1,x2,x3,x4,x5,x6: longint);
+begin
+
+	if x1 > x2 then begin x6:= x1; x5:= x2; end else begin x5:= x1; x6:= x2; end;
+	if x3 > x6 then begin x6:=x3; end else begin if x3 < x5 then x5:=x3; end;
+	if x4 > x6 then begin x6:=x4; end else begin if x4 < x5 then x5:=x4; end;
+
+end;
+
+
+procedure minmax3(var x1,x2,x3,x4,x5: longint);
+begin
+
+	if x1 > x2 then begin x5:= x1; x4:= x2; end else begin x4:= x1; x5:=x2; end;
+	if x3 > x5 then begin x5:=x3; end else begin if x3 < x4 then x4:=x3; end;
+
+end;
+
 
-typedef struct {
-	u_char	out, in, dummy, cd;
-	u_char	r0, g0, b0, code;
-	u_char	r1, g1, b1, dummy1;
-	u_char	r2, g2, b2, dummy2;
-	u_char	r3, g3, b3, dummy3;
-	u_short n0, v0;
-	u_short v1, v2;
-	u_short v3, dummy4;
-}       TMD_P_F4G;
-
-typedef struct {
-	u_char	out, in, dummy, cd;
-	u_char	r0, g0, b0, code;
-	u_char	r1, g1, b1, dummy1;
-	u_char	r2, g2, b2, dummy2;
-	u_char	r3, g3, b3, dummy3;
-	u_short n0, v0;
-	u_short n1, v1;
-	u_short n2, v2;
-	u_short n3, v3;
-}       TMD_P_G4G;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  r0, g0, b0, code;
-	u_short v0, v1;
-	u_short v2, v3;
-}       TMD_P_NF4;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  r0, g0, b0, code;
-	u_char  r1, g1, b1, p1;
-	u_char  r2, g2, b2, p2;
-	u_char  r3, g3, b3, p3;
-	u_short v0, v1;
-	u_short v2, v3;
-}       TMD_P_NG4;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  tu0, tv0;
-	u_short clut;
-	u_char  tu1, tv1;
-	u_short tpage;
-	u_char  tu2, tv2;
-	u_short p;
-	u_short n0, v0;
-	u_short v1, v2;
-}       TMD_P_TF3;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  tu0, tv0;
-	u_short clut;
-	u_char  tu1, tv1;
-	u_short tpage;
-	u_char  tu2, tv2;
-	u_short p;
-	u_short n0, v0;
-	u_short n1, v1;
-	u_short n2, v2;
-}       TMD_P_TG3;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  tu0, tv0;
-	u_short clut;
-	u_char  tu1, tv1;
-	u_short tpage;
-	u_char  tu2, tv2;
-	u_short p0;
-	u_char  r0, g0, b0, p1;
-	u_short v0, v1;
-	u_short v2, p2;
-}       TMD_P_TNF3;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  tu0, tv0;
-	u_short clut;
-	u_char  tu1, tv1;
-	u_short tpage;
-	u_char  tu2, tv2;
-	u_short p0;
-	u_char  r0, g0, b0, p1;
-	u_char  r1, g1, b1, p2;
-	u_char  r2, g2, b2, p3;
-	u_short v0, v1;
-	u_short v2, p4;
-}       TMD_P_TNG3;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  tu0, tv0;
-	u_short clut;
-	u_char  tu1, tv1;
-	u_short tpage;
-	u_char  tu2, tv2;
-	u_short p0;
-	u_char  tu3, tv3;
-	u_short p1;
-	u_short n0, v0;
-	u_short v1, v2;
-	u_short v3, p2;
-}       TMD_P_TF4;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  tu0, tv0;
-	u_short clut;
-	u_char  tu1, tv1;
-	u_short tpage;
-	u_char  tu2, tv2;
-	u_short p0;
-	u_char  tu3, tv3;
-	u_short p1;
-	u_short n0, v0;
-	u_short n1, v1;
-	u_short n2, v2;
-	u_short n3, v3;
-}       TMD_P_TG4;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  tu0, tv0;
-	u_short clut;
-	u_char  tu1, tv1;
-	u_short tpage;
-	u_char  tu2, tv2;
-	u_short p0;
-	u_char  tu3, tv3;
-	u_short p1;
-	u_char  r0, g0, b0, p2;
-	u_short v0, v1;
-	u_short v2, v3;
-}       TMD_P_TNF4;
-
-typedef struct {
-	u_char  out, in, dummy, cd;
-	u_char  tu0, tv0;
-	u_short clut;
-	u_char  tu1, tv1;
-	u_short tpage;
-	u_char  tu2, tv2;
-	u_short p0;
-	u_char  tu3, tv3;
-	u_short p1;
-	u_char  r0, g0, b0, p2;
-	u_char  r1, g1, b1, p3;
-	u_char  r2, g2, b2, p4;
-	u_char  r3, g3, b3, p5;
-	u_short v0, v1;
-	u_short v2, v3;
-}       TMD_P_TNG4;
-
-struct TMD_STRUCT {
-	u_long *vertop;         /* vertex top address of TMD format */
-	u_long  vern;           /* the number of vertex of TMD format */
-	u_long *nortop;         /* normal top address of TMD format */
-	u_long  norn;           /* the number of normal of TMD format */
-	u_long *primtop;        /* primitive top address of TMD format */
-	u_long  primn;          /* the number of primitives of TMD format */
-	u_long  scale;          /* the scale factor of TMD format */
-};
-
-/*
- * active sub divide structure 
- *
- */
-
-#define minmax4(x1,x2,x3,x4,x5,x6) x1>x2?(x6=x1,x5=x2):(x5=x1,x6=x2),\
-                                   x3>x6?x6=x3:x3<x5?x5=x3:0,\
-                                   x4>x6?x6=x4:x4<x5?x5=x4:0
-
-#define minmax3(x1,x2,x3,x4,x5)    x1>x2?(x5=x1,x4=x2):(x4=x1,x5=x2),\
-                                   x3>x5?x5=x3:x3<x4?x4=x3:0
-
-
-typedef struct {
-	short   vx, vy, vz;
-	u_char  tu, tv;
-}       VERT;
-
-typedef struct {
-	short   vx, vy, vz;
-	u_char  tu, tv;
-	CVECTOR col;
-}       VERTC;
-
-
-typedef struct {
-	u_long  limit;		/* divide limit */
-	long    hwd, vwd;	/* dummy */
-	int     shift;		/* OT shift */
-	u_long *org;		/* OT org */
-	u_long *pk;		/* packet base */
-	long    otz;		/* gte otz */
-	long    adivz;		/* active divide codition z */
-	short   adivw, adivh;	/* active divide condition w,h */
-	long    flg0;		/* gte flag */
-	long    flg;		/* gte flag */
-	short   minx, miny, maxx, maxy;	/* polygon min-max */
-	short   hwd0, vwd0;	/* resolution of screen */
-	u_long *tag;		/* work temprly for addPrim */
-	POLY_FT4 si;		/* work packet */
-}       GsADIV_FT4;
-
-typedef struct {
-	VERT    vt[4];
-}       GsADIV_P_FT4;
-
-
-
-typedef struct {
-	u_long  limit;		/* divide limit */
-	long    hwd, vwd;	/* dummy */
-	int     shift;		/* OT shift */
-	u_long *org;		/* OT org */
-	u_long *pk;		/* packet base */
-	long    otz;		/* gte otz */
-	long    adivz;		/* active divide codition z */
-	short   adivw, adivh;	/* active divide condition w,h */
-	long    flg0;		/* gte flag */
-	long    flg;		/* gte flag */
-	short   minx, miny, maxx, maxy;	/* polygon min-max */
-	short   hwd0, vwd0;	/* resolution of screen */
-	u_long *tag;		/* work temprly for addPrim */
-	POLY_GT4 si;		/* work packet */
-}       GsADIV_GT4;
-
-typedef struct {
-	VERTC   vt[4];
-}       GsADIV_P_GT4;
-
-
-typedef struct {
-	u_long  limit;		/* divide limit */
-	long    hwd, vwd;	/* dummy */
-	int     shift;		/* OT shift */
-	u_long *org;		/* OT org */
-	u_long *pk;		/* packet base */
-	long    otz;		/* gte otz */
-	long    adivz;		/* active divide codition z */
-	short   adivw, adivh;	/* active divide condition w,h */
-	long    flg0;		/* gte flag */
-	long    flg;		/* gte flag */
-	short   minx, miny, maxx, maxy;	/* polygon min-max */
-	short   hwd0, vwd0;	/* resolution of screen */
-	u_long *tag;		/* work temprly for addPrim */
-	POLY_G4 si;		/* work packet */
-}       GsADIV_G4;
-
-typedef struct {
-	VERTC   vt[4];
-}       GsADIV_P_G4;
-
-typedef struct {
-	u_long  limit;		/* divide limit */
-	long    hwd, vwd;	/* dummy */
-	int     shift;		/* OT shift */
-	u_long *org;		/* OT org */
-	u_long *pk;		/* packet base */
-	long    otz;		/* gte otz */
-	long    adivz;		/* active divide codition z */
-	short   adivw, adivh;	/* active divide condition w,h */
-	long    flg0;		/* gte flag */
-	long    flg;		/* gte flag */
-	short   minx, miny, maxx, maxy;	/* polygon min-max */
-	short   hwd0, vwd0;	/* resolution of screen */
-	u_long *tag;		/* work temprly for addPrim */
-	POLY_F4 si;		/* work packet */
-}       GsADIV_F4;
-
-typedef struct {
-	VERT    vt[4];
-}       GsADIV_P_F4;
-
-
-typedef struct {
-	u_long  limit;		/* divide limit */
-	long    hwd, vwd;	/* dummy */
-	int     shift;		/* OT shift */
-	u_long *org;		/* OT org */
-	u_long *pk;		/* packet base */
-	long    otz;		/* gte otz */
-	long    adivz;		/* active divide codition z */
-	short   adivw, adivh;	/* active divide condition w,h */
-	long    flg;		/* gte flag */
-	short   minx, miny, maxx, maxy;	/* polygon min-max */
-	short   hwd0, vwd0;	/* resolution of screen */
-	u_long *tag;		/* work temprly for addPrim */
-	POLY_FT3 si;		/* work packet */
-}       GsADIV_FT3;
-
-typedef struct {
-	VERT    vt[3];
-}       GsADIV_P_FT3;
-
-typedef struct {
-	u_long  limit;		/* divide limit */
-	long    hwd, vwd;	/* dummy */
-	int     shift;		/* OT shift */
-	u_long *org;		/* OT org */
-	u_long *pk;		/* packet base */
-	long    otz;		/* gte otz */
-	long    adivz;		/* active divide codition z */
-	short   adivw, adivh;	/* active divide condition w,h */
-	long    flg;		/* gte flag */
-	short   minx, miny, maxx, maxy;	/* polygon min-max */
-	short   hwd0, vwd0;	/* resolution of screen */
-	u_long *tag;		/* work temprly for addPrim */
-	POLY_GT3 si;		/* work packet */
-}       GsADIV_GT3;
-
-typedef struct {
-	VERTC   vt[3];
-}       GsADIV_P_GT3;
-
-typedef struct {
-	u_long  limit;		/* divide limit */
-	long    hwd, vwd;	/* dummy */
-	int     shift;		/* OT shift */
-	u_long *org;		/* OT org */
-	u_long *pk;		/* packet base */
-	long    otz;		/* gte otz */
-	long    adivz;		/* active divide codition z */
-	short   adivw, adivh;	/* active divide condition w,h */
-	long    flg;		/* gte flag */
-	short   minx, miny, maxx, maxy;	/* polygon min-max */
-	short   hwd0, vwd0;	/* resolution of screen */
-	u_long *tag;		/* work temprly for addPrim */
-	POLY_G3 si;		/* work packet */
-}       GsADIV_G3;
-
-typedef struct {
-	VERTC   vt[3];
-}       GsADIV_P_G3;
-
-typedef struct {
-	u_long  limit;		/* divide limit */
-	long    hwd, vwd;	/* dummy */
-	int     shift;		/* OT shift */
-	u_long *org;		/* OT org */
-	u_long *pk;		/* packet base */
-	long    otz;		/* gte otz */
-	long    adivz;		/* active divide codition z */
-	short   adivw, adivh;	/* active divide condition w,h */
-	long    flg;		/* gte flag */
-	short   minx, miny, maxx, maxy;	/* polygon min-max */
-	short   hwd0, vwd0;	/* resolution of screen */
-	u_long *tag;		/* work temprly for addPrim */
-	POLY_F3 si;		/* work packet */
-}       GsADIV_F3;
-
-typedef struct {
-	VERT    vt[3];
-}       GsADIV_P_F3;
-
-/*
- * PROTOTYPE DIFINITIONS 
- */
-#if defined(_LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
-extern  "C" {
-#endif
-
-	void    GsInitGraph(unsigned short x, unsigned short y, unsigned short intmode,
-		              unsigned short dith, unsigned short varmmode);
-	void    GsInit3D(void);
-	void    GsMapModelingData(unsigned long *p);
-
-	void    GsSetProjection(long h);
-	int     GsSetFlatLight(int id, GsF_LIGHT * lt);
-	void    GsSetLightMode(int mode);
-	void    GsSetFogParam(GsFOGPARAM * fogparm);
-	void    GsSetAmbient(long r, long g, long b);
-	void    GsDrawOt(GsOT * ot);
-	void    GsSetWorkBase(PACKET * outpacketp);
-
-	void    GsSortObject3(GsDOBJ3 * objp, GsOT * ot, int shift);
-	void    GsSortObject4(GsDOBJ2 * objp, GsOT * ot, int shift, u_long * scratch);
-	void    GsSortObject5(GsDOBJ5 * objp, GsOT * ot, int shift, u_long * scratch);
-	void    GsSortObject5J(GsDOBJ5 * objp, GsOT * ot, int shift, u_long * scratch);
-
-	void    GsSortSprite(GsSPRITE * sp, GsOT * ot, unsigned short pri);
-	void    GsSortSpriteB(GsSPRITE * sp, GsOT * ot, unsigned short pri,
-				unsigned short flip);
-	void    GsSortFastSprite(GsSPRITE * sp, GsOT * ot, unsigned short pri);
-	void    GsSortFastSpriteB(GsSPRITE * sp, GsOT * ot, unsigned short pri,
-				unsigned short flip);
-	void    GsSortFlipSprite(GsSPRITE * sp, GsOT * ot, unsigned short pri);
-	void    GsSortBg(GsBG * bg, GsOT * ot, unsigned short pri);
-	void    GsSortFastBg(GsBG * bg, GsOT * ot, unsigned short pri);
-	void    GsInitFixBg16(GsBG * bg, u_long * work);
-	void    GsSortFixBg16(GsBG * bg, u_long * work, GsOT * otp, unsigned short pri);
-	void    GsInitFixBg32(GsBG * bg, u_long * work);
-	void    GsSortFixBg32(GsBG * bg, u_long * work, GsOT * otp, unsigned short pri);
-	void    GsSortLine(GsLINE * lp, GsOT * ot, unsigned short pri);
-	void    GsSortGLine(GsGLINE * lp, GsOT * ot, unsigned short pri);
-	void    GsSortBoxFill(GsBOXF * bp, GsOT * ot, unsigned short pri);
-	void    GsSortPoly(void *pp, GsOT * ot, unsigned short pri);
-
-	void    GsClearOt(unsigned short offset, unsigned short point, GsOT * otp);
-	GsOT   *GsSortOt(GsOT * ot_src, GsOT * ot_dest);
-	GsOT   *GsCutOt(GsOT * ot_src, GsOT * ot_dest);
-	void    GsDefDispBuff(unsigned short x0, unsigned short y0, unsigned short x1, unsigned short y1);
-	void    GsSortClear(unsigned char, unsigned char, unsigned char, GsOT *);
-	void    GsGetTimInfo(unsigned long *im, GsIMAGE * tim);
-	void    GsSwapDispBuff(void);
-	int     GsGetActiveBuff(void);
-	void    GsSetDrawBuffClip(void);
-	void    GsSetDrawBuffOffset(void);
-	void    GsSetClip(RECT * clip);
-	DRAWENV *GsSetClip2(RECT * clip);
-	void    GsSetOffset(long x, long y);
-	void    GsSetOrign(long x, long y);
-
-	void    GsInitCoordinate2(GsCOORDINATE2 * super, GsCOORDINATE2 * base);
-	void    GsMulCoord0(MATRIX * m1, MATRIX * m2, MATRIX * m3);
-	void    GsMulCoord2(MATRIX * m1, MATRIX * m2);
-	void    GsMulCoord3(MATRIX * m1, MATRIX * m2);
-	void    GsGetLw(GsCOORDINATE2 * m, MATRIX * out);
-	void    GsGetLs(GsCOORDINATE2 * m, MATRIX * out);
-	void    GsGetLws(GsCOORDINATE2 * m, MATRIX * outw, MATRIX * outs);
-
-	u_long  GsLinkObject3(unsigned long pmd_base, GsDOBJ3 * objp);
-	void    GsLinkObject4(unsigned long tmd_base, GsDOBJ2 * objp, int n);
-	void    GsLinkObject5(unsigned long tmd_base, GsDOBJ5 * objp, int n);
-
-	void    GsSetLightMatrix(MATRIX * mp);
-	void    GsSetLightMatrix2(MATRIX * mp);
-	int     GsSetRefView2(GsRVIEW2 * pv);
-	int     GsSetRefView2L(GsRVIEW2 * pv);
-	int     GsSetView2(GsVIEW2 * pv);
-	void    GsSetLsMatrix(MATRIX * mp);
-	void    GsSetClip2D(RECT * rectp);
-	void    GsInitVcount();
-	long    GsGetVcount();
-	void    GsClearVcount();
-	void	GsDefDispBuff2(u_short x0, u_short y0, u_short x1, u_short y1);
-	void	GsDrawOtIO(GsOT *ot);
-	PACKET *GsGetWorkBase();
-	void	GsInitGraph2( u_short x, u_short y, u_short intmode, u_short dith, u_short vrammode);
-	void	GsSortObject4J(GsDOBJ2 *objp, GsOT *otp, int shift, u_long *scratch);
-	void    GsClearDispArea(unsigned char r, unsigned char g, unsigned char b);
-
-	u_long *GsPresetObject(GsDOBJ5 * objp, u_long * base_addr);
-	void    GsScaleScreen(SVECTOR * scale);
-
-	PACKET *GsA4divF3L(TMD_P_F3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			           int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divF3LFG(TMD_P_F3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divF3NL(TMD_P_F3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divNF3(TMD_P_NF3 * op, VERT * vp, PACKET * pk, int n,
-			           int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divF4L(TMD_P_F4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			           int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divF4LFG(TMD_P_F4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divF4NL(TMD_P_F4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divNF4(TMD_P_NF4 * op, VERT * vp, PACKET * pk, int n,
-			           int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divG3L(TMD_P_G3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			           int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divG3LFG(TMD_P_G3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divG3NL(TMD_P_G3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divNG3(TMD_P_NG3 * op, VERT * vp, PACKET * pk, int n,
-			           int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divG4L(TMD_P_G4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			           int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divG4LFG(TMD_P_G4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divG4NL(TMD_P_G4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divNG4(TMD_P_NG4 * op, VERT * vp, PACKET * pk, int n,
-			           int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTF3L(TMD_P_TF3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTF3LFG(TMD_P_TF3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTF3NL(TMD_P_TF3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTNF3(TMD_P_TNF3 * op, VERT * vp, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTF4L(TMD_P_TF4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTF4LFG(TMD_P_TF4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTF4NL(TMD_P_TF4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTNF4(TMD_P_TNF4 * op, VERT * vp, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTF4LM(TMD_P_TF4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTF4LFGM(TMD_P_TF4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTF4NLM(TMD_P_TF4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTNF4M(TMD_P_TNF4 * op, VERT * vp, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTG3L(TMD_P_TG3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTG3LFG(TMD_P_TG3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTG3NL(TMD_P_TG3 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTNG3(TMD_P_TNG3 * op, VERT * vp, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTG4L(TMD_P_TG4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTG4LFG(TMD_P_TG4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTG4NL(TMD_P_TG4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTNG4(TMD_P_TNG4 * op, VERT * vp, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTG4LM(TMD_P_TG4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTG4LFGM(TMD_P_TG4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTG4NLM(TMD_P_TG4 * op, VERT * vp, VERT * np, PACKET * pk, int n,
-			             int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsA4divTNG4M(TMD_P_TNG4 * op, VERT * vp, PACKET * pk, int n,
-			            int shift, GsOT * ot, u_long * scratch);
-	PACKET *GsTMDfastF3GL(TMD_P_F3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastF3GLFG(TMD_P_F3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastF3GNL(TMD_P_F3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG3GL(TMD_P_G3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG3GLFG(TMD_P_G3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG3GNL(TMD_P_G3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsPrstF3GL(TMD_P_F3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsPrstF3GLFG(TMD_P_F3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsPrstF3GNL(TMD_P_F3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsPrstG3GL(TMD_P_G3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsPrstG3GLFG(TMD_P_G3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsPrstG3GNL(TMD_P_G3G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG3M(TMD_P_G3 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG3MFG(TMD_P_G3 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastTG3M(TMD_P_TG3 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastTG3MFG(TMD_P_TG3 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastF4GL(TMD_P_F4G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastF4GLFG(TMD_P_F4G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastF4GNL(TMD_P_F4G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG4GL(TMD_P_G4G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG4GLFG(TMD_P_G4G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG4GNL(TMD_P_G4G *op, VERT *vp, VERT *np, PACKET *pk,
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG4M(TMD_P_G4 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastG4MFG(TMD_P_G4 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastTG4M(TMD_P_TG4 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastTG4MFG(TMD_P_TG4 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastF3M(TMD_P_F3 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastF3MFG(TMD_P_F3 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastTF3M(TMD_P_TF3 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastTF3MFG(TMD_P_TF3 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastF4M(TMD_P_F4 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastF4MFG(TMD_P_F4 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastTF4M(TMD_P_TF4 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-	PACKET *GsTMDfastTF4MFG(TMD_P_TF4 *op, VERT *vp, VERT *np, PACKET *pk, 
-						int n, int shift, GsOT *ot, u_long *scratch);
-
-#if defined(_LANGUAGE_C_PLUS_PLUS)||defined(__cplusplus)||defined(c_plusplus)
-}
-#endif
-
-
-
-/* EXTERN */
-extern RECT CLIP2;		/* clipping area */
-extern short PSDBASEX[2], PSDBASEY[2];	/* double buffer base */
-extern short PSDIDX;		/* double buffer index */
-extern u_long PSDCNT;		/* frame counter for using matrix cache */
-extern _GsPOSITION POSITION;	/* 2d offset */
-extern DRAWENV GsDRAWENV;	/* DRAWENV of Gs */
-extern DISPENV GsDISPENV;	/* DISPENV of Gs */
-extern MATRIX GsWSMATRIX;	/* Current World-Screen Matrix of Gs */
-extern MATRIX GsWSMATRIX_ORG;	/* Original World-Screen Matrix of Gs */
-extern long HWD0, VWD0;		/* rezolution of Holyzontal and Vertical */
-extern MATRIX GsLIGHTWSMATRIX;	/* World-Screen Light Matrix of Gs */
-extern MATRIX GsIDMATRIX;	/* Unit Matrix */
-extern MATRIX GsIDMATRIX2;	/* Unit Matrix including Aspect retio */
-extern PACKET *GsOUT_PACKET_P;	/* Work Base pointer */
-extern long GsADIVZ;		/* Active sub divide condition (z) */
-extern short GsADIVW, GsADIVH;	/* Active sub divide condition (w,h) */
-extern int GsLIGHT_MODE;	/* lighting mode global */
-extern u_long GsMATE_C, GsLMODE, GsLIGNR, GsLIOFF, GsZOVER, GsBACKC, GsNDIV;
-extern u_long GsTRATE, GsTON, GsDISPON;
-
-
-#if 0
-extern _GsFCALL GsFCALL5;	/* GsSortObject5J Func Table */
-/* hook only functions to use */
-jt_init5()
-{				/* GsSortObject5J Hook Func */
-	PACKET *GsPrstF3NL(), *GsPrstF3LFG(), *GsPrstF3L(), *GsPrstNF3();
-	PACKET *GsTMDdivF3NL(), *GsTMDdivF3LFG(), *GsTMDdivF3L(), *GsTMDdivNF3();
-	PACKET *GsPrstG3NL(), *GsPrstG3LFG(), *GsPrstG3L(), *GsPrstNG3();
-	PACKET *GsTMDdivG3NL(), *GsTMDdivG3LFG(), *GsTMDdivG3L(), *GsTMDdivNG3();
-	PACKET *GsPrstTF3NL(), *GsPrstTF3LFG(), *GsPrstTF3L(), *GsPrstTNF3();
-	PACKET *GsTMDdivTF3NL(), *GsTMDdivTF3LFG(), *GsTMDdivTF3L(),*GsTMDdivTNF3();
-	PACKET *GsPrstTG3NL(), *GsPrstTG3LFG(), *GsPrstTG3L(), *GsPrstTNG3();
-	PACKET *GsTMDdivTG3NL(), *GsTMDdivTG3LFG(), *GsTMDdivTG3L(),*GsTMDdivTNG3();
-	PACKET *GsPrstF4NL(), *GsPrstF4LFG(), *GsPrstF4L(), *GsPrstNF4();
-	PACKET *GsTMDdivF4NL(), *GsTMDdivF4LFG(), *GsTMDdivF4L(), *GsTMDdivNF4();
-	PACKET *GsPrstG4NL(), *GsPrstG4LFG(), *GsPrstG4L(), *GsPrstNG4();
-	PACKET *GsTMDdivG4NL(), *GsTMDdivG4LFG(), *GsTMDdivG4L(), *GsTMDdivNG4();
-	PACKET *GsPrstTF4NL(), *GsPrstTF4LFG(), *GsPrstTF4L(), *GsPrstTNF4();
-	PACKET *GsTMDdivTF4NL(), *GsTMDdivTF4LFG(), *GsTMDdivTF4L(),*GsTMDdivTNF4();
-	PACKET *GsPrstTG4NL(), *GsPrstTG4LFG(), *GsPrstTG4L(), *GsPrstTNG4();
-	PACKET *GsTMDdivTG4NL(), *GsTMDdivTG4LFG(), *GsTMDdivTG4L(),*GsTMDdivTNG4();
-	PACKET *GsPrstF3GNL(), *GsPrstF3GLFG(), *GsPrstF3GL();
-	PACKET *GsPrstG3GNL(), *GsPrstG3GLFG(), *GsPrstG3GL();
-
-	/* flat triangle */
-	GsFCALL5.f3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsPrstF3L;
-	GsFCALL5.f3[GsDivMODE_NDIV][GsLMODE_FOG] = GsPrstF3LFG;
-	GsFCALL5.f3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsPrstF3NL;
-	GsFCALL5.f3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivF3L;
-	GsFCALL5.f3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivF3LFG;
-	GsFCALL5.f3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivF3NL;
-	GsFCALL5.nf3[GsDivMODE_NDIV] = GsPrstNF3;
-	GsFCALL5.nf3[GsDivMODE_DIV] = GsTMDdivNF3;
-	/* gour triangle */
-	GsFCALL5.g3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsPrstG3L;
-	GsFCALL5.g3[GsDivMODE_NDIV][GsLMODE_FOG] = GsPrstG3LFG;
-	GsFCALL5.g3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsPrstG3NL;
-	GsFCALL5.g3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivG3L;
-	GsFCALL5.g3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivG3LFG;
-	GsFCALL5.g3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivG3NL;
-	GsFCALL5.ng3[GsDivMODE_NDIV] = GsPrstNG3;
-	GsFCALL5.ng3[GsDivMODE_DIV] = GsTMDdivNG3;
-	/* texture flat triangle */
-	GsFCALL5.tf3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsPrstTF3L;
-	GsFCALL5.tf3[GsDivMODE_NDIV][GsLMODE_FOG] = GsPrstTF3LFG;
-	GsFCALL5.tf3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsPrstTF3NL;
-	GsFCALL5.tf3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTF3L;
-	GsFCALL5.tf3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTF3LFG;
-	GsFCALL5.tf3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTF3NL;
-	GsFCALL5.ntf3[GsDivMODE_NDIV] = GsPrstTNF3;
-	GsFCALL5.ntf3[GsDivMODE_DIV] = GsTMDdivTNF3;
-	/* texture gour triangle */
-	GsFCALL5.tg3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsPrstTG3L;
-	GsFCALL5.tg3[GsDivMODE_NDIV][GsLMODE_FOG] = GsPrstTG3LFG;
-	GsFCALL5.tg3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsPrstTG3NL;
-	GsFCALL5.tg3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTG3L;
-	GsFCALL5.tg3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTG3LFG;
-	GsFCALL5.tg3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTG3NL;
-	GsFCALL5.ntg3[GsDivMODE_NDIV] = GsPrstTNG3;
-	GsFCALL5.ntg3[GsDivMODE_DIV] = GsTMDdivTNG3;
-	/* flat quad */
-	GsFCALL5.f4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsPrstF4L;
-	GsFCALL5.f4[GsDivMODE_NDIV][GsLMODE_FOG] = GsPrstF4LFG;
-	GsFCALL5.f4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsPrstF4NL;
-	GsFCALL5.f4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivF4L;
-	GsFCALL5.f4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivF4LFG;
-	GsFCALL5.f4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivF4NL;
-	GsFCALL5.nf4[GsDivMODE_NDIV] = GsPrstNF4;
-	GsFCALL5.nf4[GsDivMODE_DIV] = GsTMDdivNF4;
-	/* gour quad */
-	GsFCALL5.g4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsPrstG4L;
-	GsFCALL5.g4[GsDivMODE_NDIV][GsLMODE_FOG] = GsPrstG4LFG;
-	GsFCALL5.g4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsPrstG4NL;
-	GsFCALL5.g4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivG4L;
-	GsFCALL5.g4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivG4LFG;
-	GsFCALL5.g4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivG4NL;
-	GsFCALL5.ng4[GsDivMODE_NDIV] = GsPrstNG4;
-	GsFCALL5.ng4[GsDivMODE_DIV] = GsTMDdivNG4;
-	/* texture flat quad */
-	GsFCALL5.tf4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsPrstTF4L;
-	GsFCALL5.tf4[GsDivMODE_NDIV][GsLMODE_FOG] = GsPrstTF4LFG;
-	GsFCALL5.tf4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsPrstTF4NL;
-	GsFCALL5.tf4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTF4L;
-	GsFCALL5.tf4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTF4LFG;
-	GsFCALL5.tf4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTF4NL;
-	GsFCALL5.ntf4[GsDivMODE_NDIV] = GsPrstTNF4;
-	GsFCALL5.ntf4[GsDivMODE_DIV] = GsTMDdivTNF4;
-	/* texture gour quad */
-	GsFCALL5.tg4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsPrstTG4L;
-	GsFCALL5.tg4[GsDivMODE_NDIV][GsLMODE_FOG] = GsPrstTG4LFG;
-	GsFCALL5.tg4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsPrstTG4NL;
-	GsFCALL5.tg4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTG4L;
-	GsFCALL5.tg4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTG4LFG;
-	GsFCALL5.tg4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTG4NL;
-	GsFCALL5.ntg4[GsDivMODE_NDIV] = GsPrstTNG4;
-	GsFCALL5.ntg4[GsDivMODE_DIV] = GsTMDdivTNG4;
-	/* gradation triangle */
-	GsFCALL5.f3g[GsLMODE_NORMAL] = GsPrstF3GL;
-	GsFCALL5.f3g[GsLMODE_FOG] = GsPrstF3GLFG;
-	GsFCALL5.f3g[GsLMODE_LOFF] = GsPrstF3GNL;
-	GsFCALL5.g3g[GsLMODE_NORMAL] = GsPrstG3GL;
-	GsFCALL5.g3g[GsLMODE_FOG] = GsPrstG3GLFG;
-	GsFCALL5.g3g[GsLMODE_LOFF] = GsPrstG3GNL;
-}
-#endif
-
-#if 0
-extern _GsFCALL GsFCALL4;	/* GsSortObject4J Func Table */
-/* hook only functions to use*/
-jt_init4()
-{				/* GsSortObject4J Hook Func */
-	PACKET *GsTMDfastF3NL(), *GsTMDfastF3LFG(), *GsTMDfastF3L(),*GsTMDfastNF3();
-	PACKET *GsTMDdivF3NL(), *GsTMDdivF3LFG(), *GsTMDdivF3L(), *GsTMDdivNF3();
-	PACKET *GsTMDfastG3NL(), *GsTMDfastG3LFG(), *GsTMDfastG3L(),*GsTMDfastNG3();
-	PACKET *GsTMDdivG3NL(), *GsTMDdivG3LFG(), *GsTMDdivG3L(), *GsTMDdivNG3();
-	PACKET *GsTMDfastTF3NL(), *GsTMDfastTF3LFG(), *GsTMDfastTF3L(), *GsTMDfastTNF3();
-	PACKET *GsTMDdivTF3NL(), *GsTMDdivTF3LFG(), *GsTMDdivTF3L(), *GsTMDdivTNF3();
-	PACKET *GsTMDfastTG3NL(), *GsTMDfastTG3LFG(), *GsTMDfastTG3L(), *GsTMDfastTNG3();
-	PACKET *GsTMDdivTG3NL(), *GsTMDdivTG3LFG(), *GsTMDdivTG3L(), *GsTMDdivTNG3();
-	PACKET *GsTMDfastF4NL(), *GsTMDfastF4LFG(), *GsTMDfastF4L(), *GsTMDfastNF4();
-	PACKET *GsTMDdivF4NL(), *GsTMDdivF4LFG(), *GsTMDdivF4L(), *GsTMDdivNF4();
-	PACKET *GsTMDfastG4NL(), *GsTMDfastG4LFG(), *GsTMDfastG4L(), *GsTMDfastNG4();
-	PACKET *GsTMDdivG4NL(), *GsTMDdivG4LFG(), *GsTMDdivG4L(), *GsTMDdivNG4();
-	PACKET *GsTMDfastTF4NL(), *GsTMDfastTF4LFG(), *GsTMDfastTF4L(), *GsTMDfastTNF4();
-	PACKET *GsTMDdivTF4NL(), *GsTMDdivTF4LFG(), *GsTMDdivTF4L(), *GsTMDdivTNF4();
-	PACKET *GsTMDfastTG4NL(), *GsTMDfastTG4LFG(), *GsTMDfastTG4L(), *GsTMDfastTNG4();
-	PACKET *GsTMDdivTG4NL(), *GsTMDdivTG4LFG(), *GsTMDdivTG4L(), *GsTMDdivTNG4();
-
-	/* flat triangle */
-	GsFCALL4.f3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastF3L;
-	GsFCALL4.f3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastF3LFG;
-	GsFCALL4.f3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastF3NL;
-	GsFCALL4.f3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivF3L;
-	GsFCALL4.f3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivF3LFG;
-	GsFCALL4.f3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivF3NL;
-	GsFCALL4.nf3[GsDivMODE_NDIV] = GsTMDfastNF3;
-	GsFCALL4.nf3[GsDivMODE_DIV] = GsTMDdivNF3;
-	/* gour triangle */
-	GsFCALL4.g3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastG3L;
-	GsFCALL4.g3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastG3LFG;
-	GsFCALL4.g3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastG3NL;
-	GsFCALL4.g3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivG3L;
-	GsFCALL4.g3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivG3LFG;
-	GsFCALL4.g3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivG3NL;
-	GsFCALL4.ng3[GsDivMODE_NDIV] = GsTMDfastNG3;
-	GsFCALL4.ng3[GsDivMODE_DIV] = GsTMDdivNG3;
-	/* texture flat triangle */
-	GsFCALL4.tf3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTF3L;
-	GsFCALL4.tf3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTF3LFG;
-	GsFCALL4.tf3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTF3NL;
-	GsFCALL4.tf3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTF3L;
-	GsFCALL4.tf3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTF3LFG;
-	GsFCALL4.tf3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTF3NL;
-	GsFCALL4.ntf3[GsDivMODE_NDIV] = GsTMDfastTNF3;
-	GsFCALL4.ntf3[GsDivMODE_DIV] = GsTMDdivTNF3;
-	/* texture gour triangle */
-	GsFCALL4.tg3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTG3L;
-	GsFCALL4.tg3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTG3LFG;
-	GsFCALL4.tg3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTG3NL;
-	GsFCALL4.tg3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTG3L;
-	GsFCALL4.tg3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTG3LFG;
-	GsFCALL4.tg3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTG3NL;
-	GsFCALL4.ntg3[GsDivMODE_NDIV] = GsTMDfastTNG3;
-	GsFCALL4.ntg3[GsDivMODE_DIV] = GsTMDdivTNG3;
-	/* flat quad */
-	GsFCALL4.f4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastF4L;
-	GsFCALL4.f4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastF4LFG;
-	GsFCALL4.f4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastF4NL;
-	GsFCALL4.f4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivF4L;
-	GsFCALL4.f4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivF4LFG;
-	GsFCALL4.f4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivF4NL;
-	GsFCALL4.nf4[GsDivMODE_NDIV] = GsTMDfastNF4;
-	GsFCALL4.nf4[GsDivMODE_DIV] = GsTMDdivNF4;
-	/* gour quad */
-	GsFCALL4.g4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastG4L;
-	GsFCALL4.g4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastG4LFG;
-	GsFCALL4.g4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastG4NL;
-	GsFCALL4.g4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivG4L;
-	GsFCALL4.g4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivG4LFG;
-	GsFCALL4.g4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivG4NL;
-	GsFCALL4.ng4[GsDivMODE_NDIV] = GsTMDfastNG4;
-	GsFCALL4.ng4[GsDivMODE_DIV] = GsTMDdivNG4;
-	/* texture flat quad */
-	GsFCALL4.tf4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTF4L;
-	GsFCALL4.tf4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTF4LFG;
-	GsFCALL4.tf4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTF4NL;
-	GsFCALL4.tf4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTF4L;
-	GsFCALL4.tf4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTF4LFG;
-	GsFCALL4.tf4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTF4NL;
-	GsFCALL4.ntf4[GsDivMODE_NDIV] = GsTMDfastTNF4;
-	GsFCALL4.ntf4[GsDivMODE_DIV] = GsTMDdivTNF4;
-	/* texture gour quad */
-	GsFCALL4.tg4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTG4L;
-	GsFCALL4.tg4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTG4LFG;
-	GsFCALL4.tg4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTG4NL;
-	GsFCALL4.tg4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTG4L;
-	GsFCALL4.tg4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTG4LFG;
-	GsFCALL4.tg4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTG4NL;
-	GsFCALL4.ntg4[GsDivMODE_NDIV] = GsTMDfastTNG4;
-	GsFCALL4.ntg4[GsDivMODE_DIV] = GsTMDdivTNG4;
-	/* gradation  triangle */
-	GsFCALL4.f3g[GsLMODE_NORMAL] = GsTMDfastF3GL;
-	GsFCALL4.f3g[GsLMODE_FOG] = GsTMDfastF3GLFG;
-	GsFCALL4.f3g[GsLMODE_LOFF] = GsTMDfastF3GNL;
-	GsFCALL4.g3g[GsLMODE_NORMAL] = GsTMDfastG3GL;
-	GsFCALL4.g3g[GsLMODE_FOG] = GsTMDfastG3GLFG;
-	GsFCALL4.g3g[GsLMODE_LOFF] = GsTMDfastG3GNL;
-	/* gradation  quad */
-	GsFCALL4.f4g[GsLMODE_NORMAL] = GsTMDfastF4GL;
-	GsFCALL4.f4g[GsLMODE_FOG] = GsTMDfastF4GLFG;
-	GsFCALL4.f4g[GsLMODE_LOFF] = GsTMDfastF4GNL;
-	GsFCALL4.g4g[GsLMODE_NORMAL] = GsTMDfastG4GL;
-	GsFCALL4.g4g[GsLMODE_FOG] = GsTMDfastG4GLFG;
-	GsFCALL4.g4g[GsLMODE_LOFF] = GsTMDfastG4GNL;
-}
-#endif
-
-#if 0
-extern _GsFCALL GsFCALL4;	/* GsSortObject4J Func Table */
-jt_init4()
-{				/* Gs SortObject4J Active sub divide Func */
-	PACKET *GsTMDfastF3NL(), *GsTMDfastF3LFG(), *GsTMDfastF3L(), *GsTMDfastNF3();
-	PACKET *GsA4divF3NL(), *GsA4divF3LFG(), *GsA4divF3L(), *GsA4divNF3();
-	PACKET *GsTMDfastG3NL(), *GsTMDfastG3LFG(), *GsTMDfastG3L(), *GsTMDfastNG3();
-	PACKET *GsA4divG3NL(), *GsA4divG3LFG(), *GsA4divG3L(), *GsA4divNG3();
-	PACKET *GsTMDfastTF3NL(), *GsTMDfastTF3LFG(), *GsTMDfastTF3L(), *GsTMDfastTNF3();
-	PACKET *GsA4divTF3NL(), *GsA4divTF3LFG(), *GsA4divTF3L(), *GsA4divTNF3();
-	PACKET *GsTMDfastTG3NL(), *GsTMDfastTG3LFG(), *GsTMDfastTG3L(), *GsTMDfastTNG3();
-	PACKET *GsA4divTG3NL(), *GsA4divTG3LFG(), *GsA4divTG3L(), *GsA4divTNG3();
-	PACKET *GsTMDfastF4NL(), *GsTMDfastF4LFG(), *GsTMDfastF4L(), *GsTMDfastNF4();
-	PACKET *GsA4divF4NL(), *GsA4divF4LFG(), *GsA4divF4L(), *GsA4divNF4();
-	PACKET *GsTMDfastG4NL(), *GsTMDfastG4LFG(), *GsTMDfastG4L(), *GsTMDfastNG4();
-	PACKET *GsA4divG4NL(), *GsA4divG4LFG(), *GsA4divG4L(), *GsA4divNG4();
-	PACKET *GsTMDfastTF4NL(), *GsTMDfastTF4LFG(), *GsTMDfastTF4L(), *GsTMDfastTNF4();
-	PACKET *GsA4divTF4NL(), *GsA4divTF4LFG(), *GsA4divTF4L(), *GsA4divTNF4();
-	PACKET *GsTMDfastTG4NL(), *GsTMDfastTG4LFG(), *GsTMDfastTG4L(), *GsTMDfastTNG4();
-	PACKET *GsA4divTG4NL(), *GsA4divTG4LFG(), *GsA4divTG4L(), *GsA4divTNG4();
-	PACKET *GsA4divTF4L();
-
-	/* flat triangle */
-	GsFCALL4.f3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastF3L;
-	GsFCALL4.f3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastF3LFG;
-	GsFCALL4.f3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastF3NL;
-	GsFCALL4.f3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsA4divF3L;
-	GsFCALL4.f3[GsDivMODE_DIV][GsLMODE_FOG] = GsA4divF3LFG;
-	GsFCALL4.f3[GsDivMODE_DIV][GsLMODE_LOFF] = GsA4divF3NL;
-	GsFCALL4.nf3[GsDivMODE_NDIV] = GsTMDfastNF3;
-	GsFCALL4.nf3[GsDivMODE_DIV] = GsA4divNF3;
-	/* gour triangle */
-	GsFCALL4.g3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastG3L;
-	GsFCALL4.g3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastG3LFG;
-	GsFCALL4.g3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastG3NL;
-	GsFCALL4.g3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsA4divG3L;
-	GsFCALL4.g3[GsDivMODE_DIV][GsLMODE_FOG] = GsA4divG3LFG;
-	GsFCALL4.g3[GsDivMODE_DIV][GsLMODE_LOFF] = GsA4divG3NL;
-	GsFCALL4.ng3[GsDivMODE_NDIV] = GsTMDfastNG3;
-	GsFCALL4.ng3[GsDivMODE_DIV] = GsA4divNG3;
-	/* texture flat triangle */
-	GsFCALL4.tf3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTF3L;
-	GsFCALL4.tf3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTF3LFG;
-	GsFCALL4.tf3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTF3NL;
-	GsFCALL4.tf3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsA4divTF3L;
-	GsFCALL4.tf3[GsDivMODE_DIV][GsLMODE_FOG] = GsA4divTF3LFG;
-	GsFCALL4.tf3[GsDivMODE_DIV][GsLMODE_LOFF] = GsA4divTF3NL;
-	GsFCALL4.ntf3[GsDivMODE_NDIV] = GsTMDfastTNF3;
-	GsFCALL4.ntf3[GsDivMODE_DIV] = GsA4divTNF3;
-	/* texture gour triangle */
-	GsFCALL4.tg3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTG3L;
-	GsFCALL4.tg3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTG3LFG;
-	GsFCALL4.tg3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTG3NL;
-	GsFCALL4.tg3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsA4divTG3L;
-	GsFCALL4.tg3[GsDivMODE_DIV][GsLMODE_FOG] = GsA4divTG3LFG;
-	GsFCALL4.tg3[GsDivMODE_DIV][GsLMODE_LOFF] = GsA4divTG3NL;
-	GsFCALL4.ntg3[GsDivMODE_NDIV] = GsTMDfastTNG3;
-	GsFCALL4.ntg3[GsDivMODE_DIV] = GsA4divTNG3;
-	/* flat quad */
-	GsFCALL4.f4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastF4L;
-	GsFCALL4.f4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastF4LFG;
-	GsFCALL4.f4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastF4NL;
-	GsFCALL4.f4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsA4divF4L;
-	GsFCALL4.f4[GsDivMODE_DIV][GsLMODE_FOG] = GsA4divF4LFG;
-	GsFCALL4.f4[GsDivMODE_DIV][GsLMODE_LOFF] = GsA4divF4NL;
-	GsFCALL4.nf4[GsDivMODE_NDIV] = GsTMDfastNF4;
-	GsFCALL4.nf4[GsDivMODE_DIV] = GsA4divNF4;
-	/* gour quad */
-	GsFCALL4.g4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastG4L;
-	GsFCALL4.g4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastG4LFG;
-	GsFCALL4.g4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastG4NL;
-	GsFCALL4.g4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsA4divG4L;
-	GsFCALL4.g4[GsDivMODE_DIV][GsLMODE_FOG] = GsA4divG4LFG;
-	GsFCALL4.g4[GsDivMODE_DIV][GsLMODE_LOFF] = GsA4divG4NL;
-	GsFCALL4.ng4[GsDivMODE_NDIV] = GsTMDfastNG4;
-	GsFCALL4.ng4[GsDivMODE_DIV] = GsA4divNG4;
-	/* texture flat quad */
-	GsFCALL4.tf4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTF4L;
-	GsFCALL4.tf4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTF4LFG;
-	GsFCALL4.tf4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTF4NL;
-	GsFCALL4.tf4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsA4divTF4L;
-	GsFCALL4.tf4[GsDivMODE_DIV][GsLMODE_FOG] = GsA4divTF4LFG;
-	GsFCALL4.tf4[GsDivMODE_DIV][GsLMODE_LOFF] = GsA4divTF4NL;
-	GsFCALL4.ntf4[GsDivMODE_NDIV] = GsTMDfastTNF4;
-	GsFCALL4.ntf4[GsDivMODE_DIV] = GsA4divTNF4;
-	/* texture gour quad */
-	GsFCALL4.tg4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTG4L;
-	GsFCALL4.tg4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTG4LFG;
-	GsFCALL4.tg4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTG4NL;
-	GsFCALL4.tg4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsA4divTG4L;
-	GsFCALL4.tg4[GsDivMODE_DIV][GsLMODE_FOG] = GsA4divTG4LFG;
-	GsFCALL4.tg4[GsDivMODE_DIV][GsLMODE_LOFF] = GsA4divTG4NL;
-	GsFCALL4.ntg4[GsDivMODE_NDIV] = GsTMDfastTNG4;
-	GsFCALL4.ntg4[GsDivMODE_DIV] = GsA4divTNG4;
-	/* gradation triangle */
-	GsFCALL4.f3g[GsLMODE_NORMAL] = GsTMDfastF3GL;
-	GsFCALL4.f3g[GsLMODE_FOG] = GsTMDfastF3GLFG;
-	GsFCALL4.f3g[GsLMODE_LOFF] = GsTMDfastF3GNL;
-	GsFCALL4.g3g[GsLMODE_NORMAL] = GsTMDfastG3GL;
-	GsFCALL4.g3g[GsLMODE_FOG] = GsTMDfastG3GLFG;
-	GsFCALL4.g3g[GsLMODE_LOFF] = GsTMDfastG3GNL;
-	/* gradation  quad */
-	GsFCALL4.f4g[GsLMODE_NORMAL] = GsTMDfastF4GL;
-	GsFCALL4.f4g[GsLMODE_FOG] = GsTMDfastF4GLFG;
-	GsFCALL4.f4g[GsLMODE_LOFF] = GsTMDfastF4GNL;
-	GsFCALL4.g4g[GsLMODE_NORMAL] = GsTMDfastG4GL;
-	GsFCALL4.g4g[GsLMODE_FOG] = GsTMDfastG4GLFG;
-	GsFCALL4.g4g[GsLMODE_LOFF] = GsTMDfastG4GNL;
-}
-#endif
-
-#if 0
-extern _GsFCALL GsFCALL4;	/* GsSortObject4J Func Table */
-/* hook only functions to use */
-jt_init4()
-{				/* GsSortObject4J Hook Func (for material attenuation)*/
-	PACKET *GsTMDfastF3NL(), *GsTMDfastF3MFG(), *GsTMDfastF3M(),*GsTMDfastNF3();
-	PACKET *GsTMDdivF3NL(), *GsTMDdivF3LFG(), *GsTMDdivF3L(), *GsTMDdivNF3();
-	PACKET *GsTMDfastG3NL(), *GsTMDfastG3MFG(), *GsTMDfastG3M(),*GsTMDfastNG3();
-	PACKET *GsTMDdivG3NL(), *GsTMDdivG3LFG(), *GsTMDdivG3L(), *GsTMDdivNG3();
-	PACKET *GsTMDfastTF3NL(), *GsTMDfastTF3MFG(), *GsTMDfastTF3M(), *GsTMDfastTNF3();
-	PACKET *GsTMDdivTF3NL(), *GsTMDdivTF3LFG(), *GsTMDdivTF3L(), *GsTMDdivTNF3();
-	PACKET *GsTMDfastTG3NL(), *GsTMDfastTG3MFG(), *GsTMDfastTG3M(), *GsTMDfastTNG3();
-	PACKET *GsTMDdivTG3NL(), *GsTMDdivTG3LFG(), *GsTMDdivTG3L(), *GsTMDdivTNG3();
-	PACKET *GsTMDfastF4NL(), *GsTMDfastF4MFG(), *GsTMDfastF4M(), *GsTMDfastNF4();
-	PACKET *GsTMDdivF4NL(), *GsTMDdivF4LFG(), *GsTMDdivF4L(), *GsTMDdivNF4();
-	PACKET *GsTMDfastG4NL(), *GsTMDfastG4MFG(), *GsTMDfastG4M(), *GsTMDfastNG4();
-	PACKET *GsTMDdivG4NL(), *GsTMDdivG4LFG(), *GsTMDdivG4L(), *GsTMDdivNG4();
-	PACKET *GsTMDfastTF4NL(), *GsTMDfastTF4MFG(), *GsTMDfastTF4M(), *GsTMDfastTNF4();
-	PACKET *GsTMDdivTF4NL(), *GsTMDdivTF4LFG(), *GsTMDdivTF4L(), *GsTMDdivTNF4();
-	PACKET *GsTMDfastTG4NL(), *GsTMDfastTG4MFG(), *GsTMDfastTG4M(), *GsTMDfastTNG4();
-	PACKET *GsTMDdivTG4NL(), *GsTMDdivTG4LFG(), *GsTMDdivTG4L(), *GsTMDdivTNG4();
-
-	/* flat triangle */
-	GsFCALL4.f3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastF3M;
-	GsFCALL4.f3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastF3MFG;
-	GsFCALL4.f3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastF3NL;
-	GsFCALL4.f3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivF3L;
-	GsFCALL4.f3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivF3LFG;
-	GsFCALL4.f3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivF3NL;
-	GsFCALL4.nf3[GsDivMODE_NDIV] = GsTMDfastNF3;
-	GsFCALL4.nf3[GsDivMODE_DIV] = GsTMDdivNF3;
-	/* gour triangle */
-	GsFCALL4.g3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastG3M;
-	GsFCALL4.g3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastG3MFG;
-	GsFCALL4.g3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastG3NL;
-	GsFCALL4.g3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivG3L;
-	GsFCALL4.g3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivG3LFG;
-	GsFCALL4.g3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivG3NL;
-	GsFCALL4.ng3[GsDivMODE_NDIV] = GsTMDfastNG3;
-	GsFCALL4.ng3[GsDivMODE_DIV] = GsTMDdivNG3;
-	/* texture flat triangle */
-	GsFCALL4.tf3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTF3M;
-	GsFCALL4.tf3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTF3MFG;
-	GsFCALL4.tf3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTF3NL;
-	GsFCALL4.tf3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTF3L;
-	GsFCALL4.tf3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTF3LFG;
-	GsFCALL4.tf3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTF3NL;
-	GsFCALL4.ntf3[GsDivMODE_NDIV] = GsTMDfastTNF3;
-	GsFCALL4.ntf3[GsDivMODE_DIV] = GsTMDdivTNF3;
-	/* texture gour triangle */
-	GsFCALL4.tg3[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTG3M;
-	GsFCALL4.tg3[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTG3MFG;
-	GsFCALL4.tg3[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTG3NL;
-	GsFCALL4.tg3[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTG3L;
-	GsFCALL4.tg3[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTG3LFG;
-	GsFCALL4.tg3[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTG3NL;
-	GsFCALL4.ntg3[GsDivMODE_NDIV] = GsTMDfastTNG3;
-	GsFCALL4.ntg3[GsDivMODE_DIV] = GsTMDdivTNG3;
-	/* flat quad */
-	GsFCALL4.f4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastF4M;
-	GsFCALL4.f4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastF4MFG;
-	GsFCALL4.f4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastF4NL;
-	GsFCALL4.f4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivF4L;
-	GsFCALL4.f4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivF4LFG;
-	GsFCALL4.f4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivF4NL;
-	GsFCALL4.nf4[GsDivMODE_NDIV] = GsTMDfastNF4;
-	GsFCALL4.nf4[GsDivMODE_DIV] = GsTMDdivNF4;
-	/* gour quad */
-	GsFCALL4.g4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastG4M;
-	GsFCALL4.g4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastG4MFG;
-	GsFCALL4.g4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastG4NL;
-	GsFCALL4.g4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivG4L;
-	GsFCALL4.g4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivG4LFG;
-	GsFCALL4.g4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivG4NL;
-	GsFCALL4.ng4[GsDivMODE_NDIV] = GsTMDfastNG4;
-	GsFCALL4.ng4[GsDivMODE_DIV] = GsTMDdivNG4;
-	/* texture flat quad */
-	GsFCALL4.tf4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTF4M;
-	GsFCALL4.tf4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTF4MFG;
-	GsFCALL4.tf4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTF4NL;
-	GsFCALL4.tf4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTF4L;
-	GsFCALL4.tf4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTF4LFG;
-	GsFCALL4.tf4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTF4NL;
-	GsFCALL4.ntf4[GsDivMODE_NDIV] = GsTMDfastTNF4;
-	GsFCALL4.ntf4[GsDivMODE_DIV] = GsTMDdivTNF4;
-	/* texture gour quad */
-	GsFCALL4.tg4[GsDivMODE_NDIV][GsLMODE_NORMAL] = GsTMDfastTG4M;
-	GsFCALL4.tg4[GsDivMODE_NDIV][GsLMODE_FOG] = GsTMDfastTG4MFG;
-	GsFCALL4.tg4[GsDivMODE_NDIV][GsLMODE_LOFF] = GsTMDfastTG4NL;
-	GsFCALL4.tg4[GsDivMODE_DIV][GsLMODE_NORMAL] = GsTMDdivTG4L;
-	GsFCALL4.tg4[GsDivMODE_DIV][GsLMODE_FOG] = GsTMDdivTG4LFG;
-	GsFCALL4.tg4[GsDivMODE_DIV][GsLMODE_LOFF] = GsTMDdivTG4NL;
-	GsFCALL4.ntg4[GsDivMODE_NDIV] = GsTMDfastTNG4;
-	GsFCALL4.ntg4[GsDivMODE_DIV] = GsTMDdivTNG4;
-	/* gradation  triangle */
-	GsFCALL4.f3g[GsLMODE_NORMAL] = GsTMDfastF3GL;
-	GsFCALL4.f3g[GsLMODE_FOG] = GsTMDfastF3GLFG;
-	GsFCALL4.f3g[GsLMODE_LOFF] = GsTMDfastF3GNL;
-	GsFCALL4.g3g[GsLMODE_NORMAL] = GsTMDfastG3GL;
-	GsFCALL4.g3g[GsLMODE_FOG] = GsTMDfastG3GLFG;
-	GsFCALL4.g3g[GsLMODE_LOFF] = GsTMDfastG3GNL;
-	/* gradation  quad */
-	GsFCALL4.f4g[GsLMODE_NORMAL] = GsTMDfastF4GL;
-	GsFCALL4.f4g[GsLMODE_FOG] = GsTMDfastF4GLFG;
-	GsFCALL4.f4g[GsLMODE_LOFF] = GsTMDfastF4GNL;
-	GsFCALL4.g4g[GsLMODE_NORMAL] = GsTMDfastG4GL;
-	GsFCALL4.g4g[GsLMODE_FOG] = GsTMDfastG4GLFG;
-	GsFCALL4.g4g[GsLMODE_LOFF] = GsTMDfastG4GNL;
-}
-#endif
-
-#endif				/* _LIBGS_H_ */
+begin
+end.

+ 2 - 2
rtl/ps1/psy-q-sdk/libgte.pas

@@ -15,9 +15,9 @@ type
 				m : array [0..2, 0..2] of smallint;		// 3x3 rotation matrix
         		t : array [0..2] of longint;		// transfer vector
         	 end;
-    PMATRIX = ^MATRIX;
+    	PMATRIX = ^MATRIX;
 
-    VECTOR = packed record							// long word type 3D vector
+    	VECTOR = packed record							// long word type 3D vector
 				vx, vy : longint;
 				vz, pad : longint;
 			 end;

+ 13 - 0
rtl/ps1/psy-q-sdk/libgun.pas

@@ -0,0 +1,13 @@
+//  libetc.h: Light Gun Interface
+unit libgun;
+interface
+
+procedure InitGUN(bufA: Pbyte; lenA: longint; bufB: Pbyte; lenB: longint; buf1: Pbyte; buf2: Pbyte; len: longint); external;
+procedure RemoveGUN; external;
+procedure SelectGUN(ch: longint; mask: byte); external;
+function StartGUN: longint; external;
+procedure StopGUN; external;
+
+implementation
+begin
+end.

+ 1119 - 0
rtl/ps1/psy-q-sdk/libhmd.pas

@@ -0,0 +1,1119 @@
+// libhmd.h: Hierarchical Modeling Data Library
+unit libhmd;
+interface
+uses libgte, libgs;
+const
+	GsUNIT_TERM	= $ffffffff;	// Primitive terminater
+	GsUNIT_DIV1	= 1 shl 24;		//  2 x  2 divide
+	GsUNIT_DIV2	= 2 shl 24;		//  4 x  4 divide
+	GsUNIT_DIV3	= 3 shl 24;		//  8 x  8 divide
+	GsUNIT_DIV4	= 4 shl 24;		// 16 x 16 divide
+	GsUNIT_DIV5	= 5 shl 24;		// 32 x 32 divide
+
+type
+	PGsCOORDUNIT = ^GsCOORDUNIT;
+	GsCOORDUNIT = packed record
+		flg : dword;
+		matrix : MATRIX;
+		workm : MATRIX;
+		rot : SVECTOR;
+		super : PGsCOORDUNIT;
+	end;
+
+	PGsVIEWUNIT = ^GsVIEWUNIT;
+	GsVIEWUNIT = packed record
+		view : MATRIX;
+		super : PGsCOORDUNIT;
+	end;
+
+	PGsRVIEWUNIT = ^GsRVIEWUNIT;
+	GsRVIEWUNIT = packed record
+		vpx, vpy, vpz : longint;
+		vrx, vry, vrz : longint;
+		rz : longint;
+		super : PGsRVIEWUNIT;
+	end;
+
+	PGsUNIT = ^GsUNIT;
+	GsUNIT = packed record
+		coord : PGsCOORDUNIT;	// local dmatrix
+		primtop : pdword;
+	end;
+
+	PGsTYPEUNIT = ^GsTYPEUNIT;
+	GsTYPEUNIT = packed record
+		_type : dword;
+		ptr : pointer;
+	end;
+
+	PGsARGUNIT = ^GsARGUNIT;
+	GsARGUNIT = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+	end;
+	
+	PGsWORKUNIT = ^GsWORKUNIT;
+	GsWORKUNIT = packed record
+		vec : DVECTOR;
+		otz : smallint;
+		p : smallint;
+	end;
+
+	GsARGUNIT_NORMAL = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		primtop : pdword;
+		vertop : PSVECTOR;
+		nortop : PSVECTOR;
+	end;
+
+	GsARGUNIT_SHARED = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		primtop : pdword;
+		vertop : PSVECTOR;
+		vertop2 : PGsWORKUNIT;
+		nortop : PSVECTOR;
+		nortop2 : PSVECTOR;
+	end;
+
+	
+	GsARGUNIT_IMAGE = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		imagetop : pdword;
+		cluttop : pdword;
+	end;
+
+	GsARGUNIT_GND = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		polytop : pdword;
+		boxtop : pdword;
+		pointtop : pdword;
+		nortop : PSVECTOR;
+	end;
+
+	GsARGUNIT_GNDT = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		polytop : pdword;
+		boxtop : pdword;
+		pointtop : pdword;
+		nortop : PSVECTOR;
+		uvtop : pdword;
+	end;
+
+	GsARGUNIT_CAMERA = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		cparam : pdword;
+		coord : PGsCOORDUNIT;
+		rcoord : PGsCOORDUNIT;
+	end;
+
+	GsARGUNIT_LIGHT = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		lparam : pdword;
+		coord : PGsCOORDUNIT;
+		rcoord : PGsCOORDUNIT;
+	end;
+
+	GsARGUNIT_JntMIMe = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		coord_sect : pdword;
+		mimepr : plongint;
+		mimenum : dword;
+		mimeid, reserved : smallint;
+		mime_diff_sect : pdword;
+	end;
+
+
+	GsARGUNIT_RstJntMIMe = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		coord_sect : pdword;
+		mimeid, reserved : smallint;
+		mime_diff_sect : pdword;
+	end;
+
+	GsARGUNIT_VNMIMe = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		mimepr : plongint;
+		mimenum : dword;
+		mimeid, reserved : smallint;
+		mime_diff_sect : pdword;
+		orgs_vn_sect : PSVECTOR;
+		vert_sect : PSVECTOR;
+		norm_sect : PSVECTOR;
+	end;
+
+	GsARGUNIT_RstVNMIMe = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		mimeid, reserved : smallint;
+		mime_diff_sect : pdword;
+		orgs_vn_sect : PSVECTOR;
+		vert_sect : PSVECTOR;
+		norm_sect : PSVECTOR;
+	end;
+	
+	PGsARGUNIT_ANIM = ^GsARGUNIT_ANIM;
+ 	GsARGUNIT_ANIM = packed record
+		primp : pdword;
+		tagp : PGsOT;
+		shift : longint;
+		offset : longint;
+		out_packetp : PPACKET;
+		header_size : longint;
+		htop : pdword;
+		ctop : pdword;
+		ptop : pdword;
+	end;
+
+	GsSEH = packed record
+		idx : smallint;
+		sid : byte;
+		pad : byte;
+	end;
+
+	PGsSEQ = ^GsSEQ;
+	GsSEQ = packed record
+		rewrite_idx : dword;
+		size, num : word;
+		ii : word;
+		aframe : word;
+		sid : byte;
+		speed : shortint;
+		srcii : word;
+		rframe : smallint;
+		tframe : word;
+		ci, ti : word;
+		start : word;
+		start_sid : byte;
+		traveling : byte;
+	end;
+	PPGsSEQ = ^PGsSEQ;
+
+
+
+// GsTYPEUNIT code macro
+const
+	GsUF3		= $00000008;	// flat triangle
+	GsUFT3		= $00000009;	// texture flat triangle
+	GsUG3		= $0000000c;	// gour triangle 
+	GsUGT3		= $0000000d;	// texture gour triangle 
+	GsUF4		= $00000010;	// flat quad 
+	GsUFT4		= $00000011;	// texture flat quad 
+	GsUG4		= $00000014;	// gour quad 
+	GsUGT4		= $00000015;	// texture gour quad 
+
+	GsUFF3		= $00020008;	// fog flat triangle 
+	GsUFFT3		= $00020009;	// fog texture flat triangle 
+	GsUFG3		= $0002000c;	// fog gour triangle 
+	GsUFGT3		= $0002000d;	// fog texture gour triangle 
+	GsUFF4		= $00020010;	// fog flat quad 
+	GsUFFT4		= $00020011;	// fog texture flat quad 
+	GsUFG4		= $00020014;	// fog gour quad 
+	GsUFGT4		= $00020015;	// fog texture gour quad 
+
+	GsUCF3		= $0000000a;	// colored flat triangle 
+	GsUCFT3		= $0000000b;	// colored texture flat triangle 
+	GsUCG3		= $0000000e;	// colored gour triangle 
+	GsUCGT3		= $0000000f;	// colored texture gour triangle 
+	GsUCF4		= $00000012;	// colored flat quad 
+	GsUCFT4		= $00000013;	// colored texture flat quad 
+	GsUCG4		= $00000016;	// colored gour quad 
+	GsUCGT4		= $00000017;	// colored texture gour quad 
+
+	GsUNF3		= $00040048;	// nonLight flat triangle 
+	GsUNFT3		= $00040049;	// nonLight texture flat triangle 
+	GsUNG3		= $0004004c;	// nonLight gouraud triangle 
+	GsUNGT3		= $0004004d;	// nonLight texture gouraud triangle 
+	GsUNF4		= $00040050;	// nonLight flat quad 
+	GsUNFT4		= $00040051;	// nonLight texture flat quad 
+	GsUNG4		= $00040054;	// nonLight gouraud quad 
+	GsUNGT4		= $00040055;	// nonLight texture gouraud quad 
+
+	GsUDF3		= $00010008;	// div flat triangle 
+	GsUDFT3		= $00010009;	// div texture flat triangle 
+	GsUDG3		= $0001000c;	// div gour triangle 
+	GsUDGT3		= $0001000d;	// div texture gour triangle 
+	GsUDF4		= $00010010;	// div flat quad 
+	GsUDFT4		= $00010011;	// div texture flat quad 
+	GsUDG4		= $00010014;	// div gour quad 
+	GsUDGT4		= $00010015;	// div texture gour quad 
+
+	GsUDFF3		= $00030008;	// div fog flat triangle 
+	GsUDFFT3	= $00030009;	// div fog texture flat triangle 
+	GsUDFG3		= $0003000c;	// div fog gour triangle 
+	GsUDFGT3	= $0003000d;	// div fog texture gour triangle 
+	GsUDFF4		= $00030010;	// div fog flat quad 
+	GsUDFFT4	= $00030011;	// div fog texture flat quad 
+	GsUDFG4		= $00030014;	// div fog gour quad 
+	GsUDFGT4	= $00030015;	// div fog texture gour quad 
+
+	GsUDNF3		= $00050048;	// div nonLight flat triangle 
+	GsUDNFT3	= $00050049;	// div nonLight texture flat triangle 
+	GsUDNG3		= $0005004c;	// div nonLight gouraud triangle 
+	GsUDNGT3	= $0005004d;	// div nonLight tex gouraud triangle 
+	GsUDNF4		= $00050050;	// div nonLight flat quad 
+	GsUDNFT4	= $00050051;	// div nonLight texture flat quad 
+	GsUDNG4		= $00050054;	// div nonLight gouraud quad 
+	GsUDNGT4	= $00050055;	// div nonLight tex gouraud quad 
+
+	GsUSCAL		= $01000000;	// shared calculate vertex and normal 
+	GsUSG3		= $0100000c;	// shared gour triangle 
+	GsUSGT3		= $0100000d;	// shared texture gour triangle 
+	GsUSG4		= $01000014;	// shared gour quad 
+	GsUSGT4		= $01000015;	// shared texture gour quad 
+
+	GsUSTGT3	= $0100020d;	// shared tile texture gour triangle 
+	GsUSTGT4	= $01000215;	// shared tile texture gour quad 
+
+	GsUSFG3		= $0102000c;	// shared fog gour triangle 
+	GsUSFGT3	= $0102000d;	// shared fog texture gour triangle 
+	GsUSFG4		= $01020014;	// shared fog gour quad 
+	GsUSFGT4	= $01020015;	// shared fog texture gour quad 
+
+	GsUSNF3		= $01040048;	// shared nonLight flat tri 
+	GsUSNFT3	= $01040049;	// shared nonLight texture flat tri 
+	GsUSNG3		= $0104004c;	// shared nonLight gour tri 
+	GsUSNGT3	= $0104004d;	// shared nonLight texture gour tri 
+	GsUSNF4		= $01040050;	// shared nonLight flat quad 
+	GsUSNFT4	= $01040051;	// shared nonLight texture flat quad 
+	GsUSNG4		= $01040054;	// shared nonLight gour quad 
+	GsUSNGT4	= $01040055;	// shared nonLight texture gour quad 
+
+	GsUMF3		= $00000018;	// mesh flat tri 
+	GsUMFT3		= $00000019;	// mesh texture flat tri 
+	GsUMG3		= $0000001c;	// mesh gour triangle 
+	GsUMGT3		= $0000001d;	// mesh texture gour triangle 
+	GsUMNF3		= $00040058;	// mesh nonLight flat tri 
+	GsUMNFT3	= $00040059;	// mesh nonLight tex flat tri 
+	GsUMNG3		= $0004005c;	// mesh nonLight gour triangle 
+	GsUMNGT3	= $0004005d;	// mesh nonLight tex gour tri 
+
+	GsUTFT3		= $00000209;	// tile texture flat triangle 
+	GsUTGT3		= $0000020d;	// tile texture gour triangle 
+	GsUTFT4		= $00000211;	// tile texture flat quad 
+	GsUTGT4		= $00000215;	// tile texture gour quad 
+
+	GsUPNF3		= $00040148;	// preset nonLight flat triangle 
+	GsUPNFT3	= $00040149;	// preset nonLight tex flat triangle 
+	GsUPNG3		= $0004014c;	// preset nonLight gouraud triangle 
+	GsUPNGT3	= $0004014d;	// preset nonLight tex gour triangle 
+	GsUPNF4		= $00040150;	// preset nonLight flat quad 
+	GsUPNFT4	= $00040151;	// preset nonLight tex flat quad 
+	GsUPNG4		= $00040154;	// preset nonLight gouraud quad 
+	GsUPNGT4	= $00040155;	// preset nonLight tex gour quad 
+
+	GsUSTPF3	= $00200008;	// semi-trans flat triangle 
+	GsUSTPFT3	= $00200009;	// semi-trans texture flat triangle 
+	GsUSTPG3	= $0020000c;	// semi-trans gour triangle 
+	GsUSTPGT3	= $0020000d;	// semi-trans texture gour triangle 
+	GsUSTPF4	= $00200010;	// semi-trans flat quad 
+	GsUSTPFT4	= $00200011;	// semi-trans texture flat quad 
+	GsUSTPG4	= $00200014;	// semi-trans gour quad 
+	GsUSTPGT4	= $00200015;	// semi-trans texture gour quad 
+	GsUSTPSG3	= $0120000c;	// semi-trans shared gour tri 
+	GsUSTPSGT3	= $0120000d;	// semi-trans shared tex gour tri 
+	GsUSTPSG4	= $01200014;	// semi-trans shared gour quad 
+	GsUSTPSGT4	= $01200015;	// semi-trans shared tex gour quad 
+
+	GsUSTPNF3	= $00240048;	// semi-trans nonLight flat tri 
+	GsUSTPNFT3	= $00240049;	// semi-trans nonLight tex flat tri 
+	GsUSTPNG3	= $0024004c;	// semi-trans nonLight gour tri 
+	GsUSTPNGT3	= $0024004d;	// semi-trans nonLight tex gour tri 
+	GsUSTPNF4	= $00240050;	// semi-trans nonLight flat quad 
+	GsUSTPNFT4	= $00240051;	// semi-trans nonLight tex flat quad 
+	GsUSTPNG4	= $00240054;	// semi-trans nonLight gour quad 
+	GsUSTPNGT4	= $00240055;	// semi-trans nonLight tex gour quad 
+
+	GsUSTPSNF3	= $01240048;	// stp shared nonLight flat tri 
+	GsUSTPSNFT3	= $01240049;	// stp shared nonLight tex flat tri 
+	GsUSTPSNG3	= $0124004c;	// stp shared nonLight gour tri 
+	GsUSTPSNGT3	= $0124004d;	// stp shared nonLight tex gour tri 
+	GsUSTPSNF4	= $01240050;	// stp shared nonLight flat quad 
+	GsUSTPSNFT4	= $01240051;	// stp shared nonLight tex flat quad 
+	GsUSTPSNG4	= $01240054;	// stp shared nonLight gour quad 
+	GsUSTPSNGT4	= $01240055;	// stp shared nonLight tex gour quad 
+
+	GsUADF3		= $00080008;	// active-div flat triangle 
+	GsUADFT3	= $00080009;	// active-div texture flat triangle 
+	GsUADG3		= $0008000c;	// active-div gour triangle 
+	GsUADGT3	= $0008000d;	// active-div texture gour triangle 
+	GsUADF4		= $00080010;	// active-div flat quad 
+	GsUADFT4	= $00080011;	// active-div texture flat quad 
+	GsUADG4		= $00080014;	// active-div gour quad 
+	GsUADGT4	= $00080015;	// active-div texture gour quad 
+
+	GsUADFF3	= $000a0008;	// active-div fog flat tri 
+	GsUADFFT3	= $000a0009;	// active-div fog texture flat tri 
+	GsUADFG3	= $000a000c;	// active-div fog gour tri 
+	GsUADFGT3	= $000a000d;	// active-div fog texture gour tri 
+	GsUADFF4	= $000a0010;	// active-div fog flat quad 
+	GsUADFFT4	= $000a0011;	// active-div fog texture flat quad 
+	GsUADFG4	= $000a0014;	// active-div fog gour quad 
+	GsUADFGT4	= $000a0015;	// active-div fog texture gour quad 
+
+	GsUADNF3	= $000c0048;	// active-div nonLight flat tri 
+	GsUADNFT3	= $000c0049;	// active-div nonLight tex flat tri 
+	GsUADNG3	= $000c004c;	// active-div nonLight gour tri 
+	GsUADNGT3	= $000c004d;	// active-div nonLight tex gour tri 
+	GsUADNF4	= $000c0050;	// active-div nonLight flat quad 
+	GsUADNFT4	= $000c0051;	// active-div nonLight tex flat quad 
+	GsUADNG4	= $000c0054;	// active-div nonLight gour quad 
+	GsUADNGT4	= $000c0055;	// active-div nonLight tex gour quad 
+
+	GsUBF3		= $00100008;	// back-f flat tri 
+	GsUBFT3		= $00100009;	// back-f tex flat tri 
+	GsUBG3		= $0010000c;	// back-f gour tri 
+	GsUBGT3		= $0010000d;	// back-f tex gour tri 
+	GsUBF4		= $00100010;	// back-f flat quad 
+	GsUBFT4		= $00100011;	// back-f tex flat quad 
+	GsUBG4		= $00100014;	// back-f gour quad 
+	GsUBGT4		= $00100015;	// back-f tex gour quad 
+
+	GsUBCF3		= $0010000a;	// back-f colored flat tri 
+	GsUBCFT3	= $0010000b;	// back-f colored tex flat tri 
+	GsUBCG3		= $0010000e;	// back-f colored gour tri 
+	GsUBCGT3	= $0010000f;	// back-f colored tex gour tri 
+	GsUBCF4		= $00100012;	// back-f colored flat quad 
+	GsUBCFT4	= $00100013;	// back-f colored tex flat quad 
+	GsUBCG4		= $00100016;	// back-f colored gour quad 
+	GsUBCGT4	= $00100017;	// back-f colored tex gour quad 
+
+	GsUBSTPF3	= $00300008;	// back-f semi-trans flat tri 
+	GsUBSTPFT3	= $00300009;	// back-f semi-trans tex flat tri 
+	GsUBSTPG3	= $0030000c;	// back-f semi-trans gour tri 
+	GsUBSTPGT3	= $0030000d;	// back-f semi-trans tex gour tri 
+	GsUBSTPF4	= $00300010;	// back-f semi-trans flat quad 
+	GsUBSTPFT4	= $00300011;	// back-f semi-trans tex flat quad 
+	GsUBSTPG4	= $00300014;	// back-f semi-trans gour quad 
+	GsUBSTPGT4	= $00300015;	// back-f semi-trans tex gour quad 
+
+	GsUBNF3		= $00140048;	// back-f noLgt flat tri 
+	GsUBNFT3	= $00140049;	// back-f noLgt tex flat tri 
+	GsUBNG3		= $0014004c;	// back-f noLgt gouraud tri 
+	GsUBNGT3	= $0014004d;	// back-f noLgt tex gouraud tri 
+	GsUBNF4		= $00140050;	// back-f noLgt flat quad 
+	GsUBNFT4	= $00140051;	// back-f noLgt tex flat quad 
+	GsUBNG4		= $00140054;	// back-f noLgt gouraud quad 
+	GsUBNGT4	= $00140055;	// back-f noLgt tex gouraud quad 
+
+	GsUBSTPNF3	= $00340048;	// back-f stp noLgt flat tri 
+	GsUBSTPNFT3	= $00340049;	// back-f stp noLgt tex flat tri 
+	GsUBSTPNG3	= $0034004c;	// back-f stp noLgt gour tri 
+	GsUBSTPNGT3	= $0034004d;	// back-f stp noLgt tex gour tri 
+	GsUBSTPNF4	= $00340050;	// back-f stp noLgt flat quad 
+	GsUBSTPNFT4	= $00340051;	// back-f stp noLgt tex flat quad 
+	GsUBSTPNG4	= $00340054;	// back-f stp noLgt gour quad 
+	GsUBSTPNGT4	= $00340055;	// back-f stp noLgt tex gour quad 
+
+	GsUBSNF3	= $01140048;	// back-f shrd noLgt flat tri 
+	GsUBSNFT3	= $01140049;	// back-f shrd noLgt tex flat tri 
+	GsUBSNG3	= $0114004c;	// back-f shrd noLgt gour tri 
+	GsUBSNGT3	= $0114004d;	// back-f shrd noLgt tex gour tri 
+	GsUBSNF4	= $01140050;	// back-f shrd noLgt flat quad 
+	GsUBSNFT4	= $01140051;	// back-f shrd noLgt tex flat quad 
+	GsUBSNG4	= $01140054;	// back-f shrd noLgt gour quad 
+	GsUBSNGT4	= $01140055;	// back-f shrd noLgt tex gour quad 
+
+	GsUBSTPSNF3		= $01340048;	// back-f stp shrd noLgt flat tri 
+	GsUBSTPSNFT3	= $01340049;	// back-f stp shrd noLgt tex flat tri 
+	GsUBSTPSNG3		= $0134004c;	// back-f stp shrd noLgt gour tri 
+	GsUBSTPSNGT3	= $0134004d;	// back-f stp shrd noLgt tex gour tri 
+	GsUBSTPSNF4		= $01340050;	// back-f stp shrd noLgt flat quad 
+	GsUBSTPSNFT4	= $01340051;	// back-f stp shrd noLgt tex flat quad
+	GsUBSTPSNG4		= $01340054;	// back-f stp shrd noLgt gour quad 
+	GsUBSTPSNGT4	= $01340055;	// back-f stp shrd noLgt tex gour quad
+
+	GsUIMG0		= $02000000;	// image data with no-clut 
+	GsUIMG1		= $02000001;	// image data with clut 
+
+	GsUGNDF		= $05000000;	// ground flat 
+	GsUGNDFT	= $05000001;	// ground flat texture 
+
+	GsUSCAL2	= $06000100;	// envmap shared calculate 
+	GsUE1G3		= $0600100c;	// envmap 1D gour tri 
+	GsUE1G4		= $06001014;	// envmap 1D gour quad 
+	GsUE1SG3	= $0600110c;	// envmap 1D shared gour tri 
+	GsUE1SG4	= $06001114;	// envmap 1D shared gour quad 
+	GsUE2LG3	= $0600200c;	// envmap 2D reflect gour tri 
+	GsUE2LG4	= $06002014;	// envmap 2D reflect gour quad 
+	GsUE2RG3	= $0600300c;	// envmap 2D refract gour tri 
+	GsUE2RG4	= $06003014;	// envmap 2D refract gour quad 
+	GsUE2RLG3	= $0600400c;	// envmap 2D both gour tri 
+	GsUE2RLG4	= $06004014;	// envmap 2D both gour quad 
+	GsUE2OLG3	= $0600500c;	// envmap 2D org+reflect gour tri 
+	GsUE2OLG4	= $06005014;	// envmap 2D org+reflect gour quad 
+
+	GsVtxMIMe		 = $04010020;	// Vertex-MIMe 
+	GsNrmMIMe		 = $04010021;	// Normal-MIMe 
+	GsRstVtxMIMe	 = $04010028;	// Reset-Vertex-MIMe 
+	GsRstNrmMIMe	 = $04010029;	// Reset-Normal-MIMe 
+	GsJntAxesMIMe	 = $04010010;	// Joint-Axes-MIMe
+	GsRstJntAxesMIMe = $04010018;	// Reset-Joint-Axes-MIMe
+	GsJntRPYMIMe	 = $04010011;	// Joint-RPY-MIMe
+	GsRstJntRPYMIMe	 = $04010019;	// Reset-Joint-RPY-MIMe
+
+
+
+
+
+	function GsU_00000008(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000009(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000010(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000020(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000011(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000014(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000015(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020008(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020009(arg: PGsARGUNIT): pdword; external;
+	function GsU_0002000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0002000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020010(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020011(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020014(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020015(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000000a(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000000b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000000e(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000000f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000012(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000013(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000016(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000017(arg: PGsARGUNIT): pdword; external;
+	function GsU_00030008(arg: PGsARGUNIT): pdword; external;
+	function GsU_00030009(arg: PGsARGUNIT): pdword; external;
+	function GsU_0003000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0003000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00030010(arg: PGsARGUNIT): pdword; external;
+	function GsU_00030011(arg: PGsARGUNIT): pdword; external;
+	function GsU_00030014(arg: PGsARGUNIT): pdword; external;
+	function GsU_00030015(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040048(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040049(arg: PGsARGUNIT): pdword; external;
+	function GsU_0004004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0004004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040050(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040051(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040054(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040055(arg: PGsARGUNIT): pdword; external;
+	function GsU_00010008(arg: PGsARGUNIT): pdword; external;
+	function GsU_00010009(arg: PGsARGUNIT): pdword; external;
+	function GsU_0001000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0001000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00010010(arg: PGsARGUNIT): pdword; external;
+	function GsU_00010011(arg: PGsARGUNIT): pdword; external;
+	function GsU_00010014(arg: PGsARGUNIT): pdword; external;
+	function GsU_00010015(arg: PGsARGUNIT): pdword; external;
+	function GsU_00050048(arg: PGsARGUNIT): pdword; external;
+	function GsU_00050049(arg: PGsARGUNIT): pdword; external;
+	function GsU_0005004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0005004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00050050(arg: PGsARGUNIT): pdword; external;
+	function GsU_00050051(arg: PGsARGUNIT): pdword; external;
+	function GsU_00050054(arg: PGsARGUNIT): pdword; external;
+	function GsU_00050055(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040058(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040059(arg: PGsARGUNIT): pdword; external;
+	function GsU_0004005c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0004005d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01000000(arg: PGsARGUNIT): pdword; external;
+	function GsU_0100000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0100000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01000014(arg: PGsARGUNIT): pdword; external;
+	function GsU_01000015(arg: PGsARGUNIT): pdword; external;
+	function GsU_0102000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0102000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01020014(arg: PGsARGUNIT): pdword; external;
+	function GsU_01020015(arg: PGsARGUNIT): pdword; external;
+	function GsU_01040048(arg: PGsARGUNIT): pdword; external;
+	function GsU_01040049(arg: PGsARGUNIT): pdword; external;
+	function GsU_0104004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0104004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01040050(arg: PGsARGUNIT): pdword; external;
+	function GsU_01040051(arg: PGsARGUNIT): pdword; external;
+	function GsU_01040054(arg: PGsARGUNIT): pdword; external;
+	function GsU_01040055(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000018(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000019(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000001c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000001d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000209(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000020d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000211(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000215(arg: PGsARGUNIT): pdword; external;
+	function GsU_02000000(arg: PGsARGUNIT): pdword; external;
+	function GsU_02000001(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040148(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040149(arg: PGsARGUNIT): pdword; external;
+	function GsU_0004014c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0004014d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040150(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040151(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040154(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040155(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200008(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200009(arg: PGsARGUNIT): pdword; external;
+	function GsU_0020000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0020000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200010(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200011(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200014(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200015(arg: PGsARGUNIT): pdword; external;
+	function GsU_0120000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0120000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01200014(arg: PGsARGUNIT): pdword; external;
+	function GsU_01200015(arg: PGsARGUNIT): pdword; external;
+	function GsU_00240048(arg: PGsARGUNIT): pdword; external;
+	function GsU_00240049(arg: PGsARGUNIT): pdword; external;
+	function GsU_0024004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0024004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00240050(arg: PGsARGUNIT): pdword; external;
+	function GsU_00240051(arg: PGsARGUNIT): pdword; external;
+	function GsU_00240054(arg: PGsARGUNIT): pdword; external;
+	function GsU_00240055(arg: PGsARGUNIT): pdword; external;
+	function GsU_01240048(arg: PGsARGUNIT): pdword; external;
+	function GsU_01240049(arg: PGsARGUNIT): pdword; external;
+	function GsU_0124004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0124004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01240050(arg: PGsARGUNIT): pdword; external;
+	function GsU_01240051(arg: PGsARGUNIT): pdword; external;
+	function GsU_01240054(arg: PGsARGUNIT): pdword; external;
+	function GsU_01240055(arg: PGsARGUNIT): pdword; external;
+	function GsU_00080008(arg: PGsARGUNIT): pdword; external;
+	function GsU_00080009(arg: PGsARGUNIT): pdword; external;
+	function GsU_0008000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0008000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00080010(arg: PGsARGUNIT): pdword; external;
+	function GsU_00080011(arg: PGsARGUNIT): pdword; external;
+	function GsU_00080014(arg: PGsARGUNIT): pdword; external;
+	function GsU_00080015(arg: PGsARGUNIT): pdword; external;
+	function GsU_000a0008(arg: PGsARGUNIT): pdword; external;
+	function GsU_000a0009(arg: PGsARGUNIT): pdword; external;
+	function GsU_000a000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_000a000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_000a0010(arg: PGsARGUNIT): pdword; external;
+	function GsU_000a0011(arg: PGsARGUNIT): pdword; external;
+	function GsU_000a0014(arg: PGsARGUNIT): pdword; external;
+	function GsU_000a0015(arg: PGsARGUNIT): pdword; external;
+	function GsU_000c0048(arg: PGsARGUNIT): pdword; external;
+	function GsU_000c0049(arg: PGsARGUNIT): pdword; external;
+	function GsU_000c004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_000c004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_000c0050(arg: PGsARGUNIT): pdword; external;
+	function GsU_000c0051(arg: PGsARGUNIT): pdword; external;
+	function GsU_000c0054(arg: PGsARGUNIT): pdword; external;
+	function GsU_000c0055(arg: PGsARGUNIT): pdword; external;
+	function GsU_0100020d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01000215(arg: PGsARGUNIT): pdword; external;
+
+	function GsU_00100008(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100009(arg: PGsARGUNIT): pdword; external;
+	function GsU_0010000a(arg: PGsARGUNIT): pdword; external;
+	function GsU_0010000b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0010000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0010000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_0010000e(arg: PGsARGUNIT): pdword; external;
+	function GsU_0010000f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100010(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100011(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100012(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100013(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100014(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100015(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100016(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100017(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300008(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300009(arg: PGsARGUNIT): pdword; external;
+	function GsU_0030000c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0030000d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300010(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300011(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300014(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300015(arg: PGsARGUNIT): pdword; external;
+	function GsU_00140048(arg: PGsARGUNIT): pdword; external;
+	function GsU_00140049(arg: PGsARGUNIT): pdword; external;
+	function GsU_0014004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0014004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00140050(arg: PGsARGUNIT): pdword; external;
+	function GsU_00140051(arg: PGsARGUNIT): pdword; external;
+	function GsU_00140054(arg: PGsARGUNIT): pdword; external;
+	function GsU_00140055(arg: PGsARGUNIT): pdword; external;
+	function GsU_00340048(arg: PGsARGUNIT): pdword; external;
+	function GsU_00340049(arg: PGsARGUNIT): pdword; external;
+	function GsU_0034004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0034004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00340050(arg: PGsARGUNIT): pdword; external;
+	function GsU_00340051(arg: PGsARGUNIT): pdword; external;
+	function GsU_00340054(arg: PGsARGUNIT): pdword; external;
+	function GsU_00340055(arg: PGsARGUNIT): pdword; external;
+	function GsU_01140048(arg: PGsARGUNIT): pdword; external;
+	function GsU_01140049(arg: PGsARGUNIT): pdword; external;
+	function GsU_0114004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0114004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01140050(arg: PGsARGUNIT): pdword; external;
+	function GsU_01140051(arg: PGsARGUNIT): pdword; external;
+	function GsU_01140054(arg: PGsARGUNIT): pdword; external;
+	function GsU_01140055(arg: PGsARGUNIT): pdword; external;
+	function GsU_01340048(arg: PGsARGUNIT): pdword; external;
+	function GsU_01340049(arg: PGsARGUNIT): pdword; external;
+	function GsU_0134004c(arg: PGsARGUNIT): pdword; external;
+	function GsU_0134004d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01340050(arg: PGsARGUNIT): pdword; external;
+	function GsU_01340051(arg: PGsARGUNIT): pdword; external;
+	function GsU_01340054(arg: PGsARGUNIT): pdword; external;
+	function GsU_01340055(arg: PGsARGUNIT): pdword; external;
+
+	function GsU_0020000a(arg: PGsARGUNIT): pdword; external;
+	function GsU_0020000b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0020000e(arg: PGsARGUNIT): pdword; external;
+	function GsU_0020000f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200012(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200013(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200016(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200017(arg: PGsARGUNIT): pdword; external;
+	function GsU_0030000a(arg: PGsARGUNIT): pdword; external;
+	function GsU_0030000b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0030000e(arg: PGsARGUNIT): pdword; external;
+	function GsU_0030000f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300012(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300013(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300016(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300017(arg: PGsARGUNIT): pdword; external;
+
+	function GsU_0100000e(arg: PGsARGUNIT): pdword; external;
+	function GsU_0100000f(arg: PGsARGUNIT): pdword; external;
+	function GsU_01000016(arg: PGsARGUNIT): pdword; external;
+	function GsU_01000017(arg: PGsARGUNIT): pdword; external;
+	function GsU_0120000e(arg: PGsARGUNIT): pdword; external;
+	function GsU_0120000f(arg: PGsARGUNIT): pdword; external;
+	function GsU_01200016(arg: PGsARGUNIT): pdword; external;
+	function GsU_01200017(arg: PGsARGUNIT): pdword; external;
+
+	function GsU_0002000a(arg: PGsARGUNIT): pdword; external;
+	function GsU_0002000b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0002000e(arg: PGsARGUNIT): pdword; external;
+	function GsU_0002000f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020012(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020013(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020016(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020017(arg: PGsARGUNIT): pdword; external;
+	function GsU_0102000e(arg: PGsARGUNIT): pdword; external;
+	function GsU_0102000f(arg: PGsARGUNIT): pdword; external;
+	function GsU_01020016(arg: PGsARGUNIT): pdword; external;
+	function GsU_01020017(arg: PGsARGUNIT): pdword; external;
+
+	// tiled texture 
+	function GsU_0000020b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0000020f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000213(arg: PGsARGUNIT): pdword; external;
+	function GsU_00000217(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020209(arg: PGsARGUNIT): pdword; external;
+	function GsU_0002020b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0002020d(arg: PGsARGUNIT): pdword; external;
+	function GsU_0002020f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020211(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020213(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020215(arg: PGsARGUNIT): pdword; external;
+	function GsU_00020217(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040249(arg: PGsARGUNIT): pdword; external;
+	function GsU_0004024d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040251(arg: PGsARGUNIT): pdword; external;
+	function GsU_00040255(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100209(arg: PGsARGUNIT): pdword; external;
+	function GsU_0010020b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0010020d(arg: PGsARGUNIT): pdword; external;
+	function GsU_0010020f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100211(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100213(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100215(arg: PGsARGUNIT): pdword; external;
+	function GsU_00100217(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200209(arg: PGsARGUNIT): pdword; external;
+	function GsU_0020020d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200211(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200215(arg: PGsARGUNIT): pdword; external;
+	function GsU_00240249(arg: PGsARGUNIT): pdword; external;
+	function GsU_0024024d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00240251(arg: PGsARGUNIT): pdword; external;
+	function GsU_00240255(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300209(arg: PGsARGUNIT): pdword; external;
+	function GsU_0030020d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300211(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300215(arg: PGsARGUNIT): pdword; external;
+	function GsU_0100020f(arg: PGsARGUNIT): pdword; external;
+	function GsU_01000217(arg: PGsARGUNIT): pdword; external;
+	function GsU_0102020d(arg: PGsARGUNIT): pdword; external;
+	function GsU_0102020f(arg: PGsARGUNIT): pdword; external;
+	function GsU_01020215(arg: PGsARGUNIT): pdword; external;
+	function GsU_01020217(arg: PGsARGUNIT): pdword; external;
+	function GsU_01040249(arg: PGsARGUNIT): pdword; external;
+	function GsU_0104024d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01040251(arg: PGsARGUNIT): pdword; external;
+	function GsU_01040255(arg: PGsARGUNIT): pdword; external;
+	function GsU_0120020d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01200215(arg: PGsARGUNIT): pdword; external;
+	function GsU_01240249(arg: PGsARGUNIT): pdword; external;
+	function GsU_0124024d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01240251(arg: PGsARGUNIT): pdword; external;
+	function GsU_01240255(arg: PGsARGUNIT): pdword; external;
+	function GsU_00140249(arg: PGsARGUNIT): pdword; external;
+	function GsU_0014024d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00140251(arg: PGsARGUNIT): pdword; external;
+	function GsU_00140255(arg: PGsARGUNIT): pdword; external;
+	function GsU_00340249(arg: PGsARGUNIT): pdword; external;
+	function GsU_0034024d(arg: PGsARGUNIT): pdword; external;
+	function GsU_00340251(arg: PGsARGUNIT): pdword; external;
+	function GsU_00340255(arg: PGsARGUNIT): pdword; external;
+	function GsU_01140249(arg: PGsARGUNIT): pdword; external;
+	function GsU_0114024d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01140251(arg: PGsARGUNIT): pdword; external;
+	function GsU_01140255(arg: PGsARGUNIT): pdword; external;
+	function GsU_01340249(arg: PGsARGUNIT): pdword; external;
+	function GsU_0134024d(arg: PGsARGUNIT): pdword; external;
+	function GsU_01340251(arg: PGsARGUNIT): pdword; external;
+	function GsU_01340255(arg: PGsARGUNIT): pdword; external;
+	function GsU_0020020b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0020020f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200213(arg: PGsARGUNIT): pdword; external;
+	function GsU_00200217(arg: PGsARGUNIT): pdword; external;
+	function GsU_0030020b(arg: PGsARGUNIT): pdword; external;
+	function GsU_0030020f(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300213(arg: PGsARGUNIT): pdword; external;
+	function GsU_00300217(arg: PGsARGUNIT): pdword; external;
+	function GsU_0120020f(arg: PGsARGUNIT): pdword; external;
+	function GsU_01200217(arg: PGsARGUNIT): pdword; external;
+
+	function GsU_00000000(arg: PGsARGUNIT): pdword; external;
+
+	function GsU_05000000(arg: PGsARGUNIT): pdword; external;
+	function GsU_05000001(arg: PGsARGUNIT): pdword; external;
+
+	// camera 
+	function GsU_07000100(arg: PGsARGUNIT): pdword; external;
+	function GsU_07010100(arg: PGsARGUNIT): pdword; external;
+	function GsU_07020100(arg: PGsARGUNIT): pdword; external;
+	function GsU_07030100(arg: PGsARGUNIT): pdword; external;
+
+	// light 
+	function GsU_07000200(arg: PGsARGUNIT): pdword; external;
+	function GsU_07010200(arg: PGsARGUNIT): pdword; external;
+	function GsU_07020200(arg: PGsARGUNIT): pdword; external;
+	function GsU_07030200(arg: PGsARGUNIT): pdword; external;
+	
+	// update driver 
+	function GsU_03000000(sp: PGsARGUNIT_ANIM): pdword; external;
+	
+	// interpolation driver 
+	function GsU_03000001(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000002(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000003(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000009(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300000a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300000b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000010(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000011(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000012(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000013(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000019(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300001a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300001b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000020(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000021(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000022(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000023(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000029(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300002a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300002b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000030(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000031(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000032(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000033(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000039(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300003a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300003b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000100(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000111(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000112(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000119(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300011a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000901(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000902(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000909(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300090a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000910(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000911(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000912(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03000919(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300091a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001010(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001011(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001012(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001013(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001019(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300101a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300101b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001020(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001021(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001022(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001023(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001029(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300102a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300102b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001030(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001031(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001032(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001033(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001039(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300103a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300103b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001111(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001112(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001119(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300111a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001910(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001911(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001912(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03001919(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300191a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002010(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002011(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002012(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002013(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002019(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300201a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300201b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002020(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002021(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002022(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002023(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002029(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300202a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300202b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002030(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002031(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002032(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002033(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002039(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300203a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300203b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002111(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002112(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002119(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300211a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002910(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002911(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002912(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03002919(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300291a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003010(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003011(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003012(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003013(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003019(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300301a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300301b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003020(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003021(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003022(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003023(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003029(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300302a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300302b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003030(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003031(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003032(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003033(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003039(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300303a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300303b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003111(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003112(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003119(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300311a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003910(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003911(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003912(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03003919(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300391a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004010(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004011(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004012(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004013(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004019(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300401a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300401b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004020(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004021(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004022(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004023(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004029(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300402a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300402b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004030(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004031(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004032(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004033(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004039(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300403a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300403b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004111(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004112(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004119(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300411a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004910(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004911(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004912(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03004919(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300491a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005010(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005011(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005012(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005013(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005019(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300501a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300501b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005020(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005021(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005022(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005023(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005029(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300502a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300502b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005030(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005031(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005032(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005033(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005039(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300503a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300503b(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005111(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005112(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005119(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300511a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005910(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005911(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005912(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03005919(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_0300591a(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010110(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010111(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010112(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010121(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010122(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010141(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010142(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010171(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010172(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010182(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010210(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010211(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010212(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010221(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010222(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010241(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010242(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010271(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010272(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010310(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010311(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010312(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010321(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010322(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010341(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010342(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010371(sp: PGsARGUNIT_ANIM): longint; external;
+	function GsU_03010372(sp: PGsARGUNIT_ANIM): longint; external;
+
+	// envmap driver 
+	function GsU_06000100(arg: PGsARGUNIT): longint; external;
+	function GsU_0600100c(arg: PGsARGUNIT): longint; external;
+	function GsU_06001014(arg: PGsARGUNIT): longint; external;
+	function GsU_0600110c(arg: PGsARGUNIT): longint; external;
+	function GsU_06001114(arg: PGsARGUNIT): longint; external;
+	function GsU_0600200c(arg: PGsARGUNIT): longint; external;
+	function GsU_06002014(arg: PGsARGUNIT): longint; external;
+	function GsU_0600300c(arg: PGsARGUNIT): longint; external;
+	function GsU_06003014(arg: PGsARGUNIT): longint; external;
+	function GsU_0600400c(arg: PGsARGUNIT): longint; external;
+	function GsU_06004014(arg: PGsARGUNIT): longint; external;
+	function GsU_0600500c(arg: PGsARGUNIT): longint; external;
+	function GsU_06005014(arg: PGsARGUNIT): longint; external;
+
+	// MIMe driver 
+	function GsU_04010020(arg: PGsARGUNIT): longint; external;
+	function GsU_04010021(arg: PGsARGUNIT): longint; external;
+	function GsU_04010028(arg: PGsARGUNIT): longint; external;
+	function GsU_04010029(arg: PGsARGUNIT): longint; external;
+	function GsU_04010010(arg: PGsARGUNIT): longint; external;
+	function GsU_04010018(arg: PGsARGUNIT): longint; external;
+	function GsU_04010011(arg: PGsARGUNIT): longint; external;
+	function GsU_04010019(arg: PGsARGUNIT): longint; external;
+
+
+	function GsMapCoordUnit(base, p: pdword): PGsCOORDUNIT; external;
+	function GsGetHeadpUnit: pdword; external;
+	function GsScanUnit(p: pdword; ut: PGsTYPEUNIT; ot: PGsOT; scratch: pdword): longint; external;
+	procedure GsMapUnit(p: pdword); external;
+	procedure GsSortUnit(objp: PGsUNIT; otp: PGsOT; scrathc: pdword); external;
+	procedure GsGetLwUnit(coord: PGsCOORDUNIT; m: PMATRIX); external;
+	procedure GsGetLsUnit(coord: PGsCOORDUNIT; m: PMATRIX); external;
+	procedure GsGetLwsUnit(coord: PGsCOORDUNIT; lw, ls: PMATRIX); external;
+	function GsSetViewUnit(pv: PGsVIEWUNIT): longint; external;
+	function GsSetRefViewUnit(pv: PGsRVIEWUNIT): longint; external;
+	function GsSetRefViewLUnit(pv: PGsRVIEWUNIT): longint; external;
+	function GsScanAnim(p: pdword; ut: PGsTYPEUNIT): pdword; external;
+	function GsLinkAnim(seq: PPGsSEQ; p: dword): longint; external;
+
+	// for MIMe 
+	procedure GsInitRstVtxMIMe(primtop, hp: pdword); external;
+	procedure GsInitRstNrmMIMe(primtop, hp: pdword); external;
+
+implementation
+
+begin
+end.

+ 0 - 25
rtl/ps1/psy-q-sdk/libmacro.pas

@@ -1,25 +0,0 @@
-{$MODE OBJFPC}
-{$L libgtemacro.o}
-unit libmacro; 
-interface
-
-procedure gte_ldv0(r0: pdword); stdcall; external;
-procedure gte_ldv1(r0: pdword); stdcall; external;
-procedure gte_ldv2(r0: pdword); stdcall; external;
-
-procedure gte_rtpt; stdcall; external;
-procedure gte_nclip; stdcall; external;
-procedure gte_stopz(r0: plongint); stdcall; external;
-
-procedure gte_stsxy0(r0: pdword); stdcall; external;
-procedure gte_stsxy3(r0, r1, r2: pdword); stdcall; external;
-
-procedure gte_avsz3; stdcall; external;
-procedure gte_avsz4; stdcall; external;
-
-procedure gte_stotz(r0: plongint); stdcall; external;
-
-
-implementation
-begin
-end.

+ 117 - 0
rtl/ps1/psy-q-sdk/libmcgui.pas

@@ -0,0 +1,117 @@
+unit libmcgui;
+interface
+const
+	NEGICON_A				= $20;
+	NEGICON_B				= $10;
+
+	MOUSE_LBUTTON			= $08;
+	MOUSE_RBUTTON			= $04;
+
+	MCGUI_INTERNAL_FONT		= 0;
+	MCGUI_EXTERNAL_FONT		= 1;
+
+type
+	
+// Texture Information Structure
+	sMcGuiTexture = packed record
+						addr : pointer;
+	end;
+
+
+// Memory Card Information Structure */
+	sMcGuiCards = packed record
+							_file : array [0..20] of char;
+							title : array [0..64] of char;
+							frame : byte;
+							block : byte;
+							dataBytes : longint;
+							iconAddr : pointer;
+							dataAddr : pointer;
+	end;
+
+// BG Information Structure
+	sMcGuiBg = packed record
+						mode : smallint;
+						scrollDirect : shortint;	// 0:Up 1:Up&Left 2:Left 3:Down&left 4:Down ...
+						scrollSpeed : shortint;		// 0:no scroll 1:1/60 2:1/30 3:1/20
+						timadr : pointer;
+	end;
+
+
+// Cursor Information Structure
+	sMcGuiCursor = packed record
+						mode : byte;
+						r, g, b : byte;
+	end;
+
+
+// BGM,Sound Effects Information Structure
+	Tbgm = packed record
+					isbgm : longint;
+					seq : pdword;
+					vh : pdword;
+					vb : pdword;
+					SVOL : longint;
+					isReverb : longint;
+					reverbType : longint;
+					reverbDepth : longint;
+	end;
+
+	Tse = packed record
+					isse : longint;
+					vh : pdword;
+					vb : pdword;
+					vol : longint;
+					prog : longint;
+					TONE_OK : longint;
+					TONE_CANCEL : longint;
+					TONE_CURSOR : longint;
+					TONE_ERROR : longint;
+	end;
+
+
+	sMcGuiSnd = packed record
+					MVOL : longint;
+					bgm : Tbgm;
+					se : Tse;
+	end;
+
+
+// Controller Related Information Structure
+
+	TType = packed record
+					flag : longint;
+					BUTTON_OK : dword;
+					BUTTON_CANCEL : dword;
+	end;
+
+	sMcGuiController = packed record
+								buf : array [0..1] of byte;
+								type1 : Ttype;
+								type2 : Ttype;
+								type3 : Ttype;
+								type4 : Ttype;
+	end;
+
+
+// Memory Card Screen Configuration Structure
+	McGuiEnv = packed record
+						cards : sMcGuiCards;			// Memory Card Information
+						bg : sMcGuiBg;					// BG Information
+						controller : sMcGuiController;	// Controller Related Information
+						sound : sMcGuiSnd;				// BGM Sound Effects Information
+						texture : sMcGuiTexture;		// Texture Information
+						cursor : sMcGuiCursor;			// Cursor Information
+	end;
+	PMcGuiEnv = ^McGuiEnv;
+
+
+function McGuiSave(env:PMcGuiEnv): longint; external;
+function McGuiLoad(env:PMcGuiEnv): longint; external;
+
+function McGuiSetExternalFont(env: PMcGuiEnv; mode: longint): longint; external;
+
+implementation
+
+begin
+end.

+ 48 - 0
rtl/ps1/psy-q-sdk/libmcrd.pas

@@ -0,0 +1,48 @@
+// libmcrd.h	Rev. 4.2
+unit libmcrd;
+interface
+uses libstd;
+type
+	MemCB = function(cmds, rslt: longint): pointer;
+const
+ 		McFuncExist			= 1;
+ 		McFuncAccept		= 2;
+ 		McFuncReadFile		= 3;
+ 		McFuncWriteFile		= 4;
+ 		McFuncReadData		= 5;
+ 		McFuncWriteData		= 6;
+
+		McErrNone			= 0;
+		McErrCardNotExist	= 1;
+		McErrCardInvalid	= 2;
+		McErrNewCard		= 3;
+		McErrNotFormat		= 4;
+		McErrFileNotExist	= 5;
+		McErrAlreadyExist	= 6;
+		McErrBlockFull		= 7;
+		McErrExtend			= $8000;
+
+
+procedure MemCardInit(val: longint); external;
+procedure MemCardEnd; external;
+procedure MemCardStart; external;
+procedure MemCardStop; external;
+function MemCardExist(chan: longint): longint; external;
+function MemCardAccept(chan: longint): longint; external;
+function MemCardOpen(chan: longint; filename: pchar; flag: longint): longint; external;
+procedure MemCardClose; external;
+function MemCardReadData(adrs: pdword; ofs: longint; bytes: longint): longint; external;
+function MemCardReadFile(chan: longint; filename: pchar; adrs: pdword; ofs: longint; bytes: longint): longint; external;
+function MemCardWriteData(adrs: pdword; ofs: longint; bytes: longint): longint; external;
+function MemCardWriteFile(chan: longint; filename: pchar; adrs: pdword; ofs: longint; bytes: longint): longint; external;
+function MemCardCreateFile(chan: longint; filename: pchar; blocks: longint): longint; external;
+function MemCardDeleteFile(chan: longint; filename: pchar): longint; external;
+function MemCardFormat(chan: longint): longint; external;
+function MemCardUnformat(chan: longint): longint; external;
+function MemCardSync(mode: longint; cmds: plongint; rslt: plongint): longint; external;
+function MemCardCallback(func: MemCB): MemCB; external;
+function MemCardGetDirentry(chan: longint; name: pchar; dir: PDIRENTRY; files: plongint; ofs: longint; max: longint): longint; external;
+
+implementation
+begin
+end.

+ 65 - 0
rtl/ps1/psy-q-sdk/libmcx.pas

@@ -0,0 +1,65 @@
+// libmcx.h
+unit libmcx;
+interface
+
+const
+	 McxFuncGetApl		= 1;
+	 McxFuncExecApl		= 2;
+	 McxFuncGetTime		= 3;
+	 McxFuncGetMem		= 4;
+	 McxFuncSetMem		= 5;
+	 McxFuncShowTrans	= 6;
+	 McxFuncHideTrans	= 7;
+	 McxFuncCurrCtrl	= 8;
+	 McxFuncSetLED		= 9;
+	 McxFuncGetSerial	= 10;
+	 McxFuncExecFlag	= 11;
+	 McxFuncAllInfo		= 12;
+	 McxFuncFlashAcs	= 13;
+	 McxFuncReadDev		= 14;
+	 McxFuncWriteDev	= 15;
+	 McxFuncGetUIFS		= 16;
+	 McxFuncSetUIFS		= 17;
+	 McxFuncSetTime		= 18;
+	 McxFuncCardType	= 19;
+
+
+	 McxSyncRun			= 0;
+	 McxSyncNone		= -1;
+	 McxSyncFin			= 1;
+
+	 McxErrSuccess		= 0;
+	 McxErrNoCard		= 1;
+	 McxErrInvalid		= 2;
+	 McxErrNewCard		= 3;
+
+
+
+procedure McxStartCom; external;
+procedure McxStopCom; external;
+function McxSync(mode: longint; cmd: plongint; res: plongint): longint; external;
+
+function McxGetApl(port: longint; aplno: plongint): longint; external;
+function McxExecApl(port: longint; aplno: longint; arg: longint): longint; external;
+function McxGetTime(port: longint; time: pointer): longint; external;
+function McxGetMem(port: longint; data: pointer; start, len: dword): longint; external;
+function McxSetMem(port: longint; data: pointer; start, len: dword): longint; external;
+function McxShowTrans(port, dir, timeout: longint): longint; external;
+function McxHideTrans(port: longint): longint; external;
+function McxCurrCtrl(port, sound, infred, led: longint): longint; external;
+function McxFlashAcs(port, mode: longint): longint; external;
+function McxGetSerial(port: longint; serial: pdword): longint; external;
+function McxSetLED(port, mode: longint): longint; external;
+function McxAllInfo(port: longint; state: pointer): longint; external;
+function McxExecFlag(port, block, exec: longint): longint; external;
+function McxReadDev(port, dev: longint; param, data: pointer): longint; external;
+function McxWriteDev(port, dev: longint; param, data: pointer): longint; external;
+function McxSetTime(port: longint; time: pointer): longint; external;
+function McxGetUIFS(port: longint; data: pointer): longint; external;
+function McxSetUIFS(port: longint; data: pointer): longint; external;
+function McxCardType(port: longint): longint; external;
+
+
+implementation
+begin
+end.

+ 47 - 0
rtl/ps1/psy-q-sdk/libpad.pas

@@ -0,0 +1,47 @@
+//	libpad.h
+unit libpad;
+interface
+const
+	 PadStateDiscon		= 0;
+	 PadStateFindPad	= 1;
+	 PadStateFindCTP1	= 2;
+	 PadStateFindCTP2	= 3;
+	 PadStateReqInfo	= 4;
+	 PadStateExecCmd	= 5;
+	 PadStateStable		= 6;
+
+	 InfoModeCurID		= 1;
+	 InfoModeCurExID	= 2;
+	 InfoModeCurExOffs	= 3;
+	 InfoModeIdTable	= 4;
+
+	 InfoActFunc		= 1;
+	 InfoActSub			= 2;
+	 InfoActSize		= 3;
+	 InfoActCurr		= 4;
+	 InfoActSign		= 5;
+
+	 PadMaxCurr			= 60;	// PS maximum current supply
+	 PadCurrCTP1		= 10;	// SCPH-1150 biblator current
+
+
+procedure PadInitDirect(pad1, pad2: pbyte); external;
+procedure PadInitMtap(pad1, pad2: pbyte); external;
+procedure PadInitGun(buf: pbyte; len: longint); external;
+function PadChkVsync: longint; external;
+procedure PadStartCom; external;
+procedure PadStopCom; external;
+function PadEnableCom(mode: dword): dword; external;
+procedure PadEnableGun(mask: byte); external;
+procedure PadRemoveGun; external;
+function PadGetState(port: longint): longint; external;
+function PadInfoMode(port, term, ofs: longint): longint; external;
+function PadInfoAct(port, actno, term: longint): longint; external;
+function PadInfoComb(port, listno, term: longint): longint; external;
+function PadSetActAlign(port: longint; data: pointer): longint; external;
+function PadSetMainMode(socket, offs, lock: longint): longint; external;
+procedure PadSetAct(port: longint; data: pointer; len: longint); external;
+
+implementation
+begin
+end.

+ 70 - 0
rtl/ps1/psy-q-sdk/libpress.pas

@@ -0,0 +1,70 @@
+// libpress.h
+unit libpress;
+interface
+type
+// DecDCTvlc Table
+    DECDCTTAB = array [0..34815] of word;
+
+    DECDCTENV = packed record
+	               iq_y : array [0..63] of byte;	   // IQ (Y): zig-zag order
+	               iq_c : array [0..63] of byte;	   // IQ (Cb,Cr): zig-zag order
+	               dct : array [0..63] of smallint;    // IDCT coef (reserved)
+    end;
+    PDECDCTENV = ^DECDCTENV;
+
+    ENCSPUENV = packed record
+                    src : psmallint;		  // 16-bit strait PCM
+                    dest : psmallint;		  // PlayStation original waveform data
+                    work : psmallint;		  // scratch pad or NULL
+                    size : longint;		      // size (unit: byte) of source data
+                    loop_start : longint;	  // loop start point (unit: byte) of source data
+                    loop : byte;		      // whether loop or not
+                    byte_swap : byte;		  // source data is 16-bit big endian (1) / little endian (0)
+                    proceed : byte;		      // proceeding ? whole (0) / start (1) / cont. (2) / end (4)
+                    quality : byte;		      // quality ? middle (0) / high (1)
+    end;
+    PENCSPUENV = ^ENCSPUENV;
+
+    DecDCTinCallbackFunc = procedure;
+
+const
+    ENCSPU_ENCODE_ERROR    = -1;
+    ENCSPU_ENCODE_WHOLE    = 0;
+    ENCSPU_ENCODE_START    = 1 shl 0;
+    ENCSPU_ENCODE_CONTINUE = 1 shl 1;
+    ENCSPU_ENCODE_END      = 1 shl 2;
+
+    ENCSPU_ENCODE_LOOP     = 1;
+    ENCSPU_ENCODE_NO_LOOP  = 0;
+
+    ENCSPU_ENCODE_ENDIAN_LITTLE = 0;
+    ENCSPU_ENCODE_ENDIAN_BIG    = 1;
+
+    ENCSPU_ENCODE_MIDDLE_QULITY = 0;
+    ENCSPU_ENCODE_HIGH_QULITY   = 1;
+
+
+procedure DecDCTReset(mode: longint); external;
+function DecDCTGetEnv(env: PDECDCTENV): PDECDCTENV; external;
+function DecDCTPutEnv(env: PDECDCTENV): PDECDCTENV; external;
+function DecDCTBufSize(bs: pdword): longint; external;
+function DecDCTvlc(bs: pdword; buf: pdword): longint; external;
+function DecDCTvlc2(bs: pdword; buf: pdword; table: DECDCTTAB): longint; external;
+function DecDCTvlcSize(size: longint): longint; external;
+function DecDCTvlcSize2(size: longint): longint; external;
+procedure DecDCTvlcBuild(table: pword); external;
+procedure DecDCTin(buf: pdword; mode: longint); external;
+procedure DecDCTout(buf: pdword; size: longint); external;
+function DecDCTinSync(mode: longint): longint; external;
+function DecDCToutSync(mode: longint): longint; external;
+
+function DecDCTinCallback(func: DecDCTinCallbackFunc): longint; external;
+function DecDCToutCallback(func: DecDCTinCallbackFunc): longint; external;
+
+function EncSPU (env: PENCSPUENV): longint; external;
+function EncSPU2(env: PENCSPUENV): longint; external;
+
+implementation
+
+begin
+end.

+ 101 - 0
rtl/ps1/psy-q-sdk/libsn.pas

@@ -0,0 +1,101 @@
+// LIBSN.H
+unit libsn;
+interface
+{
+** FILESERVER FUNCTIONS:
+**
+** NOTE: For PCread and PCwrite do not load files by passing extreme
+** values for count as you might on UNIX as this will cause the full
+** amount specified to be transferred - the file will be padded to
+** that length with zeroes which may over-write memory beyond the
+** end of the file.
+**
+** If you are unsure of the length of a file which you are about
+** to read into memory then perform a
+** 	len = PClseek( fd, 0, 2);
+** This will set len to the length of the file which you can then
+** pass to a PCread() function call.
+}
+
+{
+** re-initialise PC filing system, close open files etc
+**
+** passed: void
+**
+** return: error code (0 if no error)
+}
+function PCinit: longint; external;
+
+{
+** open a file on PC host
+**
+** passed:	PC file pathname, open mode, permission flags
+**
+** return:	file-handle or -1 if error
+**
+** note: perms should be zero (it is ignored)
+**
+** open mode:	0 => read only
+** 		1 => write only
+**		2 => read/write
+}
+function PCopen(name: pchar; flags, perms: longint): longint; external;
+
+{
+** create (and open) a file on PC host
+**
+** passed:	PC file pathname, open mode, permission flags
+**
+** return:	file-handle or -1 if error
+**
+** note: perms should be zero (it is ignored)
+}
+function PCcreat(name: pchar; perms: longint): longint; external;
+
+{
+** seek file pointer to new position in file
+**
+** passed: file-handle, seek offset, seek mode
+**
+** return: absolute value of new file pointer position
+**
+** (mode 0 = rel to start, mode 1 = rel to current fp, mode 2 = rel to end)
+}
+function PClseek(fd: longint; offset: longint; mode: longint): longint; external;
+
+{
+** read bytes from file on PC
+**
+** passed: file-handle, buffer address, count
+**
+** return: count of number of bytes actually read
+**
+** note: unlike assembler function this provides for full 32 bit count
+}
+function PCread(fd: longint; buff: pointer; len: longint): longint; external;
+
+{
+** write bytes to file on PC
+**
+** passed: file-handle, buffer address, count
+**
+** return: count of number of bytes actually written
+**
+** note: unlike assembler function this provides for full 32 bit count
+}
+function PCwrite(fd: longint; buff: pointer; len: longint): longint; external;
+
+{
+** close an open file on PC
+**
+** passed: file-handle
+**
+** return: negative if error
+**
+}
+function PCclose(fd: longint): longint; external;
+
+implementation
+
+begin
+end.

+ 634 - 33
rtl/ps1/psy-q-sdk/libstd.pas

@@ -1,3 +1,4 @@
+{$MODE OBJFPC}
 unit libstd;
 interface
 
@@ -74,8 +75,149 @@ var
 	errno : longint; external;
 
 
+// asm.h
+const
+	R0 = 0;
+	R1 = 1;
+	R2 = 2;
+	R3 = 3;
+	R4 = 4;
+	R5 = 5;
+	R6 = 6;
+	R7 = 7;
+	R8 = 8;
+	R9 = 9;
+	R10 = 10;
+	R11 = 11;
+	R12 = 12;
+	R13 = 13;
+	R14 = 14;
+	R15 = 15;
+	R16 = 16;
+	R17 = 17;
+	R18 = 18;
+	R19 = 19;
+	R20 = 20;
+	R21 = 21;
+	R22 = 22;
+	R23 = 23;
+	R24 = 24;
+	R25 = 25;
+	R26 = 26;
+	R27 = 27;
+	R28 = 28;
+	R29 = 29;
+	R30 = 30;
+	R31 = 31;
+
+	zero = 0;
+	AT = 1;		// assembler temp
+	v0 = 2;		// return value
+	v1 = 3;
+	a0 = 4;		// argument registers
+	a1 = 5;
+	a2 = 6;
+	a3 = 7;
+	t0 = 8;		// caller saved
+	t1 = 9;
+	t2 = 10;
+	t3 = 11;
+	t4 = 12;
+	t5 = 13;
+	t6 = 14;
+	t7 = 15;
+	s0 = 16;	// callee saved
+	s1 = 17;
+	s2 = 18;
+	s3 = 19;
+	s4 = 20;
+	s5 = 21;
+	s6 = 22;
+	s7 = 23;
+	t8 = 24;	// code generator
+	t9 = 25;
+	k0 = 26;	// kernel temporary
+	k1 = 27;
+	gp = 28;	// global pointer
+	sp = 29;	// stack pointer
+	fp = 30; 	// frame pointer
+	ra = 31;	// return address
+
+	// register offset
+	R_R0 = 0;
+	R_R1 = 1;
+	R_R2 = 2;
+	R_R3 = 3;
+	R_R4 = 4;
+	R_R5 = 5;
+	R_R6 = 6;
+	R_R7 = 7;
+	R_R8 = 8;
+	R_R9 = 9;
+	R_R10 =	10;
+	R_R11 =	11;
+	R_R12 = 12;
+	R_R13 =	13;
+	R_R14 = 14;
+	R_R15 = 15;
+	R_R16 = 16;
+	R_R17 = 17;
+	R_R18 = 18;
+	R_R19 = 19;
+	R_R20 = 20;
+	R_R21 = 21;
+	R_R22 = 22;
+	R_R23 = 23;
+	R_R24 = 24;
+	R_R25 =	25;
+	R_R26 =	26;
+	R_R27 =	27;
+	R_R28 = 28;
+	R_R29 = 29;
+	R_R30 =	30;
+	R_R31 =	31;
+	R_EPC =	32;
+	R_MDHI=	33;
+	R_MDLO=	34;
+	R_SR  =	35;
+	R_CAUSE= 36;
+	NREGS =	40;
 
-
+	
+	// compiler defined bindings
+	R_ZERO = R_R0;
+	R_AT = R_R1;
+	R_V0 = R_R2;
+	R_V1 = R_R3;
+	R_A0 = R_R4;
+	R_A1 = R_R5;
+	R_A2 = R_R6;
+	R_A3 = R_R7;
+	R_T0 = R_R8;
+	R_T1 = R_R9;
+	R_T2 = R_R10;
+	R_T3 = R_R11;
+	R_T4 = R_R12;
+	R_T5 = R_R13;
+	R_T6 = R_R14;
+	R_T7 = R_R15;
+	R_S0 = R_R16;
+	R_S1 = R_R17;
+	R_S2 = R_R18;
+	R_S3 = R_R19;
+	R_S4 = R_R20;
+	R_S5 = R_R21;
+	R_S6 = R_R22;
+	R_S7 = R_R23;
+	R_T8 = R_R24;
+	R_T9 = R_R25;
+	R_K0 = R_R26;
+	R_K1 = R_R27;
+	R_GP = R_R28;
+	R_SP = R_R29;
+	R_FP = R_R30;
+	R_RA = R_R31;
+ 
 
 // types.h
 type
@@ -114,7 +256,7 @@ type
 				end;
 
 
-
+// kernel.h 	Rev. 3
 const
 	DescMask 	= $ff000000;
 	DescTH 		= DescMask;
@@ -189,7 +331,6 @@ const
 	TcbStUNUSED	= $1000;
 	TcbStACTIVE	= $4000;
 
-	NREGS		= 40;
 
 type
 
@@ -267,10 +408,11 @@ type
 	
 	
 
+// abs.h
+function abs(num: longint): longint; stdcall; external;
 
 
 
-//
 // Basic system types and major/minor device constructing/busting macros.
 function major(x: longint): dword; // major part of a device
 function minor(x: longint): longint; // minor part of a device
@@ -278,8 +420,6 @@ function makedev(x, y: longint): longint; // make a device number
 
 
 
-
-
 // memory.h
 function memcpy(dest: pointer; src: pointer; count: dword): pointer; stdcall external;
 function memmove(dest: pointer; const src: pointer; count: dword): pointer; stdcall external;
@@ -292,13 +432,12 @@ function bcmp(const s1: pointer; const s2: pointer; n: dword): longint; stdcall
 
 
 
-
 // malloc.h
-procedure InitHeap(p: pdword; l: dword); stdcall external;
-procedure free(p: pointer); stdcall external;
-function malloc(l: size_t): pointer; stdcall external;
-function calloc(nitems: size_t; l: size_t): pointer; stdcall external;
-function realloc(p: pointer; l: size_t): pointer; stdcall external;
+procedure InitHeap(p: pdword; l: dword); stdcall external;				// this doesn't work - use InitHeap2
+procedure free(p: pointer); stdcall external;							// this doesn't work - use free2
+function malloc(l: size_t): pointer; stdcall external;					// this doesn't work - use malloc2
+function calloc(nitems: size_t; l: size_t): pointer; stdcall external;	// this doesn't work - use calloc2
+function realloc(p: pointer; l: size_t): pointer; stdcall external;		// this doesn't work - use realloc2
 procedure InitHeap2(p: pdword; l: dword); stdcall external;
 procedure free2(p: pointer); stdcall external;
 function malloc2(l: size_t): pointer; stdcall external;
@@ -311,8 +450,6 @@ function calloc3(l1: size_t; l2: size_t): pointer; stdcall external;
 function realloc3(p: pointer; l: size_t): pointer; stdcall external;
 
 
-
-
 // strings.h
 const
 	LMAX = 256;
@@ -338,8 +475,6 @@ function strstr(const str1: pchar; const str2: pchar): pchar; stdcall; external;
 function strdup(p: pchar): pchar;
 
 
-
-
 // rand.h
 const 
 	RAND_MAX = 32767;
@@ -349,7 +484,6 @@ procedure srand(x: longint); stdcall; external;
 
 
 
-
 // stdlib.h
 type
 	Tcmp = function (const a: pointer; const b: pointer): longint;
@@ -360,7 +494,6 @@ procedure exit; stdcall; external;
 
 
 
-
 // stdio.h
 const
 	BUFSIZ = 1024;
@@ -381,13 +514,6 @@ procedure puts(const s: pchar); stdcall; external;
 
 
 
-
-// abs.h
-function abs(x: longint): longint; stdcall; external;
-
-
-
-
 // convert.h
 function atoi(const str: pchar): longint; stdcall; external;
 function atol(const str: pchar): longint; stdcall; external;
@@ -397,8 +523,7 @@ function labs(x: longint): longint; stdcall; external;
 
 
 
-
-//limits.h
+// limits.h
 const
 	CHAR_BIT = 8;
 	SCHAR_MIN = -128;
@@ -423,14 +548,11 @@ const
 
 
 
-
 // qsort.h
 procedure qsort(base: pointer; num: size_t; size: size_t; compar: pointer); stdcall; external;
 
 
 
-
-
 // ctype.h
 const
 	_U = $01;	// upper case letter
@@ -465,8 +587,6 @@ function toascii(ch: char): char;
 
 
 
-
-
 // ioctl.h
 function FIOCNBLOCK: longint;
 function FIOCSCAN: longint;    // scan for input
@@ -509,7 +629,6 @@ const
 
 
 
-
 // file.h
 const
 	// Flag for open()
@@ -523,11 +642,430 @@ const
 
 
 
+// fs.h
+// device table
+type
+
+	Tdevice_table = packed record
+		dt_string : pchar; 					// device name
+		dt_type : longint;					// device "type"
+		dt_bsize : longint;					// file system type
+		dt_desc : pchar;					// device description
+		dt_init : function(): plongint;		// device init routine
+		dt_open : function(): plongint;		// device open routine
+		dt_strategy : function(): plongint;	// device strategy routine, returns cnt
+		dt_close : function(): plongint;	// device close routine
+		dt_ioctl : function(): plongint;	// device ioctl routine
+		dt_read : function(): plongint;		// fs read routine, returns count
+		dt_write : function(): plongint;	// fs write routine, return count
+		dt_delete : function(): plongint;	// file delete routine
+		dt_undelete : function(): plongint;	// file delete routine
+		dt_firstfile : function(): plongint;// directory serach routine
+		dt_nextfile : function(): plongint;	// directory serach routine
+		dt_format : function(): plongint;
+		dt_cd : function(): plongint;	
+		dt_rename : function(): plongint;	
+		dt_remove : function(): plongint;	
+		dt_else : function(): plongint;
+	end;
+	Pdevice_table = ^Tdevice_table;
+
+// device types
+const
+	DTTYPE_CHAR	 = $1;	// character device
+	DTTYPE_CONS	 = $2;	// can be console
+	DTTYPE_BLOCK = $4;	// block device
+	DTTYPE_RAW	 = $8;	// raw device that uses fs switch
+	DTTYPE_FS	 = $10;
+
+
+// character device flags
+	DB_RAW = $1;			// don't interpret special chars
+	DB_STOPPED	= $2;		// stop output
+	DB_BREAK = $4;			// cntl-c raise console interrpt
+
+// character device buffer
+	CBUFSIZE = 256;
+
+type
+	device_buf = packed record
+		db_flags : longint;							// character device flags
+		db_in : pchar;								// pts at next free char
+		db_out : pchar;								// pts at next filled char
+		db_buf : array [0..CBUFSIZE - 1] of char;	// circular buffer for input
+	end;
+
+// circular buffer functions */
+{
+	CIRC_EMPTY(x)	((x)->db_in == (x)->db_out)
+	CIRC_FLUSH(x)	((x)->db_in = (x)->db_out = (x)->db_buf)
+	CIRC_STOPPED(x)	((x)->db_flags & DB_STOPPED)
+}
+
+// io block
+	iob = packed record
+		i_flgs : longint;
+		i_unit : longint;		// pseudo device unit
+		i_ma : pchar;			// memory address of i/o buffer
+		i_cc : dword;			// character count of transfer
+		i_offset : dword;		// seek offset in file
+		i_fstype : longint;		// file system type
+		i_errno : longint;		// error # return
+		i_dp : Pdevice_table;	// pointer into device_table
+	    i_size : dword;
+	    i_head : longint;
+	    i_fd : longint;			// file descriptor
+    end;
+
+// Request codes
+const
+	READ	 = 1;
+	WRITE	 = 2;
+
+	NIOB	 = 16;	// max number of open files
+
+
+
+// r3000.h
+// Segment base addresses and sizes
+	K0BASE = $80000000;
+	K0SIZE = $20000000;
+	K1BASE = $A0000000;
+	K1SIZE = $20000000;
+	K2BASE = $C0000000;
+	K2SIZE = $20000000;
+
+// Exception vectors
+	UT_VEC = K0BASE;							// utlbmiss vector
+	E_VEC  = K0BASE + $80;						// exception vector
+	R_VEC  = K1BASE + $1fc00000;				// reset vector
+
+// Address conversion macros
+function K0_TO_K1(x: dword): dword;				// kseg0 to kseg1
+function K1_TO_K0(x: dword): dword;				// kseg1 to kseg0
+function K0_TO_PHYS(x: dword): dword;			// kseg0 to physical
+function K1_TO_PHYS(x: dword): dword;			// kseg1 to physical
+function PHYS_TO_K0(x: dword): dword;			// physical to kseg0
+function PHYS_TO_K1(x: dword): dword;			// physical to kseg1
+
+// Address predicates
+function IS_KSEG0(x: dword): boolean;
+function IS_KSEG1(x: dword): boolean;
+//function IS_KSEG2(x: dword): boolean;
+//function IS_KPTESEG(x: dword): boolean;
+function IS_KUSEG(x: dword): boolean;
+
+
+const
+// Cache size constants
+	MINCACHE =	4 * 1024;
+	MAXCACHE =	64 * 1024;
+
+
+// Status register
+	SR_CUMASK =	$f0000000;					// coproc usable bits
+
+	SR_CU3    =	$80000000;					// Coprocessor 3 usable
+	SR_CU2    =	$40000000;					// Coprocessor 2 usable
+	SR_CU1	  =	$20000000;					// Coprocessor 1 usable
+	SR_CU0	  =	$10000000;					// Coprocessor 0 usable
+
+	SR_BEV	  =	$00400000;					// use boot exception vectors
+
+// Cache control bits
+	SR_TS	  =	$00200000;					// TLB shutdown
+	SR_PE	  =	$00100000;					// cache parity error
+	SR_CM	  =	$00080000;					// cache miss
+	SR_PZ	  =	$00040000;					// cache parity zero
+	SR_SWC	  =	$00020000;					// swap cache
+	SR_ISC	  =	$00010000;					// Isolate data cache
+
+ 	SR_MM_MODE = $00010000;					// lwl/swl/etc become scache/etc
+ {
+ define: 
+ lcache		lwl
+ scache		swl
+ flush		lwr $0,
+ inval		swr $0,
+}
+
+
+// Interrupt enable bits
+// (NOTE: bits set to 1 enable the corresponding level interrupt)
+	SR_IMASK	= $0000ff00;			// Interrupt mask
+	SR_IMASK8	= $00000000;			// mask level 8
+	SR_IMASK7	= $00008000;			// mask level 7
+	SR_IMASK6	= $0000c000;			// mask level 6
+	SR_IMASK5	= $0000e000;			// mask level 5
+	SR_IMASK4	= $0000f000;			// mask level 4
+	SR_IMASK3	= $0000f800;			// mask level 3
+	SR_IMASK2	= $0000fc00;			// mask level 2
+	SR_IMASK1	= $0000fe00;			// mask level 1
+	SR_IMASK0	= $0000ff00;			// mask level 0
+
+	SR_IBIT8	= $00008000;			// bit level 8
+	SR_IBIT7	= $00004000;			// bit level 7
+	SR_IBIT6	= $00002000;			// bit level 6
+	SR_IBIT5	= $00001000;			// bit level 5
+	SR_IBIT4	= $00000800;			// bit level 4
+	SR_IBIT3	= $00000400;			// bit level 3
+	SR_IBIT2	= $00000200;			// bit level 2
+	SR_IBIT1	= $00000100;			// bit level 1
+
+	SR_KUO		= $00000020;			// old kernel/user, 0 => k, 1 => u
+	SR_IEO		= $00000010;			// old interrupt enable, 1 => enable
+	SR_KUP		= $00000008;			// prev kernel/user, 0 => k, 1 => u
+	SR_IEP		= $00000004;			// prev interrupt enable, 1 => enable
+	SR_KUC		= $00000002;			// cur kernel/user, 0 => k, 1 => u
+	SR_IEC		= $00000001;			// cur interrupt enable, 1 => enable
+
+	SR_IMASKSHIFT	= 8;
+
+	SR_FMT		= '\20\40BD\26TS\25PE\24CM\23PZ\22SwC\21IsC\20IM7\17IM6\16IM5\15IM4\14IM3\13IM2\12IM1\11IM0\6KUo\5IEo\4KUp\3IEp\2KUc\1IEc';
+
+// Cause Register
+
+	CAUSE_BD		= $80000000;		// Branch delay slot */
+	CAUSE_CEMASK	= $30000000;		// coprocessor error */
+	CAUSE_CESHIFT	= 28;
+
+/// Interrupt pending bits
+	CAUSE_IP8	= $00008000;			// External level 8 pending
+	CAUSE_IP7	= $00004000;			// External level 7 pending
+	CAUSE_IP6	= $00002000;			// External level 6 pending
+	CAUSE_IP5	= $00001000;			// External level 5 pending
+	CAUSE_IP4	= $00000800;			// External level 4 pending
+	CAUSE_IP3	= $00000400;			// External level 3 pending
+	CAUSE_SW2	= $00000200;			// Software level 2 pending
+	CAUSE_SW1	= $00000100;			// Software level 1 pending
+
+	CAUSE_IPMASK	= $0000FF00;		// Pending interrupt mask
+	CAUSE_IPSHIFT	= 8;
+
+	CAUSE_EXCMASK	= $0000003C;		// Cause code bits
+	CAUSE_EXCSHIFT	= 2;
+
+	CAUSE_FMT		= '\20\40BD\36CE1\35CE0\20IP8\17IP7\16IP6\15IP5\14IP4\13IP3\12SW2\11SW1\1INT';
+
+
+// Cause register exception codes
+function EXC_CODE(x: dword): dword;
+
+const
+// Hardware exception codes
+	EXC_INT		= 0 shl 2;			// interrupt
+	EXC_MOD		= 1 shl 2;			// TLB mod
+	EXC_RMISS	= 2 shl 2;			// Read TLB Miss
+	EXC_WMISS	= 3 shl 2;			// Write TLB Miss
+	EXC_RADE	= 4 shl 2;			// Read Address Error
+	EXC_WADE	= 5 shl 2;			// Write Address Error
+	EXC_IBE		= 6 shl 2;			// Instruction Bus Error
+	EXC_DBE		= 7 shl 2;			// Data Bus Error
+	EXC_SYSCALL	= 8 shl 2;			// SYSCALL
+	EXC_BREAK	= 9 shl 2;			// BREAKpoint
+	EXC_II		= 10 shl 2;			// Illegal Instruction
+	EXC_CPU		= 11 shl 2;			// CoProcessor Unusable
+	EXC_OV		= 12 shl 2;			// OVerflow
+
+// software exception codes
+	SEXC_SEGV	= 16 shl 2;			// Software detected seg viol
+	SEXC_RESCHED= 17 shl 2;			// resched request
+	SEXC_PAGEIN	= 18 shl 2;			// page-in request
+	SEXC_CPU	= 19 shl 2;			// coprocessor unusable
+
+
+// Coprocessor 0 registers
+	C0_INX		= 0; 				// tlb index
+	C0_RAND 	= 1;				// tlb random
+	C0_TLBLO 	= 2;				// tlb entry low
+	C0_CTXT 	= 4;				// tlb context
+
+	C0_PIDMASK	= 6;				// Mips2
+
+	C0_BADVADDR = 8;			// bad virtual address
+
+	C0_TLBHI 	= 10;				// tlb entry hi
+	C0_PID		= 10;				// Mips2
+
+	C0_SR 		= 12;					// status register
+	C0_CAUSE 	= 13;				// exception cause
+	C0_EPC 		= 14;				// exception pc
+	C0_PRID 	= 15;				// revision identifier
+	C0_ERREG 	= 16;				// Mips2
+
+// Coprocessor 0 operations
+	C0_READI  	= $1;		// read ITLB entry addressed by C0_INDEX
+	C0_WRITEI 	= $2;		// write ITLB entry addressed by C0_INDEX
+	C0_WRITER 	= $6;		// write ITLB entry addressed by C0_RAND
+	C0_PROBE  	= $8;		// probe for ITLB entry addressed by TLBHI
+	C0_RFE	  	= $10;		// restore for exception
+
+// Flags for the nofault handler. 0 means no fault is expected.
+	NF_BADADDR	= 1;			// badaddr, wbadaddr
+	NF_COPYIO	= 2;			// copyin, copyout
+	NF_ADDUPC	= 3;			// addupc
+	NF_FSUMEM	= 4;			// fubyte, subyte, fuword, suword
+	NF_USERACC	= 5;			// useracc
+	NF_SOFTFP	= 6;			// softfp
+	NF_REVID	= 7;			// revision ids
+	NF_NENTRIES	= 8;
+
+// TLB size constants
+ 	TLBWIREDBASE    = 0;               					// WAG for now
+ 	NWIREDENTRIES   = 8;               					// WAG for now
+ 	TLBRANDOMBASE   = NWIREDENTRIES;
+ 	NTLBENTRIES     = 64;
+ 	NRANDOMENTRIES  = (NTLBENTRIES - NWIREDENTRIES);
+ 	              		
+
+ 	TLBRAND_RANDMASK   = $00003f00;
+	TLBRAND_RANDSHIFT  = 8;
+
+
+// Chip interrupt vector
+	NC0VECS		 = 8;
+
+
+
+// extern int (*c0vec_tbl[])();
+var
+	c0vec_tbl : array of function: longint; external;
+
+
+const
+ 	BRK_KERNEL 		 = $f1;
+ 	EXCEPT_NORM      = 1;
+ 	EXCEPT_UTLB      = 2;
+ 	EXCEPT_BRKPT   	 = 3;
+ 	EXCEPT_DB    	 = 4;
+ 	EXCEPT_GDB    	 = 4;
+	EXCEPT_INT    	 = 9;
+	EXCEPT_ELSE    	 = $ff;
+
+
+
+// setjmp.h
+// simple non-local-jump for single task environment
+// jmp_buf indices
+const
+	JB_PC = 0;
+	JB_SP = 1;
+	JB_FP = 2;
+	JB_S0 = 3;
+	JB_S1 = 4;
+	JB_S2 = 5;
+	JB_S3 = 6;
+	JB_S4 = 7;
+	JB_S5 = 8;
+	JB_S6 =	9;
+	JB_S7 =	10;
+	JB_GP =	11;
+	JB_SIZE = 12;
+
+type
+	jmp_buf = array [0..JB_SIZE - 1] of longint;
+
+function setjmp(buf: jmp_buf): longint; external;
+procedure longjmp(buf: jmp_buf; i: longint); external;
+
 
 
+// libsio.h
+// status bits
+const
+	SR_IRQ		= $200;
+ 	SR_CTS		= $100;
+ 	SR_DSR		= $80;
+ 	SR_FE		= $20;
+ 	SR_OE		= $10;
+ 	SR_PERROR	= $8;
+ 	SR_TXU		= $4;
+ 	SR_RXRDY	= $2;
+	SR_TXRDY	= $1;
+
+	SIO_CTS		= $100;
+	SIO_DSR		= $80;
+	SIO_FE		= $20;
+	SIO_OE		= $10;
+	SIO_PERROR	= $8;
+	SIO_TXU		= $4;
+	SIO_RXRDY	= $2;
+	SIO_TXRDY	= $1;
+
+
+	// control bits
+	CR_DSRIEN	= $1000;
+	CR_RXIEN	= $800;
+	CR_TXIEN	= $400;
+	CR_BUFSZ_1	= $0;
+	CR_BUFSZ_2	= $100;
+	CR_BUFSZ_4	= $200;
+	CR_BUFSZ_8	= $300;
+	CR_INTRST	= $40;
+	CR_RTS		= $20;
+	CR_ERRRST	= $10;
+	CR_BRK		= $8;
+	CR_RXEN		= $4;
+	CR_DTR		= $2;
+	CR_TXEN		= $1;
+
+	SIO_BIT_DTR	= CR_DTR;
+	SIO_BIT_RTS	= CR_RTS;
+
+	// mode bits
+	MR_SB_00	= $0;
+	MR_SB_01	= $40;
+	MR_SB_10	= $80;
+	MR_SB_11	= $C0;
+	MR_P_EVEN	= $20;
+	MR_PEN		= $10;
+	MR_CHLEN_5	= $0;
+	MR_CHLEN_6	= $4;
+	MR_CHLEN_7	= $8;
+	MR_CHLEN_8	= $C;
+	MR_BR_1		= $1;
+	MR_BR_16	= $2;
+	MR_BR_64	= $3;
+
+type
+		Sio1CallbackFunction = function: pointer;
+
+function AddSIO(baud: longint): longint; external;
+function DelSIO: longint; external;
+function _sio_control(cmd, arg, param: dword): longint; external;
+function Sio1Callback(func: Sio1CallbackFunction): longint; external;
+
+
+generic function __va_rounded_size<T>: SizeInt;
+generic procedure va_start<T>(out AP: Pointer; var LastArg: T);
+procedure va_end(out AP: Pointer);
+generic function va_arg<T>(var AP: Pointer):T;
 
 implementation
 
+generic function __va_rounded_size<T>: SizeInt;inline;
+begin
+  Result := ((sizeof(T) + sizeof (longint) - 1) div sizeof (longint)) * sizeof (longint);
+end;
+ 
+generic procedure va_start<T>(out AP: Pointer; var LastArg: T);inline;
+begin
+  AP := Pointer(@LastArg) + specialize __va_rounded_size<T>;
+end;
+ 
+procedure va_end(out AP: Pointer);inline;
+begin
+  AP := nil;
+end;
+ 
+generic function va_arg<T>(var AP: Pointer):T;inline;
+type
+  PT=^T;
+begin
+  Result := PT(AP)^;
+  Inc(AP, specialize __va_rounded_size<T>);
+end;
+
 
 function strdup(p: pchar): pchar;	
 begin
@@ -728,6 +1266,69 @@ begin
 end;
 
 
+// Address conversion macros
+function K0_TO_K1(x: dword): dword;	
+begin
+	result:= x or $A0000000;
+end;
+
+function K1_TO_K0(x: dword): dword;
+begin
+	result:= x and $9FFFFFFF;
+end;
+
+function K0_TO_PHYS(x: dword): dword;
+begin
+	result:= x and $1FFFFFFF;
+end;
+
+function K1_TO_PHYS(x: dword): dword;
+begin
+	result:= x and $1FFFFFFF;
+end;
+
+function PHYS_TO_K0(x: dword): dword;
+begin
+	result:= x or $80000000;
+end;
+
+function PHYS_TO_K1(x: dword): dword;
+begin
+	result:= x or $A0000000;
+end;
+
+// Address predicates
+function IS_KSEG0(x: dword): boolean;
+begin	
+	result:= ((x >= K0BASE) and (x < K1BASE));
+end;
+
+function IS_KSEG1(x: dword): boolean;
+begin
+	result:= ((x >= K1BASE) and (x < K2BASE));
+end;
+
+{
+function IS_KSEG2(x: dword): boolean;
+begin
+	result:= ((x >= K2BASE) and (x < KPTEBASE));
+end;
+
+function IS_KPTESEG(x: dword): boolean;
+begin
+	result:= (x >= KPTEBASE);
+end;
+}
+
+function IS_KUSEG(x: dword): boolean;
+begin
+	result:= (x < K0BASE);
+end;
+
+function EXC_CODE(x: dword): dword;
+begin
+	result:= x shl 2;
+end;
 
 begin
 end.

+ 13 - 0
rtl/ps1/psy-q-sdk/libtap.pas

@@ -0,0 +1,13 @@
+//  libtap.h: Multi Tap Interface
+unit libtap;
+interface
+
+procedure InitTAP(bufA: pbyte; lenA: longint; bufB: pbyte; lenB: longint); external;
+procedure StartTAP; external;
+procedure StopTAP; external;
+procedure EnableTAP; external;
+procedure DisableTAP; external;
+
+implementation
+begin
+end.

+ 0 - 296
rtl/ps1/psy-q-sdk/r3000.pas

@@ -1,296 +0,0 @@
-//
-// $PSLibId: Run-time Library Release 4.6$
-//
-{$MODE OBJFPC}
-unit r3000;
-interface
-const
-
-// Segment base addresses and sizes
-	K0BASE = $80000000;
-	K0SIZE = $20000000;
-	K1BASE = $A0000000;
-	K1SIZE = $20000000;
-	K2BASE = $C0000000;
-	K2SIZE = $20000000;
-
-// Exception vectors
-	UT_VEC = K0BASE;							// utlbmiss vector
-	E_VEC  = K0BASE + $80;						// exception vector
-	R_VEC  = K1BASE + $1fc00000;				// reset vector
-
-// Address conversion macros
-function K0_TO_K1(x: dword): dword;				// kseg0 to kseg1
-function K1_TO_K0(x: dword): dword;				// kseg1 to kseg0
-function K0_TO_PHYS(x: dword): dword;			// kseg0 to physical
-function K1_TO_PHYS(x: dword): dword;			// kseg1 to physical
-function PHYS_TO_K0(x: dword): dword;			// physical to kseg0
-function PHYS_TO_K1(x: dword): dword;			// physical to kseg1
-
-// Address predicates
-function IS_KSEG0(x: dword): boolean;
-function IS_KSEG1(x: dword): boolean;
-// function IS_KSEG2(x: dword): boolean;
-// function IS_KPTESEG(x: dword): boolean;
-function IS_KUSEG(x: dword): boolean;
-
-
-const
-// Cache size constants
-	MINCACHE =	4 * 1024;
-	MAXCACHE =	64 * 1024;
-
-
-// Status register
-	SR_CUMASK =	$f0000000;					// coproc usable bits
-
-	SR_CU3    =	$80000000;					// Coprocessor 3 usable
-	SR_CU2    =	$40000000;					// Coprocessor 2 usable
-	SR_CU1	  =	$20000000;					// Coprocessor 1 usable
-	SR_CU0	  =	$10000000;					// Coprocessor 0 usable
-
-	SR_BEV	  =	$00400000;					// use boot exception vectors
-
-// Cache control bits
-	SR_TS	  =	$00200000;					// TLB shutdown
-	SR_PE	  =	$00100000;					// cache parity error
-	SR_CM	  =	$00080000;					// cache miss
-	SR_PZ	  =	$00040000;					// cache parity zero
-	SR_SWC	  =	$00020000;					// swap cache
-	SR_ISC	  =	$00010000;					// Isolate data cache
-
- 	SR_MM_MODE = $00010000;					// lwl/swl/etc become scache/etc
- {
- define: 
- lcache		lwl
- scache		swl
- flush		lwr $0,
- inval		swr $0,
-}
-
-
-// Interrupt enable bits
-// (NOTE: bits set to 1 enable the corresponding level interrupt)
-	SR_IMASK	= $0000ff00;			// Interrupt mask
-	SR_IMASK8	= $00000000;			// mask level 8
-	SR_IMASK7	= $00008000;			// mask level 7
-	SR_IMASK6	= $0000c000;			// mask level 6
-	SR_IMASK5	= $0000e000;			// mask level 5
-	SR_IMASK4	= $0000f000;			// mask level 4
-	SR_IMASK3	= $0000f800;			// mask level 3
-	SR_IMASK2	= $0000fc00;			// mask level 2
-	SR_IMASK1	= $0000fe00;			// mask level 1
-	SR_IMASK0	= $0000ff00;			// mask level 0
-
-	SR_IBIT8	= $00008000;			// bit level 8
-	SR_IBIT7	= $00004000;			// bit level 7
-	SR_IBIT6	= $00002000;			// bit level 6
-	SR_IBIT5	= $00001000;			// bit level 5
-	SR_IBIT4	= $00000800;			// bit level 4
-	SR_IBIT3	= $00000400;			// bit level 3
-	SR_IBIT2	= $00000200;			// bit level 2
-	SR_IBIT1	= $00000100;			// bit level 1
-
-	SR_KUO		= $00000020;			// old kernel/user, 0 => k, 1 => u
-	SR_IEO		= $00000010;			// old interrupt enable, 1 => enable
-	SR_KUP		= $00000008;			// prev kernel/user, 0 => k, 1 => u
-	SR_IEP		= $00000004;			// prev interrupt enable, 1 => enable
-	SR_KUC		= $00000002;			// cur kernel/user, 0 => k, 1 => u
-	SR_IEC		= $00000001;			// cur interrupt enable, 1 => enable
-
-	SR_IMASKSHIFT	= 8;
-
-	SR_FMT		= '\20\40BD\26TS\25PE\24CM\23PZ\22SwC\21IsC\20IM7\17IM6\16IM5\15IM4\14IM3\13IM2\12IM1\11IM0\6KUo\5IEo\4KUp\3IEp\2KUc\1IEc';
-
-// Cause Register
-
-	CAUSE_BD		= $80000000;		// Branch delay slot */
-	CAUSE_CEMASK	= $30000000;		// coprocessor error */
-	CAUSE_CESHIFT	= 28;
-
-/// Interrupt pending bits
-	CAUSE_IP8	= $00008000;			// External level 8 pending
-	CAUSE_IP7	= $00004000;			// External level 7 pending
-	CAUSE_IP6	= $00002000;			// External level 6 pending
-	CAUSE_IP5	= $00001000;			// External level 5 pending
-	CAUSE_IP4	= $00000800;			// External level 4 pending
-	CAUSE_IP3	= $00000400;			// External level 3 pending
-	CAUSE_SW2	= $00000200;			// Software level 2 pending
-	CAUSE_SW1	= $00000100;			// Software level 1 pending
-
-	CAUSE_IPMASK	= $0000FF00;		// Pending interrupt mask
-	CAUSE_IPSHIFT	= 8;
-
-	CAUSE_EXCMASK	= $0000003C;		// Cause code bits
-	CAUSE_EXCSHIFT	= 2;
-
-	CAUSE_FMT		= '\20\40BD\36CE1\35CE0\20IP8\17IP7\16IP6\15IP5\14IP4\13IP3\12SW2\11SW1\1INT';
-
-
-// Cause register exception codes
-function EXC_CODE(x: dword): dword;
-
-const
-// Hardware exception codes
-	EXC_INT		= 0 shl 2;			// interrupt
-	EXC_MOD		= 1 shl 2;			// TLB mod
-	EXC_RMISS	= 2 shl 2;			// Read TLB Miss
-	EXC_WMISS	= 3 shl 2;			// Write TLB Miss
-	EXC_RADE	= 4 shl 2;			// Read Address Error
-	EXC_WADE	= 5 shl 2;			// Write Address Error
-	EXC_IBE		= 6 shl 2;			// Instruction Bus Error
-	EXC_DBE		= 7 shl 2;			// Data Bus Error
-	EXC_SYSCALL	= 8 shl 2;			// SYSCALL
-	EXC_BREAK	= 9 shl 2;			// BREAKpoint
-	EXC_II		= 10 shl 2;			// Illegal Instruction
-	EXC_CPU		= 11 shl 2;			// CoProcessor Unusable
-	EXC_OV		= 12 shl 2;			// OVerflow
-
-// software exception codes
-	SEXC_SEGV	= 16 shl 2;			// Software detected seg viol
-	SEXC_RESCHED= 17 shl 2;			// resched request
-	SEXC_PAGEIN	= 18 shl 2;			// page-in request
-	SEXC_CPU	= 19 shl 2;			// coprocessor unusable
-
-
-// Coprocessor 0 registers
-{$DEFINE C0_INX	$0} 				// tlb index
-{$DEFINE C0_RAND $1}				// tlb random
-{$DEFINE C0_TLBLO $2}				// tlb entry low
-{$DEFINE C0_CTXT $4}				// tlb context
-
-{$DEFINE C0_PIDMASK	$6}				// Mips2
-
-{$DEFINE C0_BADVADDR $8}			// bad virtual address
-
-{$DEFINE C0_TLBHI $10}				// tlb entry hi
-{$DEFINE C0_PID	$10}				// Mips2
-
-{$DEFINE C0_SR $12}					// status register
-{$DEFINE C0_CAUSE $13}				// exception cause
-{$DEFINE C0_EPC $14}				// exception pc
-{$DEFINE C0_PRID $15}				// revision identifier
-{$DEFINE C0_ERREG $16}				// Mips2
-
-// Coprocessor 0 operations
-	C0_READI  	= $1;		// read ITLB entry addressed by C0_INDEX
-	C0_WRITEI 	= $2;		// write ITLB entry addressed by C0_INDEX
-	C0_WRITER 	= $6;		// write ITLB entry addressed by C0_RAND
-	C0_PROBE  	= $8;		// probe for ITLB entry addressed by TLBHI
-	C0_RFE	  	= $10;		// restore for exception
-
-// Flags for the nofault handler. 0 means no fault is expected.
-	NF_BADADDR	= 1;			// badaddr, wbadaddr
-	NF_COPYIO	= 2;			// copyin, copyout
-	NF_ADDUPC	= 3;			// addupc
-	NF_FSUMEM	= 4;			// fubyte, subyte, fuword, suword
-	NF_USERACC	= 5;			// useracc
-	NF_SOFTFP	= 6;			// softfp
-	NF_REVID	= 7;			// revision ids
-	NF_NENTRIES	= 8;
-
-// TLB size constants
- 	TLBWIREDBASE    = 0;               					// WAG for now
- 	NWIREDENTRIES   = 8;               					// WAG for now
- 	TLBRANDOMBASE   = NWIREDENTRIES;
- 	NTLBENTRIES     = 64;
- 	NRANDOMENTRIES  = (NTLBENTRIES - NWIREDENTRIES);
- 	              		
-
- 	TLBRAND_RANDMASK   = $00003f00;
-	TLBRAND_RANDSHIFT  = 8;
-
-
-// Chip interrupt vector
-	NC0VECS		 = 8;
-
-
-
-// extern int (*c0vec_tbl[])();
-var
-	c0vec_tbl : array of function: longint; external;
-
-
-const
- 	BRK_KERNEL 		 = $f1;
- 	EXCEPT_NORM      = 1;
- 	EXCEPT_UTLB      = 2;
- 	EXCEPT_BRKPT   	 = 3;
- 	EXCEPT_DB    	 = 4;
- 	EXCEPT_GDB    	 = 4;
-	EXCEPT_INT    	 = 9;
-	EXCEPT_ELSE    	 = $ff;
-
-
-
-implementation
-
-// Address conversion macros
-function K0_TO_K1(x: dword): dword;	
-begin
-	result:= x or $A0000000;
-end;
-
-function K1_TO_K0(x: dword): dword;
-begin
-	result:= x and $9FFFFFFF;
-end;
-
-function K0_TO_PHYS(x: dword): dword;
-begin
-	result:= x and $1FFFFFFF;
-end;
-
-function K1_TO_PHYS(x: dword): dword;
-begin
-	result:= x and $1FFFFFFF;
-end;
-
-function PHYS_TO_K0(x: dword): dword;
-begin
-	result:= x or $80000000;
-end;
-
-function PHYS_TO_K1(x: dword): dword;
-begin
-	result:= x or $A0000000;
-end;
-
-// Address predicates
-function IS_KSEG0(x: dword): boolean;
-begin	
-	result:= ((x >= K0BASE) and (x < K1BASE));
-end;
-
-function IS_KSEG1(x: dword): boolean;
-begin
-	result:= ((x >= K1BASE) and (x < K2BASE));
-end;
-
-
-{
-function IS_KSEG2(x: dword): boolean;
-begin
-	result:= ((x >= K2BASE) and (x < KPTEBASE));
-end;
-
-function IS_KPTESEG(x: dword): boolean;
-begin
-	result:= (x >= KPTEBASE);
-end;
-}
-
-
-
-function IS_KUSEG(x: dword): boolean;
-begin
-	result:= (x < K0BASE);
-end;
-
-function EXC_CODE(x: dword): dword;
-begin
-	result:= x shl 2;
-end;
-
-begin
-end.

Some files were not shown because too many files changed in this diff