// *********************************************** // TEXT.C - how to create text // *********************************************** // **** includes #include "text.h" #include "global.h" // **** global variables static u_char LetterWidth[] = { 8,7,9,9,9,9,8,8,8,9,11,10,9,12,9,8, 10,11,5,6,11,9,15,11,11,9,12,10,7,10,10,10, 15,11,10,9,8,8,6,9,7,7,9,8,4,7,8,5, 12,8,7,9,8,7,7,6,9,8,12,9,9,8,4,7, 5,5,6,12,3,8,3,4,4,12,7}; // **** initialise the text sprites ready for text void InitText() { TEXT.attribute = (2<<24) + (1<<30) + (1<<28); TEXT2.attribute = (2<<24) + (1<<30) + (2<<28); TEXTBOX.attribute = (1<<30); TEXT.x = -128; TEXT.y = -128+5; TEXT2.x = TEXT.x+1; TEXT2.y = TEXT.y+3; TEXTBOX.x = -128-5; TEXTBOX.w = 256+10; TEXT.tpage = TEXT2.tpage = GetTPage(2, 0, 576, 0); TEXT.w = TEXT2.w = 256; TEXT.h = TEXT2.h = 128; TEXT.u = TEXT2.u = 0; TEXT.v = TEXT2.v = 90; TEXT.r = TEXT.g = TEXT.b = 128; TEXT2.r = TEXT2.g = TEXT2.b = 128; } // **** create a piece of text all in one go void CreateText(u_char* tText) { RECT tRect = {576, 90, 256, 128}; u_long tPlaceLetterX = 0, tPlaceLetterY = 0; u_long tEndWordX, tEndWordCheckLetter; u_long tCurrentLetter = 0, tLetterCode; u_char tAscii; VSync(1); // printf("WORD START... "); // clear the sprite area ready for text ClearImage(&tRect, 0, 0, 0); tRect.w = 16; tRect.h = 18; // make sure that is finished (not that it makes sod all difference) DrawSync(0); tPlaceLetterX = 0; tPlaceLetterY = 0; // process entire string up until character is '*' while (tText[tCurrentLetter] != '#') { // find a complete word tEndWordX = tPlaceLetterX; tEndWordCheckLetter = tCurrentLetter; while ((tText[tEndWordCheckLetter] != ' ') && (tText[tEndWordCheckLetter] != '#')) { tAscii = tText[tEndWordCheckLetter]; if (tAscii == 33) tLetterCode = 62; // ! if (tAscii == 34) tLetterCode = 63; // " if (tAscii == 39) tLetterCode = 64; // ' if (tAscii == 40) tLetterCode = 65; // ( if (tAscii == 41) tLetterCode = 66; // ) if (tAscii == 43) tLetterCode = 67; // + if (tAscii == 44) tLetterCode = 68; // , if (tAscii == 45) tLetterCode = 69; // - if (tAscii == 46) tLetterCode = 70; // . if (tAscii == 58) tLetterCode = 71; // : if (tAscii == 59) tLetterCode = 72; // ; if (tAscii == 61) tLetterCode = 73; // = if (tAscii == 63) tLetterCode = 74; // ? if ((tAscii >47) && (tAscii <58)) tLetterCode = tAscii-48; // numbers if ((tAscii >64) && (tAscii <91)) tLetterCode = tAscii-55; // upper case if ((tAscii >96) && (tAscii <123)) tLetterCode = tAscii-61; // lower case tEndWordX += LetterWidth[tLetterCode]; tEndWordCheckLetter++; } // if the words length will take it over 256 pixels wide, move it to a new line if (tEndWordX > 255) { tPlaceLetterX = 0; tPlaceLetterY += 18; } // process that part of the string again, drawing it this time while ((tText[tCurrentLetter] != ' ') && (tText[tCurrentLetter] != '#')) { tAscii = tText[tCurrentLetter]; if (tAscii == 33) tLetterCode = 62; // ! if (tAscii == 34) tLetterCode = 63; // " if (tAscii == 39) tLetterCode = 64; // ' if (tAscii == 40) tLetterCode = 65; // ( if (tAscii == 41) tLetterCode = 66; // ) if (tAscii == 43) tLetterCode = 67; // + if (tAscii == 44) tLetterCode = 68; // , if (tAscii == 45) tLetterCode = 69; // - if (tAscii == 46) tLetterCode = 70; // . if (tAscii == 58) tLetterCode = 71; // : if (tAscii == 59) tLetterCode = 72; // ; if (tAscii == 61) tLetterCode = 73; // = if (tAscii == 63) tLetterCode = 74; // ? if ((tAscii >47) && (tAscii <58)) tLetterCode = tAscii-48; // numbers if ((tAscii >64) && (tAscii <91)) tLetterCode = tAscii-55; // upper case if ((tAscii >96) && (tAscii <123)) tLetterCode = tAscii-61; // lower case tRect.x = (tLetterCode%16) * 16 + 576; tRect.y = (tLetterCode>>4) * 18; MoveImage(&tRect, tPlaceLetterX+576, tPlaceLetterY+90); tPlaceLetterX += LetterWidth[tLetterCode]; tCurrentLetter++; }; if (tPlaceLetterX != 0) tPlaceLetterX += 7; tCurrentLetter++; }; TEXTBOX.h = tPlaceLetterY+22; DrawSync(0); // printf("WORD END... time(%d)\n", VSync(1)); }