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

Subversion Repositories tv80

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

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 111 ghutchis
        assert (fh != NULL);
34
 
35 94 ghutchis
        if (feof(fh)) {
36
                *buf = (char) 0;
37
                return 0;
38
        }
39 92 ghutchis
        while (c) {
40 93 ghutchis
                c = fread (buf, 1, 1, fh);
41 94 ghutchis
                cnt++;
42
                if (c && (*buf == '\n')) {
43
                        buf++;
44
                        *buf = (char) 0;
45 92 ghutchis
                        c = 0;
46 94 ghutchis
                }
47 92 ghutchis
                else buf++;
48
        }
49 94 ghutchis
        return cnt;
50 92 ghutchis
}
51
 
52
/*
53
        line = ifh.readline()
54
        while (line != ''):
55
            if (line[0] == ':'):
56
                rlen = int(line[1:3], 16)
57
                addr = int(line[3:7], 16)
58
                rtyp = int(line[7:9], 16)
59
                ptr = 9
60
                for i in range (0, rlen):
61
                    laddr = addr + i
62
                    val = int(line[9+i*2:9+i*2+2], 16)
63
                    self.map[laddr] = val
64
                    self.bcount += 1
65
                    if (laddr > self.max): self.max = laddr
66
                    if (laddr < self.min): self.min = laddr
67
 
68
            line = ifh.readline()
69
 */
70
 void env_memory::load_ihex(char *filename)
71
{
72
        FILE *fh;
73
        char line[80];
74 94 ghutchis
    char *lp;
75
    int rlen, addr, rtyp, databyte;
76
    int rv;
77
    int dcount = 0;
78 92 ghutchis
 
79
        fh = fopen (filename, "r");
80
 
81 94 ghutchis
        rv = readline (fh, line);
82
    while (strlen(line) > 0) {
83
      //printf ("DEBUG: strlen(line)=%d rv=%d line=%s\n", strlen(line), rv, line);
84
      sscanf (line, ":%02x%04x%02x", &rlen, &addr, &rtyp);
85
      //printf ("DEBUG: rlen=%d addr=%d rtyp=%d\n", rlen, addr, rtyp);
86
      lp = line + 9;
87
      for (int c=0; c<rlen; c++) {
88
        sscanf (lp, "%02x", &databyte);
89
        lp += 2;
90
        //printf ("DEBUG: loaded mem[%04x]=%02x\n", addr+c, databyte);
91 111 ghutchis
        assert ( (addr+c) < AM_DEPTH );
92 94 ghutchis
        memory[addr+c] = databyte; dcount++;
93
      }
94
      rv = readline (fh, line);
95
    }
96 92 ghutchis
 
97
        fclose (fh);
98 94 ghutchis
        printf ("ENVMEM  : Read %d bytes from %s\n", dcount, filename);
99 92 ghutchis
}

powered by: WebSVN 2.1.0

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