made it compatible with latest version of Azur and new command generation structure

This commit is contained in:
Sylvain PILLOT 2023-08-01 19:01:11 +02:00
parent 65c605bd96
commit e6c1e93874
5 changed files with 116 additions and 103 deletions

View File

@ -1,4 +1,6 @@
#define DEBUG_MODE 1
#define DEBUG_MODE 0
#define USB 1
#define MORE_RAM 1
#include <azur/azur.h>
#include <azur/gint/render.h>
@ -6,11 +8,17 @@
#include <gint/rtc.h>
#include <gint/clock.h>
#include <gint/kmalloc.h>
#if(MORE_RAM)
#include <gint/kmalloc.h>
#endif
#include <libprof.h>
#include <gint/usb.h>
#include <gint/usb-ff-bulk.h>
#if(USB)
#include <gint/usb.h>
#include <gint/usb-ff-bulk.h>
#endif
#include <stdio.h>
#include <string.h>
@ -64,12 +72,12 @@ float elapsedTime = 0.0f;
uint32_t time_update=0, time_render=0;
prof_t perf_update, perf_render;
static kmalloc_arena_t extended_ram = { 0 };
static kmalloc_arena_t *_uram;
kmalloc_gint_stats_t *_uram_stats;
kmalloc_gint_stats_t *extram_stats;
#if(MORE_RAM)
static kmalloc_arena_t extended_ram = { 0 };
static kmalloc_arena_t *_uram;
kmalloc_gint_stats_t *_uram_stats;
kmalloc_gint_stats_t *extram_stats;
#endif
std::vector<Particle*> MyParticles;
std::vector<Bullet*> MyPlayerBullets;
@ -93,6 +101,7 @@ static void hook_prefrag(int id, void *fragment, int size)
/* Screenshot takes precedence */
char const *type = screenshot ? "image" : "video";
#if(USB)
int pipe = usb_ff_bulk_output();
if(id == 0) {
@ -115,6 +124,8 @@ static void hook_prefrag(int id, void *fragment, int size)
usb_commit_sync(pipe);
screenshot = false;
}
#endif
}
@ -268,10 +279,12 @@ static void render( void )
if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.3f ms", (float) time_update / 1000.0f );
if (texttodraw>=2) Azur_draw_text(1,41, "Render = %.3f ms", (float) time_render / 1000.0f );
if (texttodraw>=2) Azur_draw_text(1,51, ">Total = %.0f ms", (float) elapsedTime / 1000.0f );
if (texttodraw>=3) Azur_draw_text(1,81, "Mem Used : %d", _uram_stats->used_memory + extram_stats->used_memory);
if (texttodraw>=3) Azur_draw_text(1,91, "Mem Free : %d", _uram_stats->free_memory + extram_stats->free_memory);
if (texttodraw>=3) Azur_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory + extram_stats->peak_used_memory );
#if(MORE_RAM)
if (texttodraw>=3) Azur_draw_text(1,81, "Mem Used : %d", _uram_stats->used_memory + extram_stats->used_memory);
if (texttodraw>=3) Azur_draw_text(1,91, "Mem Free : %d", _uram_stats->free_memory + extram_stats->free_memory);
if (texttodraw>=3) Azur_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory + extram_stats->peak_used_memory );
#endif
#endif
}
@ -300,7 +313,7 @@ static void get_inputs( float dt )
if (MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyHoldPressed(MYKEY_EXIT)) {exitToOS = true; };
#if(DEBUG_MODE)
#if(USB)
if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_7) && usb_is_open() ) {screenshot = true;};
if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_8) && usb_is_open()) {record = true; };
if(MyKeyboard.IsKeyPressed(MYKEY_SHIFT) && MyKeyboard.IsKeyPressedEvent(MYKEY_9) && usb_is_open()) {record = false; };
@ -327,55 +340,64 @@ static void get_inputs( float dt )
bool AddMoreRAM( void )
{
/* allow more RAM */
char const *osv = (char*) 0x80020020;
#if(MORE_RAM)
if((!strncmp(osv, "03.", 3) && osv[3] <= '6') && gint[HWCALC] == HWCALC_FXCG50) // CG-50
{
extended_ram.name = "extram";
extended_ram.is_default = true;
extended_ram.start = (void *)0x8c200000;
extended_ram.end = (void *)0x8c4e0000 ;
/* allow more RAM */
char const *osv = (char*) 0x80020020;
kmalloc_init_arena(&extended_ram, true);
kmalloc_add_arena(&extended_ram );
return true;
}
else if (gint[HWCALC] == HWCALC_PRIZM) // CG-10/20
{
if((!strncmp(osv, "03.", 3) && osv[3] <= '6') && gint[HWCALC] == HWCALC_FXCG50) // CG-50
{
extended_ram.name = "extram";
extended_ram.is_default = true;
extended_ram.start = (void *)0x8c200000;
extended_ram.end = (void *)0x8c4e0000 ;
extended_ram.name = "extram";
extended_ram.is_default = true;
kmalloc_init_arena(&extended_ram, true);
kmalloc_add_arena(&extended_ram );
return true;
}
else if (gint[HWCALC] == HWCALC_PRIZM) // CG-10/20
{
uint16_t *vram1, *vram2;
dgetvram(&vram1, &vram2);
dsetvram(vram1, vram1);
extended_ram.name = "extram";
extended_ram.is_default = true;
extended_ram.start = vram2;
extended_ram.end = (char *)vram2 + 396*224*2;
uint16_t *vram1, *vram2;
dgetvram(&vram1, &vram2);
dsetvram(vram1, vram1);
extended_ram.start = vram2;
extended_ram.end = (char *)vram2 + 396*224*2;
kmalloc_init_arena(&extended_ram, true);
kmalloc_add_arena(&extended_ram );
return false;
}
else if (gint[HWCALC] == HWCALC_FXCG_MANAGER) // CG-50 EMULATOR
{
extended_ram.name = "extram";
extended_ram.is_default = true;
extended_ram.start = (void *)0x88200000;
extended_ram.end = (void *)0x884e0000 ;
kmalloc_init_arena(&extended_ram, true);
kmalloc_add_arena(&extended_ram );
return true;
}
#else
kmalloc_init_arena(&extended_ram, true);
kmalloc_add_arena(&extended_ram );
return false;
}
else if (gint[HWCALC] == HWCALC_FXCG_MANAGER) // CG-50 EMULATOR
{
extended_ram.name = "extram";
extended_ram.is_default = true;
extended_ram.start = (void *)0x88200000;
extended_ram.end = (void *)0x884e0000 ;
kmalloc_init_arena(&extended_ram, true);
kmalloc_add_arena(&extended_ram );
return true;
}
#endif
}
void FreeMoreRAM( void )
{
memset(extended_ram.start, 0, (char *)extended_ram.end - (char *)extended_ram.start);
#if(MORE_RAM)
memset(extended_ram.start, 0, (char *)extended_ram.end - (char *)extended_ram.start);
#endif
}
/*
@ -403,7 +425,9 @@ int main(void)
{
exitToOS = false;
_uram = kmalloc_get_arena("_uram");
#if(MORE_RAM)
_uram = kmalloc_get_arena("_uram");
#endif
bool canWeAllocate3Mb = AddMoreRAM();
@ -411,10 +435,10 @@ int main(void)
__printf_enable_fixed();
azrp_config_scale(SCALE_PIXEL);
azrp_shader_clear_configure();
azrp_shader_image_rgb16_configure();
azrp_shader_image_p8_configure();
azrp_shader_image_p4_configure();
//azrp_shader_clear_configure();
//azrp_shader_image_rgb16_configure();
//azrp_shader_image_p8_configure();
//azrp_shader_image_p4_configure();
azrp_hook_set_prefrag(hook_prefrag);
azrp_starfield_init( 250 );
@ -429,8 +453,10 @@ int main(void)
#endif
*/
#if(USB)
usb_interface_t const *interfaces[] = { &usb_ff_bulk, NULL };
usb_open(interfaces, GINT_CALL_NULL);
#endif
prof_init();
@ -450,8 +476,10 @@ int main(void)
update( elapsedTime );
// update the RAM consumption status
_uram_stats = kmalloc_get_gint_stats(_uram);
extram_stats = kmalloc_get_gint_stats(&extended_ram);
#if(MORE_RAM)
_uram_stats = kmalloc_get_gint_stats(_uram);
extram_stats = kmalloc_get_gint_stats(&extended_ram);
#endif
}
prof_leave(perf_update);
@ -500,8 +528,10 @@ int main(void)
prof_quit();
usb_close();
#if(USB)
usb_close();
#endif
FreeMoreRAM( );

View File

@ -12,7 +12,6 @@ extern bopti_image_t img_mainship1;
extern bopti_image_t img_Satellite_Lvl1;
extern Background MyBackground;
Player::Player( int16_t _x, int16_t _y, uint8_t _id )
{
x = libnum::num(_x);

View File

@ -4,8 +4,6 @@
#include <cstdio>
#include <gint/rtc.h>
#include <gint/usb.h>
#include <gint/usb-ff-bulk.h>
#include <vector>
@ -52,42 +50,23 @@ std::vector<particle*> pixels;
std::vector<star*> starfield;
__attribute__((constructor))
static void register_shader(void)
{
extern azrp_shader_t azrp_shader_starfield;
AZRP_SHADER_STARFIELD = azrp_register_shader(azrp_shader_starfield);
}
void azrp_shader_starfield_configure(void)
static void azrp_shader_starfield_configure(void)
{
azrp_set_uniforms(AZRP_SHADER_STARFIELD, (void *)azrp_width);
}
__attribute__((constructor))
static void register_shader(void)
{
extern azrp_shader_t azrp_shader_starfield;
AZRP_SHADER_STARFIELD = azrp_register_shader(azrp_shader_starfield, azrp_shader_starfield_configure );
}
void azrp_starfield_USBDEBUG( uint8_t info )
{
char texttosend[1024];
int nbpixelcumulated = 0;
if (info==SHOW_PIXELS)
for(unsigned int i=0; i<pixels.size(); i++)
{
sprintf( texttosend, "Pixel %d : x=%d : y=%d : s=%d : f=%d : c=%d : o=%d\n", i, pixels[i]->x, pixels[i]->y, pixels[i]->s, pixels[i]->frag, pixels[i]->c, pixels[i]->off );
usb_fxlink_text(texttosend, 0);
}
else if (info==SHOW_STARS)
for(unsigned int i=0; i<starfield.size(); i++)
{
if (starfield[i]->n==1 || starfield[i]->n==2) nbpixelcumulated+=4;
else if (starfield[i]->n==3) nbpixelcumulated+=9;
else if (starfield[i]->n==4) nbpixelcumulated+=21;
sprintf( texttosend, "Star %d : x=%d : y=%d : s=%d : n=%d : t=%d : cumul=%d\n", i, starfield[i]->x, starfield[i]->y, starfield[i]->s, starfield[i]->n, starfield[i]->t, nbpixelcumulated );
usb_fxlink_text(texttosend, 0);
}
}
@ -273,11 +252,21 @@ void azrp_starfield( void )
{
prof_enter(azrp_perf_cmdgen);
struct command cmd;
cmd.shader_id = AZRP_SHADER_STARFIELD;
cmd.current_frag = 0;
cmd.nbpixel = pixels.size();
cmd.data = pixels.data();
int fragmin = 0;
int fragcount = (223 >> 4) + 1;
struct command *cmd = (struct command *) azrp_new_command(sizeof *cmd, fragmin, fragcount);
if(!cmd) {
prof_leave(azrp_perf_cmdgen);
return;
}
cmd->shader_id = AZRP_SHADER_STARFIELD;
cmd->current_frag = 0;
cmd->nbpixel = pixels.size();
cmd->data = pixels.data();
for(unsigned int i=0; i<pixels.size(); i++)
{
@ -286,10 +275,6 @@ void azrp_starfield( void )
pixels[i]->off = pixels[i]->y & 15;
}
int fragmin = 0;
int fragcount = (223 >> 4) + 1;
azrp_queue_command(&cmd, sizeof cmd, fragmin, fragcount);
prof_leave(azrp_perf_cmdgen);
}

View File

@ -4,8 +4,7 @@
#include <cstdio>
#include <gint/rtc.h>
#include <gint/usb.h>
#include <gint/usb-ff-bulk.h>