From 5a7de6c53f1a6d71a1acb652c5a44efc734e50a2 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 22 May 2009 23:20:59 +0000 Subject: [PATCH] Win32 - Hex Editor - enabled & implemented the Save Rom As.. menu item. --- changelog.txt | 1 + src/drivers/win/memview.cpp | 32 ++++++++++++++++++++++++++++++++ src/drivers/win/res.rc | 2 +- src/ines.cpp | 27 +++++++++++++++++++++++++++ src/ines.h | 1 + 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index c34e674f..a508c4ac 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,4 @@ +22-may-2009 - adelikat - win32 - Hex Editor - Save Rom As... menu option enabled and implemented 22-may-2009 - adelikat - win32 - Window caption shows the name of the ROM loaded 22-may-2009 - adelikat - win32 - Hex Editor - allowed the user to customize the color scheme by use of RGB values stored in the .cfg file 21-may-2009 - adelikat - win32 - reverted fixedFontHeight to 13 instead of 14. Gave the option of adjusting the height by modifying RowHeightBorder in the .cfg file diff --git a/src/drivers/win/memview.cpp b/src/drivers/win/memview.cpp index f81a581a..3884e6bb 100644 --- a/src/drivers/win/memview.cpp +++ b/src/drivers/win/memview.cpp @@ -249,6 +249,37 @@ static int GetRomFileSize(){ //todo: fix or remove this? return 0; } + +void SaveRomAs() +{ + const char filter[]="NES ROM file (*.nes)\0*.nes\0"; + char nameo[2048]; + std::string tempName; + int x; + + OPENFILENAME ofn; + memset(&ofn,0,sizeof(ofn)); + ofn.lStructSize=sizeof(ofn); + ofn.hInstance=fceu_hInstance; + ofn.lpstrTitle="Save Nes ROM as..."; + ofn.lpstrFilter=filter; + strcpy(nameo,GetRomName()); + ofn.lpstrFile=nameo; + ofn.nMaxFile=256; + ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY; + ofn.hwndOwner = hMemView; + if (GetSaveFileName(&ofn)) + { + //if user did not add .nes, add it for them + tempName = nameo; + x = tempName.find_last_of(".nes"); + if (x < 0) + tempName.append(".nes"); + strcpy(nameo, tempName.c_str()); + iNesSaveAs(nameo); + } +} + //should return -1, otherwise returns the line number it had the error on int LoadTableFile(){ char str[50]; @@ -1357,6 +1388,7 @@ LRESULT CALLBACK MemViewCallB(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return 0; case MENU_MV_FILE_SAVE_AS: + SaveRomAs(); return 0; case MENU_MV_FILE_LOAD_TBL: diff --git a/src/drivers/win/res.rc b/src/drivers/win/res.rc index e2368dc2..7a2cfb29 100644 --- a/src/drivers/win/res.rc +++ b/src/drivers/win/res.rc @@ -241,7 +241,7 @@ BEGIN POPUP "&File" BEGIN MENUITEM "&Save Rom", MENU_MV_FILE_SAVE - MENUITEM "S&ave Rom As...", MENU_MV_FILE_SAVE_AS, INACTIVE + MENUITEM "S&ave Rom As...", MENU_MV_FILE_SAVE_AS MENUITEM "&Load *.TBL File", MENU_MV_FILE_LOAD_TBL MENUITEM "&Unload *.TBL file", MENU_MV_FILE_UNLOAD_TBL POPUP "&Dump to file" diff --git a/src/ines.cpp b/src/ines.cpp index 53ca4358..1a373bac 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -749,6 +749,33 @@ int iNesSave(){ return 1; } +int iNesSaveAs(char* name) +{ + //adelikat: TODO: iNesSave() and this have pretty much the same code, outsource the common code to a single function + FILE *fp; + + if(GameInfo->type != GIT_CART)return 0; + if(GameInterface!=iNESGI)return 0; + + fp = fopen(name,"wb"); + int x = 0; + if (!fp) + int x = 1; + if(fwrite(&head,1,16,fp)!=16)return 0; + + if(head.ROM_type&4) /* Trainer */ + { + fwrite(trainerpoo,512,1,fp); + } + + fwrite(ROM,0x4000,ROM_size,fp); + + if(head.VROM_size)fwrite(VROM,0x2000,head.VROM_size,fp); + fclose(fp); + + return 1; +} + //para edit: added function below char *iNesShortFName() { char *ret; diff --git a/src/ines.h b/src/ines.h index 91e6ac2d..516428af 100644 --- a/src/ines.h +++ b/src/ines.h @@ -74,6 +74,7 @@ extern uint8 *VROM; extern uint32 VROM_size; extern uint32 ROM_size; extern int iNesSave(); //bbit Edited: line added +extern int iNesSaveAs(char* name); extern char LoadedRomFName[2048]; //bbit Edited: line added //mbg merge 7/19/06 changed to c++ decl format