annotate simtool/writecmd.c @ 102:29cc5612797a

fc-simtool: update-rec command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 25 Jan 2021 02:16:16 +0000
parents 454ff8bd0b83
children 4aaf722ab933
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
101
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <pcsclite.h>
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <winscard.h>
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include "globals.h"
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 cmd_update_bin(argc, argv)
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 char **argv;
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 {
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 unsigned offset, len;
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 u_char data[255];
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 int rc;
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 offset = strtoul(argv[1], 0, 0);
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 if (offset > 0xFFFF) {
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 fprintf(stderr, "error: offset argument is out of range\n");
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 return(-1);
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 }
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 rc = read_hex_data_file(argv[2], data);
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (rc < 0)
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(rc);
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 len = rc;
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 return update_bin_op(offset, data, len);
454ff8bd0b83 fc-simtool: update-bin command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 }
102
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
26
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
27 cmd_update_rec(argc, argv)
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
28 char **argv;
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
29 {
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
30 unsigned recno;
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
31 u_char data[255];
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
32 int rc;
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
33
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
34 recno = strtoul(argv[1], 0, 0);
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
35 if (recno < 1 || recno > 255) {
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
36 fprintf(stderr,
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
37 "error: record number argument is out of range\n");
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
38 return(-1);
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
39 }
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
40 rc = read_hex_data_file(argv[2], data);
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
41 if (rc < 0)
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
42 return(rc);
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
43 if (rc != curfile_record_len) {
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
44 fprintf(stderr, "error: hex data length != EF record length\n");
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
45 return(-1);
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
46 }
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
47 return update_rec_op(recno, 0x04, data, curfile_record_len);
29cc5612797a fc-simtool: update-rec command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
48 }