Previous 199869 Revisions Next

r32311 Tuesday 23rd September, 2014 at 11:35:29 UTC by David Haywood
de-duplicate number conversion code (nw)
[src/mame/drivers]legionna.c raiden2.c
[src/mame/includes]raiden2.h
[src/mame/machine]raiden2cop.c raiden2cop.h seicop.c

trunk/src/mame/machine/raiden2cop.c
r32310r32311
2222   cop_dma_adr_rel(0),
2323   pal_brightness_val(0),
2424   pal_brightness_mode(0),
25   cop_itoa(0),
26   cop_itoa_digit_count(0),
27   m_cop_itoa_unused_digit_value(0x30),
2528   m_videoramout_cb(*this),
2629   m_palette(*this, ":palette")
2730{
r32310r32311
3336   memset(cop_dma_src, 0, sizeof(UINT16)*(0x200));
3437   memset(cop_dma_dst, 0, sizeof(UINT16)*(0x200));
3538   memset(cop_dma_size, 0, sizeof(UINT16)*(0x200));
39
40   memset(cop_itoa_digits, 0, sizeof(UINT8)*10);
3641}
3742
3843
r32310r32311
6267   save_item(NAME(cop_dma_dst));
6368   save_item(NAME(cop_dma_size));
6469
70   save_item(NAME(cop_itoa));
71   save_item(NAME(cop_itoa_digit_count));
72   save_item(NAME(cop_itoa_digits));
73
6574   m_videoramout_cb.resolve_safe();
75
76   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)
77
6678}
6779
6880/*** Command Table uploads ***/
r32310r32311
547559   }
548560
549561}
562
563/* Number Conversion */
564
565// according to score display in  https://www.youtube.com/watch?v=T1M8sxYgt9A
566// we should return 0x30 for unused digits? according to Raiden 2 and Zero
567// Team the value should be 0x20, can this be configured?
568WRITE16_MEMBER(raiden2cop_device::cop_itoa_low_w)
569{
570   cop_itoa = (cop_itoa & ~UINT32(mem_mask)) | (data & mem_mask);
571
572   int digits = 1 << cop_itoa_digit_count*2;
573   UINT32 val = cop_itoa;
574
575   if(digits > 9)
576      digits = 9;
577   
578   for (int i = 0; i < digits; i++)
579   {
580      if (!val && i)
581      {
582         cop_itoa_digits[i] = m_cop_itoa_unused_digit_value;
583      }
584      else
585      {
586         cop_itoa_digits[i] = 0x30 | (val % 10);
587         val = val / 10;
588      }
589   }
590   
591   cop_itoa_digits[9] = 0;
592}
593
594WRITE16_MEMBER(raiden2cop_device::cop_itoa_high_w)
595{
596   cop_itoa = (cop_itoa & ~(mem_mask << 16)) | ((data & mem_mask) << 16);
597}
598
599WRITE16_MEMBER(raiden2cop_device::cop_itoa_digit_count_w)
600{
601   COMBINE_DATA(&cop_itoa_digit_count);
602}
603
604READ16_MEMBER(raiden2cop_device::cop_itoa_digits_r)
605{
606   return cop_itoa_digits[offset*2] | (cop_itoa_digits[offset*2+1] << 8);
607}
trunk/src/mame/machine/raiden2cop.h
r32310r32311
1515#define MCFG_RAIDEN2COP_VIDEORAM_OUT_CB(_devcb) \
1616   devcb = &raiden2cop_device::set_m_videoramout_cb(*device, DEVCB_##_devcb);
1717
18#define MCFG_ITOA_UNUSED_DIGIT_VALUE(value) \
19   raiden2cop_device::set_itoa_unused_digit_value(*device, value);
1820
21
1922class raiden2cop_device : public device_t
2023{
2124public:
r32310r32311
6770   const UINT8 fade_table(int v);
6871
6972   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); }
73
74   // Number Conversion
75
76   DECLARE_WRITE16_MEMBER( cop_itoa_low_w );
77   DECLARE_WRITE16_MEMBER( cop_itoa_high_w );
78   DECLARE_WRITE16_MEMBER( cop_itoa_digit_count_w );
79   DECLARE_READ16_MEMBER ( cop_itoa_digits_r );
80   
81   UINT32 cop_itoa;
82   UINT16 cop_itoa_digit_count;
83   UINT8 cop_itoa_digits[10];
84   UINT8 m_cop_itoa_unused_digit_value;
85
86   static void set_itoa_unused_digit_value(device_t &device, int value) { downcast<raiden2cop_device &>(device).m_cop_itoa_unused_digit_value = value; }
7087protected:
7188   // device-level overrides
7289   virtual void device_start();
trunk/src/mame/machine/seicop.c
r32310r32311
16851685}
16861686
16871687//-------------------------------------------------
1688//  device_reset - device-specific startup
1688//  device_
1689//  device-specific startup
16891690//-------------------------------------------------
16901691
16911692void seibu_cop_legacy_device::device_reset()
r32310r32311
21122113      case 0x188/2:
21132114         return m_cop_hit_val_unk;
21142115
2115      /* BCD */
2116      case 0x190/2:
2117      case 0x192/2:
2118      case 0x194/2:
2119      case 0x196/2:
2120      case 0x198/2:
2121         return retvalue;
21222116
21232117      /* RNG, trusted */
21242118      case 0x1a0/2:
r32310r32311
21442138
21452139WRITE16_MEMBER( seibu_cop_legacy_device::generic_cop_w )
21462140{
2147   UINT32 temp32;
21482141
21492142   switch (offset)
21502143   {
r32310r32311
21892182      case (0x01c/2): m_cop_angle_compare = UINT16(m_cop_mcu_ram[0x1c/2]);  break;
21902183      case (0x01e/2): m_cop_angle_mod_val = UINT16(m_cop_mcu_ram[0x1e/2]); break;
21912184
2192      /* BCD Protection */
2193      case (0x020/2):
2194      case (0x022/2):
2195         temp32 = (m_cop_mcu_ram[0x020/2]) | (m_cop_mcu_ram[0x022/2] << 16);
2196         m_cop_mcu_ram[0x190/2] = (((temp32 / 1) % 10) + (((temp32 / 10) % 10) << 8) + 0x3030);
2197         m_cop_mcu_ram[0x192/2] = (((temp32 / 100) % 10) + (((temp32 / 1000) % 10) << 8) + 0x3030);
2198         m_cop_mcu_ram[0x194/2] = (((temp32 / 10000) % 10) + (((temp32 / 100000) % 10) << 8) + 0x3030);
2199         m_cop_mcu_ram[0x196/2] = (((temp32 / 1000000) % 10) + (((temp32 / 10000000) % 10) << 8) + 0x3030);
2200         m_cop_mcu_ram[0x198/2] = (((temp32 / 100000000) % 10) + (((temp32 / 1000000000) % 10) << 8) + 0x3030);
2201         break;
2202      case (0x024/2):
2203         /*
2204         This looks like a register for the BCD...
2205         Godzilla and Heated Barrel sets 3
2206         Denjin Makai sets 3 at start-up and toggles between 2 and 3 during gameplay on the BCD subroutine
2207         SD Gundam sets 0
2208         */
2209         break;
22102185
22112186
2187
22122188         
22132189         
22142190
trunk/src/mame/includes/raiden2.h
r32310r32311
2626        raiden2_tilemap_enable(0),
2727        prg_bank(0),
2828        cop_bank(0),
29        cop_itoa(0),
3029        cop_status(0),
3130        cop_scale(0),
32        cop_itoa_digit_count(0),
31
3332        cop_angle(0),
3433        cop_dist(0),
3534
r32310r32311
5150   {
5251        memset(scrollvals, 0, sizeof(UINT16)*6);
5352        memset(cop_regs, 0, sizeof(UINT32)*8);
54        memset(cop_itoa_digits, 0, sizeof(UINT8)*10);
5553
54
5655        memset(sprite_prot_src_addr, 0, sizeof(UINT16)*2);
5756        memset(cop_collision_info, 0, sizeof(colinfo)*2);
5857   }
r32310r32311
6463   required_device<gfxdecode_device> m_gfxdecode;
6564   required_device<palette_device> m_palette;
6665
67   DECLARE_WRITE16_MEMBER( cop_itoa_low_w );
68   DECLARE_WRITE16_MEMBER( cop_itoa_high_w );
69   DECLARE_WRITE16_MEMBER( cop_itoa_digit_count_w );
66
7067   DECLARE_WRITE16_MEMBER( cop_scale_w );
7168   DECLARE_WRITE16_MEMBER( cop_angle_target_w );
7269   DECLARE_WRITE16_MEMBER( cop_angle_step_w );
r32310r32311
7774   DECLARE_WRITE16_MEMBER( cop_reg_low_w );
7875
7976   DECLARE_WRITE16_MEMBER( cop_cmd_w );
80   DECLARE_READ16_MEMBER ( cop_itoa_digits_r );
8177   DECLARE_READ16_MEMBER ( cop_collision_status_r );
8278   DECLARE_READ16_MEMBER (cop_collision_status_val_r);
8379   DECLARE_READ16_MEMBER (cop_collision_status_stat_r);
r32310r32311
135131   UINT16 cop_bank;
136132
137133   UINT16 scrollvals[6];
138   UINT32 cop_regs[8], cop_itoa;
139   UINT16 cop_status, cop_scale, cop_itoa_digit_count, cop_angle, cop_dist;
140   UINT8 cop_itoa_digits[10];
134   UINT32 cop_regs[8];
135   UINT16 cop_status, cop_scale, cop_angle, cop_dist;
136   
141137
142138   UINT16 cop_angle_target;
143139   UINT16 cop_angle_step;
144140
145141
142
143
146144   DECLARE_WRITE16_MEMBER( sprite_prot_x_w );
147145   DECLARE_WRITE16_MEMBER( sprite_prot_y_w );
148146   DECLARE_WRITE16_MEMBER( sprite_prot_src_seg_w );
trunk/src/mame/drivers/legionna.c
r32310r32311
9292static ADDRESS_MAP_START( legionna_cop_mem, AS_PROGRAM, 16, legionna_state )
9393//   AM_RANGE(0x10041c, 0x10041d) AM_WRITE(cop_angle_target_w) // angle target (for 0x6200 COP macro)
9494//   AM_RANGE(0x10041e, 0x10041f) AM_WRITE(cop_angle_step_w)   // angle step   (for 0x6200 COP macro)
95//   AM_RANGE(0x100420, 0x100421) AM_WRITE(cop_itoa_low_w)
96//   AM_RANGE(0x100422, 0x100423) AM_WRITE(cop_itoa_high_w)
97//   AM_RANGE(0x100424, 0x100425) AM_WRITE(cop_itoa_digit_count_w)
95   AM_RANGE(0x100420, 0x100421) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_low_w)
96   AM_RANGE(0x100422, 0x100423) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_high_w)
97   AM_RANGE(0x100424, 0x100425) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_digit_count_w)
9898   AM_RANGE(0x100428, 0x100429) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v1_w)
9999   AM_RANGE(0x10042a, 0x10042b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v2_w)
100100   AM_RANGE(0x100432, 0x100433) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_data_w)
r32310r32311
124124//   AM_RANGE(0x100580, 0x100581) AM_READ(cop_collision_status_r)
125125//   AM_RANGE(0x100582, 0x100587) AM_READ(cop_collision_status_val_r)
126126//   AM_RANGE(0x100588, 0x100589) AM_READ(cop_collision_status_stat_r)
127//   AM_RANGE(0x100590, 0x100599) AM_READ(cop_itoa_digits_r)
127   AM_RANGE(0x100590, 0x100599) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_itoa_digits_r)
128128//   AM_RANGE(0x1005b0, 0x1005b1) AM_READ(cop_status_r)
129129//   AM_RANGE(0x1005b2, 0x1005b3) AM_READ(cop_dist_r)
130130//   AM_RANGE(0x1005b4, 0x1005b5) AM_READ(cop_angle_r)
trunk/src/mame/drivers/raiden2.c
r32310r32311
173173   save_item(NAME(raiden2_tilemap_enable));
174174   save_item(NAME(prg_bank));
175175   save_item(NAME(cop_bank));
176   save_item(NAME(cop_itoa));
177176   save_item(NAME(cop_status));
178177   save_item(NAME(cop_scale));
179   save_item(NAME(cop_itoa_digit_count));
178
180179   save_item(NAME(cop_angle));
181180   save_item(NAME(cop_dist));
182181
r32310r32311
197196   
198197   save_item(NAME(scrollvals));
199198   save_item(NAME(cop_regs));
200   save_item(NAME(cop_itoa_digits));
201199
200
201
202202   save_item(NAME(sprite_prot_src_addr));
203203
204204   save_item(NAME(cop_collision_info[0].pos));
r32310r32311
257257   }
258258}
259259
260WRITE16_MEMBER(raiden2_state::cop_itoa_low_w)
261{
262   cop_itoa = (cop_itoa & ~UINT32(mem_mask)) | (data & mem_mask);
263260
264   int digits = 1 << cop_itoa_digit_count*2;
265   UINT32 val = cop_itoa;
266
267   if(digits > 9)
268      digits = 9;
269   for(int i=0; i<digits; i++)
270      if(!val && i)
271         cop_itoa_digits[i] = 0x20;
272      else {
273         cop_itoa_digits[i] = 0x30 | (val % 10);
274         val = val / 10;
275      }
276   cop_itoa_digits[9] = 0;
277}
278
279WRITE16_MEMBER(raiden2_state::cop_itoa_high_w)
280{
281   cop_itoa = (cop_itoa & ~(mem_mask << 16)) | ((data & mem_mask) << 16);
282}
283
284WRITE16_MEMBER(raiden2_state::cop_itoa_digit_count_w)
285{
286   COMBINE_DATA(&cop_itoa_digit_count);
287}
288
289READ16_MEMBER(raiden2_state::cop_itoa_digits_r)
290{
291   return cop_itoa_digits[offset*2] | (cop_itoa_digits[offset*2+1] << 8);
292}
293
294261READ16_MEMBER(raiden2_state::cop_status_r)
295262{
296263   return cop_status;
r32310r32311
10841051   fg_bank=6;
10851052   mid_bank=1;
10861053   tx_bank = 0;
1087   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)
10881054}
10891055
10901056MACHINE_RESET_MEMBER(raiden2_state,raiden2)
r32310r32311
13321298static ADDRESS_MAP_START( raiden2_cop_mem, AS_PROGRAM, 16, raiden2_state )
13331299   AM_RANGE(0x0041c, 0x0041d) AM_WRITE(cop_angle_target_w) // angle target (for 0x6200 COP macro)
13341300   AM_RANGE(0x0041e, 0x0041f) AM_WRITE(cop_angle_step_w)   // angle step   (for 0x6200 COP macro)
1335   AM_RANGE(0x00420, 0x00421) AM_WRITE(cop_itoa_low_w)
1336   AM_RANGE(0x00422, 0x00423) AM_WRITE(cop_itoa_high_w)
1337   AM_RANGE(0x00424, 0x00425) AM_WRITE(cop_itoa_digit_count_w)
1301   AM_RANGE(0x00420, 0x00421) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_low_w)
1302   AM_RANGE(0x00422, 0x00423) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_high_w)
1303   AM_RANGE(0x00424, 0x00425) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_itoa_digit_count_w)
13381304   AM_RANGE(0x00428, 0x00429) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v1_w)
13391305   AM_RANGE(0x0042a, 0x0042b) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_dma_v2_w)
13401306   AM_RANGE(0x00432, 0x00433) AM_DEVWRITE("raiden2cop", raiden2cop_device, cop_pgm_data_w)
r32310r32311
13641330   AM_RANGE(0x00580, 0x00581) AM_READ(cop_collision_status_r)
13651331   AM_RANGE(0x00582, 0x00587) AM_READ(cop_collision_status_val_r)
13661332   AM_RANGE(0x00588, 0x00589) AM_READ(cop_collision_status_stat_r)
1367   AM_RANGE(0x00590, 0x00599) AM_READ(cop_itoa_digits_r)
1333   AM_RANGE(0x00590, 0x00599) AM_DEVREAD("raiden2cop", raiden2cop_device, cop_itoa_digits_r)
13681334   AM_RANGE(0x005b0, 0x005b1) AM_READ(cop_status_r)
13691335   AM_RANGE(0x005b2, 0x005b3) AM_READ(cop_dist_r)
13701336   AM_RANGE(0x005b4, 0x005b5) AM_READ(cop_angle_r)
r32310r32311
18331799
18341800   MCFG_RAIDEN2COP_ADD("raiden2cop")
18351801   MCFG_RAIDEN2COP_VIDEORAM_OUT_CB(WRITE16(raiden2_state, m_videoram_private_w))
1802   MCFG_ITOA_UNUSED_DIGIT_VALUE(0x20)
18361803
18371804   MCFG_VIDEO_START_OVERRIDE(raiden2_state,raiden2)
18381805
r32310r32311
18931860
18941861   MCFG_RAIDEN2COP_ADD("raiden2cop")
18951862   MCFG_RAIDEN2COP_VIDEORAM_OUT_CB(WRITE16(raiden2_state, m_videoram_private_w))
1863   MCFG_ITOA_UNUSED_DIGIT_VALUE(0x20)
18961864
18971865   MCFG_VIDEO_START_OVERRIDE(raiden2_state,raiden2)
18981866

Previous 199869 Revisions Next


© 1997-2024 The MAME Team