c0a604ab557087b338be202bb16dbc3c7bef6ddc
[fw/sdcc] / sim / ucsim / cmd.src / newcmdcl.h
1 /*
2  * Simulator of microcontrollers (cmd.src/cmdcl.h)
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 #ifndef CMD_NEWCMDCL_HEADER
29 #define CMD_NEWCMDCL_HEADER
30
31
32 #include "ddconfig.h"
33
34 #include <stdio.h>
35 #include <sys/types.h>
36 #if FD_HEADER_OK
37 # include HEADER_FD
38 #endif
39
40 // prj
41 #include "pobjcl.h"
42
43 // sim.src
44 #include "appcl.h"
45
46 // local, cmd
47 #include "commandcl.h"
48
49
50 // Flags of consoles
51 #define CONS_NONE        0
52 #define CONS_DEBUG       0x01   // Print debug messages on this console
53 #define CONS_FROZEN      0x02   // Console is frozen (g command issued)
54 #define CONS_PROMPT      0x04   // Prompt is out, waiting for input
55 #define CONS_INTERACTIVE 0x08   // Interactive console
56 #define CONS_NOWELCOME   0x10   // Do not print welcome message
57 #define CONS_INACTIVE    0x20   // Do not do any action
58 #define CONS_ECHO        0x40   // Echo commands
59
60 #define SY_ADDR         'a'
61 #define ADDRESS         "a"
62 #define SY_NUMBER       'n'
63 #define NUMBER          "n"
64 #define SY_DATA         'd'
65 #define DATA            "d"
66 #define SY_STRING       's'
67 #define STRING          "s"
68 #define SY_MEMORY       'm'
69 #define MEMORY          "m"
70 #define SY_HW           'h'
71 #define HW              "h"
72 #define SY_DATALIST     'D'
73 #define DATALIST        "D"
74 #define SY_BIT          'b'
75 #define BIT             "b"
76
77
78 class cl_prompt_option: public cl_optref
79 {
80 protected:
81   class cl_console *con;
82 public:
83   cl_prompt_option(class cl_console *console);
84   virtual int init(void);
85   virtual void option_changed(void);
86 };
87
88 class cl_debug_option: public cl_prompt_option
89 {
90 public:
91   cl_debug_option(class cl_console *console);
92   virtual int init(void);
93   virtual void option_changed(void);
94 };
95
96 /*
97  * Command console
98  */
99
100 class cl_console: public cl_base
101 {
102   friend class cl_commander;
103 protected:
104   FILE *in, *out, *rout/*redirected output*/;
105   int id;
106   class cl_prompt_option *prompt_option;
107   class cl_optref *null_prompt_option;
108   class cl_debug_option *debug_option;
109 public:
110   class cl_app *app;
111   char *last_command;
112   int flags; // See CONS_XXXX
113   char *prompt;
114
115 public:
116   cl_console(void): cl_base() { app= 0; in= out= 0; flags= 0; }
117   cl_console(char *fin, char *fout, class cl_app *the_app);
118   cl_console(FILE *fin, FILE *fout, class cl_app *the_app);
119   cl_console(char *fin, FILE *fout);
120 #ifdef SOCKET_AVAIL
121   cl_console(int portnumber, class cl_app *the_app);
122 #endif
123   virtual ~cl_console(void);
124   virtual class cl_console *cl_console::clone_for_exec(char *fin);
125   virtual int init(void);
126
127   virtual void welcome(void);
128   virtual void redirect(char *fname, char *mode);
129   virtual void un_redirect(void);
130   virtual FILE *get_out(void) { return(rout?rout:out); }
131   virtual void print_prompt(void);
132   virtual int  dd_printf(char *format, ...);
133   virtual void print_bin(long data, int bits);
134   virtual void print_char_octal(char c);
135   virtual int  match(int fdnum);
136   virtual int  get_in_fd(void);
137   virtual int  input_avail(void);
138   virtual char *read_line(void);
139   virtual int  proc_input(class cl_cmdset *cmdset);
140   virtual bool interpret(char *cmd);
141   virtual void set_id(int new_id);
142   virtual int get_id(void) { return(id); }
143   virtual void set_prompt(char *p);
144 };
145
146 #ifdef SOCKET_AVAIL
147 class cl_listen_console: public cl_console
148 {
149 public:
150   int sock;
151 public:
152   cl_listen_console(int serverport, class cl_app *the_app);
153
154   virtual void welcome(void) {}
155   virtual void prompt(void) {}
156
157   virtual int match(int fdnum);
158   virtual int get_in_fd(void);
159   virtual int proc_input(class cl_cmdset *cmdset);
160 };
161 #endif
162
163
164 class cl_sub_console: public cl_console
165 {
166   class cl_console *parent;
167 public:
168   cl_sub_console(class cl_console *the_parent,
169                  FILE *fin, FILE *fout, class cl_app *the_app);
170   virtual ~cl_sub_console(void);
171   virtual int init(void);
172 };
173
174
175 /*
176  * Command interpreter
177  */
178
179 class cl_commander: public cl_base
180 {
181 public:
182   class cl_app *app;
183   class cl_list *cons;
184   fd_set read_set, active_set;
185   int fd_num;
186   //class cl_sim *sim;
187   class cl_console *actual_console, *frozen_console;
188   class cl_cmdset *cmdset;
189
190 public:
191   cl_commander(class cl_app *the_app,
192                class cl_cmdset *acmdset/*, class cl_sim *asim*/);
193   virtual ~cl_commander(void);
194   virtual int init(void);
195
196   virtual class cl_console *mk_console(char *fin, char *fout);
197   virtual class cl_console *mk_console(FILE *fin, FILE *fout);
198 #ifdef SOCKET_AVAIL
199   virtual class cl_console *mk_console(int portnumber);
200 #endif
201   void add_console(class cl_console *console);
202   void del_console(class cl_console *console);
203   void activate_console(class cl_console *console);
204   void deactivate_console(class cl_console *console);
205   void set_fd_set(void);
206
207   void prompt(void);
208   int all_printf(char *format, ...);    // print to all consoles
209   int all_print(char *string, int length);
210   int dd_printf(char *format, ...);     // print to actual_console
211   int debug(char *format, ...);         // print consoles with debug flag set
212   int flag_printf(int iflags, char *format, ...);
213   int input_avail(void);
214   int input_avail_on_frozen(void);
215   int wait_input(void);
216   int proc_input(void);
217 };
218
219
220 #endif
221
222 /* End of cmd.src/cmdcl.h */