Progress in making the emulator build

This commit is contained in:
Lephenixnoir 2021-08-14 11:55:20 +02:00
parent a416d40eea
commit 2675d6d3aa
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
18 changed files with 225 additions and 127 deletions

Binary file not shown.

View File

@ -4,7 +4,7 @@
### Project structure.
NAME := CGDoom
SRC := $(wildcard cgdoom/*.c cgdoom/*.s)
SRC := $(wildcard cgdoom/*.c)
CFLAGS := -I cgdoom
# Extra optimization passes just in case
@ -36,7 +36,7 @@ CG_LDFLAGS += -nostartfiles -T $(LIBFXCG_ROOT)/toolchain/prizm.x
# Generate a map of every function and global variable for debugging
CG_LDFLAGS += -Wl,-Map=build-cg/$(NAME).map
CG_SRC := $(SRC) $(wildcard src-fxcg/*.c src-fxcg/*.s)
CG_SRC := $(SRC) $(wildcard src-cg/*.c src-cg/*.s)
CG_OBJ := $(CG_SRC:cgdoom/%=build-cg/%.o)
### Native SDL2 build.

View File

@ -1,5 +1,6 @@
#include "cgdoom-alloc.h"
#include "z_zone.h"
#include <stdint.h>
/* We use -fstrict-volatile-bitfields to enforce the 32-bit access size. */
struct node;

View File

@ -1,5 +1,6 @@
#include "cgdoom-ui.h"
#include <stdio.h>
#include <stdlib.h>
/* gint's font in a PrizmSDK-friendly (though ugly) form */
static uint8_t const font_width[96] = {
@ -51,6 +52,11 @@ static uint32_t const font_glyphs[263] = {
0x0,
};
static inline void SetPixel(int x, int y, int color)
{
VRAM[WIDTH * y + x] = color;
}
static void Font_RenderChar(int *x, int y, int c, int fg)
{
if(c < 32 || c >= 128)
@ -71,7 +77,7 @@ static void Font_RenderChar(int *x, int y, int c, int fg)
{
int b = font_glyphs[offset + (bit>>5)] & (0x80000000 >> (bit&31));
if (b)
Bdisp_SetPoint_VRAM(*x+dx, y+dy, fg);
SetPixel(*x+dx, y+dy, fg);
bit++;
}
@ -136,7 +142,7 @@ void UI_Checkbox(int x, int y, int checked)
if((dx == 0) || (dx == 7) || (dy == 0) || (dy == 7) ||
(checked && dx >= 2 && dx <= 5 && dy >= 2 && dy <= 5))
{
Bdisp_SetPoint_VRAM(x+dx, y+dy, 0x0000);
SetPixel(x+dx, y+dy, 0x0000);
}
}
}
@ -149,12 +155,12 @@ void UI_FileMappingProgressBar(int size_mapped, int size_total)
for(int x = x0; x < x0+w; x++)
{
Bdisp_SetPoint_VRAM(x, y0, COLOR_BLACK);
Bdisp_SetPoint_VRAM(x, y0+h-1, COLOR_BLACK);
SetPixel(x, y0, 0x0000);
SetPixel(x, y0+h-1, 0x0000);
if(x > pos && x != x0+w-1) continue;
for(int y = y0+1; y < y0+h-1; y++)
Bdisp_SetPoint_VRAM(x, y, COLOR_BLACK);
SetPixel(x, y, 0x0000);
}
Bdisp_PutDisp_DD();
}
@ -192,7 +198,7 @@ void Layout_EndFrame(Layout *l)
/* Draw cursor */
int x = LAYOUT_RIGHT - Font_StringLength(l->text + l->cursor);
for(int dy = 0; dy < 12; dy++)
Bdisp_SetPoint_VRAM(x, y+dy, 0x0000);
SetPixel(x, y+dy, 0x0000);
}
else
{

View File

@ -2,7 +2,9 @@
#define CGDOOM_UI_H
#include "platform.h"
#include "cgdoom.h"
#include <stdarg.h>
#include <stdint.h>
/* Basic rendering functions. */

View File

@ -1,7 +1,11 @@
#include "platform.h"
#include "os.h"
#include "cgdoom-ui.h"
#include "cgdoom-alloc.h"
#include "cgdoom.h"
#ifndef CG_EMULATOR
# include "cgdoom-alloc.h"
# include "cgdoom-ui.h"
#endif
#ifdef CG_EMULATOR
static int iAllocSum = 0;
@ -282,6 +286,8 @@ int CGDstrnicmp (const char*s1,const char*s2,int iLen)
// See <platform.h> for Flash traversal parameters.
///////////////////////////////////////////////////////////////////////////////
#ifndef CG_EMULATOR
//The whole sound doesn't fir onto the RAM.
//Reading per partes is not possible as this is synchronnous player (there would be silences when reading).
@ -599,15 +605,22 @@ void abort(void){
for(;;)
GetKey(&key);
}
#endif /* CG_EMULATOR */
///////////////////////////////////////////////////////////////////////////////////////////////////
int main(void){
int main(void)
{
startmap = 1;
startepisode = 1;
VRAM = (unsigned short*)GetVRAMAddress();
#ifdef CG_EMULATOR
InitFlashSimu("doom.wad");
#else
int time, ms_index=0, ms_mmap=0;
InitFlashSimu("doom.wad"); //load wad file to flash simulation on simulator, do nothing on real HW
#ifdef CG_EMULATOR
SaveVRAMBuffer = aSaveVRAMBuffer;
SystemStack = aSystemStack;
#else
EnableColor(1);
EnableStatusArea(3);
Bdisp_FrameAndColor(3, 16);
@ -616,11 +629,8 @@ int main(void){
WADFileInfo wads[16];
int wad_count = FindWADs(wads, 16);
extern int startmap, startepisode;
int dev_info = 0;
startmap = 1;
startepisode = 1;
int choice = UI_Main(wads, wad_count, &dev_info, &gWADmethod,
&startmap, &startepisode);
@ -631,8 +641,6 @@ int main(void){
SaveVRAMBuffer = (unsigned char*)tmp;
/* Graph 90+E: RAM starts at 0x0c000000 in physical memory */
SystemStack = (void *)0xac0f0000;
#endif
VRAM = (unsigned short*)GetVRAMAddress();
/* Setup access to WAD file */
if(gWADmethod == CGDOOM_WAD_BFILE)
@ -702,11 +710,15 @@ int main(void){
CGD_PRAM_Init(PRAM0_start, PRAM0_end);
}
#endif /* !CG_EMULATOR */
memset(VRAM, 0, WIDTH*HEIGHT*2);
D_DoomMain();
#ifndef CG_EMULATOR
if(gWADfd >= 0)
Bfile_CloseFile_OS(gWADfd);
#endif
return 1;
}

28
cgdoom/cgdoom.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef CGDOOM_H
#define CGDOOM_H
/* CGDoom-specific definitions that cover both calculator and native builds. */
#include <stdint.h>
/* VRAM pointer and size */
extern uint16_t *VRAM;
#define WIDTH 384
#define HEIGHT 216
/* Description of a WAD file selectable by user. */
typedef struct
{
char name[16];
uint16_t path[23];
int size;
} WADFileInfo;
// TODO: Move developer info here
/* Global variables interfacing with Doom itself. */
/* Map and episode to start at when loading the game. */
extern int startmap, startepisode;
#endif /* CGDOOM_H */

View File

@ -22,7 +22,8 @@
#include "os.h"
#include "platform.h"
#include <stdlib.h>
#include "doomdef.h"
#include "m_misc.h"
@ -58,7 +59,35 @@ int I_GetHeapSize (void)
return RAM_I_Zone_SIZE;
}
#ifdef CG_EMULATOR
/* On the native build, simply reserve a large enough region of heap. */
byte* I_ZoneBase (int* size, int i)
{
if (i == 0)
{
*size = (8 << 20);
return malloc(*size);
}
return NULL;
}
byte *I_ScreenBase(int screen)
{
if (screen == 0)
return malloc(320 * 200);
if (screen == 1)
return malloc(320 * 200);
if (screen == 4)
return malloc(320 * 32);
return NULL;
}
#else /* fx-CG build */
/* On the calculator, scrap every possible bit of RAM */
byte* I_ZoneBase (int* size, int i)
{
if (i == 0)
{
@ -75,7 +104,7 @@ byte* I_ZoneBase (int* size, int i)
*size = &eextra - &sextra;
return &sextra;
}
#ifdef CGDOOM_DIRECT_R61524
#ifdef CGDOOM_DIRECT_R61524
if (i == 2)
{
/* Secondary VRAM (screen buffers being in the main VRAM because we're
@ -83,10 +112,29 @@ byte* I_ZoneBase (int* size, int i)
*size = 384 * 216 * 2;
return SaveVRAMBuffer;
}
#endif
#endif
return NULL;
}
byte *I_ScreenBase(int screen)
{
/* The primary/secondary VRAM covers 384*216*2 = 162 kiB:
-> Give 320*200 = 64 kB to screens[0] (main display)
-> Give 320*200 = 64 kB to screens[1] (intermissions)
-> Give 320*32 = 10 kiB to screens[4] (status bar)
-> 27 kiB are left */
if (screen == 0)
return CGDOOM_SCREENS_BASE;
if (screen == 1)
return CGDOOM_SCREENS_BASE + 320*200;
if (screen == 4)
return CGDOOM_SCREENS_BASE + 320*200*2;
return NULL;
}
#endif
//
// I_Init
// Initialize machine state
@ -160,7 +208,7 @@ void I_ErrorI (const char *error, int i1,int i2,int i3,int i4)
#endif
}
void I_Error (char *error, ...)
void I_Error (const char *error, ...)
{
#ifdef CG_EMULATOR
/*// Message first.

View File

@ -41,6 +41,8 @@
// for the zone management.
byte* I_ZoneBase (int *size, int zone_no);
/* Extra CGDoom function supplying screen pointers from custom areas */
byte *I_ScreenBase(int screen);
// Called by D_DoomLoop,
// returns current time in tics.
@ -93,7 +95,7 @@ void I_ShowDBox(const char* title, const char* msg);
int toupper_int(int i);
//boolean access_ok(const char *file);
//void I_GetMainDir(char* dir);
void I_Error (char *error, ...);
void I_Error (const char *error, ...);
//CGD bastl/hack
void I_ErrorI (const char *error, int i1,int i2,int i3,int i4);

View File

@ -22,6 +22,7 @@
//-----------------------------------------------------------------------------
#include "os.h"
#include "cgdoom.h"
#include "doomstat.h"
#include "i_system.h"
@ -92,7 +93,32 @@ void I_SetPalette(int gamma_correction)
}
}
#if !defined(CG_EMULATOR) && defined(CGDOOM_DIRECT_R61524)
#if defined(CG_EMULATOR)
void I_Flip (void)
{
int x,y;
for(y=0;y<SCREENHEIGHT;y++)
{
for(x=0;x<SCREENWIDTH;x++)
{
VRAM[(x+(WIDTH-SCREENWIDTH)/2)+(y+(HEIGHT-SCREENHEIGHT)/2)*WIDTH] = gPalette[screens[0][x+y*SCREENWIDTH]];
}
}
EmuUpdateWindow();
}
void I_InitGraphics(void)
{
EmuInitGraphics();
}
void I_ShutdownGraphics(void)
{
EmuShutdownGraphics();
}
#elif defined(CGDOOM_DIRECT_R61524)
#define SYNCO() __asm__ volatile("synco":::"memory");
#define PRDR *(volatile uint8_t *)0xA405013C
@ -202,7 +228,7 @@ void I_ReinitAfterError(void)
st_firsttime = true;
}
#else
#else /* fx-CG 50 without direct-DD access */
void I_Flip (void)
{

View File

@ -33,7 +33,7 @@ void CGDAppendHex32(const char *pszText,int iNum, int iDigits,char *pszBuf);
int abs(int x);
void I_Error (char *error, ...);
void I_Error (const char *error, ...);
void I_ErrorI(const char *str, int i1, int i2, int i3, int i4);
//force compiler error on use following:
@ -47,11 +47,6 @@ int FindInFlash(const void **buf, int size, int readpos);
//direct read from flash
int Flash_ReadFile(void *buf, int size, int readpos);
//CGD: bypass for direct pointers to flash
#define PTR_TO_FLASH(x) ( \
((x) >= FLASH_START && (x) < FLASH_END) || \
((x) >= FLASH_CACHED_START && (x) < FLASH_CACHED_END))
#define min(x,y) ({ \
__auto_type __x = (x); \
__auto_type __y = (y); \

View File

@ -1114,5 +1114,5 @@ void ST_Init (void)
{
veryfirsttime = 0;
ST_loadData();
screens[4] = CGDOOM_SCREENS_4;
screens[4] = I_ScreenBase(4);
}

View File

@ -352,15 +352,11 @@ void V_GetBlock( int x, int y, int scrn, int width, int height, byte* dest
void V_Init (void)
{
/* screens[0] is the main screen */
screens[0] = CGDOOM_SCREENS_0;
screens[0] = I_ScreenBase(0);
/* screens[1] is used for the level end sequence (intermission) */
screens[1] = CGDOOM_SCREENS_1;
screens[1] = I_ScreenBase(1);
/* screens[2] and screens[3] are used for wipe effects (disabled here) */
/* screens[4] is used for the status bar (allocated by st_stuff.c) */
//Blank the screen, to indicate on real hardware that SOMETHING is going on
//Done since loading on real hardware takes so damn long
// I_PrepScreen();
}
/* CGDOOM-specific function to clear screen when changing window size */

View File

@ -27,6 +27,13 @@ enum {
#define FLASH_CACHED_START ((const void *)0x80000000)
#define FLASH_CACHED_END ((const void *)0x82000000)
/* When loading from Flash, non-fragmented lumps are returned directly via
pointers to Flash in order to save heap. Pointers to Flash can't be freed
and are detected with the following macro. */
#define PTR_TO_FLASH(x) ( \
((x) >= FLASH_START && (x) < FLASH_END) || \
((x) >= FLASH_CACHED_START && (x) < FLASH_CACHED_END))
/* Storage unit is a cluster of 512 bytes; Fugue tries to use clusters of 4 kiB
(8 sectors) but in exceptional circumstances cluster alignment can be lost
(such as when sectors are dead) */
@ -67,15 +74,6 @@ enum {
# define CGDOOM_SCREENS_BASE SaveVRAMBuffer
#endif
/* The primary/secondary VRAM covers 384*216*2 = 162 kiB:
-> Give 320*200 = 64 kB to screens[0] (main display)
-> Give 320*200 = 64 kB to screens[1] (intermissions)
-> Give 320*32 = 10 kiB to screens[4] (status bar)
-> 27 kiB are left */
#define CGDOOM_SCREENS_0 (CGDOOM_SCREENS_BASE)
#define CGDOOM_SCREENS_1 (CGDOOM_SCREENS_BASE + 320*200)
#define CGDOOM_SCREENS_4 (CGDOOM_SCREENS_BASE + 320*200*2)
//---
#include "keyboard.hpp"
@ -94,19 +92,6 @@ enum {
#include <string.h>
#include <stdint.h>
#define WIDTH 384
#define HEIGHT 216
#define EmulHack_Sleep(x)
#define ASSERT(x)
#define InitFlashSimu(filename)
/* Description of a WAD file selectable by user. */
typedef struct
{
char name[16];
uint16_t path[23];
int size;
} WADFileInfo;
#endif //#ifndef PLATFORM_H

View File

@ -5,7 +5,7 @@
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <windows.h>
#include "emul.h"
#include "platform.h"
#include <tchar.h>
#include <stdarg.h>
#include <stdio.h>
@ -442,4 +442,4 @@ void InitFlashSimu( const unsigned short*filename)
// map buffer to local process space
gpcFlashBuffer =(unsigned char *)MapViewOfFile(hMap,FILE_MAP_READ,0,0,dwFileSize);
ASSERT(gpcFlashBuffer!=NULL);
}
}

View File

@ -1,60 +0,0 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <malloc.h>
#define CG_EMULATOR
void Bdisp_PutDisp_DD();
void Bdisp_AllClr_VRAM( void );
int PRGM_GetKey();
#define WIDTH 384
#define HEIGHT 216
//extern unsigned short VRAM[WIDTH * HEIGHT];
void G3A_main( void );
int Serial_Open( unsigned char *mode );
int Serial_Close( int mode );
int Serial_DirectTransmitOneByte( unsigned char byte_to_transmit );
int Serial_CheckRX();
unsigned char Serial_Read();
#define dbgprint(x) printf(x)
#define dbgprint1(x,y) printf(x,y)
int RTC_GetTicks( void );
int RTC_Elapsed_ms( int start_value, int duration_in_ms );
void __stdcall Sleep(int dwMilliseconds );
unsigned int GetVRAMAddress( void );
#define EmulHack_Sleep(x) Sleep(x)
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 );
#define EnableColor(x)
extern const unsigned char *gpcFlashBuffer;
//flash file mapping
#define FLASH_START ((int)gpcFlashBuffer)
//page has 4 KB (I hope)
#define FLASH_PAGE_SIZE 4096
#define FLASH_PAGE_SIZE_LOG2 12
#define FLASH_PAGE_OFFSET_MASK (FLASH_PAGE_SIZE - 1)
//8K pages
#define FLASH_PAGE_COUNT (4096*2)
#define FLASH_END (FLASH_START + (FLASH_PAGE_SIZE*FLASH_PAGE_COUNT))
void InitFlashSimu( const unsigned short*filename);

View File

@ -1,3 +1,60 @@
// simulator
#include "emul.h"
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#include "keyboard.hpp"
/* 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
/* Rendering system emulation. */
// Emulated fx-CG function
void Bdisp_PutDisp_DD(void);
void Bdisp_AllClr_VRAM(void);
uint16_t *GetVRAMAddress(void);
// Additional SDL-related calls
void EmuInitGraphics(void);
void EmuShutdownGraphics(void);
void EmuUpdateWindow(void);
/* Input system emulation. */
// TODO
//~
void G3A_main( void );
int Serial_Open( unsigned char *mode );
int Serial_Close( int mode );
int Serial_DirectTransmitOneByte( unsigned char byte_to_transmit );
int Serial_CheckRX();
unsigned char Serial_Read();
#define dbgprint(x) printf(x)
#define dbgprint1(x,y) printf(x,y)
int RTC_GetTicks( void );
int RTC_Elapsed_ms( int start_value, int duration_in_ms );
void Sleep(int dwMilliseconds );
#define EmulHack_Sleep(x) Sleep(x)
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);