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 sim->cmd->printf("Address has not given.\n");
66 ne= get_name_entry(tabl, s, uc);
71 addr= strtol(s, &p, 0);
75 sim->cmd->printf("Bad address.\n");
80 if (start >= mem->size)
82 sim->cmd->printf("Address %ld(0x%lx) is bigger than %ld(0x%lx).\n",
83 start, start, mem->size-1, mem->size-1);
86 if (!(start >= first))
88 sim->cmd->printf("Address %ld(0x%lx) is less than %ld(0x%lx).\n",
89 start, start, first, first);
92 if ((s= strtok(NULL, " \t\v")) == NULL)
94 sim->cmd->printf("Data has not given.\n");
102 data= strtol(s, &p, 0);
106 sim->cmd->printf("Bad data %s\n", s);
109 mem->set(addr, data);
110 if (what == uc->MEM(MEM_SFR))
112 uc->proc_write/*FIXME*/(&what[addr]);
114 uc->set_p_flag/*FIXME*/();
116 if (what == uc->MEM(MEM_ROM))
117 uc->del_inst_at/*FIXME*/(addr);
123 p= proc_escape(s, &len);
129 if (what == uc->MEM(MEM_SFR))
131 uc->proc_write/*FIXME*/(&what[addr]);
133 uc->set_p_flag/*FIXME*/();
135 if (what == uc->MEM(MEM_ROM))
136 uc->del_inst_at/*FIXME*/(addr);
141 s= strtok(NULL, " \t\v");
143 dump_memory(mem, &start, addr-1, 16, sim->cmd->actual_console, sim);
148 * SET IRAM addr data...
152 cmd_set_iram(char *cmd, class cl_uc *uc, class cl_sim *sim)
154 set_memory(uc->mem(MEM_IRAM), 0, uc, NULL, sim);
160 * SET XRAM addr data...
164 cmd_set_xram(char *cmd, class cl_uc *uc, class cl_sim *sim)
167 set_memory(uc->mem(MEM_XRAM), 0, uc, NULL, sim);
174 * SET CODE addr data...
178 cmd_set_code(char *cmd, class cl_uc *uc, class cl_sim *sim)
180 set_memory(uc->mem(MEM_ROM), 0, uc, NULL, sim);
186 * SET SFR addr data...
190 cmd_set_sfr(char *cmd, class cl_uc *uc, class cl_sim *sim)
192 set_memory(uc->mem(MEM_SFR), SFR_START, uc, uc->sfr_tbl(), sim);
198 * SET BIT addr data...
202 cmd_set_bit(char *cmd, class cl_uc *uc, class cl_sim *sim)
206 uchar bitaddr, bitmask;
208 if ((s= strtok(NULL, delimiters)) == NULL)
210 sim->cmd->printf("Address has not given.\n");
213 if (!interpret_bitname(s, uc, &cell, &addr, &bitaddr, &bitmask, NULL))
215 sim->cmd->printf("Bad address %s\n", s);
219 if ((s= strtok(NULL, delimiters)) == NULL)
221 sim->cmd->printf("Data has not given.\n");
228 sim->cmd->printf("Bad data %s\n", s);
237 s= strtok(NULL, delimiters);
248 cmd_set_port(char *cmd, class cl_uc *uc, class cl_sim *sim)
253 if ((s= strtok(NULL, delimiters)) == NULL)
255 sim->cmd->printf("Port number has not given.\n");
258 port= strtol(s, &p, 0);
262 sim->cmd->printf("Port number %s is wrong.\n", s);
266 if ((s= strtok(NULL, delimiters)) == NULL)
268 sim->cmd->printf("Date has not given.\n");
271 data= strtol(s, &p, 0);
274 sim->cmd->printf("Data %s is wrong.\n", s);
277 uc->port_pins[port]= data;
283 * Fill memory commands
287 fill_memory(uchar *what, int size, int first, class cl_uc *uc,
294 if ((s= strtok(NULL, delimiters)) == NULL)
296 start= strtol(s, &p, 0);
301 sim->cmd->printf("Start address %s is wrong.\n", s);
303 if ((s= strtok(NULL, delimiters)) == NULL)
305 stop= strtol(s, &p, 0);
309 sim->cmd->printf("Stop address %s is wrong.\n", s);
311 if ((s= strtok(NULL, delimiters)) == NULL)
313 data= strtol(s, &p, 0);
315 sim->cmd->printf("Data %s is wrong.\n", s);
317 while (start <= stop)
320 if (what == uc->MEM(MEM_SFR))
322 uc->proc_write/*FIXME*/(&what[start]);
324 uc->set_p_flag/*FIXME*/();
326 if (what == uc->MEM(MEM_ROM))
327 uc->del_inst_at/*FIXME*/(start);
334 * FILL IRAM from to data
338 cmd_fill_iram(char *cmd, class cl_uc *uc, class cl_sim *sim)
340 fill_memory(uc->MEM(MEM_IRAM), uc->get_mem_size(MEM_IRAM), 0, uc, sim);
346 * FILL XRAM from to data
350 cmd_fill_xram(char *cmd, class cl_uc *uc, class cl_sim *sim)
352 fill_memory(uc->MEM(MEM_XRAM), uc->get_mem_size(MEM_XRAM), 0, uc, sim);
353 uc->xram2eram/*FIXME*/();
359 * FILL SFR from to data
363 cmd_fill_sfr(char *cmd, class cl_uc *uc, class cl_sim *sim)
365 fill_memory(uc->MEM(MEM_SFR), uc->get_mem_size(MEM_SFR), SFR_START, uc, sim);
371 * FILL CODE from to data
375 cmd_fill_code(char *cmd, class cl_uc *uc, class cl_sim *sim)
377 fill_memory(uc->MEM(MEM_ROM), EROM_SIZE, 0, uc, sim);
382 /* End of s51.src/set.cc */