/[projet1]/public/oric/hardware/cumulus/fw/UI.c
Defence Force logotype

Contents of /public/oric/hardware/cumulus/fw/UI.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 423 - (show annotations)
Mon Jan 24 12:19:33 2011 UTC (9 years, 2 months ago) by retromaster
File MIME type: text/plain
File size: 20206 byte(s)
Initial add of 18F46K20 firmware sources.
1 /* Cumulus 18F46K20 Firmware
2 * User interface.
3 * Copyright 2010 Retromaster.
4 *
5 * This file is part of Cumulus Firmware.
6 *
7 * Cumulus Firmware is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License,
10 * or any later version.
11 *
12 * Cumulus Firmware is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with Cumulus Firmware. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "string.h"
22 #include "179X.h"
23 #include "6610.h"
24 #include "utility.h"
25 #include "sd-mmc.h"
26 #include "fat32.h"
27 #include "delays.h"
28 #include "UI.h"
29
30 #define SCR_WIDTH_6X8 21
31
32 typedef enum
33 {
34 ui_state_emulation = 0,
35 ui_state_main_menu,
36 ui_state_image_select,
37 ui_state_about,
38 ui_state_io_error,
39 ui_state_command_log,
40 ui_state_reset_oric
41 } ui_state;
42
43 #define BUTTON_NONE 0
44 #define BUTTON_LEFT_1 1
45 #define BUTTON_LEFT_2 2
46 #define BUTTON_RIGHT_1 3
47 #define BUTTON_RIGHT_2 4
48 #define BUTTON_FIRE 5
49
50 #define DEBOUNCE_COUNT 5
51
52 typedef enum
53 {
54 ui_main_preferences = 0,
55 ui_main_reset,
56 ui_main_command_log,
57 ui_main_about,
58 ui_main_continue,
59 ui_main_count
60 } ui_main_item;
61
62 #define FILE_LIST_SIZE 10
63
64 #pragma romdata
65 far rom char str_cumulus[] = "Cumulus";
66 far rom char str_version[] = "v0.5";
67 far rom char str_about_1[] = "Oric Microdisc";
68 far rom char str_about_2[] = "compatible";
69 far rom char str_about_3[] = "SD Card Emulator";
70 far rom char str_by_retromaster[] = "by retromaster";
71 far rom char str_empty[] = "-- Empty --";
72 far rom char str_preferences[] = "Preferences";
73 far rom char str_about[] = "About";
74 far rom char str_reset_oric[] = "Reset Oric";
75 far rom char str_continue[] = "Continue";
76 far rom char str_main[] = "Main";
77 far rom char str_mount_drive[] = "Mount (Drive )";
78 far rom char str_eject[] = "Eject";
79 far rom char str_change_card[] = "Change Card";
80 far rom char str_on[] = "On";
81 far rom char str_off[] = "On";
82 far rom char str_error[] = "Error";
83 far rom char str_card_io_error[] = "SD Card I/O Error!";
84 far rom char str_command_log[] = "Command Log";
85 far rom char str_dsk[] = "DSK";
86 far rom char str_yes[] = "Yes";
87 far rom char str_no[] = "No";
88 far rom char str_log_status[] = "Status";
89 far rom char* str_status[ui_status_count] = {
90 (far rom char*) "OK.",
91 (far rom char*) "SD Card IO Error!",
92 (far rom char*) "Record Not Found!",
93 (far rom char*) "CRC Error!",
94 (far rom char*) "Disk Write-Protected!",
95 (far rom char*) "Drive Not Ready!",
96 };
97 static rom char hex_lookup[16] =
98 {
99 '0', '1', '2', '3',
100 '4', '5', '6', '7',
101 '8', '9', 'A', 'B',
102 'C', 'D', 'E', 'F'
103 };
104
105 #pragma udata ui_data_section
106 static uint8_t card_initialized;
107 static int8_t selection;
108 static int8_t file_count;
109 static uint16_t dir_page;
110 static fat32_dir_entry directory;
111 static ui_state state;
112 static uint8_t drive;
113 static uint8_t pressed_button;
114 static uint8_t debounce_button;
115 static uint8_t debounce_counter;
116 static uint8_t blink;
117 static uint32_t blink_cntr;
118 static uint8_t status;
119 static uint8_t log_line_cntr;
120 static uint8_t log_msg_cntr;
121 static fat32_dir_entry file_list[FILE_LIST_SIZE];
122
123 #pragma code
124
125 void ui_update_track(drive_state* drive)
126 {
127 uint8_t y;
128 if (state != ui_state_emulation)
129 return;
130
131 n6610_set_font(FONT_8X14);
132 if (selection == drive->number)
133 n6610_set_color(0xF, 0xF, 0xF, 0x8, 0x0, 0x0);
134 else
135 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
136 y = drive->number * 26 + 14;
137 n6610_draw_char(112, y, '0' + (drive->track / 10));
138 n6610_draw_char(120, y, '0' + (drive->track % 10));
139 }
140
141 static void prep_screen(void)
142 {
143 /* Prepare the header and footer areas */
144 n6610_set_color(0x0, 0x0, 0x0, 0xF, 0xF, 0xF);
145 n6610_fill_area(0, 0, 132, 10);
146 n6610_fill_area(0, 122, 132, 10);
147 n6610_set_font(FONT_6X8);
148 n6610_draw_rom_str(1, 2, str_cumulus);
149
150 /* Clear the background */
151 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
152 n6610_fill_area(0, 10, 132, 112);
153 }
154
155 /* Draws a drive info item in emulation mode */
156 static void draw_emulation_drive_item(uint8_t drive, uint8_t selected)
157 {
158 uint8_t len;
159 uint8_t pos;
160 uint8_t y;
161
162 y = 14 + 26 * drive;
163
164 if (selected)
165 n6610_set_color(0xF, 0xF, 0xF, 0x8, 0x0, 0x0);
166 else
167 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
168
169 n6610_fill_area(0, y, 132, 22);
170
171 n6610_set_font(FONT_8X14);
172 n6610_draw_char(112, y, '0' + (wd179x_drive[drive].track / 10));
173 n6610_draw_char(120, y, '0' + (wd179x_drive[drive].track % 10));
174 n6610_draw_char(88, y, 'A' + drive);
175 n6610_draw_char(96, y, ':');
176
177 n6610_set_font(FONT_6X8);
178 if (wd179x_drive[drive].image_type == IMAGE_NONE)
179 n6610_draw_rom_str(64, y + 14, str_empty);
180 else
181 {
182 len = strlen_ram(wd179x_drive[drive].image_file.name);
183 if (len <= SCR_WIDTH_6X8)
184 pos = 128 - (len * 6);
185 else
186 pos = 2;
187
188 n6610_draw_ram_str(pos, y + 14, wd179x_drive[drive].image_file.name);
189 }
190
191 if (wd179x_drive[drive].type_I_status & 0x40)
192 n6610_draw_char(1, y + 6, 'P');
193 }
194
195 static void draw_status(void)
196 {
197 /* Prepare the header and footer areas */
198 if (status == 0)
199 n6610_set_color(0x0, 0x8, 0x0, 0xF, 0xF, 0xF);
200 else
201 n6610_set_color(0x8, 0x0, 0x0, 0xF, 0xF, 0xF);
202
203 n6610_set_font(FONT_6X8);
204 n6610_fill_area(0, 122, 132, 10);
205 n6610_draw_rom_str(1, 123, str_status[status]);
206 }
207
208 /* Sets the status */
209 void ui_set_status(ui_status s)
210 {
211 status = s;
212 if (state == ui_state_emulation)
213 draw_status();
214 }
215
216 /* Displays emulation screen. */
217 static void enter_emulation(void)
218 {
219 uint8_t i;
220
221 state = ui_state_emulation;
222 prep_screen();
223
224 selection = 0;
225 draw_emulation_drive_item(0, 1);
226 for (i = 1; i < 4; i ++)
227 draw_emulation_drive_item(i, 0);
228
229 draw_status();
230 }
231
232 /* Prints a main menu item */
233 static void draw_main_menu_item(ui_main_item item, uint8_t selected)
234 {
235 if (selected)
236 n6610_set_color(0xF, 0xF, 0xF, 0x8, 0x0, 0x0);
237 else
238 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
239
240 switch(item)
241 {
242 case ui_main_preferences:
243 n6610_fill_area(0, 16, 130, 8);
244 n6610_draw_rom_str(0, 16, str_preferences);
245 break;
246 case ui_main_reset:
247 n6610_fill_area(0, 24, 130, 8);
248 n6610_draw_rom_str(0, 24, str_reset_oric);
249 break;
250 case ui_main_command_log:
251 n6610_fill_area(0, 32, 130, 8);
252 n6610_draw_rom_str(0, 32, str_command_log);
253 break;
254 case ui_main_about:
255 n6610_fill_area(0, 48, 130, 8);
256 n6610_draw_rom_str(0, 48, str_about);
257 break;
258 case ui_main_continue:
259 n6610_fill_area(0, 104, 130, 8);
260 n6610_draw_rom_str(0, 104, str_continue);
261 break;
262 }
263 }
264
265 /* Displays and enters the main menu. */
266 static void enter_main_menu(void)
267 {
268 uint8_t i;
269
270 prep_screen();
271
272 draw_main_menu_item(0, 1);
273 for (i = 1; i < ui_main_count; i ++)
274 draw_main_menu_item(i, 0);
275
276 n6610_set_color(0x0, 0x0, 0x0, 0xF, 0xF, 0xF);
277 n6610_draw_rom_str(1, 123, str_main);
278
279 selection = 0;
280 state = ui_state_main_menu;
281 }
282
283
284 /* Draws yes or no. */
285 static void draw_reset_oric_items(void)
286 {
287 if (selection == 0)
288 n6610_set_color(0xF, 0xF, 0xF, 0x8, 0x0, 0x0);
289 else
290 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
291 n6610_fill_area(0, 16, 130, 8);
292 n6610_draw_rom_str(0, 16, str_yes);
293
294 if (selection == 1)
295 n6610_set_color(0xF, 0xF, 0xF, 0x8, 0x0, 0x0);
296 else
297 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
298 n6610_fill_area(0, 24, 130, 8);
299 n6610_draw_rom_str(0, 24, str_no);
300 }
301
302 /* Displays and enters the main menu. */
303 static void enter_reset_oric(void)
304 {
305 uint8_t i;
306
307 prep_screen();
308
309 n6610_set_color(0x0, 0x0, 0x0, 0xF, 0xF, 0xF);
310 n6610_draw_rom_str(1, 123, str_reset_oric);
311 n6610_draw_char(61, 123, '?');
312
313 selection = 0;
314 draw_reset_oric_items();
315 state = ui_state_reset_oric;
316 }
317
318 /* Displays About screen. */
319 static void enter_about(void)
320 {
321 prep_screen();
322
323 n6610_set_color(0x0, 0x0, 0x0, 0xF, 0xF, 0xF);
324 n6610_draw_rom_str(1, 123, str_about);
325
326 n6610_set_color(0xF, 0xF, 0x0, 0x0, 0x0, 0x8);
327 n6610_set_font(FONT_8X16);
328 n6610_draw_rom_str(16, 24, str_cumulus);
329
330 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
331 n6610_set_font(FONT_6X8);
332 n6610_draw_rom_str(80, 30, str_version);
333 n6610_draw_rom_str(16, 44, str_about_1);
334 n6610_draw_rom_str(16, 52, str_about_2);
335 n6610_draw_rom_str(16, 60, str_about_3);
336 n6610_draw_rom_str(16, 76, str_by_retromaster);
337
338 state = ui_state_about;
339 }
340
341 /* Displays and enters the main menu. */
342 static void enter_command_log(void)
343 {
344 prep_screen();
345
346 n6610_set_color(0x0, 0x0, 0x0, 0xF, 0xF, 0xF);
347 n6610_draw_rom_str(1, 123, str_command_log);
348
349 log_msg_cntr = 0;
350 log_line_cntr = 0;
351 state = ui_state_command_log;
352 }
353
354 static uint8_t change_card(void)
355 {
356 if (!card_init())
357 return 0;
358 else if (!fat32_init())
359 return 0;
360
361 selection = 0;
362 dir_page = 0;
363 fat32_root_dir(&directory);
364
365 card_initialized = 1;
366 return 1;
367 }
368
369 static void io_error(void)
370 {
371 card_initialized = 0;
372
373 prep_screen();
374 n6610_set_color(0x8, 0x0, 0x0, 0xF, 0xF, 0xF);
375 n6610_draw_rom_str(1, 123, str_error);
376
377 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
378 n6610_draw_rom_str(8, 16, str_card_io_error);
379
380 n6610_set_color(0xF, 0xF, 0xF, 0x8, 0x0, 0x0);
381 n6610_fill_area(0, 104, 130, 8);
382 n6610_draw_rom_str(0, 104, str_continue);
383
384 state = ui_state_io_error;
385 }
386
387 /* Displays image selection menu item */
388 static void draw_image_select_menu_item(uint8_t item, uint8_t selected)
389 {
390 if (selected)
391 n6610_set_color(0xF, 0xF, 0xF, 0x8, 0x0, 0x0);
392 else
393 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
394
395 if (item < file_count)
396 {
397 n6610_fill_area(0, 14 + item * 8, 130, 8);
398 if (file_list[item].dir)
399 {
400 n6610_draw_char(0, 14 + item * 8, '/');
401 n6610_draw_ram_str(8, 14 + item * 8, file_list[item].name);
402 }
403 else
404 n6610_draw_ram_str(0, 14 + item * 8, file_list[item].name);
405 }
406 else if (item == FILE_LIST_SIZE)
407 {
408 n6610_fill_area(0, 100, 130, 8);
409 n6610_draw_rom_str(0, 100, str_eject);
410 }
411 else if (item == FILE_LIST_SIZE + 1)
412 {
413 n6610_fill_area(0, 108, 130, 8);
414 n6610_draw_rom_str(0, 108, str_change_card);
415 }
416 }
417
418 /* Displays image selection menu */
419 static void draw_image_select_menu(void)
420 {
421 uint8_t item;
422
423 prep_screen();
424 n6610_set_color(0x0, 0x0, 0x0, 0xF, 0xF, 0xF);
425 n6610_draw_rom_str(1, 123, str_mount_drive);
426 n6610_draw_char(79, 123, 'A' + drive);
427
428 for (item = 0; item < file_count; item ++)
429 draw_image_select_menu_item(item, (selection == item));
430 draw_image_select_menu_item(FILE_LIST_SIZE, (selection == FILE_LIST_SIZE));
431 draw_image_select_menu_item(FILE_LIST_SIZE + 1, (selection == FILE_LIST_SIZE + 1));
432 }
433
434 static void enter_image_select(void)
435 {
436 fat32_dir dir;
437 uint8_t i, j;
438
439 state = ui_state_image_select;
440 if (!card_initialized)
441 if (!change_card())
442 {
443 io_error();
444 return;
445 }
446
447 /* Go up to the current directory page */
448 fat32_dir_begin(&dir, &directory);
449 for (i = 0; i < dir_page; i ++)
450 {
451 for (j = 0; j < FILE_LIST_SIZE; j ++)
452 if (!fat32_dir_next(&dir, &(file_list[0]), str_dsk))
453 {
454 if (dir.error)
455 {
456 io_error();
457 return;
458 }
459 else
460 break;
461 }
462
463 if (j != FILE_LIST_SIZE)
464 {
465 /* Seems like we didn't get that far, just go back to the beginning */
466 dir_page = 0;
467 selection = 0;
468
469 fat32_dir_begin(&dir, &directory);
470 break;
471 }
472 }
473
474 /* Fill file list */
475 file_count = 0;
476 for (j = 0; j < FILE_LIST_SIZE; j ++)
477 {
478 if (!fat32_dir_next(&dir, &(file_list[j]), str_dsk))
479 {
480 /* This is the last page in the directory */
481 if (dir.error)
482 {
483 io_error();
484 return;
485 }
486
487 break;
488 }
489
490 file_count ++;
491 }
492
493 draw_image_select_menu();
494 }
495
496 /* Puts a log message on the Command Log */
497 void ui_log_command(const far rom char* msg, uint8_t val1, uint8_t val2, uint8_t val3)
498 {
499 uint8_t y;
500 int8_t j;
501
502 if (state != ui_state_command_log)
503 return;
504
505 // Draw string.
506 y = log_line_cntr * 8 + 12;
507 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
508 n6610_fill_area(8, y, 82, 8);
509 n6610_draw_rom_str(8, y, msg);
510
511 /* Print out value in hex */
512 for (j = 1; j >= 0; j --)
513 {
514 n6610_draw_char(j * 6 + 90, y, hex_lookup[val1 & 0xF]);
515 val1 = val1 >> 4;
516 }
517
518 /* Print out value in hex */
519 for (j = 1; j >= 0; j --)
520 {
521 n6610_draw_char(j * 6 + 104, y, hex_lookup[val2 & 0xF]);
522 val2 = val2 >> 4;
523 }
524
525 /* Print out value in hex */
526 for (j = 1; j >= 0; j --)
527 {
528 n6610_draw_char(j * 6 + 118, y, hex_lookup[val3 & 0xF]);
529 val3 = val3 >> 4;
530 }
531
532 /* Print out value in hex */
533 n6610_draw_char(0, y, hex_lookup[log_msg_cntr & 0xF]);
534
535 /* Next line */
536 log_msg_cntr ++;
537 log_line_cntr ++;
538 if (log_line_cntr >= 13)
539 log_line_cntr = 0;
540 }
541
542 /* Puts a log status message on the Command Log */
543 void ui_log_status(uint8_t val)
544 {
545 uint8_t y;
546 int8_t j;
547
548 if (state != ui_state_command_log)
549 return;
550
551 // Draw string.
552 y = log_line_cntr * 8 + 12;
553 n6610_set_color(0x8, 0x0, 0x0, 0x0, 0x0, 0x8);
554 n6610_fill_area(8, y, 82, 8);
555 n6610_draw_rom_str(8, y, str_log_status);
556
557 n6610_set_color(0xF, 0xF, 0xF, 0x0, 0x0, 0x8);
558 /* Print out value in hex */
559 for (j = 1; j >= 0; j --)
560 {
561 n6610_draw_char(j * 6 + 90, y, hex_lookup[val & 0xF]);
562 val = val >> 4;
563 }
564
565 /* Print out value in hex */
566 n6610_draw_char(0, y, hex_lookup[log_msg_cntr & 0xF]);
567
568 /* Next line */
569 log_msg_cntr ++;
570 log_line_cntr ++;
571 if (log_line_cntr >= 13)
572 log_line_cntr = 0;
573 }
574
575 /* Initializes the user interface. */
576 void ui_init(void)
577 {
578 /* Initialize the LCD */
579 n6610_init();
580
581 /* Initialize IF lines */
582 TRISEbits.TRISE0 = 1;
583 TRISEbits.TRISE1 = 1;
584 TRISEbits.TRISE2 = 1;
585 TRISAbits.TRISA4 = 1;
586 TRISAbits.TRISA5 = 1;
587 pressed_button = BUTTON_NONE;
588 debounce_button = BUTTON_NONE;
589 debounce_counter = 0;
590
591 /* More initialization */
592 ui_wd1793_command_done();
593 card_initialized = 0;
594 ui_set_status(ui_status_ok);
595
596 /* Go to the main menu */
597 enter_emulation();
598 }
599
600 static uint8_t check_buttons(void)
601 {
602 if (PORTEbits.RE0 == 0)
603 return BUTTON_RIGHT_1;
604 else if (PORTAbits.RA5 == 0)
605 return BUTTON_RIGHT_2;
606 else if (PORTAbits.RA4 == 0)
607 return BUTTON_FIRE;
608 else if (PORTEbits.RE1 == 0)
609 return BUTTON_LEFT_1;
610 else if (PORTEbits.RE2 == 0)
611 return BUTTON_LEFT_2;
612 else
613 return BUTTON_NONE;
614 }
615
616 static void handle_emulation(void)
617 {
618 if (pressed_button == BUTTON_LEFT_1)
619 {
620 draw_emulation_drive_item(selection, 0);
621 selection --;
622 if (selection < 0)
623 selection = 3;
624 draw_emulation_drive_item(selection, 1);
625 }
626 if (pressed_button == BUTTON_LEFT_2)
627 {
628 draw_emulation_drive_item(selection, 0);
629 selection ++;
630 if (selection >= 4)
631 selection = 0;
632 draw_emulation_drive_item(selection, 1);
633 }
634 if (pressed_button == BUTTON_FIRE)
635 {
636 drive = selection;
637 enter_image_select();
638 }
639 if (pressed_button == BUTTON_RIGHT_1)
640 {
641 /* Write Protect */
642 wd179x_drive[selection].type_I_status ^= 0x40;
643 draw_emulation_drive_item(selection, 1);
644 }
645 if (pressed_button == BUTTON_RIGHT_2)
646 enter_main_menu();
647 }
648
649 static void handle_main_menu(void)
650 {
651 if (pressed_button == BUTTON_LEFT_1)
652 {
653 draw_main_menu_item(selection, 0);
654 selection --;
655 if (selection < 0)
656 selection = ui_main_count - 1;
657 draw_main_menu_item(selection, 1);
658 }
659 if (pressed_button == BUTTON_LEFT_2)
660 {
661 draw_main_menu_item(selection, 0);
662 selection ++;
663 if (selection >= ui_main_count)
664 selection = 0;
665 draw_main_menu_item(selection, 1);
666 }
667 if (pressed_button == BUTTON_FIRE)
668 {
669 /* Go somewhere else */
670 switch (selection)
671 {
672 case ui_main_continue:
673 enter_emulation();
674 break;
675 case ui_main_command_log:
676 enter_command_log();
677 break;
678 case ui_main_reset:
679 enter_reset_oric();
680 break;
681 case ui_main_about:
682 enter_about();
683 break;
684 }
685 }
686 }
687
688 static void handle_image_select(void)
689 {
690 if (pressed_button == BUTTON_LEFT_1)
691 {
692 draw_image_select_menu_item(selection, 0);
693 selection --;
694 if ((selection >= file_count) && (selection < FILE_LIST_SIZE))
695 selection = file_count - 1;
696 else if (selection < 0)
697 selection = FILE_LIST_SIZE + 1;
698 draw_image_select_menu_item(selection, 1);
699 }
700 if (pressed_button == BUTTON_LEFT_2)
701 {
702 draw_image_select_menu_item(selection, 0);
703 selection ++;
704 if (selection >= FILE_LIST_SIZE + 2)
705 selection = 0;
706 else if ((selection >= file_count) && (selection < FILE_LIST_SIZE))
707 selection = FILE_LIST_SIZE;
708 draw_image_select_menu_item(selection, 1);
709 }
710 if (pressed_button == BUTTON_RIGHT_1)
711 {
712 if (dir_page > 0)
713 {
714 dir_page --;
715 enter_image_select();
716 }
717 }
718 if (pressed_button == BUTTON_RIGHT_2)
719 {
720 dir_page ++;
721 enter_image_select(); /* This will automatically handle end of directory */
722 }
723 if (pressed_button == BUTTON_FIRE)
724 {
725 if (selection == FILE_LIST_SIZE + 1)
726 {
727 card_initialized = 0;
728 enter_image_select();
729 }
730 else if (selection == FILE_LIST_SIZE)
731 {
732 /* TODO: Eject */
733 }
734 else
735 {
736 if (file_list[selection].dir)
737 {
738 /* Go into the directory */
739 directory = file_list[selection];
740 dir_page = 0;
741 selection = 0;
742 enter_image_select();
743 }
744 else
745 {
746 wd179x_mount_image(drive, &file_list[selection]);
747 enter_emulation();
748 }
749 }
750
751 }
752 }
753
754 static void handle_reset_oric(void)
755 {
756 if (pressed_button == BUTTON_LEFT_1 || pressed_button == BUTTON_LEFT_2)
757 {
758 if (selection == 1)
759 selection = 0;
760 else
761 selection = 1;
762 draw_reset_oric_items();
763 }
764 if (pressed_button == BUTTON_FIRE)
765 {
766 if (selection == 0)
767 {
768 /* Reset low */
769 PORTAbits.RA6 = 0;
770
771 /* Wait */
772 Delay10KTCYx(200);
773
774 /* Do something for the WD179X? */
775
776 /* UI */
777 enter_emulation();
778
779 /* Reset high */
780 PORTAbits.RA6 = 1;
781 }
782 else
783 {
784 /* Do nothing */
785 enter_main_menu();
786 }
787 }
788 }
789
790 static void handle_button_press(void)
791 {
792 if (state == ui_state_emulation)
793 handle_emulation();
794 else if (state == ui_state_io_error || state == ui_state_command_log || state == ui_state_about)
795 enter_emulation();
796 else if (state == ui_state_main_menu)
797 handle_main_menu();
798 else if (state == ui_state_image_select)
799 handle_image_select();
800 else if (state == ui_state_reset_oric)
801 handle_reset_oric();
802 }
803
804 /* Handles user input */
805 static void handle_user_input(void)
806 {
807 uint8_t button;
808 button = check_buttons();
809
810 if (button == debounce_button)
811 {
812 debounce_counter ++;
813 if (debounce_counter > DEBOUNCE_COUNT)
814 {
815 /* Key debounced */
816 if (pressed_button != BUTTON_NONE)
817 {
818 /* Waiting for release */
819 if (debounce_button != pressed_button)
820 {
821 /* Button released */
822 handle_button_press();
823 }
824 }
825
826 pressed_button = debounce_button;
827 debounce_counter = 0;
828 }
829 }
830 else
831 {
832 debounce_button = button;
833 debounce_counter = 0;
834 }
835 }
836
837 /* A WD1793 command is now active */
838 void ui_wd1793_command_active(void)
839 {
840 n6610_set_color(0x0, 0x0, 0x0, 0xF, 0x0, 0x0);
841 n6610_fill_area(124, 4, 4, 4);
842 blink = 2;
843 }
844
845 /* A WD1793 command is now active */
846 void ui_wd1793_command_done(void)
847 {
848 blink_cntr = 0;
849 blink = 0;
850 }
851
852 /* Blinks activity light */
853 static void blink_activity_light(void)
854 {
855 if (blink > 1)
856 return;
857
858 if (blink_cntr == 0)
859 {
860 if (blink)
861 {
862 n6610_set_color(0x0, 0x0, 0x0, 0x0, 0xF, 0x0);
863 n6610_fill_area(124, 4, 4, 4);
864 blink = 0;
865 }
866 else
867 {
868 n6610_set_color(0x0, 0x0, 0x0, 0x0, 0x0, 0x0);
869 n6610_fill_area(124, 4, 4, 4);
870 blink = 1;
871 }
872
873 blink_cntr = 150000;
874 }
875 else
876 blink_cntr --;
877 }
878
879 /* Handles UI related-stuff in between command executions */
880 void ui_run(void)
881 {
882 handle_user_input();
883 blink_activity_light();
884 }
885

  ViewVC Help
Powered by ViewVC 1.1.26