console library: upload sources

git-svn-id: svn://kolibrios.org@836 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Evgeny Grechnikov (Diamond) 2008-07-27 14:25:33 +00:00
parent a37530d3dc
commit fca4378433
13 changed files with 3344 additions and 0 deletions

View File

@ -0,0 +1,2 @@
fasm console.asm ..\console.obj
e:\zhenya\program\menuet\kpack\kpack.exe ..\console.obj

View File

@ -0,0 +1,45 @@
; ‚ᯮ¬®£ â¥«ì­ë© ä ©« ¤«ï console.inc - ®¯¨á ­¨¥ scrollbar
; ‚¥à⨪ «ì­ ï ¯à®ªàã⪠
virtual at 0
file 'conscrlv.bmp', 36h
; sanity check
load a1 word from 0
load a2 dword from 0xE
if (a1 <> 'BM') | (a2 <> 0x28)
error 'conscrlv.bmp: not BMP file!'
end if
load con.vscroll_width dword from 0x12
load con.vscroll_height dword from 0x16
load a1 dword from 0x1A
if a1 <> 0x180001
error 'conscrlv.bmp: must be 24-bit bitmap!'
end if
end virtual
con.vscroll_btn_height = 21
con.vscroll_bgr_height = 2
con.vscroll_bar_height1 = 2
con.vscroll_bar_height2 = 1
con.vscroll_bar_height3 = 2
if con.vscroll_btn_height*4 + con.vscroll_bgr_height*2 \
+ con.vscroll_bar_height1 + con.vscroll_bar_height2 + con.vscroll_bar_height3 \
<> con.vscroll_height
error 'conscrlv.bmp: invalid dimensions!'
end if
; ‡ £à㦠¥¬ ¤ ­­ë¥ BMP, ­  室㠯८¡à §ãï ¨å ¢ ¤ ­­ë¥ ¤«ï 7-© ä㭪樨
con.vscroll:
repeat con.vscroll_height
file 'conscrlv.bmp':36h + ((con.vscroll_width*3+3) and not 3)*(con.vscroll_height - %),\
con.vscroll_width*3
end repeat
con.vscroll_btn1 = con.vscroll
con.vscroll_btn2 = con.vscroll + con.vscroll_btn_height*con.vscroll_width*3
con.vscroll_btn3 = con.vscroll + 2*con.vscroll_btn_height*con.vscroll_width*3
con.vscroll_btn4 = con.vscroll + 3*con.vscroll_btn_height*con.vscroll_width*3
con.vscroll_bgr1 = con.vscroll + 4*con.vscroll_btn_height*con.vscroll_width*3
con.vscroll_bgr2 = con.vscroll_bgr1 + con.vscroll_bgr_height*con.vscroll_width*3
con.vscroll_bar1 = con.vscroll_bgr2 + con.vscroll_bgr_height*con.vscroll_width*3
con.vscroll_bar2 = con.vscroll_bar1 + con.vscroll_bar_height1*con.vscroll_width*3
con.vscroll_bar3 = con.vscroll_bar2 + con.vscroll_bar_height2*con.vscroll_width*3

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,114 @@
console.obj экспортирует следующие функции:
typedef unsigned long dword; /* 32-битное беззнаковое целое */
typedef unsigned short word; /* 16-битное беззнаковое целое */
void __stdcall con_init(dword wnd_width, dword wnd_height,
dword scr_width, dword scr_height, const char* title);
Инициализация консоли. Вызывается один раз в начале программы.
wnd_width, wnd_height - высота и ширина (в символах) видимой в окне консоли
области;
scr_width, scr_height - высота и ширина (в символах) всей консоли;
любые из первых 4 параметров могут быть установлены в -1 (=0xFFFFFFFF)
- использовать значения по умолчанию;
title - заголовок окна консоли.
void __stdcall con_exit(bool bCloseWindow);
Вызывается при завершении программы. Если (байтовый) параметр bCloseWindow
нулевой, то окно консоли остаётся на экране до того момента, как пользователь
пожелает закрыть его, при этом к заголовку добавляется строка " [Finished]".
void __stdcall con_set_title(const char* title);
Устанавливает новый заголовок окна консоли.
void __stdcall con_write_asciiz(const char* string);
Выводит ASCIIZ-строку в консоль в текущую позицию, продвигает текущую позицию.
void __stdcall con_write_string(const char* string, dword length);
Аналогично con_write_asciiz, но выводит ровно length символов.
int __cdecl con_printf(const char* format, ...)
Стандартная printf из ANSI C.
dword __stdcall con_get_flags(void);
Получает значение флагов вывода.
dword __stdcall con_set_flags(dword new_flags);
Устанавливает значение флагов вывода. Возвращает старое значение.
Флаги (битовая маска):
/* цвет текста */
#define CON_COLOR_BLUE 1
#define CON_COLOR_GREEN 2
#define CON_COLOR_RED 4
#define CON_COLOR_BRIGHT 8
/* цвет фона */
#define CON_BGR_BLUE 0x10
#define CON_BGR_GREEN 0x20
#define CON_BGR_RED 0x40
#define CON_BGR_BRIGHT 0x80
/* управление выводом */
#define CON_IGNORE_SPECIALS 0x100
/* Если флаг сброшен, функция интерпретирует специальные символы:
10 ('\n') - перевод в начало следующей строки
13 ('\r') - перевод в начало текущей строки
8 ('\b') - забой (на символ назад)
9 ('\t') - табуляция
27 ('\033'='\x1B') - начало Esc-последовательности;
иначе выводит их как обычные символы. */
/* Поддерживаемые Esc-последовательности:
Esc[<number1>;<number2>;<number3>m - выбор атрибутов символов:
можно указывать один, два или три кода в любом порядке;
0 = нормальное изображение (белые символы на чёрном фоне)
1 = выделение яркостью
5 = яркий фон
7 = реверсное изображение (чёрные символы на белом фоне)
30 = чёрные символы
31 = красные символы
32 = зелёные символы
33 = коричневые символы
34 = синие символы
35 = фиолетовые символы
36 = бирюзовые символы
37 = белые символы
40 = чёрный фон
41 = красный фон
42 = зелёный фон
43 = коричневый фон
44 = синий фон
45 = фиолетовый фон
46 = бирюзовый фон
47 = белый фон
*/
Значение по умолчанию для флагов = 7.
int __stdcall con_get_font_height(void);
Возвращает значение высоты шрифта.
int __stdcall con_get_cursor_height(void);
Получает значение высоты курсора.
int __stdcall con_set_cursor_height(int new_height);
Устанавливает значение высоты курсора. Возвращает старое значение.
Попытка установить значение вне корректного интервала (от 0 до font_height-1)
игнорируется.
Курсор высоты 0 не отображается на экране.
Значение высоты по умолчанию - 15% от высоты шрифта.
int __stdcall con_getch(void);
Считывает один символ с клавиатуры.
Для обычных символов возвращается ASCII-код. Для расширенных символов
(например, Fx и стрелочек) первый вызов функции возвращает 0,
а повторный вызов возвращает расширенный код (подобно DOS-функциям ввода).
word __stdcall con_getch2(void);
Считывает один символ с клавиатуры. Младший байт содержит ASCII-код клавиши
(0 для расширенных символов), старший - расширенный код
(подобно BIOS-функциям ввода).
int __stdcall con_kbhit(void);
Возвращает 1, если какая-то клавиша была нажата, 0 иначе. Для считывания
нажатой клавиши предназначены функции con_getch и con_getch2.
void __stdcall con_gets(char* str, int n);
Считывает строку с клавиатуры. Ввод прерывается при поступлении символа
новой строки, а также по прочтении n-1 символа (в зависимости от того, что
произойдёт раньше). В первом случае символ новой строки также записывается в
str. Считанная строка дополняется нулевым символом.

View File

@ -0,0 +1,268 @@
; Macroinstructions for defining and calling procedures
macro stdcall proc,[arg] ; directly call STDCALL procedure
{ common
if ~ arg eq
reverse
pushd arg
common
end if
call proc }
macro invoke proc,[arg] ; indirectly call STDCALL procedure
{ common
if ~ arg eq
reverse
pushd arg
common
end if
call [proc] }
macro ccall proc,[arg] ; directly call CDECL procedure
{ common
size@ccall = 0
if ~ arg eq
reverse
pushd arg
size@ccall = size@ccall+4
common
end if
call proc
if size@ccall
add esp,size@ccall
end if }
macro cinvoke proc,[arg] ; indirectly call CDECL procedure
{ common
size@ccall = 0
if ~ arg eq
reverse
pushd arg
size@ccall = size@ccall+4
common
end if
call [proc]
if size@ccall
add esp,size@ccall
end if }
macro proc [args] ; define procedure
{ common
match name params, args>
\{ define@proc name,<params \} }
prologue@proc equ prologuedef
macro prologuedef procname,flag,parmbytes,localbytes,reglist
{ if parmbytes | localbytes
push ebp
mov ebp,esp
if localbytes
sub esp,localbytes
end if
end if
irps reg, reglist \{ push reg \} }
epilogue@proc equ epiloguedef
macro epiloguedef procname,flag,parmbytes,localbytes,reglist
{ irps reg, reglist \{ reverse pop reg \}
if parmbytes | localbytes
leave
end if
if flag and 10000b
retn
else
retn parmbytes
end if }
macro define@proc name,statement
{ local params,flag,regs,parmbytes,localbytes,current
if used name
name:
match =stdcall args, statement \{ params equ args
flag = 11b \}
match =stdcall, statement \{ params equ
flag = 11b \}
match =c args, statement \{ params equ args
flag = 10001b \}
match =c, statement \{ params equ
flag = 10001b \}
match =params, params \{ params equ statement
flag = 0 \}
virtual at ebp+8
match =uses reglist=,args, params \{ regs equ reglist
params equ args \}
match =regs =uses reglist, regs params \{ regs equ reglist
params equ \}
match =regs, regs \{ regs equ \}
match =,args, params \{ defargs@proc args \}
match =args@proc args, args@proc params \{ defargs@proc args \}
parmbytes = $ - (ebp+8)
end virtual
name # % = parmbytes/4
all@vars equ
current = 0
match prologue:reglist, prologue@proc:<regs> \{ prologue name,flag,parmbytes,localbytes,reglist \}
macro locals
\{ virtual at ebp-localbytes+current
macro label . \\{ deflocal@proc .,:, \\}
struc db [val] \\{ \common deflocal@proc .,db,val \\}
struc dw [val] \\{ \common deflocal@proc .,dw,val \\}
struc dp [val] \\{ \common deflocal@proc .,dp,val \\}
struc dd [val] \\{ \common deflocal@proc .,dd,val \\}
struc dt [val] \\{ \common deflocal@proc .,dt,val \\}
struc dq [val] \\{ \common deflocal@proc .,dq,val \\}
struc rb cnt \\{ deflocal@proc .,rb cnt, \\}
struc rw cnt \\{ deflocal@proc .,rw cnt, \\}
struc rp cnt \\{ deflocal@proc .,rp cnt, \\}
struc rd cnt \\{ deflocal@proc .,rd cnt, \\}
struc rt cnt \\{ deflocal@proc .,rt cnt, \\}
struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \}
macro endl
\{ purge label
restruc db,dw,dp,dd,dt,dq
restruc rb,rw,rp,rd,rt,rq
restruc byte,word,dword,pword,tword,qword
current = $-(ebp-localbytes)
end virtual \}
macro ret operand
\{ match any, operand \\{ retn operand \\}
match , operand \\{ match epilogue:reglist, epilogue@proc:<regs>
\\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \}
macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2
end if \} }
macro defargs@proc [arg]
{ common
if ~ arg eq
forward
local ..arg,current@arg
match argname:type, arg
\{ current@arg equ argname
label ..arg type
argname equ ..arg
if dqword eq type
dd ?,?,?,?
else if tbyte eq type
dd ?,?,?
else if qword eq type | pword eq type
dd ?,?
else
dd ?
end if \}
match =current@arg,current@arg
\{ current@arg equ arg
arg equ ..arg
..arg dd ? \}
common
args@proc equ current@arg
forward
restore current@arg
common
end if }
macro deflocal@proc name,def,[val]
{ common
match vars, all@vars \{ all@vars equ all@vars, \}
all@vars equ all@vars name
forward
local ..var,..tmp
..var def val
match =?, val \{ ..tmp equ \}
match any =dup (=?), val \{ ..tmp equ \}
match tmp : value, ..tmp : val
\{ tmp: end virtual
initlocal@proc ..var,def value
virtual at tmp\}
common
match first rest, ..var, \{ name equ first \} }
macro initlocal@proc name,def
{ virtual at name
def
size@initlocal = $ - name
end virtual
position@initlocal = 0
while size@initlocal > position@initlocal
virtual at name
def
if size@initlocal - position@initlocal < 2
current@initlocal = 1
load byte@initlocal byte from name+position@initlocal
else if size@initlocal - position@initlocal < 4
current@initlocal = 2
load word@initlocal word from name+position@initlocal
else
current@initlocal = 4
load dword@initlocal dword from name+position@initlocal
end if
end virtual
if current@initlocal = 1
mov byte [name+position@initlocal],byte@initlocal
else if current@initlocal = 2
mov word [name+position@initlocal],word@initlocal
else
mov dword [name+position@initlocal],dword@initlocal
end if
position@initlocal = position@initlocal + current@initlocal
end while }
macro endp
{ purge ret,locals,endl
finish@proc
purge finish@proc
restore regs@proc
match all,args@proc \{ restore all \}
restore args@proc
match all,all@vars \{ restore all \} }
macro local [var]
{ common
locals
forward done@local equ
match varname[count]:vartype, var
\{ match =BYTE, vartype \\{ varname rb count
restore done@local \\}
match =WORD, vartype \\{ varname rw count
restore done@local \\}
match =DWORD, vartype \\{ varname rd count
restore done@local \\}
match =PWORD, vartype \\{ varname rp count
restore done@local \\}
match =QWORD, vartype \\{ varname rq count
restore done@local \\}
match =TBYTE, vartype \\{ varname rt count
restore done@local \\}
match =DQWORD, vartype \\{ label varname dqword
rq count+count
restore done@local \\}
match , done@local \\{ virtual
varname vartype
end virtual
rb count*sizeof.\#vartype
restore done@local \\} \}
match :varname:vartype, done@local:var
\{ match =BYTE, vartype \\{ varname db ?
restore done@local \\}
match =WORD, vartype \\{ varname dw ?
restore done@local \\}
match =DWORD, vartype \\{ varname dd ?
restore done@local \\}
match =PWORD, vartype \\{ varname dp ?
restore done@local \\}
match =QWORD, vartype \\{ varname dq ?
restore done@local \\}
match =TBYTE, vartype \\{ varname dt ?
restore done@local \\}
match =DQWORD, vartype \\{ label varname dqword
dq ?,?
restore done@local \\}
match , done@local \\{ varname vartype
restore done@local \\} \}
match ,done@local
\{ var
restore done@local \}
common
endl }

View File

@ -0,0 +1,166 @@
include 'proc32.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
; 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;
; while ((c=con_getch())!=27) // Esc=exit
; {
; if (c)
; con_printf("normal character with code %d=0x%02X\n",c,c);
; else
; {
; c=con_getch();
; con_printf("extended character with code %d=0x%02X\n",c,c);
; }
; }
push start_string
call [con_printf]
pop ecx
mainloop:
call [con_getch]
cmp al, 27
jz done
test eax, eax
jz extended
push eax
push eax
push string_normal
@@:
call [con_printf]
add esp, 12
jmp mainloop
extended:
call [con_getch]
push eax
push eax
push string_extended
jmp @b
done:
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
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:

View File

@ -0,0 +1,154 @@
include 'proc32.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
; 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 (;;)
; {
; con_write_asciiz("Enter string (empty for exit): ");
; con_gets(s,256);
; if (s[0] == '\n') break;
; con_write_asciiz("You entered: ");
; con_write_asciiz(s);
; }
mainloop:
push str1
call [con_write_asciiz]
push 256
push s
call [con_gets]
cmp [s], 10
jz done
push str2
call [con_write_asciiz]
push s
call [con_write_asciiz]
jmp mainloop
done:
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
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:

View File

@ -0,0 +1,106 @@
use32
db 'MENUET01'
dd 1
dd start
dd i_end
dd mem
dd mem
dd 0
dd 0
REQ_DLL_VER = 2
DLL_ENTRY = 1
start:
; First 3 steps are intended to load/init console DLL
; and are identical for all console programs
; load DLL
mov eax, 68
mov ebx, 19
mov ecx, dll_name
int 0x40
test eax, eax
jz exit
; initialize import
mov edx, eax
mov esi, myimport
import_loop:
lodsd
test eax, eax
jz import_done
push edx
import_find:
mov ebx, [edx]
test ebx, ebx
jz exit;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
pop edx
jmp import_loop
import_done:
; 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 (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
dll_name db '/sys/lib/console.obj',0
caption db 'Console test',0
aHelloWorld db 'Hello, World!',10,0
align 4
myimport:
dll_start dd aStart
dll_ver dd aVersion
con_init dd aConInit
con_write_asciiz dd aConWriteAsciiz
con_exit dd aConExit
dd 0
aStart db 'START',0
aVersion db 'version',0
aConInit db 'con_init',0
aConWriteAsciiz db 'con_write_asciiz',0
aConExit db 'con_exit',0
i_end:
align 4
rb 2048 ; stack
mem:

View File

@ -0,0 +1,161 @@
include 'proc32.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]
; C-equivalent of the following code:
; for (ebx=0;ebx<0x100;ebx++)
; {
; con_printf(t1,ebx);
; eax = con_set_flags(ebx);
; con_write_asciiz(text);
; con_set_flags(eax);
; }
; N.B. For efficiency result of first con_set_flags is not saved
; in register, but is pushed beforehand to the stack
; for second con_set_flags.
; Note that such code cannot be generated by stdcall macros.
xor ebx, ebx
@@:
push ebx
push t1
call [con_printf]
add esp, 8
push ebx
call [con_set_flags]
push eax
push text
call [con_write_asciiz]
call [con_set_flags]
inc bl
jnz @b
push text2
call [con_write_asciiz]
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
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
text2 db 27,'[7m€ íâ® ¯à¨¬¥à ¨á¯®«ì§®¢ ­¨ï '
db 27,'[1;36;41mEsc'
db 27,'[7m-¯®á«¥¤®¢ â¥«ì­®á⥩.',10,0
i_end:
align 4
rb 2048 ; stack
mem:

View File

@ -0,0 +1,161 @@
include 'proc32.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]
; C-equivalent of the following code:
; for (ebx=0;ebx<0x100;ebx++)
; {
; con_printf(t1,ebx);
; eax = con_set_flags(ebx);
; con_write_asciiz(text);
; con_set_flags(eax);
; }
; N.B. For efficiency result of first con_set_flags is not saved
; in register, but is pushed beforehand to the stack
; for second con_set_flags.
; Note that such code cannot be generated by stdcall macros.
xor ebx, ebx
@@:
push ebx
push t1
call [con_printf]
add esp, 8
push ebx
call [con_set_flags]
push eax
push text
call [con_write_asciiz]
call [con_set_flags]
inc bl
jnz @b
push text2
call [con_write_asciiz]
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
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
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:

View File

@ -0,0 +1,48 @@
fontname equ 'font8x16.bmp'
virtual at 0
file fontname, 3Eh
; sanity check
load a1 word from 0
load a2 dword from 0xE
if (a1 <> 'BM') | (a2 <> 0x28)
error 'not BMP file!'
end if
load a1 dword from 0x12
load a2 dword from 0x16
if (a1 and 0xF) | (a2 and 0xF) | (a1 > 16*16)
error 'font: invalid width or height'
end if
font_width = a1 shr 4
font_bmp_scanline = (font_width*2 + 3) and not 3
font_height = a2 shr 4
load a1 dword from 0x1A
if a1 <> 0x10001
error 'font: not monochrome bitmap'
end if
end virtual
font:
repeat font_height
cur_scan = %
repeat 256
virtual at 0
a2 = (font_width+14) shr 3
if cur_scan=1 & %=0x10
a2 = (font_width+7) shr 3
end if
file fontname:3Eh + font_bmp_scanline*(font_height*(16-((%-1) shr 4))-cur_scan) + ((((%-1) and 0xF)*font_width) shr 3), a2
dd 0
load a1 dword from 0
a1 = ((a1 and 0x55555555) shl 1) or ((a1 and 0xAAAAAAAA) shr 1)
a1 = ((a1 and 0x33333333) shl 2) or ((a1 and 0xCCCCCCCC) shr 2)
a1 = ((a1 and 0x0F0F0F0F) shl 4) or ((a1 and 0xF0F0F0F0) shr 4)
end virtual
a1 = (a1 shr (((%-1)*font_width) and 7)) and ((1 shl font_width) - 1)
a1 = a1 xor ((1 shl font_width) - 1)
if font_width > 8
dw a1
else
db a1
end if
end repeat
end repeat

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB