3 * @author Shinichiro Nakamura
4 * @brief motファイルダンププログラムの実装。
8 * ===============================================================
11 * ===============================================================
12 * Copyright (c) 2010-2011 Shinichiro Nakamura
14 * Permission is hereby granted, free of charge, to any person
15 * obtaining a copy of this software and associated documentation
16 * files (the "Software"), to deal in the Software without
17 * restriction, including without limitation the rights to use,
18 * copy, modify, merge, publish, distribute, sublicense, and/or
19 * sell copies of the Software, and to permit persons to whom the
20 * Software is furnished to do so, subject to the following
23 * The above copyright notice and this permission notice shall be
24 * included in all copies or substantial portions of the Software.
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
28 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
30 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
31 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
32 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33 * OTHER DEALINGS IN THE SOFTWARE.
34 * ===============================================================
41 unsigned char memory_image[0x100000 + 0x100];
42 unsigned int memory_lastaddr = 0;
45 const unsigned int addr,
46 const unsigned char *buf,
49 for (int i = 0; i < siz; i++) {
50 memory_image[addr + i] = buf[i];
52 if (memory_lastaddr < addr) {
53 memory_lastaddr = addr;
64 * @details 数値AをBで切り上げる。
66 #define ROUND_OUT(A,B) ((((A)+((B)-1))/(B))*(B))
71 int main(int argc, char **argv) {
73 printf("%s [filename]\n", argv[0]);
77 mot.cb_data = cb_data;
78 if (mot_read(argv[1], &mot) == 0) {
79 unsigned char cbuf[COLSIZ];
80 unsigned int ccnt = 0;
81 for (unsigned int addr = 0; addr < ROUND_OUT(memory_lastaddr, COLSIZ); addr++) {
85 if ((addr % COLSIZ) == 0) {
87 printf("0x%04X :", addr);
92 printf(" %02X", memory_image[addr] & 0xff);
93 cbuf[addr % COLSIZ] = memory_image[addr] & 0xff;
98 if (((addr + 1) % COLSIZ) == 0) {
101 for (int i = 0; i < COLSIZ; i++) {
103 printf("%c", isprint(cbuf[i] & 0xff)
104 ? (cbuf[i] & 0xff) : '.');
114 printf("Read failed.\n");