home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / zip21.zip / acorn / sendbits.s < prev    next >
Text File  |  1996-04-05  |  3KB  |  156 lines

  1. ;
  2. ; Copyright (C) 1990-1996 Mark Adler, Richard B. Wales, Jean-loup Gailly,
  3. ; Onno van der Linden, Kai Uwe Rommel, Igor Mandrichenko, Sergio Monesi and
  4. ; Karl Davis.
  5. ; Permission is granted to any individual or institution to use, copy, or
  6. ; redistribute this software so long as all of the original files are included,
  7. ; that it is not sold for profit, and that this copyright notice is retained.
  8. ;
  9. ; sendbits.s for ARM by Sergio Monesi.
  10.  
  11. r0 RN 0
  12. r1 RN 1
  13. r2 RN 2
  14. r3 RN 3
  15. r4 RN 4
  16. r5 RN 5
  17. r6 RN 6
  18. r7 RN 7
  19. r8 RN 8
  20. r9 RN 9
  21. sl RN 10
  22. fp RN 11
  23. ip RN 12
  24. sp RN 13
  25. lr RN 14
  26. pc RN 15
  27.  
  28.                 AREA    |C$$code|, CODE, READONLY
  29.  
  30. ; r1 = ....
  31.  
  32. |__bi_buf|
  33.         IMPORT  bi_buf
  34.         DCD     bi_buf
  35. |__bi_valid|
  36.         IMPORT  bi_valid
  37.         DCD     bi_valid
  38. |__out_buf|
  39.         IMPORT  out_buf
  40.         DCD     out_buf
  41. |__out_size|
  42.         IMPORT  out_size
  43.         DCD     out_size
  44. |__out_offset|
  45.         IMPORT out_offset
  46.         DCD    out_offset
  47.  
  48.         IMPORT  flush_outbuf
  49.         IMPORT  |x$stack_overflow|
  50.  
  51.         DCB     "send_bits"
  52.         DCB     &00,&00,&00
  53.         DCD     &ff00000c
  54.  
  55.         EXPORT  send_bits
  56. send_bits
  57.         LDR     r2, [pc, #|__bi_valid|-.-8]
  58.         LDR     r2, [r2]
  59.         RSB     r3, r1, #16
  60.         CMP     r2, r3
  61.         BLE     send_part2
  62.  
  63.         LDR     r3, [pc, #|__bi_buf|-.-8]
  64.         LDR     ip, [r3]
  65.         ORR     ip, ip, r0, LSL r2
  66.         STR     ip, [r3]
  67.  
  68.         LDR     r2, [pc, #|__out_offset|-.-8]
  69.         LDR     r2, [r2]
  70.         LDR     r3, [pc, #|__out_size|-.-8]
  71.         LDR     r3, [r3]
  72.         SUB     r3, r3, #1
  73.         CMP     r2, r3
  74.         BCS     send_flush
  75.  
  76.         STMFD   sp!, {r4-r6,lr}
  77.  
  78.         MOV     r6, #1
  79.  
  80.         LDR     r4, [pc, #|__out_buf|-.-8]
  81.         LDR     r4, [r4]
  82.  
  83.         AND     r5, ip, #&FF
  84.         STRB    r5, [r4, r2]
  85.         ADD     r2, r2, #1
  86.         MOV     r5, ip, LSR #8
  87.         STRB    r5, [r4, r2]
  88.         ADD     r2, r2, #1
  89.         LDR     r4, [pc, #|__out_offset|-.-8]
  90.         STR     r2, [r4]
  91.         B       send_cont
  92.  
  93. send_flush
  94.         MOV     r3, ip
  95.         MOV     ip, sp
  96.         STMFD   sp!, {r4-r6,fp,ip,lr,pc}
  97.         SUB     fp, ip, #4
  98.         CMPS    sp, sl
  99.         BLLT    |x$stack_overflow|
  100.         MOV     r4, r0
  101.         MOV     r5, r1
  102.         MOV     r0, r3
  103.         MOV     r1, #2
  104.         BL      flush_outbuf
  105.         MOV     r0, r4
  106.         MOV     r1, r5
  107.  
  108.         MOV     r6, #0
  109.  
  110. send_cont
  111.         LDR     r2, [pc, #|__bi_valid|-.-8]
  112.         LDR     r3, [r2]
  113.         RSB     r3, r3, #16
  114.         LDR     r4, [pc, #|__bi_buf|-.-8]
  115.         MOV     r5, r0, LSR r3
  116.         STR     r5, [r4]
  117.         LDR     r3, [r2]
  118.         ADD     r3, r3, r1
  119.         SUB     r3, r3, #16
  120.         STR     r3, [r2]
  121.  
  122.         CMP     r6, #0
  123.         LDMEQEA fp, {r4-r6,fp,sp,pc}^
  124.         LDMNEFD sp!, {r4-r6,pc}^
  125.  
  126. send_part2
  127.         LDR     r3, [pc, #|__bi_buf|-.-8]
  128.         LDR     ip, [r3]
  129.         ORR     ip, ip, r0, LSL r2
  130.         STR     ip, [r3]
  131.  
  132.         LDR     r3, [pc, #|__bi_valid|-.-8]
  133.         ADD     r2, r2, r1
  134.         STR     r2, [r3]
  135.  
  136.         MOVS    pc, lr
  137.  
  138.  
  139.         DCB     "bi_reverse"
  140.         DCB     &00,&00
  141.         DCD     &ff00000c
  142.  
  143.         EXPORT  bi_reverse
  144. bi_reverse
  145.         MOV     r2, #0
  146. rev_cycle
  147.         MOVS    r0, r0, LSR #1
  148.         ADCS    r2, r2, r2
  149.         SUBS    r1, r1, #1
  150.         BNE     rev_cycle
  151.         MOV     r0, r2
  152.         MOVS    pc, lr
  153.  
  154.         END
  155.  
  156.