Previous 15994 Revisions Next

r13373 Friday 25th November, 2011 at 14:57:08 UTC by Nathan Woods
Fixing CoCo VHD reading
[src/mess/machine]coco_vhd.c

src/mess/machine/coco_vhd.c
r13372r13373
4646    CONSTANTS
4747***************************************************************************/
4848
49#define VERBOSE
49#define VERBOSE 1
5050
5151#define VHDSTATUS_OK               0x00
5252#define VHDSTATUS_NO_VHD_ATTACHED      0x02
r13372r13373
131131
132132void coco_vhd_image_device::coco_vhd_readwrite(UINT8 data)
133133{
134   int result;
135   void *ptr;
134   int result, i;
136135   UINT32 bytes_to_read;
137136   UINT32 bytes_to_write;
138137   UINT64 seek_position;
r13372r13373
178177   switch(data)
179178   {
180179      case VHDCMD_READ: /* Read sector */
181         ptr = m_cpu_space->get_write_ptr(m_buffer_address);
182         memset(ptr, 0, 256);
180         memset(buffer, 0, 256);
183181         if (total_size > seek_position)
184182         {
185183            bytes_to_read = (UINT32) MIN((UINT64) 256, total_size - seek_position);
186            result = fread(ptr, bytes_to_read);
184            result = fread(buffer, bytes_to_read);
187185            if (result != bytes_to_read)
188186            {
189187               m_status = VHDSTATUS_ACCESS_DENIED;
r13372r13373
191189            }
192190         }
193191
192         /* write the bytes to memory */
193         for (i = 0; i < 256; i++)
194            m_cpu_space->write_byte(m_buffer_address + i, buffer[i]);
195
194196         m_status = VHDSTATUS_OK;
195197         break;
196198
197199      case VHDCMD_WRITE: /* Write Sector */
198         ptr = m_cpu_space->get_read_ptr(m_buffer_address);
199         result = fwrite(ptr, 256);
200         /* read the bytes from memory */
201         for (i = 0; i < 256; i++)
202            buffer[i] = m_cpu_space->read_byte(m_buffer_address + i);
200203
204         /* and write to disk */
205         result = fwrite(buffer, 256);
201206         if (result != 256)
202207         {
203208            m_status = VHDSTATUS_ACCESS_DENIED;

Previous 15994 Revisions Next


© 1998-2018 The MESS Team