diff --git a/Makefile b/Makefile index 3e564c2..490a916 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,10 @@ base_image/terminal.fxf: applications/terminal/main.asm $(wildcard applications/ $(FOX32ASM) $< $@ base_image/fetcher.fxf: applications/fetcher/Fetcher.okm $(wildcard applications/fetcher/*.okm) - $(GFX2INC) 32 32 applications/fetcher/icons/disk.png applications/fetcher/icons/disk.inc lua $(OKAMERON) -arch=fox32 -startup=applications/fetcher/start.asm $< \ applications/fetcher/About.okm \ applications/fetcher/Browser.okm \ + applications/fetcher/BrowserOpen.okm \ applications/fetcher/Desktop.okm \ applications/fetcher/OS.okm \ > applications/fetcher/fetcher.asm diff --git a/applications/fetcher/BrowserOpen.okm b/applications/fetcher/BrowserOpen.okm new file mode 100644 index 0000000..25c7c1e --- /dev/null +++ b/applications/fetcher/BrowserOpen.okm @@ -0,0 +1,101 @@ +MODULE BrowserOpen; + IMPORT OS, About, Browser; + + VAR browserOpenReturnFileNamePtr: POINTER TO CHAR; + browserOpenReturnDiskIdPtr: POINTER TO INT; + + EXTERN browserMenuItemsRoot: POINTER TO CHAR; + + PROCEDURE BrowserOpenMain(returnFileName, returnDiskId: PTR; hasIcons: CHAR; iconsResPtr: PTR;); + BEGIN + browserRunning := 1; + browserPage := 0; + browserDiskId := get_current_disk_id(); + browserHasIcons := hasIcons; + browserIconsResPtr := iconsResPtr; + browserOpenReturnFileNamePtr := returnFileName; + browserOpenReturnDiskIdPtr := returnDiskId; + + (* first, before we do anything, check to make sure the selected disk is available *) + IF browserDiskId >| 4 THEN + new_messagebox(0, "Invalid disk ID!", 0, 128, 128, 144); + end_current_task(); + ELSIF browserDiskId = 4 THEN + IF IsRomDiskAvailable() = 0 THEN + new_messagebox(0, "ROM disk not available!", 0, 128, 128, 200); + end_current_task(); + END; + ELSE + IF PortIn(080001000H OR browserDiskId) = 0 THEN + new_messagebox(0, "Disk not inserted!", 0, 128, 128, 160); + end_current_task(); + END; + END; + + (* create the window and draw its initial contents *) + new_window(PTROF(browserWindow), "Select a file - Fetcher", 384, 192, 64, 64, PTROF(browserMenuItemsRoot), PTROF(browserIcons)); + DrawBrowserWindow(); + + WHILE browserRunning DO + GetNextWindowEvent(PTROF(browserWindow)); + + (* mouse click event *) + IF eventArgs[0] = PTROF(EVENT_TYPE_MOUSE_CLICK) THEN + IF (eventArgs[1] <| 8) & (eventArgs[2] <| 16) THEN + browserRunning := 0; + ELSIF eventArgs[2] <| 16 THEN + start_dragging_window(PTROF(browserWindow)); + END; + handle_widget_click(PTROF(browserWindow), eventArgs[1], eventArgs[2]); + + (* menu bar click event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_BAR_CLICK) THEN + menu_bar_click_event(PTROF(browserMenuItemsRoot)); + + (* menu update event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_UPDATE) THEN + menu_update_event(); + + (* menu click event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_CLICK) THEN + MenuClickEvent(eventArgs[2], eventArgs[3]); + + (* menu ack event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_MENU_ACK) THEN + close_menu(PTROF(browserMenuItemsRoot)); + + (* button click event *) + ELSIF eventArgs[0] = PTROF(EVENT_TYPE_BUTTON_CLICK) THEN + HandleIconClickOpen(eventArgs[1]); + END; + + save_state_and_yield_task(); + END; + + destroy_window(PTROF(browserWindow)); + END; + + PROCEDURE HandleIconClickOpen(buttonId: INT;); + BEGIN + IF buttonId = 128 THEN + (* next page button *) + IncrementBrowserPage(); + ELSIF buttonId = 129 THEN + (* previous page button *) + DecrementBrowserPage(); + ELSE + (* an icon was clicked! *) + ReturnFromIcon(buttonId); + END; + END; + + PROCEDURE ReturnFromIcon(buttonId: INT;); + VAR icon: POINTER TO Fox32OSButtonWidget; + BEGIN + icon := PTROF(browserIcons[buttonId]); + IF CompareString(icon^.text, "") THEN RETURN(); END; + browserOpenReturnDiskIdPtr^ := browserDiskId; + copy_string(icon^.text, browserOpenReturnFileNamePtr); + browserRunning := 0; + END; +END. diff --git a/applications/fetcher/Fetcher.okm b/applications/fetcher/Fetcher.okm index fdbf884..d2f7323 100644 --- a/applications/fetcher/Fetcher.okm +++ b/applications/fetcher/Fetcher.okm @@ -1,5 +1,5 @@ MODULE Fetcher; - IMPORT OS, Browser, Desktop; + IMPORT OS, Browser, BrowserOpen, Desktop; EXTERN terminalStreamPtr: POINTER TO CHAR; EXTERN arg0Ptr: POINTER TO CHAR; @@ -26,6 +26,9 @@ MODULE Fetcher; IF (terminalStreamPtr = 0) & (arg0Ptr = 0) THEN (* probably launched from startup.cfg *) DesktopMain(hasIcons, iconsRes); + ELSIF (CompareString("open", arg0Ptr)) & (arg1Ptr # 0) & (arg2Ptr # 0) THEN + (* launched from an application wanting to open a file *) + BrowserOpenMain(arg1Ptr, arg2Ptr, hasIcons, iconsRes); ELSIF arg0Ptr <|= 5 THEN (* launched from an existing instance of fetcher *) BrowserMain(arg0Ptr, arg1Ptr, arg2Ptr, arg3Ptr, hasIcons, iconsRes); diff --git a/applications/fetcher/OS.okm b/applications/fetcher/OS.okm index a0e8bdb..ce6c10d 100644 --- a/applications/fetcher/OS.okm +++ b/applications/fetcher/OS.okm @@ -7,13 +7,12 @@ MODULE OS; 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, + set_window_flags, menu_update_event, menu_bar_click_event, close_menu, new_messagebox, get_current_disk_id, 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, - open, read, get_size, get_boot_disk_id, get_resource, allocate_memory, free_memory, string_length: INT; + ryfs_get_file_list, copy_memory_bytes, IsRomDiskAvailable, end_current_task, sleep_task, CompareString, + open, read, get_size, get_boot_disk_id, get_resource, allocate_memory, free_memory, string_length, copy_string: INT; EXTERN PROCEDURE brk: INT; - EXTERN PROCEDURE PortIn: INT; EXTERN EVENT_TYPE_MOUSE_CLICK, diff --git a/applications/fetcher/start.asm b/applications/fetcher/start.asm index c4fc1e7..704f38e 100644 --- a/applications/fetcher/start.asm +++ b/applications/fetcher/start.asm @@ -30,6 +30,12 @@ IsRomDiskAvailable: ifnz mov r0, 0 ret +CompareString: + call compare_string + ifz mov r0, 1 + ifnz mov r0, 0 + ret + brk: brk ret