source: thomson/code/C/HxCHost/pff/diskio.c@ 53c4be3

main
Last change on this file since 53c4be3 was 645c148, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

Add WIP HxC host software for Thomson computers.
Not working yet because of timing problems...

git-svn-id: svn://localhost/thomson@3 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 3.0 KB
Line 
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/*******/
12extern unsigned char* secbuf;
13extern unsigned char mark[];
14/*******/
15
16/*-----------------------------------------------------------------------*/
17/* Initialize Disk Drive */
18/*-----------------------------------------------------------------------*/
19
20DSTATUS 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
42DRESULT 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
95DRESULT 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
Note: See TracBrowser for help on using the repository browser.