Direct connect to the X server - Xwindows

This is a discussion on Direct connect to the X server - Xwindows ; I have done some experiments with graphics output to the X server in Linux/KDE using assembler code. After connecting to the server with unix domain sockets I use CreateWindow to create a window. The window is created with the given ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Direct connect to the X server

  1. Direct connect to the X server

    I have done some experiments with graphics output to the X server
    in Linux/KDE using assembler code. After connecting to the server
    with unix domain sockets I use CreateWindow to create a window.
    The window is created with the given size, but the given position
    and border width is ignored. It is also not a simple window as I
    would have expected, but has a title bar with the minimize,
    maximize and close button. I don't know why this happens, maybe
    KDE intercepts my connection to the X server and modifies my requests?
    If so, what can I do to directly connect to the X server?

    Here the Linux binary of the demo program:

    #!/bin/bash
    name=XMAS
    echo -n>$name
    x=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz0123456789123
    for (( i=0; i<65; i++ )); do eval _$(( $i/62 ))${x:$i:1}=$(( $i&63 )); done
    n=0; m=0
    (while read -n 1 c; do
    case $c in [A-Za-z0-9+/=])
    if [ "$c" == "+" ]; then c=11; elif [ "$c" == "/" ]; then c=12;
    elif [ "$c" == "=" ]; then c=13; else c=0$c; fi
    e=$d; d=$c ; eval c=\$_$c; n=$(( $n*64+$c )); m=$(( $m+1 ))
    if [ "$m" == "4" ]; then
    echo -n -e \\$(( ($n>>22&7)*100+($n>>19&7)*10+($n>>16&7) ))>>$name
    if [ "$e" != "13" ]; then
    echo -n -e \\$(( ($n>>14&7)*100+($n>>11&7)*10+($n>>8&7) ))>>$name; fi
    if [ "$d" != "13" ]; then
    echo -n -e \\$(( ($n>>6&7) *100+($n>>3&7)*10+($n&7) ))>>$name; fi
    n=0; m=0
    fi
    esac
    done)<<"---";
    f0VMRg EBAQAAAAAAAA AAAAIAAwA BAAAAdIAECDQAAAAAAA AAAAAAAD QAIAACAAAAAAAAAAEA
    AAAAAAAAAI AECACABAjIBAA AyAQAAAUAAAA AEAAAAQAAAM gEAADIlAQIyJQ ECGwAAADY7gMA
    BgAAAAAQ AAC+PH0ICLgAA AAAuUAAAA CJBoPGBAQQZgUACA UAAAQA4u6+y JQECL9gfwgIuQwA
    AADzpFiNZI QEXoX2D4SfAAAA gT5IT01 Fde+AfgQ9demDxgW Dyf9BgDwOAH X5CckPhHwAAACB
    +QABAAAPh 3AAAAC/QH4ICP OkuC8uWGG ruHV0aG+ruHJpdHmr xgcAu0B+CA gxybgFAAAAzYCF
    wHhCicO5 oH8ICLoABAAA uAMAAADNgInFuA YAAADNgIXtdC K+oH8ICAH1Mc BmrWZIdBu5BAAA
    AGatZs HICAHG4vY57nL nXr9sfwgI6zq /bH8ICDHAuQIAAA CJy2atZsHI CAHG4vZmrWbByAgP
    t8jzpA+3y PfZg+EDdAL zqsHAEEt14 6NmfwgIge9gfwgI iT00fQgIagBqAW oBieG7AQAAALhm
    AAAAzYCDxAy FwA+IhgIAAI nHaBMAAABo tIQECFeJ4bs DAAAAuGYAAAD NgIPEDIXAD4hgAgAA
    ifu5AwAAALg3AA AAzYCFwA+ ISgIAAI n7uQQAAACJwoHKA AgAALg3AAAA zYCFwA+ILAIAAGoA
    /zU0fQgIaG B/CAhXieG7C QAAALhmAAA AzYCDxBCFwA+IBQIA AGoAaAAEA ABooH8ICFeJ4bsK
    AAAAuGYAA ADNgIPEED31/// /dNuFwA+ I2AEAAL6gfwgIi0 YMi1YQidH3 2SHKo9iUBAij/JQE
    CKMIlQ QIoyCVBAgB0KMEl QQIoySVBAgB0A +3RhiDwCsk /A+2Vh3B4gMB0Is EBqPclAQIagBo
    JAAAAGj UlAQIV4nhuwk AAAC4ZgAAAM2A g8QQhcAPiGUBAA BqAGgABAAA aKB/CAhXieG7CgAA
    ALhmAAAAz YCDxBA99f// /3QIhcAPiD gBAABqAGgIAAAA aPiUBAhXieG7CQA AALhmAAAAzYCD
    xBCFwA+IE gEAAGoAaAAEAA BooH8ICFeJ4 bsKAAAAuGYAAA DNgIPEED31/ ///dAiFwA+I5QAA
    AGoAaBwAAABo AJUECFeJ 4bsJAAAAuGYA AADNgIPEEIXA D4i/AAAAagBo AAQAAGigfwgIV4nh
    uwoAAAC4ZgAAA M2Ag8QQP fX///90DYX AD4iSAAAA6JkA AAC9GOgDAL4clQ QIagBVVleJ4bsJ
    AAAAuGYAAA DNgIPEED31 ////dOOFwA+IXgAAACnFdA QBxuvTagBoAAQ AAGigfwgIV4nhuwoA
    AAC4ZgAAAM2A g8QQPfX/ //90CIXAD 4gpAAAAagBoAA QAAGigfwgIV4n huwoAAAC4ZgAAAM2A
    g8QQPfX// /8PhG7///+7 AAAAALgBAAA AzYBgMdv/BTh9 CAi5APoAADH/ifg x0rtAAQAA9/Mt
    eAAAAIH qoAAAAH8C99qJw w+v2wHQ9 +gBw3QJMdK4wCcJA PfzAwU4fQgIwOgC D7bAiwSFPH0I
    CIkEvTSVB AhH4rNhkMM AAAEAL3RtcC8 uWDExLXVuaXgvWD AAbAALAAAAAAA AAAAAAQAJAAAA
    AAAAAAAAZA AyAEAByA AKAAAAAAAAA AIAAAD/gAAACAA CAAAAAAA3AAcAAAA AAAAAAAANAAAA
    AwAAAP///wD /gAAAS AIG+gAAAAAAA AAAQAHIAAA AAAAAGAAA
    ---
    chmod +x $name
    ################################################## ###########################


    And here the source code:

    DEBUG=0
    ;================================================= ==========================

    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:
    ; ****************** initialize 64 VGA colors *********************
    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

    ; ****************** copy conect message to buffer ****************
    move.l #send1,r5
    move.l #buf1,r6
    move.l #send1l,r2
    rep_r2 move.b (r5)+-,(r6)+-{s1}

    ; *********** read cookie from $home/.Xauthority ******************
    move.l (sp)+,r0 ; number of arguments
    lea.l 4.b(r7,r0*4),r7 ; skip arguments + trailing null pointer

    _20: move.l (sp)+,r5 ; pointer to next env variable
    tst.l r5,r5
    beq.l _notfound
    cmp.l #'EMOH',(r5) ; HOME found?
    bne.b _20 ; no
    cmp.b #'=',4.b(r5)
    bne.b _20
    addq.l #5,r5
    orq.l #-1,r2
    _30: inc.l r2
    cmp.b #0,(r5,r2)
    bne.b _30

    or.l r2,r2
    beq.l _notfound
    cmp.l #256,r2 ; more than 256 charcters
    bhi.l _notfound ; somebody tries a buffer overflow
    move.l #fname,r6
    rep_r2 move.b (r5)+-,(r6)+-{s1}
    move.l #'aX./',r0
    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)

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

    IF DEBUG
    move.l #text16,r5
    bsr.l out_status
    ENDIF

    tst.l r0,r0
    bmi.b _notfound

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

    IF DEBUG
    move.l #text17,r5
    bsr.l out_status
    bsr.l dump_buf
    ENDIF

    move.l r0,r4 ; bytes read

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

    IF DEBUG
    move.l #text18,r5
    bsr.l out_status
    ENDIF

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


    move.l #buf2,r5
    add.l r5,r4
    eor.l r0,r0

    _60: move.w (r5)+-,r0
    dec.w r0
    beq.b _40 ; 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
    blo.b _60 ; try next entry

    _notfound:
    IF DEBUG
    move.l #text20,r5
    bsr.l out_status
    ENDIF
    move.l (sp)+,r5
    move.l #buf1+12,r6
    br.b _70

    _40: move.l #buf1+12,r6
    eor.l r0,r0

    IF DEBUG
    move.l r5,-(sp)
    move.l #text21,r5
    bsr.l out_status
    move.l (sp)+,r5
    ENDIF

    move.l #2,r2
    move.l r2,r3
    _41: move.w (r5)+-,r0
    ror.w #8,r0
    add.l r0,r5 ; skip address/number
    dbf.l r2,_41

    _42: move.w (r5)+-,r0
    ror.w #8,r0
    movu.wl r0,r2
    rep_r2 move.b (r5)+-,(r6)+-{s1} ; name / data
    movu.wl r0,r2
    neg.l r2
    andq.l #3,r2
    beq.b _43
    rep_r2 move.b r0,(r6)+-{s1} ; pad
    _43: rol.l #16,r0
    dec.l r3
    bne.b _42
    move.l r0,buf1+6

    _70: sub.l #buf1,r6
    move.l r6,connect_length

    IF DEBUG
    move.l #text19,r5
    bsr.l out_status
    move.l r6,r0
    bsr.l dump_buf1
    ENDIF

    a: ; ******************** get socket handel ***************************
    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
    IF DEBUG
    move.l #text1,r5
    bsr.l out_status
    ENDIF
    tst.l r0,r0 ; ERROR
    bmi.l err
    move.l r0,r6 ; socket 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 r6,-(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
    IF DEBUG
    move.l #text2,r5
    bsr.l out_status
    ENDIF
    tst.l r0,r0 ; ERROR
    bmi.l err

    ; *************** make socket read non blocking *******************
    move.l r6,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
    IF DEBUG
    move.l #text3,r5
    bsr.l out_status
    ENDIF
    tst.l r0,r0 ; ERROR
    bmi.l err
    move.l r6,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
    IF DEBUG
    move.l #text4,r5
    bsr.l out_status
    ENDIF
    tst.l r0,r0 ; ERROR
    bmi.l err

    ; ******************* send connect message *************************
    moveq.l #0,-(sp) ; flags
    move.l connect_length,-(sp)
    move.l #buf1,-(sp) ; connect message
    move.l r6,-(sp) ; socket handle
    move.l r7,r2 ; pointer to parameter for "connect"
    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
    IF DEBUG
    move.l #text5,r5
    bsr.l out_status
    ENDIF
    tst.l r0,r0 ; ERROR
    bmi.l err

    _10: moveq.l #0,-(sp) ; flags
    move.l #buf2l,-(sp)
    move.l #buf2,-(sp) ; server response for connect message
    move.l r6,-(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
    IF DEBUG
    move.l #text6,r5
    bsr.l out_status
    ENDIF
    cmp.l #-11,r0 ; EAGAIN: no message available
    beq.b _10 ; but we need a reply
    tst.l r0,r0 ; ERROR
    bmi.l err

    IF DEBUG
    bsr.l dump_connect
    ENDIF

    ; ******************* 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

    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 r1,r0 ; offset to root WINDOW id

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


    ; ******************* send CreatWindow request *********************
    moveq.l #0,-(sp) ; flags
    move.l #send2l,-(sp)
    move.l #send2,-(sp) ; CreateWindow request
    move.l r6,-(sp) ; socket handle
    move.l r7,r2 ; pointer to parameter for "CreateWindow"
    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
    IF DEBUG
    move.l #text7,r5
    bsr.l out_status
    ENDIF
    tst.l r0,r0 ; ERROR
    bmi.l err

    moveq.l #0,-(sp) ; flags
    move.l #buf2l,-(sp)
    move.l #buf2,-(sp) ; no server reply expected
    move.l r6,-(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
    IF DEBUG
    move.l #text8,r5
    bsr.l out_status
    ENDIF
    cmp.l #-11,r0 ; EAGAIN: no message available
    beq.b _20 ; no message is a good message
    tst.l r0,r0 ; ERROR
    bmi.l err

    IF DEBUG
    bsr.l dump_buf
    ENDIF

    ; ******************* send MapWindow request ***********************
    _20: moveq.l #0,-(sp) ; flags
    move.l #send3l,-(sp)
    move.l #send3,-(sp) ; MapWindow request
    move.l r6,-(sp) ; socket handle
    move.l r7,r2 ; pointer to parameter for "MapWindow"
    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
    IF DEBUG
    move.l #text9,r5
    bsr.l out_status
    ENDIF
    tst.l r0,r0 ; ERROR
    bmi.l err

    moveq.l #0,-(sp) ; flags
    move.l #buf2l,-(sp)
    move.l #buf2,-(sp) ; no server reply expected
    move.l r6,-(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
    IF DEBUG
    move.l #text10,r5
    bsr.l out_status
    ENDIF
    addq.l #4*4,r7 ; free space for parameters
    cmp.l #-11,r0 ; EAGAIN: no message available
    beq.b _30 ; no message is a good message
    tst.l r0,r0 ; ERROR
    bmi.l err

    IF DEBUG
    bsr.l dump_buf
    ENDIF

    ; ******************* send CreatDC request *************************
    _30: moveq.l #0,-(sp) ; flags
    move.l #send4l,-(sp)
    move.l #send4,-(sp) ; CreateDC request
    move.l r6,-(sp) ; socket handle
    move.l r7,r2 ; pointer to parameter for "MapWindow"
    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
    IF DEBUG
    move.l #text11,r5
    bsr.l out_status
    ENDIF
    tst.l r0,r0 ; ERROR
    bmi.l err

    moveq.l #0,-(sp) ; flags
    move.l #buf2l,-(sp)
    move.l #buf2,-(sp) ; no server reply expected
    move.l r6,-(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
    IF DEBUG
    move.l #text12,r5
    bsr.l out_status
    ENDIF
    addq.l #4*4,r7 ; free space for parameters
    cmp.l #-11,r0 ; EAGAIN: no message available
    beq.b _200 ; no message is a good message
    tst.l r0,r0 ; ERROR
    bmi.l err

    IF DEBUG
    bsr.l dump_buf
    ENDIF



    ; ********* call Annie's code to fill screen buffer ****************

    _200: bsr.l annie


    ; ******************* send PutImage request ************************
    ; all above send requests where short so we could hope they
    ; are sent without problems, but this message is 256k long,
    ; so we have to do it the proper way (we still assume the
    ; X server can handle such long messages, too lazy to check
    ; the value in the connect message or split the message to
    ; a save length of 16 KByte)
    _40: move.l #send5l,r4
    move.l #send5,r5 ; PutImage request
    _43: moveq.l #0,-(sp) ; flags
    move.l r4,-(sp)
    move.l r5,-(sp)
    move.l r6,-(sp) ; socket handle
    move.l r7,r2 ; pointer to parameter for "PutImage"
    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
    IF DEBUG
    move.l r5,-(sp)
    move.l #text13,r5
    bsr.l out_status
    move.l (sp)+,r5
    ENDIF
    cmp.l #-11,r0 ; EAGAIN:
    beq.b _43 ; message couldn't be sent, try again

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

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

    _42: moveq.l #0,-(sp) ; flags
    move.l #buf2l,-(sp)
    move.l #buf2,-(sp) ; no server reply expected
    move.l r6,-(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
    IF DEBUG
    move.l #text14,r5
    bsr.l out_status
    ENDIF
    addq.l #4*4,r7 ; free space for parameters
    cmp.l #-11,r0 ; EAGAIN: no message available
    beq.b _200 ; no message is a good message
    tst.l r0,r0 ; ERROR
    bmi.l err

    IF DEBUG
    bsr.l dump_buf
    ENDIF

    IF 0
    _50:
    moveq.l #0,-(sp) ; flags
    move.l #buf2l,-(sp)
    move.l #buf2,-(sp) ; wait for any message (close window)
    move.l r6,-(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
    cmp.l #-11,r0 ; EAGAIN: no message available
    beq.l _200 ; try again

    IF DEBUG
    move.l #text15,r5
    bsr.l out_status
    bsr.l dump_buf
    ENDIF
    ENDIF

    err:
    ende: move.l #0,r3 ; return code
    move.l #1,r0 ; exit
    trap #$80



    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




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

    IF DEBUG
    out_status:
    move.l r0,-(sp)
    move.l r5,r0
    bsr.l puts
    move.l (sp)+,r0
    bsr.l out_hex_l
    rts.l

    text1: dc.b 10,"return code socket: ",0
    text2: dc.b 10,"return code connect: ",0
    text3: dc.b 10,"return code F_GETFL: ",0
    text4: dc.b 10,"return code F_SETFL: ",0
    text5: dc.b 10,"return code send connect: ",0
    text6: dc.b 10,"return code recv connect: ",0
    text7: dc.b 10,"return code send CreateWindow: ",0
    text8: dc.b 10,"return code recv CreateWindow: ",0
    text9: dc.b 10,"return code send MapWindow: ",0
    text10: dc.b 10,"return code recv MapWindow: ",0
    text11: dc.b 10,"return code send createDC: ",0
    text12: dc.b 10,"return code recv createDC: ",0
    text13: dc.b 10,"return code send PutImage: ",0
    text14: dc.b 10,"return code recv PutImage: ",0
    text15: dc.b 10,"return code end message: ",0
    text16: dc.b 10,"return code open .Xauthority: ",0
    text17: dc.b 10,"return code read .Xauthority: ",0
    text18: dc.b 10,"return code close .Xauthority: ",0
    text19: dc.b 10,"connect message: ",0
    text20: dc.b 10,"nothing found in .Xauthority ",0
    text21: dc.b 10,"data found in .Xauthority ",0

    dump_connect:
    tst.l r0,r0
    bne.b _00
    rts.l

    _00: movem.l r0-r7,-(sp)
    bsr.l out_lf
    move.l #buf2,r5
    move.l r0,r2

    move.b (r5),r1
    cmp.b #0,r1
    beq.b _10
    cmp.b #1,r1
    beq.l _20
    cmp.b #2,r1
    beq.b _30

    movem.l (sp)+,r0-r7
    br.l dump_buf

    _10: move.l #_t1,r0
    bsr.l puts
    movu.bl 1.b(r5),r1

    move.l #_t2,r0
    bsr.l puts
    move.w 2.b(r5),r0
    bsr.l out_hex_w
    move.l #_t3,r0
    bsr.l puts
    move.w 4.b(r5),r0
    bsr.l out_hex_w

    move.l #_t4,r0
    bsr.l puts
    lea.l 8.b(r5),r0
    bsr.l putt
    bsr.l out_lf
    br.l ende

    _30: move.l #_t5,r0
    bsr.l puts
    move.l #_t4,r0
    bsr.l puts
    movu.wl 6.b(r5),r1
    lsl.l #2,r1
    lea.l 8.b(r5),r0
    bsr.l putt
    bsr.l out_lf
    br.l ende

    _20: move.l #_t6,r0
    bsr.l puts

    move.l #_t2,r0
    bsr.l puts
    move.w 2.b(r5),r0
    bsr.l out_hex_w

    move.l #_t3,r0
    bsr.l puts
    move.w 4.b(r5),r0
    bsr.l out_hex_w

    move.l #_t7,r0
    bsr.l puts
    move.l 8.b(r5),r0
    bsr.l out_hex_l

    move.l #_t8,r0
    bsr.l puts
    move.l 12.b(r5),r0
    bsr.l out_hex_l

    move.l #_t9,r0
    bsr.l puts
    move.l 16.b(r5),r0
    bsr.l out_hex_l

    move.l #_t10,r0
    bsr.l puts
    move.l 20.b(r5),r0
    bsr.l out_hex_l

    move.l #_t11,r0
    bsr.l puts
    move.w 26.b(r5),r0
    bsr.l out_hex_w

    move.l #_t12,r0
    bsr.l puts
    move.b 30.b(r5),r0
    bsr.l out_hex_b

    move.l #_t13,r0
    bsr.l puts
    move.b 31.b(r5),r0
    bsr.l out_hex_b

    move.l #_t14,r0
    bsr.l puts
    move.b 32.b(r5),r0
    bsr.l out_hex_b

    move.l #_t15,r0
    bsr.l puts
    move.b 33.b(r5),r0
    bsr.l out_hex_b

    move.l #_t16,r0
    bsr.l puts
    move.b 34.b(r5),r0
    bsr.l out_hex_b

    move.l #_t17,r0
    bsr.l puts
    move.b 35.b(r5),r0
    bsr.l out_hex_b

    move.l #_t18,r0
    bsr.l puts
    lea.l 40.b(r5),r0
    movu.wl 24.b(r5),r1
    bsr.l putt

    addq.l #3,r1
    andq.l #$fffffffc,r1
    lea.l (r0,r1),r6
    move.b #1,r3

    _50: cmp.b 29.b(r5),r3
    bhi.b _40

    move.l #_t19,r0
    bsr.l puts
    move.b r3,r0
    bsr.l out_hex_b
    move.b #'/',r0
    bsr.l putc
    move.b 29.b(r5),r0
    bsr.l out_hex_b


    move.l #_t20,r0
    bsr.l puts
    move.b (r6),r0
    bsr.l out_hex_b

    move.l #_t21,r0
    bsr.l puts
    move.b 1.b(r6),r0
    bsr.l out_hex_b

    move.l #_t22,r0
    bsr.l puts
    move.b 2.b(r6),r0
    bsr.l out_hex_b

    inc.b r3
    addq.l #8,r6
    br.b _50

    _40: move.b #1,r3

    _60: cmp.b 28.b(r5),r3
    bhi.l _70

    move.l #_t23,r0
    bsr.l puts
    move.b r3,r0
    bsr.l out_hex_b
    move.b #'/',r0
    bsr.l putc
    move.b 28.b(r5),r0
    bsr.l out_hex_b

    move.l #_t24,r0
    bsr.l puts
    move.l (r6),r0
    bsr.l out_hex_l

    move.l #_t25,r0
    bsr.l puts
    move.l 4.b(r6),r0
    bsr.l out_hex_l

    move.l #_t26,r0
    bsr.l puts
    move.l 8.b(r6),r0
    bsr.l out_hex_l

    move.l #_t27,r0
    bsr.l puts
    move.l 12.b(r6),r0
    bsr.l out_hex_l

    move.l #_t28,r0
    bsr.l puts
    move.l 16.b(r6),r0
    bsr.l out_hex_l

    move.l #_t29,r0
    bsr.l puts
    move.w 20.b(r6),r0
    bsr.l out_hex_w

    move.l #_t30,r0
    bsr.l puts
    move.w 22.b(r6),r0
    bsr.l out_hex_w

    move.l #_t31,r0
    bsr.l puts
    move.w 24.b(r6),r0
    bsr.l out_hex_w

    move.l #_t32,r0
    bsr.l puts
    move.w 26.b(r6),r0
    bsr.l out_hex_w

    move.l #_t33,r0
    bsr.l puts
    move.w 28.b(r6),r0
    bsr.l out_hex_w

    move.l #_t34,r0
    bsr.l puts
    move.w 30.b(r6),r0
    bsr.l out_hex_w

    move.l #_t35,r0
    bsr.l puts
    move.l 32.b(r6),r0
    bsr.l out_hex_l

    move.l #_t36,r0
    bsr.l puts
    move.b 36.b(r6),r0
    bsr.l out_hex_b

    move.l #_t37,r0
    bsr.l puts
    move.b 37.b(r6),r0
    bsr.l out_hex_b

    move.l #_t38,r0
    bsr.l puts
    move.b 38.b(r6),r0
    bsr.l out_hex_b

    move.b #1,r2
    move.b 39.b(r6),m2
    addq.l #40,r6

    _90: cmp.b m2,r2
    bhi.l _80

    move.l #_t39,r0
    bsr.l puts
    move.b r2,r0
    bsr.l out_hex_b
    move.b #'/',r0
    bsr.l putc
    move.b m2,r0
    bsr.l out_hex_b

    move.l #_t40,r0
    bsr.l puts
    move.b (r6),r0
    bsr.l out_hex_b

    move.w #1,r1
    move.w 2.b(r6),r4
    addq.w #8,r6

    _110: cmp.w r4,r1
    bhi.l _100

    move.l #_t41,r0
    bsr.l puts
    move.w r1,r0
    bsr.l out_hex_w
    move.b #'/',r0
    bsr.l putc
    move.w r4,r0
    bsr.l out_hex_w

    move.l #_t42,r0
    bsr.l puts
    move.l (r6),r0
    bsr.l out_hex_l

    move.l #_t43,r0
    bsr.l puts
    move.b 4.b(r6),r0
    bsr.l out_hex_b

    move.l #_t44,r0
    bsr.l puts
    move.b 5.b(r6),r0
    bsr.l out_hex_b

    move.l #_t45,r0
    bsr.l puts
    move.w 6.b(r6),r0
    bsr.l out_hex_w

    move.l #_t46,r0
    bsr.l puts
    move.l 8.b(r6),r0
    bsr.l out_hex_l

    move.l #_t47,r0
    bsr.l puts
    move.l 12.b(r6),r0
    bsr.l out_hex_l

    move.l #_t48,r0
    bsr.l puts
    move.l 16.b(r6),r0
    bsr.l out_hex_l

    addq.w #24,r6
    inc.w r1
    br.l _110

    _100: inc.b r2
    br.l _90

    _80: inc.b r3
    addq.l #8,r6
    br.l _60

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

    _t1: dc.b 10,"Failed",0
    _t2: dc.b 10,"protocol-major-version: ",0
    _t3: dc.b 10,"protocol-minor-version: ",0
    _t4: dc.b 10,"reason: ",0
    _t5: dc.b 10,"Authenticate",0
    _t6: dc.b 10,"Succes",0
    _t7: dc.b 10,"release-number: ",0
    _t8: dc.b 10,"resource_id-Base: ",0
    _t9: dc.b 10,"resource-id-mask: ",0
    _t10: dc.b 10,"motion-buffer-size: ",0
    _t11: dc.b 10,"maximum-request-length: ",0
    _t12: dc.b 10,"image-byte-order: ",0
    _t13: dc.b 10,"bitmap-format-bit-order: ",0
    _t14: dc.b 10,"bitmap-format-scanline-unit: ",0
    _t15: dc.b 10,"bitmap-format-scanline-pad: ",0
    _t16: dc.b 10,"min-keycode: ",0
    _t17: dc.b 10,"max-keykode: ",0
    _t18: dc.b 10,"vendor: ",0
    _t19: dc.b 10,10,"Format ",0
    _t20: dc.b 10," depth: ",0
    _t21: dc.b 10," bits-per-pixel: ",0
    _t22: dc.b 10," scanline-pad: ",0
    _t23: dc.b 10,10,"SCREEN ",0
    _t24: dc.b 10," root: ",0
    _t25: dc.b 10," default-colormap: ",0
    _t26: dc.b 10," white-pixel: ",0
    _t27: dc.b 10," black-pixel: ",0
    _t28: dc.b 10," current-input-mask: ",0
    _t29: dc.b 10," width-in-pixel: ",0
    _t30: dc.b 10," hight-in-pixel: ",0
    _t31: dc.b 10," width-in-millimeters: ",0
    _t32: dc.b 10," hight-in-millimeters: ",0
    _t33: dc.b 10," min-installed-maps: ",0
    _t34: dc.b 10," max-installed-maps: ",0
    _t35: dc.b 10," root-visual: ",0
    _t36: dc.b 10," backing-stores: ",0
    _t37: dc.b 10," save-unders: ",0
    _t38: dc.b 10," root-depth ",0
    _t39: dc.b 10," DEPTH ",0
    _t40: dc.b 10," depth: ",0
    _t41: dc.b 10," VISUALTYPE ",0
    _t42: dc.b 10," visual_id: ",0
    _t43: dc.b 10," class: ",0
    _t44: dc.b 10," bits-per-rgb-value: ",0
    _t45: dc.b 10," colormap-entries: ",0
    _t46: dc.b 10," red-mask: ",0
    _t47: dc.b 10," green-mask: ",0
    _t48: dc.b 10," blue-mask: ",0


    dump_buf1:
    movem.l r0-r7,-(sp)
    move.l #buf1,r5
    br.b .db1
    dump_buf:
    movem.l r0-r7,-(sp)
    move.l #buf2,r5
    ..db1: tst.l r0,r0
    beq.b _20
    bsr.l out_lf
    move.l r0,r2
    addq.l #3,r0
    lsr.l #2,r0
    move.l r0,r2
    _10: lea.l -buf2(r5),r0
    bsr.l out_hex_l
    move.b #' ',r0
    bsr.l putc
    move.l (r5),r0
    addq.l #4,r5
    bsr.l out_hex_l
    bsr.l out_lf
    dbf.l r2,_10
    bsr.l out_lf
    _20: movem.l (sp)+,r0-r7
    rts.l

    ; r0 -> hex to stdout
    out_hex_l:
    ror.l #16,r0
    bsr.l out_hex_w
    ror.l #16,r0
    out_hex_w:
    ror.w #8,r0
    bsr.l out_hex_b
    ror.w #8,r0
    out_hex_b:
    ror.b #4,r0
    bsr.l out_hex_n
    ror.b #4,r0
    out_hex_n:
    move.l r0,-(sp)
    andq.l #$0f,r0
    cmp.b #9,r0
    bls.b _10
    add.b #'a'-'0'-10,r0
    _10: add.b #'0',r0
    bsr.l putc
    move.l (sp)+,r0
    rts.l

    out_lf: move.l r0,-(sp)
    move.b #10,r0
    bsr.l putc
    move.l (sp)+,r0
    rts.l

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; r0: pointer to NULL terminated string
    puts: movem.l r0-r7,-(sp)
    move.l r0,r1
    br.b _20
    _30: bsr.l putc
    _20: move.b (r1),r0
    inc.l r1
    tst.b r0,r0
    bne.b _30
    movem.l (sp)+,r0-r7
    rts.l

    ; r0: pointer string r1: length of string
    putt: movem.l r0-r7,-(sp)
    move.l r0,r2
    br.b _20
    _30: bsr.l putc
    _20: move.b (r2),r0
    inc.l r2
    dec.l r1
    bpl.b _30
    movem.l (sp)+,r0-r7
    rts.l
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; next char from stdin -> r0.l
    ; EOF: -1 -> r0.l
    ; error: exit
    getc: movem.l r0-r7,-(sp)
    move.l #0,r3 ; stdin
    move.l #buf,r2
    move.l #1,r1 ; 1 byte
    move.l #3,r0 ; read
    trap #$80
    tst.l r0,r0
    bmi.b _10
    movem.l (sp)+,r0-r7
    beq.b _20
    movu.bl buf,r0
    rts.l
    _20: orq.l #-1,r0
    rts.l
    _10: orq.l #-1,r3 ; return code
    move.l #1,r0 ; exit
    trap #$80

    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; r0.b -> stdout
    ; error: exit
    putc: movem.l r0-r7,-(sp)
    move.l #1,r3 ; stdout
    move.l #buf,r2
    move.b r0,(r2)
    move.l #1,r1 ; 1 byte
    move.l #4,r0 ; write
    trap #$80
    cmpq.l #1,r0
    bne.b _10
    movem.l (sp)+,r0-r7
    rts.l
    _10: orq.l #-1,r3 ; return code
    move.l #1,r0 ; exit
    trap #$80

    ENDIF

    ;--------------------------- 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 ------------------------------


    ; 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 100 ; x
    dc.w 50 ; y
    dc.w 320 ; with
    dc.w 200 ; higth
    dc.w 10 ; border-width
    dc.w 0 ; class: CopyFromParent
    dc.l 0 ; visual: CopyFromParent
    dc.l 2 ; value-mask: background-pixel
    dc.l $0080ff ; light blue
    send2l=@-send2

    ; 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; 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 ; hight
    dc.w 0 ; dest-x
    dc.w 0 ; dest-y
    dc.b 0 ; left-pad
    dc.b 24 ; depth
    dc.w 0 ; unused
    screen: blk.l 320*200 ; bitmap
    send5l=@-send5

    ;--------------------------- uninitialized data ----------------------------
    connect_length: blk.l 1
    annie1: blk.l 1
    color: blk.l 64
    buf: blk.b 4
    fname: blk.b 256+32
    buf1: blk.b 64 ; must preceed buf2 !!
    buf2: blk.b 1024
    buf2l=@-buf2

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

    data_filez=@@-data_offset
    data_memsz= @-data_addr

    ;================================================= ==========================

  2. Re: Direct connect to the X server

    Herbert Kleebauer writes:

    > I have done some experiments with graphics output to the X server
    > in Linux/KDE using assembler code. After connecting to the server
    > with unix domain sockets I use CreateWindow to create a window.
    > The window is created with the given size, but the given position
    > and border width is ignored. It is also not a simple window as I
    > would have expected, but has a title bar with the minimize,
    > maximize and close button. I don't know why this happens, maybe
    > KDE intercepts my connection to the X server and modifies my requests?
    > If so, what can I do to directly connect to the X server?


    Yes, the KDE window manager is doing it's job as it is supposed to.
    If you don't want the window manager involved, set "override redirect".

    > Here the Linux binary of the demo program:


    Yes, but why?

  3. Re: Direct connect to the X server

    Dan Espen wrote:
    > Herbert Kleebauer writes:
    >
    > > I have done some experiments with graphics output to the X server
    > > in Linux/KDE using assembler code. After connecting to the server
    > > with unix domain sockets I use CreateWindow to create a window.
    > > The window is created with the given size, but the given position
    > > and border width is ignored. It is also not a simple window as I
    > > would have expected, but has a title bar with the minimize,
    > > maximize and close button. I don't know why this happens, maybe
    > > KDE intercepts my connection to the X server and modifies my requests?
    > > If so, what can I do to directly connect to the X server?

    >
    > Yes, the KDE window manager is doing it's job as it is supposed to.
    > If you don't want the window manager involved, set "override redirect".


    Many thanks. I really lost interrest in X when something always
    modified my requests. Now it works.

    > > Here the Linux binary of the demo program:

    >
    > Yes, but why?


    I would have been happy if I had some code to start with. There
    is very few documentation for a communication at that low level.
    And all I was told was: use a graphics tool kit or at least xlib.
    Maybe it's useful for somebody who also wants to directly communicate
    with the X server at the lowest level.

+ Reply to Thread