diff --git a/Makefile b/Makefile index 3562c46..4a31882 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ INCLUDES := # options for code generation #--------------------------------------------------------------------------------- -CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) -I$(DEVKITPRO)/SDL/include -U__unix +CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE) -I$(DEVKITPRO)/SDL/include -U__unix -DHAVE_SDL CXXFLAGS = $(CFLAGS) LDFLAGS = -L$(DEVKITPRO)/SDL/lib -g $(MACHDEP) -Wl,-Map,$(notdir $@).map @@ -58,7 +58,7 @@ export DEPSDIR := $(CURDIR)/$(BUILD) #--------------------------------------------------------------------------------- # automatically build a list of object files for our project #--------------------------------------------------------------------------------- -CFILES := +CFILES := menu.c char_to_kc.c CPPFILES := Display.cpp main.cpp Prefs.cpp SID.cpp REU.cpp IEC.cpp 1541fs.cpp \ 1541d64.cpp 1541t64.cpp 1541job.o SAM.cpp C64.cpp CPUC64.cpp VIC.cpp \ CIA.cpp CPU1541.cpp @@ -120,7 +120,7 @@ DEPENDS := $(OFILES:.o=.d) # main targets #--------------------------------------------------------------------------------- $(OUTPUT).dol: $(OUTPUT).elf -$(OUTPUT).elf: $(OFILES) +$(OUTPUT).elf: sysconfig.h $(OFILES) #--------------------------------------------------------------------------------- # This rule links in binary data with the .jpg extension @@ -130,6 +130,11 @@ $(OUTPUT).elf: $(OFILES) @echo $(notdir $<) $(bin2o) +sysconfig.h: sysconfig.h.Wii + cp $< $@ + +Display.cpp: Display_SDL.i + -include $(DEPENDS) #--------------------------------------------------------------------------------- diff --git a/Src/C64.cpp b/Src/C64.cpp index 4bec466..d21c2f2 100644 --- a/Src/C64.cpp +++ b/Src/C64.cpp @@ -712,8 +712,3 @@ bool C64::LoadSnapshot(char *filename) #ifdef __riscos__ #include "C64_Acorn.i" #endif - -#ifdef GEKKO -#include "C64_wii.i" -#endif - diff --git a/Src/C64_SDL.i b/Src/C64_SDL.i index c5e4af2..a092589 100644 --- a/Src/C64_SDL.i +++ b/Src/C64_SDL.i @@ -10,6 +10,9 @@ #include #include +#if defined(GEKKO) +#include +#endif static struct timeval tv_start; static char *main_menu_messages[] = { @@ -39,9 +42,11 @@ static char *bind_key_messages[] = { void C64::c64_ctor1(void) { // Initialize joystick variables +#ifdef HAVE_LINUX_JOYSTICK_H joyfd[0] = joyfd[1] = -1; joy_minx = joy_miny = 32767; joy_maxx = joy_maxy = -32768; +#endif this->base_dir = "."; @@ -358,16 +363,16 @@ uint8 C64::poll_joystick(int port) this->enter_menu(); if ( (held & WPAD_BUTTON_A) && this->joystick_key_binding[0]) TheDisplay->FakeKeyPress(this->joystick_key_binding[0], - shifted, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &joykey); + false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL); if ( (held & WPAD_BUTTON_PLUS) && this->joystick_key_binding[1]) TheDisplay->FakeKeyPress(this->joystick_key_binding[1], - shifted, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &joykey); + false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL); if ( (held & WPAD_BUTTON_MINUS) && this->joystick_key_binding[2]) TheDisplay->FakeKeyPress(this->joystick_key_binding[2], - shifted, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &joykey); + false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL); if ( (held & WPAD_BUTTON_1) && this->joystick_key_binding[1]) TheDisplay->FakeKeyPress(this->joystick_key_binding[1], - shifted, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, &joykey); + false, TheCIA1->KeyMatrix, TheCIA1->RevMatrix, NULL); return j; diff --git a/Src/Display_SDL.i b/Src/Display_SDL.i index 8379ae7..cbf62ea 100644 --- a/Src/Display_SDL.i +++ b/Src/Display_SDL.i @@ -61,7 +61,7 @@ enum { int init_graphics(void) { // Init SDL - if (SDL_Init(SDL_INIT_VIDEO) < 0) { + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) { fprintf(stderr, "Couldn't initialize SDL (%s)\n", SDL_GetError()); return 0; } diff --git a/Src/Prefs.cpp b/Src/Prefs.cpp index b7b55b5..cd960ac 100644 --- a/Src/Prefs.cpp +++ b/Src/Prefs.cpp @@ -134,10 +134,10 @@ bool Prefs::operator==(const Prefs &rhs) const && SystemKeys == rhs.SystemKeys && ShowLEDs == rhs.ShowLEDs #ifdef GEKKO - && this->JoystickKeyBinding[0] == rhs.JoystickKeybinding[0] - && this->JoystickKeyBinding[1] == rhs.JoystickKeybinding[1] - && this->JoystickKeyBinding[2] == rhs.JoystickKeybinding[2] - && this->JoystickKeyBinding[3] == rhs.JoystickKeybinding[3] + && this->JoystickKeyBinding[0] == rhs.JoystickKeyBinding[0] + && this->JoystickKeyBinding[1] == rhs.JoystickKeyBinding[1] + && this->JoystickKeyBinding[2] == rhs.JoystickKeyBinding[2] + && this->JoystickKeyBinding[3] == rhs.JoystickKeyBinding[3] #endif ); } diff --git a/Src/SID_SDL.i b/Src/SID_SDL.i new file mode 100644 index 0000000..5505767 --- /dev/null +++ b/Src/SID_SDL.i @@ -0,0 +1,132 @@ +/* + * SID_linux.i - 6581 emulation, Linux specific stuff + * + * Frodo (C) 1994-1997,2002 Christian Bauer + * Linux sound stuff by Bernd Schmidt + */ + +#include +#include +#include +#include + +#include "VIC.h" + +static int divisor = 0; +static int to_output = 0; +static int buffer_pos = 0; + +void DigitalRenderer::fill_audio(Uint8 *stream, int len) +{ + int cnt = 0; + int bytes_to_write = to_output * sizeof(Uint16); + int buf_size = this->sndbufsize * sizeof(Uint16); + + memset(stream, 0, len); + if (to_output <= 0) + return; + + while (cnt < bytes_to_write && cnt < len) + { + int datalen = buf_size; + + if (datalen > bytes_to_write) + datalen = bytes_to_write; + + if (datalen > len - cnt) + datalen = len - cnt; + + calc_buffer(sound_buffer, datalen); + memcpy(stream + cnt, (Uint8*)this->sound_buffer, datalen); + cnt += datalen; + } + if (to_output - cnt / 2 <= 0) + to_output = 0; + else + to_output -= cnt / 2; +} + +void DigitalRenderer::fill_audio_helper(void *udata, Uint8 *stream, int len) +{ + DigitalRenderer *p_this = (DigitalRenderer *)udata; + + p_this->fill_audio(stream, len); +} + +/* + * Initialization + */ + +void DigitalRenderer::init_sound(void) +{ + this->sndbufsize = 512; + + /* Set the audio format */ + this->spec.freq = 44100; + this->spec.format = AUDIO_S16LSB; + this->spec.channels = 1; /* 1 = mono, 2 = stereo */ + this->spec.samples = 512; + this->spec.callback = this->fill_audio_helper; + this->spec.userdata = (void*)this; + + ready = false; + if ( SDL_OpenAudio(&this->spec, NULL) < 0 ) { + fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError()); + return ; + } + + this->sound_buffer = new int16[this->sndbufsize]; + ready = true; + SDL_PauseAudio(0); +} + + +/* + * Destructor + */ + +DigitalRenderer::~DigitalRenderer() +{ + SDL_CloseAudio(); +} + + +/* + * Pause sound output + */ + +void DigitalRenderer::Pause(void) +{ + SDL_PauseAudio(1); +} + + +/* + * Resume sound output + */ + +void DigitalRenderer::Resume(void) +{ + SDL_PauseAudio(0); +} + + +/* + * Fill buffer, sample volume (for sampled voice) + */ + +void DigitalRenderer::EmulateLine(void) +{ + if (!ready) + return; + + sample_buf[sample_in_ptr] = volume; + sample_in_ptr = (sample_in_ptr + 1) % SAMPLE_BUF_SIZE; + + /* + * Now see how many samples have to be added for this line + */ + divisor += SAMPLE_FREQ; + while (divisor >= 0) + divisor -= TOTAL_RASTERS*SCREEN_FREQ, to_output++; +} diff --git a/Src/sysconfig.h.Wii b/Src/sysconfig.h.Wii index 2bb8dfa..ad5f23e 100644 --- a/Src/sysconfig.h.Wii +++ b/Src/sysconfig.h.Wii @@ -95,7 +95,7 @@ #define HAVE_FCNTL_H 1 /* Define if you have the header file. */ -/* #undef HAVE_LINUX_JOYSTICK_H */ +#undef HAVE_LINUX_JOYSTICK_H /* Define if you have the header file. */ /* #undef HAVE_NCURSES_H */