OpenCores
URL https://opencores.org/ocsvn/tv80/tv80/trunk

Subversion Repositories tv80

[/] [tv80/] [trunk/] [sc_env/] [env_memory.cpp] - Blame information for rev 98

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 91 ghutchis
#include "env_memory.h"
2 92 ghutchis
#include <stdio.h>
3 91 ghutchis
 
4
void env_memory::event()
5
{
6
  int lcl_cs;
7
  int ad;
8
 
9 94 ghutchis
  // ignore activity during reset
10
  if (!reset_n)
11
        return;
12 91 ghutchis
  if (!mreq_n && !wr_n && (addr < AM_DEPTH)) {
13 98 ghutchis
    ad = (int) addr;
14
    assert (memory != NULL);
15 91 ghutchis
    memory[ad] = (unsigned char) wr_data.read();
16
#ifdef DEBUG
17 94 ghutchis
    //printf ("MEM WR %04x=%02x\n", ad, (int) wr_data.read());
18 91 ghutchis
#endif
19 94 ghutchis
  }
20
 
21
  // async read output
22
  if (addr < AM_DEPTH) {
23 98 ghutchis
    ad = (int) addr;
24
    assert (memory != NULL);
25
    rd_data.write ( (unsigned int) memory[ad] );
26 91 ghutchis
  }
27
}
28 92 ghutchis
 
29 94 ghutchis
int inline readline(FILE *fh, char *buf)
30 92 ghutchis
{
31 94 ghutchis
        int c = 1, cnt = 0;
32 92 ghutchis
 
33 94 ghutchis
        if (feof(fh)) {
34
                *buf = (char) 0;
35
                return 0;
36
        }
37 92 ghutchis
        while (c) {
38 93 ghutchis
                c = fread (buf, 1, 1, fh);
39 94 ghutchis
                cnt++;
40
                if (c && (*buf == '\n')) {
41
                        buf++;
42
                        *buf = (char) 0;
43 92 ghutchis
                        c = 0;
44 94 ghutchis
                }
45 92 ghutchis
                else buf++;
46
        }
47 94 ghutchis
        return cnt;
48 92 ghutchis
}
49
 
50
/*
51
        line = ifh.readline()
52
        while (line != ''):
53
            if (line[0] == ':'):
54
                rlen = int(line[1:3], 16)
55
                addr = int(line[3:7], 16)
56
                rtyp = int(line[7:9], 16)
57
                ptr = 9
58
                for i in range (0, rlen):
59
                    laddr = addr + i
60
                    val = int(line[9+i*2:9+i*2+2], 16)
61
                    self.map[laddr] = val
62
                    self.bcount += 1
63
                    if (laddr > self.max): self.max = laddr
64
                    if (laddr < self.min): self.min = laddr
65
 
66
            line = ifh.readline()
67
 */
68
 void env_memory::load_ihex(char *filename)
69
{
70
        FILE *fh;
71
        char line[80];
72 94 ghutchis
    char *lp;
73
    int rlen, addr, rtyp, databyte;
74
    int rv;
75
    int dcount = 0;
76 92 ghutchis
 
77
        fh = fopen (filename, "r");
78
 
79 94 ghutchis
        rv = readline (fh, line);
80
    while (strlen(line) > 0) {
81
      //printf ("DEBUG: strlen(line)=%d rv=%d line=%s\n", strlen(line), rv, line);
82
      sscanf (line, ":%02x%04x%02x", &rlen, &addr, &rtyp);
83
      //printf ("DEBUG: rlen=%d addr=%d rtyp=%d\n", rlen, addr, rtyp);
84
      lp = line + 9;
85
      for (int c=0; c<rlen; c++) {
86
        sscanf (lp, "%02x", &databyte);
87
        lp += 2;
88
        //printf ("DEBUG: loaded mem[%04x]=%02x\n", addr+c, databyte);
89
        memory[addr+c] = databyte; dcount++;
90
      }
91
      rv = readline (fh, line);
92
    }
93 92 ghutchis
 
94
        fclose (fh);
95 94 ghutchis
        printf ("ENVMEM  : Read %d bytes from %s\n", dcount, filename);
96 92 ghutchis
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.