summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools/imgtool/modules/thomson.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/imgtool/modules/thomson.cpp')
-rw-r--r--src/tools/imgtool/modules/thomson.cpp249
1 files changed, 127 insertions, 122 deletions
diff --git a/src/tools/imgtool/modules/thomson.cpp b/src/tools/imgtool/modules/thomson.cpp
index f122bc00520..1978e3720ba 100644
--- a/src/tools/imgtool/modules/thomson.cpp
+++ b/src/tools/imgtool/modules/thomson.cpp
@@ -112,10 +112,15 @@
*/
#include "imgtool.h"
+#include "filter.h"
#include "iflopimg.h"
-#include "formats/imageutl.h"
-#include <time.h>
+#include "corestr.h"
+#include "multibyte.h"
+#include "opresolv.h"
+
+#include <cstdio>
+#include <ctime>
#define MAXSIZE 80*16*256*2 /* room for two faces, double-density, 80 tracks */
@@ -590,14 +595,14 @@ static int thom_find_dirent(thom_floppy* f, unsigned head,
{
int n = 0;
while ( 1 ) {
- thom_get_dirent( f, head, n, d );
- if ( d->type == THOM_DIRENT_END ) return 0;
- if ( d->type == THOM_DIRENT_FILE ) {
- char buf[13];
- sprintf( buf, "%s.%s", d->name, d->ext );
- if ( ! strcmp( buf, name ) ) return 1;
- }
- n++;
+ thom_get_dirent( f, head, n, d );
+ if ( d->type == THOM_DIRENT_END ) return 0;
+ if ( d->type == THOM_DIRENT_FILE ) {
+ char buf[13];
+ snprintf( buf, std::size(buf), "%s.%s", d->name, d->ext );
+ if ( ! strcmp( buf, name ) ) return 1;
+ }
+ n++;
}
}
@@ -952,7 +957,7 @@ static imgtoolerr_t thom_read_file(imgtool::partition &part,
/* convert filename */
thom_conv_filename( filename, name, ext );
- sprintf( fname, "%s.%s", name, ext );
+ snprintf( fname, std::size(fname), "%s.%s", name, ext );
if ( ! thom_find_dirent( f, head, fname, &d ) )
return IMGTOOLERR_FILENOTFOUND;
@@ -973,7 +978,7 @@ static imgtoolerr_t thom_delete_file(imgtool::partition &part,
/* convert filename */
thom_conv_filename( filename, name, ext );
- sprintf( fname, "%s.%s", name, ext );
+ snprintf( fname, std::size(fname), "%s.%s", name, ext );
if ( ! thom_find_dirent( f, head, fname, &d ) )
return IMGTOOLERR_FILENOTFOUND;
@@ -1002,7 +1007,7 @@ static imgtoolerr_t thom_write_file(imgtool::partition &part,
/* convert filename */
thom_conv_filename( filename, name, ext );
- sprintf( fname, "%s.%s", name, ext );
+ snprintf( fname, std::size(fname), "%s.%s", name, ext );
/* check available space & find dir entry */
if ( thom_find_dirent( f, head, fname, &d ) ) {
@@ -1067,10 +1072,11 @@ static imgtoolerr_t thom_write_file(imgtool::partition &part,
return IMGTOOLERR_SUCCESS;
}
-static imgtoolerr_t thom_suggest_transfer(imgtool::partition &part,
- const char *fname,
- imgtool_transfer_suggestion *suggestions,
- size_t suggestions_length)
+static imgtoolerr_t thom_suggest_transfer(
+ imgtool::partition &part,
+ const char *fname,
+ imgtool::transfer_suggestion *suggestions,
+ size_t suggestions_length)
{
int head = *( (int*) part.extra_bytes() );
imgtool::image &img(part.image());
@@ -1081,30 +1087,30 @@ static imgtoolerr_t thom_suggest_transfer(imgtool::partition &part,
if ( suggestions_length < 1 ) return IMGTOOLERR_SUCCESS;
if ( fname ) {
- if ( ! thom_find_dirent( f, head, fname, &d ) )
- return IMGTOOLERR_FILENOTFOUND;
- if ( d.ftype == 0 && d.format == 0 ) is_basic = 1;
+ if ( ! thom_find_dirent( f, head, fname, &d ) )
+ return IMGTOOLERR_FILENOTFOUND;
+ if ( d.ftype == 0 && d.format == 0 ) is_basic = 1;
}
if ( is_basic ) {
- suggestions[0].viability = SUGGESTION_RECOMMENDED;
- suggestions[0].filter = filter_thombas128_getinfo;
- if ( suggestions_length >= 2 ) {
- suggestions[1].viability = SUGGESTION_POSSIBLE;
- suggestions[1].filter = filter_thombas7_getinfo;
- }
- if ( suggestions_length >= 3 ) {
- suggestions[2].viability = SUGGESTION_POSSIBLE;
- suggestions[2].filter = filter_thombas5_getinfo;
- }
- if ( suggestions_length >= 4 ) {
- suggestions[3].viability = SUGGESTION_POSSIBLE;
- suggestions[3].filter = NULL;
- }
+ suggestions[0].viability = imgtool::SUGGESTION_RECOMMENDED;
+ suggestions[0].filter = filter_thombas128_getinfo;
+ if ( suggestions_length >= 2 ) {
+ suggestions[1].viability = imgtool::SUGGESTION_POSSIBLE;
+ suggestions[1].filter = filter_thombas7_getinfo;
+ }
+ if ( suggestions_length >= 3 ) {
+ suggestions[2].viability = imgtool::SUGGESTION_POSSIBLE;
+ suggestions[2].filter = filter_thombas5_getinfo;
+ }
+ if ( suggestions_length >= 4 ) {
+ suggestions[3].viability = imgtool::SUGGESTION_POSSIBLE;
+ suggestions[3].filter = nullptr;
+ }
}
else {
- suggestions[0].viability = SUGGESTION_RECOMMENDED;
- suggestions[0].filter = NULL;
+ suggestions[0].viability = imgtool::SUGGESTION_RECOMMENDED;
+ suggestions[0].filter = nullptr;
}
return IMGTOOLERR_SUCCESS;
@@ -1206,12 +1212,12 @@ static const char *const thombas7[2][128] = {
/* MO5: some keywords ar missing; DOS and TUNE are added */
static const char *const thombas5[2][128] = {
{ /* statements */
- "END", "FOR", "NEXT", "DATA", "DIM", "READ", NULL, "GO", "RUN", "IF",
+ "END", "FOR", "NEXT", "DATA", "DIM", "READ", nullptr, "GO", "RUN", "IF",
"RESTORE", "RETURN", "REM", "'", "STOP", "ELSE", "TRON", "TROFF", "DEFSTR",
- "DEFINT", "DEFSNG", NULL, "ON", "TUNE", "ERROR", "RESUME", "AUTO",
+ "DEFINT", "DEFSNG", nullptr, "ON", "TUNE", "ERROR", "RESUME", "AUTO",
"DELETE", "LOCATE", "CLS", "CONSOLE", "PSET", "MOTOR", "SKIP", "EXEC",
- "BEEP", "COLOR", "LINE", "BOX", NULL, "ATTRB", "DEF", "POKE", "PRINT",
- "CONT", "LIST", "CLEAR", "DOS", NULL, "NEW", "SAVE", "LOAD", "MERGE",
+ "BEEP", "COLOR", "LINE", "BOX", nullptr, "ATTRB", "DEF", "POKE", "PRINT",
+ "CONT", "LIST", "CLEAR", "DOS", nullptr, "NEW", "SAVE", "LOAD", "MERGE",
"OPEN", "CLOSE", "INPEN", "PEN", "PLAY", "TAB(", "TO", "SUB", "FN",
"SPC(", "USING", "USR", "ERL", "ERR", "OFF", "THEN", "NOT", "STEP",
"+", "-", "*", "/", "^", "AND", "OR", "XOR", "EQV", "IMP", "MOD", "@",
@@ -1224,8 +1230,8 @@ static const char *const thombas5[2][128] = {
},
{ /* functions: 0xff prefix */
"SGN", "INT", "ABS", "FRE", "SQR", "LOG", "EXP", "COS", "SIN",
- "TAN", "PEEK", "LEN", "STR$", "VAL", "ASC", "CHR$", "EOF", "CINT", NULL,
- NULL, "FIX", "HEX$", NULL, "STICK", "STRIG", "GR$", "LEFT$", "RIGHT$",
+ "TAN", "PEEK", "LEN", "STR$", "VAL", "ASC", "CHR$", "EOF", "CINT", nullptr,
+ nullptr, "FIX", "HEX$", nullptr, "STICK", "STRIG", "GR$", "LEFT$", "RIGHT$",
"MID$", "INSTR", "VARPTR", "RND", "INKEY$", "INPUT", "CSRLIN", "POINT",
"SCREEN", "POS", "PTRIG",
/* DOS specific */
@@ -1368,7 +1374,7 @@ static imgtoolerr_t thomcrypt_write_file(imgtool::partition &part,
}
}
-void filter_thomcrypt_getinfo(uint32_t state, union filterinfo *info)
+void filter_thomcrypt_getinfo(uint32_t state, imgtool::filterinfo *info)
{
switch(state) {
case FILTINFO_STR_NAME:
@@ -1596,16 +1602,14 @@ struct {
{ "\xc3\xa7", "\x16" "Kc" },
{ "\xc3\x87", "\x16" "KC" },
- { NULL, NULL }
+ { nullptr, nullptr }
};
static bool thom_basic_is_specialchar(const char *buf,
int *pos,
const char **thom)
{
- int i;
-
- for (i = 0; special_chars[i].utf8 != NULL; i++)
+ for (int i = 0; special_chars[i].utf8 != nullptr; i++)
{
if (!strncmp(&buf[*pos], special_chars[i].utf8, strlen(special_chars[i].utf8)))
{
@@ -1740,7 +1744,7 @@ static imgtoolerr_t thom_basic_write_file(imgtool::partition &partition,
if ((c == '\r') || (c == '\n'))
break;
- if (pos <= ARRAY_LENGTH(buf) - 1)
+ if (pos <= std::size(buf) - 1)
{
buf[pos++] = c;
}
@@ -1765,8 +1769,8 @@ static imgtoolerr_t thom_basic_write_file(imgtool::partition &partition,
/* set up line header */
memset(&line_header, 0, sizeof(line_header));
/* linelength or offset (2-bytes) will be rewritten */
- place_integer_be(line_header, 0, 2, 0xffff);
- place_integer_be(line_header, 2, 2, line_number);
+ put_u16be(&line_header[0], 0xffff);
+ put_u16be(&line_header[2], line_number);
/* emit line header */
line_header_loc = mem_stream->tell();
@@ -1841,7 +1845,7 @@ static imgtoolerr_t thom_basic_write_file(imgtool::partition &partition,
/* rewrite the line length */
end_line_loc = mem_stream->tell();
mem_stream->seek(line_header_loc, SEEK_SET);
- place_integer_be(line_header, 0, 2, end_line_loc - line_header_loc);
+ put_u16be(&line_header[0], end_line_loc - line_header_loc);
mem_stream->write(line_header, sizeof(line_header));
mem_stream->seek(end_line_loc, SEEK_SET);
}
@@ -1854,8 +1858,8 @@ static imgtoolerr_t thom_basic_write_file(imgtool::partition &partition,
mem_stream->seek(0, SEEK_SET);
/* Write file header */
- place_integer_be(file_header, 0, 1, 0xFF);
- place_integer_be(file_header, 1, 2, mem_stream->size());
+ file_header[0] = 0xFF;
+ put_u16be(&file_header[1], mem_stream->size());
mem_stream->write(file_header, 3);
mem_stream->seek(0, SEEK_SET);
@@ -1870,32 +1874,33 @@ static imgtoolerr_t thom_basic_write_file(imgtool::partition &partition,
const char *fork, \
imgtool::stream &dst) \
{ \
- return thom_basic_read_file( part, name, fork, dst, short ); \
+ return thom_basic_read_file( part, name, fork, dst, short ); \
} \
- static imgtoolerr_t short##_write_file(imgtool::partition &part, \
- const char *name, \
- const char *fork, \
- imgtool::stream &src, \
- util::option_resolution *opts) \
+ static imgtoolerr_t short##_write_file( \
+ imgtool::partition &part, \
+ const char *name, \
+ const char *fork, \
+ imgtool::stream &src, \
+ util::option_resolution *opts) \
{ \
- return thom_basic_write_file( part, name, fork, src, opts, short ); \
+ return thom_basic_write_file( part, name, fork, src, opts, short ); \
} \
- void filter_##short##_getinfo(uint32_t state, union filterinfo *info) \
+ void filter_##short##_getinfo(uint32_t state, imgtool::filterinfo *info) \
{ \
switch(state) \
{ \
case FILTINFO_STR_NAME: \
- info->s = #short; \
- break; \
+ info->s = #short; \
+ break; \
case FILTINFO_STR_HUMANNAME: \
- info->s = long; \
- break; \
+ info->s = long; \
+ break; \
case FILTINFO_PTR_READFILE: \
- info->read_file = short##_read_file; \
- break; \
+ info->read_file = short##_read_file; \
+ break; \
case FILTINFO_PTR_WRITEFILE: \
- info->write_file = short##_write_file; \
- break; \
+ info->write_file = short##_write_file; \
+ break; \
} \
}
@@ -1941,57 +1946,57 @@ static void thom_basic_get_info(const imgtool_class *clas,
{
switch ( param ) {
case IMGTOOLINFO_INT_IMAGE_EXTRA_BYTES:
- info->i = sizeof(thom_floppy); break;
+ info->i = sizeof(thom_floppy); break;
case IMGTOOLINFO_INT_PARTITION_EXTRA_BYTES:
- info->i = sizeof(int); break;
+ info->i = sizeof(int); break;
case IMGTOOLINFO_INT_DIRECTORY_EXTRA_BYTES:
- info->i = sizeof(int); break;
+ info->i = sizeof(int); break;
case IMGTOOLINFO_INT_SUPPORTS_CREATION_TIME:
case IMGTOOLINFO_INT_PREFER_UCASE:
- info->i = 1; break;
+ info->i = 1; break;
case IMGTOOLINFO_INT_PATH_SEPARATOR:
- info->i = 0; break;
+ info->i = 0; break;
case IMGTOOLINFO_STR_FILE:
- strcpy( info->s = imgtool_temp_str(), __FILE__ ); break;
+ strcpy( info->s = imgtool_temp_str(), __FILE__ ); break;
case IMGTOOLINFO_STR_NAME:
- strcpy( info->s = imgtool_temp_str(), "thom" ); break;
+ strcpy( info->s = imgtool_temp_str(), "thom" ); break;
case IMGTOOLINFO_STR_DESCRIPTION:
- strcpy( info->s = imgtool_temp_str(), "Thomson BASIC filesystem" );
- break;
+ strcpy( info->s = imgtool_temp_str(), "Thomson BASIC filesystem" );
+ break;
case IMGTOOLINFO_PTR_CREATE:
- info->create = thom_create; break;
+ info->create = thom_create; break;
case IMGTOOLINFO_PTR_CREATEIMAGE_OPTGUIDE:
- info->createimage_optguide = &thom_createimage_optguide; break;
+ info->createimage_optguide = &thom_createimage_optguide; break;
case IMGTOOLINFO_PTR_BEGIN_ENUM:
- info->begin_enum = thom_begin_enum; break;
+ info->begin_enum = thom_begin_enum; break;
case IMGTOOLINFO_PTR_NEXT_ENUM:
- info->next_enum = thom_next_enum; break;
+ info->next_enum = thom_next_enum; break;
case IMGTOOLINFO_PTR_READ_FILE:
- info->read_file = thom_read_file; break;
+ info->read_file = thom_read_file; break;
case IMGTOOLINFO_PTR_WRITE_FILE:
- info->write_file = thom_write_file; break;
+ info->write_file = thom_write_file; break;
case IMGTOOLINFO_PTR_WRITEFILE_OPTGUIDE:
- info->writefile_optguide = &thom_writefile_optguide; break;
+ info->writefile_optguide = &thom_writefile_optguide; break;
case IMGTOOLINFO_STR_WRITEFILE_OPTSPEC:
- strcpy( info->s = imgtool_temp_str(), "T[0]-4;F[0]-2;C" ); break;
+ strcpy( info->s = imgtool_temp_str(), "T[0]-4;F[0]-2;C" ); break;
case IMGTOOLINFO_PTR_SUGGEST_TRANSFER:
- info->suggest_transfer = thom_suggest_transfer; break;
+ info->suggest_transfer = thom_suggest_transfer; break;
case IMGTOOLINFO_PTR_DELETE_FILE:
- info->delete_file = thom_delete_file; break;
+ info->delete_file = thom_delete_file; break;
case IMGTOOLINFO_PTR_FREE_SPACE:
- info->free_space = thom_free_space; break;
+ info->free_space = thom_free_space; break;
case IMGTOOLINFO_PTR_GET_GEOMETRY:
- info->get_geometry = thom_get_geometry; break;
+ info->get_geometry = thom_get_geometry; break;
case IMGTOOLINFO_PTR_INFO:
- info->info = thom_info; break;
+ info->info = thom_info; break;
case IMGTOOLINFO_PTR_READ_SECTOR:
- info->read_sector = thom_read_sector; break;
+ info->read_sector = thom_read_sector; break;
case IMGTOOLINFO_PTR_WRITE_SECTOR:
- info->write_sector = thom_write_sector; break;
+ info->write_sector = thom_write_sector; break;
case IMGTOOLINFO_PTR_LIST_PARTITIONS:
- info->list_partitions = thom_list_partitions; break;
+ info->list_partitions = thom_list_partitions; break;
case IMGTOOLINFO_PTR_OPEN_PARTITION:
- info->open_partition = thom_open_partition; break;
+ info->open_partition = thom_open_partition; break;
}
}
@@ -2001,21 +2006,21 @@ void thom_fd_basic_get_info(const imgtool_class *clas,
{
switch ( param ) {
case IMGTOOLINFO_STR_NAME:
- strcpy( info->s = imgtool_temp_str(), "thom_fd" ); break;
+ strcpy( info->s = imgtool_temp_str(), "thom_fd" ); break;
case IMGTOOLINFO_STR_DESCRIPTION:
- strcpy( info->s = imgtool_temp_str(),
- "Thomson .fd disk image, BASIC format" );
- break;
+ strcpy( info->s = imgtool_temp_str(),
+ "Thomson .fd disk image, BASIC format" );
+ break;
case IMGTOOLINFO_STR_FILE_EXTENSIONS:
- strcpy( info->s = imgtool_temp_str(), "fd" ); break;
+ strcpy( info->s = imgtool_temp_str(), "fd" ); break;
case IMGTOOLINFO_PTR_OPEN:
- info->open = thom_open_fd_qd; break;
+ info->open = thom_open_fd_qd; break;
case IMGTOOLINFO_PTR_CLOSE:
- info->close = thom_close_fd_qd; break;
+ info->close = thom_close_fd_qd; break;
case IMGTOOLINFO_STR_CREATEIMAGE_OPTSPEC:
- strcpy( info->s = imgtool_temp_str(), "H[1]-2;T40/[80];D0-[1];N" ); break;
+ strcpy( info->s = imgtool_temp_str(), "H[1]-2;T40/[80];D0-[1];N" ); break;
default:
- thom_basic_get_info( clas, param, info );
+ thom_basic_get_info( clas, param, info );
}
}
@@ -2025,21 +2030,21 @@ void thom_qd_basic_get_info(const imgtool_class *clas,
{
switch ( param ) {
case IMGTOOLINFO_STR_NAME:
- strcpy( info->s = imgtool_temp_str(), "thom_qd" ); break;
+ strcpy( info->s = imgtool_temp_str(), "thom_qd" ); break;
case IMGTOOLINFO_STR_DESCRIPTION:
- strcpy( info->s = imgtool_temp_str(),
- "Thomson .qd disk image, BASIC format" );
- break;
+ strcpy( info->s = imgtool_temp_str(),
+ "Thomson .qd disk image, BASIC format" );
+ break;
case IMGTOOLINFO_STR_FILE_EXTENSIONS:
- strcpy( info->s = imgtool_temp_str(), "qd" ); break;
+ strcpy( info->s = imgtool_temp_str(), "qd" ); break;
case IMGTOOLINFO_PTR_OPEN:
- info->open = thom_open_fd_qd; break;
+ info->open = thom_open_fd_qd; break;
case IMGTOOLINFO_PTR_CLOSE:
- info->close = thom_close_fd_qd; break;
+ info->close = thom_close_fd_qd; break;
case IMGTOOLINFO_STR_CREATEIMAGE_OPTSPEC:
- strcpy( info->s = imgtool_temp_str(), "H[1]-2;T[25];D[0];N" ); break;
+ strcpy( info->s = imgtool_temp_str(), "H[1]-2;T[25];D[0];N" ); break;
default:
- thom_basic_get_info( clas, param, info );
+ thom_basic_get_info( clas, param, info );
}
}
@@ -2049,20 +2054,20 @@ void thom_sap_basic_get_info(const imgtool_class *clas,
{
switch ( param ) {
case IMGTOOLINFO_STR_NAME:
- strcpy( info->s = imgtool_temp_str(), "thom_sap" ); break;
+ strcpy( info->s = imgtool_temp_str(), "thom_sap" ); break;
case IMGTOOLINFO_STR_DESCRIPTION:
- strcpy( info->s = imgtool_temp_str(),
- "Thomson .sap disk image, BASIC format" );
- break;
+ strcpy( info->s = imgtool_temp_str(),
+ "Thomson .sap disk image, BASIC format" );
+ break;
case IMGTOOLINFO_STR_FILE_EXTENSIONS:
- strcpy( info->s = imgtool_temp_str(), "sap" ); break;
+ strcpy( info->s = imgtool_temp_str(), "sap" ); break;
case IMGTOOLINFO_PTR_OPEN:
- info->open = thom_open_sap; break;
+ info->open = thom_open_sap; break;
case IMGTOOLINFO_PTR_CLOSE:
- info->close = thom_close_sap; break;
+ info->close = thom_close_sap; break;
case IMGTOOLINFO_STR_CREATEIMAGE_OPTSPEC:
- strcpy( info->s = imgtool_temp_str(), "H[1];T40/[80];D0-[1];N" ); break;
+ strcpy( info->s = imgtool_temp_str(), "H[1];T40/[80];D0-[1];N" ); break;
default:
- thom_basic_get_info( clas, param, info );
+ thom_basic_get_info( clas, param, info );
}
}