From afd7421a4c705cb928a5ecb0416d9f2f9c42c7b5 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Fri, 2 Jul 2004 07:43:49 +0000 Subject: Added FM radio simulation, with a good station at 99.4MHz git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4823 a1c6a512-1295-4272-9138-f99709370657 --- apps/recorder/radio.c | 18 +++++++++++--- uisimulator/common/fmradio.c | 58 ++++++++++++++++++++++++++++++++++++++++++++ uisimulator/win32/Makefile | 15 +++++++++--- uisimulator/x11/Makefile | 12 +++++++-- 4 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 uisimulator/common/fmradio.c diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index d6a0b82cc9..f75387739a 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c @@ -130,7 +130,7 @@ bool radio_screen(void) bool stereo = false; int search_dir = 0; int fw, fh; - int last_stereo_status = false; + bool last_stereo_status = false; int top_of_screen = 0; bool update_screen = true; int timeout = current_tick + HZ/10; @@ -155,6 +155,7 @@ bool radio_screen(void) radio_load_presets(); +#ifndef SIMULATOR if(rec_create_directory() > 0) have_recorded = true; @@ -189,6 +190,7 @@ bool radio_screen(void) mpeg_set_recording_gain(mpeg_sound_default(SOUND_LEFT_GAIN), mpeg_sound_default(SOUND_RIGHT_GAIN), false); +#endif fmradio_set(2, 0x140884); /* 5kHz, 7.2MHz crystal */ radio_set_frequency(curr_freq); @@ -236,11 +238,13 @@ bool radio_screen(void) switch(button) { case BUTTON_OFF: +#ifndef SIMULATOR if(mpeg_status() == MPEG_STATUS_RECORD) { mpeg_stop(); } else +#endif { radio_stop(); done = true; @@ -249,6 +253,7 @@ bool radio_screen(void) break; case BUTTON_F3: +#ifndef SIMULATOR if(mpeg_status() == MPEG_STATUS_RECORD) { mpeg_new_file(rec_create_filename(buf)); @@ -261,6 +266,7 @@ bool radio_screen(void) mpeg_record(rec_create_filename(buf)); update_screen = true; } +#endif last_seconds = 0; break; @@ -395,7 +401,9 @@ bool radio_screen(void) } } +#ifndef SIMULATOR seconds = mpeg_recorded_time() / HZ; +#endif if(update_screen || seconds > last_seconds) { @@ -455,7 +463,7 @@ bool radio_screen(void) } } - +#ifndef SIMULATOR if(mpeg_status() & MPEG_STATUS_ERROR) { splash(0, true, str(LANG_DISK_FULL)); @@ -491,6 +499,7 @@ bool radio_screen(void) mpeg_sound_default(SOUND_RIGHT_GAIN), false); mas_codec_writereg(6, 0x4000); } +#endif return have_recorded; } @@ -696,6 +705,7 @@ bool radio_delete_preset(void) return reload_dir; } +#ifndef SIMULATOR static bool fm_recording_settings(void) { bool ret; @@ -715,14 +725,16 @@ static bool fm_recording_settings(void) } return ret; } - +#endif bool radio_menu(void) { struct menu_item radio_menu_items[] = { { STR(LANG_FM_SAVE_PRESET), radio_add_preset }, { STR(LANG_FM_DELETE_PRESET), radio_delete_preset }, { STR(LANG_SOUND_SETTINGS), sound_menu }, +#ifndef SIMULATOR { STR(LANG_RECORDING_SETTINGS), fm_recording_settings } +#endif }; int m; bool result; diff --git a/uisimulator/common/fmradio.c b/uisimulator/common/fmradio.c new file mode 100644 index 0000000000..280a963f5a --- /dev/null +++ b/uisimulator/common/fmradio.c @@ -0,0 +1,58 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2002 by Linus Nielsen Feltzing + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "debug.h" + +#ifdef HAVE_FMRADIO + +static int fmstatus = 0; + +static int fmradio_reg[3]; + +int fmradio_read(int addr) +{ + if(addr == 0) + return fmradio_reg[2]; /* To please the hardware detection */ + else + { + if(addr == 3) + { + /* Fake a good radio station at 99.4MHz */ + if(((fmradio_reg[1] >> 3) & 0xffff) == 11010) + return 0x100000 | 85600; + } + } + return 0; +} + +void fmradio_set(int addr, int data) +{ + fmradio_reg[addr] = data; +} + +void fmradio_set_status(int status) +{ + fmstatus = status; +} + +int fmradio_get_status(void) +{ + return fmstatus; +} + +#endif diff --git a/uisimulator/win32/Makefile b/uisimulator/win32/Makefile index 59949b951c..f9c363e17b 100644 --- a/uisimulator/win32/Makefile +++ b/uisimulator/win32/Makefile @@ -27,6 +27,8 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP) MACHINEDIR = $(RECDIR) # not very nice to set RTC like this, but... RTC += -DHAVE_RTC + # not very nice to set RADIO like this, but... + RADIO += -DHAVE_FMRADIO else MACHINEDIR = $(PLAYDIR) endif @@ -53,7 +55,8 @@ LANGUAGE = english TARGET = $(OBJDIR)/uisw32.exe DEFINES = -DHAVE_CONFIG_H -DGETTIMEOFDAY_TWO_ARGS -DSIMULATOR \ -$(KEYPAD) $(DISPLAY) -DAPPSVERSION=\"$(VERSION)\" $(EXTRA_DEFINES) $(RTC) +$(KEYPAD) $(DISPLAY) -DAPPSVERSION=\"$(VERSION)\" $(EXTRA_DEFINES) \ +$(RTC) $(RADIO) LDFLAGS = -lgdi32 -luser32 @@ -110,12 +113,12 @@ APPS = main.c tree.c menu.c credits.c main_menu.c icons.c language.c \ MENUS = settings_menu.c sound_menu.c playlist_menu.c ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP) - APPS += bmp.c widgets.c + APPS += bmp.c widgets.c radio.c endif SRCS = button.c lcd-win32.c panic-win32.c thread-win32.c \ debug-win32.c kernel.c string-win32.c uisw32.c stubs.c \ - $(APPS) $(MENUS) $(FIRMSRCS) $(COMMONSRCS) sim_icons.c + $(APPS) $(MENUS) $(FIRMSRCS) $(COMMONSRCS) sim_icons.c fmradio.c OBJS := $(OBJDIR)/lang.o $(SRCS:%.c=$(OBJDIR)/%.o) $(OBJDIR)/uisw32-res.o @@ -315,9 +318,15 @@ $(OBJDIR)/io.o: $(SIMCOMMON)/io.c $(OBJDIR)/lcd-playersim.o: $(SIMCOMMON)/lcd-playersim.c $(CC) $(CFLAGS) -c $< -o $@ +$(OBJDIR)/fmradio.o: $(SIMCOMMON)/fmradio.c + $(CC) $(CFLAGS) -c $< -o $@ + $(OBJDIR)/lcd-player.o: $(DRIVERS)/lcd-player.c $(CC) $(CFLAGS) -c $< -o $@ +$(OBJDIR)/radio.o: $(RECDIR)/radio.c + $(CC) $(APPCFLAGS) -c $< -o $@ + # these ones are simulator-specific $(OBJDIR)/%.o: %.c diff --git a/uisimulator/x11/Makefile b/uisimulator/x11/Makefile index 38983eac47..6283989776 100644 --- a/uisimulator/x11/Makefile +++ b/uisimulator/x11/Makefile @@ -26,6 +26,8 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP) MACHINEDIR = $(RECDIR) # not very nice to set RTC like this, but... RTC += -DHAVE_RTC + # not very nice to set RADIO like this, but... + RADIO += -DHAVE_FMRADIO else MACHINEDIR = $(PLAYDIR) endif @@ -110,12 +112,12 @@ APPS = main.c tree.c menu.c credits.c main_menu.c language.c\ MENUS = settings_menu.c sound_menu.c playlist_menu.c ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP) - APPS += bmp.c widgets.c + APPS += bmp.c widgets.c radio.c endif SRCS = screenhack.c uibasic.c resources.c visual.c lcd-x11.c stubs.c \ button-x11.c thread.c sim_icons.c $(APPS) $(MENUS) $(FIRMSRCS) \ - $(COMMONSRCS) lcd-common.c + $(COMMONSRCS) lcd-common.c fmradio.c ROCKSRC := $(wildcard $(APPDIR)/plugins/*.c) ROCKS := $(ROCKSRC:$(APPDIR)/plugins/%.c=$(OBJDIR)/%.rock) @@ -307,12 +309,18 @@ $(OBJDIR)/lcd-player-charset.o: $(DRIVERS)/lcd-player-charset.c $(OBJDIR)/lcd-playersim.o: $(SIMCOMMON)/lcd-playersim.c $(CC) $(CFLAGS) -c $< -o $@ +$(OBJDIR)/fmradio.o: $(SIMCOMMON)/fmradio.c + $(CC) $(CFLAGS) -c $< -o $@ + $(OBJDIR)/font-player.o: $(SIMCOMMON)/font-player.c $(CC) $(CFLAGS) -c $< -o $@ $(OBJDIR)/lcd-player.o: $(DRIVERS)/lcd-player.c $(CC) $(CFLAGS) -c $< -o $@ +$(OBJDIR)/radio.o: $(RECDIR)/radio.c + $(CC) $(APPCFLAGS) -c $< -o $@ + # these ones are simulator-specific $(OBJDIR)/%.o: %.c -- cgit v1.2.3