2 * Simulator of microcontrollers (set.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
44 #include "regs51.h" //FIXME
48 * Parsing command and write data into specified buffer
52 set_memory(cl_mem *mem, t_addr first,
53 class cl_uc *uc, struct name_entry tabl[], class cl_sim *sim)
58 struct name_entry *ne= NULL;
60 if ((s= strtok(NULL, delimiters)) == NULL)
62 fprintf(sim->cmd_out(), "Address has not given.\n");
66 ne= get_name_entry(tabl, s, uc);
71 addr= strtol(s, &p, 0);
75 fprintf(sim->cmd_out(), "Bad address.\n");
80 if (start >= mem->size)
82 fprintf(sim->cmd_out(),
83 "Address %ld(0x%lx) is bigger than %ld(0x%lx).\n",
84 start, start, mem->size-1, mem->size-1);
87 if (!(start >= first))
89 fprintf(sim->cmd_out(),
90 "Address %ld(0x%lx) is less than %ld(0x%lx).\n",
91 start, start, first, first);
94 if ((s= strtok(NULL, " \t\v")) == NULL)
96 fprintf(sim->cmd_out(), "Data has not given.\n");
104 data= strtol(s, &p, 0);
108 fprintf(sim->cmd_out(), "Bad data %s\n", s);
111 mem->set(addr, data);
112 if (what == uc->MEM(MEM_SFR))
114 uc->proc_write/*FIXME*/(&what[addr]);
116 uc->set_p_flag/*FIXME*/();
118 if (what == uc->MEM(MEM_ROM))
119 uc->del_inst_at/*FIXME*/(addr);
125 p= proc_escape(s, &len);
131 if (what == uc->MEM(MEM_SFR))
133 uc->proc_write/*FIXME*/(&what[addr]);
135 uc->set_p_flag/*FIXME*/();
137 if (what == uc->MEM(MEM_ROM))
138 uc->del_inst_at/*FIXME*/(addr);
143 s= strtok(NULL, " \t\v");
145 dump_memory(mem, &start, addr-1, 16, sim->cmd_out(), sim);
150 * SET IRAM addr data...
154 cmd_set_iram(char *cmd, class cl_uc *uc, class cl_sim *sim)
156 set_memory(uc->mem(MEM_IRAM), 0, uc, NULL, sim);
162 * SET XRAM addr data...
166 cmd_set_xram(char *cmd, class cl_uc *uc, class cl_sim *sim)
169 set_memory(uc->mem(MEM_XRAM), 0, uc, NULL, sim);
176 * SET CODE addr data...
180 cmd_set_code(char *cmd, class cl_uc *uc, class cl_sim *sim)
182 set_memory(uc->mem(MEM_ROM), 0, uc, NULL, sim);
188 * SET SFR addr data...
192 cmd_set_sfr(char *cmd, class cl_uc *uc, class cl_sim *sim)
194 set_memory(uc->mem(MEM_SFR), SFR_START, uc, uc->sfr_tbl(), sim);
200 * SET BIT addr data...
204 cmd_set_bit(char *cmd, class cl_uc *uc, class cl_sim *sim)
208 uchar bitaddr, bitmask;
210 if ((s= strtok(NULL, delimiters)) == NULL)
212 fprintf(sim->cmd_out(), "Address has not given.\n");
215 if (!interpret_bitname(s, uc, &cell, &addr, &bitaddr, &bitmask, NULL))
217 fprintf(sim->cmd_out(), "Bad address %s\n", s);
221 if ((s= strtok(NULL, delimiters)) == NULL)
223 fprintf(sim->cmd_out(), "Data has not given.\n");
230 fprintf(sim->cmd_out(), "Bad data %s\n", s);
239 s= strtok(NULL, delimiters);
250 cmd_set_port(char *cmd, class cl_uc *uc, class cl_sim *sim)
255 if ((s= strtok(NULL, delimiters)) == NULL)
257 fprintf(sim->cmd_out(), "Port number has not given.\n");
260 port= strtol(s, &p, 0);
264 fprintf(sim->cmd_out(), "Port number %s is wrong.\n", s);
268 if ((s= strtok(NULL, delimiters)) == NULL)
270 fprintf(sim->cmd_out(), "Date has not given.\n");
273 data= strtol(s, &p, 0);
276 fprintf(sim->cmd_out(), "Data %s is wrong.\n", s);
279 uc->port_pins[port]= data;
285 * Fill memory commands
289 fill_memory(uchar *what, int size, int first, class cl_uc *uc,
296 if ((s= strtok(NULL, delimiters)) == NULL)
298 start= strtol(s, &p, 0);
303 fprintf(sim->cmd_out(), "Start address %s is wrong.\n", s);
305 if ((s= strtok(NULL, delimiters)) == NULL)
307 stop= strtol(s, &p, 0);
311 fprintf(sim->cmd_out(), "Stop address %s is wrong.\n", s);
313 if ((s= strtok(NULL, delimiters)) == NULL)
315 data= strtol(s, &p, 0);
317 fprintf(sim->cmd_out(), "Data %s is wrong.\n", s);
319 while (start <= stop)
322 if (what == uc->MEM(MEM_SFR))
324 uc->proc_write/*FIXME*/(&what[start]);
326 uc->set_p_flag/*FIXME*/();
328 if (what == uc->MEM(MEM_ROM))
329 uc->del_inst_at/*FIXME*/(start);
336 * FILL IRAM from to data
340 cmd_fill_iram(char *cmd, class cl_uc *uc, class cl_sim *sim)
342 fill_memory(uc->MEM(MEM_IRAM), uc->get_mem_size(MEM_IRAM), 0, uc, sim);
348 * FILL XRAM from to data
352 cmd_fill_xram(char *cmd, class cl_uc *uc, class cl_sim *sim)
354 fill_memory(uc->MEM(MEM_XRAM), uc->get_mem_size(MEM_XRAM), 0, uc, sim);
355 uc->xram2eram/*FIXME*/();
361 * FILL SFR from to data
365 cmd_fill_sfr(char *cmd, class cl_uc *uc, class cl_sim *sim)
367 fill_memory(uc->MEM(MEM_SFR), uc->get_mem_size(MEM_SFR), SFR_START, uc, sim);
373 * FILL CODE from to data
377 cmd_fill_code(char *cmd, class cl_uc *uc, class cl_sim *sim)
379 fill_memory(uc->MEM(MEM_ROM), EROM_SIZE, 0, uc, sim);
384 /* End of s51.src/set.cc */