annotate simtool/writecmd.c @ 141:a1aa8ee2da85

read_hex_data_file(): add maxlen argument
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 24 Feb 2021 17:25:28 +0000
parents 702c2c40e51a
children 3f6f50103dd3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include "curfile.h"
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 cmd_update_bin(argc, argv)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 unsigned offset, len;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 u_char data[255];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 offset = strtoul(argv[1], 0, 0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 if (offset > 0xFFFF) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 fprintf(stderr, "error: offset argument is out of range\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 }
141
a1aa8ee2da85 read_hex_data_file(): add maxlen argument
Mychaela Falconia <falcon@freecalypso.org>
parents: 78
diff changeset
18 rc = read_hex_data_file(argv[2], data, 255);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 len = rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return update_bin_op(offset, data, len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 cmd_update_bin_imm(argc, argv)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 unsigned offset, len;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 u_char data[255];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 offset = strtoul(argv[1], 0, 0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (offset > 0xFFFF) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 fprintf(stderr, "error: offset argument is out of range\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 rc = decode_hex_data_from_string(argv[2], data, 1, 255);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 len = rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return update_bin_op(offset, data, len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 cmd_update_rec(argc, argv)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 char **argv;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 unsigned recno;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 u_char data[255];
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 int rc;
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 recno = strtoul(argv[1], 0, 0);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (recno < 1 || recno > 255) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fprintf(stderr,
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 "error: record number argument is out of range\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
141
a1aa8ee2da85 read_hex_data_file(): add maxlen argument
Mychaela Falconia <falcon@freecalypso.org>
parents: 78
diff changeset
57 rc = read_hex_data_file(argv[2], data, 255);
1
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (rc < 0)
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return(rc);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (rc != curfile_record_len) {
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fprintf(stderr, "error: hex data length != EF record length\n");
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return(-1);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return update_rec_op(recno, 0x04, data, curfile_record_len);
2071b28cd0c7 simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
78
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
66
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
67 cmd_update_rec_prev(argc, argv)
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
68 char **argv;
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
69 {
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
70 u_char data[255];
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
71 int rc;
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
72
141
a1aa8ee2da85 read_hex_data_file(): add maxlen argument
Mychaela Falconia <falcon@freecalypso.org>
parents: 78
diff changeset
73 rc = read_hex_data_file(argv[1], data, 255);
78
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
74 if (rc < 0)
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
75 return(rc);
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
76 if (rc != curfile_record_len) {
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
77 fprintf(stderr, "error: hex data length != EF record length\n");
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
78 return(-1);
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
79 }
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
80 return update_rec_op(0, 0x03, data, curfile_record_len);
702c2c40e51a fc-simtool update-rec-prev command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 1
diff changeset
81 }