1 | /*-----------------------------------------------------------------------*/
|
---|
2 | /* Low level disk I/O module skeleton for Petit FatFs (C)ChaN, 2009 */
|
---|
3 | /* Driver for MO5/TO8 HxC floppy emulator direct access
|
---|
4 | * Copyright 2011, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
|
---|
5 | -------------------------------------------------------------------------*/
|
---|
6 |
|
---|
7 | #include "diskio.h"
|
---|
8 |
|
---|
9 | #include "../macros.h"
|
---|
10 |
|
---|
11 | /*******/
|
---|
12 | extern unsigned char* secbuf;
|
---|
13 | extern unsigned char mark[];
|
---|
14 | /*******/
|
---|
15 |
|
---|
16 | /*-----------------------------------------------------------------------*/
|
---|
17 | /* Initialize Disk Drive */
|
---|
18 | /*-----------------------------------------------------------------------*/
|
---|
19 |
|
---|
20 | DSTATUS disk_initialize (void)
|
---|
21 | {
|
---|
22 | // Enter host mode
|
---|
23 | seek();
|
---|
24 |
|
---|
25 | // Read header to check everything is ok
|
---|
26 | read(255, 0, secbuf);
|
---|
27 |
|
---|
28 | // Check for HxCFEDA marker
|
---|
29 | if (*(long*)(mark) != *(long*)(secbuf))
|
---|
30 | return STA_NOINIT;
|
---|
31 | if (*(long*)(mark+4) != *(long*)(secbuf+4))
|
---|
32 | return STA_NOINIT;
|
---|
33 | return 0;
|
---|
34 | }
|
---|
35 |
|
---|
36 |
|
---|
37 |
|
---|
38 | /*-----------------------------------------------------------------------*/
|
---|
39 | /* Read Partial Sector */
|
---|
40 | /*-----------------------------------------------------------------------*/
|
---|
41 |
|
---|
42 | DRESULT disk_readp (
|
---|
43 | BYTE* dest, /* Pointer to the destination object */
|
---|
44 | DWORD sector, /* Sector number (LBA) */
|
---|
45 | WORD sofs, /* Offset in the sector */
|
---|
46 | WORD count /* Byte count (bit15:destination) */
|
---|
47 | )
|
---|
48 | {
|
---|
49 | static DWORD prevsec = -1;
|
---|
50 | // TODO implement caching system
|
---|
51 | // * If sector is reachable with current LBA, don't change it
|
---|
52 |
|
---|
53 | printhex(sector>>24);
|
---|
54 | printhex(sector>>16);
|
---|
55 | printhex(sector>>8);
|
---|
56 | printhex(sector);
|
---|
57 | mon_putc(' ');
|
---|
58 |
|
---|
59 | if (prevsec != sector)
|
---|
60 | {
|
---|
61 |
|
---|
62 | // Set LBA address
|
---|
63 | int j = 8;
|
---|
64 | mark[j++] = 1;
|
---|
65 | mark[j++] = sector;
|
---|
66 | mark[j++] = (sector>>8);
|
---|
67 | mark[j++] = (sector>>16);
|
---|
68 | mark[j++] = (sector>>24);
|
---|
69 | mark[j++] = 0; // Write disabled
|
---|
70 | mark[j++] = 6; // Sector count
|
---|
71 | for(; j <512; j++) mark[j] = 0;
|
---|
72 | write(255,0,mark);
|
---|
73 |
|
---|
74 | prevsec = sector;
|
---|
75 | // Read sector
|
---|
76 | read(255,1,secbuf);
|
---|
77 | }
|
---|
78 |
|
---|
79 | // Copy useful bytes to dest.
|
---|
80 | sofs += (int)(secbuf);
|
---|
81 | for(int j = 0; j <count;++j)
|
---|
82 | {
|
---|
83 | *(char*)(dest+j) = *(char*)(j+sofs);
|
---|
84 | }
|
---|
85 |
|
---|
86 | return RES_OK;
|
---|
87 | }
|
---|
88 |
|
---|
89 |
|
---|
90 |
|
---|
91 | /*-----------------------------------------------------------------------*/
|
---|
92 | /* Write Partial Sector */
|
---|
93 | /*-----------------------------------------------------------------------*/
|
---|
94 |
|
---|
95 | DRESULT disk_writep (
|
---|
96 | const BYTE* buff,/* Pointer to the data to be written, NULL:Initiate/Finalize write operation */
|
---|
97 | DWORD sc /* Sector number (LBA) or Number of bytes to send */
|
---|
98 | )
|
---|
99 | {
|
---|
100 | // TODO write it
|
---|
101 | // Beware of using the sector buffer, read is doing caching there...
|
---|
102 | DRESULT res = RES_ERROR;
|
---|
103 |
|
---|
104 |
|
---|
105 | if (!buff) {
|
---|
106 | if (sc) {
|
---|
107 |
|
---|
108 | // Initiate write process
|
---|
109 |
|
---|
110 | } else {
|
---|
111 |
|
---|
112 | // Finalize write process
|
---|
113 |
|
---|
114 | }
|
---|
115 | } else {
|
---|
116 |
|
---|
117 | // Send data to the disk
|
---|
118 |
|
---|
119 | }
|
---|
120 |
|
---|
121 | return res;
|
---|
122 | }
|
---|
123 |
|
---|