Ok, you want to work with me? That's great!
I continued programming:
#include "stdio.h"
#include "stdarg.h"
#include "fxlib.h"
typedef unsigned char uchar;
typedef unsigned short ushort;
typedef unsigned int uint;
int LongToAscHex(int value, uchar *dest, int digits);
struct TDirectoryItem{uchar name[8];int offset;int length;char flags[4];};
int App_PRGM(void);
int SearchDirectoryItem( uchar*dir, uchar*item, char*flags_0, struct TDirectoryItem*item_ptr, int*data_ptr, int*data_length );
int InputString( uchar*buffer, uchar *heading, int maxlen );
#define TRUE 1
#define FALSE 0
int data_ptr, data_lenght, pos = 0;
#define CHAR 1
#define CMD 2
#define LOOP 3
#define ASC_A 65
#define ASC_Z 90
#define ASC_COMMA 0x2C
#define OC_QT 0x22
#define OC_NL 0x0D
#define OC_CLRTXT 0x18
#define OC_CLRGRPH 0x19
#define OC_LCTE 0x10
#define OC_PXLON 0xAB
#define asctonum(x) (x - 48)
#define INVALID_CHAR -2
#define INVALID_VAL -3
#define SUCCESS 1
void throwerr(char errcode)
{
uint key;
Bdisp_AllClr_VRAM();
PopUpWin(2);
locate(3,3);
Print("Error!");
locate(3,4);
switch(errcode)
{
case INVALID_CHAR:
Print("Invalid character");
break;
case INVALID_VAL:
Print("Invalid parameter");
break;
}
GetKey(&key);
}
void addtostr(char **ptr, uchar lenght, char c)
{
char *temp = (char*)malloc(lenght + 2);
memcpy(temp, *ptr, lenght);
*(temp + lenght) = c;
*(temp + lenght + 1) = 0;
free(*ptr);
*ptr = temp;
}
/*
char arg(uchar count, ...)//This should become a function that reads the arguments of a command. This isn't ready yet!
{
uchar num;
uchar i;
uchar space, *pval;
va_list vl;
va_start(vl, count);
for (i = 0; i<count; i += 2)
{
pval = va_arg(vl, uchar*);
space = va_arg(vl,uchar);
num = asctonum(*(uchar*)(data_ptr + pos++));
if(num <= 9 && num >= 0)
{
*pval += num;
}
else
{
va_end(vl);
return INVALID_CHAR;
}
num = asctonum(*(uchar*)(data_ptr + pos++));
if(num <= 9 && num >= 0)
{
*pval += num * 10;
}
else
{
if(*(uchar*)(data_ptr + pos - 1) != space)
{
va_end(vl);
return INVALID_CHAR;
}
}
}
va_end(vl);
return SUCCESS;
}*/
char getarg(uchar* val1, uchar space1, uchar* val2, uchar space2)//The actual function. It supports 2 Digits, the interface is like this: CommandParam1char1Param2char2
//for example: Locate 10,2,
{
uchar num = asctonum(*(uchar*)(data_ptr + pos++));
*val1 = 0;
*val2 = 0;
if(num <= 9 && num >= 0)
{
*val1 += num;
}
else
{
return INVALID_CHAR;
}
num = asctonum(*(uchar*)(data_ptr + pos++));
if(num <= 9 && num >= 0)
{
*val1 += num * 10;
}
else
{
if(*(uchar*)(data_ptr + pos - 1) != space1)
{
return INVALID_CHAR;
}
}
num = asctonum(*(uchar*)(data_ptr + pos++));
if(num <= 9 && num >= 0)
{
*val2 += num;
}
else
{
return INVALID_CHAR;
}
num = asctonum(*(uchar*)(data_ptr + pos++));
if(num <= 9 && num >= 0)
{
*val2 += num * 10;
}
else
{
if(*(uchar*)(data_ptr + pos - 1) != space2)
{
return INVALID_CHAR;
}
}
return SUCCESS;
}
uchar cursorx = 1, cursory = 1;
void printstr()
{
uchar str = *(uchar*)(data_ptr + pos++);
locate(cursorx, cursory);
cursorx++;
if(cursorx >= 21)
{
cursorx = 1;
cursory++;
if(cursory >= 9)
cursory = 8;
}
PrintC(&str);
while(1)
{
str = *(uchar*)(data_ptr + pos++);
if(str == OC_QT)
{
Bdisp_PutDisp_DD();
return;
}
else
{
locate(cursorx, cursory);
PrintC(&str);
cursorx ++;
if(cursorx >= 21)
{
cursorx = 1;
cursory++;
if(cursory >= 9)
cursory = 8;
}
}
}
}
void basiclocate()
{
char err = getarg(&cursorx, ',', &cursory, ',');
if(err < 0)
{
throwerr(err);
}
}
void basicpxl()
{
uchar x, y;
char err = getarg(&x, ',', &y, OC_NL);
if(x > 127 || y > 63)err = INVALID_VAL;
if(err < 0)
{
throwerr(err);
return;
}
Bdisp_SetPoint_VRAM(x, y, 1);
Bdisp_PutDisp_DD();
}
char nextoc()
{
uchar opcode = *(uchar*)(data_ptr + pos++);
if(pos > data_lenght)
return 0;
if(opcode < 0xF7)//if the opcode is a character
{
switch(opcode)
{
case OC_NL:
return 1;
case OC_QT:
printstr();
return 1;
}
}
opcode = *(uchar*)(data_ptr + pos++);
switch(opcode)//if the opcode is a function with the prefix 0xF7
{
case OC_CLRTXT:
case OC_CLRGRPH:
Bdisp_AllClr_VRAM();
break;
case OC_LCTE:
basiclocate();
break;
case OC_PXLON:
basicpxl();
break;
}
return 1;
}
char loadfile()
{
char program_name[9] = {0};
struct TDirectoryItem item_ptr;
InputString(&program_name, "Open Program : ", 8);
if(SearchDirectoryItem("system", &program_name, &item_ptr.flags[0], &item_ptr, &data_ptr, &data_lenght) != 0)
return -1;
return 1;
}
int AddIn_main(int isAppli, ushort OptionNum)
{
char x = 1, txt[5];
if(loadfile() >= 0)//load the file
{
Bdisp_AllClr_DDVRAM();
while(x != 0)
{
x = nextoc();//loop through data
}
GetKey(&x);//wait
}
App_PRGM();//call PRGM-App
return 0;
}
I send you more infos soon.