Skip to content

Commit

Permalink
Merge pull request sysprog21#84 from alanjian85/master
Browse files Browse the repository at this point in the history
SDL: Allow window resizing
  • Loading branch information
jserv authored Nov 5, 2022
2 parents c1b0c4a + 8a9a28a commit 10be4b6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/syscall.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ These system calls are solely for the convenience of accessing the [SDL library]

If a window does not already exist, one will be created with the specified `width` and `height`. The `screen` buffer will replace the content of the framebuffer, passing a different `width` or `height` compared to the size of the window is undefined behavior. This system call additionally polls events from the SDL library, and, if necessary, update the internal input specific event queue.

The width and height are merely the virutal dimensions of the screen; they are unrelated to the window's real size. The system call would deal with resizing events internally when they occurred.

### `setup_queue` - Setup input system's dedicated event and submission queue

**system call number**: `0xC0DE`
Expand Down
7 changes: 5 additions & 2 deletions src/syscall_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static bool check_sdl(struct riscv_t *rv, uint32_t width, uint32_t height)
}
window = SDL_CreateWindow("rv32emu", SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, width, height,
0 /* flags */);
SDL_WINDOW_RESIZABLE);
if (!window) {
fprintf(stderr, "Window could not be created! SDL_Error: %s\n",
SDL_GetError());
Expand Down Expand Up @@ -231,7 +231,10 @@ void syscall_draw_frame(struct riscv_t *rv)
memory_read(s->mem, pixels_ptr, screen, width * height * 4);
SDL_UnlockTexture(texture);

SDL_RenderCopy(renderer, texture, NULL, &(SDL_Rect){0, 0, width, height});
int actual_width, actual_height;
SDL_GetWindowSize(window, &actual_width, &actual_height);
SDL_RenderCopy(renderer, texture, NULL,
&(SDL_Rect){0, 0, actual_width, actual_height});
SDL_RenderPresent(renderer);
}

Expand Down

0 comments on commit 10be4b6

Please sign in to comment.