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, FILE *f,
54 while ((*start <= stop) &&
57 sim->cmd->printf("%06x ", *start);
58 for (i= 0; (i < bpl) &&
59 (*start+i < mem->size) &&
64 sprintf(format, "%%0%dx ", mem->width/4);
65 fprintf(f, 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 data= uc->get_mem(MEM_SFR, P0);
148 sim->cmd->printf("P0 ");
149 print_bin(data, 8, sim->cmd_out());
150 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
152 data= uc->get_mem(MEM_SFR, P1);
153 sim->cmd->printf(" P1 ");
154 print_bin(data, 8, sim->cmd_out());
155 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
157 data= uc->port_pins[0];
158 sim->cmd->printf("Pin0 ");
159 print_bin(data, 8, sim->cmd_out());
160 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
162 data= uc->port_pins[1];
163 sim->cmd->printf(" Pin1 ");
164 print_bin(data, 8, sim->cmd_out());
165 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
167 data= uc->port_pins[0] & uc->get_mem(MEM_SFR, P0);
168 sim->cmd->printf("Port0 ");
169 print_bin(data, 8, sim->cmd_out());
170 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
172 data= uc->port_pins[1] & uc->get_mem(MEM_SFR, P1);
173 sim->cmd->printf(" Port1 ");
174 print_bin(data, 8, sim->cmd_out());
175 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
177 sim->cmd->printf("\n");
179 data= uc->get_mem(MEM_SFR, P2);
180 sim->cmd->printf("P2 ");
181 print_bin(data, 8, sim->cmd_out());
182 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
184 data= uc->get_mem(MEM_SFR, P3);
185 sim->cmd->printf(" P3 ");
186 print_bin(data, 8, sim->cmd_out());
187 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
189 data= uc->port_pins[2];
190 sim->cmd->printf("Pin2 ");
191 print_bin(data, 8, sim->cmd_out());
192 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
194 data= uc->port_pins[3];
195 sim->cmd->printf(" Pin3 ");
196 print_bin(data, 8, sim->cmd_out());
197 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
199 data= uc->port_pins[2] & uc->get_mem(MEM_SFR, P2);
200 sim->cmd->printf("Port2 ");
201 print_bin(data, 8, sim->cmd_out());
202 sim->cmd->printf(" 0x%02x %3d %c", data, data, isprint(data)?data:'.');
204 data= uc->port_pins[3] & uc->get_mem(MEM_SFR, P3);
205 sim->cmd->printf(" Port3 ");
206 print_bin(data, 8, sim->cmd_out());
207 sim->cmd->printf(" 0x%02x %3d %c\n", data, data, isprint(data)?data:'.');
218 cmd_dump_sfr(char *cmd, class t_uc51 *uc, class cl_sim *sim)
223 struct name_entry *ne;
225 if ((s= strtok(NULL, delimiters)) != NULL)
228 if ((ne= get_name_entry(uc->sfr_tbl(), s, uc)) != NULL)
230 data= uc->get_mem(MEM_SFR, ne->addr);
231 sim->cmd->printf("%6s %02x %3d %c\n", ne->name, data, data,
232 isprint(data)?data:'.');
236 start= strtol(s, NULL, 0);
237 data = uc->get_mem(MEM_SFR, start);
238 if (start >= SFR_START)
239 sim->cmd->printf("%06x %02x %3d %c\n", start, data, data,
240 isprint(data)?data:'.');
242 s= strtok(NULL, delimiters);
246 dump_memory(uc->mem(MEM_SFR), &start, 255, 16, sim->cmd_out(), sim);
256 cmd_dump_bit(char *cmd, class t_uc51 *uc, class cl_sim *sim)
260 uchar bitaddr, bitmask;
262 if ((s= strtok(NULL, delimiters)) == NULL)
264 sim->cmd->printf("Address has not given.\n");
269 if (!interpret_bitname(s, uc, &cell, &addr, &bitaddr, &bitmask, &sym))
271 sim->cmd->printf("Bad address %s\n", s);
274 sim->cmd->printf("%06x %6s %c\n", addr, sym, (*cell & bitmask)?'1':'0');
276 s= strtok(NULL, delimiters);
282 /* End of s51.src/dump.cc */