GENLIB -The ultimate (?) graph library :)


VERSION 0.99.20



#include "std_disclaimer.h"
"I do not accept responsibility for any effects, adverse or otherwise,
that this code may have on you, your computer, your sanity, your dog,
and anything else that you can think of. Use it at your own risk."



Genlib is an asm dynamic graph 4-gray tiles-oriented library for Ti-89, Ti-92 and Ti-92 + compatible with Ti-Gcc / Assembly programs. It works on both hardware 1 and hardware 2. The compatible roms are for the Ti-92+ (Rom 1.01, 1.05, 2.00, 2.01, 2.03, 2.04 & 2.05) and for the Ti-89 (Rom 1.00, 1.05, 2.00, 2.01, 2.03, 2.04 & 2.05). The Ti-92+ Rom 1.00 isn't compatible at this moment (It could be. It is easy, but I am lazy. So mail me :) ). It works on all roms of Ti-92. (I hope).
It is mainly for 2D-games which looks like the games on the famous snes and genesis. There are a lot of functions. A few of them are useless... But most of them are very usefull and quite (very) fast. Of course, you can do better functions... (If you do such routines, please mail-me, so that I can update genlib). Yon don't need to use graphlib, gray4lib or tigcclib for using the 4 levels of gray.

Index


  

What are the features of GenLib ?

  

To do ?

  

How to use GenLib ?

To use genlib in assembly programs, just copy 'genlib.h' into your include-asembly directory. You can also copy the files 'fixed.h' (Fixed reals macros) and 'struct.h' (Macros to define structures). To use the genlib functions in your program, just add :
 include genlib.h
in the include-section of your program.

To use genlib in your c program in kernel mode, just copy files gen.h and genc.h into the TIGCC include directory (include\c). To use genlib functions, just add the following line:
 #include <genc.h> 
to your sourcecode. That's all, folks.

To use genlib in your c program in nostub mode, just copy files gen.h, genc.h and genn.h into the TIGCC include directory (include\c) and genlib.a to the TIGCC lib directory. To use genlib functions, just add the following line:
 #include <genn.h> 
to your sourcecode. You will have to add 'genlib.a' to your project. It isn't supported yet. Don't forget that it will increase your code size a lot !

  

How to include data ?

You can create your TILES 16x16 with sprmaker (ticalc) and your matrix with PlaneMaker (Time To Team). These programs will create a BIN file. To add them to your asm program, you have to use the INCBIN command :
	Data2	dc.w	0
	Tiles	incbin	"tiles.bin"
	Matrix	incbin	"mat.lvl"
	
That's all. IT is very easy, no ?

To add them to your C program, you can :
  

Fist main example

The best way to understand how to use GenLib is to look at the examples. You can have a look at all the examples included in the archives. They are in general well commented. But let's see the initialisation of a genlib program. It could be complicated since you have to do more stuff than with graphlib. You have to init genlib, allocate DScreens and set the DScreen to their functions.
An assembly (a68k) genlib program looks like :

	include "tios.h"	; Ti-os header file

	xdef	_main       
	xdef	_comment


	xdef _ti92plus   
	xdef _ti89       

	include "genlib.h" 	; Genlib Header files.

_main:				; Program entry point
	jsr	genlib::init   	; Inialisation of genlib

	; Alloc a DScreen on the stack
	genlib::PUSH_DSCREEN d0 
	move.l	d0,DScr1			; Save it.
	jsr	genlib::set_dscreen_function	; D0.l = DScreen's addr
	jsr	genlib::set_dscreen_int		; D0.l = DScreen's addr
	jsr	genlib::cls			; Clear current Dscreen

	; Alloc another Dscreen (Heap)
	jsr	genlib::init_dscreen
	tst.w	d0
	beq.s	\quit
	jsr	genlib::push_hd		; Push the handle
	move.l	a0,DScr2		; Save the other DScreen
	
	bsr	lets_start

	jsr	genlib::free_hd		; Free all the allocated handles 

	genlib::POP_DSCREEN		; Pop Dscreen
	jsr	tios::PortRestore	; If we have called PortSet (Ti-92+ / Ti-89 only !)
	jmp	genlib::quit		; End of program

	; This function will exchange the buffer.
SwapBuffer:
	move.w	ts(pc),d1		; Read ts
	move.l	DScr1(pc,d1.w),d0	; Read a screen
	jsr	genlib::set_dscreen_int	; Set the interrupt to this Dscreen
	eor.w	#4,d1			; Next screen
	move.w	d1,ts			; Save ts
	move.l	DScr2(PC,d1.w),d0	; Read the other screen
	jmp	genlib::set_dscreen_function	; Set the functions to this DScreen

DScr1	dc.l	0		; DScreen 1
DScr2	dc.l	0		; DScreen 2
ts	dc.w	0		; Temps

	; This function will allow a constant Fps to the program (15Hz)
Wait15:
	clr.l	genlib::timer
	cmp.w	#1,genlib::frame_timer
	bls.s	Wait15
	clr.w	genlib::frame_timer
	rts
	
	; This function will allow a constant Fps to the program (30Hz)
Wait30:
	clr.l	genlib::timer
	tst.w	genlib::frame_timer
	beq.s	Wait30
	clr.w	genlib::frame_timer
	rts
	
	; This function waits until you cannot draw without problems.
	; You should add it before your first graphic function.
Ready:	tst.l	genlib::timer
	beq.s	Ready
	rts

lets_start:
	; Main program
	; ....
	
	rts
	
_comment	dc.b "GenLib example",0		
	end
	
It is the basic example. All the other asembly examples will have only a different 'start' function. This example just initializes genlib, and allocates 2 DScreen for Double-buffering.


A C equivalent example looks like :
	#include "doors.h"
	#include "all.h"
	#include "genc.h"

	int	_ti89, _ti92plus;

	DSCREEN	*DScr[2] = {NULL, NULL };
	int	ts = 0;

	// Double-buffern function
	void	SwapBuffer()
	{
		gl_set_dscreen_int(DScr[ts]);
		ts ^= 1;
		gl_set_dscreen_function(DScr(ts]);
	}
	
	// Constant speed 30Hz function
	void	Wait30()
	{
		gl_timer = 0;
		while	(gl_frame_timer < 1);
		gl_frame_timer = 0;
	}

	// Constant speed 15Hz function
	void	Wait15()
	{
		gl_timer = 0;
		while	(gl_frame_timer < 2);
		gl_frame_timer = 0;
	}

	// Ready to print ?
	void	Ready()
	{
		while	(gl_timer == 0);
	}
	
	void	lets_start();
	
	void	_main()
	{
		HANDLE	hd;
		
		gl_init();				// Init genlib

		gl_init_dscreen(&DScr[0], &hd);		// Alloc 1 DScreen
		if (hd == H_NULL) goto exit;		// Quit if error
		gl_push_hd(hd);				// Save the handle

		gl_init_dscreen(&DScr[1], &hd);		// Alloc the 2nd DScreen
		if (hd == 0) goto exit;			// Quit if error
		gl_push_hd(hd);				// Save the handle
	
		gl_set_dscreen_int(DScr[0]);		// Define the printed DScreen
		gl_set_dscreen_function(DScr[0]);	// Define the working DScreen
		gl_cls();				// Clear the working DScreen
		
		lets_start();				// Main program
	exit:
		PortRestore();				// If we have called PortSet
		gl_free_hd();				// Free all the allocated handles
		gl_quit();				// Quit Genlib
	}

	void	lets_start()
	{
		//...
	}
	
This program does exactly the same thing. But it is for Ti-gcc. Moreover, you will need the interface c-genlib library: genClib.

Note:

The C example doesn't allocate the first DScreen on the stack. It is because I don't know how to it without using bad programming syntax.
  

GenLib Structures

It this section of the documentation, I will explain all the different structures you have to know in order to use Genlib. There are : SCREEN, DSCREEN, VSCREEN, PLANE,
  • Palette


  •   

    GenLib Variables

    There are internal variables of genlib you could access and modify. When you could read the variable, it is set with R. When you could write it, it is set with W.

    unsigned long gl_timer;
    genlib::timer

    unsigned short gl_frame_timer;
    genlib::frame_timer

    SCREEN *gl_window;
    genlib::window

    genlib::sprite_tile_adr
    genlib::sprite_scr_x
    genlib::sprite_scr_y

    LINK_DATA gl_link_data;
    genlib::link_data

    char gl_internal_timer;
    genlib::internal_timer

    unsigned short gl_hardware;
    genlib::hardware

    char gl_flipping_tab[256];
    genlib::flipping_tab

    (signed char) gl_sin[256];
    (signed char) gl_cos[256];
    genlib::sin
    genlib::cos

    char gl_version[];
    genlib::version

      

    Functions specifications

    Here are the specifications of the functions. Under Ti-gcc, you don't care about the registers destroyed by the functions. It will be always d0-d2/a0-a1.
      

    Genlib extensions

    There are several extensions of Genlib. The first one and the more important one is GenClib. It is an asm library which provides an efficiency interface between your C program and genlib. Since Genlib uses the register convention for passsing the arguments and the C uses the stack convention for that, I need a library to call Genlib under Tigcc. Nevertheless you could call Genlib without GenClib using the macros (With prefix '_gl_' instead of 'gl_'). But it could create some strange bugs. So don't use the macros in the developement part of your program !

    The other one is GenAlib. It is a library which provides efficiency functions for allocating /freeing memory without using Ti-Os functions. It is really perfect for creating lists or trees.

    There are two other extensions in developement : GenNlib and GenBlib. The first one is an interface for using Genlib under nostub programs. The second one is an interface for using genlib under Ti-Basic programs. Both of them are still under developement.

      

    Bench

    All the tests have been done on a Ti-92+ HW1 with new batteries (alcaline), and with the version 0.99.10 of genlib.
      

    History

      

    Staff

    This documentation was written by Patrick Pelissier (a.k.a. PpHd).
    Genlib for Ti-89, Ti-92 and Ti-92+ is (c) 1999-2000-2001 Time To Team. Don't mix with Genlib for microship.
    If you want to mail us, please prefer French, then English and finally Spanish. We don't understand any other languages.
    Main code : Patrick Pélissier Additionnal code:Olivier Certner

    If you need help, please use the TIGCC Programming Message Board (English speakers) or the TI-Fr Programming Message Board. (French speakers).
    To get the latest release of Genlib, please go to Time To Team home page
      

    Thanks

    David Ellsworth
    Patrick Davidson
    Julien Muchembled
    Jimmy Mardell
    Johan Eilert
    FlashZ & Dark Angel for having done all the tests on HW2