2000-12-15 21:05:16 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2000 Stephen Williams (steve@icarus.com)
|
|
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
|
|
|
|
#if !defined(WINNT) && !defined(macintosh)
|
2000-12-15 22:54:43 +01:00
|
|
|
#ident "$Id: vvm_memory.cc,v 1.2 2000/12/15 21:54:43 steve Exp $"
|
2000-12-15 21:05:16 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
# include "vvm_signal.h"
|
|
|
|
|
|
|
|
|
|
vvm_memory_t::vvm_memory_t()
|
|
|
|
|
{
|
|
|
|
|
cb_list_ = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvm_memory_t::set_word(unsigned addr, const vvm_bitset_t&val)
|
|
|
|
|
{
|
|
|
|
|
if (addr >= size)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
unsigned base = width * addr;
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
|
|
|
|
bits[base+idx] = val[idx];
|
|
|
|
|
|
|
|
|
|
call_list_(addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvm_memory_t::set_word(unsigned addr, const vpip_bit_t*val)
|
|
|
|
|
{
|
|
|
|
|
if (addr >= size)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
unsigned base = width * addr;
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
|
|
|
|
bits[base+idx] = val[idx];
|
|
|
|
|
|
|
|
|
|
call_list_(addr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvm_memory_t::get_word(unsigned addr, vvm_bitset_t&val) const
|
|
|
|
|
{
|
|
|
|
|
if (addr >= size) {
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
|
|
|
|
val[idx] = StX;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsigned base = width * addr;
|
|
|
|
|
for (unsigned idx = 0 ; idx < width ; idx += 1)
|
|
|
|
|
val[idx] = bits[base+idx];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvm_memory_t::set_callback(vvm_ram_callback*ram)
|
|
|
|
|
{
|
|
|
|
|
ram->next_ = cb_list_;
|
|
|
|
|
cb_list_ = ram;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvm_memory_t::call_list_(unsigned idx)
|
|
|
|
|
{
|
|
|
|
|
for (vvm_ram_callback*cur = cb_list_; cur; cur = cur->next_)
|
|
|
|
|
cur->handle_write(idx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
vvm_memory_t::assign_nb::assign_nb(vvm_memory_t&m, unsigned i,
|
|
|
|
|
const vvm_bitset_t&v)
|
|
|
|
|
: mem_(m), index_(i), bits_(new vpip_bit_t[m.width]), val_(bits_, m.width)
|
|
|
|
|
{
|
2000-12-15 22:54:43 +01:00
|
|
|
unsigned top = m.width;
|
|
|
|
|
if (top > v.nbits)
|
|
|
|
|
top = v.nbits;
|
|
|
|
|
|
|
|
|
|
for (unsigned idx = 0 ; idx < top ; idx += 1)
|
2000-12-15 21:05:16 +01:00
|
|
|
val_[idx] = v[idx];
|
2000-12-15 22:54:43 +01:00
|
|
|
for (unsigned idx = top ; idx < m.width ; idx += 1)
|
|
|
|
|
val_[idx] = St0;
|
2000-12-15 21:05:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
vvm_memory_t::assign_nb::~assign_nb()
|
|
|
|
|
{
|
|
|
|
|
delete[]bits_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void vvm_memory_t::assign_nb::event_function()
|
|
|
|
|
{
|
|
|
|
|
mem_.set_word(index_, val_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* $Log: vvm_memory.cc,v $
|
2000-12-15 22:54:43 +01:00
|
|
|
* Revision 1.2 2000/12/15 21:54:43 steve
|
|
|
|
|
* Allow non-blocking assign to pad memory word with zeros.
|
|
|
|
|
*
|
2000-12-15 21:05:16 +01:00
|
|
|
* Revision 1.1 2000/12/15 20:05:16 steve
|
|
|
|
|
* Fix memory access in vvm. (PR#70)
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|