Initial revision

master
penguinc 2004-11-02 07:18:59 +00:00
commit 1d6e73cbfc
6 changed files with 455 additions and 0 deletions

79
Matrix/matrix.c Executable file
View File

@ -0,0 +1,79 @@
/*
* This program has a somewhat matrix-like effect, press a button to quit
*/
#define OPTIMIZE_ROM_CALLS
#include <tigcclib.h>
#define FONT_WIDTH 6
#define FONT_HEIGHT 8
#define CHARNUM_X 40
#define CHARNUM_Y 16
#define CHARNUM (CHARNUM_X * CHARNUM_Y)
short _ti92plus;
short _ti89;
void DrawLetters (char *ltr, int x, int y ) {
int tmp, temp;
for ( temp = 0; temp < 11; temp++ ) {
for ( tmp = 16; tmp >= 0; tmp-- )
printf_xy ( x * FONT_WIDTH, tmp * FONT_HEIGHT, "%c", random (255) + 1 );
}
for ( tmp = 0; tmp < 16; tmp++ )
printf_xy ( x * FONT_WIDTH, tmp * FONT_HEIGHT, " " );
printf_xy ( x * FONT_WIDTH, y * FONT_HEIGHT, "%s", ltr );
return;
}
void DrawBox ( int top, int bottom, int left, int right ) {
int tmp = 0;
for (tmp = 0; tmp < CHARNUM_X; tmp++ )
printf_xy( tmp * FONT_WIDTH, top * FONT_HEIGHT, "%c", 16);
for (tmp = 0; tmp < CHARNUM_X; tmp++ )
printf_xy( tmp * FONT_WIDTH, bottom * FONT_HEIGHT, "%c", 16);
for (tmp = 0; tmp < CHARNUM_Y; tmp++ )
printf_xy( left * FONT_WIDTH, tmp * FONT_HEIGHT, "%c", 16);
for (tmp = 0; tmp < CHARNUM_Y; tmp++ )
printf_xy( right * FONT_WIDTH, tmp * FONT_HEIGHT, "%c", 16);
return;
}
void _main(void)
{
int x = 1, y = 1, i = 1, foobar[CHARNUM_X][CHARNUM_Y] = {{0}};
LCD_BUFFER buffer;
LCD_save (buffer);
clrscr ();
randomize ();
FontSetSys (F_6x8);
while (!kbhit ())
printf_xy (random(40) * FONT_WIDTH, random(16) * FONT_HEIGHT, "%c", random(255) + 1);
GKeyFlush ();
for ( i=0; i < CHARNUM; i++) {
do {
x = random (CHARNUM_X);
y = random (CHARNUM_Y);
} while (foobar[x][y]);
foobar[x][y] = 1;
printf_xy(x * FONT_WIDTH, y * FONT_HEIGHT, " ");
}
DrawLetters ( "W", 11, 8 );
DrawLetters ( "h", 12, 8 );
DrawLetters ( "a", 13, 8 );
DrawLetters ( "t", 14, 8 );
DrawLetters ( "i", 16, 8 );
DrawLetters ( "s", 17, 8 );
DrawLetters ( "T", 19, 8 );
DrawLetters ( "h", 20, 8 );
DrawLetters ( "e", 21, 8 );
DrawLetters ( "M", 23, 8 );
DrawLetters ( "a", 24, 8 );
DrawLetters ( "t", 25, 8 );
DrawLetters ( "r", 26, 8 );
DrawLetters ( "i", 27, 8 );
DrawLetters ( "x", 28, 8 );
ngetchx ();
DrawBox ( 2, 13, 6, 33 );
ngetchx ();
LCD_restore (buffer);
}

16
Matrix/matrix.tpr Executable file
View File

@ -0,0 +1,16 @@
[Settings]
Archive=0
Pack=0
Packed Variable=
Project Name=matrix
GCC Switches=-Os -Wall -W
Assembler Switches=-g -t
Linker Switches=
GNU Linker Switches=
BSR Patch=1
Debug Info=0
Standard Library=1
Command Line=
[Included Files]
C File 1=matrix.c

53
PascalTriangle/pascal.c Executable file
View File

@ -0,0 +1,53 @@
//mercury@cafes.net
//GNU GPL license. get it? http://gnu.org - got it.
//pAscAl generator version (:^)
#define OPTIMIZE_ROM_CALLS
#include <tigcclib.h>
short _ti89;
short _ti92plus;
void _main(void)
{
unsigned int argtype,argflag=1,qwerty=0,asdf=0,new[18],old[18];
unsigned long iteration = 0;
char buffer[7];
HSym filecheck;
ESI argptr;
FILE *pascal = 0;
SYM_ENTRY* filechecked;
ST_busy (0);
InitArgPtr (argptr);
while ( (argtype = GetArgType(argptr)) != END_TAG){
if ( (argtype == POSINT_TAG) && (argflag == 1)) {
iteration = GetIntArg (argptr);
if (iteration < 18) {argflag = 0;}
}
else SkipArg(argptr);
}
if ( !iteration ) {ST_helpMsg ("Where are my arguments?");return;}
if ( iteration > 18 ) {ST_helpMsg ("Integer too big");return;}
filecheck = SymFind ( $(psstr) );
filechecked = DerefSym(SymFind( $(psstr) ));
if ( filecheck.folder == 0 || filechecked->flags.bits.archived != 1 || filechecked->flags.bits.locked != 1) {
ST_helpMsg ("Creating triangle...");
pascal = fopen ("psstr", "wt");
for (asdf=1; asdf <= iteration; asdf++) {old[asdf]=1;new[asdf]=1;}
fputs ("1\n", pascal);
for (qwerty = 1; qwerty <= iteration; qwerty++ ) {
fputs ("1", pascal);
for (asdf = 2; asdf <= qwerty; asdf++ ) {
new[asdf] = old[asdf]+old[asdf-1];
sprintf (buffer, " %d", new[asdf] );
fputs (buffer, pascal);
}
for (asdf=1; asdf <= iteration; asdf++) {old[asdf] = new[asdf];}
if (qwerty != iteration) {fputs (" 1\n", pascal);}
else {fputs (" 1",pascal);}
}
fclose (pascal);
ST_helpMsg ("Examine text file 'psstr'.");
}
else {
ST_helpMsg ("File 'psstr' exists.");
}
}

17
PascalTriangle/pascal.tpr Executable file
View File

@ -0,0 +1,17 @@
[Settings]
Project Name=pascal
GCC Switches=-O2 -Wall -W
Assembler Switches=-k -g -t
Linker Switches=
BSR Patch=1
Pack=0
Packed Variable=
Archive=0
GNU Linker Switches=
Debug Info=0
Standard Library=1
GNU Assembler Switches=
Command Line=
Post-Build Process=
[Included Files]
C File 1=pascal.c

16
WormHoles/WormHoles.tpr Executable file
View File

@ -0,0 +1,16 @@
[Settings]
Archive=0
Pack=0
Packed Variable=
Project Name=WormHole
GCC Switches=-Os -Wall -W -Wwrite-strings
GNU Assembler Switches=
Assembler Switches=-g -t
GNU Linker Switches=
Linker Switches=
Debug Info=0
Standard Library=1
Command Line=
Post-Build Process=
[Included Files]
C File 1=wormhole.c

274
WormHoles/wormhole.c Executable file
View File

@ -0,0 +1,274 @@
/*
* This program draws a bunch of circles on the screen in a somewhat worm-hole-ish pattern.
*/
#define OPTIMIZE_ROM_CALLS
//#define SAVE_SCREEN
#define TI92P
#ifdef TI92P
#define USE_TI92PLUS
#define SCREEN_WIDTH 240
#define SCREEN_HEIGHT 128
#endif
#include <tigcclib.h>
#define MAX_SIZE 100
#define MAX_WORMHOLES 20
int recurseDistance ( int [], int );
int (*distance)[MAX_WORMHOLES] = NULL;
void _main(void)
{
int startx = 0, starty = 0, endx = 0, endy = 0, result = 0;
int width = 0, height = 0, numwormholes = 0;
int row, col, error = 0;
LCD_BUFFER buffer;
if ( buffer == NULL )
{
ST_helpMsg ( "Not enough memory to save screen" );
return;
}
LCD_save ( buffer );
distance = NULL;
int *xcoords = NULL, *ycoords = NULL;
char params[13], numtxt[3];
HANDLE galaxywin = DialogNewSimple ( 120, 68 );
DialogAddTitle ( galaxywin, "Configuration", BT_OK, BT_NONE );
DialogAddRequest ( galaxywin, 1, 15, "Width: ", 0, 3, 4 );
DialogAddRequest ( galaxywin, 1, 28, "Height: ", 3, 3, 4 );
DialogAddRequest ( galaxywin, 1, 41, "Wormholes: ", 6, 2, 3 );
do {
memset ( params, 0, sizeof ( char ) * 13 );
memset ( numtxt, 0, sizeof ( char ) * 3 );
if ( DialogDo ( galaxywin, CENTER, CENTER, params, NULL ) == KEY_ESC )
{
result = -1;
break;
}
int num1, num2, num3;
memcpy ( numtxt, params, 3 * sizeof ( char ) );
num1 = atoi ( numtxt );
memcpy ( numtxt, params+3, 3 * sizeof ( char ) );
num2 = atoi ( numtxt );
memcpy ( numtxt, params+6, 3 * sizeof ( char ) );
num3 = atoi ( numtxt );
if ( num1 > 0 && num1 <= MAX_SIZE && num2 > 0 && num2 <= MAX_SIZE && num3 >= 0 && num3 <= MAX_WORMHOLES )
{
width = num1;
height = num2;
numwormholes = num3;
result = 1;
}
} while ( result == 0 );
HeapFree ( galaxywin );
if ( result == -1 )
{
error = 1;
}
if ( !error )
{
distance = calloc ( numwormholes + 2, sizeof ( int ) );
xcoords = calloc ( numwormholes * 2, sizeof ( int ) );
ycoords = calloc ( numwormholes * 2, sizeof ( int ) );
if ( distance == NULL || xcoords == NULL || ycoords == NULL )
{
error = 1;
}
}
if ( !error )
{
result = 0;
HANDLE routewin = DialogNewSimple ( 140, 60 );
DialogAddTitle ( routewin, "Route Points", BT_OK, BT_NONE );
DialogAddRequest ( routewin, 1, 15, "Source X Y", 0, 3, 4 );
DialogAddRequest ( routewin, 95, 15, "", 3, 3, 4 );
DialogAddRequest ( routewin, 1, 30, "Dest X Y", 6, 3, 4 );
DialogAddRequest ( routewin, 95, 30, "", 9, 3, 4 );
do {
memset ( params, 0, sizeof ( char ) * 13 );
memset ( numtxt, 0, sizeof ( char ) * 3 );
if ( DialogDo ( routewin, CENTER, CENTER, params, NULL ) == KEY_ESC )
{
result = -1;
break;
}
int coord1, coord2, coord3, coord4;
memcpy ( numtxt, params, 3 * sizeof ( char ) );
coord1 = atoi ( numtxt );
memcpy ( numtxt, params+3, 3 * sizeof ( char ) );
coord2 = atoi ( numtxt );
memcpy ( numtxt, params+6, 3 * sizeof ( char ) );
coord3 = atoi ( numtxt );
memcpy ( numtxt, params+9, 3 * sizeof ( char ) );
coord4 = atoi ( numtxt );
if ( coord1 > 0 && coord1 <= width && coord2 > 0 && coord2 <= height && coord3 > 0 && coord3 <= width && coord4 > 0 && coord4 <= height && !(coord1 == coord3 && coord2 == coord4) )
{
startx = coord1;
starty = coord2;
endx = coord3;
endy = coord4;
result = 1;
}
} while ( result == 0 );
HeapFree ( routewin );
if ( result == -1 )
{
error = 1;
}
}
if ( !error )
{
result = 0;
for ( row = 0; row < numwormholes; row++ )
{
HANDLE sourcewin = DialogNewSimple ( 140, 60 );
char title[13];
sprintf ( title, "Wormhole %d", row + 1 );
DialogAddTitle ( sourcewin, title, BT_OK, BT_NONE );
DialogAddRequest ( sourcewin, 1, 15, "Source X Y", 0, 3, 4 );
DialogAddRequest ( sourcewin, 95, 15, "", 3, 3, 4 );
DialogAddRequest ( sourcewin, 1, 30, "Dest X Y", 6, 3, 4 );
DialogAddRequest ( sourcewin, 95, 30, "", 9, 3, 4 );
do {
memset ( params, 0, sizeof ( char ) * 13 );
memset ( numtxt, 0, sizeof ( char ) * 3 );
if ( DialogDo ( sourcewin, CENTER, CENTER, params, NULL ) == KEY_ESC )
{
result = -1;
break;
}
int coord1, coord2, coord3, coord4;
memcpy ( numtxt, params, 3 * sizeof ( char ) );
coord1 = atoi ( numtxt );
memcpy ( numtxt, params+3, 3 * sizeof ( char ) );
coord2 = atoi ( numtxt );
memcpy ( numtxt, params+6, 3 * sizeof ( char ) );
coord3 = atoi ( numtxt );
memcpy ( numtxt, params+9, 3 * sizeof ( char ) );
coord4 = atoi ( numtxt );
if ( coord1 > 0 && coord1 <= width && coord2 > 0 && coord2 <= height && coord3 > 0 && coord3 <= width && coord4 > 0 && coord4 <= height && !(coord3 == coord1 && coord4 == coord2) )
{
xcoords[row] = coord1;
ycoords[row] = coord2;
xcoords[row + numwormholes] = coord3;
ycoords[row + numwormholes] = coord4;
result = 1;
}
} while ( result == 0 );
HeapFree ( sourcewin );
if ( result == -1 )
{
error = 1;
}
}
}
if ( !error )
{
for ( col = 1; col <= numwormholes; col++ )
{
distance[0][col] = abs ( xcoords[col] - startx ) + abs ( ycoords[col] - starty );
distance[numwormholes + 1][col] = abs ( xcoords[col + numwormholes] - endx ) + abs ( ycoords[col + numwormholes] - endy );
}
distance[numwormholes + 1][0] = abs ( endx - startx ) + abs ( endy - starty );
distance[0][numwormholes + 1] = distance[numwormholes + 1][0];
for ( row = 1; row <= numwormholes; row++ )
{
distance[row][0] = abs ( xcoords[row + numwormholes] - startx ) + abs ( ycoords[row + numwormholes] - starty );
distance[row][numwormholes + 1] = abs ( xcoords[row + numwormholes] - endx ) + abs ( ycoords[row + numwormholes] - endy );
for ( col = 1; col <= numwormholes; col++ )
{
if ( row != col )
{
distance[row][col] = abs ( xcoords[col] - xcoords[row + numwormholes] ) + abs ( ycoords[col] - ycoords[row + numwormholes] );
}
}
}
ClrScr();
for ( row = 0; row < numwormholes + 2; row++ )
{
char asdf[10];
sprintf ( asdf, "%d - %d", row + 1, distance[0][row] );
DrawStr ( 1, row * 8 + 1, asdf, A_NORMAL );
}
ngetchx();
ClrScr();
int radius = 3;
DrawClipEllipse ( (startx * (SCREEN_WIDTH - 10)) / width, (starty * (SCREEN_HEIGHT - 10)) / height, radius, radius, &(SCR_RECT){{0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}}, A_NORMAL );
DrawClipEllipse ( (endx * (SCREEN_WIDTH - 10)) / width, (endy * (SCREEN_HEIGHT - 10)) / height, radius, radius, &(SCR_RECT){{0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}}, A_NORMAL );
for ( row = 0; row < numwormholes; row++ )
{
DrawClipEllipse ( (xcoords[row] * (SCREEN_WIDTH - 10)) / width, (ycoords[row] * (SCREEN_HEIGHT - 10)) / height, radius, radius, &(SCR_RECT){{0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}}, A_NORMAL );
DrawClipEllipse ( (xcoords[row + numwormholes] * (SCREEN_WIDTH - 10)) / width, (ycoords[row + numwormholes] * (SCREEN_HEIGHT - 10)) / height, radius, radius, &(SCR_RECT){{0, 0, SCREEN_WIDTH, SCREEN_HEIGHT}}, A_NORMAL );
DrawLine ( (xcoords[row] * (SCREEN_WIDTH - 10)) / width, (ycoords[row] * (SCREEN_HEIGHT - 10)) / height, (xcoords[row + numwormholes] * (SCREEN_WIDTH - 10)) / width, (ycoords[row + numwormholes] * (SCREEN_HEIGHT - 10)) / height, A_THICK1 );
}
int minresult = 0;
int path[numwormholes + 1];
memset ( path, 0, sizeof ( int ) * (numwormholes + 1) );
for ( row = 1; row < numwormholes + 1; row++ )
{
path[row] = 1;
int rslt = recurseDistance ( path, 1 );
if ( minresult == 0 || rslt < minresult)
{
minresult = rslt;
}
path[row] = 0;
}
sprintf ( params, "Distance: %d", minresult );
DrawStr ( 1, 1, params, A_NORMAL );
ngetchx();
}
if ( distance != NULL )
free ( distance );
if ( xcoords != NULL )
free ( xcoords );
if ( ycoords != NULL )
free ( ycoords );
LCD_restore ( buffer );
return;
}
int recurseDistance ( int path[], int level )
{
if ( sizeof ( path ) / sizeof ( int ) == level )
return distance[level][level + 1];
int min = 0, best = 0, row = 0;
for ( row = 0; row < (signed)(sizeof ( path ) / sizeof ( int )); row++ )
{
if ( !path[row] && row != level )
{
path[row] = 1;
int rslt = recurseDistance ( path, row );
if ( min == 0 || min > rslt )
{
min = rslt;
best = row;
}
path[row] = 0;
}
}
return distance[level][best] + min;
}