Previous 199869 Revisions Next

r22774 Saturday 11th May, 2013 at 20:24:53 UTC by Wilbert Pol
(MESS) Modernized neogeo pocket video. (nw)
[src/mess/drivers]ngp.c
[src/mess/video]k1ge.c k1ge.h

trunk/src/mess/drivers/ngp.c
r22773r22774
168168   required_device<dac_device> m_dac_l;
169169   required_device<dac_device> m_dac_r;
170170   required_shared_ptr<UINT8> m_mainram;
171   required_device<device_t> m_k1ge;
171   required_device<k1ge_device> m_k1ge;
172172
173173   DECLARE_READ8_MEMBER( ngp_io_r );
174174   DECLARE_WRITE8_MEMBER( ngp_io_w );
r22773r22774
183183
184184   DECLARE_WRITE8_MEMBER( ngp_z80_clear_irq );
185185
186   DECLARE_WRITE8_MEMBER( ngp_vblank_pin_w );
187   DECLARE_WRITE8_MEMBER( ngp_hblank_pin_w );
186   DECLARE_WRITE_LINE_MEMBER( ngp_vblank_pin_w );
187   DECLARE_WRITE_LINE_MEMBER( ngp_hblank_pin_w );
188188   DECLARE_WRITE8_MEMBER( ngp_tlcs900_to3 );
189189   UINT32 screen_update_ngp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
190190   DECLARE_INPUT_CHANGED_MEMBER(power_callback);
r22773r22774
541541   AM_RANGE( 0x000080, 0x0000bf )  AM_READWRITE(ngp_io_r, ngp_io_w)                            /* ngp/c specific i/o */
542542   AM_RANGE( 0x004000, 0x006fff )  AM_RAM AM_SHARE("mainram")                                  /* work ram */
543543   AM_RANGE( 0x007000, 0x007fff )  AM_RAM AM_SHARE("share1")                                   /* shared with sound cpu */
544   AM_RANGE( 0x008000, 0x0087ff )  AM_DEVREADWRITE_LEGACY("k1ge", k1ge_r, k1ge_w)              /* video registers */
544   AM_RANGE( 0x008000, 0x0087ff )  AM_DEVREADWRITE("k1ge", k1ge_device, read, write)           /* video registers */
545545   AM_RANGE( 0x008800, 0x00bfff )  AM_RAM AM_REGION("vram", 0x800 )                            /* Video RAM area */
546546   AM_RANGE( 0x200000, 0x3fffff )  AM_ROM AM_WRITE(flash0_w) AM_REGION("cart", 0)              /* cart area #1 */
547547   AM_RANGE( 0x800000, 0x9fffff )  AM_ROM AM_WRITE(flash1_w) AM_REGION("cart", 0x200000)       /* cart area #2 */
r22773r22774
614614INPUT_PORTS_END
615615
616616
617WRITE8_MEMBER( ngp_state::ngp_vblank_pin_w )
617WRITE_LINE_MEMBER( ngp_state::ngp_vblank_pin_w )
618618{
619   m_tlcs900->set_input_line(TLCS900_INT4, data ? ASSERT_LINE : CLEAR_LINE );
619   m_tlcs900->set_input_line(TLCS900_INT4, state ? ASSERT_LINE : CLEAR_LINE );
620620}
621621
622622
623WRITE8_MEMBER( ngp_state::ngp_hblank_pin_w )
623WRITE_LINE_MEMBER( ngp_state::ngp_hblank_pin_w )
624624{
625   m_tlcs900->set_input_line(TLCS900_TIO, data ? ASSERT_LINE : CLEAR_LINE );
625   m_tlcs900->set_input_line(TLCS900_TIO, state ? ASSERT_LINE : CLEAR_LINE );
626626}
627627
628628
r22773r22774
696696
697697UINT32 ngp_state::screen_update_ngp(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
698698{
699   k1ge_update( m_k1ge, bitmap, cliprect );
699   m_k1ge->update( bitmap, cliprect );
700700   return 0;
701701}
702702
r22773r22774
787787}
788788
789789
790static const k1ge_interface ngp_k1ge_interface =
791{
792   "screen",
793   "vram",
794   DEVCB_DRIVER_MEMBER( ngp_state, ngp_vblank_pin_w ),
795   DEVCB_DRIVER_MEMBER( ngp_state, ngp_hblank_pin_w )
796};
797
798
799790static const tlcs900_interface ngp_tlcs900_interface =
800791{
801792   DEVCB_NULL,
r22773r22774
838829   MCFG_PALETTE_LENGTH( 8 )
839830   MCFG_PALETTE_INIT( k1ge )
840831
841   MCFG_K1GE_ADD( "k1ge", XTAL_6_144MHz, ngp_k1ge_interface )
832   MCFG_K1GE_ADD( "k1ge", XTAL_6_144MHz, "screen", "vram", WRITELINE( ngp_state, ngp_vblank_pin_w ), WRITELINE( ngp_state, ngp_hblank_pin_w ) )
842833
843834   MCFG_CARTSLOT_ADD("cart")
844835   MCFG_CARTSLOT_EXTENSION_LIST("bin,ngp,npc,ngc")
r22773r22774
858849   MCFG_PALETTE_LENGTH( 4096 )
859850   MCFG_PALETTE_INIT( k2ge )
860851
861   MCFG_K2GE_ADD( "k1ge", XTAL_6_144MHz, ngp_k1ge_interface )
852   MCFG_K2GE_ADD( "k1ge", XTAL_6_144MHz, "screen", "vram", WRITELINE( ngp_state, ngp_vblank_pin_w ), WRITELINE( ngp_state, ngp_hblank_pin_w ) )
862853
863854   MCFG_CARTSLOT_ADD("cart")
864855   MCFG_CARTSLOT_EXTENSION_LIST("bin,ngp,npc,ngc")
trunk/src/mess/video/k1ge.c
r22773r22774
1010#include "emu.h"
1111#include "k1ge.h"
1212
13struct k1ge_t
14{
15   const k1ge_interface *intf;
16   screen_device *screen;
17   devcb_resolved_write8 vblank_pin_w;
18   devcb_resolved_write8 hblank_pin_w;
19   UINT8 *vram;
20   UINT8 wba_h, wba_v, wsi_h, wsi_v;
2113
22   void (*draw)( device_t *device, int line );
23
24   emu_timer *timer;
25   emu_timer *hblank_on_timer;
26   bitmap_ind16 *bitmap;
27};
28
29
3014PALETTE_INIT( k1ge )
3115{
3216   int i;
r22773r22774
5741}
5842
5943
60INLINE k1ge_t *get_safe_token( device_t *device )
44READ8_MEMBER( k1ge_device::read )
6145{
62   assert( device != NULL );
63   assert( device->type() == K1GE || device->type() == K2GE );
46   UINT8   data = m_vram[offset & 0x7ff];
6447
65   return ( k1ge_t *) downcast<k1ge_device *>(device)->token();
66}
67
68
69READ8_DEVICE_HANDLER( k1ge_r )
70{
71   k1ge_t  *k1ge = get_safe_token( device );
72   UINT8   data = k1ge->vram[offset & 0x7ff];
73
7448   switch( offset )
7549   {
7650   case 0x008:     /* RAS.H */
77      data = k1ge->screen->hpos() >> 2;
51      data = m_screen->hpos() >> 2;
7852      break;
7953   case 0x009:     /* RAS.V */
80      data = k1ge->screen->vpos();
54      data = m_screen->vpos();
8155      break;
8256   }
8357   return data;
8458}
8559
8660
87WRITE8_DEVICE_HANDLER( k1ge_w )
61WRITE8_MEMBER( k1ge_device::write )
8862{
89   k1ge_t  *k1ge = get_safe_token( device );
90
9163   switch( offset )
9264   {
9365   case 0x000:
94      if (!k1ge->vblank_pin_w.isnull())
95         k1ge->vblank_pin_w(0, ( data & 0x80 ) ? ( ( k1ge->vram[0x010] & 0x40 ) ? 1 : 0 ) : 0 );
66      m_vblank_pin_w( ( data & 0x80 ) ? ( ( m_vram[0x010] & 0x40 ) ? 1 : 0 ) : 0 );
9667      break;
9768   case 0x030:
9869      data &= 0x80;
r22773r22774
10677      data &= 0x07;
10778      break;
10879   case 0x7e2:
109      if ( k1ge->vram[0x7f0] != 0xAA )
80      if ( m_vram[0x7f0] != 0xAA )
11081         return;
11182      data &= 0x80;
11283      break;
r22773r22774
11889      data &= 0x0f;
11990   }
12091
121   k1ge->vram[offset & 0x7ff] = data;
92   m_vram[offset & 0x7ff] = data;
12293}
12394
12495
125INLINE void k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, int pal_base )
96void k1ge_device::draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, int pal_base )
12697{
12798   int i;
12899   int offset_x = ( scroll_x >> 3 ) * 2;
r22773r22774
136107   base += ( ( ( ( scroll_y + line ) >> 3 ) * 0x0040 ) & 0x7ff );
137108
138109   /* setup */
139   map_data = k1ge->vram[ base + offset_x  ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
110   map_data = m_vram[ base + offset_x  ] | ( m_vram[ base + offset_x + 1 ] << 8 );
140111   hflip = map_data & 0x8000;
141112   pcode = pal_base + ( ( map_data & 0x2000 ) ? 4 : 0 );
142113   tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
r22773r22774
144115      tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
145116   else
146117      tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
147   tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
118   tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
148119   if ( hflip )
149120      tile_data >>= 2 * ( scroll_x & 0x07 );
150121   else
r22773r22774
168139
169140      if ( col )
170141      {
171         p[ i ] = k1ge->vram[ pcode + col ];
142         p[ i ] = m_vram[ pcode + col ];
172143      }
173144
174145      px++;
175146      if ( px >= 8 )
176147      {
177148         offset_x = ( offset_x + 2 ) & 0x3f;
178         map_data = k1ge->vram[ base + offset_x ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
149         map_data = m_vram[ base + offset_x ] | ( m_vram[ base + offset_x + 1 ] << 8 );
179150         hflip = map_data & 0x8000;
180151         pcode = pal_base + ( ( map_data & 0x2000 ) ? 4 : 0 );
181152         tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
r22773r22774
183154            tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
184155         else
185156            tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
186         tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
157         tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
187158         px = 0;
188159      }
189160   }
190161}
191162
192163
193INLINE void k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
164void k1ge_device::draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
194165{
195166   struct {
196167      UINT16 spr_data;
r22773r22774
207178   /* Select sprites */
208179   for ( i = 0; i < 256; i += 4 )
209180   {
210      UINT16 spr_data = k1ge->vram[ 0x800 + i ] | ( k1ge->vram[ 0x801 + i ] << 8 );
211      UINT8 x = k1ge->vram[ 0x802 + i ];
212      UINT8 y = k1ge->vram[ 0x803 + i ];
181      UINT16 spr_data = m_vram[ 0x800 + i ] | ( m_vram[ 0x801 + i ] << 8 );
182      UINT8 x = m_vram[ 0x802 + i ];
183      UINT8 y = m_vram[ 0x803 + i ];
213184
214185      spr_x = ( spr_data & 0x0400 ) ? ( spr_x + x ) :  ( scroll_x + x );
215186      spr_y = ( spr_data & 0x0200 ) ? ( spr_y + y ) :  ( scroll_y + y );
r22773r22774
239210         tile_addr += ( 7 - ( ( line - spr[i].y ) & 0x07 ) ) * 2;
240211      else
241212         tile_addr += ( ( line - spr[i].y ) & 0x07 ) * 2;
242      tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
213      tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
243214
244215      for ( j = 0; j < 8; j++ )
245216      {
r22773r22774
260231
261232         if ( spr_x < 160 && col )
262233         {
263            p[ spr_x ] = k1ge->vram[ pcode + col ];
234            p[ spr_x ] = m_vram[ pcode + col ];
264235         }
265236      }
266237   }
267238}
268239
269240
270static void k1ge_draw( device_t *device, int line )
241void k1ge_device::draw( int line )
271242{
272   k1ge_t *k1ge = get_safe_token( device );
273   UINT16 *p = &k1ge->bitmap->pix16(line);
274   UINT16 oowcol = k1ge->vram[0x012] & 0x07;
243   UINT16 *p = &m_bitmap->pix16(line);
244   UINT16 oowcol = m_vram[0x012] & 0x07;
275245   int i;
276246
277   if ( line < k1ge->wba_v || line >= k1ge->wba_v + k1ge->wsi_v )
247   if ( line < m_wba_v || line >= m_wba_v + m_wsi_v )
278248   {
279249      for( i = 0; i < 160; i++ )
280250      {
r22773r22774
283253   }
284254   else
285255   {
286      UINT16 col = ( ( k1ge->vram[0x118] & 0xc0 ) == 0x80 ) ? k1ge->vram[0x118] & 0x07 : 0;
256      UINT16 col = ( ( m_vram[0x118] & 0xc0 ) == 0x80 ) ? m_vram[0x118] & 0x07 : 0;
287257
288258      for ( i = 0; i < 160; i++ )
289259         p[i] = col;
290260
291      if ( k1ge->vram[0x030] & 0x80 )
261      if ( m_vram[0x030] & 0x80 )
292262      {
293263         /* Draw sprites with 01 priority */
294         k1ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
264         draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
295265
296266         /* Draw PF1 */
297         k1ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x108 );
267         draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x108 );
298268
299269         /* Draw sprites with 10 priority */
300         k1ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
270         draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
301271
302272         /* Draw PF2 */
303         k1ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x110 );
273         draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x110 );
304274
305275         /* Draw sprites with 11 priority */
306         k1ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
276         draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
307277      }
308278      else
309279      {
310280         /* Draw sprites with 01 priority */
311         k1ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
281         draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
312282
313283         /* Draw PF2 */
314         k1ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x110 );
284         draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x110 );
315285
316286         /* Draw sprites with 10 priority */
317         k1ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
287         draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
318288
319289         /* Draw PF1 */
320         k1ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x108 );
290         draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x108 );
321291
322292         /* Draw sprites with 11 priority */
323         k1ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
293         draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
324294      }
325295
326      for( i = 0; i < k1ge->wba_h; i++ )
296      for( i = 0; i < m_wba_h; i++ )
327297      {
328298         p[i] = oowcol;
329299      }
330300
331      for( i = k1ge->wba_h + k1ge->wsi_h; i < 160; i++ )
301      for( i = m_wba_h + m_wsi_h; i < 160; i++ )
332302      {
333303         p[i] = oowcol;
334304      }
r22773r22774
336306}
337307
338308
339INLINE void k2ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_base )
309void k2ge_device::draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_base )
340310{
341311   int i;
342312   int offset_x = ( scroll_x >> 3 ) * 2;
r22773r22774
350320   base += ( ( ( ( scroll_y + line ) >> 3 ) * 0x0040 ) & 0x7ff );
351321
352322   /* setup */
353   map_data = k1ge->vram[ base + offset_x  ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
323   map_data = m_vram[ base + offset_x  ] | ( m_vram[ base + offset_x + 1 ] << 8 );
354324   hflip = map_data & 0x8000;
355325   pcode = pal_base + ( ( map_data & 0x1e00 ) >> 6 );
356326   tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
r22773r22774
358328      tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
359329   else
360330      tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
361   tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
331   tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
362332   if ( hflip )
363333      tile_data >>= 2 * ( scroll_x & 0x07 );
364334   else
r22773r22774
382352
383353      if ( col )
384354      {
385         p[ i ]  = k1ge->vram[ pcode + col * 2 ] | ( k1ge->vram[ pcode + col * 2 + 1 ] << 8 );
355         p[ i ]  = m_vram[ pcode + col * 2 ] | ( m_vram[ pcode + col * 2 + 1 ] << 8 );
386356      }
387357
388358      px++;
389359      if ( px >= 8 )
390360      {
391361         offset_x = ( offset_x + 2 ) & 0x3f;
392         map_data = k1ge->vram[ base + offset_x ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
362         map_data = m_vram[ base + offset_x ] | ( m_vram[ base + offset_x + 1 ] << 8 );
393363         hflip = map_data & 0x8000;
394364         pcode = pal_base + ( ( map_data & 0x1e00 ) >> 6 );
395365         tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
r22773r22774
397367            tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
398368         else
399369            tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
400         tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
370         tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
401371         px = 0;
402372      }
403373   }
404374}
405375
406376
407INLINE void k2ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
377void k2ge_device::draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
408378{
409379   struct {
410380      UINT16 spr_data;
r22773r22774
422392   /* Select sprites */
423393   for ( i = 0; i < 256; i += 4 )
424394   {
425      UINT16 spr_data = k1ge->vram[ 0x800 + i ] | ( k1ge->vram[ 0x801 + i ] << 8 );
426      UINT8 x = k1ge->vram[ 0x802 + i ];
427      UINT8 y = k1ge->vram[ 0x803 + i ];
395      UINT16 spr_data = m_vram[ 0x800 + i ] | ( m_vram[ 0x801 + i ] << 8 );
396      UINT8 x = m_vram[ 0x802 + i ];
397      UINT8 y = m_vram[ 0x803 + i ];
428398
429399      spr_x = ( spr_data & 0x0400 ) ? ( spr_x + x ) :  ( scroll_x + x );
430400      spr_y = ( spr_data & 0x0200 ) ? ( spr_y + y ) :  ( scroll_y + y );
r22773r22774
448418      int j;
449419      UINT16 tile_addr;
450420      UINT16 tile_data;
451      UINT16 pcode = 0x0200 + ( ( k1ge->vram[0x0c00 + spr[i].index ] & 0x0f ) << 3 );
421      UINT16 pcode = 0x0200 + ( ( m_vram[0x0c00 + spr[i].index ] & 0x0f ) << 3 );
452422
453423      tile_addr = 0x2000 + ( ( spr[i].spr_data & 0x1ff ) * 16 );
454424      if ( spr[i].spr_data & 0x4000 )
455425         tile_addr += ( 7 - ( ( line - spr[i].y ) & 0x07 ) ) * 2;
456426      else
457427         tile_addr += ( ( line - spr[i].y ) & 0x07 ) * 2;
458      tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
428      tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
459429
460430      for ( j = 0; j < 8; j++ )
461431      {
r22773r22774
476446
477447         if ( spr_x < 160 && col )
478448         {
479            p[ spr_x ] = k1ge->vram[ pcode + col * 2 ] | ( k1ge->vram[ pcode + col * 2 + 1 ] << 8 );
449            p[ spr_x ] = m_vram[ pcode + col * 2 ] | ( m_vram[ pcode + col * 2 + 1 ] << 8 );
480450         }
481451      }
482452   }
483453}
484454
485455
486INLINE void k2ge_k1ge_draw_scroll_plane( k1ge_t *k1ge, UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_lut_base, UINT16 k2ge_lut_base )
456void k2ge_device::k1ge_draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_lut_base, UINT16 k2ge_lut_base )
487457{
488458   int i;
489459   int offset_x = ( scroll_x >> 3 ) * 2;
r22773r22774
497467   base += ( ( ( ( scroll_y + line ) >> 3 ) * 0x0040 ) & 0x7ff );
498468
499469   /* setup */
500   map_data = k1ge->vram[ base + offset_x  ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
470   map_data = m_vram[ base + offset_x  ] | ( m_vram[ base + offset_x + 1 ] << 8 );
501471   hflip = map_data & 0x8000;
502472   pcode = ( map_data & 0x2000 ) ? 1 : 0;
503473   tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
r22773r22774
505475      tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
506476   else
507477      tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
508   tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
478   tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
509479   if ( hflip )
510480      tile_data >>= 2 * ( scroll_x & 0x07 );
511481   else
r22773r22774
529499
530500      if ( col )
531501      {
532         UINT16 col2 = 16 * pcode + ( k1ge->vram[ pal_lut_base + 4 * pcode + col ] * 2 );
533         p[ i ]  = k1ge->vram[ k2ge_lut_base + col2 ] | ( k1ge->vram[ k2ge_lut_base + col2 + 1 ] << 8 );
502         UINT16 col2 = 16 * pcode + ( m_vram[ pal_lut_base + 4 * pcode + col ] * 2 );
503         p[ i ]  = m_vram[ k2ge_lut_base + col2 ] | ( m_vram[ k2ge_lut_base + col2 + 1 ] << 8 );
534504      }
535505
536506      px++;
537507      if ( px >= 8 )
538508      {
539509         offset_x = ( offset_x + 2 ) & 0x3f;
540         map_data = k1ge->vram[ base + offset_x ] | ( k1ge->vram[ base + offset_x + 1 ] << 8 );
510         map_data = m_vram[ base + offset_x ] | ( m_vram[ base + offset_x + 1 ] << 8 );
541511         hflip = map_data & 0x8000;
542512         pcode = ( map_data & 0x2000 ) ? 1 : 0;
543513         tile_addr = 0x2000 + ( ( map_data & 0x1ff ) * 16 );
r22773r22774
545515            tile_addr += ( 7 - ( ( scroll_y + line ) & 0x07 ) ) * 2;
546516         else
547517            tile_addr += ( ( scroll_y + line ) & 0x07 ) * 2;
548         tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
518         tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
549519         px = 0;
550520      }
551521   }
552522}
553523
554524
555INLINE void k2ge_k1ge_draw_sprite_plane( k1ge_t *k1ge, UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
525void k2ge_device::k1ge_draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y )
556526{
557527   struct {
558528      UINT16 spr_data;
r22773r22774
569539   /* Select sprites */
570540   for ( i = 0; i < 256; i += 4 )
571541   {
572      UINT16 spr_data = k1ge->vram[ 0x800 + i ] | ( k1ge->vram[ 0x801 + i ] << 8 );
573      UINT8 x = k1ge->vram[ 0x802 + i ];
574      UINT8 y = k1ge->vram[ 0x803 + i ];
542      UINT16 spr_data = m_vram[ 0x800 + i ] | ( m_vram[ 0x801 + i ] << 8 );
543      UINT8 x = m_vram[ 0x802 + i ];
544      UINT8 y = m_vram[ 0x803 + i ];
575545
576546      spr_x = ( spr_data & 0x0400 ) ? ( spr_x + x ) :  ( scroll_x + x );
577547      spr_y = ( spr_data & 0x0200 ) ? ( spr_y + y ) :  ( scroll_y + y );
r22773r22774
601571         tile_addr += ( 7 - ( ( line - spr[i].y ) & 0x07 ) ) * 2;
602572      else
603573         tile_addr += ( ( line - spr[i].y ) & 0x07 ) * 2;
604      tile_data = k1ge->vram[ tile_addr ] | ( k1ge->vram[ tile_addr + 1 ] << 8 );
574      tile_data = m_vram[ tile_addr ] | ( m_vram[ tile_addr + 1 ] << 8 );
605575
606576      for ( j = 0; j < 8; j++ )
607577      {
r22773r22774
622592
623593         if ( spr_x < 160 && col )
624594         {
625            UINT16 col2 = 16 * pcode + k1ge->vram[ 0x100 + 4 * pcode + col ] * 2;
626            p[ spr_x ] = k1ge->vram[ 0x380 + col2 ] | ( k1ge->vram[ 0x381 + col2 ] << 8 );
595            UINT16 col2 = 16 * pcode + m_vram[ 0x100 + 4 * pcode + col ] * 2;
596            p[ spr_x ] = m_vram[ 0x380 + col2 ] | ( m_vram[ 0x381 + col2 ] << 8 );
627597         }
628598      }
629599   }
630600}
631601
632602
633static void k2ge_draw( device_t *device, int line )
603void k2ge_device::draw( int line )
634604{
635   k1ge_t *k1ge = get_safe_token( device );
636   UINT16 *p = &k1ge->bitmap->pix16(line);
605   UINT16 *p = &m_bitmap->pix16(line);
637606   UINT16 col = 0;
638607   UINT16 oowcol;
639608   int i;
640609
641   oowcol = ( k1ge->vram[0x012] & 0x07 ) * 2;
642   oowcol = k1ge->vram[0x3f0 + oowcol ] | ( k1ge->vram[0x3f1 + oowcol ] << 8 );
610   oowcol = ( m_vram[0x012] & 0x07 ) * 2;
611   oowcol = m_vram[0x3f0 + oowcol ] | ( m_vram[0x3f1 + oowcol ] << 8 );
643612
644   if ( line < k1ge->wba_v || line >= k1ge->wba_v + k1ge->wsi_v )
613   if ( line < m_wba_v || line >= m_wba_v + m_wsi_v )
645614   {
646615      for( i = 0; i < 160; i++ )
647616      {
r22773r22774
651620   else
652621   {
653622      /* Determine the background color */
654      if ( ( k1ge->vram[0x118] & 0xc0 ) == 0x80 )
623      if ( ( m_vram[0x118] & 0xc0 ) == 0x80 )
655624      {
656         col = ( k1ge->vram[0x118] & 0x07 ) * 2;
625         col = ( m_vram[0x118] & 0x07 ) * 2;
657626      }
658      col = k1ge->vram[0x3e0 + col ] | ( k1ge->vram[0x3e1 + col ] << 8 );
627      col = m_vram[0x3e0 + col ] | ( m_vram[0x3e1 + col ] << 8 );
659628
660629      /* Set the bacground color */
661630      for ( i = 0; i < 160; i++ )
r22773r22774
663632         p[i] = col;
664633      }
665634
666      if ( k1ge->vram[0x7e2] & 0x80 )
635      if ( m_vram[0x7e2] & 0x80 )
667636      {
668637         /* K1GE compatibility mode */
669         if ( k1ge->vram[0x030] & 0x80 )
638         if ( m_vram[0x030] & 0x80 )
670639         {
671640            /* Draw sprites with 01 priority */
672            k2ge_k1ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
641            k1ge_draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
673642
674643            /* Draw PF1 */
675            k2ge_k1ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x108, 0x3a0 );
644            k1ge_draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x108, 0x3a0 );
676645
677646            /* Draw sprites with 10 priority */
678            k2ge_k1ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
647            k1ge_draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
679648
680649            /* Draw PF2 */
681            k2ge_k1ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x110, 0x3c0 );
650            k1ge_draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x110, 0x3c0 );
682651
683652            /* Draw sprites with 11 priority */
684            k2ge_k1ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
653            k1ge_draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
685654         }
686655         else
687656         {
688657            /* Draw sprites with 01 priority */
689            k2ge_k1ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
658            k1ge_draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
690659
691660            /* Draw PF2 */
692            k2ge_k1ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x110, 0x3c0 );
661            k1ge_draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x110, 0x3c0 );
693662
694663            /* Draw sprites with 10 priority */
695            k2ge_k1ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
664            k1ge_draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
696665
697666            /* Draw PF1 */
698            k2ge_k1ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x108, 0x3a0 );
667            k1ge_draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x108, 0x3a0 );
699668
700669            /* Draw sprites with 11 priority */
701            k2ge_k1ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
670            k1ge_draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
702671         }
703672      }
704673      else
705674      {
706675         /* K2GE mode */
707         if ( k1ge->vram[0x030] & 0x80 )
676         if ( m_vram[0x030] & 0x80 )
708677         {
709678            /* Draw sprites with 01 priority */
710            k2ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
679            draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
711680
712681            /* Draw PF1 */
713            k2ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x280 );
682            draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x280 );
714683
715684            /* Draw sprites with 10 priority */
716            k2ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
685            draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
717686
718687            /* Draw PF2 */
719            k2ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x300 );
688            draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x300 );
720689
721690            /* Draw sprites with 11 priority */
722            k2ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
691            draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
723692         }
724693         else
725694         {
726695            /* Draw sprites with 01 priority */
727            k2ge_draw_sprite_plane( k1ge, p, 1, line, k1ge->vram[0x020], k1ge->vram[0x021] );
696            draw_sprite_plane( p, 1, line, m_vram[0x020], m_vram[0x021] );
728697
729698            /* Draw PF2 */
730            k2ge_draw_scroll_plane( k1ge, p, 0x1800, line, k1ge->vram[0x034], k1ge->vram[0x035], 0x300 );
699            draw_scroll_plane( p, 0x1800, line, m_vram[0x034], m_vram[0x035], 0x300 );
731700
732701            /* Draw sprites with 10 priority */
733            k2ge_draw_sprite_plane( k1ge, p, 2, line, k1ge->vram[0x020], k1ge->vram[0x021] );
702            draw_sprite_plane( p, 2, line, m_vram[0x020], m_vram[0x021] );
734703
735704            /* Draw PF1 */
736            k2ge_draw_scroll_plane( k1ge, p, 0x1000, line, k1ge->vram[0x032], k1ge->vram[0x033], 0x280 );
705            draw_scroll_plane( p, 0x1000, line, m_vram[0x032], m_vram[0x033], 0x280 );
737706
738707            /* Draw sprites with 11 priority */
739            k2ge_draw_sprite_plane( k1ge, p, 3, line, k1ge->vram[0x020], k1ge->vram[0x021] );
708            draw_sprite_plane( p, 3, line, m_vram[0x020], m_vram[0x021] );
740709         }
741710      }
742711
743      for ( i = 0; i < k1ge->wba_h; i++ )
712      for ( i = 0; i < m_wba_h; i++ )
744713      {
745714         p[i] = oowcol;
746715      }
747716
748      for ( i = k1ge->wba_h + k1ge->wsi_h; i < 160; i++ )
717      for ( i = m_wba_h + m_wsi_h; i < 160; i++ )
749718      {
750719         p[i] = oowcol;
751720      }
r22773r22774
753722}
754723
755724
756static TIMER_CALLBACK( k1ge_hblank_on_timer_callback )
725TIMER_CALLBACK_MEMBER( k1ge_device::hblank_on_timer_callback )
757726{
758   device_t *device = (device_t *)ptr;
759   k1ge_t *k1ge = get_safe_token( device );
760
761   if (!k1ge->hblank_pin_w.isnull())
762      k1ge->hblank_pin_w(0, 0);
727   m_hblank_pin_w(0);
763728}
764729
765730
766static TIMER_CALLBACK( k1ge_timer_callback )
731TIMER_CALLBACK_MEMBER( k1ge_device::timer_callback )
767732{
768   device_t *device = (device_t *)ptr;
769   k1ge_t *k1ge = get_safe_token( device );
770   int y = k1ge->screen->vpos();
733   int y = m_screen->vpos();
771734
772735   /* Check for start of VBlank */
773736   if ( y >= 152 )
774737   {
775      k1ge->vram[0x010] |= 0x40;
776      if ((k1ge->vram[0x000] & 0x80 ) && !k1ge->vblank_pin_w.isnull())
777            k1ge->vblank_pin_w(0, 1);
738      m_vram[0x010] |= 0x40;
739      if (m_vram[0x000] & 0x80)
740      {
741         m_vblank_pin_w(1);
742      }
778743   }
779744
780745   /* Check for end of VBlank */
781746   if ( y == 0 )
782747   {
783      k1ge->wba_h = k1ge->vram[0x002];
784      k1ge->wba_v = k1ge->vram[0x003];
785      k1ge->wsi_h = k1ge->vram[0x004];
786      k1ge->wsi_v = k1ge->vram[0x005];
787      k1ge->vram[0x010] &= ~ 0x40;
788      if ((k1ge->vram[0x000] & 0x80 ) && !k1ge->vblank_pin_w.isnull())
789         k1ge->vblank_pin_w(0, 0);
748      m_wba_h = m_vram[0x002];
749      m_wba_v = m_vram[0x003];
750      m_wsi_h = m_vram[0x004];
751      m_wsi_v = m_vram[0x005];
752      m_vram[0x010] &= ~ 0x40;
753      if (m_vram[0x000] & 0x80)
754      {
755         m_vblank_pin_w(0);
756      }
790757   }
791758
792759   /* Check if Hint should be triggered */
793760   if ( y == K1GE_SCREEN_HEIGHT - 1 || y < 151 )
794761   {
795      if (!k1ge->hblank_pin_w.isnull())
762      if (!m_hblank_pin_w.isnull())
796763      {
797         if ( k1ge->vram[0x000] & 0x40 )
798            k1ge->hblank_pin_w(0, 1);
799         k1ge->hblank_on_timer->adjust( k1ge->screen->time_until_pos(y, 480 ) );
764         if (m_vram[0x000] & 0x40)
765         {
766            m_hblank_pin_w(1);
767         }
768         m_hblank_on_timer->adjust( m_screen->time_until_pos(y, 480 ) );
800769      }
801770   }
802771
803772   /* Draw a line when inside visible area */
804773   if ( y && y < 153 )
805774   {
806      k1ge->draw( device, y - 1 );
775      draw( y - 1 );
807776   }
808777
809   k1ge->timer->adjust( k1ge->screen->time_until_pos(( y + 1 ) % K1GE_SCREEN_HEIGHT, 0 ) );
778   m_timer->adjust( m_screen->time_until_pos(( y + 1 ) % K1GE_SCREEN_HEIGHT, 0 ) );
810779}
811780
812781
813void k1ge_update( device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect )
782void k1ge_device::update( bitmap_ind16 &bitmap, const rectangle &cliprect )
814783{
815   k1ge_t *k1ge = get_safe_token( device );
816
817   copybitmap( bitmap, *k1ge->bitmap, 0, 0, 0, 0, cliprect );
784   copybitmap( bitmap, *m_bitmap, 0, 0, 0, 0, cliprect );
818785}
819786
820787
821static DEVICE_START( k1ge )
822{
823   k1ge_t *k1ge = get_safe_token( device );
788//-------------------------------------------------
789//  device_start - device-specific startup
790//-------------------------------------------------
824791
825   k1ge->intf = (const k1ge_interface*)device->static_config();
826
827   k1ge->vblank_pin_w.resolve(k1ge->intf->vblank_pin_w, *device);
828   k1ge->hblank_pin_w.resolve(k1ge->intf->hblank_pin_w, *device);
829
830   k1ge->timer = device->machine().scheduler().timer_alloc(FUNC(k1ge_timer_callback), (void *) device );
831   k1ge->hblank_on_timer = device->machine().scheduler().timer_alloc(FUNC(k1ge_hblank_on_timer_callback), (void *) device );
832   k1ge->screen = device->machine().device<screen_device>(k1ge->intf->screen_tag);
833   k1ge->vram = device->machine().root_device().memregion( k1ge->intf->vram_tag )->base();
834   k1ge->bitmap = auto_bitmap_ind16_alloc( device->machine(), k1ge->screen->width(), k1ge->screen->height() );
835   k1ge->draw = k1ge_draw;
836}
837
838
839static DEVICE_START( k2ge )
792void k1ge_device::device_start()
840793{
841   k1ge_t *k1ge = get_safe_token( device );
794   m_vblank_pin_w.resolve();
795   m_hblank_pin_w.resolve();
842796
843   DEVICE_START_CALL( k1ge );
844   k1ge->draw = k2ge_draw;
797   m_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(k1ge_device::timer_callback), this));
798   m_hblank_on_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(k1ge_device::hblank_on_timer_callback), this));
799   m_screen = machine().device<screen_device>(m_screen_tag);
800   m_vram = machine().root_device().memregion( m_vram_tag )->base();
801   m_bitmap = auto_bitmap_ind16_alloc( machine(), m_screen->width(), m_screen->height() );
845802}
846803
847804
848static DEVICE_RESET( k1ge )
805//-------------------------------------------------
806//  device_reset - device-specific reset
807//-------------------------------------------------
808
809void k1ge_device::device_reset()
849810{
850   k1ge_t *k1ge = get_safe_token( device );
811   m_vram[0x000] = 0x00;   /* Interrupt enable */
812   m_vram[0x002] = 0x00;   /* WBA.H */
813   m_vram[0x003] = 0x00;   /* WVA.V */
814   m_vram[0x004] = 0xFF;   /* WSI.H */
815   m_vram[0x005] = 0xFF;   /* WSI.V */
816   m_vram[0x007] = 0xc6;   /* REF */
817   m_vram[0x012] = 0x00;   /* 2D control */
818   m_vram[0x020] = 0x00;   /* PO.H */
819   m_vram[0x021] = 0x00;   /* PO.V */
820   m_vram[0x030] = 0x00;   /* PF */
821   m_vram[0x032] = 0x00;   /* S1SO.H */
822   m_vram[0x033] = 0x00;   /* S1SO.V */
823   m_vram[0x034] = 0x00;   /* S2SO.H */
824   m_vram[0x035] = 0x00;   /* S2SO.V */
825   m_vram[0x101] = 0x07;   /* SPPLT01 */
826   m_vram[0x102] = 0x07;   /* SPPLT02 */
827   m_vram[0x103] = 0x07;   /* SPPLT03 */
828   m_vram[0x105] = 0x07;   /* SPPLT11 */
829   m_vram[0x106] = 0x07;   /* SPPLT12 */
830   m_vram[0x107] = 0x07;   /* SPPLT13 */
831   m_vram[0x109] = 0x07;   /* SC1PLT01 */
832   m_vram[0x10a] = 0x07;   /* SC1PLT02 */
833   m_vram[0x10b] = 0x07;   /* SC1PLT03 */
834   m_vram[0x10d] = 0x07;   /* SC1PLT11 */
835   m_vram[0x10e] = 0x07;   /* SC1PLT12 */
836   m_vram[0x10f] = 0x07;   /* SC1PLT13 */
837   m_vram[0x111] = 0x07;   /* SC2PLT01 */
838   m_vram[0x112] = 0x07;   /* SC2PLT02 */
839   m_vram[0x113] = 0x07;   /* SC2PLT03 */
840   m_vram[0x115] = 0x07;   /* SC2PLT11 */
841   m_vram[0x116] = 0x07;   /* SC2PLT12 */
842   m_vram[0x117] = 0x07;   /* SC2PLT13 */
843   m_vram[0x118] = 0x07;   /* BG */
844   m_vram[0x400] = 0xFF;   /* LED control */
845   m_vram[0x402] = 0x80;   /* LEDFREG */
846   m_vram[0x7e0] = 0x52;   /* RESET */
847   m_vram[0x7e2] = 0x00;   /* MODE */
851848
852   k1ge->vram[0x000] = 0x00;   /* Interrupt enable */
853   k1ge->vram[0x002] = 0x00;   /* WBA.H */
854   k1ge->vram[0x003] = 0x00;   /* WVA.V */
855   k1ge->vram[0x004] = 0xFF;   /* WSI.H */
856   k1ge->vram[0x005] = 0xFF;   /* WSI.V */
857   k1ge->vram[0x007] = 0xc6;   /* REF */
858   k1ge->vram[0x012] = 0x00;   /* 2D control */
859   k1ge->vram[0x020] = 0x00;   /* PO.H */
860   k1ge->vram[0x021] = 0x00;   /* PO.V */
861   k1ge->vram[0x030] = 0x00;   /* PF */
862   k1ge->vram[0x032] = 0x00;   /* S1SO.H */
863   k1ge->vram[0x033] = 0x00;   /* S1SO.V */
864   k1ge->vram[0x034] = 0x00;   /* S2SO.H */
865   k1ge->vram[0x035] = 0x00;   /* S2SO.V */
866   k1ge->vram[0x101] = 0x07;   /* SPPLT01 */
867   k1ge->vram[0x102] = 0x07;   /* SPPLT02 */
868   k1ge->vram[0x103] = 0x07;   /* SPPLT03 */
869   k1ge->vram[0x105] = 0x07;   /* SPPLT11 */
870   k1ge->vram[0x106] = 0x07;   /* SPPLT12 */
871   k1ge->vram[0x107] = 0x07;   /* SPPLT13 */
872   k1ge->vram[0x109] = 0x07;   /* SC1PLT01 */
873   k1ge->vram[0x10a] = 0x07;   /* SC1PLT02 */
874   k1ge->vram[0x10b] = 0x07;   /* SC1PLT03 */
875   k1ge->vram[0x10d] = 0x07;   /* SC1PLT11 */
876   k1ge->vram[0x10e] = 0x07;   /* SC1PLT12 */
877   k1ge->vram[0x10f] = 0x07;   /* SC1PLT13 */
878   k1ge->vram[0x111] = 0x07;   /* SC2PLT01 */
879   k1ge->vram[0x112] = 0x07;   /* SC2PLT02 */
880   k1ge->vram[0x113] = 0x07;   /* SC2PLT03 */
881   k1ge->vram[0x115] = 0x07;   /* SC2PLT11 */
882   k1ge->vram[0x116] = 0x07;   /* SC2PLT12 */
883   k1ge->vram[0x117] = 0x07;   /* SC2PLT13 */
884   k1ge->vram[0x118] = 0x07;   /* BG */
885   k1ge->vram[0x400] = 0xFF;   /* LED control */
886   k1ge->vram[0x402] = 0x80;   /* LEDFREG */
887   k1ge->vram[0x7e0] = 0x52;   /* RESET */
888   k1ge->vram[0x7e2] = 0x00;   /* MODE */
889
890   k1ge->timer->adjust( k1ge->screen->time_until_pos(( k1ge->screen->vpos() + 1 ) % K1GE_SCREEN_HEIGHT, 0 ) );
849   m_timer->adjust( m_screen->time_until_pos(( m_screen->vpos() + 1 ) % K1GE_SCREEN_HEIGHT, 0 ) );
891850}
892851
893852
r22773r22774
895854
896855k1ge_device::k1ge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
897856   : device_t(mconfig, K1GE, "K1GE Monochrome Graphics + LCD", tag, owner, clock)
857   , m_vblank_pin_w(*this)
858   , m_hblank_pin_w(*this)
898859{
899   m_token = global_alloc_clear(k1ge_t);
900860}
901861
902862k1ge_device::k1ge_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock)
903863   : device_t(mconfig, type, name, tag, owner, clock)
864   , m_vblank_pin_w(*this)
865   , m_hblank_pin_w(*this)
904866{
905   m_token = global_alloc_clear(k1ge_t);
906867}
907868
908//-------------------------------------------------
909//  device_config_complete - perform any
910//  operations now that the configuration is
911//  complete
912//-------------------------------------------------
913869
914void k1ge_device::device_config_complete()
915{
916}
917
918//-------------------------------------------------
919//  device_start - device-specific startup
920//-------------------------------------------------
921
922void k1ge_device::device_start()
923{
924   DEVICE_START_NAME( k1ge )(this);
925}
926
927//-------------------------------------------------
928//  device_reset - device-specific reset
929//-------------------------------------------------
930
931void k1ge_device::device_reset()
932{
933   DEVICE_RESET_NAME( k1ge )(this);
934}
935
936
937870const device_type K2GE = &device_creator<k2ge_device>;
938871
939872k2ge_device::k2ge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
r22773r22774
941874{
942875}
943876
944//-------------------------------------------------
945//  device_start - device-specific startup
946//-------------------------------------------------
947
948void k2ge_device::device_start()
949{
950   DEVICE_START_NAME( k2ge )(this);
951}
trunk/src/mess/video/k1ge.h
r22773r22774
55#include "devcb.h"
66
77
8#define K1GE_SCREEN_HEIGHT  199
8#define MCFG_K1GE_ADD(_tag, _clock, _screen, _vram, _vblank, _hblank ) \
9   MCFG_DEVICE_ADD( _tag, K1GE, _clock ) \
10   k1ge_device::static_set_screen( *device, _screen ); \
11   k1ge_device::static_set_vram( *device, _vram ); \
12   devcb = &k1ge_device::static_set_vblank_callback( *device, DEVCB2_##_vblank ); \
13   devcb = &k1ge_device::static_set_hblank_callback( *device, DEVCB2_##_hblank );
914
15#define MCFG_K2GE_ADD(_tag, _clock, _screen, _vram, _vblank, _hblank ) \
16   MCFG_DEVICE_ADD( _tag, K2GE, _clock ) \
17   k1ge_device::static_set_screen( *device, _screen ); \
18   k1ge_device::static_set_vram( *device, _vram ); \
19    devcb = &k1ge_device::static_set_vblank_callback( *device, DEVCB2_##_vblank ); \
20   devcb = &k1ge_device::static_set_hblank_callback( *device, DEVCB2_##_hblank );
1021
22
1123class k1ge_device : public device_t
1224{
1325public:
1426   k1ge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
1527   k1ge_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock);
16   ~k1ge_device() { global_free(m_token); }
1728
18   // access to legacy token
19   void *token() const { assert(m_token != NULL); return m_token; }
29   DECLARE_READ8_MEMBER( read );
30   DECLARE_WRITE8_MEMBER( write );
31
32   void update( bitmap_ind16 &bitmap, const rectangle &cliprect );
33
34   // Static methods
35   static void static_set_screen(device_t &device, const char *screen_name) { downcast<k1ge_device &>(device).m_screen_tag = screen_name; }
36   static void static_set_vram(device_t &device, const char *vram_name) { downcast<k1ge_device &>(device).m_vram_tag = vram_name; }
37    template<class _Object> static devcb2_base &static_set_vblank_callback(device_t &device, _Object object) { return downcast<k1ge_device &>(device).m_vblank_pin_w.set_callback(object); }
38    template<class _Object> static devcb2_base &static_set_hblank_callback(device_t &device, _Object object) { return downcast<k1ge_device &>(device).m_hblank_pin_w.set_callback(object); }
39
40   static const int K1GE_SCREEN_HEIGHT = 199;
2041protected:
2142   // device-level overrides
22   virtual void device_config_complete();
2343   virtual void device_start();
2444   virtual void device_reset();
25private:
26   // internal state
27   void *m_token;
45
46   const char *m_screen_tag;
47   const char *m_vram_tag;
48   screen_device *m_screen;
49   devcb2_write_line m_vblank_pin_w;
50   devcb2_write_line m_hblank_pin_w;
51   UINT8 *m_vram;
52   UINT8 m_wba_h, m_wba_v, m_wsi_h, m_wsi_v;
53
54   emu_timer *m_timer;
55   emu_timer *m_hblank_on_timer;
56   bitmap_ind16 *m_bitmap;
57
58   virtual void draw(int line);
59
60   void draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, int pal_base );
61   void draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y );
62   TIMER_CALLBACK_MEMBER( hblank_on_timer_callback );
63   TIMER_CALLBACK_MEMBER( timer_callback );
64
2865};
2966
30extern const device_type K1GE;
3167
3268class k2ge_device : public k1ge_device
3369{
3470public:
3571   k2ge_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
72
3673protected:
37   // device-level overrides
38   virtual void device_start();
39};
74   virtual void draw(int line);
4075
41extern const device_type K2GE;
76   void draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_base );
77   void draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y );
78   void k1ge_draw_scroll_plane( UINT16 *p, UINT16 base, int line, int scroll_x, int scroll_y, UINT16 pal_lut_base, UINT16 k2ge_lut_base );
79   void k1ge_draw_sprite_plane( UINT16 *p, UINT16 priority, int line, int scroll_x, int scroll_y );
4280
43
44
45#define MCFG_K1GE_ADD(_tag, _clock, _config ) \
46   MCFG_DEVICE_ADD( _tag, K1GE, _clock ) \
47   MCFG_DEVICE_CONFIG( _config )
48
49
50#define MCFG_K2GE_ADD(_tag, _clock, _config ) \
51   MCFG_DEVICE_ADD( _tag, K2GE, _clock ) \
52   MCFG_DEVICE_CONFIG( _config )
53
54
55struct k1ge_interface
56{
57   const char      *screen_tag;        /* screen we are drawing on */
58   const char      *vram_tag;          /* memory region we will use for video ram */
59   devcb_write8    vblank_pin_w;       /* called back when VBlank pin may have changed */
60   devcb_write8    hblank_pin_w;       /* called back when HBlank pin may have changed */
6181};
6282
6383
6484PALETTE_INIT( k1ge );
6585PALETTE_INIT( k2ge );
6686
67DECLARE_WRITE8_DEVICE_HANDLER( k1ge_w );
68DECLARE_READ8_DEVICE_HANDLER( k1ge_r );
6987
70void k1ge_update( device_t *device, bitmap_ind16 &bitmap, const rectangle &cliprect );
88extern const device_type K1GE;
89extern const device_type K2GE;
7190
91
7292#endif

Previous 199869 Revisions Next


© 1997-2024 The MAME Team