From 868564ff088944c4c938ec624d92d04db39ff0c5 Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Fri, 10 Mar 2023 17:08:22 +0100 Subject: [PATCH] Add -v3 option for call graph data, change some function in neslib to inline --- include/nes/neslib.c | 24 ++++++++++++------------ include/nes/neslib.h | 22 +++++++++++----------- oscar64/Compiler.cpp | 3 ++- oscar64/CompilerTypes.h | 1 + oscar64/Declaration.h | 1 + oscar64/Linker.cpp | 5 ++++- oscar64/oscar64.cpp | 2 ++ 7 files changed, 33 insertions(+), 25 deletions(-) diff --git a/include/nes/neslib.c b/include/nes/neslib.c index a8af9e1..b62b324 100644 --- a/include/nes/neslib.c +++ b/include/nes/neslib.c @@ -18,30 +18,30 @@ const char palBrightTable[] = { 0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30 }; -char OAM_BUF[256]; -char PAL_BUF[32]; +volatile char OAM_BUF[256]; +volatile char PAL_BUF[32]; #pragma align(OAM_BUF, 256) char NTSC_MODE; volatile char FRAME_CNT1; volatile char FRAME_CNT2; -char VRAM_UPDATE; -char * NAME_UPD_ADR; -char NAME_UPD_ENABLE; -char PAL_UPDATE; -const char * PAL_BG_PTR; -const char * PAL_SPR_PTR; -char SCROLL_X; -char SCROLL_Y; +volatile char VRAM_UPDATE; +char * volatile NAME_UPD_ADR; +volatile char NAME_UPD_ENABLE; +volatile char PAL_UPDATE; +const char *volatile PAL_BG_PTR; +const char *volatile PAL_SPR_PTR; +volatile char SCROLL_X; +volatile char SCROLL_Y; char SCROLL_X1; char SCROLL_Y1; char PAD_STATE[2]; char PAD_STATEP[2]; char PAD_STATET[2]; -char PPU_CTRL_VAR; +volatile char PPU_CTRL_VAR; char PPU_CTRL_VAR1; -char PPU_MASK_VAR; +volatile char PPU_MASK_VAR; char RAND_SEED[2]; int main(void) diff --git a/include/nes/neslib.h b/include/nes/neslib.h index a08dcaa..04bb6c2 100644 --- a/include/nes/neslib.h +++ b/include/nes/neslib.h @@ -48,7 +48,7 @@ void pal_bg(const char *data); void pal_spr(const char *data); // set a palette entry, index is 0..31 -void pal_col(unsigned char index, unsigned char color); +inline void pal_col(unsigned char index, unsigned char color); // reset palette to $0f void pal_clear(void); @@ -83,7 +83,7 @@ void ppu_on_bg(void); void ppu_on_spr(void); // set PPU_MASK directly -void ppu_mask(unsigned char mask); +inline void ppu_mask(unsigned char mask); // get current video system, 0 for PAL, not 0 for NTSC unsigned char ppu_system(void); @@ -92,19 +92,19 @@ unsigned char ppu_system(void); unsigned char nesclock(void); // get/set the internal ppu ctrl cache var for manual writing -unsigned char get_ppu_ctrl_var(void); -void set_ppu_ctrl_var(unsigned char var); +inline unsigned char get_ppu_ctrl_var(void); +inline void set_ppu_ctrl_var(unsigned char var); // clear OAM buffer, all the sprites are hidden void oam_clear(void); // set sprite display mode, 0 for 8x8 sprites, 1 for 8x16 sprites -void oam_size(unsigned char size); +inline void oam_size(unsigned char size); // set sprite in OAM buffer, chrnum is tile, attr is attribute, sprid is offset in OAM in bytes // returns sprid+4, which is offset for a next sprite -unsigned char oam_spr(unsigned char x, unsigned char y, +inline unsigned char oam_spr(unsigned char x, unsigned char y, unsigned char chrnum, unsigned char attr, unsigned char sprid); @@ -147,7 +147,7 @@ unsigned char pad_poll(unsigned char pad); unsigned char pad_trigger(unsigned char pad); // get previous pad state without polling ports -unsigned char pad_state(unsigned char pad); +inline unsigned char pad_state(unsigned char pad); // set scroll, including rhe top bits @@ -195,7 +195,7 @@ void set_rand(unsigned int seed); // length of this data should be under 256 bytes -void set_vram_update(unsigned char *buf); +inline void set_vram_update(unsigned char *buf); // all following vram functions only work when display is disabled @@ -203,16 +203,16 @@ void set_vram_update(unsigned char *buf); void flush_vram_update(unsigned char *buf); // set vram pointer to write operations if you need to write some data to vram -void vram_adr(unsigned int adr); +inline void vram_adr(unsigned int adr); // put a byte at current vram address, works only when rendering is turned off -void vram_put(unsigned char n); +inline void vram_put(unsigned char n); // fill a block with a byte at current vram address, works only when rendering is turned off void vram_fill(unsigned char n, unsigned int len); // set vram autoincrement, 0 for +1 and not 0 for +32 -void vram_inc(unsigned char n); +inline void vram_inc(unsigned char n); // read a block from current address of vram, works only when rendering is turned off void vram_read(unsigned char *dst, unsigned int size); diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index ce248dc..38f87d6 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -516,7 +516,8 @@ bool Compiler::GenerateCode(void) mGlobalAnalyzer->CheckInterrupt(); mGlobalAnalyzer->AutoInline(); - //mGlobalAnalyzer->DumpCallGraph(); + if (mCompilerOptions & COPT_VERBOSE3) + mGlobalAnalyzer->DumpCallGraph(); mInterCodeGenerator->mCompilerOptions = mCompilerOptions; mNativeCodeGenerator->mCompilerOptions = mCompilerOptions; diff --git a/oscar64/CompilerTypes.h b/oscar64/CompilerTypes.h index edbc236..d4e99b8 100644 --- a/oscar64/CompilerTypes.h +++ b/oscar64/CompilerTypes.h @@ -25,6 +25,7 @@ static const uint64 COPT_TARGET_NES = 0x4000000000ULL; static const uint64 COPT_VERBOSE = 0x10000000000ULL; static const uint64 COPT_VERBOSE2 = 0x20000000000ULL; +static const uint64 COPT_VERBOSE3 = 0x40000000000ULL; static const uint64 COPT_NATIVE = 0x01000000; diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index ce9addf..080e422 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -80,6 +80,7 @@ static const uint64 DTF_FUNC_VARIABLE = (1ULL << 32); static const uint64 DTF_FUNC_ASSEMBLER = (1ULL << 33); static const uint64 DTF_FUNC_RECURSIVE = (1ULL << 34); static const uint64 DTF_FUNC_ANALYZING = (1ULL << 35); + static const uint64 DTF_FUNC_CONSTEXPR = (1ULL << 36); static const uint64 DTF_FUNC_INTRSAVE = (1ULL << 37); static const uint64 DTF_FUNC_INTRCALLED = (1ULL << 38); diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index 482a2ce..0164ea6 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -971,7 +971,10 @@ bool Linker::WriteMlbFile(const char* filename) for(int i=0; imRanges.Size(); i++) fprintf(file, "R:%04x-%04x:%s@%s\n", obj->mAddress + obj->mRanges[i].mOffset, obj->mAddress + obj->mRanges[i].mOffset + obj->mRanges[i].mSize - 1, obj->mIdent->mString, obj->mRanges[i].mIdent->mString); } - fprintf(file, "R:%04x-%04x:%s\n", obj->mAddress, obj->mAddress + obj->mSize - 1, obj->mIdent->mString); + if (obj->mSize > 1) + fprintf(file, "R:%04x-%04x:%s\n", obj->mAddress, obj->mAddress + obj->mSize - 1, obj->mIdent->mString); + else + fprintf(file, "R:%04x:%s\n", obj->mAddress, obj->mIdent->mString); } else if (obj->mType == LOT_DATA) { diff --git a/oscar64/oscar64.cpp b/oscar64/oscar64.cpp index 3968c0b..f848370 100644 --- a/oscar64/oscar64.cpp +++ b/oscar64/oscar64.cpp @@ -216,6 +216,8 @@ int main2(int argc, const char** argv) compiler->mCompilerOptions |= COPT_VERBOSE; if (arg[2] == '2') compiler->mCompilerOptions |= COPT_VERBOSE2; + else if (arg[2] == '3') + compiler->mCompilerOptions |= COPT_VERBOSE2 | COPT_VERBOSE3; } else if (arg[1] == 'x' && arg[2] == 'z') {