diff --git a/desmume/src/GPU.c b/desmume/src/GPU.c
index 3123963bd..dfb503133 100644
--- a/desmume/src/GPU.c
+++ b/desmume/src/GPU.c
@@ -701,6 +701,7 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u8 * dst, u32 Y, u16 XBG, u16 Y
u16 yoff;
u16 x = 0;
u16 xfin;
+ u16 palette_size;
s8 line_dir = 1;
u8 pt_xor = 0;
@@ -812,51 +813,26 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u8 * dst, u32 Y, u16 XBG, u16 Y
}
return;
}
- if(!gpu->dispCnt.bits.ExBGxPalette_Enable) /* color: no extended palette */
+
+ palette_size=0; /* color: no extended palette */
+ if(gpu->dispCnt.bits.ExBGxPalette_Enable) /* color: extended palette */
{
- yoff = ((YBG&7)<<3);
- xfin = 8 - (xoff&7);
- for(x = 0; x < LG; xfin = min(x+8, LG))
- {
- tmp = (xoff & (lg-1))>>3;
- mapinfo = map + (tmp & 31) * 2;
- if(tmp > 31) mapinfo += 32*32*2;
- tileentry.val = T1ReadWord(mapinfo, 0);
-
- line = (u8 * )tile + (tileentry.bits.TileNum*0x40) + ((tileentry.bits.VFlip) ? (7*8)-yoff : yoff);
-
- if(tileentry.bits.HFlip)
- {
- line += (7 - (xoff&7));
- line_dir = -1;
- } else {
- line += (xoff&7);
- line_dir = 1;
- }
- for(; x < xfin; )
- {
- RENDERL((*line),0)
- line += line_dir;
- }
- }
- return;
+ palette_size=0x100;
+ pal = ARM9Mem.ExtPal[gpu->core][gpu->BGExtPalSlot[num]];
+ if(!pal) return;
}
- /* color: extended palette */
- pal = ARM9Mem.ExtPal[gpu->core][gpu->BGExtPalSlot[num]];
- if(!pal) return;
-
yoff = ((YBG&7)<<3);
xfin = 8 - (xoff&7);
for(x = 0; x < LG; xfin = min(x+8, LG))
{
- tmp = ((xoff&(lg-1))>>3);
- mapinfo = map + (tmp & 0x1F) * 2;
- if(tmp>31) mapinfo += 32 * 32 * 2;
+ tmp = (xoff & (lg-1))>>3;
+ mapinfo = map + (tmp & 31) * 2;
+ if(tmp > 31) mapinfo += 32*32*2;
tileentry.val = T1ReadWord(mapinfo, 0);
- line = (u8 * )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)
{
line += (7 - (xoff&7));
@@ -867,7 +843,7 @@ INLINE void renderline_textBG(GPU * gpu, u8 num, u8 * dst, u32 Y, u16 XBG, u16 Y
}
for(; x < xfin; )
{
- RENDERL((*line),0x100)
+ RENDERL((*line),palette_size)
line += line_dir;
}
}
@@ -933,19 +909,15 @@ void rot_BMP_map(GPU * gpu, int num, s32 auxX, s32 auxY, int lg, u8 * dst, u8 *
typedef void (*rot_fun)(GPU * gpu, int num, s32 auxX, s32 auxY, int lg, u8 * dst, u8 * map, u8 * tile, u8 * pal , int i, u16 H);
-INLINE void apply_rot_fun(GPU * gpu, u8 num, u8 * dst, u16 H, s32 X, s32 Y, s16 PA, s16 PB, s16 PC, s16 PD, u16 LG, rot_fun fun, u8 * map, u8 * tile, u8 * pal)
+INLINE void rot_scale_op(GPU * gpu, u8 num, u8 * dst, u16 H, s32 X, s32 Y, s16 PA, s16 PB, s16 PC, s16 PD, u16 LG, s32 wh, s32 ht, BOOL wrap, rot_fun fun, u8 * map, u8 * tile, u8 * pal)
{
ROTOCOORD x, y;
- struct _BGxCNT bgCnt = gpu->bgCnt[num].bits;
s32 dx = (s32)PA;
s32 dy = (s32)PC;
- s32 lg = gpu->BGSize[num][0];
- s32 ht = gpu->BGSize[num][1];
u32 i;
s32 auxX, auxY;
- if (!map) return;
x.val = X + (s32)PB*(s32)H;
y.val = Y + (s32)PD*(s32)H;
@@ -956,21 +928,30 @@ INLINE void apply_rot_fun(GPU * gpu, u8 num, u8 * dst, u16 H, s32 X, s32 Y, s16
auxX = x.bits.Integer;
auxY = y.bits.Integer;
- if(bgCnt.PaletteSet_Wrap)
+ if(wrap)
{
// wrap
- auxX = auxX & (lg-1);
+ auxX = auxX & (wh-1);
auxY = auxY & (ht-1);
}
- if ((auxX >= 0) && (auxX < lg) && (auxY >= 0) && (auxY < ht))
- fun(gpu, num, auxX, auxY, lg, dst, map, tile, pal, i, H);
+ if ((auxX >= 0) && (auxX < wh) && (auxY >= 0) && (auxY < ht))
+ fun(gpu, num, auxX, auxY, wh, dst, map, tile, pal, i, H);
dst += 2;
x.val += dx;
y.val += dy;
}
}
+INLINE void apply_rot_fun(GPU * gpu, u8 num, u8 * dst, u16 H, s32 X, s32 Y, s16 PA, s16 PB, s16 PC, s16 PD, u16 LG, rot_fun fun, u8 * map, u8 * tile, u8 * pal)
+{
+ struct _BGxCNT bgCnt = gpu->bgCnt[num].bits;
+ s32 wh = gpu->BGSize[num][0];
+ s32 ht = gpu->BGSize[num][1];
+ rot_scale_op(gpu, num, dst, H, X, Y, PA, PB, PC, PD, LG, wh, ht, bgCnt.PaletteSet_Wrap, fun, map, tile, pal);
+}
+
+
INLINE void rotBG2(GPU * gpu, u8 num, u8 * dst, u16 H, s32 X, s32 Y, s16 PA, s16 PB, s16 PC, s16 PD, u16 LG) {
u8 * map = gpu->BG_map_ram[num];
u8 * tile = (u8 *)gpu->BG_tile_ram[num];
@@ -1102,6 +1083,7 @@ INLINE void render_sprite_BMP (GPU * gpu, u16 l, u8 * dst, u16 * src,
}
}
+
INLINE void render_sprite_256 (GPU * gpu, u16 l, u8 * dst, u8 * src, u16 * pal,
u8 * prioTab, u8 prio, int lg, int sprX, int x, int xdir) {
int i; u8 palette_entry; u16 color;
diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h
index e9d3fa381..a1edae899 100644
--- a/desmume/src/MMU.h
+++ b/desmume/src/MMU.h
@@ -103,6 +103,14 @@ typedef struct {
extern MMU_struct MMU;
+
+static void mmu_select_savetype(int type, int *bmemtype, u32 *bmemsize) {
+ if (type<0 || type > 5) return;
+ *bmemtype=save_types[type][0];
+ *bmemsize=save_types[type][1];
+ mc_realloc(&MMU.bupmem, *bmemtype, *bmemsize);
+}
+
void MMUInit(void);
void MMUDeInit(void);
diff --git a/desmume/src/gtk-glade/callbacks.c b/desmume/src/gtk-glade/callbacks.c
index 256b6def5..2cd2004e3 100755
--- a/desmume/src/gtk-glade/callbacks.c
+++ b/desmume/src/gtk-glade/callbacks.c
@@ -152,6 +152,13 @@ void on_savestate8_activate (GtkMenuItem *m, gpointer d) { update_savestate(8);
void on_savestate9_activate (GtkMenuItem *m, gpointer d) { update_savestate(9); }
void on_savestate10_activate(GtkMenuItem *m, gpointer d) { update_savestate(10); }
+void on_savetype1_activate (GtkMenuItem *m, gpointer d) { desmume_savetype(1); }
+void on_savetype2_activate (GtkMenuItem *m, gpointer d) { desmume_savetype(2); }
+void on_savetype3_activate (GtkMenuItem *m, gpointer d) { desmume_savetype(3); }
+void on_savetype4_activate (GtkMenuItem *m, gpointer d) { desmume_savetype(4); }
+void on_savetype5_activate (GtkMenuItem *m, gpointer d) { desmume_savetype(5); }
+void on_savetype6_activate (GtkMenuItem *m, gpointer d) { desmume_savetype(6); }
+
/* MENU EMULATION ***** ***** ***** ***** */
void on_menu_exec_activate (GtkMenuItem *menuitem, gpointer user_data) { desmume_resume(); }
diff --git a/desmume/src/gtk-glade/callbacks.h b/desmume/src/gtk-glade/callbacks.h
index 2c3c806f3..3716b36c3 100755
--- a/desmume/src/gtk-glade/callbacks.h
+++ b/desmume/src/gtk-glade/callbacks.h
@@ -49,6 +49,12 @@ G_MODULE_EXPORT void on_savestate8_activate (GtkMenuItem *, gpointer );
G_MODULE_EXPORT void on_savestate9_activate (GtkMenuItem *, gpointer );
G_MODULE_EXPORT void on_savestate10_activate(GtkMenuItem *, gpointer );
+G_MODULE_EXPORT void on_savetype1_activate (GtkMenuItem *, gpointer );
+G_MODULE_EXPORT void on_savetype2_activate (GtkMenuItem *, gpointer );
+G_MODULE_EXPORT void on_savetype3_activate (GtkMenuItem *, gpointer );
+G_MODULE_EXPORT void on_savetype4_activate (GtkMenuItem *, gpointer );
+G_MODULE_EXPORT void on_savetype5_activate (GtkMenuItem *, gpointer );
+G_MODULE_EXPORT void on_savetype6_activate (GtkMenuItem *, gpointer );
diff --git a/desmume/src/gtk-glade/callbacks_IO.c b/desmume/src/gtk-glade/callbacks_IO.c
index 416b9a175..889a4b54f 100755
--- a/desmume/src/gtk-glade/callbacks_IO.c
+++ b/desmume/src/gtk-glade/callbacks_IO.c
@@ -33,10 +33,13 @@ int saveFS;
gboolean on_wMainW_key_press_event (GtkWidget *widget, GdkEventKey *event, gpointer user_data) {
u16 Key = lookup_key(event->keyval);
if (event->keyval == keyboard_cfg[KEY_BOOST-1]) {
- Boost != Boost;
- saveFS=Frameskip;
- if (Boost) Frameskip = BoostFS;
- else Frameskip = saveFS;
+ Boost = !Boost;
+ if (Boost) {
+ saveFS = Frameskip;
+ Frameskip = BoostFS;
+ } else {
+ Frameskip = saveFS;
+ }
}
ADD_KEY( Cur_Keypad, Key );
if(desmume_running()) update_keypad(Cur_Keypad);
diff --git a/desmume/src/gtk-glade/desmume.c b/desmume/src/gtk-glade/desmume.c
index 7f12c1742..d1e275a25 100755
--- a/desmume/src/gtk-glade/desmume.c
+++ b/desmume/src/gtk-glade/desmume.c
@@ -30,6 +30,8 @@ volatile BOOL execute = FALSE;
BOOL click = FALSE;
BOOL fini = FALSE;
unsigned long glock = 0;
+int savetype=MC_TYPE_AUTODETECT;
+u32 savesize=1;
void desmume_mem_init();
@@ -53,21 +55,28 @@ int desmume_open(const char *filename)
{
int i;
clear_savestates();
- i = NDS_LoadROM(filename, MC_TYPE_AUTODETECT, 1);
+ i = NDS_LoadROM(filename, savetype, savesize);
return i;
}
+void desmume_savetype(int type) {
+ mmu_select_savetype(type, &savetype, &savesize);
+}
+
+
void desmume_pause()
{
execute = FALSE;
+ SPU_Pause(1);
}
void desmume_resume()
{
- execute = TRUE;
-
- if(!regMainLoop)
- g_idle_add_full(EMULOOP_PRIO, &EmuLoop, NULL, NULL); regMainLoop = TRUE;
+ SPU_Pause(0);
+ execute = TRUE;
+ if(!regMainLoop)
+ g_idle_add_full(EMULOOP_PRIO, &EmuLoop, NULL, NULL);
+ regMainLoop = TRUE;
}
void desmume_reset()
@@ -100,48 +109,12 @@ void desmume_cycle()
SPU_Emulate();
}
-/////////////////////////////// TOOLS MANAGEMENT ///////////////////////////////
-#if 0
-//#include "dTool.h"
-
-extern const dTool_t *dTools_list[];
-extern const int dTools_list_size;
-
-BOOL *dTools_running;
-
-void Start_dTool(GtkWidget *widget, gpointer data)
-{
- int tool = GPOINTER_TO_INT(data);
-
- if(dTools_running[tool]) return;
-
- dTools_list[tool]->open(tool);
- dTools_running[tool] = TRUE;
-}
-
-void dTool_CloseCallback(int tool)
-{
- dTools_running[tool] = FALSE;
-}
-
-/////////////////////////////// MAIN EMULATOR LOOP ///////////////////////////////
-
-
-static inline void _updateDTools()
-{
- int i;
- for(i = 0; i < dTools_list_size; i++)
- {
- if(dTools_running[i]) { dTools_list[i]->update(); }
- }
-}
-#endif
-
Uint32 fps, fps_SecStart, fps_FrameCount;
static void Draw()
{
}
+
gboolean EmuLoop(gpointer data)
{
int i;
@@ -167,7 +140,6 @@ gboolean EmuLoop(gpointer data)
Draw();
- // _updateDTools();
notify_Tools();
gtk_widget_queue_draw(pDrawingArea);
gtk_widget_queue_draw(pDrawingArea2);
diff --git a/desmume/src/gtk-glade/desmume.h b/desmume/src/gtk-glade/desmume.h
index 84372421e..5b410237b 100755
--- a/desmume/src/gtk-glade/desmume.h
+++ b/desmume/src/gtk-glade/desmume.h
@@ -26,6 +26,7 @@ extern void desmume_init();
extern void desmume_free();
extern int desmume_open(const char *filename);
+extern void desmume_savetype(int type);
extern void desmume_pause();
extern void desmume_resume();
extern void desmume_reset();
diff --git a/desmume/src/gtk-glade/glade/DeSmuMe.glade b/desmume/src/gtk-glade/glade/DeSmuMe.glade
index 3c7c866f8..7fb97f31b 100755
--- a/desmume/src/gtk-glade/glade/DeSmuMe.glade
+++ b/desmume/src/gtk-glade/glade/DeSmuMe.glade
@@ -10,7 +10,7 @@
GTK_WINDOW_TOPLEVEL
GTK_WIN_POS_CENTER_ON_PARENT
False
- True
+ False
False
DeSmuME.xpm
True
@@ -98,119 +98,100 @@
@@ -394,7 +424,7 @@
-
+
True
gtk-refresh
1
@@ -431,7 +461,7 @@
True
0
True
- False
+ True
@@ -529,7 +559,7 @@
True
9
True
- True
+ False
fs0
@@ -553,7 +583,7 @@
True
1x
True
- False
+ True
@@ -574,7 +604,7 @@
True
3x
True
- True
+ False
size1x
@@ -605,7 +635,7 @@
-
+
True
gtk-preferences
1
@@ -626,7 +656,7 @@
-
+
True
gtk-preferences
1
@@ -700,7 +730,7 @@
-
+
True
gtk-properties
1
@@ -721,7 +751,7 @@
-
+
True
gtk-properties
1
@@ -742,7 +772,7 @@
-
+
True
gtk-properties
1
diff --git a/desmume/src/gtk-glade/main.c b/desmume/src/gtk-glade/main.c
index 9c4119249..bba89a553 100755
--- a/desmume/src/gtk-glade/main.c
+++ b/desmume/src/gtk-glade/main.c
@@ -146,7 +146,6 @@ void clear_savestate_menu(char * cb_name, u8 num)
sprintf( text, "State %d (empty)", num);
w = glade_xml_get_widget(xml, cb);
set_menuitem_label( w, text );
- gtk_check_menu_item_set_active((GtkCheckMenuItem*)w, FALSE);
}
void update_savestate_menu(char * cb_name, u8 num)
diff --git a/desmume/src/mc.h b/desmume/src/mc.h
index bd8a5e138..b403ad2b0 100644
--- a/desmume/src/mc.h
+++ b/desmume/src/mc.h
@@ -25,6 +25,15 @@ extern "C" {
#define MC_SIZE_16MBITS 0x200000
#define MC_SIZE_64MBITS 0x800000
+static int save_types[6][2] = {
+ {MC_TYPE_AUTODETECT,1},
+ {MC_TYPE_EEPROM1,MC_SIZE_4KBITS},
+ {MC_TYPE_EEPROM2,MC_SIZE_64KBITS},
+ {MC_TYPE_EEPROM2,MC_SIZE_512KBITS},
+ {MC_TYPE_FLASH,MC_SIZE_256KBITS},
+ {MC_TYPE_FRAM,MC_SIZE_2MBITS}
+};
+
typedef struct
{
u8 com; /* persistent command actually handled */
diff --git a/desmume/src/windows/main.c b/desmume/src/windows/main.c
index 8129d6860..f9721c848 100644
--- a/desmume/src/windows/main.c
+++ b/desmume/src/windows/main.c
@@ -34,6 +34,9 @@
#include "../MMU.h"
#include "../armcpu.h"
#include "../NDSSystem.h"
+#include "../debug.h"
+#include "../saves.h"
+#include "../cflash.h"
#include "resource.h"
#include "memView.h"
#include "disView.h"
@@ -42,10 +45,7 @@
#include "palView.h"
#include "tileView.h"
#include "oamView.h"
-#include "../debug.h"
#include "mapview.h"
-#include "../saves.h"
-#include "../cflash.h"
#include "ConfigKeys.h"
#include "snddx.h"
@@ -1211,39 +1211,27 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
case IDC_SAVETYPE1:
saver(MF_CHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED);
- backupmemorytype = MC_TYPE_AUTODETECT;
- backupmemorysize = 1;
- mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
+ mmu_select_savetype(0,&backupmemorytype,&backupmemorysize);
return 0;
case IDC_SAVETYPE2:
saver(MF_UNCHECKED,MF_CHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED);
- backupmemorytype = MC_TYPE_EEPROM1;
- backupmemorysize = MC_SIZE_4KBITS;
- mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
+ mmu_select_savetype(1,&backupmemorytype,&backupmemorysize);
return 0;
case IDC_SAVETYPE3:
saver(MF_UNCHECKED,MF_UNCHECKED,MF_CHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED);
- backupmemorytype = MC_TYPE_EEPROM2;
- backupmemorysize = MC_SIZE_64KBITS;
- mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
+ mmu_select_savetype(2,&backupmemorytype,&backupmemorysize);
return 0;
case IDC_SAVETYPE4:
saver(MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_CHECKED,MF_UNCHECKED,MF_UNCHECKED);
- backupmemorytype = MC_TYPE_EEPROM2;
- backupmemorysize = MC_SIZE_512KBITS;
- mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
+ mmu_select_savetype(3,&backupmemorytype,&backupmemorysize);
return 0;
case IDC_SAVETYPE5:
saver(MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_CHECKED,MF_UNCHECKED);
- backupmemorytype = MC_TYPE_FRAM;
- backupmemorysize = MC_SIZE_256KBITS;
- mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
+ mmu_select_savetype(4,&backupmemorytype,&backupmemorysize);
return 0;
case IDC_SAVETYPE6:
saver(MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_UNCHECKED,MF_CHECKED);
- backupmemorytype = MC_TYPE_FLASH;
- backupmemorysize = MC_SIZE_2MBITS;
- mc_realloc(&MMU.bupmem, backupmemorytype,backupmemorysize);
+ mmu_select_savetype(5,&backupmemorytype,&backupmemorysize);
return 0;
case IDM_RESET: