📄 telnet.asm
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; TERMINAL
;
; 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
; esp = 0x7FFF0
dd 0x00000000 ; reserved=no extended header
START: ; start of execution
; Clear the screen memory
mov eax, ' '
mov edi,text
mov ecx,80*30 /4
cld
rep stosd
call draw_window
still:
; check connection status
mov eax,53
mov ebx,6
mov ecx,[socket]
int 0x40
mov ebx, [socket_status]
mov [socket_status], eax
cmp eax, ebx
je waitev
call draw_window
waitev:
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
; any data from the socket?
mov eax, 53
mov ebx, 2
mov ecx, [socket]
int 0x40
cmp eax, 0
jne read_input
jmp still
read_input:
push ecx
mov eax, 53
mov ebx, 3
mov ecx, [socket]
int 0x40
pop ecx
call handle_data
push ecx
mov eax, 53
mov ebx, 2
mov ecx, [socket]
int 0x40
pop ecx
cmp eax, 0
jne read_input
call draw_text
jmp still
handle_data:
; Telnet servers will want to negotiate options about our terminal window
; just reject them all.
; Telnet options start with the byte 0xff and are 3 bytes long.
mov al, [telnetstate]
cmp al, 0
je state0
cmp al, 1
je state1
cmp al, 2
je state2
jmp hd001
state0:
cmp bl, 255
jne hd001
mov al, 1
mov [telnetstate], al
ret
state1:
mov al, 2
mov [telnetstate], al
ret
state2:
mov al, 0
mov [telnetstate], al
mov [telnetrep+2], bl
mov edx, 3
mov eax,53
mov ebx,7
mov ecx,[socket]
mov esi, telnetrep
int 0x40
ret
hd001:
cmp bl,13 ; BEGINNING OF LINE
jne nobol
mov ecx,[pos]
add ecx,1
boll1:
sub ecx,1
mov eax,ecx
xor edx,edx
mov ebx,80
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,80
div ecx
cmp edx,0
jnz addx1
mov eax,[pos]
jmp cm1
nolf:
cmp bl,8 ; BACKSPACE
jne nobasp
mov eax,[pos]
dec eax
mov [pos],eax
mov [eax+text],byte 32
mov [eax+text+60*80],byte 0
jmp newdata
nobasp:
cmp bl,15 ; CHARACTER
jbe newdata
mov eax,[pos]
mov [eax+text],bl
mov eax,[pos]
add eax,1
cm1:
mov ebx,[scroll+4]
imul ebx,80
cmp eax,ebx
jb noeaxz
mov esi,text+80
mov edi,text
mov ecx,ebx
cld
rep movsb
mov eax,ebx
sub eax,80
noeaxz:
mov [pos],eax
newdata:
ret
red: ; REDRAW WINDOW
call draw_window
jmp still
key: ; KEY
mov eax,2 ; send to modem
int 0x40
mov ebx, [socket_status]
cmp ebx, 4 ; connection open?
jne still ; no, so ignore key
shr eax,8
cmp eax,178 ; ARROW KEYS
jne noaup
mov al,'A'
call arrow
jmp still
noaup:
cmp eax,177
jne noadown
mov al,'B'
call arrow
jmp still
noadown:
cmp eax,179
jne noaright
mov al,'C'
call arrow
jmp still
noaright:
cmp eax,176
jne noaleft
mov al,'D'
call arrow
jmp still
noaleft:
modem_out:
call to_modem
jmp still
button: ; BUTTON
mov eax,17
int 0x40
cmp ah,1 ; CLOSE PROGRAM
jne noclose
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
mov eax,-1
int 0x40
noclose:
cmp ah, 2 ; Set IP
jne notip
mov [string_x], dword 78
mov [string_y], dword 276
mov [string_length], dword 15
call read_string
mov esi,string-1
mov edi,ip_address
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_address+3
jbe ip1
call draw_window
jmp still
notip:
cmp ah, 3 ; set port
jne notport
mov [string_x], dword 215
mov [string_y], dword 276
mov [string_length], dword 4
call read_string
mov esi,string-1
mov edi,port
xor eax,eax
ip11:
inc esi
cmp [esi],byte '0'
jb ip21
cmp [esi],byte '9'
jg ip21
imul eax,10
movzx ebx,byte [esi]
sub ebx,48
add eax,ebx
jmp ip11
ip21:
mov [edi],al
inc edi
mov [edi],ah
call draw_window
jmp still
notport:
cmp ah, 4 ; connect
jne notcon
mov eax, [socket_status]
cmp eax, 4
je still
call connect
jmp still
notcon:
cmp ah,5 ; disconnect
jne notdiscon
call disconnect
jmp still
notdiscon: ; Echo Toggle
cmp ah, 6
jne still
mov al, [echo]
not al
mov [echo], al
call draw_window
jmp still
arrow:
push eax
mov al,27
call to_modem
mov al,'['
call to_modem
pop eax
call to_modem
ret
to_modem:
pusha
push ax
mov [tx_buff], al
mov edx, 1
cmp al, 13
jne tm_000
mov edx, 2
tm_000:
mov eax,53
mov ebx,7
mov ecx,[socket]
mov esi, tx_buff
int 0x40
pop bx
mov al, [echo]
cmp al, 0
je tm_001
push bx
call handle_data
pop bx
cmp bl, 13
jne tm_002
mov bl, 10
call handle_data
tm_002:
call draw_text
tm_001:
popa
ret
disconnect:
mov eax,53
mov ebx,8
mov ecx,[socket]
int 0x40
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -