forked from badman12345/osmose-rpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVDP.h
139 lines (119 loc) · 4.91 KB
/
VDP.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*****************************************************************************
*
* File: VDP_GG.h
*
* Project: Osmose emulator.
*
* Description: This class will handle SMS's VDP (Video Display Processor)operation.
*
* Author: Vedder Bruno
* Date: 25/10/2006, 19h15
*
* URL: http://bcz.emu-france.com/
*****************************************************************************/
#ifndef VDP_H
#define VDP_H
#include "Definitions.h"
#include <SDL/SDL.h>
#include <iomanip>
#include <iostream>
#include "Bits.h"
#include "Options.h"
#include "./cpu/Z80.h"
#include "DebugEventThrower.h"
#include "SaveState.h"
using namespace std;
extern EmulatorOptions emu_opt;
/* Uncomment this to display sprites */
#define DISPLAY_SPRITES
#define VDP_REGISTER_NBR 16
/* Destination component when data port is written */
#define D_VRAM 0
#define D_CRAM 1
#define REG0 regs [0]
#define REG1 regs [1]
#define REG2 regs [2]
#define REG3 regs [3]
#define REG4 regs [4]
#define REG5 regs [5]
#define REG6 regs [6]
#define REG7 regs [7]
#define REG8 regs [8]
#define REG9 regs [9]
#define REG10 regs [10]
/*Uncomment this to have VDP access trace */
//#define VDP_VERBOSE
typedef struct
{
unsigned short map_addr;
unsigned short sit_addr;
unsigned char regs[VDP_REGISTER_NBR];
unsigned char vdp_status;
unsigned char v_counter;
int line;
unsigned char i_counter;
unsigned char rd_data_port_buffer;
bool irq_line_pending;
bool vsynch_irq_pending;
bool sms_irq;
unsigned char latch;
unsigned short addr;
unsigned char cmd_type;
bool cmd_flag;
} VDPSaveState;
class VDP : public DebugEventThrower, public ImplementsSaveState
{
public:
VDP(Z80 *c,bool ntsc);
virtual ~VDP(){};
virtual void writeDataPort(unsigned char data); // Port 0xBE written (overriden VDP_GG).
unsigned char readDataPort(); // Port 0xBE read.
void writeCtrlPort(unsigned char data); // Port 0xBF/0xBD written.
unsigned char readStatusFlag(); // Port 0xBF/0xBD read.
void reset(); // reset VDP.
void dumpVRAM(unsigned int, int nb_lines); // Dump VDP VRAM.
void dumpCRAM(); // Dump VDP CRAM.
void update(SDL_Surface *s, bool drawline); // Update VDP.
unsigned short getVRAMAddr(); // Get VDP pointer.
bool getIrqLinePending() {return irq_line_pending;}
unsigned short line_buffer [256]; // Line buffer for tile/sprite priority.
unsigned char tile_mask [256]; // Pixels above sprites are marked here.
unsigned char spr_col [256]; // Use for sprite collision.
unsigned short *colors; // For on fly color conversion.
unsigned char *VRAM; // Video memory.
unsigned char *CRAM; // Color RAM.
unsigned short map_addr; // Where in vram is tilemap.
unsigned short sit_addr; // for sprite info. table.
unsigned char regs[VDP_REGISTER_NBR]; // VDP Registers.
unsigned char vdp_status; // used with portBF read.
unsigned char v_counter; // Vertical scanline ctr.
unsigned char *v_cnt; // point ntsc/pal vcount values.
int line; // Line actualy drawn.
unsigned char i_counter; // Interrupt Line counter.
unsigned char rd_data_port_buffer; // Buffer used in read data port.
bool irq_line_pending;
bool vsynch_irq_pending;
bool irqAsserted() {return sms_irq;}
bool irq_accepted;
/* Implemetntation of ImplementsSaveState. */
bool saveState( ofstream &ofs);
bool loadState( ifstream &ifs);
protected:
unsigned char latch; // Latch for address.
unsigned short addr; // VDP address pointer.
unsigned char cmd_type; // VRAM Wr/Rd, VDP Wr Reg or CRAM Wr.
bool cmd_flag; // Flag for 2 bytes cmd.
unsigned char r_col[4]; // Precalc Red possible values.
unsigned char g_col[4]; // Precalc Green possible values.
unsigned char b_col[4]; // Precalc Blue possible values.
void updateIRQAssertion();
void writeRegs(unsigned char r,unsigned char v); // Called on write regs.
virtual void traceBackGroundLine(SDL_Surface *s); // Draw one line.
void displaySpritesLine(); // Used in traceBackGroundLine.
unsigned short colorSMS8BitsToColor16Bits(unsigned char c); // Color convertor Helper.
unsigned short colorGG12BitsToColor16Bits(unsigned short data);
private:
bool sms_irq; // Set when VDP gen. an irq.
Z80 *cpu;
};
#endif