diff --git a/Makefile b/Makefile index 7764c41..3e564c2 100644 --- a/Makefile +++ b/Makefile @@ -67,8 +67,19 @@ bootloader/bootloader.bin: bootloader/main.asm $(wildcard bootloader/*.asm) base_image/startup.cfg: base_image/startup.cfg.default cp $< $@ +ICONS := \ + applications/icons/cfg_icon.inc \ + applications/icons/dsk_icon.inc \ + applications/icons/fxf_icon.inc + +applications/icons/%.inc: applications/icons/%.png + $(GFX2INC) 32 32 $< $@ +base_image/icons.res: applications/icons/icons.res.asm $(ICONS) + $(FOX32ASM) $< $@ + FILES = \ base_image/startup.cfg \ + base_image/icons.res \ base_image/kernel.fxf \ base_image/sh.fxf \ base_image/barclock.fxf \ @@ -83,6 +94,7 @@ FILES = \ ROM_FILES = \ base_image/startup.cfg \ + base_image/icons.res \ base_image/kernel.fxf \ base_image/sh.fxf \ base_image/barclock.fxf \ diff --git a/applications/icons/.gitignore b/applications/icons/.gitignore new file mode 100644 index 0000000..2a06e93 --- /dev/null +++ b/applications/icons/.gitignore @@ -0,0 +1 @@ +*.inc diff --git a/applications/icons/cfg_icon.png b/applications/icons/cfg_icon.png new file mode 100644 index 0000000..5831a0b Binary files /dev/null and b/applications/icons/cfg_icon.png differ diff --git a/applications/icons/dsk_icon.png b/applications/icons/dsk_icon.png new file mode 100644 index 0000000..7c3bee0 Binary files /dev/null and b/applications/icons/dsk_icon.png differ diff --git a/applications/icons/fxf_icon.png b/applications/icons/fxf_icon.png new file mode 100644 index 0000000..918a70c Binary files /dev/null and b/applications/icons/fxf_icon.png differ diff --git a/applications/icons/icons.res.asm b/applications/icons/icons.res.asm new file mode 100644 index 0000000..74f9a3f --- /dev/null +++ b/applications/icons/icons.res.asm @@ -0,0 +1,16 @@ +const ICON_SIZE: 4096 + + ; format: "RES" magic bytes, version, number of resource IDs + data.str "RES" data.8 0 data.8 3 + + ; format: 3 character null-terminated ID, pointer to data, size + data.strz "cfg" data.32 cfg_icon data.32 ICON_SIZE + data.strz "dsk" data.32 dsk_icon data.32 ICON_SIZE + data.strz "fxf" data.32 fxf_icon data.32 ICON_SIZE + +cfg_icon: + #include "cfg_icon.inc" +dsk_icon: + #include "dsk_icon.inc" +fxf_icon: + #include "fxf_icon.inc" diff --git a/fox32os.def b/fox32os.def index 28828a0..6cd68da 100644 --- a/fox32os.def +++ b/fox32os.def @@ -52,6 +52,9 @@ get_size: jmp [0x00000D24] draw_widgets_to_window: jmp [0x00000E10] handle_widget_click: jmp [0x00000E14] +; resource jump table +get_resource: jmp [0x00000F10] + ; event types const EVENT_TYPE_BUTTON_CLICK: 0x80000000 diff --git a/kernel/main.asm b/kernel/main.asm index 7aa2dd0..927deea 100644 --- a/kernel/main.asm +++ b/kernel/main.asm @@ -77,6 +77,10 @@ jump_table: org.pad 0x00000610 data.32 draw_widgets_to_window data.32 handle_widget_click + + ; resource jump table + org.pad 0x00000710 + data.32 get_resource jump_table_end: ; initialization code @@ -374,6 +378,7 @@ get_os_api_version: #include "allocator.asm" #include "fxf/fxf.asm" + #include "res.asm" #include "task.asm" #include "vfs/vfs.asm" #include "widget/widget.asm" diff --git a/kernel/res.asm b/kernel/res.asm new file mode 100644 index 0000000..bc370e4 --- /dev/null +++ b/kernel/res.asm @@ -0,0 +1,48 @@ +; RES resource routines + +; extract resource data from a RES binary loaded in memory +; inputs: +; r0: pointer to memory buffer containing a RES binary +; r1: pointer to 3 character null-terminated resource ID string +; r2: size of resource data to be extracted +; outputs: +; r0: pointer to newly-allocated memory buffer containing the requested resource data +; this buffer must be freed by the caller! +; returns zero if resource ID not found, not enough memory, or invalid magic bytes +get_resource: + cmp [r0], [res_magic] + ifnz mov r0, 0 + ifnz ret + + push r3 + push r31 + + mov r3, r0 + movz.8 r31, [r0+4] + add r0, 5 +get_resource_find_loop: + cmp [r0], [r1] + ifz jmp get_resource_found + add r0, 12 + loop get_resource_find_loop + mov r0, 0 + jmp get_resource_end +get_resource_found: + cmp r2, [r0+8] + ifgt mov r2, [r0+8] + mov r31, [r0+4] + add r31, r3 + mov r0, r2 + call allocate_memory + cmp r0, 0 + ifz jmp get_resource_end + mov r1, r0 + mov r0, r31 + call copy_memory_bytes + mov r0, r1 +get_resource_end: + pop r31 + pop r3 + ret + +res_magic: data.strz "RES"