diff --git a/kernel/branches/net/applications/tftpc/tftpc.asm b/kernel/branches/net/applications/tftpc/tftpc.asm index df5dd4be1d..fb22d5f0d4 100644 --- a/kernel/branches/net/applications/tftpc/tftpc.asm +++ b/kernel/branches/net/applications/tftpc/tftpc.asm @@ -1,3 +1,5 @@ +format binary as "" + use32 org 0x0 @@ -13,23 +15,23 @@ include '../proc32.inc' include '../macros.inc' include '../libio.inc' include '../dll.inc' -include 'editbox_ex.mac' +include '../../../../../programs/develop/libraries/box_lib/trunk/box_lib.mac' include '../network.inc' filebuffer_size equ 4*4096 ; 16kb (dont try to change it yet..) -TIMEOUT equ 100 -buffer_len equ 1500 +TIMEOUT equ 100 +buffer_len equ 1500 -AF_INET4 equ 2 -IP_PROTO_UDP equ 17 +AF_INET4 equ 2 +IP_PROTO_UDP equ 17 -opcode_rrq equ 1 -opcode_wrq equ 2 -opcode_data equ 3 -opcode_ack equ 4 -opcode_error equ 5 +opcode_rrq equ 1 +opcode_wrq equ 2 +opcode_data equ 3 +opcode_ack equ 4 +opcode_error equ 5 ; read/write request packet ; @@ -62,142 +64,142 @@ opcode_error equ 5 START: - mcall 68, 11 + mcall 68, 11 - stdcall dll.Load, @IMPORT - or eax, eax - jnz exit + stdcall dll.Load, @IMPORT + or eax, eax + jnz exit stop_transfer: - mcall 40, 00100111b + mcall 40, 00100111b red_win: - call draw_window + call draw_window align 4 still: - mcall 10 + mcall 10 - dec eax - jz red_win + dec eax + jz red_win - dec eax - jz key + dec eax + jz key - dec eax - jz button + dec eax + jz button - push dword edit1 - call [edit_box_mouse] + push dword edit1 + call [edit_box_mouse] - push dword edit2 - call [edit_box_mouse] + push dword edit2 + call [edit_box_mouse] - push dword edit3 - call [edit_box_mouse] + push dword edit3 + call [edit_box_mouse] - push dword edit4 - call [edit_box_mouse] + push dword edit4 + call [edit_box_mouse] - push dword Option_boxs1 - call [option_box_mouse] + push dword Option_boxs1 + call [option_box_mouse] - push dword Option_boxs2 - call [option_box_mouse] + push dword Option_boxs2 + call [option_box_mouse] - jmp still + jmp still button: - mcall 17 + mcall 17 - cmp ah,0x10 - je start_transfer + cmp ah,0x10 + je start_transfer - test ah , ah - jz still + test ah , ah + jz still -exit: mcall -1 +exit: mcall -1 key: - mcall 2 + mcall 2 - push dword edit1 - call [edit_box_key] + push dword edit1 + call [edit_box_key] - push dword edit2 - call [edit_box_key] + push dword edit2 + call [edit_box_key] - push dword edit3 - call [edit_box_key] + push dword edit3 + call [edit_box_key] - push dword edit4 - call [edit_box_key] + push dword edit4 + call [edit_box_key] - jmp still + jmp still align 4 draw_window: - mcall 12,1 - mcall 0,(50*65536+400),(30*65536+180),0x34AABBCC,0x085080DD,str_title + mcall 12,1 + mcall 0,(50*65536+400),(30*65536+180),0x34AABBCC,0x085080DD,str_title - mcall 4,35*65536+10,0x80000000, str_server + mcall 4,35*65536+10,0x80000000, str_server - mov ebx,5*65536+ 30 - mov edx, str_source - mcall + mov ebx,5*65536+ 30 + mov edx, str_source + mcall - mov ebx,11*65536+ 50 - mov edx, str_destination - mcall + mov ebx,11*65536+ 50 + mov edx, str_destination + mcall - mov ebx,47*65536+72 - mov edx, str_mode - mcall + mov ebx,47*65536+72 + mov edx, str_mode + mcall - mov ebx,160*65536+72 - mov edx, str_method - mcall + mov ebx,160*65536+72 + mov edx, str_method + mcall - mov ebx,270*65536+72 - mov edx, str_blocksize - mcall + mov ebx,270*65536+72 + mov edx, str_blocksize + mcall - push dword edit1 - call [edit_box_draw] + push dword edit1 + call [edit_box_draw] - push dword edit2 - call [edit_box_draw] + push dword edit2 + call [edit_box_draw] - push dword edit3 - call [edit_box_draw] + push dword edit3 + call [edit_box_draw] - push dword edit4 - call [edit_box_draw] + push dword edit4 + call [edit_box_draw] - push dword Option_boxs1 - call [option_box_draw] + push dword Option_boxs1 + call [option_box_draw] - push dword Option_boxs2 - call [option_box_draw] + push dword Option_boxs2 + call [option_box_draw] - mcall 8,210*65536+170, 105*65536+16,0x00000010,0x085080DD + mcall 8,210*65536+170, 105*65536+16,0x00000010,0x085080DD - mcall 4,260*65536+110, 0x80000000, str_transfer + mcall 4,260*65536+110, 0x80000000, str_transfer - mcall 38,10*65536+380, 130*65536+130,0x00000000 + mcall 38,10*65536+380, 130*65536+130,0x00000000 - mcall 4,350*65536+137, 0x80000000, str_kb_s + mcall 4,350*65536+137, 0x80000000, str_kb_s - mcall 47,1 shl 31 + 7 shl 16 + 1,kbps,305*65536+137,0x00000000 + mcall 47,1 shl 31 + 7 shl 16 + 1,kbps,305*65536+137,0x00000000 - mcall 4,50*65536+137, 0x80000000, str_complete + mcall 4,50*65536+137, 0x80000000, str_complete - mcall 47,1 shl 31 + 3 shl 16 + 1,done,25*65536+137,0x00000000 + mcall 47,1 shl 31 + 3 shl 16 + 1,done,25*65536+137,0x00000000 - mcall 12,2 + mcall 12,2 - ret + ret @@ -206,79 +208,79 @@ draw_window: start_transfer: - ; first, resolve the hostname + ; first, resolve the hostname - push esp ; reserve stack place + push esp ; reserve stack place - push esp ; fourth parameter - push 0 ; third parameter - push 0 ; second parameter - push dword SRV ; first parameter - call [getaddrinfo] + push esp ; fourth parameter + push 0 ; third parameter + push 0 ; second parameter + push dword SRV ; first parameter + call [getaddrinfo] - pop esi + pop esi ; test for error - test eax, eax - jnz still + test eax, eax + jnz still - mov esi, [esi] - mov esi, [esi + sockaddr_in.sin_addr] - mov dword [IP], esi + mov esi, [esi] + mov esi, [esi + sockaddr_in.sin_addr] + mov dword [IP], esi - mcall socket, AF_INET4, SOCK_DGRAM, 0 ; socket_open - cmp eax, -1 - je still + mcall socket, AF_INET4, SOCK_DGRAM, 0 ; socket_open + cmp eax, -1 + je still - mov [socketnum], eax + mov [socketnum], eax - mcall connect, [socketnum], sockaddr, sockaddr_len ; socket_connect - cmp eax, -1 - je still + mcall connect, [socketnum], sockaddr, sockaddr_len ; socket_connect + cmp eax, -1 + je still - mov word [I_END], opcode_rrq - cmp [option_group2],op3 - je @f - mov word [I_END], opcode_wrq + mov word [I_END], opcode_rrq + cmp [option_group2],op3 + je @f + mov word [I_END], opcode_wrq @@: - xor al , al - mov edi, remote_addr - mov ecx, 250 - repnz scasb - sub edi, remote_addr-1 - mov ecx, edi - mov edi, I_END+2 - mov esi, remote_addr - rep movsb + xor al , al + mov edi, remote_addr + mov ecx, 250 + repnz scasb + sub edi, remote_addr-1 + mov ecx, edi + mov edi, I_END+2 + mov esi, remote_addr + rep movsb - cmp [option_group1], op1 - je .ascii + cmp [option_group1], op1 + je .ascii - mov esi, octet - movsd - movsb + mov esi, octet + movsd + movsb - jmp .send_request + jmp .send_request .ascii: - mov esi, netascii - movsd - movsd + mov esi, netascii + movsd + movsd .send_request: - xor al, al - stosb + xor al, al + stosb - sub edi, I_END - mov esi, edi - mcall send, [socketnum], I_END + sub edi, I_END + mov esi, edi + mcall send, [socketnum], I_END - mcall 40, 10000101b + mcall 40, 10000101b - mov [last_ack], 0 + mov [last_ack], 0 @@ -287,27 +289,27 @@ start_transfer: receive_data_loop: - mcall 23, TIMEOUT + mcall 23, TIMEOUT - dec eax - jz .red + dec eax + jz .red - dec eax - jz .key + dec eax + jz .key - mcall recv, [socketnum], buffer, buffer_len, 0 ; receive data + mcall recv, [socketnum], buffer, buffer_len, 0 ; receive data - cmp word[buffer], opcode_data - jne .error + cmp word[buffer], opcode_data + jne .error - mov bx, [last_ack] - cmp word [buffer + 2], bx - jne .packet_got_lost - inc [last_ack] + mov bx, [last_ack] + cmp word [buffer + 2], bx + jne .packet_got_lost + inc [last_ack] - cmp eax, 4+512 - je .continue + cmp eax, 4+512 + je .continue ; last packet, or something else .error: @@ -318,26 +320,26 @@ receive_data_loop: .continue: - mov word[buffer], opcode_ack ; send ack - mcall send, [socketnum], buffer, 4, 0 + mov word[buffer], opcode_ack ; send ack + mcall send, [socketnum], buffer, 4, 0 - jmp receive_data_loop + jmp receive_data_loop .red: - call draw_window + call draw_window - jmp receive_data_loop + jmp receive_data_loop .key: - mcall 2 - cmp ah, 2 - jz exit + mcall 2 + cmp ah, 2 + jz exit - ; close socket ? + ; close socket ? - jmp receive_data_loop + jmp receive_data_loop @@ -349,93 +351,93 @@ receive_data_loop: send_: - invoke file_open, local_addr, O_READ - or eax, eax - jz .exit - mov [fh], eax + invoke file_open, local_addr, O_READ + or eax, eax + jz .exit + mov [fh], eax - stdcall mem.Alloc, filebuffer_size - or eax, eax - jz .exit - mov [fb], eax + stdcall mem.Alloc, filebuffer_size + or eax, eax + jz .exit + mov [fb], eax - mov [last_ack], 0 - mov [fo], 0 + mov [last_ack], 0 + mov [fo], 0 .read_chunk: - invoke file_seek, [fh], [fo], SEEK_END - cmp eax, -1 - je .exit - invoke file_read, [fh], [fb], filebuffer_size - cmp eax, -1 - je .exit - add [fo], filebuffer_size - cmp eax, filebuffer_size - je .packet + invoke file_seek, [fh], [fo], SEEK_END + cmp eax, -1 + je .exit + invoke file_read, [fh], [fb], filebuffer_size + cmp eax, -1 + je .exit + add [fo], filebuffer_size + cmp eax, filebuffer_size + je .packet - ; ijhidfhfdsndsfqk + ; ijhidfhfdsndsfqk .packet: - movzx esi, [last_ack] - and esi, 0x000000001f ; last five bits BUFFER SIZE MUST BE 16 kb for this to work !!! - shl esi, 9 ; = * 512 - add esi, [fb] - mov edi, buffer - mov ax, opcode_data - stosw - mov ax, [last_ack] - stosw - mov ecx, 512/4 - rep movsd + movzx esi, [last_ack] + and esi, 0x000000001f ; last five bits BUFFER SIZE MUST BE 16 kb for this to work !!! + shl esi, 9 ; = * 512 + add esi, [fb] + mov edi, buffer + mov ax, opcode_data + stosw + mov ax, [last_ack] + stosw + mov ecx, 512/4 + rep movsd - mcall send, [socketnum], buffer, 4+512, 0 ; send data + mcall send, [socketnum], buffer, 4+512, 0 ; send data .loop: - mcall 23, TIMEOUT + mcall 23, TIMEOUT - dec eax - jz .red + dec eax + jz .red - dec eax - jz .key + dec eax + jz .key - mcall recv, [socketnum], buffer, buffer_len, 0 ; receive ack + mcall recv, [socketnum], buffer, buffer_len, 0 ; receive ack - cmp word[buffer], opcode_ack - jne .exit + cmp word[buffer], opcode_ack + jne .exit - mov ax, [last_ack] - cmp word[buffer+2], ax - jne .packet - inc [last_ack] - test [last_ack],0x001f - jz .read_chunk - jmp .packet + mov ax, [last_ack] + cmp word[buffer+2], ax + jne .packet + inc [last_ack] + test [last_ack],0x001f + jz .read_chunk + jmp .packet .red: - call draw_window + call draw_window - jmp .loop + jmp .loop .key: - mcall 2 - cmp ah, 2 - jz exit + mcall 2 + cmp ah, 2 + jz exit - ; close socket ? + ; close socket ? - jmp .loop + jmp .loop .exit: - invoke file_close, [fh] - jmp still + invoke file_close, [fh] + jmp still @@ -445,59 +447,59 @@ send_: ; DATA socketnum dd 0 -kbps dd 0 -done dd 0 +kbps dd 0 +done dd 0 sockaddr: - dw AF_INET4 - dw 69 -IP db 192,168,1,115 + dw AF_INET4 + dw 69 +IP db 192,168,1,115 sockaddr_len = $ - sockaddr align 16 @IMPORT: library box_lib , 'box_lib.obj' -library io_lib , 'libio.obj' +library io_lib , 'libio.obj' library network , 'network.obj' -import box_lib ,\ - edit_box_draw ,'edit_box' ,\ - edit_box_key ,'edit_box_key' ,\ - edit_box_mouse ,'edit_box_mouse' ,\ - version_ed ,'version_ed' ,\ - check_box_draw ,'check_box_draw' ,\ - check_box_mouse ,'check_box_mouse' ,\ - version_ch ,'version_ch' ,\ - option_box_draw ,'option_box_draw' ,\ - option_box_mouse ,'option_box_mouse' ,\ - version_op ,'version_op' +import box_lib ,\ + edit_box_draw ,'edit_box' ,\ + edit_box_key ,'edit_box_key' ,\ + edit_box_mouse ,'edit_box_mouse' ,\ + version_ed ,'version_ed' ,\ + check_box_draw ,'check_box_draw' ,\ + check_box_mouse ,'check_box_mouse' ,\ + version_ch ,'version_ch' ,\ + option_box_draw ,'option_box_draw' ,\ + option_box_mouse ,'option_box_mouse' ,\ + version_op ,'version_op' -import io_lib ,\ - file_find_first , 'file_find_first' ,\ - file_find_next , 'file_find_next' ,\ - file_find_close , 'file_find_close' ,\ - file_size , 'file_size' ,\ - file_open , 'file_open' ,\ - file_read , 'file_read' ,\ - file_write , 'file_write' ,\ - file_seek , 'file_seek' ,\ - file_tell , 'file_tell' ,\ - file_eof? , 'file_iseof' ,\ - file_seteof , 'file_seteof' ,\ - file_truncate , 'file_truncate' ,\ - file_close , 'file_close' +import io_lib ,\ + file_find_first , 'file_find_first' ,\ + file_find_next , 'file_find_next' ,\ + file_find_close , 'file_find_close' ,\ + file_size , 'file_size' ,\ + file_open , 'file_open' ,\ + file_read , 'file_read' ,\ + file_write , 'file_write' ,\ + file_seek , 'file_seek' ,\ + file_tell , 'file_tell' ,\ + file_eof? , 'file_iseof' ,\ + file_seteof , 'file_seteof' ,\ + file_truncate , 'file_truncate' ,\ + file_close , 'file_close' -import network ,\ - inet_ntoa , 'inet_ntoa' ,\ - getaddrinfo , 'getaddrinfo' ,\ - freeaddrinfo , 'freeaddrinfo' +import network ,\ + inet_ntoa , 'inet_ntoa' ,\ + getaddrinfo , 'getaddrinfo' ,\ + freeaddrinfo , 'freeaddrinfo' -edit1 edit_box 300,80,5 ,0xffffff,0x6f9480,0,0,0,99 ,SRV,ed_focus, 11,11 -edit2 edit_box 300,80,25,0xffffff,0x6a9480,0,0,0,99 ,remote_addr,ed_figure_only, 10,10 -edit3 edit_box 300,80,45,0xffffff,0x6a9480,0,0,0,99 ,local_addr,ed_figure_only, 27,27 -edit4 edit_box 40,340,68,0xffffff,0x6a9480,0,0,0,5 ,BLK,ed_figure_only, 3,3 +edit1 edit_box 300,80,5 ,0xffffff,0x6f9480,0,0,0,99 ,SRV,mouse_dd,ed_focus, 11,11 +edit2 edit_box 300,80,25,0xffffff,0x6a9480,0,0,0,99 ,remote_addr,mouse_dd,ed_figure_only, 10,10 +edit3 edit_box 300,80,45,0xffffff,0x6a9480,0,0,0,99 ,local_addr,mouse_dd,ed_figure_only, 27,27 +edit4 edit_box 40,340,68,0xffffff,0x6a9480,0,0,0,5 ,BLK,mouse_dd,ed_figure_only, 3,3 op1 option_box option_group1,80,68,6,12,0xffffff,0,0,netascii,octet-netascii op2 option_box option_group1,80,85,6,12,0xFFFFFF,0,0,octet,get-octet @@ -505,21 +507,21 @@ op2 option_box option_group1,80,85,6,12,0xFFFFFF,0,0,octet,get-octet op3 option_box option_group2,210,68,6,12,0xffffff,0,0,get,put-get op4 option_box option_group2,210,85,6,12,0xFFFFFF,0,0,put,BLK-put -option_group1 dd op1 -option_group2 dd op3 -Option_boxs1 dd op1,op2,0 -Option_boxs2 dd op3,op4,0 +option_group1 dd op1 +option_group2 dd op3 +Option_boxs1 dd op1,op2,0 +Option_boxs2 dd op3,op4,0 -str_title db 'TFTP client for KolibriOS',0 -str_server db 'Server:',0 -str_source db 'Remote file:',0 +str_title db 'TFTP client for KolibriOS',0 +str_server db 'Server:',0 +str_source db 'Remote file:',0 str_destination db 'Local file:',0 -str_mode db 'Mode:',0 -str_method db 'Method:',0 -str_blocksize db 'Blocksize:',0 -str_kb_s db 'kb/s',0 -str_complete db '% complete',0 -str_transfer db 'Transfer',0 +str_mode db 'Mode:',0 +str_method db 'Method:',0 +str_blocksize db 'Blocksize:',0 +str_kb_s db 'kb/s',0 +str_complete db '% complete',0 +str_transfer db 'Transfer',0 str_error: ._0 db 'Not defined, see error message (if any).',0 @@ -533,17 +535,17 @@ str_error: netascii db 'NetASCII' -octet db 'Octet' -get db 'GET' -put db 'PUT' +octet db 'Octet' +get db 'GET' +put db 'PUT' -BLK db "512",0,0,0 +BLK db "512",0,0,0 last_ack dw ? -fh dd ? ; file handle -fo dd ? ; file offset -fb dd ? ; file buffer +fh dd ? ; file handle +fo dd ? ; file offset +fb dd ? ; file buffer SRV db "192.168.1.115",0 rb (SRV + 256 - $) @@ -555,6 +557,7 @@ local_addr db "/hd0/1/KolibriOS/kernel.mnt",0 rb (local_addr + 256 - $) I_END: +mouse_dd dd ? buffer: rb buffer_len