pst-ttuf.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. | TIGCC Program Starter - ttunpack decompression support (fast & large version)
  2. | Copyright (C) 2004-2005 Samuel Stearley, Kevin Kofler
  3. |
  4. | THE LICENSE:
  5. |
  6. | wxWindows Library Licence, Version 3.1
  7. | ======================================
  8. |
  9. | Copyright (C) 1998-2005 Julian Smart, Robert Roebling et al
  10. |
  11. | Everyone is permitted to copy and distribute verbatim copies
  12. | of this licence document, but changing it is not allowed.
  13. |
  14. | WXWINDOWS LIBRARY LICENCE
  15. | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  16. |
  17. | This library is free software; you can redistribute it and/or modify it
  18. | under the terms of the GNU Library General Public Licence as published by
  19. | the Free Software Foundation; either version 2 of the Licence, or (at
  20. | your option) any later version.
  21. |
  22. | This library is distributed in the hope that it will be useful, but
  23. | WITHOUT ANY WARRANTY; without even the implied warranty of
  24. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
  25. | General Public Licence for more details.
  26. |
  27. | You should have received a copy of the GNU Library General Public Licence
  28. | along with this software, usually in a file named COPYING.LIB. If not,
  29. | write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  30. | Boston, MA 02111-1307 USA.
  31. |
  32. | EXCEPTION NOTICE
  33. |
  34. | 1. As a special exception, the copyright holders of this library give
  35. | permission for additional uses of the text contained in this release of
  36. | the library as licenced under the wxWindows Library Licence, applying
  37. | either version 3.1 of the Licence, or (at your option) any later version of
  38. | the Licence as published by the copyright holders of version
  39. | 3.1 of the Licence document.
  40. |
  41. | 2. The exception is that you may use, copy, link, modify and distribute
  42. | under your own terms, binary object code versions of works based
  43. | on the Library.
  44. |
  45. | 3. If you copy code from files distributed under the terms of the GNU
  46. | General Public Licence or the GNU Library General Public Licence into a
  47. | copy of this library, as this licence permits, the exception does not
  48. | apply to the code that you add in this way. To avoid misleading anyone as
  49. | to the status of such modified files, you must delete this exception
  50. | notice from such code and/or adjust the licensing conditions notice
  51. | accordingly.
  52. |
  53. | 4. If you write modifications of your own for this library, it is your
  54. | choice whether to permit this exception to apply to your modifications.
  55. | If you do not wish that, you must delete the exception notice from such
  56. | code and/or adjust the licensing conditions notice accordingly.
  57. | GET_UNCOMPRESSED_SIZE inline function
  58. | INPUT: %a3.l: pointer to compressed data
  59. | OUTPUT: %d6.l: uncompressed size
  60. | SIDE EFFECTS: throws a Data Type error if not a valid compressed program
  61. | may throw a Memory error
  62. | may advance %a3 for later decompression
  63. | DESTROYS: %d0-%d2/%a0-%a1
  64. .macro GET_UNCOMPRESSED_SIZE
  65. | Get the length of the variable.
  66. moveq.l #0,%d6
  67. move.w (%a3)+,%d6
  68. | Get a pointer to the data type of the variable.
  69. lea.l -1(%a3,%d6.l),%a0
  70. | Check if it has type "ppg".
  71. cmp.b #0xf8,(%a0)
  72. jbne invalid_archive
  73. tst.b -(%a0)
  74. jbne invalid_archive
  75. cmp.b #'g',-(%a0)
  76. jbne invalid_archive
  77. moveq.l #'p',%d0
  78. cmp.b -(%a0),%d0
  79. jbne invalid_archive
  80. cmp.b -(%a0),%d0
  81. jbne invalid_archive
  82. tst.b -(%a0)
  83. jbeq valid_archive
  84. | We don't need to check the magic number in the ttunpack header,
  85. | the decompression routine does that already.
  86. invalid_archive:
  87. .word 0xA000+210 | ER_DATATYPE
  88. valid_archive:
  89. | Get the uncompressed size.
  90. move.w (%a3),%d6
  91. rol.w #8,%d6
  92. .endm
  93. | MEM_TO_MEM_DECOMPRESS inline function
  94. | INPUT: %a3.l: pointer to compressed data
  95. | %a0.l: pointer to buffer for uncompressed data
  96. | %d6.l: uncompressed size
  97. | OUTPUT: %a4.l: pointer to uncompressed data
  98. | SIDE EFFECTS: may throw a Memory or Data Type error
  99. | DESTROYS: %d0-%d2/%a0-%a2
  100. .macro MEM_TO_MEM_DECOMPRESS
  101. pea.l (%a0) | destination
  102. pea.l (%a3) | source
  103. move.l %a0,%a4 | satisfy output constraint
  104. jbsr ttunpack_decompress
  105. addq.l #8,%a7
  106. tst.w %d0
  107. jbne invalid_archive
  108. .endm
  109. |-----------------------------------------------------------------------
  110. |INTRODUCTION:
  111. |
  112. | This is a 100% assembly version of the ttunpack routine, which is
  113. | based on code by Pasi 'Albert' Ojala, albert@cs.tut.fi, then
  114. | reduced by Thomas Nussbaumer to fit his needs. For a full details
  115. | on the algorithm see:
  116. |
  117. | http://www.cs.tut.fi/~albert/Dev/pucrunch/index.html
  118. |
  119. | Version 2.28 Fast
  120. |
  121. | 2006-03-20 Kevin Kofler: Ported to GNU as. Removed options not used in
  122. | pstarter.
  123. |
  124. |THE LICENSE:
  125. |
  126. | Copyright (C) 2004-2005 Samuel Stearley
  127. |
  128. | wxWindows Library Licence, Version 3.1
  129. | ======================================
  130. |
  131. | Copyright (C) 1998-2005 Julian Smart, Robert Roebling et al
  132. |
  133. | Everyone is permitted to copy and distribute verbatim copies
  134. | of this licence document, but changing it is not allowed.
  135. |
  136. | WXWINDOWS LIBRARY LICENCE
  137. | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
  138. |
  139. | This library is free software; you can redistribute it and/or modify it
  140. | under the terms of the GNU Library General Public Licence as published by
  141. | the Free Software Foundation; either version 2 of the Licence, or (at
  142. | your option) any later version.
  143. |
  144. | This library is distributed in the hope that it will be useful, but
  145. | WITHOUT ANY WARRANTY; without even the implied warranty of
  146. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
  147. | General Public Licence for more details.
  148. |
  149. | You should have received a copy of the GNU Library General Public Licence
  150. | along with this software, usually in a file named COPYING.LIB. If not,
  151. | write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  152. | Boston, MA 02111-1307 USA.
  153. |
  154. | EXCEPTION NOTICE
  155. |
  156. | 1. As a special exception, the copyright holders of this library give
  157. | permission for additional uses of the text contained in this release of
  158. | the library as licenced under the wxWindows Library Licence, applying
  159. | either version 3.1 of the Licence, or (at your option) any later version of
  160. | the Licence as published by the copyright holders of version
  161. | 3.1 of the Licence document.
  162. |
  163. | 2. The exception is that you may use, copy, link, modify and distribute
  164. | under your own terms, binary object code versions of works based
  165. | on the Library.
  166. |
  167. | 3. If you copy code from files distributed under the terms of the GNU
  168. | General Public Licence or the GNU Library General Public Licence into a
  169. | copy of this library, as this licence permits, the exception does not
  170. | apply to the code that you add in this way. To avoid misleading anyone as
  171. | to the status of such modified files, you must delete this exception
  172. | notice from such code and/or adjust the licensing conditions notice
  173. | accordingly.
  174. |
  175. | 4. If you write modifications of your own for this library, it is your
  176. | choice whether to permit this exception to apply to your modifications.
  177. | If you do not wish that, you must delete the exception notice from such
  178. | code and/or adjust the licensing conditions notice accordingly.
  179. |
  180. |
  181. |NOTES:
  182. |
  183. |1) There were several other names associated with this, but not
  184. | anymore ;)
  185. |
  186. |
  187. |2) There should be an unpack.c distributed with this that has
  188. | additional comments that will help clarify what this is doing.
  189. | But maybe not. It depends on where you got this. you should
  190. | always be able to find this on my site: http://www.nyall.net
  191. |
  192. |
  193. |3) If caller wants, they can alter the default int priority to
  194. | speed up execution before calling this routine.
  195. |
  196. |
  197. |4) The code was written with wordpad. It might look better if
  198. | opened with that program.
  199. |----------------------------------------------------------------------
  200. .include "os.h"
  201. .equ osize_lo,0 |original size lowbyte
  202. .equ osize_hi,1 |original size highbyte
  203. .equ magic1,2 |must be equal to UNPACK_MAGIC1
  204. .equ magic2,3 |must be equal to UNPACK_MAGIC2
  205. .equ csize_lo,4 |compressed size lowbyte
  206. .equ csize_hi,5 |compressed size lowbyte
  207. .equ esc1,6 |escape >> (8-escBits)
  208. .equ notused3,7 |
  209. .equ notused4,8 |
  210. .equ esc2,9 |escBits
  211. .equ gamma1,10 |maxGamma + 1
  212. .equ gamma2,11 |(1<<maxGamma)
  213. .equ extralz,12 |extraLZPosBits
  214. .equ notused1,13 |
  215. .equ notused2,14 |
  216. .equ rleentries,15 |rleUsed
  217. .equ HEADER_SIZE,16
  218. .equ __MAGIC_CHAR1,0x54
  219. .equ __MAGIC_CHAR2,0x50
  220. .equ __ERRPCK_OKAY,0
  221. .equ __ERRPCK_NOESCFOUND,8 |248
  222. .equ __ERRPCK_ESCBITS,7 |249
  223. .equ __ERRPCK_MAXGAMMA,6 |250
  224. .equ __ERRPCK_EXTRALZP,5 |251
  225. .equ __ERRPCK_NOMAGIC,4 |252
  226. .equ __ERRPCK_OUTBUFOVERRUN,3 |253
  227. .equ __ERRPCK_LZPOSUNDERRUN,2 |254
  228. |-----------------------------------------------------------------------
  229. |Notes on register useage, might be good Idea to print this.
  230. |
  231. | a0 => trashing, but may not be used by the subroutines
  232. | a1 => extra z position bits
  233. | a2 => a table that maps a byte to the highest bit set in it.
  234. | a3 => the bytecodevec table
  235. | a4 => The point to jump to when doing a continue
  236. | a5 => the destination buffer
  237. | a6 => points to the next byte of the compressed data.
  238. | updated when d7 overflows.
  239. |
  240. | d0 => trashing, output of __GetBits and __GetValue
  241. | d1 => trashing, input to __GetBits
  242. | d2 => prepared mask for isolating # of escape bits
  243. | d3 => trashing but only by the main routine, not the subroutines
  244. | It is usually the prepared count.
  245. | d4 => # of escape bits
  246. | d5 => start escape
  247. | d6 => the current compressed byte, updated when d7 overflows.
  248. | d7 => which bit we are at in the compressed data.
  249. |-----------------------------------------------------------------------
  250. .macro correct_in_mask
  251. tst.b %d7
  252. bne.s 0f
  253. moveq #8,%d7
  254. move.b (%a6)+,%d6
  255. 0:
  256. .endm
  257. ttunpack_decompress:
  258. movem.l %d3-%d7/%a2-%a6,-(%a7)
  259. move.l 4+10*4(%a7),%a6
  260. move.l 8+10*4(%a7),%a5
  261. |--------------------------------------------------------
  262. | startesc = cth->esc1; //d5
  263. | bytecodevec = &src[15]; //a3
  264. | __imask__ = 0x80; //d7
  265. |
  266. |These are initialized here to insure that certain
  267. |branches can use the short form.
  268. |--------------------------------------------------------
  269. lea 15(%a6),%a3 |'bytecodevec'
  270. moveq #0,%d5
  271. move.b esc1(%a6),%d5 |'StartEsc'
  272. moveq #8,%d7 |which bit i am at
  273. |-------------------------------------------------------------------------------------------------
  274. | if (cth->magic1 != __MAGIC_CHAR1 || cth->magic2 != __MAGIC_CHAR2) return __ERRPCK_NOMAGIC;
  275. | if (cth->gamma1 != 8 || cth->gamma2 != 128) return __ERRPCK_MAXGAMMA;
  276. | if ((escbits = cth->esc2) > 8) return __ERRPCK_ESCBITS;
  277. | if ((extralzposbits = cth->extralz) > 4) return __ERRPCK_EXTRALZP;
  278. |-------------------------------------------------------------------------------------------------
  279. moveq #__ERRPCK_NOMAGIC,%d0
  280. cmp.b #__MAGIC_CHAR1,magic1(%a6) |these could be optimized into 1 word compare
  281. bne.s __ReturnError | if evenly aligned.
  282. cmp.b #__MAGIC_CHAR2,magic2(%a6)
  283. bne.s __ReturnError
  284. moveq #__ERRPCK_MAXGAMMA,%d0
  285. cmp.b #8,gamma1(%a6)
  286. bne.s __ReturnError
  287. cmp.b #128,gamma2(%a6)
  288. bne.s __ReturnError
  289. moveq #__ERRPCK_ESCBITS,%d0
  290. moveq #0,%d1
  291. move.b esc2(%a6),%d1
  292. move.l %d1,%d4
  293. subq.w #8,%d1
  294. bhi.s __ReturnError
  295. moveq #__ERRPCK_EXTRALZP,%d0
  296. moveq #0,%d1
  297. move.b extralz(%a6),%d1
  298. move.l %d1,%a1 |extralz pos bits
  299. subq.w #5,%d1
  300. bgt.s __ReturnError
  301. |--------------------------------------------------------
  302. | escbits8 = 8 - escbits; //not used
  303. | __ibuffer__ = src + sizeof(__PACKHEADER) + cth->rleentries; //a6
  304. |--------------------------------------------------------
  305. moveq #0,%d2
  306. bset %d4,%d2
  307. subq.w #1,%d2 |the mask for the number of escape bits
  308. ror.b %d4,%d2 |set the upper bits
  309. ror.b %d4,%d5 |shift up start escape
  310. moveq #0,%d0
  311. move.b (%a3),%d0
  312. lea HEADER_SIZE(%a6,%d0),%a6
  313. |--------------------------------------------------------
  314. |To remove checking if escbits == 0 in the literal byte
  315. | loop, there are two points used for continuing.
  316. |--------------------------------------------------------
  317. lea __ReturnPointForNonZeroEscapeBits(%pc),%a4
  318. tst.b %d4
  319. bne.s __Skipper
  320. lea __SelIsStartEscape(%pc),%a4
  321. __Skipper:
  322. |--------------------------------------------------------
  323. |a2 will point to a table that maps a byte to the
  324. | highest bit set in it. 0 will be mapped to zero,
  325. | this is important.
  326. |--------------------------------------------------------
  327. lea -260(%a7),%a7
  328. move.l %a7,%a2
  329. clr.b (%a2)+
  330. moveq #0,%d0
  331. moveq #7,%d1
  332. AllBytes:
  333. moveq #0,%d3
  334. bset %d0,%d3
  335. ThisByte:
  336. move.b %d0,(%a2)+
  337. subq.w #1,%d3
  338. bne.s ThisByte
  339. addq.w #1,%d0
  340. dbra %d1,AllBytes
  341. move.l %a7,%a2
  342. move.b (%a6)+,%d6 |very first byte of compressed data
  343. jmp (%a4) |jump into the loop
  344. |---------------------------------------------------------
  345. |And when all is done branch here
  346. |---------------------------------------------------------
  347. __WeAreDone:
  348. moveq #0,%d0 |return value
  349. lea 260(%a7),%a7
  350. __ReturnError:
  351. neg.b %d0 |turn loaded error code into actual value
  352. movem.l (%a7)+,%d3-%d7/%a2-%a6
  353. rts
  354. |---------------------------------------------------------
  355. | *outbuffer++ = (sel<<escbits8) | __GetBits(escbits8);
  356. | continue;
  357. |---------------------------------------------------------
  358. __SelIsNOTStartEscape:
  359. move.b %d0,(%a5)+ |put litteral byte to the output
  360. |---------------------------------------------------------
  361. |The while(1) loop:
  362. |
  363. | sel = (escbits) ? __GetBits(escbits) : startesc;
  364. | if (sel == startesc) {
  365. |---------------------------------------------------------
  366. __ReturnPointForNonZeroEscapeBits:
  367. move.b %d6,-(%a7)
  368. move.w (%a7)+,%d0
  369. move.b (%a6)+,%d6
  370. move.b %d6,%d0
  371. lsr.w %d7,%d0 |__get8bits() done
  372. move.b %d2,%d1
  373. and.b %d0,%d1 |isolate the upper escape bits
  374. cmp.b %d5,%d1 |are they 'startesc'
  375. bne.s __SelIsNOTStartEscape
  376. subq.l #2,%a6
  377. move.b (%a6)+,%d6
  378. sub.w %d4,%d7
  379. bhi.s __StillInSameByte2
  380. move.b (%a6)+,%d6
  381. addq.w #8,%d7
  382. __StillInSameByte2:
  383. |---------------------------------------------------------
  384. |The following code is entered if sel == startesc
  385. |but it does not actually use the sel variable
  386. |
  387. | lzlen = __GetValue();
  388. | if (lzlen != 1) {
  389. |---------------------------------------------------------
  390. __SelIsStartEscape:
  391. bsr __GetValue |get a value for 'lzlen'
  392. move.w %d0,%d3 |save 'lzlen'
  393. subq.w #1,%d0 |does 'lzlen' == 1 ?
  394. beq.s __RleDecoding
  395. |---------------------------------------------------------
  396. |Zip decoding
  397. |
  398. | lzposhi = __GetValue() - 1;
  399. | if (lzposhi == 254) {
  400. |---------------------------------------------------------
  401. bsr __GetValue |if it equals 254, then lzlen must be > 3 because
  402. addq.b #1,%d0 | there is no other possiblity because Delta decompression
  403. beq.s __WeAreDone | is not being used. It the branch is not taken it
  404. | drops through to the __LzPosHi_IsNot254
  405. |----------------------------------------------------------------------------------------
  406. | if (extralzposbits) lzposhi = (lzposhi<<extralzposbits) | __GetBits(extralzposbits);
  407. | lzposlo = __Get8Bit() ^ 0xff;
  408. | lzpos = COMBINE_LOWHIGH(lzposlo,lzposhi);
  409. |
  410. | d0= lzPosHi, d3.w = lzlen, d1.l =lzpos
  411. |----------------------------------------------------------------------------------------
  412. __LzPosHi_IsNot254:
  413. subq.b #2,%d0 |undo the addq.b #1
  414. move.w %a1,%d1 |is 'extralzposbits' == 0?
  415. beq.s __extralZposBitsIsZero
  416. lsl.w %d1,%d0 |shift it by 'extralzposbits'
  417. moveq #0,%d1
  418. bset.l %d7,%d1
  419. subq.w #1,%d1
  420. and.b %d6,%d1
  421. sub.w %a1,%d7
  422. bhi.s __StillInSameByte61
  423. move.b (%a6)+,%d6
  424. move.b %d1,-(%a7)
  425. move.w (%a7)+,%d1
  426. move.b %d6,%d1
  427. addq.w #8,%d7
  428. __StillInSameByte61:
  429. lsr.w %d7,%d1
  430. or.w %d1,%d0 |or them back together
  431. __extralZposBitsIsZero: |at this point d0.b == 'lzposhi'
  432. moveq #0,%d1
  433. move.b %d0,-(%a7) |a faster way to do lsl.w #8
  434. move.w (%a7)+,%d1 |shift it into the high byte of 'lzpos', first step of COMBINE_LOWHIGH
  435. move.b %d6,-(%a7) |start the __Get8Bit
  436. move.w (%a7)+,%d0
  437. move.b (%a6)+,%d6
  438. move.b %d6,%d0
  439. lsr.w %d7,%d0 |get 8 bit done
  440. move.b %d0,%d1 |COMBINE_LOWHIGH
  441. not.b %d1
  442. not.l %d1
  443. |-----------------------------------------------------------------------------------
  444. | for (i=0; i<=lzlen; i++) {
  445. | *outbuffer = *(outbuffer - lzpos - 1); //no 'add' variable
  446. | outbuffer++;
  447. | }
  448. |
  449. | d2.l must be -lzpos+1
  450. | d3.w must be lzlen
  451. |------------------------------------------------------------------------------------
  452. lea 0(%a5,%d1.l),%a0
  453. __WriteDataLoop:
  454. move.b (%a0)+,(%a5)+
  455. dbra %d3,__WriteDataLoop
  456. jmp (%a4) |continue
  457. |----------------------------------------------------------------------
  458. |'lzlen' = 1
  459. | RLE decoding, OR 2 byte zip, OR escape from the escape
  460. |----------------------------------------------------------------------
  461. __RleDecoding:
  462. subq.b #1,%d7
  463. btst.b %d7,%d6
  464. beq.s __NextBitClear_DoZipAfterAll
  465. CORRECT_IN_MASK
  466. |The second NEXT_BIT_SET()
  467. subq.b #1,%d7
  468. btst.b %d7,%d6
  469. beq __NextBitIsClear_EscapeFromEscape
  470. |-----------------------------------------------------------------
  471. | rlelen = __GetValue();
  472. | if (rlelen >= 128) {
  473. | rlelen = ((rlelen-128)<<1) | __GetBits(1);
  474. | rlelen |= (((__GetValue())-1)<<8);
  475. | }
  476. |------------------------------------------------------------------
  477. __NextBitIsSet_RunLengthEncoding:
  478. CORRECT_IN_MASK
  479. bsr.s __GetValue |get 'rlelen' into d0, limited to 8 bit values.
  480. move.b %d0,%d3 |copy it and check sign bit to see if >= 128
  481. bpl.s __LessThan128
  482. | sub.w #128,%d3 |not needed
  483. add.b %d3,%d3 |double it, this clears the high bit so there is no need to subtract 128
  484. |-----An Inlined version of __GetBits optimized for an input of 1 --------
  485. subq.b #1,%d7
  486. btst.b %d7,%d6
  487. sne %d0
  488. sub.b %d0,%d3 |subtract -1 if the bit was set = add 1
  489. CORRECT_IN_MASK
  490. bsr.s __GetValue
  491. subq.b #1,%d0
  492. move.w %d3,-(%a7)
  493. move.b %d0,(%a7)
  494. move.w (%a7)+,%d3
  495. |-------------------------------------------------------------------
  496. |Need the byte to copy
  497. |
  498. | bytecode = __GetValue();
  499. | if (bytecode < 32) byte = bytecodevec[bytecode];
  500. | else byte = ((bytecode-32)<<3) | __GetBits(3); //subracting 32 not needed
  501. |-------------------------------------------------------------------
  502. __LessThan128:
  503. bsr.s __GetValue |get bytecode
  504. cmp.b #32,%d0
  505. bcc.s __GreaterThanOrEqual32
  506. move.b 0(%a3,%d0.w),%d0 |byte = bytecodevec[bytecode];
  507. bra.s __RleCopy
  508. __GreaterThanOrEqual32:
  509. |-----An Inlined version of GetBits that is optimized for an input of 3-------
  510. lsl.b #3,%d0
  511. move.b %d6,%d1
  512. subq.w #3,%d7
  513. bhi.s __StillInSameByte2345
  514. move.b (%a6)+,%d6
  515. move.b %d1,-(%a7)
  516. move.w (%a7)+,%d1
  517. move.b %d6,%d1
  518. addq.w #8,%d7
  519. __StillInSameByte2345:
  520. lsr.w %d7,%d1
  521. and.b #0x7,%d1
  522. or.b %d1,%d0
  523. |--------------------------------------------------------
  524. | for (i=0; i<=rlelen; i++) *outbuffer++ = byte;
  525. | continue; // continue the main loop ...
  526. |
  527. |Rle loop expects
  528. | d0 = byte
  529. | d3 = number of em to copy, no need to subtract 1 for
  530. | dbra
  531. |--------------------------------------------------------
  532. __RleCopy:
  533. __RleLoop:
  534. move.b %d0,(%a5)+
  535. dbra %d3,__RleLoop
  536. jmp (%a4)
  537. |---------------------------------------------------------
  538. | lzpos = __Get8Bit() ^ 0xff;
  539. |---------------------------------------------------------
  540. __NextBitClear_DoZipAfterAll:
  541. CORRECT_IN_MASK
  542. move.b %d6,-(%a7) |current byte
  543. move.w (%a7)+,%d1
  544. move.b (%a6)+,%d6 |next byte
  545. move.b %d6,%d1
  546. lsr.w %d7,%d1
  547. moveq #-1,%d3
  548. move.b %d1,%d3
  549. lea 0(%a5,%d3.l),%a0
  550. move.b (%a0)+,(%a5)+
  551. move.b (%a0)+,(%a5)+ |'lzlen' is 1, means 2 byte copy.
  552. jmp (%a4) |continue
  553. |-------------------------------------------------------------
  554. | __GetValue returns a value in d0.l
  555. | __GetBits takes as its input d1.b, returns a value in d0.l
  556. |
  557. | The outputs can be manipulated as:
  558. | unsigned character,
  559. | unsigned shorts,
  560. | unsigned longs
  561. |
  562. | They may update
  563. | d6, d7, a6
  564. |
  565. | They may not destroy
  566. | d3-d5/a0-a5
  567. |
  568. | They expect a2 to be a table that tells the number of the
  569. | highest bit that is set
  570. |
  571. |--------------------------------------------------------------
  572. __GetValue: |This function has a goal of counting till it finds
  573. moveq #0,%d0
  574. move.w %d7,%d1
  575. bset.l %d7,%d0
  576. subq.w #1,%d0 |made the mask
  577. and.b %d0,%d6 |mask out bits of interest, clear bits that we have already
  578. | passed by
  579. eor.b %d6,%d0 |invert the bits of interest
  580. bne.s __BitsSetInThisByte
  581. move.b (%a6),%d0
  582. not.b %d0
  583. addq.w #8,%d1
  584. __BitsSetInThisByte:
  585. sub.b 0(%a2,%d0.w),%d1
  586. cmp.b #8,%d1
  587. bcs.s __LessThan7
  588. moveq #8,%d1
  589. addq.w #1,%d7
  590. __LessThan7:
  591. sub.w %d1,%d7
  592. bhi.s __SameByte
  593. addq.w #8,%d7
  594. move.b (%a6)+,%d6
  595. __SameByte:
  596. moveq #0,%d0
  597. subq.b #1,%d1
  598. beq.s __inl_exit4
  599. bset.l %d7,%d0
  600. subq.w #1,%d0
  601. and.b %d6,%d0
  602. sub.w %d1,%d7
  603. bhi.s __StillInSameByte4
  604. move.b (%a6)+,%d6
  605. move.b %d0,-(%a7)
  606. move.w (%a7)+,%d0
  607. move.b %d6,%d0
  608. addq.w #8,%d7
  609. __StillInSameByte4:
  610. lsr.w %d7,%d0
  611. __inl_exit4:
  612. bset.b %d1,%d0
  613. rts
  614. |-----------------------------------------------------------------
  615. | newesc = __GetBits(escbits);
  616. | *outbuffer++ = (startesc<<escbits8) | __GetBits(escbits8);
  617. | startesc = newesc;
  618. | continue;
  619. |-----------------------------------------------------------------
  620. __NextBitIsClear_EscapeFromEscape:
  621. CORRECT_IN_MASK
  622. move.b %d6,-(%a7)
  623. move.w (%a7)+,%d0
  624. move.b (%a6)+,%d0
  625. move.b %d0,%d6
  626. lsr.w %d7,%d0 |get8bits done
  627. move.b %d5,%d1 |save old 'startesc'
  628. move.b %d2,%d5
  629. and.b %d0,%d5 |set the new start esc
  630. not.b %d2
  631. and.b %d2,%d0 |isolate the lower bits
  632. not.b %d2
  633. or.b %d1,%d0 |recombine
  634. move.b %d0,(%a5)+
  635. jmp (%a4)