home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / g / gamesuit / Utilities / Hammer / DecSource next >
Encoding:
Text File  |  1995-01-20  |  3.0 KB  |  227 lines

  1.  
  2. #name decomp
  3. #type &ffc
  4. #base 0
  5.  
  6. ; This file should be compiled with ExtAsm
  7.  
  8. struct v {
  9.  
  10.   .sizeof
  11. }
  12.  
  13. macro getbyte
  14. {
  15.   LDRB R0,[R11],#1
  16. }
  17. macro putbyte
  18. {
  19.   STRB R0,[R10,#1]!
  20. }
  21.  
  22.  
  23. ;init conditions
  24. ;R0 points to the file to be decomped
  25. ;exits with R1 = size of decompressed file
  26. ;           R2 = address to return to after allocation
  27.  
  28. .init
  29. LDR R1,[R0]
  30. BIC R1,R1,#&FFFF<<16
  31. LDR R2,idcode
  32. CMP R1,R2
  33. BNE nothmr
  34. LDR R1,[R0,#4]
  35. MOV R2,PC
  36. MOV PC,R14
  37.  
  38. ;entry conditions
  39. ;R0 = address of file to decomp
  40. ;R1 = address of space for decomped file
  41. .entry
  42. STMFD R13!,{R10-R11,R14}
  43. MOV R11,R0
  44. MOV R10,R1
  45. LDR R0,[R11]
  46. BIC R0,R0,#&FFFF<<16
  47. LDR R1,idcode
  48. CMP R1,R0
  49. BNE nothmr2
  50. LDR R9,[R11,#4]
  51. ADD R9,R10,R9; R9 is the end limit marker
  52. MOV R8,#0
  53. SUB R10,R10,#1; align for putbyte
  54. SUB R9,R9,#1  ; likewise
  55. ADD R11,R11,#8; skip header
  56. .loop1
  57. getbyte
  58. CMP R0,#&10
  59. BLT type1
  60. CMP R0,#&20
  61. BLT type2
  62. CMP R0,#&40
  63. BLT type3
  64. CMP R0,#&80
  65. BLT type4
  66. ;drops through
  67. .type5
  68. CMP R0,#&FF
  69. BEQ overrunerr
  70. MOV R1,R0
  71. getbyte
  72. AND R2,R1,#&78
  73. MOV R2,R2,LSR #3
  74. ADD R2,R2,#2
  75. AND R3,R1,#&7
  76. ADD R3,R0,R3,LSL #8
  77. SUB R3,R10,R3
  78. .loop7
  79. LDRB R0,[R3],#1
  80. putbyte
  81. SUBS R2,R2,#1
  82. BGT loop7
  83. .typeins
  84. CMP R10,R9
  85. BLT loop1
  86. BLNE inconserr
  87. getbyte
  88. CMP R0,#&FF
  89. BNE underrunerr
  90. .decompend
  91. LDMFD R13!,{R10-R11,PC}
  92.  
  93. .type1     ;&00-&0F
  94. MOV R1,R0
  95. CMP R1,#15
  96. ADDNE R1,R1,#2
  97. MOVEQ R1,#256
  98. getbyte
  99. .loop2
  100. putbyte
  101. SUBS R1,R1,#1
  102. BGT loop2
  103. B typeins
  104.  
  105. .type2     ;&10-&1F
  106. MOV R1,R0
  107. AND R1,R1,#&F
  108. ADD R1,R1,#1
  109. .loop3
  110. getbyte
  111. putbyte
  112. SUBS R1,R1,#1
  113. BGT loop3
  114. B typeins
  115.  
  116. .type3     ;&20-&3F
  117. MOV R1,R0
  118. getbyte
  119. AND R2,R1,#&1C
  120. MOV R2,R2,LSR #2
  121. ADD R2,R2,#2
  122. AND R3,R1,#&3
  123. ADD R3,R0,R3,LSL #8
  124. SUB R3,R10,R3
  125. .loop5
  126. LDRB R0,[R3],#-1
  127. putbyte
  128. SUBS R2,R2,#1
  129. BGT loop5
  130. B typeins
  131.  
  132. .type4      ;&40-&7F
  133. MOV R1,R0
  134. getbyte
  135. AND R2,R1,#&38
  136. MOV R2,R2,LSR #3
  137. ADD R2,R2,#2
  138. AND R4,R1,#&06
  139. MOV R4,R4,LSR #1
  140. CMP R4,#2
  141. ADDGE R4,R4,#1
  142.  
  143. AND R3,R1,#&1
  144. ADD R3,R0,R3,LSL #8
  145. SUB R5,R10,R3
  146.  
  147. MOV R1,#1
  148. MOV R4,R1,LSL R4
  149.  
  150. MOV R3,#0
  151. .loop6
  152. LDRB R0,[R5,R3,ASR #2]
  153. putbyte
  154. ADD R3,R3,R4
  155. SUBS R2,R2,#1
  156. BGT loop6
  157. B typeins
  158.  
  159. .nothmr
  160. ADR R0,nothmrtext
  161. MOV R1,#0
  162. ADR R2,traperr
  163. ORR R14,R14,#1<<28
  164. MOVS PC,R14
  165.  
  166. .nothmr2
  167. ADR R0,nothmr2text
  168. SWI OS_GenerateError
  169.  
  170. .traperr
  171. ADR R0,traperrtext
  172. SWI OS_GenerateError
  173.  
  174. .overrunerr
  175. ADR R0,overrunerrtext
  176. ADD R0,R0,#4
  177. SWI OS_Write0
  178. SWI OS_NewLine
  179. B decompend
  180. SWI OS_GenerateError
  181.  
  182. .underrunerr
  183. ADR R0,underrunerrtext
  184. ADD R0,R0,#4
  185. SWI OS_Write0
  186. SWI OS_NewLine
  187. B decompend
  188. SWI OS_GenerateError
  189.  
  190. .inconserr
  191. STMFD R13!,{R14}
  192. ADR R0,inconserrtext
  193. ADD R0,R0,#4
  194. SWI OS_Write0
  195. SWI OS_NewLine
  196. LDMFD R13!,{PC}
  197.  
  198. .nothmrtext
  199. DCD &666
  200. DCB "Decomp : Not a hammer file",0
  201. ALIGN
  202. .nothmr2text
  203. DCD &666
  204. DCB "Decomp : R0 corrupted during space allocation",0
  205. ALIGN
  206. .traperrtext
  207. DCD &666
  208. DCB "Decomp : Your error trapping is not working",0
  209. ALIGN
  210. .overrunerrtext
  211. DCD &666
  212. DCB "Decomp : Overrun - bad hammer file",0
  213. ALIGN
  214. .underrunerrtext
  215. DCD &666
  216. DCB "Decomp : Underrun - bad hammer file",0
  217. ALIGN
  218. .inconserrtext
  219. DCD &666
  220. DCB "Decomp : File length inconsistent with header",0
  221. ALIGN
  222. .idcode
  223. DCB "Hm",0,0
  224. .spec
  225. DCB "Decomp 0.01",0
  226. ALIGN
  227.