FreeCalypso > hg > fc-sim-tools
comparison simtool/writecmd.c @ 10:ddd767f6e15b
fc-simtool ported over
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 14 Mar 2021 07:11:25 +0000 |
| parents | |
| children | 3055d5c9e7a3 |
comparison
equal
deleted
inserted
replaced
| 9:c9ef9e91dd8e | 10:ddd767f6e15b |
|---|---|
| 1 #include <sys/types.h> | |
| 2 #include <stdio.h> | |
| 3 #include <stdlib.h> | |
| 4 #include <string.h> | |
| 5 #include <strings.h> | |
| 6 #include "curfile.h" | |
| 7 | |
| 8 cmd_update_bin(argc, argv) | |
| 9 char **argv; | |
| 10 { | |
| 11 unsigned offset, len; | |
| 12 u_char data[255]; | |
| 13 int rc; | |
| 14 | |
| 15 offset = strtoul(argv[1], 0, 0); | |
| 16 if (offset > 0xFFFF) { | |
| 17 fprintf(stderr, "error: offset argument is out of range\n"); | |
| 18 return(-1); | |
| 19 } | |
| 20 rc = read_hex_data_file(argv[2], data, 255); | |
| 21 if (rc < 0) | |
| 22 return(rc); | |
| 23 len = rc; | |
| 24 return update_bin_op(offset, data, len); | |
| 25 } | |
| 26 | |
| 27 cmd_update_bin_imm(argc, argv) | |
| 28 char **argv; | |
| 29 { | |
| 30 unsigned offset, len; | |
| 31 u_char data[255]; | |
| 32 int rc; | |
| 33 | |
| 34 offset = strtoul(argv[1], 0, 0); | |
| 35 if (offset > 0xFFFF) { | |
| 36 fprintf(stderr, "error: offset argument is out of range\n"); | |
| 37 return(-1); | |
| 38 } | |
| 39 rc = decode_hex_data_from_string(argv[2], data, 1, 255); | |
| 40 if (rc < 0) | |
| 41 return(rc); | |
| 42 len = rc; | |
| 43 return update_bin_op(offset, data, len); | |
| 44 } | |
| 45 | |
| 46 cmd_update_rec(argc, argv) | |
| 47 char **argv; | |
| 48 { | |
| 49 unsigned recno, mode; | |
| 50 u_char data[255]; | |
| 51 int rc; | |
| 52 | |
| 53 if (!strcmp(argv[1], "prev")) { | |
| 54 recno = 0; | |
| 55 mode = 0x03; | |
| 56 } else { | |
| 57 recno = strtoul(argv[1], 0, 0); | |
| 58 if (recno < 1 || recno > 255) { | |
| 59 fprintf(stderr, | |
| 60 "error: record number argument is out of range\n"); | |
| 61 return(-1); | |
| 62 } | |
| 63 mode = 0x04; | |
| 64 } | |
| 65 rc = read_hex_data_file(argv[2], data, 255); | |
| 66 if (rc < 0) | |
| 67 return(rc); | |
| 68 if (rc != curfile_record_len) { | |
| 69 fprintf(stderr, "error: hex data length != EF record length\n"); | |
| 70 return(-1); | |
| 71 } | |
| 72 return update_rec_op(recno, mode, data, curfile_record_len); | |
| 73 } | |
| 74 | |
| 75 cmd_update_rec_imm(argc, argv) | |
| 76 char **argv; | |
| 77 { | |
| 78 unsigned recno, mode; | |
| 79 u_char data[255]; | |
| 80 int rc; | |
| 81 | |
| 82 if (!strcmp(argv[1], "prev")) { | |
| 83 recno = 0; | |
| 84 mode = 0x03; | |
| 85 } else { | |
| 86 recno = strtoul(argv[1], 0, 0); | |
| 87 if (recno < 1 || recno > 255) { | |
| 88 fprintf(stderr, | |
| 89 "error: record number argument is out of range\n"); | |
| 90 return(-1); | |
| 91 } | |
| 92 mode = 0x04; | |
| 93 } | |
| 94 rc = decode_hex_data_from_string(argv[2], data, 1, 255); | |
| 95 if (rc < 0) | |
| 96 return(rc); | |
| 97 if (rc != curfile_record_len) { | |
| 98 fprintf(stderr, "error: hex data length != EF record length\n"); | |
| 99 return(-1); | |
| 100 } | |
| 101 return update_rec_op(recno, mode, data, curfile_record_len); | |
| 102 } | |
| 103 | |
| 104 cmd_update_rec_fill(argc, argv) | |
| 105 char **argv; | |
| 106 { | |
| 107 unsigned recno, mode, fill_byte; | |
| 108 u_char data[255]; | |
| 109 | |
| 110 if (!strcmp(argv[1], "prev")) { | |
| 111 recno = 0; | |
| 112 mode = 0x03; | |
| 113 } else { | |
| 114 recno = strtoul(argv[1], 0, 0); | |
| 115 if (recno < 1 || recno > 255) { | |
| 116 fprintf(stderr, | |
| 117 "error: record number argument is out of range\n"); | |
| 118 return(-1); | |
| 119 } | |
| 120 mode = 0x04; | |
| 121 } | |
| 122 fill_byte = strtoul(argv[2], 0, 16); | |
| 123 if (fill_byte > 0xFF) { | |
| 124 fprintf(stderr, "error: invalid fill byte argument\n"); | |
| 125 return(-1); | |
| 126 } | |
| 127 memset(data, fill_byte, curfile_record_len); | |
| 128 return update_rec_op(recno, mode, data, curfile_record_len); | |
| 129 } |
