From 14dc43710ffa0ce62e127f17bba3c10f3171005b Mon Sep 17 00:00:00 2001 From: Ry Date: Mon, 26 Dec 2022 18:22:21 -0800 Subject: [PATCH] Add support for dropping files onto the window to mount them as a disk --- src/bus.c | 10 ++++++++++ src/bus.h | 1 + src/main.c | 3 ++- src/screen.c | 13 +++++++++++-- src/screen.h | 5 ++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/bus.c b/src/bus.c index 42a758c..e3a210e 100644 --- a/src/bus.c +++ b/src/bus.c @@ -258,3 +258,13 @@ int bus_io_write(void *user, uint32_t value, uint32_t port) { return 0; } + +void drop_file(char *filename) { + int last_id = 0; + for (int i = 0; i < 4; i++) { + if (disk_controller.disks[i].size != 0) { + last_id++; + } + } + new_disk(filename, last_id); +} diff --git a/src/bus.h b/src/bus.h index e50261f..0d72ae4 100644 --- a/src/bus.h +++ b/src/bus.h @@ -2,3 +2,4 @@ int bus_io_read(void *user, uint32_t *value, uint32_t port); int bus_io_write(void *user, uint32_t value, uint32_t port); +void drop_file(char *filename); diff --git a/src/main.c b/src/main.c index 98651bb..a985702 100644 --- a/src/main.c +++ b/src/main.c @@ -88,7 +88,8 @@ int main(int argc, char *argv[]) { key_released, mouse_pressed, mouse_released, - mouse_moved + mouse_moved, + drop_file ); ScreenInit(); diff --git a/src/screen.c b/src/screen.c index 3e71420..13a9f3e 100644 --- a/src/screen.c +++ b/src/screen.c @@ -115,7 +115,6 @@ int ScreenProcessEvents() { break; } - case SDL_MOUSEBUTTONUP: { if (MainScreen.MouseReleased) MainScreen.MouseReleased(event.button.button); @@ -131,6 +130,14 @@ int ScreenProcessEvents() { if (MainScreen.KeyReleased) MainScreen.KeyReleased(event.key.keysym.scancode); break; + + case SDL_DROPFILE: + if (MainScreen.DropFile) { + char *file = event.drop.file; + MainScreen.DropFile(file); + SDL_free(file); + } + break; } } @@ -160,7 +167,8 @@ void ScreenCreate( ScreenKeyReleasedF keyreleased, ScreenMousePressedF mousepressed, ScreenMouseReleasedF mousereleased, - ScreenMouseMovedF mousemoved + ScreenMouseMovedF mousemoved, + ScreenDropFileF dropfile ) { if (w > WindowWidth) @@ -178,4 +186,5 @@ void ScreenCreate( MainScreen.MousePressed = mousepressed; MainScreen.MouseReleased = mousereleased; MainScreen.MouseMoved = mousemoved; + MainScreen.DropFile = dropfile; } diff --git a/src/screen.h b/src/screen.h index 70d3cdc..d2ec628 100644 --- a/src/screen.h +++ b/src/screen.h @@ -10,6 +10,7 @@ typedef void (*ScreenKeyReleasedF)(int sdl_scancode); typedef void (*ScreenMousePressedF)(int button); typedef void (*ScreenMouseReleasedF)(int button); typedef void (*ScreenMouseMovedF)(int dx, int dy); +typedef void (*ScreenDropFileF)(char *filename); struct Screen { int Width; @@ -22,6 +23,7 @@ struct Screen { ScreenMousePressedF MousePressed; ScreenMouseReleasedF MouseReleased; ScreenMouseMovedF MouseMoved; + ScreenDropFileF DropFile; }; void ScreenInit(); @@ -39,5 +41,6 @@ void ScreenCreate( ScreenKeyReleasedF keyreleased, ScreenMousePressedF mousepressed, ScreenMouseReleasedF mousereleased, - ScreenMouseMovedF mousemoved + ScreenMouseMovedF mousemoved, + ScreenDropFileF dropfile );