2 * Simulator of microcontrollers (port.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
35 cl_port::cl_port(class cl_uc *auc, int aid):
36 cl_hw(auc, HW_PORT, aid, "port")
46 case 0: addr_p= P0; break;
51 if ((hw= uc->get_hw(HW_TIMER, 2, 0)))
52 hws_to_inform->add(hw);*/
53 make_partner(HW_TIMER, 2);
54 make_partner(HW_PCA, 0);
57 case 2: addr_p= P2; break;
62 /*if ((hw= uc->get_hw(HW_TIMER, 0, 0)))
63 hws_to_inform->add(hw);
64 if ((hw= uc->get_hw(HW_TIMER, 1, 0)))
65 hws_to_inform->add(hw);
66 if ((hw= uc->get_hw(HW_DUMMY, 0, 0)))
67 hws_to_inform->add(hw);*/
68 make_partner(HW_TIMER, 0);
69 make_partner(HW_TIMER, 1);
70 make_partner(HW_INTERRUPT, 0);
71 make_partner(HW_DUMMY, 0);
74 default: addr_p= P0; return(1);
76 class cl_address_space *sfr= uc->address_space(MEM_SFR_ID);
79 fprintf(stderr, "No SFR to register port into\n");
81 //cell_p= sfr->register_hw(addr_p, this, (int*)0);
82 register_cell(sfr, addr_p, &cell_p, wtd_restore_write);
88 cl_port::read(class cl_memory_cell *cell)
90 //printf("port[%d] read\n",id);
91 return(cell->get() & port_pins);
95 cl_port::write(class cl_memory_cell *cell, t_mem *val)
97 struct ev_port_changed ep;
99 (*val)&= 0xff; // 8 bit port
102 ep.prev_value= cell_p->get();
104 ep.pins= ep.new_pins= port_pins;
105 if (ep.prev_value != ep.new_value)
106 inform_partners(EV_PORT_CHANGED, &ep);
108 //printf("port[%d] write 0x%x\n",id,val);
112 cl_port::set_cmd(class cl_cmdline *cmdline, class cl_console *con)
114 struct ev_port_changed ep;
115 class cl_cmd_arg *params[1]= { cmdline->param(0) };
118 if (cmdline->syntax_match(uc, NUMBER))
120 value= params[0]->value.number & 0xff;
126 ep.prev_value= cell_p->get();
127 ep.new_value= cell_p->get();
128 ep.new_pins= port_pins;
129 if (ep.pins != ep.new_pins)
130 inform_partners(EV_PORT_CHANGED, &ep);
134 con->dd_printf("set hardware port[%d] pins_value\n Set port pins\n",
141 cl_port::mem_cell_changed(class cl_m *mem, t_addr addr)
143 cl_hw::mem_cell_changed(mem, addr);
149 cl_port::print_info(class cl_console *con)
153 con->dd_printf("%s[%d]\n", id_string, id);
155 con->dd_printf("P%d ", id);
156 con->print_bin(data, 8);
157 con->dd_printf(" 0x%02x %3d %c (Value in SFR register)\n",
158 data, data, isprint(data)?data:'.');
160 data= /*uc->*/port_pins/*[id]*/;
161 con->dd_printf("Pin%d ", id);
162 con->print_bin(data, 8);
163 con->dd_printf(" 0x%02x %3d %c (Output of outside circuits)\n",
164 data, data, isprint(data)?data:'.');
166 data= cell_p->read();
167 con->dd_printf("Port%d ", id);
168 con->print_bin(data, 8);
169 con->dd_printf(" 0x%02x %3d %c (Value on the port pins)\n",
170 data, data, isprint(data)?data:'.');
174 /* End of s51.src/port.cc */