OSDN Git Service

[v2.0][SHELL][SRECORD] Invert checksum before check.
[openi2cradio/OpenI2CRadio.git] / menu.c
diff --git a/menu.c b/menu.c
index 1fd4f0f..da99968 100644 (file)
--- a/menu.c
+++ b/menu.c
  */
 
 #include "menu.h"
+#include "menu_memoryfreq.h"
 #include "power.h"
 #include "commondef.h"
-
-const char *updown_helpstr[20] = {
-        "Help", "F=exit any=continue",
-        "5: Menu", " ",
-        "1: Slow Down", "3: Slow Up",
-        "4: Down", "6: Up",
-        "7: Fast Down", "9: Fast Up",
-        "2: Band Down", "8: Band Up",
-        "0: Mode3K", " ",
-        "a: AM/FM", "b: Volume",
-        "c: Scan", "d: Stereo mode",
-        "e: Backlight", "f: (Exit) Help",
-    };
-
-const char *setup_helpstr[16] = {
-        "Help", "F=exit any=continue",
-        "0: Power OFF", "C: Save status",
-        "d: Reset default", "E: BL time",
-        "A: Load", "",
-        "1: FM CNR", "2: AM CNR"
-        "3: FM STEREO", "4: Reserve"
-        "6: Reserve", "7: Reserve",
-        "8: Reserve", "9: Reserve",
-        "5: Cancel", "f: (Exit) Help",
-    };
-
-const char *mainmenu_helpstr[18] = {
-        "Help", "F=exit any=continue",
-        "0: Setup", "1: Reserve",
-        "2: Band", "3: Freq",
-        "4: Reserve", "5: Scan"
-        "6: Gain", "7: Volume",
-        "8: FM Wide/Narrow", "9: Reserved",
-        "a: PowOFF", "b: Cancel",
-        "c: Set user", "d: Input user",
-        "e: AM/FM", "f: (Exit) Help"
-};
-
-const char *numeric_helpstr[10] = {
-     "On numeric input", " ",
-    "0-9: Numeric", "f: enter",
-    "a: Delete", "b: Reset value",
-    "d: Left", "e: Right",
-    "Press any key", " to continue."
-};
+#include "backlight.h"
 
 void toggle_amfm(void)
 {
     unsigned int freq;
-    if(fm != 0){
-        fm = 0;
-        fmfreq_bank[fmband] = fmfreq;
+    if(setup.fm != 0){
+        setup.fm = 0;
+        setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
   //      akc6955_set_amband(amband);
-        freq = amfreq_bank[amband];
+        freq = setup.amfreq_bank[setup.amband];
     } else {
-        fm = 0xff;
-        amfreq_bank[amband] = amfreq;
+        setup.fm = 0xff;
+        setup.amfreq_bank[setup.amband] = setup.amfreq;
 //        akc6955_set_fmband(fmband);
-        freq = fmfreq_bank[fmband];
+        freq = setup.fmfreq_bank[setup.fmband];
     }
-    akc6955_chg_fm(fm, freq);
+    akc6955_chg_fm(setup.fm, freq);
     idle_time_ms(500);
 //    akc6955_set_freq(freq);
 }
 
 
-void set_thresh_fmstereo(unsigned char a)
-{
-    unsigned char b;
-    a = a & 0x03;
-    threshold_fmstereo = a;
-    b = akc6955_readcmd(AKC6955_THRESH) & 0xfc;
-    akc6955_writecmd(AKC6955_THRESH, a | b);
-}
-
-void set_thresh_width(unsigned char a)
-{
-    unsigned char b;
-    a = a & 0x03;
-    threshold_width = a;
-    a = a << 2; // << 2
-    b = akc6955_readcmd(AKC6955_THRESH) & 0xf3;;
-    akc6955_writecmd(AKC6955_THRESH, a | b);
-}
-
-void set_thresh_amcnr(unsigned char a)
-{
-    unsigned char b;
-    a = a & 0x03;
-    threshold_amcnr = a;
-    a = a << 4; // << 4
-    b = akc6955_readcmd(AKC6955_THRESH) & 0xcf;
-    akc6955_writecmd(AKC6955_THRESH, a | b);
-}
-
-void set_thresh_fmcnr(unsigned char a)
-{
-    unsigned char b;
-    a = a & 0x03;
-    threshold_fmcnr = a;
-    a = a << 6; // << 4
-    b = akc6955_readcmd(AKC6955_THRESH) & 0x3f;
-    akc6955_writecmd(AKC6955_THRESH, a | b);
-}
 
 void set_stereomode(void)
 {
     __bitops_t mode;
     mode.byte = 0x00;
-    if(stereo == 0x00){
+    if(setup.stereo == 0x00){
             mode.b0 = 1; // Force mono
-    } else if(stereo < 0x80){
+    } else if(setup.stereo < 0x80){
             mode.b1 = 1; // Force stereo
     }
     akc6955_set_stereomode(mode.byte);
@@ -148,371 +67,102 @@ void set_stereomode(void)
 
 void set_stereo(void)
 {
-    if(stereo == 0xff) {// Force Mono
-        stereo = 0x00;
-    } else if(stereo == 0x00) { //Mono->Stereo
-        stereo = 0x7f;
+    
+    if(setup.stereo == 0xff) {// Force Mono
+        setup.stereo = 0x00;
+    } else if(setup.stereo == 0x00) { //Mono->Stereo
+        setup.stereo = 0x7f;
     } else { // Default, Stereo->auto
-        stereo = 0xff;
+        setup.stereo = 0xff;
     }
     set_stereomode();
 }
 
-
-void set_volume(void)
-{
-    unsigned char c;
-    unsigned char d;
-    unsigned char p;
-    unsigned char fact;
-
-    _CLS();
-    do {
-    _LOCATE(0,0);
-     d = akc6955_getvolumemode();
-      if(d == 0){
-         _PUTCHAR('D');
-       } else {
-         _PUTCHAR('K');
-       }
-     printstr(" Vol:");
-     print_numeric_nosupress(volume, 2);
-     printstr("  F:Exit");
-     _LOCATE(0,1);
-     printstr("Pre:");
-     _PUTCHAR('0' + (prevolume & 3));
-     _LOCATE(16-4, 1);
-     if(lowboost == 0x00){
-         printstr("   ");
-     } else {
-         printstr("LOW");
-     }
-     _HOME();
-     c = pollkeys(pollkeybuf, 60, 1);
-     p = 0;
-     while(c > 0) {
-         switch(pollkeybuf[p]) {
-             case charcode_6:
-                 volume++;
-                 if(volume > 63) volume = 63;
-                 break;
-             case charcode_4:
-                 volume--;
-                 if(volume < 23) volume = 23;
-                 break;
-             case charcode_f:
-                 return;
-             case charcode_a:
-                 fact = 0xff;
-                 if(d != 0){
-                     fact = 0x00;
-                 }
-                 akc6955_setvolumemode(fact);
-                 break;
-             case charcode_b:
-                 prevolume++;
-                 if(prevolume > 3) prevolume = 0;
-                 akc6955_set_prevolume(prevolume);
-                 break;
-             case charcode_d:
-                 fact = 0x00;
-                 if(lowboost == 0x00){
-                     fact = 0xff;
-                 }
-                 lowboost = fact;
-                 akc6955_set_lowboost(lowboost);
-                 break;
-             default:
-                 break;
-         }
-         c--;
-         p++;
-        }
-     if(volume < 24){
-         set_examp_mute(1);
-     } else {
-         set_examp_mute(0);
-     }
-     akc6955_setvolume(volume);
-//    _HOME();
-    } while(1);
-}
-
-void scan_start(void)
-{
-    unsigned char c;
-    _CLS();
-    _LOCATE(0,0);
-    printstr("Scan F/A/4/6");
-    do {
-        update_status();
-        print_freq(1);
-        c = pollkey_single();
-       // New Scan
-       if(c == charcode_6){
-           scanflag = 0xff;
-           akc6955_do_scan(0xff);
-       } else if(c == charcode_4){
-           scanflag = 0xff;
-           akc6955_do_scan(0);
-       } else if(c == charcode_a){
-           scanflag = 0;
-           akc6955_abort_scan();
-           break;
-       } else if(c == charcode_f){
-           break;
-       } else {
-           if((scanflag != 0) && (akc6955_chk_donescan() != 0)) {
-                scanflag = 0;
-                _LOCATE(0,0);
-                printstr("Scan F/A/4/6");
-                update_status();
-                print_freq(1);
-           }
-       }
-    _HOME();
-    } while(1);
-    _CLS();
-}
-
 void setfreq_direct(void)
 {
-    unsigned int val;
+    unsigned long val;
     _CLS();
-    _LOCATE(0,0);
+//    _LOCATE(0,0);
     printstr("Set Freq:");
-    _LOCATE(0,1);
-    if(fm != 0){
+    _LOCATE_0_1();
+    if(setup.fm != 0){
         // FM
         printstr("FM ");
-        val = fmfreq;
+        val = setup.fmfreq;
         val = read_numeric(val, 5, 7, 1);
-        fmfreq = val;
+        if((val & 0x80000000) != 0) return;
+        setup.fmfreq = val;
     } else {
         // FM
         printstr("AM ");
-        val = amfreq;
+        val = setup.amfreq;
         val = read_numeric(val, 5, 7, 1);
-        amfreq = val;
+        if((val & 0x80000000) != 0) return;
+        setup.amfreq = val;
     }
     akc6955_set_freq(val);
 }
 
 void setband_direct(void)
 {
-    unsigned int band;
-    _CLS();
-    _LOCATE(0,0);
-    if(fm != 0){
-        printstr("Set Band:FM#");
-        band = fmband & 7;
-        fmband = read_numeric(band, 2, 7, 1);
-        akc6955_set_fmband(fmband);
-        akc6955_do_tune();
-    } else {
-        printstr("Set Band:AM#");
-        band = amband & 0x1f;
-        amband = read_numeric(band, 2, 7, 1);
-        akc6955_set_amband(amband);
-        akc6955_do_tune();
-    }
-}
-
-void call_userband(unsigned char num)
-{
+    unsigned long band;
+    unsigned char band2;
     unsigned int freq;
-    unsigned int ch;
-    if(num >= USER_BAND_NUM) return;
-    if(fm != 0){
-        freq = fm_usrbands[num].freq;
-        ch = ((freq - 3000) / 25) * 10;
-        akc6955_set_userband(fm_usrbands[num].start, fm_usrbands[num].stop, ch,
-                            fm_usrbands[num].mode3k);
-        fmband = AKC6955_BAND_AMUSER;
-    } else {
-        unsigned int p = 5;
-        if(am_usrbands[num].mode3k != 0) p = 3;
-        freq = am_usrbands[num].freq;
-        ch = freq / p;
-        akc6955_set_userband(am_usrbands[num].start, am_usrbands[num].stop, ch,
-                            am_usrbands[num].mode3k);
-        amband = AKC6955_BAND_AMUSER;
-    }
-}
-
-void set_userband(void)
-{
-    unsigned int from,to;
-    unsigned char c;
-    unsigned char p;
     unsigned char mode3k;
-    char cc;
 
     _CLS();
-    _LOCATE(0,0);
-    printstr("User ch:");
-    c = pollkey_single();
-
-    if(c > charcode_0) return;
-    if(c < charcode_1) return;
-    if(c == charcode_0) {
-        c = 0;
-    } else {
-        c = c - charcode_1 + 1;
-    }
-    if(c >= USER_BAND_NUM) return;
-    if(fm != 0){
-        from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
-        to = fm_usrbands[c].stop * 80 + 3000;
-        _CLS();
-        _LOCATE(0,0);
-        printstr("FM#");
-        print_numeric_nosupress(c, 1);
-        printstr(" From:");
-        from = read_numeric(from, 5, 7, 1);
-        _LOCATE(6,1);
-        printstr("To:");
-        to = read_numeric(to, 5, 7, 1);
-        fm_usrbands[c].start = (from - 3000) / 80;
-        fm_usrbands[c].stop = (to - 3000) / 80;
-        fm_usrbands[c].freq = from * 80 + 3000;
-        fm_userbandnum = c;
-    } else {
-        mode3k = am_usrbands[c].mode3k;
-        p = 96; // 3*32
-        if(mode3k == 0) p = 160; // 5*32
-        from = am_usrbands[c].start * p;
-        to = am_usrbands[c].stop * p;
-        _CLS();
-        _LOCATE(0,0);
-        printstr("AM#");
-        print_numeric_nosupress(c, 1);
-        printstr(" Step:");
-        _LOCATE(0,1);
-        printstr("0=3k 1=5k");
-        cc = pollkey_single();
-        if(cc == charcode_0){
-            p = 96;
-            mode3k = 0xff;
-        } else if(cc = charcode_1) {
-            p = 160;
-            mode3k = 0;
+//    _LOCATE(0,0);
+    if(setup.fm != 0){
+        printstr("Set Band:FM#");
+        band2 = setup.fmband & 7;
+        if(band2 == AKC6955_BAND_FMUSER) {
+            userband.fm_usrbands[setup.fm_userbandnum].freq = setup.fmfreq;
         }
-        _CLS();
-        _LOCATE(0,0);
-        printstr("AM#");
-        print_numeric_nosupress(c, 1);
-        printstr(" From:");
-        from = read_numeric(from, 5, 7, 1);
-        _LOCATE(6, 1);
-        printstr(" To:");
-        to = read_numeric(to, 5, 7, 1);
-        am_usrbands[c].start = from / p;
-        am_usrbands[c].stop = to  / p;
-        am_usrbands[c].mode3k = mode3k;
-        am_usrbands[c].freq = from * p;
-        am_userbandnum = c;
-    }
-    call_userband(c);
-}
-
-void input_userband(void)
-{
-    unsigned char c;
-    do{
-    _CLS();
-    _LOCATE(0,0);
-    printstr("User Band");
-    _LOCATE(0,1);
-    printstr("   #");
-    c = pollkey_single();
-
-    if((c >= charcode_a) && (c <= charcode_f)){
-        break;
-    }
-    if(c == charcode_0) {
-        _PUTCHAR('0');
-        if(fm != 0){
-           fm_userbandnum = 0;
+        setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
+        band2 = pollkey_numeric(band2);
+        band2 &= 7;
+        if(band2 == AKC6955_BAND_FMUSER) {
+            call_userband(setup.fm_userbandnum);
+            freq = userband.fm_usrbands[setup.fm_userbandnum].freq;
         } else {
-           am_userbandnum = 0;
+            freq = setup.fmfreq_bank[band2];
         }
-        call_userband(0);
+        setup.fmband = band2;
+        akc6955_set_fmband(band2);
+        setup.fmfreq = freq;
     } else {
-        c = c - charcode_1 + 1;
-        if(c < USER_BAND_NUM) {
-            _PUTCHAR(c + '0');
-            if(fm != 0){
-               fm_userbandnum = c;
-            } else {
-                am_userbandnum = c;
-            }
-            call_userband(c);
+        printstr("Set Band:AM#");
+        band = setup.amband & 0x1f;
+        setup.amfreq_bank[band] = setup.amfreq;
+        if(band == AKC6955_BAND_AMUSER) {
+            userband.am_usrbands[setup.am_userbandnum].freq = setup.amfreq;
         }
+        band = read_numeric(band, 2, 7, 1);
+        if((band & 0x80000000) != 0) return;
+        band &= 0x1f;
+        setup.amband = band;
+        freq = setup.amfreq_bank[setup.amband];
+        switch(band) {
+        case AKC6955_BAND_LW:
+        case AKC6955_BAND_MW2:
+          mode3k = 0xff;
+          break;
+         case AKC6955_BAND_AMUSER:
+            call_userband(setup.am_userbandnum);
+            mode3k = userband.am_usrbands[setup.am_userbandnum].mode3k;
+            freq = userband.am_usrbands[setup.am_userbandnum].freq;
+            break;
+        default:
+            mode3k = 0x00;
+          break;
+       }
+        akc6955_mode3k(mode3k);
+        akc6955_set_amband(band);
+        setup.amfreq = freq;
+        setup.am_mode3k = mode3k;
     }
-    idle(ui_idlecount);
-    } while(1);
-    _CLS();
-}
-
-unsigned char printhelp_2lines(char *l1, char *l2)
-{
-    _CLS();
-    _LOCATE(0,0);
-    printstr(l1);
-    _LOCATE(0,1);
-    printstr(l2);
-    _HOME();
-    return pollkey_single();
-}
-
-unsigned char numeric_help(void)
-{
-    unsigned char c;
-    char l;
-    l = 0;
-    do {
-        c = printhelp_2lines(numeric_helpstr[l], numeric_helpstr[l + 1]);
-        if(c == charcode_f) return charcode_f;
-        l += 2;
-    } while(l < 10);
-    return c;
-}
-
-void mainmenu_help(void)
-{
-    unsigned char c;
-    
-    char l;
-    l = 0;
-    do {
-        c = printhelp_2lines(mainmenu_helpstr[l], mainmenu_helpstr[l + 1]);
-        if(c == charcode_f) return;
-        l += 2;
-        if(l >= 18) {
-            c = numeric_help();
-            if(c == charcode_f) return;
-            l = 0;
-        }
-    } while(1);
-}
-
-void updown_help(void)
-{
-    unsigned char c;
-    char l;
-
-    l = 0;
-    do {
-        c = printhelp_2lines(updown_helpstr[l], updown_helpstr[l + 1]);
-        if(c == charcode_f) return;
-        l += 2;
-        if(l >= 20) {
-            c = numeric_help();
-            if(c == charcode_f) return;
-            l = 0;
-        }
-    } while(1);
+    akc6955_do_tune();
+    akc6955_set_freq(freq);
 }
 
 void menu_poweroff(void)
@@ -524,248 +174,119 @@ void menu_poweroff(void)
     }
 }
 
-void setup_akc6955(void)
+void menu_setfmresolution(void)
 {
-//    akc6955_chg_fm(fm); // Set to AM
-#if 0
-/*
- * CR_DEF[18]= {
-            0x4c,  //REG00    //Modify
-            0x10,  //REG01
-            0x4a,  //REG02
-            0xc8,  //REG03
-            0x19,  //REG04
-            0x32,  //REG05
-            0xa1,  //REG06
-            0xa1,  //REG07
-            0x54,  //REG08
-            0xC7,  //REG09
-            0x7f,  //REG10
-            0xe0,  //REG11
-            0x00,  //REG12
-            0x0C,  //REG13
-            0x40,  //REG14
-            0x82,  //REG15        //Modify
-            0xcc,  //REG16
-            0xf9   //REG17
- */
-    akc6955_writecmd(0x00, 0x4c);
-    akc6955_writecmd(0x01, 0b00010000);
-    akc6955_writecmd(0x02, 0b01001010);
-    akc6955_writecmd(0x03, 0xc8);
-    akc6955_writecmd(0x04, 0x19);
-    akc6955_writecmd(0x05, 0x32);
-    akc6955_writecmd(0x06, 0xa1);
-    akc6955_writecmd(0x07, 0b10100001);
-    akc6955_writecmd(0x08, 0b01010000);
-    akc6955_writecmd(0x09, 0b11000111);
-    akc6955_writecmd(0x09, 0b01111111);
-    akc6955_writecmd(0x0b, 0b11100000);
-    akc6955_writecmd(0x0c, 0b00000000);
-    akc6955_writecmd(0x0d, 0b00001100);
-    akc6955_writecmd(0x0e, 0x40);
-    akc6955_writecmd(0x0f, 0x82);
-    akc6955_writecmd(0x10, 0xcc);
-    akc6955_writecmd(0x11, 0xf9);
-
+   unsigned char c;
+    if(setup.fm != 0){
+       _CLS();
+//       _LOCATE(0,0);
+        c = akc6955_get_scanrate_fm();
+        printstr("FM pitch:");
+        _PUTCHAR('0' + c);
+        printstr("->");
+        c = pollkey_numeric(c);
+        setup.fm_tunepitch = c & 3;
+        akc6955_set_scanrate_fm(c);
+        _CLS();
+//        _LOCATE(0,0);
+    }
+}
 
-#else
+void setup_akc6955(void)
+{
     akc6955_writecmd(AKC6955_POWER, 0xc0);  // You musto *not* mute, set b2 to '0".
     akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
-    if(fm == 0) {
-        akc6955_set_amband(amband);
-        if(amband == AKC6955_BAND_AMUSER) call_userband(am_userbandnum);
-        amfreq = amfreq_bank[amband];
-        akc6955_chg_fm(0, amfreq); // Set to AM
-        akc6955_set_freq(amfreq);
+    if(setup.fm == 0) {
+        akc6955_set_amband(setup.amband);
+        if(setup.amband == AKC6955_BAND_AMUSER) call_userband(setup.am_userbandnum);
+        setup.amfreq = setup.amfreq_bank[setup.amband];
+        akc6955_chg_fm(0, setup.amfreq); // Set to AM
+        akc6955_set_freq(setup.amfreq);
     } else {
-        akc6955_set_fmband(fmband);
-        if(fmband == AKC6955_BAND_FMUSER) call_userband(fm_userbandnum);
-        fmfreq = fmfreq_bank[fmband];
-        akc6955_chg_fm(0xff, fmfreq); // Set to AM
-        akc6955_set_freq(fmfreq);
+        akc6955_set_fmband(setup.fmband);
+        if(setup.fmband == AKC6955_BAND_FMUSER) call_userband(setup.fm_userbandnum);
+        setup.fmfreq = setup.fmfreq_bank[setup.fmband];
+        akc6955_chg_fm(0xff, setup.fmfreq); // Set to AM
+        akc6955_set_freq(setup.fmfreq);
     }// Dummy, TBS (954KHz)
     akc6955_set_power(0xff); // Power ON
     akc6955_setvolume(36); // Temporally
-    set_thresh_fmcnr(threshold_fmcnr);
-    set_thresh_amcnr(threshold_amcnr);
-    set_thresh_width(threshold_width);
-    set_thresh_fmstereo(threshold_fmstereo);
+    akc6955_set_thresh_fmcnr(setup.threshold_fmcnr);
+    akc6955_set_thresh_amcnr(setup.threshold_amcnr);
+    akc6955_set_thresh_width(setup.threshold_width);
+    akc6955_set_thresh_fmstereo(setup.threshold_fmstereo);
     akc6955_setvolumemode(0);
-    akc6955_set_lowboost(lowboost);
+    akc6955_set_lowboost(setup.lowboost);
+    akc6955_set_scanrate_fm(setup.fm_tunepitch);
     set_stereomode();
-#endif
-}
-
-void menu_save(void)
-{
-    unsigned char c;
-    c = printhelp_2lines("Save settings", "A=Yes");
-    if(c == charcode_a) {
-        save_eeprom();
-    }
 }
 
-void menu_load(void)
-{
-    unsigned char c;
-    c = printhelp_2lines("Load settings", "A=Yes B=Init");
-    if(c == charcode_a) {
-        c = load_eeprom();
-        if( c != 0xff) {
-            _CLS();
-            _LOCATE(0,0);
-            c = printhelp_2lines("X) Load Error", "A=Fix");
-            setdefault();
-            if(c == charcode_a){
-                save_eeprom();
-            }
-        }
-        setup_akc6955();
-    } else if(c == charcode_b){
-        setdefault();
-        setup_akc6955();
-    }
-}
-
-void setup_help(void)
-{
-    unsigned char c;
-    char l;
-    l = 0;
-    do {
-        c = printhelp_2lines(setup_helpstr[l], setup_helpstr[l + 1]);
-        if(c == charcode_f) return;
-        l += 2;
-        if(l >= 16) {
-            c = numeric_help();
-            if(c == charcode_f) return;
-            l = 0;
-        }
-    } while(1);
-    
-}
-void setup_menu(void)
-{
-    unsigned char c;
-    unsigned int val;
-
-    c = printhelp_2lines("Setup F=HELP", "5=Return");
-    switch(c){
-        case charcode_f:
-            setup_help();
-            break;
-        case charcode_5:
-            break;
-        case charcode_0:
-            menu_poweroff();
-            break;
-        case charcode_c:
-            menu_save();
-            break;
-        case charcode_a:
-            menu_load();
-            break;
-        case charcode_d:
-            setdefault();
-            break;
-        case charcode_e:
-            break;
-        case charcode_1:
-            _CLS();
-            _LOCATE(0,0);
-            printstr("FM-CNR threshold:");
-            val = threshold_fmcnr;
-            val = read_numeric(val, 1, 0, 1);
-            set_thresh_fmcnr((unsigned char)val);
-            break;
-        case charcode_2:
-            _CLS();
-            _LOCATE(0,0);
-            printstr("AM-CNR threshold:");
-            val = threshold_amcnr;
-            val = read_numeric(val, 1, 0, 1);
-            set_thresh_amcnr((unsigned char)val);
-            break;
-        case charcode_3:
-            _CLS();
-            _LOCATE(0,0);
-            printstr("Stereo threshold:");
-            val = threshold_fmstereo;
-            val = read_numeric(val, 1, 0, 1);
-            set_thresh_fmstereo((unsigned char)val);
-            break;
-    }
-}
 /*
  * Main Menu : initial-screen -> 'F'.
  */
 void main_menu(void)
 {
     unsigned char c;
-    unsigned char p;
-    unsigned char n;
+    unsigned char d;
     unsigned int val;
+    unsigned int freq;
 
-    _CLS();
-    _HOME();
-    _LOCATE(0,0);
-    printstr("Menu:F=HELP");
-    _LOCATE(0,1);
-    printstr("B=CANCEL");
-       do {
-           n = pollkeys(pollkeybuf, 60, 1);
-       } while(n == 0);
-       p = 0;
-       c = pollkeybuf[0];
-        if(c == charcode_f){
-            mainmenu_help();
-            // HELP
-        } else if(c == charcode_b){
-            // Cancel
-        } else if(c == charcode_1){
-            
-        } else if(c == charcode_2){
+    printhelp_2lines("Menu:F=HELP", "B=CANCEL");
+    c = pollkey_single(); // 1012ms
+    switch(c) {
+        case charcode_1:
             // Band
             setband_direct();
-        } else if(c == charcode_3){
+            break;
+        case charcode_3:
             // Band
             setfreq_direct();
-        } else if(c == charcode_a){
-            menu_poweroff();
-        } else if(c == charcode_5){
-            scan_start();
+            break;
+        case charcode_4:
+            on_call_userfreq();
+            break;
             // Scan
-        } else if(c == charcode_6){
-            
-        } else if(c == charcode_4){
-
-        } else if(c == charcode_7){
+        case charcode_5:
+            break;
+        case charcode_6:
+            on_set_userfreq();
+            break;
+            // Scan
+        case charcode_7:
+            menu_poweroff();
+            break;
+        case charcode_8:
             // Set volume
             set_volume();
-        } else if(c == charcode_8){
-            // Reserve
-        } else if(c == charcode_9){
-            _CLS();
-            _LOCATE(0,0);
-            printstr("Sig width:");
-            val = threshold_width;
-            val = read_numeric(val, 1, 0, 1);
-            set_thresh_width((unsigned char)val);
-            // Set NF
-        } else if(c == charcode_0){
+            break;
+        case charcode_9:
+            freq = akc6955_get_freq();
+            akc6955_set_freq(freq);
+            break;
+        case charcode_0:
             // Setup Menu
             setup_menu();
-        } else if(c == charcode_d){
-            // Call userband
-            input_userband();
-        } else if(c == charcode_c){
-            // Set userband
-            set_userband();
-        } else if(c == charcode_e){
+            break;
+        case charcode_a:
             toggle_amfm();
+            break;
+        case charcode_c:
+            set_userband();
+            break;
+        case charcode_d:
+            input_userband();
+            break;
+        case charcode_e:
+            menu_setfmresolution();
+            break;
+        case charcode_f:
+            mainmenu_help();
+            // HELP
+            break;
+        default:
+            break;
         }
        _CLS();
-       _LOCATE(0,0);
+       _LOCATE_0_0();
 }