Skip to content

Commit

Permalink
Add support for dropping files onto the window to mount them as a disk
Browse files Browse the repository at this point in the history
  • Loading branch information
ry755 committed Dec 27, 2022
1 parent 8b54725 commit 14dc437
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
1 change: 1 addition & 0 deletions src/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
3 changes: 2 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ int main(int argc, char *argv[]) {
key_released,
mouse_pressed,
mouse_released,
mouse_moved
mouse_moved,
drop_file
);

ScreenInit();
Expand Down
13 changes: 11 additions & 2 deletions src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ int ScreenProcessEvents() {
break;
}


case SDL_MOUSEBUTTONUP: {
if (MainScreen.MouseReleased)
MainScreen.MouseReleased(event.button.button);
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -160,7 +167,8 @@ void ScreenCreate(
ScreenKeyReleasedF keyreleased,
ScreenMousePressedF mousepressed,
ScreenMouseReleasedF mousereleased,
ScreenMouseMovedF mousemoved
ScreenMouseMovedF mousemoved,
ScreenDropFileF dropfile
) {

if (w > WindowWidth)
Expand All @@ -178,4 +186,5 @@ void ScreenCreate(
MainScreen.MousePressed = mousepressed;
MainScreen.MouseReleased = mousereleased;
MainScreen.MouseMoved = mousemoved;
MainScreen.DropFile = dropfile;
}
5 changes: 4 additions & 1 deletion src/screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@ struct Screen {
ScreenMousePressedF MousePressed;
ScreenMouseReleasedF MouseReleased;
ScreenMouseMovedF MouseMoved;
ScreenDropFileF DropFile;
};

void ScreenInit();
Expand All @@ -39,5 +41,6 @@ void ScreenCreate(
ScreenKeyReleasedF keyreleased,
ScreenMousePressedF mousepressed,
ScreenMouseReleasedF mousereleased,
ScreenMouseMovedF mousemoved
ScreenMouseMovedF mousemoved,
ScreenDropFileF dropfile
);

0 comments on commit 14dc437

Please sign in to comment.