From 93dca0ef6fa0df8a091f93b0cf78e2ecc7739a63 Mon Sep 17 00:00:00 2001 From: lephe Date: Fri, 20 Jan 2017 21:11:00 +0100 Subject: [PATCH] Made INCOMPATIBLE changes to image rendering. Added inttypes.h and bakclight management in getkey(). --- TODO | 4 + demo/gintdemo.ld | 2 + demo/test_bopti.c | 4 +- include/display.h | 14 ++- include/internals/bopti.h | 2 +- include/inttypes.h | 116 ++++++++++++++++++ include/keyboard.h | 3 + include/screen.h | 6 + src/bopti/bopti_internals.c | 6 +- src/bopti/dimage.c | 2 +- src/bopti/dimage_part.c | 2 +- src/bopti/gimage.c | 2 +- src/bopti/gimage_part.c | 2 +- src/keyboard/getkey.c | 15 ++- ...reen_setBacklight.c => screen_backlight.c} | 18 +++ 15 files changed, 178 insertions(+), 20 deletions(-) create mode 100644 include/inttypes.h rename src/screen/{screen_setBacklight.c => screen_backlight.c} (56%) diff --git a/TODO b/TODO index 637225a..5e0a027 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,9 @@ Bugs to fix: - A few key hits ignored after leaving the application (could not reproduce) - Lost keyboard control at startup (could not reproduce) +- Influence of keyboard on some timers and RTC (maybe interrupt priority) +- Alignment of ALL .data / .rodata files is required to ensure converted data + is properly aligned Simple improvements: - demo: Try 284x124 at (-60, -28) (all disadvantages) @@ -8,6 +11,7 @@ Simple improvements: - time: Compute CLOCKS_PER_SEC - core: Add VBR handlers debugging information (if possible) - events: Introduce KeyRepeat events +- library: Implement C99's inttypes.h for Cake's UpdateExe Larger improvements: - errno: Introduce errno and use it more or less everywhere - bopti: Monochrome bitmaps blending modes diff --git a/demo/gintdemo.ld b/demo/gintdemo.ld index 49062c9..1947163 100644 --- a/demo/gintdemo.ld +++ b/demo/gintdemo.ld @@ -43,7 +43,9 @@ SECTIONS .rodata : { *(.rodata.fxconv); + *(.rodata.paradox); *(.rodata) + . = ALIGN(4); *(.rodata.*) _romdata = ALIGN(4) ; diff --git a/demo/test_bopti.c b/demo/test_bopti.c index 7942f39..f769365 100644 --- a/demo/test_bopti.c +++ b/demo/test_bopti.c @@ -25,7 +25,7 @@ static void getwh(Image *img, int *width, int *height) { - const unsigned char *data; + const uint8_t *data; if(!img) { @@ -37,7 +37,7 @@ static void getwh(Image *img, int *width, int *height) *height = img->height; if(*width && *height) return; - data = img->data; + data = (uint8_t *)img->data; *width = (data[0] << 8) | data[1]; *height = (data[2] << 8) | data[3]; } diff --git a/include/display.h b/include/display.h index a7167a4..5112f86 100644 --- a/include/display.h +++ b/include/display.h @@ -9,6 +9,8 @@ #ifndef _DISPLAY_H #define _DISPLAY_H 1 +#include + //--- // Heading declarations. @@ -36,15 +38,15 @@ enum Color */ struct Image { - unsigned char magic; - unsigned char format; + uint8_t magic; + uint8_t format; - unsigned char width; - unsigned char height; + uint8_t width; + uint8_t height; - const unsigned char __attribute__((aligned(4))) data[]; + const uint32_t data[]; -} __attribute__((aligned(4))); +} __attribute__((packed, aligned(4))); // Useful shorthand for user code. typedef struct Image Image; diff --git a/include/internals/bopti.h b/include/internals/bopti.h index 7e0009c..d120db8 100644 --- a/include/internals/bopti.h +++ b/include/internals/bopti.h @@ -59,7 +59,7 @@ struct Structure int width, height; int layer_size; - const unsigned char *data; + const uint8_t *data; int columns; int end_size, end_bytes; }; diff --git a/include/inttypes.h b/include/inttypes.h new file mode 100644 index 0000000..5864d31 --- /dev/null +++ b/include/inttypes.h @@ -0,0 +1,116 @@ +#ifndef _INTTYPES_H +#define _INTTYPES_H + +// Decimal notation. +#define PRId8 "d" +#define PRId16 "d" +#define PRId32 "d" +#define PRId64 "lld" + +#define PRIdLEAST8 "d" +#define PRIdLEAST16 "d" +#define PRIdLEAST32 "d" +#define PRIdLEAST64 "lld" + +#define PRIdFAST8 "d" +#define PRIdFAST16 "d" +#define PRIdFAST32 "d" +#define PRIdFAST64 "lld" + +// Decimal notation, again. +#define PRIi8 "i" +#define PRIi16 "i" +#define PRIi32 "i" +#define PRIi64 "lli" + +#define PRIiLEAST8 "i" +#define PRIiLEAST16 "i" +#define PRIiLEAST32 "i" +#define PRIiLEAST64 "lli" + +#define PRIiFAST8 "i" +#define PRIiFAST16 "i" +#define PRIiFAST32 "i" +#define PRIiFAST64 "lli" + +// Octal notation. +#define PRIo8 "o" +#define PRIo16 "o" +#define PRIo32 "o" +#define PRIo64 "llo" + +#define PRIoLEAST8 "o" +#define PRIoLEAST16 "o" +#define PRIoLEAST32 "o" +#define PRIoLEAST64 "llo" + +#define PRIoFAST8 "o" +#define PRIoFAST16 "o" +#define PRIoFAST32 "o" +#define PRIoFAST64 "llo" + +// Unsigned integers. +#define PRIu8 "u" +#define PRIu16 "u" +#define PRIu32 "u" +#define PRIu64 "llu" + +#define PRIuLEAST8 "u" +#define PRIuLEAST16 "u" +#define PRIuLEAST32 "u" +#define PRIuLEAST64 "llu" + +#define PRIuFAST8 "u" +#define PRIuFAST16 "u" +#define PRIuFAST32 "u" +#define PRIuFAST64 "llu" + +// Lowercase hexadecimal notation. +#define PRIx8 "x" +#define PRIx16 "x" +#define PRIx32 "x" +#define PRIx64 "llx" + +#define PRIxLEAST8 "x" +#define PRIxLEAST16 "x" +#define PRIxLEAST32 "x" +#define PRIxLEAST64 "llx" + +#define PRIxFAST8 "x" +#define PRIxFAST16 "x" +#define PRIxFAST32 "x" +#define PRIxFAST64 "llx" + +// Uppercase hexadecimal notation. +#define PRIX8 "X" +#define PRIX16 "X" +#define PRIX32 "X" +#define PRIX64 "llX" + +#define PRIXLEAST8 "X" +#define PRIXLEAST16 "X" +#define PRIXLEAST32 "X" +#define PRIXLEAST64 "llX" + +#define PRIXFAST8 "X" +#define PRIXFAST16 "X" +#define PRIXFAST32 "X" +#define PRIXFAST64 "llX" + +// Format specifiers of intmax_t and uintmax_t. +#define PRIdMAX "lld" +#define PRIiMAX "lli" +#define PRIoMAX "llo" +#define PRIuMAX "llu" +#define PRIxMAX "llx" +#define PRIXMAX "llX" + +// Format specifiers of intptr_t and uintptr_t. +#define PRIdPTR "d" +#define PRIiPTR "i" +#define PRIoPTR "o" +#define PRIuPTR "u" +#define PRIxPTR "x" +#define PRIXPTR "X" + +#endif // _INTTYPES_H diff --git a/include/keyboard.h b/include/keyboard.h index d90ea1d..a1b101b 100644 --- a/include/keyboard.h +++ b/include/keyboard.h @@ -152,6 +152,9 @@ enum GetkeyOpt Getkey_ShiftModifier = 0x01, Getkey_AlphaModifier = 0x02, + // Allow changing the backlight status on [SHIFT] + [OPTN]. + Getkey_ManageBacklight = 0x04, + // Key repetition. Notice that modifiers will never be repeated. Getkey_RepeatArrowKeys = 0x10, Getkey_RepeatCharKeys = 0x20, diff --git a/include/screen.h b/include/screen.h index 899d713..7f7e48c 100644 --- a/include/screen.h +++ b/include/screen.h @@ -26,4 +26,10 @@ void screen_display(const void *vram); */ void screen_setBacklight(int on); +/* + screen_toggleBacklight() + Changes the backlight state, regardless of its current state. +*/ +void screen_toggleBacklight(void); + #endif diff --git a/src/bopti/bopti_internals.c b/src/bopti/bopti_internals.c index b8c08ce..acdf435 100644 --- a/src/bopti/bopti_internals.c +++ b/src/bopti/bopti_internals.c @@ -290,7 +290,7 @@ void getStructure(struct Image *img, struct Structure *s) { s->width = (img->data[0] << 8) | img->data[1]; s->height = (img->data[2] << 8) | img->data[3]; - s->data = img->data + 4; + s->data = (uint8_t *)img->data + 4; column_count = (s->width + 31) >> 5; end = 0; @@ -300,7 +300,7 @@ void getStructure(struct Image *img, struct Structure *s) { s->width = img->width; s->height = img->height; - s->data = img->data; + s->data = (uint8_t *)img->data; column_count = img->width >> 5; end = img->width & 31; @@ -320,7 +320,7 @@ void getStructure(struct Image *img, struct Structure *s) // The layer size must be rounded to a multiple of 4. layer = s->height * ((column_count << 2) + end_bytes); - if(layer & 3) layer += 4 - (layer & 3); + layer = (layer + 3) & ~3; s->columns = column_count; s->end_bytes = end_bytes; diff --git a/src/bopti/dimage.c b/src/bopti/dimage.c index 6b09ae5..4033398 100644 --- a/src/bopti/dimage.c +++ b/src/bopti/dimage.c @@ -7,7 +7,7 @@ */ void dimage(int x, int y, struct Image *img) { - if(!img || img->magic != 0xb7) return; + if(!img || img->magic != 0x01) return; struct Structure s; struct Command command; diff --git a/src/bopti/dimage_part.c b/src/bopti/dimage_part.c index 06ef43b..4af879f 100644 --- a/src/bopti/dimage_part.c +++ b/src/bopti/dimage_part.c @@ -10,7 +10,7 @@ void dimage_part(int x, int y, struct Image *img, int left, int top, int width, int height) { - if(!img || img->magic != 0xb7) return; + if(!img || img->magic != 0x01) return; struct Structure s; struct Command command; diff --git a/src/bopti/gimage.c b/src/bopti/gimage.c index 4f8371e..e010f20 100644 --- a/src/bopti/gimage.c +++ b/src/bopti/gimage.c @@ -8,7 +8,7 @@ */ void gimage(int x, int y, struct Image *img) { - if(!img || img->magic != 0xb7) return; + if(!img || img->magic != 0x01) return; struct Structure s; struct Command command; diff --git a/src/bopti/gimage_part.c b/src/bopti/gimage_part.c index 744a7c2..7c3314f 100644 --- a/src/bopti/gimage_part.c +++ b/src/bopti/gimage_part.c @@ -30,7 +30,7 @@ struct Rect intersect(struct Rect r1, struct Rect r2) void gimage_part(int x, int y, struct Image *img, int left, int top, int width, int height) { - if(!img || img->magic != 0xb7) return; + if(!img || img->magic != 0x01) return; struct Structure s; struct Command command; diff --git a/src/keyboard/getkey.c b/src/keyboard/getkey.c index a1d2525..89e2bc5 100644 --- a/src/keyboard/getkey.c +++ b/src/keyboard/getkey.c @@ -1,6 +1,7 @@ #include #include #include +#include /* getkey() @@ -10,11 +11,10 @@ int getkey(void) { return getkey_opt( - Getkey_ShiftModifier | - Getkey_AlphaModifier | - + Getkey_ShiftModifier | + Getkey_AlphaModifier | + Getkey_ManageBacklight | Getkey_RepeatArrowKeys, - 0 ); } @@ -77,6 +77,13 @@ int getkey_opt(enum GetkeyOpt options, int cycles) case ET_KeyPress: ; int key = event.key; + if(options & Getkey_ManageBacklight && key == KEY_OPTN + && modifier & MOD_SHIFT) + { + screen_toggleBacklight(); + modifier &= ~MOD_SHIFT; + continue; + } if(options & Getkey_ShiftModifier && key == KEY_SHIFT) { modifier ^= MOD_SHIFT; diff --git a/src/screen/screen_setBacklight.c b/src/screen/screen_backlight.c similarity index 56% rename from src/screen/screen_setBacklight.c rename to src/screen/screen_backlight.c index 8aa231d..88e4078 100644 --- a/src/screen/screen_setBacklight.c +++ b/src/screen/screen_backlight.c @@ -20,3 +20,21 @@ void screen_setBacklight(int on) else *PNDR &= ~0x10; } } + +/* + screen_toggleBacklight() + Changes the backlight state, regardless of its current state. +*/ +void screen_toggleBacklight(void) +{ + if(isSH3()) + { + volatile unsigned char *PGDR = (void *)0xa400012c; + *PGDR ^= 0x80; + } + else + { + volatile unsigned char *PNDR = (void *)0xa4050138; + *PNDR ^= 0x10; + } +}