From: Herbert Kleebauer on
santosh wrote:

> > case 0x05: {la[--j] = la[j] / la[j+1]; break;}

Seems you are a SUN and not a PC:

> case 0x05:
> {
> la[j-1] = la[j] / la[j+1];
> j--;
> break;
> }

It was interned to be:

case 0x05: {j--; la[j] = la[j] / la[j+1]; break;}


> Sure, the the construct may work in a particular instance. But the crux of
> the matter is, by violating C's semantic rules, we are opening the door for
> unpredictable behaviour. Do we really want that, especially when the fix is
> trivial?

I call this a perfect copy protection for open source software.
From: Herbert Kleebauer on
Wolfgang Kern wrote:

> Perhaps you tell us about the used algo so we can read your binaries
> with our disassemblers in our familiar/prefered syntax.
> I think you once posted it anyway, but the many M$-forced crashes
> may have wiped it from my HDs.

I'm not sure about what you are speaking here. The posted code
is just an example which OS calls you need to put some pixels
on the screen or get mouse and keyboard events. If you mean
ASCII ANNIES code to generate hearts, then this is of no
interest here, I also could have displayed some predefined
picture instead.
From: Herbert Kleebauer on
Frank Kotler wrote:
> Rod Pemberton wrote:

> > Sorry, missed the self congratulatory remark, Frank! It appears that it's
> > your code... :-)
>
> Not really. I guess Herbert has gotten some ideas about "xauthority"
> from my code, since his machine doesn't require authorization, but he's

I also wanted a .Xauthority, so I bought a second Linspire PC, removed
Linspire Linux and installed DOS (a PC without real mode DOS isn't a real
PC), Win2k and UBUNTU Linux. They now sell this Linux PC's (with a 200 GByte
hard disk and DVD burner) for 120 EURO which is less than you have to pay
for Vista.

> cleaned it up and improved it considerably. Herbert was the one who came
> up with the *name* of the socket we're connecting to, which I wouldn't
> have found in a million years. He's been in the lead ever since. I've
> got "Nasm versions" of several of his demos, some of which do things
> differently - perhaps "better". I may have figured out some things that
> helped him, but this is *not* "my code". If it were, I wouldn't be
> having so much trouble "translating" it back to Nasm! :)

I have managed to create a Window (at a position where it shouldn't
have been), but then I gave up. It was you who proveded an example
with CreateDC and some graphics output and keyboard and mouse input
which then motivated me to do some more experiments. But without
your promoting Linux assembly programming I wouldn't even have
started to take a closer look.


Here the new version with messages split to 16k, in NASM and Lindela
source (now which one is beter readable):

assemble with nasm -f bin -o xdemo xdemo.asm

NASM source:

db 0x7f,0x45,0x4c,0x46,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00
db 0x00,0x00,0x02,0x00,0x03,0x00,0x01,0x00,0x00,0x00,0x74,0x80,0x04,0x08
db 0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x34,0x00
db 0x20,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00
db 0x00,0x00,0x00,0x00,0x00,0x80,0x04,0x08,0x00,0x80,0x04,0x08,0x64,0x05
db 0x00,0x00,0x64,0x05,0x00,0x00,0x05,0x00,0x00,0x00,0x00,0x10,0x00,0x00
db 0x01,0x00,0x00,0x00,0x64,0x05,0x00,0x00,0x64,0x95,0x04,0x08,0x64,0x95
db 0x04,0x08,0x88,0x00,0x00,0x00,0xb4,0xee,0x03,0x00,0x06,0x00,0x00,0x00
db 0x00,0x10,0x00,0x00,0x89,0x25,0xec,0x7d,0x08,0x08,0x6a,0x00,0x6a,0x01
db 0x6a,0x01,0x89,0xe1,0xbb,0x01,0x00,0x00,0x00,0xb8,0x66,0x00,0x00,0x00
db 0xcd,0x80,0x83,0xc4,0x0c,0x85,0xc0,0x0f,0x88,0xfd,0x01,0x00,0x00,0xa3
db 0xf0,0x7d,0x08,0x08,0x68,0x13,0x00,0x00,0x00,0x68,0x50,0x85,0x04,0x08
db 0xff,0x35,0xf0,0x7d,0x08,0x08,0x89,0xe1,0xbb,0x03,0x00,0x00,0x00,0xb8
db 0x66,0x00,0x00,0x00,0xcd,0x80,0x83,0xc4,0x0c,0x85,0xc0,0x0f,0x88,0xcf
db 0x01,0x00,0x00,0x8b,0x1d,0xf0,0x7d,0x08,0x08,0xb9,0x03,0x00,0x00,0x00
db 0xb8,0x37,0x00,0x00,0x00,0xcd,0x80,0x85,0xc0,0x0f,0x88,0xb5,0x01,0x00
db 0x00,0x8b,0x1d,0xf0,0x7d,0x08,0x08,0xb9,0x04,0x00,0x00,0x00,0x89,0xc2
db 0x81,0xca,0x00,0x08,0x00,0x00,0xb8,0x37,0x00,0x00,0x00,0xcd,0x80,0x85
db 0xc0,0x0f,0x88,0x93,0x01,0x00,0x00,0xb8,0x6c,0x95,0x04,0x08,0xba,0x0c
db 0x00,0x00,0x00,0xe8,0x55,0x02,0x00,0x00,0x0f,0x82,0x28,0x00,0x00,0x00
db 0x66,0x89,0x1d,0x72,0x95,0x04,0x08,0x66,0x89,0x35,0x74,0x95,0x04,0x08
db 0xe8,0x31,0x03,0x00,0x00,0x89,0xc8,0x8d,0x53,0x03,0x83,0xe2,0xfc,0xe8
db 0x24,0x03,0x00,0x00,0x89,0xe8,0x8d,0x56,0x03,0x83,0xe2,0xfc,0xe8,0x17
db 0x03,0x00,0x00,0x31,0xed,0xbe,0x18,0x80,0x08,0x08,0xbf,0x00,0x04,0x00
db 0x00,0x89,0xf0,0x89,0xfa,0xe8,0xc6,0x03,0x00,0x00,0x74,0xf5,0x80,0x3d
db 0x18,0x80,0x08,0x08,0x01,0x0f,0x85,0x2d,0x01,0x00,0x00,0x01,0xc5,0x01
db 0xc6,0x29,0xc7,0x81,0xfd,0x08,0x00,0x00,0x00,0x72,0xda,0x0f,0xb7,0x1d
db 0x1e,0x80,0x08,0x08,0x8d,0x1c,0x9d,0x08,0x00,0x00,0x00,0x39,0xdd,0x72
db 0xc8,0xbe,0x18,0x80,0x08,0x08,0x8b,0x46,0x0c,0x8b,0x56,0x10,0x89,0xd1
db 0xf7,0xd9,0x21,0xca,0xa3,0x7c,0x95,0x04,0x08,0xa3,0xa8,0x95,0x04,0x08
db 0xa3,0xb4,0x95,0x04,0x08,0xa3,0xcc,0x95,0x04,0x08,0xa3,0xe4,0x95,0x04
db 0x08,0x01,0xd0,0xa3,0xb0,0x95,0x04,0x08,0xa3,0xd0,0x95,0x04,0x08,0x01
db 0xd0,0x0f,0xb7,0x46,0x18,0x83,0xc0,0x2b,0x24,0xfc,0x0f,0xb6,0x56,0x1d
db 0xc1,0xe2,0x03,0x01,0xc2,0x8b,0x04,0x16,0xa3,0x80,0x95,0x04,0x08,0x8b
db 0x44,0x16,0x14,0xa3,0x88,0x95,0x04,0x08,0x2d,0x40,0x01,0xc8,0x00,0xd1
db 0xe8,0x25,0xff,0x7f,0xff,0xff,0xa3,0xd8,0x95,0x04,0x08,0xb8,0x78,0x95
db 0x04,0x08,0xba,0x2c,0x00,0x00,0x00,0xe8,0x58,0x02,0x00,0x00,0xe8,0x8d
db 0x02,0x00,0x00,0x74,0x09,0x80,0x38,0x00,0x0f,0x84,0x82,0x00,0x00,0x00
db 0xb8,0xa4,0x95,0x04,0x08,0xba,0x08,0x00,0x00,0x00,0xe8,0x39,0x02,0x00
db 0x00,0xe8,0x6e,0x02,0x00,0x00,0x74,0x09,0x80,0x38,0x00,0x0f,0x84,0x63
db 0x00,0x00,0x00,0xb8,0xac,0x95,0x04,0x08,0xba,0x1c,0x00,0x00,0x00,0xe8
db 0x1a,0x02,0x00,0x00,0xe8,0x4f,0x02,0x00,0x00,0x74,0x09,0x80,0x38,0x00
db 0x0f,0x84,0x44,0x00,0x00,0x00,0xb8,0xe0,0x95,0x04,0x08,0xba,0x0c,0x00
db 0x00,0x00,0xe8,0xfb,0x01,0x00,0x00,0xe8,0x30,0x02,0x00,0x00,0x74,0x09
db 0x80,0x38,0x00,0x0f,0x84,0x25,0x00,0x00,0x00,0xe8,0xcc,0x00,0x00,0x00
db 0xe8,0x67,0x00,0x00,0x00,0xe8,0x22,0x00,0x00,0x00,0xe8,0x11,0x02,0x00
db 0x00,0x74,0xef,0x80,0x38,0x00,0x74,0x0a,0x80,0x38,0x02,0x74,0x05,0x80
db 0x38,0x04,0x75,0xe0,0xbb,0x00,0x00,0x00,0x00,0xb8,0x01,0x00,0x00,0x00
db 0xcd,0x80,0xbe,0xec,0x95,0x04,0x08,0xb9,0x14,0x00,0x00,0x00,0xb8,0xc8
db 0x95,0x04,0x08,0xba,0x18,0x00,0x00,0x00,0xe8,0xa1,0x01,0x00,0x00,0x89
db 0xf0,0xba,0x00,0x32,0x00,0x00,0xe8,0x95,0x01,0x00,0x00,0x66,0x81,0x05
db 0xda,0x95,0x04,0x08,0x0a,0x00,0x81,0xc6,0x00,0x32,0x00,0x00,0xe2,0xd4
db 0x66,0x81,0x2d,0xda,0x95,0x04,0x08,0xc8,0x00,0xc3,0x60,0x31,0xdb,0xff
db 0x05,0xf4,0x7d,0x08,0x08,0xb9,0x00,0xfa,0x00,0x00,0x31,0xff,0x89,0xf8
db 0x31,0xd2,0xbb,0x40,0x01,0x00,0x00,0xf7,0xf3,0x2d,0x78,0x00,0x00,0x00
db 0x81,0xea,0xa0,0x00,0x00,0x00,0x7f,0x02,0xf7,0xda,0x89,0xc3,0x0f,0xaf
db 0xdb,0x01,0xd0,0xf7,0xe8,0x01,0xc3,0x74,0x09,0x31,0xd2,0xb8,0xc0,0x27
db 0x09,0x00,0xf7,0xf3,0x03,0x05,0xf4,0x7d,0x08,0x08,0xc0,0xe8,0x02,0x0f
db 0xb6,0xc0,0x8b,0x04,0x85,0xf8,0x7d,0x08,0x08,0x89,0x04,0xbd,0xec,0x95
db 0x04,0x08,0x47,0xe2,0xb3,0x61,0x90,0xc3,0x60,0xbe,0xf8,0x7d,0x08,0x08
db 0xb8,0x00,0x00,0x00,0x00,0xb9,0x40,0x00,0x00,0x00,0x89,0x06,0x83,0xc6
db 0x04,0x04,0x10,0x66,0x05,0x00,0x08,0x05,0x00,0x00,0x04,0x00,0xe2,0xee
db 0x61,0x90,0xc3,0x50,0x52,0x57,0x8b,0x3d,0xec,0x7d,0x08,0x08,0x8b,0x07
db 0x8d,0x7c,0x87,0x08,0x8b,0x37,0x83,0xc7,0x04,0x85,0xf6,0x0f,0x84,0xaa
db 0x00,0x00,0x00,0x81,0x3e,0x48,0x4f,0x4d,0x45,0x75,0xeb,0x80,0x7e,0x04
db 0x3d,0x75,0xe5,0x83,0xc6,0x05,0x83,0xc9,0xff,0x41,0x80,0x3c,0x0e,0x00
db 0x75,0xf9,0x09,0xc9,0x0f,0x84,0x87,0x00,0x00,0x00,0x81,0xf9,0x00,0x01
db 0x00,0x00,0x0f,0x87,0x7b,0x00,0x00,0x00,0xbf,0xf8,0x7e,0x08,0x08,0xf3
db 0xa4,0xb8,0x2f,0x2e,0x58,0x61,0xab,0xb8,0x75,0x74,0x68,0x6f,0xab,0xb8
db 0x72,0x69,0x74,0x79,0xab,0xc6,0x07,0x00,0xbb,0xf8,0x7e,0x08,0x08,0x31
db 0xc9,0xb8,0x05,0x00,0x00,0x00,0xcd,0x80,0x85,0xc0,0x78,0x4d,0x89,0xc3
db 0xb9,0x18,0x80,0x08,0x08,0xba,0x00,0x04,0x00,0x00,0xb8,0x03,0x00,0x00
db 0x00,0xcd,0x80,0x3d,0x00,0x04,0x00,0x00,0x0f,0x83,0x98,0xfe,0xff,0xff
db 0x89,0xc5,0xb8,0x06,0x00,0x00,0x00,0xcd,0x80,0x85,0xed,0x74,0x22,0xbe
db 0x18,0x80,0x08,0x08,0x01,0xf5,0x31,0xc0,0x66,0xad,0x66,0x48,0x74,0x16
db 0xb9,0x04,0x00,0x00,0x00,0x66,0xad,0x66,0xc1,0xc8,0x08,0x01,0xc6,0xe2
db 0xf6,0x39,0xee,0x72,0xe7,0xf9,0xeb,0x28,0xb9,0x02,0x00,0x00,0x00,0x89
db 0xcb,0x66,0xad,0x66,0xc1,0xc8,0x08,0x01,0xc6,0xe2,0xf6,0x66,0xad,0x66
db 0xc1,0xc8,0x08,0x89,0xf1,0x89,0xc3,0x01,0xde,0x66,0xad,0x66,0xc1,0xc8
db 0x08,0x89,0xf5,0x89,0xc6,0xf8,0x5f,0x5a,0x58,0xc3,0x60,0x89,0xc5,0x89
db 0xd6,0x6a,0x00,0x56,0x55,0xff,0x35,0xf0,0x7d,0x08,0x08,0x89,0xe1,0xbb
db 0x09,0x00,0x00,0x00,0xb8,0x66,0x00,0x00,0x00,0xcd,0x80,0x83,0xc4,0x10
db 0x3d,0xf5,0xff,0xff,0xff,0x74,0xde,0x85,0xc0,0x0f,0x88,0x0b,0xfe,0xff
db 0xff,0x29,0xc6,0x74,0x04,0x01,0xc5,0xeb,0xce,0x61,0x90,0xc3,0x51,0x56
db 0x57,0xa1,0x68,0x95,0x04,0x08,0x3d,0x20,0x00,0x00,0x00,0x73,0x3b,0x8b
db 0x35,0x64,0x95,0x04,0x08,0xbf,0x18,0x80,0x08,0x08,0x89,0x3d,0x64,0x95
db 0x04,0x08,0x39,0xf7,0x74,0x08,0x09,0xc0,0x74,0x04,0x89,0xc1,0xf3,0xa4
db 0xba,0x00,0x04,0x00,0x00,0x29,0xc2,0x8d,0x80,0x18,0x80,0x08,0x08,0xe8
db 0x4c,0x00,0x00,0x00,0x75,0x02,0xeb,0x44,0x01,0x05,0x68,0x95,0x04,0x08
db 0xeb,0xb9,0x8b,0x35,0x64,0x95,0x04,0x08,0x80,0x3e,0x22,0x0f,0x87,0xa7
db 0xfd,0xff,0xff,0xba,0x20,0x00,0x00,0x00,0x80,0x3e,0x00,0x74,0x15,0x80
db 0x3e,0x01,0x75,0x10,0x03,0x56,0x0c,0x03,0x56,0x0c,0x03,0x56,0x0c,0x03
db 0x56,0x0c,0x39,0xd0,0x72,0x97,0x89,0xf0,0x29,0x15,0x68,0x95,0x04,0x08
db 0x01,0x15,0x64,0x95,0x04,0x08,0x5f,0x5e,0x59,0xc3,0x51,0x53,0x6a,0x00
db 0x52,0x50,0xff,0x35,0xf0,0x7d,0x08,0x08,0x89,0xe1,0xbb,0x0a,0x00,0x00
db 0x00,0xb8,0x66,0x00,0x00,0x00,0xcd,0x80,0x83,0xc4,0x10,0x5b,0x59,0x3d
db 0xf5,0xff,0xff,0xff,0x74,0x08,0x85,0xc0,0x0f,0x88,0x48,0xfd,0xff,0xff
db 0xc3,0x00,0x01,0x00,0x2f,0x74,0x6d,0x70,0x2f,0x2e,0x58,0x31,0x31,0x2d
db 0x75,0x6e,0x69,0x78,0x2f,0x58,0x30,0x00,0x18,0x80,0x08,0x08,0x00,0x00
db 0x00,0x00,0x6c,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
db 0x01,0x00,0x0b,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
db 0x00,0x00,0x80,0x02,0x90,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
db 0x02,0x0a,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x05,0x00
db 0x00,0x00,0x08,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x37,0x00,0x07,0x00
db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0d,0x00,0x00,0x00,0x03,0x00
db 0x00,0x00,0xff,0xff,0xff,0x00,0xff,0x80,0x00,0x00,0x48,0x02,0x86,0x0c
db 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x01,0x0a,0x00,0x00,0x00
db 0x00,0x00,0x00,0x18,0x00,0x00,0x2a,0x00,0x03,0x00,0x00,0x00,0x00,0x00
db 0x00,0x00,0x00,0x00


Lindela source:

;===========================================================================
seg32
@=$08048000
code_offset=@@
code_addr:

;--------------------------- ELF header -----------------------------------
dc.l $464c457f,$00010101,0,0,$00030002,1,main,$34,0,0,$00200034,2,0
dc.l 1,code_offset,code_addr,code_addr,code_filez,code_memsz,5,4096
dc.l 1,data_offset,data_addr,data_addr,data_filez,data_memsz,6,4096

;--------------------------- code ------------------------------------------

main: move.l r7,stack_ptr ; save initial stack pointer


; ******************** get socket handle ***************************
moveq.l #0,-(sp) ; no protocol specified
moveq.l #1,-(sp) ; 1: SOCK_STREAM (/usr/include/linux/net.h)
moveq.l #1,-(sp) ; 1: AF_UNIX, AF_LOCAL (/usr/include/linux/socket.h)
move.l r7,r2 ; pointer to parameter for "socket"
move.l #1,r3 ; "socket" (/usr/include/linux/net.h)
move.l #102,r0 ; socketcall (/usr/include/asm/unistd.h)
trap #$80
addq.l #3*4,r7 ; free space for parameters
tst.l r0,r0 ; ERROR
bmi.l err
move.l r0,x_handle


; ********** connect socket to /tmp/.X11-unix/X0" ******************
move.l #sockaddr_un_l,-(sp)
move.l #sockaddr_un,-(sp) ; (/usr/include/linux/un.h)
move.l x_handle,-(sp) ; socket handle
move.l r7,r2 ; pointer to parameter for "connect"
move.l #3,r3 ; "connect" (/usr/include/linux/net.h)
move.l #102,r0 ; socketcall (/usr/include/asm/unistd.h)
trap #$80
addq.l #3*4,r7 ; free space for parameters
tst.l r0,r0 ; ERROR
bmi.l err


; *************** make socket read non blocking *******************
move.l x_handle,r3 ; socket handle
move.l #3,r2 ; F_GETFL (/usr/include/asm/fcntl.h)
move.l #55,r0 ; fcntl (/usr/include/asm/unistd.h)
trap #$80
tst.l r0,r0 ; ERROR
bmi.l err
move.l x_handle,r3 ; socket handle
move.l #4,r2 ; F_SETFL (/usr/include/asm/fcntl.h)
move.l r0,r1
or.l #$800,r1 ; O_NONBLOCK (/usr/include/asm/fcntl.h)
move.l #55,r0 ; fcntl (/usr/include/asm/unistd.h)
trap #$80
tst.l r0,r0 ; ERROR
bmi.l err


; ******************* send connect message *************************
move.l #send1,r0 ; pointer to connect message
move.l #send1l,r1

bsr.l get_xauth ; try to read .Xauthority
bcs.l _11 ; no success, let's try without auth.

move.w r3,send1+6 ; insert name length
move.w r5,send1+8 ; insert data length

bsr.l x_send ; send header

move.l r2,r0 ; pointer to name
lea.l 3.b(r3),r1 ; pad to a multiple of 4
andq.l #$fffffffc,r1
bsr.l x_send ; send name

move.l r4,r0 ; pointer to data
lea.l 3.b(r5),r1 ; pad to a multiple of 4
andq.l #$fffffffc,r1
_11: bsr.l x_send ; send data

eor.l r4,r4 ; number of total bytes read
move.l #buf2,r5 ; pointer to buffer for next read
move.l #buf2l,r6 ; max. bytes to read

_10: move.l r5,r0
move.l r6,r1
bsr.l x_receive_raw
beq.b _10 ; but we need a reply

cmp.b #1,buf2 ; success
bne.l err ; something went wrong

add.l r0,r4 ; total read bytes
add.l r0,r5 ; pointer to buffer for next read
sub.l r0,r6 ; max. bytes to read
cmp.l #8,r4 ; at least 8 bytes read?
blo.b _10 ; no, get more

movu.wl buf2+6,r3 ; additional data in 4 bytes
lea.l 8(r3*4),r3 ; total size in bytes
cmp.l r3,r4 ; all read
blo.b _10 ; no, get more


; ******************* calculate id's *******************************
move.l #buf2,r5
move.l $0c.b(r5),r0 ; resource_id_base

move.l $10.b(r5),r1 ; resource_id_mask
move.l r1,r2
neg.l r2
and.l r2,r1 ; resource_id_incr

move.l r0,s2a ; wid for CreateWindow
move.l r0,s3a ; wid for MapWindow
move.l r0,s4a ; wid for CreateDC
move.l r0,s5a ; wid for CreateDC
move.l r0,s6a ; wid for SetInputFocus

add.l r1,r0 ; next id
move.l r0,s4b ; cid for CreateDC
move.l r0,s5b ; cid for CreateDC

add.l r1,r0 ; next id

; move.l r0,resource_id_next
; move.l r1,resource_id_incr


; ******************* get root window id ***************************
movu.wl $18.b(r5),r0 ; length of vendor string
addq.l #$28+3,r0 ; const header length + round vendor length
and.b #$fc,r0 ; round to 4 bytes

movu.bl $1d.b(r5),r1 ; number of FORMATs
lsl.l #3,r1 ; 8 byte for each FORMAT entry
add.l r0,r1 ; offset to root WINDOW id

move.l (r5,r1),r0 ; root window
move.l r0,s2b ; CreateWindow needs root window id

move.l 20.b(r5,r1),r0 ; width/hight of root window
move.l r0,s2x ; create window full size

sub.l #(200<<16)+320,r0
lsr.l #1,r0
and.l #$ffff7fff,r0
move.l r0,s5x ; center drawing


; ******************* send CreatWindow request *********************
move.l #send2,r0
move.l #send2l,r1
bsr.l x_send
bsr.l x_receive
beq.b _20 ; no message is a good message
cmp.b #0,(r0) ; error message
beq.l ende


; ******************* send MapWindow request ***********************
_20: move.l #send3,r0
move.l #send3l,r1
bsr.l x_send
bsr.l x_receive
beq.b _30 ; no message is a good message
cmp.b #0,(r0) ; error message
beq.l ende


; ******************* send CreatDC request *************************
_30: move.l #send4,r0
move.l #send4l,r1
bsr.l x_send
bsr.l x_receive
beq.b _40 ; no message is a good message
cmp.b #0,(r0) ; error message
beq.l ende


; ******************* send SetInputFocust *************************
_40: move.l #send6,r0
move.l #send6l,r1
bsr.l x_send
bsr.l x_receive
beq.b _60 ; no message is a good message
cmp.b #0,(r0) ; error message
beq.l ende


_60: bsr.l init_color ; init 64 VGA colors

; ******************** main loop ***************************
_50: bsr.l annie ; generate next picture
bsr.l display
bsr.l x_receive
beq.b _50 ; no message is a good message

cmp.b #0,(r0) ; error message
beq.b err
cmp.b #2,(r0) ; key press
beq.b ende
cmp.b #4,(r0) ; button press
bne.b _50
err:
ende: move.l #0,r3 ; return code
move.l #1,r0 ; exit
trap #$80

display:move.l #screen,r5
move.l #20,r2 ; we use 20 parts to make each <16k
_10: move.l #send5,r0
move.l #send5l,r1
bsr.l x_send ; send header
move.l r5,r0
move.l #320*10*4,r1 ; size of one part
bsr.l x_send ; send data
add.w #10,s5y ; update y pos for next part
add.l #320*10*4,r5 ; update source pointer for next part
dbf.l r2,_10
sub.w #20*10,s5y ; restore original y position
rts.l

; ********* Annie's code to draw a heart ****************
annie: movem.l r0-r7,-(sp)
eor.l r3,r3

_10: inc.l annie1
move.l #320*200,r2
eor.l r6,r6
_20: move.l r6,r0 ; byte pos in screen
eor.l r1,r1
move.l #320,r3 ; 320 lines
divu.l r3,r1|r0 ; r0: line 0-199 r1: column 0-319
sub.l #120,r0 ; center y=120 (-120 .. +79)
sub.l #160,r1 ; x=160 (-160 .. +159)
bgt.b _30
neg.l r1 ; symmetric in x (0 .. 160)
_30: move.l r0,r3
muls.l r3,r3,r3 ; r3 = x*x
add.l r1,r0 ; r0 = x*x+y
muls.l r0,r0,r1|r0 ; r0 = (x*x+y)**2 mod 2*16
add.l r0,r3
beq.b _40
eor.l r1,r1
move.l #600000,r0
divu.l r3,r1|r0
_40: add.l annie1,r0 ; change color
lsr.b #2,r0
movu.bl r0,r0
move.l color(r0*4),r0
move.l r0,screen(r6*4)
inc.l r6
dbf.l r2,_20

movem.l (sp)+,r0-r7
rts.l

; ****************** initialize 64 VGA colors *********************
init_color:
movem.l r0-r7,-(sp)
move.l #color,r5
move.l #0,r0
move.l #64,r2
_01: move.l r0,(r5)
addq.l #4,r5
add.b #$10,r0
add.w #$000800,r0
add.l #$040000,r0
dbf.l r2,_01
movem.l (sp)+,r0-r7
rts.l

;**********************************************************
;******** read cookie from $home/.Xauthority **************
;**********************************************************
; *
; input: stack_ptr: original sp at program start *
; output: C=0: cookie found in $home/.Xauthority *
; r2: pointer to protocol name *
; r3: length of protocol name *
; r4: pointer to protocol data *
; r5: length of protocol data *
; C=1: nothing found *
; r2/r3/r4/r5 undefined *
; *
; typedef struct xauth { *
; unsigned short family; *
; unsigned short address_length; *
; char *address; *
; unsigned short number_length; *
; char *number; *
; unsigned short name_length; *
; char *name; *
; unsigned short data_length; *
; char *data; *
; } Xauth; *
;**********************************************************

get_xauth:
move.l r0,-(sp)
move.l r1,-(sp)
move.l r6,-(sp)

move.l stack_ptr,r6 ; original stack pointer at program start
move.l (r6),r0 ; number of arguments
lea.l 8.b(r6,r0*4),r6 ; skip arguments + trailing null pointer

_20: move.l (r6),r5 ; pointer to next env variable
addq.l #4,r6
tst.l r5,r5 ; no more env variables
beq.l _notfound
cmp.l #'EMOH',(r5) ; HOME found?
bne.b _20 ; no, try next
cmp.b #'=',4.b(r5) ; HOME= found?
bne.b _20 ; no, try next
addq.l #5,r5 ; start of HOME path
orq.l #-1,r2
_30: inc.l r2 ; count length of HOME path
cmp.b #0,(r5,r2)
bne.b _30

or.l r2,r2 ; at least one char long?
beq.l _notfound ; no, HOME is empty
cmp.l #256,r2 ; more than 256 charcters
bhi.l _notfound ; somebody tries a buffer overflow
move.l #fname,r6 ; buffer for filename
rep_r2 move.b (r5)+-,(r6)+-{s1} ; copy HOME path
move.l #'aX./',r0 ; add .Xauthority
move.l r0,(r6)+-{s1}
move.l #'ohtu',r0
move.l r0,(r6)+-{s1}
move.l #'ytir',r0
move.l r0,(r6)+-{s1}
move.b #0,(r6) ; and a trailing 0

move.l #fname,r3
eor.l r2,r2 ; readonly
move.l #5,r0 ; open
trap #$80


tst.l r0,r0 ; file open error?
bmi.b _notfound ; yes

move.l r0,r3 ; file handle
move.l #buf2,r2
move.l #buf2l,r1 ; read 1024 byte
move.l #3,r0 ; read
trap #$80

cmp.l #buf2l,r0
bhs.l err ; .Xauthority >= 1024 byte
move.l r0,r4 ; bytes read

move.l #6,r0 ; close
trap #$80

tst.l r4,r4 ; file empty
beq.b _notfound


move.l #buf2,r5
add.l r5,r4 ; end of read data
eor.l r0,r0 ; delete upper 16 bit of r0

_60: move.w (r5)+-,r0 ; family
dec.w r0
beq.b _40 ; 1=FamilyLocal

move.l #4,r2 ; skip entry
_50: move.w (r5)+-,r0
ror.w #8,r0 ; big -> little endian
add.l r0,r5
dbf.l r2,_50
cmp.l r4,r5 ; more data
blo.b _60 ; try next entry

_notfound:
bset.w #0,sr ; set Carry
br.b _70

_40: move.l #2,r2
move.l r2,r3
_41: move.w (r5)+-,r0 ; size of data
ror.w #8,r0 ; big endian <-> little endian
add.l r0,r5 ; skip address/number
dbf.l r2,_41

_42: move.w (r5)+-,r0 ; size of protocol name
ror.w #8,r0 ; big endian <-> little endian
move.l r5,r2 ; pointer to protocol name
move.l r0,r3 ; size of protocol name
add.l r3,r5 ; skip name

move.w (r5)+-,r0 ; size of protocol data
ror.w #8,r0 ; big endian <-> little endian
move.l r5,r4 ; pointer to protocol data
move.l r0,r5 ; size of protocol data
bclr.w #0,sr ; clear carry
_70: move.l (sp)+,r6
move.l (sp)+,r1
move.l (sp)+,r0
rts.l


;**********************************************************
;******** send message to X server **************
;**********************************************************
; input: r0: pointer to message *
; r1: length of message *
;**********************************************************
x_send: movem.l r0-r7,-(sp)
move.l r0,r4 ; pointer to next byte of message
move.l r1,r5 ; remaining bytes to send

_20: moveq.l #0,-(sp) ; flags
move.l r5,-(sp) ; length
move.l r4,-(sp) ; pointer to data
move.l x_handle,-(sp) ; socket handle
move.l r7,r2 ; pointer to parameter for "send"
move.l #9,r3 ; "send" (/usr/include/linux/net.h)
move.l #102,r0 ; socketcall (/usr/include/asm/unistd.h)
trap #$80
addq.l #4*4,r7 ; free space for parameters

cmp.l #-11,r0 ; EAGAIN:
beq.b _20 ; message couldn't be sent, try again

tst.l r0,r0 ; ERROR
bmi.l err

sub.l r0,r5 ; remaining bytes to send
beq.b _30 ; nothing, all sent
add.l r0,r4 ; pointer to remaining message
br.b _20 ; send rest of message

_30: movem.l (sp)+,r0-r7
rts.l


;**********************************************************
;******** receive ONE message from X server **********
;**********************************************************
; input: none *
; output: Z=1: no complete message available *
; r0/r1 undefined *
; Z=0: r0: pointer to message data *
; r1: size of data *
;**********************************************************
x_receive:
move.l r2,-(sp)
move.l r5,-(sp)
move.l r6,-(sp)
_00: move.l buf2_rest,r0 ; still something in read buffer?
cmp.l #32,r0 ; a message has at least 32 bytes
bhs.b _10 ; maybe it is a complete message

_30: move.l buf2_ptr,r5 ; start of message
move.l #buf2,r6 ; start of buffer
move.l r6,buf2_ptr ; we copy message to top of buffer
cmp.l r5,r6 ; already at top of buffer
beq.b _50 ; then nothing to copy
or.l r0,r0 ; nothing in buffer
beq.b _50 ; then also nothing to copy
move.l r0,r2 ; copy to top of buffer
rep_r2 move.b (r5)+-,(r6)+-{s1}

_50: move.l #buf2l,r1 ; let's try to get some more data
sub.l r0,r1 ; not more bytes than space is left in the buf
lea.l buf2(r0),r0 ; append it here
bsr.l x_receive_raw
bne.b _20 ; we could read something
br.b _100 ; return with Z=1

_20: add.l r0,buf2_rest ; now we have a few more bytes in the buffer
br.b _00 ; let's try again

_10: move.l buf2_ptr,r5 ; let's test if it is a complete meesage
cmp.b #34,(r5)
bhi.l err ; the last known message is nr 34
move.l #32,r1 ; error/reply/event base length
cmp.b #0,(r5) ; error message
beq.b _40 ; error messages are always 32 byte
cmp.b #1,(r5) ; reply message
bne.b _40 ; no, then event messages (always 32 byte)
add.l 12.b(r5),r1 ; + additional data for reply
add.l 12.b(r5),r1 ; + additional data for reply
add.l 12.b(r5),r1 ; + additional data for reply
add.l 12.b(r5),r1 ; + additional data for reply
cmp.l r1,r0 ; complete reply in buffer
blo.b _30 ; no, let's try to get more
_40: move.l r5,r0 ; pointer to data
sub.l r1,buf2_rest ; new rest
add.l r1,buf2_ptr ; pointer to next data; clear Z flag
_100: move.l (sp)+,r6
move.l (sp)+,r5
move.l (sp)+,r2
rts.l

;**********************************************************
;******** read data from X server **********
;**********************************************************
; input: r0: pointer to read buffer *
; r1: size of buffer *
; output: Z=1: nothing to read *
; Z=0: r0 bytes read *
;**********************************************************
x_receive_raw:
move.l r2,-(sp)
move.l r3,-(sp)

moveq.l #0,-(sp) ; flags
move.l r1,-(sp) ; number of bytes to read
move.l r0,-(sp) ; pointer to buffer
move.l x_handle,-(sp) ; socket handle
move.l r7,r2 ; pointer to parameter for "recv"
move.l #10,r3 ; "recv" (/usr/include/linux/net.h)
move.l #102,r0 ; socketcall (/usr/include/asm/unistd.h)
trap #$80
addq.l #4*4,r7 ; free space for parameters
move.l (sp)+,r3
move.l (sp)+,r2
cmp.l #-11,r0 ; EAGAIN: no message available -> Z=1
beq.b _10
tst.l r0,r0 ; <0: ERROR 0: NULL message -> Z=1
bmi.l err
_10: rts.l




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;--------------------------- constant data ---------------------------------
even 4

sockaddr_un:
dc.w 1 ; 1: AF_UNIX, AF_LOCAL (/usr/include/linux/socket.h)
dc.b "/tmp/.X11-unix/X0"
sockaddr_un_l= @-sockaddr_un
even 4

;---------------------------------------------------------------------------

code_filez=@@-code_offset
code_memsz= @-code_addr
even 4
@=(@+4095)/4096*4096+(@@\4096)
data_offset=@@
data_addr:

;--------------------------- initialized data ------------------------------
buf2_ptr: dc.l buf2
buf2_rest: dc.l 0

; Connection Setup
send1: dc.b $6c,0 ; LSB first
dc.w 11,0 ; major/minor version
dc.w 0,0 ; length of protocol name/data
dc.w 0 ; unused
send1l=@-send1

; Create Window
send2: dc.b 1 ; opcode for Create Window
dc.b 0 ; depth from parent
dc.w send2l/4; request length
s2a: dc.l 0 ; wid (has to be calculated)
s2b: dc.l 0 ; parent (has to be calculated)
dc.w 0 ; x
dc.w 0 ; y
s2x: dc.w 640 ; with
s2y: dc.w 400 ; higth
dc.w 0 ; border-width
dc.w 0 ; class: CopyFromParent
dc.l 0 ; visual: CopyFromParent
dc.l $a02 ; value-mask: background-pixel 2
; + override-redirect 200
; + event-mask 800
dc.l $000000 ; background: black
dc.b 1 ; override-redirect = true
dc.b 0,0,0 ; pad
dc.l $05 ; event_mask: KeyPress 1
; +ButtenPress 4
; +PointerMotion 40
send2l=((@-send2)+3) & $fffffffc

; Map Window
send3: dc.b 8 ; opcode for Map Window
dc.b 0 ; unused
dc.w send3l/4; request length
s3a: dc.l 0 ; wid (has to be calculated)
send3l=@-send3


; Create GC
send4: dc.b 55 ; opcode for CreateGC
dc.b 0 ; unused
dc.w send4l/4; request length
s4b: dc.l 0 ; cid (has to be calculated)
s4a: dc.l 0 ; wid (has to be calculated)
dc.l 1+4+8 ; function+foreground+background
dc.l 3 ; function=copy
dc.l $ffffff ; foreground: white
dc.l $0080ff ; background: light blue
send4l=@-send4
; Put Image
send5: dc.b 72 ; opcode for PutImage
dc.b 2 ; ZPixmap
dc.w send5l/4+320*10*4/4; request length
s5a: dc.l 0 ; wid (has to be calculated)
s5b: dc.l 0 ; cid (has to be calculated)
dc.w 320 ; width
dc.w 200/20 ; hight; we send 20 parts each 12800 byte (<16k)
s5x: dc.w 0 ; dest-x (inserted later)
s5y: dc.w 0 ; dest-y (inserted later)
dc.b 0 ; left-pad
dc.b 24 ; depth
dc.w 0 ; unused
send5l=@-send5

; Set Input Focus
send6: dc.b 42 ; opcode for SetInputFocus
dc.b 0 ; revert-to None
dc.w send6l/4; request length
s6a: dc.l 0 ; wid (has to be calculated)
dc.l 0 ; timestamp CurrentTime
send6l=@-send6


;--------------------------- uninitialized data ----------------------------

screen: blk.l 320*200 ; bitmap
stack_ptr: blk.l 1
x_handle: blk.l 1
annie1: blk.l 1
color: blk.l 64
fname: blk.b 256+32
buf2: blk.b 1024
buf2l=@-buf2

;---------------------------------------------------------------------------

data_filez=@@-data_offset
data_memsz= @-data_addr

;===========================================================================
From: Wolfgang Kern on

Herbert Kleebauer answered

>> Perhaps you tell us about the used algo so we can read your binaries
>> with our disassemblers in our familiar/prefered syntax.
>> I think you once posted it anyway, but the many M$-forced crashes
>> may have wiped it from my HDs.

> I'm not sure about what you are speaking here. The posted code
> is just an example which OS calls you need to put some pixels
> on the screen or get mouse and keyboard events. If you mean
> ASCII ANNIES code to generate hearts, then this is of no
> interest here, I also could have displayed some predefined
> picture instead.

Thanks, I see. First I thought it was a 'text.bat2code.bin' story
(which I lost recently).

__
wolfgang



From: rhyde on
On Jul 19, 5:11 pm, Herbert Kleebauer <k...(a)unibwm.de> wrote:
>
> It doesn't invoke undefined behaviour but a compiler dependent
> behaviour. I didn't say "only on the SUN". I used a similar statement
> in a program to generate pdf files. It was ok when compiled with
> gcc in DOS and Linux but not when compiled with gcc on a SUN.
> Seems the DOS/Linux version of gcc first evaluates the left side
> and then the right side whereas the opposite is true for gcc on a
> SUN.


Am I the only one noticing a bit of a dichotomy here?

All these years you blast people for thinking they could write
applications in assembly code because assembly is sooooo bad,
nonportable, hard to write and maintain, etc., etc., and then you
demonstrate that your HLL C code is no better?

Shame on you Herbert. If you're going to play the "everyone should
write HLL code because it's better than assembly" card, you should, at
the very least, write HLL code that is worthy of such a statement.
Writing non-conforming, non-portable, C code and claiming that "as
long as *one* implementation accepts it, it is fine" is hardly a way
to make your point about how much better HLLs are than assembly.
hLater,
Randy Hyde


First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
Prev: masm linking from console
Next: NASM HelloWorld - DOS