1 // license:BSD-3-Clause
2 // copyright-holders:Curt Coder
3 /**********************************************************************
4
5 Data 20 Corporation Video Pak cartridge emulation
6 aka Data 20 Display Manager aka Protecto 40/80
7
8 **********************************************************************/
9
10 #include "emu.h"
11 #include "videopak.h"
12
13 #include "screen.h"
14
15
16
17 //**************************************************************************
18 // MACROS/CONSTANTS
19 //**************************************************************************
20
21 #define VIDEORAM_SIZE 0x800
22 #define RAM_SIZE 0x10000
23
24 #define MC6845_TAG "mc6845"
25 #define MC6845_SCREEN_TAG "screen80"
26
27
28
29 //**************************************************************************
30 // DEVICE DEFINITIONS
31 //**************************************************************************
32
33 DEFINE_DEVICE_TYPE(VIC20_VIDEO_PAK, vic20_video_pak_device, "vic20_videopak", "Data 20 Video Pak")
34
35
36 //-------------------------------------------------
37 // ROM( videopak )
38 //-------------------------------------------------
39
ROM_START(videopak)40 ROM_START( videopak )
41 ROM_REGION( 0x800, MC6845_TAG, 0 )
42 // ROM has been borrowed from the C64 XL80 cartridge
43 ROM_LOAD( "chargen", 0x000, 0x800, BAD_DUMP CRC(9edf5e58) SHA1(4b244e6d94a7653a2e52c351589f0b469119fb04) )
44 ROM_END
45
46
47 //-------------------------------------------------
48 // rom_region - device-specific ROM region
49 //-------------------------------------------------
50
51 const tiny_rom_entry *vic20_video_pak_device::device_rom_region() const
52 {
53 return ROM_NAME( videopak );
54 }
55
56 //-------------------------------------------------
57 // mc6845
58 //-------------------------------------------------
59
MC6845_UPDATE_ROW(vic20_video_pak_device::crtc_update_row)60 MC6845_UPDATE_ROW( vic20_video_pak_device::crtc_update_row )
61 {
62 const pen_t *pen = m_palette->pens();
63
64 for (int column = 0; column < x_count; column++)
65 {
66 uint8_t code = m_videoram[((ma + column) & 0x7ff)];
67 uint16_t addr = (code << 3) | (ra & 0x07);
68 uint8_t data = m_char_rom->base()[addr & 0x7ff];
69
70 if (column == cursor_x)
71 {
72 data = 0xff;
73 }
74
75 for (int bit = 0; bit < 8; bit++)
76 {
77 int x = (column * 8) + bit;
78 int color = BIT(data, 7) && de;
79
80 bitmap.pix(vbp + y, hbp + x) = pen[color];
81
82 data <<= 1;
83 }
84 }
85 }
86
87 //-------------------------------------------------
88 // GFXDECODE( vic20_video_pak )
89 //-------------------------------------------------
90
91 static GFXDECODE_START( gfx_vic20_video_pak )
92 GFXDECODE_ENTRY(MC6845_TAG, 0x0000, gfx_8x8x1, 0, 1)
93 GFXDECODE_END
94
95
96 //-------------------------------------------------
97 // device_add_mconfig - add device configuration
98 //-------------------------------------------------
99
device_add_mconfig(machine_config & config)100 void vic20_video_pak_device::device_add_mconfig(machine_config &config)
101 {
102 screen_device &screen(SCREEN(config, MC6845_SCREEN_TAG, SCREEN_TYPE_RASTER, rgb_t::white()));
103 screen.set_screen_update(MC6845_TAG, FUNC(mc6845_device::screen_update));
104 screen.set_size(80*8, 24*8);
105 screen.set_visarea(0, 80*8-1, 0, 24*8-1);
106 screen.set_refresh_hz(50);
107
108 GFXDECODE(config, "gfxdecode", m_palette, gfx_vic20_video_pak);
109 PALETTE(config, m_palette, palette_device::MONOCHROME);
110
111 MC6845(config, m_crtc, XTAL(14'318'181) / 8); // HD46505RP or similar
112 m_crtc->set_screen(MC6845_SCREEN_TAG);
113 m_crtc->set_show_border_area(true);
114 m_crtc->set_char_width(8);
115 m_crtc->set_update_row_callback(FUNC(vic20_video_pak_device::crtc_update_row));
116 }
117
118
119
120 //**************************************************************************
121 // LIVE DEVICE
122 //**************************************************************************
123
124 //-------------------------------------------------
125 // vic20_video_pak_device - constructor
126 //-------------------------------------------------
127
vic20_video_pak_device(const machine_config & mconfig,const char * tag,device_t * owner,uint32_t clock)128 vic20_video_pak_device::vic20_video_pak_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock) :
129 device_t(mconfig, VIC20_VIDEO_PAK, tag, owner, clock),
130 device_vic20_expansion_card_interface(mconfig, *this),
131 m_crtc(*this, MC6845_TAG),
132 m_palette(*this, "palette"),
133 m_char_rom(*this, MC6845_TAG),
134 m_videoram(*this, "videoram"),
135 m_ram(*this, "ram")
136 {
137 }
138
139
140 //-------------------------------------------------
141 // device_start - device-specific startup
142 //-------------------------------------------------
143
device_start()144 void vic20_video_pak_device::device_start()
145 {
146 // allocate memory
147 m_videoram.allocate(VIDEORAM_SIZE);
148 m_ram.allocate(RAM_SIZE);
149 }
150
151
152 //-------------------------------------------------
153 // device_reset - device-specific reset
154 //-------------------------------------------------
155
device_reset()156 void vic20_video_pak_device::device_reset()
157 {
158 }
159
160
161 //-------------------------------------------------
162 // vic20_cd_r - cartridge data read
163 //-------------------------------------------------
164
vic20_cd_r(offs_t offset,uint8_t data,int ram1,int ram2,int ram3,int blk1,int blk2,int blk3,int blk5,int io2,int io3)165 uint8_t vic20_video_pak_device::vic20_cd_r(offs_t offset, uint8_t data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3)
166 {
167 if (!m_ram_enable)
168 {
169 if (m_bank_size)
170 {
171 if (!blk1)
172 {
173 offs_t addr = m_bank_msb << 15 | m_bank_lsb << 14 | offset;
174 data = m_ram[addr];
175 }
176
177 if (!blk2)
178 {
179 offs_t addr = m_bank_msb << 15 | m_bank_lsb << 14 | 0x2000 | offset;
180 data = m_ram[addr];
181 }
182 }
183 else
184 {
185 if (!blk1)
186 {
187 offs_t addr = m_bank_msb << 15 | offset;
188 data = m_ram[addr];
189 }
190
191 if (!blk2)
192 {
193 offs_t addr = m_bank_msb << 15 | 0x2000 | offset;
194 data = m_ram[addr];
195 }
196
197 if (!blk3)
198 {
199 offs_t addr = m_bank_msb << 15 | 0x4000 | offset;
200 data = m_ram[addr];
201 }
202 }
203 }
204
205 if (!blk5)
206 {
207 switch ((offset >> 11) & 0x03)
208 {
209 case 0:
210 if (m_blk5)
211 data = m_blk5[offset & 0x7ff];
212 break;
213
214 case 3:
215 data = m_videoram[offset & 0x7ff];
216 break;
217 }
218 }
219
220 if (!io2)
221 {
222 if (offset == 0x1bf9)
223 {
224 data = m_crtc->register_r();
225 }
226 }
227
228 return data;
229 }
230
231
232 //-------------------------------------------------
233 // vic20_cd_w - cartridge data write
234 //-------------------------------------------------
235
vic20_cd_w(offs_t offset,uint8_t data,int ram1,int ram2,int ram3,int blk1,int blk2,int blk3,int blk5,int io2,int io3)236 void vic20_video_pak_device::vic20_cd_w(offs_t offset, uint8_t data, int ram1, int ram2, int ram3, int blk1, int blk2, int blk3, int blk5, int io2, int io3)
237 {
238 if (!m_ram_enable)
239 {
240 if (m_bank_size)
241 {
242 if (!blk1)
243 {
244 offs_t addr = m_bank_msb << 15 | m_bank_lsb << 14 | offset;
245
246 m_ram[addr] = data;
247 }
248
249 if (!blk2)
250 {
251 offs_t addr = m_bank_msb << 15 | m_bank_lsb << 14 | 0x2000 | offset;
252
253 m_ram[addr] = data;
254 }
255 }
256 else
257 {
258 if (!blk1)
259 {
260 offs_t addr = m_bank_msb << 15 | offset;
261
262 m_ram[addr] = data;
263 }
264
265 if (!blk2)
266 {
267 offs_t addr = m_bank_msb << 15 | 0x2000 | offset;
268
269 m_ram[addr] = data;
270 }
271
272 if (!blk3)
273 {
274 offs_t addr = m_bank_msb << 15 | 0x4000 | offset;
275
276 m_ram[addr] = data;
277 }
278 }
279 }
280
281 if (!blk5)
282 {
283 switch ((offset >> 11) & 0x03)
284 {
285 case 3:
286 m_videoram[offset & 0x7ff] = data;
287 break;
288 }
289 }
290
291 if (!io2)
292 {
293 switch (offset)
294 {
295 case 0x1bf8:
296 m_crtc->address_w(data);
297 break;
298
299 case 0x1bf9:
300 m_crtc->register_w(data);
301 break;
302
303 case 0x1bfc:
304 /*
305
306 bit description
307
308 0 0 = upper case, 1 = lower case
309 1 bank size: 0 = 2x24KB, 1 = 4x16KB
310 2 16KB mode address LSB
311 3 memory address MSB
312 4 0 = enable RAM, 1 = disable RAM
313 5 0 = 40 columns, 1 = 80 columns (Data 20 Video Manager)
314
315 */
316
317 m_case = BIT(data, 0);
318 m_bank_size = BIT(data, 1);
319 m_bank_lsb = BIT(data, 2);
320 m_bank_msb = BIT(data, 3);
321 m_ram_enable = BIT(data, 4);
322 m_columns = BIT(data, 5);
323 break;
324 }
325 }
326 }
327