format PE GUI 4.0
entry Start
 include 'c:\fasmw17316\include\Win32a.inc'
 include 'fasmAPI\if.inc'
 include 'macro\macro.txt'
 include 'macro\madmat32.txt'
section '.code' code readable writeable executable
                align 16
                txtFind db 'We 9not played We'
                txtRng  db 'aazzAAZZ0099AAZZ'
                skobnet db 0
                tx db ',.?:! dGeomSetPosition (&box,1);',0
                txt db ' dGeomSetPosition (box,p[0],11,22,&p[1],p[2],&dat1,dat2);',0
macro FindAnySymbol t { local .1,.2,.3
      xor cl,cl

      mov al,[t]
      mov ah,al
      sub ah,"a"
      cmp ah,"z"-"a"
      ja  .1
      ;Msg "znak"
      mov cl,1
.1:
      sub al,48
      cmp al,9
      ja  .3
      mov cl,2
      ;Msg "num"
.3:   test cl,cl
      }
macro Ifznk znk,mm,rr=edx { local .1
      cmp byte [rr],znk
      jnz .1
      mm
.1:
      }
macro formatP lb { mov dword [ecx],'    '
                add ecx,4
                inc edx
                cmp byte [edx],'&'
                jz  lb
                ;mov byte [ecx],'='
                mov dword [esi],ecx
                add esi,4
                jmp lb
      }
macro formatPoint lb { mov byte [ecx],'.'
                       inc ecx
                       inc edx
                       jmp lb
      }
Start:

        ;vimm = 0100b ;0x4
        ;movups xmm1,dqword [txtRng]
        ;pcmpistri xmm1,xmm2,vimm   ;ne mozet v 256 ymm1 iskat ! Only xmm 128 bit
        call repFind
        mov edx,txt;-1

        mov ebx,outTxt+6
        mov dword [ebx-6],'ode_'
        mov word  [ebx-2],' ,'
.back:  mov al,[edx]
        mov [ebx],al
        inc ebx
        inc edx
        cmp byte [edx],"("
        jnz .back
        mov word [ebx-1],' ,'
        add ebx,2

        mov esi,ptrKu
upp:    inc edx
        cmp byte [edx],0
        jz ennnn
        FindAnySymbol edx
        jz upp
        mov [esi],edx
        mov [esi+4],cl
        add esi,6
upp2:   inc edx
        cmp byte [edx],0
        jz  ennnn
        cmp byte [edx],'('
        jnz enn2
        mov byte [edx],','
        jmp  upp
enn2:
        cmp byte [edx],','
        jnz upp2
        jmp upp
ennnn:
;copy txt
        ;mov ecx,ebx
        ;mov ebx,esi
        ;sub ebx,ptrKu
        ;lea ebx,[esi-ptrKu]
        mov esi,ptrKu
        lea edx,[ebx-1] ;outTxt
.zu:
        mov cl,[esi+4]
        mov eax,[esi]
        test eax,eax
        jz   endinn
        cmp cl,2
        jz  .zu0
        cmp byte [eax-1],'&'
        jnz .zu2
        mov byte [skobnet],1
.zu0:   mov ch,[eax]
        cmp ch,'['
        jnz .zuX
        mov ch,'.'
.zuX:
        cmp ch,','
        jz  @f
        cmp ch,';'
        jz  endinn
        mov [edx],ch
        inc eax
        inc edx
        jmp .zu0
.zu2:   mov byte [edx],'['
        inc edx
        jmp .zu0
@@:     cmp cl,2
        jz  .ziko
        cmp byte [skobnet],1
        jnz  .zikoU
        cmp byte [edx-1],']'
        jnz .ziko
        mov byte [edx-1],' '
        jmp .ziko
.zikoU:
        cmp byte [edx-1],']'
        jz  .ziko
        mov byte [edx],']'
        inc edx
.ziko:  mov byte [edx],','
        inc edx
        mov byte [skobnet],0
        add esi,6
        ;sub ebx,6
        ;jnz .zu
        jmp .zu

        ;sub edx,35
        ;Msg edx
        ;cmp byte [edx-35],')'
        ;jnz @f
        ;mov byte [edx-35],' '
endinn:  mov byte [edx-1],']'
@@:
;fix )
rept 0 {
        mov eax,outTxt
.zio1:  inc eax
        cmp byte [eax],')'
        jnz .zio1
        mov byte [eax],' '
        }
        mov eax,$-Start        ;222 bytes
        Msg  outTxt
        invoke  ExitProcess,0


        mov esi,ptrKu
        CopyDoZnaka txt,outTxt,'('                ;chFrom(edx),chTo(ecx),chZnk. EDX stop na Znk
        cmp byte [edx],'('
        jnz .1
        mov word [ecx],', '
        add ecx,2
        inc edx
            cmp byte [edx],'&'
                jz  .1
                mov dword [esi],ecx
                add esi,4

.1:
        CopyDoZnaka edx,ecx,',',')',';','[' ;,'&'
        test al,al
        jz  .ll
        Ifznk '[',formatPoint .1
        ;Ifznk ',',formatP .1
        ;Ifznk '&',<mov byte [noskob],1>

.rr:    mov word [ecx],' ,'
        add ecx,2
        CopyDoZnaka edx,ecx,',',')',13

        Ifznk 13,<jz .ll>
        Ifznk ')',<jz .ll>
        Ifznk ',',formatP .1
        inc edx
        jmp .1

.ll:
        ;Msg RichTxt+2000 ;'ParseC2Fasm'
        mov word [ecx],0x3e20
        mov word [ecx+2],0x0a0d
        mov dword [ecx+4],0
        add ecx,4
;fix
        cmp word [ecx-5],', '
        jnz @f
        mov byte [ecx-5],' '
;fix all &
        mov edx,ecx
.ii:    dec ecx
        cmp ecx,outTxt
        jbe @f
        cmp byte [ecx],'&'
        jnz .ii
        mov byte [ecx],' '
        mov eax,ecx
.io:    inc eax
        cmp byte [eax],13
        jbe .ii
        cmp word [eax],' ,'
        jnz .io
        cmp byte [eax-1],']'
        jnz .ii
        mov byte [eax-1],' '
        jmp .ii
@@:
;fix ]
rept 0 {
        dec edx
        cmp edx,outTxt
        jbe @f
        cmp byte [edx],']'
        jnz @b
.tn:    dec edx
        cmp byte [edx],','
        jnz .tn
        mov byte [edx+1],'['
        jmp @b
@@:     }
;fix ptrKu
        mov ebx,esi
        sub ebx,ptrKu
        mov esi,ptrKu
.uu:    ;Msg dword [esi]
        mov eax,[esi]
        cmp byte [eax],'0'
        jbe @f
        cmp byte [eax],'9'
        ja @f
        ;mov byte [eax],'-'
        jmp .piko
@@:     mov byte [eax-1],'['
.piko:  add esi,4
        sub ebx,4
        jnz .uu


        Msg     outTxt
        invoke  ExitProcess,0

textFind db 'this'
SizeEcx  dd  $-textFind
text1 db 'from to this(lalal)',0
repFind:
        mov edi, text1
        mov esi,textFind
.1:     mov  ecx,[SizeEcx]
        repe cmpsb
        test ecx,ecx
        jz .2
        cmp byte [edi],0
        jz .3
        mov esi,textFind
        jmp .1

.2:     Msg 'find !'
.3:
        ret
repCopy:
        mov edi, text1
        mov esi,textFind ;outTxt
        mov ecx,4
.0:     mov al,'('
        ;repne scasb   ;edi-text1+1 uznaem kakoi bait texta
.1:     repe cmpsb     ;scasb not mov in al text !
        test ecx,ecx
        jz .2
        mov ecx,4
        mov esi,textFind
        jmp .1

.2:     Msg outTxt
        ret

SECTION '.idata' IMPORT DATA READABLE WRITEABLE

     library  kernel32, 'KERNEL32.DLL',\
              user32,   'USER32.DLL',\
              winmm,    'WINMM.DLL',\
              msvcrt,   'MSVCRT.DLL'

 include 'fasmAPI\kernel32.inc'
 include 'fasmAPI\user32.inc'
 include 'fasmAPI\winmm.inc'
 include 'fasmAPI\msvcrt.inc'

section '.bss' readable writeable
        outTxt  rb      5000000
        ptrKu   rd      10000