home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsc / computils / !CompUtils / Resources / Expand / asm / s / Example
Encoding:
Text File  |  1995-08-03  |  4.1 KB  |  244 lines

  1. ; buffer sizes
  2. IBUFF    *    16*1024
  3. OBUFF    *    16*1024
  4.  
  5. ; define register bindings
  6. R0    RN    0
  7. R1    RN    1
  8. R2    RN    2
  9. R3    RN    3
  10. R4    RN    4
  11. R5    RN    5
  12. R6    RN    6
  13. R7    RN    7
  14. R8    RN    8
  15. R9    RN    9
  16. R10    RN    10
  17. R11    RN    11
  18. R12    RN    12
  19. R13    RN    13
  20. R14    RN    14
  21. R15    RN    15
  22. PC    RN    15
  23.  
  24. ; define SWIs (I hate ObjAsm!)
  25. OS_File            *    &08
  26. OS_GBPB            *    &0C
  27. XOS_GBPB        *    OS_GBPB + (1:SHL:17)
  28. OS_Find            *    &0D
  29. XOS_Find        *    OS_Find + (1:SHL:17)
  30. OS_GetEnv        *    &10
  31. OS_Exit            *    &11
  32. OS_GenerateError    *    &2B
  33.  
  34.     ; include header file
  35.     GET    CompUtils:Expand.asm.h.Universal
  36.  
  37. ; ==========================================================================
  38.  
  39.     AREA    MyCode,CODE,READONLY
  40.  
  41.     IMPORT    |Image$$ZI$$Limit|
  42.  
  43. start
  44.     ENTRY
  45.  
  46.     ; set up stack, workspace and workspace end
  47.     SWI    OS_GetEnv
  48.     MOV    R13,R1                 ; stack ptr
  49.     LDR    R12,=|Image$$ZI$$Limit|  ; workspace ptr
  50.     SUB    R11,R13,#1024         ; workspace limit
  51.     LDR    R6,=Expand         ; ptr to Expand
  52.  
  53.     ; claim the source buffer
  54.     MOV    R0,#IBUFF
  55.     STR    R0,[R6,#Expand_SrcLength]
  56.     BL    claim
  57.     STR    R0,[R6,#Expand_SrcBufferPtr]
  58.  
  59.     ; claim the destination buffer
  60.     MOV    R0,#OBUFF
  61.     STR    R0,[R6,#Expand_DestLength]
  62.     BL    claim
  63.     STR    R0,[R6,#Expand_DestBufferPtr]
  64.  
  65.     ; set up reason code
  66.     MOV    R0,#0
  67.     STR    R0,[R6,#Expand_ReasonCode]
  68.  
  69.     ; set up output flags
  70.     MOV    R0,#OUTPUT_LINEAR
  71.     STR    R0,[R6,#Expand_OutputFlags]
  72.  
  73.     ; open source file
  74.     MOV    R0,#&4C
  75.     ADR    R1,infile
  76.     SWI    OS_Find
  77.     MOVS    R8,R0        ; input handle
  78.     ADREQ    R0,openinerror
  79.     SWIEQ    OS_GenerateError
  80.  
  81.     ; open destination file
  82.     MOV    R7,#0
  83.     MOV    R0,#&8C
  84.     ADR    R1,outfile
  85.     SWI    XOS_Find
  86.     BVS    close_and_error
  87.     MOVS    R7,R0        ; output handle
  88.     ADREQ    R0,openinerror
  89.     BEQ    close_and_error
  90.  
  91. mainloop
  92.     ; call Expand
  93.     STMFD    R13!,{R11,R12,R7,R8,R6}
  94.     BL    Expand
  95.     LDMFD    R13!,{R11,R12,R7,R8,R6}
  96.  
  97.     ; process reason code
  98.     ; r0 = reason code
  99.     CMP    R0,#9
  100.     ADDCC    PC,PC,R0,LSL #2
  101.     BCS    dont_recognise_code
  102.     ; jump table
  103.     B    finished
  104.     B    src_empty
  105.     B    dest_full
  106.     B    init_done
  107.     B    dont_recognise_code
  108.     B    dont_recognise_code ; src error - shouldn't occur
  109.     B    dont_recognise_code ; dest error - shouldn't occur
  110.     B    dont_recognise_code
  111.     B    unknown_format
  112.  
  113. src_empty
  114.     ; refill source buffer
  115.     MOV    R0,#4
  116.     MOV    R1,R8
  117.     LDR    R2,[R6,#Expand_SrcBufferPtr]
  118.     MOV    R3,#IBUFF
  119.     SWI    XOS_GBPB
  120.     BVS    close_and_error
  121.     B    mainloop
  122.  
  123. dest_full
  124.     ; output destination buffer
  125.     MOV    R0,#2
  126.     MOV    R1,R7
  127.     LDR    R2,[R6,#Expand_DestBufferPtr]
  128.     LDR    R3,[R6,#Expand_BytesWritten]
  129.     SWI    XOS_GBPB
  130.     BVS    close_and_error
  131.     B    mainloop
  132.  
  133. init_done
  134.     ; output the sample period - it's an Armadeus file
  135.     MOV    R0,#2
  136.     MOV    R1,R7
  137.     ADD    R2,R6,#Expand_SamplePeriod
  138.     MOV    R3,#1
  139.     SWI    XOS_GBPB
  140.     BVS    close_and_error
  141.     B    mainloop
  142.  
  143. finished
  144.     ; close destination file
  145.     MOV    R0,#0
  146.     MOVS    R1,R7
  147.     SWINE    XOS_Find
  148.     MOV    R7,#0
  149.  
  150.     ; close source file
  151.     MOV    R0,#0
  152.     MOVS    R1,R8
  153.     SWINE    XOS_Find
  154.     MOV    R8,#0
  155.  
  156.     ; exit
  157.     SWI    OS_Exit
  158.  
  159. ; --------------------------------------------------------------------------
  160.  
  161. dont_recognise_code
  162.     ADR    R0,dont_recognise_error
  163.     B    close_and_error
  164. dont_recognise_error
  165.     &    1
  166.     =    "Invalid reason code returned from Expand",0
  167.     ALIGN
  168.  
  169.  
  170. unknown_format
  171.     ADR    R0,unknown_format_error
  172.     B    close_and_error
  173. unknown_format_error
  174.     &    1
  175.     =    "Unrecognised file format",0
  176.     ALIGN
  177.  
  178. ; --------------------------------------------------------------------------
  179.  
  180. close_and_error
  181.     ; save error
  182.     STMFD    R13!,{R0}
  183.  
  184.     ; close destination file
  185.     MOV    R0,#0
  186.     MOVS    R1,R7
  187.     SWINE    XOS_Find
  188.     MOV    R7,#0
  189.  
  190.     ; close source file
  191.     MOV    R0,#0
  192.     MOVS    R1,R8
  193.     SWINE    XOS_Find
  194.     MOV    R8,#0
  195.  
  196.     ; generate error
  197.     LDMFD    R13!,{R0}
  198.     SWI    OS_GenerateError
  199.  
  200. ; --------------------------------------------------------------------------
  201.  
  202. infile    = "RAM:$.Infile",0
  203.     ALIGN
  204.  
  205. outfile = "RAM:$.Outfile",0
  206.     ALIGN
  207.  
  208. openinerror
  209.     &    1
  210.     =    "Unable to open input file",0
  211.     ALIGN
  212.  
  213. openouterror
  214.     &    1
  215.     =    "Unable to open output file",0
  216.     ALIGN
  217.  
  218. ; --------------------------------------------------------------------------
  219.  
  220. claim
  221.     ; r0 = size to claim
  222.     ; r12 = ptr to available workspace
  223.     ; r11 = ptr to end of available workspace
  224.     ; on exit, r0 = ptr to block claimed
  225.     ; an error occurs if not enough memory is available
  226.  
  227.     ADD    R12,R12,R0    ; update ptr
  228.     SUB    R0,R12,R0    ; ptr to new block
  229.     CMP    R12,R11        ; enough memory?
  230.     MOVLE    PC,R14        ; exit if so
  231.  
  232.     ; generate an error
  233.     ADR    R0,claim_error
  234.     SWI    OS_GenerateError
  235.  
  236. claim_error
  237.     &    1
  238.     =    "Not enough memory available",0
  239.     ALIGN
  240.  
  241.  
  242.  
  243.     END
  244.