Article View: es.comp.os.linux.programacion
Article #15783Re: ECOLP crappy code competition?
From: Drizzt
Date: Sat, 03 Jun 2000 00:00
Date: Sat, 03 Jun 2000 00:00
265 lines
8301 bytes
8301 bytes
El d�a 3 Jun 2000 22:56:22 GMT, Drizzt dec�a:
Bueno, esto me lo he encontrodado buscando por mis viejos directorios. Supongo
que ser� en parte un fusile de alg�n c�digo que vi por ah� ( en especial el
de las X11, que creo que procede de una demo de la gente que hizo la rox). El
de la SVGALib creo que lo par� todo hace tiempo. Bueno, que lo disfruteis,
todo vuestro ( este c�digo es public domain ;) )
/*
* Esqueleto para aplicaciones X11
* Drizzt (terron@trajano.us.es )
*/
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctb.h>
#include <pcx.h>
static Display *display=NULL; /*puntero a la pantalla*/
static GC gc; /*contexto grafico de la pantalla*/
static int screen; /*pantalla*/
static int num_colors; /*profundidad de la pantalla*/
static int w_ancho=320;
static int w_alto=200;
static Window *win; /*puntero a la ventana*/
static XGCValues Values;
static XSetWindowAttributes W_Attribs;
static XImage *XImg; /*de momento esto*/
static BYTE *FrameBuffer;
static Colormap Cmap; /*este ser� nuestro mapa de colores*/
static XColor paleta[256];
static unsigned long colores[256];
#define MASKS StructureNotifyMask| ExposureMask \
| KeyReleaseMask | KeyPressMask \
| ButtonPressMask | ButtonReleaseMask \
| ButtonMotionMask | PointerMotionMask
int init_x11(void)
{
char *Name; /*nombre del display*/
XSizeHints Size_Hints;
int mascara_planos;
Name=XDisplayName(NULL);
if ((display=XOpenDisplay(Name))==NULL)
{
fprintf(stderr,"No puedo abrir la conexi�n a: %s\n",Name);
return(FALSE);
}
if ((FrameBuffer=malloc(w_ancho*w_alto))==NULL)
{
fprintf(stderr,"Alloc error\n");
return(FALSE);
}
screen=DefaultScreen(display);
num_colors=XDisplayCells(display,screen);
if (num_colors!=256)
{
fprintf(stderr,"Ops: Necesito un modo de 256 colores\n");
return(FALSE);
}
win = (Window*)XCreateSimpleWindow(
display, RootWindow( display, screen ),
0, 0, w_ancho, w_alto,
0, 0, 0 );
gc=XCreateGC(display,(Drawable)win,0,&Values);
/*esto debe crear el contexto de dispositivo*/
/*bueno ahora le decimos a nuestra ventana su tama�o*/
/* y que no se puede cambiar :)*/
Size_Hints.width = w_ancho;
Size_Hints.height = w_alto;
Size_Hints.min_width = Size_Hints.width;
Size_Hints.max_width = Size_Hints.width;
Size_Hints.min_height = Size_Hints.height;
Size_Hints.max_height = Size_Hints.height;
Size_Hints.flags = PSize | PMinSize | PMaxSize;
XSetWMNormalHints ( display,(Drawable) win, &Size_Hints );
/*esto no se que hace*/
W_Attribs.backing_store = Always;
XChangeWindowAttributes( display, (Drawable)win,
CWBackingStore, &( W_Attribs ) );
/*bueno ahora se pone en marchar el gestor de imagen*/
XImg=XCreateImage(display,
DefaultVisual(display,screen),
8,ZPixmap,0,FrameBuffer,
w_ancho,w_alto,
8,0);
if (XImg==NULL)
{
free(FrameBuffer);
XFreeGC(display,gc);
XDestroyWindow(display,(Drawable)win);
return(FALSE);
}
/*bien, ahora la paleta de colores*/
Cmap=XCreateColormap(display,
(Drawable)win,
DefaultVisual( display, screen ),
AllocNone );
if (!XAllocColorCells(display,Cmap,TRUE,&mascara_planos,0,colores,256))
{
fprintf(stderr,"Esto peta!!!!\n");
return(FALSE);
}
XStoreName( display, (Drawable)win, "Skel-Vga" );
XSelectInput( display, (Drawable)win, MASKS );
XMapWindow( display, (Drawable)win );
XFlush( display );
return(TRUE);
}
int dispose_x11(void)
{
XEvent Event;
while( XPending( display ) > 0 )
XNextEvent( display, &Event );
XDestroyImage(XImg);
XUnmapWindow( display, (Drawable)win );
XDestroyWindow( display,(Drawable) win );
XFreeGC( display, gc );
/*XDestroyImage tambien borra la memoria a la que apunta*/
// free(FrameBuffer);
}
int x11putimage(void)
{
XPutImage(display,(Drawable)win,gc,XImg,0,0,0,0,w_ancho,w_alto);
}
int x11palette(BYTE *pal)
{
int i;
XColor xc;
/*
for (i=0;i<256;i++)
{
fprintf(stderr,"Valor de colores[%d] %ld\n",i,colores[i]);
}
return;
*/
for (i=0;i<256;i++)
{
paleta[i].pixel = i;
paleta[i].red = pal[3*i]<<10;
paleta[i].green = pal[3*i+1]<<10;
paleta[i].blue = pal[3*i+2]<<10;
paleta[i].flags = DoBlue | DoGreen | DoRed;
XStoreColor(display,Cmap,&paleta[i]);
}
XInstallColormap(display,Cmap);
XSetWindowColormap(display,(Drawable)win,Cmap);
for (i=0;i<256;i++)
{
xc.pixel=i;
xc.flags= DoBlue|DoGreen|DoRed;
XQueryColor(display,Cmap,&xc);
fprintf(stderr,"Valor de Pixel:%d R:%d G:%d B:%d\n"
,xc.pixel,xc.red,xc.green,xc.blue);
}
}
void main(int argc,char **argv)
{
int fin=0;
LPBITMAP lp;
XEvent Event;
if (!init_x11())
{
fprintf(stderr,"Ops error arrancado X11\n");
exit(-1);
}
if ((lp=gloadpcx("portada.pcx"))==NULL)
{
fprintf(stderr,"No se ha podido cargar la imagen\n");
dispose_x11();
exit(-1);
}
memcpy(FrameBuffer,lp->pun,w_alto*w_ancho);
x11putimage();
x11palette(lp->pal);
while (!fin)
{
XNextEvent(display,&Event);
/*
fprintf(stderr,"Evento:%d\n",Event.type);
*/
if (Event.type==ButtonPress)
if (Event.xbutton.button==Button3)
{
dispose_x11();
fin=1;
}
}
}
El de la SVGALib
/*
* Rutinas esqueleto para uso de librerias bajo Linux
*/
#include <stdio.h>
#include <stdlib.h>
#include <vga.h>
#include <vgagl.h>
#include <ctb.h>
static BYTE *framebuffer;
__inline__ BYTE *get_framebuffer(void)
{
return(framebuffer);
}
GraphicsContext *init_vga(void)
{
GraphicsContext gc;
if (!vga_hasmode(G320x200x256))
return(NULL);
vga_setmode(G320x200x256);
gl_setcontextvga(G320x200x256);
gl_getcontext(&gc);
framebuffer=gc.vbuf; //el framebuffer
}
__inline__ void dispose_vga(void)
{
vga_setmode(TEXT);
}
__inline__ void set_color(BYTE *p,int first,int num)
{
gl_setpalettecolors(first,num,p);
}
/*bueno esta funci�n hace lo que dice, espera un retrazado de pantalla*/
inline void frame(void)
{
asm volatile (" movw $0x3da,%%dx\n\t"
" frame_1: inb %%dx,%%al \n\t"
" test $8,%%al \n\t"
" jnz frame_1 \n\t"
" frame_2: inb %%dx,%%al \n\t"
" test $8,%%al \n\t"
" jz frame_2\n\t"
:::"%eax");
}
--
____________________________________________________________________________
Drizzt Do'Urden Three rings for the Elves Kings under the Sky
drizzt.dourden@iname.com Seven for the Dwarf_lords in their
hall of stone
Nine for the Mortal Men doomed to die
Technical Details
Message-ID:
<slrn8jj3vq.13u.terron@menzoberrazan.dhis.org>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<slrn8i8ndi.pa.nop@compiler.linux.es> <slrn8ifuss.v6.nop_linux@compiler.linux.es> <slrn8iljjn.20h.gorka@conan.hondarribia.org> <slrn8ilpb9.5jh.gorka@conan.hondarribia.org> <slrn8iqpgf.t6.Ridiculum@localname.localdomain> <slrn8it0q5.opo.gorka@conan.hondarribia.org> <slrn8jhhb9.m8.compiler@compiler.linux.es> <slrn8jj38m.sg.terron@menzoberrazan.dhis.org>Show Full Headers
Complete Article Headers
X-Google-Language: PORTUGUESE,ASCII X-Google-Thread: f86c8,b330975e38ed05b0 X-Google-Attributes: gidf86c8,public From: terron@menzoberrazan.dhis.org (Drizzt) Subject: Re: ECOLP crappy code competition? Date: 2000/06/03 Message-ID: <slrn8jj3vq.13u.terron@menzoberrazan.dhis.org> X-Deja-AN: 631830411 Content-Transfer-Encoding: 8bit References: <slrn8i8ndi.pa.nop@compiler.linux.es> <slrn8ifuss.v6.nop_linux@compiler.linux.es> <slrn8iljjn.20h.gorka@conan.hondarribia.org> <slrn8ilpb9.5jh.gorka@conan.hondarribia.org> <slrn8iqpgf.t6.Ridiculum@localname.localdomain> <slrn8it0q5.opo.gorka@conan.hondarribia.org> <slrn8jhhb9.m8.compiler@compiler.linux.es> <slrn8jj38m.sg.terron@menzoberrazan.dhis.org> Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: news@cica.es X-Trace: mercurio.cica.es 960312977 5696 193.147.162.130 (6 Jun 2000 17:36:17 GMT) Organization: Menzoberrazan Tales er: terron User-Agent: slrn/0.9.5.7 (UNIX) Mime-Version: 1.0 Reply-To: e_mail_en_signature@menzoberrazan NNTP-Posting-Date: 6 Jun 2000 17:36:17 GMT Newsgroups: es.comp.os.linux.programacion