diff --git a/src/console.cpp b/src/console.cpp index 4d820e5..174b6c4 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -86,16 +86,11 @@ POSITIONS dpos = void loadexternalpalette(); void initicon(); -static inline void setcharcolor(unsigned *dptr, short ch, short color) +static inline void setcharcolor(unsigned *dptr, unsigned char ch, unsigned char color) { *dptr = (ch & 0xff) | (color << 16) | (colors.CBKGND << 20); } -static inline void setcolor(unsigned *dptr, short color) -{ - *dptr = (*dptr & 0xffff) | (color << 16) | (colors.CBKGND << 20); -} - bool initscreen() { if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) @@ -292,8 +287,7 @@ void printblankc(int x, int y, int color, int length) void drawbox(int x, int y, int color, int sx, int sy) { if (!gfxinitted) return; - if (y < 0) return; - if (y >= MAX_ROWS) return; + if ((y < 0) || (y >= MAX_ROWS)) return; if (y+sy > MAX_ROWS) return; if ((!sx) || (!sy)) return; @@ -343,7 +337,7 @@ void printbg(int x, int y, int color, int length) while (length--) { - setcolor(dptr, 15 | (color << 4)); + *dptr = (*dptr & 0xffff) | (colors.CBKGND << 16) | (color << 20); dptr++; } } @@ -401,11 +395,10 @@ void fliptoscreen() unsigned char *dptr = (unsigned char*)gfx_screen->pixels + y*fontheight * gfx_screen->pitch + x*fontwidth; unsigned char bgcolor = (*sptr) >> 20; unsigned char fgcolor = ((*sptr) >> 16) & 0xf; - int c; unsigned char e = *chptr++; - for (c = 0; c < 14; c++) + for (int c = 0; c < 14; c++) { e = *chptr++; diff --git a/src/display.cpp b/src/display.cpp index e3ef549..aaa14da 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -40,22 +40,25 @@ #include #include -#define CBLACK 0x0 -#define CWHITE 0x1 -#define CDRED 0x2 -#define CCYAN 0x3 -#define CPURPLE 0x4 -#define CDGREEN 0x5 -#define CDBLUE 0x6 -#define CYELLOW 0x7 -#define CLBROWN 0x8 -#define CDBROWN 0x9 -#define CLRED 0xA -#define CDGREY 0xB -#define CGREY 0xC -#define CLGREEN 0xD -#define CLBLUE 0xE -#define CLGREY 0xF +enum +{ + CBLACK = 0x0, + CWHITE = 0x1, + CDRED = 0x2, + CCYAN = 0x3, + CPURPLE = 0x4, + CDGREEN = 0x5, + CDBLUE = 0x6, + CYELLOW = 0x7, + CLBROWN = 0x8, + CDBROWN = 0x9, + CLRED = 0xA, + CDGREY = 0xB, + CGREY = 0xC, + CLGREEN = 0xD, + CLBLUE = 0xE, + CLGREY = 0xF +}; const char *notename[] = {"C-0", "C#0", "D-0", "D#0", "E-0", "F-0", "F#0", "G-0", "G#0", "A-0", "A#0", "B-0", @@ -73,11 +76,14 @@ int timemin = 0; int timesec = 0; unsigned timeframe = 0; +int cursorflash = 0; +int cursorcolortable[] = { CWHITE, CLGREY, CGREY, CLGREY }; + void initcolorscheme(bool dark) { colors.CBKGND = dark ? CBLACK : CDBLUE; - colors.CNORMAL = (dark ? CGREY : CLBLUE) |(colors.CBKGND<<4); + colors.CNORMAL = (dark ? CGREY : CLBLUE)|(colors.CBKGND<<4); colors.CMUTE = CDGREY |(colors.CBKGND<<4); colors.CEDIT = CLGREEN|(colors.CBKGND<<4); colors.CPLAYING = CLRED |(colors.CBKGND<<4); @@ -97,21 +103,31 @@ void printmainscreen() fliptoscreen(); } +void flashCursor() +{ + if (cursorflashdelay >= 6) + { + cursorflashdelay %= 6; + cursorflash++; + cursorflash &= 3; + } +} + +int getCursorColor() +{ + return cursorcolortable[cursorflash]; +} + void displayupdate() { - if (cursorflashdelay >= 6) - { - cursorflashdelay %= 6; - cursorflash++; - cursorflash &= 3; - } + flashCursor(); printstatus(); fliptoscreen(); } void printstatus() { - int cc = cursorcolortable[cursorflash]; + int cc = getCursorColor(); int visibleOrderlist = getVisibleOrderlist(); int maxChns = getMaxChannels(); @@ -301,12 +317,12 @@ void printstatus() if (epmarkstart <= epmarkend) { if ((p >= epmarkstart) && (p <= epmarkend)) - printbg(dpos.patternsX+c*13+3, dpos.patternsY+1+d, 8, 9); + printbg(dpos.patternsX+c*13+3, dpos.patternsY+1+d, colors.CHDRBG, 9); } else { if ((p <= epmarkstart) && (p >= epmarkend)) - printbg(dpos.patternsX+c*13+3, dpos.patternsY+1+d, 8, 9); + printbg(dpos.patternsX+c*13+3, dpos.patternsY+1+d, colors.CHDRBG, 9); } } if ((color == colors.CEDIT) && (editmode == EDIT_PATTERN) && (epchn == c)) @@ -412,9 +428,9 @@ void printstatus() if ((p >= esmarkstart) && (p <= esmarkend)) { if (p != esmarkend) - printbg(dpos.orderlistX+4+d*3, dpos.orderlistY+1+c, 1, 3); + printbg(dpos.orderlistX+4+d*3, dpos.orderlistY+1+c, colors.CHDRBG, 3); else - printbg(dpos.orderlistX+4+d*3, dpos.orderlistY+1+c, 1, 2); + printbg(dpos.orderlistX+4+d*3, dpos.orderlistY+1+c, colors.CHDRBG, 2); } } else @@ -422,9 +438,9 @@ void printstatus() if ((p <= esmarkstart) && (p >= esmarkend)) { if (p != esmarkstart) - printbg(dpos.orderlistX+4+d*3, dpos.orderlistY+1+c, 1, 3); + printbg(dpos.orderlistX+4+d*3, dpos.orderlistY+1+c, colors.CHDRBG, 3); else - printbg(dpos.orderlistX+4+d*3, dpos.orderlistY+1+c, 1, 2); + printbg(dpos.orderlistX+4+d*3, dpos.orderlistY+1+c, colors.CHDRBG, 2); } } } @@ -516,12 +532,12 @@ void printstatus() if (etmarkstart <= etmarkend) { if ((p >= etmarkstart) && (p <= etmarkend)) - printbg(dpos.instrumentsX+10*c+3, dpos.instrumentsY+8+d, 1, 5); + printbg(dpos.instrumentsX+10*c+3, dpos.instrumentsY+8+d, colors.CHDRBG, 5); } else { if ((p <= etmarkstart) && (p >= etmarkend)) - printbg(dpos.instrumentsX+10*c+3, dpos.instrumentsY+8+d, 1, 5); + printbg(dpos.instrumentsX+10*c+3, dpos.instrumentsY+8+d, colors.CHDRBG, 5); } } } diff --git a/src/display.h b/src/display.h index 5364ab4..5c47da6 100644 --- a/src/display.h +++ b/src/display.h @@ -25,5 +25,7 @@ void displayupdate(); void printstatus(); void resettime(); void incrementtime(); +void flashCursor(); +int getCursorColor(); #endif diff --git a/src/file.cpp b/src/file.cpp index 8f01a40..cb085ba 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -225,13 +225,8 @@ bool fileselector(char *name, char *path, char *filter, const char *title, int f int exitfilesel = -1; while (exitfilesel < 0) { - int cc = cursorcolortable[cursorflash]; - if (cursorflashdelay >= 6) - { - cursorflashdelay %= 6; - cursorflash++; - cursorflash &= 3; - } + int cc = getCursorColor(); + flashCursor(); fliptoscreen(); getkey(); if (lastclick) lastclick--; diff --git a/src/loadtrk.cpp b/src/loadtrk.cpp index 0f8b3d1..459698f 100644 --- a/src/loadtrk.cpp +++ b/src/loadtrk.cpp @@ -61,8 +61,6 @@ int editmode = EDIT_PATTERN; bool recordmode = true; bool followplay = false; int hexnybble = -1; -int cursorflash = 0; -int cursorcolortable[] = {1,2,7,2}; bool exitprogram = false; int eacolumn = 0; int eamode = 0; diff --git a/src/loadtrk.h b/src/loadtrk.h index c4749aa..cd02779 100644 --- a/src/loadtrk.h +++ b/src/loadtrk.h @@ -50,8 +50,6 @@ extern int editmode; extern bool recordmode; extern bool followplay; extern int hexnybble; -extern int cursorflash; -extern int cursorcolortable[]; extern bool exitprogram; extern int eacolumn; extern int eamode;