Some fixes towards 0.2.37-pre5
[fw/sdcc] / sim / ucsim / s51.src / cmd.cc
1 /*
2  * Simulator of microcontrollers (cmd.cc)
3  *
4  * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
5  * 
6  * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
7  *
8  */
9
10 /* This file is part of microcontroller simulator: ucsim.
11
12 UCSIM is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 UCSIM is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with UCSIM; see the file COPYING.  If not, write to the Free
24 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 02111-1307, USA. */
26 /*@1@*/
27
28 #include "ddconfig.h"
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <ctype.h>
33 #include <errno.h>
34 #include "i_string.h"
35
36 #include "uccl.h"
37 #include "globals.h"
38
39 #include "dump.h"
40 #include "go.h"
41 #include "cmd_brk.h"
42 #include "set.h"
43 #include "where.h"
44 #include "optioncl.h"
45 #include "show.h"
46
47 #include "cmd.h"
48
49
50 /* Table is defined at the end of this file */
51
52
53 /*
54  * HELP
55  */
56
57 static bool
58 cmd_help(char *cmd, class cl_uc *uc, class cl_sim *sim)
59 {
60   int i;
61
62   i= 0;
63   while (cmd_table[i].name != NULL)
64     {
65       if (cmd_table[i].help != NULL)
66         sim->cmd->printf("%s\n", cmd_table[i].help);
67       i++;
68     }
69   sim->cmd->printf("----\nSet of new commands:\n");
70   for (i= 0; i < sim->cmdset->count; i++)
71     {
72       class cl_cmd *cmd= (class cl_cmd *)(sim->cmdset->at(i));
73       sim->cmd->printf("%s\n", cmd->short_help);
74     }
75   return(DD_FALSE);
76 }
77
78
79 /*
80  * GET OPTION [opt]
81  */
82
83 static bool
84 cmd_get_option(char *cmd, class cl_uc *uc, class cl_sim *sim)
85 {
86   char *s;
87   int i;
88   class cl_option *o;
89
90   s= strtok(NULL, delimiters);
91   for (i= 0; i < uc->options->count; i++)
92     {
93       o= (class cl_option *)(uc->options->at(i));
94       if (!s ||
95           !strcmp(s, o->id))
96         {
97           fprintf(sim->cmd_out(), "%s ", o->id);
98           o->print(sim->cmd_out());
99           fprintf(sim->cmd_out(), " %s\n", o->help);
100         }
101     }
102   return(DD_FALSE);
103 }
104
105
106 /*
107  * SET OPTION opt value
108  */
109
110 static bool
111 cmd_set_option(char *cmd, class cl_uc *uc, class cl_sim *sim)
112 {
113   char *s, *id;
114   int i;
115   class cl_option *o;
116
117   if ((id= strtok(NULL, delimiters)) == NULL)
118     {
119       fprintf(sim->cmd_out(), "Name of option has not given.\n");
120       return(DD_FALSE);
121     }
122   if ((s= strtok(NULL, delimiters)) == NULL)
123     {
124       fprintf(sim->cmd_out(), "Value has not given.\n");
125       return(DD_FALSE);
126     }
127   for (i= 0; i < uc->options->count; i++)
128     {
129       o= (class cl_option *)(uc->options->at(i));
130       if (!strcmp(id, o->id))
131         {
132           o->set_value(s);
133           break;
134         }
135     }
136   return(DD_FALSE);
137 }
138
139
140 /*
141  * Table of commands and their names
142  */
143
144 struct cmd_entry cmd_table[]=
145 {
146   {"g" , cmd_go, DD_FALSE,
147    "g [start [stop]]   Go"},
148
149   {"stop", cmd_stop, DD_FALSE,
150    "stop               Stop"},
151
152   {"pc", cmd_pc, DD_FALSE,
153    "pc [address]       Get/set content of PC"},
154
155   {"s" , cmd_step, DD_TRUE,
156    "s [step]           Step"},
157
158   {"n" , cmd_next, DD_TRUE,
159    "n [step]           Next"},
160
161   {"bse", cmd_brk_sete, DD_FALSE,
162    "bse wi|ri|wx|rx|ws|rs|rc f|d addr [hit]\n"
163    "                   Set EVENT Breakpoint"},
164
165   {"bde", cmd_brk_dele, DD_FALSE,
166    "bde wi|ri|wx|rx|ws|rs|rc addr\n"
167    "                   Delete EVENT Breakpoint"},
168   
169   {"ba", cmd_brk_delall, DD_FALSE,
170    "ba                 Delete all breakpoints"},
171
172   {"dis", cmd_disass, DD_TRUE,
173    "dis [start [offset [lines]]]\n"
174    "                   Disassemble code"},
175
176   {"dp", cmd_dump_port, DD_FALSE,
177    "dp                 Dump ports"},
178
179   {"ds", cmd_dump_sfr, DD_FALSE,
180    "ds [addr...]       Dump SFR"},
181
182   {"db", cmd_dump_bit, DD_TRUE,
183    "db addr...         Dump bit"},
184
185   {"si", cmd_set_iram, DD_FALSE,
186    "si addr data...    Set Internal RAM"},
187
188   {"sx", cmd_set_xram, DD_FALSE,
189    "sx addr data...    Set External RAM"},
190
191   {"sc", cmd_set_code, DD_FALSE,
192    "sc addr data...    Set code (ROM)"},
193   
194   {"ss", cmd_set_sfr, DD_FALSE,
195    "ss addr data...    Set SFR area"},
196       
197   {"sb", cmd_set_bit, DD_FALSE,
198    "sb addr data...    Set bit"},
199
200   {"sp", cmd_set_port, DD_FALSE,
201    "sp port data       Set port pins"},
202
203   {"fi", cmd_fill_iram, DD_FALSE,
204    "fi start stop data Fill IRAM area with `data'"},
205
206   {"fx", cmd_fill_xram, DD_FALSE,
207    "fx start stop data Fill XRAM area with `data'"},
208        
209   {"fs", cmd_fill_sfr, DD_FALSE,
210    "fs start stop data Fill SFR area with `data'"},
211         
212   {"fc", cmd_fill_code, DD_FALSE,
213    "fc start stop data Fill ROM area with `data'"},
214
215   {"wi", cmd_where_iram, DD_FALSE,
216    "wi,Wi string       Search for `string' in IRAM (Wi case sensitive)"},
217   {"Wi", cmd_Where_iram, DD_FALSE, NULL},
218
219   {"wx", cmd_where_xram, DD_FALSE,
220    "wx,Wx string       Search for `string' in XRAM (Wx case sensitive)"},
221   {"Wx", cmd_Where_xram, DD_FALSE, NULL},
222
223   {"wc", cmd_where_code, DD_FALSE,
224    "wc,Wc string       Search for `string' in ROM (Wc case sensitive)"},
225   {"Wc", cmd_Where_code, DD_FALSE, NULL},
226           
227   {"sopt", cmd_set_option, DD_FALSE,
228    "sopt opt value     Set value of option"},
229
230   {"gopt", cmd_get_option, DD_FALSE,
231    "gopt [opt]         Get value of option(s)"},
232             
233   {"show", cmd_show, DD_FALSE,
234    "show c|w           Show licensing information"},
235       
236   {"h" , cmd_help, DD_FALSE,
237    "h,?                Help about commands"},
238   {"?" , cmd_help, DD_FALSE, NULL},
239   
240   {NULL, NULL}
241 };
242
243
244 /* End of s51.src/cmd.cc */