summaryrefslogtreecommitdiffstatshomepage
path: root/src/build
diff options
context:
space:
mode:
author Aaron Giles <aaron@aarongiles.com>2014-03-11 15:54:58 +0000
committer Aaron Giles <aaron@aarongiles.com>2014-03-11 15:54:58 +0000
commit4ea9df02a1daf1893246a01e21ffe201781f9266 (patch)
tree70dcb5feb88dcabe713fc172c30fd159ed1a0a43 /src/build
parentb05606404a780c5309d39d8ee45411292279f117 (diff)
Moved core template container classes up from emutempl.h to coretmpl.h:
[Aaron Giles] * these classes now no longer take a resource_pool; everything is managed globally -- this means that objects added to lists must be allocated with global_alloc * added new auto_pointer<> template which wraps a pointer and auto-frees it upon destruction; it also defaults to NULL so it doesn't need to be explicitly initialized * moved tagged_list template to tagmap.h Redo of the low-level memory tracking system: [Aaron Giles] * moved low-level tracking out of emu\emualloc into lib\util\corealloc so it can be shared among all components and used by core libraries * global_alloc and friends no longer use a resource pool to track allocations; turns out this was a wholly redundant system that wasted a lot of memory * removed global_resource_pool entirely * added global_free_array to delete arrays allocated with global_alloc_array * added tracking of object versus array allocation; we will now error if you use global_free on an array, or global_free_array on an object Added new utility helper const_string_pool which can be used to efficiently accumulate strings that are not intended to be modified. Used by updated makelist and software list code. [Aaron Giles] Updated png2bdc and makelist tools to not leak memory and use more modern techniques (no more MAX_DRIVERS in makelist, for example). [Aaron Giles] Deprecated auto_strdup and removed all uses by way of caller-managed astrings and the software list rewrite. [Aaron Giles] Rewrote software list management: [Aaron Giles] * removed the notion of a software_list that is separate from a software_list_device; they are one and the same now * moved several functions into device_image_interface since they really didn't belong in the core software list class * lots of simplification as a result of the above changes Additional notes (no whatsnew): Moved definition of FPTR to osdcomm.h. Some changes happened in the OSD code to fix issues, especially regarding freeing arrays. SDL folks may need to fix up some of these. The following devices still are using tokens and should be modernized (I found them because they kept their token as void * and tried to delete it, which you can't): namco_52xx_device (mame/audio/namco52.c) namco_54xx_device (mame/audio/namco54.c) namco_06xx_device (mame/machine/namco06.c) namco_50xx_device (mame/machine/namco50.c) namco_51xx_device (mame/machine/namco51.c) namco_53xx_device (mame/machine/namco53.c) voodoo_device (emu/video/voodoo.c) mos6581_device (emu/sound/mos6581.c) aica_device (emu/sound/aica.c) scsp_device (emu/sound/scsp.c) dmadac_sound_device (emu/sound/dmadac.c) s3c2440_device (emu/machine/s3c2440.c) wd1770_device (emu/machine/wd17xx.c) latch8_device (emu/machine/latch8.c) duart68681_device (emu/machine/68681.c) s3c2400_device (emu/machine/s3c2400.c) s3c2410_device (emu/machine/s3c2410.c) strataflash_device (mess/machine/strata.c) hd63450_device (mess/machine/hd63450.c) tap_990_device (mess/machine/ti99/990_tap.c) omti8621_device (mess/machine/omti8621.c) vdt911_device (mess/video/911_vdt.c) apollo_graphics_15i (mess/video/apollo.c) asr733_device (mess/video/733_asr.c)
Diffstat (limited to 'src/build')
-rw-r--r--src/build/makelist.c62
-rw-r--r--src/build/png2bdc.c445
2 files changed, 234 insertions, 273 deletions
diff --git a/src/build/makelist.c b/src/build/makelist.c
index df2afef66dc..04327e78fe0 100644
--- a/src/build/makelist.c
+++ b/src/build/makelist.c
@@ -12,15 +12,12 @@
#include <stdlib.h>
#include <ctype.h>
#include "corefile.h"
+#include "cstrpool.h"
-#define MAX_DRIVERS 65536
-#define MAX_IGNORE 512
-
-static const char *drivlist[MAX_DRIVERS];
-static int drivcount;
-static const char *ignorelst[MAX_IGNORE];
-static int ignorecount;
+static dynamic_array<const char *> drivlist;
+static dynamic_array<const char *> ignorelst;
+static const_string_pool string_pool;
//-------------------------------------------------
@@ -42,11 +39,9 @@ int sort_callback(const void *elem1, const void *elem2)
bool isignored(const char *drivname)
{
- if (ignorecount>0) {
- for(int i=0;i<ignorecount;i++) {
- if (strcmp(ignorelst[i],drivname)==0) return true;
- }
- }
+ for (int i = 0; i < ignorelst.count(); i++)
+ if (strcmp(ignorelst[i], drivname) == 0)
+ return true;
return false;
}
@@ -58,9 +53,8 @@ bool isignored(const char *drivname)
int parse_file(const char *srcfile)
{
// read source file
- void *buffer;
- UINT32 length;
- file_error filerr = core_fload(srcfile, &buffer, &length);
+ dynamic_buffer buffer;
+ file_error filerr = core_fload(srcfile, buffer);
if (filerr != FILERR_NONE)
{
fprintf(stderr, "Unable to read source file '%s'\n", srcfile);
@@ -68,8 +62,8 @@ int parse_file(const char *srcfile)
}
// rip through it to find all drivers
- char *srcptr = (char *)buffer;
- char *endptr = srcptr + length;
+ char *srcptr = (char *)&buffer[0];
+ char *endptr = srcptr + buffer.count();
int linenum = 1;
bool in_comment = false;
while (srcptr < endptr)
@@ -141,9 +135,7 @@ int parse_file(const char *srcfile)
drivname[pos+1] = 0;
}
fprintf(stderr, "Place driver '%s' to ignore list\n", drivname);
- char *name = (char *)malloc(strlen(drivname) + 1);
- strcpy(name, drivname);
- ignorelst[ignorecount++] = name;
+ ignorelst.append(string_pool.add(drivname));
continue;
}
@@ -167,16 +159,10 @@ int parse_file(const char *srcfile)
}
// add it to the list
- if(!isignored(drivname))
- {
- char *name = (char *)malloc(strlen(drivname) + 1);
- strcpy(name, drivname);
- drivlist[drivcount++] = name;
- }
+ if (!isignored(drivname))
+ drivlist.append(string_pool.add(drivname));
}
- osd_free(buffer);
-
return 0;
}
@@ -201,44 +187,42 @@ int main(int argc, char *argv[])
const char *srcfile = argv[1];
// parse the root file, exit early upon failure
- drivcount = 0;
- ignorecount = 0;
if (parse_file(srcfile))
return 1;
// output a count
- if (drivcount == 0)
+ if (drivlist.count() == 0)
{
fprintf(stderr, "No drivers found\n");
return 1;
}
- fprintf(stderr, "%d drivers found\n", drivcount);
+ fprintf(stderr, "%d drivers found\n", drivlist.count());
// add a reference to the ___empty driver
- drivlist[drivcount++] = "___empty";
+ drivlist.append("___empty");
// sort the list
- qsort(drivlist, drivcount, sizeof(*drivlist), sort_callback);
+ qsort(drivlist, drivlist.count(), sizeof(drivlist[0]), sort_callback);
// start with a header
printf("#include \"emu.h\"\n\n");
printf("#include \"drivenum.h\"\n\n");
// output the list of externs first
- for (int index = 0; index < drivcount; index++)
+ for (int index = 0; index < drivlist.count(); index++)
printf("GAME_EXTERN(%s);\n", drivlist[index]);
printf("\n");
// then output the array
- printf("const game_driver * const driver_list::s_drivers_sorted[%d] =\n", drivcount);
+ printf("const game_driver * const driver_list::s_drivers_sorted[%d] =\n", drivlist.count());
printf("{\n");
- for (int index = 0; index < drivcount; index++)
- printf("\t&GAME_NAME(%s)%s\n", drivlist[index], (index == drivcount - 1) ? "" : ",");
+ for (int index = 0; index < drivlist.count(); index++)
+ printf("\t&GAME_NAME(%s)%s\n", drivlist[index], (index == drivlist.count() - 1) ? "" : ",");
printf("};\n");
printf("\n");
// also output a global count
- printf("int driver_list::s_driver_count = %d;\n", drivcount);
+ printf("int driver_list::s_driver_count = %d;\n", drivlist.count());
return 0;
}
diff --git a/src/build/png2bdc.c b/src/build/png2bdc.c
index e05633d12c4..9eb986a170c 100644
--- a/src/build/png2bdc.c
+++ b/src/build/png2bdc.c
@@ -1,12 +1,11 @@
+// license:BSD-3-Clause
+// copyright-holders:Aaron Giles
/***************************************************************************
png2bdc.c
Super-simple PNG to BDC file generator
- Copyright Nicola Salmoria and the MAME Team.
- Visit http://mamedev.org for licensing and usage restrictions.
-
****************************************************************************
Format of PNG data:
@@ -54,227 +53,219 @@
#include "png.h"
-/***************************************************************************
- CONSTANTS & DEFINES
-***************************************************************************/
+//**************************************************************************
+// CONSTANTS & DEFINES
+//**************************************************************************
#define CACHED_CHAR_SIZE 12
#define CACHED_HEADER_SIZE 16
-/***************************************************************************
- TYPE DEFINITIONS
-***************************************************************************/
+//**************************************************************************
+// TYPE DEFINITIONS
+//**************************************************************************
-/* a render_font contains information about a single character in a font */
+// a render_font contains information about a single character in a font
struct render_font_char
{
- INT32 width; /* width from this character to the next */
- INT32 xoffs, yoffs; /* X and Y offset from baseline to top,left of bitmap */
- INT32 bmwidth, bmheight; /* width and height of bitmap */
- bitmap_argb32 * bitmap; /* pointer to the bitmap containing the raw data */
+ render_font_char() : width(0), xoffs(0), yoffs(0), bmwidth(0), bmheight(0) { }
+
+ INT32 width; // width from this character to the next
+ INT32 xoffs, yoffs; // X and Y offset from baseline to top,left of bitmap
+ INT32 bmwidth, bmheight; // width and height of bitmap
+ bitmap_argb32 * bitmap; // pointer to the bitmap containing the raw data
};
-/* a render_font contains information about a font */
+// a render_font contains information about a font
struct render_font
{
- int height; /* height of the font, from ascent to descent */
- int yoffs; /* y offset from baseline to descent */
- render_font_char chars[65536]; /* array of characters */
+ render_font() : height(0), yoffs(0) { }
+
+ int height; // height of the font, from ascent to descent
+ int yoffs; // y offset from baseline to descent
+ render_font_char chars[65536]; // array of characters
};
-/***************************************************************************
- INLINE FUNCTIONS
-***************************************************************************/
+//**************************************************************************
+// INLINE FUNCTIONS
+//**************************************************************************
-INLINE int pixel_is_set(bitmap_argb32 &bitmap, int y, int x)
+inline int pixel_is_set(bitmap_argb32 &bitmap, int y, int x)
{
return (bitmap.pix32(y, x) & 0xffffff) == 0;
}
-/***************************************************************************
- MAIN
-***************************************************************************/
+//**************************************************************************
+// MAIN
+//**************************************************************************
+
+//-------------------------------------------------
+// write_data - write data to the given file and
+// throw an exception if an error occurs
+//-------------------------------------------------
-static int render_font_save_cached(render_font *font, const char *filename, UINT32 hash)
+static void write_data(core_file &file, UINT8 *base, UINT8 *end)
{
- file_error filerr;
- render_font_char *ch;
- UINT32 bytes_written;
- UINT8 *tempbuffer;
- UINT8 *chartable;
- core_file *file;
- int numchars;
- UINT8 *dest;
- int tableindex;
- int chnum;
+ UINT32 bytes_written = core_fwrite(&file, base, end - base);
+ if (bytes_written != end - base)
+ {
+ fprintf(stderr, "Error writing to destination file\n");
+ throw;
+ }
+}
+
+
+//-------------------------------------------------
+// render_font_save_cached - write the cached
+// data out to the file
+//-------------------------------------------------
- /* attempt to open the file */
- filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
+static bool render_font_save_cached(render_font &font, const char *filename, UINT32 hash)
+{
+ // attempt to open the file
+ core_file *file;
+ file_error filerr = core_fopen(filename, OPEN_FLAG_WRITE | OPEN_FLAG_CREATE, &file);
if (filerr != FILERR_NONE)
- return 1;
+ return true;
- /* determine the number of characters */
- numchars = 0;
- for (chnum = 0; chnum < 65536; chnum++)
- if (font->chars[chnum].width > 0)
- numchars++;
-
- /* allocate an array to hold the character data */
- chartable = (UINT8 *)malloc(numchars * CACHED_CHAR_SIZE);
-
- /* allocate a temp buffer to compress into */
- tempbuffer = (UINT8 *)malloc(65536);
- if (chartable == NULL || tempbuffer == NULL)
- goto error;
-
- memset(chartable, 0, numchars * CACHED_CHAR_SIZE);
-
- /* write the header */
- dest = tempbuffer;
- *dest++ = 'f';
- *dest++ = 'o';
- *dest++ = 'n';
- *dest++ = 't';
- *dest++ = hash >> 24;
- *dest++ = hash >> 16;
- *dest++ = hash >> 8;
- *dest++ = hash & 0xff;
- *dest++ = font->height >> 8;
- *dest++ = font->height & 0xff;
- *dest++ = font->yoffs >> 8;
- *dest++ = font->yoffs & 0xff;
- *dest++ = numchars >> 24;
- *dest++ = numchars >> 16;
- *dest++ = numchars >> 8;
- *dest++ = numchars & 0xff;
- bytes_written = core_fwrite(file, tempbuffer, dest - tempbuffer);
- if (bytes_written != dest - tempbuffer)
- goto error;
-
- /* write the empty table to the beginning of the file */
- bytes_written = core_fwrite(file, chartable, numchars * CACHED_CHAR_SIZE);
- if (bytes_written != numchars * CACHED_CHAR_SIZE)
- goto error;
-
- /* loop over all characters */
- tableindex = 0;
- for (chnum = 0; chnum < 65536; chnum++)
+ try
{
- ch = &font->chars[chnum];
- if (ch->width > 0)
+ // determine the number of characters
+ int numchars = 0;
+ for (int chnum = 0; chnum < 65536; chnum++)
+ if (font.chars[chnum].width > 0)
+ numchars++;
+
+ // write the header
+ dynamic_buffer tempbuffer(65536);
+ UINT8 *dest = &tempbuffer[0];
+ *dest++ = 'f';
+ *dest++ = 'o';
+ *dest++ = 'n';
+ *dest++ = 't';
+ *dest++ = hash >> 24;
+ *dest++ = hash >> 16;
+ *dest++ = hash >> 8;
+ *dest++ = hash & 0xff;
+ *dest++ = font.height >> 8;
+ *dest++ = font.height & 0xff;
+ *dest++ = font.yoffs >> 8;
+ *dest++ = font.yoffs & 0xff;
+ *dest++ = numchars >> 24;
+ *dest++ = numchars >> 16;
+ *dest++ = numchars >> 8;
+ *dest++ = numchars & 0xff;
+ write_data(*file, tempbuffer, dest);
+
+ // write the empty table to the beginning of the file
+ dynamic_buffer chartable(numchars * CACHED_CHAR_SIZE + 1, 0);
+ write_data(*file, &chartable[0], &chartable[numchars * CACHED_CHAR_SIZE]);
+
+ // loop over all characters
+ int tableindex = 0;
+ for (int chnum = 0; chnum < 65536; chnum++)
{
- UINT8 accum, accbit;
- int x, y;
-
- /* write out a bit-compressed bitmap if we have one */
- if (ch->bitmap != NULL)
+ render_font_char &ch = font.chars[chnum];
+ if (ch.width > 0)
{
- /* write the data to the tempbuffer */
- dest = tempbuffer;
- accum = 0;
- accbit = 7;
-
- /* bit-encode the character data */
- for (y = 0; y < ch->bmheight; y++)
+ // write out a bit-compressed bitmap if we have one
+ if (ch.bitmap != NULL)
{
- int desty = y + font->height + font->yoffs - ch->yoffs - ch->bmheight;
- const UINT32 *src = (desty >= 0 && desty < font->height) ? &ch->bitmap->pix32(desty) : NULL;
- for (x = 0; x < ch->bmwidth; x++)
+ // write the data to the tempbuffer
+ dest = tempbuffer;
+ UINT8 accum = 0;
+ UINT8 accbit = 7;
+
+ // bit-encode the character data
+ for (int y = 0; y < ch.bmheight; y++)
{
- if (src != NULL && src[x] != 0)
- accum |= 1 << accbit;
- if (accbit-- == 0)
+ int desty = y + font.height + font.yoffs - ch.yoffs - ch.bmheight;
+ const UINT32 *src = (desty >= 0 && desty < font.height) ? &ch.bitmap->pix32(desty) : NULL;
+ for (int x = 0; x < ch.bmwidth; x++)
{
- *dest++ = accum;
- accum = 0;
- accbit = 7;
+ if (src != NULL && src[x] != 0)
+ accum |= 1 << accbit;
+ if (accbit-- == 0)
+ {
+ *dest++ = accum;
+ accum = 0;
+ accbit = 7;
+ }
}
}
- }
- /* flush any extra */
- if (accbit != 7)
- *dest++ = accum;
+ // flush any extra
+ if (accbit != 7)
+ *dest++ = accum;
- /* write the data */
- bytes_written = core_fwrite(file, tempbuffer, dest - tempbuffer);
- if (bytes_written != dest - tempbuffer)
- goto error;
+ // write the data
+ write_data(*file, tempbuffer, dest);
- /* free the bitmap and texture */
- delete ch->bitmap;
- ch->bitmap = NULL;
- }
+ // free the bitmap and texture
+ global_free(ch.bitmap);
+ ch.bitmap = NULL;
+ }
- /* compute the table entry */
- dest = &chartable[tableindex++ * CACHED_CHAR_SIZE];
- *dest++ = chnum >> 8;
- *dest++ = chnum & 0xff;
- *dest++ = ch->width >> 8;
- *dest++ = ch->width & 0xff;
- *dest++ = ch->xoffs >> 8;
- *dest++ = ch->xoffs & 0xff;
- *dest++ = ch->yoffs >> 8;
- *dest++ = ch->yoffs & 0xff;
- *dest++ = ch->bmwidth >> 8;
- *dest++ = ch->bmwidth & 0xff;
- *dest++ = ch->bmheight >> 8;
- *dest++ = ch->bmheight & 0xff;
+ // compute the table entry
+ dest = &chartable[tableindex++ * CACHED_CHAR_SIZE];
+ *dest++ = chnum >> 8;
+ *dest++ = chnum & 0xff;
+ *dest++ = ch.width >> 8;
+ *dest++ = ch.width & 0xff;
+ *dest++ = ch.xoffs >> 8;
+ *dest++ = ch.xoffs & 0xff;
+ *dest++ = ch.yoffs >> 8;
+ *dest++ = ch.yoffs & 0xff;
+ *dest++ = ch.bmwidth >> 8;
+ *dest++ = ch.bmwidth & 0xff;
+ *dest++ = ch.bmheight >> 8;
+ *dest++ = ch.bmheight & 0xff;
+ }
}
- }
- /* seek back to the beginning and rewrite the table */
- core_fseek(file, CACHED_HEADER_SIZE, SEEK_SET);
- bytes_written = core_fwrite(file, chartable, numchars * CACHED_CHAR_SIZE);
- if (bytes_written != numchars * CACHED_CHAR_SIZE)
- goto error;
-
- /* all done */
- core_fclose(file);
- free(tempbuffer);
- free(chartable);
- return 0;
-
-error:
- core_fclose(file);
- osd_rmfile(filename);
- free(tempbuffer);
- free(chartable);
- return 1;
+ // seek back to the beginning and rewrite the table
+ core_fseek(file, CACHED_HEADER_SIZE, SEEK_SET);
+ write_data(*file, &chartable[0], &chartable[numchars * CACHED_CHAR_SIZE]);
+
+ // all done
+ core_fclose(file);
+ return false;
+ }
+ catch (...)
+ {
+ core_fclose(file);
+ osd_rmfile(filename);
+ return true;
+ }
}
-/*-------------------------------------------------
- bitmap_to_chars - convert a bitmap to
- characters in the given font
--------------------------------------------------*/
+//-------------------------------------------------
+// bitmap_to_chars - convert a bitmap to
+// characters in the given font
+//-------------------------------------------------
-static int bitmap_to_chars(bitmap_argb32 &bitmap, render_font *font)
+static bool bitmap_to_chars(bitmap_argb32 &bitmap, render_font &font)
{
+ // loop over rows
int rowstart = 0;
- int x, y;
-
- /* loop over rows */
while (rowstart < bitmap.height())
{
- int rowend, baseline, colstart;
- int chstart;
-
- /* find the top of the row */
+ // find the top of the row
for ( ; rowstart < bitmap.height(); rowstart++)
if (pixel_is_set(bitmap, rowstart, 0))
break;
if (rowstart >= bitmap.height())
break;
- /* find the bottom of the row */
+ // find the bottom of the row
+ int rowend;
for (rowend = rowstart + 1; rowend < bitmap.height(); rowend++)
if (!pixel_is_set(bitmap, rowend, 0))
{
@@ -282,7 +273,8 @@ static int bitmap_to_chars(bitmap_argb32 &bitmap, render_font *font)
break;
}
- /* find the baseline */
+ // find the baseline
+ int baseline;
for (baseline = rowstart; baseline <= rowend; baseline++)
if (pixel_is_set(bitmap, baseline, 1))
break;
@@ -292,50 +284,50 @@ static int bitmap_to_chars(bitmap_argb32 &bitmap, render_font *font)
break;
}
- /* set or confirm the height */
- if (font->height == 0)
+ // set or confirm the height
+ if (font.height == 0)
{
- font->height = rowend - rowstart + 1;
- font->yoffs = baseline - rowend;
+ font.height = rowend - rowstart + 1;
+ font.yoffs = baseline - rowend;
}
else
{
- if (font->height != rowend - rowstart + 1)
+ if (font.height != rowend - rowstart + 1)
{
fprintf(stderr, "Inconsistent font height at rows %d-%d\n", rowstart, rowend);
break;
}
- if (font->yoffs != baseline - rowend)
+ if (font.yoffs != baseline - rowend)
{
fprintf(stderr, "Inconsistent baseline at rows %d-%d\n", rowstart, rowend);
break;
}
}
- /* decode the starting character */
- chstart = 0;
- for (x = 0; x < 4; x++)
- for (y = 0; y < 4; y++)
+ // decode the starting character
+ int chstart = 0;
+ for (int x = 0; x < 4; x++)
+ for (int y = 0; y < 4; y++)
chstart = (chstart << 1) | pixel_is_set(bitmap, rowstart + y, 2 + x);
- /* print info */
+ // print info
// printf("Row %d-%d, baseline %d, character start %X\n", rowstart, rowend, baseline, chstart);
- /* scan the column to find characters */
- colstart = 0;
+ // scan the column to find characters
+ int colstart = 0;
while (colstart < bitmap.width())
{
- render_font_char *ch = &font->chars[chstart];
- int colend;
+ render_font_char &ch = font.chars[chstart];
- /* find the start of the character */
+ // find the start of the character
for ( ; colstart < bitmap.width(); colstart++)
if (pixel_is_set(bitmap, rowend + 2, colstart))
break;
if (colstart >= bitmap.width())
break;
- /* find the end of the character */
+ // find the end of the character
+ int colend;
for (colend = colstart + 1; colend < bitmap.width(); colend++)
if (!pixel_is_set(bitmap, rowend + 2, colend))
{
@@ -344,82 +336,68 @@ static int bitmap_to_chars(bitmap_argb32 &bitmap, render_font *font)
}
// skip char which code is already registered
- if (ch->width <= 0)
+ if (ch.width <= 0)
{
- /* print info */
+ // print info
// printf(" Character %X - width = %d\n", chstart, colend - colstart + 1);
- /* allocate a bitmap */
- ch->bitmap = new(std::nothrow) bitmap_argb32(colend - colstart + 1, font->height);
- if (ch->bitmap == NULL)
- {
- fprintf(stderr, "Error allocating character bitmap (%dx%d)\n", colend - colstart + 1, font->height);
- continue;
- }
+ // allocate a bitmap
+ ch.bitmap = global_alloc(bitmap_argb32(colend - colstart + 1, font.height));
+
+ // plot the character
+ for (int y = rowstart; y <= rowend; y++)
+ for (int x = colstart; x <= colend; x++)
+ ch.bitmap->pix32(y - rowstart, x - colstart) = pixel_is_set(bitmap, y, x) ? 0xffffffff : 0x00000000;
- /* plot the character */
- for (y = rowstart; y <= rowend; y++)
- for (x = colstart; x <= colend; x++)
- ch->bitmap->pix32(y - rowstart, x - colstart) = pixel_is_set(bitmap, y, x) ? 0xffffffff : 0x00000000;
-
- /* set the character parameters */
- ch->width = colend - colstart + 1;
- ch->xoffs = 0;
- ch->yoffs = font->yoffs;
- ch->bmwidth = ch->bitmap->width();
- ch->bmheight = ch->bitmap->height();
+ // set the character parameters
+ ch.width = colend - colstart + 1;
+ ch.xoffs = 0;
+ ch.yoffs = font.yoffs;
+ ch.bmwidth = ch.bitmap->width();
+ ch.bmheight = ch.bitmap->height();
}
- /* next character */
+ // next character
chstart++;
colstart = colend + 1;
}
- /* next row */
+ // next row
rowstart = rowend + 1;
}
- /* return non-zero (TRUE) if we errored */
+ // return non-zero (TRUE) if we errored
return (rowstart < bitmap.height());
}
-/*-------------------------------------------------
- main - main entry point
--------------------------------------------------*/
+//-------------------------------------------------
+// main - main entry point
+//-------------------------------------------------
int main(int argc, char *argv[])
{
- const char *bdcname;
- render_font *font;
- int error = FALSE;
- int curarg;
-
- /* validate arguments */
+ // validate arguments
if (argc < 3)
{
fprintf(stderr, "Usage:\n%s <input.png> [<input2.png> [...]] <output.bdc>\n", argv[0]);
return 1;
}
- bdcname = argv[argc - 1];
-
- /* allocate a font */
- font = (render_font *)malloc(sizeof(*font));
- if (font == NULL)
- return 1;
- memset(font, 0, sizeof(*font));
+ const char *bdcname = argv[argc - 1];
- /* iterate over input files */
- for (curarg = 1; curarg < argc - 1; curarg++)
+ // iterate over input files
+ static render_font font;
+ bool error = false;
+ for (int curarg = 1; curarg < argc - 1; curarg++)
{
- /* load the png file */
+ // load the png file
const char *pngname = argv[curarg];
core_file *file;
file_error filerr = core_fopen(pngname, OPEN_FLAG_READ, &file);
if (filerr != FILERR_NONE)
{
fprintf(stderr, "Error %d attempting to open PNG file\n", filerr);
- error = TRUE;
+ error = true;
break;
}
@@ -429,21 +407,20 @@ int main(int argc, char *argv[])
if (pngerr != PNGERR_NONE)
{
fprintf(stderr, "Error %d reading PNG file\n", pngerr);
- error = TRUE;
+ error = true;
break;
}
- /* parse the PNG into characters */
+ // parse the PNG into characters
error = bitmap_to_chars(bitmap, font);
if (error)
break;
}
- /* write out the resulting font */
+ // write out the resulting font
if (!error)
- render_font_save_cached(font, bdcname, 0);
+ error = render_font_save_cached(font, bdcname, 0);
- /* cleanup after ourselves */
- free(font);
- return error;
+ // cleanup after ourselves
+ return error ? 1 : 0;
}