1 // license:BSD-3-Clause
2 // copyright-holders:David Haywood, Stephane Humbert
3 /* Hanaroku - Alba ZC HW */
4
5 /*
6 TODO:
7 - colour decoding might not be perfect
8 - Background color should be green, but current handling might be wrong.
9 - some unknown sprite attributes
10 - don't know what to do when the jackpot is displayed (missing controls ?)
11 - according to the board pic, there should be one more 4-switches dip
12 switch bank, and probably some NVRAM because there's a battery.
13 */
14
15 #include "emu.h"
16 #include "cpu/z80/z80.h"
17 #include "machine/nvram.h"
18 #include "machine/ticket.h"
19 #include "sound/ay8910.h"
20 #include "emupal.h"
21 #include "screen.h"
22 #include "speaker.h"
23
24 class albazc_state : public driver_device
25 {
26 public:
albazc_state(const machine_config & mconfig,device_type type,const char * tag)27 albazc_state(const machine_config &mconfig, device_type type, const char *tag) :
28 driver_device(mconfig, type, tag),
29 m_spriteram1(*this, "spriteram1"),
30 m_spriteram2(*this, "spriteram2"),
31 m_spriteram3(*this, "spriteram3"),
32 m_maincpu(*this, "maincpu"),
33 m_gfxdecode(*this, "gfxdecode"),
34 m_palette(*this, "palette"),
35 m_hopper(*this, "hopper")
36 { }
37
38 void hanaroku(machine_config &config);
39
40 private:
41 /* video-related */
42 void hanaroku_out_0_w(uint8_t data);
43 void hanaroku_out_1_w(uint8_t data);
44 void hanaroku_out_2_w(uint8_t data);
45 void albazc_vregs_w(offs_t offset, uint8_t data);
46 virtual void video_start() override;
47 void albazc_palette(palette_device &palette) const;
48 uint32_t screen_update_hanaroku(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
49 void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
50 void hanaroku_map(address_map &map);
51
52 required_shared_ptr<uint8_t> m_spriteram1;
53 required_shared_ptr<uint8_t> m_spriteram2;
54 required_shared_ptr<uint8_t> m_spriteram3;
55 uint8_t m_flip_bit;
56 required_device<cpu_device> m_maincpu;
57 required_device<gfxdecode_device> m_gfxdecode;
58 required_device<palette_device> m_palette;
59 required_device<ticket_dispenser_device> m_hopper;
60 };
61
62
63
64 /* video */
65
albazc_palette(palette_device & palette) const66 void albazc_state::albazc_palette(palette_device &palette) const
67 {
68 uint8_t const *const color_prom(memregion("proms")->base());
69 for (int i = 0; i < 0x200; i++)
70 {
71 int const b = (color_prom[i * 2 + 1] & 0x1f);
72 int const g = ((color_prom[i * 2 + 1] & 0xe0) | ((color_prom[i * 2 + 0] & 0x03) <<8)) >> 5;
73 int const r = (color_prom[i * 2 + 0] & 0x7c) >> 2;
74
75 palette.set_pen_color(i, pal5bit(r), pal5bit(g), pal5bit(b));
76 }
77 }
78
79
video_start()80 void albazc_state::video_start()
81 {
82 }
83
draw_sprites(bitmap_ind16 & bitmap,const rectangle & cliprect)84 void albazc_state::draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect)
85 {
86 int i;
87
88 for (i = 511; i >= 0; i--)
89 {
90 int code = m_spriteram1[i] | (m_spriteram2[i] << 8);
91 int color = (m_spriteram2[i + 0x200] & 0xf8) >> 3;
92 int flipx = 0;
93 int flipy = 0;
94 int sx = m_spriteram1[i + 0x200] | ((m_spriteram2[i + 0x200] & 0x07) << 8);
95 int sy = 242 - m_spriteram3[i];
96
97 if (m_flip_bit)
98 {
99 sy = 242 - sy;
100 flipx = !flipx;
101 flipy = !flipy;
102 }
103
104 m_gfxdecode->gfx(0)->transpen(bitmap,cliprect, code, color, flipx, flipy,
105 sx, sy, 0);
106 }
107 }
108
screen_update_hanaroku(screen_device & screen,bitmap_ind16 & bitmap,const rectangle & cliprect)109 uint32_t albazc_state::screen_update_hanaroku(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
110 {
111 bitmap.fill(0x1f0, cliprect); // ???
112 draw_sprites(bitmap, cliprect);
113 return 0;
114 }
115
hanaroku_out_0_w(uint8_t data)116 void albazc_state::hanaroku_out_0_w(uint8_t data)
117 {
118 /*
119 bit description
120
121 0 meter1 (coin1)
122 1 meter2 (coin2)
123 2 meter3 (1/2 d-up)
124 3 meter4
125 4 call out (meter)
126 5 lockout (key)
127 6 hopper2 (play)
128 7 meter5 (start)
129 */
130
131 machine().bookkeeping().coin_counter_w(0, data & 0x01);
132 machine().bookkeeping().coin_counter_w(1, data & 0x02);
133 machine().bookkeeping().coin_counter_w(2, data & 0x04);
134 machine().bookkeeping().coin_counter_w(3, data & 0x08);
135 machine().bookkeeping().coin_counter_w(4, data & 0x80);
136 }
137
hanaroku_out_1_w(uint8_t data)138 void albazc_state::hanaroku_out_1_w(uint8_t data)
139 {
140 /*
141 bit description
142
143 0 hopper1 (data clear)
144 1 dis dat
145 2 dis clk
146 3 pay out
147 4 ext in 1
148 5 ext in 2
149 6 ?
150 7 ?
151 */
152
153 m_hopper->motor_w(BIT(data, 0));
154 }
155
hanaroku_out_2_w(uint8_t data)156 void albazc_state::hanaroku_out_2_w(uint8_t data)
157 {
158 // unused
159 }
160
albazc_vregs_w(offs_t offset,uint8_t data)161 void albazc_state::albazc_vregs_w(offs_t offset, uint8_t data)
162 {
163 #ifdef UNUSED_FUNCTION
164 {
165 static uint8_t x[5];
166 x[offset] = data;
167 popmessage("%02x %02x %02x %02x %02x",x[0],x[1],x[2],x[3],x[4]);
168 }
169 #endif
170
171 if(offset == 0)
172 {
173 /* core bug with this? */
174 //flip_screen_set((data & 0x40) >> 6);
175 m_flip_bit = (data & 0x40) >> 6;
176 }
177 }
178
179 /* main cpu */
180
hanaroku_map(address_map & map)181 void albazc_state::hanaroku_map(address_map &map)
182 {
183 map(0x0000, 0x7fff).rom();
184 map(0x8000, 0x87ff).ram().share("spriteram1");
185 map(0x9000, 0x97ff).ram().share("spriteram2");
186 map(0xa000, 0xa1ff).ram().share("spriteram3");
187 map(0xa200, 0xa2ff).nopw(); // ??? written once during P.O.S.T.
188 map(0xa300, 0xa304).w(FUNC(albazc_state::albazc_vregs_w)); // ???
189 map(0xb000, 0xb000).nopw(); // ??? always 0x40
190 map(0xc000, 0xc3ff).ram(); // main ram
191 map(0xc400, 0xc4ff).ram().share("nvram");
192 map(0xd000, 0xd000).r("aysnd", FUNC(ay8910_device::data_r));
193 map(0xd000, 0xd001).w("aysnd", FUNC(ay8910_device::address_data_w));
194 map(0xe000, 0xe000).portr("IN0").w(FUNC(albazc_state::hanaroku_out_0_w));
195 map(0xe001, 0xe001).portr("IN1");
196 map(0xe002, 0xe002).portr("IN2").w(FUNC(albazc_state::hanaroku_out_1_w));
197 map(0xe004, 0xe004).portr("DSW3").w(FUNC(albazc_state::hanaroku_out_2_w));
198 }
199
200
201 static INPUT_PORTS_START( hanaroku )
202 PORT_START("IN0") /* 0xe000 */
203 PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 ) // adds n credits depending on "Coinage" Dip Switch
204 PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 ) // adds 5 credits
205 PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_MAHJONG_DOUBLE_UP ) PORT_NAME("1/2 D-Up")
206 PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_SERVICE1 ) PORT_NAME("Reset")
207 PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_SERVICE2 ) PORT_NAME("Meter")
208 PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_SERVICE3 ) PORT_NAME("Key") PORT_TOGGLE
209 PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_START2 ) PORT_NAME("Play")
210 PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_START1 ) PORT_NAME("Start")
211
212 PORT_START("IN1") /* 0xe001 */
213 PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_HANAFUDA_A )
214 PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_HANAFUDA_B )
215 PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_HANAFUDA_C )
216 PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_HANAFUDA_D )
217 PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_HANAFUDA_E )
218 PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_HANAFUDA_F )
219 PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_HANAFUDA_YES )
220 PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_HANAFUDA_NO )
221
222 PORT_START("IN2") /* 0xe002 */
223 PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_MEMORY_RESET ) PORT_NAME("Data Clear")
224 PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_TILT )
225 PORT_BIT( 0x04, IP_ACTIVE_HIGH, IPT_CUSTOM ) PORT_READ_LINE_DEVICE_MEMBER("hopper", ticket_dispenser_device, line_r) // "Medal In"
226 PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_GAMBLE_PAYOUT )
227 PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Ext In 1")
228 PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_OTHER ) PORT_NAME("Ext In 2")
229 PORT_BIT( 0xc0, IP_ACTIVE_LOW, IPT_UNUSED )
230
231 PORT_START("DSW1") /* 0xd000 - Port A */
232 PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
233
234 PORT_START("DSW2") /* 0xd000 - Port B */
235 PORT_BIT( 0xff, IP_ACTIVE_LOW, IPT_UNUSED )
236
237 PORT_START("DSW3") /* 0xe004 */
238 PORT_DIPNAME( 0x03, 0x03, DEF_STR( Coinage ) ) // Stored at 0xc028
239 PORT_DIPSETTING( 0x03, DEF_STR( 1C_1C ) )
240 PORT_DIPSETTING( 0x02, DEF_STR( 1C_2C ) )
241 PORT_DIPSETTING( 0x01, DEF_STR( 1C_5C ) )
242 PORT_DIPSETTING( 0x00, "1 Coin/10 Credits" )
243 PORT_DIPNAME( 0x04, 0x04, DEF_STR( Flip_Screen ) ) // Stored at 0xc03a
244 PORT_DIPSETTING( 0x04, DEF_STR( Off ) )
245 PORT_DIPSETTING( 0x00, DEF_STR( On ) )
246 PORT_DIPNAME( 0x08, 0x08, DEF_STR( Unknown ) ) // Stored at 0xc078
247 PORT_DIPSETTING( 0x08, DEF_STR( Off ) )
248 PORT_DIPSETTING( 0x00, DEF_STR( On ) )
249 PORT_DIPNAME( 0x30, 0x20, "Game Mode" ) // Stored at 0xc02e
250 PORT_DIPSETTING( 0x30, "Mode 0" ) // Collect OFF
251 PORT_DIPSETTING( 0x20, "Mode 1" ) // Collect ON (code at 0x36ea)
252 PORT_DIPSETTING( 0x10, "Mode 2" ) // Collect ON (code at 0x3728)
253 PORT_DIPSETTING( 0x00, "Mode 3" ) // No credit counter
254 PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNUSED )
255 PORT_SERVICE( 0x80, IP_ACTIVE_LOW )
256 INPUT_PORTS_END
257
258
259 static const gfx_layout hanaroku_charlayout =
260 {
261 16,16,
262 RGN_FRAC(1,4),
263 4,
264 { RGN_FRAC(3,4),RGN_FRAC(2,4),RGN_FRAC(1,4),RGN_FRAC(0,4) },
265 { 0,1,2,3,4,5,6,7,
266 64,65,66,67,68,69,70,71},
267 { 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
268 128+0*8,128+1*8,128+2*8,128+3*8,128+4*8,128+5*8,128+6*8,128+7*8 },
269 16*16
270 };
271
272
273
274 static GFXDECODE_START( gfx_hanaroku )
275 GFXDECODE_ENTRY( "gfx1", 0, hanaroku_charlayout, 0, 32 )
276 GFXDECODE_END
277
278
hanaroku(machine_config & config)279 void albazc_state::hanaroku(machine_config &config)
280 {
281 Z80(config, m_maincpu, 6000000); /* ? MHz */
282 m_maincpu->set_addrmap(AS_PROGRAM, &albazc_state::hanaroku_map);
283 m_maincpu->set_vblank_int("screen", FUNC(albazc_state::irq0_line_hold));
284
285 NVRAM(config, "nvram", nvram_device::DEFAULT_ALL_0);
286
287 TICKET_DISPENSER(config, m_hopper, attotime::from_msec(50), TICKET_MOTOR_ACTIVE_HIGH, TICKET_STATUS_ACTIVE_HIGH );
288
289 /* video hardware */
290 screen_device &screen(SCREEN(config, "screen", SCREEN_TYPE_RASTER));
291 screen.set_refresh_hz(60);
292 screen.set_vblank_time(ATTOSECONDS_IN_USEC(0));
293 screen.set_size(64*8, 64*8);
294 screen.set_visarea(0, 48*8-1, 2*8, 30*8-1);
295 screen.set_screen_update(FUNC(albazc_state::screen_update_hanaroku));
296 screen.set_palette(m_palette);
297
298 GFXDECODE(config, m_gfxdecode, m_palette, gfx_hanaroku);
299
300 PALETTE(config, m_palette, FUNC(albazc_state::albazc_palette), 0x200);
301
302 /* sound hardware */
303 SPEAKER(config, "mono").front_center();
304
305 ay8910_device &aysnd(AY8910(config, "aysnd", 1500000)); /* ? MHz */
306 aysnd.port_a_read_callback().set_ioport("DSW1");
307 aysnd.port_b_read_callback().set_ioport("DSW2");
308 aysnd.add_route(ALL_OUTPUTS, "mono", 0.50);
309 }
310
311
312 ROM_START( hanaroku )
313 ROM_REGION( 0x10000, "maincpu", 0 ) /* z80 code */
314 ROM_LOAD( "zc5_1a.u02", 0x00000, 0x08000, CRC(9e3b62ce) SHA1(81aee570b67950c21ab3c8f9235dd383529b34d5) )
315
316 ROM_REGION( 0x20000, "gfx1", 0 ) /* tiles */
317 ROM_LOAD( "zc0_002.u14", 0x00000, 0x08000, CRC(76adab7f) SHA1(6efbe52ae4a1d15fe93bd05058546bf146a64154) )
318 ROM_LOAD( "zc0_003.u15", 0x08000, 0x08000, CRC(c208e64b) SHA1(0bc226c39331bb2e1d4d8f756199ceec85c28f28) )
319 ROM_LOAD( "zc0_004.u16", 0x10000, 0x08000, CRC(e8a46ee4) SHA1(09cac230c1c49cb282f540b1608ad33b1cc1a943) )
320 ROM_LOAD( "zc0_005.u17", 0x18000, 0x08000, CRC(7ad160a5) SHA1(c897fbe4a7c2a2f352333131dfd1a76e176f0ed8) )
321
322 ROM_REGION( 0x0400, "proms", 0 ) /* colour */
323 ROM_LOAD16_BYTE( "zc0_006.u21", 0x0000, 0x0200, CRC(8e8fbc30) SHA1(7075521bbd790c46c58d9e408b0d7d6a42ed00bc) )
324 ROM_LOAD16_BYTE( "zc0_007.u22", 0x0001, 0x0200, CRC(67225de1) SHA1(98322e71d93d247a67fb4e52edad6c6c32a603d8) )
325 ROM_END
326
327
328 GAME( 1988, hanaroku, 0, hanaroku, hanaroku, albazc_state, empty_init, ROT0, "Alba", "Hanaroku", MACHINE_IMPERFECT_GRAPHICS | MACHINE_IMPERFECT_COLORS | MACHINE_SUPPORTS_SAVE )
329