00001
00019
#include "storage.h"
00020
#include "board.h"
00021
#include "console.h"
00022
#include "mmc.h"
00023
#include "buffer.h"
00024
00025
00026
00027
00028
00034 xdata
unsigned char storageFlags = 0;
00035
00036
00037
00043 Public unsigned char InitStorage(){
00044
00045
unsigned char result;
00046
00047 ConsoleWrite (
"Init: Storage v2: supports: MMC,SD,miniSD in SPI mode\r");
00048
00049 result=
InitMMC();
00050
if (result==0x0e){
00051 ConsoleWrite(
"Storage initialized in seek-and-read mode.\r");
00052
storageFlags = 1;
00053
return 0;
00054 }
00055
00056
if (result){
00057 ConsoleWrite(
"InitStorage: Can't start MMC. ");
00058 ConsolePutHex8(result);
00059 ConsolePutChar(13);
00060
storageFlags = 4;
00061
return 1;
00062 }
00063
00064 ConsoleWrite(
"InitStorage ok.\r");
00065
storageFlags = 0;
00066
return 0;
00067
00068 }
00069
00070
00071 Public unsigned char PrepareToReadDiskSector(
unsigned long sectorN){
00072
00073
#ifdef MMCDEBUG
00074
ConsoleWrite(
"<strategy:");
00075 ConsolePutUInt(sectorN);
00076 ConsoleWrite(
" Flags:");
00077 ConsolePutHex8(
storageFlags);
00078
#endif
00079
00080
if (!
storageFlags){
00081
00082
if (
SeekSector(sectorN)){
00083
00084
#ifdef MMCDEBUG
00085
ConsoleWrite(
"Seek Error. strategy>");
00086
#endif
00087
00088
return 0x0f;
00089 }
00090
storageFlags |= 0x02;
00091
00092
#ifdef MMCDEBUG
00093
ConsoleWrite(
"Seeked. strategy>");
00094
#endif
00095
00096
return 0;
00097 }
00098
00099
#ifdef MMCDEBUG
00100
ConsoleWrite(
"strategy>");
00101
#endif
00102
00103
return 0;
00104 }
00105
00106
00110 Public unsigned char ReadDiskSector(
unsigned long sectorN){
00111
00112
00113
#ifdef MMCDEBUG
00114
ConsoleWrite(
"<read");
00115
#endif
00116
00117
00118
if (!(
storageFlags&0x02)){
00119
#ifdef MMCDEBUG
00120
ConsoleWrite(
"F");
00121
#endif
00122
if (
SeekSector(sectorN))
return 0x0f;
00123 }
00124
00125
storageFlags &= 0xfd;
00126
if (
ReadPhysicalSector()){
00127 ConsoleWrite(
"error read>");
00128
return 0x10;
00129 }
00130
00131
#ifdef MMCDEBUG
00132
ConsoleWrite(
"read>");
00133
#endif
00134
00135
return 0;
00136 }
00137
00138
00139
00141 Public void DumpDiskSector(){
00142
unsigned int ha,la;
00143
00144 ConsoleWrite(
"\rDiskBlock ");
00145 ConsolePutUInt(
sectorAddress.
l);
00146 ConsoleWrite(
":\r");
00147
for (ha=0; ha<32; ha++){
00148 ConsolePutHex16 ((ha<<4));
00149 ConsoleWrite(
": ");
00150
for (la=0; la<16; la++){
00151 ConsolePutHex8(
diskSect.
raw.
buf[(ha<<4)+la]);
00152 ConsolePutChar(
' ');
00153
if (la==7){
00154 ConsolePutChar(
' ');
00155 }
00156 }
00157 ConsolePutChar(
' ');
00158
for (la=0; la<16; la++){
00159
if ((
diskSect.
raw.
buf[(ha<<4)+la]) > 30){
00160 ConsolePutChar(
diskSect.
raw.
buf[(ha<<4)+la]);
00161 }
else{
00162 ConsolePutChar(
'.');
00163 }
00164 }
00165 ConsolePutChar(
'\r');
00166 }
00167 }
00168
00169
00170
00171
00172
00173
00174
00175
00176
00183 Public void WriteDiskSector(
unsigned long sectorN){
00184
sectorAddress.
l = sectorN;
00185
dataBufPtr =
diskSect.
raw.
buf;
00186
WritePhysicalSector();
00187 }