1 /* the way I hooked up the CTC is most likely completely wrong */
2
3 #include "driver.h"
4 #include "vidhrdw/generic.h"
5 #include "machine/z80fmly.h"
6
7
8
9 /*
10 Dragon's Lair has two 7 segment LEDs on the board, used to report error
11 codes.
12 The association between the bits of the port and the led segments is:
13
14 ---0---
15 | |
16 5 1
17 | |
18 ---6---
19 | |
20 4 2
21 | |
22 ---3---
23
24 bit 7 = enable (0 = display off)
25
26 Error codes for led 0:
27 1 bad CPU
28 2 bad ROM
29 3 bad RAM a000-a7ff
30 4 bad RAM c000-c7ff
31 5 bad I/O ports 0-3
32 P ?
33 */
34
35 static int led0,led1;
36
WRITE_HANDLER(dlair_led0_w)37 WRITE_HANDLER( dlair_led0_w )
38 {
39 led0 = data;
40 }
WRITE_HANDLER(dlair_led1_w)41 WRITE_HANDLER( dlair_led1_w )
42 {
43 led1 = data;
44 }
45
dlair_vh_screenrefresh(struct osd_bitmap * bitmap,int full_refresh)46 void dlair_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
47 {
48 int offs;
49
50
51 /* for every character in the Video RAM, check if it has been modified */
52 /* since last time and update it accordingly. */
53 for (offs = videoram_size - 2;offs >= 0;offs-=2)
54 {
55 if (dirtybuffer[offs] || dirtybuffer[offs+1])
56 {
57 int sx,sy;
58
59
60 dirtybuffer[offs] = 0;
61 dirtybuffer[offs+1] = 0;
62
63 sx = (offs/2) % 32;
64 sy = (offs/2) / 32;
65
66 drawgfx(tmpbitmap,Machine->gfx[0],
67 videoram[offs+1],
68 0,
69 0,0,
70 8*sx,16*sy,
71 &Machine->visible_area,TRANSPARENCY_NONE,0);
72 }
73 }
74
75
76 /* copy the character mapped graphics */
77 copybitmap(bitmap,tmpbitmap,0,0,0,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
78
79 if (led0 & 128)
80 {
81 if ((led0 & 1) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
82 8,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
83 if ((led0 & 2) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
84 16,8,&Machine->visible_area,TRANSPARENCY_NONE,0);
85 if ((led0 & 4) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
86 16,24,&Machine->visible_area,TRANSPARENCY_NONE,0);
87 if ((led0 & 8) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
88 8,32,&Machine->visible_area,TRANSPARENCY_NONE,0);
89 if ((led0 & 16) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
90 0,24,&Machine->visible_area,TRANSPARENCY_NONE,0);
91 if ((led0 & 32) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
92 0,8,&Machine->visible_area,TRANSPARENCY_NONE,0);
93 if ((led0 & 64) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
94 8,16,&Machine->visible_area,TRANSPARENCY_NONE,0);
95 }
96 if (led1 & 128)
97 {
98 if ((led1 & 1) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
99 32+8,0,&Machine->visible_area,TRANSPARENCY_NONE,0);
100 if ((led1 & 2) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
101 32+16,8,&Machine->visible_area,TRANSPARENCY_NONE,0);
102 if ((led1 & 4) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
103 32+16,24,&Machine->visible_area,TRANSPARENCY_NONE,0);
104 if ((led1 & 8) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
105 32+8,32,&Machine->visible_area,TRANSPARENCY_NONE,0);
106 if ((led1 & 16) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
107 32+0,24,&Machine->visible_area,TRANSPARENCY_NONE,0);
108 if ((led1 & 32) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
109 32+0,8,&Machine->visible_area,TRANSPARENCY_NONE,0);
110 if ((led1 & 64) == 0) drawgfx(bitmap,Machine->uifont,'x',0,0,0,
111 32+8,16,&Machine->visible_area,TRANSPARENCY_NONE,0);
112 }
113 }
114
115
116
117 /* z80 ctc */
ctc_interrupt(int state)118 static void ctc_interrupt (int state)
119 {
120 cpu_cause_interrupt (0, Z80_VECTOR(0,state) );
121 }
122
123 static z80ctc_interface ctc_intf =
124 {
125 1, /* 1 chip */
126 { 0 }, /* clock (filled in from the CPU 0 clock */
127 { 0 }, /* timer disables */
128 { ctc_interrupt }, /* interrupt handler */
129 { 0 }, /* ZC/TO0 callback */
130 { 0 }, /* ZC/TO1 callback */
131 { 0 } /* ZC/TO2 callback */
132 };
133
134
dlair_init_machine(void)135 void dlair_init_machine(void)
136 {
137 /* initialize the CTC */
138 ctc_intf.baseclock[0] = Machine->drv->cpu[0].cpu_clock;
139 z80ctc_init(&ctc_intf);
140 }
141
142
143 static struct MemoryReadAddress readmem[] =
144 {
145 { 0x0000, 0x7fff, MRA_ROM },
146 { 0xa000, 0xa7ff, MRA_RAM },
147 { 0xc000, 0xc7ff, MRA_RAM },
148 { -1 } /* end of table */
149 };
150
151 static struct MemoryWriteAddress writemem[] =
152 {
153 { 0x0000, 0x7fff, MWA_ROM },
154 { 0xa000, 0xa7ff, MWA_RAM },
155 { 0xc000, 0xc3ff, videoram_w, &videoram, &videoram_size },
156 { 0xc400, 0xc7ff, MWA_RAM },
157 { 0xe000, 0xe000, dlair_led0_w },
158 { 0xe008, 0xe008, dlair_led1_w },
159 { 0xe030, 0xe030, watchdog_reset_w },
160 { -1 } /* end of table */
161 };
162
163 static unsigned char pip[4];
READ_HANDLER(pip_r)164 static READ_HANDLER( pip_r )
165 {
166 //logerror("PC %04x: read I/O port %02x\n",cpu_get_pc(),offset);
167 return pip[offset];
168 }
WRITE_HANDLER(pip_w)169 static WRITE_HANDLER( pip_w )
170 {
171 //logerror("PC %04x: write %02x to I/O port %02x\n",cpu_get_pc(),data,offset);
172 pip[offset] = data;
173 z80ctc_0_w(offset,data);
174 }
175
176 static struct IOReadPort readport[] =
177 {
178 { 0x00, 0x03, pip_r },
179 // { 0x80, 0x83, z80ctc_0_r },
180 { -1 } /* end of table */
181 };
182
183 static struct IOWritePort writeport[] =
184 {
185 { 0x00, 0x03, pip_w },
186 // { 0x80, 0x83, z80ctc_0_w },
187 { -1 } /* end of table */
188 };
189
190
191
192 INPUT_PORTS_START( dlair )
193 PORT_START
194 INPUT_PORTS_END
195
196
197
198 static struct GfxLayout charlayout =
199 {
200 8,16,
201 512,
202 1,
203 { 0 },
204 { 7, 6, 5, 4, 3, 2, 1, 0 },
205 { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
206 8*8, 9*8, 10*8, 11*8, 12*8, 13*8, 14*8, 15*8 },
207 16*8 /* every char takes 8 consecutive bytes */
208 };
209
210
211 static struct GfxDecodeInfo gfxdecodeinfo[] =
212 {
213 { REGION_GFX1, 0x0000, &charlayout, 0, 8 },
214 { -1 } /* end of array */
215 };
216
217
218
219 static Z80_DaisyChain daisy_chain[] =
220 {
221 { z80ctc_reset, z80ctc_interrupt, z80ctc_reti, 0 }, /* CTC number 0 */
222 { 0,0,0,-1} /* end mark */
223 };
224
225
226
227 static struct MachineDriver machine_driver_dlair =
228 {
229 /* basic machine hardware */
230 {
231 {
232 CPU_Z80,
233 3072000, /* 3.072 Mhz ? */
234 readmem,writemem,readport,writeport,
235 0,0, /* interrupts are made by z80 daisy chain system */
236 0,0,daisy_chain
237 }
238 },
239 60, DEFAULT_60HZ_VBLANK_DURATION, /* frames per second, vblank duration */
240 1, /* single CPU, no need for interleaving */
241 dlair_init_machine,
242
243 /* video hardware */
244 32*8, 32*8, { 0*8, 32*8-1, 0*8, 32*8-1 },
245 gfxdecodeinfo,
246 8,8,
247 0,
248
249 VIDEO_TYPE_RASTER|VIDEO_SUPPORTS_DIRTY,
250 0,
251 generic_vh_start,
252 generic_vh_stop,
253 dlair_vh_screenrefresh,
254
255 /* sound hardware */
256 0,0,0,0,
257 };
258
259
260
261 /***************************************************************************
262
263 Game driver(s)
264
265 ***************************************************************************/
266
267 ROM_START( dlair )
268 ROM_REGION( 0x10000, REGION_CPU1 ) /* 64k for code */
269 ROM_LOAD( "u45", 0x0000, 0x2000, 0x329b354a )
270 ROM_LOAD( "u46", 0x2000, 0x2000, 0x8479612b )
271 ROM_LOAD( "u47", 0x4000, 0x2000, 0x6a66f6b4 )
272 ROM_LOAD( "u48", 0x6000, 0x2000, 0x36575106 )
273
274 ROM_REGION( 0x2000, REGION_GFX1 | REGIONFLAG_DISPOSE )
275 ROM_LOAD( "u33", 0x0000, 0x2000, 0xe7506d96 )
276 ROM_END
277
278
279
280 GAMEX( 1983, dlair, 0, dlair, dlair, 0, ROT0, "Cinematronics", "Dragon's Lair", GAME_NOT_WORKING )
281
282