Neo TeAm Forum

The 10th. NEO Project for N64 => The 10th. NEO Project for N64 Dev kit. => N64 development section => Topic started by: Conle on January 21, 2010, 11:42:29 PM

Title: N64 Development libraries/docs/code snippets
Post by: Conle on January 21, 2010, 11:42:29 PM
As title suggests , here you can post libraries/tools/code snippets/documents and all these cool things.


Releases

YETI 3D(N64 & 32X):
http://www.neoflash.com/forum/index.php/topic,5962.msg46864.html#msg46864

LIB Utility v1.4 :
http://www.neoflash.com/forum/index.php/topic,5962.msg43599.html#msg43599

LIB IO v1.0 :
http://www.neoflash.com/forum/index.php/topic,5962.msg43638.html#msg43638

Event library v2.1:
http://www.neoflash.com/forum/index.php/topic,5962.msg43639.html#msg43639

Bin2C++
http://www.neoflash.com/forum/index.php/topic,5962.msg43890.html#msg43890

Title: Re: N64 Developement libraries/tools/code snippets
Post by: Conle on January 21, 2010, 11:55:15 PM
Seems like i will the first one who will be contributing to this thread  ^-^


LIB Utility v1.4

What is it:
Its a high level support library which does all the low level C code(such as string handling/parsing/conversions)
easy to use without including a single library.

I made this exclusively for the SuperN64 Plugin and future versions of N64 MENU.
8)

Basic features:
-Does not require any libraries at all.All implementations are written from scratch
-Super portable!
-Powerful string parsing and handling
-Configurable
-Supports all memory related functionality
-Binary utilities(word/dword swapping/ w/dw -> byte conversions)
-Type conversion(Int <-> String Up to BASE_36)
-Contains all parsing-related functions plus exclusive to make parsing
super easy!

Quick example showing some basic functions:
Please study the interface for more

Code: [Select]
   char s[64];
    //UTIL_SetMemorySafe(s,'\0',64);

    //convert string to int and vise versa
    UTIL_IntegerToString(s,128,BASE_10);
    printf("value = %d\n",UTIL_StringToInteger(s));

    //try negative
    UTIL_IntegerToString(s,-128,BASE_10);
    printf("value = %d\n",UTIL_StringToInteger(s));

    printf("length = %d\n",UTIL_StringLengthFastLE32(s));
    /*
        Alternative :
                UTIL_StringLengthFastBE32
                UTIL_StringLength
                UTIL_StringLengthConst
    */

    //Powerful string handling
    char scriptLine[] = {"ConfigOption = 1;\n"};

    UTIL_CopyString(s,scriptLine,"\0\n");
    printf("script = %s\n",s);

    const char* findEQ = UTIL_StringFindAnyCaseConst(s,"=");

    if(findEQ != NULL)//NULL is defined in the library if not already
        printf("Found at %d\n",findEQ - s);

    /*
        Alternative :
                UTIL_StringFindAnyCase
                UTIL_StringFind
                UTIL_StringFindConst
                UTIL_StringFindLastConst
                UTIL_StringFindLast
                UTIL_StringFindLastAnyCase
                UTIL_StringFindLastAnyCaseConst
    */

    //Lets parse the option
    //Replace all spaces/new line
    UTIL_StringReplaceList(s,s," \n\r\t");
    printf("Clean string = %s\n",s);

    char option[1];
    UTIL_SubStringLast(option,s,"=",";");
    //Alternative : UTIL_SubString

    printf("Config option is : %d\n",
    UTIL_StringToInteger(option));


    //Another example : Parse something until a character from the list is found

    const char script[] = {"Line with text.The next is new line\n"};

    UTIL_CopyString(s,script,"\n\r\t\0");//stop at \n , \r , \t , \0
    printf("%s\n",s);
Title: Re: N64 Developement libraries/tools/code snippets
Post by: ChillyWilly on January 22, 2010, 02:23:43 AM
Go ahead and post your other libs here as well. That will fill out the thread a little more.
 ::sm-08.gif::  ::sm-15.gif::
Title: Re: N64 Developement libraries/tools/code snippets
Post by: Conle on January 22, 2010, 04:02:35 AM
Go ahead and post your other libs here as well. That will fill out the thread a little more.
 ::sm-08.gif::  ::sm-15.gif::

Yeah , i will add them all with quick sample code.
Don't forget that im a lazy machine !  ::sm-01::  ::sm-26.gif::
 ::sm-05::
Title: Re: N64 Developement libraries/docs/code snippets
Post by: Conle on January 22, 2010, 07:29:50 PM
LIB IO v1.0

What is it:
Its a simple configurable IO library.

I made this exclusively for the SuperN64 Plugin and future versions of N64 MENU.
Cool

Basic features:
-Very portable
-Does not require 3rd party libraries(Unless you use the standard IO library)

Quick example showing some basic functions:
Please study the interface for more

Code: [Select]
#include "io.h"

IOHandle read;
IOHandle write;

IO_Init();

IO_BindHandle(&read);

if(IO_Open("src.bin","rb"))
Error;

IO_BindHandle(&write);

if(IO_Open("dst.bin","wb"))
Error;

..
{
IO_BindHandle(&read);

IO_Seek(0,IO_SEEK_END);
printf("Length = %d\n",IO_Tell());
IO_Seek(0,IO_SEEK_SET);

while(!IO_Eof())
{
IO_BindHandle(&read);

if(IO_Read(buf,1,128) != 128)
ERROR

IO_BindHandle(&write);

if(IO_Write(buf,1,128) != 128)
ERROR
}
}

IO_BindHandle(&read);
IO_Close();

IO_BindHandle(&write);
IO_Close();

IO_Shutdown();
Title: Re: N64 Developement libraries/docs/code snippets
Post by: Conle on January 22, 2010, 07:42:47 PM
Event Library v2.1

What is it:
Event library is an advanced & extremely fast event  engine which works almost like a virtual machine.
It supports from basic signal messages to full static callbacks.

It was developed mainly to be used with NEO MD Myth extended menu so its
super fast and it can be used with any setup.

Here's a full explanation of how it works(its copy/paste from other thread):

There is a small stack of events.
Events  can be callback or message-type events or anything custom event type.
Because the system supports "static functions" , there is a function rellocator index pointer , that pushes ELT_EXLUSIVE callbacks on the very bottom of the stack.

The stack pointer will not move beyond the static allocator's index , because this section is reserved and "sorts"(not really) the static functions only when they are pushed/popped to have both a stack & a static table in 1 single event table.

When you push an exclusive function , it is a bit expensive call if you have many messages because it involves swapping and some jumps, so push them when you create the interface or when you have to load some content.

Callback Signals/messages/keys can be sent instantly without limits.They get called/demoted instantly & move the stack pointer.

Each event is treated as an object that gets demoted/promoted depends
the case.

The loop is starting from the last -> first object to serve this porpuse.
Each cycle cannot call more than N(->config.Private.maxIterationsPerCycle) instructions.

The last address is moving to the very bottom of the stack pointer on each
"pop" but will never pass the static allocator.

The system does not "call" any function nor using the function stack.
All the critical code is inlined in macros & using the active configuration stack.

Now you're going to ask if its really just an event library.
The answer is no , its just a system that you can "push/pop"(not manually) events while doing some tasks just like a very basic cpu/state machine optimized just for this task.




Basic features:
-Open source
-Does not uses any library at all(it's super portable!)
-Does not use function stack
-Does not use any real function
-Supports effects
-All important code is inlined using macros
-Static function allocator
-Stack based execution of commands
-No sorting or pointless data copying at runtime
-Can be used with platforms with limited hardware
-Supports debug handlers
-Configurable stacks
-Execution sync timer
-Supports custom handlers for input listener/host and timer
-Does not allocate/copy buffers  at runtime.
-Can convert values to proper message handlers
-Supports # amount of arguments per cycle ( # = defined in header )
-Supports # amount of total events per cycle ( # =  can be changed at runtime )
-The code is efficient and will not cause trouble to an existing project
-Efficient message system and even listener that gives you full control of the events
-Uses index ids for direct access to objects
-Fixed loops to active objects range


Quick example showing some basic functions:
Please study the interface for more

Advanced example:
http://www.neoflash.com/forum/index.php/topic,5839.msg41882.html#msg41882

Code: [Select]
/*
Minimal ELIB example
*/

#include "../elib/elib.h"
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>

static struct timeval timerStart;
static struct timeval timerNow;
static ELIB_Configuration config;

enum
{
MY_RUN_COMMAND_THREAD = 255,
MY_MSG_THREAD
};

static ELIB_Ptr getTimeMethod()
{
gettimeofday(&timerNow, NULL);
config.Runtime.SystemTicks = (timerNow.tv_sec-timerStart.tv_sec)*1000+(timerNow.tv_usec-timerStart.tv_usec)/1000;
}

static ELIB_Ptr eventHandler()
{
if(!config.Runtime.BindedEvent)
return;

config.Runtime.Result = ELR_POSITIVE;

switch(config.Runtime.BindedEvent->type)
{
default:
return;

case ELD_MESSAGE:
{
switch(config.Runtime.BindedEvent->callback.message)
{
case MY_MSG_THREAD:
printf("My message proccessed!\n");
return;
}
return;
}

case ELD_INPUT_EVENT:
{
/*Since keys are only executing specific events , we dont need to push keys!*/
/*if(event->key.state == ELK_PRESSED)
{
switch(config.Runtime.BindedEvent->key.code)
{
case ...
}
}*/
return;
}
}
}

static ELIB_Ptr run()
{
printf("Running...\n");

/*spam!*/
ELIB_PushMessage(config,MY_MSG_THREAD);

/*Return positive result*/
config.Runtime.Result = ELR_POSITIVE;
}

int main(int argc, char **argv)
{
config.Public.maxIterationsPerCycle = 8;
config.Public.keyRepeat = 0;
config.Public.messageRepeat = 0;
config.Public.cycleSyncTime = 60;

config.Public.eventCallback = eventHandler;
config.Public.timerCallback = getTimeMethod;
//config.Public.debugCallback = ELIB_NULL;

ELIB_Init(&config);

        //Push exlusive to the static function rellocator
ELIB_PushExclusive(config,MY_RUN_COMMAND_THREAD,run,NULL,NULL);

ELIB_Run();

return 0;
}
Title: Re: N64 Development libraries/docs/code snippets
Post by: Dr.neo on January 22, 2010, 09:59:04 PM
woooo mate, it's terrific indeed!!!  ~sm-31.gif~
Title: Re: N64 Development libraries/docs/code snippets
Post by: Conle on January 23, 2010, 12:37:05 AM
:D
Its fun to write support code! ~sm-37.gif~
I hope to see more coders active in this section ~sm-42.gif~
Title: Re: N64 Development libraries/docs/code snippets
Post by: Conle on January 30, 2010, 03:00:51 AM
LIB_Utility has been updated to v1.3.

Changes:
*Fixed an issue with binary tools
*Added UTIL_StringAppend
*Minor changes
Title: Re: N64 Development libraries/docs/code snippets
Post by: Conle on February 03, 2010, 02:49:14 AM
Bin2C++

What is it:
Its my own implementation of bin2c app that can be found in ChillyWilly's Genesis Linux SDK.

It supports directories and target directories for mass object generation.
Title: Re: N64 Development libraries/docs/code snippets
Post by: Conle on February 04, 2010, 07:59:40 PM
LIB Utility has been updated to v1.4.

Added:
*String find methods in reverse order.

Code: [Select]
const char* UTIL_StringFindReverseConst(const char* base,const char* sub);
const char* UTIL_StringFindReverseAnyCaseConst(const char* base,const char* sub);
char* UTIL_StringFindReverse(char* base,char* sub);
char* UTIL_StringFindReverseAnyCase(char* base,char* sub);

To use them you must provide the last addresses of both base and substring.
Title: Re: N64 Development libraries/docs/code snippets
Post by: the|Gamer on February 14, 2010, 05:43:23 AM
Hi,
heres an other place to get Libs :

http://www.retroactive.be/64dev/index.php?cat=5&sub=1

they are currently working at Racing game (looks nice)
Title: Re: N64 Development libraries/docs/code snippets
Post by: ChillyWilly on July 31, 2010, 03:06:17 AM
Okay, here's a "code snippet" that may help someone - Yeti3D. If you don't know what that is, it was a "simple" 3D game engine written so people could do homebrew akin to Quake on older systems without hardware 3D. All the rendering is in software and was designed around low-end systems. It was quickly eclipsed by hardware 3D, which advanced at a ridiculous rate, but it still might be handy for someone working on older systems.

In that light, I did an N64 port using the libdragon SDK we use around here. You'll also find there's a 32X port in the arc, also by yours truly.  ::sm-29.gif::

The 32X runs, but is too slow as it is - the rendering needs to be converted to assembly. The N64 runs at 15 to 20 FPS with the plain C renderer and high quality walls, so you could get by with using it as-is.

Yeti3D-20100730.zip (http://www.fileden.com/files/2009/2/3/2304902/Yeti3D-20100730.zip)
Title: Re: N64 Development libraries/docs/code snippets
Post by: Conle on July 31, 2010, 03:24:38 AM
Very cool   ;D  :)
Title: Re: N64 Development libraries/docs/code snippets
Post by: ChillyWilly on February 18, 2014, 09:42:39 AM
Fileden went under last year, so all my fileden links are bad. If you need something, PM me and I'll upload it to my MediaFire account. With that in mind, here's the old Yeti3D GPL archive:

Yeti3D-20100730.zip (http://www.mediafire.com/download/5m8yh9clk2zy6o8/Yeti3D-20100730.zip)

Note that I have a much newer Yeti3D Pro build for the N64 here:

Yeti3D_Pro_N64_r1.zip (http://www.mediafire.com/download/qhe1830lpnflgcg/Yeti3D_Pro_N64_r1.zip)

If you're interested in Yeti3D on the N64, I'd suggest the Pro version - you have slopes and lighting and 3D model support. If you check out the 2013 Compo, you'll find my post on it, complete with screenshots of the engine in action.