Emulator progress: main menu and title screen

This commit is contained in:
Lephenixnoir 2021-09-20 13:00:06 +02:00
parent 31daa78aa0
commit b870324682
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
11 changed files with 88 additions and 77 deletions

View File

@ -1,4 +1,5 @@
#include "cgdoom-frag.h"
#include "cgdoom.h"
#include "os.h"
#include "w_wad.h"
@ -7,6 +8,8 @@ int CGD_Frag_Map(const char *lumpname, CGD_Frag *frag)
int lump = W_CheckNumForName(lumpname);
if(lump < 0)
return 1;
if(CGD_WADMethod == CGDOOM_WAD_BFILE)
return 1;
lumpinfo_t *l = &lumpinfo[lump];
int size = l->size;

View File

@ -110,7 +110,7 @@ typedef struct {
} FileMapping;
/* WAD file access method. */
static int gWADmethod = CGDOOM_WAD_MMAP;
int CGD_WADMethod = CGDOOM_WAD_MMAP;
/* File descriptor to WAD, used in Flash_ReadFile calls. (CGDOOM_WAD_BFILE) */
static int gWADfd = -1;
/* Memory map of WAD file. (CGDOOM_WAD_MMAP) */
@ -322,7 +322,7 @@ int FindFragmentInMap(FileMapping *map, int sector_number)
int FindInFlash(const void **buf, int size, int readpos)
{
if(gWADmethod == CGDOOM_WAD_BFILE)
if(CGD_WADMethod == CGDOOM_WAD_BFILE)
return 0;
ASSERT(readpos >= 0);
@ -374,7 +374,7 @@ void abort(void){
int Flash_ReadFile(void *buf, int size, int readpos)
{
if(gWADmethod == CGDOOM_WAD_BFILE)
if(CGD_WADMethod == CGDOOM_WAD_BFILE)
return Bfile_ReadFile_OS(gWADfd, buf, size, readpos);
const void *pSrc;
@ -495,7 +495,7 @@ int main(void)
if(!strncmp(osv, "03.", 3) && osv[3] <= '6') // 3.60 or earlier
enable_2MBline = &CGD_2MBLineMemory;
int choice = UI_Main(wads, wad_count, &dev_info, &gWADmethod,
int choice = UI_Main(wads, wad_count, &dev_info, &CGD_WADMethod,
&startmap, &startepisode, &CGD_TrustUnalignedLumps, &autostart_,
&CGD_EnableDemos, enable_2MBline);
if(choice < 0)
@ -505,7 +505,7 @@ int main(void)
/* Parameters unavailable on the SDL2 build */
#ifdef CG_EMULATOR
gWADmethod = CGDOOM_WAD_BFILE;
CGD_WADMethod = CGDOOM_WAD_BFILE;
CGD_TrustUnalignedLumps = 0;
CGD_2MBLineMemory = 0;
#endif
@ -537,7 +537,7 @@ int main(void)
CGD_WADFileName = wad_name;
/* Setup access to WAD file */
if(gWADmethod == CGDOOM_WAD_BFILE)
if(CGD_WADMethod == CGDOOM_WAD_BFILE)
{
gWADfd = Bfile_OpenFile_OS(wads[choice].path, 0, 0);
}
@ -650,7 +650,5 @@ int main(void)
}
prof_quit();
return 1;
return EXIT_SUCCESS;
}
//todo: wrapper pro (patch_t*), + flash

View File

@ -47,6 +47,8 @@ extern struct CGD_Stats CGD_Stats;
// CGDoom options (some more are specified in platform.h)
/* File access method */
extern int CGD_WADMethod;
/* Enable demos in the title screen (most are incompatible and look bad) */
extern int CGD_EnableDemos;
/* The selected WAD is a split Ultimate Doom WAD with a single episode (this

View File

@ -279,7 +279,7 @@ void D_DoomLoop (void)
D_Display ();
}
// I_ShutdownGraphics();
free(lumpinfo);
Z_Free(lumpinfo);
CGD_PRAM_Free(lumpcache);
I_ShutdownGraphics();
return;

View File

@ -41,8 +41,6 @@
#endif
#include "i_system.h"
#define RAM_I_Zone_SIZE SYSTEM_STACK_SIZE
int contrast_change= 0;
int map_mode= 0;
unsigned short timer_def_one;
@ -56,12 +54,6 @@ ticcmd_t* I_BaseTiccmd(void)
return &emptycmd;
}
int I_GetHeapSize (void)
{
return RAM_I_Zone_SIZE;
}
#ifdef CG_EMULATOR
/* On the native build, simply reserve a large enough region of heap. */
@ -95,9 +87,8 @@ byte* I_ZoneBase (int* size, int i)
if (i-- == 0)
{
/* System stack (~500 kiB) */
*size = RAM_I_Zone_SIZE;
mb_mainzone = (byte *) SystemStack;
ASSERT(RAM_I_Zone_SIZE <= SYSTEM_STACK_SIZE);
*size = SYSTEM_STACK_SIZE;
mb_mainzone = (byte *)SystemStack;
return mb_mainzone;
}
if (i-- == 0)
@ -213,6 +204,7 @@ void I_Error (const char *error, ...)
#ifdef CG_EMULATOR
printf("Error: ");
vprintf(error, args);
printf("\n");
#else
I_ShutdownGraphics();
UI_Error(error, args);
@ -220,7 +212,6 @@ void I_Error (const char *error, ...)
#endif
va_end(args);
//I_Quit();
}
//

View File

@ -61,7 +61,7 @@ void I_SetPalette(byte* pal)
}
}
#if !defined(CG_EMULATOR) && defined(CGDOOM_DIRECT_R61524)
#ifdef CGDOOM_DIRECT_R61524
#define SYNCO() __asm__ volatile("synco":::"memory");
#define PRDR *(volatile uint8_t *)0xA405013C
@ -174,7 +174,7 @@ void I_ReinitAfterError(void)
st_firsttime = true;
}
#else /* fx-CG 50 without direct-DD access */
#else /* CGDOOM_DIRECT_R61524 */
void I_Flip (void)
{
@ -221,7 +221,7 @@ void I_ReinitAfterError(void)
Bdisp_PutDisp_DD();
}
#endif
#endif /* CGDOOM_DIRECT_R61524 */
//

View File

@ -484,13 +484,13 @@ void R_InitTextures (void)
numtextures = numtextures1 + numtextures2;
/* CGDoom: Allocate all of these in PRAM, since they have 4-byte elements */
textures = (texture_t **)CGD_PRAM_Malloc (numtextures*4);
texturecolumnlump = (short**)CGD_PRAM_Malloc (numtextures*4);
texturecolumnofs = (unsigned short**)CGD_PRAM_Malloc (numtextures*4);
texturecomposite = (byte**)CGD_PRAM_Malloc (numtextures*4);
texturecompositesize = (int*)CGD_PRAM_Malloc (numtextures*4);
texturewidthmask = (int*)CGD_PRAM_Malloc (numtextures*4);
textureheight = (fixed_t*)CGD_PRAM_Malloc (numtextures*4);
textures = (texture_t **)CGD_PRAM_Malloc (numtextures*sizeof(void *));
texturecolumnlump = (short**)CGD_PRAM_Malloc (numtextures*sizeof(void *));
texturecolumnofs = (unsigned short**)CGD_PRAM_Malloc (numtextures*sizeof(void *));
texturecomposite = (byte**)CGD_PRAM_Malloc (numtextures*sizeof(void *));
texturecompositesize = (int*)CGD_PRAM_Malloc (numtextures*sizeof(void *));
texturewidthmask = (int*)CGD_PRAM_Malloc (numtextures*sizeof(void *));
textureheight = (fixed_t*)CGD_PRAM_Malloc (numtextures*sizeof(void *));
totalwidth = 0;
@ -577,7 +577,7 @@ void R_InitTextures (void)
R_GenerateLookup (i);
// Create translation table for global animation.
texturetranslation = (int *)CGD_PRAM_Malloc ((numtextures+1)*4);
texturetranslation = (int *)CGD_PRAM_Malloc ((numtextures+1)*sizeof(void *));
for (i=0 ; i<numtextures ; i++)
texturetranslation[i] = i;

View File

@ -352,7 +352,7 @@ void R_InitTranslationTables (void)
int i;
translationtables = (byte *)Z_Malloc (256*3+255, PU_STATIC, 0);
translationtables = (byte *)(( (int)translationtables + 255 )& ~255);
translationtables = (byte *)(( (uintptr_t)translationtables + 255 )& ~255);
// translate just the 16 green colors
for (i=0 ; i<256 ; i++)

View File

@ -230,7 +230,6 @@ void* Z_Malloc( int size, int tag, void* user )
prof_enter(CGD_Perf.DynamicAllocation);
CGD_Stats.MemoryAllocated += size;
static int iCalled = 0;
int extra;
memblock_t* start;
memblock_t* rover;
@ -238,18 +237,6 @@ void* Z_Malloc( int size, int tag, void* user )
memblock_t* base;
size = (size + 3) & ~3;
iCalled++;
#ifdef CG_EMULATOR
{
static int iMaxFree = 1024*1024;
int iF = Z_FreeMemory(-1);
if(iF < iMaxFree)
{
iMaxFree = iF;
}
printf("Z_Malloc[%u]: %u [%u,max:%u]\n",iCalled,size,iF,iMaxFree);
}
#endif
// scan through the block list,
// looking for the first free block

View File

@ -67,14 +67,14 @@ void Bdisp_PutDisp_DD(void)
for(int x = 0; x < WIDTH; x++)
{
int rgb565 = VRAM[WIDTH * y + x];
int r = (rgb565 >> 8) & 0xf8;
int g = (rgb565 >> 3) & 0xfc;
int b = (rgb565 << 3) & 0xf8;
int r = (rgb565 >> 8) & 0xf8;
int g = (rgb565 >> 3) & 0xfc;
int b = (rgb565 << 3) & 0xf8;
Uint8 *rgb888 = VRAM_RGB888->pixels + y * VRAM_RGB888->pitch + 3 * x;
rgb888[0] = r;
rgb888[1] = g;
rgb888[2] = b;
Uint8 *rgb888 = VRAM_RGB888->pixels + y * VRAM_RGB888->pitch + 3 * x;
rgb888[0] = b;
rgb888[1] = g;
rgb888[2] = r;
}
SDL_BlitSurface(VRAM_RGB888, NULL, SDL_GetWindowSurface(window), NULL);
@ -90,7 +90,7 @@ int Bdisp_FrameAndColor(int p1, int p2)
void Bdisp_AllClr_VRAM(void)
{
memset(_VRAM, 0, WIDTH * HEIGHT * 2);
memset(_VRAM, 0xff, WIDTH * HEIGHT * 2);
}
/* Keyboard system emulation. */
@ -111,16 +111,20 @@ void GetKey(int *key)
while(!valid)
{
SDL_WaitEvent(&e);
if(e.type == SDL_QUIT ||
(e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE))
exit(0);
if(e.type != SDL_KEYDOWN) continue;
valid = 1;
switch((sym = e.key.keysym.sym))
{
case SDL_SCANCODE_UP: *key = KEY_CTRL_UP;
case SDL_SCANCODE_RIGHT: *key = KEY_CTRL_RIGHT;
case SDL_SCANCODE_DOWN: *key = KEY_CTRL_DOWN;
case SDL_SCANCODE_LEFT: *key = KEY_CTRL_LEFT;
case SDL_SCANCODE_RETURN: *key = KEY_CTRL_EXE;
case SDLK_UP: *key = KEY_CTRL_UP; break;
case SDLK_RIGHT: *key = KEY_CTRL_RIGHT; break;
case SDLK_DOWN: *key = KEY_CTRL_DOWN; break;
case SDLK_LEFT: *key = KEY_CTRL_LEFT; break;
case SDLK_RETURN: *key = KEY_CTRL_EXE; break;
default:
if(sym >= '0' && sym <= '9') *key = sym;
@ -163,6 +167,10 @@ static struct {
void Bfile_NameToStr_ncpy(char *dest, const uint16_t *source, size_t n)
{
size_t i = 0;
if(!memcmp(source, u"\\\\fls0\\", 14))
source += 7;
while(i < n && source[i] != 0x0000 && source[i] != 0xffff) {
dest[i] = source[i];
i++;
@ -173,6 +181,11 @@ void Bfile_NameToStr_ncpy(char *dest, const uint16_t *source, size_t n)
void Bfile_StrToName_ncpy(uint16_t *dest, const char *source, size_t n)
{
if(!strncmp(source, "\\\\fls0\\", 7)) {
memcpy(dest, u"\\\\fls0\\", 14);
dest += 7;
}
size_t i = 0;
while(i < n && source[i]) {
dest[i] = source[i];
@ -244,6 +257,7 @@ int Bfile_OpenFile_OS(const uint16_t *filename_u16, int mode, int zero)
return -1;
}
printf("Bfile_OpenFile_OS(): opened %s\n", filename_u8);
file_table[slot] = fp;
return slot;
}
@ -290,7 +304,6 @@ int Bfile_FindFirst(const uint16_t *pattern_u16, int *fd, uint16_t *found,
char pattern_u8[1024];
Bfile_NameToStr_ncpy(pattern_u8, pattern_u16, 1024);
int slot = 0;
while(slot < FILE_TABLE_MAX && search_table[slot].pos != 0)
slot++;
@ -302,6 +315,9 @@ int Bfile_FindFirst(const uint16_t *pattern_u16, int *fd, uint16_t *found,
int rc = glob(pattern_u8, 0, NULL, &search_table[slot].glob);
printf("Bfile_FindFirst(): Searching %s: %zu results\n", pattern_u8,
(rc == GLOB_NOMATCH) ? 0 : search_table[slot].glob.gl_pathc);
if(rc == GLOB_NOMATCH)
return -16;
@ -322,7 +338,15 @@ int Bfile_FindNext(int fd, uint16_t *found, void *fileinfo0)
(*pos)++;
Bfile_FileInfo *fileinfo = fileinfo0;
fileinfo->fsize = 0;
// TODO: More resonsable Bfile_FileInfo entries?
memset(fileinfo, 0, sizeof *fileinfo);
FILE *fp = fopen(name, "rb");
if(fp) {
fseek(fp, 0, SEEK_END);
fileinfo->fsize = ftell(fp);
fclose(fp);
}
return 0;
}

View File

@ -23,21 +23,21 @@ static int DoomKeyToKeycode(int key)
case KEY_RIGHTARROW: return SDL_SCANCODE_RIGHT;
case KEY_UPARROW: return SDL_SCANCODE_UP;
case KEY_DOWNARROW: return SDL_SCANCODE_DOWN;
/* case ' ': return KEYCODE_SQUARE;
case KEY_RCTRL: return KEYCODE_ALPHA;
case '1': return KEYCODE_F1;
case '2': return KEYCODE_F2;
case '3': return KEYCODE_F3;
case '4': return KEYCODE_F4;
case '5': return KEYCODE_F5;
case '6': return KEYCODE_F6;
case '7': return KEYCODE_SHIFT;
case KEY_TAB: return KEYCODE_EXIT;
case KEY_PAUSE: return KEYCODE_OPTN;
case KEY_SLEFTARROW: return KEYCODE_0;
case KEY_SRIGHTARROW: return KEYCODE_DOT;
case KEY_ESCAPE: return KEYCODE_MENU;
case KEY_ENTER: return KEYCODE_EXE; */
case ' ': return SDL_SCANCODE_SPACE;
// case KEY_RCTRL: return KEYCODE_ALPHA;
case '1': return SDL_SCANCODE_1;
case '2': return SDL_SCANCODE_2;
case '3': return SDL_SCANCODE_3;
case '4': return SDL_SCANCODE_4;
case '5': return SDL_SCANCODE_5;
case '6': return SDL_SCANCODE_6;
case '7': return SDL_SCANCODE_7;
case KEY_TAB: return SDL_SCANCODE_TAB;
// case KEY_PAUSE: return KEYCODE_OPTN;
// case KEY_SLEFTARROW: return KEYCODE_0;
// case KEY_SRIGHTARROW: return KEYCODE_DOT;
case KEY_ESCAPE: return SDL_SCANCODE_ESCAPE;
case KEY_ENTER: return SDL_SCANCODE_RETURN;
/* Special CGDoom keys */
/* case SKEY_CHEAT: return KEYCODE_POWER;
@ -61,6 +61,12 @@ static int KeyDown(Uint8 *state, int key)
void UpdateKeyboardState(void)
{
SDL_Event e;
while(SDL_PollEvent(&e)) {
if(e.type == SDL_QUIT)
exit(0);
}
free(st_prev);
st_prev = st_now;
st_now = ScanKeyboard();