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. //static volatile char rcsid[] = "$Id: scrdump.c,v 1.4 1999/02/16 05:45:41 mental Exp $";
  31. /* FIXME: not endian-safe */
  32. void dump_screen(char far *filename) {
  33. char fname[10];
  34. FILE *fp;
  35. int t1, t2, t3, t4, t5, t7, t8, snum;
  36. unsigned char *scrn = (unsigned char*)MK_FP(current_pg_seg,0);
  37. char r,g,b;
  38. for (snum = 0;snum++;snum <= 9) {
  39. sprintf(fname,"screen%d.pcx",snum);
  40. break;
  41. //if (!(access(fname,0) == 0)) break;
  42. }
  43. fp=fopen("foo.pcx","wb");
  44. //header
  45. fputc(10,fp);
  46. fputc(5,fp);
  47. fputc(1,fp);
  48. fputc(1,fp);
  49. t1=0; fwrite(&t1,1,2,fp);
  50. t1=0; fwrite(&t1,1,2,fp);
  51. t1=639; fwrite(&t1,1,2,fp);
  52. t1=349; fwrite(&t1,1,2,fp);
  53. t1=300; fwrite(&t1,1,2,fp);
  54. t1=300; fwrite(&t1,1,2,fp);
  55. //colormap
  56. for(t1=0;t1<16;t1++) {
  57. get_rgb(t1,r,g,b);
  58. fputc(r<<2,fp);
  59. fputc(g<<2,fp);
  60. fputc(b<<2,fp);
  61. }
  62. //header part 2
  63. fputc(0,fp);
  64. fputc(4,fp);
  65. t1=80; fwrite(&t1,1,2,fp);
  66. t1=1; fwrite(&t1,1,2,fp);
  67. t1=640; fwrite(&t1,1,2,fp);
  68. t1=350; fwrite(&t1,1,2,fp);
  69. for(t1=0;t1<54;t1++) fputc(0,fp);
  70. //picture
  71. for(t1=0;t1<25;t1++) {//25 rows
  72. for(t5=0;t5<14;t5++) {//14 bitmap rows per char
  73. t7=1;
  74. for(t2=0;t2<4;t2++) {//4 planes
  75. for(t3=0;t3<80;t3++) {//80 columns
  76. //Check FG color to see if applicable
  77. t4=(scrn[((t1*80+t3)<<1)+1])&t7;
  78. if(t4) {
  79. //Get character
  80. t4=scrn[(t1*80+t3)<<1];
  81. //Write character bitmap byte
  82. t8=ec_read_byte(t4,t5);
  83. }
  84. else t8=0;//Byte for this bitplane
  85. //Check BK color to see if applicable
  86. t4=((scrn[((t1*80+t3)<<1)+1])>>4)&t7;
  87. if(t4) {
  88. //Get character
  89. t4=scrn[(t1*80+t3)<<1];
  90. //Write inverse of character bitmap byte
  91. t8|=255^ec_read_byte(t4,t5);
  92. }
  93. //Write byte
  94. if(t8>191) fputc(193,fp);
  95. fputc(t8,fp);
  96. }
  97. t7<<=1;//Upgrade bit plane
  98. }
  99. }
  100. }
  101. fclose(fp);
  102. }