diff --git a/src/Graphics_GL11.c b/src/Graphics_GL11.c index 67d29ec73..81226ec37 100644 --- a/src/Graphics_GL11.c +++ b/src/Graphics_GL11.c @@ -136,28 +136,28 @@ void Gfx_SetDynamicVbData(GfxResourceID vb, void* vertices, int vCount) { static void GL_SetupVbColoured(void) { GLpointer ptr = (GLpointer)VB_PTR; - _glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_COLOURED, ptr + 0); - _glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_COLOURED, ptr + 12); + glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_COLOURED, ptr + 0); + glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_COLOURED, ptr + 12); } static void GL_SetupVbTextured(void) { GLpointer ptr = (GLpointer)VB_PTR; - _glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 0); - _glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_TEXTURED, ptr + 12); - _glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 16); + glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 0); + glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_TEXTURED, ptr + 12); + glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 16); } static void GL_SetupVbColoured_Range(int startVertex) { GLpointer ptr = (GLpointer)VB_PTR + startVertex * SIZEOF_VERTEX_COLOURED; - _glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_COLOURED, ptr + 0); - _glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_COLOURED, ptr + 12); + glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_COLOURED, ptr + 0); + glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_COLOURED, ptr + 12); } static void GL_SetupVbTextured_Range(int startVertex) { GLpointer ptr = (GLpointer)VB_PTR + startVertex * SIZEOF_VERTEX_TEXTURED; - _glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 0); - _glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_TEXTURED, ptr + 12); - _glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 16); + glVertexPointer(3, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 0); + glColorPointer(4, GL_UNSIGNED_BYTE, SIZEOF_VERTEX_TEXTURED, ptr + 12); + glTexCoordPointer(2, GL_FLOAT, SIZEOF_VERTEX_TEXTURED, ptr + 16); } void Gfx_SetVertexFormat(VertexFormat fmt) { @@ -166,14 +166,14 @@ void Gfx_SetVertexFormat(VertexFormat fmt) { gfx_stride = strideSizes[fmt]; if (fmt == VERTEX_FORMAT_TEXTURED) { - _glEnableClientState(GL_TEXTURE_COORD_ARRAY); - _glEnable(GL_TEXTURE_2D); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glEnable(GL_TEXTURE_2D); gfx_setupVBFunc = GL_SetupVbTextured; gfx_setupVBRangeFunc = GL_SetupVbTextured_Range; } else { - _glDisableClientState(GL_TEXTURE_COORD_ARRAY); - _glDisable(GL_TEXTURE_2D); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisable(GL_TEXTURE_2D); gfx_setupVBFunc = GL_SetupVbColoured; gfx_setupVBRangeFunc = GL_SetupVbColoured_Range; @@ -182,21 +182,21 @@ void Gfx_SetVertexFormat(VertexFormat fmt) { void Gfx_DrawVb_Lines(int verticesCount) { gfx_setupVBFunc(); - _glDrawArrays(GL_LINES, 0, verticesCount); + glDrawArrays(GL_LINES, 0, verticesCount); } void Gfx_DrawVb_IndexedTris_Range(int verticesCount, int startVertex, DrawHints hints) { if (activeList != gl_DYNAMICLISTID) { glCallList(activeList); return; } gfx_setupVBRangeFunc(startVertex); - _glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, gl_indices); + glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, gl_indices); } void Gfx_DrawVb_IndexedTris(int verticesCount) { if (activeList != gl_DYNAMICLISTID) { glCallList(activeList); return; } gfx_setupVBFunc(); - _glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, gl_indices); + glDrawElements(GL_TRIANGLES, ICOUNT(verticesCount), GL_UNSIGNED_SHORT, gl_indices); } void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { @@ -208,7 +208,7 @@ void Gfx_DrawIndexedTris_T2fC4b(int verticesCount, int startVertex) { *---------------------------------------------------------Textures--------------------------------------------------------* *#########################################################################################################################*/ void Gfx_BindTexture(GfxResourceID texId) { - _glBindTexture(GL_TEXTURE_2D, ptr_to_uint(texId)); + glBindTexture(GL_TEXTURE_2D, ptr_to_uint(texId)); } @@ -221,7 +221,7 @@ static int gfx_fogMode; void Gfx_SetFog(cc_bool enabled) { gfx_fogEnabled = enabled; - if (enabled) { _glEnable(GL_FOG); } else { _glDisable(GL_FOG); } + if (enabled) { glEnable(GL_FOG); } else { glDisable(GL_FOG); } } void Gfx_SetFogCol(PackedCol color) { @@ -233,19 +233,19 @@ void Gfx_SetFogCol(PackedCol color) { rgba[2] = PackedCol_B(color) / 255.0f; rgba[3] = PackedCol_A(color) / 255.0f; - _glFogfv(GL_FOG_COLOR, rgba); + glFogfv(GL_FOG_COLOR, rgba); gfx_fogColor = color; } void Gfx_SetFogDensity(float value) { if (value == gfx_fogDensity) return; - _glFogf(GL_FOG_DENSITY, value); + glFogf(GL_FOG_DENSITY, value); gfx_fogDensity = value; } void Gfx_SetFogEnd(float value) { if (value == gfx_fogEnd) return; - _glFogf(GL_FOG_END, value); + glFogf(GL_FOG_END, value); gfx_fogEnd = value; } @@ -253,12 +253,12 @@ void Gfx_SetFogMode(FogFunc func) { static GLint modes[3] = { GL_LINEAR, GL_EXP, GL_EXP2 }; if (func == gfx_fogMode) return; - _glFogi(GL_FOG_MODE, modes[func]); + glFogi(GL_FOG_MODE, modes[func]); gfx_fogMode = func; } static void SetAlphaTest(cc_bool enabled) { - if (enabled) { _glEnable(GL_ALPHA_TEST); } else { _glDisable(GL_ALPHA_TEST); } + if (enabled) { glEnable(GL_ALPHA_TEST); } else { glDisable(GL_ALPHA_TEST); } } void Gfx_DepthOnlyRendering(cc_bool depthOnly) { @@ -266,7 +266,7 @@ void Gfx_DepthOnlyRendering(cc_bool depthOnly) { SetColorWrite(enabled & gfx_colorMask[0], enabled & gfx_colorMask[1], enabled & gfx_colorMask[2], enabled & gfx_colorMask[3]); - if (enabled) { _glEnable(GL_TEXTURE_2D); } else { _glDisable(GL_TEXTURE_2D); } + if (enabled) { glEnable(GL_TEXTURE_2D); } else { glDisable(GL_TEXTURE_2D); } } @@ -277,12 +277,12 @@ static GLenum matrix_modes[] = { GL_PROJECTION, GL_MODELVIEW, GL_TEXTURE }; static int lastMatrix; void Gfx_LoadMatrix(MatrixType type, const struct Matrix* matrix) { - if (type != lastMatrix) { lastMatrix = type; _glMatrixMode(matrix_modes[type]); } + if (type != lastMatrix) { lastMatrix = type; glMatrixMode(matrix_modes[type]); } if (matrix == &Matrix_Identity) { - _glLoadIdentity(); + glLoadIdentity(); } else { - _glLoadMatrixf((const float*)matrix); + glLoadMatrixf((const float*)matrix); } } @@ -307,8 +307,8 @@ void Gfx_DisableTextureOffset(void) { Gfx_LoadMatrix(2, &Matrix_Identity); } static void Gfx_FreeState(void) { FreeDefaultResources(); } static void Gfx_RestoreState(void) { InitDefaultResources(); - _glEnableClientState(GL_VERTEX_ARRAY); - _glEnableClientState(GL_COLOR_ARRAY); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_COLOR_ARRAY); gfx_format = -1; lastMatrix = -1; @@ -319,9 +319,9 @@ static void Gfx_RestoreState(void) { gfx_fogDensity = -1.0f; gfx_fogMode = -1; - _glAlphaFunc(GL_GREATER, 0.5f); - _glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - _glDepthFunc(GL_LEQUAL); + glAlphaFunc(GL_GREATER, 0.5f); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glDepthFunc(GL_LEQUAL); } cc_bool Gfx_WarnIfNecessary(void) { diff --git a/src/Graphics_NDS.c b/src/Graphics_NDS.c index 316c9a47f..285cccba2 100644 --- a/src/Graphics_NDS.c +++ b/src/Graphics_NDS.c @@ -182,19 +182,6 @@ typedef struct CCTexture_ { #define TEX_TOTAL_BLOCKS (TEX_TOTAL_SIZE / TEX_BLOCK_SIZE) static cc_uint8 tex_table[TEX_TOTAL_BLOCKS / BLOCKS_PER_PAGE]; -static void texture_alloc(CCTexture* tex, int size) { - int blocks = (size + (TEX_BLOCK_SIZE - 1)) / TEX_BLOCK_SIZE; - int addr = blockalloc_alloc(tex_table, TEX_TOTAL_BLOCKS, blocks); - if (addr == -1) return; - - tex->texBase = addr; - tex->texBlocks = blocks; -} - -static void texture_release(CCTexture* tex) { - blockalloc_dealloc(tex_table, tex->texBase, tex->texBlocks); -} - // Palette VRAM banks - Bank E (64 kb) #define PAL_TOTAL_SIZE (64 * 1024) // Use 16 hwords for size of each block @@ -203,19 +190,6 @@ static void texture_release(CCTexture* tex) { #define PAL_TOTAL_BLOCKS (PAL_TOTAL_SIZE / PAL_BLOCK_SIZE) static cc_uint8 pal_table[PAL_TOTAL_BLOCKS / BLOCKS_PER_PAGE]; -static void palette_alloc(CCTexture* tex, int size) { - int blocks = (size + (PAL_BLOCK_SIZE - 1)) / PAL_BLOCK_SIZE; - int addr = blockalloc_alloc(pal_table, PAL_TOTAL_BLOCKS, blocks); - if (addr == -1) return; - - tex->palBase = addr; - tex->palBlocks = blocks; -} - -static void palette_release(CCTexture* tex) { - blockalloc_dealloc(pal_table, tex->palBase, tex->palBlocks); -} - /*########################################################################################################################* *---------------------------------------------------------Textures--------------------------------------------------------* @@ -294,8 +268,8 @@ static CC_INLINE int CalcPalette(cc_uint16* palette, struct Bitmap* bmp, int row } GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { - CCTexture* tex = Mem_TryAllocCleared(1, sizeof(CCTexture)); - if (!tex) return 0; + CCTexture* tex = Mem_TryAlloc(1, sizeof(CCTexture)); + if (!tex) return NULL; int dst_w = Math_NextPowOf2(bmp->width); int dst_h = Math_NextPowOf2(bmp->height); @@ -321,12 +295,17 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, tex_fmt = GL_RGBA; } - texture_alloc(tex, tex_size); - if (!tex->texBlocks) { + int blocks = SIZE_TO_BLOCKS(tex_size, TEX_BLOCK_SIZE); + int base = blockalloc_alloc(tex_table, TEX_TOTAL_BLOCKS, blocks); + if (base < 0) { Platform_Log2("No VRAM for %i x %i texture", &bmp->width, &bmp->height); + Mem_Free(tex); return NULL; } + tex->texBase = base; + tex->texBlocks = blocks; + int offset = tex->texBase * TEX_BLOCK_SIZE; u16* addr = (u16*)((u8*)VRAM_A + offset); u16* tmp_u16[128]; // 256 bytes @@ -394,14 +373,18 @@ GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, vramRestorePrimaryBanks(banks); - int sSize = (Math_ilog2(dst_w) - 3) << 20; - int tSize = (Math_ilog2(dst_h) - 3) << 23; + int sSize = (Math_ilog2(dst_w) - 3) << 20; + int tSize = (Math_ilog2(dst_h) - 3) << 23; tex->texFormat = (offset >> 3) | sSize | tSize | (tex_fmt << 26) | GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T | TEXGEN_TEXCOORD | GL_TEXTURE_COLOR0_TRANSPARENT; if (tex_fmt != GL_RGBA) { - palette_alloc(tex, pal_count * 2); + blocks = SIZE_TO_BLOCKS(pal_count * 2, PAL_BLOCK_SIZE); + base = blockalloc_alloc(pal_table, PAL_TOTAL_BLOCKS, blocks); + + tex->palBase = base < 0 ? 0 : base; // TODO probably not correct, but shouldn't happen in practice + tex->palBlocks = blocks; offset = tex->palBase * PAL_BLOCK_SIZE; vramSetBankE(VRAM_E_LCD); @@ -424,7 +407,6 @@ void Gfx_BindTexture(GfxResourceID texId) { void Gfx_UpdateTexture(GfxResourceID texId, int x, int y, struct Bitmap* part, int rowWidth, cc_bool mipmaps) { CCTexture* tex = (CCTexture*)texId; - int width = tex->width; return; // TODO doesn't work without VRAM bank changing to LCD and back maybe?? // (see what glTeximage2D does ??) @@ -445,8 +427,8 @@ void Gfx_DeleteTexture(GfxResourceID* texId) { CCTexture* tex = (CCTexture*)(*texId); if (tex) { - texture_release(tex); - palette_release(tex); + blockalloc_dealloc(tex_table, tex->texBase, tex->texBlocks); + blockalloc_dealloc(pal_table, tex->palBase, tex->palBlocks); Mem_Free(tex); } *texId = NULL; diff --git a/src/SystemFonts.c b/src/SystemFonts.c index 1c2f3bbf3..83eba18d1 100644 --- a/src/SystemFonts.c +++ b/src/SystemFonts.c @@ -248,7 +248,7 @@ void FallbackFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, } } -static void Fallback_PlotCell(int x, int scale, const cc_uint8* rows, FallbackFont_Plotter plotter, void* ctx) { +static void Fallback_PlotCell(int scale, const cc_uint8* rows, FallbackFont_Plotter plotter, void* ctx) { int xx, srcX, dstX; int yy, srcY, dstY; cc_uint8 src_row; @@ -260,8 +260,8 @@ static void Fallback_PlotCell(int x, int scale, const cc_uint8* rows, FallbackFo for (srcX = 0; srcX < CELL_SIZE; srcX++) { if (!(src_row & (1 << srcX))) continue; - dstX = x + srcX * scale; - dstY = 0 + srcY * scale; + dstX = srcX * scale; + dstY = srcY * scale; for (yy = 0; yy < scale; yy++) for (xx = 0; xx < scale; xx++) @@ -272,20 +272,14 @@ static void Fallback_PlotCell(int x, int scale, const cc_uint8* rows, FallbackFo } } -void FallbackFont_Plot(cc_string* str, FallbackFont_Plotter plotter, int scale, void* ctx) { +int FallbackFont_Plot(cc_uint8 c, FallbackFont_Plotter plotter, int scale, void* ctx) { const cc_uint8* rows; - int i, x = 0; - for (i = 0; i < str->length; i++) - { - cc_uint8 c = str->buffer[i]; - if (c == ' ') { x += SPACE_WIDTH * scale; continue; } + if (c == ' ') return SPACE_WIDTH * scale; + rows = FallbackFont_GetRows(c); - rows = FallbackFont_GetRows(c); - - Fallback_PlotCell(x, scale, rows, plotter, ctx); - x += Fallback_CellWidth(rows) * scale; - } + Fallback_PlotCell(scale, rows, plotter, ctx); + return Fallback_CellWidth(rows) * scale; } diff --git a/src/SystemFonts.h b/src/SystemFonts.h index 7ddd63478..1e7eed300 100644 --- a/src/SystemFonts.h +++ b/src/SystemFonts.h @@ -15,8 +15,9 @@ extern struct IGameComponent SystemFonts_Component; int FallbackFont_TextWidth(const struct DrawTextArgs* args); void FallbackFont_DrawText(struct DrawTextArgs* args, struct Bitmap* bmp, int x, int y, cc_bool shadow); + typedef void (*FallbackFont_Plotter)(int x, int y, void* ctx); -void FallbackFont_Plot(cc_string* str, FallbackFont_Plotter plotter, int scale, void* ctx); +int FallbackFont_Plot(cc_uint8 c, FallbackFont_Plotter plotter, int scale, void* ctx); /* Allocates a new system font from the given arguments */ cc_result SysFont_Make(struct FontDesc* desc, const cc_string* fontName, int size, int flags); diff --git a/src/Window_NDS.c b/src/Window_NDS.c index 111e62087..f722b6ff4 100644 --- a/src/Window_NDS.c +++ b/src/Window_NDS.c @@ -100,7 +100,7 @@ static void Console_LoadFont(int bgId, u16* palette) { for (int i = 0; i < FONT_NUM_CHARACTERS * 8; i++) { - u8 row = default_fontTiles[i]; + u8 row = default_fontTiles[i]; u32 gfx = 0; if (row & 0x01) gfx |= 0x0000000F; if (row & 0x02) gfx |= 0x000000F0; diff --git a/src/_BlockAlloc.h b/src/_BlockAlloc.h index 47aadb8cb..979511dd9 100644 --- a/src/_BlockAlloc.h +++ b/src/_BlockAlloc.h @@ -2,6 +2,8 @@ #define blockalloc_bit(block) (1 << ((block) & 0x07)) #define BLOCKS_PER_PAGE 8 +#define SIZE_TO_BLOCKS(size, blockSize) (((size) + ((blockSize) - 1)) / (blockSize)) + static CC_INLINE int blockalloc_can_alloc(cc_uint8* table, int beg, int blocks) { for (int i = beg; i < beg + blocks; i++) { @@ -44,10 +46,11 @@ static void blockalloc_dealloc(cc_uint8* table, int origin, int blocks) { } } -// TODO: is this worth optimising to look at entire page in 0x00 and 0xFF case? -static int blockalloc_total_free(cc_uint8* table, int maxBlocks) { +static CC_INLINE int blockalloc_total_free(cc_uint8* table, int maxBlocks) { int free_blocks = 0, i, used; cc_uint8 page; + // could be optimised to look at entire page in 0x00 and 0xFF case + // but this method is called so infrequently, not really worth it for (i = 0; i < maxBlocks; i++) { @@ -55,7 +58,6 @@ static int blockalloc_total_free(cc_uint8* table, int maxBlocks) { used = page & blockalloc_bit(i); if (!used) free_blocks++; - i++; } return free_blocks; } diff --git a/src/dreamcast/Graphics_Dreamcast.c b/src/dreamcast/Graphics_Dreamcast.c index bfddab952..5ad3d9271 100644 --- a/src/dreamcast/Graphics_Dreamcast.c +++ b/src/dreamcast/Graphics_Dreamcast.c @@ -182,24 +182,15 @@ static void texmem_free(cc_uint8* ptr, cc_uint32 size) { texmem_used[page + i] = 0; } -static cc_uint32 texmem_total_free(void) { - cc_uint32 free = 0; +static int texmem_total_free(void) { + int free = 0; for (cc_uint32 page = 0; page < texmem_pages; page++) { - if (!texmem_used[page]) free += TEXMEM_PAGE_SIZE; + if (!texmem_used[page]) free++; } return free; } -static cc_uint32 texmem_total_used(void) { - cc_uint32 used = 0; - for (cc_uint32 page = 0; page < texmem_pages; page++) - { - if (texmem_used[page]) used += TEXMEM_PAGE_SIZE; - } - return used; -} - /*########################################################################################################################* *---------------------------------------------------------General---------------------------------------------------------* @@ -1053,10 +1044,13 @@ cc_result Gfx_TakeScreenshot(struct Stream* output) { void Gfx_GetApiInfo(cc_string* info) { int freeMem = texmem_total_free(); - int usedMem = texmem_total_used(); + int usedMem = texmem_pages - freeMem; + + freeMem *= TEXMEM_PAGE_SIZE; + usedMem *= TEXMEM_PAGE_SIZE; - float freeMemMB = freeMem / (1024.0 * 1024.0); - float usedMemMB = usedMem / (1024.0 * 1024.0); + float freeMemMB = freeMem / (1024.0f * 1024.0f); + float usedMemMB = usedMem / (1024.0f * 1024.0f); String_AppendConst(info, "-- Using Dreamcast --\n"); String_AppendConst(info, "GPU: PowerVR2 CLX2 100mHz\n"); diff --git a/src/dreamcast/Platform_Dreamcast.c b/src/dreamcast/Platform_Dreamcast.c index 912e9ea50..f0ff07410 100644 --- a/src/dreamcast/Platform_Dreamcast.c +++ b/src/dreamcast/Platform_Dreamcast.c @@ -58,10 +58,15 @@ extern cc_bool window_inited; #define MAX_ONSCREEN_LINES 17 #define ONSCREEN_LINE_HEIGHT (24 + 2) // 8 * 3 text, plus 2 pixel padding -#define Onscreen_LineOffset(y) ((10 + y + (str_offset * ONSCREEN_LINE_HEIGHT)) * vid_mode->width) +#define Onscreen_LineOffset(y) ((y) * vid_mode->width) +struct LogPosition { int x, y; }; static void PlotOnscreen(int x, int y, void* ctx) { + struct LogPosition* pos = ctx; + + x += pos->x; if (x >= vid_mode->width) return; + y += pos->y; uint32 line_offset = Onscreen_LineOffset(y); vram_s[line_offset + x] = 0xFFFF; @@ -77,13 +82,21 @@ static void LogOnscreen(const char* msg, int len) { if (log_timestamp) String_Format2(&str, "[%p2.%p3] ", &secs, &ms); String_AppendAll(&str, msg, len); - short* dst = vram_s + Onscreen_LineOffset(0); + struct LogPosition pos; + pos.x = 0; + pos.y = 10 + (str_offset * ONSCREEN_LINE_HEIGHT); + + str_offset = (str_offset + 1) % MAX_ONSCREEN_LINES; + + short* dst = vram_s + Onscreen_LineOffset(pos.y); int num_pixels = ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width; for (int i = 0; i < num_pixels; i++) dst[i] = 0; - //sq_set16(vram_s + Onscreen_LineOffset(0), 0, ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width); + //sq_set16(vram_s + Onscreen_LineOffset(pos.y), 0, ONSCREEN_LINE_HEIGHT * 2 * vid_mode->width); - FallbackFont_Plot(&str, PlotOnscreen, 3, NULL); - str_offset = (str_offset + 1) % MAX_ONSCREEN_LINES; + for (int i = 0; i < str.length; i++) + { + pos.x += FallbackFont_Plot((cc_uint8)str.buffer[i], PlotOnscreen, 3, &pos); + } } void Platform_Log(const char* msg, int len) { diff --git a/src/saturn/Graphics_Saturn.c b/src/saturn/Graphics_Saturn.c index 14b8c2276..ceb733911 100644 --- a/src/saturn/Graphics_Saturn.c +++ b/src/saturn/Graphics_Saturn.c @@ -168,38 +168,28 @@ typedef struct CCTexture { #define TEX_TOTAL_BLOCKS (TEXTURE_REGION_SIZE / TEX_BLOCK_SIZE) static cc_uint8 tex_table[TEX_TOTAL_BLOCKS / BLOCKS_PER_PAGE]; -static cc_bool texture_alloc(CCTexture* tex, int width, int height) { - int size = width * height * 2; - - int blocks = (size + (TEX_BLOCK_SIZE - 1)) / TEX_BLOCK_SIZE; - int addr = blockalloc_alloc(tex_table, TEX_TOTAL_BLOCKS, blocks); - if (addr == -1) return false; - - tex->width = width; - tex->height = height; - tex->offset = addr; - tex->blocks = blocks; - return true; -} - -static void texture_release(CCTexture* tex) { - blockalloc_dealloc(tex_table, tex->offset, tex->blocks); -} - GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, int rowWidth, cc_uint8 flags, cc_bool mipmaps) { CCTexture* tex = Mem_TryAlloc(1, sizeof(CCTexture)); if (!tex) return NULL; - if (!texture_alloc(tex, bmp->width, bmp->height)) { + int width = bmp->width, height = bmp->height; + int blocks = SIZE_TO_BLOCKS(width * height * 2, TEX_BLOCK_SIZE); + int addr = blockalloc_alloc(tex_table, TEX_TOTAL_BLOCKS, blocks); + + if (addr == -1) { Platform_LogConst("OUT OF VRAM"); Mem_Free(tex); return NULL; } + tex->width = width; + tex->height = height; + tex->offset = addr; + tex->blocks = blocks; + int vram_free = blockalloc_total_free(tex_table, TEX_TOTAL_BLOCKS) * TEX_BLOCK_SIZE; Platform_Log1("VRAM left: %i bytes", &vram_free); - int width = bmp->width, height = bmp->height; cc_uint8* tmp = CCTexture_Addr(tex); cc_uint16* src = bmp->scan0; cc_uint16* dst = (cc_uint16*)tmp; @@ -226,10 +216,10 @@ void Gfx_BindTexture(GfxResourceID texId) { void Gfx_DeleteTexture(GfxResourceID* texId) { CCTexture* tex = *texId; - if (tex) { - texture_release(tex); - Mem_Free(tex); - } + if (!tex) return; + + blockalloc_dealloc(tex_table, tex->offset, tex->blocks); + Mem_Free(tex); *texId = NULL; }