Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
/[Mm]odules/[Ss][Gg][Ll]/[Ss][Rr][Cc]/*.o
/[Mm]odules/[Tt][Ll][Ss][Ff]/*.o

/[Ss]amples/**/imgui.ini
/[Ss]amples/**/*.o
/[Ss]amples/**/[Bb]uild[Dd]rop/**
/[Cc]ompiler/msys2/tmp/*
Expand Down Expand Up @@ -50,6 +51,7 @@

/[Tt]ests/**/[Bb]uild[Dd]rop/**
/[Tt]ests/**/*.o
/[Tt]ests/**/imgui.ini
/[Tt]ests/**/*.log

/Projects/**
Expand Down
4 changes: 2 additions & 2 deletions modules/sgl/INC/sgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ typedef uint16_t TEXDAT;
/********************************/
/* Old Texture Table */
/********************************/
#define cgaddress 0x10000
#define cgaddress ((SGL_MAX_POLYGONS + 6) * sizeof(SPRITE) * 2)
#define pal COL_32K
#define TEXDEF(h,v,presize) {h,v,(cgaddress+(((presize)*4)>>(pal)))/8,(((h)&0x1f8)<<5 | (v))}
#define PICDEF(texno,cmode,pcsrc) {(uint16_t)(texno),(uint16_t)(cmode),(void *)(pcsrc)}

/********************************/
/* New Texture Table */
/********************************/
#define CGADDRESS 0x10000
#define CGADDRESS ((SGL_MAX_POLYGONS + 6) * sizeof(SPRITE) * 2)
#define AdjCG(cga,hs,vs,col) ((cga) + (((((hs)*(vs)*4)>>(col))+0x1f) &0x7ffe0))
#define TEXTBL(hs,vs,cga) {hs , vs , (cga)>>3 , ((hs)&0x1f8)<<5|(vs)}
#define PICTBL(texno,cmode,pcsrc) {(uint16_t)(texno),(uint16_t)(cmode),(void *)(pcsrc)}
Expand Down
Binary file modified modules/sgl/LIB/LIBADP.A
Binary file not shown.
Binary file modified modules/sgl/LIB/LIBCD.A
Binary file not shown.
Binary file modified modules/sgl/LIB/LIBCD_D.A
Binary file not shown.
Binary file modified modules/sgl/LIB/LIBMEM.A
Binary file not shown.
Binary file modified modules/sgl/LIB/LIBPCM.A
Binary file not shown.
Binary file modified modules/sgl/LIB/LIBSGL.A
Binary file not shown.
Binary file modified modules/sgl/LIB/LIBSND.A
Binary file not shown.
Binary file modified modules/sgl/LIB/SEGA_SYS.A
Binary file not shown.
Binary file modified modules/sgl/LIB/SGLAREA.O
Binary file not shown.
Binary file modified modules/sgl/LIB/SYS_AREE.O
Binary file not shown.
Binary file modified modules/sgl/LIB/SYS_AREJ.O
Binary file not shown.
Binary file modified modules/sgl/LIB/SYS_ARET.O
Binary file not shown.
Binary file modified modules/sgl/LIB/SYS_AREU.O
Binary file not shown.
Binary file modified modules/sgl/LIB/SYS_INIT.O
Binary file not shown.
Binary file modified modules/sgl/LIB/SYS_SEC.O
Binary file not shown.
14 changes: 14 additions & 0 deletions modules/sgl/SRC/preloader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ extern "C" {
*/
extern uint32_t _bend;

/** @brief Start of a workarea area section
*/
extern uint32_t _work_area_start;

/** @brief End of a command buffer section
*/
extern uint32_t _command_buffer_end;

/** @brief Start address of constructor array
*/
extern void(*__ctors)();
Expand Down Expand Up @@ -39,6 +47,12 @@ extern "C" {
*bssBlock = 0;
}

// Zero stuff inside workarea and command buffer section
for (uint32_t* workareaBlock = &_work_area_start; workareaBlock < &_command_buffer_end; workareaBlock++)
{
*workareaBlock = 0;
}

// Initialize memory management (malloc stuff)
SRL::Memory::Initialize();

Expand Down
26 changes: 16 additions & 10 deletions modules/sgl/SRC/workarea.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@
#define _LongWord_ sizeof(uint32_t)
#define _Sprite_ (sizeof(uint16_t) * 18)

// #define SGL_MAX_VERTICES 2500 /* number of vertices that can be used */
// #define SGL_MAX_POLYGONS 1700 /* number of polygons that can be used */

struct WorkArea_
{
char SortList[(_LongWord_ * 3) * (SGL_MAX_POLYGONS + 6)];
char Zbuffer[_LongWord_ * SGL_MAX_POLYGONS];
char SpriteBuf[_Sprite_ * ((SGL_MAX_POLYGONS + 6) * 2)];
char Pbuffer[(_LongWord_ * 4) * SGL_MAX_VERTICES];
char CLOfstBuf[(_Byte_ * 32 * 3) * 32];
char CommandBuf[(_LongWord_ * 8) * SGL_MAX_POLYGONS];
char __attribute__((aligned(0x10))) SortList[(_LongWord_ * 3) * (SGL_MAX_POLYGONS + 6)];
char __attribute__((aligned(0x10))) Zbuffer[_LongWord_ * 512];
char __attribute__((aligned(0x10))) SpriteBuf[_Sprite_ * ((SGL_MAX_POLYGONS + 6) * 2)];
char __attribute__((aligned(0x10))) Pbuffer[(_LongWord_ * 4) * SGL_MAX_VERTICES];
char __attribute__((aligned(0x10))) CLOfstBuf[(_Byte_ * 32 * 3) * 32];
};

struct CommandBufArea_
{
char CommandBuf[SGL_SLAVE_BUF_SIZE];
};

// Start must be aligned to 0x1000
struct WorkArea_ __attribute__((section("WORK_AREA_DUMMY"))) WORK_AREA_DUMMY;
struct WorkArea_ __attribute__((aligned(0x1000), used, section("WORK_AREA"))) WorkArea;

// Contains commands for slave CPU
struct CommandBufArea_ __attribute__((section("COMMAND_BUF_DUMMY"))) COMMAND_BUF_DUMMY;
struct CommandBufArea_ __attribute__((aligned(0x20), used, section("COMMAND_BUF"))) CommandBufArea;

const void* PCM_Work = (void*)SoundRAM + 0x78000; /* PCM Stream Address */
const uint32_t PCM_WkSize = 0x8000; /* PCM Stream Size */
const void* SlaveStack = (void*)0x06001e00; /* SlaveSH2 StackPointer */
Expand All @@ -36,7 +42,7 @@ const void* SpriteBuf = WorkArea.SpriteBuf;
const uint32_t SpriteBufSize = sizeof(WorkArea.SpriteBuf);
const void* Pbuffer = WorkArea.Pbuffer;
const void* CLOfstBuf = WorkArea.CLOfstBuf;
const void* CommandBuf = WorkArea.CommandBuf;
const void* CommandBuf = CommandBufArea.CommandBuf;

// #define SGL_MAX_EVENTS 64 /* number of events that can be used */
const uint16_t EventSize = sizeof(EVENT);
Expand Down
63 changes: 47 additions & 16 deletions modules/sgl/sgl.linker
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
OUTPUT_FORMAT(coff-sh)
OUTPUT_FORMAT(elf32-sh)
SECTIONS {

PRELOADER 0x06004000 : {
Expand All @@ -13,19 +13,14 @@ SECTIONS {

.text ALIGN(0x20) :
{
* (.text*)
*(.text)
*(.text*)
*(.strings*)
*("SEGA_P")

*(.eh_frame_hdr*)
*(.eh_frame*)
__etext = .;
}

COMMON ALIGN(0x10): {
*(COMMON)
}

SLPROG ALIGN(0x20): {
__slprog_start = .;
*(SLPROG)
Expand All @@ -44,40 +39,76 @@ SECTIONS {

.data ALIGN(0x10):
{
* (.data*)
*(.data)
*(.data*)
. = ALIGN(0x10);
__edata = . ;
}

.rodata ALIGN(0x20) :
{
*(.rodata)
*(.rodata*)
}

.bss ALIGN(0x10) (NOLOAD):
.bss ALIGN(0x10):
{
__bstart = . ;
*(.bss)
*(.bss*)
*(COMMON)
. = ALIGN(0x10);
__bend = . ;
_end = .;
}

HEAP ALIGN(0x10)(NOLOAD):
HEAP ALIGN(0x20):
{
__heap_start = .;
}

WORK_AREA_DUMMY 0x0000000(NOLOAD):
COMMAND_BUF_DUMMY 0x0000000 (NOLOAD): ALIGN(0x20)
{
*(COMMAND_BUF_DUMMY)
. = ALIGN(0x20);
}

WORK_AREA_DUMMY 0x0000000 (NOLOAD): ALIGN(0x20)
{
*(WORK_AREA_DUMMY)
. = ALIGN(0x1000);
}

work_area_start = ALIGN(0x060FC000 - SIZEOF(WORK_AREA_DUMMY), 0x1000);
command_buf_start = ALIGN(0x060FB800 - SIZEOF(COMMAND_BUF_DUMMY), 0x20);
work_area_start = ALIGN(command_buf_start - SIZEOF(WORK_AREA_DUMMY), 0x1000);

WORK_AREA work_area_start (NOLOAD):
{
WORK_AREA work_area_start : {
__heap_end = .;
__work_area_start = .;
*(WORK_AREA)
__work_area_end = .;
}

COMMAND_BUF command_buf_start : {
__command_buffer_start = .;
*(COMMAND_BUF)
__command_buffer_end = .;
}

SYSTEM_START 0x060FB800 : {
__systemStart = .;
}

SYSTEM_END 0x060FFC00 : {
__systemEnd = .;
_end = .;
}

/DISCARD/ :
{
*(.rela*)
*(.rel.text .rel.data .rel.rodata)
*(.rela.text .rela.data .rela.rodata)
*(.rela.text.* .rela.data.*)
*(.eh_frame)
}
}
11 changes: 9 additions & 2 deletions saturnringlib/shared.mk
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ else
SYSFLAGS += -DSGL_MAX_WORKS=256
endif

# Set slave command buffer size, use 70k by default, should be aligned to 0x10
ifneq ($(strip ${SGL_SLAVE_BUF_SIZE}),)
SYSFLAGS += -DSGL_SLAVE_BUF_SIZE=$(strip ${SGL_SLAVE_BUF_SIZE})
else
SYSFLAGS += -DSGL_SLAVE_BUF_SIZE=71680
endif

# Add custom FLAGS
ifneq ($(strip ${SRL_CUSTOM_CCFLAGS}),)
CCFLAGS += $(strip ${SRL_CUSTOM_CCFLAGS})
Expand Down Expand Up @@ -252,10 +259,10 @@ compile_objects : $(OBJECTS) $(SYSOBJECTS)
@test -f $(ASSETS_DIR)/ABS.TXT || echo "NOT Abstracted by SEGA" >> $(ASSETS_DIR)/ABS.TXT
@test -f $(ASSETS_DIR)/BIB.TXT || echo "NOT Bibliographiced by SEGA" >> $(ASSETS_DIR)/BIB.TXT
@test -f $(ASSETS_DIR)/CPY.TXT || touch $(ASSETS_DIR)/CPY.TXT
$(CC) $(LDFLAGS) $(SYSOBJECTS) $(OBJECTS) $(LIBS) -o "$(BUILD_ELF)"
$(CC) $(LDFLAGS) $(SYSOBJECTS) $(OBJECTS) -Wl,-bcoff-sh $(LIBS) -Wl,-belf32-sh -o "$(BUILD_ELF)"

convert_binary : compile_objects
$(OBJCOPY) -O binary "$(BUILD_ELF)" ./cd/data/0.bin
$(OBJCOPY) -O binary -R WORK_AREA* -R COMMAND_BUF* -R SYSTEM_START* -R SYSTEM_END* "$(BUILD_ELF)" ./cd/data/0.bin

create_iso : convert_binary
ifeq ($(strip ${SRL_USE_SGL_SOUND_DRIVER}),1)
Expand Down
33 changes: 33 additions & 0 deletions saturnringlib/srl_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,39 @@ namespace std
{
while (1);
}

/** @brief Minimal std::__throw_bad_alloc handler
*
* This function is a minimal implementation to prevent compilation errors
* when the standard library expects a length error handler. It enters an
* infinite loop to prevent undefined behavior.
*/
inline void __throw_bad_alloc()
{
while(1);
}

/** @brief Minimal std::__throw_bad_array_new_length handler
*
* This function is a minimal implementation to prevent compilation errors
* when the standard library expects a length error handler. It enters an
* infinite loop to prevent undefined behavior.
*/
inline void __throw_bad_array_new_length()
{
while(1);
}

/** @brief Minimal std::__throw_bad_function_call handler
*
* This function is a minimal implementation to prevent compilation errors
* when the standard library expects a length error handler. It enters an
* infinite loop to prevent undefined behavior.
*/
inline void __throw_bad_function_call()
{
while(1);
}
}
/**
* @brief Minimal pure virtual function handler
Expand Down
Loading
Loading