Previous 15994 Revisions Next

r15580 Thursday 12th July, 2012 at 12:55:16 UTC by Robbbert
BIGBOARD2 WIP
[src/mess/drivers]bigbord2.c

src/mess/drivers/bigbord2.c
r15579r15580
2525d8 = port7
2626dc = 6845 ce
2727
28
29Difficulties encountered:
30
31CTCA controls a pair of vectored interrupts.
32One is triggered by a keypress, the other by a vsync pulse..
33Once a key is pressed, CTCA continually issues a keyboard interrupt,
34causing a complete freeze. Therefore CTCA has been isolated, and the
352 interrupts are triggered by a hack. It isn't a very good hack,
36because the system crashes after a while. However it will allow
37testing and development to continue.
38
2839****************************************************************************/
2940
3041
r15579r15580
3748#include "machine/ram.h"
3849#include "machine/z80ctc.h"
3950#include "machine/z80sio.h"
51#include "machine/z80dma.h"
4052#include "machine/wd17xx.h"
4153#include "video/mc6845.h"
4254#include "machine/keyboard.h"
4355
4456#define SCREEN_TAG      "screen"
4557
46#define Z80_TAG         "u46"
58#define Z80_TAG         "u39"
4759#define Z80SIO_TAG      "u16"
48#define Z80CTC_TAG      "u99"
49#define WD1771_TAG      "u109"
60#define Z80CTCA_TAG      "u37"
61#define Z80CTCB_TAG      "u21"
62#define Z80DMA_TAG      "u62"
5063
5164class bigbord2_state : public driver_device
5265{
r15579r15580
5568      : driver_device(mconfig, type, tag),
5669   m_maincpu(*this, Z80_TAG),
5770   m_6845(*this, "crtc"),
58   m_ctc_84(*this, "ctc_84"),
59   m_ctc_88(*this, "ctc_88"),
60   m_fdc(*this, WD1771_TAG),
71   m_ctca(*this, Z80CTCA_TAG),
72   m_ctcb(*this, Z80CTCA_TAG),
73   m_fdc(*this, "fdc"),
6174   // m_ram(*this, RAM_TAG),
6275   m_floppy0(*this, FLOPPY_0),
6376   m_floppy1(*this, FLOPPY_1),
64   m_videoram(*this, "videoram"){ }
77   m_videoram(*this, "videoram"),
78   m_workram(*this, "workram"),
79   m_attribram(*this, "attribram"){ }
6580
6681   virtual void machine_start();
6782   virtual void machine_reset();
6883
6984   virtual void video_start();
7085
71   required_device<cpu_device> m_maincpu;
72   required_device<mc6845_device> m_6845;
73   required_device<z80ctc_device> m_ctc_84;
74   required_device<z80ctc_device> m_ctc_88;
75   required_device<device_t> m_fdc;
76   //required_device<ram_device> m_ram;
77   required_device<device_t> m_floppy0;
78   required_device<device_t> m_floppy1;
79
8086   DECLARE_WRITE8_MEMBER( scroll_w );
8187   //DECLARE_WRITE8_MEMBER( x120_system_w );
8288   DECLARE_READ8_MEMBER( bigbord2_c4_r );
r15579r15580
8793   DECLARE_READ8_MEMBER( kbpio_pb_r );
8894   DECLARE_WRITE_LINE_MEMBER( intrq_w );
8995   DECLARE_WRITE_LINE_MEMBER( drq_w );
96   DECLARE_WRITE_LINE_MEMBER(frame);
9097
9198   void scan_keyboard();
9299   //void bankswitch(int bank);
r15579r15580
98105   UINT8 m_term_status;
99106
100107   /* video state */
101   required_shared_ptr<UINT8> m_videoram; /* video RAM */
102   UINT8 *m_char_rom;               /* character ROM */
108   UINT8 *m_p_chargen;               /* character ROM */
103109   UINT8 m_scroll;                  /* vertical scroll */
104110   int m_ncset2;                  /* national character set */
105111   int m_vatt;                     /* X120 video attribute */
r15579r15580
111117   int m_fdc_drq;                  /* data request */
112118   int m_8n5;                     /* 5.25" / 8" drive select */
113119   int m_dsdd;                     /* double sided disk detect */
120   required_device<cpu_device> m_maincpu;
121   required_device<mc6845_device> m_6845;
122   required_device<z80ctc_device> m_ctca;
123   required_device<z80ctc_device> m_ctcb;
124   required_device<device_t> m_fdc;
125   //required_device<ram_device> m_ram;
126   required_device<device_t> m_floppy0;
127   required_device<device_t> m_floppy1;
128   required_shared_ptr<UINT8> m_videoram; /* video RAM */
129   required_shared_ptr<UINT8> m_workram;
130   required_shared_ptr<UINT8> m_attribram;
114131};
115132
116/* Keyboard (external keyboard - so we use the 'terminal') */
133/* Keyboard (external keyboard - so we use the 'ascii keyboard') */
117134
118135READ8_MEMBER( bigbord2_state::bigbord2_c4_r )
119136{
r15579r15580
124141
125142READ8_MEMBER( bigbord2_state::bigbord2_d0_r )
126143{
127   return m_term_data;
144   UINT8 ret = m_term_data;
145   m_term_data = 0;
146   return ret;
128147}
129148
130149WRITE8_MEMBER( bigbord2_state::bigbord2_kbd_put )
131150{
132   m_term_data = data;
133   m_term_status = 8;
151   if (data)
152   {
153      m_term_data = data;
154      m_term_status = 8;
155      z80ctc_trg0_w(m_ctca, 0);
156      z80ctc_trg0_w(m_ctca, 1);
157      if (space.read_byte(0xf13d) == 0x4d)
158      {
159         // simulate interrupt by saving current pc on
160         // the stack and jumping to interrupt handler.
161         UINT16 spreg = cpu_get_reg(m_maincpu, Z80_SP);
162         UINT16 pcreg = cpu_get_reg(m_maincpu, Z80_PC);
163         spreg--;
164         space.write_byte(spreg, pcreg >> 8);
165         spreg--;
166         space.write_byte(spreg, pcreg);
167         cpu_set_reg(m_maincpu, Z80_SP, spreg);
168         cpu_set_reg(m_maincpu, Z80_PC, 0xF120);
169      }
170   }
134171}
135172
136173static ASCII_KEYBOARD_INTERFACE( keyboard_intf )
r15579r15580
138175   DEVCB_DRIVER_MEMBER(bigbord2_state, bigbord2_kbd_put)
139176};
140177
178
141179static READ8_DEVICE_HANDLER( bigbord2_sio_r )
142180{
143181   if (!offset)
r15579r15580
167205}
168206
169207
170/* Read/Write Handlers */
208/* Z80 DMA */
171209
172#if 0
173void bigbord2_state::bankswitch(int bank)
174{
175   address_space *program = m_maincpu->memory().space(AS_PROGRAM);
176   UINT8 *ram = m_ram->pointer();
177210
178   if (bank)
179   {
180      /* ROM */
181      program->install_rom(0x0000, 0x0fff, machine.root_device().memregion("monitor")->base());
182      program->unmap_readwrite(0x1000, 0x1fff);
183      program->install_ram(0x3000, 0x3fff, m_videoram);
184   }
185   else
186   {
187      /* RAM */
188      program->install_ram(0x0000, 0x3fff, ram);
189   }
190}
191#endif
211static UINT8 memory_read_byte(address_space *space, offs_t address) { return space->read_byte(address); }
212static void memory_write_byte(address_space *space, offs_t address, UINT8 data) { space->write_byte(address, data); }
192213
193WRITE8_MEMBER( bigbord2_state::scroll_w )
214static Z80DMA_INTERFACE( dma_intf )
194215{
195   m_scroll = (offset >> 8) & 0x1f;
196}
216   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_HALT), // actually BUSRQ
217   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_IRQ0),
218   DEVCB_NULL,
219   DEVCB_MEMORY_HANDLER(Z80_TAG, PROGRAM, memory_read_byte),
220   DEVCB_MEMORY_HANDLER(Z80_TAG, PROGRAM, memory_write_byte),
221   DEVCB_MEMORY_HANDLER(Z80_TAG, IO, memory_read_byte),
222   DEVCB_MEMORY_HANDLER(Z80_TAG, IO, memory_write_byte)
223};
197224
225
226/* Read/Write Handlers */
227
228
229
198230#ifdef UNUSED_CODE
199231WRITE8_MEMBER( bigbord2_state::x120_system_w )
200232{
r15579r15580
252284
253285static ADDRESS_MAP_START( bigbord2_mem, AS_PROGRAM, 8, bigbord2_state )
254286   ADDRESS_MAP_UNMAP_HIGH
255   AM_RANGE(0x6000, 0x67ff) AM_RAM AM_SHARE("videoram")
256287   AM_RANGE(0x0000, 0x0fff) AM_ROM
257288   AM_RANGE(0x1000, 0x5fff) AM_RAM
258   AM_RANGE(0x6800, 0xffff) AM_RAM
289   AM_RANGE(0x6000, 0x6fff) AM_RAM AM_SHARE("videoram")
290   AM_RANGE(0x7000, 0x7fff) AM_RAM AM_SHARE("attribram")
291   AM_RANGE(0x8000, 0xfeff) AM_RAM
292   AM_RANGE(0xff00, 0xffff) AM_RAM AM_SHARE("workram")
259293ADDRESS_MAP_END
260294
261295static ADDRESS_MAP_START( bigbord2_io, AS_IO, 8, bigbord2_state )
262296   ADDRESS_MAP_GLOBAL_MASK(0xff)
263297   AM_RANGE(0x80, 0x83) AM_DEVREADWRITE_LEGACY(Z80SIO_TAG, bigbord2_sio_r, bigbord2_sio_w)
264   //AM_RANGE(0x84, 0x87) AM_DEVREADWRITE_LEGACY(Z80CTC_TAG, z80ctc_r, z80ctc_w)
265   //AM_RANGE(0x88, 0x8b) AM_DEVREADWRITE_LEGACY(Z80CTC_TAG, z80ctc_r, z80ctc_w)
266   //AM_RANGE(0x8C, 0x8F) AM_DEVREADWRITE_LEGACY(Z80DMA_TAG, z80ctc_r, z80ctc_w)
298   //AM_RANGE(0x84, 0x87) AM_DEVREADWRITE_LEGACY(Z80CTCA_TAG, z80ctc_r, z80ctc_w) //has issues
299   AM_RANGE(0x88, 0x8b) AM_DEVREADWRITE_LEGACY(Z80CTCB_TAG, z80ctc_r, z80ctc_w)
300   AM_RANGE(0x8C, 0x8F) AM_DEVREADWRITE_LEGACY(Z80DMA_TAG, z80dma_r, z80dma_w)
267301   AM_RANGE(0xC4, 0xC7) AM_READ(bigbord2_c4_r)
268302   AM_RANGE(0xD0, 0xD3) AM_READ(bigbord2_d0_r)
269   AM_RANGE(0xD4, 0xD7) AM_DEVREADWRITE_LEGACY(WD1771_TAG, wd17xx_r, wd17xx_w)
270   AM_RANGE(0xDC, 0xDC) AM_MIRROR(2) AM_DEVWRITE("crtc", mc6845_device, address_w)
303   AM_RANGE(0xD4, 0xD7) AM_DEVREADWRITE_LEGACY("fdc", wd17xx_r, wd17xx_w)
304   AM_RANGE(0xDC, 0xDC) AM_MIRROR(2) AM_DEVREADWRITE("crtc", mc6845_device, status_r, address_w)
271305   AM_RANGE(0xDD, 0xDD) AM_MIRROR(2) AM_DEVREADWRITE("crtc", mc6845_device, register_r, register_w)
272306ADDRESS_MAP_END
273307
r15579r15580
367401
368402static TIMER_DEVICE_CALLBACK( ctc_tick )
369403{
370   //bigbord2_state *state = timer.machine().driver_data<bigbord2_state>();
404   bigbord2_state *state = timer.machine().driver_data<bigbord2_state>();
371405
372   //z80ctc_trg0_w(state->m_ctc, 1);
373   //z80ctc_trg0_w(state->m_ctc, 0);
406   z80ctc_trg0_w(state->m_ctcb, 1);
407   z80ctc_trg1_w(state->m_ctcb, 1);
408   z80ctc_trg0_w(state->m_ctcb, 0);
409   z80ctc_trg1_w(state->m_ctcb, 0);
374410}
375411
376static WRITE_LINE_DEVICE_HANDLER( ctc_z0_w )
412WRITE_LINE_MEMBER( bigbord2_state::frame )
377413{
378//  z80ctc_trg1_w(device, state);
414   address_space *space = m_maincpu->memory().space(AS_PROGRAM);
415   static UINT8 framecnt;
416   framecnt++;
417
418   if ((space->read_byte(0xf13d) == 0x4d) & (framecnt > 3))
419   {
420      framecnt = 0;
421      // simulate interrupt by saving current pc on
422      // the stack and jumping to interrupt handler.
423      UINT16 spreg = cpu_get_reg(m_maincpu, Z80_SP);
424      UINT16 pcreg = cpu_get_reg(m_maincpu, Z80_PC);
425      spreg--;
426      space->write_byte(spreg, pcreg >> 8);
427      spreg--;
428      space->write_byte(spreg, pcreg);
429      cpu_set_reg(m_maincpu, Z80_SP, spreg);
430      cpu_set_reg(m_maincpu, Z80_PC, 0xF18E);
431   }
379432}
380433
434
435// other inputs of ctca:
436// trg0 = KBDSTB; trg1 = index pulse from fdc; trg2 = synca output from sio
437
438
439
381440static WRITE_LINE_DEVICE_HANDLER( ctc_z2_w )
382441{
383//  z80ctc_trg3_w(device, state);
442   z80ctc_trg3_w(device, state);
384443}
385444
386static Z80CTC_INTERFACE( ctc_intf )
445static Z80CTC_INTERFACE( ctca_intf )
387446{
388447   0,                       /* timer disables */
389448   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_IRQ0),   /* interrupt handler */
390   DEVCB_LINE(ctc_z0_w),      /* ZC/TO0 callback */
391   DEVCB_LINE(z80ctc_trg2_w),   /* ZC/TO1 callback */
392   DEVCB_LINE(ctc_z2_w)      /* ZC/TO2 callback */
449   DEVCB_NULL,      /* ZC/TO0 callback - KBDCLK */
450   DEVCB_NULL,      /* ZC/TO1 callback - not connected */
451   DEVCB_NULL      /* ZC/TO2 callback - not connected */
393452};
394453
454static Z80CTC_INTERFACE( ctcb_intf )
455{
456   0,                       /* timer disables */
457   DEVCB_CPU_INPUT_LINE(Z80_TAG, INPUT_LINE_IRQ0),   /* interrupt handler */
458   DEVCB_NULL,      /* ZC/TO0 callback - SIO channel B clock */
459   DEVCB_NULL,      /* ZC/TO1 callback - SIO channel A clock */
460   DEVCB_DEVICE_LINE(Z80CTCB_TAG, ctc_z2_w) /* ZC/TO2 callback */
461};
462
395463/* Z80 Daisy Chain */
396464
397465static const z80_daisy_config bigbord2_daisy_chain[] =
398466{
467   { Z80DMA_TAG },
468   { Z80CTCA_TAG },
469   { Z80CTCB_TAG },
399470   { Z80SIO_TAG },
400   { "ctc_84" },
401   { "ctc_88" },
402471   { NULL }
403472};
404473
405/* WD1771 Interface */
474/* WD1793 Interface */
406475
407476WRITE_LINE_MEMBER( bigbord2_state::intrq_w )
408477{
409   int halt = cpu_get_reg(m_maincpu, Z80_HALT);
478//   int halt = cpu_get_reg(m_maincpu, Z80_HALT);
410479
411480   m_fdc_irq = state;
412481
413   if (halt && state)
414      device_set_input_line(m_maincpu, INPUT_LINE_NMI, ASSERT_LINE);
415   else
416      device_set_input_line(m_maincpu, INPUT_LINE_NMI, CLEAR_LINE);
482//   if (halt && state)
483//      device_set_input_line(m_maincpu, INPUT_LINE_NMI, ASSERT_LINE);
484//   else
485//      device_set_input_line(m_maincpu, INPUT_LINE_NMI, CLEAR_LINE);
417486}
418487
419488WRITE_LINE_MEMBER( bigbord2_state::drq_w )
420489{
421   int halt = cpu_get_reg(m_maincpu, Z80_HALT);
490//   int halt = cpu_get_reg(m_maincpu, Z80_HALT);
422491
423492   m_fdc_drq = state;
424493
425   if (halt && state)
426      device_set_input_line(m_maincpu, INPUT_LINE_NMI, ASSERT_LINE);
427   else
428      device_set_input_line(m_maincpu, INPUT_LINE_NMI, CLEAR_LINE);
494//   if (halt && state)
495//      device_set_input_line(m_maincpu, INPUT_LINE_NMI, ASSERT_LINE);
496//   else
497//      device_set_input_line(m_maincpu, INPUT_LINE_NMI, CLEAR_LINE);
429498}
430499
431500static const wd17xx_interface fdc_intf =
r15579r15580
442511void bigbord2_state::video_start()
443512{
444513   /* find memory regions */
445   m_char_rom = memregion("chargen")->base();
514   m_p_chargen = memregion("chargen")->base();
446515}
447516
448517
r15579r15580
500569
501570void bigbord2_state::machine_reset()
502571{
503   //bankswitch(1);
572
504573}
505574
506575static LEGACY_FLOPPY_OPTIONS_START( bigbord2 )
r15579r15580
569638   UINT16 mem,x;
570639   UINT32 *p = &bitmap.pix32(y);
571640
572   for (x = 0; x < x_count; x++)            // for each character
641   for (x = 0; x < x_count; x++)
573642   {
574643      inv=0;
575      if (x == cursor_x) inv^=0xff;
576644      mem = (ma + x) & 0x7ff;
645      if (BIT(state->m_attribram[mem], 7)) inv^=0xff;
577646      chr = state->m_videoram[mem];
578647
579648      /* get pattern of pixels for that character scanline */
580      gfx = state->m_char_rom[(chr<<4) | ra ] ^ inv;
649      gfx = state->m_p_chargen[(chr<<4) | ra ] ^ inv;
581650
582651      /* Display a scanline of a character */
583      *p++ = palette[BIT( gfx, 7 ) ? 1 : 0];
584      *p++ = palette[BIT( gfx, 6 ) ? 1 : 0];
585      *p++ = palette[BIT( gfx, 5 ) ? 1 : 0];
586      *p++ = palette[BIT( gfx, 4 ) ? 1 : 0];
587      *p++ = palette[BIT( gfx, 3 ) ? 1 : 0];
588      *p++ = palette[BIT( gfx, 2 ) ? 1 : 0];
589      *p++ = palette[BIT( gfx, 1 ) ? 1 : 0];
590      *p++ = palette[BIT( gfx, 0 ) ? 1 : 0];
652      *p++ = palette[BIT( gfx, 7 )];
653      *p++ = palette[BIT( gfx, 6 )];
654      *p++ = palette[BIT( gfx, 5 )];
655      *p++ = palette[BIT( gfx, 4 )];
656      *p++ = palette[BIT( gfx, 3 )];
657      *p++ = palette[BIT( gfx, 2 )];
658      *p++ = palette[BIT( gfx, 1 )];
659      *p++ = palette[BIT( gfx, 0 )];
591660   }
592661}
593662
r15579r15580
600669   DEVCB_NULL,
601670   DEVCB_NULL,
602671   DEVCB_NULL,
603   DEVCB_NULL,
672   DEVCB_DRIVER_LINE_MEMBER(bigbord2_state, frame), //DEVCB_DEVICE_LINE(Z80CTCA_TAG, z80ctc_trg3_w), // vsync
604673   NULL
605674};
606675
r15579r15580
628697   MCFG_TIMER_ADD_PERIODIC("ctc", ctc_tick, attotime::from_hz(MAIN_CLOCK))
629698
630699   /* devices */
700   MCFG_Z80DMA_ADD(Z80DMA_TAG, MAIN_CLOCK, dma_intf)
631701   MCFG_Z80SIO_ADD(Z80SIO_TAG, MAIN_CLOCK, sio_intf)
632   MCFG_Z80CTC_ADD("ctc_84", MAIN_CLOCK, ctc_intf)
633   MCFG_Z80CTC_ADD("ctc_88", MAIN_CLOCK, ctc_intf)
634   MCFG_FD1793_ADD(WD1771_TAG, fdc_intf)
702   MCFG_Z80CTC_ADD(Z80CTCA_TAG, MAIN_CLOCK, ctca_intf)
703   MCFG_Z80CTC_ADD(Z80CTCB_TAG, MAIN_CLOCK / 6, ctcb_intf)
704   MCFG_FD1793_ADD("fdc", fdc_intf)
635705   MCFG_LEGACY_FLOPPY_2_DRIVES_ADD(bigbord2_floppy_interface)
636706   MCFG_MC6845_ADD("crtc", MC6845, XTAL_16MHz / 8, bigbord2_crtc)
637707   MCFG_ASCII_KEYBOARD_ADD(KEYBOARD_TAG, keyboard_intf)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team