Previous 199869 Revisions Next

r18804 Thursday 1st November, 2012 at 15:43:21 UTC by smf
turned znsec into a device [smf]
[src/emu/cpu/psx]sio.h
[src/mame/drivers]taitogn.c zn.c
[src/mame/machine]znsec.c znsec.h

trunk/src/mame/drivers/taitogn.c
r18803r18804
332332class taitogn_state : public psx_state
333333{
334334public:
335   taitogn_state(const machine_config &mconfig, device_type type, const char *tag)
336      : psx_state(mconfig, type, tag) { }
335   taitogn_state(const machine_config &mconfig, device_type type, const char *tag) :
336      psx_state(mconfig, type, tag),
337      m_znsec0(*this,"znsec0"),
338      m_znsec1(*this,"znsec1")
339   {
340   }
337341
342   required_device<znsec_device> m_znsec0;
343   required_device<znsec_device> m_znsec1;
344
338345   intel_te28f160_device *m_biosflash;
339346   intel_e28f400_device *m_pgmflash;
340347   intel_te28f160_device *m_sndflash[3];
r18803r18804
690697   taitogn_state *state = machine.driver_data<taitogn_state>();
691698
692699   if( ( n_data & PSX_SIO_OUT_CLOCK ) == 0 )
693        {
694         if( state->m_b_lastclock )
695            psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 0, ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA );
696         state->m_b_lastclock = 0;
697        }
700   {
701      if( state->m_b_lastclock )
702         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( state->m_znsec0->step( ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA );
703
704      state->m_b_lastclock = 0;
705   }
698706   else
699        {
700         state->m_b_lastclock = 1;
701        }
707   {
708      state->m_b_lastclock = 1;
709   }
702710}
703711
704712static void sio_znsec1_handler( running_machine &machine, int n_data )
r18803r18804
706714   taitogn_state *state = machine.driver_data<taitogn_state>();
707715
708716   if( ( n_data & PSX_SIO_OUT_CLOCK ) == 0 )
709        {
710         if( state->m_b_lastclock )
711            psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 1, ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA );
712         state->m_b_lastclock = 0;
713        }
717   {
718      if( state->m_b_lastclock )
719         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( state->m_znsec1->step( ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA );
720
721      state->m_b_lastclock = 0;
722   }
714723   else
715        {
716         state->m_b_lastclock = 1;
717        }
724   {
725      state->m_b_lastclock = 1;
726   }
718727}
719728
720729static void sio_pad_handler( running_machine &machine, int n_data )
r18803r18804
722731   taitogn_state *state = machine.driver_data<taitogn_state>();
723732
724733   if( ( n_data & PSX_SIO_OUT_DTR ) != 0 )
725        {
726         state->m_b_znsecport = 1;
727        }
734   {
735      state->m_b_znsecport = 1;
736   }
728737   else
729        {
730         state->m_b_znsecport = 0;
731        }
738   {
739      state->m_b_znsecport = 0;
740   }
732741
733742   psx_sio_input( machine, 0, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR, PSX_SIO_IN_DATA | PSX_SIO_IN_DSR );
734743}
r18803r18804
758767{
759768   COMBINE_DATA( &m_n_znsecsel );
760769
770   m_znsec0->select( ( m_n_znsecsel >> 2 ) & 1 );
771   m_znsec1->select( ( m_n_znsecsel >> 3 ) & 1 );
772
761773   if( ( m_n_znsecsel & 0x80 ) == 0 )
762        {
763         psx_sio_install_handler( machine(), 0, sio_pad_handler );
764         psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
765        }
774   {
775      psx_sio_install_handler( machine(), 0, sio_pad_handler );
776      psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
777   }
766778   else if( ( m_n_znsecsel & 0x08 ) == 0 )
767        {
768         znsec_start( 1 );
769         psx_sio_install_handler( machine(), 0, sio_znsec1_handler );
770         psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
771        }
779   {
780      psx_sio_install_handler( machine(), 0, sio_znsec1_handler );
781      psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
782   }
772783   else if( ( m_n_znsecsel & 0x04 ) == 0 )
773        {
774         znsec_start( 0 );
775         psx_sio_install_handler( machine(), 0, sio_znsec0_handler );
776         psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
777        }
784   {
785      psx_sio_install_handler( machine(), 0, sio_znsec0_handler );
786      psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
787   }
778788   else
779        {
780         m_n_dip_bit = 0;
781         m_b_lastclock = 1;
789   {
790      m_n_dip_bit = 0;
791      m_b_lastclock = 1;
782792
783         psx_sio_install_handler( machine(), 0, sio_dip_handler );
784         psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
793      psx_sio_install_handler( machine(), 0, sio_dip_handler );
794      psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
785795
786         m_dip_timer->adjust( downcast<cpu_device *>(&space.device())->cycles_to_attotime( 100 ), 1 );
787        }
796      m_dip_timer->adjust( downcast<cpu_device *>(&space.device())->cycles_to_attotime( 100 ), 1 );
797   }
788798}
789799
790800TIMER_CALLBACK_MEMBER(taitogn_state::dip_timer_fired)
r18803r18804
869879   m_sndflash[2] = machine().device<intel_te28f160_device>("sndflash2");
870880
871881   psx_driver_init(machine());
872   znsec_init(0, tt10);
873   znsec_init(1, tt16);
882   m_znsec0->init(tt10);
883   m_znsec1->init(tt16);
874884   psx_sio_install_handler(machine(), 0, sio_pad_handler);
875885   m_dip_timer = machine().scheduler().timer_alloc( timer_expired_delegate(FUNC(taitogn_state::dip_timer_fired),this), NULL );
876886
r18803r18804
941951   MCFG_CPU_ADD( "maincpu", CXD8661R, XTAL_100MHz )
942952   MCFG_CPU_PROGRAM_MAP(taitogn_map)
943953
954   MCFG_DEVICE_ADD("znsec0", ZNSEC, 0)
955   MCFG_DEVICE_ADD("znsec1", ZNSEC, 0)
956
944957   /* video hardware */
945958   MCFG_PSXGPU_ADD( "maincpu", "gpu", CXD8654Q, 0x200000, XTAL_53_693175MHz )
946959
trunk/src/mame/drivers/zn.c
r18803r18804
3434public:
3535   zn_state(const machine_config &mconfig, device_type type, const char *tag) :
3636      psx_state(mconfig, type, tag),
37      m_gpu(*this, "gpu")
37      m_gpu(*this, "gpu"),
38      m_znsec0(*this,"znsec0"),
39      m_znsec1(*this,"znsec1")
3840   {
3941   }
4042
4143   required_device<psxgpu_device> m_gpu;
44   required_device<znsec_device> m_znsec0;
45   required_device<znsec_device> m_znsec1;
4246   UINT32 m_n_znsecsel;
4347   UINT32 m_b_znsecport;
4448   int m_n_dip_bit;
r18803r18804
323327   {
324328      if( state->m_b_lastclock )
325329      {
326         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 0, ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA );
330         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( state->m_znsec0->step( ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA );
327331      }
332
328333      state->m_b_lastclock = 0;
329334   }
330335   else
r18803r18804
341346   {
342347      if( state->m_b_lastclock )
343348      {
344         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( znsec_step( 1, ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA );
349         psx_sio_input( machine, 0, PSX_SIO_IN_DATA, ( state->m_znsec1->step( ( n_data & PSX_SIO_OUT_DATA ) != 0 ) != 0 ) * PSX_SIO_IN_DATA );
345350      }
351
346352      state->m_b_lastclock = 0;
347353   }
348354   else
r18803r18804
394400{
395401   COMBINE_DATA( &m_n_znsecsel );
396402
403   m_znsec0->select( ( m_n_znsecsel >> 2 ) & 1 );
404   m_znsec1->select( ( m_n_znsecsel >> 3 ) & 1 );
405
397406   if( ( m_n_znsecsel & 0x80 ) == 0 )
398407   {
399408      psx_sio_install_handler( machine(), 0, sio_pad_handler );
r18803r18804
401410   }
402411   else if( ( m_n_znsecsel & 0x08 ) == 0 )
403412   {
404      znsec_start( 1 );
405413      psx_sio_install_handler( machine(), 0, sio_znsec1_handler );
406414      psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
407415   }
408416   else if( ( m_n_znsecsel & 0x04 ) == 0 )
409417   {
410      znsec_start( 0 );
411418      psx_sio_install_handler( machine(), 0, sio_znsec0_handler );
412419      psx_sio_input( machine(), 0, PSX_SIO_IN_DSR, 0 );
413420   }
r18803r18804
527534   {
528535      if( strcmp( machine.system().name, zn_config_table[ n_game ].s_name ) == 0 )
529536      {
530         znsec_init( 0, zn_config_table[ n_game ].p_n_mainsec );
531         znsec_init( 1, zn_config_table[ n_game ].p_n_gamesec );
537         state->m_znsec0->init( zn_config_table[ n_game ].p_n_mainsec );
538         state->m_znsec1->init( zn_config_table[ n_game ].p_n_gamesec );
532539         psx_sio_install_handler( machine, 0, sio_pad_handler );
533540         break;
534541      }
r18803r18804
551558   MCFG_CPU_ADD( "maincpu", CXD8530CQ, XTAL_67_7376MHz )
552559   MCFG_CPU_PROGRAM_MAP( zn_map)
553560
561   MCFG_DEVICE_ADD("znsec0", ZNSEC, 0)
562   MCFG_DEVICE_ADD("znsec1", ZNSEC, 0)
563
554564   /* video hardware */
555565   MCFG_PSXGPU_ADD( "maincpu", "gpu", CXD8561Q, 0x100000, XTAL_53_693175MHz )
556566
r18803r18804
573583   MCFG_CPU_ADD( "maincpu", CXD8661R, XTAL_100MHz )
574584   MCFG_CPU_PROGRAM_MAP( zn_map)
575585
586   MCFG_DEVICE_ADD("znsec0", ZNSEC, 0)
587   MCFG_DEVICE_ADD("znsec1", ZNSEC, 0)
588
576589   /* video hardware */
577590   MCFG_PSXGPU_ADD( "maincpu", "gpu", CXD8654Q, 0x200000, XTAL_53_693175MHz )
578591
trunk/src/mame/machine/znsec.c
r18803r18804
8282                      = Shift(c[n-1, 6])^Shift(c[n-1, 7])
8383*/
8484
85#include "emu.h"
8685#include "znsec.h"
8786
88struct znsec_state {
89   const UINT8 *transform;
90   UINT8 state;
91   UINT8 bit;
92};
87const device_type ZNSEC = &device_creator<znsec_device>;
9388
94static znsec_state zns[2];
89znsec_device::znsec_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
90   device_t(mconfig, ZNSEC, "ZNSEC", tag, owner, clock)
91{
92}
9593
94void znsec_device::device_start()
95{
96   save_item(NAME(m_select));
97   save_item(NAME(m_state));
98   save_item(NAME(m_bit));
99}
96100
97101// Given the value for x7..x0 and linear transform coefficients a7..a0
98102// compute the value of the transform
r18803r18804
111115#endif
112116
113117// Derive the sbox xor mask for a given input and select bit
114static UINT8 compute_sbox_coef(int chip, int sel, int bit)
118UINT8 znsec_device::compute_sbox_coef(int sel, int bit)
115119{
116   UINT8 r;
117120   if(!sel)
118      return zns[chip].transform[bit];
119   r = compute_sbox_coef(chip, (sel-1) & 7, (bit-1) & 7);
121      return m_transform[bit];
122
123   UINT8 r = compute_sbox_coef((sel-1) & 7, (bit-1) & 7);
120124   r = (r << 1)|(((r >> 7)^(r >> 6)) & 1);
121125   if(bit != 7)
122126      return r;
123127
124   return r ^ compute_sbox_coef(chip, sel, 0);
128   return r ^ compute_sbox_coef(sel, 0);
125129}
126130
127131// Apply the sbox for a input 0 bit
128static UINT8 apply_bit_sbox(int chip, UINT8 state, int sel)
132void znsec_device::apply_bit_sbox(int sel)
129133{
130134   int i;
131135   UINT8 r = 0;
132136   for(i=0; i<8; i++)
133      if(state & (1<<i))
134         r ^= compute_sbox_coef(chip, sel, i);
135   return r;
137      if(m_state & (1<<i))
138         r ^= compute_sbox_coef(sel, i);
139
140   m_state = r;
136141}
137142
138143// Apply a sbox
139static UINT8 apply_sbox(UINT8 state, const UINT8 *sbox)
144void znsec_device::apply_sbox(const UINT8 *sbox)
140145{
141146   int i;
142147   UINT8 r = 0;
143148   for(i=0; i<8; i++)
144      if(state & (1<<i))
149      if(m_state & (1<<i))
145150         r ^= sbox[i];
146   return r;
151
152   m_state = r;
147153}
148154
149void znsec_init(int chip, const UINT8 *transform)
155void znsec_device::init(const UINT8 *transform)
150156{
151   zns[chip].transform = transform;
152   zns[chip].state = 0xfc;
153   zns[chip].bit = 0;
157   m_transform = transform;
154158}
155159
156void znsec_start(int chip)
160void znsec_device::select(int select)
157161{
158   zns[chip].state = 0xfc;
159   zns[chip].bit = 0;
162   if (m_select && !select)
163   {
164      m_state = 0xfc;
165      m_bit = 0;
166   }
167   
168   m_select = select;
160169}
161170
162UINT8 znsec_step(int chip, UINT8 input)
171UINT8 znsec_device::step(UINT8 input)
163172{
164173   UINT8 res;
165174   static const UINT8 initial_sbox[8] = { 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x7f };
166175
167   if (zns[chip].bit==0)
176   if (m_bit==0)
168177   {
169      // Apply the initial xbox
170      zns[chip].state = apply_sbox(zns[chip].state, initial_sbox);
178      // Apply the initial sbox
179      apply_sbox(initial_sbox);
171180   }
172181
173182   // Compute the output and change the state
174   res = (zns[chip].state>>zns[chip].bit) & 1;
183   res = (m_state >> m_bit) & 1;
175184   if((input & 1)==0)
176      zns[chip].state = apply_bit_sbox(chip, zns[chip].state, zns[chip].bit);
185      apply_bit_sbox(m_bit);
177186
178   zns[chip].bit++;
179   zns[chip].bit&=7;
187   m_bit++;
188   m_bit&=7;
180189   return res;
181190}
trunk/src/mame/machine/znsec.h
r18803r18804
11/*  CAT702 ZN security chip */
22
3void znsec_init(int chip, const UINT8 *transform);
4void znsec_start(int chip);
5UINT8 znsec_step(int chip, UINT8 input);
3#pragma once
4
5#ifndef __ZNSEC_H__
6#define __ZNSEC_H__
7
8#include "emu.h"
9
10extern const device_type ZNSEC;
11
12class znsec_device : public device_t
13{
14public:
15   znsec_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
16
17   void init(const UINT8 *transform);
18   void select(int select);
19   UINT8 step(UINT8 input);
20
21protected:
22   void device_start();
23
24private:
25   UINT8 compute_sbox_coef(int sel, int bit);
26   void apply_bit_sbox(int sel);
27   void apply_sbox(const UINT8 *sbox);
28
29   const UINT8 *m_transform;
30   int m_select;
31   UINT8 m_state;
32   UINT8 m_bit;
33};
34
35#endif
trunk/src/emu/cpu/psx/sio.h
r18803r18804
100100   devcb2_write_line m_irq1_handler;
101101};
102102
103DECLARE_WRITE32_HANDLER( psx_sio_w );
104DECLARE_READ32_HANDLER( psx_sio_r );
105
106103#endif

Previous 199869 Revisions Next


© 1997-2024 The MAME Team