dev_fdc.cc Source File
Back to the index.
src
devices
dev_fdc.cc
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2003-2009 Anders Gavare. All rights reserved.
3
*
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions are met:
6
*
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* 3. The name of the author may not be used to endorse or promote products
13
* derived from this software without specific prior written permission.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25
* SUCH DAMAGE.
26
*
27
*
28
* COMMENT: PC-style floppy controller
29
*
30
* TODO! (This is just a dummy skeleton right now.)
31
*
32
* TODO 2: Make it work nicely with both ARC and PC emulation.
33
*
34
* See http://members.tripod.com/~oldboard/assembly/765.html for a
35
* quick overview.
36
*/
37
38
#include <stdio.h>
39
#include <stdlib.h>
40
#include <string.h>
41
42
#include "
device.h
"
43
#include "
interrupt.h
"
44
#include "
machine.h
"
45
#include "
memory.h
"
46
#include "
misc.h
"
47
48
49
#define DEV_FDC_LENGTH 6
/* TODO 8, but collision with wdc */
50
51
52
struct
fdc_data
{
53
uint8_t
reg
[
DEV_FDC_LENGTH
];
54
struct
interrupt
irq
;
55
};
56
57
58
DEVICE_ACCESS
(fdc)
59
{
60
struct
fdc_data
*d = (
struct
fdc_data
*) extra;
61
uint64_t idata = 0, odata = 0;
62
size_t
i;
63
64
if
(writeflag ==
MEM_WRITE
)
65
idata =
memory_readmax64
(
cpu
,
data
, len);
66
67
switch
(relative_addr) {
68
case
0x04:
69
break
;
70
default
:
if
(writeflag==
MEM_READ
) {
71
fatal
(
"[ fdc: read from reg %i ]\n"
,
72
(
int
)relative_addr);
73
odata = d->
reg
[relative_addr];
74
}
else
{
75
fatal
(
"[ fdc: write to reg %i:"
, (
int
)relative_addr);
76
for
(i=0; i<len; i++)
77
fatal
(
" %02x"
,
data
[i]);
78
fatal
(
" ]\n"
);
79
d->
reg
[relative_addr] = idata;
80
}
81
}
82
83
if
(writeflag ==
MEM_READ
)
84
memory_writemax64
(
cpu
,
data
, len, odata);
85
86
return
1;
87
}
88
89
90
DEVINIT
(fdc)
91
{
92
struct
fdc_data
*d;
93
94
CHECK_ALLOCATION
(d = (
struct
fdc_data
*) malloc(
sizeof
(
struct
fdc_data
)));
95
memset(d, 0,
sizeof
(
struct
fdc_data
));
96
97
INTERRUPT_CONNECT
(
devinit
->
interrupt_path
, d->
irq
);
98
99
memory_device_register
(
devinit
->
machine
->
memory
,
devinit
->
name
,
100
devinit
->
addr
,
DEV_FDC_LENGTH
, dev_fdc_access, d,
101
DM_DEFAULT
, NULL);
102
103
return
1;
104
}
105
memory_readmax64
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition:
memory.cc:55
fatal
void fatal(const char *fmt,...)
Definition:
main.cc:152
DM_DEFAULT
#define DM_DEFAULT
Definition:
memory.h:130
fdc_data::irq
struct interrupt irq
Definition:
dev_fdc.cc:54
memory.h
misc.h
devinit::name
char * name
Definition:
device.h:43
MEM_READ
#define MEM_READ
Definition:
memory.h:116
machine::memory
struct memory * memory
Definition:
machine.h:126
DEVINIT
DEVINIT(fdc)
Definition:
dev_fdc.cc:90
CHECK_ALLOCATION
#define CHECK_ALLOCATION(ptr)
Definition:
misc.h:239
data
u_short data
Definition:
siireg.h:79
MEM_WRITE
#define MEM_WRITE
Definition:
memory.h:117
fdc_data::reg
uint8_t reg[DEV_FDC_LENGTH]
Definition:
dev_fdc.cc:53
devinit
Definition:
device.h:40
DEVICE_ACCESS
DEVICE_ACCESS(fdc)
Definition:
dev_fdc.cc:58
interrupt.h
DEV_FDC_LENGTH
#define DEV_FDC_LENGTH
Definition:
dev_fdc.cc:49
INTERRUPT_CONNECT
#define INTERRUPT_CONNECT(name, istruct)
Definition:
interrupt.h:77
cpu
Definition:
cpu.h:326
devinit::machine
struct machine * machine
Definition:
device.h:41
memory_writemax64
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition:
memory.cc:89
memory_device_register
void memory_device_register(struct memory *mem, const char *, uint64_t baseaddr, uint64_t len, int(*f)(struct cpu *, struct memory *, uint64_t, unsigned char *, size_t, int, void *), void *extra, int flags, unsigned char *dyntrans_data)
Definition:
memory.cc:339
device.h
devinit::addr
uint64_t addr
Definition:
device.h:46
fdc_data
Definition:
dev_fdc.cc:52
machine.h
interrupt
Definition:
interrupt.h:36
devinit::interrupt_path
char * interrupt_path
Definition:
device.h:50
Generated on Fri Dec 7 2018 19:52:23 for GXemul by
1.8.13