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

Subversion Repositories tv80

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

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
  if (!mreq_n && !wr_n && (addr < AM_DEPTH)) {
10
        ad = (int) addr;
11
    memory[ad] = (unsigned char) wr_data.read();
12
#ifdef DEBUG
13
    printf ("Wrote %x to address %x\n", (int) wr_data.read(), ad);
14
#endif
15
  } else if (!mreq_n && !rd_n && (addr < AM_DEPTH)) {
16
        ad = (int) addr;
17
        rd_data.write ( (unsigned int) memory[ad] );
18
#ifdef DEBUG
19
    printf ("Read %x from address %x\n", memory[ad], ad);
20
#endif
21
  }
22
}
23 92 ghutchis
 
24
void inline readline(FILE *fh, char *buf)
25
{
26
        int c = 1;
27
 
28
        while (c) {
29 93 ghutchis
                c = fread (buf, 1, 1, fh);
30 92 ghutchis
                if (c && (*buf == '\n'))
31
                        c = 0;
32
                else buf++;
33
        }
34
}
35
 
36
/*
37
        line = ifh.readline()
38
        while (line != ''):
39
            if (line[0] == ':'):
40
                rlen = int(line[1:3], 16)
41
                addr = int(line[3:7], 16)
42
                rtyp = int(line[7:9], 16)
43
                ptr = 9
44
                for i in range (0, rlen):
45
                    laddr = addr + i
46
                    val = int(line[9+i*2:9+i*2+2], 16)
47
                    self.map[laddr] = val
48
                    self.bcount += 1
49
                    if (laddr > self.max): self.max = laddr
50
                    if (laddr < self.min): self.min = laddr
51
 
52
            line = ifh.readline()
53
 */
54
 void env_memory::load_ihex(char *filename)
55
{
56
        FILE *fh;
57
        char line[80];
58 93 ghutchis
        char *lp;
59
        int rlen, addr, rtyp;
60 92 ghutchis
 
61
        fh = fopen (filename, "r");
62
 
63
        readline (fh, line);
64 93 ghutchis
        while (strlen(line) > 0) {
65
          printf ("DEBUG: strlen(line)=%d\n", strlen(line));
66
          sscanf (line, "%2x%2x%2x", &rlen, &addr, &rtyp);
67
          printf ("DEBUG: rlen=%d addr=%d rtyp=%d\n", rlen, addr, rtyp);
68
          lp = line + 6;
69
          for (int c=0; c<rlen; c++) {
70
          }
71
        }
72 92 ghutchis
 
73
        fclose (fh);
74
}

powered by: WebSVN 2.1.0

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