Previous 15994 Revisions Next

r10969 Monday 28th March, 2011 at 20:14:35 UTC by Curt Coder
Moved some C++ devices to emu folder.
[src/emu]emu.mak
[src/emu/machine]cdp1871.c* cdp1871.h* e0516.c* e0516.h* i8155.c* i8155.h* i8212.c* i8212.h* i8355.c* i8355.h* nmc9306.c* nmc9306.h* z8536.c* z8536.h*
[src/emu/video]crt9007.c* crt9007.h* crt9021.c* crt9021.h* crt9212.c* crt9212.h* hd61830.c* hd61830.h*
[src/mess]mess.mak
[src/mess/machine]cdp1871.c cdp1871.h e0516.c e0516.h i8155.c i8155.h i8212.c i8212.h i8355.c i8355.h nmc9306.c nmc9306.h z8536.c z8536.h
[src/mess/video]crt9007.c crt9007.h crt9021.c crt9021.h crt9212.c crt9212.h hd61830.c hd61830.h

src/emu/video/crt9021.c
r0r10969
1/**********************************************************************
2
3    SMC CRT9021 Video Attributes Controller (VAC) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10/*
11
12    TODO:
13
14    - attributes
15        - reverse video
16        - character blank
17        - character blink
18        - underline
19        - full/half intensity
20    - operation modes
21        - wide graphics
22        - thin graphics
23        - character mode w/o underline
24        - character mode w/underline
25    - double height characters
26    - double width characters
27    - parallel scan line
28    - serial scan line
29    - cursor
30        - underline
31        - blinking underline
32        - reverse video
33        - blinking reverse video
34    - programmable character blink rate (75/25 duty)
35    - programmable cursor blink rate (50/50 duty)
36    - data/attribute latches
37
38*/
39
40#include "emu.h"
41#include "crt9021.h"
42
43
44
45//**************************************************************************
46//  MACROS / CONSTANTS
47//**************************************************************************
48
49#define LOG 1
50
51
52// attributes
53enum
54{
55   ATTRIBUTE_REVID = 0x80,
56   ATTRIBUTE_INT   = 0x40,
57   ATTRIBUTE_BLINK = 0x20,
58   ATTRIBUTE_MS1   = 0x10,
59   ATTRIBUTE_MS0   = 0x08,
60   ATTRIBUTE_CHABL = 0x04,
61   ATTRIBUTE_BKC   = 0x02,
62   ATTRIBUTE_BLC   = 0x01
63};
64
65
66//**************************************************************************
67//  GLOBAL VARIABLES
68//**************************************************************************
69
70// devices
71const device_type CRT9021 = crt9021_device_config::static_alloc_device_config;
72
73
74
75//**************************************************************************
76//  DEVICE CONFIGURATION
77//**************************************************************************
78
79//-------------------------------------------------
80//  crt9021_device_config - constructor
81//-------------------------------------------------
82
83crt9021_device_config::crt9021_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
84   : device_config(mconfig, static_alloc_device_config, "SMC CRT9021", tag, owner, clock)
85{
86}
87
88
89//-------------------------------------------------
90//  static_alloc_device_config - allocate a new
91//  configuration object
92//-------------------------------------------------
93
94device_config *crt9021_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
95{
96   return global_alloc(crt9021_device_config(mconfig, tag, owner, clock));
97}
98
99
100//-------------------------------------------------
101//  alloc_device - allocate a new device object
102//-------------------------------------------------
103
104device_t *crt9021_device_config::alloc_device(running_machine &machine) const
105{
106   return auto_alloc(&machine, crt9021_device(machine, *this));
107}
108
109
110//-------------------------------------------------
111//  device_config_complete - perform any
112//  operations now that the configuration is
113//  complete
114//-------------------------------------------------
115
116void crt9021_device_config::device_config_complete()
117{
118   // inherit a copy of the static data
119   const crt9021_interface *intf = reinterpret_cast<const crt9021_interface *>(static_config());
120   if (intf != NULL)
121      *static_cast<crt9021_interface *>(this) = *intf;
122
123   // or initialize to defaults if none provided
124   else
125   {
126      memset(&in_data_func, 0, sizeof(in_data_func));
127      memset(&in_attr_func, 0, sizeof(in_attr_func));
128      memset(&in_atten_func, 0, sizeof(in_atten_func));
129   }
130}
131
132
133
134//**************************************************************************
135//  INLINE HELPERS
136//**************************************************************************
137
138
139
140//**************************************************************************
141//  LIVE DEVICE
142//**************************************************************************
143
144//-------------------------------------------------
145//  crt9021_device - constructor
146//-------------------------------------------------
147
148crt9021_device::crt9021_device(running_machine &_machine, const crt9021_device_config &config)
149    : device_t(_machine, config),
150      m_config(config)
151{
152}
153
154
155//-------------------------------------------------
156//  device_start - device-specific startup
157//-------------------------------------------------
158
159void crt9021_device::device_start()
160{
161   // allocate timers
162
163   // resolve callbacks
164   devcb_resolve_read8(&m_in_data_func, &m_config.in_data_func, this);
165   devcb_resolve_read8(&m_in_attr_func, &m_config.in_attr_func, this);
166   devcb_resolve_read_line(&m_in_atten_func, &m_config.in_atten_func, this);
167
168   // get the screen device
169   m_screen = machine->device<screen_device>(m_config.screen_tag);
170   assert(m_screen != NULL);
171
172   // register for state saving
173   save_item(NAME(m_slg));
174   save_item(NAME(m_sld));
175   save_item(NAME(m_cursor));
176   save_item(NAME(m_retbl));
177   save_item(NAME(m_vsync));
178}
179
180
181//-------------------------------------------------
182//  device_clock_changed - handle clock change
183//-------------------------------------------------
184
185void crt9021_device::device_clock_changed()
186{
187}
188
189
190//-------------------------------------------------
191//  device_timer - handle timer events
192//-------------------------------------------------
193
194void crt9021_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
195{
196}
197
198
199//-------------------------------------------------
200//  slg_w - scan line gate
201//-------------------------------------------------
202
203WRITE_LINE_MEMBER( crt9021_device::slg_w )
204{
205   if (LOG) logerror("CRT9021 '%s' SLG: %u\n", tag(), state);
206
207   m_slg = state;
208}
209
210
211//-------------------------------------------------
212//  sld_w - scan line data
213//-------------------------------------------------
214
215WRITE_LINE_MEMBER( crt9021_device::sld_w )
216{
217   if (LOG) logerror("CRT9021 '%s' SLG: %u\n", tag(), state);
218
219   if (!m_slg)
220   {
221      m_sld <<= 1;
222      m_sld |= state;
223   }
224}
225
226
227//-------------------------------------------------
228//  cursor_w - cursor
229//-------------------------------------------------
230
231WRITE_LINE_MEMBER( crt9021_device::cursor_w )
232{
233   if (LOG) logerror("CRT9021 '%s' CURSOR: %u\n", tag(), state);
234
235   m_cursor = state;
236}
237
238
239//-------------------------------------------------
240//  retbl_w - retrace blank
241//-------------------------------------------------
242
243WRITE_LINE_MEMBER( crt9021_device::retbl_w )
244{
245   if (LOG) logerror("CRT9021 '%s' RETBL: %u\n", tag(), state);
246
247   m_retbl = state;
248}
249
250
251//-------------------------------------------------
252//  vsync_w - vertical sync
253//-------------------------------------------------
254
255WRITE_LINE_MEMBER( crt9021_device::vsync_w )
256{
257   if (LOG) logerror("CRT9021 '%s' VSYNC: %u\n", tag(), state);
258
259   m_vsync = state;
260}
261
262
263//-------------------------------------------------
264//  update_screen - update screen
265//-------------------------------------------------
266
267void crt9021_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect)
268{
269}
src/emu/video/crt9007.c
r0r10969
1/**********************************************************************
2
3    SMC CRT9007 CRT Video Processor and Controller (VPAC) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10/*
11
12    TODO:
13
14    - cursor timer
15    - interrupts
16        - light pen
17        - frame timer
18    - non-DMA mode
19    - DMA mode
20    - cursor/blank skew
21    - sequential breaks
22    - interlaced mode
23    - smooth scroll
24    - page blank
25    - double height cursor
26    - row attributes
27    - pin configuration
28    - operation modes 0,4,7
29    - address modes 1,2,3
30    - light pen
31    - state saving
32
33*/
34
35#include "emu.h"
36#include "crt9007.h"
37
38
39
40//**************************************************************************
41//  MACROS / CONSTANTS
42//**************************************************************************
43
44#define LOG 1
45
46#define HAS_VALID_PARAMETERS \
47   (m_reg[0x00] && m_reg[0x01] && m_reg[0x07] && m_reg[0x08] && m_reg[0x09])
48
49#define CHARACTERS_PER_HORIZONTAL_PERIOD \
50   m_reg[0x00]
51
52#define CHARACTERS_PER_DATA_ROW \
53   (m_reg[0x01] + 1)
54
55#define HORIZONTAL_DELAY \
56   m_reg[0x02]
57
58#define HORIZONTAL_SYNC_WIDTH \
59   m_reg[0x03]
60
61#define VERTICAL_SYNC_WIDTH \
62   m_reg[0x04]
63
64#define VERTICAL_DELAY \
65   (m_reg[0x05] - 1)
66
67#define PIN_CONFIGURATION \
68   (m_reg[0x06] >> 6)
69
70#define CURSOR_SKEW \
71   ((m_reg[0x06] >> 3) & 0x07)
72
73#define BLANK_SKEW \
74   (m_reg[0x06] & 0x07)
75
76#define VISIBLE_DATA_ROWS_PER_FRAME \
77   (m_reg[0x07] + 1)
78
79#define SCAN_LINES_PER_DATA_ROW \
80   ((m_reg[0x08] & 0x1f) + 1)
81
82#define SCAN_LINES_PER_FRAME \
83   (((m_reg[0x08] << 3) & 0x0700) | m_reg[0x09])
84
85#define DMA_BURST_COUNT \
86   ((m_reg[0x0a] & 0x0f) + 1)
87
88#define DMA_BURST_DELAY \
89   ((((m_reg[0x0a] >> 4) & 0x07) + 1) % 8)
90
91#define DMA_DISABLE \
92   BIT(m_reg[0x0a], 7)
93
94#define SINGLE_HEIGHT_CURSOR \
95   BIT(m_reg[0x0b], 0)
96
97#define OPERATION_MODE \
98   ((m_reg[0x0b] >> 1) & 0x07)
99
100#define INTERLACE_MODE \
101   ((m_reg[0x0b] >> 4) & 0x03)
102
103#define PAGE_BLANK \
104   BIT(m_reg[0x0b], 6)
105
106#define TABLE_START \
107   (((m_reg[0x0d] << 8) & 0x3f00) | m_reg[0x0c])
108
109#define ADDRESS_MODE \
110   ((m_reg[0x0d] >> 6) & 0x03)
111
112#define AUXILIARY_ADDRESS_1 \
113   (((m_reg[0x0f] << 8) & 0x3f00) | m_reg[0x0e])
114
115#define ROW_ATTRIBUTES_1 \
116   ((m_reg[0x0f] >> 6) & 0x03)
117
118#define SEQUENTIAL_BREAK_1 \
119   m_reg[0x10]
120
121#define SEQUENTIAL_BREAK_2 \
122   m_reg[0x12]
123
124#define DATA_ROW_START \
125   m_reg[0x11]
126
127#define DATA_ROW_END \
128   m_reg[0x12]
129
130#define AUXILIARY_ADDRESS_2 \
131   (((m_reg[0x14] << 8) & 0x3f00) | m_reg[0x13])
132
133#define ROW_ATTRIBUTES_2 \
134   ((m_reg[0x14] >> 6) & 0x03)
135
136#define SMOOTH_SCROLL_OFFSET \
137   ((m_reg[0x17] >> 1) & 0x3f)
138
139#define SMOOTH_SCROLL_OFFSET_OVERFLOW \
140   BIT(m_reg[0x17], 7)
141
142#define VERTICAL_CURSOR \
143   m_reg[0x18]
144
145#define HORIZONTAL_CURSOR \
146   m_reg[0x19]
147
148#define INTERRUPT_ENABLE \
149   m_reg[0x1a]
150
151#define FRAME_TIMER \
152   BIT(m_reg[0x1a], 0)
153
154#define LIGHT_PEN_INTERRUPT \
155   BIT(m_reg[0x1a], 5)
156
157#define VERTICAL_RETRACE_INTERRUPT \
158   BIT(m_reg[0x1a], 6)
159
160#define VERTICAL_LIGHT_PEN \
161   m_reg[0x3b]
162
163#define HORIZONTAL_LIGHT_PEN \
164   m_reg[0x3c]
165
166
167// interlace
168enum
169{
170   NON_INTERLACED = 0,
171   ENHANCED_VIDEO_INTERFACE,
172   NORMAL_VIDEO_INTERFACE,
173};
174
175
176// operation modes
177enum
178{
179   OPERATION_MODE_REPETITIVE_MEMORY_ADDRESSING = 0,   // not implemented
180   OPERATION_MODE_DOUBLE_ROW_BUFFER = 1,
181   OPERATION_MODE_SINGLE_ROW_BUFFER = 4,            // not implemented
182   OPERATION_MODE_ATTRIBUTE_ASSEMBLE = 7            // not implemented
183};
184
185
186// addressing modes
187enum
188{
189   ADDRESS_MODE_SEQUENTIAL_ADDRESSING = 0,
190   ADDRESS_MODE_SEQUENTIAL_ROLL_ADDRESSING,         // not implemented
191   ADDRESS_MODE_CONTIGUOUS_ROW_TABLE,               // not implemented
192   ADDRESS_MODE_LINKED_LIST_ROW_TABLE               // not implemented
193};
194
195
196// interrupt enable register bits
197const int IE_VERTICAL_RETRACE         = 0x40;
198const int IE_LIGHT_PEN               = 0x20;
199const int IE_FRAME_TIMER            = 0x01;
200
201// status register bits
202const int STATUS_INTERRUPT_PENDING      = 0x80;
203const int STATUS_VERTICAL_RETRACE      = 0x40;
204const int STATUS_LIGHT_PEN_UPDATE      = 0x20;
205const int STATUS_ODD_EVEN            = 0x04;
206const int STATUS_FRAME_TIMER_OCCURRED   = 0x01;
207
208
209
210//**************************************************************************
211//  GLOBAL VARIABLES
212//**************************************************************************
213
214// devices
215const device_type CRT9007 = crt9007_device_config::static_alloc_device_config;
216
217
218// default address map
219static ADDRESS_MAP_START( crt9007, AS_0, 8 )
220   AM_RANGE(0x0000, 0x3fff) AM_RAM
221ADDRESS_MAP_END
222
223
224
225//**************************************************************************
226//  DEVICE CONFIGURATION
227//**************************************************************************
228
229//-------------------------------------------------
230//  crt9007_device_config - constructor
231//-------------------------------------------------
232
233crt9007_device_config::crt9007_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
234   : device_config(mconfig, static_alloc_device_config, "SMC CRT9007", tag, owner, clock),
235     device_config_memory_interface(mconfig, *this),
236     m_space_config("videoram", ENDIANNESS_LITTLE, 8, 14, 0, NULL, *ADDRESS_MAP_NAME(crt9007))
237{
238}
239
240
241//-------------------------------------------------
242//  static_alloc_device_config - allocate a new
243//  configuration object
244//-------------------------------------------------
245
246device_config *crt9007_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
247{
248   return global_alloc(crt9007_device_config(mconfig, tag, owner, clock));
249}
250
251
252//-------------------------------------------------
253//  alloc_device - allocate a new device object
254//-------------------------------------------------
255
256device_t *crt9007_device_config::alloc_device(running_machine &machine) const
257{
258   return auto_alloc(&machine, crt9007_device(machine, *this));
259}
260
261
262//-------------------------------------------------
263//  memory_space_config - return a description of
264//  any address spaces owned by this device
265//-------------------------------------------------
266
267const address_space_config *crt9007_device_config::memory_space_config(address_spacenum spacenum) const
268{
269   return (spacenum == AS_0) ? &m_space_config : NULL;
270}
271
272
273//-------------------------------------------------
274//  device_config_complete - perform any
275//  operations now that the configuration is
276//  complete
277//-------------------------------------------------
278
279void crt9007_device_config::device_config_complete()
280{
281   // inherit a copy of the static data
282   const crt9007_interface *intf = reinterpret_cast<const crt9007_interface *>(static_config());
283   if (intf != NULL)
284      *static_cast<crt9007_interface *>(this) = *intf;
285
286   // or initialize to defaults if none provided
287   else
288   {
289      memset(&out_int_func, 0, sizeof(out_int_func));
290      memset(&out_dmar_func, 0, sizeof(out_dmar_func));
291      memset(&out_vs_func, 0, sizeof(out_vs_func));
292      memset(&out_hs_func, 0, sizeof(out_hs_func));
293      memset(&out_vlt_func, 0, sizeof(out_vlt_func));
294      memset(&out_curs_func, 0, sizeof(out_curs_func));
295      memset(&out_drb_func, 0, sizeof(out_drb_func));
296      memset(&out_cblank_func, 0, sizeof(out_cblank_func));
297      memset(&out_slg_func, 0, sizeof(out_slg_func));
298      memset(&out_sld_func, 0, sizeof(out_sld_func));
299   }
300}
301
302
303
304//**************************************************************************
305//  INLINE HELPERS
306//**************************************************************************
307
308//-------------------------------------------------
309//  readbyte - read a byte at the given address
310//-------------------------------------------------
311
312inline UINT8 crt9007_device::readbyte(offs_t address)
313{
314   return space()->read_byte(address);
315}
316
317
318//-------------------------------------------------
319//  trigger_interrupt -
320//-------------------------------------------------
321
322inline void crt9007_device::trigger_interrupt(int line)
323{
324   if (INTERRUPT_ENABLE & line)
325   {
326      int status = m_status;
327
328      m_status |= STATUS_INTERRUPT_PENDING | line;
329
330      if (!(status & STATUS_INTERRUPT_PENDING))
331      {
332         if (LOG) logerror("CRT9007 '%s' INT 1\n", tag());
333         devcb_call_write_line(&m_out_int_func, ASSERT_LINE);
334      }
335   }
336}
337
338
339//-------------------------------------------------
340//  update_cblank_line -
341//-------------------------------------------------
342
343inline void crt9007_device::update_cblank_line()
344{
345   int x = m_screen->hpos();
346   int y = m_screen->vpos();
347
348   // composite blank
349   int cblank = !(m_hs & m_vs);
350
351   if (m_cblank != cblank)
352   {
353      m_cblank = cblank;
354
355      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CBLANK %u\n", tag(), y, x, m_cblank);
356
357      devcb_call_write_line(&m_out_cblank_func, m_cblank);
358   }
359}
360
361
362//-------------------------------------------------
363//  update_hsync_timer -
364//-------------------------------------------------
365
366inline void crt9007_device::update_hsync_timer(int state)
367{
368   int y = m_screen->vpos();
369
370   int next_x = state ? m_hsync_start : m_hsync_end;
371   int next_y = state ? (y + 1) % SCAN_LINES_PER_FRAME : y;
372
373   attotime duration = m_screen->time_until_pos(next_y, next_x);
374
375   m_hsync_timer->adjust(duration, !state);
376}
377
378
379//-------------------------------------------------
380//  update_vsync_timer -
381//-------------------------------------------------
382
383inline void crt9007_device::update_vsync_timer(int state)
384{
385   int next_y = state ? m_vsync_start : m_vsync_end;
386
387   attotime duration = m_screen->time_until_pos(next_y, 0);
388
389   m_vsync_timer->adjust(duration, !state);
390}
391
392
393//-------------------------------------------------
394//  update_vlt_timer -
395//-------------------------------------------------
396
397inline void crt9007_device::update_vlt_timer(int state)
398{
399   // this signal is active during all visible scan lines and during the horizontal trace at vertical retrace
400   int y = m_screen->vpos();
401
402   int next_x = state ? m_vlt_end : m_vlt_start;
403   int next_y = state ? y : ((y == m_vlt_bottom) ? 0 : (y + 1));
404
405   attotime duration = m_screen->time_until_pos(next_y, next_x);
406
407   m_vlt_timer->adjust(duration, !state);
408}
409
410
411//-------------------------------------------------
412//  update_curs_timer -
413//-------------------------------------------------
414
415inline void crt9007_device::update_curs_timer(int state)
416{
417   // this signal is active for 1 character time for all scanlines within the data row
418   // TODO
419}
420
421
422//-------------------------------------------------
423//  update_drb_timer -
424//-------------------------------------------------
425
426inline void crt9007_device::update_drb_timer(int state)
427{
428   // this signal is active for 1 full scan line (VLT edge to edge) at the top scan line of each new row
429   // there is 1 extra DRB signal during the 1st scanline of the vertical retrace interval
430   int y = m_screen->vpos();
431
432   int next_x = m_vlt_end;
433   int next_y = y ? y + 1 : y;
434
435   if (state)
436   {
437      if (y == 0)
438      {
439         next_y = VERTICAL_DELAY - 1;
440      }
441      else if (y == m_drb_bottom)
442      {
443         next_x = 0;
444         next_y = 0;
445      }
446      else
447      {
448         next_y = y + SCAN_LINES_PER_DATA_ROW - 1;
449      }
450   }
451
452   attotime duration = m_screen->time_until_pos(next_y, next_x);
453
454   m_drb_timer->adjust(duration, !state);
455}
456
457
458//-------------------------------------------------
459//  update_dma_timer -
460//-------------------------------------------------
461
462inline void crt9007_device::update_dma_timer()
463{
464   // TODO
465}
466
467
468//-------------------------------------------------
469//  recompute_parameters -
470//-------------------------------------------------
471
472inline void crt9007_device::recompute_parameters()
473{
474   // check that necessary registers have been loaded
475   if (!HAS_VALID_PARAMETERS) return;
476
477   // screen dimensions
478   int horiz_pix_total = CHARACTERS_PER_HORIZONTAL_PERIOD * m_hpixels_per_column;
479   int vert_pix_total = SCAN_LINES_PER_FRAME;
480
481   // refresh rate
482   attoseconds_t refresh = HZ_TO_ATTOSECONDS(clock()) * horiz_pix_total * vert_pix_total;
483
484   // horizontal sync
485   m_hsync_start = 0;
486   m_hsync_end = HORIZONTAL_SYNC_WIDTH * m_hpixels_per_column;
487
488   // visible line time
489   m_vlt_start = HORIZONTAL_DELAY * m_hpixels_per_column;
490   m_vlt_end = (HORIZONTAL_DELAY + CHARACTERS_PER_DATA_ROW) * m_hpixels_per_column;
491   m_vlt_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - 1;
492
493   // data row boundary
494   m_drb_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - SCAN_LINES_PER_DATA_ROW;
495
496   // vertical sync
497   m_vsync_start = 0;
498   m_vsync_end = VERTICAL_SYNC_WIDTH;
499
500   // visible area
501   rectangle visarea;
502
503   visarea.min_x = m_hsync_end;
504   visarea.max_x = horiz_pix_total - 1;
505
506   visarea.min_y = m_vsync_end;
507   visarea.max_y = vert_pix_total - 1;
508
509   if (LOG)
510   {
511      logerror("CRT9007 '%s' Screen: %u x %u @ %f Hz\n", tag(), horiz_pix_total, vert_pix_total, 1 / ATTOSECONDS_TO_DOUBLE(refresh));
512      logerror("CRT9007 '%s' Visible Area: (%u, %u) - (%u, %u)\n", tag(), visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y);
513   }
514
515   m_screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh);
516
517   m_hsync_timer->adjust(m_screen->time_until_pos(0, 0));
518   m_vsync_timer->adjust(m_screen->time_until_pos(0, 0));
519   m_vlt_timer->adjust(m_screen->time_until_pos(0, m_vlt_start), 1);
520   m_drb_timer->adjust(m_screen->time_until_pos(0, 0));
521}
522
523
524//**************************************************************************
525//  LIVE DEVICE
526//**************************************************************************
527
528//-------------------------------------------------
529//  crt9007_device - constructor
530//-------------------------------------------------
531
532crt9007_device::crt9007_device(running_machine &_machine, const crt9007_device_config &config)
533    : device_t(_machine, config),
534     device_memory_interface(_machine, config, *this),
535      m_config(config)
536{
537   for (int i = 0; i < 0x3d; i++)
538      m_reg[i] = 0;
539}
540
541
542//-------------------------------------------------
543//  device_start - device-specific startup
544//-------------------------------------------------
545
546void crt9007_device::device_start()
547{
548   // allocate timers
549   m_hsync_timer = timer_alloc(TIMER_HSYNC);
550   m_vsync_timer = timer_alloc(TIMER_VSYNC);
551   m_vlt_timer = timer_alloc(TIMER_VLT);
552   m_curs_timer = timer_alloc(TIMER_CURS);
553   m_drb_timer = timer_alloc(TIMER_DRB);
554   m_dma_timer = timer_alloc(TIMER_DMA);
555
556   // resolve callbacks
557   devcb_resolve_write_line(&m_out_int_func, &m_config.out_int_func, this);
558   devcb_resolve_write_line(&m_out_dmar_func, &m_config.out_dmar_func, this);
559   devcb_resolve_write_line(&m_out_hs_func, &m_config.out_hs_func, this);
560   devcb_resolve_write_line(&m_out_vs_func, &m_config.out_vs_func, this);
561   devcb_resolve_write_line(&m_out_vlt_func, &m_config.out_vlt_func, this);
562   devcb_resolve_write_line(&m_out_curs_func, &m_config.out_curs_func, this);
563   devcb_resolve_write_line(&m_out_drb_func, &m_config.out_drb_func, this);
564   devcb_resolve_write_line(&m_out_cblank_func, &m_config.out_cblank_func, this);
565   devcb_resolve_write_line(&m_out_slg_func, &m_config.out_slg_func, this);
566   devcb_resolve_write_line(&m_out_sld_func, &m_config.out_sld_func, this);
567
568   // get the screen device
569   m_screen = machine->device<screen_device>(m_config.screen_tag);
570   assert(m_screen != NULL);
571
572   // set horizontal pixels per column
573   m_hpixels_per_column = m_config.hpixels_per_column;
574
575   // register for state saving
576//  state_save_register_device_item(this, 0, );
577}
578
579
580//-------------------------------------------------
581//  device_reset - device-specific reset
582//-------------------------------------------------
583
584void crt9007_device::device_reset()
585{
586   m_disp = 0;
587
588   // HS = 1
589   devcb_call_write_line(&m_out_hs_func, 1);
590
591   // VS = 1
592   devcb_call_write_line(&m_out_vs_func, 1);
593
594   // CBLANK = 1
595   devcb_call_write_line(&m_out_cblank_func, 0);
596
597   // CURS = 0
598   devcb_call_write_line(&m_out_curs_func, 0);
599
600   // VLT = 0
601   devcb_call_write_line(&m_out_vlt_func, 0);
602
603   // DRB = 1
604   devcb_call_write_line(&m_out_drb_func, 1);
605
606   // INT = 0
607   devcb_call_write_line(&m_out_int_func, CLEAR_LINE);
608
609   // 28 (DMAR) = 0
610   devcb_call_write_line(&m_out_dmar_func, CLEAR_LINE);
611
612   // 29 (WBEN) = 0
613
614   // 30 (SLG) = 0
615   devcb_call_write_line(&m_out_slg_func, 0);
616
617   // 31 (SLD) = 0
618   devcb_call_write_line(&m_out_sld_func, 0);
619
620   // 32 (LPSTB) = 0
621}
622
623
624//-------------------------------------------------
625//  device_clock_changed - handle clock change
626//-------------------------------------------------
627
628void crt9007_device::device_clock_changed()
629{
630   recompute_parameters();
631}
632
633
634//-------------------------------------------------
635//  device_timer - handle timer events
636//-------------------------------------------------
637
638void crt9007_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
639{
640   int x = m_screen->hpos();
641   int y = m_screen->vpos();
642
643   switch (id)
644   {
645   case TIMER_HSYNC:
646      m_hs = param;
647
648      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : HS %u\n", tag(), y, x, m_hs);
649
650      devcb_call_write_line(&m_out_hs_func, m_hs);
651
652      update_cblank_line();
653
654      update_hsync_timer(param);
655      break;
656
657   case TIMER_VSYNC:
658      m_vs = param;
659
660      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VS %u\n", tag(), y, x, m_vs);
661
662      devcb_call_write_line(&m_out_vs_func, param);
663
664      if (m_vs)
665      {
666         // reset all other bits except Light Pen Update to logic 0
667         m_status &= STATUS_LIGHT_PEN_UPDATE;
668      }
669      else
670      {
671         trigger_interrupt(IE_VERTICAL_RETRACE);
672
673         update_cblank_line();
674      }
675
676      update_vsync_timer(param);
677      break;
678
679   case TIMER_VLT:
680      m_vlt = param;
681
682      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VLT %u\n", tag(), y, x, m_vlt);
683
684      devcb_call_write_line(&m_out_vlt_func, param);
685
686      update_vlt_timer(param);
687      break;
688
689   case TIMER_CURS:
690      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CURS %u\n", tag(), y, x, param);
691
692      devcb_call_write_line(&m_out_curs_func, param);
693
694      update_curs_timer(param);
695      break;
696
697   case TIMER_DRB:
698      m_drb = param;
699
700      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : DRB %u\n", tag(), y, x, m_drb);
701
702      devcb_call_write_line(&m_out_drb_func, param);
703
704      if (!m_drb && !DMA_DISABLE)
705      {
706         // start DMA burst sequence
707         m_dma_count = CHARACTERS_PER_DATA_ROW;
708         m_dma_burst = DMA_BURST_COUNT ? (DMA_BURST_COUNT * 4) : CHARACTERS_PER_DATA_ROW;
709         m_dma_delay = DMA_BURST_DELAY;
710         m_dmar = 1;
711
712         if (LOG) logerror("CRT9007 '%s' DMAR 1\n", tag());
713         devcb_call_write_line(&m_out_dmar_func, ASSERT_LINE);
714      }
715
716      update_drb_timer(param);
717      break;
718
719   case TIMER_DMA:
720      readbyte(AUXILIARY_ADDRESS_2);
721
722      update_dma_timer();
723      break;
724   }
725}
726
727
728//-------------------------------------------------
729//  read - register read
730//-------------------------------------------------
731
732READ8_MEMBER( crt9007_device::read )
733{
734   UINT8 data = 0;
735
736   switch (offset)
737   {
738   case 0x15:
739      if (LOG) logerror("CRT9007 '%s' Start\n", tag());
740      m_disp = 1;
741      break;
742
743   case 0x16:
744      if (LOG) logerror("CRT9007 '%s' Reset\n", tag());
745      device_reset();
746      break;
747
748   case 0x38:
749      data = VERTICAL_CURSOR;
750      break;
751
752   case 0x39:
753      data = HORIZONTAL_CURSOR;
754      break;
755
756   case 0x3a:
757      data = m_status;
758
759      // reset interrupt pending bit
760      m_status &= ~STATUS_INTERRUPT_PENDING;
761      if (LOG) logerror("CRT9007 '%s' INT 0\n", tag());
762      devcb_call_write_line(&m_out_int_func, CLEAR_LINE);
763      break;
764
765   case 0x3b:
766      data = VERTICAL_LIGHT_PEN;
767      break;
768
769   case 0x3c:
770      data = HORIZONTAL_LIGHT_PEN;
771
772      // reset light pen update bit
773      m_status &= ~STATUS_LIGHT_PEN_UPDATE;
774      break;
775
776   default:
777      logerror("CRT9007 '%s' Read from Invalid Register: %02x!\n", tag(), offset);
778   }
779
780   return data;
781}
782
783
784//-------------------------------------------------
785//  write - register write
786//-------------------------------------------------
787
788WRITE8_MEMBER( crt9007_device::write )
789{
790   m_reg[offset] = data;
791
792   switch (offset)
793   {
794   case 0x00:
795      recompute_parameters();
796      if (LOG) logerror("CRT9007 '%s' Characters per Horizontal Period: %u\n", tag(), CHARACTERS_PER_HORIZONTAL_PERIOD);
797      break;
798
799   case 0x01:
800      recompute_parameters();
801      if (LOG) logerror("CRT9007 '%s' Characters per Data Row: %u\n", tag(), CHARACTERS_PER_DATA_ROW);
802      break;
803
804   case 0x02:
805      recompute_parameters();
806      if (LOG) logerror("CRT9007 '%s' Horizontal Delay: %u\n", tag(), HORIZONTAL_DELAY);
807      break;
808
809   case 0x03:
810      recompute_parameters();
811      if (LOG) logerror("CRT9007 '%s' Horizontal Sync Width: %u\n", tag(), HORIZONTAL_SYNC_WIDTH);
812      break;
813
814   case 0x04:
815      recompute_parameters();
816      if (LOG) logerror("CRT9007 '%s' Vertical Sync Width: %u\n", tag(), VERTICAL_SYNC_WIDTH);
817      break;
818
819   case 0x05:
820      recompute_parameters();
821      if (LOG) logerror("CRT9007 '%s' Vertical Delay: %u\n", tag(), VERTICAL_DELAY);
822      break;
823
824   case 0x06:
825      recompute_parameters();
826      if (LOG)
827      {
828         logerror("CRT9007 '%s' Pin Configuration: %u\n", tag(), PIN_CONFIGURATION);
829         logerror("CRT9007 '%s' Cursor Skew: %u\n", tag(), CURSOR_SKEW);
830         logerror("CRT9007 '%s' Blank Skew: %u\n", tag(), BLANK_SKEW);
831      }
832      break;
833
834   case 0x07:
835      recompute_parameters();
836      if (LOG) logerror("CRT9007 '%s' Visible Data Rows per Frame: %u\n", tag(), VISIBLE_DATA_ROWS_PER_FRAME);
837      break;
838
839   case 0x08:
840      recompute_parameters();
841      if (LOG) logerror("CRT9007 '%s' Scan Lines per Data Row: %u\n", tag(), SCAN_LINES_PER_DATA_ROW);
842      break;
843
844   case 0x09:
845      recompute_parameters();
846      if (LOG) logerror("CRT9007 '%s' Scan Lines per Frame: %u\n", tag(), SCAN_LINES_PER_FRAME);
847      break;
848
849   case 0x0a:
850      if (LOG)
851      {
852         logerror("CRT9007 '%s' DMA Burst Count: %u\n", tag(), DMA_BURST_COUNT);
853         logerror("CRT9007 '%s' DMA Burst Delay: %u\n", tag(), DMA_BURST_DELAY);
854         logerror("CRT9007 '%s' DMA Disable: %u\n", tag(), DMA_DISABLE);
855      }
856      break;
857
858   case 0x0b:
859      if (LOG)
860      {
861         logerror("CRT9007 '%s' %s Height Cursor\n", tag(), SINGLE_HEIGHT_CURSOR ? "Single" : "Double");
862         logerror("CRT9007 '%s' Operation Mode: %u\n", tag(), OPERATION_MODE);
863         logerror("CRT9007 '%s' Interlace Mode: %u\n", tag(), INTERLACE_MODE);
864         logerror("CRT9007 '%s' %s Mechanism\n", tag(), PAGE_BLANK ? "Page Blank" : "Smooth Scroll");
865      }
866      break;
867
868   case 0x0c:
869      break;
870
871   case 0x0d:
872      if (LOG)
873      {
874         logerror("CRT9007 '%s' Table Start Register: %04x\n", tag(), TABLE_START);
875         logerror("CRT9007 '%s' Address Mode: %u\n", tag(), ADDRESS_MODE);
876      }
877      break;
878
879   case 0x0e:
880      break;
881
882   case 0x0f:
883      if (LOG)
884      {
885         logerror("CRT9007 '%s' Auxialiary Address Register 1: %04x\n", tag(), AUXILIARY_ADDRESS_1);
886         logerror("CRT9007 '%s' Row Attributes: %u\n", tag(), ROW_ATTRIBUTES_1);
887      }
888      break;
889
890   case 0x10:
891      if (LOG) logerror("CRT9007 '%s' Sequential Break Register 1: %u\n", tag(), SEQUENTIAL_BREAK_1);
892      break;
893
894   case 0x11:
895      if (LOG) logerror("CRT9007 '%s' Data Row Start Register: %u\n", tag(), DATA_ROW_START);
896      break;
897
898   case 0x12:
899      if (LOG) logerror("CRT9007 '%s' Data Row End/Sequential Break Register 2: %u\n", tag(), SEQUENTIAL_BREAK_2);
900      break;
901
902   case 0x13:
903      break;
904
905   case 0x14:
906      if (LOG)
907      {
908         logerror("CRT9007 '%s' Auxiliary Address Register 2: %04x\n", tag(), AUXILIARY_ADDRESS_2);
909         logerror("CRT9007 '%s' Row Attributes: %u\n", tag(), ROW_ATTRIBUTES_2);
910      }
911      break;
912
913   case 0x15:
914      if (LOG) logerror("CRT9007 '%s' Start\n", tag());
915      m_disp = 1;
916      break;
917
918   case 0x16:
919      if (LOG) logerror("CRT9007 '%s' Reset\n", tag());
920      device_reset();
921      break;
922
923   case 0x17:
924      if (LOG)
925      {
926         logerror("CRT9007 '%s' Smooth Scroll Offset: %u\n", tag(), SMOOTH_SCROLL_OFFSET);
927         logerror("CRT9007 '%s' Smooth Scroll Offset Overflow: %u\n", tag(), SMOOTH_SCROLL_OFFSET_OVERFLOW);
928      }
929      break;
930
931   case 0x18:
932      if (LOG) logerror("CRT9007 '%s' Vertical Cursor Register: %u\n", tag(), VERTICAL_CURSOR);
933      break;
934
935   case 0x19:
936      if (LOG) logerror("CRT9007 '%s' Horizontal Cursor Register: %u\n", tag(), HORIZONTAL_CURSOR);
937      break;
938
939   case 0x1a:
940      if (LOG)
941      {
942         logerror("CRT9007 '%s' Frame Timer: %u\n", tag(), FRAME_TIMER);
943         logerror("CRT9007 '%s' Light Pen Interrupt: %u\n", tag(), LIGHT_PEN_INTERRUPT);
944         logerror("CRT9007 '%s' Vertical Retrace Interrupt: %u\n", tag(), VERTICAL_RETRACE_INTERRUPT);
945      }
946      break;
947
948   default:
949      logerror("CRT9007 '%s' Write to Invalid Register: %02x!\n", tag(), offset);
950   }
951}
952
953
954//-------------------------------------------------
955//  ack_w - DMA acknowledge
956//-------------------------------------------------
957
958WRITE_LINE_MEMBER( crt9007_device::ack_w )
959{
960   if (LOG) logerror("CRT9007 '%s' ACK: %u\n", tag(), state);
961
962   if (m_dmar && !m_ack && state)
963   {
964      // start DMA transfer
965      m_dma_timer->adjust(attotime::from_hz(clock()));
966   }
967
968   m_ack = state;
969}
970
971
972//-------------------------------------------------
973//  lpstb_w - light pen strobe
974//-------------------------------------------------
975
976WRITE_LINE_MEMBER( crt9007_device::lpstb_w )
977{
978   if (LOG) logerror("CRT9007 '%s' LPSTB: %u\n", tag(), state);
979
980   if (!m_lpstb && state)
981   {
982      // TODO latch current row/column position
983   }
984
985   m_lpstb = state;
986}
987
988
989//-------------------------------------------------
990//  vlt_r -
991//-------------------------------------------------
992
993READ_LINE_MEMBER( crt9007_device::vlt_r )
994{
995   return m_vlt;
996}
997
998
999//-------------------------------------------------
1000//  wben_r -
1001//-------------------------------------------------
1002
1003READ_LINE_MEMBER( crt9007_device::wben_r )
1004{
1005   return m_wben;
1006}
1007
1008
1009//-------------------------------------------------
1010//  set_hpixels_per_column -
1011//-------------------------------------------------
1012
1013void crt9007_device::set_hpixels_per_column(int hpixels_per_column)
1014{
1015   m_hpixels_per_column = hpixels_per_column;
1016   recompute_parameters();
1017}
src/emu/video/crt9021.h
r0r10969
1/**********************************************************************
2
3    SMC CRT9021 Video Attributes Controller (VAC) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                    D0   1 |*    \_/     | 28  D1
11                   MS0   2 |             | 27  D2
12                   MS1   3 |             | 26  D3
13                 REVID   4 |             | 25  D4
14                 CHABL   5 |             | 24  D5
15                 BLINK   6 |             | 23  D6
16                 INTIN   7 |   CRT9021   | 22  D7
17                   +5V   8 |             | 21  _VSYNC
18                 ATTEN   9 |             | 20  GND
19                INTOUT  10 |             | 19  SL0/SLD
20                CURSOR  11 |             | 18  SL1/_SLG
21                 RETBL  12 |             | 17  SL2/BLC
22                _LD/SH  13 |             | 16  SL3/BKC
23                 VIDEO  14 |_____________| 15  VDC
24
25**********************************************************************/
26
27#pragma once
28
29#ifndef __CRT9021__
30#define __CRT9021__
31
32#include "emu.h"
33
34
35
36//**************************************************************************
37//  MACROS / CONSTANTS
38//**************************************************************************
39
40
41
42
43//**************************************************************************
44//  INTERFACE CONFIGURATION MACROS
45//**************************************************************************
46
47#define MCFG_CRT9021_ADD(_tag, _clock, _config) \
48   MCFG_DEVICE_ADD(_tag, CRT9021, _clock) \
49   MCFG_DEVICE_CONFIG(_config)
50
51
52#define CRT9021_INTERFACE(name) \
53   const crt9021_interface (name) =
54
55
56
57//**************************************************************************
58//  TYPE DEFINITIONS
59//**************************************************************************
60
61
62// ======================> crt9021_interface
63
64struct crt9021_interface
65{
66   const char *screen_tag;      /* screen we are acting on */
67
68   devcb_read8            in_data_func;
69   devcb_read8            in_attr_func;
70
71   devcb_read_line         in_atten_func;
72};
73
74
75
76// ======================> crt9021_device_config
77
78class crt9021_device_config :   public device_config,
79                                public crt9021_interface
80{
81    friend class crt9021_device;
82
83    // construction/destruction
84    crt9021_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
85
86public:
87    // allocators
88    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
89    virtual device_t *alloc_device(running_machine &machine) const;
90
91protected:
92   // device_config overrides
93   virtual void device_config_complete();
94};
95
96
97
98// ======================> crt9021_device
99
100class crt9021_device :   public device_t
101{
102    friend class crt9021_device_config;
103
104    // construction/destruction
105    crt9021_device(running_machine &_machine, const crt9021_device_config &_config);
106
107public:
108   DECLARE_WRITE_LINE_MEMBER( slg_w );
109   DECLARE_WRITE_LINE_MEMBER( sld_w );
110   DECLARE_WRITE_LINE_MEMBER( cursor_w );
111   DECLARE_WRITE_LINE_MEMBER( retbl_w );
112   DECLARE_WRITE_LINE_MEMBER( vsync_w );
113
114   void update_screen(bitmap_t *bitmap, const rectangle *cliprect);
115
116protected:
117    // device-level overrides
118    virtual void device_start();
119   virtual void device_clock_changed();
120   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
121
122private:
123   devcb_resolved_read8         m_in_data_func;
124   devcb_resolved_read8         m_in_attr_func;
125   devcb_resolved_read_line      m_in_atten_func;
126
127   screen_device *m_screen;
128
129   int m_slg;
130   int m_sld;
131   int m_cursor;
132   int m_retbl;
133   int m_vsync;
134
135   const crt9021_device_config &m_config;
136};
137
138
139// device type definition
140extern const device_type CRT9021;
141
142
143
144#endif
src/emu/video/crt9007.h
r0r10969
1/**********************************************************************
2
3    SMC CRT9007 CRT Video Processor and Controller (VPAC) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                   VA2   1 |*    \_/     | 40  GND
11                  VA10   2 |             | 39  VA9
12                   VA3   3 |             | 38  VA1
13                  VA11   4 |             | 37  VA8
14                  VA12   5 |             | 36  VA0
15                   VA4   6 |             | 35  CBLANK
16                  VA13   7 |             | 34  CURS
17                   VA5   8 |             | 33  ACK/_TSC
18                   VA6   9 |             | 32  _CSYNC/LPSTB
19                   VA7  10 |   CRT9007   | 31  SLD/SL0
20                   VLT  11 |             | 30  _SLG/SL1
21                   _VS  12 |             | 29  WBEN/SL2/_CSYNC
22                   _HS  13 |             | 28  DMAR/SL3/VBLANK
23                 _CCLK  14 |             | 27  INT
24                  _DRB  15 |             | 26  _RST
25                   VD7  16 |             | 25  _CS
26                   VD6  17 |             | 24  VD0
27                   VD5  18 |             | 23  VD1
28                   VD4  19 |             | 22  VD2
29                   VD3  20 |_____________| 21  +5V
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __CRT9007__
36#define __CRT9007__
37
38#include "emu.h"
39
40
41
42//**************************************************************************
43//  MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
53#define MCFG_CRT9007_ADD(_tag, _clock, _config, _map) \
54   MCFG_DEVICE_ADD(_tag, CRT9007, _clock) \
55   MCFG_DEVICE_CONFIG(_config) \
56   MCFG_DEVICE_ADDRESS_MAP(AS_0, _map)
57
58
59#define CRT9007_INTERFACE(name) \
60   const crt9007_interface (name) =
61
62
63
64//**************************************************************************
65//  TYPE DEFINITIONS
66//**************************************************************************
67
68
69// ======================> crt9007_interface
70
71struct crt9007_interface
72{
73   const char *screen_tag;      /* screen we are acting on */
74   int hpixels_per_column;      /* number of pixels per video memory address */
75
76   devcb_write_line      out_int_func;
77   devcb_write_line      out_dmar_func;
78
79   devcb_write_line      out_vs_func;
80   devcb_write_line      out_hs_func;
81
82   devcb_write_line        out_vlt_func;
83    devcb_write_line        out_curs_func;
84    devcb_write_line        out_drb_func;
85    devcb_write_line        out_cblank_func;
86
87   devcb_write_line        out_slg_func;
88   devcb_write_line        out_sld_func;
89};
90
91
92
93// ======================> crt9007_device_config
94
95class crt9007_device_config :   public device_config,
96                        public device_config_memory_interface,
97                                public crt9007_interface
98{
99    friend class crt9007_device;
100
101    // construction/destruction
102    crt9007_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
103
104public:
105    // allocators
106    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
107    virtual device_t *alloc_device(running_machine &machine) const;
108
109protected:
110   // device_config overrides
111   virtual void device_config_complete();
112
113   // device_config_memory_interface overrides
114   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
115
116    // address space configurations
117   const address_space_config      m_space_config;
118};
119
120
121
122// ======================> crt9007_device
123
124class crt9007_device :   public device_t,
125                  public device_memory_interface
126{
127    friend class crt9007_device_config;
128
129    // construction/destruction
130    crt9007_device(running_machine &_machine, const crt9007_device_config &_config);
131
132public:
133    DECLARE_READ8_MEMBER( read );
134    DECLARE_WRITE8_MEMBER( write );
135   DECLARE_WRITE_LINE_MEMBER( ack_w );
136   DECLARE_WRITE_LINE_MEMBER( lpstb_w );
137   DECLARE_READ_LINE_MEMBER( vlt_r );
138   DECLARE_READ_LINE_MEMBER( wben_r );
139
140   void set_hpixels_per_column(int hpixels_per_column);
141
142protected:
143    // device-level overrides
144    virtual void device_start();
145    virtual void device_reset();
146   virtual void device_clock_changed();
147   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
148
149private:
150   static const device_timer_id TIMER_HSYNC = 0;
151   static const device_timer_id TIMER_VSYNC = 1;
152   static const device_timer_id TIMER_VLT = 2;
153   static const device_timer_id TIMER_CURS = 3;
154   static const device_timer_id TIMER_DRB = 4;
155   static const device_timer_id TIMER_DMA = 5;
156
157   inline UINT8 readbyte(offs_t address);
158
159   inline void trigger_interrupt(int line);
160   inline void update_cblank_line();
161   inline void update_hsync_timer(int state);
162   inline void update_vsync_timer(int state);
163   inline void update_vlt_timer(int state);
164   inline void update_curs_timer(int state);
165   inline void update_drb_timer(int state);
166   inline void update_dma_timer();
167
168   inline void recompute_parameters();
169
170   devcb_resolved_write_line   m_out_int_func;
171   devcb_resolved_write_line   m_out_dmar_func;
172   devcb_resolved_write_line   m_out_hs_func;
173   devcb_resolved_write_line   m_out_vs_func;
174   devcb_resolved_write_line   m_out_vlt_func;
175   devcb_resolved_write_line   m_out_curs_func;
176   devcb_resolved_write_line   m_out_drb_func;
177   devcb_resolved_write_line   m_out_cblank_func;
178   devcb_resolved_write_line   m_out_slg_func;
179   devcb_resolved_write_line   m_out_sld_func;
180
181   screen_device *m_screen;
182
183   // registers
184   UINT8 m_reg[0x3d];
185   UINT8 m_status;
186
187   int m_disp;
188   int m_hpixels_per_column;
189
190   // runtime variables, do not state save
191   int m_vsync_start;
192   int m_vsync_end;
193   int m_hsync_start;
194   int m_hsync_end;
195   int m_vlt_start;
196   int m_vlt_end;
197   int m_vlt_bottom;
198   int m_drb_bottom;
199   int m_hs;
200   int m_vs;
201   int m_cblank;
202   int m_vlt;
203   int m_drb;
204   int m_wben;
205   int m_slg;
206   int m_sld;
207   int m_lpstb;
208
209   // DMA
210   int m_dmar;
211   int m_ack;
212   int m_dma_count;
213   int m_dma_burst;
214   int m_dma_delay;
215
216   // timers
217   emu_timer *m_vsync_timer;
218   emu_timer *m_hsync_timer;
219   emu_timer *m_vlt_timer;
220   emu_timer *m_curs_timer;
221   emu_timer *m_drb_timer;
222   emu_timer *m_dma_timer;
223
224   const crt9007_device_config &m_config;
225};
226
227
228// device type definition
229extern const device_type CRT9007;
230
231
232
233#endif
src/emu/video/hd61830.c
r0r10969
1/**********************************************************************
2
3    HD61830 LCD Timing Controller emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "hd61830.h"
12
13
14
15//**************************************************************************
16//  MACROS / CONSTANTS
17//**************************************************************************
18
19#define LOG 0
20
21enum
22{
23   INSTRUCTION_MODE_CONTROL = 0,
24   INSTRUCTION_CHARACTER_PITCH,
25   INSTRUCTION_NUMBER_OF_CHARACTERS,
26   INSTRUCTION_NUMBER_OF_TIME_DIVISIONS,
27   INSTRUCTION_CURSOR_POSITION,
28   INSTRUCTION_DISPLAY_START_LOW = 8,
29   INSTRUCTION_DISPLAY_START_HIGH,
30   INSTRUCTION_CURSOR_ADDRESS_LOW,
31   INSTRUCTION_CURSOR_ADDRESS_HIGH,
32   INSTRUCTION_DISPLAY_DATA_WRITE,
33   INSTRUCTION_DISPLAY_DATA_READ,
34   INSTRUCTION_CLEAR_BIT,
35   INSTRUCTION_SET_BIT
36};
37
38static const int CYCLES[] =
39{
40   4, 4, 4, 4, 4, -1, -1, -1, 4, 4, 4, 4, 6, 6, 36, 36
41};
42
43const int MODE_EXTERNAL_CG      = 0x01;
44const int MODE_GRAPHIC         = 0x02;
45const int MODE_CURSOR         = 0x04;
46const int MODE_BLINK         = 0x08;
47const int MODE_MASTER         = 0x10;
48const int MODE_DISPLAY_ON      = 0x20;
49
50
51
52//**************************************************************************
53//  GLOBAL VARIABLES
54//**************************************************************************
55
56// devices
57const device_type HD61830 = hd61830_device_config::static_alloc_device_config;
58
59
60// default address map
61static ADDRESS_MAP_START( hd61830, AS_0, 8 )
62   AM_RANGE(0x0000, 0xffff) AM_RAM
63ADDRESS_MAP_END
64
65
66// internal character generator ROM
67ROM_START( hd61830 )
68   ROM_REGION( 0x5c0, "hd61830", ROMREGION_LOADBYNAME ) // internal 7360-bit chargen ROM
69   ROM_LOAD( "hd61830.bin", 0x000, 0x5c0, BAD_DUMP CRC(06a934da) SHA1(bf3f074db5dc92e6f530cb18d6c013563099a87d) ) // typed in from manual
70ROM_END
71
72
73
74//**************************************************************************
75//  DEVICE CONFIGURATION
76//**************************************************************************
77
78//-------------------------------------------------
79//  hd61830_device_config - constructor
80//-------------------------------------------------
81
82hd61830_device_config::hd61830_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
83   : device_config(mconfig, static_alloc_device_config, "Hitachi HD61830", tag, owner, clock),
84     device_config_memory_interface(mconfig, *this),
85     m_space_config("videoram", ENDIANNESS_LITTLE, 8, 16, 0, NULL, *ADDRESS_MAP_NAME(hd61830))
86{
87   m_shortname = "hd61830";
88}
89
90
91//-------------------------------------------------
92//  static_alloc_device_config - allocate a new
93//  configuration object
94//-------------------------------------------------
95
96device_config *hd61830_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
97{
98   return global_alloc(hd61830_device_config(mconfig, tag, owner, clock));
99}
100
101
102//-------------------------------------------------
103//  alloc_device - allocate a new device object
104//-------------------------------------------------
105
106device_t *hd61830_device_config::alloc_device(running_machine &machine) const
107{
108   return auto_alloc(&machine, hd61830_device(machine, *this));
109}
110
111
112//-------------------------------------------------
113//  memory_space_config - return a description of
114//  any address spaces owned by this device
115//-------------------------------------------------
116
117const address_space_config *hd61830_device_config::memory_space_config(address_spacenum spacenum) const
118{
119   return (spacenum == AS_0) ? &m_space_config : NULL;
120}
121
122
123//-------------------------------------------------
124//  rom_region - device-specific ROM region
125//-------------------------------------------------
126
127const rom_entry *hd61830_device_config::rom_region() const
128{
129   return ROM_NAME(hd61830);
130}
131
132
133//-------------------------------------------------
134//  device_config_complete - perform any
135//  operations now that the configuration is
136//  complete
137//-------------------------------------------------
138
139void hd61830_device_config::device_config_complete()
140{
141   // inherit a copy of the static data
142   const hd61830_interface *intf = reinterpret_cast<const hd61830_interface *>(static_config());
143   if (intf != NULL)
144      *static_cast<hd61830_interface *>(this) = *intf;
145
146   // or initialize to defaults if none provided
147   else
148   {
149      memset(&m_in_rd_func, 0, sizeof(m_in_rd_func));
150   }
151}
152
153
154
155//**************************************************************************
156//  INLINE HELPERS
157//**************************************************************************
158
159//-------------------------------------------------
160//  readbyte - read a byte at the given address
161//-------------------------------------------------
162
163inline UINT8 hd61830_device::readbyte(offs_t address)
164{
165   return space()->read_byte(address);
166}
167
168
169//-------------------------------------------------
170//  writebyte - write a byte at the given address
171//-------------------------------------------------
172
173inline void hd61830_device::writebyte(offs_t address, UINT8 data)
174{
175   space()->write_byte(address, data);
176}
177
178
179
180//**************************************************************************
181//  LIVE DEVICE
182//**************************************************************************
183
184//-------------------------------------------------
185//  hd61830_device - constructor
186//-------------------------------------------------
187
188hd61830_device::hd61830_device(running_machine &_machine, const hd61830_device_config &config)
189    : device_t(_machine, config),
190     device_memory_interface(_machine, config, *this),
191     m_bf(false),
192     m_blink(0),
193      m_config(config)
194{
195
196}
197
198
199//-------------------------------------------------
200//  device_start - device-specific startup
201//-------------------------------------------------
202
203void hd61830_device::device_start()
204{
205   // allocate timers
206   m_busy_timer = timer_alloc();
207
208   // resolve callbacks
209    devcb_resolve_read8(&m_in_rd_func, &m_config.m_in_rd_func, this);
210
211   m_screen = machine->device<screen_device>(m_config.screen_tag);
212
213   // register for state saving
214   save_item(NAME(m_bf));
215   save_item(NAME(m_ir));
216   save_item(NAME(m_mcr));
217   save_item(NAME(m_dor));
218   save_item(NAME(m_cac));
219   save_item(NAME(m_dsa));
220   save_item(NAME(m_vp));
221   save_item(NAME(m_hp));
222   save_item(NAME(m_hn));
223   save_item(NAME(m_nx));
224   save_item(NAME(m_cp));
225   save_item(NAME(m_blink));
226   save_item(NAME(m_cursor));
227}
228
229
230//-------------------------------------------------
231//  device_reset - device-specific reset
232//-------------------------------------------------
233
234void hd61830_device::device_reset()
235{
236   // display off, slave mode
237   m_mcr &= ~(MODE_MASTER | MODE_DISPLAY_ON);
238
239   // default horizontal pitch
240   m_hp = 6;
241}
242
243
244//-------------------------------------------------
245//  device_timer - handler timer events
246//-------------------------------------------------
247
248void hd61830_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
249{
250   // clear busy flag
251   m_bf = false;
252}
253
254
255/*-------------------------------------------------
256    set_busy_flag - set busy flag and arm timer
257                    to clear it later
258-------------------------------------------------*/
259
260void hd61830_device::set_busy_flag()
261{
262   // set busy flag
263   m_bf = true;
264
265   // adjust busy timer
266   m_busy_timer->adjust(attotime::from_usec(CYCLES[m_ir]));
267}
268
269
270//-------------------------------------------------
271//  status_r - status register read
272//-------------------------------------------------
273
274READ8_MEMBER( hd61830_device::status_r )
275{
276   if (LOG) logerror("HD61830 '%s' Status Read: %s\n", tag(), m_bf ? "busy" : "ready");
277
278   return m_bf ? 0x80 : 0;
279}
280
281
282//-------------------------------------------------
283//  control_w - instruction register write
284//-------------------------------------------------
285
286WRITE8_MEMBER( hd61830_device::control_w )
287{
288   m_ir = data;
289}
290
291
292//-------------------------------------------------
293//  data_r - data register read
294//-------------------------------------------------
295
296READ8_MEMBER( hd61830_device::data_r )
297{
298   UINT8 data = m_dor;
299
300   if (LOG) logerror("HD61830 '%s' Display Data Read %02x\n", tag(), m_dor);
301
302   m_dor = readbyte(m_cac);
303
304   m_cac++;
305
306   return data;
307}
308
309
310//-------------------------------------------------
311//  data_w - data register write
312//-------------------------------------------------
313
314WRITE8_MEMBER( hd61830_device::data_w )
315{
316   if (m_bf)
317   {
318      logerror("HD61830 '%s' Ignoring data write %02x due to business\n", tag(), data);
319      return;
320   }
321
322   switch (m_ir)
323   {
324   case INSTRUCTION_MODE_CONTROL:
325      m_mcr = data;
326
327      if (LOG)
328      {
329         logerror("HD61830 '%s' %s CG\n", tag(), (data & MODE_EXTERNAL_CG) ? "External" : "Internal");
330         logerror("HD61830 '%s' %s Display Mode\n", tag(), (data & MODE_GRAPHIC) ? "Graphic" : "Character");
331         logerror("HD61830 '%s' %s Mode\n", tag(), (data & MODE_MASTER) ? "Master" : "Slave");
332         logerror("HD61830 '%s' Cursor %s\n", tag(), (data & MODE_CURSOR) ? "On" : "Off");
333         logerror("HD61830 '%s' Blink %s\n", tag(), (data & MODE_BLINK) ? "On" : "Off");
334         logerror("HD61830 '%s' Display %s\n", tag(), (data & MODE_DISPLAY_ON) ? "On" : "Off");
335      }
336      break;
337
338   case INSTRUCTION_CHARACTER_PITCH:
339      m_hp = (data & 0x07) + 1;
340      m_vp = (data >> 4) + 1;
341
342      if (LOG) logerror("HD61830 '%s' Horizontal Character Pitch: %u\n", tag(), m_hp);
343      if (LOG) logerror("HD61830 '%s' Vertical Character Pitch: %u\n", tag(), m_vp);
344      break;
345
346   case INSTRUCTION_NUMBER_OF_CHARACTERS:
347      m_hn = (data & 0x7f) + 1;
348
349      if (LOG) logerror("HD61830 '%s' Number of Characters: %u\n", tag(), m_hn);
350      break;
351
352   case INSTRUCTION_NUMBER_OF_TIME_DIVISIONS:
353      m_nx = (data & 0x7f) + 1;
354
355      if (LOG) logerror("HD61830 '%s' Number of Time Divisions: %u\n", tag(), m_nx);
356      break;
357
358   case INSTRUCTION_CURSOR_POSITION:
359      m_cp = (data & 0x7f) + 1;
360
361      if (LOG) logerror("HD61830 '%s' Cursor Position: %u\n", tag(), m_cp);
362      break;
363
364   case INSTRUCTION_DISPLAY_START_LOW:
365      m_dsa = (m_dsa & 0xff00) | data;
366
367      if (LOG) logerror("HD61830 '%s' Display Start Address Low %04x\n", tag(), m_dsa);
368      break;
369
370   case INSTRUCTION_DISPLAY_START_HIGH:
371      m_dsa = (data << 8) | (m_dsa & 0xff);
372
373      if (LOG) logerror("HD61830 '%s' Display Start Address High %04x\n", tag(), m_dsa);
374      break;
375
376   case INSTRUCTION_CURSOR_ADDRESS_LOW:
377      if (BIT(m_cac, 7) && !BIT(data, 7))
378      {
379         m_cac = (((m_cac >> 8) + 1) << 8) | data;
380      }
381      else
382      {
383         m_cac = (m_cac & 0xff00) | data;
384      }
385
386      if (LOG) logerror("HD61830 '%s' Cursor Address Low %02x: %04x\n", tag(), data, m_cac);
387      break;
388
389   case INSTRUCTION_CURSOR_ADDRESS_HIGH:
390      m_cac = (data << 8) | (m_cac & 0xff);
391
392      if (LOG) logerror("HD61830 '%s' Cursor Address High %02x: %04x\n", tag(), data, m_cac);
393      break;
394
395   case INSTRUCTION_DISPLAY_DATA_WRITE:
396      writebyte(m_cac, data);
397
398      if (LOG) logerror("HD61830 '%s' Display Data Write %02x -> %04x row %u col %u\n", tag(), data, m_cac, m_cac / 40, m_cac % 40);
399
400      m_cac++;
401      break;
402
403   case INSTRUCTION_CLEAR_BIT:
404      {
405      int bit = data & 0x07;
406      UINT8 md = readbyte(m_cac);
407
408      md &= ~(1 << bit);
409
410      if (LOG) logerror("HD61830 '%s' Clear Bit %u at %04x\n", tag(), bit + 1, m_cac);
411
412      writebyte(m_cac, md);
413
414      m_cac++;
415      }
416      break;
417
418   case INSTRUCTION_SET_BIT:
419      {
420      int bit = data & 0x07;
421      UINT8 md = readbyte(m_cac);
422
423      md |= 1 << bit;
424
425      if (LOG) logerror("HD61830 '%s' Set Bit %u at %04x\n", tag(), bit + 1, m_cac);
426
427      writebyte(m_cac, md);
428
429      m_cac++;
430      }
431      break;
432
433   default:
434      logerror("HD61830 '%s' Illegal Instruction %02x!\n", tag(), m_ir);
435      return;
436   }
437
438   // burn cycles
439   set_busy_flag();
440}
441
442
443//-------------------------------------------------
444//  draw_scanline - draw one graphics scanline
445//-------------------------------------------------
446
447void hd61830_device::draw_scanline(bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ra)
448{
449   for (int sx = 0; sx < m_hn; sx++)
450   {
451      UINT8 data = readbyte(ra++);
452
453      for (int x = 0; x < m_hp; x++)
454      {
455         *BITMAP_ADDR16(bitmap, y, (sx * m_hp) + x) = BIT(data, x);
456      }
457   }
458}
459
460
461//-------------------------------------------------
462//  update_graphics - draw graphics mode screen
463//-------------------------------------------------
464
465void hd61830_device::update_graphics(bitmap_t *bitmap, const rectangle *cliprect)
466{
467   for (int y = 0; y < m_nx; y++)
468   {
469      UINT16 rac1 = m_dsa + (y * m_hn);
470      UINT16 rac2 = rac1 + (m_nx * m_hn);
471
472      /* draw upper half scanline */
473      draw_scanline(bitmap, cliprect, y, rac1);
474
475      /* draw lower half scanline */
476      draw_scanline(bitmap, cliprect, y + m_nx, rac2);
477   }
478}
479
480
481//-------------------------------------------------
482//  draw_char - draw a char
483//-------------------------------------------------
484
485void hd61830_device::draw_char(bitmap_t *bitmap, const rectangle *cliprect, UINT16 ma, int x, int y, UINT8 md)
486{
487   for (int cl = 0; cl < m_vp; cl++)
488   {
489      for (int cr = 0; cr < m_hp; cr++)
490      {
491         int sy = y * m_vp + cl;
492         int sx = x * m_hp + cr;
493         UINT8 data = 0;
494
495         if (m_mcr & MODE_EXTERNAL_CG)
496         {
497            data = devcb_call_read8(&m_in_rd_func, (cl << 12) | md);
498         }
499         else
500         {
501            UINT16 addr = 0;
502
503            if (md >= 0x20 && md < 0x80 && cl < 7)
504            {
505               // 5x7 characters 0x20..0x7f
506               addr = (md - 0x20) * 7 + cl;
507            }
508            else if (md >= 0xa0 && md < 0xe0 && cl < 7)
509            {
510               // 5x7 characters 0xa0..0xdf
511               addr = 96*7 + (md - 0xa0) * 7 + cl;
512            }
513            else if (md >= 0xe0 && cl < 11)
514            {
515               // 5x11 characters 0xe0..0xff
516               addr = 160*7 + (md - 0xe0) * 11 + cl;
517            }
518
519            data = subregion("hd61830")->u8(addr);
520         }
521
522         int cursor = m_mcr & MODE_CURSOR;
523         int blink = m_mcr & MODE_BLINK;
524
525         // cursor off
526         int pixel = BIT(data, cr);
527
528         if (blink && (ma == m_cac))
529         {
530            // cursor off, character blink
531            if (!cursor)
532               pixel = m_cursor ? pixel : 0;
533
534            // cursor blink
535            if (cursor && (cl == m_cp))
536               pixel = m_cursor ? 1 : 0;
537         }
538         else
539         {
540            // cursor on
541            if (cursor && (cl == m_cp))
542               pixel = m_cursor ? 1 : 0;
543         }
544
545         if (sy < m_screen->height() && sx < m_screen->width())
546            *BITMAP_ADDR16(bitmap, sy, sx) = pixel;
547      }
548   }
549}
550
551
552//-------------------------------------------------
553//  update_text - draw text mode screen
554//-------------------------------------------------
555
556void hd61830_device::update_text(bitmap_t *bitmap, const rectangle *cliprect)
557{
558   for (int y = 0; y < (m_nx / m_vp); y++)
559   {
560      for (int x = 0; x < m_hn; x++)
561      {
562         UINT16 ma = y * m_hn + x;
563         UINT8 md = readbyte(ma);
564
565         draw_char(bitmap, cliprect, ma, x, y, md);
566      }
567   }
568}
569
570
571//-------------------------------------------------
572//  update_screen - update screen
573//-------------------------------------------------
574
575void hd61830_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect)
576{
577   if (m_mcr & MODE_DISPLAY_ON)
578   {
579      if (m_mcr & MODE_GRAPHIC)
580      {
581         update_graphics(bitmap, cliprect);
582      }
583      else
584      {
585         update_text(bitmap, cliprect);
586      }
587   }
588   else
589   {
590      bitmap_fill(bitmap, cliprect, 0);
591   }
592
593   m_blink++;
594
595   if (m_blink == 0x20)
596   {
597      m_blink = 0;
598      m_cursor = !m_cursor;
599   }
600}
src/emu/video/hd61830.h
r0r10969
1/**********************************************************************
2
3    HD61830 LCD Timing Controller emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#pragma once
11
12#ifndef __HD61830__
13#define __HD61830__
14
15#include "emu.h"
16
17
18
19//**************************************************************************
20//  MACROS / CONSTANTS
21//**************************************************************************
22
23
24
25
26//**************************************************************************
27//  INTERFACE CONFIGURATION MACROS
28//**************************************************************************
29
30#define MCFG_HD61830_ADD(_tag, _clock, _config) \
31   MCFG_DEVICE_ADD(_tag, HD61830, _clock) \
32   MCFG_DEVICE_CONFIG(_config)
33
34
35#define HD61830_INTERFACE(name) \
36   const hd61830_interface (name) =
37
38
39
40//**************************************************************************
41//  TYPE DEFINITIONS
42//**************************************************************************
43
44// ======================> hd61830_interface
45
46struct hd61830_interface
47{
48   const char *screen_tag;
49
50    devcb_read8 m_in_rd_func;
51};
52
53
54
55// ======================> hd61830_device_config
56
57class hd61830_device_config :   public device_config,
58                        public device_config_memory_interface,
59                                public hd61830_interface
60{
61    friend class hd61830_device;
62
63    // construction/destruction
64    hd61830_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
65
66public:
67    // allocators
68    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
69    virtual device_t *alloc_device(running_machine &machine) const;
70
71   // optional information overrides
72   virtual const rom_entry *rom_region() const;
73
74protected:
75   // device_config overrides
76   virtual void device_config_complete();
77
78   // device_config_memory_interface overrides
79   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
80
81    // address space configurations
82   const address_space_config      m_space_config;
83};
84
85
86
87// ======================> hd61830_device
88
89class hd61830_device :   public device_t,
90                  public device_memory_interface
91{
92    friend class hd61830_device_config;
93
94    // construction/destruction
95    hd61830_device(running_machine &_machine, const hd61830_device_config &_config);
96
97public:
98    DECLARE_READ8_MEMBER( status_r );
99    DECLARE_WRITE8_MEMBER( control_w );
100
101    DECLARE_READ8_MEMBER( data_r );
102    DECLARE_WRITE8_MEMBER( data_w );
103
104   void update_screen(bitmap_t *bitmap, const rectangle *cliprect);
105
106protected:
107    // device-level overrides
108    virtual void device_start();
109    virtual void device_reset();
110   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
111
112   inline UINT8 readbyte(offs_t address);
113   inline void writebyte(offs_t address, UINT8 data);
114
115private:
116   void set_busy_flag();
117
118   void draw_scanline(bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ra);
119   void update_graphics(bitmap_t *bitmap, const rectangle *cliprect);
120   void draw_char(bitmap_t *bitmap, const rectangle *cliprect, UINT16 ma, int x, int y, UINT8 md);
121   void update_text(bitmap_t *bitmap, const rectangle *cliprect);
122
123    devcb_resolved_read8 m_in_rd_func;
124
125   screen_device *m_screen;
126   emu_timer *m_busy_timer;
127   address_space *m_data;
128
129   bool m_bf;                  // busy flag
130
131   UINT8 m_ir;                  // instruction register
132   UINT8 m_mcr;               // mode control register
133   UINT8 m_dor;               // data output register
134
135   UINT16 m_dsa;               // display start address
136   UINT16 m_cac;               // cursor address counter
137
138   int m_vp;                  // vertical character pitch
139   int m_hp;                  // horizontal character pitch
140   int m_hn;                  // horizontal number of characters
141   int m_nx;                  // number of time divisions
142   int m_cp;                  // cursor position
143
144    int m_blink;               // blink counter
145   int m_cursor;               // cursor visible
146
147   const hd61830_device_config &m_config;
148};
149
150
151// device type definition
152extern const device_type HD61830;
153
154
155
156#endif
src/emu/video/crt9212.c
r0r10969
1/**********************************************************************
2
3    SMC CRT9212 Double Row Buffer (DRB) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "crt9212.h"
12
13
14
15//**************************************************************************
16//  MACROS / CONSTANTS
17//**************************************************************************
18
19#define LOG 1
20
21
22#define REN \
23   devcb_call_read_line(&m_in_ren_func)
24
25#define WEN \
26   devcb_call_read_line(&m_in_wen_func)
27
28#define WEN2 \
29   devcb_call_read_line(&m_in_wen2_func)
30
31#define ROF(_state) \
32   devcb_call_write_line(&m_out_rof_func, _state);
33
34#define WOF(_state) \
35   devcb_call_write_line(&m_out_wof_func, _state);
36
37
38
39//**************************************************************************
40//  GLOBAL VARIABLES
41//**************************************************************************
42
43// devices
44const device_type CRT9212 = crt9212_device_config::static_alloc_device_config;
45
46
47
48//**************************************************************************
49//  DEVICE CONFIGURATION
50//**************************************************************************
51
52//-------------------------------------------------
53//  crt9212_device_config - constructor
54//-------------------------------------------------
55
56crt9212_device_config::crt9212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
57   : device_config(mconfig, static_alloc_device_config, "SMC CRT9212", tag, owner, clock)
58{
59}
60
61
62//-------------------------------------------------
63//  static_alloc_device_config - allocate a new
64//  configuration object
65//-------------------------------------------------
66
67device_config *crt9212_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
68{
69   return global_alloc(crt9212_device_config(mconfig, tag, owner, clock));
70}
71
72
73//-------------------------------------------------
74//  alloc_device - allocate a new device object
75//-------------------------------------------------
76
77device_t *crt9212_device_config::alloc_device(running_machine &machine) const
78{
79   return auto_alloc(&machine, crt9212_device(machine, *this));
80}
81
82
83//-------------------------------------------------
84//  device_config_complete - perform any
85//  operations now that the configuration is
86//  complete
87//-------------------------------------------------
88
89void crt9212_device_config::device_config_complete()
90{
91   // inherit a copy of the static data
92   const crt9212_interface *intf = reinterpret_cast<const crt9212_interface *>(static_config());
93   if (intf != NULL)
94      *static_cast<crt9212_interface *>(this) = *intf;
95
96   // or initialize to defaults if none provided
97   else
98   {
99      memset(&out_rof_func, 0, sizeof(out_rof_func));
100      memset(&out_wof_func, 0, sizeof(out_wof_func));
101      memset(&in_ren_func, 0, sizeof(in_ren_func));
102      memset(&in_wen_func, 0, sizeof(in_wen_func));
103      memset(&in_wen2_func, 0, sizeof(in_wen2_func));
104   }
105}
106
107
108
109//**************************************************************************
110//  INLINE HELPERS
111//**************************************************************************
112
113
114//**************************************************************************
115//  LIVE DEVICE
116//**************************************************************************
117
118//-------------------------------------------------
119//  crt9212_device - constructor
120//-------------------------------------------------
121
122crt9212_device::crt9212_device(running_machine &_machine, const crt9212_device_config &config)
123    : device_t(_machine, config),
124      m_config(config)
125{
126}
127
128
129//-------------------------------------------------
130//  device_start - device-specific startup
131//-------------------------------------------------
132
133void crt9212_device::device_start()
134{
135   // resolve callbacks
136   devcb_resolve_write_line(&m_out_rof_func, &m_config.out_rof_func, this);
137   devcb_resolve_write_line(&m_out_wof_func, &m_config.out_wof_func, this);
138   devcb_resolve_read_line(&m_in_ren_func, &m_config.in_ren_func, this);
139   devcb_resolve_read_line(&m_in_wen_func, &m_config.in_wen_func, this);
140   devcb_resolve_read_line(&m_in_wen2_func, &m_config.in_wen2_func, this);
141
142   // register for state saving
143   save_item(NAME(m_input));
144   save_item(NAME(m_output));
145   save_item(NAME(m_buffer));
146   save_item(NAME(m_rac));
147   save_item(NAME(m_wac));
148   save_item(NAME(m_tog));
149   save_item(NAME(m_clrcnt));
150   save_item(NAME(m_rclk));
151   save_item(NAME(m_wclk));
152}
153
154
155//-------------------------------------------------
156//  read - buffer read
157//-------------------------------------------------
158
159READ8_MEMBER( crt9212_device::read )
160{
161   return m_output;
162}
163
164
165//-------------------------------------------------
166//  write - buffer write
167//-------------------------------------------------
168
169WRITE8_MEMBER( crt9212_device::write )
170{
171   m_input = data;
172}
173
174
175//-------------------------------------------------
176//  clrcnt_w - clear address counters
177//-------------------------------------------------
178
179WRITE_LINE_MEMBER( crt9212_device::clrcnt_w )
180{
181   m_clrcnt = state;
182}
183
184
185//-------------------------------------------------
186//  tog_w - toggle buffer
187//-------------------------------------------------
188
189WRITE_LINE_MEMBER( crt9212_device::tog_w )
190{
191   m_tog = state;
192}
193
194
195//-------------------------------------------------
196//  rclk_w - read clock
197//-------------------------------------------------
198
199WRITE_LINE_MEMBER( crt9212_device::rclk_w )
200{
201   if (m_rclk && !state)
202   {
203      if (!m_clrcnt)
204      {
205         if (!m_tog)
206         {
207            // switch buffer
208            m_buffer = !m_buffer;
209
210            // clear write address counter
211            m_wac = 0;
212            WOF(0);
213         }
214         else
215         {
216            // clear read address counter
217            m_rac = 0;
218            ROF(0);
219         }
220      }
221      else
222      {
223         if (REN && (m_rac < CRT9212_RAM_SIZE))
224         {
225            //
226            m_output = m_ram[m_rac][!m_buffer];
227
228            // increment read address counter
229            m_rac++;
230
231            if (m_rac == CRT9212_RAM_SIZE)
232            {
233               // set read overflow
234               ROF(1);
235            }
236         }
237      }
238   }
239
240   m_rclk = state;
241}
242
243
244//-------------------------------------------------
245//  wclk_w - write clock
246//-------------------------------------------------
247
248WRITE_LINE_MEMBER( crt9212_device::wclk_w )
249{
250   if (!m_rclk && state)
251   {
252      if (WEN && WEN2 && (m_wac < CRT9212_RAM_SIZE))
253      {
254         //
255         m_ram[m_rac][m_buffer] = m_input;
256
257         // increment read address counter
258         m_wac++;
259
260         if (m_wac == CRT9212_RAM_SIZE)
261         {
262            // set write overflow
263            WOF(1);
264         }
265      }
266   }
267
268   m_wclk = state;
269}
src/emu/video/crt9212.h
r0r10969
1/**********************************************************************
2
3    SMC CRT9212 Double Row Buffer (DRB) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                  DIN2   1 |*    \_/     | 28  DIN3
11                  DIN1   2 |             | 27  _WCLK
12                  DIN0   3 |             | 26  _OE
13                 DOUT7   4 |             | 25  WEN2
14                 DOUT6   5 |             | 24  WEN1
15                 DOUT5   6 |             | 23  GND
16                 DOUT4   7 |   CRT9212   | 22  ROF
17                   Vcc   8 |             | 21  WOF
18                 DOUT3   9 |             | 20  REN
19                 DOUT2  10 |             | 19  _CLRCNT
20                 DOUT1  11 |             | 18  _TOG
21                 DOUT0  12 |             | 17  _RCLK
22                  DIN7  13 |             | 16  DIN4
23                  DIN6  14 |_____________| 15  DIN5
24
25**********************************************************************/
26
27#pragma once
28
29#ifndef __CRT9212__
30#define __CRT9212__
31
32#include "emu.h"
33
34
35
36//**************************************************************************
37//  MACROS / CONSTANTS
38//**************************************************************************
39
40const int CRT9212_RAM_SIZE   = 135;
41
42
43
44//**************************************************************************
45//  INTERFACE CONFIGURATION MACROS
46//**************************************************************************
47
48#define MCFG_CRT9212_ADD(_tag, _config) \
49   MCFG_DEVICE_ADD(_tag, CRT9212, 0) \
50   MCFG_DEVICE_CONFIG(_config)
51
52
53#define CRT9212_INTERFACE(name) \
54   const crt9212_interface (name) =
55
56
57
58//**************************************************************************
59//  TYPE DEFINITIONS
60//**************************************************************************
61
62
63// ======================> crt9212_interface
64
65struct crt9212_interface
66{
67   devcb_write_line      out_rof_func;
68   devcb_write_line      out_wof_func;
69   devcb_read_line         in_ren_func;
70   devcb_read_line         in_wen_func;
71   devcb_read_line         in_wen2_func;
72};
73
74
75
76// ======================> crt9212_device_config
77
78class crt9212_device_config :   public device_config,
79                                public crt9212_interface
80{
81    friend class crt9212_device;
82
83    // construction/destruction
84    crt9212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
85
86public:
87    // allocators
88    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
89    virtual device_t *alloc_device(running_machine &machine) const;
90
91protected:
92   // device_config overrides
93   virtual void device_config_complete();
94};
95
96
97
98// ======================> crt9212_device
99
100class crt9212_device :   public device_t
101{
102    friend class crt9212_device_config;
103
104    // construction/destruction
105    crt9212_device(running_machine &_machine, const crt9212_device_config &_config);
106
107public:
108    DECLARE_READ8_MEMBER( read );
109    DECLARE_WRITE8_MEMBER( write );
110   DECLARE_WRITE_LINE_MEMBER( clrcnt_w );
111   DECLARE_WRITE_LINE_MEMBER( tog_w );
112   DECLARE_WRITE_LINE_MEMBER( rclk_w );
113   DECLARE_WRITE_LINE_MEMBER( wclk_w );
114
115protected:
116    // device-level overrides
117    virtual void device_start();
118
119private:
120   devcb_resolved_write_line   m_out_rof_func;
121   devcb_resolved_write_line   m_out_wof_func;
122   devcb_resolved_read_line   m_in_ren_func;
123   devcb_resolved_read_line   m_in_wen_func;
124   devcb_resolved_read_line   m_in_wen2_func;
125
126   UINT8 m_ram[CRT9212_RAM_SIZE][2];
127
128   UINT8 m_input;
129   UINT8 m_output;
130
131   int m_buffer;
132   int m_rac;
133   int m_wac;
134   int m_tog;
135   int m_clrcnt;
136   int m_rclk;
137   int m_wclk;
138
139   const crt9212_device_config &m_config;
140};
141
142
143// device type definition
144extern const device_type CRT9212;
145
146
147
148#endif
src/emu/emu.mak
r10968r10969
133133   $(EMUDRIVERS)/empty.o \
134134
135135EMUMACHINEOBJS = \
136   $(EMUMACHINE)/53c810.o \
137   $(EMUMACHINE)/6522via.o \
138   $(EMUMACHINE)/6526cia.o \
139   $(EMUMACHINE)/6532riot.o \
140   $(EMUMACHINE)/6821pia.o \
141   $(EMUMACHINE)/6840ptm.o \
142   $(EMUMACHINE)/6850acia.o \
143   $(EMUMACHINE)/68681.o \
144   $(EMUMACHINE)/74123.o \
145   $(EMUMACHINE)/74148.o \
146   $(EMUMACHINE)/74153.o \
147   $(EMUMACHINE)/74181.o \
148   $(EMUMACHINE)/7474.o \
149   $(EMUMACHINE)/8042kbdc.o \
150   $(EMUMACHINE)/8237dma.o \
151   $(EMUMACHINE)/8255ppi.o \
152   $(EMUMACHINE)/8257dma.o \
153   $(EMUMACHINE)/adc083x.o \
154   $(EMUMACHINE)/adc1038.o \
155   $(EMUMACHINE)/adc1213x.o \
156   $(EMUMACHINE)/am53cf96.o \
157   $(EMUMACHINE)/at28c16.o \
158   $(EMUMACHINE)/cdp1852.o \
159   $(EMUMACHINE)/cr589.o \
160   $(EMUMACHINE)/ds1302.o \
161   $(EMUMACHINE)/ds2401.o \
162   $(EMUMACHINE)/ds2404.o \
163   $(EMUMACHINE)/eeprom.o \
164   $(EMUMACHINE)/er2055.o \
165   $(EMUMACHINE)/f3853.o \
166   $(EMUMACHINE)/generic.o \
167   $(EMUMACHINE)/i2cmem.o \
168   $(EMUMACHINE)/i8243.o \
169   $(EMUMACHINE)/i8255a.o \
170   $(EMUMACHINE)/idectrl.o \
171   $(EMUMACHINE)/ins8154.o   \
172   $(EMUMACHINE)/ins8250.o \
173   $(EMUMACHINE)/intelfsh.o \
174   $(EMUMACHINE)/k033906.o \
175   $(EMUMACHINE)/k056230.o \
176   $(EMUMACHINE)/latch8.o \
177   $(EMUMACHINE)/ldcore.o \
178   $(EMUMACHINE)/ldpr8210.o \
179   $(EMUMACHINE)/ldv1000.o \
180   $(EMUMACHINE)/ldvp931.o \
181   $(EMUMACHINE)/mb14241.o \
182   $(EMUMACHINE)/mb3773.o \
183   $(EMUMACHINE)/mb87078.o \
184   $(EMUMACHINE)/mc146818.o \
185   $(EMUMACHINE)/mc68901.o \
186   $(EMUMACHINE)/microtch.o \
187   $(EMUMACHINE)/msm6242.o \
188   $(EMUMACHINE)/nvram.o \
189   $(EMUMACHINE)/pc16552d.o \
190   $(EMUMACHINE)/pci.o \
191   $(EMUMACHINE)/pd4990a.o \
192   $(EMUMACHINE)/pic8259.o \
193   $(EMUMACHINE)/pit8253.o \
194   $(EMUMACHINE)/ram.o \
195   $(EMUMACHINE)/roc10937.o \
196   $(EMUMACHINE)/rp5h01.o \
197   $(EMUMACHINE)/rtc65271.o \
198   $(EMUMACHINE)/s3c2400.o \
199   $(EMUMACHINE)/s3c2410.o \
200   $(EMUMACHINE)/s3c2440.o \
201   $(EMUMACHINE)/scsi.o \
202   $(EMUMACHINE)/scsicd.o \
203   $(EMUMACHINE)/scsidev.o \
204   $(EMUMACHINE)/scsihd.o \
205   $(EMUMACHINE)/secflash.o \
206   $(EMUMACHINE)/smc91c9x.o \
207   $(EMUMACHINE)/timekpr.o \
208   $(EMUMACHINE)/tmp68301.o \
209   $(EMUMACHINE)/tms6100.o \
210   $(EMUMACHINE)/upd4701.o \
211   $(EMUMACHINE)/wd33c93.o \
212   $(EMUMACHINE)/x2212.o \
213   $(EMUMACHINE)/x76f041.o \
214   $(EMUMACHINE)/x76f100.o \
215   $(EMUMACHINE)/z80ctc.o \
216   $(EMUMACHINE)/z80dart.o \
217   $(EMUMACHINE)/z80dma.o \
218   $(EMUMACHINE)/z80pio.o \
219   $(EMUMACHINE)/z80sio.o \
220   $(EMUMACHINE)/z80sti.o \
136   $(EMUMACHINE)/53c810.o      \
137   $(EMUMACHINE)/6522via.o      \
138   $(EMUMACHINE)/6526cia.o      \
139   $(EMUMACHINE)/6532riot.o   \
140   $(EMUMACHINE)/6821pia.o      \
141   $(EMUMACHINE)/6840ptm.o      \
142   $(EMUMACHINE)/6850acia.o   \
143   $(EMUMACHINE)/68681.o      \
144   $(EMUMACHINE)/74123.o      \
145   $(EMUMACHINE)/74148.o      \
146   $(EMUMACHINE)/74153.o      \
147   $(EMUMACHINE)/74181.o      \
148   $(EMUMACHINE)/7474.o      \
149   $(EMUMACHINE)/8042kbdc.o   \
150   $(EMUMACHINE)/8237dma.o      \
151   $(EMUMACHINE)/8255ppi.o      \
152   $(EMUMACHINE)/8257dma.o      \
153   $(EMUMACHINE)/adc083x.o      \
154   $(EMUMACHINE)/adc1038.o      \
155   $(EMUMACHINE)/adc1213x.o   \
156   $(EMUMACHINE)/am53cf96.o   \
157   $(EMUMACHINE)/at28c16.o      \
158   $(EMUMACHINE)/cdp1852.o      \
159   $(EMUMACHINE)/cdp1871.o      \
160   $(EMUMACHINE)/cr589.o      \
161   $(EMUMACHINE)/ds1302.o      \
162   $(EMUMACHINE)/ds2401.o      \
163   $(EMUMACHINE)/ds2404.o      \
164   $(EMUMACHINE)/e0516.o      \
165   $(EMUMACHINE)/eeprom.o      \
166   $(EMUMACHINE)/er2055.o      \
167   $(EMUMACHINE)/f3853.o      \
168   $(EMUMACHINE)/generic.o      \
169   $(EMUMACHINE)/i2cmem.o      \
170   $(EMUMACHINE)/i8155.o      \
171   $(EMUMACHINE)/i8212.o      \
172   $(EMUMACHINE)/i8243.o      \
173   $(EMUMACHINE)/i8255a.o      \
174   $(EMUMACHINE)/i8355.o      \
175   $(EMUMACHINE)/idectrl.o      \
176   $(EMUMACHINE)/ins8154.o      \
177   $(EMUMACHINE)/ins8250.o      \
178   $(EMUMACHINE)/intelfsh.o   \
179   $(EMUMACHINE)/k033906.o      \
180   $(EMUMACHINE)/k056230.o      \
181   $(EMUMACHINE)/latch8.o      \
182   $(EMUMACHINE)/ldcore.o      \
183   $(EMUMACHINE)/ldpr8210.o   \
184   $(EMUMACHINE)/ldv1000.o      \
185   $(EMUMACHINE)/ldvp931.o      \
186   $(EMUMACHINE)/mb14241.o      \
187   $(EMUMACHINE)/mb3773.o      \
188   $(EMUMACHINE)/mb87078.o      \
189   $(EMUMACHINE)/mc146818.o   \
190   $(EMUMACHINE)/mc68901.o      \
191   $(EMUMACHINE)/microtch.o   \
192   $(EMUMACHINE)/msm6242.o      \
193   $(EMUMACHINE)/nmc9306.o      \
194   $(EMUMACHINE)/nvram.o      \
195   $(EMUMACHINE)/pc16552d.o   \
196   $(EMUMACHINE)/pci.o         \
197   $(EMUMACHINE)/pd4990a.o      \
198   $(EMUMACHINE)/pic8259.o      \
199   $(EMUMACHINE)/pit8253.o      \
200   $(EMUMACHINE)/ram.o         \
201   $(EMUMACHINE)/roc10937.o   \
202   $(EMUMACHINE)/rp5h01.o      \
203   $(EMUMACHINE)/rtc65271.o   \
204   $(EMUMACHINE)/s3c2400.o      \
205   $(EMUMACHINE)/s3c2410.o      \
206   $(EMUMACHINE)/s3c2440.o      \
207   $(EMUMACHINE)/scsi.o      \
208   $(EMUMACHINE)/scsicd.o      \
209   $(EMUMACHINE)/scsidev.o      \
210   $(EMUMACHINE)/scsihd.o      \
211   $(EMUMACHINE)/secflash.o   \
212   $(EMUMACHINE)/smc91c9x.o   \
213   $(EMUMACHINE)/timekpr.o      \
214   $(EMUMACHINE)/tmp68301.o   \
215   $(EMUMACHINE)/tms6100.o      \
216   $(EMUMACHINE)/upd4701.o      \
217   $(EMUMACHINE)/wd33c93.o      \
218   $(EMUMACHINE)/x2212.o      \
219   $(EMUMACHINE)/x76f041.o      \
220   $(EMUMACHINE)/x76f100.o      \
221   $(EMUMACHINE)/z80ctc.o      \
222   $(EMUMACHINE)/z80dart.o      \
223   $(EMUMACHINE)/z80dma.o      \
224   $(EMUMACHINE)/z80pio.o      \
225   $(EMUMACHINE)/z80sio.o      \
226   $(EMUMACHINE)/z80sti.o      \
227   $(EMUMACHINE)/z8536.o      \
221228
222229EMUVIDEOOBJS = \
223   $(EMUVIDEO)/generic.o \
224   $(EMUVIDEO)/hd63484.o \
225   $(EMUVIDEO)/mc6845.o \
226   $(EMUVIDEO)/pc_vga.o \
227   $(EMUVIDEO)/pc_video.o \
228   $(EMUVIDEO)/poly.o \
229   $(EMUVIDEO)/resnet.o \
230   $(EMUVIDEO)/rgbutil.o \
231   $(EMUVIDEO)/s2636.o \
232   $(EMUVIDEO)/saa5050.o \
233   $(EMUVIDEO)/tlc34076.o \
234   $(EMUVIDEO)/tms34061.o \
235   $(EMUVIDEO)/tms9927.o \
236   $(EMUVIDEO)/tms9928a.o \
237   $(EMUVIDEO)/v9938.o \
238   $(EMUVIDEO)/vector.o \
239   $(EMUVIDEO)/voodoo.o \
230   $(EMUVIDEO)/crt9007.o      \
231   $(EMUVIDEO)/crt9021.o      \
232   $(EMUVIDEO)/crt9212.o      \
233   $(EMUVIDEO)/generic.o      \
234   $(EMUVIDEO)/hd61830.o      \
235   $(EMUVIDEO)/hd63484.o      \
236   $(EMUVIDEO)/mc6845.o      \
237   $(EMUVIDEO)/pc_vga.o      \
238   $(EMUVIDEO)/pc_video.o      \
239   $(EMUVIDEO)/poly.o         \
240   $(EMUVIDEO)/resnet.o      \
241   $(EMUVIDEO)/rgbutil.o      \
242   $(EMUVIDEO)/s2636.o         \
243   $(EMUVIDEO)/saa5050.o      \
244   $(EMUVIDEO)/tlc34076.o      \
245   $(EMUVIDEO)/tms34061.o      \
246   $(EMUVIDEO)/tms9927.o      \
247   $(EMUVIDEO)/tms9928a.o      \
248   $(EMUVIDEO)/v9938.o         \
249   $(EMUVIDEO)/vector.o      \
250   $(EMUVIDEO)/voodoo.o      \
240251
241252EMUIMAGEDEVOBJS = \
242253   $(EMUIMAGEDEV)/bitbngr.o   \
src/emu/machine/i8212.c
r0r10969
1/**********************************************************************
2
3    Intel 8212 8-Bit Input/Output Port emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "machine/devhelpr.h"
12#include "i8212.h"
13
14
15
16//**************************************************************************
17//  MACROS / CONSTANTS
18//**************************************************************************
19
20#define LOG 0
21
22
23
24//**************************************************************************
25//  GLOBAL VARIABLES
26//**************************************************************************
27
28// devices
29const device_type I8212 = i8212_device_config::static_alloc_device_config;
30
31
32
33//**************************************************************************
34//  DEVICE CONFIGURATION
35//**************************************************************************
36
37GENERIC_DEVICE_CONFIG_SETUP(i8212, "Intel 8212")
38
39
40//-------------------------------------------------
41//  device_config_complete - perform any
42//  operations now that the configuration is
43//  complete
44//-------------------------------------------------
45
46void i8212_device_config::device_config_complete()
47{
48   // inherit a copy of the static data
49   const i8212_interface *intf = reinterpret_cast<const i8212_interface *>(static_config());
50   if (intf != NULL)
51      *static_cast<i8212_interface *>(this) = *intf;
52
53   // or initialize to defaults if none provided
54   else
55   {
56      memset(&out_int_func, 0, sizeof(out_int_func));
57      memset(&in_di_func, 0, sizeof(in_di_func));
58      memset(&out_do_func, 0, sizeof(out_do_func));
59   }
60}
61
62
63
64//**************************************************************************
65//  LIVE DEVICE
66//**************************************************************************
67
68//-------------------------------------------------
69//  i8212_device - constructor
70//-------------------------------------------------
71
72i8212_device::i8212_device(running_machine &_machine, const i8212_device_config &config)
73    : device_t(_machine, config),
74     m_md(I8212_MODE_INPUT),
75     m_stb(0),
76      m_config(config)
77{
78
79}
80
81
82//-------------------------------------------------
83//  device_start - device-specific startup
84//-------------------------------------------------
85
86void i8212_device::device_start()
87{
88   // resolve callbacks
89   devcb_resolve_write_line(&m_out_int_func, &m_config.out_int_func, this);
90   devcb_resolve_read8(&m_in_di_func, &m_config.in_di_func, this);
91   devcb_resolve_write8(&m_out_do_func, &m_config.out_do_func, this);
92
93   // register for state saving
94   save_item(NAME(m_md));
95   save_item(NAME(m_stb));
96   save_item(NAME(m_data));
97}
98
99
100//-------------------------------------------------
101//  device_reset - device-specific reset
102//-------------------------------------------------
103
104void i8212_device::device_reset()
105{
106   m_data = 0;
107
108   if (m_md == I8212_MODE_OUTPUT)
109   {
110      // output data
111      devcb_call_write8(&m_out_do_func, 0, m_data);
112   }
113}
114
115
116//-------------------------------------------------
117//  data_r - data latch read
118//-------------------------------------------------
119
120READ8_MEMBER( i8212_device::data_r )
121{
122   // clear interrupt line
123   devcb_call_write_line(&m_out_int_func, CLEAR_LINE);
124
125   if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), CLEAR_LINE);
126
127   return m_data;
128}
129
130
131//-------------------------------------------------
132//  data_w - data latch write
133//-------------------------------------------------
134
135WRITE8_MEMBER( i8212_device::data_w )
136{
137   // latch data
138   m_data = data;
139
140   // output data
141   devcb_call_write8(&m_out_do_func, 0, m_data);
142}
143
144
145//-------------------------------------------------
146//  md_w - mode write
147//-------------------------------------------------
148
149WRITE_LINE_MEMBER( i8212_device::md_w )
150{
151   if (LOG) logerror("I8212 '%s' Mode: %s\n", tag(), state ? "output" : "input");
152
153   m_md = state;
154}
155
156
157//-------------------------------------------------
158//  stb_w - data strobe write
159//-------------------------------------------------
160
161WRITE_LINE_MEMBER( i8212_device::stb_w )
162{
163   if (LOG) logerror("I8212 '%s' STB: %u\n", tag(), state);
164
165   if (m_md == I8212_MODE_INPUT)
166   {
167      if (m_stb && !state)
168      {
169         // input data
170         m_data = devcb_call_read8(&m_in_di_func, 0);
171
172         // assert interrupt line
173         devcb_call_write_line(&m_out_int_func, ASSERT_LINE);
174
175         if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), ASSERT_LINE);
176      }
177   }
178
179   m_stb = state;
180}
src/emu/machine/i8212.h
r0r10969
1/**********************************************************************
2
3    Intel 8212 8-Bit Input/Output Port emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                  _DS1   1 |*    \_/     | 24  Vcc
11                    MD   2 |             | 23  _INT
12                   DI1   3 |             | 22  DI8
13                   DO1   4 |             | 21  DO8
14                   DI2   5 |             | 20  DI7
15                   DO2   6 |    8212     | 19  DO7
16                   DI3   7 |             | 18  DI6
17                   DO3   8 |             | 17  DO6
18                   DI4   9 |             | 16  DI5
19                   DO4  10 |             | 15  DO5
20                   STB  11 |             | 14  _CLR
21                   GND  12 |_____________| 13  DS2
22
23**********************************************************************/
24
25#pragma once
26
27#ifndef __I8212__
28#define __I8212__
29
30#include "emu.h"
31
32
33
34///*************************************************************************
35//  MACROS / CONSTANTS
36///*************************************************************************
37
38enum
39{
40   I8212_MODE_INPUT = 0,
41   I8212_MODE_OUTPUT
42};
43
44
45
46///*************************************************************************
47//  INTERFACE CONFIGURATION MACROS
48///*************************************************************************
49
50#define MCFG_I8212_ADD(_tag, _config) \
51   MCFG_DEVICE_ADD((_tag), I8212, 0)   \
52   MCFG_DEVICE_CONFIG(_config)
53
54#define I8212_INTERFACE(name) \
55   const i8212_interface (name) =
56
57
58
59///*************************************************************************
60//  TYPE DEFINITIONS
61///*************************************************************************
62
63// ======================> i8212_interface
64
65struct i8212_interface
66{
67   devcb_write_line   out_int_func;
68
69   devcb_read8         in_di_func;
70   devcb_write8      out_do_func;
71};
72
73
74
75// ======================> i8212_device_config
76
77class i8212_device_config :   public device_config,
78                                public i8212_interface
79{
80    friend class i8212_device;
81
82    // construction/destruction
83    i8212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
84
85public:
86    // allocators
87    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
88    virtual device_t *alloc_device(running_machine &machine) const;
89
90protected:
91   // device_config overrides
92   virtual void device_config_complete();
93};
94
95
96
97// ======================> i8212_device
98
99class i8212_device :   public device_t
100{
101    friend class i8212_device_config;
102
103    // construction/destruction
104    i8212_device(running_machine &_machine, const i8212_device_config &_config);
105
106public:
107    DECLARE_READ8_MEMBER( data_r );
108    DECLARE_WRITE8_MEMBER( data_w );
109
110   DECLARE_WRITE_LINE_MEMBER( md_w );
111   DECLARE_WRITE_LINE_MEMBER( stb_w );
112
113protected:
114    // device-level overrides
115    virtual void device_start();
116    virtual void device_reset();
117
118private:
119   devcb_resolved_write_line   m_out_int_func;
120   devcb_resolved_read8      m_in_di_func;
121   devcb_resolved_write8      m_out_do_func;
122
123   int m_md;               // mode
124   int m_stb;               // strobe
125   UINT8 m_data;            // data latch
126
127   const i8212_device_config &m_config;
128};
129
130
131// device type definition
132extern const device_type I8212;
133
134
135
136#endif
src/emu/machine/z8536.c
r0r10969
1/**********************************************************************
2
3    Zilog Z8536 Counter/Timer and Parallel I/O emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "z8536.h"
12#include "machine/devhelpr.h"
13
14
15
16//**************************************************************************
17//  MACROS / CONSTANTS
18//**************************************************************************
19
20// states
21enum
22{
23   STATE_RESET = -1,
24   STATE_0,
25   STATE_1
26};
27
28
29// ports
30enum
31{
32   PORT_C = 0,
33   PORT_B,
34   PORT_A,
35   CONTROL
36};
37
38
39// registers
40enum
41{
42   MASTER_INTERRUPT_CONTROL = 0,
43   MASTER_CONFIGURATION_CONTROL,
44   PORT_A_INTERRUPT_VECTOR,
45   PORT_B_INTERRUPT_VECTOR,
46   COUNTER_TIMER_INTERRUPT_VECTOR,
47   PORT_C_DATA_PATH_POLARITY,
48   PORT_C_DATA_DIRECTION,
49   PORT_C_SPECIAL_IO_CONTROL,
50   PORT_A_COMMAND_AND_STATUS,
51   PORT_B_COMMAND_AND_STATUS,
52   COUNTER_TIMER_1_COMMAND_AND_STATUS,
53   COUNTER_TIMER_2_COMMAND_AND_STATUS,
54   COUNTER_TIMER_3_COMMAND_AND_STATUS,
55   PORT_A_DATA,
56   PORT_B_DATA,
57   PORT_C_DATA,
58   COUNTER_TIMER_1_CURRENT_COUNT_MS_BYTE,
59   COUNTER_TIMER_1_CURRENT_COUNT_LS_BYTE,
60   COUNTER_TIMER_2_CURRENT_COUNT_MS_BYTE,
61   COUNTER_TIMER_2_CURRENT_COUNT_LS_BYTE,
62   COUNTER_TIMER_3_CURRENT_COUNT_MS_BYTE,
63   COUNTER_TIMER_3_CURRENT_COUNT_LS_BYTE,
64   COUNTER_TIMER_1_TIME_CONSTANT_MS_BYTE,
65   COUNTER_TIMER_1_TIME_CONSTANT_LS_BYTE,
66   COUNTER_TIMER_2_TIME_CONSTANT_MS_BYTE,
67   COUNTER_TIMER_2_TIME_CONSTANT_LS_BYTE,
68   COUNTER_TIMER_3_TIME_CONSTANT_MS_BYTE,
69   COUNTER_TIMER_3_TIME_CONSTANT_LS_BYTE,
70   COUNTER_TIMER_1_MODE_SPECIFICATION,
71   COUNTER_TIMER_2_MODE_SPECIFICATION,
72   COUNTER_TIMER_3_MODE_SPECIFICATION,
73   CURRENT_VECTOR,
74   PORT_A_MODE_SPECIFICATION,
75   PORT_A_HANDSHAKE_SPECIFICATION,
76   PORT_A_DATA_PATH_POLARITY,
77   PORT_A_DATA_DIRECTION,
78   PORT_A_SPECIAL_IO_CONTROL,
79   PORT_A_PATTERN_POLARITY,
80   PORT_A_PATTERN_TRANSITION,
81   PORT_A_PATTERN_MASK,
82   PORT_B_MODE_SPECIFICATION,
83   PORT_B_HANDSHAKE_SPECIFICATION,
84   PORT_B_DATA_PATH_POLARITY,
85   PORT_B_DATA_DIRECTION,
86   PORT_B_SPECIAL_IO_CONTROL,
87   PORT_B_PATTERN_POLARITY,
88   PORT_B_PATTERN_TRANSITION,
89   PORT_B_PATTERN_MASK
90};
91
92
93// counter/timer link control
94enum
95{
96   LC_INDEPENDENT = 0,
97   LC_CT1_GATES_CT2,
98   LC_CT1_TRIGGERS_CT2,
99   LC_CT1_COUNTS_CT2
100};
101
102
103// port type select
104enum
105{
106   PTS_BIT = 0,
107   PTS_INPUT,
108   PTS_OUTPUT,
109   PTS_BIDIRECTIONAL
110};
111
112
113// pattern mode specification
114enum
115{
116   PMS_DISABLE = 0,
117   PMS_AND,
118   PMS_OR,
119   PMS_VECTOR
120};
121
122
123// handshake specification
124enum
125{
126   HTS_INTERLOCKED = 0,
127   HTS_STROBED,
128   HTS_PULSED,
129   HTS_3_WIRE
130};
131
132
133// request/wait specification
134enum
135{
136   RWS_DISABLED = 0,
137   RWS_OUTPUT_WAIT,
138   RWS_INPUT_WAIT = 3,
139   RWS_SPECIAL_REQUEST,
140   RWS_OUTPUT_REQUEST,
141   RWS_INPUT_REQUEST = 7
142};
143
144
145// pattern specification
146enum
147{
148   BIT_MASKED_OFF = 0,
149   ANY_TRANSITION,
150   ZERO = 4,
151   ONE,
152   ONE_TO_ZERO,
153   ZERO_TO_ONE
154};
155
156
157// output duty cycle
158enum
159{
160   DCS_PULSE,
161   DCS_ONE_SHOT,
162   DCS_SQUARE_WAVE,
163   DCS_DO_NOT_USE
164};
165
166
167// master interrupt control register
168#define MICR_RESET      0x01   // reset
169#define MICR_RJA       0x02   // right justified address
170#define MICR_CT_VIS      0x04   // counter/timer vector includes status
171#define MICR_PB_VIS      0x08   // port B vector includes status
172#define MICR_PA_VIS      0x10   // port A vector includes status
173#define MICR_NV       0x20   // no vector
174#define MICR_DLC       0x40   // disable lower chain
175#define MICR_MIE       0x80   // master interrupt enable
176
177
178// master configuration control register
179#define MCCR_LC_MASK   0x03   // counter/timer link controls
180#define MCCR_PAE      0x04   // port A enable
181#define MCCR_PLC      0x08   // port link control
182#define MCCR_PCE_CT3E   0x10   // port C and counter/timer 3 enable
183#define MCCR_CT2E      0x20   // counter/timer 2 enable
184#define MCCR_CT1E      0x40   // counter/timer 1 enable
185#define MCCR_PBE      0x80   // port B enable
186
187
188// port mode specification registers
189#define PMS_LPM         0x01   // latch on pattern match
190#define PMS_PMS_MASK   0x06   // pattern mode specification
191#define PMS_IMO         0x08   // interrupt on match only
192#define PMS_SB         0x10   // single buffer
193#define PMS_ITB         0x20   // interrupt on two bytes
194#define PMS_PTS_MASK   0xc0   // port type select
195
196
197// port handshake specification registers
198#define PHS_DTS_MASK   0x07   // deskew time specification
199#define PHS_RWS_MASK   0x38   // request/wait specification
200#define PHS_HTS_MASK   0xc0   // handshake type specification
201
202
203// port command and status registers
204#define PCS_IOE         0x01   // interrupt on error
205#define PCS_PMF         0x02   // pattern match flag (read only)
206#define PCS_IRF         0x04   // input register full (read only)
207#define PCS_ORE         0x08   // output register empty (read only)
208#define PCS_ERR         0x10   // interrupt error (read only)
209#define PCS_IP         0x20   // interrupt pending
210#define PCS_IE         0x40   // interrupt enable
211#define PCS_IUS         0x80   // interrupt under service
212
213
214// counter/timer mode specification registers
215#define CTMS_DCS_MASK   0x03   // output duty cycle
216#define CTMS_REB      0x04   // retrigger enable bit
217#define CTMS_EDE      0x08   // external gate enable
218#define CTMS_ETE      0x10   // external trigger enable
219#define CTMS_ECE      0x20   // external count enable
220#define CTMS_EOE      0x40   // external output enable
221#define CTMS_CSC      0x80   // continuous single cycle
222
223
224// counter/timer command and status registers
225#define CTCS_CIP      0x01   // count in progress (read only)
226#define CTCS_TCB      0x02   // trigger command bit (write only - read returns 0)
227#define CTCS_GCB      0x04   // gate command bit
228#define CTCS_RCC      0x08   // read counter control (read/set only - cleared by reading CCR LSB)
229#define CTCS_ERR      0x10   // interrupt error (read only)
230#define CTCS_IP         0x20   // interrupt pending
231#define CTCS_IE         0x40   // interrupt enable
232#define CTCS_IUS      0x80   // interrupt under service
233
234
235
236//**************************************************************************
237//  DEVICE DEFINITIONS
238//**************************************************************************
239
240const device_type Z8536 = z8536_device_config::static_alloc_device_config;
241
242
243
244//**************************************************************************
245//  DEVICE CONFIGURATION
246//**************************************************************************
247
248GENERIC_DEVICE_CONFIG_SETUP(z8536, "Zilog Z8536")
249
250
251//-------------------------------------------------
252//  device_config_complete - perform any
253//  operations now that the configuration is
254//  complete
255//-------------------------------------------------
256
257void z8536_device_config::device_config_complete()
258{
259   // inherit a copy of the static data
260   const z8536_interface *intf = reinterpret_cast<const z8536_interface *>(static_config());
261   if (intf != NULL)
262      *static_cast<z8536_interface *>(this) = *intf;
263
264   // or initialize to defaults if none provided
265   else
266   {
267      memset(&m_out_int_func, 0, sizeof(m_out_int_func));
268      memset(&m_in_pa_func, 0, sizeof(m_in_pa_func));
269      memset(&m_out_pa_func, 0, sizeof(m_out_pa_func));
270      memset(&m_in_pb_func, 0, sizeof(m_in_pb_func));
271      memset(&m_out_pb_func, 0, sizeof(m_out_pb_func));
272      memset(&m_in_pc_func, 0, sizeof(m_in_pc_func));
273      memset(&m_out_pc_func, 0, sizeof(m_out_pc_func));
274   }
275}
276
277
278
279//**************************************************************************
280//  INLINE HELPERS
281//**************************************************************************
282
283//-------------------------------------------------
284//  read_register - read from register
285//-------------------------------------------------
286
287inline UINT8 z8536_device::read_register(offs_t offset)
288{
289   UINT8 data = 0;
290   
291   data = m_register[offset]; // HACK
292
293   switch (offset)
294   {
295   case PORT_A_DATA:
296      data = devcb_call_read8(&m_in_pa_func, 0);
297      break;
298     
299   case PORT_B_DATA:
300      data = devcb_call_read8(&m_in_pb_func, 0);
301      break;
302     
303   case PORT_C_DATA:
304      data = 0xf0 | (devcb_call_read8(&m_in_pc_func, 0) & 0x0f);
305      break;
306     
307   default:
308      logerror("Z8536 '%s' Unimplemented read from register %u\n", tag(), offset);
309   }
310   
311   return data;
312}
313
314
315//-------------------------------------------------
316//  read_register - masked read from register
317//-------------------------------------------------
318
319inline UINT8 z8536_device::read_register(offs_t offset, UINT8 mask)
320{
321   return read_register(offset) & mask;
322}
323
324
325//-------------------------------------------------
326//  write_register - write to register
327//-------------------------------------------------
328
329inline void z8536_device::write_register(offs_t offset, UINT8 data)
330{
331   switch (offset)
332   {
333   case MASTER_INTERRUPT_CONTROL:
334      if (data & MICR_RESET)
335      {
336         device_reset();
337      }
338      else if (m_state == STATE_RESET)
339      {
340         m_state = STATE_0;
341      }
342      break;
343     
344   case PORT_A_DATA:
345      devcb_call_write8(&m_out_pa_func, 0, data);
346      break;
347     
348   case PORT_B_DATA:
349      devcb_call_write8(&m_out_pb_func, 0, data);
350      break;
351     
352   case PORT_C_DATA:
353      {
354      UINT8 mask = (data & 0xf0) | (data >> 4);
355
356      m_output[PORT_C] = (m_output[PORT_C] & mask) | ((data & 0x0f) & (mask ^ 0xff));
357     
358      devcb_call_write8(&m_out_pc_func, 0, m_output[PORT_C]);
359      }
360      break;
361     
362   default:
363      logerror("Z8536 '%s' Unimplemented write %02x to register %u\n", tag(), data, offset);
364   }
365   
366   m_register[offset] = data; // HACK
367}
368
369
370//-------------------------------------------------
371//  write_register - masked write to register
372//-------------------------------------------------
373
374inline void z8536_device::write_register(offs_t offset, UINT8 data, UINT8 mask)
375{
376   UINT8 combined_data = (data & mask) | (m_register[offset] & (mask ^ 0xff));
377   
378   write_register(offset, combined_data);
379}
380
381
382//-------------------------------------------------
383//   count -
384//-------------------------------------------------
385
386inline void z8536_device::count(device_timer_id id)
387{
388}
389
390
391//-------------------------------------------------
392//  trigger -
393//-------------------------------------------------
394
395inline void z8536_device::trigger(device_timer_id id)
396{
397}
398
399
400//-------------------------------------------------
401//  gate -
402//-------------------------------------------------
403
404inline void z8536_device::gate(device_timer_id id)
405{
406}
407
408
409
410//**************************************************************************
411//  LIVE DEVICE
412//**************************************************************************
413
414//-------------------------------------------------
415//  z8536_device - constructor
416//-------------------------------------------------
417
418z8536_device::z8536_device(running_machine &_machine, const z8536_device_config &config)
419    : device_t(_machine, config),
420      m_config(config)
421{
422}
423
424
425//-------------------------------------------------
426//  device_start - device-specific startup
427//-------------------------------------------------
428
429void z8536_device::device_start()
430{
431   // allocate timers
432   m_timer[TIMER_1] = timer_alloc(TIMER_1);
433   m_timer[TIMER_2] = timer_alloc(TIMER_2);
434   m_timer[TIMER_3] = timer_alloc(TIMER_3);
435     
436   // resolve callbacks
437   devcb_resolve_write_line(&m_out_int_func, &m_config.m_out_int_func, this);
438   devcb_resolve_read8(&m_in_pa_func, &m_config.m_in_pa_func, this);
439   devcb_resolve_write8(&m_out_pa_func, &m_config.m_out_pa_func, this);
440   devcb_resolve_read8(&m_in_pb_func, &m_config.m_in_pb_func, this);
441   devcb_resolve_write8(&m_out_pb_func, &m_config.m_out_pb_func, this);
442   devcb_resolve_read8(&m_in_pc_func, &m_config.m_in_pc_func, this);
443   devcb_resolve_write8(&m_out_pc_func, &m_config.m_out_pc_func, this);
444}
445
446
447//-------------------------------------------------
448//  device_start - device-specific reset
449//-------------------------------------------------
450
451void z8536_device::device_reset()
452{
453   m_state = STATE_RESET;
454   
455   for (int i = 0; i < 48; i++)
456   {
457      m_register[i] = 0;
458   }
459   
460   m_register[MASTER_INTERRUPT_CONTROL] = MICR_RESET;
461   m_pointer = 0;
462}
463
464
465//-------------------------------------------------
466//  device_timer - handler timer events
467//-------------------------------------------------
468
469void z8536_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
470{
471   switch (id)
472   {
473   case TIMER_1:
474      count(TIMER_1);
475      break;
476     
477   case TIMER_2:
478      count(TIMER_2);
479      break;
480     
481   case TIMER_3:
482      count(TIMER_3);
483      break;
484   }
485}
486
487
488//-------------------------------------------------
489//  read - register read
490//-------------------------------------------------
491
492READ8_MEMBER( z8536_device::read )
493{
494   UINT8 data = 0;
495
496   if (m_state == STATE_RESET)
497   {
498      // read RESET bit
499      data = read_register(m_pointer, 0x01);
500   }
501   else
502   {
503      switch (offset & 0x03)
504      {
505      case PORT_C:
506         data = read_register(PORT_C_DATA);
507         break;
508
509      case PORT_B:
510         data = read_register(PORT_B_DATA);
511         break;
512
513      case PORT_A:
514         data = read_register(PORT_A_DATA);
515         break;
516
517      case CONTROL:
518         switch (m_state)
519         {
520         case STATE_1:
521            m_state = STATE_0;
522            // fallthru
523         case STATE_0:
524            data = read_register(m_pointer);
525            break;
526         }
527         break;
528      }
529   }
530   
531   return data;
532}
533
534
535//-------------------------------------------------
536//  write - register write
537//-------------------------------------------------
538
539WRITE8_MEMBER( z8536_device::write )
540{
541   if (m_state == STATE_RESET)
542   {
543      // write RESET bit
544      write_register(m_pointer, data, 0x01);
545   }
546   else
547   {
548      switch (offset & 0x03)
549      {
550      case PORT_C:
551         write_register(PORT_C_DATA, data);
552         break;
553
554      case PORT_B:
555         write_register(PORT_B_DATA, data);
556         break;
557
558      case PORT_A:
559         write_register(PORT_A_DATA, data);
560         break;
561
562      case CONTROL:
563         switch (m_state)
564         {
565         case STATE_0:
566            m_pointer = data;
567            m_state = STATE_1;
568            break;
569
570         case STATE_1:
571            write_register(m_pointer, data);
572            m_state = STATE_0;
573         }
574         break;
575      }
576   }
577}
578
579
580//-------------------------------------------------
581//  intack_w - interrupt acknowledge
582//-------------------------------------------------
583
584WRITE_LINE_MEMBER( z8536_device::intack_w )
585{
586}
587
588
589//-------------------------------------------------
590//  pb*_w - port B bits 0-7 write
591//-------------------------------------------------
592
593WRITE_LINE_MEMBER( z8536_device::pb0_w ) { }
594WRITE_LINE_MEMBER( z8536_device::pb1_w ) { }
595WRITE_LINE_MEMBER( z8536_device::pb2_w ) { }
596WRITE_LINE_MEMBER( z8536_device::pb3_w ) { }
597WRITE_LINE_MEMBER( z8536_device::pb4_w ) { }
598WRITE_LINE_MEMBER( z8536_device::pb5_w ) { }
599WRITE_LINE_MEMBER( z8536_device::pb6_w ) { }
600WRITE_LINE_MEMBER( z8536_device::pb7_w ) { }
601
602
603//-------------------------------------------------
604//  pc*_w - port C bits 0-3 write
605//-------------------------------------------------
606
607WRITE_LINE_MEMBER( z8536_device::pc0_w ) { }
608WRITE_LINE_MEMBER( z8536_device::pc1_w ) { }
609WRITE_LINE_MEMBER( z8536_device::pc2_w ) { }
610WRITE_LINE_MEMBER( z8536_device::pc3_w ) { }
src/emu/machine/z8536.h
r0r10969
1/**********************************************************************
2
3    Zilog Z8536 Counter/Timer and Parallel I/O emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                    D4   1 |*    \_/     | 40  D3
11                    D5   2 |             | 39  D2
12                    D6   3 |             | 38  D1
13                    D7   4 |             | 37  D0
14                   _RD   5 |             | 36  _CE
15                   _WR   6 |             | 35  A1
16                   GND   7 |             | 34  A0
17                   PB0   8 |             | 33  PA0
18                   PB1   9 |             | 32  PA1
19                   PB2  10 |    Z8536    | 31  PA2
20                   PB3  11 |             | 30  PA3
21                   PB4  12 |             | 29  PA4
22                   PB5  13 |             | 28  PA5
23                   PB6  14 |             | 27  PA6
24                   PB7  15 |             | 26  PA7
25                  PCLK  16 |             | 25  _INTACK
26                   IEI  17 |             | 24  _INT
27                   IEO  18 |             | 23  +5 V
28                   PC0  19 |             | 22  PC3
29                   PC1  20 |_____________| 21  PC2
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __Z8536__
36#define __Z8536__
37
38#include "emu.h"
39
40
41
42//**************************************************************************
43//  MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
53#define MCFG_Z8536_ADD(_tag, _clock, _intrf) \
54   MCFG_DEVICE_ADD(_tag, Z8536, _clock) \
55   MCFG_DEVICE_CONFIG(_intrf)
56
57#define Z8536_INTERFACE(name) \
58   const z8536_interface (name)=
59
60
61
62//**************************************************************************
63//  TYPE DEFINITIONS
64//**************************************************************************
65
66// ======================> z8536_interface
67
68struct z8536_interface
69{
70   devcb_write_line      m_out_int_func;
71   
72   devcb_read8            m_in_pa_func;
73   devcb_write8         m_out_pa_func;
74   
75   devcb_read8            m_in_pb_func;
76   devcb_write8         m_out_pb_func;
77   
78   devcb_read8            m_in_pc_func;
79   devcb_write8         m_out_pc_func;
80};
81
82
83// ======================> z8536_device_config
84
85class z8536_device_config :   public device_config,
86                                public z8536_interface
87{
88    friend class z8536_device;
89
90    // construction/destruction
91    z8536_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
92
93public:
94    // allocators
95    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
96    virtual device_t *alloc_device(running_machine &machine) const;
97
98protected:
99    // device_config overrides
100    virtual void device_config_complete();
101};
102
103
104// ======================> z8536_device
105
106class z8536_device :  public device_t
107{
108    friend class z8536_device_config;
109
110    // construction/destruction
111    z8536_device(running_machine &_machine, const z8536_device_config &_config);
112
113public:
114    DECLARE_READ8_MEMBER( read );
115    DECLARE_WRITE8_MEMBER( write );
116
117   DECLARE_WRITE_LINE_MEMBER( intack_w );
118
119   DECLARE_WRITE_LINE_MEMBER( pb0_w );
120   DECLARE_WRITE_LINE_MEMBER( pb1_w );
121   DECLARE_WRITE_LINE_MEMBER( pb2_w );
122   DECLARE_WRITE_LINE_MEMBER( pb3_w );
123   DECLARE_WRITE_LINE_MEMBER( pb4_w );
124   DECLARE_WRITE_LINE_MEMBER( pb5_w );
125   DECLARE_WRITE_LINE_MEMBER( pb6_w );
126   DECLARE_WRITE_LINE_MEMBER( pb7_w );
127   DECLARE_WRITE_LINE_MEMBER( pc0_w );
128   DECLARE_WRITE_LINE_MEMBER( pc1_w );
129   DECLARE_WRITE_LINE_MEMBER( pc2_w );
130   DECLARE_WRITE_LINE_MEMBER( pc3_w );
131
132protected:
133    // device-level overrides
134    virtual void device_start();
135    virtual void device_reset();
136   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
137
138private:
139   static const device_timer_id TIMER_1 = 0;
140   static const device_timer_id TIMER_2 = 1;
141   static const device_timer_id TIMER_3 = 2;
142
143   inline UINT8 read_register(offs_t offset);
144   inline UINT8 read_register(offs_t offset, UINT8 mask);
145   inline void write_register(offs_t offset, UINT8 data);
146   inline void write_register(offs_t offset, UINT8 data, UINT8 mask);
147   
148   inline void count(device_timer_id id);
149   inline void trigger(device_timer_id id);
150   inline void gate(device_timer_id id);
151   
152   devcb_resolved_write_line      m_out_int_func;
153   
154   devcb_resolved_read8         m_in_pa_func;
155   devcb_resolved_write8         m_out_pa_func;
156   
157   devcb_resolved_read8         m_in_pb_func;
158   devcb_resolved_write8         m_out_pb_func;
159   
160   devcb_resolved_read8         m_in_pc_func;
161   devcb_resolved_write8         m_out_pc_func;
162
163   int m_state;
164   UINT8 m_register[48];
165   UINT8 m_pointer;
166   UINT8 m_input[3];
167   UINT8 m_output[3];
168   UINT8 m_buffer[3];
169
170   // timers
171   emu_timer *m_timer[3];
172
173   const z8536_device_config &m_config;
174};
175
176
177// device type definition
178extern const device_type Z8536;
179
180
181
182#endif
src/emu/machine/cdp1871.c
r0r10969
1/**********************************************************************
2
3    RCA CDP1871 Keyboard Encoder emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "cdp1871.h"
12#include "cpu/mcs48/mcs48.h"
13#include "machine/devhelpr.h"
14
15
16
17//**************************************************************************
18//  MACROS / CONSTANTS
19//**************************************************************************
20
21static const UINT8 CDP1871_KEY_CODES[4][11][8] =
22{
23   // normal
24   {
25      { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 },
26      { 0x38, 0x39, 0x3a, 0x3b, 0x2c, 0x2d, 0x2e, 0x2f },
27      { 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67 },
28      { 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f },
29      { 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77 },
30      { 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f },
31      { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f },
32      { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 },
33      { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f },
34      { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 },
35      { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }
36   },
37
38   // alpha
39   {
40      { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 },
41      { 0x38, 0x39, 0x3a, 0x3b, 0x2c, 0x2d, 0x2e, 0x2f },
42      { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 },
43      { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f },
44      { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 },
45      { 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f },
46      { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f },
47      { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 },
48      { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f },
49      { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 },
50      { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }
51   },
52
53   // shift
54   {
55      { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 },
56      { 0x28, 0x29, 0x2a, 0x2b, 0x3c, 0x3d, 0x3e, 0x3f },
57      { 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 },
58      { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f },
59      { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 },
60      { 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f },
61      { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f },
62      { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 },
63      { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f },
64      { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 },
65      { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }
66   },
67
68   // control
69   {
70      { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
71      { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
72      { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
73      { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
74      { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },
75      { 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
76      { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f },
77      { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 },
78      { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f },
79      { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 },
80      { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }
81   }
82};
83
84
85
86//**************************************************************************
87//  DEVICE DEFINITIONS
88//**************************************************************************
89
90const device_type CDP1871 = cdp1871_device_config::static_alloc_device_config;
91
92
93
94//**************************************************************************
95//  DEVICE CONFIGURATION
96//**************************************************************************
97
98GENERIC_DEVICE_CONFIG_SETUP(cdp1871, "RCA CDP1871")
99
100
101//-------------------------------------------------
102//  device_config_complete - perform any
103//  operations now that the configuration is
104//  complete
105//-------------------------------------------------
106
107void cdp1871_device_config::device_config_complete()
108{
109   // inherit a copy of the static data
110   const cdp1871_interface *intf = reinterpret_cast<const cdp1871_interface *>(static_config());
111   if (intf != NULL)
112      *static_cast<cdp1871_interface *>(this) = *intf;
113
114   // or initialize to defaults if none provided
115   else
116   {
117      memset(&out_da_func, 0, sizeof(out_da_func));
118      memset(&out_rpt_func, 0, sizeof(out_rpt_func));
119      // m_in_d_func[]
120      memset(&in_shift_func, 0, sizeof(in_shift_func));
121      memset(&in_control_func, 0, sizeof(in_control_func));
122      memset(&in_alpha_func, 0, sizeof(in_alpha_func));
123   }
124}
125
126
127
128//**************************************************************************
129//  LIVE DEVICE
130//**************************************************************************
131
132//-------------------------------------------------
133//  cdp1871_device - constructor
134//-------------------------------------------------
135
136cdp1871_device::cdp1871_device(running_machine &_machine, const cdp1871_device_config &config)
137    : device_t(_machine, config),
138     m_inhibit(false),
139     m_sense(0),
140     m_drive(0),
141     m_next_da(CLEAR_LINE),
142     m_next_rpt(CLEAR_LINE),
143      m_config(config)
144{
145
146}
147
148
149//-------------------------------------------------
150//  device_start - device-specific startup
151//-------------------------------------------------
152
153void cdp1871_device::device_start()
154{
155   // resolve callbacks
156   devcb_resolve_write_line(&m_out_da_func, &m_config.out_da_func, this);
157   devcb_resolve_write_line(&m_out_rpt_func, &m_config.out_rpt_func, this);
158   devcb_resolve_read8(&m_in_d_func[0], &m_config.in_d1_func, this);
159   devcb_resolve_read8(&m_in_d_func[1], &m_config.in_d2_func, this);
160   devcb_resolve_read8(&m_in_d_func[2], &m_config.in_d3_func, this);
161   devcb_resolve_read8(&m_in_d_func[3], &m_config.in_d4_func, this);
162   devcb_resolve_read8(&m_in_d_func[4], &m_config.in_d5_func, this);
163   devcb_resolve_read8(&m_in_d_func[5], &m_config.in_d6_func, this);
164   devcb_resolve_read8(&m_in_d_func[6], &m_config.in_d7_func, this);
165   devcb_resolve_read8(&m_in_d_func[7], &m_config.in_d8_func, this);
166   devcb_resolve_read8(&m_in_d_func[8], &m_config.in_d9_func, this);
167   devcb_resolve_read8(&m_in_d_func[9], &m_config.in_d10_func, this);
168   devcb_resolve_read8(&m_in_d_func[10], &m_config.in_d11_func, this);
169   devcb_resolve_read_line(&m_in_shift_func, &m_config.in_shift_func, this);
170   devcb_resolve_read_line(&m_in_control_func, &m_config.in_control_func, this);
171   devcb_resolve_read_line(&m_in_alpha_func, &m_config.in_alpha_func, this);
172
173   // set initial values
174   change_output_lines();
175
176   // allocate timers
177   m_scan_timer = timer_alloc();
178   m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(clock()));
179
180   // register for state saving
181   save_item(NAME(m_inhibit));
182   save_item(NAME(m_sense));
183   save_item(NAME(m_drive));
184   save_item(NAME(m_shift));
185   save_item(NAME(m_control));
186   save_item(NAME(m_da));
187   save_item(NAME(m_next_da));
188   save_item(NAME(m_rpt));
189   save_item(NAME(m_next_rpt));
190}
191
192
193//-------------------------------------------------
194//  device_timer - handler timer events
195//-------------------------------------------------
196
197void cdp1871_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
198{
199   change_output_lines();
200   clock_scan_counters();
201   detect_keypress();
202}
203
204
205//-------------------------------------------------
206//  change_output_lines - change output lines
207//-------------------------------------------------
208
209void cdp1871_device::change_output_lines()
210{
211   if (m_next_da != m_da)
212   {
213      m_da = m_next_da;
214
215      devcb_call_write_line(&m_out_da_func, m_da);
216   }
217
218   if (m_next_rpt != m_rpt)
219   {
220      m_rpt = m_next_rpt;
221
222      devcb_call_write_line(&m_out_rpt_func, m_rpt);
223   }
224}
225
226
227//-------------------------------------------------
228//  clock_scan_counters - clock the keyboard
229//  scan counters
230//-------------------------------------------------
231
232void cdp1871_device::clock_scan_counters()
233{
234   if (!m_inhibit)
235   {
236      m_sense++;
237
238      if (m_sense == 8)
239      {
240         m_sense = 0;
241         m_drive++;
242
243         if (m_drive == 11)
244         {
245            m_drive = 0;
246         }
247      }
248   }
249}
250
251
252//-------------------------------------------------
253//  detect_keypress - detect key press
254//-------------------------------------------------
255
256void cdp1871_device::detect_keypress()
257{
258   UINT8 data = 0;
259
260   data = devcb_call_read8(&m_in_d_func[m_drive], 0);
261
262   if (data == (1 << m_sense))
263   {
264      if (!m_inhibit)
265      {
266         m_shift = devcb_call_read_line(&m_in_shift_func);
267         m_control = devcb_call_read_line(&m_in_control_func);
268         m_inhibit = true;
269         m_next_da = ASSERT_LINE;
270      }
271      else
272      {
273         m_next_rpt = ASSERT_LINE;
274      }
275   }
276   else
277   {
278      m_inhibit = false;
279      m_next_rpt = CLEAR_LINE;
280   }
281}
282
283
284//-------------------------------------------------
285//  data_r - keyboard data read
286//-------------------------------------------------
287
288READ8_MEMBER( cdp1871_device::data_r )
289{
290   int table = 0;
291   int alpha = devcb_call_read_line(&m_in_alpha_func);
292
293   if (m_control) table = 3; else if (m_shift) table = 2; else if (alpha) table = 1;
294
295   // reset DA on next TPB
296   m_next_da = CLEAR_LINE;
297
298   return CDP1871_KEY_CODES[table][m_drive][m_sense];
299}
300
301
302//-------------------------------------------------
303//  da_r - data available
304//-------------------------------------------------
305
306READ_LINE_MEMBER( cdp1871_device::da_r )
307{
308   return m_da;
309}
310
311
312//-------------------------------------------------
313//  rpt_r - keyboard repeat
314//-------------------------------------------------
315
316READ_LINE_MEMBER( cdp1871_device::rpt_r )
317{
318   return m_rpt;
319}
src/emu/machine/cdp1871.h
r0r10969
1/**********************************************************************
2
3    RCA CDP1871 Keyboard Encoder emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                    D1   1 |*    \_/     | 40  Vdd
11                    D2   2 |             | 39  SHIFT
12                    D3   3 |             | 38  CONTROL
13                    D4   4 |             | 37  ALPHA
14                    D5   5 |             | 36  DEBOUNCE
15                    D6   6 |             | 35  _RTP
16                    D7   7 |             | 34  TPB
17                    D8   8 |             | 33  _DA
18                    D9   9 |             | 32  BUS 7
19                   D10  10 |   CDP1871   | 31  BUS 6
20                   D11  11 |             | 30  BUS 5
21                    S1  12 |             | 29  BUS 4
22                    S2  13 |             | 28  BUS 3
23                    S3  14 |             | 27  BUS 2
24                    S4  15 |             | 26  BUS 1
25                    S5  16 |             | 25  BUS 0
26                    S6  17 |             | 24  CS4
27                    S7  18 |             | 23  CS3
28                    S8  19 |             | 22  CS2
29                   Vss  20 |_____________| 21  _CS1
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __CDP1871__
36#define __CDP1871__
37
38#include "emu.h"
39
40
41
42//**************************************************************************
43//  MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
53#define MCFG_CDP1871_ADD(_tag, _intrf, _clock) \
54   MCFG_DEVICE_ADD(_tag, CDP1871, _clock) \
55   MCFG_DEVICE_CONFIG(_intrf)
56
57#define CDP1871_INTERFACE(name) \
58   const cdp1871_interface (name)=
59
60
61
62//**************************************************************************
63//  TYPE DEFINITIONS
64//**************************************************************************
65
66// ======================> cdp1871_interface
67
68struct cdp1871_interface
69{
70   devcb_read8         in_d1_func;
71   devcb_read8         in_d2_func;
72   devcb_read8         in_d3_func;
73   devcb_read8         in_d4_func;
74   devcb_read8         in_d5_func;
75   devcb_read8         in_d6_func;
76   devcb_read8         in_d7_func;
77   devcb_read8         in_d8_func;
78   devcb_read8         in_d9_func;
79   devcb_read8         in_d10_func;
80   devcb_read8         in_d11_func;
81
82   devcb_read_line      in_shift_func;
83   devcb_read_line      in_control_func;
84   devcb_read_line      in_alpha_func;
85
86   // this gets called for every change of the DA pin (pin 33)
87   devcb_write_line   out_da_func;
88
89   // this gets called for every change of the RPT pin (pin 35)
90   devcb_write_line   out_rpt_func;
91};
92
93
94// ======================> cdp1871_device_config
95
96class cdp1871_device_config :   public device_config,
97                                public cdp1871_interface
98{
99    friend class cdp1871_device;
100
101    // construction/destruction
102    cdp1871_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
103
104public:
105    // allocators
106    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
107    virtual device_t *alloc_device(running_machine &machine) const;
108
109protected:
110    // device_config overrides
111    virtual void device_config_complete();
112};
113
114
115// ======================> cdp1871_device
116
117class cdp1871_device :  public device_t
118{
119    friend class cdp1871_device_config;
120
121    // construction/destruction
122    cdp1871_device(running_machine &_machine, const cdp1871_device_config &_config);
123
124public:
125    DECLARE_READ8_MEMBER( data_r );
126
127   DECLARE_READ_LINE_MEMBER( da_r );
128   DECLARE_READ_LINE_MEMBER( rpt_r );
129
130protected:
131    // device-level overrides
132    virtual void device_start();
133   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
134
135   void change_output_lines();
136   void clock_scan_counters();
137   void detect_keypress();
138
139private:
140   devcb_resolved_write_line      m_out_da_func;
141   devcb_resolved_write_line      m_out_rpt_func;
142   devcb_resolved_read8         m_in_d_func[11];
143   devcb_resolved_read_line      m_in_shift_func;
144   devcb_resolved_read_line      m_in_control_func;
145   devcb_resolved_read_line      m_in_alpha_func;
146
147   bool m_inhibit;               // scan counter clock inhibit
148   int m_sense;               // sense input scan counter
149   int m_drive;               // modifier inputs
150
151   int m_shift;               // latched shift modifier
152   int m_control;               // latched control modifier
153
154   int m_da;                  // data available flag
155   int m_next_da;               // next value of data available flag
156   int m_rpt;                  // repeat flag
157   int m_next_rpt;               // next value of repeat flag
158
159   // timers
160   emu_timer *m_scan_timer;      // keyboard scan timer
161
162   const cdp1871_device_config &m_config;
163};
164
165
166// device type definition
167extern const device_type CDP1871;
168
169
170
171#endif
src/emu/machine/nmc9306.c
r0r10969
1/**********************************************************************
2
3    National Semiconductor NMC9306 256-Bit Serial EEPROM emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "nmc9306.h"
12#include "machine/devhelpr.h"
13
14
15
16//**************************************************************************
17//  MACROS / CONSTANTS
18//**************************************************************************
19
20#define LOG 1
21
22#define RAM_SIZE 32
23
24
25// instructions
26enum
27{
28   OTHER = 0,
29   WRITE,         // write register A3A2A1A0
30   READ,         // read register  A3A2A1A0
31   ERASE         // erase register A3A2A1A0
32};
33
34// other instructions
35enum
36{
37   EWDS = 0,      // erase/write disable
38   WRAL,         // write all registers
39   ERAL,         // erase all registers
40   EWEN,         // erase/write enable
41};
42
43// states
44enum
45{
46   STATE_IDLE = 0,
47   STATE_COMMAND,
48   STATE_ADDRESS,
49   STATE_DATA_IN,
50   STATE_DATA_OUT,
51   STATE_ERASE
52};
53
54
55
56//**************************************************************************
57//  DEVICE DEFINITIONS
58//**************************************************************************
59
60const device_type NMC9306 = nmc9306_device_config::static_alloc_device_config;
61
62
63
64//**************************************************************************
65//  DEVICE CONFIGURATION
66//**************************************************************************
67
68//-------------------------------------------------
69//  nmc9306_device_config - constructor
70//-------------------------------------------------
71
72nmc9306_device_config::nmc9306_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
73   : device_config(mconfig, static_alloc_device_config, "NMC9306", tag, owner, clock),
74     device_config_nvram_interface(mconfig, *this)
75{
76}
77
78
79//-------------------------------------------------
80//  static_alloc_device_config - allocate a new
81//  configuration object
82//-------------------------------------------------
83
84device_config *nmc9306_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
85{
86   return global_alloc(nmc9306_device_config(mconfig, tag, owner, clock));
87}
88
89
90//-------------------------------------------------
91//  alloc_device - allocate a new device object
92//-------------------------------------------------
93
94device_t *nmc9306_device_config::alloc_device(running_machine &machine) const
95{
96   return auto_alloc(&machine, nmc9306_device(machine, *this));
97}
98
99
100
101//**************************************************************************
102//  INLINE HELPERS
103//**************************************************************************
104
105//-------------------------------------------------
106//  nmc9306_device - constructor
107//-------------------------------------------------
108
109inline UINT16 nmc9306_device::read(offs_t offset)
110{
111   return m_register[offset];
112}
113
114
115//-------------------------------------------------
116//  nmc9306_device - constructor
117//-------------------------------------------------
118
119inline void nmc9306_device::write(offs_t offset, UINT16 data)
120{
121   if (m_ewen)
122   {
123      m_register[offset] &= data;
124   }
125}
126
127
128//-------------------------------------------------
129//  nmc9306_device - constructor
130//-------------------------------------------------
131
132inline void nmc9306_device::erase(offs_t offset)
133{
134   if (m_ewen)
135   {
136      m_register[offset] = 0xffff;
137   }
138}
139
140
141
142//**************************************************************************
143//  LIVE DEVICE
144//**************************************************************************
145
146//-------------------------------------------------
147//  nmc9306_device - constructor
148//-------------------------------------------------
149
150nmc9306_device::nmc9306_device(running_machine &_machine, const nmc9306_device_config &config)
151    : device_t(_machine, config),
152     device_nvram_interface(_machine, config, *this),
153     m_state(STATE_IDLE),
154     m_ewen(false),
155      m_config(config)
156{
157}
158
159
160//-------------------------------------------------
161//  device_start - device-specific startup
162//-------------------------------------------------
163
164void nmc9306_device::device_start()
165{
166   // state saving
167   save_item(NAME(m_bits));
168   save_item(NAME(m_state));
169   save_item(NAME(m_command));
170   save_item(NAME(m_address));
171   save_item(NAME(m_data));
172   save_item(NAME(m_ewen));
173   save_item(NAME(m_cs));
174   save_item(NAME(m_sk));
175   save_item(NAME(m_do));
176   save_item(NAME(m_di));
177}
178
179
180//-------------------------------------------------
181//  nvram_default - called to initialize NVRAM to
182//  its default state
183//-------------------------------------------------
184
185void nmc9306_device::nvram_default()
186{
187}
188
189
190//-------------------------------------------------
191//  nvram_read - called to read NVRAM from the
192//  .nv file
193//-------------------------------------------------
194
195void nmc9306_device::nvram_read(emu_file &file)
196{
197   file.read(m_register, RAM_SIZE);
198}
199
200
201//-------------------------------------------------
202//  nvram_write - called to write NVRAM to the
203//  .nv file
204//-------------------------------------------------
205
206void nmc9306_device::nvram_write(emu_file &file)
207{
208   file.write(m_register, RAM_SIZE);
209}
210
211
212//-------------------------------------------------
213//  cs_w - chip select input
214//-------------------------------------------------
215
216WRITE_LINE_MEMBER( nmc9306_device::cs_w )
217{
218   m_cs = state;
219}
220
221
222//-------------------------------------------------
223//  ck_w - serial clock input
224//-------------------------------------------------
225
226WRITE_LINE_MEMBER( nmc9306_device::sk_w )
227{
228   m_sk = state;
229   
230   if (!m_cs || !m_sk) return;
231   
232   switch (m_state)
233   {
234   case STATE_IDLE:
235      if (LOG) logerror("NMC9306 '%s' Idle %u\n", tag(), m_di);
236     
237      if (m_di)
238      {
239         // start bit received
240         m_state = STATE_COMMAND;
241         m_bits = 0;
242      }
243      break;
244     
245   case STATE_COMMAND:
246      if (LOG) logerror("NMC9306 '%s' Command Bit %u\n", tag(), m_di);
247     
248      m_command <<= 1;
249      m_command |= m_di;
250      m_bits++;
251     
252      if (m_bits == 4)
253      {
254         m_state = STATE_ADDRESS;
255         m_bits = 0;
256      }
257      break;
258     
259   case STATE_ADDRESS:
260      if (LOG) logerror("NMC9306 '%s' Address Bit %u\n", tag(), m_di);
261     
262      m_address <<= 1;
263      m_address |= m_di;
264      m_bits++;
265     
266      if (m_bits == 4)
267      {
268         switch ((m_command >> 2) & 0x03)
269         {
270         case OTHER:
271            switch (m_command & 0x03)
272            {
273            case EWDS:
274               if (LOG) logerror("NMC9306 '%s' EWDS\n", tag());
275               m_ewen = false;
276               m_state = STATE_IDLE;
277               break;
278               
279            case WRAL:
280               if (LOG) logerror("NMC9306 '%s' WRAL\n", tag());
281               break;
282               
283            case ERAL:
284               if (LOG) logerror("NMC9306 '%s' ERAL\n", tag());
285               break;
286
287            case EWEN:
288               if (LOG) logerror("NMC9306 '%s' EWEN\n", tag());
289               m_ewen = true;
290               m_state = STATE_IDLE;
291               break;
292            }
293            break;
294
295         case WRITE:
296            if (LOG) logerror("NMC9306 '%s' WRITE %u\n", tag(), m_address & 0x0f);
297            m_state = STATE_DATA_IN;
298            break;
299           
300         case READ:
301            if (LOG) logerror("NMC9306 '%s' READ %u\n", tag(), m_address & 0x0f);
302            m_data = read(m_address & 0x0f);
303            m_state = STATE_DATA_OUT;
304            break;
305           
306         case ERASE:
307            if (LOG) logerror("NMC9306 '%s' ERASE %u\n", tag(), m_address & 0x0f);
308            erase(m_address & 0x0f);
309            m_state = STATE_ERASE;
310            break;
311         }
312         
313         m_bits = 0;
314      }
315      break;
316     
317   case STATE_DATA_IN:
318      if (LOG) logerror("NMC9306 '%s' Data Bit IN %u\n", tag(), m_di);
319     
320      m_data <<= 1;
321      m_data |= m_di;
322      m_bits++;
323     
324      if (m_bits == 16)
325      {
326         write(m_address & 0x0f, m_data);
327         
328         m_state = STATE_IDLE;
329      }
330      break;
331     
332   case STATE_DATA_OUT:
333      if (LOG) logerror("NMC9306 '%s' Data Bit OUT %u\n", tag(), m_di);
334     
335      m_do = BIT(m_data, 15);
336      m_data <<= 1;
337      m_bits++;
338     
339      if (m_bits == 16)
340      {
341         m_state = STATE_IDLE;
342      }
343      break;
344   }
345}
346
347
348//-------------------------------------------------
349//  di_w - serial data input
350//-------------------------------------------------
351
352WRITE_LINE_MEMBER( nmc9306_device::di_w )
353{
354   m_di = state;
355}
356
357
358//-------------------------------------------------
359//  do_r - serial data output
360//-------------------------------------------------
361
362READ_LINE_MEMBER( nmc9306_device::do_r )
363{
364   return m_do;
365}
src/emu/machine/e0516.c
r0r10969
1/**********************************************************************
2
3    E05-16 Real Time Clock emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "e0516.h"
12#include "machine/devhelpr.h"
13
14
15
16//**************************************************************************
17//  MACROS / CONSTANTS
18//**************************************************************************
19
20#define LOG 1
21
22
23// states
24enum
25{
26   STATE_ADDRESS = 0,
27   STATE_DATA
28};
29
30
31// registers
32enum
33{
34   SECOND = 0,
35   MINUTE,
36   HOUR,
37   DAY,
38   MONTH,
39   DAY_OF_WEEK,
40   YEAR,
41   ALL
42};
43
44
45
46//**************************************************************************
47//  DEVICE DEFINITIONS
48//**************************************************************************
49
50const device_type E0516 = e0516_device_config::static_alloc_device_config;
51
52
53
54//**************************************************************************
55//  DEVICE CONFIGURATION
56//**************************************************************************
57
58GENERIC_DEVICE_CONFIG_SETUP(e0516, "E05-16")
59
60
61
62//**************************************************************************
63//  INLINE HELPERS
64//**************************************************************************
65
66
67
68//**************************************************************************
69//  LIVE DEVICE
70//**************************************************************************
71
72//-------------------------------------------------
73//  e0516_device - constructor
74//-------------------------------------------------
75
76e0516_device::e0516_device(running_machine &_machine, const e0516_device_config &config)
77    : device_t(_machine, config),
78      m_config(config)
79{
80}
81
82
83//-------------------------------------------------
84//  device_start - device-specific startup
85//-------------------------------------------------
86
87void e0516_device::device_start()
88{
89   // allocate timers
90   m_timer = timer_alloc();
91   m_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768));
92   
93   // state saving
94   save_item(NAME(m_cs));
95   save_item(NAME(m_clk));
96   save_item(NAME(m_data_latch));
97   save_item(NAME(m_reg_latch));
98   save_item(NAME(m_read_write));
99   save_item(NAME(m_state));
100   save_item(NAME(m_bits));
101   save_item(NAME(m_dio));
102   save_item(NAME(m_register));
103}
104
105
106//-------------------------------------------------
107//  device_start - device-specific reset
108//-------------------------------------------------
109
110void e0516_device::device_reset()
111{
112}
113
114
115//-------------------------------------------------
116//  device_timer - handler timer events
117//-------------------------------------------------
118
119void e0516_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
120{
121   m_register[SECOND]++;
122
123   if (m_register[SECOND] == 60)
124   {
125      m_register[SECOND] = 0;
126      m_register[MINUTE]++;
127   }
128
129   if (m_register[MINUTE] == 60)
130   {
131      m_register[MINUTE] = 0;
132      m_register[HOUR]++;
133   }
134
135   if (m_register[HOUR] == 24)
136   {
137      m_register[HOUR] = 0;
138      m_register[DAY]++;
139      m_register[DAY_OF_WEEK]++;
140   }
141
142   if (m_register[DAY_OF_WEEK] == 8)
143   {
144      m_register[DAY_OF_WEEK] = 1;
145   }
146
147   if (m_register[DAY] == 32)
148   {
149      m_register[DAY] = 1;
150      m_register[MONTH]++;
151   }
152
153   if (m_register[MONTH] == 13)
154   {
155      m_register[MONTH] = 1;
156      m_register[YEAR]++;
157   }
158}
159
160
161//-------------------------------------------------
162//  cs_w - chip select input
163//-------------------------------------------------
164
165WRITE_LINE_MEMBER( e0516_device::cs_w )
166{
167   m_cs = state;
168   
169   if (m_cs)
170   {
171      m_data_latch = 0;
172      m_reg_latch = 0;
173      m_bits = 0;
174      m_state = STATE_ADDRESS;
175   }
176}
177
178
179//-------------------------------------------------
180//  clk_w - serial clock input
181//-------------------------------------------------
182
183WRITE_LINE_MEMBER( e0516_device::clk_w )
184{
185   m_clk = state;
186   
187   if (m_cs || m_clk) return;
188
189   m_bits++;
190
191   if (m_state == STATE_ADDRESS)
192   {
193      if (LOG) logerror("E05-16 '%s' Command Bit %u\n", tag(), m_dio);
194
195      // command
196      m_reg_latch |= m_dio << 3;
197      m_reg_latch >>= 1;
198
199      if (m_bits == 4)
200      {
201         m_state = STATE_DATA;
202         m_bits = 0;
203
204         if (BIT(m_reg_latch, 0))
205         {
206            // load register value to data latch
207            m_data_latch = m_register[m_reg_latch >> 1];
208         }
209      }
210   }
211   else
212   {
213      // data
214      if (BIT(m_reg_latch, 0))
215      {
216         // read
217         if (LOG) logerror("E05-16 '%s' Data Bit OUT %u\n", tag(), m_dio);
218         
219         m_dio = BIT(m_data_latch, 0);
220         m_data_latch >>= 1;
221      }
222      else
223      {
224         // write
225         if (LOG) logerror("E05-16 '%s' Data Bit IN %u\n", tag(), m_dio);
226
227         m_data_latch |= m_dio << 7;
228         m_data_latch >>= 1;
229      }
230
231      if (m_bits == 8)
232      {
233         m_state = STATE_ADDRESS;
234         m_bits = 0;
235
236         if (!BIT(m_reg_latch, 0))
237         {
238            // write latched data to register
239            m_register[m_reg_latch >> 1] = m_data_latch;
240         }
241      }
242   }
243}
244
245
246//-------------------------------------------------
247//  dio_w - serial data input
248//-------------------------------------------------
249
250WRITE_LINE_MEMBER( e0516_device::dio_w )
251{
252   m_dio = state;
253}
254
255
256//-------------------------------------------------
257//  do_r - serial data output
258//-------------------------------------------------
259
260READ_LINE_MEMBER( e0516_device::dio_r )
261{
262   return m_dio;
263}
src/emu/machine/nmc9306.h
r0r10969
1/**********************************************************************
2
3    National Semiconductor NMC9306 256-Bit Serial EEPROM emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                    CS   1 |*    \_/     | 8   Vcc
11                    SK   2 |             | 7   NC
12                    DI   3 |             | 6   NC
13                    DO   4 |_____________| 5   GND
14
15**********************************************************************/
16
17#pragma once
18
19#ifndef __NMC9306__
20#define __NMC9306__
21
22#include "emu.h"
23
24
25
26//**************************************************************************
27//  MACROS / CONSTANTS
28//**************************************************************************
29
30
31
32
33//**************************************************************************
34//  INTERFACE CONFIGURATION MACROS
35//**************************************************************************
36
37#define MCFG_NMC9306_ADD(_tag) \
38   MCFG_DEVICE_ADD(_tag, NMC9306, 0)
39
40
41
42//**************************************************************************
43//  TYPE DEFINITIONS
44//**************************************************************************
45
46
47// ======================> nmc9306_device_config
48
49class nmc9306_device_config :   public device_config,
50                        public device_config_nvram_interface
51{
52    friend class nmc9306_device;
53
54    // construction/destruction
55    nmc9306_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
56
57public:
58    // allocators
59    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
60    virtual device_t *alloc_device(running_machine &machine) const;
61
62protected:
63};
64
65
66// ======================> nmc9306_device
67
68class nmc9306_device :  public device_t,
69                  public device_nvram_interface
70{
71    friend class nmc9306_device_config;
72
73    // construction/destruction
74    nmc9306_device(running_machine &_machine, const nmc9306_device_config &_config);
75
76public:
77    DECLARE_WRITE_LINE_MEMBER( cs_w );
78    DECLARE_WRITE_LINE_MEMBER( sk_w );
79    DECLARE_WRITE_LINE_MEMBER( di_w );
80    DECLARE_READ_LINE_MEMBER( do_r );
81
82protected:
83    // device-level overrides
84    virtual void device_start();
85
86   // device_nvram_interface overrides
87   virtual void nvram_default();
88   virtual void nvram_read(emu_file &file);
89   virtual void nvram_write(emu_file &file);
90
91private:
92   inline UINT16 read(offs_t offset);
93   inline void write(offs_t offset, UINT16 data);
94   inline void erase(offs_t offset);
95
96   UINT16 m_register[16];
97   
98   int m_bits;
99   int m_state;
100   UINT8 m_command;
101   UINT8 m_address;
102   UINT16 m_data;
103   bool m_ewen;
104   int m_cs;
105   int m_sk;
106   int m_do;
107   int m_di;
108
109   const nmc9306_device_config &m_config;
110};
111
112
113// device type definition
114extern const device_type NMC9306;
115
116
117
118#endif
src/emu/machine/e0516.h
r0r10969
1/**********************************************************************
2
3    E05-16 Real Time Clock emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                  Vdd1   1 |*    \_/     | 16  Vdd2
11                OSC IN   2 |             | 15  Clk
12               OSC OUT   3 |             | 14  XOUT
13                 _STOP   4 |   E05-16    | 13  DI/O
14                _RESET   5 |   E050-16   | 12  _SEC
15               _OUTSEL   6 |             | 11  _MIN
16                  _DAY   7 |             | 10  _HRS
17                   Vss   8 |_____________| 9   _CS
18
19**********************************************************************/
20
21#pragma once
22
23#ifndef __E0516__
24#define __E0516__
25
26#include "emu.h"
27
28
29
30//**************************************************************************
31//  MACROS / CONSTANTS
32//**************************************************************************
33
34
35
36
37//**************************************************************************
38//  INTERFACE CONFIGURATION MACROS
39//**************************************************************************
40
41#define MCFG_E0516_ADD(_tag, _clock) \
42   MCFG_DEVICE_ADD(_tag, E0516, _clock)
43
44
45
46//**************************************************************************
47//  TYPE DEFINITIONS
48//**************************************************************************
49
50
51// ======================> e0516_device_config
52
53class e0516_device_config :   public device_config
54{
55    friend class e0516_device;
56
57    // construction/destruction
58    e0516_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
59
60public:
61    // allocators
62    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
63    virtual device_t *alloc_device(running_machine &machine) const;
64
65protected:
66};
67
68
69// ======================> e0516_device
70
71class e0516_device :  public device_t
72{
73    friend class e0516_device_config;
74
75    // construction/destruction
76    e0516_device(running_machine &_machine, const e0516_device_config &_config);
77
78public:
79    DECLARE_WRITE_LINE_MEMBER( cs_w );
80    DECLARE_WRITE_LINE_MEMBER( clk_w );
81    DECLARE_WRITE_LINE_MEMBER( dio_w );
82    DECLARE_READ_LINE_MEMBER( dio_r );
83
84protected:
85    // device-level overrides
86    virtual void device_start();
87    virtual void device_reset();
88   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
89
90private:
91   int m_cs;                  // chip select
92   int m_clk;                  // clock
93   int m_data_latch;            // data latch
94   int m_reg_latch;            // register latch
95   int m_read_write;            // read/write data
96   int m_state;               // state
97   int m_bits;                  // number of bits transferred
98   int m_dio;                  // data pin
99
100   UINT8 m_register[8];         // registers
101
102   // timers
103   emu_timer *m_timer;
104
105   const e0516_device_config &m_config;
106};
107
108
109// device type definition
110extern const device_type E0516;
111
112
113
114#endif
src/emu/machine/i8155.c
r0r10969
1/**********************************************************************
2
3    Intel 8155 - 2048-Bit Static MOS RAM with I/O Ports and Timer emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10/*
11
12    TODO:
13
14    - strobed mode
15
16*/
17
18#include "emu.h"
19#include "i8155.h"
20
21
22
23//**************************************************************************
24//  MACROS / CONSTANTS
25//**************************************************************************
26
27#define LOG 1
28
29enum
30{
31   REGISTER_COMMAND = 0,
32   REGISTER_STATUS = 0,
33   REGISTER_PORT_A,
34   REGISTER_PORT_B,
35   REGISTER_PORT_C,
36   REGISTER_TIMER_LOW,
37   REGISTER_TIMER_HIGH
38};
39
40enum
41{
42   PORT_A = 0,
43   PORT_B,
44   PORT_C,
45   PORT_COUNT
46};
47
48enum
49{
50   PORT_MODE_INPUT = 0,
51   PORT_MODE_OUTPUT,
52   PORT_MODE_STROBED_PORT_A,   // not supported
53   PORT_MODE_STROBED         // not supported
54};
55
56enum
57{
58   MEMORY = 0,
59   IO
60};
61
62#define COMMAND_PA               0x01
63#define COMMAND_PB               0x02
64#define COMMAND_PC_MASK            0x0c
65#define COMMAND_PC_ALT_1         0x00
66#define COMMAND_PC_ALT_2         0x0c
67#define COMMAND_PC_ALT_3         0x04   // not supported
68#define COMMAND_PC_ALT_4         0x08   // not supported
69#define COMMAND_IEA               0x10   // not supported
70#define COMMAND_IEB               0x20   // not supported
71#define COMMAND_TM_MASK            0xc0
72#define COMMAND_TM_NOP            0x00
73#define COMMAND_TM_STOP            0x40
74#define COMMAND_TM_STOP_AFTER_TC   0x80
75#define COMMAND_TM_START         0xc0
76
77#define STATUS_INTR_A            0x01   // not supported
78#define STATUS_A_BF               0x02   // not supported
79#define STATUS_INTE_A            0x04   // not supported
80#define STATUS_INTR_B            0x08   // not supported
81#define STATUS_B_BF               0x10   // not supported
82#define STATUS_INTE_B            0x20   // not supported
83#define STATUS_TIMER            0x40
84
85#define TIMER_MODE_MASK            0xc0
86#define TIMER_MODE_LOW            0x00
87#define TIMER_MODE_SQUARE_WAVE      0x40
88#define TIMER_MODE_SINGLE_PULSE      0x80
89#define TIMER_MODE_AUTOMATIC_RELOAD   0xc0
90
91
92
93//**************************************************************************
94//  GLOBAL VARIABLES
95//**************************************************************************
96
97// devices
98const device_type I8155 = i8155_device_config::static_alloc_device_config;
99
100
101// default address map
102static ADDRESS_MAP_START( i8155, AS_0, 8 )
103   AM_RANGE(0x00, 0xff) AM_RAM
104ADDRESS_MAP_END
105
106
107
108//**************************************************************************
109//  DEVICE CONFIGURATION
110//**************************************************************************
111
112//-------------------------------------------------
113//  i8155_device_config - constructor
114//-------------------------------------------------
115
116i8155_device_config::i8155_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
117   : device_config(mconfig, static_alloc_device_config, "Intel 8155", tag, owner, clock),
118     device_config_memory_interface(mconfig, *this),
119     m_space_config("ram", ENDIANNESS_LITTLE, 8, 8, 0, NULL, *ADDRESS_MAP_NAME(i8155))
120{
121}
122
123
124//-------------------------------------------------
125//  static_alloc_device_config - allocate a new
126//  configuration object
127//-------------------------------------------------
128
129device_config *i8155_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
130{
131   return global_alloc(i8155_device_config(mconfig, tag, owner, clock));
132}
133
134
135//-------------------------------------------------
136//  alloc_device - allocate a new device object
137//-------------------------------------------------
138
139device_t *i8155_device_config::alloc_device(running_machine &machine) const
140{
141   return auto_alloc(&machine, i8155_device(machine, *this));
142}
143
144
145//-------------------------------------------------
146//  memory_space_config - return a description of
147//  any address spaces owned by this device
148//-------------------------------------------------
149
150const address_space_config *i8155_device_config::memory_space_config(address_spacenum spacenum) const
151{
152   return (spacenum == AS_0) ? &m_space_config : NULL;
153}
154
155
156//-------------------------------------------------
157//  device_config_complete - perform any
158//  operations now that the configuration is
159//  complete
160//-------------------------------------------------
161
162void i8155_device_config::device_config_complete()
163{
164   // inherit a copy of the static data
165   const i8155_interface *intf = reinterpret_cast<const i8155_interface *>(static_config());
166   if (intf != NULL)
167      *static_cast<i8155_interface *>(this) = *intf;
168
169   // or initialize to defaults if none provided
170   else
171   {
172      memset(&in_pa_func, 0, sizeof(in_pa_func));
173      memset(&out_pa_func, 0, sizeof(out_pa_func));
174      memset(&in_pb_func, 0, sizeof(in_pb_func));
175      memset(&out_pb_func, 0, sizeof(out_pb_func));
176      memset(&in_pc_func, 0, sizeof(in_pc_func));
177      memset(&out_pc_func, 0, sizeof(out_pc_func));
178      memset(&out_to_func, 0, sizeof(out_to_func));
179   }
180}
181
182
183
184//**************************************************************************
185//  INLINE HELPERS
186//**************************************************************************
187
188inline UINT8 i8155_device::get_timer_mode()
189{
190   return (m_count_length >> 8) & TIMER_MODE_MASK;
191}
192
193inline void i8155_device::timer_output()
194{
195   devcb_call_write_line(&m_out_to_func, m_to);
196
197   if (LOG) logerror("8155 '%s' Timer Output: %u\n", tag(), m_to);
198}
199
200inline void i8155_device::pulse_timer_output()
201{
202   m_to = 0; timer_output();
203   m_to = 1; timer_output();
204}
205
206inline int i8155_device::get_port_mode(int port)
207{
208   int mode = -1;
209
210   switch (port)
211   {
212   case PORT_A:
213      mode = (m_command & COMMAND_PA) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT;
214      break;
215
216   case PORT_B:
217      mode = (m_command & COMMAND_PB) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT;
218      break;
219
220   case PORT_C:
221      switch (m_command & COMMAND_PC_MASK)
222      {
223      case COMMAND_PC_ALT_1: mode = PORT_MODE_INPUT;         break;
224      case COMMAND_PC_ALT_2: mode = PORT_MODE_OUTPUT;         break;
225      case COMMAND_PC_ALT_3: mode = PORT_MODE_STROBED_PORT_A; break;
226      case COMMAND_PC_ALT_4: mode = PORT_MODE_STROBED;      break;
227      }
228      break;
229   }
230
231   return mode;
232}
233
234inline UINT8 i8155_device::read_port(int port)
235{
236   UINT8 data = 0;
237
238   switch (port)
239   {
240   case PORT_A:
241   case PORT_B:
242      switch (get_port_mode(port))
243      {
244      case PORT_MODE_INPUT:
245         data = devcb_call_read8(&m_in_port_func[port], 0);
246         break;
247
248      case PORT_MODE_OUTPUT:
249         data = m_output[port];
250         break;
251      }
252      break;
253
254   case PORT_C:
255      switch (get_port_mode(PORT_C))
256      {
257      case PORT_MODE_INPUT:
258         data = devcb_call_read8(&m_in_port_func[port], 0) & 0x3f;
259         break;
260
261      case PORT_MODE_OUTPUT:
262         data = m_output[port] & 0x3f;
263         break;
264
265      default:
266         logerror("8155 '%s' Unsupported Port C mode!\n", tag());
267      }
268      break;
269   }
270
271   return data;
272}
273
274inline void i8155_device::write_port(int port, UINT8 data)
275{
276   switch (get_port_mode(port))
277   {
278   case PORT_MODE_OUTPUT:
279      m_output[port] = data;
280      devcb_call_write8(&m_out_port_func[port], 0, m_output[port]);
281      break;
282   }
283}
284
285
286//**************************************************************************
287//  LIVE DEVICE
288//**************************************************************************
289
290//-------------------------------------------------
291//  i8155_device - constructor
292//-------------------------------------------------
293
294i8155_device::i8155_device(running_machine &_machine, const i8155_device_config &config)
295    : device_t(_machine, config),
296     device_memory_interface(_machine, config, *this),
297      m_config(config)
298{
299
300}
301
302
303//-------------------------------------------------
304//  device_start - device-specific startup
305//-------------------------------------------------
306
307void i8155_device::device_start()
308{
309   // resolve callbacks
310   devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this);
311   devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this);
312   devcb_resolve_read8(&m_in_port_func[2], &m_config.in_pc_func, this);
313   devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this);
314   devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this);
315   devcb_resolve_write8(&m_out_port_func[2], &m_config.out_pc_func, this);
316   devcb_resolve_write_line(&m_out_to_func, &m_config.out_to_func, this);
317
318   // allocate timers
319   m_timer = timer_alloc();
320
321   // register for state saving
322   save_item(NAME(m_io_m));
323   save_item(NAME(m_ad));
324   save_item(NAME(m_command));
325   save_item(NAME(m_status));
326   save_item(NAME(m_output));
327   save_item(NAME(m_count_length));
328   save_item(NAME(m_counter));
329   save_item(NAME(m_to));
330}
331
332
333//-------------------------------------------------
334//  device_reset - device-specific reset
335//-------------------------------------------------
336
337void i8155_device::device_reset()
338{
339   // clear output registers
340   m_output[PORT_A] = 0;
341   m_output[PORT_B] = 0;
342   m_output[PORT_C] = 0;
343
344   // set ports to input mode
345   register_w(REGISTER_COMMAND, m_command & ~(COMMAND_PA | COMMAND_PB | COMMAND_PC_MASK));
346
347   // clear timer flag
348   m_status &= ~STATUS_TIMER;
349
350   // stop counting
351   m_timer->enable(0);
352
353   // clear timer output
354   m_to = 1;
355   timer_output();
356}
357
358
359//-------------------------------------------------
360//  device_timer - handler timer events
361//-------------------------------------------------
362
363void i8155_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
364{
365   // count down
366   m_counter--;
367
368   if (get_timer_mode() == TIMER_MODE_LOW)
369   {
370      // pulse on every count
371      pulse_timer_output();
372   }
373
374   if (m_counter == 0)
375   {
376      if (LOG) logerror("8155 '%s' Timer Count Reached\n", tag());
377
378      switch (m_command & COMMAND_TM_MASK)
379      {
380      case COMMAND_TM_STOP_AFTER_TC:
381         // stop timer
382         m_timer->enable(0);
383
384         if (LOG) logerror("8155 '%s' Timer Stopped\n", tag());
385         break;
386      }
387
388      switch (get_timer_mode())
389      {
390      case TIMER_MODE_SQUARE_WAVE:
391         // toggle timer output
392         m_to = !m_to;
393         timer_output();
394         break;
395
396      case TIMER_MODE_SINGLE_PULSE:
397         // single pulse upon TC being reached
398         pulse_timer_output();
399
400         // clear timer mode setting
401         m_command &= ~COMMAND_TM_MASK;
402         break;
403
404      case TIMER_MODE_AUTOMATIC_RELOAD:
405         // automatic reload, i.e. single pulse every time TC is reached
406         pulse_timer_output();
407         break;
408      }
409
410      // set timer flag
411      m_status |= STATUS_TIMER;
412
413      // reload timer counter
414      m_counter = m_count_length & 0x3fff;
415   }
416}
417
418
419//-------------------------------------------------
420//  io_r - register read
421//-------------------------------------------------
422
423READ8_MEMBER( i8155_device::io_r )
424{
425   UINT8 data = 0;
426
427   switch (offset & 0x03)
428   {
429   case REGISTER_STATUS:
430      data = m_status;
431
432      // clear timer flag
433      m_status &= ~STATUS_TIMER;
434      break;
435
436   case REGISTER_PORT_A:
437      data = read_port(PORT_A);
438      break;
439
440   case REGISTER_PORT_B:
441      data = read_port(PORT_B);
442      break;
443
444   case REGISTER_PORT_C:
445      data = read_port(PORT_C);
446      break;
447   }
448
449   return data;
450}
451
452
453//-------------------------------------------------
454//  register_w - register write
455//-------------------------------------------------
456
457void i8155_device::register_w(int offset, UINT8 data)
458{
459   switch (offset & 0x07)
460   {
461   case REGISTER_COMMAND:
462      m_command = data;
463
464      if (LOG) logerror("8155 '%s' Port A Mode: %s\n", tag(), (data & COMMAND_PA) ? "output" : "input");
465      if (LOG) logerror("8155 '%s' Port B Mode: %s\n", tag(), (data & COMMAND_PB) ? "output" : "input");
466
467      if (LOG) logerror("8155 '%s' Port A Interrupt: %s\n", tag(), (data & COMMAND_IEA) ? "enabled" : "disabled");
468      if (LOG) logerror("8155 '%s' Port B Interrupt: %s\n", tag(), (data & COMMAND_IEB) ? "enabled" : "disabled");
469
470      switch (data & COMMAND_PC_MASK)
471      {
472      case COMMAND_PC_ALT_1:
473         if (LOG) logerror("8155 '%s' Port C Mode: Alt 1\n", tag());
474         break;
475
476      case COMMAND_PC_ALT_2:
477         if (LOG) logerror("8155 '%s' Port C Mode: Alt 2\n", tag());
478         break;
479
480      case COMMAND_PC_ALT_3:
481         if (LOG) logerror("8155 '%s' Port C Mode: Alt 3\n", tag());
482         break;
483
484      case COMMAND_PC_ALT_4:
485         if (LOG) logerror("8155 '%s' Port C Mode: Alt 4\n", tag());
486         break;
487      }
488
489      switch (data & COMMAND_TM_MASK)
490      {
491      case COMMAND_TM_NOP:
492         // do not affect counter operation
493         break;
494
495      case COMMAND_TM_STOP:
496         // NOP if timer has not started, stop counting if the timer is running
497         if (LOG) logerror("8155 '%s' Timer Command: Stop\n", tag());
498         m_timer->enable(0);
499         break;
500
501      case COMMAND_TM_STOP_AFTER_TC:
502         // stop immediately after present TC is reached (NOP if timer has not started)
503         if (LOG) logerror("8155 '%s' Timer Command: Stop after TC\n", tag());
504         break;
505
506      case COMMAND_TM_START:
507         if (LOG) logerror("8155 '%s' Timer Command: Start\n", tag());
508
509         if (m_timer->enabled())
510         {
511            // if timer is running, start the new mode and CNT length immediately after present TC is reached
512         }
513         else
514         {
515            // load mode and CNT length and start immediately after loading (if timer is not running)
516            m_counter = m_count_length;
517            m_timer->adjust(attotime::zero, 0, attotime::from_hz(clock()));
518         }
519         break;
520      }
521      break;
522
523   case REGISTER_PORT_A:
524      write_port(PORT_A, data);
525      break;
526
527   case REGISTER_PORT_B:
528      write_port(PORT_B, data);
529      break;
530
531   case REGISTER_PORT_C:
532      write_port(PORT_C, data);
533      break;
534
535   case REGISTER_TIMER_LOW:
536      m_count_length = (m_count_length & 0xff00) | data;
537      if (LOG) logerror("8155 '%s' Count Length Low: %04x\n", tag(), m_count_length);
538      break;
539
540   case REGISTER_TIMER_HIGH:
541      m_count_length = (data << 8) | (m_count_length & 0xff);
542      if (LOG) logerror("8155 '%s' Count Length High: %04x\n", tag(), m_count_length);
543
544      switch (data & TIMER_MODE_MASK)
545      {
546      case TIMER_MODE_LOW:
547         // puts out LOW during second half of count
548         if (LOG) logerror("8155 '%s' Timer Mode: LOW\n", tag());
549         break;
550
551      case TIMER_MODE_SQUARE_WAVE:
552         // square wave, i.e. the period of the square wave equals the count length programmed with automatic reload at terminal count
553         if (LOG) logerror("8155 '%s' Timer Mode: Square wave\n", tag());
554         break;
555
556      case TIMER_MODE_SINGLE_PULSE:
557         // single pulse upon TC being reached
558         if (LOG) logerror("8155 '%s' Timer Mode: Single pulse\n", tag());
559         break;
560
561      case TIMER_MODE_AUTOMATIC_RELOAD:
562         // automatic reload, i.e. single pulse every time TC is reached
563         if (LOG) logerror("8155 '%s' Timer Mode: Automatic reload\n", tag());
564         break;
565      }
566      break;
567   }
568}
569
570//-------------------------------------------------
571//  io_w - register write
572//-------------------------------------------------
573
574WRITE8_MEMBER( i8155_device::io_w )
575{
576   register_w(offset, data);
577}
578
579
580//-------------------------------------------------
581//  memory_r - internal RAM read
582//-------------------------------------------------
583
584READ8_MEMBER( i8155_device::memory_r )
585{
586   return this->space()->read_byte(offset);
587}
588
589
590//-------------------------------------------------
591//  memory_w - internal RAM write
592//-------------------------------------------------
593
594WRITE8_MEMBER( i8155_device::memory_w )
595{
596   this->space()->write_byte(offset, data);
597}
598
599
600//-------------------------------------------------
601//  ale_w - address latch write
602//-------------------------------------------------
603
604WRITE8_MEMBER( i8155_device::ale_w )
605{
606   // I/O / memory select
607   m_io_m = BIT(offset, 0);
608
609   // address
610   m_ad = data;
611}
612
613
614//-------------------------------------------------
615//  read - memory or I/O read
616//-------------------------------------------------
617
618READ8_MEMBER( i8155_device::read )
619{
620   UINT8 data = 0;
621
622   switch (m_io_m)
623   {
624   case MEMORY:
625      data = memory_r(space, m_ad);
626      break;
627
628   case IO:
629      data = io_r(space, m_ad);
630      break;
631   }
632
633   return data;
634}
635
636
637//-------------------------------------------------
638//  write - memory or I/O write
639//-------------------------------------------------
640
641WRITE8_MEMBER( i8155_device::write )
642{
643   switch (m_io_m)
644   {
645   case MEMORY:
646      memory_w(space, m_ad, data);
647      break;
648
649   case IO:
650      io_w(space, m_ad, data);
651      break;
652   }
653}
src/emu/machine/i8355.c
r0r10969
1/**********************************************************************
2
3    Intel 8355 - 16,384-Bit ROM with I/O emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "i8355.h"
12
13
14
15//**************************************************************************
16//  MACROS / CONSTANTS
17//**************************************************************************
18
19#define LOG 0
20
21enum
22{
23   REGISTER_PORT_A = 0,
24   REGISTER_PORT_B,
25   REGISTER_PORT_A_DDR,
26   REGISTER_PORT_B_DDR
27};
28
29enum
30{
31   PORT_A = 0,
32   PORT_B,
33   PORT_COUNT
34};
35
36
37
38//**************************************************************************
39//  GLOBAL VARIABLES
40//**************************************************************************
41
42// devices
43const device_type I8355 = i8355_device_config::static_alloc_device_config;
44
45
46// default address map
47static ADDRESS_MAP_START( i8355, AS_0, 8 )
48   AM_RANGE(0x000, 0x7ff) AM_ROM
49ADDRESS_MAP_END
50
51
52
53//**************************************************************************
54//  DEVICE CONFIGURATION
55//**************************************************************************
56
57//-------------------------------------------------
58//  i8355_device_config - constructor
59//-------------------------------------------------
60
61i8355_device_config::i8355_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
62   : device_config(mconfig, static_alloc_device_config, "Intel 8355", tag, owner, clock),
63     device_config_memory_interface(mconfig, *this),
64     m_space_config("ram", ENDIANNESS_LITTLE, 8, 11, 0, NULL, *ADDRESS_MAP_NAME(i8355))
65{
66}
67
68
69//-------------------------------------------------
70//  static_alloc_device_config - allocate a new
71//  configuration object
72//-------------------------------------------------
73
74device_config *i8355_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
75{
76   return global_alloc(i8355_device_config(mconfig, tag, owner, clock));
77}
78
79
80//-------------------------------------------------
81//  alloc_device - allocate a new device object
82//-------------------------------------------------
83
84device_t *i8355_device_config::alloc_device(running_machine &machine) const
85{
86   return auto_alloc(&machine, i8355_device(machine, *this));
87}
88
89
90//-------------------------------------------------
91//  memory_space_config - return a description of
92//  any address spaces owned by this device
93//-------------------------------------------------
94
95const address_space_config *i8355_device_config::memory_space_config(address_spacenum spacenum) const
96{
97   return (spacenum == AS_0) ? &m_space_config : NULL;
98}
99
100
101//-------------------------------------------------
102//  device_config_complete - perform any
103//  operations now that the configuration is
104//  complete
105//-------------------------------------------------
106
107void i8355_device_config::device_config_complete()
108{
109   // inherit a copy of the static data
110   const i8355_interface *intf = reinterpret_cast<const i8355_interface *>(static_config());
111   if (intf != NULL)
112      *static_cast<i8355_interface *>(this) = *intf;
113
114   // or initialize to defaults if none provided
115   else
116   {
117      memset(&in_pa_func, 0, sizeof(in_pa_func));
118      memset(&out_pa_func, 0, sizeof(out_pa_func));
119      memset(&in_pb_func, 0, sizeof(in_pb_func));
120      memset(&out_pb_func, 0, sizeof(out_pb_func));
121   }
122}
123
124
125
126//**************************************************************************
127//  INLINE HELPERS
128//**************************************************************************
129
130//-------------------------------------------------
131//  read_port - read from input port
132//-------------------------------------------------
133
134inline UINT8 i8355_device::read_port(int port)
135{
136   UINT8 data = m_output[port] & m_ddr[port];
137
138   if (m_ddr[port] != 0xff)
139   {
140      data |= devcb_call_read8(&m_in_port_func[port], 0) & ~m_ddr[port];
141   }
142
143   return data;
144}
145
146
147//-------------------------------------------------
148//  write_port - write to output port
149//-------------------------------------------------
150
151inline void i8355_device::write_port(int port, UINT8 data)
152{
153   m_output[port] = data;
154
155   devcb_call_write8(&m_out_port_func[port], 0, m_output[port] & m_ddr[port]);
156}
157
158
159
160//**************************************************************************
161//  LIVE DEVICE
162//**************************************************************************
163
164//-------------------------------------------------
165//  i8355_device - constructor
166//-------------------------------------------------
167
168i8355_device::i8355_device(running_machine &_machine, const i8355_device_config &config)
169    : device_t(_machine, config),
170     device_memory_interface(_machine, config, *this),
171      m_config(config)
172{
173
174}
175
176
177//-------------------------------------------------
178//  device_start - device-specific startup
179//-------------------------------------------------
180
181void i8355_device::device_start()
182{
183   // resolve callbacks
184   devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this);
185   devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this);
186   devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this);
187   devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this);
188
189   // register for state saving
190   save_item(NAME(m_output));
191   save_item(NAME(m_ddr));
192}
193
194
195//-------------------------------------------------
196//  device_reset - device-specific reset
197//-------------------------------------------------
198
199void i8355_device::device_reset()
200{
201   // set ports to input mode
202   m_ddr[PORT_A] = 0;
203   m_ddr[PORT_B] = 0;
204}
205
206
207//-------------------------------------------------
208//  io_r - register read
209//-------------------------------------------------
210
211READ8_MEMBER( i8355_device::io_r )
212{
213   int port = offset & 0x01;
214
215   UINT8 data = 0;
216
217   switch (offset & 0x03)
218   {
219   case REGISTER_PORT_A:
220   case REGISTER_PORT_B:
221      data = read_port(port);
222      break;
223
224   case REGISTER_PORT_A_DDR:
225   case REGISTER_PORT_B_DDR:
226      // write only
227      break;
228   }
229
230   return data;
231}
232
233
234//-------------------------------------------------
235//  io_w - register write
236//-------------------------------------------------
237
238WRITE8_MEMBER( i8355_device::io_w )
239{
240   int port = offset & 0x01;
241
242   switch (offset & 0x03)
243   {
244   case REGISTER_PORT_A:
245   case REGISTER_PORT_B:
246      if (LOG) logerror("I8355 '%s' Port %c Write %02x\n", tag(), 'A' + port, data);
247
248      write_port(port, data);
249      break;
250
251   case REGISTER_PORT_A_DDR:
252   case REGISTER_PORT_B_DDR:
253      if (LOG) logerror("I8355 '%s' Port %c DDR: %02x\n", tag(), 'A' + port, data);
254
255      m_ddr[port] = data;
256      write_port(port, data);
257      break;
258   }
259}
260
261
262//-------------------------------------------------
263//  memory_r - internal ROM read
264//-------------------------------------------------
265
266READ8_MEMBER( i8355_device::memory_r )
267{
268   return this->space()->read_byte(offset);
269}
src/emu/machine/i8155.h
r0r10969
1/**********************************************************************
2
3    Intel 8155 - 2048-Bit Static MOS RAM with I/O Ports and Timer emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                   PC3   1 |*    \_/     | 40  Vcc
11                   PC4   2 |             | 39  PC2
12              TIMER IN   3 |             | 38  PC1
13                 RESET   4 |             | 37  PC0
14                   PC5   5 |             | 36  PB7
15            _TIMER OUT   6 |             | 35  PB6
16                 IO/_M   7 |             | 34  PB5
17             CE or _CE   8 |             | 33  PB4
18                   _RD   9 |             | 32  PB3
19                   _WR  10 |    8155     | 31  PB2
20                   ALE  11 |    8156     | 30  PB1
21                   AD0  12 |             | 29  PB0
22                   AD1  13 |             | 28  PA7
23                   AD2  14 |             | 27  PA6
24                   AD3  15 |             | 26  PA5
25                   AD4  16 |             | 25  PA4
26                   AD5  17 |             | 24  PA3
27                   AD6  18 |             | 23  PA2
28                   AD7  19 |             | 22  PA1
29                   Vss  20 |_____________| 21  PA0
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __I8155__
36#define __I8155__
37
38#include "emu.h"
39
40
41
42//**************************************************************************
43//  MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
53#define MCFG_I8155_ADD(_tag, _clock, _config) \
54   MCFG_DEVICE_ADD((_tag), I8155, _clock)   \
55   MCFG_DEVICE_CONFIG(_config)
56
57#define I8155_INTERFACE(name) \
58   const i8155_interface (name) =
59
60
61
62//**************************************************************************
63//  TYPE DEFINITIONS
64//**************************************************************************
65
66// ======================> i8155_interface
67
68struct i8155_interface
69{
70   devcb_read8            in_pa_func;
71   devcb_write8         out_pa_func;
72
73   devcb_read8            in_pb_func;
74   devcb_write8         out_pb_func;
75
76   devcb_read8            in_pc_func;
77   devcb_write8         out_pc_func;
78
79   // this gets called for each change of the TIMER OUT pin (pin 6)
80   devcb_write_line      out_to_func;
81};
82
83
84
85// ======================> i8155_device_config
86
87class i8155_device_config :   public device_config,
88                        public device_config_memory_interface,
89                                public i8155_interface
90{
91    friend class i8155_device;
92
93    // construction/destruction
94    i8155_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
95
96public:
97    // allocators
98    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
99    virtual device_t *alloc_device(running_machine &machine) const;
100
101protected:
102   // device_config overrides
103   virtual void device_config_complete();
104
105   // device_config_memory_interface overrides
106   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
107
108    // address space configurations
109   const address_space_config      m_space_config;
110};
111
112
113
114// ======================> i8155_device
115
116class i8155_device :   public device_t,
117                  public device_memory_interface
118{
119    friend class i8155_device_config;
120
121    // construction/destruction
122    i8155_device(running_machine &_machine, const i8155_device_config &_config);
123
124public:
125    DECLARE_READ8_MEMBER( io_r );
126    DECLARE_WRITE8_MEMBER( io_w );
127
128    DECLARE_READ8_MEMBER( memory_r );
129    DECLARE_WRITE8_MEMBER( memory_w );
130
131    DECLARE_WRITE8_MEMBER( ale_w );
132    DECLARE_READ8_MEMBER( read );
133    DECLARE_WRITE8_MEMBER( write );
134
135protected:
136    // device-level overrides
137    virtual void device_start();
138    virtual void device_reset();
139   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
140
141   inline UINT8 get_timer_mode();
142   inline void timer_output();
143   inline void pulse_timer_output();
144   inline int get_port_mode(int port);
145   inline UINT8 read_port(int port);
146   inline void write_port(int port, UINT8 data);
147
148   void register_w(int offset, UINT8 data);
149
150private:
151   devcb_resolved_read8      m_in_port_func[3];
152   devcb_resolved_write8      m_out_port_func[3];
153   devcb_resolved_write_line   m_out_to_func;
154
155   // CPU interface
156   int m_io_m;               // I/O or memory select
157   UINT8 m_ad;               // address
158
159   // registers
160   UINT8 m_command;         // command register
161   UINT8 m_status;            // status register
162   UINT8 m_output[3];         // output latches
163
164   // counter
165   UINT16 m_count_length;      // count length register
166   UINT16 m_counter;         // counter register
167   int m_to;               // timer output
168
169   // timers
170   emu_timer *m_timer;         // counter timer
171
172   const i8155_device_config &m_config;
173};
174
175
176// device type definition
177extern const device_type I8155;
178
179
180
181#endif
src/emu/machine/i8355.h
r0r10969
1/**********************************************************************
2
3    Intel 8355 - 16,384-Bit ROM with I/O emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                  _CE1   1 |*    \_/     | 40  Vcc
11                   CE2   2 |             | 39  PB7
12                   CLK   3 |             | 38  PB6
13                 RESET   4 |             | 37  PB5
14                  N.C.   5 |             | 36  PB4
15                 READY   6 |             | 35  PB3
16                 IO/_M   7 |             | 34  PB2
17                  _IOR   8 |             | 33  PB1
18                   _RD   9 |             | 32  PB0
19                  _IOW  10 |    8355     | 31  PA7
20                   ALE  11 |    8355-2   | 30  PA6
21                   AD0  12 |             | 29  PA5
22                   AD1  13 |             | 28  PA4
23                   AD2  14 |             | 27  PA3
24                   AD3  15 |             | 26  PA2
25                   AD4  16 |             | 25  PA1
26                   AD5  17 |             | 24  PA0
27                   AD6  18 |             | 23  A10
28                   AD7  19 |             | 22  A9
29                   Vss  20 |_____________| 21  A8
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __I8355__
36#define __I8355__
37
38#include "emu.h"
39
40
41
42///*************************************************************************
43//  MACROS / CONSTANTS
44///*************************************************************************
45
46
47
48
49///*************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51///*************************************************************************
52
53#define MCFG_I8355_ADD(_tag, _clock, _config) \
54   MCFG_DEVICE_ADD((_tag), I8355, _clock)   \
55   MCFG_DEVICE_CONFIG(_config)
56
57#define I8355_INTERFACE(name) \
58   const i8355_interface (name) =
59
60
61
62///*************************************************************************
63//  TYPE DEFINITIONS
64///*************************************************************************
65
66// ======================> i8355_interface
67
68struct i8355_interface
69{
70   devcb_read8            in_pa_func;
71   devcb_write8         out_pa_func;
72
73   devcb_read8            in_pb_func;
74   devcb_write8         out_pb_func;
75};
76
77
78
79// ======================> i8355_device_config
80
81class i8355_device_config :   public device_config,
82                        public device_config_memory_interface,
83                                public i8355_interface
84{
85    friend class i8355_device;
86
87    // construction/destruction
88    i8355_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
89
90public:
91    // allocators
92    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
93    virtual device_t *alloc_device(running_machine &machine) const;
94
95protected:
96   // device_config overrides
97   virtual void device_config_complete();
98
99   // device_config_memory_interface overrides
100   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
101
102    // address space configurations
103   const address_space_config      m_space_config;
104};
105
106
107
108// ======================> i8355_device
109
110class i8355_device :   public device_t,
111                  public device_memory_interface
112{
113    friend class i8355_device_config;
114
115    // construction/destruction
116    i8355_device(running_machine &_machine, const i8355_device_config &_config);
117
118public:
119    DECLARE_READ8_MEMBER( io_r );
120    DECLARE_WRITE8_MEMBER( io_w );
121
122    DECLARE_READ8_MEMBER( memory_r );
123    DECLARE_WRITE8_MEMBER( memory_w );
124
125protected:
126    // device-level overrides
127    virtual void device_start();
128    virtual void device_reset();
129
130   inline UINT8 read_port(int port);
131   inline void write_port(int port, UINT8 data);
132
133private:
134   devcb_resolved_read8      m_in_port_func[2];
135   devcb_resolved_write8      m_out_port_func[2];
136
137   // registers
138   UINT8 m_output[2];         // output latches
139   UINT8 m_ddr[2];            // DDR latches
140
141   const i8355_device_config &m_config;
142};
143
144
145// device type definition
146extern const device_type I8355;
147
148
149
150#endif
src/mess/machine/cdp1871.c
r10968r10969
1/**********************************************************************
2
3    RCA CDP1871 Keyboard Encoder emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "cdp1871.h"
12#include "cpu/mcs48/mcs48.h"
13#include "machine/devhelpr.h"
14
15
16
17//**************************************************************************
18//  MACROS / CONSTANTS
19//**************************************************************************
20
21static const UINT8 CDP1871_KEY_CODES[4][11][8] =
22{
23   // normal
24   {
25      { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 },
26      { 0x38, 0x39, 0x3a, 0x3b, 0x2c, 0x2d, 0x2e, 0x2f },
27      { 0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67 },
28      { 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f },
29      { 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77 },
30      { 0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f },
31      { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f },
32      { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 },
33      { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f },
34      { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 },
35      { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }
36   },
37
38   // alpha
39   {
40      { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37 },
41      { 0x38, 0x39, 0x3a, 0x3b, 0x2c, 0x2d, 0x2e, 0x2f },
42      { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 },
43      { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f },
44      { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 },
45      { 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f },
46      { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f },
47      { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 },
48      { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f },
49      { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 },
50      { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }
51   },
52
53   // shift
54   {
55      { 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 },
56      { 0x28, 0x29, 0x2a, 0x2b, 0x3c, 0x3d, 0x3e, 0x3f },
57      { 0x60, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47 },
58      { 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f },
59      { 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 },
60      { 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f },
61      { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f },
62      { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 },
63      { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f },
64      { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 },
65      { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }
66   },
67
68   // control
69   {
70      { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
71      { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
72      { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
73      { 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
74      { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 },
75      { 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
76      { 0x20, 0xff, 0x0a, 0x1b, 0xff, 0x0d, 0xff, 0x7f },
77      { 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87 },
78      { 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f },
79      { 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97 },
80      { 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f }
81   }
82};
83
84
85
86//**************************************************************************
87//  DEVICE DEFINITIONS
88//**************************************************************************
89
90const device_type CDP1871 = cdp1871_device_config::static_alloc_device_config;
91
92
93
94//**************************************************************************
95//  DEVICE CONFIGURATION
96//**************************************************************************
97
98GENERIC_DEVICE_CONFIG_SETUP(cdp1871, "RCA CDP1871")
99
100
101//-------------------------------------------------
102//  device_config_complete - perform any
103//  operations now that the configuration is
104//  complete
105//-------------------------------------------------
106
107void cdp1871_device_config::device_config_complete()
108{
109   // inherit a copy of the static data
110   const cdp1871_interface *intf = reinterpret_cast<const cdp1871_interface *>(static_config());
111   if (intf != NULL)
112      *static_cast<cdp1871_interface *>(this) = *intf;
113
114   // or initialize to defaults if none provided
115   else
116   {
117      memset(&out_da_func, 0, sizeof(out_da_func));
118      memset(&out_rpt_func, 0, sizeof(out_rpt_func));
119      // m_in_d_func[]
120      memset(&in_shift_func, 0, sizeof(in_shift_func));
121      memset(&in_control_func, 0, sizeof(in_control_func));
122      memset(&in_alpha_func, 0, sizeof(in_alpha_func));
123   }
124}
125
126
127
128//**************************************************************************
129//  LIVE DEVICE
130//**************************************************************************
131
132//-------------------------------------------------
133//  cdp1871_device - constructor
134//-------------------------------------------------
135
136cdp1871_device::cdp1871_device(running_machine &_machine, const cdp1871_device_config &config)
137    : device_t(_machine, config),
138     m_inhibit(false),
139     m_sense(0),
140     m_drive(0),
141     m_next_da(CLEAR_LINE),
142     m_next_rpt(CLEAR_LINE),
143      m_config(config)
144{
145
146}
147
148
149//-------------------------------------------------
150//  device_start - device-specific startup
151//-------------------------------------------------
152
153void cdp1871_device::device_start()
154{
155   // resolve callbacks
156   devcb_resolve_write_line(&m_out_da_func, &m_config.out_da_func, this);
157   devcb_resolve_write_line(&m_out_rpt_func, &m_config.out_rpt_func, this);
158   devcb_resolve_read8(&m_in_d_func[0], &m_config.in_d1_func, this);
159   devcb_resolve_read8(&m_in_d_func[1], &m_config.in_d2_func, this);
160   devcb_resolve_read8(&m_in_d_func[2], &m_config.in_d3_func, this);
161   devcb_resolve_read8(&m_in_d_func[3], &m_config.in_d4_func, this);
162   devcb_resolve_read8(&m_in_d_func[4], &m_config.in_d5_func, this);
163   devcb_resolve_read8(&m_in_d_func[5], &m_config.in_d6_func, this);
164   devcb_resolve_read8(&m_in_d_func[6], &m_config.in_d7_func, this);
165   devcb_resolve_read8(&m_in_d_func[7], &m_config.in_d8_func, this);
166   devcb_resolve_read8(&m_in_d_func[8], &m_config.in_d9_func, this);
167   devcb_resolve_read8(&m_in_d_func[9], &m_config.in_d10_func, this);
168   devcb_resolve_read8(&m_in_d_func[10], &m_config.in_d11_func, this);
169   devcb_resolve_read_line(&m_in_shift_func, &m_config.in_shift_func, this);
170   devcb_resolve_read_line(&m_in_control_func, &m_config.in_control_func, this);
171   devcb_resolve_read_line(&m_in_alpha_func, &m_config.in_alpha_func, this);
172
173   // set initial values
174   change_output_lines();
175
176   // allocate timers
177   m_scan_timer = timer_alloc();
178   m_scan_timer->adjust(attotime::zero, 0, attotime::from_hz(clock()));
179
180   // register for state saving
181   save_item(NAME(m_inhibit));
182   save_item(NAME(m_sense));
183   save_item(NAME(m_drive));
184   save_item(NAME(m_shift));
185   save_item(NAME(m_control));
186   save_item(NAME(m_da));
187   save_item(NAME(m_next_da));
188   save_item(NAME(m_rpt));
189   save_item(NAME(m_next_rpt));
190}
191
192
193//-------------------------------------------------
194//  device_timer - handler timer events
195//-------------------------------------------------
196
197void cdp1871_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
198{
199   change_output_lines();
200   clock_scan_counters();
201   detect_keypress();
202}
203
204
205//-------------------------------------------------
206//  change_output_lines - change output lines
207//-------------------------------------------------
208
209void cdp1871_device::change_output_lines()
210{
211   if (m_next_da != m_da)
212   {
213      m_da = m_next_da;
214
215      devcb_call_write_line(&m_out_da_func, m_da);
216   }
217
218   if (m_next_rpt != m_rpt)
219   {
220      m_rpt = m_next_rpt;
221
222      devcb_call_write_line(&m_out_rpt_func, m_rpt);
223   }
224}
225
226
227//-------------------------------------------------
228//  clock_scan_counters - clock the keyboard
229//  scan counters
230//-------------------------------------------------
231
232void cdp1871_device::clock_scan_counters()
233{
234   if (!m_inhibit)
235   {
236      m_sense++;
237
238      if (m_sense == 8)
239      {
240         m_sense = 0;
241         m_drive++;
242
243         if (m_drive == 11)
244         {
245            m_drive = 0;
246         }
247      }
248   }
249}
250
251
252//-------------------------------------------------
253//  detect_keypress - detect key press
254//-------------------------------------------------
255
256void cdp1871_device::detect_keypress()
257{
258   UINT8 data = 0;
259
260   data = devcb_call_read8(&m_in_d_func[m_drive], 0);
261
262   if (data == (1 << m_sense))
263   {
264      if (!m_inhibit)
265      {
266         m_shift = devcb_call_read_line(&m_in_shift_func);
267         m_control = devcb_call_read_line(&m_in_control_func);
268         m_inhibit = true;
269         m_next_da = ASSERT_LINE;
270      }
271      else
272      {
273         m_next_rpt = ASSERT_LINE;
274      }
275   }
276   else
277   {
278      m_inhibit = false;
279      m_next_rpt = CLEAR_LINE;
280   }
281}
282
283
284//-------------------------------------------------
285//  data_r - keyboard data read
286//-------------------------------------------------
287
288READ8_MEMBER( cdp1871_device::data_r )
289{
290   int table = 0;
291   int alpha = devcb_call_read_line(&m_in_alpha_func);
292
293   if (m_control) table = 3; else if (m_shift) table = 2; else if (alpha) table = 1;
294
295   // reset DA on next TPB
296   m_next_da = CLEAR_LINE;
297
298   return CDP1871_KEY_CODES[table][m_drive][m_sense];
299}
300
301
302//-------------------------------------------------
303//  da_r - data available
304//-------------------------------------------------
305
306READ_LINE_MEMBER( cdp1871_device::da_r )
307{
308   return m_da;
309}
310
311
312//-------------------------------------------------
313//  rpt_r - keyboard repeat
314//-------------------------------------------------
315
316READ_LINE_MEMBER( cdp1871_device::rpt_r )
317{
318   return m_rpt;
319}
src/mess/machine/cdp1871.h
r10968r10969
1/**********************************************************************
2
3    RCA CDP1871 Keyboard Encoder emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                    D1   1 |*    \_/     | 40  Vdd
11                    D2   2 |             | 39  SHIFT
12                    D3   3 |             | 38  CONTROL
13                    D4   4 |             | 37  ALPHA
14                    D5   5 |             | 36  DEBOUNCE
15                    D6   6 |             | 35  _RTP
16                    D7   7 |             | 34  TPB
17                    D8   8 |             | 33  _DA
18                    D9   9 |             | 32  BUS 7
19                   D10  10 |   CDP1871   | 31  BUS 6
20                   D11  11 |             | 30  BUS 5
21                    S1  12 |             | 29  BUS 4
22                    S2  13 |             | 28  BUS 3
23                    S3  14 |             | 27  BUS 2
24                    S4  15 |             | 26  BUS 1
25                    S5  16 |             | 25  BUS 0
26                    S6  17 |             | 24  CS4
27                    S7  18 |             | 23  CS3
28                    S8  19 |             | 22  CS2
29                   Vss  20 |_____________| 21  _CS1
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __CDP1871__
36#define __CDP1871__
37
38#include "emu.h"
39
40
41
42//**************************************************************************
43//  MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
53#define MCFG_CDP1871_ADD(_tag, _intrf, _clock) \
54   MCFG_DEVICE_ADD(_tag, CDP1871, _clock) \
55   MCFG_DEVICE_CONFIG(_intrf)
56
57#define CDP1871_INTERFACE(name) \
58   const cdp1871_interface (name)=
59
60
61
62//**************************************************************************
63//  TYPE DEFINITIONS
64//**************************************************************************
65
66// ======================> cdp1871_interface
67
68struct cdp1871_interface
69{
70   devcb_read8         in_d1_func;
71   devcb_read8         in_d2_func;
72   devcb_read8         in_d3_func;
73   devcb_read8         in_d4_func;
74   devcb_read8         in_d5_func;
75   devcb_read8         in_d6_func;
76   devcb_read8         in_d7_func;
77   devcb_read8         in_d8_func;
78   devcb_read8         in_d9_func;
79   devcb_read8         in_d10_func;
80   devcb_read8         in_d11_func;
81
82   devcb_read_line      in_shift_func;
83   devcb_read_line      in_control_func;
84   devcb_read_line      in_alpha_func;
85
86   // this gets called for every change of the DA pin (pin 33)
87   devcb_write_line   out_da_func;
88
89   // this gets called for every change of the RPT pin (pin 35)
90   devcb_write_line   out_rpt_func;
91};
92
93
94// ======================> cdp1871_device_config
95
96class cdp1871_device_config :   public device_config,
97                                public cdp1871_interface
98{
99    friend class cdp1871_device;
100
101    // construction/destruction
102    cdp1871_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
103
104public:
105    // allocators
106    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
107    virtual device_t *alloc_device(running_machine &machine) const;
108
109protected:
110    // device_config overrides
111    virtual void device_config_complete();
112};
113
114
115// ======================> cdp1871_device
116
117class cdp1871_device :  public device_t
118{
119    friend class cdp1871_device_config;
120
121    // construction/destruction
122    cdp1871_device(running_machine &_machine, const cdp1871_device_config &_config);
123
124public:
125    DECLARE_READ8_MEMBER( data_r );
126
127   DECLARE_READ_LINE_MEMBER( da_r );
128   DECLARE_READ_LINE_MEMBER( rpt_r );
129
130protected:
131    // device-level overrides
132    virtual void device_start();
133   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
134
135   void change_output_lines();
136   void clock_scan_counters();
137   void detect_keypress();
138
139private:
140   devcb_resolved_write_line      m_out_da_func;
141   devcb_resolved_write_line      m_out_rpt_func;
142   devcb_resolved_read8         m_in_d_func[11];
143   devcb_resolved_read_line      m_in_shift_func;
144   devcb_resolved_read_line      m_in_control_func;
145   devcb_resolved_read_line      m_in_alpha_func;
146
147   bool m_inhibit;               // scan counter clock inhibit
148   int m_sense;               // sense input scan counter
149   int m_drive;               // modifier inputs
150
151   int m_shift;               // latched shift modifier
152   int m_control;               // latched control modifier
153
154   int m_da;                  // data available flag
155   int m_next_da;               // next value of data available flag
156   int m_rpt;                  // repeat flag
157   int m_next_rpt;               // next value of repeat flag
158
159   // timers
160   emu_timer *m_scan_timer;      // keyboard scan timer
161
162   const cdp1871_device_config &m_config;
163};
164
165
166// device type definition
167extern const device_type CDP1871;
168
169
170
171#endif
src/mess/machine/nmc9306.c
r10968r10969
1/**********************************************************************
2
3    National Semiconductor NMC9306 256-Bit Serial EEPROM emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "nmc9306.h"
12#include "machine/devhelpr.h"
13
14
15
16//**************************************************************************
17//  MACROS / CONSTANTS
18//**************************************************************************
19
20#define LOG 1
21
22#define RAM_SIZE 32
23
24
25// instructions
26enum
27{
28   OTHER = 0,
29   WRITE,         // write register A3A2A1A0
30   READ,         // read register  A3A2A1A0
31   ERASE         // erase register A3A2A1A0
32};
33
34// other instructions
35enum
36{
37   EWDS = 0,      // erase/write disable
38   WRAL,         // write all registers
39   ERAL,         // erase all registers
40   EWEN,         // erase/write enable
41};
42
43// states
44enum
45{
46   STATE_IDLE = 0,
47   STATE_COMMAND,
48   STATE_ADDRESS,
49   STATE_DATA_IN,
50   STATE_DATA_OUT,
51   STATE_ERASE
52};
53
54
55
56//**************************************************************************
57//  DEVICE DEFINITIONS
58//**************************************************************************
59
60const device_type NMC9306 = nmc9306_device_config::static_alloc_device_config;
61
62
63
64//**************************************************************************
65//  DEVICE CONFIGURATION
66//**************************************************************************
67
68//-------------------------------------------------
69//  nmc9306_device_config - constructor
70//-------------------------------------------------
71
72nmc9306_device_config::nmc9306_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
73   : device_config(mconfig, static_alloc_device_config, "NMC9306", tag, owner, clock),
74     device_config_nvram_interface(mconfig, *this)
75{
76}
77
78
79//-------------------------------------------------
80//  static_alloc_device_config - allocate a new
81//  configuration object
82//-------------------------------------------------
83
84device_config *nmc9306_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
85{
86   return global_alloc(nmc9306_device_config(mconfig, tag, owner, clock));
87}
88
89
90//-------------------------------------------------
91//  alloc_device - allocate a new device object
92//-------------------------------------------------
93
94device_t *nmc9306_device_config::alloc_device(running_machine &machine) const
95{
96   return auto_alloc(&machine, nmc9306_device(machine, *this));
97}
98
99
100
101//**************************************************************************
102//  INLINE HELPERS
103//**************************************************************************
104
105//-------------------------------------------------
106//  nmc9306_device - constructor
107//-------------------------------------------------
108
109inline UINT16 nmc9306_device::read(offs_t offset)
110{
111   return m_register[offset];
112}
113
114
115//-------------------------------------------------
116//  nmc9306_device - constructor
117//-------------------------------------------------
118
119inline void nmc9306_device::write(offs_t offset, UINT16 data)
120{
121   if (m_ewen)
122   {
123      m_register[offset] &= data;
124   }
125}
126
127
128//-------------------------------------------------
129//  nmc9306_device - constructor
130//-------------------------------------------------
131
132inline void nmc9306_device::erase(offs_t offset)
133{
134   if (m_ewen)
135   {
136      m_register[offset] = 0xffff;
137   }
138}
139
140
141
142//**************************************************************************
143//  LIVE DEVICE
144//**************************************************************************
145
146//-------------------------------------------------
147//  nmc9306_device - constructor
148//-------------------------------------------------
149
150nmc9306_device::nmc9306_device(running_machine &_machine, const nmc9306_device_config &config)
151    : device_t(_machine, config),
152     device_nvram_interface(_machine, config, *this),
153     m_state(STATE_IDLE),
154     m_ewen(false),
155      m_config(config)
156{
157}
158
159
160//-------------------------------------------------
161//  device_start - device-specific startup
162//-------------------------------------------------
163
164void nmc9306_device::device_start()
165{
166   // state saving
167   save_item(NAME(m_bits));
168   save_item(NAME(m_state));
169   save_item(NAME(m_command));
170   save_item(NAME(m_address));
171   save_item(NAME(m_data));
172   save_item(NAME(m_ewen));
173   save_item(NAME(m_cs));
174   save_item(NAME(m_sk));
175   save_item(NAME(m_do));
176   save_item(NAME(m_di));
177}
178
179
180//-------------------------------------------------
181//  nvram_default - called to initialize NVRAM to
182//  its default state
183//-------------------------------------------------
184
185void nmc9306_device::nvram_default()
186{
187}
188
189
190//-------------------------------------------------
191//  nvram_read - called to read NVRAM from the
192//  .nv file
193//-------------------------------------------------
194
195void nmc9306_device::nvram_read(emu_file &file)
196{
197   file.read(m_register, RAM_SIZE);
198}
199
200
201//-------------------------------------------------
202//  nvram_write - called to write NVRAM to the
203//  .nv file
204//-------------------------------------------------
205
206void nmc9306_device::nvram_write(emu_file &file)
207{
208   file.write(m_register, RAM_SIZE);
209}
210
211
212//-------------------------------------------------
213//  cs_w - chip select input
214//-------------------------------------------------
215
216WRITE_LINE_MEMBER( nmc9306_device::cs_w )
217{
218   m_cs = state;
219}
220
221
222//-------------------------------------------------
223//  ck_w - serial clock input
224//-------------------------------------------------
225
226WRITE_LINE_MEMBER( nmc9306_device::sk_w )
227{
228   m_sk = state;
229   
230   if (!m_cs || !m_sk) return;
231   
232   switch (m_state)
233   {
234   case STATE_IDLE:
235      if (LOG) logerror("NMC9306 '%s' Idle %u\n", tag(), m_di);
236     
237      if (m_di)
238      {
239         // start bit received
240         m_state = STATE_COMMAND;
241         m_bits = 0;
242      }
243      break;
244     
245   case STATE_COMMAND:
246      if (LOG) logerror("NMC9306 '%s' Command Bit %u\n", tag(), m_di);
247     
248      m_command <<= 1;
249      m_command |= m_di;
250      m_bits++;
251     
252      if (m_bits == 4)
253      {
254         m_state = STATE_ADDRESS;
255         m_bits = 0;
256      }
257      break;
258     
259   case STATE_ADDRESS:
260      if (LOG) logerror("NMC9306 '%s' Address Bit %u\n", tag(), m_di);
261     
262      m_address <<= 1;
263      m_address |= m_di;
264      m_bits++;
265     
266      if (m_bits == 4)
267      {
268         switch ((m_command >> 2) & 0x03)
269         {
270         case OTHER:
271            switch (m_command & 0x03)
272            {
273            case EWDS:
274               if (LOG) logerror("NMC9306 '%s' EWDS\n", tag());
275               m_ewen = false;
276               m_state = STATE_IDLE;
277               break;
278               
279            case WRAL:
280               if (LOG) logerror("NMC9306 '%s' WRAL\n", tag());
281               break;
282               
283            case ERAL:
284               if (LOG) logerror("NMC9306 '%s' ERAL\n", tag());
285               break;
286
287            case EWEN:
288               if (LOG) logerror("NMC9306 '%s' EWEN\n", tag());
289               m_ewen = true;
290               m_state = STATE_IDLE;
291               break;
292            }
293            break;
294
295         case WRITE:
296            if (LOG) logerror("NMC9306 '%s' WRITE %u\n", tag(), m_address & 0x0f);
297            m_state = STATE_DATA_IN;
298            break;
299           
300         case READ:
301            if (LOG) logerror("NMC9306 '%s' READ %u\n", tag(), m_address & 0x0f);
302            m_data = read(m_address & 0x0f);
303            m_state = STATE_DATA_OUT;
304            break;
305           
306         case ERASE:
307            if (LOG) logerror("NMC9306 '%s' ERASE %u\n", tag(), m_address & 0x0f);
308            erase(m_address & 0x0f);
309            m_state = STATE_ERASE;
310            break;
311         }
312         
313         m_bits = 0;
314      }
315      break;
316     
317   case STATE_DATA_IN:
318      if (LOG) logerror("NMC9306 '%s' Data Bit IN %u\n", tag(), m_di);
319     
320      m_data <<= 1;
321      m_data |= m_di;
322      m_bits++;
323     
324      if (m_bits == 16)
325      {
326         write(m_address & 0x0f, m_data);
327         
328         m_state = STATE_IDLE;
329      }
330      break;
331     
332   case STATE_DATA_OUT:
333      if (LOG) logerror("NMC9306 '%s' Data Bit OUT %u\n", tag(), m_di);
334     
335      m_do = BIT(m_data, 15);
336      m_data <<= 1;
337      m_bits++;
338     
339      if (m_bits == 16)
340      {
341         m_state = STATE_IDLE;
342      }
343      break;
344   }
345}
346
347
348//-------------------------------------------------
349//  di_w - serial data input
350//-------------------------------------------------
351
352WRITE_LINE_MEMBER( nmc9306_device::di_w )
353{
354   m_di = state;
355}
356
357
358//-------------------------------------------------
359//  do_r - serial data output
360//-------------------------------------------------
361
362READ_LINE_MEMBER( nmc9306_device::do_r )
363{
364   return m_do;
365}
src/mess/machine/nmc9306.h
r10968r10969
1/**********************************************************************
2
3    National Semiconductor NMC9306 256-Bit Serial EEPROM emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                    CS   1 |*    \_/     | 8   Vcc
11                    SK   2 |             | 7   NC
12                    DI   3 |             | 6   NC
13                    DO   4 |_____________| 5   GND
14
15**********************************************************************/
16
17#pragma once
18
19#ifndef __NMC9306__
20#define __NMC9306__
21
22#include "emu.h"
23
24
25
26//**************************************************************************
27//  MACROS / CONSTANTS
28//**************************************************************************
29
30
31
32
33//**************************************************************************
34//  INTERFACE CONFIGURATION MACROS
35//**************************************************************************
36
37#define MCFG_NMC9306_ADD(_tag) \
38   MCFG_DEVICE_ADD(_tag, NMC9306, 0)
39
40
41
42//**************************************************************************
43//  TYPE DEFINITIONS
44//**************************************************************************
45
46
47// ======================> nmc9306_device_config
48
49class nmc9306_device_config :   public device_config,
50                        public device_config_nvram_interface
51{
52    friend class nmc9306_device;
53
54    // construction/destruction
55    nmc9306_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
56
57public:
58    // allocators
59    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
60    virtual device_t *alloc_device(running_machine &machine) const;
61
62protected:
63};
64
65
66// ======================> nmc9306_device
67
68class nmc9306_device :  public device_t,
69                  public device_nvram_interface
70{
71    friend class nmc9306_device_config;
72
73    // construction/destruction
74    nmc9306_device(running_machine &_machine, const nmc9306_device_config &_config);
75
76public:
77    DECLARE_WRITE_LINE_MEMBER( cs_w );
78    DECLARE_WRITE_LINE_MEMBER( sk_w );
79    DECLARE_WRITE_LINE_MEMBER( di_w );
80    DECLARE_READ_LINE_MEMBER( do_r );
81
82protected:
83    // device-level overrides
84    virtual void device_start();
85
86   // device_nvram_interface overrides
87   virtual void nvram_default();
88   virtual void nvram_read(emu_file &file);
89   virtual void nvram_write(emu_file &file);
90
91private:
92   inline UINT16 read(offs_t offset);
93   inline void write(offs_t offset, UINT16 data);
94   inline void erase(offs_t offset);
95
96   UINT16 m_register[16];
97   
98   int m_bits;
99   int m_state;
100   UINT8 m_command;
101   UINT8 m_address;
102   UINT16 m_data;
103   bool m_ewen;
104   int m_cs;
105   int m_sk;
106   int m_do;
107   int m_di;
108
109   const nmc9306_device_config &m_config;
110};
111
112
113// device type definition
114extern const device_type NMC9306;
115
116
117
118#endif
src/mess/machine/i8155.c
r10968r10969
1/**********************************************************************
2
3    Intel 8155 - 2048-Bit Static MOS RAM with I/O Ports and Timer emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10/*
11
12    TODO:
13
14    - strobed mode
15
16*/
17
18#include "emu.h"
19#include "i8155.h"
20
21
22
23//**************************************************************************
24//  MACROS / CONSTANTS
25//**************************************************************************
26
27#define LOG 1
28
29enum
30{
31   REGISTER_COMMAND = 0,
32   REGISTER_STATUS = 0,
33   REGISTER_PORT_A,
34   REGISTER_PORT_B,
35   REGISTER_PORT_C,
36   REGISTER_TIMER_LOW,
37   REGISTER_TIMER_HIGH
38};
39
40enum
41{
42   PORT_A = 0,
43   PORT_B,
44   PORT_C,
45   PORT_COUNT
46};
47
48enum
49{
50   PORT_MODE_INPUT = 0,
51   PORT_MODE_OUTPUT,
52   PORT_MODE_STROBED_PORT_A,   // not supported
53   PORT_MODE_STROBED         // not supported
54};
55
56enum
57{
58   MEMORY = 0,
59   IO
60};
61
62#define COMMAND_PA               0x01
63#define COMMAND_PB               0x02
64#define COMMAND_PC_MASK            0x0c
65#define COMMAND_PC_ALT_1         0x00
66#define COMMAND_PC_ALT_2         0x0c
67#define COMMAND_PC_ALT_3         0x04   // not supported
68#define COMMAND_PC_ALT_4         0x08   // not supported
69#define COMMAND_IEA               0x10   // not supported
70#define COMMAND_IEB               0x20   // not supported
71#define COMMAND_TM_MASK            0xc0
72#define COMMAND_TM_NOP            0x00
73#define COMMAND_TM_STOP            0x40
74#define COMMAND_TM_STOP_AFTER_TC   0x80
75#define COMMAND_TM_START         0xc0
76
77#define STATUS_INTR_A            0x01   // not supported
78#define STATUS_A_BF               0x02   // not supported
79#define STATUS_INTE_A            0x04   // not supported
80#define STATUS_INTR_B            0x08   // not supported
81#define STATUS_B_BF               0x10   // not supported
82#define STATUS_INTE_B            0x20   // not supported
83#define STATUS_TIMER            0x40
84
85#define TIMER_MODE_MASK            0xc0
86#define TIMER_MODE_LOW            0x00
87#define TIMER_MODE_SQUARE_WAVE      0x40
88#define TIMER_MODE_SINGLE_PULSE      0x80
89#define TIMER_MODE_AUTOMATIC_RELOAD   0xc0
90
91
92
93//**************************************************************************
94//  GLOBAL VARIABLES
95//**************************************************************************
96
97// devices
98const device_type I8155 = i8155_device_config::static_alloc_device_config;
99
100
101// default address map
102static ADDRESS_MAP_START( i8155, AS_0, 8 )
103   AM_RANGE(0x00, 0xff) AM_RAM
104ADDRESS_MAP_END
105
106
107
108//**************************************************************************
109//  DEVICE CONFIGURATION
110//**************************************************************************
111
112//-------------------------------------------------
113//  i8155_device_config - constructor
114//-------------------------------------------------
115
116i8155_device_config::i8155_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
117   : device_config(mconfig, static_alloc_device_config, "Intel 8155", tag, owner, clock),
118     device_config_memory_interface(mconfig, *this),
119     m_space_config("ram", ENDIANNESS_LITTLE, 8, 8, 0, NULL, *ADDRESS_MAP_NAME(i8155))
120{
121}
122
123
124//-------------------------------------------------
125//  static_alloc_device_config - allocate a new
126//  configuration object
127//-------------------------------------------------
128
129device_config *i8155_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
130{
131   return global_alloc(i8155_device_config(mconfig, tag, owner, clock));
132}
133
134
135//-------------------------------------------------
136//  alloc_device - allocate a new device object
137//-------------------------------------------------
138
139device_t *i8155_device_config::alloc_device(running_machine &machine) const
140{
141   return auto_alloc(&machine, i8155_device(machine, *this));
142}
143
144
145//-------------------------------------------------
146//  memory_space_config - return a description of
147//  any address spaces owned by this device
148//-------------------------------------------------
149
150const address_space_config *i8155_device_config::memory_space_config(address_spacenum spacenum) const
151{
152   return (spacenum == AS_0) ? &m_space_config : NULL;
153}
154
155
156//-------------------------------------------------
157//  device_config_complete - perform any
158//  operations now that the configuration is
159//  complete
160//-------------------------------------------------
161
162void i8155_device_config::device_config_complete()
163{
164   // inherit a copy of the static data
165   const i8155_interface *intf = reinterpret_cast<const i8155_interface *>(static_config());
166   if (intf != NULL)
167      *static_cast<i8155_interface *>(this) = *intf;
168
169   // or initialize to defaults if none provided
170   else
171   {
172      memset(&in_pa_func, 0, sizeof(in_pa_func));
173      memset(&out_pa_func, 0, sizeof(out_pa_func));
174      memset(&in_pb_func, 0, sizeof(in_pb_func));
175      memset(&out_pb_func, 0, sizeof(out_pb_func));
176      memset(&in_pc_func, 0, sizeof(in_pc_func));
177      memset(&out_pc_func, 0, sizeof(out_pc_func));
178      memset(&out_to_func, 0, sizeof(out_to_func));
179   }
180}
181
182
183
184//**************************************************************************
185//  INLINE HELPERS
186//**************************************************************************
187
188inline UINT8 i8155_device::get_timer_mode()
189{
190   return (m_count_length >> 8) & TIMER_MODE_MASK;
191}
192
193inline void i8155_device::timer_output()
194{
195   devcb_call_write_line(&m_out_to_func, m_to);
196
197   if (LOG) logerror("8155 '%s' Timer Output: %u\n", tag(), m_to);
198}
199
200inline void i8155_device::pulse_timer_output()
201{
202   m_to = 0; timer_output();
203   m_to = 1; timer_output();
204}
205
206inline int i8155_device::get_port_mode(int port)
207{
208   int mode = -1;
209
210   switch (port)
211   {
212   case PORT_A:
213      mode = (m_command & COMMAND_PA) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT;
214      break;
215
216   case PORT_B:
217      mode = (m_command & COMMAND_PB) ? PORT_MODE_OUTPUT : PORT_MODE_INPUT;
218      break;
219
220   case PORT_C:
221      switch (m_command & COMMAND_PC_MASK)
222      {
223      case COMMAND_PC_ALT_1: mode = PORT_MODE_INPUT;         break;
224      case COMMAND_PC_ALT_2: mode = PORT_MODE_OUTPUT;         break;
225      case COMMAND_PC_ALT_3: mode = PORT_MODE_STROBED_PORT_A; break;
226      case COMMAND_PC_ALT_4: mode = PORT_MODE_STROBED;      break;
227      }
228      break;
229   }
230
231   return mode;
232}
233
234inline UINT8 i8155_device::read_port(int port)
235{
236   UINT8 data = 0;
237
238   switch (port)
239   {
240   case PORT_A:
241   case PORT_B:
242      switch (get_port_mode(port))
243      {
244      case PORT_MODE_INPUT:
245         data = devcb_call_read8(&m_in_port_func[port], 0);
246         break;
247
248      case PORT_MODE_OUTPUT:
249         data = m_output[port];
250         break;
251      }
252      break;
253
254   case PORT_C:
255      switch (get_port_mode(PORT_C))
256      {
257      case PORT_MODE_INPUT:
258         data = devcb_call_read8(&m_in_port_func[port], 0) & 0x3f;
259         break;
260
261      case PORT_MODE_OUTPUT:
262         data = m_output[port] & 0x3f;
263         break;
264
265      default:
266         logerror("8155 '%s' Unsupported Port C mode!\n", tag());
267      }
268      break;
269   }
270
271   return data;
272}
273
274inline void i8155_device::write_port(int port, UINT8 data)
275{
276   switch (get_port_mode(port))
277   {
278   case PORT_MODE_OUTPUT:
279      m_output[port] = data;
280      devcb_call_write8(&m_out_port_func[port], 0, m_output[port]);
281      break;
282   }
283}
284
285
286//**************************************************************************
287//  LIVE DEVICE
288//**************************************************************************
289
290//-------------------------------------------------
291//  i8155_device - constructor
292//-------------------------------------------------
293
294i8155_device::i8155_device(running_machine &_machine, const i8155_device_config &config)
295    : device_t(_machine, config),
296     device_memory_interface(_machine, config, *this),
297      m_config(config)
298{
299
300}
301
302
303//-------------------------------------------------
304//  device_start - device-specific startup
305//-------------------------------------------------
306
307void i8155_device::device_start()
308{
309   // resolve callbacks
310   devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this);
311   devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this);
312   devcb_resolve_read8(&m_in_port_func[2], &m_config.in_pc_func, this);
313   devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this);
314   devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this);
315   devcb_resolve_write8(&m_out_port_func[2], &m_config.out_pc_func, this);
316   devcb_resolve_write_line(&m_out_to_func, &m_config.out_to_func, this);
317
318   // allocate timers
319   m_timer = timer_alloc();
320
321   // register for state saving
322   save_item(NAME(m_io_m));
323   save_item(NAME(m_ad));
324   save_item(NAME(m_command));
325   save_item(NAME(m_status));
326   save_item(NAME(m_output));
327   save_item(NAME(m_count_length));
328   save_item(NAME(m_counter));
329   save_item(NAME(m_to));
330}
331
332
333//-------------------------------------------------
334//  device_reset - device-specific reset
335//-------------------------------------------------
336
337void i8155_device::device_reset()
338{
339   // clear output registers
340   m_output[PORT_A] = 0;
341   m_output[PORT_B] = 0;
342   m_output[PORT_C] = 0;
343
344   // set ports to input mode
345   register_w(REGISTER_COMMAND, m_command & ~(COMMAND_PA | COMMAND_PB | COMMAND_PC_MASK));
346
347   // clear timer flag
348   m_status &= ~STATUS_TIMER;
349
350   // stop counting
351   m_timer->enable(0);
352
353   // clear timer output
354   m_to = 1;
355   timer_output();
356}
357
358
359//-------------------------------------------------
360//  device_timer - handler timer events
361//-------------------------------------------------
362
363void i8155_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
364{
365   // count down
366   m_counter--;
367
368   if (get_timer_mode() == TIMER_MODE_LOW)
369   {
370      // pulse on every count
371      pulse_timer_output();
372   }
373
374   if (m_counter == 0)
375   {
376      if (LOG) logerror("8155 '%s' Timer Count Reached\n", tag());
377
378      switch (m_command & COMMAND_TM_MASK)
379      {
380      case COMMAND_TM_STOP_AFTER_TC:
381         // stop timer
382         m_timer->enable(0);
383
384         if (LOG) logerror("8155 '%s' Timer Stopped\n", tag());
385         break;
386      }
387
388      switch (get_timer_mode())
389      {
390      case TIMER_MODE_SQUARE_WAVE:
391         // toggle timer output
392         m_to = !m_to;
393         timer_output();
394         break;
395
396      case TIMER_MODE_SINGLE_PULSE:
397         // single pulse upon TC being reached
398         pulse_timer_output();
399
400         // clear timer mode setting
401         m_command &= ~COMMAND_TM_MASK;
402         break;
403
404      case TIMER_MODE_AUTOMATIC_RELOAD:
405         // automatic reload, i.e. single pulse every time TC is reached
406         pulse_timer_output();
407         break;
408      }
409
410      // set timer flag
411      m_status |= STATUS_TIMER;
412
413      // reload timer counter
414      m_counter = m_count_length & 0x3fff;
415   }
416}
417
418
419//-------------------------------------------------
420//  io_r - register read
421//-------------------------------------------------
422
423READ8_MEMBER( i8155_device::io_r )
424{
425   UINT8 data = 0;
426
427   switch (offset & 0x03)
428   {
429   case REGISTER_STATUS:
430      data = m_status;
431
432      // clear timer flag
433      m_status &= ~STATUS_TIMER;
434      break;
435
436   case REGISTER_PORT_A:
437      data = read_port(PORT_A);
438      break;
439
440   case REGISTER_PORT_B:
441      data = read_port(PORT_B);
442      break;
443
444   case REGISTER_PORT_C:
445      data = read_port(PORT_C);
446      break;
447   }
448
449   return data;
450}
451
452
453//-------------------------------------------------
454//  register_w - register write
455//-------------------------------------------------
456
457void i8155_device::register_w(int offset, UINT8 data)
458{
459   switch (offset & 0x07)
460   {
461   case REGISTER_COMMAND:
462      m_command = data;
463
464      if (LOG) logerror("8155 '%s' Port A Mode: %s\n", tag(), (data & COMMAND_PA) ? "output" : "input");
465      if (LOG) logerror("8155 '%s' Port B Mode: %s\n", tag(), (data & COMMAND_PB) ? "output" : "input");
466
467      if (LOG) logerror("8155 '%s' Port A Interrupt: %s\n", tag(), (data & COMMAND_IEA) ? "enabled" : "disabled");
468      if (LOG) logerror("8155 '%s' Port B Interrupt: %s\n", tag(), (data & COMMAND_IEB) ? "enabled" : "disabled");
469
470      switch (data & COMMAND_PC_MASK)
471      {
472      case COMMAND_PC_ALT_1:
473         if (LOG) logerror("8155 '%s' Port C Mode: Alt 1\n", tag());
474         break;
475
476      case COMMAND_PC_ALT_2:
477         if (LOG) logerror("8155 '%s' Port C Mode: Alt 2\n", tag());
478         break;
479
480      case COMMAND_PC_ALT_3:
481         if (LOG) logerror("8155 '%s' Port C Mode: Alt 3\n", tag());
482         break;
483
484      case COMMAND_PC_ALT_4:
485         if (LOG) logerror("8155 '%s' Port C Mode: Alt 4\n", tag());
486         break;
487      }
488
489      switch (data & COMMAND_TM_MASK)
490      {
491      case COMMAND_TM_NOP:
492         // do not affect counter operation
493         break;
494
495      case COMMAND_TM_STOP:
496         // NOP if timer has not started, stop counting if the timer is running
497         if (LOG) logerror("8155 '%s' Timer Command: Stop\n", tag());
498         m_timer->enable(0);
499         break;
500
501      case COMMAND_TM_STOP_AFTER_TC:
502         // stop immediately after present TC is reached (NOP if timer has not started)
503         if (LOG) logerror("8155 '%s' Timer Command: Stop after TC\n", tag());
504         break;
505
506      case COMMAND_TM_START:
507         if (LOG) logerror("8155 '%s' Timer Command: Start\n", tag());
508
509         if (m_timer->enabled())
510         {
511            // if timer is running, start the new mode and CNT length immediately after present TC is reached
512         }
513         else
514         {
515            // load mode and CNT length and start immediately after loading (if timer is not running)
516            m_counter = m_count_length;
517            m_timer->adjust(attotime::zero, 0, attotime::from_hz(clock()));
518         }
519         break;
520      }
521      break;
522
523   case REGISTER_PORT_A:
524      write_port(PORT_A, data);
525      break;
526
527   case REGISTER_PORT_B:
528      write_port(PORT_B, data);
529      break;
530
531   case REGISTER_PORT_C:
532      write_port(PORT_C, data);
533      break;
534
535   case REGISTER_TIMER_LOW:
536      m_count_length = (m_count_length & 0xff00) | data;
537      if (LOG) logerror("8155 '%s' Count Length Low: %04x\n", tag(), m_count_length);
538      break;
539
540   case REGISTER_TIMER_HIGH:
541      m_count_length = (data << 8) | (m_count_length & 0xff);
542      if (LOG) logerror("8155 '%s' Count Length High: %04x\n", tag(), m_count_length);
543
544      switch (data & TIMER_MODE_MASK)
545      {
546      case TIMER_MODE_LOW:
547         // puts out LOW during second half of count
548         if (LOG) logerror("8155 '%s' Timer Mode: LOW\n", tag());
549         break;
550
551      case TIMER_MODE_SQUARE_WAVE:
552         // square wave, i.e. the period of the square wave equals the count length programmed with automatic reload at terminal count
553         if (LOG) logerror("8155 '%s' Timer Mode: Square wave\n", tag());
554         break;
555
556      case TIMER_MODE_SINGLE_PULSE:
557         // single pulse upon TC being reached
558         if (LOG) logerror("8155 '%s' Timer Mode: Single pulse\n", tag());
559         break;
560
561      case TIMER_MODE_AUTOMATIC_RELOAD:
562         // automatic reload, i.e. single pulse every time TC is reached
563         if (LOG) logerror("8155 '%s' Timer Mode: Automatic reload\n", tag());
564         break;
565      }
566      break;
567   }
568}
569
570//-------------------------------------------------
571//  io_w - register write
572//-------------------------------------------------
573
574WRITE8_MEMBER( i8155_device::io_w )
575{
576   register_w(offset, data);
577}
578
579
580//-------------------------------------------------
581//  memory_r - internal RAM read
582//-------------------------------------------------
583
584READ8_MEMBER( i8155_device::memory_r )
585{
586   return this->space()->read_byte(offset);
587}
588
589
590//-------------------------------------------------
591//  memory_w - internal RAM write
592//-------------------------------------------------
593
594WRITE8_MEMBER( i8155_device::memory_w )
595{
596   this->space()->write_byte(offset, data);
597}
598
599
600//-------------------------------------------------
601//  ale_w - address latch write
602//-------------------------------------------------
603
604WRITE8_MEMBER( i8155_device::ale_w )
605{
606   // I/O / memory select
607   m_io_m = BIT(offset, 0);
608
609   // address
610   m_ad = data;
611}
612
613
614//-------------------------------------------------
615//  read - memory or I/O read
616//-------------------------------------------------
617
618READ8_MEMBER( i8155_device::read )
619{
620   UINT8 data = 0;
621
622   switch (m_io_m)
623   {
624   case MEMORY:
625      data = memory_r(space, m_ad);
626      break;
627
628   case IO:
629      data = io_r(space, m_ad);
630      break;
631   }
632
633   return data;
634}
635
636
637//-------------------------------------------------
638//  write - memory or I/O write
639//-------------------------------------------------
640
641WRITE8_MEMBER( i8155_device::write )
642{
643   switch (m_io_m)
644   {
645   case MEMORY:
646      memory_w(space, m_ad, data);
647      break;
648
649   case IO:
650      io_w(space, m_ad, data);
651      break;
652   }
653}
src/mess/machine/i8155.h
r10968r10969
1/**********************************************************************
2
3    Intel 8155 - 2048-Bit Static MOS RAM with I/O Ports and Timer emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                   PC3   1 |*    \_/     | 40  Vcc
11                   PC4   2 |             | 39  PC2
12              TIMER IN   3 |             | 38  PC1
13                 RESET   4 |             | 37  PC0
14                   PC5   5 |             | 36  PB7
15            _TIMER OUT   6 |             | 35  PB6
16                 IO/_M   7 |             | 34  PB5
17             CE or _CE   8 |             | 33  PB4
18                   _RD   9 |             | 32  PB3
19                   _WR  10 |    8155     | 31  PB2
20                   ALE  11 |    8156     | 30  PB1
21                   AD0  12 |             | 29  PB0
22                   AD1  13 |             | 28  PA7
23                   AD2  14 |             | 27  PA6
24                   AD3  15 |             | 26  PA5
25                   AD4  16 |             | 25  PA4
26                   AD5  17 |             | 24  PA3
27                   AD6  18 |             | 23  PA2
28                   AD7  19 |             | 22  PA1
29                   Vss  20 |_____________| 21  PA0
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __I8155__
36#define __I8155__
37
38#include "emu.h"
39
40
41
42//**************************************************************************
43//  MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
53#define MCFG_I8155_ADD(_tag, _clock, _config) \
54   MCFG_DEVICE_ADD((_tag), I8155, _clock)   \
55   MCFG_DEVICE_CONFIG(_config)
56
57#define I8155_INTERFACE(name) \
58   const i8155_interface (name) =
59
60
61
62//**************************************************************************
63//  TYPE DEFINITIONS
64//**************************************************************************
65
66// ======================> i8155_interface
67
68struct i8155_interface
69{
70   devcb_read8            in_pa_func;
71   devcb_write8         out_pa_func;
72
73   devcb_read8            in_pb_func;
74   devcb_write8         out_pb_func;
75
76   devcb_read8            in_pc_func;
77   devcb_write8         out_pc_func;
78
79   // this gets called for each change of the TIMER OUT pin (pin 6)
80   devcb_write_line      out_to_func;
81};
82
83
84
85// ======================> i8155_device_config
86
87class i8155_device_config :   public device_config,
88                        public device_config_memory_interface,
89                                public i8155_interface
90{
91    friend class i8155_device;
92
93    // construction/destruction
94    i8155_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
95
96public:
97    // allocators
98    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
99    virtual device_t *alloc_device(running_machine &machine) const;
100
101protected:
102   // device_config overrides
103   virtual void device_config_complete();
104
105   // device_config_memory_interface overrides
106   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
107
108    // address space configurations
109   const address_space_config      m_space_config;
110};
111
112
113
114// ======================> i8155_device
115
116class i8155_device :   public device_t,
117                  public device_memory_interface
118{
119    friend class i8155_device_config;
120
121    // construction/destruction
122    i8155_device(running_machine &_machine, const i8155_device_config &_config);
123
124public:
125    DECLARE_READ8_MEMBER( io_r );
126    DECLARE_WRITE8_MEMBER( io_w );
127
128    DECLARE_READ8_MEMBER( memory_r );
129    DECLARE_WRITE8_MEMBER( memory_w );
130
131    DECLARE_WRITE8_MEMBER( ale_w );
132    DECLARE_READ8_MEMBER( read );
133    DECLARE_WRITE8_MEMBER( write );
134
135protected:
136    // device-level overrides
137    virtual void device_start();
138    virtual void device_reset();
139   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
140
141   inline UINT8 get_timer_mode();
142   inline void timer_output();
143   inline void pulse_timer_output();
144   inline int get_port_mode(int port);
145   inline UINT8 read_port(int port);
146   inline void write_port(int port, UINT8 data);
147
148   void register_w(int offset, UINT8 data);
149
150private:
151   devcb_resolved_read8      m_in_port_func[3];
152   devcb_resolved_write8      m_out_port_func[3];
153   devcb_resolved_write_line   m_out_to_func;
154
155   // CPU interface
156   int m_io_m;               // I/O or memory select
157   UINT8 m_ad;               // address
158
159   // registers
160   UINT8 m_command;         // command register
161   UINT8 m_status;            // status register
162   UINT8 m_output[3];         // output latches
163
164   // counter
165   UINT16 m_count_length;      // count length register
166   UINT16 m_counter;         // counter register
167   int m_to;               // timer output
168
169   // timers
170   emu_timer *m_timer;         // counter timer
171
172   const i8155_device_config &m_config;
173};
174
175
176// device type definition
177extern const device_type I8155;
178
179
180
181#endif
src/mess/machine/i8212.c
r10968r10969
1/**********************************************************************
2
3    Intel 8212 8-Bit Input/Output Port emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "machine/devhelpr.h"
12#include "i8212.h"
13
14
15
16//**************************************************************************
17//  MACROS / CONSTANTS
18//**************************************************************************
19
20#define LOG 0
21
22
23
24//**************************************************************************
25//  GLOBAL VARIABLES
26//**************************************************************************
27
28// devices
29const device_type I8212 = i8212_device_config::static_alloc_device_config;
30
31
32
33//**************************************************************************
34//  DEVICE CONFIGURATION
35//**************************************************************************
36
37GENERIC_DEVICE_CONFIG_SETUP(i8212, "Intel 8212")
38
39
40//-------------------------------------------------
41//  device_config_complete - perform any
42//  operations now that the configuration is
43//  complete
44//-------------------------------------------------
45
46void i8212_device_config::device_config_complete()
47{
48   // inherit a copy of the static data
49   const i8212_interface *intf = reinterpret_cast<const i8212_interface *>(static_config());
50   if (intf != NULL)
51      *static_cast<i8212_interface *>(this) = *intf;
52
53   // or initialize to defaults if none provided
54   else
55   {
56      memset(&out_int_func, 0, sizeof(out_int_func));
57      memset(&in_di_func, 0, sizeof(in_di_func));
58      memset(&out_do_func, 0, sizeof(out_do_func));
59   }
60}
61
62
63
64//**************************************************************************
65//  LIVE DEVICE
66//**************************************************************************
67
68//-------------------------------------------------
69//  i8212_device - constructor
70//-------------------------------------------------
71
72i8212_device::i8212_device(running_machine &_machine, const i8212_device_config &config)
73    : device_t(_machine, config),
74     m_md(I8212_MODE_INPUT),
75     m_stb(0),
76      m_config(config)
77{
78
79}
80
81
82//-------------------------------------------------
83//  device_start - device-specific startup
84//-------------------------------------------------
85
86void i8212_device::device_start()
87{
88   // resolve callbacks
89   devcb_resolve_write_line(&m_out_int_func, &m_config.out_int_func, this);
90   devcb_resolve_read8(&m_in_di_func, &m_config.in_di_func, this);
91   devcb_resolve_write8(&m_out_do_func, &m_config.out_do_func, this);
92
93   // register for state saving
94   save_item(NAME(m_md));
95   save_item(NAME(m_stb));
96   save_item(NAME(m_data));
97}
98
99
100//-------------------------------------------------
101//  device_reset - device-specific reset
102//-------------------------------------------------
103
104void i8212_device::device_reset()
105{
106   m_data = 0;
107
108   if (m_md == I8212_MODE_OUTPUT)
109   {
110      // output data
111      devcb_call_write8(&m_out_do_func, 0, m_data);
112   }
113}
114
115
116//-------------------------------------------------
117//  data_r - data latch read
118//-------------------------------------------------
119
120READ8_MEMBER( i8212_device::data_r )
121{
122   // clear interrupt line
123   devcb_call_write_line(&m_out_int_func, CLEAR_LINE);
124
125   if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), CLEAR_LINE);
126
127   return m_data;
128}
129
130
131//-------------------------------------------------
132//  data_w - data latch write
133//-------------------------------------------------
134
135WRITE8_MEMBER( i8212_device::data_w )
136{
137   // latch data
138   m_data = data;
139
140   // output data
141   devcb_call_write8(&m_out_do_func, 0, m_data);
142}
143
144
145//-------------------------------------------------
146//  md_w - mode write
147//-------------------------------------------------
148
149WRITE_LINE_MEMBER( i8212_device::md_w )
150{
151   if (LOG) logerror("I8212 '%s' Mode: %s\n", tag(), state ? "output" : "input");
152
153   m_md = state;
154}
155
156
157//-------------------------------------------------
158//  stb_w - data strobe write
159//-------------------------------------------------
160
161WRITE_LINE_MEMBER( i8212_device::stb_w )
162{
163   if (LOG) logerror("I8212 '%s' STB: %u\n", tag(), state);
164
165   if (m_md == I8212_MODE_INPUT)
166   {
167      if (m_stb && !state)
168      {
169         // input data
170         m_data = devcb_call_read8(&m_in_di_func, 0);
171
172         // assert interrupt line
173         devcb_call_write_line(&m_out_int_func, ASSERT_LINE);
174
175         if (LOG) logerror("I8212 '%s' INT: %u\n", tag(), ASSERT_LINE);
176      }
177   }
178
179   m_stb = state;
180}
src/mess/machine/i8212.h
r10968r10969
1/**********************************************************************
2
3    Intel 8212 8-Bit Input/Output Port emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                  _DS1   1 |*    \_/     | 24  Vcc
11                    MD   2 |             | 23  _INT
12                   DI1   3 |             | 22  DI8
13                   DO1   4 |             | 21  DO8
14                   DI2   5 |             | 20  DI7
15                   DO2   6 |    8212     | 19  DO7
16                   DI3   7 |             | 18  DI6
17                   DO3   8 |             | 17  DO6
18                   DI4   9 |             | 16  DI5
19                   DO4  10 |             | 15  DO5
20                   STB  11 |             | 14  _CLR
21                   GND  12 |_____________| 13  DS2
22
23**********************************************************************/
24
25#pragma once
26
27#ifndef __I8212__
28#define __I8212__
29
30#include "emu.h"
31
32
33
34///*************************************************************************
35//  MACROS / CONSTANTS
36///*************************************************************************
37
38enum
39{
40   I8212_MODE_INPUT = 0,
41   I8212_MODE_OUTPUT
42};
43
44
45
46///*************************************************************************
47//  INTERFACE CONFIGURATION MACROS
48///*************************************************************************
49
50#define MCFG_I8212_ADD(_tag, _config) \
51   MCFG_DEVICE_ADD((_tag), I8212, 0)   \
52   MCFG_DEVICE_CONFIG(_config)
53
54#define I8212_INTERFACE(name) \
55   const i8212_interface (name) =
56
57
58
59///*************************************************************************
60//  TYPE DEFINITIONS
61///*************************************************************************
62
63// ======================> i8212_interface
64
65struct i8212_interface
66{
67   devcb_write_line   out_int_func;
68
69   devcb_read8         in_di_func;
70   devcb_write8      out_do_func;
71};
72
73
74
75// ======================> i8212_device_config
76
77class i8212_device_config :   public device_config,
78                                public i8212_interface
79{
80    friend class i8212_device;
81
82    // construction/destruction
83    i8212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
84
85public:
86    // allocators
87    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
88    virtual device_t *alloc_device(running_machine &machine) const;
89
90protected:
91   // device_config overrides
92   virtual void device_config_complete();
93};
94
95
96
97// ======================> i8212_device
98
99class i8212_device :   public device_t
100{
101    friend class i8212_device_config;
102
103    // construction/destruction
104    i8212_device(running_machine &_machine, const i8212_device_config &_config);
105
106public:
107    DECLARE_READ8_MEMBER( data_r );
108    DECLARE_WRITE8_MEMBER( data_w );
109
110   DECLARE_WRITE_LINE_MEMBER( md_w );
111   DECLARE_WRITE_LINE_MEMBER( stb_w );
112
113protected:
114    // device-level overrides
115    virtual void device_start();
116    virtual void device_reset();
117
118private:
119   devcb_resolved_write_line   m_out_int_func;
120   devcb_resolved_read8      m_in_di_func;
121   devcb_resolved_write8      m_out_do_func;
122
123   int m_md;               // mode
124   int m_stb;               // strobe
125   UINT8 m_data;            // data latch
126
127   const i8212_device_config &m_config;
128};
129
130
131// device type definition
132extern const device_type I8212;
133
134
135
136#endif
src/mess/machine/z8536.c
r10968r10969
1/**********************************************************************
2
3    Zilog Z8536 Counter/Timer and Parallel I/O emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "z8536.h"
12#include "machine/devhelpr.h"
13
14
15
16//**************************************************************************
17//  MACROS / CONSTANTS
18//**************************************************************************
19
20// states
21enum
22{
23   STATE_RESET = -1,
24   STATE_0,
25   STATE_1
26};
27
28
29// ports
30enum
31{
32   PORT_C = 0,
33   PORT_B,
34   PORT_A,
35   CONTROL
36};
37
38
39// registers
40enum
41{
42   MASTER_INTERRUPT_CONTROL = 0,
43   MASTER_CONFIGURATION_CONTROL,
44   PORT_A_INTERRUPT_VECTOR,
45   PORT_B_INTERRUPT_VECTOR,
46   COUNTER_TIMER_INTERRUPT_VECTOR,
47   PORT_C_DATA_PATH_POLARITY,
48   PORT_C_DATA_DIRECTION,
49   PORT_C_SPECIAL_IO_CONTROL,
50   PORT_A_COMMAND_AND_STATUS,
51   PORT_B_COMMAND_AND_STATUS,
52   COUNTER_TIMER_1_COMMAND_AND_STATUS,
53   COUNTER_TIMER_2_COMMAND_AND_STATUS,
54   COUNTER_TIMER_3_COMMAND_AND_STATUS,
55   PORT_A_DATA,
56   PORT_B_DATA,
57   PORT_C_DATA,
58   COUNTER_TIMER_1_CURRENT_COUNT_MS_BYTE,
59   COUNTER_TIMER_1_CURRENT_COUNT_LS_BYTE,
60   COUNTER_TIMER_2_CURRENT_COUNT_MS_BYTE,
61   COUNTER_TIMER_2_CURRENT_COUNT_LS_BYTE,
62   COUNTER_TIMER_3_CURRENT_COUNT_MS_BYTE,
63   COUNTER_TIMER_3_CURRENT_COUNT_LS_BYTE,
64   COUNTER_TIMER_1_TIME_CONSTANT_MS_BYTE,
65   COUNTER_TIMER_1_TIME_CONSTANT_LS_BYTE,
66   COUNTER_TIMER_2_TIME_CONSTANT_MS_BYTE,
67   COUNTER_TIMER_2_TIME_CONSTANT_LS_BYTE,
68   COUNTER_TIMER_3_TIME_CONSTANT_MS_BYTE,
69   COUNTER_TIMER_3_TIME_CONSTANT_LS_BYTE,
70   COUNTER_TIMER_1_MODE_SPECIFICATION,
71   COUNTER_TIMER_2_MODE_SPECIFICATION,
72   COUNTER_TIMER_3_MODE_SPECIFICATION,
73   CURRENT_VECTOR,
74   PORT_A_MODE_SPECIFICATION,
75   PORT_A_HANDSHAKE_SPECIFICATION,
76   PORT_A_DATA_PATH_POLARITY,
77   PORT_A_DATA_DIRECTION,
78   PORT_A_SPECIAL_IO_CONTROL,
79   PORT_A_PATTERN_POLARITY,
80   PORT_A_PATTERN_TRANSITION,
81   PORT_A_PATTERN_MASK,
82   PORT_B_MODE_SPECIFICATION,
83   PORT_B_HANDSHAKE_SPECIFICATION,
84   PORT_B_DATA_PATH_POLARITY,
85   PORT_B_DATA_DIRECTION,
86   PORT_B_SPECIAL_IO_CONTROL,
87   PORT_B_PATTERN_POLARITY,
88   PORT_B_PATTERN_TRANSITION,
89   PORT_B_PATTERN_MASK
90};
91
92
93// counter/timer link control
94enum
95{
96   LC_INDEPENDENT = 0,
97   LC_CT1_GATES_CT2,
98   LC_CT1_TRIGGERS_CT2,
99   LC_CT1_COUNTS_CT2
100};
101
102
103// port type select
104enum
105{
106   PTS_BIT = 0,
107   PTS_INPUT,
108   PTS_OUTPUT,
109   PTS_BIDIRECTIONAL
110};
111
112
113// pattern mode specification
114enum
115{
116   PMS_DISABLE = 0,
117   PMS_AND,
118   PMS_OR,
119   PMS_VECTOR
120};
121
122
123// handshake specification
124enum
125{
126   HTS_INTERLOCKED = 0,
127   HTS_STROBED,
128   HTS_PULSED,
129   HTS_3_WIRE
130};
131
132
133// request/wait specification
134enum
135{
136   RWS_DISABLED = 0,
137   RWS_OUTPUT_WAIT,
138   RWS_INPUT_WAIT = 3,
139   RWS_SPECIAL_REQUEST,
140   RWS_OUTPUT_REQUEST,
141   RWS_INPUT_REQUEST = 7
142};
143
144
145// pattern specification
146enum
147{
148   BIT_MASKED_OFF = 0,
149   ANY_TRANSITION,
150   ZERO = 4,
151   ONE,
152   ONE_TO_ZERO,
153   ZERO_TO_ONE
154};
155
156
157// output duty cycle
158enum
159{
160   DCS_PULSE,
161   DCS_ONE_SHOT,
162   DCS_SQUARE_WAVE,
163   DCS_DO_NOT_USE
164};
165
166
167// master interrupt control register
168#define MICR_RESET      0x01   // reset
169#define MICR_RJA       0x02   // right justified address
170#define MICR_CT_VIS      0x04   // counter/timer vector includes status
171#define MICR_PB_VIS      0x08   // port B vector includes status
172#define MICR_PA_VIS      0x10   // port A vector includes status
173#define MICR_NV       0x20   // no vector
174#define MICR_DLC       0x40   // disable lower chain
175#define MICR_MIE       0x80   // master interrupt enable
176
177
178// master configuration control register
179#define MCCR_LC_MASK   0x03   // counter/timer link controls
180#define MCCR_PAE      0x04   // port A enable
181#define MCCR_PLC      0x08   // port link control
182#define MCCR_PCE_CT3E   0x10   // port C and counter/timer 3 enable
183#define MCCR_CT2E      0x20   // counter/timer 2 enable
184#define MCCR_CT1E      0x40   // counter/timer 1 enable
185#define MCCR_PBE      0x80   // port B enable
186
187
188// port mode specification registers
189#define PMS_LPM         0x01   // latch on pattern match
190#define PMS_PMS_MASK   0x06   // pattern mode specification
191#define PMS_IMO         0x08   // interrupt on match only
192#define PMS_SB         0x10   // single buffer
193#define PMS_ITB         0x20   // interrupt on two bytes
194#define PMS_PTS_MASK   0xc0   // port type select
195
196
197// port handshake specification registers
198#define PHS_DTS_MASK   0x07   // deskew time specification
199#define PHS_RWS_MASK   0x38   // request/wait specification
200#define PHS_HTS_MASK   0xc0   // handshake type specification
201
202
203// port command and status registers
204#define PCS_IOE         0x01   // interrupt on error
205#define PCS_PMF         0x02   // pattern match flag (read only)
206#define PCS_IRF         0x04   // input register full (read only)
207#define PCS_ORE         0x08   // output register empty (read only)
208#define PCS_ERR         0x10   // interrupt error (read only)
209#define PCS_IP         0x20   // interrupt pending
210#define PCS_IE         0x40   // interrupt enable
211#define PCS_IUS         0x80   // interrupt under service
212
213
214// counter/timer mode specification registers
215#define CTMS_DCS_MASK   0x03   // output duty cycle
216#define CTMS_REB      0x04   // retrigger enable bit
217#define CTMS_EDE      0x08   // external gate enable
218#define CTMS_ETE      0x10   // external trigger enable
219#define CTMS_ECE      0x20   // external count enable
220#define CTMS_EOE      0x40   // external output enable
221#define CTMS_CSC      0x80   // continuous single cycle
222
223
224// counter/timer command and status registers
225#define CTCS_CIP      0x01   // count in progress (read only)
226#define CTCS_TCB      0x02   // trigger command bit (write only - read returns 0)
227#define CTCS_GCB      0x04   // gate command bit
228#define CTCS_RCC      0x08   // read counter control (read/set only - cleared by reading CCR LSB)
229#define CTCS_ERR      0x10   // interrupt error (read only)
230#define CTCS_IP         0x20   // interrupt pending
231#define CTCS_IE         0x40   // interrupt enable
232#define CTCS_IUS      0x80   // interrupt under service
233
234
235
236//**************************************************************************
237//  DEVICE DEFINITIONS
238//**************************************************************************
239
240const device_type Z8536 = z8536_device_config::static_alloc_device_config;
241
242
243
244//**************************************************************************
245//  DEVICE CONFIGURATION
246//**************************************************************************
247
248GENERIC_DEVICE_CONFIG_SETUP(z8536, "Zilog Z8536")
249
250
251//-------------------------------------------------
252//  device_config_complete - perform any
253//  operations now that the configuration is
254//  complete
255//-------------------------------------------------
256
257void z8536_device_config::device_config_complete()
258{
259   // inherit a copy of the static data
260   const z8536_interface *intf = reinterpret_cast<const z8536_interface *>(static_config());
261   if (intf != NULL)
262      *static_cast<z8536_interface *>(this) = *intf;
263
264   // or initialize to defaults if none provided
265   else
266   {
267      memset(&m_out_int_func, 0, sizeof(m_out_int_func));
268      memset(&m_in_pa_func, 0, sizeof(m_in_pa_func));
269      memset(&m_out_pa_func, 0, sizeof(m_out_pa_func));
270      memset(&m_in_pb_func, 0, sizeof(m_in_pb_func));
271      memset(&m_out_pb_func, 0, sizeof(m_out_pb_func));
272      memset(&m_in_pc_func, 0, sizeof(m_in_pc_func));
273      memset(&m_out_pc_func, 0, sizeof(m_out_pc_func));
274   }
275}
276
277
278
279//**************************************************************************
280//  INLINE HELPERS
281//**************************************************************************
282
283//-------------------------------------------------
284//  read_register - read from register
285//-------------------------------------------------
286
287inline UINT8 z8536_device::read_register(offs_t offset)
288{
289   UINT8 data = 0;
290   
291   data = m_register[offset]; // HACK
292
293   switch (offset)
294   {
295   case PORT_A_DATA:
296      data = devcb_call_read8(&m_in_pa_func, 0);
297      break;
298     
299   case PORT_B_DATA:
300      data = devcb_call_read8(&m_in_pb_func, 0);
301      break;
302     
303   case PORT_C_DATA:
304      data = 0xf0 | (devcb_call_read8(&m_in_pc_func, 0) & 0x0f);
305      break;
306     
307   default:
308      logerror("Z8536 '%s' Unimplemented read from register %u\n", tag(), offset);
309   }
310   
311   return data;
312}
313
314
315//-------------------------------------------------
316//  read_register - masked read from register
317//-------------------------------------------------
318
319inline UINT8 z8536_device::read_register(offs_t offset, UINT8 mask)
320{
321   return read_register(offset) & mask;
322}
323
324
325//-------------------------------------------------
326//  write_register - write to register
327//-------------------------------------------------
328
329inline void z8536_device::write_register(offs_t offset, UINT8 data)
330{
331   switch (offset)
332   {
333   case MASTER_INTERRUPT_CONTROL:
334      if (data & MICR_RESET)
335      {
336         device_reset();
337      }
338      else if (m_state == STATE_RESET)
339      {
340         m_state = STATE_0;
341      }
342      break;
343     
344   case PORT_A_DATA:
345      devcb_call_write8(&m_out_pa_func, 0, data);
346      break;
347     
348   case PORT_B_DATA:
349      devcb_call_write8(&m_out_pb_func, 0, data);
350      break;
351     
352   case PORT_C_DATA:
353      {
354      UINT8 mask = (data & 0xf0) | (data >> 4);
355
356      m_output[PORT_C] = (m_output[PORT_C] & mask) | ((data & 0x0f) & (mask ^ 0xff));
357     
358      devcb_call_write8(&m_out_pc_func, 0, m_output[PORT_C]);
359      }
360      break;
361     
362   default:
363      logerror("Z8536 '%s' Unimplemented write %02x to register %u\n", tag(), data, offset);
364   }
365   
366   m_register[offset] = data; // HACK
367}
368
369
370//-------------------------------------------------
371//  write_register - masked write to register
372//-------------------------------------------------
373
374inline void z8536_device::write_register(offs_t offset, UINT8 data, UINT8 mask)
375{
376   UINT8 combined_data = (data & mask) | (m_register[offset] & (mask ^ 0xff));
377   
378   write_register(offset, combined_data);
379}
380
381
382//-------------------------------------------------
383//   count -
384//-------------------------------------------------
385
386inline void z8536_device::count(device_timer_id id)
387{
388}
389
390
391//-------------------------------------------------
392//  trigger -
393//-------------------------------------------------
394
395inline void z8536_device::trigger(device_timer_id id)
396{
397}
398
399
400//-------------------------------------------------
401//  gate -
402//-------------------------------------------------
403
404inline void z8536_device::gate(device_timer_id id)
405{
406}
407
408
409
410//**************************************************************************
411//  LIVE DEVICE
412//**************************************************************************
413
414//-------------------------------------------------
415//  z8536_device - constructor
416//-------------------------------------------------
417
418z8536_device::z8536_device(running_machine &_machine, const z8536_device_config &config)
419    : device_t(_machine, config),
420      m_config(config)
421{
422}
423
424
425//-------------------------------------------------
426//  device_start - device-specific startup
427//-------------------------------------------------
428
429void z8536_device::device_start()
430{
431   // allocate timers
432   m_timer[TIMER_1] = timer_alloc(TIMER_1);
433   m_timer[TIMER_2] = timer_alloc(TIMER_2);
434   m_timer[TIMER_3] = timer_alloc(TIMER_3);
435     
436   // resolve callbacks
437   devcb_resolve_write_line(&m_out_int_func, &m_config.m_out_int_func, this);
438   devcb_resolve_read8(&m_in_pa_func, &m_config.m_in_pa_func, this);
439   devcb_resolve_write8(&m_out_pa_func, &m_config.m_out_pa_func, this);
440   devcb_resolve_read8(&m_in_pb_func, &m_config.m_in_pb_func, this);
441   devcb_resolve_write8(&m_out_pb_func, &m_config.m_out_pb_func, this);
442   devcb_resolve_read8(&m_in_pc_func, &m_config.m_in_pc_func, this);
443   devcb_resolve_write8(&m_out_pc_func, &m_config.m_out_pc_func, this);
444}
445
446
447//-------------------------------------------------
448//  device_start - device-specific reset
449//-------------------------------------------------
450
451void z8536_device::device_reset()
452{
453   m_state = STATE_RESET;
454   
455   for (int i = 0; i < 48; i++)
456   {
457      m_register[i] = 0;
458   }
459   
460   m_register[MASTER_INTERRUPT_CONTROL] = MICR_RESET;
461   m_pointer = 0;
462}
463
464
465//-------------------------------------------------
466//  device_timer - handler timer events
467//-------------------------------------------------
468
469void z8536_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
470{
471   switch (id)
472   {
473   case TIMER_1:
474      count(TIMER_1);
475      break;
476     
477   case TIMER_2:
478      count(TIMER_2);
479      break;
480     
481   case TIMER_3:
482      count(TIMER_3);
483      break;
484   }
485}
486
487
488//-------------------------------------------------
489//  read - register read
490//-------------------------------------------------
491
492READ8_MEMBER( z8536_device::read )
493{
494   UINT8 data = 0;
495
496   if (m_state == STATE_RESET)
497   {
498      // read RESET bit
499      data = read_register(m_pointer, 0x01);
500   }
501   else
502   {
503      switch (offset & 0x03)
504      {
505      case PORT_C:
506         data = read_register(PORT_C_DATA);
507         break;
508
509      case PORT_B:
510         data = read_register(PORT_B_DATA);
511         break;
512
513      case PORT_A:
514         data = read_register(PORT_A_DATA);
515         break;
516
517      case CONTROL:
518         switch (m_state)
519         {
520         case STATE_1:
521            m_state = STATE_0;
522            // fallthru
523         case STATE_0:
524            data = read_register(m_pointer);
525            break;
526         }
527         break;
528      }
529   }
530   
531   return data;
532}
533
534
535//-------------------------------------------------
536//  write - register write
537//-------------------------------------------------
538
539WRITE8_MEMBER( z8536_device::write )
540{
541   if (m_state == STATE_RESET)
542   {
543      // write RESET bit
544      write_register(m_pointer, data, 0x01);
545   }
546   else
547   {
548      switch (offset & 0x03)
549      {
550      case PORT_C:
551         write_register(PORT_C_DATA, data);
552         break;
553
554      case PORT_B:
555         write_register(PORT_B_DATA, data);
556         break;
557
558      case PORT_A:
559         write_register(PORT_A_DATA, data);
560         break;
561
562      case CONTROL:
563         switch (m_state)
564         {
565         case STATE_0:
566            m_pointer = data;
567            m_state = STATE_1;
568            break;
569
570         case STATE_1:
571            write_register(m_pointer, data);
572            m_state = STATE_0;
573         }
574         break;
575      }
576   }
577}
578
579
580//-------------------------------------------------
581//  intack_w - interrupt acknowledge
582//-------------------------------------------------
583
584WRITE_LINE_MEMBER( z8536_device::intack_w )
585{
586}
587
588
589//-------------------------------------------------
590//  pb*_w - port B bits 0-7 write
591//-------------------------------------------------
592
593WRITE_LINE_MEMBER( z8536_device::pb0_w ) { }
594WRITE_LINE_MEMBER( z8536_device::pb1_w ) { }
595WRITE_LINE_MEMBER( z8536_device::pb2_w ) { }
596WRITE_LINE_MEMBER( z8536_device::pb3_w ) { }
597WRITE_LINE_MEMBER( z8536_device::pb4_w ) { }
598WRITE_LINE_MEMBER( z8536_device::pb5_w ) { }
599WRITE_LINE_MEMBER( z8536_device::pb6_w ) { }
600WRITE_LINE_MEMBER( z8536_device::pb7_w ) { }
601
602
603//-------------------------------------------------
604//  pc*_w - port C bits 0-3 write
605//-------------------------------------------------
606
607WRITE_LINE_MEMBER( z8536_device::pc0_w ) { }
608WRITE_LINE_MEMBER( z8536_device::pc1_w ) { }
609WRITE_LINE_MEMBER( z8536_device::pc2_w ) { }
610WRITE_LINE_MEMBER( z8536_device::pc3_w ) { }
src/mess/machine/z8536.h
r10968r10969
1/**********************************************************************
2
3    Zilog Z8536 Counter/Timer and Parallel I/O emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                    D4   1 |*    \_/     | 40  D3
11                    D5   2 |             | 39  D2
12                    D6   3 |             | 38  D1
13                    D7   4 |             | 37  D0
14                   _RD   5 |             | 36  _CE
15                   _WR   6 |             | 35  A1
16                   GND   7 |             | 34  A0
17                   PB0   8 |             | 33  PA0
18                   PB1   9 |             | 32  PA1
19                   PB2  10 |    Z8536    | 31  PA2
20                   PB3  11 |             | 30  PA3
21                   PB4  12 |             | 29  PA4
22                   PB5  13 |             | 28  PA5
23                   PB6  14 |             | 27  PA6
24                   PB7  15 |             | 26  PA7
25                  PCLK  16 |             | 25  _INTACK
26                   IEI  17 |             | 24  _INT
27                   IEO  18 |             | 23  +5 V
28                   PC0  19 |             | 22  PC3
29                   PC1  20 |_____________| 21  PC2
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __Z8536__
36#define __Z8536__
37
38#include "emu.h"
39
40
41
42//**************************************************************************
43//  MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
53#define MCFG_Z8536_ADD(_tag, _clock, _intrf) \
54   MCFG_DEVICE_ADD(_tag, Z8536, _clock) \
55   MCFG_DEVICE_CONFIG(_intrf)
56
57#define Z8536_INTERFACE(name) \
58   const z8536_interface (name)=
59
60
61
62//**************************************************************************
63//  TYPE DEFINITIONS
64//**************************************************************************
65
66// ======================> z8536_interface
67
68struct z8536_interface
69{
70   devcb_write_line      m_out_int_func;
71   
72   devcb_read8            m_in_pa_func;
73   devcb_write8         m_out_pa_func;
74   
75   devcb_read8            m_in_pb_func;
76   devcb_write8         m_out_pb_func;
77   
78   devcb_read8            m_in_pc_func;
79   devcb_write8         m_out_pc_func;
80};
81
82
83// ======================> z8536_device_config
84
85class z8536_device_config :   public device_config,
86                                public z8536_interface
87{
88    friend class z8536_device;
89
90    // construction/destruction
91    z8536_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
92
93public:
94    // allocators
95    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
96    virtual device_t *alloc_device(running_machine &machine) const;
97
98protected:
99    // device_config overrides
100    virtual void device_config_complete();
101};
102
103
104// ======================> z8536_device
105
106class z8536_device :  public device_t
107{
108    friend class z8536_device_config;
109
110    // construction/destruction
111    z8536_device(running_machine &_machine, const z8536_device_config &_config);
112
113public:
114    DECLARE_READ8_MEMBER( read );
115    DECLARE_WRITE8_MEMBER( write );
116
117   DECLARE_WRITE_LINE_MEMBER( intack_w );
118
119   DECLARE_WRITE_LINE_MEMBER( pb0_w );
120   DECLARE_WRITE_LINE_MEMBER( pb1_w );
121   DECLARE_WRITE_LINE_MEMBER( pb2_w );
122   DECLARE_WRITE_LINE_MEMBER( pb3_w );
123   DECLARE_WRITE_LINE_MEMBER( pb4_w );
124   DECLARE_WRITE_LINE_MEMBER( pb5_w );
125   DECLARE_WRITE_LINE_MEMBER( pb6_w );
126   DECLARE_WRITE_LINE_MEMBER( pb7_w );
127   DECLARE_WRITE_LINE_MEMBER( pc0_w );
128   DECLARE_WRITE_LINE_MEMBER( pc1_w );
129   DECLARE_WRITE_LINE_MEMBER( pc2_w );
130   DECLARE_WRITE_LINE_MEMBER( pc3_w );
131
132protected:
133    // device-level overrides
134    virtual void device_start();
135    virtual void device_reset();
136   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
137
138private:
139   static const device_timer_id TIMER_1 = 0;
140   static const device_timer_id TIMER_2 = 1;
141   static const device_timer_id TIMER_3 = 2;
142
143   inline UINT8 read_register(offs_t offset);
144   inline UINT8 read_register(offs_t offset, UINT8 mask);
145   inline void write_register(offs_t offset, UINT8 data);
146   inline void write_register(offs_t offset, UINT8 data, UINT8 mask);
147   
148   inline void count(device_timer_id id);
149   inline void trigger(device_timer_id id);
150   inline void gate(device_timer_id id);
151   
152   devcb_resolved_write_line      m_out_int_func;
153   
154   devcb_resolved_read8         m_in_pa_func;
155   devcb_resolved_write8         m_out_pa_func;
156   
157   devcb_resolved_read8         m_in_pb_func;
158   devcb_resolved_write8         m_out_pb_func;
159   
160   devcb_resolved_read8         m_in_pc_func;
161   devcb_resolved_write8         m_out_pc_func;
162
163   int m_state;
164   UINT8 m_register[48];
165   UINT8 m_pointer;
166   UINT8 m_input[3];
167   UINT8 m_output[3];
168   UINT8 m_buffer[3];
169
170   // timers
171   emu_timer *m_timer[3];
172
173   const z8536_device_config &m_config;
174};
175
176
177// device type definition
178extern const device_type Z8536;
179
180
181
182#endif
src/mess/machine/e0516.c
r10968r10969
1/**********************************************************************
2
3    E05-16 Real Time Clock emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "e0516.h"
12#include "machine/devhelpr.h"
13
14
15
16//**************************************************************************
17//  MACROS / CONSTANTS
18//**************************************************************************
19
20#define LOG 1
21
22
23// states
24enum
25{
26   STATE_ADDRESS = 0,
27   STATE_DATA
28};
29
30
31// registers
32enum
33{
34   SECOND = 0,
35   MINUTE,
36   HOUR,
37   DAY,
38   MONTH,
39   DAY_OF_WEEK,
40   YEAR,
41   ALL
42};
43
44
45
46//**************************************************************************
47//  DEVICE DEFINITIONS
48//**************************************************************************
49
50const device_type E0516 = e0516_device_config::static_alloc_device_config;
51
52
53
54//**************************************************************************
55//  DEVICE CONFIGURATION
56//**************************************************************************
57
58GENERIC_DEVICE_CONFIG_SETUP(e0516, "E05-16")
59
60
61
62//**************************************************************************
63//  INLINE HELPERS
64//**************************************************************************
65
66
67
68//**************************************************************************
69//  LIVE DEVICE
70//**************************************************************************
71
72//-------------------------------------------------
73//  e0516_device - constructor
74//-------------------------------------------------
75
76e0516_device::e0516_device(running_machine &_machine, const e0516_device_config &config)
77    : device_t(_machine, config),
78      m_config(config)
79{
80}
81
82
83//-------------------------------------------------
84//  device_start - device-specific startup
85//-------------------------------------------------
86
87void e0516_device::device_start()
88{
89   // allocate timers
90   m_timer = timer_alloc();
91   m_timer->adjust(attotime::from_hz(clock() / 32768), 0, attotime::from_hz(clock() / 32768));
92   
93   // state saving
94   save_item(NAME(m_cs));
95   save_item(NAME(m_clk));
96   save_item(NAME(m_data_latch));
97   save_item(NAME(m_reg_latch));
98   save_item(NAME(m_read_write));
99   save_item(NAME(m_state));
100   save_item(NAME(m_bits));
101   save_item(NAME(m_dio));
102   save_item(NAME(m_register));
103}
104
105
106//-------------------------------------------------
107//  device_start - device-specific reset
108//-------------------------------------------------
109
110void e0516_device::device_reset()
111{
112}
113
114
115//-------------------------------------------------
116//  device_timer - handler timer events
117//-------------------------------------------------
118
119void e0516_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
120{
121   m_register[SECOND]++;
122
123   if (m_register[SECOND] == 60)
124   {
125      m_register[SECOND] = 0;
126      m_register[MINUTE]++;
127   }
128
129   if (m_register[MINUTE] == 60)
130   {
131      m_register[MINUTE] = 0;
132      m_register[HOUR]++;
133   }
134
135   if (m_register[HOUR] == 24)
136   {
137      m_register[HOUR] = 0;
138      m_register[DAY]++;
139      m_register[DAY_OF_WEEK]++;
140   }
141
142   if (m_register[DAY_OF_WEEK] == 8)
143   {
144      m_register[DAY_OF_WEEK] = 1;
145   }
146
147   if (m_register[DAY] == 32)
148   {
149      m_register[DAY] = 1;
150      m_register[MONTH]++;
151   }
152
153   if (m_register[MONTH] == 13)
154   {
155      m_register[MONTH] = 1;
156      m_register[YEAR]++;
157   }
158}
159
160
161//-------------------------------------------------
162//  cs_w - chip select input
163//-------------------------------------------------
164
165WRITE_LINE_MEMBER( e0516_device::cs_w )
166{
167   m_cs = state;
168   
169   if (m_cs)
170   {
171      m_data_latch = 0;
172      m_reg_latch = 0;
173      m_bits = 0;
174      m_state = STATE_ADDRESS;
175   }
176}
177
178
179//-------------------------------------------------
180//  clk_w - serial clock input
181//-------------------------------------------------
182
183WRITE_LINE_MEMBER( e0516_device::clk_w )
184{
185   m_clk = state;
186   
187   if (m_cs || m_clk) return;
188
189   m_bits++;
190
191   if (m_state == STATE_ADDRESS)
192   {
193      if (LOG) logerror("E05-16 '%s' Command Bit %u\n", tag(), m_dio);
194
195      // command
196      m_reg_latch |= m_dio << 3;
197      m_reg_latch >>= 1;
198
199      if (m_bits == 4)
200      {
201         m_state = STATE_DATA;
202         m_bits = 0;
203
204         if (BIT(m_reg_latch, 0))
205         {
206            // load register value to data latch
207            m_data_latch = m_register[m_reg_latch >> 1];
208         }
209      }
210   }
211   else
212   {
213      // data
214      if (BIT(m_reg_latch, 0))
215      {
216         // read
217         if (LOG) logerror("E05-16 '%s' Data Bit OUT %u\n", tag(), m_dio);
218         
219         m_dio = BIT(m_data_latch, 0);
220         m_data_latch >>= 1;
221      }
222      else
223      {
224         // write
225         if (LOG) logerror("E05-16 '%s' Data Bit IN %u\n", tag(), m_dio);
226
227         m_data_latch |= m_dio << 7;
228         m_data_latch >>= 1;
229      }
230
231      if (m_bits == 8)
232      {
233         m_state = STATE_ADDRESS;
234         m_bits = 0;
235
236         if (!BIT(m_reg_latch, 0))
237         {
238            // write latched data to register
239            m_register[m_reg_latch >> 1] = m_data_latch;
240         }
241      }
242   }
243}
244
245
246//-------------------------------------------------
247//  dio_w - serial data input
248//-------------------------------------------------
249
250WRITE_LINE_MEMBER( e0516_device::dio_w )
251{
252   m_dio = state;
253}
254
255
256//-------------------------------------------------
257//  do_r - serial data output
258//-------------------------------------------------
259
260READ_LINE_MEMBER( e0516_device::dio_r )
261{
262   return m_dio;
263}
src/mess/machine/e0516.h
r10968r10969
1/**********************************************************************
2
3    E05-16 Real Time Clock emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                  Vdd1   1 |*    \_/     | 16  Vdd2
11                OSC IN   2 |             | 15  Clk
12               OSC OUT   3 |             | 14  XOUT
13                 _STOP   4 |   E05-16    | 13  DI/O
14                _RESET   5 |   E050-16   | 12  _SEC
15               _OUTSEL   6 |             | 11  _MIN
16                  _DAY   7 |             | 10  _HRS
17                   Vss   8 |_____________| 9   _CS
18
19**********************************************************************/
20
21#pragma once
22
23#ifndef __E0516__
24#define __E0516__
25
26#include "emu.h"
27
28
29
30//**************************************************************************
31//  MACROS / CONSTANTS
32//**************************************************************************
33
34
35
36
37//**************************************************************************
38//  INTERFACE CONFIGURATION MACROS
39//**************************************************************************
40
41#define MCFG_E0516_ADD(_tag, _clock) \
42   MCFG_DEVICE_ADD(_tag, E0516, _clock)
43
44
45
46//**************************************************************************
47//  TYPE DEFINITIONS
48//**************************************************************************
49
50
51// ======================> e0516_device_config
52
53class e0516_device_config :   public device_config
54{
55    friend class e0516_device;
56
57    // construction/destruction
58    e0516_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
59
60public:
61    // allocators
62    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
63    virtual device_t *alloc_device(running_machine &machine) const;
64
65protected:
66};
67
68
69// ======================> e0516_device
70
71class e0516_device :  public device_t
72{
73    friend class e0516_device_config;
74
75    // construction/destruction
76    e0516_device(running_machine &_machine, const e0516_device_config &_config);
77
78public:
79    DECLARE_WRITE_LINE_MEMBER( cs_w );
80    DECLARE_WRITE_LINE_MEMBER( clk_w );
81    DECLARE_WRITE_LINE_MEMBER( dio_w );
82    DECLARE_READ_LINE_MEMBER( dio_r );
83
84protected:
85    // device-level overrides
86    virtual void device_start();
87    virtual void device_reset();
88   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
89
90private:
91   int m_cs;                  // chip select
92   int m_clk;                  // clock
93   int m_data_latch;            // data latch
94   int m_reg_latch;            // register latch
95   int m_read_write;            // read/write data
96   int m_state;               // state
97   int m_bits;                  // number of bits transferred
98   int m_dio;                  // data pin
99
100   UINT8 m_register[8];         // registers
101
102   // timers
103   emu_timer *m_timer;
104
105   const e0516_device_config &m_config;
106};
107
108
109// device type definition
110extern const device_type E0516;
111
112
113
114#endif
src/mess/machine/i8355.c
r10968r10969
1/**********************************************************************
2
3    Intel 8355 - 16,384-Bit ROM with I/O emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "i8355.h"
12
13
14
15//**************************************************************************
16//  MACROS / CONSTANTS
17//**************************************************************************
18
19#define LOG 0
20
21enum
22{
23   REGISTER_PORT_A = 0,
24   REGISTER_PORT_B,
25   REGISTER_PORT_A_DDR,
26   REGISTER_PORT_B_DDR
27};
28
29enum
30{
31   PORT_A = 0,
32   PORT_B,
33   PORT_COUNT
34};
35
36
37
38//**************************************************************************
39//  GLOBAL VARIABLES
40//**************************************************************************
41
42// devices
43const device_type I8355 = i8355_device_config::static_alloc_device_config;
44
45
46// default address map
47static ADDRESS_MAP_START( i8355, AS_0, 8 )
48   AM_RANGE(0x000, 0x7ff) AM_ROM
49ADDRESS_MAP_END
50
51
52
53//**************************************************************************
54//  DEVICE CONFIGURATION
55//**************************************************************************
56
57//-------------------------------------------------
58//  i8355_device_config - constructor
59//-------------------------------------------------
60
61i8355_device_config::i8355_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
62   : device_config(mconfig, static_alloc_device_config, "Intel 8355", tag, owner, clock),
63     device_config_memory_interface(mconfig, *this),
64     m_space_config("ram", ENDIANNESS_LITTLE, 8, 11, 0, NULL, *ADDRESS_MAP_NAME(i8355))
65{
66}
67
68
69//-------------------------------------------------
70//  static_alloc_device_config - allocate a new
71//  configuration object
72//-------------------------------------------------
73
74device_config *i8355_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
75{
76   return global_alloc(i8355_device_config(mconfig, tag, owner, clock));
77}
78
79
80//-------------------------------------------------
81//  alloc_device - allocate a new device object
82//-------------------------------------------------
83
84device_t *i8355_device_config::alloc_device(running_machine &machine) const
85{
86   return auto_alloc(&machine, i8355_device(machine, *this));
87}
88
89
90//-------------------------------------------------
91//  memory_space_config - return a description of
92//  any address spaces owned by this device
93//-------------------------------------------------
94
95const address_space_config *i8355_device_config::memory_space_config(address_spacenum spacenum) const
96{
97   return (spacenum == AS_0) ? &m_space_config : NULL;
98}
99
100
101//-------------------------------------------------
102//  device_config_complete - perform any
103//  operations now that the configuration is
104//  complete
105//-------------------------------------------------
106
107void i8355_device_config::device_config_complete()
108{
109   // inherit a copy of the static data
110   const i8355_interface *intf = reinterpret_cast<const i8355_interface *>(static_config());
111   if (intf != NULL)
112      *static_cast<i8355_interface *>(this) = *intf;
113
114   // or initialize to defaults if none provided
115   else
116   {
117      memset(&in_pa_func, 0, sizeof(in_pa_func));
118      memset(&out_pa_func, 0, sizeof(out_pa_func));
119      memset(&in_pb_func, 0, sizeof(in_pb_func));
120      memset(&out_pb_func, 0, sizeof(out_pb_func));
121   }
122}
123
124
125
126//**************************************************************************
127//  INLINE HELPERS
128//**************************************************************************
129
130//-------------------------------------------------
131//  read_port - read from input port
132//-------------------------------------------------
133
134inline UINT8 i8355_device::read_port(int port)
135{
136   UINT8 data = m_output[port] & m_ddr[port];
137
138   if (m_ddr[port] != 0xff)
139   {
140      data |= devcb_call_read8(&m_in_port_func[port], 0) & ~m_ddr[port];
141   }
142
143   return data;
144}
145
146
147//-------------------------------------------------
148//  write_port - write to output port
149//-------------------------------------------------
150
151inline void i8355_device::write_port(int port, UINT8 data)
152{
153   m_output[port] = data;
154
155   devcb_call_write8(&m_out_port_func[port], 0, m_output[port] & m_ddr[port]);
156}
157
158
159
160//**************************************************************************
161//  LIVE DEVICE
162//**************************************************************************
163
164//-------------------------------------------------
165//  i8355_device - constructor
166//-------------------------------------------------
167
168i8355_device::i8355_device(running_machine &_machine, const i8355_device_config &config)
169    : device_t(_machine, config),
170     device_memory_interface(_machine, config, *this),
171      m_config(config)
172{
173
174}
175
176
177//-------------------------------------------------
178//  device_start - device-specific startup
179//-------------------------------------------------
180
181void i8355_device::device_start()
182{
183   // resolve callbacks
184   devcb_resolve_read8(&m_in_port_func[0], &m_config.in_pa_func, this);
185   devcb_resolve_read8(&m_in_port_func[1], &m_config.in_pb_func, this);
186   devcb_resolve_write8(&m_out_port_func[0], &m_config.out_pa_func, this);
187   devcb_resolve_write8(&m_out_port_func[1], &m_config.out_pb_func, this);
188
189   // register for state saving
190   save_item(NAME(m_output));
191   save_item(NAME(m_ddr));
192}
193
194
195//-------------------------------------------------
196//  device_reset - device-specific reset
197//-------------------------------------------------
198
199void i8355_device::device_reset()
200{
201   // set ports to input mode
202   m_ddr[PORT_A] = 0;
203   m_ddr[PORT_B] = 0;
204}
205
206
207//-------------------------------------------------
208//  io_r - register read
209//-------------------------------------------------
210
211READ8_MEMBER( i8355_device::io_r )
212{
213   int port = offset & 0x01;
214
215   UINT8 data = 0;
216
217   switch (offset & 0x03)
218   {
219   case REGISTER_PORT_A:
220   case REGISTER_PORT_B:
221      data = read_port(port);
222      break;
223
224   case REGISTER_PORT_A_DDR:
225   case REGISTER_PORT_B_DDR:
226      // write only
227      break;
228   }
229
230   return data;
231}
232
233
234//-------------------------------------------------
235//  io_w - register write
236//-------------------------------------------------
237
238WRITE8_MEMBER( i8355_device::io_w )
239{
240   int port = offset & 0x01;
241
242   switch (offset & 0x03)
243   {
244   case REGISTER_PORT_A:
245   case REGISTER_PORT_B:
246      if (LOG) logerror("I8355 '%s' Port %c Write %02x\n", tag(), 'A' + port, data);
247
248      write_port(port, data);
249      break;
250
251   case REGISTER_PORT_A_DDR:
252   case REGISTER_PORT_B_DDR:
253      if (LOG) logerror("I8355 '%s' Port %c DDR: %02x\n", tag(), 'A' + port, data);
254
255      m_ddr[port] = data;
256      write_port(port, data);
257      break;
258   }
259}
260
261
262//-------------------------------------------------
263//  memory_r - internal ROM read
264//-------------------------------------------------
265
266READ8_MEMBER( i8355_device::memory_r )
267{
268   return this->space()->read_byte(offset);
269}
src/mess/machine/i8355.h
r10968r10969
1/**********************************************************************
2
3    Intel 8355 - 16,384-Bit ROM with I/O emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                  _CE1   1 |*    \_/     | 40  Vcc
11                   CE2   2 |             | 39  PB7
12                   CLK   3 |             | 38  PB6
13                 RESET   4 |             | 37  PB5
14                  N.C.   5 |             | 36  PB4
15                 READY   6 |             | 35  PB3
16                 IO/_M   7 |             | 34  PB2
17                  _IOR   8 |             | 33  PB1
18                   _RD   9 |             | 32  PB0
19                  _IOW  10 |    8355     | 31  PA7
20                   ALE  11 |    8355-2   | 30  PA6
21                   AD0  12 |             | 29  PA5
22                   AD1  13 |             | 28  PA4
23                   AD2  14 |             | 27  PA3
24                   AD3  15 |             | 26  PA2
25                   AD4  16 |             | 25  PA1
26                   AD5  17 |             | 24  PA0
27                   AD6  18 |             | 23  A10
28                   AD7  19 |             | 22  A9
29                   Vss  20 |_____________| 21  A8
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __I8355__
36#define __I8355__
37
38#include "emu.h"
39
40
41
42///*************************************************************************
43//  MACROS / CONSTANTS
44///*************************************************************************
45
46
47
48
49///*************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51///*************************************************************************
52
53#define MCFG_I8355_ADD(_tag, _clock, _config) \
54   MCFG_DEVICE_ADD((_tag), I8355, _clock)   \
55   MCFG_DEVICE_CONFIG(_config)
56
57#define I8355_INTERFACE(name) \
58   const i8355_interface (name) =
59
60
61
62///*************************************************************************
63//  TYPE DEFINITIONS
64///*************************************************************************
65
66// ======================> i8355_interface
67
68struct i8355_interface
69{
70   devcb_read8            in_pa_func;
71   devcb_write8         out_pa_func;
72
73   devcb_read8            in_pb_func;
74   devcb_write8         out_pb_func;
75};
76
77
78
79// ======================> i8355_device_config
80
81class i8355_device_config :   public device_config,
82                        public device_config_memory_interface,
83                                public i8355_interface
84{
85    friend class i8355_device;
86
87    // construction/destruction
88    i8355_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
89
90public:
91    // allocators
92    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
93    virtual device_t *alloc_device(running_machine &machine) const;
94
95protected:
96   // device_config overrides
97   virtual void device_config_complete();
98
99   // device_config_memory_interface overrides
100   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
101
102    // address space configurations
103   const address_space_config      m_space_config;
104};
105
106
107
108// ======================> i8355_device
109
110class i8355_device :   public device_t,
111                  public device_memory_interface
112{
113    friend class i8355_device_config;
114
115    // construction/destruction
116    i8355_device(running_machine &_machine, const i8355_device_config &_config);
117
118public:
119    DECLARE_READ8_MEMBER( io_r );
120    DECLARE_WRITE8_MEMBER( io_w );
121
122    DECLARE_READ8_MEMBER( memory_r );
123    DECLARE_WRITE8_MEMBER( memory_w );
124
125protected:
126    // device-level overrides
127    virtual void device_start();
128    virtual void device_reset();
129
130   inline UINT8 read_port(int port);
131   inline void write_port(int port, UINT8 data);
132
133private:
134   devcb_resolved_read8      m_in_port_func[2];
135   devcb_resolved_write8      m_out_port_func[2];
136
137   // registers
138   UINT8 m_output[2];         // output latches
139   UINT8 m_ddr[2];            // DDR latches
140
141   const i8355_device_config &m_config;
142};
143
144
145// device type definition
146extern const device_type I8355;
147
148
149
150#endif
src/mess/video/crt9007.c
r10968r10969
1/**********************************************************************
2
3    SMC CRT9007 CRT Video Processor and Controller (VPAC) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10/*
11
12    TODO:
13
14    - cursor timer
15    - interrupts
16        - light pen
17        - frame timer
18    - non-DMA mode
19    - DMA mode
20    - cursor/blank skew
21    - sequential breaks
22    - interlaced mode
23    - smooth scroll
24    - page blank
25    - double height cursor
26    - row attributes
27    - pin configuration
28    - operation modes 0,4,7
29    - address modes 1,2,3
30    - light pen
31    - state saving
32
33*/
34
35#include "emu.h"
36#include "crt9007.h"
37
38
39
40//**************************************************************************
41//  MACROS / CONSTANTS
42//**************************************************************************
43
44#define LOG 1
45
46#define HAS_VALID_PARAMETERS \
47   (m_reg[0x00] && m_reg[0x01] && m_reg[0x07] && m_reg[0x08] && m_reg[0x09])
48
49#define CHARACTERS_PER_HORIZONTAL_PERIOD \
50   m_reg[0x00]
51
52#define CHARACTERS_PER_DATA_ROW \
53   (m_reg[0x01] + 1)
54
55#define HORIZONTAL_DELAY \
56   m_reg[0x02]
57
58#define HORIZONTAL_SYNC_WIDTH \
59   m_reg[0x03]
60
61#define VERTICAL_SYNC_WIDTH \
62   m_reg[0x04]
63
64#define VERTICAL_DELAY \
65   (m_reg[0x05] - 1)
66
67#define PIN_CONFIGURATION \
68   (m_reg[0x06] >> 6)
69
70#define CURSOR_SKEW \
71   ((m_reg[0x06] >> 3) & 0x07)
72
73#define BLANK_SKEW \
74   (m_reg[0x06] & 0x07)
75
76#define VISIBLE_DATA_ROWS_PER_FRAME \
77   (m_reg[0x07] + 1)
78
79#define SCAN_LINES_PER_DATA_ROW \
80   ((m_reg[0x08] & 0x1f) + 1)
81
82#define SCAN_LINES_PER_FRAME \
83   (((m_reg[0x08] << 3) & 0x0700) | m_reg[0x09])
84
85#define DMA_BURST_COUNT \
86   ((m_reg[0x0a] & 0x0f) + 1)
87
88#define DMA_BURST_DELAY \
89   ((((m_reg[0x0a] >> 4) & 0x07) + 1) % 8)
90
91#define DMA_DISABLE \
92   BIT(m_reg[0x0a], 7)
93
94#define SINGLE_HEIGHT_CURSOR \
95   BIT(m_reg[0x0b], 0)
96
97#define OPERATION_MODE \
98   ((m_reg[0x0b] >> 1) & 0x07)
99
100#define INTERLACE_MODE \
101   ((m_reg[0x0b] >> 4) & 0x03)
102
103#define PAGE_BLANK \
104   BIT(m_reg[0x0b], 6)
105
106#define TABLE_START \
107   (((m_reg[0x0d] << 8) & 0x3f00) | m_reg[0x0c])
108
109#define ADDRESS_MODE \
110   ((m_reg[0x0d] >> 6) & 0x03)
111
112#define AUXILIARY_ADDRESS_1 \
113   (((m_reg[0x0f] << 8) & 0x3f00) | m_reg[0x0e])
114
115#define ROW_ATTRIBUTES_1 \
116   ((m_reg[0x0f] >> 6) & 0x03)
117
118#define SEQUENTIAL_BREAK_1 \
119   m_reg[0x10]
120
121#define SEQUENTIAL_BREAK_2 \
122   m_reg[0x12]
123
124#define DATA_ROW_START \
125   m_reg[0x11]
126
127#define DATA_ROW_END \
128   m_reg[0x12]
129
130#define AUXILIARY_ADDRESS_2 \
131   (((m_reg[0x14] << 8) & 0x3f00) | m_reg[0x13])
132
133#define ROW_ATTRIBUTES_2 \
134   ((m_reg[0x14] >> 6) & 0x03)
135
136#define SMOOTH_SCROLL_OFFSET \
137   ((m_reg[0x17] >> 1) & 0x3f)
138
139#define SMOOTH_SCROLL_OFFSET_OVERFLOW \
140   BIT(m_reg[0x17], 7)
141
142#define VERTICAL_CURSOR \
143   m_reg[0x18]
144
145#define HORIZONTAL_CURSOR \
146   m_reg[0x19]
147
148#define INTERRUPT_ENABLE \
149   m_reg[0x1a]
150
151#define FRAME_TIMER \
152   BIT(m_reg[0x1a], 0)
153
154#define LIGHT_PEN_INTERRUPT \
155   BIT(m_reg[0x1a], 5)
156
157#define VERTICAL_RETRACE_INTERRUPT \
158   BIT(m_reg[0x1a], 6)
159
160#define VERTICAL_LIGHT_PEN \
161   m_reg[0x3b]
162
163#define HORIZONTAL_LIGHT_PEN \
164   m_reg[0x3c]
165
166
167// interlace
168enum
169{
170   NON_INTERLACED = 0,
171   ENHANCED_VIDEO_INTERFACE,
172   NORMAL_VIDEO_INTERFACE,
173};
174
175
176// operation modes
177enum
178{
179   OPERATION_MODE_REPETITIVE_MEMORY_ADDRESSING = 0,   // not implemented
180   OPERATION_MODE_DOUBLE_ROW_BUFFER = 1,
181   OPERATION_MODE_SINGLE_ROW_BUFFER = 4,            // not implemented
182   OPERATION_MODE_ATTRIBUTE_ASSEMBLE = 7            // not implemented
183};
184
185
186// addressing modes
187enum
188{
189   ADDRESS_MODE_SEQUENTIAL_ADDRESSING = 0,
190   ADDRESS_MODE_SEQUENTIAL_ROLL_ADDRESSING,         // not implemented
191   ADDRESS_MODE_CONTIGUOUS_ROW_TABLE,               // not implemented
192   ADDRESS_MODE_LINKED_LIST_ROW_TABLE               // not implemented
193};
194
195
196// interrupt enable register bits
197const int IE_VERTICAL_RETRACE         = 0x40;
198const int IE_LIGHT_PEN               = 0x20;
199const int IE_FRAME_TIMER            = 0x01;
200
201// status register bits
202const int STATUS_INTERRUPT_PENDING      = 0x80;
203const int STATUS_VERTICAL_RETRACE      = 0x40;
204const int STATUS_LIGHT_PEN_UPDATE      = 0x20;
205const int STATUS_ODD_EVEN            = 0x04;
206const int STATUS_FRAME_TIMER_OCCURRED   = 0x01;
207
208
209
210//**************************************************************************
211//  GLOBAL VARIABLES
212//**************************************************************************
213
214// devices
215const device_type CRT9007 = crt9007_device_config::static_alloc_device_config;
216
217
218// default address map
219static ADDRESS_MAP_START( crt9007, AS_0, 8 )
220   AM_RANGE(0x0000, 0x3fff) AM_RAM
221ADDRESS_MAP_END
222
223
224
225//**************************************************************************
226//  DEVICE CONFIGURATION
227//**************************************************************************
228
229//-------------------------------------------------
230//  crt9007_device_config - constructor
231//-------------------------------------------------
232
233crt9007_device_config::crt9007_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
234   : device_config(mconfig, static_alloc_device_config, "SMC CRT9007", tag, owner, clock),
235     device_config_memory_interface(mconfig, *this),
236     m_space_config("videoram", ENDIANNESS_LITTLE, 8, 14, 0, NULL, *ADDRESS_MAP_NAME(crt9007))
237{
238}
239
240
241//-------------------------------------------------
242//  static_alloc_device_config - allocate a new
243//  configuration object
244//-------------------------------------------------
245
246device_config *crt9007_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
247{
248   return global_alloc(crt9007_device_config(mconfig, tag, owner, clock));
249}
250
251
252//-------------------------------------------------
253//  alloc_device - allocate a new device object
254//-------------------------------------------------
255
256device_t *crt9007_device_config::alloc_device(running_machine &machine) const
257{
258   return auto_alloc(&machine, crt9007_device(machine, *this));
259}
260
261
262//-------------------------------------------------
263//  memory_space_config - return a description of
264//  any address spaces owned by this device
265//-------------------------------------------------
266
267const address_space_config *crt9007_device_config::memory_space_config(address_spacenum spacenum) const
268{
269   return (spacenum == AS_0) ? &m_space_config : NULL;
270}
271
272
273//-------------------------------------------------
274//  device_config_complete - perform any
275//  operations now that the configuration is
276//  complete
277//-------------------------------------------------
278
279void crt9007_device_config::device_config_complete()
280{
281   // inherit a copy of the static data
282   const crt9007_interface *intf = reinterpret_cast<const crt9007_interface *>(static_config());
283   if (intf != NULL)
284      *static_cast<crt9007_interface *>(this) = *intf;
285
286   // or initialize to defaults if none provided
287   else
288   {
289      memset(&out_int_func, 0, sizeof(out_int_func));
290      memset(&out_dmar_func, 0, sizeof(out_dmar_func));
291      memset(&out_vs_func, 0, sizeof(out_vs_func));
292      memset(&out_hs_func, 0, sizeof(out_hs_func));
293      memset(&out_vlt_func, 0, sizeof(out_vlt_func));
294      memset(&out_curs_func, 0, sizeof(out_curs_func));
295      memset(&out_drb_func, 0, sizeof(out_drb_func));
296      memset(&out_cblank_func, 0, sizeof(out_cblank_func));
297      memset(&out_slg_func, 0, sizeof(out_slg_func));
298      memset(&out_sld_func, 0, sizeof(out_sld_func));
299   }
300}
301
302
303
304//**************************************************************************
305//  INLINE HELPERS
306//**************************************************************************
307
308//-------------------------------------------------
309//  readbyte - read a byte at the given address
310//-------------------------------------------------
311
312inline UINT8 crt9007_device::readbyte(offs_t address)
313{
314   return space()->read_byte(address);
315}
316
317
318//-------------------------------------------------
319//  trigger_interrupt -
320//-------------------------------------------------
321
322inline void crt9007_device::trigger_interrupt(int line)
323{
324   if (INTERRUPT_ENABLE & line)
325   {
326      int status = m_status;
327
328      m_status |= STATUS_INTERRUPT_PENDING | line;
329
330      if (!(status & STATUS_INTERRUPT_PENDING))
331      {
332         if (LOG) logerror("CRT9007 '%s' INT 1\n", tag());
333         devcb_call_write_line(&m_out_int_func, ASSERT_LINE);
334      }
335   }
336}
337
338
339//-------------------------------------------------
340//  update_cblank_line -
341//-------------------------------------------------
342
343inline void crt9007_device::update_cblank_line()
344{
345   int x = m_screen->hpos();
346   int y = m_screen->vpos();
347
348   // composite blank
349   int cblank = !(m_hs & m_vs);
350
351   if (m_cblank != cblank)
352   {
353      m_cblank = cblank;
354
355      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CBLANK %u\n", tag(), y, x, m_cblank);
356
357      devcb_call_write_line(&m_out_cblank_func, m_cblank);
358   }
359}
360
361
362//-------------------------------------------------
363//  update_hsync_timer -
364//-------------------------------------------------
365
366inline void crt9007_device::update_hsync_timer(int state)
367{
368   int y = m_screen->vpos();
369
370   int next_x = state ? m_hsync_start : m_hsync_end;
371   int next_y = state ? (y + 1) % SCAN_LINES_PER_FRAME : y;
372
373   attotime duration = m_screen->time_until_pos(next_y, next_x);
374
375   m_hsync_timer->adjust(duration, !state);
376}
377
378
379//-------------------------------------------------
380//  update_vsync_timer -
381//-------------------------------------------------
382
383inline void crt9007_device::update_vsync_timer(int state)
384{
385   int next_y = state ? m_vsync_start : m_vsync_end;
386
387   attotime duration = m_screen->time_until_pos(next_y, 0);
388
389   m_vsync_timer->adjust(duration, !state);
390}
391
392
393//-------------------------------------------------
394//  update_vlt_timer -
395//-------------------------------------------------
396
397inline void crt9007_device::update_vlt_timer(int state)
398{
399   // this signal is active during all visible scan lines and during the horizontal trace at vertical retrace
400   int y = m_screen->vpos();
401
402   int next_x = state ? m_vlt_end : m_vlt_start;
403   int next_y = state ? y : ((y == m_vlt_bottom) ? 0 : (y + 1));
404
405   attotime duration = m_screen->time_until_pos(next_y, next_x);
406
407   m_vlt_timer->adjust(duration, !state);
408}
409
410
411//-------------------------------------------------
412//  update_curs_timer -
413//-------------------------------------------------
414
415inline void crt9007_device::update_curs_timer(int state)
416{
417   // this signal is active for 1 character time for all scanlines within the data row
418   // TODO
419}
420
421
422//-------------------------------------------------
423//  update_drb_timer -
424//-------------------------------------------------
425
426inline void crt9007_device::update_drb_timer(int state)
427{
428   // this signal is active for 1 full scan line (VLT edge to edge) at the top scan line of each new row
429   // there is 1 extra DRB signal during the 1st scanline of the vertical retrace interval
430   int y = m_screen->vpos();
431
432   int next_x = m_vlt_end;
433   int next_y = y ? y + 1 : y;
434
435   if (state)
436   {
437      if (y == 0)
438      {
439         next_y = VERTICAL_DELAY - 1;
440      }
441      else if (y == m_drb_bottom)
442      {
443         next_x = 0;
444         next_y = 0;
445      }
446      else
447      {
448         next_y = y + SCAN_LINES_PER_DATA_ROW - 1;
449      }
450   }
451
452   attotime duration = m_screen->time_until_pos(next_y, next_x);
453
454   m_drb_timer->adjust(duration, !state);
455}
456
457
458//-------------------------------------------------
459//  update_dma_timer -
460//-------------------------------------------------
461
462inline void crt9007_device::update_dma_timer()
463{
464   // TODO
465}
466
467
468//-------------------------------------------------
469//  recompute_parameters -
470//-------------------------------------------------
471
472inline void crt9007_device::recompute_parameters()
473{
474   // check that necessary registers have been loaded
475   if (!HAS_VALID_PARAMETERS) return;
476
477   // screen dimensions
478   int horiz_pix_total = CHARACTERS_PER_HORIZONTAL_PERIOD * m_hpixels_per_column;
479   int vert_pix_total = SCAN_LINES_PER_FRAME;
480
481   // refresh rate
482   attoseconds_t refresh = HZ_TO_ATTOSECONDS(clock()) * horiz_pix_total * vert_pix_total;
483
484   // horizontal sync
485   m_hsync_start = 0;
486   m_hsync_end = HORIZONTAL_SYNC_WIDTH * m_hpixels_per_column;
487
488   // visible line time
489   m_vlt_start = HORIZONTAL_DELAY * m_hpixels_per_column;
490   m_vlt_end = (HORIZONTAL_DELAY + CHARACTERS_PER_DATA_ROW) * m_hpixels_per_column;
491   m_vlt_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - 1;
492
493   // data row boundary
494   m_drb_bottom = VERTICAL_DELAY + (VISIBLE_DATA_ROWS_PER_FRAME * SCAN_LINES_PER_DATA_ROW) - SCAN_LINES_PER_DATA_ROW;
495
496   // vertical sync
497   m_vsync_start = 0;
498   m_vsync_end = VERTICAL_SYNC_WIDTH;
499
500   // visible area
501   rectangle visarea;
502
503   visarea.min_x = m_hsync_end;
504   visarea.max_x = horiz_pix_total - 1;
505
506   visarea.min_y = m_vsync_end;
507   visarea.max_y = vert_pix_total - 1;
508
509   if (LOG)
510   {
511      logerror("CRT9007 '%s' Screen: %u x %u @ %f Hz\n", tag(), horiz_pix_total, vert_pix_total, 1 / ATTOSECONDS_TO_DOUBLE(refresh));
512      logerror("CRT9007 '%s' Visible Area: (%u, %u) - (%u, %u)\n", tag(), visarea.min_x, visarea.min_y, visarea.max_x, visarea.max_y);
513   }
514
515   m_screen->configure(horiz_pix_total, vert_pix_total, visarea, refresh);
516
517   m_hsync_timer->adjust(m_screen->time_until_pos(0, 0));
518   m_vsync_timer->adjust(m_screen->time_until_pos(0, 0));
519   m_vlt_timer->adjust(m_screen->time_until_pos(0, m_vlt_start), 1);
520   m_drb_timer->adjust(m_screen->time_until_pos(0, 0));
521}
522
523
524//**************************************************************************
525//  LIVE DEVICE
526//**************************************************************************
527
528//-------------------------------------------------
529//  crt9007_device - constructor
530//-------------------------------------------------
531
532crt9007_device::crt9007_device(running_machine &_machine, const crt9007_device_config &config)
533    : device_t(_machine, config),
534     device_memory_interface(_machine, config, *this),
535      m_config(config)
536{
537   for (int i = 0; i < 0x3d; i++)
538      m_reg[i] = 0;
539}
540
541
542//-------------------------------------------------
543//  device_start - device-specific startup
544//-------------------------------------------------
545
546void crt9007_device::device_start()
547{
548   // allocate timers
549   m_hsync_timer = timer_alloc(TIMER_HSYNC);
550   m_vsync_timer = timer_alloc(TIMER_VSYNC);
551   m_vlt_timer = timer_alloc(TIMER_VLT);
552   m_curs_timer = timer_alloc(TIMER_CURS);
553   m_drb_timer = timer_alloc(TIMER_DRB);
554   m_dma_timer = timer_alloc(TIMER_DMA);
555
556   // resolve callbacks
557   devcb_resolve_write_line(&m_out_int_func, &m_config.out_int_func, this);
558   devcb_resolve_write_line(&m_out_dmar_func, &m_config.out_dmar_func, this);
559   devcb_resolve_write_line(&m_out_hs_func, &m_config.out_hs_func, this);
560   devcb_resolve_write_line(&m_out_vs_func, &m_config.out_vs_func, this);
561   devcb_resolve_write_line(&m_out_vlt_func, &m_config.out_vlt_func, this);
562   devcb_resolve_write_line(&m_out_curs_func, &m_config.out_curs_func, this);
563   devcb_resolve_write_line(&m_out_drb_func, &m_config.out_drb_func, this);
564   devcb_resolve_write_line(&m_out_cblank_func, &m_config.out_cblank_func, this);
565   devcb_resolve_write_line(&m_out_slg_func, &m_config.out_slg_func, this);
566   devcb_resolve_write_line(&m_out_sld_func, &m_config.out_sld_func, this);
567
568   // get the screen device
569   m_screen = machine->device<screen_device>(m_config.screen_tag);
570   assert(m_screen != NULL);
571
572   // set horizontal pixels per column
573   m_hpixels_per_column = m_config.hpixels_per_column;
574
575   // register for state saving
576//  state_save_register_device_item(this, 0, );
577}
578
579
580//-------------------------------------------------
581//  device_reset - device-specific reset
582//-------------------------------------------------
583
584void crt9007_device::device_reset()
585{
586   m_disp = 0;
587
588   // HS = 1
589   devcb_call_write_line(&m_out_hs_func, 1);
590
591   // VS = 1
592   devcb_call_write_line(&m_out_vs_func, 1);
593
594   // CBLANK = 1
595   devcb_call_write_line(&m_out_cblank_func, 0);
596
597   // CURS = 0
598   devcb_call_write_line(&m_out_curs_func, 0);
599
600   // VLT = 0
601   devcb_call_write_line(&m_out_vlt_func, 0);
602
603   // DRB = 1
604   devcb_call_write_line(&m_out_drb_func, 1);
605
606   // INT = 0
607   devcb_call_write_line(&m_out_int_func, CLEAR_LINE);
608
609   // 28 (DMAR) = 0
610   devcb_call_write_line(&m_out_dmar_func, CLEAR_LINE);
611
612   // 29 (WBEN) = 0
613
614   // 30 (SLG) = 0
615   devcb_call_write_line(&m_out_slg_func, 0);
616
617   // 31 (SLD) = 0
618   devcb_call_write_line(&m_out_sld_func, 0);
619
620   // 32 (LPSTB) = 0
621}
622
623
624//-------------------------------------------------
625//  device_clock_changed - handle clock change
626//-------------------------------------------------
627
628void crt9007_device::device_clock_changed()
629{
630   recompute_parameters();
631}
632
633
634//-------------------------------------------------
635//  device_timer - handle timer events
636//-------------------------------------------------
637
638void crt9007_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
639{
640   int x = m_screen->hpos();
641   int y = m_screen->vpos();
642
643   switch (id)
644   {
645   case TIMER_HSYNC:
646      m_hs = param;
647
648      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : HS %u\n", tag(), y, x, m_hs);
649
650      devcb_call_write_line(&m_out_hs_func, m_hs);
651
652      update_cblank_line();
653
654      update_hsync_timer(param);
655      break;
656
657   case TIMER_VSYNC:
658      m_vs = param;
659
660      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VS %u\n", tag(), y, x, m_vs);
661
662      devcb_call_write_line(&m_out_vs_func, param);
663
664      if (m_vs)
665      {
666         // reset all other bits except Light Pen Update to logic 0
667         m_status &= STATUS_LIGHT_PEN_UPDATE;
668      }
669      else
670      {
671         trigger_interrupt(IE_VERTICAL_RETRACE);
672
673         update_cblank_line();
674      }
675
676      update_vsync_timer(param);
677      break;
678
679   case TIMER_VLT:
680      m_vlt = param;
681
682      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : VLT %u\n", tag(), y, x, m_vlt);
683
684      devcb_call_write_line(&m_out_vlt_func, param);
685
686      update_vlt_timer(param);
687      break;
688
689   case TIMER_CURS:
690      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : CURS %u\n", tag(), y, x, param);
691
692      devcb_call_write_line(&m_out_curs_func, param);
693
694      update_curs_timer(param);
695      break;
696
697   case TIMER_DRB:
698      m_drb = param;
699
700      if (LOG) logerror("CRT9007 '%s' y %03u x %04u : DRB %u\n", tag(), y, x, m_drb);
701
702      devcb_call_write_line(&m_out_drb_func, param);
703
704      if (!m_drb && !DMA_DISABLE)
705      {
706         // start DMA burst sequence
707         m_dma_count = CHARACTERS_PER_DATA_ROW;
708         m_dma_burst = DMA_BURST_COUNT ? (DMA_BURST_COUNT * 4) : CHARACTERS_PER_DATA_ROW;
709         m_dma_delay = DMA_BURST_DELAY;
710         m_dmar = 1;
711
712         if (LOG) logerror("CRT9007 '%s' DMAR 1\n", tag());
713         devcb_call_write_line(&m_out_dmar_func, ASSERT_LINE);
714      }
715
716      update_drb_timer(param);
717      break;
718
719   case TIMER_DMA:
720      readbyte(AUXILIARY_ADDRESS_2);
721
722      update_dma_timer();
723      break;
724   }
725}
726
727
728//-------------------------------------------------
729//  read - register read
730//-------------------------------------------------
731
732READ8_MEMBER( crt9007_device::read )
733{
734   UINT8 data = 0;
735
736   switch (offset)
737   {
738   case 0x15:
739      if (LOG) logerror("CRT9007 '%s' Start\n", tag());
740      m_disp = 1;
741      break;
742
743   case 0x16:
744      if (LOG) logerror("CRT9007 '%s' Reset\n", tag());
745      device_reset();
746      break;
747
748   case 0x38:
749      data = VERTICAL_CURSOR;
750      break;
751
752   case 0x39:
753      data = HORIZONTAL_CURSOR;
754      break;
755
756   case 0x3a:
757      data = m_status;
758
759      // reset interrupt pending bit
760      m_status &= ~STATUS_INTERRUPT_PENDING;
761      if (LOG) logerror("CRT9007 '%s' INT 0\n", tag());
762      devcb_call_write_line(&m_out_int_func, CLEAR_LINE);
763      break;
764
765   case 0x3b:
766      data = VERTICAL_LIGHT_PEN;
767      break;
768
769   case 0x3c:
770      data = HORIZONTAL_LIGHT_PEN;
771
772      // reset light pen update bit
773      m_status &= ~STATUS_LIGHT_PEN_UPDATE;
774      break;
775
776   default:
777      logerror("CRT9007 '%s' Read from Invalid Register: %02x!\n", tag(), offset);
778   }
779
780   return data;
781}
782
783
784//-------------------------------------------------
785//  write - register write
786//-------------------------------------------------
787
788WRITE8_MEMBER( crt9007_device::write )
789{
790   m_reg[offset] = data;
791
792   switch (offset)
793   {
794   case 0x00:
795      recompute_parameters();
796      if (LOG) logerror("CRT9007 '%s' Characters per Horizontal Period: %u\n", tag(), CHARACTERS_PER_HORIZONTAL_PERIOD);
797      break;
798
799   case 0x01:
800      recompute_parameters();
801      if (LOG) logerror("CRT9007 '%s' Characters per Data Row: %u\n", tag(), CHARACTERS_PER_DATA_ROW);
802      break;
803
804   case 0x02:
805      recompute_parameters();
806      if (LOG) logerror("CRT9007 '%s' Horizontal Delay: %u\n", tag(), HORIZONTAL_DELAY);
807      break;
808
809   case 0x03:
810      recompute_parameters();
811      if (LOG) logerror("CRT9007 '%s' Horizontal Sync Width: %u\n", tag(), HORIZONTAL_SYNC_WIDTH);
812      break;
813
814   case 0x04:
815      recompute_parameters();
816      if (LOG) logerror("CRT9007 '%s' Vertical Sync Width: %u\n", tag(), VERTICAL_SYNC_WIDTH);
817      break;
818
819   case 0x05:
820      recompute_parameters();
821      if (LOG) logerror("CRT9007 '%s' Vertical Delay: %u\n", tag(), VERTICAL_DELAY);
822      break;
823
824   case 0x06:
825      recompute_parameters();
826      if (LOG)
827      {
828         logerror("CRT9007 '%s' Pin Configuration: %u\n", tag(), PIN_CONFIGURATION);
829         logerror("CRT9007 '%s' Cursor Skew: %u\n", tag(), CURSOR_SKEW);
830         logerror("CRT9007 '%s' Blank Skew: %u\n", tag(), BLANK_SKEW);
831      }
832      break;
833
834   case 0x07:
835      recompute_parameters();
836      if (LOG) logerror("CRT9007 '%s' Visible Data Rows per Frame: %u\n", tag(), VISIBLE_DATA_ROWS_PER_FRAME);
837      break;
838
839   case 0x08:
840      recompute_parameters();
841      if (LOG) logerror("CRT9007 '%s' Scan Lines per Data Row: %u\n", tag(), SCAN_LINES_PER_DATA_ROW);
842      break;
843
844   case 0x09:
845      recompute_parameters();
846      if (LOG) logerror("CRT9007 '%s' Scan Lines per Frame: %u\n", tag(), SCAN_LINES_PER_FRAME);
847      break;
848
849   case 0x0a:
850      if (LOG)
851      {
852         logerror("CRT9007 '%s' DMA Burst Count: %u\n", tag(), DMA_BURST_COUNT);
853         logerror("CRT9007 '%s' DMA Burst Delay: %u\n", tag(), DMA_BURST_DELAY);
854         logerror("CRT9007 '%s' DMA Disable: %u\n", tag(), DMA_DISABLE);
855      }
856      break;
857
858   case 0x0b:
859      if (LOG)
860      {
861         logerror("CRT9007 '%s' %s Height Cursor\n", tag(), SINGLE_HEIGHT_CURSOR ? "Single" : "Double");
862         logerror("CRT9007 '%s' Operation Mode: %u\n", tag(), OPERATION_MODE);
863         logerror("CRT9007 '%s' Interlace Mode: %u\n", tag(), INTERLACE_MODE);
864         logerror("CRT9007 '%s' %s Mechanism\n", tag(), PAGE_BLANK ? "Page Blank" : "Smooth Scroll");
865      }
866      break;
867
868   case 0x0c:
869      break;
870
871   case 0x0d:
872      if (LOG)
873      {
874         logerror("CRT9007 '%s' Table Start Register: %04x\n", tag(), TABLE_START);
875         logerror("CRT9007 '%s' Address Mode: %u\n", tag(), ADDRESS_MODE);
876      }
877      break;
878
879   case 0x0e:
880      break;
881
882   case 0x0f:
883      if (LOG)
884      {
885         logerror("CRT9007 '%s' Auxialiary Address Register 1: %04x\n", tag(), AUXILIARY_ADDRESS_1);
886         logerror("CRT9007 '%s' Row Attributes: %u\n", tag(), ROW_ATTRIBUTES_1);
887      }
888      break;
889
890   case 0x10:
891      if (LOG) logerror("CRT9007 '%s' Sequential Break Register 1: %u\n", tag(), SEQUENTIAL_BREAK_1);
892      break;
893
894   case 0x11:
895      if (LOG) logerror("CRT9007 '%s' Data Row Start Register: %u\n", tag(), DATA_ROW_START);
896      break;
897
898   case 0x12:
899      if (LOG) logerror("CRT9007 '%s' Data Row End/Sequential Break Register 2: %u\n", tag(), SEQUENTIAL_BREAK_2);
900      break;
901
902   case 0x13:
903      break;
904
905   case 0x14:
906      if (LOG)
907      {
908         logerror("CRT9007 '%s' Auxiliary Address Register 2: %04x\n", tag(), AUXILIARY_ADDRESS_2);
909         logerror("CRT9007 '%s' Row Attributes: %u\n", tag(), ROW_ATTRIBUTES_2);
910      }
911      break;
912
913   case 0x15:
914      if (LOG) logerror("CRT9007 '%s' Start\n", tag());
915      m_disp = 1;
916      break;
917
918   case 0x16:
919      if (LOG) logerror("CRT9007 '%s' Reset\n", tag());
920      device_reset();
921      break;
922
923   case 0x17:
924      if (LOG)
925      {
926         logerror("CRT9007 '%s' Smooth Scroll Offset: %u\n", tag(), SMOOTH_SCROLL_OFFSET);
927         logerror("CRT9007 '%s' Smooth Scroll Offset Overflow: %u\n", tag(), SMOOTH_SCROLL_OFFSET_OVERFLOW);
928      }
929      break;
930
931   case 0x18:
932      if (LOG) logerror("CRT9007 '%s' Vertical Cursor Register: %u\n", tag(), VERTICAL_CURSOR);
933      break;
934
935   case 0x19:
936      if (LOG) logerror("CRT9007 '%s' Horizontal Cursor Register: %u\n", tag(), HORIZONTAL_CURSOR);
937      break;
938
939   case 0x1a:
940      if (LOG)
941      {
942         logerror("CRT9007 '%s' Frame Timer: %u\n", tag(), FRAME_TIMER);
943         logerror("CRT9007 '%s' Light Pen Interrupt: %u\n", tag(), LIGHT_PEN_INTERRUPT);
944         logerror("CRT9007 '%s' Vertical Retrace Interrupt: %u\n", tag(), VERTICAL_RETRACE_INTERRUPT);
945      }
946      break;
947
948   default:
949      logerror("CRT9007 '%s' Write to Invalid Register: %02x!\n", tag(), offset);
950   }
951}
952
953
954//-------------------------------------------------
955//  ack_w - DMA acknowledge
956//-------------------------------------------------
957
958WRITE_LINE_MEMBER( crt9007_device::ack_w )
959{
960   if (LOG) logerror("CRT9007 '%s' ACK: %u\n", tag(), state);
961
962   if (m_dmar && !m_ack && state)
963   {
964      // start DMA transfer
965      m_dma_timer->adjust(attotime::from_hz(clock()));
966   }
967
968   m_ack = state;
969}
970
971
972//-------------------------------------------------
973//  lpstb_w - light pen strobe
974//-------------------------------------------------
975
976WRITE_LINE_MEMBER( crt9007_device::lpstb_w )
977{
978   if (LOG) logerror("CRT9007 '%s' LPSTB: %u\n", tag(), state);
979
980   if (!m_lpstb && state)
981   {
982      // TODO latch current row/column position
983   }
984
985   m_lpstb = state;
986}
987
988
989//-------------------------------------------------
990//  vlt_r -
991//-------------------------------------------------
992
993READ_LINE_MEMBER( crt9007_device::vlt_r )
994{
995   return m_vlt;
996}
997
998
999//-------------------------------------------------
1000//  wben_r -
1001//-------------------------------------------------
1002
1003READ_LINE_MEMBER( crt9007_device::wben_r )
1004{
1005   return m_wben;
1006}
1007
1008
1009//-------------------------------------------------
1010//  set_hpixels_per_column -
1011//-------------------------------------------------
1012
1013void crt9007_device::set_hpixels_per_column(int hpixels_per_column)
1014{
1015   m_hpixels_per_column = hpixels_per_column;
1016   recompute_parameters();
1017}
src/mess/video/crt9007.h
r10968r10969
1/**********************************************************************
2
3    SMC CRT9007 CRT Video Processor and Controller (VPAC) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                   VA2   1 |*    \_/     | 40  GND
11                  VA10   2 |             | 39  VA9
12                   VA3   3 |             | 38  VA1
13                  VA11   4 |             | 37  VA8
14                  VA12   5 |             | 36  VA0
15                   VA4   6 |             | 35  CBLANK
16                  VA13   7 |             | 34  CURS
17                   VA5   8 |             | 33  ACK/_TSC
18                   VA6   9 |             | 32  _CSYNC/LPSTB
19                   VA7  10 |   CRT9007   | 31  SLD/SL0
20                   VLT  11 |             | 30  _SLG/SL1
21                   _VS  12 |             | 29  WBEN/SL2/_CSYNC
22                   _HS  13 |             | 28  DMAR/SL3/VBLANK
23                 _CCLK  14 |             | 27  INT
24                  _DRB  15 |             | 26  _RST
25                   VD7  16 |             | 25  _CS
26                   VD6  17 |             | 24  VD0
27                   VD5  18 |             | 23  VD1
28                   VD4  19 |             | 22  VD2
29                   VD3  20 |_____________| 21  +5V
30
31**********************************************************************/
32
33#pragma once
34
35#ifndef __CRT9007__
36#define __CRT9007__
37
38#include "emu.h"
39
40
41
42//**************************************************************************
43//  MACROS / CONSTANTS
44//**************************************************************************
45
46
47
48
49//**************************************************************************
50//  INTERFACE CONFIGURATION MACROS
51//**************************************************************************
52
53#define MCFG_CRT9007_ADD(_tag, _clock, _config, _map) \
54   MCFG_DEVICE_ADD(_tag, CRT9007, _clock) \
55   MCFG_DEVICE_CONFIG(_config) \
56   MCFG_DEVICE_ADDRESS_MAP(AS_0, _map)
57
58
59#define CRT9007_INTERFACE(name) \
60   const crt9007_interface (name) =
61
62
63
64//**************************************************************************
65//  TYPE DEFINITIONS
66//**************************************************************************
67
68
69// ======================> crt9007_interface
70
71struct crt9007_interface
72{
73   const char *screen_tag;      /* screen we are acting on */
74   int hpixels_per_column;      /* number of pixels per video memory address */
75
76   devcb_write_line      out_int_func;
77   devcb_write_line      out_dmar_func;
78
79   devcb_write_line      out_vs_func;
80   devcb_write_line      out_hs_func;
81
82   devcb_write_line        out_vlt_func;
83    devcb_write_line        out_curs_func;
84    devcb_write_line        out_drb_func;
85    devcb_write_line        out_cblank_func;
86
87   devcb_write_line        out_slg_func;
88   devcb_write_line        out_sld_func;
89};
90
91
92
93// ======================> crt9007_device_config
94
95class crt9007_device_config :   public device_config,
96                        public device_config_memory_interface,
97                                public crt9007_interface
98{
99    friend class crt9007_device;
100
101    // construction/destruction
102    crt9007_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
103
104public:
105    // allocators
106    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
107    virtual device_t *alloc_device(running_machine &machine) const;
108
109protected:
110   // device_config overrides
111   virtual void device_config_complete();
112
113   // device_config_memory_interface overrides
114   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
115
116    // address space configurations
117   const address_space_config      m_space_config;
118};
119
120
121
122// ======================> crt9007_device
123
124class crt9007_device :   public device_t,
125                  public device_memory_interface
126{
127    friend class crt9007_device_config;
128
129    // construction/destruction
130    crt9007_device(running_machine &_machine, const crt9007_device_config &_config);
131
132public:
133    DECLARE_READ8_MEMBER( read );
134    DECLARE_WRITE8_MEMBER( write );
135   DECLARE_WRITE_LINE_MEMBER( ack_w );
136   DECLARE_WRITE_LINE_MEMBER( lpstb_w );
137   DECLARE_READ_LINE_MEMBER( vlt_r );
138   DECLARE_READ_LINE_MEMBER( wben_r );
139
140   void set_hpixels_per_column(int hpixels_per_column);
141
142protected:
143    // device-level overrides
144    virtual void device_start();
145    virtual void device_reset();
146   virtual void device_clock_changed();
147   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
148
149private:
150   static const device_timer_id TIMER_HSYNC = 0;
151   static const device_timer_id TIMER_VSYNC = 1;
152   static const device_timer_id TIMER_VLT = 2;
153   static const device_timer_id TIMER_CURS = 3;
154   static const device_timer_id TIMER_DRB = 4;
155   static const device_timer_id TIMER_DMA = 5;
156
157   inline UINT8 readbyte(offs_t address);
158
159   inline void trigger_interrupt(int line);
160   inline void update_cblank_line();
161   inline void update_hsync_timer(int state);
162   inline void update_vsync_timer(int state);
163   inline void update_vlt_timer(int state);
164   inline void update_curs_timer(int state);
165   inline void update_drb_timer(int state);
166   inline void update_dma_timer();
167
168   inline void recompute_parameters();
169
170   devcb_resolved_write_line   m_out_int_func;
171   devcb_resolved_write_line   m_out_dmar_func;
172   devcb_resolved_write_line   m_out_hs_func;
173   devcb_resolved_write_line   m_out_vs_func;
174   devcb_resolved_write_line   m_out_vlt_func;
175   devcb_resolved_write_line   m_out_curs_func;
176   devcb_resolved_write_line   m_out_drb_func;
177   devcb_resolved_write_line   m_out_cblank_func;
178   devcb_resolved_write_line   m_out_slg_func;
179   devcb_resolved_write_line   m_out_sld_func;
180
181   screen_device *m_screen;
182
183   // registers
184   UINT8 m_reg[0x3d];
185   UINT8 m_status;
186
187   int m_disp;
188   int m_hpixels_per_column;
189
190   // runtime variables, do not state save
191   int m_vsync_start;
192   int m_vsync_end;
193   int m_hsync_start;
194   int m_hsync_end;
195   int m_vlt_start;
196   int m_vlt_end;
197   int m_vlt_bottom;
198   int m_drb_bottom;
199   int m_hs;
200   int m_vs;
201   int m_cblank;
202   int m_vlt;
203   int m_drb;
204   int m_wben;
205   int m_slg;
206   int m_sld;
207   int m_lpstb;
208
209   // DMA
210   int m_dmar;
211   int m_ack;
212   int m_dma_count;
213   int m_dma_burst;
214   int m_dma_delay;
215
216   // timers
217   emu_timer *m_vsync_timer;
218   emu_timer *m_hsync_timer;
219   emu_timer *m_vlt_timer;
220   emu_timer *m_curs_timer;
221   emu_timer *m_drb_timer;
222   emu_timer *m_dma_timer;
223
224   const crt9007_device_config &m_config;
225};
226
227
228// device type definition
229extern const device_type CRT9007;
230
231
232
233#endif
src/mess/video/crt9212.c
r10968r10969
1/**********************************************************************
2
3    SMC CRT9212 Double Row Buffer (DRB) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "crt9212.h"
12
13
14
15//**************************************************************************
16//  MACROS / CONSTANTS
17//**************************************************************************
18
19#define LOG 1
20
21
22#define REN \
23   devcb_call_read_line(&m_in_ren_func)
24
25#define WEN \
26   devcb_call_read_line(&m_in_wen_func)
27
28#define WEN2 \
29   devcb_call_read_line(&m_in_wen2_func)
30
31#define ROF(_state) \
32   devcb_call_write_line(&m_out_rof_func, _state);
33
34#define WOF(_state) \
35   devcb_call_write_line(&m_out_wof_func, _state);
36
37
38
39//**************************************************************************
40//  GLOBAL VARIABLES
41//**************************************************************************
42
43// devices
44const device_type CRT9212 = crt9212_device_config::static_alloc_device_config;
45
46
47
48//**************************************************************************
49//  DEVICE CONFIGURATION
50//**************************************************************************
51
52//-------------------------------------------------
53//  crt9212_device_config - constructor
54//-------------------------------------------------
55
56crt9212_device_config::crt9212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
57   : device_config(mconfig, static_alloc_device_config, "SMC CRT9212", tag, owner, clock)
58{
59}
60
61
62//-------------------------------------------------
63//  static_alloc_device_config - allocate a new
64//  configuration object
65//-------------------------------------------------
66
67device_config *crt9212_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
68{
69   return global_alloc(crt9212_device_config(mconfig, tag, owner, clock));
70}
71
72
73//-------------------------------------------------
74//  alloc_device - allocate a new device object
75//-------------------------------------------------
76
77device_t *crt9212_device_config::alloc_device(running_machine &machine) const
78{
79   return auto_alloc(&machine, crt9212_device(machine, *this));
80}
81
82
83//-------------------------------------------------
84//  device_config_complete - perform any
85//  operations now that the configuration is
86//  complete
87//-------------------------------------------------
88
89void crt9212_device_config::device_config_complete()
90{
91   // inherit a copy of the static data
92   const crt9212_interface *intf = reinterpret_cast<const crt9212_interface *>(static_config());
93   if (intf != NULL)
94      *static_cast<crt9212_interface *>(this) = *intf;
95
96   // or initialize to defaults if none provided
97   else
98   {
99      memset(&out_rof_func, 0, sizeof(out_rof_func));
100      memset(&out_wof_func, 0, sizeof(out_wof_func));
101      memset(&in_ren_func, 0, sizeof(in_ren_func));
102      memset(&in_wen_func, 0, sizeof(in_wen_func));
103      memset(&in_wen2_func, 0, sizeof(in_wen2_func));
104   }
105}
106
107
108
109//**************************************************************************
110//  INLINE HELPERS
111//**************************************************************************
112
113
114//**************************************************************************
115//  LIVE DEVICE
116//**************************************************************************
117
118//-------------------------------------------------
119//  crt9212_device - constructor
120//-------------------------------------------------
121
122crt9212_device::crt9212_device(running_machine &_machine, const crt9212_device_config &config)
123    : device_t(_machine, config),
124      m_config(config)
125{
126}
127
128
129//-------------------------------------------------
130//  device_start - device-specific startup
131//-------------------------------------------------
132
133void crt9212_device::device_start()
134{
135   // resolve callbacks
136   devcb_resolve_write_line(&m_out_rof_func, &m_config.out_rof_func, this);
137   devcb_resolve_write_line(&m_out_wof_func, &m_config.out_wof_func, this);
138   devcb_resolve_read_line(&m_in_ren_func, &m_config.in_ren_func, this);
139   devcb_resolve_read_line(&m_in_wen_func, &m_config.in_wen_func, this);
140   devcb_resolve_read_line(&m_in_wen2_func, &m_config.in_wen2_func, this);
141
142   // register for state saving
143   save_item(NAME(m_input));
144   save_item(NAME(m_output));
145   save_item(NAME(m_buffer));
146   save_item(NAME(m_rac));
147   save_item(NAME(m_wac));
148   save_item(NAME(m_tog));
149   save_item(NAME(m_clrcnt));
150   save_item(NAME(m_rclk));
151   save_item(NAME(m_wclk));
152}
153
154
155//-------------------------------------------------
156//  read - buffer read
157//-------------------------------------------------
158
159READ8_MEMBER( crt9212_device::read )
160{
161   return m_output;
162}
163
164
165//-------------------------------------------------
166//  write - buffer write
167//-------------------------------------------------
168
169WRITE8_MEMBER( crt9212_device::write )
170{
171   m_input = data;
172}
173
174
175//-------------------------------------------------
176//  clrcnt_w - clear address counters
177//-------------------------------------------------
178
179WRITE_LINE_MEMBER( crt9212_device::clrcnt_w )
180{
181   m_clrcnt = state;
182}
183
184
185//-------------------------------------------------
186//  tog_w - toggle buffer
187//-------------------------------------------------
188
189WRITE_LINE_MEMBER( crt9212_device::tog_w )
190{
191   m_tog = state;
192}
193
194
195//-------------------------------------------------
196//  rclk_w - read clock
197//-------------------------------------------------
198
199WRITE_LINE_MEMBER( crt9212_device::rclk_w )
200{
201   if (m_rclk && !state)
202   {
203      if (!m_clrcnt)
204      {
205         if (!m_tog)
206         {
207            // switch buffer
208            m_buffer = !m_buffer;
209
210            // clear write address counter
211            m_wac = 0;
212            WOF(0);
213         }
214         else
215         {
216            // clear read address counter
217            m_rac = 0;
218            ROF(0);
219         }
220      }
221      else
222      {
223         if (REN && (m_rac < CRT9212_RAM_SIZE))
224         {
225            //
226            m_output = m_ram[m_rac][!m_buffer];
227
228            // increment read address counter
229            m_rac++;
230
231            if (m_rac == CRT9212_RAM_SIZE)
232            {
233               // set read overflow
234               ROF(1);
235            }
236         }
237      }
238   }
239
240   m_rclk = state;
241}
242
243
244//-------------------------------------------------
245//  wclk_w - write clock
246//-------------------------------------------------
247
248WRITE_LINE_MEMBER( crt9212_device::wclk_w )
249{
250   if (!m_rclk && state)
251   {
252      if (WEN && WEN2 && (m_wac < CRT9212_RAM_SIZE))
253      {
254         //
255         m_ram[m_rac][m_buffer] = m_input;
256
257         // increment read address counter
258         m_wac++;
259
260         if (m_wac == CRT9212_RAM_SIZE)
261         {
262            // set write overflow
263            WOF(1);
264         }
265      }
266   }
267
268   m_wclk = state;
269}
src/mess/video/crt9212.h
r10968r10969
1/**********************************************************************
2
3    SMC CRT9212 Double Row Buffer (DRB) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                  DIN2   1 |*    \_/     | 28  DIN3
11                  DIN1   2 |             | 27  _WCLK
12                  DIN0   3 |             | 26  _OE
13                 DOUT7   4 |             | 25  WEN2
14                 DOUT6   5 |             | 24  WEN1
15                 DOUT5   6 |             | 23  GND
16                 DOUT4   7 |   CRT9212   | 22  ROF
17                   Vcc   8 |             | 21  WOF
18                 DOUT3   9 |             | 20  REN
19                 DOUT2  10 |             | 19  _CLRCNT
20                 DOUT1  11 |             | 18  _TOG
21                 DOUT0  12 |             | 17  _RCLK
22                  DIN7  13 |             | 16  DIN4
23                  DIN6  14 |_____________| 15  DIN5
24
25**********************************************************************/
26
27#pragma once
28
29#ifndef __CRT9212__
30#define __CRT9212__
31
32#include "emu.h"
33
34
35
36//**************************************************************************
37//  MACROS / CONSTANTS
38//**************************************************************************
39
40const int CRT9212_RAM_SIZE   = 135;
41
42
43
44//**************************************************************************
45//  INTERFACE CONFIGURATION MACROS
46//**************************************************************************
47
48#define MCFG_CRT9212_ADD(_tag, _config) \
49   MCFG_DEVICE_ADD(_tag, CRT9212, 0) \
50   MCFG_DEVICE_CONFIG(_config)
51
52
53#define CRT9212_INTERFACE(name) \
54   const crt9212_interface (name) =
55
56
57
58//**************************************************************************
59//  TYPE DEFINITIONS
60//**************************************************************************
61
62
63// ======================> crt9212_interface
64
65struct crt9212_interface
66{
67   devcb_write_line      out_rof_func;
68   devcb_write_line      out_wof_func;
69   devcb_read_line         in_ren_func;
70   devcb_read_line         in_wen_func;
71   devcb_read_line         in_wen2_func;
72};
73
74
75
76// ======================> crt9212_device_config
77
78class crt9212_device_config :   public device_config,
79                                public crt9212_interface
80{
81    friend class crt9212_device;
82
83    // construction/destruction
84    crt9212_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
85
86public:
87    // allocators
88    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
89    virtual device_t *alloc_device(running_machine &machine) const;
90
91protected:
92   // device_config overrides
93   virtual void device_config_complete();
94};
95
96
97
98// ======================> crt9212_device
99
100class crt9212_device :   public device_t
101{
102    friend class crt9212_device_config;
103
104    // construction/destruction
105    crt9212_device(running_machine &_machine, const crt9212_device_config &_config);
106
107public:
108    DECLARE_READ8_MEMBER( read );
109    DECLARE_WRITE8_MEMBER( write );
110   DECLARE_WRITE_LINE_MEMBER( clrcnt_w );
111   DECLARE_WRITE_LINE_MEMBER( tog_w );
112   DECLARE_WRITE_LINE_MEMBER( rclk_w );
113   DECLARE_WRITE_LINE_MEMBER( wclk_w );
114
115protected:
116    // device-level overrides
117    virtual void device_start();
118
119private:
120   devcb_resolved_write_line   m_out_rof_func;
121   devcb_resolved_write_line   m_out_wof_func;
122   devcb_resolved_read_line   m_in_ren_func;
123   devcb_resolved_read_line   m_in_wen_func;
124   devcb_resolved_read_line   m_in_wen2_func;
125
126   UINT8 m_ram[CRT9212_RAM_SIZE][2];
127
128   UINT8 m_input;
129   UINT8 m_output;
130
131   int m_buffer;
132   int m_rac;
133   int m_wac;
134   int m_tog;
135   int m_clrcnt;
136   int m_rclk;
137   int m_wclk;
138
139   const crt9212_device_config &m_config;
140};
141
142
143// device type definition
144extern const device_type CRT9212;
145
146
147
148#endif
src/mess/video/crt9021.c
r10968r10969
1/**********************************************************************
2
3    SMC CRT9021 Video Attributes Controller (VAC) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10/*
11
12    TODO:
13
14    - attributes
15        - reverse video
16        - character blank
17        - character blink
18        - underline
19        - full/half intensity
20    - operation modes
21        - wide graphics
22        - thin graphics
23        - character mode w/o underline
24        - character mode w/underline
25    - double height characters
26    - double width characters
27    - parallel scan line
28    - serial scan line
29    - cursor
30        - underline
31        - blinking underline
32        - reverse video
33        - blinking reverse video
34    - programmable character blink rate (75/25 duty)
35    - programmable cursor blink rate (50/50 duty)
36    - data/attribute latches
37
38*/
39
40#include "emu.h"
41#include "crt9021.h"
42
43
44
45//**************************************************************************
46//  MACROS / CONSTANTS
47//**************************************************************************
48
49#define LOG 1
50
51
52// attributes
53enum
54{
55   ATTRIBUTE_REVID = 0x80,
56   ATTRIBUTE_INT   = 0x40,
57   ATTRIBUTE_BLINK = 0x20,
58   ATTRIBUTE_MS1   = 0x10,
59   ATTRIBUTE_MS0   = 0x08,
60   ATTRIBUTE_CHABL = 0x04,
61   ATTRIBUTE_BKC   = 0x02,
62   ATTRIBUTE_BLC   = 0x01
63};
64
65
66//**************************************************************************
67//  GLOBAL VARIABLES
68//**************************************************************************
69
70// devices
71const device_type CRT9021 = crt9021_device_config::static_alloc_device_config;
72
73
74
75//**************************************************************************
76//  DEVICE CONFIGURATION
77//**************************************************************************
78
79//-------------------------------------------------
80//  crt9021_device_config - constructor
81//-------------------------------------------------
82
83crt9021_device_config::crt9021_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
84   : device_config(mconfig, static_alloc_device_config, "SMC CRT9021", tag, owner, clock)
85{
86}
87
88
89//-------------------------------------------------
90//  static_alloc_device_config - allocate a new
91//  configuration object
92//-------------------------------------------------
93
94device_config *crt9021_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
95{
96   return global_alloc(crt9021_device_config(mconfig, tag, owner, clock));
97}
98
99
100//-------------------------------------------------
101//  alloc_device - allocate a new device object
102//-------------------------------------------------
103
104device_t *crt9021_device_config::alloc_device(running_machine &machine) const
105{
106   return auto_alloc(&machine, crt9021_device(machine, *this));
107}
108
109
110//-------------------------------------------------
111//  device_config_complete - perform any
112//  operations now that the configuration is
113//  complete
114//-------------------------------------------------
115
116void crt9021_device_config::device_config_complete()
117{
118   // inherit a copy of the static data
119   const crt9021_interface *intf = reinterpret_cast<const crt9021_interface *>(static_config());
120   if (intf != NULL)
121      *static_cast<crt9021_interface *>(this) = *intf;
122
123   // or initialize to defaults if none provided
124   else
125   {
126      memset(&in_data_func, 0, sizeof(in_data_func));
127      memset(&in_attr_func, 0, sizeof(in_attr_func));
128      memset(&in_atten_func, 0, sizeof(in_atten_func));
129   }
130}
131
132
133
134//**************************************************************************
135//  INLINE HELPERS
136//**************************************************************************
137
138
139
140//**************************************************************************
141//  LIVE DEVICE
142//**************************************************************************
143
144//-------------------------------------------------
145//  crt9021_device - constructor
146//-------------------------------------------------
147
148crt9021_device::crt9021_device(running_machine &_machine, const crt9021_device_config &config)
149    : device_t(_machine, config),
150      m_config(config)
151{
152}
153
154
155//-------------------------------------------------
156//  device_start - device-specific startup
157//-------------------------------------------------
158
159void crt9021_device::device_start()
160{
161   // allocate timers
162
163   // resolve callbacks
164   devcb_resolve_read8(&m_in_data_func, &m_config.in_data_func, this);
165   devcb_resolve_read8(&m_in_attr_func, &m_config.in_attr_func, this);
166   devcb_resolve_read_line(&m_in_atten_func, &m_config.in_atten_func, this);
167
168   // get the screen device
169   m_screen = machine->device<screen_device>(m_config.screen_tag);
170   assert(m_screen != NULL);
171
172   // register for state saving
173   save_item(NAME(m_slg));
174   save_item(NAME(m_sld));
175   save_item(NAME(m_cursor));
176   save_item(NAME(m_retbl));
177   save_item(NAME(m_vsync));
178}
179
180
181//-------------------------------------------------
182//  device_clock_changed - handle clock change
183//-------------------------------------------------
184
185void crt9021_device::device_clock_changed()
186{
187}
188
189
190//-------------------------------------------------
191//  device_timer - handle timer events
192//-------------------------------------------------
193
194void crt9021_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
195{
196}
197
198
199//-------------------------------------------------
200//  slg_w - scan line gate
201//-------------------------------------------------
202
203WRITE_LINE_MEMBER( crt9021_device::slg_w )
204{
205   if (LOG) logerror("CRT9021 '%s' SLG: %u\n", tag(), state);
206
207   m_slg = state;
208}
209
210
211//-------------------------------------------------
212//  sld_w - scan line data
213//-------------------------------------------------
214
215WRITE_LINE_MEMBER( crt9021_device::sld_w )
216{
217   if (LOG) logerror("CRT9021 '%s' SLG: %u\n", tag(), state);
218
219   if (!m_slg)
220   {
221      m_sld <<= 1;
222      m_sld |= state;
223   }
224}
225
226
227//-------------------------------------------------
228//  cursor_w - cursor
229//-------------------------------------------------
230
231WRITE_LINE_MEMBER( crt9021_device::cursor_w )
232{
233   if (LOG) logerror("CRT9021 '%s' CURSOR: %u\n", tag(), state);
234
235   m_cursor = state;
236}
237
238
239//-------------------------------------------------
240//  retbl_w - retrace blank
241//-------------------------------------------------
242
243WRITE_LINE_MEMBER( crt9021_device::retbl_w )
244{
245   if (LOG) logerror("CRT9021 '%s' RETBL: %u\n", tag(), state);
246
247   m_retbl = state;
248}
249
250
251//-------------------------------------------------
252//  vsync_w - vertical sync
253//-------------------------------------------------
254
255WRITE_LINE_MEMBER( crt9021_device::vsync_w )
256{
257   if (LOG) logerror("CRT9021 '%s' VSYNC: %u\n", tag(), state);
258
259   m_vsync = state;
260}
261
262
263//-------------------------------------------------
264//  update_screen - update screen
265//-------------------------------------------------
266
267void crt9021_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect)
268{
269}
src/mess/video/crt9021.h
r10968r10969
1/**********************************************************************
2
3    SMC CRT9021 Video Attributes Controller (VAC) emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************
9                            _____   _____
10                    D0   1 |*    \_/     | 28  D1
11                   MS0   2 |             | 27  D2
12                   MS1   3 |             | 26  D3
13                 REVID   4 |             | 25  D4
14                 CHABL   5 |             | 24  D5
15                 BLINK   6 |             | 23  D6
16                 INTIN   7 |   CRT9021   | 22  D7
17                   +5V   8 |             | 21  _VSYNC
18                 ATTEN   9 |             | 20  GND
19                INTOUT  10 |             | 19  SL0/SLD
20                CURSOR  11 |             | 18  SL1/_SLG
21                 RETBL  12 |             | 17  SL2/BLC
22                _LD/SH  13 |             | 16  SL3/BKC
23                 VIDEO  14 |_____________| 15  VDC
24
25**********************************************************************/
26
27#pragma once
28
29#ifndef __CRT9021__
30#define __CRT9021__
31
32#include "emu.h"
33
34
35
36//**************************************************************************
37//  MACROS / CONSTANTS
38//**************************************************************************
39
40
41
42
43//**************************************************************************
44//  INTERFACE CONFIGURATION MACROS
45//**************************************************************************
46
47#define MCFG_CRT9021_ADD(_tag, _clock, _config) \
48   MCFG_DEVICE_ADD(_tag, CRT9021, _clock) \
49   MCFG_DEVICE_CONFIG(_config)
50
51
52#define CRT9021_INTERFACE(name) \
53   const crt9021_interface (name) =
54
55
56
57//**************************************************************************
58//  TYPE DEFINITIONS
59//**************************************************************************
60
61
62// ======================> crt9021_interface
63
64struct crt9021_interface
65{
66   const char *screen_tag;      /* screen we are acting on */
67
68   devcb_read8            in_data_func;
69   devcb_read8            in_attr_func;
70
71   devcb_read_line         in_atten_func;
72};
73
74
75
76// ======================> crt9021_device_config
77
78class crt9021_device_config :   public device_config,
79                                public crt9021_interface
80{
81    friend class crt9021_device;
82
83    // construction/destruction
84    crt9021_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
85
86public:
87    // allocators
88    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
89    virtual device_t *alloc_device(running_machine &machine) const;
90
91protected:
92   // device_config overrides
93   virtual void device_config_complete();
94};
95
96
97
98// ======================> crt9021_device
99
100class crt9021_device :   public device_t
101{
102    friend class crt9021_device_config;
103
104    // construction/destruction
105    crt9021_device(running_machine &_machine, const crt9021_device_config &_config);
106
107public:
108   DECLARE_WRITE_LINE_MEMBER( slg_w );
109   DECLARE_WRITE_LINE_MEMBER( sld_w );
110   DECLARE_WRITE_LINE_MEMBER( cursor_w );
111   DECLARE_WRITE_LINE_MEMBER( retbl_w );
112   DECLARE_WRITE_LINE_MEMBER( vsync_w );
113
114   void update_screen(bitmap_t *bitmap, const rectangle *cliprect);
115
116protected:
117    // device-level overrides
118    virtual void device_start();
119   virtual void device_clock_changed();
120   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
121
122private:
123   devcb_resolved_read8         m_in_data_func;
124   devcb_resolved_read8         m_in_attr_func;
125   devcb_resolved_read_line      m_in_atten_func;
126
127   screen_device *m_screen;
128
129   int m_slg;
130   int m_sld;
131   int m_cursor;
132   int m_retbl;
133   int m_vsync;
134
135   const crt9021_device_config &m_config;
136};
137
138
139// device type definition
140extern const device_type CRT9021;
141
142
143
144#endif
src/mess/video/hd61830.c
r10968r10969
1/**********************************************************************
2
3    HD61830 LCD Timing Controller emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#include "emu.h"
11#include "hd61830.h"
12
13
14
15//**************************************************************************
16//  MACROS / CONSTANTS
17//**************************************************************************
18
19#define LOG 0
20
21enum
22{
23   INSTRUCTION_MODE_CONTROL = 0,
24   INSTRUCTION_CHARACTER_PITCH,
25   INSTRUCTION_NUMBER_OF_CHARACTERS,
26   INSTRUCTION_NUMBER_OF_TIME_DIVISIONS,
27   INSTRUCTION_CURSOR_POSITION,
28   INSTRUCTION_DISPLAY_START_LOW = 8,
29   INSTRUCTION_DISPLAY_START_HIGH,
30   INSTRUCTION_CURSOR_ADDRESS_LOW,
31   INSTRUCTION_CURSOR_ADDRESS_HIGH,
32   INSTRUCTION_DISPLAY_DATA_WRITE,
33   INSTRUCTION_DISPLAY_DATA_READ,
34   INSTRUCTION_CLEAR_BIT,
35   INSTRUCTION_SET_BIT
36};
37
38static const int CYCLES[] =
39{
40   4, 4, 4, 4, 4, -1, -1, -1, 4, 4, 4, 4, 6, 6, 36, 36
41};
42
43const int MODE_EXTERNAL_CG      = 0x01;
44const int MODE_GRAPHIC         = 0x02;
45const int MODE_CURSOR         = 0x04;
46const int MODE_BLINK         = 0x08;
47const int MODE_MASTER         = 0x10;
48const int MODE_DISPLAY_ON      = 0x20;
49
50
51
52//**************************************************************************
53//  GLOBAL VARIABLES
54//**************************************************************************
55
56// devices
57const device_type HD61830 = hd61830_device_config::static_alloc_device_config;
58
59
60// default address map
61static ADDRESS_MAP_START( hd61830, AS_0, 8 )
62   AM_RANGE(0x0000, 0xffff) AM_RAM
63ADDRESS_MAP_END
64
65
66// internal character generator ROM
67ROM_START( hd61830 )
68   ROM_REGION( 0x5c0, "hd61830", ROMREGION_LOADBYNAME ) // internal 7360-bit chargen ROM
69   ROM_LOAD( "hd61830.bin", 0x000, 0x5c0, BAD_DUMP CRC(06a934da) SHA1(bf3f074db5dc92e6f530cb18d6c013563099a87d) ) // typed in from manual
70ROM_END
71
72
73
74//**************************************************************************
75//  DEVICE CONFIGURATION
76//**************************************************************************
77
78//-------------------------------------------------
79//  hd61830_device_config - constructor
80//-------------------------------------------------
81
82hd61830_device_config::hd61830_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
83   : device_config(mconfig, static_alloc_device_config, "Hitachi HD61830", tag, owner, clock),
84     device_config_memory_interface(mconfig, *this),
85     m_space_config("videoram", ENDIANNESS_LITTLE, 8, 16, 0, NULL, *ADDRESS_MAP_NAME(hd61830))
86{
87   m_shortname = "hd61830";
88}
89
90
91//-------------------------------------------------
92//  static_alloc_device_config - allocate a new
93//  configuration object
94//-------------------------------------------------
95
96device_config *hd61830_device_config::static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock)
97{
98   return global_alloc(hd61830_device_config(mconfig, tag, owner, clock));
99}
100
101
102//-------------------------------------------------
103//  alloc_device - allocate a new device object
104//-------------------------------------------------
105
106device_t *hd61830_device_config::alloc_device(running_machine &machine) const
107{
108   return auto_alloc(&machine, hd61830_device(machine, *this));
109}
110
111
112//-------------------------------------------------
113//  memory_space_config - return a description of
114//  any address spaces owned by this device
115//-------------------------------------------------
116
117const address_space_config *hd61830_device_config::memory_space_config(address_spacenum spacenum) const
118{
119   return (spacenum == AS_0) ? &m_space_config : NULL;
120}
121
122
123//-------------------------------------------------
124//  rom_region - device-specific ROM region
125//-------------------------------------------------
126
127const rom_entry *hd61830_device_config::rom_region() const
128{
129   return ROM_NAME(hd61830);
130}
131
132
133//-------------------------------------------------
134//  device_config_complete - perform any
135//  operations now that the configuration is
136//  complete
137//-------------------------------------------------
138
139void hd61830_device_config::device_config_complete()
140{
141   // inherit a copy of the static data
142   const hd61830_interface *intf = reinterpret_cast<const hd61830_interface *>(static_config());
143   if (intf != NULL)
144      *static_cast<hd61830_interface *>(this) = *intf;
145
146   // or initialize to defaults if none provided
147   else
148   {
149      memset(&m_in_rd_func, 0, sizeof(m_in_rd_func));
150   }
151}
152
153
154
155//**************************************************************************
156//  INLINE HELPERS
157//**************************************************************************
158
159//-------------------------------------------------
160//  readbyte - read a byte at the given address
161//-------------------------------------------------
162
163inline UINT8 hd61830_device::readbyte(offs_t address)
164{
165   return space()->read_byte(address);
166}
167
168
169//-------------------------------------------------
170//  writebyte - write a byte at the given address
171//-------------------------------------------------
172
173inline void hd61830_device::writebyte(offs_t address, UINT8 data)
174{
175   space()->write_byte(address, data);
176}
177
178
179
180//**************************************************************************
181//  LIVE DEVICE
182//**************************************************************************
183
184//-------------------------------------------------
185//  hd61830_device - constructor
186//-------------------------------------------------
187
188hd61830_device::hd61830_device(running_machine &_machine, const hd61830_device_config &config)
189    : device_t(_machine, config),
190     device_memory_interface(_machine, config, *this),
191     m_bf(false),
192     m_blink(0),
193      m_config(config)
194{
195
196}
197
198
199//-------------------------------------------------
200//  device_start - device-specific startup
201//-------------------------------------------------
202
203void hd61830_device::device_start()
204{
205   // allocate timers
206   m_busy_timer = timer_alloc();
207
208   // resolve callbacks
209    devcb_resolve_read8(&m_in_rd_func, &m_config.m_in_rd_func, this);
210
211   m_screen = machine->device<screen_device>(m_config.screen_tag);
212
213   // register for state saving
214   save_item(NAME(m_bf));
215   save_item(NAME(m_ir));
216   save_item(NAME(m_mcr));
217   save_item(NAME(m_dor));
218   save_item(NAME(m_cac));
219   save_item(NAME(m_dsa));
220   save_item(NAME(m_vp));
221   save_item(NAME(m_hp));
222   save_item(NAME(m_hn));
223   save_item(NAME(m_nx));
224   save_item(NAME(m_cp));
225   save_item(NAME(m_blink));
226   save_item(NAME(m_cursor));
227}
228
229
230//-------------------------------------------------
231//  device_reset - device-specific reset
232//-------------------------------------------------
233
234void hd61830_device::device_reset()
235{
236   // display off, slave mode
237   m_mcr &= ~(MODE_MASTER | MODE_DISPLAY_ON);
238
239   // default horizontal pitch
240   m_hp = 6;
241}
242
243
244//-------------------------------------------------
245//  device_timer - handler timer events
246//-------------------------------------------------
247
248void hd61830_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
249{
250   // clear busy flag
251   m_bf = false;
252}
253
254
255/*-------------------------------------------------
256    set_busy_flag - set busy flag and arm timer
257                    to clear it later
258-------------------------------------------------*/
259
260void hd61830_device::set_busy_flag()
261{
262   // set busy flag
263   m_bf = true;
264
265   // adjust busy timer
266   m_busy_timer->adjust(attotime::from_usec(CYCLES[m_ir]));
267}
268
269
270//-------------------------------------------------
271//  status_r - status register read
272//-------------------------------------------------
273
274READ8_MEMBER( hd61830_device::status_r )
275{
276   if (LOG) logerror("HD61830 '%s' Status Read: %s\n", tag(), m_bf ? "busy" : "ready");
277
278   return m_bf ? 0x80 : 0;
279}
280
281
282//-------------------------------------------------
283//  control_w - instruction register write
284//-------------------------------------------------
285
286WRITE8_MEMBER( hd61830_device::control_w )
287{
288   m_ir = data;
289}
290
291
292//-------------------------------------------------
293//  data_r - data register read
294//-------------------------------------------------
295
296READ8_MEMBER( hd61830_device::data_r )
297{
298   UINT8 data = m_dor;
299
300   if (LOG) logerror("HD61830 '%s' Display Data Read %02x\n", tag(), m_dor);
301
302   m_dor = readbyte(m_cac);
303
304   m_cac++;
305
306   return data;
307}
308
309
310//-------------------------------------------------
311//  data_w - data register write
312//-------------------------------------------------
313
314WRITE8_MEMBER( hd61830_device::data_w )
315{
316   if (m_bf)
317   {
318      logerror("HD61830 '%s' Ignoring data write %02x due to business\n", tag(), data);
319      return;
320   }
321
322   switch (m_ir)
323   {
324   case INSTRUCTION_MODE_CONTROL:
325      m_mcr = data;
326
327      if (LOG)
328      {
329         logerror("HD61830 '%s' %s CG\n", tag(), (data & MODE_EXTERNAL_CG) ? "External" : "Internal");
330         logerror("HD61830 '%s' %s Display Mode\n", tag(), (data & MODE_GRAPHIC) ? "Graphic" : "Character");
331         logerror("HD61830 '%s' %s Mode\n", tag(), (data & MODE_MASTER) ? "Master" : "Slave");
332         logerror("HD61830 '%s' Cursor %s\n", tag(), (data & MODE_CURSOR) ? "On" : "Off");
333         logerror("HD61830 '%s' Blink %s\n", tag(), (data & MODE_BLINK) ? "On" : "Off");
334         logerror("HD61830 '%s' Display %s\n", tag(), (data & MODE_DISPLAY_ON) ? "On" : "Off");
335      }
336      break;
337
338   case INSTRUCTION_CHARACTER_PITCH:
339      m_hp = (data & 0x07) + 1;
340      m_vp = (data >> 4) + 1;
341
342      if (LOG) logerror("HD61830 '%s' Horizontal Character Pitch: %u\n", tag(), m_hp);
343      if (LOG) logerror("HD61830 '%s' Vertical Character Pitch: %u\n", tag(), m_vp);
344      break;
345
346   case INSTRUCTION_NUMBER_OF_CHARACTERS:
347      m_hn = (data & 0x7f) + 1;
348
349      if (LOG) logerror("HD61830 '%s' Number of Characters: %u\n", tag(), m_hn);
350      break;
351
352   case INSTRUCTION_NUMBER_OF_TIME_DIVISIONS:
353      m_nx = (data & 0x7f) + 1;
354
355      if (LOG) logerror("HD61830 '%s' Number of Time Divisions: %u\n", tag(), m_nx);
356      break;
357
358   case INSTRUCTION_CURSOR_POSITION:
359      m_cp = (data & 0x7f) + 1;
360
361      if (LOG) logerror("HD61830 '%s' Cursor Position: %u\n", tag(), m_cp);
362      break;
363
364   case INSTRUCTION_DISPLAY_START_LOW:
365      m_dsa = (m_dsa & 0xff00) | data;
366
367      if (LOG) logerror("HD61830 '%s' Display Start Address Low %04x\n", tag(), m_dsa);
368      break;
369
370   case INSTRUCTION_DISPLAY_START_HIGH:
371      m_dsa = (data << 8) | (m_dsa & 0xff);
372
373      if (LOG) logerror("HD61830 '%s' Display Start Address High %04x\n", tag(), m_dsa);
374      break;
375
376   case INSTRUCTION_CURSOR_ADDRESS_LOW:
377      if (BIT(m_cac, 7) && !BIT(data, 7))
378      {
379         m_cac = (((m_cac >> 8) + 1) << 8) | data;
380      }
381      else
382      {
383         m_cac = (m_cac & 0xff00) | data;
384      }
385
386      if (LOG) logerror("HD61830 '%s' Cursor Address Low %02x: %04x\n", tag(), data, m_cac);
387      break;
388
389   case INSTRUCTION_CURSOR_ADDRESS_HIGH:
390      m_cac = (data << 8) | (m_cac & 0xff);
391
392      if (LOG) logerror("HD61830 '%s' Cursor Address High %02x: %04x\n", tag(), data, m_cac);
393      break;
394
395   case INSTRUCTION_DISPLAY_DATA_WRITE:
396      writebyte(m_cac, data);
397
398      if (LOG) logerror("HD61830 '%s' Display Data Write %02x -> %04x row %u col %u\n", tag(), data, m_cac, m_cac / 40, m_cac % 40);
399
400      m_cac++;
401      break;
402
403   case INSTRUCTION_CLEAR_BIT:
404      {
405      int bit = data & 0x07;
406      UINT8 md = readbyte(m_cac);
407
408      md &= ~(1 << bit);
409
410      if (LOG) logerror("HD61830 '%s' Clear Bit %u at %04x\n", tag(), bit + 1, m_cac);
411
412      writebyte(m_cac, md);
413
414      m_cac++;
415      }
416      break;
417
418   case INSTRUCTION_SET_BIT:
419      {
420      int bit = data & 0x07;
421      UINT8 md = readbyte(m_cac);
422
423      md |= 1 << bit;
424
425      if (LOG) logerror("HD61830 '%s' Set Bit %u at %04x\n", tag(), bit + 1, m_cac);
426
427      writebyte(m_cac, md);
428
429      m_cac++;
430      }
431      break;
432
433   default:
434      logerror("HD61830 '%s' Illegal Instruction %02x!\n", tag(), m_ir);
435      return;
436   }
437
438   // burn cycles
439   set_busy_flag();
440}
441
442
443//-------------------------------------------------
444//  draw_scanline - draw one graphics scanline
445//-------------------------------------------------
446
447void hd61830_device::draw_scanline(bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ra)
448{
449   for (int sx = 0; sx < m_hn; sx++)
450   {
451      UINT8 data = readbyte(ra++);
452
453      for (int x = 0; x < m_hp; x++)
454      {
455         *BITMAP_ADDR16(bitmap, y, (sx * m_hp) + x) = BIT(data, x);
456      }
457   }
458}
459
460
461//-------------------------------------------------
462//  update_graphics - draw graphics mode screen
463//-------------------------------------------------
464
465void hd61830_device::update_graphics(bitmap_t *bitmap, const rectangle *cliprect)
466{
467   for (int y = 0; y < m_nx; y++)
468   {
469      UINT16 rac1 = m_dsa + (y * m_hn);
470      UINT16 rac2 = rac1 + (m_nx * m_hn);
471
472      /* draw upper half scanline */
473      draw_scanline(bitmap, cliprect, y, rac1);
474
475      /* draw lower half scanline */
476      draw_scanline(bitmap, cliprect, y + m_nx, rac2);
477   }
478}
479
480
481//-------------------------------------------------
482//  draw_char - draw a char
483//-------------------------------------------------
484
485void hd61830_device::draw_char(bitmap_t *bitmap, const rectangle *cliprect, UINT16 ma, int x, int y, UINT8 md)
486{
487   for (int cl = 0; cl < m_vp; cl++)
488   {
489      for (int cr = 0; cr < m_hp; cr++)
490      {
491         int sy = y * m_vp + cl;
492         int sx = x * m_hp + cr;
493         UINT8 data = 0;
494
495         if (m_mcr & MODE_EXTERNAL_CG)
496         {
497            data = devcb_call_read8(&m_in_rd_func, (cl << 12) | md);
498         }
499         else
500         {
501            UINT16 addr = 0;
502
503            if (md >= 0x20 && md < 0x80 && cl < 7)
504            {
505               // 5x7 characters 0x20..0x7f
506               addr = (md - 0x20) * 7 + cl;
507            }
508            else if (md >= 0xa0 && md < 0xe0 && cl < 7)
509            {
510               // 5x7 characters 0xa0..0xdf
511               addr = 96*7 + (md - 0xa0) * 7 + cl;
512            }
513            else if (md >= 0xe0 && cl < 11)
514            {
515               // 5x11 characters 0xe0..0xff
516               addr = 160*7 + (md - 0xe0) * 11 + cl;
517            }
518
519            data = subregion("hd61830")->u8(addr);
520         }
521
522         int cursor = m_mcr & MODE_CURSOR;
523         int blink = m_mcr & MODE_BLINK;
524
525         // cursor off
526         int pixel = BIT(data, cr);
527
528         if (blink && (ma == m_cac))
529         {
530            // cursor off, character blink
531            if (!cursor)
532               pixel = m_cursor ? pixel : 0;
533
534            // cursor blink
535            if (cursor && (cl == m_cp))
536               pixel = m_cursor ? 1 : 0;
537         }
538         else
539         {
540            // cursor on
541            if (cursor && (cl == m_cp))
542               pixel = m_cursor ? 1 : 0;
543         }
544
545         if (sy < m_screen->height() && sx < m_screen->width())
546            *BITMAP_ADDR16(bitmap, sy, sx) = pixel;
547      }
548   }
549}
550
551
552//-------------------------------------------------
553//  update_text - draw text mode screen
554//-------------------------------------------------
555
556void hd61830_device::update_text(bitmap_t *bitmap, const rectangle *cliprect)
557{
558   for (int y = 0; y < (m_nx / m_vp); y++)
559   {
560      for (int x = 0; x < m_hn; x++)
561      {
562         UINT16 ma = y * m_hn + x;
563         UINT8 md = readbyte(ma);
564
565         draw_char(bitmap, cliprect, ma, x, y, md);
566      }
567   }
568}
569
570
571//-------------------------------------------------
572//  update_screen - update screen
573//-------------------------------------------------
574
575void hd61830_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect)
576{
577   if (m_mcr & MODE_DISPLAY_ON)
578   {
579      if (m_mcr & MODE_GRAPHIC)
580      {
581         update_graphics(bitmap, cliprect);
582      }
583      else
584      {
585         update_text(bitmap, cliprect);
586      }
587   }
588   else
589   {
590      bitmap_fill(bitmap, cliprect, 0);
591   }
592
593   m_blink++;
594
595   if (m_blink == 0x20)
596   {
597      m_blink = 0;
598      m_cursor = !m_cursor;
599   }
600}
src/mess/video/hd61830.h
r10968r10969
1/**********************************************************************
2
3    HD61830 LCD Timing Controller emulation
4
5    Copyright MESS Team.
6    Visit http://mamedev.org for licensing and usage restrictions.
7
8**********************************************************************/
9
10#pragma once
11
12#ifndef __HD61830__
13#define __HD61830__
14
15#include "emu.h"
16
17
18
19//**************************************************************************
20//  MACROS / CONSTANTS
21//**************************************************************************
22
23
24
25
26//**************************************************************************
27//  INTERFACE CONFIGURATION MACROS
28//**************************************************************************
29
30#define MCFG_HD61830_ADD(_tag, _clock, _config) \
31   MCFG_DEVICE_ADD(_tag, HD61830, _clock) \
32   MCFG_DEVICE_CONFIG(_config)
33
34
35#define HD61830_INTERFACE(name) \
36   const hd61830_interface (name) =
37
38
39
40//**************************************************************************
41//  TYPE DEFINITIONS
42//**************************************************************************
43
44// ======================> hd61830_interface
45
46struct hd61830_interface
47{
48   const char *screen_tag;
49
50    devcb_read8 m_in_rd_func;
51};
52
53
54
55// ======================> hd61830_device_config
56
57class hd61830_device_config :   public device_config,
58                        public device_config_memory_interface,
59                                public hd61830_interface
60{
61    friend class hd61830_device;
62
63    // construction/destruction
64    hd61830_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
65
66public:
67    // allocators
68    static device_config *static_alloc_device_config(const machine_config &mconfig, const char *tag, const device_config *owner, UINT32 clock);
69    virtual device_t *alloc_device(running_machine &machine) const;
70
71   // optional information overrides
72   virtual const rom_entry *rom_region() const;
73
74protected:
75   // device_config overrides
76   virtual void device_config_complete();
77
78   // device_config_memory_interface overrides
79   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
80
81    // address space configurations
82   const address_space_config      m_space_config;
83};
84
85
86
87// ======================> hd61830_device
88
89class hd61830_device :   public device_t,
90                  public device_memory_interface
91{
92    friend class hd61830_device_config;
93
94    // construction/destruction
95    hd61830_device(running_machine &_machine, const hd61830_device_config &_config);
96
97public:
98    DECLARE_READ8_MEMBER( status_r );
99    DECLARE_WRITE8_MEMBER( control_w );
100
101    DECLARE_READ8_MEMBER( data_r );
102    DECLARE_WRITE8_MEMBER( data_w );
103
104   void update_screen(bitmap_t *bitmap, const rectangle *cliprect);
105
106protected:
107    // device-level overrides
108    virtual void device_start();
109    virtual void device_reset();
110   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
111
112   inline UINT8 readbyte(offs_t address);
113   inline void writebyte(offs_t address, UINT8 data);
114
115private:
116   void set_busy_flag();
117
118   void draw_scanline(bitmap_t *bitmap, const rectangle *cliprect, int y, UINT16 ra);
119   void update_graphics(bitmap_t *bitmap, const rectangle *cliprect);
120   void draw_char(bitmap_t *bitmap, const rectangle *cliprect, UINT16 ma, int x, int y, UINT8 md);
121   void update_text(bitmap_t *bitmap, const rectangle *cliprect);
122
123    devcb_resolved_read8 m_in_rd_func;
124
125   screen_device *m_screen;
126   emu_timer *m_busy_timer;
127   address_space *m_data;
128
129   bool m_bf;                  // busy flag
130
131   UINT8 m_ir;                  // instruction register
132   UINT8 m_mcr;               // mode control register
133   UINT8 m_dor;               // data output register
134
135   UINT16 m_dsa;               // display start address
136   UINT16 m_cac;               // cursor address counter
137
138   int m_vp;                  // vertical character pitch
139   int m_hp;                  // horizontal character pitch
140   int m_hn;                  // horizontal number of characters
141   int m_nx;                  // number of time divisions
142   int m_cp;                  // cursor position
143
144    int m_blink;               // blink counter
145   int m_cursor;               // cursor visible
146
147   const hd61830_device_config &m_config;
148};
149
150
151// device type definition
152extern const device_type HD61830;
153
154
155
156#endif
src/mess/mess.mak
r10968r10969
515515   $(MESS_MACHINE)/at29040.o   \
516516   $(MESS_MACHINE)/at45dbxx.o   \
517517   $(MESS_MACHINE)/ay31015.o   \
518   $(MESS_MACHINE)/cdp1871.o   \
519518   $(MESS_MACHINE)/ctronics.o   \
520519   $(MESS_MACHINE)/com8116.o   \
521   $(MESS_MACHINE)/e0516.o      \
522520   $(MESS_MACHINE)/er59256.o   \
523521   $(MESS_MACHINE)/hd63450.o   \
524   $(MESS_MACHINE)/i8155.o      \
525   $(MESS_MACHINE)/i8212.o      \
526522   $(MESS_MACHINE)/i8214.o      \
527523   $(MESS_MACHINE)/i82371ab.o   \
528524   $(MESS_MACHINE)/i82439tx.o   \
529525   $(MESS_MACHINE)/i8271.o      \
530   $(MESS_MACHINE)/i8355.o      \
531526   $(MESS_MACHINE)/ieee488.o   \
532527   $(MESS_MACHINE)/isa.o      \
533528   $(MESS_MACHINE)/kb3600.o   \
r10968r10969
542537   $(MESS_MACHINE)/msm58321.o   \
543538   $(MESS_MACHINE)/msm8251.o   \
544539   $(MESS_MACHINE)/mos6530.o   \
545   $(MESS_MACHINE)/nmc9306.o   \
546540   $(MESS_MACHINE)/upd765.o   \
547541   $(MESS_MACHINE)/ncr5380.o   \
548542   $(MESS_MACHINE)/pc_lpt.o   \
r10968r10969
563557   $(MESS_MACHINE)/upd7002.o   \
564558   $(MESS_MACHINE)/upd7201.o   \
565559   $(MESS_MACHINE)/wd17xx.o   \
566   $(MESS_MACHINE)/z8536.o   \
567560   $(MESS_VIDEO)/cdp1861.o      \
568561   $(MESS_VIDEO)/cdp1862.o      \
569   $(MESS_VIDEO)/crt9007.o      \
570   $(MESS_VIDEO)/crt9021.o      \
571   $(MESS_VIDEO)/crt9212.o      \
572562   $(MESS_VIDEO)/crtc6845.o   \
573563   $(MESS_VIDEO)/dl1416.o      \
574564   $(MESS_VIDEO)/dm9368.o      \
575565   $(MESS_VIDEO)/hd44102.o      \
576566   $(MESS_VIDEO)/hd44780.o      \
577   $(MESS_VIDEO)/hd61830.o      \
578567   $(MESS_VIDEO)/hd66421.o      \
579568   $(MESS_VIDEO)/i82720.o      \
580569   $(MESS_VIDEO)/i8275.o      \

Previous 15994 Revisions Next


© 1998-2018 The MESS Team