cake
/
libg1m
Archived
1
0
Fork 0

Corrected add-in encoding (size_t filesize = 0).

This commit is contained in:
Thomas Touhey 2017-03-27 19:37:24 +02:00
parent da972cbc73
commit 168d3b1e09
5 changed files with 46 additions and 51 deletions

View File

@ -138,13 +138,13 @@ struct _cas100 {
/* driver number, in ASCII (0x30 + <num>) */
uint8_t id;
/* ExportDrive: 0x00000400, size? */
/* ExportDrive: 0x400, size? */
uint32_t _size;
/* ExportDrive: 128, type? */
/* ExportDrive: 0x80, type? */
uint32_t _type;
/* ExportDrive: 0x00020000, other size? */
/* ExportDrive: 0x20000, other size? */
uint32_t _othersize;
/* 0xFFs */

View File

@ -84,7 +84,7 @@
# endif
/* Log memory (behind the `logm_*` macros) */
extern void g1m_log_mem(const char *prefix, void *m, size_t n);
extern void g1m_log_mem(const char *prefix, const void *m, size_t n);
/* Type strings */
extern const char *g1m_get_type_string(int main_id, int type);

View File

@ -42,14 +42,14 @@ static void putascii(unsigned char *p, unsigned int i, int n)
{
/* goto end of the field */
p += (n - 1);
/* for each digit */
while (n--) {
/* get end digit from this point */
int j = i % 16;
/* put it in ASCII-hex */
/* get end digit from this point, put in ASCII-hex */
div_t dv = div(i, 16);
int j = dv.rem;
*p-- = j >= 10 ? j - 10 + 'A' : j + '0';
/* then go to digit that's left */
i /= 16;
/* go to the digit to the left */
i = dv.quot;
}
}
@ -62,19 +62,21 @@ static void putascii(unsigned char *p, unsigned int i, int n)
* @arg n the size of the memory zone
*/
static void log_mem_hex(char *s, unsigned char *m, size_t n)
static void log_mem_hex(char *s, const unsigned char *m, size_t n)
{
size_t l = 0;
while (l < 16) {
/* put the hex number */
if (n) putascii((unsigned char*)s, *m++, 2), s += 2;
else *s++ = ' ', *s++ = ' ';
for (size_t l = 0; l < 8; l++) {
/* put the first hex number */
if (n) putascii((unsigned char*)s, *m++, 2);
else { *s++ = ' '; *s-- = ' '; }
s += 2; n -= !!n;
/* decrement size of the memory zone to go */
n -= !!n;
/* put the second hex number */
if (n) putascii((unsigned char*)s, *m++, 2);
else { *s++ = ' '; *s-- = ' '; }
s += 2; n -= !!n;
/* go to next character if s is at the ending of a group */
if (l++ % 2) s++;
/* put a space */
*s++ = ' ';
}
}
@ -87,17 +89,12 @@ static void log_mem_hex(char *s, unsigned char *m, size_t n)
* @arg n the size of the memory zone
*/
static void log_mem_asc(char *s, unsigned char *m, size_t n)
static void log_mem_asc(char *s, const unsigned char *m, size_t n)
{
size_t l = 0;
/* for each byte */
while (n-- && l++ < 16) {
/* put the character (or a dot if non printable) */
if (isprint(*m++)) *s++ = *((char*)m - 1);
else *s++ = '.';
}
/* put the line ending */
*s++ = '\n', *s = '\0';
for (n = min(n, 16); n; n--, m++)
*s++ = isprint(*m) ? *m : '.';
*s++ = '\n';
*s = '\0';
}
/**
@ -109,7 +106,7 @@ static void log_mem_asc(char *s, unsigned char *m, size_t n)
* @arg n the size of the memory zone
*/
void g1m_log_mem(const char *prefx, void *m, size_t n)
void g1m_log_mem(const char *prefx, const void *m, size_t n)
{
/* if nothing, print it directly */
if (!n) fprintf(stderr, "%s(nothing)\n", prefx);
@ -122,16 +119,12 @@ void g1m_log_mem(const char *prefx, void *m, size_t n)
memcpy(&linebuf[lineoff], "0000 0000 0000 0000 0000 0000 0000 0000 ", 40);
/* then loop-loop-loop-loop-loop */
unsigned char *p = m;
while (n > 0) {
/* fill in ascii-hex part */
for (const unsigned char *p = m; n > 0; p += 16, n -= min(16, n)) {
/* prepare the parts */
log_mem_hex(&linebuf[lineoff], p, n);
/* fill in ascii part */
log_mem_asc(&linebuf[lineoff + 40], p, n);
/* then print line */
/* put the line */
fputs(linebuf, stderr);
/* and increment pointer */
p += 16;
n -= min(16, n);
}
}

View File

@ -48,7 +48,7 @@ int g1m_encode_addin(g1m_handle_t *handle, g1m_buffer_t *buffer)
size_t i; uint8_t *b;
/* make the StandardHeader up */
size_t filesize; g1m_announce_addin(handle, &filesize);
size_t filesize = 0; g1m_announce_addin(handle, &filesize);
struct standard_header std = {
.main_id = "USBPower",
.subtype = "\xF3\x00\x10\x00\x10\x00",

View File

@ -194,29 +194,31 @@ int g1m_make_addin(g1m_handle_t **h, g1m_platform_t platform, size_t size,
/* check the platform */
unsigned int width, height;
int titlesize = 8;
int titlesize = 8, intsize = 8;
switch (platform) {
case g1m_platform_fx:
width = G1A_ICON_WIDTH;
height = G1A_ICON_HEIGHT;
width = G1A_ICON_WIDTH; height = G1A_ICON_HEIGHT;
break;
case g1m_platform_cp:
width = C1A_ICON_WIDTH;
height = C1A_ICON_HEIGHT;
titlesize = 16;
break;
width = C1A_ICON_WIDTH; height = C1A_ICON_HEIGHT;
titlesize = 16; break;
default: /* case g1m_platform_cg: */
width = G3A_ICON_WIDTH;
height = G3A_ICON_HEIGHT;
titlesize = 16;
titlesize = 16; break;
}
/* copy the name and internal name */
int i; for (i = 0; isupper(name[i]) && i < titlesize; i++)
/* copy the addin title */
int i; for (i = 0; (isupper(name[i]) || isdigit(name[i]))
&& i < titlesize; i++)
handle->title[i] = name[i];
handle->title[i] = 0;
if (!handle->title[0]) strcpy(handle->title, "@ADDIN");
/* copy the internal name */
handle->intname[0] = '@';
for (i = 1; isupper(internal[i]) && i < 8; i++)
for (i = 1; (isupper(internal[i]) || isdigit(internal[i]))
&& i < intsize; i++)
handle->intname[i] = internal[i];
handle->intname[i] = 0;