3 * Menu sub-routines: Memory Freq.
4 * Copyright (C) 2013-08-14 K.Ohta <whatisthis.sowhat ai gmail.com>
7 * This program 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 2,
10 * or (at your option) any later version.
11 * This library / program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this library; see the file COPYING. If not, write to the
18 * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 * As a special exception, if you link this(includeed from sdcc) library
22 * with other files, some of which are compiled with SDCC,
23 * to produce an executable, this library does not by itself cause
24 * the resulting executable to be covered by the GNU General Public License.
25 * This exception does not however invalidate any other reasons why
26 * the executable file might be covered by the GNU General Public License.
31 #include "commondef.h"
33 #include "backlight.h"
35 void call_freqbank(unsigned int num)
39 unsigned char _userband;
40 unsigned int bank = num / USER_MEMORY_NUM;
41 unsigned int n = num % USER_MEMORY_NUM;
43 if(num >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) return;
45 if(bank != setup.pagenum){ // Swap memory
46 // save_frequencies();
47 load_frequencies(bank, 0x00);
50 _fm = freqset.memoryfreqs[n].fm;
51 _userband = freqset.memoryfreqs[n].band;
52 _band = _userband & 0x1f;
53 _userband = _userband >> 5;
56 setup.fm_userbandnum = _userband;
59 setup.am_userbandnum = _userband;
61 setup.memorynum = num;
62 akc6955_chg_fm(_fm, freqset.memoryfreqs[n].freq);
66 void set_freqbank(unsigned int num)
70 unsigned char _userband;
72 unsigned int bank = num / USER_MEMORY_NUM;
73 unsigned int n = num % USER_MEMORY_NUM;
75 if(num >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) return;
77 if(bank != setup.pagenum){ // Save now bank, and load using bank
79 load_frequencies(bank, 0x00);
84 _userband = setup.am_userbandnum;
87 _userband = setup.fm_userbandnum;
91 freqset.memoryfreqs[n].fm = _fm;
92 freqset.memoryfreqs[n].band = (_userband << 5) | (_band & 0x1f);
93 freqset.memoryfreqs[n].freq = _freq;
99 void on_call_userfreq(void)
101 unsigned long val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
104 printstr("Mem: 000-");
105 print_numeric_nosupress(val - 1, 3);
106 val = read_numeric(val, 3, 4, 1);
107 if(val >= 0x80000000) return;
111 void on_set_userfreq(void)
113 unsigned long val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
118 printstr("Set Mem: 000-");
119 print_numeric_nosupress(val - 1, 3);
120 val = read_numeric(val, 3, 4, 1);
121 if(val >= 0x80000000) return;
124 printstr("OK? A=OK ");
125 c = pollkey_single();
126 if(c != charcode_a) return;
131 void on_updown_userfreq(void)
136 unsigned char _userband;
138 unsigned char dispf = 0xff;
141 _freq = setup.amfreq;
142 _userband = setup.am_userbandnum;
143 _band = setup.amband;
145 _userband = setup.fm_userbandnum;
146 _band = setup.fmband;
147 _freq = setup.fmfreq;
155 print_numeric_nosupress(setup.memorynum, 3);
161 c = pollkey_single_timeout(41, 1); // 23*41 = 943ms
163 dispf = backlight_dec(dispf);
166 case charcode_7: // UP 1CH
168 if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) setup.memorynum = 0;
169 call_freqbank(setup.memorynum);
171 case charcode_1: // Down 1CH
172 if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM * USER_MEMORY_BANKS;
174 call_freqbank(setup.memorynum);
176 case charcode_9: // Up CH FAST
177 setup.memorynum += 100;
178 if(setup.memorynum > (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
179 setup.memorynum = setup.memorynum % 100;
181 call_freqbank(setup.memorynum);
183 case charcode_3: // Down CH FAST
184 if(setup.memorynum < 100) {
185 setup.memorynum = (((USER_MEMORY_NUM * USER_MEMORY_BANKS) / 100 - 1) * 100) + (setup.memorynum % 100);
187 setup.memorynum -= 100;
189 call_freqbank(setup.memorynum);
191 case charcode_8: // Up CH MID
192 setup.memorynum += USER_MEMORY_NUM;
193 if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
194 setup.memorynum = setup.memorynum - USER_MEMORY_NUM * USER_MEMORY_BANKS;
196 call_freqbank(setup.memorynum);
198 case charcode_2: // Down CH MID
199 if(setup.memorynum < USER_MEMORY_NUM) {
200 setup.memorynum = (USER_MEMORY_NUM * USER_MEMORY_BANKS) - USER_MEMORY_NUM + setup.memorynum;
202 setup.memorynum -= USER_MEMORY_NUM;
204 call_freqbank(setup.memorynum);
206 case charcode_5: // Recall
207 call_freqbank(setup.memorynum);
209 case charcode_d: // Reset
211 setup.fmband = _band;
212 setup.fm_userbandnum = _userband;
213 setup.fmfreq = _freq;
215 setup.amband = _band;
216 setup.am_userbandnum = _userband;
217 setup.amfreq = _freq;
219 akc6955_chg_fm(_fm, _freq);
234 case charcode_e: // Set Light
238 idle_time_ms(9); // Pad 9ms, 1Loop = 1000ms.