#ifndef __MY_DOS_H
#define __MY_DOS_H

/* OPERATING SYSTEM CONSTANTS */
#define MAX_STIRNG       100

#define MAX_FILE        30
#define MAX_USER        10
#define MAX_PROC        10

#define SEEK_SET        1
#define SEEK_CUR        2
#define SEEK_END        4

#define ACCESS_READ     1
#define ACCESS_WRITE    2
#define ACCESS_EXE      4

#define RUN_STATE       1
#define SLEEP_STATE     2

#define STDIN_FILENO    0
#define STDOUT_FILENO   1
#define STDERR_FILENO   2

#define SCREEN_WIDTH    640
#define SCREEN_WIDTH    480

/* SYSTEM STRUCTS */
struct file;
struct envi;
struct proc;
struct chunck;

/* SYSTEM TYPEDEFS */
typedef short word_t;
typedef int dword_t;
typedef long qword_t;

/* OPERATING SYSTEM STRUCTS */
struct addr {
   word_t head;
   word_t track;
   word_t sector;
   word_t address;
};
struct inode {
   char buffer[504];
   struct addr next;
};
struct time {
   word_t hour;
   word_t min;
   word_t sec;
   word_t mill;
};
struct date {
   word_t year;
   word_t month;
   word_t day;
   sturct time t;
};
struct file {
   word_t fd;
   addr start;
   char name[MAX_STRING];
   date last_mod;
   date create_date;
   word_t access_code;
   word_t length;
};
struct regs {
   short ip;
   short ax;
   short dx;
   short bx;
   short bp;
   short sp;
   short cx;
   short al;
   short di;
   short si;
};
struct proc {
   word_t pid;
   char name[MAX_STRING];
   struct regs reg;
};
struct envi {
   char name[MAX_STRING];
   cahr value[MAX_STRING];
};
struct chunck {
   char * ptr;
   word_t size;
   struct check * next;
};

/* ALLOCATION OF STATE FOR THE OS */
struct file file_array[MAX_FILE];
struct proc proc_array[MAX_PROC];
struct envi envi_array[MAX_ENVI];

struct chunck * p_chunk_list;
char * base_ptr;
char * stack_ptr;

word_t file_count;
word_t proc_count;
word_t envic_count;

word_t screen_row;
word_t screen_col;

/* THE INTERNAL FUNCTIONS OF THE OS */
void ___printf(const char * fmt, ...);
word_t ___gets(char * buffer, word_t size);
word_t __k_read_disk(word_t track, word_t haed, word_t sector, word_t addr, char * buffer);
word_t ___write_disk(word_t track, word_t haed, word_t sector, word_tladdr, char * buffer);
word_t ___write_crt(const char * buffer, short size);
short ___read_kb(const char * buffer, word_t size);
void ___swapin(struct regs * p_regs);
void ___swapout(struct regs * p_regs);
word_t ___runbat(const char * bname);
word_t ___runcom(const char * pname);
word_t ___exec(const char * pname);

/* THE FUNCTIONS OF THE OS */
void start();
void init();
ovid fin();
word_t spawnl(const char * pname, short argc, char ** argv, char ** envp);
word_t open(const char * fname, short mode);
void close(word_t fd);
word_t read(word_t fd, char * buffer, short size);
word_t write(word_t fd, char * buffer, short size);
word_t lseek(word_t fd, short addr, short whence);
word_t mkdir(const char * dir);
word_t unlink(const char * fn);
void* malloc(short size);
void free(char * ptr);
void exit(word_t code);
const char * getenv(const char * name);
void setenv(const char * name, const char * value);
char * alloca(word_t size);
qword_t time(struct datetime * tm);
void srand(qword_t seed);
qword_t rand();
word_t system(const char * cmd);

#endif
