Code: Select all
' Event Constants
Const REDRAW_EVENT = 1
Const KEY_EVENT = 2
Const BUTTON_EVENT = 3
Const MOUSE_EVENT = 6
' Window Style Constants
Const WS_SKINNED_FIXED = &H4000000
Const WS_SKINNED_SIZABLE = &H3000000
Const WS_FIXED = &H0000000
Const WS_SIZABLE = &H2000000
Const WS_FILL_TRANSPARENT = &B1000000000000000000000000000000
Const WS_FILL_GRADIENT = &B10000000000000000000000000000000
Const WS_COORD_CLIENT = &B100000000000000000000000000000
Const WS_CAPTION = &B10000000000000000000000000000
' Color Constants
Const COLOR_BLUE = &H000000FF
Const COLOR_RED = &H00FF0000
Const COLOR_GREEN = &H0000FF00
Const COLOR_WHITE = &H00FFFFFF
Const COLOR_BLACK = &H00000000
Type Size
height As UShort
width As UShort
End Type
type buf2d_buffer
img As ULong
left As UShort
top As UShort
width As ULong
height As ULong
color As ULong
bpp As byte
End Type
Dim Shared Scr As Size
Dim Shared Window_width As Long
Dim Shared Window_height As Long
Dim Shared Window_left As Long
Dim Shared Window_top As Long
DIM Shared sz_lib_init As ZString Ptr = @"lib_init"
DIM Shared sz_buf2d As ZString Ptr = @"/rd/1/lib/buf2d.obj"
DIM Shared sz_buf2d_create As ZString Ptr = @"buf2d_create"
DIM Shared sz_buf2d_draw As ZString Ptr = @"buf2d_draw"
DIM Shared sz_buf2d_delete As ZString Ptr = @"buf2d_delete"
DIM Shared sz_buf2d_create_f_img As ZString Ptr = @"buf2d_create_f_img"
DIM Shared sz_buf2d_bit_blt As ZString Ptr = @"buf2d_bit_blt"
DIM Shared sz_libimg As ZString Ptr = @"/rd/1/lib/libimg.obj"
DIM Shared sz_img_decode As ZString Ptr = @"img_decode"
DIM Shared sz_img_to_rgb2 As ZString Ptr = @"img_to_rgb2"
DIM Shared sz_img_destroy As ZString Ptr = @"img_destroy"
Dim Shared buf2d As Long
DIM Shared libimg As Long
Dim Shared buf2d_ItemBuffer as buf2d_buffer
Dim Shared buf2d_ImageBuffer as buf2d_buffer
DIM Shared sz_filepath As ZString Ptr = @"/rd/1/file managers/z_icons.png"
'DIM Shared sz_filepath As ZString Ptr = @"/rd/1/ICONSTRP.png"
'DIM Shared sz_filepath As ZString Ptr = @"/rd/1/DEVELOP/TE_ICON.PNG"
DIM Shared imgFileSize As ULong
DIM Shared imgFile As ULong
DIM Shared imgData As ULong
DIM Shared imgBuffer As ULong
DIM Shared ImgWidth As ULong
DIM Shared ImgHeight As ULong
DIM Shared icons As ULong
Dim Shared PaddingX As Long
Dim Shared PaddingY As Long
Dim Shared MarginX As Long
Dim Shared MarginY As Long
Declare Function WAIT_EVENT() As Long
Declare Function GET_KEY_CODE() As Long
Declare Function GET_BUTTON_NUMBER() As Long
Declare Function GET_SCREEN_SIZE() As size
Declare Function LOAD_LIBRARY(filename As ZString) As Long
Declare Function MEMORY_ALLOCATE(bytes As ULong) As ULong
Declare Function MEMORY_REALLOCATE(memPtr As ULong, bytes As ULong) As ULong
Declare Function MEMORY_FREE(memPtr As ULong) As ULong
Declare Function GET_FILE_SIZE(filename As ZString)As ULong
Declare Function FILE_READ(filename As ZString, buffer As ULong, position As ULong, count As ULong) As ULong
Declare Sub DRAW_WINDOW(Window_left As Long, Window_top As Long, Window_width As Long, Window_height As Long, Caption As ZString, BackColor As Long, Style As Long)
Declare Function GetProcAddress(hLib As Long, procname As ZString) As Long
Declare Sub DllInit(lib_init As Sub)
Declare Sub On_Redraw()
Declare Sub Event_Processor()
Declare Sub On_KeyPress()
Declare Sub On_ButtonPress()
Declare Sub DrawItem(x As Long, y As Long, index As Long, BackColor As Long)
DIM Shared buf2d_lib_init As Sub()
DIM Shared buf2d_create As Sub( buf2d_buffer As buf2d_buffer)
DIM Shared buf2d_draw As Sub( buf2d_buffer As buf2d_buffer)
DIM Shared buf2d_delete As Sub( buf2d_buffer As buf2d_buffer)
DIM Shared buf2d_create_f_img As Sub( buf2d_buffer As buf2d_buffer, ImgBuffer As ULong)
DIM Shared buf2d_bit_blt As Sub( dst_buf2d_buffer As buf2d_buffer, x As Long, y As Long, src_buf2d_buffer As buf2d_buffer)
DIM Shared libimg_lib_init As Sub()
DIM Shared img_decode As Function(Data As ULong, length As ULong, options As ULong)As ULong
DIM Shared img_to_rgb2 As Sub(imgData As ULong, dst As ULong)
DIM Shared img_destroy As Sub(imgData As ULong)
#Undef RGB
#Define RGB(r,g,b) ((cuint(r) shl 16) or (cuint(g) shl 8) or cuint(b))
#Macro PROGRAM_TERMINATE()
Asm
or eax, -1
int 64
End Asm
#EndMacro
#Macro REDRAW_START()
Asm
mov eax, 12
mov ebx, 1
int 64
End Asm
#EndMacro
#Macro REDRAW_FINISH()
Asm
mov eax, 12
mov ebx, 2
int 64
End Asm
#EndMacro
#Macro SET_EVENT(mask)
Asm
mov eax, 40
mov ebx, mask
int 64
End Asm
#EndMacro
Sub Main()
Scr = GET_SCREEN_SIZE()
Window_width = Scr.width Shr 1
Window_height = Scr.height Shr 2
Window_left = (Scr.width - Window_width) Shr 1
Window_top = (Scr.height - Window_height) Shr 1
buf2d = LOAD_LIBRARY(*sz_buf2d)
buf2d_lib_init = GetProcAddress(buf2d, *sz_lib_init)
buf2d_create = GetProcAddress(buf2d, *sz_buf2d_create)
buf2d_draw = GetProcAddress(buf2d, *sz_buf2d_draw)
buf2d_delete = GetProcAddress(buf2d, *sz_buf2d_delete)
buf2d_create_f_img = GetProcAddress(buf2d, *sz_buf2d_create_f_img)
buf2d_bit_blt = GetProcAddress(buf2d, *sz_buf2d_bit_blt)
libimg = LOAD_LIBRARY(*sz_libimg)
libimg_lib_init = GetProcAddress(libimg, *sz_lib_init)
img_decode = GetProcAddress(libimg, *sz_img_decode)
img_to_rgb2 = GetProcAddress(libimg, *sz_img_to_rgb2)
img_destroy = GetProcAddress(libimg, *sz_img_destroy)
DllInit libimg_lib_init
DllInit buf2d_lib_init
imgFileSize = GET_FILE_SIZE(*sz_filepath)
imgFile = MEMORY_ALLOCATE(imgFileSize)
FILE_READ *sz_filepath, imgFile, 0, imgFileSize
imgData = img_decode(imgFile, imgFileSize, 0)
MEMORY_FREE imgFile
ImgWidth = Peek(ULong, (imgData + 4))
ImgHeight = Peek(ULong, (imgData + 8))
imgBuffer = MEMORY_ALLOCATE(ImgWidth*ImgHeight*3)
img_to_rgb2(imgData, imgBuffer)
img_destroy(imgData)
buf2d_ImageBuffer.width = ImgWidth
buf2d_ImageBuffer.height = ImgHeight
buf2d_ImageBuffer.bpp = 24
buf2d_create_f_img(buf2d_ImageBuffer, imgBuffer)
buf2d_ImageBuffer.height = ImgWidth
icons = buf2d_ImageBuffer.img
MEMORY_FREE imgBuffer
On_Redraw
Do
Event_Processor
Loop
End Sub
'========================================================='
' Обработка Событий
'========================================================='
Sub Event_Processor()
Select Case WAIT_EVENT()
Case REDRAW_EVENT
On_Redraw
Case KEY_EVENT
On_KeyPress
Case BUTTON_EVENT
On_ButtonPress
End Select
End Sub
'========================================================='
' Нажатие Клавиатуры
'========================================================='
Sub On_KeyPress()
GET_KEY_CODE
End Sub
'========================================================='
' Нажатие Кнопки
'========================================================='
Sub On_ButtonPress()
Select Case GET_BUTTON_NUMBER()
Case 1
PROGRAM_TERMINATE()
End Select
End Sub
'========================================================='
' Перерисовка
'========================================================='
Sub On_Redraw()
REDRAW_START()
DRAW_WINDOW Window_left, Window_top, Window_width, Window_height, *sz_filepath, COLOR_WHITE, WS_SKINNED_FIXED + WS_COORD_CLIENT + WS_CAPTION
Dim index As Long = 0
Dim x As Long = 10
While x <= 330
Dim y As Long = 20
While y <= 100
DrawItem x, y, index, RGB(-index*16 + 255, y + 120, x Shr 1 + 20)
index = index + 1
y = y + buf2d_ItemBuffer.height + MarginY
Wend
x = x + buf2d_ItemBuffer.width + MarginX
Wend
REDRAW_FINISH()
End Sub
Sub DrawItem(x As Long, y As Long, index As Long, BackColor As Long)
PaddingY = 4
MarginX = 6
MarginY = 8
buf2d_ItemBuffer.width = 100
buf2d_ItemBuffer.height = PaddingY Shl 1 + ImgWidth
buf2d_ItemBuffer.left = x
buf2d_ItemBuffer.top = y
buf2d_ItemBuffer.color = BackColor
buf2d_ItemBuffer.bpp = 24
PaddingX = (buf2d_ItemBuffer.width - ImgWidth) Shr 1
buf2d_ImageBuffer.img = ImgWidth * ImgWidth * 3 * index + icons
buf2d_create(buf2d_ItemBuffer)
buf2d_bit_blt(buf2d_ItemBuffer, PaddingX, PaddingY, buf2d_ImageBuffer)
buf2d_draw(buf2d_ItemBuffer)
buf2d_delete(buf2d_ItemBuffer)
End Sub
Sub DRAW_WINDOW(Window_left As Long, Window_top As Long, Window_width As Long, Window_height As Long, Caption As ZString, BackColor As Long, Style As Long)
Asm
xor eax, eax
mov ebx, [Window_left]
shl ebx, 16
add ebx, [Window_width]
mov ecx, [Window_top]
shl ecx, 16
add ecx, [Window_height]
mov edx, [Style]
or edx, [BackColor]
mov edi, [Caption]
int 64
End Asm
End Sub
Function WAIT_EVENT() As Long
Asm
mov eax, 10
int 64
mov [Function], eax
End Asm
End Function
Function GET_KEY_CODE() As Long
Asm
mov eax, 2
int 64
mov [Function], eax
End Asm
End Function
Function GET_BUTTON_NUMBER() As Long
Asm
mov eax, 17
int 64
shr eax, 8
mov [Function], eax
End Asm
End Function
Function GET_SCREEN_SIZE() As size
Asm
mov eax, 61
mov ebx, 1
int 64
mov [Function], eax
End Asm
End Function
Function MEMORY_ALLOCATE(bytes As ULong) As ULong
Asm
push ecx
mov eax, 68
mov ebx, 12
mov ecx, [bytes]
Int 64
pop ecx
mov [Function], eax
End Asm
End Function
Function MEMORY_REALLOCATE(memPtr As ULong, bytes As ULong) As ULong
Asm
push ecx
push edx
mov eax, 68
mov ebx, 20
mov ecx, [bytes]
mov edx, [memPtr]
Int 64
pop edx
pop ecx
mov [Function], eax
End Asm
End Function
Function MEMORY_FREE(memPtr As ULong) As ULong
Asm
push ecx
mov eax, 68
mov ebx, 13
mov ecx, [memPtr]
Int 64
pop ecx
mov [Function], eax
End Asm
End Function
Function GET_FILE_SIZE(filename As ZString)As ULong
Asm
mov ecx, esp
sub ecx, 28 + 40
mov dword Ptr [ecx + 0], 5
mov dword Ptr [ecx + 8], 0
mov byte Ptr [ecx + 20], 0
mov [ecx + 16], ecx
add dword Ptr [ecx + 16], 28
mov eax, [filename]
mov [ecx + 21], eax
mov eax, 70
lea ebx, [ecx]
int 64
mov eax, [ecx + 28 + 32]
mov [Function], eax
End Asm
End Function
Function FILE_READ(filename As ZString, buffer As ULong, position As ULong, count As ULong) As ULong
Asm
mov ecx, esp
sub ecx, 28
mov dword Ptr [ecx + 0], 0
mov dword Ptr [ecx + 8], 0
mov Byte Ptr [ecx + 20], 0
mov eax, [position]
mov [ecx + 4], eax
mov eax, [buffer]
mov [ecx + 16], eax
mov eax, [count]
mov [ecx + 12], eax
mov eax, [filename]
mov [ecx + 21], eax
mov eax, 70
lea ebx, [ecx]
int 64
mov [Function], eax
End Asm
End Function
Function GetProcAddress(hLib As Long, procname As ZString) As Long
Asm
mov edx, [hLib]
xor eax, eax
test edx, edx
jz 2f
' -----------------------
1:
cmp dword Ptr [edx], 0
jz 2f
xor eax, eax
mov esi, [edx]
mov edi, [procname]
' -----------------------
0:
lodsb
scasb
jne 0f
or al, al
jnz 0b
jmp 1f
' -----------------------
0:
add edx, 8
jmp 1b
' -----------------------
1:
mov eax, [edx + 4]
' -----------------------
2:
mov [Function], eax
End Asm
End Function
Function LOAD_LIBRARY(filename As ZString) As Long
Asm
mov eax, 68
mov ebx, 19
mov ecx, [filename]
int 64
mov [Function], eax
End Asm
End Function
Sub DllInit(lib_init As Sub)
Asm
pushad
mov eax, offset MEMORY_ALLOCATE
mov ebx, offset MEMORY_FREE
mov ecx, offset MEMORY_REALLOCATE
mov edx, offset 0f
call [lib_init]
popad
jmp 4f
'--------------------------------------
0:
push ebp
mov ebp, esp
mov esi, [ebp + 8]
'--------------------------------------
2:
mov edx, [esi]
or edx, edx
jz 3f
push esi
mov esi, [esi + 4]
mov edi, offset 6f
'--------------------------------------
0:
lodsb
stosb
or al, al
jnz 0b
push offset 5f
Call LOAD_LIBRARY
or eax, eax
jz 2f
mov ecx, [eax]
cmp dword Ptr [ecx + 4], 0x74696E69
jne 0f
push dword Ptr [eax + 4]
call DllInit
'--------------------------------------
0:
mov ecx, eax
mov ebx, edx
test edx, edx
jz 1f
'--------------------------------------
0:
mov eax, [ebx]
test eax, eax
jz 1f
push eax
push ecx
Call GetProcAddress
or eax, eax
jz 0f
mov [ebx], eax
Add ebx, 4
jmp 0b
'--------------------------------------
0:
mov dword Ptr [esp], eax
'--------------------------------------
1:
pop esi
add esi, 8
jmp 2b
'--------------------------------------
3:
xor eax, eax
jmp 0f
'--------------------------------------
2:
pop esi
inc eax
'--------------------------------------
0:
pop ebp
ret 4
'--------------------------------------
5: .ascii "/sys/lib/"
6: .skip 32
'--------------------------------------
4:
End Asm
End Sub