/****************************************************************************** * * project name: TICT Tutorial S2P1 * file name: scaler.c * initial date: 21/02/2001 (TiCT's first Anniversary ;-) * author: thomas.nussbaumer@gmx.net * * description: Demonstration of Texturing Vertical Strips Algorithm * * NOTE: This is no raycaster nor is this program capable of rendering * images for realtime 3D. Its just a "proof of concept" program for * the strips texturing and may be improved heavily. Nevertheless * it demonstrates the idea quite well. * * $Id: scaler.c,v 1.1 2001/02/22 19:58:28 Thomas Nussbaumer Exp $ * ******************************************************************************/ #define SAVE_SCREEN #define OPTIMIZE_ROM_CALLS #include short _ti92plus; short _ti89; //----------------------------------------------------------------------------- // 64x64 pixels texture (2 planes ==> 4 grays) // // converted from BMP to BIN with ImageStudio and converted to hex array // with TTBin2Hex from TIGCC Tools Suite //----------------------------------------------------------------------------- unsigned char wall[2][64*8] = {{ 0x00,0x00,0x00,0x34,0x00,0x9f,0xfc,0x00,0x00,0x00,0x00,0x73,0xff,0xb8,0x01,0xff, 0x01,0x00,0x00,0xba,0xaf,0xb8,0x06,0x00,0x09,0x0f,0xff,0x3a,0xff,0x38,0x00,0x00, 0xf9,0x0f,0xfb,0x3d,0xfe,0x38,0xff,0xff,0xf9,0xcf,0xfb,0x39,0xb0,0xf9,0xff,0x7d, 0xb9,0xcf,0xef,0x39,0xf0,0xf9,0xed,0xbb,0xf7,0xcf,0xef,0x3c,0x3f,0xf8,0xea,0xad, 0xf7,0xee,0xeb,0x3f,0xff,0xf8,0x5e,0xfe,0x0f,0xef,0x57,0x3f,0xff,0xfc,0x5e,0x00, 0x0f,0xce,0x35,0x3f,0x80,0x15,0x00,0x7f,0xff,0xc2,0x39,0x3c,0x40,0x96,0x1f,0xff, 0xff,0xe2,0x69,0x3e,0x10,0xbd,0xff,0xff,0xff,0xf7,0x26,0x3e,0x2f,0x3f,0xff,0xff, 0xff,0xe7,0xd7,0x3e,0xd0,0xbf,0xff,0xff,0x00,0xe7,0x75,0x3e,0xb0,0xb9,0xb0,0x00, 0xfe,0xdb,0x24,0x3e,0xff,0x38,0x68,0x00,0x46,0xd7,0xd4,0x3e,0xce,0x38,0xe0,0x00, 0xfe,0xf6,0xc0,0x7f,0x81,0xf9,0x73,0xff,0xfe,0xe8,0x1b,0xfe,0x1f,0xf3,0x77,0xf3, 0xfe,0xef,0xff,0xfc,0xff,0xf3,0x77,0xf3,0xc6,0xef,0xff,0xfe,0x7f,0xfb,0x67,0xfb, 0x0f,0xe0,0xff,0x03,0x9e,0x63,0x67,0xf1,0x09,0xf0,0x76,0x80,0x01,0x63,0x67,0xe3, 0xf1,0xe7,0xfa,0x0d,0x0e,0xe7,0x6a,0x0a,0x81,0xef,0xff,0x37,0xf0,0xe7,0x71,0xc0, 0x0f,0xef,0xaf,0x73,0x30,0xe7,0x5f,0xff,0xff,0xed,0xcf,0x3c,0x3e,0xe6,0x5f,0xff, 0xff,0xed,0xcf,0x50,0x4e,0xe7,0x5f,0xff,0x8f,0x2a,0x8f,0x40,0x40,0xe7,0x5c,0x07, 0x40,0xec,0x4e,0x2a,0x0e,0xe1,0x73,0x3e,0x0f,0xee,0x6e,0x20,0x50,0xe6,0x62,0x06, 0x78,0xeb,0x46,0xb8,0x11,0xe6,0x6d,0xfb,0x76,0xef,0x66,0x14,0xaf,0xe5,0x6b,0x2b, 0x77,0xe2,0xe7,0x12,0x7f,0xe6,0x6f,0xbb,0x7f,0xe3,0xc7,0x15,0x41,0xe9,0xff,0xdb, 0x7f,0xe3,0x27,0x50,0x3f,0xef,0xe4,0x03,0x7e,0xf5,0xa7,0x33,0xff,0xef,0xff,0xff, 0x4f,0xe7,0xa7,0xff,0xff,0xef,0xff,0xff,0x7f,0xe7,0x67,0xff,0xff,0xe0,0x00,0x03, 0x7f,0x36,0x67,0x80,0x00,0x0f,0xff,0xfa,0x7f,0x35,0x27,0xbf,0xff,0xc0,0x00,0x0b, 0x7f,0x36,0xa7,0x80,0x00,0x00,0x00,0x03,0x7e,0x36,0xa7,0x80,0x00,0x07,0xff,0xf3, 0x78,0x37,0xc7,0x8f,0xff,0xfe,0xfb,0xf3,0xf0,0xf5,0xc7,0x82,0xbf,0xfe,0xbf,0xf3, 0xf0,0xfe,0x87,0xc6,0xaf,0x79,0x99,0x53,0xf0,0xf0,0x07,0xe7,0x4f,0x7b,0xd0,0xc3, 0xff,0xf7,0xff,0xe5,0xee,0x7f,0x44,0xc3,0xff,0xff,0xff,0xcc,0xb1,0x54,0x56,0x43, 0x81,0xff,0xff,0xc0,0x01,0x00,0x52,0x03,0xc6,0x1f,0xff,0xdf,0xf0,0x00,0x00,0x07, 0x80,0x20,0x03,0xdf,0xff,0xff,0xff,0xff,0xb8,0x00,0x1f,0x00,0xff,0xff,0xff,0xff, 0xbf,0xc0,0x00,0x06,0xff,0xff,0xff,0xff,0xb9,0xd7,0x6b,0x82,0xd0,0x7f,0xff,0xfe, 0xbf,0xfa,0x25,0x5c,0xfe,0xc1,0x00,0x06,0xb9,0xf9,0x15,0x5c,0xf1,0x09,0x00,0x3a, 0x80,0x00,0x00,0x03,0xf1,0xfa,0x7f,0xf2,0xbf,0xff,0xff,0xff,0xff,0xd2,0xbf,0xea, 0xff,0xff,0xff,0xff,0xff,0x82,0xff,0xe2,0x7f,0xff,0xff,0xff,0xf1,0xfe,0x7f,0xfe, 0x0f,0xff,0xff,0xff,0xf0,0x7e,0x7f,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff },{ 0xff,0xc0,0x00,0x38,0x00,0x7f,0xff,0xff,0xff,0xc0,0x00,0x38,0x00,0x7f,0xff,0xff, 0xff,0xc0,0x00,0x71,0x50,0x7c,0x01,0xff,0x07,0xc0,0x00,0xf1,0x00,0xfc,0x00,0x00, 0x07,0xc0,0x04,0xfa,0x01,0xfc,0x00,0x00,0x07,0xc0,0x04,0xfe,0x4f,0xfc,0x00,0x82, 0x47,0xc0,0x10,0xfe,0x0f,0xfc,0x12,0x44,0x0f,0xc0,0x10,0xff,0xff,0xfc,0x15,0x52, 0x0f,0xc1,0x14,0xff,0xff,0xfc,0xa1,0x01,0xff,0xc0,0xa8,0xff,0xff,0xfc,0xa1,0xff, 0xff,0xe1,0xca,0xff,0xff,0xfc,0xff,0xff,0xff,0xe5,0xc6,0xff,0x80,0x7d,0xff,0xff, 0xff,0xe5,0x96,0xfc,0x00,0x7f,0xff,0xff,0xff,0xe0,0xd9,0xfc,0x10,0xff,0xff,0xff, 0xff,0xf0,0x28,0xfc,0x2f,0x7f,0xff,0xff,0xff,0xf0,0x8a,0xfc,0x4f,0x7e,0x7f,0xff, 0x01,0xf0,0xdb,0xfc,0x00,0xfc,0x70,0x00,0x01,0xf8,0x2b,0xfc,0x31,0xf8,0x70,0x00, 0x01,0xf9,0x3f,0xfc,0x7f,0xf8,0xe0,0x00,0x01,0xff,0xff,0xfd,0xff,0xf8,0xe0,0x0c, 0x01,0xff,0xff,0xff,0xff,0xf8,0xe0,0x0c,0x39,0xff,0xff,0xff,0xff,0xf0,0xf0,0x04, 0xf1,0xff,0xff,0xfc,0x01,0xf0,0xf0,0x0e,0xf7,0xe0,0x0f,0x00,0x00,0xf0,0xf0,0x1c, 0x0f,0xe0,0x0f,0x00,0x01,0xf0,0xf5,0xf5,0x7f,0xe0,0x0e,0x08,0x0f,0xf0,0xff,0xff, 0xff,0xe0,0x5e,0x0c,0xcf,0xf0,0xff,0xff,0xff,0xe2,0x3e,0x43,0xc1,0xf1,0xff,0xff, 0xff,0xe2,0x3e,0x2f,0xb1,0xf0,0xff,0xff,0xf0,0xe5,0x7e,0x3f,0xbf,0xf0,0xff,0xff, 0x80,0x23,0xbf,0x15,0xf1,0xf6,0xe0,0xff,0x80,0x21,0x9f,0x1f,0xaf,0xf1,0xec,0x03, 0x87,0x24,0xbf,0x07,0xef,0xf1,0xe2,0x07,0x89,0x20,0x9f,0x8b,0x51,0xf2,0xe4,0xd7, 0x88,0x25,0x1f,0x8d,0x81,0xf1,0xe0,0x47,0x80,0x24,0x3f,0x8a,0xbf,0xf7,0xe0,0x27, 0x80,0x24,0xdf,0x8f,0xff,0xff,0xff,0xff,0x81,0x22,0x5f,0xcf,0xff,0xff,0xff,0xff, 0xb0,0x30,0x5f,0xff,0xff,0xff,0xff,0xff,0x80,0x30,0x9f,0xff,0xff,0xff,0xff,0xff, 0x80,0xf1,0x9f,0xff,0xff,0xf0,0x00,0x07,0x80,0xf2,0xdf,0xc0,0x00,0x00,0x00,0x07, 0x80,0xf1,0x5f,0xc0,0x00,0x00,0x00,0x0f,0x81,0xf1,0x5f,0xc0,0x00,0x00,0x00,0x0f, 0x87,0xf0,0x3f,0xc0,0x00,0x01,0x04,0x0f,0x8f,0xf2,0x3f,0xc5,0x40,0x01,0x40,0x0f, 0x8f,0xf1,0x7f,0xc1,0x50,0x86,0x66,0xaf,0xff,0xff,0xff,0xc0,0xb0,0x84,0x2f,0x3f, 0xff,0xff,0xff,0xc2,0x11,0x80,0xbb,0x3f,0xff,0xff,0xff,0xe3,0x4e,0xab,0xa9,0xbf, 0xff,0xff,0xff,0xff,0xfe,0xff,0xad,0xff,0x81,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0x80,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0x80,0x00,0x00,0xff,0xff,0xff,0xff,0xff, 0x80,0x00,0x00,0x01,0xff,0xff,0xff,0xff,0x86,0x28,0x94,0x01,0xff,0xff,0xff,0xff, 0x80,0x05,0xda,0xa3,0xf0,0x3f,0xff,0xff,0x86,0x06,0xea,0xa3,0xf0,0x07,0x00,0x07, 0xff,0xff,0xff,0xff,0xf0,0x07,0x00,0x07,0xff,0xff,0xff,0xff,0xf0,0x2e,0x40,0x17, 0xff,0xff,0xff,0xff,0xff,0xfe,0x00,0x1f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff}}; //----------------------------------------------------------------------------- // lookup table to speedup vertical scaling of a texture strip // // generated with genlookup.exe (subdirectory tools) //----------------------------------------------------------------------------- // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // NOTE: this is a static definition of an array which consists of arrays of // different length. It took my quite a while to figure out how this can // be implemented (the correct syntax) // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! unsigned short** lookup_table = (unsigned short *[64]){ (unsigned short [1]){0}, (unsigned short [2]){0,256}, (unsigned short [3]){0,168,176}, (unsigned short [4]){0,128,128,128}, (unsigned short [5]){0,104,104,96,104}, (unsigned short [6]){0,88,80,88,88,80}, (unsigned short [7]){0,72,72,72,80,72,72}, (unsigned short [8]){0,64,64,64,64,64,64,64}, (unsigned short [9]){0,56,56,56,56,64,56,56,56}, (unsigned short [10]){0,48,56,48,56,48,48,56,48,56}, (unsigned short [11]){0,48,48,40,48,48,48,48,48,40,48}, (unsigned short [12]){0,40,48,40,40,48,40,40,48,40,40,48}, (unsigned short [13]){0,40,40,40,40,40,40,32,40,40,40,40,40}, (unsigned short [14]){0,40,32,40,32,40,32,40,40,32,40,32,40,32}, (unsigned short [15]){0,32,40,32,32,32,40,32,32,32,40,32,32,32,40}, (unsigned short [16]){0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32}, (unsigned short [17]){0,32,32,24,32,32,32,24,32,32,32,24,32,32,32,24,32}, (unsigned short [18]){0,32,24,32,24,32,24,32,24,32,32,24,32,24,32,24,32,24}, (unsigned short [19]){0,24,32,24,24,32,24,32,24,24,32,24,24,32,24,32,24,24,32}, (unsigned short [20]){0,24,24,32,24,24,24,24,32,24,24,24,24,32,24,24,24,24,32,24}, (unsigned short [21]){0,24,24,24,24,24,24,24,24,24,24,32,24,24,24,24,24,24,24,24,24}, (unsigned short [22]){0,24,24,24,24,24,16,24,24,24,24,24,24,24,24,24,24,16,24,24,24,24}, (unsigned short [23]){0,24,24,16,24,24,24,16,24,24,24,24,16,24,24,24,24,16,24,24,24,16,24}, (unsigned short [24]){0,24,16,24,24,16,24,24,16,24,24,16,24,24,16,24,24,16,24,24,16,24,24,16}, (unsigned short [25]){0,24,16,24,16,24,16,24,16,24,24,16,24,16,24,16,24,24,16,24,16,24,16,24,16}, (unsigned short [26]){0,16,24,16,24,16,24,16,24,16,24,16,24,16,16,24,16,24,16,24,16,24,16,24,16,24}, (unsigned short [27]){0,16,24,16,16,24,16,24,16,16,24,16,16,24,16,24,16,16,24,16,16,24,16,24,16,16,24}, (unsigned short [28]){0,16,24,16,16,16,24,16,16,24,16,16,16,24,16,16,24,16,16,16,24,16,16,24,16,16,16,24}, (unsigned short [29]){0,16,16,24,16,16,16,16,24,16,16,16,16,24,16,16,16,24,16,16,16,16,24,16,16,16,16,24,16}, (unsigned short [30]){0,16,16,16,24,16,16,16,16,16,16,16,24,16,16,16,16,16,16,24,16,16,16,16,16,16,16,24,16,16}, (unsigned short [31]){0,16,16,16,16,16,16,16,24,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,24,16,16,16,16,16,16}, (unsigned short [32]){0,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16}, (unsigned short [33]){0,16,16,16,16,16,16,16,16,8,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,8,16,16,16,16,16,16,16}, (unsigned short [34]){0,16,16,16,16,8,16,16,16,16,16,16,16,8,16,16,16,16,16,16,16,16,8,16,16,16,16,16,16,16,8,16,16,16}, (unsigned short [35]){0,16,16,8,16,16,16,16,16,8,16,16,16,16,16,8,16,16,16,16,16,8,16,16,16,16,16,8,16,16,16,16,16,8,16}, (unsigned short [36]){0,16,16,8,16,16,16,8,16,16,16,16,8,16,16,16,8,16,16,16,16,8,16,16,16,8,16,16,16,16,8,16,16,16,8,16}, (unsigned short [37]){0,16,8,16,16,16,8,16,16,16,8,16,16,8,16,16,16,8,16,16,16,8,16,16,16,8,16,16,8,16,16,16,8,16,16,16,8}, (unsigned short [38]){0,16,8,16,16,8,16,16,8,16,16,16,8,16,16,8,16,16,8,16,16,8,16,16,8,16,16,8,16,16,16,8,16,16,8,16,16,8}, (unsigned short [39]){0,16,8,16,16,8,16,8,16,16,8,16,16,8,16,16,8,16,16,8,16,8,16,16,8,16,16,8,16,16,8,16,16,8,16,8,16,16,8}, (unsigned short [40]){0,16,8,16,8,16,16,8,16,8,16,16,8,16,8,16,16,8,16,8,16,16,8,16,8,16,16,8,16,8,16,16,8,16,8,16,16,8,16,8}, (unsigned short [41]){0,16,8,16,8,16,8,16,8,16,16,8,16,8,16,8,16,16,8,16,8,16,8,16,8,16,16,8,16,8,16,8,16,16,8,16,8,16,8,16,8}, (unsigned short [42]){0,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8}, (unsigned short [43]){0,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16,8,16}, (unsigned short [44]){0,8,16,8,16,8,16,8,16,8,16,8,8,16,8,16,8,16,8,16,8,16,8,8,16,8,16,8,16,8,16,8,16,8,8,16,8,16,8,16,8,16,8,16}, (unsigned short [45]){0,8,16,8,16,8,16,8,8,16,8,16,8,8,16,8,16,8,16,8,8,16,8,16,8,16,8,8,16,8,16,8,16,8,8,16,8,16,8,8,16,8,16,8,16}, (unsigned short [46]){0,8,16,8,16,8,8,16,8,16,8,8,16,8,8,16,8,16,8,8,16,8,16,8,8,16,8,16,8,8,16,8,16,8,8,16,8,8,16,8,16,8,8,16,8,16}, (unsigned short [47]){0,8,16,8,8,16,8,16,8,8,16,8,8,16,8,8,16,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,16,8,8,16,8,8,16,8,8,16,8,16,8,8,16}, (unsigned short [48]){0,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16,8,8,16}, (unsigned short [49]){0,8,16,8,8,16,8,8,8,16,8,8,16,8,8,16,8,8,16,8,8,8,16,8,8,16,8,8,16,8,8,8,16,8,8,16,8,8,16,8,8,16,8,8,8,16,8,8,16}, (unsigned short [50]){0,8,16,8,8,8,16,8,8,16,8,8,8,16,8,8,8,16,8,8,16,8,8,8,16,8,8,16,8,8,8,16,8,8,16,8,8,8,16,8,8,8,16,8,8,16,8,8,8,16}, (unsigned short [51]){0,8,16,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,16}, (unsigned short [52]){0,8,8,16,8,8,8,16,8,8,8,16,8,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,8,16,8,8,8,16,8,8,8,16,8,8,8,8,16,8,8,8,16,8,8,8,16,8}, (unsigned short [53]){0,8,8,16,8,8,8,8,16,8,8,8,8,16,8,8,8,16,8,8,8,8,16,8,8,8,8,16,8,8,8,8,16,8,8,8,8,16,8,8,8,16,8,8,8,8,16,8,8,8,8,16,8}, (unsigned short [54]){0,8,8,16,8,8,8,8,8,16,8,8,8,8,16,8,8,8,8,16,8,8,8,8,8,16,8,8,8,8,16,8,8,8,8,8,16,8,8,8,8,16,8,8,8,8,16,8,8,8,8,8,16,8}, (unsigned short [55]){0,8,8,8,16,8,8,8,8,8,16,8,8,8,8,8,16,8,8,8,8,8,16,8,8,8,8,8,16,8,8,8,8,8,16,8,8,8,8,8,16,8,8,8,8,8,16,8,8,8,8,8,16,8,8}, (unsigned short [56]){0,8,8,8,16,8,8,8,8,8,8,16,8,8,8,8,8,8,16,8,8,8,8,8,8,16,8,8,8,8,8,8,16,8,8,8,8,8,8,16,8,8,8,8,8,8,16,8,8,8,8,8,8,16,8,8}, (unsigned short [57]){0,8,8,8,8,16,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,16,8,8,8}, (unsigned short [58]){0,8,8,8,8,16,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,16,8,8,8}, (unsigned short [59]){0,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8}, (unsigned short [60]){0,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8}, (unsigned short [61]){0,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8}, (unsigned short [62]){0,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8}, (unsigned short [63]){0,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,16,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8}, (unsigned short [64]){0,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8} }; unsigned char* backbuffer0 = NULL; // address to backbuffer for lightgray plane unsigned char* backbuffer1 = NULL; // address to backbuffer for darkgray plane short display_offset = 0; // used to center the image on a TI-92plus //============================================================================= // draws a single strip ... //============================================================================= void RenderStrip(short dest_height,short dest_x,short dest_y,short texture_x) { unsigned short* ytable = lookup_table[dest_height-1]; // fetch lookup table which corresponds to given height unsigned char texture_mask = 0x80 >> (texture_x & 7); // generate bitmask for texture unsigned char screenx_mask = 0x80 >> (dest_x & 7); // generate bitmask for display unsigned char* dest0 = backbuffer0+dest_y*30+(dest_x>>3)+display_offset; // byte position in display unsigned char* dest1 = backbuffer1+dest_y*30+(dest_x>>3)+display_offset; unsigned char* src0 = wall[0]+(texture_x>>3); // byte position in texture unsigned char* src1 = wall[1]+(texture_x>>3); short i; for (i=0;i set it on screen, too if ((*src0) & texture_mask) *dest0 |= screenx_mask; if ((*src1) & texture_mask) *dest1 |= screenx_mask; } } //---------------------------------------------------------------------------- // structure which defines a wall //---------------------------------------------------------------------------- typedef struct { short height_left; // height at the left side short height_right; // height at the right side short start_x; // screen x position where the wall starts short end_x; // screen x position where the wall ends } WALL_T; //============================================================================= // draw a single wall // // NOTE: this function still uses floating point operations which make // the rendering slow. //============================================================================= void DrawWall(WALL_T* wt) { short hdiff = wt->height_right-wt->height_left; short width = wt->end_x - wt->start_x; float hdelta = (float)hdiff/(float)(width); float height = wt->height_left; unsigned short* xtable = lookup_table[width-1]; unsigned short xtexture = 0; short x; for (x=wt->start_x; xend_x; x++) { unsigned short tmp_h = (unsigned short)height; xtexture += (*xtable++)/8; RenderStrip(tmp_h,x,48-(tmp_h>>1),xtexture); height += hdelta; } } //============================================================================= // draw some walls ... //============================================================================= void DrawSomeWalls(void) { WALL_T wt[5] = { {64,64,0,32},{64,20,32,64},{20,20,64,84},{20,64,84,116},{64,64,116,159}}; int i; memset(backbuffer0,0,LCD_SIZE*2); for (i=0;i<5;i++) DrawWall(&wt[i]); memcpy(GetPlane(0),backbuffer0,LCD_SIZE); memcpy(GetPlane(1),backbuffer1,LCD_SIZE); } //============================================================================= // where all the fun starts ... //============================================================================= void _main(void) { LCD_BUFFER lcdbuffer; // we are not using SAVE_SCREEN, because we want put // messages into into the statusline in some cases int i,j; //------------------------------------------------------------------------- // allocate memory for 2 planes for double buffering in one piece !! //------------------------------------------------------------------------- if (!(backbuffer0 = malloc(LCD_SIZE*2))) { ST_showHelp("ERR: out of mem"); return; } backbuffer1 = backbuffer0 + LCD_SIZE; // the start address of the second // plane LCD_SIZE bytes apart from // the first plane //------------------------------------------------------------------------- // setup the display offset for TI-92p calculators // the output image should be centered on these calcs //------------------------------------------------------------------------- if (TI89) display_offset = 0; else display_offset = 4 + 14*30; //------------------------------------------------------------------------- // save original screen content and turn on grayscale graphics //------------------------------------------------------------------------- LCD_save(lcdbuffer); if (!GrayMode(GRAY_ON)) { free(backbuffer0); return; } memcpy(GetPlane(0),lcdbuffer,LCD_SIZE); DrawSomeWalls(); FontSetSys(F_6x8); for (i=0;i<2;i++) { SetPlane(i); if (TI89) DrawStrXY(4,90,"Tutorial S2P1 - TiCT 2001",A_REPLACE); else DrawStrXY(4+4*8,90+14,"Tutorial S2P1 - TiCT 2001",A_REPLACE); } ngetchx(); //------------------------------------------------------------------------- // turn graymode off, free backbuffer and restore previous screen content //------------------------------------------------------------------------- GrayMode(GRAY_OFF); free(backbuffer0); LCD_restore(lcdbuffer); } //############################################################################# // Revision History //############################################################################# // // $Log: scaler.c,v $ // Revision 1.1 2001/02/22 19:58:28 Thomas Nussbaumer // initial version // //