sunpack.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * GTools C compiler
  3. * =================
  4. * source file :
  5. * precompiled header string unpacking
  6. *
  7. * Copyright 2001-2004 Paul Froissart.
  8. * Credits to Christoph van Wuellen and Matthew Brandt.
  9. * All commercial rights reserved.
  10. *
  11. * This compiler may be redistributed as long there is no
  12. * commercial interest. The compiler must not be redistributed
  13. * without its full sources. This notice must stay intact.
  14. */
  15. #ifdef PC
  16. #include <string.h>
  17. char *sUnpack(char *in,char *out,char *dic) {
  18. char c; char *out0=out;
  19. while ((c=*in++)) {
  20. if ((char)c>=0) *out++=c;
  21. else {
  22. if (c==(char)0x80) *out++=*in++;
  23. else if (c==(char)0xFF) {
  24. } else {
  25. char *dp=dic;
  26. c-=(char)0x81;
  27. while (c--) {
  28. while (*dp++);
  29. }
  30. strcpy(out,dp);
  31. while (*out++); out--;
  32. }
  33. }
  34. }
  35. *out++=0;
  36. return out0;
  37. }
  38. #else
  39. char *__attribute__((stkparm)) sUnpack(char *in,char *out,char *dic);
  40. asm(
  41. " xdef sUnpack\n"
  42. "sUnpack:\n"
  43. "/* bra.s sUnpack*/\n"
  44. " move.l 4(%sp),%a0\n"
  45. " move.l 8(%sp),%a1\n"
  46. " moveq #126,%d1\n"
  47. " moveq #0,%d0\n"
  48. " move.b (%a0)+,%d0\n"
  49. " beq su_quit\n"
  50. " bmi su_special\n"
  51. "su_copy_lp:\n"
  52. " move.b %d0,(%a1)+\n"
  53. "su_next:\n"
  54. " move.b (%a0)+,%d0\n"
  55. " bgt su_copy_lp\n"
  56. " beq su_quit\n"
  57. "su_special:\n"
  58. " subq.b #1,%d0\n"
  59. " bmi su_not_escape\n"
  60. " move.b (%a0)+,(%a1)+\n"
  61. " bra su_next\n"
  62. "su_not_escape:\n"
  63. " addq.b #2,%d0\n"
  64. " bmi su_not_romcall\n"
  65. " \n"
  66. "su_not_romcall:\n"
  67. " add.b %d1,%d0\n"
  68. " move.l %a0,%d2\n"
  69. " move.l 12(%sp),%a0\n"
  70. " dbf %d0,su_search_loop\n"
  71. " bra su_search_done\n"
  72. "su_search_loop:\n"
  73. " tst.b (%a0)+\n"
  74. " bne su_search_loop\n"
  75. " dbf %d0,su_search_loop\n"
  76. "su_search_done:\n"
  77. " move.b (%a0)+,(%a1)+\n"
  78. " bne su_search_done\n"
  79. " subq.w #1,%a1\n"
  80. " move.l %d2,%a0\n"
  81. " moveq #0,%d0\n"
  82. " bra su_next\n"
  83. "su_quit:\n"
  84. " move.b %d0,(%a1)+\n"
  85. " move.l 8(%sp),%a0\n"
  86. " rts");
  87. #endif
  88. // vim:ts=4:sw=4