dev_ps2_gs.cc Source File
Back to the index.
src
devices
dev_ps2_gs.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: PlayStation 2 graphics system
29
*/
30
31
#include <stdio.h>
32
#include <stdlib.h>
33
#include <string.h>
34
35
#include "
device.h
"
36
#include "
machine.h
"
37
#include "
memory.h
"
38
#include "
misc.h
"
39
40
41
#define DEV_PS2_GS_LENGTH 0x2000
42
43
/* NOTE/TODO: This should be the same as in ps2_stuff: */
44
#define DEV_PS2_GIF_FAKE_BASE 0x50000000
45
46
#define N_GS_REGS 0x108
47
48
struct
gs_data
{
49
uint64_t
reg
[
N_GS_REGS
];
/* GS registers */
50
};
51
52
#define GS_S_PMODE_REG 0x00
53
#define GS_S_SMODE1_REG 0x01
54
#define GS_S_SMODE2_REG 0x02
55
#define GS_S_SRFSH_REG 0x03
56
#define GS_S_SYNCH1_REG 0x04
57
#define GS_S_SYNCH2_REG 0x05
58
#define GS_S_SYNCV_REG 0x06
59
#define GS_S_DISPFB1_REG 0x07
60
#define GS_S_DISPLAY1_REG 0x08
61
#define GS_S_DISPFB2_REG 0x09
62
#define GS_S_DISPLAY2_REG 0x0a
63
#define GS_S_EXTBUF_REG0 0x0b
64
#define GS_S_EXTDATA_REG 0x0c
65
#define GS_S_EXTWRITE_REG 0x0d
66
#define GS_S_BGCOLOR_REG 0x0e
67
68
//static const char *gs_reg_names[15] = {
69
// "PMODE", "SMODE1", "SMODE2", "SRFSH",
70
// "SYNCH1", "SYNCH2", "SYNCV", "DISPFB1",
71
// "DISPLAY1", "DISPFB2", "DISPLAY2", "EXTBUF",
72
// "EXTDATA", "EXTWRITE", "BGCOLOR" };
73
74
#define GS_S_CSR_REG 0x100
75
#define GS_S_IMR_REG 0x101
76
#define GS_S_BUSDIR_REG 0x104
77
#define GS_S_SIGLBLID_REG 0x108
78
79
//static const char *gs_reg_high_names[4] = {
80
// "CSR", "IMR", "BUSDIR", "SIGLBLID"
81
// };
82
83
84
DEVICE_ACCESS
(ps2_gs)
85
{
86
struct
gs_data
*d = (
struct
gs_data
*) extra;
87
uint64_t idata = 0, odata = 0;
88
size_t
i;
89
int
regnr;
90
91
if
(writeflag ==
MEM_WRITE
)
92
idata =
memory_readmax64
(
cpu
,
data
, len);
93
94
regnr = relative_addr / 16;
95
if
(relative_addr & 0xf) {
96
debug
(
"[ gs unaligned access, addr 0x%x ]\n"
,
97
(
int
)relative_addr);
98
return
0;
99
}
100
101
/* Empty the GS FIFO: */
102
d->
reg
[
GS_S_CSR_REG
] &= ~(3 << 14);
103
d->
reg
[
GS_S_CSR_REG
] |= (1 << 14);
104
105
switch
(relative_addr) {
106
default
:
107
if
(writeflag==
MEM_READ
) {
108
debug
(
"[ gs read from addr 0x%x ]\n"
,
109
(
int
)relative_addr);
110
odata = d->
reg
[regnr];
111
}
else
{
112
debug
(
"[ gs write to addr 0x%x:"
, (
int
)relative_addr);
113
for
(i=0; i<len; i++)
114
debug
(
" %02x"
,
data
[i]);
115
debug
(
" ]\n"
);
116
d->
reg
[regnr] = idata;
117
return
1;
118
}
119
}
120
121
if
(writeflag ==
MEM_READ
)
122
memory_writemax64
(
cpu
,
data
, len, odata);
123
124
return
1;
125
}
126
127
128
/*
129
* devinit_ps2_gs():
130
*
131
* Initialize the Playstation 2 graphics system. This is a bit tricky.
132
* 'gs' is the memory mapped device, as seen by the main processor.
133
* 'gif' is another thing which has its own memory. DMA is used to
134
* transfer stuff to the gif from the main memory.
135
* There is also a framebuffer, which is separated from the main
136
* memory.
137
*
138
* TODO: Make this clearer.
139
*/
140
DEVINIT
(ps2_gs)
141
{
142
struct
gs_data
*d;
143
char
str[100];
144
145
CHECK_ALLOCATION
(d = (
struct
gs_data
*) malloc(
sizeof
(
struct
gs_data
)));
146
memset(d, 0,
sizeof
(
struct
gs_data
));
147
148
snprintf(str,
sizeof
(str) - 1,
"ps2_gif addr=0x%llx"
,
149
(
long
long
)
DEV_PS2_GIF_FAKE_BASE
);
150
device_add
(
devinit
->
machine
, str);
151
152
memory_device_register
(
devinit
->
machine
->
memory
,
devinit
->
name
,
153
devinit
->
addr
,
DEV_PS2_GS_LENGTH
, dev_ps2_gs_access, d,
154
DM_DEFAULT
, NULL);
155
156
return
1;
157
}
158
data
u_short data
Definition:
siireg.h:79
DEVICE_ACCESS
DEVICE_ACCESS(ps2_gs)
Definition:
dev_ps2_gs.cc:84
gs_data::reg
uint64_t reg[N_GS_REGS]
Definition:
dev_ps2_gs.cc:49
DEV_PS2_GS_LENGTH
#define DEV_PS2_GS_LENGTH
Definition:
dev_ps2_gs.cc:41
debug
#define debug
Definition:
dev_adb.cc:57
devinit::addr
uint64_t addr
Definition:
device.h:46
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
MEM_READ
#define MEM_READ
Definition:
memory.h:116
DEV_PS2_GIF_FAKE_BASE
#define DEV_PS2_GIF_FAKE_BASE
Definition:
dev_ps2_gs.cc:44
DM_DEFAULT
#define DM_DEFAULT
Definition:
memory.h:130
devinit::machine
struct machine * machine
Definition:
device.h:41
device.h
N_GS_REGS
#define N_GS_REGS
Definition:
dev_ps2_gs.cc:46
MEM_WRITE
#define MEM_WRITE
Definition:
memory.h:117
misc.h
memory_readmax64
uint64_t memory_readmax64(struct cpu *cpu, unsigned char *buf, int len)
Definition:
memory.cc:55
device_add
void * device_add(struct machine *machine, const char *name_and_params)
Definition:
device.cc:252
machine.h
GS_S_CSR_REG
#define GS_S_CSR_REG
Definition:
dev_ps2_gs.cc:74
devinit::name
char * name
Definition:
device.h:43
devinit
Definition:
device.h:40
machine::memory
struct memory * memory
Definition:
machine.h:126
gs_data
Definition:
dev_ps2_gs.cc:48
memory_writemax64
void memory_writemax64(struct cpu *cpu, unsigned char *buf, int len, uint64_t data)
Definition:
memory.cc:89
DEVINIT
DEVINIT(ps2_gs)
Definition:
dev_ps2_gs.cc:140
cpu
Definition:
cpu.h:326
memory.h
CHECK_ALLOCATION
#define CHECK_ALLOCATION(ptr)
Definition:
misc.h:239
Generated on Tue Aug 25 2020 19:25:06 for GXemul by
1.8.18