1 |
|
/* |
2 |
< |
* mon.cpp - mon main program |
2 |
> |
* mon.cpp - cxmon main program |
3 |
|
* |
4 |
< |
* mon (C) 1997-2000 Christian Bauer, Marc Hellwig |
4 |
> |
* cxmon (C) 1997-2002 Christian Bauer, Marc Hellwig |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
24 |
|
#include <stdlib.h> |
25 |
|
#include <signal.h> |
26 |
|
#include <ctype.h> |
27 |
+ |
#include <string> |
28 |
+ |
#include <map> |
29 |
|
|
30 |
< |
#ifdef HAVE_READLINE_READLINE_H |
30 |
> |
#if defined(HAVE_READLINE_H) |
31 |
> |
extern "C" { |
32 |
> |
#include <readline.h> |
33 |
> |
} |
34 |
> |
#elif defined(HAVE_READLINE_READLINE_H) |
35 |
|
extern "C" { |
36 |
|
#include <readline/readline.h> |
37 |
|
} |
38 |
|
#endif |
39 |
|
|
40 |
< |
#ifdef HAVE_READLINE_HISTORY_H |
40 |
> |
#if defined(HAVE_HISTORY_H) |
41 |
> |
extern "C" { |
42 |
> |
#include <history.h> |
43 |
> |
} |
44 |
> |
#elif defined(HAVE_READLINE_HISTORY_H) |
45 |
|
extern "C" { |
46 |
|
#include <readline/history.h> |
47 |
|
} |
49 |
|
|
50 |
|
#include "mon.h" |
51 |
|
#include "mon_cmd.h" |
52 |
+ |
#include "mon_lowmem.h" |
53 |
+ |
|
54 |
+ |
#ifndef VERSION |
55 |
+ |
#define VERSION "3" |
56 |
+ |
#endif |
57 |
|
|
58 |
|
|
59 |
|
// Buffer we're operating on |
71 |
|
char *mon_args_ptr; |
72 |
|
|
73 |
|
// Current address, value of '.' in expressions |
74 |
< |
uint32 mon_dot_address; |
74 |
> |
uintptr mon_dot_address; |
75 |
|
|
76 |
|
// Current value of ':' in expression |
77 |
|
static uint32 colon_value; |
79 |
|
|
80 |
|
// Scanner variables |
81 |
|
enum Token mon_token; // Last token read |
82 |
< |
uint32 mon_number; // Contains the number if mon_token==T_NUMBER |
82 |
> |
uintptr mon_number; // Contains the number if mon_token==T_NUMBER |
83 |
|
char mon_string[INPUT_LENGTH]; // Contains the string if mon_token==T_STRING |
84 |
|
char mon_name[INPUT_LENGTH]; // Contains the variable name if mon_token==T_NAME |
85 |
|
|
96 |
|
|
97 |
|
|
98 |
|
// List of variables |
99 |
< |
struct Variable { |
100 |
< |
Variable *next; // Pointer to next variable (must be first element of struct) |
86 |
< |
char *name; // Variable name |
87 |
< |
uint32 value; // Variable value |
88 |
< |
}; |
89 |
< |
|
90 |
< |
static Variable *first_var; // Pointer to first variable |
99 |
> |
typedef std::map<std::string, uintptr> var_map; |
100 |
> |
static var_map vars; |
101 |
|
|
102 |
|
|
103 |
|
// Prototypes |
107 |
|
static void read_line(char *prompt); // Scanner |
108 |
|
static char get_char(void); |
109 |
|
static void put_back(char c); |
110 |
< |
static enum Token get_hex_number(uint32 &i); |
111 |
< |
static enum Token get_dec_number(uint32 &i); |
112 |
< |
static enum Token get_char_number(uint32 &i); |
110 |
> |
static enum Token get_hex_number(uintptr &i); |
111 |
> |
static enum Token get_dec_number(uintptr &i); |
112 |
> |
static enum Token get_char_number(uintptr &i); |
113 |
|
static enum Token get_string(char *str); |
114 |
< |
static enum Token get_hex_or_name(uint32 &i, char *name); |
114 |
> |
static enum Token get_hex_or_name(uintptr &i, char *name); |
115 |
|
|
116 |
< |
static bool eor_expr(uint32 *number); // Parser |
117 |
< |
static bool and_expr(uint32 *number); |
118 |
< |
static bool shift_expr(uint32 *number); |
119 |
< |
static bool add_expr(uint32 *number); |
120 |
< |
static bool mul_expr(uint32 *number); |
121 |
< |
static bool factor(uint32 *number); |
112 |
< |
static Variable *lookup_var(const char *s); |
113 |
< |
static Variable *insert_var(const char *s); |
114 |
< |
static void remove_var(const char *s); |
116 |
> |
static bool eor_expr(uintptr *number); // Parser |
117 |
> |
static bool and_expr(uintptr *number); |
118 |
> |
static bool shift_expr(uintptr *number); |
119 |
> |
static bool add_expr(uintptr *number); |
120 |
> |
static bool mul_expr(uintptr *number); |
121 |
> |
static bool factor(uintptr *number); |
122 |
|
|
123 |
|
|
124 |
|
/* |
202 |
|
* Access to buffer |
203 |
|
*/ |
204 |
|
|
205 |
< |
uint32 (*mon_read_byte)(uint32 adr); |
205 |
> |
uint32 (*mon_read_byte)(uintptr adr); |
206 |
|
|
207 |
< |
uint32 mon_read_byte_buffer(uint32 adr) |
207 |
> |
uint32 mon_read_byte_buffer(uintptr adr) |
208 |
|
{ |
209 |
|
return mem[adr % mon_mem_size]; |
210 |
|
} |
211 |
|
|
212 |
< |
uint32 mon_read_byte_real(uint32 adr) |
212 |
> |
uint32 mon_read_byte_real(uintptr adr) |
213 |
|
{ |
214 |
|
return *(uint8 *)adr; |
215 |
|
} |
216 |
|
|
217 |
< |
void (*mon_write_byte)(uint32 adr, uint32 b); |
217 |
> |
void (*mon_write_byte)(uintptr adr, uint32 b); |
218 |
|
|
219 |
< |
void mon_write_byte_buffer(uint32 adr, uint32 b) |
219 |
> |
void mon_write_byte_buffer(uintptr adr, uint32 b) |
220 |
|
{ |
221 |
|
mem[adr % mon_mem_size] = b; |
222 |
|
} |
223 |
|
|
224 |
< |
void mon_write_byte_real(uint32 adr, uint32 b) |
224 |
> |
void mon_write_byte_real(uintptr adr, uint32 b) |
225 |
|
{ |
226 |
|
*(uint8 *)adr = b; |
227 |
|
} |
228 |
|
|
229 |
< |
uint32 mon_read_half(uint32 adr) |
229 |
> |
uint32 mon_read_half(uintptr adr) |
230 |
|
{ |
231 |
|
return (mon_read_byte(adr) << 8) | mon_read_byte(adr+1); |
232 |
|
} |
233 |
|
|
234 |
< |
void mon_write_half(uint32 adr, uint32 w) |
234 |
> |
void mon_write_half(uintptr adr, uint32 w) |
235 |
|
{ |
236 |
|
mon_write_byte(adr, w >> 8); |
237 |
|
mon_write_byte(adr+1, w); |
238 |
|
} |
239 |
|
|
240 |
< |
uint32 mon_read_word(uint32 adr) |
240 |
> |
uint32 mon_read_word(uintptr adr) |
241 |
|
{ |
242 |
|
return (mon_read_byte(adr) << 24) | (mon_read_byte(adr+1) << 16) | (mon_read_byte(adr+2) << 8) | mon_read_byte(adr+3); |
243 |
|
} |
244 |
|
|
245 |
< |
void mon_write_word(uint32 adr, uint32 l) |
245 |
> |
void mon_write_word(uintptr adr, uint32 l) |
246 |
|
{ |
247 |
|
mon_write_byte(adr, l >> 24); |
248 |
|
mon_write_byte(adr+1, l >> 16); |
267 |
|
|
268 |
|
line_read = readline(prompt); |
269 |
|
|
270 |
< |
if (line_read && *line_read) |
271 |
< |
add_history(line_read); |
270 |
> |
if (line_read) { |
271 |
> |
|
272 |
> |
if (*line_read) |
273 |
> |
add_history(line_read); |
274 |
> |
|
275 |
> |
strncpy(in_ptr = input, line_read, INPUT_LENGTH); |
276 |
> |
input[INPUT_LENGTH-1] = 0; |
277 |
|
|
278 |
< |
strncpy(in_ptr = input, line_read, INPUT_LENGTH); |
279 |
< |
input[INPUT_LENGTH-1] = 0; |
278 |
> |
} else { |
279 |
> |
|
280 |
> |
// EOF, quit cxmon |
281 |
> |
fprintf(monout, "x\n"); |
282 |
> |
input[0] = 'x'; |
283 |
> |
input[1] = 0; |
284 |
> |
in_ptr = input; |
285 |
> |
} |
286 |
|
#else |
287 |
|
fprintf(monout, prompt); |
288 |
|
fflush(monout); |
396 |
|
} |
397 |
|
} |
398 |
|
|
399 |
< |
static enum Token get_hex_number(uint32 &i) |
399 |
> |
static enum Token get_hex_number(uintptr &i) |
400 |
|
{ |
401 |
|
char c = get_char(); |
402 |
|
|
405 |
|
return T_NULL; |
406 |
|
|
407 |
|
do { |
408 |
+ |
c = tolower(c); |
409 |
|
if (c < 'a') |
410 |
|
i = (i << 4) + (c - '0'); |
411 |
|
else |
421 |
|
} |
422 |
|
} |
423 |
|
|
424 |
< |
static enum Token get_dec_number(uint32 &i) |
424 |
> |
static enum Token get_dec_number(uintptr &i) |
425 |
|
{ |
426 |
|
char c = get_char(); |
427 |
|
|
442 |
|
} |
443 |
|
} |
444 |
|
|
445 |
< |
static enum Token get_char_number(uint32 &i) |
445 |
> |
static enum Token get_char_number(uintptr &i) |
446 |
|
{ |
447 |
|
char c; |
448 |
|
|
473 |
|
return T_NULL; |
474 |
|
} |
475 |
|
|
476 |
< |
static enum Token get_hex_or_name(uint32 &i, char *name) |
476 |
> |
static enum Token get_hex_or_name(uintptr &i, char *name) |
477 |
|
{ |
478 |
|
char *old_in_ptr = in_ptr; |
479 |
|
char c; |
501 |
|
* true: OK, false: Error |
502 |
|
*/ |
503 |
|
|
504 |
< |
bool mon_expression(uint32 *number) |
504 |
> |
bool mon_expression(uintptr *number) |
505 |
|
{ |
506 |
< |
uint32 accu, expr; |
506 |
> |
uintptr accu, expr; |
507 |
|
|
508 |
|
if (!eor_expr(&accu)) |
509 |
|
return false; |
529 |
|
* true: OK, false: Error |
530 |
|
*/ |
531 |
|
|
532 |
< |
static bool eor_expr(uint32 *number) |
532 |
> |
static bool eor_expr(uintptr *number) |
533 |
|
{ |
534 |
< |
uint32 accu, expr; |
534 |
> |
uintptr accu, expr; |
535 |
|
|
536 |
|
if (!and_expr(&accu)) |
537 |
|
return false; |
557 |
|
* true: OK, false: Error |
558 |
|
*/ |
559 |
|
|
560 |
< |
static bool and_expr(uint32 *number) |
560 |
> |
static bool and_expr(uintptr *number) |
561 |
|
{ |
562 |
< |
uint32 accu, expr; |
562 |
> |
uintptr accu, expr; |
563 |
|
|
564 |
|
if (!shift_expr(&accu)) |
565 |
|
return false; |
585 |
|
* true: OK, false: Error |
586 |
|
*/ |
587 |
|
|
588 |
< |
static bool shift_expr(uint32 *number) |
588 |
> |
static bool shift_expr(uintptr *number) |
589 |
|
{ |
590 |
< |
uint32 accu, expr; |
590 |
> |
uintptr accu, expr; |
591 |
|
|
592 |
|
if (!add_expr(&accu)) |
593 |
|
return false; |
620 |
|
* true: OK, false: Error |
621 |
|
*/ |
622 |
|
|
623 |
< |
static bool add_expr(uint32 *number) |
623 |
> |
static bool add_expr(uintptr *number) |
624 |
|
{ |
625 |
< |
uint32 accu, expr; |
625 |
> |
uintptr accu, expr; |
626 |
|
|
627 |
|
if (!mul_expr(&accu)) |
628 |
|
return false; |
655 |
|
* true: OK, false: Error |
656 |
|
*/ |
657 |
|
|
658 |
< |
static bool mul_expr(uint32 *number) |
658 |
> |
static bool mul_expr(uintptr *number) |
659 |
|
{ |
660 |
< |
uint32 accu, fact; |
660 |
> |
uintptr accu, fact; |
661 |
|
|
662 |
|
if (!factor(&accu)) |
663 |
|
return false; |
705 |
|
* true: OK, false: Error |
706 |
|
*/ |
707 |
|
|
708 |
< |
static bool factor(uint32 *number) |
708 |
> |
static bool factor(uintptr *number) |
709 |
|
{ |
710 |
|
switch (mon_token) { |
711 |
|
case T_NUMBER: |
714 |
|
return true; |
715 |
|
|
716 |
|
case T_NAME:{ |
717 |
< |
Variable *var; |
718 |
< |
if ((var = lookup_var(mon_name)) != NULL) { |
719 |
< |
*number = var->value; |
717 |
> |
var_map::const_iterator v = vars.find(mon_name); |
718 |
> |
if (v == vars.end()) |
719 |
> |
return false; |
720 |
> |
else { |
721 |
> |
*number = v->second; |
722 |
|
mon_get_token(); |
723 |
|
return true; |
724 |
< |
} else |
704 |
< |
return false; |
724 |
> |
} |
725 |
|
} |
726 |
|
|
727 |
|
case T_DOT: |
781 |
|
|
782 |
|
|
783 |
|
/* |
764 |
– |
* Lookup the value of a variable |
765 |
– |
*/ |
766 |
– |
|
767 |
– |
static Variable *lookup_var(const char *s) |
768 |
– |
{ |
769 |
– |
// Lookup variable |
770 |
– |
for (Variable *var=first_var; var; var=var->next) |
771 |
– |
if (!strcmp(s, var->name)) |
772 |
– |
return var; |
773 |
– |
|
774 |
– |
// Not found, error |
775 |
– |
mon_error("Undefined variable"); |
776 |
– |
return NULL; |
777 |
– |
} |
778 |
– |
|
779 |
– |
|
780 |
– |
/* |
781 |
– |
* Insert new variable (or redefine old) |
782 |
– |
*/ |
783 |
– |
|
784 |
– |
static Variable *insert_var(const char *s) |
785 |
– |
{ |
786 |
– |
// Lookup variable |
787 |
– |
for (Variable *var=first_var; var; var=var->next) |
788 |
– |
if (!strcmp(s, var->name)) |
789 |
– |
return var; |
790 |
– |
|
791 |
– |
// Insert new variable |
792 |
– |
Variable *var = new Variable; |
793 |
– |
var->name = strdup(s); |
794 |
– |
var->next = first_var; |
795 |
– |
first_var = var; |
796 |
– |
return var; |
797 |
– |
} |
798 |
– |
|
799 |
– |
|
800 |
– |
/* |
801 |
– |
* Remove variable |
802 |
– |
*/ |
803 |
– |
|
804 |
– |
static void remove_var(const char *s) |
805 |
– |
{ |
806 |
– |
Variable *var, *prev = (Variable *)&first_var; |
807 |
– |
|
808 |
– |
// Lookup variable and remove it |
809 |
– |
for (var=prev->next; var; prev=var, var=var->next) |
810 |
– |
if (!strcmp(s, var->name)) { |
811 |
– |
prev->next = var->next; |
812 |
– |
free(var->name); |
813 |
– |
free(var); |
814 |
– |
return; |
815 |
– |
} |
816 |
– |
} |
817 |
– |
|
818 |
– |
|
819 |
– |
/* |
784 |
|
* Set/clear/show variables |
785 |
|
* set [var[=value]] |
786 |
|
*/ |
790 |
|
if (mon_token == T_END) { |
791 |
|
|
792 |
|
// Show all variables |
793 |
< |
if (first_var == NULL) |
793 |
> |
if (vars.empty()) |
794 |
|
fprintf(monout, "No variables defined\n"); |
795 |
< |
else |
796 |
< |
for (Variable *v=first_var; v; v=v->next) |
797 |
< |
fprintf(monout, "%s = %08x\n", v->name, v->value); |
795 |
> |
else { |
796 |
> |
var_map::const_iterator v = vars.begin(), end = vars.end(); |
797 |
> |
for (v=vars.begin(); v!=end; ++v) |
798 |
> |
fprintf(monout, "%s = %08x\n", v->first.c_str(), v->second); |
799 |
> |
} |
800 |
|
|
801 |
|
} else if (mon_token == T_NAME) { |
802 |
< |
char var_name[256]; |
837 |
< |
strcpy(var_name, mon_name); |
802 |
> |
std::string var_name = mon_name; |
803 |
|
mon_get_token(); |
804 |
|
if (mon_token == T_ASSIGN) { |
805 |
|
|
806 |
|
// Set variable |
807 |
< |
uint32 value; |
807 |
> |
uintptr value; |
808 |
|
mon_get_token(); |
809 |
|
if (!mon_expression(&value)) |
810 |
|
return; |
812 |
|
mon_error("Too many arguments"); |
813 |
|
return; |
814 |
|
} |
815 |
< |
insert_var(var_name)->value = value; |
815 |
> |
vars[var_name] = value; |
816 |
|
|
817 |
|
} else if (mon_token == T_END) { |
818 |
|
|
819 |
|
// Clear variable |
820 |
< |
remove_var(var_name); |
820 |
> |
vars.erase(var_name); |
821 |
|
|
822 |
|
} else |
823 |
|
mon_error("'=' expected"); |
833 |
|
|
834 |
|
static void clear_vars(void) |
835 |
|
{ |
836 |
< |
Variable *var, *next; |
872 |
< |
for (var=first_var; var; var=next) { |
873 |
< |
free(var->name); |
874 |
< |
next = var->next; |
875 |
< |
free(var); |
876 |
< |
} |
877 |
< |
first_var = NULL; |
836 |
> |
vars.clear(); |
837 |
|
} |
838 |
|
|
839 |
|
|
874 |
|
|
875 |
|
static void reallocate(void) |
876 |
|
{ |
877 |
< |
uint32 size; |
877 |
> |
uintptr size; |
878 |
|
|
879 |
|
if (mon_use_real_mem) { |
880 |
|
fprintf(monerr, "Cannot reallocate buffer in real mode\n"); |
907 |
|
|
908 |
|
static void apply(int size) |
909 |
|
{ |
910 |
< |
uint32 adr, end_adr, value; |
910 |
> |
uintptr adr, end_adr, value; |
911 |
|
char c; |
912 |
|
|
913 |
|
if (!mon_expression(&adr)) |
921 |
|
return; |
922 |
|
} |
923 |
|
|
924 |
< |
uint32 (*read_func)(uint32 adr); |
925 |
< |
void (*write_func)(uint32 adr, uint32 val); |
924 |
> |
uint32 (*read_func)(uintptr adr); |
925 |
> |
void (*write_func)(uintptr adr, uint32 val); |
926 |
|
switch (size) { |
927 |
|
case 1: |
928 |
|
read_func = mon_read_byte; |
1015 |
|
num_cmds = 0; |
1016 |
|
cmd_help = NULL; |
1017 |
|
|
1018 |
< |
mon_add_command("??", mon_cmd_list, "?? Show list of commands\n"); |
1019 |
< |
mon_add_command("ver", version, "ver Show version\n"); |
1020 |
< |
mon_add_command("?", print_expr, "? expression Calculate expression\n"); |
1021 |
< |
mon_add_command("@", reallocate, "@ [size] Reallocate buffer\n"); |
1022 |
< |
mon_add_command("i", ascii_dump, "i [start [end]] ASCII memory dump\n"); |
1023 |
< |
mon_add_command("m", memory_dump, "m [start [end]] Hex/ASCII memory dump\n"); |
1024 |
< |
mon_add_command("b", binary_dump, "b [start [end]] Binary memory dump\n"); |
1025 |
< |
mon_add_command("d", disassemble_ppc, "d [start [end]] Disassemble PowerPC code\n"); |
1026 |
< |
mon_add_command("d65", disassemble_6502, "d65 [start [end]] Disassemble 6502 code\n"); |
1027 |
< |
mon_add_command("d68", disassemble_680x0, "d68 [start [end]] Disassemble 680x0 code\n"); |
1028 |
< |
mon_add_command("d80", disassemble_8080, "d80 [start [end]] Disassemble 8080 code\n"); |
1029 |
< |
mon_add_command("d86", disassemble_80x86, "d86 [start [end]] Disassemble 80x86 code\n"); |
1030 |
< |
mon_add_command(":", modify, ": start string Modify memory\n"); |
1031 |
< |
mon_add_command("f", fill, "f start end string Fill memory\n"); |
1032 |
< |
mon_add_command("y", apply_byte, "y[b|h|w] start end expr Apply expression to memory\n"); |
1018 |
> |
mon_add_command("??", mon_cmd_list, "?? Show list of commands\n"); |
1019 |
> |
mon_add_command("ver", version, "ver Show version\n"); |
1020 |
> |
mon_add_command("?", print_expr, "? expression Calculate expression\n"); |
1021 |
> |
mon_add_command("@", reallocate, "@ [size] Reallocate buffer\n"); |
1022 |
> |
mon_add_command("i", ascii_dump, "i [start [end]] ASCII memory dump\n"); |
1023 |
> |
mon_add_command("m", memory_dump, "m [start [end]] Hex/ASCII memory dump\n"); |
1024 |
> |
mon_add_command("b", binary_dump, "b [start [end]] Binary memory dump\n"); |
1025 |
> |
mon_add_command("d", disassemble_ppc, "d [start [end]] Disassemble PowerPC code\n"); |
1026 |
> |
mon_add_command("d65", disassemble_6502, "d65 [start [end]] Disassemble 6502 code\n"); |
1027 |
> |
mon_add_command("d68", disassemble_680x0, "d68 [start [end]] Disassemble 680x0 code\n"); |
1028 |
> |
mon_add_command("d80", disassemble_z80, "d80 [start [end]] Disassemble Z80 code\n"); |
1029 |
> |
mon_add_command("d86", disassemble_80x86_32, "d86 [start [end]] Disassemble 80x86 (32-bit) code\n"); |
1030 |
> |
mon_add_command("d8086", disassemble_80x86_16, "d8086 [start [end]] Disassemble 80x86 (16-bit) code\n"); |
1031 |
> |
mon_add_command("d8664", disassemble_x86_64, "d8664 [start [end]] Disassemble x86-64 code\n"); |
1032 |
> |
mon_add_command(":", modify, ": start string Modify memory\n"); |
1033 |
> |
mon_add_command("f", fill, "f start end string Fill memory\n"); |
1034 |
> |
mon_add_command("y", apply_byte, "y[b|h|w] start end expr Apply expression to memory\n"); |
1035 |
|
mon_add_command("yb", apply_byte, NULL); |
1036 |
|
mon_add_command("yh", apply_half, NULL); |
1037 |
|
mon_add_command("yw", apply_word, NULL); |
1038 |
< |
mon_add_command("t", transfer, "t start end dest Transfer memory\n"); |
1039 |
< |
mon_add_command("c", compare, "c start end dest Compare memory\n"); |
1040 |
< |
mon_add_command("h", help_or_hunt, "h start end string Search for byte string\n"); |
1041 |
< |
mon_add_command("\\", shell_command, "\\ \"command\" Execute shell command\n"); |
1042 |
< |
mon_add_command("ls", mon_exec, "ls [args] List directory contents\n"); |
1043 |
< |
mon_add_command("rm", mon_exec, "rm [args] Remove file(s)\n"); |
1044 |
< |
mon_add_command("cp", mon_exec, "cp [args] Copy file(s)\n"); |
1045 |
< |
mon_add_command("mv", mon_exec, "mv [args] Move file(s)\n"); |
1046 |
< |
mon_add_command("cd", mon_change_dir, "cd directory Change current directory\n"); |
1047 |
< |
mon_add_command("o", redir_output, "o [\"file\"] Redirect output\n"); |
1048 |
< |
mon_add_command("[", load_data, "[ start \"file\" Load data from file\n"); |
1049 |
< |
mon_add_command("]", save_data, "] start size \"file\" Save data to file\n"); |
1050 |
< |
mon_add_command("set", set_var, "set [var[=value]] Set/clear/show variables\n"); |
1051 |
< |
mon_add_command("cv", clear_vars, "cv Clear all variables\n"); |
1038 |
> |
mon_add_command("t", transfer, "t start end dest Transfer memory\n"); |
1039 |
> |
mon_add_command("c", compare, "c start end dest Compare memory\n"); |
1040 |
> |
mon_add_command("h", help_or_hunt, "h start end string Search for byte string\n"); |
1041 |
> |
mon_add_command("\\", shell_command, "\\ \"command\" Execute shell command\n"); |
1042 |
> |
mon_add_command("ls", mon_exec, "ls [args] List directory contents\n"); |
1043 |
> |
mon_add_command("rm", mon_exec, "rm [args] Remove file(s)\n"); |
1044 |
> |
mon_add_command("cp", mon_exec, "cp [args] Copy file(s)\n"); |
1045 |
> |
mon_add_command("mv", mon_exec, "mv [args] Move file(s)\n"); |
1046 |
> |
mon_add_command("cd", mon_change_dir, "cd directory Change current directory\n"); |
1047 |
> |
mon_add_command("o", redir_output, "o [\"file\"] Redirect output\n"); |
1048 |
> |
mon_add_command("[", load_data, "[ start \"file\" Load data from file\n"); |
1049 |
> |
mon_add_command("]", save_data, "] start size \"file\" Save data to file\n"); |
1050 |
> |
mon_add_command("set", set_var, "set [var[=value]] Set/clear/show variables\n"); |
1051 |
> |
mon_add_command("cv", clear_vars, "cv Clear all variables\n"); |
1052 |
|
|
1053 |
|
mon_read_byte = NULL; |
1054 |
|
mon_write_byte = NULL; |
1082 |
|
monout = stdout; |
1083 |
|
monerr = stdout; |
1084 |
|
|
1085 |
< |
if (argc) { |
1086 |
< |
// Access real memory if mon was started as "rmon" |
1087 |
< |
char *prgname = argv[0]; |
1088 |
< |
char *lastslash; |
1089 |
< |
if ((lastslash = strrchr(prgname, '/')) != NULL) |
1090 |
< |
prgname = lastslash + 1; |
1091 |
< |
if (strcmp(prgname, "rmon") == 0) |
1085 |
> |
// Make argc/argv point to the actual arguments |
1086 |
> |
const char *prg_name = argv[0]; |
1087 |
> |
if (argc) |
1088 |
> |
argc--; argv++; |
1089 |
> |
|
1090 |
> |
// Parse arguments |
1091 |
> |
mon_macos_mode = false; |
1092 |
> |
mon_use_real_mem = false; |
1093 |
> |
while (argc > 0) { |
1094 |
> |
if (strcmp(argv[0], "-h") == 0 || strcmp(argv[0], "--help") == 0) { |
1095 |
> |
printf("Usage: %s [-m] [-r] [command...]\n", prg_name); |
1096 |
> |
exit(0); |
1097 |
> |
} else if (strcmp(argv[0], "-m") == 0) |
1098 |
> |
mon_macos_mode = true; |
1099 |
> |
else if (strcmp(argv[0], "-r") == 0) |
1100 |
|
mon_use_real_mem = true; |
1101 |
< |
|
1102 |
< |
// Make argc/argv point to the actual arguments |
1103 |
< |
argc--; |
1135 |
< |
argv++; |
1136 |
< |
interactive = (argc == 0); |
1101 |
> |
else |
1102 |
> |
break; |
1103 |
> |
argc--; argv++; |
1104 |
|
} |
1105 |
+ |
interactive = (argc == 0); |
1106 |
|
|
1107 |
|
// Set up memory access functions if not supplied by the user |
1108 |
|
if (mon_read_byte == NULL) { |
1125 |
|
|
1126 |
|
// Print banner |
1127 |
|
if (interactive) |
1128 |
< |
fprintf(monerr, "\n *** mon V" VERSION " by Christian Bauer and Marc Hellwig ***\n" |
1129 |
< |
" *** Press 'h' for help ***\n\n"); |
1128 |
> |
fprintf(monerr, "\n *** cxmon V" VERSION " by Christian Bauer and Marc Hellwig ***\n" |
1129 |
> |
" *** Press 'h' for help ***\n\n"); |
1130 |
> |
} |
1131 |
> |
|
1132 |
> |
// Clear variables |
1133 |
> |
vars.clear(); |
1134 |
> |
|
1135 |
> |
// In MacOS mode, pull in the lowmem globals as variables |
1136 |
> |
if (mon_macos_mode) { |
1137 |
> |
const lowmem_info *l = lowmem; |
1138 |
> |
while (l->name) { |
1139 |
> |
vars[l->name] = l->addr; |
1140 |
> |
l++; |
1141 |
> |
} |
1142 |
|
} |
1143 |
|
|
1144 |
|
init_abort(); |
1147 |
|
while (!done) { |
1148 |
|
if (interactive) { |
1149 |
|
char prompt[16]; |
1150 |
< |
sprintf(prompt, "[%08x]-> ", mon_dot_address); |
1150 |
> |
sprintf(prompt, "[%0*lx]-> ", 2 * sizeof(mon_dot_address), mon_dot_address); |
1151 |
|
read_line(prompt); |
1152 |
|
} else { |
1153 |
|
if (argc == 0) { |