2 * Simulator of microcontrollers (dump.cc)
4 * Copyright (C) 1999,99 Drotos Daniel, Talker Bt.
6 * To contact author send email to drdani@mazsola.iit.uni-miskolc.hu
10 /* This file is part of microcontroller simulator: ucsim.
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.
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.
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
37 #include "uc51cl.h" //FIXME
38 #include "regs51.h" //FIXME
48 dump_memory(cl_mem *mem,
49 t_addr *start, t_addr stop, int bpl, class cl_console *con,
54 while ((*start <= stop) &&
57 con->printf("%06x ", *start);
58 for (i= 0; (i < bpl) &&
59 (*start+i < mem->size) &&
64 sprintf(format, "%%0%dx ", mem->width/4);
65 con->printf(format/*"%02x "*/, mem->get(*start+i));
72 for (i= 0; (i < bpl) &&
73 (*start+i < mem->size) &&
77 isprint(mem->get(*start+i))?(char)mem->get(*start+i):'.');
85 * DISASSEMBLE [start [offset [lines]]]
88 static int disass_last_stop= 0;
91 cmd_disass(char *cmd, class t_uc51 *uc, class cl_sim *sim)
94 int start, offset= -1, dir;
98 if (!uc->there_is_inst())
100 if ((s= strtok(NULL, delimiters)) != NULL)
101 start= strtol(s, NULL, 0);
103 start= disass_last_stop;
104 if ((s= strtok(NULL, delimiters)) != NULL)
105 offset= strtol(s, NULL, 0);
106 if ((s= strtok(NULL, delimiters)) != NULL)
107 lines= strtol(s, NULL, 0);
110 while (!uc->inst_at(realstart))
111 realstart= (realstart+1) & (EROM_SIZE-1);
114 dir= (offset < 0)?-1:+1;
117 realstart= (realstart+dir) & (EROM_SIZE-1);
118 while (!uc->inst_at(realstart))
119 realstart= (realstart+dir) & (EROM_SIZE-1);
126 uc->print_disass(realstart, sim->cmd->actual_console);
127 realstart= (realstart+1) & (EROM_SIZE-1);
128 while (!uc->inst_at(realstart))
129 realstart= (realstart+1) & (EROM_SIZE-1);
133 disass_last_stop= realstart;
143 cmd_dump_port(char *cmd, class t_uc51 *uc, class cl_sim *sim)
147 if (sim->cmd->actual_console == 0)
149 data= uc->get_mem(MEM_SFR, P0);
150 sim->cmd->printf("P0 ");
151 sim->cmd->actual_console->print_bin(data, 8);
152 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
154 data= uc->get_mem(MEM_SFR, P1);
155 sim->cmd->printf(" P1 ");
156 sim->cmd->actual_console->print_bin(data, 8);
157 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
159 data= uc->port_pins[0];
160 sim->cmd->printf("Pin0 ");
161 sim->cmd->actual_console->print_bin(data, 8);
162 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
164 data= uc->port_pins[1];
165 sim->cmd->printf(" Pin1 ");
166 sim->cmd->actual_console->print_bin(data, 8);
167 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
169 data= uc->port_pins[0] & uc->get_mem(MEM_SFR, P0);
170 sim->cmd->printf("Port0 ");
171 sim->cmd->actual_console->print_bin(data, 8);
172 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
174 data= uc->port_pins[1] & uc->get_mem(MEM_SFR, P1);
175 sim->cmd->printf(" Port1 ");
176 sim->cmd->actual_console->print_bin(data, 8);
177 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
179 sim->cmd->printf("\n");
181 data= uc->get_mem(MEM_SFR, P2);
182 sim->cmd->printf("P2 ");
183 sim->cmd->actual_console->print_bin(data, 8);
184 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
186 data= uc->get_mem(MEM_SFR, P3);
187 sim->cmd->printf(" P3 ");
188 sim->cmd->actual_console->print_bin(data, 8);
189 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
191 data= uc->port_pins[2];
192 sim->cmd->printf("Pin2 ");
193 sim->cmd->actual_console->print_bin(data, 8);
194 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
196 data= uc->port_pins[3];
197 sim->cmd->printf(" Pin3 ");
198 sim->cmd->actual_console->print_bin(data, 8);
199 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
201 data= uc->port_pins[2] & uc->get_mem(MEM_SFR, P2);
202 sim->cmd->printf("Port2 ");
203 sim->cmd->actual_console->print_bin(data, 8);
204 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
206 data= uc->port_pins[3] & uc->get_mem(MEM_SFR, P3);
207 sim->cmd->printf(" Port3 ");
208 sim->cmd->actual_console->print_bin(data, 8);
209 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
220 cmd_dump_sfr(char *cmd, class t_uc51 *uc, class cl_sim *sim)
225 struct name_entry *ne;
227 if ((s= strtok(NULL, delimiters)) != NULL)
230 if ((ne= get_name_entry(uc->sfr_tbl(), s, uc)) != NULL)
232 data= uc->get_mem(MEM_SFR, ne->addr);
233 sim->cmd->printf("%6s %02x %3d %c\n", ne->name, data, data,
234 isprint(data)?data:'.');
238 start= strtol(s, NULL, 0);
239 data = uc->get_mem(MEM_SFR, start);
240 if (start >= SFR_START)
241 sim->cmd->printf("%06x %02x %3d %c\n", start, data, data,
242 isprint(data)?data:'.');
244 s= strtok(NULL, delimiters);
248 dump_memory(uc->mem(MEM_SFR), &start, 255, 16, sim->cmd->actual_console,
259 cmd_dump_bit(char *cmd, class t_uc51 *uc, class cl_sim *sim)
263 uchar bitaddr, bitmask;
265 if ((s= strtok(NULL, delimiters)) == NULL)
267 sim->cmd->printf("Address has not given.\n");
272 if (!interpret_bitname(s, uc, &cell, &addr, &bitaddr, &bitmask, &sym))
274 sim->cmd->printf("Bad address %s\n", s);
277 sim->cmd->printf("%06x %6s %c\n", addr, sym, (*cell & bitmask)?'1':'0');
279 s= strtok(NULL, delimiters);
285 /* End of s51.src/dump.cc */