From 0f7aa4d5741bd49d2c8450d7543290686dfcf1de Mon Sep 17 00:00:00 2001 From: "Evgeny Grechnikov (Diamond)" Date: Thu, 10 May 2007 12:29:08 +0000 Subject: [PATCH] * popc modified to use function 70 and standard header in function 0 * desktop modified to use function 70 * rsquare (level compression part) modified to use function 70 git-svn-id: svn://kolibrios.org@484 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/games/rsquare/trunk/MACROS.INC | 269 ++++++++ programs/games/rsquare/trunk/RSQUARE.ASM | 711 +++++++++++++++++++++ programs/games/rsquare/trunk/build_en.bat | 4 + programs/games/rsquare/trunk/build_ru.bat | 4 + programs/games/rsquare/trunk/rlevels.bin | Bin 0 -> 4312 bytes programs/network/popc/trunk/popc.asm | 76 +-- programs/system/desktop/trunk/desktop.asm | 108 ++-- programs/system/desktop/trunk/kglobals.inc | 59 ++ programs/system/desktop/trunk/unpacker.inc | 504 +++++++++++++++ 9 files changed, 1641 insertions(+), 94 deletions(-) create mode 100644 programs/games/rsquare/trunk/MACROS.INC create mode 100644 programs/games/rsquare/trunk/RSQUARE.ASM create mode 100644 programs/games/rsquare/trunk/build_en.bat create mode 100644 programs/games/rsquare/trunk/build_ru.bat create mode 100644 programs/games/rsquare/trunk/rlevels.bin create mode 100644 programs/system/desktop/trunk/kglobals.inc create mode 100644 programs/system/desktop/trunk/unpacker.inc diff --git a/programs/games/rsquare/trunk/MACROS.INC b/programs/games/rsquare/trunk/MACROS.INC new file mode 100644 index 0000000000..14185dbfce --- /dev/null +++ b/programs/games/rsquare/trunk/MACROS.INC @@ -0,0 +1,269 @@ +; new application structure +macro meos_app_start + { + use32 + org 0x0 + + db 'MENUET01' + dd 0x01 + dd __start + dd __end + dd __memory + dd __stack + + if used __params & ~defined __params + dd __params + else + dd 0x0 + end if + + dd 0x0 + } +MEOS_APP_START fix meos_app_start + +macro code + { + __start: + } +CODE fix code + +macro data + { + __data: + } +DATA fix data + +macro udata + { + if used __params & ~defined __params + __params: + db 0 + __end: + rb 255 + else + __end: + end if + __udata: + } +UDATA fix udata + +macro meos_app_end + { + align 32 + rb 2048 + __stack: + __memory: + } +MEOS_APP_END fix meos_app_end + + +; macro for defining multiline text data +struc mstr [sstring] + { + forward + local ssize + virtual at 0 + db sstring + ssize = $ + end virtual + dd ssize + db sstring + common + dd -1 + } + + +; strings +macro sz name,[data] { ; from MFAR [mike.dld] + common + if used name + label name + end if + forward + if used name + db data + end if + common + if used name + .size = $-name + end if +} + +macro lsz name,[lng,data] { ; from MFAR [mike.dld] + common + if used name + label name + end if + forward + if (used name)&(lang eq lng) + db data + end if + common + if used name + .size = $-name + end if +} + + + +; easy system call macro +macro mpack dest, hsrc, lsrc +{ + if (hsrc eqtype 0) & (lsrc eqtype 0) + mov dest, (hsrc) shl 16 + lsrc + else + if (hsrc eqtype 0) & (~lsrc eqtype 0) + mov dest, (hsrc) shl 16 + add dest, lsrc + else + mov dest, hsrc + shl dest, 16 + add dest, lsrc + end if + end if +} + +macro __mov reg,a,b { ; mike.dld + if (~a eq)&(~b eq) + mpack reg,a,b + else if (~a eq)&(b eq) + mov reg,a + end if +} + +macro mcall a,b,c,d,e,f { ; mike.dld + __mov eax,a + __mov ebx,b + __mov ecx,c + __mov edx,d + __mov esi,e + __mov edi,f + int 0x40 +} + + + +; optimize the code for size +__regs fix + +macro add arg1,arg2 + { + if (arg2 eqtype 0) + if (arg2) = 1 + inc arg1 + else + add arg1,arg2 + end if + else + add arg1,arg2 + end if + } + +macro sub arg1,arg2 + { + if (arg2 eqtype 0) + if (arg2) = 1 + dec arg1 + else + sub arg1,arg2 + end if + else + sub arg1,arg2 + end if + } + +macro mov arg1,arg2 + { + if (arg1 in __regs) & ((arg2 eqtype 0) | (arg2 eqtype '0')) + if (arg2) = 0 + xor arg1,arg1 + else if (arg2) = 1 + xor arg1,arg1 + inc arg1 + else if (arg2) = -1 + or arg1,-1 + else if (arg2) > -128 & (arg2) < 128 + push arg2 + pop arg1 + else + mov arg1,arg2 + end if + else + mov arg1,arg2 + end if + } + + +macro struct name + { + virtual at 0 + name name + sizeof.#name = $ - name + end virtual + } + +; structures used in MeOS +struc process_information + { + .cpu_usage dd ? ; +0 + .window_stack_position dw ? ; +4 + .window_stack_value dw ? ; +6 + .not_used1 dw ? ; +8 + .process_name rb 12 ; +10 + .memory_start dd ? ; +22 + .used_memory dd ? ; +26 + .PID dd ? ; +30 + .x_start dd ? ; +34 + .y_start dd ? ; +38 + .x_size dd ? ; +42 + .y_size dd ? ; +46 + .slot_state dw ? ; +50 + dw ? ; +52 - reserved + .client_left dd ? ; +54 + .client_top dd ? ; +58 + .client_width dd ? ; +62 + .client_height dd ? ; +66 + .wnd_state db ? ; +70 + rb (1024-71) + } +struct process_information + +struc system_colors + { + .frame dd ? + .grab dd ? + .grab_button dd ? + .grab_button_text dd ? + .grab_text dd ? + .work dd ? + .work_button dd ? + .work_button_text dd ? + .work_text dd ? + .work_graph dd ? + } +struct system_colors + + +; constants + +; events +EV_IDLE = 0 +EV_TIMER = 0 +EV_REDRAW = 1 +EV_KEY = 2 +EV_BUTTON = 3 +EV_EXIT = 4 +EV_BACKGROUND = 5 +EV_MOUSE = 6 +EV_IPC = 7 +EV_STACK = 8 + +; event mask bits for function 40 +EVM_REDRAW = 1b +EVM_KEY = 10b +EVM_BUTTON = 100b +EVM_EXIT = 1000b +EVM_BACKGROUND = 10000b +EVM_MOUSE = 100000b +EVM_IPC = 1000000b +EVM_STACK = 10000000b \ No newline at end of file diff --git a/programs/games/rsquare/trunk/RSQUARE.ASM b/programs/games/rsquare/trunk/RSQUARE.ASM new file mode 100644 index 0000000000..63c1cfe399 --- /dev/null +++ b/programs/games/rsquare/trunk/RSQUARE.ASM @@ -0,0 +1,711 @@ +LEVELCONV equ 10 +SQ equ 8 +FLDSIZE equ 49 +FLDSIZE2 equ FLDSIZE*8 +DELAY equ 20 +TICKS equ 10 +LEV_START equ 1 +MOBILITY equ 9;13 + + use32 + org 0x0 + + db 'MENUET01' ; 8 byte id + dd 0x01 ; header version + dd run ; start of code + dd I_END ; size of image + dd stak+0x400 ; memory for app + dd stak+0x400 ; esp + dd 0x0 , 0x0 ; I_Param , I_Icon +include "lang.inc" +include "MACROS.INC" +;include "DEBUG.INC" + +run: +if LEVELCONV eq 1 + call compress_levels + jmp close +end if + mcall 3 + mov cl,16 + ror eax,cl + mov [generator],eax ; random generator from Tetris +reset: + mov [levptr],level + mov [levnum],LEV_START + if ~ LEV_START eq 1 + mov ecx,[levnum] + dec ecx + mov esi,[levptr] + jecxz start + .lp: + movzx eax,word[esi] + and eax,0x7fff + add esi,eax ; limit + loop .lp + mov [levptr],esi +; sub esi,level +; dpd esi + end if +start: + mov ecx,[generator] + and ecx,0xff + .shuf: + call random + loop .shuf + xor eax,eax + and [locked],eax + and [captured],eax + mov [ticks],TICKS + mov [mode],-1 + mov ebx,FLDSIZE + mov eax,[generator] + xor edx,edx + div ebx + mov cl,dl + call random + mov eax,[generator] + xor edx,edx + div ebx + mov ch,dl + xchg eax,ecx + movzx ecx,al + imul cx,bx + shr ax,8 + add cx,ax + mov esi,[levptr] + mov [dot],ecx + call decompress_level + mov ebx,8 + call nokey +red: + call draw_window +; and [event],0 + +still: + + .flush: + mcall 2 + test al,al + jz .flush + + mov ebx,DELAY + mov eax,[levnum] + shr eax,1 + sub ebx,eax + mov eax,23 + cmp [mode],0 + jl .wait + mov eax,10 + .wait: + mcall + .evt: + mov ebx,8 + test eax,eax + jne .ev_yes + dec [ticks] + jne still +; mov [ticks],TICKS +; cmp al,[event] + jmp key.ex +; and [event],al +; jmp still + .ev_yes: + cmp eax,2 + je key + cmp eax,1 ; redraw request ? + je red + cmp eax,3 ; button in buffer ? + je button +key: +; mov [event],al + mcall 2 + cmp ah,13 + je button.mode + cmp ah,27 + je button.mode + cmp [mode],-1 + jne still + cmp ah,104 + jne .nohelp + mov [mode],4 + jmp red + .nohelp: + cmp ah,112 + jne .nopau + mov [mode],3 + jmp red + .nopau: + shr eax,8 +; dpd eax + cmp eax,' ' + je .ex + cmp eax,176 + jb still + cmp eax,179 + ja still + cmp [locked],0 + jnz still + lea ebx,[eax-176] + .ex: + mov [ticks],TICKS + call nokey + call evolution + call red_field + jmp still + +button: ; BUTTON - only close supported + mcall 17 + cmp ah,2 + jne close + mcall 8,,,2+1 shl 31 +; mov [event],2 + .mode: + mov [ticks],TICKS + mov al,[mode] + cmp al,1 + je reset + cmp al,2 + je reset + mov [mode],-1 + test al,al + jnz .no0 + inc [levnum] + jmp start + .no0: + jmp red + close: + or eax,-1 + int 0x40 + +; ********************************************* +; ******* WINDOW DEFINITIONS AND DRAW ******** +; ********************************************* +draw_window: + mov [ticks],TICKS + mcall 12,1 + mcall 0,<100,FLDSIZE2+16>,<100,FLDSIZE2+38>,0x03008000 + mcall 4,<8,8>,0x10ffffff,header,header.size + mov esi,ecx + if lang eq ru + mcall 47,0x20000,[levnum],<165,8> + else + mcall 47,0x20000,[levnum],<145,8> + end if + call red_field + cmp [mode],0 + jl .edraw + mov ecx,(FLDSIZE2-20) shl 16+20 + cmp [mode],4 + jne .nohelp + mov ecx,100 shl 16+FLDSIZE2-35-100+38 + .nohelp: + mcall 13,<5+8,FLDSIZE2-8>,,0xf5deb3;0xffff00 + mcall 8,,,2,0xc0c000 + mcall 4,<363,FLDSIZE2-20+6>,0x100000ff,msg_ok,2 + mov ebx,(5+8+35)shl 16+FLDSIZE2-20+6 + movzx ecx,[mode] + mov edx,messages+4 + cmp ecx,4 + jne .nxt + mov edx,desc+4 + xor ecx,ecx + mov ebx,20 shl 16+110 + .nxt: + mov esi,[edx-4] + jecxz .drw + dec ecx + lea edx,[edx+esi+4] + jmp .nxt + .drw: + cmp esi,-1 + je .edraw + mcall ,,0x000000ff + mov ecx,1 + add ebx,18 + cmp [mode],4 + je .nxt + .edraw: + mcall 12,2 + ret + +red_field: + mov edi,field + mov ebp,28 shl 16+SQ ; y + mov ecx,FLDSIZE + .lp1: + push ecx + mov ecx,FLDSIZE + mov ebx,8 shl 16+SQ ; x + .lp2: + push ecx + mov edx,0x8000 + cmp byte[edi],0 + je .zero + cmp byte[edi],2 + jne .nored + mov edx,0xff0000 + cmp [locked],0 + jz .zero + mov edx,0xa00000 + jmp .zero + .nored: + mov edx,0 + .zero: + mcall 13,,ebp + inc edi + pop ecx + add ebx,8 shl 16 + loop .lp2 + pop ecx + add ebp,8 shl 16 + loop .lp1 + + mov eax,[dot] + mov cl,FLDSIZE + div cl + +; movzx ebx,ah +; shl ebx,19 +; add ebx,8 shl 16+7 +; movzx ecx,al +; shl ecx,19 +; add ecx,28 shl 16+7 +; push eax +; mcall 13,,,0xff +; pop eax + + movzx ebx,ah + shl ebx,19 + add ebx,8 shl 16 + shld edx,ebx,16 + add dx,SQ-1 + mov bx,dx + movzx ecx,al + shl ecx,19 + add ecx,28 shl 16 + shld edx,ecx,16 + add dx,SQ-1 + mov cx,dx + mcall 38,,,0xffffff + ror ecx,16 + mcall + ret + +nokey: + xor eax,eax + mov edi,buff + mov ecx,FLDSIZE*FLDSIZE+3 + push ecx edi + rep stosb + pop edi + ;mov esi,field + mov edi,field + mov edx,FLDSIZE + pop ecx + .llp: + mov eax,2 + repne scasb + jecxz .exx + and byte[edi-1],0 + push ecx + lea eax,[edi-field-1] + div dl + call get_cell + mov byte[buff+ecx],2 + pop ecx + loop .llp + .exx: + mov edi,field + mov esi,buff + mov ecx,FLDSIZE*FLDSIZE + .lp4: + lodsb + cmp al,2 + jne .skip3 + mov [edi],al + .skip3: + inc edi + loop .lp4 + + ret + +get_cell: +; ax - source cell [x][y] +; ebx - direction +; 4 2 5 +; 0 . 3 +; 6 1 7 +; out - ecx cell ptr + + push eax ebx + add ax,[ebx*2+dirs] + mov ebx,FLDSIZE + .c0: + cmp al,bl + jb .c1 + sub al,bl + jmp .c0 + .c1: + cmp ah,bl + jb .c2 + sub ah,bl + jmp .c1 + .c2: + movzx ecx,al + imul cx,bx + shr ax,8 + add cx,ax + pop ebx eax + ret + +evolution: + xor edi,edi + and [locked],edi + mov edx,FLDSIZE + mov ecx,FLDSIZE*FLDSIZE + .l1: + push ecx + mov eax,edi + div dl + mov ecx,8 + xor ebx,ebx + mov word[neib],bx ; neighbour count + .l2: + push ecx + call get_cell + movzx esi,byte[field+ecx] + test esi,esi ; 0? + jz .skip2 + inc byte[neib-1+esi] + .skip2: + inc ebx + pop ecx + loop .l2 + mov cl,[neib] + add cl,[neib+1] + cmp cl,2 + jne .no2 + mov al,[field+edi] + jmp .writebuf + .no2: + xor al,al + cmp cl,3 + jne .writebuf + inc al + mov cl,[neib+1] + cmp cl,[neib] + jb .writebuf + inc al + .writebuf: + mov [buff+edi],al + pop ecx + inc edi + loop .l1 + + mov esi,buff + mov edi,field + mov ecx,FLDSIZE*FLDSIZE + rep movsb + call square_check + call dot_move + ret + +square_check: + mov ecx,FLDSIZE*FLDSIZE+3 + mov edx,FLDSIZE + mov edi,field + xor eax,eax + pusha + and dword[cells],eax + and [locked],eax + .nored: + mov al,[edi] + inc edi + dec ecx + jecxz .ex1 + test al,al + jz .nored + inc [cells-2+eax*2] + jmp .nored + .ex1: + mov ax,[cells+2] + cmp ax,[cells] + ja dot_move.next_lev + cmp [cells+2],4 + je .sq_check + add esp,32 + cmp [cells+2],0 + jne .loc + mov [mode],1 + mov dword[esp+4],red + .loc: + inc [locked] + ret + .sq_check: + popa + .nored2: + mov eax,2 + repne scasb + jecxz .loc + lea eax,[edi-field-1] + div dl + xor dh,dh + push ecx + mov ebx,1 + call get_cell + add dh,[field+ecx] + mov ebx,3 + call get_cell + add dh,[field+ecx] + mov ebx,7 + call get_cell + add dh,[field+ecx] + pop ecx + cmp dh,6 + jne .nored2 + ret + +random: + mov eax, [generator] + sub eax,0x43ab45b5 ; next random number + ror eax,1 + xor eax,0x32c4324f + ror eax,1 + mov [generator],eax + ret + +dot_move: + call random + mov eax,[generator] + xor edx,edx + mov ebx,MOBILITY + div ebx + cmp edx,8 + jb .nostay + mov edx,16 + .nostay: + mov ebx,edx + shr ebx,1 + mov eax,[dot] +; dpd eax + mov cl,FLDSIZE + div cl + call get_cell + mov [dot],ecx + cmp byte[field+ecx],2 + jne .nocap + inc [captured] + cmp [captured],2 + jne .ex + .next_lev: + mov [mode],0 + pop eax + mov eax,[levptr] + cmp word[eax],0 + jne .nxt + mov [mode],2 + .nxt: + mov dword[esp],red + ret + .nocap: + and [captured],0 + .ex: + ret + +if LEVELCONV eq 1 +fileinfo: + + dd 2 + dd 0x0 + dd 0x0 +.fsize dd 10000 +.ptr dd 0x20000 + db '/RD/1/newlev.bin',0 + +macro flush +{ + mov [edi],dh + inc edi +} + +compress_levels: + mov esi,raw_level + mov edi,I_END + mov [fileinfo.ptr],edi + mov ecx,(raw_level_size-raw_level)/(FLDSIZE*FLDSIZE*4) ; 19 + .lp1: + push ecx + mov ecx,FLDSIZE*FLDSIZE + mov ebx,edi + mov eax,[esi] +; movzx eax,byte[esi] + movzx edx,al + dpd edx + shl eax,15 + stosw + .lp2: + lodsd ;lodsb + cmp al,0xd + jne .nored + flush + xor al,al + stosb + add esi,4 + dec ecx + xor dh,dh + jmp .eloop + .nored: + cmp al,dl + jne .change + inc dh + cmp dh,0xff + jb .eloop + flush + xor dh,dh + jmp .eloop + .change: + flush + xor dl,1 + mov dh,1 + .eloop: + loop .lp2 + flush + mov eax,edi + sub eax,ebx + add [ebx],ax + pop ecx + loop .lp1 + xor eax,eax + stosw + sub edi,I_END + mov [fileinfo.fsize],edi + mcall 70,fileinfo + ret + +raw_level: + file 'noname1.dat' +raw_level_size: + +end if + +decompress_level: +; esi - level begin + mov edi,field + movzx edx,word[esi] + xor ecx,ecx + mov eax,edx + and edx,0x7fff + add edx,esi ; limit + mov [levptr],edx + add esi,2 + shr eax,15 + .next: + cmp esi,edx + jae .exloop + movzx ebx,byte[esi] + inc esi + test ebx,ebx + jne .nored + rep stosb + xor al,1 + mov word[edi],0x0202 + add edi,2 + jmp .next + .nored: + add ecx,ebx + cmp ebx,0xff + je .next + rep stosb + xor al,1 + jmp .next + .exloop: + rep stosb + ret + +; DATA AREA + +FS1 equ (FLDSIZE-1) +dirs dw FS1 shl 8,\ + 1,\ + FS1,\ + 1 shl 8,\ + FS1 shl 8+FS1,\ + 1 shl 8+FS1,\ + FS1 shl 8+1,\ + 1 shl 8+1,\ + 0 +level: +file 'rlevels.bin' + +msg_ok db 'OK' +if lang eq ru +header db 'Red Square - Уровень h - Помощь, p - Пауза' + .size = $ - header +messages mstr 'Отлично! Вы переходите на следующий уровень.',\ + 'Красные клетки уничтожены. Вы проиграли.',\ + 'Вы прошли все уровни. Поздравляем!',\ + 'Игра приостановлена...' + +desc mstr ' Вы играете красным квадратиком. Цель игры - выжить среди',\ + 'развивающихся черных клеток. Если Вам удастся поймать белый',\ + 'крестик, Вы пройдете уровень.',\ + ' Чтобы поймать белый крестик, он должен быть накрыт одной',\ + 'из красных клеток на протяжении 2 поколений подряд.',\ + ' Если красный квадрат разрушен, это еще не проигрыш. Может',\ + 'быть, Вам повезет и если в процессе эволюции количество Ваших',\ + 'красных клеток станет больше, чем черных, уровень будет',\ + "пройден.",\ + '---',\ + 'Джон Хортон Конуэй изобрел прекрасную игру. Почти каждый',\ + 'программист начинает свою практику с нее. Однако реальные',\ + 'возможности этой игры еще плохо изучены.',\ + '---',\ + 'Оригинал игры под Win32 написал Владимир Привалов, 2002',\ + 'Запрограммировал на ассемблере Willow, 2005' +else +header db 'Red Square - Level h - Help, p - Pause' + .size = $ - header +messages mstr 'Well done! You are on the next level',\ + 'Your red cells are vanished! Game over.',\ + "You've completed the game. Congratulations!",\ + 'Game paused...' + +desc mstr ' The main goal of the game for your red square is to stay',\ + 'alive going through the evolving black cells. If you manage to',\ + 'catch the white cross, you will pass the level.',\ + ' To catch the white cross, it must be covered by red cell',\ + 'during 2 generations.',\ + " If your red square is corrupted, you haven't lost yet. You",\ + 'may have a luck, and if your red cells is developing and the',\ + 'quantity of black cells is bigger than that of black cells,',\ + "you'll pass the level.",\ + '---',\ + 'John Horton Conway has created a great game. Almost every',\ + 'programmer begins his professional work from it. But the real',\ + 'possibilities of this game have not discovered yet.',\ + '---',\ + 'Original game under Win32 by Vladimir Privalov, 2002',\ + 'Programmed in assembly by Willow, 2005' +end if +I_END: +neib db ?,? +cells dw ?,? +mode db ? +levptr dd ? +levnum dd ? +reds dd ? +locked dd ? +generator dd ? +dot dd ? +ticks dd ? +captured dd ? +if LEVELCONV eq 1 + os_work rb 4096 +end if +field: + rb FLDSIZE*FLDSIZE +rd 1 +buff: + rb FLDSIZE*FLDSIZE +stak: diff --git a/programs/games/rsquare/trunk/build_en.bat b/programs/games/rsquare/trunk/build_en.bat new file mode 100644 index 0000000000..28d7c890c7 --- /dev/null +++ b/programs/games/rsquare/trunk/build_en.bat @@ -0,0 +1,4 @@ +@echo lang fix en >lang.inc +@fasm 3dcube2.asm 3dcube2 +@erase lang.inc +@pause \ No newline at end of file diff --git a/programs/games/rsquare/trunk/build_ru.bat b/programs/games/rsquare/trunk/build_ru.bat new file mode 100644 index 0000000000..b02414d688 --- /dev/null +++ b/programs/games/rsquare/trunk/build_ru.bat @@ -0,0 +1,4 @@ +@echo lang fix ru >lang.inc +@fasm 3dcube2.asm 3dcube2 +@erase lang.inc +@pause \ No newline at end of file diff --git a/programs/games/rsquare/trunk/rlevels.bin b/programs/games/rsquare/trunk/rlevels.bin new file mode 100644 index 0000000000000000000000000000000000000000..5fe1caa6bfa2a2abe0ecf6e39ab4c71db178823a GIT binary patch literal 4312 zcmeI0IgcDw5P-Yt^)b^u$L@}I*L!()#_VBxFIyOp5mx|4B1M*f00=mQ5Dx6X2pK_! z1VSP~APym95+p{s_tpen#dAz#I)X3Rj*#Xy1IIT{3VGT zr>S&gNrI?$=nI~}(~)HniJ4h1j7qQdm^l=Pf~Tn(noir!v7)m*<0l6mps_ZF*;qav z@4)o14CpiItButPN+&gOOn|^aLDJa9S`eQZ8{j;ZxMQqA1)c_vCGmrUCQ^P9?L}pI z`m3ls8MkCp#?2VpK_aVuFt@Us$s({xnU_M`99(`FO#W?e`;yfxxU92M$;X>vWH9f2 zdxLTLD~!6bi~0alyvZHwzU+qbqRIXJ{m~`e?25<1V;v z`0V^2uWjqm_g0iD&H{78n8sx9B0^t16ZS2bc#e4YZ{{({ENyc57m?j0d8FFIW%#W(O6R% z;O8}kHvF%nR9P5PX)Wahh01D$Rli%qdEKCj2K<~8=;R~wwDPeFwW}?=d(7c1D{8K` zuQ%#y2j~eE+*DWKHzylWTh^m2RA-$3Gx~{qU_q16Zt;FsQk{{W9sy#y?fYmQDbS5M zuYJ!Tg)Wjv=Ap2Bk|Qoex}d#gM~=tL`)Y;%FV@7Sg$~ErNAqTHS#xarksPM5m^yg2bcjDBa z9=5i;G;TA}_Gh{t%V%oB{sfT`_iBQ{nDD*-n&UgT#J88Cm)sS8l};FPg^mol>g%Xx zHndn5=(Yed4=fM7s6rcP4%~2U&84G-TyflNgP8+X=;u(6oNmPW4cTSBr}vmAKE5qy zCL;A#nZ`I>vn@&v+GTVDF~^np6~3O56^t||xegpkHrGSEYl7y!ZeipN%-7aw+XOV2 z+39m%XWV05XOS&+FCmD*RsLeMl>i-R?er?{V%MA!O5sK}nBdYp25nfjWB@h4XGT#3bMCx&lkedpZltZ569?m-T! zQ}v$z&uw&bQ}k@PbJG6fIWMyVzjrOncYch%bm*q{1DtL^Nij=!rljW(1p?m+uBrgB zT)Jlk07)gKj!FqscVeo=97PP&6m$;A)9-)7dwoj(qazLidt9~siKzN&p3&j zam=)?b6ay!bD%bFEK6@WcXP>s^0xGyH$oSqDbt^gea2;5g1=m*b7 z=Lp7>VyI;{XS73NDue{;ul5Nr{Rq-B3)pxvNv&gd-c;6u}$l*FJ=j12_xu77pFs7)T z*E?#yg?nnWN*|((BBcOUfF-~94$))gxKymBrxgN6c!Qxm=4a90B6E|_#`=?mJ1t`d z+a+3FiSxJ}Pa~|wVT(3P6n5BZefQU>e4o$1b*Hv)8L=~y5tq*}L-3>rZy5$tf&JEi zS>d;qCfN}R>VU;LN!P5eNaz)j?c3AJAtBsF;wPB-_kUmAu!R)0mTA#n&JdW}aeiOI8WAGe9+__w0yAEpw|e*gdg literal 0 HcmV?d00001 diff --git a/programs/network/popc/trunk/popc.asm b/programs/network/popc/trunk/popc.asm index 70a7684d89..31840d7094 100644 --- a/programs/network/popc/trunk/popc.asm +++ b/programs/network/popc/trunk/popc.asm @@ -10,7 +10,6 @@ ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -include 'lang.inc' version equ '0.1' use32 @@ -29,18 +28,21 @@ START: ; start of execution mov [file_start],0x100000 - mov eax,58 + mov eax,70 mov ebx,filel int 0x40 - cmp eax,0 - jne notfound + test eax,eax + jz @f + cmp eax,6 + jnz notfound +@@: add [file_start],ebx notfound: mov edi,I_END mov ecx,60*120 - mov eax,32 + mov al,32 cld rep stosb @@ -98,14 +100,12 @@ save_file: pusha - mov edi,[file_start] - + mov ebx,files mov eax,[file_start] sub eax,0x100000 - mov [files+8],eax + mov [ebx+12],eax - mov eax,58 - mov ebx,files + mov eax,70 int 0x40 popa @@ -230,10 +230,9 @@ button: ; button cmp ah,60 jne no_open - mov eax,19 - mov ebx,tp - mov ecx,pr - int 0x40 + mov eax, 70 + mov ebx, tinypad_start + int 0x40 jmp still no_open: @@ -816,21 +815,12 @@ draw_window: mov eax,0 ; draw window mov ebx,5*65536+435 mov ecx,5*65536+232 - mov edx,[wcolor] - add edx,0x03ffffff - mov esi,0x80555599 - mov edi,0x00ffffff + mov edx,0x13ffffff + mov edi,labelt int 0x40 mov [old_status],300 - mov eax,4 ; label - mov ebx,9*65536+8 - mov ecx,0x10ffffff - mov edx,labelt - mov esi,labellen-labelt - int 0x40 - mov eax,8 ; button: open socket mov ebx,23*65536+22 mov ecx,155*65536+10 @@ -838,14 +828,14 @@ draw_window: mov esi,0x44cc44 int 0x40 - mov eax,8 ; button: close socket +; mov eax,8 ; button: close socket mov ebx,295*65536+22 mov ecx,155*65536+10 mov edx,24 mov esi,0xcc4444 int 0x40 - mov eax,8 ; button: text entries +; mov eax,8 ; button: text entries mov ebx,243*65536+8 mov ecx,180*65536+8 mov edx,51 @@ -857,7 +847,7 @@ draw_window: cmp edx,53 jbe newi - mov eax,8 ; open inbox +; mov eax,8 ; open inbox mov ebx,295*65536+102 mov ecx,190*65536+14 mov edx,60 @@ -904,9 +894,9 @@ draw_server_data: mov esi,[rxs] dct: pusha - mov cx,bx + mov ecx,ebx shl ecx,16 - mov cx,9 + mov cl,9 mov eax,13 mov ebx,10*65536 mov bx,word [rxs] @@ -941,16 +931,18 @@ db ' User : < Open popc.txt ' l3_text: db ' Password : (not shown) < ' -db 'x <- END MARKER, DONT DELETE ' +db 'x' ; <- END MARKER, DONT DELETE file_start dd 0x100000 +; max size is 0x100000 bytes, read to/write from 0x100000 files: - dd 1,0,0,0x100000,0xd0000 - db '/rd/1/popc.txt',0 + dd 2,0,0,?,0x100000 + db 0 + dd pr filel: - dd 0,0,10000/512,0x100000,0xd0000 - db '/rd/1/popc.txt',0 + dd 0,0,0,0x100000,0x100000 +pr db '/rd/1/popc.txt',0 ip db 192,168,1,200 @@ -973,14 +965,16 @@ command_position dd 0 counter dd 0 numtext db ' ' -wcolor dd 0x000000 -labelt db 'POP client v ',version -labellen: +labelt db 'POP client v ',version,0 scroll: dd 1,8 -tp: db 'TINYPAD ' -pr: db 'POPC TXT',0 - +tinypad_start: + dd 7 + dd 0 + dd pr + dd 0 + dd 0 + db '/RD/1/TINYPAD',0 getmail: db 'user xyz ',13,10 diff --git a/programs/system/desktop/trunk/desktop.asm b/programs/system/desktop/trunk/desktop.asm index d16d6ff23a..c84c4770bc 100644 --- a/programs/system/desktop/trunk/desktop.asm +++ b/programs/system/desktop/trunk/desktop.asm @@ -15,11 +15,13 @@ dd START ; start address dd I_END ; file size dd 28000h ; memory - dd 28000h ; stack pointer (0x10000+ - work area for os) + dd 10000h ; stack pointer dd 0,0 ; parameters, reserved include 'lang.inc' include 'macros.inc' + include 'kglobals.inc' + include 'unpacker.inc' ;****************************************************************************** @@ -141,16 +143,13 @@ still: mov ebx,1 mov ecx,1 int 0x40 - mov eax,48 - mov ebx,0 - mov ecx,0 - int 0x40 - jmp still + jmp doapply no_3d: cmp ah,15 ; set flat buttons jne no_flat mcall 48, 1, 0 +doapply: mcall 48, 0, 0 jmp still no_flat: @@ -163,10 +162,7 @@ still: mov ecx,color_table mov edx,10*4 int 0x40 - mov eax,48 - mov ebx,0 - mov ecx,0 - int 0x40 + jmp doapply no_apply: cmp ah,17 ; load skin file @@ -275,43 +271,50 @@ draw_cursor: load_file: - pushad - - mov [read_info.mode] ,0 - mov [read_info.start_block],0 - mov [read_info.blocks] ,1 - mov [read_info.address] ,color_table - mov [read_info.workarea] ,0x10000 - mcall 58, read_info - -; call draw_colours - - popad -ret + xor eax, eax + mov ebx, read_info + mov dword [ebx], eax ; subfunction: read + mov dword [ebx+4], eax ; offset (low dword) + mov dword [ebx+8], eax ; offset (high dword) + mov dword [ebx+12], 40 ; read colors file: 4*10 bytes + mov dword [ebx+16], color_table ; address + mcall 70 + ret load_skin_file: - pushad + xor eax, eax + mov ebx, read_info + mov dword [ebx], eax ; subfunction: read + mov dword [ebx+4], eax ; offset (low dword) + mov dword [ebx+8], eax ; offset (high dword) + mov dword [ebx+12], 32*1024 ; read: max 32 KBytes + mov dword [ebx+16], 0x10000 ; address + mcall 70 - mov [read_info.mode] ,0 - mov [read_info.start_block],0 - mov [read_info.blocks] ,64 - mov [read_info.address] ,0x20000 - mov [read_info.workarea] ,0x10000 - mcall 58, read_info + mov esi, 0x10000 - cmp dword[0x20000+SKIN_HEADER.ident],'SKIN' - jne @f + cmp dword [esi], 'KPCK' + jnz notpacked + cmp dword [esi+4], 32*1024 ; max 32 KBytes + ja doret + push 0x20000 + push esi + call unpack + mov esi, 0x20000 +notpacked: + + cmp dword[esi+SKIN_HEADER.ident],'SKIN' + jne doret + + mov edi,0x18000 + mov ecx,0x8000/4 + rep movsd mov esi,fname mov edi,skin_info.fname mov ecx,257 rep movsb - mov esi,0x20000 - mov edi,0x18000 - mov ecx,0x8000/4 - rep movsd - mov ebp,0x18000 mov esi,[ebp+SKIN_HEADER.params] add esi,ebp @@ -319,24 +322,20 @@ load_skin_file: mov edi,color_table mov ecx,10 rep movsd - @@: + doret: - popad ret save_file: - pushad - - mov [write_info.mode] ,1 - mov [write_info.bytes2write],10*4 - mov [write_info.address] ,color_table - mov [write_info.workarea] ,0x10000 - mcall 58, write_info - - popad -ret - + mov ebx, write_info + mov dword [ebx], 2 ; subfunction: write + and dword [ebx+4], 0 ; (reserved) + and dword [ebx+8], 0 ; (reserved) + mov dword [ebx+12], 10*4 ; bytes to write + mov dword [ebx+16], color_table ; address + mcall 70 + ret read_string: @@ -357,7 +356,7 @@ read_string: int 0x40 cmp eax,2 jne read_done - mov eax,2 +; mov eax,2 int 0x40 shr eax,8 cmp eax,13 @@ -381,8 +380,7 @@ read_string: read_done: - mov ecx, fname - add ecx, 88 + mov ecx, fname+88 sub ecx, edi mov eax, 0 cld @@ -1041,8 +1039,12 @@ end if color dd 0 +IncludeIGlobals + I_END: +IncludeUGlobals + read_info: .mode dd ? ; read .start_block dd ? ; first block diff --git a/programs/system/desktop/trunk/kglobals.inc b/programs/system/desktop/trunk/kglobals.inc new file mode 100644 index 0000000000..68276a10c7 --- /dev/null +++ b/programs/system/desktop/trunk/kglobals.inc @@ -0,0 +1,59 @@ +;------------------------------------------------------------------ +; use "iglobal" for inserting initialized global data definitions. +;------------------------------------------------------------------ +macro iglobal { + IGlobals equ IGlobals, + macro __IGlobalBlock { } + +macro iglobal_nested { + IGlobals equ IGlobals, + macro __IGlobalBlock \{ } + +;------------------------------------------------------------- +; use 'uglobal' for inserting uninitialized global definitions. +; even when you define some data values, these variables +; will be stored as uninitialized data. +;------------------------------------------------------------- +macro uglobal { + UGlobals equ UGlobals, + macro __UGlobalBlock { } + +macro uglobal_nested { + UGlobals equ UGlobals, + macro __UGlobalBlock \{ } + +endg fix } ; Use endg for ending iglobal and uglobal blocks. +endg_nested fix \} + +macro IncludeIGlobals{ + macro IGlobals dummy,[n] \{ __IGlobalBlock + purge __IGlobalBlock \} + match I, IGlobals \{ I \} } + + +macro IncludeUGlobals{ + macro UGlobals dummy,[n] \{ + \common + \local begin, size + begin = $ + virtual at $ + \forward + __UGlobalBlock + purge __UGlobalBlock + \common + size = $ - begin + end virtual + rb size + \} + match U, UGlobals \{ U \} } + +macro IncludeAllGlobals { + IncludeIGlobals + IncludeUGlobals +} + +iglobal +endg + +uglobal +endg diff --git a/programs/system/desktop/trunk/unpacker.inc b/programs/system/desktop/trunk/unpacker.inc new file mode 100644 index 0000000000..044ad697cf --- /dev/null +++ b/programs/system/desktop/trunk/unpacker.inc @@ -0,0 +1,504 @@ +; void __stdcall unpack(void* packed_data, void* unpacked_data); +unpack: + pushad + mov esi, [esp+32+4] + mov edi, [esp+32+8] + mov eax, [esi+8] + and al, 0xC0 + cmp al, 0xC0 + jz .failed + mov eax, [esi+8] + push eax + add esi, 12 + and al, not 0xC0 + dec eax + jz .lzma +.failed: + pop eax + popad + ret 8 +.lzma: + call .lzma_unpack +.common: + pop eax + test al, 0x80 + jnz .ctr1 + test al, 0x40 + jz .ok + lodsd + mov ecx, eax + jecxz .ok + mov dl, [esi] + mov esi, [esp+32+8] +.c1: + lodsb + sub al, 0E8h + cmp al, 1 + ja .c1 + cmp byte [esi], dl + jnz .c1 + lodsd +; "bswap eax" is not supported on i386 + shr ax, 8 + ror eax, 16 + xchg al, ah + sub eax, esi + add eax, [esp+32+8] + mov [esi-4], eax + loop .c1 +.ok: + popad + ret 8 +.ctr1: + lodsd + mov ecx, eax + jecxz .ok + mov dl, [esi] + mov esi, [esp+32+8] +.c2: + lodsb +@@: + cmp al, 0xF + jnz .f + lodsb + cmp al, 80h + jb @b + cmp al, 90h + jb @f +.f: + sub al, 0E8h + cmp al, 1 + ja .c2 +@@: + cmp byte [esi], dl + jnz .c2 + lodsd + shr ax, 8 + ror eax, 16 + xchg al, ah + sub eax, esi + add eax, [esp+32+8] + mov [esi-4], eax + loop .c2 + jmp .ok + +.lzma_unpack: + +.pb = 2 ; pos state bits +.lp = 0 ; literal pos state bits +.lc = 3 ; literal context bits +.posStateMask = ((1 shl .pb)-1) +.literalPosMask = ((1 shl .lp)-1) + +.kNumPosBitsMax = 4 +.kNumPosStatesMax = (1 shl .kNumPosBitsMax) + +.kLenNumLowBits = 3 +.kLenNumLowSymbols = (1 shl .kLenNumLowBits) +.kLenNumMidBits = 3 +.kLenNumMidSymbols = (1 shl .kLenNumMidBits) +.kLenNumHighBits = 8 +.kLenNumHighSymbols = (1 shl .kLenNumHighBits) + +.LenChoice = 0 +.LenChoice2 = 1 +.LenLow = 2 +.LenMid = (.LenLow + (.kNumPosStatesMax shl .kLenNumLowBits)) +.LenHigh = (.LenMid + (.kNumPosStatesMax shl .kLenNumMidBits)) +.kNumLenProbs = (.LenHigh + .kLenNumHighSymbols) + +.kNumStates = 12 +.kNumLitStates = 7 +.kStartPosModelIndex = 4 +.kEndPosModelIndex = 14 +.kNumFullDistances = (1 shl (.kEndPosModelIndex/2)) +.kNumPosSlotBits = 6 +.kNumLenToPosStates = 4 +.kNumAlignBits = 4 +.kAlignTableSize = (1 shl .kNumAlignBits) +.kMatchMinLen = 2 + +.IsMatch = 0 +.IsRep = (.IsMatch + (.kNumStates shl .kNumPosBitsMax)) +.IsRepG0 = (.IsRep + .kNumStates) +.IsRepG1 = (.IsRepG0 + .kNumStates) +.IsRepG2 = (.IsRepG1 + .kNumStates) +.IsRep0Long = (.IsRepG2 + .kNumStates) +.PosSlot = (.IsRep0Long + (.kNumStates shl .kNumPosBitsMax)) +.SpecPos = (.PosSlot + (.kNumLenToPosStates shl .kNumPosSlotBits)) +.Align_ = (.SpecPos + .kNumFullDistances - .kEndPosModelIndex) +.Lencoder = (.Align_ + .kAlignTableSize) +.RepLencoder = (.Lencoder + .kNumLenProbs) +.Literal = (.RepLencoder + .kNumLenProbs) + +.LZMA_BASE_SIZE = 1846 ; must be ==Literal +.LZMA_LIT_SIZE = 768 + +.kNumTopBits = 24 +.kTopValue = (1 shl .kNumTopBits) + +.kNumBitModelTotalBits = 11 +.kBitModelTotal = (1 shl .kNumBitModelTotalBits) +.kNumMoveBits = 5 + + push edi +; int state=0; + xor ebx, ebx + mov [.previousByte], bl +; unsigned rep0=1,rep1=1,rep2=1,rep3=1; + mov eax, 1 + mov edi, .rep0 + stosd + stosd + stosd + stosd +; int len=0; +; result=0; + mov ecx, .Literal + (.LZMA_LIT_SIZE shl (.lc+.lp)) + mov eax, .kBitModelTotal/2 + mov edi, .p + rep stosd +; RangeDecoderInit +; rd->ExtraBytes = 0 +; rd->Buffer = stream +; rd->BufferLim = stream+bufferSize +; rd->Range = 0xFFFFFFFF + pop edi + mov ebp, [esi-8] ; dest_length + add ebp, edi ; ebp = destination limit + lodsd +; rd->code_ = eax + mov [.code_], eax + or [.range], -1 +.main_loop: + cmp edi, ebp + jae .main_loop_done + mov edx, edi + and edx, .posStateMask + mov eax, ebx + shl eax, .kNumPosBitsMax+2 + lea eax, [.p + .IsMatch*4 + eax + edx*4] + call .RangeDecoderBitDecode + jc .1 + movzx eax, [.previousByte] +if .literalPosMask + mov ah, dl + and ah, .literalPosMask +end if + shr eax, 8-.lc + imul eax, .LZMA_LIT_SIZE*4 + add eax, .p+.Literal*4 + cmp ebx, .kNumLitStates + jb .literal + xor edx, edx + sub edx, [.rep0] + mov dl, [edi + edx] + call .LzmaLiteralDecodeMatch + jmp @f +.literal: + call .LzmaLiteralDecode +@@: + mov [.previousByte], al + stosb + mov al, bl + cmp bl, 4 + jb @f + mov al, 3 + cmp bl, 10 + jb @f + mov al, 6 +@@: sub bl, al + jmp .main_loop +.1: + lea eax, [.p + .IsRep*4 + ebx*4] + call .RangeDecoderBitDecode + jnc .10 + lea eax, [.p + .IsRepG0*4 + ebx*4] + call .RangeDecoderBitDecode + jc .111 + mov eax, ebx + shl eax, .kNumPosBitsMax+2 + lea eax, [.p + .IsRep0Long*4 + eax + edx*4] + call .RangeDecoderBitDecode + jc .1101 + cmp bl, 7 + setae bl + lea ebx, [9 + ebx + ebx] + xor edx, edx + sub edx, [.rep0] + mov al, [edi + edx] + stosb + mov [.previousByte], al + jmp .main_loop +.111: + lea eax, [.p + .IsRepG1*4 + ebx*4] + call .RangeDecoderBitDecode + mov eax, [.rep1] + jnc .l3 +.l1: + lea eax, [.p + .IsRepG2*4 + ebx*4] + call .RangeDecoderBitDecode + mov eax, [.rep2] + jnc .l2 + xchg [.rep3], eax +.l2: + push [.rep1] + pop [.rep2] +.l3: + xchg eax, [.rep0] + mov [.rep1], eax +.1101: + mov eax, .p + .RepLencoder*4 + call .LzmaLenDecode + cmp bl, 7 + setc bl + adc bl, bl + xor bl, 3 + add bl, 8 + jmp .repmovsb +.10: + mov eax, [.rep0] + xchg eax, [.rep1] + xchg eax, [.rep2] + xchg eax, [.rep3] + cmp bl, 7 + setc bl + adc bl, bl + xor bl, 3 + add bl, 7 + mov eax, .p + .Lencoder*4 + call .LzmaLenDecode + mov eax, .kNumLenToPosStates-1 + cmp eax, ecx + jb @f + mov eax, ecx +@@: + push ecx + mov ecx, .kNumPosSlotBits + shl eax, cl + shl eax, 2 + add eax, .p+.PosSlot*4 + call .RangeDecoderBitTreeDecode + mov [.rep0], ecx + cmp ecx, .kStartPosModelIndex + jb .l6 + push ecx + mov eax, ecx + and eax, 1 + shr ecx, 1 + or eax, 2 + dec ecx + shl eax, cl + mov [.rep0], eax + pop edx + cmp edx, .kEndPosModelIndex + jae .l5 + sub eax, edx + shl eax, 2 + add eax, .p + (.SpecPos - 1)*4 + call .RangeDecoderReverseBitTreeDecode + add [.rep0], ecx + jmp .l6 +.l5: + sub ecx, .kNumAlignBits + call .RangeDecoderDecodeDirectBits + mov ecx, .kNumAlignBits + shl eax, cl + add [.rep0], eax + mov eax, .p+.Align_*4 + call .RangeDecoderReverseBitTreeDecode + add [.rep0], ecx +.l6: + pop ecx + inc [.rep0] + jz .main_loop_done +.repmovsb: + add ecx, .kMatchMinLen + push esi + mov esi, edi + sub esi, [.rep0] + rep movsb + pop esi + mov al, [edi-1] + mov [.previousByte], al + jmp .main_loop +.main_loop_done: + ret + +.RangeDecoderBitDecode: +; in: eax->prob +; out: CF=bit; destroys eax + push edx + mov edx, [.range] + shr edx, .kNumBitModelTotalBits + imul edx, [eax] + cmp [.code_], edx + jae .ae + mov [.range], edx + mov edx, .kBitModelTotal + sub edx, [eax] + shr edx, .kNumMoveBits + add [eax], edx + clc +.n: + lahf + cmp [.range], .kTopValue + jae @f + shl [.range], 8 + shl [.code_], 8 + lodsb + mov byte [.code_], al +@@: + sahf + pop edx + ret +.ae: + sub [.range], edx + sub [.code_], edx + mov edx, [eax] + shr edx, .kNumMoveBits + sub [eax], edx + stc + jmp .n + +.RangeDecoderDecodeDirectBits: +; in: ecx=numTotalBits +; out: eax=result; destroys edx + xor eax, eax +.l: + shr [.range], 1 + shl eax, 1 + mov edx, [.code_] + sub edx, [.range] + jb @f + mov [.code_], edx + or eax, 1 +@@: + cmp [.range], .kTopValue + jae @f + shl [.range], 8 + shl [.code_], 8 + push eax + lodsb + mov byte [.code_], al + pop eax +@@: + loop .l + ret + +.LzmaLiteralDecode: +; in: eax->probs +; out: al=byte; destroys edx + push ecx + mov ecx, 1 +@@: + push eax + lea eax, [eax+ecx*4] + call .RangeDecoderBitDecode + pop eax + adc cl, cl + jnc @b +.LzmaLiteralDecode.ret: + mov al, cl + pop ecx + ret +.LzmaLiteralDecodeMatch: +; in: eax->probs, dl=matchByte +; out: al=byte; destroys edx + push ecx + mov ecx, 1 +.LzmaLiteralDecodeMatch.1: + add dl, dl + setc ch + push eax + lea eax, [eax+ecx*4+0x100*4] + call .RangeDecoderBitDecode + pop eax + adc cl, cl + jc .LzmaLiteralDecode.ret + xor ch, cl + test ch, 1 + mov ch, 0 + jnz @b + jmp .LzmaLiteralDecodeMatch.1 + +.LzmaLenDecode: +; in: eax->prob, edx=posState +; out: ecx=len + push eax + add eax, .LenChoice*4 + call .RangeDecoderBitDecode + pop eax + jnc .0 + push eax + add eax, .LenChoice2*4 + call .RangeDecoderBitDecode + pop eax + jc @f + mov ecx, .kLenNumMidBits + shl edx, cl + lea eax, [eax + .LenMid*4 + edx*4] + call .RangeDecoderBitTreeDecode + add ecx, .kLenNumLowSymbols + ret +@@: + add eax, .LenHigh*4 + mov ecx, .kLenNumHighBits + call .RangeDecoderBitTreeDecode + add ecx, .kLenNumLowSymbols + .kLenNumMidSymbols + ret +.0: + mov ecx, .kLenNumLowBits + shl edx, cl + lea eax, [eax + .LenLow*4 + edx*4] +.RangeDecoderBitTreeDecode: +; in: eax->probs,ecx=numLevels +; out: ecx=length; destroys edx + push ebx + mov edx, 1 + mov ebx, edx +@@: + push eax + lea eax, [eax+edx*4] + call .RangeDecoderBitDecode + pop eax + adc dl, dl + add bl, bl + loop @b + sub dl, bl + pop ebx + mov ecx, edx + ret +.RangeDecoderReverseBitTreeDecode: +; in: eax->probs,ecx=numLevels +; out: ecx=length; destroys edx + push ebx ecx + mov edx, 1 + xor ebx, ebx +@@: + push eax + lea eax, [eax+edx*4] + call .RangeDecoderBitDecode + lahf + adc edx, edx + sahf + rcr ebx, 1 + pop eax + loop @b + pop ecx + rol ebx, cl + mov ecx, ebx + pop ebx + ret + +uglobal +align 4 +unpack.p rd unpack.LZMA_BASE_SIZE + (unpack.LZMA_LIT_SIZE shl (unpack.lc+unpack.lp)) +unpack.code_ dd ? +unpack.range dd ? +unpack.rep0 dd ? +unpack.rep1 dd ? +unpack.rep2 dd ? +unpack.rep3 dd ? +unpack.previousByte db ? +endg