mirror of
https://github.com/Jimmy-Z/term256.git
synced 2025-06-18 16:55:43 -04:00
activity() like a drive LED
This commit is contained in:
parent
66260fff6b
commit
4133fe59ed
@ -179,6 +179,7 @@ int main(void)
|
||||
prt("A QUICK BROWN FOX JUMPS OVER THE LAZY DOG.\n");
|
||||
prt("\x1b[7m");
|
||||
prt("A QUICK BROWN FOX JUMPS OVER THE LAZY DOG.\n");
|
||||
activity(COLOR_BRIGHT_RED);
|
||||
|
||||
if (!wait) {
|
||||
select_term(&t0);
|
||||
|
@ -13,10 +13,16 @@ void dbg_iprtf(const char *fmt, ...)
|
||||
#define TERM_WIDTH (FONT_WIDTH * TERM_COLS)
|
||||
#define TERM_HEIGHT (FONT_HEIGHT * TERM_ROWS)
|
||||
|
||||
#define MARGIN_LEFT ((SCREEN_WIDTH - TERM_WIDTH) / 2)
|
||||
#define MARGIN_RIGHT (SCREEN_WIDTH - TERM_WIDTH - MARGIN_LEFT)
|
||||
static_assert(MARGIN_LEFT == MARGIN_RIGHT, "should be centered");
|
||||
|
||||
#define MARGIN_TOP (SCREEN_HEIGHT - TERM_HEIGHT)
|
||||
|
||||
// default scroll x, center, border both side
|
||||
#define SCROLL_X0 ((TERM_WIDTH - SCREEN_WIDTH) / 2)
|
||||
#define SCROLL_X0 (-MARGIN_LEFT)
|
||||
// default scroll y, touch bottom to hide text below on bg, border(previous lines) on top
|
||||
#define SCROLL_Y0 ((TERM_HEIGHT - SCREEN_HEIGHT))
|
||||
#define SCROLL_Y0 (-MARGIN_TOP)
|
||||
|
||||
// use extra bg space to do native scroll, if possible
|
||||
#define BG_ROWS (BG_HEIGHT / FONT_HEIGHT)
|
||||
@ -99,7 +105,7 @@ ITCM_CODE
|
||||
UNROLL
|
||||
static inline void write_char(term_t *t, unsigned x, unsigned y, unsigned char c, unsigned char color, unsigned char bg_color) {
|
||||
const unsigned char *g = font + c * FONT_HEIGHT;
|
||||
u16 *p = t->bg + (y * BG_WIDTH + x) / 2;
|
||||
u16 *p = t->bg + (y * BG_WIDTH + x) / sizeof(u16);
|
||||
for (unsigned fy = 0; fy < FONT_HEIGHT; ++fy) {
|
||||
u16 *c = t->clut + (*g++) * FONT_WIDTH / sizeof(u16);
|
||||
*p++ = *c++;
|
||||
@ -284,6 +290,28 @@ void term_raw(term_t *t, char c) {
|
||||
++t->cur;
|
||||
}
|
||||
|
||||
// use the right most two pixels of current row, so nothing if margin can't contain that
|
||||
// 0~255 to ANSI color palette, -1 to use current background color
|
||||
void term_activity(term_t *t, int color) {
|
||||
#if MARGIN_RIGHT >= 2
|
||||
if (color == -1) {
|
||||
color = t->color_bg;
|
||||
}
|
||||
color &= 0xff;
|
||||
color = color | (color << 8);
|
||||
int row = t->cur / TERM_COLS;
|
||||
if (row >= TERM_ROWS) {
|
||||
row = TERM_ROWS - 1;
|
||||
}
|
||||
u16 *start = t->bg + (BG_WIDTH * (row + t->scroll_pos) * FONT_HEIGHT + SCREEN_WIDTH - MARGIN_LEFT - 2) / sizeof(u16);
|
||||
u16 *end = start + (BG_WIDTH * FONT_HEIGHT);
|
||||
while (start < end) {
|
||||
*start = color;
|
||||
start += BG_WIDTH / sizeof(u16);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
our ANSI ESC state machine only supports (some) CSI
|
||||
either two bytes \x1b(ESC/27/033)\x5b([/91/133) or single byte \x9b(155/233)
|
||||
|
@ -47,8 +47,27 @@ enum {
|
||||
};
|
||||
|
||||
enum {
|
||||
COLOR_FG_DEF = 7,
|
||||
COLOR_BG_DEF = 0,
|
||||
COLOR_BLACK = 0,
|
||||
COLOR_RED,
|
||||
COLOR_GREEN,
|
||||
COLOR_YELLOW,
|
||||
COLOR_BLUE,
|
||||
COLOR_MAGENTA,
|
||||
COLOR_CYAN,
|
||||
COLOR_WHITE,
|
||||
COLOR_BRIGHT_BLACK,
|
||||
COLOR_BRIGHT_RED,
|
||||
COLOR_BRIGHT_GREEN,
|
||||
COLOR_BRIGHT_YELLOW,
|
||||
COLOR_BRIGHT_BLUE,
|
||||
COLOR_BRIGHT_MAGENTA,
|
||||
COLOR_BRIGHT_CYAN,
|
||||
COLOR_BRIGHT_WHITE
|
||||
};
|
||||
|
||||
enum {
|
||||
COLOR_FG_DEF = COLOR_WHITE,
|
||||
COLOR_BG_DEF = COLOR_BLACK,
|
||||
};
|
||||
|
||||
void clr_bg(void *bg, unsigned height, u8 color);
|
||||
@ -62,3 +81,5 @@ void term_prt(term_t *t, const char *string);
|
||||
void term_ctl(term_t *t, int ctl_code, int param0, int param1);
|
||||
|
||||
void term_raw(term_t *t, char c);
|
||||
|
||||
void term_activity(term_t *t, int color);
|
||||
|
@ -32,3 +32,7 @@ void prtf(const char *fmt, ...) {
|
||||
void prt(const char *s) {
|
||||
term_prt(current_term, s);
|
||||
}
|
||||
|
||||
void activity(int color) {
|
||||
term_activity(current_term, color);
|
||||
}
|
||||
|
@ -11,3 +11,5 @@ void prtf(const char *fmt, ...)
|
||||
_ATTRIBUTE ((__format__ (__printf__, 1, 2)));
|
||||
|
||||
void prt(const char *s);
|
||||
|
||||
void activity(int color);
|
||||
|
Loading…
Reference in New Issue
Block a user