Skip to content

Commit

Permalink
Fetcher: Use the global icons.res resource for the desktop icons
Browse files Browse the repository at this point in the history
  • Loading branch information
ry755 committed Oct 12, 2023
1 parent 19f5996 commit a033fae
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 13 deletions.
12 changes: 11 additions & 1 deletion applications/fetcher/Browser.okm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ MODULE Browser;
EXTERN browserMenuItemsRoot: POINTER TO CHAR;
EXTERN browserFileListFriendly: ARRAY 12 OF POINTER TO CHAR;

PROCEDURE BrowserMain(diskId, iconX, iconY: INT; desktopWin: PTR;);
PROCEDURE BrowserMain(diskId, iconX, iconY: INT; desktopWin: PTR; hasIcons: CHAR; iconsResPtr: PTR;);
VAR tempDskIconResPtr: PTR;
BEGIN
(* first, before we do anything, check to make sure the selected disk is available *)
IF diskId >| 4 THEN
Expand All @@ -36,6 +37,15 @@ MODULE Browser;
browserPage := 0;
browserDiskId := diskId;

(* if icons.res was loaded, then pull the `dsk` resource from it *)
IF hasIcons THEN
tempDskIconResPtr := get_resource(iconsResPtr, "dsk", 4096);
IF tempDskIconResPtr THEN
copy_memory_bytes(tempDskIconResPtr, PTROF(desktopDiskIcon), 4096);
free_memory(tempDskIconResPtr);
END;
END;

(* create the window and draw its initial contents *)
new_window(PTROF(browserWindow), "Fetcher", 384, 192, 64, 64, PTROF(browserMenuItemsRoot), PTROF(browserIcons));
DrawBrowserWindow();
Expand Down
17 changes: 13 additions & 4 deletions applications/fetcher/Desktop.okm
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@ MODULE Desktop;
VAR desktopRunning: CHAR;
desktopWindow: ARRAY WINDOW_STRUCT_SIZE OF CHAR;
desktopIcons: ARRAY 5 OF Fox32OSButtonWidget;
desktopDiskIcon: ARRAY 4096 OF CHAR;

EXTERN diskIcon: ARRAY 1024 OF INT;

PROCEDURE DesktopMain();
PROCEDURE DesktopMain(hasIcons: CHAR; iconsResPtr: PTR;);
VAR tempDskIconResPtr: PTR;
BEGIN
desktopRunning := 1;

(* if icons.res was loaded, then pull the `dsk` resource from it *)
IF hasIcons THEN
tempDskIconResPtr := get_resource(iconsResPtr, "dsk", 4096);
IF tempDskIconResPtr THEN
copy_memory_bytes(tempDskIconResPtr, PTROF(desktopDiskIcon), 4096);
free_memory(tempDskIconResPtr);
END;
END;

(* set up the desktop icon widgets *)
SetupDesktopIconStructs();

Expand Down Expand Up @@ -72,7 +81,7 @@ MODULE Desktop;
draw_widgets_to_window(desktopWin);

(* set the tilemap and draw the icons! *)
set_tilemap(PTROF(diskIcon), 32, 32);
set_tilemap(PTROF(desktopDiskIcon), 32, 32);
overlay := get_window_overlay_number(desktopWin);
i := 5;
y := 16;
Expand Down
24 changes: 21 additions & 3 deletions applications/fetcher/Fetcher.okm
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,35 @@ MODULE Fetcher;
EXTERN arg2Ptr: POINTER TO CHAR;
EXTERN arg3Ptr: POINTER TO CHAR;

VAR iconsResFile: ARRAY FILE_STRUCT_SIZE OF CHAR;
iconsRes: POINTER TO CHAR;
iconsResSize: INT;
hasIcons: CHAR;

PROCEDURE Main();
BEGIN
(* open icons.res from the boot disk and read its contents into `iconsRes` *)
hasIcons := 0;
IF open("icons.res", get_boot_disk_id(), PTROF(iconsResFile)) THEN
iconsResSize := get_size(PTROF(iconsResFile));
iconsRes := allocate_memory(iconsResSize);
read(iconsResSize, PTROF(iconsResFile), iconsRes);
hasIcons := 1;
END;

IF (terminalStreamPtr = 0) & (arg0Ptr = 0) THEN
(* probably launched from startup.cfg *)
DesktopMain();
DesktopMain(hasIcons, iconsRes);
ELSIF arg0Ptr <|= 5 THEN
(* launched from an existing instance of fetcher *)
BrowserMain(arg0Ptr, arg1Ptr, arg2Ptr, arg3Ptr);
BrowserMain(arg0Ptr, arg1Ptr, arg2Ptr, arg3Ptr, hasIcons, iconsRes);
ELSE
(* probably launched from the terminal *)
BrowserMain(string_to_int(arg0Ptr, 10), 0, 0, 0);
BrowserMain(string_to_int(arg0Ptr, 10), 0, 0, 0, hasIcons, iconsRes);
END;

IF hasIcons THEN
free_memory(iconsRes);
END;
END;
END.
4 changes: 3 additions & 1 deletion applications/fetcher/OS.okm
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

MODULE OS;
CONST WINDOW_STRUCT_SIZE = 36;
CONST FILE_STRUCT_SIZE = 32;

EXTERN PROCEDURE new_window, destroy_window, draw_str_to_overlay, get_window_overlay_number,
draw_widgets_to_window, draw_filled_rectangle_to_overlay, GetNextWindowEvent, DrawPixel,
save_state_and_yield_task, start_dragging_window, handle_widget_click, fill_window, fill_overlay,
set_window_flags, menu_update_event, menu_bar_click_event, close_menu, new_messagebox,
launch_fxf_from_disk, get_boot_disk_id, string_to_int, set_tilemap, draw_tile_to_overlay,
ryfs_get_file_list, copy_memory_bytes, IsRomDiskAvailable, end_current_task, sleep_task: INT;
ryfs_get_file_list, copy_memory_bytes, IsRomDiskAvailable, end_current_task, sleep_task,
open, read, get_size, get_boot_disk_id, get_resource, allocate_memory, free_memory: INT;

EXTERN PROCEDURE brk: INT;

Expand Down
1 change: 0 additions & 1 deletion applications/fetcher/icons/.gitignore

This file was deleted.

Binary file removed applications/fetcher/icons/disk.png
Binary file not shown.
3 changes: 0 additions & 3 deletions applications/fetcher/start.asm
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,5 @@ menu_items_system_list:
data.8 7 ; menu width (usually longest item + 2)
data.8 5 data.strz "About" ; text length, text, null-terminator

diskIcon:
#include "icons/disk.inc"

#include "../../../fox32rom/fox32rom.def"
#include "../../fox32os.def"

0 comments on commit a033fae

Please sign in to comment.