// set up the reference to the simulator
this.simulator = simulator;
this.clock = simulator.clock;
MicrocontrollerProperties props = simulator.getMicrocontroller().getProperties();
SREG = props.getIOReg("SREG");
// only look for the RAMPZ register if the flash is more than 64kb
if ( props.hasIOReg("RAMPZ") )
RAMPZ = props.getIOReg("RAMPZ");
else
RAMPZ = -1;
// if program will not fit onto hardware, error
if (p.program_end > pr.flash_size)
throw Avrora.failure("program will not fit into " + pr.flash_size + " bytes");
// beginning address of SRAM array
sram_start = pr.ioreg_size + NUM_REGS;
// maximum data address
sram_max = NUM_REGS + pr.ioreg_size + pr.sram_size;
// allocate SRAM
sram = new byte[sram_max];
// initialize IO registers to default values
registers = simulator.getMicrocontroller().getRegisterSet();
// for performance, we share a refernce to the ActiveRegister[] array
ioregs = registers.share();
SREG_reg = ioregs[SREG] = new SREG_reg();
// allocate FLASH
ErrorReporter reporter = new ErrorReporter();
flash = props.codeSegmentFactory.newCodeSegment("flash", this, reporter, p);
reporter.segment = flash;
// for performance, we share a reference to the Instr[] array representing flash
// TODO: implement share() method
shared_instr = flash.shareCode(null);
// initialize the interrupt table
interrupts = new InterruptTable(this, props.num_interrupts);
SPL_reg = (RWRegister) ioregs[props.getIOReg("SPL")];
SPH_reg = (RWRegister) ioregs[props.getIOReg("SPH")];
}