aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl Heuer1995-12-13 02:22:47 +0000
committerKarl Heuer1995-12-13 02:22:47 +0000
commitc9adab2527a57f9d2ca4bc85bffe2c92f368c22f (patch)
treef1ae935de9775342775f50fd47caac80410a0b03
parent7e34da22f006fec1a9b6b4bec0bce4824349feb3 (diff)
downloademacs-c9adab2527a57f9d2ca4bc85bffe2c92f368c22f.tar.gz
emacs-c9adab2527a57f9d2ca4bc85bffe2c92f368c22f.zip
(IT_set_terminal_modes): Save screen color attribute
byte at startup, write saved screen dimensions to termscript file. (IT_reset_terminal_modes): When restoring startup screen contents, only restore as much as was saved, and only as much as the screen dimensions on exit can hold. Blank the rest with the background color saved at startup. Write restored screen dimensions to termscript file.
-rw-r--r--src/msdos.c55
1 files changed, 50 insertions, 5 deletions
diff --git a/src/msdos.c b/src/msdos.c
index 4d3c4028117..cff45ca3f94 100644
--- a/src/msdos.c
+++ b/src/msdos.c
@@ -249,6 +249,7 @@ static int startup_screen_size_X;
249static int startup_screen_size_Y; 249static int startup_screen_size_Y;
250static int startup_pos_X; 250static int startup_pos_X;
251static int startup_pos_Y; 251static int startup_pos_Y;
252static unsigned char startup_screen_attrib;
252 253
253static int term_setup_done; 254static int term_setup_done;
254 255
@@ -554,12 +555,14 @@ IT_set_terminal_modes (void)
554 555
555 startup_screen_size_X = screen_size_X; 556 startup_screen_size_X = screen_size_X;
556 startup_screen_size_Y = screen_size_Y; 557 startup_screen_size_Y = screen_size_Y;
558 startup_screen_attrib = ScreenAttrib;
557 559
558 ScreenGetCursor (&startup_pos_Y, &startup_pos_X); 560 ScreenGetCursor (&startup_pos_Y, &startup_pos_X);
559 ScreenRetrieve (startup_screen_buffer = xmalloc (screen_size * 2)); 561 ScreenRetrieve (startup_screen_buffer = xmalloc (screen_size * 2));
560 562
561 if (termscript) 563 if (termscript)
562 fprintf (termscript, "<SCREEN SAVED>\n"); 564 fprintf (termscript, "<SCREEN SAVED (dimensions=%dx%d)>\n",
565 screen_size_X, screen_size_Y);
563} 566}
564 567
565/* 568/*
@@ -570,6 +573,15 @@ IT_set_terminal_modes (void)
570static 573static
571IT_reset_terminal_modes (void) 574IT_reset_terminal_modes (void)
572{ 575{
576 int display_row_start = (int) ScreenPrimary;
577 int saved_row_len = startup_screen_size_X * 2;
578 int update_row_len = ScreenCols () * 2;
579 int current_rows = ScreenRows ();
580 int to_next_row = update_row_len;
581 unsigned char *saved_row = startup_screen_buffer;
582 int cursor_pos_X = ScreenCols () - 1;
583 int cursor_pos_Y = ScreenRows () - 1;
584
573 if (termscript) 585 if (termscript)
574 fprintf (termscript, "\n<RESET_TERM>"); 586 fprintf (termscript, "\n<RESET_TERM>");
575 587
@@ -578,12 +590,45 @@ IT_reset_terminal_modes (void)
578 if (!term_setup_done) 590 if (!term_setup_done)
579 return; 591 return;
580 592
581 ScreenUpdate (startup_screen_buffer); 593 mouse_off ();
582 ScreenSetCursor (startup_pos_Y, startup_pos_X); 594
583 xfree (startup_screen_buffer); 595 /* We have a situation here.
596 We cannot just do ScreenUpdate(startup_screen_buffer) because
597 the luser could have changed screen dimensions inside Emacs
598 and failed (or didn't want) to restore them before killing
599 Emacs. ScreenUpdate() uses the *current* screen dimensions and
600 thus will happily use memory outside what was allocated for
601 `startup_screen_buffer'.
602 Thus we only restore as much as the current screen dimensions
603 can hold, and clear the rest (if the saved screen is smaller than
604 the current) with the color attribute saved at startup. The cursor
605 is also restored within the visible dimensions. */
606
607 ScreenAttrib = startup_screen_attrib;
608 ScreenClear ();
609
610 if (update_row_len > saved_row_len)
611 update_row_len = saved_row_len;
612 if (current_rows > startup_screen_size_Y)
613 current_rows = startup_screen_size_Y;
584 614
585 if (termscript) 615 if (termscript)
586 fprintf (termscript, "<SCREEN RESTORED>\n"); 616 fprintf (termscript, "<SCREEN RESTORED (dimensions=%dx%d)>\n",
617 update_row_len / 2, current_rows);
618
619 while (current_rows--)
620 {
621 dosmemput (saved_row, update_row_len, display_row_start);
622 saved_row += saved_row_len;
623 display_row_start += to_next_row;
624 }
625 if (startup_pos_X < cursor_pos_X)
626 cursor_pos_X = startup_pos_X;
627 if (startup_pos_Y < cursor_pos_Y)
628 cursor_pos_Y = startup_pos_Y;
629
630 ScreenSetCursor (cursor_pos_Y, cursor_pos_X);
631 xfree (startup_screen_buffer);
587 632
588 term_setup_done = 0; 633 term_setup_done = 0;
589} 634}