Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Ignore whitespace Rev 108 → Rev 109

/programs/network/airc/trunk/airc.asm
0,0 → 1,2359
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; IRC CLIENT for MenuetOS ;;
;; ;;
;; License: GPL / See file COPYING for details ;;
;; Copyright 2004 (c) Ville Turjanmaa ;;
;; ;;
;; Compile with FASM for Menuet ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
version equ '0.3'
 
use32
 
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
dd 0x100000
dd 0,0
include "lang.inc"
include "macros.inc"
 
irc_server_ip db 192,168,1,1
 
user_nick dd 4 ; length
db 'airc ' ; string
 
user_real_name dd 8 ; length
db 'Joe User ' ; string
 
 
START: ; start of execution
 
mov eax,40
mov ebx,10000111b
int 0x40
 
mov edi,I_END
mov ecx,60*120
mov eax,32
cld
rep stosb
 
mov eax,[rxs]
imul eax,11
mov [pos],eax
 
mov ebp,0
mov edx,I_END
call draw_window ; at first, draw the window
 
still:
 
inc [cursor_on_off]
 
mov eax,5
mov ebx,1
int 0x40
 
mov eax,11 ; wait here for event
int 0x40
 
call print_status
 
cmp eax,1 ; redraw
je redraw
cmp eax,2 ; key
je main_window_key
cmp eax,3 ; button
je button
 
cmp [I_END+120*60],byte 1
jne no_main_update
mov [I_END+120*60],byte 0
mov edx,I_END
call draw_channel_text
no_main_update:
 
call read_incoming_data
 
call send_data_to_server
 
test [cursor_on_off],0x3f
jnz nopri
inc [blink]
call blink_cursor
call print_channel_list
nopri:
 
jmp still
 
 
redraw: ; redraw
 
call draw_window
jmp still
 
 
button: ; button
 
mov eax,17 ; get id
int 0x40
 
cmp ah,1 ; close program
jne noclose
mov eax,-1
int 0x40
noclose:
 
call socket_commands
 
jmp still
 
 
print_status:
 
pusha
 
mov eax,53
mov ebx,6
mov ecx,[socket]
int 0x40
 
mov [status],eax
 
cmp [old_status],eax
je nopr
 
mov [old_status],eax
 
push eax
 
mov eax,13
mov ebx,450*65536+30
mov ecx,231*65536+10
mov edx,0xffffff
int 0x40
 
pop ecx
mov eax,47
mov ebx,2*65536
mov edx,450*65536+231
mov esi,0x000000
int 0x40
 
nopr:
 
popa
 
ret
 
status dd 0
old_status dd 0
 
 
socket_commands:
 
cmp ah,22 ; open socket
jnz tst3
mov eax,3
int 0x40
mov ecx,eax
mov eax,53
mov ebx,5
mov edx,6667
mov esi,dword [irc_server_ip]
mov edi,1
int 0x40
mov [socket], eax
ret
tst3:
 
 
cmp ah,23 ; write userinfo
jnz tst4
 
mov eax,53 ; user
mov ebx,7
mov ecx,[socket]
mov edx,string0l-string0
mov esi,string0
int 0x40
 
mov eax,53 ;
mov ebx,7
mov ecx,[socket]
mov edx,[user_real_name]
mov esi,user_real_name+4
int 0x40
 
mov eax,53 ;
mov ebx,7
mov ecx,[socket]
mov edx,2
mov esi,line_feed
int 0x40
 
 
mov eax,5
mov ebx,10
int 0x40
 
mov eax,53 ; nick
mov ebx,7
mov ecx,[socket]
mov edx,string1l-string1
mov esi,string1
int 0x40
 
mov eax,53 ;
mov ebx,7
mov ecx,[socket]
mov edx,[user_nick]
mov esi,user_nick+4
int 0x40
 
mov eax,53 ;
mov ebx,7
mov ecx,[socket]
mov edx,2
mov esi,line_feed
int 0x40
 
 
ret
 
line_feed: db 13,10
 
tst4:
 
 
cmp ah,24 ; close socket
jnz no_24
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
ret
no_24:
 
 
ret
 
 
main_window_key:
 
mov eax,2
int 0x40
 
shr eax,8
 
cmp eax,8
jne no_bks2
cmp [xpos],0
je still
dec [xpos]
call print_entry
jmp still
no_bks2:
 
cmp eax,20
jbe no_character2
mov ebx,[xpos]
mov [send_string+ebx],al
inc [xpos]
cmp [xpos],80
jb noxposdec
mov [xpos],79
noxposdec:
call print_entry
jmp still
no_character2:
 
cmp eax,13
jne no_send
cmp [xpos],0
je no_send2
cmp [send_string],byte '/' ; server command
jne no_send2
mov [send_to_server],1
jmp still
no_send2:
 
jmp still
 
 
print_channel_list:
 
pusha
 
mov eax,13
mov ebx,415*65536+6*13
mov ecx,27*65536+12*10
mov edx,0xffffff
int 0x40
 
mov eax,4
mov ebx,415*65536+27
mov ecx,[index_list_1]
mov edx,channel_list+32
newch:
movzx esi,byte [edx+31]
and esi,0x1f
int 0x40
add edx,32
add ebx,12
cmp edx,channel_list+32*10
jbe newch
 
no_channel_list:
 
popa
 
ret
 
 
print_user_list:
 
pusha
 
newtry:
 
mov edx,ebp
imul edx,120*80
add edx,120*60+8+I_END
cmp [edx],byte 1
je nonp
 
mov edx,ebp
imul edx,120*80
add edx,120*70+I_END
mov edi,edx
 
mov eax,[edx-8]
mov ebx,[edx-4]
add ebx,edx
sub ebx,3
inc eax
dec edx
newnss:
inc edx
dec eax
jz startuu
asdf:
cmp [edx],word ' '
jne nodouble
inc edx
nodouble:
cmp [edx],byte ' '
je newnss
inc edx
cmp edx,ebx
jbe asdf
dec dword [edi-8]
 
popa
ret
 
startuu:
 
cmp [edx],byte ' '
jne startpr
inc edx
startpr:
 
pusha
mov eax,13
mov ebx,415*65536+6*13
mov ecx,27*65536+12*10
mov edx,0xffffff
int 0x40
popa
 
mov eax,4
mov ebx,415*65536+27
 
mov ebp,0
newuser:
 
mov esi,0
newusers:
cmp [edx+esi],byte ' '
je do_print
inc esi
cmp esi,20
jbe newusers
do_print:
 
mov ecx,[index_list_1]
cmp [edx],byte '@'
jne no_op
mov ecx,[index_list_2]
no_op:
 
int 0x40
 
inc ebp
cmp ebp,10
je nonp
 
add ebx,12
 
add edx,esi
 
inc edx
cmp [edx],byte ' '
jne newuser
inc edx
jmp newuser
 
nonp:
 
popa
 
ret
 
 
start_user_list_at dd 0x0
 
 
 
 
send_data_to_server:
 
pusha
 
cmp [send_to_server],1
jne sdts_ret
 
mov eax,[xpos]
mov [send_string+eax+0],byte 13
mov [send_string+eax+1],byte 10
 
mov eax,[rxs]
imul eax,11
mov [pos],eax
mov eax,[send_to_channel]
imul eax,120*80
add eax,I_END
mov [text_start],eax
 
cmp [send_string],byte '/' ; server command
je server_command
 
mov bl,13
call print_character
mov bl,10
call print_character
mov bl,'<'
call print_character
 
mov esi,user_nick+4
mov ecx,[user_nick]
newnp:
mov bl,[esi]
call print_character
inc esi
loop newnp
 
mov bl,'>'
call print_character
mov bl,' '
call print_character
 
mov ecx,[xpos]
mov esi,send_string
newcw:
mov bl,[esi]
call print_character
inc esi
loop newcw
 
mov eax,dword [send_to_channel]
shl eax,5
add eax,channel_list
mov esi,eax
 
mov edi,send_string_header+8
movzx ecx,byte [eax+31]
cld
rep movsb
 
mov [edi],word ' :'
 
mov esi, send_string_header
mov edx,10
movzx ebx,byte [eax+31]
add edx,ebx
 
mov eax, 53 ; write channel
mov ebx, 7
mov ecx, [socket]
int 0x40
 
mov esi,send_string
mov edx,[xpos]
inc edx
 
mov eax, 53 ; write message
mov ebx, 7
mov ecx, [socket]
int 0x40
 
jmp send_done
 
server_command:
 
cmp [send_string+1],dword 'anic'
jne no_set_nick
 
mov ecx,[xpos]
sub ecx,7
mov [user_nick],ecx
 
mov esi,send_string+7
mov edi,user_nick+4
cld
rep movsb
 
pusha
mov edi,text+70*1+15
mov eax,32
mov ecx,15
cld
rep stosb
popa
 
mov esi,user_nick+4
mov edi,text+70*1+15
mov ecx,[user_nick]
cld
rep movsb
 
call draw_window
 
mov [xpos],0
mov [send_to_server],0
 
popa
ret
 
no_set_nick:
 
cmp [send_string+1],dword 'area'
jne no_set_real_name
 
mov ecx,[xpos]
sub ecx,7
mov [user_real_name],ecx
 
mov esi,send_string+7
mov edi,user_real_name+4
cld
rep movsb
 
pusha
mov edi,text+70*0+15
mov eax,32
mov ecx,15
cld
rep stosb
popa
 
mov esi,user_real_name+4
mov edi,text+70*0+15
mov ecx,[xpos]
sub ecx,7
cld
rep movsb
 
call draw_window
 
mov [xpos],0
mov [send_to_server],0
 
popa
ret
 
no_set_real_name:
 
cmp [send_string+1],dword 'aser'
jne no_set_server
 
pusha
mov edi,irc_server_ip
mov esi,send_string+7
mov eax,0
mov edx,[xpos]
add edx,send_string-1
newsip:
cmp [esi],byte '.'
je sipn
cmp esi,edx
jg sipn
movzx ebx,byte [esi]
inc esi
imul eax,10
sub ebx,48
add eax,ebx
jmp newsip
sipn:
mov [edi],al
xor eax,eax
inc esi
cmp esi,send_string+30
jg sipnn
inc edi
cmp edi,irc_server_ip+3
jbe newsip
sipnn:
popa
 
mov ecx,[xpos]
sub ecx,7
 
pusha
mov edi,text+70*2+15
mov eax,32
mov ecx,15
cld
rep stosb
popa
 
mov esi,send_string+7
mov edi,text+70*2+15
cld
rep movsb
 
call draw_window
 
mov [xpos],0
mov [send_to_server],0
 
popa
ret
 
no_set_server:
 
 
 
 
cmp [send_string+1],dword 'quer'
jne no_query_create
 
mov edi,I_END+120*80
mov eax,1 ; create channel window - search for empty slot
newse2:
mov ebx,eax
shl ebx,5
cmp dword [channel_list+ebx],dword ' '
je free_found2
add edi,120*80
inc eax
cmp eax,[max_windows]
jb newse2
 
free_found2:
 
mov edx,send_string+7
 
mov ecx,[xpos]
sub ecx,7
mov [channel_list+ebx+31],cl
 
call create_channel_name
 
push edi
push eax
mov [edi+120*60+8],byte 1 ; query window
mov eax,32
mov ecx,120*60
cld
rep stosb
pop eax
pop edi
 
; eax has the free position
mov [thread_screen],edi
call create_channel_window
 
mov [xpos],0
mov [send_to_server],0
 
popa
ret
 
no_query_create:
 
 
mov esi, send_string+1
mov edx, [xpos]
add edx,1
 
mov eax, 53 ; write server command
mov ebx, 7
mov ecx, [socket]
int 0x40
 
send_done:
 
mov [xpos],0
mov [send_to_server],0
 
cmp [send_string+1],dword 'quit'
jne no_quit_server
mov eax,5
mov ebx,200
int 0x40
 
mov eax, 53 ; close socket
mov ebx, 8
mov ecx, [socket]
int 0x40
 
mov ecx,[max_windows]
mov edi,I_END
newclose:
mov [edi+120*60+4],byte 1
add edi,120*80
loop newclose
 
popa
ret
 
no_quit_server:
 
sdts_ret:
 
popa
ret
 
 
 
read_incoming_data:
 
pusha
 
read_new_byte:
 
call read_incoming_byte
cmp ecx,-1
je no_data_in_buffer
 
cmp bl,10
jne no_start_command
mov [cmd],1
no_start_command:
 
cmp bl,13
jne no_end_command
mov eax,[cmd]
mov [eax+command-2],byte 0
call analyze_command
mov edi,command
mov ecx,250
mov eax,0
cld
rep stosb
mov [cmd],0
no_end_command:
 
mov eax,[cmd]
cmp eax,512
jge still
 
mov [eax+command-2],bl
inc [cmd]
 
jmp read_new_byte
 
no_data_in_buffer:
 
popa
 
ret
 
 
create_channel_name:
 
pusha
 
search_first_letter:
cmp [edx],byte ' '
jne first_letter_found
inc edx
jmp search_first_letter
first_letter_found:
 
mov esi,edx
mov edi,channel_list
add edi,ebx
mov ecx,30
xor eax,eax
newcase:
mov al,[esi]
cmp eax,'a'
jb nocdec
cmp eax,'z'
jg nocdec
sub al,97-65
nocdec:
mov [edi],al
inc esi
inc edi
loop newcase
 
popa
 
ret
 
 
create_channel_window:
 
pusha
 
mov [cursor_on_off],0
 
mov [thread_nro],eax
 
mov eax,51
mov ebx,1
mov ecx,channel_thread
mov edx,[thread_stack]
int 0x40
 
mov eax,5
mov ebx,10
int 0x40
 
add [thread_stack],0x4000
add [thread_screen],120*80
 
popa
 
ret
 
 
print_entry:
 
pusha
 
mov eax,13
mov ebx,8*65536+6*80
mov ecx,151*65536+13
mov edx,0xffffff
int 0x40
 
mov eax,4
mov ebx,8*65536+154
mov ecx,0x000000
mov edx,send_string
mov esi,[xpos]
int 0x40
 
popa
 
ret
 
blink dd 0x0
 
blink_cursor:
 
pusha
 
mov eax,9
mov ebx,0xe0000
mov ecx,-1
int 0x40
 
mov edx,[blink]
and edx,1
sub edx,1
and edx,0xffffff
; mov edx,0
 
cmp ax,word [0xe0000+4]
jne no_blink
 
call print_entry
 
mov ebx,[xpos]
imul ebx,6
add ebx,8
mov cx,bx
shl ebx,16
mov bx,cx
mov ecx,151*65536+163
mov eax,38
int 0x40
 
popa
 
ret
 
no_blink:
 
mov eax,13
mov ebx,8*65536+6*60
mov ecx,151*65536+13
mov edx,0xffffff
int 0x40
 
popa
 
ret
 
 
 
 
 
set_channel:
 
pusha
 
; UPPER / LOWER CASE CHECK
 
mov esi,eax
mov edi,channel_temp
mov ecx,40
xor eax,eax
newcase2:
mov al,[esi]
cmp eax,'#'
jb newcase_over2
cmp eax,'a'
jb nocdec2
cmp eax,'z'
jg nocdec2
sub al,97-65
nocdec2:
mov [edi],al
inc esi
inc edi
loop newcase2
newcase_over2:
sub edi,channel_temp
mov [channel_temp_length],edi
 
mov eax,channel_temp
 
mov [text_start],I_END+120*80
mov ebx,channel_list+32
mov eax,[eax]
 
mov edx,[channel_temp_length]
 
stcl1:
cmp dl,[ebx+31]
jne notfound
 
pusha
xor eax,eax
xor edx,edx
mov ecx,0
stc4:
mov dl,[ebx+ecx]
mov al,[channel_temp+ecx]
cmp eax,edx
jne notfound2
inc ecx
cmp ecx,[channel_temp_length]
jb stc4
popa
 
jmp found
 
notfound2:
popa
 
notfound:
add [text_start],120*80
add ebx,32
cmp ebx,channel_list+19*32
jb stcl1
 
mov [text_start],I_END
 
found:
 
popa
 
ret
 
 
channel_temp: times 100 db 0
channel_temp_length dd 0x0
 
 
 
print_nick:
 
pusha
 
mov eax,command+1
mov dl,'!'
call print_text
 
popa
ret
 
 
analyze_command:
 
pusha
 
mov [text_start],I_END
mov ecx,[rxs]
imul ecx,11
mov [pos],ecx
 
mov bl,13
; call print_character
mov bl,10
; call print_character
 
mov ecx,[cmd]
sub ecx,2
mov esi,command+0
newcmdc:
mov bl,[esi]
; call print_character
inc esi
loop newcmdc
 
mov edx,I_END
; call draw_channel_text
 
cmp [cmd],20
jge cmd_len_ok
 
mov [cmd],0
 
popa
ret
 
 
cmd_len_ok:
 
cmp [command],dword 'PING' ; ping response
jne no_ping_responce
 
call print_command_to_main
 
mov [command],dword 'PONG'
 
call print_command_to_main
 
mov eax,4
mov ebx,100*65536+3
mov ecx,0xffffff
mov edx,command
mov esi,[cmd]
mov [command+esi-1],word '**'
; int 0x40
 
mov eax,53
mov ebx,7
mov ecx,[socket]
mov edx,[cmd]
sub edx,2
and edx,255
mov esi,command
int 0x40
 
mov eax,53
mov ebx,7
mov ecx,[socket]
mov edx,2
mov esi,linef
int 0x40
 
popa
ret
 
linef db 13,10
 
no_ping_responce:
 
mov eax,[rxs]
imul eax,11
mov [pos],eax
 
mov [command],byte '<'
 
mov eax,command
mov ecx,100
new_blank:
cmp [eax],byte ' '
je bl_found
inc eax
loop new_blank
mov eax,50
bl_found:
 
inc eax
mov [command_position],eax
 
mov esi,eax
mov edi,irc_command
mov ecx,8
cld
rep movsb
 
 
cmp [irc_command],'PRIV' ; message to channel
jne no_privmsg
 
; compare nick
 
mov eax,[command_position]
add eax,8
call compare_to_nick
cmp [cresult],0
jne no_query_msg
mov eax,command+1
no_query_msg:
call set_channel
 
mov ecx,100 ; [cmd]
mov eax,command+10
acl3:
cmp [eax],byte ':'
je acl4
inc eax
loop acl3
mov eax,10
acl4:
inc eax
 
cmp [eax+1],dword 'ACTI'
jne no_action
push eax
mov eax,action_header_short
mov dl,0
call print_text
mov eax,command+1
mov dl,'!'
call print_text
mov bl,' '
call print_character
pop eax
add eax,8
mov dl,0
call print_text
popa
ret
 
no_action:
 
push eax
mov bl,10
call print_character
mov eax,command
mov dl,'!'
call print_text
mov bl,'>'
call print_character
mov bl,' '
call print_character
pop eax
 
mov dl,0
call print_text
 
popa
ret
 
no_privmsg:
 
 
cmp [irc_command],'PART' ; channel leave
jne no_part
 
; compare nick
 
mov eax,command+1
call compare_to_nick
cmp [cresult],0
jne no_close_window
 
mov eax,[command_position]
add eax,5
call set_channel
 
mov eax,[text_start]
mov [eax+120*60+4],byte 1
 
popa
ret
 
no_close_window:
 
mov eax,[command_position]
add eax,5
call set_channel
 
mov eax,action_header_red
mov dl,0
call print_text
mov eax,command+1
mov dl,'!'
mov cl,' '
call print_text
mov eax,has_left_channel
mov dl,0
call print_text
mov eax,[command_position]
add eax,5
mov dl,' '
call print_text
 
popa
ret
 
no_part:
 
 
cmp [irc_command],'JOIN' ; channel join
jne no_join
 
; compare nick
 
mov eax,command+1
call compare_to_nick
cmp [cresult],0
jne no_new_window
 
mov edi,I_END+120*80
mov eax,1 ; create channel window - search for empty slot
newse:
mov ebx,eax
shl ebx,5
cmp dword [channel_list+ebx],dword ' '
je free_found
add edi,120*80
inc eax
cmp eax,[max_windows]
jb newse
 
free_found:
 
mov edx,[command_position]
add edx,6
 
push eax
push edx
mov ecx,0
finde:
inc ecx
inc edx
movzx eax,byte [edx]
cmp eax,'#'
jge finde
mov [channel_list+ebx+31],cl
pop edx
pop eax
 
call create_channel_name
 
push edi
push eax
mov [edi+120*60+8],byte 0 ; channel window
mov eax,32
mov ecx,120*60
cld
rep stosb
pop eax
pop edi
 
; eax has the free position
mov [thread_screen],edi
call create_channel_window
 
no_new_window:
 
mov eax,[command_position]
add eax,6
call set_channel
 
mov eax,action_header_blue
mov dl,0
call print_text
mov eax,command+1
mov dl,'!'
mov cl,' '
call print_text
 
mov eax,joins_channel
mov dl,0
call print_text
 
mov eax,[command_position]
add eax,6
mov dl,0
call print_text
 
popa
ret
 
no_join:
 
 
cmp [irc_command],'NICK' ; nick change
jne no_nick_change
 
mov [text_start],I_END
add [text_start],120*80
 
new_all_channels3:
 
mov eax,action_header_short
mov dl,0
call print_text
mov eax,command+1
mov dl,'!'
call print_text
mov eax,is_now_known_as
mov dl,0
call print_text
mov eax,[command_position]
add eax,6
mov dl,0
call print_text
 
add [text_start],120*80
cmp [text_start],I_END+120*80*20
jb new_all_channels3
 
popa
ret
 
no_nick_change:
 
 
cmp [irc_command],'KICK' ; kick
jne no_kick
 
mov [text_start],I_END
add [text_start],120*80
 
mov eax,[command_position]
add eax,5
call set_channel
 
; new_all_channels4:
 
mov eax,action_header_short
mov dl,0
call print_text
mov eax,command+1
mov dl,'!'
call print_text
mov eax,kicked
mov dl,0
call print_text
mov eax,[command_position]
add eax,5
mov dl,0
call print_text
 
; add [text_start],120*80
; cmp [text_start],I_END+120*80*20
; jb new_all_channels4
 
popa
ret
 
no_kick:
 
 
 
 
cmp [irc_command],'QUIT' ; irc quit
jne no_quit
 
mov [text_start],I_END
add [text_start],120*80
 
new_all_channels2:
 
mov eax,action_header_red
mov dl,0
call print_text
mov eax,command+1
mov dl,'!'
call print_text
mov eax,has_quit_irc
mov dl,0
call print_text
 
add [text_start],120*80
cmp [text_start],I_END+120*80*20
jb new_all_channels2
 
popa
ret
 
no_quit:
 
 
cmp [irc_command],dword 'MODE' ; channel mode change
jne no_mode
 
mov [text_start],I_END
add [text_start],120*80
 
mov eax,[command_position]
add eax,5
call set_channel
 
new_all_channels:
 
mov eax,action_header_short
mov dl,0
call print_text
 
call print_nick
 
mov eax,sets_mode
mov dl,0
call print_text
 
mov eax,[command_position]
add eax,5
mov dl,0
call print_text
 
; add [text_start],120*80
; cmp [text_start],I_END+120*80*20
; jb new_all_channels
 
popa
ret
 
no_mode:
 
 
cmp [irc_command],dword '353 ' ; channel user names
jne no_user_list
 
mov eax,[command_position]
finde2:
inc eax
cmp [eax],byte '#'
jne finde2
call set_channel
 
finde3:
inc eax
cmp [eax],byte ':'
jne finde3
 
pusha
cmp [user_list_pos],0
jne no_clear_user_list
mov edi,[text_start]
add edi,120*70
mov [edi-8],dword 0
mov [edi-4],dword 0
mov eax,32
mov ecx,1200
cld
rep stosb
no_clear_user_list:
popa
 
push eax
 
mov esi,eax
inc esi
mov edi,[text_start]
add edi,120*70
add edi,[user_list_pos]
mov edx,edi
mov ecx,command
add ecx,[cmd]
sub ecx,[esp]
sub ecx,3
and ecx,0xfff
cld
rep movsb
 
pop eax
mov ebx,command
add ebx,[cmd]
sub ebx,eax
sub ebx,2
mov [edx+ebx-1],dword ' '
 
add [user_list_pos],ebx
 
mov eax,[user_list_pos]
mov ebx,[text_start]
add ebx,120*70
mov [ebx-4],eax
 
popa
ret
 
user_list_pos dd 0x0
 
no_user_list:
 
 
cmp [irc_command],dword '366 ' ; channel user names end
jne no_user_list_end
 
mov [user_list_pos],0
 
popa
ret
 
no_user_list_end:
 
mov [command],byte '-'
call print_command_to_main
 
popa
 
ret
 
 
cresult db 0
 
compare_to_nick:
 
; input : eax = start of compare
; output : [cresult] = 0 if match, [cresult]=1 if no match
 
 
pusha
 
mov esi,eax
mov edi,0
 
new_nick_compare:
 
mov bl,byte [esi]
mov cl,byte [user_nick+4+edi]
 
cmp bl,cl
jne nonickm
 
add esi,1
add edi,1
 
cmp edi,[user_nick]
jb new_nick_compare
 
movzx eax,byte [esi]
cmp eax,40
jge nonickm
 
popa
mov [cresult],0
ret
 
nonickm:
 
popa
mov [cresult],1
ret
 
 
 
 
 
print_command_to_main:
 
pusha
 
mov [text_start],I_END
mov ecx,[rxs]
imul ecx,11
mov [pos],ecx
 
mov bl,13
call print_character
mov bl,10
call print_character
 
mov ecx,[cmd]
sub ecx,2
mov esi,command
newcmdc2:
mov bl,[esi]
call print_character
inc esi
loop newcmdc2
 
mov edx,I_END
call draw_channel_text
 
popa
 
ret
 
 
 
 
print_text:
 
pusha
 
mov ecx,command-2
add ecx,[cmd]
 
ptr2:
mov bl,[eax]
cmp bl,dl
je ptr_ret
cmp bl,0
je ptr_ret
call print_character
inc eax
cmp eax,ecx
jbe ptr2
 
ptr_ret:
 
mov eax,[text_start]
mov [eax+120*60],byte 1
 
popa
ret
 
 
 
print_character:
 
pusha
 
cmp bl,13 ; line beginning
jne nobol
mov ecx,[pos]
add ecx,1
boll1:
sub ecx,1
mov eax,ecx
xor edx,edx
mov ebx,[rxs]
div ebx
cmp edx,0
jne boll1
mov [pos],ecx
jmp newdata
nobol:
 
cmp bl,10 ; line down
jne nolf
addx1:
add [pos],dword 1
mov eax,[pos]
xor edx,edx
mov ecx,[rxs]
div ecx
cmp edx,0
jnz addx1
mov eax,[pos]
jmp cm1
nolf:
no_lf_ret:
 
 
cmp bl,15 ; character
jbe newdata
 
mov eax,[irc_data]
shl eax,8
mov al,bl
mov [irc_data],eax
 
mov eax,[pos]
call draw_data
 
mov eax,[pos]
add eax,1
cm1:
mov ebx,[scroll+4]
imul ebx,[rxs]
cmp eax,ebx
jb noeaxz
 
mov esi,[text_start]
add esi,[rxs]
 
mov edi,[text_start]
mov ecx,ebx
cld
rep movsb
 
mov esi,[text_start]
mov ecx,[rxs]
imul ecx,61
add esi,ecx
 
mov edi,[text_start]
mov ecx,[rxs]
imul ecx,60
add edi,ecx
mov ecx,ebx
cld
rep movsb
 
mov eax,ebx
sub eax,[rxs]
noeaxz:
mov [pos],eax
 
newdata:
 
mov eax,[text_start]
mov [eax+120*60],byte 1
 
popa
ret
 
 
 
draw_data:
 
pusha
 
and ebx,0xff
 
cmp bl,0xe4 ; finnish a
jne noe4
mov bl,0xc1
noe4:
cmp bl,0xc4 ; ?
jne noc4
mov bl,0xc9
noc4:
 
cmp ebx,229 ; swedish a
jne no_swedish_a
mov bl,192
no_swedish_a:
 
add eax,[text_start]
mov [eax],bl
 
popa
ret
 
 
 
read_incoming_byte:
 
mov eax, 53
mov ebx, 2
mov ecx, [socket]
int 0x40
 
mov ecx,-1
 
cmp eax,0
je no_more_data
 
mov eax, 53
mov ebx, 3
mov ecx, [socket]
int 0x40
 
mov ecx,0
 
no_more_data:
 
ret
 
 
 
draw_window:
 
pusha
 
mov eax,12
mov ebx,1
int 0x40
 
mov [old_status],300
 
mov eax,0 ; draw window
mov ebx,5*65536+499
mov ecx,5*65536+345
mov edx,[wcolor]
add edx,0x03ffffff
mov esi,0x80555599
mov edi,0x00ffffff
int 0x40
 
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,43*65536+22
mov ecx,229*65536+10
mov edx,22
mov esi,[main_button]
int 0x40
 
mov eax,8 ; button: send userinfo
mov ebx,180*65536+22
mov ecx,229*65536+10
mov edx,23
int 0x40
 
mov eax,8 ; button: close socket
mov ebx,317*65536+22
mov ecx,229*65536+10
mov edx,24
int 0x40
 
mov eax,38 ; line
mov ebx,5*65536+494
mov ecx,148*65536+148
mov edx,[main_line]
int 0x40
add ecx,1*65536+1
; mov edx,0x5555cc
; int 0x40
 
mov eax,38 ; line
mov ebx,5*65536+494
mov ecx,166*65536+166
int 0x40
add ecx,1*65536+1
; mov edx,0x5555cc
; int 0x40
 
mov eax,38 ; line
mov ebx,410*65536+410
mov ecx,22*65536+148
int 0x40
add ebx,1*65536+1
; mov edx,0x5555cc
; int 0x40
 
mov ebx,25*65536+183 ; info text
mov ecx,0x000000
mov edx,text
mov esi,70
newline:
mov eax,4
int 0x40
add ebx,12
add edx,70
cmp [edx],byte 'x'
jne newline
 
mov edx,I_END ; text from server
call draw_channel_text
 
mov eax,12
mov ebx,2
int 0x40
 
popa
 
ret
 
main_line dd 0x000000
main_button dd 0x6565cc
 
 
text:
 
db ' Real name : Joe User - change with eg /areal Jill User '
db ' Nick : AIRC - change with eg /anick Jill '
db ' Server : 192.168.1.1 - change with eg /aserv 192.168.1.24 '
db ' '
db ' 1) Open socket 2) Send userinfo Close socket '
db ' '
db ' Commands after established connection: '
db ' '
db ' /join #ChannelName - eg /join #menuet '
db ' /part #ChannelName - eg /part #linux '
db ' /query Nickname - eg /query Mary '
db ' /quit - Quit server and Close socket '
 
db 'x <- END MARKER, DONT DELETE '
 
 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; CHANNEL THREADS
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
 
channel_thread:
 
mov ebp,[thread_nro]
mov eax,ebp
shl eax,14
add eax,0x80000
mov esp,eax
 
mov edi,ebp ; clear thread memory
imul edi,120*80
add edi,I_END
mov ecx,120*80
mov eax,32
cld
; rep stosb
 
mov edx,[thread_screen]
 
call thread_draw_window
 
w_t:
 
mov esi,ebp
imul esi,120*80
add esi,I_END
cmp [esi+120*60+4],byte 1
jne no_channel_leave
mov [esi+120*60+4],byte 0
mov edi,ebp
shl edi,5
mov dword [channel_list+edi],dword ' '
mov byte [channel_list+edi+31],byte 1
mov eax,-1
int 0x40
no_channel_leave:
 
call check_mouse
 
mov eax,23
mov ebx,1
int 0x40
 
cmp eax,1
jne no_draw_window
call thread_draw_window
call draw_channel_text
call print_user_list
no_draw_window:
 
cmp eax,2
je thread_key
 
cmp eax,3
jne no_end
mov eax,17
int 0x40
mov eax,ebp
imul eax,120*80
add eax,I_END
cmp [eax+120*60+8],byte 0 ; channel window
je not_close
mov eax,ebp
shl eax,5
add eax,channel_list
mov [eax],dword ' '
mov [eax+31],byte 1
mov eax,-1
int 0x40
not_close:
mov [text_start],eax
mov eax,nocl
newcc:
mov bl,[eax]
call print_character
inc eax
cmp [eax],byte 0
jne newcc
call draw_channel_text
jmp w_t
nocl: db 13,10,'To exit channel, use PART or QUIT command.',0
no_end:
 
cmp [edx+120*60],byte 1
jne no_update
mov [edx+120*60],byte 0
call draw_channel_text
no_update:
 
test [cursor_on_off],0x3f
jnz nopri2
 
call blink_cursor
call print_user_list
 
nopri2:
 
jmp w_t
 
 
 
check_mouse:
 
pusha
 
mov eax,37
mov ebx,1
int 0x40
 
mov ebx,eax
shr eax,16
and ebx,0xffff
 
cmp eax,420
jb no_mouse
cmp eax,494
jg no_mouse
 
cmp ebx,145
jg no_mouse
cmp ebx,23
jb no_mouse
 
 
cmp ebx,100
jb no_plus
mov eax,ebp
imul eax,120*80
add eax,120*70+I_END
inc dword [eax-8]
call print_user_list
mov eax,5
mov ebx,8
int 0x40
jmp no_mouse
no_plus:
 
cmp ebx,80
jg no_mouse
mov eax,ebp
imul eax,120*80
add eax,120*70+I_END
cmp dword [eax-8],dword 0
je no_mouse
dec dword [eax-8]
call print_user_list
mov eax,5
mov ebx,8
int 0x40
 
no_minus:
 
no_mouse:
 
popa
 
ret
 
 
 
 
thread_key:
 
mov eax,2
int 0x40
 
shr eax,8
 
cmp eax,8
jne no_bks
cmp [xpos],0
je w_t
dec [xpos]
call print_entry
jmp w_t
no_bks:
 
cmp eax,20
jbe no_character
mov ebx,[xpos]
mov [send_string+ebx],al
inc [xpos]
cmp [xpos],80
jb xpok
mov [xpos],79
xpok:
call print_entry
jmp w_t
no_character:
 
cmp eax,13
jne no_send
cmp [xpos],0
je no_send
mov dword [send_to_channel],ebp
mov [send_to_server],1
wait_for_sending:
mov eax,5
mov ebx,1
int 0x40
cmp [send_to_server],1
je wait_for_sending
call draw_channel_text
call print_entry
jmp w_t
no_send:
 
jmp w_t
 
 
 
 
 
 
draw_channel_text:
 
pusha
 
mov eax,4
mov ebx,10*65536+26
mov ecx,12
mov esi,[rxs]
dct:
pusha
mov cx,bx
shl ecx,16
mov cx,9
mov eax,13
mov ebx,10*65536
mov bx,word [rxs]
imul bx,6
mov edx,0xffffff
int 0x40
popa
push ecx
mov eax,4
mov ecx,0
cmp [edx],word '* '
jne no_red
mov ecx,0x0000ff
no_red:
cmp [edx],word '**'
jne no_light_blue
cmp [edx+2],byte '*'
jne no_light_blue
mov ecx,0x0000ff
no_light_blue:
cmp [edx],byte '#'
jne no_blue
mov ecx,0x0000ff
no_blue:
int 0x40
add edx,[rxs]
add ebx,10
pop ecx
loop dct
 
popa
ret
 
 
 
 
 
thread_draw_window:
 
pusha
 
mov eax,12
mov ebx,1
int 0x40
 
mov ebx,ebp ; draw window
shl ebx,16+4
mov eax,0
mov ecx,ebx
mov bx,499
mov cx,170
 
; mov edx,ebp ; draw window
; imul edx,120*80
; add edx,I_END+120*60+8
; movzx edx,byte [edx]
; imul edx,88
; sub bx,dx
 
mov edx,[wcolor]
add edx,0x03ffffff
mov esi,0x80555599
mov edi,0x00ffffff
 
int 0x40
 
mov eax,ebp ; label
add eax,48
mov [labelc+14],al
mov eax,ebp
shl eax,5
add eax,channel_list
mov esi,eax
mov edi,labelc+17
movzx ecx,byte [eax+31]
cld
rep movsb
 
mov esi,17 ; print label
movzx ebx,byte [eax+31]
add esi,ebx
mov eax,4
mov ebx,9*65536+8
mov ecx,0x00ffffff
mov edx,labelc
int 0x40
 
mov eax,38 ; line
mov ebx,5*65536+494
mov ecx,148*65536+148
mov edx,[channel_line_sun]
int 0x40
add ecx,1*65536+1
mov edx,[channel_line_shadow]
int 0x40
 
 
mov eax,38 ; line
mov ebx,410*65536+410
mov ecx,22*65536+148
mov edx,[channel_line_sun]
int 0x40
add ebx,1*65536+1
mov edx,[channel_line_shadow]
int 0x40
 
mov eax,12
mov ebx,2
int 0x40
 
popa
 
ret
 
 
 
; DATA AREA
 
socket dd 0x0
 
bgc dd 0x000000
dd 0x000000
dd 0x00ff00
dd 0x0000ff
dd 0x005500
dd 0xff00ff
dd 0x00ffff
dd 0x770077
 
tc dd 0xffffff
dd 0xff00ff
dd 0xffffff
dd 0xffffff
dd 0xffffff
dd 0xffffff
dd 0xffffff
dd 0xffffff
 
channel_line_sun dd 0x9999ff
channel_line_shadow dd 0x666699
 
cursor_on_off dd 0x0
 
max_windows dd 20
 
thread_stack dd 0x9fff0
thread_nro dd 1
thread_screen dd I_END+120*80*1
 
action_header_blue db 10,'*** ',0
action_header_red db 10,'*** ',0
 
action_header_short db 10,'* ',0
 
has_left_channel db ' left channel ',0
joins_channel db ' joined channel ',0
is_now_known_as db ' is now known as ',0
has_quit_irc db ' has quit irc',0
sets_mode db ' sets mode ',0
kicked db ' kicked from ',0
 
index_list_1 dd 0x0000bb
index_list_2 dd 0x0000ff
 
posx dd 0x0
incoming_pos dd 0x0
incoming_string: times 128 db 0
 
pos dd 0x0
 
text_start dd I_END
irc_data dd 0x0
print db 0x0
cmd dd 0x0
rxs dd 66
 
res: db 0,0
command: times 600 db 0x0
 
nick dd 0,0,0
irc_command dd 0,0
 
command_position dd 0x0
counter dd 0
send_to_server db 0
 
channel_list: times 32*20 db 32
send_to_channel dd 0x0
 
send_string_header: db 'privmsg #eax :'
times 100 db 0x0
 
send_string: times 100 db 0x0
xpos dd 0
 
string0: db 'USER guest ser1 ser2 :'
string0l:
string1: db 'nick '
string1l:
 
attribute dd 0
scroll dd 1
dd 12
 
numtext db ' '
 
wcolor dd 0x000000
 
labelc db 'AIRC - WINDOW X: #xxx '
labelt db 'IRC client ',version
labellen:
 
;;
;; Channel data at I_END
;;
;; 120*80 * channel window (1+)
;;
;; At Size
;;
;; 00 , 120*60 window text 120 characters per row
;; 120*60 , 1 text is updated
;; 120*60+4 , 1 close yourself
;; 120*60+8 , 1 0 = channel window : 1 = private chat
;; 120*61 , 256 channel name
;; 120*61+254 , 254 channel entry text from user
;; 120*61+255 , 1 length of entry text
;; 120*69+248 , 4 display names from n:th name
;; 120*69+252 , 4 length of names string
;; 120*70 , 1200 names separated with space
;;
I_END: ;;
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/airc/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm airc.asm airc
@pause
/programs/network/airc/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm airc.asm airc
@pause
/programs/network/airc/trunk/macros.inc
0,0 → 1,266
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/arpstat/trunk/arpstat.asm
0,0 → 1,442
;
; ARP Status Monitor
;
; Compile with FASM for Menuet
;
; This program displays the ARP table, and it's settings
use32
org 0x0
db 'MENUET00' ; 8 byte id
dd 38 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
dd 0x00000000 ; reserved=no extended header
include 'lang.inc'
include 'macros.inc'
START: ; start of execution
call draw_window ; at first, draw the window
still:
mov eax,23 ; wait here for event
mov ebx,200 ; Time out after 2s
int 0x40
cmp eax,1 ; redraw request ?
jz red
cmp eax,2 ; key in buffer ?
jz key
cmp eax,3 ; button in buffer ?
jz button
; read the stack status data, and write it to the screen buffer
 
mov eax, 53
mov ebx, 255
mov ecx, 200
int 0x40
 
push eax
mov ebx, text + 24
call printhex
 
mov eax, 53
mov ebx, 255
mov ecx, 201
int 0x40
mov ebx, text + 64
call printhex
; Fill the table with blanks
mov edx, text + 160
doBlank:
mov esi, blank
mov edi, edx
mov ecx, 40
rep movsb
add edx, 40
 
cmp edx, text + 560
jne doBlank
pop ecx ; The number of entries
mov ebx, text+ 160 +1 ; the position for the first IP address line
xor edx, edx ; edx is index into the ARP table
 
cmp ecx, 10
jle show_entries
mov ecx, 10
; The following code is not very efficient; Sorry about that.
; ARPSTAT is a debugging tool, so I didn't want to put much effort in
show_entries:
; Ecx now holds the number of entries to populate.
; Ebx holds the place to put the data
; edx is a counter
cmp ecx, 0
je red
push ecx
push edx
push ebx
 
; select the arp table entry (in edx)
mov eax, 53
mov ebx, 255
mov ecx, 202
int 0x40
; Read the IP address
mov eax, 53
mov ebx, 255
mov ecx, 203
int 0x40
; IP in eax. Get the address to put it back
pop ebx
push ebx
call writeDecimal ; Extract 1 byte from eax, store it in string
add ebx, 4
shr eax, 8
call writeDecimal ; Extract 1 byte from eax, store it in string
add ebx, 4
shr eax, 8
call writeDecimal ; Extract 1 byte from eax, store it in string
add ebx, 4
shr eax, 8
call writeDecimal ; Extract 1 byte from eax, store it in string
 
add ebx, 4
; Now display the 6 byte MAC
push ebx
mov eax, 53
mov ebx, 255
mov ecx, 204
int 0x40
pop ebx
mov ecx, eax
 
shr eax, 4
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 12
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 8
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 20
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 16
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 28
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 24
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
 
push ebx
mov eax, 53
mov ebx, 255
mov ecx, 205
int 0x40
pop ebx
mov ecx, eax
 
shr eax, 4
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 12
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 8
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
 
; Now display the stat field
inc ebx
inc ebx
push ebx
mov eax, 53
mov ebx, 255
mov ecx, 206
int 0x40
pop ebx
mov ecx, eax
 
shr eax, 4
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 12
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 8
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
; Now display the TTL field (this is intel word format)
inc ebx
inc ebx
push ebx
mov eax, 53
mov ebx, 255
mov ecx, 207
int 0x40
pop ebx
mov ecx, eax
 
shr eax, 12
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 8
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
shr eax, 4
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
inc ebx
mov eax, ecx
and eax, 0x0f
mov al, [eax + hextable]
mov [ebx], al
 
pop ebx
add ebx, 40
pop edx
inc edx
pop ecx
dec ecx
jmp show_entries
 
red: ; redraw
call draw_window
jmp still
key: ; Keys are not valid at this part of the
mov eax,2 ; loop. Just read it and ignore
int 0x40
jmp still
button: ; button
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jnz still
 
mov eax,0xffffffff ; close this program
int 0x40
 
jmp still
 
 
 
writeDecimal:
pusha
and eax, 0xff
mov ecx, eax
mov dl, 100
div dl
mov cl, ah
add al, '0'
mov [ebx], al
inc ebx
mov eax, ecx
mov dl, 10
div dl
mov cl, ah
add al, '0'
mov [ebx], al
inc ebx
mov al, ah
add al, '0'
mov [ebx], al
popa
ret
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+280 ; [x start] *65536 + [x size]
mov ecx,100*65536+270 ; [y start] *65536 + [y size]
mov edx,0x03224466 ; color of work area RRGGBB
mov esi,0x00334455 ; color of grab bar RRGGBB,8->color gl
mov edi,0x00ddeeff ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ffffff ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
; Re-draw the screen text
cld
mov ebx,25*65536+35 ; draw info text with function 4
mov ecx,0xffffff
mov edx,text
mov esi,40
newline:
mov eax,4
int 0x40
add ebx,16
add edx,40
cmp [edx],byte 'x'
jnz newline
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; Taken from PS.ASM
printhex:
; number in eax
; print to ebx
; xlat from hextable
pusha
mov esi, ebx
add esi, 8
mov ebx, hextable
mov ecx, 8
phex_loop:
mov edx, eax
and eax, 15
xlatb
mov [esi], al
mov eax, edx
shr eax, 4
dec esi
loop phex_loop
popa
ret
; DATA AREA
text:
db ' Number of ARP entries: xxxxxxxx '
db ' Maximum # of entries : xxxxxxxx '
db ' '
db ' IP Address MAC Stat TTL '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
db 'x <- END MARKER, DONT DELETE '
 
blank:
db ' xxx.xxx.xxx.xxx xxxxxxxxxxxx xxxx xxxx '
 
labelt:
db 'ARP Table ( First 10 Entries )'
labellen:
hextable db '0123456789ABCDEF'
 
 
I_END:
 
 
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/arpstat/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm arpstat.asm arpstat
@pause
/programs/network/arpstat/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm arpstat.asm arpstat
@pause
/programs/network/arpstat/trunk/macros.inc
0,0 → 1,266
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/autodhcp/trunk/MACROS.INC
0,0 → 1,268
; 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
}
 
 
 
; language for programs
lang fix ru ; ru en fr ge fi
 
 
 
; optimize the code for size
__regs fix <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
/programs/network/autodhcp/trunk/autodhcp.asm
0,0 → 1,501
;
; Automated dhcp client
;
; v 1.1
;
; by the hidden player
;
 
DEBUG equ 1
TIMEOUT equ 60 ; in seconds
 
use32
 
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd IM_END ; size of image
dd I_END ; memory for app
dd I_END ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
 
include 'macros.inc'
 
if DEBUG = 1
include 'debug.inc'
end if
 
 
START: ; start of execution
 
mov eax,40 ; Report events
mov ebx,10000000b ; Only Stack
int 0x40
 
mov eax,52 ; first, enable the stack
mov ebx,2
mov ecx,0x00000383
int 0x40
 
if DEBUG = 1
newline
dps "DHCP: Stack Initialized"
newline
end if
 
mov eax, 53 ; then, read in the status
mov ebx, 255
mov ecx, 6
int 0x40
 
cmp eax,0 ; if eax is zero, no driver was found
jne @f
 
if DEBUG = 1
dps "DHCP: No Card detected"
newline
end if
 
jmp close
 
@@:
if DEBUG = 1
dps "DHCP: Detected card: "
dph eax
newline
end if
 
; now that the stack is running, lets start the dhcp request
 
; First, open socket
mov eax, 53
mov ebx, 0
mov ecx, 68 ; local port dhcp client
mov edx, 67 ; remote port - dhcp server
mov esi, -1 ; broadcast
int 0x40
 
mov [socketNum], eax
 
if DEBUG = 1
dps "DHCP: Socket opened: "
dpd eax
newline
end if
 
; Setup the first msg we will send
mov byte [dhcpMsgType], 0x01 ; DHCP discover
mov dword [dhcpLease], esi ; esi is still -1 (-1 = forever)
 
;***************************************************************************
; Function
; buildRequest
;
; Description
; Creates a DHCP request packet.
;
;***************************************************************************
buildRequest:
; Clear dhcpMsg to all zeros
xor eax,eax
mov edi,dhcpMsg
mov ecx,512
cld
rep stosb
 
mov edx, dhcpMsg
 
mov [edx], byte 0x01 ; Boot request
mov [edx+1], byte 0x01 ; Ethernet
mov [edx+2], byte 0x06 ; Ethernet h/w len
mov [edx+4], dword 0x11223344 ; xid
mov [edx+10], byte 0x80 ; broadcast flag set
mov [edx+236], dword 0x63538263 ; magic number
 
; option DHCP msg type
mov [edx+240], word 0x0135
mov al, [dhcpMsgType]
mov [edx+240+2], al
 
; option Lease time = infinity
mov [edx+240+3], word 0x0433
mov eax, [dhcpLease]
mov [edx+240+5], eax
 
; ; option requested IP address
mov [edx+240+9], word 0x0432
; mov eax, [dhcpClientIP]
; mov [edx+240+11], eax
 
; option request list
mov [edx+240+15], word 0x0437
mov [edx+240+17], dword 0x0f060301
 
; Check which msg we are sending
cmp [dhcpMsgType], byte 0x01
jne br001
 
; "Discover" options
; end of options marker
mov [edx+240+21], byte 0xff
 
mov [dhcpMsgLen], dword 262
jmp ctr000
 
br001:
; "Request" options
 
; server IP
mov [edx+240+21], word 0x0436
mov eax, [dhcpServerIP]
mov [edx+240+23], eax
 
; end of options marker
mov [edx+240+27], byte 0xff
 
mov [dhcpMsgLen], dword 268
 
ctr000:
 
; write to socket ( send broadcast request )
mov eax, 53
mov ebx, 4
mov ecx, [socketNum]
mov edx, [dhcpMsgLen]
mov esi, dhcpMsg
int 0x40
 
; Setup the DHCP buffer to receive response
 
mov eax, dhcpMsg
mov [dhcpMsgLen], eax ; Used as a pointer to the data
 
; now, we wait for data from remote
 
wait_for_data:
mov eax,23 ; wait here for event NOTE a TIME-OUT should be placed here
mov ebx,TIMEOUT*100
int 0x40
 
; Any data in the UDP receive buffer?
mov eax, 53
mov ebx, 2
mov ecx, [socketNum]
int 0x40
 
cmp eax, 0
jne ctr002
 
if DEBUG = 1
dps "DHCP: Timeout!"
newline
end if
 
jmp close
 
; we have data - this will be the response
ctr002:
 
mov eax, 53
mov ebx, 3
mov ecx, [socketNum]
int 0x40 ; read byte - block (high byte)
 
; Store the data in the response buffer
mov eax, [dhcpMsgLen]
mov [eax], bl
inc dword [dhcpMsgLen]
 
mov eax, 53
mov ebx, 2
mov ecx, [socketNum]
int 0x40 ; any more data?
 
cmp eax, 0
jne ctr002 ; yes, so get it
 
; depending on which msg we sent, handle the response
; accordingly.
; If the response is to a dhcp discover, then:
; 1) If response is DHCP OFFER then
; 1.1) record server IP, lease time & IP address.
; 1.2) send a request packet
; 2) else exit ( display error )
; If the response is to a dhcp request, then:
; 1) If the response is DHCP ACK then
; 1.1) extract the DNS & subnet fields. Set them in the stack
; 2) else exit ( display error )
 
 
cmp [dhcpMsgType], byte 0x01 ; did we send a discover?
je discover
cmp [dhcpMsgType], byte 0x03 ; did we send a request?
je request
 
; should never get here - we only send discover or request
jmp close
 
discover:
 
call parseResponse
 
; Was the response an offer? It should be
cmp [dhcpMsgType], byte 0x02
jne close ; NO - so quit
 
; send request
mov [dhcpMsgType], byte 0x03 ; DHCP request
jmp buildRequest
 
request:
 
call parseResponse
 
; Was the response an ACK? It should be
cmp [dhcpMsgType], byte 0x05
jne close ; NO - so quit
 
close:
 
; close socket
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
 
if DEBUG = 1
dps "DHCP: Exiting"
newline
end if
 
mov eax,-1 ; at last, exit
int 0x40
 
 
;***************************************************************************
; Function
; parseResponse
;
; Description
; extracts the fields ( client IP address and options ) from
; a DHCP response
; The values go into
; dhcpMsgType,dhcpLease,dhcpClientIP,dhcpServerIP,
; dhcpDNSIP, dhcpSubnet
; The message is stored in dhcpMsg
;
;***************************************************************************
parseResponse:
 
if DEBUG = 1
dps "DHCP: Data received, parsing response"
newline
end if
 
mov edx, dhcpMsg
 
pusha
 
mov eax,52 ; Set Client IP
mov ebx,3
mov ecx, [edx+16]
int 0x40
 
if DEBUG = 1
dps "DHCP: Client: "
 
xor esi,esi
.loop:
 
pusha
movzx eax,byte[edx+esi+16]
call debug_outdec
popa
 
inc esi
cmp esi,4
jne .loop
 
newline
end if
 
popa
 
; Scan options
 
add edx, 240 ; Point to first option
 
pr001:
; Get option id
mov al, [edx]
cmp al, 0xff ; End of options?
je pr_exit
 
cmp al, 53 ; Msg type is a single byte option
jne pr002
 
mov al, [edx+2]
mov [dhcpMsgType], al
add edx, 3
jmp pr001 ; Get next option
 
pr002:
; All other (accepted) options are 4 bytes in length
inc edx
movzx ecx, byte [edx]
inc edx ; point to data
 
cmp al, 54 ; server id
jne pr0021
mov eax, [edx] ; All options are 4 bytes, so get it
mov [dhcpServerIP], eax
jmp pr003
 
pr0021:
cmp al, 51 ; lease
jne pr0022
 
if DEBUG = 1
pusha
dps "DHCP: lease: "
 
cmp dword[edx],-1
jne no_lease_forever
dps "forever"
jmp lease_newline
no_lease_forever:
dpd [edx]
lease_newline:
newline
popa
end if
 
jmp pr003
 
pr0022:
cmp al, 1 ; subnet mask
jne pr0023
 
pusha
mov eax,52
mov ebx,12
mov ecx,[edx]
int 0x40
 
 
if DEBUG = 1
dps "DHCP: Subnet: "
 
xor esi,esi
.loop:
 
pusha
movzx eax,byte[edx+esi]
call debug_outdec
popa
 
inc esi
cmp esi,4
jne .loop
 
newline
end if
 
popa
 
jmp pr003
 
pr0023:
cmp al, 6 ; dns ip
jne pr0024
 
pusha
 
mov eax,52
mov ebx,14
mov ecx,[edx]
int 0x40
 
 
if DEBUG = 1
dps "DHCP: DNS IP: "
 
xor esi,esi
.loop:
 
pusha
movzx eax,byte[edx+esi]
call debug_outdec
popa
 
inc esi
cmp esi,4
jne .loop
 
newline
end if
 
popa
 
pr0024:
cmp al, 3 ; gateway ip
jne pr003
 
pusha
 
mov eax,52
mov ebx,11
mov ecx,[edx]
int 0x40
 
 
if DEBUG = 1
dps "DHCP: Gateway:"
 
xor esi,esi
.loop:
 
pusha
movzx eax,byte[edx+esi]
call debug_outdec
popa
 
inc esi
cmp esi,4
jne .loop
 
newline
end if
 
popa
 
pr003:
add edx, ecx
jmp pr001
 
pr_exit:
 
if DEBUG = 1
dps "DHCP: Done"
newline
end if
 
jmp close
 
 
; DATA AREA
 
IM_END:
 
dhcpMsgType: db 0
dhcpLease: dd 0
;dhcpClientIP: dd 0
dhcpServerIP: dd 0
 
dhcpMsgLen: dd 0
socketNum: dd 0xFFFF
dhcpMsg: rb 512
 
I_END:
/programs/network/autodhcp/trunk/debug.inc
0,0 → 1,131
macro debug_print str
{
local ..string, ..label
 
jmp ..label
..string db str,0
..label:
 
pushf
pushad
mov edx,..string
call debug_outstr
popad
popf
}
 
dps fix debug_print
 
macro debug_print_dec arg
{
pushf
pushad
if ~arg eq eax
mov eax,arg
end if
call debug_outdec
popad
popf
}
 
dpd fix debug_print_dec
 
;---------------------------------
debug_outdec: ;(eax - num, edi-str)
push 10 ;2
pop ecx ;1
push -'0' ;2
.l0:
xor edx,edx ;2
div ecx ;2
push edx ;1
test eax,eax ;2
jnz .l0 ;2
.l1:
pop eax ;1
add al,'0' ;2
call debug_outchar ; stosb
jnz .l1 ;2
ret ;1
;---------------------------------
 
debug_outchar: ; al - char
pushf
pushad
mov cl,al
mov eax,63
mov ebx,1
int 0x40
popad
popf
ret
 
debug_outstr:
mov eax,63
mov ebx,1
@@:
mov cl,[edx]
test cl,cl
jz @f
int 40h
inc edx
jmp @b
@@:
ret
 
 
macro newline
{
dps <13,10>
}
 
macro print message
{
dps message
newline
}
 
macro pregs
{
dps "EAX: "
dpd eax
dps " EBX: "
dpd ebx
newline
dps "ECX: "
dpd ecx
dps " EDX: "
dpd edx
newline
}
 
macro debug_print_hex arg
{
pushf
pushad
if ~arg eq eax
mov eax, arg
end if
call debug_outhex
popad
popf
}
dph fix debug_print_hex
 
debug_outhex:
; eax - number
mov edx, 8
.new_char:
rol eax, 4
movzx ecx, al
and cl, 0x0f
mov cl, [__hexdigits + ecx]
pushad
mcall 63, 1
popad
dec edx
jnz .new_char
ret
 
__hexdigits:
db '0123456789ABCDEF'
/programs/network/dhcp/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm dhcp.asm dhcp
@pause
/programs/network/dhcp/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm dhcp.asm dhcp
@pause
/programs/network/dhcp/trunk/dhcp.asm
0,0 → 1,595
;
; DHCP Client
;
; Compile with FASM for Menuet
;
 
include 'lang.inc'
include 'macros.inc'
 
use32
 
org 0x0
 
db 'MENUET00' ; 8 byte id
dd 38 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
dd 0x00000000 ; reserved=no extended header
 
 
START: ; start of execution
mov eax,40 ; Report events
mov ebx,10000111b ; Stack 8 + defaults
int 0x40
 
call draw_window ; at first, draw the window
 
still:
mov eax,10 ; wait here for event
int 0x40
 
cmp eax,1 ; redraw request ?
jz red
cmp eax,2 ; key in buffer ?
jz key
cmp eax,3 ; button in buffer ?
jz button
 
jmp still
 
red: ; redraw
call draw_window
jmp still
 
key: ; Keys are not valid at this part of the
mov eax,2 ; loop. Just read it and ignore
int 0x40
jmp still
 
button: ; button
mov eax,17 ; get id
int 0x40
 
cmp ah,1 ; button id=1 ?
jnz noclose
 
; close socket before exiting
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
 
mov eax,0xffffffff ; close this program
int 0x40
 
noclose:
cmp ah,3 ; Resolve address?
jnz still
 
call draw_window
 
call contactDHCPServer
 
jmp still
 
 
;***************************************************************************
; Function
; parseResponse
;
; Description
; extracts the fields ( client IP address and options ) from
; a DHCP response
; The values go into
; dhcpMsgType,dhcpLease,dhcpClientIP,dhcpServerIP,
; dhcpDNSIP, dhcpSubnet
; The message is stored in dhcpMsg
;
;***************************************************************************
parseResponse:
mov edx, dhcpMsg
 
mov eax, [edx+16]
mov [dhcpClientIP], eax
 
; Scan options
 
add edx, 240 ; Point to first option
 
pr001:
; Get option id
mov al, [edx]
cmp al, 0xff ; End of options?
je pr_exit
 
cmp al, 53 ; Msg type is a single byte option
jne pr002
 
mov al, [edx+2]
mov [dhcpMsgType], al
add edx, 3
jmp pr001 ; Get next option
 
pr002:
; All other (accepted) options are 4 bytes in length
inc edx
movzx ecx, byte [edx]
inc edx ; point to data
 
cmp al, 54 ; server id
jne pr0021
mov eax, [edx] ; All options are 4 bytes, so get it
mov [dhcpServerIP], eax
jmp pr003
 
pr0021:
cmp al, 51 ; lease
jne pr0022
mov eax, [edx] ; All options are 4 bytes, so get it
mov [dhcpLease], eax
jmp pr003
 
pr0022:
cmp al, 1 ; subnet mask
jne pr0023
mov eax, [edx] ; All options are 4 bytes, so get it
mov [dhcpSubnet], eax
jmp pr003
 
pr0023:
cmp al, 6 ; dns ip
jne pr0024
mov eax, [edx] ; All options are 4 bytes, so get it
mov [dhcpDNSIP], eax
 
pr0024:
cmp al, 3 ; gateway ip
jne pr003
mov eax, [edx] ; All options are 4 bytes, so get it
mov [dhcpGateway], eax
 
pr003:
add edx, ecx
jmp pr001
 
pr_exit:
ret
 
 
;***************************************************************************
; Function
; buildRequest
;
; Description
; Creates a DHCP request packet.
;
;***************************************************************************
buildRequest:
; Clear dhcpMsg to all zeros
xor eax,eax
mov edi,dhcpMsg
mov ecx,512
cld
rep stosb
 
mov edx, dhcpMsg
 
mov [edx], byte 0x01 ; Boot request
mov [edx+1], byte 0x01 ; Ethernet
mov [edx+2], byte 0x06 ; Ethernet h/w len
mov [edx+4], dword 0x11223344 ; xid
mov [edx+10], byte 0x80 ; broadcast flag set
mov [edx+236], dword 0x63538263 ; magic number
 
; option DHCP msg type
mov [edx+240], word 0x0135
mov al, [dhcpMsgType]
mov [edx+240+2], al
 
; option Lease time = infinity
mov [edx+240+3], word 0x0433
mov eax, [dhcpLease]
mov [edx+240+5], eax
 
; option requested IP address
mov [edx+240+9], word 0x0432
mov eax, [dhcpClientIP]
mov [edx+240+11], eax
 
; option request list
mov [edx+240+15], word 0x0437
mov [edx+240+17], dword 0x0f060301
 
; Check which msg we are sending
cmp [dhcpMsgType], byte 0x01
jne br001
 
; "Discover" options
; end of options marker
mov [edx+240+21], byte 0xff
 
mov [dhcpMsgLen], dword 262
jmp br_exit
 
br001:
; "Request" options
 
; server IP
mov [edx+240+21], word 0x0436
mov eax, [dhcpServerIP]
mov [edx+240+23], eax
 
; end of options marker
mov [edx+240+27], byte 0xff
 
mov [dhcpMsgLen], dword 268
 
br_exit:
ret
 
 
 
;***************************************************************************
; Function
; contactDHCPServer
;
; Description
; negotiates settings with a DHCP server
;
;***************************************************************************
contactDHCPServer:
; First, open socket
mov eax, 53
mov ebx, 0
mov ecx, 68 ; local port dhcp client
mov edx, 67 ; remote port - dhcp server
mov esi, 0xffffffff ; broadcast
int 0x40
 
mov [socketNum], eax
 
; Setup the first msg we will send
mov [dhcpMsgType], byte 0x01 ; DHCP discover
mov [dhcpLease], dword 0xffffffff
mov [dhcpClientIP], dword 0
mov [dhcpServerIP], dword 0
 
call buildRequest
 
ctr000:
; write to socket ( send broadcast request )
mov eax, 53
mov ebx, 4
mov ecx, [socketNum]
mov edx, [dhcpMsgLen]
mov esi, dhcpMsg
int 0x40
 
; Setup the DHCP buffer to receive response
 
mov eax, dhcpMsg
mov [dhcpMsgLen], eax ; Used as a pointer to the data
 
; now, we wait for
; UI redraw
; UI close
; or data from remote
 
ctr001:
mov eax,10 ; wait here for event
int 0x40
 
cmp eax,1 ; redraw request ?
je ctr003
cmp eax,2 ; key in buffer ?
je ctr004
cmp eax,3 ; button in buffer ?
je ctr005
 
 
; Any data in the UDP receive buffer?
mov eax, 53
mov ebx, 2
mov ecx, [socketNum]
int 0x40
 
cmp eax, 0
je ctr001
 
; we have data - this will be the response
ctr002:
mov eax, 53
mov ebx, 3
mov ecx, [socketNum]
int 0x40 ; read byte - block (high byte)
 
; Store the data in the response buffer
mov eax, [dhcpMsgLen]
mov [eax], bl
inc dword [dhcpMsgLen]
 
mov eax, 53
mov ebx, 2
mov ecx, [socketNum]
int 0x40 ; any more data?
 
cmp eax, 0
jne ctr002 ; yes, so get it
 
; depending on which msg we sent, handle the response
; accordingly.
; If the response is to a dhcp discover, then:
; 1) If response is DHCP OFFER then
; 1.1) record server IP, lease time & IP address.
; 1.2) send a request packet
; 2) else exit ( display error )
; If the response is to a dhcp request, then:
; 1) If the response is DHCP ACK then
; 1.1) extract the DNS & subnet fields. Set them in the stack
; 2) else exit ( display error )
 
 
cmp [dhcpMsgType], byte 0x01 ; did we send a discover?
je ctr007
cmp [dhcpMsgType], byte 0x03 ; did we send a request?
je ctr008
 
; should never get here - we only send discover or request
jmp ctr006
 
ctr007:
call parseResponse
 
; Was the response an offer? It should be
cmp [dhcpMsgType], byte 0x02
jne ctr006 ; NO - so quit
 
; send request
mov [dhcpMsgType], byte 0x03 ; DHCP request
call buildRequest
jmp ctr000
 
ctr008:
call parseResponse
 
; Was the response an ACK? It should be
cmp [dhcpMsgType], byte 0x05
jne ctr006 ; NO - so quit
 
; Set or display addresses here...
 
ctr006:
; close socket
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
 
mov [socketNum], dword 0xFFFF
 
call draw_window
 
jmp ctr001
 
ctr003: ; redraw
call draw_window
jmp ctr001
 
ctr004: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp ctr001
 
ctr005: ; button
mov eax,17 ; get id
int 0x40
 
; close socket
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
 
mov [socketNum], dword 0xFFFF
 
call draw_window ; at first, draw the window
 
ret
 
 
 
 
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
 
 
; Pass in the IP address in edi
; row to display in [ya]
drawIP:
; mov edi,hostIP
mov ecx, edi
add ecx, 4
mov edx,[ya]
add edx, 97*65536
mov esi,0x00ffffff
mov ebx,3*65536
 
ipdisplay:
mov eax,47
push ecx
movzx ecx,byte [edi]
int 0x40
pop ecx
add edx,6*4*65536
inc edi
cmp edi,ecx
jb ipdisplay
ret
 
 
drawDHMS:
 
mov eax,[edi]
bswap eax
 
mov esi,dhms
mov ecx,16
mov edi,text+40*4+12
cmp eax,0xffffffff
jne nforever
mov esi,forever
cld
rep movsb
ret
nforever:
cld
rep movsb
 
mov ecx,28
xor edx,edx
mov ebx,60
div ebx
call displayDHMS
xor edx,edx
div ebx
call displayDHMS
xor edx,edx
mov ebx,24
div ebx
call displayDHMS
mov edx,eax
call displayDHMS
 
ret
 
 
displayDHMS:
 
pusha
mov eax,47
mov ebx,3*65536
mov edx,ecx
imul edx,6
shl edx,16
add edx,1*65536+99
mov ecx,[esp+20]
mov esi,0xffffff
int 0x40
popa
sub ecx,4
ret
 
 
draw_window:
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+300 ; [x start] *65536 + [x size]
mov ecx,100*65536+156 ; [y start] *65536 + [y size]
mov edx,0x03224466 ; color of work area RRGGBB
mov esi,0x00334455 ; color of grab bar RRGGBB,8->color gl
mov edi,0x00ddeeff ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ffffff ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
 
mov eax,8 ; Resolve
mov ebx,20*65536+90
mov ecx,127*65536+15
mov edx,3
mov esi,0x557799
int 0x40
 
; Pass in the IP address in edi
; row to display in [ya]
mov edi, dhcpClientIP
mov eax, 35
mov [ya], eax
call drawIP
mov edi, dhcpGateway
mov eax, 35 + 16
mov [ya], eax
call drawIP
mov edi, dhcpSubnet
mov eax, 35 + 32
mov [ya], eax
call drawIP
mov edi, dhcpDNSIP
mov eax, 35 + 48
mov [ya], eax
call drawIP
mov edi, dhcpLease
call drawDHMS
 
; Re-draw the screen text
cld
mov ebx,25*65536+35 ; draw info text with function 4
mov ecx,0xffffff
mov edx,text
mov esi,40
 
newline:
mov eax,4
int 0x40
add ebx,16
add edx,40
cmp [edx],byte 'x'
jnz newline
 
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
ret
 
 
 
; DATA AREA
 
ya dd 0x0
 
text:
db 'Client IP : . . . '
db 'Gateway IP: . . . '
db 'Subnet : . . . '
db 'DNS IP : . . . '
db 'Lease Time: d h m s '
db ' '
db ' SEND REQUEST '
db 'x <- END MARKER, DONT DELETE '
 
 
dhms db ' d h m s'
forever db 'Forever '
 
labelt: db 'DHCP Client Test'
labellen:
 
dhcpMsgType: db 0
dhcpLease: dd 0
dhcpClientIP: dd 0
dhcpServerIP: dd 0
dhcpDNSIP: dd 0
dhcpSubnet: dd 0
dhcpGateway: dd 0
 
dhcpMsgLen: dd 0
socketNum: dd 0xFFFF
dhcpMsg:
I_END:
 
 
 
 
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/dhcp/trunk/macros.inc
0,0 → 1,266
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/dnsr/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm dnsr.asm dnsr
@pause
/programs/network/dnsr/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm dnsr.asm dnsr
@pause
/programs/network/dnsr/trunk/dnsr.asm
0,0 → 1,780
;
; DNS Domain name -> IP lookup
;
; Compile with FASM for Menuet
;
 
 
; If you like, you camd change the DNS server default by changing the
; IP address in the dnsServer string.
 
 
; Enabling debugging puts the received response to the
; debug board
DEBUGGING_ENABLED equ 1
DEBUGGING_DISABLED equ 0
DEBUGGING_STATE equ DEBUGGING_DISABLED
 
 
use32
 
org 0x0
 
db 'MENUET00' ; 8 byte id
dd 38 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
dd 0x00000000 ; reserved=no extended header
 
include 'lang.inc'
include 'macros.inc'
 
START: ; start of execution
mov eax,40 ; Report events
mov ebx,10000111b ; Stack 8 + defaults
int 0x40
 
mov dword [prompt], p1
mov dword [promptlen], p1len - p1 ; 'waiting for command'
 
call draw_window ; at first, draw the window
 
still:
mov eax,10 ; wait here for event
int 0x40
 
cmp eax,1 ; redraw request ?
jz red
cmp eax,2 ; key in buffer ?
jz key
cmp eax,3 ; button in buffer ?
jz button
 
jmp still
 
red: ; redraw
call draw_window
jmp still
 
key: ; Keys are not valid at this part of the
mov eax,2 ; loop. Just read it and ignore
int 0x40
jmp still
 
button: ; button
mov eax,17 ; get id
int 0x40
 
cmp ah,1 ; button id=1 ?
jnz noclose
 
; close socket before exiting
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
 
mov eax,0xffffffff ; close this program
int 0x40
 
noclose:
cmp ah,3 ; Resolve address?
jnz noresolve
 
mov dword [prompt], p5
mov dword [promptlen], p5len - p5 ; display 'Resolving'
call draw_window
 
call translateData ; Convert domain & DNS IP address
 
call resolveDomain
 
jmp still
 
 
noresolve:
cmp ah,4
jz f1 ; Enter domain name
cmp ah,5
jz f2 ; enter DNS Server IP
jmp still
 
 
f1:
mov [addr],dword query
mov [ya],dword 35
jmp rk
 
f2:
mov [addr],dword dnsServer
mov [ya],dword 35+16
 
rk:
mov ecx,26
mov edi,[addr]
mov al,' '
rep stosb
 
call print_text
 
mov edi,[addr]
 
f11:
mov eax,10
int 0x40
cmp eax,2
jz fbu
jmp still
 
fbu:
mov eax,2
int 0x40 ; get key
shr eax,8
cmp eax,8
jnz nobs
cmp edi,[addr]
jz f11
sub edi,1
mov [edi],byte ' '
call print_text
jmp f11
 
nobs:
cmp eax,dword 31
jbe f11
cmp eax,dword 95
jb keyok
sub eax,32
 
keyok:
mov [edi],al
 
call print_text
 
add edi,1
mov esi,[addr]
add esi,26
cmp esi,edi
jnz f11
 
jmp still
 
 
 
print_text:
mov eax,13
mov ebx,103*65536+26*6
mov ecx,[ya]
shl ecx,16
mov cx,8
mov edx,0x224466
int 0x40
 
mov eax,4
mov ebx,103*65536
add ebx,[ya]
mov ecx,0xffffff
mov edx,[addr]
mov esi,26
int 0x40
 
ret
 
 
 
;***************************************************************************
; Function
; translateData
;
; Description
; Coverts the domain name and DNS IP address typed in by the user into
; a format suitable for the IP layer.
;
; The ename, in query, is converted and stored in dnsMsg
; The DNS ip, in dnsServer, is converted and stored in dnsIP
;
;***************************************************************************
translateData:
 
; first, get the IP address of the DNS server
; Then, build up the request string.
 
xor eax, eax
mov dh, 10
mov dl, al
mov [dnsIP], eax
 
mov esi, dnsServer
mov edi, dnsIP
 
mov ecx, 4
 
td003:
lodsb
sub al, '0'
add dl, al
lodsb
cmp al, '.'
je ipNext
cmp al, ' '
je ipNext
mov dh, al
sub dh, '0'
mov al, 10
mul dl
add al, dh
mov dl, al
lodsb
cmp al, '.'
je ipNext
cmp al, ' '
je ipNext
mov dh, al
sub dh, '0'
mov al, 10
mul dl
add al, dh
mov dl, al
lodsb
 
ipNext:
mov [edi], dl
inc edi
mov dl, 0
loop td003
 
; Build the request string
 
 
mov eax, 0x00010100
mov [dnsMsg], eax
mov eax, 0x00000100
mov [dnsMsg+4], eax
mov eax, 0x00000000
mov [dnsMsg+8], eax
 
; domain name goes in at dnsMsg+12
mov esi, dnsMsg + 12 ; location of label length
mov edi, dnsMsg + 13 ; label start
mov edx, query
mov ecx, 12 ; total string length so far
 
td002:
mov [esi], byte 0
inc ecx
 
td0021:
mov al, [edx]
cmp al, ' '
je td001 ; we have finished the string translation
cmp al, '.' ; we have finished the label
je td004
 
inc byte [esi]
inc ecx
mov [edi], al
inc edi
inc edx
jmp td0021
 
td004:
mov esi, edi
inc edi
inc edx
jmp td002
 
 
 
; write label len + label text
 
td001:
mov [edi], byte 0
inc ecx
inc edi
mov [edi], dword 0x01000100
add ecx, 4
 
mov [dnsMsgLen], ecx
 
ret
 
 
 
 
 
;***************************************************************************
; Function
; resolveDomain
;
; Description
; Sends a question to the dns server
; works out the IP address from the response from the DNS server
;
;***************************************************************************
resolveDomain:
; Get a free port number
mov ecx, 1000 ; local port starting at 1000
getlp:
inc ecx
push ecx
mov eax, 53
mov ebx, 9
int 0x40
pop ecx
cmp eax, 0 ; is this local port in use?
jz getlp ; yes - so try next
 
; First, open socket
mov eax, 53
mov ebx, 0
mov edx, 53 ; remote port - dns
mov esi, [dnsIP]
int 0x40
 
mov [socketNum], eax
 
; write to socket ( request DNS lookup )
mov eax, 53
mov ebx, 4
mov ecx, [socketNum]
mov edx, [dnsMsgLen]
mov esi, dnsMsg
int 0x40
 
; Setup the DNS response buffer
 
mov eax, dnsMsg
mov [dnsMsgLen], eax
 
; now, we wait for
; UI redraw
; UI close
; or data from remote
 
ctr001:
mov eax,10 ; wait here for event
int 0x40
 
cmp eax,1 ; redraw request ?
je ctr003
cmp eax,2 ; key in buffer ?
je ctr004
cmp eax,3 ; button in buffer ?
je ctr005
 
 
; Any data in the UDP receive buffer?
mov eax, 53
mov ebx, 2
mov ecx, [socketNum]
int 0x40
 
cmp eax, 0
je ctr001
 
; we have data - this will be the response
ctr002:
mov eax, 53
mov ebx, 3
mov ecx, [socketNum]
int 0x40 ; read byte - block (high byte)
 
; Store the data in the response buffer
mov eax, [dnsMsgLen]
mov [eax], bl
inc dword [dnsMsgLen]
 
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
call debug_print_rx_ip
end if
 
mov eax, 53
mov ebx, 2
mov ecx, [socketNum]
int 0x40 ; any more data?
 
cmp eax, 0
jne ctr002 ; yes, so get it
 
; close socket
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
 
mov [socketNum], dword 0xFFFF
 
; Now parse the message to get the host IP
; Man, this is complicated. It's described in
; RFC 1035
 
; 1) Validate that we have an answer with > 0 responses
; 2) Find the answer record with TYPE 0001 ( host IP )
; 3) Finally, copy the IP address to the display
; Note: The response is in dnsMsg
; The end of the buffer is pointed to by [dnsMsgLen]
 
; Clear the IP address text
mov [hostIP], dword 0
 
mov esi, dnsMsg
 
; Is this a response to my question?
mov al, [esi+2]
and al, 0x80
cmp al, 0x80
jne ctr002a
 
; Were there any errors?
mov al, [esi+3]
and al, 0x0F
cmp al, 0x00
jne ctr002a
 
; Is there ( at least 1 ) answer?
mov ax, [esi+6]
cmp ax, 0x00
je ctr002a
 
; Header validated. Scan through and get my answer
 
add esi, 12 ; Skip to the question field
 
; Skip through the question field
call skipName
add esi, 4 ; skip past the questions qtype, qclass
 
ctr002z:
; Now at the answer. There may be several answers,
; find the right one ( TYPE = 0x0001 )
call skipName
mov ax, [esi]
cmp ax, 0x0100 ; Is this the IP address answer?
jne ctr002c
 
; Yes! Point esi to the first byte of the IP address
add esi, 10
 
mov eax, [esi]
mov [hostIP], eax
jmp ctr002a ; And exit...
 
 
ctr002c: ; Skip through the answer, move to the next
add esi, 8
movzx eax, byte [esi+1]
mov ah, [esi]
add esi, eax
add esi, 2
 
; Have we reached the end of the msg?
; This is an error condition, should not happen
cmp esi, [dnsMsgLen]
jl ctr002z ; Check next answer
jmp ctr002a ; abort
 
 
ctr002a:
mov dword [prompt], p4 ; Display IP address
mov dword [promptlen], p4len - p4
call draw_window
 
jmp ctr001
 
ctr003: ; redraw
call draw_window
jmp ctr001
 
ctr004: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp ctr001
 
ctr005: ; button
mov eax,17 ; get id
int 0x40
 
; close socket
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
 
mov [socketNum], dword 0xFFFF
mov [hostIP], dword 0
 
mov dword [prompt], p1
mov dword [promptlen], p1len - p1 ; 'waiting for command'
 
call draw_window ; at first, draw the window
 
ret
 
 
 
;***************************************************************************
; Function
; skipName
;
; Description
; Increment esi to the first byte past the name field
; Names may use compressed labels. Normally do.
; RFC 1035 page 30 gives details
;
;***************************************************************************
skipName:
mov al, [esi]
cmp al, 0
je sn_exit
and al, 0xc0
cmp al, 0xc0
je sn001
 
movzx eax, byte [esi]
inc eax
add esi, eax
jmp skipName
 
sn001:
add esi, 2 ; A pointer is always at the end
ret
 
sn_exit:
inc esi
ret
 
 
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
 
 
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+300 ; [x start] *65536 + [x size]
mov ecx,100*65536+140 ; [y start] *65536 + [y size]
mov edx,0x03224466 ; color of work area RRGGBB
mov esi,0x00334455 ; color of grab bar RRGGBB,8->color gl
mov edi,0x00ddeeff ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ffffff ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
 
mov eax,8 ; Resolve
mov ebx,20*65536+190
mov ecx,79*65536+15
mov edx,3
mov esi,0x557799
int 0x40
 
mov eax,8
mov ebx,270*65536+10
mov ecx,34*65536+10
mov edx,4
mov esi,0x557799
int 0x40
 
mov eax,8
mov ebx,270*65536+10
mov ecx,50*65536+10
mov edx,5
mov esi,0x557799
int 0x40
 
; Copy the file name to the screen buffer
; file name is same length as IP address, to
; make the math easier later.
cld
mov esi,query
mov edi,text+13
mov ecx,26
rep movsb
 
 
; copy the IP address to the screen buffer
mov esi,dnsServer
mov edi,text+40+13
mov ecx,26
rep movsb
 
; copy the prompt to the screen buffer
mov esi,[prompt]
mov edi,text+200
mov ecx,[promptlen]
rep movsb
 
; Re-draw the screen text
cld
mov ebx,25*65536+35 ; draw info text with function 4
mov ecx,0xffffff
mov edx,text
mov esi,40
 
newline:
mov eax,4
int 0x40
add ebx,16
add edx,40
cmp [edx],byte 'x'
jnz newline
 
 
; Write the host IP, if we have one
mov eax, [hostIP]
cmp eax, 0
je dw001
 
; We have an IP address... display it
mov edi,hostIP
mov edx,97*65536+115
mov esi,0x00ffffff
mov ebx,3*65536
 
ipdisplay:
mov eax,47
movzx ecx,byte [edi]
int 0x40
add edx,6*4*65536
inc edi
cmp edi,hostIP+4
jb ipdisplay
 
dw001:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
ret
 
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
;****************************************************************************
; Function
; debug_print_string
;
; Description
; prints a string to the debug board
;
; esi holds ptr to msg to display
;
; Nothing preserved; I'm assuming a pusha/popa is done before calling
;
;****************************************************************************
debug_print_string:
mov cl, [esi]
cmp cl, 0
jnz dps_001
ret
 
dps_001:
mov eax,63
mov ebx, 1
push esi
int 0x40
 
inc word [ind]
mov ax, [ind]
and ax, 0x1f
cmp ax, 0
jne ds1
 
mov cl, 13
mov eax,63
mov ebx, 1
int 0x40
mov cl, 10
mov eax,63
mov ebx, 1
int 0x40
 
 
ds1:
pop esi
inc esi
jmp debug_print_string
 
 
ind: dw 0
; This is used for translating hex to ASCII for display or output
hexchars db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
IP_STR db 'xx',0
 
 
debug_print_rx_ip:
pusha
mov edi, IP_STR
 
xor eax, eax
mov al, bl
shr al, 4
mov ah, [eax + hexchars]
mov [edi], ah
inc edi
 
xor eax, eax
mov al, bl
and al, 0x0f
mov ah, [eax + hexchars]
mov [edi], ah
mov esi, IP_STR
 
call debug_print_string
popa
ret
end if
 
 
; DATA AREA
 
addr dd 0x0
ya dd 0x0
 
text:
db 'Host name : xxxxxxxxxxxxxxx '
db 'DNS server : xxx.xxx.xxx.xxx '
db ' '
db ' RESOLVE ADDRESS '
db ' '
db ' '
db 'x <- END MARKER, DONT DELETE '
 
 
labelt:
db 'DNS Client'
labellen:
 
 
prompt: dd 0
promptlen: dd 0
 
 
p1: db 'Waiting for Command '
p1len:
 
p4: db 'IP Address: . . . '
p4len:
 
p5: db 'Resolving... '
p5len:
 
 
dnsServer db '194.145.128.1 ' ; iolfree.ie DNS
query db 'WWW.MENUETOS.ORG '
 
hostIP: dd 0
dnsIP: dd 0
dnsMsgLen: dd 0
socketNum: dd 0xFFFF
dnsMsg:
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/dnsr/trunk/macros.inc
0,0 → 1,266
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/ethstat/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm ethstat.asm ethstat
@pause
/programs/network/ethstat/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm ethstat.asm ethstat
@pause
/programs/network/ethstat/trunk/ethstat.asm
0,0 → 1,228
;
; Stack Status Monitor
;
; Compile with FASM for Menuet
;
use32
org 0x0
db 'MENUET00' ; 8 byte id
dd 38 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
dd 0x00000000 ; reserved=no extended header
include 'lang.inc'
include 'macros.inc'
START: ; start of execution
call draw_window ; at first, draw the window
still:
mov eax,23 ; wait here for event
mov ebx,200 ; Time out after 2s
int 0x40
cmp eax,1 ; redraw request ?
jz red
cmp eax,2 ; key in buffer ?
jz key
cmp eax,3 ; button in buffer ?
jz button
; read the stack status data, and write it to the screen buffer
mov eax, 53
mov ebx, 255
mov ecx, 6
int 0x40
mov ebx, text + 24
call printhex
mov eax, 53
mov ebx, 255
mov ecx, 2
int 0x40
mov ebx, text + 107
call printhex
mov eax, 53
mov ebx, 255
mov ecx, 5
int 0x40
mov ebx, text + 107 + 40
call printhex
mov eax, 53
mov ebx, 255
mov ecx, 4
int 0x40
mov ebx, text + 107 + 80
call printhex
mov eax, 53
mov ebx, 255
mov ecx, 100
int 0x40
mov ebx, text + 258
call printhex
mov eax, 53
mov ebx, 255
mov ecx, 101
int 0x40
mov ebx, text + 258 + 40
call printhex
mov eax, 53
mov ebx, 255
mov ecx, 102
int 0x40
mov ebx, text + 258 + 80
call printhex
mov eax, 53
mov ebx, 255
mov ecx, 103
int 0x40
mov ebx, text + 258 + 120
call printhex
red: ; redraw
call draw_window
jmp still
key: ; Keys are not valid at this part of the
mov eax,2 ; loop. Just read it and ignore
int 0x40
jmp still
button: ; button
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jnz still
mov eax,0xffffffff ; close this program
int 0x40
jmp still
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+260 ; [x start] *65536 + [x size]
mov ecx,100*65536+205 ; [y start] *65536 + [y size]
mov edx,0x03224466 ; color of work area RRGGBB
mov esi,0x00334455 ; color of grab bar RRGGBB,8->color gl
mov edi,0x00ddeeff ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ffffff ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
; Re-draw the screen text
cld
mov ebx,25*65536+35 ; draw info text with function 4
mov ecx,0xffffff
mov edx,text
mov esi,40
newline:
mov eax,4
int 0x40
add ebx,16
add edx,40
cmp [edx],byte 'x'
jnz newline
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; Taken from PS.ASM
printhex:
; number in eax
; print to ebx
; xlat from hextable
pusha
mov esi, ebx
add esi, 8
mov ebx, hextable
mov ecx, 8
phex_loop:
mov edx, eax
and eax, 15
xlatb
mov [esi], al
mov eax, edx
shr eax, 4
dec esi
loop phex_loop
popa
ret
; DATA AREA
text:
db ' Ethernet card status : xxxxxxxx '
db ' '
db ' IP packets received : xxxxxxxx '
db ' ARP packets received : xxxxxxxx '
db ' Dumped received packets : xxxxxxxx '
db ' '
db ' EMPTY QUEUE : xxxxxxxx '
db ' IPOUT QUEUE : xxxxxxxx '
db ' IPIN QUEUE : xxxxxxxx '
db ' NET1OUT QUEUE : xxxxxxxx '
db 'x <- END MARKER, DONT DELETE '
labelt:
db 'Stack Status'
labellen:
hextable db '0123456789ABCDEF'
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/ethstat/trunk/macros.inc
0,0 → 1,267
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/httpc/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm httpc.asm httpc
@pause
/programs/network/httpc/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm httpc.asm httpc
@pause
/programs/network/httpc/trunk/httpc.asm
0,0 → 1,1529
;
; HTTPC.ASM
;
; Compile with FASM for Menuet ( v1.40 for DOS )
;
; This program implements a very simple web browser
;
; Version 0.4 2nd December 2003 Mike Hibbett
; Enabled lowercase/uppcase characters in URL
; Version 0.3 30th November 2003 Mike Hibbett
; Fixed bug with tcp socket opne - uses unique port
; Version 0.2 27th November 2003 Mike Hibbett
; Added user entry of url, and implements url -> IP address
; resolution through DNS
;
; Version 0.1 Ville Mikael Turjanmaa
; Original version
 
 
; Enabling debugging puts stuff to the debug board
DEBUGGING_ENABLED equ 1
DEBUGGING_DISABLED equ 0
DEBUGGING_STATE equ DEBUGGING_DISABLED
 
use32
 
org 0x0
 
db 'MENUET00' ; 8 byte id
dd 38 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
dd 0x00000000 ; reserved=no extended header
 
include 'lang.inc'
include 'macros.inc'
;include "DEBUG.INC"
 
URLMAXLEN equ 50 ; maximum length of url string
 
; Memory usage
; webpage source file at 0x10000
; decoded text page at 0x20000
; text attribute 0x30000 (1 = normal, 2 = bold, 128+ = link)
 
START: ; start of execution
 
;dps <"Program started",13,10>
 
mov eax,40 ; Report events
mov ebx,10000111b ; Stack 8 + defaults
int 0x40
 
call draw_window
 
still:
mov eax,23 ; wait here for event
mov ebx,1
int 0x40
 
cmp eax,1 ; redraw request ?
je red
cmp eax,2 ; key in buffer ?
je key
cmp eax,3 ; button in buffer ?
je button
 
; Get the web page data from the remote server
call read_incoming_data
 
mov eax,[status]
mov [prev_status],eax
 
mov eax,53
mov ebx,6
mov ecx,[socket]
int 0x40
 
mov [status],eax
 
cmp [prev_status],4
jge no_send
cmp [status],4
jne no_send
 
mov [onoff],1
 
call send_request
 
no_send:
call print_status
 
cmp [prev_status],4
jne no_close
cmp [status],4 ; connection closed by server
jbe no_close ; respond to connection close command
; draw page
 
call read_incoming_data
 
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
 
call draw_page
 
mov [onoff],0
 
no_close:
jmp still
 
red: ; redraw
call draw_window
jmp still
 
key: ; key
mov eax,2 ; just read it and ignore
int 0x40
shr eax,8
cmp eax,184
jne no_down
cmp [display_from],25
jb no_down
sub [display_from],25
call display_page
 
no_down:
cmp eax,183
jne no_up
add [display_from],25
call display_page
 
no_up:
jmp still
 
button: ; button
;dps <"Button pressed",13,10>
mov eax,17 ; get id
int 0x40
cmp ah,1 ; button id=1 ?
jne noclose
 
;dps "Closing socket before exit... "
 
mov eax, 53
mov ebx, 8
mov ecx, [socket]
int 0x40
 
;dpd eax
;dps <13,10>
 
exit:
or eax,-1 ; close this program
int 0x40
 
noclose:
cmp ah,31
jne noup
sub [display_from],20
call display_page
jmp still
 
noup:
cmp ah,32
jne nodown
add [display_from],20
call display_page
jmp still
 
nodown:
cmp ah, 10 ; Enter url
jne nourl
 
mov [addr],dword document_user
mov [ya],dword 38
mov [len],dword URLMAXLEN
 
mov ecx,[len]
mov edi,[addr]
mov al,' '
rep stosb
 
call print_text
 
mov edi,[addr]
 
f11:
mov eax,10
int 0x40
cmp eax,2 ; key?
jz fbu
jmp still
 
fbu:
mov eax,2
int 0x40 ; get key
shr eax,8
cmp eax,8
jnz nobs
cmp edi,[addr]
jz f11
sub edi,1
mov [edi],byte ' '
call print_text
jmp f11
 
nobs:
cmp eax, dword 10
je retkey
cmp eax, dword 13
je retkey
 
cmp eax,dword 31
jbe f11
 
; Removed in v0.4
; cmp eax,dword 95
; jb keyok
; sub eax,32
 
keyok:
mov [edi],al
 
call print_text
 
add edi,1
mov esi,[addr]
add esi,URLMAXLEN
cmp esi,edi
jnz f11
 
jmp still
 
retkey:
mov ah, 22 ; start load
 
nourl:
call socket_commands ; opens or closes the connection
jmp still
 
 
;****************************************************************************
; Function
; send_request
;
; Description
; Transmits the GET request to the server.
; This is done as GET then URL then HTTP/1.0',13,10,13,10 in 3 packets
;
;****************************************************************************
send_request:
pusha
mov eax,53 ; 'GET '
mov ebx,7
mov ecx,[socket]
mov edx,4
mov esi,string0
int 0x40
 
mov edx,0
 
next_edx:
; Determine the length of the url to send in the GET request
inc edx
cmp [edx+document],byte ' '
jne next_edx
 
mov eax,53 ; document_user
mov ebx,7
mov ecx,[socket]
mov esi,document
int 0x40
 
mov eax,53 ; ' HTTP/1.0 .. '
mov ebx,7
mov ecx,[socket]
mov edx,stringh_end-stringh
mov esi,stringh
int 0x40
 
popa
ret
 
 
;****************************************************************************
; Function
; print_status
;
; Description
; displays the socket/data received status information
;
;****************************************************************************
print_status:
pusha
 
mov eax,26
mov ebx,9
int 0x40
 
cmp eax,[nextupdate]
jb status_return
 
add eax,25
 
mov [nextupdate],eax
 
mov eax,13
mov ebx,5*65536+100
mov ecx,[winys]
shl ecx,16
add ecx,-18*65536+10
mov edx,0xffffff
int 0x40
 
mov eax,47
mov ebx,3*65536
mov ecx,[status]
mov edx,12*65536-18
add edx,[winys]
mov esi,0x000000
int 0x40
 
mov eax,47
mov ebx,6*65536
mov ecx,[pos]
mov edx,40*65536-18
add edx,[winys]
mov esi,0x000000
int 0x40
 
status_return:
popa
ret
 
 
;****************************************************************************
; Function
; read_incoming_data
;
; Description
; receive the web page from the server, storing it without processing
;
;****************************************************************************
read_incoming_data:
cmp [onoff],1
je rid
ret
 
rid:
mov ecx,-1
 
newbyteread:
mov eax, 53
mov ebx, 2
mov ecx, [socket]
int 0x40
 
cmp eax,0
je no_more_data
 
read_more:
mov eax, 53
mov ebx, 3
mov ecx, [socket]
int 0x40
 
yesm:
inc [pos]
mov ecx,[pos]
mov [0x10000+ecx],bl
 
call print_status
 
cmp eax,0
jne read_more
 
mov eax,5
mov ebx,50
int 0x40
 
jmp newbyteread
 
no_more_data:
ret
 
 
;****************************************************************************
; Function
; draw_page
;
; Description
; parses the web page data, storing displayable data at 0x20000
; and attributes at 0x30000. It then calls display_page to render
; the data
;
;****************************************************************************
draw_page:
pusha
mov esi,0
mov [command_on_off],0
 
newlettercheck:
movzx eax,byte [esi+0x10000]
cmp al,'<'
jne no_c_on
mov [command_on_off],1
 
no_c_on:
cmp al,'>'
jne no_c_off
mov [command_on_off],0
 
no_c_off:
cmp [command_on_off],0
je no_lower_case
 
cmp eax,96
jg no_lower_case
cmp eax,65
jb no_lower_case
add eax,32
 
no_lower_case:
mov [esi+0x10000],al
inc esi
cmp esi,[pos]
jbe newlettercheck
mov edi,0x30000
mov ecx,0x10000
mov al,0
cld
rep stosb
mov [text_type],1
mov [command_on_off],0
 
mov esi,0
mov ecx,[pos]
 
; search for double lf
 
find_dlf:
cmp [0x10000+esi-4],dword 0x0d0a0d0a
je found_dlf
cmp [0x10000+esi-4],dword 0x0a0d0a0d
je found_dlf
cmp [0x10000+esi-2],word 0x0d0d
je found_dlf
cmp [0x10000+esi-2],word 0x0a0a
je found_dlf
 
cmp esi,5500
je found_dlf
 
inc esi
 
jmp find_dlf
 
found_dlf:
newbyte:
mov al,[esi+0x10000]
cmp al,'<'
jne no_command_on
mov [command_on_off],1
 
no_command_on:
cmp al,'>'
jne no_command_off
mov [command_on_off],0
jmp byte_done
 
no_command_off:
mov eax,[esi+0x10000] ; <!--
cmp eax,'<!--'
jne no_com2_start
mov [com2],1
 
no_com2_start:
mov ax,[esi+0x10000] ; -->
cmp ax,'->'
jne no_com2_end
mov [com2],0
inc esi
jmp byte_done
 
no_com2_end:
mov eax,[esi+0x10000] ; <script
cmp eax,'<scr'
jne no_script_start
mov [script],1
 
no_script_start:
mov eax,[esi+0x10000] ; /script>
cmp eax,'</sc'
jne no_script_end
mov [script],0
inc esi
jmp byte_done
 
no_script_end:
cmp [command_on_off],0
jne no_print
 
cmp [com2],0
jne no_print
 
cmp [script],0
jne no_print
 
mov al,[esi+0x10000] ; &
cmp al,'&'
jne no_nbsp
 
newsps:
inc esi
mov al,[esi+0x10000] ;
cmp al,';'
jne newsps
jmp byte_done
 
no_nbsp:
cmp al,13
jne no_lb
jmp byte_done
 
no_lb:
cmp al,10
jne no_lf
jmp byte_done
 
no_lf:
mov ebx,[pagey]
imul ebx,[pagexs]
add ebx,[pagex]
add ebx,0x20000
and eax,0xff
cmp eax,31
jbe byte_done
cmp [lastletter],al
jne letter_ok
cmp al,' '
je byte_done
 
letter_ok:
mov [ebx],al
mov dl,[text_type]
mov [ebx+0x10000],dl
mov [pageyinc],0
mov [lastletter],al
 
inc [pagex]
 
mov ebx,[pagex]
cmp ebx,[pagexs]
jb byte_done
mov [pagex],0
inc [pagey]
 
jmp byte_done
 
no_print:
; HTML -COMMAND
 
mov ax,[esi+0x10000] ; b> bold
cmp ax,'b>'
jne no_bold_start
mov [text_type],2
 
no_bold_start:
mov eax,[esi+0x10000] ; /b bold end
cmp eax,'</b>'
jne no_bold_end
mov [text_type],1
add esi,2
 
no_bold_end:
mov ax,[esi+0x10000] ; <a
cmp ax,'a '
jne no_link_start
mov [text_type],128
add esi,2
 
no_link_start:
mov ax,[esi+0x10000] ; /a
cmp ax,'/a'
jne no_link_end2
mov [text_type],1
add esi,0
 
no_link_end2:
mov ax,[esi+0x10000]
cmp ax,'br'
jne no_br
call linefeed
inc esi
 
no_br:
mov ax,[esi+0x10000]
cmp ax,'td'
jne no_td
call linefeed
inc esi
 
no_td:
mov eax,[esi+0x10000]
cmp eax,'tabl'
jne no_table
call linefeed
add esi,3
 
no_table:
byte_done:
inc esi
cmp esi,[pos]
jbe newbyte
 
mov [display_from],0
call display_page
 
popa
ret
 
 
 
;****************************************************************************
; Function
; linefeed
;
; Description
;
;
;****************************************************************************
linefeed:
cmp [pageyinc],2
jge nolf
 
mov [pagex],0
inc [pagey]
inc [pageyinc]
 
nolf:
ret
 
 
 
;****************************************************************************
; Function
; display_page
;
; Description
; Renders the text decoded by draw_page
;
;****************************************************************************
display_page:
pusha
 
mov eax,0
mov ebx,0
 
newpxy:
push eax
push ebx
 
mov eax,13 ; background for letter
mov ebx,[esp+4]
imul ebx,6
add ebx,[dpx]
shl ebx,16
add ebx,6
mov ecx,[esp+0]
imul ecx,10
add ecx,[dpy]
shl ecx,16
add ecx,10
mov edx,0xffffff
int 0x40
 
mov eax,4
mov ebx,[esp+4]
imul ebx,6
add ebx,[dpx]
shl ebx,16
 
mov bx,[esp+0]
imul bx,10
add bx,word [dpy]
 
mov esi,[esp]
imul esi,[pagexs]
add esi,[esp+4]
 
mov edx,[display_from]
imul edx,[pagexs]
add edx,0x20000
add edx,esi
 
movzx ecx,byte [edx+0x10000]
cmp ecx,1
jne noecx1
mov ecx,0x000000
 
noecx1:
movzx ecx,byte [edx+0x10000]
cmp ecx,2
jne noecx2
mov ecx,0xff0000
 
noecx2:
cmp ecx,128
jne noecx128
mov ecx,0x0000ff
 
noecx128:
mov esi,1
 
int 0x40
 
pop ebx
pop eax
 
inc eax
cmp eax,[pagexs]
jb newpxy
mov eax,0
inc ebx
cmp ebx,30
jb newpxy
 
popa
ret
 
 
 
 
;****************************************************************************
; Function
; socket_commands
;
; Description
; opens or closes the socket
;
;****************************************************************************
socket_commands:
cmp ah,22 ; open socket
jnz tst3
 
; Clear all page memory
mov edi,0x10000
mov ecx,0x30000
mov al,0
cld
rep stosb
 
; Parse the entered url
call parse_url
 
; Get a free port number
mov ecx, 1000 ; local port starting at 1000
getlp1:
inc ecx
push ecx
mov eax, 53
mov ebx, 9
int 0x40
pop ecx
cmp eax, 0 ; is this local port in use?
jz getlp1 ; yes - so try next
 
mov eax,53
mov ebx,5
mov edx,80
mov esi,dword [server_ip]
mov edi,1
int 0x40
mov [socket], eax
 
mov [pos],0
mov [pagex],0
mov [pagey],0
mov [pagexs],80
mov [command_on_off],0
 
ret
 
tst3:
cmp ah,24 ; close socket
jnz no_24
 
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
 
call draw_page
 
ret
 
no_24:
ret
 
 
 
;****************************************************************************
; Function
; parse_url
;
; Description
; parses the full url typed in by the user into a web address ( that
; can be turned into an IP address by DNS ) and the page to display
; DNS will be used to translate the web address into an IP address, if
; needed.
; url is at document_user and will be space terminated.
; web address goes to webAddr and is space terminated.
; ip address goes to server_ip
; page goes to document and is space terminated.
;
; Supported formats:
; <protocol://>address<page>
; <protocol> is optional, removed and ignored - only http supported
; <address> is required. It can be an ip address or web address
; <page> is optional and must start with a leading / character
;
;****************************************************************************
parse_url:
; First, reset destination variables
cld
mov al, ' '
mov edi, document
mov ecx,URLMAXLEN
rep stosb
mov edi, webAddr
mov ecx,URLMAXLEN
rep stosb
mov al, '/'
mov [document], al
 
mov esi, document_user
; remove any leading protocol text
mov ecx, URLMAXLEN
mov ax, '//'
 
pu_000:
cmp [esi], byte ' ' ; end of text?
je pu_002 ; yep, so not found
cmp word [esi], ax
je pu_001 ; Found it, so esi+2 is start
inc esi
loop pu_000
 
pu_002:
; not found, so reset esi to start
mov esi, document_user -2
 
pu_001:
add esi, 2
 
mov ebx, esi ; save address of start of web address
mov edi, document_user + URLMAXLEN ; end of string
 
; look for page delimiter - it's a '/' character
pu_003:
cmp [esi], byte ' ' ; end of text?
je pu_004 ; yep, so none found
cmp esi, edi ; end of string?
je pu_004 ; yep, so none found
cmp [esi], byte '/' ; delimiter?
je pu_005 ; yep - process it
inc esi
jmp pu_003
 
pu_005:
; copy page to document address
; esi = delimiter
push esi
inc esi
mov ecx, edi ; end of document_user
mov edi, document
cld
 
pu_006:
movsb
cmp esi, ecx
je pu_007 ; end of string?
cmp [esi], byte ' ' ; end of text
je pu_007
jmp pu_006
 
pu_007:
pop esi ; point esi to '/' delimiter
 
pu_004:
; copy web address to webAddr
; start in ebx, end in esi-1
mov ecx, esi
mov esi, ebx
mov edi, webAddr
cld
 
pu_008:
movsb
cmp esi, ecx
je pu_009
jmp pu_008
 
pu_009:
; For debugging, display resulting strings
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
mov esi, document_user
call debug_print_string
mov esi, webAddr
call debug_print_string
mov esi, document
call debug_print_string
end if
 
; Look up the ip address, or was it specified?
mov al, [webAddr]
cmp al, '0'
jb pu_010 ; Resolve address
cmp al, '9'
ja pu_010 ; Resolve address
 
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
mov esi, str2 ; print gotip
call debug_print_string
end if
 
; Convert address
mov esi,webAddr-1
mov edi,server_ip
xor eax,eax
ip1:
inc esi
cmp [esi],byte '0'
jb ip2
cmp [esi],byte '9'
jg ip2
imul eax,10
movzx ebx,byte [esi]
sub ebx,48
add eax,ebx
jmp ip1
ip2:
mov [edi],al
xor eax,eax
inc edi
cmp edi,server_ip+3
jbe ip1
 
jmp pu_011
 
pu_010:
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
mov esi, str1 ; print resolving
call debug_print_string
end if
 
; Resolve Address
call translateData ; Convert domain & DNS IP address
call resolveDomain ; get ip address
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
mov esi, str3
call debug_print_string
end if
 
pu_011:
 
; Done
ret
 
 
;***************************************************************************
; Function
; translateData
;
; Description
; Coverts the domain name and DNS IP address typed in by the user into
; a format suitable for the IP layer.
;
; The ename, in query, is converted and stored in dnsMsg
;
;***************************************************************************
translateData:
 
; first, get the IP address of the DNS server
; Then, build up the request string.
 
 
; Build the request string
 
 
mov eax, 0x00010100
mov [dnsMsg], eax
mov eax, 0x00000100
mov [dnsMsg+4], eax
mov eax, 0x00000000
mov [dnsMsg+8], eax
 
; domain name goes in at dnsMsg+12
mov esi, dnsMsg + 12 ; location of label length
mov edi, dnsMsg + 13 ; label start
mov edx, webAddr
mov ecx, 12 ; total string length so far
 
td002:
mov [esi], byte 0
inc ecx
 
td0021:
mov al, [edx]
cmp al, ' '
je td001 ; we have finished the string translation
cmp al, '.' ; we have finished the label
je td004
 
inc byte [esi]
inc ecx
mov [edi], al
inc edi
inc edx
jmp td0021
 
td004:
mov esi, edi
inc edi
inc edx
jmp td002
 
 
 
; write label len + label text
 
td001:
mov [edi], byte 0
inc ecx
inc edi
mov [edi], dword 0x01000100
add ecx, 4
 
mov [dnsMsgLen], ecx
 
ret
 
 
 
 
 
;***************************************************************************
; Function
; resolveDomain
;
; Description
; Sends a question to the dns server
; works out the IP address from the response from the DNS server
;
;***************************************************************************
resolveDomain:
; Get a free port number
mov ecx, 1000 ; local port starting at 1000
getlp:
inc ecx
push ecx
mov eax, 53
mov ebx, 9
int 0x40
pop ecx
cmp eax, 0 ; is this local port in use?
jz getlp ; yes - so try next
 
; First, open socket
mov eax, 53
mov ebx, 0
mov edx, 53 ; remote port - dns
mov esi, dword [dns_ip]
int 0x40
 
mov [socketNum], eax
 
; write to socket ( request DNS lookup )
mov eax, 53
mov ebx, 4
mov ecx, [socketNum]
mov edx, [dnsMsgLen]
mov esi, dnsMsg
int 0x40
 
; Setup the DNS response buffer
 
mov eax, dnsMsg
mov [dnsMsgLen], eax
 
; now, we wait for
; UI redraw
; UI close
; or data from remote
 
ctr001:
mov eax,10 ; wait here for event
int 0x40
 
cmp eax,1 ; redraw request ?
je ctr003
cmp eax,2 ; key in buffer ?
je ctr004
cmp eax,3 ; button in buffer ?
je ctr005
 
 
; Any data in the UDP receive buffer?
mov eax, 53
mov ebx, 2
mov ecx, [socketNum]
int 0x40
 
cmp eax, 0
je ctr001
 
; we have data - this will be the response
ctr002:
mov eax, 53
mov ebx, 3
mov ecx, [socketNum]
int 0x40 ; read byte - block (high byte)
 
; Store the data in the response buffer
mov eax, [dnsMsgLen]
mov [eax], bl
inc dword [dnsMsgLen]
 
mov eax, 53
mov ebx, 2
mov ecx, [socketNum]
int 0x40 ; any more data?
 
cmp eax, 0
jne ctr002 ; yes, so get it
 
; close socket
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
 
mov [socketNum], dword 0xFFFF
 
; Now parse the message to get the host IP
; Man, this is complicated. It's described in
; RFC 1035
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
mov esi, str4
call debug_print_string
end if
 
; 1) Validate that we have an answer with > 0 responses
; 2) Find the answer record with TYPE 0001 ( host IP )
; 3) Finally, copy the IP address to the display
; Note: The response is in dnsMsg
; The end of the buffer is pointed to by [dnsMsgLen]
 
; Clear the IP address text
mov [server_ip], dword 0
 
mov esi, dnsMsg
 
; Is this a response to my question?
mov al, [esi+2]
and al, 0x80
cmp al, 0x80
jne ctr002a
 
; Were there any errors?
mov al, [esi+3]
and al, 0x0F
cmp al, 0x00
jne ctr002a
 
; Is there ( at least 1 ) answer?
mov ax, [esi+6]
cmp ax, 0x00
je ctr002a
 
; Header validated. Scan through and get my answer
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
pusha
mov esi, str4
call debug_print_string
popa
end if
 
add esi, 12 ; Skip to the question field
 
; Skip through the question field
call skipName
add esi, 4 ; skip past the questions qtype, qclass
 
ctr002z:
; Now at the answer. There may be several answers,
; find the right one ( TYPE = 0x0001 )
call skipName
mov ax, [esi]
cmp ax, 0x0100 ; Is this the IP address answer?
jne ctr002c
 
; Yes! Point esi to the first byte of the IP address
add esi, 10
 
mov eax, [esi]
mov [server_ip], eax
ret
 
 
ctr002c: ; Skip through the answer, move to the next
add esi, 8
movzx eax, byte [esi+1]
mov ah, [esi]
add esi, eax
add esi, 2
 
; Have we reached the end of the msg?
; This is an error condition, should not happen
cmp esi, [dnsMsgLen]
jl ctr002z ; Check next answer
jmp ctr002a ; abort
 
ctr002a:
jmp ctr001
 
ctr003: ; redraw
call draw_window
jmp ctr001
 
ctr004: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp ctr001
 
ctr005: ; button
mov eax,17 ; get id
int 0x40
 
mov dl, ah
 
; close socket
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
 
cmp dl, 1
je exit
 
mov [socketNum], dword 0xFFFF
mov [server_ip], dword 0
 
ret
 
 
 
;***************************************************************************
; Function
; skipName
;
; Description
; Increment esi to the first byte past the name field
; Names may use compressed labels. Normally do.
; RFC 1035 page 30 gives details
;
;***************************************************************************
skipName:
mov al, [esi]
cmp al, 0
je sn_exit
and al, 0xc0
cmp al, 0xc0
je sn001
 
movzx eax, byte [esi]
inc eax
add esi, eax
jmp skipName
 
sn001:
add esi, 2 ; A pointer is always at the end
ret
 
sn_exit:
inc esi
ret
 
 
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
 
;****************************************************************************
; Function
; debug_print_string
;
; Description
; prints a string to the debug board, in quotes
;
; esi holds ptr to msg to display, which is space or 0 terminated
;
; Nothing preserved; I'm assuming a pusha/popa is done before calling
;
;****************************************************************************
debug_print_string:
push esi
mov cl, '"'
mov eax,63
mov ebx, 1
int 0x40
pop esi
 
dps_000:
mov cl, [esi]
cmp cl, 0
je dps_exit
cmp cl, ' '
je dps_exit
jmp dps_001
 
dps_exit:
mov cl, '"'
mov eax,63
mov ebx, 1
int 0x40
mov cl, 13
mov eax,63
mov ebx, 1
int 0x40
mov cl, 10
mov eax,63
mov ebx, 1
int 0x40
ret
 
dps_001:
mov eax,63
mov ebx, 1
push esi
int 0x40
 
pop esi
inc esi
jmp dps_000
end if
 
 
;****************************************************************************
; Function
; print_text
;
; Description
; display the url (full path) text
;
;****************************************************************************
print_text:
; Draw a bar to blank out previous text
mov eax,13
mov ebx,30*65536+URLMAXLEN*6 ; 50 should really be [len], and 103 [xa]
mov ecx,[ya]
shl ecx,16
mov cx,9
mov edx,0xFFFFFF
int 0x40
 
; write text
mov eax,4
mov ebx,30*65536
add ebx,[ya]
mov ecx,0x000000
mov edx,[addr]
mov esi,URLMAXLEN
int 0x40
 
ret
 
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
 
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
 
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,50*65536+550 ; [x start] *65536 + [x size]
mov ecx,50*65536+400 ; [y start] *65536 + [y size]
mov edx,0x03ffffff ; color of work area RRGGBB,8->color gl
mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl
mov edi,0x005080d0 ; color of frames RRGGBB
int 0x40
 
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ddeeff ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
 
 
mov esi, URLMAXLEN ; URL
mov eax,4 ; function 4 : write text to window
mov ebx,30*65536+38 ; [x start] *65536 + [y start]
mov ecx,0x000000 ; color of text RRGGBB
mov edx,document_user ; pointer to text beginning
int 0x40
 
mov eax,38
mov ebx,5*65536+545
mov ecx,60*65536+60
mov edx,0x000000
int 0x40
 
mov eax,38
mov ebx,5*65536+545
mov ecx,[winys]
shl ecx,16
add ecx,[winys]
sub ecx,26*65536+26
mov edx,0x000000
int 0x40
; RELOAD
mov eax,8 ; function 8 : define and draw button
mov ebx,388*65536+50 ; [x start] *65536 + [x size]
mov ecx,34*65536+14 ; [y start] *65536 + [y size]
mov edx,22 ; button id
mov esi,0x5588dd ; button color RRGGBB
int 0x40
 
; URL
mov eax,8 ; function 8 : define and draw button
mov ebx,10*65536+12 ; [x start] *65536 + [x size]
mov ecx,34*65536+12 ; [y start] *65536 + [y size]
mov edx,10 ; button id
mov esi,0x5588dd ; button color RRGGBB
int 0x40
 
; STOP
mov eax,8 ; function 8 : define and draw button
mov ebx,443*65536+50 ; [x start] *65536 + [x size]
mov ecx,34*65536+14 ; [y start] *65536 + [y size]
mov edx,24 ; button id
mov esi,0x5588dd ; button color RRGGBB
int 0x40
 
; BUTTON TEXT
mov eax,4 ; function 4 : write text to window
mov ebx,390*65536+38 ; [x start] *65536 + [y start]
mov ecx,0xffffff ; color of text RRGGBB
mov edx,button_text ; pointer to text beginning
mov esi,20 ; text length
int 0x40
 
call display_page
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
ret
 
 
if DEBUGGING_STATE = DEBUGGING_ENABLED
str1: db "Resolving...",0
str3: db "Resolved",0
str2: db "GotIP",0
str4: db "GotResponse",0
end if
 
button_text db ' RELOAD STOP '
dpx dd 25 ; x - start of html page in pixels in window
dpy dd 65 ; for y
lastletter db 0
pageyinc dd 0
display_from dd 20
pos dd 0x0
pagex dd 0x0
pagey dd 0x0
pagexs dd 80
command_on_off dd 0x0
text_type db 1
com2 dd 0x0
script dd 0x0
socket dd 0x0
 
addr dd 0x0
ya dd 0x0
len dd 0x00
 
labelt: db 'HTTPC - PgUp/PgDown'
labellen:
 
server_ip: db 207,44,212,20
dns_ip: db 194,145,128,1
webAddr: times 128 db ' '
document_user: db 'Click on the button to the left to enter a URL',0
times 100 db 0x0
document: db '/'
times 100 db ' '
 
string0: db 'GET '
 
stringh: db ' HTTP/1.0',13,10,13,10
stringh_end:
 
status dd 0x0
prev_status dd 0x0
 
onoff dd 0x0
 
nextupdate: dd 0
winys: dd 400
 
dnsMsgLen: dd 0
socketNum: dd 0xFFFF
dnsMsg:
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/httpc/trunk/macros.inc
0,0 → 1,265
; 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 { ; mike.dld
if ~a 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/https/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm https.asm https
@pause
/programs/network/https/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm https.asm https
@pause
/programs/network/https/trunk/https.asm
0,0 → 1,1394
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Tiny HTTP Server v 0.4 for MenuetOS ;
; ;
; License GPL / See file COPYING for details. ;
; Copyright 2003 Ville Turjanmaa ;
; ;
; Compile with FASM for Menuet ;
; ;
; Request /TinyStat for server statistics ;
; Request /TinyBoard for server message board ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
version equ '0.4'
 
use32
 
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x400000 ; required amount of memory
dd 0x20000
dd 0,0 ; reserved=no extended header
 
include 'lang.inc'
include "macros.inc"
 
; 0x0+ - program image
; 0x1ffff - stack
; 0x20000+ - message board
; 0x100000+ - requested file
 
filel:
dd 0x0,0x0,50000/512,0x20000,0x70000
db '/rd/1/board.htm',0
 
files:
dd 0x1,0x0,0x0,0x20000,0x70000
db '/rd/1/board.htm',0
 
 
 
START: ; start of execution
 
mov eax,58
mov ebx,filel
int 0x40
mov [board_size],ebx
cmp eax,0
je board_found
 
mov [board_size],board_end-board
mov esi,board
mov edi,0x20000
mov ecx,[board_size]
cld
rep movsb
 
board_found:
 
mov eax,58
mov ebx,files
mov ecx,[board_size]
mov [files+8],ecx
int 0x40
 
mov [status],-1
mov [last_status],-2
call clear_input
call draw_window ; at first, draw the window
 
; call ops
 
still:
 
call check_status
cmp [status],4
je start_transmission
 
cmp [status],0
jne nnn
cmp [server_active],1
jne nnn
call ops
nnn:
 
mov eax,5
mov ebx,1
int 0x40
 
mov eax,11
int 0x40
call check_events
 
jmp still
 
 
reb: ; boot
 
mov eax,18
mov ebx,1
int 0x40
 
jmp $
 
 
last_status dd 0x0
 
check_events:
 
cmp eax,1 ; redraw request ?
jz red
cmp eax,2 ; key in buffer ?
jz key
cmp eax,3 ; button in buffer ?
jz button
 
ret
 
red: ; redraw
call draw_window
ret
 
key: ; Keys are not valid at this part of the
mov eax,2 ; loop. Just read it and ignore
int 0x40
ret
 
button: ; button
 
mov eax,17 ; get id
int 0x40
 
cmp ah,1 ; close
jnz tst2
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
mov eax,-1
int 0x40
tst2:
 
cmp ah,2 ; button id=2 ?
jnz tst3
; open socket
ops:
mov eax,53
mov ebx,5
mov ecx,80 ; local port # - http
mov edx,0 ; no remote port specified
mov esi,0 ; no remote ip specified
mov edi,0 ; PASSIVE open
int 0x40
mov [socket], eax
mov [posy],1
mov [posx],0
call check_for_incoming_data
call clear_input
call draw_data
mov [server_active],1
call check_status
; cmp [status],0
; je reb
ret
tst3:
 
cmp ah,4 ; button id=4 ?
jnz no4
mov [server_active],0
close_socket:
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
mov eax,5
mov ebx,2
int 0x40
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
 
cmp [server_active],1
jne no_re_open
mov eax,53
mov ebx,5
mov ecx,80 ; local port # - http
mov edx,0 ; no remote port specified
mov esi,0 ; no remote ip specified
mov edi,0 ; PASSIVE open
int 0x40
mov [socket], eax
no_re_open:
 
mov edi,input_text+256*15+1
mov [edi+2],dword ': :'
call set_time
mov edi,input_text+256*16+1
mov [edi+2],dword '. .'
call set_date
 
mov eax,[documents_served]
mov ecx,9
mov edi,input_text+256*15+12
call set_value
 
mov eax,[bytes_transferred]
mov ecx,9
mov edi,input_text+256*16+12
call set_value
 
call draw_data
 
mov esp,0x1ffff
jmp still
no4:
 
cmp ah,6 ; read directory
je read_string
 
ret
 
 
clear_input:
 
mov edi,input_text
mov eax,0
mov ecx,256*30
cld
rep stosb
 
ret
 
 
retries dd 50
 
start_transmission:
 
mov [posy],1
mov [posx],0
call clear_input
mov [retries],50
 
wait_for_data:
call check_for_incoming_data
cmp [input_text+256+1],dword 'GET '
je data_received
cmp [input_text+256+1],dword 'POST'
je data_received
mov eax,5
mov ebx,1
int 0x40
dec [retries]
jnz wait_for_data
jmp no_http_request
data_received:
 
mov eax,0x100000
mov ebx,0x2f0000 / 512
call read_file
 
call wait_for_empty_slot
call send_header
 
mov [filepos],0x100000
mov [fileadd],700
 
call check_status
call draw_data
 
newblock:
 
call wait_for_empty_slot
 
mov edx,[fileadd]
cmp edx,[file_left]
jbe file_size_ok
mov edx,[file_left]
file_size_ok:
sub [file_left],edx
 
; write to socket
mov eax,53
mov ebx,7
mov ecx,[socket]
mov esi,[filepos]
int 0x40
 
mov eax,esi
add eax,edx
sub eax,0x100000
call display_progress
 
mov edx,[fileadd]
add [filepos],edx
 
cmp [file_left],0
jg newblock
 
no_http_request:
 
jmp close_socket
 
 
filepos dd 0x100000
fileadd dd 0x1
filesize dd 0x0
file_left dd 0x0
 
 
wait_for_empty_slot:
 
pusha
 
wait_more:
 
; rdtsc
; mov ecx,eax
; add ecx,1000000
; wr:
; rdtsc
; cmp eax,ecx
; jb wr
 
mov eax,5
mov ebx,1
int 0x40
 
mov eax,11
int 0x40
call check_events
 
mov eax,53
mov ebx,255
mov ecx,103
int 0x40
 
cmp eax,0
je no_wait_more
 
jmp wait_more
 
no_wait_more:
 
popa
ret
 
 
 
 
display_progress:
 
pusha
 
mov edi,eax
 
mov eax,13
mov ebx,115*65536+8*6
mov ecx,178*65536+10
mov edx,0xffffff
int 0x40
 
mov eax,47
mov ebx,8*65536
mov ecx,edi
mov edx,115*65536+178
mov esi,0x000000
int 0x40
 
popa
ret
 
 
send_header:
 
pusha
 
mov eax,53 ; send response and file length
mov ebx,7
mov ecx,[socket]
mov edx,h_len-html_header
mov esi,html_header
int 0x40
 
mov eax,53 ; send file type
mov ebx,7
mov ecx,[socket]
mov edx,[type_len]
mov esi,[file_type]
int 0x40
 
popa
ret
 
 
fileinfo dd 0,0,1,0x100000,0xf0000
getf db '/RD/1/'
times 50 db 0
wanted_file: times 100 db 0
 
getflen dd 6
 
make_room:
 
pusha
 
mov edx,ecx
 
mov esi,0x20000
add esi,[board_size]
mov edi,esi
add edi,edx
mov ecx,[board_size]
sub ecx,board1-board
inc ecx
std
rep movsb
cld
 
popa
ret
 
 
from_i dd 0x0
from_len dd 0x0
 
message dd 0x0
message_len dd 0x0
 
read_file: ; start of execution
 
mov [fileinfo+12],eax
mov [fileinfo+8],ebx
 
mov [file_type],unk
mov [type_len],unkl-unk
mov [filename+40*2+6],dword 'UNK '
 
cmp [input_text+256+1],dword 'POST'
je yes_new_message
 
cmp [input_text+256+11],dword 'oard' ; server board message
jne no_server_message_2
 
yes_new_message:
 
mov eax,58
mov ebx,filel
int 0x40
mov [board_size],ebx
 
cmp [input_text+256+1],dword 'POST'
jne no_new_message
 
mov edi,bsmt
call set_time
mov edi,bsmd
call set_date
 
call check_for_incoming_data
 
mov esi,input_text+256 ; from
newfroms:
inc esi
cmp esi,input_text+256*20
je no_server_message_2
cmp [esi],dword 'from'
jne newfroms
 
add esi,5
mov [from_i],esi
 
mov edx,0
name_new_len:
cmp [esi+edx],byte 13
je name_found_len
cmp [esi+edx],byte '&'
je name_found_len
cmp edx,1000
je name_found_len
inc edx
jmp name_new_len
name_found_len:
 
mov [from_len],edx
 
mov esi,input_text+256
newmessages:
inc esi
cmp esi,input_text+256*20
je no_server_message_2
cmp [esi],dword 'sage'
jne newmessages
 
add esi,5
mov [message],esi
 
mov edx,0
new_len:
inc edx
cmp [esi+edx],byte ' '
je found_len
cmp [esi+edx],byte 13
jbe found_len
cmp edx,input_text+5000
je found_len
jmp new_len
found_len:
mov [message_len],edx
 
 
mov edx,0
 
change_letters:
 
cmp [esi+edx],byte '+'
jne no_space
mov [esi+edx],byte ' '
no_space:
 
cmp [esi+edx+1],word '0D'
jne no_br
mov [esi+edx],dword '<br>'
mov [esi+edx+4],word ' '
no_br:
 
cmp [esi+edx],byte '%'
jne no_ascii
movzx eax,byte [esi+edx+2]
sub eax,48
cmp eax,9
jbe eax_ok
sub eax,7
eax_ok:
movzx ebx,byte [esi+edx+1]
sub ebx,48
cmp ebx,9
jbe ebx_ok
sub ebx,7
ebx_ok:
imul ebx,16
add ebx,eax
mov [esi+edx],bl
mov [esi+edx+1],word ' '
add edx,2
no_ascii:
 
inc edx
cmp edx,[message_len]
jbe change_letters
 
 
mov edx,board1e-board1 + board2e-board2 + board3e-board3
add edx,[from_len]
add edx,[message_len]
 
add [board_size],edx
 
mov ecx,edx
call make_room
 
 
mov esi,board1 ; first part
mov edi,0x20000
add edi,board1-board
mov ecx,edx
cld
rep movsb
 
mov esi,[from_i] ; name
mov edi,0x20000
add edi,board1-board + board1e-board1
mov ecx,[from_len]
cld
rep movsb
 
mov esi,board2 ; middle part
mov edi,0x20000
add edi,board1-board + board1e-board1
add edi,[from_len]
mov ecx,board2e-board2
cld
rep movsb
 
mov esi,[message] ; message
mov edi,0x20000
add edi,board1-board + board1e-board1 +board2e-board2
add edi,[from_len]
mov ecx,[message_len]
cld
rep movsb
 
mov esi,board3 ; end part
mov edi,0x20000
add edi,board1-board + board1e-board1 +board2e-board2
add edi,[from_len]
add edi,[message_len]
mov ecx,board3e-board3
cld
rep movsb
 
inc [board_messages]
 
mov eax,[board_size]
mov [files+8],eax
 
mov eax,58
mov ebx,files
int 0x40
 
no_new_message:
mov esi,0x20000
mov edi,0x100000
mov ecx,[board_size]
cld
rep movsb
mov ebx,[board_size]
 
mov [file_type],htm
mov [type_len],html-htm
mov [filename+40*2+6],dword 'HTM '
 
jmp file_loaded
no_server_message_2:
 
cmp [input_text+256+9],dword 'ySta' ; server message
jne no_server_message_1
mov edi,smt
call set_time
mov edi,smd
call set_date
mov eax,[documents_served]
mov ecx,9
mov edi,sms+21
call set_value
mov eax,[bytes_transferred]
mov ecx,9
mov edi,smb+21
call set_value
mov eax,[board_messages]
mov ecx,9
mov edi,smm+21
call set_value
mov eax,[board_size]
mov ecx,9
mov edi,smz+21
call set_value
mov esi,sm
mov edi,0x100000
mov ecx,sme-sm
cld
rep movsb
mov ebx,sme-sm
 
mov [file_type],htm
mov [type_len],html-htm
mov [filename+40*2+6],dword 'HTM '
 
jmp file_loaded
no_server_message_1:
 
mov esi,input_text+256+6
cmp [input_text+256+1],dword 'GET '
jne no_new_let
mov edi,wanted_file
cld
new_let:
cmp [esi],byte ' '
je no_new_let
cmp edi,wanted_file+30
jge no_new_let
movsb
jmp new_let
no_new_let:
mov [edi+0],dword 0
mov [edi+4],dword 0
mov [edi+8],dword 0
 
cmp esi,input_text+256+6
jne no_index
mov edi,wanted_file
mov [edi+0],dword 'inde'
mov [edi+4],dword 'x.ht'
mov [edi+8],byte 'm'
mov [edi+9],byte 0
add edi,9
 
mov [file_type],htm
mov [type_len],html-htm
mov [filename+40*2+6],dword 'HTM '
 
jmp html_file
no_index:
 
cmp [edi-3],dword 'htm'+0
je htm_header
cmp [edi-3],dword 'HTM'+0
je htm_header
jmp no_htm_header
htm_header:
mov [file_type],htm
mov [type_len],html-htm
mov [filename+40*2+6],dword 'HTM '
jmp found_file_type
no_htm_header:
 
cmp [edi-3],dword 'png'+0
je png_header
cmp [edi-3],dword 'PNG'+0
je png_header
jmp no_png_header
png_header:
mov [file_type],png
mov [type_len],pngl-png
mov [filename+40*2+6],dword 'PNG '
jmp found_file_type
no_png_header:
 
cmp [edi-3],dword 'gif'+0
je gif_header
cmp [edi-3],dword 'GIF'+0
je gif_header
jmp no_gif_header
gif_header:
mov [file_type],gif
mov [type_len],gifl-gif
mov [filename+40*2+6],dword 'GIF '
jmp found_file_type
no_gif_header:
 
cmp [edi-3],dword 'jpg'+0
je jpg_header
cmp [edi-3],dword 'JPG'+0
je jpg_header
jmp no_jpg_header
jpg_header:
mov [file_type],jpg
mov [type_len],jpgl-jpg
mov [filename+40*2+6],dword 'JPG '
jmp found_file_type
no_jpg_header:
 
cmp [edi-3],dword 'asm'+0
je txt_header
cmp [edi-3],dword 'ASM'+0
je txt_header
cmp [edi-3],dword 'txt'+0
je txt_header
cmp [edi-3],dword 'TXT'+0
je txt_header
jmp no_txt_header
txt_header:
mov [file_type],txt
mov [type_len],txtl-txt
mov [filename+40*2+6],dword 'TXT '
jmp found_file_type
no_txt_header:
 
html_file:
 
found_file_type:
 
mov edi,getf
add edi,[getflen]
mov esi,wanted_file
mov ecx,40
cld
rep movsb
 
mov esi,getf
mov edi,filename
mov ecx,35
cld
rep movsb
 
mov [fileinfo+8],dword 1 ; file exists ?
mov eax,58
mov ebx,fileinfo
int 0x40
 
cmp eax,0 ; file not found - message
je file_found
mov edi,et
call set_time
mov edi,ed
call set_date
mov esi,fnf
mov edi,0x100000
mov ecx,fnfe-fnf
cld
rep movsb
mov ebx,fnfe-fnf
 
mov [file_type],htm
mov [type_len],html-htm
mov [filename+40*2+6],dword 'HTM '
 
jmp file_not_found
 
file_found:
 
mov [fileinfo+8],dword 0x2f0000 / 512 ; read all of file
mov eax,58
mov ebx,fileinfo
int 0x40
 
file_not_found:
file_loaded:
 
and ebx,0x3fffff
mov [filesize],ebx
mov [file_left],ebx
 
mov eax,ebx
mov edi,c_l+5
mov ebx,10
newl:
xor edx,edx
div ebx
mov ecx,edx
add cl,48
mov [edi],cl
dec edi
cmp edi,c_l
jge newl
 
mov esi,c_l
mov edi,filename+46
mov ecx,7
cld
rep movsb
 
inc [documents_served]
mov eax,[filesize]
add [bytes_transferred],eax
 
call draw_data
 
ret
 
 
set_value:
 
pusha
 
add edi,ecx
mov ebx,10
new_value:
xor edx,edx
div ebx
add dl,48
mov [edi],dl
dec edi
loop new_value
 
popa
ret
 
 
set_time:
 
pusha
 
mov eax,3
int 0x40
 
mov ecx,3
new_time_digit:
mov ebx,eax
and ebx,0xff
shl ebx,4
shr bl,4
add bx,48*256+48
mov [edi],bh
mov [edi+1],bl
add edi,3
shr eax,8
loop new_time_digit
 
popa
ret
 
 
 
set_date:
 
pusha
 
mov eax,29
int 0x40
 
mov ecx,3
add edi,6
new_date_digit:
mov ebx,eax
and ebx,0xff
shl ebx,4
shr bl,4
add bx,48*256+48
mov [edi],bh
mov [edi+1],bl
sub edi,3
shr eax,8
loop new_date_digit
 
popa
ret
 
 
 
check_for_incoming_data:
 
pusha
 
check:
 
mov eax, 53
mov ebx, 2
mov ecx, [socket]
int 0x40
 
cmp eax,0
je _ret_now
 
new_data:
 
mov eax,53
mov ebx,2
mov ecx,[socket]
int 0x40
 
cmp eax,0
je _ret
 
mov eax,53
mov ebx,3
mov ecx,[socket]
int 0x40
 
cmp bl,10
jne no_lf
inc [posy]
mov [posx],0
jmp new_data
no_lf:
 
cmp bl,20
jb new_data
 
inc [posx]
cmp [posy],20
jbe yok
mov [posy],1
yok:
 
mov eax,[posy]
imul eax,256
add eax,[posx]
 
mov [input_text+eax],bl
 
jmp new_data
 
_ret:
 
call draw_data
 
mov eax,5
mov ebx,1
cmp [input_text+256+1],dword 'POST'
jne no_ld
mov ebx,50
no_ld:
int 0x40
 
jmp check
 
_ret_now:
 
popa
ret
 
 
posy dd 1
posx dd 0
 
 
check_status:
 
pusha
 
mov eax,53
mov ebx,6
mov ecx,[socket]
int 0x40
 
cmp eax,[status]
je c_ret
mov [status],eax
add al,48
mov [text+12],al
call draw_data
c_ret:
 
popa
ret
 
 
addr dd 0x0
ya dd 0x0
 
filename2: times 100 db 32
 
read_string:
 
mov [addr],dword getf
mov [ya],dword 139
 
mov edi,[addr]
mov eax,0
mov ecx,30
cld
rep stosb
 
call print_text
 
mov edi,[addr]
 
f11:
mov eax,10
int 0x40
cmp eax,2
jne read_done
mov eax,2
int 0x40
shr eax,8
cmp eax,13
je read_done
cmp eax,8
jnz nobsl
cmp edi,[addr]
jz f11
sub edi,1
mov [edi],byte 32
call print_text
jmp f11
nobsl:
mov [edi],al
 
call print_text
 
add edi,1
mov esi,[addr]
add esi,30
cmp esi,edi
jnz f11
 
read_done:
 
push edi
 
mov ecx,40
mov eax,32
cld
rep stosb
 
call print_text
 
pop edi
sub edi,[addr]
mov [getflen],edi
 
mov esi,getf
mov edi,dirp+12
mov ecx,28
cld
rep movsb
 
jmp still
 
 
print_text:
 
pusha
 
mov eax,13
mov ebx,97*65536+23*6
mov ecx,[ya]
shl ecx,16
mov cx,9
mov edx,0xffffff
int 0x40
 
mov eax,4
mov edx,[addr]
mov ebx,97*65536
add ebx,[ya]
mov ecx,0x000000
mov esi,23
int 0x40
 
popa
ret
 
 
 
 
 
 
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
 
 
draw_window:
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
 
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+480 ; [x start] *65536 + [x size]
mov ecx,100*65536+215 ; [y start] *65536 + [y size]
mov edx,0x03ffffff ; color of work area RRGGBB
mov esi,0x8050a0b0 ; color of grab bar RRGGBB,8->color gl
mov edi,0x0050a0b0 ; color of frames RRGGBB
int 0x40
 
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x10ffffff ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
 
mov eax,8 ; function 8 : define and draw button
mov ebx,(40)*65536+20 ; [x start] *65536 + [x size]
mov ecx,59*65536+9 ; [y start] *65536 + [y size]
mov edx,2 ; button id
mov esi,0x66aa66 ; button color RRGGBB
int 0x40
 
mov eax,8 ; function 8 : define and draw button
mov ebx,(40)*65536+20 ; [x start] *65536 + [x size]
mov ecx,72*65536+9 ; [y start] *65536 + [y size]
mov edx,4 ; button id
mov esi,0xaa6666 ; button color RRGGBB
int 0x40
 
mov eax,8 ; Enter directory
mov ebx,(25)*65536+66
mov ecx,135*65536+15
mov edx,6
mov esi,0x3388dd
int 0x40
 
mov eax,38
mov ebx,240*65536+240
mov ecx,22*65536+210
mov edx,0x6699cc ; 002288
int 0x40
 
mov eax,38
mov ebx,241*65536+241
mov ecx,22*65536+210
mov edx,0x336699 ; 002288
int 0x40
 
call draw_data
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
ret
 
 
draw_data:
 
pusha
 
mov ebx,25*65536+35 ; draw info text with function 4
mov ecx,0x000000
mov edx,text
mov esi,35
newline:
pusha
cmp ebx,25*65536+61
je now
cmp ebx,25*65536+74
je now
cmp ebx,25*65536+74+13*5
je now
mov ecx,ebx
mov bx,35*6
shl ecx,16
mov cx,9
mov eax,13
mov edx,0xffffff
int 0x40
now:
popa
mov eax,4
int 0x40
add ebx,13
add edx,40
cmp [edx],byte 'x'
jnz newline
 
mov [input_text+0],dword 'RECE'
mov [input_text+4],dword 'IVED'
mov [input_text+8],dword ': '
 
mov ebx,255*65536+35 ; draw info text with function 4
mov ecx,0x000000
mov edx,input_text
mov esi,35
mov edi,17
newline2:
pusha
mov ecx,ebx
mov bx,35*6
shl ecx,16
mov cx,9
mov eax,13
mov edx,0xffffff
int 0x40
popa
mov eax,4
int 0x40
add ebx,10
add edx,256
dec edi
jnz newline2
 
popa
 
ret
 
 
; DATA AREA
 
status dd 0x0
 
text:
db 'TCB status: x '
db ' '
db ' Activate server '
db ' Stop server '
db ' '
db 'Requests: /TinyStat -statistics '
db ' /TinyBoard -message board '
db ' '
dirp:
db ' Files: /RD/1/ '
db ' '
filename:
db ' '
db 'Size: ------- '
db 'Type: --- '
db 'x' ; <- END MARKER, DONT DELETE
 
 
html_header:
 
db 'HTTP/1.0 200 OK',13,10
db 'Server: MenuetOS HTTP Server',13,10
db 'Content-Length: '
c_l: db '000000',13,10
 
h_len:
 
fnf:
db '<body>'
db '<pre>'
db "TinyServer v ",version," for MenuetOS",13,10,13,10
db "Error 404 - File not found.",13,10,13,10
db "For more info about server: request /TinyStat",13,10,13,10
et: db "xx:xx:xx",13,10
ed: db "xx.xx.xx",13,10
db "</pre></body>"
fnfe:
 
 
sm:
db '<body>'
db '<pre>'
db "TinyServer v ",version," for MenuetOS",13,10,13,10
db "Statistics: (before current request)",13,10,13,10
sms: db "- Documents served : xxxxxxxxx",13,10
smb: db "- Bytes transferred : xxxxxxxxx",13,10
db "- Location : <a href=/TinyStat>/TinyStat</a>",13,10,13,10
db "TinyBoard:",13,10,13,10
smm: db "- Messages : xxxxxxxxx",13,10
smz: db "- Size in bytes : xxxxxxxxx",13,10
db "- Location : <a href=/TinyBoard>/TinyBoard</a>",13,10,13,10
smt: db "xx:xx:xx",13,10
smd: db "xx.xx.xx",13,10
db '</pre></body>'
sme:
 
documents_served dd 0x0
bytes_transferred dd 0x0
 
file_type dd 0
type_len dd 0
 
htm: db 'Content-Type: text/html',13,10,13,10
html:
txt: db 'Content-Type: text/plain',13,10,13,10
txtl:
png: db 'Content-Type: image/png',13,10,13,10
pngl:
gif: db 'Content-Type: image/gif',13,10,13,10
gifl:
jpg: db 'Content-Type: image/jpeg',13,10,13,10
jpgl:
unk: db 'Content-Type: unknown/unknown',13,10,13,10
unkl:
 
 
labelt: db 'Tiny http server ',version
labellen:
 
socket dd 0x0
server_active db 0x0
 
board:
 
db "<HTML><BODY BGCOLOR=#ffffff ALINK=black VLINK=black><br>",13,10
db "<center>",13,10
db "<TABLE CELLPADDING=10 CELLSPACING=0 BORDER=0 bgcolor=#ffffff width=600>"
db 13,10
db "<TR VALIGN=top><TD ALIGN=center bgcolor=f0f0f8>",13,10
db "<font size=3>Tinyserver Messageboard</TD></TR></TABLE><br>",13,10
db "<TABLE CELLPADDING=14 CELLSPACING=2 BORDER=0 bgcolor=#ffffff width=600>"
db 13,10,13,10
 
board1:
 
db "<TR VALIGN=top>",13,10
db "<TD ALIGN=left width=80 bgcolor=f0f0f8><P>",13,10
db "<font size=3>",13,10
board1e:
db "WebMaster",13,10
board2:
db "</font>",13,10
db "<br><br><br>",13,10
db "<br><br><br><br>",13,10
bsmt:
db "12.23.45<br>",13,10
bsmd:
db "02.05.03",13,10
db "</P></TD>",13,10
db "<TD bgcolor=f0f0f8><P>",13,10
board2e:
db "Assembly written messageboard from assembly written MenuetOS.<br>"
db 13,10
board3:
db "</P></TD></TR>",13,10,13,10
board3e:
 
boardadd:
 
db "</TABLE>",13,10
db "<br>",13,10
db "<TABLE CELLPADDING=14 CELLSPACING=3 BORDER=0 bgcolor=#ffffff width=600>"
db 13,10
db "<TR VALIGN=top>",13,10
db "<TD ALIGN=left bgcolor=f0f0f8><P>",13,10
db "<form method=Post Action=/TinyBoard>",13,10
db "Name: <br><input type=text name=from size=20 MAXLENGTH=20><br>",13,10
db "Message: <br><textarea cols=60 rows=6 name=message></textarea><br>",13,10
db "<input type=Submit Value=' Send Message '></form>",13,10
db "</TD></TR>",13,10
db "</TABLE>",13,10
db "</BODY>",13,10
db "</HTML>",13,10
 
board_end:
 
board_size dd 0x0
board_messages dd 0x0
 
input_text:
 
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/https/trunk/macros.inc
0,0 → 1,265
; 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 { ; mike.dld
if ~a 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/ipc/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm ipc.asm ipc
@pause
/programs/network/ipc/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm ipc.asm ipc
@pause
/programs/network/ipc/trunk/ipc.asm
0,0 → 1,424
;
; Example for Inter Process Communication
;
; Compile with FASM for Menuet
;
include 'lang.inc'
include 'macros.inc'
 
use32
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd I_END ; size of image
dd 0x60000 ; memory for app
dd 0x60000 ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
 
START: ; start of execution
 
 
mov eax,60 ; IPC
mov ebx,1 ; define receive area
mov ecx,received_messages ; pointer to start
mov edx,1000 ; size of area
int 0x40
 
mov eax,40 ; WANTED EVENTS
mov ebx,01000111b ; IPC 7 + defaults
int 0x40
 
mov [received_messages+8],dword 0*256+0
mov [received_messages+12],dword 0
 
call draw_window ; at first, draw the window
 
still:
 
mov eax,23 ; wait here for event
mov ebx,50
int 0x40
 
cmp eax,1 ; redraw request ?
je red
cmp eax,2 ; key in buffer ?
je key
cmp eax,3 ; button in buffer ?
je button
 
cmp eax,7 ; IPC ?
jne no_ipc
call display_ipc_messages
jmp still
no_ipc:
 
jmp still
 
red: ; redraw
call draw_window
jmp still
 
key: ; key
mov eax,2 ; just read it and ignore
int 0x40
jmp still
 
button: ; button
mov eax,17 ; get id
int 0x40
 
cmp ah,1 ; button id=1 ?
jne noclose
mov eax,-1 ; close this program
int 0x40
noclose:
 
cmp ah,2
jne no_read
call read_string
 
movzx eax,byte [message]
sub eax,48
imul eax,10
movzx ebx,byte [message+1]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [message+2]
add eax,ebx
sub eax,48
imul eax,10
movzx ebx,byte [message+3]
add eax,ebx
sub eax,48
 
mov [PID],eax
 
mov eax,60 ; IPC
mov ebx,2 ; send message
mov ecx,[PID]
mov edx,message+4
mov esi,20;[message_size]
int 0x40
 
jmp still
no_read:
 
 
cmp ah,3
jne no_messages_pop ; pop the first out
call ipc_message_pop
jmp still
no_messages_pop:
 
jmp still
 
 
ipc_message_pop:
 
pusha
 
cmp [received_messages+4],dword 8
je already_empty
 
mov [received_messages],byte 1 ; lock the area
 
push dword [received_messages+4]
 
mov ecx,[received_messages+12]
 
sub [received_messages+4],ecx
sub [received_messages+4],dword 8
 
mov edi,received_messages+8
mov esi,edi
add esi,ecx
add esi,8
 
pop ecx
 
cld
rep movsb
 
call display_ipc_messages
 
mov [received_messages],byte 0 ; free the area
 
already_empty:
 
popa
ret
 
 
 
display_ipc_messages:
 
pusha
 
mov eax,13
mov ebx,25*65536+245
mov ecx,105*65536+90
mov edx,0xdddddd
int 0x40
 
cmp [received_messages+4],dword 8 ; empty list
je ipma1
 
mov ebx,25*65536+105 ; draw info text with function 4
mov ecx,0x224466
mov edx,received_messages+8
mov esi,40
mov [counter],0
newline2:
pusha
mov ecx,[edx]
and ecx,0xfff
mov edx,ebx
mov eax,47
mov ebx,4*65536
mov esi,0xff0000
int 0x40
popa
pusha
mov esi,20
add edx,8
add ebx,30*65536
mov eax,4
int 0x40
popa
 
add ebx,10
mov edi,[edx+4]
add edi,8
and edi,0xfff
add edx,edi
 
mov edi,[received_messages+4]
add edi,received_messages
cmp edx,edi
jge ipma1
 
inc [counter]
cmp [counter],8
jbe newline2
 
ipma1:
 
popa
ret
 
 
counter dd 0x0
 
 
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
 
 
draw_window:
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
 
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+290 ; [x start] *65536 + [x size]
mov ecx,100*65536+220 ; [y start] *65536 + [y size]
mov edx,0x03ffffff ; color of work area RRGGBB,8->color gl
int 0x40
 
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x10ffffff ; color of text RRGGBB
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
 
mov eax,9
mov ebx,process_info
mov ecx,-1
int 0x40
 
mov eax,47
mov ebx,4*65536
mov ecx,[process_info+30]
mov edx,180*65536+35
mov esi,0x000000
int 0x40
 
mov eax,8 ; MESSAGE
mov ebx,25*65536+87
mov ecx,50*65536+16
mov edx,2
mov esi,0x5588dd
int 0x40
 
mov eax,8 ; POP
mov ebx,216*65536+53
mov ecx,80*65536+16
mov edx,3
mov esi,0x5588dd
int 0x40
 
mov ebx,25*65536+35 ; draw info text with function 4
mov ecx,0x224466
mov edx,text
mov esi,40
newline:
mov eax,4
int 0x40
add ebx,10
add edx,40
cmp [edx],byte 'x'
jne newline
 
call display_ipc_messages
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
ret
 
 
 
 
read_string:
 
pusha
 
mov [addr],dword message
mov [ya],55
mov [xa],120
 
mov ecx,20
mov edi,[addr]
mov al,' '
cld
rep stosb
 
call print_text
 
mov edi,[addr]
 
f11:
mov eax,10
int 0x40
cmp eax,2
jz fbu
 
exit_readkey:
 
popa
ret
 
fbu:
mov eax,2
int 0x40 ; get key
shr eax,8
 
cmp eax,13
je exit_readkey
 
cmp eax,8
jnz nobs
cmp edi,[addr]
jz f11
dec edi
mov [edi],byte ' '
call print_text
jmp f11
nobs:
 
cmp eax,31
jbe f11
cmp eax,95
jb keyok
sub eax,32
keyok:
mov [edi],al
 
call print_text
 
inc edi
mov esi,[addr]
add esi,20
cmp esi,edi
jnz f11
 
popa
ret
 
 
 
print_text:
 
mov eax,13
mov ebx,[xa]
shl ebx,16
add ebx,25*6
mov ecx,[ya]
shl ecx,16
mov cx,8
mov edx,0xffffff
int 0x40
 
mov eax,4
mov ebx,[xa]
shl ebx,16
add ebx,[ya]
mov ecx,0x000000
mov edx,[addr]
mov esi,25
int 0x40
 
ret
 
 
 
 
 
 
; DATA AREA
 
ya dd 0x0
xa dd 0x0
addr dd 0x0
 
text:
db 'PROCESS ID FOR THIS APP : '
db ' '
db ' PID:MESSAGE 0130 EXAMPLE MESSAGE '
db ' '
db ' '
db 'RECEIVED: POP '
db 'x' ; <- END MARKER, DONT DELETE
 
 
labelt:
db 'IPC - START AT LEAST 2'
labellen:
 
I_END:
 
PID: dd 0x0
message_size: dd 20
 
received_messages:
 
db 0 ; lock byte
db 0,0,0 ; reserved
dd 8 ; pointer to free msg position from received_messages
 
; Sender PID
; Msg length
; Msg data
 
rb 0x1000
message: times 70 db ?
process_info: times 256 dd ?
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/ipc/trunk/macros.inc
0,0 → 1,267
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/local/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm local.asm local
@pause
/programs/network/local/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm local.asm local
@pause
/programs/network/local/trunk/local.asm
0,0 → 1,522
;
; Remote processing example (local node)
;
; Compile with FASM for Menuet
;
use32
org 0x0
db 'MENUET00' ; 8 byte id
dd 38 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
dd 0x00000000 ; reserved=no extended header
include 'lang.inc'
include 'macros.inc'
START: ; start of execution
mov eax,53 ; open socket
mov ebx,0
mov ecx,0x2000 ; local port
mov edx,0x3000 ; remote port
mov esi,dword [host_ip] ; node IP
int 0x40
mov [socketNum], eax
call draw_window ; at first, draw the window
still:
mov eax,23 ; wait here for event
mov ebx,1
int 0x40
cmp eax,1 ; redraw request ?
jz red
cmp eax,2 ; key in buffer ?
jz key
cmp eax,3 ; button in buffer ?
jz button
mov eax, 53 ; get data
mov ebx, 2
mov ecx, [socketNum]
int 0x40
cmp eax, 0
jne read
jmp still
red:
call draw_window
jmp still
key:
mov eax,2
int 0x40
jmp still
button:
mov eax,17
int 0x40
cmp ah,1 ; button id=1 ?
jnz noclose
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
mov eax,-1
int 0x40
noclose:
cmp ah,2 ; SEND CODE ?
je send_xcode
cmp ah,3 ; LEFT COORDINATES ?
jne no_left
mov [picture_position],0
mov dword [send_data+15],dword STARTX
mov dword [send_data+19],dword 4
mov esi,send_data
mov edi,I_END
mov ecx,23
cld
rep movsb
mov [I_END+23],dword -20
mov eax,53
mov ebx,4
mov ecx,[socketNum]
mov edx,23 + 4
mov esi,I_END
int 0x40
jmp still
no_left:
cmp ah,4 ; RIGHT COORDINATES ?
jne no_right
mov [picture_position],128
mov dword [send_data+15],dword STARTX
mov dword [send_data+19],dword 4
mov esi,send_data
mov edi,I_END
mov ecx,23
cld
rep movsb
mov [I_END+23],dword -20 + 128
mov eax,53
mov ebx,4
mov ecx,[socketNum]
mov edx,23 + 4
mov esi,I_END
int 0x40
jmp still
no_right:
cmp ah,5 ; SEND EXECUTE ?
je send_execute
jmp still
xx dd 0
yy dd 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; SEND CODE TO REMOTE ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
send_xcode:
mov dword [send_data+15],dword 0x80000
mov dword [send_data+19],dword remote_code_end - remote_code_start
mov esi,send_data ; header
mov edi,I_END
mov ecx,23
cld
rep movsb
mov esi,remote_code ; remote_code_start ; data
mov edi,I_END+23
mov ecx,remote_code_end - remote_code_start
cld
rep movsb
mov eax,53 ; SEND CODE TO REMOTE
mov ebx,4
mov ecx,[socketNum]
mov edx,23 + remote_code_end - remote_code_start
mov esi,I_END
int 0x40
jmp still
send_execute:
mov dword [execute+15],dword draw_fractal
mov eax,53 ; START EXECUTE AT REMOTE
mov ebx,4
mov ecx,[socketNum]
mov edx,19
mov esi,execute
int 0x40
mov edi,3
jmp still
;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; READ ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;
read:
cfr007:
mov eax, 53
mov ebx, 3
mov ecx, [socketNum]
int 0x40 ; read byte
shl edx,8
mov dl,bl
dec edi
jnz cok
mov edi,3
and edx,0xffffff
mov eax,1
mov ebx,[xx]
mov ecx,[yy]
add ebx,15
add ecx,35
add ebx,[picture_position]
int 0x40
inc [xx]
cmp [xx],dword 128
jb cok
mov [xx],0
inc [yy]
cmp [yy],dword 128
jb cok
mov [yy],0
cok:
mov eax, 53
mov ebx, 2
mov ecx, [socketNum]
int 0x40 ; any more data?
cmp eax, 0
jne cfr007 ; yes, so get it
jmp still
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+286 ; [x start] *65536 + [x size]
mov ecx,60*65536+330 ; [y start] *65536 + [y size]
mov edx,0x03ffffff ; color of work area RRGGBB
mov esi,0x80aabbcc ; color of grab bar RRGGBB,8->color gl
mov edi,0x00aabbcc ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ffffff ; color of text RRGGBB
mov edx,labeltext ; pointer to text beginning
mov esi,lte-labeltext ; text length
int 0x40
mov eax,8 ; SEND CODE
mov ebx,60*65536+160
mov ecx,181*65536+13
mov edx,2
mov esi,0x667788
int 0x40
mov eax,8 ; LEFT
mov ebx,60*65536+75
mov ecx,197*65536+13
mov edx,3
mov esi,0x667788
int 0x40
mov eax,8 ; RIGHT
mov ebx,148*65536+72
mov ecx,197*65536+13
mov edx,4
mov esi,0x667788
int 0x40
mov eax,8 ; SEND EXECUTE
mov ebx,60*65536+160
mov ecx,213*65536+13
mov edx,5
mov esi,0x667788
int 0x40
cld
mov ebx,25*65536+185 ; draw info text with function 4
mov ecx,0x000000
mov edx,text
mov esi,40
newline:
mov eax,4
int 0x40
add ebx,16
add edx,40
cmp [edx],byte 'x'
jnz newline
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; DATA AREA
text:
db ' 1) SEND CODE '
db ' 2) LEFT RIGHT '
db " 3) SEND 'EXECUTE' "
db ' '
db ' LOCAL : 192.168.1.26 '
db ' REMOTE : 192.168.1.22 '
db ' REMOTE CODE AT THE END OF THIS FILE '
db 'x <- END MARKER, DONT DELETE '
labeltext: db 'CLUSTER LOCAL' ;
lte:
socketNum dd 0x0
host_ip db 192,168,1,22
picture_position dd 0x0
send_data db 'MenuetRemote00' ; 00 header ; -> remote port 0x3000
db 1 ; 14 send
dd 0x0 ; 15 position
dd 0x0 ; 19 size
; 23
execute db 'MenuetRemote00' ; 00 header ; -> remote port 0x3000
db 2 ; 14 execute
dd 0x0 ; 15 position
; 19
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; REMOTE CODE ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
remote_code:
org 0x80000
remote_code_start:
PIXWIDTH equ 129
PIXHEIGHT equ 129
ZOOMLIMIT equ 13
DELTA equ 200
THRESHOLD equ 7
STARTSCALE equ 6
CHAR_COLOR equ 0fh
STARTX dd -20
STARTY dd 10
scaleaddy dd 60
scaleaddx dd 100
draw_fractal:
pusha
movzx ebp,word [STARTX]
movzx edi,word [STARTY]
mov cx, PIXHEIGHT ; height of screen in pixels
sub di,cx ; adjust our Y offset
@@CalcRow:
push cx
mov cx, PIXWIDTH -1 ; width of screen in pixels
sub bp,cx ;
@@CalcPixel:
push cx ; save the column counter on stack
xor cx, cx ; clear out color loop counter
xor bx, bx ; zero i coefficient
xor dx, dx ; zero j coefficient
@@CycleColors:
push dx ; save j value for later
mov ax, bx ; ax = i
sub ax, dx ; ax = i - j
add dx, bx ; dx = i + j
stc ; one additional shift, please
call Shifty ; ax = ((i+j)*(i-j)) shifted right
pop dx ; retrieve our saved value for j
add ax,bp ; account for base offset...
cmp ah,THRESHOLD ; Q: is i &gt; THRESHOLD * 256?
xchg bx,ax ; now swap new i with old i
jg @@draw ; Y: draw this pixel
clc ; no additional shifts here, please
call Shifty ; now dx:ax = old i * j
xchg dx,ax ;
add dx,di ; account for base offset...
inc cl ; increment color
jnz @@CycleColors ; keep going until we're done
@@draw:
xchg ax, cx ; mov color into al
pop cx ; retrieve our column counter
pop dx ; fetch row (column already in cx)
push dx ; must leave a copy on the stack
xor bx,bx ; write to video page zero
call store_pixel
inc bp
loop @@CalcPixel
inc di
pop cx
loop @@CalcRow
call return_data
popa
ret
Shifty:
push cx
db 0b1h
scale db STARTSCALE
adc cl,0
imul dx
xchg ax,dx
shl eax,16
xchg ax,dx
shr eax,cl
pop cx
ret
pixel_pos: dd data_area
store_pixel:
pusha
mov ebx,[pixel_pos]
shl eax,3
and eax,0xff
mov [ebx],eax
add dword [pixel_pos],dword 3
popa
ret
return_data:
mov ecx,128 * 128/16
mov esi,data_area
sd:
pusha
mov eax,53 ; use the socket provided by host
mov ebx,4
mov ecx,[0]
mov edx,3*16
int 0x40
mov eax,5
mov ebx,1
int 0x40
popa
add esi,3*16
loop sd
ret
data_area:
remote_code_end:
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/local/trunk/macros.inc
0,0 → 1,267
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/md5/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm md5.asm md5
@pause
/programs/network/md5/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm md5.asm md5
@pause
/programs/network/md5/trunk/md5.asm
0,0 → 1,445
; à¨¬¥à ॠ«¨§ æ¨¨ £¥­¥à â®à  MD5 - å¥è 
;
; MD5 Generator
;
; €¢â®à: Hex
; ‘ ©â: www.mestack.narod.ru
; ˆ¤¥ï, ॠ«¨§ æ¨ï ¨ ®â« ¤ª .
;
; €¢â®à: Halyavin
; ‘ ©â: www.shade.msu.ru/~msu-se/home.html
; „®à ¡®âª , ®â« ¤ª  ¨ ®¯â¨¬¨§ æ¨ï.
;
; Š®¬¯¨«¨àã¥âìáï Fasm'®¬ ¤«ï Œ¥­ãí⎑
include 'lang.inc'
macro diff16 title,l2
{
local s,d,l1
s = l2
display title,': 0x'
repeat 8
d = 48 + s shr ((8-%) shl 2) and $0F
if d > 57
d = d + 65-57-1
end if
display d
end repeat
display 13,10
}
 
use32
 
org 0x0
 
db 'MENUET01' ; 8-¡ ©â­ë© ¨¤¥­â¨ä¨ª â®à MenuetOS
dd 0x01 ; ¢¥àá¨ï § £®«®¢ª  (¢á¥£¤  1)
dd START ;  ¤à¥á ¯¥à¢®© ª®¬ ­¤ë
dd I_END ; à §¬¥à ¯à®£à ¬¬ë
dd 0x100000 ; ª®«¨ç¥á⢮ ¯ ¬ïâ¨
dd 0x100000 ;  ¤à¥á ¢¥à設ë áâíª 
dd 0x0 ;  ¤à¥á ¡ãä¥à  ¤«ï ¯ à ¬¥â஢ (­¥ ¨á¯®«ì§ã¥âáï)
dd 0x0 ; § à¥§¥à¢¨à®¢ ­®
 
START: ;  ç «® ¢ë¯®«­¥­¨ï ¯à®£à ¬¬ë
 
call draw_window ; ‘¯¥à¢  ¯¥à¥à¨á㥬 ®ª­®
 
still:
 
mov eax,23 ; Ž¦¨¤ ¥¬ ᮡë⨩
mov ebx,1
int 0x40
 
cmp eax,1 ; ‡ ¯à®á ­  ¯¥à¥à¨á®¢ªã ?
jz red
cmp eax,2 ; ­ ¦ â  ª« ¢¨è¨ ?
jz key
cmp eax,3 ; ­ ¦ â  ª­®¯ª  ?
jz button
 
jmp still
 
red:
call draw_window
jmp still
 
key:
mov eax,2
int 0x40
jmp still
 
button:
mov eax,17
int 0x40
 
cmp ah,1 ; id ª­®¯ª¨ = 1 ?
jnz noclose
mov eax,-1
int 0x40
 
noclose:
 
cmp ah,2 ; ƒ¥­¥à¨à®¢ âì?
je procMD5hash
 
jmp still
 
 
procMD5hash:
 
; phase I - padding
mov edi,ptBuffer
mov eax,[dtBufferLength]
 
inc eax
add edi,eax
mov byte [edi-1],0x80
 
xor edx,edx
 
mov ebx,64
div ebx
 
neg edx
add edx,64
 
cmp edx,8
jae @f
 
add edx,64
@@: mov ecx,edx
xor al,al
rep stosb
 
mov eax,[dtBufferLength]
 
inc edx
add [dtBufferLength],edx
 
xor edx,edx
 
mov ebx,8
mul ebx
 
mov [edi-8],eax
mov [edi-4],edx
 
mov edx,[dtBufferLength]
 
mov edi,ptBuffer
 
; phase II - chaining variables initialization
mov dword [dtA],067452301h
mov dword [dtB],0efcdab89h
mov dword [dtC],098badcfeh
mov dword [dtD],010325476h
mov esi,ptMD5Result
 
hashloop:
;diff16 "hashloop",hashloop
mov eax,[dtA]
mov [dta],eax
mov eax,[dtB]
mov [dtb],eax
mov eax,[dtC]
mov [dtc],eax
mov eax,[dtD]
mov [dtd],eax
macro ff dta,dtb,dtc,dtd,data,shift,cc
{
mov eax,dtb
mov ebx,dtc
mov ecx,dtd
and ebx,eax
not eax
and eax,ecx
or eax,ebx
add eax,dta
add eax,data
add eax,cc
rol eax,shift
add eax,dtb
mov dta,eax
}
macro gg dta,dtb,dtc,dtd,data,shift,cc
{
mov eax,dtb
mov ebx,dtc
mov ecx,dtd
and eax,ecx
not ecx
and ecx,ebx
or eax,ecx
add eax,dta
add eax,data
add eax,cc
rol eax,shift
add eax,dtb
mov dta,eax
}
macro hh dta,dtb,dtc,dtd,data,shift,cc
{
mov eax,dtb
mov ebx,dtc
mov ecx,dtd
xor eax,ebx
xor eax,ecx
add eax,dta
add eax,data
add eax,cc
rol eax,shift
add eax,dtb
mov dta,eax
}
macro ii dta,dtb,dtc,dtd,data,shift,cc
{
mov eax,dtb
mov ebx,dtc
mov ecx,dtd
not ecx
or eax,ecx
xor eax,ebx
add eax,dta
add eax,data
add eax,cc
rol eax,shift
add eax,dtb
mov dta,eax
}
; round 1
ff [dta],[dtb],[dtc],[dtd],dword [edi+00*4],07,0xd76aa478
ff [dtd],[dta],[dtb],[dtc],dword [edi+01*4],12,0xe8c7b756
ff [dtc],[dtd],[dta],[dtb],dword [edi+02*4],17,0x242070db
ff [dtb],[dtc],[dtd],[dta],dword [edi+03*4],22,0xc1bdceee
ff [dta],[dtb],[dtc],[dtd],dword [edi+04*4],07,0xf57c0faf
ff [dtd],[dta],[dtb],[dtc],dword [edi+05*4],12,0x4787c62a
ff [dtc],[dtd],[dta],[dtb],dword [edi+06*4],17,0xa8304613
ff [dtb],[dtc],[dtd],[dta],dword [edi+07*4],22,0xfd469501
ff [dta],[dtb],[dtc],[dtd],dword [edi+08*4],07,0x698098d8
ff [dtd],[dta],[dtb],[dtc],dword [edi+09*4],12,0x8b44f7af
ff [dtc],[dtd],[dta],[dtb],dword [edi+10*4],17,0xffff5bb1
ff [dtb],[dtc],[dtd],[dta],dword [edi+11*4],22,0x895cd7be
ff [dta],[dtb],[dtc],[dtd],dword [edi+12*4],07,0x6b901122
ff [dtd],[dta],[dtb],[dtc],dword [edi+13*4],12,0xfd987193
ff [dtc],[dtd],[dta],[dtb],dword [edi+14*4],17,0xa679438e
ff [dtb],[dtc],[dtd],[dta],dword [edi+15*4],22,0x49b40821
; round 2
gg [dta],[dtb],[dtc],[dtd],dword [edi+01*4],05,0xf61e2562
gg [dtd],[dta],[dtb],[dtc],dword [edi+06*4],09,0xc040b340
gg [dtc],[dtd],[dta],[dtb],dword [edi+11*4],14,0x265e5a51
gg [dtb],[dtc],[dtd],[dta],dword [edi+00*4],20,0xe9b6c7aa
gg [dta],[dtb],[dtc],[dtd],dword [edi+05*4],05,0xd62f105d
gg [dtd],[dta],[dtb],[dtc],dword [edi+10*4],09,0x02441453
gg [dtc],[dtd],[dta],[dtb],dword [edi+15*4],14,0xd8a1e681
gg [dtb],[dtc],[dtd],[dta],dword [edi+04*4],20,0xe7d3fbc8
gg [dta],[dtb],[dtc],[dtd],dword [edi+09*4],05,0x21e1cde6
gg [dtd],[dta],[dtb],[dtc],dword [edi+14*4],09,0xc33707d6
gg [dtc],[dtd],[dta],[dtb],dword [edi+03*4],14,0xf4d50d87
gg [dtb],[dtc],[dtd],[dta],dword [edi+08*4],20,0x455a14ed
gg [dta],[dtb],[dtc],[dtd],dword [edi+13*4],05,0xa9e3e905
gg [dtd],[dta],[dtb],[dtc],dword [edi+02*4],09,0xfcefa3f8
gg [dtc],[dtd],[dta],[dtb],dword [edi+07*4],14,0x676f02d9
gg [dtb],[dtc],[dtd],[dta],dword [edi+12*4],20,0x8d2a4c8a
; round 3
hh [dta],[dtb],[dtc],[dtd],dword [edi+05*4],04,0xfffa3942
hh [dtd],[dta],[dtb],[dtc],dword [edi+08*4],11,0x8771f681
hh [dtc],[dtd],[dta],[dtb],dword [edi+11*4],16,0x6d9d6122
hh [dtb],[dtc],[dtd],[dta],dword [edi+14*4],23,0xfde5380c
hh [dta],[dtb],[dtc],[dtd],dword [edi+01*4],04,0xa4beea44
hh [dtd],[dta],[dtb],[dtc],dword [edi+04*4],11,0x4bdecfa9
hh [dtc],[dtd],[dta],[dtb],dword [edi+07*4],16,0xf6bb4b60
hh [dtb],[dtc],[dtd],[dta],dword [edi+10*4],23,0xbebfbc70
hh [dta],[dtb],[dtc],[dtd],dword [edi+13*4],04,0x289b7ec6
hh [dtd],[dta],[dtb],[dtc],dword [edi+00*4],11,0xeaa127fa
hh [dtc],[dtd],[dta],[dtb],dword [edi+03*4],16,0xd4ef3085
hh [dtb],[dtc],[dtd],[dta],dword [edi+06*4],23,0x04881d05
hh [dta],[dtb],[dtc],[dtd],dword [edi+09*4],04,0xd9d4d039
hh [dtd],[dta],[dtb],[dtc],dword [edi+12*4],11,0xe6db99e5
hh [dtc],[dtd],[dta],[dtb],dword [edi+15*4],16,0x1fa27cf8
hh [dtb],[dtc],[dtd],[dta],dword [edi+02*4],23,0xc4ac5665
; round 4
ii [dta],[dtb],[dtc],[dtd],dword [edi+00*4],06,0xf4292244
ii [dtd],[dta],[dtb],[dtc],dword [edi+07*4],10,0x432aff97
ii [dtc],[dtd],[dta],[dtb],dword [edi+14*4],15,0xab9423a7
ii [dtb],[dtc],[dtd],[dta],dword [edi+05*4],21,0xfc93a039
ii [dta],[dtb],[dtc],[dtd],dword [edi+12*4],06,0x655b59c3
ii [dtd],[dta],[dtb],[dtc],dword [edi+03*4],10,0x8f0ccc92
ii [dtc],[dtd],[dta],[dtb],dword [edi+10*4],15,0xffeff47d
ii [dtb],[dtc],[dtd],[dta],dword [edi+01*4],21,0x85845dd1
ii [dta],[dtb],[dtc],[dtd],dword [edi+08*4],06,0x6fa87e4f
ii [dtd],[dta],[dtb],[dtc],dword [edi+15*4],10,0xfe2ce6e0
ii [dtc],[dtd],[dta],[dtb],dword [edi+06*4],15,0xa3014314
ii [dtb],[dtc],[dtd],[dta],dword [edi+13*4],21,0x4e0811a1
ii [dta],[dtb],[dtc],[dtd],dword [edi+04*4],06,0xf7537e82
ii [dtd],[dta],[dtb],[dtc],dword [edi+11*4],10,0xbd3af235
ii [dtc],[dtd],[dta],[dtb],dword [edi+02*4],15,0x2ad7d2bb
ii [dtb],[dtc],[dtd],[dta],dword [edi+09*4],21,0xeb86d391
mov eax,[dta]
add [dtA],eax
mov eax,[dtb]
add [dtB],eax
mov eax,[dtc]
add [dtC],eax
mov eax,[dtd]
add [dtD],eax
 
add edi,64
 
sub edx,64
jnz hashloop
 
; phase IV - results
 
mov ecx,4
mov esi,ptMD5Result
 
@@: mov eax,[esi]
xchg al,ah
rol eax,16
xchg al,ah
mov [esi],eax
 
add esi,4
loop @b
 
translate:
;diff16 "translate",translate
mov esi,ptMD5Result-5
mov edi,hexresult
mov ecx,16
@@:
test ecx,3
jnz .nojmp
add esi,8
.nojmp:
xor eax,eax
mov al,byte [esi]
mov edx,eax
shr eax,4
mov bl,byte [table+eax]
mov [edi],bl
inc edi
and edx,15
mov bl,byte [table+edx]
mov [edi],bl
dec esi
inc edi
loop @b
mov esi,hexresult
mov [text], esi
mov eax,32
mov [textlen], eax
call draw_window
 
jmp still
 
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
 
 
draw_window:
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+230 ; [x start] *65536 + [x size]
mov ecx,60*65536+100 ; [y start] *65536 + [y size]
mov edx,0x03ffffff ; color of work area RRGGBB
mov esi,0x80aabbcc ; color of grab bar RRGGBB,8->color gl
mov edi,0x00aabbcc ; color of frames RRGGBB
int 0x40
 
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ffffff ; color of text RRGGBB
mov edx,labeltext ; pointer to text beginning
mov esi,lte-labeltext ; text length
int 0x40
; ¨á㥬 ª­®¯ªã ¤«ï £¥­¥à æ¨¨
mov eax,8 ; function 8 : define and draw button
mov ebx,20*65536+80 ; [x start] *65536 + [x size]
mov ecx,34*65536+14 ; [y start] *65536 + [y size]
mov edx,2 ; button id
mov esi,0x5588dd ; button color RRGGBB
int 0x40
;  §¢ ­¨¥ ­  ª­®¯ªã
mov eax,4 ; function 4 : write text to window
mov ebx,23*65536+38 ; [x start] *65536 + [y start]
mov ecx,0x000000 ; color of text RRGGBB
mov edx,gen_txt ; pointer to text beginning
mov esi,gen_len-gen_txt ; text length
int 0x40
 
mov eax,4 ; draw info text with function 4
mov ebx,20*65536+70
mov ecx,0x000000
mov edx,[text]
xor eax,eax
mov al, [textlen]
mov esi,eax
mov eax,4
int 0x40
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
ret
 
;Ž¡« áâì ¤ ­­ëå
 
labeltext: db 'MD5 Generator'
lte:
 
text: dd 0
textlen: dd 0
 
gen_txt: db '‘£¥­¥à¨à®¢ âì'
gen_len:
 
InputMD5Rez: dd 0
InputMD5Rezlen:
 
ptBuffer: db '123' ;‡ ¬¥­¨âì ­  £¥­¥à¨à㥬®¥ á«®¢®
rb 61
dtBufferLength: dd 3 ; §¬¥à ptBuffer
 
ptMD5Result:
 
dtA: dd 0
dtB: dd 0
dtC: dd 0
dtD: dd 0
 
dta: dd 0
dtb: dd 0
dtc: dd 0
dtd: dd 0
 
x: dd 0
s: dd 0
t: dd 0
 
table: db '0123456789abcdef'
hexresult db 32
 
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/netsendc/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm netsendc.asm netsendc
@pause
/programs/network/netsendc/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm netsendc.asm netsendc
@pause
/programs/network/netsendc/trunk/macros.inc
0,0 → 1,267
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/netsendc/trunk/netsendc.asm
0,0 → 1,198
;
; NetSend(Client)
;
; €¢â®à: Hex
; ‘ ©â: www.mestack.narod.ru
;
; Ž¯¨á ­¨¥:
; à®£à ¬¬  ¤«ï ®¡¬¥­  á®®¡é¥­¨ï¬¨ ¢ á¥â¨.Š«¨¥­â᪠ï ç áâì.
;
; Compile with FASM for Menuet
; Š®¬¯¨«¨àã¥âáï FASM'®¬ ¤«ï Œ¥­ãí⠎‘
;
use32
org 0x0
db 'MENUET00' ; 8 byte id
dd 38 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
dd 0x00000000 ; reserved=no extended header
include 'lang.inc'
include 'macros.inc'
START: ; start of execution
mov eax,53 ; open socket
mov ebx,0
mov ecx,0x4000 ; local port
mov edx,0x5000 ; remote port
mov esi,dword [remote_ip] ; node IP
int 0x40
mov [socketNum], eax
call draw_window ; at first, draw the window
still:
mov eax,23 ; wait here for event
mov ebx,1
int 0x40
cmp eax,1 ; redraw request ?
jz red
cmp eax,2 ; key in buffer ?
jz key
cmp eax,3 ; button in buffer ?
jz button
jmp still
red:
call draw_window
jmp still
key:
mov eax,2
int 0x40
jmp still
button:
mov eax,17
int 0x40
cmp ah,1 ; button id=1 ?
jnz noclose
mov eax, 53
mov ebx, 1
mov ecx, [socketNum]
int 0x40
mov eax,-1
int 0x40
noclose:
cmp ah,2 ; SEND CODE ?
je send_xcode
 
jmp still
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; SEND CODE TO REMOTE ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
send_xcode:
 
mov esi,send_data ; header
mov edi,I_END
mov ecx,end_message-send_data
cld
rep movsb
mov eax,53 ; SEND CODE TO REMOTE
mov ebx,4
mov ecx,[socketNum]
mov edx,end_message-send_data
mov esi,I_END
int 0x40
jmp still
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+250 ; [x start] *65536 + [x size]
mov ecx,60*65536+150 ; [y start] *65536 + [y size]
mov edx,0x03ffffff ; color of work area RRGGBB
mov esi,0x80aabbcc ; color of grab bar RRGGBB,8->color gl
mov edi,0x00aabbcc ; color of frames RRGGBB
int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ffffff ; color of text RRGGBB
mov edx,labeltext ; pointer to text beginning
mov esi,lte-labeltext ; text length
int 0x40
mov eax,8 ; SEND MESSAGE
mov ebx,50*65536+145
mov ecx,47*65536+13
mov edx,2
mov esi,0x667788
int 0x40
cld
mov ebx,25*65536+50 ; draw info text with function 4
mov ecx,0x000000
mov edx,text
mov esi,40
newline:
mov eax,4
int 0x40
add ebx,16
add edx,40
cmp [edx],byte 'x'
jnz newline
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; DATA AREA
text:
db ' ®á« âì á®®¡é¥­¨¥ '
db ' '
db ' ‹®ª «ì­ë©  ¤à¥á : 192.168.0.1 '
db ' “¤ «ñ­­ë©  ¤à¥á : 192.168.0.2 '
db '’¥ªáâ ¨  ¤à¥á ¢ ª®­æ¥ ¨á室­¨ª  '
db 'x <- END MARKER, DONT DELETE '
labeltext: db 'NetSend(Client)' ;
lte:
socketNum dd 0x0
remote_ip db 192,168,1,2
picture_position dd 0x0
send_data db 'à¨¢¥â,íâ® â¥áâ!Hello,this is a test!'
end_message:
 
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/netsends/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm netsends.asm netsends
@pause
/programs/network/netsends/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm netsends.asm netsends
@pause
/programs/network/netsends/trunk/macros.inc
0,0 → 1,267
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/netsends/trunk/netsends.asm
0,0 → 1,207
;
; NetSend(Server)
;
; €¢â®à: Hex
; ‘ ©â: www.mestack.narod.ru
;
; Ž¯¨á ­¨¥:
; à®£à ¬¬  ¤«ï ®¡¬¥­  á®®¡é¥­¨ï¬¨ ¢ á¥â¨.‘¥à¢¥à­ ï ç áâì.
;
; Compile with FASM for Menuet
; Š®¬¯¨«¨àã¥âáï FASM'®¬ ¤«ï Œ¥­ãí⠎‘
;
use32
org 0x0
db 'MENUET00' ; 8 byte id
dd 38 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
dd 0x00000000 ; reserved=no extended header
include 'lang.inc'
include 'macros.inc'
remote_ip db 192,168,0,1
START: ; start of execution
mov eax, 53 ; open receiver socket
mov ebx, 0
mov ecx, 0x5000 ; local port
mov edx, 0xffff ; remote port
mov esi, dword [remote_ip] ; remote IP
int 0x40
mov [socketNum],eax
mov [0],eax ; save for remote code
call draw_window ; at first, draw the window
still:
mov eax,23 ; wait here for event
mov ebx,1
int 0x40
cmp eax,1 ; redraw request ?
jz red
cmp eax,2 ; key in buffer ?
jz key
cmp eax,3 ; button in buffer ?
jz button
mov eax,53 ; data from cluster terminal ?
mov ebx,2
mov ecx,[socketNum]
int 0x40
cmp eax,0
jne data_arrived
jmp still
red:
call draw_window
jmp still
key:
mov eax,2
int 0x40
jmp still
button:
mov eax,53
mov ebx,1
mov ecx,[socketNum]
int 0x40
mov eax,-1
int 0x40
data_arrived:
mov eax,5 ; wait a second for everything to arrive
mov ebx,10
int 0x40
mov edi,I_END
get_data:
mov eax,53
mov ebx,3
mov ecx,[socketNum]
int 0x40
mov [edi],bl
inc edi
mov eax,53
mov ebx,2
mov ecx,[socketNum]
int 0x40
cmp eax,0
jne get_data
mov eax,4
mov ebx,10*65536+60
add ebx,[y]
mov ecx,0x000000
mov edx,I_END
mov esi,100
int 0x40
add [y],10
jmp still
y dd 0x10
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
draw_window:
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+300 ; [x start] *65536 + [x size]
mov ecx,100*65536+330 ; [y start] *65536 + [y size]
mov edx,0x03ffffff ; color of work area RRGGBB
mov esi,0x80aabbcc ; color of grab bar RRGGBB,8->color gl
mov edi,0x00aabbcc ; color of frames RRGGBB
int 0x40
mov eax,8
mov ebx,(286-19)*65536+12
mov ecx,4*65536+12
mov edx,1
mov esi,0xaabbcc
; int 0x40
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x00ffffff ; color of text RRGGBB
mov edx,labeltext ; pointer to text beginning
mov esi,lte-labeltext ; text length
int 0x40
; Re-draw the screen text
cld
mov ebx,10*65536+30 ; draw info text with function 4
mov ecx,0x000000
mov edx,text
mov esi,40
newline:
mov eax,4
int 0x40
add ebx,16
add edx,40
cmp [edx],byte 'x'
jnz newline
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
ret
; DATA AREA
text:
db '„ ­­ë©  ¤à¥á : 192.168.0.2 '
db 'à®á«ã訢 ¥¬ë© ¯®àâ : 0x5000 '
db 'à¨á« ­­ë¥ á®®¡é¥­¨ï: '
db 'x <- END MARKER, DONT DELETE '
labeltext: db 'NetSend(Server)'
lte:
socketNum dd 0x0
 
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/nntpc/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm nntpc.asm nntpc
@pause
/programs/network/nntpc/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm nntpc.asm nntpc
@pause
/programs/network/nntpc/trunk/macros.inc
0,0 → 1,267
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/nntpc/trunk/nntpc.asm
0,0 → 1,933
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; NNTP CLIENT v 0.1
;;
;; (C) Ville Turjanmaa
;;
 
version equ '0.1'
 
include "lang.inc"
include "macros.inc"
 
use32
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; header version
dd START ; start of code
dd I_END ; size of image
dd 0x80000 ; memory for app
dd 0x80000 ; esp
dd 0x0 , 0x0 ; I_Param , I_Icon
 
 
connect_state db 0,0,'Disconnected'
db 1,3,'Trying.. '
db 4,4,'Connected '
db 5,9,'Closing.. '
 
prev_state dd -1
 
space dd 0x0
 
text_start dd 0x0
 
text_current dd 0x0
 
status dd 0x0
 
server_ip db 192,168,0,96
 
socket dd 0x0
 
xpos dd 0x0
ypos dd 0x0
 
;;
 
group db 'GROUP alt.test',13,10
db ' '
 
grouplen dd 16
 
stat db 'STAT '
 
statlen dd 0x0
 
article db 'ARTICLE',13,10
articlelen:
 
;;
 
quit db 'QUIT',13,10
quitlen:
 
xwait dd 0x0
ywait dd 0x0
 
article_n dd 0x0
article_l dd 0x0
 
article_start dd 0x0
article_last dd 0x0
article_all dd 0x0
 
article_fetch dd 0x0
 
xpost dd 0x0
 
edisave dd 0x0
 
 
connection_status:
 
pusha
 
mov eax,53
mov ebx,6
mov ecx,[socket]
int 0x40
 
cmp eax,[prev_state]
je no_cos
 
mov [prev_state],eax
 
mov eax,13
mov ebx,435*65536+12*6
mov ecx,42*65536+10
mov edx,0xffffff
int 0x40
 
mov ecx,-14
mov eax,[prev_state]
 
next_test:
 
add ecx,14
 
cmp ecx,14*4
je no_cos
 
cmp al,[connect_state+ecx+0]
jb next_test
cmp al,[connect_state+ecx+1]
jg next_test
 
mov edx,ecx
add edx,2
add edx,connect_state
 
mov eax,4
mov ebx,435*65536+42
mov ecx,0x000000
mov esi,12
int 0x40
 
no_cos:
 
popa
 
ret
 
 
 
text_input:
 
pusha
mov ecx,25
mov eax,32
cld
rep stosb
popa
 
mov [edisave],edi
 
ti0:
 
mov [edi],byte ' '
call draw_entries
 
mov eax,10
int 0x40
 
cmp eax,2
jne no_more_text
 
mov eax,2
int 0x40
 
cmp ah,8
jne no_bg
cmp edi,[edisave]
je ti0
dec edi
jmp ti0
no_bg:
 
cmp ah,13
je no_more_text
 
mov [edi],ah
inc edi
 
call draw_entries
 
jmp ti0
 
no_more_text:
 
mov [xpost],edi
 
ret
 
 
convert_text_to_ip:
 
pusha
 
mov edi,server_ip
mov esi,text+10
mov eax,0
mov edx,[xpost]
newsip:
cmp [esi],byte '.'
je sipn
cmp esi,edx
jge sipn
movzx ebx,byte [esi]
inc esi
imul eax,10
sub ebx,48
add eax,ebx
jmp newsip
sipn:
mov [edi],al
xor eax,eax
inc esi
cmp esi,text+50
jg sipnn
inc edi
cmp edi,server_ip+3
jbe newsip
sipnn:
 
popa
 
ret
 
 
send_group:
 
mov eax,53
mov ebx,7
mov ecx,[socket]
mov edx,[grouplen]
mov esi,group
int 0x40
mov [status],3
call clear_text
call save_coordinates
 
ret
 
 
convert_number_to_text:
 
pusha
 
mov eax,[esi]
mov ecx,0
newch:
inc ecx
xor edx,edx
mov ebx,10
div ebx
cmp eax,0
jne newch
 
add edi,ecx
dec edi
mov [article_l],ecx
 
mov eax,[esi]
newdiv:
xor edx,edx
mov ebx,10
div ebx
add edx,48
mov [edi],dl
dec edi
loop newdiv
 
popa
 
ret
 
 
convert_text_to_number:
 
pusha
 
mov edx,0
newdigit:
movzx eax,byte [esi]
cmp eax,'0'
jb cend
cmp eax,'9'
jg cend
imul edx,10
add edx,eax
sub edx,48
inc esi
jmp newdigit
cend:
mov [edi],edx
popa
 
ret
 
 
clear_text:
 
mov [text_start],0
mov [xpos],0
mov [ypos],0
mov [xwait],0
mov [ywait],0
mov edi,nntp_text
mov ecx,0x50000
mov eax,32
cld
rep stosb
ret
 
 
state_machine_write:
 
 
cmp [status],2
jne no_22
call send_group
ret
no_22:
 
cmp [status],4
jne no_4
mov eax,53
mov ebx,7
mov ecx,[socket]
mov edx,[statlen] ; -stat
mov esi,stat
int 0x40
mov [status],5
call save_coordinates
ret
no_4:
 
cmp [status],6
jne no_6
mov eax,53
mov ebx,7
mov ecx,[socket]
mov edx,articlelen-article
mov esi,article
int 0x40
mov [status],7
call save_coordinates
ret
no_6:
 
 
ret
 
save_coordinates:
 
mov eax,[xpos]
mov ebx,[ypos]
mov [xwait],eax
mov [ywait],ebx
 
ret
 
 
state_machine_read:
 
cmp [status],1
jne no_1
mov eax,'200 '
call wait_for_string
ret
no_1:
 
cmp [status],3 ;; responce to group
jne no_3
mov eax,'211 '
call wait_for_string
ret
no_3:
 
cmp [status],5 ;; responce to stat
jne no_5
mov eax,'223 '
call wait_for_string
ret
no_5:
 
;; after 'article' request - no wait
 
cmp [status],9
jne no_9
mov eax,'222 '
call wait_for_string
ret
no_9:
 
 
 
ret
 
 
 
wait_for_string:
 
mov ecx,[ywait]
imul ecx,80
add ecx,[xwait]
 
mov ecx,[nntp_text+ecx]
 
cmp eax,ecx
jne no_match
 
cmp [status],3
jne no_stat_ret
 
mov esi,[ywait]
imul esi,80
add esi,[xwait]
 
new32s:
inc esi
movzx eax,byte [esi+nntp_text]
cmp eax,47
jge new32s
new32s2:
inc esi
movzx eax,byte [esi+nntp_text]
cmp eax,47
jge new32s2
inc esi
add esi,nntp_text
; mov [esi-1],byte '.'
 
mov edi,article_n
call convert_text_to_number
mov eax,[article_n]
mov [article_start],eax
 
new32s3:
inc esi
movzx eax,byte [esi]
cmp eax,47
jge new32s3
inc esi
 
mov edi,article_last
call convert_text_to_number
 
mov eax,[text_current]
add [article_n],eax
 
mov esi,article_n
mov edi,nntp_text+71
call convert_number_to_text
 
mov esi,article_n
mov edi,stat+5
call convert_number_to_text
 
mov eax,[article_l]
mov [stat+5+eax],byte 13
mov [stat+6+eax],byte 10
add eax,5+2
mov [statlen],eax
 
pusha
mov edi,text+10+66*2
mov ecx,25
mov eax,32
cld
rep stosb
mov esi,text_current
mov edi,text+10+66*2
call convert_number_to_text
mov eax,32
mov ecx,20
mov edi,text+10+66*3
cld
rep stosb
mov eax,[article_last]
sub eax,[article_start]
mov [article_all],eax
mov esi,article_all
mov edi,text+10+66*3
call convert_number_to_text
call draw_entries
popa
 
call draw_text
 
no_stat_ret:
 
inc [status]
 
mov eax,5
mov ebx,10
int 0x40
 
call check_for_incoming_data
 
no_match:
 
ret
 
 
 
START: ; start of execution
 
mov eax,40
mov ebx,10000111b
int 0x40
 
call clear_text
 
call draw_window
 
still:
 
call state_machine_write
call state_machine_read
 
mov eax,23 ; wait here for event
mov ebx,5
int 0x40
 
cmp eax,1 ; redraw request ?
je red
cmp eax,2 ; key in buffer ?
je key
cmp eax,3 ; button in buffer ?
je button
 
call check_for_incoming_data
 
call connection_status
 
jmp still
 
red: ; redraw
call draw_window
jmp still
 
key: ; key
mov eax,2 ; just read it and ignore
int 0x40
 
cmp ah,' '
jne no_space
mov eax,[space]
dec eax
add [text_start],eax
call draw_text
jmp still
no_space:
 
cmp ah,177
jne no_plus
inc [text_start]
call draw_text
jmp still
no_plus:
 
cmp ah,178
jne no_minus
cmp [text_start],0
je no_minus
dec [text_start]
call draw_text
jmp still
no_minus:
 
cmp ah,179
jne no_next
inc [text_current]
call send_group
jmp still
no_next:
 
cmp ah,176
jne no_prev
cmp [text_current],0
je still
dec [text_current]
call send_group
jmp still
no_prev:
 
jmp still
 
 
button: ; button
mov eax,17 ; get id
int 0x40
 
shr eax,8
 
cmp eax,11
jne no_11
mov edi,text+10
call text_input
call convert_text_to_ip
jmp still
no_11:
 
cmp eax,12
jne no_12
mov edi,text+66+10
call text_input
mov esi,text+66+10
mov edi,group+6
mov ecx,[xpost]
sub ecx,text+66+10
mov eax,ecx
cld
rep movsb
mov [group+6+eax],byte 13
mov [group+7+eax],byte 10
add eax,6+2
mov [grouplen],eax
mov [text_current],0
jmp still
no_12:
 
cmp eax,13
jne no_13
mov edi,text+10+66*2
call text_input
mov esi,text+10+66*2
mov edi,text_current
call convert_text_to_number
call send_group
jmp still
no_13:
 
 
cmp eax,14
jne no_start
call clear_text
mov eax,3
int 0x40
mov ecx,eax
mov eax,53
mov ebx,5
mov edx,119
mov esi,dword [server_ip]
mov edi,1
int 0x40
mov [socket],eax
mov [status],1
jmp still
no_start:
 
cmp eax,15
jne no_end
mov eax,53
mov ebx,7
mov ecx,[socket]
mov edx,quitlen-quit
mov esi,quit
int 0x40
mov eax,5
mov ebx,10
int 0x40
call check_for_incoming_data
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
mov eax,5
mov ebx,5
int 0x40
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
mov [status],0
jmp still
no_end:
 
cmp eax,1 ; button id=1 ?
jne noclose
mov eax,-1 ; close this program
int 0x40
noclose:
 
jmp still
 
 
check_for_incoming_data:
 
cmp [status],0
jne go_on
ret
go_on:
 
mov eax,53
mov ebx,2
mov ecx,[socket]
int 0x40
 
cmp eax,0
je ch_ret
 
mov eax,53
mov ebx,3
mov ecx,[socket]
int 0x40
 
and ebx,0xff
 
cmp ebx,13
jb no_print
 
cmp bl,13
jne char
mov [xpos],0
inc [ypos]
jmp no_print
char:
 
cmp ebx,128
jbe char_ok
mov ebx,'?'
char_ok:
 
mov ecx,[ypos]
imul ecx,80
add ecx,[xpos]
mov [nntp_text+ecx],bl
cmp [xpos],78
jg noxinc
inc [xpos]
noxinc:
 
no_print:
 
mov eax,53
mov ebx,2
mov ecx,[socket]
int 0x40
 
cmp eax,0
jne check_for_incoming_data
 
call draw_text
 
ch_ret:
 
ret
 
 
 
; *********************************************
; ******* WINDOW DEFINITIONS AND DRAW ********
; *********************************************
 
 
draw_window:
 
pusha
 
mov [prev_state],-1
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,1 ; 1, start of draw
int 0x40
 
; DRAW WINDOW
mov eax,0 ; function 0 : define and draw window
mov ebx,100*65536+520 ; [x start] *65536 + [x size]
mov ecx,5*65536+470 ; [y start] *65536 + [y size]
mov edx,0x03ffffff ; color of work area RRGGBB,8->color gl
mov esi,0x805080d0 ; color of grab bar RRGGBB,8->color gl
mov edi,0x005080d0 ; color of frames RRGGBB
int 0x40
 
mov eax,38
mov ebx,5*65536+515
mov ecx,101*65536+101
mov edx,0x99bbff
int 0x40
mov eax,38
mov ebx,5*65536+515
mov ecx,102*65536+102
mov edx,0x3366aa
int 0x40
 
; WINDOW LABEL
mov eax,4 ; function 4 : write text to window
mov ebx,8*65536+8 ; [x start] *65536 + [y start]
mov ecx,0x10ddeeff ; font 1 & color ( 0xF0RRGGBB )
mov edx,labelt ; pointer to text beginning
mov esi,labellen-labelt ; text length
int 0x40
 
mov eax,8
mov ebx,238*65536+8
mov ecx,30*65536+8
mov edx,11
mov esi,0x88aadd
int 0x40
mov eax,8
mov ebx,238*65536+8
mov ecx,41*65536+8
mov edx,12
int 0x40
mov eax,8
mov ebx,238*65536+8
mov ecx,52*65536+8
mov edx,13
int 0x40
 
mov eax,8
mov ebx,265*65536+75
mov ecx,39*65536+13
mov edx,14
int 0x40
mov eax,8
mov ebx,351*65536+75
mov ecx,39*65536+13
mov edx,15
int 0x40
 
call draw_entries
 
call draw_text
 
mov eax,12 ; function 12:tell os about windowdraw
mov ebx,2 ; 2, end of draw
int 0x40
 
popa
 
ret
 
 
draw_entries:
 
pusha
 
mov eax,13
mov ebx,30*65536+200
mov ecx,30*65536+44
mov edx,0xffffff
int 0x40
 
mov ebx,30*65536+31 ; draw info text with function 4
mov ecx,0x000000
mov edx,text
mov esi,66
mov edi,6
 
newline2:
 
mov eax,4
int 0x40
add ebx,11
add edx,66
dec edi
jnz newline2
 
popa
 
ret
 
 
draw_text:
 
pusha
 
mov eax,9
mov ebx,0x70000
mov ecx,-1
int 0x40
 
mov eax,[0x70000+46]
cmp eax,150
jbe dtret
 
sub eax,111
mov ebx,10
xor edx,edx
div ebx
mov edi,eax
dec edi
 
mov [space],edi
 
mov ebx,20*65536+111 ; draw info text with function 4
mov ecx,0x000000
mov edx,[text_start]
imul edx,80
add edx,nntp_text
mov esi,80
newline:
 
pusha
mov ecx,ebx
shl ecx,16
mov eax,13
mov ebx,20*65536+80*6
mov cx,10
mov edx,0xffffff
int 0x40
popa
 
mov eax,4
int 0x40
add ebx,10
add edx,80
dec edi
jnz newline
 
dtret:
 
popa
 
ret
 
 
; DATA AREA
 
text:
db 'NNTP IP : 192.168.0.96 < '
db 'Group : alt.test < Connect Disconnect '
db 'Article : 0 < '
db 'Art.max : ? '
db ' '
db 'Arrow left/rigth: fetch prev/next - Arrow up/down & space: scroll '
 
textl:
 
 
labelt:
db 'NNTP client v',version
labellen:
 
nntp_text:
 
db 'a'
 
I_END: ;;;
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/popc/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm popc.asm popc
@pause
/programs/network/popc/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm popc.asm popc
@pause
/programs/network/popc/trunk/popc.asm
0,0 → 1,1029
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; POP CLIENT for MenuetOS ;;
;; - Modified from IRC client ;;
;; ;;
;; License: GPL / See file COPYING for details ;;
;; Copyright 2002 (c) Ville Turjanmaa ;;
;; ;;
;; Compile with FASM for Menuet ;;
;; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
include 'lang.inc'
version equ '0.1'
 
use32
 
org 0x0
 
db 'MENUET01' ; 8 byte id
dd 0x01 ; required os
dd START ; program start
dd I_END ; program image size
dd 0x200000 ; required amount of memory
dd 0xffff0
dd 0,0
 
START: ; start of execution
 
mov [file_start],0x100000
 
mov eax,58
mov ebx,filel
int 0x40
 
cmp eax,0
jne notfound
add [file_start],ebx
notfound:
 
mov edi,I_END
mov ecx,60*120
mov eax,32
cld
rep stosb
 
mov eax,[rxs]
imul eax,11
mov [pos],eax
 
mov ebp,0
mov edx,I_END
call draw_window ; at first, draw the window
 
still:
 
mov eax,5
mov ebx,1
int 0x40
 
mov eax,11 ; wait here for event
int 0x40
 
cmp eax,1 ; redraw
je redraw
cmp eax,2 ; key
je key
cmp eax,3 ; button
je button
 
cmp [I_END+120*60],byte 1
jne no_main_update
mov [I_END+120*60],byte 0
mov edx,I_END
call draw_server_data
no_main_update:
 
cmp [server_active],0
je noread
call read_incoming_data
noread:
 
call print_status
 
cmp [status],4
je send_request
 
jmp still
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Save the fetched mails
;;
 
 
save_file:
 
pusha
 
mov edi,[file_start]
 
mov eax,[file_start]
sub eax,0x100000
mov [files+8],eax
 
mov eax,58
mov ebx,files
int 0x40
 
popa
 
ret
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Send user id/passwd/mailrq
;;
 
 
send_request:
 
inc [mcounter]
 
cmp [mcounter],1000
jbe no_send
 
mov eax,[ccounter]
imul eax,32
add eax,getmail
mov esi,eax
 
inc [ccounter]
 
mov edx,32
 
cmp [ccounter],1
jne no1
mov edx,5+2
add edx,[l2]
no1:
 
cmp [ccounter],2
jne no2
mov edx,5+2
add edx,[l3]
no2:
 
mov eax,53
mov ebx,7
mov ecx,[socket]
int 0x40
mov [mcounter],0
 
cmp [esi],dword 'quit'
je close_fetch
 
 
no_send:
 
jmp still
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Close connection to server
;;
 
 
close_fetch:
 
mov eax,53
mov ebx,7
mov ecx,[socket]
mov edx,14
mov esi,quitc
int 0x40
mov [mcounter],0
 
mov eax,5
mov ebx,150
int 0x40
 
call read_incoming_data
 
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
 
mov eax,5
mov ebx,2
int 0x40
 
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
 
mov [server_active],0
 
jmp still
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; User input processing
;;
 
 
redraw: ; redraw
 
call draw_window
jmp still
 
 
key:
 
mov eax,2
int 0x40
 
jmp still
 
 
button: ; button
 
mov eax,17 ; get id
int 0x40
 
cmp ah,60
jne no_open
mov eax,19
mov ebx,tp
mov ecx,pr
int 0x40
jmp still
no_open:
 
cmp ah,1 ; close program
jne noclose
mov eax,-1
int 0x40
noclose:
 
cmp ah,51
je read_string
cmp ah,52
je read_string
cmp ah,53
je read_string
 
call socket_commands
 
jmp still
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Socket open & close
;;
 
socket_commands:
 
cmp ah,22 ; open socket
jnz tst3
 
mov [server_active],1
 
mov [mcounter],900
mov [ccounter],0
 
mov eax,3
int 0x40
 
mov eax,3
int 0x40
mov ecx,eax
and ecx,0xffff
 
mov eax,53
mov ebx,5
mov edx,110
mov esi,dword [ip]
mov edi,1
int 0x40
mov [socket], eax
 
ret
tst3:
 
 
cmp ah,24 ; close socket
jnz no_24
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
mov [header_sent],0
mov [mail_rp],0
mov [server_active],0
 
ret
no_24:
 
ret
 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Display connection status
;;
 
old_status dd 0x0
 
print_status:
 
pusha
 
mov eax,53
mov ebx,6
mov ecx,[socket]
int 0x40
 
mov [status],eax
 
cmp eax,[old_status]
je nopr
 
mov [old_status],eax
 
push eax
 
mov eax,13
mov ebx,200*65536+30
mov ecx,160*65536+10
mov edx,0xffffff
int 0x40
 
pop ecx
 
cmp [server_active],1
jne nopr
 
mov eax,47
mov ebx,3*65536
mov edx,200*65536+160
mov esi,0x000000
int 0x40
 
nopr:
 
popa
 
ret
 
 
 
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Read data from server
;;
 
 
read_incoming_data:
 
pusha
 
read_new_byte:
 
call read_incoming_byte
cmp ecx,-1
je no_data_in_buffer
 
mov eax,[file_start]
mov [eax],bl
inc [file_start]
 
cmp bl,10
jne no_start_command
mov [cmd],1
no_start_command:
 
cmp bl,13
jne no_end_command
mov eax,[cmd]
mov [eax+command-2],byte 0
call save_file
call analyze_data
mov edi,command
mov ecx,250
mov eax,0
cld
rep stosb
mov [cmd],0
no_end_command:
 
mov eax,[cmd]
cmp eax,250
jge still
 
mov [eax+command-2],bl
inc [cmd]
 
jmp read_new_byte
 
no_data_in_buffer:
 
popa
 
ret
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Read user input for ip/user/passwd
;;
 
 
read_string:
 
shr eax,8
sub eax,51
mov ebx,eax
imul eax,12
add eax,181
 
mov [len],ebx
shl [len],2
add [len],l1
 
imul ebx,50
add ebx,input1
 
mov [addr],ebx
mov [ya],eax
 
mov edi,[addr]
mov eax,0
mov ecx,30
cld
rep stosb
 
call print_input_text
 
mov edi,[addr]
 
f11:
mov eax,10
int 0x40
cmp eax,2
jne read_done
mov eax,2
int 0x40
shr eax,8
cmp eax,13
je read_done
cmp eax,8
jnz nobsl
cmp edi,[addr]
jz f11
sub edi,1
mov [edi],byte 32
call print_text
jmp f11
nobsl:
mov [edi],al
 
call print_input_text
 
add edi,1
mov esi,[addr]
add esi,30
cmp esi,edi
jnz f11
 
read_done:
 
push edi
 
mov ecx,40
mov eax,32
cld
rep stosb
 
call print_input_text
 
pop edi
sub edi,[addr]
mov eax,[len]
mov [eax],edi
 
cmp [len],l1
jne noip
mov esi,input1
mov edi,ip_text+15
mov ecx,16
cld
rep movsb
call ip_set
noip:
 
cmp [len],l2
jne nol2
mov esi,input2
mov edi,l2_text+15
mov ecx,22
cld
rep movsb
mov esi,input2
mov edi,getmail+5
mov ecx,[l2]
cld
rep movsb
mov al,13
stosb
mov al,10
stosb
nol2:
 
cmp [len],l3
jne nol3
mov esi,input3
mov edi,getmail+32+5
mov ecx,[l3]
cld
rep movsb
mov al,13
stosb
mov al,10
stosb
nol3:
 
call draw_window
 
jmp still
 
 
 
print_input_text:
 
pusha
 
mov eax,13
mov ebx,95*65536+23*6
mov ecx,[ya]
shl ecx,16
mov cx,9
mov edx,0xffffff
int 0x40
 
cmp [len],l3
je noprt
 
mov eax,4
mov edx,[addr]
mov ebx,95*65536
add ebx,[ya]
mov ecx,0x000000
mov esi,23
int 0x40
 
noprt:
 
popa
ret
 
 
ip_set:
 
mov esi,input1-1
mov edi,ip
xor eax,eax
ip1:
inc esi
cmp [esi],byte '0'
jb ip2
cmp [esi],byte '9'
jg ip2
imul eax,10
movzx ebx,byte [esi]
sub ebx,48
add eax,ebx
jmp ip1
ip2:
mov [edi],al
xor eax,eax
inc edi
cmp edi,ip+3
jbe ip1
ret
no_read_ip:
 
ret
 
 
analyze_data:
 
pusha
 
mov [text_start],I_END
mov ecx,[rxs]
imul ecx,11
mov [pos],ecx
 
mov bl,13
call print_character
mov bl,10
call print_character
 
cmp [cmd],2
jbe nott
mov ecx,[cmd]
sub ecx,2
mov esi,command+0
newcmdc:
mov bl,[esi]
call print_character
inc esi
loop newcmdc
 
nott:
 
mov edx,I_END
call draw_server_data
 
cmd_len_ok:
 
cmp [command],dword '-ERR'
je close_fetch
 
cmp [command],word '+O'
jne nook
mov [mcounter],990
nook:
 
popa
 
ret
 
 
 
draw_data:
 
push eax
 
add eax,[text_start]
mov [eax],bl
 
pop eax
ret
 
 
 
print_text:
 
pusha
 
mov ecx,command-2
add ecx,[cmd]
 
ptr2:
mov bl,[eax]
cmp bl,dl
je ptr_ret
cmp bl,0
je ptr_ret
call print_character
inc eax
cmp eax,ecx
jbe ptr2
 
ptr_ret:
 
mov eax,[text_start]
mov [eax+120*60],byte 1
 
popa
ret
 
 
 
print_character:
 
pusha
 
cmp bl,13 ; line beginning
jne nobol
mov ecx,[pos]
add ecx,1
boll1:
sub ecx,1
mov eax,ecx
xor edx,edx
mov ebx,[rxs]
div ebx
cmp edx,0
jne boll1
mov [pos],ecx
jmp newdata
nobol:
 
cmp bl,10 ; line down
jne nolf
addx1:
add [pos],dword 1
mov eax,[pos]
xor edx,edx
mov ecx,[rxs]
div ecx
cmp edx,0
jnz addx1
mov eax,[pos]
jmp cm1
nolf:
no_lf_ret:
 
 
cmp bl,15 ; character
jbe newdata
 
mov eax,[irc_data]
shl eax,8
mov al,bl
mov [irc_data],eax
 
mov eax,[pos]
call draw_data
 
mov eax,[pos]
add eax,1
cm1:
mov ebx,[scroll+4]
imul ebx,[rxs]
cmp eax,ebx
jb noeaxz
 
mov esi,[text_start]
add esi,[rxs]
 
mov edi,[text_start]
mov ecx,ebx
cld
rep movsb
 
mov esi,[text_start]
mov ecx,[rxs]
imul ecx,61
add esi,ecx
 
mov edi,[text_start]
mov ecx,[rxs]
imul ecx,60
add edi,ecx
mov ecx,ebx
cld
rep movsb
 
mov eax,ebx
sub eax,[rxs]
noeaxz:
mov [pos],eax
 
newdata:
 
mov eax,[text_start]
mov [eax+120*60],byte 1
 
popa
ret
 
 
 
read_incoming_byte:
 
mov eax, 53
mov ebx, 2
mov ecx, [socket]
int 0x40
 
mov ecx,-1
 
cmp eax,0
je no_more_data
 
mov eax, 53
mov ebx, 3
mov ecx, [socket]
int 0x40
 
mov ecx,0
 
no_more_data:
 
ret
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Window definitions
;;
 
 
 
draw_window:
 
pusha
 
mov eax,12
mov ebx,1
int 0x40
 
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
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
mov edx,22
mov esi,0x44cc44
int 0x40
 
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 ebx,243*65536+8
mov ecx,180*65536+8
mov edx,51
mov esi,0x4488dd
newi:
int 0x40
inc edx
add ecx,12*65536
cmp edx,53
jbe newi
 
mov eax,8 ; open inbox
mov ebx,295*65536+102
mov ecx,190*65536+14
mov edx,60
mov esi,0x5577dd
int 0x40
 
mov eax,38 ; line
mov ebx,5*65536+430
mov ecx,114*65536+114
mov edx,0x000000
int 0x40
 
mov ebx,5*65536+133 ; info text
mov ecx,0x000000
mov edx,text
mov esi,70
newline:
mov eax,4
int 0x40
add ebx,12
add edx,70
cmp [edx],byte 'x'
jne newline
 
mov edx,I_END ; text from server
call draw_server_data
 
mov eax,12
mov ebx,2
int 0x40
 
popa
 
ret
 
 
draw_server_data:
 
pusha
 
mov eax,4
mov ebx,10*65536+26
mov ecx,8
mov esi,[rxs]
dct:
pusha
mov cx,bx
shl ecx,16
mov cx,9
mov eax,13
mov ebx,10*65536
mov bx,word [rxs]
imul bx,6
mov edx,0xffffff
int 0x40
popa
push ecx
mov eax,4
mov ecx,0
int 0x40
add edx,[rxs]
add ebx,10
pop ecx
loop dct
 
popa
ret
 
 
 
text:
 
db ' Incoming mails are written to /rd/1/popc.txt '
db ' '
db ' Check for mail. Force close '
db ' '
ip_text:
db ' Server IP : 192.168.1.200 < '
l2_text:
db ' User : < Open popc.txt '
l3_text:
db ' Password : (not shown) < '
 
db 'x <- END MARKER, DONT DELETE '
 
file_start dd 0x100000
 
files:
dd 1,0,0,0x100000,0xd0000
db '/rd/1/popc.txt',0
filel:
dd 0,0,10000/512,0x100000,0xd0000
db '/rd/1/popc.txt',0
 
ip db 192,168,1,200
 
socket dd 0x0
 
posx dd 0x0
incoming_pos dd 0x0
incoming_string: times 128 db 0
pos dd 0x0
 
text_start dd I_END
print db 0x0
cmd dd 0x0
rxs dd 66
 
res: db 0,0
command: times 256 db 0x0
 
command_position dd 0
counter dd 0
 
numtext db ' '
wcolor dd 0x000000
labelt db 'POP client v ',version
labellen:
scroll: dd 1,8
 
tp: db 'TINYPAD '
pr: db 'POPC TXT',0
 
 
getmail:
db 'user xyz ',13,10
db 'pass xyz ',13,10
db 'retr 1 ',13,10
db 'retr 2 ',13,10
db 'retr 3 ',13,10
db 'retr 4 ',13,10
db 'retr 5 ',13,10
db 'retr 6 ',13,10
db 'retr 7 ',13,10
db 'retr 8 ',13,10
db 'retr 9 ',13,10
 
quitc:
db 'quit ',13,10
 
mcounter dd 900
ccounter dd 0
 
ld db 13,10
 
server_active db 0
 
header_sent db 0
 
close_connection dd 0x0
 
mail_rp dd 0
 
irc_data dd 0x0
addr dd 0x0
ya dd 0x0
len dd 0x0
 
input1: times 50 db 32
input2: times 50 db 32
input3: times 50 db 32
 
l1 dd 0
l2 dd 3
l3 dd 3
 
status dd 0x0
 
I_END:
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/ppp/trunk/build_en.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix en >lang.inc
@fasm ppp.asm ppp
@pause
/programs/network/ppp/trunk/build_ru.bat
0,0 → 1,4
@erase lang.inc
@echo lang fix ru >lang.inc
@fasm ppp.asm ppp
@pause
/programs/network/ppp/trunk/chat.inc
0,0 → 1,188
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; CHAT.INC ;;
;; ;;
;; Modem Chat Initiator for PPP Dialer ;;
;; ;;
;; Version 3 2nd May 2003 ;;
;; ;;
;; Copyright 2002 Shrirang Bhagwat, b_shrirang@hotmail.com ;;
;; ;;
;; See file COPYING for details ;;
;; ;;
;; 2/5/03 - Shrirang - Added Abort Strings For sendwait ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Request And Response Chat Strings
; Following Data Structure is used for Request Response Chatting
; with the modem, for each request there is an expected response
; chatreq <-> chatres, 0 (NULL) is delimeter for 1 string
; '`' is delimiter for the section, modify according to your
; modem dialing scheme; in future MenuetOS might provide a graphical
; client to generate this kind of data structure and the PAP packet
; for username and password!
; Aborts strings are used to get outta sendwait early...
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
; REQUESTS
chatreq db 'ATH',13,0 ; 0 (NULL) is required by sendwait
db 'ATZ',13,0
db 'ATM1',13,0
db 'ATX1',13,0 ; My Modem doesn't connect without this
; db 'ATDT;',13,0
db 'ATDT phonenumber',13,0
db '`' ; <- End Marker
 
; RESPONSES
chatres db 'OK',0
db 'OK',0
db 'OK',0
db 'OK',0
; db 'OK',0
db 'CONNECT',0
db '`' ; <- End Marker
 
; ABORTS
aborts db 'ERROR',0
db 'NO CARRIER',0
db 'NO DIALTONE',0
db 'BUSY',0
db 'LINE IN USE',0
db 'NO ANSWER',0
db '`' ; <- End Marker
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; modem_chat - chats with the modem to initiate a connection
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
modem_chat:
 
push edi
push esi
push edx
 
mov edi, chatreq ; init everytime, safe, stateless
mov esi, chatres
 
chat_now:
 
cmp byte [esi], '`' ; are we done?
je chatover
 
mov edx, 6000 ; strings like "atdt;" take long on my modem
call sendwait
 
and eax, eax
jz timeoutoccured
 
updatereq:
 
inc edi
cmp byte [edi], '`'
je updateres
 
cmp byte [edi], 0
jne updatereq
 
inc edi
 
updateres:
 
inc esi
cmp byte [esi], '`'
je chatover
 
cmp byte [esi], 0
jne updateres
 
inc esi
 
jmp chat_now
 
 
chatover:
 
xor eax, eax ; SUCCESS!
inc eax
 
pop edx
pop esi
pop edi
 
ret
 
timeoutoccured:
 
xor eax, eax ; FAIL!
 
pop edx
pop esi
pop edi
 
ret
 
 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; scanaborts - scans the response from modem for abort srings
; ESI - Response from modem
; EDI - Pointer to Abort Table
; ECX - Response Length
; Returns 1 if abort detected, 0 otherwise
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
scanaborts:
 
push esi
push edi
push ecx
 
checkit:
 
push esi
repe cmpsb ; any abort matches?
je abortdetected
pop esi
 
 
updatetbl:
 
inc edi
cmp byte [edi], '`'
je noabortfound
 
cmp byte [edi], 0
jne updatetbl
 
inc edi
 
jmp checkit
 
abortdetected:
 
pop esi
pop ecx
pop edi
pop esi
 
xor eax, eax ; SUCCESS!
inc eax
ret
 
noabortfound :
 
pop ecx
pop edi
pop esi
 
 
xor eax, eax ; FAILED!
ret
 
 
 
 
 
 
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
/programs/network/ppp/trunk/macros.inc
0,0 → 1,266
; 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 <eax,ebx,ecx,edx,esi,edi,ebp,esp>
 
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)
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
rb (1024-52)
}
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
Property changes:
Added: svn:eol-style
+native
\ No newline at end of property
<
/programs/network/ppp/trunk/ppp.asm
0,0 → 1,2255
;
; PPP.ASM
;
; Compile with FASM for Menuet
; This program dials into an ISP and establishes a PPP connection
;
; Version 11 26th January 2004
;
; This code is a port of the PPP dialer program by Microchip, from
; their application note AN724
; It has been ported by Mike Hibbett mikeh@oceanfree.net for Menuet
;
; 26/1/04 - Mike Hibbett - added support for com port selected by
; stackcfg
; 2/5/03 - Shrirang - Added Abort Strings To sendwait to get out early
; if modem sends abort strings like NO CARRIER etc.
;
; The original copyright statement follows
;//////////////////////////////////////////////////////////////////////////
;//
;//PING.C version 1.10 July 29/99 (C)opyright by Microchip Technology Inc
;//
;//////////////////////////////////////////////////////////////////////////
 
FALSE equ 0
TRUE equ 1
DEBUG_OUTPUT equ TRUE ; If FALSE, not debugging info outputted
DEBUG_PPP_OUTPUT equ TRUE ; write PPP status msgs to debug board?
DEBUG_PORT2_OUTPUT equ TRUE ; write debug data also to com2
 
 
BAUD_9600 equ 12
BAUD_57600 equ 2
; The next line sets the baud rate of the connection to the modem
BAUDRATE equ BAUD_57600
 
 
LINE_END equ 0x0D ; End of input data character
 
 
; Defines for Internet constants
REQ equ 1 ; Request options list for PPP negotiations
PPP_ACK equ 2 ; Acknowledge options list for PPP negotiations
PPP_NAK equ 3 ; Not acknowledged options list for PPP neg
REJ equ 4 ; Reject options list for PPP negotiations
TERM equ 5 ; Termination packet for LCP to close connectio
LCP_ECHO_REQ equ 9
LCP_ECHO_REP equ 10
IP equ 0x0021 ; Internet Protocol packet
IPCP equ 0x8021 ; Internet Protocol Configure Protocol packet
CCP equ 0x80FD ; Compression Configure Protocol packet
LCP equ 0xC021 ; Link Configure Protocol packet
PAP equ 0xC023 ; Password Authenication Protocol packet
 
 
MaxRx equ 1500
MaxTx equ 1500
 
 
 
 
use32
 
org 0x0
 
db 'MENUET00' ; 8 byte id
dd 38 ; required os
dd STARTAPP ; program start
dd I_END ; program image size
dd 0x100000 ; required amount of memory
; esp = 0x7FFF0
dd 0x00000000 ; reserved=no extended header
 
 
include "lang.inc"
include "macros.inc"
include "chat.inc" ; Hosts modem chatting routine
 
 
STARTAPP:
; mov eax, 0x3f8
; mov [comport], eax
; mov eax, 4
; mov [comirq], eax
 
; Get the com port & IRQ to use from the kernel stack config option
 
mov eax, 52 ; Stack Interface
mov ebx, 0 ; read configuration word
int 0x40
mov ecx, eax
shr ecx, 16 ; get the port address
mov [comport], ecx
shr eax, 8
and eax, 0x000000FF ; get the irq
mov [comirq], eax
 
 
mov eax, [comport]
add eax, 0x01000000
mov [irqtable], eax
 
 
call enable_port
 
appdsp:
mov eax, welcomep
mov [prompt], eax ; set up prompt to display
mov al, [welcomep_len]
mov [prompt_len], al
 
call draw_window ; at first, draw the window
 
 
apploop:
mov eax, 23 ; wait here for event
mov ebx, 20
int 0x40
 
cmp eax, 1 ; redraw request ?
je red
cmp eax, 2 ; key in buffer ?
je key
cmp eax, 3 ; button in buffer ?
je button
mov ebx, [comirq]
add ebx, 16
cmp eax, ebx
je flush_input ; Dont want serial data yet
jmp apploop
 
red: ; redraw
call draw_window
jmp apploop
 
key: ; key - ignore
mov eax, 2 ; just read it
int 0x40
jmp apploop
 
button: ; button
mov eax, 17 ; get id
int 0x40
 
cmp ah, 1 ; close program ?
jne noclose
 
mov esi, hangupWait
mov edi, hangupSend
mov edx, 1000 ; Allow sendwait 10s
call sendwait
 
call disable_port
 
mov eax, -1 ; close this program
int 0x40
jmp apploop
 
noclose:
cmp ah, 2 ; Dial Button pressed?
jne apploop
 
mov eax, conp
mov [prompt], eax ; set up prompt to display
mov al,[conp_len]
mov [prompt_len], al
call draw_window
 
jmp dialloop ; connect to the host
 
 
; Data received, so get it, and throw it away at this point
flush_input:
mov eax,42
mov ebx, [comirq]
int 0x40
 
mov eax,11 ; This will return 0 most of the time
int 0x40
mov ebx, [comirq]
add ebx, 16
cmp eax, ebx
je flush_input
jmp apploop
 
 
dialloop:
call modem_chat ; Try chatting with the modem
 
cmp eax, 1 ; Did it work? ( = 1)
jne appdsp
 
; OK, we are now connected.
 
mov eax, pppOnp
mov [prompt], eax ; set up prompt to display
mov al,[pppOnp_len]
mov [prompt_len], al
call draw_window
 
mov eax, 23
mov ebx, 100
int 0x40 ; wait for 1s to display message
 
call PPPStateMachine ; This is the main code
 
jmp appdsp
 
 
 
 
;****************************************************************************
; Function
; PPPStateMachine
;
; Description
; Handles PPP link establishment
;
;****************************************************************************
PPPStateMachine:
; Start the timer
xor eax, eax
call settimer
 
PPPLoop:
 
mov eax, 11 ; check event
int 0x40
cmp eax, 3
jne PPPLred
; button pressed
mov eax, 17 ; get id
int 0x40
 
 
mov eax, hangp
mov [prompt], eax ; set up prompt to display
mov al,[hangp_len]
mov [prompt_len], al
call draw_window
 
mov esi, hangupWait
mov edi, hangupSend
mov edx, 1000 ; Allow sendwait 10s
call sendwait
 
call disable_port
mov eax, -1 ; close this program
int 0x40
jmp PPPLoop
 
PPPLred:
cmp eax, 1 ; redraw request ?
jne PPPLoop0
 
call draw_window
jmp PPPLoop
 
PPPLoop0:
mov ebx, [comirq]
add ebx, 16
cmp eax, ebx
jne ppp_002 ; check for tx to send
 
 
; we have data in the rx buffer, get it
 
mov eax, 42
mov ebx, [comirq] ; ecx will return 0 =data read, 1 =no data
int 0x40 ; or 2 =not irq owner
 
inc dword [rxbytes]
 
cmp bl, 0x7E
jne ppp_001a
 
mov eax, [rx_ptr]
cmp eax, 0
jz ppp_001
mov eax, [checksum1]
cmp eax, 0xf0b8
jne ppp_001
 
 
movzx eax, byte [rx_str + 3]
mov ah, [rx_str + 2]
mov [packet], eax
 
ppp_001:
mov eax, [extended]
and eax, 0x7e
mov [extended], eax
xor eax, eax
mov [rx_ptr], eax
 
mov eax, 0xffff
mov [checksum1], eax
jmp ppp_003
 
ppp_001a:
cmp bl, 0x7D
jne ppp_001b
 
mov eax, [extended]
or eax, 0x01
mov [extended], eax
jmp ppp_003
 
ppp_001b:
mov eax, [extended]
test eax, 0x01
jz ppp_001c
 
xor bl, 0x20
and eax, 0xFE
mov [extended], eax
 
ppp_001c:
mov edx, [rx_ptr]
cmp edx, 0
jnz ppp_001d
cmp bl, 0xff
je ppp_001d
 
mov [rx_str + edx], byte 0xff
inc edx
 
ppp_001d:
cmp edx, 1
jnz ppp_001e
cmp bl, 0x03
je ppp_001e
 
mov [rx_str + edx], byte 0x03
inc edx
 
ppp_001e:
cmp edx, 2
jnz ppp_001f
test bl, 0x01
jz ppp_001f
 
mov [rx_str + edx], byte 0
inc edx
 
ppp_001f:
mov [rx_str + edx], bl
inc edx
mov [rx_ptr], edx
 
cmp edx, MaxRx
jle ppp_001g
mov edx, MaxRx
mov [rx_ptr], edx
 
ppp_001g:
; do checksum calc
mov eax, [checksum1]
xor bh, bh
xor ax, bx
call calc
mov ebx, [checksum1]
and ebx, 0xffff
shr ebx, 8
xor eax, ebx
mov [checksum1], eax
jmp ppp_003
 
ppp_002:
mov eax, [tx_end]
cmp eax, 0
jz ppp_003
 
mov ebx, [tx_ptr]
mov cl, [tx_str + ebx]
 
cmp ebx, eax
jne ppp_002a
mov [tx_end], dword 0
mov cl, '~'
jmp ppp_002d
 
ppp_002a:
mov eax, [extended]
and eax, 0x02
jz ppp_002b
 
xor cl, 0x20
mov eax, [extended]
and eax, 0xFD
mov [extended], eax
inc [tx_ptr]
jmp ppp_002d
 
ppp_002b:
cmp cl, 0x20
jl ppp_002b1
cmp cl, 0x7d
je ppp_002b1
cmp cl, 0x7e
je ppp_002b1
jmp ppp_002c
 
ppp_002b1:
mov eax, [extended]
or eax, 0x02
mov [extended], eax
mov cl, 0x7d
jmp ppp_002d
 
ppp_002c:
mov eax, [tx_ptr]
cmp eax, 0
jnz ppp_002c1
mov cl, '~'
 
ppp_002c1:
inc [tx_ptr]
 
ppp_002d:
; Test for tx ready.
 
push ecx
 
wait_txd2:
mov eax,43
mov ecx, [comport]
add ecx, 0x80000000 + 5
int 0x40
and bl, 0x40
cmp bl, 0
jz wait_txd2 ; loop until free
 
pop ebx
 
 
; send the character
 
inc dword [txbytes]
 
mov ecx, [comport]
mov eax, 43
int 0x40
 
ppp_003:
mov eax, [packet]
cmp eax, LCP
jne ppp_004
 
mov al, [rx_str + 4]
cmp al, REQ
jne ppp_003b
 
; Debugging output to debug board
pusha
mov esi, RX_LCP_REQ
call debug_output
popa
 
mov eax, [state]
and eax, 0xfd
mov [state], eax
 
mov ebx, 0xc6
push eax
call TestOptions
pop eax
cmp edx, 0
jz ppp_003g
 
cmp edx, 1
jle ppp_003h
 
mov edx, PPP_ACK
cmp eax, 3
jge ppp_003i
 
or eax, 0x02
mov [state], eax
jmp ppp_003i
 
ppp_003h:
mov bl, 0xc0
mov [rx_str + 10], bl
mov edx, PPP_NAK
jmp ppp_003i
 
ppp_003g:
mov edx, REJ
 
ppp_003i:
 
mov ebx, LCP
mov ecx, edx
movzx edx, byte [rx_str + 5]
mov esi, rx_str + 7
call MakePacket
 
mov eax, 0
call settimer
jmp ppp_003a
 
ppp_003b:
cmp al, PPP_ACK
jne ppp_003c
 
; Debugging output to debug board
pusha
mov esi, RX_LCP_ACK
call debug_output
popa
 
mov eax, [number]
cmp al, [rx_str+5]
jne ppp_003a
 
mov eax, [state]