Código:
//OUTPUT USB on GP32 SCREEN DEMO
//Based on.
// PandaForth by Torlus (c) 2005
// Some C functions for system-related stuff
// This code is based on Harry Denholm's GP32 USB code
// See the original copyright notice below
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2003 Harry Denholm http://www.ishani.plus.com
//
//
////////////////////////////////////////////////////////////////////////////////
#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpcomm.h"
#include "gpstdio.h"
#include "gpfont.h"
#include "USBDebugging.h"
#ifndef u8
#define u8 unsigned char
#endif
#ifndef u16
#define u16 unsigned short
#endif
#ifndef u32
#define u32 unsigned long
#endif
// Space reserved for PandaForth
u8 user_area[256*4];
// This stack is used by Forth and C, so it needs to be large enough
// I could have made these two stacks distinct...
u8 ps_area[1024*4];
u8 rs_area[256*4];
u8 holdpad_area[40+88];
// Memory Map Information needed by PandaForth
u8 *forthInfo[] = { ps_area+128, rs_area+128, user_area, holdpad_area+40 };
// PandaForth entry point function
extern void boot(u8 *forthInfo[]);
GPN_COMM usbCom;
char inbuf[256];
int inbufPos;
int inbufLen;
char buffer[256];
char buffern[8192];
char salida;
char outbuf[2];
int longitud;
void GpMain(void *arg)
{
GPDRAWSURFACE gpDraw;
// Create surface
GpLcdSurfaceGet(&gpDraw, 0);
// Clear surface to black
GpRectFill(NULL, &gpDraw, 0, 0, gpDraw.buf_w, gpDraw.buf_h, 0xff);
// Set gpDraw as primary surface
GpSurfaceSet(&gpDraw);
if ( !(GPC_LCD_ON_BIT & GpLcdStatusGet()) ) GpLcdEnable();
// Draw some text
GPRECT rect;
rect.left=0;
rect.top=0;
rect.right=320;
rect.bottom=240;
GpRectFill(NULL, &gpDraw, 0, 0, gpDraw.buf_w, gpDraw.buf_h, 0x00);
char *text = "";
//GpTextDraw (&gpDraw, &rect, 0, text, 0, strlen(text), 0xF8);
// Setup communications
USBDebuggingStart(&usbCom);
// Init input buffer
inbufLen=0;
inbufPos=0;
longitud = 0;
while(1) {
salida = service(6, 0xFF);
//en longitud tenemos la cuenta hasta 40 para ahi meter un word wrap
if(salida != 0) {
longitud += 1;
sprintf(buffer, "%c", salida);
sprintf(buffern, "%s%s", buffern, buffer);
if(longitud == 40) {
sprintf(buffern, "%s\n", buffern);
longitud = 0;
}
if(salida == 172) {
buffern = "";
}
GpRectFill(NULL, &gpDraw, 0, 0, gpDraw.buf_w, gpDraw.buf_h, 0x00);
GpTextDraw (&gpDraw, &rect, 0, buffern, 0, strlen(buffern), 0xF8);
}
}
// The following lines are never reached
// finish with usb comms
USBDebuggingStop();
// quit back to firmware!
GpAppExit();
}
// PandaForth service function
int service(int serv, int param) {
int ch;
if (serv == 6) {
if (param != 0xff) {
outbuf[0]=1;
outbuf[1]=param;
inbufLen += USBDebuggingSendText(&usbCom, outbuf, inbuf+inbufLen);
} else {
outbuf[0]=0;
inbufLen += USBDebuggingSendText(&usbCom, outbuf, inbuf+inbufLen);
ch = 0;
if (inbufPos < inbufLen) {
ch = inbuf[inbufPos++];
if (inbufPos == inbufLen) {
inbufPos=0;
inbufLen=0;
}
}
//if (ch == '\n') return 0;
//if (ch == '\t') return ' ';
return ch;
}
} else if (serv == 1) {
return 0;
}
return 0;
}
Eso se compila junto a los otros archivos que vienen en la carpeta Source del Pandaforth. Me voy ya, asi que una explicacion rapida:
Marcadores