diff --git a/src/risc-io.h b/src/risc-io.h index f559ec7..ccaf017 100644 --- a/src/risc-io.h +++ b/src/risc-io.h @@ -21,4 +21,8 @@ struct RISC_Clipboard { uint32_t (*read_data)(const struct RISC_Clipboard *); }; +struct RISC_LED { + void (*write)(const struct RISC_LED *, uint32_t); +}; + #endif // RISC_IO_H diff --git a/src/risc.c b/src/risc.c index 72d199f..6dd42ce 100644 --- a/src/risc.c +++ b/src/risc.c @@ -39,8 +39,8 @@ struct RISC { uint32_t mouse; uint8_t key_buf[16]; uint32_t key_cnt; - uint32_t leds; + const struct RISC_LED *leds; const struct RISC_Serial *serial; uint32_t spi_selected; const struct RISC_SPI *spi[4]; @@ -83,6 +83,10 @@ struct RISC *risc_new() { return risc; } +void risc_set_leds(struct RISC *risc, const struct RISC_LED *leds) { + risc->leds = leds; +} + void risc_set_serial(struct RISC *risc, const struct RISC_Serial *serial) { risc->serial = serial; } @@ -477,16 +481,9 @@ static void risc_store_io(struct RISC *risc, uint32_t address, uint32_t value) { switch (address - IOStart) { case 4: { // LED control - risc->leds = value; - printf("LEDs: "); - for (int i = 7; i >= 0; i--) { - if (risc->leds & (1 << i)) { - printf("%d", i); - } else { - printf("-"); - } + if (risc->leds) { + risc->leds->write(risc->leds, value); } - printf("\n"); break; } case 8: { diff --git a/src/risc.h b/src/risc.h index 29f61f0..6d3adb0 100644 --- a/src/risc.h +++ b/src/risc.h @@ -16,6 +16,7 @@ struct Damage { }; struct RISC *risc_new(); +void risc_set_leds(struct RISC *risc, const struct RISC_LED *leds); void risc_set_serial(struct RISC *risc, const struct RISC_Serial *serial); void risc_set_spi(struct RISC *risc, int index, const struct RISC_SPI *spi); void risc_set_clipboard(struct RISC *risc, const struct RISC_Clipboard *clipboard); diff --git a/src/sdl-main.c b/src/sdl-main.c index 5e6f2f9..892f9e9 100644 --- a/src/sdl-main.c +++ b/src/sdl-main.c @@ -8,6 +8,7 @@ #include #include #include "risc.h" +#include "risc-io.h" #include "disk.h" #include "pclink.h" #include "raw-serial.h" @@ -28,6 +29,7 @@ static uint32_t BLACK = 0x657b83, WHITE = 0xfdf6e3; static int best_display(const SDL_Rect *rect); static int clamp(int x, int min, int max); static enum Action map_keyboard_event(SDL_KeyboardEvent *event); +static void show_leds(const struct RISC_LED *leds, uint32_t value); static double scale_display(SDL_Window *window, const SDL_Rect *risc_rect, SDL_Rect *display_rect); static void update_texture(struct RISC *risc, SDL_Texture *texture, const SDL_Rect *risc_rect); @@ -61,6 +63,7 @@ struct KeyMapping key_map[] = { static struct option long_options[] = { { "fullscreen", no_argument, NULL, 'f' }, + { "leds", no_argument, NULL, 'L' }, { "size", required_argument, NULL, 's' }, { "serial-fd", required_argument, NULL, 'F' }, { NULL } @@ -76,7 +79,7 @@ static void fail(int code, const char *fmt, ...) { } static void usage() { - fail(1, "Usage: risc [--fullscreen] [--size x] disk-file-name"); + fail(1, "Usage: risc [--fullscreen] [--size x] [--leds] disk-file-name"); } int main (int argc, char *argv[]) { @@ -84,6 +87,10 @@ int main (int argc, char *argv[]) { risc_set_serial(risc, &pclink); risc_set_clipboard(risc, &sdl_clipboard); + struct RISC_LED leds = { + .write = show_leds + }; + bool fullscreen = false; SDL_Rect risc_rect = { .w = RISC_FRAMEBUFFER_WIDTH, @@ -91,12 +98,16 @@ int main (int argc, char *argv[]) { }; int opt; - while ((opt = getopt_long(argc, argv, "fS:F:", long_options, NULL)) != -1) { + while ((opt = getopt_long(argc, argv, "fLS:F:", long_options, NULL)) != -1) { switch (opt) { case 'f': { fullscreen = true; break; } + case 'L': { + risc_set_leds(risc, &leds); + break; + } case 's': { int w, h; if (sscanf(optarg, "%dx%d", &w, &h) != 2) { @@ -300,6 +311,18 @@ static enum Action map_keyboard_event(SDL_KeyboardEvent *event) { return ACTION_OBERON_INPUT; } +static void show_leds(const struct RISC_LED *leds, uint32_t value) { + printf("LEDs: "); + for (int i = 7; i >= 0; i--) { + if (value & (1 << i)) { + printf("%d", i); + } else { + printf("-"); + } + } + printf("\n"); +} + static double scale_display(SDL_Window *window, const SDL_Rect *risc_rect, SDL_Rect *display_rect) { int win_w, win_h; SDL_GetWindowSize(window, &win_w, &win_h);