Difference between revisions of "84PCE:OS:C Include File"

From WikiTI
Jump to: navigation, search
(Created page with "= C Function Prototypes= <pre>// Parts from Matt "MateoConLechuga" Waltz and Jacob "jacobly" Young, in addtion to // contributors of http://wikiti.brandonw.net/index.php?title...")
 
Line 1: Line 1:
 +
[[Category:84PCE:OS_Information]]
 
= C Function Prototypes=
 
= C Function Prototypes=
 
<pre>// Parts from Matt "MateoConLechuga" Waltz and Jacob "jacobly" Young, in addtion to
 
<pre>// Parts from Matt "MateoConLechuga" Waltz and Jacob "jacobly" Young, in addtion to

Revision as of 00:33, 6 March 2016

C Function Prototypes

// Parts from Matt "MateoConLechuga" Waltz and Jacob "jacobly" Young, in addtion to
// contributors of http://wikiti.brandonw.net/index.php?title=84PCE:OS:Include_File
// Latest as of March. 5, 2016

#ifndef TICE_H
#define TICE_H

#include <stdbool.h>
#include <stdint.h>

/* Defines for MMIO memory areas */

/* RTC defines */
/* There’s a whole slew of bootcode RTC functions, but a lot of them are kind of pointless when you could just use these defines from MMIO */
#define rtc_GetSeconds()        (*((uint8_t*)0xF30000))
#define rtc_GetMinutes()        (*((uint8_t*)0xF30004))
#define rtc_GetHours()          (*((uint8_t*)0xF30008))
#define rtc_GetDays()           (*((uint16_t*)0xF3000C))
#define rtc_GetControl()        (*((uint8_t*)0xF30020))
#define rtc_SetControl(c)       ((*((uint8_t*)0xF30020)) = (uint8_t)(c))
#define rtc_LoadSetTime()       ((*((uint8_t*)0xF30020)) = (*((uint8_t*)0xF30020))|64)
#define rtc_SetSeconds(s)       ((*((uint8_t*)0xF30024)) = (uint8_t)(s))
#define rtc_SetMinutes(m)       ((*((uint8_t*)0xF30028)) = (uint8_t)(m))
#define rtc_SetHours(h)         ((*((uint8_t*)0xF3002C)) = (uint8_t)(h))
#define rtc_SetDays(d)          ((*((uint16_t*)0xF3002C)) = (uint16_t)(d))
#define rtc_Time()              (*(volatile uint32_t*)0xF30044)

/* LCD defines */
#define lcd_GetBacklightLevel()  (*((uint8_t*)0xF60024))
#define lcd_SetBacklightLevel(b) ((*((uint8_t*)0xF60024)) = (uint8_t)(b);

/**
 * OS varaible type definitions
 */
typedef struct { int8_t sign, exp; uint8_t mant[7]; } real_t;
typedef struct { real_t real, imag; } cplx_t;
typedef struct { uint16_t dim; real_t *items; } list_t;
typedef struct { uint16_t dim; cplx_t *items; } cplx_list_t;
typedef struct { uint8_t cols, rows; real_t *items; } matrix_t;
typedef struct { uint16_t size; uint8_t *data; } var_t;

/**
 * Cleans up everything and gets ready to enter back to the OS
 * when you are ready to exit your program
 */
void pgrm_CleanUp(void);

/**
 * A faster implementation of memset
 */
void *memset_fast(void *ptr,int value,size_t num);

/**
 * Returns the Bootcode version major
 */
uint8_t boot_GetBootVerMajor(void);

/**
 * Returns the Bootcode version minor
 */
uint8_t boot_GetBootVerMinor(void);

/**
 * Returns the Harware version
 */
uint8_t boot_GetHardwareVers(void);

/**
 * Turns all of VRAM into 0xFF (white)
 */
void boot_ClearVRAM(void);

/**
 * Checks if the [on] key was pressed
 */
bool boot_CheckOnPressed(void);

/**
 * Returns extended keys as 16-bits
 */
int os_GetKey(void);

/**
 * Performs an OS call to get the keypad scan code
 */
int os_GetCSC(void);

/**
 * Disables the OS cursor
 */
void os_DisableCursor(void);

/**
 * Enables the OS cursor
 */
void os_EnableCursor(void);

/**
 * Set/Get the foreground color used to draw text on the graphscreen
 */
void os_SetDrawFGColor(int color);
int os_GetDrawFGColor(void);

/**
 * Set/Get the backgroundground color used to draw text on the graphscreen
 * os_GetDrawBGColor is broken; use at your own risk
 */
void os_SetDrawBGColor(int color);
void os_GetDrawBGColor_BROKEN(int color);

/**
 * Set/Get the cursor posistion used on the homescreen
 */
void os_SetCursorPos(uint8_t curRow, uint8_t curCol);
void os_GetCursorPos(unsigned int *curRow, unsigned int *curCol);

/**
 * Selects/Gets the font to use when drawing on the graphscreen
 * 0: small font
 * 1: large monospace font
 */
void os_FontSelect(char id);
int os_FontGetID(void);

/**
 * Returns the width of a string in the varaible-width format
 * Second function is used to get the height of the characters
 */
int os_FontGetWidth(const char *string);
int os_FontGetHeight(void);

/**
 * Draws a text using the small font to the screen
 * Returns the end column
 */
int os_FontDrawText(const char *string, uint16_t col, uint8_t row);
int os_FontDrawTransText(const char *string, uint16_t col, uint8_t row);

/**
 * Puts some text at the current homescreen cursor location
 * Returns 1 if string fits on screen, 0 otherwise
 */
int os_PutStrFull(const char *string);

/**
 * Puts some text at the current homescreen cursor location
 * Returns 1 if string fits on line, 0 otherwise
 */
int os_PutStrLine(const char *string);

/**
 * Set/Get a particular flag variable
 */
void os_SetFlagByte(int offset, uint8_t set);
uint8_t os_GetFlagByte(int offset);

/**
 * Returns amount of free ram, free set to start of free ram
 */
size_t os_MemChk(void **free);

/**
 * Throws an OS error
 */
void os_ThrowError(uint8_t error);

/**
 * Returns a pointer to symtable of the OS
 */
void *os_GetSymTablePtr(void);

/**
 * Creates an appvar; and returns a pointer to the structure 
 * Returns NULL if creation failed for some reason, otherwise a pointer to the size bytes
 */
var_t *os_CreateAppVar(const char *name, uint16_t size);

/**
 * Returns next entry or NULL if no more entries, pass os_GetSymTablePtr() as first entry
 */
void *os_NextSymEntry(void *entry, uint24_t *type, uint24_t *nameLength, char *name, void **data);

/**
 * If file exists, returns 1 and sets entry and data, otherwise returns 0.
 * entry and/or data can be NULL if you don't care
 */
int os_ChkFindSym(uint8_t type, const char *name, void **entry, void **data);

/**
 * type is set to the current varaible type in ANS, and a pointer to the data is returned
 * Returns NULL if Ans doesn't exist or type is NULL
 */
void *os_RclAns(uint8_t *type);

/**
 * Copies a real_t type to another location
 * Returns dest
 */
real_t *os_RealCopy(real_t *dest, const real_t *src);

/**
 * Urnary operations used to interact with the OS math functions
 * All return result
 */
real_t *os_RealAcosRad(real_t *result, const real_t *arg);
real_t *os_RealAsinRad(real_t *result, const real_t *arg);
real_t *os_RealAtanRad(real_t *result, const real_t *arg);
real_t *os_RealCosRad(real_t *result, const real_t *arg);
real_t *os_RealRadToDeg(real_t *result, const real_t *arg);
real_t *os_RealExp(real_t *result, const real_t *arg);
real_t *os_RealFloor(real_t *result, const real_t *arg);
real_t *os_RealFrac(real_t *result, const real_t *arg);
real_t *os_RealRoundInt(real_t *result, const real_t *arg);
real_t *os_RealLog(real_t *result, const real_t *arg);
real_t *os_RealNeg(real_t *result, const real_t *arg);
real_t *os_RealDegToRad(real_t *result, const real_t *arg);
real_t *os_RealInv(real_t *result, const real_t *arg);
real_t *os_RealSinRad(real_t *result, const real_t *arg);
real_t *os_RealSqrt(real_t *result, const real_t *arg);
real_t *os_RealTanRad(real_t *result, const real_t *arg);
real_t *os_RealInt(real_t *result, const real_t *arg);
cplx_t *os_CplxSquare(cplx_t *result, const cplx_t *arg);

/**
 * Binary operations used to interact with the OS math functions
 * All return result
 */
real_t *os_RealAdd(real_t *result, const real_t *arg1, const real_t *arg2);
real_t *os_RealDiv(real_t *result, const real_t *arg1, const real_t *arg2);
real_t *os_RealGcd(real_t *result, const real_t *arg1, const real_t *arg2);
real_t *os_RealLcm(real_t *result, const real_t *arg1, const real_t *arg2);
real_t *os_RealMax(real_t *result, const real_t *arg1, const real_t *arg2);
real_t *os_RealMin(real_t *result, const real_t *arg1, const real_t *arg2);
real_t *os_RealMul(real_t *result, const real_t *arg1, const real_t *arg2);
real_t *os_RealNcr(real_t *result, const real_t *total, const real_t *num);
real_t *os_RealNpr(real_t *result, const real_t *total, const real_t *num);
real_t *os_RealPow(real_t *result, const real_t *base, const real_t *exp);
real_t *os_RealRandInt(real_t *result, const real_t *min, const real_t *max);
real_t *os_RealMod(real_t *result, const real_t *arg1, const real_t *arg2);
real_t *os_RealSub(real_t *result, const real_t *arg1, const real_t *arg2);
/**
 * digits must be in the range 0 - 9
 */
real_t *os_RealRound(real_t *result, const real_t *arg, char digits);

/**
 * Returns -1, 0, or 1 depending on the comparison
 */
int os_RealCompare(const real_t *arg1, const real_t *arg2);

/** os_RealToStr:
  *  This converts a ti-float to a ti-ascii string.
  *  result: zero terminated string copied to this address
  *  arg: real to convert
  * maxLength: 
  *  <=0: use default max length (14)
  *  >0:  max length of result, minimum of 6
  * mode:
  *  0: Use current mode for everything (digits ignored)
  *  1: Normal mode
  *  2: Sci mode
  *  3: Eng mode
  *  >4: Use current Normal/Sci/Eng mode (digits still used)
  * digits:
  *  -1:  Float mode
  *  0-9: Fix # mode
  *  returns length of result
  */
int os_RealToStr(char *result, const real_t *arg, char maxLength, char mode, char digits);

/** os_StrToReal:
  *  This converts a ti-ascii string to a ti-float.
  *  String format regexp: / *[-\032+]?[0-9]*(\.[0-9]*)?([eE\033][-\032+]?[0-9]*)?/
  *  result: resulting ti-float stored here, on exponent overflow this is +-9.9999999999999e99
  *  string: ti-ascii string to convert
  *  end: if non-null, pointer to end of parsed number is stored here
  *  returns result
  */
real_t *os_StrToReal(real_t *result, const char *string, char **end);

/** 
 * Basically a reimplemented form of printf that prints to some debugging device
 */
void boot_DebugPrintf(const char *string);

/**
 * Turns off the calculator (probably not a good idea to use)
 */
void boot_TurnOff(void);

/**
 * Inserts a new line at the current cursor posistion on the homescreen
 */
void boot_NewLine(void);

/**
 * Prints the boot version at a really silly place on the homescreen
 */
void boot_PrintBootVersion(void);

/**
 * Sets the calculator into 6MHz mode and 48MHz modes. Note that the ones
 * suffix with I perserve the interrupt vectors
 */
void boot_Set6MHzMode(void);
void boot_Set48MHzMode(void);
void boot_Set6MHzModeI(void);
void boot_Set48MHzModeI(void);

/**
 * Returns the current battery status
 */
uint8_t boot_GetBatteryStatus(void);

/**
 * Waits for just a bit
 * Someone should really look at this to see how long it actually is
 */
void boot_WaitShort(void);

/**
 * Checks if the calculator is being powered via USB
 */
bool boot_USBPowered(void);

/**
 * Checks if there is not a USB plug of A type in the USB port
 */
bool boot_NotPlugTypeA(void);

/**
 * Set the time of the calculator
 */
void boot_SetTime(uint8_t seconds, uint8_t minutes, uint8_t hours);

/**
 * High 8 is unsigned offset, low 8 is bits to test
 * os_TestFlagBits will return a 0 or 1
 */
int os_TestFlagBits(uint16_t offset_pattern);
void os_SetFlagBits(int16_t offset_pattern);
void os_ResetFlagBits(int16_t offset_pattern);

/**
 * Whole bunch of possibly useful timer functions
 */
void boot_SetTimersControlRegister(uint16_t value);
uint16_t boot_GetTimersControlRegister(void);
void boot_SetTimersInterruptStatus(uint16_t value);
uint16_t boot_GetTimersInterruptStatus(void);
void boot_SetTimersInterruptMask(uint16_t value);
uint16_t boot_GetTimersInterruptMask(void);
void boot_SetTimer1Counter(uint32_t count);
uint32_t boot_GetTimer1Counter(void);
void boot_SetTimer1ReloadValue(uint32_t value);
uint32_t boot_GetTimer1ReloadValue(void);
void boot_SetTimer1MatchValue1(uint32_t value);
uint32_t boot_GetTimer1MatchValue1(void);
void boot_SetTimer1MatchValue2(uint32_t value);
uint32_t boot_GetTimer1MatchValue2(void);
void boot_SetTimer2Counter(uint32_t count);
uint32_t boot_GetTimer2Counter(void);
void boot_SetTimer2ReloadValue(uint32_t value);
uint32_t boot_GetTimer2ReloadValue(void);
void boot_SetTimer2MatchValue1(uint32_t value);
uint32_t boot_GetTimer2MatchValue1(void);
void boot_SetTimer2MatchValue2(uint32_t value);
uint32_t boot_GetTimer2MatchValue2(void);

/**
 * Things you shouldn't use unless you know what you are doing:
 */
void os_ForceCmdNoChar(void);
/* ============================================ */

/* === OS and Bootcode Funtion Wrapper ======== */
#pragma asm "xref __saveIY"
#define _OS(FUNC) \
    do { \
      asm("	LD	(__saveIY),IY"); \
      asm("	LD	IY, 13631616"); \
      FUNC ; \
      asm("	LD	IY,(__saveIY)"); \
    } while (0)
/* ============================================ */

#endif

C Function Locations and definitions

; C Functions present in the CE OS and Bootcode

; === External Definitions ===================
    .assume ADL=1
    .def _boot_GetBootVerMajor
    .def _boot_GetHardwareVers
    .def _boot_GetBootVerMinor
    .def _boot_DebugPrintf
    .def _boot_ClearVRAM
    .def _boot_TurnOff
    .def _boot_NewLine
    .def _boot_PrintBootVersion
    .def _boot_Set6MHzMode
    .def _boot_Set48MHzMode
    .def _boot_Set6MHzModeI
    .def _boot_Set48MHzModeI
    .def _boot_GetBatteryStatus
    .def _boot_WaitShort
    .def _boot_DoNothing1, _boot_DoNothing2
    .def _boot_USBPowered
    .def _boot_NotPlugTypeA
    .def _boot_SetTimersControlRegister
    .def _boot_GetTimersControlRegister
    .def _boot_SetTimersInterruptStatus
    .def _boot_GetTimersInterruptStatus
    .def _boot_SetTimersInterruptMask
    .def _boot_GetTimersInterruptMask
    .def _boot_SetTimer1Counter
    .def _boot_GetTimer1Counter
    .def _boot_SetTimer1ReloadValue
    .def _boot_GetTimer1ReloadValue
    .def _boot_SetTimer1MatchValue1
    .def _boot_GetTimer1MatchValue1
    .def _boot_SetTimer1MatchValue2 
    .def _boot_GetTimer1MatchValue2
    .def _boot_SetTimer2Counter
    .def _boot_GetTimer2Counter
    .def _boot_SetTimer2ReloadValue
    .def _boot_GetTimer2ReloadValue
    .def _boot_SetTimer2MatchValue1
    .def _boot_GetTimer2MatchValue1
    .def _boot_SetTimer2MatchValue2 
    .def _boot_GetTimer2MatchValue2
    .def _boot_CheckOnPressed
    .def _boot_SetTime
    .def _os_ThrowError
    .def _os_RealCopy
    .def _os_RealAsinRad
    .def _os_RealAcosRad
    .def _os_RealAtanRad
    .def _os_RealAdd
    .def _os_CplxSquare
    .def _os_RealCompare
    .def _os_RealCosRad
    .def _os_RealRadToDeg
    .def _os_RealDiv
    .def _os_RealExp
    .def _os_RealFloor
    .def _os_RealToStr
    .def _os_RealFrac
    .def _os_RealGcd
    .def _os_RealRoundInt
    .def _os_RealLcm
    .def _os_RealLog
    .def _os_RealMax
    .def _os_RealMin
    .def _os_RealMul
    .def _os_RealNcr
    .def _os_RealNeg
    .def _os_RealNpr
    .def _os_RealPow
    .def _os_RealDegToRad
    .def _os_RealRandInt
    .def _os_RealInv
    .def _os_RealMod
    .def _os_RealRound
    .def _os_RealSinRad
    .def _os_RealSqrt
    .def _os_RealSub
    .def _os_RealTanRad
    .def _os_StrToReal
    .def _os_RealInt
    .def _os_SetFlagBits
    .def _os_ResetFlagBits
    .def _os_TestFlagBits
    .def _os_SetFlagByte
    .def _os_GetFlagByte
    .def _os_GetCursorPos
    .def _os_PutStrFull
    .def _os_PutStrLine
    .def _os_SetCursorPos
    .def _os_GetKey
    .def _os_GetCSC
    .def _os_DisableCursor
    .def _os_EnableCursor
    .def _os_FontDrawText
    .def _os_FontGetHeight
    .def _os_FontGetWidth
    .def _os_InitDrawing
    .def _os_SetDrawBGColor
    .def _os_SetDrawFGColor
    .def _os_FontSelect
    .def _os_GetDrawBGColor_BROKEN
    .def _os_GetDrawFGColor
    .def _os_FontGetID
    .def _os_ForceCmdNoChar
    .def _os_GetSymTablePtr
    .def _os_NextSymEntry
    .def _os_ChkFindSym
    .def _os_MemChk
    .def _os_FontDrawTransText
    .def _os_CreateAppVar
; ============================================

; === Location Equates =======================
_boot_GetBootVerMajor           equ 000080h
_boot_GetHardwareVers           equ 000084h
_boot_GetBootVerMinor           equ 00008Ch
_boot_DebugPrintf               equ 0000B4h
_boot_ClearVRAM                 equ 000374h
_boot_TurnOff                   equ 000388h
_boot_NewLine                   equ 000390h
_boot_PrintBootVersion          equ 000394h
_boot_Set6MHzMode               equ 00039Ch
_boot_Set48MHzMode              equ 0003A0h
_boot_Set6MHzModeI              equ 0003A4h
_boot_Set48MHzModeI             equ 0003A8h
_boot_GetBatteryStatus          equ 0003B0h
_boot_WaitShort                 equ 0003B4h
_boot_DoNothing1                equ 0003D8h
_boot_DoNothing2                equ 0003DCh
_boot_USBPowered                equ 0003E4h
_boot_NotPlugTypeA              equ 0003E8h
_boot_SetTimersControlRegister  equ 000520h
_boot_GetTimersControlRegister  equ 000524h
_boot_SetTimersInterruptStatus  equ 000528h
_boot_GetTimersInterruptStatus  equ 00052Ch
_boot_SetTimersInterruptMask    equ 000530h
_boot_GetTimersInterruptMask    equ 000534h
_boot_SetTimer1Counter          equ 000538h
_boot_GetTimer1Counter          equ 00053Ch
_boot_SetTimer1ReloadValue      equ 000540h
_boot_GetTimer1ReloadValue      equ 000544h
_boot_SetTimer1MatchValue1      equ 000548h
_boot_GetTimer1MatchValue1      equ 00054Ch
_boot_SetTimer1MatchValue2      equ 000550h
_boot_GetTimer1MatchValue2      equ 000554h
_boot_SetTimer2Counter          equ 000558h
_boot_GetTimer2Counter          equ 00055Ch
_boot_SetTimer2ReloadValue      equ 000560h
_boot_GetTimer2ReloadValue      equ 000564h
_boot_SetTimer2MatchValue1      equ 000568h
_boot_GetTimer2MatchValue1      equ 00056Ch
_boot_SetTimer2MatchValue2      equ 000570h
_boot_GetTimer2MatchValue2      equ 000574h
_boot_CheckOnPressed            equ 00057Ch
_boot_SetTime                   equ 0005B4h
_os_ThrowError                  equ 021C80h
_os_RealCopy                    equ 021C84h
_os_RealAsinRad                 equ 021C88h
_os_RealAcosRad                 equ 021C8Ch
_os_RealAtanRad                 equ 021C90h
_os_RealAdd                     equ 021C94h
_os_CplxSquare                  equ 021C98h
_os_RealCompare                 equ 021C9Ch
_os_RealCosRad                  equ 021CA0h
_os_RealRadToDeg                equ 021CA4h
_os_RealDiv                     equ 021CA8h
_os_RealExp                     equ 021CACh
_os_RealFloor                   equ 021CB0h
_os_RealToStr                   equ 021CB4h
_os_RealFrac                    equ 021CB8h
_os_RealGcd                     equ 021CBCh
_os_RealRoundInt                equ 021CC0h
_os_RealLcm                     equ 021CC4h
_os_RealLog                     equ 021CC8h
_os_RealMax                     equ 021CCCh
_os_RealMin                     equ 021CD0h
_os_RealMul                     equ 021CD4h
_os_RealNcr                     equ 021CD8h
_os_RealNeg                     equ 021CDCh
_os_RealNpr                     equ 021CE0h
_os_RealPow                     equ 021CE4h
_os_RealDegToRad                equ 021CE8h
_os_RealRandInt                 equ 021CECh
_os_RealInv                     equ 021CF0h
_os_RealMod                     equ 021CF4h
_os_RealRound                   equ 021CF8h
_os_RealSinRad                  equ 021CFCh
_os_RealSqrt                    equ 021D00h
_os_RealSub                     equ 021D04h
_os_RealTanRad                  equ 021D08h
_os_StrToReal                   equ 021D0Ch
_os_RealInt                     equ 021D10h 
_os_SetFlagBits                 equ 021D14h
_os_ResetFlagBits               equ 021D18h
_os_TestFlagBits                equ 021D1Ch
_os_SetFlagByte                 equ 021D20h
_os_GetFlagByte                 equ 021D24h
_os_GetCursorPos                equ 021D28h
_os_PutStrFull                  equ 021D2Ch
_os_PutStrLine                  equ 021D30h
_os_SetCursorPos                equ 021D34h
_os_GetKey                      equ 021D38h
_os_GetCSC                      equ 021D3Ch
_os_DisableCursor               equ 021DE4h
_os_EnableCursor                equ 021DE8h
_os_FontDrawText                equ 021E00h
_os_FontGetHeight               equ 021E14h
_os_FontGetWidth                equ 021E18h
_os_InitDrawing                 equ 021E1Ch
_os_SetDrawBGColor              equ 021E20h
_os_SetDrawFGColor              equ 021E24h
_os_FontSelect                  equ 021E28h
_os_GetDrawBGColor_BROKEN       equ 021EE4h ; doesn't work due to bug (needs to be ld hl.sis)
_os_GetDrawFGColor              equ 021EE8h
_os_FontGetID                   equ 021EECh
_os_ForceCmdNoChar              equ 021FA8h
_os_GetSymTablePtr              equ 021FB0h
_os_NextSymEntry                equ 021FB4h
_os_ChkFindSym                  equ 021FB8h
_os_MemChk                      equ 021FF0h
_os_FontDrawTransText           equ 022178h
_os_CreateAppVar                equ 022184h
; ============================================