#include "env_memory.h"
|
#include "env_memory.h"
|
#include <stdio.h>
|
#include <stdio.h>
|
|
|
void env_memory::event()
|
void env_memory::event()
|
{
|
{
|
int lcl_cs;
|
int lcl_cs;
|
int ad;
|
int ad;
|
|
|
// ignore activity during reset
|
// ignore activity during reset
|
if (!reset_n)
|
if (!reset_n)
|
return;
|
return;
|
if (!mreq_n && !wr_n && (addr < AM_DEPTH)) {
|
if (!mreq_n && !wr_n && (addr < AM_DEPTH)) {
|
ad = (int) addr;
|
ad = (int) addr;
|
assert (memory != NULL);
|
assert (memory != NULL);
|
memory[ad] = (unsigned char) wr_data.read();
|
memory[ad] = (unsigned char) wr_data.read();
|
#ifdef DEBUG
|
#ifdef DEBUG
|
//printf ("MEM WR %04x=%02x\n", ad, (int) wr_data.read());
|
//printf ("MEM WR %04x=%02x\n", ad, (int) wr_data.read());
|
#endif
|
#endif
|
}
|
}
|
|
|
// async read output
|
// async read output
|
if (addr < AM_DEPTH) {
|
if (addr < AM_DEPTH) {
|
ad = (int) addr;
|
ad = (int) addr;
|
assert (memory != NULL);
|
assert (memory != NULL);
|
rd_data.write ( (unsigned int) memory[ad] );
|
rd_data.write ( (unsigned int) memory[ad] );
|
}
|
}
|
}
|
}
|
|
|
int inline readline(FILE *fh, char *buf)
|
int inline readline(FILE *fh, char *buf)
|
{
|
{
|
int c = 1, cnt = 0;
|
int c = 1, cnt = 0;
|
|
|
|
assert (fh != NULL);
|
|
|
if (feof(fh)) {
|
if (feof(fh)) {
|
*buf = (char) 0;
|
*buf = (char) 0;
|
return 0;
|
return 0;
|
}
|
}
|
while (c) {
|
while (c) {
|
c = fread (buf, 1, 1, fh);
|
c = fread (buf, 1, 1, fh);
|
cnt++;
|
cnt++;
|
if (c && (*buf == '\n')) {
|
if (c && (*buf == '\n')) {
|
buf++;
|
buf++;
|
*buf = (char) 0;
|
*buf = (char) 0;
|
c = 0;
|
c = 0;
|
}
|
}
|
else buf++;
|
else buf++;
|
}
|
}
|
return cnt;
|
return cnt;
|
}
|
}
|
|
|
/*
|
/*
|
line = ifh.readline()
|
line = ifh.readline()
|
while (line != ''):
|
while (line != ''):
|
if (line[0] == ':'):
|
if (line[0] == ':'):
|
rlen = int(line[1:3], 16)
|
rlen = int(line[1:3], 16)
|
addr = int(line[3:7], 16)
|
addr = int(line[3:7], 16)
|
rtyp = int(line[7:9], 16)
|
rtyp = int(line[7:9], 16)
|
ptr = 9
|
ptr = 9
|
for i in range (0, rlen):
|
for i in range (0, rlen):
|
laddr = addr + i
|
laddr = addr + i
|
val = int(line[9+i*2:9+i*2+2], 16)
|
val = int(line[9+i*2:9+i*2+2], 16)
|
self.map[laddr] = val
|
self.map[laddr] = val
|
self.bcount += 1
|
self.bcount += 1
|
if (laddr > self.max): self.max = laddr
|
if (laddr > self.max): self.max = laddr
|
if (laddr < self.min): self.min = laddr
|
if (laddr < self.min): self.min = laddr
|
|
|
line = ifh.readline()
|
line = ifh.readline()
|
*/
|
*/
|
void env_memory::load_ihex(char *filename)
|
void env_memory::load_ihex(char *filename)
|
{
|
{
|
FILE *fh;
|
FILE *fh;
|
char line[80];
|
char line[80];
|
char *lp;
|
char *lp;
|
int rlen, addr, rtyp, databyte;
|
int rlen, addr, rtyp, databyte;
|
int rv;
|
int rv;
|
int dcount = 0;
|
int dcount = 0;
|
|
|
fh = fopen (filename, "r");
|
fh = fopen (filename, "r");
|
|
|
rv = readline (fh, line);
|
rv = readline (fh, line);
|
while (strlen(line) > 0) {
|
while (strlen(line) > 0) {
|
//printf ("DEBUG: strlen(line)=%d rv=%d line=%s\n", strlen(line), rv, line);
|
//printf ("DEBUG: strlen(line)=%d rv=%d line=%s\n", strlen(line), rv, line);
|
sscanf (line, ":%02x%04x%02x", &rlen, &addr, &rtyp);
|
sscanf (line, ":%02x%04x%02x", &rlen, &addr, &rtyp);
|
//printf ("DEBUG: rlen=%d addr=%d rtyp=%d\n", rlen, addr, rtyp);
|
//printf ("DEBUG: rlen=%d addr=%d rtyp=%d\n", rlen, addr, rtyp);
|
lp = line + 9;
|
lp = line + 9;
|
for (int c=0; c<rlen; c++) {
|
for (int c=0; c<rlen; c++) {
|
sscanf (lp, "%02x", &databyte);
|
sscanf (lp, "%02x", &databyte);
|
lp += 2;
|
lp += 2;
|
//printf ("DEBUG: loaded mem[%04x]=%02x\n", addr+c, databyte);
|
//printf ("DEBUG: loaded mem[%04x]=%02x\n", addr+c, databyte);
|
|
assert ( (addr+c) < AM_DEPTH );
|
memory[addr+c] = databyte; dcount++;
|
memory[addr+c] = databyte; dcount++;
|
}
|
}
|
rv = readline (fh, line);
|
rv = readline (fh, line);
|
}
|
}
|
|
|
fclose (fh);
|
fclose (fh);
|
printf ("ENVMEM : Read %d bytes from %s\n", dcount, filename);
|
printf ("ENVMEM : Read %d bytes from %s\n", dcount, filename);
|
}
|
}
|
|
|