1 // license:BSD-3-Clause
2 // copyright-holders:Nicola Salmoria
3 #include "emu.h"
4
5 #include "includes/crshrace.h"
6
7
8 /***************************************************************************
9
10 Callbacks for the TileMap code
11
12 ***************************************************************************/
13
TILE_GET_INFO_MEMBER(crshrace_state::get_tile_info1)14 TILE_GET_INFO_MEMBER(crshrace_state::get_tile_info1)
15 {
16 int code = m_videoram[0][tile_index];
17
18 tileinfo.set(1, (code & 0xfff) + (m_roz_bank << 12), code >> 12, 0);
19 }
20
TILE_GET_INFO_MEMBER(crshrace_state::get_tile_info2)21 TILE_GET_INFO_MEMBER(crshrace_state::get_tile_info2)
22 {
23 int code = m_videoram[1][tile_index];
24
25 tileinfo.set(0, code, 0, 0);
26 }
27
28
29 /***************************************************************************
30
31 Start the video hardware emulation.
32
33 ***************************************************************************/
34
35
tile_callback(uint32_t code)36 uint32_t crshrace_state::tile_callback(uint32_t code)
37 {
38 return m_spriteram[1]->buffer()[code&0x7fff];
39 }
40
41
video_start()42 void crshrace_state::video_start()
43 {
44 m_tilemap[0] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(crshrace_state::get_tile_info1)), TILEMAP_SCAN_ROWS, 16, 16, 64, 64);
45 m_tilemap[1] = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(crshrace_state::get_tile_info2)), TILEMAP_SCAN_ROWS, 8, 8, 64, 64);
46
47 m_tilemap[0]->set_transparent_pen(0x0f);
48 m_tilemap[1]->set_transparent_pen(0xff);
49
50 }
51
52
53 /***************************************************************************
54
55 Memory handlers
56
57 ***************************************************************************/
58
59
roz_bank_w(offs_t offset,uint8_t data)60 void crshrace_state::roz_bank_w(offs_t offset, uint8_t data)
61 {
62 if (m_roz_bank != data)
63 {
64 m_roz_bank = data;
65 m_tilemap[0]->mark_all_dirty();
66 }
67 }
68
69
gfxctrl_w(offs_t offset,uint8_t data)70 void crshrace_state::gfxctrl_w(offs_t offset, uint8_t data)
71 {
72 m_gfxctrl = data;
73 m_flipscreen = data & 0x20;
74 }
75
76
77 /***************************************************************************
78
79 Display refresh
80
81 ***************************************************************************/
82
draw_bg(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)83 void crshrace_state::draw_bg(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
84 {
85 m_tilemap[1]->draw(screen, bitmap, cliprect, 0, 0);
86 }
87
88
draw_fg(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)89 void crshrace_state::draw_fg(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
90 {
91 m_k053936->zoom_draw(screen, bitmap, cliprect, m_tilemap[0], 0, 0, 1);
92 }
93
94
screen_update(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)95 uint32_t crshrace_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
96 {
97 if (m_gfxctrl & 0x04) // display disable?
98 {
99 bitmap.fill(m_palette->black_pen(), cliprect);
100 return 0;
101 }
102
103 bitmap.fill(0x1ff, cliprect);
104
105
106
107 switch (m_gfxctrl & 0xfb)
108 {
109 case 0x00: // high score screen
110 m_spr->draw_sprites(m_spriteram[0]->buffer(), 0x2000, screen, bitmap, cliprect);
111 draw_bg(screen, bitmap, cliprect);
112 draw_fg(screen, bitmap, cliprect);
113 break;
114 case 0x01:
115 case 0x02:
116 draw_bg(screen, bitmap, cliprect);
117 draw_fg(screen, bitmap, cliprect);
118 m_spr->draw_sprites(m_spriteram[0]->buffer(), 0x2000, screen, bitmap, cliprect);
119 break;
120 default:
121 popmessage("gfxctrl = %02x", m_gfxctrl);
122 break;
123 }
124 return 0;
125 }
126