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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
// license:BSD-3-Clause
// copyright-holders:Wilbert Pol
/*****************************************************************************
*
* includes/gb.h
*
****************************************************************************/
#ifndef MAME_INCLUDES_GB_H
#define MAME_INCLUDES_GB_H
#pragma once
#include "sound/gb.h"
#include "cpu/lr35902/lr35902.h"
#include "bus/gameboy/gb_slot.h"
#include "machine/ram.h"
#include "video/gb_lcd.h"
#include "emupal.h"
class gb_state : public driver_device
{
public:
gb_state(const machine_config &mconfig, device_type type, const char *tag) :
driver_device(mconfig, type, tag),
m_cartslot(*this, "gbslot"),
m_maincpu(*this, "maincpu"),
m_apu(*this, "apu"),
m_region_maincpu(*this, "maincpu"),
m_rambank(*this, "cgb_ram"),
m_inputs(*this, "INPUTS"),
m_bios_hack(*this, "SKIP_CHECK"),
m_ram(*this, RAM_TAG),
m_ppu(*this, "ppu"),
m_palette(*this, "palette"),
m_cart_low(*this, "cartlow"),
m_cart_high(*this, "carthigh")
{ }
uint8_t m_gb_io[0x10]{};
/* Timer related */
uint16_t m_divcount = 0;
uint8_t m_shift = 0;
uint16_t m_shift_cycles = 0;
uint8_t m_triggering_irq = 0;
uint8_t m_reloading = 0;
/* Serial I/O related */
uint16_t m_internal_serial_clock = 0;
uint16_t m_internal_serial_frequency = 0;
uint32_t m_sio_count = 0; /* Serial I/O counter */
/* SGB variables */
int8_t m_sgb_packets = 0;
uint8_t m_sgb_bitcount = 0;
uint8_t m_sgb_bytecount = 0;
uint8_t m_sgb_start = 0;
uint8_t m_sgb_rest = 0;
uint8_t m_sgb_controller_no = 0;
uint8_t m_sgb_controller_mode = 0;
uint8_t m_sgb_data[0x100]{};
/* CGB variables */
uint8_t *m_gbc_rammap[8]{}; /* (CGB) Addresses of internal RAM banks */
uint8_t m_gbc_rambank = 0; /* (CGB) Current CGB RAM bank */
void gb_io_w(offs_t offset, uint8_t data);
void gb_io2_w(offs_t offset, uint8_t data);
void sgb_io_w(offs_t offset, uint8_t data);
uint8_t gb_ie_r();
void gb_ie_w(uint8_t data);
uint8_t gb_io_r(offs_t offset);
void gbc_io_w(offs_t offset, uint8_t data);
void gbc_io2_w(offs_t offset, uint8_t data);
uint8_t gbc_io2_r(offs_t offset);
void gb_palette(palette_device &palette) const;
DECLARE_MACHINE_START(sgb);
DECLARE_MACHINE_RESET(sgb);
void sgb_palette(palette_device &palette) const;
void gbp_palette(palette_device &palette) const;
DECLARE_MACHINE_START(gbc);
DECLARE_MACHINE_RESET(gbc);
void gbc_palette(palette_device &palette) const;
void gb_timer_callback(uint8_t data);
uint8_t gb_bios_r(offs_t offset);
optional_device<gb_cart_slot_device> m_cartslot;
void supergb(machine_config &config);
void supergb2(machine_config &config);
void gbcolor(machine_config &config);
void gbpocket(machine_config &config);
void gameboy(machine_config &config);
void gameboy_map(address_map &map);
void gbc_map(address_map &map);
void sgb_map(address_map &map);
protected:
enum {
SIO_ENABLED = 0x80,
SIO_FAST_CLOCK = 0x02,
SIO_INTERNAL_CLOCK = 0x01
};
static constexpr u8 NO_CART = 0x00;
static constexpr u8 BIOS_ENABLED = 0x00;
static constexpr u8 CART_PRESENT = 0x01;
static constexpr u8 BIOS_DISABLED = 0x02;
required_device<lr35902_cpu_device> m_maincpu;
required_device<gameboy_sound_device> m_apu;
required_memory_region m_region_maincpu;
optional_memory_bank m_rambank; // cgb
required_ioport m_inputs;
required_ioport m_bios_hack;
optional_device<ram_device> m_ram;
required_device<dmg_ppu_device> m_ppu;
required_device<palette_device> m_palette;
memory_view m_cart_low;
memory_view m_cart_high;
void gb_timer_increment();
void gb_timer_check_irq();
void gb_init();
void gb_init_regs();
void gb_serial_timer_tick();
void save_gb_base();
void save_gbc_only();
void save_sgb_only();
virtual void machine_start() override;
virtual void machine_reset() override;
};
class megaduck_state : public gb_state
{
public:
megaduck_state(const machine_config &mconfig, device_type type, const char *tag) :
gb_state(mconfig, type, tag),
m_cartslot(*this, "duckslot")
{ }
void megaduck(machine_config &config);
protected:
virtual void machine_start() override;
virtual void machine_reset() override;
private:
uint8_t megaduck_video_r(offs_t offset);
void megaduck_video_w(offs_t offset, uint8_t data);
void megaduck_sound_w1(offs_t offset, uint8_t data);
uint8_t megaduck_sound_r1(offs_t offset);
void megaduck_sound_w2(offs_t offset, uint8_t data);
uint8_t megaduck_sound_r2(offs_t offset);
void megaduck_palette(palette_device &palette) const;
void megaduck_map(address_map &map);
required_device<megaduck_cart_slot_device> m_cartslot;
};
#endif // MAME_INCLUDES_GB_H
|