Advertisement
Guest User

Untitled

a guest
Aug 24th, 2022
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.33 KB | None | 0 0
  1. // license:BSD-3-Clause
  2. // copyright-holders:hap
  3. /******************************************************************************
  4.  
  5. ******************************************************************************/
  6.  
  7. #include "emu.h"
  8. #include "cpu/z80/z80.h"
  9. #include "sound/dac.h"
  10.  
  11. #include "emupal.h"
  12. #include "screen.h"
  13. #include "speaker.h"
  14. #include "tilemap.h"
  15.  
  16.  
  17. namespace {
  18.  
  19. class mmahjong_state : public driver_device
  20. {
  21. public:
  22. mmahjong_state(const machine_config &mconfig, device_type type, const char *tag) :
  23. driver_device(mconfig, type, tag),
  24. m_maincpu(*this, "maincpu"),
  25. m_vram(*this, "vram"),
  26. m_tilemap(*this, "tilemap"),
  27. m_screen(*this, "screen"),
  28. m_dac(*this, "dac"),
  29. m_inputs(*this, "IN.%u", 0)
  30. { }
  31.  
  32. void mmahjong(machine_config &config);
  33.  
  34. protected:
  35. virtual void machine_start() override;
  36.  
  37. private:
  38. required_device<cpu_device> m_maincpu;
  39. required_shared_ptr<u8> m_vram;
  40. required_device<tilemap_device> m_tilemap;
  41. required_device<screen_device> m_screen;
  42. optional_device<dac_bit_interface> m_dac;
  43. required_ioport_array<4> m_inputs;
  44.  
  45. TILE_GET_INFO_MEMBER(get_tile_info) { tileinfo.set(0, m_vram[tile_index], 0, 0); }
  46. u32 screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
  47.  
  48. void main_map(address_map &map);
  49.  
  50. u8 input_r();
  51. void vram_w(offs_t offset, u8 data);
  52.  
  53. void input_w(u8 data);
  54. void sound_w(u8 data);
  55.  
  56. u8 m_inp_mux = 0;
  57. };
  58.  
  59. void mmahjong_state::machine_start()
  60. {
  61. save_item(NAME(m_inp_mux));
  62. }
  63.  
  64.  
  65.  
  66. /******************************************************************************
  67. I/O
  68. ******************************************************************************/
  69.  
  70. u32 mmahjong_state::screen_update(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect)
  71. {
  72. m_tilemap->draw(screen, bitmap, cliprect);
  73. return 0;
  74. }
  75.  
  76. void mmahjong_state::vram_w(offs_t offset, u8 data)
  77. {
  78. m_vram[offset] = data;
  79. m_tilemap->mark_tile_dirty(offset);
  80. }
  81.  
  82. void mmahjong_state::input_w(u8 data)
  83. {
  84. // d0-d3: input mux
  85. m_inp_mux = ~data;
  86. }
  87.  
  88. void mmahjong_state::sound_w(u8 data)
  89. {
  90. // d0: speaker out
  91. m_dac->write(data & 1);
  92. }
  93.  
  94. u8 mmahjong_state::input_r()
  95. {
  96. u8 data = 0;
  97.  
  98. // d0-d7: multiplexed inputs
  99. for (int i = 0; i < 4; i++)
  100. if (BIT(m_inp_mux, i))
  101. data |= m_inputs[i]->read();
  102.  
  103. return ~data;
  104. }
  105.  
  106.  
  107.  
  108. /******************************************************************************
  109. Address Maps
  110. ******************************************************************************/
  111.  
  112. void mmahjong_state::main_map(address_map &map)
  113. {
  114. map.unmap_value_high();
  115. map(0x0000, 0x3fff).rom();
  116. map(0x5000, 0x53ff).ram();
  117. map(0x6000, 0x63ff).w(FUNC(mmahjong_state::vram_w)).share("vram");
  118.  
  119. map(0x7001, 0x7001).r(FUNC(mmahjong_state::input_r));
  120. map(0x7002, 0x7002).w(FUNC(mmahjong_state::input_w));
  121. map(0x7004, 0x7004).w(FUNC(mmahjong_state::sound_w));
  122. }
  123.  
  124.  
  125.  
  126. /******************************************************************************
  127. Input Ports
  128. ******************************************************************************/
  129.  
  130. static INPUT_PORTS_START( mmahjong )
  131. PORT_START("IN.0")
  132. PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_1)
  133. PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_2)
  134. PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_3)
  135. PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_4)
  136. PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_5)
  137. PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_6)
  138. PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_7)
  139. PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_8)
  140.  
  141. PORT_START("IN.1")
  142. PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_Q)
  143. PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_W)
  144. PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_E)
  145. PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_R)
  146. PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_T)
  147. PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_Y)
  148. PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_U)
  149. PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_I)
  150.  
  151. PORT_START("IN.2")
  152. PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_A)
  153. PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_S)
  154. PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_D)
  155. PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_F)
  156. PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_G)
  157. PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_H)
  158. PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_J)
  159. PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_K)
  160.  
  161. PORT_START("IN.3")
  162. PORT_BIT(0x01, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_Z)
  163. PORT_BIT(0x02, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_X)
  164. PORT_BIT(0x04, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_C)
  165. PORT_BIT(0x08, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_V)
  166. PORT_BIT(0x10, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_B)
  167. PORT_BIT(0x20, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_N)
  168. PORT_BIT(0x40, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_M)
  169. PORT_BIT(0x80, IP_ACTIVE_HIGH, IPT_KEYPAD) PORT_CODE(KEYCODE_COMMA)
  170. INPUT_PORTS_END
  171.  
  172.  
  173. static GFXDECODE_START( gfx_mmahjong )
  174. GFXDECODE_ENTRY( "tiles", 0, gfx_8x8x1, 0, 1 )
  175. GFXDECODE_END
  176.  
  177.  
  178.  
  179. /******************************************************************************
  180. Machine Configs
  181. ******************************************************************************/
  182.  
  183. void mmahjong_state::mmahjong(machine_config &config)
  184. {
  185. // basic machine hardware
  186. Z80(config, m_maincpu, 11.0592_MHz_XTAL / 4);
  187. m_maincpu->set_addrmap(AS_PROGRAM, &mmahjong_state::main_map);
  188.  
  189. // video hardware
  190. GFXDECODE(config, "gfxdecode", "palette", gfx_mmahjong);
  191.  
  192. PALETTE(config, "palette", palette_device::MONOCHROME);
  193.  
  194. TILEMAP(config, m_tilemap, "gfxdecode", 0, 8, 8, TILEMAP_SCAN_ROWS, 32, 32).set_info_callback(FUNC(mmahjong_state::get_tile_info));
  195.  
  196. SCREEN(config, m_screen, SCREEN_TYPE_RASTER);
  197. m_screen->set_refresh_hz(60);
  198. m_screen->set_size(8*32, 8*32);
  199. m_screen->set_visarea(0, 8*32-1, 0, 8*32-1);
  200. m_screen->set_screen_update(FUNC(mmahjong_state::screen_update));
  201. m_screen->set_palette("palette");
  202.  
  203. // sound hardware
  204. SPEAKER(config, "speaker").front_center();
  205. DAC_1BIT(config, m_dac).add_route(ALL_OUTPUTS, "speaker", 0.25);
  206. }
  207.  
  208.  
  209.  
  210. /******************************************************************************
  211. ROM Definitions
  212. ******************************************************************************/
  213.  
  214. ROM_START( mmahjong )
  215. ROM_REGION( 0x10000, "maincpu", 0 )
  216. ROM_LOAD( "prg.rom", 0x0000, 0x4000, CRC(5adba031) SHA1(301413ded4778c7c0b19a508bb8309a57c7fc97f) )
  217.  
  218. ROM_REGION( 0x0800, "tiles", 0 )
  219. ROM_LOAD( "cg.rom", 0x0000, 0x0800, CRC(d1dfe5c1) SHA1(5042b89555867db418f4aeef6b520619d8f533f2) )
  220. ROM_END
  221.  
  222.  
  223.  
  224. /******************************************************************************
  225. Drivers
  226. ******************************************************************************/
  227.  
  228. // YEAR NAME PARENT CMP MACHINE INPUT STATE INIT COMPANY, FULLNAME, FLAGS
  229. CONS( 1982, mmahjong, 0, 0, mmahjong, mmahjong, mmahjong_state, empty_init, "<unknown>", "Micom Mahjong", MACHINE_SUPPORTS_SAVE )
  230.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement