home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsc / computils / !CompUtils / Resources / ExpCode / asm / s / Example
Encoding:
Text File  |  1995-07-31  |  2.2 KB  |  128 lines

  1. ; buffer sizes
  2. IBUFF    *    16*1024
  3.  
  4. ; define register bindings
  5. R0    RN    0
  6. R1    RN    1
  7. R2    RN    2
  8. R3    RN    3
  9. R4    RN    4
  10. R5    RN    5
  11. R6    RN    6
  12. R7    RN    7
  13. R8    RN    8
  14. R9    RN    9
  15. R10    RN    10
  16. R11    RN    11
  17. R12    RN    12
  18. R13    RN    13
  19. R14    RN    14
  20. R15    RN    15
  21. PC    RN    15
  22.  
  23. ; define SWIs (I hate ObjAsm!)
  24. OS_File            *    &08
  25. OS_GetEnv        *    &10
  26. OS_Exit            *    &11
  27. OS_GenerateError    *    &2B
  28.  
  29.     ; include header file
  30.     GET    CompUtils:ExpCode.asm.h.Universal
  31.  
  32. ; ==========================================================================
  33.  
  34.     AREA    MyCode,CODE,READONLY
  35.  
  36.     IMPORT    |Image$$ZI$$Limit|
  37.  
  38. start
  39.     ENTRY
  40.  
  41.     ; set up stack, workspace and workspace end
  42.     SWI    OS_GetEnv
  43.     MOV    R13,R1                 ; stack ptr
  44.     LDR    R12,=|Image$$ZI$$Limit|  ; workspace ptr
  45.     SUB    R11,R13,#1024         ; workspace limit
  46.     LDR    R6,=ExpCode         ; ptr to ExpCode
  47.  
  48.     ; claim the source buffer
  49.     MOV    R0,#IBUFF
  50.     STR    R0,[R6,#ExpCode_SrcLength]
  51.     BL    claim
  52.     STR    R0,[R6,#ExpCode_SrcBufferPtr]
  53.  
  54.     ; set up output flags
  55.     MOV    R0,#OUTPUT_LINEAR
  56.     STR    R0,[R6,#ExpCode_OutputFlags]
  57.  
  58.     ; set up data offset
  59.     MOV    R0,#0
  60.     STR    R0,[R6,#ExpCode_DataOffset]
  61.  
  62.     ; set up source filename ptr
  63.     ADR    R0,infile
  64.     STR    R0,[R6,#ExpCode_FilenamePtr]
  65.  
  66.     ; initialise the code
  67.     BL    ExpCode_InitCode
  68.     SWIVS    OS_GenerateError
  69.  
  70.     ; claim the destination buffer
  71.     LDR    R0,[R6,#ExpCode_SampleLength]
  72.     STR    R0,[R6,#ExpCode_DestLength]
  73.     BL    claim
  74.     STR    R0,[R6,#ExpCode_DestBufferPtr]
  75.  
  76.     ; decompress the sample
  77.     BL    ExpCode_ProcessCode
  78.     SWIVS    OS_GenerateError
  79.  
  80.     ; finally, save the output and exit
  81.     MOV    R0,#10
  82.     ADR    R1,outfile
  83.     MOV    R2,#&FF0
  84.     ORR    R2,R2,#&00D
  85.     LDR    R4,[R6,#ExpCode_DestBufferPtr]
  86.     LDR    R5,[R6,#ExpCode_SampleLength]
  87.     ADD    R5,R4,R5
  88.     SWI    OS_File
  89.  
  90.     ; exit
  91.     SWI    OS_Exit
  92.  
  93.  
  94. ; --------------------------------------------------------------------------
  95.  
  96. infile    = "RAM:$.Infile",0
  97.     ALIGN
  98.  
  99. outfile = "RAM:$.Outfile",0
  100.     ALIGN
  101.  
  102. ; --------------------------------------------------------------------------
  103.  
  104. claim
  105.     ; r0 = size to claim
  106.     ; r12 = ptr to available workspace
  107.     ; r11 = ptr to end of available workspace
  108.     ; on exit, r0 = ptr to block claimed
  109.     ; an error occurs if not enough memory is available
  110.  
  111.     ADD    R12,R12,R0    ; update ptr
  112.     SUB    R0,R12,R0    ; ptr to new block
  113.     CMP    R12,R11        ; enough memory?
  114.     MOVLE    PC,R14        ; exit if so
  115.  
  116.     ; generate an error
  117.     ADR    R0,claim_error
  118.     SWI    OS_GenerateError
  119.  
  120. claim_error
  121.     &    1
  122.     =    "Not enough memory available",0
  123.     ALIGN
  124.  
  125.  
  126.  
  127.     END
  128.