sendbits.s 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. ;===========================================================================
  2. ; Copyright (c) 1990-1999 Info-ZIP. All rights reserved.
  3. ;
  4. ; See the accompanying file LICENSE, version 1999-Oct-05 or later
  5. ; (the contents of which are also included in zip.h) for terms of use.
  6. ; If, for some reason, both of these files are missing, the Info-ZIP license
  7. ; also may be found at: ftp://ftp.cdrom.com/pub/infozip/license.html
  8. ;===========================================================================
  9. ; sendbits.s for ARM by Sergio Monesi and Darren Salt.
  10. r0 RN 0
  11. r1 RN 1
  12. r2 RN 2
  13. r3 RN 3
  14. r4 RN 4
  15. r5 RN 5
  16. r6 RN 6
  17. r7 RN 7
  18. r8 RN 8
  19. r9 RN 9
  20. sl RN 10
  21. fp RN 11
  22. ip RN 12
  23. sp RN 13
  24. lr RN 14
  25. pc RN 15
  26. AREA |Asm$$Code|, CODE, READONLY
  27. = "send_bits",0
  28. ALIGN
  29. & &FF00000C
  30. IMPORT __rt_stkovf_split_small
  31. IMPORT flush_outbuf
  32. IMPORT bi_valid
  33. IMPORT bi_buf
  34. IMPORT out_size
  35. IMPORT out_offset
  36. IMPORT out_buf
  37. EXPORT send_bits
  38. send_bits
  39. MOV ip,sp
  40. STMDB sp!,{r4,r5,fp,ip,lr,pc}
  41. SUB fp,ip,#4
  42. LDR r5,=bi_buf
  43. LDR r3,=bi_valid
  44. LDR r4,[r5]
  45. LDR r2,[r3]
  46. ORR r4,r4,r0,LSL r2 ; |= value<<bi_valid
  47. ADD r2,r2,r1 ; += length
  48. CMP r2,#&10
  49. STRLE r2,[r3] ; short? store & return
  50. STRLE r4,[r5]
  51. LDMLEDB fp,{r4,r5,fp,sp,pc}^
  52. SUB r2,r2,#&10 ; adjust bi_valid, bi_buf
  53. MOV ip,r4,LSR #16 ; (done early, keeping the old bi_buf
  54. STR r2,[r3] ; in R4 for later storage)
  55. STR ip,[r5]
  56. LDR r0,=out_size
  57. LDR r1,=out_offset
  58. LDR r0,[r0]
  59. LDR r2,[r1]
  60. SUB r0,r0,#1
  61. CMP r2,r0 ; if out_offset >= out_size-1
  62. LDRHS r0,=out_buf
  63. LDRHS r0,[r0]
  64. BLHS flush_outbuf ; then flush the buffer
  65. LDR r0,=out_buf
  66. LDR r1,=out_offset
  67. LDR r0,[r0]
  68. LDR r2,[r1]
  69. MOV r5,r4,LSR #8
  70. STRB r4,[r0,r2]! ; store 'old' bi_buf
  71. STRB r5,[r0,#1]
  72. ADD r2,r2,#2
  73. STR r2,[r1]
  74. LDMDB fp,{r4,r5,fp,sp,pc}^
  75. ptr_bi & bi_valid
  76. & bi_buf
  77. = "bi_reverse",0
  78. ALIGN
  79. & &FF00000C
  80. EXPORT bi_reverse
  81. bi_reverse
  82. MOV r2,#0
  83. loop MOVS r0,r0,LSR #1
  84. ADCS r2,r2,r2
  85. SUBS r1,r1,#1
  86. BNE loop
  87. MOV r0,r2
  88. MOVS pc,lr
  89. END