1 /*  Copyright 2003-2005 Guillaume Duhamel
2     Copyright 2004-2006 Theo Berkau
3 
4     This file is part of Yabause.
5 
6     Yabause is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     Yabause is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with Yabause; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19 */
20 
21 #ifndef VDP1_H
22 #define VDP1_H
23 
24 #include "memory.h"
25 
26 #define VIDCORE_DEFAULT         -1
27 #define VIDCORE_DUMMY           0
28 
29 typedef struct {
30    u16 TVMR;
31    u16 FBCR;
32    u16 PTMR;
33    u16 EWDR;
34    u16 EWLR;
35    u16 EWRR;
36    u16 ENDR;
37    u16 EDSR;
38    u16 LOPR;
39    u16 COPR;
40    u16 MODR;
41 
42    u32 addr;
43    int disptoggle_dont_use_me; // not used anymore, see Vdp1External_struct
44 
45    s16 localX;
46    s16 localY;
47 
48    u16 systemclipX1;
49    u16 systemclipY1;
50    u16 systemclipX2;
51    u16 systemclipY2;
52 
53    u16 userclipX1;
54    u16 userclipY1;
55    u16 userclipX2;
56    u16 userclipY2;
57 } Vdp1;
58 
59 typedef struct
60 {
61    int id;
62    const char *Name;
63    int (*Init)(void);
64    void (*DeInit)(void);
65    void (*Resize)(unsigned int, unsigned int, int);
66    int (*IsFullscreen)(void);
67    // VDP1 specific
68    int (*Vdp1Reset)(void);
69    void (*Vdp1DrawStart)(void);
70    void (*Vdp1DrawEnd)(void);
71    void(*Vdp1NormalSpriteDraw)(u8 * ram, Vdp1 * regs, u8 * back_framebuffer);
72    void(*Vdp1ScaledSpriteDraw)(u8 * ram, Vdp1 * regs, u8 * back_framebuffer);
73    void(*Vdp1DistortedSpriteDraw)(u8 * ram, Vdp1 * regs, u8 * back_framebuffer);
74    void(*Vdp1PolygonDraw)(u8 * ram, Vdp1 * regs, u8 * back_framebuffer);
75    void(*Vdp1PolylineDraw)(u8 * ram, Vdp1 * regs, u8 * back_framebuffer);
76    void(*Vdp1LineDraw)(u8 * ram, Vdp1 * regs, u8 * back_framebuffer);
77    void(*Vdp1UserClipping)(u8 * ram, Vdp1 * regs);
78    void(*Vdp1SystemClipping)(u8 * ram, Vdp1 * regs);
79    void(*Vdp1LocalCoordinate)(u8 * ram, Vdp1 * regs);
80    void(*Vdp1ReadFrameBuffer)(u32 type, u32 addr, void * out);
81    void(*Vdp1WriteFrameBuffer)(u32 type, u32 addr, u32 val);
82    // VDP2 specific
83    int (*Vdp2Reset)(void);
84    void (*Vdp2DrawStart)(void);
85    void (*Vdp2DrawEnd)(void);
86    void (*Vdp2DrawScreens)(void);
87    void (*GetGlSize)(int *width, int *height);
88    void (*GetNativeResolution)(int *width, int *height, int * interlace);
89    void(*Vdp2DispOff)(void);
90 } VideoInterface_struct;
91 
92 extern VideoInterface_struct *VIDCore;
93 extern VideoInterface_struct VIDDummy;
94 
95 extern u8 * Vdp1Ram;
96 
97 u8 FASTCALL	Vdp1RamReadByte(u32);
98 u16 FASTCALL	Vdp1RamReadWord(u32);
99 u32 FASTCALL	Vdp1RamReadLong(u32);
100 void FASTCALL	Vdp1RamWriteByte(u32, u8);
101 void FASTCALL	Vdp1RamWriteWord(u32, u16);
102 void FASTCALL	Vdp1RamWriteLong(u32, u32);
103 u8 FASTCALL Vdp1FrameBufferReadByte(u32);
104 u16 FASTCALL Vdp1FrameBufferReadWord(u32);
105 u32 FASTCALL Vdp1FrameBufferReadLong(u32);
106 void FASTCALL Vdp1FrameBufferWriteByte(u32, u8);
107 void FASTCALL Vdp1FrameBufferWriteWord(u32, u16);
108 void FASTCALL Vdp1FrameBufferWriteLong(u32, u32);
109 
110 u8 FASTCALL	Sh2Vdp1RamReadByte(SH2_struct *sh, u32);
111 u16 FASTCALL	Sh2Vdp1RamReadWord(SH2_struct *sh, u32);
112 u32 FASTCALL	Sh2Vdp1RamReadLong(SH2_struct *sh, u32);
113 void FASTCALL	Sh2Vdp1RamWriteByte(SH2_struct *sh, u32, u8);
114 void FASTCALL	Sh2Vdp1RamWriteWord(SH2_struct *sh, u32, u16);
115 void FASTCALL	Sh2Vdp1RamWriteLong(SH2_struct *sh, u32, u32);
116 u8 FASTCALL Sh2Vdp1FrameBufferReadByte(SH2_struct *sh, u32);
117 u16 FASTCALL Sh2Vdp1FrameBufferReadWord(SH2_struct *sh, u32);
118 u32 FASTCALL Sh2Vdp1FrameBufferReadLong(SH2_struct *sh, u32);
119 void FASTCALL Sh2Vdp1FrameBufferWriteByte(SH2_struct *sh, u32, u8);
120 void FASTCALL Sh2Vdp1FrameBufferWriteWord(SH2_struct *sh, u32, u16);
121 void FASTCALL Sh2Vdp1FrameBufferWriteLong(SH2_struct *sh, u32, u32);
122 
123 void Vdp1DrawCommands(u8 * ram, Vdp1 * regs, u8* back_framebuffer);
124 void Vdp1FakeDrawCommands(u8 * ram, Vdp1 * regs);
125 
126 extern Vdp1 * Vdp1Regs;
127 
128 // struct for Vdp1 part that shouldn't be saved
129 typedef struct {
130    int disptoggle;
131    int manualerase;
132    int manualchange;
133 } Vdp1External_struct;
134 
135 extern Vdp1External_struct Vdp1External;
136 
137 typedef struct
138 {
139    u16 CMDCTRL;
140    u16 CMDLINK;
141    u16 CMDPMOD;
142    u16 CMDCOLR;
143    u16 CMDSRCA;
144    u16 CMDSIZE;
145    s16 CMDXA;
146    s16 CMDYA;
147    s16 CMDXB;
148    s16 CMDYB;
149    s16 CMDXC;
150    s16 CMDYC;
151    s16 CMDXD;
152    s16 CMDYD;
153    u16 CMDGRDA;
154 } vdp1cmd_struct;
155 
156 int Vdp1Init(void);
157 void Vdp1DeInit(void);
158 int VideoInit(int coreid);
159 int VideoChangeCore(int coreid);
160 void VideoDeInit(void);
161 void Vdp1Reset(void);
162 
163 u8 FASTCALL	Vdp1ReadByte(u32);
164 u16 FASTCALL	Vdp1ReadWord(u32);
165 u32 FASTCALL	Vdp1ReadLong(u32);
166 void FASTCALL	Vdp1WriteByte(u32, u8);
167 void FASTCALL	Vdp1WriteWord(u32, u16);
168 void FASTCALL	Vdp1WriteLong(u32, u32);
169 
170 u8 FASTCALL	Sh2Vdp1ReadByte(SH2_struct *, u32);
171 u16 FASTCALL	Sh2Vdp1ReadWord(SH2_struct *, u32);
172 u32 FASTCALL	Sh2Vdp1ReadLong(SH2_struct *, u32);
173 void FASTCALL	Sh2Vdp1WriteByte(SH2_struct *, u32, u8);
174 void FASTCALL	Sh2Vdp1WriteWord(SH2_struct *, u32, u16);
175 void FASTCALL	Sh2Vdp1WriteLong(SH2_struct *, u32, u32);
176 
177 void Vdp1Draw(void);
178 void Vdp1NoDraw(void);
179 void FASTCALL Vdp1ReadCommand(vdp1cmd_struct *cmd, u32 addr, u8* ram);
180 
181 int Vdp1SaveState(FILE *fp);
182 int Vdp1LoadState(FILE *fp, int version, int size);
183 
184 void Vdp1DebugGetCommandNumberName(u32 number, char *outstring);
185 void Vdp1DebugCommand(u32 number, char *outstring);
186 u32 *Vdp1DebugTexture(u32 number, int *w, int *h);
187 void ToggleVDP1(void);
188 
189 void VideoDisableGL(void);
190 
191 #endif
192