Skip to content

Commit edbb67d

Browse files
committed
ENH: separate buffer for upper (status line) and lower screen
1 parent 2010622 commit edbb67d

File tree

4 files changed

+97
-21
lines changed

4 files changed

+97
-21
lines changed

frotz/src/dumb/dumb_frotz.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ void dumb_set_picture_cell(int row, int col, char c);
4444
void dumb_row_to_str(char *s);
4545
void dumb_clear_output(void);
4646
char* dumb_get_screen(void);
47+
char* dumb_get_lower_screen(void);
4748
void dumb_clear_screen(void);
4849

4950
/* dumb-pic.c */

frotz/src/dumb/dumb_output.c

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ static cell make_cell(int style, char c) {return (style << 8) | (0xff & c);}
5050
static char cell_char(cell c) {return c & 0xff;}
5151
static int cell_style(cell c) {return c >> 8;}
5252

53+
#define UPPER_SCREEN_BUFF_SIZE 256
5354
#define SCREEN_BUFF_SIZE 8192
54-
static char screen_buffer[SCREEN_BUFF_SIZE];
55+
static char screen_buffer[SCREEN_BUFF_SIZE]; // aka window 0 (lower screen)
56+
static char upper_screen_buffer[UPPER_SCREEN_BUFF_SIZE]; // aka window 1 (upper screen)
57+
5558
char* screen_buffer_ptr = screen_buffer;
59+
char* upper_screen_buffer_ptr = upper_screen_buffer;
5660

5761
/* A cell's style is REVERSE_STYLE, normal (0), or PICTURE_STYLE.
5862
* PICTURE_STYLE means the character is part of an ascii image outline
@@ -114,7 +118,12 @@ int os_string_width (const zchar *s)
114118

115119
void os_set_cursor(int row, int col)
116120
{
117-
cursor_row = row - 1; cursor_col = col - 1;
121+
//printf("\n--> win:%d\trow:%d\tcol:%d MAX_COLS:%d<--\n", cwin, row, col, h_screen_cols);
122+
if (cwin == 1 && row == 1) {
123+
upper_screen_buffer_ptr = upper_screen_buffer + (col-1);
124+
}
125+
126+
cursor_row = row - 1; cursor_col = col - 1; // 0-index
118127
if (cursor_row >= h_screen_rows)
119128
cursor_row = h_screen_rows - 1;
120129
}
@@ -148,9 +157,16 @@ void os_set_text_style(int x)
148157
/* put a character in the cell at the cursor and advance the cursor. */
149158
static void dumb_display_char(char c)
150159
{
151-
if ((screen_buffer_ptr - screen_buffer) < (SCREEN_BUFF_SIZE - 1)) {
152-
*screen_buffer_ptr++ = c;
153-
}
160+
if (cwin == 1 && cursor_row == 0) {
161+
if ((upper_screen_buffer_ptr - upper_screen_buffer) < (UPPER_SCREEN_BUFF_SIZE - 1)) {
162+
*upper_screen_buffer_ptr++ = c;
163+
}
164+
}
165+
else {
166+
if ((screen_buffer_ptr - screen_buffer) < (SCREEN_BUFF_SIZE - 1)) {
167+
*screen_buffer_ptr++ = c;
168+
}
169+
}
154170
}
155171

156172
void dumb_display_user_input(char *s)
@@ -210,7 +226,7 @@ void os_display_string (const zchar *s)
210226
}
211227
}
212228

213-
void os_erase_area (int top, int left, int bottom, int right, int UNUSED (win))
229+
void os_erase_area (int top, int left, int bottom, int right, int win)
214230
{
215231
int row, col;
216232
top--; left--; bottom--; right--;
@@ -222,9 +238,16 @@ void os_erase_area (int top, int left, int bottom, int right, int UNUSED (win))
222238

223239
void os_scroll_area (int top, int left, int bottom, int right, int units)
224240
{
225-
if ((screen_buffer_ptr - screen_buffer) < (SCREEN_BUFF_SIZE - 1)) {
226-
*screen_buffer_ptr++ = '\n';
227-
}
241+
if (cwin == 1) {
242+
if ((upper_screen_buffer_ptr - upper_screen_buffer) < (UPPER_SCREEN_BUFF_SIZE - 1)) {
243+
*upper_screen_buffer_ptr++ = '\n';
244+
}
245+
}
246+
else {
247+
if ((screen_buffer_ptr - screen_buffer) < (SCREEN_BUFF_SIZE - 1)) {
248+
*screen_buffer_ptr++ = '\n';
249+
}
250+
}
228251
}
229252

230253
int os_font_data(int font, int *height, int *width)
@@ -557,6 +580,26 @@ void dumb_clear_screen(void) {
557580
screen_buffer_ptr = screen_buffer;
558581
}
559582

583+
584+
char* dumb_get_lower_screen(void) {
585+
*screen_buffer_ptr = '\0';
586+
return screen_buffer;
587+
}
588+
589+
void dumb_clear_lower_screen(void) {
590+
screen_buffer_ptr = screen_buffer;
591+
}
592+
593+
char* dumb_get_upper_screen(void) {
594+
upper_screen_buffer[UPPER_SCREEN_BUFF_SIZE-1] = '\0';
595+
// *upper_screen_buffer_ptr = '\0';
596+
return upper_screen_buffer;
597+
}
598+
599+
void dumb_clear_upper_screen(void) {
600+
upper_screen_buffer_ptr = upper_screen_buffer;
601+
}
602+
560603
void dumb_free(void) {
561604
if (screen_data) {
562605
free(screen_data);

frotz/src/interface/frotz_interface.c

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ extern void dumb_set_next_action (char *a);
3737
extern void dumb_show_screen (int a);
3838
extern char* dumb_get_screen(void);
3939
extern void dumb_clear_screen(void);
40+
extern char* dumb_get_lower_screen(void);
41+
extern void dumb_clear_lower_screen(void);
42+
extern char* dumb_get_upper_screen(void);
43+
extern void dumb_clear_upper_screen(void);
4044
extern void z_save (void);
4145
extern void load_story(char *s);
4246
extern void load_story_rom(char *s, void* rom, size_t rom_size);
@@ -72,7 +76,11 @@ zbyte next_opcode;
7276
int last_ret_pc = -1;
7377
int desired_seed = 0;
7478
int ROM_IDX = 0;
75-
char world[8192] = "";
79+
80+
char upper_screen[256] = "";
81+
char lower_screen[8192] = "";
82+
char world[256 + 8192] = ""; // Upper + lower screens.
83+
7684
int emulator_halted = 0;
7785
char halted_message[] = "Emulator halted due to runtime error.\n";
7886
// Track the addresses and values of special per-game ram locations.
@@ -1427,10 +1435,10 @@ void take_intro_actions() {
14271435

14281436
char* text;
14291437
for (int i=0; i<num_actions; ++i) {
1430-
text = dumb_get_screen();
1438+
text = dumb_get_lower_screen();
14311439
text = clean_observation(text);
1432-
strcat(world, text);
1433-
dumb_clear_screen();
1440+
strcat(lower_screen, text);
1441+
dumb_clear_lower_screen();
14341442

14351443
dumb_set_next_action(intro_actions[i]);
14361444
zstep();
@@ -1533,7 +1541,7 @@ char* setup(char *story_file, int seed, void *rom, size_t rom_size) {
15331541
run_free();
15341542
load_rom_bindings(story_file);
15351543

1536-
world[0] = '\0'; // Clear buffer.
1544+
lower_screen[0] = '\0'; // Clear lower screen buffer.
15371545
take_intro_actions();
15381546
init_special_ram();
15391547

@@ -1568,11 +1576,24 @@ char* setup(char *story_file, int seed, void *rom, size_t rom_size) {
15681576
// get_world_state_hash(last_state_hash);
15691577
// get_world_state_hash(current_state_hash);
15701578

1571-
text = dumb_get_screen();
1579+
text = dumb_get_lower_screen();
1580+
strcat(text, dumb_get_upper_screen());
15721581
text = clean_observation(text);
1573-
// strcpy(world, text);
1574-
strcat(world, text);
1575-
dumb_clear_screen();
1582+
// strcat(lower_screen, text);
1583+
dumb_clear_lower_screen();
1584+
1585+
// text = dumb_get_upper_screen();
1586+
// strcpy(upper_screen, text);
1587+
dumb_clear_upper_screen();
1588+
1589+
1590+
// Concatenate upper and lower screens.
1591+
strcpy(world, text);
1592+
// strcpy(world, lower_screen);
1593+
// strcat(world, upper_screen);
1594+
// strcpy(world, upper_screen);
1595+
// strcat(world, "\n");
1596+
15761597
return world;
15771598
}
15781599

@@ -1627,10 +1648,19 @@ char* step(char *next_action) {
16271648
state_has_changed = memcmp(old_objs, new_objs, (get_num_world_objs() + 1) * sizeof(zobject)) != 0;
16281649
// printf("%s =(%d)= %s <== %s", current_state_hash, state_has_changed, last_state_hash, next_action);
16291650

1630-
text = dumb_get_screen();
1651+
// Retrieve and concatenate upper and lower screens.
1652+
text = dumb_get_lower_screen();
1653+
strcat(text, dumb_get_upper_screen());
16311654
text = clean_observation(text);
16321655
strcpy(world, text);
1633-
dumb_clear_screen();
1656+
dumb_clear_lower_screen();
1657+
1658+
// text = dumb_get_upper_screen();
1659+
// strcat(world, text);
1660+
// // strcpy(world, text);
1661+
// // strcat(world, "\n");
1662+
dumb_clear_upper_screen();
1663+
16341664
return world;
16351665
}
16361666

frotz/src/interface/frotz_interface.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ extern void getRAM(unsigned char *ram);
5353

5454
int filter_candidate_actions(char *candidate_actions, char *valid_actions, zword *diff_array);
5555

56-
extern char world[8192];
56+
extern char upper_screen[256];
57+
extern char lower_screen[8192];
58+
extern char world[256 + 8192];
5759

5860
extern int tw_max_score;
5961

0 commit comments

Comments
 (0)