source: thomson/code/C/HxCHost/pff/diskio.c@ 1b74fa2

main
Last change on this file since 1b74fa2 was 1b74fa2, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago

work in progress write support.

  • With latest beta firmware there is no spinup problem anymore in direct access mode,
  • Read the CFG file and display settings menu
  • Save settings (not perfectly working yet)
  • Some tweaks all around.
  • Move code downwards in memory, because we run out of space !

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

  • Property mode set to 100644
File size: 3.6 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
15static DWORD prevsec = -1;
16/*******/
17
18/*-----------------------------------------------------------------------*/
19/* Initialize Disk Drive */
20/*-----------------------------------------------------------------------*/
21
22DSTATUS disk_initialize (void)
23{
24 // Enter host mode
25 seek();
26
27 // Read header to check everything is ok
28 read(255, 0, secbuf);
29
30 // Check for HxCFEDA marker
31 if (*(long*)(mark) != *(long*)(secbuf))
32 return STA_NOINIT;
33 if (*(long*)(mark+4) != *(long*)(secbuf+4))
34 return STA_NOINIT;
35 return 0;
36}
37
38
39void map_sector(DWORD sector, BYTE write)
40{
41 // Set LBA address
42 int j = 8;
43 mark[j++] = 1;
44 mark[j++] = sector;
45 mark[j++] = (sector>>8);
46 mark[j++] = (sector>>16);
47 mark[j++] = (sector>>24);
48 mark[j++] = write;
49 mark[j++] = 1; // Sector count
50 // BEWARE of changing this to something else than 1 !
51 // In write burst mode it could erase all the sectors you don't rewrite
52
53 // TODO extract a send_hxc_command function from this
54 for(; j <512; j++) mark[j] = 0;
55 write(255,0,mark);
56}
57
58
59/*-----------------------------------------------------------------------*/
60/* Read Partial Sector */
61/*-----------------------------------------------------------------------*/
62
63DRESULT disk_readp (
64 BYTE* dest, /* Pointer to the destination object */
65 DWORD sector, /* Sector number (LBA) */
66 WORD sofs, /* Offset in the sector */
67 WORD count /* Byte count (bit15:destination) */
68)
69{
70 // TODO implement caching system
71 // * If sector is reachable with current LBA, don't change it
72
73 if (prevsec != sector)
74 {
75 map_sector(sector, 0);
76 prevsec = sector;
77 // Read sector
78 read(255,1,secbuf);
79 }
80
81 // Copy useful bytes to dest.
82 sofs += (int)(secbuf);
83 for(int j = 0; j <count;++j)
84 {
85 *(char*)(dest+j) = *(char*)(j+sofs);
86 }
87
88 return RES_OK;
89}
90
91
92
93/*-----------------------------------------------------------------------*/
94/* Write Partial Sector */
95/*-----------------------------------------------------------------------*/
96
97DRESULT disk_writep (
98 const BYTE* buff,/* Pointer to the data to be written, NULL:Initiate/Finalize write operation */
99 DWORD sc /* Sector number (LBA) or Number of bytes to send */
100)
101{
102 static WORD ptr;
103 static char* wrbuf[256];
104 // Separate buffer because we need to use map_sector, and it kills secbuf
105
106 if (!buff) {
107 if (sc) {
108 mon_putc('A');
109 // Initiate write process
110 prevsec = sc;
111 ptr = 0;
112 } else {
113 mon_putc('C');
114 mon_putc(' ');
115 printhex(ptr);
116 // Called with both param = 0 - flush buffer to disk
117 // First make sure it's zero-filled
118 for(;ptr < 512; ++ptr)
119 {
120 *(wrbuf + ptr) = 0;
121 }
122
123 // map in the sector (no need to read from SD)
124 map_sector(prevsec, 0xA5);
125
126 for(int j = 0; j < 40; j++)
127 printhex(*(char*)(wrbuf + j));
128
129 write(255,1,wrbuf);
130 }
131 } else {
132 mon_putc('B');
133 // Here SC is a bytecount. copy that much bytes to the buffer
134 for(int j = 0; j <sc;++j)
135 {
136 *(char*)(wrbuf+ptr) = *(char*)(ptr++ + buff);
137 }
138 }
139
140 return RES_OK;
141}
142
Note: See TracBrowser for help on using the repository browser.