// mbos.h

// this is the entry vector to the bios, the address of the bios
// is stored at this address
#define BIOS_F_ADDRESS 0xbd000000U

// structure used for all bios calls
// bs is defined as a global so that it can be used in many functions
// without having to pass the structure each time
typedef struct { // bios control block
	short int function;
	unsigned char uc;
	char c;
	char *cp;
	int	i1;
	int i2;
	int error;
	unsigned u1;
	unsigned u2;
	int fn;
} BCB; 
BCB bs;

int errorn; // holde error values
int ccard; // current mounted card
 
unsigned *adr2=(unsigned *)BIOS_F_ADDRESS;

// funcrion prototype to get access to BCB
typedef int (*func) (BCB*);


// ============== Prototypes ===========================================
// For an explanantion of how the functions work, see mbos.c
//-------------------------------------------------------------
// this is a convenient way to use the single point of entry
// using a static ram loaction se bt BCB_RAM. The base address
// is where the entry point is
int bios();
void reset();
void initProc();
void openIO(int port, int baudRate, unsigned int mode);
void b_putc(int port,char c);
int b_puts(int port,char *s);
int b_getc(int port,unsigned char echo);
int b_getcq(int port);
int flowcontrol(int bon);
int b_gets(int port,char *s, int max);
void closeIO(int port);

void hexLoader();
int xm_start();
int xm_load(char *buf);

int get_defp();
int get_eop();

void erasePages(unsigned address, unsigned pages);
void programFlash(unsigned address, int size, char *data);

int tick();
void delayMS(unsigned ms);
int tick();

// ============== FILE SYSTEM =================================
int initSDCARD(int card);
int getCD(int card);
int readSector(int card, int sect, char *buf);
int writeSector(int card, int sect, char *buf);
int fmode(int fn);
int ffd(int card);
int fbuf(int fn);
int ferror();
int mount(int card);
int unmount(int card);
int fileOpen(int card, char *name, char mode);
int fileclose(int fn);
int dir(int card);
int cd(int card, char *dname);
int md(int card, char *dname);
int del(int card, char *dname);
int b_fputc(int fn, char c);
int b_fputs(int fn, char *buf);
int b_fgetc(int fn);
int b_fgets(int fn, char *s, int max);
int fpos(int fn);
int b_fread(int fn, char *buf, int start, int length);
int fileWrite(int fn, char *data, int start, int length);
int fileExists(int card, char *name);
int fileSize(int fn);

//================== date and time ================
int startRTC();
int setTime(int h, int m, unsigned s);
int getTime(int *h, int *m, unsigned *s);
int setDate(int wday, int mday, unsigned mon, unsigned year);
int getDate(int *wday, int *mday, unsigned *mon, unsigned *year);


// ============= not part of bios but useful to have ==============
void b_line_end(int port);


