📄 sol_system.inc
字号:
mov ecx,[memory_end]
sub ecx,edi
cmp ecx,4000h
jbe buffer_for_variable_ok
mov ecx,4000h
buffer_for_variable_ok:
;push ecx
;push edi
;push esi
;call [GetEnvironmentVariable]
; there are NO environment variables in SOL
mov eax,0
add edi,eax
cmp edi,[memory_end]
jae out_of_memory
ret
open:
;push 0
;push 0
;push OPEN_EXISTING
;push 0
;push FILE_SHARE_READ
;push GENERIC_READ
;push edx
;call [CreateFile]
;cmp eax,-1
;je file_error
;-------------------------------
; works ok in SOL ;)
;-------------------------------
invoke API_File_Open, edx
cmp eax,-1
je file_error
mov ebx,eax
clc
ret
file_error:
stc
ret
create:
;push 0
;push 0
;push CREATE_ALWAYS
;push 0
;push FILE_SHARE_READ
;push GENERIC_WRITE
;push edx
;call [CreateFile]
;cmp eax,-1
;je file_error
;mov ebx,eax
;clc
;ret
;push edx
;Call [API_File_Open]
;cmp eax,-1
;je file_error
mov eax,[fasm_write_fhandle]
mov ebx,eax
clc
ret
write:
;push 0 ; overlaped
;push bytes_count ; bytes_wr_ptr
;push ecx ; nr_of_bytes to write
;push edx ; buffer_ptr
;push ebx ; file_handle
;call [WriteFile]
;or eax,eax
;jz file_error
;-------------------------------------------
; write is simulated in a memory buffer
;-------------------------------------------
pushad
mov esi,edx
mov edi,[fasm_write_mem_ptr]
add edi,[fasm_write_fpos]
add [fasm_write_fpos],ecx
mov [bytes_count],ecx
rep movsb
popad
clc
ret
read:
;mov ebp,ecx
;push 0 ; lpoverlapped
;push bytes_count ; bytes read ptr
;push ecx ; bytes_to_read
;push edx ; lpBuff
;push ebx ; hFile
;call [ReadFile]
;or eax,eax
;jz file_error
;cmp ebp,[bytes_count]
;jne file_error
; push 0 ; callback_ptr
; push 0 ; read_flags
; push edx ; dest_buff_ptr
; push ecx ; read_size
; push ebx ; file_handle
; Call [API_File_Read]
;-------------------------------------------
; surprise:
; this read is really performed in SOL ;)
;-------------------------------------------
invoke API_File_Read, ebx,ecx,edx,0,0
cmp eax,-1
je file_error
; no error
clc
ret
close:
; push ebx
; call [CloseHandle]
cmp ebx,[fasm_write_fhandle]
jz .close_done
;-------------------------------------------
; surprise: this works in SOL ;)
;-------------------------------------------
invoke API_File_Close,ebx
.close_done:
mov eax,1
ret
lseek:
movzx eax,al
; push eax ; move method: 2 = FILE_END
; push 0 ; distance to move high
; push edx ; distance to move low
; push ebx ; file_handle
; call [SetFilePointer]
;--------------------------------------------------------------------
; FASM does use lseek from file end in order to get file size ;)
;--------------------------------------------------------------------
cmp eax,2 ; 2 = FILE_END in windows
jz .is_file_end
; normal seek is dummy
; because SOL does not yet have a lseek API :D
mov eax,edx
ret
.is_file_end:
cmp edx,0
jz .is_get_fsize
; WARN: another unhandled situation
xor eax,eax
ret
.is_get_fsize:
invoke API_File_Get_Size,ebx
ret
;display_string:
; push esi
; push STD_OUTPUT_HANDLE
; call [GetStdHandle]
; mov ebp,eax
; pop esi
; mov edi,esi
; or ecx,-1
; xor al,al
; repne scasb
; neg ecx
; sub ecx,2
; push 0
; push bytes_count
; push ecx
; push esi
; push ebp
; call [WriteFile]
; ret
display_string:
push edi
push ecx
mov edi,esi
xor ecx,ecx
.len_loop:
mov al,[edi]
test al,al
jz .wr_string
inc ecx
inc edi
jmp .len_loop
.wr_string:
test ecx,ecx
jz .done
js .done
call write_stdout
.done:
pop ecx
pop edi
ret
display_string2:
push 0 ; no_cli
push esi ; string_ptr
push 0 ; wnd_handle
Call [API_Debug_Out_String]
ret
display_character:
push ebx
push edi
mov [character],dl
; push 0 ; no_cli
; push sol_character ; string_ptr
; push 0 ; wnd_handle
; Call [API_Debug_Out_String]
mov edi,[fasm_stdout_mem_ptr]
add edi,[fasm_stdout_size]
inc [fasm_stdout_size]
mov [edi],dl
; push STD_OUTPUT_HANDLE
; call [GetStdHandle]
; mov ebx,eax
; push 0
; push bytes_count
; push 1
; push character
; push ebx
; call [WriteFile]
pop edi
pop ebx
ret
display_number:
push ebx
mov ecx,1000000000
xor edx,edx
xor bl,bl
display_loop:
div ecx
push edx
cmp ecx,1
je display_digit
or bl,bl
jnz display_digit
or al,al
jz digit_ok
not bl
display_digit:
mov dl,al
add dl,30h
push ecx
call display_character
pop ecx
digit_ok:
mov eax,ecx
xor edx,edx
mov ecx,10
div ecx
mov ecx,eax
pop eax
or ecx,ecx
jnz display_loop
pop ebx
ret
display_user_messages:
mov [displayed_count],0
call flush_display_buffer
cmp [displayed_count],1
jb line_break_ok
je make_line_break
mov ax,word [last_displayed]
cmp ax,0A0Dh
je line_break_ok
cmp ax,0D0Ah
je line_break_ok
make_line_break:
mov word [buffer],0A0Dh
; push STD_OUTPUT_HANDLE
; call [GetStdHandle]
; push 0
; push bytes_count
; push 2
; push buffer
; push eax
; call [WriteFile]
push edi
mov edi,[fasm_stdout_mem_ptr]
add edi,[fasm_stdout_size]
add [fasm_stdout_size],2
mov word [edi],0A0Dh
pop edi
line_break_ok:
ret
display_block:
add [displayed_count],ecx
cmp ecx,1
ja take_last_two_characters
jb block_displayed
mov al,[last_displayed+1]
mov ah,[esi]
mov word [last_displayed],ax
jmp block_ok
take_last_two_characters:
mov ax,[esi+ecx-2]
mov word [last_displayed],ax
block_ok:
push ecx
; push STD_OUTPUT_HANDLE
; call [GetStdHandle]
pop ecx
; push 0
; push bytes_count
; push ecx
; push esi
; push eax
; call [WriteFile]
;----------------------------------------------------------
; does not work corectly because of lseek issues on SOL
;----------------------------------------------------------
;call write_stdout
block_displayed:
ret
fatal_error:
mov esi,error_prefix
call display_string
pop esi
call display_string
mov esi,error_suffix
call display_string
mov al,0FFh
jmp exit_program
assembler_error:
call display_user_messages
push dword 0
mov ebx,[current_line]
get_error_lines:
push ebx
test byte [ebx+7],80h
jz display_error_line
mov edx,ebx
find_definition_origin:
mov edx,[edx+12]
test byte [edx+7],80h
jnz find_definition_origin
push edx
mov ebx,[ebx+8]
jmp get_error_lines
display_error_line:
mov esi,[ebx]
call display_string
mov esi,line_number_start
call display_string
mov eax,[ebx+4]
and eax,7FFFFFFFh
call display_number
mov dl,']'
call display_character
pop esi
cmp ebx,esi
je line_number_ok
mov dl,20h
call display_character
push esi
mov esi,[esi]
movzx ecx,byte [esi]
inc esi
call display_block
mov esi,line_number_start
call display_string
pop esi
mov eax,[esi+4]
and eax,7FFFFFFFh
call display_number
mov dl,']'
call display_character
line_number_ok:
mov esi,line_data_start
call display_string
mov esi,ebx
mov edx,[esi]
call open
mov al,2
xor edx,edx
call lseek
mov edx,[esi+8]
sub eax,edx
push eax
xor al,al
call lseek
mov ecx,[esp]
mov edx,[additional_memory]
lea eax,[edx+ecx]
cmp eax,[additional_memory_end]
ja out_of_memory
call read
call close
pop ecx
mov esi,[additional_memory]
get_line_data:
mov al,[esi]
cmp al,0Ah
je display_line_data
cmp al,0Dh
je display_line_data
cmp al,1Ah
je display_line_data
or al,al
jz display_line_data
inc esi
loop get_line_data
display_line_data:
mov ecx,esi
mov esi,[additional_memory]
sub ecx,esi
call display_block
mov esi,cr_lf
call display_string
pop ebx
or ebx,ebx
jnz display_error_line
mov esi,error_prefix
call display_string
pop esi
call display_string
mov esi,error_suffix
call display_string
mov al,2
jmp exit_program
make_timestamp:
; push buffer
; call [GetSystemTime]
; movzx ecx,word [buffer]
; mov eax,ecx
; sub eax,1970
; mov ebx,365
; mul ebx
; mov ebp,eax
; mov eax,ecx
; sub eax,1969
; shr eax,2
; add ebp,eax
; mov eax,ecx
; sub eax,1901
; mov ebx,100
; div ebx
; sub ebp,eax
; mov eax,ecx
; xor edx,edx
; sub eax,1601
; mov ebx,400
; div ebx
; add ebp,eax
; movzx ecx,word [buffer+2]
; mov eax,ecx
; dec eax
; mov ebx,30
; mul ebx
; add ebp,eax
; cmp ecx,8
; jbe months_correction
; mov eax,ecx
; sub eax,7
; shr eax,1
; add ebp,eax
; mov ecx,8
; months_correction:
; mov eax,ecx
; shr eax,1
; add ebp,eax
; cmp ecx,2
; jbe day_correction_ok
; sub ebp,2
; movzx ecx,word [buffer]
; test ecx,11b
; jnz day_correction_ok
; xor edx,edx
; mov eax,ecx
; mov ebx,100
; div ebx
; or edx,edx
; jnz day_correction
; mov eax,ecx
; mov ebx,400
; div ebx
; or edx,edx
; jnz day_correction_ok
; day_correction:
; inc ebp
; day_correction_ok:
; movzx eax,word [buffer+6]
; dec eax
; add eax,ebp
; mov ebx,24
; mul ebx
; movzx ecx,word [buffer+8]
; add eax,ecx
; mov ebx,60
; mul ebx
; movzx ecx,word [buffer+10]
; add eax,ecx
; mov ebx,60
; mul ebx
; movzx ecx,word [buffer+12]
; add eax,ecx
;
mov eax,111234567
ret
character db ?
bytes_count dd ?
displayed_count dd ?
last_displayed rb 2
error_prefix db 'error: ',0
error_suffix db '.'
cr_lf db 0Dh,0Ah,0
line_number_start db ' [',0
line_data_start db ':',0Dh,0Ah,0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -