diff --git a/desmume/AUTHORS b/AUTHORS similarity index 100% rename from desmume/AUTHORS rename to AUTHORS diff --git a/desmume/COPYING b/COPYING similarity index 100% rename from desmume/COPYING rename to COPYING diff --git a/desmume/ChangeLog b/ChangeLog similarity index 97% rename from desmume/ChangeLog rename to ChangeLog index 074edc2cd..6b2f8c5e3 100644 --- a/desmume/ChangeLog +++ b/ChangeLog @@ -1,367 +1,355 @@ -0.9.2 -> 0.9.3 -General/Core: - bug: fixed 64 bit issues and misc integer types usage cleanup [ldesnogues, rm] - enh: added Action Replay code parser [CrazyMax] -Gtk frontend: - enh: switch all of menu/toolbar system to GtkAction + GtkUIManager [matusz] - enh: remove the gtglext 3d code [rm] - enh: fix screen resize in gtk frontend, just resize the window [matusz] - -Windows: - bug: fixed many bugs in Cheats [CrazyMax] - -0.9.1 -> 0.9.2 -General/Core: - bug: fix error in SBCS/RSCS flags; fixes many odd behaviors and crashes [zeromus] - bug: add support for sleep mode and power registers [luigi__] - bug: important fixes to RTC so correct time is actually told [luigi__] - bug: fix card reads below 0x8000; fixes some game freezes [normatt] - bug: fix 4 mbit save type; fix non-autodetect savefile dumping [zeromus, matusz] - enh: add sram to GBA game addon emulation for importing savefiles [zeromus] - enh: many improvements and feature hookups in linux ports [matusz, luigi__] - -Graphics: - bug: fix specular texture mapping mode [luigi__] - bug: repairs to some capture modes and vram mapping [zeromus, CrazyMax] - bug: viewports finally correctly handled [zeromus] - enh: add software rasterizer. quirky, but on par with opengl [zeromus] - -Windows: - bug: mitigate bad frameskipper; default to old frameskipping mode [zeromus] - bug: fixes with recent roms and zipfile loading [zeromus] - bug: fix window position memory [zeromus] - enh: bios and firmware may now be used and booted [luigi__] - enh: many display, OSD, and input enhancements [luigi__] - enh: brand new hotkey and controls binding system [zeromus] - enh: configurable screen separation [luigi__] - enh: fast forward key [pa__] - enh: improvements to mic [luigi__] - enh: faster updates in debug tools, up to once per frame [pa__] - -Mac OS X Port: - enh: added Italian translation thanks to Paolo Bernini [jeff] - enh: resurrection of GDB stub [sigmaris] - -0.9 -> 0.9.1 -General/Core: - enh: GBA slot emulation [CrazyMax] - - Rumble support (windows only) - - GBA game - enh: Mic support (windows only?) [luigi__] - enh: Preliminary cheats system [CrazyMax] - enh: Savestates invalidated, as more variables have been added. - bug: Added PSG white noise [luigi__] - bug: fix arm/thumb ROR [zeromus] - bug: [ 2550645 ] Super Princess Peach: crash when starting a puzzle [zeromus] - bug: win32: fix spu wav file writer (regression from 0.8) [zeromus,luigi__] - bug: Much work on FIFOs, still not finished [CrazyMax] - bug: Many fixes to dma [zeromus, CrazyMax] - bug: bios WaitForVblank and WaitForInterrupt fixed [luigi__] - -Graphics: - bug: Added sprite blending [luigi__] - bug: more correct mosaic effects, still imperfect [zeromus] - bug: Many fixes to tile rendering; all graphics tests now pass [luigi__] - bug: fix crashes in some affine BG [zeromus] - bug: Implement some pos test function [luigi__] - bug: fix texture mapping across texture and palette banks and to unmapped banks [zeromus] - bug: fix texture handling for texels with MSB set (fixes some texture corruption) [zeromus] - bug: fix texture coordinate generation, including environment mapping [zeromus] - bug: texture cache invalidates when palettes change, prevents some texture corruption [zeromus] - bug: fix display capturing from 2d+3d source when display mode is display-vram [zeromus] - bug: [ 2488334 ].1 fixes to layer compositing [luigi__] - bug: [ 2488334 ].3 fix bug in support for hdma affine bg parameters [zeromus] - bug: Improvements to 3d h-scrolling [luigi__] - bug: Fix some errors in rendering 512 tall BG [zeromus,CrazyMax] (still not fully resolved) - bug: Add optional fragment shading pipeline (more precision) [luigi__] - bug: Fix bug where some sprites got cut of on x=255 [zeromus] - bug: Implement GXSTAT register [CrazyMax] - -Windows: - bug: resizing and rotating work in vista [luigi__] - enh: 0 frameskip now lets emulator run at excess speed [zeromus] - -Mac OS X Port: - bug: left key setting no longer gets confused with the right key [jeff] - enh: more keys can be mapped - -0.8 -> 0.9 - There have been so many changes that this list can hardly be considered complete. - For this release, we have formatted the list into a high level overview of big changes and bad bugs relative to the previous release. Hopefully what you're interested in. - This list does not include items which are solely performance boosts, for let us just say that virtually every system has been speeded up. - - * The savestate system is totally changed and incompatible with old savestates. - * The 3d system should be considered rewritten. - -General/Core: - enh: Convert to c++ - enh: Add functions for a lid open/close. Holding key (default "Backspace" in Windows port) while game is freeze/non freeze. [CrazyMax] - enh: Add secure area decryption from ndstool [zeromus] - enh: Change savestate code to support loosely bound chunks and more easily other parts of the emu (GE, GPU). - The savestate format is changed, but from now on it is in principle more resilient - (though it will continue to break as we tinker with the internals) [zeromus] - enh: Added SSE2 optimizations for matrices. Since we now make an SSE2 build, more optimizations can be made. [CrazyMax] - enh: Add a preliminary GUI hud system [CrazyMax,zeromus] - -CPU/MMU: - bug: Many fixes in IPC and GE FIFOs. Fixes freezes in NSMB, dsracing, and others. [CrazyMax,luigi__,shash] - bug: Fix ARM instructions SBC and RSC (likewise SBC in thumb) [normatt] - bug: Fixed Thumb LDMIA (fixes ingame Dead'n'Furious) [shash] - bug: Fix repeating DMA (fixes NSMB parallax BG) [zeromus] - bug: Proper handling for unaligned CPU accesses [luigi__] - bug: Proper handling for undefined instruction exceptions [Salva Peiró] - bug: correctly return vram control register values (fixes homebrew 3d games) [zeromus] - enh: Remove 16MB of WRAM at 0x01****** from arm9. Mapped to unused instead. Nobody knows what this was. [zeromus] - enh: Changed instruction execution to 16 at a time blocks (tested and stable) [shash] - -Hardware: - bug: Newer and better sqrt and div emulation; makes SM64DS playable [luigi__,shash,zeromus] - bug: Add preliminary RTC implementations [CrazyMax] - enh: Add cosine interpolation in the SPU (conditionally compiled) [zeromus,luigi__] - enh: Experimental: always one silent non-mixing SPU core at 44.1khz synched with emu, for more precision. - The audible core runs with the host, causing music to slow down but not tear or pitch bend. [zeromus] - -Graphics: - - Overhaul 3d: - . Move entire GE to core emu. - . Move OpenGL renderer to emu core for optional use by platforms, removing ogl_collector. Now every platform shares the same 3d code. - . Reorganize 3d code to defer rendering to after 3d vblank. Eliminates tearing, and texturing artifacts. [zeromus] - . Add optional fragment shading pipeline (more precision) [luigi__] - . Move lighting model to software instead of using opengl's fixed function model [zeromus] - . Render shadow volumes; toon shading and highlight table [zeromus, luigi__] - . Added texture caching! big speed up. [CrazyMax] - - bug: Many assorted tweaks and improvements to 3d and 2d precision [zeromus,CrazyMax,luigi__] - bug: Fixes to GE: command unpacking, projection and pos-vector mode matrix handling, mult and load commands [zeromus] - bug: Fix a bug in texture transformation mode 1 [zeromus] - bug: Fixed GPU rendering bugs in sprites and BG [CrazyMax] - bug: Fixes to texture conversion [CrazyMax,zeromus] - bug: Fixes in capture display (no blinking in many games with dual 3D) [CrazyMax] - bug: Fixes in master brightness (this fixes some games with black screens) [CrazyMax] - bug: Fixes in screen, backdrop, and sprite blending [luigi__] - bug: Changed clear depths and how depth initial values are calculated (fixes SM64DS skybox, Castlevania) [shash,lugi__] - bug: Add 3d layer h-scrolling [zeromus] - bug: Added transparency and fixed material alpha support and alpha testing on the 3D core [shash] - bug: Rewrite VRAM mapping control and rendering (more accurate) [CrazyMax,luigi__] - - bug: convert colors to opengl better to prevent alpha=31 polys from being ever so slightly transparent [zeromus] - enh: Add MMU->GPU signal for when vram mappings change to function as a texture cache invalidate signal [zeromus] - enh: Make matrix 4x4 multiply routines use W-coordinate; carry w coord through pipeline [zeromus] - -Mac OS X port: - bug: Fixed: Filenames and paths with unicode characters now work. [Jeff] - bug: Fixed: Load state from file button works again. [Jeff] - enh: Save State panel now pauses emulation while the file selection box is open. [Jeff] - bug: Fixed: Frozen video output (and/or messed 3d emulation) after loading a state. [Jeff] - bug: Added option to load the most recent file upon launching the program. [Jeff] - enh: Added French translation (thanks to Pierre Rudloff). [Jeff] - enh: Added basic key mapping configuration to application preferences (thanks to Julio GorgŽ). [Jeff] - enh: Added keyboard shortcuts for Execute, Pause and Reset command (thanks to Julio GorgŽ). [Jeff] - enh: Default key mappings are no longer case sensitive. [Jeff] - enh: Added ability to limit speed. [Jeff] - enh: Fixed: Video output should work on software-only 3D renderers. [Jeff] - -Windows port: - bug: Fix a race condition in NDS_3D_Reset and NDS_glInit [zeromus] - bug: Fix the buggy auto frameskip logic which made the emu slow to a crawl. Now it runs fast! [zeromus] - bug: Fix resizing, rotate & aspect ration of main window. [CrazyMax,_zeromus] - bug: Remove multithreading from user interface after finding several synchronization issues [zeromus] - enh: recent roms menu [luigi_] - enh: Changed graphics render core to DirectDraw (work faster) [CrazyMax] - enh: Add an arm9 cpu load average calculator similar to no$. but I dont think it works right. [zeromus] - enh: Rewrite all debug tools (autoupdate works now) [CrazyMax] - enh: Rewrite input core & replace config input dialog [CrazyMax] - enh: Add AVI output [zeromus] - enh: Add pause toggle and frame advance hotkeys [adelikat] - enh: Add frame counter display and hud messages framework [adelikat] - enh: Main window remembers position, size, and a few other emu preferences [adelikat] - enh: Removed directx sdk dependency for easier building. [zeromus] - enh: Savestate doesnt unpause emu if it is already paused [adelikat] - -0.7.3 -> 0.8 - Cocoa: - - Save State As function now works. [Jeff B] - - Recent Items menu now works. [Jeff B] - - Opening NDS files from Finder now works. [Jeff B] - - Added screenshot feature. [Jeff B] - - Added preferences. [Jeff B] - - Many more strings are translatable now. [Jeff B] - - Default screen color is black (better represents being "off" and easier on eyes at night). [Jeff B] - - Added sound. [Jeff B] - - Now is a universal binary. [Jeff B] - - Leopard resolution icon added. [Jeff B] - - Added a Japanese translation. [Jeff B] - - Added an optional status bar (resize handle no longer overlaps screen). [Jeff B] - - New ROM Info and About DeSmuME windows have been added. [Jeff B] - - Fixed several bugs in window resizing. [Jeff B] - - Added FAT image support for homebrew games (thanks to TypeError). [Jeff B] - - Key config can be changed on the command line. Save/load hotkeys changed (so expose doesn't override). [Jeff B] - - Key bindings may work better on non-US keyboards now (needs testing). [Jeff B] - general: - - Encapsulate GDB debug stub to avoid certain problems [shash] - - Fixed CPU LD*/ST* bugs [shash] - - Fixed New SMB mini-games freeze [shash] - - Fixed possible segfault in ROMReader on ia64 and amd64. [evilynux] - - Fixed a crash bug with 2D background corrupting memory [shash] - - Flag check optimization [carlo_bramini] - - Applied some endian fixes in GPU (thanks to Phazz) [Jeff B] - gtk-glade: - - Added DeSmuME version in about dialog. [evilynux] - - Updated website url in about dialog. [evilynux] - - Added Brazilian Portuguese translation by Dreampeppers99. [evilynux] - - Better desktop menu entry following FreeDesktop specifications. [evilynux] - gtk: - - Updated website url in about dialog. [evilynux] - - Better desktop menu entry following FreeDesktop specifications. [evilynux] - windows port: - - Added an "about" box [shash] - - DirectInput control interface with joystick support [CrazyMax] - - Matrix and Light viewer [Acid Burn] - -0.7.2 -> 0.7.3 - gtk-glade: - - Full localization using intltool/gettext. [evilynux] - general: - - Added a README.TRANSLATION documenting the localization process. [evilynux] - MacOS X: - - Initial version of the Mac interface added. [Jeff B] - -0.7.1 -> 0.7.2 - spu: - - big endian fixes. [cyberwarriorx] - gpu: - - big endian fixes. [marcus_c] - gtk-glade: - - opengl improvements. [masscat] - general: - - Added support for setting NDS firmware language value. [masscat] - - Function added for setting firmware language. [masscat] - - Mac/msys compilation fixes. [cyberwarriorx] - - Fix compilation when pkg-config macros are not available [evilynux] - -0.7.0 -> 0.7.1 - general: - - Added GDB debugger stub [masscat] - - Added new/different GBAMP CFlash image reader/writer [masscat] - gpu: - - Major speedup to the 2D core [shash] - gtk-glade: - - Added command line options. [masscat] - - Added FPS limiter [masscat] - cli: - - Added command line options. [masscat] - - Added FPS limiter [masscat] - - Added option to use OpenGl to render window (allows resizing). [masscat] - windows port: - - Added command line options. [masscat] - - Added multiple language support [cyberwarriorx] - - Added Danish language translation [thomas-2007] - -0.6.0 -> 0.7.0 - general: - - Added support for *.duc files [cyberwarriorx] - gpu: - - Added support for sprite rotation/scaling [shash] - - Added support for the 3D core (openGL and null plugins) [shash] - windows port: - - A bunch of fixes [Dmitry Krutskih] - - Fixed a bug in sound that was causing it to still not work for some - people [cyberwarriorx] - gtk: - - Added 3D emulation - - Added command line options. - - Added option to use OpenGL to render window (allows resizing). - gtk-glade: - - Added 3D emulation - -0.5.0 -> 0.6.0 - general: - - Added zipped (based on zziplib) and gzipped (based on zlib) rom support. - arm: - - Added relocation interrupt vector. - - Added region access right checks. - - Enabled LDC/STC instructions. - - Fixed powersave (cp15) IRQ wait. - - Fixed MOV instructions - gpu: - - Added special color effects. - - Added windowing feature. - - Fixed transparent direct color backgrounds. - - Fixed disabled sprites showing. - - Fixed 8/32 bit access to gpu registers. - - Fixed missing backgrounds - - Support for master brightness - wifi: - - Added RF chip interface. - - Added BB chip interface. - windows port: - - Fixed address calculation in disassembler. - - Added Force Maintain Ratio option for window stretching - linux port (cli, gtk and gtk-glade): - all: - - Added joystick support. - - Fixed X and Y buttons. - gtk-glade: - - Added joystick configuration. - - Improved I/O registers viewer tool. - - Added save and load states support. - -0.3.3 -> 0.5.0 - arm: - - Fixed MSR with immediate value opcode. - - Fixed LSR_0 thumb opcode (C flag is correctly set now). - - Fixed LDR*/STR* opcodes. - - Fixed unaligned memory access on THUMB Core. - - Added relocating SWI routines. - bios: - - Added decompression functions. - - Added GetPitchTable function. - - Added GetVolumeTable function. - - Added GetCRC16 function. - - Added experimental SoundBias function. - - Added GetSineTable function. - cart: - - Added CompactFlash/FAT emulation. - - Added Get ROM chip ID Cartridge command. - gpu: - - Added framebuffer emulation. - - Fixed a bug in GPU (xfin could be greater than LG causing a segfault). - - Added support for Display Mode 0(Display Off). - - Added the basic framework for Display Mode 3(Display from Main RAM). - spu: - - Added sound emulation. - - Added sound core system. - - Added WAV write core. - - Added dummy core. - - Added Direct Sound core. - linux port: - - Added GTK+ GUI. - - Added command line interface. - - Added stylus and arm9 keypad support in CLI version. - - Added FPS display. - - Added basic frameskip. - windows port: - - Fixed a bug when displaying a ROM's information. - - Added key configuration. - - Removed the debug key. - - Added new experimental auto frameskip/frame limit code. - - Added sound settings dialog. - - Added a few menu options for accessing the website, forums, and for - submitting bugs. - general: - - Rewrote code in C. - - Fixed warnings. - - Used defines and typedef's to make things more portable and easier to - read. - - Added autotools stuff. - - Changes to logging system. - - Added screenshot function. - - Translated most french to english. - - Added savestate support. - - Added firmware reading support(needs work). - - Added Backup Memory support with autodetection. - - Fixed some endianess issues. - - Fixed things so Visual C++ can compile code. - - Added bsd support. - - Reworked ROM loading so you can load a different rom without any problems. - - Finished NDS_Reset. Now the emulation can be reset even while running. +0.9.1 -> 0.9.2 +General/Core: + bug: fix error in SBCS/RSCS flags; fixes many odd behaviors and crashes [zeromus] + bug: add support for sleep mode and power registers [luigi__] + bug: important fixes to RTC so correct time is actually told [luigi__] + bug: fix card reads below 0x8000; fixes some game freezes [normatt] + bug: fix 4 mbit save type; fix non-autodetect savefile dumping [zeromus, matusz] + enh: add sram to GBA game addon emulation for importing savefiles [zeromus] + enh: many improvements and feature hookups in linux ports [matusz, luigi__] + +Graphics: + bug: fix specular texture mapping mode [luigi__] + bug: repairs to some capture modes and vram mapping [zeromus, CrazyMax] + bug: viewports finally correctly handled [zeromus] + enh: add software rasterizer. quirky, but on par with opengl [zeromus] + +Windows: + bug: mitigate bad frameskipper; default to old frameskipping mode [zeromus] + bug: fixes with recent roms and zipfile loading [zeromus] + bug: fix window position memory [zeromus] + enh: bios and firmware may now be used and booted [luigi__] + enh: many display, OSD, and input enhancements [luigi__] + enh: brand new hotkey and controls binding system [zeromus] + enh: configurable screen separation [luigi__] + enh: fast forward key [pa__] + enh: improvements to mic [luigi__] + enh: faster updates in debug tools, up to once per frame [pa__] + +Mac OS X Port: + enh: added Italian translation thanks to Paolo Bernini [jeff] + enh: resurrection of GDB stub [sigmaris] + +0.9 -> 0.9.1 +General/Core: + enh: GBA slot emulation [CrazyMax] + - Rumble support (windows only) + - GBA game + enh: Mic support (windows only?) [luigi__] + enh: Preliminary cheats system [CrazyMax] + enh: Savestates invalidated, as more variables have been added. + bug: Added PSG white noise [luigi__] + bug: fix arm/thumb ROR [zeromus] + bug: [ 2550645 ] Super Princess Peach: crash when starting a puzzle [zeromus] + bug: win32: fix spu wav file writer (regression from 0.8) [zeromus,luigi__] + bug: Much work on FIFOs, still not finished [CrazyMax] + bug: Many fixes to dma [zeromus, CrazyMax] + bug: bios WaitForVblank and WaitForInterrupt fixed [luigi__] + +Graphics: + bug: Added sprite blending [luigi__] + bug: more correct mosaic effects, still imperfect [zeromus] + bug: Many fixes to tile rendering; all graphics tests now pass [luigi__] + bug: fix crashes in some affine BG [zeromus] + bug: Implement some pos test function [luigi__] + bug: fix texture mapping across texture and palette banks and to unmapped banks [zeromus] + bug: fix texture handling for texels with MSB set (fixes some texture corruption) [zeromus] + bug: fix texture coordinate generation, including environment mapping [zeromus] + bug: texture cache invalidates when palettes change, prevents some texture corruption [zeromus] + bug: fix display capturing from 2d+3d source when display mode is display-vram [zeromus] + bug: [ 2488334 ].1 fixes to layer compositing [luigi__] + bug: [ 2488334 ].3 fix bug in support for hdma affine bg parameters [zeromus] + bug: Improvements to 3d h-scrolling [luigi__] + bug: Fix some errors in rendering 512 tall BG [zeromus,CrazyMax] (still not fully resolved) + bug: Add optional fragment shading pipeline (more precision) [luigi__] + bug: Fix bug where some sprites got cut of on x=255 [zeromus] + bug: Implement GXSTAT register [CrazyMax] + +Windows: + bug: resizing and rotating work in vista [luigi__] + enh: 0 frameskip now lets emulator run at excess speed [zeromus] + +Mac OS X Port: + bug: left key setting no longer gets confused with the right key [jeff] + enh: more keys can be mapped + +0.8 -> 0.9 + There have been so many changes that this list can hardly be considered complete. + For this release, we have formatted the list into a high level overview of big changes and bad bugs relative to the previous release. Hopefully what you're interested in. + This list does not include items which are solely performance boosts, for let us just say that virtually every system has been speeded up. + + * The savestate system is totally changed and incompatible with old savestates. + * The 3d system should be considered rewritten. + +General/Core: + enh: Convert to c++ + enh: Add functions for a lid open/close. Holding key (default "Backspace" in Windows port) while game is freeze/non freeze. [CrazyMax] + enh: Add secure area decryption from ndstool [zeromus] + enh: Change savestate code to support loosely bound chunks and more easily other parts of the emu (GE, GPU). + The savestate format is changed, but from now on it is in principle more resilient + (though it will continue to break as we tinker with the internals) [zeromus] + enh: Added SSE2 optimizations for matrices. Since we now make an SSE2 build, more optimizations can be made. [CrazyMax] + enh: Add a preliminary GUI hud system [CrazyMax,zeromus] + +CPU/MMU: + bug: Many fixes in IPC and GE FIFOs. Fixes freezes in NSMB, dsracing, and others. [CrazyMax,luigi__,shash] + bug: Fix ARM instructions SBC and RSC (likewise SBC in thumb) [normatt] + bug: Fixed Thumb LDMIA (fixes ingame Dead'n'Furious) [shash] + bug: Fix repeating DMA (fixes NSMB parallax BG) [zeromus] + bug: Proper handling for unaligned CPU accesses [luigi__] + bug: Proper handling for undefined instruction exceptions [Salva Peiró] + bug: correctly return vram control register values (fixes homebrew 3d games) [zeromus] + enh: Remove 16MB of WRAM at 0x01****** from arm9. Mapped to unused instead. Nobody knows what this was. [zeromus] + enh: Changed instruction execution to 16 at a time blocks (tested and stable) [shash] + +Hardware: + bug: Newer and better sqrt and div emulation; makes SM64DS playable [luigi__,shash,zeromus] + bug: Add preliminary RTC implementations [CrazyMax] + enh: Add cosine interpolation in the SPU (conditionally compiled) [zeromus,luigi__] + enh: Experimental: always one silent non-mixing SPU core at 44.1khz synched with emu, for more precision. + The audible core runs with the host, causing music to slow down but not tear or pitch bend. [zeromus] + +Graphics: + - Overhaul 3d: + . Move entire GE to core emu. + . Move OpenGL renderer to emu core for optional use by platforms, removing ogl_collector. Now every platform shares the same 3d code. + . Reorganize 3d code to defer rendering to after 3d vblank. Eliminates tearing, and texturing artifacts. [zeromus] + . Add optional fragment shading pipeline (more precision) [luigi__] + . Move lighting model to software instead of using opengl's fixed function model [zeromus] + . Render shadow volumes; toon shading and highlight table [zeromus, luigi__] + . Added texture caching! big speed up. [CrazyMax] + + bug: Many assorted tweaks and improvements to 3d and 2d precision [zeromus,CrazyMax,luigi__] + bug: Fixes to GE: command unpacking, projection and pos-vector mode matrix handling, mult and load commands [zeromus] + bug: Fix a bug in texture transformation mode 1 [zeromus] + bug: Fixed GPU rendering bugs in sprites and BG [CrazyMax] + bug: Fixes to texture conversion [CrazyMax,zeromus] + bug: Fixes in capture display (no blinking in many games with dual 3D) [CrazyMax] + bug: Fixes in master brightness (this fixes some games with black screens) [CrazyMax] + bug: Fixes in screen, backdrop, and sprite blending [luigi__] + bug: Changed clear depths and how depth initial values are calculated (fixes SM64DS skybox, Castlevania) [shash,lugi__] + bug: Add 3d layer h-scrolling [zeromus] + bug: Added transparency and fixed material alpha support and alpha testing on the 3D core [shash] + bug: Rewrite VRAM mapping control and rendering (more accurate) [CrazyMax,luigi__] + + bug: convert colors to opengl better to prevent alpha=31 polys from being ever so slightly transparent [zeromus] + enh: Add MMU->GPU signal for when vram mappings change to function as a texture cache invalidate signal [zeromus] + enh: Make matrix 4x4 multiply routines use W-coordinate; carry w coord through pipeline [zeromus] + +Mac OS X port: + bug: Fixed: Filenames and paths with unicode characters now work. [Jeff] + bug: Fixed: Load state from file button works again. [Jeff] + enh: Save State panel now pauses emulation while the file selection box is open. [Jeff] + bug: Fixed: Frozen video output (and/or messed 3d emulation) after loading a state. [Jeff] + bug: Added option to load the most recent file upon launching the program. [Jeff] + enh: Added French translation (thanks to Pierre Rudloff). [Jeff] + enh: Added basic key mapping configuration to application preferences (thanks to Julio GorgŽ). [Jeff] + enh: Added keyboard shortcuts for Execute, Pause and Reset command (thanks to Julio GorgŽ). [Jeff] + enh: Default key mappings are no longer case sensitive. [Jeff] + enh: Added ability to limit speed. [Jeff] + enh: Fixed: Video output should work on software-only 3D renderers. [Jeff] + +Windows port: + bug: Fix a race condition in NDS_3D_Reset and NDS_glInit [zeromus] + bug: Fix the buggy auto frameskip logic which made the emu slow to a crawl. Now it runs fast! [zeromus] + bug: Fix resizing, rotate & aspect ration of main window. [CrazyMax,_zeromus] + bug: Remove multithreading from user interface after finding several synchronization issues [zeromus] + enh: recent roms menu [luigi_] + enh: Changed graphics render core to DirectDraw (work faster) [CrazyMax] + enh: Add an arm9 cpu load average calculator similar to no$. but I dont think it works right. [zeromus] + enh: Rewrite all debug tools (autoupdate works now) [CrazyMax] + enh: Rewrite input core & replace config input dialog [CrazyMax] + enh: Add AVI output [zeromus] + enh: Add pause toggle and frame advance hotkeys [adelikat] + enh: Add frame counter display and hud messages framework [adelikat] + enh: Main window remembers position, size, and a few other emu preferences [adelikat] + enh: Removed directx sdk dependency for easier building. [zeromus] + enh: Savestate doesnt unpause emu if it is already paused [adelikat] + +0.7.3 -> 0.8 + Cocoa: + - Save State As function now works. [Jeff B] + - Recent Items menu now works. [Jeff B] + - Opening NDS files from Finder now works. [Jeff B] + - Added screenshot feature. [Jeff B] + - Added preferences. [Jeff B] + - Many more strings are translatable now. [Jeff B] + - Default screen color is black (better represents being "off" and easier on eyes at night). [Jeff B] + - Added sound. [Jeff B] + - Now is a universal binary. [Jeff B] + - Leopard resolution icon added. [Jeff B] + - Added a Japanese translation. [Jeff B] + - Added an optional status bar (resize handle no longer overlaps screen). [Jeff B] + - New ROM Info and About DeSmuME windows have been added. [Jeff B] + - Fixed several bugs in window resizing. [Jeff B] + - Added FAT image support for homebrew games (thanks to TypeError). [Jeff B] + - Key config can be changed on the command line. Save/load hotkeys changed (so expose doesn't override). [Jeff B] + - Key bindings may work better on non-US keyboards now (needs testing). [Jeff B] + general: + - Encapsulate GDB debug stub to avoid certain problems [shash] + - Fixed CPU LD*/ST* bugs [shash] + - Fixed New SMB mini-games freeze [shash] + - Fixed possible segfault in ROMReader on ia64 and amd64. [evilynux] + - Fixed a crash bug with 2D background corrupting memory [shash] + - Flag check optimization [carlo_bramini] + - Applied some endian fixes in GPU (thanks to Phazz) [Jeff B] + gtk-glade: + - Added DeSmuME version in about dialog. [evilynux] + - Updated website url in about dialog. [evilynux] + - Added Brazilian Portuguese translation by Dreampeppers99. [evilynux] + - Better desktop menu entry following FreeDesktop specifications. [evilynux] + gtk: + - Updated website url in about dialog. [evilynux] + - Better desktop menu entry following FreeDesktop specifications. [evilynux] + windows port: + - Added an "about" box [shash] + - DirectInput control interface with joystick support [CrazyMax] + - Matrix and Light viewer [Acid Burn] + +0.7.2 -> 0.7.3 + gtk-glade: + - Full localization using intltool/gettext. [evilynux] + general: + - Added a README.TRANSLATION documenting the localization process. [evilynux] + MacOS X: + - Initial version of the Mac interface added. [Jeff B] + +0.7.1 -> 0.7.2 + spu: + - big endian fixes. [cyberwarriorx] + gpu: + - big endian fixes. [marcus_c] + gtk-glade: + - opengl improvements. [masscat] + general: + - Added support for setting NDS firmware language value. [masscat] + - Function added for setting firmware language. [masscat] + - Mac/msys compilation fixes. [cyberwarriorx] + - Fix compilation when pkg-config macros are not available [evilynux] + +0.7.0 -> 0.7.1 + general: + - Added GDB debugger stub [masscat] + - Added new/different GBAMP CFlash image reader/writer [masscat] + gpu: + - Major speedup to the 2D core [shash] + gtk-glade: + - Added command line options. [masscat] + - Added FPS limiter [masscat] + cli: + - Added command line options. [masscat] + - Added FPS limiter [masscat] + - Added option to use OpenGl to render window (allows resizing). [masscat] + windows port: + - Added command line options. [masscat] + - Added multiple language support [cyberwarriorx] + - Added Danish language translation [thomas-2007] + +0.6.0 -> 0.7.0 + general: + - Added support for *.duc files [cyberwarriorx] + gpu: + - Added support for sprite rotation/scaling [shash] + - Added support for the 3D core (openGL and null plugins) [shash] + windows port: + - A bunch of fixes [Dmitry Krutskih] + - Fixed a bug in sound that was causing it to still not work for some + people [cyberwarriorx] + gtk: + - Added 3D emulation + - Added command line options. + - Added option to use OpenGL to render window (allows resizing). + gtk-glade: + - Added 3D emulation + +0.5.0 -> 0.6.0 + general: + - Added zipped (based on zziplib) and gzipped (based on zlib) rom support. + arm: + - Added relocation interrupt vector. + - Added region access right checks. + - Enabled LDC/STC instructions. + - Fixed powersave (cp15) IRQ wait. + - Fixed MOV instructions + gpu: + - Added special color effects. + - Added windowing feature. + - Fixed transparent direct color backgrounds. + - Fixed disabled sprites showing. + - Fixed 8/32 bit access to gpu registers. + - Fixed missing backgrounds + - Support for master brightness + wifi: + - Added RF chip interface. + - Added BB chip interface. + windows port: + - Fixed address calculation in disassembler. + - Added Force Maintain Ratio option for window stretching + linux port (cli, gtk and gtk-glade): + all: + - Added joystick support. + - Fixed X and Y buttons. + gtk-glade: + - Added joystick configuration. + - Improved I/O registers viewer tool. + - Added save and load states support. + +0.3.3 -> 0.5.0 + arm: + - Fixed MSR with immediate value opcode. + - Fixed LSR_0 thumb opcode (C flag is correctly set now). + - Fixed LDR*/STR* opcodes. + - Fixed unaligned memory access on THUMB Core. + - Added relocating SWI routines. + bios: + - Added decompression functions. + - Added GetPitchTable function. + - Added GetVolumeTable function. + - Added GetCRC16 function. + - Added experimental SoundBias function. + - Added GetSineTable function. + cart: + - Added CompactFlash/FAT emulation. + - Added Get ROM chip ID Cartridge command. + gpu: + - Added framebuffer emulation. + - Fixed a bug in GPU (xfin could be greater than LG causing a segfault). + - Added support for Display Mode 0(Display Off). + - Added the basic framework for Display Mode 3(Display from Main RAM). + spu: + - Added sound emulation. + - Added sound core system. + - Added WAV write core. + - Added dummy core. + - Added Direct Sound core. + linux port: + - Added GTK+ GUI. + - Added command line interface. + - Added stylus and arm9 keypad support in CLI version. + - Added FPS display. + - Added basic frameskip. + windows port: + - Fixed a bug when displaying a ROM's information. + - Added key configuration. + - Removed the debug key. + - Added new experimental auto frameskip/frame limit code. + - Added sound settings dialog. + - Added a few menu options for accessing the website, forums, and for + submitting bugs. + general: + - Rewrote code in C. + - Fixed warnings. + - Used defines and typedef's to make things more portable and easier to + read. + - Added autotools stuff. + - Changes to logging system. + - Added screenshot function. + - Translated most french to english. + - Added savestate support. + - Added firmware reading support(needs work). + - Added Backup Memory support with autodetection. + - Fixed some endianess issues. + - Fixed things so Visual C++ can compile code. + - Added bsd support. + - Reworked ROM loading so you can load a different rom without any problems. + - Finished NDS_Reset. Now the emulation can be reset even while running. diff --git a/INSTALL b/INSTALL new file mode 100644 index 000000000..d3c5b40a9 --- /dev/null +++ b/INSTALL @@ -0,0 +1,237 @@ +Installation Instructions +************************* + +Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, +2006, 2007 Free Software Foundation, Inc. + +This file is free documentation; the Free Software Foundation gives +unlimited permission to copy, distribute and modify it. + +Basic Installation +================== + +Briefly, the shell commands `./configure; make; make install' should +configure, build, and install this package. The following +more-detailed instructions are generic; see the `README' file for +instructions specific to this package. + + The `configure' shell script attempts to guess correct values for +various system-dependent variables used during compilation. It uses +those values to create a `Makefile' in each directory of the package. +It may also create one or more `.h' files containing system-dependent +definitions. Finally, it creates a shell script `config.status' that +you can run in the future to recreate the current configuration, and a +file `config.log' containing compiler output (useful mainly for +debugging `configure'). + + It can also use an optional file (typically called `config.cache' +and enabled with `--cache-file=config.cache' or simply `-C') that saves +the results of its tests to speed up reconfiguring. Caching is +disabled by default to prevent problems with accidental use of stale +cache files. + + If you need to do unusual things to compile the package, please try +to figure out how `configure' could check whether to do them, and mail +diffs or instructions to the address given in the `README' so they can +be considered for the next release. If you are using the cache, and at +some point `config.cache' contains results you don't want to keep, you +may remove or edit it. + + The file `configure.ac' (or `configure.in') is used to create +`configure' by a program called `autoconf'. You need `configure.ac' if +you want to change it or regenerate `configure' using a newer version +of `autoconf'. + +The simplest way to compile this package is: + + 1. `cd' to the directory containing the package's source code and type + `./configure' to configure the package for your system. + + Running `configure' might take a while. While running, it prints + some messages telling which features it is checking for. + + 2. Type `make' to compile the package. + + 3. Optionally, type `make check' to run any self-tests that come with + the package. + + 4. Type `make install' to install the programs and any data files and + documentation. + + 5. You can remove the program binaries and object files from the + source code directory by typing `make clean'. To also remove the + files that `configure' created (so you can compile the package for + a different kind of computer), type `make distclean'. There is + also a `make maintainer-clean' target, but that is intended mainly + for the package's developers. If you use it, you may have to get + all sorts of other programs in order to regenerate files that came + with the distribution. + + 6. Often, you can also type `make uninstall' to remove the installed + files again. + +Compilers and Options +===================== + +Some systems require unusual options for compilation or linking that the +`configure' script does not know about. Run `./configure --help' for +details on some of the pertinent environment variables. + + You can give `configure' initial values for configuration parameters +by setting variables in the command line or in the environment. Here +is an example: + + ./configure CC=c99 CFLAGS=-g LIBS=-lposix + + *Note Defining Variables::, for more details. + +Compiling For Multiple Architectures +==================================== + +You can compile the package for more than one kind of computer at the +same time, by placing the object files for each architecture in their +own directory. To do this, you can use GNU `make'. `cd' to the +directory where you want the object files and executables to go and run +the `configure' script. `configure' automatically checks for the +source code in the directory that `configure' is in and in `..'. + + With a non-GNU `make', it is safer to compile the package for one +architecture at a time in the source code directory. After you have +installed the package for one architecture, use `make distclean' before +reconfiguring for another architecture. + +Installation Names +================== + +By default, `make install' installs the package's commands under +`/usr/local/bin', include files under `/usr/local/include', etc. You +can specify an installation prefix other than `/usr/local' by giving +`configure' the option `--prefix=PREFIX'. + + You can specify separate installation prefixes for +architecture-specific files and architecture-independent files. If you +pass the option `--exec-prefix=PREFIX' to `configure', the package uses +PREFIX as the prefix for installing programs and libraries. +Documentation and other data files still use the regular prefix. + + In addition, if you use an unusual directory layout you can give +options like `--bindir=DIR' to specify different values for particular +kinds of files. Run `configure --help' for a list of the directories +you can set and what kinds of files go in them. + + If the package supports it, you can cause programs to be installed +with an extra prefix or suffix on their names by giving `configure' the +option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. + +Optional Features +================= + +Some packages pay attention to `--enable-FEATURE' options to +`configure', where FEATURE indicates an optional part of the package. +They may also pay attention to `--with-PACKAGE' options, where PACKAGE +is something like `gnu-as' or `x' (for the X Window System). The +`README' should mention any `--enable-' and `--with-' options that the +package recognizes. + + For packages that use the X Window System, `configure' can usually +find the X include and library files automatically, but if it doesn't, +you can use the `configure' options `--x-includes=DIR' and +`--x-libraries=DIR' to specify their locations. + +Specifying the System Type +========================== + +There may be some features `configure' cannot figure out automatically, +but needs to determine by the type of machine the package will run on. +Usually, assuming the package is built to be run on the _same_ +architectures, `configure' can figure that out, but if it prints a +message saying it cannot guess the machine type, give it the +`--build=TYPE' option. TYPE can either be a short name for the system +type, such as `sun4', or a canonical name which has the form: + + CPU-COMPANY-SYSTEM + +where SYSTEM can have one of these forms: + + OS KERNEL-OS + + See the file `config.sub' for the possible values of each field. If +`config.sub' isn't included in this package, then this package doesn't +need to know the machine type. + + If you are _building_ compiler tools for cross-compiling, you should +use the option `--target=TYPE' to select the type of system they will +produce code for. + + If you want to _use_ a cross compiler, that generates code for a +platform different from the build platform, you should specify the +"host" platform (i.e., that on which the generated programs will +eventually be run) with `--host=TYPE'. + +Sharing Defaults +================ + +If you want to set default values for `configure' scripts to share, you +can create a site shell script called `config.site' that gives default +values for variables like `CC', `cache_file', and `prefix'. +`configure' looks for `PREFIX/share/config.site' if it exists, then +`PREFIX/etc/config.site' if it exists. Or, you can set the +`CONFIG_SITE' environment variable to the location of the site script. +A warning: not all `configure' scripts look for a site script. + +Defining Variables +================== + +Variables not defined in a site shell script can be set in the +environment passed to `configure'. However, some packages may run +configure again during the build, and the customized values of these +variables may be lost. In order to avoid this problem, you should set +them in the `configure' command line, using `VAR=value'. For example: + + ./configure CC=/usr/local2/bin/gcc + +causes the specified `gcc' to be used as the C compiler (unless it is +overridden in the site shell script). + +Unfortunately, this technique does not work for `CONFIG_SHELL' due to +an Autoconf bug. Until the bug is fixed you can use this workaround: + + CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash + +`configure' Invocation +====================== + +`configure' recognizes the following options to control how it operates. + +`--help' +`-h' + Print a summary of the options to `configure', and exit. + +`--version' +`-V' + Print the version of Autoconf used to generate the `configure' + script, and exit. + +`--cache-file=FILE' + Enable the cache: use and save the results of the tests in FILE, + traditionally `config.cache'. FILE defaults to `/dev/null' to + disable caching. + +`--config-cache' +`-C' + Alias for `--cache-file=config.cache'. + +`--quiet' +`--silent' +`-q' + Do not print messages saying which checks are being made. To + suppress all normal output, redirect it to `/dev/null' (any error + messages will still be shown). + +`--srcdir=DIR' + Look for the package's source code in directory DIR. Usually + `configure' can determine that directory automatically. + +`configure' also accepts some other, not widely useful, options. Run +`configure --help' for more details. + diff --git a/desmume/Makefile.am b/Makefile.am similarity index 100% rename from desmume/Makefile.am rename to Makefile.am diff --git a/desmume/NEWS b/NEWS similarity index 100% rename from desmume/NEWS rename to NEWS diff --git a/desmume/README b/README similarity index 100% rename from desmume/README rename to README diff --git a/desmume/README.LIN b/README.LIN similarity index 100% rename from desmume/README.LIN rename to README.LIN diff --git a/desmume/README.MAC b/README.MAC similarity index 100% rename from desmume/README.MAC rename to README.MAC diff --git a/desmume/README.TRANSLATION b/README.TRANSLATION similarity index 100% rename from desmume/README.TRANSLATION rename to README.TRANSLATION diff --git a/README.WIN b/README.WIN new file mode 100644 index 000000000..0d293b9ba --- /dev/null +++ b/README.WIN @@ -0,0 +1,215 @@ + DeSmuME + _________________________________________ + Copyright (C) 2006 yopyop + Copyright (C) 2006-2007-2008-2009 DeSmuME team + + +1) Compiling instructions...................................13 +2) How to use DeSmuME.......................................51 +3) Contact information.....................................166 +4) Disclaimer..............................................184 + + +1 Compiling instructions______________________________________ + +DeSmuME is written in C++, using the DirectX 8.0, OpenGL, zlib, +zziplib libraries, so you need a working C++ compiler, such as +Visual C++ 2005, Visual C++ 2008 or Intel compiler. It should +also be possible to compile it on dev-cpp, but it's currently +untested. + + * OpenGL should be included with your compiler, if it isn't, + check on your compiler's website for links. + + * zlib can be found at http://www.zlib.net + + * zziplib can be found at http://zziplib.sourceforge.net + +Visual C++: + Load either the project file DeSmuME_2005.vcproj +or DeSmuME_2008.vcproj (depending on the VisualC++ version +you're using) in the src/windows directory, compile, and +you're set. + + +2 How to use DeSmuME__________________________________________ + +Execute "desmume". A new window (and a information console) +should pop up. The default settings should be fine for most +people, but in case you need to adjust them, here's a brief +explanation: + +Under the "Config", there are a number of items: + +Save Type: +Here you can select which type of Backup Memory DeSmuME should +emulate. By default, Autodetect works fine, but in some cases +DeSmuME doesn't correctly detect the Backup Memory. In that +case, you will want to select the correct one. + +3D Config: +Here you can change what will be used to emulate the 3D core +of the DS. By default it's on openGL, but you can also select +a Null device, that won't show any 3D. + +Control Config: +Here you can change the default key mappings. For now only the +keyboard is supported, but in the near future gamepads and +joysticks will be supported. + +Here are the default key mappings (they may be subject to +change): + + Up arrow - Up + Left arrow - Left + Down arrow - Down + Right arrow - Right + x - A button + z - B button + s - X button + a - Y button + q - Left Trigger + w - Right Trigger + Enter - Start button + Right Shift - Select button + Backspace - Lid fold/unfold + + n - Frame advance + Space - Pause/Unpause + p - Load current state + 1,2,3,4,5,6,7,8,9,0 - Select current state + F1-F10 - Load relevant state + Shift+F1-F10 - Save relevant state + + +Sound Settings: +Here you can change the default sound settings. By default +DeSmuME uses Direct Sound, a buffer size of 2940, and volume +set to max. But if you want to mute the sound, you can set the +sound core to none. Or if you want to save the sound to a +file, you can set the sound core to WAV write. If you find the +sound is crackling a lot, try increasing the buffer size. On +the other hand, if you find the sound somewhat delayed or +jumpy, try decreasing the buffer size. + +Firmware Settings: +Here you can change settings that are used as a customization +on the real DS: your name, birthday, favourite colour, etc... + +Frame Skip: +Here you can adjust the amount of frame draws to skip during +emulation. Normally the emulator detects whether the emulator +is running too fast or slow and skips a frame or more if it +needs to speed things up. However some people don't like the +results of it, so here you can adjust that. + +Language: +Here you can change the emulator menus language. Currently we +only support English, French and Danish. + + + +After all the settings are set to your satisfaction, you can +then load a ROM image by going into the "File" menu, and +choosing "Open". Select which file you'd like to open, and the +emulator will automatically load and start running the +selected ROM. + +------------------------ + +Under the View menu there's also a few additional options you +may wish to change. + +Rotation: +Here you can adjust which angle of the display. Some programs +require that you normally turn the DS on its side. You can set +it up in that manner using this. + +Window size: +With these options you can increase or decrease the window +size. + +Note: You can also adjust the window size by clicking on the +edge of the window, and dragging the mouse. + +Force Maintain Ratio: +Sometimes when the window size is changed it's doesn't look +correct on the screen. This option forces the window to +maintain a correct ratio so it looks correct. + +Default size: +This option makes the emulator window go back to the default +size. + +------------------------ + +GDB Debugger Stubs: +Source level debugging of ARM9 and/or ARM7 code is supported +using a GDB/Insight debugger. The GDB stubs are enabled from +the command line using the following options: + +--arm9gdb= (for the ARM9) +--arm7gdb= (for the ARM7) + +The PORT_NUM is the TCP port upon which the stub will listen +for connections. Once enabled you can connect to the stub +using the following command at the GDB debugger prompt +(assuming GDB and DeSmuME are running on the same machine): + +target remote : + +NOTE: There are problems with the ARM support when stepping +code with GDB versions prior to version 6.6. It is recommended +that you use at least version 6.6 if possible. + +------------------------ + +GBAMP compact flash emulation: +The default behaviour of DeSmumME is to attempt to emulate the +FAT image for the contents of the directory where the running +.nds file was located. + +This behaviour can be altered using the --cflash= +command line option. Using this option DeSmuME will emulation +a GBAMP and read and write sectors from/to the disk image +file. The disk image file must be created and populated with +files using some external tool. + +NOTE: Currently if desmume fails to open the disk image file +it will silently continue minus a working GBAMP emulation. + + +3 Contact information_________________________________________ + +General inquiries should go to: + +E-mail: guillaume@desmume.org +Web: http://www.desmume.org +Forums: http://forums.desmume.org + +Please don't ask for roms, bios files or any other copyrighted +stuff. + +If you want to submit a bug report, please run desmume, go +into the "Help" menu, and click on "Submit a bug report". If +you're having trouble with it, please feel free to email. + + +4 Disclaimer__________________________________________________ + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License as +published by the Free Software Foundation; either version 2 of +the License, or (at your option) any later version. + +This program is distributed in the hope that it will be +useful,but WITHOUT ANY WARRANTY; without even the implied +warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public +License along with this program; if not, write to the Free +Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, +MA 02111-1307 USA + +See the GNU General Public License details in COPYING. diff --git a/desmume/TODO b/TODO similarity index 100% rename from desmume/TODO rename to TODO diff --git a/desmume/autogen.sh b/autogen.sh similarity index 100% rename from desmume/autogen.sh rename to autogen.sh diff --git a/desmume/autopackage/default.apspec.in b/autopackage/default.apspec.in similarity index 100% rename from desmume/autopackage/default.apspec.in rename to autopackage/default.apspec.in diff --git a/desmume/compile b/compile similarity index 100% rename from desmume/compile rename to compile diff --git a/desmume/configure.ac b/configure.ac similarity index 92% rename from desmume/configure.ac rename to configure.ac index 1451afde7..b028b91c8 100644 --- a/desmume/configure.ac +++ b/configure.ac @@ -31,20 +31,10 @@ dnl - Check for intltool/gettext macros m4_ifdef([IT_PROG_INTLTOOL],[IT_PROG_INTLTOOL]) dnl - Check for zlib -AC_CHECK_LIB(z, gzopen, [], [AC_MSG_ERROR([zlib was not found, we can't go further. Please install it or specify the location where it's installed.])]) +AC_CHECK_LIB(z, gzopen) dnl - Check for zziplib -AC_CHECK_LIB(zzip, zzip_open, [ - LIBS="-lzzip $LIBS" - AC_DEFINE([HAVE_LIBZZIP]) - AC_MSG_CHECKING([[whether zzip use void * as second parameter]]) - AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[#include ]], [[ - void * v; - zzip_read(NULL, v, 0);]]), - AC_MSG_RESULT(yes), - AC_DEFINE([ZZIP_OLD_READ]) - AC_MSG_RESULT(no)) -]) +AC_CHECK_LIB(zzip, zzip_open) dnl - Check for SDL AC_PATH_PROGS(SDLCONFIG, [sdl-config sdl11-config]) @@ -66,11 +56,10 @@ dnl - if --enable-osmesa is used, check for it AC_ARG_ENABLE([osmesa], [AC_HELP_STRING([--enable-osmesa], [use off-screen mesa])], [osmesa=$enableval], - [osmesa=yes]) + [osmesa=no]) if test "x$osmesa" = "xyes" ; then AC_CHECK_LIB(dl, main) - AC_CHECK_LIB([GL], main) AC_CHECK_LIB(OSMesa, main,[ useosmesa=yes AC_DEFINE(HAVE_LIBOSMESA) @@ -88,20 +77,28 @@ AC_PROVIDE_IFELSE([PKG_PROG_PKG_CONFIG], [ glib-2.0 >= $GLIB_VER, HAVE_GLIB=yes, HAVE_GLIB=no) + if test "$HAVE_GLIB" = "no"; then + AC_MSG_ERROR([glib-2.0 >= $GLIB_VER is required to build desmume gtk frontend]) + fi PKG_CHECK_MODULES(GTK, gtk+-2.0 >= $GTK_VER, HAVE_GTK=yes, HAVE_GTK=no) + if test "$HAVE_GTK" = "no"; then + AC_MSG_ERROR([gtk-2.0 >= $GTK_VER is required to build desmume gtk frontend]) + fi AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) + if test ! "x$useosmesa" = "xyes" ; then PKG_CHECK_MODULES(GTKGLEXT, "gtkglext-1.0", HAVE_GTKGLEXT=yes, HAVE_GTKGLEXT=no) AC_SUBST(GTKGLEXT_CFLAGS) AC_SUBST(GTKGLEXT_LIBS) + fi PKG_CHECK_MODULES(GTHREAD, "gthread-2.0", @@ -212,7 +209,7 @@ if test "x[$]ENABLE_HARDCORE" = "x1"; then dnl - only valid for C with newer gcc's CPPFLAGS="[$]CPPFLAGS -Wmissing-prototypes" fi - CPPFLAGS="[$]CPPFLAGS -Wall -Wextra -D_FORTIFY_SOURCE=2 -Wno-missing-field-initializers -Wpointer-arith -Wcast-align -Wwrite-strings -Wno-unused-parameter -Wmissing-declarations -Wundef -Wmissing-noreturn -Wshadow -Wredundant-decls -Wformat-nonliteral -Wformat-security -Winit-self" + CPPFLAGS="[$]CPPFLAGS -Wall -Wextra -D_FORTIFY_SOURCE=2 -Wno-missing-field-initializers -Wpointer-arith -Wcast-align -Wwrite-strings -Wno-unused-parameter -Wmissing-declarations -Wundef -Wmissing-noreturn -Wshadow -Wredundant-decls -Wformat-nonliteral -Wformat-security -Wswitch-enum -Winit-self" fi dnl - Enable debug mode diff --git a/desmume/README.WIN b/desmume/README.WIN deleted file mode 100644 index 45d860d18..000000000 --- a/desmume/README.WIN +++ /dev/null @@ -1,503 +0,0 @@ - - -DeSmuME Manual for the Windows port - -1 Quick Getting Started Guide -1.1 Menu Layout -1.1.1 File Menu -1.1.1.1 File | Open Rom -1.1.1.2 File | Recent Rom -1.1.1.3 File | Rom Info -1.1.1.4 File | Save State As... -1.1.1.5 File | Load State As... -1.1.1.6 File | Save State -1.1.1.7 File | Load State -1.1.1.8 File | Import Backup Memory -1.1.1.9 File | Save Screenshot As... -1.1.1.10 File | Quick Screenshot -1.1.1.11 File | Record AVI -1.1.1.12 File | Stop AVI -1.1.1.13 File | Quit -1.1.2 Emulation Menu -1.1.2.1 Emulation | Pause -1.1.2.2 Emulation | Reset -1.1.2.3 Emulation | Shut Up -1.1.2.4 Emulation | GBA Slot -1.1.2.5 Emulation | Cheats -1.1.2.6 Emulation | Cheats | List -1.1.2.7 Emulation | Cheats | Search -1.1.3 View Menu -1.1.3.1 View | Rotation -1.1.3.2 View | Window size -1.1.3.3 View | Screen Separation -1.1.3.4 View | Force Maintain Ratio -1.1.3.5 View | Display Frame Counter -1.1.3.6 View | Display FPS -1.1.3.7 View | Display Input -1.1.3.8 View | Display Lag Counter -1.1.3.9 View | HUD Editing Mode -1.1.4 Config Menu -1.1.4.1 Config | Save Type -1.1.4.2 Config | 3D Settings -1.1.4.3 Config | Control Config -1.1.4.4 Config | Hotkey Config -1.1.4.5 Config | Sound Settings -1.1.4.6 Config | WIFI Settings -1.1.4.7 Config | Firmware Settings -1.1.4.8 Config | Emulation Settings -1.1.4.9 Config | Frame Skip -1.1.4.10 Config | Language -1.1.5 Tools Menu -1.1.5.1 Tools | Disassembler -1.1.5.2 Tools | View Memory -1.1.5.3 Tools | View Registers -1.1.5.4 Tools | View Palette -1.1.5.5 Tools | View Tiles -1.1.5.6 Tools | View Maps -1.1.5.7 Tools | View OAM -1.1.5.8 Tools | View Matrices -1.1.5.9 Tools | View Lights -1.1.5.10 Tools | View Layers -1.1.6 Help Menu -1.1.6.1 Help | Website -1.1.6.2 Help | Forums -1.1.6.3 Help | Submit a bug report -1.1.6.4 Help | About - - -Quick Getting Started Guide -When you start the emulator for the first time, you probably just want to play a certain game. You can do this by going to 'File' in the menu, and selecting 'Open Rom'. This will open up an explorer window, within which you can browse to the rom (nds file) that you wish to play. Once the game has finished loading (and this should only take a few seconds at most), your game will automatically start running. But if you want, you can also compile from source. See the article Installing DeSmuME from source on Windows for details. - -Menu Layout -The rest of this manual will be spend on explaining all the other options in the menu. - - - - -File Menu -File | Open Rom -This option is for loading games. A game is typically called a rom file. Just use the explorer window to browse to the file, and click on open. The game should just load and start. The desmume windows port is also able to load some compressed formats, like zip, rar, and 7-zip. Just as long as there is a valid game (rom) file in the compressed archive ending with an .nds extension, it should load fine. - -File | Recent Rom -This menu option contains a list of the roms that you have most recently loaded. You can quickly access a game that way, without having browse to the right directory with the 'Open Rom' option. - -File | Rom Info -This option offers some information about the internals of the rom file, like name, code, manufacturer, and size. This should not concern the casual gamer, but may come in handy for developers. - -File | Save State As... -Imagine you have gotten to a certian point in a game, and you need to do something else. The emulator let's you save the current state of the game, so that you can continue the game later at precisely the same point somewhere in the future. - -File | Load State As... -Once you have saved a game's position, or 'state', you can load it again with this option. - -File | Save State -This option works fairly similair to the 'Save As' option, altough it let's you save numbers instead os specifying a chosen name. Also, All the states saved via this option end up with a pre-determined name of 'game (rom) name'.dsx. So if the game is called MyGame, the first savefile will be called MyGame.ds0, the second one MyGame.ds1, etc. - -File | Load State -This option let's you load the states that you saved via the 'File | Save State' option - -File | Import Backup Memory -Backup Memory is the data the game uses to remember its own state. It is stored on the cart in a normal game. The file format is '.duc'. .duc is the same thing as .sav but a different format. People use pro action replays to capture it from their card and post it online without using emulators. Go to gamefaqs.com and find a '.duc' save file for a game you can use that function to import it into desmume. Its the save file. save ram. where your saved game goes. desmume calls it .sav file - -File | Save Screenshot As... -This lets you take a screenshot of the current view of the emulator, and specify it's name to save as a bitmap (.bmp) file. - -File | Quick Screenshot -This option also dumps a screencapture, but it has a pre-determied filename and location. It will be called printscreen.bmp, and located in the current directory. In Windows, this is probably the same folder as where your desmume binary is located. - -File | Record AVI -This option lets you capture what's going on in the emulator, and save it in an avi file. - -File | Stop AVI -The 'Record AVI' option continues to record the game, untill you press the 'Stop Avi' option. - -File | Quit -Choosing this option exits the emulator. - - - - -Emulation Menu -Emulation | Pause -This option will pause the emulation, freezing it at the current moment of execution. Selecting it again will resume the execution of the ROM at the exact moment where you paused it. - -Emulation | Reset -This option will reset the ROM that is currently loaded to the very start of the ROM, just as if you chose 'File | Open Rom' again. - -Emulation | Shut Up -This option turns off all the sound. - -Emulation | GBA Slot -This menu option pop-ups a new window, which lets you specirfy what to do with the GBA slot of the Nintendo DS. It has the following choices : NONE, Compact Flash, Rumble Pack, GBA Game. Rumble pack allows some games to use vibration. Memory extension... Extends memory. And some DS games can have bonuses, unlockable by GBA cart. For example in Megaman ZX you can fight some Megaman Zero Bosses when correct cartridge is inserted. There are also other GBA slot extensions, like... a Guitar hero controller. But these are currently not emulated by desmume. Flash Cartridge is used for homebrew software emulation, for example that uses DLDI ( Dynamically Linked Device Interface). - -Emulation | Cheats -This option pulls down a drop-down menu, and presents the options list and search. Be aware though, that cheats are sort of half baked right now. If you are not having luck, wait for some news on an improved cheat system. - -Emulation | Cheats | List -Choosing 'list' will list all the currently known cheats. Please refer to the article Using Cheats in DeSmuMe for further details on how to use the cheat mechanism in desmume. - -Emulation | Cheats | Search -Choosing 'search' will let you search for cheats. Please refer to the article Using Cheats in DeSmuMe for further details on how to use the cheat mechanism in desmume. - -View Menu -View | Rotation -This option will let you rotate the screen a pre-determined amount of degrees in order to adjust the angle of the display. Some programs require that you normally turn the DS on its side. You can set it up in that manner using this. The options are 0 (no rotation),90 ,180, and 270. - -View | Window size -This option will let you enlarge the windows a pre-determined size. The resize options are: 1x, 1.5x, 2x, 3x, and 4x the default size. You can also adjust the window size by clicking on the edge of the window, and dragging the mouse. - -View | Screen Separation -This option controls how far the two windows should be apart of each other, in other words: how big the border between them should be. Valid choices are: None (which is the default), narrow border (which is slightly larger), DS (which is about the wsame amount of room there is on a real Nintendo DS). - -View | Force Maintain Ratio -Here you can choose, when re-sizing the windows, if you wan to maintain the ratio of the windows. Sometimes when the window size is changed it doesn't look correct on the screen. This option forces the window to maintain a correct ratio so it looks correct. You can select or de-select this option. - -View | Display Frame Counter -Selecting this option causes a counter to run, that counts all the frames that have been displayed. - -View | Display FPS -Selecting this option causes the 'frames-per-second' (or 'fps', for short) to be displayed. - -View | Display Input -Selecting this option displays the keys you press on the keyboard, which is the input - -View | Display Lag Counter -This option causes a counter to display that counts frames where the game doesn't poll input. - -View | HUD Editing Mode -This option will let you drag around hud elements to pick their position. - - - - -Config Menu -Config | Save Type -This option lets you specify the save type of a particular game. The default is 'automatic'. However, this is not fail-safe in all cases, so you might need to manually select one of the other savetypes. - -Config | 3D Settings -This option lets you select the method that is used to draw the screen. You can choose between OpenGL (an open standard) or SoftRasterizer (a desmume specific method). - -Config | Control Config -This option lets you configure keyboard keys or a joystick. The joystick support is implemented using a DirectInput control interface. - -Config | Hotkey Config -This menu option lets you define keys, that can be used to quickly select other options without having to go through the entire menu structure. Some examples are A hotkey for 'pause', or a hotkey for loading a specific savestate. - -Config | Sound Settings -This option lets you choose between different sound generating methods, which currectly are 'Direct Sound Interface' and 'WAV Write sound Interface'. it also let's you specify the size of the buffer to buffer the sound. - -Config | WIFI Settings -WIFI support is currently under heavy development, but it is not deemed ready for inclusion in the general public releases yet. Therefore, you may find this option missing, or simply 'greyed-out' for now. - -Config | Firmware Settings -This option provides you with the same set of options that a real Nintendo DS firmware does. The most important here is the language, for multi-langual games will often look at how this option is set. - -Config | Emulation Settings -These options let you boot from the extracted BIOS and Firmware of a real Nintendo DS. unless you have extracted/downloaded the firmware or bios from a Nintendo DS that you actually own yourself, these settings have no value for you qas desmume does not require them to run correctly. - -Config | Frame Skip -This option lets you select how many frames should not be displayed, in order to gain speed improvements. The default is 'Auto'. If you have speed problems, you could decide to skip (not display) one or more frames in order to improve the speed. 'Limit Frameskip' let's you limit the frame rate to 60fps maximum. 60fps is essentially the speed that the game plays at on the actual console itself. So by selecting this option, you're limiting the framerate to the actual speed of the actual console. - -Config | Language -This lets you set the langguage the emulator displays it's menu's and options in. - -Tools Menu -Tools | Disassembler -This option displays the ARM9 and ARM7 disassembler. Be aware though, that the windows are drawn exactly on top of each other, so that you have to move (drag n drop) the first windows before the second window shows. - -Tools | View Memory -This tool displays the ARM7 and ARM9 memory. Be aware though, that the windows are drawn exactly on top of each other, so that you have to move (drag n drop) the first windows before the second window shows. - -The "View mode" radio buttons allow you to choose how the memory will be shown: - -8-bit : shows the memory as bytes -16-bit : shows the memory as words -32-bit : shows the memory as dwords -The "View address" textbox and button allow you to jump to a different address: - -Enter an hexadecimal address without 0x prefix, with up to 8 digits -Click "Go" to jump to the entered address -The "View dump" buttons allow you to dump the current view: - -Text dump : dumps the view to a text file, in an human-readable form -Raw dump : dumps the memory directly to a binary file which can be read with an hex editor -Note that if you dump memory to a file already containing (a) dump(s), the new dump will be appended to the existing one(s). - -The scrollbar... well, you surely know how a scrollbar works. - -The viewers additionally allow to edit the memory. For it, click on the value you want to edit, then type the new value. The new value is applied only once you've entirely entered it. - -Tools | View Registers -This option lets you view the ARM7 and ARM9 I/O registers. - -Tools | View Palette -This option lets you view the palette in detail. - -Tools | View Tiles -This option lets you view the tiles in detail. - -Tools | View Maps -This option lets you view the maps in detail. - -Tools | View OAM -This option lets you view the OAM layer in detail. - -Tools | View Matrices -This option lets you view the matrices in detail. - -Tools | View Lights -This option lets you view the lights in detail. - -Tools | View Layers -This option lets you view the Layers one by one. - - - - -Help Menu -Help | Website -This option directs your browser to the desmume homepage. - -Help | Forums -This option directs your browser to the desmume forums. - -Help | Submit a bug report -This option directs your browser to the SourceForge bugtracker for desmume. - -Help | About -This option displays the authors of the emulator. - -Retrieved from "http://wiki.desmume.org/index.php?title=DeSmuME_Manual_for_the_Windows_port - -This page was last modified on 20 April 2009, at 10:45. - -==================================================================== - -Faq - -If the FAQ is unable to answer your question(s), then please make sure that you also consult the manual. - -Contents [hide] -1 General Questions -1.1 What does desmume emulate and on what systems? -1.2 What does DeSmuME mean? -1.3 Why doesn't my desmume play this game? -1.4 Why does this game fail to save? -1.5 Can I use my savefile's acrosss versions ? -1.6 Why can't I find a mac binary? -1.7 Why does my mac binary say something about being unsupported? -1.8 Where can I report bugs? -1.9 Can I attach files to bug reports I did not create myself ? -1.10 How do I get the latest svn code and build desmume myself? -1.11 Whats 'svn' ? -1.12 What compilers are supported for building desmume from source ? -1.13 Im a developer, and would like to contribute to the codebase. What can I do ? -1.14 Im not a developer, but would like to help out anyway. What can I do ? -1.15 It is hard to zoom in on a widescreen display due to the weird aspect ratio of the DS. -1.16 Why doesn't my openGL 3d work in linux? -1.17 Why doesn't my openGL 3d work in windows? -1.18 Why doesn't a menu option or tool exist in my linux or mac build? -1.19 Why does music sound bad sometimes? -1.20 Why doesn't my game boot or progress into the main game engine? -1.21 What hardware features are emulated? -1.22 Does the GDB stub still work? -1.23 Where/what is IRC? -1.24 Where is the manual? -1.25 How do I enter 'cheat codes' in desmume ? -1.26 Why is the emulator slow? -1.27 What are the minimum hardware requirements for desmume ? -1.28 What are the recommended hardware requirements for desmume ? -1.29 Does desmume support wifi ? -1.30 Why do I get an assert in wifi.cpp which keeps me from playing a game? -1.31 OK, then why does it make my firewall alert since 0.9.2 ? -1.32 Does desmume support the microphone ? -1.33 Where can I find technical details on the Nintendo DS and GBA ? -1.34 Does the 'GBA slot' option let me play GBA games ? -1.35 What is DLDI ? -1.36 I get the error: Data could not be accessed. Turn off the power and reinsert the DS card. -1.37 How can I post a screenshot file on the desmume forum ? -1.38 How can I post a savefile or avi capture on the desmume forum ? -1.39 How can I post a large log or other text file on the desmume IRC chat room ? -1.40 My display is incorrect or corrupted -1.41 What are the origins of DeSmuME ? - - -General Questions -What does desmume emulate and on what systems? -Desmume attempts to emulate, as faithfully as possible, the Nintendo DS and Nintendo DS Lite handheld game consoles (nds). It currently runs on Windows, Linux, and mac OSX. DSi is not supported. - -What does DeSmuME mean? -DeSmuME is a Nintendo DS emulator and the name is a play of words - DS Emu + ME (like FlashMe - firmware hack and PassMe mod-chip for DS) The name DeSmuME derives from the popular use of ME in Nintendo DS products by homebrew developers. So DeSmuME would equal DSemuMe. Other popular uses of ME include: - -LoadMe - a generic patcher for commercial DS roms that works with any GBA Flash Card -PassMe - "mod-chip" using which takes authentication from an original DS card an allows execution of unauthenticated DS rom code - from the GBA cartridge slot / GBA flash card. -FlashMe - a hacked firmware for DS that allows you to start code in DS mode from a flash card in the GBA slot. -WifiMe - are a set of a custom drivers and software by FireFly for RALink based wireless network cards enabling to boot homebrew code on DS via Nintendo Wireless Multiboot method. -Why doesn't my desmume play this game? -Go to desmume.org and make sure you are using the latest version. Hint: desmume 0.8 and 0.3.4 are very old. Older versions will not be supported, under any circumstances. -Why does this game fail to save? -Desmume's autodetection for save types is not very good. For now, you need to manually specify the correct save type for your game. Consult the manual for details on how to do this for your platform. We want to fix this, but there are no specific plans so far. You may also consult http://www.advanscene.com/ to easily identify the save type for your game. -Can I use my savefile's acrosss versions ? -Probably not. Due to the constant internal changes sin desmume, it is unlikely that a savefile created with one version will work with another version of desmume -Why can't I find a mac binary? -We have an 0.9.2 mac binary which might not be linked to from the downloads page yet. Go to https://sourceforge.net/project/showfiles.php?group_id=164579&package_id=186413 -Why does my mac binary say something about being unsupported? -There is no universal mac binary. Only i386 is supported. I blame the big endians. If you don't like this, better volunteer yourself to fix endian issues in the code (every day, I see something new that makes me say 'hmmmm that doesnt look endian safe') -Where can I report bugs? -In the official bug tracker; you may also request features around the same location, too, but in the other trackers. -Can I attach files to bug reports I did not create myself ? -SourceForge likes for folks to only respond on items they submit. If you see a ticket that represents something you are encountering, SourceForge doesn't necessarily want you commenting on that. The reasoning for this given by SourceForge is that they feel it is best to open your own ticket, which helps appreciate the extent of issues in many cases. The authors of desmume may or may not agree with this point of view from SourceForge. -How do I get the latest svn code and build desmume myself? -Please check out the instructions related to your platform, over at Installing DeSmuME from source -Whats 'svn' ? -svn is a developers tool. It's used to let multiple developers work on the same codebase without conflicts. If youre an end-user, don't worry about it. And if you're a developer, see the question on how to get the latest svn code and build desmume yourself. See wikipedia for more info - -What compilers are supported for building desmume from source ? -At the moment, for Windows Microsoft Visual C++ 2005 and 2008 are the only supported compilers. Dev-c++ is not supported. Why won't you just download visual c++ express? -For Linux, any recent version of GCC and toolchain should work. -Im a developer, and would like to contribute to the codebase. What can I do ? -To start you off in the right direction, the best thing you can do is join the developer team on IRC and discuss your intentions with the developers. - -Im not a developer, but would like to help out anyway. What can I do ? -The most helpful thing you can do is use it, learn its ins and outs, and learn how to compile svn builds. Then monitor it for regressions and report bugs. You can patrol the bug tracker for bugs which could use elucidation or which, based on your awareness of how the emulator is changing, might be fixed without us having specifically addressed the bug. Basically, be a super user. And hang out on irc. Also, adding to or perfecting the documentation in the wiki is usefull. You could also watch for and answer questions placed on the desmume forum. - -It is hard to zoom in on a widescreen display due to the weird aspect ratio of the DS. -In fact it is hard to zoom in on a 4:3 screen, too. Proposals involve tearing apart windows and floating them side by side or separately or something. This may happen one day, in the form of side by side windows. - -Why doesn't my openGL 3d work in linux? -Blame nvidia and ati for putting out shoddy drivers. Then switch to software rasterizer. - -Why doesn't my openGL 3d work in windows? -You are probably using an ATI video card. ATI driver support of OpenGL is known to be poor. Get an nvidia. Do not argue with that, we are professional programmers and know what we're talking about. Or, switch to software rasterizer - -Why doesn't a menu option or tool exist in my linux or mac build? -Because making portable tools and platform harnesses are not our cup of tea and so a developer puts a feature into whichever ports he cares about. This policy is never going to change, although some features might migrate to other platforms over time. Better check the manual. - -Why does music sound bad sometimes? -Most DS music is sequenced music, loaded from the cart to the ARM7 entirely when the level loads. This works fine. Your music that doesn't work is probably streaming music, which loads from the cart on the fly and goes straight to the speakers. This is much harder to emulate as it requires correct timing, which is not one of desmume's strengths right now. This may not be fixed for a while. - -Why doesn't my game boot or progress into the main game engine? -Desmume is not perfect yet. Some games may fail due to wifi emulation. Apparently if you search the web correctly you can find ways to patch games to work better on emulators. - -What hardware features are emulated? -All known 2d graphics features are correct. Mosaics work but are imperfect. There may be small issues with colors as the correct color bit depths are not used at all points in the pipeline. -All 3d features are emulated, except for: tests, wireframes, edge marking, fog, and antialising. The opengl engine is near its limit and renders some things incorrectly. Eventually the software rasterizer (will support more features and be far more precise in the basic features. Both engines have trouble with some shadows, but software rasterizer is better. Software rasterizer has some noticeable texturing issues right now, especially in 2d games. Software rasterizer supports more correct lighting interpolation than opengl ever will (e.g. glitches at the edge of the screen while scrolling.) In software rasterizer, there are issues similar to 2d with incorrect bit depth being used in the pipeline. There are inaccurate edge conditions in each renderer; in opengl, textures tend to get overdrawn; in software rasterizer, edges of textures tend to be jittery. -One last thing -- if buttons and labels and menus rendering on the 3d screen are obscured (for example, a button but no label is on it) then you may need to use the software rasterizer. - -All sound features are emulated. The microphone support is new and the manual should be consulted, where you will find out, among other things, that it is only supported in windows right now. -Wifi is not supported. It is currently under slow and incomplete development. Therefore, you may find this option missing, or simply 'greyed-out' for now. Also, since WIFI support does not work yet, don't ask any questions about it's functioning because it still is unfinished and does not work yet. -We are unaware of any outstanding issues in the core system hardware (cpu, dma, mmu) but there are certainly still some. The instruction and memory timings are quite incorrect; however, this seems not to hurt most softwares. -DLDI does anybody know if this still works? -Dynamically Linked Driver Interface, commonly known as DLDI, is a driver framework that allows NDS and GBA homebrew to easily read and write to any number of different devices, just by substituting a driver file. -RTC (real-time clock) works; This is what makes the time in your games stay at 00:00:00, and what makes your random number values always come up the same. -Does the GDB stub still work? -This has not been built into the public releases, nor has the feature been tested in a while. If you want to be a test user, please hop on IRC and coordinate with us. - -Where/what is IRC? -IRC is an on-line communication system. - -data you need: - -server: irc.freenode.net -port: 6667 -channel: #desmume -what to use: - -mIRC - windows -ChatZilla - FireFox add-on -xchat - X -plenty other, see wikipedia -Where is the manual? -A manual for desmume is over at http://wiki.desmume.org/index.php?title=Manual. It may not have the information that other entries in this FAQ promised that it would. - -How do I enter 'cheat codes' in desmume ? -It is impossible yet to use "commercial" codes, such as Action Replay and Codebreaker, so what you'll have to do is manually search for, and alter the memory positions to your advantage. There's an excellent article in the wiki on Using Cheats in DeSmuMe - -Why is the emulator slow? -Because nobody pays us to work on it full time and it runs fast enough for us to be happy. Well, almost. The cheapest way to get 60fps is to buy the cart. Buying a newer, faster computer is somewhat more expensive, and it has other side benefits. Also, if you are in Windows, make sure you have tried the SSE build which helps a little bit. Additionally, if you are using someone else's interim build it might not be fully optimized since we make our Windows releases using some profiler-guided optimization which helps by several FPS. You could try turning off the sound. And one last thing: try a new video card. But only as long as it is an nvidia. Also, a faster CPU is more helpfull than a bleeding edge graphics card. desmume is more CPU intensive than it is GPU intensive. It just needs a graphics card that is glitch-free, and currently the nvidia cards have a better track record. - -What are the minimum hardware requirements for desmume ? -From a purely technical viewpoint, there are no minimum requirements. However, for 'real-world' playable speeds, you would need at least the following : - -Windows OS: Windows XP or Vista -Linux OS: Any recent Linux distribution with a 2.6 kernel. -2 GHz Processor -512 MB Available System Memory -Available Hard Drive Space: A few MB for desmume, and several GB for the nds files. -128 MB 3D Video Card (Nvidia GeForce 6800 or better), ATI cards are not recommended. -Optional: Sound Card, if you want sound support -Optional: Microphone, if you wish to make use the Windows Microphone feature -What are the recommended hardware requirements for desmume ? -From a purely technical viewpoint, there are no recommended requirements. However, for 'real-world' playable speeds, the following gives you good performance: - -Windows OS: Windows XP or Vista -Linux OS: Any recent Linux distribution with a 2.6 kernel. -3 GHz Processor -1 GB Available System Memory -Available Hard Drive Space: A few MB for desmume, and lots of GB's for the nds files. -512 MB 3D Video Card (Nvidia GeForce), ATI cards are not recommended. -Sound Card. -Microphone. -Does desmume support wifi ? -Wifi is not supported. It is currently under slow and incomplete development. Therefore, you may find this option missing, or simply 'greyed-out' for now. Also, since WIFI support does not work yet, don't ask any questions about it's functioning because it still is unfinished and does not work yet. Furthermore, current development activities focus mainly on the Windows build. - -Why do I get an assert in wifi.cpp which keeps me from playing a game? -This was a glitch in 0.9.2 release. The download package has been replaced. Download it again and check the changelog to see if you have the fixed version. - -OK, then why does it make my firewall alert since 0.9.2 ? -Your firewall is stupid, or winsock is stupid, (I am not sure which yet) for alerting just when winsock gets initialized. The emulator hasnt actually tried to connect to the internet yet. How could it? There isn't any wifi. All we are doing is some network initialization code. For those of you who are still not satisfied, then I will admit that there is actually some wifi code--but it doesnt actually do anything yet! Except alert your firewall. Sorry. Also, maybe that is actually a good, unobtrusive time for firewalls to alert. But I am not sorry for calling them stupid. They are hyperactive crybabies. - -Does desmume support the microphone ? -Yes, but only on the Windows port. You do have to have an actual microphone attached to your PC, though. And perhaps somewhat confusing, the Linux ports do report 'Microphone successfully initialized' on startup of the emulator - but currently this is just a piece of stub (dummy) code used only to correctly start the emulator. - -Where can I find technical details on the Nintendo DS and GBA ? -http://nocash.emubase.de/gbatek.htm - -Does the 'GBA slot' option let me play GBA games ? -No. A 'real' Nintendo DS can use the gba slot to play gba games, but desmume does not emulate this. But a 'real' Nintnedo DS can also use the gba slot to access gba roms and sram so that ds games can import savefiles, and that part is emulated by desmume. If you are looking for a Game Boy Advance (GBA) emulator, perhaps you can try mednafen or visualboy advance. - -What is DLDI ? -let me give you an overview on DLDI. You should know that there are many various flash cartridges for DS. They use different file allocation systems, different storages, etc. They are used for launching homebrew. So to make one proram run on all cards. You’d have to write support for each and every card so that it worked for everyone. But none needs support for other cards than their And then genial solution was found. There was an universal IO unit made that’s just interface to IO operations. If you don't have a DS, why do you bother with desmume ? You surely don't have bought any game to run on it. And compiled program does not know how to handle file system etc. And then user can append IO routines for his own card. “DLDI patch”. So, now when I have an M3 cart. I download rom, patch it with m3 DLDI patch. And it works on my cart. Say you had Supercard instead. You’d have to download very same rom and apply Supercart DLDI patch to it. DLDI patch is the same for all roms. So it’s easy for both developper and end user. - -I get the error: Data could not be accessed. Turn off the power and reinsert the DS card. -The automatic savetype detection probably failed to detect the correct savetype, and you have to set it manually to the correct type. If you are lucky, information about your game (and the corresponding savetype) can be found on a website such as http://www.advanscene.com/. And if you're not as lucky, you'll just have to try them all out until you find the correct type. - -How can I post a screenshot file on the desmume forum ? -You can create a screenshot, and then upload it to a free external service provider like ImageShack (http://imageshack.us/), and then put the provided links to the page in the message you post on the forum. - -How can I post a savefile or avi capture on the desmume forum ? -After you created it, yo can upload it to a free external service provider like MediaFire (http://www.mediafire.com/), and then put the provided links to the page in the message you post on the forum. - -How can I post a large log or other text file on the desmume IRC chat room ? -Make use of the external service provider 'pastebin' (http://pastebin.com/), and post the url to it on the IRC channel. - -My display is incorrect or corrupted -Try switching the 3D Renderer from opengl or SoftRasterizer, or vice versa, to see if that resolves the bug. In windows, the default hotkey to do this quickly is numpad minus. - -What are the origins of DeSmuME ? -DeSmuME is a freeware emulator for the Nintendo DS created by YopYop156. - -Due to change in French laws regarding emulation YopYop has decided to stop development of DeSmuME Nintendo DS emulator but that doesn't mean that DeSmuME is obsolete - programmers in this project have picked up where Yopyop left off. The original website was http://yopyop156.ifrance.com/. - -Yopyop said: - -It’s release under GPL. I have just removed the new 3D engine because it’s too much bugged. Hopefully it will be helpful for some of you. - -The latest statement heard from yopyop was : - -DeSmuMe project is over. -You may don’t know but there are a new law in France that could put me in big trouble. -With DeSmuMe, I have closed the doors of game company but I can not offer to pay for it. -The worst thing is that I have found the bad coded instructions. -For those how have download the sources you have to look in sbc, rsbc instructions the Carry flag updating is wrong. -Sorry for the home brew programmers. -For the illegality the demonstration seemed to me convincing thus without proof clarify I prefer to stick to this decision. -It is also the fact that few people seem interested by the project. Put besides some people who sent demonstrations to me which did not go, I received only malls to wonder to make function such or such plays or to ask me why moved is in French . -Thus I will not do something of useless and illegal. -For the site it would not obstruct me if there were not the bond on the left which does nothing but add to confusion on the goal of the project. -And for the sources it is the same problem as for the project. -good week end -yopyop -edit the law relates to the royalties and the rights close, not? - -Retrieved from "http://wiki.desmume.org/index.php?title=Faq" diff --git a/desmume/faq.htm b/desmume/faq.htm deleted file mode 100644 index 9f8486754..000000000 --- a/desmume/faq.htm +++ /dev/null @@ -1,432 +0,0 @@ - - - - - - - - - - - Faq - DeSmuME - - - - - - - - - - - - - - - - - -
-
-
- -

Faq

-
-

From DeSmuME

-
-
Jump to: navigation, search
-

DesMuMe Faq -

If the FAQ is unable to answer your question(s), then please make sure that you also consult the manual. -

-

Contents

- -
-

[edit] General Questions

-

[edit] What does desmume emulate and on what systems?

-

Desmume attempts to emulate, as faithfully as possible, the Nintendo DS and Nintendo DS Lite handheld game consoles (nds). It currently runs on Windows, Linux, and mac OSX. DSi is not supported. -

-

[edit] What does DeSmuME mean?

-

DeSmuME is a Nintendo DS emulator and the name is a play of words - DS Emu + ME (like FlashMe - firmware hack and PassMe mod-chip for DS) -The name DeSmuME derives from the popular use of ME in Nintendo DS products by homebrew developers. So DeSmuME would equal DSemuMe. Other popular uses of ME include: -

-
  • LoadMe - a generic patcher for commercial DS roms that works with any GBA Flash Card -
  • PassMe - "mod-chip" using which takes authentication from an original DS card an allows execution of unauthenticated DS rom code - from the GBA cartridge slot / GBA flash card. -
  • FlashMe - a hacked firmware for DS that allows you to start code in DS mode from a flash card in the GBA slot. -
  • WifiMe - are a set of a custom drivers and software by FireFly for RALink based wireless network cards enabling to boot homebrew code on DS via Nintendo Wireless Multiboot method. -
-

[edit] Why doesn't my desmume play this game?

-
  • Go to desmume.org and make sure you are using the latest version. Hint: desmume 0.8 and 0.3.4 are very old. Older versions will not be supported, under any circumstances. -
-

[edit] Why does this game fail to save?

-
  • Desmume's autodetection for save types is not very good. For now, you need to manually specify the correct save type for your game. Consult the manual for details on how to do this for your platform. We want to fix this, but there are no specific plans so far. You may also consult http://www.advanscene.com/ to easily identify the save type for your game. -
-

[edit] Can I use my savefile's acrosss versions ?

-
  • Probably not. Due to the constant internal changes sin desmume, it is unlikely that a savefile created with one version will work with another version of desmume -
-

[edit] Why can't I find a mac binary?

- -

[edit] Why does my mac binary say something about being unsupported?

-
  • There is no universal mac binary. Only i386 is supported. I blame the big endians. If you don't like this, better volunteer yourself to fix endian issues in the code (every day, I see something new that makes me say 'hmmmm that doesnt look endian safe') -
-

[edit] Where can I report bugs?

-
  • In the official bug tracker; you may also request features around the same location, too, but in the other trackers. -
-

[edit] Can I attach files to bug reports I did not create myself ?

-
  • SourceForge likes for folks to only respond on items they submit. If you see a ticket that represents something you are encountering, SourceForge doesn't necessarily want you commenting on that. The reasoning for this given by SourceForge is that they feel it is best to open your own ticket, which helps appreciate the extent of issues in many cases. The authors of desmume may or may not agree with this point of view from SourceForge. -
-

[edit] How do I get the latest svn code and build desmume myself?

- -

[edit] Whats 'svn' ?

-

svn is a developers tool. It's used to let multiple developers work on the same codebase without conflicts. If youre an end-user, don't worry about it. And if you're a developer, see the question on how to get the latest svn code and build desmume yourself. See wikipedia for more info -

-

[edit] What compilers are supported for building desmume from source ?

-
  • At the moment, for Windows Microsoft Visual C++ 2005 and 2008 are the only supported compilers. Dev-c++ is not supported. Why won't you just download visual c++ express? -
  • For Linux, any recent version of GCC and toolchain should work. -
-

[edit] Im a developer, and would like to contribute to the codebase. What can I do ?

-

To start you off in the right direction, the best thing you can do is join the developer team on IRC and discuss your intentions with the developers. -

-

[edit] Im not a developer, but would like to help out anyway. What can I do ?

-

The most helpful thing you can do is use it, learn its ins and outs, and learn how to compile svn builds. Then monitor it for regressions and report bugs. You can patrol the bug tracker for bugs which could use elucidation or which, based on your awareness of how the emulator is changing, might be fixed without us having specifically addressed the bug. Basically, be a super user. And hang out on irc. Also, adding to or perfecting the documentation in the wiki is usefull. You could also watch for and answer questions placed on the desmume forum. -

-

[edit] It is hard to zoom in on a widescreen display due to the weird aspect ratio of the DS.

-

In fact it is hard to zoom in on a 4:3 screen, too. Proposals involve tearing apart windows and floating them side by side or separately or something. This may happen one day, in the form of side by side windows. -

-

[edit] Why doesn't my openGL 3d work in linux?

-

Blame nvidia and ati for putting out shoddy drivers. Then switch to software rasterizer. -

-

[edit] Why doesn't my openGL 3d work in windows?

-

You are probably using an ATI video card. ATI driver support of OpenGL is known to be poor. Get an nvidia. Do not argue with that, we are professional programmers and know what we're talking about. Or, switch to software rasterizer -

-

[edit] Why doesn't a menu option or tool exist in my linux or mac build?

-

Because making portable tools and platform harnesses are not our cup of tea and so a developer puts a feature into whichever ports he cares about. This policy is never going to change, although some features might migrate to other platforms over time. Better check the manual. -

-

[edit] Why does music sound bad sometimes?

-

Most DS music is sequenced music, loaded from the cart to the ARM7 entirely when the level loads. This works fine. Your music that doesn't work is probably streaming music, which loads from the cart on the fly and goes straight to the speakers. This is much harder to emulate as it requires correct timing, which is not one of desmume's strengths right now. This may not be fixed for a while. -

-

[edit] Why doesn't my game boot or progress into the main game engine?

-

Desmume is not perfect yet. Some games may fail due to wifi emulation. Apparently if you search the web correctly you can find ways to patch games to work better on emulators. -

-

[edit] What hardware features are emulated?

-
  • All known 2d graphics features are correct. Mosaics work but are imperfect. There may be small issues with colors as the correct color bit depths are not used at all points in the pipeline. -
-
  • All 3d features are emulated, except for: tests, wireframes, edge marking, fog, and antialising. The opengl engine is near its limit and renders some things incorrectly. Eventually the software rasterizer (will support more features and be far more precise in the basic features. Both engines have trouble with some shadows, but software rasterizer is better. Software rasterizer has some noticeable texturing issues right now, especially in 2d games. Software rasterizer supports more correct lighting interpolation than opengl ever will (e.g. glitches at the edge of the screen while scrolling.) In software rasterizer, there are issues similar to 2d with incorrect bit depth being used in the pipeline. There are inaccurate edge conditions in each renderer; in opengl, textures tend to get overdrawn; in software rasterizer, edges of textures tend to be jittery. -
-

One last thing -- if buttons and labels and menus rendering on the 3d screen are obscured (for example, a button but no label is on it) then you may need to use the software rasterizer. -

-
  • All sound features are emulated. The microphone support is new and the manual should be consulted, where you will find out, among other things, that it is only supported in windows right now. -
-
  • Wifi is not supported. It is currently under slow and incomplete development. Therefore, you may find this option missing, or simply 'greyed-out' for now. Also, since WIFI support does not work yet, don't ask any questions about it's functioning because it still is unfinished and does not work yet. -
-
  • We are unaware of any outstanding issues in the core system hardware (cpu, dma, mmu) but there are certainly still some. The instruction and memory timings are quite incorrect; however, this seems not to hurt most softwares. -
-
  • DLDI does anybody know if this still works? -
-
Dynamically Linked Driver Interface, commonly known as DLDI, is a driver framework that allows NDS and GBA homebrew to easily read and write to any number of different devices, just by substituting a driver file. -
-
  • RTC (real-time clock) works; This is what makes the time in your games stay at 00:00:00, and what makes your random number values always come up the same. -
-

[edit] Does the GDB stub still work?

-

This has not been built into the public releases, nor has the feature been tested in a while. If you want to be a test user, please hop on IRC and coordinate with us. -

-

[edit] Where/what is IRC?

-

IRC is an on-line communication system. -

data you need: -

-
  • server: irc.freenode.net -
  • port: 6667 -
  • channel: #desmume -
-

what to use: -

-
  • mIRC - windows -
  • ChatZilla - FireFox add-on -
  • xchat - X -
  • plenty other, see wikipedia -
-

[edit] Where is the manual?

-

A manual for desmume is over at http://wiki.desmume.org/index.php?title=Manual. It may not have the information that other entries in this FAQ promised that it would. -

-

[edit] How do I enter 'cheat codes' in desmume ?

-

It is impossible yet to use "commercial" codes, such as Action Replay and Codebreaker, so what you'll have to do is manually search for, and alter the memory positions to your advantage. There's an excellent article in the wiki on Using Cheats in DeSmuMe -

-

[edit] Why is the emulator slow?

-

Because nobody pays us to work on it full time and it runs fast enough for us to be happy. Well, almost. The cheapest way to get 60fps is to buy the cart. Buying a newer, faster computer is somewhat more expensive, and it has other side benefits. Also, if you are in Windows, make sure you have tried the SSE build which helps a little bit. Additionally, if you are using someone else's interim build it might not be fully optimized since we make our Windows releases using some profiler-guided optimization which helps by several FPS. You could try turning off the sound. And one last thing: try a new video card. But only as long as it is an nvidia. Also, a faster CPU is more helpfull than a bleeding edge graphics card. desmume is more CPU intensive than it is GPU intensive. It just needs a graphics card that is glitch-free, and currently the nvidia cards have a better track record. -

-

[edit] What are the minimum hardware requirements for desmume ?

-

From a purely technical viewpoint, there are no minimum requirements. However, for 'real-world' playable speeds, you would need at least the following : -

-
  • Windows OS: Windows XP or Vista -
  • Linux OS: Any recent Linux distribution with a 2.6 kernel. -
  • 2 GHz Processor -
  • 512 MB Available System Memory -
  • Available Hard Drive Space: A few MB for desmume, and several GB for the nds files. -
  • 128 MB 3D Video Card (Nvidia GeForce 6800 or better), ATI cards are not recommended. -
  • Optional: Sound Card, if you want sound support -
  • Optional: Microphone, if you wish to make use the Windows Microphone feature -
-

[edit] What are the recommended hardware requirements for desmume ?

-

From a purely technical viewpoint, there are no recommended requirements. However, for 'real-world' playable speeds, the following gives you good performance: -

-
  • Windows OS: Windows XP or Vista -
  • Linux OS: Any recent Linux distribution with a 2.6 kernel. -
  • 3 GHz Processor -
  • 1 GB Available System Memory -
  • Available Hard Drive Space: A few MB for desmume, and lots of GB's for the nds files. -
  • 512 MB 3D Video Card (Nvidia GeForce), ATI cards are not recommended. -
  • Sound Card. -
  • Microphone. -
-

[edit] Does desmume support wifi ?

-

Wifi is not supported. It is currently under slow and incomplete development. Therefore, you may find this option missing, or simply 'greyed-out' for now. Also, since WIFI support does not work yet, don't ask any questions about it's functioning because it still is unfinished and does not work yet. Furthermore, current development activities focus mainly on the Windows build. -

-

[edit] Why do I get an assert in wifi.cpp which keeps me from playing a game?

-

This was a glitch in 0.9.2 release. The download package has been replaced. Download it again and check the changelog to see if you have the fixed version. -

-

[edit] OK, then why does it make my firewall alert since 0.9.2 ?

-

Your firewall is stupid, or winsock is stupid, (I am not sure which yet) for alerting just when winsock gets initialized. The emulator hasnt actually tried to connect to the internet yet. How could it? There isn't any wifi. All we are doing is some network initialization code. For those of you who are still not satisfied, then I will admit that there is actually some wifi code--but it doesnt actually do anything yet! Except alert your firewall. Sorry. Also, maybe that is actually a good, unobtrusive time for firewalls to alert. But I am not sorry for calling them stupid. They are hyperactive crybabies. -

-

[edit] Does desmume support the microphone ?

-

Yes, but only on the Windows port. You do have to have an actual microphone attached to your PC, though. And perhaps somewhat confusing, the Linux ports do report 'Microphone successfully initialized' on startup of the emulator - but currently this is just a piece of stub (dummy) code used only to correctly start the emulator. -

-

[edit] Where can I find technical details on the Nintendo DS and GBA ?

-

http://nocash.emubase.de/gbatek.htm -

-

[edit] Does the 'GBA slot' option let me play GBA games ?

-

No. A 'real' Nintendo DS can use the gba slot to play gba games, but desmume does not emulate this. But a 'real' Nintnedo DS can also use the gba slot to access gba roms and sram so that ds games can import savefiles, and that part is emulated by desmume. If you are looking for a Game Boy Advance (GBA) emulator, perhaps you can try mednafen or visualboy advance. -

-

[edit] What is DLDI ?

-

let me give you an overview on DLDI. You should know that there are many various flash cartridges for DS. They use different file allocation systems, different storages, etc. They are used for launching homebrew. So to make one proram run on all cards. You’d have to write support for each and every card so that it worked for everyone. But none needs support for other cards than their -And then genial solution was found. There was an universal IO unit made that’s just interface to IO operations. If you don't have a DS, why do you bother with desmume ? You surely don't have bought any game to run on it. And compiled program does not know how to handle file system etc. And then user can append IO routines for his own card. “DLDI patch”. So, now when I have an M3 cart. I download rom, patch it with m3 DLDI patch. And it works on my cart. Say you had Supercard instead. You’d have to download very same rom and apply Supercart DLDI patch to it. DLDI patch is the same for all roms. So it’s easy for both developper and end user. -

-

[edit] I get the error: Data could not be accessed. Turn off the power and reinsert the DS card.

-

The automatic savetype detection probably failed to detect the correct savetype, and you have to set it manually to the correct type. If you are lucky, information about your game (and the corresponding savetype) can be found on a website such as http://www.advanscene.com/. And if you're not as lucky, you'll just have to try them all out until you find the correct type. -

-

[edit] How can I post a screenshot file on the desmume forum ?

-

You can create a screenshot, and then upload it to a free external service provider like ImageShack (http://imageshack.us/), and then put the provided links to the page in the message you post on the forum. -

-

[edit] How can I post a savefile or avi capture on the desmume forum ?

-

After you created it, yo can upload it to a free external service provider like MediaFire (http://www.mediafire.com/), and then put the provided links to the page in the message you post on the forum. -

-

[edit] How can I post a large log or other text file on the desmume IRC chat room ?

-

Make use of the external service provider 'pastebin' (http://pastebin.com/), and post the url to it on the IRC channel. -

-

[edit] My display is incorrect or corrupted

-

Try switching the 3D Renderer from opengl or SoftRasterizer, or vice versa, to see if that resolves the bug. In windows, the default hotkey to do this quickly is numpad minus. -

-

[edit] What are the origins of DeSmuME ?

-

DeSmuME is a freeware emulator for the Nintendo DS created by YopYop156. -

Due to change in French laws regarding emulation YopYop has decided to stop development of DeSmuME Nintendo DS emulator but that doesn't mean that DeSmuME is obsolete - programmers in this project have picked up where Yopyop left off. The original website was http://yopyop156.ifrance.com/. -

Yopyop said: -

-
It’s release under GPL. I have just removed the new 3D engine because it’s too much bugged. Hopefully it will be helpful for some of you. -
-


-The latest statement heard from yopyop was : -

-
DeSmuMe project is over. -
You may don’t know but there are a new law in France that could put me in big trouble. -
With DeSmuMe, I have closed the doors of game company but I can not offer to pay for it. -
-
The worst thing is that I have found the bad coded instructions. -
For those how have download the sources you have to look in sbc, rsbc instructions the Carry flag updating is wrong. -
Sorry for the home brew programmers. -
-
For the illegality the demonstration seemed to me convincing thus without proof clarify I prefer to stick to this decision. -
-
It is also the fact that few people seem interested by the project. Put besides some people who sent demonstrations to me which did not go, I received only malls to wonder to make function such or such plays or to ask me why moved is in French . -
Thus I will not do something of useless and illegal. -
-
For the site it would not obstruct me if there were not the bond on the left which does nothing but add to confusion on the goal of the project. -
-
And for the sources it is the same problem as for the project. -
-
good week end -
-
yopyop -
-
edit the law relates to the royalties and the rights close, not? -
- - - - - - -
-
-
-
-
-
-
Views
-
- -
-
-
-
Personal tools
- -
- - - - - -
-
- -
- - - - - diff --git a/desmume/src/gtk/main.cpp b/desmume/src/gtk/main.cpp deleted file mode 100644 index d62b50a36..000000000 --- a/desmume/src/gtk/main.cpp +++ /dev/null @@ -1,1746 +0,0 @@ -/* main.c - this file is part of DeSmuME - * - * Copyright (C) 2006,2007 DeSmuME Team - * Copyright (C) 2007 Pascal Giard (evilynux) - * - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This file is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef GTK_UI -#define GTK_UI -#endif - -#include -#include -#include -#include -#include - -#include "types.h" -#include "armcpu.h" -#include "NDSSystem.h" -#include "sndsdl.h" -#include "ctrlssdl.h" -#include "MMU.h" -#include "render3D.h" -#include "desmume.h" -#include "debug.h" -#include "rasterize.h" -#include "saves.h" -#include "mic.h" - -#ifdef GDB_STUB -#include "gdbstub.h" -#endif - -#ifdef HAVE_LIBOSMESA -#include -#include -#include "OGLRender.h" -#include "osmesa_3Demu.h" -#endif - -#include "DeSmuME.xpm" - -#define EMULOOP_PRIO (G_PRIORITY_HIGH_IDLE + 20) - -#include - -static int backupmemorytype=MC_TYPE_AUTODETECT; -static u32 backupmemorysize=1; - -static const char *bad_glob_cflash_disk_image_file; - -#define SCREENS_PIXEL_SIZE (256*192*2) - -#define FPS_LIMITER_FRAME_PERIOD 8 -static SDL_sem *fps_limiter_semaphore; -static int gtk_fps_limiter_disabled; - -const u16 gtk_kb_cfg[NB_KEYS] = - { - GDK_x, // A - GDK_z, // B - GDK_Shift_R, // select - GDK_Return, // start - GDK_Right, // Right - GDK_Left, // Left - GDK_Up, // Up - GDK_Down, // Down - GDK_w, // R - GDK_q, // L - GDK_s, // X - GDK_a, // Y - GDK_p, // DEBUG - GDK_o // BOOST - }; - -enum { - MAIN_BG_0 = 0, - MAIN_BG_1, - MAIN_BG_2, - MAIN_BG_3, - MAIN_OBJ, - SUB_BG_0, - SUB_BG_1, - SUB_BG_2, - SUB_BG_3, - SUB_OBJ -}; - -/************************ CONFIG FILE *****************************/ - -static void Open_Select(); -static void Launch(); -static void Pause(); -static void Printscreen(); -static void Reset(); -static void Edit_Controls(); -static void MenuSave(GtkMenuItem *item, gpointer slot); -static void MenuLoad(GtkMenuItem *item, gpointer slot); -static void About(); -static void desmume_gtk_disable_audio (GtkToggleAction *action); -static void desmume_gtk_mic_noise (GtkToggleAction *action); -static void SetRotation (GtkAction *action, gpointer data); -static void Modify_Layer(GtkToggleAction* action, gpointer data); -#ifdef DESMUME_GTK_FIRMWARE_BROKEN -static void SelectFirmwareFile(); -#endif - -static const char *ui_description = -"" -" " -" " -" " -//" " -//" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -#ifdef GTK_DESMUME_FIRMWARE_BROKEN -" " -#endif -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -" " -""; - -static const GtkActionEntry action_entries[] = { - { "FileMenu", NULL, "_File" }, - { "open", "gtk-open", "_Open", "o", NULL, Open_Select }, -// { "savestateto", NULL, "S_ave state as ...", NULL, NULL, Open_Select }, -// { "loadstatefrom", NULL, "Load state f_rom ...", NULL, NULL, Open_Select }, - { "SavestateMenu", NULL, "Sa_ve state" }, - { "LoadstateMenu", NULL, "_Load state" }, -#ifdef DESMUME_GTK_FIRMWARE_BROKEN - { "loadfirmware","gtk-open", "_Load Firmware file", "l", NULL, SelectFirmwareFile }, -#endif - { "printscreen","gtk-media-record", "Take a _screenshot", "s", NULL, Printscreen }, - { "quit", "gtk-quit", "_Quit", "q", NULL, gtk_main_quit }, - - { "EmulationMenu", NULL, "_Emulation" }, - { "run", "gtk-media-play", "_Run", "r", NULL, Launch }, - { "pause", "gtk-media-pause", "_Pause", "p", NULL, Pause }, - { "reset", "gtk-refresh", "Re_set", NULL, NULL, Reset }, - { "FrameskipMenu", NULL, "_Frameskip" }, - { "LayersMenu", NULL, "_Layers" }, - - { "ConfigMenu", NULL, "_Config" }, - { "ConfigSaveMenu", NULL, "_Saves" }, - { "editctrls", NULL, "_Edit controls",NULL, NULL, Edit_Controls }, - { "RotationMenu", NULL, "_Rotation" }, - { "rotate_0", "gtk-orientation-portrait", "_0", NULL, NULL, G_CALLBACK(SetRotation) }, - { "rotate_90", "gtk-orientation-landscape", "_90", NULL, NULL, G_CALLBACK(SetRotation) }, - { "rotate_180", "gtk-orientation-reverse-portrait", "_180",NULL, NULL, G_CALLBACK(SetRotation) }, - { "rotate_270", "gtk-orientation-reverse-landscape", "_270",NULL, NULL, G_CALLBACK(SetRotation) }, - { "InterpolationMenu", NULL, "_Interpolation" }, - - { "ToolsMenu", NULL, "_Tools" }, - - { "HelpMenu", NULL, "_Help" }, - { "about", "gtk-about", "_About", NULL, NULL, About } -}; - -static const GtkToggleActionEntry toggle_entries[] = { - { "enableaudio", NULL, "_Enable audio", NULL, NULL, G_CALLBACK(desmume_gtk_disable_audio), TRUE}, - { "micnoise", NULL, "Fake _mic noise", NULL, NULL, G_CALLBACK(desmume_gtk_mic_noise), FALSE} -}; - -static const GtkRadioActionEntry interpolation_entries[] = { - { "interp_nearest", NULL, "_Nearest", NULL, NULL, 0}, - { "interp_bilinear", NULL, "_Bilinear", NULL, NULL, 1}, -}; - -static const GtkRadioActionEntry frameskip_entries[] = { - { "frameskip0", NULL, "_0", NULL, NULL, 0}, - { "frameskip1", NULL, "_1", NULL, NULL, 1}, - { "frameskip2", NULL, "_2", NULL, NULL, 2}, - { "frameskip3", NULL, "_3", NULL, NULL, 3}, - { "frameskip4", NULL, "_4", NULL, NULL, 4}, - { "frameskip5", NULL, "_5", NULL, NULL, 5}, - { "frameskip6", NULL, "_6", NULL, NULL, 6}, - { "frameskip7", NULL, "_7", NULL, NULL, 7}, - { "frameskip8", NULL, "_8", NULL, NULL, 8}, - { "frameskip9", NULL, "_9", NULL, NULL, 9}, -}; - -static const GtkRadioActionEntry savet_entries[] = { - { "save_t0", NULL, "_0 Autodetect", NULL, NULL, 0}, - { "save_t1", NULL, "_1 EEPROM 4kbit", NULL, NULL, 1}, - { "save_t2", NULL, "_2 EEPROM 64kbit", NULL, NULL, 2}, - { "save_t3", NULL, "_3 EEPROM 512kbit", NULL, NULL, 3}, - { "save_t4", NULL, "_4 FRAM 256kbit", NULL, NULL, 4}, - { "save_t5", NULL, "_5 FLASH 2mbit", NULL, NULL, 5}, - { "save_t6", NULL, "_6 FLASH 4mbit", NULL, NULL, 6} -}; - -SoundInterface_struct *SNDCoreList[] = { -&SNDDummy, -&SNDFile, -&SNDSDL, -NULL -}; - -GPU3DInterface *core3DList[] = { - &gpu3DNull, - &gpu3DRasterize -#if defined(HAVE_LIBOSMESA) - , - &gpu3Dgl -#endif -}; - -static u16 Cur_Keypad = 0; -static u16 gdk_shift_pressed = 0; - -struct configured_features { - int load_slot; - - int disable_sound; - int engine_3d; - int disable_limiter; - int savetype; - - int arm9_gdb_port; - int arm7_gdb_port; - - int firmware_language; - - const char *nds_file; - const char *cflash_disk_image_file; -}; - -static void -init_configured_features( struct configured_features *config) -{ - config->load_slot = 0; - - config->arm9_gdb_port = 0; - config->arm7_gdb_port = 0; - - config->disable_sound = 0; - - config->engine_3d = 1; - - config->disable_limiter = 0; - - config->nds_file = NULL; - config->savetype = 0; - - config->cflash_disk_image_file = NULL; - - /* use the default language */ - config->firmware_language = -1; -} - -static int -fill_configured_features( struct configured_features *config, - int argc, char ** argv) -{ - GOptionEntry options[] = { - { "load-slot", 0, 0, G_OPTION_ARG_INT, &config->load_slot, "Loads savegame from slot NUM", "NUM"}, - { "disable-sound", 0, 0, G_OPTION_ARG_NONE, &config->disable_sound, "Disables the sound emulation", NULL}, - { "disable-limiter", 0, 0, G_OPTION_ARG_NONE, &config->disable_limiter, "Disables the 60fps limiter", NULL}, - { "3d-engine", 0, 0, G_OPTION_ARG_INT, &config->engine_3d, "Select 3d rendering engine. Available engines:\n" - "\t\t\t\t 0 = 3d disabled\n" - "\t\t\t\t 1 = internal rasterizer (default)\n" -#ifdef HAVE_LIBOSMESA - "\t\t\t\t 2 = osmesa opengl\n" -#endif - ,"ENGINE"}, - { "save-type", 0, 0, G_OPTION_ARG_INT, &config->savetype, "Select savetype from the following:\n" - "\t\t\t\t 0 = Autodetect (default)\n" - "\t\t\t\t 1 = EEPROM 4kbit\n" - "\t\t\t\t 2 = EEPROM 64kbit\n" - "\t\t\t\t 3 = EEPROM 512kbit\n" - "\t\t\t\t 4 = FRAM 256kbit\n" - "\t\t\t\t 5 = FLASH 2mbit\n" - "\t\t\t\t 6 = FLASH 4mbit\n", - "SAVETYPE"}, - { "fwlang", 0, 0, G_OPTION_ARG_INT, &config->firmware_language, "Set the language in the firmware, LANG as follows:\n" - "\t\t\t\t 0 = Japanese\n" - "\t\t\t\t 1 = English\n" - "\t\t\t\t 2 = French\n" - "\t\t\t\t 3 = German\n" - "\t\t\t\t 4 = Italian\n" - "\t\t\t\t 5 = Spanish\n", - "LANG"}, -#ifdef GDB_STUB - { "arm9gdb", 0, 0, G_OPTION_ARG_INT, &config->arm9_gdb_port, "Enable the ARM9 GDB stub on the given port", "PORT_NUM"}, - { "arm7gdb", 0, 0, G_OPTION_ARG_INT, &config->arm7_gdb_port, "Enable the ARM7 GDB stub on the given port", "PORT_NUM"}, -#endif - { "cflash", 0, 0, G_OPTION_ARG_FILENAME, &config->cflash_disk_image_file, "Enable disk image GBAMP compact flash emulation", "PATH_TO_DISK_IMAGE"}, - { NULL } - }; - GOptionContext *ctx; - GError *error = NULL; - - ctx = g_option_context_new (""); - g_option_context_add_main_entries (ctx, options, "options"); - g_option_context_add_group (ctx, gtk_get_option_group (TRUE)); - g_option_context_parse (ctx, &argc, &argv, &error); - g_option_context_free (ctx); - - if (error) { - g_printerr("Error parsing command line arguments: %s\n", error->message); - g_error_free (error); - return 0; - } - - if (argc == 2) - config->nds_file = argv[1]; - if (argc > 2) - goto error; - - if (config->savetype < 0 || config->savetype > 6) { - g_printerr("Accepted savetypes are from 0 to 6.\n"); - goto error; - } - - if (config->firmware_language < -1 || config->firmware_language > 5) { - g_printerr("Firmware language must be set to a value from 0 to 5.\n"); - goto error; - } - - if (config->load_slot < 0 || config->load_slot > 10) { - g_printerr("I only know how to load from slots 1-10, 0 means 'do not load savegame' and is default\n"); - goto error; - } - - if (config->engine_3d != 0 && config->engine_3d != 1 -#if defined(HAVE_LIBOSMESA) - && config->engine_3d != 2 -#endif - ) { - g_printerr("Currently available ENGINES: 0, 1" -#if defined(HAVE_LIBOSMESA) - ", 2" -#endif - "\n"); - goto error; - } - -#ifdef GDB_STUB - if (config->arm9_gdb_port != 0 && (config->arm9_gdb_port < 1 || config->arm9_gdb_port > 65535)) { - g_printerr("ARM9 GDB stub port must be in the range 1 to 65535\n"); - goto error; - } - - if (config->arm7_gdb_port != 0 && (config->arm7_gdb_port < 1 || config->arm7_gdb_port > 65535)) { - g_printerr("ARM7 GDB stub port must be in the range 1 to 65535\n"); - goto error; - } -#endif - - return 1; - -error: - g_printerr("USAGE: %s [options] [nds-file]\n", argv[0]); - g_printerr("USAGE: %s --help - for help\n", argv[0]); - return 0; -} - - -/* - * The thread handling functions needed by the GDB stub code. - */ -#ifdef GDB_STUB -void * -createThread_gdb( void (*thread_function)( void *data), - void *thread_data) -{ - GThread *new_thread = g_thread_create( (GThreadFunc)thread_function, - thread_data, - TRUE, - NULL); - - return new_thread; -} - -void -joinThread_gdb( void *thread_handle) { - g_thread_join( (GThread *)thread_handle); -} -#endif - - -u16 Keypad_Temp[NB_KEYS]; - -static int Write_ConfigFile(const gchar *config_file) -{ - int i; - GKeyFile * keyfile; - gchar *contents; - gboolean ret; - - keyfile = g_key_file_new(); - - for(i = 0; i < NB_KEYS; i++) { - g_key_file_set_integer(keyfile, "KEYS", key_names[i], keyboard_cfg[i]); - g_key_file_set_integer(keyfile, "JOYKEYS", key_names[i], joypad_cfg[i]); - } - - contents = g_key_file_to_data(keyfile, 0, 0); - ret = g_file_set_contents(config_file, contents, -1, NULL); - if (!ret) - g_printerr("Failed to write to %s\n", config_file); - g_free (contents); - - g_key_file_free(keyfile); - - return 0; -} - -static int Read_ConfigFile(const gchar *config_file) -{ - int i, tmp; - GKeyFile * keyfile = g_key_file_new(); - GError * error = NULL; - - load_default_config(gtk_kb_cfg); - - g_key_file_load_from_file(keyfile, config_file, G_KEY_FILE_NONE, 0); - - /* Load keyboard keys */ - for(i = 0; i < NB_KEYS; i++) { - tmp = g_key_file_get_integer(keyfile, "KEYS", key_names[i], &error); - if (error != NULL) { - g_error_free(error); - error = NULL; - } else { - keyboard_cfg[i] = tmp; - } - } - - /* Load joystick keys */ - for(i = 0; i < NB_KEYS; i++) { - tmp = g_key_file_get_integer(keyfile, "JOYKEYS", key_names[i], &error); - if (error != NULL) { - g_error_free(error); - error = NULL; - } else { - joypad_cfg[i] = tmp; - } - } - - g_key_file_free(keyfile); - - return 0; -} - -/************************ GTK *******************************/ - -uint Frameskip = 0; -GdkInterpType Interpolation = GDK_INTERP_BILINEAR; - -static GtkWidget *pWindow; -static GtkWidget *pStatusBar; -static GtkWidget *pDrawingArea; -GtkActionGroup * action_group; -GtkUIManager *ui_manager; -GtkAspectFrame * pAspectFrame; - -float nds_screen_size_ratio = 1.0f; -int nds_screen_rotation_angle = 0.0f; - -static BOOL regMainLoop = FALSE; - -static inline void pStatusBar_Change (const char *message) -{ - gint pStatusBar_Ctx; - - pStatusBar_Ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(pStatusBar), "Global"); - gtk_statusbar_pop(GTK_STATUSBAR(pStatusBar), pStatusBar_Ctx); - gtk_statusbar_push(GTK_STATUSBAR(pStatusBar), pStatusBar_Ctx, message); -} - -gboolean EmuLoop(gpointer data); - -static void About()//GtkWidget* widget, gpointer data) -{ - GdkPixbuf * pixbuf = gdk_pixbuf_new_from_xpm_data(DeSmuME_xpm); - - gtk_show_about_dialog(GTK_WINDOW(pWindow), - "name", "DeSmuME", - "version", VERSION, - "website", "http://desmume.org", - "logo", pixbuf, - "comments", "Nintendo DS emulator based on work by Yopyop", - NULL); - - g_object_unref(pixbuf); -} - -static int Open(const char *filename, const char *cflash_disk_image) -{ - return NDS_LoadROM( filename, backupmemorytype, backupmemorysize, cflash_disk_image ); -} - -static void Launch() -{ - desmume_resume(); - - if(!regMainLoop) { - g_idle_add_full(EMULOOP_PRIO, &EmuLoop, pWindow, NULL); - regMainLoop = TRUE; - } - - pStatusBar_Change("Running ..."); - - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "pause"), TRUE); - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), FALSE); - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "reset"), TRUE); - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "printscreen"), TRUE); -} - -static void Pause() -{ - desmume_pause(); - pStatusBar_Change("Paused"); - - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "pause"), FALSE); - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), TRUE); -} - -/* Choose a file then load it */ -static void Open_Select() -{ - GtkFileFilter *pFilter_nds, *pFilter_dsgba, *pFilter_any; - GtkWidget *pFileSelection; - GtkWidget *pParent; - gchar *sPath; - - if (desmume_running()) - Pause(); - - pParent = GTK_WIDGET(pWindow); - - pFilter_nds = gtk_file_filter_new(); - gtk_file_filter_add_pattern(pFilter_nds, "*.nds"); -#ifdef HAVE_LIBZ - gtk_file_filter_add_pattern(pFilter_nds, "*.nds.gz"); -#endif -#ifdef HAVE_LIBZZIP - gtk_file_filter_add_pattern(pFilter_nds, "*.nds.zip"); -#endif - gtk_file_filter_set_name(pFilter_nds, "Nds binary (.nds)"); - - pFilter_dsgba = gtk_file_filter_new(); - gtk_file_filter_add_pattern(pFilter_dsgba, "*.ds.gba"); - gtk_file_filter_set_name(pFilter_dsgba, "Nds binary with loader (.ds.gba)"); - - pFilter_any = gtk_file_filter_new(); - gtk_file_filter_add_pattern(pFilter_any, "*"); - gtk_file_filter_set_name(pFilter_any, "All files"); - - /* Creating the selection window */ - pFileSelection = gtk_file_chooser_dialog_new("Open...", - GTK_WINDOW(pParent), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, - NULL); - /* Only the dialog window is accepting events: */ - gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE); - - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_nds); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_dsgba); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); - - /* Showing the window */ - switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { - case GTK_RESPONSE_OK: - sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); - if(Open((const char*)sPath, bad_glob_cflash_disk_image_file) < 0) { - GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - "Unable to load :\n%s", sPath); - gtk_dialog_run(GTK_DIALOG(pDialog)); - gtk_widget_destroy(pDialog); - } else { - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), TRUE); - } - - //Launch(NULL, pWindow); - - g_free(sPath); - break; - default: - break; - } - gtk_widget_destroy(pFileSelection); -} - -static void Reset() -{ - NDS_Reset(); - desmume_resume(); - - pStatusBar_Change("Running ..."); -} - - -/////////////////////////////// DRAWING SCREEN ////////////////////////////////// -#define SCREEN_BYTES_PER_PIXEL 3 -static inline void gpu_screen_to_rgb(u8 * rgb, int size) -{ - u16 gpu_pixel; - int rot = nds_screen_rotation_angle; - int bytesize = size * SCREEN_BYTES_PER_PIXEL; - gint W, H; - gtk_widget_get_size_request(pDrawingArea, &W, &H); - memset(rgb, 0, bytesize); - for (int i = 0; i < 256; i++) { - for (int j = 0; j < 384; j++) { - - gpu_pixel = *((u16 *) & GPU_screen[(i + j * 256) << 1]); - u32 offset; - if(rot == 0 || rot == 180) - offset = i * 3 + j * 3 * 256; - else - offset = j * 3 + (255 - i) * 3 * 384; - switch (rot) { - case 0: - case 270: - *(rgb + offset + 0) = ((gpu_pixel >> 0) & 0x1f) << 3; - *(rgb + offset + 1) = ((gpu_pixel >> 5) & 0x1f) << 3; - *(rgb + offset + 2) = ((gpu_pixel >> 10) & 0x1f) << 3; - break; - case 180: - case 90: - *(rgb + bytesize - offset - 3) = - ((gpu_pixel >> 0) & 0x1f) << 3; - *(rgb + bytesize - offset - 2) = - ((gpu_pixel >> 5) & 0x1f) << 3; - *(rgb + bytesize - offset - 1) = - ((gpu_pixel >> 10) & 0x1f) << 3; - break; - } - } - } -} - -/* Drawing callback */ -static int gtkFloatExposeEvent (GtkWidget *widget, GdkEventExpose *event, gpointer data) -{ - GdkPixbuf *origPixbuf, *resizedPixbuf; - guchar rgb[SCREENS_PIXEL_SIZE*SCREEN_BYTES_PER_PIXEL]; - float ssize; - gint W, H; - gtk_widget_get_size_request(pDrawingArea, &W, &H); - - nds_screen_size_ratio = W / (float)widget->allocation.width; - ssize = 1 / (float)nds_screen_size_ratio; - - gpu_screen_to_rgb(rgb, SCREENS_PIXEL_SIZE); - origPixbuf = gdk_pixbuf_new_from_data(rgb, GDK_COLORSPACE_RGB, 0, 8, W, H, W*SCREEN_BYTES_PER_PIXEL, NULL, NULL); - if(nds_screen_size_ratio != 1.0) { - resizedPixbuf = gdk_pixbuf_scale_simple (origPixbuf, ssize*W, ssize*H, Interpolation); - gdk_draw_pixbuf(widget->window, NULL, resizedPixbuf, 0,0,0,0, ssize*W, ssize*H, GDK_RGB_DITHER_NONE, 0,0); - g_object_unref(resizedPixbuf); - } else { - gdk_draw_pixbuf(widget->window, NULL, origPixbuf, 0,0,0,0, ssize*W, ssize*H, GDK_RGB_DITHER_NONE, 0,0); - } - g_object_unref(origPixbuf); - - return TRUE; -} - -/////////////////////////////// KEYS AND STYLUS UPDATE /////////////////////////////////////// - -inline static void rotoscaled_touchpos(gint x, gint y) -{ - int X, Y, rot, inv; - u16 EmuX, EmuY; - - rot = ( nds_screen_rotation_angle == 90 || nds_screen_rotation_angle == 270); - inv = ( nds_screen_rotation_angle == 180 || nds_screen_rotation_angle == 90); - if(rot){ - X = y; Y = x; - } else { - X = x; Y = y; - } - X = int (X * nds_screen_size_ratio); - Y = int (Y * nds_screen_size_ratio)-192; - - if(inv){ - Y = -Y; - } - - if((inv && !rot) || (!inv && rot)){ - X = 255 - X; - } - - LOG("X=%d, Y=%d\n", x,y); - - // FIXME: should ignore events only when STARTING touched-position - // was outside touchscreen - desmume window does not have physical band - // to limit movement of stylus - if ( Y >= 0 ) { - EmuX = CLAMP(X, 0, 255); - EmuY = CLAMP(Y, 0, 191); - NDS_setTouchPos(EmuX, EmuY); - } -} - -static gboolean Stylus_Move(GtkWidget *w, GdkEventMotion *e, gpointer data) -{ - GdkModifierType state; - gint x,y; - - if(click) { - if(e->is_hint) - gdk_window_get_pointer(w->window, &x, &y, &state); - else { - x= (gint)e->x; - y= (gint)e->y; - state=(GdkModifierType)e->state; - } - - if(state & GDK_BUTTON1_MASK) - rotoscaled_touchpos(x,y); - } - - return TRUE; -} - -static gboolean Stylus_Press(GtkWidget * w, GdkEventButton * e, - gpointer data) -{ - GdkModifierType state; - gint x, y; - - if( !desmume_running()) - return TRUE; - - if (e->button == 1) { - click = TRUE; - - gdk_window_get_pointer(w->window, &x, &y, &state); - - if(state & GDK_BUTTON1_MASK) - rotoscaled_touchpos(x, y); - } - - return TRUE; -} -static gboolean Stylus_Release(GtkWidget *w, GdkEventButton *e, gpointer data) -{ - if(click) NDS_releaseTouch(); - click = FALSE; - return TRUE; -} - -static void loadgame(int num){ - if (desmume_running()) - { - Pause(); - loadstate_slot(num); - Launch(); - } - else - loadstate_slot(num); -} - -static void savegame(int num){ - if (desmume_running()) - { - Pause(); - savestate_slot(num); - Launch(); - } - else - savestate_slot(num); -} - -static void MenuLoad(GtkMenuItem *item, gpointer slot) -{ - loadgame(GPOINTER_TO_INT(slot)); -} - -static void MenuSave(GtkMenuItem *item, gpointer slot) -{ - savegame(GPOINTER_TO_INT(slot)); -} - -static gint Key_Press(GtkWidget *w, GdkEventKey *e, gpointer data) -{ - if (e->keyval == GDK_Shift_L){ - gdk_shift_pressed |= 1; - return 1; - } - if (e->keyval == GDK_Shift_R){ - gdk_shift_pressed |= 2; - return 1; - } - if( e->keyval >= GDK_F1 && e->keyval <= GDK_F10 ){ - if(!gdk_shift_pressed) - loadgame(e->keyval - GDK_F1 + 1); - else - savegame(e->keyval - GDK_F1 + 1); - return 1; - } - guint mask; - mask = gtk_accelerator_get_default_mod_mask (); - if( (e->state & mask) == 0){ - u16 Key = lookup_key(e->keyval); - if(Key){ - ADD_KEY( Cur_Keypad, Key ); - if(desmume_running()) update_keypad(Cur_Keypad); - return 1; - } - } - -#ifdef PROFILE_MEMORY_ACCESS - if ( e->keyval == GDK_Tab) { - print_memory_profiling(); - return 1; - } -#endif - return 0; -} - -static gint Key_Release(GtkWidget *w, GdkEventKey *e, gpointer data) -{ - if (e->keyval == GDK_Shift_L){ - gdk_shift_pressed &= ~1; - return 1; - } - if (e->keyval == GDK_Shift_R){ - gdk_shift_pressed &= ~2; - return 1; - } - u16 Key = lookup_key(e->keyval); - RM_KEY( Cur_Keypad, Key ); - if(desmume_running()) update_keypad(Cur_Keypad); - return 1; - -} - -/////////////////////////////// CONTROLS EDIT ////////////////////////////////////// - -struct modify_key_ctx { - gint mk_key_chosen; - GtkWidget *label; -}; - -static void Modify_Key_Press(GtkWidget *w, GdkEventKey *e, struct modify_key_ctx *ctx) -{ - gchar *YouPressed; - - ctx->mk_key_chosen = e->keyval; - YouPressed = g_strdup_printf("You pressed : %s\nClick OK to keep this key.", gdk_keyval_name(e->keyval)); - gtk_label_set(GTK_LABEL(ctx->label), YouPressed); - g_free(YouPressed); -} - -static void Modify_Key(GtkWidget* widget, gpointer data) -{ - struct modify_key_ctx ctx; - GtkWidget *mkDialog; - gchar *Key_Label; - gchar *Title; - gint Key; - - Key = GPOINTER_TO_INT(data); - ctx.mk_key_chosen = 0; - Title = g_strdup_printf("Press \"%s\" key ...\n", key_names[Key]); - mkDialog = gtk_dialog_new_with_buttons(Title, - GTK_WINDOW(pWindow), - GTK_DIALOG_MODAL, - GTK_STOCK_OK,GTK_RESPONSE_OK, - GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL, - NULL); - - ctx.label = gtk_label_new(Title); - g_free(Title); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mkDialog)->vbox), ctx.label, TRUE, FALSE, 0); - - g_signal_connect(G_OBJECT(mkDialog), "key_press_event", G_CALLBACK(Modify_Key_Press), &ctx); - - gtk_widget_show_all(GTK_DIALOG(mkDialog)->vbox); - - switch(gtk_dialog_run(GTK_DIALOG(mkDialog))) { - case GTK_RESPONSE_OK: - Keypad_Temp[Key] = ctx.mk_key_chosen; - Key_Label = g_strdup_printf("%s (%s)", key_names[Key], gdk_keyval_name(Keypad_Temp[Key])); - gtk_button_set_label(GTK_BUTTON(widget), Key_Label); - g_free(Key_Label); - break; - case GTK_RESPONSE_CANCEL: - case GTK_RESPONSE_NONE: - ctx.mk_key_chosen = 0; - break; - } - - gtk_widget_destroy(mkDialog); - -} - -static void Edit_Controls() -{ - GtkWidget *ecDialog; - GtkWidget *ecKey; - gchar *Key_Label; - int i; - - memcpy(&Keypad_Temp, &keyboard_cfg, sizeof(keyboard_cfg)); - - ecDialog = gtk_dialog_new_with_buttons("Edit controls", - GTK_WINDOW(pWindow), - GTK_DIALOG_MODAL, - GTK_STOCK_OK,GTK_RESPONSE_OK, - GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL, - NULL); - - for(i = 0; i < NB_KEYS; i++) { - Key_Label = g_strdup_printf("%s (%s)", key_names[i], gdk_keyval_name(Keypad_Temp[i])); - ecKey = gtk_button_new_with_label(Key_Label); - g_free(Key_Label); - g_signal_connect(G_OBJECT(ecKey), "clicked", G_CALLBACK(Modify_Key), GINT_TO_POINTER(i)); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(ecDialog)->vbox), ecKey,TRUE, FALSE, 0); - } - - gtk_widget_show_all(GTK_DIALOG(ecDialog)->vbox); - - switch (gtk_dialog_run(GTK_DIALOG(ecDialog))) { - case GTK_RESPONSE_OK: - memcpy(&keyboard_cfg, &Keypad_Temp, sizeof(keyboard_cfg)); - case GTK_RESPONSE_CANCEL: - case GTK_RESPONSE_NONE: - break; - } - gtk_widget_destroy(ecDialog); - -} - -/////////////////////////////// LAYER HIDING ///////////////////////////////// - -static void SetRotation(GtkAction* action, gpointer data) -{ - const gchar *angle = gtk_action_get_name(GTK_ACTION(action)) + strlen("rotate_"); - nds_screen_rotation_angle = atoi(angle); - int a = nds_screen_rotation_angle; - if( a != 0 && a != 90 && a != 180 && a != 270 ){ - g_printerr("Congratulations, you've managed to set unsupported screen rotation angle (%s)", angle); - exit(1); - } - gint H, W; - gfloat ratio; - if(a == 90 || a == 270){ - W = 384; H = 256; - } else { - W = 256; H = 384; - } - ratio = (gfloat) W / (gfloat) H; - gtk_widget_set_size_request(GTK_WIDGET(pDrawingArea), W, H); - gtk_aspect_frame_set (pAspectFrame , - 0.5, /* center x */ - 0.5, /* center y */ - ratio, /* xsize/ysize */ - FALSE /* ignore child's aspect */); - -} - -static void Modify_Layer(GtkToggleAction* action, gpointer data) -{ - guint Layer = GPOINTER_TO_UINT(data); - gboolean active; - - // FIXME: make it work after resume - if (!desmume_running()) - return; - - active = gtk_toggle_action_get_active(action); - - switch (Layer) { - case MAIN_BG_0: - case MAIN_BG_1: - case MAIN_BG_2: - case MAIN_BG_3: - if(active == TRUE) { - if (!MainScreen.gpu->dispBG[Layer]) - GPU_addBack(MainScreen.gpu, Layer); - } else { - if (MainScreen.gpu->dispBG[Layer]) - GPU_remove(MainScreen.gpu, Layer); - } - break; - case MAIN_OBJ: - if(active == TRUE) { - if (!MainScreen.gpu->dispOBJ) - GPU_addBack(MainScreen.gpu, Layer); - } else { - if (MainScreen.gpu->dispOBJ) - GPU_remove(MainScreen.gpu, Layer); - } - break; - case SUB_BG_0: - case SUB_BG_1: - case SUB_BG_2: - case SUB_BG_3: - if(active == TRUE) { - if (!SubScreen.gpu->dispBG[Layer-SUB_BG_0]) - GPU_addBack(SubScreen.gpu, Layer-SUB_BG_0); - } else { - if (SubScreen.gpu->dispBG[Layer-SUB_BG_0]) - GPU_remove(SubScreen.gpu, Layer-SUB_BG_0); - } - break; - case SUB_OBJ: - if(active == TRUE) { - if (!SubScreen.gpu->dispOBJ) - GPU_addBack(SubScreen.gpu, Layer-SUB_BG_0); - } else { - if (SubScreen.gpu->dispOBJ) - GPU_remove(SubScreen.gpu, Layer-SUB_BG_0); - } - break; - default: - break; - } -} - -/////////////////////////////// PRINTSCREEN ///////////////////////////////// - -static void Printscreen() -{ - GdkPixbuf *screenshot; - gchar *filename; - GError *error = NULL; - u8 *rgb; - static int seq = 0; - - rgb = (u8 *) malloc(SCREENS_PIXEL_SIZE*3); - if (!rgb) - return; - - gpu_screen_to_rgb(rgb, SCREENS_PIXEL_SIZE); - screenshot = gdk_pixbuf_new_from_data(rgb, - GDK_COLORSPACE_RGB, - FALSE, - 8, - 256, - 192*2, - 256*3, - NULL, - NULL); - - filename = g_strdup_printf("./desmume-screenshot-%d.png", seq); - gdk_pixbuf_save(screenshot, filename, "png", &error, NULL); - if (error) { - g_error_free (error); - g_printerr("Failed to save %s", filename); - } else { - seq++; - } - - free(rgb); - g_object_unref(screenshot); - g_free(filename); -} - -/////////////////////////////// DS CONFIGURATION ////////////////////////////////// - -#ifdef DESMUME_GTK_FIRMWARE_BROKEN -static void SelectFirmwareFile() -{ - GtkFileFilter *pFilter_nds, *pFilter_bin, *pFilter_any; - GtkWidget *pFileSelection; - GtkWidget *pParent; - gchar *sPath; - - BOOL oldState = desmume_running(); - Pause(); - - pParent = GTK_WIDGET(pWindow); - - pFilter_nds = gtk_file_filter_new(); - gtk_file_filter_add_pattern(pFilter_nds, "*.nds"); - gtk_file_filter_set_name(pFilter_nds, "Nds binary (.nds)"); - - pFilter_bin = gtk_file_filter_new(); - gtk_file_filter_add_pattern(pFilter_bin, "*.bin"); - gtk_file_filter_set_name(pFilter_bin, "Binary file (.bin)"); - - pFilter_any = gtk_file_filter_new(); - gtk_file_filter_add_pattern(pFilter_any, "*"); - gtk_file_filter_set_name(pFilter_any, "All files"); - - pFileSelection = gtk_file_chooser_dialog_new("Load firmware...", - GTK_WINDOW(pParent), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, - NULL); - gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE); - - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_nds); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_bin); - gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); - - switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { - case GTK_RESPONSE_OK: - sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); - CommonSettings.UseExtFirmware = true; - strncpy(CommonSettings.Firmware, (const char*)sPath, g_utf8_strlen(sPath, -1)); - g_free(sPath); - break; - default: - break; - } - gtk_widget_destroy(pFileSelection); - - if(oldState) Launch(); -} -#endif - -static void Modify_Interpolation(GtkAction *action, GtkRadioAction *current) -{ - uint i = gtk_radio_action_get_current_value(current) ; - Interpolation = (i == 0 ? GDK_INTERP_NEAREST : GDK_INTERP_BILINEAR); -} - -/////////////////////////////// FRAMESKIP ///////////////////////////////// - -#define MAX_FRAMESKIP 10 - -static void Modify_Frameskip(GtkAction *action, GtkRadioAction *current) -{ - Frameskip = gtk_radio_action_get_current_value(current) ; -} - -/////////////////////////////// TOOLS MANAGEMENT /////////////////////////////// - -#include "dTool.h" - -extern const dTool_t *dTools_list[]; -extern const int dTools_list_size; - -BOOL *dTools_running; - -static void Start_dTool(GtkWidget *widget, gpointer data) -{ - int tool = GPOINTER_TO_INT(data); - - if(dTools_running == NULL || dTools_running[tool]) - return; - - dTools_list[tool]->open(tool); - dTools_running[tool] = TRUE; -} - -void dTool_CloseCallback(int tool) -{ - if (dTools_running == NULL) - return; - - dTools_running[tool] = FALSE; -} - -/////////////////////////////// MAIN EMULATOR LOOP /////////////////////////////// - -static inline void _updateDTools() -{ - if (dTools_running == NULL) - return; - - for(int i = 0; i < dTools_list_size; i++) { - if(dTools_running[i]) { dTools_list[i]->update(); } - } -} - -gboolean EmuLoop(gpointer data) -{ - static Uint32 fps, fps_SecStart, fps_FrameCount; - unsigned int i; - gchar *Title; - - if (!desmume_running()) { - regMainLoop = FALSE; - return FALSE; - } - - /* If desmume is currently running */ - static int limiter_frame_counter = 0; - fps_FrameCount += Frameskip + 1; - if (!fps_SecStart) - fps_SecStart = SDL_GetTicks(); - if (SDL_GetTicks() - fps_SecStart >= 1000) { - fps_SecStart = SDL_GetTicks(); - fps = fps_FrameCount; - fps_FrameCount = 0; - - Title = g_strdup_printf("Desmume - %dfps", fps); - gtk_window_set_title(GTK_WINDOW(pWindow), Title); - g_free(Title); - } - - desmume_cycle(); /* Emule ! */ - NDS_SkipFrame(true); - for (i = 0; i < Frameskip; i++) { - desmume_cycle(); - } - NDS_SkipFrame(false); - - _updateDTools(); - gtk_widget_queue_draw( pDrawingArea ); - - if (!gtk_fps_limiter_disabled) { - limiter_frame_counter += 1; - if (limiter_frame_counter >= FPS_LIMITER_FRAME_PERIOD) { - limiter_frame_counter = 0; - /* wait for the timer to expire */ - SDL_SemWait( fps_limiter_semaphore); - } - } - - return TRUE; -} - - -/** - * A SDL timer callback function. Signals the supplied SDL semaphore - * if its value is small. - * - * @param interval The interval since the last call (in ms) - * @param param The pointer to the semaphore. - * - * @return The interval to the next call (required by SDL) - */ -static Uint32 fps_limiter_fn(Uint32 interval, void *param) -{ - SDL_sem *sdl_semaphore = (SDL_sem *)param; - - /* signal the semaphore if it is getting low */ - if ( SDL_SemValue( sdl_semaphore) < 4) { - SDL_SemPost( sdl_semaphore); - } - - return interval; -} - -static void desmume_try_adding_ui(GtkUIManager *self, const char *ui_descr){ - GError *error; - error = NULL; - if (!gtk_ui_manager_add_ui_from_string (self, ui_descr, -1, &error)) - { - g_message ("building menus failed: %s", error->message); - g_error_free (error); - exit (EXIT_FAILURE); - } -} - -static void dui_set_accel_group(gpointer action, gpointer group) { - gtk_action_set_accel_group((GtkAction *)action, (GtkAccelGroup *)group); -} - -static void desmume_gtk_menu_file_saveload_slot (GtkActionGroup *ag) -{ - for(guint i = 1; i <= 10; i++){ - GtkAction *act; - char label[64], name[64]; - - snprintf(label, 60, "_%d", i); - - snprintf(name, 60, "savestate%d", i); - act = gtk_action_new(name, label, NULL, NULL); - g_signal_connect(G_OBJECT(act), "activate", G_CALLBACK(MenuSave), GUINT_TO_POINTER(i)); - gtk_action_group_add_action_with_accel(ag, GTK_ACTION(act), NULL); - - snprintf(name, 60, "loadstate%d", i); - act = gtk_action_new(name, label, NULL, NULL); - g_signal_connect(G_OBJECT(act), "activate", G_CALLBACK(MenuLoad), GUINT_TO_POINTER(i)); - gtk_action_group_add_action_with_accel(ag, GTK_ACTION(act), NULL); - } -} - -static void changesavetype(GtkAction *action, GtkRadioAction *current) -{ - mmu_select_savetype( gtk_radio_action_get_current_value(current), - &backupmemorytype, &backupmemorysize); -} - -static void desmume_gtk_menu_emulation_layers (GtkActionGroup *ag) -{ - const char *Layers_Menu[10][2] = { - {"layermainbg0","_0 Main BG 0"}, - {"layermainbg1","_1 Main BG 1"}, - {"layermainbg2","_2 Main BG 2"}, - {"layermainbg3","_3 Main BG 3"}, - {"layermainobj","_4 Main OBJ"}, - {"layersubbg0", "_5 SUB BG 0"}, - {"layersubbg1", "_6 SUB BG 1"}, - {"layersubbg2", "_7 SUB BG 2"}, - {"layersubbg3", "_8 SUB BG 3"}, - {"layersubobj", "_9 SUB OBJ"} - }; - guint i; - - GtkToggleAction *act; - for(i = 0; i< 10; i++){ - act = gtk_toggle_action_new(Layers_Menu[i][0],Layers_Menu[i][1],NULL,NULL); - gtk_toggle_action_set_active(act, TRUE); - g_signal_connect(G_OBJECT(act), "activate", G_CALLBACK(Modify_Layer), GUINT_TO_POINTER(i)); - gtk_action_group_add_action_with_accel(ag, GTK_ACTION(act), NULL); - } -} - -static void desmume_gtk_disable_audio (GtkToggleAction *action) -{ - if (gtk_toggle_action_get_active(action) == TRUE) { - SPU_ChangeSoundCore(SNDCORE_SDL, 735 * 4); - } else { - SPU_ChangeSoundCore(0, 0); - } -} - -static void desmume_gtk_mic_noise (GtkToggleAction *action) -{ - Mic_DoNoise((BOOL)gtk_toggle_action_get_active(action)); -} - -static void desmume_gtk_menu_tools (GtkActionGroup *ag) -{ - gint i; - for(i = 0; i < dTools_list_size; i++) { - GtkAction *act; - //FIXME: remove hardcoded 'ioregtool' from here and in ui_description - act = gtk_action_new("ioregtool", dTools_list[i]->name, NULL, NULL); - g_signal_connect(G_OBJECT(act), "activate", G_CALLBACK(Start_dTool), GINT_TO_POINTER(i)); - gtk_action_group_add_action(ag, GTK_ACTION(act)); - } -} - -static int -common_gtk_main( struct configured_features *my_config) -{ - SDL_TimerID limiter_timer = NULL; - gchar *config_file; - - GtkAccelGroup * accel_group; - GtkWidget *pVBox; - GtkWidget *pMenuBar; - GtkWidget *pToolBar; - gint pStatusBar_Ctx; - -#ifdef GDB_STUB - gdbstub_handle_t arm9_gdb_stub; - gdbstub_handle_t arm7_gdb_stub; -#endif - struct armcpu_memory_iface *arm9_memio = &arm9_base_memory_iface; - struct armcpu_memory_iface *arm7_memio = &arm7_base_memory_iface; - struct armcpu_ctrl_iface *arm9_ctrl_iface; - struct armcpu_ctrl_iface *arm7_ctrl_iface; - - /* the firmware settings */ - struct NDS_fw_config_data fw_config; - - /* default the firmware settings, they may get changed later */ - NDS_FillDefaultFirmwareConfigData( &fw_config); - - /* use any language set on the command line */ - if ( my_config->firmware_language != -1) { - fw_config.language = my_config->firmware_language; - } - - bad_glob_cflash_disk_image_file = my_config->cflash_disk_image_file; - -#ifdef GDB_STUB - if ( my_config->arm9_gdb_port != 0) { - arm9_gdb_stub = createStub_gdb( my_config->arm9_gdb_port, - &arm9_memio, - &arm9_base_memory_iface); - - if ( arm9_gdb_stub == NULL) { - g_printerr("Failed to create ARM9 gdbstub on port %d\n", - my_config->arm9_gdb_port); - exit( -1); - } - } - if ( my_config->arm7_gdb_port != 0) { - arm7_gdb_stub = createStub_gdb( my_config->arm7_gdb_port, - &arm7_memio, - &arm7_base_memory_iface); - - if ( arm7_gdb_stub == NULL) { - g_printerr("Failed to create ARM7 gdbstub on port %d\n", - my_config->arm7_gdb_port); - exit( -1); - } - } -#endif - - /* FIXME: SDL_INIT_VIDEO is needed for joystick support to work!? - Perhaps it needs a "window" to catch events...? */ - if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO) == -1) { - g_printerr("Error trying to initialize SDL: %s\n", - SDL_GetError()); - return 1; - } - desmume_init( arm9_memio, &arm9_ctrl_iface, - arm7_memio, &arm7_ctrl_iface, - my_config->disable_sound); - - /* - * Activate the GDB stubs - * This has to come after the NDS_Init (called in desmume_init) - * where the cpus are set up. - */ -#ifdef GDB_STUB - if ( my_config->arm9_gdb_port != 0) { - activateStub_gdb( arm9_gdb_stub, arm9_ctrl_iface); - } - if ( my_config->arm7_gdb_port != 0) { - activateStub_gdb( arm7_gdb_stub, arm7_ctrl_iface); - } -#endif - - /* Create the dummy firmware */ - NDS_CreateDummyFirmware( &fw_config); - - /* Initialize joysticks */ - if(!init_joy()) return 1; - - dTools_running = (BOOL*)malloc(sizeof(BOOL) * dTools_list_size); - if (dTools_running != NULL) - memset(dTools_running, FALSE, sizeof(BOOL) * dTools_list_size); - - config_file = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL); - Read_ConfigFile(config_file); - - /* Create the window */ - pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(pWindow), "Desmume"); - - gtk_window_set_resizable(GTK_WINDOW (pWindow), TRUE); - - gtk_window_set_icon(GTK_WINDOW (pWindow), gdk_pixbuf_new_from_xpm_data(DeSmuME_xpm)); - - g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL); - g_signal_connect(G_OBJECT(pWindow), "key_press_event", G_CALLBACK(Key_Press), NULL); - g_signal_connect(G_OBJECT(pWindow), "key_release_event", G_CALLBACK(Key_Release), NULL); - - /* Create the GtkVBox */ - pVBox = gtk_vbox_new(FALSE, 0); - gtk_container_add(GTK_CONTAINER(pWindow), pVBox); - - ui_manager = gtk_ui_manager_new (); - accel_group = gtk_accel_group_new(); - action_group = gtk_action_group_new("dui"); - - gtk_action_group_add_actions(action_group, action_entries, G_N_ELEMENTS(action_entries), NULL); - gtk_action_group_add_toggle_actions(action_group, toggle_entries, G_N_ELEMENTS(toggle_entries), NULL); - desmume_gtk_menu_emulation_layers(action_group); - desmume_gtk_menu_file_saveload_slot(action_group); - desmume_gtk_menu_tools(action_group); - gtk_action_group_add_radio_actions(action_group, savet_entries, G_N_ELEMENTS(savet_entries), - my_config->savetype, G_CALLBACK(changesavetype), NULL); - gtk_action_group_add_radio_actions(action_group, interpolation_entries, G_N_ELEMENTS(interpolation_entries), - 1, G_CALLBACK(Modify_Interpolation), NULL); - gtk_action_group_add_radio_actions(action_group, frameskip_entries, G_N_ELEMENTS(frameskip_entries), - 0, G_CALLBACK(Modify_Frameskip), NULL); - { - GList * list = gtk_action_group_list_actions(action_group); - g_list_foreach(list, dui_set_accel_group, accel_group); - } - gtk_window_add_accel_group(GTK_WINDOW(pWindow), accel_group); - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "pause"), FALSE); - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), FALSE); - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "reset"), FALSE); - gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "printscreen"), FALSE); - - gtk_ui_manager_insert_action_group (ui_manager, action_group, 0); - - accel_group = gtk_ui_manager_get_accel_group (ui_manager); - gtk_window_add_accel_group (GTK_WINDOW (pWindow), accel_group); - - desmume_try_adding_ui(ui_manager, ui_description); - - pMenuBar = gtk_ui_manager_get_widget (ui_manager, "/MainMenu"); - gtk_box_pack_start (GTK_BOX (pVBox), pMenuBar, FALSE, FALSE, 0); - pToolBar = gtk_ui_manager_get_widget (ui_manager, "/ToolBar"); - gtk_box_pack_start (GTK_BOX(pVBox), pToolBar, FALSE, FALSE, 0); - - pAspectFrame = GTK_ASPECT_FRAME(gtk_aspect_frame_new (NULL, /* label */ - 0.5, /* center x */ - 0.5, /* center y */ - 256.0/384.0, /* xsize/ysize */ - FALSE /* ignore child's aspect */)); - - gtk_container_add (GTK_CONTAINER (pVBox), GTK_WIDGET(pAspectFrame)); - - /* Creating the place for showing DS screens */ - pDrawingArea = gtk_drawing_area_new(); - - gtk_widget_set_size_request(GTK_WIDGET(pDrawingArea), 256, 384); - - gtk_widget_set_events(pDrawingArea, - GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | - GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK ); - - g_signal_connect(G_OBJECT(pDrawingArea), "button_press_event", - G_CALLBACK(Stylus_Press), NULL); - g_signal_connect(G_OBJECT(pDrawingArea), "button_release_event", - G_CALLBACK(Stylus_Release), NULL); - g_signal_connect(G_OBJECT(pDrawingArea), "motion_notify_event", - G_CALLBACK(Stylus_Move), NULL); - - g_signal_connect(G_OBJECT(pDrawingArea), "expose_event", - G_CALLBACK(gtkFloatExposeEvent), NULL ) ; - gtk_container_add (GTK_CONTAINER (pAspectFrame), pDrawingArea); - - /* Status bar */ - pStatusBar = gtk_statusbar_new(); - pStatusBar_Ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(pStatusBar), "Global"); - pStatusBar_Change("Desmume"); - gtk_box_pack_end(GTK_BOX(pVBox), pStatusBar, FALSE, FALSE, 0); - - gtk_widget_show_all(pWindow); - - gtk_fps_limiter_disabled = my_config->disable_limiter; - if ( !gtk_fps_limiter_disabled) { - /* create the semaphore used for fps limiting */ - fps_limiter_semaphore = SDL_CreateSemaphore( 1); - - /* start a SDL timer for every FPS_LIMITER_FRAME_PERIOD frames to keep us at 60 fps */ - limiter_timer = SDL_AddTimer( 16 * FPS_LIMITER_FRAME_PERIOD, fps_limiter_fn, fps_limiter_semaphore); - if ( limiter_timer == NULL) { - g_printerr("Error trying to start FPS limiter timer: %s\n", - SDL_GetError()); - return 1; - } - } - - /* - * Set the 3D emulation to use - */ - unsigned core = my_config->engine_3d; - /* setup the gdk 3D emulation; */ -#if defined(HAVE_LIBOSMESA) - if(my_config->engine_3d == 2){ - core = init_osmesa_3Demu() ? 2 : GPU3D_NULL; - } -#endif - NDS_3D_ChangeCore(core); - if(my_config->engine_3d != 0 && gpu3D == &gpu3DNull) { - g_printerr("Failed to initialise openGL 3D emulation; " - "removing 3D support\n"); - } - - mmu_select_savetype(my_config->savetype, &backupmemorytype, &backupmemorysize); - - /* Command line arg */ - if( my_config->nds_file != NULL) { - if(Open( my_config->nds_file, bad_glob_cflash_disk_image_file) >= 0) { - if(my_config->load_slot){ - loadstate_slot(my_config->load_slot); - } - - Launch(); - } else { - GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow), - GTK_DIALOG_MODAL, - GTK_MESSAGE_INFO, - GTK_BUTTONS_OK, - "Unable to load :\n%s", my_config->nds_file); - gtk_dialog_run(GTK_DIALOG(pDialog)); - gtk_widget_destroy(pDialog); - } - } - - /* Main loop */ - -// gtk_idle_add(&EmuLoop, pWindow); -// g_idle_add(&EmuLoop, pWindow); - - gtk_main(); - - desmume_free(); - - if ( !gtk_fps_limiter_disabled) { - /* tidy up the FPS limiter timer and semaphore */ - SDL_RemoveTimer( limiter_timer); - SDL_DestroySemaphore( fps_limiter_semaphore); - } - - /* Unload joystick */ - uninit_joy(); - - SDL_Quit(); - - Write_ConfigFile(config_file); - g_free(config_file); - -#ifdef GDB_STUB - if ( my_config->arm9_gdb_port != 0) { - destroyStub_gdb( arm9_gdb_stub); - } - if ( my_config->arm7_gdb_port != 0) { - destroyStub_gdb( arm7_gdb_stub); - } -#endif - - return EXIT_SUCCESS; -} - - -int -main (int argc, char *argv[]) -{ - struct configured_features my_config; - - init_configured_features( &my_config); - - if (!g_thread_supported()) - g_thread_init( NULL); - - gtk_init(&argc, &argv); - - if ( !fill_configured_features( &my_config, argc, argv)) { - exit(0); - } - - return common_gtk_main( &my_config); -} - -#ifdef WIN32 -int WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) -{ - int argc = 0; - char *argv[] = NULL; - - /* - * FIXME: - * Emulate the argc and argv main parameters. Could do this using - * CommandLineToArgvW and then convert the wide chars to thin chars. - * Or parse the wide chars directly and call common_gtk_main with a - * filled configuration structure. - */ - main( argc, argv); -} -#endif - diff --git a/desmume/src/windows/DeSmuME_2005.sln b/desmume/src/windows/DeSmuME_2005.sln deleted file mode 100644 index c1443642b..000000000 --- a/desmume/src/windows/DeSmuME_2005.sln +++ /dev/null @@ -1,20 +0,0 @@ -ďťż -Microsoft Visual Studio Solution File, Format Version 9.00 -# Visual Studio 2005 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DeSmuME_VS2005", "DeSmuME_2005.vcproj", "{9F5F72A1-D3A5-4918-B460-E076B16D10A9}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9F5F72A1-D3A5-4918-B460-E076B16D10A9}.Debug|Win32.ActiveCfg = Debug|Win32 - {9F5F72A1-D3A5-4918-B460-E076B16D10A9}.Debug|Win32.Build.0 = Debug|Win32 - {9F5F72A1-D3A5-4918-B460-E076B16D10A9}.Release|Win32.ActiveCfg = Release|Win32 - {9F5F72A1-D3A5-4918-B460-E076B16D10A9}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/desmume/src/windows/DeSmuME_2008.sln b/desmume/src/windows/DeSmuME_2008.sln deleted file mode 100644 index 974af79ab..000000000 --- a/desmume/src/windows/DeSmuME_2008.sln +++ /dev/null @@ -1,20 +0,0 @@ -ďťż -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual C++ Express 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DeSmuME_VS2008", "DeSmuME_2008.vcproj", "{9F5F72A1-D3A5-4918-B460-E076B16D10A9}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {9F5F72A1-D3A5-4918-B460-E076B16D10A9}.Debug|Win32.ActiveCfg = Debug|Win32 - {9F5F72A1-D3A5-4918-B460-E076B16D10A9}.Debug|Win32.Build.0 = Debug|Win32 - {9F5F72A1-D3A5-4918-B460-E076B16D10A9}.Release|Win32.ActiveCfg = Release|Win32 - {9F5F72A1-D3A5-4918-B460-E076B16D10A9}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/desmume/src/windows/config.h b/desmume/src/windows/config.h deleted file mode 100644 index fc3646704..000000000 --- a/desmume/src/windows/config.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _CONFIG_H -#define _CONFIG_H - -#include "userconfig.h" - -#endif diff --git a/desmume/src/windows/defaultconfig/userconfig.h b/desmume/src/windows/defaultconfig/userconfig.h deleted file mode 100644 index 9ce974c00..000000000 --- a/desmume/src/windows/defaultconfig/userconfig.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _USERCONFIG_H -#define _USERCONFIG_H - -//this is a default file. it should not be edited, or else you will mess up the defaults. -//to customize your build, place a customized copy in the userconfig directory -//(alongside this defaultconfig directory) - -//#define NOSSE2 //disables SSE2 optimizations (better change it in the vc++ codegen options too) -//#define DEVELOPER //enables dev+ features - - -#endif //_USERCONFIG_H diff --git a/desmume/po/ChangeLog b/po/ChangeLog similarity index 100% rename from desmume/po/ChangeLog rename to po/ChangeLog diff --git a/desmume/po/LINGUAS b/po/LINGUAS similarity index 100% rename from desmume/po/LINGUAS rename to po/LINGUAS diff --git a/desmume/po/PACKAGE b/po/PACKAGE similarity index 100% rename from desmume/po/PACKAGE rename to po/PACKAGE diff --git a/desmume/po/POTFILES.in b/po/POTFILES.in similarity index 100% rename from desmume/po/POTFILES.in rename to po/POTFILES.in diff --git a/desmume/po/desmume.pot b/po/desmume.pot similarity index 100% rename from desmume/po/desmume.pot rename to po/desmume.pot diff --git a/desmume/po/fr.po b/po/fr.po similarity index 100% rename from desmume/po/fr.po rename to po/fr.po diff --git a/desmume/po/pt_BR.po b/po/pt_BR.po similarity index 100% rename from desmume/po/pt_BR.po rename to po/pt_BR.po diff --git a/desmume/po/sv.po b/po/sv.po similarity index 100% rename from desmume/po/sv.po rename to po/sv.po diff --git a/desmume/po/windows/en_US.po b/po/windows/en_US.po similarity index 100% rename from desmume/po/windows/en_US.po rename to po/windows/en_US.po diff --git a/desmume/po/windows/fr_FR.po b/po/windows/fr_FR.po similarity index 100% rename from desmume/po/windows/fr_FR.po rename to po/windows/fr_FR.po diff --git a/desmume/src/ARM9.h b/src/ARM9.h similarity index 89% rename from desmume/src/ARM9.h rename to src/ARM9.h index 06d0bf163..0a9b6849d 100644 --- a/desmume/src/ARM9.h +++ b/src/ARM9.h @@ -11,7 +11,7 @@ struct ALIGN(16) ARM9_struct { u8 ARM9_REG[0x1000000]; u8 ARM9_BIOS[0x8000]; u8 ARM9_VMEM[0x800]; - u8 ARM9_LCD[0xA4000+0x4000]; //an extra 16KB for blank memory + u8 ARM9_LCD[0xA4000]; u8 ARM9_OAM[0x800]; u8* ExtPal[2][4]; diff --git a/desmume/src/Disassembler.cpp b/src/Disassembler.cpp similarity index 99% rename from desmume/src/Disassembler.cpp rename to src/Disassembler.cpp index bf8f193d8..56f11f017 100644 --- a/desmume/src/Disassembler.cpp +++ b/src/Disassembler.cpp @@ -3743,7 +3743,7 @@ static char * OP_BLX(u32 adr, u32 i, char * txt) static char * OP_BL_10(u32 adr, u32 i, char * txt) { part = adr+4 + (SIGNEEXT_IMM11(i)<<12); - sprintf(txt, "calculating high part of the address"); + sprintf(txt, "CALCUL LA PARTIE HAUTE DE L'ADRESSE"); return txt; } diff --git a/desmume/src/Disassembler.h b/src/Disassembler.h similarity index 100% rename from desmume/src/Disassembler.h rename to src/Disassembler.h diff --git a/desmume/src/FIFO.cpp b/src/FIFO.cpp similarity index 100% rename from desmume/src/FIFO.cpp rename to src/FIFO.cpp diff --git a/desmume/src/FIFO.h b/src/FIFO.h similarity index 100% rename from desmume/src/FIFO.h rename to src/FIFO.h diff --git a/desmume/src/GPU.cpp b/src/GPU.cpp similarity index 86% rename from desmume/src/GPU.cpp rename to src/GPU.cpp index aeaf82584..b2bc0a800 100644 --- a/desmume/src/GPU.cpp +++ b/src/GPU.cpp @@ -49,11 +49,9 @@ #include "GPU.h" #include "debug.h" #include "render3D.h" -#include "gfx3d.h" #include "GPU_osd.h" #include "debug.h" #include "NDSSystem.h" -#include "readwrite.h" ARM9_struct ARM9Mem; @@ -79,6 +77,15 @@ OSDCLASS *osdB = NULL; u16 gpu_angle = 0; +const short sizeTab[4][4][2] = +{ + {{256,256}, {512, 256}, {256, 512}, {512, 512}}, + {{128,128}, {256, 256}, {512, 512}, {1024, 1024}}, + {{128,128}, {256, 256}, {512, 256}, {512, 512}}, + {{512,1024}, {1024, 512}, {0, 0}, {0, 0}}, +// {{0, 0}, {0, 0}, {0, 0}, {0, 0}} +}; + const size sprSizeTab[4][4] = { {{8, 8}, {16, 8}, {8, 16}, {8, 8}}, @@ -87,53 +94,34 @@ const size sprSizeTab[4][4] = {{64, 64}, {64, 32}, {32, 64}, {8, 8}}, }; - - -static const BGType mode2type[8][4] = +const s8 mode2type[8][4] = { - {BGType_Text, BGType_Text, BGType_Text, BGType_Text}, - {BGType_Text, BGType_Text, BGType_Text, BGType_Affine}, - {BGType_Text, BGType_Text, BGType_Affine, BGType_Affine}, - {BGType_Text, BGType_Text, BGType_Text, BGType_AffineExt}, - {BGType_Text, BGType_Text, BGType_Affine, BGType_AffineExt}, - {BGType_Text, BGType_Text, BGType_AffineExt, BGType_AffineExt}, - {BGType_Invalid, BGType_Invalid, BGType_Large8bpp, BGType_Invalid}, - {BGType_Invalid, BGType_Invalid, BGType_Invalid, BGType_Invalid} -}; - -const short sizeTab[8][4][2] = -{ - {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, //Invalid - {{256,256}, {512,256}, {256,512}, {512,512}}, //text - {{128,128}, {256,256}, {512,512}, {1024,1024}}, //affine - {{512,1024}, {1024,512}, {0,0}, {0,0}}, //large 8bpp - {{0, 0}, {0, 0}, {0, 0}, {0, 0}}, //affine ext (to be elaborated with another value) - {{128,128}, {256,256}, {512,512}, {1024,1024}}, //affine ext 256x16 - {{128,128}, {256,256}, {512,256}, {512,512}}, //affine ext 256x1 - {{128,128}, {256,256}, {512,256}, {512,512}}, //affine ext direct + {0, 0, 0, 0}, + {0, 0, 0, 1}, + {0, 0, 1, 1}, + {0, 0, 0, 1}, + {0, 0, 1, 1}, + {0, 0, 1, 1}, + {3, 3, 2, 3}, + {0, 0, 0, 0} }; void lineText(GPU * gpu); void lineRot(GPU * gpu); void lineExtRot(GPU * gpu); -void lineNull(GPU * gpu); -void lineLarge8bpp(GPU * gpu); -void GPU::modeRender(int layer) +typedef void (*TModeRender)(GPU * gpu); +TModeRender modeRender[8][4] = { - switch(mode2type[dispCnt().BG_Mode][layer]) - { - case BGType_Text: lineText(this); break; - case BGType_Affine: lineRot(this); break; - case BGType_AffineExt: lineExtRot(this); break; - case BGType_Large8bpp: lineExtRot(this); break; - case BGType_Invalid: - PROGINFO("Attempting to render an invalid BG type\n"); - break; - default: - break; - } -} + {lineText, lineText, lineText, lineText}, //0 + {lineText, lineText, lineText, lineRot}, //1 + {lineText, lineText, lineRot, lineRot}, //2 + {lineText, lineText, lineText, lineExtRot}, //3 + {lineText, lineText, lineRot, lineExtRot}, //4 + {lineText, lineText, lineExtRot, lineExtRot}, //5 + {lineText, lineText, lineText, lineText}, //6 + {lineText, lineText, lineText, lineText}, //7 +}; static GraphicsInterface_struct *GFXCore=NULL; @@ -143,397 +131,6 @@ GraphicsInterface_struct *GFXCoreList[] = { NULL }; -static const CACHE_ALIGN u8 win_empty[256] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; -static CACHE_ALIGN u16 fadeInColors[17][0x8000]; -static CACHE_ALIGN u16 fadeOutColors[17][0x8000]; - -//this should be public, because it gets used somewhere else -CACHE_ALIGN u8 gpuBlendTable555[17][17][32][32]; - - -/*****************************************************************************/ -// PIXEL RENDERING - 3D -/*****************************************************************************/ - -#define DECL3D \ - int x = dstX; \ - int passing = dstX<<1; \ - u16 color = _3dColorLine[srcX]; \ - u8 alpha = _3dAlphaLine[srcX]; \ - u8* dst = currDst; - -FORCEINLINE void GPU::setFinal3DColorSpecialNone(int dstX, int srcX) -{ - DECL3D; - - // We must blend if the 3D layer has the highest prio - if((alpha < 16) && bg0HasHighestPrio) - { - int bg_under = bgPixels[dstX]; - u16 final = color; - - // If the layer we are drawing on is selected as 2nd source, we can blend - if(BLDCNT & (0x100 << bg_under)) - { - { - COLOR c1, c2, cfinal; - - c1.val = color; - c2.val = T2ReadWord(dst, passing); - - cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); - cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); - cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); - - final = cfinal.val; - } - } - - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - else - { - T2WriteWord(dst, passing, (color | 0x8000)); - bgPixels[x] = 0; - } -} - -FORCEINLINE void GPU::setFinal3DColorSpecialBlend(int dstX, int srcX) -{ - DECL3D; - - // We can blend if the 3D layer is selected as 1st target, - //but also if the 3D layer has the highest prio. - if((alpha < 16) && ((BLDCNT & 0x1) || bg0HasHighestPrio)) - { - int bg_under = bgPixels[x]; - u16 final = color; - - //If the layer we are drawing on is selected as 2nd source, we can blend - if(BLDCNT & (0x100 << bg_under)) - { - { - COLOR c1, c2, cfinal; - - c1.val = color; - c2.val = T2ReadWord(dst, passing); - - cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); - cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); - cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); - - final = cfinal.val; - } - } - - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - else - { - T2WriteWord(dst, passing, (color | 0x8000)); - bgPixels[x] = 0; - } -} - -FORCEINLINE void GPU::setFinal3DColorSpecialIncrease(int dstX, int srcX) -{ - DECL3D; - u16 final = color; - - // We must blend if the 3D layer has the highest prio - // But it doesn't seem to have priority over fading, - // unlike semi-transparent sprites - if((alpha < 16) && bg0HasHighestPrio) - { - int bg_under = bgPixels[x]; - - /* If the layer we are drawing on is selected as 2nd source, we can blend */ - if(BLDCNT & (0x100 << bg_under)) - { - { - COLOR c1, c2, cfinal; - - c1.val = color; - c2.val = T2ReadWord(dst, passing); - - cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); - cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); - cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); - - final = cfinal.val; - } - } - } - - if(BLDCNT & 0x1) - { - if (BLDY_EVY != 0x0) - { - final = fadeInColors[BLDY_EVY][final&0x7FFF]; - } - - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - else - { - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } -} - -FORCEINLINE void GPU::setFinal3DColorSpecialDecrease(int dstX, int srcX) -{ - DECL3D; - - u16 final = color; - - // We must blend if the 3D layer has the highest prio - // But it doesn't seem to have priority over fading - // unlike semi-transparent sprites - if((alpha < 16) && bg0HasHighestPrio) - { - int bg_under = bgPixels[x]; - - // If the layer we are drawing on is selected as 2nd source, we can blend - if(BLDCNT & (0x100 << bg_under)) - { - { - COLOR c1, c2, cfinal; - - c1.val = color; - c2.val = T2ReadWord(dst, passing); - - cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); - cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); - cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); - - final = cfinal.val; - } - } - } - - if(BLDCNT & 0x1) - { - if (BLDY_EVY != 0x0) - { - final = fadeOutColors[BLDY_EVY][final&0x7FFF]; - } - - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - else - { - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } -} - -FORCEINLINE void GPU::setFinal3DColorSpecialNoneWnd(int dstX, int srcX) -{ - DECL3D; - - bool windowDraw = true, windowEffect = true; - - renderline_checkWindows(x, windowDraw, windowEffect); - - if(windowDraw) - { - // We must blend if the 3D layer has the highest prio - if((alpha < 16) && bg0HasHighestPrio) - { - int bg_under = bgPixels[x]; - u16 final = color; - - // If the layer we are drawing on is selected as 2nd source, we can blend - if(BLDCNT & (0x100 << bg_under)) - { - { - COLOR c1, c2, cfinal; - - c1.val = color; - c2.val = T2ReadWord(dst, passing); - - cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); - cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); - cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); - - final = cfinal.val; - } - } - - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - else - { - T2WriteWord(dst, passing, (color | 0x8000)); - bgPixels[x] = 0; - } - } -} - -FORCEINLINE void GPU::setFinal3DColorSpecialBlendWnd(int dstX, int srcX) -{ - DECL3D; - - bool windowDraw = true, windowEffect = true; - - renderline_checkWindows(x, windowDraw, windowEffect); - - if(windowDraw) - { - // We can blend if the 3D layer is selected as 1st target, - // but also if the 3D layer has the highest prio. - if((alpha < 16) && (((BLDCNT & 0x1) && windowEffect) || bg0HasHighestPrio)) - { - int bg_under = bgPixels[x]; - u16 final = color; - - // If the layer we are drawing on is selected as 2nd source, we can blend - if(BLDCNT & (0x100 << bg_under)) - { - { - COLOR c1, c2, cfinal; - - c1.val = color; - c2.val = T2ReadWord(dst, passing); - - cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); - cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); - cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); - - final = cfinal.val; - } - } - - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - else - { - T2WriteWord(dst, passing, (color | 0x8000)); - bgPixels[x] = 0; - } - } -} - -FORCEINLINE void GPU::setFinal3DColorSpecialIncreaseWnd(int dstX, int srcX) -{ - DECL3D; - - bool windowDraw = true, windowEffect = true; - u16 final = color; - - renderline_checkWindows(x, windowDraw, windowEffect); - - if(windowDraw) - { - // We must blend if the 3D layer has the highest prio - // But it doesn't seem to have priority over fading, - // unlike semi-transparent sprites - if((alpha < 16) && bg0HasHighestPrio) - { - int bg_under = bgPixels[x]; - - // If the layer we are drawing on is selected as 2nd source, we can blend - if(BLDCNT & (0x100 << bg_under)) - { - { - COLOR c1, c2, cfinal; - - c1.val = color; - c2.val = T2ReadWord(dst, passing); - - cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); - cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); - cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); - - final = cfinal.val; - } - } - } - - if((BLDCNT & 0x1) && windowEffect) - { - if (BLDY_EVY != 0x0) - { - final = fadeInColors[BLDY_EVY][final&0x7FFF]; - } - - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - else - { - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - } -} - -FORCEINLINE void GPU::setFinal3DColorSpecialDecreaseWnd(int dstX, int srcX) -{ - DECL3D; - - bool windowDraw = true, windowEffect = true; - u16 final = color; - - renderline_checkWindows(x, windowDraw, windowEffect); - - if(windowDraw) - { - // We must blend if the 3D layer has the highest prio - // But it doesn't seem to have priority over fading, - // unlike semi-transparent sprites - if((alpha < 16) && bg0HasHighestPrio) - { - int bg_under = bgPixels[x]; - - // If the layer we are drawing on is selected as 2nd source, we can blend - if(BLDCNT & (0x100 << bg_under)) - { - { - COLOR c1, c2, cfinal; - - c1.val = color; - c2.val = T2ReadWord(dst, passing); - - cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); - cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); - cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); - - final = cfinal.val; - } - } - } - - if((BLDCNT & 0x1) && windowEffect) - { - if (BLDY_EVY != 0x0) - { - final = fadeOutColors[BLDY_EVY][final&0x7FFF]; - } - - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - else - { - T2WriteWord(dst, passing, (final | 0x8000)); - bgPixels[x] = 0; - } - } -} - - static void setFinalOBJColorSpecialNone (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u8 type, u16 x); static void setFinalOBJColorSpecialBlend (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u8 type, u16 x); static void setFinalOBJColorSpecialIncrease (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u8 type, u16 x); @@ -543,6 +140,16 @@ static void setFinalOBJColorSpecialBlendWnd (GPU *gpu, u32 passing, u8 *dst, u1 static void setFinalOBJColorSpecialIncreaseWnd (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u8 type, u16 x); static void setFinalOBJColorSpecialDecreaseWnd (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u8 type, u16 x); +static void setFinal3DColorSpecialNone (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x); +static void setFinal3DColorSpecialBlend (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x); +static void setFinal3DColorSpecialIncrease (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x); +static void setFinal3DColorSpecialDecrease (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x); +static void setFinal3DColorSpecialNoneWnd (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x); +static void setFinal3DColorSpecialBlendWnd (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x); +static void setFinal3DColorSpecialIncreaseWnd (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x); +static void setFinal3DColorSpecialDecreaseWnd (GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x); + + const GPU::FinalOBJColFunct pixelBlittersOBJ[8] = { setFinalOBJColorSpecialNone, setFinalOBJColorSpecialBlend, @@ -553,6 +160,24 @@ const GPU::FinalOBJColFunct pixelBlittersOBJ[8] = { setFinalOBJColorSpecialIncreaseWnd, setFinalOBJColorSpecialDecreaseWnd,}; +const GPU::Final3DColFunct pixelBlitters3D[8] = { + setFinal3DColorSpecialNone, + setFinal3DColorSpecialBlend, + setFinal3DColorSpecialIncrease, + setFinal3DColorSpecialDecrease, + setFinal3DColorSpecialNoneWnd, + setFinal3DColorSpecialBlendWnd, + setFinal3DColorSpecialIncreaseWnd, + setFinal3DColorSpecialDecreaseWnd}; + +static const CACHE_ALIGN u8 win_empty[256] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +static CACHE_ALIGN u16 fadeInColors[17][0x8000]; +static CACHE_ALIGN u16 fadeOutColors[17][0x8000]; +CACHE_ALIGN u8 gpuBlendTable555[17][17][32][32]; /*****************************************************************************/ // INITIALIZATION @@ -611,6 +236,9 @@ static void GPU_InitFadeColors() } } +static u16 line3Dcolor[512]; +static u8 line3Dalpha[512]; + GPU * GPU_Init(u8 l) { GPU * g; @@ -621,13 +249,17 @@ GPU * GPU_Init(u8 l) GPU_Reset(g, l); GPU_InitFadeColors(); + //clear out the excess line buffers (beyond x=255) + memset(line3Dcolor+256, 0, 256*sizeof(u16)); + memset(line3Dalpha+256, 0, 256*sizeof(u8)); + g->curr_win[0] = win_empty; g->curr_win[1] = win_empty; g->need_update_winh[0] = true; g->need_update_winh[1] = true; g->setFinalColorBck_funcNum = 0; - g->setFinalColor3d_funcNum = 0; g->setFinalColorSpr = setFinalOBJColorSpecialNone; + g->setFinalColor3D = setFinal3DColorSpecialNone; return g; } @@ -637,8 +269,8 @@ void GPU_Reset(GPU *g, u8 l) memset(g, 0, sizeof(GPU)); g->setFinalColorBck_funcNum = 0; - g->setFinalColor3d_funcNum = 0; g->setFinalColorSpr = setFinalOBJColorSpecialNone; + g->setFinalColor3D = setFinal3DColorSpecialNone; g->core = l; g->BGSize[0][0] = g->BGSize[1][0] = g->BGSize[2][0] = g->BGSize[3][0] = 256; g->BGSize[0][1] = g->BGSize[1][1] = g->BGSize[2][1] = g->BGSize[3][1] = 256; @@ -781,7 +413,7 @@ void SetupFinalPixelBlitter (GPU *gpu) gpu->setFinalColorSpr = pixelBlittersOBJ[windowUsed*4 + blendMode]; gpu->setFinalColorBck_funcNum = windowUsed*4 + blendMode; - gpu->setFinalColor3d_funcNum = windowUsed*4 + blendMode; + gpu->setFinalColor3D = pixelBlitters3D[windowUsed*4 + blendMode]; } @@ -852,11 +484,13 @@ void GPU_setVideoProp(GPU * gpu, u32 p) //GPU_resortBGs(gpu); } -//this handles writing in BGxCNT +/* this is writing in BGxCNT */ +/* FIXME: all DEBUG_TRI are broken */ void GPU_setBGProp(GPU * gpu, u16 num, u16 p) { struct _BGxCNT * cnt = &((gpu->dispx_st)->dispx_BGxCNT[num].bits); struct _DISPCNT * dispCnt = &(gpu->dispx_st)->dispx_DISPCNT.bits; + int mode; T1WriteWord((u8 *)&(gpu->dispx_st)->dispx_BGxCNT[num].val, 0, p); @@ -866,15 +500,13 @@ void GPU_setBGProp(GPU * gpu, u16 num, u16 p) { gpu->BG_tile_ram[num] = ARM9MEM_BBG; gpu->BG_bmp_ram[num] = ARM9MEM_BBG; - gpu->BG_bmp_large_ram[num] = ARM9MEM_BBG; gpu->BG_map_ram[num] = ARM9MEM_BBG; } else { - gpu->BG_tile_ram[num] = ARM9MEM_ABG + dispCnt->CharacBase_Block * ADDRESS_STEP_64KB ; + gpu->BG_tile_ram[num] = ARM9MEM_ABG + dispCnt->CharacBase_Block * ADDRESS_STEP_64kB ; gpu->BG_bmp_ram[num] = ARM9MEM_ABG; - gpu->BG_bmp_large_ram[num] = ARM9MEM_ABG; - gpu->BG_map_ram[num] = ARM9MEM_ABG + dispCnt->ScreenBase_Block * ADDRESS_STEP_64KB; + gpu->BG_map_ram[num] = ARM9MEM_ABG + dispCnt->ScreenBase_Block * ADDRESS_STEP_64kB; } gpu->BG_tile_ram[num] += (cnt->CharacBase_Block * ADDRESS_STEP_16KB); @@ -893,30 +525,7 @@ void GPU_setBGProp(GPU * gpu, u16 num, u16 p) break; } - BGType mode = mode2type[dispCnt->BG_Mode][num]; - - //clarify affine ext modes - if(mode == BGType_AffineExt) - { - //see: http://nocash.emubase.de/gbatek.htm#dsvideobgmodescontrol - u8 affineModeSelection = (cnt->Palette_256 << 1) | (cnt->CharacBase_Block & 1) ; - switch(affineModeSelection) - { - case 0: - case 1: - mode = BGType_AffineExt_256x16; - break; - case 2: - mode = BGType_AffineExt_256x1; - break; - case 3: - mode = BGType_AffineExt_Direct; - break; - } - } - - gpu->BGTypes[num] = mode; - + mode = mode2type[dispCnt->BG_Mode][num]; gpu->BGSize[num][0] = sizeTab[mode][cnt->ScreenSize][0]; gpu->BGSize[num][1] = sizeTab[mode][cnt->ScreenSize][1]; @@ -1426,9 +1035,364 @@ static void setFinalOBJColorSpecialDecreaseWnd(GPU *gpu, u32 passing, u8 *dst, u } } +/*****************************************************************************/ +// PIXEL RENDERING - 3D +/*****************************************************************************/ + +static void setFinal3DColorSpecialNone(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x) +{ + /* We must blend if the 3D layer has the highest prio */ + if((alpha < 16) && gpu->bg0HasHighestPrio) + { + int bg_under = gpu->bgPixels[x]; + u16 final = color; + + /* If the layer we are drawing on is selected as 2nd source, we can blend */ + if(gpu->BLDCNT & (0x100 << bg_under)) + { + { + COLOR c1, c2, cfinal; + + c1.val = color; + c2.val = T2ReadWord(dst, passing); + + cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); + cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); + cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); + + final = cfinal.val; + } + } + + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + else + { + T2WriteWord(dst, passing, (color | 0x8000)); + gpu->bgPixels[x] = 0; + } +} + +static void setFinal3DColorSpecialBlend(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x) +{ + /* We can blend if the 3D layer is selected as 1st target, */ + /* but also if the 3D layer has the highest prio. */ + if((alpha < 16) && ((gpu->BLDCNT & 0x1) || gpu->bg0HasHighestPrio)) + { + int bg_under = gpu->bgPixels[x]; + u16 final = color; + + /* If the layer we are drawing on is selected as 2nd source, we can blend */ + if(gpu->BLDCNT & (0x100 << bg_under)) + { + { + COLOR c1, c2, cfinal; + + c1.val = color; + c2.val = T2ReadWord(dst, passing); + + cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); + cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); + cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); + + final = cfinal.val; + } + } + + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + else + { + T2WriteWord(dst, passing, (color | 0x8000)); + gpu->bgPixels[x] = 0; + } +} + +static void setFinal3DColorSpecialIncrease(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x) +{ + u16 final = color; + + /* We must blend if the 3D layer has the highest prio */ + /* But it doesn't seem to have priority over fading, */ + /* unlike semi-transparent sprites */ + if((alpha < 16) && gpu->bg0HasHighestPrio) + { + int bg_under = gpu->bgPixels[x]; + + /* If the layer we are drawing on is selected as 2nd source, we can blend */ + if(gpu->BLDCNT & (0x100 << bg_under)) + { + { + COLOR c1, c2, cfinal; + + c1.val = color; + c2.val = T2ReadWord(dst, passing); + + cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); + cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); + cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); + + final = cfinal.val; + } + } + } + + if(gpu->BLDCNT & 0x1) + { + if (gpu->BLDY_EVY != 0x0) + { + final = fadeInColors[gpu->BLDY_EVY][final&0x7FFF]; + } + + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + else + { + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } +} + +static void setFinal3DColorSpecialDecrease(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x) +{ + u16 final = color; + + /* We must blend if the 3D layer has the highest prio */ + /* But it doesn't seem to have priority over fading, */ + /* unlike semi-transparent sprites */ + if((alpha < 16) && gpu->bg0HasHighestPrio) + { + int bg_under = gpu->bgPixels[x]; + + /* If the layer we are drawing on is selected as 2nd source, we can blend */ + if(gpu->BLDCNT & (0x100 << bg_under)) + { + { + COLOR c1, c2, cfinal; + + c1.val = color; + c2.val = T2ReadWord(dst, passing); + + cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); + cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); + cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); + + final = cfinal.val; + } + } + } + + if(gpu->BLDCNT & 0x1) + { + if (gpu->BLDY_EVY != 0x0) + { + final = fadeOutColors[gpu->BLDY_EVY][final&0x7FFF]; + } + + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + else + { + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } +} + +static void setFinal3DColorSpecialNoneWnd(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x) +{ + bool windowDraw = true, windowEffect = true; + + gpu->renderline_checkWindows(x, windowDraw, windowEffect); + + if(windowDraw) + { + /* We must blend if the 3D layer has the highest prio */ + if((alpha < 16) && gpu->bg0HasHighestPrio) + { + int bg_under = gpu->bgPixels[x]; + u16 final = color; + + /* If the layer we are drawing on is selected as 2nd source, we can blend */ + if(gpu->BLDCNT & (0x100 << bg_under)) + { + { + COLOR c1, c2, cfinal; + + c1.val = color; + c2.val = T2ReadWord(dst, passing); + + cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); + cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); + cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); + + final = cfinal.val; + } + } + + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + else + { + T2WriteWord(dst, passing, (color | 0x8000)); + gpu->bgPixels[x] = 0; + } + } +} + +static void setFinal3DColorSpecialBlendWnd(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x) +{ + bool windowDraw = true, windowEffect = true; + + gpu->renderline_checkWindows(x, windowDraw, windowEffect); + + if(windowDraw) + { + /* We can blend if the 3D layer is selected as 1st target, */ + /* but also if the 3D layer has the highest prio. */ + if((alpha < 16) && (((gpu->BLDCNT & 0x1) && windowEffect) || gpu->bg0HasHighestPrio)) + { + int bg_under = gpu->bgPixels[x]; + u16 final = color; + + /* If the layer we are drawing on is selected as 2nd source, we can blend */ + if(gpu->BLDCNT & (0x100 << bg_under)) + { + { + COLOR c1, c2, cfinal; + + c1.val = color; + c2.val = T2ReadWord(dst, passing); + + cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); + cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); + cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); + + final = cfinal.val; + } + } + + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + else + { + T2WriteWord(dst, passing, (color | 0x8000)); + gpu->bgPixels[x] = 0; + } + } +} + +static void setFinal3DColorSpecialIncreaseWnd(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x) +{ + bool windowDraw = true, windowEffect = true; + u16 final = color; + + gpu->renderline_checkWindows(x, windowDraw, windowEffect); + + if(windowDraw) + { + /* We must blend if the 3D layer has the highest prio */ + /* But it doesn't seem to have priority over fading, */ + /* unlike semi-transparent sprites */ + if((alpha < 16) && gpu->bg0HasHighestPrio) + { + int bg_under = gpu->bgPixels[x]; + + /* If the layer we are drawing on is selected as 2nd source, we can blend */ + if(gpu->BLDCNT & (0x100 << bg_under)) + { + { + COLOR c1, c2, cfinal; + + c1.val = color; + c2.val = T2ReadWord(dst, passing); + + cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); + cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); + cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); + + final = cfinal.val; + } + } + } + + if((gpu->BLDCNT & 0x1) && windowEffect) + { + if (gpu->BLDY_EVY != 0x0) + { + final = fadeInColors[gpu->BLDY_EVY][final&0x7FFF]; + } + + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + else + { + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + } +} + +static void setFinal3DColorSpecialDecreaseWnd(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x) +{ + bool windowDraw = true, windowEffect = true; + u16 final = color; + + gpu->renderline_checkWindows(x, windowDraw, windowEffect); + + if(windowDraw) + { + /* We must blend if the 3D layer has the highest prio */ + /* But it doesn't seem to have priority over fading, */ + /* unlike semi-transparent sprites */ + if((alpha < 16) && gpu->bg0HasHighestPrio) + { + int bg_under = gpu->bgPixels[x]; + + /* If the layer we are drawing on is selected as 2nd source, we can blend */ + if(gpu->BLDCNT & (0x100 << bg_under)) + { + { + COLOR c1, c2, cfinal; + + c1.val = color; + c2.val = T2ReadWord(dst, passing); + + cfinal.bits.red = ((c1.bits.red * alpha / 16) + (c2.bits.red * (16 - alpha) / 16)); + cfinal.bits.green = ((c1.bits.green * alpha / 16) + (c2.bits.green * (16 - alpha) / 16)); + cfinal.bits.blue = ((c1.bits.blue * alpha / 16) + (c2.bits.blue * (16 - alpha) / 16)); + + final = cfinal.val; + } + } + } + + if((gpu->BLDCNT & 0x1) && windowEffect) + { + if (gpu->BLDY_EVY != 0x0) + { + final = fadeOutColors[gpu->BLDY_EVY][final&0x7FFF]; + } + + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + else + { + T2WriteWord(dst, passing, (final | 0x8000)); + gpu->bgPixels[x] = 0; + } + } +} + FORCEINLINE void GPU::setFinalColorBG(u16 color, u8 x) { - //if someone disagrees with these, they could be reimplemented as a function pointer easily switch(setFinalColorBck_funcNum | (blend1?8:0)) { case 0x0: setFinalBGColorSpecialNone(color,x,false); break; @@ -1451,22 +1415,6 @@ FORCEINLINE void GPU::setFinalColorBG(u16 color, u8 x) } -FORCEINLINE void GPU::setFinalColor3d(int dstX, int srcX) -{ - //if someone disagrees with these, they could be reimplemented as a function pointer easily - switch(setFinalColor3d_funcNum) - { - case 0x0: setFinal3DColorSpecialNone(dstX,srcX); break; - case 0x1: setFinal3DColorSpecialBlend(dstX,srcX); break; - case 0x2: setFinal3DColorSpecialIncrease(dstX,srcX); break; - case 0x3: setFinal3DColorSpecialDecrease(dstX,srcX); break; - case 0x4: setFinal3DColorSpecialNoneWnd(dstX,srcX); break; - case 0x5: setFinal3DColorSpecialBlendWnd(dstX,srcX); break; - case 0x6: setFinal3DColorSpecialIncreaseWnd(dstX,srcX); break; - case 0x7: setFinal3DColorSpecialDecreaseWnd(dstX,srcX); break; - }; -} - //this was forced inline because most of the time it just falls through to setFinalColorBck() and the function call //overhead was ridiculous and terrible FORCEINLINE void GPU::__setFinalColorBck(u16 color, u8 x, bool opaque) @@ -1547,39 +1495,6 @@ static void mosaicSpriteLine(GPU * gpu, u16 l, u8 * dst, u8 * dst_alpha, u8 * ty mosaicSpriteLinePixel(gpu,i,l,dst,dst_alpha,typeTab,prioTab); } -void lineLarge8bpp(GPU * gpu) -{ - if(gpu->core == 1) { - PROGINFO("Cannot use large 8bpp screen on sub core\n"); - return; - } - - BGxOFS * ofs = &gpu->dispx_st->dispx_BGxOFS[gpu->currBgNum]; - u8 num = gpu->currBgNum; - u16 XBG = T1ReadWord((u8 *)&ofs->BGxHOFS, 0); - u16 YBG = gpu->currLine + T1ReadWord((u8 *)&ofs->BGxVOFS, 0); - u16 lg = gpu->BGSize[num][0]; - u16 ht = gpu->BGSize[num][1]; - u16 wmask = (lg-1); - u16 hmask = (ht-1); - YBG &= hmask; - - //TODO - handle wrapping / out of bounds correctly from rot_scale_op? - - u32 tmp_map = gpu->BG_bmp_large_ram[num] + lg * YBG; - u8* map = MMU_RenderMapToLCD(tmp_map); - - u8* pal = ARM9Mem.ARM9_VMEM + gpu->core * ADDRESS_STEP_1KB; - - for(int x = 0; x < lg; ++x, ++XBG) - { - XBG &= wmask; - u8 pixel = map[XBG]; - u16 color = T1ReadWord(pal, pixel<<1); - gpu->__setFinalColorBck(color,x,color!=0); - } - -} /*****************************************************************************/ // BACKGROUND RENDERING -TEXT- @@ -1595,9 +1510,8 @@ INLINE void renderline_textBG(GPU * gpu, u16 XBG, u16 YBG, u16 LG) u16 wmask = (lg-1); u16 hmask = (ht-1); u16 tmp = ((YBG & hmask) >> 3); - u32 map; - u8 *pal, *line; - u32 tile; + u8 *map = NULL; + u8 *tile, *pal, *line; u16 color; u16 xoff; u16 yoff; @@ -1605,19 +1519,18 @@ INLINE void renderline_textBG(GPU * gpu, u16 XBG, u16 YBG, u16 LG) u16 xfin; s8 line_dir = 1; - u32 mapinfo; + u8 * mapinfo; TILEENTRY tileentry; u32 tmp_map = gpu->BG_map_ram[num] + (tmp&31) * 64; if(tmp>31) tmp_map+= ADDRESS_STEP_512B << bgCnt->ScreenSize ; - //map = (u8*)MMU_RenderMapToLCD(tmp_map); - map = tmp_map; - //if(!map) return; // no map + map = (u8*)MMU_RenderMapToLCD(tmp_map); + if(!map) return; // no map - tile = gpu->BG_tile_ram[num]; - //if(!tile) return; // no tiles + tile = (u8*) MMU_RenderMapToLCD(gpu->BG_tile_ram[num]); + if(!tile) return; // no tiles xoff = XBG; pal = ARM9Mem.ARM9_VMEM + gpu->core * ADDRESS_STEP_1KB; @@ -1632,11 +1545,11 @@ INLINE void renderline_textBG(GPU * gpu, u16 XBG, u16 YBG, u16 LG) tmp = ((xoff&wmask)>>3); mapinfo = map + (tmp&0x1F) * 2; if(tmp>31) mapinfo += 32*32*2; - tileentry.val = T1ReadWord(MMU_gpu_map(mapinfo), 0); + tileentry.val = T1ReadWord(mapinfo, 0); tilePalette = (tileentry.bits.Palette*16); - line = (u8*)MMU_gpu_map(tile + (tileentry.bits.TileNum * 0x20) + ((tileentry.bits.VFlip) ? (7*4)-yoff : yoff)); + line = (u8 * )tile + (tileentry.bits.TileNum * 0x20) + ((tileentry.bits.VFlip) ? (7*4)-yoff : yoff); if(tileentry.bits.HFlip) { @@ -1695,9 +1608,9 @@ INLINE void renderline_textBG(GPU * gpu, u16 XBG, u16 YBG, u16 LG) tmp = (xoff & (lg-1))>>3; mapinfo = map + (tmp & 31) * 2; if(tmp > 31) mapinfo += 32*32*2; - tileentry.val = T1ReadWord(MMU_gpu_map(mapinfo), 0); + tileentry.val = T1ReadWord(mapinfo, 0); - line = (u8*)MMU_gpu_map(tile + (tileentry.bits.TileNum*0x40) + ((tileentry.bits.VFlip) ? (7*8)-yoff : yoff)); + line = (u8 * )tile + (tileentry.bits.TileNum*0x40) + ((tileentry.bits.VFlip) ? (7*8)-yoff : yoff); if(tileentry.bits.HFlip) { @@ -1837,10 +1750,15 @@ FORCEINLINE void extRotBG2(GPU * gpu, s32 X, s32 Y, s16 PA, s16 PB, s16 PC, s16 struct _DISPCNT * dispCnt = &(gpu->dispx_st)->dispx_DISPCNT.bits; u8 *map, *tile, *pal; + u8 affineModeSelection ; - switch(gpu->BGTypes[num]) + /* see: http://nocash.emubase.de/gbatek.htm#dsvideobgmodescontrol */ + affineModeSelection = (bgCnt->Palette_256 << 1) | (bgCnt->CharacBase_Block & 1) ; +// printf("extrot mode %d\n", affineModeSelection); + switch(affineModeSelection) { - case BGType_AffineExt_256x16: + case 0 : + case 1 : map = (u8 *)MMU_RenderMapToLCD(gpu->BG_map_ram[num]); if (!map) return; tile = (u8 *)MMU_RenderMapToLCD(gpu->BG_tile_ram[num]); @@ -1853,27 +1771,19 @@ FORCEINLINE void extRotBG2(GPU * gpu, s32 X, s32 Y, s16 PA, s16 PB, s16 PC, s16 // 16 bit bgmap entries apply_rot_fun(gpu,X,Y,PA,PB,PC,PD,LG, map, tile, pal, dispCnt->ExBGxPalette_Enable); return; - case BGType_AffineExt_256x1: + case 2 : // 256 colors map = (u8 *)MMU_RenderMapToLCD(gpu->BG_bmp_ram[num]); if (!map) return; pal = ARM9Mem.ARM9_VMEM + gpu->core * 0x400; apply_rot_fun(gpu,X,Y,PA,PB,PC,PD,LG, map, NULL, pal, 0); return; - case BGType_AffineExt_Direct: + case 3 : // direct colors / BMP map = (u8 *)MMU_RenderMapToLCD(gpu->BG_bmp_ram[num]); if (!map) return; apply_rot_fun(gpu,X,Y,PA,PB,PC,PD,LG, map, NULL, NULL, 0); return; - case BGType_Large8bpp: - // large screen 256 colors - map = (u8 *)MMU_RenderMapToLCD(gpu->BG_bmp_large_ram[num]); - if (!map) return; - pal = ARM9Mem.ARM9_VMEM + gpu->core * 0x400; - apply_rot_fun(gpu,X,Y,PA,PB,PC,PD,LG, map, NULL, pal, 0); - return; - default: break; } } @@ -1881,10 +1791,6 @@ FORCEINLINE void extRotBG2(GPU * gpu, s32 X, s32 Y, s16 PA, s16 PB, s16 PC, s16 // BACKGROUND RENDERING -HELPER FUNCTIONS- /*****************************************************************************/ -void lineNull(GPU * gpu) -{ -} - void lineText(GPU * gpu) { BGxOFS * ofs = &gpu->dispx_st->dispx_BGxOFS[gpu->currBgNum]; @@ -2222,17 +2128,10 @@ void GPU::_spriteRender(u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab) blockparameter = (spriteInfo->RotScalIndex + (spriteInfo->HFlip<< 3) + (spriteInfo->VFlip << 4))*4; // Get rotation/scale parameters -#ifdef WORDS_BIGENDIAN - dx = ((s16)(gpu->oam + blockparameter+0)->attr31 << 8) | ((s16)(gpu->oam + blockparameter+0)->attr30); - dmx = ((s16)(gpu->oam + blockparameter+1)->attr31 << 8) | ((s16)(gpu->oam + blockparameter+1)->attr30); - dy = ((s16)(gpu->oam + blockparameter+2)->attr31 << 8) | ((s16)(gpu->oam + blockparameter+2)->attr30); - dmy = ((s16)(gpu->oam + blockparameter+3)->attr31 << 8) | ((s16)(gpu->oam + blockparameter+3)->attr30); -#else dx = (s16)(gpu->oam + blockparameter+0)->attr3; dmx = (s16)(gpu->oam + blockparameter+1)->attr3; dy = (s16)(gpu->oam + blockparameter+2)->attr3; dmy = (s16)(gpu->oam + blockparameter+3)->attr3; -#endif // Calculate fixed poitn 8.8 start offsets realX = ((sprSize.x) << 7) - (fieldX >> 1)*dx - (fieldY>>1)*dmx + y * dmx; @@ -2386,7 +2285,7 @@ void GPU::_spriteRender(u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab) if(colour && (prioTab[sprX]>=prio)) { - T2WriteWord(dst, (sprX<<1), LE_TO_LOCAL_16(T2ReadWord(pal, colour << 1))); + T2WriteWord(dst, (sprX<<1), T2ReadWord(pal, (colour<<1))); dst_alpha[sprX] = 16; typeTab[sprX] = spriteInfo->Mode; prioTab[sprX] = prio; @@ -2447,10 +2346,7 @@ void GPU::_spriteRender(u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab) //NOT TESTED: if (dispCnt->OBJ_BMP_2D_dim) // 256*256 - { - //verified by heroes of mana FMV intro src = (u8 *)MMU_RenderMapToLCD(gpu->sprMem + (((spriteInfo->TileIndex&0x3E0) * 64 + (spriteInfo->TileIndex&0x1F) *8 + ( y << 8)) << 1)); - } else // 128 * 512 src = (u8 *)MMU_RenderMapToLCD(gpu->sprMem + (((spriteInfo->TileIndex&0x3F0) * 64 + (spriteInfo->TileIndex&0x0F) *8 + ( y << 8)) << 1)); } @@ -2791,25 +2687,23 @@ static void GPU_ligne_layer(NDS_Screen * screen, u16 l) BGxOFS *bgofs = &gpu->dispx_st->dispx_BGxOFS[i16]; u16 hofs = (T1ReadWord((u8*)&bgofs->BGxHOFS, 0) & 0x1FF); - gfx3d_GetLineData(l, &gpu->_3dColorLine, &gpu->_3dAlphaLine); - u16* colorLine = gpu->_3dColorLine; + //line3Dcolor and line3Dalpha are left cleared by GPU initialization, + //and they always stay that way. + + gpu3D->NDS_3D_GetLine(l, line3Dcolor, line3Dalpha); for(int k = 0; k < 256; k++) { int q = ((k + hofs) & 0x1FF); - if((q < 0) || (q > 255)) - continue; - - if(colorLine[q] & 0x8000) - gpu->setFinalColor3d(k, q); + if(line3Dcolor[q] & 0x8000) + gpu->setFinalColor3D(gpu, (k << 1), gpu->currDst, line3Dcolor[q], line3Dalpha[q], k); } continue; } } - //if(gpu->core == 1 && i16 != 1) continue; - gpu->modeRender(i16); + modeRender[dispCnt->BG_Mode][i16](gpu); } //layer enabled } } @@ -2891,9 +2785,9 @@ static void GPU_ligne_DispCapture(u16 l) case 1: // Capture 3D { //INFO("Capture 3D\n"); - u16* colorLine; - gfx3d_GetLineData(l, &colorLine, NULL); - CAPCOPY(((u8*)colorLine),cap_dst); + u16 cap3DLine[512]; + gpu3D->NDS_3D_GetLineCaptured(l, (u16*)cap3DLine); + CAPCOPY(((u8*)cap3DLine),cap_dst); } break; } @@ -2924,6 +2818,7 @@ static void GPU_ligne_DispCapture(u16 l) //INFO("Capture source is SourceA+B blended\n"); u16 *srcA = NULL; u16 *srcB = NULL; + u16 cap3DLine[512]; if (gpu->dispCapCnt.srcA == 0) { @@ -2935,11 +2830,12 @@ static void GPU_ligne_DispCapture(u16 l) } else { - gfx3d_GetLineData(l, &srcA, NULL); + gpu3D->NDS_3D_GetLineCaptured(l, (u16*)cap3DLine); + srcA = (u16 *)cap3DLine; // 3D screen } if (gpu->dispCapCnt.srcB == 0) // VRAM screen - srcB = (u16 *)((gpu->dispCapCnt.src) + (l * 512)); + srcB = (u16 *)(gpu->dispCapCnt.src) + (l * 512); else srcB = NULL; // DISP FIFOS @@ -2996,12 +2892,11 @@ static INLINE void GPU_ligne_MasterBrightness(NDS_Screen * screen, u16 l) u8 * dst = GPU_tempScreen + (screen->offset + l) * 512; u16 i16; - //isn't it odd that we can set uselessly high factors here? - //factors above 16 change nothing. curious. - int factor = gpu->MasterBrightFactor; - if(factor==0) return; - if(factor>16) factor=16; + if (!gpu->MasterBrightFactor) return; +#ifdef BRIGHT_TABLES + calc_bright_colors(); +#endif // Apply final brightness adjust (MASTER_BRIGHT) // Reference: http://nocash.emubase.de/gbatek.htm#dsvideo (Under MASTER_BRIGHTNESS) @@ -3019,7 +2914,7 @@ static INLINE void GPU_ligne_MasterBrightness(NDS_Screen * screen, u16 l) { for(i16 = 0; i16 < 256; ++i16) { - ((u16*)dst)[i16] = fadeInColors[factor][((u16*)dst)[i16]&0x7FFF]; + ((u16*)dst)[i16] = fadeInColors[gpu->MasterBrightFactor][((u16*)dst)[i16]&0x7FFF]; } break; } @@ -3029,7 +2924,7 @@ static INLINE void GPU_ligne_MasterBrightness(NDS_Screen * screen, u16 l) { for(i16 = 0; i16 < 256; ++i16) { - ((u16*)dst)[i16] = fadeOutColors[factor][((u16*)dst)[i16]&0x7FFF]; + ((u16*)dst)[i16] = fadeOutColors[gpu->MasterBrightFactor][((u16*)dst)[i16]&0x7FFF]; } break; } @@ -3134,16 +3029,17 @@ void GPU_ligne(NDS_Screen * screen, u16 l) //here is some setup which is only done on line 0 if(l == 0) { - //this is speculative. the idea is as follows: - //whenever the user updates the affine start position regs, it goes into the active regs immediately - //(this is handled on the set event from MMU) - //maybe it shouldnt take effect until the next hblank or something.. - //this is a based on a combination of: - //heroes of mana intro FMV - //SPP level 3-8 rotoscale room - //NSMB raster fx backdrops - //bubble bobble revolution classic mode - gpu->refreshAffineStartRegs(); + for(int num=2;num<=3;num++) + { + BGxPARMS * parms; + if (num==2) + parms = &(gpu->dispx_st)->dispx_BG2PARMS; + else + parms = &(gpu->dispx_st)->dispx_BG3PARMS; + + parms->BGxX = gpu->affineInfo[num-2].x; + parms->BGxY = gpu->affineInfo[num-2].y; + } } //cache some parameters which are assumed to be stable throughout the rendering of the entire line @@ -3227,79 +3123,21 @@ void GPU_ligne(NDS_Screen * screen, u16 l) void gpu_savestate(std::ostream* os) { - //version - write32le(0,os); - os->write((char*)GPU_tempScreen,sizeof(GPU_tempScreen)); - - write32le(MainScreen.gpu->affineInfo[0].x,os); - write32le(MainScreen.gpu->affineInfo[0].y,os); - write32le(MainScreen.gpu->affineInfo[1].x,os); - write32le(MainScreen.gpu->affineInfo[1].y,os); - write32le(SubScreen.gpu->affineInfo[0].x,os); - write32le(SubScreen.gpu->affineInfo[0].y,os); - write32le(SubScreen.gpu->affineInfo[1].x,os); - write32le(SubScreen.gpu->affineInfo[1].y,os); } bool gpu_loadstate(std::istream* is) { - //read version - int version; - if(read32le(&version,is) != 1) return false; - if(version != 0) return false; - is->read((char*)GPU_tempScreen,sizeof(GPU_tempScreen)); - read32le(&MainScreen.gpu->affineInfo[0].x,is); - read32le(&MainScreen.gpu->affineInfo[0].y,is); - read32le(&MainScreen.gpu->affineInfo[1].x,is); - read32le(&MainScreen.gpu->affineInfo[1].y,is); - read32le(&SubScreen.gpu->affineInfo[0].x,is); - read32le(&SubScreen.gpu->affineInfo[0].y,is); - read32le(&SubScreen.gpu->affineInfo[1].x,is); - read32le(&SubScreen.gpu->affineInfo[1].y,is); - - MainScreen.gpu->refreshAffineStartRegs(); - SubScreen.gpu->refreshAffineStartRegs(); MainScreen.gpu->updateBLDALPHA(); SubScreen.gpu->updateBLDALPHA(); return !is->fail(); } -u32 GPU::getAffineStart(int layer, int xy) -{ - if(xy==0) return affineInfo[layer-2].x; - else return affineInfo[layer-2].y; -} - -void GPU::setAffineStartWord(int layer, int xy, u16 val, int word) -{ - u32 curr = getAffineStart(layer,xy); - if(word==0) curr = (curr&0xFFFF0000)|val; - else curr = (curr&0x0000FFFF)|(((u32)val)<<16); - setAffineStart(layer,xy,curr); -} - void GPU::setAffineStart(int layer, int xy, u32 val) { if(xy==0) affineInfo[layer-2].x = val; else affineInfo[layer-2].y = val; - refreshAffineStartRegs(); -} - -void GPU::refreshAffineStartRegs() -{ - for(int num=2;num<=3;num++) - { - BGxPARMS * parms; - if (num==2) - parms = &(dispx_st)->dispx_BG2PARMS; - else - parms = &(dispx_st)->dispx_BG3PARMS; - - parms->BGxX = affineInfo[num-2].x; - parms->BGxY = affineInfo[num-2].y; - } } void gpu_UpdateRender() diff --git a/desmume/src/GPU.h b/src/GPU.h similarity index 87% rename from desmume/src/GPU.h rename to src/GPU.h index b226b80f9..936273531 100644 --- a/desmume/src/GPU.h +++ b/src/GPU.h @@ -402,7 +402,7 @@ void register_gl_fun(fun_gl_Begin beg,fun_gl_End end); #define ADDRESS_STEP_8KB 0x02000 #define ADDRESS_STEP_16KB 0x04000 #define ADDRESS_STEP_32KB 0x08000 -#define ADDRESS_STEP_64KB 0x10000 +#define ADDRESS_STEP_64kB 0x10000 #define ADDRESS_STEP_128KB 0x20000 #define ADDRESS_STEP_256KB 0x40000 #define ADDRESS_STEP_512KB 0x80000 @@ -533,7 +533,7 @@ typedef struct /*12*/ unsigned PaletteIndex:4; /*10*/ unsigned Priority:2; // attr3 - unsigned attr3:16; +unsigned attr3:16; #else // attr0 /* 0*/ unsigned Y:8; @@ -559,24 +559,14 @@ typedef struct typedef struct { -#ifdef WORDS_BIGENDIAN - u8 attr00; - u8 attr01; - u8 attr10; - u8 attr11; - u8 attr20; - u8 attr21; - u8 attr30; - u8 attr31; -#else u16 attr0; u16 attr1; u16 attr2; u16 attr3; -#endif } OAM; + typedef struct { s16 x; @@ -608,21 +598,12 @@ typedef struct extern CACHE_ALIGN u8 gpuBlendTable555[17][17][32][32]; -enum BGType { - BGType_Invalid=0, BGType_Text=1, BGType_Affine=2, BGType_Large8bpp=3, - BGType_AffineExt=4, BGType_AffineExt_256x16=5, BGType_AffineExt_256x1=6, BGType_AffineExt_Direct=7 -}; - struct GPU { // some structs are becoming redundant // some functions too (no need to recopy some vars as it is done by MMU) REG_DISPx * dispx_st; - _BGxCNT & bgcnt(int num) { return (dispx_st)->dispx_BGxCNT[num].bits; } - _DISPCNT & dispCnt() { return dispx_st->dispx_DISPCNT.bits; } - void modeRender(int layer); - DISPCAPCNT dispCapCnt; BOOL LayersEnable[5]; itemsForPriority_t itemsForPriority[NB_PRIORITIES]; @@ -630,14 +611,12 @@ struct GPU #define BGBmpBB BG_bmp_ram #define BGChBB BG_tile_ram - u32 BG_bmp_large_ram[4]; u32 BG_bmp_ram[4]; u32 BG_tile_ram[4]; u32 BG_map_ram[4]; u8 BGExtPalSlot[4]; u32 BGSize[4][2]; - BGType BGTypes[4]; struct MosaicColor { u16 bg[4][256]; @@ -716,9 +695,6 @@ struct GPU bool blend1; u8* currDst; - u16* _3dColorLine; - u8* _3dAlphaLine; - static struct MosaicLookup { @@ -745,12 +721,11 @@ struct GPU u16 blend(u16 colA, u16 colB); typedef void (*FinalOBJColFunct)(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u8 type, u16 x); - typedef void (*Final3DColFunct)(GPU *gpu, int dstX, int srcX); + typedef void (*Final3DColFunct)(GPU *gpu, u32 passing, u8 *dst, u16 color, u8 alpha, u16 x); int setFinalColorBck_funcNum; - int setFinalColor3d_funcNum; FinalOBJColFunct setFinalColorSpr; - //Final3DColFunct setFinalColor3D; + Final3DColFunct setFinalColor3D; enum SpriteRenderMode { SPRITE_1D, SPRITE_2D } spriteRenderMode; @@ -760,8 +735,6 @@ struct GPU void spriteRender(u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab); void setFinalColorBG(u16 color, u8 x); - void setFinalColor3d(int dstX, int srcX); - FORCEINLINE void setFinalBGColorSpecialNone(u16 color, u8 x, bool blend1); FORCEINLINE void setFinalBGColorSpecialBlend(u16 color, u8 x, bool blend1); FORCEINLINE void setFinalBGColorSpecialIncrease(u16 color, u8 x, bool blend1); @@ -770,22 +743,9 @@ struct GPU FORCEINLINE void setFinalBGColorSpecialBlendWnd(u16 color, u8 x, bool blend1); FORCEINLINE void setFinalBGColorSpecialIncreaseWnd(u16 color, u8 x, bool blend1); FORCEINLINE void setFinalBGColorSpecialDecreaseWnd(u16 color, u8 x, bool blend1); - - FORCEINLINE void setFinal3DColorSpecialNone(int dstX, int srcX); - FORCEINLINE void setFinal3DColorSpecialBlend(int dstX, int srcX); - FORCEINLINE void setFinal3DColorSpecialIncrease(int dstX, int srcX); - FORCEINLINE void setFinal3DColorSpecialDecrease(int dstX, int srcX); - FORCEINLINE void setFinal3DColorSpecialNoneWnd(int dstX, int srcX); - FORCEINLINE void setFinal3DColorSpecialBlendWnd(int dstX, int srcX); - FORCEINLINE void setFinal3DColorSpecialIncreaseWnd(int dstX, int srcX); - FORCEINLINE void setFinal3DColorSpecialDecreaseWnd(int dstX, int srcX); - void __setFinalColorBck(u16 color, u8 x, bool opaque); void setAffineStart(int layer, int xy, u32 val); - void setAffineStartWord(int layer, int xy, u16 val, int word); - u32 getAffineStart(int layer, int xy); - void refreshAffineStartRegs(); struct AffineInfo { AffineInfo() : x(0), y(0) {} @@ -864,7 +824,9 @@ namespace GPU_EXT void sprite1D(GPU * gpu, u16 l, u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab); void sprite2D(GPU * gpu, u16 l, u8 * dst, u8 * dst_alpha, u8 * typeTab, u8 * prioTab); +extern const short sizeTab[4][4][2]; extern const size sprSizeTab[4][4]; +extern const s8 mode2type[8][4]; typedef struct { GPU * gpu; @@ -887,7 +849,7 @@ extern MMU_struct MMU; #define GFXCORE_FULLSCREEN (1 << 0) -struct GraphicsInterface_struct +typedef struct { int id; // ID number for core(see above defines) const char *Name; // Name of core @@ -896,7 +858,7 @@ struct GraphicsInterface_struct void (*DeInit)(); // Deinitializes stuff related to core void (*Resize)(int width, int height, BOOL fullscreen); // Resizes window or fullscreen void (*OnScreenText)(char *string, ...); // For handling save state messages, etc. -} ; +} GraphicsInterface_struct; extern GraphicsInterface_struct GFXDummy; @@ -917,46 +879,43 @@ void GPU_set_DISPCAPCNT(u32 val) ; void GPU_ligne(NDS_Screen * screen, u16 l) ; void GPU_setMasterBrightness (GPU *gpu, u16 val); -inline void GPU_setWIN0_H(GPU* gpu, u16 val) { gpu->WIN0H0 = val >> 8; gpu->WIN0H1 = val&0xFF; gpu->need_update_winh[0] = true; } -inline void GPU_setWIN0_H0(GPU* gpu, u8 val) { gpu->WIN0H0 = val; gpu->need_update_winh[0] = true; } -inline void GPU_setWIN0_H1(GPU* gpu, u8 val) { gpu->WIN0H1 = val; gpu->need_update_winh[0] = true; } +#define GPU_setWIN0_H(gpu, val) {gpu->WIN0H0 = val >> 8; gpu->WIN0H1 = val&0xFF; gpu->need_update_winh[0] = true; } +#define GPU_setWIN0_H0(gpu, val) { gpu->WIN0H0 = val; gpu->need_update_winh[0] = true; } +#define GPU_setWIN0_H1(gpu, val) { gpu->WIN0H1 = val; gpu->need_update_winh[0] = true; } -inline void GPU_setWIN0_V(GPU* gpu, u16 val) { gpu->WIN0V0 = val >> 8; gpu->WIN0V1 = val&0xFF;} -inline void GPU_setWIN0_V0(GPU* gpu, u8 val) { gpu->WIN0V0 = val; } -inline void GPU_setWIN0_V1(GPU* gpu, u8 val) { gpu->WIN0V1 = val; } +#define GPU_setWIN0_V(gpu, val) {gpu->WIN0V0 = val >> 8; gpu->WIN0V1 = val&0xFF;} +#define GPU_setWIN0_V0(gpu, val) gpu->WIN0V0 = val +#define GPU_setWIN0_V1(gpu, val) gpu->WIN0V1 = val -inline void GPU_setWIN1_H(GPU* gpu, u16 val) {gpu->WIN1H0 = val >> 8; gpu->WIN1H1 = val&0xFF; gpu->need_update_winh[1] = true; } -inline void GPU_setWIN1_H0(GPU* gpu, u8 val) { gpu->WIN1H0 = val; gpu->need_update_winh[1] = true; } -inline void GPU_setWIN1_H1(GPU* gpu, u8 val) { gpu->WIN1H1 = val; gpu->need_update_winh[1] = true; } +#define GPU_setWIN1_H(gpu, val) {gpu->WIN1H0 = val >> 8; gpu->WIN1H1 = val&0xFF; gpu->need_update_winh[1] = true; } +#define GPU_setWIN1_H0(gpu, val) { gpu->WIN1H0 = val; gpu->need_update_winh[1] = true; } +#define GPU_setWIN1_H1(gpu, val) { gpu->WIN1H1 = val; gpu->need_update_winh[1] = true; } -inline void GPU_setWIN1_V(GPU* gpu, u16 val) { gpu->WIN1V0 = val >> 8; gpu->WIN1V1 = val&0xFF; } -inline void GPU_setWIN1_V0(GPU* gpu, u8 val) { gpu->WIN1V0 = val; } -inline void GPU_setWIN1_V1(GPU* gpu, u8 val) { gpu->WIN1V1 = val; } +#define GPU_setWIN1_V(gpu, val) {gpu->WIN1V0 = val >> 8; gpu->WIN1V1 = val&0xFF;} +#define GPU_setWIN1_V0(gpu, val) gpu->WIN1V0 = val +#define GPU_setWIN1_V1(gpu, val) gpu->WIN1V1 = val -inline void GPU_setWININ(GPU* gpu, u16 val) { - gpu->WININ0=val&0x1F; - gpu->WININ0_SPECIAL=(val>>5)&1; - gpu->WININ1=(val>>8)&0x1F; - gpu->WININ1_SPECIAL=(val>>13)&1; -} +#define GPU_setWININ(gpu, val) {gpu->WININ0=val&0x1F;\ + gpu->WININ0_SPECIAL=(val>>5)&1;\ + gpu->WININ1=(val>>8)&0x1F;\ + gpu->WININ1_SPECIAL=(val>>13)&1;\ + } +#define GPU_setWININ0(gpu, val) {gpu->WININ0 = val&0x1F; gpu->WININ0_SPECIAL = (val>>5)&1;} +#define GPU_setWININ1(gpu, val) {gpu->WININ1 = val&0x1F; gpu->WININ1_SPECIAL = (val>>5)&1;} -inline void GPU_setWININ0(GPU* gpu, u8 val) { gpu->WININ0 = val&0x1F; gpu->WININ0_SPECIAL = (val>>5)&1; } -inline void GPU_setWININ1(GPU* gpu, u8 val) { gpu->WININ1 = val&0x1F; gpu->WININ1_SPECIAL = (val>>5)&1; } - -inline void GPU_setWINOUT16(GPU* gpu, u16 val) { - gpu->WINOUT=val&0x1F; - gpu->WINOUT_SPECIAL=(val>>5)&1; - gpu->WINOBJ=(val>>8)&0x1F; - gpu->WINOBJ_SPECIAL=(val>>13)&1; -} -inline void GPU_setWINOUT(GPU* gpu, u8 val) { gpu->WINOUT = val&0x1F; gpu->WINOUT_SPECIAL = (val>>5)&1; } -inline void GPU_setWINOBJ(GPU* gpu, u8 val) { gpu->WINOBJ = val&0x1F; gpu->WINOBJ_SPECIAL = (val>>5)&1; } +#define GPU_setWINOUT16(gpu, val) { gpu->WINOUT=val&0x1F;\ + gpu->WINOUT_SPECIAL=(val>>5)&1;\ + gpu->WINOBJ=(val>>8)&0x1F;\ + gpu->WINOBJ_SPECIAL=(val>>13)&1;\ + } +#define GPU_setWINOUT(gpu, val) {gpu->WINOUT = val&0x1F; gpu->WINOUT_SPECIAL = (val>>5)&1;} +#define GPU_setWINOBJ(gpu, val) {gpu->WINOBJ = val&0x1F; gpu->WINOBJ_SPECIAL = (val>>5)&1;} // Blending void SetupFinalPixelBlitter (GPU *gpu); -#define GPU_setBLDCNT_LOW(gpu, val) {gpu->BLDCNT = (gpu->BLDCNT&0xFF00) | (val); SetupFinalPixelBlitter (gpu);} +#define GPU_setBLDCNT_LOW(gpu, val) {gpu->BLDCNT = (gpu->BLDCNT&0xFF00) | val; SetupFinalPixelBlitter (gpu);} #define GPU_setBLDCNT_HIGH(gpu, val) {gpu->BLDCNT = (gpu->BLDCNT&0xFF) | (val<<8); SetupFinalPixelBlitter (gpu);} -#define GPU_setBLDCNT(gpu, val) {gpu->BLDCNT = (val); SetupFinalPixelBlitter (gpu);} +#define GPU_setBLDCNT(gpu, val) {gpu->BLDCNT = val; SetupFinalPixelBlitter (gpu);} diff --git a/desmume/src/GPU_osd.cpp b/src/GPU_osd.cpp similarity index 100% rename from desmume/src/GPU_osd.cpp rename to src/GPU_osd.cpp diff --git a/desmume/src/GPU_osd.h b/src/GPU_osd.h similarity index 100% rename from desmume/src/GPU_osd.h rename to src/GPU_osd.h diff --git a/desmume/src/MMU.cpp b/src/MMU.cpp similarity index 89% rename from desmume/src/MMU.cpp rename to src/MMU.cpp index a3f0b1cce..753e4c89e 100644 --- a/desmume/src/MMU.cpp +++ b/src/MMU.cpp @@ -155,11 +155,15 @@ void mmu_log_debug_ARM7(u32 adr, const char *fmt, ...) INFO("MMU ARM7 0x%08X: %s\n", adr, msg); } -#else -#define mmu_log_debug_ARM9(...) -#define mmu_log_debug_ARM7(...) #endif +/* + * + */ +#define EARLY_MEMORY_ACCESS 1 + +#define INTERNAL_DTCM_READ 1 +#define INTERNAL_DTCM_WRITE 1 //#define LOG_CARD //#define LOG_GPU @@ -262,13 +266,12 @@ u32 MMU_struct::MMU_MASK[2][256] = { } }; -CACHE_ALIGN + TWaitState MMU_struct::MMU_WAIT16[2][16] = { { 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 1, 1, 1, 1, 1 }, //arm9 { 1, 1, 1, 1, 1, 1, 1, 1, 5, 5, 5, 1, 1, 1, 1, 1 }, //arm7 }; -CACHE_ALIGN TWaitState MMU_struct::MMU_WAIT32[2][16] = { { 1, 1, 1, 1, 1, 2, 2, 1, 8, 8, 5, 1, 1, 1, 1, 1 }, //arm9 { 1, 1, 1, 1, 1, 1, 1, 1, 8, 8, 5, 1, 1, 1, 1, 1 }, //arm7 @@ -289,6 +292,7 @@ u8 vram_lcdc_map[VRAM_LCDC_PAGES]; //in the range of 0x06000000 - 0x06800000 in 16KB pages (the ARM9 vram mappable area) //this maps to 16KB pages in the LCDC buffer which is what will actually contain the data +#define VRAM_ARM9_PAGES 512 u8 vram_arm9_map[VRAM_ARM9_PAGES]; //this chooses which banks are mapped in the 128K banks starting at 0x06000000 in ARM7 @@ -470,7 +474,6 @@ struct VramConfiguration { case BBGEXTPAL: return "BBGEXTPAL"; case AOBJEXTPAL: return "AOBJEXTPAL"; case BOBJEXTPAL: return "BOBJEXTPAL"; - default: return "UNHANDLED CASE"; } } @@ -512,11 +515,6 @@ static inline u8* MMU_vram_physical(const int page) //todo - templateize //note: it doesnt seem right to me to map LCDC whenever a bank is allocated to BG/OBJ but thats how it is //(in FF4, when entering a town from worldmap, the subscreen tiles are via LCDC while mapped to sub BG) -//UPDATED: i had to take them out in order to fix tetris DS music mode. -//since then, other issues fixed FF4's problems, so they are staying out for now -//as further, almost definitive proof that these should remain unmapped, -//making them mapped permit's spiderman2's legal screens / intro FMV to render garbage -//on top of the studio logo if you interrupt it by pressing enter. static inline void MMU_VRAMmapRefreshBank(const int bank) { int block = bank; @@ -542,7 +540,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //ABG vramConfiguration.banks[bank].purpose = VramConfiguration::ABG; - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_ABG+ofs*8); break; case 2: //AOBJ @@ -550,7 +548,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) switch(ofs) { case 0: case 1: - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_AOBJ+ofs*8); break; default: @@ -576,7 +574,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //ABG vramConfiguration.banks[bank].purpose = VramConfiguration::ABG; - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_ABG+ofs*8); break; case 2: //arm7 @@ -598,7 +596,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) ARM9Mem.texInfo.textureSlotAddr[ofs] = MMU_vram_physical(vram_bank_info[bank].page_addr); break; case 4: //BGB or BOBJ - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); if(bank == VRAM_BANK_C) { vramConfiguration.banks[bank].purpose = VramConfiguration::BBG; MMU_vram_arm9(bank,VRAM_PAGE_BBG); //BBG @@ -620,11 +618,11 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //ABG vramConfiguration.banks[bank].purpose = VramConfiguration::ABG; - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_ABG); break; case 2: //AOBJ - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); vramConfiguration.banks[bank].purpose = VramConfiguration::AOBJ; MMU_vram_arm9(bank,VRAM_PAGE_AOBJ); break; @@ -660,13 +658,13 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //ABG vramConfiguration.banks[bank].purpose = VramConfiguration::ABG; - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_ABG+pageofs); MMU_vram_arm9(bank,VRAM_PAGE_ABG+pageofs+2); //unexpected mirroring (required by spyro eternal night) break; case 2: //AOBJ vramConfiguration.banks[bank].purpose = VramConfiguration::AOBJ; - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_AOBJ+pageofs); MMU_vram_arm9(bank,VRAM_PAGE_AOBJ+pageofs+2); //unexpected mirroring - I have no proof, but it is inferred from the ABG above break; @@ -708,7 +706,7 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //BBG vramConfiguration.banks[bank].purpose = VramConfiguration::BBG; - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_BBG); MMU_vram_arm9(bank,VRAM_PAGE_BBG + 4); //unexpected mirroring break; @@ -733,13 +731,13 @@ static inline void MMU_VRAMmapRefreshBank(const int bank) break; case 1: //BBG vramConfiguration.banks[bank].purpose = VramConfiguration::BBG; - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_BBG+2); MMU_vram_arm9(bank,VRAM_PAGE_BBG+3); //unexpected mirroring break; case 2: //BOBJ vramConfiguration.banks[bank].purpose = VramConfiguration::BOBJ; - //MMU_vram_lcdc(bank); + MMU_vram_lcdc(bank); MMU_vram_arm9(bank,VRAM_PAGE_BOBJ); break; case 3: //B OBJ extended palette @@ -822,9 +820,8 @@ static inline void MMU_VRAMmapControl(u8 block, u8 VRAMBankCnt) //if texInfo changed, trigger notifications if(memcmp(&oldTexInfo,&ARM9Mem.texInfo,sizeof(ARM9_struct::TextureInfo))) { - if(!nds.isIn3dVblank()) { + if(!nds.isIn3dVblank()) PROGINFO("Changing texture or texture palette mappings outside of 3d vblank\n"); - } gpu3D->NDS_3D_VramReconfigureSignal(); } @@ -1284,10 +1281,453 @@ void FASTCALL MMU_write32_acl(u32 proc, u32 adr, u32 val) } #endif -//a stub for memory profiler, if we choose to re-add it -#define PROFILE_PREFETCH 1 -#define profile_memory_access(X,Y,Z) +#ifdef PROFILE_MEMORY_ACCESS +#define PROFILE_PREFETCH 0 +#define PROFILE_READ 1 +#define PROFILE_WRITE 2 + +struct mem_access_profile { + u64 num_accesses; + u32 address_mask; + u32 masked_value; +}; + +#define PROFILE_NUM_MEM_ACCESS_PROFILES 4 + +static u64 profile_num_accesses[2][3]; +static u64 profile_unknown_addresses[2][3]; +static struct mem_access_profile +profile_memory_accesses[2][3][PROFILE_NUM_MEM_ACCESS_PROFILES]; + +static void +setup_profiling( void) { + int i; + + for ( i = 0; i < 2; i++) { + int access_type; + + for ( access_type = 0; access_type < 3; access_type++) { + profile_num_accesses[i][access_type] = 0; + profile_unknown_addresses[i][access_type] = 0; + + /* + * Setup the access testing structures + */ + profile_memory_accesses[i][access_type][0].address_mask = 0x0e000000; + profile_memory_accesses[i][access_type][0].masked_value = 0x00000000; + profile_memory_accesses[i][access_type][0].num_accesses = 0; + + /* main memory */ + profile_memory_accesses[i][access_type][1].address_mask = 0x0f000000; + profile_memory_accesses[i][access_type][1].masked_value = 0x02000000; + profile_memory_accesses[i][access_type][1].num_accesses = 0; + + /* shared memory */ + profile_memory_accesses[i][access_type][2].address_mask = 0x0f800000; + profile_memory_accesses[i][access_type][2].masked_value = 0x03000000; + profile_memory_accesses[i][access_type][2].num_accesses = 0; + + /* arm7 memory */ + profile_memory_accesses[i][access_type][3].address_mask = 0x0f800000; + profile_memory_accesses[i][access_type][3].masked_value = 0x03800000; + profile_memory_accesses[i][access_type][3].num_accesses = 0; + } + } +} + +static void +profile_memory_access( int arm9, u32 adr, int access_type) { + static int first = 1; + int mem_profile; + int address_found = 0; + + if ( first) { + setup_profiling(); + first = 0; + } + + profile_num_accesses[arm9][access_type] += 1; + + for ( mem_profile = 0; + mem_profile < PROFILE_NUM_MEM_ACCESS_PROFILES && + !address_found; + mem_profile++) { + if ( (adr & profile_memory_accesses[arm9][access_type][mem_profile].address_mask) == + profile_memory_accesses[arm9][access_type][mem_profile].masked_value) { + /*printf( "adr %08x mask %08x res %08x expected %08x\n", + adr, + profile_memory_accesses[arm9][access_type][mem_profile].address_mask, + adr & profile_memory_accesses[arm9][access_type][mem_profile].address_mask, + profile_memory_accesses[arm9][access_type][mem_profile].masked_value);*/ + address_found = 1; + profile_memory_accesses[arm9][access_type][mem_profile].num_accesses += 1; + } + } + + if ( !address_found) { + profile_unknown_addresses[arm9][access_type] += 1; + } +} + + +static const char *access_type_strings[] = { + "prefetch", + "read ", + "write " +}; + +void +print_memory_profiling( void) { + int arm; + + printf("------ Memory access profile ------\n"); + + for ( arm = 0; arm < 2; arm++) { + int access_type; + + for ( access_type = 0; access_type < 3; access_type++) { + int mem_profile; + printf("ARM%c: num of %s %lld\n", + arm ? '9' : '7', + access_type_strings[access_type], + profile_num_accesses[arm][access_type]); + + for ( mem_profile = 0; + mem_profile < PROFILE_NUM_MEM_ACCESS_PROFILES; + mem_profile++) { + printf( "address %08x: %lld\n", + profile_memory_accesses[arm][access_type][mem_profile].masked_value, + profile_memory_accesses[arm][access_type][mem_profile].num_accesses); + } + + printf( "unknown addresses %lld\n", + profile_unknown_addresses[arm][access_type]); + + printf( "\n"); + } + } + + printf("------ End of Memory access profile ------\n\n"); +} +#else +void +print_memory_profiling( void) { +} +#endif /* End of PROFILE_MEMORY_ACCESS area */ + +static u16 FASTCALL +arm9_prefetch16( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 1, adr, PROFILE_PREFETCH); +#endif + +#ifdef EARLY_MEMORY_ACCESS + if((adr & ~0x3FFF) == MMU.DTCMRegion) + { + /* Returns data from DTCM (ARM9 only) */ + return T1ReadWord(ARM9Mem.ARM9_DTCM, adr & 0x3FFF); + } + /* access to main memory */ + if ( (adr & 0x0f000000) == 0x02000000) { + return T1ReadWord( MMU.MMU_MEM[ARMCPU_ARM9][(adr >> 20) & 0xFF], + adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20) & 0xFF]); + } +#endif + + return _MMU_read16(adr); +} +static u32 FASTCALL +arm9_prefetch32( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 1, adr, PROFILE_PREFETCH); +#endif + +#ifdef EARLY_MEMORY_ACCESS + if((adr & ~0x3FFF) == MMU.DTCMRegion) + { + /* Returns data from DTCM (ARM9 only) */ + return T1ReadLong(ARM9Mem.ARM9_DTCM, adr & 0x3FFF); + } + /* access to main memory */ + if ( (adr & 0x0f000000) == 0x02000000) { + return T1ReadLong( MMU.MMU_MEM[ARMCPU_ARM9][(adr >> 20) & 0xFF], + adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20) & 0xFF]); + } +#endif + + return _MMU_read32(adr); +} + +static u8 FASTCALL +arm9_read8( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 1, adr, PROFILE_READ); +#endif + +#ifdef EARLY_MEMORY_ACCESS + if( (adr&(~0x3FFF)) == MMU.DTCMRegion) + { + return ARM9Mem.ARM9_DTCM[adr&0x3FFF]; + } + /* access to main memory */ + if ( (adr & 0x0f000000) == 0x02000000) { + return MMU.MMU_MEM[ARMCPU_ARM9][(adr >> 20) & 0xFF] + [adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20) & 0xFF]]; + } +#endif + + return _MMU_read08(adr); +} +static u16 FASTCALL +arm9_read16( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 1, adr, PROFILE_READ); +#endif + +#ifdef EARLY_MEMORY_ACCESS + if((adr & ~0x3FFF) == MMU.DTCMRegion) + { + /* Returns data from DTCM (ARM9 only) */ + return T1ReadWord(ARM9Mem.ARM9_DTCM, adr & 0x3FFF); + } + + /* access to main memory */ + if ( (adr & 0x0f000000) == 0x02000000) { + return T1ReadWord( MMU.MMU_MEM[ARMCPU_ARM9][(adr >> 20) & 0xFF], + adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20) & 0xFF]); + } +#endif + + return _MMU_read16(adr); +} +static u32 FASTCALL +arm9_read32( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 1, adr, PROFILE_READ); +#endif + +#ifdef EARLY_MEMORY_ACCESS + if((adr & ~0x3FFF) == MMU.DTCMRegion) + { + /* Returns data from DTCM (ARM9 only) */ + return T1ReadLong(ARM9Mem.ARM9_DTCM, adr & 0x3FFF); + } + /* access to main memory */ + if ( (adr & 0x0f000000) == 0x02000000) { + return T1ReadLong( MMU.MMU_MEM[ARMCPU_ARM9][(adr >> 20) & 0xFF], + adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20) & 0xFF]); + } +#endif + + return _MMU_read32(adr); +} + + +static void FASTCALL +arm9_write8(void *data, u32 adr, u8 val) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 1, adr, PROFILE_WRITE); +#endif + +#ifdef EARLY_MEMORY_ACCESS + if( (adr & ~0x3FFF) == MMU.DTCMRegion) + { + /* Writes data in DTCM (ARM9 only) */ + ARM9Mem.ARM9_DTCM[adr&0x3FFF] = val; + return ; + } + /* main memory */ + if ( (adr & 0x0f000000) == 0x02000000) { + MMU.MMU_MEM[ARMCPU_ARM9][(adr>>20)&0xFF] + [adr&MMU.MMU_MASK[ARMCPU_ARM9][(adr>>20)&0xFF]] = val; + return; + } +#endif + + _MMU_write08(adr, val); +} +static void FASTCALL +arm9_write16(void *data, u32 adr, u16 val) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 1, adr, PROFILE_WRITE); +#endif + +#ifdef EARLY_MEMORY_ACCESS + if((adr & ~0x3FFF) == MMU.DTCMRegion) + { + /* Writes in DTCM (ARM9 only) */ + T1WriteWord(ARM9Mem.ARM9_DTCM, adr & 0x3FFF, val); + return; + } + /* main memory */ + if ( (adr & 0x0f000000) == 0x02000000) { + T1WriteWord( MMU.MMU_MEM[ARMCPU_ARM9][(adr>>20)&0xFF], + adr&MMU.MMU_MASK[ARMCPU_ARM9][(adr>>20)&0xFF], val); + return; + } +#endif + + _MMU_write16(adr, val); +} +static void FASTCALL +arm9_write32(void *data, u32 adr, u32 val) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 1, adr, PROFILE_WRITE); +#endif + +#ifdef EARLY_MEMORY_ACCESS + if((adr & ~0x3FFF) == MMU.DTCMRegion) + { + /* Writes in DTCM (ARM9 only) */ + T1WriteLong(ARM9Mem.ARM9_DTCM, adr & 0x3FFF, val); + return; + } + /* main memory */ + if ( (adr & 0x0f000000) == 0x02000000) { + T1WriteLong( MMU.MMU_MEM[ARMCPU_ARM9][(adr>>20)&0xFF], + adr&MMU.MMU_MASK[ARMCPU_ARM9][(adr>>20)&0xFF], val); + return; + } +#endif + + _MMU_write32(adr, val); +} + + + + +static u16 FASTCALL +arm7_prefetch16( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 0, adr, PROFILE_PREFETCH); +#endif + +#ifdef EARLY_MEMORY_ACCESS + /* ARM7 private memory */ + if ( (adr & 0x0f800000) == 0x03800000) { + T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM7][(adr >> 20) & 0xFF], + adr & MMU.MMU_MASK[ARMCPU_ARM7][(adr >> 20) & 0xFF]); + } +#endif + + return _MMU_read16(adr); +} +static u32 FASTCALL +arm7_prefetch32( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 0, adr, PROFILE_PREFETCH); +#endif + +#ifdef EARLY_MEMORY_ACCESS + /* ARM7 private memory */ + if ( (adr & 0x0f800000) == 0x03800000) { + T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM7][(adr >> 20) & 0xFF], + adr & MMU.MMU_MASK[ARMCPU_ARM7][(adr >> 20) & 0xFF]); + } +#endif + + return _MMU_read32(adr); +} + +static u8 FASTCALL +arm7_read8( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 0, adr, PROFILE_READ); +#endif + + return _MMU_read08(adr); +} +static u16 FASTCALL +arm7_read16( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 0, adr, PROFILE_READ); +#endif + + return _MMU_read16(adr); +} +static u32 FASTCALL +arm7_read32( void *data, u32 adr) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 0, adr, PROFILE_READ); +#endif + + return _MMU_read32(adr); +} + +static void FASTCALL +arm7_write8(void *data, u32 adr, u8 val) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 0, adr, PROFILE_WRITE); +#endif + + _MMU_write08(adr, val); +} +static void FASTCALL +arm7_write16(void *data, u32 adr, u16 val) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 0, adr, PROFILE_WRITE); +#endif + + _MMU_write16(adr, val); +} +static void FASTCALL +arm7_write32(void *data, u32 adr, u32 val) { +#ifdef PROFILE_MEMORY_ACCESS + profile_memory_access( 0, adr, PROFILE_WRITE); +#endif + + _MMU_write32(adr, val); +} + + + +/* + * the base memory interfaces + */ +struct armcpu_memory_iface arm9_base_memory_iface = { + arm9_prefetch32, + arm9_prefetch16, + + arm9_read8, + arm9_read16, + arm9_read32, + + arm9_write8, + arm9_write16, + arm9_write32 +}; + +struct armcpu_memory_iface arm7_base_memory_iface = { + arm7_prefetch32, + arm7_prefetch16, + + arm7_read8, + arm7_read16, + arm7_read32, + + arm7_write8, + arm7_write16, + arm7_write32 +}; + +/* + * The direct memory interface for the ARM9. + * This avoids the ARM9 protection unit when accessing + * memory. + */ +struct armcpu_memory_iface arm9_direct_memory_iface = { + NULL, + NULL, + + arm9_read8, + arm9_read16, + arm9_read32, + + arm9_write8, + arm9_write16, + arm9_write32 +}; static INLINE void MMU_IPCSync(u8 proc, u32 val) { @@ -1311,12 +1751,18 @@ static INLINE void MMU_IPCSync(u8 proc, u32 val) //================================================= MMU write 08 void FASTCALL _MMU_ARM9_write08(u32 adr, u8 val) { - mmu_log_debug_ARM9(adr, "(write08) %0x%X", val); - +#ifdef INTERNAL_DTCM_WRITE + if(((adr & ~0x3FFF) == MMU.DTCMRegion)) + { + /* Writes data in DTCM (ARM9 only) */ + ARM9Mem.ARM9_DTCM[adr & 0x3FFF] = val; + return ; + } +#endif if(adr < 0x02000000) { T1WriteByte(ARM9Mem.ARM9_ITCM, adr&0x7FFF, val); - return; + return ; } #ifdef EXPERIMENTAL_GBASLOT @@ -1503,7 +1949,9 @@ void FASTCALL _MMU_ARM9_write08(u32 adr, u8 val) LOG("%08X : %02X\r\n", adr, val); #endif } - +#ifdef _MMU_DEBUG + mmu_log_debug_ARM9(adr, "(write08) %0x%X", val); +#endif MMU.MMU_MEM[ARMCPU_ARM9][0x40][adr&MMU.MMU_MASK[ARMCPU_ARM9][adr>>20]]=val; return; } @@ -1519,12 +1967,18 @@ void FASTCALL _MMU_ARM9_write08(u32 adr, u8 val) //================================================= MMU ARM9 write 16 void FASTCALL _MMU_ARM9_write16(u32 adr, u16 val) { - mmu_log_debug_ARM9(adr, "(write16) %0x%X", val); - +#ifdef INTERNAL_DTCM_WRITE + if((adr & ~0x3FFF) == MMU.DTCMRegion) + { + /* Writes in DTCM (ARM9 only) */ + T1WriteWord(ARM9Mem.ARM9_DTCM, adr & 0x3FFF, val); + return; + } +#endif if (adr < 0x02000000) { T1WriteWord(ARM9Mem.ARM9_ITCM, adr&0x7FFF, val); - return; + return ; } #ifdef EXPERIMENTAL_GBASLOT @@ -1560,23 +2014,6 @@ void FASTCALL _MMU_ARM9_write16(u32 adr, u16 val) // Address is an IO register switch(adr) { - case REG_DISPA_BG2XL: MainScreen.gpu->setAffineStartWord(2,0,val,0); break; - case REG_DISPA_BG2XH: MainScreen.gpu->setAffineStartWord(2,0,val,1); break; - case REG_DISPA_BG2YL: MainScreen.gpu->setAffineStartWord(2,1,val,0); break; - case REG_DISPA_BG2YH: MainScreen.gpu->setAffineStartWord(2,1,val,1); break; - case REG_DISPA_BG3XL: MainScreen.gpu->setAffineStartWord(3,0,val,0); break; - case REG_DISPA_BG3XH: MainScreen.gpu->setAffineStartWord(3,0,val,1); break; - case REG_DISPA_BG3YL: MainScreen.gpu->setAffineStartWord(3,1,val,0); break; - case REG_DISPA_BG3YH: MainScreen.gpu->setAffineStartWord(3,1,val,1); break; - case REG_DISPB_BG2XL: SubScreen.gpu->setAffineStartWord(2,0,val,0); break; - case REG_DISPB_BG2XH: SubScreen.gpu->setAffineStartWord(2,0,val,1); break; - case REG_DISPB_BG2YL: SubScreen.gpu->setAffineStartWord(2,1,val,0); break; - case REG_DISPB_BG2YH: SubScreen.gpu->setAffineStartWord(2,1,val,1); break; - case REG_DISPB_BG3XL: SubScreen.gpu->setAffineStartWord(3,0,val,0); break; - case REG_DISPB_BG3XH: SubScreen.gpu->setAffineStartWord(3,0,val,1); break; - case REG_DISPB_BG3YL: SubScreen.gpu->setAffineStartWord(3,1,val,0); break; - case REG_DISPB_BG3YH: SubScreen.gpu->setAffineStartWord(3,1,val,1); break; - case REG_DISPA_DISP3DCNT: { MainScreen.gpu->dispx_st->dispA_DISP3DCNT.val = val; @@ -1757,7 +2194,7 @@ void FASTCALL _MMU_ARM9_write16(u32 adr, u16 val) } else { - //LOG("Main core on bottom\n"); + //LOG("Main core on bottom (%04X)\n", val); MainScreen.offset = 192; SubScreen.offset = 0; } @@ -1973,14 +2410,14 @@ void FASTCALL _MMU_ARM9_write16(u32 adr, u16 val) case REG_DISPA_DISPCAPCNT : { u32 v = (T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], 0x64) & 0xFFFF0000) | val; - GPU_set_DISPCAPCNT(v); + GPU_set_DISPCAPCNT(val); T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], 0x64, v); return; } case REG_DISPA_DISPCAPCNT + 2: { - u32 v = (T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], 0x64) & 0xFFFF) | ((u32)val << 16); - GPU_set_DISPCAPCNT(v); + u32 v = (T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], 0x64) & 0xFFFF) | val; + GPU_set_DISPCAPCNT(val); T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], 0x64, v); return; } @@ -2097,7 +2534,9 @@ void FASTCALL _MMU_ARM9_write16(u32 adr, u16 val) return; } } - +#ifdef _MMU_DEBUG + mmu_log_debug_ARM9(adr, "(write16) %0x%X", val); +#endif T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM9][0x40], adr&MMU.MMU_MASK[ARMCPU_ARM9][adr>>20], val); return; } @@ -2113,7 +2552,20 @@ void FASTCALL _MMU_ARM9_write16(u32 adr, u16 val) //================================================= MMU ARM9 write 32 void FASTCALL _MMU_ARM9_write32(u32 adr, u32 val) { - mmu_log_debug_ARM9(adr, "(write32) %0x%X", val); +#ifdef INTERNAL_DTCM_WRITE + if((adr&(~0x3FFF)) == MMU.DTCMRegion) + { + T1WriteLong(ARM9Mem.ARM9_DTCM, adr & 0x3FFF, val); + return ; + } +#endif + +#ifdef EARLY_MEMORY_ACCESS + if ( (adr & 0x0F000000) == 0x02000000) { + T1WriteLong( ARM9Mem.MAIN_MEM, adr & 0x3FFFFF, val); + return; + } +#endif if(adr<0x02000000) { @@ -2217,28 +2669,28 @@ void FASTCALL _MMU_ARM9_write32(u32 adr, u32 val) { case REG_DISPA_BG2XL: MainScreen.gpu->setAffineStart(2,0,val); - return; + break; case REG_DISPA_BG2YL: MainScreen.gpu->setAffineStart(2,1,val); - return; + break; case REG_DISPB_BG2XL: SubScreen.gpu->setAffineStart(2,0,val); - return; + break; case REG_DISPB_BG2YL: SubScreen.gpu->setAffineStart(2,1,val); - return; + break; case REG_DISPA_BG3XL: MainScreen.gpu->setAffineStart(3,0,val); - return; + break; case REG_DISPA_BG3YL: MainScreen.gpu->setAffineStart(3,1,val); - return; + break; case REG_DISPB_BG3XL: SubScreen.gpu->setAffineStart(3,0,val); - return; + break; case REG_DISPB_BG3YL: SubScreen.gpu->setAffineStart(3,1,val); - return; + break; case 0x04000600: GFX_FIFOcnt(val); @@ -2660,6 +3112,9 @@ void FASTCALL _MMU_ARM9_write32(u32 adr, u32 val) return; } } +#ifdef _MMU_DEBUG + mmu_log_debug_ARM9(adr, "(write32) %0x%X", val); +#endif T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], adr & MMU.MMU_MASK[ARMCPU_ARM9][adr>>20], val); return; @@ -2676,7 +3131,12 @@ void FASTCALL _MMU_ARM9_write32(u32 adr, u32 val) //================================================= MMU ARM9 read 08 u8 FASTCALL _MMU_ARM9_read08(u32 adr) { - mmu_log_debug_ARM9(adr, "(read08) %0x%X", MMU.MMU_MEM[ARMCPU_ARM9][(adr>>20)&0xFF][adr&MMU.MMU_MASK[ARMCPU_ARM9][(adr>>20)&0xFF]]); +#ifdef INTERNAL_DTCM_READ + if((adr&(~0x3FFF)) == MMU.DTCMRegion) + { + return T1ReadByte(ARM9Mem.ARM9_DTCM, adr&0x3FFF); + } +#endif if(adr<0x02000000) return T1ReadByte(ARM9Mem.ARM9_ITCM, adr&0x7FFF); @@ -2690,6 +3150,11 @@ u8 FASTCALL _MMU_ARM9_read08(u32 adr) return (unsigned char)cflash_read(adr); #endif +#ifdef _MMU_DEBUG + mmu_log_debug_ARM9(adr, "(read08) %0x%X", + MMU.MMU_MEM[ARMCPU_ARM9][(adr>>20)&0xFF][adr&MMU.MMU_MASK[ARMCPU_ARM9][(adr>>20)&0xFF]]); +#endif + bool unmapped; adr = MMU_LCDmap(adr, unmapped); if(unmapped) return 0; @@ -2700,7 +3165,12 @@ u8 FASTCALL _MMU_ARM9_read08(u32 adr) //================================================= MMU ARM9 read 16 u16 FASTCALL _MMU_ARM9_read16(u32 adr) { - mmu_log_debug_ARM9(adr, "(read16) %0x%X", T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM9][0x40], adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20) & 0xFF])); +#ifdef INTERNAL_DTCM_READ + if((adr&(~0x3FFF)) == MMU.DTCMRegion) + { + return T1ReadWord(ARM9Mem.ARM9_DTCM, adr & 0x3FFF); + } +#endif if(adr<0x02000000) return T1ReadWord(ARM9Mem.ARM9_ITCM, adr & 0x7FFF); @@ -2759,7 +3229,10 @@ u16 FASTCALL _MMU_ARM9_read16(u32 adr) case REG_POSTFLG : return 1; } - +#ifdef _MMU_DEBUG + mmu_log_debug_ARM9(adr, "(read16) %0x%X", + T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM9][0x40], adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20) & 0xFF])); +#endif return T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM9][0x40], adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20) & 0xFF]); } @@ -2773,7 +3246,22 @@ u16 FASTCALL _MMU_ARM9_read16(u32 adr) //================================================= MMU ARM9 read 32 u32 FASTCALL _MMU_ARM9_read32(u32 adr) { - mmu_log_debug_ARM9(adr, "(read32) %0x%X", T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20)])); +#ifdef INTERNAL_DTCM_READ + if((adr&(~0x3FFF)) == MMU.DTCMRegion) + { + /* Returns data from DTCM (ARM9 only) */ + return T1ReadLong(ARM9Mem.ARM9_DTCM, adr & 0x3FFF); + } +#endif + +#ifdef EARLY_MEMORY_ACCESS + if ( (adr & 0x0F000000) == 0x02000000) + return T1ReadLong( ARM9Mem.MAIN_MEM, adr & 0x3FFFFF); +#endif + + if(adr>=0x02400000 && adr<0x03000000) { + //int zzz=9; + } if(adr<0x02000000) return T1ReadLong(ARM9Mem.ARM9_ITCM, adr&0x7FFF); @@ -2940,6 +3428,10 @@ u32 FASTCALL _MMU_ARM9_read32(u32 adr) return val; } } +#ifdef _MMU_DEBUG + mmu_log_debug_ARM9(adr, "(read32) %0x%X", + T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20)])); +#endif return T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][0x40], adr & MMU.MMU_MASK[ARMCPU_ARM9][(adr >> 20)]); } @@ -2956,8 +3448,6 @@ u32 FASTCALL _MMU_ARM9_read32(u32 adr) //================================================= MMU ARM7 write 08 void FASTCALL _MMU_ARM7_write08(u32 adr, u8 val) { - mmu_log_debug_ARM7(adr, "(write08) %0x%X", val); - #ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) { @@ -3005,6 +3495,9 @@ void FASTCALL _MMU_ARM7_write08(u32 adr, u8 val) adr = MMU_LCDmap(adr,unmapped); if(unmapped) return; +#ifdef _MMU_DEBUG + mmu_log_debug_ARM7(adr, "(write08) %0x%X", val); +#endif // Removed the &0xFF as they are implicit with the adr&0x0FFFFFFFF [shash] MMU.MMU_MEM[ARMCPU_ARM7][adr>>20][adr&MMU.MMU_MASK[ARMCPU_ARM7][adr>>20]]=val; } @@ -3012,8 +3505,6 @@ void FASTCALL _MMU_ARM7_write08(u32 adr, u8 val) //================================================= MMU ARM7 write 16 void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val) { - mmu_log_debug_ARM7(adr, "(write16) %0x%X", val); - #ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) { @@ -3423,7 +3914,9 @@ void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val) return; //case REG_AUXSPICNT : emu_halt(); } - +#ifdef _MMU_DEBUG + mmu_log_debug_ARM7(adr, "(write16) %0x%X", val); +#endif T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM7][0x40], adr&MMU.MMU_MASK[ARMCPU_ARM7][adr>>20], val); return; } @@ -3438,8 +3931,6 @@ void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val) //================================================= MMU ARM7 write 32 void FASTCALL _MMU_ARM7_write32(u32 adr, u32 val) { - mmu_log_debug_ARM7(adr, "(write32) %0x%X", val); - #ifdef EXPERIMENTAL_GBASLOT if ( (adr >= 0x08000000) && (adr < 0x0A010000) ) { @@ -3712,6 +4203,9 @@ void FASTCALL _MMU_ARM7_write32(u32 adr, u32 val) } return; } +#ifdef _MMU_DEBUG + mmu_log_debug_ARM7(adr, "(write32) %0x%X", val); +#endif T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM7][0x40], adr & MMU.MMU_MASK[ARMCPU_ARM7][adr>>20], val); return; } @@ -3727,8 +4221,6 @@ void FASTCALL _MMU_ARM7_write32(u32 adr, u32 val) //================================================= MMU ARM7 read 08 u8 FASTCALL _MMU_ARM7_read08(u32 adr) { - mmu_log_debug_ARM7(adr, "(read08) %0x%X", MMU.MMU_MEM[ARMCPU_ARM7][(adr>>20)&0xFF][adr&MMU.MMU_MASK[ARMCPU_ARM7][(adr>>20)&0xFF]]); - #ifdef EXPERIMENTAL_WIFI /* wifi mac access */ if ((adr>=0x04800000)&&(adr<0x05000000)) @@ -3751,6 +4243,11 @@ u8 FASTCALL _MMU_ARM7_read08(u32 adr) if (adr == REG_RTC) return (u8)rtcRead(); +#ifdef _MMU_DEBUG + mmu_log_debug_ARM7(adr, "(read08) %0x%X", + MMU.MMU_MEM[ARMCPU_ARM7][(adr>>20)&0xFF][adr&MMU.MMU_MASK[ARMCPU_ARM7][(adr>>20)&0xFF]]); +#endif + bool unmapped; adr = MMU_LCDmap(adr,unmapped); if(unmapped) return 0; @@ -3760,8 +4257,6 @@ u8 FASTCALL _MMU_ARM7_read08(u32 adr) //================================================= MMU ARM7 read 16 u16 FASTCALL _MMU_ARM7_read16(u32 adr) { - mmu_log_debug_ARM7(adr, "(read16) %0x%X", T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM7][(adr >> 20) & 0xFF], adr & MMU.MMU_MASK[ARMCPU_ARM7][(adr >> 20) & 0xFF])); - #ifdef EXPERIMENTAL_WIFI /* wifi mac access */ if ((adr>=0x04800000)&&(adr<0x05000000)) @@ -3817,6 +4312,10 @@ u16 FASTCALL _MMU_ARM7_read16(u32 adr) case REG_POSTFLG : return 1; } +#ifdef _MMU_DEBUG + mmu_log_debug_ARM7(adr, "(read16) %0x%X", + T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM7][(adr >> 20) & 0xFF], adr & MMU.MMU_MASK[ARMCPU_ARM7][(adr >> 20) & 0xFF])); +#endif return T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM7][(adr >> 20) & 0xFF], adr & MMU.MMU_MASK[ARMCPU_ARM7][(adr >> 20) & 0xFF]); } @@ -3830,8 +4329,6 @@ u16 FASTCALL _MMU_ARM7_read16(u32 adr) //================================================= MMU ARM7 read 32 u32 FASTCALL _MMU_ARM7_read32(u32 adr) { - mmu_log_debug_ARM7(adr, "(read32) %0x%X", T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM7][(adr >> 20) & 0xFF], adr & MMU.MMU_MASK[ARMCPU_ARM7][(adr >> 20) & 0xFF])); - #ifdef EXPERIMENTAL_WIFI /* wifi mac access */ if ((adr>=0x04800000)&&(adr<0x05000000)) @@ -3930,6 +4427,10 @@ u32 FASTCALL _MMU_ARM7_read32(u32 adr) return val; } } +#ifdef _MMU_DEBUG + mmu_log_debug_ARM7(adr, "(read32) %0x%X", + T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM7][(adr >> 20) & 0xFF], adr & MMU.MMU_MASK[ARMCPU_ARM7][(adr >> 20) & 0xFF])); +#endif return T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM7][(adr >> 20)], adr & MMU.MMU_MASK[ARMCPU_ARM7][(adr >> 20)]); } @@ -4016,278 +4517,3 @@ void mmu_select_savetype(int type, int *bmemtype, u32 *bmemsize) { *bmemsize=save_types[type][1]; mc_realloc(&MMU.bupmem, *bmemtype, *bmemsize); } - -//////////////////////////////////////////////////////////// -//function pointer handlers for gdb stub stuff - -static u16 FASTCALL arm9_prefetch16( void *data, u32 adr) { - profile_memory_access( 1, adr, PROFILE_PREFETCH); - return _MMU_read16(adr); -} - -static u32 FASTCALL arm9_prefetch32( void *data, u32 adr) { - profile_memory_access( 1, adr, PROFILE_PREFETCH); - return _MMU_read32(adr); -} - -static u8 FASTCALL arm9_read8( void *data, u32 adr) { - profile_memory_access( 1, adr, PROFILE_READ); - return _MMU_read08(adr); -} - -static u16 FASTCALL arm9_read16( void *data, u32 adr) { - profile_memory_access( 1, adr, PROFILE_READ); - return _MMU_read16(adr); -} - -static u32 FASTCALL arm9_read32( void *data, u32 adr) { - profile_memory_access( 1, adr, PROFILE_READ); - return _MMU_read32(adr); -} - -static void FASTCALL arm9_write8(void *data, u32 adr, u8 val) { - profile_memory_access( 1, adr, PROFILE_WRITE); - _MMU_write08(adr, val); -} - -static void FASTCALL arm9_write16(void *data, u32 adr, u16 val) { - profile_memory_access( 1, adr, PROFILE_WRITE); - _MMU_write16(adr, val); -} - -static void FASTCALL arm9_write32(void *data, u32 adr, u32 val) { - profile_memory_access( 1, adr, PROFILE_WRITE); - _MMU_write32(adr, val); -} - -static u16 FASTCALL arm7_prefetch16( void *data, u32 adr) { - profile_memory_access( 0, adr, PROFILE_PREFETCH); - return _MMU_read16(adr); -} - -static u32 FASTCALL arm7_prefetch32( void *data, u32 adr) { - profile_memory_access( 0, adr, PROFILE_PREFETCH); - return _MMU_read32(adr); -} - -static u8 FASTCALL arm7_read8( void *data, u32 adr) { - profile_memory_access( 0, adr, PROFILE_READ); - return _MMU_read08(adr); -} - -static u16 FASTCALL arm7_read16( void *data, u32 adr) { - profile_memory_access( 0, adr, PROFILE_READ); - return _MMU_read16(adr); -} - -static u32 FASTCALL arm7_read32( void *data, u32 adr) { - profile_memory_access( 0, adr, PROFILE_READ); - return _MMU_read32(adr); -} - -static void FASTCALL arm7_write8(void *data, u32 adr, u8 val) { - profile_memory_access( 0, adr, PROFILE_WRITE); - _MMU_write08(adr, val); -} - -static void FASTCALL arm7_write16(void *data, u32 adr, u16 val) { - profile_memory_access( 0, adr, PROFILE_WRITE); - _MMU_write16(adr, val); -} - -static void FASTCALL arm7_write32(void *data, u32 adr, u32 val) { - profile_memory_access( 0, adr, PROFILE_WRITE); - _MMU_write32(adr, val); -} - - - -/* - * the base memory interfaces - */ -struct armcpu_memory_iface arm9_base_memory_iface = { - arm9_prefetch32, - arm9_prefetch16, - - arm9_read8, - arm9_read16, - arm9_read32, - - arm9_write8, - arm9_write16, - arm9_write32 -}; - -struct armcpu_memory_iface arm7_base_memory_iface = { - arm7_prefetch32, - arm7_prefetch16, - - arm7_read8, - arm7_read16, - arm7_read32, - - arm7_write8, - arm7_write16, - arm7_write32 -}; - -/* - * The direct memory interface for the ARM9. - * This avoids the ARM9 protection unit when accessing - * memory. - */ -struct armcpu_memory_iface arm9_direct_memory_iface = { - NULL, - NULL, - - arm9_read8, - arm9_read16, - arm9_read32, - - arm9_write8, - arm9_write16, - arm9_write32 -}; - - -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////// - -//#ifdef PROFILE_MEMORY_ACCESS -// -//#define PROFILE_PREFETCH 0 -//#define PROFILE_READ 1 -//#define PROFILE_WRITE 2 -// -//struct mem_access_profile { -// u64 num_accesses; -// u32 address_mask; -// u32 masked_value; -//}; -// -//#define PROFILE_NUM_MEM_ACCESS_PROFILES 4 -// -//static u64 profile_num_accesses[2][3]; -//static u64 profile_unknown_addresses[2][3]; -//static struct mem_access_profile -//profile_memory_accesses[2][3][PROFILE_NUM_MEM_ACCESS_PROFILES]; -// -//static void -//setup_profiling( void) { -// int i; -// -// for ( i = 0; i < 2; i++) { -// int access_type; -// -// for ( access_type = 0; access_type < 3; access_type++) { -// profile_num_accesses[i][access_type] = 0; -// profile_unknown_addresses[i][access_type] = 0; -// -// /* -// * Setup the access testing structures -// */ -// profile_memory_accesses[i][access_type][0].address_mask = 0x0e000000; -// profile_memory_accesses[i][access_type][0].masked_value = 0x00000000; -// profile_memory_accesses[i][access_type][0].num_accesses = 0; -// -// /* main memory */ -// profile_memory_accesses[i][access_type][1].address_mask = 0x0f000000; -// profile_memory_accesses[i][access_type][1].masked_value = 0x02000000; -// profile_memory_accesses[i][access_type][1].num_accesses = 0; -// -// /* shared memory */ -// profile_memory_accesses[i][access_type][2].address_mask = 0x0f800000; -// profile_memory_accesses[i][access_type][2].masked_value = 0x03000000; -// profile_memory_accesses[i][access_type][2].num_accesses = 0; -// -// /* arm7 memory */ -// profile_memory_accesses[i][access_type][3].address_mask = 0x0f800000; -// profile_memory_accesses[i][access_type][3].masked_value = 0x03800000; -// profile_memory_accesses[i][access_type][3].num_accesses = 0; -// } -// } -//} -// -//static void -//profile_memory_access( int arm9, u32 adr, int access_type) { -// static int first = 1; -// int mem_profile; -// int address_found = 0; -// -// if ( first) { -// setup_profiling(); -// first = 0; -// } -// -// profile_num_accesses[arm9][access_type] += 1; -// -// for ( mem_profile = 0; -// mem_profile < PROFILE_NUM_MEM_ACCESS_PROFILES && -// !address_found; -// mem_profile++) { -// if ( (adr & profile_memory_accesses[arm9][access_type][mem_profile].address_mask) == -// profile_memory_accesses[arm9][access_type][mem_profile].masked_value) { -// /*printf( "adr %08x mask %08x res %08x expected %08x\n", -// adr, -// profile_memory_accesses[arm9][access_type][mem_profile].address_mask, -// adr & profile_memory_accesses[arm9][access_type][mem_profile].address_mask, -// profile_memory_accesses[arm9][access_type][mem_profile].masked_value);*/ -// address_found = 1; -// profile_memory_accesses[arm9][access_type][mem_profile].num_accesses += 1; -// } -// } -// -// if ( !address_found) { -// profile_unknown_addresses[arm9][access_type] += 1; -// } -//} -// -// -//static const char *access_type_strings[] = { -// "prefetch", -// "read ", -// "write " -//}; -// -//void -//print_memory_profiling( void) { -// int arm; -// -// printf("------ Memory access profile ------\n"); -// -// for ( arm = 0; arm < 2; arm++) { -// int access_type; -// -// for ( access_type = 0; access_type < 3; access_type++) { -// int mem_profile; -// printf("ARM%c: num of %s %lld\n", -// arm ? '9' : '7', -// access_type_strings[access_type], -// profile_num_accesses[arm][access_type]); -// -// for ( mem_profile = 0; -// mem_profile < PROFILE_NUM_MEM_ACCESS_PROFILES; -// mem_profile++) { -// printf( "address %08x: %lld\n", -// profile_memory_accesses[arm][access_type][mem_profile].masked_value, -// profile_memory_accesses[arm][access_type][mem_profile].num_accesses); -// } -// -// printf( "unknown addresses %lld\n", -// profile_unknown_addresses[arm][access_type]); -// -// printf( "\n"); -// } -// } -// -// printf("------ End of Memory access profile ------\n\n"); -//} -//#else -//void -//print_memory_profiling( void) { -//} -//#endif /* End of PROFILE_MEMORY_ACCESS area */ diff --git a/desmume/src/MMU.h b/src/MMU.h similarity index 63% rename from desmume/src/MMU.h rename to src/MMU.h index d4e987951..cb81e178b 100644 --- a/desmume/src/MMU.h +++ b/src/MMU.h @@ -45,7 +45,7 @@ /* theses ones for reading in rom data */ #define ROM_8(m, a) (((u8*)(m))[(a)]) -typedef const u8 TWaitState; +typedef const u32 TWaitState; struct MMU_struct { //ARM7 mem @@ -80,8 +80,8 @@ struct MMU_struct { u8 ARM9_RW_MODE; - static CACHE_ALIGN TWaitState MMU_WAIT16[2][16]; - static CACHE_ALIGN TWaitState MMU_WAIT32[2][16]; + static TWaitState MMU_WAIT16[2][16]; + static TWaitState MMU_WAIT32[2][16]; u32 DTCMRegion; u32 ITCMRegion; @@ -175,57 +175,21 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val); template void FASTCALL MMU_doDMA(u32 num); -//The base ARM memory interfaces +/* + * The base ARM memory interfaces + */ extern struct armcpu_memory_iface arm9_base_memory_iface; extern struct armcpu_memory_iface arm7_base_memory_iface; extern struct armcpu_memory_iface arm9_direct_memory_iface; extern u8 *MMU_RenderMapToLCD(u32 vram_addr); -#define VRAM_ARM9_PAGES 512 -extern u8 vram_arm9_map[VRAM_ARM9_PAGES]; -FORCEINLINE void* MMU_gpu_map(u32 vram_addr) -{ - //THIS FUNCTION IS NOT AS DANGEROUS! - //as an alternative to the above, use this: - //it is supposed to map a single gpu vram address to emulator host memory - //but it returns a pointer to some zero memory in case of accesses to unmapped memory. - //this correctly handles the case with tile accesses to unmapped memory. - //it could also potentially go through a different LUT than vram_arm9_map in case we discover - //that it needs to be set up with different or no mirroring - //(I think it is a reasonable possibility that only the cpu has the nutty mirroring rules) - // - //if this system isn't used, Fantasy Aquarium displays garbage in the first ingame screen - //due to it storing 0x0F0F or somesuch in screen memory which points to a ridiculously big tile - //which should contain all 0 pixels - - u32 vram_page = (vram_addr>>14)&(VRAM_ARM9_PAGES-1); - u32 ofs = vram_addr & 0x3FFF; - vram_page = vram_arm9_map[vram_page]; - //blank pages are handled by the extra 16KB of blank memory at the end of ARM9_LCD - //and the fact that blank pages are mapped to appear at that location - return ARM9Mem.ARM9_LCD + (vram_page<<14) + ofs; -} - - -enum MMU_ACCESS_TYPE -{ - MMU_AT_CODE, MMU_AT_DATA, MMU_AT_GPU -}; - -template u8 _MMU_read08(u32 addr); -template u16 _MMU_read16(u32 addr); -template u32 _MMU_read32(u32 addr); -template void _MMU_write08(u32 addr, u8 val); -template void _MMU_write16(u32 addr, u16 val); -template void _MMU_write32(u32 addr, u32 val); - -template u8 _MMU_read08(u32 addr) { return _MMU_read08(addr); } -template u16 _MMU_read16(u32 addr) { return _MMU_read16(addr); } -template u32 _MMU_read32(u32 addr) { return _MMU_read32(addr); } -template void _MMU_write08(u32 addr, u8 val) { _MMU_write08(addr,val); } -template void _MMU_write16(u32 addr, u16 val) { _MMU_write16(addr,val); } -template void _MMU_write32(u32 addr, u32 val) { _MMU_write32(addr,val); } +template u8 _MMU_read08(u32 addr); +template u16 _MMU_read16(u32 addr); +template u32 _MMU_read32(u32 addr); +template void _MMU_write08(u32 addr, u8 val); +template void _MMU_write16(u32 addr, u16 val); +template void _MMU_write32(u32 addr, u32 val); void FASTCALL _MMU_ARM9_write08(u32 adr, u8 val); void FASTCALL _MMU_ARM9_write16(u32 adr, u16 val); @@ -247,13 +211,7 @@ inline void SetupMMU(bool debugConsole) { else _MMU_MAIN_MEM_MASK = 0x3FFFFF; } -//TODO: at one point some of the early access code included this. consider re-adding it - //ARM7 private memory - //if ( (adr & 0x0f800000) == 0x03800000) { - //T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM7][(adr >> 20) & 0xFF], - // adr & MMU.MMU_MASK[ARMCPU_ARM7][(adr >> 20) & 0xFF]); - -FORCEINLINE u8 _MMU_read08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u32 addr) { +FORCEINLINE u8 _MMU_read08(const int PROCNUM, u32 addr) { if(PROCNUM==ARMCPU_ARM9) if((addr&(~0x3FFF)) == MMU.DTCMRegion) { @@ -268,20 +226,7 @@ FORCEINLINE u8 _MMU_read08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u3 else return _MMU_ARM7_read08(addr); } -FORCEINLINE u16 _MMU_read16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u32 addr) { - - //special handling for execution from arm9, since we spend so much time in there - if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_CODE) - { - if ((addr & 0x0F000000) == 0x02000000) - return T1ReadWord( ARM9Mem.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK); - - if(addr<0x02000000) - return T1ReadWord(ARM9Mem.ARM9_ITCM, addr&0x7FFF); - - goto dunno; - } - +FORCEINLINE u16 _MMU_read16(const int PROCNUM, u32 addr) { if(PROCNUM==ARMCPU_ARM9) if((addr&(~0x3FFF)) == MMU.DTCMRegion) { @@ -292,26 +237,11 @@ FORCEINLINE u16 _MMU_read16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u if ( (addr & 0x0F000000) == 0x02000000) return T1ReadWord( ARM9Mem.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK); -dunno: if(PROCNUM==ARMCPU_ARM9) return _MMU_ARM9_read16(addr); else return _MMU_ARM7_read16(addr); } -FORCEINLINE u32 _MMU_read32(int PROCNUM, const MMU_ACCESS_TYPE AT, const u32 addr) { - - //special handling for execution from arm9, since we spend so much time in there - if(PROCNUM==ARMCPU_ARM9 && AT == MMU_AT_CODE) - { - if ( (addr & 0x0F000000) == 0x02000000) - return T1ReadLong( ARM9Mem.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK); - - if(addr<0x02000000) - return T1ReadLong(ARM9Mem.ARM9_ITCM, addr&0x7FFF); - - goto dunno; - } - - //for other cases, we have to check from dtcm first because it is patched on top of the main memory range +FORCEINLINE u32 _MMU_read32(int PROCNUM, u32 addr) { if(PROCNUM==ARMCPU_ARM9) if((addr&(~0x3FFF)) == MMU.DTCMRegion) { @@ -322,12 +252,11 @@ FORCEINLINE u32 _MMU_read32(int PROCNUM, const MMU_ACCESS_TYPE AT, const u32 add if ( (addr & 0x0F000000) == 0x02000000) return T1ReadLong( ARM9Mem.MAIN_MEM, addr & _MMU_MAIN_MEM_MASK); -dunno: if(PROCNUM==ARMCPU_ARM9) return _MMU_ARM9_read32(addr); else return _MMU_ARM7_read32(addr); } -FORCEINLINE void _MMU_write08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u32 addr, u8 val) { +FORCEINLINE void _MMU_write08(const int PROCNUM, u32 addr, u8 val) { if(PROCNUM==ARMCPU_ARM9) if((addr&(~0x3FFF)) == MMU.DTCMRegion) { @@ -344,7 +273,7 @@ FORCEINLINE void _MMU_write08(const int PROCNUM, const MMU_ACCESS_TYPE AT, const else _MMU_ARM7_write08(addr,val); } -FORCEINLINE void _MMU_write16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u32 addr, u16 val) { +FORCEINLINE void _MMU_write16(const int PROCNUM, u32 addr, u16 val) { if(PROCNUM==ARMCPU_ARM9) if((addr&(~0x3FFF)) == MMU.DTCMRegion) { @@ -361,7 +290,7 @@ FORCEINLINE void _MMU_write16(const int PROCNUM, const MMU_ACCESS_TYPE AT, const else _MMU_ARM7_write16(addr,val); } -FORCEINLINE void _MMU_write32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const u32 addr, u32 val) { +FORCEINLINE void _MMU_write32(const int PROCNUM, u32 addr, u32 val) { if(PROCNUM==ARMCPU_ARM9) if((addr&(~0x3FFF)) == MMU.DTCMRegion) { @@ -391,8 +320,8 @@ FORCEINLINE void _MMU_write32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const #define MMU_write16_acl(proc, adr, val) _MMU_write16(adr, val) #define MMU_write32_acl(proc, adr, val) _MMU_write32(adr, val) #define MMU_read8_acl(proc,adr,access) _MMU_read08(adr) - #define MMU_read16_acl(proc,adr,access) ((access==CP15_ACCESS_EXECUTE)?_MMU_read16(adr):_MMU_read16(adr)) - #define MMU_read32_acl(proc,adr,access) ((access==CP15_ACCESS_EXECUTE)?_MMU_read32(adr):_MMU_read32(adr)) + #define MMU_read16_acl(proc,adr,access) _MMU_read16(adr) + #define MMU_read32_acl(proc,adr,access) _MMU_read32(adr) #endif // Use this macros for reading/writing, so the GDB stub isn't broken @@ -412,23 +341,23 @@ FORCEINLINE void _MMU_write32(const int PROCNUM, const MMU_ACCESS_TYPE AT, const #define WRITE8(a,b,c) _MMU_write08(b, c) #endif -template -u8 _MMU_read08(u32 addr) { return _MMU_read08(PROCNUM, AT, addr); } +template +u8 _MMU_read08(u32 addr) { return _MMU_read08(PROCNUM, addr); } -template -u16 _MMU_read16(u32 addr) { return _MMU_read16(PROCNUM, AT, addr); } +template +u16 _MMU_read16(u32 addr) { return _MMU_read16(PROCNUM, addr); } -template -u32 _MMU_read32(u32 addr) { return _MMU_read32(PROCNUM, AT, addr); } +template +u32 _MMU_read32(u32 addr) { return _MMU_read32(PROCNUM, addr); } -template -void _MMU_write08(u32 addr, u8 val) { _MMU_write08(PROCNUM, AT, addr, val); } +template +void _MMU_write08(u32 addr, u8 val) { _MMU_write08(PROCNUM, addr, val); } -template -void _MMU_write16(u32 addr, u16 val) { _MMU_write16(PROCNUM, AT, addr, val); } +template +void _MMU_write16(u32 addr, u16 val) { _MMU_write16(PROCNUM, addr, val); } -template -void _MMU_write32(u32 addr, u32 val) { _MMU_write32(PROCNUM, AT, addr, val); } +template +void _MMU_write32(u32 addr, u32 val) { _MMU_write32(PROCNUM, addr, val); } void FASTCALL MMU_DumpMemBlock(u8 proc, u32 address, u32 size, u8 *buffer); diff --git a/desmume/src/Makefile.am b/src/Makefile.am similarity index 100% rename from desmume/src/Makefile.am rename to src/Makefile.am diff --git a/desmume/src/NDSSystem.cpp b/src/NDSSystem.cpp similarity index 99% rename from desmume/src/NDSSystem.cpp rename to src/NDSSystem.cpp index e874bc47a..d9a0ec3b1 100644 --- a/desmume/src/NDSSystem.cpp +++ b/src/NDSSystem.cpp @@ -854,7 +854,7 @@ void NDS_FreeROM(void) MMU.bupmem.fp = NULL; } -void NDS_Reset(BOOL resetBySavestate) +void NDS_Reset( void) { unsigned int i; u32 src; @@ -1034,8 +1034,7 @@ void NDS_Reset(BOOL resetBySavestate) gfx3d_reset(); gpu3D->NDS_3D_Reset(); SPU_Reset(); - if (!resetBySavestate) - cheatsSearchClose(); + cheatsSearchClose(); #ifdef EXPERIMENTAL_WIFI WIFI_Init(&wifiMac); @@ -1815,7 +1814,7 @@ u32 NDS_exec(s32 nb) if(MMU.DMAStartTime[1][3] == 1) MMU_doDMA(3); } - else if(nds.VCount==214) + else if(nds.VCount==215) { gfx3d_VBlankEndSignal(false); } diff --git a/desmume/src/NDSSystem.h b/src/NDSSystem.h similarity index 99% rename from desmume/src/NDSSystem.h rename to src/NDSSystem.h index 0092d79b9..2cfefa3fd 100644 --- a/desmume/src/NDSSystem.h +++ b/src/NDSSystem.h @@ -274,7 +274,7 @@ int NDS_LoadROM(const char *filename, int bmtype, u32 bmsize, const char *cflash_disk_image_file); #endif void NDS_FreeROM(void); -void NDS_Reset(BOOL resetBySaveState = FALSE); +void NDS_Reset(void); int NDS_ImportSave(const char *filename); int NDS_WriteBMP(const char *filename); diff --git a/desmume/src/OGLRender.cpp b/src/OGLRender.cpp similarity index 86% rename from desmume/src/OGLRender.cpp rename to src/OGLRender.cpp index 4cd4cae75..da136c3b0 100644 --- a/desmume/src/OGLRender.cpp +++ b/src/OGLRender.cpp @@ -75,15 +75,19 @@ static void ENDGL() { #define CTASSERT(x) typedef char __assert ## y[(x) ? 1 : -1] #endif -static ALIGN(16) u8 GPU_screen3D [256*192*4]; - +static ALIGN(16) u8 GPU_screen3D [256*192*4]; +//static ALIGN(16) unsigned char GPU_screenStencil[256*256]; static const unsigned short map3d_cull[4] = {GL_FRONT_AND_BACK, GL_FRONT, GL_BACK, 0}; static const int texEnv[4] = { GL_MODULATE, GL_DECAL, GL_MODULATE, GL_MODULATE }; static const int depthFunc[2] = { GL_LESS, GL_EQUAL }; static bool needRefreshFramebuffer = false; -static bool validFramebuffer = false; + +float clearAlpha; + + + //derived values extracted from polyattr etc static bool wireframe=false, alpha31=false; @@ -470,6 +474,11 @@ static char OGLInit(void) glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP); //clamp so that we dont run off the edges due to 1.0 -> [0,31] math } + if(glBlendFuncSeparateEXT == NULL) + clearAlpha = 1; + else + clearAlpha = 0; + OGLReset(); ENDGL(); @@ -527,7 +536,7 @@ static void setTexture(unsigned int format, unsigned int texpal) } - TexCache_SetTexture(format, texpal); + TexCache_SetTexture(format, texpal); } @@ -830,7 +839,6 @@ static void OGLVramReconfigureSignal() TexCache_Invalidate(); } - static void GL_ReadFramebuffer() { if(!BEGINGL()) return; @@ -841,47 +849,141 @@ static void GL_ReadFramebuffer() //convert the pixels to a different format which is more convenient //is it safe to modify the screen buffer? if not, we could make a temp copy - for(int i=0,y=191;y>=0;y--) - { - u16* dst = gfx3d_convertedScreen + (y<<8); - u8* dstAlpha = gfx3d_convertedAlpha + (y<<8); - - #ifndef NOSSE2 - //I dont know much about this kind of stuff, but this seems to help - //for some reason I couldnt make the intrinsics work - u8* wanx = (u8*)&((u32*)GPU_screen3D)[i]; - #define ASS(X,Y) __asm { prefetchnta [wanx+32*0x##X##Y] } - #define PUNK(X) ASS(X,0) ASS(X,1) ASS(X,2) ASS(X,3) ASS(X,4) ASS(X,5) ASS(X,6) ASS(X,7) ASS(X,8) ASS(X,9) ASS(X,A) ASS(X,B) ASS(X,C) ASS(X,D) ASS(X,E) ASS(X,F) - PUNK(0); PUNK(1); - #endif - - for(int x=0;x<256;x++,i++) - { - u32 &u32screen3D = ((u32*)GPU_screen3D)[i]; - u32screen3D>>=3; - u32screen3D &= 0x1F1F1F1F; - - const int t = i<<2; - const u8 a = GPU_screen3D[t+3]; - const u8 r = GPU_screen3D[t+2]; - const u8 g = GPU_screen3D[t+1]; - const u8 b = GPU_screen3D[t+0]; - dst[x] = R5G5B5TORGB15(r,g,b) | alpha_lookup[a]; - dstAlpha[x] = alpha_5bit_to_4bit[a]; - } + for(int i=0;i<256*192;i++) { + u32 &u32screen3D = ((u32*)GPU_screen3D)[i]; + u32screen3D>>=3; + u32screen3D &= 0x1F1F1F1F; } + + +//debug: view depth buffer via color buffer for debugging + //int ctr=0; + //for(ctr=0;ctr<256*192;ctr++) { + // float zval = GPU_screen3Ddepth[ctr]; + // u8* colorPtr = GPU_screen3D+ctr*3; + // if(zval<0) { + // colorPtr[0] = 255; + // colorPtr[1] = 0; + // colorPtr[2] = 0; + // } else if(zval>1) { + // colorPtr[0] = 0; + // colorPtr[1] = 0; + // colorPtr[2] = 255; + // } else { + // colorPtr[0] = colorPtr[1] = colorPtr[2] = zval*255; + // //INFO("%f %f %d\n",zval, zval*255,colorPtr[0]); + // } + + //} } -static void OGLCheckFresh() +static void OGLGetLineCaptured(int line, u16* dst) { - if(needRefreshFramebuffer) - { + if(needRefreshFramebuffer) { needRefreshFramebuffer = false; GL_ReadFramebuffer(); } + + u8 *screen3D = (u8*)GPU_screen3D+((191-line)<<10); +// u8 *screenStencil = (u8*)GPU_screenStencil+((191-line)<<8); + + for(int i = 0; i < 256; i++) + { + /* u32 stencil = screenStencil[i]; + + if(!stencil) + { + dst[i] = 0x0000; + continue; + }*/ + + int t=i<<2; + /* u8 r = screen3D[t+2]; + u8 g = screen3D[t+1]; + u8 b = screen3D[t+0];*/ + + //if this math strikes you as wrong, be sure to look at GL_ReadFramebuffer() where the pixel format in screen3D is changed + //dst[i] = (b<<10) | (g<<5) | (r) | 0x8000; + dst[i] = (screen3D[t+2] | (screen3D[t+1] << 5) | (screen3D[t+0] << 10) | ((screen3D[t+3] > 0) ? 0x8000 : 0x0000)); + } } +static void OGLGetLine(int line, u16* dst, u8* dstAlpha) +{ + assert(line<192 && line>=0); + + if(needRefreshFramebuffer) { + needRefreshFramebuffer = false; + GL_ReadFramebuffer(); + } + + u8 *screen3D = (u8*)GPU_screen3D+((191-line)<<10); + //u8 *screenStencil = (u8*)GPU_screenStencil+((191-line)<<8); + + //the renderer clears the stencil to 0 + //then it sets it to 1 whenever it renders a pixel that passes the alpha test + //(it also sets it to 2 under some circumstances when rendering shadow volumes) + //so, we COULD use a zero stencil value to indicate that nothing should get composited. + //in fact, we are going to do that to fix some problems. + //but beware that it i figure it might could CAUSE some problems + + //this alpha compositing blending logic isnt thought through very much + //someone needs to think about what bitdepth it should take place at and how to do it efficiently + + for(int i=0;i<256;i++) + { + // u32 stencil = screenStencil[i]; + + //you would use this if you wanted to use the stencil buffer to make decisions here + // if(!stencil) continue; + + // u16 oldcolor = dst[j]; + + int t=i<<2; + // u32 dstpixel; + + dst[i] = (screen3D[t+2] | (screen3D[t+1] << 5) | (screen3D[t+0] << 10) | ((screen3D[t+3] > 0) ? 0x8000 : 0x0000)); + dstAlpha[i] = alpha_5bit_to_4bit[screen3D[t+3]]; + + //old debug reminder: display alpha channel + //u32 r = screen3D[t+3]; + //u32 g = screen3D[t+3]; + //u32 b = screen3D[t+3]; + + //if this math strikes you as wrong, be sure to look at GL_ReadFramebuffer() where the pixel format in screen3D is changed + + /* u32 a = screen3D[t+3]; + + typedef u8 mixtbl[32][32]; + mixtbl & mix = mixTable555[a]; + + //r + u32 newpix = screen3D[t+2]; + u32 oldpix = oldcolor&0x1F; + newpix = mix[newpix][oldpix]; + dstpixel = newpix; + + //g + newpix = screen3D[t+1]; + oldpix = (oldcolor>>5)&0x1F; + newpix = mix[newpix][oldpix]; + dstpixel |= (newpix<<5); + + //b + newpix = screen3D[t+0]; + oldpix = (oldcolor>>10)&0x1F; + newpix = mix[newpix][oldpix]; + dstpixel |= (newpix<<10); + + dst[j] = dstpixel;*/ + } +} + + + + + GPU3DInterface gpu3Dgl = { "OpenGL", OGLInit, @@ -889,5 +991,9 @@ GPU3DInterface gpu3Dgl = { OGLClose, OGLRender, OGLVramReconfigureSignal, - OGLCheckFresh, + OGLGetLine, + OGLGetLineCaptured }; + + + diff --git a/desmume/src/OGLRender.h b/src/OGLRender.h similarity index 100% rename from desmume/src/OGLRender.h rename to src/OGLRender.h diff --git a/desmume/src/PACKED.h b/src/PACKED.h similarity index 100% rename from desmume/src/PACKED.h rename to src/PACKED.h diff --git a/desmume/src/PACKED_END.h b/src/PACKED_END.h similarity index 100% rename from desmume/src/PACKED_END.h rename to src/PACKED_END.h diff --git a/desmume/src/ROMReader.cpp b/src/ROMReader.cpp similarity index 98% rename from desmume/src/ROMReader.cpp rename to src/ROMReader.cpp index 66b8d8900..96d4767ac 100644 --- a/desmume/src/ROMReader.cpp +++ b/src/ROMReader.cpp @@ -227,10 +227,6 @@ int ZIPROMReaderSeek(void * file, int offset, int whence) int ZIPROMReaderRead(void * file, void * buffer, u32 size) { -#ifdef ZZIP_OLD_READ - return zzip_read((ZZIP_FILE*)file, (char *) buffer, size); -#else return zzip_read((ZZIP_FILE*)file, buffer, size); -#endif } #endif diff --git a/desmume/src/ROMReader.h b/src/ROMReader.h similarity index 100% rename from desmume/src/ROMReader.h rename to src/ROMReader.h diff --git a/desmume/src/SPU.cpp b/src/SPU.cpp similarity index 100% rename from desmume/src/SPU.cpp rename to src/SPU.cpp diff --git a/desmume/src/SPU.h b/src/SPU.h similarity index 100% rename from desmume/src/SPU.h rename to src/SPU.h diff --git a/desmume/src/addons.cpp b/src/addons.cpp similarity index 100% rename from desmume/src/addons.cpp rename to src/addons.cpp diff --git a/desmume/src/addons.h b/src/addons.h similarity index 100% rename from desmume/src/addons.h rename to src/addons.h diff --git a/desmume/src/addons/compactFlash.cpp b/src/addons/compactFlash.cpp similarity index 100% rename from desmume/src/addons/compactFlash.cpp rename to src/addons/compactFlash.cpp diff --git a/desmume/src/addons/gbagame.cpp b/src/addons/gbagame.cpp similarity index 100% rename from desmume/src/addons/gbagame.cpp rename to src/addons/gbagame.cpp diff --git a/desmume/src/addons/none.cpp b/src/addons/none.cpp similarity index 100% rename from desmume/src/addons/none.cpp rename to src/addons/none.cpp diff --git a/desmume/src/addons/rumblepak.cpp b/src/addons/rumblepak.cpp similarity index 100% rename from desmume/src/addons/rumblepak.cpp rename to src/addons/rumblepak.cpp diff --git a/desmume/src/arm_instructions.cpp b/src/arm_instructions.cpp similarity index 100% rename from desmume/src/arm_instructions.cpp rename to src/arm_instructions.cpp diff --git a/desmume/src/arm_instructions.h b/src/arm_instructions.h similarity index 100% rename from desmume/src/arm_instructions.h rename to src/arm_instructions.h diff --git a/desmume/src/armcpu.cpp b/src/armcpu.cpp similarity index 100% rename from desmume/src/armcpu.cpp rename to src/armcpu.cpp diff --git a/desmume/src/armcpu.h b/src/armcpu.h similarity index 100% rename from desmume/src/armcpu.h rename to src/armcpu.h diff --git a/desmume/src/bios.cpp b/src/bios.cpp similarity index 88% rename from desmume/src/bios.cpp rename to src/bios.cpp index 238a3425c..ba78e588b 100644 --- a/desmume/src/bios.cpp +++ b/src/bios.cpp @@ -224,7 +224,7 @@ TEMPLATE u32 intrWaitARM() } else { intrFlagAdr = (((armcp15_t *)(cpu->coproc[15]))->DTCMRegion&0xFFFFF000)+0x3FF8; } - intr = _MMU_read32(intrFlagAdr); + intr = _MMU_read32(cpu->proc_ID,intrFlagAdr); intrFlag = (cpu->R[1] & intr); if(!noDiscard) @@ -236,7 +236,7 @@ TEMPLATE u32 intrWaitARM() // on efface son(les) occurence(s). intr ^= intrFlag; cpu->newIrqFlags ^= intrFlag; - _MMU_write32(intrFlagAdr, intr); + _MMU_write32(cpu->proc_ID, intrFlagAdr, intr); //cpu->switchMode(oldmode[cpu->proc_ID]); return 1; } @@ -266,7 +266,7 @@ TEMPLATE static u32 waitVBlankARM() } else { intrFlagAdr = (((armcp15_t *)(cpu->coproc[15]))->DTCMRegion&0xFFFFF000)+0x3FF8; } - intr = _MMU_read32(intrFlagAdr); + intr = _MMU_read32(cpu->proc_ID,intrFlagAdr); intrFlag = 1 & intr; // if(intrFlag) @@ -274,7 +274,7 @@ TEMPLATE static u32 waitVBlankARM() // si une(ou plusieurs) des interruptions que l'on attend s'est(se sont) produite(s) // on efface son(les) occurence(s). intr ^= intrFlag; - _MMU_write32(intrFlagAdr, intr); + _MMU_write32(cpu->proc_ID,intrFlagAdr, intr); //cpu->switchMode(oldmode[cpu->proc_ID]); return 1; } @@ -314,7 +314,7 @@ TEMPLATE static u32 wait4IRQ() TEMPLATE static u32 sleep() { - _MMU_write08(0x04000301, 0xC0); + _MMU_write08(cpu->proc_ID, 0x04000301, 0xC0); return 1; } @@ -351,7 +351,7 @@ TEMPLATE static u32 copy() cnt &= 0x1FFFFF; while(cnt) { - _MMU_write16(dst, _MMU_read16(src)); + _MMU_write16(cpu->proc_ID,dst, _MMU_read16(cpu->proc_ID,src)); cnt--; dst+=2; src+=2; @@ -359,11 +359,11 @@ TEMPLATE static u32 copy() break; case 1: { - u32 val = _MMU_read16(src); + u32 val = _MMU_read16(cpu->proc_ID, src); cnt &= 0x1FFFFF; while(cnt) { - _MMU_write16(dst, val); + _MMU_write16(cpu->proc_ID, dst, val); cnt--; dst+=2; } @@ -380,7 +380,7 @@ TEMPLATE static u32 copy() cnt &= 0x1FFFFF; while(cnt) { - _MMU_write32(dst, _MMU_read32(src)); + _MMU_write32(cpu->proc_ID, dst, _MMU_read32(cpu->proc_ID, src)); cnt--; dst+=4; src+=4; @@ -388,11 +388,11 @@ TEMPLATE static u32 copy() break; case 1: { - u32 val = _MMU_read32(src); + u32 val = _MMU_read32(cpu->proc_ID, src); cnt &= 0x1FFFFF; while(cnt) { - _MMU_write32(dst, val); + _MMU_write32(cpu->proc_ID,dst, val); cnt--; dst+=4; } @@ -418,7 +418,7 @@ TEMPLATE static u32 fastCopy() cnt &= 0x1FFFFF; while(cnt) { - _MMU_write32(dst, _MMU_read32(src)); + _MMU_write32(cpu->proc_ID,dst, _MMU_read32(cpu->proc_ID,src)); cnt--; dst+=4; src+=4; @@ -426,11 +426,11 @@ TEMPLATE static u32 fastCopy() break; case 1: { - u32 val = _MMU_read32(src); + u32 val = _MMU_read32(cpu->proc_ID,src); cnt &= 0x1FFFFF; while(cnt) { - _MMU_write32(dst, val); + _MMU_write32(cpu->proc_ID,dst, val); cnt--; dst+=4; } @@ -449,7 +449,7 @@ TEMPLATE static u32 LZ77UnCompVram() int len; u32 source = cpu->R[0]; u32 dest = cpu->R[1]; - u32 header = _MMU_read32(source); + u32 header = _MMU_read32(cpu->proc_ID,source); source += 4; //INFO("swi lz77uncompvram\n"); @@ -465,7 +465,7 @@ TEMPLATE static u32 LZ77UnCompVram() len = header >> 8; while(len > 0) { - u8 d = _MMU_read08(source++); + u8 d = _MMU_read08(cpu->proc_ID,source++); if(d) { for(i1 = 0; i1 < 8; i1++) { @@ -473,18 +473,18 @@ TEMPLATE static u32 LZ77UnCompVram() int length; int offset; u32 windowOffset; - u16 data = _MMU_read08(source++) << 8; - data |= _MMU_read08(source++); + u16 data = _MMU_read08(cpu->proc_ID,source++) << 8; + data |= _MMU_read08(cpu->proc_ID,source++); length = (data >> 12) + 3; offset = (data & 0x0FFF); windowOffset = dest + byteCount - offset - 1; for(i2 = 0; i2 < length; i2++) { - writeValue |= (_MMU_read08(windowOffset++) << byteShift); + writeValue |= (_MMU_read08(cpu->proc_ID,windowOffset++) << byteShift); byteShift += 8; byteCount++; if(byteCount == 2) { - _MMU_write16(dest, writeValue); + _MMU_write16(cpu->proc_ID,dest, writeValue); dest += 2; byteCount = 0; byteShift = 0; @@ -495,11 +495,11 @@ TEMPLATE static u32 LZ77UnCompVram() return 0; } } else { - writeValue |= (_MMU_read08(source++) << byteShift); + writeValue |= (_MMU_read08(cpu->proc_ID,source++) << byteShift); byteShift += 8; byteCount++; if(byteCount == 2) { - _MMU_write16(dest, writeValue); + _MMU_write16(cpu->proc_ID,dest, writeValue); dest += 2; byteCount = 0; byteShift = 0; @@ -513,11 +513,11 @@ TEMPLATE static u32 LZ77UnCompVram() } } else { for(i1 = 0; i1 < 8; i1++) { - writeValue |= (_MMU_read08(source++) << byteShift); + writeValue |= (_MMU_read08(cpu->proc_ID, source++) << byteShift); byteShift += 8; byteCount++; if(byteCount == 2) { - _MMU_write16(dest, writeValue); + _MMU_write16(cpu->proc_ID, dest, writeValue); dest += 2; byteShift = 0; byteCount = 0; @@ -539,7 +539,7 @@ TEMPLATE static u32 LZ77UnCompWram() u32 source = cpu->R[0]; u32 dest = cpu->R[1]; - u32 header = _MMU_read32(source); + u32 header = _MMU_read32(cpu->proc_ID, source); source += 4; //INFO("swi lz77uncompwram\n"); @@ -551,7 +551,7 @@ TEMPLATE static u32 LZ77UnCompWram() len = header >> 8; while(len > 0) { - u8 d = _MMU_read08(source++); + u8 d = _MMU_read08(cpu->proc_ID, source++); if(d) { for(i1 = 0; i1 < 8; i1++) { @@ -559,19 +559,19 @@ TEMPLATE static u32 LZ77UnCompWram() int length; int offset; u32 windowOffset; - u16 data = _MMU_read08(source++) << 8; - data |= _MMU_read08(source++); + u16 data = _MMU_read08(cpu->proc_ID, source++) << 8; + data |= _MMU_read08(cpu->proc_ID, source++); length = (data >> 12) + 3; offset = (data & 0x0FFF); windowOffset = dest - offset - 1; for(i2 = 0; i2 < length; i2++) { - _MMU_write08(dest++, _MMU_read08(windowOffset++)); + _MMU_write08(cpu->proc_ID, dest++, _MMU_read08(cpu->proc_ID, windowOffset++)); len--; if(len == 0) return 0; } } else { - _MMU_write08(dest++, _MMU_read08(source++)); + _MMU_write08(cpu->proc_ID, dest++, _MMU_read08(cpu->proc_ID,source++)); len--; if(len == 0) return 0; @@ -580,7 +580,7 @@ TEMPLATE static u32 LZ77UnCompWram() } } else { for(i1 = 0; i1 < 8; i1++) { - _MMU_write08(dest++, _MMU_read08(source++)); + _MMU_write08(cpu->proc_ID,dest++, _MMU_read08(cpu->proc_ID, source++)); len--; if(len == 0) return 0; @@ -600,7 +600,7 @@ TEMPLATE static u32 RLUnCompVram() u32 source = cpu->R[0]; u32 dest = cpu->R[1]; - u32 header = _MMU_read32(source); + u32 header = _MMU_read32(cpu->proc_ID, source); source += 4; //INFO("swi rluncompvram\n"); @@ -615,10 +615,10 @@ TEMPLATE static u32 RLUnCompVram() writeValue = 0; while(len > 0) { - u8 d = _MMU_read08(source++); + u8 d = _MMU_read08(cpu->proc_ID, source++); int l = d & 0x7F; if(d & 0x80) { - u8 data = _MMU_read08(source++); + u8 data = _MMU_read08(cpu->proc_ID, source++); l += 3; for(i = 0;i < l; i++) { writeValue |= (data << byteShift); @@ -626,7 +626,7 @@ TEMPLATE static u32 RLUnCompVram() byteCount++; if(byteCount == 2) { - _MMU_write16(dest, writeValue); + _MMU_write16(cpu->proc_ID, dest, writeValue); dest += 2; byteCount = 0; byteShift = 0; @@ -639,11 +639,11 @@ TEMPLATE static u32 RLUnCompVram() } else { l++; for(i = 0; i < l; i++) { - writeValue |= (_MMU_read08(source++) << byteShift); + writeValue |= (_MMU_read08(cpu->proc_ID, source++) << byteShift); byteShift += 8; byteCount++; if(byteCount == 2) { - _MMU_write16(dest, writeValue); + _MMU_write16(cpu->proc_ID, dest, writeValue); dest += 2; byteCount = 0; byteShift = 0; @@ -665,7 +665,7 @@ TEMPLATE static u32 RLUnCompWram() u32 source = cpu->R[0]; u32 dest = cpu->R[1]; - u32 header = _MMU_read32(source); + u32 header = _MMU_read32(cpu->proc_ID, source); source += 4; //INFO("swi rluncompwram\n"); @@ -677,13 +677,13 @@ TEMPLATE static u32 RLUnCompWram() len = header >> 8; while(len > 0) { - u8 d = _MMU_read08(source++); + u8 d = _MMU_read08(cpu->proc_ID, source++); int l = d & 0x7F; if(d & 0x80) { - u8 data = _MMU_read08(source++); + u8 data = _MMU_read08(cpu->proc_ID, source++); l += 3; for(i = 0;i < l; i++) { - _MMU_write08(dest++, data); + _MMU_write08(cpu->proc_ID,dest++, data); len--; if(len == 0) return 0; @@ -691,7 +691,7 @@ TEMPLATE static u32 RLUnCompWram() } else { l++; for(i = 0; i < l; i++) { - _MMU_write08(dest++, _MMU_read08(source++)); + _MMU_write08(cpu->proc_ID, dest++, _MMU_read08(cpu->proc_ID,source++)); len--; if(len == 0) return 0; @@ -712,7 +712,7 @@ TEMPLATE static u32 UnCompHuffman() source = cpu->R[0]; dest = cpu->R[1]; - header = _MMU_read08(source); + header = _MMU_read08(cpu->proc_ID, source); source += 4; //INFO("swi uncomphuffman\n"); @@ -721,7 +721,7 @@ TEMPLATE static u32 UnCompHuffman() ((source + ((header >> 8) & 0x1fffff)) & 0xe000000) == 0) return 0; - treeSize = _MMU_read08(source++); + treeSize = _MMU_read08(cpu->proc_ID,source++); treeStart = source; @@ -730,11 +730,11 @@ TEMPLATE static u32 UnCompHuffman() len = header >> 8; mask = 0x80000000; - data = _MMU_read08(source); + data = _MMU_read08(cpu->proc_ID,source); source += 4; pos = 0; - rootNode = _MMU_read08(treeStart); + rootNode = _MMU_read08(cpu->proc_ID,treeStart); currentNode = rootNode; writeData = 0; byteShift = 0; @@ -753,12 +753,12 @@ TEMPLATE static u32 UnCompHuffman() // right if(currentNode & 0x40) writeData = 1; - currentNode = _MMU_read08(treeStart+pos+1); + currentNode = _MMU_read08(cpu->proc_ID,treeStart+pos+1); } else { // left if(currentNode & 0x80) writeData = 1; - currentNode = _MMU_read08(treeStart+pos); + currentNode = _MMU_read08(cpu->proc_ID,treeStart+pos); } if(writeData) { @@ -773,7 +773,7 @@ TEMPLATE static u32 UnCompHuffman() if(byteCount == 4) { byteCount = 0; byteShift = 0; - _MMU_write08(dest, writeValue); + _MMU_write08(cpu->proc_ID, dest, writeValue); writeValue = 0; dest += 4; len -= 4; @@ -782,7 +782,7 @@ TEMPLATE static u32 UnCompHuffman() mask >>= 1; if(mask == 0) { mask = 0x80000000; - data = _MMU_read08(source); + data = _MMU_read08(cpu->proc_ID,source); source += 4; } } @@ -800,12 +800,12 @@ TEMPLATE static u32 UnCompHuffman() // right if(currentNode & 0x40) writeData = 1; - currentNode = _MMU_read08(treeStart+pos+1); + currentNode = _MMU_read08(cpu->proc_ID, treeStart+pos+1); } else { // left if(currentNode & 0x80) writeData = 1; - currentNode = _MMU_read08(treeStart+pos); + currentNode = _MMU_read08(cpu->proc_ID, treeStart+pos); } if(writeData) { @@ -826,7 +826,7 @@ TEMPLATE static u32 UnCompHuffman() if(byteCount == 4) { byteCount = 0; byteShift = 0; - _MMU_write08(dest, writeValue); + _MMU_write08(cpu->proc_ID,dest, writeValue); dest += 4; writeValue = 0; len -= 4; @@ -839,7 +839,7 @@ TEMPLATE static u32 UnCompHuffman() mask >>= 1; if(mask == 0) { mask = 0x80000000; - data = _MMU_read08(source); + data = _MMU_read08(cpu->proc_ID, source); source += 4; } } @@ -859,15 +859,15 @@ TEMPLATE static u32 BitUnPack() //INFO("swi bitunpack\n"); - len = _MMU_read16(header); + len = _MMU_read16(cpu->proc_ID, header); // check address - bits = _MMU_read08(header+2); + bits = _MMU_read08(cpu->proc_ID, header+2); revbits = 8 - bits; // u32 value = 0; - base = _MMU_read08(header+4); + base = _MMU_read08(cpu->proc_ID, header+4); addBase = (base & 0x80000000) ? 1 : 0; base &= 0x7fffffff; - dataSize = _MMU_read08(header+3); + dataSize = _MMU_read08(cpu->proc_ID, header+3); data = 0; bitwritecount = 0; @@ -876,7 +876,7 @@ TEMPLATE static u32 BitUnPack() if(len < 0) break; mask = 0xff >> revbits; - b = _MMU_read08(source); + b = _MMU_read08(cpu->proc_ID, source); source++; bitcount = 0; while(1) { @@ -890,7 +890,7 @@ TEMPLATE static u32 BitUnPack() data |= temp << bitwritecount; bitwritecount += dataSize; if(bitwritecount >= 32) { - _MMU_write08(dest, data); + _MMU_write08(cpu->proc_ID,dest, data); dest += 4; data = 0; bitwritecount = 0; @@ -911,7 +911,7 @@ TEMPLATE static u32 Diff8bitUnFilterWram() source = cpu->R[0]; dest = cpu->R[1]; - header = _MMU_read08(source); + header = _MMU_read08(cpu->proc_ID, source); source += 4; //INFO("swi diff8bitunfilterwram\n"); @@ -922,14 +922,14 @@ TEMPLATE static u32 Diff8bitUnFilterWram() len = header >> 8; - data = _MMU_read08(source++); - _MMU_write08(dest++, data); + data = _MMU_read08(cpu->proc_ID, source++); + _MMU_write08(cpu->proc_ID, dest++, data); len--; while(len > 0) { - diff = _MMU_read08(source++); + diff = _MMU_read08(cpu->proc_ID,source++); data += diff; - _MMU_write08(dest++, data); + _MMU_write08(cpu->proc_ID, dest++, data); len--; } return 1; @@ -946,7 +946,7 @@ TEMPLATE static u32 Diff16bitUnFilter() //INFO("swi diff16bitunfilter\n"); - header = _MMU_read08(source); + header = _MMU_read08(cpu->proc_ID, source); source += 4; if(((source & 0xe000000) == 0) || @@ -955,17 +955,17 @@ TEMPLATE static u32 Diff16bitUnFilter() len = header >> 8; - data = _MMU_read16(source); + data = _MMU_read16(cpu->proc_ID,source); source += 2; - _MMU_write16(dest, data); + _MMU_write16(cpu->proc_ID, dest, data); dest += 2; len -= 2; while(len >= 2) { - u16 diff = _MMU_read16(source); + u16 diff = _MMU_read16(cpu->proc_ID, source); source += 2; data += diff; - _MMU_write16(dest, data); + _MMU_write16(cpu->proc_ID,dest, data); dest += 2; len -= 2; } @@ -980,7 +980,7 @@ TEMPLATE static u32 bios_sqrt() TEMPLATE static u32 setHaltCR() { - _MMU_write08(0x4000300+cpu->proc_ID, cpu->R[0]); + _MMU_write08(cpu->proc_ID,0x4000300+cpu->proc_ID, cpu->R[0]); return 1; } @@ -1013,7 +1013,7 @@ TEMPLATE static u32 getCRC16() const u16 val[] = { 0xC0C1,0xC181,0xC301,0xC601,0xCC01,0xD801,0xF001,0xA001 }; for(i = 0; i < size; i++) { - crc = crc ^ _MMU_read08(datap + i); + crc = crc ^ _MMU_read08(cpu->proc_ID, datap + i); for(j = 0; j < 8; j++) { int do_bit = 0; diff --git a/desmume/src/bios.h b/src/bios.h similarity index 100% rename from desmume/src/bios.h rename to src/bios.h diff --git a/desmume/src/bits.h b/src/bits.h similarity index 100% rename from desmume/src/bits.h rename to src/bits.h diff --git a/desmume/src/build.bat b/src/build.bat similarity index 100% rename from desmume/src/build.bat rename to src/build.bat diff --git a/desmume/src/cflash.cpp b/src/cflash.cpp similarity index 100% rename from desmume/src/cflash.cpp rename to src/cflash.cpp diff --git a/desmume/src/cflash.h b/src/cflash.h similarity index 100% rename from desmume/src/cflash.h rename to src/cflash.h diff --git a/desmume/src/cheatSystem.cpp b/src/cheatSystem.cpp similarity index 57% rename from desmume/src/cheatSystem.cpp rename to src/cheatSystem.cpp index 2b2606b6f..228be8765 100644 --- a/desmume/src/cheatSystem.cpp +++ b/src/cheatSystem.cpp @@ -83,428 +83,14 @@ BOOL cheatsUpdate(u8 size, u32 address, u32 val, char *description, BOOL enabled return TRUE; } -static void cheats_ARparser(CHEATS_LIST cheat) -{ - u8 type = 0; - u8 subtype = 0; - u32 hi = 0; - u32 lo = 0; - u32 addr = 0; - u32 val = 0; - // AR temporary vars & flags - u32 offset = 0; - u32 datareg = 0; - u32 loopcount = 0; - u32 counter = 0; - u32 if_flag = 0; - s32 loopbackline = 0; - u32 loop_flag = 0; - - for (int i=0; i < cheat.num; i++) - { - type = cheat.hi[i] >> 28; - subtype = (cheat.hi[i] >> 24) & 0x0F; - - hi = cheat.hi[i] & 0x0FFFFFFF; - lo = cheat.lo[i]; - - if (if_flag > 0) - { - if ( (type == 0x0D) && (subtype == 0)) if_flag--; // ENDIF - if ( (type == 0x0D) && (subtype == 2)) // NEXT & Flush - { - if (loop_flag) - i = (loopbackline-1); - else - { - offset = 0; - datareg = 0; - loopcount = 0; - counter = 0; - if_flag = 0; - loop_flag = 0; - } - } - continue; - } - - switch (type) - { - case 0x00: - { - if (hi==0) - { - //manual hook - } - else - if ((hi==0x0000AA99) && (lo==0)) - { - //parameter bytes 9..10 for above code (padded with 00s) - } - else - { - addr = hi + offset; - T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20], lo); - } - } - break; - - case 0x01: - addr = hi + offset; - T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20], lo & 0x0000FFFF); - break; - - case 0x02: - addr = hi + offset; - T1WriteByte(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20], lo & 0x000000FF); - break; - - case 0x03: - val = T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][hi>>20], hi & MMU.MMU_MASK[ARMCPU_ARM9][hi>>20]); - if ( lo > val ) - { - if (if_flag > 0) if_flag--; - } - else - { - if_flag++; - } - break; - - case 0x04: - val = T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][hi>>20], hi & MMU.MMU_MASK[ARMCPU_ARM9][hi>>20]); - if ( lo < val ) - { - if (if_flag > 0) if_flag--; - } - else - { - if_flag++; - } - break; - - case 0x05: - val = T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][hi>>20], hi & MMU.MMU_MASK[ARMCPU_ARM9][hi>>20]); - if ( lo == val ) - { - if (if_flag > 0) if_flag--; - } - else - { - if_flag++; - } - break; - - case 0x06: - val = T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][hi>>20], hi & MMU.MMU_MASK[ARMCPU_ARM9][hi>>20]); - if ( lo != val ) - { - if (if_flag > 0) if_flag--; - } - else - { - if_flag++; - } - break; - - case 0x07: - val = T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM9][hi>>20], hi & MMU.MMU_MASK[ARMCPU_ARM9][hi>>20]) & 0x0000FFFF; - if ( (lo & 0xFFFF) > ( (~(lo >> 16)) & val) ) - { - if (if_flag > 0) if_flag--; - } - else - { - if_flag++; - } - break; - - case 0x08: - val = T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM9][hi>>20], hi & MMU.MMU_MASK[ARMCPU_ARM9][hi>>20]) & 0x0000FFFF; - if ( (lo & 0xFFFF) < ( (~(lo >> 16)) & val) ) - { - if (if_flag > 0) if_flag--; - } - else - { - if_flag++; - } - break; - - case 0x09: - val = T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM9][hi>>20], hi & MMU.MMU_MASK[ARMCPU_ARM9][hi>>20]); - if ( (lo & 0xFFFF) == ( (~(lo >> 16)) & val) ) - { - if (if_flag > 0) if_flag--; - } - else - { - if_flag++; - } - break; - - case 0x0A: - val = T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM9][hi>>20], hi & MMU.MMU_MASK[ARMCPU_ARM9][hi>>20]) & 0x0000FFFF; - if ( (lo & 0xFFFF) != ( (~(lo >> 16)) & val) ) - { - if (if_flag > 0) if_flag--; - } - else - { - if_flag++; - } - break; - - case 0x0B: - addr = hi + offset; - offset = T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20]); - break; - - case 0x0C: - switch (subtype) - { - case 0x0: - if (loopcount < (lo+1)) - loop_flag = 1; - else - loop_flag = 0; - loopcount++; - loopbackline = i; - break; - - case 0x4: - break; - - case 0x5: - counter++; - if ( (counter & (lo & 0xFFFF)) == ((lo >> 8) & 0xFFFF) ) - { - if (if_flag > 0) if_flag--; - } - else - { - if_flag++; - } - break; - - case 0x6: - T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][lo>>20], lo & MMU.MMU_MASK[ARMCPU_ARM9][lo>>20], offset); - break; - } - break; - - case 0x0D: - { - switch (subtype) - { - case 0x0: - break; - - case 0x1: - if (loop_flag) - i = (loopbackline-1); - break; - - case 0x2: - if (loop_flag) - i = (loopbackline-1); - else - { - offset = 0; - datareg = 0; - loopcount = 0; - counter = 0; - if_flag = 0; - loop_flag = 0; - } - break; - - case 0x3: - offset = lo; - break; - - case 0x4: - datareg += lo; - break; - - case 0x5: - datareg = lo; - break; - - case 0x6: - addr = lo + offset; - T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20], datareg); - offset += 4; - break; - - case 0x7: - addr = lo + offset; - T1WriteWord(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20], datareg & 0x0000FFFF); - offset += 2; - break; - - case 0x8: - addr = lo + offset; - T1WriteByte(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20], datareg & 0x000000FF); - offset += 1; - break; - - case 0x9: - addr = lo + offset; - datareg = T1ReadLong(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20]); - break; - - case 0xA: - addr = lo + offset; - datareg = T1ReadWord(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20]) & 0x0000FFFF; - break; - - case 0xB: - addr = lo + offset; - datareg = T1ReadByte(MMU.MMU_MEM[ARMCPU_ARM9][addr>>20], addr & MMU.MMU_MASK[ARMCPU_ARM9][addr>>20]) & 0x000000FF; - break; - - case 0xC: - offset += lo; - break; - } - } - break; - - case 0xE: - for (u32 t = 0; t < lo; t++) - { - u8 tmp = T1ReadByte(MMU.MMU_MEM[ARMCPU_ARM9][(hi+t)>>20], (hi+t) & MMU.MMU_MASK[ARMCPU_ARM9][(hi+t)>>20]); - T1WriteByte(MMU.MMU_MEM[ARMCPU_ARM9][(offset+t)>>20], (offset+t) & MMU.MMU_MASK[ARMCPU_ARM9][(offset+t)>>20], tmp); - } - break; - - case 0xF: - for (u32 t = 0; t < lo; t++) - { - u8 tmp = T1ReadByte(MMU.MMU_MEM[ARMCPU_ARM9][(offset+t)>>20], (offset+t) & MMU.MMU_MASK[ARMCPU_ARM9][(offset+t)>>20]); - T1WriteByte(MMU.MMU_MEM[ARMCPU_ARM9][(hi+t)>>20], (hi+t) & MMU.MMU_MASK[ARMCPU_ARM9][(hi+t)>>20], tmp); - } - break; - //default: INFO("AR: ERROR uknown command 0x%2X at %08X:%08X\n", type, hi, lo); break; - } - } -} - -static BOOL cheatsXXcodePreparser(CHEATS_LIST *cheat, char *code) -{ - u16 count = 0; - u16 t = 0; - char tmp_buf[sizeof(cheat->hi)+sizeof(cheat->lo)]; - - memset(tmp_buf, 0, sizeof(tmp_buf)); - // remove wrong chars - for (unsigned int i=0; i < strlen(code); i++) - { - switch (code[i]) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - case 'A': - case 'a': - case 'B': - case 'b': - case 'C': - case 'c': - case 'D': - case 'd': - case 'E': - case 'e': - case 'F': - case 'f': - tmp_buf[t] = code[i]; - t++; - break; - } - } - - if ((strlen(tmp_buf) % 8) != 0) return FALSE; // error - if ((strlen(tmp_buf) % 16) != 0) return FALSE; // error - - // TODO: syntax check - count = (strlen(tmp_buf) / 16); - for (int i=0; i < count; i++) - { - char buf[8] = {0}; - strncpy(buf, tmp_buf+(i*16), 8); - sscanf_s(buf, "%x", &cheat->hi[i]); - strncpy(buf, tmp_buf+(i*16) + 8, 8); - sscanf_s(buf, "%x", &cheat->lo[i]); - } - - cheat->num = count; - cheat->size = 0; - return TRUE; -} - BOOL cheatsAdd_AR(char *code, char *description, BOOL enabled) { - if (cheatsNum == MAX_CHEAT_LIST) return FALSE; - - if (!cheatsXXcodePreparser(&cheats[cheatsNum], code)) return FALSE; - - cheats[cheatsNum].type = 1; - - strcpy(cheats[cheatsNum].description, description); - cheats[cheatsNum].enabled = enabled; - cheatsNum++; - return TRUE; -} - -BOOL cheatsUpdate_AR(char *code, char *description, BOOL enabled, u32 pos) -{ - if (pos > cheatsNum) return FALSE; - - if (code != NULL) - { - if (!cheatsXXcodePreparser(&cheats[pos], code)) return FALSE; - strcpy(cheats[pos].description, description); - cheats[pos].type = 1; - } - - cheats[pos].enabled = enabled; - return TRUE; + return FALSE; } BOOL cheatsAdd_CB(char *code, char *description, BOOL enabled) { - if (cheatsNum == MAX_CHEAT_LIST) return FALSE; - - if (!cheatsXXcodePreparser(&cheats[cheatsNum], code)) return FALSE; - - cheats[cheatsNum].type = 2; - - strcpy(cheats[cheatsNum].description, description); - cheats[cheatsNum].enabled = enabled; - cheatsNum++; - return TRUE; -} - -BOOL cheatsUpdate_CB(char *code, char *description, BOOL enabled, u32 pos) -{ - if (pos > cheatsNum) return FALSE; - - if (code != NULL) - { - if (!cheatsXXcodePreparser(&cheats[pos], code)) return FALSE; - cheats[pos].type = 2; - strcpy(cheats[pos].description, description); - } - cheats[pos].enabled = enabled; - return TRUE; + return FALSE; } BOOL cheatsRemove(u32 pos) @@ -571,10 +157,9 @@ BOOL cheatsSave() if (cheats[i].num > 0) { - fprintf(fcheat, "Data="); for (int t = 0; t < cheats[i].num; t++) { - fprintf(fcheat, "%08X%08X", cheats[i].hi[t], cheats[i].lo[t]); + fprintf(fcheat, "Data=%08X%08X", cheats[i].hi[t], cheats[i].lo[t]); if (t < (cheats[i].num - 1)) fputs(",", fcheat); } fputs("\n", fcheat); @@ -619,28 +204,14 @@ BOOL cheatsLoad() (buf[3] == 'o') && (buf[4] == '=') ) // Info cheat { - u32 dstart = 5; - u32 dsize = 0; - char bf[4] = { 0 }; - - while ( (buf[dstart+dsize] != ',') && (buf[dstart+dsize]!=0)) { dsize++; }; - if (buf[dstart+dsize]==0) continue; // error - strncpy(bf, (char*)buf+dstart, dsize); - cheats[last].type=atoi(bf); - dstart += (dsize+1); dsize=0; - while ( (buf[dstart+dsize] != ',') && (buf[dstart+dsize]!=0)) { dsize++; }; - if (buf[dstart+dsize]==0) continue; // error - strncpy(bf, (char*)buf+dstart, dsize); - dstart += (dsize+1); dsize=0; - cheats[last].num=atoi(bf); - while ( (buf[dstart+dsize] != ',') && (buf[dstart+dsize]!=0)) { dsize++; }; - if (buf[dstart+dsize]==0) continue; // error - strncpy(bf, (char*)(buf+dstart), dsize); - dstart += (dsize+1); dsize=0; - cheats[last].enabled=atoi(bf); - while ( (buf[dstart+dsize] != ',') && (buf[dstart+dsize]!=0)) { dsize++; }; - strncpy(bf, (char*)buf+dstart, dsize); - cheats[last].size=atoi(bf); + // TODO: parse number for comma + cheats[last].type=atoi(&buf[5]); + if (buf[6]!=',') continue; // error + cheats[last].num=atoi(&buf[7]); + if (buf[8]!=',') continue; // error + cheats[last].enabled=atoi(&buf[9]); + if (buf[10]!=',') continue; // error + cheats[last].size=atoi(&buf[11]); fgets(buf, 1024, fcheat); if ( (buf[0] == 'D') && (buf[1] == 'a') && @@ -659,8 +230,6 @@ BOOL cheatsLoad() offs+=8; strncpy(tmp_buf, (char *)buf+offs, 8); sscanf_s(tmp_buf, "%x", &cheats[last].lo[j]); - offs+=8; - if (buf[offs] != ',') continue; //error offs++; // skip comma } } @@ -736,7 +305,6 @@ void cheatsProcess() break; case 1: // Action Replay - cheats_ARparser(cheats[i]); break; case 2: // Codebreaker break; @@ -745,17 +313,6 @@ void cheatsProcess() } } -void cheatGetXXcodeString(CHEATS_LIST cheat, char *res_buf) -{ - char buf[50] = { 0 }; - - for (int i=0; i < cheat.num; i++) - { - sprintf(buf, "%08X %08X\n", cheat.hi[i], cheat.lo[i]); - strcat(res_buf, buf); - } -} - // ========================================== search u8 *searchStatMem = NULL; u8 *searchMem = NULL; @@ -1009,23 +566,14 @@ u32 cheatSearchNumber() BOOL cheatSearchGetList(u32 *address, u32 *curVal) { - u8 step = (searchSize+1); - u8 stepMem = 1; - switch (searchSize) - { - case 1: stepMem = 0x3; break; - case 2: stepMem = 0x7; break; - case 3: stepMem = 0xF; break; - } - - for (u32 i = searchLastRecord; i < (4 * 1024 * 1024); i+=step) + for (u32 i = searchLastRecord; i < (4 * 1024 * 1024); i++) { u32 addr = (i >> 3); u32 offs = (i % 8); - if (searchStatMem[addr] & (stepMem<CFBundlePackageType APPL CFBundleShortVersionString - 0.9.3 + 0.8 CFBundleSignature ???? CFBundleVersion - 0.9.3 + 0.8 NSMainNibFile MainMenu NSPrincipalClass diff --git a/desmume/src/cocoa/InfoPlist.strings b/src/cocoa/InfoPlist.strings similarity index 100% rename from desmume/src/cocoa/InfoPlist.strings rename to src/cocoa/InfoPlist.strings diff --git a/desmume/src/cocoa/Makefile.am b/src/cocoa/Makefile.am similarity index 100% rename from desmume/src/cocoa/Makefile.am rename to src/cocoa/Makefile.am diff --git a/desmume/src/cocoa/PkgInfo b/src/cocoa/PkgInfo similarity index 100% rename from desmume/src/cocoa/PkgInfo rename to src/cocoa/PkgInfo diff --git a/desmume/src/cocoa/Rakefile b/src/cocoa/Rakefile similarity index 100% rename from desmume/src/cocoa/Rakefile rename to src/cocoa/Rakefile diff --git a/desmume/src/cocoa/about.m b/src/cocoa/about.m similarity index 100% rename from desmume/src/cocoa/about.m rename to src/cocoa/about.m diff --git a/desmume/src/cocoa/cocoa_util.m b/src/cocoa/cocoa_util.m similarity index 100% rename from desmume/src/cocoa/cocoa_util.m rename to src/cocoa/cocoa_util.m diff --git a/desmume/src/cocoa/dialogs/rom_info.h b/src/cocoa/dialogs/rom_info.h similarity index 100% rename from desmume/src/cocoa/dialogs/rom_info.h rename to src/cocoa/dialogs/rom_info.h diff --git a/desmume/src/cocoa/dialogs/rom_info.m b/src/cocoa/dialogs/rom_info.m similarity index 100% rename from desmume/src/cocoa/dialogs/rom_info.m rename to src/cocoa/dialogs/rom_info.m diff --git a/desmume/src/cocoa/dialogs/speed_limit_selection_window.h b/src/cocoa/dialogs/speed_limit_selection_window.h similarity index 100% rename from desmume/src/cocoa/dialogs/speed_limit_selection_window.h rename to src/cocoa/dialogs/speed_limit_selection_window.h diff --git a/desmume/src/cocoa/dialogs/speed_limit_selection_window.mm b/src/cocoa/dialogs/speed_limit_selection_window.mm similarity index 100% rename from desmume/src/cocoa/dialogs/speed_limit_selection_window.mm rename to src/cocoa/dialogs/speed_limit_selection_window.mm diff --git a/desmume/src/cocoa/globals.h b/src/cocoa/globals.h similarity index 100% rename from desmume/src/cocoa/globals.h rename to src/cocoa/globals.h diff --git a/desmume/src/cocoa/input.h b/src/cocoa/input.h similarity index 100% rename from desmume/src/cocoa/input.h rename to src/cocoa/input.h diff --git a/desmume/src/cocoa/input.mm b/src/cocoa/input.mm similarity index 100% rename from desmume/src/cocoa/input.mm rename to src/cocoa/input.mm diff --git a/desmume/src/cocoa/main.mm b/src/cocoa/main.mm similarity index 100% rename from desmume/src/cocoa/main.mm rename to src/cocoa/main.mm diff --git a/desmume/src/cocoa/main_window.h b/src/cocoa/main_window.h similarity index 100% rename from desmume/src/cocoa/main_window.h rename to src/cocoa/main_window.h diff --git a/desmume/src/cocoa/main_window.mm b/src/cocoa/main_window.mm similarity index 100% rename from desmume/src/cocoa/main_window.mm rename to src/cocoa/main_window.mm diff --git a/desmume/src/cocoa/makeapp.sh b/src/cocoa/makeapp.sh similarity index 100% rename from desmume/src/cocoa/makeapp.sh rename to src/cocoa/makeapp.sh diff --git a/desmume/src/cocoa/nds_control.h b/src/cocoa/nds_control.h similarity index 100% rename from desmume/src/cocoa/nds_control.h rename to src/cocoa/nds_control.h diff --git a/desmume/src/cocoa/nds_control.mm b/src/cocoa/nds_control.mm similarity index 100% rename from desmume/src/cocoa/nds_control.mm rename to src/cocoa/nds_control.mm diff --git a/desmume/src/cocoa/preferences.h b/src/cocoa/preferences.h similarity index 100% rename from desmume/src/cocoa/preferences.h rename to src/cocoa/preferences.h diff --git a/desmume/src/cocoa/preferences.mm b/src/cocoa/preferences.mm similarity index 100% rename from desmume/src/cocoa/preferences.mm rename to src/cocoa/preferences.mm diff --git a/desmume/src/cocoa/screen_state.h b/src/cocoa/screen_state.h similarity index 100% rename from desmume/src/cocoa/screen_state.h rename to src/cocoa/screen_state.h diff --git a/desmume/src/cocoa/screen_state.m b/src/cocoa/screen_state.m similarity index 100% rename from desmume/src/cocoa/screen_state.m rename to src/cocoa/screen_state.m diff --git a/desmume/src/cocoa/screenshot.h b/src/cocoa/screenshot.h similarity index 100% rename from desmume/src/cocoa/screenshot.h rename to src/cocoa/screenshot.h diff --git a/desmume/src/cocoa/screenshot.mm b/src/cocoa/screenshot.mm similarity index 100% rename from desmume/src/cocoa/screenshot.mm rename to src/cocoa/screenshot.mm diff --git a/desmume/src/cocoa/sndOSX.h b/src/cocoa/sndOSX.h similarity index 100% rename from desmume/src/cocoa/sndOSX.h rename to src/cocoa/sndOSX.h diff --git a/desmume/src/cocoa/sndOSX.mm b/src/cocoa/sndOSX.mm similarity index 100% rename from desmume/src/cocoa/sndOSX.mm rename to src/cocoa/sndOSX.mm diff --git a/desmume/src/cocoa/translations/English.lproj/Localizable.strings b/src/cocoa/translations/English.lproj/Localizable.strings similarity index 100% rename from desmume/src/cocoa/translations/English.lproj/Localizable.strings rename to src/cocoa/translations/English.lproj/Localizable.strings diff --git a/desmume/src/cocoa/translations/English.lproj/MainMenu.nib/classes.nib b/src/cocoa/translations/English.lproj/MainMenu.nib/classes.nib similarity index 100% rename from desmume/src/cocoa/translations/English.lproj/MainMenu.nib/classes.nib rename to src/cocoa/translations/English.lproj/MainMenu.nib/classes.nib diff --git a/desmume/src/cocoa/translations/English.lproj/MainMenu.nib/info.nib b/src/cocoa/translations/English.lproj/MainMenu.nib/info.nib similarity index 100% rename from desmume/src/cocoa/translations/English.lproj/MainMenu.nib/info.nib rename to src/cocoa/translations/English.lproj/MainMenu.nib/info.nib diff --git a/desmume/src/cocoa/translations/English.lproj/MainMenu.nib/keyedobjects.nib b/src/cocoa/translations/English.lproj/MainMenu.nib/keyedobjects.nib similarity index 100% rename from desmume/src/cocoa/translations/English.lproj/MainMenu.nib/keyedobjects.nib rename to src/cocoa/translations/English.lproj/MainMenu.nib/keyedobjects.nib diff --git a/desmume/src/cocoa/translations/French.lproj/Localizable.strings b/src/cocoa/translations/French.lproj/Localizable.strings similarity index 100% rename from desmume/src/cocoa/translations/French.lproj/Localizable.strings rename to src/cocoa/translations/French.lproj/Localizable.strings diff --git a/desmume/src/cocoa/translations/French.lproj/MainMenu.nib/classes.nib b/src/cocoa/translations/French.lproj/MainMenu.nib/classes.nib similarity index 100% rename from desmume/src/cocoa/translations/French.lproj/MainMenu.nib/classes.nib rename to src/cocoa/translations/French.lproj/MainMenu.nib/classes.nib diff --git a/desmume/src/cocoa/translations/French.lproj/MainMenu.nib/info.nib b/src/cocoa/translations/French.lproj/MainMenu.nib/info.nib similarity index 100% rename from desmume/src/cocoa/translations/French.lproj/MainMenu.nib/info.nib rename to src/cocoa/translations/French.lproj/MainMenu.nib/info.nib diff --git a/desmume/src/cocoa/translations/French.lproj/MainMenu.nib/keyedobjects.nib b/src/cocoa/translations/French.lproj/MainMenu.nib/keyedobjects.nib similarity index 100% rename from desmume/src/cocoa/translations/French.lproj/MainMenu.nib/keyedobjects.nib rename to src/cocoa/translations/French.lproj/MainMenu.nib/keyedobjects.nib diff --git a/desmume/src/cocoa/translations/Italian.lproj/Localizable.strings b/src/cocoa/translations/Italian.lproj/Localizable.strings similarity index 100% rename from desmume/src/cocoa/translations/Italian.lproj/Localizable.strings rename to src/cocoa/translations/Italian.lproj/Localizable.strings diff --git a/desmume/src/cocoa/translations/Italian.lproj/MainMenu.nib/classes.nib b/src/cocoa/translations/Italian.lproj/MainMenu.nib/classes.nib similarity index 100% rename from desmume/src/cocoa/translations/Italian.lproj/MainMenu.nib/classes.nib rename to src/cocoa/translations/Italian.lproj/MainMenu.nib/classes.nib diff --git a/desmume/src/cocoa/translations/Italian.lproj/MainMenu.nib/info.nib b/src/cocoa/translations/Italian.lproj/MainMenu.nib/info.nib similarity index 100% rename from desmume/src/cocoa/translations/Italian.lproj/MainMenu.nib/info.nib rename to src/cocoa/translations/Italian.lproj/MainMenu.nib/info.nib diff --git a/desmume/src/cocoa/translations/Italian.lproj/MainMenu.nib/keyedobjects.nib b/src/cocoa/translations/Italian.lproj/MainMenu.nib/keyedobjects.nib similarity index 100% rename from desmume/src/cocoa/translations/Italian.lproj/MainMenu.nib/keyedobjects.nib rename to src/cocoa/translations/Italian.lproj/MainMenu.nib/keyedobjects.nib diff --git a/desmume/src/cocoa/translations/Japanese.lproj/Localizable.strings b/src/cocoa/translations/Japanese.lproj/Localizable.strings similarity index 100% rename from desmume/src/cocoa/translations/Japanese.lproj/Localizable.strings rename to src/cocoa/translations/Japanese.lproj/Localizable.strings diff --git a/desmume/src/cocoa/translations/Japanese.lproj/MainMenu.nib/classes.nib b/src/cocoa/translations/Japanese.lproj/MainMenu.nib/classes.nib similarity index 100% rename from desmume/src/cocoa/translations/Japanese.lproj/MainMenu.nib/classes.nib rename to src/cocoa/translations/Japanese.lproj/MainMenu.nib/classes.nib diff --git a/desmume/src/cocoa/translations/Japanese.lproj/MainMenu.nib/info.nib b/src/cocoa/translations/Japanese.lproj/MainMenu.nib/info.nib similarity index 100% rename from desmume/src/cocoa/translations/Japanese.lproj/MainMenu.nib/info.nib rename to src/cocoa/translations/Japanese.lproj/MainMenu.nib/info.nib diff --git a/desmume/src/cocoa/translations/Japanese.lproj/MainMenu.nib/keyedobjects.nib b/src/cocoa/translations/Japanese.lproj/MainMenu.nib/keyedobjects.nib similarity index 100% rename from desmume/src/cocoa/translations/Japanese.lproj/MainMenu.nib/keyedobjects.nib rename to src/cocoa/translations/Japanese.lproj/MainMenu.nib/keyedobjects.nib diff --git a/desmume/src/cocoa/video_output_view.h b/src/cocoa/video_output_view.h similarity index 100% rename from desmume/src/cocoa/video_output_view.h rename to src/cocoa/video_output_view.h diff --git a/desmume/src/cocoa/video_output_view.mm b/src/cocoa/video_output_view.mm similarity index 100% rename from desmume/src/cocoa/video_output_view.mm rename to src/cocoa/video_output_view.mm diff --git a/desmume/src/common.cpp b/src/common.cpp similarity index 100% rename from desmume/src/common.cpp rename to src/common.cpp diff --git a/desmume/src/common.h b/src/common.h similarity index 100% rename from desmume/src/common.h rename to src/common.h diff --git a/desmume/src/cp15.cpp b/src/cp15.cpp similarity index 100% rename from desmume/src/cp15.cpp rename to src/cp15.cpp diff --git a/desmume/src/cp15.h b/src/cp15.h similarity index 100% rename from desmume/src/cp15.h rename to src/cp15.h diff --git a/desmume/src/ctrlssdl.cpp b/src/ctrlssdl.cpp similarity index 100% rename from desmume/src/ctrlssdl.cpp rename to src/ctrlssdl.cpp diff --git a/desmume/src/ctrlssdl.h b/src/ctrlssdl.h similarity index 100% rename from desmume/src/ctrlssdl.h rename to src/ctrlssdl.h diff --git a/desmume/src/debug.cpp b/src/debug.cpp similarity index 96% rename from desmume/src/debug.cpp rename to src/debug.cpp index 93f3625a6..2d0683ee3 100644 --- a/desmume/src/debug.cpp +++ b/src/debug.cpp @@ -34,11 +34,6 @@ Logger::Logger() { flags = 0; } -Logger::~Logger() { - for(int i=0;i<(int)channels.size();i++) - delete channels[i]; -} - void Logger::vprintf(const char * format, va_list l, const char * file, unsigned int line) { char buffer[1024]; char * cur = buffer; diff --git a/desmume/src/debug.h b/src/debug.h similarity index 99% rename from desmume/src/debug.h rename to src/debug.h index daba337ce..d0c0e6897 100644 --- a/desmume/src/debug.h +++ b/src/debug.h @@ -35,7 +35,6 @@ protected: static void fixSize(unsigned int channel); public: Logger(); - ~Logger(); void vprintf(const char * format, va_list l, const char * filename, unsigned int line); void setOutput(std::ostream * o); diff --git a/desmume/src/desmume.mk b/src/desmume.mk similarity index 100% rename from desmume/src/desmume.mk rename to src/desmume.mk diff --git a/desmume/src/dscard.h b/src/dscard.h similarity index 100% rename from desmume/src/dscard.h rename to src/dscard.h diff --git a/desmume/src/fat.h b/src/fat.h similarity index 100% rename from desmume/src/fat.h rename to src/fat.h diff --git a/desmume/src/fs-linux.cpp b/src/fs-linux.cpp similarity index 100% rename from desmume/src/fs-linux.cpp rename to src/fs-linux.cpp diff --git a/desmume/src/fs-windows.cpp b/src/fs-windows.cpp similarity index 100% rename from desmume/src/fs-windows.cpp rename to src/fs-windows.cpp diff --git a/desmume/src/fs.h b/src/fs.h similarity index 100% rename from desmume/src/fs.h rename to src/fs.h diff --git a/desmume/src/gdbstub.h b/src/gdbstub.h similarity index 100% rename from desmume/src/gdbstub.h rename to src/gdbstub.h diff --git a/desmume/src/gdbstub/Makefile.am b/src/gdbstub/Makefile.am similarity index 100% rename from desmume/src/gdbstub/Makefile.am rename to src/gdbstub/Makefile.am diff --git a/desmume/src/gdbstub/gdbstub.cpp b/src/gdbstub/gdbstub.cpp similarity index 100% rename from desmume/src/gdbstub/gdbstub.cpp rename to src/gdbstub/gdbstub.cpp diff --git a/desmume/src/gdbstub/gdbstub_internal.h b/src/gdbstub/gdbstub_internal.h similarity index 100% rename from desmume/src/gdbstub/gdbstub_internal.h rename to src/gdbstub/gdbstub_internal.h diff --git a/desmume/src/gfx3d.cpp b/src/gfx3d.cpp similarity index 96% rename from desmume/src/gfx3d.cpp rename to src/gfx3d.cpp index e61cffb14..429a3c1f2 100644 --- a/desmume/src/gfx3d.cpp +++ b/src/gfx3d.cpp @@ -41,9 +41,6 @@ #include "readwrite.h" #include "FIFO.h" -using std::max; -using std::min; - GFX3D gfx3d; //tables that are provided to anyone @@ -82,11 +79,6 @@ CACHE_ALIGN const u8 material_3bit_to_8bit[] = { 0x00, 0x24, 0x49, 0x6D, 0x92, 0xB6, 0xDB, 0xFF }; -//maybe not very precise -CACHE_ALIGN const u8 material_3bit_to_5bit[] = { - 0, 4, 8, 13, 17, 22, 26, 31 -}; - CACHE_ALIGN const u8 alpha_5bit_to_4bit[] = { 0x00, 0x00, 0x01, 0x01, @@ -106,13 +98,6 @@ CACHE_ALIGN const u8 alpha_5bit_to_4bit[] = { 0x10, 0x10 }; -CACHE_ALIGN const u16 alpha_lookup[] = { - 0x0000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000, - 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000, - 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000, - 0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000,0x8000}; - - //private acceleration tables static float float16table[65536]; static float float10Table[1024]; @@ -122,9 +107,6 @@ static float normalTable[1024]; #define fix2float(v) (((float)((s32)(v))) / (float)(1<<12)) #define fix10_2float(v) (((float)((s32)(v))) / (float)(1<<9)) -CACHE_ALIGN u16 gfx3d_convertedScreen[256*192]; -CACHE_ALIGN u8 gfx3d_convertedAlpha[256*192]; - // Matrix stack handling static CACHE_ALIGN MatrixStack mtxStack[4] = { MatrixStack(1), // Projection stack @@ -414,8 +396,6 @@ void gfx3d_glStoreMatrix(u32 v) if(mymode==0) v = 0; - if(v==31) v=30; //? what should happen in this case? - MatrixStackLoadMatrix (&mtxStack[mymode], v&31, mtxCurrent[mymode]); if(mymode==2) MatrixStackLoadMatrix (&mtxStack[1], v&31, mtxCurrent[1]); @@ -430,8 +410,6 @@ void gfx3d_glRestoreMatrix(u32 v) if(mymode==0) v = 0; - if(v==31) v=30; //? what should happen in this case? - MatrixCopy (mtxCurrent[mymode], MatrixStackGetPos(&mtxStack[mymode], v&31)); if (mymode == 2) MatrixCopy (mtxCurrent[1], MatrixStackGetPos(&mtxStack[1], v&31)); @@ -1365,32 +1343,43 @@ static void gfx3d_FlushFIFO() void gfx3d_glFlush(u32 v) { + gfx3d.frameCtr++; + + gfx3d_FlushFIFO(); + + //assert(!flushPending); flushPending = TRUE; gfx3d.sortmode = BIT0(v); gfx3d.wbuffer = BIT1(v); + + // reset + clInd = 0; + clCmd = 0; + + //the renderer wil lget the lists we just built + gfx3d.polylist = polylist; + gfx3d.vertlist = vertlist; + + //we need to sort the poly list with alpha polys last + //first, look for opaque polys + int polycount = polylist->count; + int ctr=0; + for(int i=0;ilist[i]; + if(!poly.isTranslucent()) + gfx3d.indexlist[ctr++] = i; + } + //then look for translucent polys + for(int i=0;ilist[i]; + if(poly.isTranslucent()) + gfx3d.indexlist[ctr++] = i; + } + + //switch to the new lists + twiddleLists(); } -static int _CDECL_ gfx3d_ysort_compare(const void * elem1, const void * elem2) -{ - int num1 = *(int*)elem1; - int num2 = *(int*)elem2; - - POLY &poly1 = polylist->list[num1]; - POLY &poly2 = polylist->list[num2]; - - if(poly1.maxy > poly2.maxy) - return 1; - else if(poly1.maxy < poly2.maxy) - return -1; - else if(poly1.miny < poly2.miny) - return 1; - else if(poly1.miny > poly2.miny) - return -1; - else - return 0; -} - - void gfx3d_VBlankSignal() { //the 3d buffers are swapped when a vblank begins. @@ -1401,62 +1390,6 @@ void gfx3d_VBlankSignal() return; } - gfx3d.frameCtr++; - - gfx3d_FlushFIFO(); - - // reset - clInd = 0; - clCmd = 0; - - //the renderer wil lget the lists we just built - gfx3d.polylist = polylist; - gfx3d.vertlist = vertlist; - - int polycount = polylist->count; - - //find the min and max y values for each poly. - //TODO - this could be a small waste of time if we are manual sorting the translucent polys - for(int i=0;ilist[i]; - for(int j=0;jlist[poly.vertIndexes[j]]; - poly.miny = j==0?vert.y:min(poly.miny,vert.y); - poly.maxy = j==0?vert.y:max(poly.maxy,vert.y); - } - } - - //we need to sort the poly list with alpha polys last - //first, look for opaque polys - int ctr=0; - for(int i=0;ilist[i]; - if(!poly.isTranslucent()) - gfx3d.indexlist[ctr++] = i; - } - int opaqueCount = ctr; - //then look for translucent polys - for(int i=0;ilist[i]; - if(poly.isTranslucent()) - gfx3d.indexlist[ctr++] = i; - } - - //now we have to sort the opaque polys by y-value. - //should this be done after clipping?? - //test case: harvest moon island of happiness character cretor UI - qsort(gfx3d.indexlist, opaqueCount, 4, gfx3d_ysort_compare); - - if(!gfx3d.sortmode) - { - //if we are autosorting translucent polys, we need to do this also - //TODO - this is unverified behavior. need a test case - qsort(gfx3d.indexlist + opaqueCount, polycount - opaqueCount, 4, gfx3d_ysort_compare); - } - - //switch to the new lists - twiddleLists(); - flushPending = FALSE; drawPending = TRUE; } @@ -2219,16 +2152,6 @@ void gfx3d_glGetLightColor(unsigned int index, unsigned int* dest) *dest = lightColor[index]; } -void gfx3d_GetLineData(int line, u16** dst, u8** dstAlpha) -{ - gpu3D->NDS_3D_CheckFresh(); - *dst = gfx3d_convertedScreen+((line)<<8); - if(dstAlpha != NULL) - { - *dstAlpha = gfx3d_convertedAlpha+((line)<<8); - } -} - //http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node17.html //talks about the state required to process verts in quadlists etc. helpful ideas. diff --git a/desmume/src/gfx3d.h b/src/gfx3d.h similarity index 84% rename from desmume/src/gfx3d.h rename to src/gfx3d.h index eb65084c6..a83b42560 100644 --- a/desmume/src/gfx3d.h +++ b/src/gfx3d.h @@ -33,9 +33,6 @@ //produce a 32bpp color from a ds RGB15 plus an 8bit alpha, using a table #define RGB15TO32(col,alpha8) ( ((alpha8)<<24) | color_15bit_to_24bit[col&0x7FFF] ) -//produce a 5555 32bit color from a ds RGB15 plus an 5bit alpha -#define RGB15TO5555(col,alpha5) (((alpha5)<<24) | ((((col) & 0x7C00)>>10)<<16) | ((((col) & 0x3E0)>>5)<<8) | (((col) & 0x1F))) - //produce a 24bpp color from a ds RGB15, using a table #define RGB15TO24_REVERSE(col) ( color_15bit_to_24bit_reverse[col&0x7FFF] ) @@ -61,9 +58,6 @@ void gfx3d_init(); void gfx3d_reset(); -#define OSWRITE(x) os->write((char*)&(x),sizeof((x))); -#define OSREAD(x) is->read((char*)&(x),sizeof((x))); - struct POLY { int type; //tri or quad u16 vertIndexes[4]; //up to four verts can be referenced by this poly @@ -71,7 +65,6 @@ struct POLY { // int projIndex; //the index into the projlist that this poly uses u32 pad; u32 viewport; - float miny, maxy; bool isTranslucent() { @@ -184,22 +177,15 @@ extern GFX3D gfx3d; //--------------------- -extern CACHE_ALIGN const u16 alpha_lookup[32]; extern CACHE_ALIGN u32 color_15bit_to_24bit[32768]; extern CACHE_ALIGN u32 color_15bit_to_24bit_reverse[32768]; extern CACHE_ALIGN u16 color_15bit_to_16bit_reverse[32768]; extern CACHE_ALIGN u8 mixTable555[32][32][32]; extern CACHE_ALIGN const int material_5bit_to_31bit[32]; extern CACHE_ALIGN const u8 material_5bit_to_8bit[32]; -extern CACHE_ALIGN const u8 material_3bit_to_5bit[8]; extern CACHE_ALIGN const u8 material_3bit_to_8bit[8]; extern CACHE_ALIGN const u8 alpha_5bit_to_4bit[32]; -//these contain the 3d framebuffer converted into the most useful format -//they are stored here instead of in the renderers in order to consolidate the buffers -extern CACHE_ALIGN u16 gfx3d_convertedScreen[256*192]; -extern CACHE_ALIGN u8 gfx3d_convertedAlpha[256*192]; - //GE commands: void gfx3d_glViewPort(u32 v); void gfx3d_glClearColor(u32 v); @@ -222,11 +208,11 @@ BOOL gfx3d_glMultMatrix4x4(s32 v); void gfx3d_glBegin(u32 v); void gfx3d_glEnd(void); void gfx3d_glColor3b(u32 v); -BOOL gfx3d_glVertex16b(u32 v); +BOOL gfx3d_glVertex16b(unsigned int v); void gfx3d_glVertex10b(u32 v); -void gfx3d_glVertex3_cord(u32 one, u32 two, u32 v); +void gfx3d_glVertex3_cord(unsigned int one, unsigned int two, unsigned int v); void gfx3d_glVertex_rel(u32 v); -void gfx3d_glSwapScreen(u32 screen); +void gfx3d_glSwapScreen(unsigned int screen); int gfx3d_GetNumPolys(); int gfx3d_GetNumVertex(); void gfx3d_glPolygonAttrib (u32 val); @@ -239,16 +225,16 @@ void gfx3d_glTexImage(u32 val); void gfx3d_glTexPalette(u32 val); void gfx3d_glTexCoord(u32 val); void gfx3d_glNormal(u32 v); -s32 gfx3d_GetClipMatrix (u32 index); -s32 gfx3d_GetDirectionalMatrix (u32 index); +s32 gfx3d_GetClipMatrix (unsigned int index); +s32 gfx3d_GetDirectionalMatrix (unsigned int index); void gfx3d_glLightDirection (u32 v); void gfx3d_glLightColor (u32 v); void gfx3d_glAlphaFunc(u32 v); BOOL gfx3d_glBoxTest(u32 v); BOOL gfx3d_glPosTest(u32 v); void gfx3d_glVecTest(u32 v); -u32 gfx3d_glGetPosRes(u32 index); -u16 gfx3d_glGetVecRes(u32 index); +unsigned int gfx3d_glGetPosRes(unsigned int index); +unsigned short gfx3d_glGetVecRes(unsigned int index); void gfx3d_glFlush(u32 v); void gfx3d_VBlankSignal(); void gfx3d_VBlankEndSignal(bool skipFrame); @@ -258,11 +244,9 @@ void gfx3d_sendCommandToFIFO(u32 val); void gfx3d_sendCommand(u32 cmd, u32 param); //other misc stuff -void gfx3d_glGetMatrix(u32 mode, int index, float* dest); -void gfx3d_glGetLightDirection(u32 index, u32* dest); -void gfx3d_glGetLightColor(u32 index, u32* dest); - -void gfx3d_GetLineData(int line, u16** dst, u8** dstAlpha); +void gfx3d_glGetMatrix(unsigned int mode, int index, float* dest); +void gfx3d_glGetLightDirection(unsigned int index, unsigned int* dest); +void gfx3d_glGetLightColor(unsigned int index, unsigned int* dest); struct SFORMAT; extern SFORMAT SF_GFX3D[]; diff --git a/desmume/src/gtk-glade/Makefile.am b/src/gtk-glade/Makefile.am similarity index 100% rename from desmume/src/gtk-glade/Makefile.am rename to src/gtk-glade/Makefile.am diff --git a/desmume/src/gtk-glade/callbacks.cpp b/src/gtk-glade/callbacks.cpp similarity index 99% rename from desmume/src/gtk-glade/callbacks.cpp rename to src/gtk-glade/callbacks.cpp index a879a2a1d..b0c32c4d3 100755 --- a/desmume/src/gtk-glade/callbacks.cpp +++ b/src/gtk-glade/callbacks.cpp @@ -60,7 +60,7 @@ static void update_savestate_menu(const char * cb_name, u8 num) GtkWidget * w; char cb[40]; - snprintf( cb, 39, "%s%d", cb_name, num); + sprintf( cb, "%s%d", cb_name, num); w = glade_xml_get_widget(xml, cb); set_menuitem_label( w, savestates[num-1].date ); } @@ -205,7 +205,7 @@ static void file_open() { gtk_widget_destroy(pFileSelection); } -void on_menu_open_activate (GtkMenuItem *menuitem, gpointer user_data) { file_open();} +void on_menu_ouvrir_activate (GtkMenuItem *menuitem, gpointer user_data) { file_open();} void on_menu_quit_activate (GtkMenuItem *menuitem, gpointer user_data) { gtk_main_quit(); } #define SCREENS_PIXEL_SIZE 98304 diff --git a/desmume/src/gtk-glade/callbacks.h b/src/gtk-glade/callbacks.h similarity index 97% rename from desmume/src/gtk-glade/callbacks.h rename to src/gtk-glade/callbacks.h index 7ba0a86f5..71928d835 100755 --- a/desmume/src/gtk-glade/callbacks.h +++ b/src/gtk-glade/callbacks.h @@ -24,7 +24,7 @@ extern "C" { /* MENU FILE */ -G_MODULE_EXPORT void on_menu_open_activate (GtkMenuItem *menuitem, gpointer user_data); +G_MODULE_EXPORT void on_menu_ouvrir_activate (GtkMenuItem *menuitem, gpointer user_data); G_MODULE_EXPORT void on_menu_pscreen_activate (GtkMenuItem *menuitem, gpointer user_data); G_MODULE_EXPORT void on_menu_quit_activate (GtkMenuItem *menuitem, gpointer user_data); diff --git a/desmume/src/gtk-glade/callbacks_IO.cpp b/src/gtk-glade/callbacks_IO.cpp similarity index 100% rename from desmume/src/gtk-glade/callbacks_IO.cpp rename to src/gtk-glade/callbacks_IO.cpp diff --git a/desmume/src/gtk-glade/callbacks_IO.h b/src/gtk-glade/callbacks_IO.h similarity index 100% rename from desmume/src/gtk-glade/callbacks_IO.h rename to src/gtk-glade/callbacks_IO.h diff --git a/desmume/src/gtk-glade/dTools/callbacks_1_ioregs.cpp b/src/gtk-glade/dTools/callbacks_1_ioregs.cpp similarity index 100% rename from desmume/src/gtk-glade/dTools/callbacks_1_ioregs.cpp rename to src/gtk-glade/dTools/callbacks_1_ioregs.cpp diff --git a/desmume/src/gtk-glade/dTools/callbacks_2_memview.cpp b/src/gtk-glade/dTools/callbacks_2_memview.cpp similarity index 100% rename from desmume/src/gtk-glade/dTools/callbacks_2_memview.cpp rename to src/gtk-glade/dTools/callbacks_2_memview.cpp diff --git a/desmume/src/gtk-glade/dTools/callbacks_3_palview.cpp b/src/gtk-glade/dTools/callbacks_3_palview.cpp similarity index 100% rename from desmume/src/gtk-glade/dTools/callbacks_3_palview.cpp rename to src/gtk-glade/dTools/callbacks_3_palview.cpp diff --git a/desmume/src/gtk-glade/dTools/callbacks_4_tileview.cpp b/src/gtk-glade/dTools/callbacks_4_tileview.cpp similarity index 100% rename from desmume/src/gtk-glade/dTools/callbacks_4_tileview.cpp rename to src/gtk-glade/dTools/callbacks_4_tileview.cpp diff --git a/desmume/src/gtk-glade/dTools/callbacks_dtools.h b/src/gtk-glade/dTools/callbacks_dtools.h similarity index 100% rename from desmume/src/gtk-glade/dTools/callbacks_dtools.h rename to src/gtk-glade/dTools/callbacks_dtools.h diff --git a/desmume/src/gtk-glade/dTools/dTools_display.h b/src/gtk-glade/dTools/dTools_display.h similarity index 100% rename from desmume/src/gtk-glade/dTools/dTools_display.h rename to src/gtk-glade/dTools/dTools_display.h diff --git a/desmume/src/gtk-glade/desmume-glade.desktop b/src/gtk-glade/desmume-glade.desktop similarity index 100% rename from desmume/src/gtk-glade/desmume-glade.desktop rename to src/gtk-glade/desmume-glade.desktop diff --git a/desmume/src/gtk-glade/desmume.cpp b/src/gtk-glade/desmume.cpp similarity index 88% rename from desmume/src/gtk-glade/desmume.cpp rename to src/gtk-glade/desmume.cpp index 03327e222..fcfb08aa4 100755 --- a/desmume/src/gtk-glade/desmume.cpp +++ b/src/gtk-glade/desmume.cpp @@ -131,8 +131,17 @@ static void Draw() gboolean EmuLoop(gpointer data) { + /* + int i; + if (!noticed_3D) { + GtkWidget * dlg = glade_xml_get_widget(xml, "w3Dop"); + gtk_widget_show(dlg); + noticed_3D=TRUE; + }*/ + if(desmume_running()) /* Si on est en train d'executer le programme ... */ { + // static int limiter_frame_counter = 0; if(Frameskip == 0) NDS_SkipFrame(false); else @@ -173,6 +182,16 @@ gboolean EmuLoop(gpointer data) ticksPrevFrame = SDL_GetTicks(); + /* if ( !glade_fps_limiter_disabled) { + limiter_frame_counter += 1; + if ( limiter_frame_counter >= FPS_LIMITER_FRAME_PERIOD) { + limiter_frame_counter = 0; + + /* wait for the timer to expire *-/ + SDL_SemWait( glade_fps_limiter_semaphore); + } + }*/ + return TRUE; } gtk_widget_queue_draw(pDrawingArea); diff --git a/desmume/src/gtk-glade/desmume.h b/src/gtk-glade/desmume.h similarity index 100% rename from desmume/src/gtk-glade/desmume.h rename to src/gtk-glade/desmume.h diff --git a/desmume/src/gtk-glade/doc/Makefile.am b/src/gtk-glade/doc/Makefile.am similarity index 100% rename from desmume/src/gtk-glade/doc/Makefile.am rename to src/gtk-glade/doc/Makefile.am diff --git a/desmume/src/gtk-glade/doc/desmume-glade.1 b/src/gtk-glade/doc/desmume-glade.1 similarity index 98% rename from desmume/src/gtk-glade/doc/desmume-glade.1 rename to src/gtk-glade/doc/desmume-glade.1 index 0b9d66dae..b20f7b175 100644 --- a/desmume/src/gtk-glade/doc/desmume-glade.1 +++ b/src/gtk-glade/doc/desmume-glade.1 @@ -49,7 +49,7 @@ Select available 3d emulation: 1 = internal desmume software rasterizer (default) .RE .RS -2 = osmesa or gtkglext opengl (if available, depending on compilation options, see desmume \-\-help) +2 = osmesa or gtkglext opengl (if available, depending on compilation options, see desmume --help) .RE .TP .B \-\-disable-limiter diff --git a/desmume/src/gtk-glade/gdk_3Demu.cpp b/src/gtk-glade/gdk_3Demu.cpp similarity index 100% rename from desmume/src/gtk-glade/gdk_3Demu.cpp rename to src/gtk-glade/gdk_3Demu.cpp diff --git a/desmume/src/gtk-glade/gdk_3Demu.h b/src/gtk-glade/gdk_3Demu.h similarity index 100% rename from desmume/src/gtk-glade/gdk_3Demu.h rename to src/gtk-glade/gdk_3Demu.h diff --git a/desmume/src/gtk-glade/gdk_gl.cpp b/src/gtk-glade/gdk_gl.cpp similarity index 100% rename from desmume/src/gtk-glade/gdk_gl.cpp rename to src/gtk-glade/gdk_gl.cpp diff --git a/desmume/src/gtk-glade/gdk_gl.h b/src/gtk-glade/gdk_gl.h similarity index 100% rename from desmume/src/gtk-glade/gdk_gl.h rename to src/gtk-glade/gdk_gl.h diff --git a/desmume/src/gtk-glade/glade-xml.cpp b/src/gtk-glade/glade-xml.cpp similarity index 100% rename from desmume/src/gtk-glade/glade-xml.cpp rename to src/gtk-glade/glade-xml.cpp diff --git a/desmume/src/gtk-glade/glade/DeSmuME.xpm b/src/gtk-glade/glade/DeSmuME.xpm similarity index 100% rename from desmume/src/gtk-glade/glade/DeSmuME.xpm rename to src/gtk-glade/glade/DeSmuME.xpm diff --git a/desmume/src/gtk-glade/glade/DeSmuMe.glade b/src/gtk-glade/glade/DeSmuMe.glade similarity index 99% rename from desmume/src/gtk-glade/glade/DeSmuMe.glade rename to src/gtk-glade/glade/DeSmuMe.glade index d4cb41cd3..e61b613f5 100755 --- a/desmume/src/gtk-glade/glade/DeSmuMe.glade +++ b/src/gtk-glade/glade/DeSmuMe.glade @@ -49,11 +49,11 @@ - + True gtk-open True - + @@ -361,7 +361,7 @@ True Layers True - False + True @@ -619,17 +619,6 @@ - - - - True - TYPE: FRAM (4MB) - True - False - savetype1 - - - @@ -1050,7 +1039,7 @@ - False + True False 0 @@ -1166,7 +1155,7 @@ - False + True False 0 diff --git a/desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade b/src/gtk-glade/glade/DeSmuMe_Dtools.glade similarity index 100% rename from desmume/src/gtk-glade/glade/DeSmuMe_Dtools.glade rename to src/gtk-glade/glade/DeSmuMe_Dtools.glade diff --git a/desmume/src/gtk-glade/globals.h b/src/gtk-glade/globals.h similarity index 100% rename from desmume/src/gtk-glade/globals.h rename to src/gtk-glade/globals.h diff --git a/desmume/src/gtk-glade/keyval_names.cpp b/src/gtk-glade/keyval_names.cpp similarity index 100% rename from desmume/src/gtk-glade/keyval_names.cpp rename to src/gtk-glade/keyval_names.cpp diff --git a/desmume/src/gtk-glade/keyval_names.h b/src/gtk-glade/keyval_names.h similarity index 100% rename from desmume/src/gtk-glade/keyval_names.h rename to src/gtk-glade/keyval_names.h diff --git a/desmume/src/gtk-glade/main.cpp b/src/gtk-glade/main.cpp similarity index 90% rename from desmume/src/gtk-glade/main.cpp rename to src/gtk-glade/main.cpp index 485529e8a..d948de375 100755 --- a/desmume/src/gtk-glade/main.cpp +++ b/src/gtk-glade/main.cpp @@ -19,14 +19,13 @@ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ - + #include "callbacks.h" #include "callbacks_IO.h" #include "dTools/callbacks_dtools.h" #include "globals.h" #include "keyval_names.h" #include "rasterize.h" -#include "desmume.h" #ifdef GDB_STUB #include "../gdbstub.h" @@ -38,6 +37,10 @@ #include "gdk_3Demu.h" #endif +/* + * The frame limiter semaphore + */ +//SDL_sem *glade_fps_limiter_semaphore; int glade_fps_limiter_disabled = 0; GtkWidget * pWindow; @@ -89,7 +92,6 @@ struct configured_features { int opengl_2d; int engine_3d; int disable_limiter; - int savetype; u16 arm9_gdb_port; u16 arm7_gdb_port; @@ -111,7 +113,6 @@ init_configured_features( struct configured_features *config) { config->engine_3d = 1; config->disable_limiter = 0; - config->savetype = 0; config->nds_file = NULL; @@ -147,18 +148,8 @@ fill_configured_features( struct configured_features *config, 2 = gtkglext off-screen 3d opengl\n\n")); #endif g_print( _("\ - --disable-limiter Disables the 60 fps limiter\n\n")); - g_print( _("\ - --save-type=TYPE Selects savetype:\n\ - 0 = Autodetect (default)\n\ - 1 = EEPROM 4kbit\n\ - 2 = EEPROM 64kbit\n\ - 3 = EEPROM 512kbit\n\ - 4 = FRAM 256kbit\n\ - 5 = FLASH 2mbit\n\ - 6 = FLASH 4mbit\n\ - \n")); - g_print( _("\ + --disable-limiter Disables the 60 fps limiter\n\ + \n\ --fwlang=LANG Set the language in the firmware, LANG as follows:\n\ 0 = Japanese\n\ 1 = English\n\ @@ -212,18 +203,6 @@ fill_configured_features( struct configured_features *config, good_args = 0; } } - else if ( strncmp( argv[i], "--save-type=", 12) == 0) { - char *end_char; - int type = strtoul( &argv[i][12], &end_char, 10); - - if ( type >= 0 && type <= 6) { - config->savetype = type; - } - else { - g_printerr( _("select savetype from 0 to 6; use --help option for details\n")); - good_args = 0; - } - } else if ( strncmp( argv[i], "--fwlang=", 9) == 0) { char *end_char; int lang = strtoul( &argv[i][9], &end_char, 10); @@ -422,6 +401,28 @@ joinThread_gdb( void *thread_handle) { #endif + +/** + * A SDL timer callback function. Signals the supplied SDL semaphore + * if its value is small. + * + * @param interval The interval since the last call (in ms) + * @param param The pointer to the semaphore. + * + * @return The interval to the next call (required by SDL) + */ +/*static Uint32 +glade_fps_limiter_fn( Uint32 interval, void *param) { + SDL_sem *sdl_semaphore = (SDL_sem *)param; + + /* signal the semaphore if it is getting low *-/ + if ( SDL_SemValue( sdl_semaphore) < 4) { + SDL_SemPost( sdl_semaphore); + } + + return interval; +}*/ + /* ***** ***** MAIN ***** ***** */ static int @@ -446,7 +447,6 @@ common_gtk_glade_main( struct configured_features *my_config) { if ( my_config->firmware_language != -1) { fw_config.language = my_config->firmware_language; } - desmume_savetype(my_config->savetype); #ifdef GTKGLEXT_AVAILABLE // check if you have GTHREAD when running configure script @@ -525,13 +525,6 @@ common_gtk_glade_main( struct configured_features *my_config) { pDrawingArea = glade_xml_get_widget(xml, "wDraw_Main"); pDrawingArea2 = glade_xml_get_widget(xml, "wDraw_Sub"); - { - char wdgName[40]; - snprintf(wdgName, 39, "savetype%d", my_config->savetype+1); - GtkWidget * wdgt = glade_xml_get_widget(xml, wdgName); - gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (wdgt), TRUE); - } - /* connect the signals in the interface */ glade_xml_signal_autoconnect_StringObject(xml); glade_xml_signal_autoconnect_StringObject(xml_tools); @@ -580,10 +573,33 @@ common_gtk_glade_main( struct configured_features *my_config) { /* setup the frame limiter and indicate if it is disabled */ glade_fps_limiter_disabled = my_config->disable_limiter; + /* if ( !glade_fps_limiter_disabled) { + /* create the semaphore used for fps limiting *-/ + glade_fps_limiter_semaphore = SDL_CreateSemaphore( 1); + + /* start a SDL timer for every FPS_LIMITER_FRAME_PERIOD + * frames to keep us at 60 fps *-/ + limiter_timer = SDL_AddTimer( 16 * FPS_LIMITER_FRAME_PERIOD, + glade_fps_limiter_fn, + glade_fps_limiter_semaphore); + if ( limiter_timer == NULL) { + fprintf( stderr, _("Error trying to start FPS limiter timer: %s\n"), + SDL_GetError()); + SDL_DestroySemaphore( glade_fps_limiter_semaphore); + glade_fps_limiter_disabled = 1; + } + }*/ + /* start event loop */ gtk_main(); desmume_free(); + /* if ( !glade_fps_limiter_disabled) { + /* tidy up the FPS limiter timer and semaphore *-/ + SDL_RemoveTimer( limiter_timer); + SDL_DestroySemaphore( glade_fps_limiter_semaphore); + }*/ + /* Unload joystick */ uninit_joy(); diff --git a/desmume/src/gtk/DeSmuME.xpm b/src/gtk/DeSmuME.xpm similarity index 100% rename from desmume/src/gtk/DeSmuME.xpm rename to src/gtk/DeSmuME.xpm diff --git a/desmume/src/gtk/Makefile.am b/src/gtk/Makefile.am similarity index 77% rename from desmume/src/gtk/Makefile.am rename to src/gtk/Makefile.am index 056b62ee6..adaf2c122 100644 --- a/desmume/src/gtk/Makefile.am +++ b/src/gtk/Makefile.am @@ -1,7 +1,7 @@ SUBDIRS = doc include $(top_srcdir)/src/desmume.mk -AM_CPPFLAGS += $(SDL_CFLAGS) $(GTK_CFLAGS) $(GTHREAD_CFLAGS) +AM_CPPFLAGS += $(SDL_CFLAGS) $(GTK_CFLAGS) $(GTKGLEXT_CFLAGS) $(GTHREAD_CFLAGS) Applicationsdir = $(datadir)/applications Applications_DATA = desmume.desktop @@ -15,10 +15,11 @@ desmume_SOURCES = \ tools/ioregsView.cpp tools/ioregsView.h \ ../sndsdl.cpp \ ../ctrlssdl.h ../ctrlssdl.cpp \ + gdk_3Demu.cpp gdk_3Demu.h \ osmesa_3Demu.cpp osmesa_3Demu.h \ main.cpp desmume_LDADD = ../libdesmume.a \ - $(SDL_LIBS) $(GTK_LIBS) $(GTHREAD_LIBS) + $(SDL_LIBS) $(GTK_LIBS) $(GTKGLEXT_LIBS) $(GTHREAD_LIBS) if HAVE_GDB_STUB desmume_LDADD += ../gdbstub/libgdbstub.a endif diff --git a/desmume/src/gtk/dTool.h b/src/gtk/dTool.h similarity index 100% rename from desmume/src/gtk/dTool.h rename to src/gtk/dTool.h diff --git a/desmume/src/gtk/dToolsList.cpp b/src/gtk/dToolsList.cpp similarity index 100% rename from desmume/src/gtk/dToolsList.cpp rename to src/gtk/dToolsList.cpp diff --git a/desmume/src/gtk/desmume.cpp b/src/gtk/desmume.cpp similarity index 100% rename from desmume/src/gtk/desmume.cpp rename to src/gtk/desmume.cpp diff --git a/desmume/src/gtk/desmume.desktop b/src/gtk/desmume.desktop similarity index 100% rename from desmume/src/gtk/desmume.desktop rename to src/gtk/desmume.desktop diff --git a/desmume/src/gtk/desmume.h b/src/gtk/desmume.h similarity index 100% rename from desmume/src/gtk/desmume.h rename to src/gtk/desmume.h diff --git a/desmume/src/gtk/doc/Makefile.am b/src/gtk/doc/Makefile.am similarity index 100% rename from desmume/src/gtk/doc/Makefile.am rename to src/gtk/doc/Makefile.am diff --git a/desmume/src/gtk/doc/desmume.1 b/src/gtk/doc/desmume.1 similarity index 98% rename from desmume/src/gtk/doc/desmume.1 rename to src/gtk/doc/desmume.1 index 477b6d6ae..f931ccd35 100644 --- a/desmume/src/gtk/doc/desmume.1 +++ b/src/gtk/doc/desmume.1 @@ -52,7 +52,7 @@ Select available 3d emulation: 1 = internal desmume software rasterizer (default) .RE .RS -2 = osmesa or gtkglext opengl (if available, depending on compilation options, see desmume \-\-help) +2 = osmesa or gtkglext opengl (if available, depending on compilation options, see desmume --help) .RE .TP .B \-\-disable-sound diff --git a/src/gtk/gdk_3Demu.cpp b/src/gtk/gdk_3Demu.cpp new file mode 100644 index 000000000..b9aa58e93 --- /dev/null +++ b/src/gtk/gdk_3Demu.cpp @@ -0,0 +1,205 @@ +/* + Copyright (C) 2006-2007 Ben Jaques + + This file is part of DeSmuME + + DeSmuME is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DeSmuME is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DeSmuME; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifdef GTKGLEXT_AVAILABLE + +#include +#include + +#include "../types.h" +#include "../render3D.h" +#include "../OGLRender.h" +#include "gdk_3Demu.h" + +/* + * The GDK 3D emulation. + * This uses the OpenGL Collector plugin, using gdkGLext for the platform + * specific helper functions. + */ + + +static GdkPixmap *target_pixmap; +static GdkGLContext *glcontext = NULL; +static GdkGLDrawable *gldrawable; + + +#if 0 /* not used */ +static void +print_gl_config_attrib (GdkGLConfig *glconfig, + const gchar *attrib_str, + int attrib, + gboolean is_boolean) +{ + int value; + + g_print ("%s = ", attrib_str); + if (gdk_gl_config_get_attrib (glconfig, attrib, &value)) + { + if (is_boolean) + g_print ("%s\n", value == TRUE ? "TRUE" : "FALSE"); + else + g_print ("%d\n", value); + } + else + g_print ("*** Cannot get %s attribute value\n", attrib_str); +} + + +static void +examine_gl_config_attrib (GdkGLConfig *glconfig) +{ + g_print ("\nOpenGL visual configurations :\n\n"); + + g_print ("gdk_gl_config_is_rgba (glconfig) = %s\n", + gdk_gl_config_is_rgba (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_is_double_buffered (glconfig) = %s\n", + gdk_gl_config_is_double_buffered (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_is_stereo (glconfig) = %s\n", + gdk_gl_config_is_stereo (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_has_alpha (glconfig) = %s\n", + gdk_gl_config_has_alpha (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_has_depth_buffer (glconfig) = %s\n", + gdk_gl_config_has_depth_buffer (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_has_stencil_buffer (glconfig) = %s\n", + gdk_gl_config_has_stencil_buffer (glconfig) ? "TRUE" : "FALSE"); + g_print ("gdk_gl_config_has_accum_buffer (glconfig) = %s\n", + gdk_gl_config_has_accum_buffer (glconfig) ? "TRUE" : "FALSE"); + + g_print ("\n"); + + print_gl_config_attrib (glconfig, "GDK_GL_USE_GL", + GDK_GL_USE_GL, TRUE); + print_gl_config_attrib (glconfig, "GDK_GL_BUFFER_SIZE", + GDK_GL_BUFFER_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_LEVEL", + GDK_GL_LEVEL, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_RGBA", + GDK_GL_RGBA, TRUE); + print_gl_config_attrib (glconfig, "GDK_GL_DOUBLEBUFFER", + GDK_GL_DOUBLEBUFFER, TRUE); + print_gl_config_attrib (glconfig, "GDK_GL_STEREO", + GDK_GL_STEREO, TRUE); + print_gl_config_attrib (glconfig, "GDK_GL_AUX_BUFFERS", + GDK_GL_AUX_BUFFERS, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_RED_SIZE", + GDK_GL_RED_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_GREEN_SIZE", + GDK_GL_GREEN_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_BLUE_SIZE", + GDK_GL_BLUE_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ALPHA_SIZE", + GDK_GL_ALPHA_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_DEPTH_SIZE", + GDK_GL_DEPTH_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_STENCIL_SIZE", + GDK_GL_STENCIL_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_RED_SIZE", + GDK_GL_ACCUM_RED_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_GREEN_SIZE", + GDK_GL_ACCUM_GREEN_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_BLUE_SIZE", + GDK_GL_ACCUM_BLUE_SIZE, FALSE); + print_gl_config_attrib (glconfig, "GDK_GL_ACCUM_ALPHA_SIZE", + GDK_GL_ACCUM_ALPHA_SIZE, FALSE); + + g_print ("\n"); +} +#endif + + +static bool +_oglrender_beginOpenGL( void) { + int failed = 0; + + gdk_error_trap_push(); + failed = !gdk_gl_drawable_gl_begin(gldrawable, glcontext); + gdk_flush(); + failed = failed | gdk_error_trap_pop(); + + if (failed) return 0; + + return 1; +} + +static void +_oglrender_endOpenGL( void) { + gdk_gl_drawable_gl_end (gldrawable); +} + +static bool +_oglrender_init( void) { + /* this does nothing */ + return true; +} + +int +init_opengl_gdk_3Demu( GdkDrawable * drawable) { + GdkGLConfig *glconfig; + + /* create the off screen pixmap */ + target_pixmap = gdk_pixmap_new ( drawable, 256, 192, -1); + + if ( target_pixmap == NULL) { + g_print ("*** Failed to create pixmap.\n"); + return 0; + } + + glconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)(GDK_GL_MODE_RGBA | + GDK_GL_MODE_DEPTH | + GDK_GL_MODE_STENCIL | + GDK_GL_MODE_SINGLE)); + if (glconfig == NULL) + { + g_print ("*** No appropriate OpenGL-capable visual found.\n"); + return 0; + } + + /* + * Set OpenGL-capability to the pixmap + */ + + gldrawable = GDK_GL_DRAWABLE (gdk_pixmap_set_gl_capability (target_pixmap, + glconfig, + NULL)); + + if ( gldrawable == NULL) { + g_print ("Failed to create the GdkGLPixmap\n"); + return 0; + } + + glcontext = gdk_gl_context_new (gldrawable, + NULL, + FALSE, + GDK_GL_RGBA_TYPE); + if (glcontext == NULL) + { + g_print ("Connot create the OpenGL rendering context\n"); + return 0; + } + + + oglrender_init = _oglrender_init; + oglrender_beginOpenGL = _oglrender_beginOpenGL; + oglrender_endOpenGL = _oglrender_endOpenGL; + + + return 1; +} + +#endif diff --git a/src/gtk/gdk_3Demu.h b/src/gtk/gdk_3Demu.h new file mode 100644 index 000000000..9b2e881fa --- /dev/null +++ b/src/gtk/gdk_3Demu.h @@ -0,0 +1,32 @@ +/* $Id: gdk_3Demu.h,v 1.1 2007-04-17 16:49:33 masscat Exp $ + */ +/* + Copyright (C) 2006-2007 Ben Jaques + + This file is part of DeSmuME + + DeSmuME is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + DeSmuME is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with DeSmuME; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifdef GTKGLEXT_AVAILABLE +/* + * The GDK 3D emulation. + * This uses the OpenGL Collector plugin, using gdkGLext for the platform + * specific helper functions. + */ + +int +init_opengl_gdk_3Demu( GdkDrawable * drawable); + +#endif diff --git a/src/gtk/main.cpp b/src/gtk/main.cpp new file mode 100644 index 000000000..1f2485dc5 --- /dev/null +++ b/src/gtk/main.cpp @@ -0,0 +1,2206 @@ +/* main.c - this file is part of DeSmuME + * + * Copyright (C) 2006,2007 DeSmuME Team + * Copyright (C) 2007 Pascal Giard (evilynux) + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef GTK_UI +#define GTK_UI +#endif + +#include +#include +#include +#include +#include + +#include "types.h" +#include "armcpu.h" +#include "NDSSystem.h" +#include "sndsdl.h" +#include "ctrlssdl.h" +#include "MMU.h" +#include "render3D.h" +#include "desmume.h" +#include "debug.h" +#include "rasterize.h" +#include "saves.h" + +#ifdef GDB_STUB +#include "gdbstub.h" +#endif + +#if defined(GTKGLEXT_AVAILABLE) || defined(HAVE_LIBOSMESA) +#include +#include +#include "OGLRender.h" +#ifdef GTKGLEXT_AVAILABLE +#include +#include "gdk_3Demu.h" +#endif +#ifdef HAVE_LIBOSMESA +#include "osmesa_3Demu.h" +#endif +#endif + +#include "DeSmuME.xpm" + +#define EMULOOP_PRIO (G_PRIORITY_HIGH_IDLE + 20) + +#include + +static int backupmemorytype=MC_TYPE_AUTODETECT; +static u32 backupmemorysize=1; + +static const char *bad_glob_cflash_disk_image_file; + +#define SCREENS_PIXEL_SIZE 98304 + +#define FPS_LIMITER_FRAME_PERIOD 8 +static SDL_sem *fps_limiter_semaphore; +static int gtk_fps_limiter_disabled; + +const char * save_type_names[] = { + "Autodetect", + "EEPROM 4kbit", + "EEPROM 64kbit", + "EEPROM 512kbit", + "FRAM 256kbit", + "FLASH 2mbit", + "FLASH 4mbit", + NULL +}; + +const u16 gtk_kb_cfg[NB_KEYS] = + { + GDK_x, // A + GDK_z, // B + GDK_Shift_R, // select + GDK_Return, // start + GDK_Right, // Right + GDK_Left, // Left + GDK_Up, // Up + GDK_Down, // Down + GDK_w, // R + GDK_q, // L + GDK_s, // X + GDK_a, // Y + GDK_p, // DEBUG + GDK_o // BOOST + }; + +enum { + MAIN_BG_0 = 0, + MAIN_BG_1, + MAIN_BG_2, + MAIN_BG_3, + MAIN_OBJ, + SUB_BG_0, + SUB_BG_1, + SUB_BG_2, + SUB_BG_3, + SUB_OBJ +}; + +/************************ CONFIG FILE *****************************/ + +// extern char FirmwareFile[256]; +// int LoadFirmware(const char *filename); + +static void Open_Select(GtkWidget* widget, gpointer data); +static void Launch(); +static void Pause(); +static void Printscreen(); +static void Reset(); + +static const GtkActionEntry action_entries[] = { + { "open", "gtk-open", "Open", "o", NULL, G_CALLBACK(Open_Select) }, + { "run", "gtk-media-play", "Run", "r", NULL, G_CALLBACK(Launch) }, + { "pause", "gtk-media-pause", "Pause", "p", NULL, G_CALLBACK(Pause) }, + { "quit", "gtk-quit", "Quit", "q", NULL, G_CALLBACK(gtk_main_quit) }, + { "printscreen","gtk-media-record", "Take a screenshot", "s", NULL, G_CALLBACK(Printscreen) }, + { "reset", "gtk-refresh", "Reset", NULL, NULL, G_CALLBACK(Reset) } +}; + +GtkActionGroup * action_group; + +SoundInterface_struct *SNDCoreList[] = { +&SNDDummy, +&SNDFile, +&SNDSDL, +NULL +}; + +GPU3DInterface *core3DList[] = { + &gpu3DNull, + &gpu3DRasterize +#if defined(GTKGLEXT_AVAILABLE) || defined(HAVE_LIBOSMESA) + , + &gpu3Dgl +#endif +}; + +static u16 Cur_Keypad = 0; +static u16 gdk_shift_pressed = 0; + +struct configured_features { + int load_slot; + int opengl_2d; + int soft_colour; + + int disable_sound; + int engine_3d; + int disable_limiter; + int savetype; + + int arm9_gdb_port; + int arm7_gdb_port; + + int firmware_language; + + const char *nds_file; + const char *cflash_disk_image_file; +}; + +static void +init_configured_features( struct configured_features *config) +{ + config->load_slot = 0; + + config->arm9_gdb_port = 0; + config->arm7_gdb_port = 0; + + config->disable_sound = 0; + + config->opengl_2d = 0; + config->soft_colour = 0; + + config->engine_3d = 1; + + config->disable_limiter = 0; + + config->nds_file = NULL; + config->savetype = 0; + + config->cflash_disk_image_file = NULL; + + /* use the default language */ + config->firmware_language = -1; +} + +static int +fill_configured_features( struct configured_features *config, + int argc, char ** argv) +{ + GOptionEntry options[] = { + { "load-slot", 0, 0, G_OPTION_ARG_INT, &config->load_slot, "Loads savegame from slot NUM", "NUM"}, + { "disable-sound", 0, 0, G_OPTION_ARG_NONE, &config->disable_sound, "Disables the sound emulation", NULL}, + { "disable-limiter", 0, 0, G_OPTION_ARG_NONE, &config->disable_limiter, "Disables the 60fps limiter", NULL}, + { "3d-engine", 0, 0, G_OPTION_ARG_INT, &config->engine_3d, "Select 3d rendering engine. Available engines:\n" + "\t\t\t\t 0 = 3d disabled\n" + "\t\t\t\t 1 = internal rasterizer (default)\n" +// GTKGLEXT and LIBOSMESA are currently exclusive, so, no conflict below +#ifdef GTKGLEXT_AVAILABLE + "\t\t\t\t 2 = gtkglext off-screen opengl\n" +#endif +#ifdef HAVE_LIBOSMESA + "\t\t\t\t 2 = osmesa opengl\n" +#endif + ,"ENGINE"}, +#if defined(GTKGLEXT_AVAILABLE) + { "opengl-2d", 0, 0, G_OPTION_ARG_NONE, &config->opengl_2d, "Enables using OpenGL for screen rendering", NULL}, + { "soft-convert", 0, 0, G_OPTION_ARG_NONE, &config->soft_colour, + "Use software colour conversion during OpenGL screen rendering.\n" + "\t\t\t\t May produce better or worse frame rates depending on hardware", NULL}, +#endif + { "save-type", 0, 0, G_OPTION_ARG_INT, &config->savetype, "Select savetype from the following:\n" + "\t\t\t\t 0 = Autodetect (default)\n" + "\t\t\t\t 1 = EEPROM 4kbit\n" + "\t\t\t\t 2 = EEPROM 64kbit\n" + "\t\t\t\t 3 = EEPROM 512kbit\n" + "\t\t\t\t 4 = FRAM 256kbit\n" + "\t\t\t\t 5 = FLASH 2mbit\n" + "\t\t\t\t 6 = FLASH 4mbit\n", + "SAVETYPE"}, + { "fwlang", 0, 0, G_OPTION_ARG_INT, &config->firmware_language, "Set the language in the firmware, LANG as follows:\n" + "\t\t\t\t 0 = Japanese\n" + "\t\t\t\t 1 = English\n" + "\t\t\t\t 2 = French\n" + "\t\t\t\t 3 = German\n" + "\t\t\t\t 4 = Italian\n" + "\t\t\t\t 5 = Spanish\n", + "LANG"}, +#ifdef GDB_STUB + { "arm9gdb", 0, 0, G_OPTION_ARG_INT, &config->arm9_gdb_port, "Enable the ARM9 GDB stub on the given port", "PORT_NUM"}, + { "arm7gdb", 0, 0, G_OPTION_ARG_INT, &config->arm7_gdb_port, "Enable the ARM7 GDB stub on the given port", "PORT_NUM"}, +#endif + { "cflash", 0, 0, G_OPTION_ARG_FILENAME, &config->cflash_disk_image_file, "Enable disk image GBAMP compact flash emulation", "PATH_TO_DISK_IMAGE"}, + { NULL } + }; + GOptionContext *ctx; + GError *error = NULL; + + ctx = g_option_context_new (""); + g_option_context_add_main_entries (ctx, options, "options"); + g_option_context_add_group (ctx, gtk_get_option_group (TRUE)); + g_option_context_parse (ctx, &argc, &argv, &error); + g_option_context_free (ctx); + + if (error) { + g_printerr("Error parsing command line arguments: %s\n", error->message); + g_error_free (error); + return 0; + } + + if (argc == 2) + config->nds_file = argv[1]; + if (argc > 2) + goto error; + + if (config->firmware_language < -1 || config->firmware_language > 5) { + g_printerr("Firmware language must be set to a value from 0 to 5.\n"); + goto error; + } + + if (config->load_slot < 0 || config->load_slot > 10) { + g_printerr("I only know how to load from slots 1-10, 0 means 'do not load savegame' and is default\n"); + goto error; + } + + if (config->engine_3d != 0 && config->engine_3d != 1 +#if defined(GTKGLEXT_AVAILABLE) || defined(HAVE_LIBOSMESA) + && config->engine_3d != 2 +#endif + ) { + g_printerr("Currently available ENGINES: 0, 1" +#if defined(GTKGLEXT_AVAILABLE) || defined(HAVE_LIBOSMESA) + ", 2" +#endif + "\n"); + goto error; + } + +#ifdef GDB_STUB + if (config->arm9_gdb_port != 0 && (config->arm9_gdb_port < 1 || config->arm9_gdb_port > 65535)) { + g_printerr("ARM9 GDB stub port must be in the range 1 to 65535\n"); + goto error; + } + + if (config->arm7_gdb_port != 0 && (config->arm7_gdb_port < 1 || config->arm7_gdb_port > 65535)) { + g_printerr("ARM7 GDB stub port must be in the range 1 to 65535\n"); + goto error; + } +#endif + + return 1; + +error: + g_printerr("USAGE: %s [options] [nds-file]\n", argv[0]); + g_printerr("USAGE: %s --help - for help\n", argv[0]); + return 0; +} + + +/* + * The thread handling functions needed by the GDB stub code. + */ +#ifdef GDB_STUB +void * +createThread_gdb( void (*thread_function)( void *data), + void *thread_data) +{ + GThread *new_thread = g_thread_create( (GThreadFunc)thread_function, + thread_data, + TRUE, + NULL); + + return new_thread; +} + +void +joinThread_gdb( void *thread_handle) { + g_thread_join( (GThread *)thread_handle); +} +#endif + + +u16 Keypad_Temp[NB_KEYS]; + +static int Write_ConfigFile(const gchar *config_file) +{ + int i; + GKeyFile * keyfile; + gchar *contents; + gboolean ret; + + keyfile = g_key_file_new(); + + for(i = 0; i < NB_KEYS; i++) { + g_key_file_set_integer(keyfile, "KEYS", key_names[i], keyboard_cfg[i]); + g_key_file_set_integer(keyfile, "JOYKEYS", key_names[i], joypad_cfg[i]); + } + +// if(FirmwareFile[0]) { +// ini_add_section(ini, "FIRMWARE"); +// ini_add_value(ini, "FIRMWARE", "FILE", FirmwareFile); +// } + + contents = g_key_file_to_data(keyfile, 0, 0); + ret = g_file_set_contents(config_file, contents, -1, NULL); + if (!ret) + g_printerr("Failed to write to %s\n", config_file); + g_free (contents); + + g_key_file_free(keyfile); + + return 0; +} + +static int Read_ConfigFile(const gchar *config_file) +{ + int i, tmp; + GKeyFile * keyfile = g_key_file_new(); + GError * error = NULL; + + load_default_config(gtk_kb_cfg); + + g_key_file_load_from_file(keyfile, config_file, G_KEY_FILE_NONE, 0); + + /* Load keyboard keys */ + for(i = 0; i < NB_KEYS; i++) { + tmp = g_key_file_get_integer(keyfile, "KEYS", key_names[i], &error); + if (error != NULL) { + g_error_free(error); + error = NULL; + } else { + keyboard_cfg[i] = tmp; + } + } + + /* Load joystick keys */ + for(i = 0; i < NB_KEYS; i++) { + tmp = g_key_file_get_integer(keyfile, "JOYKEYS", key_names[i], &error); + if (error != NULL) { + g_error_free(error); + error = NULL; + } else { + joypad_cfg[i] = tmp; + } + } + + g_key_file_free(keyfile); + + return 0; +} + +/************************ GTK *******************************/ + +uint Frameskip = 0; + +static GtkWidget *pWindow; +static GtkWidget *pStatusBar; +static GtkWidget *pDrawingArea; + +/** The target for the expose event */ +static GtkWidget *nds_screen_widget; + +#ifdef GTKGLEXT_AVAILABLE +static GtkWidget *top_screen_widget; +static GtkWidget *bottom_screen_widget; + +GLuint screen_texture[1]; +#endif + +float nds_screen_size_ratio = 1.0f; + +static BOOL regMainLoop = FALSE; + +static inline void pStatusBar_Change (const char *message) +{ + gint pStatusBar_Ctx; + + pStatusBar_Ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(pStatusBar), "Global"); + gtk_statusbar_pop(GTK_STATUSBAR(pStatusBar), pStatusBar_Ctx); + gtk_statusbar_push(GTK_STATUSBAR(pStatusBar), pStatusBar_Ctx, message); +} + +gboolean EmuLoop(gpointer data); + +static void About(GtkWidget* widget, gpointer data) +{ + GdkPixbuf * pixbuf = gdk_pixbuf_new_from_xpm_data(DeSmuME_xpm); + + gtk_show_about_dialog(GTK_WINDOW(pWindow), + "name", "DeSmuME", + "version", VERSION, + "website", "http://desmume.org", + "logo", pixbuf, + "comments", "Nintendo DS emulator based on work by Yopyop", + NULL); + + g_object_unref(pixbuf); +} + +static int Open(const char *filename, const char *cflash_disk_image) +{ + return NDS_LoadROM( filename, backupmemorytype, backupmemorysize, cflash_disk_image ); +} + +static void Launch() +{ + desmume_resume(); + + if(!regMainLoop) { + g_idle_add_full(EMULOOP_PRIO, &EmuLoop, pWindow, NULL); + regMainLoop = TRUE; + } + + pStatusBar_Change("Running ..."); + + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "pause"), TRUE); + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), FALSE); + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "reset"), TRUE); + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "printscreen"), TRUE); +} + +static void Pause() +{ + desmume_pause(); + pStatusBar_Change("Paused"); + + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "pause"), FALSE); + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), TRUE); +} + +/* Choose a file then load it */ +static void Open_Select(GtkWidget* widget, gpointer data) +{ + GtkFileFilter *pFilter_nds, *pFilter_dsgba, *pFilter_any; + GtkWidget *pFileSelection; + GtkWidget *pParent; + gchar *sPath; + + if (desmume_running()) + Pause(); + + pParent = GTK_WIDGET(data); + + pFilter_nds = gtk_file_filter_new(); + gtk_file_filter_add_pattern(pFilter_nds, "*.nds"); +#ifdef HAVE_LIBZ + gtk_file_filter_add_pattern(pFilter_nds, "*.nds.gz"); +#endif +#ifdef HAVE_LIBZZIP + gtk_file_filter_add_pattern(pFilter_nds, "*.nds.zip"); +#endif + gtk_file_filter_set_name(pFilter_nds, "Nds binary (.nds)"); + + pFilter_dsgba = gtk_file_filter_new(); + gtk_file_filter_add_pattern(pFilter_dsgba, "*.ds.gba"); + gtk_file_filter_set_name(pFilter_dsgba, "Nds binary with loader (.ds.gba)"); + + pFilter_any = gtk_file_filter_new(); + gtk_file_filter_add_pattern(pFilter_any, "*"); + gtk_file_filter_set_name(pFilter_any, "All files"); + + /* Creating the selection window */ + pFileSelection = gtk_file_chooser_dialog_new("Open...", + GTK_WINDOW(pParent), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL); + /* Only the dialog window is accepting events: */ + gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE); + + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_nds); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_dsgba); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); + + /* Showing the window */ + switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { + case GTK_RESPONSE_OK: + sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); + if(Open((const char*)sPath, bad_glob_cflash_disk_image_file) < 0) { + GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), + GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "Unable to load :\n%s", sPath); + gtk_dialog_run(GTK_DIALOG(pDialog)); + gtk_widget_destroy(pDialog); + } else { + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), TRUE); + } + + //Launch(NULL, pWindow); + + g_free(sPath); + break; + default: + break; + } + gtk_widget_destroy(pFileSelection); +} + +#if 0 /* not used */ +static void Close() +{ +} +#endif + +static void Reset() +{ + NDS_Reset(); + desmume_resume(); + + pStatusBar_Change("Running ..."); +} + +#ifdef GTKGLEXT_AVAILABLE +static void +gtk_init_main_gl_area(GtkWidget *widget, + gpointer data) +{ + GLenum errCode; + GdkGLContext *glcontext; + GdkGLDrawable *gldrawable; + glcontext = gtk_widget_get_gl_context (widget); + gldrawable = gtk_widget_get_gl_drawable (widget); + uint16_t blank_texture[256 * 512]; + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return; + + LOG("Doing GL init\n"); + + memset(blank_texture, 0x001f, sizeof(blank_texture)); + + /* Enable Texture Mapping */ + glEnable( GL_TEXTURE_2D ); + + /* Set the background black */ + glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); + + /* Create The Texture */ + glGenTextures( 1, &screen_texture[0]); + + glBindTexture( GL_TEXTURE_2D, screen_texture[0]); + + /* Generate The Texture */ + glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 256, 512, + 0, GL_RGBA, + GL_UNSIGNED_SHORT_1_5_5_5_REV, + blank_texture); + + /* Linear Filtering */ + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); + glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); + + if ((errCode = glGetError()) != GL_NO_ERROR) { + const GLubyte *errString; + + errString = gluErrorString(errCode); + g_printerr("Failed to init GL: %s\n", errString); + } + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ +} + +static void +gtk_init_sub_gl_area(GtkWidget *widget, + gpointer data) +{ + GLenum errCode; + GdkGLContext *glcontext; + GdkGLDrawable *gldrawable; + glcontext = gtk_widget_get_gl_context (widget); + gldrawable = gtk_widget_get_gl_drawable (widget); + + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return; + + /* Enable Texture Mapping */ + glEnable( GL_TEXTURE_2D ); + + /* Set the background black */ + glClearColor( 0.0f, 0.0f, 0.0f, 0.0f ); + + glBindTexture( GL_TEXTURE_2D, screen_texture[0]); + + if ((errCode = glGetError()) != GL_NO_ERROR) { + const GLubyte *errString; + + errString = gluErrorString(errCode); + g_printerr("Failed to init GL: %s\n", errString); + } + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ +} +#endif + + +/////////////////////////////// DRAWING SCREEN ////////////////////////////////// + +static inline void gpu_screen_to_rgb(u8 *rgb, int size) +{ + for (int i = 0; i < size; i++) { + rgb[(i*3)+0] = ((*((u16 *)&GPU_screen[(i<<1)]) >> 0) & 0x1f) << 3; + rgb[(i*3)+1] = ((*((u16 *)&GPU_screen[(i<<1)]) >> 5) & 0x1f) << 3; + rgb[(i*3)+2] = ((*((u16 *)&GPU_screen[(i<<1)]) >> 10) & 0x1f) << 3; + } +} + +#ifdef GTKGLEXT_AVAILABLE +static int +top_screen_expose_fn( GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + int software_convert = *((int *)data); + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return FALSE; + + GLenum errCode; + + /* Clear The Screen And The Depth Buffer */ + glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); + + /* Move Into The Screen 5 Units */ + //glLoadIdentity( ); + + /* Select screen Texture */ + glBindTexture( GL_TEXTURE_2D, screen_texture[0]); + + if ( software_convert) { + u8 converted[256 * 384 * 3]; + + gpu_screen_to_rgb(converted, 256 * 384); + glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 256, 384, + GL_RGB, + GL_UNSIGNED_BYTE, + converted); + } else { + glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 256, 384, + GL_RGBA, + GL_UNSIGNED_SHORT_1_5_5_5_REV, + &GPU_screen); + } + + + if ((errCode = glGetError()) != GL_NO_ERROR) { + const GLubyte *errString; + + errString = gluErrorString(errCode); + g_printerr("GL subimage failed: %s\n", errString); + } + + + glBegin( GL_QUADS); + + /* Top screen */ + glTexCoord2f( 0.0f, 0.0f ); glVertex3f( 0.0f, 0.0f, 0.0f ); + glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 256.0f, 0.0f, 0.0f ); + glTexCoord2f( 1.0f, 0.375f ); glVertex3f( 256.0f, 192.0f, 0.0f ); + glTexCoord2f( 0.0f, 0.375f ); glVertex3f( 0.0f, 192.0f, 0.0f ); + glEnd( ); + + if ((errCode = glGetError()) != GL_NO_ERROR) { + const GLubyte *errString; + + errString = gluErrorString(errCode); + g_printerr("GL draw failed: %s\n", errString); + } + + if (gdk_gl_drawable_is_double_buffered (gldrawable)) + gdk_gl_drawable_swap_buffers (gldrawable); + else + glFlush (); + + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ + + gtk_widget_queue_draw( bottom_screen_widget); + + return TRUE; +} + +static int +bottom_screen_expose_fn(GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + + LOG("Sub Expose\n"); + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) { + g_printerr("begin failed\n"); + return FALSE; + } + LOG("begin\n"); + + GLenum errCode; + + /* Clear The Screen */ + glClear( GL_COLOR_BUFFER_BIT); + + //glBindTexture( GL_TEXTURE_2D, screen_texture[0]); + + glBegin( GL_QUADS); + + /* Bottom screen */ + glTexCoord2f( 0.0f, 0.375f ); glVertex2f( 0.0f, 0.0f); + glTexCoord2f( 1.0f, 0.375f ); glVertex2f( 256.0f, 0.0f); + glTexCoord2f( 1.0f, 0.75f ); glVertex2f( 256.0f, 192.0f); + glTexCoord2f( 0.0f, 0.75f ); glVertex2f( 0.0f, 192.0f); + glEnd( ); + + if (gdk_gl_drawable_is_double_buffered (gldrawable)) + gdk_gl_drawable_swap_buffers (gldrawable); + else + glFlush (); + + + if ((errCode = glGetError()) != GL_NO_ERROR) { + const GLubyte *errString; + + errString = gluErrorString(errCode); + g_printerr("sub GL draw failed: %s\n", errString); + } + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ + + return 1; +} + +static gboolean +common_configure_fn( GtkWidget *widget, + GdkEventConfigure *event ) +{ + if ( gtk_widget_is_gl_capable( widget) == FALSE) + return TRUE; + + GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); + + int comp_width = 3 * event->width; + int comp_height = 4 * event->height; + int use_width = 1; + GLenum errCode; + + /* Height / width ration */ + GLfloat ratio; + + LOG("width %d, height %d\n", event->width, event->height); + + /*** OpenGL BEGIN ***/ + if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) + return FALSE; + + if ( comp_width > comp_height) { + use_width = 0; + } + + /* Protect against a divide by zero */ + if ( event->height == 0 ) + event->height = 1; + if ( event->width == 0) + event->width = 1; + + ratio = ( GLfloat )event->width / ( GLfloat )event->height; + + /* Setup our viewport. */ + glViewport( 0, 0, ( GLint )event->width, ( GLint )event->height ); + + /* + * change to the projection matrix and set + * our viewing volume. + */ + glMatrixMode( GL_PROJECTION ); + glLoadIdentity( ); + + { + double left; + double right; + double bottom; + double top; + double other_dimen; + + if ( use_width) { + left = 0.0; + right = 256.0; + + nds_screen_size_ratio = 256.0 / (double)event->width; + + other_dimen = (double)event->width * 3.0 / 4.0; + + top = 0.0; + bottom = 192.0 * ((double)event->height / other_dimen); + } else { + top = 0.0; + bottom = 192.0; + + nds_screen_size_ratio = 192.0 / (double)event->height; + + other_dimen = (double)event->height * 4.0 / 3.0; + + left = 0.0; + right = 256.0 * ((double)event->width / other_dimen); + } + + LOG("%d,%d\n", event->width, event->height); + LOG("l %lf, r %lf, t %lf, b %lf, other dimen %lf\n", + left, right, top, bottom, other_dimen); + + /* get the area (0,0) to (256,384) into the middle of the viewport */ + gluOrtho2D( left, right, bottom, top); + } + + /* Make sure we're chaning the model view and not the projection */ + glMatrixMode( GL_MODELVIEW ); + + /* Reset The View */ + glLoadIdentity( ); + + if ((errCode = glGetError()) != GL_NO_ERROR) { + const GLubyte *errString; + + errString = gluErrorString(errCode); + g_printerr("GL resie failed: %s\n", errString); + } + + gdk_gl_drawable_gl_end (gldrawable); + /*** OpenGL END ***/ + + return TRUE; +} + +#endif + + + +/* Drawing callback */ +static int gtkFloatExposeEvent (GtkWidget *widget, GdkEventExpose *event, gpointer data) +{ + guchar *rgb; + rgb = (guchar *) malloc(SCREENS_PIXEL_SIZE*3); + if (!rgb) + return 0; + + gpu_screen_to_rgb(rgb, SCREENS_PIXEL_SIZE); + gdk_draw_rgb_image (widget->window, + widget->style->fg_gc[widget->state], 0, 0, + 256, 192*2, + GDK_RGB_DITHER_NONE, + rgb, 256*3); + + free(rgb); + return 1; +} + +/////////////////////////////// KEYS AND STYLUS UPDATE /////////////////////////////////////// + +static gboolean Stylus_Move(GtkWidget *w, GdkEventMotion *e, gpointer data) +{ + GdkModifierType state; + gint x,y; + s32 EmuX, EmuY; + const int *opengl = (const int *)data; + + if(click) { + int scaled_x, scaled_y; + if(e->is_hint) + gdk_window_get_pointer(w->window, &x, &y, &state); + else { + x= (gint)e->x; + y= (gint)e->y; + state=(GdkModifierType)e->state; + } + + scaled_x = int(x * nds_screen_size_ratio); + scaled_y = int(y * nds_screen_size_ratio); + + LOG("X=%d, Y=%d, S&1=%d\n", x,y,state&GDK_BUTTON1_MASK); + + if ( !(*opengl)) { + scaled_y -= 192; + } + if(scaled_y >= 0 && (state & GDK_BUTTON1_MASK)) { + EmuX = CLAMP(scaled_x, 0, 255); + EmuY = CLAMP(scaled_y, 0, 192); + NDS_setTouchPos(EmuX, EmuY); + } + } + + return TRUE; +} + +static gboolean Stylus_Press(GtkWidget * w, GdkEventButton * e, + gpointer data) +{ + GdkModifierType state; + gint x, y; + s32 EmuX, EmuY; + const int *opengl = (const int *) data; + + if (desmume_running()) { + if (e->button == 1) { + int scaled_x, scaled_y; + click = TRUE; + + gdk_window_get_pointer(w->window, &x, &y, &state); + + scaled_x = int(x * nds_screen_size_ratio); + scaled_y = int(y * nds_screen_size_ratio); + + if (!(*opengl)) { + scaled_y -= 192; + } + if (scaled_y >= 0 && (state & GDK_BUTTON1_MASK)) { + EmuX = CLAMP(scaled_x, 0, 255); + EmuY = CLAMP(scaled_y, 0, 192); + NDS_setTouchPos(EmuX, EmuY); + } + } + } + + return TRUE; +} +static gboolean Stylus_Release(GtkWidget *w, GdkEventButton *e, gpointer data) +{ + if(click) NDS_releaseTouch(); + click = FALSE; + return TRUE; +} + +static void loadgame(int num){ + if (desmume_running()) + { + Pause(); + loadstate_slot(num); + Launch(); + } + else + loadstate_slot(num); +} + +static void savegame(int num){ + if (desmume_running()) + { + Pause(); + savestate_slot(num); + Launch(); + } + else + savestate_slot(num); +} + +static gint Key_Press(GtkWidget *w, GdkEventKey *e, gpointer data) +{ + if (e->keyval == GDK_Shift_L){ + gdk_shift_pressed |= 1; + return 1; + } + if (e->keyval == GDK_Shift_R){ + gdk_shift_pressed |= 2; + return 1; + } + if( e->keyval >= GDK_F1 && e->keyval <= GDK_F10 ){ + if(!gdk_shift_pressed) + loadgame(e->keyval - GDK_F1 + 1); + else + savegame(e->keyval - GDK_F1 + 1); + return 1; + } + // FIXME: this is a hack to allow accels to work together with keypad emulation + // should be fixed by somebody who knows how to make key_press_event trigger AFTER all GtkAccels + guint mask; + mask = GDK_SHIFT_MASK | GDK_CONTROL_MASK | GDK_MOD1_MASK | GDK_MOD5_MASK; // shift,ctrl, both alts + if( (e->state & mask) == 0){ + u16 Key = lookup_key(e->keyval); + if(Key){ + ADD_KEY( Cur_Keypad, Key ); + if(desmume_running()) update_keypad(Cur_Keypad); + return 1; + } + } + +#ifdef PROFILE_MEMORY_ACCESS + if ( e->keyval == GDK_Tab) { + print_memory_profiling(); + return 1; + } +#endif + return 0; +} + +static gint Key_Release(GtkWidget *w, GdkEventKey *e, gpointer data) +{ + if (e->keyval == GDK_Shift_L){ + gdk_shift_pressed &= ~1; + return 1; + } + if (e->keyval == GDK_Shift_R){ + gdk_shift_pressed &= ~2; + return 1; + } + u16 Key = lookup_key(e->keyval); + RM_KEY( Cur_Keypad, Key ); + if(desmume_running()) update_keypad(Cur_Keypad); + return 1; + +} + +/////////////////////////////// CONTROLS EDIT ////////////////////////////////////// + +struct modify_key_ctx { + gint mk_key_chosen; + GtkWidget *label; +}; + +static void Modify_Key_Press(GtkWidget *w, GdkEventKey *e, struct modify_key_ctx *ctx) +{ + gchar *YouPressed; + + ctx->mk_key_chosen = e->keyval; + YouPressed = g_strdup_printf("You pressed : %s\nClick OK to keep this key.", gdk_keyval_name(e->keyval)); + gtk_label_set(GTK_LABEL(ctx->label), YouPressed); + g_free(YouPressed); +} + +static void Modify_Key(GtkWidget* widget, gpointer data) +{ + struct modify_key_ctx ctx; + GtkWidget *mkDialog; + gchar *Key_Label; + gchar *Title; + gint Key; + + Key = GPOINTER_TO_INT(data); + ctx.mk_key_chosen = 0; + Title = g_strdup_printf("Press \"%s\" key ...\n", key_names[Key]); + mkDialog = gtk_dialog_new_with_buttons(Title, + GTK_WINDOW(pWindow), + GTK_DIALOG_MODAL, + GTK_STOCK_OK,GTK_RESPONSE_OK, + GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL, + NULL); + + ctx.label = gtk_label_new(Title); + g_free(Title); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(mkDialog)->vbox), ctx.label, TRUE, FALSE, 0); + + g_signal_connect(G_OBJECT(mkDialog), "key_press_event", G_CALLBACK(Modify_Key_Press), &ctx); + + gtk_widget_show_all(GTK_DIALOG(mkDialog)->vbox); + + switch(gtk_dialog_run(GTK_DIALOG(mkDialog))) { + case GTK_RESPONSE_OK: + Keypad_Temp[Key] = ctx.mk_key_chosen; + Key_Label = g_strdup_printf("%s (%s)", key_names[Key], gdk_keyval_name(Keypad_Temp[Key])); + gtk_button_set_label(GTK_BUTTON(widget), Key_Label); + g_free(Key_Label); + break; + case GTK_RESPONSE_CANCEL: + case GTK_RESPONSE_NONE: + ctx.mk_key_chosen = 0; + break; + } + + gtk_widget_destroy(mkDialog); + +} + +static void Edit_Controls(GtkWidget* widget, gpointer data) +{ + GtkWidget *ecDialog; + GtkWidget *ecKey; + gchar *Key_Label; + int i; + + memcpy(&Keypad_Temp, &keyboard_cfg, sizeof(keyboard_cfg)); + + ecDialog = gtk_dialog_new_with_buttons("Edit controls", + GTK_WINDOW(pWindow), + GTK_DIALOG_MODAL, + GTK_STOCK_OK,GTK_RESPONSE_OK, + GTK_STOCK_CANCEL,GTK_RESPONSE_CANCEL, + NULL); + + for(i = 0; i < NB_KEYS; i++) { + Key_Label = g_strdup_printf("%s (%s)", key_names[i], gdk_keyval_name(Keypad_Temp[i])); + ecKey = gtk_button_new_with_label(Key_Label); + g_free(Key_Label); + g_signal_connect(G_OBJECT(ecKey), "clicked", G_CALLBACK(Modify_Key), GINT_TO_POINTER(i)); + gtk_box_pack_start(GTK_BOX(GTK_DIALOG(ecDialog)->vbox), ecKey,TRUE, FALSE, 0); + } + + gtk_widget_show_all(GTK_DIALOG(ecDialog)->vbox); + + switch (gtk_dialog_run(GTK_DIALOG(ecDialog))) { + case GTK_RESPONSE_OK: + memcpy(&keyboard_cfg, &Keypad_Temp, sizeof(keyboard_cfg)); + case GTK_RESPONSE_CANCEL: + case GTK_RESPONSE_NONE: + break; + } + gtk_widget_destroy(ecDialog); + +} + +///////////////////////////////// SCREEN SCALING ////////////////////////////// + +#ifdef BROKEN_SCREENSIZE +#define MAX_SCREENCOEFF 4 + +static void Modify_ScreenCoeff(GtkWidget* widget, gpointer data) +{ + guint Size = GPOINTER_TO_UINT(data); + static int ScreenCoeff_Size; + + gtk_drawing_area_size(GTK_DRAWING_AREA(pDrawingArea), 256 * Size, 384 * Size); + gtk_widget_set_usize (pDrawingArea, 256 * Size, 384 * Size); + + ScreenCoeff_Size = Size; +} +#endif + +/////////////////////////////// LAYER HIDING ///////////////////////////////// + +static void Modify_Layer(GtkWidget* widget, gpointer data) +{ + guint Layer = GPOINTER_TO_UINT(data); + gboolean active; + + if (!desmume_running()) + return; + + active = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)); + + switch (Layer) { + case MAIN_BG_0: + case MAIN_BG_1: + case MAIN_BG_2: + case MAIN_BG_3: + if(active == TRUE) { + if (!MainScreen.gpu->dispBG[Layer]) + GPU_addBack(MainScreen.gpu, Layer); + } else { + if (MainScreen.gpu->dispBG[Layer]) + GPU_remove(MainScreen.gpu, Layer); + } + break; + case MAIN_OBJ: + if(active == TRUE) { + if (!MainScreen.gpu->dispOBJ) + GPU_addBack(MainScreen.gpu, Layer); + } else { + if (MainScreen.gpu->dispOBJ) + GPU_remove(MainScreen.gpu, Layer); + } + break; + case SUB_BG_0: + case SUB_BG_1: + case SUB_BG_2: + case SUB_BG_3: + if(active == TRUE) { + if (!SubScreen.gpu->dispBG[Layer-SUB_BG_0]) + GPU_addBack(SubScreen.gpu, Layer-SUB_BG_0); + } else { + if (SubScreen.gpu->dispBG[Layer-SUB_BG_0]) + GPU_remove(SubScreen.gpu, Layer-SUB_BG_0); + } + break; + case SUB_OBJ: + if(active == TRUE) { + if (!SubScreen.gpu->dispOBJ) + GPU_addBack(SubScreen.gpu, Layer-SUB_BG_0); + } else { + if (SubScreen.gpu->dispOBJ) + GPU_remove(SubScreen.gpu, Layer-SUB_BG_0); + } + break; + default: + break; + } +} + +/////////////////////////////// PRINTSCREEN ///////////////////////////////// + +static void Printscreen() +{ + GdkPixbuf *screenshot; + gchar *filename; + GError *error = NULL; + u8 *rgb; + static int seq = 0; + + rgb = (u8 *) malloc(SCREENS_PIXEL_SIZE*3); + if (!rgb) + return; + + gpu_screen_to_rgb(rgb, SCREENS_PIXEL_SIZE); + screenshot = gdk_pixbuf_new_from_data(rgb, + GDK_COLORSPACE_RGB, + FALSE, + 8, + 256, + 192*2, + 256*3, + NULL, + NULL); + + filename = g_strdup_printf("./desmume-screenshot-%d.png", seq); + gdk_pixbuf_save(screenshot, filename, "png", &error, NULL); + if (error) { + g_error_free (error); + g_printerr("Failed to save %s", filename); + } else { + seq++; + } + + free(rgb); + g_object_unref(screenshot); + g_free(filename); +} + +/////////////////////////////// DS CONFIGURATION ////////////////////////////////// + +#if 0 + +char FirmwareFile[256]; + +int LoadFirmware(const char *filename) +{ + int i; + u32 size; + FILE *f; + + strncpy(FirmwareFile, filename, ARRAY_SIZE(FirmwareFile)); + + f = fopen(filename, "rb"); + if(!f) return -1; + + fseek(f, 0, SEEK_END); + size = ftell(f); + fseek(f, 0, SEEK_SET); + + if(size > MMU.spi7.fw.size) { fclose(f); return -1; } /* this must be a small file*/ + + i = fread(MMU.spi7.fw.data, size, 1, f); + + fclose(f); + + return i; +} + +int SelectFirmwareFile_Load(GtkWidget *w, gpointer data) +{ + GtkFileFilter *pFilter_nds, *pFilter_bin, *pFilter_any; + GtkWidget *pFileSelection; + GtkWidget *pParent; + gchar *sPath; + + BOOL oldState = desmume_running(); + Pause(); + + pParent = GTK_WIDGET(data); + + pFilter_nds = gtk_file_filter_new(); + gtk_file_filter_add_pattern(pFilter_nds, "*.nds"); + gtk_file_filter_set_name(pFilter_nds, "Nds binary (.nds)"); + + pFilter_bin = gtk_file_filter_new(); + gtk_file_filter_add_pattern(pFilter_bin, "*.bin"); + gtk_file_filter_set_name(pFilter_bin, "Binary file (.bin)"); + + pFilter_any = gtk_file_filter_new(); + gtk_file_filter_add_pattern(pFilter_any, "*"); + gtk_file_filter_set_name(pFilter_any, "All files"); + + pFileSelection = gtk_file_chooser_dialog_new("Load firmware...", + GTK_WINDOW(pParent), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL); + gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE); + + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_nds); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_bin); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); + + if(FirmwareFile[0]) gtk_file_chooser_select_uri(GTK_FILE_CHOOSER(pFileSelection), FirmwareFile); + + switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { + case GTK_RESPONSE_OK: + sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); + if(LoadFirmware((const char*)sPath) < 0) { + GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Unable to load :\n%s", sPath); + gtk_dialog_run(GTK_DIALOG(pDialog)); + gtk_widget_destroy(pDialog); + } else { + GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Selected firmware :\n%s", sPath); + gtk_dialog_run(GTK_DIALOG(pDialog)); + gtk_widget_destroy(pDialog); + } + + g_free(sPath); + break; + default: + break; + } + gtk_widget_destroy(pFileSelection); + + if(oldState) Launch(); + +} + +int SelectFirmwareFile_Load(GtkWidget *w, gpointer data) +{ + GtkFileFilter *pFilter_nds, *pFilter_bin, *pFilter_any; + GtkWidget *pFileSelection; + GtkWidget *pParent; + gchar *sPath; + + BOOL oldState = desmume_running(); + Pause(); + + pParent = GTK_WIDGET(data); + + pFilter_nds = gtk_file_filter_new(); + gtk_file_filter_add_pattern(pFilter_nds, "*.nds"); + gtk_file_filter_set_name(pFilter_nds, "Nds binary (.nds)"); + + pFilter_bin = gtk_file_filter_new(); + gtk_file_filter_add_pattern(pFilter_bin, "*.bin"); + gtk_file_filter_set_name(pFilter_bin, "Binary file (.bin)"); + + pFilter_any = gtk_file_filter_new(); + gtk_file_filter_add_pattern(pFilter_any, "*"); + gtk_file_filter_set_name(pFilter_any, "All files"); + + pFileSelection = gtk_file_chooser_dialog_new("Save firmware...", + GTK_WINDOW(pParent), + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_OK, + NULL); + gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE); + + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_nds); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_bin); + gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(pFileSelection), pFilter_any); + + if(FirmwareFile[0]) gtk_file_chooser_select_uri(GTK_FILE_CHOOSER(pFileSelection), FirmwareFile); + + switch(gtk_dialog_run(GTK_DIALOG(pFileSelection))) { + case GTK_RESPONSE_OK: + sPath = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection)); + if(LoadFirmware((const char*)sPath) < 0) { + GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "Unable to load :\n%s", sPath); + gtk_dialog_run(GTK_DIALOG(pDialog)); + gtk_widget_destroy(pDialog); + } else { + GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pFileSelection), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "Selected firmware :\n%s", sPath); + gtk_dialog_run(GTK_DIALOG(pDialog)); + gtk_widget_destroy(pDialog); + } + + g_free(sPath); + break; + default: + break; + } + gtk_widget_destroy(pFileSelection); + + if(oldState) Launch(); + +} + +#endif + +/////////////////////////////// FRAMESKIP ///////////////////////////////// + +#define MAX_FRAMESKIP 10 + +static void Modify_Frameskip(GtkWidget *widget, gpointer data) +{ + Frameskip = GPOINTER_TO_INT(data); +} + +/////////////////////////////// TOOLS MANAGEMENT /////////////////////////////// + +#include "dTool.h" + +extern const dTool_t *dTools_list[]; +extern const int dTools_list_size; + +BOOL *dTools_running; + +static void Start_dTool(GtkWidget *widget, gpointer data) +{ + int tool = GPOINTER_TO_INT(data); + + if(dTools_running == NULL || dTools_running[tool]) + return; + + dTools_list[tool]->open(tool); + dTools_running[tool] = TRUE; +} + +void dTool_CloseCallback(int tool) +{ + if (dTools_running == NULL) + return; + + dTools_running[tool] = FALSE; +} + +/////////////////////////////// MAIN EMULATOR LOOP /////////////////////////////// + +static inline void _updateDTools() +{ + if (dTools_running == NULL) + return; + + for(int i = 0; i < dTools_list_size; i++) { + if(dTools_running[i]) { dTools_list[i]->update(); } + } +} + +gboolean EmuLoop(gpointer data) +{ + static Uint32 fps, fps_SecStart, fps_FrameCount; + unsigned int i; + gchar *Title; + + if(desmume_running()) { /* Si on est en train d'executer le programme ... */ + static int limiter_frame_counter = 0; + fps_FrameCount += Frameskip + 1; + if(!fps_SecStart) fps_SecStart = SDL_GetTicks(); + if(SDL_GetTicks() - fps_SecStart >= 1000) { + fps_SecStart = SDL_GetTicks(); + fps = fps_FrameCount; + fps_FrameCount = 0; + + Title = g_strdup_printf("Desmume - %dfps", fps); + gtk_window_set_title(GTK_WINDOW(pWindow), Title); + g_free(Title); + } + + desmume_cycle(); /* Emule ! */ + NDS_SkipFrame(true); + for(i = 0; i < Frameskip; i++) { + desmume_cycle(); + } + NDS_SkipFrame(false); + + _updateDTools(); + gtk_widget_queue_draw( nds_screen_widget); + + if ( !gtk_fps_limiter_disabled) { + limiter_frame_counter += 1; + if ( limiter_frame_counter >= FPS_LIMITER_FRAME_PERIOD) { + limiter_frame_counter = 0; + + /* wait for the timer to expire */ + SDL_SemWait( fps_limiter_semaphore); + } + } + + + return TRUE; + } + + regMainLoop = FALSE; + return FALSE; +} + + +/** + * A SDL timer callback function. Signals the supplied SDL semaphore + * if its value is small. + * + * @param interval The interval since the last call (in ms) + * @param param The pointer to the semaphore. + * + * @return The interval to the next call (required by SDL) + */ +static Uint32 fps_limiter_fn(Uint32 interval, void *param) +{ + SDL_sem *sdl_semaphore = (SDL_sem *)param; + + /* signal the semaphore if it is getting low */ + if ( SDL_SemValue( sdl_semaphore) < 4) { + SDL_SemPost( sdl_semaphore); + } + + return interval; +} + +static void dui_set_accel_group(gpointer action, gpointer group) { + gtk_action_set_accel_group((GtkAction *)action, (GtkAccelGroup *)group); +} + +/////////////////////////////// MAIN /////////////////////////////// + +static void desmume_gtk_menu_file (GtkWidget *pMenuBar) +{ + GtkWidget *pMenu, *pMenuItem; + + pMenu = gtk_menu_new(); + gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "open"))); + gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "printscreen"))); + gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "quit"))); + + pMenuItem = gtk_menu_item_new_with_label("File"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); +} + +static void changesavetype(GtkCheckMenuItem *checkmenuitem, gpointer type) +{ + if (gtk_check_menu_item_get_active(checkmenuitem)) + mmu_select_savetype(GPOINTER_TO_INT(type), &backupmemorytype, &backupmemorysize); +} + +static void desmume_gtk_menu_emulation_saves (GtkWidget *pMenu, int act_savetype) +{ + GtkWidget *pMenuItem, *pSubmenu, *item; + GSList * list; + + pSubmenu = gtk_menu_new(); + pMenuItem = gtk_menu_item_new_with_label("Saves"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pSubmenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); + + list = NULL; + for (gint i = 0; save_type_names[i] != NULL; i++) + { + item = gtk_radio_menu_item_new_with_label(list, save_type_names[i]); + g_signal_connect(item, "toggled", G_CALLBACK(changesavetype), GINT_TO_POINTER(i)); + list = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(item)); + gtk_menu_shell_append(GTK_MENU_SHELL(pSubmenu), item); + if( i == act_savetype ) + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE); + } +} + +static void desmume_gtk_menu_emulation_frameskip (GtkWidget *pMenu) +{ + GtkWidget *mFrameskip_Radio[MAX_FRAMESKIP]; + GtkWidget *pMenuItem, *pSubmenu; + gchar *buf; + guint i; + + pSubmenu = gtk_menu_new(); + pMenuItem = gtk_menu_item_new_with_label("Frameskip"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pSubmenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); + + for(i = 0; i < MAX_FRAMESKIP; i++) { + buf = g_strdup_printf("%d", i); + if (i>0) + mFrameskip_Radio[i] = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(mFrameskip_Radio[i-1]), buf); + else + mFrameskip_Radio[i] = gtk_radio_menu_item_new_with_label(NULL, buf); + g_free(buf); + g_signal_connect(G_OBJECT(mFrameskip_Radio[i]), "activate", G_CALLBACK(Modify_Frameskip), GINT_TO_POINTER(i)); + gtk_menu_shell_append(GTK_MENU_SHELL(pSubmenu), mFrameskip_Radio[i]); + } + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mFrameskip_Radio[0]), TRUE); +} + +#ifdef BROKEN_SCREENSIZE +static void desmume_gtk_menu_emulation_display_size (GtkWidget *pMenu, gboolean opengl) +{ + GtkWidget *pMenuItem, *pSubmenu; + GtkWidget *mSize_Radio[MAX_SCREENCOEFF]; + gchar *buf; + guint i; + + /* FIXME: this does not work and there's a lot of code that assume the default screen size, drawing function included */ + if (!opengl) { + pSubmenu = gtk_menu_new(); + pMenuItem = gtk_menu_item_new_with_label("Display size"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pSubmenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); + + for(i = 1; i < MAX_SCREENCOEFF; i++) { + buf = g_strdup_printf("x%d", i); + if (i>1) + mSize_Radio[i] = gtk_radio_menu_item_new_with_label_from_widget(GTK_RADIO_MENU_ITEM(mSize_Radio[i-1]), buf); + else + mSize_Radio[i] = gtk_radio_menu_item_new_with_label(NULL, buf); + g_free(buf); + g_signal_connect(G_OBJECT(mSize_Radio[i]), "activate", G_CALLBACK(Modify_ScreenCoeff), GUINT_TO_POINTER(i)); + gtk_menu_shell_append(GTK_MENU_SHELL(pSubmenu), mSize_Radio[i]); + } + } +} +#endif + +static void desmume_gtk_menu_emulation_layers (GtkWidget *pMenu, gboolean opengl) +{ + GtkWidget *pMenuItem, *pSubmenu; + GtkWidget *mLayers_Radio[10]; + const char *Layers_Menu[10] = { + "Main BG 0", + "Main BG 1", + "Main BG 2", + "Main BG 3", + "Main OBJ", + "SUB BG 0", + "SUB BG 1", + "SUB BG 2", + "SUB BG 3", + "SUB OBJ" + }; + guint i; + + pSubmenu = gtk_menu_new(); + pMenuItem = gtk_menu_item_new_with_label("Layers"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pSubmenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); + + for(i = 0; i < 10; i++) { + mLayers_Radio[i] = gtk_check_menu_item_new_with_label(Layers_Menu[i]); + g_signal_connect(G_OBJECT(mLayers_Radio[i]), "activate", G_CALLBACK(Modify_Layer), GUINT_TO_POINTER(i)); + gtk_menu_shell_append(GTK_MENU_SHELL(pSubmenu), mLayers_Radio[i]); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(mLayers_Radio[i]), TRUE); + } +} + +static void desmume_gtk_disable_audio (GtkWidget *widget, gpointer data) +{ + if (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(widget)) == TRUE) { + SPU_ChangeSoundCore(SNDCORE_SDL, 735 * 4); + } else { + SPU_ChangeSoundCore(0, 0); + } +} + +static void desmume_gtk_menu_emulation_disable_audio (GtkWidget *pMenu) +{ + GtkWidget *pMenuItem; + + pMenuItem = gtk_check_menu_item_new_with_label("Enable Audio"); + g_signal_connect(G_OBJECT(pMenuItem), "toggled", G_CALLBACK(desmume_gtk_disable_audio), NULL); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(pMenuItem), TRUE); +} + +static void desmume_gtk_menu_emulation (GtkWidget *pMenuBar, gboolean opengl) +{ + GtkWidget *pMenu, *pMenuItem; + + pMenu = gtk_menu_new(); + pMenuItem = gtk_menu_item_new_with_label("Emulation"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); + + gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "run"))); + gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "pause"))); + gtk_container_add(GTK_CONTAINER(pMenu), gtk_action_create_menu_item(gtk_action_group_get_action(action_group, "reset"))); + + desmume_gtk_menu_emulation_disable_audio(pMenu); + desmume_gtk_menu_emulation_frameskip(pMenu); + desmume_gtk_menu_emulation_layers(pMenu, opengl); +#ifdef BROKEN_SCREENSIZE + desmume_gtk_menu_emulation_display_size(pMenu, opengl); +#endif +} + +static void desmume_gtk_menu_config (GtkWidget *pMenuBar, int act_savetype) +{ + GtkWidget *pMenu, *pMenuItem; + + pMenu = gtk_menu_new(); + pMenuItem = gtk_menu_item_new_with_label("Config"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); + + desmume_gtk_menu_emulation_saves(pMenu, act_savetype); + pMenuItem = gtk_menu_item_new_with_label("Edit controls"); + g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(Edit_Controls), (GtkWidget*) pWindow); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); + +#if 0 + GtkWidget *pSubMenu; + pSubmenu = gtk_menu_new(); + pMenuItem = gtk_menu_item_new_with_label("Firmware"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pSubmenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); + + pMenuItem = gtk_menu_item_new_with_label("Select..."); + g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(SelectFirmwareFile), (gpointer)0); + gtk_menu_shell_append(GTK_MENU_SHELL(pSubmenu), pMenuItem); +#endif +} + +static void desmume_gtk_menu_tools (GtkWidget *pMenuBar) +{ + GtkWidget *pMenu, *pMenuItem; + gint i; + + pMenu = gtk_menu_new(); + for(i = 0; i < dTools_list_size; i++) { + pMenuItem = gtk_menu_item_new_with_label(dTools_list[i]->name); + g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(Start_dTool), GINT_TO_POINTER(i)); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); + } + + pMenuItem = gtk_menu_item_new_with_label("Tools"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); +} + +static void desmume_gtk_menu_help (GtkWidget *pMenuBar) +{ + GtkWidget *pMenu, *pMenuItem; + + pMenu = gtk_menu_new(); + pMenuItem = gtk_image_menu_item_new_from_stock(GTK_STOCK_ABOUT,NULL); + g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(About), (GtkWidget*) pWindow); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem); + + pMenuItem = gtk_menu_item_new_with_label("Help"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu); + gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem); +} + +static void desmume_gtk_toolbar (GtkWidget *pVBox) +{ + GtkWidget *pToolbar; + + pToolbar = gtk_toolbar_new(); + gtk_box_pack_start(GTK_BOX(pVBox), pToolbar, FALSE, FALSE, 0); + + gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "open"))), -1); + gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "run"))), -1); + gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "pause"))), -1); + gtk_toolbar_insert(GTK_TOOLBAR(pToolbar), GTK_TOOL_ITEM(gtk_action_create_tool_item(gtk_action_group_get_action(action_group, "quit"))), -1); +} + +static int +common_gtk_main( struct configured_features *my_config) +{ + SDL_TimerID limiter_timer = NULL; + gchar *config_file; + + GtkAccelGroup * accel_group; + GtkWidget *pVBox; + GtkWidget *pMenuBar; + gint pStatusBar_Ctx; + +#ifdef GTKGLEXT_AVAILABLE + GdkGLConfig *glconfig; + GdkGLContext *glcontext; +#endif +#ifdef GDB_STUB + gdbstub_handle_t arm9_gdb_stub; + gdbstub_handle_t arm7_gdb_stub; +#endif + struct armcpu_memory_iface *arm9_memio = &arm9_base_memory_iface; + struct armcpu_memory_iface *arm7_memio = &arm7_base_memory_iface; + struct armcpu_ctrl_iface *arm9_ctrl_iface; + struct armcpu_ctrl_iface *arm7_ctrl_iface; + + /* the firmware settings */ + struct NDS_fw_config_data fw_config; + + /* default the firmware settings, they may get changed later */ + NDS_FillDefaultFirmwareConfigData( &fw_config); + + /* use any language set on the command line */ + if ( my_config->firmware_language != -1) { + fw_config.language = my_config->firmware_language; + } + + bad_glob_cflash_disk_image_file = my_config->cflash_disk_image_file; + +#ifdef GDB_STUB + if ( my_config->arm9_gdb_port != 0) { + arm9_gdb_stub = createStub_gdb( my_config->arm9_gdb_port, + &arm9_memio, + &arm9_base_memory_iface); + + if ( arm9_gdb_stub == NULL) { + g_printerr("Failed to create ARM9 gdbstub on port %d\n", + my_config->arm9_gdb_port); + exit( -1); + } + } + if ( my_config->arm7_gdb_port != 0) { + arm7_gdb_stub = createStub_gdb( my_config->arm7_gdb_port, + &arm7_memio, + &arm7_base_memory_iface); + + if ( arm7_gdb_stub == NULL) { + g_printerr("Failed to create ARM7 gdbstub on port %d\n", + my_config->arm7_gdb_port); + exit( -1); + } + } +#endif + +#ifdef GTKGLEXT_AVAILABLE + /* Try double-buffered visual */ + glconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)(GDK_GL_MODE_RGB | + GDK_GL_MODE_DEPTH | + GDK_GL_MODE_DOUBLE)); + if (glconfig == NULL) { + g_printerr ("*** Cannot find the double-buffered visual.\n"); + g_printerr ("*** Trying single-buffered visual.\n"); + + /* Try single-buffered visual */ + glconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)(GDK_GL_MODE_RGB | + GDK_GL_MODE_DEPTH)); + if (glconfig == NULL) { + g_printerr ("*** No appropriate OpenGL-capable visual found.\n"); + exit (1); + } + } +#endif + /* FIXME: SDL_INIT_VIDEO is needed for joystick support to work!? + Perhaps it needs a "window" to catch events...? */ + if(SDL_Init(SDL_INIT_TIMER|SDL_INIT_VIDEO) == -1) { + g_printerr("Error trying to initialize SDL: %s\n", + SDL_GetError()); + return 1; + } + desmume_init( arm9_memio, &arm9_ctrl_iface, + arm7_memio, &arm7_ctrl_iface, + my_config->disable_sound); + + /* + * Activate the GDB stubs + * This has to come after the NDS_Init (called in desmume_init) + * where the cpus are set up. + */ +#ifdef GDB_STUB + if ( my_config->arm9_gdb_port != 0) { + activateStub_gdb( arm9_gdb_stub, arm9_ctrl_iface); + } + if ( my_config->arm7_gdb_port != 0) { + activateStub_gdb( arm7_gdb_stub, arm7_ctrl_iface); + } +#endif + + /* Create the dummy firmware */ + NDS_CreateDummyFirmware( &fw_config); + + /* Initialize joysticks */ + if(!init_joy()) return 1; + + dTools_running = (BOOL*)malloc(sizeof(BOOL) * dTools_list_size); + if (dTools_running != NULL) + memset(dTools_running, FALSE, sizeof(BOOL) * dTools_list_size); + + config_file = g_build_filename(g_get_home_dir(), ".desmume.ini", NULL); + Read_ConfigFile(config_file); + + /* Create the window */ + pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(pWindow), "Desmume"); + + gtk_window_set_resizable(GTK_WINDOW (pWindow), my_config->opengl_2d ? TRUE : FALSE); + + gtk_window_set_icon(GTK_WINDOW (pWindow), gdk_pixbuf_new_from_xpm_data(DeSmuME_xpm)); + + g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit), NULL); + g_signal_connect(G_OBJECT(pWindow), "key_press_event", G_CALLBACK(Key_Press), NULL); + g_signal_connect(G_OBJECT(pWindow), "key_release_event", G_CALLBACK(Key_Release), NULL); + + /* Create the GtkVBox */ + pVBox = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(pWindow), pVBox); + + accel_group = gtk_accel_group_new(); + action_group = gtk_action_group_new("dui"); + gtk_action_group_add_actions(action_group, action_entries, sizeof(action_entries) / sizeof(GtkActionEntry), pWindow); + { + GList * list = gtk_action_group_list_actions(action_group); + g_list_foreach(list, dui_set_accel_group, accel_group); + } + gtk_window_add_accel_group(GTK_WINDOW(pWindow), accel_group); + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "pause"), FALSE); + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "run"), FALSE); + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "reset"), FALSE); + gtk_action_set_sensitive(gtk_action_group_get_action(action_group, "printscreen"), FALSE); + + /* Menu and Toolbar */ + pMenuBar = gtk_menu_bar_new(); + + desmume_gtk_menu_file(pMenuBar); + desmume_gtk_menu_emulation(pMenuBar, my_config->opengl_2d); + desmume_gtk_menu_config(pMenuBar, my_config->savetype); + desmume_gtk_menu_tools(pMenuBar); + desmume_gtk_menu_help(pMenuBar); + + gtk_box_pack_start(GTK_BOX(pVBox), pMenuBar, FALSE, FALSE, 0); + + desmume_gtk_toolbar(pVBox); + + /* Creating the place for showing DS screens */ +#ifdef GTKGLEXT_AVAILABLE + if ( my_config->opengl_2d) { + /* + * Create the top screen render area + */ + top_screen_widget = gtk_drawing_area_new(); + gtk_drawing_area_size(GTK_DRAWING_AREA(top_screen_widget), 256, 192); + gtk_widget_set_gl_capability ( top_screen_widget, + glconfig, + NULL, + TRUE, + GDK_GL_RGBA_TYPE); + + g_signal_connect_after (G_OBJECT (top_screen_widget), "realize", + G_CALLBACK (gtk_init_main_gl_area), + NULL); + gtk_widget_set_events( top_screen_widget, GDK_EXPOSURE_MASK); + g_signal_connect( G_OBJECT(top_screen_widget), "expose_event", + G_CALLBACK(top_screen_expose_fn), + &my_config->soft_colour) ; + g_signal_connect( G_OBJECT(top_screen_widget), "configure_event", + G_CALLBACK(common_configure_fn), NULL ) ; + + gtk_box_pack_start(GTK_BOX(pVBox), top_screen_widget, TRUE, TRUE, 0); + + /* realise the topscreen so we can get the openGL context */ + gtk_widget_realize ( top_screen_widget); + glcontext = gtk_widget_get_gl_context( top_screen_widget); + + LOG("Window is direct? %d\n", + gdk_gl_context_is_direct( glcontext)); + + /* + *create the bottom screen drawing area. + */ + bottom_screen_widget = gtk_drawing_area_new(); + gtk_drawing_area_size(GTK_DRAWING_AREA(bottom_screen_widget), 256, 192); + gtk_widget_set_gl_capability ( bottom_screen_widget, + glconfig, + glcontext, + TRUE, + GDK_GL_RGBA_TYPE); + + g_signal_connect_after (G_OBJECT (bottom_screen_widget), "realize", + G_CALLBACK (gtk_init_sub_gl_area), + NULL); + gtk_widget_set_events( bottom_screen_widget, + GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | + GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK ); + g_signal_connect( G_OBJECT(bottom_screen_widget), "expose_event", + G_CALLBACK(bottom_screen_expose_fn), NULL ) ; + g_signal_connect( G_OBJECT(bottom_screen_widget), "configure_event", + G_CALLBACK(common_configure_fn), NULL ) ; + g_signal_connect(G_OBJECT(bottom_screen_widget), "button_press_event", + G_CALLBACK(Stylus_Press), &my_config->opengl_2d); + g_signal_connect(G_OBJECT(bottom_screen_widget), "button_release_event", + G_CALLBACK(Stylus_Release), NULL); + g_signal_connect(G_OBJECT(bottom_screen_widget), "motion_notify_event", + G_CALLBACK(Stylus_Move), &my_config->opengl_2d); + + gtk_box_pack_start(GTK_BOX(pVBox), bottom_screen_widget, TRUE, TRUE, 0); + + /* each frame expose the top screen */ + nds_screen_widget = top_screen_widget; + } else { +#else + { +#endif + pDrawingArea= gtk_drawing_area_new(); + + gtk_drawing_area_size(GTK_DRAWING_AREA(pDrawingArea), 256, 384); + gtk_widget_set_usize (pDrawingArea, 256, 384); + + gtk_widget_set_events(pDrawingArea, + GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | + GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | + GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK ); + + g_signal_connect(G_OBJECT(pDrawingArea), "button_press_event", + G_CALLBACK(Stylus_Press), &my_config->opengl_2d); + g_signal_connect(G_OBJECT(pDrawingArea), "button_release_event", + G_CALLBACK(Stylus_Release), NULL); + g_signal_connect(G_OBJECT(pDrawingArea), "motion_notify_event", + G_CALLBACK(Stylus_Move), &my_config->opengl_2d); + + g_signal_connect( G_OBJECT(pDrawingArea), "expose_event", + G_CALLBACK(gtkFloatExposeEvent), NULL ) ; + + gtk_box_pack_start(GTK_BOX(pVBox), pDrawingArea, FALSE, FALSE, 0); + + nds_screen_widget = pDrawingArea; + } + + /* Status bar */ + pStatusBar = gtk_statusbar_new(); + pStatusBar_Ctx = gtk_statusbar_get_context_id(GTK_STATUSBAR(pStatusBar), "Global"); + pStatusBar_Change("Desmume"); + gtk_box_pack_end(GTK_BOX(pVBox), pStatusBar, FALSE, FALSE, 0); + + gtk_widget_show_all(pWindow); + + //LoadFirmware("fw.bin"); + + gtk_fps_limiter_disabled = my_config->disable_limiter; + if ( !gtk_fps_limiter_disabled) { + /* create the semaphore used for fps limiting */ + fps_limiter_semaphore = SDL_CreateSemaphore( 1); + + /* start a SDL timer for every FPS_LIMITER_FRAME_PERIOD frames to keep us at 60 fps */ + limiter_timer = SDL_AddTimer( 16 * FPS_LIMITER_FRAME_PERIOD, fps_limiter_fn, fps_limiter_semaphore); + if ( limiter_timer == NULL) { + g_printerr("Error trying to start FPS limiter timer: %s\n", + SDL_GetError()); + return 1; + } + } + + /* + * Set the 3D emulation to use + */ + unsigned core = my_config->engine_3d; + /* setup the gdk 3D emulation; GTKGLEXT and LIBOSMESA are exclusive currently */ +#if defined(GTKGLEXT_AVAILABLE) || defined(HAVE_LIBOSMESA) + if(my_config->engine_3d == 2){ +#if defined(GTKGLEXT_AVAILABLE) + core = init_opengl_gdk_3Demu(GDK_DRAWABLE(pWindow->window)) ? 2 : GPU3D_NULL; +#else + core = init_osmesa_3Demu() ? 2 : GPU3D_NULL; +#endif + } +#endif + NDS_3D_ChangeCore(core); + if(my_config->engine_3d != 0 && gpu3D == &gpu3DNull){ + g_printerr("Failed to initialise openGL 3D emulation; " + "removing 3D support\n"); + } + + mmu_select_savetype(my_config->savetype, &backupmemorytype, &backupmemorysize); + + /* Command line arg */ + if( my_config->nds_file != NULL) { + if(Open( my_config->nds_file, bad_glob_cflash_disk_image_file) >= 0) { + if(my_config->load_slot){ + loadstate_slot(my_config->load_slot); + } + + Launch(); + } else { + GtkWidget *pDialog = gtk_message_dialog_new(GTK_WINDOW(pWindow), + GTK_DIALOG_MODAL, + GTK_MESSAGE_INFO, + GTK_BUTTONS_OK, + "Unable to load :\n%s", my_config->nds_file); + gtk_dialog_run(GTK_DIALOG(pDialog)); + gtk_widget_destroy(pDialog); + } + } + + /* Main loop */ + +// gtk_idle_add(&EmuLoop, pWindow); +// g_idle_add(&EmuLoop, pWindow); + + gtk_main(); + + desmume_free(); + + if ( !gtk_fps_limiter_disabled) { + /* tidy up the FPS limiter timer and semaphore */ + SDL_RemoveTimer( limiter_timer); + SDL_DestroySemaphore( fps_limiter_semaphore); + } + + /* Unload joystick */ + uninit_joy(); + + SDL_Quit(); + + Write_ConfigFile(config_file); + g_free(config_file); + +#ifdef GDB_STUB + if ( my_config->arm9_gdb_port != 0) { + destroyStub_gdb( arm9_gdb_stub); + } + if ( my_config->arm7_gdb_port != 0) { + destroyStub_gdb( arm7_gdb_stub); + } +#endif + + return EXIT_SUCCESS; +} + + +int +main (int argc, char *argv[]) +{ + struct configured_features my_config; + + init_configured_features( &my_config); + + if (!g_thread_supported()) + g_thread_init( NULL); + + gtk_init(&argc, &argv); + +#ifdef GTKGLEXT_AVAILABLE + gtk_gl_init( &argc, &argv); +#endif + + if ( !fill_configured_features( &my_config, argc, argv)) { + exit(0); + } + + return common_gtk_main( &my_config); +} + +#ifdef WIN32 +int WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) +{ + int argc = 0; + char *argv[] = NULL; + + /* + * FIXME: + * Emulate the argc and argv main parameters. Could do this using + * CommandLineToArgvW and then convert the wide chars to thin chars. + * Or parse the wide chars directly and call common_gtk_main with a + * filled configuration structure. + */ + main( argc, argv); +} +#endif + diff --git a/desmume/src/gtk/osmesa_3Demu.cpp b/src/gtk/osmesa_3Demu.cpp similarity index 100% rename from desmume/src/gtk/osmesa_3Demu.cpp rename to src/gtk/osmesa_3Demu.cpp diff --git a/desmume/src/gtk/osmesa_3Demu.h b/src/gtk/osmesa_3Demu.h similarity index 100% rename from desmume/src/gtk/osmesa_3Demu.h rename to src/gtk/osmesa_3Demu.h diff --git a/desmume/src/gtk/tools/ioregsView.cpp b/src/gtk/tools/ioregsView.cpp similarity index 99% rename from desmume/src/gtk/tools/ioregsView.cpp rename to src/gtk/tools/ioregsView.cpp index c701b4791..8bbc236f4 100644 --- a/desmume/src/gtk/tools/ioregsView.cpp +++ b/src/gtk/tools/ioregsView.cpp @@ -20,7 +20,6 @@ */ #include -#include #include "../dTool.h" #include "../MMU.h" @@ -399,7 +398,6 @@ static int DTOOL_ID; static void close() { - memset(current_reg, 0, sizeof(current_reg)); dTool_CloseCallback(DTOOL_ID); } diff --git a/desmume/src/gtk/tools/ioregsView.h b/src/gtk/tools/ioregsView.h similarity index 100% rename from desmume/src/gtk/tools/ioregsView.h rename to src/gtk/tools/ioregsView.h diff --git a/desmume/src/instruction_tabdef.inc b/src/instruction_tabdef.inc similarity index 100% rename from desmume/src/instruction_tabdef.inc rename to src/instruction_tabdef.inc diff --git a/desmume/src/matrix.cpp b/src/matrix.cpp similarity index 99% rename from desmume/src/matrix.cpp rename to src/matrix.cpp index d9c3bd780..0e9f4f25b 100644 --- a/desmume/src/matrix.cpp +++ b/src/matrix.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include "matrix.h" extern "C" { @@ -34,7 +33,7 @@ void MatrixInit (float *matrix) matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.f; } -#ifdef NOSSE2 +#ifndef SSE2 void MATRIXFASTCALL MatrixMultVec4x4 (const float *matrix, float *vecPtr) { float x = vecPtr[0]; @@ -214,7 +213,6 @@ float * MatrixStackPopMatrix (MatrixStack *stack, int size) float * MatrixStackGetPos (MatrixStack *stack, int pos) { - assert(pos<31); return &stack->matrix[pos*16]; } @@ -225,7 +223,6 @@ float * MatrixStackGet (MatrixStack *stack) void MatrixStackLoadMatrix (MatrixStack *stack, int pos, const float *ptr) { - assert(pos<31); MatrixCopy (&stack->matrix[pos*16], ptr); } diff --git a/desmume/src/matrix.h b/src/matrix.h similarity index 74% rename from desmume/src/matrix.h rename to src/matrix.h index bbb3ee6f8..13afc4da9 100644 --- a/desmume/src/matrix.h +++ b/src/matrix.h @@ -41,28 +41,11 @@ void MatrixInit (float *matrix); #define MATRIXFASTCALL #endif -//In order to conditionally use these asm optimized functions in visual studio -//without having to make new build types to exclude the assembly files. -//a bit sloppy, but there aint much to it -#ifndef NOSSE2 -#define SSE2_FUNC(X) _sse2_##X -#define MatrixMultVec4x4 _sse2_MatrixMultVec4x4 -#define MatrixMultVec3x3 _sse2_MatrixMultVec3x3 -#define MatrixMultiply _sse2_MatrixMultiply -#define MatrixTranslate _sse2_MatrixTranslate -#define MatrixScale _sse2_MatrixScale -#else -#define SSE2_FUNC(X) X -#endif - -void MATRIXFASTCALL SSE2_FUNC(MatrixMultVec3x3) (const float * matrix, float * vecPtr); -void MATRIXFASTCALL SSE2_FUNC(MatrixMultVec4x4) (const float * matrix, float * vecPtr); -void MATRIXFASTCALL SSE2_FUNC(MatrixMultiply) (float * matrix, const float * rightMatrix); -void MATRIXFASTCALL SSE2_FUNC(MatrixTranslate) (float *matrix, const float *ptr); -void MATRIXFASTCALL SSE2_FUNC(MatrixScale) (float * matrix, const float * ptr); - - - +void MATRIXFASTCALL MatrixMultVec3x3 (const float * matrix, float * vecPtr); +void MATRIXFASTCALL MatrixMultVec4x4 (const float * matrix, float * vecPtr); +void MATRIXFASTCALL MatrixMultiply (float * matrix, const float * rightMatrix); +void MATRIXFASTCALL MatrixTranslate (float *matrix, const float *ptr); +void MATRIXFASTCALL MatrixScale (float * matrix, const float * ptr); float MATRIXFASTCALL MatrixGetMultipliedIndex (int index, float *matrix, float *rightMatrix); void MATRIXFASTCALL MatrixSet (float *matrix, int x, int y, float value); void MATRIXFASTCALL MatrixCopy (float * matrixDST, const float * matrixSRC); diff --git a/desmume/src/matrix_sse2-x64.asm b/src/matrix_sse2-x64.asm similarity index 100% rename from desmume/src/matrix_sse2-x64.asm rename to src/matrix_sse2-x64.asm diff --git a/desmume/src/matrix_sse2-x86.asm b/src/matrix_sse2-x86.asm similarity index 89% rename from desmume/src/matrix_sse2-x86.asm rename to src/matrix_sse2-x86.asm index 668e488c1..067881592 100644 --- a/desmume/src/matrix_sse2-x86.asm +++ b/src/matrix_sse2-x86.asm @@ -24,7 +24,7 @@ .model flat .code -@_sse2_MatrixMultVec4x4@8 PROC PUBLIC +@MatrixMultVec4x4@8 PROC PUBLIC movaps xmm0, XMMWORD PTR [ecx] movaps xmm1, XMMWORD PTR [ecx+16] movaps xmm2, XMMWORD PTR [ecx+32] @@ -46,9 +46,9 @@ addps xmm4, xmm7 movaps XMMWORD PTR [edx], xmm4 ret 0 -@_sse2_MatrixMultVec4x4@8 ENDP +@MatrixMultVec4x4@8 ENDP -@_sse2_MatrixMultVec3x3@8 PROC PUBLIC +@MatrixMultVec3x3@8 PROC PUBLIC movaps xmm0, XMMWORD PTR [ecx] movaps xmm1, XMMWORD PTR [ecx+16] movaps xmm2, XMMWORD PTR [ecx+32] @@ -66,9 +66,9 @@ addps xmm4, xmm6 movaps XMMWORD PTR [edx], xmm4 ret 0 -@_sse2_MatrixMultVec3x3@8 ENDP +@MatrixMultVec3x3@8 ENDP -@_sse2_MatrixMultiply@8 PROC PUBLIC +@MatrixMultiply@8 PROC PUBLIC movaps xmm0, XMMWORD PTR [ecx] movaps xmm1, XMMWORD PTR [ecx+16] movaps xmm2, XMMWORD PTR [ecx+32] @@ -138,9 +138,9 @@ addps xmm4,xmm7 movaps XMMWORD PTR [ecx+48],xmm4 ret 0 -@_sse2_MatrixMultiply@8 ENDP +@MatrixMultiply@8 ENDP -@_sse2_MatrixTranslate@8 PROC PUBLIC +@MatrixTranslate@8 PROC PUBLIC movaps xmm0, XMMWORD PTR [ecx] movaps xmm1, XMMWORD PTR [ecx+16] movaps xmm2, XMMWORD PTR [ecx+32] @@ -160,9 +160,9 @@ addps xmm4, xmm3 movaps XMMWORD PTR [ecx+48], xmm4 ret 0 -@_sse2_MatrixTranslate@8 ENDP +@MatrixTranslate@8 ENDP -@_sse2_MatrixScale@8 PROC PUBLIC +@MatrixScale@8 PROC PUBLIC movaps xmm0, XMMWORD PTR [ecx] movaps xmm1, XMMWORD PTR [ecx+16] movaps xmm2, XMMWORD PTR [ecx+32] @@ -179,7 +179,7 @@ movaps XMMWORD PTR [ecx+16],xmm5 movaps XMMWORD PTR [ecx+32],xmm6 ret 0 -@_sse2_MatrixScale@8 ENDP +@MatrixScale@8 ENDP end diff --git a/desmume/src/mc.cpp b/src/mc.cpp similarity index 100% rename from desmume/src/mc.cpp rename to src/mc.cpp diff --git a/desmume/src/mc.h b/src/mc.h similarity index 100% rename from desmume/src/mc.h rename to src/mc.h diff --git a/desmume/src/mem.h b/src/mem.h similarity index 95% rename from desmume/src/mem.h rename to src/mem.h index 10a01690e..62058a5f4 100644 --- a/desmume/src/mem.h +++ b/src/mem.h @@ -31,12 +31,12 @@ static INLINE u8 T1ReadByte(u8 * mem, u32 addr) return mem[addr]; } -static INLINE u16 T1ReadWord(void * mem, u32 addr) +static INLINE u16 T1ReadWord(u8 * mem, u32 addr) { #ifdef WORDS_BIGENDIAN - return (((u8*)mem)[addr + 1] << 8) | ((u8*)mem)[addr]; + return (mem[addr + 1] << 8) | mem[addr]; #else - return *((u16 *) ((u8*)mem + addr)); + return *((u16 *) (mem + addr)); #endif } diff --git a/desmume/src/memorystream.h b/src/memorystream.h similarity index 100% rename from desmume/src/memorystream.h rename to src/memorystream.h diff --git a/desmume/src/mic.cpp b/src/mic.cpp similarity index 57% rename from desmume/src/mic.cpp rename to src/mic.cpp index afee6dd44..e072b8a11 100644 --- a/desmume/src/mic.cpp +++ b/src/mic.cpp @@ -3,8 +3,6 @@ #include "types.h" #include "mic.h" -static BOOL silence = TRUE; - BOOL Mic_Init() { return TRUE; @@ -20,15 +18,7 @@ void Mic_DeInit() u8 Mic_ReadSample() { - if (silence) - return 0; - - return 150; -} - -void Mic_DoNoise(BOOL noise) -{ - silence = !noise; + return 0; } #endif diff --git a/desmume/src/mic.h b/src/mic.h similarity index 89% rename from desmume/src/mic.h rename to src/mic.h index 8632f39e0..06c3c9a12 100644 --- a/desmume/src/mic.h +++ b/src/mic.h @@ -6,8 +6,6 @@ extern int MicButtonPressed; static char MicSampleName[256]; char* LoadSample(const char *name); extern int MicDisplay; -#else -void Mic_DoNoise(BOOL); #endif BOOL Mic_Init(); diff --git a/desmume/src/movie.cpp b/src/movie.cpp similarity index 100% rename from desmume/src/movie.cpp rename to src/movie.cpp diff --git a/desmume/src/movie.h b/src/movie.h similarity index 100% rename from desmume/src/movie.h rename to src/movie.h diff --git a/desmume/src/rasterize.cpp b/src/rasterize.cpp similarity index 86% rename from desmume/src/rasterize.cpp rename to src/rasterize.cpp index 1401e7ec8..87971143e 100644 --- a/desmume/src/rasterize.cpp +++ b/src/rasterize.cpp @@ -63,7 +63,6 @@ template T _min(T a, T b, T c, T d) { return min(_min(a,b,d),c); } template T _max(T a, T b, T c, T d) { return max(_max(a,b,d),c); } static int polynum; -static bool validFramebuffer = false; static u8 modulate_table[32][32]; static u8 decal_table[32][32][32]; @@ -203,16 +202,16 @@ struct PolyAttr } polyAttr; -union FragmentColor { - u32 color; - struct { - //#ifdef WORDS_BIGENDIAN ? - u8 r,g,b,a; - }; -}; - struct Fragment { + union Color { + u32 color; + struct { + //#ifdef WORDS_BIGENDIAN ? + u8 r,g,b,a; + } components; + } color; + u32 depth; struct { @@ -221,7 +220,7 @@ struct Fragment u8 stencil; - u8 pad; + u8 pad[5]; }; static VERT* verts[MAX_CLIPPED_VERTS]; @@ -232,8 +231,6 @@ INLINE static void SubmitVertex(int vert_index, VERT& rawvert) } static Fragment screen[256*192]; -static FragmentColor screenColor[256*192]; - FORCEINLINE int iround(float f) { return (int)f; //lol @@ -303,7 +300,7 @@ static struct Sampler } } - FORCEINLINE FragmentColor sample(float u, float v) + FORCEINLINE Fragment::Color sample(float u, float v) { //finally, we can use floor here. but, it is slower than we want. //the best solution is probably to wait until the pipeline is full of fixed point @@ -311,8 +308,13 @@ static struct Sampler int iv = floorf(v); dowrap(iu,iv); - FragmentColor color; - color.color = ((u32*)textures.currentData)[(iv<>= 3; + col32 &= 0x1F1F1F1F; + color.color = col32; + return color; } @@ -330,11 +332,11 @@ struct Shader } float invu, invv, w; - FragmentColor materialColor; + Fragment::Color materialColor; - FORCEINLINE void shade(FragmentColor& dst) + FORCEINLINE void shade(Fragment& dst) { - FragmentColor texColor; + Fragment::Color texColor; float u,v; switch(mode) @@ -343,19 +345,19 @@ struct Shader u = invu*w; v = invv*w; texColor = sampler.sample(u,v); - dst.r = modulate_table[texColor.r][materialColor.r]; - dst.g = modulate_table[texColor.g][materialColor.g]; - dst.b = modulate_table[texColor.b][materialColor.b]; - dst.a = modulate_table[texColor.a][materialColor.a]; + dst.color.components.r = modulate_table[texColor.components.r][materialColor.components.r]; + dst.color.components.g = modulate_table[texColor.components.g][materialColor.components.g]; + dst.color.components.b = modulate_table[texColor.components.b][materialColor.components.b]; + dst.color.components.a = modulate_table[texColor.components.a][materialColor.components.a]; //dst.color.components.a = 31; //#ifdef _MSC_VER //if(GetAsyncKeyState(VK_SHIFT)) { // //debugging tricks - // dst = materialColor; + // dst.color = materialColor; // if(GetAsyncKeyState(VK_TAB)) { - // u8 alpha = dst.a; - // dst.color = polynum*8+8; - // dst.a = alpha; + // u8 alpha = dst.color.components.a; + // dst.color.color = polynum*8+8; + // dst.color.components.a = alpha; // } //} //#endif @@ -364,37 +366,37 @@ struct Shader u = invu*w; v = invv*w; texColor = sampler.sample(u,v); - dst.r = decal_table[texColor.a][texColor.r][materialColor.r]; - dst.g = decal_table[texColor.a][texColor.g][materialColor.g]; - dst.b = decal_table[texColor.a][texColor.b][materialColor.b]; - dst.a = materialColor.a; + dst.color.components.r = decal_table[texColor.components.a][texColor.components.r][materialColor.components.r]; + dst.color.components.g = decal_table[texColor.components.a][texColor.components.g][materialColor.components.g]; + dst.color.components.b = decal_table[texColor.components.a][texColor.components.b][materialColor.components.b]; + dst.color.components.a = materialColor.components.a; break; case 2: //toon/highlight shading u = invu*w; v = invv*w; texColor = sampler.sample(u,v); - u32 toonColorVal; toonColorVal = gfx3d.rgbToonTable[materialColor.r]; - FragmentColor toonColor; - toonColor.r = ((toonColorVal & 0x0000FF) >> 3); - toonColor.g = ((toonColorVal & 0x00FF00) >> 11); - toonColor.b = ((toonColorVal & 0xFF0000) >> 19); - dst.r = modulate_table[texColor.r][toonColor.r]; - dst.g = modulate_table[texColor.g][toonColor.g]; - dst.b = modulate_table[texColor.b][toonColor.b]; - dst.a = modulate_table[texColor.a][materialColor.a]; + u32 toonColorVal; toonColorVal = gfx3d.rgbToonTable[materialColor.components.r]; + Fragment::Color toonColor; + toonColor.components.r = ((toonColorVal & 0x0000FF) >> 3); + toonColor.components.g = ((toonColorVal & 0x00FF00) >> 11); + toonColor.components.b = ((toonColorVal & 0xFF0000) >> 19); + dst.color.components.r = modulate_table[texColor.components.r][toonColor.components.r]; + dst.color.components.g = modulate_table[texColor.components.g][toonColor.components.g]; + dst.color.components.b = modulate_table[texColor.components.b][toonColor.components.b]; + dst.color.components.a = modulate_table[texColor.components.a][materialColor.components.a]; if(gfx3d.shading == GFX3D::HIGHLIGHT) { - dst.r = min(31, (dst.r + toonColor.r)); - dst.g = min(31, (dst.g + toonColor.g)); - dst.b = min(31, (dst.b + toonColor.b)); + dst.color.components.r = min(31, (dst.color.components.r + toonColor.components.r)); + dst.color.components.g = min(31, (dst.color.components.g + toonColor.components.g)); + dst.color.components.b = min(31, (dst.color.components.b + toonColor.components.b)); } break; case 3: //shadows //is this right? only with the material color? - dst = materialColor; + dst.color = materialColor; break; case 4: //our own special mode which only uses the material color (for when texturing is disabled) - dst = materialColor; + dst.color = materialColor; break; } @@ -402,45 +404,44 @@ struct Shader } shader; -static FORCEINLINE void alphaBlend(FragmentColor & dst, const FragmentColor & src) +static FORCEINLINE void alphaBlend(Fragment::Color & dst, const Fragment::Color & src) { if(gfx3d.enableAlphaBlending) { - if(src.a == 0) + if(src.components.a == 0) { - dst.a = max(src.a,dst.a); + dst.components.a = max(src.components.a,dst.components.a); } - else if(src.a == 31 || dst.a == 0) + else if(src.components.a == 31 || dst.components.a == 0) { - dst = src; - dst.a = max(src.a,dst.a); + dst.color = src.color; + dst.components.a = max(src.components.a,dst.components.a); } else { - u8 alpha = src.a+1; + u8 alpha = src.components.a+1; u8 invAlpha = 32 - alpha; - dst.r = (alpha*src.r + invAlpha*dst.r)>>5; - dst.g = (alpha*src.g + invAlpha*dst.g)>>5; - dst.b = (alpha*src.b + invAlpha*dst.b)>>5; - dst.a = max(src.a,dst.a); + dst.components.r = (alpha*src.components.r + invAlpha*dst.components.r)>>5; + dst.components.g = (alpha*src.components.g + invAlpha*dst.components.g)>>5; + dst.components.b = (alpha*src.components.b + invAlpha*dst.components.b)>>5; + dst.components.a = max(src.components.a,dst.components.a); } } else { - if(src.a == 0) + if(src.components.a == 0) { //do nothing; the fragment is totally transparent } else { - dst = src; + dst.color = src.color; } } } static FORCEINLINE void pixel(int adr,float r, float g, float b, float invu, float invv, float w, float z) { Fragment &destFragment = screen[adr]; - FragmentColor &destFragmentColor = screenColor[adr]; //depth test u32 depth; @@ -482,25 +483,25 @@ static FORCEINLINE void pixel(int adr,float r, float g, float b, float invu, flo //this is a HACK: //we are being very sloppy with our interpolation precision right now //and rather than fix it, i just want to clamp it - shader.materialColor.r = max(0,min(31,(int)r)); - shader.materialColor.g = max(0,min(31,(int)g)); - shader.materialColor.b = max(0,min(31,(int)b)); + shader.materialColor.components.r = max(0,min(31,(int)r)); + shader.materialColor.components.g = max(0,min(31,(int)g)); + shader.materialColor.components.b = max(0,min(31,(int)b)); - shader.materialColor.a = polyAttr.alpha; + shader.materialColor.components.a = polyAttr.alpha; //pixel shader - FragmentColor shaderOutput; + Fragment shaderOutput; shader.shade(shaderOutput); //alpha test if(gfx3d.enableAlphaTest) { - if(shaderOutput.a < gfx3d.alphaTestRef) + if(shaderOutput.color.components.a < gfx3d.alphaTestRef) goto rejected_fragment; } //we shouldnt do any of this if we generated a totally transparent pixel - if(shaderOutput.a != 0) + if(shaderOutput.color.components.a != 0) { //handle shadow polys if(shader.mode == 3) @@ -537,7 +538,7 @@ static FORCEINLINE void pixel(int adr,float r, float g, float b, float invu, flo } //handle polyids - bool isOpaquePixel = shaderOutput.a == 31; + bool isOpaquePixel = shaderOutput.color.components.a == 31; if(isOpaquePixel) { destFragment.polyid.opaque = polyAttr.polyid; @@ -565,7 +566,7 @@ static FORCEINLINE void pixel(int adr,float r, float g, float b, float invu, flo } //alpha blending and write color - alphaBlend(destFragmentColor, shaderOutput); + alphaBlend(destFragment.color, shaderOutput.color); //depth writing if(isOpaquePixel || polyAttr.translucentDepthWrite) @@ -929,9 +930,7 @@ static char SoftRastInit(void) return 1; } -static void SoftRastReset() { - validFramebuffer = false; -} +static void SoftRastReset() {} static void SoftRastClose() { @@ -941,41 +940,45 @@ static void SoftRastVramReconfigureSignal() { TexCache_Invalidate(); } -static void SoftRastConvertFramebuffer() +static void SoftRastGetLine(int line, u16* dst, u8* dstAlpha) { - FragmentColor* src = screenColor; - u16* dst = gfx3d_convertedScreen; - u8* dstAlpha = gfx3d_convertedAlpha; - - //in an effort to speed this up, the misc pixel buffers and the color buffer were separated. - - for(int i=0,y=0;y<192;y++) + Fragment* src = screen+((line)<<8); + for(int i=0;i<256;i++) { - #ifndef NOSSE2 - u8* wanx = (u8*)&src[i]; - #define ASS(X,Y) __asm { prefetchnta [wanx+32*0x##X##Y] } - #define PUNK(X) ASS(X,0) ASS(X,1) ASS(X,2) ASS(X,3) ASS(X,4) ASS(X,5) ASS(X,6) ASS(X,7) ASS(X,8) ASS(X,9) ASS(X,A) ASS(X,B) ASS(X,C) ASS(X,D) ASS(X,E) ASS(X,F) - PUNK(0); PUNK(1); - #endif + const bool testRenderAlpha = false; + u8 r = src->color.components.r; + u8 g = src->color.components.g; + u8 b = src->color.components.b; + *dst = R5G5B5TORGB15(r,g,b); + if(src->color.components.a > 0) + *dst |= 0x8000; + *dstAlpha = alpha_5bit_to_4bit[src->color.components.a]; - for(int x=0;x<256;x++,i++) + if(testRenderAlpha) { - const u8 r = src[i].r; - const u8 g = src[i].g; - const u8 b = src[i].b; - const u8 a = src[i].a; - dst[i] = R5G5B5TORGB15(r,g,b) | alpha_lookup[a]; - dstAlpha[i] = alpha_5bit_to_4bit[a]; + *dst = 0x8000 | R5G5B5TORGB15(src->color.components.a,src->color.components.a,src->color.components.a); + *dstAlpha = 16; } + + src++; + dst++; + dstAlpha++; } - validFramebuffer = true; + } -static void SoftRastCheckFresh() -{ - if(!validFramebuffer) +static void SoftRastGetLineCaptured(int line, u16* dst) { + Fragment* src = screen+((line)<<8); + for(int i=0;i<256;i++) { - SoftRastConvertFramebuffer(); + u8 r = src->color.components.r; + u8 g = src->color.components.g; + u8 b = src->color.components.b; + *dst = R5G5B5TORGB15(r,g,b); + if(src->color.components.a > 0) + *dst |= 0x8000; + src++; + dst++; } } @@ -1155,11 +1158,10 @@ static void clipPoly(POLY* poly) static void SoftRastRender() { Fragment clearFragment; - FragmentColor clearFragmentColor; - clearFragmentColor.r = gfx3d.clearColor&0x1F; - clearFragmentColor.g = (gfx3d.clearColor>>5)&0x1F; - clearFragmentColor.b = (gfx3d.clearColor>>10)&0x1F; - clearFragmentColor.a = (gfx3d.clearColor>>16)&0x1F; + clearFragment.color.components.r = gfx3d.clearColor&0x1F; + clearFragment.color.components.g = (gfx3d.clearColor>>5)&0x1F; + clearFragment.color.components.b = (gfx3d.clearColor>>10)&0x1F; + clearFragment.color.components.a = (gfx3d.clearColor>>16)&0x1F; clearFragment.polyid.opaque = (gfx3d.clearColor>>24)&0x3F; //special value for uninitialized translucent polyid. without this, fires in spiderman2 dont display //I am not sure whether it is right, though. previously this was cleared to 0, as a guess, @@ -1169,8 +1171,6 @@ static void SoftRastRender() clearFragment.stencil = 0; for(int i=0;i<256*192;i++) screen[i] = clearFragment; - for(int i=0;i<256*192;i++) - screenColor[i] = clearFragmentColor; //convert colors to float to get more precision in case we need it for(int i=0;icount;i++) @@ -1269,7 +1269,7 @@ static void SoftRastRender() if(needInitTexture || lastTextureFormat != poly->texParam || lastTexturePalette != poly->texPalette) { - TexCache_SetTexture(poly->texParam,poly->texPalette); + TexCache_SetTexture(poly->texParam,poly->texPalette); sampler.setup(poly->texParam); lastTextureFormat = poly->texParam; lastTexturePalette = poly->texPalette; @@ -1292,9 +1292,8 @@ static void SoftRastRender() shape_engine(type,!polyAttr.backfacing); } - validFramebuffer = false; - // printf("rendered %d of %d polys after backface culling\n",gfx3d.polylist->count-culled,gfx3d.polylist->count); + } GPU3DInterface gpu3DRasterize = { @@ -1304,5 +1303,6 @@ GPU3DInterface gpu3DRasterize = { SoftRastClose, SoftRastRender, SoftRastVramReconfigureSignal, - SoftRastCheckFresh, + SoftRastGetLine, + SoftRastGetLineCaptured }; diff --git a/desmume/src/rasterize.h b/src/rasterize.h similarity index 100% rename from desmume/src/rasterize.h rename to src/rasterize.h diff --git a/desmume/src/readwrite.cpp b/src/readwrite.cpp similarity index 100% rename from desmume/src/readwrite.cpp rename to src/readwrite.cpp diff --git a/desmume/src/readwrite.h b/src/readwrite.h similarity index 100% rename from desmume/src/readwrite.h rename to src/readwrite.h diff --git a/desmume/src/registers.h b/src/registers.h similarity index 100% rename from desmume/src/registers.h rename to src/registers.h diff --git a/desmume/src/render3D.cpp b/src/render3D.cpp similarity index 88% rename from desmume/src/render3D.cpp rename to src/render3D.cpp index 9c2bb7a17..8ef8c0c50 100644 --- a/desmume/src/render3D.cpp +++ b/src/render3D.cpp @@ -24,6 +24,8 @@ int cur3DCore = GPU3D_NULL; static void NDS_nullFunc1 (void){} static char NDS_nullFunc2 (void){ return 1; } +static void NDS_nullFunc3 (int,unsigned short*) {} +static void NDS_nullFunc4 (int,unsigned short*,unsigned char*) {} GPU3DInterface gpu3DNull = { "None", @@ -32,7 +34,8 @@ GPU3DInterface gpu3DNull = { NDS_nullFunc1, //NDS_3D_Close NDS_nullFunc1, //NDS_3D_Render NDS_nullFunc1, //NDS_3D_VramReconfigureSignal - NDS_nullFunc1, //NDS_3D_CheckFresh + NDS_nullFunc4, //NDS_3D_GetLine + NDS_nullFunc3 //NDS_3D_GetLineCaptured }; GPU3DInterface *gpu3D = &gpu3DNull; diff --git a/desmume/src/render3D.h b/src/render3D.h similarity index 87% rename from desmume/src/render3D.h rename to src/render3D.h index a6d32fbdc..8df9133c4 100644 --- a/desmume/src/render3D.h +++ b/src/render3D.h @@ -21,8 +21,6 @@ #ifndef RENDER3D_H #define RENDER3D_H -#include "types.h" - //not using this right now #define CALL_CONVENTION @@ -46,9 +44,13 @@ typedef struct Render3DInterface //called when the emulator reconfigures its vram. you may need to invalidate your texture cache. void (CALL_CONVENTION* NDS_3D_VramReconfigureSignal) (); - //ensures that the plugin's framebuffer generation is fresh - void (CALL_CONVENTION* NDS_3D_CheckFresh) (); + //Retrieves a line of color buffer data + void (CALL_CONVENTION* NDS_3D_GetLine) (int line, unsigned short* dst, unsigned char* dstAlpha); + //Retrieves a line of color buffer data for capture + void (CALL_CONVENTION* NDS_3D_GetLineCaptured) (int line, unsigned short* dst); + + } GPU3DInterface; extern int cur3DCore; diff --git a/desmume/src/rtc.cpp b/src/rtc.cpp similarity index 100% rename from desmume/src/rtc.cpp rename to src/rtc.cpp diff --git a/desmume/src/rtc.h b/src/rtc.h similarity index 100% rename from desmume/src/rtc.h rename to src/rtc.h diff --git a/desmume/src/saves.cpp b/src/saves.cpp similarity index 99% rename from desmume/src/saves.cpp rename to src/saves.cpp index 5bd5da886..38ab97f14 100644 --- a/desmume/src/saves.cpp +++ b/src/saves.cpp @@ -383,12 +383,12 @@ static bool cp15_loadstate(std::istream* is) static char * format_time(time_t cal_time) { struct tm *time_struct; - static char str[64]; + static char string[30]; time_struct=localtime(&cal_time); - strftime(str, sizeof str, "%d-%b-%Y %H:%M:%S", time_struct); + strftime(string, sizeof string, "%Y-%m-%d %H:%M", time_struct); - return(str); + return(string); } void clear_savestates() @@ -828,7 +828,7 @@ static bool savestate_load(std::istream* is) //while the series of resets below should work, //we are testing the robustness of the savestate system with this full reset. //the full reset wipes more things, so we can make sure that they are being restored correctly - NDS_Reset(TRUE); + NDS_Reset(); //reset some options to their old defaults which werent saved nds.debugConsole = FALSE; diff --git a/desmume/src/saves.h b/src/saves.h similarity index 100% rename from desmume/src/saves.h rename to src/saves.h diff --git a/desmume/src/shaders.h b/src/shaders.h similarity index 100% rename from desmume/src/shaders.h rename to src/shaders.h diff --git a/desmume/src/sndsdl.cpp b/src/sndsdl.cpp similarity index 100% rename from desmume/src/sndsdl.cpp rename to src/sndsdl.cpp diff --git a/desmume/src/sndsdl.h b/src/sndsdl.h similarity index 100% rename from desmume/src/sndsdl.h rename to src/sndsdl.h diff --git a/desmume/src/softrender.cpp b/src/softrender.cpp similarity index 100% rename from desmume/src/softrender.cpp rename to src/softrender.cpp diff --git a/desmume/src/softrender.h b/src/softrender.h similarity index 100% rename from desmume/src/softrender.h rename to src/softrender.h diff --git a/desmume/src/softrender_config.h b/src/softrender_config.h similarity index 100% rename from desmume/src/softrender_config.h rename to src/softrender_config.h diff --git a/desmume/src/softrender_desmumefont.h b/src/softrender_desmumefont.h similarity index 100% rename from desmume/src/softrender_desmumefont.h rename to src/softrender_desmumefont.h diff --git a/desmume/src/softrender_v3sysfont.h b/src/softrender_v3sysfont.h similarity index 100% rename from desmume/src/softrender_v3sysfont.h rename to src/softrender_v3sysfont.h diff --git a/desmume/src/texcache.cpp b/src/texcache.cpp similarity index 88% rename from desmume/src/texcache.cpp rename to src/texcache.cpp index 0adfac384..1f14115ed 100644 --- a/desmume/src/texcache.cpp +++ b/src/texcache.cpp @@ -12,7 +12,6 @@ using std::min; using std::max; -//only dump this from ogl renderer. for now, softrasterizer creates things in an incompatible pixel format //#define DEBUG_DUMP_TEXTURE //This class represents a number of regions of memory which should be viewed as contiguous @@ -151,11 +150,7 @@ static void DebugDumpTexture(int which) static int lastTexture = -1; - -#define CONVERT(color,alpha) ((TEXFORMAT == TexFormat_32bpp)?(RGB15TO32(color,alpha)):RGB15TO5555(color,alpha)) - -template -void TexCache_SetTexture(u32 format, u32 texpal) +void TexCache_SetTexture(unsigned int format, unsigned int texpal) { //for each texformat, number of palette entries const int palSizes[] = {0, 32, 4, 16, 256, 0, 8, 0}; @@ -314,8 +309,7 @@ REJECT: //INFO("Texture %03i - format=%08X; pal=%04X (mode %X, width %04i, height %04i)\n",i, texcache[i].frm, texcache[i].pal, texcache[i].mode, sizeX, sizeY); //============================================================================ Texture conversion - const u32 opaqueColor = TEXFORMAT==TexFormat_32bpp?255:31; - u32 palZeroTransparent = (1-((format>>29)&1))*opaqueColor; + u32 palZeroTransparent = (1-((format>>29)&1))*255; // shash: CONVERT THIS TO A TABLE :) switch (texcache[tx].mode) { @@ -327,10 +321,7 @@ REJECT: { u16 c = pal[*adr&31]; u8 alpha = *adr>>5; - if(TEXFORMAT == TexFormat_15bpp) - *dwdst++ = RGB15TO5555(c,material_3bit_to_5bit[alpha]); - else - *dwdst++ = RGB15TO32(c,material_3bit_to_8bit[alpha]); + *dwdst++ = RGB15TO32(c,material_3bit_to_8bit[alpha]); adr++; } } @@ -348,19 +339,19 @@ REJECT: bits = (*adr)&0x3; c = pal[bits]; - *dwdst++ = CONVERT(c,(bits == 0) ? palZeroTransparent : opaqueColor); + *dwdst++ = RGB15TO32(c,(bits == 0) ? palZeroTransparent : 255); bits = ((*adr)>>2)&0x3; c = pal[bits]; - *dwdst++ = CONVERT(c,(bits == 0) ? palZeroTransparent : opaqueColor); + *dwdst++ = RGB15TO32(c,(bits == 0) ? palZeroTransparent : 255); bits = ((*adr)>>4)&0x3; c = pal[bits]; - *dwdst++ = CONVERT(c,(bits == 0) ? palZeroTransparent : opaqueColor); + *dwdst++ = RGB15TO32(c,(bits == 0) ? palZeroTransparent : 255); bits = ((*adr)>>6)&0x3; c = pal[bits]; - *dwdst++ = CONVERT(c,(bits == 0) ? palZeroTransparent : opaqueColor); + *dwdst++ = RGB15TO32(c,(bits == 0) ? palZeroTransparent : 255); adr++; } @@ -378,11 +369,11 @@ REJECT: bits = (*adr)&0xF; c = pal[bits]; - *dwdst++ = CONVERT(c,(bits == 0) ? palZeroTransparent : opaqueColor); + *dwdst++ = RGB15TO32(c,(bits == 0) ? palZeroTransparent : 255); bits = ((*adr)>>4); c = pal[bits]; - *dwdst++ = CONVERT(c,(bits == 0) ? palZeroTransparent : opaqueColor); + *dwdst++ = RGB15TO32(c,(bits == 0) ? palZeroTransparent : 255); adr++; } } @@ -395,7 +386,7 @@ REJECT: for(u32 x = 0; x < ms.items[j].len; ++x) { u16 c = pal[*adr]; - *dwdst++ = CONVERT(c,(*adr == 0) ? palZeroTransparent : opaqueColor); + *dwdst++ = RGB15TO32(c,(*adr == 0) ? palZeroTransparent : 255); adr++; } } @@ -453,7 +444,7 @@ REJECT: u16 pal1offset = (pal1 & 0x3FFF)<<1; u8 mode = pal1>>14; u32 tmp_col[4]; - + tmp_col[0]=RGB16TO32(PAL4X4(pal1offset),255); tmp_col[1]=RGB16TO32(PAL4X4(pal1offset+1),255); @@ -501,17 +492,6 @@ REJECT: } } - if(TEXFORMAT==TexFormat_15bpp) - { - for(int i=0;i<4;i++) - { - tmp_col[i] >>= 3; - tmp_col[i] &= 0x1F1F1F1F; - } - } - - //TODO - this could be more precise for 32bpp mode (run it through the color separation table) - //set all 16 texels for (int sy = 0; sy < 4; sy++) { @@ -540,10 +520,7 @@ REJECT: { u16 c = pal[*adr&0x07]; u8 alpha = (*adr>>3); - if(TEXFORMAT == TexFormat_15bpp) - *dwdst++ = RGB15TO5555(c,alpha); - else - *dwdst++ = RGB15TO32(c,material_5bit_to_8bit[alpha]); + *dwdst++ = RGB15TO32(c,material_5bit_to_8bit[alpha]); adr++; } } @@ -556,8 +533,8 @@ REJECT: for(u32 x = 0; x < ms.items[j].len; ++x) { u16 c = map[x]; - int alpha = ((c&0x8000)?opaqueColor:0); - *dwdst++ = CONVERT(c&0x7FFF,alpha); + int alpha = ((c&0x8000)?255:0); + *dwdst++ = RGB15TO32(c&0x7FFF,alpha); } } break; @@ -608,7 +585,3 @@ void TexCache_Invalidate() void (*TexCache_BindTexture)(u32 texnum) = NULL; void (*TexCache_BindTextureData)(u32 texnum, u8* data); - -//these templates needed to be instantiated manually -template void TexCache_SetTexture(u32 format, u32 texpal); -template void TexCache_SetTexture(u32 format, u32 texpal); \ No newline at end of file diff --git a/desmume/src/texcache.h b/src/texcache.h similarity index 82% rename from desmume/src/texcache.h rename to src/texcache.h index c350a2fe4..f018667ef 100644 --- a/desmume/src/texcache.h +++ b/src/texcache.h @@ -3,14 +3,8 @@ #include "common.h" -enum TexCache_TexFormat -{ - TexFormat_32bpp, - TexFormat_15bpp -}; - #define MAX_TEXTURE 500 -#ifndef NOSSE2 +#ifdef SSE2 struct ALIGN(16) TextureCache #else struct ALIGN(8) TextureCache @@ -42,10 +36,7 @@ extern void (*TexCache_BindTexture)(u32 texnum); extern void (*TexCache_BindTextureData)(u32 texnum, u8* data); void TexCache_Reset(); - -template -void TexCache_SetTexture(u32 format, u32 texpal); - +void TexCache_SetTexture(unsigned int format, unsigned int texpal); void TexCache_Invalidate(); extern u8 TexCache_texMAP[1024*2048*4]; diff --git a/desmume/src/thumb_instructions.cpp b/src/thumb_instructions.cpp similarity index 100% rename from desmume/src/thumb_instructions.cpp rename to src/thumb_instructions.cpp diff --git a/desmume/src/thumb_instructions.h b/src/thumb_instructions.h similarity index 100% rename from desmume/src/thumb_instructions.h rename to src/thumb_instructions.h diff --git a/desmume/src/thumb_tabdef.inc b/src/thumb_tabdef.inc similarity index 100% rename from desmume/src/thumb_tabdef.inc rename to src/thumb_tabdef.inc diff --git a/desmume/src/types.h b/src/types.h similarity index 93% rename from desmume/src/types.h rename to src/types.h index abaf1152e..ea9c82eeb 100644 --- a/desmume/src/types.h +++ b/src/types.h @@ -20,14 +20,10 @@ #ifndef TYPES_HPP #define TYPES_HPP -//todo - everyone will want to support this eventually, i suppose -#ifdef _MSC_VER -#include "config.h" -#endif - -#ifndef _MSC_VER -#define NOSSE2 -#endif +//-------------- +//configuration +#define DEVELOPER +//-------------- #define DESMUME_NAME "DeSmuME" @@ -41,24 +37,26 @@ #endif #endif -#ifdef NOSSE2 -#define DESMUME_CPUEXT_STRING " NOSSE2" +#ifdef SSE2 +#define DESMUME_CPUEXT_STRING " SSE2" #else #define DESMUME_CPUEXT_STRING "" #endif -#ifdef DEVELOPER -#define DESMUME_FEATURE_STRING " dev+" -#else +//#ifdef DEVELOPER +//#define DESMUME_FEATURE_STRING " dev+" +//#else #define DESMUME_FEATURE_STRING "" -#endif +//#endif #ifdef DEBUG #define DESMUME_SUBVERSION_STRING " debug" -#elif defined(PUBLIC_RELEASE) +#else +#ifdef RELEASE #define DESMUME_SUBVERSION_STRING "" #else -#define DESMUME_SUBVERSION_STRING " svn" +#define DESMUME_SUBVERSION_STRING " prerelease" +#endif #endif #ifdef __INTEL_COMPILER @@ -78,7 +76,7 @@ #endif #define DESMUME_VERSION_NUMERIC 90300 -#define DESMUME_VERSION_STRING " " "0.9.3" DESMUME_SUBVERSION_STRING DESMUME_FEATURE_STRING DESMUME_PLATFORM_STRING DESMUME_CPUEXT_STRING DESMUME_COMPILER +#define DESMUME_VERSION_STRING " " "0.9.3 svn" DESMUME_FEATURE_STRING DESMUME_PLATFORM_STRING DESMUME_CPUEXT_STRING DESMUME_SUBVERSION_STRING DESMUME_COMPILER #define DESMUME_NAME_AND_VERSION " " DESMUME_NAME DESMUME_VERSION_STRING #ifdef _WIN32 @@ -114,12 +112,6 @@ #endif #endif -#ifdef _MSC_VER -#define _CDECL_ __cdecl -#else -#define _CDECL_ -#endif - #ifndef INLINE #if defined(_MSC_VER) || defined(__INTEL_COMPILER) #define INLINE _inline diff --git a/desmume/src/utils/ConvertUTF.c b/src/utils/ConvertUTF.c similarity index 100% rename from desmume/src/utils/ConvertUTF.c rename to src/utils/ConvertUTF.c diff --git a/desmume/src/utils/ConvertUTF.h b/src/utils/ConvertUTF.h similarity index 100% rename from desmume/src/utils/ConvertUTF.h rename to src/utils/ConvertUTF.h diff --git a/desmume/src/utils/decrypt/crc.cpp b/src/utils/decrypt/crc.cpp similarity index 100% rename from desmume/src/utils/decrypt/crc.cpp rename to src/utils/decrypt/crc.cpp diff --git a/desmume/src/utils/decrypt/crc.h b/src/utils/decrypt/crc.h similarity index 100% rename from desmume/src/utils/decrypt/crc.h rename to src/utils/decrypt/crc.h diff --git a/desmume/src/utils/decrypt/decrypt.cpp b/src/utils/decrypt/decrypt.cpp similarity index 100% rename from desmume/src/utils/decrypt/decrypt.cpp rename to src/utils/decrypt/decrypt.cpp diff --git a/desmume/src/utils/decrypt/decrypt.h b/src/utils/decrypt/decrypt.h similarity index 100% rename from desmume/src/utils/decrypt/decrypt.h rename to src/utils/decrypt/decrypt.h diff --git a/desmume/src/utils/decrypt/header.cpp b/src/utils/decrypt/header.cpp similarity index 100% rename from desmume/src/utils/decrypt/header.cpp rename to src/utils/decrypt/header.cpp diff --git a/desmume/src/utils/decrypt/header.h b/src/utils/decrypt/header.h similarity index 100% rename from desmume/src/utils/decrypt/header.h rename to src/utils/decrypt/header.h diff --git a/desmume/src/utils/guid.cpp b/src/utils/guid.cpp similarity index 100% rename from desmume/src/utils/guid.cpp rename to src/utils/guid.cpp diff --git a/desmume/src/utils/guid.h b/src/utils/guid.h similarity index 100% rename from desmume/src/utils/guid.h rename to src/utils/guid.h diff --git a/desmume/src/utils/md5.cpp b/src/utils/md5.cpp similarity index 100% rename from desmume/src/utils/md5.cpp rename to src/utils/md5.cpp diff --git a/desmume/src/utils/md5.h b/src/utils/md5.h similarity index 100% rename from desmume/src/utils/md5.h rename to src/utils/md5.h diff --git a/desmume/src/utils/valuearray.h b/src/utils/valuearray.h similarity index 100% rename from desmume/src/utils/valuearray.h rename to src/utils/valuearray.h diff --git a/desmume/src/utils/xstring.cpp b/src/utils/xstring.cpp similarity index 100% rename from desmume/src/utils/xstring.cpp rename to src/utils/xstring.cpp diff --git a/desmume/src/utils/xstring.h b/src/utils/xstring.h similarity index 100% rename from desmume/src/utils/xstring.h rename to src/utils/xstring.h diff --git a/desmume/src/wifi.cpp b/src/wifi.cpp similarity index 98% rename from desmume/src/wifi.cpp rename to src/wifi.cpp index 10278cfa7..0214262f4 100644 --- a/desmume/src/wifi.cpp +++ b/src/wifi.cpp @@ -513,14 +513,12 @@ static void WIFI_TXStart(wifimac_t *wifi,u8 slot) wifi->txSlotLen[slot] = txLen; wifi->txSlotRemainingBytes[slot] = (txLen + 12); -#if 0 - WIFI_Host_SendData(wifi->udpSocket,wifi->channel,(u8 *)&wifi->circularBuffer[address],txLen) ; + /* WIFI_Host_SendData(wifi->udpSocket,wifi->channel,(u8 *)&wifi->circularBuffer[address],txLen) ; WIFI_SoftAP_RecvPacketFromDS(wifi, (u8*)&wifi->circularBuffer[address+6], txLen); - WIFI_triggerIRQ(wifi,/*WIFI_IRQ_SENDCOMPLETE*/1) ; + WIFI_triggerIRQ(wifi,/*WIFI_IRQ_SENDCOMPLETE*-/1) ; wifi->circularBuffer[address] = 0x0001; - wifi->circularBuffer[address+4] &= 0x00FF; -#endif + wifi->circularBuffer[address+4] &= 0x00FF;*/ } } @@ -686,19 +684,17 @@ void WIFI_write16(wifimac_t *wifi,u32 address, u16 val) wifi->TXSlot[(address - REG_WIFI_TXLOC1) >> 2] = val ; break ; case REG_WIFI_TXOPT: -#if 0 - if (val == 0xFFFF) + /* if (val == 0xFFFF) { - /* reset TX logic */ - /* CHECKME */ + /* reset TX logic *-/ + /* CHECKME *-/ // wifi->TXSlot[0] = 0 ; wifi->TXSlot[1] = 0 ; wifi->TXSlot[2] = 0 ; wifi->TXOpt = 0 ; wifi->TXCnt = 0 ; } else { wifi->TXOpt = val ; - } -#endif + }*/ wifi->TXCnt &= ~val; break ; case REG_WIFI_TXCNT: @@ -931,7 +927,8 @@ u16 WIFI_read16(wifimac_t *wifi,u32 address) //printf("wifi: read reg 0x0214\n"); return 0x0009; case 0x19C: - return 0; //luigi, please pick something to return from here + assert(false); //luigi, please pick something to return from here + return 0; default: // printf("wifi: read unhandled reg %03X\n", address); return wifi->ioMem[address >> 1]; @@ -962,24 +959,22 @@ void WIFI_usTrigger(wifimac_t *wifi) } /* receive check, given a 2 mbit connection, 2 bits per usec can be transfered. */ /* for a packet of 32 Bytes, at least 128 usec passed, we will use the 32 byte accuracy to reduce load */ -#if 0 - if (!(wifi->RXCheckCounter++ & 0x7F)) + /*if (!(wifi->RXCheckCounter++ & 0x7F)) { - /* check if data arrived in the meantime */ + /* check if data arrived in the meantime *-/ rcvSize = WIFI_Host_RecvData(wifi->udpSocket,dataBuffer,0x2000) ; if (rcvSize) { u16 i ; - /* process data, put it into mac memory */ - WIFI_triggerIRQ(wifi,/*WIFI_IRQ_RECVSTART*/6) ; + /* process data, put it into mac memory *-/ + WIFI_triggerIRQ(wifi,/*WIFI_IRQ_RECVSTART*-/6) ; for (i=0;i<(rcvSize+1) << 1;i++) { WIFI_RXPutWord(wifi,((u16 *)dataBuffer)[i]) ; } - WIFI_triggerIRQ(wifi,/*WIFI_IRQ_RECVCOMPLETE*/0) ; + WIFI_triggerIRQ(wifi,/*WIFI_IRQ_RECVCOMPLETE*-/0) ; } - } -#endif + }*/ if((wifi->usec & 3) == 0) { int slot = wifi->txCurSlot; diff --git a/desmume/src/wifi.h b/src/wifi.h similarity index 100% rename from desmume/src/wifi.h rename to src/wifi.h diff --git a/desmume/src/windows/AboutBox.cpp b/src/windows/AboutBox.cpp similarity index 100% rename from desmume/src/windows/AboutBox.cpp rename to src/windows/AboutBox.cpp diff --git a/desmume/src/windows/AboutBox.h b/src/windows/AboutBox.h similarity index 100% rename from desmume/src/windows/AboutBox.h rename to src/windows/AboutBox.h diff --git a/desmume/src/windows/CWindow.cpp b/src/windows/CWindow.cpp similarity index 100% rename from desmume/src/windows/CWindow.cpp rename to src/windows/CWindow.cpp diff --git a/desmume/src/windows/CWindow.h b/src/windows/CWindow.h similarity index 100% rename from desmume/src/windows/CWindow.h rename to src/windows/CWindow.h diff --git a/desmume/src/windows/DeSmuME.ico b/src/windows/DeSmuME.ico similarity index 100% rename from desmume/src/windows/DeSmuME.ico rename to src/windows/DeSmuME.ico diff --git a/desmume/src/windows/DeSmuME_2005.vcproj b/src/windows/DeSmuME_2005.vcproj similarity index 60% rename from desmume/src/windows/DeSmuME_2005.vcproj rename to src/windows/DeSmuME_2005.vcproj index f8e22d599..822cf0241 100644 --- a/desmume/src/windows/DeSmuME_2005.vcproj +++ b/src/windows/DeSmuME_2005.vcproj @@ -50,11 +50,11 @@ FavorSizeOrSpeed="0" EnableFiberSafeOptimizations="false" WholeProgramOptimization="false" - AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig" - PreprocessorDefinitions="DEBUG;_CRT_SECURE_NO_DEPRECATE;WIN32;SPU_INTERPOLATE;HAVE_LIBZ;HAVE_LIBZZIP;NOMINMAX;DEBUG;EXPERIMENTAL_WIFI" + AdditionalIncludeDirectories=".;..;.\zlib123;.\zziplib;.\winpcap" + PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;WIN32;BETA_VERSION;SPU_INTERPOLATE;HAVE_LIBZ;HAVE_LIBZZIP;NOMINMAX;DEBUG;WANTPROGINFO;EXPERIMENTAL_WIFI" ExceptionHandling="1" BufferSecurityCheck="false" - EnableEnhancedInstructionSet="2" + EnableEnhancedInstructionSet="0" FloatingPointModel="2" WarningLevel="1" DebugInformationFormat="4" @@ -107,7 +107,96 @@ /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - @@ -241,10 +491,6 @@ RelativePath=".\colorctrl.h" > - - @@ -340,6 +586,14 @@ + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - 16)?TRUE:FALSE); - SetWindowText(GetDlgItem(dialog, IDOK), "Update"); - } - CheckDlgButton(dialog, IDC_CHECK1, tempCheat.enabled?BST_CHECKED:BST_UNCHECKED); - - SendMessage(GetDlgItem(dialog, IDC_EDIT2), EM_SETLIMITTEXT, sizeof(tempCheat.hi)+sizeof(tempCheat.lo), 0); - SendMessage(GetDlgItem(dialog, IDC_EDIT3), EM_SETLIMITTEXT, sizeof(tempCheat.description), 0); - } - return TRUE; - - case WM_COMMAND: - { - switch (LOWORD(wparam)) - { - case IDOK: - { - char buf[sizeof(tempCheat.hi)+sizeof(tempCheat.lo)] = { 0 }; - - memset(buf, 0, sizeof(buf)); - GetWindowText(GetDlgItem(dialog, IDC_EDIT2), buf, sizeof(buf)); - - if (cheatXXtype == 0) // Action Replay - { - if (cheatXXaction == 0) // add - { - if (!cheatsAdd_AR(buf, tempCheat.description, tempCheat.enabled)) - { - MessageBox(dialog, "Syntax error in Action Replay code.\nTry again", "DeSmuME", - MB_OK | MB_ICONERROR); - return FALSE; - } - } - else // edit - { - if (!cheatsUpdate_AR(buf, tempCheat.description, tempCheat.enabled, cheatEditPos)) - { - MessageBox(dialog, "Syntax error in Action Replay code.\nTry again", "DeSmuME", - MB_OK | MB_ICONERROR); - return FALSE; - } - } - } - else - { - if (cheatXXaction == 0) // add - { - if (!cheatsAdd_CB(buf, tempCheat.description, tempCheat.enabled)) - { - MessageBox(dialog, "Syntax error in Codebreaker code.\nTry again", "DeSmuME", - MB_OK | MB_ICONERROR); - return FALSE; - } - } - else // edit - { - if (!cheatsUpdate_CB(buf, tempCheat.description, tempCheat.enabled, cheatEditPos)) - { - MessageBox(dialog, "Syntax error in Codebreaker code.\nTry again", "DeSmuME", - MB_OK | MB_ICONERROR); - return FALSE; - } - } - } - EndDialog(dialog, TRUE); - } - return TRUE; - - case IDCANCEL: - EndDialog(dialog, FALSE); - return TRUE; - - case IDC_EDIT2: // code - if (HIWORD(wparam) == EN_UPDATE) - { - char buf[sizeof(tempCheat.hi)+sizeof(tempCheat.lo)] = { 0 }; - - memset(buf, 0, sizeof(buf)); - GetWindowText(GetDlgItem(dialog, IDC_EDIT2), buf, sizeof(buf)); - if (strlen(buf) < 17) // min size of code "CXXXXXXX YYYYYYYY" - { - EnableWindow(GetDlgItem(dialog, IDOK), FALSE); - return TRUE; - } - EnableWindow(GetDlgItem(dialog, IDOK), TRUE); - } - return TRUE; - - case IDC_EDIT3: // description - if (HIWORD(wparam) == EN_UPDATE) - { - memset(tempCheat.description, 0, sizeof(tempCheat.description)); - GetWindowText(GetDlgItem(dialog, IDC_EDIT3), tempCheat.description, sizeof(tempCheat.description)); - } - return TRUE; - - case IDC_CHECK1: - if (IsDlgButtonChecked(dialog, IDC_CHECK1) == BST_CHECKED) - tempCheat.enabled = 1; - else - tempCheat.enabled = 0; - return TRUE; - } - } - } - return FALSE; -} //============================================================================== BOOL CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lparam) { @@ -647,37 +496,12 @@ BOOL CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpar lvi.pszText= "X"; else lvi.pszText= ""; - switch (tempCheat.type) - { - case 0: // Internal - { - u32 row = ListView_InsertItem(cheatListView, &lvi); - wsprintf(buf, "0x02%06X", tempCheat.hi[0]); - ListView_SetItemText(cheatListView, row, 1, buf); - ltoa(tempCheat.lo[0], buf, 10); - ListView_SetItemText(cheatListView, row, 2, buf); - ListView_SetItemText(cheatListView, row, 3, tempCheat.description); - break; - } - - case 1: // Action Replay - { - u32 row = ListView_InsertItem(cheatListView, &lvi); - ListView_SetItemText(cheatListView, row, 1, "Action"); - ListView_SetItemText(cheatListView, row, 2, "Replay"); - ListView_SetItemText(cheatListView, row, 3, tempCheat.description); - break; - } - - case 2: // Codebreaker - { - u32 row = ListView_InsertItem(cheatListView, &lvi); - ListView_SetItemText(cheatListView, row, 1, "Code"); - ListView_SetItemText(cheatListView, row, 2, "breaker"); - ListView_SetItemText(cheatListView, row, 3, tempCheat.description); - break; - } - } + u32 row = ListView_InsertItem(cheatListView, &lvi); + wsprintf(buf, "0x02%06X", tempCheat.hi[0]); + ListView_SetItemText(cheatListView, row, 1, buf); + ltoa(tempCheat.lo[0], buf, 10); + ListView_SetItemText(cheatListView, row, 2, buf); + ListView_SetItemText(cheatListView, row, 3, tempCheat.description); } SendMessage(cheatListView, WM_SETREDRAW, (WPARAM)TRUE,0); @@ -695,22 +519,7 @@ BOOL CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpar cheatEditPos = ListView_GetNextItem(cheatListView, -1, LVNI_SELECTED|LVNI_FOCUSED); cheatsGet(&tempCheat, cheatEditPos); tempCheat.enabled = !tempCheat.enabled; - switch (tempCheat.type) - { - case 0: // internal - cheatsUpdate(tempCheat.size, tempCheat.hi[0], tempCheat.lo[0], tempCheat.description, tempCheat.enabled, cheatEditPos); - break; - - case 1: // Action Replay - cheatsUpdate_AR(NULL, NULL, tempCheat.enabled, cheatEditPos); - break; - - case 2: // Codebreaker - cheatsUpdate_CB(NULL, NULL, tempCheat.enabled, cheatEditPos); - break; - } - - + cheatsUpdate(tempCheat.size, tempCheat.hi[0], tempCheat.lo[0], tempCheat.description, tempCheat.enabled, cheatEditPos); if (tempCheat.enabled) ListView_SetItemText(cheatListView, cheatEditPos, 0, "X") else @@ -783,105 +592,20 @@ BOOL CALLBACK CheatsListBox_Proc(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpar } return TRUE; - case IDC_BADD_AR: - { - if (LOWORD(wparam) == IDC_BADD_AR) - { - cheatXXtype = 0; - } - else - if (LOWORD(wparam) == IDC_BADD_CB) - { - cheatXXtype = 1; - } - else - return TRUE; - cheatXXaction = 0; // 0 = add - - if (DialogBox(hAppInst, MAKEINTRESOURCE(IDD_CHEAT_ADD_XX_CODE), dialog, (DLGPROC) CheatsAdd_XX_Proc)) - { - LVITEM lvi; - - memset(&lvi,0,sizeof(LVITEM)); - lvi.mask = LVIF_TEXT|LVIF_STATE; - lvi.iItem = INT_MAX; - - if (tempCheat.enabled) - lvi.pszText= "X"; - else - lvi.pszText= " "; - u32 row = ListView_InsertItem(cheatListView, &lvi); - if (cheatXXtype == 0) - { - ListView_SetItemText(cheatListView, row, 1, "Action"); - ListView_SetItemText(cheatListView, row, 2, "Replay"); - } - else - { - ListView_SetItemText(cheatListView, row, 1, "Code"); - ListView_SetItemText(cheatListView, row, 2, "breaker"); - } - ListView_SetItemText(cheatListView, row, 3, tempCheat.description); - - EnableWindow(GetDlgItem(dialog, IDOK), TRUE); - } - } - return TRUE; - case IDC_BEDIT: { cheatEditPos = ListView_GetNextItem(cheatListView, -1, LVNI_SELECTED|LVNI_FOCUSED); if (cheatEditPos > cheatsGetSize()) return TRUE; - - cheatsGet(&tempCheat, cheatEditPos); - - switch (tempCheat.type) + if (DialogBox(hAppInst, MAKEINTRESOURCE(IDD_CHEAT_ADD), dialog, (DLGPROC) CheatsEditProc)) { - case 0: // internal - if (DialogBox(hAppInst, MAKEINTRESOURCE(IDD_CHEAT_ADD), dialog, (DLGPROC) CheatsEditProc)) - { - char buf[256]; - cheatsGet(&tempCheat, cheatEditPos); - if (tempCheat.enabled) - ListView_SetItemText(cheatListView, cheatEditPos, 0, "X"); - wsprintf(buf, "0x02%06X", tempCheat.hi[0]); - ListView_SetItemText(cheatListView, cheatEditPos, 1, buf); - ltoa(tempCheat.lo[0], buf, 10); - ListView_SetItemText(cheatListView, cheatEditPos, 2, buf); - ListView_SetItemText(cheatListView, cheatEditPos, 3, tempCheat.description); - EnableWindow(GetDlgItem(dialog, IDOK), TRUE); - } - break; - - case 1: // Action replay - case 2: // Codebreaker - if (tempCheat.type == 1) - cheatXXtype = 0; - else - cheatXXtype = 1; - cheatXXaction = 1; // 1 = edit - - if (DialogBox(hAppInst, MAKEINTRESOURCE(IDD_CHEAT_ADD_XX_CODE), dialog, (DLGPROC) CheatsAdd_XX_Proc)) - { - cheatsGet(&tempCheat, cheatEditPos); - if (tempCheat.enabled) - ListView_SetItemText(cheatListView, cheatEditPos, 0, "X"); - - if (cheatXXtype == 0) - { - ListView_SetItemText(cheatListView, cheatEditPos, 1, "Action"); - ListView_SetItemText(cheatListView, cheatEditPos, 2, "Replay"); - } - else - { - ListView_SetItemText(cheatListView, cheatEditPos, 1, "Code"); - ListView_SetItemText(cheatListView, cheatEditPos, 2, "breaker"); - } - - ListView_SetItemText(cheatListView, cheatEditPos, 3, tempCheat.description); - EnableWindow(GetDlgItem(dialog, IDOK), TRUE); - } - break; + char buf[256]; + cheatsGet(&tempCheat, cheatEditPos); + wsprintf(buf, "0x02%06X", tempCheat.hi[0]); + ListView_SetItemText(cheatListView, cheatEditPos, 1, buf); + ltoa(tempCheat.lo[0], buf, 10); + ListView_SetItemText(cheatListView, cheatEditPos, 2, buf); + ListView_SetItemText(cheatListView, cheatEditPos, 3, tempCheat.description); + EnableWindow(GetDlgItem(dialog, IDOK), TRUE); } } return TRUE; @@ -946,7 +670,7 @@ BOOL CALLBACK CheatsSearchExactWnd(HWND dialog, UINT msg,WPARAM wparam,LPARAM lp ltoa(searchNumberResults, buf, 10); SetWindowText(GetDlgItem(dialog, IDC_SNUMBER), buf); SetFocus(GetDlgItem(dialog, IDC_EVALUE)); - break; + return TRUE; } case WM_COMMAND: @@ -1001,7 +725,7 @@ BOOL CALLBACK CheatsSearchCompWnd(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpa char buf[256]; ltoa(searchNumberResults, buf, 10); SetWindowText(GetDlgItem(dialog, IDC_SNUMBER), buf); - break; + return TRUE; } case WM_COMMAND: @@ -1085,7 +809,6 @@ BOOL CALLBACK CheatsSearchViewWnd(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpa SetFocus(searchListView); } return TRUE; - case WM_COMMAND: { switch (LOWORD(wparam)) @@ -1129,7 +852,7 @@ BOOL CALLBACK CheatsSearchMainWnd(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpa EnableWindow(hBRestart, FALSE); EnableWindow(hBView, FALSE); EnableWindow(hBSearch, TRUE); - break; + return TRUE; } case WM_COMMAND: @@ -1150,26 +873,28 @@ BOOL CALLBACK CheatsSearchMainWnd(HWND dialog, UINT msg,WPARAM wparam,LPARAM lpa return TRUE; case IDC_RADIO5: // unsigned + { searchSign = 0; for (int i = 0; i < 4; i++) SetWindowText(GetDlgItem(dialog, searchRangeIDDs[i]), searchRangeText[searchSign][i]); - return TRUE; - + return TRUE; + } case IDC_RADIO6: //signed + { searchSign = 1; for (int i = 0; i < 4; i++) SetWindowText(GetDlgItem(dialog, searchRangeIDDs[i]), searchRangeText[searchSign][i]); - return TRUE; + return TRUE; + } case IDC_RADIO7: // exact value search searchType = 0; return TRUE; - case IDC_RADIO8: // comparative search searchType = 1; return TRUE; } - return TRUE; + break; } } return FALSE; diff --git a/desmume/src/windows/cheatsWin.h b/src/windows/cheatsWin.h similarity index 100% rename from desmume/src/windows/cheatsWin.h rename to src/windows/cheatsWin.h diff --git a/desmume/src/windows/colorctrl.cpp b/src/windows/colorctrl.cpp similarity index 100% rename from desmume/src/windows/colorctrl.cpp rename to src/windows/colorctrl.cpp diff --git a/desmume/src/windows/colorctrl.h b/src/windows/colorctrl.h similarity index 100% rename from desmume/src/windows/colorctrl.h rename to src/windows/colorctrl.h diff --git a/desmume/src/windows/console.cpp b/src/windows/console.cpp similarity index 95% rename from desmume/src/windows/console.cpp rename to src/windows/console.cpp index e17edf7fa..13535d1aa 100644 --- a/desmume/src/windows/console.cpp +++ b/src/windows/console.cpp @@ -29,7 +29,7 @@ ///////////////////////////////////////////////////////////////// Console -#if !defined(PUBLIC_RELEASE) || defined(DEVELOPER) +#ifdef BETA_VERSION #define BUFFER_SIZE 100 HANDLE hConsole; void printlog(const char *fmt, ...); @@ -87,9 +87,4 @@ void printlog(const char *fmt, ...) va_end(list); WriteConsole(hConsole,msg, (DWORD)strlen(msg), &tmp, 0); } -#else - -void OpenConsole() {} -void CloseConsole() {} - #endif diff --git a/desmume/src/windows/console.h b/src/windows/console.h similarity index 95% rename from desmume/src/windows/console.h rename to src/windows/console.h index 193eb8ae2..45d8c8e58 100644 --- a/desmume/src/windows/console.h +++ b/src/windows/console.h @@ -29,13 +29,15 @@ #include #include "debug.h" +void OpenConsole(); +void CloseConsole(); + #else +#define OpenConsole() +#define CloseConsole() #define pringlog(...) #endif -void OpenConsole(); -void CloseConsole(); - #endif \ No newline at end of file diff --git a/desmume/src/windows/directx/DxErr8.lib b/src/windows/directx/DxErr8.lib similarity index 100% rename from desmume/src/windows/directx/DxErr8.lib rename to src/windows/directx/DxErr8.lib diff --git a/desmume/src/windows/directx/ddraw.h b/src/windows/directx/ddraw.h similarity index 100% rename from desmume/src/windows/directx/ddraw.h rename to src/windows/directx/ddraw.h diff --git a/desmume/src/windows/directx/ddraw.lib b/src/windows/directx/ddraw.lib similarity index 100% rename from desmume/src/windows/directx/ddraw.lib rename to src/windows/directx/ddraw.lib diff --git a/desmume/src/windows/directx/dinput.h b/src/windows/directx/dinput.h similarity index 100% rename from desmume/src/windows/directx/dinput.h rename to src/windows/directx/dinput.h diff --git a/desmume/src/windows/directx/dinput8.lib b/src/windows/directx/dinput8.lib similarity index 100% rename from desmume/src/windows/directx/dinput8.lib rename to src/windows/directx/dinput8.lib diff --git a/desmume/src/windows/directx/dsound.h b/src/windows/directx/dsound.h similarity index 100% rename from desmume/src/windows/directx/dsound.h rename to src/windows/directx/dsound.h diff --git a/desmume/src/windows/directx/dsound.lib b/src/windows/directx/dsound.lib similarity index 100% rename from desmume/src/windows/directx/dsound.lib rename to src/windows/directx/dsound.lib diff --git a/desmume/src/windows/directx/dxerr8.h b/src/windows/directx/dxerr8.h similarity index 100% rename from desmume/src/windows/directx/dxerr8.h rename to src/windows/directx/dxerr8.h diff --git a/desmume/src/windows/directx/dxguid.lib b/src/windows/directx/dxguid.lib similarity index 100% rename from desmume/src/windows/directx/dxguid.lib rename to src/windows/directx/dxguid.lib diff --git a/desmume/src/windows/disView.cpp b/src/windows/disView.cpp similarity index 100% rename from desmume/src/windows/disView.cpp rename to src/windows/disView.cpp diff --git a/desmume/src/windows/disView.h b/src/windows/disView.h similarity index 100% rename from desmume/src/windows/disView.h rename to src/windows/disView.h diff --git a/desmume/src/windows/gbaslot_config.cpp b/src/windows/gbaslot_config.cpp similarity index 100% rename from desmume/src/windows/gbaslot_config.cpp rename to src/windows/gbaslot_config.cpp diff --git a/desmume/src/windows/gbaslot_config.h b/src/windows/gbaslot_config.h similarity index 100% rename from desmume/src/windows/gbaslot_config.h rename to src/windows/gbaslot_config.h diff --git a/desmume/src/windows/ginfo.cpp b/src/windows/ginfo.cpp similarity index 100% rename from desmume/src/windows/ginfo.cpp rename to src/windows/ginfo.cpp diff --git a/desmume/src/windows/ginfo.h b/src/windows/ginfo.h similarity index 100% rename from desmume/src/windows/ginfo.h rename to src/windows/ginfo.h diff --git a/desmume/src/windows/hotkey.cpp b/src/windows/hotkey.cpp similarity index 100% rename from desmume/src/windows/hotkey.cpp rename to src/windows/hotkey.cpp diff --git a/desmume/src/windows/hotkey.h b/src/windows/hotkey.h similarity index 100% rename from desmume/src/windows/hotkey.h rename to src/windows/hotkey.h diff --git a/desmume/src/windows/inputdx.cpp b/src/windows/inputdx.cpp similarity index 100% rename from desmume/src/windows/inputdx.cpp rename to src/windows/inputdx.cpp diff --git a/desmume/src/windows/inputdx.h b/src/windows/inputdx.h similarity index 100% rename from desmume/src/windows/inputdx.h rename to src/windows/inputdx.h diff --git a/desmume/src/windows/langs/build_utils/gettextlib.dll b/src/windows/langs/build_utils/gettextlib.dll similarity index 100% rename from desmume/src/windows/langs/build_utils/gettextlib.dll rename to src/windows/langs/build_utils/gettextlib.dll diff --git a/desmume/src/windows/langs/build_utils/gettextpo.dll b/src/windows/langs/build_utils/gettextpo.dll similarity index 100% rename from desmume/src/windows/langs/build_utils/gettextpo.dll rename to src/windows/langs/build_utils/gettextpo.dll diff --git a/desmume/src/windows/langs/build_utils/gettextsrc.dll b/src/windows/langs/build_utils/gettextsrc.dll similarity index 100% rename from desmume/src/windows/langs/build_utils/gettextsrc.dll rename to src/windows/langs/build_utils/gettextsrc.dll diff --git a/desmume/src/windows/langs/build_utils/iconv.dll b/src/windows/langs/build_utils/iconv.dll similarity index 100% rename from desmume/src/windows/langs/build_utils/iconv.dll rename to src/windows/langs/build_utils/iconv.dll diff --git a/desmume/src/windows/langs/build_utils/intl.dll b/src/windows/langs/build_utils/intl.dll similarity index 100% rename from desmume/src/windows/langs/build_utils/intl.dll rename to src/windows/langs/build_utils/intl.dll diff --git a/desmume/src/windows/langs/build_utils/libiconv-2.dll b/src/windows/langs/build_utils/libiconv-2.dll similarity index 100% rename from desmume/src/windows/langs/build_utils/libiconv-2.dll rename to src/windows/langs/build_utils/libiconv-2.dll diff --git a/desmume/src/windows/langs/build_utils/msgfmt.exe b/src/windows/langs/build_utils/msgfmt.exe similarity index 100% rename from desmume/src/windows/langs/build_utils/msgfmt.exe rename to src/windows/langs/build_utils/msgfmt.exe diff --git a/desmume/src/windows/langs/fr_FR.mo b/src/windows/langs/fr_FR.mo similarity index 100% rename from desmume/src/windows/langs/fr_FR.mo rename to src/windows/langs/fr_FR.mo diff --git a/desmume/src/windows/lightView.cpp b/src/windows/lightView.cpp similarity index 100% rename from desmume/src/windows/lightView.cpp rename to src/windows/lightView.cpp diff --git a/desmume/src/windows/lightView.h b/src/windows/lightView.h similarity index 100% rename from desmume/src/windows/lightView.h rename to src/windows/lightView.h diff --git a/desmume/src/windows/main.cpp b/src/windows/main.cpp similarity index 98% rename from desmume/src/windows/main.cpp rename to src/windows/main.cpp index e79d9e7e3..e38288da1 100644 --- a/desmume/src/windows/main.cpp +++ b/src/windows/main.cpp @@ -1186,62 +1186,6 @@ void NDS_UnPause() } -/*** - * Author: Hicoder - * Function: UpdateSaveStateMenu - * Date Added: April 20, 2009 - * Description: Updates the specified savestate menus - * Known Usage: - * ResetSaveStateTimes - * LoadSaveStateInfo - **/ -void UpdateSaveStateMenu(int pos, char* txt) -{ - ModifyMenu(mainMenu,IDM_STATE_SAVE_F1 + pos, MF_BYCOMMAND | MF_STRING, IDM_STATE_SAVE_F1 + pos, txt); - ModifyMenu(mainMenu,IDM_STATE_LOAD_F1 + pos, MF_BYCOMMAND | MF_STRING, IDM_STATE_LOAD_F1 + pos, txt); -} - -/*** - * Author: Hicoder - * Function: ResetSaveStateTime - * Date Added: April 20, 2009 - * Description: Resets the times for save states to blank - * Known Usage: - * LoadRom - **/ -void ResetSaveStateTimes() -{ - char ntxt[64]; - for(int i = 0; i < NB_STATES;i++) - { - sprintf(ntxt,"%d %s", i+1, ""); - UpdateSaveStateMenu(i, ntxt); - } -} - -/*** - * Author: Hicoder - * Function: LoadSaveStateInfo - * Date Added: April 20, 2009 - * Description: Checks The Rom thats opening for save states asscociated with it - * Known Usage: - * LoadRom - **/ -void LoadSaveStateInfo() -{ - scan_savestates(); - char ntxt[22]; - for(int i = 0; i < NB_STATES; i++) - { - if(savestates[i].exists) - { - sprintf(ntxt, "%d %s", i+1, savestates[i].date); - UpdateSaveStateMenu(i, ntxt); - } - } -} - - #ifdef EXPERIMENTAL_GBASLOT BOOL LoadROM(char * filename) @@ -1249,7 +1193,6 @@ BOOL LoadROM(char * filename) BOOL LoadROM(char * filename, const char *cflash_disk_image) #endif { - ResetSaveStateTimes(); NDS_Pause(); //if (strcmp(filename,"")!=0) INFO("Attempting to load ROM: %s\n",filename); @@ -1260,7 +1203,6 @@ BOOL LoadROM(char * filename, const char *cflash_disk_image) #endif { INFO("Loading %s was successful\n",filename); - LoadSaveStateInfo(); frameCounter=0; lagframecounter=0; UpdateRecentRoms(filename); @@ -1297,8 +1239,6 @@ int MenuInit() recentromsmenu = LoadMenu(hAppInst, "RECENTROMS"); GetRecentRoms(); - ResetSaveStateTimes(); - return 1; } @@ -1322,17 +1262,14 @@ void SetLanguage(int langid) case 1: // French setLanguage(MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH), SORT_DEFAULT)); - SetThreadLocale(MAKELCID(MAKELANGID(LANG_FRENCH, SUBLANG_FRENCH), SORT_DEFAULT)); break; case 2: // Danish setLanguage(MAKELCID(MAKELANGID(LANG_DANISH, SUBLANG_DEFAULT), SORT_DEFAULT)); - SetThreadLocale(MAKELCID(MAKELANGID(LANG_DANISH, SUBLANG_DEFAULT), SORT_DEFAULT)); break; case 0: // English setLanguage(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)); - SetThreadLocale(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), SORT_DEFAULT)); break; default: break; break; @@ -2192,9 +2129,9 @@ int GetModifiers(int key) if (key == VK_MENU || key == VK_CONTROL || key == VK_SHIFT) return 0; - if(GetAsyncKeyState(VK_MENU )&0x8000) modifiers |= CUSTKEY_ALT_MASK; - if(GetAsyncKeyState(VK_CONTROL)&0x8000) modifiers |= CUSTKEY_CTRL_MASK; - if(GetAsyncKeyState(VK_SHIFT )&0x8000) modifiers |= CUSTKEY_SHIFT_MASK; + if(GetAsyncKeyState(VK_MENU )) modifiers |= CUSTKEY_ALT_MASK; + if(GetAsyncKeyState(VK_CONTROL)) modifiers |= CUSTKEY_CTRL_MASK; + if(GetAsyncKeyState(VK_SHIFT )) modifiers |= CUSTKEY_SHIFT_MASK; return modifiers; } @@ -2692,19 +2629,35 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM } return 0; case IDM_STATE_SAVE_F1: + HK_StateSaveSlot(1); + return 0; case IDM_STATE_SAVE_F2: + HK_StateSaveSlot(2); + return 0; case IDM_STATE_SAVE_F3: + HK_StateSaveSlot(3); + return 0; case IDM_STATE_SAVE_F4: + HK_StateSaveSlot(4); + return 0; case IDM_STATE_SAVE_F5: + HK_StateSaveSlot(5); + return 0; case IDM_STATE_SAVE_F6: + HK_StateSaveSlot(6); + return 0; case IDM_STATE_SAVE_F7: + HK_StateSaveSlot(7); + return 0; case IDM_STATE_SAVE_F8: + HK_StateSaveSlot(8); + return 0; case IDM_STATE_SAVE_F9: + HK_StateSaveSlot(9); + return 0; case IDM_STATE_SAVE_F10: - HK_StateSaveSlot( abs(IDM_STATE_SAVE_F1 - LOWORD(wParam)) +1); - LoadSaveStateInfo(); - return 0; - + HK_StateSaveSlot(10); + return 0; case IDM_STATE_LOAD_F1: HK_StateLoadSlot(1); return 0; @@ -3103,10 +3056,11 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM CheckLanguage(LOWORD(wParam)); return 0; case IDC_FRAMELIMIT: + { FrameLimit ^= 1; MainWindow->checkMenu(IDC_FRAMELIMIT, FrameLimit ? MF_CHECKED : MF_UNCHECKED); WritePrivateProfileInt("FrameLimit", "FrameLimit", FrameLimit, IniName); - return 0; + } case IDM_SCREENSEP_NONE: { SetScreenGap(0); diff --git a/desmume/src/windows/main.h b/src/windows/main.h similarity index 100% rename from desmume/src/windows/main.h rename to src/windows/main.h diff --git a/desmume/src/windows/mapView.cpp b/src/windows/mapView.cpp similarity index 100% rename from desmume/src/windows/mapView.cpp rename to src/windows/mapView.cpp diff --git a/desmume/src/windows/mapView.h b/src/windows/mapView.h similarity index 100% rename from desmume/src/windows/mapView.h rename to src/windows/mapView.h diff --git a/desmume/src/windows/matrixView.cpp b/src/windows/matrixView.cpp similarity index 100% rename from desmume/src/windows/matrixView.cpp rename to src/windows/matrixView.cpp diff --git a/desmume/src/windows/matrixView.h b/src/windows/matrixView.h similarity index 100% rename from desmume/src/windows/matrixView.h rename to src/windows/matrixView.h diff --git a/desmume/src/windows/memView.cpp b/src/windows/memView.cpp similarity index 99% rename from desmume/src/windows/memView.cpp rename to src/windows/memView.cpp index d7d794cb3..a23d58d3f 100644 --- a/desmume/src/windows/memView.cpp +++ b/src/windows/memView.cpp @@ -88,6 +88,7 @@ void MemView_DeInit() BOOL MemView_DlgOpen(HWND hParentWnd, char *Title, u8 CPU) { HWND hDlg; + char title[32]; MemView_Data[CPU] = new MemView_DataStruct(CPU); if(MemView_Data[CPU] == NULL) diff --git a/desmume/src/windows/memView.h b/src/windows/memView.h similarity index 100% rename from desmume/src/windows/memView.h rename to src/windows/memView.h diff --git a/desmume/src/windows/mic.cpp b/src/windows/mic.cpp similarity index 100% rename from desmume/src/windows/mic.cpp rename to src/windows/mic.cpp diff --git a/desmume/src/windows/oamView.cpp b/src/windows/oamView.cpp similarity index 100% rename from desmume/src/windows/oamView.cpp rename to src/windows/oamView.cpp diff --git a/desmume/src/windows/oamView.h b/src/windows/oamView.h similarity index 100% rename from desmume/src/windows/oamView.h rename to src/windows/oamView.h diff --git a/desmume/src/windows/ogl.cpp b/src/windows/ogl.cpp similarity index 100% rename from desmume/src/windows/ogl.cpp rename to src/windows/ogl.cpp diff --git a/desmume/src/windows/palView.cpp b/src/windows/palView.cpp similarity index 100% rename from desmume/src/windows/palView.cpp rename to src/windows/palView.cpp diff --git a/desmume/src/windows/palView.h b/src/windows/palView.h similarity index 100% rename from desmume/src/windows/palView.h rename to src/windows/palView.h diff --git a/desmume/src/windows/resource.h b/src/windows/resource.h similarity index 99% rename from desmume/src/windows/resource.h rename to src/windows/resource.h index 205811e3a..5f26d4430 100644 --- a/desmume/src/windows/resource.h +++ b/src/windows/resource.h @@ -155,7 +155,6 @@ #define IDD_EMULATIONSETTINGS 916 #define IDD_WIFISETTINGS 918 #define IDD_MEM_VIEW 920 -#define IDD_CHEAT_ADD_XX_CODE 921 #define IDC_BGMAP_SEL 1000 #define IDC_BRIDGEADAPTER 1000 #define IDC_EDIT03 1000 @@ -371,7 +370,9 @@ #define IDC_LIGHT_VIEWER_LIGHT1COLOR_COLORCTRL 1312 #define IDD_CHEAT_SEARCH 1312 #define IDC_LIGHT_VIEWER_LIGHT1COLOR_EDIT 1313 +#define IDD_CHEAT_ADD_AR_CODE 1313 #define IDC_LIGHT_VIEWER_LIGHT1VECTOR_EDIT 1314 +#define IDD_CHEAT_ADD_BC_CODE 1314 #define IDC_LIGHT_VIWER_LIGHT2_GROUP 1321 #define IDC_LIGHT_VIEWER_LIGHT2COLOR_COLORCTRL 1322 #define IDC_LIGHT_VIEWER_LIGHT2COLOR_EDIT 1323 diff --git a/desmume/src/windows/resources.rc b/src/windows/resources.rc similarity index 97% rename from desmume/src/windows/resources.rc rename to src/windows/resources.rc index 2fe3ba0ca..6b1758a9a 100644 --- a/desmume/src/windows/resources.rc +++ b/src/windows/resources.rc @@ -583,10 +583,10 @@ RECENTROMS MENU // Dialog resources // LANGUAGE LANG_DANISH, SUBLANG_DANISH_DENMARK -IDD_3DSETTINGS DIALOGEX 0, 0, 174, 120 +IDD_3DSETTINGS DIALOG 0, 0, 174, 120 STYLE DS_MODALFRAME | DS_SETFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU CAPTION "3D settings" -FONT 8, "MS Sans Serif", 0, 0, 0 +FONT 8, "MS Sans Serif" { DEFPUSHBUTTON "OK", IDOK, 62, 92, 50, 14, BS_DEFPUSHBUTTON PUSHBUTTON "Cancel", IDCANCEL, 117, 92, 50, 14, BS_PUSHBUTTON @@ -617,10 +617,10 @@ FONT 8, "MS Sans Serif", 0, 0, 0 LANGUAGE LANG_FRENCH, SUBLANG_FRENCH -IDD_3DSETTINGS DIALOGEX 0, 0, 174, 120 +IDD_3DSETTINGS DIALOG 0, 0, 174, 120 STYLE DS_MODALFRAME | DS_SETFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU CAPTION "Configuration 3D" -FONT 8, "MS Sans Serif", 0, 0, 0 +FONT 8, "MS Sans Serif" { DEFPUSHBUTTON "OK", IDOK, 62, 92, 50, 14, BS_DEFPUSHBUTTON PUSHBUTTON "Annuler", IDCANCEL, 117, 92, 50, 14, BS_PUSHBUTTON @@ -720,15 +720,32 @@ FONT 8, "MS Shell Dlg", 400, 0, 1 LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -IDD_CHEAT_ADD_XX_CODE DIALOGEX 0, 0, 121, 193 +IDD_CHEAT_ADD_AR_CODE DIALOGEX 0, 0, 121, 193 STYLE DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU CAPTION "Add Action Replay code" FONT 8, "MS Shell Dlg", 400, 0, 1 { - EDITTEXT IDC_EDIT2, 7, 17, 107, 97, WS_VSCROLL | ES_AUTOVSCROLL | ES_UPPERCASE | ES_MULTILINE | ES_WANTRETURN + EDITTEXT IDC_EDIT2, 7, 17, 107, 97, ES_AUTOHSCROLL EDITTEXT IDC_EDIT3, 7, 124, 107, 30, ES_MULTILINE AUTOCHECKBOX "turn on code", IDC_CHECK1, 47, 159, 67, 10, BS_AUTOCHECKBOX - DEFPUSHBUTTON "Add", IDOK, 7, 172, 50, 14, WS_DISABLED | BS_DEFPUSHBUTTON + DEFPUSHBUTTON "Add", IDOK, 7, 172, 50, 14, BS_DEFPUSHBUTTON + PUSHBUTTON "Cancel", IDCANCEL, 64, 172, 50, 14, BS_PUSHBUTTON + LTEXT "Code:", -1, 7, 7, 20, 8, SS_LEFT + LTEXT "Description:", -1, 9, 116, 39, 8, SS_LEFT +} + + + +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +IDD_CHEAT_ADD_BC_CODE DIALOGEX 0, 0, 121, 193 +STYLE DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_POPUP | WS_SYSMENU +CAPTION "Add Action Replay code" +FONT 8, "MS Shell Dlg", 400, 0, 1 +{ + EDITTEXT IDC_EDIT2, 7, 17, 107, 97, ES_AUTOHSCROLL + EDITTEXT IDC_EDIT3, 7, 124, 107, 30, ES_MULTILINE + AUTOCHECKBOX "turn on code", IDC_CHECK1, 47, 159, 67, 10, BS_AUTOCHECKBOX + DEFPUSHBUTTON "Add", IDOK, 7, 172, 50, 14, BS_DEFPUSHBUTTON PUSHBUTTON "Cancel", IDCANCEL, 64, 172, 50, 14, BS_PUSHBUTTON LTEXT "Code:", -1, 7, 7, 20, 8, SS_LEFT LTEXT "Description:", -1, 9, 116, 39, 8, SS_LEFT @@ -744,7 +761,7 @@ FONT 8, "MS Shell Dlg", 400, 0, 1 { CONTROL "", IDC_LIST1, WC_LISTVIEW, WS_TABSTOP | WS_BORDER | LVS_ALIGNLEFT | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | LVS_SINGLESEL | LVS_REPORT, 7, 7, 302, 103 PUSHBUTTON "internal", IDC_BADD, 10, 125, 50, 14, BS_PUSHBUTTON - PUSHBUTTON "Action Replay", IDC_BADD_AR, 66, 125, 67, 14, BS_PUSHBUTTON + PUSHBUTTON "Action Replay", IDC_BADD_AR, 66, 125, 67, 14, WS_DISABLED | BS_PUSHBUTTON PUSHBUTTON "Codebreaker", IDC_BADD_CB, 139, 125, 67, 14, WS_DISABLED | BS_PUSHBUTTON PUSHBUTTON "Edit", IDC_BEDIT, 245, 113, 64, 14, WS_DISABLED | BS_PUSHBUTTON PUSHBUTTON "Remove", IDC_BREMOVE, 246, 129, 63, 14, WS_DISABLED | BS_PUSHBUTTON diff --git a/desmume/src/windows/snddx.cpp b/src/windows/snddx.cpp similarity index 100% rename from desmume/src/windows/snddx.cpp rename to src/windows/snddx.cpp diff --git a/desmume/src/windows/snddx.h b/src/windows/snddx.h similarity index 100% rename from desmume/src/windows/snddx.h rename to src/windows/snddx.h diff --git a/desmume/src/windows/throttle.cpp b/src/windows/throttle.cpp similarity index 100% rename from desmume/src/windows/throttle.cpp rename to src/windows/throttle.cpp diff --git a/desmume/src/windows/throttle.h b/src/windows/throttle.h similarity index 100% rename from desmume/src/windows/throttle.h rename to src/windows/throttle.h diff --git a/desmume/src/windows/tileView.cpp b/src/windows/tileView.cpp similarity index 100% rename from desmume/src/windows/tileView.cpp rename to src/windows/tileView.cpp diff --git a/desmume/src/windows/tileView.h b/src/windows/tileView.h similarity index 100% rename from desmume/src/windows/tileView.h rename to src/windows/tileView.h diff --git a/desmume/src/windows/windriver.h b/src/windows/windriver.h similarity index 100% rename from desmume/src/windows/windriver.h rename to src/windows/windriver.h diff --git a/desmume/src/windows/winpcap/Devioctl.h b/src/windows/winpcap/Devioctl.h similarity index 100% rename from desmume/src/windows/winpcap/Devioctl.h rename to src/windows/winpcap/Devioctl.h diff --git a/desmume/src/windows/winpcap/Gnuc.h b/src/windows/winpcap/Gnuc.h similarity index 100% rename from desmume/src/windows/winpcap/Gnuc.h rename to src/windows/winpcap/Gnuc.h diff --git a/desmume/src/windows/winpcap/Ntddndis.h b/src/windows/winpcap/Ntddndis.h similarity index 100% rename from desmume/src/windows/winpcap/Ntddndis.h rename to src/windows/winpcap/Ntddndis.h diff --git a/desmume/src/windows/winpcap/Ntddpack.h b/src/windows/winpcap/Ntddpack.h similarity index 100% rename from desmume/src/windows/winpcap/Ntddpack.h rename to src/windows/winpcap/Ntddpack.h diff --git a/desmume/src/windows/winpcap/Packet.lib b/src/windows/winpcap/Packet.lib similarity index 100% rename from desmume/src/windows/winpcap/Packet.lib rename to src/windows/winpcap/Packet.lib diff --git a/desmume/src/windows/winpcap/Packet32.h b/src/windows/winpcap/Packet32.h similarity index 100% rename from desmume/src/windows/winpcap/Packet32.h rename to src/windows/winpcap/Packet32.h diff --git a/desmume/src/windows/winpcap/Win32-Extensions.h b/src/windows/winpcap/Win32-Extensions.h similarity index 100% rename from desmume/src/windows/winpcap/Win32-Extensions.h rename to src/windows/winpcap/Win32-Extensions.h diff --git a/desmume/src/windows/winpcap/bittypes.h b/src/windows/winpcap/bittypes.h similarity index 100% rename from desmume/src/windows/winpcap/bittypes.h rename to src/windows/winpcap/bittypes.h diff --git a/desmume/src/windows/winpcap/bucket_lookup.h b/src/windows/winpcap/bucket_lookup.h similarity index 100% rename from desmume/src/windows/winpcap/bucket_lookup.h rename to src/windows/winpcap/bucket_lookup.h diff --git a/desmume/src/windows/winpcap/count_packets.h b/src/windows/winpcap/count_packets.h similarity index 100% rename from desmume/src/windows/winpcap/count_packets.h rename to src/windows/winpcap/count_packets.h diff --git a/desmume/src/windows/winpcap/ip6_misc.h b/src/windows/winpcap/ip6_misc.h similarity index 100% rename from desmume/src/windows/winpcap/ip6_misc.h rename to src/windows/winpcap/ip6_misc.h diff --git a/desmume/src/windows/winpcap/memory_t.h b/src/windows/winpcap/memory_t.h similarity index 100% rename from desmume/src/windows/winpcap/memory_t.h rename to src/windows/winpcap/memory_t.h diff --git a/desmume/src/windows/winpcap/normal_lookup.h b/src/windows/winpcap/normal_lookup.h similarity index 100% rename from desmume/src/windows/winpcap/normal_lookup.h rename to src/windows/winpcap/normal_lookup.h diff --git a/desmume/src/windows/winpcap/pcap-bpf.h b/src/windows/winpcap/pcap-bpf.h similarity index 100% rename from desmume/src/windows/winpcap/pcap-bpf.h rename to src/windows/winpcap/pcap-bpf.h diff --git a/desmume/src/windows/winpcap/pcap-int.h b/src/windows/winpcap/pcap-int.h similarity index 100% rename from desmume/src/windows/winpcap/pcap-int.h rename to src/windows/winpcap/pcap-int.h diff --git a/desmume/src/windows/winpcap/pcap-stdinc.h b/src/windows/winpcap/pcap-stdinc.h similarity index 100% rename from desmume/src/windows/winpcap/pcap-stdinc.h rename to src/windows/winpcap/pcap-stdinc.h diff --git a/desmume/src/windows/winpcap/pcap.h b/src/windows/winpcap/pcap.h similarity index 100% rename from desmume/src/windows/winpcap/pcap.h rename to src/windows/winpcap/pcap.h diff --git a/desmume/src/windows/winpcap/remote-ext.h b/src/windows/winpcap/remote-ext.h similarity index 100% rename from desmume/src/windows/winpcap/remote-ext.h rename to src/windows/winpcap/remote-ext.h diff --git a/desmume/src/windows/winpcap/tcp_session.h b/src/windows/winpcap/tcp_session.h similarity index 100% rename from desmume/src/windows/winpcap/tcp_session.h rename to src/windows/winpcap/tcp_session.h diff --git a/desmume/src/windows/winpcap/time_calls.h b/src/windows/winpcap/time_calls.h similarity index 100% rename from desmume/src/windows/winpcap/time_calls.h rename to src/windows/winpcap/time_calls.h diff --git a/desmume/src/windows/winpcap/tme.h b/src/windows/winpcap/tme.h similarity index 100% rename from desmume/src/windows/winpcap/tme.h rename to src/windows/winpcap/tme.h diff --git a/desmume/src/windows/winpcap/wpcap.lib b/src/windows/winpcap/wpcap.lib similarity index 100% rename from desmume/src/windows/winpcap/wpcap.lib rename to src/windows/winpcap/wpcap.lib diff --git a/desmume/src/windows/zlib123/README b/src/windows/zlib123/README similarity index 100% rename from desmume/src/windows/zlib123/README rename to src/windows/zlib123/README diff --git a/desmume/src/windows/zlib123/zconf.h b/src/windows/zlib123/zconf.h similarity index 100% rename from desmume/src/windows/zlib123/zconf.h rename to src/windows/zlib123/zconf.h diff --git a/desmume/src/windows/zlib123/zlib-2005-x32.lib b/src/windows/zlib123/zlib-2005-x32.lib similarity index 100% rename from desmume/src/windows/zlib123/zlib-2005-x32.lib rename to src/windows/zlib123/zlib-2005-x32.lib diff --git a/desmume/src/windows/zlib123/zlib-2005-x64.lib b/src/windows/zlib123/zlib-2005-x64.lib similarity index 100% rename from desmume/src/windows/zlib123/zlib-2005-x64.lib rename to src/windows/zlib123/zlib-2005-x64.lib diff --git a/desmume/src/windows/zlib123/zlib-2008-x32.lib b/src/windows/zlib123/zlib-2008-x32.lib similarity index 100% rename from desmume/src/windows/zlib123/zlib-2008-x32.lib rename to src/windows/zlib123/zlib-2008-x32.lib diff --git a/desmume/src/windows/zlib123/zlib-2008-x64.lib b/src/windows/zlib123/zlib-2008-x64.lib similarity index 100% rename from desmume/src/windows/zlib123/zlib-2008-x64.lib rename to src/windows/zlib123/zlib-2008-x64.lib diff --git a/desmume/src/windows/zlib123/zlib.h b/src/windows/zlib123/zlib.h similarity index 100% rename from desmume/src/windows/zlib123/zlib.h rename to src/windows/zlib123/zlib.h diff --git a/desmume/src/windows/zlib123/zutil.h b/src/windows/zlib123/zutil.h similarity index 100% rename from desmume/src/windows/zlib123/zutil.h rename to src/windows/zlib123/zutil.h diff --git a/desmume/src/windows/zziplib/README b/src/windows/zziplib/README similarity index 100% rename from desmume/src/windows/zziplib/README rename to src/windows/zziplib/README diff --git a/desmume/src/windows/zziplib/zzip/_msvc.h b/src/windows/zziplib/zzip/_msvc.h similarity index 100% rename from desmume/src/windows/zziplib/zzip/_msvc.h rename to src/windows/zziplib/zzip/_msvc.h diff --git a/desmume/src/windows/zziplib/zzip/conf.h b/src/windows/zziplib/zzip/conf.h similarity index 100% rename from desmume/src/windows/zziplib/zzip/conf.h rename to src/windows/zziplib/zzip/conf.h diff --git a/desmume/src/windows/zziplib/zzip/types.h b/src/windows/zziplib/zzip/types.h similarity index 100% rename from desmume/src/windows/zziplib/zzip/types.h rename to src/windows/zziplib/zzip/types.h diff --git a/desmume/src/windows/zziplib/zzip/zzip.h b/src/windows/zziplib/zzip/zzip.h similarity index 100% rename from desmume/src/windows/zziplib/zzip/zzip.h rename to src/windows/zziplib/zzip/zzip.h diff --git a/desmume/src/windows/zziplib/zziplib-2005-x32.lib b/src/windows/zziplib/zziplib-2005-x32.lib similarity index 100% rename from desmume/src/windows/zziplib/zziplib-2005-x32.lib rename to src/windows/zziplib/zziplib-2005-x32.lib diff --git a/desmume/src/windows/zziplib/zziplib-2005-x64.lib b/src/windows/zziplib/zziplib-2005-x64.lib similarity index 100% rename from desmume/src/windows/zziplib/zziplib-2005-x64.lib rename to src/windows/zziplib/zziplib-2005-x64.lib diff --git a/desmume/src/windows/zziplib/zziplib-2008-x32.lib b/src/windows/zziplib/zziplib-2008-x32.lib similarity index 100% rename from desmume/src/windows/zziplib/zziplib-2008-x32.lib rename to src/windows/zziplib/zziplib-2008-x32.lib diff --git a/desmume/src/windows/zziplib/zziplib-2008-x64.lib b/src/windows/zziplib/zziplib-2008-x64.lib similarity index 100% rename from desmume/src/windows/zziplib/zziplib-2008-x64.lib rename to src/windows/zziplib/zziplib-2008-x64.lib