comparison simtool/writecmd.c @ 1:2071b28cd0c7

simtool: first refactored version
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 11 Feb 2021 23:04:28 +0000
parents
children 702c2c40e51a
comparison
equal deleted inserted replaced
0:f7145c77b7fb 1:2071b28cd0c7
1 #include <sys/types.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include "curfile.h"
5
6 cmd_update_bin(argc, argv)
7 char **argv;
8 {
9 unsigned offset, len;
10 u_char data[255];
11 int rc;
12
13 offset = strtoul(argv[1], 0, 0);
14 if (offset > 0xFFFF) {
15 fprintf(stderr, "error: offset argument is out of range\n");
16 return(-1);
17 }
18 rc = read_hex_data_file(argv[2], data);
19 if (rc < 0)
20 return(rc);
21 len = rc;
22 return update_bin_op(offset, data, len);
23 }
24
25 cmd_update_bin_imm(argc, argv)
26 char **argv;
27 {
28 unsigned offset, len;
29 u_char data[255];
30 int rc;
31
32 offset = strtoul(argv[1], 0, 0);
33 if (offset > 0xFFFF) {
34 fprintf(stderr, "error: offset argument is out of range\n");
35 return(-1);
36 }
37 rc = decode_hex_data_from_string(argv[2], data, 1, 255);
38 if (rc < 0)
39 return(rc);
40 len = rc;
41 return update_bin_op(offset, data, len);
42 }
43
44 cmd_update_rec(argc, argv)
45 char **argv;
46 {
47 unsigned recno;
48 u_char data[255];
49 int rc;
50
51 recno = strtoul(argv[1], 0, 0);
52 if (recno < 1 || recno > 255) {
53 fprintf(stderr,
54 "error: record number argument is out of range\n");
55 return(-1);
56 }
57 rc = read_hex_data_file(argv[2], data);
58 if (rc < 0)
59 return(rc);
60 if (rc != curfile_record_len) {
61 fprintf(stderr, "error: hex data length != EF record length\n");
62 return(-1);
63 }
64 return update_rec_op(recno, 0x04, data, curfile_record_len);
65 }