From 7197c02726cdc66f21c7265c884a95ce1748df60 Mon Sep 17 00:00:00 2001 From: hap Date: Sun, 9 Jul 2023 22:18:42 +0200 Subject: [PATCH] changela: shorthand variable types --- src/mame/taito/changela.cpp | 24 +++---- src/mame/taito/changela.h | 110 ++++++++++++++--------------- src/mame/taito/changela_v.cpp | 128 ++++++++++++++++------------------ 3 files changed, 126 insertions(+), 136 deletions(-) diff --git a/src/mame/taito/changela.cpp b/src/mame/taito/changela.cpp index b7bcb04bacc..be4859a7703 100644 --- a/src/mame/taito/changela.cpp +++ b/src/mame/taito/changela.cpp @@ -93,12 +93,12 @@ TIMER_DEVICE_CALLBACK_MEMBER(changela_state::changela_scanline) MCU *********************************/ -void changela_state::changela_68705_port_a_w(uint8_t data) +void changela_state::changela_68705_port_a_w(u8 data) { m_port_a_out = data; } -void changela_state::changela_68705_port_c_w(uint8_t data) +void changela_state::changela_68705_port_c_w(u8 data) { // PC3 is connected to the CLOCK input of the LS374, so we latch the data on rising edge if (BIT(data, 3) && !BIT(m_port_c_out, 3)) @@ -111,14 +111,14 @@ void changela_state::changela_68705_port_c_w(uint8_t data) } // latch LS374 at U40 -uint8_t changela_state::mcu_r() +u8 changela_state::mcu_r() { //osd_printf_debug("Z80 MCU R = %x\n", m_mcu_out); return m_mcu_out & (BIT(m_port_c_out, 2) ? 0xff : m_mcu_in); } // latch LS374 at U39 -void changela_state::mcu_w(uint8_t data) +void changela_state::mcu_w(u8 data) { m_mcu_in = data; if (!BIT(m_port_c_out, 2)) @@ -126,7 +126,7 @@ void changela_state::mcu_w(uint8_t data) } // U30 -uint8_t changela_state::changela_24_r() +u8 changela_state::changela_24_r() { return (BIT(m_port_c_out, 1) << 3) | 0x07; // bits 2,1,0-N/C inputs } @@ -146,24 +146,24 @@ INTERRUPT_GEN_MEMBER(changela_state::chl_mcu_irq) Other I/O *********************************/ -uint8_t changela_state::changela_25_r() +u8 changela_state::changela_25_r() { // collisions on bits 3,2, bits 1,0-N/C inputs return (m_tree1_col << 3) | (m_tree0_col << 2) | 0x03; } -uint8_t changela_state::changela_30_r() +u8 changela_state::changela_30_r() { return m_wheel->read() & 0x0f; // wheel control (clocked input) signal on bits 3,2,1,0 } -uint8_t changela_state::changela_31_r() +u8 changela_state::changela_31_r() { /* If the new value is less than the old value, and it did not wrap around, or if the new value is greater than the old value, and it did wrap around, then we are moving LEFT. */ - uint8_t cur = m_wheel->read(); - uint8_t prev = m_prev_value_31; + u8 cur = m_wheel->read(); + u8 prev = m_prev_value_31; if ((cur < prev && (prev - cur) < 0x80) || (cur > prev && (cur - prev) > 0x80)) m_dir_31 = 1; @@ -176,9 +176,9 @@ uint8_t changela_state::changela_31_r() return (m_dir_31 << 3) | (m_left_bank_col << 2) | (m_right_bank_col << 1) | m_boat_shore_col; } -uint8_t changela_state::changela_2d_r() +u8 changela_state::changela_2d_r() { - int gas; + u8 gas; // Gas pedal is made up of 2 switches, 1 active low, 1 active high switch (m_gas->read() & 0x03) diff --git a/src/mame/taito/changela.h b/src/mame/taito/changela.h index 3174b74ea54..ddc829a84dc 100644 --- a/src/mame/taito/changela.h +++ b/src/mame/taito/changela.h @@ -40,26 +40,26 @@ protected: private: // devices/pointers - required_device m_maincpu; + required_device m_maincpu; required_device m_mcu; - required_device m_screen; + required_device m_screen; required_device m_palette; // memory pointers - required_shared_ptr m_spriteram; - required_shared_ptr m_videoram; - required_shared_ptr m_colorram; - required_region_ptr m_tilerom; - required_region_ptr m_obj0rom; - required_region_ptr m_obj1rom; - required_region_ptr m_sloperom; - required_region_ptr m_treerom; - required_region_ptr m_proms; + required_shared_ptr m_spriteram; + required_shared_ptr m_videoram; + required_shared_ptr m_colorram; + required_region_ptr m_tilerom; + required_region_ptr m_obj0rom; + required_region_ptr m_obj1rom; + required_region_ptr m_sloperom; + required_region_ptr m_treerom; + required_region_ptr m_proms; // input ports - required_ioport_array<2> m_inputs; - required_ioport m_gas; - required_ioport m_wheel; + required_ioport_array<2> m_inputs; + required_ioport m_gas; + required_ioport m_wheel; // video-related bitmap_ind16 m_obj0_bitmap; @@ -67,64 +67,64 @@ private: bitmap_ind16 m_tree0_bitmap; bitmap_ind16 m_tree1_bitmap; - std::unique_ptr m_riverram; - std::unique_ptr m_treeram; - uint8_t m_treeram2[0x20 * 2] = { }; - uint8_t m_stateram[0x40 * 3] = { }; + std::unique_ptr m_riverram; + std::unique_ptr m_treeram; + u8 m_treeram2[0x20 * 2] = { }; + u8 m_stateram[0x40 * 3] = { }; - uint32_t m_mem_dev_selected = 0; - uint32_t m_sloperom_bank = 0; - uint8_t m_tree_en = 0; - uint8_t m_horizon = 0; - uint8_t m_v_count_river = 0; - uint8_t m_v_count_tree = 0; - uint8_t m_tree_on[2] = { }; - emu_timer* m_scanline_timer = nullptr; + u8 m_mem_dev_selected = 0; + u32 m_sloperom_bank = 0; + u8 m_tree_en = 0; + u8 m_horizon = 0; + u8 m_v_count_river = 0; + u8 m_v_count_tree = 0; + u8 m_tree_on[2] = { }; + emu_timer *m_scanline_timer = nullptr; // mcu-related - uint8_t m_port_a_out = 0xff; - uint8_t m_port_c_out = 0xff; - uint8_t m_mcu_out = 0xff; - uint8_t m_mcu_in = 0xff; + u8 m_port_a_out = 0xff; + u8 m_port_c_out = 0xff; + u8 m_mcu_out = 0xff; + u8 m_mcu_in = 0xff; // misc - uint8_t m_tree0_col = 0; - uint8_t m_tree1_col = 0; - uint8_t m_left_bank_col = 0; - uint8_t m_right_bank_col = 0; - uint8_t m_boat_shore_col = 0; - uint8_t m_collision_reset = 0; - uint8_t m_tree_collision_reset = 0; - uint8_t m_prev_value_31 = 0; - uint8_t m_dir_31 = 0; + u8 m_tree0_col = 0; + u8 m_tree1_col = 0; + u8 m_left_bank_col = 0; + u8 m_right_bank_col = 0; + u8 m_boat_shore_col = 0; + u8 m_collision_reset = 0; + u8 m_tree_collision_reset = 0; + u8 m_prev_value_31 = 0; + u8 m_dir_31 = 0; // devices - uint8_t mcu_r(); - void mcu_w(uint8_t data); - void changela_68705_port_a_w(uint8_t data); - void changela_68705_port_c_w(uint8_t data); - uint8_t changela_24_r(); - uint8_t changela_25_r(); - uint8_t changela_30_r(); - uint8_t changela_31_r(); - uint8_t changela_2d_r(); + u8 mcu_r(); + void mcu_w(u8 data); + void changela_68705_port_a_w(u8 data); + void changela_68705_port_c_w(u8 data); + u8 changela_24_r(); + u8 changela_25_r(); + u8 changela_30_r(); + u8 changela_31_r(); + u8 changela_2d_r(); void mcu_pc_0_w(int state); void collision_reset_0_w(int state); void collision_reset_1_w(int state); void coin_counter_1_w(int state); void coin_counter_2_w(int state); - void changela_colors_w(offs_t offset, uint8_t data); - void changela_mem_device_select_w(uint8_t data); - void changela_mem_device_w(offs_t offset, uint8_t data); - uint8_t changela_mem_device_r(offs_t offset); - void changela_slope_rom_addr_hi_w(uint8_t data); - void changela_slope_rom_addr_lo_w(uint8_t data); + void changela_colors_w(offs_t offset, u8 data); + void changela_mem_device_select_w(u8 data); + void changela_mem_device_w(offs_t offset, u8 data); + u8 changela_mem_device_r(offs_t offset); + void changela_slope_rom_addr_hi_w(u8 data); + void changela_slope_rom_addr_lo_w(u8 data); INTERRUPT_GEN_MEMBER(chl_mcu_irq); TIMER_DEVICE_CALLBACK_MEMBER(changela_scanline); TIMER_CALLBACK_MEMBER(changela_scanline_callback); - uint32_t screen_update_changela(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); + u32 screen_update_changela(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect); void draw_obj0(bitmap_ind16 &bitmap, int sy); void draw_obj1(bitmap_ind16 &bitmap); void draw_river(bitmap_ind16 &bitmap, int sy); diff --git a/src/mame/taito/changela_v.cpp b/src/mame/taito/changela_v.cpp index e1163097e2e..2af8aaa36cd 100644 --- a/src/mame/taito/changela_v.cpp +++ b/src/mame/taito/changela_v.cpp @@ -20,10 +20,10 @@ TODO: Priority between tree0 and tree1. void changela_state::video_start() { - m_riverram = std::make_unique(0x800); + m_riverram = std::make_unique(0x800); save_pointer(NAME(m_riverram), 0x800); - m_treeram = std::make_unique(0x800); + m_treeram = std::make_unique(0x800); save_pointer(NAME(m_treeram), 0x800); m_screen->register_screen_bitmap(m_obj0_bitmap); @@ -42,34 +42,34 @@ void changela_state::video_start() void changela_state::draw_obj0(bitmap_ind16 &bitmap, int sy) { - uint8_t const *const ROM = m_obj0rom; - uint8_t const *const RAM = m_spriteram; + u8 const *const ROM = m_obj0rom; + u8 const *const RAM = m_spriteram; for (int sx = 0; sx < 256; sx++) { int vr = (RAM[sx * 4 + 0] & 0x80) >> 7; int hr = (RAM[sx * 4 + 0] & 0x40) >> 6; int hs = (RAM[sx * 4 + 0] & 0x20) >> 5; - uint32_t vsize = RAM[sx * 4 + 0] & 0x1f; - uint8_t ypos = ~RAM[sx * 4 + 1]; - uint8_t tile = RAM[sx * 4 + 2]; - uint8_t xpos = RAM[sx * 4 + 3]; + u32 vsize = RAM[sx * 4 + 0] & 0x1f; + u8 ypos = ~RAM[sx * 4 + 1]; + u8 tile = RAM[sx * 4 + 2]; + u8 xpos = RAM[sx * 4 + 3]; if (sy - ypos <= vsize) { for (int i = 0; i < 16; i++) { - uint8_t sum = sy - ypos; + u8 sum = sy - ypos; - uint8_t counter = i; + u8 counter = i; if (hr) counter ^= 0x0f; - uint32_t A8 = ((tile & 0x02) >> 1) ^ ((hr & hs) ^ hs); - uint32_t A7 = ((((vr ^ ((sum & 0x10) >> 4)) & ((vsize & 0x10) >> 4)) ^ 0x01) & (tile & 0x01)) ^ 0x01; - uint32_t rom_addr = (counter >> 1) | ((sum & 0x0f) << 3) | (A7 << 7) | (A8 << 8) | ((tile >> 2) << 9); + u32 A8 = ((tile & 0x02) >> 1) ^ ((hr & hs) ^ hs); + u32 A7 = ((((vr ^ ((sum & 0x10) >> 4)) & ((vsize & 0x10) >> 4)) ^ 0x01) & (tile & 0x01)) ^ 0x01; + u32 rom_addr = (counter >> 1) | ((sum & 0x0f) << 3) | (A7 << 7) | (A8 << 8) | ((tile >> 2) << 9); if (vr) rom_addr ^= (0x0f << 3); - uint8_t data; + u8 data; if (counter & 1) data = ROM[rom_addr] & 0x0f; else @@ -100,12 +100,12 @@ void changela_state::draw_obj0(bitmap_ind16 &bitmap, int sy) void changela_state::draw_obj1(bitmap_ind16 &bitmap) { - uint8_t const *const ROM = m_obj1rom; - uint8_t const *const RAM = m_videoram; + u8 const *const ROM = m_obj1rom; + u8 const *const RAM = m_videoram; - uint8_t reg[4] = { 0 }; // 4x4-bit registers (U58, U59) + u8 reg[4] = { 0 }; // 4x4-bit registers (U58, U59) - uint8_t attrib = 0; + u8 attrib = 0; for (int sy = 0; sy < 256; sy++) { @@ -118,7 +118,7 @@ void changela_state::draw_obj1(bitmap_ind16 &bitmap) if (!(RAM[ram_addr + 1] & 0x10) && (sx & 0x04)) // D4=0 enables latch at U32 attrib = RAM[ram_addr + 1]; - uint8_t tile = ROM[(tile_addr << 4) | ((sx & 0x04) >> 2) | ((sy & 0x07) << 1)]; + u8 tile = ROM[(tile_addr << 4) | ((sx & 0x04) >> 2) | ((sy & 0x07) << 1)]; reg[(sx & 0x0c) >> 2] = tile; int sum = (sx & 0x0f) + (attrib & 0x0f); // 4-bit adder (U45) @@ -159,21 +159,21 @@ void changela_state::draw_obj1(bitmap_ind16 &bitmap) void changela_state::draw_river(bitmap_ind16 &bitmap, int sy) { - uint8_t const *const ROM = m_sloperom; - uint8_t *const RAM = m_stateram; - uint8_t const *const TILE_ROM = m_tilerom; - uint8_t const *const TILE_RAM = m_riverram.get(); - uint8_t const *const PROM = m_proms; + u8 const *const ROM = m_sloperom; + u8 *const RAM = m_stateram; + u8 const *const TILE_ROM = m_tilerom; + u8 const *const TILE_RAM = m_riverram.get(); + u8 const *const PROM = m_proms; int preload = ((sy < 32) ? 1 : 0); - uint8_t math_train[10] = { 0 }; - uint8_t pre_train[3] = { 0 }; + u8 math_train[10] = { 0 }; + u8 pre_train[3] = { 0 }; - uint8_t prev_state = 0; + u8 prev_state = 0; - uint8_t ram_count = 0; - uint8_t rom_count = 0; + u8 ram_count = 0; + u8 rom_count = 0; int hosc = 0; int carry = 0; @@ -185,7 +185,7 @@ void changela_state::draw_river(bitmap_ind16 &bitmap, int sy) // ----- STATE MACHINE ----- for (int i = 0; i < 0x20; i++) { - uint8_t curr_state = PROM[i]; + u8 curr_state = PROM[i]; // Update Counters if (prev_state & 0x80) @@ -317,25 +317,25 @@ void changela_state::draw_river(bitmap_ind16 &bitmap, int sy) void changela_state::draw_tree(bitmap_ind16 &bitmap, int sy, int tree_num) { // State machine - uint8_t const *const ROM = m_sloperom; - uint8_t *const RAM = m_stateram + 0x40 + 0x40 * tree_num; - uint8_t const *const PROM = m_proms; + u8 const *const ROM = m_sloperom; + u8 *const RAM = m_stateram + 0x40 + 0x40 * tree_num; + u8 const *const PROM = m_proms; // Tree Data - uint8_t *const RAM2 = m_treeram2 + 0x20 * tree_num; - uint8_t const *const TILE_ROM = (tree_num ? (m_treerom + 0x1000) : (m_tilerom + 0x2000)); - uint8_t const *const TILE_RAM = (tree_num ? m_treerom : m_treeram.get()); + u8 *const RAM2 = m_treeram2 + 0x20 * tree_num; + u8 const *const TILE_ROM = (tree_num ? (m_treerom + 0x1000) : (m_tilerom + 0x2000)); + u8 const *const TILE_RAM = (tree_num ? m_treerom : m_treeram.get()); int preload = ((sy < 32) ? 1 : 0); - uint8_t math_train[10] = { 0 }; - uint8_t pre_train[3] = { 0 }; - uint8_t tree_train[3] = { 0 }; + u8 math_train[10] = { 0 }; + u8 pre_train[3] = { 0 }; + u8 tree_train[3] = { 0 }; - uint8_t prev_state = 0; + u8 prev_state = 0; - uint8_t ram_count = 0; - uint8_t rom_count = 0; + u8 ram_count = 0; + u8 rom_count = 0; int hosc = 0; int carry = 0; @@ -357,7 +357,7 @@ void changela_state::draw_tree(bitmap_ind16 &bitmap, int sy, int tree_num) //* ----- STATE MACHINE ----- for (int i = 0; i < 0x20; i++) { - uint8_t curr_state = PROM[i]; + u8 curr_state = PROM[i]; // Update Counters if (prev_state & 0x80) @@ -619,21 +619,11 @@ TIMER_CALLBACK_MEMBER(changela_state::changela_scanline_callback) // Collision Detection for (int sx = 1; sx < 256; sx++) { - int riv_col; - if ((m_river_bitmap.pix(sy, sx) == 0x08) - || (m_river_bitmap.pix(sy, sx) == 0x09) - || (m_river_bitmap.pix(sy, sx) == 0x0a)) - riv_col = 1; - else - riv_col = 0; + u16 pix = m_river_bitmap.pix(sy, sx); + const bool riv_col = (pix == 0x08 || pix == 0x09 || pix == 0x0a); - int prev_col; - if ((m_river_bitmap.pix(sy, sx-1) == 0x08) - || (m_river_bitmap.pix(sy, sx-1) == 0x09) - || (m_river_bitmap.pix(sy, sx-1) == 0x0a)) - prev_col = 1; - else - prev_col = 0; + pix = m_river_bitmap.pix(sy, sx-1); + const bool prev_col = (pix == 0x08 || pix == 0x09 || pix == 0x0a); if (m_obj0_bitmap.pix(sy, sx) == 0x14) // Car Outline Color { @@ -646,15 +636,15 @@ TIMER_CALLBACK_MEMBER(changela_state::changela_scanline_callback) m_tree1_col = 1; // Hit Right Bank - if (riv_col == 0 && prev_col == 1) + if (!riv_col && prev_col) m_right_bank_col = 1; // Hit Left Bank - if (riv_col == 1 && prev_col == 0) + if (riv_col && !prev_col) m_left_bank_col = 1; // Boat Hit Shore - if (riv_col == 1) + if (riv_col) m_boat_shore_col = 1; } } @@ -675,7 +665,7 @@ TIMER_CALLBACK_MEMBER(changela_state::changela_scanline_callback) m_scanline_timer->adjust(m_screen->time_until_pos(sy), sy); } -uint32_t changela_state::screen_update_changela(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) +u32 changela_state::screen_update_changela(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect) { copybitmap(bitmap, m_river_bitmap, 0, 0, 0, 0, cliprect); copybitmap_trans(bitmap, m_obj0_bitmap, 0, 0, 0, 0, cliprect, 0); @@ -686,7 +676,7 @@ uint32_t changela_state::screen_update_changela(screen_device &screen, bitmap_in return 0; } -void changela_state::changela_colors_w(offs_t offset, uint8_t data) +void changela_state::changela_colors_w(offs_t offset, u8 data) { /* Each color is combined from 3 bits from open-collector outputs of ram. Each of the bits is connected to a 220, 470, or 1000 Ohm resistor. @@ -703,10 +693,10 @@ void changela_state::changela_colors_w(offs_t offset, uint8_t data) 111 | 3.819 (2.2k) Which were normalized to produce the following table: */ - static const uint8_t color_table[8] = { 0, 7, 18, 31, 58, 88, 146, 255 }; + static const u8 color_table[8] = { 0, 7, 18, 31, 58, 88, 146, 255 }; int r, g, b; - uint32_t c, color_index; + u32 c, color_index; c = (data) | ((offset & 0x01) << 8); //* a0 used as D8 bit input c ^= 0x1ff; // active low @@ -722,7 +712,7 @@ void changela_state::changela_colors_w(offs_t offset, uint8_t data) } -void changela_state::changela_mem_device_select_w(uint8_t data) +void changela_state::changela_mem_device_select_w(u8 data) { /* (data & 0x07) possible settings: @@ -737,7 +727,7 @@ void changela_state::changela_mem_device_select_w(uint8_t data) m_tree_en = (data & 0x30) >> 4; } -void changela_state::changela_mem_device_w(offs_t offset, uint8_t data) +void changela_state::changela_mem_device_w(offs_t offset, u8 data) { switch (m_mem_dev_selected) { @@ -760,7 +750,7 @@ void changela_state::changela_mem_device_w(offs_t offset, uint8_t data) } -uint8_t changela_state::changela_mem_device_r(offs_t offset) +u8 changela_state::changela_mem_device_r(offs_t offset) { switch (m_mem_dev_selected) { @@ -778,12 +768,12 @@ uint8_t changela_state::changela_mem_device_r(offs_t offset) } -void changela_state::changela_slope_rom_addr_hi_w(uint8_t data) +void changela_state::changela_slope_rom_addr_hi_w(u8 data) { m_sloperom_bank = (data & 0x03) << 9; } -void changela_state::changela_slope_rom_addr_lo_w(uint8_t data) +void changela_state::changela_slope_rom_addr_lo_w(u8 data) { m_horizon = data; }