FreeCalypso > hg > fc-sim-tools
comparison simtool/readcmd.c @ 10:ddd767f6e15b
fc-simtool ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 07:11:25 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:c9ef9e91dd8e | 10:ddd767f6e15b |
---|---|
1 /* | |
2 * This module implements elementary low-level readbin and readrec commands. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <stdlib.h> | |
8 #include "simresp.h" | |
9 #include "curfile.h" | |
10 | |
11 cmd_readbin(argc, argv, outf) | |
12 char **argv; | |
13 FILE *outf; | |
14 { | |
15 unsigned offset, len; | |
16 int rc; | |
17 | |
18 offset = strtoul(argv[1], 0, 0); | |
19 if (offset > 0xFFFF) { | |
20 fprintf(stderr, "error: offset argument is out of range\n"); | |
21 return(-1); | |
22 } | |
23 len = strtoul(argv[2], 0, 0); | |
24 if (len < 1 || len > 256) { | |
25 fprintf(stderr, "error: length argument is out of range\n"); | |
26 return(-1); | |
27 } | |
28 rc = readbin_op(offset, len); | |
29 if (rc < 0) | |
30 return(rc); | |
31 display_sim_resp_in_hex(outf); | |
32 return(0); | |
33 } | |
34 | |
35 cmd_readrec(argc, argv, outf) | |
36 char **argv; | |
37 FILE *outf; | |
38 { | |
39 unsigned recno, len; | |
40 int rc; | |
41 | |
42 recno = strtoul(argv[1], 0, 0); | |
43 if (recno < 1 || recno > 255) { | |
44 fprintf(stderr, | |
45 "error: record number argument is out of range\n"); | |
46 return(-1); | |
47 } | |
48 if (argv[2]) { | |
49 len = strtoul(argv[2], 0, 0); | |
50 if (len < 1 || len > 255) { | |
51 fprintf(stderr, | |
52 "error: length argument is out of range\n"); | |
53 return(-1); | |
54 } | |
55 } else { | |
56 if (!curfile_record_len) { | |
57 fprintf(stderr, | |
58 "error: no current file record length is available\n"); | |
59 return(-1); | |
60 } | |
61 len = curfile_record_len; | |
62 } | |
63 rc = readrec_op(recno, 0x04, len); | |
64 if (rc < 0) | |
65 return(rc); | |
66 display_sim_resp_in_hex(outf); | |
67 return(0); | |
68 } |