Hide LED output by default.

This commit is contained in:
Peter De Wachter 2016-08-06 23:08:14 +02:00
parent b320cb6d6d
commit 5c3a1b020d
4 changed files with 37 additions and 12 deletions

View File

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

View File

@ -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: {

View File

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

View File

@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#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 <width>x<height>] disk-file-name");
fail(1, "Usage: risc [--fullscreen] [--size <width>x<height>] [--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);