draw_states.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. #include "draw_states.h"
  2. #include "fxlib.h"
  3. #include "fixed.h"
  4. #include <stdio.h>
  5. // static functions
  6. static void fillBackground(Game_Data *data);
  7. static void draw_big_num(unsigned char *txt, int x, int y, unsigned char isReversed);
  8. static void drawPlayer(Game_Data *data, int player_angle);
  9. static void drawPolygon(Game_Data *data, int nb_lines, Line_Transition line_transition);
  10. static void drawDiagonals(Game_Data *data, int nb_lines, Line_Transition line_transition);
  11. static void drawHud(Game_Data *data);
  12. static void drawChrono(Game_Data *data);
  13. static int getLevel(Game_Data *data);
  14. static unsigned int length_of_print_string(unsigned char* txt);
  15. static void drawTopLeftCornerTextOffset(unsigned char* txt, unsigned char isReversed, int y);
  16. static void drawTopLeftCornerText(unsigned char* txt, unsigned char isReversed);
  17. static void drawTopRightCornerTextOffset(unsigned char* txt, unsigned char isReversed, int y);
  18. static void drawTopRightCornerText(unsigned char* txt, unsigned char isReversed);
  19. static void drawBottomLeftCornerText(unsigned char* txt, unsigned char isReversed);
  20. static void drawBottomRightCornerText(unsigned char* txt, unsigned char isReversed);
  21. static const unsigned char title_spr[] = {0x07, 0xF6, 0x1B, 0xFD, 0xFE, 0xFE, 0x00, 0x00, 0x0F, 0xF6, 0x1B, 0xFD, 0xFE, 0xFF, 0x00, 0x00, 0x0C, 0x06, 0x1B, 0x0D, 0x80, 0xC3, 0x00, 0x00, 0x0F, 0xF6, 0x1B, 0x0D, 0xFE, 0xC3, 0x00, 0x00, 0x0F, 0xF6, 0x1B, 0xFD, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x36, 0x1B, 0xF9, 0x80, 0xFF, 0x00, 0x00, 0x0F, 0xF7, 0xFB, 0x01, 0xFE, 0xC3, 0x00, 0x00, 0x0F, 0xE3, 0xFB, 0x00, 0xFE, 0xC3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0x7F, 0xB0, 0xCF, 0xEF, 0xF3, 0xFB, 0xF8, 0xC3, 0x7F, 0xB0, 0xDF, 0xEF, 0xF7, 0xFB, 0xFC, 0xC3, 0x60, 0x30, 0xD8, 0x6C, 0x06, 0x1B, 0x0C, 0xFF, 0x7F, 0xBF, 0xD8, 0x6C, 0x36, 0x1B, 0x0C, 0xFF, 0x7F, 0x9F, 0x9F, 0xEC, 0x36, 0x1B, 0x0C, 0xC3, 0x60, 0x30, 0xDF, 0xEC, 0x36, 0x1B, 0x0C, 0xC3, 0x7F, 0xB0, 0xD8, 0x6F, 0xF7, 0xFB, 0x0C, 0xC3, 0x3F, 0xB0, 0xD8, 0x6F, 0xE7, 0xF3, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0x9F, 0xCF, 0xEF, 0xF3, 0xF8, 0x00, 0x00, 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xF8, 0x00, 0x00, 0x60, 0x30, 0xD8, 0x01, 0x86, 0x18, 0x00, 0x00, 0x60, 0x30, 0xDF, 0xE1, 0x86, 0x18, 0x00, 0x00, 0x60, 0x3F, 0xDF, 0xE1, 0x86, 0x18, 0x00, 0x00, 0x60, 0x3F, 0xC0, 0x61, 0x86, 0x18, 0x00, 0x00, 0x7F, 0xB0, 0xDF, 0xEF, 0xF7, 0xF8, 0x00, 0x00, 0x3F, 0xB0, 0xDF, 0xCF, 0xF7, 0xF0, 0x00};
  22. static const unsigned char hex_border_top_left[8] = {0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0xC0, 0x80, 0x80};
  23. static const unsigned char hex_border_top_right[8] ={0x1F, 0x1F, 0x0F, 0x0F, 0x07, 0x07, 0x03, 0x03};
  24. static const unsigned char hex_border_bottom_left[8] = {0x80, 0x80, 0xC0, 0xC0, 0xE0, 0xE0, 0xF0, 0xF0};
  25. static const unsigned char hex_border_bottom_right[8] ={0x03, 0x03, 0x07, 0x07, 0x0F, 0x0F, 0x1F, 0x1F};
  26. static const unsigned char hex_border_top_left_rev[8] = {0x0F, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F};
  27. static const unsigned char hex_border_top_right_rev[8] ={0xE0, 0xE0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC, 0xFC};
  28. static const unsigned char hex_border_bottom_left_rev[8] = {0x7F, 0x7F, 0x3F, 0x3F, 0x1F, 0x1F, 0x0F, 0x0F};
  29. static const unsigned char hex_border_bottom_right_rev[8] ={0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xE0};
  30. static const unsigned char big_hex_border_left[] = {128,128,192,192,224,224,240,240,248,248};
  31. static const unsigned char big_hex_border_left_rev[] = {248,248,120,120,56,56,24,24,8,8};
  32. // 44*8
  33. static const unsigned char level_spr[] = {192,127,176,223,236,0,192,127,176,223,236,0,192,96,48,216,12,0,192,127,176,223,236,0,192,127,176,223,236,0,192,96,48,216,12,0,255,127,191,223,239,240,127,63,191,143,231,240};
  34. static const unsigned char level_spr_rev[] = {63,128,79,32,19,240,63,128,79,32,19,240,63,159,207,39,243,240,63,128,79,32,19,240,63,128,79,32,19,240,63,159,207,39,243,240,0,128,64,32,16,0,128,192,64,112,24,0};
  35. static const unsigned char num_0[] = {127,255,195,195,195,195,255,254};
  36. static const unsigned char num_1[] = {240,248,24,24,24,24,255,255};
  37. static const unsigned char num_2[] = {255,255,3,127,254,192,255,255};
  38. static const unsigned char num_3[] = {254,255,3,255,255,3,255,254};
  39. static const unsigned char num_4[] = {195,195,195,255,127,3,3,3};
  40. static const unsigned char num_5[] = {255,255,192,254,127,3,255,255};
  41. static const unsigned char num_6[] = {255,255,192,254,255,195,255,255};
  42. static const unsigned char num_7[] = {254,255,3,3,3,3,3,3};
  43. static const unsigned char num_8[] = {127,255,195,255,255,195,255,254};
  44. static const unsigned char num_9[] = {255,255,195,255,127,3,255,255};
  45. static const unsigned char num_0_rev[] = {128,0,60,60,60,60,0,1};
  46. static const unsigned char num_1_rev[] = {15,7,231,231,231,231,0,0};
  47. static const unsigned char num_2_rev[] = {0,0,252,128,1,63,0,0};
  48. static const unsigned char num_3_rev[] = {1,0,252,0,0,252,0,1};
  49. static const unsigned char num_4_rev[] = {60,60,60,0,128,252,252,252};
  50. static const unsigned char num_5_rev[] = {0,0,63,1,128,252,0,0};
  51. static const unsigned char num_6_rev[] = {0,0,63,1,0,60,0,0};
  52. static const unsigned char num_7_rev[] = {1,0,252,252,252,252,252,252};
  53. static const unsigned char num_8_rev[] = {128,0,60,0,0,60,0,1};
  54. static const unsigned char num_9_rev[] = {0,0,60,0,128,252,0,0};
  55. static const unsigned char *num_tab[10] = {
  56. num_0,
  57. num_1,
  58. num_2,
  59. num_3,
  60. num_4,
  61. num_5,
  62. num_6,
  63. num_7,
  64. num_8,
  65. num_9
  66. };
  67. static const unsigned char *num_tab_rev[10] = {
  68. num_0_rev,
  69. num_1_rev,
  70. num_2_rev,
  71. num_3_rev,
  72. num_4_rev,
  73. num_5_rev,
  74. num_6_rev,
  75. num_7_rev,
  76. num_8_rev,
  77. num_9_rev
  78. };
  79. static const unsigned char *step_text[6] = {
  80. "Point",
  81. "Line",
  82. "Triangle",
  83. "Square",
  84. "Pentagon",
  85. "Hexagon"
  86. };
  87. void draw_game(Game_Data *data)
  88. {
  89. fillBackground(data);
  90. // draw the player and the lines
  91. drawPlayer(data, data->player_angle);
  92. drawPolygon(data, data->nb_lines, data->line_transition);
  93. drawDiagonals(data, data->nb_lines, data->line_transition);
  94. // showing the walls
  95. if(data->list != NULL)
  96. drawWalls(data->list, data, data->nb_lines, data->line_transition);
  97. drawHud(data);
  98. }
  99. void draw_title(Game_Data *data)
  100. {
  101. fillBackground(data);
  102. ML_bmp_or(title_spr, 12, (64-26)/2, 62, 26);
  103. drawPolygon(data, data->nb_lines, data->line_transition);
  104. drawDiagonals(data, data->nb_lines, data->line_transition);
  105. drawBottomLeftCornerText("Press Shift", data->are_colors_reversed);
  106. drawTopRightCornerText("By Eiyeron & Adbook", data->are_colors_reversed);
  107. }
  108. void draw_menu(Game_Data *data)
  109. {
  110. char highscore_text[50] = {0};
  111. sprintf(highscore_text, "Best time : %.2f", data->entry_highscores[data->current_entry - 1]);
  112. fillBackground(data);
  113. drawPolygon(data, data->nb_lines, data->line_transition);
  114. drawDiagonals(data, data->nb_lines, data->line_transition);
  115. drawPlayer(data, (360 - data->cam.angle + 270)%360);
  116. drawTopRightCornerText(data->entry_difficulties[data->current_entry - 1], data->are_colors_reversed);
  117. if(data->current_entry > 3) {
  118. // Hyper Mode
  119. drawTopLeftCornerText("Hyper Mode", data->are_colors_reversed);
  120. drawTopLeftCornerTextOffset(highscore_text, data->are_colors_reversed, 8);
  121. drawTopLeftCornerTextOffset(step_text[getLevel(data)], data->are_colors_reversed, 16);
  122. } else {
  123. drawTopRightCornerTextOffset(highscore_text, data->are_colors_reversed, 8);
  124. drawTopRightCornerTextOffset(step_text[getLevel(data)], data->are_colors_reversed, 16);
  125. }
  126. }
  127. void draw_game_over(Game_Data *data)
  128. {
  129. const int time_y_position = 21;
  130. const int time_border_y_position = time_y_position - 1;
  131. const int time_bottom_border_y_position = time_border_y_position + 9;
  132. const int level_y_position = 10;
  133. const int level_border_y_position = level_y_position - 1;
  134. const int level_bottom_border_y_position = level_border_y_position + 9;
  135. const int x_offset = 2;
  136. const int level_num_x_position = 44+2 + x_offset; // offset from level sprite
  137. int time_length;
  138. unsigned char int_time_text[32];
  139. unsigned char decimal_text[32];
  140. unsigned char level_text[2] = "0";
  141. level_text[0] = getLevel(data) + '1';
  142. sprintf(int_time_text, "%u", (int)data->chrono_time);
  143. sprintf(decimal_text, ":%02u", (int)(data->chrono_time*100)%100);
  144. time_length = time_length = 9*strlen(int_time_text);
  145. fillBackground(data);
  146. drawPolygon(data, data->nb_lines, data->line_transition);
  147. drawDiagonals(data, data->nb_lines, data->line_transition);
  148. if(!data->are_colors_reversed) {
  149. ML_rectangle(0, level_border_y_position, level_num_x_position + 9, level_bottom_border_y_position, 0, BLACK, BLACK);
  150. ML_bmp_or(big_hex_border_left, level_num_x_position + 9, level_border_y_position, 5, 10);
  151. ML_bmp_and(level_spr_rev, x_offset, level_y_position, 44, 8);
  152. ML_rectangle(0, time_border_y_position, time_length + 3*4, time_bottom_border_y_position, 0, BLACK, BLACK);
  153. ML_bmp_or(big_hex_border_left, time_length + 3*4, time_border_y_position, 5, 10);
  154. PrintMini(time_length + x_offset, time_y_position, decimal_text, MINI_REV);
  155. }
  156. else {
  157. ML_rectangle(0, level_border_y_position, level_num_x_position + 9, level_bottom_border_y_position, 0, WHITE, WHITE);
  158. ML_bmp_and(big_hex_border_left_rev, level_num_x_position + 9 + 1, level_border_y_position, 4, 10);
  159. ML_bmp_or(level_spr, x_offset, level_y_position, 44, 8);
  160. ML_rectangle(0, time_border_y_position, time_length + 3*4, time_bottom_border_y_position, 0, WHITE, WHITE);
  161. ML_bmp_and(big_hex_border_left_rev, time_length + 3*4 + 1, time_border_y_position, 4, 10);
  162. PrintMini(time_length + x_offset, time_y_position, decimal_text, MINI_OVER);
  163. }
  164. draw_big_num(level_text, level_num_x_position, level_y_position, !data->are_colors_reversed);
  165. draw_big_num(int_time_text, x_offset, time_y_position, !data->are_colors_reversed);
  166. drawTopLeftCornerText(step_text[getLevel(data)], data->are_colors_reversed);
  167. if(data->it_s_a_highscore) {
  168. drawTopRightCornerText("New highscore!", data->are_colors_reversed);
  169. }
  170. drawBottomRightCornerText("Shift to retry", data->are_colors_reversed);
  171. }
  172. void draw_oom(Game_Data* data) {
  173. fillBackground(data);
  174. drawPolygon(data, data->nb_lines, data->line_transition);
  175. drawDiagonals(data, data->nb_lines, data->line_transition);
  176. drawTopRightCornerText("Oops! Out of Memory", data->are_colors_reversed);
  177. drawTopRightCornerTextOffset("Your progress will be saved.", data->are_colors_reversed, 8);
  178. drawBottomLeftCornerText("Press EXIT to quit.", data->are_colors_reversed);
  179. }
  180. static void fillBackground(Game_Data *data) {
  181. if(data->are_colors_reversed) {
  182. int i, end, *pointer_long, vram;
  183. char *pointer_byte;
  184. vram = (int)ML_vram_adress();
  185. end = 4-vram&3;
  186. pointer_byte = (char*)vram;
  187. for(i=0 ; i<end ; i++) pointer_byte[i] = 0xFF;
  188. pointer_long = (int*) (vram+end);
  189. for(i=0 ; i<255 ; i++) pointer_long[i] = 0xFFFFFFFF;
  190. pointer_byte += 1020+end;
  191. end = vram&3;
  192. for(i=0 ; i<end ; i++) pointer_byte[i] = 0xFF;
  193. } else {
  194. ML_clear_vram();
  195. }
  196. }
  197. static void drawChrono(Game_Data *data) {
  198. unsigned char time_text[32] = "";
  199. sprintf(time_text, "%.2f", data->chrono_time);
  200. if(data->chrono_time < 60) {
  201. // Drawing the text with the little progress bar. As I offset the text,
  202. // I need to remake the whole routine.
  203. ML_Color drawing_color = data->are_colors_reversed ? WHITE : BLACK;
  204. unsigned int text_color = data->are_colors_reversed ? MINI_OVER : MINI_REV;
  205. unsigned short length_of_time, length_of_time_line;
  206. length_of_time = strlen(time_text);
  207. length_of_time_line = 4 * length_of_time;
  208. PrintMini(0, 0, time_text, text_color);
  209. ML_horizontal_line(6, 0, (data->chrono_time/60.) * (length_of_time_line - 2), drawing_color);
  210. ML_horizontal_line(7, 0, length_of_time_line - 1, drawing_color);
  211. if(!data->are_colors_reversed) {
  212. ML_bmp_8_or(hex_border_top_left, length_of_time_line, 0);
  213. } else {
  214. ML_bmp_8_and(hex_border_top_left_rev, length_of_time_line, 0);
  215. }
  216. }
  217. else {
  218. drawTopLeftCornerText(time_text, data->are_colors_reversed);
  219. }
  220. }
  221. static int getLevel(Game_Data *data) {
  222. unsigned short step_time[5] = {
  223. 10,
  224. 20,
  225. 30,
  226. 45,
  227. 60
  228. };
  229. unsigned short current_step, i;
  230. current_step = 5;
  231. for(i = 0; i < 5; i++) {
  232. if(data->chrono_time < step_time[i]) {
  233. current_step = i;
  234. break;
  235. }
  236. }
  237. return current_step;
  238. }
  239. static void drawHud(Game_Data *data) {
  240. drawChrono(data);
  241. drawTopRightCornerText(step_text[getLevel(data)], data->are_colors_reversed);
  242. }
  243. static void drawPolygon(Game_Data *data, int nb_lines, Line_Transition line_transition) {
  244. int x[32];
  245. int y[32];
  246. int i = 0;
  247. int angle = 0;
  248. Camera* cam= &data->cam;
  249. ML_Color drawing_color = data->are_colors_reversed ? WHITE : BLACK;
  250. float tmp_angle = 0.0;
  251. float transition_angle = 0.0;
  252. float delta_angle = 0.0;
  253. if(line_transition.delta_nb_lines == 1)
  254. nb_lines ++;
  255. if(line_transition.counter_start != 0)
  256. transition_angle = (360.0 / (float)nb_lines) * ((float)line_transition.counter / (float)line_transition.counter_start);
  257. delta_angle = 360.0/nb_lines;
  258. do
  259. {
  260. // TODO : use fixed for only two trig calls?
  261. x[i] = (8. + cam->zoom)*cos(PI * (tmp_angle + cam->angle)/180.) + cam->cX;
  262. y[i] = (8. + cam->zoom)*sin(PI * (tmp_angle + cam->angle)/180.) + cam->cY;
  263. i++;
  264. switch(line_transition.delta_nb_lines)
  265. {
  266. case 0:
  267. tmp_angle += delta_angle;
  268. break;
  269. case 1:
  270. if(i < nb_lines)
  271. tmp_angle += (360 - (delta_angle - transition_angle)) / (nb_lines - 1);
  272. else
  273. tmp_angle += delta_angle - transition_angle;
  274. break;
  275. case -1:
  276. if(i < nb_lines)
  277. tmp_angle += (360 - transition_angle) / (nb_lines - 1);
  278. else
  279. tmp_angle = transition_angle;
  280. break;
  281. }
  282. }while(i <= nb_lines);
  283. // draw the aforementionned circle, depending on the camera's center
  284. // ML_filled_circle(cam.cX, cam.cY, 6, BLACK);
  285. ML_polygone(x, y, nb_lines, drawing_color);
  286. // draw the player. At such a low scale, it was impossible to draw a rotating triangle, so its a radius 1 circle instead.
  287. // TODO : Replace it for a quick sprite blit, or unwrapped ML_pixel procedure.
  288. }
  289. // draws the player
  290. // at first, was supposed to draw an hexagon in the center, plus a triangle to show the player,
  291. // but the hexagon was not visible, and it was a pixel mess, so we're showing a circle instead.
  292. // there is still for code to calculate the vertices of the hexagon, in case we want to change that again
  293. static void drawPlayer(Game_Data *data, int player_angle)
  294. {
  295. ML_Color drawing_color = data->are_colors_reversed ? WHITE : BLACK;
  296. ML_point((9. + data->cam.zoom)*cos( PI*(player_angle + data->cam.angle)/180) + data->cam.cX, (9. + data->cam.zoom)*sin( PI*(player_angle+data->cam.angle)/180) + data->cam.cY, 3, drawing_color);
  297. }
  298. // draws one of the three rotating lines
  299. static void drawDiagonals(Game_Data *data, int nb_lines, Line_Transition line_transition)
  300. {
  301. fix tmp_angle = FIX(data->cam.angle);
  302. int i = 0;
  303. fix x1 = 0, y1 = 0, x2 = 0, y2 = 0;
  304. fix delta_angle = 0;
  305. fix coeff = 0;
  306. fix transition_angle = 0;
  307. ML_Color drawing_color = data->are_colors_reversed ? WHITE : BLACK;
  308. delta_angle = fdiv(FIX(360), FIX(nb_lines));
  309. if(line_transition.delta_nb_lines == 1)
  310. nb_lines ++;
  311. if(line_transition.counter_start != 0)
  312. coeff = fdiv(FIX(line_transition.counter), FIX(line_transition.counter_start));
  313. transition_angle = fmul(delta_angle, coeff);
  314. do{
  315. x1 = fmul(FIX(9) + ftofix(data->cam.zoom), fcos(tmp_angle));
  316. y1 = fmul(FIX(9) + ftofix(data->cam.zoom), fsin(tmp_angle));
  317. x2 = fmul(fcos(tmp_angle), FIX(128));
  318. y2 = fmul(fsin(tmp_angle), FIX(128));
  319. ML_line(UNFIX(x1) + data->cam.cX, UNFIX(y1) + data->cam.cY, UNFIX(x2) + data->cam.cX, UNFIX(y2) + data->cam.cY, drawing_color);
  320. i++;
  321. switch(line_transition.delta_nb_lines){
  322. case 0:
  323. tmp_angle += fdiv(FIX(360), FIX(nb_lines));
  324. break;
  325. case 1:
  326. if(i < nb_lines - 1)
  327. {
  328. tmp_angle += fdiv(FIX(360) - (delta_angle - transition_angle), FIX(nb_lines - 1));
  329. }else{
  330. tmp_angle += delta_angle - transition_angle;
  331. }
  332. break;
  333. case -1:
  334. if(i < nb_lines - 1)
  335. {
  336. tmp_angle += fdiv(FIX(360) - transition_angle, FIX(nb_lines - 1));
  337. }else{
  338. tmp_angle += transition_angle;
  339. }
  340. break;
  341. }
  342. if(tmp_angle >= FIX(360)) tmp_angle = tmp_angle - FIX(359);
  343. }while(i < nb_lines);
  344. }
  345. static unsigned int length_of_print_string(unsigned char* txt) {
  346. // TODO : define
  347. unsigned int text_length = 0;
  348. unsigned int i;
  349. unsigned int current_char_length = 0;
  350. for(i = 0; i < strlen(txt); i++) {
  351. switch(txt[i]) {
  352. // upper case
  353. case 'K':
  354. case 'M':
  355. case 'N':
  356. case 'Q':
  357. case 'W':
  358. current_char_length = 6;
  359. break;
  360. // lower case
  361. case 'i':
  362. current_char_length = 2;
  363. break;
  364. case 'n':
  365. case 'r':
  366. current_char_length = 5;
  367. break;
  368. case 'm':
  369. case 'w':
  370. current_char_length = 6;
  371. break;
  372. case '!':
  373. current_char_length = 2;
  374. break;
  375. case '&':
  376. current_char_length = 5;
  377. break;
  378. case '[':
  379. case ']':
  380. /*case '.':*/
  381. case '\'':
  382. current_char_length = 3;
  383. break;
  384. default:
  385. current_char_length = 4;
  386. break;
  387. }
  388. text_length += current_char_length;
  389. }
  390. return text_length;
  391. }
  392. static void drawTopLeftCornerTextOffset(unsigned char* txt, unsigned char isReversed, int y) {
  393. ML_Color drawing_color = isReversed ? WHITE : BLACK;
  394. unsigned int text_color = isReversed ? MINI_OVER : MINI_REV;
  395. unsigned int text_length = length_of_print_string(txt);
  396. if(!isReversed) {
  397. ML_bmp_8_or(hex_border_top_left, text_length, y);
  398. } else {
  399. ML_bmp_8_and(hex_border_top_left_rev, text_length, y);
  400. }
  401. PrintMini(0, y + 1, txt, text_color);
  402. ML_horizontal_line(7 + y, 0, text_length, drawing_color);
  403. }
  404. static void drawTopLeftCornerText(unsigned char* txt, unsigned char isReversed) {
  405. drawTopLeftCornerTextOffset(txt, isReversed, 0);
  406. }
  407. static void drawTopRightCornerTextOffset(unsigned char* txt, unsigned char isReversed, int y) {
  408. ML_Color drawing_color = isReversed ? WHITE : BLACK;
  409. unsigned int text_color = isReversed ? MINI_OVER : MINI_REV;
  410. int text_length = length_of_print_string(txt);
  411. int xPosition = 128 - text_length;
  412. if(!isReversed) {
  413. ML_bmp_8_or(hex_border_top_right, xPosition - 8, y);
  414. } else {
  415. ML_bmp_8_and(hex_border_top_right_rev, xPosition - 8, y);
  416. }
  417. PrintMini(xPosition, y + 1, txt, text_color);
  418. ML_horizontal_line(7 + y, xPosition, 127, drawing_color);
  419. }
  420. static void drawTopRightCornerText(unsigned char* txt, unsigned char isReversed) {
  421. drawTopRightCornerTextOffset(txt, isReversed, 0);
  422. }
  423. static void drawBottomLeftCornerText(unsigned char* txt, unsigned char isReversed) {
  424. ML_Color drawing_color = isReversed ? WHITE : BLACK;
  425. unsigned int text_length = length_of_print_string(txt);
  426. unsigned int text_color = isReversed ? MINI_OVER : MINI_REV;
  427. if(!isReversed) {
  428. ML_bmp_8_or(hex_border_bottom_left, text_length - 1, 56);
  429. } else {
  430. ML_bmp_8_and(hex_border_bottom_left_rev, text_length - 1, 56);
  431. }
  432. PrintMini(0, 57, txt, text_color);
  433. ML_horizontal_line(63, 0, text_length, drawing_color);
  434. }
  435. static void drawBottomRightCornerText(unsigned char* txt, unsigned char isReversed) {
  436. ML_Color drawing_color = isReversed ? WHITE : BLACK;
  437. unsigned int text_color = isReversed ? MINI_OVER : MINI_REV;
  438. int text_length = length_of_print_string(txt);
  439. int xPosition = 128 - text_length;
  440. if(!isReversed) {
  441. ML_bmp_8_or(hex_border_bottom_right, xPosition - 8, 56);
  442. } else {
  443. ML_bmp_8_and(hex_border_bottom_right_rev, xPosition - 8, 56);
  444. }
  445. ML_horizontal_line(63, xPosition, 127, drawing_color);
  446. PrintMini(xPosition, 57, txt, text_color);
  447. }
  448. static void draw_big_num(unsigned char *txt, int x, int y, unsigned char isReversed) {
  449. int i;
  450. for(i = 0; i < strlen(txt); i++) {
  451. if(txt[i] >= '0' && txt[i] <= '9')
  452. if(isReversed)
  453. ML_bmp_8_and(num_tab_rev[txt[i] - '0'], x + 9*i, y);
  454. else
  455. ML_bmp_8_or(num_tab[txt[i] - '0'], x + 9*i, y);
  456. }
  457. }