--- /dev/null
+/*
+ * Acess2 Test Client
+ */
+#include <acess/sys.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+/**
+ * \fn int main(int argc, char *argv[])
+ * \brief Entrypoint
+ */
+int main(int argc, char *argv[])
+{
+ int con = -1;
+ int len;
+ uint16_t port;
+ uint8_t buf[4] = {10,0,2,1};
+ uint8_t data[4096]; // Packet Data
+
+ con = open("/Devices/ip/1/tcpc", OPENFLAG_READ|OPENFLAG_WRITE);
+ if(con == -1) {
+ fprintf(stderr, "Unable top open TCP client '/Devices/ip/1/tcpc'\n");
+ return -1;
+ }
+
+ port = 80; ioctl(con, 5, &port); // Set Remote Port
+ ioctl(con, 6, buf); // Set remote IP
+ ioctl(con, 7, NULL); // Connect
+
+ #define REQ_STR "GET / HTTP/1.1\r\n"\
+ "Host: prelude\r\n"\
+ "User-Agent: Acess2 TCP Test Client\r\n"\
+ "\r\n"
+
+ write(con, sizeof(REQ_STR)-1, REQ_STR);
+
+ len = read(con, 4096, data);
+ close(con);
+ if( len == -1 ) {
+ printf("Connection closed on us\n");
+ return 0;
+ }
+ if( len != 0 )
+ {
+ printf("Packet Data: (%i bytes)\n", len);
+ printf("%s\n", data);
+ printf("--- EOP ---\n");
+ }
+ return 0;
+}
--- /dev/null
+/*
+ */
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <image.h>
+//#include <image_sif.h>
+
+// === CODE ===
+int SoMain(void)
+{
+ return 0;
+}
+
+/**
+ */
+tImage *Image_SIF_Parse(void *Buffer, size_t Size)
+{
+ uint16_t magic;
+ uint16_t flags;
+ uint16_t w, h;
+ int ofs, i;
+ tImage_SIF *ret;
+ int bRevOrder;
+ int fileOfs = 0;
+ int comp, fmt;
+ int sampleSize = 4;
+
+ // Get magic word and determine byte ordering
+ magic = *(uint16_t*)Buffer+fileOfs; fileOfs += 2;
+ if(magic == 0x51F0)
+ bRevOrder = 0;
+ else if(magic == 0xF051)
+ bRevOrder = 1;
+ else {
+ return NULL;
+ }
+
+ // Read flags
+ flags = *(uint16_t*)Buffer+fileOfs; fileOfs += 2;
+ comp = flags & 7;
+ fmt = (flags >> 3) & 7;
+
+ // Read dimensions
+ w = *(uint16_t*)Buffer+fileOfs; fileOfs += 2;
+ h = *(uint16_t*)Buffer+fileOfs; fileOfs += 2;
+
+
+ // Allocate space
+ ret = calloc(1, sizeof(tImage) + w * h * sampleSize);
+ ret->Width = w;
+ ret->Height = h;
+
+ // Get image format
+ switch(fmt)
+ {
+ case 0: // ARGB
+ ret->Format = IMGFMT_ARGB;
+ sampleSize = 4;
+ break;
+ case 1: // RGB
+ ret->Format = IMGFMT_RGB;
+ sampleSize = 3;
+ break;
+ default:
+ free(ret);
+ return NULL;
+ }
+
+ switch(comp)
+ {
+ // Uncompressed 32-bpp data
+ case 0:
+ if( fileOfs + w*h*sampleSize > Size ) {
+ memcpy(ret->Data, Buffer+fileOfs, Size-fileOfs);
+ }
+ else {
+ memcpy(ret->Data, Buffer+fileOfs, w*h*sampleSize);
+ }
+ return ret;
+
+ // 1.7.n*8 RLE
+ // (1 Flag, 7-bit size, 32-bit value)
+ case 1:
+ ofs = 0;
+ while( ofs < w*h )
+ {
+ uint8_t len;
+ if( fileOfs + 1 > Size ) return ret;
+ len = *(uint8_t*)Buffer+fileOfs; fileOfs += 1;
+ if(len & 0x80) {
+ len &= 0x7F;
+ if( fileOfs + len*sampleSize > Size ) {
+ memcpy(ret->Data + ofs*sampleSize, Buffer+fileOfs, Size-fileOfs);
+ return ret;
+ }
+ else {
+ memcpy(ret->Data + ofs*sampleSize, Buffer+fileOfs, len*sampleSize);
+ }
+ ofs += len;
+ }
+ else {
+ uint8_t tmp[sampleSize];
+
+ if( fileOfs + sampleSize > Size ) return ret;
+
+ for(i=0;i<sampleSize;i++)
+ tmp[i] = *(uint8_t*)Buffer+fileOfs; fileOfs += 1;
+
+ i = 0;
+ while(len--) {
+ for(i=0;i<sampleSize;i++)
+ ret->Data[ofs++] = tmp[i];
+ }
+ }
+ }
+ return ret;
+
+ // Channel 1.7.8 RLE
+ case 3:
+ // Alpha, Red, Green, Blue
+ for( i = 0; i < sampleSize; i++ )
+ {
+ ofs = i;
+ while( ofs < w*h*sampleSize )
+ {
+ uint8_t len, val;
+ if( fileOfs + 1 > Size ) return ret;
+ len = *(uint8_t*)Buffer+fileOfs; fileOfs += 1;
+ if(len & 0x80) {
+ len &= 0x7F;
+ while(len--) {
+ if( fileOfs + 1 > Size ) return ret;
+ val = *(uint8_t*)Buffer+fileOfs; fileOfs += 1;
+ if(i == 0)
+ ret->Data[ofs] = val;
+ else
+ ret->Data[ofs] |= val;
+ ofs += sampleSize;
+ }
+ }
+ else {
+ if( fileOfs + 1 > Size ) return ret;
+ val = *(uint8_t*)Buffer+fileOfs; fileOfs += 1;
+ if(i == 0) {
+ while(len--) {
+ ret->Data[ofs] = val; ofs += sampleSize;
+ }
+ }
+ else {
+ while(len--) {
+ ret->Data[ofs] |= val; ofs += sampleSize;
+ }
+ }
+ }
+ }
+ }
+ return ret;
+
+ default:
+ fprintf(stderr, "Warning: Unknown compression scheme %i for SIF\n", comp);
+ return NULL;
+ }
+}
--- /dev/null
+/*
+ *
+ */
+#ifndef _SPIDERSCRIPT_H_
+#define _SPIDERSCRIPT_H_
+
+#include <stdint.h>
+
+#define ERRPTR ((void*)((intptr_t)0-1))
+
+/**
+ * \brief Opaque script handle
+ */
+typedef struct sSpiderScript tSpiderScript;
+
+/**
+ * \brief Variant type
+ */
+typedef struct sSpiderVariant tSpiderVariant;
+typedef struct sSpiderFunction tSpiderFunction;
+typedef struct sSpiderValue tSpiderValue;
+typedef struct sSpiderObjectDef tSpiderObjectDef;
+typedef struct sSpiderObject tSpiderObject;
+
+
+/**
+ * \brief SpiderScript Variable Datatypes
+ */
+enum eSpiderScript_DataTypes
+{
+ SS_DATATYPE_UNDEF, //!< Undefined
+ SS_DATATYPE_NULL, //!< NULL (Probably will never be used)
+ SS_DATATYPE_DYNAMIC, //!< Dynamically typed variable (will this be used?)
+ SS_DATATYPE_OBJECT, //!< Opaque object reference
+ SS_DATATYPE_ARRAY, //!< Array
+ SS_DATATYPE_INTEGER, //!< Integer (64-bits)
+ SS_DATATYPE_REAL, //!< Real Number (double)
+ SS_DATATYPE_STRING, //!< String
+ NUM_SS_DATATYPES
+};
+
+/**
+ * \brief Variant of SpiderScript
+ */
+struct sSpiderVariant
+{
+ const char *Name; // Just for debug
+
+ int bDyamicTyped;
+
+ int NFunctions; //!< Number of functions
+ tSpiderFunction *Functions; //!< Functions
+
+ int NConstants; //!< Number of constants
+ tSpiderValue *Constants; //!< Number of constants
+};
+
+/**
+ * \brief SpiderScript data object
+ */
+struct sSpiderValue
+{
+ int Type; //!< Variable type
+ int ReferenceCount; //!< Reference count
+
+ union {
+ uint64_t Integer; //!< Integer data
+ double Real; //!< Real Number data
+ /**
+ * \brief String data
+ */
+ struct {
+ int Length; //!< Length
+ char Data[]; //!< Actual string (\a Length bytes)
+ } String;
+ /**
+ * \brief Variable data
+ */
+ struct {
+ int Length; //!< Length of the array
+ tSpiderValue *Items[]; //!< Array elements (\a Length long)
+ } Array;
+
+ tSpiderObject *Object;
+ };
+};
+
+/**
+ * \brief Object Definition
+ *
+ * Internal representation of an arbitary object.
+ */
+struct sSpiderObjectDef
+{
+ /**
+ * \brief Construct an instance of the object
+ * \param NArgs Number of arguments
+ * \param Args Argument count
+ * \return Pointer to an object instance (which must be fully valid)
+ * \retval NULL Invalid parameter (usually, actually just a NULL value)
+ * \retval ERRPTR Invalid parameter count
+ */
+ tSpiderObject *(*Constructor)(int NArgs, tSpiderValue *Args);
+
+ /**
+ * \brief Clean up and destroy the object
+ * \param This Object instace
+ * \note The object pointer (\a This) should be invalidated and freed
+ * by this function.
+ */
+ void (*Destructor)(tSpiderObject *This);
+
+ int NAttributes; //!< Number of attributes
+
+ //! Attribute definitions
+ struct {
+ const char *Name; //!< Attribute Name
+ int bReadOnly; //!< Allow writes to the attribute?
+ } *AttributeDefs;
+
+
+ int NMethods; //!< Number of methods
+ tSpiderFunction *Methods; //!< Method Definitions
+};
+
+/**
+ * \brief Object Instance
+ */
+struct sSpiderObject
+{
+ tSpiderObjectDef *Type; //!< Object Type
+ int NReferences; //!< Number of references
+ void *OpaqueData; //!< Pointer to the end of the \a Attributes array
+ tSpiderValue *Attributes[]; //!< Attribute Array
+};
+
+/**
+ * \brief Represents a function avaliable to a script
+ */
+struct sSpiderFunction
+{
+ /**
+ * \brief Function name
+ */
+ const char *Name;
+ /**
+ * \brief Function handler
+ */
+ tSpiderValue *(*Handler)(tSpiderScript *Script, int nParams, tSpiderValue **Parameters);
+ /**
+ * \brief Argument types
+ *
+ * Zero or -1 terminated array of \a eSpiderScript_DataTypes.
+ * If the final entry is zero, the function has a fixed number of
+ * parameters, if the final entry is -1, the function has a variable
+ * number of arguments.
+ */
+ int *ArgTypes; // Zero (or -1) terminated array of parameter types
+};
+
+
+// === FUNCTIONS ===
+/**
+ * \brief Parse a file into a script
+ * \param Variant Variant structure
+ * \param Filename File to parse
+ * \return Script suitable for execution
+ */
+extern tSpiderScript *SpiderScript_ParseFile(tSpiderVariant *Variant, const char *Filename);
+/**
+ * \brief Execute a method from a script
+ * \param Script Script to run
+ * \param Function Name of function to run ("" for the 'main')
+ * \return Return value
+ */
+extern tSpiderValue *SpiderScript_ExecuteMethod(tSpiderScript *Script,
+ const char *Function,
+ int NArguments, tSpiderValue **Arguments
+ );
+
+/**
+ * \brief Free a script
+ */
+extern void SpiderScript_Free(tSpiderScript *Script);
+
+#endif