JAM_IO.C 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* Catacomb Armageddon Source Code
  2. * Copyright (C) 1993-2014 Flat Rock Software
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along
  15. * with this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17. */
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <ctype.h>
  22. #include <alloc.h>
  23. #include <fcntl.h>
  24. #include <dos.h>
  25. #include <io.h>
  26. #include "def.h"
  27. #include "gelib.h"
  28. #include "jam_io.h"
  29. //----------------------------------------------------------------------------
  30. //
  31. // PTR/PTR COMPRESSION ROUTINES
  32. //
  33. //
  34. //----------------------------------------------------------------------------
  35. //---------------------------------------------------------------------------
  36. // WritePtr() -- Outputs data to a particular ptr type
  37. //
  38. // PtrType MUST be of type DEST_TYPE.
  39. //
  40. // NOTE : For PtrTypes DEST_MEM a ZERO (0) is always returned.
  41. //
  42. //---------------------------------------------------------------------------
  43. char WritePtr(long outfile, unsigned char data, unsigned PtrType)
  44. {
  45. int returnval = 0;
  46. switch (PtrType & DEST_TYPES)
  47. {
  48. case DEST_FILE:
  49. write(*(int far *)outfile,(char *)&data,1);
  50. break;
  51. case DEST_FFILE:
  52. returnval = putc(data, *(FILE **)outfile);
  53. break;
  54. case DEST_IMEM:
  55. printf("WritePtr - unsupported ptr type\n");
  56. exit(0);
  57. break;
  58. case DEST_MEM:
  59. *((char far *)*(char far **)outfile)++ = data;
  60. break;
  61. }
  62. return(returnval);
  63. }
  64. //---------------------------------------------------------------------------
  65. // ReadPtr() -- Reads data from a particular ptr type
  66. //
  67. // PtrType MUST be of type SRC_TYPE.
  68. //
  69. // RETURNS :
  70. // The char read in or EOF for SRC_FFILE type of reads.
  71. //
  72. //
  73. //---------------------------------------------------------------------------
  74. int ReadPtr(long infile, unsigned PtrType)
  75. {
  76. int returnval = 0;
  77. switch (PtrType & SRC_TYPES)
  78. {
  79. case SRC_FILE:
  80. read(*(int far *)infile,(char *)&returnval,1);
  81. break;
  82. case SRC_FFILE:
  83. returnval = getc(*(FILE far **)infile
  84. );
  85. break;
  86. case SRC_BFILE:
  87. returnval = bio_readch((BufferedIO *)*(void far **)infile);
  88. break;
  89. // case SRC_IMEM:
  90. // printf("WritePtr - unsupported ptr type\n");
  91. // exit(0);
  92. // break;
  93. case SRC_MEM:
  94. returnval = (unsigned char)*((char far *)*(char far **)infile)++;
  95. break;
  96. }
  97. return(returnval);
  98. }