Previous 199869 Revisions Next

r20322 Friday 18th January, 2013 at 18:48:32 UTC by Carl
[mess] make playstation memory cards load and save to a file [Carl]
[src/mess/machine]psxcard.c psxcard.h

trunk/src/mess/machine/psxcard.c
r20321r20322
1919//
2020//
2121
22static const int block_size = 128;
23static const int card_size = block_size * 1024;
24
2225const device_type PSXCARD = &device_creator<psxcard_device>;
2326
2427enum transfer_states
r20321r20322
3740};
3841
3942psxcard_device::psxcard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
40   : device_t(mconfig, PSXCARD, "Sony PSX Memory Card", tag, owner, clock)
43   : device_t(mconfig, PSXCARD, "Sony PSX Memory Card", tag, owner, clock),
44   device_image_interface(mconfig, *this)
4145{
4246}
4347
4448void psxcard_device::device_start()
4549{
46   cache=new unsigned char [128*1024];
47
48   memset(cache, 0, 128*1024);
49
5050   m_owner = dynamic_cast<psx_controller_port_device *>(owner());
5151   m_ack_timer = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(psxcard_device::ack_timer), this));
5252
r20321r20322
7777   m_owner->ack();
7878}
7979
80void psxcard_device::device_config_complete()
81{
82   update_names(PSXCARD, "memcard", "mc");
83}
84
8085//
8186//
8287//
r20321r20322
8893   switch (state)
8994   {
9095      case state_illegal:
91         if (to == 0x81)
96         if ((to == 0x81) && is_loaded())
9297         {
9398//              printf("CARD: begin\n");
9499            state = state_command;
r20321r20322
233238      printf("card: read block %d\n",addr);
234239   #endif
235240
236   if (addr<1024)
241   if (addr<(card_size/block_size))
237242   {
238      memcpy(buf,cache+(addr*128),128);
243      fseek(addr*block_size, SEEK_SET);
244      fread(buf, block_size);
239245   } else
240246   {
241      memset(buf,0,128);
247      memset(buf,0,block_size);
242248   }
243249}
244250
r20321r20322
252258      printf("card: write block %d\n",addr);
253259   #endif
254260
255   if (addr<1024)
261   if (addr<(card_size/block_size))
256262   {
257      memcpy(cache+(addr*128),buf,128);
263      fseek(addr*block_size, SEEK_SET);
264      fwrite(buf, block_size);
258265   }
259266}
260267
261//
262//
263//
264
265268unsigned char psxcard_device::checksum_data(const unsigned char *buf, const unsigned int sz)
266269{
267270   unsigned char chk=*buf++;
r20321r20322
270273   return chk;
271274}
272275
276bool psxcard_device::call_load()
277{
278   if(length() != card_size)
279      return IMAGE_INIT_FAIL;
280   return IMAGE_INIT_PASS;
281}
282
283bool psxcard_device::call_create(int format_type, option_resolution *format_options)
284{
285   UINT8 block[block_size];
286   int i, ret;
287
288   memset(block, '\0', block_size);
289   for(i = 0; i < (card_size/block_size); i++)
290   {
291      ret = fwrite(block, block_size);
292      if(ret != block_size)
293         return IMAGE_INIT_FAIL;
294   }
295   return IMAGE_INIT_PASS;
296}
297
273298void psxcard_device::do_card()
274299{
275300   if(!m_bit)
trunk/src/mess/machine/psxcard.h
r20321r20322
1010#define MCFG_PSXCARD_ADD(_tag) \
1111   MCFG_DEVICE_ADD(_tag, PSXCARD, 0)
1212
13class psxcard_device : public device_t
13class psxcard_device :   public device_t,
14                  public device_image_interface
1415{
1516public:
1617   psxcard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
1718
19   virtual iodevice_t image_type() const { return IO_MEMCARD; }
20
21   virtual bool is_readable()  const { return 1; }
22   virtual bool is_writeable() const { return 1; }
23   virtual bool is_creatable() const { return 1; }
24   virtual bool must_be_loaded() const { return 0; }
25   virtual bool is_reset_on_load() const { return 0; }
26   virtual const char *file_extensions() const { return "mc"; }
27   virtual const option_guide *create_option_guide() const { return NULL; }
28
29   virtual bool call_load();
30   virtual bool call_create(int format_type, option_resolution *format_options);
31
1832private:
19   unsigned char pkt[0x8b], pkt_ptr, pkt_sz, cmd, *cache;
33   unsigned char pkt[0x8b], pkt_ptr, pkt_sz, cmd;
2034   unsigned short addr;
2135   int state;
2236
r20321r20322
4458public:
4559   virtual void device_start();
4660   virtual void device_reset();
61   virtual void device_config_complete();
4762
4863   void clock_w(bool state) { if(m_clock && !m_sel && !state && !m_pad) do_card(); m_clock = state; }
4964   void sel_w(bool state);

Previous 199869 Revisions Next


© 1997-2024 The MAME Team