Skip to content

Commit 53cf1ea

Browse files
committed
Added a macro for NES header size to avoid having magic number 16 all over code. Fixed ld65 bank calculation to account for header.
1 parent b33b27c commit 53cf1ea

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/debug.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ int getBank(int offs)
266266
//Anything over FFFFF will kill it.
267267

268268
//GetNesFileAddress doesn't work well with Unif files
269-
int addr = GetNesFileAddress(offs)-16;
269+
int addr = GetNesFileAddress(offs)-NES_HEADER_SIZE;
270270

271271
if (GameInfo && GameInfo->type==GIT_NSF)
272272
return addr != -1 ? addr / 0x1000 : -1;
@@ -278,12 +278,12 @@ int GetNesFileAddress(int A){
278278
if((A < 0x6000) || (A > 0xFFFF))return -1;
279279
result = &Page[A>>11][A]-PRGptr[0];
280280
if((result > (int)(PRGsize[0])) || (result < 0))return -1;
281-
else return result+16; //16 bytes for the header remember
281+
else return result+NES_HEADER_SIZE; //16 bytes for the header remember
282282
}
283283

284284
int GetRomAddress(int A){
285285
int i;
286-
uint8 *p = GetNesPRGPointer(A-=16);
286+
uint8 *p = GetNesPRGPointer(A-=NES_HEADER_SIZE);
287287
for(i = 16;i < 32;i++){
288288
if((&Page[i][i<<11] <= p) && (&Page[i][(i+1)<<11] > p))break;
289289
}

src/debugsymboltable.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ int debugSymbolTable_t::loadGameSymbols(void)
749749

750750
if ( GameInfo != nullptr )
751751
{
752-
romSize = 16 + CHRsize[0] + PRGsize[0];
752+
romSize = NES_HEADER_SIZE + CHRsize[0] + PRGsize[0];
753753
}
754754

755755
loadFileNL( -1 );
@@ -934,7 +934,7 @@ void debugSymbolTable_t::ld65_SymbolLoad( ld65::sym *s )
934934
//printf("Symbol Label Load: name:\"%s\" val:%i 0x%x\n", s->name(), s->value(), s->value() );
935935
if (seg)
936936
{
937-
int romAddr = seg->ofs();
937+
int romAddr = seg->ofs() - NES_HEADER_SIZE;
938938

939939
bank = romAddr >= 0 ? romAddr / (1<<debuggerPageSize) : -1;
940940

@@ -968,7 +968,7 @@ void debugSymbolTable_t::ld65_SymbolLoad( ld65::sym *s )
968968

969969
if ( page->addSymbol( sym ) )
970970
{
971-
//printf("Failed to load sym: '%s'\n", s->name() );
971+
//printf("Failed to load sym: id:%i name:'%s' bank:%i \n", s->id(), s->name(), bank );
972972
delete sym;
973973
}
974974
}
@@ -982,6 +982,7 @@ int debugSymbolTable_t::ld65LoadDebugFile( const char *dbgFilePath )
982982
{
983983
return -1;
984984
}
985+
FCEU::autoScopedLock alock(cs);
985986

986987
db.iterateSymbols( this, ld65_iterate_cb );
987988

src/fceu.h

+1
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,5 @@ extern uint8 vsdip;
185185
#define EMULATIONPAUSED_FA 2
186186

187187
#define FRAMEADVANCE_DELAY_DEFAULT 10
188+
#define NES_HEADER_SIZE 16
188189

src/ld65dbg.h

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ namespace ld65
7070

7171
sym( int id, const char *name = nullptr, int size = 0, int value = 0, int type = IMPORT);
7272

73+
int id(void){ return _id; };
74+
7375
const char *name(void){ return _name.c_str(); };
7476

7577
int size(void){ return _size; };

0 commit comments

Comments
 (0)