summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--project/common.mk1
-rw-r--r--project/headers.mk3
-rw-r--r--project/tree.mk1
-rw-r--r--src/internal/gdi/gdi.c132
-rw-r--r--src/internal/gdi/gdi.h23
-rw-r--r--src/internal/gdi/gdi_system.h95
-rw-r--r--src/internal/gdi/gdi_window.h95
7 files changed, 350 insertions, 0 deletions
diff --git a/project/common.mk b/project/common.mk
index c0cf2a7..3b490d4 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -1,6 +1,7 @@
COMMON_SRCS = \
src/driver/ptyc_amain.c \
src/driver/ptyc_driver_ctx.c \
+ src/internal/gdi/gdi.c \
src/internal/nolibc/ptyc_compiler.c \
src/internal/ptycon_memfn_impl.c \
src/internal/ptycon_nolibc_impl.c \
diff --git a/project/headers.mk b/project/headers.mk
index 84041cc..6ce37e4 100644
--- a/project/headers.mk
+++ b/project/headers.mk
@@ -4,6 +4,9 @@ API_HEADERS = \
INTERNAL_HEADERS = \
$(PROJECT_DIR)/src/internal/argv/argv.h \
+ $(PROJECT_DIR)/src/internal/gdi/gdi.h \
+ $(PROJECT_DIR)/src/internal/gdi/gdi_system.h \
+ $(PROJECT_DIR)/src/internal/gdi/gdi_window.h \
$(PROJECT_DIR)/src/internal/$(PACKAGE)_driver_impl.h \
$(PROJECT_DIR)/src/internal/$(PACKAGE)_init_impl.h \
$(PROJECT_DIR)/src/internal/$(PACKAGE)_ioctl_impl.h \
diff --git a/project/tree.mk b/project/tree.mk
index 46818f8..07f4d48 100644
--- a/project/tree.mk
+++ b/project/tree.mk
@@ -2,6 +2,7 @@ tree.tag:
mkdir -p src
mkdir -p src/driver
mkdir -p src/internal
+ mkdir -p src/internal/gdi
mkdir -p src/internal/nolibc
mkdir -p src/logic
mkdir -p src/output
diff --git a/src/internal/gdi/gdi.c b/src/internal/gdi/gdi.c
new file mode 100644
index 0000000..3edf1a2
--- /dev/null
+++ b/src/internal/gdi/gdi.c
@@ -0,0 +1,132 @@
+#include <psxtypes/psxtypes.h>
+#include <pemagine/pemagine.h>
+#include <ntapi/ntapi.h>
+#include <gdi/gdi.h>
+
+#ifndef GDI_ADDRESS_SPACE_OCD
+#define GDI_ADDRESS_SPACE_OCD 0
+#endif
+
+int32_t __fastcall gdi_vtbl_init(gdi_vtbl * gdi)
+{
+ int32_t status;
+ void * hgdi32;
+ void * huser32;
+
+ ntapi_vtbl * ntapi;
+ struct dalist_ex ldr_module_list;
+ struct dalist_node * node;
+
+ uintptr_t block[0x80];
+ wchar16_t gdi32_base_name[] = {'g','d','i','3','2','.','d','l','l',0};
+ wchar16_t user32_base_name[] = {'u','s','e','r','3','2','.','d','l','l',0};
+
+ /* init */
+ if ((status = ntapi_init(&ntapi)))
+ return status;
+
+ ntapi->tt_aligned_block_memset(
+ block,0,sizeof(block));
+
+ /* module list */
+ if ((status = dalist_init_ex(
+ &ldr_module_list,
+ 0,0,0,
+ DALIST_MEMFN_CUSTOM)))
+ return status;
+
+ if ((status = dalist_deposit_memory_block(
+ &ldr_module_list,
+ block,sizeof(block))))
+ return status;
+
+ if ((status = ntapi->ldr_create_state_snapshot(
+ &ldr_module_list)))
+ return status;
+
+ /* load gdi32 (explicit), user32 (implicit) */
+ hgdi32 = 0;
+ huser32 = 0;
+
+ if ((status = ntapi->ldr_load_system_dll(
+ 0,
+ gdi32_base_name,
+ sizeof(gdi32_base_name),
+ 0,&hgdi32)))
+ return status;
+
+ hgdi32 = pe_get_module_handle(gdi32_base_name);
+ huser32 = pe_get_module_handle(user32_base_name);
+
+ if (!hgdi32 || !huser32)
+ return NT_STATUS_INTERNAL_ERROR;
+
+ /* address space ocd */
+ if ((status = dalist_get_node_by_key(
+ &ldr_module_list,
+ (struct dalist_node_ex **)&node,
+ (uintptr_t)hgdi32,
+ DALIST_NODE_TYPE_EXISTING | DALIST_NODE_TYPE_NEW,
+ 0)))
+ return status;
+
+ if ((status = dalist_get_node_by_key(
+ &ldr_module_list,
+ (struct dalist_node_ex **)&node,
+ (uintptr_t)huser32,
+ DALIST_NODE_TYPE_EXISTING | DALIST_NODE_TYPE_NEW,
+ 0)))
+ return status;
+
+ if (GDI_ADDRESS_SPACE_OCD)
+ if ((status = ntapi->ldr_revert_state_to_snapshot(&ldr_module_list)))
+ return status;
+
+ /* gdi vtbl */
+ gdi->get_system_metrics = (gdi_get_system_metrics *)pe_get_procedure_address(
+ huser32,
+ "GetSystemMetrics");
+
+ gdi->is_iconic = (gdi_is_iconic *)pe_get_procedure_address(
+ huser32,
+ "IsIconic");
+
+ gdi->is_zoomed = (gdi_is_zoomed *)pe_get_procedure_address(
+ huser32,
+ "IsZoomed");
+
+ gdi->peek_message = (gdi_peek_message *)pe_get_procedure_address(
+ huser32,
+ "PeekMessageW");
+
+ gdi->move_window = (gdi_move_window *)pe_get_procedure_address(
+ huser32,
+ "MoveWindow");
+
+ gdi->set_window_pos = (gdi_set_window_pos *)pe_get_procedure_address(
+ huser32,
+ "SetWindowPos");
+
+ gdi->get_window_rect = (gdi_get_window_rect *)pe_get_procedure_address(
+ huser32,
+ "GetWindowRect");
+
+ gdi->get_client_rect = (gdi_get_client_rect *)pe_get_procedure_address(
+ huser32,
+ "GetClientRect");
+
+ gdi->get_desktop_window = (gdi_get_desktop_window *)pe_get_procedure_address(
+ huser32,
+ "GetDesktopWindow");
+
+ if (sizeof(size_t) == 8)
+ gdi->set_window_long_ptr = (gdi_set_window_long_ptr *)pe_get_procedure_address(
+ huser32,
+ "SetWindowLongPtrW");
+ else
+ gdi->set_window_long_ptr = (gdi_set_window_long_ptr *)pe_get_procedure_address(
+ huser32,
+ "SetWindowLongW");
+
+ return NT_STATUS_SUCCESS;
+}
diff --git a/src/internal/gdi/gdi.h b/src/internal/gdi/gdi.h
new file mode 100644
index 0000000..f68c292
--- /dev/null
+++ b/src/internal/gdi/gdi.h
@@ -0,0 +1,23 @@
+#ifndef GDI_H
+#define GDI_H
+
+#include <psxtypes/psxtypes.h>
+#include "gdi_window.h"
+#include "gdi_system.h"
+
+typedef struct _gdi_vtbl {
+ gdi_get_system_metrics * get_system_metrics;
+ gdi_is_iconic * is_iconic;
+ gdi_is_zoomed * is_zoomed;
+ gdi_peek_message_utf16 * peek_message;
+ gdi_move_window * move_window;
+ gdi_set_window_pos * set_window_pos;
+ gdi_get_window_rect * get_window_rect;
+ gdi_get_client_rect * get_client_rect;
+ gdi_get_desktop_window * get_desktop_window;
+ gdi_set_window_long_ptr_utf16 * set_window_long_ptr;
+} gdi_vtbl;
+
+int32_t __fastcall gdi_vtbl_init(gdi_vtbl *);
+
+#endif
diff --git a/src/internal/gdi/gdi_system.h b/src/internal/gdi/gdi_system.h
new file mode 100644
index 0000000..23fd28c
--- /dev/null
+++ b/src/internal/gdi/gdi_system.h
@@ -0,0 +1,95 @@
+#ifndef GDI_SYSTEM_H
+#define GDI_SYSTEM_H
+
+#define GDI_SM_CXSCREEN 0
+#define GDI_SM_CYSCREEN 1
+#define GDI_SM_CXVSCROLL 2
+#define GDI_SM_CYHSCROLL 3
+#define GDI_SM_CYCAPTION 4
+#define GDI_SM_CXBORDER 5
+#define GDI_SM_CYBORDER 6
+#define GDI_SM_CXDLGFRAME 7
+#define GDI_SM_CXFIXEDFRAME 7
+#define GDI_SM_CYDLGFRAME 8
+#define GDI_SM_CYFIXEDFRAME 8
+#define GDI_SM_CYVTHUMB 9
+#define GDI_SM_CXHTHUMB 10
+#define GDI_SM_CXICON 11
+#define GDI_SM_CYICON 12
+#define GDI_SM_CXCURSOR 13
+#define GDI_SM_CYCURSOR 14
+#define GDI_SM_CYMENU 15
+#define GDI_SM_CXFULLSCREEN 16
+#define GDI_SM_CYFULLSCREEN 17
+#define GDI_SM_CYKANJIWINDOW 18
+#define GDI_SM_MOUSEPRESENT 19
+#define GDI_SM_CYVSCROLL 20
+#define GDI_SM_CXHSCROLL 21
+#define GDI_SM_DEBUG 22
+#define GDI_SM_SWAPBUTTON 23
+#define GDI_SM_RESERVED1 24
+#define GDI_SM_RESERVED2 25
+#define GDI_SM_RESERVED3 26
+#define GDI_SM_RESERVED4 27
+#define GDI_SM_CXMIN 28
+#define GDI_SM_CYMIN 29
+#define GDI_SM_CXSIZE 30
+#define GDI_SM_CYSIZE 31
+#define GDI_SM_CXSIZEFRAME 32
+#define GDI_SM_CXFRAME 32
+#define GDI_SM_CYSIZEFRAME 33
+#define GDI_SM_CYFRAME 33
+#define GDI_SM_CXMINTRACK 34
+#define GDI_SM_CYMINTRACK 35
+#define GDI_SM_CXDOUBLECLK 36
+#define GDI_SM_CYDOUBLECLK 37
+#define GDI_SM_CXICONSPACING 38
+#define GDI_SM_CYICONSPACING 39
+#define GDI_SM_MENUDROPALIGNMENT 40
+#define GDI_SM_PENWINDOWS 41
+#define GDI_SM_DBCSENABLED 42
+#define GDI_SM_CMOUSEBUTTONS 43
+#define GDI_SM_SECURE 44
+#define GDI_SM_CXEDGE 45
+#define GDI_SM_CYEDGE 46
+#define GDI_SM_CXMINSPACING 47
+#define GDI_SM_CYMINSPACING 48
+#define GDI_SM_CXSMICON 49
+#define GDI_SM_CYSMICON 50
+#define GDI_SM_CYSMCAPTION 51
+#define GDI_SM_CXSMSIZE 52
+#define GDI_SM_CYSMSIZE 53
+#define GDI_SM_CXMENUSIZE 54
+#define GDI_SM_CYMENUSIZE 55
+#define GDI_SM_ARRANGE 56
+#define GDI_SM_CXMINIMIZED 57
+#define GDI_SM_CYMINIMIZED 58
+#define GDI_SM_CXMAXTRACK 59
+#define GDI_SM_CYMAXTRACK 60
+#define GDI_SM_CXMAXIMIZED 61
+#define GDI_SM_CYMAXIMIZED 62
+#define GDI_SM_NETWORK 63
+#define GDI_SM_CLEANBOOT 67
+#define GDI_SM_CXDRAG 68
+#define GDI_SM_CYDRAG 69
+#define GDI_SM_SHOWSOUNDS 70
+#define GDI_SM_CXMENUCHECK 71
+#define GDI_SM_CYMENUCHECK 72
+#define GDI_SM_SLOWMACHINE 73
+#define GDI_SM_MIDEASTENABLED 74
+#define GDI_SM_MOUSEWHEELPRESENT 75
+#define GDI_SM_XVIRTUALSCREEN 76
+#define GDI_SM_YVIRTUALSCREEN 77
+#define GDI_SM_CXVIRTUALSCREEN 78
+#define GDI_SM_CYVIRTUALSCREEN 79
+#define GDI_SM_CMONITORS 80
+#define GDI_SM_SAMEDISPLAYFORMAT 81
+#define GDI_SM_IMMENABLED 82
+#define GDI_SM_CXFOCUSBORDER 83
+#define GDI_SM_CYFOCUSBORDER 84
+#define GDI_SM_TABLETPC 86
+#define GDI_SM_MEDIACENTER 87
+#define GDI_SM_STARTER 88
+#define GDI_SM_SERVERR2 89
+
+#endif
diff --git a/src/internal/gdi/gdi_window.h b/src/internal/gdi/gdi_window.h
new file mode 100644
index 0000000..eecf023
--- /dev/null
+++ b/src/internal/gdi/gdi_window.h
@@ -0,0 +1,95 @@
+#ifndef GDI_WINDOW_H
+#define GDI_WINDOW_H
+
+#include <psxtypes/psxtypes.h>
+
+
+#define GDI_GWL_USERDATA (-21)
+#define GDI_GWL_EXSTYLE (-20)
+#define GDI_GWL_STYLE (-16)
+#define GDI_GWL_ID (-12)
+#define GDI_GWL_HINSTANCE (-6)
+#define GDI_GWL_WNDPROC (-4)
+
+
+typedef struct _gdi_point {
+ int32_t x;
+ int32_t y;
+} gdi_point;
+
+typedef struct _gdi_rect {
+ int32_t left;
+ int32_t top;
+ int32_t right;
+ int32_t bottom;
+} gdi_rect;
+
+
+typedef struct _gdi_msg {
+ void * hwnd;
+ uint32_t message;
+ uintptr_t wparam;
+ intptr_t lparam;
+ uint32_t time;
+ gdi_point pt;
+} gdi_msg;
+
+
+typedef int32_t __stdcall gdi_peek_message(
+ gdi_msg * msg,
+ void * hwnd,
+ uint32_t msg_filter_min,
+ uint32_t msg_filter_max,
+ uint32_t remove_msg);
+
+typedef gdi_peek_message gdi_peek_message_ansi;
+typedef gdi_peek_message gdi_peek_message_utf16;
+
+typedef int32_t __stdcall gdi_get_system_metrics(
+ int32_t index);
+
+typedef int32_t __stdcall gdi_is_iconic(
+ void * hwnd);
+
+typedef int32_t __stdcall gdi_is_zoomed(
+ void * hwnd);
+
+typedef int32_t __stdcall gdi_move_window(
+ void * hwnd,
+ int32_t x,
+ int32_t y,
+ int32_t nwindth,
+ int32_t nheight,
+ int32_t repaint);
+
+
+typedef int32_t __stdcall gdi_set_window_pos(
+ void * hwnd,
+ void * hwnd_insert_after,
+ int32_t x,
+ int32_t y,
+ int32_t cx,
+ int32_t cy,
+ uint32_t flags);
+
+
+typedef int32_t __stdcall gdi_get_window_rect(
+ void * hwnd,
+ gdi_rect * rect);
+
+typedef int32_t __stdcall gdi_get_client_rect(
+ void * hwnd,
+ gdi_rect * rect);
+
+typedef void * __stdcall gdi_get_desktop_window(void);
+
+
+typedef int32_t __stdcall gdi_set_window_long_ptr(
+ void * hwnd,
+ int32_t index,
+ intptr_t new_long);
+
+typedef gdi_set_window_long_ptr gdi_set_window_long_ptr_ansi;
+typedef gdi_set_window_long_ptr gdi_set_window_long_ptr_utf16;
+
+#endif