version 0.2.39: fix of arith insts and start of re-structure
[fw/sdcc] / sim / ucsim / s51.src / where.cc
1 /*
2  * Simulator of microcontrollers (where.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 "i_string.h"
34
35 #include "stypes.h"
36 #include "simcl.h"
37 #include "memcl.h"
38 #include "uccl.h"
39 #include "globals.h"
40
41 #include "cmdutil.h"
42 #include "dump.h"
43
44
45 /*
46  * Searching for a string in memory
47  */
48
49 static void
50 where_memory(cl_mem *mem, bool cs, class cl_sim *sim)
51 {
52   char *s;
53   uchar *str;
54   int len, i, found;
55   t_addr start;
56
57   if ((s= strtok(NULL, "\0")) == NULL)
58     return;
59   str= (uchar *)proc_escape(s, &len);
60   // assume len < size!
61   if (!cs)
62     for (i= 0; i < len; i++)
63       str[i]= toupper(str[i]);
64   start= 0;
65   while (start < mem->size-len)
66     {
67       t_addr tmp= start;
68       found= DD_TRUE;
69       for (i= 0; found && (i<len); i++)
70         found= str[i] == (cs?mem->get(start+i):toupper(mem->get(start+i)));
71       if (found)
72         {
73           dump_memory(mem, &tmp, start+len-1, 8, sim->cmd->actual_console,sim);
74           start+= len;
75         }
76       else
77         start++;
78     }
79   free(str);
80 }
81
82
83 /*
84  * WHERE IRAM string
85  */
86
87 bool
88 cmd_where_iram(char *cmd, class cl_uc *uc, class cl_sim *sim)
89 {
90   where_memory(uc->mem(MEM_IRAM), DD_FALSE, sim);
91   return(DD_FALSE);
92 }
93
94 bool
95 cmd_Where_iram(char *cmd, class cl_uc *uc, class cl_sim *sim)
96 {
97   where_memory(uc->mem(MEM_IRAM), DD_TRUE, sim);
98   return(DD_FALSE);
99 }
100
101
102 /*
103  * WHERE XRAM string
104  */
105
106 bool
107 cmd_where_xram(char *cmd, class cl_uc *uc, class cl_sim *sim)
108 {
109   uc->eram2xram/*FIXME*/();
110   where_memory(uc->mem(MEM_XRAM), DD_FALSE, sim);
111   return(DD_FALSE);
112 }
113
114 bool
115 cmd_Where_xram(char *cmd, class cl_uc *uc, class cl_sim *sim)
116 {
117   uc->eram2xram/*FIXME*/();
118   where_memory(uc->mem(MEM_XRAM), DD_TRUE, sim);
119   return(DD_FALSE);
120 }
121
122
123 /*
124  * WHERE CODE string
125  */
126
127 bool
128 cmd_where_code(char *cmd, class cl_uc *uc, class cl_sim *sim)
129 {
130   where_memory(uc->mem(MEM_ROM), DD_FALSE, sim);
131   return(DD_FALSE);
132 }
133
134 bool
135 cmd_Where_code(char *cmd, class cl_uc *uc, class cl_sim *sim)
136 {
137   where_memory(uc->mem(MEM_ROM), DD_TRUE, sim);
138   return(DD_FALSE);
139 }
140
141
142 /* End of s51.src/where.cc */