From 54712199cb2e909a6c41daa2062434122b326e49 Mon Sep 17 00:00:00 2001 From: maxcodehack Date: Tue, 8 Dec 2020 17:17:40 +0000 Subject: [PATCH] Add KolibriOS.lib example to bcc32 git-svn-id: svn://kolibrios.org@8340 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/bcc32/LScript.x | 23 ++++ programs/bcc32/Makefile_kolibrios_lib_app | 5 + .../bcc32/examples/kolibrios_lib/Makefile | 8 ++ programs/bcc32/examples/kolibrios_lib/test.c | 121 ++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100755 programs/bcc32/LScript.x create mode 100755 programs/bcc32/Makefile_kolibrios_lib_app create mode 100755 programs/bcc32/examples/kolibrios_lib/Makefile create mode 100755 programs/bcc32/examples/kolibrios_lib/test.c diff --git a/programs/bcc32/LScript.x b/programs/bcc32/LScript.x new file mode 100755 index 0000000000..30d3625172 --- /dev/null +++ b/programs/bcc32/LScript.x @@ -0,0 +1,23 @@ +PATH_SIZE = 1024; +PARAMS_SIZE = 256; +STACK_SIZE = 1024; + +SECTIONS +{ + .all : AT(0){ + LONG(0x554e454D); + LONG(0x31305445); + LONG(1); + LONG("_Main"); + LONG(END); + LONG($END + PATH_SIZE + PARAMS_SIZE + STACK_SIZE); + LONG($END + PATH_SIZE + PARAMS_SIZE + STACK_SIZE); + LONG($END + PATH_SIZE); + LONG($END); + *(.text) + *(.data) + } +END = .; + .bss ALIGN(16) : {*(.bss)} +$END = .; +} \ No newline at end of file diff --git a/programs/bcc32/Makefile_kolibrios_lib_app b/programs/bcc32/Makefile_kolibrios_lib_app new file mode 100755 index 0000000000..0f7464247a --- /dev/null +++ b/programs/bcc32/Makefile_kolibrios_lib_app @@ -0,0 +1,5 @@ +program: + wine bcc32 -c $(FILENAME).c + wine link -edit $(FILENAME).obj + kos32-ld -T $(SVN_BCC)/LScript.x $(FILENAME).obj -o $(FILENAME).kex $(SVN)/contrib/sdk/lib/KolibriOS.lib + objcopy -O binary -j .all $(FILENAME).kex diff --git a/programs/bcc32/examples/kolibrios_lib/Makefile b/programs/bcc32/examples/kolibrios_lib/Makefile new file mode 100755 index 0000000000..bcf3b44df6 --- /dev/null +++ b/programs/bcc32/examples/kolibrios_lib/Makefile @@ -0,0 +1,8 @@ +SVN:=../../../.. +SVN_PROGR:=$(SVN)/programs + +SVN_BCC:=$(SVN_PROGR)/bcc32 + +FILENAME:=test + +include $(SVN_BCC)/Makefile_kolibrios_lib_app diff --git a/programs/bcc32/examples/kolibrios_lib/test.c b/programs/bcc32/examples/kolibrios_lib/test.c new file mode 100755 index 0000000000..f47456b97f --- /dev/null +++ b/programs/bcc32/examples/kolibrios_lib/test.c @@ -0,0 +1,121 @@ +/* Event Constants */ +#define REDRAW_EVENT 1 +#define KEY_EVENT 2 +#define BUTTON_EVENT 3 + +/* Window Style Constants */ +#define WS_SKINNED_FIXED 0x4000000 +#define WS_COORD_CLIENT 0x20000000 +#define WS_CAPTION 0x10000000 + +/* Caption Style Constants */ +#define CS_MOVABLE 0 + +/* Charset specifiers for DrawText */ +#define DT_CP866_8X16 0x10000000 + +/* Fill styles for DrawText */ +#define DT_FILL_OPAQUE 0x40000000 + +/* Draw zero terminated string for DrawText */ +#define DT_ZSTRING 0x80000000 + +/* Button identifiesrs */ +#define BUTTON_CLOSE 1 + +/* Key code values */ +#define KEY_CODE_ENTER 13 + +#pragma pack(1) + +struct TButtonInput{ + union{ + struct{ + unsigned char MouseButton; + unsigned short ID; + unsigned char HiID; + }; + unsigned long Value; + }; +}; + +struct TKeyboardInput{ + union{ + struct{ + unsigned char Flag; + char Code; + union{ + char Scan; + unsigned short Control; + }; + }; + unsigned long Value; + }; +}; + +struct TSize{ + union{ + struct{ + unsigned short Height; + unsigned short Width; + }; + unsigned long Value; + }; +}; + +struct TRect{ + long Left; + long Top; + long Right; + long Bottom; +}; + +extern struct TButtonInput __stdcall GetButton(void); +extern struct TKeyboardInput __stdcall GetKey(void); +extern struct TSize __stdcall GetScreenSize(void); +extern unsigned long __stdcall WaitEvent(void); +extern void __stdcall BeginDraw(void); +extern void __stdcall EndDraw(void); +extern void __stdcall ThreadTerminate(void); +extern void __stdcall DrawWindow(long Left, + long Top, + long Right, + long Bottom, + char* Caption, + unsigned long BackColor, + unsigned long Style, + unsigned long CapStyle); +extern void __stdcall DrawText(long X, + long Y, + char* Text, + unsigned long ForeColor, + unsigned long BackColor, + unsigned long Flags, + unsigned long Count); + +struct TSize Screen; +struct TRect Window; + +void Main(){ + Screen = GetScreenSize(); + Window.Right = Screen.Width / 3; + Window.Bottom = Screen.Height / 3; + Window.Left = (Screen.Width - Window.Right) / 2; + Window.Top = (Screen.Height - Window.Bottom) / 2; + while(1){ + switch (WaitEvent()){ + case BUTTON_EVENT: + if (GetButton().ID == BUTTON_CLOSE) ThreadTerminate(); + break; + case KEY_EVENT: + if (GetKey().Code == KEY_CODE_ENTER) ThreadTerminate(); + break; + case REDRAW_EVENT: + BeginDraw(); + DrawWindow(Window.Right, Window.Bottom, Window.Left, Window.Top, "C with KolibriOS.lib", 0x00C0DDEE, WS_SKINNED_FIXED | WS_COORD_CLIENT | WS_CAPTION, CS_MOVABLE); + DrawText( 8, 25, "Press Enter to quit", 0, 0x00FFFFFF, DT_CP866_8X16 | DT_FILL_OPAQUE | DT_ZSTRING, 0); + EndDraw(); + break; + } + } +}