* removed some more unused stuff in the simulator makefile
[kugel-rb.git] / apps / debug_menu.c
blob02b86feefc131a7410fb300d0cd45ebc16b11849
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Heikki Hannikainen
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "config.h"
21 #ifndef SIMULATOR
22 #include <stdio.h>
23 #include <stdbool.h>
24 #include <string.h>
25 #include "lcd.h"
26 #include "menu.h"
27 #include "debug_menu.h"
28 #include "kernel.h"
29 #include "sprintf.h"
30 #include "button.h"
31 #include "adc.h"
32 #include "mas.h"
33 #include "power.h"
34 #include "rtc.h"
35 #include "debug.h"
36 #include "thread.h"
37 #include "powermgmt.h"
38 #include "system.h"
39 #include "font.h"
40 #include "disk.h"
41 #include "mpeg.h"
42 #include "mp3_playback.h"
43 #include "settings.h"
44 #include "ata.h"
45 #include "fat.h"
46 #include "dir.h"
47 #include "panic.h"
48 #include "screens.h"
49 #ifdef HAVE_LCD_BITMAP
50 #include "widgets.h"
51 #include "peakmeter.h"
52 #endif
53 #ifdef HAVE_FMRADIO
54 #include "radio.h"
55 #endif
57 /*---------------------------------------------------*/
58 /* SPECIAL DEBUG STUFF */
59 /*---------------------------------------------------*/
60 extern int ata_device;
61 extern int ata_io_address;
62 extern int num_threads;
63 extern char *thread_name[];
65 #ifdef HAVE_LCD_BITMAP
66 /* Test code!!! */
67 bool dbg_os(void)
69 char buf[32];
70 int button;
71 int i;
72 int usage;
74 #ifdef HAVE_LCD_BITMAP
75 lcd_setmargins(0, 0);
76 #endif
77 lcd_clear_display();
79 while(1)
81 lcd_puts(0, 0, "Stack usage:");
82 for(i = 0; i < num_threads;i++)
84 usage = thread_stack_usage(i);
85 snprintf(buf, 32, "%s: %d%%", thread_name[i], usage);
86 lcd_puts(0, 1+i, buf);
89 lcd_update();
91 button = button_get_w_tmo(HZ/10);
93 switch(button)
95 #ifdef BUTTON_OFF
96 case BUTTON_OFF:
97 #endif
98 case BUTTON_LEFT:
99 return false;
102 return false;
104 #else
105 bool dbg_os(void)
107 char buf[32];
108 int button;
109 int usage;
110 int currval = 0;
112 #ifdef HAVE_LCD_BITMAP
113 lcd_setmargins(0, 0);
114 #endif
115 lcd_clear_display();
117 while(1)
119 lcd_puts(0, 0, "Stack usage");
121 usage = thread_stack_usage(currval);
122 snprintf(buf, 32, "%d: %d%% ", currval, usage);
123 lcd_puts(0, 1, buf);
125 button = button_get_w_tmo(HZ/10);
127 switch(button)
129 case BUTTON_STOP:
130 return false;
132 case BUTTON_LEFT:
133 currval--;
134 if(currval < 0)
135 currval = num_threads-1;
136 break;
138 case BUTTON_RIGHT:
139 currval++;
140 if(currval > num_threads-1)
141 currval = 0;
142 break;
145 return false;
147 #endif
149 #ifdef HAVE_LCD_BITMAP
150 bool dbg_mpeg_thread(void)
152 char buf[32];
153 int button;
154 int percent;
155 struct mpeg_debug d;
157 lcd_setmargins(0, 0);
159 while(1)
161 button = button_get_w_tmo(HZ/5);
162 switch(button)
164 case BUTTON_OFF | BUTTON_REL:
165 return false;
168 mpeg_get_debugdata(&d);
170 lcd_clear_display();
172 snprintf(buf, sizeof(buf), "read: %x", d.mp3buf_read);
173 lcd_puts(0, 0, buf);
174 snprintf(buf, sizeof(buf), "write: %x", d.mp3buf_write);
175 lcd_puts(0, 1, buf);
176 snprintf(buf, sizeof(buf), "swap: %x", d.mp3buf_swapwrite);
177 lcd_puts(0, 2, buf);
178 snprintf(buf, sizeof(buf), "playing: %d", d.playing);
179 lcd_puts(0, 3, buf);
180 snprintf(buf, sizeof(buf), "playable: %x", d.playable_space);
181 lcd_puts(0, 4, buf);
182 snprintf(buf, sizeof(buf), "unswapped: %x", d.unswapped_space);
183 lcd_puts(0, 5, buf);
185 percent = d.playable_space * 100 / d.mp3buflen;
186 progressbar(0, 6*8, 112, 4, percent, Grow_Right);
188 percent = d.low_watermark_level * 100 / d.mp3buflen;
189 progressbar(0, 6*8+4, 112, 4, percent, Grow_Right);
191 snprintf(buf, sizeof(buf), "wm: %x - %x",
192 d.low_watermark_level, d.lowest_watermark_level);
193 lcd_puts(0, 7, buf);
195 lcd_update();
197 return false;
199 #endif
202 /* Tool function to calculate a CRC16 across some buffer */
203 unsigned short crc_16(unsigned char* buf, unsigned len)
205 /* CCITT standard polynomial 0x1021 */
206 static const unsigned short crc16_lookup[16] =
207 { /* lookup table for 4 bits at a time is affordable */
208 0x0000, 0x1021, 0x2042, 0x3063,
209 0x4084, 0x50A5, 0x60C6, 0x70E7,
210 0x8108, 0x9129, 0xA14A, 0xB16B,
211 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF
213 unsigned short crc16 = 0xFFFF; /* initialise to 0xFFFF (CCITT specification) */
214 unsigned t;
215 unsigned char byte;
217 while (len--)
219 byte = *buf++; /* get one byte of data */
221 /* upper nibble of our data */
222 t = crc16 >> 12; /* extract the 4 most significant bits */
223 t ^= byte >> 4; /* XOR in 4 bits of the data into the extracted bits */
224 crc16 <<= 4; /* shift the CRC Register left 4 bits */
225 crc16 ^= crc16_lookup[t]; /* do the table lookup and XOR the result */
227 /* lower nibble of our data */
228 t = crc16 >> 12; /* extract the 4 most significant bits */
229 t ^= byte & 0x0F; /* XOR in 4 bits of the data into the extracted bits */
230 crc16 <<= 4; /* shift the CRC Register left 4 bits */
231 crc16 ^= crc16_lookup[t]; /* do the table lookup and XOR the result */
234 return crc16;
239 /* Tool function to read the flash manufacturer and type, if available.
240 Only chips which could be reprogrammed in system will return values.
241 (The mode switch addresses vary between flash manufacturers, hence addr1/2) */
242 bool dbg_flash_id(unsigned* p_manufacturer, unsigned* p_device, unsigned addr1, unsigned addr2)
244 unsigned not_manu, not_id; /* read values before switching to ID mode */
245 unsigned manu, id; /* read values when in ID mode */
246 volatile unsigned char* flash = (unsigned char*)0x2000000; /* flash mapping */
248 not_manu = flash[0]; /* read the normal content */
249 not_id = flash[1]; /* should be 'A' (0x41) and 'R' (0x52) from the "ARCH" marker */
251 flash[addr1] = 0xAA; /* enter command mode */
252 flash[addr2] = 0x55;
253 flash[addr1] = 0x90; /* ID command */
254 sleep(HZ/50); /* Atmel wants 20ms pause here */
256 manu = flash[0]; /* read the IDs */
257 id = flash[1];
259 flash[0] = 0xF0; /* reset flash (back to normal read mode) */
260 sleep(HZ/50); /* Atmel wants 20ms pause here */
262 /* I assume success if the obtained values are different from
263 the normal flash content. This is not perfectly bulletproof, they
264 could theoretically be the same by chance, causing us to fail. */
265 if (not_manu != manu || not_id != id) /* a value has changed */
267 *p_manufacturer = manu; /* return the results */
268 *p_device = id;
269 return true; /* success */
271 return false; /* fail */
275 #ifdef HAVE_LCD_BITMAP
276 bool dbg_hw_info(void)
278 char buf[32];
279 int button;
280 int usb_polarity;
281 int pr_polarity;
282 int bitmask = *(unsigned short*)0x20000fc;
283 int rom_version = *(unsigned short*)0x20000fe;
284 unsigned manu, id; /* flash IDs */
285 bool got_id; /* flag if we managed to get the flash IDs */
286 unsigned rom_crc = 0xFFFF; /* CRC16 of the boot ROM */
287 bool has_bootrom; /* flag for boot ROM present */
289 if(PADR & 0x400)
290 usb_polarity = 0; /* Negative */
291 else
292 usb_polarity = 1; /* Positive */
294 if(PADR & 0x800)
295 pr_polarity = 0; /* Negative */
296 else
297 pr_polarity = 1; /* Positive */
299 /* get flash ROM type */
300 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
301 if (!got_id)
302 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
304 /* check if the boot ROM area is a flash mirror */
305 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
306 if (has_bootrom) /* if ROM and Flash different */
308 /* calculate CRC16 checksum of boot ROM */
309 rom_crc = crc_16((unsigned char*)0x0000, 64*1024);
312 lcd_setmargins(0, 0);
313 lcd_setfont(FONT_SYSFIXED);
314 lcd_clear_display();
316 lcd_puts(0, 0, "[Hardware info]");
318 snprintf(buf, 32, "ROM: %d.%02d", rom_version/100, rom_version%100);
319 lcd_puts(0, 1, buf);
321 snprintf(buf, 32, "Mask: 0x%04x", bitmask);
322 lcd_puts(0, 2, buf);
324 snprintf(buf, 32, "USB: %s", usb_polarity?"positive":"negative");
325 lcd_puts(0, 3, buf);
327 snprintf(buf, 32, "ATA: 0x%x,%s", ata_io_address,
328 ata_device ? "slave":"master");
329 lcd_puts(0, 4, buf);
331 snprintf(buf, 32, "PR: %s", pr_polarity?"positive":"negative");
332 lcd_puts(0, 5, buf);
334 if (got_id)
335 snprintf(buf, 32, "Flash: M=%02x D=%02x", manu, id);
336 else
337 snprintf(buf, 32, "Flash: M=?? D=??"); /* unknown, sorry */
338 lcd_puts(0, 6, buf);
340 if (has_bootrom)
342 snprintf(buf, 32-3, "ROM CRC: 0x%04x", rom_crc);
343 if (rom_crc == 0x222F) /* known Version 1 */
344 strcat(buf, " V1");
346 else
348 snprintf(buf, 32, "Boot ROM: none");
350 lcd_puts(0, 7, buf);
352 lcd_update();
354 while(1)
356 button = button_get(true);
357 if(button == (BUTTON_OFF | BUTTON_REL))
358 return false;
361 return false;
363 #else
364 bool dbg_hw_info(void)
366 char buf[32];
367 int button;
368 int currval = 0;
369 int usb_polarity;
370 int bitmask = *(unsigned short*)0x20000fc;
371 int rom_version = *(unsigned short*)0x20000fe;
372 unsigned manu, id; /* flash IDs */
373 bool got_id; /* flag if we managed to get the flash IDs */
374 unsigned rom_crc = 0xFFFF; /* CRC16 of the boot ROM */
375 bool has_bootrom; /* flag for boot ROM present */
377 if(PADR & 0x400)
378 usb_polarity = 0; /* Negative */
379 else
380 usb_polarity = 1; /* Positive */
382 /* get flash ROM type */
383 got_id = dbg_flash_id(&manu, &id, 0x5555, 0x2AAA); /* try SST, Atmel, NexFlash */
384 if (!got_id)
385 got_id = dbg_flash_id(&manu, &id, 0x555, 0x2AA); /* try AMD, Macronix */
387 /* check if the boot ROM area is a flash mirror */
388 has_bootrom = (memcmp((char*)0, (char*)0x02000000, 64*1024) != 0);
389 if (has_bootrom) /* if ROM and Flash different */
391 /* calculate CRC16 checksum of boot ROM */
392 rom_crc = crc_16((unsigned char*)0x0000, 64*1024);
395 lcd_clear_display();
397 lcd_puts(0, 0, "[HW Info]");
398 while(1)
400 switch(currval)
402 case 0:
403 snprintf(buf, 32, "ROM: %d.%02d",
404 rom_version/100, rom_version%100);
405 break;
406 case 1:
407 snprintf(buf, 32, "USB: %s",
408 usb_polarity?"pos":"neg");
409 break;
410 case 2:
411 snprintf(buf, 32, "ATA: 0x%x%s",
412 ata_io_address, ata_device ? "s":"m");
413 break;
414 case 3:
415 snprintf(buf, 32, "Mask: %04x", bitmask);
416 break;
417 case 4:
418 if (got_id)
419 snprintf(buf, 32, "Flash:%02x,%02x", manu, id);
420 else
421 snprintf(buf, 32, "Flash:??,??"); /* unknown, sorry */
422 break;
423 case 5:
424 if (has_bootrom)
425 snprintf(buf, 32, "RomCRC:%04x", rom_crc);
426 else
427 snprintf(buf, 32, "BootROM: no");
430 lcd_puts(0, 1, buf);
431 lcd_update();
433 button = button_get(true);
435 switch(button)
437 case BUTTON_STOP:
438 return false;
440 case BUTTON_LEFT:
441 currval--;
442 if(currval < 0)
443 currval = 5;
444 break;
446 case BUTTON_RIGHT:
447 currval++;
448 if(currval > 5)
449 currval = 0;
450 break;
453 return false;
455 #endif
457 bool dbg_partitions(void)
459 int partition=0;
461 lcd_clear_display();
462 lcd_puts(0, 0, "Partition");
463 lcd_puts(0, 1, "list");
464 lcd_update();
465 sleep(HZ/2);
467 while(1)
469 char buf[32];
470 int button;
471 struct partinfo* p = disk_partinfo(partition);
473 lcd_clear_display();
474 snprintf(buf, sizeof buf, "P%d: S:%x", partition, p->start);
475 lcd_puts(0, 0, buf);
476 snprintf(buf, sizeof buf, "T:%x %d MB", p->type, p->size / 2048);
477 lcd_puts(0, 1, buf);
478 lcd_update();
480 button = button_get(true);
482 switch(button)
484 #ifdef HAVE_RECORDER_KEYPAD
485 case BUTTON_OFF:
486 #else
487 case BUTTON_STOP:
488 #endif
489 return false;
491 #ifdef HAVE_RECORDER_KEYPAD
492 case BUTTON_UP:
493 #endif
494 case BUTTON_LEFT:
495 partition--;
496 if (partition < 0)
497 partition = 3;
498 break;
500 #ifdef HAVE_RECORDER_KEYPAD
501 case BUTTON_DOWN:
502 #endif
503 case BUTTON_RIGHT:
504 partition++;
505 if (partition > 3)
506 partition = 0;
507 break;
509 case SYS_USB_CONNECTED:
510 usb_screen();
511 return true;
514 return false;
517 #ifdef HAVE_LCD_BITMAP
518 /* Test code!!! */
519 bool dbg_ports(void)
521 unsigned short porta;
522 unsigned short portb;
523 unsigned char portc;
524 char buf[32];
525 int button;
526 int battery_voltage;
527 int batt_int, batt_frac;
529 #ifdef HAVE_LCD_BITMAP
530 lcd_setmargins(0, 0);
531 #endif
532 lcd_clear_display();
534 while(1)
536 porta = PADR;
537 portb = PBDR;
538 portc = PCDR;
540 snprintf(buf, 32, "PADR: %04x", porta);
541 lcd_puts(0, 0, buf);
542 snprintf(buf, 32, "PBDR: %04x", portb);
543 lcd_puts(0, 1, buf);
545 snprintf(buf, 32, "AN0: %03x AN4: %03x", adc_read(0), adc_read(4));
546 lcd_puts(0, 2, buf);
547 snprintf(buf, 32, "AN1: %03x AN5: %03x", adc_read(1), adc_read(5));
548 lcd_puts(0, 3, buf);
549 snprintf(buf, 32, "AN2: %03x AN6: %03x", adc_read(2), adc_read(6));
550 lcd_puts(0, 4, buf);
551 snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7));
552 lcd_puts(0, 5, buf);
554 battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
555 batt_int = battery_voltage / 100;
556 batt_frac = battery_voltage % 100;
558 snprintf(buf, 32, "Batt: %d.%02dV %d%% ", batt_int, batt_frac,
559 battery_level());
560 lcd_puts(0, 6, buf);
562 snprintf(buf, 32, "ATA: %s, 0x%x",
563 ata_device?"slave":"master", ata_io_address);
564 lcd_puts(0, 7, buf);
566 lcd_update();
567 button = button_get_w_tmo(HZ/10);
569 switch(button)
571 case BUTTON_OFF | BUTTON_REL:
572 return false;
575 return false;
577 #else
578 bool dbg_ports(void)
580 unsigned short porta;
581 unsigned short portb;
582 unsigned char portc;
583 char buf[32];
584 int button;
585 int battery_voltage;
586 int batt_int, batt_frac;
587 int currval = 0;
589 #ifdef HAVE_LCD_BITMAP
590 lcd_setmargins(0, 0);
591 #endif
592 lcd_clear_display();
594 while(1)
596 porta = PADR;
597 portb = PBDR;
598 portc = PCDR;
600 switch(currval)
602 case 0:
603 snprintf(buf, 32, "PADR: %04x ", porta);
604 break;
605 case 1:
606 snprintf(buf, 32, "PBDR: %04x ", portb);
607 break;
608 case 2:
609 snprintf(buf, 32, "AN0: %03x ", adc_read(0));
610 break;
611 case 3:
612 snprintf(buf, 32, "AN1: %03x ", adc_read(1));
613 break;
614 case 4:
615 snprintf(buf, 32, "AN2: %03x ", adc_read(2));
616 break;
617 case 5:
618 snprintf(buf, 32, "AN3: %03x ", adc_read(3));
619 break;
620 case 6:
621 snprintf(buf, 32, "AN4: %03x ", adc_read(4));
622 break;
623 case 7:
624 snprintf(buf, 32, "AN5: %03x ", adc_read(5));
625 break;
626 case 8:
627 snprintf(buf, 32, "AN6: %03x ", adc_read(6));
628 break;
629 case 9:
630 snprintf(buf, 32, "AN7: %03x ", adc_read(7));
631 break;
632 case 10:
633 snprintf(buf, 32, "%s, 0x%x ",
634 ata_device?"slv":"mst", ata_io_address);
635 break;
637 lcd_puts(0, 0, buf);
639 battery_voltage = (adc_read(ADC_UNREG_POWER) *
640 BATTERY_SCALE_FACTOR) / 10000;
641 batt_int = battery_voltage / 100;
642 batt_frac = battery_voltage % 100;
644 snprintf(buf, 32, "Batt: %d.%02dV", batt_int, batt_frac);
645 lcd_puts(0, 1, buf);
647 button = button_get_w_tmo(HZ/5);
649 switch(button)
651 case BUTTON_STOP | BUTTON_REL:
652 return false;
654 case BUTTON_LEFT:
655 currval--;
656 if(currval < 0)
657 currval = 10;
658 break;
660 case BUTTON_RIGHT:
661 currval++;
662 if(currval > 10)
663 currval = 0;
664 break;
667 return false;
669 #endif
671 #ifdef HAVE_RTC
672 /* Read RTC RAM contents and display them */
673 bool dbg_rtc(void)
675 char buf[32];
676 unsigned char addr = 0, r, c;
677 int i;
678 int button;
680 #ifdef HAVE_LCD_BITMAP
681 lcd_setmargins(0, 0);
682 #endif
683 lcd_clear_display();
684 lcd_puts(0, 0, "RTC read:");
686 while(1)
688 for (r = 0; r < 4; r++) {
689 snprintf(buf, 10, "0x%02x: ", addr + r*4);
690 for (c = 0; c <= 3; c++) {
691 i = rtc_read(addr + r*4 + c);
692 snprintf(buf + 6 + c*2, 3, "%02x", i);
694 lcd_puts(1, r+1, buf);
697 lcd_update();
699 button = button_get_w_tmo(HZ/2);
701 switch(button)
703 case BUTTON_DOWN:
704 if (addr < 63-16) { addr += 16; }
705 break;
706 case BUTTON_UP:
707 if (addr) { addr -= 16; }
708 break;
709 case BUTTON_F2:
710 /* clear the user RAM space */
711 for (c = 0; c <= 43; c++)
712 rtc_write(0x14 + c, 0);
713 break;
714 case BUTTON_OFF | BUTTON_REL:
715 case BUTTON_LEFT | BUTTON_REL:
716 return false;
719 return false;
721 #else
722 bool dbg_rtc(void)
724 return false;
726 #endif
728 #ifdef HAVE_LCD_CHARCELLS
729 #define NUMROWS 1
730 #else
731 #define NUMROWS 4
732 #endif
733 /* Read MAS registers and display them */
734 bool dbg_mas(void)
736 char buf[32];
737 unsigned int addr = 0, r, i;
739 #ifdef HAVE_LCD_BITMAP
740 lcd_setmargins(0, 0);
741 #endif
742 lcd_clear_display();
743 lcd_puts(0, 0, "MAS register read:");
745 while(1)
747 for (r = 0; r < NUMROWS; r++) {
748 i = mas_readreg(addr + r);
749 snprintf(buf, 30, "%02x %08x", addr + r, i);
750 lcd_puts(0, r+1, buf);
753 lcd_update();
755 switch(button_get_w_tmo(HZ/16))
757 #ifdef HAVE_RECORDER_KEYPAD
758 case BUTTON_DOWN:
759 #else
760 case BUTTON_RIGHT:
761 #endif
762 addr += NUMROWS;
763 break;
764 #ifdef HAVE_RECORDER_KEYPAD
765 case BUTTON_UP:
766 #else
767 case BUTTON_LEFT:
768 #endif
769 if(addr)
770 addr -= NUMROWS;
771 break;
772 #ifdef HAVE_RECORDER_KEYPAD
773 case BUTTON_LEFT:
774 #else
775 case BUTTON_DOWN:
776 #endif
777 return false;
780 return false;
783 #ifdef HAVE_MAS3587F
784 bool dbg_mas_codec(void)
786 char buf[32];
787 unsigned int addr = 0, r, i;
789 #ifdef HAVE_LCD_BITMAP
790 lcd_setmargins(0, 0);
791 #endif
792 lcd_clear_display();
793 lcd_puts(0, 0, "MAS codec reg read:");
795 while(1)
797 for (r = 0; r < 4; r++) {
798 i = mas_codec_readreg(addr + r);
799 snprintf(buf, 30, "0x%02x: %08x", addr + r, i);
800 lcd_puts(1, r+1, buf);
803 lcd_update();
805 switch(button_get_w_tmo(HZ/16))
807 case BUTTON_DOWN:
808 addr += 4;
809 break;
810 case BUTTON_UP:
811 if (addr) { addr -= 4; }
812 break;
813 case BUTTON_LEFT | BUTTON_REL:
814 case BUTTON_OFF | BUTTON_REL:
815 return false;
818 return false;
820 #endif
822 #ifdef HAVE_LCD_BITMAP
824 * view_battery() shows a automatically scaled graph of the battery voltage
825 * over time. Usable for estimating battery life / charging rate.
826 * The power_history array is updated in power_thread of powermgmt.c.
829 #define BAT_FIRST_VAL MAX(POWER_HISTORY_LEN - LCD_WIDTH - 1, 0)
830 #define BAT_YSPACE (LCD_HEIGHT - 20)
832 bool view_battery(void)
834 int view = 0;
835 int i, x, y;
836 int maxv, minv;
837 char buf[32];
839 #ifdef HAVE_LCD_BITMAP
840 lcd_setmargins(0, 0);
841 #endif
842 while(1)
844 switch (view) {
845 case 0: /* voltage history graph */
846 /* Find maximum and minimum voltage for scaling */
847 maxv = minv = 0;
848 for (i = BAT_FIRST_VAL; i < POWER_HISTORY_LEN; i++) {
849 if (power_history[i] > maxv)
850 maxv = power_history[i];
851 if ((minv == 0) || ((power_history[i]) &&
852 (power_history[i] < minv)) )
854 minv = power_history[i];
858 if (minv < 1)
859 minv = 1;
860 if (maxv < 2)
861 maxv = 2;
863 lcd_clear_display();
864 lcd_puts(0, 0, "Battery voltage:");
865 snprintf(buf, 30, "scale %d.%02d-%d.%02d V",
866 minv / 100, minv % 100, maxv / 100, maxv % 100);
867 lcd_puts(0, 1, buf);
869 x = 0;
870 for (i = BAT_FIRST_VAL+1; i < POWER_HISTORY_LEN; i++) {
871 y = (power_history[i] - minv) * BAT_YSPACE / (maxv - minv);
872 lcd_clearline(x, LCD_HEIGHT-1, x, 20);
873 lcd_drawline(x, LCD_HEIGHT-1, x,
874 MIN(MAX(LCD_HEIGHT-1 - y, 20), LCD_HEIGHT-1));
875 x++;
878 break;
880 case 1: /* status: */
881 lcd_clear_display();
882 lcd_puts(0, 0, "Power status:");
884 y = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000;
885 snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100);
886 lcd_puts(0, 1, buf);
887 y = (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000;
888 snprintf(buf, 30, "External: %d.%02d V", y / 100, y % 100);
889 lcd_puts(0, 2, buf);
890 snprintf(buf, 30, "Charger: %s",
891 charger_inserted() ? "present" : "absent");
892 lcd_puts(0, 3, buf);
893 #ifdef HAVE_CHARGE_CTRL
894 snprintf(buf, 30, "Charging: %s",
895 charger_enabled ? "yes" : "no");
896 lcd_puts(0, 4, buf);
897 #endif
898 y = ( power_history[POWER_HISTORY_LEN-1] * 100
899 + power_history[POWER_HISTORY_LEN-2] * 100
900 - power_history[POWER_HISTORY_LEN-1-CHARGE_END_NEGD+1] * 100
901 - power_history[POWER_HISTORY_LEN-1-CHARGE_END_NEGD] * 100 )
902 / CHARGE_END_NEGD / 2;
904 snprintf(buf, 30, "short delta: %d", y);
905 lcd_puts(0, 5, buf);
907 y = ( power_history[POWER_HISTORY_LEN-1] * 100
908 + power_history[POWER_HISTORY_LEN-2] * 100
909 - power_history[POWER_HISTORY_LEN-1-CHARGE_END_ZEROD+1] * 100
910 - power_history[POWER_HISTORY_LEN-1-CHARGE_END_ZEROD] * 100 )
911 / CHARGE_END_ZEROD / 2;
913 snprintf(buf, 30, "long delta: %d", y);
914 lcd_puts(0, 6, buf);
916 #ifdef HAVE_CHARGE_CTRL
917 lcd_puts(0, 7, power_message);
918 #endif
919 break;
921 case 2: /* voltage deltas: */
922 lcd_clear_display();
923 lcd_puts(0, 0, "Voltage deltas:");
925 for (i = 0; i <= 6; i++) {
926 y = power_history[POWER_HISTORY_LEN-1-i] -
927 power_history[POWER_HISTORY_LEN-1-i-1];
928 snprintf(buf, 30, "-%d min: %s%d.%02d V", i,
929 (y < 0) ? "-" : "", ((y < 0) ? y * -1 : y) / 100,
930 ((y < 0) ? y * -1 : y ) % 100);
931 lcd_puts(0, i+1, buf);
933 break;
935 case 3: /* remeining time estimation: */
936 lcd_clear_display();
938 #ifdef HAVE_CHARGE_CTRL
939 snprintf(buf, 30, "charge_state: %d", charge_state);
940 lcd_puts(0, 0, buf);
942 snprintf(buf, 30, "Cycle time: %d m", powermgmt_last_cycle_startstop_min);
943 lcd_puts(0, 1, buf);
945 snprintf(buf, 30, "Lev.at cycle start: %d%%", powermgmt_last_cycle_level);
946 lcd_puts(0, 2, buf);
947 #endif
949 snprintf(buf, 30, "Last PwrHist val: %d.%02d V",
950 power_history[POWER_HISTORY_LEN-1] / 100,
951 power_history[POWER_HISTORY_LEN-1] % 100);
952 lcd_puts(0, 3, buf);
954 snprintf(buf, 30, "battery level: %d%%", battery_level());
955 lcd_puts(0, 5, buf);
957 snprintf(buf, 30, "Est. remaining: %d m", battery_time());
958 lcd_puts(0, 6, buf);
960 #ifdef HAVE_CHARGE_CTRL
961 snprintf(buf, 30, "Trickle sec: %d/60", trickle_sec);
962 lcd_puts(0, 7, buf);
963 #endif
964 break;
967 lcd_update();
969 switch(button_get_w_tmo(HZ/2))
971 case BUTTON_UP:
972 if (view)
973 view--;
974 break;
976 case BUTTON_DOWN:
977 if (view < 3)
978 view++;
979 break;
981 case BUTTON_LEFT | BUTTON_REL:
982 case BUTTON_OFF | BUTTON_REL:
983 return false;
986 return false;
989 #endif
991 #ifdef HAVE_MAS3507D
992 bool dbg_mas_info(void)
994 int button;
995 char buf[32];
996 int currval = 0;
997 unsigned long val;
998 unsigned long pll48, pll44, config;
999 int pll_toggle = 0;
1001 #ifdef HAVE_LCD_BITMAP
1002 lcd_setmargins(0, 0);
1003 #endif
1004 while(1)
1006 switch(currval)
1008 case 0:
1009 mas_readmem(MAS_BANK_D1, 0xff7, &val, 1);
1010 lcd_puts(0, 0, "Design Code");
1011 snprintf(buf, 32, "%05x ", val);
1012 break;
1013 case 1:
1014 lcd_puts(0, 0, "DC/DC mode ");
1015 snprintf(buf, 32, "8e: %05x ", mas_readreg(0x8e) & 0xfffff);
1016 break;
1017 case 2:
1018 lcd_puts(0, 0, "Mute/Bypass");
1019 snprintf(buf, 32, "aa: %05x ", mas_readreg(0xaa) & 0xfffff);
1020 break;
1021 case 3:
1022 lcd_puts(0, 0, "PIOData ");
1023 snprintf(buf, 32, "ed: %05x ", mas_readreg(0xed) & 0xfffff);
1024 break;
1025 case 4:
1026 lcd_puts(0, 0, "Startup Cfg");
1027 snprintf(buf, 32, "e6: %05x ", mas_readreg(0xe6) & 0xfffff);
1028 break;
1029 case 5:
1030 lcd_puts(0, 0, "KPrescale ");
1031 snprintf(buf, 32, "e7: %05x ", mas_readreg(0xe7) & 0xfffff);
1032 break;
1033 case 6:
1034 lcd_puts(0, 0, "KBass ");
1035 snprintf(buf, 32, "6b: %05x ", mas_readreg(0x6b) & 0xfffff);
1036 break;
1037 case 7:
1038 lcd_puts(0, 0, "KTreble ");
1039 snprintf(buf, 32, "6f: %05x ", mas_readreg(0x6f) & 0xfffff);
1040 break;
1041 case 8:
1042 mas_readmem(MAS_BANK_D0, 0x300, &val, 1);
1043 lcd_puts(0, 0, "Frame Count");
1044 snprintf(buf, 32, "0/300: %04x", val & 0xffff);
1045 break;
1046 case 9:
1047 mas_readmem(MAS_BANK_D0, 0x301, &val, 1);
1048 lcd_puts(0, 0, "Status1 ");
1049 snprintf(buf, 32, "0/301: %04x", val & 0xffff);
1050 break;
1051 case 10:
1052 mas_readmem(MAS_BANK_D0, 0x302, &val, 1);
1053 lcd_puts(0, 0, "Status2 ");
1054 snprintf(buf, 32, "0/302: %04x", val & 0xffff);
1055 break;
1056 case 11:
1057 mas_readmem(MAS_BANK_D0, 0x303, &val, 1);
1058 lcd_puts(0, 0, "CRC Count ");
1059 snprintf(buf, 32, "0/303: %04x", val & 0xffff);
1060 break;
1061 case 12:
1062 mas_readmem(MAS_BANK_D0, 0x36d, &val, 1);
1063 lcd_puts(0, 0, "PLLOffset48");
1064 snprintf(buf, 32, "0/36d %05x", val & 0xfffff);
1065 break;
1066 case 13:
1067 mas_readmem(MAS_BANK_D0, 0x32d, &val, 1);
1068 lcd_puts(0, 0, "PLLOffset48");
1069 snprintf(buf, 32, "0/32d %05x", val & 0xfffff);
1070 break;
1071 case 14:
1072 mas_readmem(MAS_BANK_D0, 0x36e, &val, 1);
1073 lcd_puts(0, 0, "PLLOffset44");
1074 snprintf(buf, 32, "0/36e %05x", val & 0xfffff);
1075 break;
1076 case 15:
1077 mas_readmem(MAS_BANK_D0, 0x32e, &val, 1);
1078 lcd_puts(0, 0, "PLLOffset44");
1079 snprintf(buf, 32, "0/32e %05x", val & 0xfffff);
1080 break;
1081 case 16:
1082 mas_readmem(MAS_BANK_D0, 0x36f, &val, 1);
1083 lcd_puts(0, 0, "OutputConf ");
1084 snprintf(buf, 32, "0/36f %05x", val & 0xfffff);
1085 break;
1086 case 17:
1087 mas_readmem(MAS_BANK_D0, 0x32f, &val, 1);
1088 lcd_puts(0, 0, "OutputConf ");
1089 snprintf(buf, 32, "0/32f %05x", val & 0xfffff);
1090 break;
1091 case 18:
1092 mas_readmem(MAS_BANK_D1, 0x7f8, &val, 1);
1093 lcd_puts(0, 0, "LL Gain ");
1094 snprintf(buf, 32, "1/7f8 %05x", val & 0xfffff);
1095 break;
1096 case 19:
1097 mas_readmem(MAS_BANK_D1, 0x7f9, &val, 1);
1098 lcd_puts(0, 0, "LR Gain ");
1099 snprintf(buf, 32, "1/7f9 %05x", val & 0xfffff);
1100 break;
1101 case 20:
1102 mas_readmem(MAS_BANK_D1, 0x7fa, &val, 1);
1103 lcd_puts(0, 0, "RL Gain ");
1104 snprintf(buf, 32, "1/7fa %05x", val & 0xfffff);
1105 break;
1106 case 21:
1107 mas_readmem(MAS_BANK_D1, 0x7fb, &val, 1);
1108 lcd_puts(0, 0, "RR Gain ");
1109 snprintf(buf, 32, "1/7fb %05x", val & 0xfffff);
1110 break;
1111 case 22:
1112 lcd_puts(0, 0, "L Trailbits");
1113 snprintf(buf, 32, "c5: %05x ", mas_readreg(0xc5) & 0xfffff);
1114 break;
1115 case 23:
1116 lcd_puts(0, 0, "R Trailbits");
1117 snprintf(buf, 32, "c6: %05x ", mas_readreg(0xc6) & 0xfffff);
1118 break;
1120 lcd_puts(0, 1, buf);
1122 button = button_get_w_tmo(HZ/5);
1123 switch(button)
1125 case BUTTON_STOP:
1126 return false;
1128 case BUTTON_LEFT:
1129 currval--;
1130 if(currval < 0)
1131 currval = 23;
1132 break;
1134 case BUTTON_RIGHT:
1135 currval++;
1136 if(currval > 23)
1137 currval = 0;
1138 break;
1139 case BUTTON_PLAY:
1140 pll_toggle = !pll_toggle;
1141 if(pll_toggle)
1143 /* 14.31818 MHz crystal */
1144 pll48 = 0x5d9d0;
1145 pll44 = 0xfffceceb;
1146 config = 0;
1148 else
1150 /* 14.725 MHz crystal */
1151 pll48 = 0x2d0de;
1152 pll44 = 0xfffa2319;
1153 config = 0;
1155 mas_writemem(MAS_BANK_D0, 0x32d, &pll48, 1);
1156 mas_writemem(MAS_BANK_D0, 0x32e, &pll44, 1);
1157 mas_writemem(MAS_BANK_D0, 0x32f, &config, 1);
1158 mas_run(0x475);
1159 break;
1162 return false;
1164 #endif
1166 static bool view_runtime(void)
1168 char s[32];
1169 bool done = false;
1170 int state = 1;
1172 while(!done)
1174 int y=0;
1175 int t;
1176 int key;
1177 lcd_clear_display();
1178 #ifdef HAVE_LCD_BITMAP
1179 lcd_puts(0, y++, "Running time:");
1180 y++;
1181 #endif
1183 if (state & 1) {
1184 if (charger_inserted())
1186 global_settings.runtime = 0;
1188 else
1190 global_settings.runtime += ((current_tick - lasttime) / HZ);
1192 lasttime = current_tick;
1194 t = global_settings.runtime;
1195 lcd_puts(0, y++, "Current time");
1197 else {
1198 t = global_settings.topruntime;
1199 lcd_puts(0, y++, "Top time");
1202 snprintf(s, sizeof(s), "%dh %dm %ds",
1203 t / 3600, (t % 3600) / 60, t % 60);
1204 lcd_puts(0, y++, s);
1205 lcd_update();
1207 /* Wait for a key to be pushed */
1208 key = button_get_w_tmo(HZ);
1209 switch(key) {
1210 #if defined(HAVE_PLAYER_KEYPAD) || defined(HAVE_NEO_KEYPAD)
1211 case BUTTON_STOP | BUTTON_REL:
1212 #elif HAVE_RECORDER_KEYPAD
1213 case BUTTON_OFF | BUTTON_REL:
1214 #endif
1215 done = true;
1216 break;
1218 case BUTTON_LEFT:
1219 case BUTTON_RIGHT:
1220 if (state == 1)
1221 state = 2;
1222 else
1223 state = 1;
1224 break;
1226 case BUTTON_PLAY:
1227 lcd_clear_display();
1228 lcd_puts(0,0,"Clear time?");
1229 lcd_puts(0,1,"PLAY = Yes");
1230 lcd_update();
1231 while (1) {
1232 key = button_get_w_tmo(HZ*10);
1233 if ( key & BUTTON_REL )
1234 continue;
1235 if ( key == BUTTON_PLAY ) {
1236 if ( state == 1 )
1237 global_settings.runtime = 0;
1238 else
1239 global_settings.topruntime = 0;
1241 break;
1243 break;
1247 return false;
1250 static bool dbg_disk_info(void)
1252 char buf[128];
1253 bool done = false;
1254 int i;
1255 int page = 0;
1256 const int max_page = 11;
1257 unsigned short* identify_info = ata_get_identify();
1258 bool timing_info_present = false;
1259 char pio3[2], pio4[2];
1261 #ifdef HAVE_LCD_BITMAP
1262 lcd_setmargins(0, 0);
1263 #endif
1265 while(!done)
1267 int y=0;
1268 int key;
1269 lcd_clear_display();
1270 #ifdef HAVE_LCD_BITMAP
1271 lcd_puts(0, y++, "Disk info:");
1272 y++;
1273 #endif
1275 switch (page) {
1276 case 0:
1277 for (i=0; i < 20; i++)
1278 ((unsigned short*)buf)[i]=identify_info[i+27];
1279 buf[40]=0;
1280 /* kill trailing space */
1281 for (i=39; i && buf[i]==' '; i--)
1282 buf[i] = 0;
1283 lcd_puts(0, y++, "Model");
1284 lcd_puts_scroll(0, y++, buf);
1285 break;
1287 case 1:
1288 for (i=0; i < 4; i++)
1289 ((unsigned short*)buf)[i]=identify_info[i+23];
1290 buf[8]=0;
1291 lcd_puts(0, y++, "Firmware");
1292 lcd_puts(0, y++, buf);
1293 break;
1295 case 2:
1296 snprintf(buf, sizeof buf, "%d MB",
1297 ((unsigned)identify_info[61] << 16 |
1298 (unsigned)identify_info[60]) / 2048 );
1299 lcd_puts(0, y++, "Size");
1300 lcd_puts(0, y++, buf);
1301 break;
1303 case 3: {
1304 unsigned int free;
1305 fat_size( NULL, &free );
1306 snprintf(buf, sizeof buf, "%d MB", free / 1024 );
1307 lcd_puts(0, y++, "Free");
1308 lcd_puts(0, y++, buf);
1309 break;
1312 case 4:
1313 snprintf(buf, sizeof buf, "%d ms", ata_spinup_time * (1000/HZ));
1314 lcd_puts(0, y++, "Spinup time");
1315 lcd_puts(0, y++, buf);
1316 break;
1318 case 5:
1319 i = identify_info[83] & (1<<3);
1320 lcd_puts(0, y++, "Power mgmt:");
1321 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1322 break;
1324 case 6:
1325 i = identify_info[83] & (1<<9);
1326 lcd_puts(0, y++, "Noise mgmt:");
1327 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1328 break;
1330 case 7:
1331 i = identify_info[82] & (1<<6);
1332 lcd_puts(0, y++, "Read-ahead:");
1333 lcd_puts(0, y++, i ? "enabled" : "unsupported");
1334 break;
1336 case 8:
1337 timing_info_present = identify_info[53] & (1<<1);
1338 if(timing_info_present) {
1339 pio3[1] = 0;
1340 pio4[1] = 0;
1341 lcd_puts(0, y++, "PIO modes:");
1342 pio3[0] = (identify_info[64] & (1<<0)) ? '3' : 0;
1343 pio4[0] = (identify_info[64] & (1<<1)) ? '4' : 0;
1344 snprintf(buf, 128, "0 1 2 %s %s", pio3, pio4);
1345 lcd_puts(0, y++, buf);
1346 } else {
1347 lcd_puts(0, y++, "No PIO mode info");
1349 break;
1351 case 9:
1352 timing_info_present = identify_info[53] & (1<<1);
1353 if(timing_info_present) {
1354 lcd_puts(0, y++, "Cycle times");
1355 snprintf(buf, 128, "%dns/%dns",
1356 identify_info[67],
1357 identify_info[68]);
1358 lcd_puts(0, y++, buf);
1359 } else {
1360 lcd_puts(0, y++, "No timing info");
1362 break;
1364 case 10:
1365 timing_info_present = identify_info[53] & (1<<1);
1366 if(timing_info_present) {
1367 i = identify_info[49] & (1<<11);
1368 snprintf(buf, 128, "IORDY support: %s", i ? "yes" : "no");
1369 lcd_puts(0, y++, buf);
1370 i = identify_info[49] & (1<<10);
1371 snprintf(buf, 128, "IORDY disable: %s", i ? "yes" : "no");
1372 lcd_puts(0, y++, buf);
1373 } else {
1374 lcd_puts(0, y++, "No timing info");
1376 break;
1378 case 11:
1379 lcd_puts(0, y++, "Cluster size");
1380 snprintf(buf, 128, "%d bytes", fat_get_cluster_size());
1381 lcd_puts(0, y++, buf);
1382 break;
1384 lcd_update();
1386 /* Wait for a key to be pushed */
1387 key = button_get_w_tmo(HZ*5);
1388 switch(key) {
1389 #if defined(HAVE_PLAYER_KEYPAD) || defined(HAVE_NEO_KEYPAD)
1390 case BUTTON_STOP | BUTTON_REL:
1391 #else
1392 case BUTTON_OFF | BUTTON_REL:
1393 #endif
1394 done = true;
1395 break;
1397 case BUTTON_LEFT:
1398 if (--page < 0)
1399 page = max_page;
1400 break;
1402 case BUTTON_RIGHT:
1403 if (++page > max_page)
1404 page = 0;
1405 break;
1407 case BUTTON_PLAY:
1408 if (page == 3) {
1409 mpeg_stop(); /* stop playback, to avoid disk access */
1410 lcd_clear_display();
1411 lcd_puts(0,0,"Scanning");
1412 lcd_puts(0,1,"disk...");
1413 lcd_update();
1414 fat_recalc_free();
1416 break;
1418 lcd_stop_scroll();
1421 return false;
1424 bool dbg_save_roms(void)
1426 int fd;
1428 fd = creat("/internal_rom_0000-FFFF.bin", O_WRONLY);
1429 if(fd >= 0)
1431 write(fd, (void *)0, 0x10000);
1432 close(fd);
1435 fd = creat("/internal_rom_2000000-203FFFF.bin", O_WRONLY);
1436 if(fd >= 0)
1438 write(fd, (void *)0x2000000, 0x40000);
1439 close(fd);
1442 return false;
1445 #ifdef HAVE_FMRADIO
1446 extern int debug_fm_detection;
1448 bool dbg_fm_radio(void)
1450 char buf[32];
1451 int button;
1452 bool fm_detected;
1454 #ifdef HAVE_LCD_BITMAP
1455 lcd_setmargins(0, 0);
1456 #endif
1458 while(1)
1460 lcd_clear_display();
1461 fm_detected = radio_hardware_present();
1463 snprintf(buf, sizeof buf, "HW detected: %s", fm_detected?"yes":"no");
1464 lcd_puts(0, 0, buf);
1465 snprintf(buf, sizeof buf, "Result: %08x", debug_fm_detection);
1466 lcd_puts(0, 1, buf);
1467 lcd_update();
1469 button = button_get(true);
1471 switch(button)
1473 #ifdef HAVE_RECORDER_KEYPAD
1474 case BUTTON_OFF:
1475 #else
1476 case BUTTON_STOP:
1477 #endif
1478 return false;
1481 return false;
1483 #endif
1485 static bool dbg_sound(void)
1487 char buf[128];
1488 bool done = false;
1489 bool set = true;
1490 long ll, lr, rr, rl;
1491 int d, i;
1492 #ifdef HAVE_MAS3587F
1493 long superbass;
1494 long val;
1495 #endif
1497 #ifdef HAVE_LCD_BITMAP
1498 lcd_setmargins(0, 0);
1499 #endif
1501 /* Normal stereo */
1502 ll = 0x80000;
1503 lr = 0x00000;
1504 rr = 0x80000;
1505 rl = 0x00000;
1507 #ifdef HAVE_MAS3587F
1508 /* Set the MDB to the Archos "flat" setting, but not activated */
1509 mas_codec_writereg(MAS_REG_KMDB_STR, 0);
1510 mas_codec_writereg(MAS_REG_KMDB_HAR, 0x3000);
1511 mas_codec_writereg(MAS_REG_KMDB_FC, 0x0600);
1512 mas_codec_writereg(MAS_REG_KMDB_SWITCH, 0);
1513 #endif
1515 while(!done)
1517 int button;
1519 #ifdef HAVE_MAS3587F
1520 superbass = mas_codec_readreg(MAS_REG_KLOUDNESS) & 0x0004;
1521 #endif
1523 lcd_clear_display();
1524 d = 200 - ll * 100 / 0x80000;
1525 i = d / 100;
1526 snprintf(buf, sizeof buf, "LL: -%d.%02d (%05x)", i, d % 100, ll);
1527 lcd_puts(0, 0, buf);
1529 d = - lr * 100 / 0x80000;
1530 i = d / 100;
1531 snprintf(buf, sizeof buf, "LR: -%d.%02d (%05x)", i, d % 100,
1532 lr & 0x000fffff);
1533 lcd_puts(0, 1, buf);
1535 #ifdef HAVE_MAS3587F
1536 if(superbass)
1537 lcd_puts(0, 2, "Super Bass");
1538 #endif
1539 lcd_update();
1541 /* Wait for a key to be pushed */
1542 button = button_get(true);
1543 switch(button) {
1544 #if defined(HAVE_PLAYER_KEYPAD) || defined(HAVE_NEO_KEYPAD)
1545 case BUTTON_STOP | BUTTON_REL:
1546 #else
1547 case BUTTON_OFF | BUTTON_REL:
1548 #endif
1549 done = true;
1550 break;
1552 case BUTTON_LEFT:
1553 case BUTTON_LEFT | BUTTON_REPEAT:
1554 if(ll < 0x100000)
1556 ll += 0x80000/128;
1557 rr += 0x80000/128;
1558 lr -= 0x80000/128;
1559 rl -= 0x80000/128;
1561 set = true;
1562 break;
1564 case BUTTON_RIGHT:
1565 case BUTTON_RIGHT | BUTTON_REPEAT:
1566 if(ll > 0x80000)
1568 ll -= 0x80000/128;
1569 rr -= 0x80000/128;
1570 lr += 0x80000/128;
1571 rl += 0x80000/128;
1573 set = true;
1574 break;
1576 case BUTTON_PLAY:
1577 if(set) /* This means that the current config is the
1578 custom one */
1579 mpeg_sound_set(SOUND_CHANNELS, MPEG_SOUND_STEREO);
1581 set = !set;
1582 break;
1584 #ifdef HAVE_MAS3587F
1585 case BUTTON_ON:
1586 val = mas_codec_readreg(MAS_REG_KLOUDNESS);
1587 val ^= 0x0004;
1588 mas_codec_writereg(MAS_REG_KLOUDNESS, val);
1589 if(val)
1590 mas_codec_writereg(MAS_REG_KMDB_SWITCH, 0x0902);
1591 else
1592 mas_codec_writereg(MAS_REG_KMDB_SWITCH, 0);
1593 break;
1594 #endif
1596 if(set)
1598 #ifdef HAVE_MAS3587F
1599 mas_writemem(MAS_BANK_D0, 0x7fc, &ll, 1); /* LL */
1600 mas_writemem(MAS_BANK_D0, 0x7fd, &lr, 1); /* LR */
1601 mas_writemem(MAS_BANK_D0, 0x7fe, &rl, 1); /* RL */
1602 mas_writemem(MAS_BANK_D0, 0x7ff, &rr, 1); /* RR */
1603 #else
1604 mas_writemem(MAS_BANK_D1, 0x7f8, &ll, 1); /* LL */
1605 mas_writemem(MAS_BANK_D1, 0x7f9, &lr, 1); /* LR */
1606 mas_writemem(MAS_BANK_D1, 0x7fa, &rl, 1); /* RL */
1607 mas_writemem(MAS_BANK_D1, 0x7fb, &rr, 1); /* RR */
1608 #endif
1612 return false;
1615 bool debug_menu(void)
1617 int m;
1618 bool result;
1620 struct menu_item items[] = {
1621 { "Dump ROM contents", -1, dbg_save_roms },
1622 { "View I/O ports", -1, dbg_ports },
1623 #ifdef HAVE_LCD_BITMAP
1624 #ifdef HAVE_RTC
1625 { "View/clr RTC RAM", -1, dbg_rtc },
1626 #endif /* HAVE_RTC */
1627 #endif /* HAVE_LCD_BITMAP */
1628 { "View OS stacks", -1, dbg_os },
1629 #ifdef HAVE_MAS3507D
1630 { "View MAS info", -1, dbg_mas_info },
1631 #endif
1632 { "View MAS regs", -1, dbg_mas },
1633 #ifdef HAVE_MAS3587F
1634 { "View MAS codec", -1, dbg_mas_codec },
1635 #endif
1636 #ifdef HAVE_LCD_BITMAP
1637 { "View battery", -1, view_battery },
1638 #endif
1639 { "View HW info", -1, dbg_hw_info },
1640 { "View partitions", -1, dbg_partitions },
1641 { "View disk info", -1, dbg_disk_info },
1642 #ifdef HAVE_LCD_BITMAP
1643 { "View mpeg thread", -1, dbg_mpeg_thread },
1644 #ifdef PM_DEBUG
1645 { "pm histogram", -1, peak_meter_histogram},
1646 #endif /* PM_DEBUG */
1647 #endif /* HAVE_LCD_BITMAP */
1648 { "View runtime", -1, view_runtime },
1649 #ifdef HAVE_FMRADIO
1650 { "FM Radio", -1, dbg_fm_radio },
1651 #endif
1652 { "Sound test", -1, dbg_sound },
1655 m=menu_init( items, sizeof items / sizeof(struct menu_item), NULL,
1656 NULL, NULL, NULL);
1657 result = menu_run(m);
1658 menu_exit(m);
1660 return result;
1663 #endif /* SIMULATOR */