tama_p1.c 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. #include <furi.h>
  2. #include <gui/gui.h>
  3. #include <input/input.h>
  4. #include <storage/storage.h>
  5. #include <stdlib.h>
  6. #include <stm32wbxx_ll_tim.h>
  7. #include "tamalib/tamalib.h"
  8. #include "tama.h"
  9. #include "compiled/assets_icons.h"
  10. TamaApp* g_ctx;
  11. FuriMutex* g_state_mutex;
  12. uint8_t layout_mode = 0; // 3: portrait => 4: portrait <=
  13. // 0: landscape (small) 1: landscape (big) 2: landscape (full)
  14. bool in_menu = false;
  15. uint8_t speed = 1;
  16. const uint8_t speed_options[] = {1, 2, 4};
  17. const uint8_t min_speed = 1;
  18. const uint8_t max_speed = 4;
  19. const uint8_t speed_options_size = 3;
  20. // = sizeof(speed_options) / sizeof(speed_options[0]);
  21. uint8_t menu_cursor = 3; // 0: layout mode; 1: speed; 2: A+C;
  22. const uint8_t menu_items = 4; // 3: Close menu, Save & Exit
  23. uint8_t sub_menu_buttons = 0;
  24. uint8_t sub_menu_last = 0;
  25. static const Icon* icons_list[] = {
  26. &I_icon_0,
  27. &I_icon_1,
  28. &I_icon_2,
  29. &I_icon_3,
  30. &I_icon_4,
  31. &I_icon_5,
  32. &I_icon_6,
  33. &I_icon_7,
  34. };
  35. // static void draw_landscape(Canvas* const canvas, void* cb_ctx)
  36. static void draw_landscape(Canvas* const canvas, uint8_t scale) {
  37. // FURI_LOG_D(TAG, "Drawing frame");
  38. // Calculate positioning
  39. uint16_t canv_width = canvas_width(canvas);
  40. uint16_t canv_height = canvas_height(canvas);
  41. uint16_t lcd_matrix_scaled_width = 32 * scale;
  42. uint16_t lcd_matrix_scaled_height = 16 * scale;
  43. uint16_t lcd_matrix_top = (canv_height - lcd_matrix_scaled_height) / 2; // 0
  44. uint16_t lcd_matrix_left = (canv_width - lcd_matrix_scaled_width) / 2;
  45. // uint16_t lcd_icon_upper_top = lcd_matrix_top - TAMA_LCD_ICON_SIZE - TAMA_LCD_ICON_MARGIN;
  46. // uint16_t lcd_icon_lower_top = lcd_matrix_top + lcd_matrix_scaled_height + TAMA_LCD_ICON_MARGIN;
  47. uint16_t lcd_icon_upper_left = lcd_matrix_left;
  48. uint16_t lcd_icon_lower_left = lcd_matrix_left;
  49. uint16_t lcd_icon_spacing_horiz =
  50. (lcd_matrix_scaled_width - (4 * TAMA_LCD_ICON_SIZE)) / 3 + TAMA_LCD_ICON_SIZE;
  51. uint16_t y = lcd_matrix_top;
  52. for(uint8_t row = 0; row < 16; ++row) {
  53. uint16_t x = lcd_matrix_left;
  54. uint32_t row_pixels = g_ctx->framebuffer[row];
  55. for(uint8_t col = 0; col < 32; ++col) {
  56. if(row_pixels & 1) {
  57. canvas_draw_box(canvas, x, y, scale, scale);
  58. }
  59. x += scale;
  60. row_pixels >>= 1;
  61. }
  62. y += scale;
  63. }
  64. // Start drawing icons
  65. uint8_t lcd_icons = g_ctx->icons;
  66. // Draw top icons
  67. y = 0;
  68. uint16_t x_ic = lcd_icon_upper_left;
  69. for(uint8_t i = 0; i < 4; ++i) {
  70. if(lcd_icons & 1) {
  71. canvas_draw_icon(canvas, x_ic, y, icons_list[i]);
  72. }
  73. // x_ic += TAMA_LCD_ICON_SIZE + 4;
  74. // if(scale == 3) {
  75. // y += 16;
  76. // } else {
  77. x_ic += lcd_icon_spacing_horiz;
  78. // }
  79. lcd_icons >>= 1;
  80. }
  81. // Draw bottom icons
  82. y = 64 - TAMA_LCD_ICON_SIZE;
  83. // if(scale == 3) {
  84. // y = 0;
  85. // x_ic = 128 - TAMA_LCD_ICON_SIZE;
  86. // x_ic = 0;
  87. // } else {
  88. // y = 64 - TAMA_LCD_ICON_SIZE;
  89. x_ic = lcd_icon_lower_left;
  90. // }
  91. for(uint8_t i = 4; i < 8; ++i) {
  92. // canvas_draw_frame(canvas, x_ic, y, TAMA_LCD_ICON_SIZE, TAMA_LCD_ICON_SIZE);
  93. if(lcd_icons & 1) {
  94. canvas_draw_icon(canvas, x_ic, y, icons_list[i]);
  95. }
  96. // if(scale == 3) {
  97. // y += 16;
  98. // } else {
  99. x_ic += lcd_icon_spacing_horiz;
  100. // }
  101. lcd_icons >>= 1;
  102. }
  103. }
  104. // static void draw_portrait_right(Canvas* const canvas, void* cb_ctx)
  105. static void draw_portrait_right(Canvas* const canvas, uint8_t scale) {
  106. // FURI_LOG_D(TAG, "Drawing frame");
  107. // Calculate positioning
  108. // uint16_t canv_width = canvas_width(canvas);
  109. uint16_t canv_height = canvas_height(canvas);
  110. uint16_t lcd_matrix_scaled_width = 32 * scale;
  111. uint16_t lcd_matrix_scaled_height = 16 * scale;
  112. // uint16_t lcd_matrix_top = 0;
  113. uint16_t lcd_matrix_top = (canv_height - lcd_matrix_scaled_height) / 2;
  114. // uint16_t lcd_matrix_left = (canv_width - lcd_matrix_scaled_width) / 2;
  115. uint16_t lcd_matrix_left = 64 - TAMA_LCD_ICON_SIZE;
  116. uint16_t lcd_icon_upper_left = lcd_matrix_left;
  117. uint16_t lcd_icon_lower_left = lcd_matrix_left;
  118. uint16_t lcd_icon_spacing_horiz =
  119. (lcd_matrix_scaled_width - (4 * TAMA_LCD_ICON_SIZE)) / 3 + TAMA_LCD_ICON_SIZE;
  120. uint16_t y = lcd_matrix_top; // 64
  121. for(uint8_t row = 0; row < 16; ++row) {
  122. uint16_t x = 128; // lcd_matrix_left
  123. uint32_t row_pixels = g_ctx->framebuffer[row];
  124. for(uint8_t col = 0; col < 32; ++col) {
  125. if(row_pixels & 1) {
  126. canvas_draw_box(canvas, y + 32, x - 66, scale, scale);
  127. }
  128. x -= scale;
  129. row_pixels >>= 1;
  130. }
  131. y += scale;
  132. }
  133. // Start drawing icons
  134. uint8_t lcd_icons = g_ctx->icons;
  135. // Draw top icons
  136. // y = lcd_icon_upper_top;
  137. y = 30;
  138. // y = 64 - TAMA_LCD_ICON_SIZE;
  139. uint16_t x_ic = lcd_icon_upper_left;
  140. // uint16_t x_ic = 64 - TAMA_LCD_ICON_SIZE;
  141. for(uint8_t i = 0; i < 4; ++i) {
  142. if(lcd_icons & 1) {
  143. canvas_draw_icon(canvas, y, x_ic, icons_list[i]);
  144. }
  145. x_ic -= lcd_icon_spacing_horiz; // TAMA_LCD_ICON_SIZE + 4;
  146. lcd_icons >>= 1;
  147. }
  148. // Draw bottom icons
  149. y = 84; // lcd_icon_lower_top
  150. x_ic = lcd_icon_lower_left; // 64 - TAMA_LCD_ICON_SIZE
  151. for(uint8_t i = 4; i < 8; ++i) {
  152. // canvas_draw_frame(canvas, x_ic, y, TAMA_LCD_ICON_SIZE, TAMA_LCD_ICON_SIZE);
  153. if(lcd_icons & 1) {
  154. canvas_draw_icon(canvas, y, x_ic, icons_list[i]);
  155. }
  156. x_ic -= lcd_icon_spacing_horiz;
  157. lcd_icons >>= 1;
  158. }
  159. }
  160. static void draw_portrait_left(Canvas* const canvas, uint8_t scale) {
  161. // FURI_LOG_D(TAG, "Drawing frame");
  162. // Calculate positioning
  163. // uint16_t canv_width = canvas_width(canvas);
  164. // uint16_t canv_height = canvas_height(canvas);
  165. uint16_t lcd_matrix_scaled_width = 32 * scale;
  166. // uint16_t lcd_matrix_scaled_height = 16 * scale;
  167. // uint16_t lcd_matrix_top = 0;
  168. // uint16_t lcd_matrix_top = (canv_height - lcd_matrix_scaled_height) / 2;
  169. // uint16_t lcd_matrix_left = (canv_width - lcd_matrix_scaled_width) / 2;
  170. uint16_t lcd_matrix_left = 0;
  171. uint16_t lcd_icon_upper_left = lcd_matrix_left;
  172. uint16_t lcd_icon_lower_left = lcd_matrix_left;
  173. uint16_t lcd_icon_spacing_horiz =
  174. (lcd_matrix_scaled_width - (4 * TAMA_LCD_ICON_SIZE)) / 3 + TAMA_LCD_ICON_SIZE;
  175. // uint16_t y = 64 + lcd_matrix_top;
  176. uint16_t y = 64;
  177. for(uint8_t row = 0; row < 16; ++row) {
  178. uint16_t x = 0; // lcd_matrix_left
  179. uint32_t row_pixels = g_ctx->framebuffer[row];
  180. for(uint8_t col = 0; col < 32; ++col) {
  181. if(row_pixels & 1) {
  182. canvas_draw_box(canvas, y, x, scale, scale);
  183. }
  184. x += scale;
  185. row_pixels >>= 1;
  186. }
  187. y -= scale;
  188. }
  189. // Start drawing icons
  190. uint8_t lcd_icons = g_ctx->icons;
  191. // Draw top icons
  192. // y = lcd_icon_upper_top;
  193. y = 70;
  194. // y = 64 - TAMA_LCD_ICON_SIZE;
  195. uint16_t x_ic = lcd_icon_upper_left;
  196. // uint16_t x_ic = 64 - TAMA_LCD_ICON_SIZE;
  197. for(uint8_t i = 0; i < 4; ++i) {
  198. if(lcd_icons & 1) {
  199. canvas_draw_icon(canvas, y, x_ic, icons_list[i]);
  200. }
  201. x_ic += lcd_icon_spacing_horiz; // TAMA_LCD_ICON_SIZE + 4;
  202. lcd_icons >>= 1;
  203. }
  204. // Draw bottom icons
  205. y = 16; // lcd_icon_lower_top
  206. x_ic = lcd_icon_lower_left; // 64 - TAMA_LCD_ICON_SIZE
  207. for(uint8_t i = 4; i < 8; ++i) {
  208. // canvas_draw_frame(canvas, x_ic, y, TAMA_LCD_ICON_SIZE, TAMA_LCD_ICON_SIZE);
  209. if(lcd_icons & 1) {
  210. canvas_draw_icon(canvas, y, x_ic, icons_list[i]);
  211. }
  212. x_ic += lcd_icon_spacing_horiz;
  213. lcd_icons >>= 1;
  214. }
  215. }
  216. // static void draw_mini(Canvas* const canvas, uint16_t inX, uint16_t inY)
  217. static void draw_mini(Canvas* const canvas) {
  218. // Calculate positioning
  219. // uint16_t y = inY;
  220. uint16_t y = 34;
  221. for(uint8_t row = 0; row < 16; ++row) {
  222. // uint16_t x = inX;
  223. uint16_t x = 84;
  224. uint32_t row_pixels = g_ctx->framebuffer[row];
  225. for(uint8_t col = 0; col < 32; ++col) {
  226. if(row_pixels & 1) {
  227. canvas_draw_dot(canvas, x, y);
  228. }
  229. x += 1;
  230. row_pixels >>= 1;
  231. }
  232. y += 1;
  233. }
  234. // Start drawing icons
  235. uint8_t lcd_icons = g_ctx->icons;
  236. // Draw top icons
  237. y = 32;
  238. uint16_t x_ic = 84;
  239. for(uint8_t i = 0; i < 4; ++i) {
  240. if(lcd_icons & 1) {
  241. // canvas_draw_icon(canvas, x_ic, y, icons_list[i]);
  242. canvas_draw_line(canvas, x_ic, y, x_ic + 6, y);
  243. }
  244. x_ic += 8;
  245. lcd_icons >>= 1;
  246. }
  247. // Draw bottom icons
  248. y = 51;
  249. x_ic = 84;
  250. for(uint8_t i = 4; i < 8; ++i) {
  251. // canvas_draw_frame(canvas, x_ic, y, TAMA_LCD_ICON_SIZE, TAMA_LCD_ICON_SIZE);
  252. if(lcd_icons & 1) {
  253. // canvas_draw_icon(canvas, x_ic, y, icons_list[i]);
  254. canvas_draw_line(canvas, x_ic, y, x_ic + 6, y);
  255. }
  256. x_ic += 8;
  257. lcd_icons >>= 1;
  258. }
  259. }
  260. // static void draw_menu_portrait(Canvas* const canvas, void* cb_ctx) {}
  261. // static void draw_menu_landscape(Canvas* const canvas)
  262. static void draw_menu(Canvas* const canvas) {
  263. canvas_draw_frame(canvas, 0, 0, 128, 64);
  264. canvas_draw_str_aligned(canvas, 64, 6, AlignCenter, AlignCenter, "Menu");
  265. canvas_draw_line(canvas, 0, 10, 128, 10);
  266. draw_mini(canvas);
  267. // draw_mini(canvas, 34, 84);
  268. switch(menu_cursor) {
  269. case 0:
  270. canvas_draw_triangle(canvas, 4, 16, 6, 6, CanvasDirectionLeftToRight);
  271. break;
  272. case 1:
  273. canvas_draw_triangle(canvas, 4, 26, 6, 6, CanvasDirectionLeftToRight);
  274. break;
  275. case 2:
  276. switch(sub_menu_buttons) {
  277. case 0:
  278. canvas_draw_triangle(canvas, 4, 36, 6, 6, CanvasDirectionLeftToRight);
  279. break;
  280. case 1:
  281. canvas_draw_triangle(canvas, 47, 44, 6, 4, CanvasDirectionBottomToTop);
  282. break;
  283. case 2:
  284. canvas_draw_triangle(canvas, 57, 44, 6, 4, CanvasDirectionBottomToTop);
  285. break;
  286. case 3:
  287. canvas_draw_triangle(canvas, 67, 44, 6, 4, CanvasDirectionBottomToTop);
  288. break;
  289. default:
  290. break;
  291. }
  292. break;
  293. case menu_items - 1:
  294. switch(sub_menu_last) {
  295. case 0:
  296. canvas_draw_triangle(canvas, 4, 56, 6, 6, CanvasDirectionLeftToRight);
  297. break;
  298. case 1:
  299. canvas_draw_triangle(canvas, 36, 56, 6, 6, CanvasDirectionLeftToRight);
  300. break;
  301. case 2:
  302. canvas_draw_triangle(canvas, 67, 56, 6, 6, CanvasDirectionLeftToRight);
  303. break;
  304. default:
  305. break;
  306. }
  307. break;
  308. }
  309. switch(layout_mode) {
  310. case 0:
  311. canvas_draw_str(canvas, 12, 20, "Layout: Landscape (small)");
  312. break;
  313. case 1:
  314. canvas_draw_str(canvas, 12, 20, "Layout: Landscape (big)");
  315. break;
  316. case 2:
  317. canvas_draw_str(canvas, 12, 20, "Layout: Landscape (full)");
  318. break;
  319. case 3:
  320. canvas_draw_str(canvas, 12, 20, "Layout: Portrait =>");
  321. break;
  322. case 4:
  323. canvas_draw_str(canvas, 12, 20, "Layout: Portrait <=");
  324. break;
  325. default:
  326. canvas_draw_str(canvas, 12, 20, "Layout: ???");
  327. break;
  328. }
  329. switch(speed) { // match with speed_options
  330. // case 0: // freeze menu too
  331. // canvas_draw_str(canvas, 12, 30, "Speed: 0x");
  332. // break;
  333. case 1:
  334. canvas_draw_str(canvas, 12, 30, "Speed: 1x");
  335. break;
  336. case 2:
  337. canvas_draw_str(canvas, 12, 30, "Speed: 2x");
  338. break;
  339. // case 3:
  340. // canvas_draw_str(canvas, 12, 30, "Speed: 3x");
  341. // break;
  342. case 4:
  343. canvas_draw_str(canvas, 12, 30, "Speed: 4x (max)");
  344. break;
  345. // case 8: // can't handle 8x
  346. // canvas_draw_str(canvas, 12, 40, "Speed: 8x (max)");
  347. // break;
  348. default:
  349. canvas_draw_str(canvas, 12, 30, "Speed ??x");
  350. break;
  351. }
  352. canvas_draw_str(canvas, 12, 40, "A+C");
  353. canvas_draw_str(canvas, 45, 40, "A");
  354. canvas_draw_str(canvas, 55, 40, "B");
  355. canvas_draw_str(canvas, 65, 40, "C");
  356. canvas_draw_str(canvas, 12, 60, "Close");
  357. canvas_draw_str(canvas, 44, 60, "Save");
  358. canvas_draw_str(canvas, 75, 60, "Save & Exit");
  359. }
  360. static void speed_up() {
  361. switch(speed) {
  362. case max_speed:
  363. speed = speed_options[0];
  364. break;
  365. default:
  366. for(uint8_t i = 0; i < speed_options_size - 1; i++) {
  367. if(speed == speed_options[i]) {
  368. speed = speed_options[i + 1];
  369. break;
  370. }
  371. }
  372. break;
  373. }
  374. tamalib_set_speed(speed);
  375. }
  376. static void speed_down() {
  377. switch(speed) {
  378. case min_speed:
  379. speed = speed_options[speed_options_size - 1];
  380. break;
  381. default:
  382. for(uint8_t i = speed_options_size - 1; i > 0; i--) {
  383. if(speed == speed_options[i]) {
  384. speed = speed_options[i - 1];
  385. break;
  386. }
  387. }
  388. break;
  389. }
  390. tamalib_set_speed(speed);
  391. }
  392. static void tama_p1_draw_callback(Canvas* const canvas, void* cb_ctx) {
  393. furi_assert(cb_ctx);
  394. FuriMutex* const mutex = cb_ctx;
  395. if(furi_mutex_acquire(mutex, 25) != FuriStatusOk) return;
  396. if(g_ctx->rom == NULL) {
  397. canvas_set_font(canvas, FontPrimary);
  398. canvas_draw_str(canvas, 30, 30, "No ROM");
  399. } else if(g_ctx->halted) {
  400. canvas_set_font(canvas, FontPrimary);
  401. canvas_draw_str(canvas, 30, 30, "Halted");
  402. } else {
  403. if(in_menu) {
  404. // switch(layout_mode)
  405. // draw_menu_landscape(canvas);
  406. draw_menu(canvas);
  407. } else {
  408. switch(layout_mode) {
  409. case 0:
  410. draw_landscape(canvas, TAMA_SCREEN_SCALE_FACTOR); // 2
  411. break;
  412. case 1:
  413. draw_landscape(canvas, 3);
  414. break;
  415. case 2:
  416. draw_landscape(canvas, 4);
  417. break;
  418. case 3:
  419. draw_portrait_right(canvas, TAMA_SCREEN_SCALE_FACTOR);
  420. break;
  421. case 4:
  422. draw_portrait_left(canvas, TAMA_SCREEN_SCALE_FACTOR);
  423. break;
  424. default:
  425. break;
  426. }
  427. }
  428. }
  429. furi_mutex_release(mutex);
  430. }
  431. static void tama_p1_input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) {
  432. furi_assert(event_queue);
  433. TamaEvent event = {.type = EventTypeInput, .input = *input_event};
  434. furi_message_queue_put(event_queue, &event, FuriWaitForever);
  435. }
  436. static void tama_p1_update_timer_callback(FuriMessageQueue* event_queue) {
  437. furi_assert(event_queue);
  438. TamaEvent event = {.type = EventTypeTick};
  439. furi_message_queue_put(event_queue, &event, 0);
  440. }
  441. static void tama_p1_load_state() {
  442. state_t* state;
  443. uint8_t buf[4];
  444. bool error = false;
  445. state = tamalib_get_state();
  446. Storage* storage = furi_record_open(RECORD_STORAGE);
  447. File* file = storage_file_alloc(storage);
  448. if(storage_file_open(file, TAMA_SAVE_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
  449. storage_file_read(file, &buf, 4);
  450. if(buf[0] != (uint8_t)STATE_FILE_MAGIC[0] || buf[1] != (uint8_t)STATE_FILE_MAGIC[1] ||
  451. buf[2] != (uint8_t)STATE_FILE_MAGIC[2] || buf[3] != (uint8_t)STATE_FILE_MAGIC[3]) {
  452. FURI_LOG_E(TAG, "FATAL: Wrong state file magic in \"%s\" !\n", TAMA_SAVE_PATH);
  453. error = true;
  454. }
  455. storage_file_read(file, &buf, 1);
  456. if(buf[0] != STATE_FILE_VERSION) {
  457. FURI_LOG_E(TAG, "FATAL: Unsupported version");
  458. error = true;
  459. }
  460. if(!error) {
  461. FURI_LOG_D(TAG, "Reading save.bin");
  462. storage_file_read(file, &buf, 2);
  463. *(state->pc) = buf[0] | ((buf[1] & 0x1F) << 8);
  464. storage_file_read(file, &buf, 2);
  465. *(state->x) = buf[0] | ((buf[1] & 0xF) << 8);
  466. storage_file_read(file, &buf, 2);
  467. *(state->y) = buf[0] | ((buf[1] & 0xF) << 8);
  468. storage_file_read(file, &buf, 1);
  469. *(state->a) = buf[0] & 0xF;
  470. storage_file_read(file, &buf, 1);
  471. *(state->b) = buf[0] & 0xF;
  472. storage_file_read(file, &buf, 1);
  473. *(state->np) = buf[0] & 0x1F;
  474. storage_file_read(file, &buf, 1);
  475. *(state->sp) = buf[0];
  476. storage_file_read(file, &buf, 1);
  477. *(state->flags) = buf[0] & 0xF;
  478. storage_file_read(file, &buf, 4);
  479. *(state->tick_counter) = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
  480. storage_file_read(file, &buf, 4);
  481. *(state->clk_timer_timestamp) = buf[0] | (buf[1] << 8) | (buf[2] << 16) |
  482. (buf[3] << 24);
  483. storage_file_read(file, &buf, 4);
  484. *(state->prog_timer_timestamp) = buf[0] | (buf[1] << 8) | (buf[2] << 16) |
  485. (buf[3] << 24);
  486. storage_file_read(file, &buf, 1);
  487. *(state->prog_timer_enabled) = buf[0] & 0x1;
  488. storage_file_read(file, &buf, 1);
  489. *(state->prog_timer_data) = buf[0];
  490. storage_file_read(file, &buf, 1);
  491. *(state->prog_timer_rld) = buf[0];
  492. storage_file_read(file, &buf, 4);
  493. *(state->call_depth) = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
  494. FURI_LOG_D(TAG, "Restoring Interupts");
  495. for(uint32_t i = 0; i < INT_SLOT_NUM; i++) {
  496. storage_file_read(file, &buf, 1);
  497. state->interrupts[i].factor_flag_reg = buf[0] & 0xF;
  498. storage_file_read(file, &buf, 1);
  499. state->interrupts[i].mask_reg = buf[0] & 0xF;
  500. storage_file_read(file, &buf, 1);
  501. state->interrupts[i].triggered = buf[0] & 0x1;
  502. }
  503. /* First 640 half bytes correspond to the RAM */
  504. FURI_LOG_D(TAG, "Restoring RAM");
  505. for(uint32_t i = 0; i < MEM_RAM_SIZE; i++) {
  506. storage_file_read(file, &buf, 1);
  507. SET_RAM_MEMORY(state->memory, i + MEM_RAM_ADDR, buf[0] & 0xF);
  508. }
  509. /* I/Os are from 0xF00 to 0xF7F */
  510. FURI_LOG_D(TAG, "Restoring I/O");
  511. for(uint32_t i = 0; i < MEM_IO_SIZE; i++) {
  512. storage_file_read(file, &buf, 1);
  513. SET_IO_MEMORY(state->memory, i + MEM_IO_ADDR, buf[0] & 0xF);
  514. }
  515. FURI_LOG_D(TAG, "Refreshing Hardware");
  516. tamalib_refresh_hw();
  517. }
  518. }
  519. storage_file_close(file);
  520. storage_file_free(file);
  521. furi_record_close(RECORD_STORAGE);
  522. }
  523. static void tama_p1_save_state() {
  524. // Saving state
  525. FURI_LOG_D(TAG, "Saving Gamestate");
  526. uint8_t buf[4];
  527. state_t* state;
  528. uint32_t offset = 0;
  529. state = tamalib_get_state();
  530. Storage* storage = furi_record_open(RECORD_STORAGE);
  531. File* file = storage_file_alloc(storage);
  532. if(storage_file_open(file, TAMA_SAVE_PATH, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
  533. buf[0] = (uint8_t)STATE_FILE_MAGIC[0];
  534. buf[1] = (uint8_t)STATE_FILE_MAGIC[1];
  535. buf[2] = (uint8_t)STATE_FILE_MAGIC[2];
  536. buf[3] = (uint8_t)STATE_FILE_MAGIC[3];
  537. offset += storage_file_write(file, &buf, sizeof(buf));
  538. buf[0] = STATE_FILE_VERSION & 0xFF;
  539. offset += storage_file_write(file, &buf, 1);
  540. buf[0] = *(state->pc) & 0xFF;
  541. buf[1] = (*(state->pc) >> 8) & 0x1F;
  542. offset += storage_file_write(file, &buf, 2);
  543. buf[0] = *(state->x) & 0xFF;
  544. buf[1] = (*(state->x) >> 8) & 0xF;
  545. offset += storage_file_write(file, &buf, 2);
  546. buf[0] = *(state->y) & 0xFF;
  547. buf[1] = (*(state->y) >> 8) & 0xF;
  548. offset += storage_file_write(file, &buf, 2);
  549. buf[0] = *(state->a) & 0xF;
  550. offset += storage_file_write(file, &buf, 1);
  551. buf[0] = *(state->b) & 0xF;
  552. offset += storage_file_write(file, &buf, 1);
  553. buf[0] = *(state->np) & 0x1F;
  554. offset += storage_file_write(file, &buf, 1);
  555. buf[0] = *(state->sp) & 0xFF;
  556. offset += storage_file_write(file, &buf, 1);
  557. buf[0] = *(state->flags) & 0xF;
  558. offset += storage_file_write(file, &buf, 1);
  559. buf[0] = *(state->tick_counter) & 0xFF;
  560. buf[1] = (*(state->tick_counter) >> 8) & 0xFF;
  561. buf[2] = (*(state->tick_counter) >> 16) & 0xFF;
  562. buf[3] = (*(state->tick_counter) >> 24) & 0xFF;
  563. offset += storage_file_write(file, &buf, sizeof(buf));
  564. buf[0] = *(state->clk_timer_timestamp) & 0xFF;
  565. buf[1] = (*(state->clk_timer_timestamp) >> 8) & 0xFF;
  566. buf[2] = (*(state->clk_timer_timestamp) >> 16) & 0xFF;
  567. buf[3] = (*(state->clk_timer_timestamp) >> 24) & 0xFF;
  568. offset += storage_file_write(file, &buf, sizeof(buf));
  569. buf[0] = *(state->prog_timer_timestamp) & 0xFF;
  570. buf[1] = (*(state->prog_timer_timestamp) >> 8) & 0xFF;
  571. buf[2] = (*(state->prog_timer_timestamp) >> 16) & 0xFF;
  572. buf[3] = (*(state->prog_timer_timestamp) >> 24) & 0xFF;
  573. offset += storage_file_write(file, &buf, sizeof(buf));
  574. buf[0] = *(state->prog_timer_enabled) & 0x1;
  575. offset += storage_file_write(file, &buf, 1);
  576. buf[0] = *(state->prog_timer_data) & 0xFF;
  577. offset += storage_file_write(file, &buf, 1);
  578. buf[0] = *(state->prog_timer_rld) & 0xFF;
  579. offset += storage_file_write(file, &buf, 1);
  580. buf[0] = *(state->call_depth) & 0xFF;
  581. buf[1] = (*(state->call_depth) >> 8) & 0xFF;
  582. buf[2] = (*(state->call_depth) >> 16) & 0xFF;
  583. buf[3] = (*(state->call_depth) >> 24) & 0xFF;
  584. offset += storage_file_write(file, &buf, sizeof(buf));
  585. for(uint32_t i = 0; i < INT_SLOT_NUM; i++) {
  586. buf[0] = state->interrupts[i].factor_flag_reg & 0xF;
  587. offset += storage_file_write(file, &buf, 1);
  588. buf[0] = state->interrupts[i].mask_reg & 0xF;
  589. offset += storage_file_write(file, &buf, 1);
  590. buf[0] = state->interrupts[i].triggered & 0x1;
  591. offset += storage_file_write(file, &buf, 1);
  592. }
  593. /* First 640 half bytes correspond to the RAM */
  594. for(uint32_t i = 0; i < MEM_RAM_SIZE; i++) {
  595. buf[0] = GET_RAM_MEMORY(state->memory, i + MEM_RAM_ADDR) & 0xF;
  596. offset += storage_file_write(file, &buf, 1);
  597. }
  598. /* I/Os are from 0xF00 to 0xF7F */
  599. for(uint32_t i = 0; i < MEM_IO_SIZE; i++) {
  600. buf[0] = GET_IO_MEMORY(state->memory, i + MEM_IO_ADDR) & 0xF;
  601. offset += storage_file_write(file, &buf, 1);
  602. }
  603. }
  604. storage_file_close(file);
  605. storage_file_free(file);
  606. furi_record_close(RECORD_STORAGE);
  607. FURI_LOG_D(TAG, "Finished Writing %lu", offset);
  608. }
  609. static int32_t tama_p1_worker(void* context) {
  610. bool running = true;
  611. FuriMutex* mutex = context;
  612. while(furi_mutex_acquire(mutex, FuriWaitForever) != FuriStatusOk) furi_delay_tick(1);
  613. cpu_sync_ref_timestamp();
  614. LL_TIM_EnableCounter(TIM2);
  615. tama_p1_load_state();
  616. while(running) {
  617. if(furi_thread_flags_get()) {
  618. running = false;
  619. } else {
  620. // FURI_LOG_D(TAG, "Stepping"); // enabling this cause blank screen somehow
  621. // for (int i = 0; i < 100; ++i)
  622. tamalib_step(); // tamalib_mainloop();
  623. }
  624. }
  625. LL_TIM_DisableCounter(TIM2);
  626. furi_mutex_release(mutex);
  627. return 0;
  628. }
  629. static void tama_p1_init(TamaApp* const ctx) {
  630. g_ctx = ctx;
  631. memset(ctx, 0, sizeof(TamaApp));
  632. tama_p1_hal_init(&ctx->hal);
  633. // Load ROM
  634. Storage* storage = furi_record_open(RECORD_STORAGE);
  635. FileInfo fi;
  636. if(storage_common_stat(storage, TAMA_ROM_PATH, &fi) == FSE_OK) {
  637. File* rom_file = storage_file_alloc(storage);
  638. if(storage_file_open(rom_file, TAMA_ROM_PATH, FSAM_READ, FSOM_OPEN_EXISTING)) {
  639. ctx->rom = malloc((size_t)fi.size);
  640. uint8_t* buf_ptr = ctx->rom;
  641. size_t read = 0;
  642. while(read < fi.size) {
  643. size_t to_read = fi.size - read;
  644. if(to_read > UINT16_MAX) to_read = UINT16_MAX;
  645. uint16_t now_read = storage_file_read(rom_file, buf_ptr, (uint16_t)to_read);
  646. read += now_read;
  647. buf_ptr += now_read;
  648. }
  649. // Reorder endianess of ROM
  650. for(size_t i = 0; i < fi.size; i += 2) {
  651. uint8_t b = ctx->rom[i];
  652. ctx->rom[i] = ctx->rom[i + 1];
  653. ctx->rom[i + 1] = b & 0xF;
  654. }
  655. }
  656. storage_file_close(rom_file);
  657. storage_file_free(rom_file);
  658. }
  659. furi_record_close(RECORD_STORAGE);
  660. if(ctx->rom != NULL) {
  661. // Init TIM2
  662. // 64KHz
  663. LL_TIM_InitTypeDef tim_init = {
  664. .Prescaler = 999,
  665. .CounterMode = LL_TIM_COUNTERMODE_UP,
  666. .Autoreload = 0xFFFFFFFF,
  667. };
  668. LL_TIM_Init(TIM2, &tim_init);
  669. LL_TIM_SetClockSource(TIM2, LL_TIM_CLOCKSOURCE_INTERNAL);
  670. LL_TIM_DisableCounter(TIM2);
  671. LL_TIM_SetCounter(TIM2, 0);
  672. // Init TamaLIB
  673. tamalib_register_hal(&ctx->hal);
  674. tamalib_init((u12_t*)ctx->rom, NULL, 64000);
  675. tamalib_set_speed(speed);
  676. // TODO: implement fast forwarding
  677. // ctx->fast_forward_done = true;
  678. // Start stepping thread
  679. ctx->thread = furi_thread_alloc();
  680. furi_thread_set_name(ctx->thread, "TamaLIB");
  681. furi_thread_set_stack_size(ctx->thread, 1024);
  682. furi_thread_set_callback(ctx->thread, tama_p1_worker);
  683. furi_thread_set_context(ctx->thread, g_state_mutex);
  684. furi_thread_start(ctx->thread);
  685. }
  686. }
  687. static void tama_p1_deinit(TamaApp* const ctx) {
  688. if(ctx->rom != NULL) {
  689. tamalib_release();
  690. furi_thread_free(ctx->thread);
  691. free(ctx->rom);
  692. }
  693. }
  694. int32_t tama_p1_app(void* p) {
  695. UNUSED(p);
  696. TamaApp* ctx = malloc(sizeof(TamaApp));
  697. g_state_mutex = furi_mutex_alloc(FuriMutexTypeRecursive);
  698. tama_p1_init(ctx);
  699. FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(TamaEvent));
  700. ViewPort* view_port = view_port_alloc();
  701. view_port_draw_callback_set(view_port, tama_p1_draw_callback, g_state_mutex);
  702. view_port_input_callback_set(view_port, tama_p1_input_callback, event_queue);
  703. Gui* gui = furi_record_open(RECORD_GUI);
  704. gui_add_view_port(gui, view_port, GuiLayerFullscreen);
  705. FuriTimer* timer =
  706. furi_timer_alloc(tama_p1_update_timer_callback, FuriTimerTypePeriodic, event_queue);
  707. furi_timer_start(timer, furi_kernel_get_tick_frequency() / 30);
  708. // in_menu = false;
  709. // menu_cursor = 2;
  710. for(bool running = true; running;) {
  711. TamaEvent event;
  712. FuriStatus event_status = furi_message_queue_get(event_queue, &event, FuriWaitForever);
  713. if(event_status == FuriStatusOk) {
  714. // Local override with acquired context
  715. if(furi_mutex_acquire(g_state_mutex, FuriWaitForever) != FuriStatusOk) continue;
  716. if(event.type == EventTypeTick) {
  717. // FURI_LOG_D(TAG, "EventTypeTick");
  718. view_port_update(view_port);
  719. } else if(event.type == EventTypeInput) {
  720. FURI_LOG_D(
  721. TAG,
  722. "EventTypeInput: %ld %d %d",
  723. event.input.sequence,
  724. event.input.key,
  725. event.input.type);
  726. InputType input_type = event.input.type;
  727. btn_state_t tama_btn_state = 0;
  728. if(in_menu) {
  729. if(event.input.key == InputKeyBack) {
  730. in_menu = false;
  731. } else if(event.input.key == InputKeyUp && event.input.type == InputTypePress) {
  732. if(menu_cursor > 0) {
  733. menu_cursor -= 1;
  734. } else {
  735. menu_cursor = menu_items - 1;
  736. }
  737. if(menu_cursor >= menu_items - 2 && sub_menu_last > 0)
  738. sub_menu_buttons = 1;
  739. else
  740. sub_menu_buttons = 0;
  741. } else if(event.input.key == InputKeyDown && event.input.type == InputTypePress) {
  742. if(menu_cursor < menu_items - 1) {
  743. menu_cursor += 1;
  744. } else {
  745. menu_cursor = 0;
  746. }
  747. if(menu_cursor >= menu_items - 2 && sub_menu_buttons > 0)
  748. sub_menu_last = 1;
  749. else
  750. sub_menu_last = 0;
  751. } else if(event.input.key == InputKeyLeft && event.input.type == InputTypePress) {
  752. switch(menu_cursor) {
  753. case 0:
  754. switch(layout_mode) {
  755. case 0:
  756. layout_mode = 4;
  757. break;
  758. case 1:
  759. case 2:
  760. case 3:
  761. case 4:
  762. layout_mode -= 1;
  763. break;
  764. }
  765. break;
  766. case 1:
  767. speed_down();
  768. break;
  769. case 2:
  770. switch(sub_menu_buttons) {
  771. case 0:
  772. sub_menu_buttons = 3;
  773. break;
  774. case 1:
  775. case 2:
  776. case 3:
  777. sub_menu_buttons -= 1;
  778. break;
  779. default:
  780. break;
  781. }
  782. break;
  783. case menu_items - 1:
  784. switch(sub_menu_last) {
  785. case 0:
  786. sub_menu_last = 2;
  787. break;
  788. case 1:
  789. case 2:
  790. sub_menu_last -= 1;
  791. break;
  792. default:
  793. break;
  794. }
  795. break;
  796. default:
  797. break;
  798. }
  799. } else if(event.input.key == InputKeyRight && event.input.type == InputTypePress) {
  800. switch(menu_cursor) {
  801. case 0:
  802. switch(layout_mode) {
  803. case 0:
  804. case 1:
  805. case 2:
  806. case 3:
  807. layout_mode += 1;
  808. break;
  809. case 4:
  810. layout_mode = 0;
  811. break;
  812. }
  813. break;
  814. case 1:
  815. speed_up();
  816. break;
  817. case 2:
  818. switch(sub_menu_buttons) {
  819. case 0:
  820. case 1:
  821. case 2:
  822. sub_menu_buttons += 1;
  823. break;
  824. case 3:
  825. sub_menu_buttons = 0;
  826. break;
  827. default:
  828. break;
  829. }
  830. break;
  831. case menu_items - 1:
  832. switch(sub_menu_last) {
  833. case 0:
  834. case 1:
  835. sub_menu_last += 1;
  836. break;
  837. case 2:
  838. sub_menu_last = 0;
  839. break;
  840. default:
  841. break;
  842. }
  843. break;
  844. default:
  845. break;
  846. }
  847. } else if(event.input.key == InputKeyOk) {
  848. switch(menu_cursor) {
  849. case 0:
  850. if(event.input.type == InputTypePress) {
  851. switch(layout_mode) {
  852. case 0:
  853. case 1:
  854. case 2:
  855. case 3:
  856. layout_mode += 1;
  857. break;
  858. case 4:
  859. layout_mode = 0;
  860. break;
  861. }
  862. }
  863. break;
  864. case 1:
  865. if(event.input.type == InputTypePress) {
  866. speed_up();
  867. }
  868. break;
  869. case 2:
  870. if(input_type == InputTypePress)
  871. tama_btn_state = BTN_STATE_PRESSED;
  872. else if(input_type == InputTypeRelease)
  873. tama_btn_state = BTN_STATE_RELEASED;
  874. switch(sub_menu_buttons) {
  875. case 0: // A+C
  876. tamalib_set_button(BTN_LEFT, tama_btn_state);
  877. tamalib_set_button(BTN_RIGHT, tama_btn_state);
  878. break;
  879. case 1: // A
  880. tamalib_set_button(BTN_LEFT, tama_btn_state);
  881. break;
  882. case 2: // B
  883. tamalib_set_button(BTN_MIDDLE, tama_btn_state);
  884. break;
  885. case 3: // C
  886. tamalib_set_button(BTN_RIGHT, tama_btn_state);
  887. break;
  888. }
  889. break;
  890. case menu_items - 1:
  891. default:
  892. switch(sub_menu_last) {
  893. case 0: // close menu
  894. in_menu = false;
  895. break;
  896. case 1: // Save
  897. if(speed != 1) {
  898. // uint8_t temp = speed;
  899. // speed = 1;
  900. tamalib_set_speed(1);
  901. tama_p1_save_state();
  902. // speed = temp;
  903. tamalib_set_speed(speed);
  904. } else {
  905. tama_p1_save_state();
  906. }
  907. // in_menu = false;
  908. break;
  909. case 2: // Save & Exit
  910. if(speed != 1) {
  911. // speed = 1;
  912. // tamalib_set_speed(speed);
  913. tamalib_set_speed(1);
  914. }
  915. furi_timer_stop(timer);
  916. tama_p1_save_state();
  917. running = false;
  918. break;
  919. default:
  920. break;
  921. }
  922. break;
  923. }
  924. }
  925. } else { // out of menu
  926. if(event.input.key == InputKeyBack && event.input.type == InputTypeLong) {
  927. if(speed != 1) {
  928. // speed = 1;
  929. // tamalib_set_speed(speed);
  930. tamalib_set_speed(1);
  931. }
  932. furi_timer_stop(timer);
  933. tama_p1_save_state();
  934. running = false;
  935. }
  936. if(input_type == InputTypePress || input_type == InputTypeRelease) {
  937. if(event.input.key != InputKeyBack) { // TODO: clean up code -.-
  938. switch(layout_mode) {
  939. case 0:
  940. case 1:
  941. case 2:
  942. if(event.input.key != InputKeyUp) {
  943. if(input_type == InputTypePress)
  944. tama_btn_state = BTN_STATE_PRESSED;
  945. else if(input_type == InputTypeRelease)
  946. tama_btn_state = BTN_STATE_RELEASED;
  947. }
  948. break;
  949. case 3:
  950. if(event.input.key != InputKeyLeft) {
  951. if(input_type == InputTypePress)
  952. tama_btn_state = BTN_STATE_PRESSED;
  953. else if(input_type == InputTypeRelease)
  954. tama_btn_state = BTN_STATE_RELEASED;
  955. }
  956. break;
  957. case 4:
  958. if(event.input.key != InputKeyRight) {
  959. if(input_type == InputTypePress)
  960. tama_btn_state = BTN_STATE_PRESSED;
  961. else if(input_type == InputTypeRelease)
  962. tama_btn_state = BTN_STATE_RELEASED;
  963. }
  964. break;
  965. default:
  966. break;
  967. }
  968. }
  969. if(input_type == InputTypePress)
  970. tama_btn_state = BTN_STATE_PRESSED;
  971. else if(input_type == InputTypeRelease)
  972. tama_btn_state = BTN_STATE_RELEASED;
  973. if(event.input.key == InputKeyOk) {
  974. tamalib_set_button(BTN_MIDDLE, tama_btn_state);
  975. }
  976. switch(layout_mode) {
  977. case 0:
  978. case 1:
  979. case 2:
  980. switch(event.input.key) {
  981. case InputKeyUp:
  982. in_menu = true;
  983. break;
  984. case InputKeyLeft:
  985. tamalib_set_button(BTN_LEFT, tama_btn_state);
  986. break;
  987. case InputKeyDown:
  988. tamalib_set_button(BTN_MIDDLE, tama_btn_state);
  989. break;
  990. case InputKeyRight:
  991. tamalib_set_button(BTN_RIGHT, tama_btn_state);
  992. break;
  993. default:
  994. break;
  995. }
  996. break;
  997. case 3:
  998. switch(event.input.key) {
  999. case InputKeyLeft:
  1000. in_menu = true;
  1001. break;
  1002. case InputKeyDown:
  1003. tamalib_set_button(BTN_LEFT, tama_btn_state);
  1004. break;
  1005. case InputKeyRight:
  1006. tamalib_set_button(BTN_MIDDLE, tama_btn_state);
  1007. break;
  1008. case InputKeyUp:
  1009. tamalib_set_button(BTN_RIGHT, tama_btn_state);
  1010. break;
  1011. default:
  1012. break;
  1013. }
  1014. break;
  1015. case 4:
  1016. switch(event.input.key) {
  1017. case InputKeyRight:
  1018. in_menu = true;
  1019. break;
  1020. case InputKeyUp:
  1021. tamalib_set_button(BTN_LEFT, tama_btn_state);
  1022. break;
  1023. case InputKeyLeft:
  1024. tamalib_set_button(BTN_MIDDLE, tama_btn_state);
  1025. break;
  1026. case InputKeyDown:
  1027. tamalib_set_button(BTN_RIGHT, tama_btn_state);
  1028. break;
  1029. default:
  1030. break;
  1031. }
  1032. break;
  1033. default:
  1034. break;
  1035. }
  1036. }
  1037. }
  1038. }
  1039. furi_mutex_release(g_state_mutex);
  1040. }
  1041. // else {
  1042. // // Timeout
  1043. // FURI_LOG_D(TAG, "Timed out");
  1044. // }
  1045. }
  1046. if(ctx->rom != NULL) {
  1047. furi_thread_flags_set(furi_thread_get_id(ctx->thread), 1);
  1048. furi_thread_join(ctx->thread);
  1049. }
  1050. furi_timer_free(timer);
  1051. view_port_enabled_set(view_port, false);
  1052. gui_remove_view_port(gui, view_port);
  1053. furi_record_close(RECORD_GUI);
  1054. view_port_free(view_port);
  1055. furi_message_queue_free(event_queue);
  1056. furi_mutex_free(g_state_mutex);
  1057. tama_p1_deinit(ctx);
  1058. free(ctx);
  1059. return 0;
  1060. }