de-duplicate number conversion code (nw)

This commit is contained in:
David Haywood 2014-09-23 11:35:29 +00:00
parent 7915ef329d
commit a1aed6adf4
6 changed files with 99 additions and 82 deletions

View file

@ -92,9 +92,9 @@ WRITE16_MEMBER(legionna_state::sound_comms_w)
static ADDRESS_MAP_START( legionna_cop_mem, AS_PROGRAM, 16, legionna_state )
// AM_RANGE(0x10041c, 0x10041d) AM_WRITE(cop_angle_target_w) // angle target (for 0x6200 COP macro)
// AM_RANGE(0x10041e, 0x10041f) AM_WRITE(cop_angle_step_w) // angle step (for 0x6200 COP macro)
// AM_RANGE(0x100420, 0x100421) AM_WRITE(cop_itoa_low_w)
// AM_RANGE(0x100422, 0x100423) AM_WRITE(cop_itoa_high_w)
// AM_RANGE(0x100424, 0x100425) AM_WRITE(cop_itoa_digit_count_w)
AM_RANGE(0x100420, 0x100421) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_low_w)
AM_RANGE(0x100422, 0x100423) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_high_w)
AM_RANGE(0x100424, 0x100425) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_digit_count_w)
AM_RANGE(0x100428, 0x100429) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v1_w)
AM_RANGE(0x10042a, 0x10042b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v2_w)
AM_RANGE(0x100432, 0x100433) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_data_w)
@ -124,7 +124,7 @@ static ADDRESS_MAP_START( legionna_cop_mem, AS_PROGRAM, 16, legionna_state )
// AM_RANGE(0x100580, 0x100581) AM_READ(cop_collision_status_r)
// AM_RANGE(0x100582, 0x100587) AM_READ(cop_collision_status_val_r)
// AM_RANGE(0x100588, 0x100589) AM_READ(cop_collision_status_stat_r)
// AM_RANGE(0x100590, 0x100599) AM_READ(cop_itoa_digits_r)
AM_RANGE(0x100590, 0x100599) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_itoa_digits_r)
// AM_RANGE(0x1005b0, 0x1005b1) AM_READ(cop_status_r)
// AM_RANGE(0x1005b2, 0x1005b3) AM_READ(cop_dist_r)
// AM_RANGE(0x1005b4, 0x1005b5) AM_READ(cop_angle_r)

View file

@ -173,10 +173,9 @@ void raiden2_state::machine_start()
save_item(NAME(raiden2_tilemap_enable));
save_item(NAME(prg_bank));
save_item(NAME(cop_bank));
save_item(NAME(cop_itoa));
save_item(NAME(cop_status));
save_item(NAME(cop_scale));
save_item(NAME(cop_itoa_digit_count));
save_item(NAME(cop_angle));
save_item(NAME(cop_dist));
@ -197,7 +196,8 @@ void raiden2_state::machine_start()
save_item(NAME(scrollvals));
save_item(NAME(cop_regs));
save_item(NAME(cop_itoa_digits));
save_item(NAME(sprite_prot_src_addr));
@ -257,39 +257,6 @@ WRITE16_MEMBER(raiden2_state::m_videoram_private_w)
}
}
WRITE16_MEMBER(raiden2_state::cop_itoa_low_w)
{
cop_itoa = (cop_itoa & ~UINT32(mem_mask)) | (data & mem_mask);
int digits = 1 << cop_itoa_digit_count*2;
UINT32 val = cop_itoa;
if(digits > 9)
digits = 9;
for(int i=0; i<digits; i++)
if(!val && i)
cop_itoa_digits[i] = 0x20;
else {
cop_itoa_digits[i] = 0x30 | (val % 10);
val = val / 10;
}
cop_itoa_digits[9] = 0;
}
WRITE16_MEMBER(raiden2_state::cop_itoa_high_w)
{
cop_itoa = (cop_itoa & ~(mem_mask << 16)) | ((data & mem_mask) << 16);
}
WRITE16_MEMBER(raiden2_state::cop_itoa_digit_count_w)
{
COMBINE_DATA(&cop_itoa_digit_count);
}
READ16_MEMBER(raiden2_state::cop_itoa_digits_r)
{
return cop_itoa_digits[offset*2] | (cop_itoa_digits[offset*2+1] << 8);
}
READ16_MEMBER(raiden2_state::cop_status_r)
{
@ -1084,7 +1051,6 @@ void raiden2_state::common_reset()
fg_bank=6;
mid_bank=1;
tx_bank = 0;
cop_itoa_digit_count = 4; //TODO: Raiden 2 never inits the BCD register, value here is a guess (8 digits, as WR is 10.000.000 + a)
}
MACHINE_RESET_MEMBER(raiden2_state,raiden2)
@ -1332,9 +1298,9 @@ WRITE16_MEMBER(raiden2_state::cop_sort_dma_trig_w)
static ADDRESS_MAP_START( raiden2_cop_mem, AS_PROGRAM, 16, raiden2_state )
AM_RANGE(0x0041c, 0x0041d) AM_WRITE(cop_angle_target_w) // angle target (for 0x6200 COP macro)
AM_RANGE(0x0041e, 0x0041f) AM_WRITE(cop_angle_step_w) // angle step (for 0x6200 COP macro)
AM_RANGE(0x00420, 0x00421) AM_WRITE(cop_itoa_low_w)
AM_RANGE(0x00422, 0x00423) AM_WRITE(cop_itoa_high_w)
AM_RANGE(0x00424, 0x00425) AM_WRITE(cop_itoa_digit_count_w)
AM_RANGE(0x00420, 0x00421) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_low_w)
AM_RANGE(0x00422, 0x00423) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_high_w)
AM_RANGE(0x00424, 0x00425) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_digit_count_w)
AM_RANGE(0x00428, 0x00429) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v1_w)
AM_RANGE(0x0042a, 0x0042b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v2_w)
AM_RANGE(0x00432, 0x00433) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_data_w)
@ -1364,7 +1330,7 @@ static ADDRESS_MAP_START( raiden2_cop_mem, AS_PROGRAM, 16, raiden2_state )
AM_RANGE(0x00580, 0x00581) AM_READ(cop_collision_status_r)
AM_RANGE(0x00582, 0x00587) AM_READ(cop_collision_status_val_r)
AM_RANGE(0x00588, 0x00589) AM_READ(cop_collision_status_stat_r)
AM_RANGE(0x00590, 0x00599) AM_READ(cop_itoa_digits_r)
AM_RANGE(0x00590, 0x00599) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_itoa_digits_r)
AM_RANGE(0x005b0, 0x005b1) AM_READ(cop_status_r)
AM_RANGE(0x005b2, 0x005b3) AM_READ(cop_dist_r)
AM_RANGE(0x005b4, 0x005b5) AM_READ(cop_angle_r)
@ -1833,6 +1799,7 @@ static MACHINE_CONFIG_START( raiden2, raiden2_state )
MCFG_RAIDEN2COP_ADD("raiden2cop")
MCFG_RAIDEN2COP_VIDEORAM_OUT_CB(WRITE16(raiden2_state, m_videoram_private_w))
MCFG_ITOA_UNUSED_DIGIT_VALUE(0x20)
MCFG_VIDEO_START_OVERRIDE(raiden2_state,raiden2)
@ -1893,6 +1860,7 @@ static MACHINE_CONFIG_START( zeroteam, raiden2_state )
MCFG_RAIDEN2COP_ADD("raiden2cop")
MCFG_RAIDEN2COP_VIDEORAM_OUT_CB(WRITE16(raiden2_state, m_videoram_private_w))
MCFG_ITOA_UNUSED_DIGIT_VALUE(0x20)
MCFG_VIDEO_START_OVERRIDE(raiden2_state,raiden2)

View file

@ -26,10 +26,9 @@ public:
raiden2_tilemap_enable(0),
prg_bank(0),
cop_bank(0),
cop_itoa(0),
cop_status(0),
cop_scale(0),
cop_itoa_digit_count(0),
cop_angle(0),
cop_dist(0),
@ -51,7 +50,7 @@ public:
{
memset(scrollvals, 0, sizeof(UINT16)*6);
memset(cop_regs, 0, sizeof(UINT32)*8);
memset(cop_itoa_digits, 0, sizeof(UINT8)*10);
memset(sprite_prot_src_addr, 0, sizeof(UINT16)*2);
memset(cop_collision_info, 0, sizeof(colinfo)*2);
@ -64,9 +63,7 @@ public:
required_device<gfxdecode_device> m_gfxdecode;
required_device<palette_device> m_palette;
DECLARE_WRITE16_MEMBER( cop_itoa_low_w );
DECLARE_WRITE16_MEMBER( cop_itoa_high_w );
DECLARE_WRITE16_MEMBER( cop_itoa_digit_count_w );
DECLARE_WRITE16_MEMBER( cop_scale_w );
DECLARE_WRITE16_MEMBER( cop_angle_target_w );
DECLARE_WRITE16_MEMBER( cop_angle_step_w );
@ -77,7 +74,6 @@ public:
DECLARE_WRITE16_MEMBER( cop_reg_low_w );
DECLARE_WRITE16_MEMBER( cop_cmd_w );
DECLARE_READ16_MEMBER ( cop_itoa_digits_r );
DECLARE_READ16_MEMBER ( cop_collision_status_r );
DECLARE_READ16_MEMBER (cop_collision_status_val_r);
DECLARE_READ16_MEMBER (cop_collision_status_stat_r);
@ -135,14 +131,16 @@ public:
UINT16 cop_bank;
UINT16 scrollvals[6];
UINT32 cop_regs[8], cop_itoa;
UINT16 cop_status, cop_scale, cop_itoa_digit_count, cop_angle, cop_dist;
UINT8 cop_itoa_digits[10];
UINT32 cop_regs[8];
UINT16 cop_status, cop_scale, cop_angle, cop_dist;
UINT16 cop_angle_target;
UINT16 cop_angle_step;
DECLARE_WRITE16_MEMBER( sprite_prot_x_w );
DECLARE_WRITE16_MEMBER( sprite_prot_y_w );
DECLARE_WRITE16_MEMBER( sprite_prot_src_seg_w );

View file

@ -22,6 +22,9 @@ raiden2cop_device::raiden2cop_device(const machine_config &mconfig, const char *
cop_dma_adr_rel(0),
pal_brightness_val(0),
pal_brightness_mode(0),
cop_itoa(0),
cop_itoa_digit_count(0),
m_cop_itoa_unused_digit_value(0x30),
m_videoramout_cb(*this),
m_palette(*this, ":palette")
{
@ -33,6 +36,8 @@ raiden2cop_device::raiden2cop_device(const machine_config &mconfig, const char *
memset(cop_dma_src, 0, sizeof(UINT16)*(0x200));
memset(cop_dma_dst, 0, sizeof(UINT16)*(0x200));
memset(cop_dma_size, 0, sizeof(UINT16)*(0x200));
memset(cop_itoa_digits, 0, sizeof(UINT8)*10);
}
@ -62,7 +67,14 @@ void raiden2cop_device::device_start()
save_item(NAME(cop_dma_dst));
save_item(NAME(cop_dma_size));
save_item(NAME(cop_itoa));
save_item(NAME(cop_itoa_digit_count));
save_item(NAME(cop_itoa_digits));
m_videoramout_cb.resolve_safe();
cop_itoa_digit_count = 4; //TODO: Raiden 2 never inits the BCD register, value here is a guess (8 digits, as WR is 10.000.000 + a)
}
/*** Command Table uploads ***/
@ -547,3 +559,49 @@ WRITE16_MEMBER(raiden2cop_device::cop_dma_trigger_w)
}
}
/* Number Conversion */
// according to score display in https://www.youtube.com/watch?v=T1M8sxYgt9A
// we should return 0x30 for unused digits? according to Raiden 2 and Zero
// Team the value should be 0x20, can this be configured?
WRITE16_MEMBER(raiden2cop_device::cop_itoa_low_w)
{
cop_itoa = (cop_itoa & ~UINT32(mem_mask)) | (data & mem_mask);
int digits = 1 << cop_itoa_digit_count*2;
UINT32 val = cop_itoa;
if(digits > 9)
digits = 9;
for (int i = 0; i < digits; i++)
{
if (!val && i)
{
cop_itoa_digits[i] = m_cop_itoa_unused_digit_value;
}
else
{
cop_itoa_digits[i] = 0x30 | (val % 10);
val = val / 10;
}
}
cop_itoa_digits[9] = 0;
}
WRITE16_MEMBER(raiden2cop_device::cop_itoa_high_w)
{
cop_itoa = (cop_itoa & ~(mem_mask << 16)) | ((data & mem_mask) << 16);
}
WRITE16_MEMBER(raiden2cop_device::cop_itoa_digit_count_w)
{
COMBINE_DATA(&cop_itoa_digit_count);
}
READ16_MEMBER(raiden2cop_device::cop_itoa_digits_r)
{
return cop_itoa_digits[offset*2] | (cop_itoa_digits[offset*2+1] << 8);
}

View file

@ -15,6 +15,9 @@
#define MCFG_RAIDEN2COP_VIDEORAM_OUT_CB(_devcb) \
devcb = &raiden2cop_device::set_m_videoramout_cb(*device, DEVCB_##_devcb);
#define MCFG_ITOA_UNUSED_DIGIT_VALUE(value) \
raiden2cop_device::set_itoa_unused_digit_value(*device, value);
class raiden2cop_device : public device_t
{
@ -67,6 +70,20 @@ public:
const UINT8 fade_table(int v);
template<class _Object> static devcb_base &set_m_videoramout_cb(device_t &device, _Object object) { return downcast<raiden2cop_device &>(device).m_videoramout_cb.set_callback(object); }
// Number Conversion
DECLARE_WRITE16_MEMBER( cop_itoa_low_w );
DECLARE_WRITE16_MEMBER( cop_itoa_high_w );
DECLARE_WRITE16_MEMBER( cop_itoa_digit_count_w );
DECLARE_READ16_MEMBER ( cop_itoa_digits_r );
UINT32 cop_itoa;
UINT16 cop_itoa_digit_count;
UINT8 cop_itoa_digits[10];
UINT8 m_cop_itoa_unused_digit_value;
static void set_itoa_unused_digit_value(device_t &device, int value) { downcast<raiden2cop_device &>(device).m_cop_itoa_unused_digit_value = value; }
protected:
// device-level overrides
virtual void device_start();

View file

@ -1685,7 +1685,8 @@ void seibu_cop_legacy_device::device_start()
}
//-------------------------------------------------
// device_reset - device-specific startup
// device_
// device-specific startup
//-------------------------------------------------
void seibu_cop_legacy_device::device_reset()
@ -2112,13 +2113,6 @@ READ16_MEMBER( seibu_cop_legacy_device::generic_cop_r )
case 0x188/2:
return m_cop_hit_val_unk;
/* BCD */
case 0x190/2:
case 0x192/2:
case 0x194/2:
case 0x196/2:
case 0x198/2:
return retvalue;
/* RNG, trusted */
case 0x1a0/2:
@ -2144,7 +2138,6 @@ READ16_MEMBER( seibu_cop_legacy_device::generic_cop_r )
WRITE16_MEMBER( seibu_cop_legacy_device::generic_cop_w )
{
UINT32 temp32;
switch (offset)
{
@ -2189,24 +2182,7 @@ WRITE16_MEMBER( seibu_cop_legacy_device::generic_cop_w )
case (0x01c/2): m_cop_angle_compare = UINT16(m_cop_mcu_ram[0x1c/2]); break;
case (0x01e/2): m_cop_angle_mod_val = UINT16(m_cop_mcu_ram[0x1e/2]); break;
/* BCD Protection */
case (0x020/2):
case (0x022/2):
temp32 = (m_cop_mcu_ram[0x020/2]) | (m_cop_mcu_ram[0x022/2] << 16);
m_cop_mcu_ram[0x190/2] = (((temp32 / 1) % 10) + (((temp32 / 10) % 10) << 8) + 0x3030);
m_cop_mcu_ram[0x192/2] = (((temp32 / 100) % 10) + (((temp32 / 1000) % 10) << 8) + 0x3030);
m_cop_mcu_ram[0x194/2] = (((temp32 / 10000) % 10) + (((temp32 / 100000) % 10) << 8) + 0x3030);
m_cop_mcu_ram[0x196/2] = (((temp32 / 1000000) % 10) + (((temp32 / 10000000) % 10) << 8) + 0x3030);
m_cop_mcu_ram[0x198/2] = (((temp32 / 100000000) % 10) + (((temp32 / 1000000000) % 10) << 8) + 0x3030);
break;
case (0x024/2):
/*
This looks like a register for the BCD...
Godzilla and Heated Barrel sets 3
Denjin Makai sets 3 at start-up and toggles between 2 and 3 during gameplay on the BCD subroutine
SD Gundam sets 0
*/
break;