Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 5098 → Rev 7133

/programs/develop/libraries/console/examples/Tupfile.lua
1,2 → 1,3
if tup.getconfig("NO_FASM") ~= "" then return end
tup.foreach_rule("*.asm", "fasm %f %o " .. tup.getconfig("KPACK_CMD"), "%B")
ROOT = "../../../../.."
tup.foreach_rule("*.asm", "fasm %f %o " .. tup.getconfig("PESTRIP_CMD") .. tup.getconfig("KPACK_CMD"), "%B")
/programs/develop/libraries/console/examples/test_getch.asm
1,42 → 1,10
 
format PE console 0.8
include 'proc32.inc'
include '../../../../import.inc'
 
DLL_ENTRY equ 1
DLL_EXIT equ -1
REQ_DLL_VER equ 3
 
use32
db 'MENUET01'
dd 1
dd start
dd i_end
dd mem
dd mem
dd 0
dd 0
 
start:
stdcall load_dll_and_import, dllname, imports
test eax, eax
jz exit
invoke con_set_title, caption
 
; check version
cmp word [dll_ver], REQ_DLL_VER
jb exit
cmp word [dll_ver+2], REQ_DLL_VER
ja exit
push DLL_ENTRY
call [dll_start]
 
; yes! Now do some work (getch() demo in this case).
 
push caption
push -1
push -1
push -1
push -1
call [con_init]
 
; C-equivalent of the following code:
; con_printf(start_string);
; int c;
78,91 → 46,20
push 1
call [con_exit]
exit:
or eax, -1
int 0x40
 
proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
pushad
; load DLL
push 68
pop eax
push 19
pop ebx
mov ecx, [_dllname]
int 0x40
test eax, eax
jz import_fail
 
; initialize import
mov edi, eax
mov esi, [_imports]
import_loop:
lodsd
test eax, eax
jz import_done
mov edx, edi
import_find:
mov ebx, [edx]
test ebx, ebx
jz import_not_found
push eax
@@:
mov cl, [eax]
cmp cl, [ebx]
jnz import_find_next
test cl, cl
jz import_found
inc eax
inc ebx
jmp @b
import_find_next:
pop eax
add edx, 8
jmp import_find
import_found:
pop eax
mov eax, [edx+4]
mov [esi-4], eax
jmp import_loop
import_not_found:
import_fail:
popad
xor eax, eax
ret
import_done:
popad
xor eax, eax
inc eax
ret
endp
 
align 4
data import
library console, 'console.dll'
import console, \
con_set_title, 'con_set_title', \
con_printf, 'con_printf', \
con_exit, 'con_exit', \
con_getch, 'con_getch'
end data
 
imports:
dll_start dd szStart
dll_ver dd szVersion
con_init dd szcon_init
con_printf dd szcon_printf
con_exit dd szcon_exit
con_getch dd szcon_getch
dd 0
 
szStart db 'START',0
szVersion db 'version',0
szcon_init db 'con_init',0
szcon_printf db 'con_printf',0
szcon_exit db 'con_exit',0
szcon_getch db 'con_getch',0
 
dllname db '/sys/lib/console.obj',0
 
caption db 'Console test - getch()',0
start_string db 'Press any key to see its code, or Esc to exit',10,0
string_normal db 'normal character with code %d=0x%02X',10,0
string_extended db 'extended character with code %d=0x%02X',10,0
 
i_end:
 
align 4
rb 2048 ; stack
mem:
/programs/develop/libraries/console/examples/test_gets.asm
1,42 → 1,10
 
format PE console 0.8
include 'proc32.inc'
include '../../../../import.inc'
 
DLL_ENTRY equ 1
DLL_EXIT equ -1
REQ_DLL_VER equ 3
 
use32
db 'MENUET01'
dd 1
dd start
dd i_end
dd mem
dd mem
dd 0
dd 0
 
start:
stdcall load_dll_and_import, dllname, imports
test eax, eax
jz exit
invoke con_set_title, caption
 
; check version
cmp word [dll_ver], REQ_DLL_VER
jb exit
cmp word [dll_ver+2], REQ_DLL_VER
ja exit
push DLL_ENTRY
call [dll_start]
 
; yes! Now do some work (gets() demo in this case).
 
push caption
push -1
push -1
push -1
push -1
call [con_init]
 
; C-equivalent of the following code:
; for (;;)
; {
65,92 → 33,22
push 1
call [con_exit]
exit:
or eax, -1
int 0x40
 
proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
pushad
; load DLL
push 68
pop eax
push 19
pop ebx
mov ecx, [_dllname]
int 0x40
test eax, eax
jz import_fail
 
; initialize import
mov edi, eax
mov esi, [_imports]
import_loop:
lodsd
test eax, eax
jz import_done
mov edx, edi
import_find:
mov ebx, [edx]
test ebx, ebx
jz import_not_found
push eax
@@:
mov cl, [eax]
cmp cl, [ebx]
jnz import_find_next
test cl, cl
jz import_found
inc eax
inc ebx
jmp @b
import_find_next:
pop eax
add edx, 8
jmp import_find
import_found:
pop eax
mov eax, [edx+4]
mov [esi-4], eax
jmp import_loop
import_not_found:
import_fail:
popad
xor eax, eax
ret
import_done:
popad
xor eax, eax
inc eax
ret
endp
 
 
align 4
data import
library console, 'console.dll'
import console, \
con_set_title, 'con_set_title', \
con_write_asciiz, 'con_write_asciiz', \
con_exit, 'con_exit', \
con_gets, 'con_gets'
end data
 
imports:
dll_start dd szStart
dll_ver dd szVersion
con_init dd szcon_init
con_write_asciiz dd szcon_write_asciiz
con_exit dd szcon_exit
con_gets dd szcon_gets
dd 0
 
szStart db 'START',0
szVersion db 'version',0
szcon_init db 'con_init',0
szcon_write_asciiz db 'con_write_asciiz',0
szcon_exit db 'con_exit',0
szcon_gets db 'con_gets',0
 
dllname db '/sys/lib/console.obj',0
 
caption db 'Console test - gets()',0
str1 db 'Enter string (empty for exit): ',0
str2 db 'You entered: ',0
 
i_end:
 
s rb 256
 
align 4
rb 2048 ; stack
mem:
/programs/develop/libraries/console/examples/test_gets2.asm
1,35 → 1,8
 
format PE GUI 0.8 ; initialize console ourselves
include 'proc32.inc'
include '../../../../import.inc'
 
DLL_ENTRY equ 1
DLL_EXIT equ -1
REQ_DLL_VER equ 4
 
use32
db 'MENUET01'
dd 1
dd start
dd i_end
dd mem
dd mem
dd 0
dd 0
 
start:
stdcall load_dll_and_import, dllname, imports
test eax, eax
jz exit
 
; check version
cmp word [dll_ver], REQ_DLL_VER
jb exit
cmp word [dll_ver+2], REQ_DLL_VER
ja exit
push DLL_ENTRY
call [dll_start]
 
; yes! Now do some work (gets2() demo in this case).
 
push caption
push 25
push 80
66,8 → 39,8
push 1
call [con_exit]
exit:
or eax, -1
int 0x40
xor eax, eax
ret
 
proc mycallback stdcall, keycode:dword, pstr:dword, pn:dword, ppos:dword
mov eax, [keycode]
160,81 → 133,17
ret
endp
 
proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
pushad
; load DLL
push 68
pop eax
push 19
pop ebx
mov ecx, [_dllname]
int 0x40
test eax, eax
jz import_fail
 
; initialize import
mov edi, eax
mov esi, [_imports]
import_loop:
lodsd
test eax, eax
jz import_done
mov edx, edi
import_find:
mov ebx, [edx]
test ebx, ebx
jz import_not_found
push eax
@@:
mov cl, [eax]
cmp cl, [ebx]
jnz import_find_next
test cl, cl
jz import_found
inc eax
inc ebx
jmp @b
import_find_next:
pop eax
add edx, 8
jmp import_find
import_found:
pop eax
mov eax, [edx+4]
mov [esi-4], eax
jmp import_loop
import_not_found:
import_fail:
popad
xor eax, eax
ret
import_done:
popad
xor eax, eax
inc eax
ret
endp
 
align 4
data import
library console, 'console.dll'
import console, \
con_init, 'con_init', \
con_write_asciiz, 'con_write_asciiz', \
con_exit, 'con_exit', \
con_gets2, 'con_gets2'
end data
 
imports:
dll_start dd szStart
dll_ver dd szVersion
con_init dd szcon_init
con_write_asciiz dd szcon_write_asciiz
con_exit dd szcon_exit
con_gets2 dd szcon_gets2
dd 0
 
szStart db 'START',0
szVersion db 'version',0
szcon_init db 'con_init',0
szcon_write_asciiz db 'con_write_asciiz',0
szcon_exit db 'con_exit',0
szcon_gets2 db 'con_gets2',0
 
dllname db '/sys/lib/console.obj',0
 
caption db 'Console test - gets2()',0
str1 db 'Enter string (empty for exit): ',0
str2 db 'You entered: ',0
246,10 → 155,4
str6 db 'next line in the history'
str6.len = $ - str6
 
i_end:
 
s rb 256
 
align 4
rb 2048 ; stack
mem:
/programs/develop/libraries/console/examples/testcon.asm
1,58 → 1,20
use32
db 'MENUET01'
dd 1
dd start
dd i_end
dd mem
dd mem
dd 0
dd 0
format PE console 0.8
include '../../../../import.inc'
 
; useful includes
include '../../../../macros.inc'
purge mov,add,sub
include '../../../../proc32.inc'
include '../../../../dll.inc'
 
start:
; First 3 steps are intended to load/init console DLL
; and are identical for all console programs
 
; load DLL
stdcall dll.Load, @IMPORT
test eax, eax
jnz exit
 
; yes! Now do some work (say helloworld in this case).
push caption
push -1
push -1
push -1
push -1
call [con_init]
push aHelloWorld
call [con_write_asciiz]
push 0
call [con_exit]
exit:
or eax, -1
int 0x40
xor eax, eax
ret
 
caption db 'Console test',0
aHelloWorld db 'Hello, World!',10,0
 
align 4
@IMPORT:
library console, 'console.obj'
data import
library console, 'console.dll'
import console, \
con_start, 'START', \
con_init, 'con_init', \
con_write_asciiz, 'con_write_asciiz', \
con_exit, 'con_exit', \
con_gets, 'con_gets'
i_end:
 
 
align 4
rb 2048 ; stack
mem:
con_exit, 'con_exit'
end data
/programs/develop/libraries/console/examples/testcon2_eng.asm
1,41 → 1,9
 
format PE console 0.8
include 'proc32.inc'
include '../../../../import.inc'
 
DLL_ENTRY equ 1
DLL_EXIT equ -1
REQ_DLL_VER equ 2
 
use32
db 'MENUET01'
dd 1
dd start
dd i_end
dd mem
dd mem
dd 0
dd 0
 
start:
stdcall load_dll_and_import, dllname, imports
test eax, eax
jz exit
 
; check version
cmp word [dll_ver], REQ_DLL_VER
jb exit
cmp word [dll_ver+2], REQ_DLL_VER
ja exit
push DLL_ENTRY
call [dll_start]
 
; yes! Now do some work (show color strings in this case).
 
push caption
push -1
push -1
push -1
push -1
call [con_init]
invoke con_set_title, caption
; C-equivalent of the following code:
; for (ebx=0;ebx<0x100;ebx++)
; {
67,86 → 35,20
push 0
call [con_exit]
exit:
or eax, -1
int 0x40
 
proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
pushad
; load DLL
push 68
pop eax
push 19
pop ebx
mov ecx, [_dllname]
int 0x40
test eax, eax
jz import_fail
 
; initialize import
mov edi, eax
mov esi, [_imports]
import_loop:
lodsd
test eax, eax
jz import_done
mov edx, edi
import_find:
mov ebx, [edx]
test ebx, ebx
jz import_not_found
push eax
@@:
mov cl, [eax]
cmp cl, [ebx]
jnz import_find_next
test cl, cl
jz import_found
inc eax
inc ebx
jmp @b
import_find_next:
pop eax
add edx, 8
jmp import_find
import_found:
pop eax
mov eax, [edx+4]
mov [esi-4], eax
jmp import_loop
import_not_found:
import_fail:
popad
xor eax, eax
ret
import_done:
popad
xor eax, eax
inc eax
ret
endp
 
align 4
data import
library console, 'console.dll'
import console, \
con_set_title, 'con_set_title', \
con_write_asciiz, 'con_write_asciiz', \
con_printf, 'con_printf', \
con_set_flags, 'con_set_flags', \
con_exit, 'con_exit'
end data
 
imports:
dll_start dd szStart
dll_ver dd szVersion
con_init dd szcon_init
con_write_asciiz dd szcon_write_asciiz
con_printf dd szcon_printf
con_set_flags dd szcon_set_flags
con_exit dd szcon_exit
dd 0
 
szStart db 'START',0
szVersion db 'version',0
szcon_init db 'con_init',0
szcon_write_asciiz db 'con_write_asciiz',0
szcon_printf db 'con_printf',0
szcon_set_flags db 'con_set_flags',0
szcon_exit db 'con_exit',0
 
dllname db '/sys/lib/console.obj',0
 
caption db 'Console test - colors',0
t1 db 'Color 0x%02X: ',0
text db 'This is sample text.',10,0
153,9 → 55,3
text2 db 27,'[7mAnd this is an example of '
db 27,'[1;36;41mEsc'
db 27,'[7m-sequences.',10,0
 
i_end:
 
align 4
rb 2048 ; stack
mem:
/programs/develop/libraries/console/examples/testcon2_rus.asm
1,41 → 1,9
 
format PE console 0.8
include 'proc32.inc'
include '../../../../import.inc'
 
DLL_ENTRY equ 1
DLL_EXIT equ -1
REQ_DLL_VER equ 2
 
use32
db 'MENUET01'
dd 1
dd start
dd i_end
dd mem
dd mem
dd 0
dd 0
 
start:
stdcall load_dll_and_import, dllname, imports
test eax, eax
jz exit
 
; check version
cmp word [dll_ver], REQ_DLL_VER
jb exit
cmp word [dll_ver+2], REQ_DLL_VER
ja exit
push DLL_ENTRY
call [dll_start]
 
; yes! Now do some work (show color strings in this case).
 
push caption
push -1
push -1
push -1
push -1
call [con_init]
invoke con_set_title, caption
; C-equivalent of the following code:
; for (ebx=0;ebx<0x100;ebx++)
; {
67,86 → 35,20
push 0
call [con_exit]
exit:
or eax, -1
int 0x40
 
proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
pushad
; load DLL
push 68
pop eax
push 19
pop ebx
mov ecx, [_dllname]
int 0x40
test eax, eax
jz import_fail
 
; initialize import
mov edi, eax
mov esi, [_imports]
import_loop:
lodsd
test eax, eax
jz import_done
mov edx, edi
import_find:
mov ebx, [edx]
test ebx, ebx
jz import_not_found
push eax
@@:
mov cl, [eax]
cmp cl, [ebx]
jnz import_find_next
test cl, cl
jz import_found
inc eax
inc ebx
jmp @b
import_find_next:
pop eax
add edx, 8
jmp import_find
import_found:
pop eax
mov eax, [edx+4]
mov [esi-4], eax
jmp import_loop
import_not_found:
import_fail:
popad
xor eax, eax
ret
import_done:
popad
xor eax, eax
inc eax
ret
endp
 
align 4
data import
library console, 'console.dll'
import console, \
con_set_title, 'con_set_title', \
con_write_asciiz, 'con_write_asciiz', \
con_printf, 'con_printf', \
con_set_flags, 'con_set_flags', \
con_exit, 'con_exit'
end data
 
imports:
dll_start dd szStart
dll_ver dd szVersion
con_init dd szcon_init
con_write_asciiz dd szcon_write_asciiz
con_printf dd szcon_printf
con_set_flags dd szcon_set_flags
con_exit dd szcon_exit
dd 0
 
szStart db 'START',0
szVersion db 'version',0
szcon_init db 'con_init',0
szcon_write_asciiz db 'con_write_asciiz',0
szcon_printf db 'con_printf',0
szcon_set_flags db 'con_set_flags',0
szcon_exit db 'con_exit',0
 
dllname db '/sys/lib/console.obj',0
 
caption db 'Console test - colors',0
t1 db '–¢¥â 0x%02X: ',0
text db '‚®â ¯à¨¬¥à ⥪áâ .',10,0
153,9 → 55,3
text2 db 27,'[7m€ íâ® ¯à¨¬¥à ¨á¯®«ì§®¢ ­¨ï '
db 27,'[1;36;41mEsc'
db 27,'[7m-¯®á«¥¤®¢ â¥«ì­®á⥩.',10,0
 
i_end:
 
align 4
rb 2048 ; stack
mem: