HPGCC3 Documentation 3.0 R003

kos.h

Go to the documentation of this file.
00001 //& *** (c) 2006-2011 The HPGCC3 Team ***
00002 //& Claudio Lapilli
00003 //& Ingo Blank
00004 //&
00005 //& This file is licensed under the terms and conditions of the
00006 //& HPGCC3 license that is included with the source distribution.
00007 //& *** (c) 2006-2011 The HPGCC3 Team ***
00008 
00009 // $Id: kos.h 517 2007-11-19 04:09:04Z claudio $
00010 
00011 #ifndef _KOS_H
00012 #define _KOS_H
00013 
00014 
00015 
00016 typedef unsigned int U32;
00017 typedef int S32;
00018 typedef unsigned short U16;
00019 typedef short S16;
00020 typedef unsigned char U8,*P_U8;
00021 typedef char S8;
00022 typedef char BYTE;
00023 typedef char *P_BYTE;
00024 typedef int BOOL;
00025 typedef void *P_VOID;
00026 
00027 #ifndef size_t
00028 #define size_t unsigned int
00029 #endif /* size_t */
00030 
00031 #ifndef SIZE_T
00032 #define SIZE_T size_t
00033 #endif
00034 
00035 
00036 //Al 19th Nov '04
00037 #ifndef NULL
00038 #define NULL 0
00039 #endif
00040 
00041 // < ibl ; 2004-10-28 >
00042 #define TIME_T unsigned int 
00043 
00044 typedef U32 (*FUNC_PTR)();
00045 typedef U32 (*FUNC0PTR)();
00046 typedef U32 (*FUNC1PTR)(U32);
00047 typedef U32 (*FUNC2PTR)(U32,U32);
00048 typedef U32 (*FUNC3PTR)(U32,U32,U32);
00049 
00050 
00051 
00052 #ifndef FALSE
00053 #define FALSE 0
00054 #define TRUE (! FALSE)
00055 #endif
00056 
00057 
00058 
00059 
00061 typedef struct
00062 {
00063     U16 year;    
00064     U8 month;    
00065     U8 day;        
00066 }
00067 KDATE;
00068 
00070 typedef struct
00071 {
00072     U8 hours;        
00073     U8 minutes;        
00074     U8 seconds;        
00075     U8 unknown1;    
00076     U32 unknown2;    
00077 } KTIME;
00078 
00079 // The KOS Date&Time Structure (nesting)
00080 typedef struct
00081 {
00082     KDATE date;        
00083     KTIME time;        
00084 }
00085 KDATETIME, *P_KDATETIME;
00086 
00087 
00088 
00089 
00090 // memory alloc type define
00091 #define KOS_MEM_FREE                        0x0000
00092 // memory not allocated
00093 #define KOS_MEM_GLOBAL                      0x1000
00094 // global memory type
00095 #define KOS_MEM_LOCAL                       0x2000
00096 // local (task) memory type
00097 #define KOS_MEM_HEAP0                       0x0100
00098 // heap number
00099 
00100 #define KOS_MODULE_FILESYSTEM 1
00101 
00102 #define KOS_FUNC_FOPEN    0
00103 #define KOS_FUNC_FREAD    1
00104 #define KOS_FUNC_FWRITE    2
00105 #define KOS_FUNC_FCLOSE    3
00106 #define KOS_FUNC_FSEEK    4
00107 #define KOS_FUNC_FDELETE 5
00108 // < Benjamin ; 2005-06-12 >
00109 #define KOS_FUNC_FRENAME        6
00110 #define KOS_FUNC_CHDIR            7
00111 #define KOS_FUNC_GETFILEINFO    8
00112 #define KOS_FUNC_GETFIRSTDIR    9
00113 #define KOS_FUNC_GETNEXTDIR        10
00114 #define KOS_FUNC_GETPREVDIR        11
00115 #define KOS_FUNC_GETFIRSTFILE    12
00116 #define KOS_FUNC_GETNEXTFILE    13
00117 #define KOS_FUNC_GETPREVFILE    14
00118 #define KOS_FUNC_FATTR            15
00119 #define KOS_FUNC_GETSIZE        16
00120 #define KOS_FUNC_CHECKINSERT    17
00121 #define KOS_FUNC_CHECKPROTECT    18
00122 
00123 
00124 
00125 #define KOS_READMODE 1        
00126 #define KOS_WRITEMODE 2
00127 
00128 // Filesystem (fs.h)
00129 
00130 // we don't have that...
00131 // #include "kgeneraldef.h"
00132 
00133 #define FAT32_SUPPORT  1
00134 
00135 
00136 #define NEW_FILE_NAME
00137 
00138 // < Benjamin ; 2005-06-12 >
00140 typedef struct 
00141 //__file_dir_info
00142 {
00143        KDATETIME       last_modifier;
00144        KDATETIME       create_date;
00145        KDATE           last_access_date;
00146 #ifdef  NEW_FILE_NAME
00147        BYTE            file_name[13];    
00148 #else
00149        BYTE            extension[4];
00150        BYTE            name[9];
00151 #endif
00152 
00170        U8               attribute;    
00171        U16             ext_attr;    
00172        U32             size;        
00173 }
00174 FILE_INFO, DIR_INFO, *P_FILE_INFO, *P_DIR_INFO;
00175 
00176 
00177 
00178 typedef S32     H_FILE;
00179 
00180 // < Benjamin ; 2005-06-12 >
00181 // Attributes for FILE_INFO/DIR_INFO
00183 #define KOS_READONLY_ATTRIBUTE (1)
00184 
00185 #define KOS_HIDDEN_ATTRIBUTE (1<<1)
00186 
00187 #define KOS_SYSTEM_ATTRIBUTE (1<<2)
00188 
00189 #define KOS_ARCHIVE_ATTRIBUTE (1<<5)
00190 
00191 #define FILE_READONLY   0x00000001      //mode parameter in kos_fopen
00192 #define FILE_READWRITE  0x00000002
00193 #define FILE_APPEND     0x00000003
00194 
00195 #define FS_SEEK_SET             0
00196 #define FS_SEEK_CUR             1
00197 #define FS_SEEK_END             2
00198 
00199 #define ERR_FS_INVALID_NAME                     -1
00200 #define ERR_FS_FILE_OPENED                      -2
00201 #define ERR_FS_INVALID_HANDLE                   -3
00202 #define ERR_FS_INVALID_INDEX                    -4
00203 #define ERR_FS_INVALID_MODE                     -5
00204 #define ERR_FS_DISK_FULL                        -6
00205 #define ERR_FS_DISK_ERROR                       -7
00206 #define ERR_FS_DISK_CHANGE                      -8
00207 #define ERR_FS_NO_SDCARD                        -9
00208 #define ERR_FS_NO_MEMORY                       -10
00209 #define ERR_FS_NOT_SUPPORT                     -11
00210 #define ERR_FS_PROTECT                         -13
00211 #define ERR_FS_NOTFIND                         -14
00212 #define ERR_FS_DISK_REMOVE                     -15
00213 #define ERR_FS_FILE_NOTEXIST                   -16
00214 #define ERR_FS_UNKNOWN                        -100
00215 
00216 
00217 
00218 // Errors
00219 
00220 #define SUCCESS 0
00221 #define EOF -1
00222 #define KOS_ERR_INVALIDPTR    -200 // FIXME: random guess
00223 
00224 // Kernel
00225 
00226 FUNC_PTR kos_GetFuncEntry(U32 module, U32 index);
00227 
00228 // Filesystem
00229 
00230 H_FILE kos_fopen(P_BYTE fname, U8 mode);
00231 SIZE_T kos_fread(H_FILE fd, P_BYTE buf, U32 length);
00232 SIZE_T kos_fwrite(H_FILE fd, P_BYTE buf, U32 length);
00233 S32 kos_fseek(H_FILE fd, S32 offset, U32 mode);
00234 S32 kos_fclose(H_FILE fd);
00235 S32 kos_fdelete(P_BYTE fname);
00236 
00237 
00238 // CHANGED TO A MACRO
00239 #define fdelete(a) kos_fdelete(a);
00240 
00241 
00242 
00243 
00244 
00245 
00246 
00247 // < Benjamin ; 2005-06-12 >
00249 
00252 S32 kos_frename(P_BYTE oldname, P_BYTE newname);
00253 
00255 
00265 S32 kos_chdir(P_BYTE pDir);
00266 
00268 S32 kos_GetSpecialFileInfo(P_BYTE fname, P_FILE_INFO pInfo);
00269 
00271 
00276 S32 kos_GetFirstDirInfo(P_DIR_INFO pInfo);
00277 
00279 
00288 S32 kos_GetNextDirInfo(P_DIR_INFO pInfo, U32 index);
00289 
00291 
00300 S32 kos_GetPrevDirInfo(P_DIR_INFO pInfo, U32 index);
00301 
00303 
00346 S32 kos_GetFirstFileInfo(P_FILE_INFO pInfo);
00347 
00349 
00358 S32 kos_GetNextFileInfo(P_FILE_INFO pInfo, U32 index);
00359 
00361 
00370 S32 kos_GetPrevFileInfo(P_FILE_INFO pInfo, U32 index);
00371 
00373 
00376 S32 kos_fattr(P_BYTE fname, U8 attr);
00377 
00378 
00380 
00384 S32 kos_GetDiskFreeSize(void);
00385 
00387 
00391 S32 kos_CheckDiskInsert(void);
00392 
00394 
00398 S32 kos_CheckDiskProtect(void);
00399 
00401 
00407 void kos_ResetSD(void);
00408 
00409 
00410 
00411 
00412 
00413 
00414 //Edit by Al 19th October
00415 //Include more of HP's KOS functions
00416 
00417 //TODO: Add the rest (except maybe the dangerous ones)
00418 
00419 //memory management
00420 
00421 void *kos_malloc(SIZE_T size); //malloc. ~100kb free on 49g+, <30k free on 39g+
00422 S32 kos_free(void *pMemory); //free
00423  
00424 
00425 //display routines
00426 
00427 void kos_ClearLcd(void); //clears the LCD
00428 U32 kos_PutString(U32 dx, U32 dy, P_VOID ptr); //writes a string, in large 5 x 8 font
00429 void kos_PutHexNumber(U32 dx, U32 dy, U32 value); //write a number in hex
00430 void kos_PutDecNumber(U32 dx, U32 dy, U32 value, U32 bit); //writes a number in base-10
00431 
00432 U32 kos_LCDGetContrast(void); //gets and sets LCD contrast
00433 void kos_LCDSetContrast(U32 contrast);
00434 
00435 //misc routines
00436 
00437 P_BYTE kos_getSerialNumber(void); //seems to return garbage, and a Kinpo copyright. 
00438 void kos_Reset(void); // reset OS + emulator?
00439 S32 kos_beep(U32 freq, TIME_T time, U32 override);
00440 
00441 // Time
00442 
00443 U32 kos_GetSysTickTime();
00444 
00445 
00446 
00447 #endif