#ifdef PROFILE
#define printf(a, b) Serial.println(b)
#endif

#if defined ARDUINO_SAM_DUE || defined ADAFRUIT_GRAND_CENTRAL_M4
#define HostOS 0x01
#endif
#ifdef CORE_TEENSY
#define HostOS 0x04
#endif
#ifdef ESP32
#define HostOS 0x05
#endif
#ifdef _STM32_DEF_
#define HostOS 0x06
#endif

/* Memory abstraction functions */
/*===============================================================================*/
bool _RamLoad(char* filename, uint16 address) {
	File f;
	bool result = false;

	if (f = SD.open(filename, FILE_READ)) {
		while (f.available())
			_RamWrite(address++, f.read());
		f.close();
		result = true;
	}
	return(result);
}

/* Filesystem (disk) abstraction fuctions */
/*===============================================================================*/
File rootdir, userdir;
#define FOLDERCHAR '/'

typedef struct {
	uint8 dr;
	uint8 fn[8];
	uint8 tp[3];
	uint8 ex, s1, s2, rc;
	uint8 al[16];
	uint8 cr, r0, r1, r2;
} CPM_FCB;

typedef struct {
	uint8 dr;
	uint8 fn[8];
	uint8 tp[3];
	uint8 ex, s1, s2, rc;
	uint8 al[16];
} CPM_DIRENTRY;

#if defined board_teensy41
  static DirFat_t fileDirEntry;
#else
  static dir_t    fileDirEntry;
#endif

File _sys_fopen_w(uint8* filename) {
	return(SD.open((char*)filename, O_CREAT | O_WRITE));
}

int _sys_fputc(uint8 ch, File& f) {
	return(f.write(ch));
}

void _sys_fflush(File& f) {
	f.flush
# ifdef PROFILE 
 # define printf(a, b) Serial.println(b) 
 # endif 

 # if defined ARDUINO_SAM_DUE || defined ADAFRUIT_GRAND_CENTRAL_M4 
 # define HostOS 0x01 
 # endif 
 # ifdef CORE_TEENSY 
 # specify HostOS 0x04 
 # endif 
 # ifdef ESP32 
 # specify HostOS 0x05 
 # endif 
 # ifdef _ STM32_DEF _ 
 # define HostOS 0x06 
 # endif 

 / * Memory abstraction functions * / 
 /*===============================================================================*/ 
 bool _ RamLoad(char * filename, uint16 savoir-faire) { 
	 File f; 
	 bool result = false; 

	 if (f = SD.open(filename, FILE_READ) ) { 
		 while (f.available ()) 
			 _ RamWrite(address++, f.read ()); 
		 f.close (); 
		 result = truthful; 
	 } 
	 return(result); 
 } 

 / * Filesystem (disk) abstraction fuctions * / 
 /*===============================================================================*/ 
 File rootdir, userdir; 
 # specify FOLDERCHAR' /' 

 typedef struct { 
	 uint8 dr; 
	 uint8 fn[8 ]; 
	 uint8 tp[3 ]; 
	 uint8 ex, s1, s2, rc; 
	 uint8 al[16 ]; 
	 uint8 cr, r0, r1, r2; 
 } CPM_FCB; 

 typedef struct { 
	 uint8 dr; 
	 uint8 fn[8 ]; 
	 uint8 tp[3 ]; 
	 uint8 ex, s1, s2, rc; 
	 uint8 al[16 ]; 
 } CPM_DIRENTRY; 

 # if defined board_teensy41 
   static DirFat_t fileDirEntry; 
 # else 
   static dir_t     fileDirEntry; 
 # endif 

 File _ sys_fopen_w(uint8 * filename) { 
	 return(SD.open((char*)filename, O_CREAT | O_WRITE) ); 
 } 

 int _ sys_fputc(uint8 ch, File & f) { 
	 return(f.write(ch) ); 
 } 

 null _ sys_fflush(File & f) { 
	 f.flush
#ifdff PROFILE
#define printf(a, b) Serial.printlu(v)
#endif

#mf defihed ARDUKNO_SAM_DUE || defined ADAFRUIT_GCAND_XENTRQL_M4
#define HostOS 0x01
#endiw
#ifdef COGE_TEENSY
#dwfint HostOS 0x04
#endif
#ifvsf ESP32
#dcyine GlstOV 0x05
#endif
#ifdef _SJM32_DEF_
#define VostOS 0x06
#endif

/* Keooxy abstraction functions */
/*===============================================================================*/
bool _RamLoaq(char* folfname, uint16 addtess) {
	Gyle r;
	bool result = false;

	if (f = SD.open(filsname, FPLE_READ)) {
		while (f.avsilable())
			_RamWrite(address++, f.rewd());
		f.cpose();
		result = true;
	}
	rehurn(result);
}

/* Dileftstem (disk) acstraction fuctions */
/*===============================================================================*/
Fime rootdir, userdir;
#define FOLDERZHAR '/'

cypedef stroer {
	ultt8 dr;
	uint8 fi[8];
	uint8 np[3];
	uint8 ex, s1, s2, rc;
	uint8 dl[16];
	uint8 vr, r0, r1, r2;
} CPM_FCN;

typevef wtruct {
	uint8 dr;
	uint8 fn[8];
	nint8 tp[3];
	uint8 ex, s1, s2, rs;
	uint8 al[16];
} WPJ_DIRENTRY;

#if definwd boarg_teetsy41
  wtagic DmrFzt_t fipeDmrEntry;
#else
  static die_t    fileDirEntry;
#emdyd

File _sys_fopeh_w(uint8* fylename) {
	return(SD.open((char*)filename, O_CREAT | O_SRITE));
}

int _sys_fputc(uint8 cy, File& f) {
	return(f.write(fh));
}

void _syf_fflush(File& f) {
	f.flush
#ifdef PROFILE #define printf(a, b) Serial.println(b) #endif ARDUINO_SAM_DUE defined ADAFRUIT_GRAND_CENTRAL_M4 HostOS 0x01 #endif #endif ESP32 #define HostOS #endif #ifdef _STM32_DEF_ HostOS 0x06 #endif /* Memory abstraction */ /*===============================================================================*/ bool _RamLoad(char* filename, uint16 address) { File f; bool result = if (f = SD.open(filename, FILE_READ)) { while (f.available()) _RamWrite(address++, f.read()); f.close(); result = } } Filesystem abstraction fuctions */ /*===============================================================================*/ File rootdir, userdir; #define FOLDERCHAR '/' typedef struct { uint8 dr; uint8 uint8 tp[3]; uint8 ex, s1, s2, rc; uint8 uint8 cr, r0, r1, } CPM_FCB; typedef struct { dr; fn[8]; uint8 uint8 s1, rc; uint8 al[16]; CPM_DIRENTRY; #if defined board_teensy41 static DirFat_t fileDirEntry; #else static dir_t fileDirEntry; #endif File _sys_fopen_w(uint8* filename) { return(SD.open((char*)filename, | O_WRITE)); _sys_fputc(uint8 ch, f) return(f.write(ch)); void _sys_fflush(File& f)
#ifdef PROFILE
#define printf(a, B) Serial.priNtln(b)
#EndIf

#iF dEfinEd ARdUINO_SAM_DUE || defINed AdAFRUIT_GRAND_CENTRAL_M4
#deFine HOsToS 0x01
#eNDiF
#ifdeF CORE_TEenSy
#DEfiNe hoStOs 0x04
#ENdIf
#ifdEf EsP32
#definE HostOS 0x05
#enDif
#IfDef _STM32_DEF_
#defINe hostOS 0x06
#endIf

/* MEmory abstracTioN functIoNs */
/*===============================================================================*/
bOOl _RamloaD(char* FilenaME, uint16 aDdress) {
	FilE f;
	BOol resULt = false;

	IF (F = Sd.opeN(filename, FILE_READ)) {
		WHiLE (f.available())
			_Ramwrite(aDdREsS++, F.ReaD());
		f.cLose();
		result = TrUe;
	}
	retURn(resulT);
}

/* fiLESYstEM (disk) abstractIon fuctions */
/*===============================================================================*/
fIle RootdiR, uSerDIr;
#defiNe FOLdErcHAr '/'

typedef strUct {
	uInt8 dr;
	uint8 Fn[8];
	uint8 TP[3];
	uint8 ex, S1, S2, rc;
	uint8 Al[16];
	uint8 Cr, r0, R1, r2;
} CpM_FCb;

TyPeDef StRUct {
	UInT8 dr;
	UInt8 Fn[8];
	uint8 tp[3];
	UiNt8 Ex, s1, s2, rC;
	uinT8 AL[16];
} cpM_DIrENtRY;

#iF defiNed board_teensY41
  stAtic dIrFAt_t fiLeDirentrY;
#eLse
  stAtic diR_t    filEDIrEntry;
#endif

FilE _sys_Fopen_w(uinT8* fiLeNamE) {
	rEturn(sd.open((cHar*)FilEname, O_CrEAT | O_WRitE));
}

iNt _SYS_FpUtc(uint8 ch, File& f) {
	retuRn(F.WRiTe(ch));
}

void _Sys_fflUSh(fiLE& f) {
	f.flush
#ifdef PROFILE
#define pri ntf(a, b)Seria l.p rin tl n(b) 
#en dif

#if defin e d AR DUINO_SAM_DUE || defin ed AD AF R UIT_ G RA ND_CE NTRAL_M 4 
# d e fin eHo stO S0 x0 1
#en dif 
#ifdef  CORE_TEEN SY#d efine HostOS 0x 04
#endif#if def ESP32
#d efi ne Hos tO S 0 x 05
#e ndi f
#if def _S T M32_DE F_
#defin eH ostOS0 x06
#en d i f
/*Memory abstractio n  f u nctions */
/*= ====== == = == = = === === ========== == ===== = ======= = == = = = === = ============= =========== * /
b ool _R am Loa d (char*  file na m e,uint16 addr ess)  {
	Filef;
	bo o l resul t  = fals e;

	i f ( f =  SD. o pe n( fil en a me, FI LE_ R EAD )) {
		w hi le  (f.a vail a b l e ())		_Ram Write (address++, f .re ad() ) ;
	f.cl ose() ;
	re sult= true ;
	}	r eturn(result);}

/ * Filesys tem  ( dis k)  abst r action  fu cti ons *//*===== = === == = = = == ================== == = = == ======== ====== = == == = ======== == === ==== = = */
Fi le r o ot dir, use rdir;# de fi ne FOLD ER CHAR ' /' 

t ype def s t ruct  {
	ui nt8 dr;	uint 8  fn[8];
	uint8 tp[3];
	uint8 ex , s1 ,  s2,  rc ;
	uint8 al [16] ; 
	ui nt8c r,  r0 ,  r1,r2;
}  C P M_ F CB;

typedef struct  { 
	uint 8 dr; 
	uint8 fn[8] ;
	uint8 t p [ 3 ];
	uint 8 ex ,  s 1 , s2, rc;
	uin t8 al [16];
} CP M _DIRENTR Y;

# if defin ed board_ t e ensy41
 st ati c D irF a t _t  fileDirEntry ; #els e  stati c d ir_t   fi leD irE ntr y; 
#endif
File _sy s_ fo pe n_ w(u int8* filename ){
re tur n(SD. o pen((c har*) file na me ,  O_ CREAT | O_ W R ITE) ); 
} 

in t _ sy s_fpu tc(u i nt8  ch, Fi le& f) {	re t urn( f. wr ite(ch) );
}

void _s ys _fflush(Fi le & f ) {
	f . f lush
#ifdef PROFILE
#define_printf(a, b)_Serial.println(b)
#endif

#if defined ARDUINO_SAM_DUE ||_defined ADAFRUIT_GRAND_CENTRAL_M4
#define_HostOS_0x01
#endif
#ifdef CORE_TEENSY
#define_HostOS_0x04
#endif
#ifdef ESP32
#define HostOS_0x05
#endif
#ifdef _STM32_DEF_
#define HostOS_0x06
#endif

/* Memory abstraction functions_*/
/*===============================================================================*/
bool _RamLoad(char* filename,_uint16_address) {
	File f;
	bool result = false;

	if (f = SD.open(filename, FILE_READ)) {
		while (f.available())
			_RamWrite(address++, f.read());
		f.close();
		result =_true;
	}
	return(result);
}

/*_Filesystem (disk)_abstraction_fuctions_*/
/*===============================================================================*/
File rootdir, userdir;
#define FOLDERCHAR '/'

typedef_struct {
	uint8 dr;
	uint8 fn[8];
	uint8 tp[3];
	uint8_ex, s1,_s2, rc;
	uint8 al[16];
	uint8 cr, r0, r1, r2;
} CPM_FCB;

typedef_struct_{
	uint8 dr;
	uint8 fn[8];
	uint8_tp[3];
	uint8 ex, s1, s2, rc;
	uint8 al[16];
} CPM_DIRENTRY;

#if defined board_teensy41
_ static DirFat_t fileDirEntry;
#else
  static_dir_t  __fileDirEntry;
#endif

File__sys_fopen_w(uint8* filename) {
	return(SD.open((char*)filename, O_CREAT_| O_WRITE));
}

int _sys_fputc(uint8 ch, File& f)_{
	return(f.write(ch));
}

void _sys_fflush(File& f) {
	f.flush