Previous 15994 Revisions Next

r11000 Thursday 31st March, 2011 at 05:59:10 UTC by Curt Coder
[MC1000] Modernized driver.
[src/mess/drivers]mc1000.c
[src/mess/includes]mc1000.h

src/mess/includes/mc1000.h
r10999r11000
11#ifndef __MC1000__
22#define __MC1000__
33
4#define ADDRESS_MAP_MODERN
5
6#include "emu.h"
7#include "cpu/z80/z80.h"
8#include "imagedev/cassette.h"
9#include "video/m6847.h"
10#include "sound/ay8910.h"
11#include "machine/ctronics.h"
12#include "machine/rescap.h"
13#include "machine/ram.h"
14
415#define SCREEN_TAG      "screen"
516#define Z80_TAG         "u13"
617#define AY8910_TAG      "u21"
r10999r11000
1627{
1728public:
1829   mc1000_state(running_machine &machine, const driver_device_config_base &config)
19      : driver_device(machine, config) { }
30      : driver_device(machine, config),
31        m_maincpu(*this, Z80_TAG),
32        m_crtc0(*this, MC6847_TAG),
33        m_crtc1(*this, MC6845_TAG),
34        m_centronics(*this, CENTRONICS_TAG),
35        m_cassette(*this, CASSETTE_TAG),
36        m_ram(*this, RAM_TAG)
37   { }
2038
39   required_device<cpu_device> m_maincpu;
40   required_device<device_t> m_crtc0;
41   optional_device<device_t> m_crtc1;
42   required_device<device_t> m_centronics;
43   required_device<device_t> m_cassette;
44   required_device<device_t> m_ram;
45
46   virtual void machine_start();
47   virtual void machine_reset();
48
49   virtual bool screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect);
50
51   DECLARE_READ8_MEMBER( printer_r );
52   DECLARE_WRITE8_MEMBER( printer_w );
53   DECLARE_WRITE8_MEMBER( mc6845_ctrl_w );
54   DECLARE_WRITE8_MEMBER( mc6847_attr_w );
55   DECLARE_WRITE_LINE_MEMBER( fs_w );
56   DECLARE_WRITE_LINE_MEMBER( hs_w );
57   DECLARE_READ8_MEMBER( videoram_r );
58   DECLARE_WRITE8_MEMBER( keylatch_w );
59   DECLARE_READ8_MEMBER( keydata_r );
60   
61   void bankswitch();
62   
2163   /* cpu state */
22   int ne555_int;
64   int m_ne555_int;
2365
2466   /* memory state */
25   int rom0000;
26   int mc6845_bank;
27   int mc6847_bank;
67   int m_rom0000;
68   int m_mc6845_bank;
69   int m_mc6847_bank;
2870
2971   /* keyboard state */
30   int keylatch;
72   int m_keylatch;
3173
3274   /* video state */
33   int hsync;
34   int vsync;
35   UINT8 *mc6845_video_ram;
36   UINT8 *mc6847_video_ram;
37   UINT8 mc6847_attr;
38
39   /* devices */
40   device_t *mc6845;
41   device_t *mc6847;
42   device_t *centronics;
43   device_t *cassette;
75   int m_hsync;
76   int m_vsync;
77   UINT8 *m_mc6845_video_ram;
78   UINT8 *m_mc6847_video_ram;
79   UINT8 m_mc6847_attr;
4480};
4581
4682#endif
src/mess/drivers/mc1000.c
r10999r11000
2020
2121*/
2222
23#include "emu.h"
2423#include "includes/mc1000.h"
25#include "cpu/z80/z80.h"
26#include "imagedev/cassette.h"
27#include "video/m6847.h"
28#include "sound/ay8910.h"
29#include "machine/ctronics.h"
30#include "machine/rescap.h"
31#include "machine/ram.h"
3224
3325/* Memory Banking */
3426
35static void mc1000_bankswitch(running_machine &machine)
27void mc1000_state::bankswitch()
3628{
37   mc1000_state *state = machine.driver_data<mc1000_state>();
38   address_space *program = machine.device(Z80_TAG)->memory().space(AS_PROGRAM);
29   address_space *program = m_maincpu->memory().space(AS_PROGRAM);
3930
4031   /* MC6845 video RAM */
41   memory_set_bank(machine, "bank2", state->mc6845_bank);
32   memory_set_bank(m_machine, "bank2", m_mc6845_bank);
4233
4334   /* extended RAM */
44   if (ram_get_size(machine.device(RAM_TAG)) > 16*1024)
35   if (ram_get_size(m_ram) > 16*1024)
4536   {
4637      program->install_readwrite_bank(0x4000, 0x7fff, "bank3");
4738   }
r10999r11000
5142   }
5243
5344   /* MC6847 video RAM */
54   if (state->mc6847_bank)
45   if (m_mc6847_bank)
5546   {
56      if (ram_get_size(machine.device(RAM_TAG)) > 16*1024)
47      if (ram_get_size(m_ram) > 16*1024)
5748      {
5849         program->install_readwrite_bank(0x8000, 0x97ff, "bank4");
5950      }
r10999r11000
6758      program->install_readwrite_bank(0x8000, 0x97ff, "bank4");
6859   }
6960
70   memory_set_bank(machine, "bank4", state->mc6847_bank);
61   memory_set_bank(m_machine, "bank4", m_mc6847_bank);
7162
7263   /* extended RAM */
73   if (ram_get_size(machine.device(RAM_TAG)) > 16*1024)
64   if (ram_get_size(m_ram) > 16*1024)
7465   {
7566      program->install_readwrite_bank(0x9800, 0xbfff, "bank5");
7667   }
r10999r11000
8273
8374/* Read/Write Handlers */
8475
85static READ8_HANDLER( printer_r )
76READ8_MEMBER( mc1000_state::printer_r )
8677{
87   mc1000_state *state = space->machine().driver_data<mc1000_state>();
88
89   return centronics_busy_r(state->centronics);
78   return centronics_busy_r(m_centronics);
9079}
9180
92static WRITE8_HANDLER( printer_w )
81WRITE8_MEMBER( mc1000_state::printer_w )
9382{
94   mc1000_state *state = space->machine().driver_data<mc1000_state>();
95
96   centronics_strobe_w(state->centronics, BIT(data, 0));
83   centronics_strobe_w(m_centronics, BIT(data, 0));
9784}
9885
99static WRITE8_HANDLER( mc6845_ctrl_w )
86WRITE8_MEMBER( mc1000_state::mc6845_ctrl_w )
10087{
101   mc1000_state *state = space->machine().driver_data<mc1000_state>();
88   m_mc6845_bank = BIT(data, 0);
10289
103   state->mc6845_bank = BIT(data, 0);
104
105   mc1000_bankswitch(space->machine());
90   bankswitch();
10691}
10792
108static WRITE8_HANDLER( mc6847_attr_w )
93WRITE8_MEMBER( mc1000_state::mc6847_attr_w )
10994{
11095   /*
11196
r10999r11000
122107
123108    */
124109
125   mc1000_state *state = space->machine().driver_data<mc1000_state>();
110   m_mc6847_bank = BIT(data, 0);
111   mc6847_css_w(m_crtc0, BIT(data, 1));
112   mc6847_gm0_w(m_crtc0, BIT(data, 2));
113   mc6847_gm1_w(m_crtc0, BIT(data, 3));
114   mc6847_gm2_w(m_crtc0, BIT(data, 4));
115   mc6847_intext_w(m_crtc0, BIT(data, 5));
116   mc6847_as_w(m_crtc0, BIT(data, 6));
117   mc6847_ag_w(m_crtc0, BIT(data, 7));
126118
127   state->mc6847_bank = BIT(data, 0);
128   mc6847_css_w(state->mc6847, BIT(data, 1));
129   mc6847_gm0_w(state->mc6847, BIT(data, 2));
130   mc6847_gm1_w(state->mc6847, BIT(data, 3));
131   mc6847_gm2_w(state->mc6847, BIT(data, 4));
132   mc6847_intext_w(state->mc6847, BIT(data, 5));
133   mc6847_as_w(state->mc6847, BIT(data, 6));
134   mc6847_ag_w(state->mc6847, BIT(data, 7));
135
136   mc1000_bankswitch(space->machine());
119   bankswitch();
137120}
138121
139122/* Memory Maps */
140123
141static ADDRESS_MAP_START( mc1000_mem, AS_PROGRAM, 8 )
124static ADDRESS_MAP_START( mc1000_mem, AS_PROGRAM, 8, mc1000_state )
142125   AM_RANGE(0x0000, 0x1fff) AM_RAMBANK("bank1")
143   AM_RANGE(0x2000, 0x27ff) AM_RAMBANK("bank2") AM_BASE_MEMBER(mc1000_state, mc6845_video_ram)
126   AM_RANGE(0x2000, 0x27ff) AM_RAMBANK("bank2") AM_BASE(m_mc6845_video_ram)
144127   AM_RANGE(0x2800, 0x3fff) AM_RAM
145128   AM_RANGE(0x4000, 0x7fff) AM_RAMBANK("bank3")
146   AM_RANGE(0x8000, 0x97ff) AM_RAMBANK("bank4") AM_BASE_MEMBER(mc1000_state, mc6847_video_ram)
129   AM_RANGE(0x8000, 0x97ff) AM_RAMBANK("bank4") AM_BASE(m_mc6847_video_ram)
147130   AM_RANGE(0x9800, 0xbfff) AM_RAMBANK("bank5")
148131   AM_RANGE(0xc000, 0xffff) AM_ROM
149132ADDRESS_MAP_END
150133
151static ADDRESS_MAP_START( mc1000_io, AS_IO, 8 )
134static ADDRESS_MAP_START( mc1000_io, AS_IO, 8, mc1000_state )
152135   ADDRESS_MAP_GLOBAL_MASK(0xff)
153136   AM_RANGE(0x04, 0x04) AM_READWRITE(printer_r, printer_w)
154   AM_RANGE(0x05, 0x05) AM_DEVWRITE(CENTRONICS_TAG, centronics_data_w)
155//  AM_RANGE(0x10, 0x10) AM_DEVWRITE(MC6845_TAG, mc6845_address_w)
156//  AM_RANGE(0x11, 0x11) AM_DEVREADWRITE(MC6845_TAG, mc6845_register_r, mc6845_register_w)
137   AM_RANGE(0x05, 0x05) AM_DEVWRITE_LEGACY(CENTRONICS_TAG, centronics_data_w)
138//  AM_RANGE(0x10, 0x10) AM_DEVWRITE_LEGACY(MC6845_TAG, mc6845_address_w)
139//  AM_RANGE(0x11, 0x11) AM_DEVREADWRITE_LEGACY(MC6845_TAG, mc6845_register_r, mc6845_register_w)
157140   AM_RANGE(0x12, 0x12) AM_WRITE(mc6845_ctrl_w)
158   AM_RANGE(0x20, 0x20) AM_DEVWRITE(AY8910_TAG, ay8910_address_w)
159   AM_RANGE(0x40, 0x40) AM_DEVREAD(AY8910_TAG, ay8910_r)
160   AM_RANGE(0x60, 0x60) AM_DEVWRITE(AY8910_TAG, ay8910_data_w)
141   AM_RANGE(0x20, 0x20) AM_DEVWRITE_LEGACY(AY8910_TAG, ay8910_address_w)
142   AM_RANGE(0x40, 0x40) AM_DEVREAD_LEGACY(AY8910_TAG, ay8910_r)
143   AM_RANGE(0x60, 0x60) AM_DEVWRITE_LEGACY(AY8910_TAG, ay8910_data_w)
161144   AM_RANGE(0x80, 0x80) AM_WRITE(mc6847_attr_w)
162145ADDRESS_MAP_END
163146
r10999r11000
272255
273256/* Video */
274257
275static WRITE_LINE_DEVICE_HANDLER( mc1000_mc6847_fs_w )
258WRITE_LINE_MEMBER( mc1000_state::fs_w )
276259{
277   mc1000_state *mc1000 = device->machine().driver_data<mc1000_state>();
278   mc1000->vsync = state;
260   m_vsync = state;
279261}
280262
281static WRITE_LINE_DEVICE_HANDLER( mc1000_mc6847_hs_w )
263WRITE_LINE_MEMBER( mc1000_state::hs_w )
282264{
283   mc1000_state *mc1000 = device->machine().driver_data<mc1000_state>();
284   mc1000->hsync = state;
265   m_hsync = state;
285266}
286267
287static READ8_DEVICE_HANDLER( mc1000_mc6847_videoram_r )
268READ8_MEMBER( mc1000_state::videoram_r )
288269{
289   mc1000_state *state = device->machine().driver_data<mc1000_state>();
270   mc6847_inv_w(m_crtc0, BIT(m_mc6847_video_ram[offset], 7));
290271
291   mc6847_inv_w(device, BIT(state->mc6847_video_ram[offset], 7));
292
293   return state->mc6847_video_ram[offset];
272   return m_mc6847_video_ram[offset];
294273}
295274
296static SCREEN_UPDATE( mc1000 )
275bool mc1000_state::screen_update(screen_device &screen, bitmap_t &bitmap, const rectangle &cliprect)
297276{
298   mc1000_state *state = screen->machine().driver_data<mc1000_state>();
299   return mc6847_update(state->mc6847, bitmap, cliprect);
277   return mc6847_update(m_crtc0, &bitmap, &cliprect);
300278}
301279
302280static UINT8 mc1000_get_char_rom(running_machine &machine, UINT8 ch, int line)
r10999r11000
306284
307285/* AY-3-8910 Interface */
308286
309static WRITE8_DEVICE_HANDLER( keylatch_w )
287WRITE8_MEMBER( mc1000_state::keylatch_w )
310288{
311   mc1000_state *state = device->machine().driver_data<mc1000_state>();
289   m_keylatch = data;
312290
313   state->keylatch = data;
314
315   cassette_output(state->cassette, BIT(data, 7) ? -1.0 : +1.0);
291   cassette_output(m_cassette, BIT(data, 7) ? -1.0 : +1.0);
316292}
317293
318static READ8_DEVICE_HANDLER( keydata_r )
294READ8_MEMBER( mc1000_state::keydata_r )
319295{
320   mc1000_state *state = device->machine().driver_data<mc1000_state>();
321
322296   UINT8 data = 0xff;
323297
324   if (!BIT(state->keylatch, 0))
298   if (!BIT(m_keylatch, 0))
325299   {
326                                 data &= input_port_read(device->machine(), "ROW0");
327      if (input_port_read(device->machine(), "JOYBKEYMAP"))
328                                 data &= input_port_read(device->machine(), "JOYB");
300      data &= input_port_read(m_machine, "ROW0");
301      if (input_port_read(m_machine, "JOYBKEYMAP")) data &= input_port_read(m_machine, "JOYB");
329302   }
330   if (!BIT(state->keylatch, 1))
303   if (!BIT(m_keylatch, 1))
331304   {
332                                 data &= input_port_read(device->machine(), "ROW1");
333      if (input_port_read(device->machine(), "JOYAKEYMAP"))
334                                 data &= input_port_read(device->machine(), "JOYA");
305      data &= input_port_read(m_machine, "ROW1");
306      if (input_port_read(m_machine, "JOYAKEYMAP")) data &= input_port_read(m_machine, "JOYA");
335307   }
336   if (!BIT(state->keylatch, 2)) data &= input_port_read(device->machine(), "ROW2");
337   if (!BIT(state->keylatch, 3)) data &= input_port_read(device->machine(), "ROW3");
338   if (!BIT(state->keylatch, 4)) data &= input_port_read(device->machine(), "ROW4");
339   if (!BIT(state->keylatch, 5)) data &= input_port_read(device->machine(), "ROW5");
340   if (!BIT(state->keylatch, 6)) data &= input_port_read(device->machine(), "ROW6");
341   if (!BIT(state->keylatch, 7)) data &= input_port_read(device->machine(), "ROW7");
308   if (!BIT(m_keylatch, 2)) data &= input_port_read(m_machine, "ROW2");
309   if (!BIT(m_keylatch, 3)) data &= input_port_read(m_machine, "ROW3");
310   if (!BIT(m_keylatch, 4)) data &= input_port_read(m_machine, "ROW4");
311   if (!BIT(m_keylatch, 5)) data &= input_port_read(m_machine, "ROW5");
312   if (!BIT(m_keylatch, 6)) data &= input_port_read(m_machine, "ROW6");
313   if (!BIT(m_keylatch, 7)) data &= input_port_read(m_machine, "ROW7");
342314
343   data = (input_port_read(device->machine(), "MODIFIERS") & 0xc0) | (data & 0x3f);
315   data = (input_port_read(m_machine, "MODIFIERS") & 0xc0) | (data & 0x3f);
344316
345   if (cassette_input(state->cassette) < +0.0)   data &= 0x7f;
317   if (cassette_input(m_cassette) < +0.0)   data &= 0x7f;
346318
347319   return data;
348320}
r10999r11000
352324   AY8910_SINGLE_OUTPUT,
353325   { RES_K(2.2), 0, 0 },
354326   DEVCB_NULL,
355   DEVCB_HANDLER(keydata_r),
356   DEVCB_HANDLER(keylatch_w),
327   DEVCB_DRIVER_MEMBER(mc1000_state, keydata_r),
328   DEVCB_DRIVER_MEMBER(mc1000_state, keylatch_w),
357329   DEVCB_NULL
358330};
359331
360332/* Machine Initialization */
361333
362static MACHINE_START( mc1000 )
334void mc1000_state::machine_start()
363335{
364   mc1000_state *state = machine.driver_data<mc1000_state>();
365   address_space *program = machine.device(Z80_TAG)->memory().space(AS_PROGRAM);
336   address_space *program = m_maincpu->memory().space(AS_PROGRAM);
366337
367   /* find devices */
368   state->mc6845 = machine.device(MC6845_TAG);
369   state->mc6847 = machine.device(MC6847_TAG);
370   state->centronics = machine.device(CENTRONICS_TAG);
371   state->cassette = machine.device(CASSETTE_TAG);
372
373338   /* setup memory banking */
339   UINT8 *rom = m_machine.region(Z80_TAG)->base();
340   
374341   program->install_readwrite_bank(0x0000, 0x1fff, "bank1");
375   memory_configure_bank(machine, "bank1", 0, 1, machine.region(Z80_TAG)->base(), 0);
376   memory_configure_bank(machine, "bank1", 1, 1, machine.region(Z80_TAG)->base() + 0xc000, 0);
377   memory_set_bank(machine, "bank1", 1);
342   memory_configure_bank(m_machine, "bank1", 0, 1, rom, 0);
343   memory_configure_bank(m_machine, "bank1", 1, 1, rom + 0xc000, 0);
344   memory_set_bank(m_machine, "bank1", 1);
378345
379   state->rom0000 = 1;
346   m_rom0000 = 1;
380347
381348   program->install_readwrite_bank(0x2000, 0x27ff, "bank2");
382   memory_configure_bank(machine, "bank2", 0, 1, machine.region(Z80_TAG)->base() + 0x2000, 0);
383   memory_configure_bank(machine, "bank2", 1, 1, state->mc6845_video_ram, 0);
384   memory_set_bank(machine, "bank2", 0);
349   memory_configure_bank(m_machine, "bank2", 0, 1, rom + 0x2000, 0);
350   memory_configure_bank(m_machine, "bank2", 1, 1, m_mc6845_video_ram, 0);
351   memory_set_bank(m_machine, "bank2", 0);
385352
386   memory_configure_bank(machine, "bank3", 0, 1, machine.region(Z80_TAG)->base() + 0x4000, 0);
387   memory_set_bank(machine, "bank3", 0);
353   memory_configure_bank(m_machine, "bank3", 0, 1, rom + 0x4000, 0);
354   memory_set_bank(m_machine, "bank3", 0);
388355
389   memory_configure_bank(machine, "bank4", 0, 1, state->mc6847_video_ram, 0);
390   memory_configure_bank(machine, "bank4", 1, 1, machine.region(Z80_TAG)->base() + 0x8000, 0);
391   memory_set_bank(machine, "bank4", 0);
356   memory_configure_bank(m_machine, "bank4", 0, 1, m_mc6847_video_ram, 0);
357   memory_configure_bank(m_machine, "bank4", 1, 1, rom + 0x8000, 0);
358   memory_set_bank(m_machine, "bank4", 0);
392359
393   memory_configure_bank(machine, "bank5", 0, 1, machine.region(Z80_TAG)->base() + 0x9800, 0);
394   memory_set_bank(machine, "bank5", 0);
360   memory_configure_bank(m_machine, "bank5", 0, 1, rom + 0x9800, 0);
361   memory_set_bank(m_machine, "bank5", 0);
395362
396   mc1000_bankswitch(machine);
363   bankswitch();
397364
398365   /* register for state saving */
399   state->save_item(NAME(state->rom0000));
400   state->save_item(NAME(state->mc6845_bank));
401   state->save_item(NAME(state->mc6847_bank));
402   state->save_item(NAME(state->keylatch));
403   state->save_item(NAME(state->hsync));
404   state->save_item(NAME(state->vsync));
366   save_item(NAME(m_rom0000));
367   save_item(NAME(m_mc6845_bank));
368   save_item(NAME(m_mc6847_bank));
369   save_item(NAME(m_keylatch));
370   save_item(NAME(m_hsync));
371   save_item(NAME(m_vsync));
405372}
406373
407static MACHINE_RESET( mc1000 )
374void mc1000_state::machine_reset()
408375{
409   mc1000_state *state = machine.driver_data<mc1000_state>();
376   memory_set_bank(m_machine, "bank1", 1);
410377
411   memory_set_bank(machine, "bank1", 1);
412
413   state->rom0000 = 1;
378   m_rom0000 = 1;
414379}
415380
416381/* Machine Driver */
r10999r11000
458423{
459424   mc1000_state *state = timer.machine().driver_data<mc1000_state>();
460425
461   // (state->ne555_int not needed anymore and can be done with?)
462   state->ne555_int = param;
426   // (m_ne555_int not needed anymore and can be done with?)
427   state->m_ne555_int = param;
463428
464   cputag_set_input_line(timer.machine(), Z80_TAG, INPUT_LINE_IRQ0, param);
429   state->m_maincpu->set_input_line(INPUT_LINE_IRQ0, param);
465430}
466431
467432static const cassette_config mc1000_cassette_config =
r10999r11000
474439
475440static const mc6847_interface mc1000_mc6847_intf =
476441{
477   DEVCB_HANDLER(mc1000_mc6847_videoram_r),
442   DEVCB_DRIVER_MEMBER(mc1000_state, videoram_r),
478443   DEVCB_NULL,
479444   DEVCB_NULL,
480445   DEVCB_NULL,
r10999r11000
483448   DEVCB_NULL,
484449   DEVCB_NULL,
485450   DEVCB_NULL,
486   DEVCB_LINE(mc1000_mc6847_fs_w),
487   DEVCB_LINE(mc1000_mc6847_hs_w),
451   DEVCB_DRIVER_LINE_MEMBER(mc1000_state, fs_w),
452   DEVCB_DRIVER_LINE_MEMBER(mc1000_state, hs_w),
488453   DEVCB_NULL
489454};
490455
r10999r11000
495460   MCFG_CPU_PROGRAM_MAP(mc1000_mem)
496461   MCFG_CPU_IO_MAP(mc1000_io)
497462
498   MCFG_MACHINE_START(mc1000)
499   MCFG_MACHINE_RESET(mc1000)
500
501463   /* timers */
502464   MCFG_TIMER_ADD_PERIODIC("ne555clear", ne555_tick, attotime::from_hz(MC1000_NE555_FREQ))
503465   MCFG_TIMER_PARAM(CLEAR_LINE)
r10999r11000
513475   MCFG_SCREEN_FORMAT(BITMAP_FORMAT_RGB32)
514476   MCFG_SCREEN_SIZE(320, 25+192+26)
515477   MCFG_SCREEN_VISIBLE_AREA(0, 319, 1, 239)
516   MCFG_SCREEN_UPDATE(mc1000)
517478   
518479   MCFG_PALETTE_LENGTH(16)
519480
r10999r11000
552513{
553514   mc1000_state *state = machine->driver_data<mc1000_state>();
554515
555   if (state->rom0000)
516   if (state->m_rom0000)
556517   {
557518      if (address >= 0xc000)
558519      {
559520         memory_set_bank(*machine, "bank1", 0);
560         state->rom0000 = 0;
521         state->m_rom0000 = 0;
561522      }
562523   }
563524

Previous 15994 Revisions Next


© 1998-2018 The MESS Team