1,287 → 1,164 |
;------------------------------------------------------------------------------- |
; DEBUG BOARD v1.0.1 for APPLICATIONS and KERNEL DEVELOPMENT |
;------------------------------------------------------------------------------ |
; DEBUG BOARD for APPLICATIONS and KERNEL DEVELOPMENT |
; See f63 |
; Compile with FASM for KolibriOS |
;------------------------------------------------------------------------------- |
;------------------------------------------------------------------------------ |
use32 |
org 0 |
db "MENUET01" |
db 'MENUET01' |
dd 1 |
dd START |
dd I_END |
dd MEM_END |
dd STACK_TOP |
dd PARAMS_STRING |
dd mem |
dd mem |
dd filename |
dd 0 |
;------------------------------------------------------------------------------- |
include "lang.inc" |
include "../../../macros.inc" |
;------------------------------------------------------------------------------ |
include 'lang.inc' |
include '../../../macros.inc' |
include '../../../debug.inc' |
purge newline |
;SMALL FONT |
MAXSTRINGS = 45 |
LINE_H = 10 |
WINDOW_W = 399 |
WINDOW_H = MAXSTRINGS*LINE_H+45 |
FONT_TYPE = 0x40000000 |
;BIG FONT |
; MAXSTRINGS = 30 |
; LINE_H = 15 |
; WINDOW_W = 630 |
; WINDOW_H = MAXSTRINGS*LINE_H+50 |
; FONT_TYPE = 0x50000000 |
|
purge newline |
MAX_STRINGS = 45 |
STRING_LENGTH = 80 ;must be a multiple of 4 |
LINE_HEIGHT = 16 |
WINDOW_W = 60*8+5*2 |
WINDOW_W_MIN = 330 |
WORK_AREA_H_MIN = 60 |
WINDOW_W_PRCNT = 40 |
WINDOW_H_PRCNT = 75 |
TEXTFIELD_H = MAX_STRINGS*LINE_HEIGHT |
FONT_TYPE = 0x50000000 |
;------------------------------------------------------------------------------- |
;------------------------------------------------------------------------------ |
START: |
mcall 68, 11 ;init heap |
|
call parse_params_string |
test eax, eax |
jnz .no_params |
call check_and_fix_params |
|
.no_params: |
call STATE_handler |
|
mov ecx, MAX_STRINGS*(STRING_LENGTH/4) |
call CheckUnique |
mov edi, filename |
cmp [edi], byte 0 |
jnz param |
mov esi, default_filename |
@@: |
lodsb |
stosb |
test al,al |
jnz @b |
param: |
mov ecx, (MAXSTRINGS+1)*20 |
mov edi, text1 |
mov eax, " " |
push ecx |
mov eax, ' ' |
rep stosd |
|
pop ecx |
mov ecx, (MAXSTRINGS+1)*20 |
mov edi, text2 |
rep stosd |
|
cmp [params.daemon_mode], 1 |
je .create_log_file |
mov byte [tmp1], 'x' |
mov byte [tmp2], 'x' |
|
call calc_window_size |
mov ax, word [xstart+2] |
mov [prev_win_x], ax |
mov ax, word [ystart+2] |
mov [prev_win_y], ax |
mov ax, word [xstart] |
mov [prev_win_w], ax |
mov ax, word [ystart] |
mov [prev_win_h], ax |
|
cmp [fullscreen_mode], 0 |
je @f |
call calc_fullscreen_window_size |
|
@@: |
mcall 14 |
and eax, 0xffff0000 |
sub eax, WINDOW_W shl 16 |
add eax, WINDOW_W |
mov [xstart], eax |
mcall 48, 3, sc, sizeof.system_colors |
|
xor eax, eax |
mov [vmode], eax |
mov dword [text1-4], eax |
mov dword [text1-8], eax |
mov dword [text2-4], eax |
mov dword [text2-8], eax |
mov [krnl_cnt], eax |
mov [hl_line_count], eax |
|
.create_log_file: |
xor eax, eax |
mov byte [buffer_length], al |
mov [filepos], eax |
|
cmp [params.logging_mode], 0 |
je @f |
|
mov esi, [log_filename] |
call create_file |
jnc @f |
mov esi, default_log_filename |
mov [log_filename], default_log_filename |
call create_file |
|
@@: |
cmp [params.daemon_mode], 0 |
je .red |
mcall 40, 0 ;set event mask (do not receive any event codes) |
|
.red: |
cmp [params.daemon_mode], 1 |
je .still |
mcall 9, procinfo, -1 ;get info about board process |
mov eax, dword [procinfo+42] ;width of board window |
mov edx, WINDOW_W_MIN |
cmp eax, edx |
jae @f |
mcall 67, -1, -1, WINDOW_W_MIN, -1 ;resize window |
mov dword [procinfo+42], edx |
|
@@: |
mcall 48, 4 ; get window header height |
mov [window_header_height], eax |
mov esi, WORK_AREA_H_MIN |
add esi, eax |
mov eax, dword [procinfo+46] ;height of board window |
cmp eax, esi |
jae @f |
mcall 67, -1, -1, -1 ;resize window |
mov dword [procinfo+46], esi |
|
@@: |
mov esi, filename |
call CreateFile |
;------------------------------------------------------------------------------ |
red: |
call draw_window |
|
.still: |
cmp byte [buffer_length], 0 |
;------------------------------------------------------------------------------ |
still: |
cmp [buffer_length], 0 |
je @f |
cmp [params.logging_mode], 0 |
je @f |
call write_buffer |
|
@@: |
cmp [params.daemon_mode], 0 |
je @f |
mcall 5, 50 ;pause for 0.5 sec |
jmp .read_byte |
@@: |
mcall 23, 50 ; wait here for event |
dec eax ; redraw request ? |
jz .red |
cmp eax, 1 ; redraw request ? |
je red |
|
dec eax ; key in buffer ? |
jz .key |
cmp eax, 2 ; key in buffer ? |
je key |
|
dec eax ; button in buffer ? |
jz .button |
cmp eax, 3 ; button in buffer ? |
je button |
|
.read_byte: |
mcall 63, 2 ;read a byte from the debug buffer |
mcall 63, 2 |
cmp ebx, 1 |
je .new_data |
jne .still |
jne still |
|
.key: |
mcall 2 |
cmp ah, " " |
new_data: |
cmp [buffer_length], 255 |
jne @f |
not [vmode] |
and [vmode], 1 |
jmp .red |
@@: |
cmp ah, 51 ; F2 |
je .open_boardlog |
cmp ah, 0x1B ;[Esc]? |
je terminate_board |
cmp ah, 0x44 ;[F11]? |
jne .still |
cmp [fullscreen_mode], 0 |
jne @f |
mov [fullscreen_mode], 1 |
mcall 9, procinfo, -1 ;get info about process |
mov ax, word [ebx+34] |
mov [prev_win_x], ax |
mov ax, word [ebx+38] |
mov [prev_win_y], ax |
mov ax, word [ebx+42] |
mov [prev_win_w], ax |
mov ax, word [ebx+46] |
mov [prev_win_h], ax |
call calc_fullscreen_window_size |
movzx ebx, word [xstart+2] |
movzx ecx, word [ystart+2] |
movzx edx, word [xstart] |
movzx esi, word [ystart] |
mcall 67 ;change window size & position |
jmp .still |
|
@@: |
mov [fullscreen_mode], 0 |
mcall 71, 2, title, 1 ;set window caption |
mcall 18, 25, 2, -1, 0 ;set window position (usual) |
mov [already_on_top], 0 |
movzx ebx, word [prev_win_x] |
movzx ecx, word [prev_win_y] |
movzx edx, word [prev_win_w] |
movzx esi, word [prev_win_h] |
mcall 67 ;change window size & position |
|
@@: |
jmp .still |
|
.open_boardlog: |
mov eax, [log_filename] |
mov [open_log_in_tinypad+8], eax |
mcall 70, open_log_in_tinypad |
jmp .red |
|
.button: |
mcall 17 ; get id |
cmp ah, 1 ; button id=1 ? |
jne .button.noclose |
|
.exit: |
jmp terminate_board |
.button.noclose: |
cmp ah, 3 |
jne @f |
mov [vmode], 0 |
jmp .red |
@@: |
cmp ah, 4 |
jne @f |
mov [vmode], 1 |
@@: |
jmp .red |
|
.new_data: |
cmp byte [buffer_length], 255 |
jne @f |
cmp [params.logging_mode], 0 |
je @f |
call write_buffer |
|
@@: |
movzx ebx, byte [buffer_length] |
mov [ebx+tmp], al |
inc byte [buffer_length] |
cmp [params.daemon_mode], 1 |
je .read_byte |
inc [buffer_length] |
mov ebp, [targ] |
cmp al, 10 |
jz .new_line |
jz new_line |
cmp al, 13 |
jz .new_check |
jmp .char |
|
.new_line: |
jz new_check |
jmp char |
;------------------------------------------ |
write_buffer: |
pusha |
mov edx, tmp |
movzx ecx, byte[buffer_length] |
mov esi, filename |
.write_to_logfile: |
call WriteToFile |
cmp eax, 5 |
jne @f |
mov esi, filename |
mov [filepos], 0 |
call CreateFile |
jnc .write_to_logfile |
@@: |
movzx eax,byte[buffer_length] |
add [filepos],eax |
xor eax,eax |
mov [buffer_length],al |
popa |
ret |
;------------------------------------------ |
new_line: |
and [ebp-8], dword 0 |
inc dword [ebp-4] |
cmp [ebp-4], dword MAX_STRINGS |
jb .noypos |
mov [ebp-4], dword MAX_STRINGS-1 |
lea esi, [ebp+STRING_LENGTH] |
cmp [ebp-4], dword MAXSTRINGS |
jbe .noypos |
mov [ebp-4], dword MAXSTRINGS |
lea esi, [ebp+80] |
mov edi, ebp |
mov ecx, (MAX_STRINGS-1)*(STRING_LENGTH/4) |
mov ecx, 20*(MAXSTRINGS) |
cld |
rep movsd |
|
mov esi, [ebp-4] |
imul esi, STRING_LENGTH |
imul esi, 80 |
add esi, [ebp-8] |
add esi, ebp |
mov ecx, STRING_LENGTH/4 |
mov eax, " " |
mov ecx, 20 |
mov eax, ' ' |
rep stosd |
|
.noypos: |
mov [targ], text1 |
mov [targ],text2 |
and [krnl_cnt], 0 |
jmp .new_check |
|
.char: |
cmp ebp, text2 |
je .add2 |
jmp new_check |
;------------------------------------------ |
char: |
cmp ebp, text1 |
je add2 |
mov ecx, [krnl_cnt] |
cmp al, [krnl_msg+ecx] |
jne .nokrnl |
jne .noknl |
inc [krnl_cnt] |
cmp [krnl_cnt], 4 |
jne .new_check |
mov [targ], text2 |
.nokrnl: |
jne new_check |
mov [targ], text1 |
.noknl: |
mov ebp, [targ] |
jecxz .add |
push eax |
293,801 → 170,149 |
pop eax |
.add: |
and [krnl_cnt], 0 |
.add2: |
add2: |
call add_char |
|
.new_check: |
mcall 63, 2 ;read a byte from the debug buffer |
new_check: |
mcall 63, 2 |
cmp ebx, 1 |
je .new_data |
|
cmp [params.daemon_mode], 1 |
je .still |
je new_data |
call draw_text |
jmp still |
;------------------------------------------------------------------------------ |
key: |
mcall 2 |
cmp ah, ' ' |
je button.noclose |
cmp ah, 51 ; F2 |
je open_boardlog |
jmp still |
open_boardlog: |
mcall 70, open_log_in_tinypad |
jmp red |
|
jmp .still |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------ |
button: |
mcall 17 ; get id |
cmp ah, 1 ; button id=1 ? |
jne .noclose |
or eax, -1 ; close this program |
mcall |
.noclose: |
xor [vmode], 1 |
jmp red |
;------------------------------------------------------------------------------ |
add_char: |
push esi |
mov esi, [ebp-4] |
imul esi, STRING_LENGTH |
imul esi, 80 |
add esi, [ebp-8] |
mov [ebp+esi], al |
cmp dword [ebp-8], STRING_LENGTH-1 |
je .ok |
inc dword [ebp-8] |
cmp dword[ebp-8], 80 |
jb .ok |
mov dword[ebp-8], 79 |
.ok: |
pop esi |
ret |
;------------------------------------------------------------------------------- |
|
calc_fullscreen_window_size: |
;------------------------------------------------------------------------------- |
push eax |
|
mcall 14 ;get screen size |
; inc ax |
mov word [ystart], ax |
shr eax, 16 |
; inc ax |
mov word [xstart], ax |
xor eax, eax |
mov word [xstart+2], ax |
mov word [ystart+2], ax |
|
pop eax |
ret |
;------------------------------------------------------------------------------- |
|
calc_window_size: |
;------------------------------------------------------------------------------- |
pusha |
|
mcall 48, 5 ;get screen working area size |
mov [ystart], ebx |
ror eax, 16 |
ror ebx, 16 |
mov [xstart], eax |
movzx ecx, ax |
movzx edx, bx |
shr eax, 16 |
shr ebx, 16 |
sub eax, ecx |
sub ebx, edx |
inc eax |
inc ebx |
|
mov ecx, 100 |
mov edx, WINDOW_W_PRCNT |
mul edx |
xor edx, edx |
div ecx |
cmp ax, WINDOW_W_MIN |
jae @f |
mov ax, WINDOW_W_MIN |
@@: |
mov word [xstart], ax |
sub word [xstart+2], ax |
mov eax, ebx |
mov edx, WINDOW_H_PRCNT |
mul edx |
xor edx, edx |
div ecx |
mov dx, ax |
mov cx, WORK_AREA_H_MIN |
mcall 48, 4 ; get window header height |
add ax, cx |
cmp dx, ax |
jae @f |
mov dx, ax |
@@: |
mov word [ystart], dx |
|
popa |
ret |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
write_buffer: |
pusha |
|
mov edx, tmp |
movzx ecx, byte [buffer_length] |
mov esi, [log_filename] |
mov ebx, ecx |
|
.write_to_logfile: |
call write_to_file |
cmp eax, 5 |
jne @f |
mov esi, [log_filename] |
mov [filepos], 0 |
call create_file |
jnc .write_to_logfile |
; mov [params.logging_mode], 0 |
jmp .ret |
@@: |
add [filepos], ebx |
xor eax, eax |
mov byte [buffer_length], al |
|
.ret: |
popa |
ret |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
parse_params_string: |
;result: eax = 0 (OK), eax = -1 (no params string), -2 (wrong params string) |
xor eax, eax |
pusha |
|
mov esi, PARAMS_STRING |
mov ecx, 256 |
|
cmp byte [esi], 0 |
je .no_params_string |
|
@@: |
call skip_spaces |
call check_param |
inc eax |
jz .no_params_string |
inc eax |
jz .wrong_params_string |
cmp byte [esi], 0 |
je .ok |
loop @b |
|
.ok: |
popa |
|
ret |
|
.no_params_string: |
popa |
|
dec eax |
|
ret |
|
.wrong_params_string: |
popa |
|
dec eax |
dec eax |
|
ret |
|
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
skip_spaces: |
push eax |
cld |
.0: |
lodsb |
cmp al, " " |
je @f |
cmp al, 9 ;skip tabs too |
jne .ret |
@@: |
loop .0 |
|
.ret: |
dec esi |
|
pop eax |
ret |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
check_param: |
push ebx |
|
test ecx, ecx |
jz .empty |
|
cld |
lodsb |
test al, al |
jnz @f |
dec esi |
jmp .empty |
|
@@: |
cmp al, "-" |
jne .not_option |
dec ecx |
lodsb |
test al, al |
jz .wrong_option |
cmp al, " " |
je .wrong_option |
cmp al, 9 |
je .wrong_option |
|
dec esi |
call check_option |
inc eax |
jnz .ok |
|
.wrong_option: |
lea esi, [esi-2] |
jmp .wrong |
|
.not_option: |
cmp [params.log_filename_found], 1 |
je .wrong |
mov [params.log_filename], esi |
cmp al, '"' |
je .quoted |
dec [params.log_filename] |
xor ebx, ebx |
inc ebx |
dec ecx |
|
@@: |
lodsb |
test al, al |
jz @f |
cmp al, " " |
je @f |
cmp al, 9 |
je @f |
inc ebx |
loop @b |
dec ebx |
|
@@: |
dec esi |
mov [params.log_filename_found], 1 |
mov [params.log_filename.size], ebx |
jmp .ok |
|
.quoted: |
xor ebx, ebx |
dec ecx |
.quoted.0: |
lodsb |
test al, al |
jnz @f |
lea ecx, [ecx+ebx+1] |
lea esi, [esi-2] |
sub esi, ebx |
jmp .wrong |
@@: |
cmp al, '"' |
je @f |
inc ebx |
loop .quoted.0 |
lea ecx, [ecx+ebx+1] |
lea esi, [esi-2] |
sub esi, ebx |
jmp .wrong |
|
@@: |
mov al, byte [esi] |
test al, al |
jz @f |
cmp al, " " |
je @f |
cmp al, 9 |
jne .wrong ;there must be spaces or null after closing (final) quote mark |
@@: |
mov [params.log_filename_found], 1 |
mov [params.log_filename.size], ebx |
|
|
.ok: |
xor eax, eax |
|
pop ebx |
ret |
|
.empty: |
xor eax, eax |
dec eax |
|
pop ebx |
ret |
|
.wrong: |
xor eax, eax |
dec eax |
dec eax |
|
pop ebx |
ret |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
check_option: |
push ebx edi |
lea ebx, [esi-1] |
cmp byte [esi], "-" |
je .long_option |
|
cld |
@@: |
lodsb |
test al, al |
jz .ok |
cmp al, " " |
je .ok |
cmp al, 9 |
je .ok |
call .subcheck |
test eax, eax |
jz .wrong |
loop @b |
|
.subcheck: |
cmp al, "d" |
jne @f |
mov [params.daemon_mode], 1 |
ret |
|
@@: |
cmp al, "s" |
jne @f |
mov [params.stop_daemon_flag], 1 |
ret |
|
@@: |
cmp al, "n" |
jne @f |
mov [params.logging_mode], 0 |
ret |
|
@@: |
cmp al, "r" |
jne @f |
mov [params.rewrite_log_flag], 1 |
ret |
|
@@: |
cmp al, "f" |
jne @f |
mov [fullscreen_mode], 1 |
ret |
|
|
|
|
@@: |
xor eax, eax |
ret |
|
|
.long_option: |
lodsb |
dec ecx |
jz .wrong |
mov edi, esi |
push esi |
cmp ecx, params.options.d.size-1 |
jl @f |
mov esi, params.options.d |
call cmp_str |
jnz @f |
pop esi |
lea ecx, [ecx-params.options.d.size-1] |
lea esi, [esi+params.options.d.size-1] |
mov [params.daemon_mode], 1 |
jmp .long_option.0 |
|
@@: |
cmp ecx, params.options.s.size-1 |
jl @f |
mov esi, params.options.s |
call cmp_str |
jnz @f |
pop esi |
lea ecx, [ecx-params.options.s.size-1] |
lea esi, [esi+params.options.s.size-1] |
mov [params.stop_daemon_flag], 1 |
jmp .long_option.0 |
|
@@: |
cmp ecx, params.options.n.size-1 |
jl @f |
mov esi, params.options.n |
call cmp_str |
jnz @f |
pop esi |
lea ecx, [ecx-params.options.n.size-1] |
lea esi, [esi+params.options.n.size-1] |
mov [params.logging_mode], 0 |
jmp .long_option.0 |
|
@@: |
cmp ecx, params.options.r.size-1 |
jl @f |
mov esi, params.options.r |
call cmp_str |
jnz @f |
pop esi |
lea ecx, [ecx-params.options.r.size-1] |
lea esi, [esi+params.options.r.size-1] |
mov [params.rewrite_log_flag], 1 |
jmp .long_option.0 |
|
@@: |
cmp ecx, params.options.f.size-1 |
jl @f |
mov esi, params.options.f |
call cmp_str |
jnz @f |
pop esi |
lea ecx, [ecx-params.options.f.size-1] |
lea esi, [esi+params.options.f.size-1] |
mov [fullscreen_mode], 1 |
jmp .long_option.0 |
|
@@: |
pop esi |
jmp .wrong |
|
.long_option.0: |
mov al, byte [esi] |
test al, al |
jz @f |
cmp al, " " |
je @f |
cmp al, 9 |
jne .wrong ;there must be spaces or null after long option |
@@: |
inc esi |
|
.ok: |
dec esi |
xor eax, eax |
|
pop edi ebx |
ret |
|
.wrong: |
xor eax, eax |
dec eax |
pop edi esi |
ret |
;------------------------------------------------------------------------------- |
|
check_and_fix_params: |
;------------------------------------------------------------------------------- |
push eax |
|
cmp [params.daemon_mode], 1 |
jne @f |
mov [params.stop_daemon_flag], 0 |
mov [params.logging_mode], 1 |
|
@@: |
mov eax, [params.log_filename] |
test eax, eax |
jz @f |
mov [log_filename], eax |
add ebx, [params.log_filename.size] |
mov byte [eax+ebx], 0 |
|
@@: |
pop eax |
ret |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
;------------------------------------------------------------------------------ |
;************************ WINDOW DEFINITIONS AND DRAW ************************ |
;------------------------------------------------------------------------------- |
;------------------------------------------------------------------------------ |
draw_window: |
mcall 12, 1 ; start of draw |
xor edx, edx |
mov dl, 0x13 |
cmp [fullscreen_mode], 0 |
je @f |
mov dl, 1 ;set fullscreen mode window |
|
@@: |
shl edx, 24 |
or edx, 0xFFFFFF |
mcall 12, 1 ; 1, start of draw |
mcall 48, 5 ; GetClientTop |
shr ebx, 16 |
mov ecx, ebx |
shl ecx, 16 |
add ecx, WINDOW_H ; [y start] *65536 + [y size] |
mov edx, 0xffffff |
or edx, 0x14000000 |
xor esi, esi |
mcall 0,[xstart],[ystart],,,title |
|
cmp [fullscreen_mode], 0 |
je .l0 |
|
cmp [already_on_top], 1 |
je @f |
mcall 18, 25, 2, -1, 1 ;set window position (always on top) |
mov [already_on_top], 1 |
|
@@: |
mcall 13, [xstart], [ystart], 0xFFFFFF ;draw a rectangle (fill the window) |
|
.l0: |
mov ebx, 15 shl 16+(8*4+5) |
xor ecx, ecx |
cmp [fullscreen_mode], 1 |
je @f |
mov ecx, [window_header_height] |
|
@@: |
add ecx, 5 |
shl ecx, 16 |
mov cx, LINE_HEIGHT+5 |
mov eax, [sc.work_button] |
cmp [vmode], 0 |
jne @f |
call lighten_color ;make button lighter if it's active |
@@: |
mov esi, eax |
mcall 8,,,3 ;'User' button |
|
push ebx ecx |
|
shr ecx, 16 |
mov bx, cx |
rol ebx, 16 |
add bx, 3 |
ror ebx, 16 |
add bx, 4 |
mov ecx, 0x90 |
shl ecx, 24 |
mcall 0,[xstart],,,,title |
mov ebx, 296 shl 16+31 |
mcall 8,,<4,13>,3,[sc.work_button] |
mov edx, [vmode] |
lea edx, [edx*4+duk] |
mov ecx, 0x80 |
shr ecx, 24 |
add ecx, [sc.work_button_text] |
mcall 4,,, u_button_text |
cmp [vmode], 0 |
jne @f |
add ebx, 1 shl 16 |
mcall ;make text bolder if the button is active |
|
@@: |
pop ecx ebx |
|
add ebx, (8*4+10) shl 16 |
mov bx, (8*6+5+5) |
mov eax, [sc.work_button] |
cmp [vmode], 1 |
jne @f |
call lighten_color ;make button lighter if it's active |
@@: |
mov esi, eax |
mcall 8,,,4 ;'Kernel' button |
|
shr ecx, 16 |
mov bx, cx |
rol ebx, 16 |
add bx, 3 |
ror ebx, 16 |
add bx, 4 |
mov ecx, 0x90 |
shl ecx, 24 |
add ecx, [sc.work_button_text] |
mcall 4,,, k_button_text |
cmp [vmode], 1 |
jne @f |
add ebx, 1 shl 16 |
mcall ;make text bolder if the button is active |
|
@@: |
mcall 4,<300,7>,,,4 |
call draw_text |
mcall 12, 2 ; 2, end of draw |
ret |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
;------------------------------------------------------------------------------ |
draw_text: |
mov ebx, 15 shl 16 + 0 |
xor bx, bx |
cmp [fullscreen_mode], 1 |
je @f |
mov bx, word [window_header_height] |
|
@@: |
add bx, 5+(LINE_HEIGHT+5)+5 ;space between window header and textfield |
mov ecx, FONT_TYPE |
mov edi, 0xFFFFFF |
mov ebx, 15*65536+30 ; draw info text with function 4 |
xor ecx, ecx |
or ecx, FONT_TYPE |
mov edi, 0xffffff |
mov edx, text1 |
cmp [vmode], 0 |
je .kern |
mov edx, text2 |
cmp [vmode], 1 |
je .kern |
mov edx, text1 |
.kern: |
push ebx edx |
|
|
|
mov eax, dword [procinfo+42] ;x-size of board window |
sub eax, 15*2 |
push ebx ecx edx |
mcall 9, procinfo,-1 |
mov eax, [ebx+42] |
xor edx, edx |
mov ebx, 8 |
mov ebx, 6 |
div ebx |
|
@@: |
cmp [vmode], 1 |
jne @f |
add eax, 4 |
|
@@: |
mov esi, STRING_LENGTH |
pop edx ecx ebx |
mov esi, 80 |
cmp eax, esi |
ja @f |
mov esi, eax |
|
@@: |
mov eax, dword [procinfo+46] ;y-size of board window |
cmp [fullscreen_mode], 1 |
je @f |
sub eax, [window_header_height] |
|
@@: |
sub eax, 5+(LINE_HEIGHT+5)+5+5 |
xor edx, edx |
mov ebx, 16 |
div ebx |
|
pop edx ebx |
|
mov ebp, [edx-4] ;[edx-4] = count of strings |
cmp eax, ebp |
cmp esi, 5 |
ja @f |
mov ebp, eax |
|
mov esi, 5 |
@@: |
test ebp, ebp |
jz .ret |
sub esi, 4 |
mov eax, 4 |
.newline: |
cmp [edx], dword "K : " |
jne .no_k_prefix |
|
push edx esi |
add edx, 4 |
sub esi, 4 |
|
push ecx esi edi |
mov ecx, STRING_LENGTH-4 |
mov edi, edx |
|
mov esi, proc_fors_term |
call cmp_str |
jz .highlight |
|
mov esi, proc_fors_term_sp |
call cmp_str |
jnz .no_fors_term |
|
.highlight: |
lea edi, [edx+STRING_LENGTH*7] |
mov esi, unexp_end_of_stack |
call cmp_str |
jnz @f |
mov [hl_line_count], 8 |
jmp .no_fors_term |
@@: |
mov [hl_line_count], 10 |
|
.no_fors_term: |
pop edi esi ecx |
push ecx |
cmp [hl_line_count], 0 |
je @f |
and ecx, 0xFF000000 |
or ecx, 0xCC0000 ;red |
dec [hl_line_count] |
@@: |
mcall ; draw info text with function 4 |
pop ecx |
pop esi edx |
jmp @f |
.no_k_prefix: |
newline: |
mcall |
@@: |
add ebx, LINE_HEIGHT |
add edx, STRING_LENGTH |
dec ebp |
jnz .newline |
.ret: |
add ebx, LINE_H |
add edx, 80 |
cmp [edx], byte 'x' |
jne newline |
ret |
;------------------------------------------------------------------------------- |
|
cmp_str: |
;------------------------------------------------------------------------------- |
pusha |
|
@@: |
lodsb |
test al, al |
jz .ret |
scasb |
loope @b |
xor eax, eax |
inc eax |
|
.ret: |
popa |
ret |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
lighten_color: |
ror eax, 16 |
add al, 20 |
rol eax, 8 |
add al, 20 |
rol eax, 8 |
add al, 20 |
ret |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
;------------------------------------------------------------------------------ |
;* input: esi = pointer to the file name * |
;------------------------------------------------------------------------------- |
create_file: |
;------------------------------------------------------------------------------ |
CreateFile: |
pusha |
|
cmp [params.rewrite_log_flag], 1 |
je .create |
xor eax, eax |
mov dword [f70_structure+0], 5 ; get file info |
mov dword [f70_structure+4], eax ; reserved |
mov dword [f70_structure+8], eax ; reserved |
mov dword [f70_structure+12], eax ; reserved |
mov dword [f70_structure+16], file_info ; file info buf pointer |
mov dword [f70_structure+20], eax ; reserved |
mov dword [f70_structure+21], esi ; pointer to the file name |
mcall 70, f70_structure |
cmp eax, 5 |
je .create ;create file if it doesn't exist |
mov dword [InfoStructure+00], 2 ; create file |
mov dword [InfoStructure+04], 0 ; reserved |
mov dword [InfoStructure+08], 0 ; reserved |
mov dword [InfoStructure+12], 0 ; 0 bytes to write (just create) |
mov dword [InfoStructure+16], 0 ; NULL data pointer (no data) |
mov dword [InfoStructure+20], 0 ; reserved |
mov dword [InfoStructure+21], esi ; pointer to the file name |
mcall 70, InfoStructure |
test eax, eax |
jnz .create |
|
cmp dword [file_info+36], 0 |
jne .create |
mov eax, dword [file_info+32] |
mov [filepos], eax |
|
jmp .ret |
|
.create: |
xor eax, eax |
mov dword [f70_structure+0], 2 ; create file |
mov dword [f70_structure+4], eax ; reserved |
mov dword [f70_structure+8], eax ; reserved |
mov dword [f70_structure+12], eax ; 0 bytes to write (just create) |
mov dword [f70_structure+16], eax ; NULL data pointer (no data) |
mov dword [f70_structure+20], eax ; reserved |
mov dword [f70_structure+21], esi ; pointer to the file name |
mcall 70, f70_structure |
test eax, eax |
jz .ret |
jz .out |
stc |
.ret: |
.out: |
popa |
ret |
;------------------------------------------------------------------------------- |
|
|
|
|
|
|
;------------------------------------------------------------------------------- |
;------------------------------------------------------------------------------ |
;* input: esi = pointer to the file name * |
;* edx = pointer to data buffer * |
;* ecx = data length * |
;------------------------------------------------------------------------------- |
write_to_file: |
;------------------------------------------------------------------------------ |
WriteToFile: |
push ebx |
mov dword [f70_structure+0], 3 ; write to file |
mov dword [InfoStructure+00], 3 ; write to file |
mov eax, [filepos] |
mov dword [f70_structure+4], eax ; lower position addr |
mov dword [f70_structure+8], 0 ; upper position addr (0 for FAT) |
mov dword [f70_structure+12], ecx ; number of bytes to write |
mov dword [f70_structure+16], edx ; pointer to data buffer |
mov dword [f70_structure+20], 0 ; reserved |
mov dword [f70_structure+21], esi ; pointer to the file name |
mcall 70, f70_structure |
mov dword [InfoStructure+04], eax ; lower position addr |
mov dword [InfoStructure+08], 0 ; upper position addr (0 for FAT) |
mov dword [InfoStructure+12], ecx ; number of bytes to write |
mov dword [InfoStructure+16], edx ; pointer to data buffer |
mov dword [InfoStructure+20], 0 ; reserved |
mov dword [InfoStructure+21], esi ; pointer to the file name |
mcall 70, InfoStructure |
clc |
test eax, eax |
jz .out |
1095,187 → 320,161 |
.out: |
pop ebx |
ret |
;------------------------------------------------------------------------------- |
|
;------------------------------------------------------------------------------- |
STATE_handler: |
mcall 68, 22, STATE_shm_block.name,, 0x00 ;open "BOARDAPP:STATE" shared memory block (ro access) |
test eax, eax |
jz .create_STATE_shm_block |
;------------------------------------------------------------------------------ |
;* input: esi = pointer to string * |
;* edi = pointer to string * |
;* ecx = data length * |
;------------------------------------------------------------------------------ |
StrCmp: |
repe cmpsb |
ja .a_greater_b |
jb .a_less_b |
.equal: |
mov eax, 0 |
jmp .end |
.a_less_b: |
mov eax, 1 |
jmp .end |
.a_greater_b: |
mov eax, -1 |
.end: |
ret |
|
mov ecx, 20*10 ;timeout = 20 sec |
.0: |
mov ebx, [eax] |
test ebx, ebx |
jz @f |
mcall 5, 10 ;wait for 0.1 sec |
loop .0 |
jmp terminate_board |
;------------------------------------------------------------------------------ |
;* input: edi = pointer to string * |
;* ecx = data length * |
;------------------------------------------------------------------------------ |
; 'a' - 'A' = 32 -> 'A'|32 = 'a' |
ToLower: |
xor eax, eax |
.cycle: |
or byte[edi+eax], 32 |
inc eax |
loop .cycle |
.end: |
ret |
|
@@: |
mov ebx, [eax+4] |
test ebx, ebx |
jnz terminate_board |
cmp dword [eax+12], 0 |
jne @f |
mov ecx, [eax+16] |
mcall 18, 21 ;get slot number by PID |
test eax, eax |
jz terminate_board |
mov ecx, eax |
mcall 18, 3 ;activate board window |
jmp terminate_board |
;------------------------------------------------------------------------------ |
;* get info on current thread, save pid/tid |
;* look for another process with same name and different pid/tid |
;* if found, close self |
;* else continue normally |
;------------------------------------------------------------------------------ |
CheckUnique: |
.get_thread_info: |
mov ebx, procinfo |
mov ecx, -1 |
mcall 9 |
|
@@: |
cmp [params.stop_daemon_flag], 1 |
jne terminate_board |
cmp dword [eax+12], 1 |
jne terminate_board |
mov ecx, [eax+16] |
mcall 18, 18 ;terminate daemonized board |
jmp terminate_board |
.get_pid: ; check_buffer |
mov [process_count], eax |
mov eax, [ebx+process_information.PID] |
mov [pid_tid], eax |
mov ecx, 2 |
|
.create_STATE_shm_block: |
cmp [params.stop_daemon_flag], 1 |
je terminate_board |
.check_threads: |
cmp ecx, [process_count] |
ja .leave_check |
mov eax, 9 |
mcall |
|
mcall 68,,,STATE_shm_block.size, 0x08 ;create "BOARDAPP:STATE" shared memory block (ro access for other processes) |
test eax, eax |
jz terminate_board |
.check_slot_free: |
cmp dword [ebx+process_information.slot_state], 9 |
je .next_thread |
|
mov edi, eax |
mov dword [edi], 1 |
mov dword [edi+4], STATE_shm_block.version |
mov dword [edi+8], STATE_shm_block.size |
movzx eax, byte [params.daemon_mode] |
mov dword [edi+12], eax |
mcall 9, procinfo, -1 |
mov eax, [ebx+30] ;PID of board |
mov dword [edi+16], eax |
mov dword [edi], 0 |
.check_pid: |
mov eax, [pid_tid] |
cmp [ebx+process_information.PID], eax |
je .next_thread |
|
.ret: |
.get_proc_name: |
lea edi, [ebx+process_information.process_name] |
push ecx |
mov ecx, my_name_size-1 |
|
.lower_case: |
call ToLower |
lea esi, [my_name] |
mov ecx, my_name_size |
call StrCmp |
pop ecx |
cmp eax, 0 |
je .close_program |
|
.next_thread: |
inc ecx |
jmp .check_threads |
|
.close_program: |
; restore and active window of previous thread |
mcall 18, 3 |
mov eax, -1 |
mcall |
|
.leave_check: |
ret |
;------------------------------------------------------------------------------- |
|
terminate_board: |
mcall -1 |
;------------------------------------------------------------------------------- |
;------------------------------------------------------------------------------ |
; DATA |
|
if lang eq ru |
title db "®áª ®â« ¤ª¨ ¨ á®®¡é¥¨© v1.0.1", 0 |
title db '®áª ®â« ¤ª¨ ¨ á®®¡é¥¨©',0 |
else if lang eq it |
title db "Notifiche e informazioni generiche per il debug v1.0.1", 0 |
title db 'Notifiche e informazioni generiche per il debug',0 |
else if lang eq ge |
title db "Allgemeines debug- & nachrichtenboard v1.0.1", 0 |
title db 'Allgemeines debug- & nachrichtenboard',0 |
else |
title db "General debug & message board v1.0.1", 0 |
title db 'General debug & message board',0 |
end if |
|
STATE_shm_block: |
;structure of BOARDAPP:STATE shared memory block: |
;+0 dd mutex (0 - unlocked, block was already written by board, 1 - locked, board is writing into block) |
;+4 dd version of block structure (current is 0) |
;+8 dd size of block (min. 4096 byte for version 0) |
;+12 dd board's state (0 - usual windowed app, 1 - daemonized) |
;+16 dd board's PID |
;next bytes are reserved |
default_filename db '/tmp0/1/boardlog.txt',0 |
krnl_msg db 'K : ' |
duk db 'KernUser' |
my_name db 'board',0 |
my_name_size = $-my_name |
|
.name db "BOARDAPP:STATE", 0 |
.size = 4*1024 |
.version = 0 |
|
default_log_filename db "/tmp0/1/boardlog.txt", 0 |
krnl_msg db "K : " |
k_button_text db "Kernel", 0 |
u_button_text db "User", 0 |
|
proc_fors_term db "Process - forced terminate PID: ", 0 |
proc_fors_term_sp db "Proceso - terminado forzado PID: ", 0 |
unexp_end_of_stack db "Unexpected end of the stack", 0 |
|
log_filename dd default_log_filename |
|
filepos dd 0 |
|
already_on_top db 0 |
|
|
params: |
.log_filename dd 0 |
.log_filename.size dd 0 |
.log_filename_found db 0 |
.daemon_mode db 0 ;0 - normal mode, 1 - daemon mode |
.stop_daemon_flag db 0 |
.logging_mode db 1 ;0 - don't log, 1 - log |
.rewrite_log_flag db 0 |
.options.d db "daemonize", 0 |
.options.d.size = $-.options.d |
.options.s db "stop-daemon", 0 |
.options.s.size = $-.options.s |
.options.n db "no-log", 0 |
.options.n.size = $-.options.n |
.options.r db "rewrite-log", 0 |
.options.r.size = $-.options.r |
.options.f db "fullscreen", 0 |
.options.f.size = $-.options.f |
|
align 4 |
vmode dd 1 |
fullscreen_mode db 0 |
targ dd text2 |
|
I_END: |
|
align 4 |
InfoStructure: |
dd ? ; subfunction number |
dd ? ; position in the file in bytes |
dd ? ; upper part of the position address |
dd ? ; number of bytes to read |
dd ? ; pointer to the buffer to write data |
db ? |
dd ? ; pointer to the filename |
|
targ dd text1 |
|
open_log_in_tinypad: |
dd 7 |
dd 0 |
dd filename |
dd 0 |
dd 0 |
dd 0 |
db "/sys/tinypad", 0 |
db '/sys/tinypad',0 |
|
I_END: |
|
prev_win_x dw ? |
prev_win_y dw ? |
prev_win_w dw ? |
prev_win_h dw ? |
|
f70_structure: |
dd ? ; subfunction number |
dd ? ; |
dd ? ; |
dd ? ; |
dd ? ; |
db ? |
dd ? ; pointer to the filename |
|
window_header_height dd ? |
buffer_length dd ? |
buffer_length rb 3 |
process_count dd ? |
krnl_cnt dd ? |
pid_tid dd ? |
filepos dd ? |
xstart dd ? |
ystart dd ? |
|
hl_line_count rd 1 |
|
sc system_colors |
|
rd 2 |
text1 rb STRING_LENGTH*MAX_STRINGS ;'User' messages |
text1 rb 80*(MAXSTRINGS+1) |
tmp1 dd ? |
|
rd 2 |
text2 rb STRING_LENGTH*MAX_STRINGS ;'Kernel' messages |
text2 rb 80*(MAXSTRINGS+1) |
tmp2 dd ? |
|
tmp rb 256 |
PARAMS_STRING rb 256 |
filename rb 256 |
procinfo rb 1024 |
file_info rb 40 |
|
align 4 |
rb 512 |
STACK_TOP: |
|
MEM_END: |
stackbuf rb 2000h |
mem: |