Compare commits

...

17 Commits

Author SHA1 Message Date
mibi88 b885134e79 v.0.2
Reviewed-on: https://gitea.planet-casio.com/mibi88/libMicrofx/pulls/2
2023-04-19 20:24:42 +02:00
mibi88 d07748b059 Improved headers. Documented functions in ext/strtools.h. 2023-04-19 20:17:45 +02:00
mibi88 462c0ebf23 Added comments a bit everywhere, tested and fixed file functions. 2023-04-19 19:09:28 +02:00
mibi88 bc13b79cd2 Improved file functions but made no tests. 2023-04-18 21:42:40 +02:00
mibi88 a73d1afa85 Updated template. 2023-04-17 21:17:43 +02:00
mibi88 d076b5548e Improved file functions (no tests made, but I will make some tests soon). File search functions will come soon. 2023-04-17 21:16:52 +02:00
mibi88 ee87b5e14b Split microfx.c into multiple files. 2023-04-17 09:55:52 +02:00
mibi88 4040920fba Basic file creation, edition, etc. functions. 2023-04-16 19:11:37 +02:00
mibi88 83867d6b6c Added timers 2023-02-03 19:47:07 +01:00
mibi88 9fa301d27a Some improvements. 2023-01-29 17:21:45 +01:00
mibi88 6cd9a9a4e6 Small fix at spixel. 2023-01-23 17:49:36 +01:00
mibi88 2b1f4fa1b3 Updated template. 2023-01-21 12:22:43 +01:00
mibi88 7520667c42 Updated template 2023-01-21 11:41:32 +01:00
mibi88 2fc9309d6b Added some string.h functions. 2023-01-21 11:36:29 +01:00
mibi88 7316b74db1 Started adding string.h functions 2023-01-20 23:05:33 +01:00
mibi88 40e4d7dd31 Added some tools, some drawing functions and some GUI functions. 2023-01-20 18:19:42 +01:00
mibi88 64aa5dcc5e You can get some inputs, now. 2023-01-19 19:53:23 +01:00
26 changed files with 1490 additions and 187 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
build/
lib/
*g1a

View File

@ -2,6 +2,8 @@
Make very small add-ins.
You can also write this name "libµfx" or "ufx".
With this library you can easly make very small add-ins, but they are not as fast as add-ins made using gint, so you should use gint to write more complex add-ins. This library only provides support of the fx98xx series of CASIO monochrome calculators that support add-ins.
## Getting started

View File

@ -4,18 +4,28 @@ AR = sh-elf-ar
OUT = libMicrofx.a
OUT_DIR = lib
SRC = src/start.c src/syscall.S src/microfx.c src/img.c
SRC = src/start.c \
src/syscall.S \
src/display.c \
src/keyboard.c \
src/misc.c \
src/time.c \
src/gui.c \
src/memory.c \
src/ext/img.c
OBJ = $(SRC:src/%=build/%.o)
CFLAGS = -Os -Wall -Wextra -Wpedantic -Werror -std=c89
BUILD = build
all: $(OBJ) | $(OUT_DIR)/
$(AR) rsv $(OUT_DIR)/$(OUT) $(OBJ)
$(AR) rsv $(OUT_DIR)/$(OUT) $(addprefix build/, $(notdir $(OBJ)))
cp --recursive include $(OUT_DIR)/
cp src/fx98xx.ld $(OUT_DIR)/
$(BUILD)/%.o: src/% | $(BUILD)/
$(CC) -c $< -o $@ -Os
$(CC) -c $< -o build/$(notdir $@) $(CFLAGS)
.PRECIOUS: %/

View File

@ -1,6 +0,0 @@
#ifndef MICROFX_CONFIG_H
#define MICROFX_CONFIG_H
#define EX_VERSION "@libMicrofx_VERSION@"
#endif

View File

@ -1,5 +1,5 @@
#ifndef IMG_H
#define IMG_H
#ifndef MICROFX_IMG_H
#define MICROFX_IMG_H
enum {SNORMAL = 0, SINVERTED, STRANSP, SNOWHITE, SNOBLACK};

View File

@ -0,0 +1,132 @@
#ifndef MICROFX_STRTOOLS_H
#define MICROFX_STRTOOLS_H
/* Some string.h functions */
/* int memcmp(void const *__s1, void const *__s2, size_t __n);
Compares the __n first bytes of __s1 and __s2.
Returns
- 0 if they are equal
- a number <0 if the first unsigned char that is diffrent is smaller in __s1
than in __s2.
- a number >0 if the first unsigned char that is diffrent is bigger in __s1 than
in __s2.
*/
int memcmp(void const *__s1, void const *__s2, size_t __n);
/* void *memcpy(void *__dest, void const *__src, size_t __n);
Copy __n first bytes from __src to __dest.
Returns __s1.
*/
void *memcpy(void *__dest, void const *__src, size_t __n);
/* void *memset(void *__s, int __c, size_t __n);
Fills __n first bytes of __s with __c (note that __c is converted to an unsigned
char).
__s is returned.
Overlapping is not allowed.
*/
void *memset(void *__s, int __c, size_t __n);
/* char *strcat(char *__dest, char const *__src);
Copies __src to the end of __dest. The \0 at the end of __dest will be
overwritten, and \0 will be appended at the end of the __dest.
Returns __dest.
*/
char *strcat(char *__dest, char const *__src);
/* int strcmp(char const *__s1, char const *__s2);
Compares __s1 and __s2.
Returns
- 0 if they are equal
- a number <0 if the first char that is diffrent is smaller in __s1 than in
__s2.
- a number >0 if the first char that is diffrent is bigger in __s1 than in __s2.
*/
int strcmp(char const *__s1, char const *__s2);
/* size_t strlen(char const *__s);
Returns the size of the null-terminated string __s, whitout counting the \0.
*/
size_t strlen(char const *__s);
/* char *strncat(char *__dest, char const *__src, size_t __n);
Copies the first __n chars of __src to the end of __dest. The \0 at the end of
__dest will be overwritten, and \0 will be appended at the end of the __dest. If
__n is bigger than the size of the string, only the chars up to the \0 will be
copied.
Returns __dest.
*/
char *strncat(char *__dest, char const *__src, size_t __n);
/* int strncmp(char const *__s1, char const *__s2, size_t __n);
Compares the __n first char of __s1 and __s2.
Returns
- 0 if they are equal
- a number <0 if the first char that is diffrent is smaller in __s1 than in
__s2.
- a number >0 if the first char that is diffrent is bigger in __s1 than in __s2.
If __n is bigger than the size of one of the string, only the chars up to the \0
will be copied.
*/
int strncmp(char const *__s1, char const *__s2, size_t __n);
/* char *strncpy(char *__dest, char const *__src, size_t __n);
Copy __n first bytes from __src to __dest. No \0 is appended at the end of
__dest. If __src is smaller than __n, __dest will be filled with \0 until __n is
reached.
Returns __s1.
*/
char *strncpy(char *__dest, char const *__src, size_t __n);
/* char *strrchr(char const *__s, int __c);
Returns a pointer to the last occurence of __c in __s. The \0 at the end of __s
is included.
*/
char *strrchr(char const *__s, int __c);
/* char *strchr(char const *__s, int __c);
Returns a pointer to the first occurence of __c in __s. The \0 at the end of __s
is included.
*/
char *strchr(char const *__s, int __c);
/* char *strstr(char const *__s1, char const *__s2);
Returns a pointer to the first occurence of __s2 in __s1, or NULL if there was
no one. The \0 at the end of the strings is not included.
*/
char *strstr(char const *__s1, char const *__s2);
/* void *memmove(void *__dest, void const *__src, size_t __n);
Copies the __n first bytes of __src to __dest, but __src and __dest can overlap.
__dest is returned.
*/
void *memmove(void *__dest, void const *__src, size_t __n);
#endif

View File

@ -1,5 +1,5 @@
#ifndef KEYCODES_H
#define KEYCODES_H
#ifndef MICROFX_KEYCODES_H
#define MICROFX_KEYCODES_H
#define KCF1 79
#define KCF2 69

View File

@ -3,8 +3,15 @@
#include "keycodes.h"
#define size_t unsigned int
#define NULL 0
/******* DISPLAY *******/
#define SWIDTH 128
#define SHEIGHT 64
enum {SWHITE = 0, SBLACK};
/* void sclear(void);
@ -23,8 +30,8 @@ void supdate(void);
/* void srect(int x1, int y1, int x2, int y2);
Draws a white rectangle with a black border of one pixel from (x1, y1) to (x2, y2)
in the VRAM.
Draws a white rectangle with a black border of one pixel from (x1, y1) to
(x2, y2) in the VRAM.
*/
void srect(int x1, int y1, int x2, int y2);
@ -46,13 +53,13 @@ The available colors are SWHITE or SBLACK.
void spixel(int x, int y, int color);
/* void stext(int x, int y, char *text);
/* void stext(int x, int y, char *text, int color);
Puts the text text at (x, y) on the screen using casio
default font.
Puts the text text at (x, y) on the screen using casio default font with color
color.
*/
void stext(int x, int y, char *text);
void stext(int x, int y, char *text, int color);
/* void slocate(int x, int y, char *text);
@ -61,6 +68,28 @@ Works like the Locate function of CASIO Basic.
void slocate(int x, int y, char *text);
/* void saddlocate(char *text);
Continues the text displayed with slocate, can be used multiple times after a
locate.
*/
void saddlocate(char *text);
/* void sgoto(int x, int y);
Moves the position where you can add text with saddlocate.
*/
void sgoto(int x, int y);
/* void stextmini(int x, int y, char *text);
Works like stext, but here the font is PrintMini and you cannot set the color.
*/
void stextmini(int x, int y, char *text);
/******* KEYBOARD *******/
/* int kisdown(void);
@ -70,12 +99,10 @@ Returns 0 if there is no key down.
*/
int kisdown(void);
/* int kcheck(int key, int type);
/* int kcheck(int key);
/!\ Not working /!\
Checks if the key key is down or not : returns a positive
int if the key is down, or 0 if he's not down.
Checks if the key key is down or not : returns a positive int if the key is
down, or 0 if the key key is not down.
*/
int kcheck(int key);
@ -95,6 +122,42 @@ Put a string of the int n in buffer.
void itoa(int n, char *buffer);
/* void *malloc(size_t __size);
returns a pointer of size __size.
*/
void *malloc(size_t __size);
/* void *calloc(size_t __nmemb, size_t __size);
returns a pointer of size __nmemb * __size.
*/
void *calloc(size_t __nmemb, size_t __size);
/* void *realloc(void *__ptr, size_t __size);
returns __ptr but changes the size of this pointer to __size.
*/
void *realloc(void *__ptr, size_t __size);
/* void free(void *__ptr);
Free __ptr.
*/
void free(void *__ptr);
/* void itohex(char *buffer, int value, int len);
Puts the hex representation of value into buffer. The hex number will have the
size len.
*/
void itohex(char *buffer, int value, int len);
/******* TIME *******/
/* void tsleep_ms(int ms);
@ -112,13 +175,50 @@ int tgetticks(void);
/* int tiselapsed(int start, int ms);
Check if ms where elapsed since start (ticks that you can
get with tgetticks).
Check if ms where elapsed since start (ticks that you can get with tgetticks).
Returns 1 if ms is elapsed and 0 if it is not.
*/
int tiselapsed(int start, int ms);
/* void treset(void);
Resets RTC.
*/
void treset(void);
/* int tinittimer(int ms, void (*callback)(void));
Initializes a timer that call callback each ms miliseconds.
The timers have a precision of 25 ms.
Returns the id of the timer.
*/
int tinittimer(int ms, void (*callback)(void));
/* void tfreetimer(int id);
Free the timer id.
*/
void tfreetimer(int id);
/* void tstarttimer(int id);
Start the timer id.
*/
void tstarttimer(int id);
/* void tstoptimer(int id);
Stop the timer id.
*/
void tstoptimer(int id);
/******* CPU *******/
/* void csleep(void);
@ -129,4 +229,227 @@ Can be used to reduce battery usage of some loops.
void csleep(void);
/******* GUI *******/
enum {GDEC = 0, GHEX};
/* int gnumask(char *message, int maxlen, int type);
Asks for a num that is returned. message contains the message that will be
displayed when asking for the number. maxlen is the maximal length of the input
and type can be GDEC or GHEX. Set type to GDEC if you want to ask for a decimal
number or GHEX if you want that the user inputs a hexadecimal number.
*/
int gnumask(char *message, int maxlen, int type);
/* void gstrask(char *buffer, char *message, int maxlen);
Asks for a str that will be in buffer. message contains the message that will be
displayed when asking for the string and maxlen is the maximal length of the
input.
*/
void gstrask(char *buffer, char *message, int maxlen);
/* void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
Draws an fkey from a Sprite Coder string that is in img, at fkey position pos.
*/
void gfkeyset(int pos, unsigned char *img);
/* void gmessagebox(int height, char *message);
Draws a message box of height height with that contains message.
*/
void gmessagebox(int height, char *message);
/******* Memory *******/
/* File structure */
typedef struct {
int fd; /* The file descriptor of the file */
int fpos; /* The position in the file (0 after mopen) */
int fwpos; /* The writing position in the file */
int error; /* Positive if there was an error, NULL if there was no one */
int out; /* There was an error if this value is negative */
} MFile;
/* Errors */
enum {
MTOOBIGSIZE = 2,
MODDSIZEWRITE = 1,
MBF_ENTRYNOTFOUND = -1,
MBF_ILLEGALPARAM = -2,
MBF_ILLEGALPATH = -3,
MBF_DEVICEFULL = -4,
MBF_ILLEGALDEVICE = -5,
MBF_ILLEGALFS = -6,
MBF_ILLEGALSYS = -7,
MBF_ACCESSDENIED = -8,
MBF_ALREADYLOCKED = -9,
MBF_ILLEGALTASKID = -10,
MBF_PERMISSIONERROR = -11,
MBF_ENTRYFULL = -12,
MBF_ALREADYEXISTS = -13,
MBF_READONLYFILE = -14,
MBF_ILLEGALFILTER = -15,
MBF_ENUMEND = -16,
MBF_DEVICECHANGED = -17,
MBF_NOTRECORDFILE = -18,
MBF_ILLEGALSEEKPOS = -19,
MBF_ILLEGALBLOCKFILE = -20,
MBF_NOSUCHDEVICE = -21,
MBF_EOF = -22,
MBF_NOTMOUNTDEVICE = -23,
MBF_NOTUNMOUNTDEVICE = -24,
MBF_CANNOTLOCKSYS = -25,
MBF_RECORDNOTFOUND = -26,
MBF_NOTDUALRECORDFILE = -27,
MBF_NOALARMSUPPORT = -28,
MBF_CANNOTADDALARM = -29,
MBF_FILEFINDUSED = -30,
MBF_DEVICEERROR = -31,
MBF_SYSTEMNOTLOCKED = -32,
MBF_DEVICENOTFOUND = -33,
MBF_FILETYPEMISMATCH = -34,
MBF_NOTEMPTY = -35,
MBF_BROKENSYSTEMDATA = -36,
MBF_MEDIANOTREADY = -37,
MBF_TOOMANYALARMS = -38,
MBF_SAMEALARMEXISTS = -39,
MBF_ACCESSSWAPAREA = -40,
MBF_MULTIMEDIACARD = -41,
MBF_COPYPROTECTION = -42,
MBF_ILLEGALFILEDATA = -43
};
/* File types */
enum {
MFILE = 1,
MFOLDER = 5
};
/* Open modes */
enum {
MREAD = 0x01,
MWRITE = 0x02,
MREADW = (MREAD | MWRITE),
MSHARE = 0x80,
MRWS = (MREADW | MSHARE)
};
/* Defines */
#define MRCONTINUE -1 /* Start reading from the current position. */
#define PATHSIZELIMIT 256 /* Max. path size */
/* Prototypes */
/* IMPORTANT NOTES :
- The CASIOWIN/Fugue compatibility is made automatically.
- To see if there is an error, check if the int error in the MFile struct. If
error is not NULL, there was an error. To get the error code just get the
output of the function.
- To get the output of a function, read the int out in the MFile struct.
- Errors are defined later on.
- DO NOT MODIFY fwpos : MODIFING THIS VARIABLE MAY BREAK THINGS !
*/
/* int mfugue(void);
Returns a postive int if the calculator has a fugue filesystem, or 0 if his fs
is CASIOWIN.
*/
int mfugue(void);
/* int mremove(const char *filename);
Removes the file filename. filename is a const char path for UNIX.
If the returned int is negative there was an error (errors are listed above in
an enum).
*/
int mremove(const char *filename);
/* int mcreate(const char *filename, int type, int size);
Creates the file or folder filename with size size. filename is a const char
path for UNIX.
Set type to MFILE if you want to create a file. Please consider that your add-in
may run on a CASIOWIN calculator, so please enter the real size of your file,
and not 0.
But if you want to create a folder, set type to MFOLDER and then you can also
set the size to 0 and I also recommend that because fxlib does that.
Returns a negative int if there was an error.
*/
int mcreate(const char *filename, int type, int size);
/* MFile mopen(const char *filename, int mode);
Opens the file filename with mode mode.
Available modes are :
- MREAD : Opens the file only for reading.
- MWRITE : Opens the file only for writing.
- MREADW : Opens the file for reading and writing.
- MSHARE : (I don't know what it is XD) Opens the file in shared mode.
- MRWS : Opens the file for reading, writing and in shared mode.
As always the filename is for UNIX and is fixed for the calc.
The error, if there was one, is as I described it in "IMPORTANT NOTES" above,
stored in the MFile struct file.
*/
MFile mopen(const char *filename, int mode);
/* void mwrite(MFile *file, const void *data, int size);
Writes size bytes of data to the file at fwpos of MFile struct file that you can
initialise with mopen.
As always, if there was an error, she's stored in MFile.
*/
void mwrite(MFile *file, const void *data, int size);
/* void mread(MFile *file, void *data, int size, int whence);
Read size bytes of the file of the MFile struct file and put them into data. Set
whence to a positive value to set where mread should start reading, or to
MRCONTINUE to continue reading from the current position.
As always, if there was an error, she's stored in MFile.
*/
void mread(MFile *file, void *data, int size, int whence);
/* void mclose(MFile *file);
Close the file MFile.
*/
void mclose(MFile *file);
/* void mseek(MFile *file, int pos);
Jump to the position pos in the file. if the position is invalid, errors may
occur later on. Pass the MFile struct of the file.
*/
void mseek(MFile *file, int pos);
/* void msize(MFile *file);
Puts the size of the file into out of file. Pass the MFile struct of the file.
*/
void msize(MFile *file);
#endif

90
microfx_src/src/display.c Normal file
View File

@ -0,0 +1,90 @@
#include "../include/microfx/microfx.h"
/******* DISPLAY *******/
/* Syscalls */
void _Bdisp_PutDisp_DD(void);
void _Bdisp_DrawRectangle(int x1, int y1, int x2, int y2);
void _Bdisp_AllClr_VRAM(void);
void _Bdisp_SetPoint_VRAM(int x, int y, int color);
void _PrintXY(int x, int y, unsigned char *text, int type);
void _locate(int x, int y);
void _Print(unsigned char *text);
void _Bdisp_DrawLineVRAM(int x1, int y1, int x2, int y2);
void _Bdisp_ClearLineVRAM(int x1, int y1, int x2, int y2);
void _PrintMiniSd(int x, int y, unsigned char *text, int color);
void _DisplayMessageBox(int height, unsigned char *message);
/* Microfx */
void sclear() {
_Bdisp_AllClr_VRAM();
}
void supdate() {
_Bdisp_PutDisp_DD();
}
void spixel(int x, int y, int color) {
if(x>=0 && x<SWIDTH && y>=0 && y<SHEIGHT){
_Bdisp_SetPoint_VRAM(x, y, color);
}
}
void srect(int x1, int y1, int x2, int y2) {
_Bdisp_DrawRectangle(x1, y1, x2, y2);
}
void sline(int x1, int y1, int x2, int y2, int color) {
if(color){
_Bdisp_DrawLineVRAM(x1, y1, x2, y2);
}else{
_Bdisp_ClearLineVRAM(x1, y1, x2, y2);
}
}
void stext(int x, int y, char *text, int color) {
_PrintXY(x, y, (unsigned char*)text, !color);
}
void slocate(int x, int y, char *text) {
_locate(x, y);
_Print((unsigned char*)text);
}
void saddlocate(char *text) {
_Print((unsigned char*)text);
}
void sgoto(int x, int y) {
_locate(x, y);
}
void stextmini(int x, int y, char *text) {
_PrintMiniSd(x, y, (unsigned char*)text, 0);
}
void gmessagebox(int height, char *message) {
_DisplayMessageBox(height, (unsigned char*)message);
}
/******* Tools *******/
/* Syscalls */
int _LongToAscHex(int value, char *dest, int digits);
/* Microfx */
void itohex(char *buffer, int value, int len) {
_LongToAscHex(value, buffer, len);
}
/******* CPU *******/
/* Microfx */
void csleep(void) {
__asm__("sleep");
}

View File

@ -1,4 +1,4 @@
#include "../include/microfx/ext/img.h"
#include "../../include/microfx/ext/img.h"
#include <microfx/microfx.h>
void simage(int sx, int sy, int w, int h, unsigned char *img, int mode) {

23
microfx_src/src/gui.c Normal file
View File

@ -0,0 +1,23 @@
#include "../include/microfx/microfx.h"
/******* GUI *******/
/* Syscalls */
int _InputNumber(unsigned char *heading, int maxlen, int mode);
int _InputString(unsigned char *buffer, unsigned char *heading, int maxlen);
void _DisplayFKeyIcon(int FKeyPos, unsigned char *pBitmap);
/* Microfx */
int gnumask(char *message, int maxlen, int type) {
return _InputNumber((unsigned char *)message, maxlen, type);
}
void gstrask(char *buffer, char *message, int maxlen) {
_InputString((unsigned char *)buffer, (unsigned char *)message, maxlen);
}
void gfkeyset(int pos, unsigned char *img) {
_DisplayFKeyIcon(pos, img);
}

View File

@ -0,0 +1,42 @@
#include "../include/microfx/microfx.h"
/******* KEYBOARD *******/
/* Syscalls */
int _Keyboard_KeyDown(void);
int _Keyboard_PRGM_GetKey(unsigned char* buffer);
/* Microfx */
int kisdown(void) {
return _Keyboard_KeyDown();
}
int kcheck(int key) {
/* TODO : Compatibility with older calcs. */
/* Get the column and the row of the key. */
int row = key%10;
int column = key/10 - 1;
/* The bit that I will read in the KIUDATA
register. */
int column_pos = column + 8 * (row & 1);
/* row_data will contain the data of the
KIUDATA register that we need.
keyboard_register contains the address of
KIUDATA0. */
unsigned short *keyboard_register = (unsigned short*)0xA44B0000;
unsigned short row_data;
/* Get KIUDATAx where x is row / 2 because two rows
are stored in each KIUDATA register. */
row_data = keyboard_register[row/2];
/* Get the bit located at column. */
return (row_data >> column_pos) & 1;
}
int kgetkey(void){
/* Made a prgm like getkey in the same way as simlo described it. */
unsigned char buffer[12];
_Keyboard_PRGM_GetKey(buffer);
return (buffer[1] & 0x0F) * 10 + ((buffer[2] & 0xF0 ) >> 4);
}

151
microfx_src/src/memory.c Normal file
View File

@ -0,0 +1,151 @@
#include "../include/microfx/microfx.h"
/******* Memory *******/
const unsigned short int fname_start[7] = {'\\', '\\', 'f','l','s','0','\\'};
/* Syscalls */
int _Bfile_DeleteEntry(const unsigned short int *filename);
int _Bfile_Create(const unsigned short int *filename, int type, int *size);
int _Bfile_Write(int fd, const void *data, int size);
int _Bfile_Open(const unsigned short int *filename, int mode);
int _Bfile_Read(int fd, void *data, int size, int whence);
int _Bfile_Close(int fd);
int _Bfile_Size(int fd);
/* Microfx */
extern int fugue;
int mfugue(void) {
return fugue;
}
unsigned short int fname[PATHSIZELIMIT];
void _fixname(const char *filename) {
int len, i;
len = 0;
/* Getting the lenght of the filename */
while(filename[len] != '\0' && len < PATHSIZELIMIT){
len++;
}
/* Clearing fname, the file name for Bfile. */
for(i=0;i<PATHSIZELIMIT;i++){
fname[i] = '\0';
}
/* Copying the start of a Bfile file name to fname */
for(i=0;i<7;i++){
fname[i] = fname_start[i];
}
/* Copying the file name to fname, slashs are also replaced by backslashs */
for(i=0;i<len;i++){
if(filename[i+1] != '/'){
fname[i+7] = filename[i+1];
}else{
fname[i+7] = '\\';
}
}
}
int mremove(const char *filename) {
_fixname(filename);
return _Bfile_DeleteEntry(fname);
}
int mcreate(const char *filename, int type, int size) {
int out;
_fixname(filename);
out = _Bfile_Create(fname, type, &size);
return out;
}
MFile mopen(const char *filename, int mode) {
MFile file;
_fixname(filename);
file.out = _Bfile_Open(fname, mode);
if(file.out > 0){
file.fd = file.out;
file.error = 0;
file.fpos = 0;
file.fwpos = 0;
}else{
file.error = 1;
}
return file;
}
void mwrite(MFile *file, const void *data, int size) {
/* Some checks to make the operation more secure. */
if(!fugue && size%2){
file->error = MODDSIZEWRITE;
file->out = 1;
return;
}
msize(file);
if(file->fwpos + size > file->out && !file->error){
file->out = MTOOBIGSIZE;
file->error = 1;
return;
}
/* Calling the Bfile syscall and updating the MFile struct. */
file->out = _Bfile_Write(file->fd, data, size);
file->fpos += size;
file->fwpos += size;
if(file->out < 0){
file->error = 1;
}else{
file->error = 0;
}
}
void mread(MFile *file, void *data, int size, int whence) {
/* Making an absolute position out of whence. */
if(whence == MRCONTINUE) whence = file->fpos;
/* A check to make the operation more secure. */
msize(file);
if(whence + size > file->out && !file->error){
file->out = MTOOBIGSIZE;
file->error = 1;
return;
}
/* Calling the Bfile syscall and updating the MFile struct. */
file->out = _Bfile_Read(file->fd, data, size, whence);
file->fpos += size;
if(file->out < 0){
file->error = 1;
}else{
file->error = 0;
}
}
void mclose(MFile *file) {
/* Calling the Bfile syscall and updating the MFile struct. */
file->out = _Bfile_Close(file->fd);
if(file->out < 0){
file->error = 1;
}else{
file->error = 0;
}
}
void mseek(MFile *file, int pos) {
/* Setting the new position whitout making checks because more informations
are required to make checks, so they are made directly when doing operations
on the file.
error and out are set to 0 because no error can occur when doing this. */
file->fpos = pos;
file->error = 0;
file->out = 0;
}
void msize(MFile *file) {
/* Calling the Bfile syscall and updating the MFile struct. */
file->out = _Bfile_Size(file->fd);
if(file->out < 0){
file->error = 1;
}else{
file->error = 0;
}
}

View File

@ -1,119 +0,0 @@
#include "../include/microfx/microfx.h"
/******* DISPLAY *******/
/* Syscalls */
void _Bdisp_PutDisp_DD(void);
void _Bdisp_DrawRectangle(int x1, int y1, int x2, int y2);
void _Bdisp_AllClr_VRAM(void);
void _Bdisp_SetPoint_VRAM(int x, int y, int color);
void _PrintXY(int x, int y, unsigned char *text, int type);
void _locate(int x, int y);
void _Print(unsigned char *text);
void _Bdisp_DrawLineVRAM(int x1, int y1, int x2, int y2);
void _Bdisp_ClearLineVRAM(int x1, int y1, int x2, int y2);
/* Microfx */
void sclear() {
_Bdisp_AllClr_VRAM();
}
void supdate() {
_Bdisp_PutDisp_DD();
}
void spixel(int x, int y, int color) {
_Bdisp_SetPoint_VRAM(x, y, color);
}
void srect(int x1, int y1, int x2, int y2) {
_Bdisp_DrawRectangle(x1, y1, x2, y2);
}
void sline(int x1, int y1, int x2, int y2, int color) {
if(color){
_Bdisp_DrawLineVRAM(x1, y1, x2, y2);
}else{
_Bdisp_ClearLineVRAM(x1, y1, x2, y2);
}
}
void stext(int x, int y, char *text) {
_PrintXY(x, y, (unsigned char*)text, 0);
}
void slocate(int x, int y, char *text) {
_locate(x, y);
_Print((unsigned char*)text);
}
/******* KEYBOARD *******/
/* Syscalls */
short _Keyboard_GetPressedTime(void);
int _Keyboard_KeyDown(void);
int _Keyboard_PRGM_GetKey(unsigned char* buffer);
/* Microfx */
int kisdown(void) {
return _Keyboard_KeyDown();
}
int kcheck(int key) {
/* TODO : Compatibility with older calcs. */
/* Get the column and the row of the key. */
int row = key%10;
int column = key/10 - 1;
/* The bit that I will read in the KIUDATA
register. */
int column_pos = column + 8 * (row & 1);
/* row_data will contain the data of the
KIUDATA register that we need.
keyboard_register contains the address of
KIUDATA0. */
unsigned short *keyboard_register = (unsigned short*)0xA44B0000;
unsigned short row_data;
/* Get KIUDATAx where x is row / 2 because two rows
are stored in each KIUDATA register. */
row_data = keyboard_register[row/2];
/* Get the bit located at column. */
return (row_data >> column_pos) & 1;
}
int kgetkey(void){
unsigned char buffer[12];
_Keyboard_PRGM_GetKey(buffer);
return (buffer[1] & 0x0F) * 10 + ((buffer[2] & 0xF0 ) >> 4);
}
/******* Time *******/
/* Syscalls */
void _Sleep(int delay_ms);
int _RTC_GetTicks(void);
int _RTC_Elapsed_ms(int start_value, int duration_in_ms);
/* Microfx */
void tsleep_ms(int ms) {
_Sleep(ms);
}
int tgetticks(void) {
return _RTC_GetTicks();
}
int tiselapsed(int start, int ms) {
return _RTC_Elapsed_ms(start, ms);
}
/******* CPU *******/
void csleep(void) {
__asm__("sleep");
}

21
microfx_src/src/misc.c Normal file
View File

@ -0,0 +1,21 @@
#include "../include/microfx/microfx.h"
/******* Tools *******/
/* Syscalls */
int _LongToAscHex(int value, char *dest, int digits);
/* Microfx */
void itohex(char *buffer, int value, int len) {
_LongToAscHex(value, buffer, len);
}
/******* CPU *******/
/* Microfx */
void csleep(void) {
__asm__("sleep");
}

View File

@ -1,21 +1,44 @@
/* Pointers that contain the start and the end address of some sections of the
add-in. */
extern char start_bss, end_bss;
extern char start_data, end_data;
extern char romdata_start;
/* The main function. */
extern int main(void);
/* The variable used when manipulating files, to check if the filesystem is
Fugue or CASIOWIN. */
int fugue;
/* .pretext is where the add-in starts to be executed. */
__attribute__((section(".pretext")))
int start(int isappli, int optnum) {
int start(void) {
int i;
char *bss_startptr = &start_bss;
char *bss_startptr, *data_startptr, *romdataptr;
char *os_version = (void *)0x80010020;
/* Clearing the bss. */
bss_startptr = &start_bss;
for(i=0;i<&end_bss - &start_bss;i++){
bss_startptr[i] = 0;
}
char *data_startptr = &start_data;
char *romdataptr = &romdata_start;
/* Load the ROM data into the RAM. */
data_startptr = &start_data;
romdataptr = &romdata_start;
for(i=0;i<&end_data - &start_data;i++){
data_startptr[i] = romdataptr[i];
}
/* Checking if the calculator has a fugue filesystem, because it is
important to know that when using Bfile. */
if(os_version[1] == '3'){
fugue = 1;
}else{
fugue = 0;
}
/* Calling main. The return value of main is directly returned because no
modifications need to be made. */
return main();
}

View File

@ -10,19 +10,53 @@
.global __Print
.global __Bdisp_DrawLineVRAM
.global __Bdisp_ClearLineVRAM
.global __PrintMiniSd
.global __DisplayMessageBox
/* Keyboard */
.global __Keyboard_GetPressedTime
.global __Keyboard_IsKeyPressed
.global __Keyboard_IsKeyPressed_fast
.global __Keyboard_KeyDown
.global __Keyboard_PRGM_GetKey
/* Time */
.global __Sleep
.global __RTC_GetTicks
.global __RTC_Elapsed_ms
.global __RTC_Reset
.global __Timer_Install
.global __Timer_Deinstall
.global __Timer_Start
.global __Timer_Stop
/* Files */
.global __Bfile_DeleteEntry
.global __Bfile_Create
.global __Bfile_Write
.global __Bfile_Open
.global __Bfile_Read
.global __Bfile_Close
.global __Bfile_Size
/* Tools */
.global _itoa
.global _malloc
.global _calloc
.global _realloc
.global _free
.global __LongToAscHex
/* Tools - str/mem */
.global _memcmp
.global _memcpy
.global _memset
.global _strcat
.global _strcmp
.global _strlen
.global _strncat
.global _strncmp
.global _strncpy
.global _strrchr
.global _strchr
.global _strstr
.global _memmove
/* GUI */
.global __InputNumber
.global __InputString
.global __DisplayFKeyIcon
#define syscall(syscall_number) \
mov.l 1f, r0 ;\
@ -53,13 +87,11 @@ __Bdisp_DrawLineVRAM:
syscall(0x030)
__Bdisp_ClearLineVRAM:
syscall(0x031)
__PrintMiniSd:
syscall(0xC4F)
__DisplayMessageBox:
syscall(0x0901)
/* Keyboard */
__Keyboard_GetPressedTime:
syscall(0x249)
__Keyboard_IsKeyPressed:
syscall(0x24C)
__Keyboard_IsKeyPressed_fast:
syscall(0x24B)
__Keyboard_KeyDown:
syscall(0x24D)
__Keyboard_PRGM_GetKey:
@ -71,11 +103,79 @@ __RTC_GetTicks:
syscall(0x03B)
__RTC_Elapsed_ms:
syscall(0x03C)
__RTC_Reset:
syscall(0x039)
__Timer_Install:
syscall(0x0118)
__Timer_Deinstall:
syscall(0x0119)
__Timer_Start:
syscall(0x011A)
__Timer_Stop:
syscall(0x011B)
/* Files */
/* Nothing here ... */
__Bfile_DeleteEntry:
mov #0, r5
syscall(0x0439)
__Bfile_Create:
syscall(0x434)
__Bfile_Write:
syscall(0x435)
__Bfile_Open:
mov #0, r6
syscall(0x42C)
__Bfile_Read:
syscall(0x432)
__Bfile_Close:
syscall(0x042D)
__Bfile_Size:
syscall(0x042F)
/* Tools */
_itoa:
syscall(0x541)
_malloc:
syscall(0xACD)
_calloc:
syscall(0xE6B)
_realloc:
syscall(0xE6D)
_free:
syscall(0xACC)
__LongToAscHex:
syscall(0x467)
_memcmp:
syscall(0xACE)
_memcpy:
syscall(0xACF)
_memset:
syscall(0xAD0)
_strcat:
syscall(0xAD4)
_strcmp:
syscall(0xAD5)
_strlen:
syscall(0xAD6)
_strncat:
syscall(0xAD7)
_strncmp:
syscall(0xAD8)
_strncpy:
syscall(0xAD9)
_strrchr:
syscall(0xADA)
_strchr:
syscall(0xE6E)
_strstr:
syscall(0xE6F)
_memmove:
syscall(0xE6C)
/* GUI */
__InputNumber:
syscall(0x0CC4)
__InputString:
syscall(0x0CC5)
__DisplayFKeyIcon:
syscall(0x04D1)
/* Menu */
/* Nothing here ... */

49
microfx_src/src/time.c Normal file
View File

@ -0,0 +1,49 @@
#include "../include/microfx/microfx.h"
/******* Time *******/
/* Syscalls */
void _Sleep(int delay_ms);
int _RTC_GetTicks(void);
int _RTC_Elapsed_ms(int start_value, int duration_in_ms);
void _RTC_Reset(unsigned int mode);
int _Timer_Install(int InternalTimerID, void (*handler)(void), int elapse);
int _Timer_Deinstall(int InternalTimerID);
int _Timer_Start(int InternalTimerID);
int _Timer_Stop(int InternalTimerID);
/* Microfx */
void tsleep_ms(int ms) {
_Sleep(ms);
}
int tgetticks(void) {
return _RTC_GetTicks();
}
int tiselapsed(int start, int ms) {
return _RTC_Elapsed_ms(start, ms);
}
void treset(void) {
_RTC_Reset(1);
}
int tinittimer(int ms, void (*callback)(void)) {
return _Timer_Install(0, callback, ms);
}
void tfreetimer(int id) {
_Timer_Deinstall(id);
}
void tstarttimer(int id) {
_Timer_Start(id);
}
void tstoptimer(int id) {
_Timer_Stop(id);
}

View File

@ -24,10 +24,10 @@ $(BIN): $(ELF)
sh-elf-objcopy -O binary build/$(ELF) build/$(BIN) -R .bss
$(ELF): $(OBJ) | $(LIB)/
$(CC) $(OBJ) $(LIB)/libMicrofx.a -o $(BUILD)/$@ -nostdlib -T lib/fx98xx.ld -ffreestanding -mb -m3 -Os -Wa,--dsp
$(CC) $(OBJ) $(LIB)/libMicrofx.a -o $(BUILD)/$@ -nostdlib -T lib/fx98xx.ld -ffreestanding -mb -m3 -Os -Wa,--dsp -lgcc
$(BUILD)/%.o: src/% | $(BUILD)/
$(CC) -c $< -o $@ -Os -Ilib/include/
$(CC) -c $< -o $@ -Os -Ilib/include/ -std=c89
.PRECIOUS: %/

View File

@ -1,6 +0,0 @@
#ifndef MICROFX_CONFIG_H
#define MICROFX_CONFIG_H
#define EX_VERSION "@libMicrofx_VERSION@"
#endif

View File

@ -1,5 +1,5 @@
#ifndef IMG_H
#define IMG_H
#ifndef MICROFX_IMG_H
#define MICROFX_IMG_H
enum {SNORMAL = 0, SINVERTED, STRANSP, SNOWHITE, SNOBLACK};

View File

@ -0,0 +1,132 @@
#ifndef MICROFX_STRTOOLS_H
#define MICROFX_STRTOOLS_H
/* Some string.h functions */
/* int memcmp(void const *__s1, void const *__s2, size_t __n);
Compares the __n first bytes of __s1 and __s2.
Returns
- 0 if they are equal
- a number <0 if the first unsigned char that is diffrent is smaller in __s1
than in __s2.
- a number >0 if the first unsigned char that is diffrent is bigger in __s1 than
in __s2.
*/
int memcmp(void const *__s1, void const *__s2, size_t __n);
/* void *memcpy(void *__dest, void const *__src, size_t __n);
Copy __n first bytes from __src to __dest.
Returns __s1.
*/
void *memcpy(void *__dest, void const *__src, size_t __n);
/* void *memset(void *__s, int __c, size_t __n);
Fills __n first bytes of __s with __c (note that __c is converted to an unsigned
char).
__s is returned.
Overlapping is not allowed.
*/
void *memset(void *__s, int __c, size_t __n);
/* char *strcat(char *__dest, char const *__src);
Copies __src to the end of __dest. The \0 at the end of __dest will be
overwritten, and \0 will be appended at the end of the __dest.
Returns __dest.
*/
char *strcat(char *__dest, char const *__src);
/* int strcmp(char const *__s1, char const *__s2);
Compares __s1 and __s2.
Returns
- 0 if they are equal
- a number <0 if the first char that is diffrent is smaller in __s1 than in
__s2.
- a number >0 if the first char that is diffrent is bigger in __s1 than in __s2.
*/
int strcmp(char const *__s1, char const *__s2);
/* size_t strlen(char const *__s);
Returns the size of the null-terminated string __s, whitout counting the \0.
*/
size_t strlen(char const *__s);
/* char *strncat(char *__dest, char const *__src, size_t __n);
Copies the first __n chars of __src to the end of __dest. The \0 at the end of
__dest will be overwritten, and \0 will be appended at the end of the __dest. If
__n is bigger than the size of the string, only the chars up to the \0 will be
copied.
Returns __dest.
*/
char *strncat(char *__dest, char const *__src, size_t __n);
/* int strncmp(char const *__s1, char const *__s2, size_t __n);
Compares the __n first char of __s1 and __s2.
Returns
- 0 if they are equal
- a number <0 if the first char that is diffrent is smaller in __s1 than in
__s2.
- a number >0 if the first char that is diffrent is bigger in __s1 than in __s2.
If __n is bigger than the size of one of the string, only the chars up to the \0
will be copied.
*/
int strncmp(char const *__s1, char const *__s2, size_t __n);
/* char *strncpy(char *__dest, char const *__src, size_t __n);
Copy __n first bytes from __src to __dest. No \0 is appended at the end of
__dest. If __src is smaller than __n, __dest will be filled with \0 until __n is
reached.
Returns __s1.
*/
char *strncpy(char *__dest, char const *__src, size_t __n);
/* char *strrchr(char const *__s, int __c);
Returns a pointer to the last occurence of __c in __s. The \0 at the end of __s
is included.
*/
char *strrchr(char const *__s, int __c);
/* char *strchr(char const *__s, int __c);
Returns a pointer to the first occurence of __c in __s. The \0 at the end of __s
is included.
*/
char *strchr(char const *__s, int __c);
/* char *strstr(char const *__s1, char const *__s2);
Returns a pointer to the first occurence of __s2 in __s1, or NULL if there was
no one. The \0 at the end of the strings is not included.
*/
char *strstr(char const *__s1, char const *__s2);
/* void *memmove(void *__dest, void const *__src, size_t __n);
Copies the __n first bytes of __src to __dest, but __src and __dest can overlap.
__dest is returned.
*/
void *memmove(void *__dest, void const *__src, size_t __n);
#endif

View File

@ -1,5 +1,5 @@
#ifndef KEYCODES_H
#define KEYCODES_H
#ifndef MICROFX_KEYCODES_H
#define MICROFX_KEYCODES_H
#define KCF1 79
#define KCF2 69

View File

@ -3,8 +3,15 @@
#include "keycodes.h"
#define size_t unsigned int
#define NULL 0
/******* DISPLAY *******/
#define SWIDTH 128
#define SHEIGHT 64
enum {SWHITE = 0, SBLACK};
/* void sclear(void);
@ -23,8 +30,8 @@ void supdate(void);
/* void srect(int x1, int y1, int x2, int y2);
Draws a white rectangle with a black border of one pixel from (x1, y1) to (x2, y2)
in the VRAM.
Draws a white rectangle with a black border of one pixel from (x1, y1) to
(x2, y2) in the VRAM.
*/
void srect(int x1, int y1, int x2, int y2);
@ -46,13 +53,13 @@ The available colors are SWHITE or SBLACK.
void spixel(int x, int y, int color);
/* void stext(int x, int y, char *text);
/* void stext(int x, int y, char *text, int color);
Puts the text text at (x, y) on the screen using casio
default font.
Puts the text text at (x, y) on the screen using casio default font with color
color.
*/
void stext(int x, int y, char *text);
void stext(int x, int y, char *text, int color);
/* void slocate(int x, int y, char *text);
@ -61,6 +68,28 @@ Works like the Locate function of CASIO Basic.
void slocate(int x, int y, char *text);
/* void saddlocate(char *text);
Continues the text displayed with slocate, can be used multiple times after a
locate.
*/
void saddlocate(char *text);
/* void sgoto(int x, int y);
Moves the position where you can add text with saddlocate.
*/
void sgoto(int x, int y);
/* void stextmini(int x, int y, char *text);
Works like stext, but here the font is PrintMini and you cannot set the color.
*/
void stextmini(int x, int y, char *text);
/******* KEYBOARD *******/
/* int kisdown(void);
@ -70,12 +99,10 @@ Returns 0 if there is no key down.
*/
int kisdown(void);
/* int kcheck(int key, int type);
/* int kcheck(int key);
/!\ Not working /!\
Checks if the key key is down or not : returns a positive
int if the key is down, or 0 if he's not down.
Checks if the key key is down or not : returns a positive int if the key is
down, or 0 if the key key is not down.
*/
int kcheck(int key);
@ -95,6 +122,42 @@ Put a string of the int n in buffer.
void itoa(int n, char *buffer);
/* void *malloc(size_t __size);
returns a pointer of size __size.
*/
void *malloc(size_t __size);
/* void *calloc(size_t __nmemb, size_t __size);
returns a pointer of size __nmemb * __size.
*/
void *calloc(size_t __nmemb, size_t __size);
/* void *realloc(void *__ptr, size_t __size);
returns __ptr but changes the size of this pointer to __size.
*/
void *realloc(void *__ptr, size_t __size);
/* void free(void *__ptr);
Free __ptr.
*/
void free(void *__ptr);
/* void itohex(char *buffer, int value, int len);
Puts the hex representation of value into buffer. The hex number will have the
size len.
*/
void itohex(char *buffer, int value, int len);
/******* TIME *******/
/* void tsleep_ms(int ms);
@ -112,13 +175,50 @@ int tgetticks(void);
/* int tiselapsed(int start, int ms);
Check if ms where elapsed since start (ticks that you can
get with tgetticks).
Check if ms where elapsed since start (ticks that you can get with tgetticks).
Returns 1 if ms is elapsed and 0 if it is not.
*/
int tiselapsed(int start, int ms);
/* void treset(void);
Resets RTC.
*/
void treset(void);
/* int tinittimer(int ms, void (*callback)(void));
Initializes a timer that call callback each ms miliseconds.
The timers have a precision of 25 ms.
Returns the id of the timer.
*/
int tinittimer(int ms, void (*callback)(void));
/* void tfreetimer(int id);
Free the timer id.
*/
void tfreetimer(int id);
/* void tstarttimer(int id);
Start the timer id.
*/
void tstarttimer(int id);
/* void tstoptimer(int id);
Stop the timer id.
*/
void tstoptimer(int id);
/******* CPU *******/
/* void csleep(void);
@ -129,4 +229,227 @@ Can be used to reduce battery usage of some loops.
void csleep(void);
/******* GUI *******/
enum {GDEC = 0, GHEX};
/* int gnumask(char *message, int maxlen, int type);
Asks for a num that is returned. message contains the message that will be
displayed when asking for the number. maxlen is the maximal length of the input
and type can be GDEC or GHEX. Set type to GDEC if you want to ask for a decimal
number or GHEX if you want that the user inputs a hexadecimal number.
*/
int gnumask(char *message, int maxlen, int type);
/* void gstrask(char *buffer, char *message, int maxlen);
Asks for a str that will be in buffer. message contains the message that will be
displayed when asking for the string and maxlen is the maximal length of the
input.
*/
void gstrask(char *buffer, char *message, int maxlen);
/* void simage(int sx, int sy, int w, int h, unsigned char *img, int mode);
Draws an fkey from a Sprite Coder string that is in img, at fkey position pos.
*/
void gfkeyset(int pos, unsigned char *img);
/* void gmessagebox(int height, char *message);
Draws a message box of height height with that contains message.
*/
void gmessagebox(int height, char *message);
/******* Memory *******/
/* File structure */
typedef struct {
int fd; /* The file descriptor of the file */
int fpos; /* The position in the file (0 after mopen) */
int fwpos; /* The writing position in the file */
int error; /* Positive if there was an error, NULL if there was no one */
int out; /* There was an error if this value is negative */
} MFile;
/* Errors */
enum {
MTOOBIGSIZE = 2,
MODDSIZEWRITE = 1,
MBF_ENTRYNOTFOUND = -1,
MBF_ILLEGALPARAM = -2,
MBF_ILLEGALPATH = -3,
MBF_DEVICEFULL = -4,
MBF_ILLEGALDEVICE = -5,
MBF_ILLEGALFS = -6,
MBF_ILLEGALSYS = -7,
MBF_ACCESSDENIED = -8,
MBF_ALREADYLOCKED = -9,
MBF_ILLEGALTASKID = -10,
MBF_PERMISSIONERROR = -11,
MBF_ENTRYFULL = -12,
MBF_ALREADYEXISTS = -13,
MBF_READONLYFILE = -14,
MBF_ILLEGALFILTER = -15,
MBF_ENUMEND = -16,
MBF_DEVICECHANGED = -17,
MBF_NOTRECORDFILE = -18,
MBF_ILLEGALSEEKPOS = -19,
MBF_ILLEGALBLOCKFILE = -20,
MBF_NOSUCHDEVICE = -21,
MBF_EOF = -22,
MBF_NOTMOUNTDEVICE = -23,
MBF_NOTUNMOUNTDEVICE = -24,
MBF_CANNOTLOCKSYS = -25,
MBF_RECORDNOTFOUND = -26,
MBF_NOTDUALRECORDFILE = -27,
MBF_NOALARMSUPPORT = -28,
MBF_CANNOTADDALARM = -29,
MBF_FILEFINDUSED = -30,
MBF_DEVICEERROR = -31,
MBF_SYSTEMNOTLOCKED = -32,
MBF_DEVICENOTFOUND = -33,
MBF_FILETYPEMISMATCH = -34,
MBF_NOTEMPTY = -35,
MBF_BROKENSYSTEMDATA = -36,
MBF_MEDIANOTREADY = -37,
MBF_TOOMANYALARMS = -38,
MBF_SAMEALARMEXISTS = -39,
MBF_ACCESSSWAPAREA = -40,
MBF_MULTIMEDIACARD = -41,
MBF_COPYPROTECTION = -42,
MBF_ILLEGALFILEDATA = -43
};
/* File types */
enum {
MFILE = 1,
MFOLDER = 5
};
/* Open modes */
enum {
MREAD = 0x01,
MWRITE = 0x02,
MREADW = (MREAD | MWRITE),
MSHARE = 0x80,
MRWS = (MREADW | MSHARE)
};
/* Defines */
#define MRCONTINUE -1 /* Start reading from the current position. */
#define PATHSIZELIMIT 256 /* Max. path size */
/* Prototypes */
/* IMPORTANT NOTES :
- The CASIOWIN/Fugue compatibility is made automatically.
- To see if there is an error, check if the int error in the MFile struct. If
error is not NULL, there was an error. To get the error code just get the
output of the function.
- To get the output of a function, read the int out in the MFile struct.
- Errors are defined later on.
- DO NOT MODIFY fwpos : MODIFING THIS VARIABLE MAY BREAK THINGS !
*/
/* int mfugue(void);
Returns a postive int if the calculator has a fugue filesystem, or 0 if his fs
is CASIOWIN.
*/
int mfugue(void);
/* int mremove(const char *filename);
Removes the file filename. filename is a const char path for UNIX.
If the returned int is negative there was an error (errors are listed above in
an enum).
*/
int mremove(const char *filename);
/* int mcreate(const char *filename, int type, int size);
Creates the file or folder filename with size size. filename is a const char
path for UNIX.
Set type to MFILE if you want to create a file. Please consider that your add-in
may run on a CASIOWIN calculator, so please enter the real size of your file,
and not 0.
But if you want to create a folder, set type to MFOLDER and then you can also
set the size to 0 and I also recommend that because fxlib does that.
Returns a negative int if there was an error.
*/
int mcreate(const char *filename, int type, int size);
/* MFile mopen(const char *filename, int mode);
Opens the file filename with mode mode.
Available modes are :
- MREAD : Opens the file only for reading.
- MWRITE : Opens the file only for writing.
- MREADW : Opens the file for reading and writing.
- MSHARE : (I don't know what it is XD) Opens the file in shared mode.
- MRWS : Opens the file for reading, writing and in shared mode.
As always the filename is for UNIX and is fixed for the calc.
The error, if there was one, is as I described it in "IMPORTANT NOTES" above,
stored in the MFile struct file.
*/
MFile mopen(const char *filename, int mode);
/* void mwrite(MFile *file, const void *data, int size);
Writes size bytes of data to the file at fwpos of MFile struct file that you can
initialise with mopen.
As always, if there was an error, she's stored in MFile.
*/
void mwrite(MFile *file, const void *data, int size);
/* void mread(MFile *file, void *data, int size, int whence);
Read size bytes of the file of the MFile struct file and put them into data. Set
whence to a positive value to set where mread should start reading, or to
MRCONTINUE to continue reading from the current position.
As always, if there was an error, she's stored in MFile.
*/
void mread(MFile *file, void *data, int size, int whence);
/* void mclose(MFile *file);
Close the file MFile.
*/
void mclose(MFile *file);
/* void mseek(MFile *file, int pos);
Jump to the position pos in the file. if the position is invalid, errors may
occur later on. Pass the MFile struct of the file.
*/
void mseek(MFile *file, int pos);
/* void msize(MFile *file);
Puts the size of the file into out of file. Pass the MFile struct of the file.
*/
void msize(MFile *file);
#endif

Binary file not shown.

View File

@ -1,6 +1,16 @@
#include <microfx/microfx.h>
int main(void) {
stext(1, 1, "A Microfx Add-in !");
while(kisdown());
/* Clear the screen */
sclear();
stext(1, 1, "A Microfx Add-in !", SBLACK);
/* Update the screen */
supdate();
/* Waits that the user presses EXIT. */
int key = 0;
while(key != KCEXIT){
key = kgetkey();
}
return 1;
}