--- previous/src/statusbar.c 2018/04/24 19:25:10 1.1 +++ previous/src/statusbar.c 2018/04/24 19:31:08 1.1.1.5 @@ -24,22 +24,17 @@ hiding the overlay drive led when drive leds are turned OFF. - If other information shown by Statusbar (TOS version etc) changes, call Statusbar_UpdateInfo() - - TODO: - - re-calculate colors on each update to make sure they're - correct in Falcon & TT 8-bit palette modes? - - call Statusbar_AddMessage() from log.c? */ const char Statusbar_fileid[] = "Hatari statusbar.c : " __DATE__ " " __TIME__; #include #include "main.h" #include "configuration.h" -#include "screenSnapShot.h" #include "sdlgui.h" #include "statusbar.h" +#include "screen.h" #include "video.h" -#include "avi_record.h" +#include "dimension.h" #define DEBUG 0 #if DEBUG @@ -48,15 +43,13 @@ const char Statusbar_fileid[] = "Hatari #define DEBUGPRINT(x) #endif -#define MAX_DRIVE_LEDS (DRIVE_LED_HD + 1) - /* whether drive leds should be ON and their previous shown state */ static struct { bool state; bool oldstate; Uint32 expire; /* when to disable led, valid only if >0 && state=TRUE */ int offset; /* led x-pos on screen */ -} Led[MAX_DRIVE_LEDS]; +} Led[NUM_DEVICE_LEDS]; /* drive leds size & y-pos */ static SDL_Rect LedRect; @@ -73,15 +66,21 @@ static enum { OVERLAY_RESTORED } bOverlayState; -static SDL_Rect RecLedRect; -static bool bOldRecording; +static SDL_Rect SystemLedRect; +static bool bOldSystemLed; + +static SDL_Rect DspLedRect; +static bool bOldDspLed; + +static SDL_Rect NdLedRect; +static int nOldNdLed; /* led colors */ -static Uint32 LedColorOn, LedColorOff, RecColorOn, RecColorOff; +static Uint32 LedColorOn, LedColorOnWP, LedColorOff, SysColorOn, SysColorOff, DspColorOn, DspColorOff; +static Uint32 NdColorOn, NdColorCS8, NdColorOff; static Uint32 GrayBg, LedColorBg; - -#define MAX_MESSAGE_LEN 33 +#define MAX_MESSAGE_LEN 69 /* changed for Previous, was 50 */ typedef struct msg_item { struct msg_item *next; char msg[MAX_MESSAGE_LEN+1]; @@ -94,12 +93,6 @@ static msg_item_t DefaultMessage; static msg_item_t *MessageList = &DefaultMessage; static SDL_Rect MessageRect; -/* rect for both frame skip value and fast forward indicator */ -static SDL_Rect FrameSkipsRect; -static int nOldFrameSkips; -static int bOldFastForward; - - /* screen height above statusbar and height of statusbar below screen */ static int ScreenHeight; static int StatusbarHeight; @@ -151,26 +144,32 @@ int Statusbar_GetHeight(void) /*-----------------------------------------------------------------------*/ /** - * Enable HD drive led, it will be automatically disabled after a while. + * Enable device led, it will be automatically disabled after a while. */ -void Statusbar_EnableHDLed(void) +void Statusbar_BlinkLed(drive_index_t drive) { /* leds are shown for 1/2 sec after enabling */ - Led[DRIVE_LED_HD].expire = SDL_GetTicks() + 1000/2; - Led[DRIVE_LED_HD].state = true; + Led[drive].expire = SDL_GetTicks() + 1000/2; + Led[drive].state = true; } + /*-----------------------------------------------------------------------*/ /** - * Set given floppy drive led state, anything enabling led with this - * needs also to take care of disabling it. + * Set system, DSP, CPU and NeXTdimension led state, anything enabling led with + * this needs also to take care of disabling it. */ -void Statusbar_SetFloppyLed(drive_index_t drive, bool state) -{ - assert(drive == DRIVE_LED_A || drive == DRIVE_LED_B); - Led[drive].state = state; +void Statusbar_SetSystemLed(bool state) { + bOldSystemLed = state; } +void Statusbar_SetDspLed(bool state) { + bOldDspLed = state; +} + +void Statusbar_SetNdLed(int state) { + nOldNdLed = state; +} /*-----------------------------------------------------------------------*/ /** @@ -208,20 +207,26 @@ void Statusbar_Init(SDL_Surface *surf) msg_item_t *item; SDL_Rect ledbox, sbarbox; int i, fontw, fonth, offset; - const char *text[MAX_DRIVE_LEDS] = { "A:", "B:", "HD:" }; + const char *text[NUM_DEVICE_LEDS] = { "EN:", "MO:", "SD:", "FD:" }; assert(surf); /* dark green and light green for leds themselves */ - LedColorOff = SDL_MapRGB(surf->format, 0x00, 0x40, 0x00); - LedColorOn = SDL_MapRGB(surf->format, 0x00, 0xe0, 0x00); - LedColorBg = SDL_MapRGB(surf->format, 0x00, 0x00, 0x00); - RecColorOff = SDL_MapRGB(surf->format, 0x40, 0x00, 0x00); - RecColorOn = SDL_MapRGB(surf->format, 0xe0, 0x00, 0x00); - GrayBg = SDL_MapRGB(surf->format, 0xc0, 0xc0, 0xc0); - + LedColorOff = SDL_MapRGB(surf->format, 0x00, 0x40, 0x00); + LedColorOn = SDL_MapRGB(surf->format, 0x00, 0xe0, 0x00); + LedColorOnWP = SDL_MapRGB(surf->format, 0xFF, 0xe0, 0x00); + LedColorBg = SDL_MapRGB(surf->format, 0x00, 0x00, 0x00); + SysColorOff = SDL_MapRGB(surf->format, 0x40, 0x00, 0x00); + SysColorOn = SDL_MapRGB(surf->format, 0xe0, 0x00, 0x00); + DspColorOff = SDL_MapRGB(surf->format, 0x00, 0x00, 0x40); + DspColorOn = SDL_MapRGB(surf->format, 0x00, 0x00, 0xe0); + NdColorOff = SDL_MapRGB(surf->format, 0x00, 0x00, 0x40); + NdColorCS8 = SDL_MapRGB(surf->format, 0xe0, 0x00, 0x00); + NdColorOn = SDL_MapRGB(surf->format, 0x00, 0x00, 0xe0); + GrayBg = SDL_MapRGB(surf->format, 0xb5, 0xb7, 0xaa); + /* disable leds */ - for (i = 0; i < MAX_DRIVE_LEDS; i++) { + for (i = 0; i < NUM_DEVICE_LEDS; i++) { Led[i].state = Led[i].oldstate = false; Led[i].expire = 0; } @@ -270,7 +275,7 @@ void Statusbar_Init(SDL_Surface *surf) offset = fontw; MessageRect.y = LedRect.y - 2; /* draw led texts and boxes + calculate box offsets */ - for (i = 0; i < MAX_DRIVE_LEDS; i++) { + for (i = 0; i < NUM_DEVICE_LEDS; i++) { SDLGui_Text(offset, MessageRect.y, text[i]); offset += strlen(text[i]) * fontw; offset += fontw/2; @@ -284,39 +289,39 @@ void Statusbar_Init(SDL_Surface *surf) Led[i].offset = offset; offset += LedRect.w + fontw; } - - /* draw frameskip */ - FrameSkipsRect.x = offset; - FrameSkipsRect.y = MessageRect.y; - SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, "FS:"); - FrameSkipsRect.x += 3 * fontw + fontw/2; - FrameSkipsRect.w = 4 * fontw; - FrameSkipsRect.h = fonth; - - if(ConfigureParams.System.bFastForward) { - SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, "0 >>"); - } else { - SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, "0"); - } - - nOldFrameSkips = 0; - - /* intialize messages */ - MessageRect.x = FrameSkipsRect.x + FrameSkipsRect.w + fontw; + MessageRect.x = offset + fontw; MessageRect.w = MAX_MESSAGE_LEN * fontw; MessageRect.h = fonth; for (item = MessageList; item; item = item->next) { item->shown = false; } + + /* draw i860 led box */ + NdLedRect = LedRect; + NdLedRect.x = surf->w - 15*fontw - NdLedRect.w; + ledbox.x = NdLedRect.x - 1; + SDLGui_Text(ledbox.x - 3*fontw - fontw/2, MessageRect.y, "ND:"); + SDL_FillRect(surf, &ledbox, LedColorBg); + SDL_FillRect(surf, &NdLedRect, NdColorOff); + nOldNdLed = 0; + + /* draw dsp led box */ + DspLedRect = LedRect; + DspLedRect.x = surf->w - 8*fontw - DspLedRect.w; + ledbox.x = DspLedRect.x - 1; + SDLGui_Text(ledbox.x - 4*fontw - fontw/2, MessageRect.y, "DSP:"); + SDL_FillRect(surf, &ledbox, LedColorBg); + SDL_FillRect(surf, &DspLedRect, DspColorOff); + bOldDspLed = false; - /* draw recording led box */ - RecLedRect = LedRect; - RecLedRect.x = surf->w - fontw - RecLedRect.w; - ledbox.x = RecLedRect.x - 1; - SDLGui_Text(ledbox.x - 4*fontw - fontw/2, MessageRect.y, "REC:"); + /* draw system led box */ + SystemLedRect = LedRect; + SystemLedRect.x = surf->w - fontw - SystemLedRect.w; + ledbox.x = SystemLedRect.x - 1; + SDLGui_Text(ledbox.x - 4*fontw - fontw/2, MessageRect.y, "LED:"); SDL_FillRect(surf, &ledbox, LedColorBg); - SDL_FillRect(surf, &RecLedRect, RecColorOff); - bOldRecording = false; + SDL_FillRect(surf, &SystemLedRect, SysColorOff); + bOldSystemLed = false; /* and blit statusbar on screen */ SDL_UpdateRects(surf, 1, &sbarbox); @@ -374,42 +379,72 @@ static char *Statusbar_AddString(char *b void Statusbar_UpdateInfo(void) { char *end = DefaultMessage.msg; - - /* CPU MHz */ - if (ConfigureParams.System.nCpuFreq > 9) { - *end++ = '0' + ConfigureParams.System.nCpuFreq / 10; + char memsize[8]; + + /* Message for NeXTdimension */ + if (ConfigureParams.Dimension.bEnabled && + ConfigureParams.Screen.nMonitorType==MONITOR_TYPE_DIMENSION) { + end = Statusbar_AddString(end, "33MHz/i860XR/"); + sprintf(memsize, "%iMB/",Configuration_CheckDimensionMemory(ConfigureParams.Dimension.nMemoryBankSize)); + end = Statusbar_AddString(end, memsize); + end = Statusbar_AddString(end, "NeXTdimension"); + *end = '\0'; + assert(end - DefaultMessage.msg < MAX_MESSAGE_LEN); + DefaultMessage.shown = false; + return; } - *end++ = '0' + ConfigureParams.System.nCpuFreq % 10; - end = Statusbar_AddString(end, "MHz/"); + + /* CPU MHz */ + end = Statusbar_AddString(end, Main_SpeedMsg()); /* CPU type */ if(ConfigureParams.System.nCpuLevel > 0) { + *end++ = '6'; + *end++ = '8'; *end++ = '0'; - *end++ = '0' + ConfigureParams.System.nCpuLevel % 10; + switch (ConfigureParams.System.nCpuLevel) { + case 0: *end++ = '0'; break; + case 1: *end++ = '1'; break; + case 2: *end++ = '2'; break; + case 3: *end++ = '3'; break; + case 4: *end++ = '4'; break; + case 5: *end++ = '6'; break; + default: break; + } *end++ = '0'; *end++ = '/'; } /* amount of memory */ - if (ConfigureParams.Memory.nMemorySize > 9) { - *end++ = '1'; - *end++ = '0' + ConfigureParams.Memory.nMemorySize % 10; - } else { - if (ConfigureParams.Memory.nMemorySize) { - *end++ = '0' + ConfigureParams.Memory.nMemorySize; - } else { - end = Statusbar_AddString(end, "1/2"); - } - } - end = Statusbar_AddString(end, "MB "); + sprintf(memsize, "%iMB/", Configuration_CheckMemory(ConfigureParams.Memory.nMemoryBankSize)); + end = Statusbar_AddString(end, memsize); /* machine type */ - end = Statusbar_AddString(end, "NEXT"); + switch (ConfigureParams.System.nMachineType) { + case NEXT_CUBE030: + end = Statusbar_AddString(end, "NeXT Computer"); + break; + case NEXT_CUBE040: + end = Statusbar_AddString(end, "NeXTcube"); + break; + case NEXT_STATION: + end = Statusbar_AddString(end, "NeXTstation"); + break; + + default: + break; + } + if (ConfigureParams.System.bTurbo) + end = Statusbar_AddString(end, (ConfigureParams.System.nCpuFreq==40)?" Nitro":" Turbo"); + + if (ConfigureParams.System.bColor) + end = Statusbar_AddString(end, " Color"); *end = '\0'; assert(end - DefaultMessage.msg < MAX_MESSAGE_LEN); DEBUGPRINT(("Set default message: '%s'\n", DefaultMessage.msg)); + /* make sure default message gets (re-)drawn when next checked */ DefaultMessage.shown = false; } @@ -441,7 +476,7 @@ static void Statusbar_ShowMessage(SDL_Su if (MessageList->shown) { if (!MessageList->expire) { - /* last/default message */ + /* last/default message never expires */ return; } if (MessageList->expire > ticks) { @@ -544,13 +579,13 @@ static void Statusbar_OverlayDraw(SDL_Su int i; assert(surf); - for (i = 0; i < MAX_DRIVE_LEDS; i++) { + for (i = 0; i < NUM_DEVICE_LEDS; i++) { if (Led[i].state) { if (Led[i].expire && Led[i].expire < currentticks) { Led[i].state = false; continue; } - Statusbar_OverlayDrawLed(surf, LedColorOn); + Statusbar_OverlayDrawLed(surf, ConfigureParams.SCSI.nWriteProtection == WRITEPROT_ON && i == DEVICE_LED_SCSI ? LedColorOnWP : LedColorOn); break; } } @@ -577,8 +612,7 @@ static void Statusbar_OverlayDraw(SDL_Su * * May not be called when screen is locked (SDL limitation). */ -void Statusbar_Update(SDL_Surface *surf) -{ +void Statusbar_Update(SDL_Surface *surf) { Uint32 color, currentticks; SDL_Rect rect; int i; @@ -596,7 +630,7 @@ void Statusbar_Update(SDL_Surface *surf) rect = LedRect; currentticks = SDL_GetTicks(); - for (i = 0; i < MAX_DRIVE_LEDS; i++) { + for (i = 0; i < NUM_DEVICE_LEDS; i++) { if (Led[i].expire && Led[i].expire < currentticks) { Led[i].state = false; } @@ -605,17 +639,42 @@ void Statusbar_Update(SDL_Surface *surf) } Led[i].oldstate = Led[i].state; if (Led[i].state) { - color = LedColorOn; + color = ConfigureParams.SCSI.nWriteProtection == WRITEPROT_ON && i == DEVICE_LED_SCSI ? LedColorOnWP : LedColorOn; } else { color = LedColorOff; } rect.x = Led[i].offset; SDL_FillRect(surf, &rect, color); SDL_UpdateRects(surf, 1, &rect); - DEBUGPRINT(("LED[%d] = %s\n", i, Led[i].state?"ON":"OFF")); } Statusbar_ShowMessage(surf, currentticks); + /* Draw dsp LED */ + if (bOldDspLed) { + color = DspColorOn; + } else { + color = DspColorOff; + } + SDL_FillRect(surf, &DspLedRect, color); + SDL_UpdateRects(surf, 1, &DspLedRect); + /* Draw scr2 LED */ + if (bOldSystemLed) { + color = SysColorOn; + } else { + color = SysColorOff; + } + SDL_FillRect(surf, &SystemLedRect, color); + SDL_UpdateRects(surf, 1, &SystemLedRect); + + /* Draw NeXTdimension LED */ + switch(nOldNdLed) { + case 0: color = NdColorOff; break; + case 1: color = NdColorCS8; break; + case 2: color = NdColorOn; break; + default: color = NdColorOff; break; + } + SDL_FillRect(surf, &NdLedRect, color); + SDL_UpdateRects(surf, 1, &NdLedRect); }