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
11r0      RN      0
12r1      RN      1
13r2      RN      2
14r3      RN      3
15r4      RN      4
16r5      RN      5
17r6      RN      6
18r7      RN      7
19r8      RN      8
20r9      RN      9
21sl      RN      10
22fp      RN      11
23ip      RN      12
24sp      RN      13
25lr      RN      14
26pc      RN      15
27
28        AREA    |Asm$$Code|, CODE, READONLY
29
30        =       "send_bits",0
31        ALIGN
32        &       &FF00000C
33
34        IMPORT  __rt_stkovf_split_small
35        IMPORT  flush_outbuf
36
37        IMPORT  bi_valid
38        IMPORT  bi_buf
39        IMPORT  out_size
40        IMPORT  out_offset
41        IMPORT  out_buf
42
43        EXPORT  send_bits
44send_bits
45        MOV     ip,sp
46        STMDB   sp!,{r4,r5,fp,ip,lr,pc}
47        SUB     fp,ip,#4
48        LDR     r5,=bi_buf
49        LDR     r3,=bi_valid
50        LDR     r4,[r5]
51        LDR     r2,[r3]
52        ORR     r4,r4,r0,LSL r2 ; |= value<<bi_valid
53        ADD     r2,r2,r1        ; += length
54        CMP     r2,#&10
55        STRLE   r2,[r3]         ; short? store & return
56        STRLE   r4,[r5]
57        LDMLEDB fp,{r4,r5,fp,sp,pc}^
58
59        SUB     r2,r2,#&10      ; adjust bi_valid, bi_buf
60        MOV     ip,r4,LSR #16   ;  (done early, keeping the old bi_buf
61        STR     r2,[r3]         ;  in R4 for later storage)
62        STR     ip,[r5]
63
64        LDR     r0,=out_size
65        LDR     r1,=out_offset
66        LDR     r0,[r0]
67        LDR     r2,[r1]
68        SUB     r0,r0,#1
69        CMP     r2,r0           ; if out_offset >= out_size-1
70        LDRHS   r0,=out_buf
71        LDRHS   r0,[r0]
72        BLHS    flush_outbuf    ; then flush the buffer
73        LDR     r0,=out_buf
74        LDR     r1,=out_offset
75        LDR     r0,[r0]
76        LDR     r2,[r1]
77        MOV     r5,r4,LSR #8
78        STRB    r4,[r0,r2]!     ; store 'old' bi_buf
79        STRB    r5,[r0,#1]
80        ADD     r2,r2,#2
81        STR     r2,[r1]
82
83        LDMDB   fp,{r4,r5,fp,sp,pc}^
84
85
86ptr_bi          &       bi_valid
87                &       bi_buf
88
89
90        =       "bi_reverse",0
91        ALIGN
92        &       &FF00000C
93
94        EXPORT  bi_reverse
95bi_reverse
96        MOV     r2,#0
97loop    MOVS    r0,r0,LSR #1
98        ADCS    r2,r2,r2
99        SUBS    r1,r1,#1
100        BNE     loop
101        MOV     r0,r2
102        MOVS    pc,lr
103
104
105        END
106