FreeCalypso > hg > freecalypso-hwlab
changeset 120:70219d92c32e
fc-simtool: pb-update-imm-hex command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Jan 2021 04:46:41 +0000 |
parents | c77b0d4cf89f |
children | 87b34a244901 |
files | simtool/dispatch.c simtool/pbupdate.c |
diffstat | 2 files changed, 57 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/simtool/dispatch.c Thu Jan 28 04:19:52 2021 +0000 +++ b/simtool/dispatch.c Thu Jan 28 04:46:41 2021 +0000 @@ -23,6 +23,7 @@ extern int cmd_pb_erase_one(); extern int cmd_pb_update(); extern int cmd_pb_update_imm(); +extern int cmd_pb_update_imm_hex(); extern int cmd_readbin(); extern int cmd_readef(); extern int cmd_readrec(); @@ -70,6 +71,7 @@ {"pb-erase-one", 2, 2, cmd_pb_erase_one}, {"pb-update", 2, 2, cmd_pb_update}, {"pb-update-imm", 3, 4, cmd_pb_update_imm}, + {"pb-update-imm-hex", 4, 4, cmd_pb_update_imm_hex}, {"quit", 0, 0, cmd_exit}, {"readbin", 2, 2, cmd_readbin}, {"readef", 1, 1, cmd_readef},
--- a/simtool/pbupdate.c Thu Jan 28 04:19:52 2021 +0000 +++ b/simtool/pbupdate.c Thu Jan 28 04:46:41 2021 +0000 @@ -447,3 +447,58 @@ } return update_rec_op(recno, 0x04, record, curfile_record_len); } + +static +decode_alphatag_arg_hex(arg, record) + char *arg; + u_char *record; +{ + unsigned maxlen, acclen; + + maxlen = curfile_record_len - 14; + for (acclen = 0; ; acclen++) { + while (isspace(*arg)) + arg++; + if (!*arg) + break; + if (!isxdigit(arg[0]) || !isxdigit(arg[1])) { + fprintf(stderr, "error: invalid hex string input\n"); + return(-1); + } + if (acclen >= maxlen) { + fprintf(stderr, + "error: alpha tag string is longer than SIM limit\n"); + return(-1); + } + record[acclen] = (decode_hex_digit(arg[0]) << 4) | + decode_hex_digit(arg[1]); + arg += 2; + } + return(0); +} + +cmd_pb_update_imm_hex(argc, argv) + char **argv; +{ + int rc; + unsigned recno; + u_char record[255], *fixp; + + rc = phonebook_op_common(argv[1]); + if (rc < 0) + return(rc); + recno = strtoul(argv[2], 0, 0); + if (recno < 1 || recno > curfile_record_count) { + fprintf(stderr, "error: specified record number is invalid\n"); + return(-1); + } + memset(record, 0xFF, curfile_record_len); + fixp = record + curfile_record_len - 14; + rc = decode_number_arg(argv[3], fixp); + if (rc < 0) + return(rc); + rc = decode_alphatag_arg_hex(argv[4], record); + if (rc < 0) + return(rc); + return update_rec_op(recno, 0x04, record, curfile_record_len); +}