scrdump.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* $Id: scrdump.c,v 1.4 1999/02/16 05:45:41 mental Exp $
  2. * MegaZeux
  3. *
  4. * Copyright (C) 1996 Greg Janson
  5. * Copyright (C) 1998 Matthew D. Williams - dbwilli@scsn.net
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <stdlib.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <io.h>
  25. #include <dos.h>
  26. #include "const.h"
  27. #include "data.h"
  28. #include "egacode.h"
  29. #include "palette.h"
  30. #include "scrdump.h"
  31. //static volatile char rcsid[] = "$Id: scrdump.c,v 1.4 1999/02/16 05:45:41 mental Exp $";
  32. /* FIXME: not endian-safe */
  33. void dump_screen() {
  34. char fname[11];
  35. FILE *fp;
  36. int t1, t2, t3, t4, t5, t7, t8, snum;
  37. unsigned char *scrn = (unsigned char*)MK_FP(current_pg_seg,0);
  38. char r,g,b;
  39. for (snum = 0;snum <= 99;snum++) {
  40. sprintf(fname,"screen%d.pcx",snum);
  41. //break;
  42. if (!(access(fname,0) == 0)) break;
  43. }
  44. fp=fopen(fname,"wb");
  45. //header
  46. fputc(10,fp);
  47. fputc(5,fp);
  48. fputc(1,fp);
  49. fputc(1,fp);
  50. t1=0; fwrite(&t1,1,2,fp);
  51. t1=0; fwrite(&t1,1,2,fp);
  52. t1=639; fwrite(&t1,1,2,fp);
  53. t1=349; fwrite(&t1,1,2,fp);
  54. t1=300; fwrite(&t1,1,2,fp);
  55. t1=300; fwrite(&t1,1,2,fp);
  56. //colormap
  57. for(t1=0;t1<16;t1++) {
  58. get_rgb(t1,r,g,b);
  59. fputc(r<<2,fp);
  60. fputc(g<<2,fp);
  61. fputc(b<<2,fp);
  62. }
  63. //header part 2
  64. fputc(0,fp);
  65. fputc(4,fp);
  66. t1=80; fwrite(&t1,1,2,fp);
  67. t1=1; fwrite(&t1,1,2,fp);
  68. t1=640; fwrite(&t1,1,2,fp);
  69. t1=350; fwrite(&t1,1,2,fp);
  70. for(t1=0;t1<54;t1++) fputc(0,fp);
  71. //picture
  72. for(t1=0;t1<25;t1++) {//25 rows
  73. for(t5=0;t5<14;t5++) {//14 bitmap rows per char
  74. t7=1;
  75. for(t2=0;t2<4;t2++) {//4 planes
  76. for(t3=0;t3<80;t3++) {//80 columns
  77. //Check FG color to see if applicable
  78. t4=(scrn[((t1*80+t3)<<1)+1])&t7;
  79. if(t4) {
  80. //Get character
  81. t4=scrn[(t1*80+t3)<<1];
  82. //Write character bitmap byte
  83. t8=ec_read_byte(t4,t5);
  84. }
  85. else t8=0;//Byte for this bitplane
  86. //Check BK color to see if applicable
  87. t4=((scrn[((t1*80+t3)<<1)+1])>>4)&t7;
  88. if(t4) {
  89. //Get character
  90. t4=scrn[(t1*80+t3)<<1];
  91. //Write inverse of character bitmap byte
  92. t8|=255^ec_read_byte(t4,t5);
  93. }
  94. //Write byte
  95. if(t8>191) fputc(193,fp);
  96. fputc(t8,fp);
  97. }
  98. t7<<=1;//Upgrade bit plane
  99. }
  100. }
  101. }
  102. fclose(fp);
  103. }