Previous 15994 Revisions Next

r13282 Wednesday 16th November, 2011 at 15:55:27 UTC by Fabio Priuli
hd66421: converted to be a C++ device [Fabio Priuli]
[src/mess/drivers]cybiko.c
[src/mess/machine]cybiko.c
[src/mess/video]hd66421.c hd66421.h tms3556.h

src/mess/machine/cybiko.c
r13281r13282
405405
406406READ16_HANDLER( cybiko_lcd_r )
407407{
408   hd66421_device *hd66421 = space->machine().device<hd66421_device>( "hd66421" );
408409   UINT16 data = 0;
409   if (ACCESSING_BITS_8_15) data = data | (hd66421_reg_idx_r() << 8);
410   if (ACCESSING_BITS_0_7) data = data | (hd66421_reg_dat_r() << 0);
410   if (ACCESSING_BITS_8_15) data = data | (hd66421->reg_idx_r(*space, offset) << 8);
411   if (ACCESSING_BITS_0_7) data = data | (hd66421->reg_dat_r(*space, offset) << 0);
411412   return data;
412413}
413414
414415WRITE16_HANDLER( cybiko_lcd_w )
415416{
416   if (ACCESSING_BITS_8_15) hd66421_reg_idx_w( (data >> 8) & 0xFF);
417   if (ACCESSING_BITS_0_7) hd66421_reg_dat_w( (data >> 0) & 0xFF);
417   hd66421_device *hd66421 = space->machine().device<hd66421_device>( "hd66421" );
418   if (ACCESSING_BITS_8_15) hd66421->reg_idx_w(*space, offset, (data >> 8) & 0xff);
419   if (ACCESSING_BITS_0_7) hd66421->reg_dat_w(*space, offset, (data >> 0) & 0xff);
418420}
419421
420422static READ16_HANDLER( cybiko_key_r )
src/mess/video/tms3556.h
r13281r13282
1/*
2    tms3556.h: header file for tms3556.c
3*/
1/***************************************************************************
2 
3  Texas Instruments TMS3556 Video Display Processor
4 
5 ***************************************************************************/
46
7
8#pragma once
9
510#ifndef __TMS3556_H__
611#define __TMS3556_H__
712
8#include "emu.h"
9
10
1113///*************************************************************************
1214//  MACROS / CONSTANTS
1315///*************************************************************************
r13281r13282
3335///*************************************************************************
3436
3537#define MCFG_TMS3556_ADD(_tag) \
36MCFG_DEVICE_ADD(_tag, TMS3556, 0) \
38   MCFG_DEVICE_ADD(_tag, TMS3556, 0) \
3739
3840
3941///*************************************************************************
src/mess/video/hd66421.c
r13281r13282
99#include "emu.h"
1010#include "hd66421.h"
1111
12//**************************************************************************
13//  MACROS / CONSTANTS
14//**************************************************************************
15
1216#define LOG_LEVEL  1
1317#define _logerror(level,x)  do { if (LOG_LEVEL > level) logerror x; } while (0)
1418
15//#define BRIGHTNESS_DOES_NOT_WORK
16
1719#define HD66421_RAM_SIZE  (HD66421_WIDTH * HD66421_HEIGHT / 4) // 2-bits per pixel
1820
1921// R0 - control register 1
r13281r13282
5658#define LCD_REG_CONTRAST    0x10 // contrast control register
5759#define LCD_REG_PLANE       0x11 // plane selection register
5860
59typedef struct
61//**************************************************************************
62//  GLOBAL VARIABLES
63//**************************************************************************
64
65// devices
66const device_type HD66421 = &device_creator<hd66421_device>;
67
68
69// default address map
70static ADDRESS_MAP_START( hd66421, AS_0, 8 )
71   AM_RANGE(0x0000, HD66421_RAM_SIZE) AM_RAM
72ADDRESS_MAP_END
73
74//-------------------------------------------------
75//  memory_space_config - return a description of
76//  any address spaces owned by this device
77//-------------------------------------------------
78
79const address_space_config *hd66421_device::memory_space_config(address_spacenum spacenum) const
6080{
61   UINT8 cmd, reg[32];
62   UINT8 *ram;
63   int x, y;
64} HD66421;
81   return (spacenum == AS_0) ? &m_space_config : NULL;
82}
6583
66static HD66421 lcd;
6784
68UINT8 hd66421_reg_idx_r(void)
85//**************************************************************************
86//  INLINE HELPERS
87//**************************************************************************
88
89//-------------------------------------------------
90//  readbyte - read a byte at the given address
91//-------------------------------------------------
92
93inline UINT8 hd66421_device::readbyte(offs_t address)
6994{
70   _logerror( 2, ("hd66421_reg_idx_r\n"));
71   return lcd.cmd;
95   return space()->read_byte(address);
7296}
7397
74void hd66421_reg_idx_w(UINT8 data)
98
99//-------------------------------------------------
100//  writebyte - write a byte at the given address
101//-------------------------------------------------
102
103inline void hd66421_device::writebyte(offs_t address, UINT8 data)
75104{
76   _logerror( 2, ("hd66421_reg_idx_w (%02X)\n", data));
77   lcd.cmd = data;
105   space()->write_byte(address, data);
78106}
79107
80UINT8 hd66421_reg_dat_r(void)
108
109//**************************************************************************
110//  LIVE DEVICE
111//**************************************************************************
112
113//-------------------------------------------------
114//  hd66421_device - constructor
115//-------------------------------------------------
116
117hd66421_device::hd66421_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
118   : device_t(mconfig, HD66421, "Hitachi HD66421 LCD Controller", tag, owner, clock),
119     device_memory_interface(mconfig, *this),
120     m_space_config("videoram", ENDIANNESS_LITTLE, 8, 17, 0, NULL, *ADDRESS_MAP_NAME(hd66421)),
121     m_cmd(0),
122     m_x(0),
123     m_y(0)
81124{
82   _logerror( 2, ("hd66421_reg_dat_r\n"));
83   return lcd.reg[lcd.cmd];
125   for (int i = 0; i < 32; i++)
126   {
127      m_reg[i] = 0;
128   }
84129}
85130
86void hd66421_reg_dat_w(UINT8 data)
131
132//-------------------------------------------------
133//  device_start - device-specific startup
134//-------------------------------------------------
135
136void hd66421_device::device_start()
137{   
138   // register for state saving
139   save_item(NAME(m_cmd));
140   save_item(NAME(m_reg));
141   save_item(NAME(m_x));
142   save_item(NAME(m_y));
143}
144
145READ8_MEMBER( hd66421_device::reg_idx_r )
87146{
88   _logerror( 2, ("hd66421_reg_dat_w (%02X)\n", data));
89   lcd.reg[lcd.cmd] = data;
90   switch (lcd.cmd)
147   _logerror( 2, ("reg_idx_r\n"));
148   return m_cmd;
149}
150
151WRITE8_MEMBER( hd66421_device::reg_idx_w )
152{
153   _logerror( 2, ("reg_idx_w (%02X)\n", data));
154   m_cmd = data;
155}
156
157READ8_MEMBER( hd66421_device::reg_dat_r )
158{
159   _logerror( 2, ("reg_dat_r\n"));
160   return m_reg[m_cmd];
161}
162
163WRITE8_MEMBER( hd66421_device::reg_dat_w )
164{
165   _logerror( 2, ("reg_dat_w (%02X)\n", data));
166   m_reg[m_cmd] = data;
167
168   switch (m_cmd)
91169   {
92170      case LCD_REG_ADDR_X :
93      {
94         lcd.x = data;
95      }
96      break;
171         m_x = data;
172         break;
173
97174      case LCD_REG_ADDR_Y :
98      {
99         lcd.y = data;
100      }
101      break;
175         m_y = data;
176         break;
177
102178      case LCD_REG_RAM :
103179      {
104180         UINT8 r1;
105         *(lcd.ram + lcd.y * (HD66421_WIDTH / 4) + lcd.x) = data;
106         r1 = lcd.reg[LCD_REG_CONTROL_2];
181         writebyte(m_y * (HD66421_WIDTH / 4) + m_x, data);
182         r1 = m_reg[LCD_REG_CONTROL_2];
107183         if (r1 & 0x02)
108         {
109            lcd.x++;
110         }
184            m_x++;
111185         else
186            m_y++;
187
188         if (m_x >= (HD66421_WIDTH / 4))
112189         {
113            lcd.y++;
190            m_x = 0;
191            m_y++;
114192         }
115         if (lcd.x >= (HD66421_WIDTH / 4))
116         {
117            lcd.x = 0;
118            lcd.y++;
119         }
120         if (lcd.y >= HD66421_HEIGHT)
121         {
122            lcd.y = 0;
123         }
193
194         if (m_y >= HD66421_HEIGHT)
195            m_y = 0;
124196      }
125197      break;
126198   }
127199}
128200
129INLINE void hd66421_plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color)
201void hd66421_device::plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color)
130202{
131   *BITMAP_ADDR16( bitmap, y, x) = (UINT16)color;
203   *BITMAP_ADDR16(bitmap, y, x) = (UINT16)color;
132204}
133205
134PALETTE_INIT( hd66421 )
206void hd66421_device::update_screen(bitmap_t *bitmap, const rectangle *cliprect)
135207{
136   int i;
137   _logerror( 0, ("palette_init_hd66421\n"));
138   // init palette
139   for (i=0;i<4;i++)
140   {
141      palette_set_color( machine, i, RGB_WHITE);
142      #ifndef BRIGHTNESS_DOES_NOT_WORK
143      palette_set_pen_contrast( machine, i, 1.0 * i / (4 - 1));
144      #endif
145   }
146}
208   pen_t pen[4];
147209
148static void hd66421_state_save(running_machine &machine)
149{
150   const char *name = "hd66421";
151   state_save_register_item(machine, name, NULL, 0, lcd.cmd);
152   state_save_register_item_array(machine, name, NULL, 0, lcd.reg);
153   state_save_register_item(machine, name, NULL, 0, lcd.x);
154   state_save_register_item(machine, name, NULL, 0, lcd.y);
155   state_save_register_item_pointer(machine, name, NULL, 0, lcd.ram, HD66421_RAM_SIZE);
156}
210   _logerror( 1, ("video_update_hd66421\n"));
157211
158VIDEO_START( hd66421 )
159{
160   _logerror( 0, ("video_start_hd66421\n"));
161   memset( &lcd, 0, sizeof( lcd));
162   lcd.ram = auto_alloc_array(machine, UINT8, HD66421_RAM_SIZE);
163   hd66421_state_save(machine);
164}
165
166SCREEN_UPDATE( hd66421 )
167{
168   pen_t pen[4];
169   int i;
170   _logerror( 1, ("video_update_hd66421\n"));
171212   // update palette
172   for (i=0;i<4;i++)
213   for (int i = 0; i < 4; i++)
173214   {
174215      double bright;
175216      int temp;
176      temp = 31 - (lcd.reg[LCD_REG_COLOR_1+i] - lcd.reg[LCD_REG_CONTRAST] + 0x03);
217      temp = 31 - (m_reg[LCD_REG_COLOR_1 + i] - m_reg[LCD_REG_CONTRAST] + 0x03);
177218      if (temp <  0) temp =  0;
178219      if (temp > 31) temp = 31;
179220      bright = 1.0 * temp / 31;
180221      pen[i] = i;
181      #ifdef BRIGHTNESS_DOES_NOT_WORK
182      palette_set_color(screen->machine(), pen[i], 255 * bright, 255 * bright, 255 * bright);
222      #ifdef HD66421_BRIGHTNESS_DOES_NOT_WORK
223      palette_set_color(machine(), pen[i], 255 * bright, 255 * bright, 255 * bright);
183224      #else
184      palette_set_pen_contrast(screen->machine(), pen[i], bright);
225      palette_set_pen_contrast(machine(), pen[i], bright);
185226      #endif
186227   }
228
187229   // draw bitmap (bottom to top)
188   if (lcd.reg[0] & LCD_R0_DISP)
230   if (m_reg[0] & LCD_R0_DISP)
189231   {
190232      int x, y;
191233      x = 0;
192234      y = HD66421_HEIGHT - 1;
193      for (i=0;i<HD66421_RAM_SIZE;i++)
235
236      for (int i = 0; i < HD66421_RAM_SIZE; i++)
194237      {
195         hd66421_plot_pixel( bitmap, x++, y, pen[(lcd.ram[i] >> 6) & 3]);
196         hd66421_plot_pixel( bitmap, x++, y, pen[(lcd.ram[i] >> 4) & 3]);
197         hd66421_plot_pixel( bitmap, x++, y, pen[(lcd.ram[i] >> 2) & 3]);
198         hd66421_plot_pixel( bitmap, x++, y, pen[(lcd.ram[i] >> 0) & 3]);
238         plot_pixel(bitmap, x++, y, pen[(readbyte(i) >> 6) & 3]);
239         plot_pixel(bitmap, x++, y, pen[(readbyte(i) >> 4) & 3]);
240         plot_pixel(bitmap, x++, y, pen[(readbyte(i) >> 2) & 3]);
241         plot_pixel(bitmap, x++, y, pen[(readbyte(i) >> 0) & 3]);
199242         if (x >= HD66421_WIDTH)
200243         {
201244            x = 0;
r13281r13282
210253      rect.max_x = HD66421_WIDTH - 1;
211254      rect.min_y = 0;
212255      rect.max_y = HD66421_HEIGHT - 1;
213      bitmap_fill( bitmap, &rect, get_white_pen(screen->machine()));
256      bitmap_fill(bitmap, &rect, get_white_pen(machine()));
214257   }
215   // flags
216   return 0;
217258}
src/mess/video/hd66421.h
r13281r13282
1/*
1/***************************************************************************
2 
3  Hitachi HD66421 LCD Controller
24
3    Hitachi HD66421 LCD Controller/Driver
5  (c) 2001-2007 Tim Schuerewegen
46
5    (c) 2001-2007 Tim Schuerewegen
7 ***************************************************************************/
68
7*/
9#pragma once
810
9#ifndef HD66421_H_
10#define HD66421_H_
11#ifndef __HD66421_H__
12#define __HD66421_H__
1113
1214
15///*************************************************************************
16//  MACROS / CONSTANTS
17///*************************************************************************
18
19//#define HD66421_BRIGHTNESS_DOES_NOT_WORK
20
1321#define HD66421_WIDTH   160
1422#define HD66421_HEIGHT  100
1523
1624
1725/*----------- defined in video/hd66421.c -----------*/
1826
19UINT8 hd66421_reg_idx_r(void);
20void hd66421_reg_idx_w(UINT8 data);
27///*************************************************************************
28//  INTERFACE CONFIGURATION MACROS
29///*************************************************************************
2130
22UINT8 hd66421_reg_dat_r(void);
23void hd66421_reg_dat_w(UINT8 data);
31#define MCFG_HD66421_ADD(_tag) \
32   MCFG_DEVICE_ADD(_tag, HD66421, 0) \
2433
25PALETTE_INIT( hd66421 );
2634
27VIDEO_START( hd66421 );
28SCREEN_UPDATE( hd66421 );
35///*************************************************************************
36//  TYPE DEFINITIONS
37///*************************************************************************
2938
39// ======================> hd66421_device
3040
31#endif /* HD66421_H_ */
41class hd66421_device :   public device_t,
42                  public device_memory_interface
43{
44public:
45    // construction/destruction
46    hd66421_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
47   
48   DECLARE_READ8_MEMBER( reg_idx_r );
49   DECLARE_WRITE8_MEMBER( reg_idx_w );
50   DECLARE_READ8_MEMBER( reg_dat_r );
51   DECLARE_WRITE8_MEMBER( reg_dat_w );
52   
53   void update_screen(bitmap_t *bitmap, const rectangle *cliprect);
54   
55protected:
56    // device-level overrides
57    virtual void device_start();
58   
59   // device_config_memory_interface overrides
60   virtual const address_space_config *memory_space_config(address_spacenum spacenum = AS_0) const;
61   
62    // address space configurations
63   const address_space_config      m_space_config;
64   
65   inline UINT8 readbyte(offs_t address);
66   inline void writebyte(offs_t address, UINT8 data);
67
68   void plot_pixel(bitmap_t *bitmap, int x, int y, UINT32 color);
69   
70private:
71   UINT8 m_cmd, m_reg[32];
72   int m_x, m_y;
73};
74
75
76// device type definition
77extern const device_type HD66421;
78
79
80#endif
src/mess/drivers/cybiko.c
r13281r13282
289289INPUT_PORTS_END
290290
291291////////////////////
292// PALETTE INIT   //
293////////////////////
294
295PALETTE_INIT( hd66421 )
296{
297   // init palette
298   for (int i = 0; i < 4; i++)
299   {
300      palette_set_color(machine, i, RGB_WHITE);
301#ifndef HD66421_BRIGHTNESS_DOES_NOT_WORK
302      palette_set_pen_contrast(machine, i, 1.0 * i / (4 - 1));
303#endif
304   }
305}
306
307////////////////////
308// SCREEN UPDATE  //
309////////////////////
310
311static SCREEN_UPDATE( cybiko )
312{
313   hd66421_device *hd66421 = screen->machine().device<hd66421_device>( "hd66421" );
314   hd66421->update_screen(bitmap, cliprect);
315   return 0;
316}
317
318
319////////////////////
292320// MACHINE DRIVER //
293321////////////////////
294322
r13281r13282
303331   MCFG_SCREEN_FORMAT( BITMAP_FORMAT_INDEXED16 )
304332   MCFG_SCREEN_SIZE( HD66421_WIDTH, HD66421_HEIGHT )
305333   MCFG_SCREEN_VISIBLE_AREA( 0, HD66421_WIDTH - 1, 0, HD66421_HEIGHT - 1 )
306   MCFG_SCREEN_UPDATE(hd66421)
334   MCFG_SCREEN_UPDATE(cybiko)
307335
308336   // video
337   MCFG_HD66421_ADD("hd66421")
309338   MCFG_PALETTE_LENGTH(4)
310339   MCFG_PALETTE_INIT(hd66421)
311   MCFG_VIDEO_START(hd66421)
312340   MCFG_DEFAULT_LAYOUT(layout_lcd)
313341   // sound
314342   MCFG_SPEAKER_STANDARD_MONO("mono")

Previous 15994 Revisions Next


© 1998-2018 The MESS Team