diff --git a/cgdoom/am_map.c b/cgdoom/am_map.c index f180d21..68b2b54 100644 --- a/cgdoom/am_map.c +++ b/cgdoom/am_map.c @@ -499,7 +499,7 @@ void AM_loadPics(void) char sBuf[8]; for (i=0;i<10;i++) { - CGDAppendNum09("AMMNUM",i,sBuf); + sprintf (sBuf, "AMMNUM%d", i); marknums[i] =W_CacheLumpNamePatch(sBuf, PU_STATIC); } } diff --git a/cgdoom/cgdoom-alloc.h b/cgdoom/cgdoom-alloc.h index 424ef4c..87c3b3c 100644 --- a/cgdoom/cgdoom-alloc.h +++ b/cgdoom/cgdoom-alloc.h @@ -1,7 +1,6 @@ #ifndef CGDOOM_ALLOC_H #define CGDOOM_ALLOC_H -#include "platform.h" #include /* The simple CGDoom allocator from SPU2 memory diff --git a/cgdoom/cgdoom-frag.c b/cgdoom/cgdoom-frag.c index c882b95..d243c94 100644 --- a/cgdoom/cgdoom-frag.c +++ b/cgdoom/cgdoom-frag.c @@ -32,7 +32,7 @@ int CGD_Frag_Map(const char *lumpname, CGD_Frag *frag) return 0; } -byte CGD_Frag_u8(CGD_Frag const *frag, int offset) +uint8_t CGD_Frag_u8(CGD_Frag const *frag, int offset) { int f = 0; while(frag->size[f] != 0 && offset >= frag->size[f]) { @@ -43,24 +43,24 @@ byte CGD_Frag_u8(CGD_Frag const *frag, int offset) if(frag->size[f] == 0) return 0; /* read out-of-bounds */ - const byte *data = frag->data[f]; + const uint8_t *data = frag->data[f]; return data[offset]; } short CGD_Frag_i16LE(CGD_Frag const *frag, int offset) { - byte b1 = CGD_Frag_u8(frag, offset); - byte b2 = CGD_Frag_u8(frag, offset + 1); + uint8_t b1 = CGD_Frag_u8(frag, offset); + uint8_t b2 = CGD_Frag_u8(frag, offset + 1); return (b2 << 8) | b1; } int CGD_Frag_i32LE(CGD_Frag const *frag, int offset) { - byte b1 = CGD_Frag_u8(frag, offset); - byte b2 = CGD_Frag_u8(frag, offset + 1); - byte b3 = CGD_Frag_u8(frag, offset + 2); - byte b4 = CGD_Frag_u8(frag, offset + 3); + uint8_t b1 = CGD_Frag_u8(frag, offset); + uint8_t b2 = CGD_Frag_u8(frag, offset + 1); + uint8_t b3 = CGD_Frag_u8(frag, offset + 2); + uint8_t b4 = CGD_Frag_u8(frag, offset + 3); return (b4 << 24) | (b3 << 16) | (b2 << 8) | b1; } diff --git a/cgdoom/cgdoom-frag.h b/cgdoom/cgdoom-frag.h index 68ae6f4..a7ba47a 100644 --- a/cgdoom/cgdoom-frag.h +++ b/cgdoom/cgdoom-frag.h @@ -1,7 +1,7 @@ #ifndef CGDOOM_FRAG_H #define CGDOOM_FRAG_H -#include "doomtype.h" +#include /* CGDoom's abstracted access to fragmented lumps @@ -37,7 +37,7 @@ typedef struct { int CGD_Frag_Map(const char *lumpname, CGD_Frag *frag); /* Read different types within the lump */ -byte CGD_Frag_u8(CGD_Frag const *frag, int offset); +uint8_t CGD_Frag_u8(CGD_Frag const *frag, int offset); short CGD_Frag_i16LE(CGD_Frag const *frag, int offset); int CGD_Frag_i32LE(CGD_Frag const *frag, int offset); diff --git a/cgdoom/cgdoom-ui.h b/cgdoom/cgdoom-ui.h index d50961f..9a8289a 100644 --- a/cgdoom/cgdoom-ui.h +++ b/cgdoom/cgdoom-ui.h @@ -1,7 +1,6 @@ #ifndef CGDOOM_UI_H #define CGDOOM_UI_H -#include "platform.h" #include "cgdoom.h" #include #include diff --git a/cgdoom/cgdoom.c b/cgdoom/cgdoom.c index 878fd64..6854f2f 100644 --- a/cgdoom/cgdoom.c +++ b/cgdoom/cgdoom.c @@ -6,127 +6,39 @@ #include "doomtype.h" #include "m_misc.h" +#include "d_main.h" -#ifndef CG_EMULATOR -# include "cgdoom-alloc.h" -# include "cgdoom-ui.h" -#endif +#include "cgdoom-alloc.h" +#include "cgdoom-ui.h" -void * CGDMalloc(int iSize) +void *CGD_malloc(int size) { - void *p = malloc(iSize); + void *p = malloc(size); if (!p) - I_Error ("CGDMalloc failure"); + I_Error ("CGD_malloc(%d) failure", size); return p; } -void * CGDCalloc(int iSize) +void *CGD_calloc(int size) { - void *p = CGDMalloc(iSize); - if(p != NULL) - { - memset(p,0,iSize); - } + void *p = CGD_malloc(size); + if(p) + memset(p, 0, size); return p; } - -void * CGDRealloc (void *p, int iSize) +void *CGD_realloc(void *p, int size) { if(p == NULL) - return malloc(iSize); + return malloc(size); else - return realloc(p,iSize); + return realloc(p, size); } unsigned short *VRAM; unsigned char *SaveVRAMBuffer; unsigned char *SystemStack; -void CGDAppendNum09(const char *pszText,int iNum,char *pszBuf) -{ - int i = 0; - while(pszText[i]) - { - pszBuf[i] = pszText[i]; - i++; - } - ASSERT(iNum < 10); - ASSERT(iNum >= 0); - pszBuf[i] = (char)('0'+iNum); - pszBuf[i+1] = 0; -} - -void CGDAppendNum0_999(const char *pszText,int iNum,int iMinDigits,char *pszBuf) -{ - int i = 0; - int z = 0; - while(pszText[i]) - { - pszBuf[i] = pszText[i]; - i++; - } - ASSERT(iNum < 1000000); - ASSERT(iNum >= 0); - if((iNum > 999999) || (iMinDigits>6)) - { - pszBuf[i] = (char)('0'+(iNum / 1000000)); - iNum %= 1000000; - i++; - z = 1; - } - if(z || (iNum > 99990) || (iMinDigits>5)) - { - pszBuf[i] = (char)('0'+(iNum / 100000)); - iNum %= 100000; - i++; - z = 1; - } - - if(z || (iNum > 9999) || (iMinDigits>4)) - { - pszBuf[i] = (char)('0'+(iNum / 10000)); - iNum %= 10000; - i++; - z = 1; - } - if(z || (iNum > 999) || (iMinDigits>3)) - { - pszBuf[i] = (char)('0'+(iNum / 1000)); - iNum %= 1000; - i++; - z = 1; - } - if(z || (iNum > 99) || (iMinDigits>2)) - { - pszBuf[i] = (char)('0'+(iNum / 100)); - iNum %= 100; - i++; - z = 1; - } - if(z || (iNum > 9) || (iMinDigits>1)) - { - pszBuf[i] = (char)('0'+(iNum / 10)); - iNum %= 10; - i++; - } - pszBuf[i] = (char)('0'+iNum); - pszBuf[i+1] = 0; -} - -void CGDAppendHex32(const char *pszText,int iNum,int iDigits,char *pszBuf) -{ - strcpy(pszBuf, pszText); - pszBuf += strlen(pszText); - for(int i = 0; i < iDigits; i++) - { - int c = (iNum >> (i * 4)) & 0xf; - c = c + '0' + 7 * (c > 9); - pszBuf[iDigits-i-1] = c; - } - pszBuf[iDigits] = 0; -} - int strnicmp(const char *s1,const char *s2,int count) { for(int i = 0; i < count; i++) { @@ -275,7 +187,7 @@ const void *ReadNextSector(FileAccessCache *fc, int *size) return NULL; } - *size = min(fc->size, FLASH_PAGE_SIZE); + *size = (fc->size < FLASH_PAGE_SIZE) ? fc->size : FLASH_PAGE_SIZE; fc->size -= *size; const void *sector = fc->data + fc->offset; fc->offset += *size; @@ -454,7 +366,8 @@ int FindInFlash(const void **buf, int size, int readpos) *buf = FLASH_CACHED_START + (gWADMap.mTable[iFragIndx].flash_address * FLASH_PAGE_SIZE) + iSubOffset; /* Return how many bytes can be read off the fragment (up to size). */ - int iAvailableLen = min(iFragEnd - readpos, size); + int iAvailableLen = (iFragEnd-readpos < size) ? iFragEnd-readpos : size; + ASSERT(iAvailableLen > 0); return iAvailableLen; } @@ -483,16 +396,6 @@ int Flash_ReadFile(void *buf, int size, int readpos) return iRet; } -void abort(void){ - int x=0,y=160; - PrintMini(&x,&y,"Abort called",0,0xFFFFFFFF,0,0,0xFFFF,0,1,0); - int key; - for(;;) - GetKey(&key); -} - -#endif /* CG_EMULATOR */ - static int FindZeroedMemory(void *start) { /* Look for zero-longwords every 16 bytes */ @@ -507,6 +410,16 @@ static int FindZeroedMemory(void *start) return size & ~0xfff; } +void abort(void){ + int x=0,y=160; + PrintMini(&x,&y,"Abort called",0,0xFFFFFFFF,0,0,0xFFFF,0,1,0); + int key; + for(;;) + GetKey(&key); +} + +#endif /* CG_EMULATOR */ + static void DelayedWriteFile(int i) { CGD_DelayedFileWrite const *dfw = &CGD_DelayedSaves[i]; diff --git a/cgdoom/cgdoom.h b/cgdoom/cgdoom.h index ee99b49..6d2a115 100644 --- a/cgdoom/cgdoom.h +++ b/cgdoom/cgdoom.h @@ -1,10 +1,10 @@ #ifndef CGDOOM_H #define CGDOOM_H -// CGDoom-specific definitions that cover both calculator and native builds. - -#include #include "libprof.h" +#include + +// CGDoom-specific definitions that cover both calculator and native builds. /* VRAM pointer and size */ extern uint16_t *VRAM; @@ -27,6 +27,16 @@ typedef struct int size; } CGD_DelayedFileWrite; +/* File access method (numbering is used in checkbox; keep as is) */ +enum { + /* Use BFile (100% accurate but slows down the game quite a bit because of + reads happening all the time; mostly a good reference for testing) */ + CGDOOM_WAD_BFILE = 0, + /* Search fragments in physical ROM when loading the game, and copy by hand + from ROM to RAM during accesses (much faster) */ + CGDOOM_WAD_MMAP = 1, +}; + /* Delay file saves until exit to avoid quitting immediately */ #define CGDOOM_DELAY_SAVES diff --git a/cgdoom/f_finale.c b/cgdoom/f_finale.c index d4990a0..badbb51 100644 --- a/cgdoom/f_finale.c +++ b/cgdoom/f_finale.c @@ -629,8 +629,7 @@ void F_BunnyScroll (void) laststage = stage; } - //sprintf (name,"END%i",stage); - CGDAppendNum09("END",stage,name); + sprintf (name,"END%d",stage); V_DrawPatch ((SCREENWIDTH-13*8)/2, (SCREENHEIGHT-8*8)/2,0, (const patch_t*)W_CacheLumpNameConst(name,PU_CACHE)); } diff --git a/cgdoom/hu_stuff.c b/cgdoom/hu_stuff.c index 015dede..7f91c3b 100644 --- a/cgdoom/hu_stuff.c +++ b/cgdoom/hu_stuff.c @@ -193,7 +193,7 @@ void HU_Init(void) j = HU_FONTSTART; for (i=0;inext) diff --git a/cgdoom/st_stuff.c b/cgdoom/st_stuff.c index bf0c8e1..9c4a265 100644 --- a/cgdoom/st_stuff.c +++ b/cgdoom/st_stuff.c @@ -940,12 +940,10 @@ void ST_loadGraphics(void) // Load the numbers, tall and short for (i=0;i<10;i++) { - //sprintf(namebuf, "STTNUM%d", i); - CGDAppendNum09("STTNUM",i,namebuf); + sprintf(namebuf, "STTNUM%d", i); tallnum[i] = W_CacheLumpNamePatch(namebuf, PU_STATIC); - //sprintf(namebuf, "STYSNUM%d", i); - CGDAppendNum09("STYSNUM",i,namebuf); + sprintf(namebuf, "STYSNUM%d", i); shortnum[i] = W_CacheLumpNamePatch(namebuf, PU_STATIC); } @@ -977,8 +975,7 @@ void ST_loadGraphics(void) arms_5 = shortnum[7]; // face backgrounds for different color players - //sprintf(namebuf, "STFB%d", consoleplayer); - CGDAppendNum09("STFB",consoleplayer,namebuf); + sprintf(namebuf, "STFB%d", consoleplayer); if (netgame) { faceback = W_CacheLumpNamePatch(namebuf, PU_STATIC); @@ -993,26 +990,18 @@ void ST_loadGraphics(void) { for (j=0;jname, fileinfo->name, 8); } - //Nspire has no alloca() function for temporary memory, so we have to use malloc() and free() to compensate free(fileinfo_mem); return 1; // CX port } diff --git a/cgdoom/wi_stuff.c b/cgdoom/wi_stuff.c index 7c8babd..bed1416 100644 --- a/cgdoom/wi_stuff.c +++ b/cgdoom/wi_stuff.c @@ -968,16 +968,13 @@ static void WI_loadData(void) { int i; int j; - char name[9]; + char name[17]; wi_stuff_anim_t* a; if (gamemode == commercial) strcpy(name, "INTERPIC"); else - { - //sprintf(name, "WIMAP%d", wbs->epsd); - CGDAppendNum09("WIMAP",wbs->epsd,name); - } + sprintf(name, "WIMAP%d", wbs->epsd); if ( gamemode == retail ) { @@ -1006,10 +1003,8 @@ static void WI_loadData(void) NUMCMAPS = 32; lnames = (const patch_t **) Z_Malloc(sizeof(patch_t*) * NUMCMAPS,PU_STATIC, 0); for (i=0 ; iepsd, i); - CGDAppendNum0_999("WILV",wbs->epsd*10+i,2,name); + sprintf(name, "WILV%d%d", wbs->epsd, i); lnames[i] = W_CacheLumpNamePatch(name, PU_STATIC); } @@ -1048,10 +1042,7 @@ static void WI_loadData(void) // MONDO HACK! if (wbs->epsd != 1 || j != 8) { - CGDAppendNum0_999("WIA",wbs->epsd,1,name); - CGDAppendNum0_999(name,j,2,name); - CGDAppendNum09(name,0,name); - CGDAppendNum0_999(name,i,1,name); + sprintf(name, "WIA%d%02d%02d", wbs->epsd, j, i); a->p[i] = W_CacheLumpNamePatch(name, PU_STATIC); } else @@ -1070,8 +1061,7 @@ static void WI_loadData(void) for (i=0;i<10;i++) { // numbers 0-9 - //sprintf(name, "WINUM%d", i); - CGDAppendNum09("WINUM",i,name); + sprintf(name, "WINUM%d", i); num[i] = W_CacheLumpNamePatch(name, PU_STATIC); } diff --git a/src-cg/platform.h b/src-cg/platform.h index 62e7eab..574abf9 100644 --- a/src-cg/platform.h +++ b/src-cg/platform.h @@ -6,16 +6,6 @@ // WAD file access in Flash //--- -/* File access method (numbering is used in checkbox; keep as is) */ -enum { - /* Use BFile (100% accurate but slows down the game quite a bit because of - reads happening all the time; mostly a good reference for testing) */ - CGDOOM_WAD_BFILE = 0, - /* Search fragments in physical ROM when loading the game, and copy by hand - from ROM to RAM during accesses (much faster) */ - CGDOOM_WAD_MMAP = 1, -}; - /* Settings for file mappings: traverse the whole 32-MiB Flash */ #define FLASH_START ((const void *)0xA0000000) #define FLASH_END ((const void *)0xA2000000) diff --git a/src-sdl2/libprof.c b/src-sdl2/libprof.c new file mode 100644 index 0000000..5cf789f --- /dev/null +++ b/src-sdl2/libprof.c @@ -0,0 +1,13 @@ +#include "libprof.h" + +uint64_t prof_current_time(void) +{ + struct timespec tp; + clock_gettime(CLOCK_REALTIME, &tp); + return (uint64_t)tp.tv_sec * 1000000000ull + tp.tv_nsec; +} + +uint32_t prof_time(prof_t prof) +{ + return -prof.elapsed / 1000; +} diff --git a/src-sdl2/libprof.h b/src-sdl2/libprof.h new file mode 100644 index 0000000..a00aa9a --- /dev/null +++ b/src-sdl2/libprof.h @@ -0,0 +1,42 @@ +//--- +// This is a dummy version of libprof for Linux with clock_gettime(2). +//--- + +#ifndef LIBPROF_LIBPROF +#define LIBPROF_LIBPROF + +#include +#include + +#define prof_init() +#define prof_quit() + +typedef struct prof_t +{ + int64_t elapsed; /* in nanoseconds, generally */ + uint32_t rec; +} prof_t; + +#define prof_make() ((prof_t){ 0, 0 }) + +uint64_t prof_current_time(void); + +#define prof_enter(prof) { \ + if(!prof.rec++) prof.elapsed += prof_current_time(); \ +} + +#define prof_leave(prof) { \ + if(!--prof.rec) prof.elapsed -= prof_current_time(); \ +} + +#define prof_exec(code) ({ \ + prof_t prof = prof_make(); \ + prof_enter(prof); \ + code; \ + prof_leave(prof); \ + prof_time(prof); \ +}) + +uint32_t prof_time(prof_t prof); + +#endif /* LIBPROF_LIBPROF */ diff --git a/src-sdl2/platform.h b/src-sdl2/platform.h index d6f2810..977d47a 100644 --- a/src-sdl2/platform.h +++ b/src-sdl2/platform.h @@ -1,9 +1,15 @@ +/* file for Linux/SDL2 */ +#ifndef PLATFORM_H +#define PLATFORM_H + #include #include #include #include #include "keyboard.hpp" +#include "../../../include/fxcg/file.h" + /* On the emulator all lumps are allocated with malloc(), so there are not pointers-to-flash to account for when freeing. */ #define PTR_TO_FLASH(p) 0 @@ -46,13 +52,8 @@ void assert(int iLine,const char *pszFilename,const char *pszAassert); #define ASSERT(x) if(!(x)){assert(__LINE__,__FILE__,#x);} -int Bfile_OpenFile_OS( const unsigned short*filename, int mode ); -int Bfile_SeekFile_OS( int HANDLE, int pos ); -int Bfile_ReadFile_OS( int HANDLE, void *buf, int size, int readpos ); -int Bfile_CloseFile_OS( int HANDLE ); - - extern const unsigned char *gpcFlashBuffer; void InitFlashSimu(const char *filename); +#endif /* PLATFORM_H */