mgh: fix for default HDD DMA mode, that wasn't correctly set
[open-ps2-loader/simon.git] / modules / mcemu / mcemu_io.c
blob87777edbb69e17bff453784759deb11e75987330
1 /*
2 Copyright 2006-2008, Romz
3 Copyright 2010, Polo
4 Licenced under Academic Free License version 3.0
5 Review OpenUsbLd README & LICENSE files for further details.
6 */
8 #include "mcemu.h"
10 int mc_configure(MemoryCard *mcds)
12 register int i;
14 DPRINTF("vmcSpec[0].active = %d\n", vmcSpec[0].active);
15 DPRINTF("vmcSpec[1].active = %d\n", vmcSpec[1].active);
17 if(vmcSpec[0].active == 0 && vmcSpec[1].active == 0)
18 return 0;
20 for (i = 0; i < MCEMU_PORTS; i ++, mcds ++)
22 DPRINTF("vmcSpec[%d].flags = 0x%X\n", i, vmcSpec[i].flags );
23 DPRINTF("vmcSpec[%d].cspec.PageSize = 0x%X\n", i, vmcSpec[i].cspec.PageSize );
24 DPRINTF("vmcSpec[%d].cspec.BlockSize = 0x%X\n", i, vmcSpec[i].cspec.BlockSize );
25 DPRINTF("vmcSpec[%d].cspec.CardSize = 0x%X\n", i, (unsigned int)vmcSpec[i].cspec.CardSize );
27 if(vmcSpec[i].active == 1)
29 // Set virtual memorycard informations
30 mcds->mcnum = i;
31 mcds->tcode = 0x5A; /* 'Z' */
32 mcds->cbufp = &mceccbuf[i][0];
33 mcds->dbufp = &mcdatabuf[0];
34 mcds->flags = vmcSpec[i].flags;
35 mcds->cspec.PageSize = vmcSpec[i].cspec.PageSize;
36 mcds->cspec.BlockSize = vmcSpec[i].cspec.BlockSize;
37 mcds->cspec.CardSize = vmcSpec[i].cspec.CardSize;
39 else
40 mcds->mcnum = -1;
43 return 1;
46 //---------------------------------------------------------------------------
47 int mc_read(int mc_num, void *buf, u32 page_num)
49 register u32 lba = 0;
51 #ifdef HDD_DRIVER
52 lba = Mcpage_to_Apasector(mc_num, page_num);
53 #endif
55 #ifdef USB_DRIVER
56 lba = vmcSpec[mc_num].stsec + page_num;
57 #endif
59 #ifdef SMB_DRIVER
60 lba = page_num * vmcSpec[mc_num].cspec.PageSize;
61 #endif
63 DPRINTF("reading page 0x%X at lba 0x%X\n", (unsigned int)page_num, (unsigned int)lba);
65 #ifdef HDD_DRIVER
66 ata_device_dma_transfer(0, buf, lba, 1, ATA_DIR_READ);
67 #endif
69 #ifdef USB_DRIVER
70 mass_stor_readSector(lba, 1, buf);
71 #endif
73 #ifdef SMB_DRIVER
74 if(vmcSpec[mc_num].fid == 0xFFFF)
76 if(!smb_OpenAndX(vmcSpec[mc_num].fname, &vmcSpec[mc_num].fid, 1))
77 return 0;
80 smb_ReadFile(vmcSpec[mc_num].fid, lba, 0, buf, vmcSpec[mc_num].cspec.PageSize);
81 #endif
83 return 1;
86 //---------------------------------------------------------------------------
87 int mc_write(int mc_num, void *buf, u32 page_num)
89 register u32 lba = 0;
91 #ifdef HDD_DRIVER
92 lba = Mcpage_to_Apasector(mc_num, page_num);
93 #endif
95 #ifdef USB_DRIVER
96 lba = vmcSpec[mc_num].stsec + page_num;
97 #endif
99 #ifdef SMB_DRIVER
100 lba = page_num * vmcSpec[mc_num].cspec.PageSize;
101 #endif
103 DPRINTF("writing page 0x%X at lba 0x%X\n", (unsigned int)page_num, (unsigned int)lba);
105 #ifdef HDD_DRIVER
106 ata_device_dma_transfer(0, buf, lba, 1, ATA_DIR_WRITE);
107 #endif
109 #ifdef USB_DRIVER
110 mass_stor_writeSector(lba, 1, buf);
111 #endif
113 #ifdef SMB_DRIVER
114 smb_WriteFile(vmcSpec[mc_num].fid, lba, 0, buf, vmcSpec[mc_num].cspec.PageSize);
115 #endif
117 return 1;