From: Rod Pemberton on

"Wolfgang Kern" <nowhere(a)never.at> wrote in message
news:f7v9t6$skq$1(a)newsreader2.utanet.at...
>
> Rod Pemberton replied:
> > :) All I remember is that it halted or hung right after startup...
>
> any message, like 'no disass.com'?
>
> then you got the version with 'default path' = 'Wolfgang's path',
> I changed this several weeks ago to save from recompilation and
> use 'current path' as default now.
>
> A hung ?
> the ESC-key terminates this (former) unmoveable, frontmost box.
> Latest upload is moveable and can be minimised (even only by taskbar).
>

Damn... you want me to dl it again and tell you if it's fixed, don't you?


Rod Pemberton

From: Begzin Aiken on
Phil Carmody wrote:

<snip>

> If you'd like me to stop shredding your garbage, please just include
> "the order of evaluation of a[--i]=i can follow from precedence"
> in your reply and I will quite happily dump you in the bozo-bin
> with Skybuck. You're nearly there, I'd just like to be 100% sure
> that you're incapable of getting your head around the issue.

I saw this coming. When you see you're losing, you try and make it look
as if the other person is not able to understand, that they're not able
to get their "head around the issue", as you put it here. When in fact,
it's you that cannot get your head around the issue. And then you tell
them you're going to "dump them in the bozo-bin", that way you won't
have to actually face the embarrassment of losing. It reminds me of an
ostrich sticking it's head in the sand, thinking that will make whatever
it is confronting it go away. It's not going to go away, just because
you can't be responsible enough to face it.

From: Phil Carmody on
Begzin Aiken <baiken(a)mishmash.net> writes:
> Phil Carmody wrote:
>
> <snip>
>
> > If you'd like me to stop shredding your garbage, please just include
> > "the order of evaluation of a[--i]=i can follow from precedence"
> > in your reply and I will quite happily dump you in the bozo-bin with
> > Skybuck. You're nearly there, I'd just like to be 100% sure
> > that you're incapable of getting your head around the issue.
>
> I saw this coming. When you see you're losing, you try and make it
> look as if the other person is not able to understand, that they're
> not able to get their "head around the issue", as you put it
> here. When in fact, it's you that cannot get your head around the
> issue.

Do you believe that either an implicitly or explicitly undefined
order of evaluation can be dependent upon parsing method and
precedence rules?

Do you believe that the order of evaluation of a[--i]=i follows
from precedence?

Answers please. Chop, chop.

Phil
--
"Home taping is killing big business profits. We left this side blank
so you can help." -- Dead Kennedys, written upon the B-side of tapes of
/In God We Trust, Inc./.
From: Frank Kotler on
Herbert Kleebauer wrote:

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

That's readable enough, but it might want some comments. My attempts to
add some comments (still working with the first, uncorrected version,
actually) have gone from SIGBUS to SIGSEGV to SIGPIPE... which I
consider "progress". But I still havent got it.

I took the "regular linker" version out of retirement, updated it to
Herbert's latest version (mostly), and got *that* running, finally. For
those who prefer the illogical, unreadable syntax (most of us), here 'tis.

Best,
Frank

; "Annie's Heart" for Xwindows
; Herbert's code, translated to Nasm
; "regular linkable version"
;
; nasm -f elf -O999 myprog.asm
; ld -o myprog myprog.o

global _start

section .text
_start:

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

main: mov [stack_ptr], esp ; save initial stack pointer


; ******************** get socket handle
***************************
push 0 ; no protocol specified
push 1 ; 1: SOCK_STREAM (/usr/include/linux/net.h)
push 1 ; 1: AF_UNIX, AF_LOCAL (/usr/include/linux/socket.h)
mov ecx, esp ; pointer to parameter for "socket"
mov ebx, 1 ; "socket" (/usr/include/linux/net.h)
mov eax, 102 ; socketcall (/usr/include/asm/unistd.h)
int 80h
add esp, 3 * 4 ; free space for parameters
test eax, eax ; ERROR
js err

; my apologies for propagating this sloppiness.
; really should be "cmp eax, -4096" (or -4095?)
; won't happen here, but we *could* get a
; valid return over 2G! - fbk

mov [x_handle], eax


; ********** connect socket to /tmp/.X11-unix/X0"
******************
push sockaddr_un_l
push sockaddr_un ; (/usr/include/linux/un.h)
push dword [x_handle] ; socket handle
mov ecx, esp ; pointer to parameter for "connect"
mov ebx, 3 ; "connect" (/usr/include/linux/net.h)
mov eax, 102 ; socketcall (/usr/include/asm/unistd.h)
int 80h
add esp, 3 * 4 ; free space for parameters
test eax, eax ; ERROR
js err


; *************** make socket read non blocking
*******************
mov ebx, [x_handle] ; socket handle
mov ecx, 3 ; F_GETFL (/usr/include/asm/fcntl.h)
mov eax, 55 ; fcntl (/usr/include/asm/unistd.h)
int 80h
test eax, eax ; ERROR
js err
mov ebx, [x_handle] ; socket handle
mov ecx, 4 ; F_SETFL (/usr/include/asm/fcntl.h)
mov edx, eax
or edx, 800h ; O_NONBLOCK (/usr/include/asm/fcntl.h)
mov eax, 55 ; fcntl (/usr/include/asm/unistd.h)
int 80h
test eax, eax ; ERROR
js err


; ******************* send connect message
*************************
mov eax, send1 ; pointer to connect message
mov edx, send1l

call get_xauth ; try to read .Xauthority
jc _11 ; no success, let's try without auth.

mov [send1+6], bx ; insert name length
mov [send1+8], si ; insert data length

call x_send ; send header

mov eax, ecx ; pointer to name
lea edx, [ebx + 3] ; pad to a multiple of 4
and edx, -4
call x_send ; send name

mov eax, ebp ; pointer to data
lea edx, [esi + 3] ; pad to a multiple of 4
and edx, -4
_11: call x_send ; send data

xor ebp, ebp ; number of total bytes read
mov esi, buf2 ; pointer to buffer for next read
mov edi, buf2l ; max. bytes to read

.10: mov eax, esi
mov edx, edi
call x_receive_raw
jz .10 ; but we need a reply

cmp byte [buf2], 1 ; success
jne err ; something went wrong

add ebp, eax ; total read bytes
add esi, eax ; pointer to buffer for next read
sub edi, eax ; max. bytes to read
cmp ebp, 8 ; at least 8 bytes read?
jc .10 ; no, get more

movzx ebx, word [buf2 + 6] ; additional data in 4 bytes
lea ebx, [ebx * 4 + 8] ; total size in bytes
cmp ebp, ebx ; all read
jc .10 ; no, get more


; ******************* calculate id's
*******************************
mov esi, buf2
mov eax, [esi + 0Ch] ; resource_id_base

mov edx, [esi + 10h] ; resource_id_mask
mov ecx, edx
neg ecx
and edx, ecx ; resource_id_incr

mov [s2a], eax ; wid for CreateWindow
mov [s3a], eax ; wid for MapWindow
mov [s4a], eax ; wid for CreateDC
mov [s5a], eax ; wid for CreateDC
mov [s6a], eax ; wid for SetInputFocus

add eax, edx ; next id
mov [s4b], eax ; cid for CreateDC
mov [s5b], eax ; cid for CreateDC

add eax, edx ; next id ; lint!!!

; mov [resource_id_next], eax
; mov [resource_id_incr], edx


; ******************* get root window id
***************************
movzx eax, word [esi + 18h] ; length of vendor string
add eax, 28h + 3 ; const header length + round vendor length
and al, -4 ; round to 4 bytes

movzx edx, byte [esi + 1Dh] ; number of FORMATs
shl edx, 3 ; 8 byte for each FORMAT entry
add edx, eax ; offset to root WINDOW id

mov eax, [esi + edx] ; root window
mov [s2b], eax ; CreateWindow needs root window id

mov eax, [esi + edx + 20] ; width/height of root window
mov [s2x], eax ; create window full size

sub eax, (200 << 16) + 320
shr eax, 1
and eax, 0FFFF7FFFh
mov [s5x], eax ; center drawing


; ******************* send CreatWindow request
*********************
mov eax, send2
mov edx, send2l
call x_send
call x_receive
jz .20 ; no message is a good message
cmp byte [eax], 0 ; error message
je ende


; ******************* send MapWindow request
***********************
.20: mov eax, send3
mov edx, send3l
call x_send
call x_receive
jz .30 ; no message is a good message
cmp byte [eax], 0 ; error message
je ende


; ******************* send CreatDC request
*************************
.30: mov eax, send4
mov edx, send4l
call x_send
call x_receive
jz .40 ; no message is a good message
cmp byte [eax], 0 ; error message
je ende


; ******************* send SetInputFocust *************************
.40: mov eax, send6
mov edx, send6l
call x_send
call x_receive
jz .60 ; no message is a good message
cmp byte [eax], 0 ; error message
je ende


.60: call init_color ; init 64 VGA colors

; ******************** main loop ***************************
.50: call annie ; generate next picture
call display
call x_receive
jz .50 ; no message is a good message

cmp byte [eax], 0 ; error message
je err
cmp byte [eax], 2 ; key press
je ende
cmp byte [eax], 4 ; button press
jne .50
err:
ende: mov ebx, 0 ; return code
mov eax, 1 ; exit
int 80h

;------------------------------------------
display:
mov esi, screen
mov ecx, 20 ; we use 20 parts to make each less than 16k
..10
mov eax, send5
mov edx, send5l
call x_send
mov eax, esi
mov edx, 320 * 10 * 4 ; size of one part
call x_send
add word [s5y], 10 ; update y pos for next part
add esi, 320*10*4 ; update source pointer for next part
loop .10
sub word [s5y], 20*10 ; restore original y position
ret
;-----------------------------------------


; ********* Annie's code to draw a heart ****************
annie: pusha
xor ebx, ebx

.10: inc dword [annie1]
mov ecx, 320 * 200
xor edi, edi
.20: mov eax, edi ; byte pos in screen
xor edx, edx
mov ebx, 320 ; 320 lines
div ebx ; eax: line 0-199 edx: column 0-319
sub eax, 120 ; center y=120 (-120 .. +79)
sub edx, 160 ; x=160 (-160 .. +159)
jg .30
neg edx ; symmetric in x (0 .. 160)
.30: mov ebx, eax
imul ebx, ebx ; ebx = x*x
add eax, edx ; eax = x*x+y
imul eax ; eax = (x*x+y)**2 mod 2*16
add ebx, eax
jz .40
xor edx, edx
mov eax, 600000
div ebx
.40: add eax, [annie1] ; change color
shr eax, 2
movzx eax, al
mov eax, [color+ eax * 4]
mov [screen + edi * 4], eax
inc edi
loop .20

popa
; nop ???
ret

; ****************** initialize 64 VGA colors *********************
init_color:
pusha
mov esi, color
mov eax, 0 ; sic
mov ecx, 64
_01: mov [esi], eax
add esi, 4
add al, 10h
add ax, 800h
add eax, 40000h
loop _01
popa
; nop ???
ret

;**********************************************************
;******** 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:
push eax
push edx
push edi

mov edi, [stack_ptr] ; original stack pointer at program start
mov eax, [edi] ; number of arguments
lea edi, [edi + eax * 4 + 8] ; skip arguments + trailing
null pointer

.20: mov esi, [edi] ; pointer to next env variable
add edi, 4
test esi, esi ; no more env variables
jz .notfound
cmp dword [esi], 'HOME' ; HOME found?
jne .20 ; no, try next
cmp byte [esi + 4], '=' ; HOME= found?
jne .20 ; no, try next
add esi, 5 ; start of HOME path
or ecx, -1
.30: inc ecx ; count length of HOME path
cmp byte [esi + ecx], 0
jne .30

or ecx, ecx ; at least one char long?
jz .notfound ; no, HOME is empty
cmp ecx, 256 ; more than 256 charcters
ja .notfound ; somebody tries a buffer overflow
mov edi, fname ; buffer for filename
rep movsb ; copy HOME path
mov eax, '/.Xa' ; 'aX./' ; add .Xauthority
stosd
mov eax, 'utho' ; 'ohtu'
stosd
mov eax, 'rity' ; 'ytir'
stosd
mov byte [edi], 0 ; and a trailing 0

mov ebx, fname
xor ecx, ecx ; readonly
mov eax, 5 ; open
int 80h


test eax, eax ; file open error?
js .notfound ; yes

mov ebx, eax ; file handle
mov ecx, buf2
mov edx, buf2l ; read 1024 byte
mov eax, 3 ; read
int 80h

cmp eax, buf2l
jnc err ; .Xauthority >= 1024 byte
mov ebp, eax ; bytes read

mov eax, 6 ; close
int 80h

test ebp, ebp ; file empty
jz .notfound


mov esi, buf2
add ebp, esi ; end of read data
xor eax, eax

.60: lodsw ; family
dec ax
jz .40 ; 1=FamilyLocal

mov ecx, 4 ; skip entry
.50: lodsw
ror ax, 8 ; big -> little endian
add esi, eax
loop .50
cmp esi, ebp ; more data
jc .60 ; try next entry

..notfound:
stc
jmp _70

.40: mov ecx, 2
mov ebx, ecx
.41: lodsw
ror ax, 8
add esi, eax ; skip address/number
loop .41

.42: lodsw
ror ax, 8
mov ecx, esi
movzx ebx, ax
add esi, ebx

lodsw
ror ax, 8
mov ebp, esi
movzx esi, ax
clc
_70: pop edi
pop edx
pop eax
ret


;**********************************************************
;******** send message to X server **************
;**********************************************************
; input: eax: pointer to message *
; edx: length of message *
;**********************************************************
x_send: pusha
mov ebp, eax ; pointer to next byte of message
mov esi, edx ; remaining bytes to send

.20: push 0 ; flags
push esi ; length
push ebp ; pointer to data
push dword [x_handle] ; socket handle
mov ecx, esp ; pointer to parameter for "send"
mov ebx, 9 ; "send" (/usr/include/linux/net.h)
mov eax, 102 ; socketcall (/usr/include/asm/unistd.h)
int 80h
add esp, 4*4 ; free space for parameters

cmp eax, -11 ; EAGAIN:
je .20 ; message couldn't be sent, try again

test eax, eax ; ERROR
js err

sub esi, eax ; remaining bytes to send
jz .30 ; nothing, all sent
add ebp, eax ; pointer to remaining message
jmp .20 ; send rest of message

.30: popa
; nop ?
ret


;**********************************************************
;******** receive ONE message from X server **********
;**********************************************************
; input: none *
; output: Z=1: no complete message available *
; eax/edx undefined *
; Z=0: eax: pointer to message data *
; edx: size of data *
;**********************************************************
x_receive:
push ecx
push esi
push edi
_00: mov eax, [buf2_rest] ; still something in read buffer?
cmp eax, 32 ; a message has at least 32 bytes
jnc .10 ; maybe it is a complete message

.30: mov esi, [buf2_ptr] ; start of message
mov edi, buf2 ; start of buffer
mov [buf2_ptr], edi ; we copy message to top of buffer
cmp edi, esi ; already at top of buffer
je .50 ; then nothing to copy
or eax, eax ; nothing in buffer
jz .50 ; then also nothing to copy
mov ecx, eax ; copy to top of buffer
rep movsb

.50: mov edx, buf2l ; let's try to get some more data
sub edx, eax ; not more bytes than space is left in
the buf
lea eax, [buf2 + eax] ; append it here
call x_receive_raw
jnz .20 ; we could read something
jmp _100 ; return with Z=1

.20: add [buf2_rest], eax ; now we have a few more bytes in the
buffer
jmp _00 ; let's try again

.10: mov esi, [buf2_ptr] ; let's test if it is a complete meesage
cmp byte [esi], 34
ja err ; the last known message is nr 34
mov edx, 32
cmp byte [esi], 0 ; error message
cmp byte [esi], 1 ; reply message
jne .40 ; event message is always 32 byte
add edx, [esi + 12] ; + additional data for reply
add edx, [esi + 12] ; + additional data for reply
add edx, [esi + 12] ; + additional data for reply
add edx, [esi + 12] ; + additional data for reply
cmp eax, edx ; complete reply in buffer
jc .30 ; no, let's try to get more
.40: mov eax, esi ; pointer to data
sub [buf2_rest], edx ; new rest
add [buf2_ptr], edx ; pointer to next data; clear Z flag
_100: pop edi
pop esi
pop ecx
ret

;**********************************************************
;******** read data from X server **********
;**********************************************************
; input: eax: pointer to read buffer *
; edx: size of buffer *
; output: Z=1: nothing to read *
; Z=0: eax bytes read *
;**********************************************************
x_receive_raw:
push ecx
push ebx

push 0 ; flags
push edx ; bytes to read
push eax ; pointer to buffer
push dword [x_handle] ; socket handle
mov ecx, esp ; pointer to parameter for "recv"
mov ebx, 10 ; "recv" (/usr/include/linux/net.h)
mov eax, 102 ; socketcall (/usr/include/asm/unistd.h)
int 80h
add esp, 4 * 4 ; free space for parameters
pop ebx
pop ecx
cmp eax, -11 ; EAGAIN: no message available -> Z=1
je .10
test eax, eax ; <0: ERROR 0: NULL message -> Z=1
js err
.10: ret




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

;--------------------------- constant data ---------------------------------
; (note that we're in .text, not .rdata)

align 4

sockaddr_un:
dw 1 ; 1: AF_UNIX, AF_LOCAL (/usr/include/linux/socket.h)
db "/tmp/.X11-unix/X0"
sockaddr_un_l equ $ - sockaddr_un

align 4

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


section .data


;--------------------------- initialized data ------------------------------
buf2_ptr: dd buf2
buf2_rest: dd 0

; Connection Setup
send1: db $6c,0 ; LSB first
dw 11,0 ; major/minor version
dw 0,0 ; length of protocol name/data
dw 0 ; unused
send1l equ $ - send1

; Create Window
send2: db 1 ; opcode for Create Window
db 0 ; depth from parent
dw send2l/4; request length
s2a: dd 0 ; wid (has to be calculated)
s2b: dd 0 ; parent (has to be calculated)
dw 0 ; x
dw 0 ; y
s2x: dw 640 ; width
s2y: dw 400 ; heigth
dw 0 ; border-width
dw 0 ; class: CopyFromParent
dd 0 ; visual: CopyFromParent
dd 0A02h ; value-mask: background-pixel 2
; + override-redirect 200
; + event-mask 800
dd 0 ; background: black
db 1 ; override-redirect = true
db 0,0,0 ; pad
dd 5 ; event_mask: KeyPress 1
; +ButtenPress 4
; +PointerMotion 40
send2l equ (($-send2)+3) & 0fffffffch

; Map Window
send3: db 8 ; opcode for Map Window
db 0 ; unused
dw send3l/4; request length
s3a: dd 0 ; wid (has to be calculated)
send3l equ $ - send3


; Create GC
send4: db 55 ; opcode for CreateGC
db 0 ; unused
dw send4l/4; request length
s4b: dd 0 ; cid (has to be calculated)
s4a: dd 0 ; wid (has to be calculated)
dd 1+4+8 ; function+foreground+background
dd 3 ; function=copy
dd 0ffffffh ; foreground: white
dd 0080ffh ; background: light blue
send4l equ $ - send4

; Set Input Focus
send6: db 42 ; opcode for SetInputFocus
db 0 ; revert-to None
dw send6l/4; request length
s6a: dd 0 ; wid (has to be calculated)
dd 0 ; timestamp CurrentTime
send6l equ $ - send6

; Put Image
send5: db 72 ; opcode for PutImage
db 2 ; ZPixmap
dw send5l/4 + 320*10*4/4 ; request length
s5a: dd 0 ; wid (has to be calculated)
s5b: dd 0 ; cid (has to be calculated)
dw 320 ; width
dw 200/20 ; height
s5x: dw 0 ; dest-x
s5y: dw 0 ; dest-y
db 0 ; left-pad
db 24 ; depth
dw 0 ; unused
send5l equ $ - send5

section .bss
;--------------------------- uninitialized data ----------------------------

screen: resd 320*200 ; bitmap

stack_ptr: resd 1
x_handle: resd 1
annie1: resd 1
color: resd 64
fname: resb 256+32
buf2: resb 1024
buf2l equ $ - buf2

;---------------------------------------------------------------------------
From: Wolfgang Kern on

Rod Pemberton asked:

>> A hung ?
>> the ESC-key terminates this (former) unmoveable, frontmost box.
>> Latest upload is moveable and can be minimised (even only by taskbar).
>>

> Damn... you want me to dl it again and tell you if it's fixed,
> don't you?

:) TIA, <sub> yes please </sub> :)

It would save me from searching a possible bug if there isn't any.
__
wolfgang


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