SGL replacement

a homebrew Saturn library in the making

about

This project attempts to recreate parts of the SGL library. The main focus is not to make it an exact 1:1 reimplementation nor is it going to cover all parts of the SGL.

It is created in the intention to allow certain Saturn homebrew applications to work just as if they were using the original SGL. The more Saturn homebrew is requested to work with the SGL replacement, the better it's compatibility will get.

I'm trying to use (or start from) existing homebrew Saturn libs (from Charles MacDonald maybe Bart Tryznadlowski and Mic) or to implement it myself (actually most stuff is self written), although I'm far from being an expert in this category. This project is in a very early stage and everyone willing to help coding or debugging is welcome (and will get the source).

goal

You know the SGL links a lot of object code even though you've only used a few functions of it. Furthermore it requires a lot of variable storage and it wastes CPU time while waiting for the v-blank. The usage of the slave CPU is simple, but underlies some restrictions. Also the SGL has been compiled with rather old compilers. And not to forget: it's always better if a Saturn homebrew game is 100 percent hombrew.

While in an overall view, this SGL replacement may never be better than the original, for special cases it can give an advantage, as one gets more control over master CPU, slave CPU and RAM usage.

Examples: I could verify that the Game Boy Color emu is faster with sglrep than with original SGL. The Super Nintendo emu is by default using sglrep and benefits a lot.

features

Current focus is on support of all easy to implement VDP2 scroll functions. But it also already allows limited control pad and sprite handling.

fast debug printing (slPrint...) with very small font

supports bitmap library (completely)

supports slave cpu

lots of compile flags for customization

buffered VDP2 registers, allows reading of write only regs, allows writing to VDP2 immediately or later

comes with working SGL demos (from others and special test demos)

functions already implemented are:

sl16MapRA, sl16MapRB, sl1MapRA, sl1MapRB, slBack1ColSet, slBackColTable, slBitMapBase, slBitMapNbg0, slBitMapNbg1, slBitMapRbg0, slBMBox, slBMBoxFill, slBMCircle, slBMGet, slBMLine, slBMPalette (slBMPaletteNbg0, slBMPaletteNbg1, slBMPaletteRbg0), slBMPoint, slBMPset, slBMPut, slBMSprPut, slCharNbg0, slCharNbg1, slCharNbg2, slCharNbg3, slCharRbg0, slClearBitMap, slColOffsetA, slColOffsetAUse, slColOffsetB, slColOffsetBUse, slColOffsetOn, slColOffsetOff, slColorCalc, slColorCalcOn, slColRAMMode, slDispHex, slDispSprite, slDMACopy, slExtSignal, slGetHCount, slGetVCount, slInitBitMap (slInitBitMapNbg0, slInitBitMapNbg1, slInitBitMapRbg0), slInitSystem, slLineColDisp, slLine1ColSet, slLineColTable, slLocate, slLocateBitMap, slLocateNbg (slLocateNbg0, slLocateNbg1, slLocateNbg2, slLocateNbg3), slLocatePage, slMapNbg0, slMapNbg1, slMapNbg2, slMapNbg3, slPageNbg0, slPageNbg1, slPageNbg2, slPageNbg3, slPageRbg0, slPlaneNbg0, slPlaneNbg1, slPlaneNbg2, slPlaneNbg3, slPlaneRA, slPlaneRB, slPrint, slPrintFX, slPrintHex, slPrintMatrix, slPriority (slPriorityNbg0, slPriorityNbg1, slPriorityNbg2, slPriorityNbg3, slPriorityRbg0, slPrioritySpr0, slPrioritySpr1, slPrioritySpr2, slPrioritySpr3, slPrioritySpr4, slPrioritySpr5, slPrioritySpr6, slPrioritySpr7), slRequestCommand, slScrAutoDisp, slScrCycleSet, slScrDisp, slScrLineWindow0, slScrLineWindow1, slScrPosNbg0, slScrPosNbg1, slScrPosNbg2, slScrPosNbg3, slScrTransparent, slScrWindow0, slScrWindow1, slScrWindowMode, slSetScrTVMode, slSetTVMode, slSlaveFunc, slSpriteCCalcCond, slSpriteCCalcNum, slSpriteColMode, slSpriteType, slSynch, slTVOff, slTVOn, slVRAMMode, slZoomMode (slZoomModeNbg0, slZoomModeNbg1), slZoomNbg0, slZoomNbg1

todo

improve font for better readability

improve slScrAutoDisp even more(hires, bank spanning, zoom)

implement fixed math, matrix stack

get interrupts running

increase VDP1 sprite support

faster controler access (SH2 direct currently)

done

fixed slPrint on real hardware

improve slScrAutoDisp (most difficult function of all) to be good enough to use it on real hardware

move debug text (slPrint, ...) implementation from Charles MacDonald's one (bitmap, no hardware acceleration, slow) to a more exact and faster one

compatibility

Only tested games are listed, it's not complete.

working

GameBoy emu, SNES emu (Rockin'-B), 12 player pong, 12 player snake(slinga), bm15bpp (CyberWarriorX), satdemo, bitmdemo, chaos89 (Charles Doty), morpion (Reinhart)

working, but incomplete

memory(Reinhart)

supported flags

SBL

Compatibility mode to comply with the SGL declarations that shipped with SBL

PRINT_BITMAP

first attempt, outdated, slow, low compatibility

PRINT_TILE

top choice, fast, compatible

PRINT_TILE_SMALL

compressed font and 2 element palette

PRINT_SET_RGB_FLAG

set RGB flag for custom font palette, except first entry

BITMAP_CLIP_CIRCLE_PERPIXEL

draw circle even if some pixels are outside the scroll, more like SGL

NO_VBLANK_WAITING

no vsynch, fast option for CPU demanding emus

NO_VDP1

Disables the use of VDP1 sprite gpu, makes slSynch() faster and makes all VDP1 RAM available for you!

SLAVE_COMMAND_BUFFER_LENGTH

Set the number of request being held in a master-to-slave command buffer.

SLAVE_IF_BUFFER_FULL_*

What to do if master->slave command buffer is full, specify only one of these flags, else priority selects a single flag. Default(no flag defined) is wait.

SLAVE_IF_BUFFER_FULL_SKIP

Just returns immediately without processing the function with slave or master. This can be applicable if the computation is not crucial to the program flow and if you give speed priority over the computation of this function. Example: liny-by-line rendering in emulators

SLAVE_IF_BUFFER_FULL_EXECUTE_ON_MASTER

Instead of waiting for a free entry in the command buffer (the slave has to finish it's current task), don't waste time and do it on the master. !! BEWARE global variables, executing the same function on both CPUs causes problems, if it uses global variables

SLAVE_IF_BUFFER_FULL_OVERWRITE_LAST

This seems to be the SGL behaviour I experienced with GNUBoy

SLAVE_CACHE_PURGE_ON_IDLE

When changing from idle to busy, let slave do a cache-purge to have it's content up-to-date. Disabled because redundant when SLAVE_CACHE_PURGE_ON_BUSY is set.

SLAVE_CACHE_PURGE_ON_BUSY

In the slave busy state, let slave do a cache-purge everytime a new task is started to have it's content up-to-date.

SLAVE_DEBUG

To monitor master and slave behaviour, their state is recorded:

SLAVE_DUMP_LENGTH

SlvDbgDump masterDump[SLAVE_DUMP_LENGTH], slaveDump[SLAVE_DUMP_LENGTH];

Uint32 masterDumpCount, slaveDumpCount;

Collects some statistic in variables: Uint32 slvDbg_nSlv, slvDbg_nSlvIdle, slvDbg_nMas;

screenshots

Supportable by
Compiled with
Is used by