1 // license:BSD-3-Clause
2 // copyright-holders:Mike Coates
3 /***************************************************************************
4
5 circus.c video
6
7 Functions to emulate the video hardware of the machine.
8
9 ***************************************************************************/
10
11 #include "emu.h"
12 #include "sound/samples.h"
13 #include "includes/circus.h"
14
15
circus_videoram_w(offs_t offset,uint8_t data)16 void circus_state::circus_videoram_w(offs_t offset, uint8_t data)
17 {
18 m_videoram[offset] = data;
19 m_bg_tilemap->mark_tile_dirty(offset);
20 }
21
circus_clown_x_w(uint8_t data)22 void circus_state::circus_clown_x_w(uint8_t data)
23 {
24 m_clown_x = 240 - data;
25 }
26
circus_clown_y_w(uint8_t data)27 void circus_state::circus_clown_y_w(uint8_t data)
28 {
29 m_clown_y = 240 - data;
30 }
31
TILE_GET_INFO_MEMBER(circus_state::get_bg_tile_info)32 TILE_GET_INFO_MEMBER(circus_state::get_bg_tile_info)
33 {
34 int code = m_videoram[tile_index];
35
36 tileinfo.set(0, code, 0, 0);
37 }
38
video_start()39 void circus_state::video_start()
40 {
41 m_bg_tilemap = &machine().tilemap().create(*m_gfxdecode, tilemap_get_info_delegate(*this, FUNC(circus_state::get_bg_tile_info)), TILEMAP_SCAN_ROWS, 8, 8, 32, 32);
42 }
43
draw_line(bitmap_ind16 & bitmap,const rectangle & cliprect,int x1,int y1,int x2,int y2,int dotted)44 void circus_state::draw_line( bitmap_ind16 &bitmap, const rectangle &cliprect, int x1, int y1, int x2, int y2, int dotted )
45 {
46 /* Draws horizontal and Vertical lines only! */
47 int count, skip;
48
49 /* Draw the Line */
50 if (dotted > 0)
51 skip = 2;
52 else
53 skip = 1;
54
55 if (x1 == x2)
56 for (count = y2; count >= y1; count -= skip)
57 bitmap.pix(count, x1) = 1;
58 else
59 for (count = x2; count >= x1; count -= skip)
60 bitmap.pix(y1, count) = 1;
61 }
62
draw_sprite_collision(bitmap_ind16 & bitmap,const rectangle & cliprect)63 void circus_state::draw_sprite_collision( bitmap_ind16 &bitmap, const rectangle &cliprect )
64 {
65 gfx_element *sprite_gfx = m_gfxdecode->gfx(1);
66 const uint8_t *sprite_data = sprite_gfx->get_data(m_clown_z);
67 int collision = 0;
68
69 // draw sprite and check collision on a pixel basis
70 for (int sy = 0; sy < 16; sy++)
71 {
72 int dy = m_clown_x + sy-1;
73 if (dy>=0 && dy<bitmap.height())
74 {
75 for (int sx = 0; sx < 16; sx++)
76 {
77 int dx = m_clown_y + sx;
78 if (dx>=0 && dx<bitmap.width())
79 {
80 int pixel = sprite_data[sy * sprite_gfx->rowbytes() + sx];
81 if (pixel)
82 {
83 collision |= bitmap.pix(dy, dx);
84 bitmap.pix(dy, dx) = m_palette->pen(pixel);
85 }
86 }
87 }
88 }
89 }
90
91 if (collision)
92 m_maincpu->set_input_line(0, ASSERT_LINE);
93 }
94
circus_draw_fg(bitmap_ind16 & bitmap,const rectangle & cliprect)95 void circus_state::circus_draw_fg( bitmap_ind16 &bitmap, const rectangle &cliprect )
96 {
97 /* The sync generator hardware is used to */
98 /* draw the border and diving boards */
99
100 draw_line(bitmap, cliprect, 0, 18, 255, 18, 0);
101 draw_line(bitmap, cliprect, 0, 249, 255, 249, 1);
102 draw_line(bitmap, cliprect, 0, 18, 0, 248, 0);
103 draw_line(bitmap, cliprect, 247, 18, 247, 248, 0);
104
105 draw_line(bitmap, cliprect, 0, 136, 17, 136, 0);
106 draw_line(bitmap, cliprect, 231, 136, 248, 136, 0);
107 draw_line(bitmap, cliprect, 0, 192, 17, 192, 0);
108 draw_line(bitmap, cliprect, 231, 192, 248, 192, 0);
109 }
110
screen_update_circus(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)111 uint32_t circus_state::screen_update_circus(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
112 {
113 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
114 circus_draw_fg(bitmap, cliprect);
115 draw_sprite_collision(bitmap, cliprect);
116 return 0;
117 }
118
robotbwl_draw_box(bitmap_ind16 & bitmap,const rectangle & cliprect,int x,int y)119 void circus_state::robotbwl_draw_box( bitmap_ind16 &bitmap, const rectangle &cliprect, int x, int y )
120 {
121 /* Box */
122 int ex = x + 24;
123 int ey = y + 26;
124
125 draw_line(bitmap, cliprect, x, y, ex, y, 0); /* Top */
126 draw_line(bitmap, cliprect, x, ey, ex, ey, 0); /* Bottom */
127 draw_line(bitmap, cliprect, x, y, x, ey, 0); /* Left */
128 draw_line(bitmap, cliprect, ex, y, ex, ey, 0); /* Right */
129
130 /* Score Grid */
131 ey = y + 10;
132 draw_line(bitmap, cliprect, x + 8, ey, ex, ey, 0); /* Horizontal Divide Line */
133 draw_line(bitmap, cliprect, x + 8, y, x + 8, ey, 0);
134 draw_line(bitmap, cliprect, x + 16, y, x + 16, ey, 0);
135 }
136
robotbwl_draw_scoreboard(bitmap_ind16 & bitmap,const rectangle & cliprect)137 void circus_state::robotbwl_draw_scoreboard( bitmap_ind16 &bitmap, const rectangle &cliprect )
138 {
139 int offs;
140
141 /* The sync generator hardware is used to */
142 /* draw the bowling alley & scorecards */
143
144 for (offs = 15; offs <= 63; offs += 24)
145 {
146 robotbwl_draw_box(bitmap, cliprect, offs, 31);
147 robotbwl_draw_box(bitmap, cliprect, offs, 63);
148 robotbwl_draw_box(bitmap, cliprect, offs, 95);
149
150 robotbwl_draw_box(bitmap, cliprect, offs + 152, 31);
151 robotbwl_draw_box(bitmap, cliprect, offs + 152, 63);
152 robotbwl_draw_box(bitmap, cliprect, offs + 152, 95);
153 }
154
155 robotbwl_draw_box(bitmap, cliprect, 39, 127); /* 10th Frame */
156 draw_line(bitmap, cliprect, 39, 137, 47, 137, 0); /* Extra digit box */
157
158 robotbwl_draw_box(bitmap, cliprect, 39 + 152, 127);
159 draw_line(bitmap, cliprect, 39 + 152, 137, 47 + 152, 137, 0);
160 }
161
robotbwl_draw_bowling_alley(bitmap_ind16 & bitmap,const rectangle & cliprect)162 void circus_state::robotbwl_draw_bowling_alley( bitmap_ind16 &bitmap, const rectangle &cliprect )
163 {
164 draw_line(bitmap, cliprect, 103, 17, 103, 205, 0);
165 draw_line(bitmap, cliprect, 111, 17, 111, 203, 1);
166 draw_line(bitmap, cliprect, 152, 17, 152, 205, 0);
167 draw_line(bitmap, cliprect, 144, 17, 144, 203, 1);
168 }
169
robotbwl_draw_ball(bitmap_ind16 & bitmap,const rectangle & cliprect)170 void circus_state::robotbwl_draw_ball( bitmap_ind16 &bitmap, const rectangle &cliprect )
171 {
172 m_gfxdecode->gfx(1)->transpen(bitmap,/* Y is horizontal position */
173 cliprect,
174 m_clown_z,
175 0,
176 0,0,
177 m_clown_y + 8, m_clown_x + 8, 0);
178 }
179
screen_update_robotbwl(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)180 uint32_t circus_state::screen_update_robotbwl(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
181 {
182 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
183 robotbwl_draw_scoreboard(bitmap, cliprect);
184 robotbwl_draw_bowling_alley(bitmap, cliprect);
185 robotbwl_draw_ball(bitmap, cliprect);
186 return 0;
187 }
188
crash_draw_car(bitmap_ind16 & bitmap,const rectangle & cliprect)189 void circus_state::crash_draw_car( bitmap_ind16 &bitmap, const rectangle &cliprect )
190 {
191 m_gfxdecode->gfx(1)->transpen(bitmap,/* Y is horizontal position */
192 cliprect,
193 m_clown_z,
194 0,
195 0,0,
196 m_clown_y, m_clown_x - 1, 0);
197 }
198
screen_update_crash(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)199 uint32_t circus_state::screen_update_crash(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
200 {
201 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
202 crash_draw_car(bitmap, cliprect);
203 return 0;
204 }
205
screen_update_ripcord(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)206 uint32_t circus_state::screen_update_ripcord(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
207 {
208 m_bg_tilemap->draw(screen, bitmap, cliprect, 0, 0);
209 draw_sprite_collision(bitmap, cliprect);
210 return 0;
211 }
212