Talk About Network

Google





Programming > Assembly Language > Re: I pee in th...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 42 of 65 Topic 5073 of 5194
Post > Topic >>

Re: I pee in the open

by Herbert Kleebauer <klee@[EMAIL PROTECTED] > Jul 28, 2008 at 09:27 PM

Herbert Kleebauer wrote:

> Ok, at least now I converted "Annie's flying hearts" as an example

Here the second example with a moveable window, mouse and keyboard input.
Again, for comments see the assembly source, hla.asm (NASM) or hla.mac
(Lindela).


Use mouse to convert any "HLA" to "asm", press "r" for reset and "ESC"
for exit.



/* gcc -O3 -o hla hla.c*/

#include <stdio.h>
#define abs(x) (((x) >=0) ? (x) : (- (x)))
void exit();
void x_send();
int  x_receive_raw();
int  x_receive();
void display();
void annie();
void init_color();

unsigned int eax, x_handle, id_next, id_incr;
int screen[320*200];
int color[64];
char brett[10][10];

#define BUF_SIZE 1024
char buf[BUF_SIZE]; int buf_rest=0; char* buf_ptr;
int mes_size; char *mes_ptr;

char fname[300];
char prot_name[256], prot_data[256]; int prot_name_size=0,
prot_data_size=0;
FILE *fp=NULL;

/**************************************************************************/
const char sockaddr_un[]=
 
{1,0,'/','t','m','p','/','.','X','1','1','-','u','n','i','x','/','X','0'};
/**************************************************************************/

/*************************  Connection Setup
******************************/
volatile struct {char a[2]; short b[2],s1n,s1d,c;} 
send1={0x6c,0,11,0,0,0,0};
/**************************************************************************/

/*************************  Create Window
*********************************/
volatile struct {char a[2]; short b; int s2a,s2b; short c[2],s2x,s2y,d[2];
                 int e[4];} 

send2={1,0,sizeof(send2)/4,0,0,0,0,400,400,0,0,0,0x802,0x8080ff,0x8005};
/**************************************************************************/

/*************************  Map Window 
***********************************/
volatile struct {char a[2]; short b; int s3a;} 
send3={8,0,sizeof(send3)/4,0};
/**************************************************************************/

/*************************  Open Font 
************************************/
volatile struct {char a[2]; short b; int s4c; short c[2];char d[18];
                 char e[2];}
send4={45,0,sizeof(send4)/4,0,18,0,'l','u','c','i','d','a',
       's','a','n','s','-','b','o','l','d','-','1','2',0,0};
/**************************************************************************/

/*************************  Create GC 
************************************/
volatile struct {char a[2]; short b; int s5b,s5a, c[4], s5c;}
send5={55,0,sizeof(send5)/4,0,0,1+4+8+0x4000,3,0xe02020,0x20e020,0};
/**************************************************************************/

/*************************  Change GC
*************************************/
volatile struct {char a[2]; short b; int s6b, c[3];} 
send6={56,0,sizeof(send6)/4,0,4+8,0x20e020,0xe02020};
/**************************************************************************/

/*************************  Change GC
*************************************/
volatile struct {char a[2]; short b; int s7b, c[3];} 
send7={56,0,sizeof(send7)/4,0,4+8,0xe02020,0x20e020};
/**************************************************************************/

/*************************  PolyFillArc
***********************************/
volatile struct {char a[2]; short b; int s8a,s8b; short s8x,s8y,c[4];}
send8={71,0,sizeof(send8)/4,0,0,0,0,50,50,0*64,360*64};
/**************************************************************************/

/*************************  ImageText8
************************************/
volatile struct {char a[2]; short b;int s9a,s9b;short s9x,s9y; char
s9t[3]; 
                 char d;}
send9={76,3,sizeof(send9)/4,0,0,0,30,'H','L','A',0};
/**************************************************************************/



/**************************************************************************/
/*************************  main 
*****************************************/
/**************************************************************************/

int main(nargs,args) int nargs; char **args;
{char *p, *q;
 int i,j,k,n=nargs+1;

/*************************  read .Xauthority 
*****************************/
 while ((p=args[n++]) != NULL)
  {if (*(int*)p != ('H'+('O'<<8) +('M'<<16) +('E'<<24)) ) continue;
   if (p[4] != '=' || p[5] == 0) continue;
   p=p+5; q=fname;
   for (i=0; i<256; i++) if ( (*q++ = *p++) == 0) break; 
   if (*(--q)) exit(0); 
   p="/.Xauthority"; while ((*q++ = *p++));
   fp=fopen(fname,"rb");
   break;
  }

 if (fp != NULL)
  {while ( (i=getc(fp),j=getc(fp)) != EOF) 
      {if ( ((j<<8)+i) != 1)  
        {for (k=0; k<4; k++)
          {i=getc(fp); i = (i<<8) + getc(fp);
           for (j=0; j<i; j++) if (getc(fp) == EOF) break;
          }
        } 
       else
        {for (k=0; k<2; k++)
          {i=getc(fp); i = (i<<8) + getc(fp);
           for (j=0; j<i; j++) if (getc(fp) == EOF) break;
          }
         i=getc(fp); prot_name_size = (i<<8) + getc(fp);
         if (prot_name_size > 256) exit(0); p=prot_name;
         for (i=0; i<prot_name_size; i++) *p++=getc(fp); 

         i=getc(fp); prot_data_size = (i<<8) + getc(fp);
         if (prot_data_size > 256) exit(0); p=prot_data;
         for (i=0; i<prot_data_size; i++) *p++=getc(fp); 
         break;  
        }
      }
   fclose(fp);
  }
/**************************************************************************/

/*************************  get socket handle 
****************************/
const int gsh[] = {1,1,0};
asm volatile ("int $0x80":"=a" (x_handle): "0" (102), "b" (1), "c"
(&gsh)); 
if (x_handle>=-4095) exit(0);
/**************************************************************************/

/*********************** connect socket to tmp/.X11-unix/X0
***************/
const int cst[]={x_handle, (int) &sockaddr_un,sizeof(sockaddr_un)};
/* with -O3 but without volatile, cst[1/2] is intialized after the int 80
*/
asm volatile ("int $0x80":"=a" (eax): "0" (102), "b" (3), "c" (&cst)); 
if (eax>=-4095) exit(0);
/**************************************************************************/

/***************************** send connect message 
**********************/
send1.s1n=prot_name_size;
send1.s1d=prot_data_size;

x_send((char*)&send1, sizeof(send1));
if (prot_name_size) x_send(prot_name,(prot_name_size+3)&0xfffffffc);
if (prot_data_size) x_send(prot_data,(prot_data_size+3)&0xfffffffc);

buf_ptr=buf; buf_rest=0;

n=8; 
for (k=0; k<2; k++)
 {while (buf_rest < n)
   {i=x_receive_raw(buf_ptr,BUF_SIZE-buf_rest);
    buf_rest += i; buf_ptr += i;
    if ( (buf_ptr != buf) && buf[0] != 1) exit(0);
   }
  n= 4 * (*(short*)(buf+6)) + 8;
 }

buf_ptr=buf; buf_rest=0;
/**************************************************************************/

/***************************** calculate id's 
****************************/
id_next = *(int*)(buf+12); n = *(int*)(buf+16);
id_incr = n & (-n);

send2.s2a=id_next; send3.s3a=id_next; send5.s5a=id_next;
send8.s8a=id_next; send9.s9a=id_next;

id_next += id_incr; 
send5.s5b=id_next; send6.s6b=id_next; send7.s7b=id_next;
send8.s8b=id_next; send9.s9b=id_next;

id_next += id_incr;
send4.s4c=id_next; send5.s5c=id_next;

id_next += id_incr;

/**************************************************************************/

/***************************** get root window id 
************************/
n = (((*(short*)(buf+24)) + 43) & -4) + ((*(unsigned char*)(buf+29)) *8);
send2.s2b = *(int*)(buf+n);
/**************************************************************************/

/***************************** send CreatWindow request
*******************/
x_send((char*)&send2, sizeof(send2));

/***************************** send MapWindow request
*********************/
x_send((char*)&send3, sizeof(send3));

/***************************** send OpenFont request
**********************/
x_send((char*)&send4, sizeof(send4));

/***************************** send CreatDC request
***********************/
x_send((char*)&send5, sizeof(send5));
/**************************************************************************/


/***************************** main loop 
*********************************/
display();
while (1)
 {
  if (x_receive() !=0 )
  switch (*mes_ptr)
    {case  0: exit(0);
     case  2: if (mes_ptr[1] == 0x1b) 
                {for (i=1; i<10; i++) for (j=1; j<10; j++) brett[i][j]=0;
                 display();
                }
              else if (mes_ptr[1] == 0x09) exit(0);
              
              break;
     case  4: i = 1+(((*(short*)(mes_ptr+26))/50)&0x07);
              j = 1+(((*(short*)(mes_ptr+24))/50)&0x07);
              brett[i  ][j  ] = !brett[i  ][j  ];
              brett[i-1][j  ] = !brett[i-1][j  ];
              brett[i+1][j  ] = !brett[i+1][j  ];
              brett[i  ][j-1] = !brett[i  ][j-1];
              brett[i  ][j+1] = !brett[i  ][j+1];
              display();
              break;

     case 12: display();
              break;
    }


 }
}
/**************************************************************************/
/**************************************************************************/
/**************************************************************************/

/***************************** display 
***********************************/
void display()
{int i,j;
 send8.s8y=0;
 for (i=1;i<9;i++)
  {send8.s8x=0;
   for (j=1;j<9;j++)
     {if (brett[i][j]) x_send((char*)&send8, sizeof(send8));
      send8.s8x += 50;
     }
   send8.s8y += 50;
  }

 x_send((char*)&send7, sizeof(send7));
 send9.s9t[0]='a'; send9.s9t[1]='s'; send9.s9t[2]='m';

 send8.s8y=0; send9.s9y=30;
 for (i=1;i<9;i++)
  {send8.s8x=0; send9.s9x=5;
   for (j=1;j<9;j++)
     {if (!brett[i][j]) x_send((char*)&send8, sizeof(send8));
      else              x_send((char*)&send9, sizeof(send9));
      send8.s8x += 50; send9.s9x += 50;
     }
   send8.s8y += 50; send9.s9y += 50;
  }

 x_send((char*)&send6, sizeof(send6));
 send9.s9t[0]='H'; send9.s9t[1]='L'; send9.s9t[2]='A';

 send9.s9y=30;
 for (i=1;i<9;i++)
  {send8.s8x=0; send9.s9x=5;
   for (j=1;j<9;j++)
     {if (!brett[i][j]) x_send((char*)&send9, sizeof(send9));
      send9.s9x += 50;
     }
   send9.s9y += 50;
  }


}
/**************************************************************************/

/******************** send message to X server
****************************/
void x_send(p,n) char *p; int n;
{while (n)
  {eax=-11;
   const int par[]={x_handle, (int)p, n, 0};
   while (eax == -11) 
     asm volatile ("int $0x80":"=a" (eax): "0" (102), "b" (9), "c"
(&par)); 
   if (eax>=-4095) exit(0);
   n -= eax; p += eax;
  }
}
/**************************************************************************/

/*********************** receive ONE message from X server 
***************/
int x_receive()
{int n;
 while (1)
  {if (buf_rest >= 32)
     {n=32;
      if (*buf_ptr == 1) n += (*(int*)(buf_ptr+4))*4;
      if (buf_rest >= n)
           {mes_ptr=buf_ptr; mes_size=n; 
            buf_ptr += n; buf_rest -= n; return 1;
           }
     }

   if (buf_ptr != buf )
    {for (n=0; n<buf_rest; n++) buf[n] = *buf_ptr++;
     buf_ptr=buf;
    }
   if ((n=x_receive_raw(buf+buf_rest,BUF_SIZE-buf_rest)) == 0) return 0;
   buf_rest += n;
  }
}
/**************************************************************************/

/************************ read data from X server 
************************/
int x_receive_raw(p,n) char *p; int n;
{const int par[]={x_handle, (int)p, n, 0};
 /* with -O3 but without "memory", modif. of buf[0] is not recognized !!!
*/
 asm volatile 
     ("int $0x80":"=a" (eax): "0" (102), "b" (10), "c" (&par):"memory"); 
 if (eax == -11) return 0;
 if (eax>=-4095) exit(0);
 if (eax == 0) exit(0);
 return eax;
}
/**************************************************************************/
 




 65 Posts in Topic:
I pee in the open
Evenbit <nbaker2328@[E  2008-07-09 16:53:06 
Re: popen
"Rod Pemberton"  2008-07-09 20:56:51 
Re: popen
Evenbit <nbaker2328@[E  2008-07-09 19:58:21 
Re: popen
"Rod Pemberton"  2008-07-11 02:52:12 
Re: popen
Frank Kotler <fbkotler  2008-07-13 00:30:59 
Re: popen
"Wolfgang Kern"  2008-07-13 12:26:35 
Re: I pee in the open
Frank Kotler <fbkotler  2008-07-10 02:28:37 
Re: popen
"Rod Pemberton"  2008-07-10 06:21:23 
Re: I pee in the open
dickey <dickey@[EMAIL   2008-07-10 12:28:50 
Re: I pee in the open
Evenbit <nbaker2328@[E  2008-07-10 22:40:17 
Re: popen
"Rod Pemberton"  2008-07-11 02:51:50 
Re: popen
"Wolfgang Kern"  2008-07-11 10:20:05 
Re: popen
Frank Kotler <fbkotler  2008-07-13 00:02:24 
Re: I pee in the open
Frank Kotler <fbkotler  2008-07-12 23:29:49 
Re: I pee in the open
Evenbit <nbaker2328@[E  2008-07-10 22:46:01 
Re: popen
Evenbit <nbaker2328@[E  2008-07-10 23:04:28 
Re: popen
"Rod Pemberton"  2008-07-11 02:52:30 
Re: I pee in the open
dickey <dickey@[EMAIL   2008-07-11 04:29:55 
Re: popen
Evenbit <nbaker2328@[E  2008-07-11 10:26:00 
Re: popen
"Rod Pemberton"  2008-07-12 04:30:09 
Re: I pee in the open
Evenbit <nbaker2328@[E  2008-07-11 11:07:14 
Re: popen
Evenbit <nbaker2328@[E  2008-07-11 22:50:36 
Re: popen
"Wolfgang Kern"  2008-07-12 10:12:07 
Re: popen
Evenbit <nbaker2328@[E  2008-07-11 23:40:34 
Re: popen
"Rod Pemberton"  2008-07-12 04:30:18 
Re: popen
Evenbit <nbaker2328@[E  2008-07-12 06:04:15 
Re: popen
"Rod Pemberton"  2008-07-12 12:17:53 
Re: I pee in the open
Robert Redelmeier <red  2008-07-12 14:38:08 
Re: popen
Evenbit <nbaker2328@[E  2008-07-12 17:23:12 
Re: I pee in the open
Evenbit <nbaker2328@[E  2008-07-12 17:50:34 
Re: I pee in the open
Robert Redelmeier <red  2008-07-13 15:28:01 
Re: I pee in the open
Evenbit <nbaker2328@[E  2008-07-12 23:18:34 
Re: I pee in the open
Robert Redelmeier <red  2008-07-13 15:43:23 
Re: I pee in the open
Herbert Kleebauer <kle  2008-07-13 10:55:11 
Re: I pee in the open
Frank Kotler <fbkotler  2008-07-13 11:13:18 
Re: I pee in the open
Herbert Kleebauer <kle  2008-07-13 23:14:26 
Re: I pee in the open
Frank Kotler <fbkotler  2008-07-14 16:58:07 
Re: I pee in the open
Herbert Kleebauer <kle  2008-07-15 03:26:44 
Re: I pee in the open
"Wolfgang Kern"  2008-07-15 11:14:58 
Re: I pee in the open
"rio" <a@[EM  2008-07-15 14:01:18 
Re: I pee in the open
Herbert Kleebauer <kle  2008-07-25 21:19:28 
Re: I pee in the open
Herbert Kleebauer <kle  2008-07-28 21:27:18 
Re: I pee in the open
Evenbit <nbaker2328@[E  2008-07-13 12:21:39 
Re: I pee in the open
Evenbit <nbaker2328@[E  2008-07-13 12:29:56 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-13 15:52:23 
Re: I pee in the open
"Rod Pemberton"  2008-07-14 03:57:23 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-14 13:52:24 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-14 14:18:56 
Re: I pee in the open
Evenbit <nbaker2328@[E  2008-07-15 15:59:33 
Re: I pee in the open
"Rod Pemberton"  2008-07-16 02:25:36 
Re: I pee in the open
Robert Redelmeier <red  2008-07-16 13:08:26 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-15 19:04:35 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-19 13:07:45 
Re: I pee in the open
"Rod Pemberton"  2008-07-19 18:50:56 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-19 20:00:51 
Re: I pee in the open
"Rod Pemberton"  2008-07-20 14:46:04 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-20 19:21:50 
Re: I pee in the open
"Rod Pemberton"  2008-07-21 04:18:17 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-20 21:06:28 
Re: I pee in the open
Robert Redelmeier <red  2008-07-22 23:18:19 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-21 13:19:49 
Re: I pee in the open
"Rod Pemberton"  2008-07-21 19:49:34 
Re: I pee in the open
"Rod Pemberton"  2008-07-22 17:53:28 
Re: I pee in the open
Chuck Crayne <ccrayne@  2008-07-21 20:53:52 
Re: I pee in the open
NathanCBaker@[EMAIL PROTE  2008-08-02 10:41:43 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
localhost-V2008-12-19 Wed Jan 7 17:21:29 PST 2009.