Add support for dropping files onto the window to mount them as a disk

This commit is contained in:
Ry 2022-12-26 18:22:21 -08:00
parent 8b5472519e
commit 14dc43710f
5 changed files with 28 additions and 4 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -88,7 +88,8 @@ int main(int argc, char *argv[]) {
key_released,
mouse_pressed,
mouse_released,
mouse_moved
mouse_moved,
drop_file
);
ScreenInit();

View File

@ -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;
}

View File

@ -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
);