Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
5.8 KiB

  1. /*
  2. * decvars.h
  3. *
  4. * Variables for the decoder
  5. */
  6. /*
  7. * MAX_MAIN_TREE_ELEMENTS should be >= 256 + 8*num_position_slots
  8. * (that comes out to 256 + 8*51 right now, for a 2 MB window).
  9. *
  10. * Make divisible by 4 so things are longword aligned.
  11. */
  12. #define MAX_MAIN_TREE_ELEMENTS 672
  13. typedef struct
  14. {
  15. /* 16-bit version does not have one big window pointer */
  16. #ifndef BIT16
  17. /* pointer to beginning of window buffer */
  18. byte *dec_mem_window;
  19. #endif
  20. /* window/decoding buffer parameters */
  21. ulong dec_window_size;
  22. ulong dec_window_mask;
  23. /* previous match offsets */
  24. ulong dec_last_matchpos_offset[NUM_REPEATED_OFFSETS];
  25. /* main tree table */
  26. short dec_main_tree_table[1 << MAIN_TREE_TABLE_BITS];
  27. /* secondary length tree table */
  28. short dec_secondary_length_tree_table[1 << SECONDARY_LEN_TREE_TABLE_BITS];
  29. /* main tree bit lengths */
  30. byte dec_main_tree_len[MAX_MAIN_TREE_ELEMENTS];
  31. /* secondary tree bit lengths */
  32. byte dec_secondary_length_tree_len[NUM_SECONDARY_LENGTHS];
  33. byte pad1[3]; /* NUM_SECONDARY_LENGTHS == 249 */
  34. /* aligned offset table */
  35. char dec_aligned_table[1 << ALIGNED_TABLE_BITS];
  36. byte dec_aligned_len[ALIGNED_NUM_ELEMENTS];
  37. /* left/right pointers for main tree (2*n shorts left, 2*n shorts for right) */
  38. short dec_main_tree_left_right[MAX_MAIN_TREE_ELEMENTS*4];
  39. /* left/right pointers for secondary length tree */
  40. short dec_secondary_length_tree_left_right[NUM_SECONDARY_LENGTHS*4];
  41. /* input (compressed) data pointers */
  42. byte * dec_input_curpos;
  43. byte * dec_end_input_pos;
  44. /* output (uncompressed) data pointer */
  45. byte * dec_output_buffer;
  46. /* position in data stream at start of this decode call */
  47. long dec_position_at_start;
  48. /* previous lengths */
  49. byte dec_main_tree_prev_len[MAX_MAIN_TREE_ELEMENTS];
  50. byte dec_secondary_length_tree_prev_len[NUM_SECONDARY_LENGTHS];
  51. /* bitwise i/o */
  52. ulong dec_bitbuf;
  53. signed char dec_bitcount;
  54. /* number of distinct position (displacement) slots */
  55. byte dec_num_position_slots;
  56. bool dec_first_time_this_group;
  57. bool dec_error_condition;
  58. /* misc */
  59. long dec_bufpos;
  60. ulong dec_current_file_size;
  61. ulong dec_instr_pos;
  62. ulong dec_num_cfdata_frames;
  63. /* original size of current block being decoded (in uncompressed bytes) */
  64. long dec_original_block_size;
  65. /* remaining size of current block being decoded (in uncompressed bytes) */
  66. long dec_block_size;
  67. /* type of current block being decoded */
  68. lzx_block_type dec_block_type;
  69. /* current state of decoder */
  70. decoder_state dec_decoder_state;
  71. /* memory allocation functions */
  72. PFNALLOC dec_malloc;
  73. PFNFREE dec_free;
  74. /* file i/o functions */
  75. PFNOPEN dec_open;
  76. PFNREAD dec_read;
  77. PFNWRITE dec_write;
  78. PFNCLOSE dec_close;
  79. PFNSEEK dec_seek;
  80. #ifdef BIT16
  81. byte * dec_output_curpos;
  82. int dec_last_chance_page_to_use;
  83. int dec_pos_to_page[NUM_OUTPUT_BUFFER_PAGES];
  84. /*
  85. * Variables for big buffer
  86. */
  87. struct
  88. {
  89. BYTE HUGE *Buf; /* history buffer: NULL -> using disk ring buffer */
  90. BYTE HUGE *BufEnd; /* last byte in history buffer + 1 */
  91. BYTE HUGE *BufPos; /* current position in output buffer */
  92. unsigned long Cur; /* current position in the history buffer */
  93. unsigned short NumBytes; /* total number of bytes to decompress */
  94. int fOutOverflow; /* if too little space in output buffer */
  95. BYTE WindowBits; /* needed in DComp_Reset() */
  96. int fRingFault; /* if disk callbacks fail */
  97. } DComp;
  98. /*
  99. * Variables for ring buffer
  100. */
  101. struct
  102. {
  103. int Handle; /* ring file handle */
  104. PBUFFER RingBuffer; /* current output ring buffer */
  105. BYTE FAR *RingPointer; /* current output pointer (into RingBuffer) */
  106. BYTE FAR *RingPointerLimit; /* address of last byte of RingBuffer + 1 */
  107. int RingPages; /* how many pages there are total */
  108. PBUFFER pNewest; /* pointer to most recently used buffer */
  109. PBUFFER pOldest; /* pointer to least recently used buffer */
  110. PAGETABLEENTRY FAR *PageTable; /* pointer to array of pointers */
  111. } Disk;
  112. void (NEAR *DComp_Token_Match)(void *context, MATCH Match);
  113. void (NEAR *DComp_Token_Literal)(void *context, int Chr);
  114. #endif
  115. } t_decoder_context;
  116. /* declare arrays? */
  117. #ifndef ALLOC_VARS
  118. EXT const byte NEAR dec_extra_bits[];
  119. EXT const long NEAR MP_POS_minus2[];
  120. #else
  121. const byte NEAR dec_extra_bits[] =
  122. {
  123. 0,0,0,0,1,1,2,2,
  124. 3,3,4,4,5,5,6,6,
  125. 7,7,8,8,9,9,10,10,
  126. 11,11,12,12,13,13,14,14,
  127. 15,15,16,16,17,17,17,17,
  128. 17,17,17,17,17,17,17,17,
  129. 17,17,17
  130. };
  131. /*
  132. * first (base) position covered by each slot
  133. * 2 subtracted for optimisation purposes (see decverb.c/decalign.c comments)
  134. */
  135. const long NEAR MP_POS_minus2[sizeof(dec_extra_bits)] =
  136. {
  137. 0-2, 1-2, 2-2, 3-2, 4-2, 6-2, 8-2, 12-2,
  138. 16-2, 24-2, 32-2, 48-2, 64-2, 96-2, 128-2, 192-2,
  139. 256-2, 384-2, 512-2, 768-2, 1024-2, 1536-2, 2048-2, 3072-2,
  140. 4096-2, 6144-2, 8192-2, 12288-2, 16384-2, 24576-2, 32768-2, 49152-2,
  141. 65536-2, 98304-2, 131072-2, 196608-2, 262144-2, 393216-2, 524288-2, 655360-2,
  142. 786432-2, 917504-2, 1048576-2, 1179648-2, 1310720-2, 1441792-2, 1572864-2, 1703936-2,
  143. 1835008-2, 1966080-2, 2097152-2
  144. };
  145. #endif