VOGONS


First post, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

A problem that seems to be in SDL causes a problem with DOSBox under OS X: if you minimize DOSBox, and then restore it, the color palette changes. The quickest way I've found to fix this problem when it occurs is to run the Mapper and immediately exit the mapper. This redraws the whole screen, and the colors are correct again.

Is it possible to add a few lines of code to a project so that the screen could be fully redrawn with a shortcut key, like the other keys that you can add via the mapper?

Or is it possible to add code that would open the mapper, and then immediately exit the mapper, to do the same thing? I've experimented with this, without success.

I think this might be useful feature to have in DOSBox. I'll be grateful for any help from anyone who knows how to code this kind of thing.

(Of course, it would be best if the screen got redrawn whenever the DOSBox window was restored after being minimized, but I suppose that would be a lot more complicated.)

Reply 1 of 11, by truth_deleted

User metadata
emendelson wrote:

(Of course, it would be best if the screen got redrawn whenever the DOSBox window was restored after being minimized, but I suppose that would be a lot more complicated.)

The "restore window event" may be a detectable event in the SDL OSX driver and set to reset the screen. However, in dosbox, you could bind a key to the GFX_ResetScreen function. That may fix the palette problem and it is called when you exit the mapper program.

Reply 2 of 11, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
truth5678 wrote:
emendelson wrote:

(Of course, it would be best if the screen got redrawn whenever the DOSBox window was restored after being minimized, but I suppose that would be a lot more complicated.)

The "restore window event" may be a detectable event in the SDL OSX driver and set to reset the screen. However, in dosbox, you could bind a key to the GFX_ResetScreen function. That may fix the palette problem and it is called when you exit the mapper program.

Thank you for this. If I knew more, I could probably follow this suggestion, but this is as far as I got:

1. I added this line to sdlmain.cpp:

 MAPPER_AddHandler(GFX_ResetScreen,MK_f3,MMOD1|MMOD2,"redraw","Redraw Screen");

2. When I compiled in OS X, I got these errors that don't appear if that line is absent:

sdlmain.cpp: In function ‘void GUI_StartUp(Section*)’:
sdlmain.cpp:1348: error: invalid conversion from ‘void (*)()’ to ‘void (*)(bool)’
sdlmain.cpp:1348: error: initializing argument 1 of ‘void MAPPER_AddHandler(void (*)(bool), MapKeys, Bitu, const char*, const char*)’
...
make[3]: *** [sdlmain.o] Error 1

Where the "..." is in the above, these errors also appear, but they appear in a successful build also:

sdlmain.cpp: In function ‘void show_warning(const char*)’:
sdlmain.cpp:1655: warning: format not a string literal and no format arguments
sdlmain.cpp:1655: warning: format not a string literal and no format arguments

What obvious thing am I doing incorrectly here? Apologies for coming back for more help after you provided help already!

Reply 3 of 11, by truth_deleted

User metadata

Try the attached patch against DOSBox SVN; or copy the lines which start with "+" to sdl_mapper.cpp.

Reply 4 of 11, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

That's perfect! Works beautifully. Thank you!

I hope the devs might consider adding this to SVN. It's clearly useful for games, and really needed under OS X - until someone figures out how to make the same thing happen automatically when DOSBox gets restored after being minimized.

Thank you again!

Reply 5 of 11, by truth_deleted

User metadata

Glad it worked! 😀

Two lines in that patch may fix the other issue on switching from text to graphics mode in OSX:
KEYBOARD_ClrBuffer();
GFX_LosingFocus();

Those lines will clear the keyboard buffer and may prevent the repeating keypresses on changing OSX resolution (text -> graphics). I recall there is a function (perhaps in sdlmain) for changing graphics resolution, those two lines could be added there along with defining the code block as OSX only.

Reply 6 of 11, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

The closest thing I could find that fits your description in sdlmain.cpp was this:

case SDL_VIDEORESIZE:
// HandleVideoResize(&event.resize);
break;

Because I don't know any better, I simply inserted the two lines that you suggested, between the commented line and "break", but I didn't see any consistent effect. My guess is that I need a block that begins something like:

static void HandleVideoResize

but I haven't the faintest idea of how to write it. Am I at least looking in the right direction? If this problem could be solved, it would eliminate the last serious annoyances in DOSBox under OS X.

Again, I can't thank you enough for the trouble you've taken over this.

Reply 8 of 11, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

or the focus gain/loss function

Water flows down the stream
How to ask questions the smart way!

Reply 9 of 11, by truth_deleted

User metadata

Thanks, Qbix!

void GFX_LosingFocus(void) {
+ KEYBOARD_ClrBuffer();

Just in case, here is the 2nd option:

Bitu GFX_SetSize(Bitu width,Bitu height,Bitu flags,double scalex,double scaley,GFX_CallBack_t callback) {
+ KEYBOARD_ClrBuffer();
+ GFX_LosingFocus();

Reply 10 of 11, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
truth5678 wrote:
Just in case, here is the 2nd option: […]
Show full quote

Just in case, here is the 2nd option:

Bitu GFX_SetSize(Bitu width,Bitu height,Bitu flags,double scalex,double scaley,GFX_CallBack_t callback) {
+ KEYBOARD_ClrBuffer();
+ GFX_LosingFocus();

This one solved it! (The other one seems to have produced the same results I saw earlier, repeated keys.) At least I haven't seen the problem in my first tests, but I'll continue testing it.

Incidentally, the symptom of the problem (now solved, apparently) is that the repeated characters do NOT occur the first time I shift from text to graphics, and rarely occurs when I switch from graphics back to text, but always occurs when I switch from text to graphics, or switch between different graphic modes, after the first time.

If this fix doesn't cause any other problems, I hope it might go into SVN. The problem has been discussed more than once on the forum and would seem to apply to games.

Again, thank you!

Reply 11 of 11, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

In the hope of avoiding the problem of changing colors (after restoring DOSBox from being minimized, in OS X), I looked around the SDL docs, and found that the "videoresize" event in SDL occurs when the window has been changed by the window manager and needs to be rewritten.

I wonder if this might point to a solution of the color-changing problem? I tried adding some lines of code from your RedrawScreen.diff file to sdlmain.cpp, underneath "case SDL_VIDEORESIZE", but of course it didn't work because your patch works only in sdl_mapper.cpp.

But is it possible to adapt that code to work in sdlmain.cpp? That might do away with this problem forever.