Skip to content

Commit

Permalink
GLK: FROTZ: Improved setup and handling of fg/bg colors
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Feb 16, 2019
1 parent f4fa6ef commit 25b0665
Show file tree
Hide file tree
Showing 10 changed files with 242 additions and 110 deletions.
14 changes: 11 additions & 3 deletions engines/glk/frotz/config.cpp
Expand Up @@ -145,7 +145,12 @@ void Header::loadHeader(Common::SeekableReadStream &f) {

/*--------------------------------------------------------------------------*/

UserOptions::UserOptions() : _undo_slots(MAX_UNDO_SLOTS), _sound(true), _quetzal(true) {
UserOptions::UserOptions() : _undo_slots(MAX_UNDO_SLOTS), _sound(true), _quetzal(true), _color_enabled(false),
_err_report_mode(ERR_REPORT_ONCE), _ignore_errors(false), _expand_abbreviations(false), _tandyBit(false),
_piracy(false), _script_cols(0), _left_margin(0), _right_margin(0) {
}

void UserOptions::initialize(uint hVersion) {
_err_report_mode = getConfigInt("err_report_mode", ERR_REPORT_ONCE, ERR_REPORT_FATAL);
_ignore_errors = getConfigBool("ignore_errors");
_expand_abbreviations = getConfigBool("expand_abbreviations");
Expand All @@ -161,8 +166,11 @@ UserOptions::UserOptions() : _undo_slots(MAX_UNDO_SLOTS), _sound(true), _quetzal
_object_locating = getConfigBool("object_locating");
_object_movement = getConfigBool("object_movement");

_defaultForeground = getConfigInt("foreground", 0xffffff, 0xffffff);
_defaultBackground = getConfigInt("background", 0x000080, 0xffffff);
int defaultFg = hVersion == V6 ? 0 : 0xffffff;
int defaultBg = hVersion == V6 ? 0xffffff : 0;

_defaultForeground = getConfigInt("foreground", defaultFg, 0xffffff);
_defaultBackground = getConfigInt("background", defaultBg, 0xffffff);
}

bool UserOptions::isInfocom() const {
Expand Down
10 changes: 8 additions & 2 deletions engines/glk/frotz/config.h
Expand Up @@ -148,14 +148,20 @@ struct UserOptions {
int _undo_slots;
int _script_cols;
int _err_report_mode;
uint _defaultForeground;
uint _defaultBackground;
int _defaultForeground;
int _defaultBackground;
bool _color_enabled;

/**
* Constructor
*/
UserOptions();

/**
* Initializes the options
*/
void initialize(uint hVersion);

/**
* Returns true if the game being played is one of the original Infocom releases
*/
Expand Down
99 changes: 87 additions & 12 deletions engines/glk/frotz/glk_interface.cpp
Expand Up @@ -33,13 +33,14 @@ namespace Frotz {

GlkInterface::GlkInterface(OSystem *syst, const GlkGameDescription &gameDesc) :
GlkAPI(syst, gameDesc),
_pics(nullptr), oldstyle(0), curstyle(0), cury(1), curx(1), fixforced(0),
curr_fg(zcolor_Current), curr_bg(zcolor_Current), curr_font(1), prev_font(1), temp_font(0),
_pics(nullptr), oldstyle(0), curstyle(0), cury(1), curx(1), curr_font(1), prev_font(1), temp_font(0),
curr_status_ht(0), mach_status_ht(0), gos_status(nullptr), gos_curwin(nullptr), gos_linepending(0),
gos_linebuf(nullptr), gos_linewin(nullptr), gos_channel(nullptr), cwin(0), mwin(0), mouse_x(0), mouse_y(0),
menu_selected(0), enable_wrapping(false), enable_scripting(false), enable_scrolling(false),
enable_buffering(false), next_sample(0), next_volume(0), _soundLocked(false), _soundPlaying(false) {
fixforced(0), menu_selected(0), enable_wrapping(false), enable_scripting(false), enable_scrolling(false),
enable_buffering(false), next_sample(0), next_volume(0), _soundLocked(false), _soundPlaying(false),
_reverseVideo(false) {
Common::fill(&statusline[0], &statusline[256], '\0');
Common::fill(&zcolors[0], &zcolors[zcolor_NUMCOLORS], 0);
}

GlkInterface::~GlkInterface() {
Expand All @@ -49,6 +50,29 @@ GlkInterface::~GlkInterface() {
void GlkInterface::initialize() {
uint width, height;

/* Setup options */
UserOptions::initialize(h_version);

/* Setup colors array */
const int COLOR_MAP[zcolor_NUMCOLORS - 2] = {
0x0000, ///< 2 = black
0x001D, ///< 3 = red
0x0340, ///< 4 = green
0x03BD, ///< 5 = yellow
0x59A0, ///< 6 = blue
0x7C1F, ///< 7 = magenta
0x77A0, ///< 8 = cyan
0x7FFF, ///< 9 = white
0x5AD6, ///< 10 = light grey
0x4631, ///< 11 = medium grey
0x2D6B, ///< 12 = dark grey
};

zcolors[0] = -2; // Current
zcolors[1] = -1; // Default
for (int i = 2; i < zcolor_NUMCOLORS; ++i)
zcolors[i] = zRGB(COLOR_MAP[i - 2]);

/*
* Init glk stuff
*/
Expand Down Expand Up @@ -134,11 +158,27 @@ void GlkInterface::initialize() {
h_interpreter_number = h_version == 6 ? INTERP_MSDOS : INTERP_AMIGA;
h_interpreter_version = 'F';

// Set these per spec 8.3.2.
h_default_foreground = WHITE_COLOUR;
h_default_background = BLACK_COLOUR;
if (h_flags & COLOUR_FLAG)
h_flags &= ~COLOUR_FLAG;
// Set up the foreground & background
_color_enabled = ((h_version >= 5) && (h_flags & COLOUR_FLAG))
|| (_defaultForeground != -1) || (_defaultBackground != -1);

if (_color_enabled) {
h_config |= CONFIG_COLOUR;
h_flags |= COLOUR_FLAG; // FIXME: beyond zork handling?

assert(_defaultForeground != -1 && _defaultBackground != -1);
h_default_foreground = BLACK_COLOUR;
h_default_background = WHITE_COLOUR;
zcolors[h_default_foreground] = _defaultForeground;
zcolors[h_default_background] = _defaultBackground;
} else {
// Set these per spec 8.3.2.
h_default_foreground = WHITE_COLOUR;
h_default_background = BLACK_COLOUR;

if (h_flags & COLOUR_FLAG)
h_flags &= ~COLOUR_FLAG;
}

/*
* Open the windows
Expand All @@ -147,6 +187,11 @@ void GlkInterface::initialize() {
showBeyondZorkTitle();

_wp.setup(h_version == 6);
for (uint i = 0; i < _wp.size(); ++i) {
_wp[i][TRUE_FG_COLOR] = zcolors[h_default_foreground];
_wp[i][TRUE_BG_COLOR] = zcolors[h_default_background];
}

cwin = 0;
gos_curwin = _wp._lower;

Expand Down Expand Up @@ -366,9 +411,7 @@ void GlkInterface::erase_window(zword w) {
if (w == 0)
glk_window_clear(_wp._lower);
else if (_wp._upper) {
#ifdef GARGLK
garglk_set_reversevideo_stream(glk_window_get_stream(_wp._upper), true);
#endif /* GARGLK */
//os_set_reverse_video(glk_window_get_stream(_wp._upper), true);

memset(statusline, ' ', sizeof statusline);
glk_window_clear(_wp._upper);
Expand Down Expand Up @@ -512,6 +555,31 @@ void GlkInterface::os_draw_picture(int picture, const Common::Rect &r) {
r.width() * cell.x, r.height() * cell.y);
}

int GlkInterface::os_peek_color() {
if (_color_enabled) {
return _defaultBackground;
} else {
return (_reverseVideo) ? h_default_foreground : h_default_background;
}
/*
if (u_setup.color_enabled) {
#ifdef COLOR_SUPPORT
short fg, bg;
pair_content(PAIR_NUMBER(inch() & A_COLOR), &fg, &bg);
switch(bg) {
case COLOR_BLACK: return BLACK_COLOUR;
case COLOR_RED: return RED_COLOUR;
case COLOR_GREEN: return GREEN_COLOUR;
case COLOR_YELLOW: return YELLOW_COLOUR;
case COLOR_BLUE: return BLUE_COLOUR;
case COLOR_MAGENTA: return MAGENTA_COLOUR;
case COLOR_CYAN: return CYAN_COLOUR;
case COLOR_WHITE: return WHITE_COLOUR;
}
return 0;
#endif /* COLOR_SUPPORT */
}

zchar GlkInterface::os_read_key(int timeout, bool show_cursor) {
event_t ev;
winid_t win = gos_curwin ? gos_curwin : _wp._lower;
Expand Down Expand Up @@ -622,5 +690,12 @@ uint GlkInterface::roundDiv(uint x, uint y) {
return quotient;
}

void GlkInterface::os_set_reverse_video(bool flag) {
#ifdef GARGLK
_reverseVideo = flag;
garglk_set_reversevideo(flag);
#endif
}

} // End of namespace Frotz
} // End of namespace Glk
21 changes: 20 additions & 1 deletion engines/glk/frotz/glk_interface.h
Expand Up @@ -30,6 +30,12 @@
namespace Glk {
namespace Frotz {

#define zB(i) ((((i >> 10) & 0x1F) << 3) | (((i >> 10) & 0x1F) >> 2))
#define zG(i) ((((i >> 5) & 0x1F) << 3) | (((i >> 5) & 0x1F) >> 2))
#define zR(i) ((((i ) & 0x1F) << 3) | (((i ) & 0x1F) >> 2))
#define zRGB(i) _screen->format.RGBToColor(zR(i), zG(i), zB(i))
#define zcolor_NUMCOLORS (13)

enum SoundEffect {
EFFECT_PREPARE = 1,
EFFECT_PLAY = 2,
Expand All @@ -50,16 +56,18 @@ class Pics;
* and sound effect handling
*/
class GlkInterface : public GlkAPI, public virtual UserOptions, public virtual Mem {
private:
bool _reverseVideo;
public:
Pics *_pics;
zchar statusline[256];
int zcolors[zcolor_NUMCOLORS];
int oldstyle;
int curstyle;
int cury;
int curx;
int fixforced;

uint curr_fg, curr_bg;
int curr_font;
int prev_font;
int temp_font;
Expand Down Expand Up @@ -182,6 +190,12 @@ class GlkInterface : public GlkAPI, public virtual UserOptions, public virtual M
*/
void os_draw_picture(int picture, const Common::Rect &r);

/**
* Return the colour of the pixel below the cursor. This is used by V6 games to print
* text on top of pictures. The coulor need not be in the standard set of Z-machine colours.
*/
int os_peek_color();

/**
* Call the IO interface to play a sample.
*/
Expand Down Expand Up @@ -238,6 +252,11 @@ class GlkInterface : public GlkAPI, public virtual UserOptions, public virtual M
* Waits for the user to type an input line
*/
zchar os_read_line(int max, zchar *buf, int timeout, int width, int continued);

/**
* Set whether reverse video mode is active
*/
void os_set_reverse_video(bool flag);
public:
/**
* Constructor
Expand Down
10 changes: 10 additions & 0 deletions engines/glk/frotz/processor.h
Expand Up @@ -346,6 +346,16 @@ class Processor : public GlkInterface, public virtual Mem {
*/
void screen_word(const zchar *s);

/**
* Erase the entire screen to background colour.
*/
void erase_screen(zword win);

/**
* Erase a window to background colour.
*/
void erase_window(zword win);

/**@}*/

/**
Expand Down

0 comments on commit 25b0665

Please sign in to comment.