- initial import

git-svn-id: http://moon:8086/svn/mips@1 a8ebac50-d88d-4704-bea3-6648445a41b3
This commit is contained in:
2014-07-20 15:01:37 +00:00
commit 26291bca3d
1549 changed files with 3997969 additions and 0 deletions
BIN
View File
Binary file not shown.
+13793
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
Binary file not shown.
+2024
View File
File diff suppressed because it is too large Load Diff
+3656
View File
File diff suppressed because it is too large Load Diff
+291
View File
@@ -0,0 +1,291 @@
/***************************************************************************
- description
-------------------
begin : Sun Mar 12 2000
copyright : (C) 2000 by
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/***************************************************************************
Backpropagation.cpp - description
-------------------
begin : Sun Mar 12 2000
copyright : (C) 2000 by
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/***************************************************************************
Backpropagation.cpp - description
-------------------
begin : Fri Mar 10 2000
copyright : (C) 2000 by
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* <c>1998 Thomas Hasenknopf */
/* Listing zu "Künstliche Intelligenz, Teil 3 */
/* Elektronik, Heft 7/2000 */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#define MAX_NEURON_INPUTS 64
#define MAX_NEURON_PER_LAYER 512
#define MAX_LAYER_PER_NET 16
#define MAX_EPOCH 10000
typedef struct NF{ /* Definition eines Neurons */
int NumberInputs; /* Anzahl der Neuroneneingänge */
double w[MAX_NEURON_INPUTS]; /* Gewichtsfaktoren (max. 16) */
double dw[MAX_NEURON_INPUTS]; /* letzte Gewichtsaenderungen */
double b; /* Schwellwert */
double db; /* letzte Schwellwertaenderung */
double n; /* Neuronenaktivierung */
double a; /* Ausgang des Neurons */
double ebp; /* Rückvermittlungs-Fehler */
double (*F)(double); /* Zeiger auf Aktivierungsfunktion */
double (*Fd)(struct NF*); /* Zeiger auf Ableitungsfunktion */
} Neuron;
typedef struct { /* Definition einer Neuronenschicht */
int NumberNeurons; /* Anzahl der Neuronen in der Schicht */
Neuron N[MAX_NEURON_PER_LAYER]; /* Neuronen der Schicht (max. 16) */
} NeuronLayer;
typedef struct { /* Definition eines Neuronennetzwerks */
int NumberLayers; /* Anzahl der Schichten im Netzwerk */
NeuronLayer L[MAX_LAYER_PER_NET]; /* Schichten im Netzwerk (max. 8) */
} NeuronNet;
typedef struct { /* Trainingsergebnis */
double sse; /* Summierter quadratischer Fehler */
unsigned long epochs; /* Trainingsepochen */
int overflow; /* Ziel des Trainings verfehlt? */
} TrainingResult;
double LinearFunction(double x) {
return x;
}
double LinearDerivative(Neuron *N) {
return 1;
}
double TanhDerivative(Neuron *N) {
return (1.0-pow(N->a,2));
}
/* Initialisieren einer Neuronenschicht mit Zufallszahlen */
void InitLayer(int NumberInputs, int NumberNeurons, NeuronLayer *L,
double(*ActFct)(double), double(*DerivFct)(Neuron*)) {
int i,n;
L->NumberNeurons=NumberNeurons;
srand(1); /* Init. des Generators */
for(n=0;n<NumberNeurons;n++) { /* Init. der Neuronen */
L->N[n].NumberInputs=NumberInputs;
L->N[n].F=ActFct; /* Zuweisung von F */
L->N[n].Fd=DerivFct; /* Zuweisung von F' */
for(i=0;i<NumberInputs;i++) { /* Init. der Gewichte */
L->N[n].w[i]=rand()*2.0/RAND_MAX-1.0;
}
L->N[n].b=rand()*2.0/RAND_MAX-1.0; /* Init. des Schwellwertes */
}
}
Neuron N;
/* Simulation einer Neuronenschicht */
void SimuLayer(double *Input, NeuronLayer *L) {
int m,i;
double n;
for(m=0;m<L->NumberNeurons;m++) {
N=L->N[m];
n=0.0;
for(i=0;i<N.NumberInputs;i++) { /* Summieren d. gewichteten Eingänge */
n+=Input[i]*N.w[i];
}
n+=N.b; /* Summieren der Schwellwerte */
N.n=n; /* Neuronenaktivierung */
N.a=N.F(n); /* Aufruf der Aktivierungsfunktion */
L->N[m]=N;
}
}
void DisplayNeuron(Neuron *N) {
int i;
for(i=0;i<N->NumberInputs;i++) {
printf("w[%d] = %lf\n",i,N->w[i]); /* Ausgabe der Eingangsgewichte */
}
printf("b = %lf\n",N->b); /* Ausgabe des Schwellwertes */
}
void DisplayNet(NeuronNet* Net) {
int i,m;
for(i=0;i<Net->NumberLayers;i++) {
printf("\n>>>> Layer %d <<<<\n",i);
for(m=0;m<Net->L[i].NumberNeurons;m++) {
printf("Neuron %d \n",m);
DisplayNeuron(&Net->L[i].N[m]);
}
}
}
void DisplayTrainingResult(TrainingResult Result) {
printf("\nTraining %ld epochs, SSE=%e:\n",Result.epochs,Result.sse);
if(Result.overflow) {
printf("Training not succeeded. Change training parameters!\n");
}
}
Neuron *pthis;
TrainingResult TrainNet(int NumberTargets, double *Input, double *Target,
NeuronNet *Net, double Lrate, double Mf, double SseMax) {
long layer,epoch,inputs,outputs,set,numSets,numLayers,numNeurons,i,m,n;
double sse,inp[MAX_NEURON_INPUTS],err;
TrainingResult result;
numLayers=Net->NumberLayers;
outputs=Net->L[numLayers-1].NumberNeurons;/* Anz. d. Netzwerkausgaenge*/
numSets=NumberTargets/outputs; /* Trainings-Wertepaare*/
inputs=Net->L[0].N[0].NumberInputs; /* Anz. d. Netzwerkeingaenge*/
/* Backpropagation Algorithmus */
for(epoch=0;epoch<MAX_EPOCH;epoch++)
{
sse=0.0;
printf("Epoch %d\n",epoch);
for(set=0;set<numSets;set++)
{
/* Vorwaertsvermittlung */
for(layer=0;layer<numLayers;layer++)
{
if(layer==0)
{
SimuLayer(&Input[set*inputs],&Net->L[0]);
}
else
{
for(i=0;i<Net->L[layer-1].NumberNeurons;i++)
{
inp[i]= Net->L[layer-1].N[i].a;
}
SimuLayer(&inp[0],&Net->L[layer]);
}
}
/* Fehlerrückvermittlung */
for(layer=numLayers-1;layer>=0;layer--)
{
numNeurons=Net->L[layer].NumberNeurons;
for(m=0;m<numNeurons;m++)
{
pthis=&Net->L[layer].N[m];
if(layer== (numLayers-1))
{ /* Ausgangsschicht */
err=Target[set*outputs+m] - pthis->a;
sse+=pow(err,2);
}
else
{ /* verborgene Schicht */
err=0;
for(n=0;n<Net->L[layer+1].NumberNeurons;n++)
{
err+=Net->L[layer+1].N[n].w[m]*Net->L[layer+1].N[n].ebp;
}
}
pthis->ebp=pthis->Fd(pthis)*err;
}
}
/* Gewichte berechnen */
for(layer=0;layer<numLayers;layer++)
{
numNeurons=Net->L[layer].NumberNeurons;
for(m=0;m<numNeurons;m++)
{
pthis=&Net->L[layer].N[m];
for(i=0;i<pthis->NumberInputs;i++)
{
if(layer==0)
{ /* Eingangsschicht */
pthis->dw[i]=(1.0-Mf)*pthis->ebp*Input[set*inputs+i]*Lrate + Mf*pthis->dw[i];
}
else
{
pthis->dw[i]=(1.0-Mf)*pthis->ebp*Net->L[layer-1].N[i].a*Lrate + Mf*pthis->dw[i];
}
pthis->w[i]+=pthis->dw[i];
}
pthis->db=(1.0-Mf)*pthis->ebp*Lrate + Mf*pthis->db;
pthis->b+=pthis->db;
}
}
}
if(sse<=SseMax) break;
}
result.sse=sse;
result.epochs=epoch;
result.overflow=(epoch==MAX_EPOCH);
return result;
}
double P[]={-1.0,
-0.5,
0.0,
0.2,
0.5,
1.0,
-0.6};
double T[]={ 1.0,
0.5,
0.0,
0.0,
0.3,
0.2,
0.1};
NeuronNet Net;
void main(void) {
TrainingResult result;
unsigned long epochs;
/* Definition eines 3-lagigen Netzwerks mit 1 Eingang und 1 Ausgang,
2 verborgenen nichtlin. Schichten und lin. Ausgangsschicht
*/
Net.NumberLayers=3;
/* 1 Input 4 Neuronen */
InitLayer(1,4,&Net.L[0],tanh,TanhDerivative);
/* 4 Input 2 Neuronen */
InitLayer(4,2,&Net.L[1],tanh,TanhDerivative);
/* 2 Inputs 1 Neuron */
InitLayer(2,1,&Net.L[2],LinearFunction,LinearDerivative);
/* Lrate=0.7, Momentfaktor=0.8, SSE=0.005 */
result=TrainNet(sizeof(T)/sizeof(double),P,T,&Net,0.7,0.8,0.005);
DisplayNet(&Net);
DisplayTrainingResult(result);
}
Binary file not shown.
+87
View File
@@ -0,0 +1,87 @@
/************************************************************************/
/* Ein Programm zur Berechnung der Bessel-Koeffizienten Jn
/* Dateiname : Bessel.cpp
/* Autoren : T. Burr, J. Ahrensfeld
/* Datum : 28.10.1999
/* letzte Änderung : 28.01.2000
/* Version : 1.0
/************************************************************************/
#include "stdio.h"
#include "math.h"
#include "stdlib.h"
#define MAX_SUM 25
#define VERSION "1.0"
/************************************************************************/
/* Funktionsdeklarationen */
/************************************************************************/
// Fakultätsberechnung
double fak (int N)
{
int index;
double erg=1;
for (index = 1; index <= N; index++)
erg = erg * index;
return erg;
}
// Bessel()
// Berechnung von Jn von mfm
double bessel(int n, double mfm)
{
int m;
double Jn=0;
for (m=0; m < MAX_SUM; m++)
{
Jn = Jn + (pow(-1.0,m)/(fak(m)*fak(m+n))*pow(mfm/2.0,(2*m+n)));
}
return Jn;
}
/************************************************************************/
/* Das Hauptprogramm
/************************************************************************/
void main()
{
int N, Nmax;
double erg;
float mfm;
printf("\n\t Besselfunktion Version %s",VERSION);
printf("\n\t ~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("\n\tCopyright by J. Ahrensfeld & T. Burr\n\n");
// ---------------------------------------------------------------------------------
// Benutzereingaben
printf("\nBerechnungen fuer J = 0...");
if(scanf("%d",&Nmax)==0)
exit (-1);
printf("Bitte Modulationsindex eingeben : ");
if(scanf("%f",&mfm)==0)
exit(-1);
printf("\n");
// ---------------------------------------------------------------------------------
// Berechnung
for (N=0; N <= Nmax; N++)
{
erg = bessel(N,(double)mfm);
printf("J(%d) = %10.8f\n",N,erg);
}
printf("FERTIG.\n");
}
/************************************************************************/
+20087
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
+2945
View File
File diff suppressed because it is too large Load Diff
+5372
View File
File diff suppressed because it is too large Load Diff
+123
View File
@@ -0,0 +1,123 @@
/***********************************************************************/
/* Klassen in C++, Beispiel 4
/* 24.07.1999
/***********************************************************************/
#include <iostream>
#include <string>
using namespace std;
/***********************************************************************/
/* Definition der Klasse Rechteck
/* Es hat sich gegenüber Beispiel 3 nichts geändert
/***********************************************************************/
class CRechteck
{
public:
CRechteck (int, int) ; // Konstruktor
void BerechneFlaeche(void);
protected:
int breite;
int hoehe;
};
/***********************************************************************/
/* Definition der Elementfunktionen der Klasse CRechteck
/* Es hat sich gegenüber Beispiel 3 nichts geändert
/***********************************************************************/
// Elementfunktion zur Berechnung der Rechteckflaeche
void CRechteck::BerechneFlaeche(void)
{
int f;
f = breite * hoehe;
cout << endl << "Die Flaeche des Rechtecks betraegt: "
<< f << " qcm." << endl;
}
// Konstruktor Funktionsdeklaration
CRechteck::CRechteck(int b, int h)
{
breite = b;
hoehe = h;
}
/* Ende CRechteck
/***********************************************************************/
/* Definition einer neuen, abgeleiteten Klasse CRechteck2 welche die gleichen
/* Eigenschaften besitzt wie die Basisklasse CRechteck (Vererbung) aber durch
/* die Funktion BerechneUmfang() ergänzt wird
/***********************************************************************/
class CRechteck2 : public CRechteck
{
public:
// Es muß ein neuer Konstruktor her
CRechteck2 (int b, int h);
// Neue Elementfunktion BerechneUmfang();
void BerechneUmfang(void);
};
/***********************************************************************/
/* Definition der zusätzlichen Elementfunktionen
/* innerhalb der Klasse CRechteck2
/***********************************************************************/
// Die Konstruktorfunktion CRechteck2 muß noch von der
// Basisklasse CRechteck abgeleitet werden.
CRechteck2::CRechteck2(int b, int h):CRechteck(b, h)
{ } // {} keine neuen Konstruktorfunktionen hinzugekommen
// Neue Elementfunktion BerechneUmfang();
void CRechteck2::BerechneUmfang(void)
{
int u;
u = 2 * (breite + hoehe);
cout << endl << "Der Umfang des Rechtecks betraegt: "
<< u << " cm." << endl;
}
/* Ende CRechteck2
/***********************************************************************/
/* Hauptprogramm zum Testen der Klasse Rechteck2
/*
/***********************************************************************/
int main (void)
{
// Ein Rechteck-Objekt der neuen abgeleiteten Klasse CRechteck2
// erzeugen
CRechteck2 MeinRechteck(10, 5);
// Fläche des Objekts 'MeinRechteck' berechnen und anzeigen
// Mit Hilfe der bewährten Basis-Elementfunktion BerechneFlaeche()
MeinRechteck.BerechneFlaeche();
// Umfang des Objekts 'MeinRechteck' berechnen und anzeigen
// Mit Hilfe der hinzugekommenen Elementfunktion BerechneUmfang();
MeinRechteck.BerechneUmfang();
return 0;
}
/*
Das war das vierte und letzte Beispiel.
Das hier waren erstmal die Grundlagen zum Verständnis.
Bis hierhin ist ungefähr mein Kenntnisstand.
Ich hoffe ich konnte ein wenig helfen.
Du könntest vielleicht mal weitere Elementfunktionen wie
z.B. setbreite() und sethoehe() hinzufügen,
um ein vorhandenes Rechteck-Objekt zu verändern.
*/
Binary file not shown.
+133
View File
@@ -0,0 +1,133 @@
// Fhourstones 3.0 Board Logic
// (http://www.cwi.nl/~tromp/c4/fhour.html)
//
// implementation of the well-known game
// usually played on a vertical board of 7 columns by 6 rows,
// where 2 players take turns in dropping counters in a column.
// the first player to get four of his counters
// in a horizontal, vertical or diagonal row, wins the game.
// if neither player has won after 42 moves, then the game is drawn.
//
// This software is copyright (c) 1996-2008 by
// John Tromp
// 600 Route 25A
// East Setauket
// NY 11733
// E-mail: john.tromp@gmail.com
//
// This notice must not be removed.
// This software must not be sold for profit.
// You may redistribute if your distributees have the
// same rights and restrictions.
#include <stdio.h>
#include <stdlib.h>
//#define WIDTH 6
//#define HEIGHT 5
#define WIDTH 5
#define HEIGHT 4
// bitmask corresponds to board as follows in 7x6 case:
// . . . . . . . TOP
// 5 12 19 26 33 40 47
// 4 11 18 25 32 39 46
// 3 10 17 24 31 38 45
// 2 9 16 23 30 37 44
// 1 8 15 22 29 36 43
// 0 7 14 21 28 35 42 BOTTOM
#define H1 (HEIGHT+1)
#define H2 (HEIGHT+2)
#define SIZE (HEIGHT*WIDTH)
#define SIZE1 (H1*WIDTH)
#include <sys/types.h>
typedef unsigned long long uint64;
typedef long long int64;
#if (SIZE1<=64)
typedef uint64 bitboard;
#else
typedef __int128_t bitboard;
#endif
#define COL1 (((bitboard)1<<H1)-(bitboard)1)
#if (SIZE1 != 64)
#define ALL1 (((bitboard)1<<SIZE1)-(bitboard)1)
#define BOTTOM (ALL1 / COL1) // has bits i*H1 set
#elif (WIDTH==8 && HEIGHT==7) // one of exceptional cases
#define BOTTOM 0x0101010101010101LL
#else
# add definition for missing (weird) exceptional cases
#endif
#define TOP (BOTTOM << HEIGHT)
bitboard color[2]; // black and white bitboard
int moves[SIZE],nplies;
char height[WIDTH]; // holds bit index of lowest free square
void reset()
{
int i;
nplies = 0;
color[0] = color[1] = 0;
for (i=0; i<WIDTH; i++)
height[i] = (char)(H1*i);
}
bitboard positioncode()
{
return color[nplies&1] + color[0] + color[1] + BOTTOM;
// color[0] + color[1] + BOTTOM forms bitmap of heights
// so that positioncode() is a complete board encoding
}
void printMoves()
{
int i;
for (i=0; i<nplies; i++)
printf("%d", 1+moves[i]);
}
// return whether newboard lacks overflowing column
int islegal(bitboard newboard)
{
return (newboard & TOP) == 0;
}
// return whether columns col has room
int isplayable(int col)
{
return islegal(color[nplies&1] | ((bitboard)1 << height[col]));
}
// return non-zero iff newboard includes a win
bitboard haswon(bitboard newboard)
{
bitboard diag1 = newboard & (newboard>>HEIGHT);
bitboard hori = newboard & (newboard>>H1);
bitboard diag2 = newboard & (newboard>>H2);
bitboard vert = newboard & (newboard>>1);
return ((diag1 & (diag1 >> 2*HEIGHT)) |
(hori & (hori >> 2*H1)) |
(diag2 & (diag2 >> 2*H2)) |
(vert & (vert >> 2)));
}
// return whether newboard is legal and includes a win
int islegalhaswon(bitboard newboard)
{
return islegal(newboard) && haswon(newboard);
}
void backmove()
{
int n;
n = moves[--nplies];
color[nplies&1] ^= (bitboard)1<<--height[n];
}
void makemove(int n)
{
color[nplies&1] ^= (bitboard)1<<height[n]++;
moves[nplies++] = n;
}
+208
View File
@@ -0,0 +1,208 @@
CFLAGS=-msoft-float -O2 -march=r3000 -I. -Wl,-M
LIBS=-lc -lm
AS=mipsel-elf-as
AR=mipsel-elf-ar
CC=mipsel-elf-gcc
LD=mipsel-elf-ld
OBJDUMP=mipsel-elf-objdump
OBJCOPY=mipsel-elf-objcopy
FLASHGEN=flashgen_el
PROG = hello testbench test_irq dhry queens stanford paranoia rmd160_test Bessel whet phrasen dttl richards_benchmark 4win test_hpi r3 test_exception life
all: $(PROG)
libsys: startup.S kernel.S libsys.c xcpt.c irq.c
$(CC) $(CFLAGS) -Os -G 0 -c startup.S -o startup.o
$(CC) $(CFLAGS) -Os -G 0 -c kernel.S -o kernel.o
$(CC) $(CFLAGS) -Os -G 0 -DSTDOUT_FUNCTION=_putchar -c libsys.c -o libsys.o
$(CC) $(CFLAGS) -Os -G 0 -c xcpt.c -o xcpt.o
$(CC) $(CFLAGS) -Os -G 0 -c irq.c -o irq.o
$(AR) -r libsys.a libsys.o xcpt.o irq.o
hello: hello.c
$(CC) $(CFLAGS) -o $@.elf -Os -g hello.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
testbench: testbench.c
$(CC) $(CFLAGS) -o $@.elf -DNOSIGNAL -DBATCHMODE -DNOMAIN -Os -g testbench.c paranoia.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
test_irq: test_irq.c
$(CC) $(CFLAGS) -o $@.elf -Os -g test_irq.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
test_dcache: test_dcache.c
$(CC) $(CFLAGS) -o $@.elf -Os -g test_dcache.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
dhry: dhry_1.c dhry_2.c dhry.h
$(CC) $(CFLAGS) -o $@.elf -O3 -g -DHZ=1000 dhry_1.c dhry_2.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
queens: queens.c
$(CC) $(CFLAGS) -o $@.elf -DUNIX_Old -DHZ=1000 -g queens.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
stanford: stanford.c
$(CC) $(CFLAGS) -o $@.elf -g -DHZ=1000 stanford.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
paranoia: paranoia.c
$(CC) $(CFLAGS) -o $@.elf -DNOSIGNAL -DBATCHMODE -g paranoia.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
rmd160_test: rmd160_test.c rmd160.c rmd160.h
$(CC) $(CFLAGS) -o $@.elf -DNOSIGNAL -DBATCHMODE -g rmd160.c rmd160_test.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
Bessel: Bessel.c
$(CC) $(CFLAGS) -o $@.elf -g Bessel.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
whet: whet.c
$(CC) $(CFLAGS) -o $@.elf -g whet.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
phrasen: phrasen.c
$(CC) $(CFLAGS) -o $@.elf -g phrasen.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
dttl: dttl.c random.c
$(CC) $(CFLAGS) -o $@.elf -g dttl.c random.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
richards_benchmark: richards_benchmark.c
$(CC) $(CFLAGS) -o $@.elf -g richards_benchmark.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
4win: SearchGame.c
$(CC) $(CFLAGS) -o $@.elf -g SearchGame.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
test_hpi: hpi.c test_hpi.c
$(CC) $(CFLAGS) -o $@.elf -g hpi.c test_hpi.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
life: life.c
$(CC) $(CFLAGS) -o $@.elf -g life.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
kml2rte: kml2rte.c
$(CC) $(CFLAGS) -o $@.elf -g kml2rte.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
test_vga: test_vga.c
$(CC) $(CFLAGS) -o $@.elf -g test_vga.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
llloops: llloops.c
$(CC) $(CFLAGS) -o $@.elf -g llloops.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
linpack: linpack.c
$(CC) $(CFLAGS) -o $@.elf -g linpack.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
r3: r3.c
$(CC) $(CFLAGS) -o $@.elf -DJMIPS_VGA -O2 r3.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
test_exception: test_exception.c
$(CC) $(CFLAGS) -o $@.elf -O1 test_exception.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
eldby: eldby.c
$(CC) $(CFLAGS) -o $@.elf eldby.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
gunzip: gunzip.c inflate.c crc32.c
$(CC) $(CFLAGS) -o $@.elf -o $@.elf gunzip.c inflate.c crc32.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
gcctest: hello.c
$(CC) $(CFLAGS) -o $@.elf -o $@.elf hello.c $(LIBS) >$@.map
$(OBJDUMP) -d $@.elf > $@.dis
$(OBJCOPY) $@.elf -O binary $@.bin
$(OBJCOPY) -O srec $@.elf $@.srec
$(FLASHGEN) $@.bin
clean:
rm -rf *.a *.o *.bin *.map *.dis *.srec *.elf $(PROG) > /dev/null
+208
View File
@@ -0,0 +1,208 @@
// This software is copyright (c) 1996-2008 by
// John Tromp
// 600 Route 25A
// East Setauket
// NY 11733
// E-mail: john.tromp@gmail.com
//
// This notice must not be removed.
// This software must not be sold for profit.
// You may redistribute if your distributees have the
// same rights and restrictions.
#include "TransGame.c"
#include <sys/time.h>
#include <sys/resource.h>
#define BOOKPLY 0 // additional plies to be searched full-width
#define REPORTPLY 2 // additional plies on which to report value
unsigned long millisecs()
{
struct timeval t;
gettimeofday(&t, NULL);
return t.tv_sec * 1000 + t.tv_usec / 1000;
}
int history[2][SIZE1];
unsigned long nodes, msecs;
int bookply,reportply;
int min(int x, int y) { return x<y ? x : y; }
int max(int x, int y) { return x>y ? x : y; }
void inithistory()
{
int side,i,h;
for (side=0; side<2; side++)
for (i=0; i<(WIDTH+1)/2; i++)
for (h=0; h<H1/2; h++)
history[side][H1*i+h] = history[side][H1*(WIDTH-1-i)+HEIGHT-1-h] =
history[side][H1*i+HEIGHT-1-h] = history[side][H1*(WIDTH-1-i)+h] =
4+min(3,i) + max(-1,min(3,h)-max(0,3-i)) + min(3,min(i,h)) + min(3,h);
}
int ab(int alpha, int beta)
{
int besti,i,j,l,v,val,score,ttscore;
int winontop,work;
int nav,av[WIDTH];
uint64 poscnt;
bitboard newbrd,other;
int side,otherside;
unsigned int hashindx,hashlock;
nodes++;
if (nplies == SIZE-1) // one move left
return DRAW; // by assumption, player to move can't win
otherside = (side = nplies & 1) ^ 1;
other = color[otherside];
for (i = nav = 0; i < WIDTH; i++) {
newbrd = other | ((bitboard)1 << height[i]); // check opponent move
if (!islegal(newbrd))
continue;
winontop = islegalhaswon(other | ((bitboard)2 << height[i]));
if (haswon(newbrd)) { // immediate threat
if (winontop) // can't stop double threat
return LOSS;
nav = 0; // forced move
av[nav++] = i;
while (++i < WIDTH)
if (islegalhaswon(other | ((bitboard)1 << height[i])))
return LOSS;
break;
}
if (!winontop)
av[nav++] = i;
}
if (nav == 0)
return LOSS;
if (nplies == SIZE-2) // two moves left
return DRAW; // opponent has no win either
if (nav == 1) {
makemove(av[0]);
score = LOSSWIN-ab(LOSSWIN-beta,LOSSWIN-alpha);
backmove();
return score;
}
ttscore = transpose();
if (ttscore != UNKNOWN) {
if (ttscore == DRAWLOSS) {
if ((beta = DRAW) <= alpha)
return ttscore;
} else if (ttscore == DRAWWIN) {
if ((alpha = DRAW) >= beta)
return ttscore;
} else return ttscore; // exact score
}
hashindx = htindex;
hashlock = lock;
poscnt = posed;
besti=0;
score = LOSS;
for (i = 0; i < nav; i++) {
val = history[side][(int)height[av[l = i]]];
for (j = i+1; j < nav; j++) {
v = history[side][(int)height[av[j]]];
if (v > val) {
val = v; l = j;
}
}
for (j = av[l]; l>i; l--)
av[l] = av[l-1];
makemove(av[i] = j);
val = LOSSWIN-ab(LOSSWIN-beta,LOSSWIN-alpha);
backmove();
if (val > score) {
besti = i;
if ((score=val) > alpha && nplies >= bookply && (alpha=val) >= beta) {
if (score == DRAW && i < nav-1)
score = DRAWWIN;
if (besti > 0) {
for (i = 0; i < besti; i++)
history[side][(int)height[av[i]]]--; // punish bad histories
history[side][(int)height[av[besti]]] += besti;
}
break;
}
}
}
if (score == LOSSWIN-ttscore) // combine < and >
score = DRAW;
poscnt = posed - poscnt;
for (work=0; (poscnt>>=1) != 0; work++) ; // work=log #positions stored
transtore(hashindx, hashlock, score, work);
if (nplies <= reportply) {
printMoves();
printf("%c%d\n", "#-<=>+"[score], work);
}
return score;
}
int solve()
{
int i, side = nplies & 1, otherside = side ^ 1, score;
nodes = 0;
msecs = 1L;
if (haswon(color[otherside]))
return LOSS;
for (i = 0; i < WIDTH; i++)
if (islegalhaswon(color[side] | ((bitboard)1 << height[i])))
return WIN;
inithistory();
reportply = nplies + REPORTPLY;
bookply = nplies + BOOKPLY;
msecs = millisecs();
score = ab(LOSS, WIN);
msecs = 1L + millisecs() - msecs; // prevent division by 0
return score;
}
int main()
{
int c, result, work;
uint64 poscnt;
char init_str[] = "45461667\n35333571\n13333111\n\n";
char *pStr = init_str;
if (SIZE1 > 8*sizeof(bitboard)) {
printf("sizeof(bitboard)=%lu bits, but need %d. please redefine.\n", 8*sizeof(bitboard), SIZE1);
exit(0);
}
if (TRANSIZE < ((bitboard)1 << (SIZE1-LOCKSIZE))*31/32) {
printf("transposition table size %d significantly smaller than 2^{(WIDTH*(HEIGHT+1)-LOCKSIZE}=2^{%d-%d}\nplease redefine.\n", TRANSIZE,SIZE1,LOCKSIZE);
exit(0);
}
trans_init();
puts("Fhourstones 3.2 (C)");
printf("Boardsize = %dx%d\n",WIDTH,HEIGHT);
printf("Using %d transposition table entries of size %lu.\n", TRANSIZE, sizeof(hashentry));
for (;;) {
reset();
while ((c = *pStr++) != 0) {
if (c >= '1' && c <= '0'+WIDTH)
makemove(c - '1');
else if (c == '\n')
break;
}
if (c == 0)
break;
printf("\nSolving %d-ply position after ", nplies);
printMoves();
puts(" . . .");
emptyTT();
result = solve(); // expect score << 6 | work
poscnt = posed;
for (work=0; (poscnt>>=1) != 0; work++) ; //work = log of #positions stored
printf("score = %d (%c) work = %d\n",
result, "#-<=>+"[result], work);
printf("%lu pos / %lu msec = %.1f Kpos/sec\n",
nodes, msecs, (double)nodes/msecs);
htstat();
}
return 0;
}
+146
View File
@@ -0,0 +1,146 @@
// Java Fhourstones 3.1 Transposition table logic
// (http://www.cwi.nl/~tromp/c4/fhour.html)
//
// implementation of the well-known game
// usually played on a vertical board of 7 columns by 6 rows,
// where 2 players take turns in dropping counters in a column.
// the first player to get four of his counters
// in a horizontal, vertical or diagonal row, wins the game.
// if neither player has won after 42 moves, then the game is drawn.
//
// This software is copyright (c) 1996-2008 by
// John Tromp
// 600 Route 25A
// East Setauket
// NY 11733
// E-mail: john.tromp@gmail.com
//
// This notice must not be removed.
// This software must not be sold for profit.
// You may redistribute if your distributees have the
// same rights and restrictions.
#include "Game.c"
//#define LOCKSIZE 14
//#define TRANSIZE 4194301
#define LOCKSIZE 20
#define TRANSIZE 31
// should be a prime no less than about 2^{SIZE1-LOCKSIZE}, e.g.
// 4194301,8306069,8388593,15999961,33554393,67108859,134217689,268435399
#define SYMMREC 10 // symmetry normalize first SYMMREC moves
#define UNKNOWN 0
#define LOSS 1
#define DRAWLOSS 2
#define DRAW 3
#define DRAWWIN 4
#define WIN 5
#define LOSSWIN 6
typedef struct {
#if (LOCKSIZE<=32)
unsigned biglock:LOCKSIZE;
unsigned bigwork:6;
unsigned newlock:LOCKSIZE;
#else
uint64 biglock:LOCKSIZE;
unsigned bigwork:6;
uint64 newlock:LOCKSIZE;
#endif
unsigned newscore:3;
unsigned bigscore:3;
} hashentry;
unsigned int htindex, lock;
hashentry *ht;
uint64 posed; // counts transtore calls
void trans_init()
{
ht = (hashentry *)calloc(TRANSIZE, sizeof(hashentry));
if (!ht) {
printf("Failed to allocate %lu bytes\n", TRANSIZE*sizeof(hashentry));
exit(0);
}
}
void emptyTT()
{
int i;
for (i=0; i<TRANSIZE; i++) {
ht[i] = (hashentry){0,0,0,0,0};
}
posed = 0;
}
void hash()
{
bitboard htmp, htemp = positioncode();
if (nplies < SYMMREC) { // try symmetry recognition by reversing columns
bitboard htemp2 = 0;
for (htmp=htemp; htmp!=0; htmp>>=H1)
htemp2 = htemp2<<H1 | (htmp & COL1);
if (htemp2 < htemp)
htemp = htemp2;
}
lock = (unsigned int)(SIZE1>LOCKSIZE ? htemp >> (SIZE1-LOCKSIZE) : htemp);
htindex = (unsigned int)(htemp % TRANSIZE);
}
int transpose()
{
hashentry he;
hash();
he = ht[htindex];
if (he.biglock == lock)
return he.bigscore;
if (he.newlock == lock)
return he.newscore;
return UNKNOWN;
}
void transtore(int x, unsigned int lock, int score, int work)
{
hashentry he;
posed++;
he = ht[x];
if (he.biglock == lock || work >= he.bigwork) {
he.biglock = lock;
he.bigscore = score;
he.bigwork = work;
} else {
he.newlock = lock;
he.newscore = score;
}
ht[x] = he;
}
void htstat() /* some statistics on hash table performance */
{
int total, i;
int typecnt[8]; /* bound type stats */
hashentry he;
for (i=0; i<8; i++)
typecnt[i] = 0;
for (i=0; i<TRANSIZE; i++) {
he = ht[i];
if (he.biglock != 0)
typecnt[he.bigscore]++;
if (he.newlock != 0)
typecnt[he.newscore]++;
}
for (total=0,i=LOSS; i<=WIN; i++)
total += typecnt[i];
if (total > 0) {
printf("- %5.3f < %5.3f = %5.3f > %5.3f + %5.3f\n",
typecnt[LOSS]/(double)total, typecnt[DRAWLOSS]/(double)total,
typecnt[DRAW]/(double)total, typecnt[DRAWWIN]/(double)total,
typecnt[WIN]/(double)total);
}
}
+471
View File
@@ -0,0 +1,471 @@
/** ANSIDEMO.c
*
* ANSIDEMO.C
* (C) Copyright 1985 Don F. Ridgway
* All Rights Reserved.
* This program may be copied for
* personal, non-profit use only.
*
* Don F. Ridgway
* Owner & Chief Programmer/Analyst
* A-1 IBM Programming & Training Service
* Custom Business Programs
* 119 Plantation Court, Suite D
* Temple Terrace, FL 33617-3731
* Ph: (813) 985-3342 (10:00am - 2:00pm EST)
*
* Written, compiled and tested in Microsoft C,
* ver. 2.03, and Lattice C, ver. 2.15, under
* PC-DOS 2.1 on a Compaq w/640Kb RAM & 8087
* using the PC-DOS 3.0 LINK and the TURBO
* Pascal 3.0 screen editor.
*
* (470 lines of code.)
*
* This program demonstrates the features and
* capabilities of my C programming language
* header/module file named "ANSISYS.c", which
* activates and implements the MS/PC-DOS
* "ANSI.SYS" device driver for extended screen
* and keyboard functions and control sequences.
*
* NOTICE: To run this program you MUST have booted
* up with the DOS "ANSI.SYS" file on your boot disk
* with a "CONFIG.SYS" file containing the statement
* "device = ansi.sys" on your boot disk. (Other-
* wise you'll get meaningless numbers and symbols
* across your screen. If so, hit F10 or '0' to exit,
* then boot up properly. See the introduction to
* ANSISYS.C for instructions on how to make the
* CONFIG.SYS file.)
*
* The "ANSISYS.c" file is to be #included in
* your C programs to give them "smart" cursor
* control and eye-catching "turtlegraphics"-type
* screen/graphics display capability.
*
**/
#include <stdio.h>
#include <string.h>
#include "libsys.h" /* this is the file to #include in all */
#include "ansisys.h" /* this is the file to #include in all */
/* your C programs from now on to enable */
main() /* all of the following fabulous screen, */
{ /* cursor and keyboard features */
int dd,key1;
dd=0;
while (key1 != 196 && key1 != 48) /* while key1 not equal to F10 or '0' */
{ /* show main menu */
if (dd==0)
mainmenu();
XKPROMPT(20,29,key1);
dd=0;
switch(key1)
{
case 187: /* F1 key -- Set Screen & Graphics */
case 49: /* '1' key -- just in case some jelly */
/* spilled on the Function keys */
shoscreen();
break;
case 188: /* F2 key -- Set Display & Color */
case 50: /* '2' key */
shodisplay();
break;
case 189: /* F3 key -- Extended Keyboard demo */
case 51: /* '3' key */
xkeyboard();
break;
case 190: /* F4 key -- Arrow Keys demo */
case 52: /* '4' key */
cursarrow();
break;
case 191: /* F5 key -- DRAW function demo */
case 53: /* '5' key */
showdraw();
break;
case 192: /* F6 key -- FILL function demo */
case 54: /* '6' key */
showfill();
break;
case 193: /* F7 key -- WINDOW function demo */
case 55: /* '7' key */
showindow();
break;
case 196: /* F10 key -- to exit program */
case 48: /* '0' key */
break;
default:
dd=1; /* any other key loops back around */
break;
} /* end switch */
} /* end while */
XYPRINTF(23,1,"Goom\nbye!");
BEEP;
exit(0);
} /* end main ANSIDEMO.c */
/*
* ------------------------------------------------------------------------
*/
mainmenu() /* draw Main Menu */
{
CLS; /* clear screen */
DRAW(3,19,23,61,213); /* draw distinctive one/two line border */
HLON; /* turn high-intensity display on */
DRAW(4,21,22,59,178); /* draw artistic inside border to offset */
XYPRINTF(2,31,"A N S I D E M O . c");
XYPRINTF(24,29,"(c) 1985 Don F. Ridgway");
HLOFF; /* turn high-intensity off */
XYPRINTF(6,28,"F1) Set Screen/Graphics");
XYPRINTF(8,28,"F2) Set Display/Color");
XYPRINTF(10,28,"F3) Extended Keyboard Keys");
XYPRINTF(12,28,"F4) Cursor Arrow Keys");
XYPRINTF(14,28,"F5) DRAW Border,Line,Point");
XYPRINTF(16,28,"F6) FILL macro/function");
XYPRINTF(18,28,"F7) WINDOW macro/function");
XYPRINTF(20,28," <---- (F10 to Exit)");
return(0);
} /* return to main program */
/*
* ------------------------------------------------------------------------
*/
shoscreen() /* Set Screen Graphics demo */
{
int c;
CLS; /* clear screen */
while (c!=9) /* while not number 9 */
{
DRAW(1,1,1,80,178);
XCTRPRINTF(5,"This is Set Screen - Set Graphics Demo");
XCTRPRINTF(7,"0=40x25 monochrome,1=40x25 color, 2=80x25 mono, 3=80x25 color, ");
XCTRPRINTF(9,"4=320x200 color, 5=320x200 mono,6=640x200 mono,7=enable word-wrap");
c=' ';
XYPRINTF(12,5,"Enter # of Graphics Mode desired ( 9 => Exit) : ");
scanf("%d",&c);
if (c==9) break; /* if 9 break out of loop */
SETSCREEN(c);
XYPRINTF(15,1,"ABCDEFGHIJKLabcdefghijkl");
XCTRPRINTF(18,"1234567890");
}
return(0);
} /* return to main menu */
/*
* ------------------------------------------------------------------------
*/
shodisplay() /* Set Display/Color attributes demo */
{
int c,d,e;
CLS;
while (c!=9) /* while not number 9 */
{
DRAW(1,1,1,80,178);
XCTRPRINTF(3,"This is Set Display/Color Attributes Demo");
XCTRPRINTF(5,"Set screen display attributes and colors:");
XYPRINTF(7,1," 0 = default, 1 = high-intensity, 4 = underline,");
XYPRINTF(8,1," 5 = blink, 7 = inverse, 8 = invisible (black-on-black),");
XYPRINTF(10,1,"30 = FOREGROUND black, 31 = fore red, 32 = fore green, 33 = fore yellow,");
XYPRINTF(11,1,"34 = fore blue, 35 = fore magenta, 36 = fore cyan, 37 = fore white, ");
XYPRINTF(13,1,"40 = BACKGROUND black, 41 = back red, 42 = back green, 43 = back yellow,");
XYPRINTF(14,1,"44 = back blue, 45 = back magenta, 46 = back white.");
c=d=e=' ';
XYPRINTF(16,1,"Enter three numbers, seperated by SPACES of Display/Color desired");
XYPRINTF(17,1,"putting numbers in right-hand columns first, e.g., 0 0 5 is BLINK");
XYPRINTF(18,1,"(A '9'in any column will Exit) '0 0 0' resets to normal ");
XY(18,58);
scanf("%d %d %d",&c,&d,&e); /* careful! no error-trapping here! */
if (c==9||d==9||e==9) break; /* if any number 9, break out */
SETDISPLAY(c,d,e);
DRAW(18,58,18,80,255);
XCTRPRINTF(20,"Is this what you wanted?");
}
return(0);
} /* return to main menu */
/*
* ------------------------------------------------------------------------
*/
xkeyboard() /* Extended Keyboard demo */
{
int c;
CLS;
HLON;
DRAW(1,1,1,80,178);
HLOFF;
printf("\nHello there, This is Extended Keyboard Demo ('*'= Exit )\n\n\n");
while (c!='*') /* while not '*' */
{
printf("\n ----> Press ANY key on the keyboard: ");
XKREAD(c); /* no-echo read */
printf(" The extended-keyboard-read code = %d",c);
}
return(0);
} /* return to main menu */
/*
* ------------------------------------------------------------------------
*/
cursarrow() /* Display use of cursor arrow keys */
{
int key;
CLS; /* clear screen */
HLON;
DRAW(1,1,1,80,178);
HLOFF;
XCTRPRINTF(3,"Move cursor with ARROW keys, HOME and END ('*'= Exit )");
XY(12,40);
SAVCURS; /* save cursor position (12,40) for later */
while (key != '*') /* while not '*' */
{
XKREAD(key); /* read keystroke, no echo */
switch(key)
{
case 199: /* HOME key */
XY(1,1);
break;
case 200: /* UP arrow key */
printf("\033[1A\b"); /* --> NOTE: When utilizing these macros */
/* CURSUP(1); */ /* from the actual keyboard, as we are doing */
/* in this demo, they need a '\b' backspace */
break; /* because hitting the key moves it forward */
case 203: /* LEFT arrow key */
CURSBCK(2); /* NOTE the (2) per above reason (need two */
break; /* spaces back to overcome the one forward) */
case 205: /* RIGHT arrow */
/* CURSFWD(1);*/ /* NOTE letting it move forward by itself */
break; /* because of the physical keystroke */
case 207: /* END (of screen) key */
XY(24,79);
break;
case 208:
printf("\033[1B\b"); /* DOWN key */
/* CURSDWN(1);*/ /* see NOTE on UP arrow key */
break;
case 42: /* hit '*' to quit program */
break;
default: /* Any other key, while not doing any- */
CURSBCK(1); /* thing, nevertheless needs to be moved */
break; /* back where it was. See NOTE UP arrow */
} /* end switch */
} /* end while */
RECALLCURS; /* recall cursor (to 12,40) */
puts("Press any key to return to Main Menu"); /* then print message */
XKREAD(key);
CLS;
return(0);
} /* end cursarrow demo */
/*
* ------------------------------------------------------------------------
*/
showdraw() /* DRAW(row1,col1,row2,col2,icon) demo */
{
int a,b,c,d,e,key;
char *greet;
greet="Hi there -- I'm Fast-draw Demo!";
CLS;
XCTRPRINTF(2,"Demo of DRAW(row1,col1,row2,col2,icon)");
DRAW(5,9,20,71,205); /* little demo display */
DRAW(6,11,19,69,176);
DRAW(7,12,18,68,177);
DRAW(8,13,17,67,178);
DRAW(9,14,16,66,219);
DRAW(11,20,14,60,196);
HLON;
XCTRPRINTF(12,greet);
DRAW(21,3,21,77,207);
DRAW(22,3,22,77,178);
DRAW(8,4,8,4,14);
DRAW(16,4,16,4,2);
DRAW(8,76,16,76,219);
DRAW(8,75,16,75,182);
HLOFF;
CURSPOSPRTF(24,46,"Press any key to continue ");
XKREAD(key);
key=99;
CLS;
while (key!=81&&key!=113) /* while not Capital Q or lower case q q)uit */
/* NOTE: The possibility of upper or lower case data */
/* entry is handled throughout in this fashion so */
/* this program could more "stand on its own" and */
/* not require the islower() or toupper() functions */
/* to be #included from ctype.h header file */
{
if (key==99||key==67) /* if C)learscreen */
{
XCTRPRINTF(1,"Demonstration of DRAW(row1,col1,row2,col2,icon)");
SETDISPLAY(0,0,1); /* high intensity */
DRAW(3,1,3,80,196); /* border line */
SETDISPLAY(0,0,0);
CURSPOSPRTF(2,3,"-> Enter row1,col1,row2,col2,icon, SPACES delimiting: ");
XCTRPRINTF(4,"Try: 10 25 15 55 205, 5 9 20 71 178, 13 1 13 80 219, 9 24 16 56 213");
};
key=a=b=c=d=e=0; /* initialize */
CURSPOSPRTF(2,59,".. .. .. .. ..."); /* little input guide -- don't have */
CURSPOS(2,59); /* to follow exactly but just space */
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e); /* between entries and hit carriage */
/* return at end. If goof, do ^C */
/* to start all over again. [solly] */
DRAW(a,b,c,d,e); /* Careful! No input error-checking */
CURSPOSPRTF(24,46,"A)nother E)raselast C)LS Q)uit?");
SETDISPLAY(0,0,5);
CPR(24,46,65); /* blink the */
CPR(24,55,69); /* A,E,C and Q */
CPR(24,66,67);
CPR(24,71,81);
CURSPOS(24,79);
SETDISPLAY(0,0,0);
XKREADE(key); /* extended keyboard read */
if (key==97||key==65) /* do A)nother */
DRAW(24,46,24,80,255);
else if (key==99||key==67) /* C)learScreen,restart */
CLS;
else if (key==101||key==69) /* E)rase last figure */
{
DRAW(a,b,c,d,255); /* redraw with blanks */
DRAW(24,46,24,80,255);
} /* Q)uit falls through */
} /* end while */
CLS;
return(0);
} /* end of Showdraw Demo */
/*
* ------------------------------------------------------------------------
*/
showfill() /* Demo of FILL(row1,col1,row2,col2,fill) */
{
int a,b,c,d,e,key;
CLS;
XCTRPRINTF(2,"Demo of FILL(row1,col1,row2,col2,fill)");
FILL(10,25,15,55,219); /* little razzledazzle */
FILL(5,9,20,71,197);
FILL(4,40,24,40,221);
FILL(5,41,20,71,255);
FILL(10,45,15,75,219);
CURSPOSPRTF(24,46,"Press any key to continue ");
XKREAD(key);
key=99;
CLS;
while (key!=81&&key!=113) /* while not Q)uit */
{
if (key==99||key==67) /* if C)learscreen */
{
XCTRPRINTF(1,"Demonstration of FILL(row1,col1,row2,col2,fill)");
SETDISPLAY(0,0,1); /* high intensity */
DRAW(3,1,3,80,196); /* border line */
SETDISPLAY(0,0,0);
CURSPOSPRTF(2,3,"-> Enter row1,col1,row2,col2,fill, SPACES delimiting: ");
XCTRPRINTF(4,"Try: 10 25 15 55 219, 5 9 20 71 197, 4 40 24 40 221, 9 24 16 56 178");
};
key=a=b=c=d=e=0; /* initialize */
CURSPOSPRTF(2,59,".. .. .. .. ..."); /* little input guide */
CURSPOS(2,59);
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
FILL(a,b,c,d,e); /* careful! -- no input */
/* error-checking here! */
CURSPOSPRTF(24,46,"A)nother E)raselast C)LS Q)uit?");
SETDISPLAY(0,0,5);
CPR(24,46,65); /* blink the */
CPR(24,55,69); /* A,E,C and Q */
CPR(24,66,67);
CPR(24,71,81);
CURSPOS(24,79);
SETDISPLAY(0,0,0);
XKREADE(key); /* extended keyboard read */
if (key==97||key==65) /* do A)nother */
XYEOL(24,46);
else if (key==99||key==67) /* C)learScreen,restart */
CLS;
else if (key==101||key==69) /* E)rase last figure */
{
FILL(a,b,c,d,255); /* refill with blanks */
XYEOL(24,46);
} /* Q)uit falls through */
} /* end while */
CLS;
return(0);
} /* end of Showfill Demo */
/*
* ------------------------------------------------------------------------
*/
showindow() /* WINDOW(row1,col1,row2,col2,fill,bord) demo */
{
int a,b,c,d,e,f,key;
CLS; /* clearscreen */
XCTRPRINTF(2,"Demo of WINDOW(row1,col1,row2,col2,fill,bord)");
WINDOW(10,25,15,55,219,205); /* ----------------- */
WINDOW(8,23,19,59,178,213); /* if you got it */
WINDOW(5,65,10,75,219,196); /* ------------- */
WINDOW(15,5,20,15,254,205); /* flaunt it! */
WINDOW(5,1,7,63,14,219); /* ----------------- */
WINDOW(15,70,15,70,7,2);
CURSPOSPRTF(24,46,"Press any key to continue ");
XKREAD(key);
key=99;
CLS;
while (key!=81&&key!=113) /* while not Q)uit do */
{ /* note upper/lowercase */
if (key==99||key==67) /* if screen's cleared */
{ /* redraw header-menu */
XCTRPRINTF(1,"Demonstration of WINDOW(row1,col1,row2,col2,fill,bord)");
SETDISPLAY(0,0,1); /* set high intensity */
DRAW(3,1,3,80,196); /* border line */
SETDISPLAY(0,0,0); /* set display normal */
CURSPOSPRTF(2,1,"-> Enter coordinates & fill & border with SPACE delimit: ");
XCTRPRINTF(4,"Try: 10 25 15 55 219 205, 5 65 10 75 219 196, 9 24 16 56 219 213");
};
key=a=b=c=d=e=f=0; /* initialize */
CURSPOSPRTF(2,59,".. .. .. .. ... ..."); /* little input guide */
CURSPOS(2,59); /* position cursor */
scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f); /* BE CAREFUL!!! -- no */
WINDOW(a,b,c,d,e,f); /* error-checking here! */
CURSPOSPRTF(24,46,"A)nother E)raselast C)LS Q)uit?");
SETDISPLAY(0,0,5); /* set display to blink */
CPR(24,46,65); /* print/blink the 'A' */
CPR(24,55,69); /* blink 'E' */
CPR(24,66,67); /* blink 'C' */
CPR(24,71,81); /* blink 'Q' */
CURSPOS(24,79); /* position cursor */
SETDISPLAY(0,0,0); /* set display normal */
XKREADE(key); /* extended keyboard read */
if (key==97||key==65) /* do A)nother */
XYEOL(24,46); /* erase line 24 menu */
else if (key==101||key==69) /* E)rase last figure */
{
FILL(a,b,c,d,255); /* refill with blanks */
DRAW(24,46,24,80,255); /* erase line 24 menu */
}
else if (key==99||key==67) /* C)learscreen,restart */
CLS; /* Q)uit falls through */
} /* end while */
CLS; /* clear screen so image */
return(0); /* ends with program */
} /* end of WINDOW Demo */
/*
*** the end of ANSIDEMO.c -- hope you liked it! -- C you again sometime? ***
*/
+281
View File
@@ -0,0 +1,281 @@
/** ansisys.c
*
* ANSISYS.C
* (C) Copyright 1985 Don F. Ridgway
* All rights reserved.
* This program may be copied for
* personal, non-profit use only.
*
* This is an original and unique C programming
* language header/function file to #include with
* your C programs to give them "smart" cursor
* control and eye-catching "turtlegraphics"-
* type screen and graphics display qualities.
*
* Programmed by:
* Don F. Ridgway
* Owner & Chief Programmer/Analyst
* A-1 IBM Programming & Training Service
* CUSTOM BUSINESS PROGRAMS
* 119 Plantation Ct., Suite D
* Temple Terrace, FL 33617-3731
* Ph: (813) 985-3342 (10:00 am - 2:00 pm EST)
*
* Written, compiled & tested in Microsoft C,
* ver. 2.03, and Lattice C, ver. 2.15, under
* PC-DOS 2.1 on a Compaq w/640Kb RAM & 8087, using
* the TURBO Pascal 3.0 screen editor. (260+ lines.)
*
* NOTE: To utilize these macros you must have: (1) The
* ANSI.SYS file that came with your PC-DOS or MS-DOS 2.xx
* operating system on your boot disk and, (2) you must boot
* up with a CONFIG.SYS file on that boot disk which
* contains the statement: DEVICE = ANSI.SYS. This loads
* the ANSI.SYS device driver into DOS at bootup time. The
* operating system searches (for) CONFIG.SYS before it looks
* for an AUTOEXEC.BAT file. Please refer to your DOS
* Reference Guide under "ANSI.SYS" and "COPY" for details.
*
* (Simply, at A> prompt on a boot diskette, type:
* COPY CON:CONFIG.SYS<cr>
* DEVICE=ANSI.SYS<cr>
* <F6><cr>
* and then reboot and you're ready to go! Small bother
* for the brilliant performance gained in your C programs--
* just have these two files, ANSI.SYS and CONFIG.SYS, on
* your boot disk whenever you boot up.)
*
* (The diskette these programs are sent to you on is a
* PC-DOS 2.1 boot disk so you may boot up with it and run
* ANSIDEMO.EXE. Note the ANSI.SYS and CONFIG.SYS files.)
*
* This custom C module/header file connects the C programming
* language to the MS-DOS/PC-DOS "ANSI.SYS" device driver
* used to implement extended screen and keyboard functions.
* Like any C program, each of the following macros can itself
* become a building block for a still larger one. Note the
* evolution of WINDOW(row1,col1,row2,col2,fill,border) from
* DRAW(row1,col1,row2,col2,icon) and FILL(row1,col1,row2,col2,fill).
*
* Please refer to the MS-DOS/PC-DOS Reference Manual and the
* ANSI.SYS Device Driver commands for the "original" commands
* and control sequences that are here made into C macros.
*
* Refer to the IBM Technical Reference Manual or to the
* appendix of the BASIC Version 2 Reference for the ASCII
* Character Codes and the Extended Keyboard Function codes.
*
* Run the ANSIDEMO.EXE for a superb demonstration of all these
* powerful macros and C programming tools in action. The
* actual source code is included in ANSIDEMO.C, an excellent
* demonstration/introduction to the C programming language.
*
* Simply #include "ansisys.c" this file in your programs
* to enable the following "smart" screen and cursor commands
* to really supercharge your C programs with professional
* features that are easier, safer and more portable than
* tacked-on assembly languge routines.
*
* Remember that C is "case sensitive" so be sure and
* reference the following macros with CAPITAL LETTERS.
*
**/
#define BEEP printf("\007")
/* 800 Mz tone for 1/4 second -- same as PRINT CHR$(7) */
#define CLEARSCREEN printf("\033[2J")
#define CLS CLEARSCREEN
/* clears the screen and positions cursor at top left corner */
/* "\033" is Octal for "Escape" or ASCII Decimal 27 (CHR$(27)) */
/* "Escape-[" is the lead-in for the ANSI.SYS code routines */
#define CURSPOS(x,y) printf("\033[%u;%uH",(x),(y))
#define XY(x,y) CURSPOS(x,y)
/* positions cursor at x = row, y = column */
#define EOL printf("\033[K")
/* erases to end of line, including cursor position */
/* NOTE: error in DOS documentation has 'K' lower case */
#define XYEOL(x,y) printf("\033[%u;%uH\033[K",(x),(y))
/* positions cursor at x,y then erases to end of line */
#define XYWHERE printf("\033[6n");scanf("%*1c%2d%*1c%2d%*2c",&row,&col)
/* requests cursor position, device driver answers row,col--declare int */
#define CURSUP(x) printf("\033[%uA",(x))
#define CURSDWN(x) printf("\033[%uB",(x))
/* cursor up or down x-many lines */
#define CURSFWD(y) printf("\033[%uC",(y))
#define CURSBCK(y) printf("\033[%uD",(y))
/* cursor forward (right) or backward (left) y-many spaces */
#define SAVCURS printf("\033[s")
#define RECALLCURS printf("\033[u")
/* cursor position is saved for later recall via RECALLCURS */
#define CPR(x,y,z) printf("\033[%u;%uH%c",(x),(y),(z))
#define XYCHAR(x,y,z) CPR(x,y,z)
/* position cursor at x,y and print char z (using ASCII code) */
#define XCTRPRINTF(x,str) printf("\033[%u;%uH%s",(x),((80-(strlen(str)-1))/2),str)
/* on row x, center (and printf) the string str (in double quotes) */
#define CURSPOSPRTF(x,y,str) printf("\033[%u;%uH%s",(x),(y),str)
#define XYPRINTF(x,y,str) CURSPOSPRTF(x,y,str)
/* at position x,y printf the string str (in double quotes) */
#define XKREAD(x) x=readchar()
/* extended code keyboard read, reads function keys, arrow keys, etc. */
#define XKREADE(x) x=readchar()
/* same as XKREAD(), except this one echoes the input on the screen */
#define CHKBRK if (key==196) break
/* if F10 key was pressed, break out of loop */
#define SETSCREEN(a) printf("\033[=%uh",a)
/* set screen graphics mode */
/* 0=40x25 monochrome,1=40x25 color,2=80x25 mono,3=80x25 color, */
/* 4=320x200 color,5=320x200 mono,6=640x200 mono,7=enable word-wrap. */
#define RESETSCREEN(a) printf("\033[=%ul",a)
/* reset screen graphics mode */
/* the attributes are same as SETSCREEN(a) except 7=disables word-wrap */
#define SETDISPLAY(a,b,c) printf("\033[%u;%u;%um",a,b,c)
/* set screen display attributes and colors = (a,b,c) any order: */
/* 0 = default, 1 = high intensity, 4 = underline, */
/* 5=blinking,7=inverse,8=invisible (black-on-black),30=foreground black, */
/* 31=fore red,32=fore green,33=fore yellow,34=fore blue,35=fore magenta, */
/* 36=fore cyan,37=fore white,40=background black,41=back red,42=back green,*/
/* 43=back yellow,44=back blue,45=back magenta,46=back cyan,47=back white. */
#define HLON SETDISPLAY(0,0,1)
/* set high light (high intensity) on */
#define BLON SETDISPLAY(0,0,5)
/* set blinking on */
#define HLOFF SETDISPLAY(0,0,0)
#define BLOFF HLOFF
/* set high intensity, blink (and all other display attributes) to off */
#define PROMPT(x,y,cc) SETDISPLAY(0,0,7);printf("\033[%u;%uH",(x),(y));\
cc=getchar();SETDISPLAY(0,0,0)
/* at position x,y read inverse prompt for input cc */
#define XKPROMPT(x,y,z) HLON;XY((x),(y));printf(" \b");XKREAD(z);HLOFF
/* at position x,y read highlighted prompt for input z */
#define WINDOW(a,b,c,d,e,f) DRAW(a,b,c,d,f);FILL(a+1,b+2,c-1,d-2,e)
/* a rectangle determined by upper left-hand corner coordinates, */
/* row1 = a, col1 = b, and lower right-hand corner coordinates, */
/* row2 = c, col2 = d, is filled with extended graphics character */
/* ASCII decimal code e, and the border is ASCII decimal code f */
#define WINDOW2(a,b,c,d,e,f) DRAW(a,b,c,d,f);DRAW(a+1,b+1,c-1,d-1,255);\
FILL(a+1,b+2,c-1,d-2,e)
/* same as WINDOW(a,b,c,d,e,f) except use this one to overwrite other */
/* drawings because this one fills empty spaces with blanks */
/* ------------------------------------------------------------- */
/** DRAW(row1,col1,row2,col2,icon) */
/* */
/* can be rectangle, vertical line, horizontal line or point! */
/* */
/* row1,col1=Upper Left-hand corner of border */
/* row2,col2=Lower Right-hand corner */
/* icon=ASCII Decimal number of Character want border made of */
/* */
/* (Note: Error-trapping is up to you in calling program, */
/* e.g., [0<=row<=24], [0<=col<=80], graphics mode, */
/* etc.) */
/* */
/* Dbl Lines=205;Sngl Line=196;Dark=176;Medium=177;Light=178 */
/* White=219;Blank=255;Sunshine=15;Music notes=14;Asterisks=42 */
/* Happy Face=1,2;Hearts=3;Diamonds=4;Clubs=5;Spades=6;Beeps=7 */
/* ------------------------------------------------------------- */
/**/
DRAW(row1,col1,row2,col2,icon)
int row1,col1,row2,col2,icon;
{
int hlen,vlen,r,c,hzl,vtl,ulc,llc,urc,lrc;
hlen=col2-col1;
vlen=row2-row1;
if (hlen<0 || vlen<0) BEEP; /* audibly alert possible input error */
if (hlen<=0 && vlen<=0) /* then it's a point or a corner */
{
CPR(row1,col1,icon);
return(0);
}
if (vlen<=0) /* then it's a horizontal line */
{
CURSPOS(row1,col1);
for (c=0;c<=hlen;c++)
printf("%c",icon);
return(0);
}
switch (icon)
{
case 196: /* for Single line border */
case 218:
hzl=196;vtl=179;ulc=218;llc=192;urc=191;lrc=217;
break;
case 201: /* for Double line border */
case 205:
hzl=205;vtl=186;ulc=201;llc=200;urc=187;lrc=188;
break;
case 213: /* for Double top, single side */
hzl=205;vtl=179;ulc=213;llc=212;urc=184;lrc=190;
break;
default:
hzl=vtl=ulc=llc=urc=lrc=icon; /* for same char all around */
}
if (hlen<=0) /* it's a vertical line -- use vtl from above */
{
CURSPOS(row1,col1);
for (r=row1;r<=row2;r++)
CPR(r,col1,vtl);
return(0);
}
/* if it's fallen through this far it's a rectangle */
CURSPOS(row1,col1);
for (c=1;c<=hlen;c++) /* print horizintal icon top row, left to right */
printf("%c",hzl);
CPR(row1,col2,urc); /* print upper right-hand corner */
for (r=row1+1;r<row2;r++) /* print vertical right-hand column, top to bottom */
CPR(r,col2,vtl);
CPR(row2,col2,lrc); /* print lower right-hand corner */
CURSPOS(row2,col2-1);
for (c=1;c<=hlen;c++) /* print horizontal bottom row, right to left */
printf("%c\b\b",hzl); /* one forward, two back (NOTE: this is slow) */
CPR(row2,col1,llc); /* print lower left-hand corner */
for (r=row2-1;r>row1;r--) /* print vertical left-hand column, bottom to top */
CPR(r,col1,vtl);
CPR(row1,col1,ulc); /* print upper left-hand corner to complete object */
return(0);
} /* end DRAW() function */
/* ------------------------------------------------------------- */
/** FILL(row1,col1,row2,col2,icon) */
/* */
/* can be "window," vertical line, horizontal line or point! */
/* */
/* row1,col1=Upper Left-hand corner of area-to-be-filled */
/* row2,col2=Lower Right-hand corner */
/* icon=ASCII Decimal number of Character want area filled with */
/* */
/* (Note: Error-trapping is up to you in calling program, */
/* e.g., [0<=row<=24], [0<=col<=80], graphics mode, */
/* etc. */
/* */
/* Dbl Lines=205;Sngl Line=196;Dark=176;Medium=177;Light=178 */
/* White=219;Blank=255;Sunshine=15;Music notes=14;Asterisks=42 */
/* Happy Face=1,2;Hearts=3;Diamonds=4;Clubs=5;Spades=6;Beeps=7 */
/* ------------------------------------------------------------- */
/**/
FILL(row1,col1,row2,col2,icon)
int row1,col1,row2,col2,icon;
{
int hlen,vlen,r,c;
hlen=col2-col1;
vlen=row2-row1;
if (hlen<0 || vlen<0) BEEP; /* audibly alert possible input error */
for (r=row1;r<=row2;r++)
{
CURSPOS(r,col1);
{
for (c=0;c<=hlen;c++)
printf("%c",icon);
}
}
return(0);
} /* end FILL() function */
+18
View File
@@ -0,0 +1,18 @@
/* WinBond bug report
this is a compile test. At one time static arrays over 500 elements
didn't work. We'll test both global and local array. If it compiles at
all, it it passes.
*/
#include <stdio.h>
static short aa[64][64];
static int bb[500];
main()
{
static short cc[64][64];
static int dd[500];
printf ("large arrays");
fflush(stdout);
}
BIN
View File
Binary file not shown.
+37
View File
@@ -0,0 +1,37 @@
int m = 754974721, N, t[1 << 22], a, *p, i, e = 1 << 22, j, s, b, c, U;
f (d)
{
for (s = 1 << 23; s; s /= 2, d = d * 1LL * d % m)
if (s < N)
for (p = t; p < t + N; p += s)
for (i = s, c = 1; i; i--)
b = *p + p[s], p[s] = (m + *p - p[s]) *
1LL * c % m, *p++ = b % m, c = c * 1LL * d % m;
for (j = 0; i < N - 1;)
{
for (s = N / 2; !((j ^= s) & s); s /= 2);
if (++i < j)
a = t[i], t[i] = t[j], t[j] = a;
}
}
main ()
{
*t = 2;
U = N = 1;
while (e /= 2)
{
N *= 2;
U = U * 1LL * (m + 1) / 2 % m;
f (362);
for (p = t; p < t + N;)
*p++ = (*p * 1LL ** p % m) * U % m;
f (415027540);
for (a = 0, p = t; p < t + N;)
a += (6972593 & e ? 2 : 1) ** p, *p++ = a % 10, a /= 10;
}
while (!*--p);
t[0]--;
while (p >= t)
printf ("%d", *p--);
}
+6
View File
@@ -0,0 +1,6 @@
#!/bin/sh
TARGET=$(basename $1 .c)
dd if=/dev/ttyS2 bs=1 count=4 2>/dev/null && cat $TARGET.srec > /dev/ttyS2
+403
View File
@@ -0,0 +1,403 @@
#include "libsys.h"
#include "cfiflash.h"
typedef struct _ssrec_t
{
UINT32 addr;
UINT32 size;
UINT32 type;
UINT8 *data;
} srec_t;
enum srec_type
{
srec_err, srec_sob, srec_data, srec_rec, srec_eob
};
UINT8 h2i(UINT8 *c)
{
int i;
UINT8 t, b = 0;
for (i=0; i < 2; i++)
{
t = c[i];
if (t >= 'A')
t = t - 'A' + 10;
else
t -= '0';
b = (b << 4) | t;
}
return b;
}
int decode_srec(srec_t *pRec, UINT8 *pBuf, int buflen)
{
UINT8 chksum, byte;
int alen, i;
if (!buflen)
return srec_err;
pRec->type = srec_rec;
alen = 0;
if ((pBuf[1] > '0') && (pBuf[1] < '4'))
{
alen = pBuf[1] - '0' + 1;
pRec->type = srec_data;
}
else if ((pBuf[1] >= '7') && (pBuf[1] <= '9'))
{
alen = 11 - (pBuf[1] - '0');
pRec->type = srec_eob;
}
else if (pBuf[1] == '0')
{
alen = 2;
pRec->type = srec_sob;
}
byte = h2i(&pBuf[2]);
pRec->size = byte;
chksum = byte;
pRec->addr = 0;
for (i=0; i < alen; i++)
{
byte = h2i(&pBuf[4+2*i]);
pRec->addr = pRec->addr << 8 | byte;
chksum += byte;
}
pRec->size -= (alen+1);
pRec->data = (UINT8*) &pBuf[4 + 2*alen];
for (i=0; i < (int)pRec->size; i++)
{
byte = h2i(&pRec->data[2*i]);
pRec->data[i] = byte;
chksum += byte;
}
chksum = ~chksum;
byte = h2i(&pRec->data[2*i]);
if (chksum != byte)
return 0;
return pRec->type;
}
int srec_getline(UINT8 *pLine)
{
char c;
int i = 0;
do
{
c = readchar();
} while ((c != 's') && (c != 'S'));
while(((c != 0x0D) && (c != 0x0A)))
{
pLine[i++] = c;
c = readchar();
};
return i;
}
void Exec_at(void *pEntry)
{
__asm
(
".set noreorder\n"
"mfc0 $26, $12\n" // change exception vector
"li $27, 0xFFBFFFFF\n"
"and $26, $27\n"
"mtc0 $26, $12\n"
"jr $4\n" // jump entry
"rfe\n"
".set reorder\n"
);
}
void PrintCPUinfo(void)
{
int result, rev_id;
char *cpu_type_str[7] = {"invalid", "R2000", "R3000", "R6000", "R4000", "reserved", "R6000A"};
// Print Status register
result = CP0_SR_read();
sputs("Status : ");
print_word(result);
sputs("\n");
// Print Revision
result = CP0_PRID_read();
rev_id = (result >> 8) & 0xFF;
sputs("CPU type: ");
if ((rev_id > 0) && (rev_id < 0x07))
{
sputs(cpu_type_str[rev_id]);
sputs(" Rev.");
rev_id = result & 0xFF;
print_byte((char)rev_id);
}
else
sputs("Unknown");
sputs("\n");
}
#define TEST_SIZE (1024*1024) // bytes
//#define TEST_SIZE (1024) // bytes
#define SDRAM_BASE 0x40000000
#define IMAGE_OFFSET 0x01000000
#define FLASH_OFFSET 0x00700000
int main(int argc, char *argv[])
{
UINT8 buf[256];
srec_t srec;
int result, i;
UINT32 haddr, addr;
flash_t flash;
volatile UINT32 *pReg = (UINT32*)sys_led_port;
volatile UINT32 *pBtn = (UINT32*)sys_gpio0;
volatile UINT8 *pMem;
volatile UINT32 *pROM32;
volatile UINT32 *pMem32;
volatile UINT32 *pFlash = (UINT32*)sys_flash_io;
volatile UINT32 *pUSB = (UINT32*)sys_usb_data;
volatile UINT8 *ram8 = (UINT8*)SDRAM_BASE;
volatile UINT16 *ram16 = (UINT16*)SDRAM_BASE;
volatile UINT32 *ram32 = (UINT32*)SDRAM_BASE;
*pReg = 0;
haddr = 0;
/*
__asm __volatile
(
".set noreorder\n"
"li $a0, 0xA0020000\n"
"li $t0, 0x12345678\n"
"li $t1, 0x5555AAAA\n"
"sw $t0, 0($a0)\n"
// "nop\n"
"sw $t1, 4($a0)\n"
// "nop\n"
"lw $v0, 0($a0)\n"
// "nop\n"
"lw $v0, 4($a0)\n"
// "nop\n"
"sw $t0, 0($a0)\n"
// "nop\n"
"lw $v0, 4($a0)\n"
// "nop\n"
"sw $t1, 4($a0)\n"
// "nop\n"
"lw $v0, 0($a0)\n"
".set reorder\n"
);
__asm __volatile
(
".set noreorder\n"
"lui $v1, 0xA002\n"
"lui $v0,0x70\n"
"ori $v0,$v0,0x70\n"
"sw $v0,0($v1)\n"
"lui $a0,0x4002\n"
"lw $a1,0($v1)\n"
"lw $ra,12($sp)\n"
"lw $s1,8($sp)\n"
"lw $s0,4($sp)\n"
".set reorder\n"
);
*/
// PrintCPUinfo();
/*
*(pFlash+0) = 0x12345678;
*(pFlash+1) = 0xAAAA5555;
*(pFlash+2) = 0xFFFF0000;
*(pFlash+3) = 0x0000FFFF;
*pReg = *(pFlash+0);
*pReg = *(pFlash+1);
*pReg = *(pFlash+2);
*pReg = *(pFlash+3);
*(pUSB+0) = 0x12345678;
*(pUSB+1) = 0xAAAA5555;
*(pUSB+2) = 0xFFFF0000;
*(pUSB+3) = 0x0000FFFF;
*pReg = *(pUSB+0);
*pReg = *(pUSB+1);
*pReg = *(pUSB+2);
*pReg = *(pUSB+3);
sputs("BOOT ");
pMem32 = (UINT32*)0x40000000;
pROM32 = (UINT32*)0x00000000;
for (i=0; i < 0x3500; i+=4)
*pMem32++ = *pROM32++;
Exec_at((void*)0x40000000);
// Memtest BEGIN
sputs("SDRAM Memory Test\r\n");
sputs("Write (8-Bit access)...");
for (i=0; i < TEST_SIZE; i++)
ram8[i] = (UINT8)i;
sputs("done\r\n");
sputs("Verify (8-Bit access)...");
for (i=TEST_SIZE-1; i >= 0; i--)
if (ram8[i] != (UINT8)i)
break;
i++;
if (i)
sputs("failed\r\n");
else
sputs("passed\r\n");
sputs("Write (16-Bit access)...");
for (i=0; i < TEST_SIZE/2; i++)
ram16[i] = (UINT16)i;
sputs("done\r\n");
sputs("Verify (16-Bit access)...");
for (i=TEST_SIZE/2-1; i >= 0; i--)
if (ram16[i] != (UINT16)i)
break;
i++;
if (i)
sputs("failed\r\n");
else
sputs("passed\r\n");
sputs("Write (32-Bit access)...");
for (i=0; i < TEST_SIZE/4; i++)
ram32[i] = (UINT32)i;
sputs("done\r\n");
sputs("Verify (32-Bit access)...");
for (i=TEST_SIZE/4-1; i >= 0; i--)
if (ram32[i] != (UINT32)i)
break;
i++;
if (i)
sputs("failed\r\n");
else
sputs("passed\r\n");
for (i=0; i < TEST_SIZE/4; i++)
ram32[i] = 0;
// Memtest END
// ----------------------------------------------------------
*/
ram32 = (UINT32*)(SDRAM_BASE + IMAGE_OFFSET);
pFlash = (UINT32*)(sys_flash_io + FLASH_OFFSET);
print_word((UINT32)*pBtn);
if (!*pBtn)
{
sputs("Booting from flash..");
for (i=0; i < TEST_SIZE/4; i++)
ram32[i] = pFlash[i];
sputs("done");
Exec_at((void*)ram32);
}
else
{
sputs("SDRAM erase at : ");
print_word((UINT32)ram32);
sputs("\n");
for (i=0; i < TEST_SIZE/4; i++)
ram32[i] = 0;
cfi_init(&flash, sys_flash_io);
if (cfi_find(&flash) < 0)
return 1;
sputs("Found Flash at ");
print_word((UINT32)flash.pBase);
sputs("\n");
addr = FLASH_OFFSET;
sputs("Flash erase at : ");
print_word(addr);
sputs("\n");
cfi_block_erase(&flash, addr/4);
while(1)
{
sputs("BOOT ");
while(1)
{
result = srec_getline(buf);
result = decode_srec(&srec, buf, result);
*pReg = 0;
srec.addr += IMAGE_OFFSET;
switch (result)
{
case srec_data:
if ((srec.addr + srec.size) > haddr)
haddr = srec.addr + srec.size;
pMem = (UINT8*)srec.addr;
for (i=0; i < srec.size; i++)
*pMem++ = srec.data[i];
break;
case srec_eob:
*pReg = 1;
print_word(srec.addr);
sputs(" to ");
print_word(haddr-4);
sputs("\n");
addr = FLASH_OFFSET;
sputs("Program Flash at : ");
print_word(addr);
sputs("\n");
cfi_program_multi(&flash, addr/4, (UINT32*)ram32, TEST_SIZE/4);
// Exec_at((void*)srec.addr);
break;
default:
break;
}
if (result == srec_err)
{
*pReg = 0x40000000;
break;
}
};
}
}
return 0;
}
+47
View File
@@ -0,0 +1,47 @@
/* bubble.c */
#include <stdio.h>
#include <stdlib.h>
#define MAX 20000
int a[MAX];
rnum() {
return( rand()%MAX );
}
initran() {
int i;
for(i=0; i<MAX; i++)
a[i] = rnum();
}
bubble() {
int i,j,t;
for(i=MAX-1; i>=0; i--)
for(j=1; j<MAX; j++ )
if ( a[j-1] > a[j] ) {
t = a[j-1];
a[j-1] = a[j];
a[j] = t;
}
}
show(n)
int n;
{
int i;
for(i=0; i<n; i++ ) printf("%d ",a[i]);
printf("\n");
}
main() {
initran();
bubble();
show(10);
}
+253
View File
@@ -0,0 +1,253 @@
#include <stdio.h>
#include <stdlib.h>
#include "libsys.h"
#include "cfiflash.h"
UINT32 cfi_get_status(flash_t *pObj)
{
volatile UINT32 *pF;
UINT32 status;
pF = (UINT32*)pObj->pBase;
*pF = 0x00700070;
status = *pF;
*pF = 0x00FF00FF;
return status;
}
void cfi_init(flash_t *pObj, UINT32 base_addr)
{
int i;
UINT8 *pInfo;
pObj->pBase = (void*)base_addr;
pInfo = (UINT8*)&pObj->info;
for (i=0; i < sizeof(flash_info_t); i++)
{
pInfo[i] = 0;
}
}
UINT32 cfi_find(flash_t *pObj)
{
int i;
volatile UINT32 *pF;
volatile UINT16 *pF16;
UINT8 qry_ref[12] = {0x51, 0x00, 0x51, 0x00, 0x52, 0x00, 0x52, 0x00, 0x59, 0x00, 0x59, 0x00};
UINT32 size;
pF = (UINT32*)pObj->pBase;
pF16 = (UINT16*)pObj->pBase;
// Look for flash
*pF = 0x00980098;
for (i=0; i < sizeof(qry_ref); i++)
if (((UINT8*)(&pF[0x10]))[i] != qry_ref[i])
return (UINT32)-1;
*pF = 0x00FF00FF;
*pF = 0x00900090;
/*
printf("ManID : %8.8X\n", (UINT32)pF[0]);
printf("Device code : %8.8X\n", (UINT32)pF[1]);
printf("Block info : %8.8X\n", (UINT32)pF[2]);
printf("VCC(min) : %8.8X\n", (UINT32)pF[0x1B]);
printf("VCC(max) : %8.8X\n", (UINT32)pF[0x1C]);
printf("VPP(min) : %8.8X\n", (UINT32)pF[0x1D]);
printf("VPP(max) : %8.8X\n", (UINT32)pF[0x1E]);
printf("Device Layout : %8.8X\n", (UINT32)pF[0x27]);
printf("Interface type : %8.8X %8.8X\n", (UINT32)pF[0x28], (UINT32)pF[0x29]);
printf("Write buffer size : %8.8X %8.8X\n", (UINT32)pF[0x2A], (UINT32)pF[0x2B]);
printf("Num. erase blocks : %8.8X\n", (UINT32)pF[0x2C]);
printf("Erase block info : %8.8X %8.8X %8.8X %8.8X\n", (UINT32)pF[0x2D], (UINT32)pF[0x2E], (UINT32)pF[0x2F], (UINT32)pF[0x30]);
*/
pObj->info.num_flash = 2;
pObj->info.if_width = 32;
size = (UINT32)pF16[2*0x27];
pObj->info.flashsize = pObj->info.num_flash;
for (i=0; i < size; i++)
pObj->info.flashsize *= 2;
size = (UINT32)(pF16[2*0x2B] << 8 | pF16[2*0x2A]);
pObj->info.wbuf_size = pObj->info.num_flash;
for (i=0; i < size; i++)
pObj->info.wbuf_size *= 2;
pObj->info.nblocks = pObj->info.num_flash * ((UINT32)(pF16[2*0x2E] << 8 | pF16[2*0x2D]) + 1);
pObj->info.blocksize = pObj->info.num_flash * ((UINT32)(pF16[2*0x30] << 8 | pF16[2*0x2F]) * 256);
*pF = 0x00FF00FF;
return 0;
}
UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index)
{
volatile UINT32 *pF;
UINT32 status, block_index, block_mask;
pF = (UINT32*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4))
return -1;
block_mask = ((pObj->info.nblocks-1) << 16);
block_index = word_index & block_mask;
pF[block_index] = 0x00200020;
pF[block_index] = 0x00D000D0;
do
{
status = pF[block_index];
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
pF[block_index] = 0x00FF00FF;
return 0;
}
UINT32 cfi_program_single(flash_t *pObj, UINT32 word_index, UINT32 word)
{
volatile UINT32 *pF;
UINT32 status;
pF = (UINT32*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4))
return -1;
pF[word_index] = 0x00400040;
pF[word_index] = word;
do
{
status = pF[word_index];
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
pF[word_index] = 0x00FF00FF;
return 0;
}
UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT32 num_words)
{
int i, j, k;
volatile UINT32 *pF;
UINT32 status, bcurr, bnext, block_mask, nblock_write, nbuf_write;
pF = (UINT32*)pObj->pBase;
if (word_index >= (pObj->info.flashsize/4))
return -1;
block_mask = ((pObj->info.nblocks-1) << 16);
k = 0;
while(num_words)
{
bcurr = word_index & block_mask;
bnext = bcurr + (1 << 16);
nblock_write = bnext - word_index;
if (nblock_write > num_words)
nblock_write = num_words;
// printf("bcurr : %8.8X\n", bcurr);
// printf("bnext : %8.8X\n", bnext);
// printf("windex : %8.8X\n", word_index);
// printf("num_words : %d\n", num_words);
// printf("nblock_write : %d\n", nblock_write);
while(nblock_write)
{
pF[bcurr] = 0x00E800E8;
do
{
status = pF[bcurr];
// printf("status : %8.8X\n", status);
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
nbuf_write = nblock_write;
if (nblock_write > pObj->info.wbuf_size/4)
nbuf_write = pObj->info.wbuf_size/4;
// printf("nbuf_write : %d\n", nbuf_write);
pF[bcurr] = (nbuf_write-1) << 16 | (nbuf_write-1);
for (j=0; j < nbuf_write; j++)
pF[word_index+j] = pWords[k++];
word_index += j;
nblock_write -= j;
num_words -= j;
pF[bcurr] = 0x00D000D0;
do
{
status = pF[bcurr];
// printf("status : %8.8X\n", status);
} while((status & SR_BIT_ISMS) != SR_BIT_ISMS);
pF[bcurr] = 0x00FF00FF;
}
bcurr = bnext;
}
return 0;
}
UINT32 flash_find(flash_t *pObj, UINT32 base_addr)
{
cfi_init(pObj, base_addr);
return cfi_find(pObj);
}
UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size)
{
int i;
UINT32 offset_end;
offset_end = offset + size;
for (i=offset; i < offset_end; i += pObj->info.blocksize)
if (cfi_block_erase(pObj, i/4) < 0)
return -1;
return 0;
}
UINT32 flash_program(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size)
{
return cfi_program_multi(pObj, offset/4, (UINT32*)pData, size/4);
}
UINT32 flash_verify(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size)
{
int i;
UINT8 *pF;
pF = (UINT8*)(pObj->pBase + offset);
for (i=0; i < size; i++)
if (pF[i] != pData[i])
return -1;
return 0;
}
+44
View File
@@ -0,0 +1,44 @@
/************************************************************************/
#ifndef CFIFLASH_H
#define CFIFLASH_H
#include "libsys.h"
#define SR_BIT_DPS 0x00020002
#define SR_BIT_PSS 0x00040004
#define SR_BIT_VPENS 0x00080008
#define SR_BIT_PSLBS 0x00100010
#define SR_BIT_ECLBS 0x00200020
#define SR_BIT_ESS 0x00400040
#define SR_BIT_ISMS 0x00800080
typedef struct _sflash_info_t
{
UINT32 flashsize;
UINT32 blocksize;
UINT32 nblocks;
UINT32 wbuf_size;
UINT32 if_width;
UINT32 num_flash;
} flash_info_t;
typedef struct _sflash_t
{
void *pBase;
flash_info_t info;
} flash_t;
void cfi_init(flash_t *pObj, UINT32 base_addr);
UINT32 cfi_find(flash_t *pObj);
UINT32 cfi_block_erase(flash_t *pObj, UINT32 word_index);
UINT32 cfi_program_single(flash_t *pObj, UINT32 word_index, UINT32 word);
UINT32 cfi_program_multi(flash_t *pObj, UINT32 word_index, UINT32 *pWords, UINT32 num_words);
UINT32 flash_find(flash_t *pObj, UINT32 base_addr);
UINT32 flash_erase(flash_t *pObj, UINT32 offset, UINT32 size);
UINT32 flash_program(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size);
UINT32 flash_verify(flash_t *pObj, UINT32 offset, UINT8 *pData, UINT32 size);
#endif // CFIFLASH_H
+429
View File
@@ -0,0 +1,429 @@
#include <stdio.h>
#include <stdlib.h>
#define NDATA (int *)malloc(ncol * sizeof(int))
#define NLIST (struct _list *)malloc(sizeof(struct _list))
#define NPLAY (struct _play *)malloc(sizeof(struct _play))
struct _list
{
int *data;
struct _list *next;
} *wanted;
struct _play
{
int value;
int *state;
struct _list *first;
struct _play *next;
} *game_tree;
int nrow,ncol; /* global so as to avoid passing them all over the place */
int *copy_data(data) /* creates a duplicate of a given -data list */
int *data;
{
int *new = NDATA;
int counter = ncol;
while (counter --)
new[counter] = data[counter];
return new;
}
int next_data(int *data) /* gives the next logical setup to the one passed */
/* new setup replaces the old. Returns 0 if no valid */
{ /* setup exists after the one passed */
int counter = 0;
int valid = 0; /* default to none */
while ((counter != ncol) && (! valid)) /* until its done */
{
if (data[counter] == nrow) /* if we hit a border */
{
data[counter] = 0; /* reset it to zero */
counter ++; /* and take next column */
}
else
{
data[counter] ++; /* otherwise, just increment row number */
valid = 1; /* and set valid to true. */
}
}
return valid; /* return whether or not */
} /* a next could be found */
void melt_data(int *data1,int *data2) /* melts 2 _data's into the first one. */
{
int counter = ncol;
while (counter --) /* do every column */
{
if (data1[counter] > data2[counter]) /* take the lowest one */
data1[counter] = data2[counter]; /* and put in first _data */
}
}
int equal_data(int *data1,int *data2) /* check if both _data's are equal */
{
int counter = ncol;
while ((counter --) && (data1[counter] == data2[counter]));
return (counter < 0);
}
int valid_data(int *data) /* checks if the play could ever be achieved. */
{
int low; /* var to hold the current height */
int counter = 0;
low = nrow; /* default to top of board */
while (counter != ncol) /* for every column */
{
if (data[counter] > low) break; /* if you get something higher */
low = data[counter]; /* set this as current height */
counter ++;
}
return (counter == ncol);
}
void dump_list(struct _list *list) /* same for a _list structure */
{
if (list != NULL)
{
dump_list(list -> next); /* dump the rest of it */
free(list -> data); /* and its _data structure */
free(list);
}
}
void dump_play(play) /* and for the entire game tree */
struct _play *play;
{
if (play != NULL)
{
dump_play(play -> next); /* dump the rest of the _play */
dump_list(play -> first); /* its _list */
free(play -> state); /* and its _data */
free(play);
}
}
int get_value(int *data) /* get the value (0 or 1) for a specific _data */
{
struct _play *search;
search = game_tree; /* start at the begginig */
while (! equal_data(search -> state,data)) /* until you find a match */
search = search -> next; /* take next element */
return search -> value; /* return its value */
}
void show_data(int *data) /* little display routine to give off results */
{
int counter = 0;
while (counter != ncol)
{
printf("%d",data[counter ++]);
if (counter != ncol) putchar(',');
}
}
void show_move(int *data) /* puts in the "(" and ")" for show_data() */
{
putchar('(');
show_data(data);
printf(")\n");
}
void show_list(struct _list *list) /* show the entire list of moves */
{
while (list != NULL)
{
show_move(list -> data);
list = list -> next;
}
}
void show_play(struct _play *play) /* to diplay the whole tree */
{
while (play != NULL)
{
printf("For state :\n");
show_data(play -> state);
printf(" value = %d\n",play -> value);
printf("We get, in order :\n");
show_list(play -> first);
play = play -> next;
}
}
int in_wanted(int *data) /* checks if the current _data is in the wanted list */
{
struct _list *current;
current = wanted; /* start at the begginig */
while (current != NULL) /* unitl the last one */
{
if (equal_data(current -> data,data)) break; /* break if found */
current = current -> next; /* take next element */
}
if (current == NULL) return 0; /* if at the end, not found */
return 1;
}
int *make_data(int row,int col) /* creates a new _data with the correct */
/* contents for the specified row & col */
{
int count;
int *new = NDATA;
for (count = 0;count != col;count ++) /* creates col-1 cells with nrow */
new[count] = nrow;
for (;count != ncol;count ++) /* and the rest with row as value */
new[count] = row;
return new; /* and return pointer to first element */
}
struct _list *make_list(int *data,int *value,int *all) /* create the whole _list of moves */
/* for the _data structure data */
{
int row,col;
int *temp;
struct _list *head,*current;
*value = 1; /* set to not good to give */
head = NLIST; /* create dummy header */
head -> next = NULL; /* set NULL as next element */
current = head; /* start from here */
for (row = 0;row != nrow;row ++) /* for every row */
{
for (col = 0;col != ncol;col ++) /* for every column */
{
temp = make_data(row,col); /* create _data for this play */
melt_data(temp,data); /* melt it with the current one */
if (! equal_data(temp,data)) /* if they are different, it good */
{
current -> next = NLIST; /* create new element in list */
current -> next -> data = copy_data(temp); /* copy data, and place in list */
current -> next -> next = NULL; /* NULL the next element */
current = current -> next; /* advance pointer */
if (*value == 1) /* if still not found a good one */
*value = get_value(temp); /* look at this value */
if ((! *all) && (*value == 0))
{ /* if we found it, and all is not set */
col = ncol - 1; /* do what it take sto break out now */
row = nrow - 1;
if (in_wanted(temp)) /* if in the wanted list */
*all = 2; /* flag it */
}
}
else /* if its not a valid move */
{
if (col == 0) row = nrow - 1; /* break out if at first column */
col = ncol - 1; /* but make sure you break out */
} /* of the col for-loop anyway */
free(temp); /* dump this unneeded space */
}
}
current = head -> next; /* skip first element */
free(head); /* dump it */
if (current != NULL) *value = 1 - *value; /* invert value if its */
return current; /* not the empty board */
}
struct _play *make_play(int all) /* make up the entire tree-like stuff */
{
int val;
int *temp;
struct _play *head,*current;
head = NPLAY; /* dummy header again */
current = head; /* start here */
game_tree = NULL; /* no elements yet */
temp = make_data(0,0); /* new data, for empty board */
temp[0] --; /* set it up at (-1,xx) so that next_data() returns (0,xx) */
while (next_data(temp)) /* take next one, and break if none */
{
if (valid_data(temp)) /* if board position is possible */
{
current -> next = NPLAY; /* create a new _play cell */
if (game_tree == NULL) game_tree = current -> next;
/* set up game_tree if it was previously NULL */
current -> next -> state = copy_data(temp); /* make a copy of temp */
current -> next -> first = make_list(temp,&val,&all);
/* make up its whole list of possible moves */
current -> next -> value = val; /* place its value */
current -> next -> next = NULL; /* no next element */
current = current -> next; /* advance pointer */
if (all == 2) /* if found flag is on */
{
free(temp); /* dump current temp */
temp = make_data(nrow,ncol); /* and create one that will break */
}
}
}
current = head -> next; /* skip first element */
free(head); /* dump it */
return current; /* and return pointer to start of list */
}
void make_wanted(int *data) /* makes up the list of positions from the full board */
{
/* everything here is almost like in the previous function. */
/* The reason its here, is that it does not do as much as */
/* the one before, and thus goes faster. Also, it saves the */
/* results directly in wanted, which is a global variable. */
int row,col;
int *temp;
struct _list *head,*current;
head = NLIST;
head -> next = NULL;
current = head;
for (row = 0;row != nrow;row ++)
{
for (col = 0;col != ncol;col ++)
{
temp = make_data(row,col);
melt_data(temp,data);
if (! equal_data(temp,data))
{
current -> next = NLIST;
current -> next -> data = copy_data(temp);
current -> next -> next = NULL;
current = current -> next;
}
else
{
if (col == 0) row = nrow - 1;
col = ncol - 1;
}
free(temp);
}
}
current = head -> next;
free(head);
wanted = current;
}
int *get_good_move(struct _list *list) /* gets the first good move from a _list */
{
if (list == NULL) return NULL; /* if list is NULL, say so */
/* until end-of-list or a good one is found */
/* a good move is one that gives off a zero value */
while ((list -> next != NULL) && (get_value(list -> data)))
list = list -> next;
return copy_data(list -> data); /* return the value */
}
int *get_winning_move(struct _play *play) /* just scans for the first good move */
/* in the last _list of a _play. This */
{ /* is the full board */
int *temp;
while (play -> next != NULL) play = play -> next; /* go to end of _play */
temp = get_good_move(play -> first); /* get good move */
return temp; /* return it */
}
struct _list *where(int *data,struct _play *play)
{
while (! equal_data(play -> state,data)) /* search for given _data */
play = play -> next;
return play -> first; /* return the pointer */
}
void get_real_move(int *data1,int *data2,int *row,int *col) /* returns row & col of the move */
/* which created data1 from data2 */
{
*col = 0;
while (data1[*col] == data2[*col]) /* until there is a change */
(*col) ++; /* and increment col number */
*row = data1[*col]; /* row is given by the content of the structure */
}
int main(void)
{
int row,col,maxrow,player;
int *win,*current,*temp;
struct _play *tree,*look;
/* allow user to select mode */
printf("Mode : 1 -> multiple first moves\n");
printf(" 2 -> report game\n");
printf(" 3 -> good positions\n");
printf(" Selection : ");
#if 0
scanf("%d",&row); /* put it in row for now */
#else
row = 2;
#endif
switch (row)
{
case 1:
printf("Enter number of Columns : ");
scanf("%d",&ncol);
printf("Enter Initial number of Rows : ");
scanf("%d",&nrow);
printf("Enter Maximum number of Rows : ");
scanf("%d",&maxrow);
for (;nrow <= maxrow;nrow ++)
{
make_wanted(make_data(nrow,ncol)); /* created wanted list */
tree = make_play(0); /* create tree */
win = get_winning_move(tree); /* get the winning move */
/* get the coordinates of this move */
get_real_move(win,make_data(nrow,ncol),&row,&col);
/* print it out nicely */
printf("The winning initial move for %d x %d CHOMP is (%d,%d)\n",nrow,ncol,row,col);
dump_play(tree); /* dump for memory management */
dump_list(wanted);
}
break;
case 2:
printf("Enter number of Columns : ");
#if 0
scanf("%d",&ncol);
#else
ncol = 7;
#endif
printf("Enter number of Rows : ");
#if 0
scanf("%d",&nrow);
#else
#ifdef SMALL_PROBLEM_SIZE
nrow = 7;
#else
nrow = 8;
#endif
#endif
tree = make_play(1); /* create entire tree structure, not just the */
player = 0; /* needed part for first move */
current = make_data(nrow,ncol); /* start play at full board */
while (current != NULL)
{
temp = get_good_move(where(current,tree)); /* get best move */
if (temp != NULL) /* temp = NULL when the poison pill is taken */
{
get_real_move(temp,current,&row,&col); /* calculate coordinates */
/* print it out nicely */
printf("player %d plays at (%d,%d)\n",player,row,col);
player = 1 - player; /* next player to do the same */
free(current); /* dump for memory management */
}
current = temp; /* update board */
}
dump_play(tree); /* dump unneeded tree */
printf("player %d loses\n",1 - player); /* display winning player */
break;
case 3:
printf("Enter number of Columns : ");
scanf("%d",&ncol);
printf("Enter number of Rows : ");
scanf("%d",&nrow);
printf("ATTENTION : representation is as in a _data structure\n");
tree = make_play(1); /* create tree */
look = tree; /* start here */
while (look != NULL)
{
if (look -> value == 0) /* show all positions bad for player 2 */
show_move(look -> state); /* i.e. bad positions to be in */
look = look -> next; /* with zero value */
}
dump_play(tree); /* dump for memory management */
break;
}
return 0;
}
/*****************************************************************************/
+574
View File
@@ -0,0 +1,574 @@
// ----------------------------------------------------------------------
// color_conv.c
// 21.02.2005, Jens Ahrensfeld
// ----------------------------------------------------------------------
#include <string.h>
#include <math.h>
#include "color_conv.h"
#include "colortypes.h"
// ----------------------------------------------------------------------
void rgb2hsv(rgb_t *pRGB, rgb_t *pHSV, int len)
{
int i;
double *rgb, *hsv, v_min, v_max, diff_max, diff_max_r, diff_r, diff_g, diff_b;
for (i=0; i < len; i++)
{
rgb = (double*)&pRGB[i];
hsv = (double*)&pHSV[i];
v_min = smin(rgb[0], rgb[1]);
v_min = smin(v_min, rgb[2]);
v_max = smax(rgb[0], rgb[1]);
v_max = smax(v_max, rgb[2]);
diff_max = v_max - v_min;
hsv[2] = v_max;
if (diff_max == 0)
{
hsv[0] = diff_max;
hsv[1] = diff_max;
}
else
{
diff_max_r = 1.0/diff_max;
hsv[1] = diff_max/v_max;
diff_r = (((v_max - rgb[0])*(1.0/6)) + (0.5*diff_max))*diff_max_r;
diff_g = (((v_max - rgb[1])*(1.0/6)) + (0.5*diff_max))*diff_max_r;
diff_b = (((v_max - rgb[2])*(1.0/6)) + (0.5*diff_max))*diff_max_r;
if (rgb[0] == v_max)
{
hsv[0] = diff_b - diff_g;
}
else
{
if (rgb[1] == v_max)
{
hsv[0] = 1.0/3 + diff_r - diff_b;
}
else
{
if (rgb[2] == v_max)
{
hsv[0] = 2.0/3 + diff_g - diff_r;
}
}
}
if (hsv[0] < 0)
hsv[0] += 1;
if (hsv[0] > 1.0)
hsv[0] -= 1;
}
}
}
// ----------------------------------------------------------------------
void hsv2rgb(rgb_t *pHSV, rgb_t *pRGB, int len)
{
int i, j;
double h, t1, t2, t3, *rgb, *hsv;
for (i=0; i < len; i++)
{
rgb = (double*)&pRGB[i];
hsv = (double*)&pHSV[i];
if (hsv[1] == 0)
{
rgb[0] = hsv[2];
rgb[1] = hsv[2];
rgb[2] = hsv[2];
continue;
}
h = hsv[0] * 6;
j = (int)h;
t1 = hsv[2]*(1 - hsv[1]);
t2 = hsv[2]*(1 - hsv[1]*(h-(double)j));
t3 = hsv[2]*(1 - hsv[1]*(1-(h-(double)j)));
switch(j)
{
case 0:
rgb[0] = hsv[2];
rgb[1] = t3;
rgb[2] = t1;
break;
case 1:
rgb[0] = t2;
rgb[1] = hsv[2];
rgb[2] = t1;
break;
case 2:
rgb[0] = t1;
rgb[1] = hsv[2];
rgb[2] = t3;
break;
case 3:
rgb[0] = t1;
rgb[1] = t2;
rgb[2] = hsv[2];
break;
case 4:
rgb[0] = t3;
rgb[1] = t1;
rgb[2] = hsv[2];
break;
default:
rgb[0] = hsv[2];
rgb[1] = t1;
rgb[2] = t2;
break;
}
}
}
// ----------------------------------------------------------------------
void rgb2hsl(rgb_t *pRGB, rgb_t *pHSL, int len)
{
int i;
double *rgb, *hsl, v_min, v_max, diff_max, diff_max_r, diff_r, diff_g, diff_b;
for (i=0; i < len; i++)
{
rgb = (double*)&pRGB[i];
hsl = (double*)&pHSL[i];
v_min = smin(rgb[0], rgb[1]);
v_min = smin(v_min, rgb[2]);
v_max = smax(rgb[0], rgb[1]);
v_max = smax(v_max, rgb[2]);
diff_max = v_max - v_min;
hsl[2] = (v_max + v_min)/2;
if (diff_max == 0)
{
hsl[0] = diff_max;
hsl[1] = diff_max;
}
else
{
diff_max_r = 1.0/diff_max;
if(hsl[2] < 0.5)
{
hsl[1] = diff_max/(v_max + v_min);
}
else
{
hsl[1] = diff_max/(2 - v_max - v_min);
}
diff_r = (((v_max - rgb[0])*(1.0/6)) + (0.5*diff_max))*diff_max_r;
diff_g = (((v_max - rgb[1])*(1.0/6)) + (0.5*diff_max))*diff_max_r;
diff_b = (((v_max - rgb[2])*(1.0/6)) + (0.5*diff_max))*diff_max_r;
if (rgb[0] == v_max)
{
hsl[0] = diff_b - diff_g;
}
else
{
if (rgb[1] == v_max)
{
hsl[0] = 1.0/3 + diff_r - diff_b;
}
else
{
if (rgb[2] == v_max)
{
hsl[0] = 2.0/3 + diff_g - diff_r;
}
}
}
if (hsl[0] < 0)
hsl[0] += 1;
if (hsl[0] > 1.0)
hsl[0] -= 1;
}
}
}
// ----------------------------------------------------------------------
inline double Hue_2_RGB(double v1, double v2, double vH) //Function Hue_2_RGB
{
if (vH < 0)
vH += 1;
if (vH > 1)
vH -= 1;
if ((6*vH) < 1)
return v1 + (v2 - v1)*6*vH;
if ((2*vH) < 1)
return v2;
if ((3*vH) < 2)
return v1 + (v2 - v1)*((2.0/3) - vH)*6;
return v1;
}
// ----------------------------------------------------------------------
void hsl2rgb(rgb_t *pHSL, rgb_t *pRGB, int len)
{
int i, j;
double h, t1, t2, t3, *rgb, *hsl;
for (i=0; i < len; i++)
{
rgb = (double*)&pRGB[i];
hsl = (double*)&pHSL[i];
if (hsl[1] == 0)
{
rgb[0] = hsl[2];
rgb[1] = hsl[2];
rgb[2] = hsl[2];
continue;
}
if(hsl[2] < 0.5)
{
t2 = hsl[2]*(1 + hsl[1]);
}
else
{
t2 = (hsl[2] + hsl[1]) - hsl[2]*hsl[1];
}
t1 = 2*hsl[2] - t2;
rgb[0] = Hue_2_RGB(t1, t2, hsl[0] + 1.0/3);
rgb[1] = Hue_2_RGB(t1, t2, hsl[0]);
rgb[2] = Hue_2_RGB(t1, t2, hsl[0] - 1.0/3);
}
}
// ----------------------------------------------------------------------
void rgb2xyz(double **ppRGB, double **ppXYZ, int len)
{
int i, j;
double rgb[3];
double *pRGB, *pXYZ;
for (i=0; i < len; i++)
{
pRGB = ((double*)ppRGB[i]);
pXYZ = ((double*)ppXYZ[i]);
for (j=0; j < 3; j++)
{
if (pRGB[j] > 0.04045)
{
rgb[j] = pow((pRGB[j]+0.055)/1.055,2.4);
}
else
{
rgb[j] = 1.0/12.92 * pRGB[j];
}
rgb[j] *= K_XYZ;
}
// Observer = 2°, Illuminant = D65
pXYZ[0] = 0.412453*rgb[0] + 0.357580*rgb[1] + 0.180423*rgb[2];
pXYZ[1] = 0.212671*rgb[0] + 0.715160*rgb[1] + 0.072169*rgb[2];
pXYZ[2] = 0.019334*rgb[0] + 0.119193*rgb[1] + 0.950227*rgb[2];
}
}
// ----------------------------------------------------------------------
void xyz2rgb(double **ppXYZ, double **ppRGB, int len)
{
int i, j;
double xyz[3];
double *pRGB, *pXYZ;
for (i=0; i < len; i++)
{
pRGB = ((double*)ppRGB[i]);
pXYZ = ((double*)ppXYZ[i]);
for (j=0; j < 3; j++)
{
xyz[j] = 1.0/K_XYZ * pXYZ[j];
}
// Observer = 2°, Illuminant = D65
pRGB[0] = 3.240479*xyz[0] - 1.537150*xyz[1] - 0.498535*xyz[2];
pRGB[1] = -0.969256*xyz[0] + 1.875992*xyz[1] + 0.041556*xyz[2];
pRGB[2] = 0.055648*xyz[0] - 0.204043*xyz[1] + 1.057311*xyz[2];
for (j=0; j < 3; j++)
{
if (pRGB[j] > 0.0031308)
{
pRGB[j] = 1.055 * pow(pRGB[j],1.0/2.4) - 0.055;
}
else
{
pRGB[j] = 12.92 * pRGB[j];
}
}
}
}
// ----------------------------------------------------------------------
void xyz2lab(double **ppXYZ, double **ppLAB, double *pRef, int len)
{
int i, j;
double xyz[3] = {0};
double *pLAB, *pXYZ;
for (i=0; i < len; i++)
{
pXYZ = ((double*)ppXYZ[i]);
pLAB = ((double*)ppLAB[i]);
for (j=0; j < 3; j++)
{
xyz[j] = pXYZ[j] / pRef[j];
}
for (j=0; j < 3; j++)
{
if (xyz[j] > 0.008856)
{
xyz[j] = pow(xyz[j],1.0/3.0);
}
else
{
xyz[j] = 7.787*xyz[j] + 16.0/116.0;
}
}
pLAB[0] = 116.0*xyz[1] - 16;
pLAB[1] = 500.0*(xyz[0] - xyz[1]);
pLAB[2] = 200.0*(xyz[1] - xyz[2]);
}
}
// ----------------------------------------------------------------------
void lab2xyz(double **ppLAB, double **ppXYZ, double *pRef, int len)
{
int i, j;
double xyz[3], xyz3;
double *pLAB, *pXYZ;
for (i=0; i < len; i++)
{
pXYZ = ((double*)ppXYZ[i]);
pLAB = ((double*)ppLAB[i]);
xyz[1] = 1.0/116.0*(pLAB[0] + 16);
xyz[0] = 1.0/500.0*pLAB[1] + xyz[1];
xyz[2] = xyz[1] - 1.0/200.0*pLAB[2];
for (j=0; j < 3; j++)
{
xyz3 = pow(xyz[j],3.0);
if (xyz3 > 0.008856)
{
xyz[j] = xyz3;
}
else
{
xyz[j] = 1.0/7.787*(xyz[j] - 16.0/116);
}
}
for (j=0; j < 3; j++)
{
pXYZ[j] = xyz[j] *pRef[j];
}
}
}
// ----------------------------------------------------------------------
void tristimulus(double *pRef, unsigned illuminant_type, unsigned observer_type)
{
double ref[3] = {K_XYZ*0.95047, K_XYZ*1.0, K_XYZ*1.08883};
if(observer_type == OBS_TYPE_2DEG)
{
switch (illuminant_type)
{
case ILLU_TYPE_A:
case ILLU_TYPE_INCANDESCENT:
pRef[0] = K_XYZ*1.09850;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.35585;
break;
case ILLU_TYPE_C:
pRef[0] = K_XYZ*0.98074;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*1.18232;
break;
case ILLU_TYPE_D50:
pRef[0] = K_XYZ*0.96422;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.82521;
break;
case ILLU_TYPE_D55:
pRef[0] = K_XYZ*0.95682;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.92149;
break;
case ILLU_TYPE_D65:
case ILLU_TYPE_DAYLIGHT:
pRef[0] = K_XYZ*0.95047;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*1.08883;
break;
case ILLU_TYPE_D75:
pRef[0] = K_XYZ*0.94972;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*1.22638;
break;
case ILLU_TYPE_F2:
case ILLU_TYPE_FLUORESCENT:
pRef[0] = K_XYZ*0.99187;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.67395;
break;
case ILLU_TYPE_F7:
pRef[0] = K_XYZ*0.95044;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*1.08755;
break;
case ILLU_TYPE_F11:
pRef[0] = K_XYZ*1.00966;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.64370;
break;
default:
memcpy(pRef, ref, 3*sizeof(double));
break;
}
}
if(observer_type == OBS_TYPE_10DEG)
{
switch (illuminant_type)
{
case ILLU_TYPE_A:
case ILLU_TYPE_INCANDESCENT:
pRef[0] = K_XYZ*1.11144;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.35200;
break;
case ILLU_TYPE_C:
pRef[0] = K_XYZ*0.97285;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*1.16145;
break;
case ILLU_TYPE_D50:
pRef[0] = K_XYZ*0.96720;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.81427;
break;
case ILLU_TYPE_D55:
pRef[0] = K_XYZ*0.95799;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.90926;
break;
case ILLU_TYPE_D65:
case ILLU_TYPE_DAYLIGHT:
pRef[0] = K_XYZ*0.94811;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*1.07304;
break;
case ILLU_TYPE_D75:
pRef[0] = K_XYZ*0.94416;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*1.20641;
break;
case ILLU_TYPE_F2:
case ILLU_TYPE_FLUORESCENT:
pRef[0] = K_XYZ*1.03280;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.69026;
break;
case ILLU_TYPE_F7:
pRef[0] = K_XYZ*0.95792;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*1.07687;
break;
case ILLU_TYPE_F11:
pRef[0] = K_XYZ*1.03866;
pRef[1] = K_XYZ*1.0;
pRef[2] = K_XYZ*0.65627;
break;
default:
memcpy(pRef, ref, 3*sizeof(double));
break;
}
}
}
void rgb2rgb(double **ppSrc, double **ppDst, int len)
{
int i, j;
double *pSrc, *pDst;
for (i=0; i < len; i++)
{
pSrc = ((double*)ppSrc[i]);
pDst = ((double*)ppDst[i]);
for (j=0; j < 3; j++)
{
pDst[j] = pSrc[j];
}
}
}
+41
View File
@@ -0,0 +1,41 @@
// ----------------------------------------------------------------------
// color_conv.h
// 21.02.2005, Jens Ahrensfeld
// ----------------------------------------------------------------------
#ifndef COLOR_CONV_H
#define COLOR_CONV_H
#include "colortypes.h"
// ----------------------------------------------------------------------
#define K_XYZ 1.0
#define OBS_TYPE_2DEG 2
#define OBS_TYPE_10DEG 10
#define ILLU_TYPE_A 1
#define ILLU_TYPE_C 2
#define ILLU_TYPE_D50 3
#define ILLU_TYPE_D55 4
#define ILLU_TYPE_D65 5
#define ILLU_TYPE_D75 6
#define ILLU_TYPE_F2 7
#define ILLU_TYPE_F7 8
#define ILLU_TYPE_F11 9
#define ILLU_TYPE_INCANDESCENT 10
#define ILLU_TYPE_DAYLIGHT 11
#define ILLU_TYPE_FLUORESCENT 12
// ----------------------------------------------------------------------
void rgb2hsv(rgb_t *pRGB, rgb_t *pHSV, int len);
void hsv2rgb(rgb_t *pHSV, rgb_t *pRGB, int len);
void rgb2hsl(rgb_t *pRGB, rgb_t *pHSL, int len);
void hsl2rgb(rgb_t *pHSL, rgb_t *pRGB, int len);
void rgb2xyz(double **ppRGB, double **ppXYZ, int len);
void xyz2rgb(double **ppXYZ, double **ppRGB, int len);
void xyz2lab(double **ppXYZ, double **ppLAB, double *pRef, int len);
void lab2xyz(double **ppLAB, double **ppXYZ, double *pRef, int len);
void rgb2rgb(double **ppSrc, double **ppDst, int len);
void tristimulus(double *pRef, unsigned illuminant_type, unsigned observer_type);
// ----------------------------------------------------------------------
#endif // COLOR_CONV_H
+36
View File
@@ -0,0 +1,36 @@
// ------------------------------------------------------------
// colortypes.h
//
// Reading writing tiff images
//
// 12.03.2005, J.Ahrensfeld
// ------------------------------------------------------------
#ifndef COLORTYPES_H
#define COLORTYPES_H
// ------------------------------------------------------------
#define COMP_RED 0
#define COMP_GREEN 1
#define COMP_BLUE 2
#define COMP_ALPHA 3
#define COMP_L 0
#define COMP_A 1
#define COMP_B 2
#define COORD_X 0
#define COORD_Y 1
typedef double color_t[3];
typedef double color_vector_t[3];
typedef color_t color_matrix_t[3];
typedef double rgb_t[3];
typedef double rgb_vector_t[3];
typedef rgb_t rgb_matrix_t[3];
typedef double rgba_t[4];
typedef double rgba_vector_t[4];
typedef rgba_t rgba_matrix_t[4];
// ------------------------------------------------------------
#endif // COLORTYPES_H
BIN
View File
Binary file not shown.
+42
View File
@@ -0,0 +1,42 @@
#include<unistd.h>
#include<time.h>
#define k ("C9B7351A@D-/E+F?')G>H%J#=I"[(d[(i/13)*2]*91+d[(i/13)*2+1]-3220)&(\
4096>>(i%13))?l+1:l]-59)
#define g(n)e(n<13?n:n<20?n+1:n>20?11+n/10:13,0);e(n>12&&n<20?26:n>20&&n%10?n%\
10:-1,2);
#define x(n)g(localtime(&a)->tm_##n)
unsigned char *d="KZs2ITTwhwZYvec@JbYxOjf9-TZRGDb/el7#q(`SZ#|_neTwq\\MqJ5cVgte\
K-ReK-(Mq8+D'6Ui0tG88vXJ-Tu{VI=d%cR]h7CumwBq\\-#{thj8fw$OEfEvLHP13_##w.OD[7Cw2\
]<T{|[F}L;L:*+A#PwLnp{9'M3Mr|w_|unm'}$*(5]_$?O9zO{{wz4p6vP8Ipu}$BQospf=-Isnyl'\
|g53o^c`ov-P`-x+|ZAd<e?<'b9P|LkZOf{B-8`K([srqv&gy1,:}$|s7D{yN6M#cQyKpC|*_|#xA#\
'YfQ}$k$kr7dM#dcnWDg|PHdA#^j&q}$x@(a;k2JB]50ZKp{xRwbkTm.v\\a3fJ@V[`J#fN`s|sZeH\
mmHX7`JKiry4sm,bUfz69{rt'k*pBq^l,ut6UVvb9N%r%l:Py3r[.Z/pBkaz2J4u{GTu)hyp#%gbS$\
r`mzi9G|3M,r}-Dt?w)_##%fQt$k&n]e$HzFXu(|Fvt`i#$A#|ykrz+nhs'P#|pm*9[_#,5P#}$}$x\
&s(i,HzO'&d&g?/_$P#kZ7Dn]e$J{zi8ypi|hq$_.|cLx`sy;f8GRMQM#7R5$hym*:^`sxrvtfQ|z_\
N|ye[7dH[}#Ts\\59V@|#z}$}$y;usL)vXFiA0AukZ8H|fyKurd]|s5<|xq@Cpm,}${,e$KufO?/2M\
t$zmM#vtfQ|zRKlEA#P&fPOwJ#pf_$?/2#@|$w}$?fLxA#^-}$cM^aA#&g#wIv?^|yY#s)Lwt'K#ON\
yoXKYkpCl0m}D[9OGU7n([ZrL)[8eRy7uR*PJ#^5xRG>zSf>p]ZrJ_[9q?qgYe^4$r3lY$4SdsSyNv\
J_l&w2I?q#fN*F1n|s9OGUv|w&l+pR-3Nudtyn@|Dfq#^o|s9Pt=oZCol/{VdgkLdwyn1yDed}?Dzi\
}#Kje#d}Y${8pSt<q?qgIv|`DH?9}$O{k(LgE;|KU-tJnWOw*F@YP#|yY$b4|.50[2d}D'kaqhp;JE\
$r&fH&'6nykYGCv>K$t?yLbwtUn[F{ncOx_.:K#nwF#f|HQs&<&bfQPE?:uJm*&\\S=*/@|We*w@$@\
f0,*H])WL<i@^xX@)(a.>MV*p{Zqf&zH%###################u2#A#_$A#_$A#_$A#_$@tA#QI#\
3#0&:p#?1[P*6WQ@i#C1{[;@|1}S%^r#g.d^z#M}$ziZe|kU6oZbq5$kF]4[E^nA#_.|}e$Ku^r&WA\
#_$?/*P_$@t&gA#[;_$A#^j2#A#_*d}@v^z#8?D?D9Q`s}$5$L|u<3JC/xVz;#s^{?9$M}$x_Y,7uP\
$",p[6789];
int o[]={145,1145,1745,2545,3045,4045,4345,5145,5745,6369},i=0,j=0,l=0;
void e(n,h){
for(j=0;n>0;n-=!(p[j++]^9));
for(;!n&&j[p]^9;j++)write(1,p+p[j][o],o[p[j]+1]-p[j][o]);
for(i=0;i<h[o];i++)write(1,d+7,1);}
int main(){
time_t a=time(&a);
for(;i<8476;j[p]=k>=0?j<*o?k-2:(p[j+1]=k<<4):0,j+=k>=0?1+(j>=*o):0,
l=-k*(k<0),i++);e(21,4);x(hour)e(22,1);x(min)e(23,1);e(25,0);x(sec)e(24,0);
return;}
File diff suppressed because one or more lines are too long
+54
View File
@@ -0,0 +1,54 @@
#include <stdio.h>
unsigned long MakeCRC32(char *data, unsigned int len, unsigned int CRC)
{
/* ========================================================================
* Table of CRC-32's of all single-byte values (made by makecrc.c)
*/
unsigned long crc_32_tab[] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL
};
if (data == NULL)
return 0;
CRC = ~CRC;
while (len --)
{
CRC = crc_32_tab[((unsigned char) CRC ^ *data) & 0xFF] ^ (CRC >> 8);
data ++;
}
return ~CRC;
}
+13
View File
@@ -0,0 +1,13 @@
// CRC32 function
// To create a CRC from a new buffer, use this:
// crc = MakeCRC32(mydata, data_len, 0);
// If you need to continue the CRC (e.g. your data is in multiple buffers),
// continue like this:
// crc = MakeCRC32(moredata, more_len, crc);
//
// Your desired CRC should be the complement of the CRC generated by
// MakeCRC32:
// desired = crc
// desired - crc = 0
unsigned long MakeCRC32(char *data, unsigned int len, unsigned long CRC);
+270
View File
@@ -0,0 +1,270 @@
/* Script for -z combreloc: combine and sort reloc sections */
OUTPUT_FORMAT("elf32-littlemips", "elf32-bigmips",
"elf32-littlemips")
OUTPUT_ARCH(mips)
ENTRY(_start)
SEARCH_DIR("/usr/local/mipsel-elf/lib");
stack_ptr = 0x7FFFEFF0;
baudrate = 0x0D;
sys_led_port = 0xA0000000;
sys_uart_data = 0xA0010000;
sys_uart_stat = 0xA0010004;
sys_uart_baud = 0xA0010008;
sys_timer_usec = 0xA000008;
sys_timer_sec = 0xA000000C;
SECTIONS
{
/* Read-only sections, merged into text segment: */
PROVIDE (__executable_start = 0x40000000); . = 0x40000000;
.etext __executable_start :
{
start = ALIGN(2);
entry = ALIGN(2);
_entry = ALIGN(2);
__entry = ALIGN(2);
*(.etext)
}
.ktext __executable_start + 0x180 :
{
*(.ktext)
}
.interp : { *(.interp) }
.reginfo : { *(.reginfo) }
.note.gnu.build-id : { *(.note.gnu.build-id) }
.dynamic : { *(.dynamic) }
.hash : { *(.hash) }
.gnu.hash : { *(.gnu.hash) }
.dynsym : { *(.dynsym) }
.dynstr : { *(.dynstr) }
.gnu.version : { *(.gnu.version) }
.gnu.version_d : { *(.gnu.version_d) }
.gnu.version_r : { *(.gnu.version_r) }
.rel.dyn :
{
*(.rel.init)
*(.rel.text .rel.text.* .rel.gnu.linkonce.t.*)
*(.rel.fini)
*(.rel.rodata .rel.rodata.* .rel.gnu.linkonce.r.*)
*(.rel.data.rel.ro* .rel.gnu.linkonce.d.rel.ro.*)
*(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
*(.rel.tdata .rel.tdata.* .rel.gnu.linkonce.td.*)
*(.rel.tbss .rel.tbss.* .rel.gnu.linkonce.tb.*)
*(.rel.ctors)
*(.rel.dtors)
*(.rel.got)
*(.rel.dyn)
*(.rel.sdata .rel.sdata.* .rel.gnu.linkonce.s.*)
*(.rel.sbss .rel.sbss.* .rel.gnu.linkonce.sb.*)
*(.rel.sdata2 .rel.sdata2.* .rel.gnu.linkonce.s2.*)
*(.rel.sbss2 .rel.sbss2.* .rel.gnu.linkonce.sb2.*)
*(.rel.bss .rel.bss.* .rel.gnu.linkonce.b.*)
}
.rela.dyn :
{
*(.rela.init)
*(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)
*(.rela.fini)
*(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)
*(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)
*(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)
*(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)
*(.rela.ctors)
*(.rela.dtors)
*(.rela.got)
*(.rela.sdata .rela.sdata.* .rela.gnu.linkonce.s.*)
*(.rela.sbss .rela.sbss.* .rela.gnu.linkonce.sb.*)
*(.rela.sdata2 .rela.sdata2.* .rela.gnu.linkonce.s2.*)
*(.rela.sbss2 .rela.sbss2.* .rela.gnu.linkonce.sb2.*)
*(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)
}
.rel.plt : { *(.rel.plt) }
.rela.plt : { *(.rela.plt) }
.init :
{
KEEP (*(.init))
} =0
.plt : { *(.plt) }
.text :
{
_ftext = . ;
*(.text .stub .text.* .gnu.linkonce.t.*)
/* .gnu.warning sections are handled specially by elf32.em. */
*(.gnu.warning)
*(.mips16.fn.*) *(.mips16.call.*)
}
.fini :
{
KEEP (*(.fini))
} =0
PROVIDE (__etext = .);
PROVIDE (_etext = .);
PROVIDE (etext = .);
.rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
.rodata1 : { *(.rodata1) }
.sdata2 :
{
*(.sdata2 .sdata2.* .gnu.linkonce.s2.*)
}
.sbss2 : { *(.sbss2 .sbss2.* .gnu.linkonce.sb2.*) }
.eh_frame_hdr : { *(.eh_frame_hdr) }
.eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }
.gcc_except_table : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
/* Adjust the address for the data segment. We want to adjust up to
the same address within the page on the next page up. */
. = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));
/* Exception handling */
.eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }
.gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
/* Thread Local Storage sections */
.tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }
.tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
.preinit_array :
{
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP (*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
}
.init_array :
{
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
}
.fini_array :
{
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP (*(.fini_array))
KEEP (*(SORT(.fini_array.*)))
PROVIDE_HIDDEN (__fini_array_end = .);
}
.ctors :
{
/* gcc uses crtbegin.o to find the start of
the constructors, so we make sure it is
first. Because this is a wildcard, it
doesn't matter if the user does not
actually link against crtbegin.o; the
linker won't look for a file to match a
wildcard. The wildcard also means that it
doesn't matter which directory crtbegin.o
is in. */
KEEP (*crtbegin.o(.ctors))
KEEP (*crtbegin?.o(.ctors))
/* We don't want to include the .ctor section from
the crtend.o file until after the sorted ctors.
The .ctor section from the crtend file contains the
end of ctors marker and it must be last */
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))
KEEP (*(SORT(.ctors.*)))
KEEP (*(.ctors))
}
.dtors :
{
KEEP (*crtbegin.o(.dtors))
KEEP (*crtbegin?.o(.dtors))
KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))
KEEP (*(SORT(.dtors.*)))
KEEP (*(.dtors))
}
.jcr : { KEEP (*(.jcr)) }
.data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro* .gnu.linkonce.d.rel.ro.*) }
. = DATA_SEGMENT_RELRO_END (0, .);
.data :
{
_fdata = . ;
*(.data .data.* .gnu.linkonce.d.*)
SORT(CONSTRUCTORS)
}
.data1 : { *(.data1) }
.got.plt : { *(.got.plt) }
. = .;
_gp = ALIGN(16) + 0x7ff0;
.got : { *(.got) }
/* We want the small data sections together, so single-instruction offsets
can access them all, and initialized data all before uninitialized, so
we can shorten the on-disk segment size. */
.sdata :
{
*(.sdata .sdata.* .gnu.linkonce.s.*)
}
.lit8 : { *(.lit8) }
.lit4 : { *(.lit4) }
_edata = .; PROVIDE (edata = .);
__bss_start = .;
_fbss = .;
.sbss :
{
*(.dynsbss)
*(.sbss .sbss.* .gnu.linkonce.sb.*)
*(.scommon)
}
.bss :
{
*(.dynbss)
*(.bss .bss.* .gnu.linkonce.b.*)
*(COMMON)
/* Align here to ensure that the .bss section occupies space up to
_end. Align after .bss to ensure correct alignment even if the
.bss section disappears because there are no input sections.
FIXME: Why do we need it? When there is no .bss section, we don't
pad the .data section. */
. = ALIGN(. != 0 ? 32 / 8 : 1);
}
. = ALIGN(32 / 8);
. = ALIGN(32 / 8);
_end = .; PROVIDE (end = .);
. = DATA_SEGMENT_END (.);
/* Stabs debugging sections. */
.stab 0 : { *(.stab) }
.stabstr 0 : { *(.stabstr) }
.stab.excl 0 : { *(.stab.excl) }
.stab.exclstr 0 : { *(.stab.exclstr) }
.stab.index 0 : { *(.stab.index) }
.stab.indexstr 0 : { *(.stab.indexstr) }
.comment 0 : { *(.comment) }
/* DWARF debug sections.
Symbols in the DWARF debugging sections are relative to the beginning
of the section so we begin them at 0. */
/* DWARF 1 */
.debug 0 : { *(.debug) }
.line 0 : { *(.line) }
/* GNU DWARF 1 extensions */
.debug_srcinfo 0 : { *(.debug_srcinfo) }
.debug_sfnames 0 : { *(.debug_sfnames) }
/* DWARF 1.1 and DWARF 2 */
.debug_aranges 0 : { *(.debug_aranges) }
.debug_pubnames 0 : { *(.debug_pubnames) }
/* DWARF 2 */
.debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }
.debug_abbrev 0 : { *(.debug_abbrev) }
.debug_line 0 : { *(.debug_line) }
.debug_frame 0 : { *(.debug_frame) }
.debug_str 0 : { *(.debug_str) }
.debug_loc 0 : { *(.debug_loc) }
.debug_macinfo 0 : { *(.debug_macinfo) }
/* SGI/MIPS DWARF 2 extensions */
.debug_weaknames 0 : { *(.debug_weaknames) }
.debug_funcnames 0 : { *(.debug_funcnames) }
.debug_typenames 0 : { *(.debug_typenames) }
.debug_varnames 0 : { *(.debug_varnames) }
/* DWARF 3 */
.debug_pubtypes 0 : { *(.debug_pubtypes) }
.debug_ranges 0 : { *(.debug_ranges) }
.gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }
.gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
.gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
.mdebug.abi32 : { KEEP(*(.mdebug.abi32)) }
.mdebug.abiN32 : { KEEP(*(.mdebug.abiN32)) }
.mdebug.abi64 : { KEEP(*(.mdebug.abi64)) }
.mdebug.abiO64 : { KEEP(*(.mdebug.abiO64)) }
.mdebug.eabi32 : { KEEP(*(.mdebug.eabi32)) }
.mdebug.eabi64 : { KEEP(*(.mdebug.eabi64)) }
.gcc_compiled_long32 : { KEEP(*(.gcc_compiled_long32)) }
.gcc_compiled_long64 : { KEEP(*(.gcc_compiled_long64)) }
/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) }
}
BIN
View File
Binary file not shown.
+13365
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
Binary file not shown.
+430
View File
@@ -0,0 +1,430 @@
/*
****************************************************************************
*
* "DHRYSTONE" Benchmark Program
* -----------------------------
*
* Version: C, Version 2.1
*
* File: dhry.h (part 1 of 3)
*
* Date: May 25, 1988
*
* Author: Reinhold P. Weicker
* Siemens AG, E STE 35
* Postfach 3240
* 8520 Erlangen
* Germany (West)
* Phone: [xxx-49]-9131-7-20330
* (8-17 Central European Time)
* Usenet: ..!mcvax!unido!estevax!weicker
*
* Original Version (in Ada) published in
* "Communications of the ACM" vol. 27., no. 10 (Oct. 1984),
* pp. 1013 - 1030, together with the statistics
* on which the distribution of statements etc. is based.
*
* In this C version, the following C library functions are used:
* - strcpy, strcmp (inside the measurement loop)
* - printf, scanf (outside the measurement loop)
* In addition, Berkeley UNIX system calls "times ()" or "time ()"
* are used for execution time measurement. For measurements
* on other systems, these calls have to be changed.
*
* Collection of Results:
* Reinhold Weicker (address see above) and
*
* Rick Richardson
* PC Research. Inc.
* 94 Apple Orchard Drive
* Tinton Falls, NJ 07724
* Phone: (201) 389-8963 (9-17 EST)
* Usenet: ...!uunet!pcrat!rick
*
* Please send results to Rick Richardson and/or Reinhold Weicker.
* Complete information should be given on hardware and software used.
* Hardware information includes: Machine type, CPU, type and size
* of caches; for microprocessors: clock frequency, memory speed
* (number of wait states).
* Software information includes: Compiler (and runtime library)
* manufacturer and version, compilation switches, OS version.
* The Operating System version may give an indication about the
* compiler; Dhrystone itself performs no OS calls in the measurement loop.
*
* The complete output generated by the program should be mailed
* such that at least some checks for correctness can be made.
*
***************************************************************************
*
* History: This version C/2.1 has been made for two reasons:
*
* 1) There is an obvious need for a common C version of
* Dhrystone, since C is at present the most popular system
* programming language for the class of processors
* (microcomputers, minicomputers) where Dhrystone is used most.
* There should be, as far as possible, only one C version of
* Dhrystone such that results can be compared without
* restrictions. In the past, the C versions distributed
* by Rick Richardson (Version 1.1) and by Reinhold Weicker
* had small (though not significant) differences.
*
* 2) As far as it is possible without changes to the Dhrystone
* statistics, optimizing compilers should be prevented from
* removing significant statements.
*
* This C version has been developed in cooperation with
* Rick Richardson (Tinton Falls, NJ), it incorporates many
* ideas from the "Version 1.1" distributed previously by
* him over the UNIX network Usenet.
* I also thank Chaim Benedelac (National Semiconductor),
* David Ditzel (SUN), Earl Killian and John Mashey (MIPS),
* Alan Smith and Rafael Saavedra-Barrera (UC at Berkeley)
* for their help with comments on earlier versions of the
* benchmark.
*
* Changes: In the initialization part, this version follows mostly
* Rick Richardson's version distributed via Usenet, not the
* version distributed earlier via floppy disk by Reinhold Weicker.
* As a concession to older compilers, names have been made
* unique within the first 8 characters.
* Inside the measurement loop, this version follows the
* version previously distributed by Reinhold Weicker.
*
* At several places in the benchmark, code has been added,
* but within the measurement loop only in branches that
* are not executed. The intention is that optimizing compilers
* should be prevented from moving code out of the measurement
* loop, or from removing code altogether. Since the statements
* that are executed within the measurement loop have NOT been
* changed, the numbers defining the "Dhrystone distribution"
* (distribution of statements, operand types and locality)
* still hold. Except for sophisticated optimizing compilers,
* execution times for this version should be the same as
* for previous versions.
*
* Since it has proven difficult to subtract the time for the
* measurement loop overhead in a correct way, the loop check
* has been made a part of the benchmark. This does have
* an impact - though a very minor one - on the distribution
* statistics which have been updated for this version.
*
* All changes within the measurement loop are described
* and discussed in the companion paper "Rationale for
* Dhrystone version 2".
*
* Because of the self-imposed limitation that the order and
* distribution of the executed statements should not be
* changed, there are still cases where optimizing compilers
* may not generate code for some statements. To a certain
* degree, this is unavoidable for small synthetic benchmarks.
* Users of the benchmark are advised to check code listings
* whether code is generated for all statements of Dhrystone.
*
* Version 2.1 is identical to version 2.0 distributed via
* the UNIX network Usenet in March 1988 except that it corrects
* some minor deficiencies that were found by users of version 2.0.
* The only change within the measurement loop is that a
* non-executed "else" part was added to the "if" statement in
* Func_3, and a non-executed "else" part removed from Proc_3.
*
***************************************************************************
*
* Defines: The following "Defines" are possible:
* -DREG=register (default: Not defined)
* As an approximation to what an average C programmer
* might do, the "register" storage class is applied
* (if enabled by -DREG=register)
* - for local variables, if they are used (dynamically)
* five or more times
* - for parameters if they are used (dynamically)
* six or more times
* Note that an optimal "register" strategy is
* compiler-dependent, and that "register" declarations
* do not necessarily lead to faster execution.
* -DNOSTRUCTASSIGN (default: Not defined)
* Define if the C compiler does not support
* assignment of structures.
* -DNOENUMS (default: Not defined)
* Define if the C compiler does not support
* enumeration types.
* -DTIMES (default)
* -DTIME
* The "times" function of UNIX (returning process times)
* or the "time" function (returning wallclock time)
* is used for measurement.
* For single user machines, "time ()" is adequate. For
* multi-user machines where you cannot get single-user
* access, use the "times ()" function. If you have
* neither, use a stopwatch in the dead of night.
* "printf"s are provided marking the points "Start Timer"
* and "Stop Timer". DO NOT use the UNIX "time(1)"
* command, as this will measure the total time to
* run this program, which will (erroneously) include
* the time to allocate storage (malloc) and to perform
* the initialization.
* -DHZ=nnn
* In Berkeley UNIX, the function "times" returns process
* time in 1/HZ seconds, with HZ = 60 for most systems.
* CHECK YOUR SYSTEM DESCRIPTION BEFORE YOU JUST APPLY
* A VALUE.
*
***************************************************************************
*
* Compilation model and measurement (IMPORTANT):
*
* This C version of Dhrystone consists of three files:
* - dhry.h (this file, containing global definitions and comments)
* - dhry_1.c (containing the code corresponding to Ada package Pack_1)
* - dhry_2.c (containing the code corresponding to Ada package Pack_2)
*
* The following "ground rules" apply for measurements:
* - Separate compilation
* - No procedure merging
* - Otherwise, compiler optimizations are allowed but should be indicated
* - Default results are those without register declarations
* See the companion paper "Rationale for Dhrystone Version 2" for a more
* detailed discussion of these ground rules.
*
* For 16-Bit processors (e.g. 80186, 80286), times for all compilation
* models ("small", "medium", "large" etc.) should be given if possible,
* together with a definition of these models for the compiler system used.
*
**************************************************************************
*
* Dhrystone (C version) statistics:
*
* [Comment from the first distribution, updated for version 2.
* Note that because of language differences, the numbers are slightly
* different from the Ada version.]
*
* The following program contains statements of a high level programming
* language (here: C) in a distribution considered representative:
*
* assignments 52 (51.0 %)
* control statements 33 (32.4 %)
* procedure, function calls 17 (16.7 %)
*
* 103 statements are dynamically executed. The program is balanced with
* respect to the three aspects:
*
* - statement type
* - operand type
* - operand locality
* operand global, local, parameter, or constant.
*
* The combination of these three aspects is balanced only approximately.
*
* 1. Statement Type:
* ----------------- number
*
* V1 = V2 9
* (incl. V1 = F(..)
* V = Constant 12
* Assignment, 7
* with array element
* Assignment, 6
* with record component
* --
* 34 34
*
* X = Y +|-|"&&"|"|" Z 5
* X = Y +|-|"==" Constant 6
* X = X +|- 1 3
* X = Y *|/ Z 2
* X = Expression, 1
* two operators
* X = Expression, 1
* three operators
* --
* 18 18
*
* if .... 14
* with "else" 7
* without "else" 7
* executed 3
* not executed 4
* for ... 7 | counted every time
* while ... 4 | the loop condition
* do ... while 1 | is evaluated
* switch ... 1
* break 1
* declaration with 1
* initialization
* --
* 34 34
*
* P (...) procedure call 11
* user procedure 10
* library procedure 1
* X = F (...)
* function call 6
* user function 5
* library function 1
* --
* 17 17
* ---
* 103
*
* The average number of parameters in procedure or function calls
* is 1.82 (not counting the function values aX *
*
* 2. Operators
* ------------
* number approximate
* percentage
*
* Arithmetic 32 50.8
*
* + 21 33.3
* - 7 11.1
* * 3 4.8
* / (int div) 1 1.6
*
* Comparison 27 42.8
*
* == 9 14.3
* /= 4 6.3
* > 1 1.6
* < 3 4.8
* >= 1 1.6
* <= 9 14.3
*
* Logic 4 6.3
*
* && (AND-THEN) 1 1.6
* | (OR) 1 1.6
* ! (NOT) 2 3.2
*
* -- -----
* 63 100.1
*
*
* 3. Operand Type (counted once per operand reference):
* ---------------
* number approximate
* percentage
*
* Integer 175 72.3 %
* Character 45 18.6 %
* Pointer 12 5.0 %
* String30 6 2.5 %
* Array 2 0.8 %
* Record 2 0.8 %
* --- -------
* 242 100.0 %
*
* When there is an access path leading to the final operand (e.g. a record
* component), only the final data type on the access path is counted.
*
*
* 4. Operand Locality:
* -------------------
* number approximate
* percentage
*
* local variable 114 47.1 %
* global variable 22 9.1 %
* parameter 45 18.6 %
* value 23 9.5 %
* reference 22 9.1 %
* function result 6 2.5 %
* constant 55 22.7 %
* --- -------
* 242 100.0 %
*
*
* The program does not compute anything meaningful, but it is syntactically
* and semantically correct. All variables have a value assigned to them
* before they are used as a source operand.
*
* There has been no explicit effort to account for the effects of a
* cache, or to balance the use of long or short displacements for code or
* data.
*
***************************************************************************
*/
/* Compiler and system dependent definitions: */
#ifndef TIME
#undef TIMES
#define TIMES
#endif
/* Use times(2) time function unless */
/* explicitly defined otherwise */
#ifdef MSC_CLOCK
#undef HZ
#undef TIMES
#include <time.h>
#define HZ CLK_TCK
#endif
/* Use Microsoft C hi-res clock */
#ifdef TIMES
#include <sys/types.h>
#include <sys/times.h>
/* for "times" */
#endif
#define Mic_secs_Per_Second 1000000.0
/* Berkeley UNIX C returns process times in seconds/HZ */
#ifdef NOSTRUCTASSIGN
#define structassign(d, s) memcpy(&(d), &(s), sizeof(d))
#else
#define structassign(d, s) d = s
#endif
#ifdef NOENUM
#define Ident_1 0
#define Ident_2 1
#define Ident_3 2
#define Ident_4 3
#define Ident_5 4
typedef int Enumeration;
#else
typedef enum {Ident_1, Ident_2, Ident_3, Ident_4, Ident_5}
Enumeration;
#endif
/* for boolean and enumeration types in Ada, Pascal */
/* General definitions: */
#include <stdio.h>
/* for strcpy, strcmp */
#define Null 0
/* Value of a Null pointer */
#define true 1
#define false 0
typedef int One_Thirty;
typedef int One_Fifty;
typedef char Capital_Letter;
typedef int Boolean;
typedef char Str_30 [31];
typedef int Arr_1_Dim [50];
typedef int Arr_2_Dim [50] [50];
typedef struct record
{
struct record *Ptr_Comp;
Enumeration Discr;
union {
struct {
Enumeration Enum_Comp;
int Int_Comp;
char Str_Comp [31];
} var_1;
struct {
Enumeration E_Comp_2;
char Str_2_Comp [31];
} var_2;
struct {
char Ch_1_Comp;
char Ch_2_Comp;
} var_3;
} variant;
} Rec_Type, *Rec_Pointer;
+2293
View File
File diff suppressed because it is too large Load Diff
+3555
View File
File diff suppressed because it is too large Load Diff
+402
View File
@@ -0,0 +1,402 @@
/*
****************************************************************************
*
* "DHRYSTONE" Benchmark Program
* -----------------------------
*
* Version: C, Version 2.1
*
* File: dhry_1.c (part 2 of 3)
*
* Date: May 25, 1988
*
* Author: Reinhold P. Weicker
*
****************************************************************************
*/
#include "dhry.h"
/* Global Variables: */
Rec_Pointer Ptr_Glob,
Next_Ptr_Glob;
int Int_Glob;
Boolean Bool_Glob;
char Ch_1_Glob,
Ch_2_Glob;
int Arr_1_Glob [50];
int Arr_2_Glob [50] [50];
extern char *malloc ();
Enumeration Func_1 ();
/* forward declaration necessary since Enumeration may not simply be int */
#ifndef REG
Boolean Reg = false;
#define REG
/* REG becomes defined as empty */
/* i.e. no register variables */
#else
Boolean Reg = true;
#endif
/* variables for time measurement: */
#ifdef TIMES
struct tms time_info;
/* see library function "times" */
#define Too_Small_Time (2*HZ)
/* Measurements should last at least about 2 seconds */
#endif
#ifdef TIME
extern long time();
/* see library function "time" */
#define Too_Small_Time 2
/* Measurements should last at least 2 seconds */
#endif
#ifdef MSC_CLOCK
extern clock_t clock();
#define Too_Small_Time (2*HZ)
#endif
long Begin_Time,
End_Time,
User_Time;
float Microseconds,
Dhrystones_Per_Second;
/* end of variables for time measurement */
main ()
/*****/
/* main program, corresponds to procedures */
/* Main and Proc_0 in the Ada version */
{
One_Fifty Int_1_Loc;
REG One_Fifty Int_2_Loc;
One_Fifty Int_3_Loc;
REG char Ch_Index;
Enumeration Enum_Loc;
Str_30 Str_1_Loc;
Str_30 Str_2_Loc;
REG int Run_Index;
REG int Number_Of_Runs;
/* Initializations */
Next_Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
Ptr_Glob = (Rec_Pointer) malloc (sizeof (Rec_Type));
Ptr_Glob->Ptr_Comp = Next_Ptr_Glob;
Ptr_Glob->Discr = Ident_1;
Ptr_Glob->variant.var_1.Enum_Comp = Ident_3;
Ptr_Glob->variant.var_1.Int_Comp = 40;
strcpy (Ptr_Glob->variant.var_1.Str_Comp,
"DHRYSTONE PROGRAM, SOME STRING");
strcpy (Str_1_Loc, "DHRYSTONE PROGRAM, 1'ST STRING");
Arr_2_Glob [8][7] = 10;
/* Was missing in published program. Without this statement, */
/* Arr_2_Glob [8][7] would have an undefined value. */
/* Warning: With 16-Bit processors and Number_Of_Runs > 32000, */
/* overflow may occur for this array element. */
/*
printf ("\n");
printf ("Dhrystone Benchmark, Version 2.1 (Language: C)\n");
printf ("\n");
if (Reg)
{
printf ("Program compiled with 'register' attribute\n");
printf ("\n");
}
else
{
printf ("Program compiled without 'register' attribute\n");
printf ("\n");
}
printf ("Please give the number of runs through the benchmark: ");
{
int n;
scanf ("%d", &n);
Number_Of_Runs = n;
}
printf ("\n");
*/
#ifdef NRUNS
Number_Of_Runs = NRUNS;
#else
Number_Of_Runs = 2000000;
#endif
printf ("Execution starts, %d runs through Dhrystone\n", Number_Of_Runs);
/***************/
/* Start timer */
/***************/
#ifdef TIMES
times (&time_info);
Begin_Time = (long) time_info.tms_utime;
#endif
#ifdef TIME
Begin_Time = time ( (long *) 0);
#endif
#ifdef MSC_CLOCK
Begin_Time = clock();
#endif
for (Run_Index = 1; Run_Index <= Number_Of_Runs; ++Run_Index)
{
Proc_5();
Proc_4();
/* Ch_1_Glob == 'A', Ch_2_Glob == 'B', Bool_Glob == true */
Int_1_Loc = 2;
Int_2_Loc = 3;
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 2'ND STRING");
Enum_Loc = Ident_2;
Bool_Glob = ! Func_2 (Str_1_Loc, Str_2_Loc);
/* Bool_Glob == 1 */
while (Int_1_Loc < Int_2_Loc) /* loop body executed once */
{
Int_3_Loc = 5 * Int_1_Loc - Int_2_Loc;
/* Int_3_Loc == 7 */
Proc_7 (Int_1_Loc, Int_2_Loc, &Int_3_Loc);
/* Int_3_Loc == 7 */
Int_1_Loc += 1;
} /* while */
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
Proc_8 (Arr_1_Glob, Arr_2_Glob, Int_1_Loc, Int_3_Loc);
/* Int_Glob == 5 */
Proc_1 (Ptr_Glob);
for (Ch_Index = 'A'; Ch_Index <= Ch_2_Glob; ++Ch_Index)
/* loop body executed twice */
{
if (Enum_Loc == Func_1 (Ch_Index, 'C'))
/* then, not executed */
{
Proc_6 (Ident_1, &Enum_Loc);
strcpy (Str_2_Loc, "DHRYSTONE PROGRAM, 3'RD STRING");
Int_2_Loc = Run_Index;
Int_Glob = Run_Index;
}
}
/* Int_1_Loc == 3, Int_2_Loc == 3, Int_3_Loc == 7 */
Int_2_Loc = Int_2_Loc * Int_1_Loc;
Int_1_Loc = Int_2_Loc / Int_3_Loc;
Int_2_Loc = 7 * (Int_2_Loc - Int_3_Loc) - Int_1_Loc;
/* Int_1_Loc == 1, Int_2_Loc == 13, Int_3_Loc == 7 */
Proc_2 (&Int_1_Loc);
/* Int_1_Loc == 5 */
} /* loop "for Run_Index" */
/**************/
/* Stop timer */
/**************/
#ifdef TIMES
times (&time_info);
End_Time = (long) time_info.tms_utime;
#endif
#ifdef TIME
End_Time = time ( (long *) 0);
#endif
#ifdef MSC_CLOCK
End_Time = clock();
#endif
/*
printf ("Execution ends\n");
printf ("\n");
printf ("Final values of the variables used in the benchmark:\n");
printf ("\n");
printf ("Int_Glob: %d\n", Int_Glob);
printf (" should be: %d\n", 5);
printf ("Bool_Glob: %d\n", Bool_Glob);
printf (" should be: %d\n", 1);
printf ("Ch_1_Glob: %c\n", Ch_1_Glob);
printf (" should be: %c\n", 'A');
printf ("Ch_2_Glob: %c\n", Ch_2_Glob);
printf (" should be: %c\n", 'B');
printf ("Arr_1_Glob[8]: %d\n", Arr_1_Glob[8]);
printf (" should be: %d\n", 7);
printf ("Arr_2_Glob[8][7]: %d\n", Arr_2_Glob[8][7]);
printf (" should be: Number_Of_Runs + 10\n");
printf ("Ptr_Glob->\n");
printf (" Ptr_Comp: %d\n", (int) Ptr_Glob->Ptr_Comp);
printf (" should be: (implementation-dependent)\n");
printf (" Discr: %d\n", Ptr_Glob->Discr);
printf (" should be: %d\n", 0);
printf (" Enum_Comp: %d\n", Ptr_Glob->variant.var_1.Enum_Comp);
printf (" should be: %d\n", 2);
printf (" Int_Comp: %d\n", Ptr_Glob->variant.var_1.Int_Comp);
printf (" should be: %d\n", 17);
printf (" Str_Comp: %s\n", Ptr_Glob->variant.var_1.Str_Comp);
printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
printf ("Next_Ptr_Glob->\n");
printf (" Ptr_Comp: %d\n", (int) Next_Ptr_Glob->Ptr_Comp);
printf (" should be: (implementation-dependent), same as above\n");
printf (" Discr: %d\n", Next_Ptr_Glob->Discr);
printf (" should be: %d\n", 0);
printf (" Enum_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Enum_Comp);
printf (" should be: %d\n", 1);
printf (" Int_Comp: %d\n", Next_Ptr_Glob->variant.var_1.Int_Comp);
printf (" should be: %d\n", 18);
printf (" Str_Comp: %s\n",
Next_Ptr_Glob->variant.var_1.Str_Comp);
printf (" should be: DHRYSTONE PROGRAM, SOME STRING\n");
printf ("Int_1_Loc: %d\n", Int_1_Loc);
printf (" should be: %d\n", 5);
printf ("Int_2_Loc: %d\n", Int_2_Loc);
printf (" should be: %d\n", 13);
printf ("Int_3_Loc: %d\n", Int_3_Loc);
printf (" should be: %d\n", 7);
printf ("Enum_Loc: %d\n", Enum_Loc);
printf (" should be: %d\n", 1);
printf ("Str_1_Loc: %s\n", Str_1_Loc);
printf (" should be: DHRYSTONE PROGRAM, 1'ST STRING\n");
printf ("Str_2_Loc: %s\n", Str_2_Loc);
printf (" should be: DHRYSTONE PROGRAM, 2'ND STRING\n");
printf ("\n");
*/
User_Time = End_Time - Begin_Time;
if (User_Time < Too_Small_Time)
{
printf ("Measured time too small to obtain meaningful results\n");
printf ("Please increase number of runs\n");
printf ("\n");
}
else
{
#ifdef TIME
Microseconds = (float) User_Time * Mic_secs_Per_Second
/ (float) Number_Of_Runs;
Dhrystones_Per_Second = (float) Number_Of_Runs / (float) User_Time;
#else
Microseconds = (float) User_Time * Mic_secs_Per_Second
/ ((float) HZ * ((float) Number_Of_Runs));
Dhrystones_Per_Second = ((float) HZ * (float) Number_Of_Runs)
/ (float) User_Time;
#endif
printf ("Microseconds for one run through Dhrystone: ");
printf ("%6.1f \n", Microseconds);
printf ("Dhrystones per Second: ");
printf ("%6.1f \n", Dhrystones_Per_Second);
printf ("\n");
printf ("This equals to %6.1f DMIPS\n", Dhrystones_Per_Second/1757);
}
}
Proc_1 (Ptr_Val_Par)
/******************/
REG Rec_Pointer Ptr_Val_Par;
/* executed once */
{
REG Rec_Pointer Next_Record = Ptr_Val_Par->Ptr_Comp;
/* == Ptr_Glob_Next */
/* Local variable, initialized with Ptr_Val_Par->Ptr_Comp, */
/* corresponds to "rename" in Ada, "with" in Pascal */
structassign (*Ptr_Val_Par->Ptr_Comp, *Ptr_Glob);
Ptr_Val_Par->variant.var_1.Int_Comp = 5;
Next_Record->variant.var_1.Int_Comp
= Ptr_Val_Par->variant.var_1.Int_Comp;
Next_Record->Ptr_Comp = Ptr_Val_Par->Ptr_Comp;
Proc_3 (&Next_Record->Ptr_Comp);
/* Ptr_Val_Par->Ptr_Comp->Ptr_Comp
== Ptr_Glob->Ptr_Comp */
if (Next_Record->Discr == Ident_1)
/* then, executed */
{
Next_Record->variant.var_1.Int_Comp = 6;
Proc_6 (Ptr_Val_Par->variant.var_1.Enum_Comp,
&Next_Record->variant.var_1.Enum_Comp);
Next_Record->Ptr_Comp = Ptr_Glob->Ptr_Comp;
Proc_7 (Next_Record->variant.var_1.Int_Comp, 10,
&Next_Record->variant.var_1.Int_Comp);
}
else /* not executed */
structassign (*Ptr_Val_Par, *Ptr_Val_Par->Ptr_Comp);
} /* Proc_1 */
Proc_2 (Int_Par_Ref)
/******************/
/* executed once */
/* *Int_Par_Ref == 1, becomes 4 */
One_Fifty *Int_Par_Ref;
{
One_Fifty Int_Loc;
Enumeration Enum_Loc;
Int_Loc = *Int_Par_Ref + 10;
do /* executed once */
if (Ch_1_Glob == 'A')
/* then, executed */
{
Int_Loc -= 1;
*Int_Par_Ref = Int_Loc - Int_Glob;
Enum_Loc = Ident_1;
} /* if */
while (Enum_Loc != Ident_1); /* true */
} /* Proc_2 */
Proc_3 (Ptr_Ref_Par)
/******************/
/* executed once */
/* Ptr_Ref_Par becomes Ptr_Glob */
Rec_Pointer *Ptr_Ref_Par;
{
if (Ptr_Glob != Null)
/* then, executed */
*Ptr_Ref_Par = Ptr_Glob->Ptr_Comp;
Proc_7 (10, Int_Glob, &Ptr_Glob->variant.var_1.Int_Comp);
} /* Proc_3 */
Proc_4 () /* without parameters */
/*******/
/* executed once */
{
Boolean Bool_Loc;
Bool_Loc = Ch_1_Glob == 'A';
Bool_Glob = Bool_Loc | Bool_Glob;
Ch_2_Glob = 'B';
} /* Proc_4 */
Proc_5 () /* without parameters */
/*******/
/* executed once */
{
Ch_1_Glob = 'A';
Bool_Glob = false;
} /* Proc_5 */
/* Procedure for the assignment of structures, */
/* if the C compiler doesn't support this feature */
#ifdef NOSTRUCTASSIGN
memcpy (d, s, l)
register char *d;
register char *s;
register int l;
{
while (l--) *d++ = *s++;
}
#endif
+192
View File
@@ -0,0 +1,192 @@
/*
****************************************************************************
*
* "DHRYSTONE" Benchmark Program
* -----------------------------
*
* Version: C, Version 2.1
*
* File: dhry_2.c (part 3 of 3)
*
* Date: May 25, 1988
*
* Author: Reinhold P. Weicker
*
****************************************************************************
*/
#include "dhry.h"
#ifndef REG
#define REG
/* REG becomes defined as empty */
/* i.e. no register variables */
#endif
extern int Int_Glob;
extern char Ch_1_Glob;
Proc_6 (Enum_Val_Par, Enum_Ref_Par)
/*********************************/
/* executed once */
/* Enum_Val_Par == Ident_3, Enum_Ref_Par becomes Ident_2 */
Enumeration Enum_Val_Par;
Enumeration *Enum_Ref_Par;
{
*Enum_Ref_Par = Enum_Val_Par;
if (! Func_3 (Enum_Val_Par))
/* then, not executed */
*Enum_Ref_Par = Ident_4;
switch (Enum_Val_Par)
{
case Ident_1:
*Enum_Ref_Par = Ident_1;
break;
case Ident_2:
if (Int_Glob > 100)
/* then */
*Enum_Ref_Par = Ident_1;
else *Enum_Ref_Par = Ident_4;
break;
case Ident_3: /* executed */
*Enum_Ref_Par = Ident_2;
break;
case Ident_4: break;
case Ident_5:
*Enum_Ref_Par = Ident_3;
break;
} /* switch */
} /* Proc_6 */
Proc_7 (Int_1_Par_Val, Int_2_Par_Val, Int_Par_Ref)
/**********************************************/
/* executed three times */
/* first call: Int_1_Par_Val == 2, Int_2_Par_Val == 3, */
/* Int_Par_Ref becomes 7 */
/* second call: Int_1_Par_Val == 10, Int_2_Par_Val == 5, */
/* Int_Par_Ref becomes 17 */
/* third call: Int_1_Par_Val == 6, Int_2_Par_Val == 10, */
/* Int_Par_Ref becomes 18 */
One_Fifty Int_1_Par_Val;
One_Fifty Int_2_Par_Val;
One_Fifty *Int_Par_Ref;
{
One_Fifty Int_Loc;
Int_Loc = Int_1_Par_Val + 2;
*Int_Par_Ref = Int_2_Par_Val + Int_Loc;
} /* Proc_7 */
Proc_8 (Arr_1_Par_Ref, Arr_2_Par_Ref, Int_1_Par_Val, Int_2_Par_Val)
/*********************************************************************/
/* executed once */
/* Int_Par_Val_1 == 3 */
/* Int_Par_Val_2 == 7 */
Arr_1_Dim Arr_1_Par_Ref;
Arr_2_Dim Arr_2_Par_Ref;
int Int_1_Par_Val;
int Int_2_Par_Val;
{
REG One_Fifty Int_Index;
REG One_Fifty Int_Loc;
Int_Loc = Int_1_Par_Val + 5;
Arr_1_Par_Ref [Int_Loc] = Int_2_Par_Val;
Arr_1_Par_Ref [Int_Loc+1] = Arr_1_Par_Ref [Int_Loc];
Arr_1_Par_Ref [Int_Loc+30] = Int_Loc;
for (Int_Index = Int_Loc; Int_Index <= Int_Loc+1; ++Int_Index)
Arr_2_Par_Ref [Int_Loc] [Int_Index] = Int_Loc;
Arr_2_Par_Ref [Int_Loc] [Int_Loc-1] += 1;
Arr_2_Par_Ref [Int_Loc+20] [Int_Loc] = Arr_1_Par_Ref [Int_Loc];
Int_Glob = 5;
} /* Proc_8 */
Enumeration Func_1 (Ch_1_Par_Val, Ch_2_Par_Val)
/*************************************************/
/* executed three times */
/* first call: Ch_1_Par_Val == 'H', Ch_2_Par_Val == 'R' */
/* second call: Ch_1_Par_Val == 'A', Ch_2_Par_Val == 'C' */
/* third call: Ch_1_Par_Val == 'B', Ch_2_Par_Val == 'C' */
Capital_Letter Ch_1_Par_Val;
Capital_Letter Ch_2_Par_Val;
{
Capital_Letter Ch_1_Loc;
Capital_Letter Ch_2_Loc;
Ch_1_Loc = Ch_1_Par_Val;
Ch_2_Loc = Ch_1_Loc;
if (Ch_2_Loc != Ch_2_Par_Val)
/* then, executed */
return (Ident_1);
else /* not executed */
{
Ch_1_Glob = Ch_1_Loc;
return (Ident_2);
}
} /* Func_1 */
Boolean Func_2 (Str_1_Par_Ref, Str_2_Par_Ref)
/*************************************************/
/* executed once */
/* Str_1_Par_Ref == "DHRYSTONE PROGRAM, 1'ST STRING" */
/* Str_2_Par_Ref == "DHRYSTONE PROGRAM, 2'ND STRING" */
Str_30 Str_1_Par_Ref;
Str_30 Str_2_Par_Ref;
{
REG One_Thirty Int_Loc;
Capital_Letter Ch_Loc;
Int_Loc = 2;
while (Int_Loc <= 2) /* loop body executed once */
if (Func_1 (Str_1_Par_Ref[Int_Loc],
Str_2_Par_Ref[Int_Loc+1]) == Ident_1)
/* then, executed */
{
Ch_Loc = 'A';
Int_Loc += 1;
} /* if, while */
if (Ch_Loc >= 'W' && Ch_Loc < 'Z')
/* then, not executed */
Int_Loc = 7;
if (Ch_Loc == 'R')
/* then, not executed */
return (true);
else /* executed */
{
if (strcmp (Str_1_Par_Ref, Str_2_Par_Ref) > 0)
/* then, not executed */
{
Int_Loc += 7;
Int_Glob = Int_Loc;
return (true);
}
else /* executed */
return (false);
} /* if Ch_Loc */
} /* Func_2 */
Boolean Func_3 (Enum_Par_Val)
/***************************/
/* executed once */
/* Enum_Par_Val == Ident_3 */
Enumeration Enum_Par_Val;
{
Enumeration Enum_Loc;
Enum_Loc = Enum_Par_Val;
if (Enum_Loc == Ident_3)
/* then, executed */
return (true);
else /* not executed */
return (false);
} /* Func_3 */
+35
View File
@@ -0,0 +1,35 @@
/* WinBond bug report
Please don't use "gcc -O3 -S hello.c" command, because it
will optimize "i/5" to be "2" in compile time.
*/
#include <stdio.h>
#define TESTSEED 10
main ()
{
int a1,b1,c1;
long a2,b2,c2;
double a3,b3,c3;
float a4,b4,c4;
char buf[20];
/* integer tests */
for (a1 = 1; a1 < 16; a1++) {
b1 = TESTSEED/a1;
c1 = TESTSEED%a1;
printf ("%d/%d = %d, ^ = %d\n", TESTSEED, a1, b1, c1);
if ((c1 + (a1 * b1)) == TESTSEED) {
sprintf (buf, "div %d by %d", TESTSEED, a1);
printf ("Passed: %s\n", buf);
} else {
sprintf (buf, "div %d by %d", TESTSEED, a1);
printf ("Failed: %s\n", buf);
}
fflush (stdout);
}
}
+33
View File
@@ -0,0 +1,33 @@
/* Oki bug report [OKI001](gcc008_1)
The following program is not executed.
error messages are as follow.
illegal trap: 0x12 pc=d000d954
d000d954 08000240 NOP
*/
#include <stdio.h>
extern double dcall ();
main ()
{
double d1, d2, d3;
int i;
d1 = dcall (1.);
printf ("d1 = %e\n", d1);
printf ("double [OKI001]");
fflush(stdout);
}
double
dcall (d)
double d;
{
int Zero = 0;
return d + Zero;
}
BIN
View File
Binary file not shown.
+261
View File
@@ -0,0 +1,261 @@
/* dttl.c -- simulation of Cassini/Huygens symbol synchronizer loop
*
* Author: Lorenzo Simone's (matlab script)
* Modifications by: Jon Hamkins (conversion to C, support routines,
* memory requirement reductions)
* Last Revised: Wed Jan 31 10:47:52 PST 2001
*/
#define M_PI 3.1415926535897932384626433832795
#include <math.h>
#include <stdio.h>
#include "random.h"
/* global variables */
int delay,
L; /* samples per symbol */
double Pt, /* transition density */
sigma; /* noise standard deviation */
long seed=-123;
/* This function simulates a large 1-dimensional array without requiring
* storage for the whole array. This is possible because the array is
* accessed in roughly increasing indices. Thus, we only need to
* store a few symbols worth of samples in the array, and we can reuse
* the array indices as time goes on. */
int drint(double v)
{
return (int)(v+0.5);
}
double
rec(int idx)
{
static int firsttime = 1,
max, /* maximum index containing data */
mod, /* length of ring buffer */
b; /* value of last transmitted bit */
static double r[2000]; /* need several symbols worth of samples */
int i,j,k;
/* First time, store samples for random delay and first few symbols */
if (firsttime==1) {
firsttime=0;
for (i=0; i<delay; i++) r[i] = 0; /* random delay */
b = (ran1(&seed)>0.5) ? 1 : -1; /* first random symbol */
for (j=0; j<3; j++) { /* 3 binary symbols with transition Pt */
b = (ran1(&seed)>Pt) ? b : -b; /* next symbol value */
for (k=0; k<L; k++) r[i++] = b + sigma*gaussian(&seed);
}
max = i-1;
mod = i;
}
if (idx>max) /* check if we need to create another sample */
{
b = (ran1(&seed)>Pt) ? b : -b; /* next symbol value */
/* generate samples for one symbol and store in ring buffer */
for (i=1; i<=L; i++) r[(int)(fmod(max+i,mod))] = b+sigma*gaussian(&seed);
max += L; /* maximum index for which samples exist */
}
/* return appropriate sample from ring buffer */
return(r[(int)(fmod(idx,mod))]);
}
main()
{
double
detout, /* detector output */
I, old_I, /* in-phase accumulations */
Q, old_Q, /* quadrature accumulations */
T, /* transition detection */
theta, /* baseband NCO output (radians) */
lambda, /* normalized timing error (symbols) */
A, alfa, Ampl, Bl, Df,
DR, Es_No, Es_No_lin, Fc1, Fc2, Fvco, Fs, Kd, Kv,
lambda_ss_sim = 0., lambda_ss_th, No, P, P_No,
sigma_lambda_sim = 0., sigma_lambda_th, SNR_sim, SNR_th, tau, Tc1, Tc2,
time, Ts, x1, Y, bit_I, bit_Q, bit;
int i, j, k, N, offset, k1, k2, EOB;
FILE *p1, *p2, *p3, *p4, *p5;
/* Data settings */
Fc1 = 48000; /* sample rate at DTTL input (F1/2 = 8.215MHz/2) */
Tc1 = 1./Fc1;
DR = 4800; /* data rate (symb/sec) */
Fc2 = DR; /* sampling rate pre-detection */
Tc2 = 1./Fc2;
L = drint(Tc2/Tc1); /* samples per symbol in the arm filters */
offset = drint(L/2.);
Es_No = 600.; /* dB */
P_No = Es_No+10.*log10(DR); /* data power-over-noise spectral density */
/* ratio (dBHz) */
N = 2500; /* number of symbols to simulate */
Pt=.5; /* Transition density */
Bl=0.01*DR; /* loop bandwidth (Hz) */
Df=0.001*DR; /* frequency offset */
Fvco=DR+Df;
tau=ran1(&seed)-.5; /* set symbol timing offset, -.5 to .5 */
delay=drint(2.*L+tau*L+1); /* channel delay */
P=1.; /* data power */
Ampl=sqrt(P);
No=10.*log10(P*Tc2)-Es_No; /* noise spectral density (dBW/Hz) */
sigma=sqrt(pow(10.,0.1*No)/(2.*Tc1));
printf("sigma=%f\n",sigma);
/* DPLL settings */
Fs=DR; /* loop sampling frequency (Hz) */
Ts=1./Fs; /* loop sampling time (s) */
/* Loop gain */
Kd=2.*Ampl*Pt; /* phase detector gain (quants/rad) */
/* @ high Es/No */
Kv=1.; /* VCO gain (rad/quants) */
/* Analog loop filter components */
alfa=4.*Bl/(Kd*Kv);
/* Digital loop filter components */
A=alfa*Ts;
/* Initial condition */
theta = 0;
old_I=1;
old_Q=1;
x1=0;
Y=0;
/* Plot data files */
// p1 = fopen("plot1.dat","w"); /* theta */
// p2 = fopen("plot2.dat","w"); /* lambda */
// p3 = fopen("plot3.dat","w"); /* detout */
// p4 = fopen("plot4.dat","w"); /* I-Data */
// p5 = fopen("plot5.dat","w"); /* Q-Data */
k1 = drint(0.5*N);
k2 = N;
printf("Data rate: %.0f symbols/sec\n",DR);
printf("Sample rate at DTTL input: %.0f samples/sec\n",Fc1);
printf("Samples per symbol: %d\n",L);
printf("Random delay set to: %f symbols (%d samples)\n",tau,delay);
printf("Transition density used in random bit generation: %f\n",Pt);
printf("Es/No: %f dB\n",Es_No);
printf("Loop bandwidth: %f Hz\n",Bl);
printf("Doppler: %f Hz\n",Df);
printf("Simulation length: %d symbols (%d samples)\n\n",N,N*L+delay);
/* Simulation Loop */
for (i=2; i<=N; i++)
{
/* loop over symbols */
/* find start of in-phase integration */
for (j=1; j < L; j++)
{
if (fmod(theta + 2*M_PI * Fvco*(j+1+(i-1)*(Fc1/DR))/Fc1, 2*M_PI)
< fmod(theta + 2*M_PI * Fvco*(j +(i-1)*(Fc1/DR))/Fc1, 2*M_PI))
break;
/* one could replace loop above with a direct calculation such as: */
/* j=ceil((1.-modulo(theta/(2*M_PI),1.))/(Fvco*Tc1))-1.; */
/* j+1 is the first index in the block */
EOB=j+(i-1)*L; /* End of Block */
}
/* In-phase integrator */
bit_I = 0.;
printf("Symbol # %d\n", i);
printf("I[%d:%d] :\n", EOB-L+1, EOB);
for (j=EOB-L+1; j<=EOB; j++)
{
bit = rec(j);
if (bit > 0)
printf("-");
else
printf("_");
bit_I += bit;
}
printf("\n");
I = bit_I;
/* Mid-Phase integrator */
bit_Q = 0.;
printf("Q[%d:%d] :\n", EOB-L+offset+1, EOB+offset);
for (j=EOB-L+offset+1; j<=EOB+offset; j++)
{
bit = rec(j);
if (bit > 0)
printf("-");
else
printf("_");
bit_Q += bit;
}
printf("\n\n");
Q = bit_Q;
Q *= 2.*M_PI/(Tc2/Tc1);
/* Transition Detector */
I = (I > 0) ? 1. : -1.; /* hard limiter */
T = 0.5*(I - old_I);
/* Detector Output */
detout = fmod(old_Q*T,2*M_PI);
/* Save accumulations for next time through loop */
old_I = I;
old_Q = Q;
if (fabs(detout)>M_PI)
detout = -detout+2*M_PI*((detout>0) ? 1. : -1.);
/* NCO */
Y += detout*A; /* Loop filter */
theta=Kv*Y; /* phase */
// lambda = theta/(2.*M_PI)+(i*Tc2*Df+tau); /* normalized error */
lambda = theta/(2.*M_PI)+(i*(Fvco/DR -1) + tau); /* normalized error */
/* error mean and variance calculation */
lambda_ss_sim += lambda; /* partial sum */
sigma_lambda_sim += lambda*lambda; /* partial sum of squares */
/* store phase and normalized error to data files */
// fprintf(p1,"%f %f\n",(double)i,theta);
// fprintf(p2,"%f %f\n",(double)i,lambda);
// fprintf(p3,"%f %f\n",(double)i,detout);
// fprintf(p4,"%f %f\n",(double)i,I);
// fprintf(p5,"%f %f\n",(double)i,Q);
}
// fclose(p1);
// fclose(p2);
// fclose(p3);
// fclose(p4);
// fclose(p5);
/* Statistics Analysis */
/* ------------------- */
/* complete the mean and variance calculation */
lambda_ss_sim /= N;
sigma_lambda_sim = sigma_lambda_sim/N - lambda_ss_sim*lambda_ss_sim;
Es_No_lin = pow(10.,0.1*Es_No);
// sigma_lambda_th = Bl*Tc2/(4.*Pt*Es_No_lin*pow(erf(sqrt(Es_No_lin)),2.));
sigma_lambda_th = Bl*Tc2/(4.*Pt*Es_No_lin*Es_No_lin);
SNR_sim = -10*log10(sigma_lambda_sim);
SNR_th = -10*log10(sigma_lambda_th);
/* Steady-State error */
lambda_ss_th=Df/(4.*Bl);
printf("Simulation: var: %f rad^2 loop SNR: %f dB ss error: %f%%\n",
sigma_lambda_sim, SNR_sim, 100.*lambda_ss_sim);
printf("Theory: var: %f rad^2 loop SNR: %f dB ss error: %f%%\n",
sigma_lambda_th, SNR_th, 100.*lambda_ss_th);
// system("gnuplot < plot1.gp");
// system("gnuplot < plot2.gp");
printf("Done.\n");
}
+15010
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
Binary file not shown.
+2353
View File
File diff suppressed because it is too large Load Diff
+4001
View File
File diff suppressed because it is too large Load Diff
BIN
View File
Binary file not shown.
+8
View File
@@ -0,0 +1,8 @@
float s=1944,x[5],y[5],z[5],r[5],j,h,a,b,d,e;int i=33,c,l,f=1;int g(){return f=
(f*6478+1)%65346;}m(){x[i]=g()-l;y[i]=(g()-l)/4;r[i]=g()>>4;}main(){char t[1948
]=" `MYmtw%FFlj%Jqig~%`jqig~Etsqnsj3stb",*p=t+3,*k="3tjlq9TX";l=s*20;while(i<s)
p[i++]='\n'+5;for(i=0;i<5;i++)z[i]=(i?z[i-1]:0)+l/3+!m();while(1){for(c=33;c<s;
c++){c+=!((c+1)%81);j=c/s-.5;h=c%81/40.0-1;p[c]=37;for(i=4;i+1;i--)if((b=(a=h*x
[i]+j*y[i]+z[i])*a-(d=1+j*j+h*h)*(-r[i]*r[i]+x[i]*x[i]+y[i]*y[i]+z[i]*z[i]))>0)
{for(e=b;e*e>b*1.01||e*e<b*.99;e-=.5*(e*e-b)/e);p[c]=k[(int)(8*e/d/r[i])];}}for
(i=4;i+1;z[i]-=s/2,i--)z[i]=z[i]<0?l*2+!m():z[i];while(i<s)putchar(t[i++]-5);}}
+7
View File
@@ -0,0 +1,7 @@
phrasen.c: In function `main':
phrasen.c:161: warning: return type of 'main' is not `int'
/tmp/ccW1wSMZ.o: In function `getch':
phrasen.c:(.text+0x7): undefined reference to `readchar'
/tmp/ccW1wSMZ.o: In function `main':
phrasen.c:(.text+0x34): undefined reference to `randomize'
collect2: ld returned 1 exit status
+389
View File
@@ -0,0 +1,389 @@
/***************************************************************************
PART 1: PROGRAM
Pierre Ouellet ID 9009791
The problem solved by this program is stated as follows:
Given a set S of k nonzero natural numbers, labeled n1..nk,
a "total" t, which is also a nonzero natural number, find
an expression tree, whose leaves are taken from S, and whose
interior nodes are each labeled one of {+, -, *, /}, and that
evaluates to t. There is the additional restriction that any
subtree must evaluate to a natural number greater than 0.
Division is permitted only if the value of the left child
is exactly divisible by the value of the right child. Also,
numbers in S may not be used more times than they appear,
e.g. if S = { 2, 3, 3 }, "3" may be used at most twice.
The program uses a brute-force search, more precisely an
iterative deepening depth-first search. The search can be
viewed as an attempt to build the tree bottom-up: whenever
the value t is not present, we try to obtain it by "combining"
two available values, which are taken from the "work list",
which consists of those elements of S not yet used and the values
obtained by previous combinations. This is the equivalent of
creating a new root and making the two operands its children.
The work list is an array of integers, originally containing
the elements of S. When elements are combined, they're marked
used and the result of combining them (the result of evaluating
the new root) is added at the end of the list.
The combinations are saved in an array of Comb, to be printed out
when a solution is found.
***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#define NOOP 0
#define ADD 1
#define SUB 2
#define MUL 3
#define DIV 4
typedef struct
{
int operand1, operand2;
int operation;
} Comb;
/* Global variables are used to save time during the search */
static int goal; /* the value of t explained above */
static int listLength; /* |S| */
static int *workList;
static Comb *combList;
static Comb *solution;
static int best = 0; /* value of best solution found yet */
static int dmax; /* maximal depth of search */
static int stopSearch; /* flag so we stop at first solution */
static int bestDepth = 0; /* depth of best solution; used if no exact
solution is found */
static int nbNodes; /* statistics: number of nodes examined
(number of calls to recSearch) */
/************************* INITIALIZATION STUFF *************************/
int *newWorkList( int length )
/* Create a "work list", which is an array of integers with length
elements
*/
{
int *newList = (int *) calloc( length, sizeof( int ) );
if( newList ) return newList;
else
{
fprintf( stderr, "Out of memory for work list\n" );
exit( 1 );
}
}
Comb *newCombList( int length )
/* Create a "combination list", which is to be used all the way through
the search. It contains the combinations attempted so far in the search.
*/
{
Comb *newList = (Comb *) calloc( length, sizeof( Comb ) );
if( newList ) return newList;
else
{
fprintf( stderr, "Out of memory for combination list\n" );
exit( 1 );
}
}
void initWorkList( int *workList, int *givenList, int length )
{
int i;
for( i = 0; i < length; i++ )
workList[i] = givenList[i];
}
void initCombList( Comb *combList, int length )
{
int i;
for( i = 0; i < length; i++ )
combList[i].operation = NOOP;
}
/************************* AUXILIARY FUNCTIONS *************************/
void saveSolution( Comb *sol, Comb *combList, int length )
/* Copy a sequence of combinations.
*/
{
int i;
for( i = 0; i < length; i++ )
{
sol[i].operand1 = combList[i].operand1;
sol[i].operand2 = combList[i].operand2;
sol[i].operation = combList[i].operation;
}
sol[length].operation = NOOP; /* End marker */
}
int calculate( Comb *comb )
/* Compute the value generated by a combination.
*/
{
switch( comb->operation )
{
case ADD: return comb->operand1 + comb->operand2;
case SUB: return comb->operand1 - comb->operand2;
case MUL: return comb->operand1 * comb->operand2;
case DIV: return comb->operand1 / comb->operand2;
default: return 0;
}
}
/************************* OUTPUT STUFF *************************/
void printSolution( Comb *combList, int length )
{
int i;
for( i = 0; i < length; i++ )
{
printf( "%d", combList[i].operand1 );
switch( combList[i].operation )
{
case NOOP: printf( " " ); break;
case ADD: printf( "+" ); break;
case SUB: printf( "-" ); break;
case MUL: printf( "*" ); break;
case DIV: printf( ":" ); break;
default: printf( " d%d ", combList[i].operation );
}
printf( "%d=%d", combList[i].operand2, calculate( &combList[i] ) );
if( i < length - 1 ) printf( "; " ); else printf( ".\n" );
}
printf( "\n" );
}
void printList( int *list, int length, int mask )
{
int i;
for( i = 0; i < length; i++ )
{
if( ( 1 << i ) & mask ) continue;
printf( "%d ", list[i] );
}
printf( "\n" );
}
/************************* ACTUAL SEARCH STUFF *************************/
void recSearch( int searchDepth, int usedMask )
/* searchDepth: current depth within the search.
usedMask: used to tell which elements of the work list
have been used.
*/
{
int currOp; /* current operation under consideration */
int newMask; /* or'ed with old mask to mark used numbers from work list */
int operand1; /* offset of operand 1 of combination within work list */
int operand2; /* offset of operand 2 of combination within work list */
if( stopSearch ) return; /* unroll recursion when solution is found */
nbNodes++; /* Statistics */
if( searchDepth == dmax )
{
/* check whether last number generated is nearer to t than best */
if( abs( workList[listLength + searchDepth - 1] - goal )
< abs( best - goal ) )
{
/* if so, save solution */
best = workList[listLength + searchDepth - 1];
bestDepth = searchDepth;
saveSolution( solution, combList, searchDepth );
if( best == goal )
{
printSolution( combList, searchDepth );
stopSearch = 1;
}
}
}
else
{
int working1, working2; /* hold values of numbers considered
for combination */
int temp; /* for swapping */
/* iterate over all four operators {+, -, *, /} */
for( currOp = ADD; currOp <= DIV; currOp++ )
{
for( operand1 = 0; operand1 < listLength + searchDepth;
operand1++ )
{
/* do not use already used numbers */
if( ( 1 << operand1 ) & usedMask ) continue;
for( operand2 = 0; operand2 < operand1; operand2++ )
{
if( ( 1 << operand2 ) & usedMask ) continue;
working1 = workList[operand1];
working2 = workList[operand2];
/* x * 1 = 1 * x = x; x / 1 = x */
if( ( currOp == MUL || currOp == DIV ) &&
( working1 == 1 || working2 == 1 ) ) continue;
/* could arise from combination a - a for some a */
if( working1 == 0 || working2 == 0 ) continue;
/* make dure operand2 divides operand1 */
if( currOp == DIV &&
( working1 % working2 ) ) continue;
/* make sure operand1 >= operand2 for subtraction and
division */
if( ( currOp == DIV || currOp == SUB ) &&
( working1 < working2 ) )
{
temp = working1;
working1 = working2;
working2 = temp;
}
/* mark operands used */
newMask = usedMask |
( 1 << operand1 ) |
( 1 << operand2 );
/* save current combination */
combList[searchDepth].operand1 =
working1;
combList[searchDepth].operand2 =
working2;
combList[searchDepth].operation = currOp;
workList[listLength + searchDepth] =
calculate( &combList[searchDepth] );
/* search deeper */
recSearch( searchDepth + 1, newMask );
}
}
}
}
}
void doSearch(void)
/* Preliminary search. Takes care of the special case where |S| = 1
and the only element of S is t.
*/
{
int i;
for( i = 0; i < listLength; i++ )
if( abs( workList[i] - goal ) < abs( best - goal ) )
{
best = workList[i];
}
if( best == goal )
{
printf( ".\n" );
return;
}
for( dmax = 1; dmax < listLength; dmax++ )
{
recSearch( 0, 0 );
if( stopSearch ) break;
}
/* If no exact solution was found */
if( stopSearch == 0 )
printSolution( solution, bestDepth );
}
int getInput(void)
{
int nums[16];
int i = 0;
int c;
nums[0] = 13;
nums[1] = 32;
nums[2] = 14;
nums[3] = 1412;
/* while( ( c = getchar() ) != '\n' && c != EOF )
{
ungetc( c, stdin );
fscanf( stdin, "%d", &nums[i] );
i++;
}
*/
if( i == 0 ) i = 4;
listLength = i - 1;
goal = nums[listLength];
workList = newWorkList( 2 * listLength );
combList = newCombList( listLength );
solution = newCombList( listLength );
initWorkList( workList, nums, listLength );
initCombList( combList, listLength );
initCombList( solution, listLength );
return( listLength );
}
void search(void)
{
/* set up global variables for search */
stopSearch = 0;
nbNodes = 0;
doSearch();
}
int main( int argc, char *argv[] )
{
if( getInput() )
search();
return 0;
}
+167
View File
@@ -0,0 +1,167 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define pi 3.14159265359
#define datasize 1024
double COSINE[datasize], SINE[datasize]; /* Twiddle tables */
/* RData[] is the real component, CData[] is the imaginary component */
double RData[datasize], CData[datasize];
/********************************************************/
/* MAKE_TWIDDLE_TABLE */
/* - Generates a FFT twiddle table. */
/********************************************************/
void make_twiddle_table(int Inputs)
{
int i;
int size = (Inputs / 2);
double arg1, arg2;
arg1 = (2.0 * pi / (double)Inputs);
for (i = 1; i <= Inputs; i++) {
arg2 = (double)(i - size) * arg1;
COSINE[i-1] = cos(arg2);
SINE[i-1] = sin(arg2);
}
}
/****************************************/
/* FFT */
/****************************************/
void fft(double RData[datasize], double CData[datasize], int Inputs)
{
int i, z, zz, j, j2, j3, k, r, d, st;
int nd2, nml, arg, twf;
double tempr, tempc, c, s;
for (i = 0; i < Inputs; i+=2) {
RData[i] = -1.0 * RData[i];
CData[i] = -1.0 * CData[i];
}
if (Inputs == 16) st = 4;
if (Inputs == 32) st = 5;
if (Inputs == 64) st = 6;
if (Inputs == 128) st = 7;
if (Inputs == 256) st = 8;
if (Inputs == 512) st = 9;
if (Inputs == 1024) st = 10;
j = 1;
for (z = 1; z < Inputs; z++) {
if (z < j) {
tempr = RData[j-1];
RData[j-1] = RData[z-1];
RData[z-1] = tempr;
tempc = CData[j-1];
CData[j-1] = CData[z-1];
CData[z-1] = tempc;
}
k = (Inputs / 2);
while (k < j) {
j -= k;
k = (k / 2);
}
j += k;
}
for (z = 1; z <= st; z++) {
r = 1;
for (i = 1; i <= z; i++) r = (r * 2);
d = (r / 2);
arg = (Inputs / r);
for (zz = 1; zz <= d; zz++) {
twf = (Inputs/4-1) + (arg * (zz-1));
c = COSINE[twf];
s = SINE[twf];
k = zz;
while (k <= Inputs) {
j2 = (k + d) - 1;
j3 = (k - 1);
tempr = (RData[j2] * c) + (CData[j2] * s);
tempc = (CData[j2] * c) - (RData[j2] * s);
RData[j2] = (RData[j3] - tempr);
CData[j2] = (CData[j3] - tempc);
RData[j3] = (RData[j3] + tempr);
CData[j3] = (CData[j3] + tempc);
k += r;
}
}
}
}
/****************************************/
/* MODULUS */
/* - Calculates modulus of data. */
/****************************************/
void modulus(double rdata[datasize], double cdata[datasize], int Inputs)
{
int i;
double temp;
for (i = 0; i < Inputs; i++) {
temp = sqrt(rdata[i] * rdata[i] + cdata[i] * cdata[i]);
rdata[i] = temp;
cdata[i] = 0.0;
}
}
/********************************************************/
/* MAIN */
/********************************************************/
void main(void)
{
/* Pixels can be 32, 64, 128, 256, or 512 depends on data set size */
int k;
double fk;
int n;
int N = 32;
float kf = 2;
float f;
float fmax;
float fa;
float W;
/********************************************************/
printf ("\nFast-Fourier-Transformation eines Sinussignals.");
printf ("\nAnzahl der Sttzstellen: ");
scanf ("%d",&N);
printf ("Frequenz des Sinussignals [Hz]: ");
scanf ("%f",&f);
printf ("Maximale Frequenz des Nutzsignals [Hz] : ");
scanf ("%f",&fmax);
while (1) {
printf ("Abtastfrequenz [Hz]: ");
scanf ("%f",&fa);
if (fa < 2*fmax)
{ printf ("Verletzung des Abtasttheorems nach Nyquist.\nBitte Eingabe wiederholen\n"); continue ;}
break;
}
kf = fa / fmax;
W = 2.0 * pi * f;
/********************************************************/
for (n=0; n < datasize; n++)
{ RData[n] = (double) sin (W*n/fa);
CData[n] = 0;
}
make_twiddle_table(N/2);
/* Call FFT routine with complex data */
fft(RData, CData, N);
/* Call modulus routine - optional */
modulus(RData, CData, N);
printf ("\n\n%d-Punkt FFT",N);
printf ("\nf = %g Hz\nH”chste Frequenz = %g Hz",f,fmax);
printf ("\nAbtastfrequenz = %g Hz\n\nFrequenzspektrum S(f):",fa);
for ( k=0; k <= N/2; k++)
{ printf ( "\n%g Hz = %f",(double)k*fa/(N),2*RData[k]/N);
}
printf ("\n\nEnde");
}
BIN
View File
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
#include <stdio.h>
main()
{
float a,b,c;
a = 0.11;
b = 3.12;
c = a+b;
printf ("Print float, result with 'f' = %f\n", c);
printf ("Print float, result with 'e' = %e\n", c);
printf ("Print float, result with 'E' = %E\n", c);
printf ("Print float, result with 'g' = %g\n", c);
printf ("Print float, result with 'G' = %G\n", c);
printf ("float");
fflush (stdout);
}
+1178
View File
File diff suppressed because it is too large Load Diff
+26
View File
@@ -0,0 +1,26 @@
/* Oki bug report [OKI002](gcc008_2)
The following program is not executed.
Error message is as follow.
illegal trap: 0x12 pc=d000d954
d000d954 08000240 NOP
*/
#include <stdio.h>
#include <stdarg.h>
int func (int, ...);
void main ()
{
func (2, 1., 2., 3.);
printf ("func [OKI002]");
fflush (stdout);
}
int func (int i, ...)
{
return (i);
}
BIN
View File
Binary file not shown.
+104
View File
File diff suppressed because one or more lines are too long
+28
View File
@@ -0,0 +1,28 @@
X=320; Y=200; A=1;
J=0;K=-10;L=-7;M=1296;N=36;O=255;P=9;_=1<<15;E;S;C;D;F(b){E="1""111886:6:??AAF"
"FHHMMOO55557799@@>>>BBBGGIIKK"[b]-64;C="C@=::C@@==@=:C@=:C@=:C5""31/513/5131/"
"31/531/53"[b ]-64;S=b<22?9:0;D=2;}I(x,Y,X){Y?(X^=Y,X*X>x?(X^=Y):0, I (x,Y/2,X
)):(E=X); }H(x){I(x, _,0);}p;q( c,x,y,z,k,l,m,a, b){F(c
);x-=E*M ;y-=S*M ;z-=C*M ;b=x* x/M+ y*y/M+z
*z/M-D*D *M;a=-x *k/M -y*l/M-z *m/M; p=((b=a*a/M-
b)>=0?(I (b*M,_ ,0),b =E, a+(a>b ?-b:b)): -1.0);}Z;W;o
(c,x,y, z,k,l, m,a){Z=! c? -1:Z;c <44?(q(c,x ,y,z,k,
l,m,0,0 ),(p> 0&&c!= a&& (p<W ||Z<0) )?(W=
p,Z=c): 0,o(c+ 1, x,y,z, k,l, m,a)):0 ;}Q;T;
U;u;v;w ;n(e,f,g, h,i,j,d,a, b,V){o(0 ,e,f,g,h,i,j,a);d>0
&&Z>=0? (e+=h*W/M,f+=i*W/M,g+=j*W/M,F(Z),u=e-E*M,v=f-S*M,w=g-C*M,b=(-2*u-2*v+w)
/3,H(u*u+v*v+w*w),b/=D,b*=b,b*=200,b/=(M*M),V=Z,E!=0?(u=-u*M/E,v=-v*M/E,w=-w*M/
E):0,E=(h*u+i*v+j*w)/M,h-=u*E/(M/2),i-=v*E/(M/2),j-=w*E/(M/2),n(e,f,g,h,i,j,d-1
,Z,0,0),Q/=2,T/=2, U/=2,V=V<22?7: (V<30?1:(V<38?2:(V<44?4:(V==44?6:3))))
,Q+=V&1?b:0,T +=V&2?b :0,U+=V &4?b:0) :(d==P?(g+=2
,j=g>0?g/8:g/ 20):0,j >0?(U= j *j/M,Q =255- 250*U/M,T=255
-150*U/M,U=255 -100 *U/M):(U =j*j /M,U<M /5?(Q=255-210*U
/M,T=255-435*U /M,U=255 -720* U/M):(U -=M/5,Q=213-110*U
/M,T=168-113*U / M,U=111 -85*U/M) ),d!=P?(Q/=2,T/=2
,U/=2):0);Q=Q< 0?0: Q>O? O: Q;T=T<0? 0:T>O?O:T;U=U<0?0:
U>O?O:U;}R;G;B ;t(x,y ,a, b){n(M*J+M *40*(A*x +a)/X/A-M*20,M*K,M
*L-M*30*(A*y+b)/Y/A+M*15,0,M,0,P, -1,0,0);R+=Q ;G+=T;B +=U;++a<A?t(x,y,a,
b):(++b<A?t(x,y,0,b):0);}r(x,y){R=G=B=0;t(x,y,0,0);x<X?(printf("%c%c%c",R/A/A,G
/A/A,B/A/A),r(x+1,y)):0;}s(y){r(0,--y?s(y),y:y);}main(){printf("P6\n%i %i\n255"
"\n",X,Y);s(Y);}
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+5531
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
+186
View File
@@ -0,0 +1,186 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <time.h>
#include "crc32.h"
#include "inflate.h"
#include "libsys.h"
#include "irq.h"
char buffer[4*16384];
char * volatile pPtr_r;
char * volatile pPtr_w;
volatile int timeout_cnt;
volatile int file_len;
void handler3(void)
{
volatile char *pUART_stat = (char*)sys_uart_stat;
volatile char *pUART_data = (char*)sys_uart_data;
while((0x10 & *pUART_stat))
{
// sputs("w: "); print_word((int)pPtr_w); sputs("\n");
if (pPtr_w == &buffer[sizeof(buffer)-1])
pPtr_w = buffer;
*(pPtr_w++) = *pUART_data;
timeout_cnt = 100;
file_len++;
}
}
int READBYTE(z_stream *zs) {
if (zs->avail_in <= 0)
return -1;
zs->avail_in --;
return *(zs->next_in ++);
}
#define MAX_BUFOUT 16*65536
int main(int argc, char **argv)
{
unsigned char outData[MAX_BUFOUT];
FILE *infp;
int i, gpflags, tmp[4];
unsigned long size, crc;
unsigned char *fileData;
unsigned long bytes, InflatedSize, InflatedCRC, speed_count;
z_stream zs, zs_speed;
time_t start_time;
sputs("Reading gzipped stream..\n");
pPtr_r = buffer;
pPtr_w = buffer;
interrupt_register(3, handler3);
interrupt_enable(3);
file_len = 0;
timeout_cnt = 1000000;
while(timeout_cnt--)
{
sleep(1);
}
bytes = file_len;
fileData = pPtr_r;
zs.next_in = fileData;
zs.avail_in = (unsigned int) bytes;
zs.next_out = outData;
zs.avail_out = MAX_BUFOUT;
tmp[0] = READBYTE(&zs);
if (tmp[0] == -1)
{
// error reading from file
sputs("error reading data from file\n");
return 0;
}
tmp[1] = READBYTE(&zs);
if (tmp[0] != 0x1f || tmp[1] != 0x8b) {
// fprintf(stderr, "Magic number mismatch 0x%02x%02x\n",
// tmp[0], tmp[1]);
return 20;
}
tmp[0] = READBYTE(&zs);
if(tmp[0] != 8) {
// fprintf(stderr, "Unknown compression method: 0x%02x\n", tmp[0]);
return 20;
}
gpflags = READBYTE(&zs);
if ((gpflags & ~0x1f)) {
sputs("Unknown flags set!\n");
}
/* Skip file modification time (4 bytes) */
READBYTE(&zs);
READBYTE(&zs);
READBYTE(&zs);
READBYTE(&zs);
/* Skip extra flags and operating system fields (2 bytes) */
READBYTE(&zs);
READBYTE(&zs);
if ((gpflags & 4)) {
/* Skip extra field */
tmp[0] = READBYTE(&zs);
tmp[1] = READBYTE(&zs);
i = tmp[0] + 256*tmp[1];
while (i--)
{
READBYTE(&zs);
}
}
if((gpflags & 8)) {
while((READBYTE(&zs))) {
}
}
if((gpflags & 16)) {
while((READBYTE(&zs))) {
}
}
if((gpflags & 2)) {
/* Skip CRC16 */
READBYTE(&zs);
READBYTE(&zs);
}
// normal test
if (InflateData(&zs))
{
sputs("Problem during decompression!\n");
return 0;
}
/*
// speed test
fprintf(stderr, "SPEED TEST!\n");
time(&start_time);
speed_count = 0;
while (time(NULL) - start_time < 20)
{
zs_speed.next_in = zs.next_in;
zs_speed.next_out = zs.next_out;
zs_speed.avail_in = zs.avail_in;
zs_speed.avail_out = zs.avail_out;
if (InflateData(&zs_speed))
{
fprintf(stderr, "Problem during decompression!\n");
return 0;
}
speed_count ++;
}
fprintf(stderr, "speed count %ld\n", speed_count);
zs.next_in = zs_speed.next_in;
zs.next_out = zs_speed.next_out;
zs.avail_in = zs_speed.avail_in;
zs.avail_out = zs_speed.avail_out;
*/
crc = READBYTE(&zs);
crc |= (READBYTE(&zs)<<8);
crc |= (READBYTE(&zs)<<16);
crc |= (READBYTE(&zs)<<24);
size = READBYTE(&zs);
size |= (READBYTE(&zs)<<8);
size |= (READBYTE(&zs)<<16);
size |= (READBYTE(&zs)<<24);
InflatedSize = MAX_BUFOUT - zs.avail_out;
InflatedCRC = MakeCRC32(outData, InflatedSize, 0);
// fprintf(stderr, "CRC: %08lx %08lx %s\n", crc, InflatedCRC,
// (crc != InflatedCRC)?"**error**":"");
// fprintf(stderr, "Size: %08lx %08lx %s\n", size, InflatedSize,
// (size != InflatedSize)?"**error**":"");
write(1, outData, InflatedSize);
return 0;
}
Binary file not shown.
+8800
View File
File diff suppressed because one or more lines are too long
Binary file not shown.
+30
View File
@@ -0,0 +1,30 @@
/* tower of hanoi */
int num[4];
mov( int n, int from, int to)
{
int other;
if( n == 1) {
num[from] = num[from] - 1;
num[to] = num[to] + 1;
printf("%d -> %d\n",from,to);
} else {
other = 6 - from - to;
mov(n-1, from, other);
mov(1, from, to );
mov(n-1, other, to);
}
}
main() {
int disk;
printf("%f\n", 1.375f);
disk = 3;
num[0] = 0;
num[1] = disk;
num[2] = 0;
num[3] = 0;
mov(disk,1,3);
}
Binary file not shown.
+124
View File
@@ -0,0 +1,124 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "irq.h"
#include "libsys.h"
char buffer[16384];
char * volatile pPtr_r;
char * volatile pPtr_w;
void handler0(void)
{
printf("Interrupt 0\n");
interrupt_clr(0);
}
void handler1(void)
{
printf("Interrupt 1\n");
interrupt_clr(1);
}
void handler2(void)
{
printf("Interrupt 2\n");
}
void handler3(void)
{
volatile char *pUART_stat = (char*)sys_uart_stat;
volatile char *pUART_data = (char*)sys_uart_data;
while((0x10 & *pUART_stat))
{
// sputs("w: "); print_word((int)pPtr_w); sputs("\n");
if (pPtr_w == &buffer[16383])
pPtr_w = buffer;
*(pPtr_w++) = *pUART_data;
}
}
void handler4(void)
{
printf("Interrupt 4\n");
}
void handler5(void)
{
printf("Interrupt 5\n");
}
void handler6(void)
{
printf("Interrupt 6\n");
}
void handler7(void)
{
printf("Interrupt 7\n");
}
int main(void)
{
printf("Hello\n");
memset(buffer, 0, sizeof(buffer));
pPtr_r = buffer;
pPtr_w = buffer;
interrupt_register(0, handler0);
interrupt_enable(0);
interrupt_register(1, handler1);
interrupt_enable(1);
interrupt_register(2, handler2);
interrupt_enable(2);
interrupt_register(3, handler3);
interrupt_enable(3);
interrupt_register(4, handler4);
// interrupt_enable(4);
interrupt_register(5, handler5);
interrupt_enable(5);
interrupt_register(6, handler6);
interrupt_enable(6);
interrupt_register(7, handler7);
interrupt_enable(7);
printf("Start:\n");
interrupt_set(0);
interrupt_set(1);
interrupt_set(2);
interrupt_set(3);
interrupt_set(4);
interrupt_set(5);
interrupt_set(6);
interrupt_set(7);
sputs("r: "); print_word((int)pPtr_r); sputs("\n");
sputs("w: "); print_word((int)pPtr_w); sputs("\n");
// Print Status register
sputs("Status : ");
print_word(CP0_SR_read());
sputs("\n");
while(1)
{
if(pPtr_w != pPtr_r)
{
// sputs("r: "); print_word((int)pPtr_r); sputs("\n");
if (pPtr_r == &buffer[16383])
pPtr_r = buffer;
writechar(*(pPtr_r++));
}
}
return 0;
}
+4870
View File
File diff suppressed because it is too large Load Diff
Binary file not shown.
Binary file not shown.
+1236
View File
File diff suppressed because it is too large Load Diff
+1363
View File
File diff suppressed because it is too large Load Diff
+946
View File
@@ -0,0 +1,946 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include "libsys.h"
#include "hpi.h"
static volatile UINT32 _g_int_active;
static volatile UINT32 _g_mbx_return;
static volatile UINT32 _g_mbx_in_flag;
// ---------------------------------------------------------
// Globals
// ---------------------------------------------------------
typedef struct _susb_t
{
fp_t fptr_ept[USB_MAX_NUM_EPT];
void *aptr_ept[USB_MAX_NUM_EPT];
fp_t fptr_rst;
void *aptr_rst;
fp_t fptr_sof;
void *aptr_sof;
fp_t fptr_cfg;
void *aptr_cfg;
fp_t fptr_sus;
void *aptr_sus;
fp_t fptr_id;
void *aptr_id;
fp_t fptr_vbus;
void *aptr_vbus;
} usb_t;
static usb_t _g_usb[USB_MAX_NUM_PORTS];
//static usb_irp_t *_g_usb_irp_ptr[USB_MAX_NUM_PORTS][USB_MAX_NUM_EPT];
// ---------------------------------------------------------
// HPI ISR
// ---------------------------------------------------------
void cy67k3_isr(void)
{
INT32 i;
UINT16 sie_msg, hpi_status;
UINT32 port, siemsg_handled, int_handled;
_g_int_active = 1;
// sputs("--------------------------------------------------------\n");
// sputs("USB-Interrupt(4)\n");
// sputs("HPI Status : ");
hpi_status = cy67k3_read_HPI_STATUS();
// print_word(hpi_status);
// sputs("\n");
// sputs("MAILBOX (REG): ");
// cy67k3_write(HPI_ADDRESS, HPI_REG_MAILBOX);
// print_word(cy67k3_read_HPI_DATA());
// sputs("\n");
int_handled = 0;
if (hpi_status & HPI_STATUS_MBX_IN)
{
int_handled = 1;
// sputs("MAILBOX (HPI): ");
_g_mbx_return = cy67k3_read_HPI_MAILBOX();
_g_mbx_in_flag = 1;
// print_word(_g_mbx_return);
// sputs("\n");
}
if (hpi_status & HPI_STATUS_RESET1)
{
int_handled = 1;
hpi_read_reg(SUSB1_REG_STATUS);
hpi_comm_exec_int(SUSB_INIT_INT, 2, R1, 0, R2, 1);
// sputs("RESET 1\n");
}
if (hpi_status & HPI_STATUS_RESET2)
{
int_handled = 1;
hpi_read_reg(SUSB2_REG_STATUS);
hpi_comm_exec_int(SUSB_INIT_INT, 2, R1, 0, R2, 2);
// sputs("RESET 2\n");
}
if (hpi_status & HPI_STATUS_DONE1)
{
int_handled = 1;
// sputs("DONE 1\n");
}
if (hpi_status & HPI_STATUS_DONE2)
{
int_handled = 1;
// sputs("DONE 2\n");
}
if (hpi_status & HPI_STATUS_SOFEOP1)
{
int_handled = 1;
hpi_read_reg(SUSB1_REG_STATUS);
// sputs("SOF/EOP 1\n");
}
if (hpi_status & HPI_STATUS_SOFEOP2)
{
int_handled = 1;
hpi_read_reg(SUSB2_REG_STATUS);
// sputs("SOF/EOP 2\n");
}
port = 0;
siemsg_handled = 0;
if (hpi_status & HPI_STATUS_SIEMSG1)
{
int_handled = 1;
sie_msg = hpi_read_reg(HPI_REG_SIE1MSG);
// Reset message register
hpi_write_reg(HPI_REG_SIE1MSG, 0x0000);
if (sie_msg & SUSB_RST_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_rst)
(_g_usb[port].fptr_rst)(_g_usb[port].aptr_rst);
}
if (sie_msg & SUSB_SOF_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_sof)
(_g_usb[port].fptr_sof)(_g_usb[port].aptr_sof);
}
if (sie_msg & SUSB_CFG_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_cfg)
(_g_usb[port].fptr_cfg)(_g_usb[port].aptr_cfg);
}
if (sie_msg & SUSB_SUS_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_sus)
(_g_usb[port].fptr_sus)(_g_usb[port].aptr_sus);
}
if (sie_msg & SUSB_ID_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_id)
(_g_usb[port].fptr_id)(_g_usb[port].aptr_id);
}
if (sie_msg & SUSB_VBUS_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_vbus)
(_g_usb[port].fptr_vbus)(_g_usb[port].aptr_vbus);
}
for (i=0; i < 8; i++)
{
if (sie_msg & (SUSB_EP0_MSG << i))
{
siemsg_handled = 1;
if (_g_usb[port].fptr_ept[i])
(_g_usb[port].fptr_ept[i])(_g_usb[port].aptr_ept[i]);
}
}
if (!siemsg_handled)
{
sputs("Unhandled SIE1 message ");
print_word(sie_msg);
sputs("!\n");
}
}
port = 1;
siemsg_handled = 0;
if (hpi_status & HPI_STATUS_SIEMSG2)
{
int_handled = 1;
sie_msg = hpi_read_reg(HPI_REG_SIE2MSG);
// Reset message register
hpi_write_reg(HPI_REG_SIE2MSG, 0x0000);
if (sie_msg & SUSB_RST_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_rst)
(_g_usb[port].fptr_rst)(_g_usb[port].aptr_rst);
}
if (sie_msg & SUSB_SOF_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_sof)
(_g_usb[port].fptr_sof)(_g_usb[port].aptr_sof);
}
if (sie_msg & SUSB_CFG_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_cfg)
(_g_usb[port].fptr_cfg)(_g_usb[port].aptr_cfg);
}
if (sie_msg & SUSB_SUS_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_sus)
(_g_usb[port].fptr_sus)(_g_usb[port].aptr_sus);
}
if (sie_msg & SUSB_ID_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_id)
(_g_usb[port].fptr_id)(_g_usb[port].aptr_id);
}
if (sie_msg & SUSB_VBUS_MSG)
{
siemsg_handled = 1;
if (_g_usb[port].fptr_vbus)
(_g_usb[port].fptr_vbus)(_g_usb[port].aptr_vbus);
}
for (i=0; i < 8; i++)
{
if (sie_msg & (SUSB_EP0_MSG << i))
{
siemsg_handled = 1;
if (_g_usb[port].fptr_ept[i])
(_g_usb[port].fptr_ept[i])(_g_usb[port].aptr_ept[i]);
}
}
if (!siemsg_handled)
{
sputs("Unhandled SIE2 message ");
print_word(sie_msg);
sputs("!\n");
}
}
if (!int_handled)
{
sputs("Unhandled interrupt (status = ");
print_word(hpi_status);
sputs(")!\n");
}
// sputs("--------------------------------------------------------\n");
_g_int_active = 0;
}
// ---------------------------------------------------------
// CY7C67300 low-level routines
// ---------------------------------------------------------
void cy67k3_reset(void)
{
int i;
volatile UINT32 *pHpi = (UINT32*)sys_usb_ctrl;
*pHpi = 1;
for (i=0; i <160; i++)
{
__asm __volatile
(
".set noreorder\n"
"nop\n"
"nop\n"
"nop\n"
"nop\n"
".set reorder\n"
);
}
*pHpi = 0;
}
UINT16 cy67k3_read_HPI_DATA(void)
{
volatile UINT32 *pHpi = (UINT32*)sys_usb_data;
return (UINT16)*pHpi;
}
UINT16 cy67k3_read_HPI_MAILBOX(void)
{
volatile UINT32 *pHpi = (UINT32*)sys_usb_mbx;
return (UINT16)*pHpi;
}
UINT16 cy67k3_read_HPI_ADDRESS(void)
{
volatile UINT32 *pHpi = (UINT32*)sys_usb_addr;
return (UINT16)*pHpi;
}
UINT16 cy67k3_read_HPI_STATUS(void)
{
volatile UINT32 *pHpi = (UINT32*)sys_usb_status;
return (UINT16)*pHpi;
}
void cy67k3_write_HPI_DATA(UINT16 data)
{
volatile UINT32 *pHpi = (UINT32*)sys_usb_data;
*pHpi = (UINT32)data;
}
void cy67k3_write_HPI_MAILBOX(UINT16 data)
{
volatile UINT32 *pHpi = (UINT32*)sys_usb_mbx;
*pHpi = (UINT32)data;
}
void cy67k3_write_HPI_ADDRESS(UINT16 data)
{
volatile UINT32 *pHpi = (UINT32*)sys_usb_addr;
*pHpi = (UINT32)data;
}
void cy67k3_write_HPI_STATUS(UINT16 data)
{
volatile UINT32 *pHpi = (UINT32*)sys_usb_status;
*pHpi = (UINT32)data;
}
// ---------------------------------------------------------
// HPI API
// ---------------------------------------------------------
UINT32 hpi_init(void)
{
int i;
UINT16 reg;
// ToDo: Enable HPI interrupt
_g_int_active = 0;
hpi_write_reg(HPI_REG_SIE1MSG, 0x0000);
hpi_write_reg(HPI_REG_SIE2MSG, 0x0000);
hpi_write_reg(SUSB1_REG_STATUS, 0xFFFF);
hpi_write_reg(SUSB2_REG_STATUS, 0xFFFF);
// Init 1
for(i=0; i < USB_MAX_NUM_EPT; i++)
{
hpi_write_reg(SUSB1_REG_EP_ADDR0 + 16*i, 0);
hpi_write_reg(SUSB1_REG_EP_CNTRES0 + 16*i, 0);
hpi_write_reg(SUSB1_REG_EP_COUNT0 + 16*i, 0);
hpi_write_reg(SUSB1_REG_EP_CTRL0 + 16*i, 0);
hpi_write_reg(SUSB1_REG_EP_STATUS0 + 16*i, 0);
}
// Init 2
for(i=0; i < USB_MAX_NUM_EPT; i++)
{
hpi_write_reg(SUSB2_REG_EP_ADDR0 + 16*i, 0);
hpi_write_reg(SUSB2_REG_EP_CNTRES0 + 16*i, 0);
hpi_write_reg(SUSB2_REG_EP_COUNT0 + 16*i, 0);
hpi_write_reg(SUSB2_REG_EP_CTRL0 + 16*i, 0);
hpi_write_reg(SUSB2_REG_EP_STATUS0 + 16*i, 0);
}
hpi_write_reg(HPI_REG_INTROUTE, 0x0000);
reg = hpi_read_reg(HPI_REG_INTROUTE);
// hpi_write_reg(HPI_REG_INTROUTE, reg | 0x0202); // Route reset {1,2} to HPI only
// hpi_write_reg(HPI_REG_INTROUTE, reg | 0x2800); // Route SOF/EOP {1,2} to HPI only
// hpi_write_reg(HPI_REG_INTROUTE, reg | 0x1400); // Route SOF/EOP {1,2} to CY16 only
hpi_write_reg(HPI_REG_INTROUTE, reg | 0x3C00); // Route SOF/EOP {1,2} to HPI and CY16
interrupt_register(4, cy67k3_isr);
interrupt_enable(4);
return HPI_NOERROR;
}
void hpi_mbx_write(UINT16 msgcode)
{
_g_mbx_in_flag = 0;
cy67k3_write_HPI_MAILBOX(msgcode);
}
UINT32 hpi_mbx_read(void)
{
UINT32 err;
UINT16 cy_return;
if (_g_int_active)
{
while (!(cy67k3_read_HPI_STATUS() & HPI_STATUS_MBX_IN));
cy_return = cy67k3_read_HPI_MAILBOX();
}
else
{
while(!_g_mbx_in_flag);
cy_return = _g_mbx_return;
}
switch (cy_return)
{
case COMM_ACK:
err = cy_return;
break;
case COMM_NAK:
case COMM_ASYNC:
err = HPI_ERR_PREFIX_MBX | cy_return;
break;
default:
err = HPI_ERR_PREFIX_MBX | cy_return;
break;
}
return err;
}
UINT32 hpi_check_addr(UINT16 addr)
{
if ((addr >= 0x0000) && (addr < 0x4000))
return 0;
if ((addr >= 0xC080) && (addr < 0xC0BC))
return 0;
if (addr >= 0xE000)
return 0;
sputs("Invalid address for HPI direct access! Use LCP-command instead!\n");
return HPI_ERR_INVPARAM;
}
UINT32 hpi_read_reg(UINT16 addr)
{
UINT32 result;
result = hpi_check_addr(addr);
if (IS_ERROR(result))
return result;
cy67k3_write_HPI_ADDRESS(addr);
return cy67k3_read_HPI_DATA();
}
UINT32 hpi_write_reg(UINT16 addr, UINT16 data)
{
UINT32 result;
result = hpi_check_addr(addr);
if (IS_ERROR(result))
return result;
cy67k3_write_HPI_ADDRESS(addr);
cy67k3_write_HPI_DATA(data);
}
UINT32 hpi_write_ram(UINT16 addr, UINT16 *pData, UINT32 len)
{
int i, num_words;
if (addr > 0x3FFE)
return HPI_ERR_INVPARAM;
if (addr & 1) // Not 16bit aligned?
return HPI_ERR_INVPARAM;
cy67k3_write_HPI_ADDRESS(addr);
num_words = len/2;
if (len % 2)
num_words++;
for (i=0; i < num_words; i++)
cy67k3_write_HPI_DATA(pData[i]);
return len;
}
UINT32 hpi_read_ram(UINT16 addr, UINT16 *pData, UINT32 len)
{
int i, num_words;
if (addr > 0x3FFE)
return HPI_ERR_INVPARAM;
if (addr & 1) // Not 16bit aligned?
return HPI_ERR_INVPARAM;
cy67k3_write_HPI_ADDRESS(addr);
num_words = len/2;
if (len % 2)
num_words++;
for (i=0; i < num_words; i++)
pData[i] = cy67k3_read_HPI_DATA();
return len;
}
UINT32 hpi_comm_reset(void)
{
hpi_mbx_write(COMM_RESET);
return hpi_mbx_read();
}
UINT32 hpi_comm_jump2code(UINT16 addr)
{
cy67k3_write_HPI_ADDRESS(addr);
hpi_mbx_write(COMM_JUMP2CODE);
return hpi_mbx_read();
}
UINT32 hpi_comm_callcode(UINT16 addr)
{
hpi_write_reg(COMM_CODE_ADDR, addr);
hpi_mbx_write(COMM_CALL_CODE);
return hpi_mbx_read();
}
UINT32 hpi_comm_write_ctrl_reg(UINT16 addr, UINT16 data, UINT16 logic)
{
hpi_write_reg(COMM_CTRL_REG_ADDR, addr);
hpi_write_reg(COMM_CTRL_REG_DATA, data);
hpi_write_reg(COMM_CTRL_REG_LOGIC, logic);
hpi_mbx_write(COMM_WRITE_CTRL_REG);
return hpi_mbx_read();
}
UINT32 hpi_comm_read_ctrl_reg(UINT16 addr)
{
UINT32 result;
hpi_write_reg(COMM_CTRL_REG_ADDR, addr);
hpi_mbx_write(COMM_READ_CTRL_REG);
result = hpi_mbx_read();
if (IS_ERROR(result))
return result;
cy67k3_write_HPI_ADDRESS(COMM_CTRL_REG_DATA);
return (UINT32)cy67k3_read_HPI_DATA();
}
UINT32 hpi_comm_write_xmem(UINT16 addr, UINT8 *pData, UINT16 len)
{
return HPI_ERR_NOTIMPL;
}
UINT32 hpi_comm_read_xmem(UINT16 addr, UINT8 *pData, UINT16 len)
{
return HPI_ERR_NOTIMPL;
}
typedef struct _sreg_param_t
{
UINT32 id;
UINT16 val;
} reg_param_t;
UINT32 hpi_comm_exec_int(UINT16 intnum, UINT32 nargs, ...)
{
int i;
UINT32 result;
va_list args;
reg_param_t reg_param[MAX_NUM_REGS];
va_start(args, nargs);
if (nargs > MAX_NUM_REGS)
{
fprintf(stderr, "hpi_comm_exec_int(): Number (%d), of arguments exceeds %d!\n", nargs, MAX_NUM_REGS);
return HPI_ERR_INVPARAM;
}
for (i=0; i < nargs; i++)
{
reg_param[i].id = va_arg(args, UINT32);
if (reg_param[i].id > MAX_NUM_REGS)
{
fprintf(stderr, "hpi_comm_exec_int(): Invalid register R%d!\n", reg_param[i].id);
return HPI_ERR_INVPARAM;
}
reg_param[i].val = (UINT16)va_arg(args, UINT32);
}
va_end(args);
hpi_write_reg(COMM_INT_NUM, intnum);
for (i=0; i < nargs; i++)
{
hpi_write_reg(COMM_R0 + 2*reg_param[i].id, reg_param[i].val);
}
hpi_mbx_write(COMM_EXEC_INT);
result = hpi_mbx_read();
if (IS_ERROR(result))
return result;
return (UINT32)hpi_read_reg(COMM_R0);
}
UINT32 usb_init(void)
{
INT32 i;
for (i=0; i < USB_MAX_NUM_PORTS; i++)
{
memset(&_g_usb[i], 0, sizeof(usb_t));
}
return 0;
}
UINT32 usb_callback_register(UINT32 port, UINT32 type, fp_t pFunc, void *pArg)
{
UINT32 result;
if (port >= USB_MAX_NUM_PORTS)
return -1;
result = 0;
switch (type)
{
case SUSB_EP0_MSG:
_g_usb[port].fptr_ept[0] = pFunc;
_g_usb[port].aptr_ept[0] = pArg;
break;
case SUSB_EP1_MSG:
_g_usb[port].fptr_ept[1] = pFunc;
_g_usb[port].aptr_ept[1] = pArg;
break;
case SUSB_EP2_MSG:
_g_usb[port].fptr_ept[2] = pFunc;
_g_usb[port].aptr_ept[2] = pArg;
break;
case SUSB_EP3_MSG:
_g_usb[port].fptr_ept[3] = pFunc;
_g_usb[port].aptr_ept[3] = pArg;
break;
case SUSB_EP4_MSG:
_g_usb[port].fptr_ept[4] = pFunc;
_g_usb[port].aptr_ept[4] = pArg;
break;
case SUSB_EP5_MSG:
_g_usb[port].fptr_ept[5] = pFunc;
_g_usb[port].aptr_ept[5] = pArg;
break;
case SUSB_EP6_MSG:
_g_usb[port].fptr_ept[6] = pFunc;
_g_usb[port].aptr_ept[6] = pArg;
break;
case SUSB_EP7_MSG:
_g_usb[port].fptr_ept[7] = pFunc;
_g_usb[port].aptr_ept[7] = pArg;
break;
case SUSB_RST_MSG:
_g_usb[port].fptr_rst = pFunc;
_g_usb[port].aptr_rst = pArg;
break;
case SUSB_SOF_MSG:
_g_usb[port].fptr_sof = pFunc;
_g_usb[port].aptr_sof = pArg;
break;
case SUSB_CFG_MSG:
_g_usb[port].fptr_cfg = pFunc;
_g_usb[port].aptr_cfg = pArg;
break;
case SUSB_SUS_MSG:
_g_usb[port].fptr_sus = pFunc;
_g_usb[port].aptr_sus = pArg;
break;
case SUSB_ID_MSG:
_g_usb[port].fptr_id = pFunc;
_g_usb[port].aptr_id = pArg;
break;
case SUSB_VBUS_MSG:
_g_usb[port].fptr_vbus = pFunc;
_g_usb[port].aptr_vbus = pArg;
break;
default:
result = -1;
break;
}
return result;
}
UINT32 usb_irp_register(usb_irp_t *pIRP, UINT32 port, UINT32 ept, UINT32 size, UINT32 is_out)
{
if (!pIRP)
return -1;
if (port >= USB_MAX_NUM_PORTS)
return -1;
if (ept >= USB_MAX_NUM_EPT)
return -1;
if (size >= USB_MAX_IMG_SIZE)
return -1;
memset(pIRP, 0, sizeof(usb_irp_t));
pIRP->is_out = is_out;
pIRP->is_in = !is_out;
pIRP->tsize = size;
pIRP->port = port;
pIRP->ept = ept;
pIRP->cy_irp_addr = USB_IRP_BASE + port*USB_MAX_NUM_EPT*sizeof(cy_req_t) + ept*sizeof(cy_req_t);
pIRP->cy_req.next = 0;
pIRP->cy_req.addr = USB_IMG_BASE + port*USB_MAX_NUM_EPT*USB_MAX_IMG_SIZE + ept*USB_MAX_IMG_SIZE;
pIRP->cy_req.size = size;
pIRP->cy_req.callback = 0;
fifo_alloc(&pIRP->fifo, 8*USB_MAX_IMG_SIZE);
return 0;
}
UINT32 usb_irp_enqueue(usb_irp_t *pIRP)
{
UINT32 result;
if (!pIRP)
{
// sputs ("usb_irp_enqueue(): Invalid IRP!\n");
return -1;
}
// printf("cy_addr: %4.4X, Next: %4.4X, Addr: %4.4X, Size: %4.4X, CB: %4.4X\n", pIRP->cy_irp_addr, pIRP->cy_req.next, pIRP->cy_req.addr, pIRP->cy_req.size, pIRP->cy_req.callback);
if (pIRP->is_out)
{
hpi_write_ram(pIRP->cy_irp_addr, (UINT16*)&pIRP->cy_req, sizeof(cy_req_t));
if (pIRP->port == 0)
result = hpi_comm_exec_int(SUSB1_RECEIVE_INT, 2, R1, pIRP->ept, R8, pIRP->cy_irp_addr);
if (pIRP->port == 1)
result = hpi_comm_exec_int(SUSB2_RECEIVE_INT, 2, R1, pIRP->ept, R8, pIRP->cy_irp_addr);
}
if (pIRP->is_in)
{
pIRP->tx_in_progress = 1;
hpi_write_ram(pIRP->cy_irp_addr, (UINT16*)&pIRP->cy_req, sizeof(cy_req_t));
if (pIRP->port == 0)
result = hpi_comm_exec_int(SUSB1_SEND_INT, 2, R1, pIRP->ept, R8, pIRP->cy_irp_addr);
if (pIRP->port == 1)
result = hpi_comm_exec_int(SUSB2_SEND_INT, 2, R1, pIRP->ept, R8, pIRP->cy_irp_addr);
}
// if (result)
// printf ("usb_irp_enqueue(): Result = %8.8X\n", result);
return result;
}
UINT32 fifo_alloc(fifo_t *pObj, UINT32 size)
{
pObj->pBuf = (UINT8*)malloc(size);
if (!pObj->pBuf)
{
// printf ("fifo_alloc(): Error allocating memory!\n");
return -1;
}
// printf ("fifo_alloc(): pBuf at %8.8X\n", (UINT32)pObj->pBuf);
pObj->size = size;
pObj->pPtr_wr = pObj->pBuf;
pObj->pPtr_rd = pObj->pBuf;
return 0;
}
UINT32 fifo_free(fifo_t *pObj)
{
if (pObj->pBuf)
free(pObj->pBuf);
return 0;
}
UINT32 fifo_flush(fifo_t *pObj)
{
pObj->pPtr_wr = pObj->pBuf;
pObj->pPtr_rd = pObj->pBuf;
return 0;
}
UINT32 fifo_is_empty(fifo_t *pObj)
{
return (pObj->pPtr_wr == pObj->pPtr_rd);
}
UINT32 fifo_is_full(fifo_t *pObj)
{
UINT8 *pNext, *pEnd;
pEnd = pObj->pBuf + pObj->size;
pNext = pObj->pPtr_wr + 1;
if (pNext == pEnd)
pNext = pObj->pBuf;
return (pNext == pObj->pPtr_rd);
}
UINT32 fifo_read(fifo_t *pObj, UINT8 *pData, UINT32 size, UINT32 timeout, UINT32 do_block)
{
UINT32 i;
UINT32 wait_4ever, timeout_cnt, cnt;
UINT8 *pEnd;
pEnd = pObj->pBuf + pObj->size;
wait_4ever = (timeout == 0);
cnt = 0;
while(size)
{
timeout_cnt = timeout;
while(fifo_is_empty(pObj))
{
if (!do_block)
return cnt;
if (!wait_4ever)
{
if (timeout_cnt)
{
timeout_cnt--;
sleep(1);
}
else
{
return cnt;
}
}
}
if (pData)
pData[cnt] = *(pObj->pPtr_rd);
cnt++;
pObj->pPtr_rd++;
if (pObj->pPtr_rd == pEnd)
pObj->pPtr_rd = pObj->pBuf;
size--;
}
return cnt;
}
UINT32 fifo_write(fifo_t *pObj, UINT8 *pData, UINT32 size, UINT32 timeout, UINT32 do_block)
{
UINT32 wait_4ever, timeout_cnt, cnt;
UINT8 *pEnd;
pEnd = pObj->pBuf + pObj->size;
wait_4ever = (timeout == 0);
cnt = 0;
while(size)
{
timeout_cnt = timeout;
while(fifo_is_full(pObj))
{
if (!do_block)
return cnt;
if (!wait_4ever)
{
if (timeout_cnt)
{
timeout_cnt--;
sleep(1);
}
else
{
return cnt;
}
}
}
if (pData)
*(pObj->pPtr_wr) = pData[cnt];
cnt++;
pObj->pPtr_wr++;
if (pObj->pPtr_wr == pEnd)
pObj->pPtr_wr = pObj->pBuf;
size--;
}
return cnt;
}
// ---------------------------------------------------------
+384
View File
@@ -0,0 +1,384 @@
#ifndef HPI_H
#define HPI_H
// ---------------------------------------------------------
// API related
// ---------------------------------------------------------
#define IS_ERROR(e) (0 != (e & HPI_ERROR))
#define HPI_NOERROR 0
#define HPI_ERROR 0x80000000
#define HPI_ERR_NOTIMPL (HPI_ERROR + 1)
#define HPI_ERR_INVPARAM (HPI_ERROR + 2)
#define HPI_ERR_TIMEOUT (HPI_ERROR + 3)
#define HPI_ERR_PREFIX_MBX (HPI_ERROR + 0x00010000)
#define MAX_NUM_REGS 14
#define R0 0
#define R1 1
#define R2 2
#define R3 3
#define R4 4
#define R5 5
#define R6 6
#define R7 7
#define R8 8
#define R9 9
#define R10 10
#define R11 11
#define R12 12
#define R13 13
#define USB_MAX_NUM_PORTS 2
#define USB_MAX_NUM_EPT 8
#define USB_MAX_IMG_SIZE 512
#define USB_IRP_BASE 0x0F80
#define USB_IMG_BASE 0x1000
typedef void (*fp_t)(void*);
// Receive buffer on EP
typedef struct _scy_req_t
{
UINT16 next;
UINT16 addr;
UINT16 size;
UINT16 callback;
} cy_req_t;
typedef struct _sfifo_t
{
UINT32 size;
UINT8 *pBuf;
UINT8 * volatile pPtr_wr, * volatile pPtr_rd;
} fifo_t;
typedef struct _susb_irp_t
{
UINT16 tsize;
UINT32 is_in, is_out;
UINT32 port, ept;
UINT16 cy_irp_addr;
fifo_t fifo;
UINT32 tx_in_progress;
cy_req_t cy_req;
} usb_irp_t;
// ---------------------------------------------------------
// CY7C67300 related
// ---------------------------------------------------------
#define HPI_WAITACK 1
#define HPI_NOWAIT 0
// ---------------------------------------------------------
// HPI status flags
#define HPI_STATUS_MBX_IN 0x0001
#define HPI_STATUS_RESET1 0x0002
#define HPI_STATUS_DONE1 0x0004
#define HPI_STATUS_DONE2 0x0008
#define HPI_STATUS_SIEMSG1 0x0010
#define HPI_STATUS_SIEMSG2 0x0020
#define HPI_STATUS_RESUME1 0x0040
#define HPI_STATUS_RESUME2 0x0080
#define HPI_STATUS_MBX_OUT 0x0100
#define HPI_STATUS_RESET2 0x0200
#define HPI_STATUS_SOFEOP1 0x0400
#define HPI_STATUS_SOFEOP2 0x1000
#define HPI_STATUS_ID 0x4000
#define HPI_STATUS_VBUS 0x8000
// ---------------------------------------------------------
// LCP command codes
#define COMM_RESET 0xFA50
#define COMM_JUMP2CODE 0xCE00
#define COMM_EXEC_INT 0xCE01
#define COMM_READ_CTRL_REG 0xCE02
#define COMM_WRITE_CTRL_REG 0xCE03
#define COMM_CALL_CODE 0xCE04
#define COMM_READ_XMEM 0xCE05
#define COMM_WRITE_XMEM 0xCE06
#define C0MM_CONFIG 0xCE07
#define COMM_READ_MEM 0xCE08
#define COMM_WRITE_MEM 0xCE09
// LCP response codes
#define COMM_ACK 0x0FED
#define COMM_NAK 0xDEAD
#define COMM_ASYNC 0xF00D
// ---------------------------------------------------------
// LCP memory addresses
#define COMM_PORT_CMD 0x01BA // For PORT Command
#define COMM_MEM_ADDR 0x01BC // Address for COMM_RD/WR_MEM
#define COMM_MEM_LEN 0x01BE // Address for COMM_RD/WR_MEM
#define COMM_LAST_DATA 0x01C0 // memory pointer for xmem
#define COMM_CTRL_REG_ADDR 0x01BC // Address for COMM_RD/WR_CTRL_REG
#define COMM_CTRL_REG_DATA 0x01BE // Address for COMM_RD/WR_CTRL_REG
#define COMM_CTRL_REG_LOGIC 0x01C0 // Address used for AND/OR
#define REG_WRITE_FLG 0x0000 // Value for COMM_CTRL_REG_LOGIC
#define REG_AND_FLG 0x0001 // Value for COMM_CTRL_REG_LOGIC
#define REG_OR_FLG 0x0002 // Value for COMM_CTRL_REG_LOGIC
#define COMM_TIMEOUT 0x01BE // Address setting Timeout for sending response to host
#define COMM_CODE_ADDR 0x01BC // Address for COMM_CALL_CODE and COMM_JUMP2CODE
#define COMM_INT_NUM 0x01C2 // Address used for COMM_EXEC_INT
#define COMM_R0 0x01C4 // CY16-R0 register
#define COMM_R1 0x01C6 // CY16-R1 register
#define COMM_R2 0x01C8 // CY16-R2 register
#define COMM_R3 0x01CA // CY16-R3 register
#define COMM_R4 0x01CC // CY16-R4 register
#define COMM_R5 0x01CE // CY16-R5 register
#define COMM_R6 0x01D0 // CY16-R6 register
#define COMM_R7 0x01D2 // CY16-R7 register
#define COMM_R8 0x01D4 // CY16-R8 register
#define COMM_R9 0x01D6 // CY16-R9 register
#define COMM_R10 0x01D8 // CY16-R10 register
#define COMM_R11 0x01DA // CY16-R11 register
#define COMM_R12 0x01DC // CY16-R12 register
#define COMM_R13 0x01DE // CY16-R13 register
// for COMM_CTRL_REG_LOGIC
#define LOGIC_DIRECT 0
#define LOGIC_AND 1
#define LOGIC_OR 2
// ---------------------------------------------------------
// Software interrupts
#define SUSB_INIT_INT 113
// USB 1
#define SUSB1_DEVICE_DESCRIPTOR_VEC 90
#define SUSB1_CONFIGURATION_DESCRIPTOR_VEC 91
#define SUSB1_STRING_DESCRIPTOR_VEC 92
#define SUSB1_FINISH_INT 89
#define SUSB1_STALL_INT 82
#define SUSB1_STANDARD_INT 83
#define SUSB1_SEND_INT 80
#define SUSB1_RECEIVE_INT 81
#define SUSB1_VENDOR_INT 85
#define SUSB1_CLASS_INT 87
#define SUSB1_LOADER_INT 94
#define SUSB1_DELTA_CONFIG_INT 95
// USB 2
#define SUSB2_DEVICE_DESCRIPTOR_VEC 106
#define SUSB2_CONFIGURATION_DESCRIPTOR_VEC 107
#define SUSB2_STRING_DESCRIPTOR_VEC 108
#define SUSB2_FINISH_INT 105
#define SUSB2_STALL_INT 98
#define SUSB2_STANDARD_INT 99
#define SUSB2_SEND_INT 96
#define SUSB2_RECEIVE_INT 97
#define SUSB2_VENDOR_INT 101
#define SUSB2_CLASS_INT 103
#define SUSB2_LOADER_INT 110
#define SUSB2_DELTA_CONFIG_INT 111
// ---------------------------------------------------------
// General USB Registers
#define USB_REG_FLAGS 0xC000 // CPU Flags
#define USB_REG_BANK 0xC002 // Register Bank
#define USB_REG_REVISON 0xC004 // Hardware Revision
#define USB_REG_SPEED 0xC008 // CPU Speed
#define USB_REG_PWRCTRL 0xC00A // Power Control
#define USB_REG_INTEN 0xC00E // Interrupt Enable
#define USB_REG_BP 0xC014 // Breakpoint
#define USB_REG_USBDIAG 0xC03C // USB Diagnostic
#define USB_REG_MEMDIAG 0xC03E // Memory Diagnostic
// HPI registers
#define HPI_REG_BP 0x0140 // HPI Breakpoint
#define HPI_REG_INTROUTE 0x0142 // Interrupt Routing
#define HPI_REG_SIE1MSG 0x0144 // SIE1msg
#define HPI_REG_SIE2MSG 0x0148 // SIE2msg
#define HPI_REG_MAILBOX 0xC0C6 // HPI Mailbox
// ---------------------------------------------------------
// General Device Registers
// Device 1
#define SUSB1_REG_PORTSEL 0xC084 // Port select
#define SUSB1_REG_USBCTRL 0xC08A // USB control
#define SUSB1_REG_INTEN 0xC08C // Interrupt enable
#define SUSB1_REG_ADDR 0xC08E // Address
#define SUSB1_REG_STATUS 0xC090 // Status
#define SUSB1_REG_FRAMENUM 0xC092 // Frame number
#define SUSB1_REG_SOFEOPCNT 0xC094 // SOF/EOP count
// Device 2
#define SUSB2_REG_PORTSEL 0xC0A4 // Port select
#define SUSB2_REG_USBCTRL 0xC0AA // USB control
#define SUSB2_REG_INTEN 0xC0AC // Interrupt enable
#define SUSB2_REG_ADDR 0xC0AE // Address
#define SUSB2_REG_STATUS 0xC0B0 // Status
#define SUSB2_REG_FRAMENUM 0xC0B2 // Frame number
#define SUSB2_REG_SOFEOPCNT 0xC0B4 // SOF/EOP count
// ---------------------------------------------------------
// Endpoint Registers
// Device 1 Control
#define SUSB1_REG_EP_CTRL0 0x0200
#define SUSB1_REG_EP_CTRL1 0x0210
#define SUSB1_REG_EP_CTRL2 0x0220
#define SUSB1_REG_EP_CTRL3 0x0230
#define SUSB1_REG_EP_CTRL4 0x0240
#define SUSB1_REG_EP_CTRL5 0x0250
#define SUSB1_REG_EP_CTRL6 0x0260
#define SUSB1_REG_EP_CTRL7 0x0270
// Device 1 Address
#define SUSB1_REG_EP_ADDR0 0x0202
#define SUSB1_REG_EP_ADDR1 0x0212
#define SUSB1_REG_EP_ADDR2 0x0222
#define SUSB1_REG_EP_ADDR3 0x0232
#define SUSB1_REG_EP_ADDR4 0x0242
#define SUSB1_REG_EP_ADDR5 0x0252
#define SUSB1_REG_EP_ADDR6 0x0262
#define SUSB1_REG_EP_ADDR7 0x0272
// Device 1 Count
#define SUSB1_REG_EP_COUNT0 0x0204
#define SUSB1_REG_EP_COUNT1 0x0214
#define SUSB1_REG_EP_COUNT2 0x0224
#define SUSB1_REG_EP_COUNT3 0x0234
#define SUSB1_REG_EP_COUNT4 0x0244
#define SUSB1_REG_EP_COUNT5 0x0254
#define SUSB1_REG_EP_COUNT6 0x0264
#define SUSB1_REG_EP_COUNT7 0x0274
// Device 1 Status
#define SUSB1_REG_EP_STATUS0 0x0206
#define SUSB1_REG_EP_STATUS1 0x0216
#define SUSB1_REG_EP_STATUS2 0x0226
#define SUSB1_REG_EP_STATUS3 0x0236
#define SUSB1_REG_EP_STATUS4 0x0246
#define SUSB1_REG_EP_STATUS5 0x0256
#define SUSB1_REG_EP_STATUS6 0x0266
#define SUSB1_REG_EP_STATUS7 0x0276
// Device 1 Count result
#define SUSB1_REG_EP_CNTRES0 0x0208
#define SUSB1_REG_EP_CNTRES1 0x0218
#define SUSB1_REG_EP_CNTRES2 0x0228
#define SUSB1_REG_EP_CNTRES3 0x0238
#define SUSB1_REG_EP_CNTRES4 0x0248
#define SUSB1_REG_EP_CNTRES5 0x0258
#define SUSB1_REG_EP_CNTRES6 0x0268
#define SUSB1_REG_EP_CNTRES7 0x0278
// Device 2 Control
#define SUSB2_REG_EP_CTRL0 0x0280
#define SUSB2_REG_EP_CTRL1 0x0290
#define SUSB2_REG_EP_CTRL2 0x02A0
#define SUSB2_REG_EP_CTRL3 0x02B0
#define SUSB2_REG_EP_CTRL4 0x02C0
#define SUSB2_REG_EP_CTRL5 0x02D0
#define SUSB2_REG_EP_CTRL6 0x02E0
#define SUSB2_REG_EP_CTRL7 0x02F0
// Device 2 Address
#define SUSB2_REG_EP_ADDR0 0x0282
#define SUSB2_REG_EP_ADDR1 0x0292
#define SUSB2_REG_EP_ADDR2 0x02A2
#define SUSB2_REG_EP_ADDR3 0x02B2
#define SUSB2_REG_EP_ADDR4 0x02C2
#define SUSB2_REG_EP_ADDR5 0x02D2
#define SUSB2_REG_EP_ADDR6 0x02E2
#define SUSB2_REG_EP_ADDR7 0x02F2
// Device 2 Count
#define SUSB2_REG_EP_COUNT0 0x0284
#define SUSB2_REG_EP_COUNT1 0x0294
#define SUSB2_REG_EP_COUNT2 0x02A4
#define SUSB2_REG_EP_COUNT3 0x02B4
#define SUSB2_REG_EP_COUNT4 0x02C4
#define SUSB2_REG_EP_COUNT5 0x02D4
#define SUSB2_REG_EP_COUNT6 0x02E4
#define SUSB2_REG_EP_COUNT7 0x02F4
// Device 2 Status
#define SUSB2_REG_EP_STATUS0 0x0286
#define SUSB2_REG_EP_STATUS1 0x0296
#define SUSB2_REG_EP_STATUS2 0x02A6
#define SUSB2_REG_EP_STATUS3 0x02B6
#define SUSB2_REG_EP_STATUS4 0x02C6
#define SUSB2_REG_EP_STATUS5 0x02D6
#define SUSB2_REG_EP_STATUS6 0x02E6
#define SUSB2_REG_EP_STATUS7 0x02F6
// Device 2 Count result
#define SUSB2_REG_EP_CNTRES0 0x0288
#define SUSB2_REG_EP_CNTRES1 0x0298
#define SUSB2_REG_EP_CNTRES2 0x02A8
#define SUSB2_REG_EP_CNTRES3 0x02B8
#define SUSB2_REG_EP_CNTRES4 0x02C8
#define SUSB2_REG_EP_CNTRES5 0x02D8
#define SUSB2_REG_EP_CNTRES6 0x02E8
#define SUSB2_REG_EP_CNTRES7 0x02F8
// ---------------------------------------------------------
// others
#define HUSB_TDLISTDONE 0x1000
#define HUSB_SOF 0x2000
#define HUSB_ARMV 0x0001
#define HUSB_AINS_FS 0x0002
#define HUSB_AINS_LS 0x0004
#define HUSB_AWAKEUP 0x0008
#define HUSB_BRMV 0x0010
#define HUSB_BINS_FS 0x0020
#define HUSB_BINS_LS 0x0040
#define HUSB_BWAKEUP 0x0080
#define SUSB_EP0_MSG 0x0001
#define SUSB_EP1_MSG 0x0002
#define SUSB_EP2_MSG 0x0004
#define SUSB_EP3_MSG 0x0008
#define SUSB_EP4_MSG 0x0010
#define SUSB_EP5_MSG 0x0020
#define SUSB_EP6_MSG 0x0040
#define SUSB_EP7_MSG 0x0080
#define SUSB_RST_MSG 0x0100
#define SUSB_SOF_MSG 0x0200
#define SUSB_CFG_MSG 0x0400
#define SUSB_SUS_MSG 0x0800
#define SUSB_ID_MSG 0x4000
#define SUSB_VBUS_MSG 0x8000
// ---------------------------------------------------------
// Functions
// ---------------------------------------------------------
// HPI low-level routines
void cy67k3_isr(void);
void cy67k3_reset(void);
UINT16 cy67k3_read_HPI_DATA(void);
UINT16 cy67k3_read_HPI_MAILBOX(void);
UINT16 cy67k3_read_HPI_ADDRESS(void);
UINT16 cy67k3_read_HPI_STATUS(void);
void cy67k3_write_HPI_DATA(UINT16 data);
void cy67k3_write_HPI_MAILBOX(UINT16 data);
void cy67k3_write_HPI_ADDRESS(UINT16 data);
void cy67k3_write_HPI_STATUS(UINT16 data);
// HPI API
UINT32 hpi_init(void);
void hpi_mbx_write(UINT16 msgcode);
UINT32 hpi_mbx_read(void);
UINT32 hpi_read_reg(UINT16 addr);
UINT32 hpi_write_reg(UINT16 addr, UINT16 data);
UINT32 hpi_write_ram(UINT16 addr, UINT16 *pData, UINT32 num_words);
UINT32 hpi_read_ram(UINT16 addr, UINT16 *pData, UINT32 num_words);
UINT32 hpi_comm_reset(void);
UINT32 hpi_comm_jump2code(UINT16 addr);
UINT32 hpi_comm_callcode(UINT16 addr);
UINT32 hpi_comm_write_ctrl_reg(UINT16 addr, UINT16 data, UINT16 logic);
UINT32 hpi_comm_read_ctrl_reg(UINT16 addr);
UINT32 hpi_comm_write_xmem(UINT16 addr, UINT8 *pData, UINT16 len);
UINT32 hpi_comm_read_xmem(UINT16 addr, UINT8 *pData, UINT16 len);
UINT32 hpi_comm_exec_int(UINT16 intnum, UINT32 nargs, ...);
// USB API
UINT32 usb_init(void);
UINT32 usb_irp_register(usb_irp_t *pIRP, UINT32 port, UINT32 ept, UINT32 size, UINT32 is_out);
UINT32 usb_irp_enqueue(usb_irp_t *pIRP);
UINT32 usb_callback_register(UINT32 port, UINT32 type, fp_t pFunc, void *pArg);
#define FIFO_BLOCK 1
#define FIFO_NONBLOCK 0
UINT32 fifo_alloc(fifo_t *pObj, UINT32 size);
UINT32 fifo_free(fifo_t *pObj);
UINT32 fifo_flush(fifo_t *pObj);
UINT32 fifo_is_full(fifo_t *pObj);
UINT32 fifo_is_empty(fifo_t *pObj);
UINT32 fifo_read(fifo_t *pObj, UINT8 *pData, UINT32 size, UINT32 timeout, UINT32 do_block);
UINT32 fifo_write(fifo_t *pObj, UINT8 *pData, UINT32 size, UINT32 timeout, UINT32 do_block);
#endif // HPI_H
+499
View File
@@ -0,0 +1,499 @@
/* inflate routines for Palm OS (to inflate a deflated stream)
*
* Based heavily upon gunzip.c by Pasi Ojala <albert@cs.tut.fi>
* http://www.cs.tut.fi/~albert/Dev/gunzip/
* Many, many thanks for that code!
*
* Changes:
* 2002-12-30 - Added #defines to use zlib's struct instead of mine, just
* in case you want to compile it that way.
* 2002-12-29 - Found out that this is VERY slow. ZLib is 3x faster.
* Worked on speeding it up. Partially successful. Profiled
* code and marked critical areas. 1932 bytes added to a
* Palm program by linking in the .o file. Schweet!
* 2002-12-21 - Finished surgery. Only one function to inflate dynamic and
* fixed data. Rewrote table generation to be iterative.
* Hacked and slashed my way through unnecessary code.
* The size is now down to 3512 bytes.
* 2002-12-20 - Started major surgery
* 2002-12-19 - Looked at the code a bit more
* 2002-12-17 - Continued work. Down to about 6k for the .o file
* 2002-12-09 - Continued work, added z_stream_fid instead of globals
* 2002-12-08 - Started work so that it decompresses up to 64k (one memory
* chunk on the Palm.
* 2002-12-07 - Removed bit reverse table. Removed unzip code.
*/
#include "inflate.h"
#ifdef VERBOSE
#include <stdio.h> // Just in case you put a printf() function back in
#endif
void Status(char *, int);
typedef struct HufNode_struct {
// b0 and b1 are either values in the tree array to jump to (branches)
// or are literal values.
// if (bX & 0x8000)
// value = bX ^ 0x8000;
// else
// link_to_array_element = bX;
unsigned int b0; // Bigger than 1 byte (2 is ideal)
unsigned int b1; // Bigger than 1 byte (2 is ideal)
} HufNode;
// Not that rhobust anymore -- If out of data, this will
// return a whole lot of 1 bits.
//
// This function consumes a large percentage of time (#1)
char READBIT(z_stream *zs)
{
char carry;
if (zs->reserved == 1)
{
if (zs->avail_in == 0)
return 1;
zs->reserved = *(zs->next_in ++) | 0x0100;
zs->avail_in --;
}
carry = zs->reserved & 1;
zs->reserved >>= 1;
return carry;
}
// Make sure that [a] is <= 16
// If there are endian problems, force [a] to be <= 8
// Might be faster if all (up to [a] bits) of zs->reserved was read into res
// right away.
//
// This function consumes a large percentage of time (#4)
int READBITS(z_stream *zs, int a)
{
int res = 0, pos = 0;
while (a --)
{
if (zs->reserved == 1)
{
if (zs->avail_in == 0)
return 1;
zs->reserved = *(zs->next_in ++) | 0x0100;
zs->avail_in --;
}
res += (zs->reserved & 1) << pos;
zs->reserved >>= 1;
pos ++;
}
return res;
}
// Huffman tree structures, variables and related routines
//
// These routines are one-bit-at-a-time decode routines. They
// are not as fast as multi-bit routines, but maybe a bit easier
// to understand and use a lot less memory.
//
// The tree is created in an array
//
// currentTree = where to put the tree (in an array)
// numval = Number of elements in the lengths array
// lengths = array of lengths
//
//
// This function consumes a large percentage of time (#5)
int CreateTree(HufNode *currentTree, int numval, unsigned char *lengths) {
int i, j, len; // basically scratch values
int BlankNode; // Where is the next blank array index
int this_code, mask, *bitData; // used in tree generation
int bl_count[16] = { 0, }; // Counter of code lengths
int next_code[16] = { 0, }; // Code for a specific length
// 16 = (15 is max length of a code when inflating) + (1 for zero)
// Step 1: Count the code lengths
for (i = 0; i < numval; i ++)
{
j = lengths[i];
if (j > 15)
return 1;
bl_count[j] ++;
}
// Step 2: Find numerical value of the smallest code of each length
// Also note that I've inserted some weak validation code here. I'm
// not 100% sure that it is up to RFC specs, but it seems to work fine
// in my tests
//
// The validation theory is that at the root node, you have 2 branches or
// values possible. If you branch, you get 2 more potentials. If you
// get a value, you lose one potential. So, if the root node has one of
// each, the number of potentials at the next level is still two. If that
// node just has branches, the number of potentials is four. If both of
// the nodes on the following level just have values, the number of
// potentials is 0, leaving us with a complete tree.
//
// If I don't validate and if an invalid tree gets generated, an
// infinite loop is possible
bl_count[0] = 0;
j = 0;
len = 2;
for (i = 1; i < 16; i ++)
{
len -= bl_count[i];
len *= 2;
j = (j + bl_count[i - 1]) << 1;
next_code[i] = j;
}
if (len)
return 1;
// Step 3: Assign numerical values to all codes
BlankNode = 1;
currentTree[0].b0 = 0x0000;
currentTree[0].b1 = 0x0000;
for (i = 0; i < numval; i ++)
{
len = lengths[i];
if (len != 0)
{
this_code = next_code[len];
next_code[len] ++;
mask = 1 << (len - 1);
j = 0;
while (mask > 1)
{
if (this_code & mask)
bitData = &(currentTree[j].b1);
else
bitData = &(currentTree[j].b0);
if (*bitData == 0x0000)
{
*bitData = BlankNode;
j = BlankNode;
BlankNode ++;
currentTree[j].b0 = 0x0000;
currentTree[j].b1 = 0x0000;
}
else
j = *bitData;
mask >>= 1;
}
if (this_code & 0x01)
currentTree[j].b1 = 0x8000 | i;
else
currentTree[j].b0 = 0x8000 | i;
}
}
#ifdef VERBOSE
fprintf(stderr, "%d table entries used\n",
BlankNode);
if (numval < 20) {
for (i = 0; i < BlankNode; i ++)
{
fprintf(stdout, "0x%03x - ", i);
if (currentTree[i].b0 & 0x8000)
fprintf(stdout, "value: 0x%03x ", currentTree[i].b0 ^ 0x8000);
else
fprintf(stdout, " link: 0x%03x ", currentTree[i].b0);
if (currentTree[i].b1 & 0x8000)
fprintf(stdout, "value: 0x%03x\n", currentTree[i].b1 ^ 0x8000);
else
fprintf(stdout, " link: 0x%03x\n", currentTree[i].b1);
}
}
#endif
return 0;
}
// Using the tree passed in, read bits from the data stream until we arrive
// at the proper value
//
// This function consumes a large percentage of time (#2)
int DecodeValue(z_stream *zs, HufNode *currentTree)
{
unsigned int i = 0;
// decode one symbol of the data per iteration
// Infinite loop detection code could go here. Maximum
// bits to read is 15.
while (i < 0x8000)
{
if (READBIT(zs))
i = currentTree[i].b1;
else
i = currentTree[i].b0;
}
return i & 0x7FFF;
}
int Decompress_Stored(z_stream *zs)
{
int blockLen, cSum;
#ifdef VERBOSE
fprintf(stderr, "Stored\n");
#endif
zs->reserved = 1;;
if (zs->avail_in < 4)
return -1;
zs->avail_in -= 4;
blockLen = *(zs->next_in ++);
blockLen |= *(zs->next_in ++) << 8;
cSum = *(zs->next_in ++);
cSum |= (*(zs->next_in ++) << 8);
if ((blockLen + cSum) ^ 0xFFFF)
return 1;
if (zs->avail_in < blockLen || zs->avail_out < blockLen)
return -1;
zs->avail_in -= blockLen;
zs->avail_out -= blockLen;
while (blockLen --)
{
*(zs->next_out) = *(zs->next_in);
zs->next_out ++;
zs->next_in ++;
}
return 0;
}
int MakeTrees(z_stream *zs, char is_fixed, HufNode *literalTree,
HufNode *distanceTree)
{
// Order of the bit length code lengths
static const unsigned border[] = {
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 };
unsigned char ll[288+32];
int i, j, n, l, literalCodes, distCodes;
if (is_fixed)
{
literalCodes = 288;
// Set a large range to 8
for (i = 0; i < 288; i ++)
ll[i] = 8;
// In that range, set some to 9 and others to 7
// (smaller code, but slightly slower table generation)
for (i = 144; i < 256; i ++)
ll[i] = 9;
for (; i < 280; i ++)
ll[i] = 7;
distCodes = 32;
for (i = 288; i < 320; i ++)
ll[i] = 5;
}
else
{
literalCodes = 257 + READBITS(zs, 5);
distCodes = 1 + READBITS(zs, 5);
l = 4 + READBITS(zs, 4);
for (j = 0; j < 19; j ++)
ll[j] = 0;
// Get the decode tree code lengths
// The decode tree is Huffman encoded
for (j = 0; j < l; j++)
{
ll[border[j]] = READBITS(zs, 3);
}
if (CreateTree(distanceTree, 19, ll))
return 1;
// read in literal and distance code lengths
n = literalCodes + distCodes;
i = 0;
while (i < n)
{
j = DecodeValue(zs, distanceTree);
if (j < 16) // length of code in bits (0..15)
ll[i++] = j;
else if (j == 16)
{ // repeat last length 3 to 6 times
j = 3 + READBITS(zs, 2);
if (i + j > n)
return 1;
l = i ? ll[i-1] : 0;
while (j --)
ll[i++] = l;
}
else
{
if (j == 17) // 3 to 10 zero length codes
j = 3 + READBITS(zs, 3);
else // j == 18: 11 to 138 zero length codes
j = 11 + READBITS(zs, 7);
if (i + j > n)
return 1;
while (j --)
ll[i++] = 0;
}
}
}
// Can overwrite tree decode tree as it is not used anymore
if (CreateTree(literalTree, literalCodes, &ll[0]))
return 1;
if(CreateTree(distanceTree, distCodes, &ll[literalCodes]))
return 1;
return 0;
}
// This function consumes a large percentage of time (#3)
// Most output produced by gzip/zlib/etc is dynamic.
int Decompress_DynamicOrFixed(z_stream *zs, char is_fixed)
{
// Copy lengths for literal codes 257..285
static const unsigned short cplens[] = {
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0 };
// Extra bits for literal codes 257..285
static const unsigned short cplext[] = {
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2,
3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 99, 99 }; // 99==invalid
// Copy offsets for distance codes 0..29
static const unsigned short cpdist[] = {
0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0007, 0x0009, 0x000d,
0x0011, 0x0019, 0x0021, 0x0031, 0x0041, 0x0061, 0x0081, 0x00c1,
0x0101, 0x0181, 0x0201, 0x0301, 0x0401, 0x0601, 0x0801, 0x0c01,
0x1001, 0x1801, 0x2001, 0x3001, 0x4001, 0x6001 };
// Extra bits for distance codes
static const unsigned short cpdext[] = {
0, 0, 0, 0, 1, 1, 2, 2,
3, 3, 4, 4, 5, 5, 6, 6,
7, 7, 8, 8, 9, 9, 10, 10,
11, 11, 12, 12, 13, 13 };
HufNode literalTree[288];
HufNode distanceTree[32];
int j, l, dist;
#ifdef VERBOSE
if (is_fixed)
fprintf(stderr, "Fixed Huffman codes\n");
else
fprintf(stderr, "Dynamic Huffman codes\n");
#endif
if (MakeTrees(zs, is_fixed, literalTree, distanceTree))
return 1;
while (1)
{
j = DecodeValue(zs, literalTree);
if (j >= 256)
{
if (j == 256) // EOF
break;
//printf("%04x ", j);
j -= 256 + 1; // bytes + EOF
l = READBITS(zs, cplext[j]) + cplens[j];
//printf("%04x ", l);
j = DecodeValue(zs, distanceTree);
//printf("%02x ", j);
dist = READBITS(zs, cpdext[j]) + cpdist[j];
//printf("%04x ", dist);
//printf("LZ77 len %d dist %d @%04x\n", l, dist, bIdx);
while(l--)
{
//printf("%02x ", c);
if (! zs->avail_out --)
return -1;
*(zs->next_out ++) = *(zs->next_out - dist);
}
//printf("\n");
}
else
{
//printf("%02x\n", j);
if (! zs->avail_out --)
return -1;
*(zs->next_out ++) = (unsigned char) j;
}
}
return 0;
}
// Returns 0 if success
int InflateData(z_stream *zs) {
int last, type;
zs->reserved = 1;;
do
{
last = READBIT(zs);
#ifdef VERBOSE
if (last)
fprintf(stderr, "Last Block: ");
else
fprintf(stderr, "Not Last Block: ");
#endif
type = READBITS(zs, 2);
if (type == 0)
{
if (Decompress_Stored(zs))
return 1;
}
else if (type > 2)
{
#ifdef VERBOSE
if (type == 3)
fprintf(stderr, "Reserved block type!!\n");
else // the "else" should never happen
fprintf(stderr, "Unexpected value %d!\n", type);
#endif
zs->reserved = 1;;
return 1;
}
else
{
if (Decompress_DynamicOrFixed(zs, type & 0x01))
return 1;
}
} while(!last);
zs->reserved = 1;;
return 0;
}
+15
View File
@@ -0,0 +1,15 @@
#ifdef USE_ZLIB_STRUCT
#include "SysZLib.h" // For PalmOS. Change to your liking.
#else
typedef struct z_stream_s
{
unsigned char *next_in; // Next input byte (CHANGES)
unsigned int avail_in; // number of bytes left at next_in
unsigned char *next_out; // Next output byte goes here (CHANGES)
unsigned int avail_out; // number of bytes left at next_out
unsigned int reserved; // For the readbit() and readbits() functions
// Bigger than 1 byte
} z_stream;
#endif
int InflateData(z_stream *zs);
+71
View File
@@ -0,0 +1,71 @@
/*
io.c -- Test the serial I/O.
*/
#define BUFSIZE 80
#include <stdio.h>
main()
{
char buf[100];
char *tmp;
int result;
/* test the lowest level output function */
result = outbyte ('&');
if (result != 0x0) {
pass ("outbyte");
} else {
fail ("outbyte");
}
/* try writing a string */
result = write ("Write Test:\n", 12);
print ("result was ");
putnum (result);
outbyte ('\n');
if (result == 12) {
pass ("write");
} else {
fail ("write");
}
/* try the print() function too */
result = print ("Print Test:\n");
print ("result was ");
putnum (result);
outbyte ('\n');
if (result == 12) {
pass ("print");
} else {
fail ("print");
}
/* try the iprintf() function too */
result = print ("Iprintf Test:\n");
print ("result was ");
putnum (result);
outbyte ('\n');
if (result == 14) {
pass ("iprintf");
} else {
fail ("iprintf");
}
/* try to read a string */
print ("Type 5 characters");
result = 0;
result = read (0, buf, 5);
print (buf);
if (result == 5) {
pass ("read");
} else {
fail ("read");
}
/* clear everything out */
fflush (stdout);
}
+91
View File
@@ -0,0 +1,91 @@
#include <sys/times.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdlib.h>
#include "libsys.h"
#include "regdef.h"
#include "xcpt.h"
#include "irq.h"
static fp_t g_irq_handler[MAX_NUM_IRQ] = {NULL};
int _irq_dispatch(struct xcptcontext * xcp)
{
int i, ip;
ip = (xcp->cr >> 8) & 0xFF;
for (i=0; i < MAX_NUM_IRQ; i++)
{
if (ip & 1)
if (g_irq_handler[i])
(g_irq_handler[i])();
ip >>= 1;
}
return 0;
}
void interrupt_register(int irq_num, fp_t fp)
{
if ((irq_num >= 0) && (irq_num < MAX_NUM_IRQ))
g_irq_handler[irq_num] = fp;
}
void interrupt_enable(int irq_num)
{
reg_t reg, im;
if ((irq_num >= 0) && (irq_num < MAX_NUM_IRQ))
{
im = 1 << irq_num;
reg = CP0_SR_read();
reg |= (SR_MASK_IM & (im << 8));
CP0_SR_write(reg);
}
}
void interrupt_disable(int irq_num)
{
reg_t reg, im;
if ((irq_num >= 0) && (irq_num < MAX_NUM_IRQ))
{
im = 1 << irq_num;
reg = CP0_SR_read();
reg &= ~(SR_MASK_IM & (im << 8));
CP0_SR_write(reg);
}
}
void interrupt_set(int irq_num)
{
reg_t reg, ip;
if ((irq_num >= 0) && (irq_num < MAX_NUM_IRQ))
{
ip = 1 << irq_num;
reg = CP0_CR_read();
reg |= (CR_MASK_IP & (ip << 8));
CP0_CR_write(reg);
}
}
void interrupt_clr(int irq_num)
{
reg_t reg, ip;
if ((irq_num >= 0) && (irq_num < MAX_NUM_IRQ))
{
ip = 1 << irq_num;
reg = CP0_CR_read();
reg &= ~(CR_MASK_IP & (ip << 8));
CP0_CR_write(reg);
}
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef IRQ_H
#define IRQ_H
#include "xcpt.h"
#define MAX_NUM_IRQ 8
typedef void (*fp_t)(void);
int _irq_dispatch(struct xcptcontext * xcp);
void interrupt_register(int irq_num, fp_t fp);
void interrupt_enable(int irq_num);
void interrupt_disable(int irq_num);
#endif // IRQ_H
+7
View File
@@ -0,0 +1,7 @@
#!/bin/sh
TARGET=$(basename $1 .c)
xtclsh.exe $TARGET.RAM.tcl
#xtclsh.exe $TARGET.ROM.tcl
+180
View File
@@ -0,0 +1,180 @@
#include <regdef.h>
#include <xcpt_asm.h>
.section .ktext,"ax"
LEAF(xcptlow_handler)
.set noreorder
.set noat
/* Note: exceptions do not save and restore registers k0 and k1.
* on entry, k1 = exception class.
*/
/* allocate exception stack frame (on 8-byte boundary) */
subu k1, sp, XCP_SIZE
srl k1, 3 /* shift right/left -> alligned on boundary */
sll k1, 3
/* save enough registers to get by */
sw AT, XCP_AT(k1)
sw v0, XCP_V0(k1)
sw v1, XCP_V1(k1)
sw a0, XCP_A0(k1)
sw a1, XCP_A1(k1)
sw a2, XCP_A2(k1)
sw a3, XCP_A3(k1)
sw sp, XCP_SP(k1)
sw ra, XCP_RA(k1)
/* get coprocessor 0 exception state */
mfc0 a0, CP0_CR
mfc0 a1, CP0_SR
mfc0 a2, CP0_BADDR
mfc0 a3, CP0_EPC
/* we can safely use AT now */
.set at
/* switch to using sp to point at exception frame */
move sp, k1
/* nothing sensible to store for k0/k1, store zero */
sw zero, XCP_K0(sp)
sw zero, XCP_K1(sp)
/* we are now interruptible: dump all remaining state
* into the exception stack frame.
*/
/* coprocessor exception state */
sw a0, XCP_CR(sp)
sw a1, XCP_SR(sp)
sw a2, XCP_BADDR(sp)
sw a3, XCP_EPC(sp)
/* mdhi and mdlo */
mfhi v0
mflo v1
sw v0, XCP_MDHI(sp)
sw v1, XCP_MDLO(sp)
/* Save all the other general registers.
* We save zero, s0-s7 and s8 as well, as instruction emulators (e.g. FP
* operations) and debuggers rely on all registers stored together in
* well-defined structure.
*/
sw zero, XCP_ZERO(sp)
sw t0, XCP_T0(sp)
sw t1, XCP_T1(sp)
sw t2, XCP_T2(sp)
sw t3, XCP_T3(sp)
sw t4, XCP_T4(sp)
sw t5, XCP_T5(sp)
sw t6, XCP_T6(sp)
sw t7, XCP_T7(sp)
sw s0, XCP_S0(sp)
sw s1, XCP_S1(sp)
sw s2, XCP_S2(sp)
sw s3, XCP_S3(sp)
sw s4, XCP_S4(sp)
sw s5, XCP_S5(sp)
sw s6, XCP_S6(sp)
sw s7, XCP_S7(sp)
sw t8, XCP_T8(sp)
sw t9, XCP_T9(sp)
sw gp, XCP_GP(sp)
sw s8, XCP_S8(sp)
/* I don't know what the following does. [rb] */
/* load our _gp pointer */
# la gp, _gp
/* and call the C exception handler */
move a0, sp # arg1 = &xcp
subu sp, 16 # (arg save area)
j _xcptcall
move ra, zero # fake return address
/* This strange call to _xcptcall with zero return address is to
* help exception-aware debuggers to trace back over the exception event.
* We are basically interposing a bogus stackframe (with a zero return
* address) between the C exception handler and the actual machine
* exception.
*/
xcptrest:
.set noat
add AT, sp, 16
/* at points to exception frame */
xcptrestother:
/* restore all state */
/* restore most general registers */
lw t0, XCP_T0(AT)
lw t1, XCP_T1(AT)
lw t2, XCP_T2(AT)
lw t3, XCP_T3(AT)
lw t4, XCP_T4(AT)
lw t5, XCP_T5(AT)
lw t6, XCP_T6(AT)
lw t7, XCP_T7(AT)
lw s0, XCP_S0(AT)
lw s1, XCP_S1(AT)
lw s2, XCP_S2(AT)
lw s3, XCP_S3(AT)
lw s4, XCP_S4(AT)
lw s5, XCP_S5(AT)
lw s6, XCP_S6(AT)
lw s7, XCP_S7(AT)
lw t8, XCP_T8(AT)
lw t9, XCP_T9(AT)
lw gp, XCP_GP(AT)
lw s8, XCP_S8(AT)
/* mdhi and mdlo */
lw v0, XCP_MDHI(AT)
lw v1, XCP_MDLO(AT)
mthi v0
mtlo v1
/* remaining general registers */
lw a0, XCP_A0(AT)
lw a1, XCP_A1(AT)
lw a2, XCP_A2(AT)
lw a3, XCP_A3(AT)
lw ra, XCP_RA(AT)
/* restore the exception-time status register */
.set noreorder
lw v0, XCP_SR(AT)
nop
mtc0 v0, CP0_SR
lw v1, XCP_V1(AT)
lw v0, XCP_V0(AT)
lw sp, XCP_SP(AT)
/* we are not uninterruptible and can use k1 safely */
lw k1, XCP_EPC(AT)
lw AT, XCP_AT(AT)
mtc0 k1, CP0_EPC
j k1
rfe
.set reorder
.set at
END(xcptlow_handler)
LEAF(_xcptcall)
/* on entry: a0 == &xcp */
subu sp, 24
sw ra, 16(sp)
/* punt out to _xcpt_deliver */
jal _xcpt_deliver
nop
lw ra, 16(sp)
addu sp, 24
beqz ra, xcptrest
nop
j ra
nop
END(_xcptcall)
+210
View File
@@ -0,0 +1,210 @@
GAS LISTING /tmp/ccsFBUzg.s page 1
1 # 1 "kernel.S"
1 #include <regdef.h>
0
0
1 /*
2 #include <xcpt_asm.h>
1 #ifndef XCPT_ASM_H
3
4 .section .ktext,"ax"
5
6 LEAF(xcptlow_handler)
7 .set noreorder
8 .set noat
9 /* Note: exceptions do not save and restore registers k0 and k1.
10 * on entry, k1 = exception class.
11 */
12
13 /* allocate exception stack frame (on 8-byte boundary) */
14 0000 00FCBB27 subu k1, sp, XCP_SIZE
15 0004 C2D81B00 srl k1, 3 /* shift right/left -> alligned on boundary */
16 0008 C0D81B00 sll k1, 3
17
18 /* save enough registers to get by */
19 000c 140061AF sw AT, XCP_AT(k1)
20 0010 180062AF sw v0, XCP_V0(k1)
21 0014 1C0063AF sw v1, XCP_V1(k1)
22 0018 200064AF sw a0, XCP_A0(k1)
23 001c 240065AF sw a1, XCP_A1(k1)
24 0020 280066AF sw a2, XCP_A2(k1)
25 0024 2C0067AF sw a3, XCP_A3(k1)
26 0028 84007DAF sw sp, XCP_SP(k1)
27 002c 8C007FAF sw ra, XCP_RA(k1)
28
29 /* get coprocessor 0 exception state */
30 0030 00680440 mfc0 a0, CP0_CR
31 0034 00600540 mfc0 a1, CP0_SR
32 0038 00400640 mfc0 a2, CP0_BADDR
33 003c 00700740 mfc0 a3, CP0_EPC
34
35 /* we can safely use AT now */
36 .set at
37
38 /* switch to using sp to point at exception frame */
39 0040 21E86003 move sp, k1
40
41 /* nothing sensible to store for k0/k1, store zero */
42 0044 7800A0AF sw zero, XCP_K0(sp)
43 0048 7C00A0AF sw zero, XCP_K1(sp)
44
45 /* we are now interruptible: dump all remaining state
46 * into the exception stack frame.
47 */
48 /* coprocessor exception state */
49 004c 0400A4AF sw a0, XCP_CR(sp)
50 0050 0000A5AF sw a1, XCP_SR(sp)
51 0054 0C00A6AF sw a2, XCP_BADDR(sp)
52 0058 0800A7AF sw a3, XCP_EPC(sp)
GAS LISTING /tmp/ccsFBUzg.s page 2
53
54 /* mdhi and mdlo */
55 005c 10100000 mfhi v0
56 0060 12180000 mflo v1
57 0064 9400A2AF sw v0, XCP_MDHI(sp)
58 0068 9000A3AF sw v1, XCP_MDLO(sp)
59
60 /* Save all the other general registers.
61 * We save zero, s0-s7 and s8 as well, as instruction emulators (e.g. FP
62 * operations) and debuggers rely on all registers stored together in
63 * well-defined structure.
64 */
65 006c 1000A0AF sw zero, XCP_ZERO(sp)
66 0070 3000A8AF sw t0, XCP_T0(sp)
67 0074 3400A9AF sw t1, XCP_T1(sp)
68 0078 3800AAAF sw t2, XCP_T2(sp)
69 007c 3C00ABAF sw t3, XCP_T3(sp)
70 0080 4000ACAF sw t4, XCP_T4(sp)
71 0084 4400ADAF sw t5, XCP_T5(sp)
72 0088 4800AEAF sw t6, XCP_T6(sp)
73 008c 4C00AFAF sw t7, XCP_T7(sp)
74 0090 5000B0AF sw s0, XCP_S0(sp)
75 0094 5400B1AF sw s1, XCP_S1(sp)
76 0098 5800B2AF sw s2, XCP_S2(sp)
77 009c 5C00B3AF sw s3, XCP_S3(sp)
78 00a0 6000B4AF sw s4, XCP_S4(sp)
79 00a4 6400B5AF sw s5, XCP_S5(sp)
80 00a8 6800B6AF sw s6, XCP_S6(sp)
81 00ac 6C00B7AF sw s7, XCP_S7(sp)
82 00b0 7000B8AF sw t8, XCP_T8(sp)
83 00b4 7400B9AF sw t9, XCP_T9(sp)
84 00b8 8000BCAF sw gp, XCP_GP(sp)
85 00bc 8800BEAF sw s8, XCP_S8(sp)
86
87 /* I don't know what the following does. [rb] */
88 /* load our _gp pointer */
89 # la gp, _gp
90
91 /* and call the C exception handler */
92 00c0 2120A003 move a0, sp # arg1 = &xcp
93 00c4 F0FFBD27 subu sp, 16 # (arg save area)
94 00c8 00000008 j _xcptcall
95 00cc 21F80000 move ra, zero # fake return address
96
97 /* This strange call to _xcptcall with zero return address is to
98 * help exception-aware debuggers to trace back over the exception event.
99 * We are basically interposing a bogus stackframe (with a zero return
100 * address) between the C exception handler and the actual machine
101 * exception.
102 */
103 xcptrest:
104 .set noat
105 00d0 1000A123 add AT, sp, 16
106
107 /* at points to exception frame */
108 xcptrestother:
109 /* restore all state */
GAS LISTING /tmp/ccsFBUzg.s page 3
110 /* restore most general registers */
111 00d4 3000288C lw t0, XCP_T0(AT)
112 00d8 3400298C lw t1, XCP_T1(AT)
113 00dc 38002A8C lw t2, XCP_T2(AT)
114 00e0 3C002B8C lw t3, XCP_T3(AT)
115 00e4 40002C8C lw t4, XCP_T4(AT)
116 00e8 44002D8C lw t5, XCP_T5(AT)
117 00ec 48002E8C lw t6, XCP_T6(AT)
118 00f0 4C002F8C lw t7, XCP_T7(AT)
119 00f4 5000308C lw s0, XCP_S0(AT)
120 00f8 5400318C lw s1, XCP_S1(AT)
121 00fc 5800328C lw s2, XCP_S2(AT)
122 0100 5C00338C lw s3, XCP_S3(AT)
123 0104 6000348C lw s4, XCP_S4(AT)
124 0108 6400358C lw s5, XCP_S5(AT)
125 010c 6800368C lw s6, XCP_S6(AT)
126 0110 6C00378C lw s7, XCP_S7(AT)
127 0114 7000388C lw t8, XCP_T8(AT)
128 0118 7400398C lw t9, XCP_T9(AT)
129 011c 80003C8C lw gp, XCP_GP(AT)
130 0120 88003E8C lw s8, XCP_S8(AT)
131
132 /* mdhi and mdlo */
133 0124 9400228C lw v0, XCP_MDHI(AT)
134 0128 9000238C lw v1, XCP_MDLO(AT)
135 012c 11004000 mthi v0
136 0130 13006000 mtlo v1
137
138 /* remaining general registers */
139 0134 2000248C lw a0, XCP_A0(AT)
140 0138 2400258C lw a1, XCP_A1(AT)
141 013c 2800268C lw a2, XCP_A2(AT)
142 0140 2C00278C lw a3, XCP_A3(AT)
143 0144 8C003F8C lw ra, XCP_RA(AT)
144
145 /* restore the exception-time status register */
146 .set noreorder
147 0148 0000228C lw v0, XCP_SR(AT)
148 014c 00000000 nop
149 0150 00608240 mtc0 v0, CP0_SR
150 0154 1C00238C lw v1, XCP_V1(AT)
151 0158 1800228C lw v0, XCP_V0(AT)
152 015c 84003D8C lw sp, XCP_SP(AT)
153
154 /* we are not uninterruptible and can use k1 safely */
155 0160 08003B8C lw k1, XCP_EPC(AT)
156 0164 1400218C lw AT, XCP_AT(AT)
157 0168 00709B40 mtc0 k1, CP0_EPC
158 016c 08006003 j k1
159 0170 10000042 rfe
160
161 .set reorder
162 .set at
163 END(xcptlow_handler)
164
165
166 LEAF(_xcptcall)
GAS LISTING /tmp/ccsFBUzg.s page 4
167 /* on entry: a0 == &xcp */
168 0174 E8FFBD27 subu sp, 24
169 0178 1000BFAF sw ra, 16(sp)
170
171 /* punt out to _xcpt_deliver */
172 017c 0000000C jal _xcpt_deliver
172 00000000
173 0184 00000000 nop
174 0188 1000BF8F lw ra, 16(sp)
175 018c 1800BD27 addu sp, 24
176 0190 CFFFE013 beqz ra, xcptrest
176 00000000
177 0198 0800E003 nop
178 019c 00000000 j ra
179 01a0 00000000 nop
180 END(_xcptcall)
GAS LISTING /tmp/ccsFBUzg.s page 5
DEFINED SYMBOLS
kernel.S:6 .ktext:0000000000000000 xcptlow_handler
kernel.S:166 .ktext:0000000000000174 _xcptcall
kernel.S:103 .ktext:00000000000000d0 xcptrest
kernel.S:108 .ktext:00000000000000d4 xcptrestother
UNDEFINED SYMBOLS
_xcpt_deliver
+260
View File
@@ -0,0 +1,260 @@
.file "kernel.s"
.equ stack_ptr, 0x7FFFEFFC
.equ baudrate, 0x0D
.equ sys_led_port, 0xA0000000
.equ sys_uart_baud, 0xA0000009
.equ sys_uart_stat, 0xA0000008
.equ sys_uart_data, 0xA0000004
.equ sys_timer_sec, 0xA0000014
.equ sys_timer_usec, 0xA0000010
.section .kdata,"a"
.align 2
_k_stack: .space 256, 0
_k_msg1: .asciiz "Exception at "
_k_msg2: .asciiz "EPC : "
_k_msg3: .asciiz "Cause : "
_k_msg4: .asciiz "Status : "
_k_msg5: .asciiz "BadVAddr : "
_k_crlf: .asciiz "\r\n"
_k_hextbl: .ascii "0123456789ABCDEF"
.section .ktext,"ax"
.align 2
.globl _kputs
.macro kpush reg
addiu $sp, 4
sw \reg, 0($sp)
.endm
.macro kpop reg
lw \reg, 0($sp)
addiu $sp, -4
.endm
_exc_handler:
sw $sp, _k_stack
la $sp, _k_stack
kpush $8
kpush $9
kpush $10
kpush $11
kpush $12
kpush $31
.set noreorder
# # Get BadVAddr
# mfc0 $10, $8
# kpush $10
# # Get Status
# mfc0 $10, $12
# kpush $10
# # Get Cause
# mfc0 $10, $13
# kpush $10
# srl $10, 29
# andi $11, $10, 4
# # Get EPC
# mfc0 $10, $14
# kpush $10
#
# # Get real EPC
# addu $10, $11
# kpush $10
#
# # set uart
# la $26, sys_uart_baud
# addiu $27, $0, baudrate
# sb $27, 0($26)
#
# # Print CRLF
# la $11, _k_crlf
# jal _kputs
# nop
#
# # Print real EPC
# la $11, _k_msg1
# jal _kputs
# nop
# kpop $10
# jal _kprint_word
# nop
# la $11, _k_crlf
# jal _kputs
# nop
#
# # Print EPC
# la $11, _k_msg2
# jal _kputs
# nop
# kpop $10
# jal _kprint_word
# nop
# la $11, _k_crlf
# jal _kputs
# nop
#
# # Print Cause
# la $11, _k_msg3
# jal _kputs
# nop
# kpop $10
# jal _kprint_word
# nop
# la $11, _k_crlf
# jal _kputs
# nop
#
# # Print Status
# la $11, _k_msg4
# jal _kputs
# nop
# kpop $10
# jal _kprint_word
# nop
# la $11, _k_crlf
# jal _kputs
# nop
#
# # Print BadVAddr
# la $11, _k_msg5
# jal _kputs
# nop
# kpop $10
# jal _kprint_word
# nop
# la $11, _k_crlf
# jal _kputs
# nop
#
# Set Error LED and ExcCode LEDs
# Get Cause
# mfc0 $26, $13
# la $27, sys_led_port
# srl $26, 2
# andi $26, 0x000F
# or $26, $27
# sw $26, 0($27)
# wait for all interrupts = 0
#$w4x: mfc0 $26, $13
# mfc0 $27, $12
# srl $26, 8
# srl $27, 8
# and $26, $27
# bnez $26, $w4x
# Get return address
mfc0 $26, $14
$no_int: kpop $31
kpop $12
kpop $11
kpop $10
kpop $9
kpop $8
lw $sp, _k_stack
# Return
jr $26
rfe
.set reorder
# word = $10
_kprint_word:
.set noreorder
kpush $31
kpush $10
srl $10, 16
jal _kprint_halfword
nop
kpop $10
jal _kprint_halfword
nop
kpop $31
jr $31
nop
.set noreorder
# halfword = $10
_kprint_halfword:
.set noreorder
kpush $31
kpush $10
srl $10, 8
jal _kprint_byte
nop
kpop $10
jal _kprint_byte
nop
kpop $31
jr $31
nop
.set noreorder
# byte = $10
_kprint_byte:
.set noreorder
kpush $31
kpush $10
srl $10, 4
jal _kprint_nibble
nop
kpop $10
jal _kprint_nibble
nop
kpop $31
jr $31
nop
.set noreorder
_kprint_nibble:
.set noreorder
kpush $31
kpush $10
la $12, _k_hextbl
andi $10, 0xF
addu $12, $10
lbu $10, 0($12)
jal _ksaus
nop
kpop $10
kpop $31
jr $31
nop
.set noreorder
# char = $10
_ksaus:
.set noreorder
la $8, sys_uart_stat
lbu $8, 0($8)
la $9, sys_uart_data
andi $8, 0x02
bnez $8, _ksaus
nop
j $31
sb $10, 0($9)
.set reorder
_kputs:
.set noreorder
kpush $11
kpush $31
$kpl: lbu $10, 0($11)
addiu $11, 1
blez $10, $kpex
nop
jal _ksaus
nop
j $kpl
nop
$kpex: kpop $31
kpop $11
jr $31
nop
.set reorder
+187
View File
@@ -0,0 +1,187 @@
/***************************************************************/
/* main.c */
/* Digital PLL */
/***************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define TYPE_AP_DEP 1
#define TYPE_AP_ARR 2
#define TYPE_DIRECT 3
#define TYPE_LEG 4
/***************************************************************/
typedef struct _srtentry_t
{
char name[257];
int type;
char typestr[257];
char long_prefix;
double longitude;
char lat_prefix;
double latitude;
int ground_level;
} rtentry_t;
typedef struct _splan_t
{
char name[1025];
FILE *pFile;
} plant_t;
/***************************************************************/
int entry_print(FILE *pFile, rtentry_t *pEnt)
{
int err = 0;
switch (pEnt->type)
{
case TYPE_AP_DEP:
fprintf(pFile, "%s\n", pEnt->name);
fprintf(pFile, "1\n");
fprintf(pFile, "%s\n", pEnt->typestr);
fprintf(pFile, "1 %c %.5f %c %.6f %d\n", toupper(pEnt->long_prefix), pEnt->longitude, toupper(pEnt->lat_prefix), pEnt->latitude, pEnt->ground_level);
fprintf(pFile, "-----\n");
fprintf(pFile, "1\n"); // departure
fprintf(pFile, "0\n");
fprintf(pFile, "\n");
fprintf(pFile, "1\n");
fprintf(pFile, "%d\n", pEnt->ground_level);
fprintf(pFile, "-\n");
fprintf(pFile, "-1000000\n");
fprintf(pFile, "-1000000\n");
fprintf(pFile, "\n");
break;
case TYPE_AP_ARR:
fprintf(pFile, "%s\n", pEnt->name);
fprintf(pFile, "1\n"); // Airport
fprintf(pFile, "-\n");
fprintf(pFile, "1 %c %.5f %c %.6f %d\n", toupper(pEnt->long_prefix), pEnt->longitude, toupper(pEnt->lat_prefix), pEnt->latitude, pEnt->ground_level);
fprintf(pFile, "-----\n");
fprintf(pFile, "0\n"); // arrival
fprintf(pFile, "0\n");
fprintf(pFile, "\n");
fprintf(pFile, "1\n");
fprintf(pFile, "%d\n", pEnt->ground_level);
fprintf(pFile, "-\n");
fprintf(pFile, "-1000000\n");
fprintf(pFile, "-1000000\n");
fprintf(pFile, "\n");
break;
case TYPE_DIRECT:
fprintf(pFile, "%s\n", pEnt->name);
fprintf(pFile, "2\n"); // Direct
fprintf(pFile, "%s\n", pEnt->typestr);
fprintf(pFile, "1 %c %.5f %c %.6f %d\n", toupper(pEnt->long_prefix), pEnt->longitude, toupper(pEnt->lat_prefix), pEnt->latitude, pEnt->ground_level);
fprintf(pFile, "0\n");
fprintf(pFile, "0\n");
fprintf(pFile, "0\n");
fprintf(pFile, "\n");
break;
case TYPE_LEG:
fprintf(pFile, "%s\n", pEnt->name);
fprintf(pFile, "5\n"); // LEG
fprintf(pFile, "%s\n", pEnt->typestr);
fprintf(pFile, "1 %c %.5f %c %.6f %d\n", toupper(pEnt->long_prefix), pEnt->longitude, toupper(pEnt->lat_prefix), pEnt->latitude, pEnt->ground_level);
fprintf(pFile, "0\n");
fprintf(pFile, "0\n");
fprintf(pFile, "0\n");
fprintf(pFile, "\n");
break;
default:
err = -1;
break;
}
return err;
}
int entry_set(rtentry_t *pEnt, int type, char *pName, char *pTypeStr, double latitude, double longitude, int gl)
{
strcpy(pEnt->typestr, pTypeStr);
if (longitude < 0)
pEnt->long_prefix = 'S';
else
pEnt->long_prefix = 'N';
pEnt->longitude = fabs(longitude);
if (latitude < 0)
pEnt->lat_prefix = 'E';
else
pEnt->lat_prefix = 'W';
pEnt->latitude = fabs(latitude);
if (!pName)
{
if (TYPE_DIRECT != type)
return -1;
sprintf(pEnt->name, "%c%.0f%c%.0f", pEnt->long_prefix, pEnt->longitude, pEnt->lat_prefix, pEnt->latitude);
}
else
{
strcpy(pEnt->name, pName);
}
pEnt->ground_level = gl;
pEnt->type = type;
return 0;
}
#define NUM_WP 17
int main(void)
{
int i;
rtentry_t ent[NUM_WP];
FILE *pFile;
// pFile = fopen("C:\\Programme\\Microsoft Games\\Flight Simulator 9\\PMDG\\FLIGHTPLANS\\test.rte", "w");
pFile = stderr;
/*
entry_set(&ent[0], TYPE_AP_DEP, "EDDF", "DIRECT", -8.543125, 50.12642, 364);
entry_set(&ent[1], TYPE_DIRECT, "NAPSI", "DIRECT", -6.021389, 51.85528, 0);
entry_set(&ent[2], TYPE_LEG, "GOMUP", "UN572", 10, 57, 0);
entry_set(&ent[3], TYPE_DIRECT, NULL, "DIRECT", 10.321, 60.123, 0);
entry_set(&ent[4], TYPE_AP_ARR, "KSFO", "-", 122.543125, 37.12642, 13);
*/
i = 0;
entry_set(&ent[i++], TYPE_AP_DEP, "EDDF", "DIRECT", -8.543125, 50.12642, 364);
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.495517678260868,50.08917173742456,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.437482727705472,50.09692405502469,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.314112693383819,50.12183705278613,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.282904310172924,50.19787276231849,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.310346569009369,50.43053520194942,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.310814943566584,50.7757798665427,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.339329466837882,51.98034086955558,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.24621634315524,52.92949698506673,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.192535830735153,53.12125289919808,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.279381463623494,53.18778726201814,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.444951496795227,53.16928101451241,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.503513867383489,53.07199210889475,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.571512947137819,53.04267405471422,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.648398246256804,53.0469130539089,0 );
entry_set(&ent[i++], TYPE_DIRECT, NULL, "DIRECT", -8.723907341812861,53.0466716799862,0 );
entry_set(&ent[i++], TYPE_AP_ARR, "EDDW", "-", -8.723907341812861, 53.0466716799862, 13);
fprintf(pFile, "Generated by kml2rte v0.1\n\n%d\n\n", NUM_WP);
for (i=0; i < NUM_WP; i++)
entry_print(pFile, &ent[i]);
// fclose (pFile);
return EXIT_SUCCESS;
}
+448
View File
@@ -0,0 +1,448 @@
#include <sys/times.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include "libsys.h"
// ---------------------------------------------------------------------------------
// MIPS specific
UINT32 CP0_SR_read(void)
{
UINT32 result;
__asm
(
"mfc0 %[val], $12\n"
: [val] "=r" (result)
);
return result;
}
void CP0_SR_write(UINT32 val)
{
__asm
(
"mtc0 %[val], $12\n"
: /* no output */
: [val] "r" (val)
);
}
UINT32 CP0_CR_read(void)
{
UINT32 result;
__asm
(
"mfc0 %[val], $13\n"
: [val] "=r" (result)
);
return result;
}
void CP0_CR_write(UINT32 val)
{
__asm
(
"mtc0 %[val], $13\n"
:
: [val] "r" (val)
);
}
UINT32 CP0_TR_read(void)
{
UINT32 result;
__asm
(
"mfc0 %[val], $31\n"
: [val] "=r" (result)
);
return result;
}
void CP0_TR_write(UINT32 val)
{
__asm
(
"mtc0 %[val], $31\n"
:
: [val] "r" (val)
);
}
UINT32 CP0_PRID_read(void)
{
UINT32 result;
__asm
(
"mfc0 %[val], $15\n"
: [val] "=r" (result)
);
return result;
}
// ---------------------------------------------------------------------------------
char readchar(void)
{
volatile UINT32 *pUART_stat = (UINT32*)sys_uart_stat;
volatile UINT32 *pUART_data = (UINT32*)sys_uart_data;
while(!(0x10 & *pUART_stat));
return (char)*pUART_data;
}
void writechar(char c)
{
volatile UINT32 *pUART_stat = (UINT32*)sys_uart_stat;
volatile UINT32 *pUART_data = (UINT32*)sys_uart_data;
while((0x01 & *pUART_stat) != 0);
*pUART_data = (UINT32)c;
}
void _putchar(char c)
{
if (c == 0x0A)
{
writechar(0x0D);
}
writechar(c);
}
void cg_writechar(char c)
{
volatile UINT32 *pCG_data = (UINT32*)sys_vga_data;
while (!(*pCG_data & 1));
*pCG_data = (UINT32)c;
}
void cg_clr_line(void)
{
volatile UINT32 *pCG_clrline = (UINT32*)sys_vga_clrline;
while (!(*pCG_clrline & 1));
*pCG_clrline = 1;
}
void _cg_putchar(char c)
{
if (c == 0x0A)
{
cg_writechar(0x0D);
}
cg_writechar(c);
if (c == 0x0A)
cg_clr_line();
}
void _exit (int exitcode)
{
while(1);
}
void sleep(unsigned ms)
{
unsigned stop;
struct tms t;
times(&t);
stop = t.tms_utime + ms;
do
{
times(&t);
} while (t.tms_utime < stop);
}
int getrusage(int who, struct rusage *usage)
{
volatile long *pReg_usec = (long*)sys_timer_usec;
volatile long *pReg_sec = (long*)sys_timer_sec;
// who: RUSAGE_SELF or RUSAGE_CHILDREN
usage->ru_utime.tv_usec = *pReg_usec;
usage->ru_utime.tv_sec = *pReg_sec;
usage->ru_stime.tv_usec = *pReg_usec;
usage->ru_stime.tv_sec = *pReg_sec;
}
clock_t times(struct tms *buffer)
{
volatile long *pReg_usec = (long*)sys_timer_usec;
volatile long *pReg_sec = (long*)sys_timer_sec;
long sec;
long usec;
sec = *pReg_sec;
usec = *pReg_usec;
if (buffer)
{
buffer->tms_utime = sec*1000 + usec/1000;
buffer->tms_stime = 0;
buffer->tms_cutime = 0;
buffer->tms_cstime = 0;
}
return (clock_t)sec;
}
int gettimeofday(struct timeval *tp, void *tzp)
{
volatile long *pReg_usec = (long*)sys_timer_usec;
volatile long *pReg_sec = (long*)sys_timer_sec;
if (tp)
{
tp->tv_sec = *pReg_sec;
tp->tv_usec = *pReg_usec;
}
return 0;
}
int settimeofday(const struct timeval *tp, const struct timezone *tzp)
{
volatile long *pReg_usec = (long*)sys_timer_usec;
volatile long *pReg_sec = (long*)sys_timer_sec;
// div_t res;
// res = div(tp->tv_usec, 1E6);
if (tp)
{
*pReg_usec = tp->tv_usec % (long)1E6; //res.rem;
*pReg_sec = tp->tv_sec + tp->tv_usec / (long)1E6;
}
return 0;
}
caddr_t sbrk(int incr)
{
extern char end;
extern char stack_ptr;
static char *heap_end;
char *prev_heap_end;
if (heap_end == 0)
{
heap_end = &end;
}
prev_heap_end = heap_end;
if (heap_end + incr > &stack_ptr)
{
// sputs("Heap and stack collision\n");
// sputs("Stack Ptr = ");print_word(&stack_ptr);sputs("\n");
// sputs("Heap end = ");print_word(heap_end);sputs("\n");
// sputs("Increment = ");print_word(incr);sputs("\n");
exit(1);
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
int fstat(int file, struct stat *st)
{
// sputs("fstat\n");
st->st_mode = S_IFCHR;
st->st_blksize = 0;
return 0;
}
int lseek(int file, int ptr, int dir)
{
// sputs("lseek\n");
errno = ESPIPE;
return -1;
}
int open(const char *name, int flags, int mode)
{
// sputs("open\n");
errno = EIO;
return -1;
}
int close(int file)
{
// sputs("close\n");
return 0;
}
int read(int file, char *ptr, int len)
{
int i;
char c;
// sputs("read\n");
i = 0;
while (i < len)
{
c = readchar();
if ((c == 0x0D) || (c == 0x0A))
{
writechar(0x0D);
writechar(0x0A);
if (i==0)
continue;
ptr[i++] = c;
break;
}
else
{
ptr[i++] = c;
writechar(c);
}
}
return i;
}
int write(int file, char *ptr, int len)
{
int i;
if (file == 1)
{
for (i=0; i < len; i++)
STDOUT_FUNCTION(*ptr++);
}
if (file == 2)
{
for (i=0; i < len; i++)
STDERR_FUNCTION(*ptr++);
}
return i;
}
int isatty(int file)
{
// sputs("Isatty()\n");
return 1;
}
int sputs(char *pStr)
{
char *start;
start = pStr;
while(*pStr)
_putchar(*(pStr++));
return pStr - start;
}
void print_byte(char byte)
{
int i;
unsigned char c, nibble;
for (i=0; i < 2; i++)
{
nibble = (char)((byte >> 4) & 0xF);
byte <<= 4;
if (nibble < 10)
c = nibble + '0';
else
c = nibble + 'A' - 10;
_putchar(c);
}
}
void print_word(int word)
{
int i;
unsigned char c, nibble;
for (i=0; i < 4; i++)
{
c = (char) (word >> 24);
print_byte(c);
word <<= 8;
}
}
// ---------------------------------------------------------------------------------
// PrintBuffer8()
// Prints byte buffer as hex and ascii interpretation
// ---------------------------------------------------------------------------------
// _Parameters :
// pBuf: : IN: Buffer to display
// nbpr : Number of bytes per row to display
// len : Length of input buffer
// _Return: none
//
// ---------------------------------------------------------------------------
void PrintBuffer8(UINT8 *pBuf, int nbpr, int len)
{
int i, j, cnt_hex, cnt_asc;
unsigned char c;
i = j = 0;
cnt_hex = len;
cnt_asc = len;
do
{
print_word(i);
sputs(": ");
for (j=0; j < nbpr; j++)
{
if (cnt_hex)
{
print_byte(pBuf[i+j]);
sputs(" ");
cnt_hex--;
}
else
{
sputs(" ");
break;
}
}
sputs(" ");
for (j=0; j < nbpr; j++)
{
if (cnt_asc)
{
c = pBuf[i+j];
if((c < 0x20) || (c > 0x7F))
c = '.';
_putchar(c);
cnt_asc--;
}
else
{
sputs(" ");
break;
}
}
sputs("\n");
i += nbpr;
} while (cnt_hex);
}

Some files were not shown because too many files have changed in this diff Show More