📄 airc.asm
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; 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 0xffff0
dd 0,0
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 ' '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -