/* ----------------------------------------------- GTASC - GTA adaptation for TI Calculators ----------------------------------------------- Programmed by : Olivier SANGALA Version : 1.2 License : Free under GNU General Public License ( see "gpl.txt" ) Release Date : 05/01/2007 Platform : TI89/TI92+/V200 Website : http://olivier.sangala.free.fr Email : olivier_sangala@hotmail.com ---------- License ---------- Copyright (C) 2002-2007 Olivier SANGALA This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ //----------------------------------------------------------------------------- //-------------------------------------------------------------------------- // TMDE FUNCTIONS //-------------------------------------------------------------------------- /* Routines that run the display engine */ #include // Include All Header Files #include #include "defines.h" #include "tmde.h" //-------------------------------------------------------------------------- extern TGame*Game; //-------------------------------------------------------------------------- TCamera Camera; TPoint8 TMSize; // position of left up pixel on tile map int scx; int scy; int FrameCounter=0; int TileMasked=0; int SpriteObject=0; int BlankSquare=0; //-------------------------------------------------------------------------- char * PlanesMem=NULL; char * Plane0=NULL; char * Plane1=NULL; unsigned char * TileMap=NULL; unsigned short * TileData=NULL; //-------------------------------------------------------------------------- int TilePalette=PAL_0123; //-------------------------------------------------------------------------- /* PALETTES = 4 colors = (C0,C1,C2,C3) 1 color = 4 possible values 0 = white 1 = light gray 2 = dark gray 3 = black P0 = tile line pattern plane 0 P1 = tile line pattern plane 1 Q0 = tile line pattern plane 0, after applying palette Q1 = tile line pattern plane 1, after applying palette formulas for palettes : Normal palette 0123 : Q0 = P0 and Q1 = P1 Black palette (vehs blown up) 0333 : Q0 = Q1 = (P0|P1) Black reversed palette 3000 : Q0 = Q1 = (~(P0|P1)) */ //-------------------------------------------------------------------------- void TMDE_Enable(void) { // WARNING : ENOUGH MEMORY NEEDED SUPPOSED int size=9120; // ((16+128+16+128+16)*30) PlanesMem = malloc(size); Plane0 = PlanesMem+480; // 16*30 Plane1 = PlanesMem+4800; // ((16+128+16)*30) Camera.ScreenPos.x = (160/2); Camera.ScreenPos.y = (100/2); } //-------------------------------------------------------------------------- void TMDE_Disable(void) { if (PlanesMem) free(PlanesMem); } //-------------------------------------------------------------------------- int CANDRAWSPRITE16(int left,int top) { return (left>-16 && left<160 && top>-16 && top<100); } //-------------------------------------------------------------------------- void DrawScreen(void) { FrameCounter++; PlaceCamera(); scx = Camera.Position.x-Camera.ScreenPos.x; scy = Camera.Position.y-Camera.ScreenPos.y; // TM BORDER CAMERA BOUNDS if (scx<0) scx=0; if (scy<0) scy=0; if (scx>MUL16(TMSize.x)-160) scx=MUL16(TMSize.x)-160; if (scy>MUL16(TMSize.y)-100) scy=MUL16(TMSize.y)-100; ClearGrayScreen2B(Plane0,Plane1); DrawBG(); SpriteObject=1; DrawSprites(); SpriteObject=0; DrawWindows(); FastCopyScreen (Plane0,GetPlane(0)); FastCopyScreen (Plane1,GetPlane(1)); } //-------------------------------------------------------------------------- void DrawBG(void) { int x,y; unsigned short * TileDataPtr; unsigned char tilenum; long offset = (long)Game->TMSizeX*(long)QUOT16(scy)+(long)QUOT16(scx); unsigned char*TileMapPtr=TileMap+offset; int TileY=-REM16(scy); int TileX=0; int ty0=QUOT16(scy); int ty1=QUOT16(scy+99); int tx0=QUOT16(scx); int tx1=QUOT16(scx+159); for (y=ty0;y<=ty1;y++,TileY+=16) { TileX = -REM16(scx); for (x=tx0;x<=tx1;x++,TileX+=16) { tilenum=*TileMapPtr++; TileDataPtr = TileData+MUL32(tilenum); TilePalette=PAL_0123; // white_streets if (Game->Save.white_streets) { if (ISTILE_STREET(tilenum)) TilePalette=PAL_3000; } // white_paving if (Game->Save.white_paving) { if (tilenum>=0x1A && tilenum<=0x1F) // paving and grass { tilenum=0x1B; TileDataPtr = TileData+MUL32(0x1B); } } //if (CANDRAWSPRITE16(TileX,TileY)) DrawTile16(TileX,TileY,TileDataPtr); } TileMapPtr+=(TMSize.x-(tx1-tx0+1)); } } //-------------------------------------------------------------------------- // Function 'DrawTile8' from ExtGraph (modified) void DrawTile8(int x,int y,unsigned char* sprite1) { register long offset = (y<<5)-(y<<1)+((x>>3)&0xfffffffe); register long addr1 = (long)Plane0+offset; register long addr2 = (long)Plane1+offset; register unsigned int cnt= 24-(x&15); register int h=8; register unsigned char* sprite2 = sprite1+8; for (;h;h--,addr1+=30,addr2+=30) { if (TileMasked) { *(long*)addr1&=~((long)(*sprite1|*sprite2)<>3)&0xfffffffe); register long addr1 = (long)Plane0+offset; register long addr2 = (long)Plane1+offset; register unsigned int cnt= 16-(x&15); register int h=16; register unsigned short* sprite2 = sprite1+16; switch (TilePalette) { case PAL_0123: for (;h;h--,addr1+=30,addr2+=30) { if (TileMasked) { *(long*)addr1&=~((long)(*sprite1|*sprite2)<