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

Subversion Repositories t48

[/] [t48/] [tags/] [rel_1_1/] [sw/] [i8039emu/] [memory.c] - Blame information for rev 51

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

Line No. Rev Author Line
1 49 arniml
/*
2 51 arniml
 * $Id: memory.c,v 1.2 2004-04-14 20:50:51 arniml Exp $
3 49 arniml
 *
4
 * Copyright (c) 2004, Arnim Laeuger (arniml@opencores.org)
5
 *
6
 * All rights reserved
7
 *
8
 *  This program is free software; you can redistribute it and/or modify
9
 *  it under the terms of the GNU General Public License as published by
10
 *  the Free Software Foundation; either version 2 of the License, or
11
 *  (at your option) any later version. See also the file COPYING which
12
 *  came with this application.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU General Public License
20
 *  along with this program; if not, write to the Free Software
21
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 *
23
 */
24
 
25
#include <stdio.h>
26
#include <string.h>
27
 
28
#include "memory.h"
29 51 arniml
#include "i8039.h"
30 49 arniml
 
31
 
32
static UINT8 code_mem[4096];
33
 
34
 
35 51 arniml
static UINT8 port1 = 0xff, port2 = 0xff;
36 49 arniml
 
37 51 arniml
 
38 49 arniml
UINT8 program_read_byte_8(UINT16 address)
39
{
40 51 arniml
  return(code_mem[address]);
41 49 arniml
}
42
 
43
UINT8 cpu_readop(UINT16 address)
44
{
45
  return(code_mem[address]);
46
}
47
 
48
UINT8 cpu_readop_arg(UINT16 address)
49
{
50
  return(code_mem[address]);
51
}
52
 
53 51 arniml
 
54 49 arniml
UINT8 io_read_byte_8(UINT8 address)
55
{
56 51 arniml
  UINT8 data;
57
 
58
  switch (0x100 | address) {
59
    case I8039_p1:
60
      data = port1;
61
      break;
62
 
63
    case I8039_p2:
64
      data = port2;
65
      break;
66
 
67
    case I8039_t0:
68
      /* connect T0 to P1[0] */
69
      data = port1 & 0x01;
70
      break;
71
 
72
    case I8039_t1:
73
      /* connect T1 to P1[1] */
74
      data = (port1 & 0x02) >> 1;
75
      break;
76
 
77
    default:
78
      data = 0;
79
      break;
80
  }
81
 
82
 
83
  return(data);
84 49 arniml
}
85
 
86 51 arniml
 
87 49 arniml
void io_write_byte_8(UINT8 address, UINT8 data)
88
{
89 51 arniml
  switch (0x100 | address) {
90
    case I8039_p1:
91
      port1 = data;
92
      break;
93
 
94
    case I8039_p2:
95
      port2 = data;
96
      break;
97
 
98
    default:
99
      break;
100
  }
101 49 arniml
}
102
 
103
 
104
int read_hex_file(char *filename)
105
{
106
  FILE *hex_file;
107
  UINT16 record_len, offset, record_type;
108
  UINT16 byte;
109
  char line[540];
110
  char *payload, *idx;
111
  int result = 0;
112
 
113
  record_len = offset = record_type = 0;
114
  hex_file = fopen(filename, "r");
115
  if (hex_file != NULL) {
116
 
117
    while (fgets(line, 539, hex_file)) {
118
      if (sscanf(line, ":%2hx%4hx%2hx", &record_len, &offset, &record_type) == 3) {
119
        /* strip off newline */
120
        idx = (char *)strchr(line, '\n');
121
        if (idx != NULL)
122
          *idx = '\0';
123
        /* extract payload */
124
        payload = &(line[9]);
125
        /* strip of checksum */
126
        if (strlen(payload) > 2)
127
          payload[strlen(payload) - 2] = '\0';
128
 
129
        /* read payload to array */
130
        if (record_type == 0) {
131
          while (strlen(payload) >= 2) {
132
            if (sscanf(payload, "%2hx", &byte) == 1)
133
              code_mem[offset++] = byte;
134
 
135
            payload++;
136
            payload++;
137
          }
138
        }
139
 
140
      }
141
    }
142
 
143
    result = 1;
144
 
145
    fclose(hex_file);
146
  }
147
 
148
  return(result);
149
}

powered by: WebSVN 2.1.0

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