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

Subversion Repositories tv80

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

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

powered by: WebSVN 2.1.0

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