Skip to content

Commit

Permalink
Adding functions to libfxcg.
Browse files Browse the repository at this point in the history
  • Loading branch information
AHelper committed Aug 8, 2012
1 parent 9bec2f4 commit dfd8f10
Show file tree
Hide file tree
Showing 16 changed files with 141 additions and 4 deletions.
23 changes: 22 additions & 1 deletion include/fxcg/display.h
Expand Up @@ -42,7 +42,21 @@ enum
TEXT_MODE_AND = 0x21
};

typedef struct
{
unsigned int I1; // unknown changes indicator height, set to 0
unsigned int indicatormaximum; // max logical indicator range
unsigned int indicatorheight; // height of the indicator in units
unsigned int indicatorpos; // indicator position in units of max
unsigned int I5; // unknown, set to 0
unsigned short barleft; // x position of bar
unsigned short bartop; // y position of bar
unsigned short barheight; // height of bar
unsigned short barwidth; // width of bar
} TScrollbar;

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

Change this name. I like fxcg_scrollbar_t, perhaps.

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

scrollbar_t is fine with me. I would stay away with fxcg_* prefixing just as I would like to stay away from T* prefixing.

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

We need to be careful that we don't clutter up the user's namespace, though. Syscalls are fairly recognizable by name due to their rather silly names and capitalization, and the standard library just does its own thing, but 'scrollbar_t' is not at all obvious. The fxcg_ prefix makes the name more obvious, in the same way many shared libraries (libpng, zlib...) do.

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

note that the syscall itself is named 'Scrollbar', so it does make sense to have Scrollbar's struct be scrollbar*. I partly agree on namespace cluttering, but the syscall's name is just asking to interfere :P

Would fxcg_* be applied to all structs in libfxcg then?

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

My gut reaction is "yes", but there may be some cases in there that will force me to backpedal (I don't think there are). I can't think of any other (non-stdlib) API structs that we expose.

Scrollbar is a rather unfortunate name for the syscall, but the capitalization will prevent most conflicts (few C programmers capitalize function names like that).


void Bdisp_AreaClr_DD_x3( void*p1 );
void Bdisp_DDRegisterSelect( int registerno );
void Bdisp_EnableColor( int n );
void Print_OS( unsigned char*msg, int mode, int zero2 );
void Bdisp_PutDisp_DD( void );
Expand All @@ -63,18 +77,25 @@ void MsgBoxPop( void );
void Box2( int, int );
void locate_OS( int X, int y );
void PrintLine( unsigned char*msg, int imax );
void *GetMiniGlyphPtr( unsigned short mb_glyph_no, unsigned short*glyph_info );
void PrintMiniGlyph(int x, int y, void*glyph, int mode_flags, int glyph_width, int, int, int, int, int color, int back_color, int );
void PrintXY_2( int mode, int x, int y, int msgno, int color );
void PrintXY( int x, int y, char*string, int mode, int color );
void PrintMini( int *x, int *y, unsigned char *MB_string, int mode_flags, unsigned int xlimit, int P6, int P7, int color, int back_color, int writeflag, int P11 );
void PrintMiniMini( int *x, int *y, unsigned char *MB_string, int mode1, char color, int mode2 );
void SaveVRAM_1( void );
void LoadVRAM_1( void );
void SetBackGround( int );
// These are needed for current addins and should be in this file
int DefineStatusAreaFlags( int, int, void*, void* );
void DefineStatusMessage( char*msg, short P2, char P3, char P4 );
void DefineStatusMessage( char*msg, short P2, char color, char P4 );
void DisplayStatusArea( void );
void DrawFrame( int color );
void DrawHeaderLine( void );
void EnableStatusArea( int );
void Scrollbar(TScrollbar *scrollbar);
void ProgressBar0(int P1, int P2, int P3, int current, int max);
void ProgressBar2(unsigned char *heading, int current, int max);

// Original Author, Shaun McFall (Merthsoft)
// Used with permission
Expand Down
1 change: 1 addition & 0 deletions include/fxcg/file.h
Expand Up @@ -23,6 +23,7 @@ enum
int Bfile_CloseFile_OS( int HANDLE );
int Bfile_CreateEntry_OS( const unsigned short*filename, int mode, int*size );
int Bfile_DeleteEntry( const unsigned short *filename );
int Bfile_RenameEntry( const unsigned short *oldpath, const unsigned short *newpath );
int Bfile_FindClose( int FindHandle );
int Bfile_FindFirst( const char *pathname, int *FindHandle, char *foundfile, void *fileinfo );
int Bfile_FindFirst_NON_SMEM( const char *pathname, int *FindHandle, char *foundfile, void *fileinfo );
Expand Down
3 changes: 3 additions & 0 deletions include/fxcg/keyboard.h
Expand Up @@ -174,6 +174,9 @@ void PRGM_GetKey_OS( unsigned char*p );
int GetKey(int*key);
int GetKeyWait_OS(int*column, int*row, int type_of_waiting, int timeout_period, int menu, unsigned short*keycode );
int PRGM_GetKey();
void EditMBStringCtrl(unsigned char *MB_string, int posmax, int *start, int *xpos, int *key, int x, int y);
int EditMBStringChar(unsigned char *MB_string, int posmax, int xpos, int char_to_insert);
void DisplayMBString(unsigned char *MB_string, int start, int xpos, int x, int y);

#ifdef __cplusplus
}
Expand Down
61 changes: 61 additions & 0 deletions include/fxcg/misc.h
@@ -0,0 +1,61 @@
#ifdef __cplusplus
extern "C" {
#endif

#ifndef _MISC_H_
#define _MISC_H_

#include <stddef.h>

typedef unsigned short color_t;

int PRGM_GetKey();

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

This is a keyboard function, put it in the right header.


void VRAM_CopySprite(const color_t* data, int x, int y, int width, int height);

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

fxcg/display.h

void VRAM_XORSprite(const color_t* data, int x, int y, int width, int height);

void sys_rand(unsigned seed);

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

If the syscalls actually perform as stdlib functions should, there's on reason to have sys_* aliases. Remove the sys_ prefix where applicable on all of these.

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

Can do.

void sys_srand(unsigned seed);

void *sys_memmove(void *dest, const void *src, size_t n);

void *memsetZero(void *s, size_t n);

int sys_atoi(const char * s);

void *sys_calloc(int elements, int elementSize);

char *sys_strcat(char *dest, const char *src);
char *sys_strchr(const char *s, int c);
int sys_strcmp(const char *s1, const char *s2);
char *sys_strcpy(char *dest, const char *src);
char *sys_strncpy(char *dest, const char *src, size_t n);

#ifdef USE_FXCG_STDLIB

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

This shouldn't be necessary with the unnecessary prefixes removed.


#define atoi sys_atoi
#define rand sys_rand
#define srand sys_rand
#define malloc sys_malloc

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

Exception to the no-prefix rule, since libc will (eventually) extend the system-provided malloc implementation.

#define calloc sys_calloc
#define realloc sys_realloc
#define free sys_free
#define memcmp sys_memcmp
#define memcmp3 sys_memcmp3
#define memcpy sys_memcpy
#define memset sys_memset
#define memmove sys_memmove
#define strlen sys_strlen
#define strcpy sys_strcpy
#define strncpy sys_strncpy
#define strchr sys_strchr
#define strcmp sys_strcmp
#define strcat sys_strcat

#endif

#endif

#ifdef __cplusplus
}
#endif
16 changes: 16 additions & 0 deletions include/fxcg/system.h
@@ -0,0 +1,16 @@
#ifdef __cplusplus
extern "C" {
#endif

// This adds in syscalls for interfacing with the OS

void SetAutoPowerOffTime(int duration); // in minutes

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

Not really happy with this header name. fxcg/power.h, maybe? Same applies to lines 10 and 13.

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

This isn't all about power. I want to also put in other system syscalls, like system settings (the above syscall is related to but doesn't change Setup), addin calling, etc..

The reason why these are in a separate header is because they change settings system-wide. These settings persist for the OS itself, all addins. I don't feel comfortable putting these with the other headers.

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

A fair argument, but I'm still not really pleased with the 'system' name. Maybe 'os.h' since these are knobs in the OS (and not really the system alone)?

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

I see os and system being mostly the same for this case. Just preference. I see the term 'system' used more than 'os' in programming libraries/languages, meaning different things. :-\

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

I'd like to make a distinction here, because our target is so deeply embedded. When targeting an environment that has significant hardware abstraction, "system" makes sense to refer to the software environment. Here, there's an important distinction between functionality provided by the OS and that provided by the system [hardware].

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

:-\ For the Setup changing syscalls, I agree that os.h would be better. The syscalls in it now directly access the hardware, hence system. Should I just group both OS-calls and more direct hardware calls together in os.h?

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

I think it would be cleaner to split them up more, but that's probably not worth adding more files. Just changing this file to be os.h is okay, I guess, since these are interfaces that the OS also exposes to the user.

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

Fine with me.

void SetBacklightDuration(char duration); // in half-minutes

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

fxcg/display.h

Same for line 11.

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

see above


int GetAutoPowerOffTime();
char GetBacklightDuration();

int GetMainBatteryVoltage(int one);
#ifdef __cplusplus
}
#endif
2 changes: 2 additions & 0 deletions include/stdlib.h
Expand Up @@ -20,6 +20,8 @@ long strtol(const char *str, char **str_end, int base);
void qsort(void *base, size_t nel, size_t width, int (*compar)(const void *, const void *));

void exit(int status);
// This belongs here...
void itoa( int value, unsigned char*result );

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

itoa is a non-standard function. I see no reason to support it.

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

It is a syscall, and I didn't see anywhere else to put it. Where would you put it? (I don't want to have an SDK that purposely removes syscalls)

This comment has been minimized.

Copy link
@tari

tari Sep 24, 2012

That's reasonable. Change the comment to indicate that it's nonstandard, but provided by a syscall.

This comment has been minimized.

Copy link
@AHelper

AHelper Sep 24, 2012

Author Owner

Done.


#ifdef __cplusplus
}
Expand Down
5 changes: 3 additions & 2 deletions libc/string.c
Expand Up @@ -60,14 +60,15 @@ void* memmove(void* destination, const void* source, size_t num) {
free(d);
return destination;
}

// Syscall
/*
void *memset(void *dest, int c, unsigned int n) {
char* d = (char*)dest;
while (n-- > 0) { *d++ = (char)c; }
return dest;
}

*/

char *strcat(char *dest, const char *src) {
dest += strlen(dest);
Expand Down
2 changes: 1 addition & 1 deletion libfxcg/misc/keyboard.c
Expand Up @@ -3,5 +3,5 @@
int PRGM_GetKey() {
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return (( buffer[1] - 1) | ( buffer[2] >> 4 ));
return ( ( buffer[1] & 0x0F) *10 + ( ( buffer[2] & 0xF0) >> 4 ));
}
4 changes: 4 additions & 0 deletions libfxcg/syscalls/Bdisp_DDRegisterSelect.S
@@ -0,0 +1,4 @@
#include <asm.h>

SYSCALL(_Bdisp_DDRegisterSelect, 0x01a2)

4 changes: 4 additions & 0 deletions libfxcg/syscalls/Bfile_RenameEntry.S
@@ -0,0 +1,4 @@
#include <asm.h>

SYSCALL(_Bfile_RenameEntry, 0x1DB3)

4 changes: 4 additions & 0 deletions libfxcg/syscalls/GetAutoPowerOffTime.S
@@ -0,0 +1,4 @@
#include <asm.h>

SYSCALL(_GetAutoPowerOffTime, 0x1E91)

4 changes: 4 additions & 0 deletions libfxcg/syscalls/GetBacklightDuration.S
@@ -0,0 +1,4 @@
#include <asm.h>

SYSCALL(_GetBacklightDuration, 0x12D9)

4 changes: 4 additions & 0 deletions libfxcg/syscalls/PrintMiniMini.S
@@ -0,0 +1,4 @@
#include <asm.h>

SYSCALL(_PrintMiniMini, 0x021B)

4 changes: 4 additions & 0 deletions libfxcg/syscalls/ProgressBar2.S
@@ -0,0 +1,4 @@
#include <asm.h>

SYSCALL(_ProgressBar2, 0x1809)

4 changes: 4 additions & 0 deletions libfxcg/syscalls/SetAutoPowerOffTime.S
@@ -0,0 +1,4 @@
#include <asm.h>

SYSCALL(_SetAutoPowerOffTime, 0x1E90)

4 changes: 4 additions & 0 deletions libfxcg/syscalls/SetBacklightDuration.S
@@ -0,0 +1,4 @@
#include <asm.h>

SYSCALL(_SetBacklightDuration, 0x12D8)

0 comments on commit dfd8f10

Please sign in to comment.