Skip to content

Commit

Permalink
SGDK 1.3 (June 2017)
Browse files Browse the repository at this point in the history
DOCUMENTATION
* updated to last version

COMPILER
* Updated to GCC 6.3 (thanks a tons to Gligli for that !)
 - many bugs fix and new features compared to old GCC 3.4.6
 - much better assembly code generation :)
 - added LTO (Linker Time Optimization) support
* Modified makefile to enable LTO and improve optimization level.
* Rescomp:
 - updated to handle structure changes in the Sprite Engine.

LIBRARY
* DMA:
 - minor optimization to DMA_queue(..) method (thanks to HpMan)
* Memory:
 - default stack size increased to 0x800 bytes (GCC 6.3 requires more stack memory :p)
* Sprite Engine:
 - added automatic Y sorting (per sprite)
 - added SPR_sort(..) for generic sorting
 - added SPR_sortOnY(..) for generic sorting
 - by default now sprite visibility is set to always ON (faster than automatic visibility)
 - updated 'Collision' structure (hierarchical structure)
 - some changes to internal structures to provide better performance
* VDP BG/Tile:
 - fixed a minor bug in VDP_setTileMapDataEx(..) and VDP_setTileMapDataRectEx(..) methods (thanks to Alekmaul for reporting it)
* minors fixes...

SAMPLE
* Bench:
 - fixed math tests for GCC 6.3
  • Loading branch information
Stephane-D committed Jun 18, 2017
1 parent 7cb7d73 commit d1b6073
Show file tree
Hide file tree
Showing 98 changed files with 4,743 additions and 1,265 deletions.
Binary file modified bin/ar.exe
Binary file not shown.
Binary file modified bin/as.exe
Binary file not shown.
Binary file modified bin/cc1.exe
Binary file not shown.
Binary file modified bin/cp.exe
Binary file not shown.
Binary file modified bin/cpp.exe
Binary file not shown.
Binary file removed bin/cygiconv-2.dll
Binary file not shown.
Binary file removed bin/cygintl-3.dll
Binary file not shown.
Binary file removed bin/cygwin1.dll
Binary file not shown.
Binary file modified bin/gcc.exe
Binary file not shown.
Binary file modified bin/gdb.exe
Binary file not shown.
Binary file modified bin/ld.exe
Binary file not shown.
Binary file added bin/libgcc_s_dw2-1.dll
Binary file not shown.
Binary file added bin/libgmp-10.dll
Binary file not shown.
Binary file added bin/libiconv-2.dll
Binary file not shown.
Binary file removed bin/libintl3.dll
Binary file not shown.
Binary file added bin/liblto_plugin-0.dll
Binary file not shown.
Binary file added bin/libmpc-3.dll
Binary file not shown.
Binary file added bin/libmpfr-4.dll
Binary file not shown.
Binary file added bin/lto-wrapper.exe
Binary file not shown.
Binary file added bin/lto1.exe
Binary file not shown.
Binary file modified bin/make.exe
Binary file not shown.
Binary file modified bin/mkdir.exe
Binary file not shown.
Binary file added bin/msys-1.0.dll
Binary file not shown.
Binary file renamed bin/libiconv2.dll → bin/msys-iconv-2.dll
Binary file not shown.
Binary file added bin/msys-intl-8.dll
Binary file not shown.
Binary file added bin/msys-regex-1.dll
Binary file not shown.
Binary file added bin/msys-termcap-0.dll
Binary file not shown.
Binary file modified bin/nm.exe
Binary file not shown.
Binary file modified bin/objcopy.exe
Binary file not shown.
Binary file added bin/objdump.exe
Binary file not shown.
Binary file modified bin/rescomp.exe
Binary file not shown.
Binary file modified bin/rm.exe
Binary file not shown.
Binary file modified bin/sh.exe
Binary file not shown.
Binary file added bin/size.exe
Binary file not shown.
Binary file removed bin/uftcpack.exe
Binary file not shown.
Binary file modified bin/xgmtool.exe
Binary file not shown.
17 changes: 8 additions & 9 deletions inc/bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
* This unit provides methods to simulate bitmap mode on SEGA genesis.<br>
*<br>
* The software bitmap engine permit to simulate a 256x160 pixels bitmap screen.<br>
* Almost methods as #BMP_setPixel and #BMP_drawLine however use doubled X pixel so you can
* Some methods as #BMP_setPixel and #BMP_drawLine use doubled X pixel so you can
* consider resolution to be 128x160 in this case.<br>
* It uses a double buffer so you can draw to buffer while other buffer is being sent to video memory.<br>
* Bitmap buffer requires ~41 KB of memory which is dynamically allocated.<br>
* These buffers are transfered to VRAM during blank area, by default on NTSC system the blanking period<br>
* is very short so it takes approximately 10 frames to blit an entire buffer.<br>
* Bitmap engine requires a large amount of memory (~41KB) which is dynamically allocated at BMP_init(..) time and released when BMP_end) is called.<br>
* Bitmap engine uses a double buffer so you can draw to the write buffer while the read buffer is being sent to video memory.<br>
* These buffers are transfered to VRAM during blank area, by default on NTSC system the blanking period is really short so it takes approximately 10 frames to blit an entire buffer.<br>
* To improve transfer performance the blank area is extended to fit bitmap resolution:<br>
* 0-31 = blank<br>
* 32-191 = active<br>
* 192-262/312 = blank<br>
* scanline 0-31 = blank<br>
* scanline 32-191 = active<br>
* scanline 192-262/312 = blank<br>
* <br>
* With extended blank bitmap can be transfered to VRAM 20 times per second in NTSC<br>
* With extended blank bitmap buffer can be transfered to VRAM 20 times per second in NTSC<br>
* and 25 time per second in PAL.
*/

Expand Down
7 changes: 4 additions & 3 deletions inc/dma.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
*/
typedef struct
{
u32 regStepLenL; // (0x8F00 | step) | ((0x9300 | (len & 0xFF)) << 16)
u32 regLenHAddrL; // (0x9400 | ((len >> 8) & 0xFF)) | ((0x9500 | ((addr >> 1) & 0xFF)) << 16)
u32 regAddrMAddrH; // (0x9600 | ((addr >> 9) & 0xFF)) | ((0x9700 | ((addr >> 17) & 0x7F)) << 16)
u32 regLen; // ((len | (len << 8)) & 0xFF00FF) | 0x94009300;
u32 regAddrMStep; // (((addr << 7) & 0xFF0000) | 0x96008F00) + step;
u32 regAddrHAddrL; // ((addr >> 1) & 0x7F00FF) | 0x97009500;
u32 regCtrlWrite; // GFX_DMA_VRAMCOPY_ADDR(to)
} DMAOpInfo;


/**
* \brief
* DMA queue structure
Expand Down
4 changes: 2 additions & 2 deletions inc/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@

/**
* \brief
* Define memory allocated for stack (default = 0x400).
* Define memory allocated for stack (default = 0x800)
*/
#define STACK_SIZE 0x400
#define STACK_SIZE 0x800
/**
* \brief
* Define the memory high address limit for dynamic allocation
Expand Down
133 changes: 109 additions & 24 deletions inc/sprite_eng.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@
#define COLLISION_TYPE_CIRCLE 2


/**
* \brief
* Flag to know if a sprite if currently allocated or not
*/
#define SPR_FLAG_ALLOCATED 0x8000
/**
* \brief
* Enable automatic visibility calculation
Expand All @@ -59,6 +54,11 @@
* Enable automatic upload of sprite tiles data into VRAM
*/
#define SPR_FLAG_AUTO_TILE_UPLOAD 0x0200
/**
* \brief
* Enable automatic Y sorting
*/
#define SPR_FLAG_AUTO_YSORTING 0x0100
/**
* \brief
* Mask for sprite flags
Expand Down Expand Up @@ -89,15 +89,36 @@ typedef enum
* Box definition if type = #COLLISION_TYPE_BOX
* \param circle
* Circle definition if type = #COLLISION_TYPE_CIRCLE
* \param inner
* if current collision is verified the we test inner for more precise collisions if needed
* \param next
* if current collision is not verified then we test next for next collision if needed
*/
typedef struct
typedef struct _collision
{
u16 type;
union
{
Box box;
Circle circle;
};
} norm;
union
{
Box box;
Circle circle;
} hflip;
union
{
Box box;
Circle circle;
} vflip;
union
{
Box box;
Circle circle;
} hvflip;
void* inner;
void* next;
} Collision;

/**
Expand Down Expand Up @@ -128,12 +149,10 @@ typedef struct
*
* \param numSprite
* number of VDP sprite which compose this frame
* \param vdpSprites
* VDP sprites composing the frame
* \param numCollision
* number of collision structure for this frame
* \param collisions
* collisions structures (can be either Box or Circle)
* \param vdpSpritesInf
* pointer to an array of VDP sprites info composing the frame (followed by H/V/HV flipped versions)
* \param collision
* collision structure
* \param tileset
* tileset containing tiles for this animation frame (ordered for sprite)
* \param w
Expand All @@ -147,8 +166,7 @@ typedef struct
{
u16 numSprite;
VDPSpriteInf **vdpSpritesInf;
u16 numCollision;
Collision **collisions;
Collision *collision;
TileSet *tileset;
s16 w;
s16 h;
Expand Down Expand Up @@ -212,8 +230,6 @@ typedef struct
*
* \param status
* Internal state and automatic allocation information (internal)
* \param index
* Current index in active sprite list (internal)
* \param spriteDef
* Sprite definition pointer
* \param animation
Expand Down Expand Up @@ -245,13 +261,16 @@ typedef struct
* Pointer to last VDP sprite used by this Sprite (used internally to update link between sprite)
* \param data
* this is a free field for user data, use it for whatever you want (flags, pointer...)
* \param prev
* pointer on previous Sprite in list
* \param next
* pointer on next Sprite in list
*
* Used to manage an active sprite in game condition.
*/
typedef struct
typedef struct _Sprite
{
u16 status;
u16 index;
u16 visibility;
const SpriteDefinition *definition;
Animation *animation;
Expand All @@ -267,9 +286,24 @@ typedef struct
u16 frameNumSprite;
VDPSprite *lastVDPSprite;
u32 data;
struct _Sprite *prev;
struct _Sprite *next;
} Sprite;


/**
* \brief
* Callback for the sprite sorting method SPR_sort(..)
*
* This callback is used to compare 2 sprite objects.<br>
* Return value should be:<br>
* negatif if s1 is before s2<br>
* 0 if s1 is equal to s2<br>
* positif if s1 is after s2
*/
typedef s16 _spriteComparatorCallback(Sprite* s1, Sprite* s2);


/**
* \brief
* Init the Sprite engine with specified VRAM allocation and unpacking buffer size.
Expand Down Expand Up @@ -340,8 +374,11 @@ void SPR_reset();
* If you don't set this flag you will have to manually define VRAM tile index position for this sprite with the <i>attribut</i> parameter or by using the #SPR_setVRAMTileIndex(..) method<br>
* #SPR_FLAG_AUTO_SPRITE_ALLOC = Enable automatic hardware/VDP sprite allocation (enabled by default)<br>
* If you don't set this flag you will have to manually define the hardware sprite table index to reserve with the <i>spriteIndex</i> parameter or by using the #SPR_setSpriteTableIndex(..) method<br>
* #SPR_FLAG_AUTO_TILE_UPLOAD = Enable automatic upload of sprite tiles data into VRAM (enabled by default)<br>
* #SPR_FLAG_AUTO_TILE_UPLOAD = Enable automatic upload of sprite tiles data into VRAM (enabled by default)<br>
* If you don't set this flag you will have to manually upload tiles data of sprite into the VRAM.<br>
* #SPR_FLAG_AUTO_YSORTING = Enable automatic Y sorting for this sprite so it will always appear in front of sprites with lower Y position.<br>
* If you don't set this flag you can still use SPR_sortOnY() to do Y sorting on the whole sprite list.<br>
* <br>
* It's recommended to use the following default settings:<br>
* SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_SPRITE_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD<br>
* \return the new sprite or <i>NULL</i> if the operation failed (some logs can be generated in the KMod console in this case)
Expand All @@ -368,8 +405,7 @@ Sprite* SPR_addSpriteEx(const SpriteDefinition *spriteDef, s16 x, s16 y, u16 att
* sprite attribut (see TILE_ATTR() macro).
* \return the new sprite or <i>NULL</i> if the operation failed (some logs can be generated in the KMod console in this case)
*
* By default the sprite uses automatic resources allocation (VRAM and hardware sprite) and visibility
* is automatically computed depending the sprite size information (from SpriteDefinition structure) and the sprite position.<br>
* By default the sprite uses automatic resources allocation (VRAM and hardware sprite) and visibility is set to ON.<br>
* You can change these defaults settings later by calling SPR_setVRAMTileIndex(..), SPR_setSpriteTableIndex(..), SPR_setAutoTileUpload(..) and SPR_setVisibility(..) methods.<br>
* You can release all sprite resources by using SPR_releaseSprite(..) or SPR_reset(..).
*
Expand Down Expand Up @@ -548,6 +584,20 @@ u16 SPR_setSpriteTableIndex(Sprite *sprite, s16 value);
* FALSE to disable it (mean you have to handle that on your own).<br>
*/
void SPR_setAutoTileUpload(Sprite *sprite, u16 value);
/**
* \brief
* Enable/disable the automatic Y sorting for this sprite so it will always appear in front of sprites will lower Y position.<br>
* Note that you can also use SPR_sortOnY() to do manual Y sorting on the whole sprite list.
*
* \param sprite
* Sprite we want to enable/disable Y sorting for
* \param value
* TRUE to enable the automatic Y sorting for this sprite<br>
* FALSE to disable it, you can still use the SPR_sort(..) method.<br>
*
* \see SPR_sort(..)
*/
void SPR_setYSorting(Sprite *sprite, u16 value);
/**
* \brief
* Set the <i>visibility</i> state for this sprite.
Expand All @@ -558,8 +608,8 @@ void SPR_setAutoTileUpload(Sprite *sprite, u16 value);
* Visibility value to set.<br>
* SpriteVisibility.VISIBLE = sprite is visible<br>
* SpriteVisibility.HIDDEN = sprite is not visible<br>
* SpriteVisibility.AUTO_FAST = visibility is automatically computed from the sprite position (global visibility)<br>
* SpriteVisibility.AUTO_SLOW = visibility is automatically computed from the sprite position (per hardware sprite visibility)<br>
* SpriteVisibility.AUTO_FAST = visibility is automatically computed from sprite position (global visibility)<br>
* SpriteVisibility.AUTO_SLOW = visibility is automatically computed from sprite position (per hardware sprite visibility)<br>
*/
void SPR_setVisibility(Sprite *sprite, SpriteVisibility value);
/**
Expand Down Expand Up @@ -617,6 +667,41 @@ void SPR_clear();
* \see #SPR_addSprite(..)
*/
void SPR_update();
/**
* \brief
* Sort the sprites to define display order.
*
* This method uses the given comparator callback to sort the whole list of Sprite and so define
* the display order of the sprites.<br>
* If the comparator callback is set to NULL then by default Y sorting is performed.<br>
* This method can take a long time, use it carefully !
*
* \param comparator
* the comparator callback used to compare sprites.<br>
* It should return a value < 0 if sprite 1 is below sprite 2 and a value > 0 in the opposite case.<br>
* If order doesn't matter it can return 0.
*
* \see #SPR_sortOnYPos()
*/
void SPR_sort(_spriteComparatorCallback* comparator);
/**
* \brief
* Sort the sprites by their Y position to define display order (same as SPR_sort(NULL))
*
* \see #SPR_sort(..)
*/
void SPR_sortOnYPos();

/**
* \brief
* Log the profil informations (when enabled) in the KMod message window.
*/
void SPR_logProfil();
/**
* \brief
* Log the sprites informations (when enabled) in the KMod message window.
*/
void SPR_logSprites();


#endif // _SPRITE_ENG_H_
Expand Down
5 changes: 0 additions & 5 deletions inc/sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
#define PROCESS_XGM_TASK (1 << 4)


// internals V/H timer
extern u32 vtimer;
extern u32 htimer;


/**
* \brief
* Bus error interrupt callback.
Expand Down
2 changes: 1 addition & 1 deletion inc/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
#define MAXTIMER 16

extern u32 vtimer;
extern vu32 vtimer;


/**
Expand Down
Binary file modified lib/libmd.a
Binary file not shown.
Binary file modified lib/libmd_debug.a
Binary file not shown.
11 changes: 5 additions & 6 deletions makefile.gen
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ INCLUDE= inc
SHELL= $(BIN)/sh
RM= $(BIN)/rm
CP= $(BIN)/cp
AR= $(BIN)/ar
CC= $(BIN)/gcc
LD= $(BIN)/ld
NM= $(BIN)/nm
Expand Down Expand Up @@ -54,8 +53,8 @@ DEFAULT_FLAGS= -m68000 -Wall -fno-builtin $(INCS) -B$(BIN)
FLAGSZ80= -i$(SRC) -i$(INCLUDE) -i$(RES) -i$(LIBSRC) -i$(LIBINCLUDE)


#release: FLAGS= $(DEFAULT_FLAGS) -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer
release: FLAGS= $(DEFAULT_FLAGS) -O1 -fomit-frame-pointer
release: FLAGS= $(DEFAULT_FLAGS) -O3 -flto -fuse-linker-plugin -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer
#release: FLAGS= $(DEFAULT_FLAGS) -O1 -fomit-frame-pointer
release: LIBMD= $(LIB)/libmd.a
release: pre-build out/rom.bin

Expand Down Expand Up @@ -102,7 +101,7 @@ out/rom.bin: out/rom.out
$(SIZEBND) out/rom.bin -sizealign 131072

out/symbol.txt: out/rom.out
$(NM) -n out/rom.out > out/symbol.txt
$(NM) --plugin=liblto_plugin-0.dll -n out/rom.out > out/symbol.txt

out/rom.out: out/sega.o out/cmd_ $(LIBMD)
$(CC) -B$(BIN) -n -T $(GDK)/md.ld -nostdlib out/sega.o @out/cmd_ $(LIBMD) $(LIB)/libgcc.a -o out/rom.out
Expand All @@ -112,13 +111,13 @@ out/cmd_: $(OBJS)
$(ECHO) "$(OBJS)" > out/cmd_

out/sega.o: $(SRC)/boot/sega.s out/rom_head.bin
$(CC) $(FLAGS) -c $(SRC)/boot/sega.s -o $@
$(CC) $(DEFAULT_FLAGS) -c $(SRC)/boot/sega.s -o $@

out/rom_head.bin: out/rom_head.o
$(LD) -T $(GDK)/md.ld -nostdlib --oformat binary -o $@ $<

out/rom_head.o: $(SRC)/boot/rom_head.c
$(CC) $(FLAGS) -c $< -o $@
$(CC) $(DEFAULT_FLAGS) -c $< -o $@

$(SRC)/boot/sega.s: $(LIBSRC)/boot/sega.s
$(CP) $< $@
Expand Down
8 changes: 4 additions & 4 deletions makelib.gen
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ DEFAULT_FLAGS_LIB= -m68000 -Wall -fno-builtin $(INCS_LIB) -B$(BIN)
FLAGSZ80_LIB= -i$(SRC_LIB) -i$(INCLUDE_LIB)


#release: FLAGS_LIB= $(DEFAULT_FLAGS_LIB) -O3 -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer
release: FLAGS_LIB= $(DEFAULT_FLAGS_LIB) -O1 -fomit-frame-pointer
release: FLAGS_LIB= $(DEFAULT_FLAGS_LIB) -O3 -flto -fuse-linker-plugin -fno-web -fno-gcse -fno-unit-at-a-time -fomit-frame-pointer
#release: FLAGS_LIB= $(DEFAULT_FLAGS_LIB) -O1 -fomit-frame-pointer
release: $(LIB)/libmd.a

debug: FLAGS_LIB= $(DEFAULT_FLAGS_LIB) -O1 -ggdb -DDEBUG=1
Expand Down Expand Up @@ -73,11 +73,11 @@ cleanDebug: cleandebug


$(LIB)/libmd.a: cmd_
$(AR) rs $(LIB)/libmd.a @cmd_
$(AR) rs $(LIB)/libmd.a --plugin=liblto_plugin-0.dll @cmd_
$(RM) cmd_

$(LIB)/libmd_debug.a: cmd_
$(AR) rs $(LIB)/libmd_debug.a @cmd_
$(AR) rs $(LIB)/libmd_debug.a --plugin=liblto_plugin-0.dll @cmd_
$(RM) cmd_

cmd_ : $(OBJ_LIB)
Expand Down
9 changes: 0 additions & 9 deletions res/libres.h

This file was deleted.

Binary file added sample/astrofra/starfield_donut/out/rom.bin
Binary file not shown.
Binary file added sample/astrofra/starfield_donut/res/donut.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions sample/astrofra/starfield_donut/res/gfx.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
IMAGE starfield "starfield.png" BEST
SPRITE donut "donut.png" 4 4 BEST
Binary file added sample/astrofra/starfield_donut/res/starfield.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d1b6073

Please sign in to comment.