home *** CD-ROM | disk | FTP | other *** search
- ; buffer sizes
- IBUFF * 16*1024
- OBUFF * 16*1024
-
- ; define register bindings
- R0 RN 0
- R1 RN 1
- R2 RN 2
- R3 RN 3
- R4 RN 4
- R5 RN 5
- R6 RN 6
- R7 RN 7
- R8 RN 8
- R9 RN 9
- R10 RN 10
- R11 RN 11
- R12 RN 12
- R13 RN 13
- R14 RN 14
- R15 RN 15
- PC RN 15
-
- ; define SWIs (I hate ObjAsm!)
- OS_File * &08
- OS_GBPB * &0C
- XOS_GBPB * OS_GBPB + (1:SHL:17)
- OS_Find * &0D
- XOS_Find * OS_Find + (1:SHL:17)
- OS_GetEnv * &10
- OS_Exit * &11
- OS_GenerateError * &2B
-
- ; include header file
- GET CompUtils:Expand.asm.h.Universal
-
- ; ==========================================================================
-
- AREA MyCode,CODE,READONLY
-
- IMPORT |Image$$ZI$$Limit|
-
- start
- ENTRY
-
- ; set up stack, workspace and workspace end
- SWI OS_GetEnv
- MOV R13,R1 ; stack ptr
- LDR R12,=|Image$$ZI$$Limit| ; workspace ptr
- SUB R11,R13,#1024 ; workspace limit
- LDR R6,=Expand ; ptr to Expand
-
- ; claim the source buffer
- MOV R0,#IBUFF
- STR R0,[R6,#Expand_SrcLength]
- BL claim
- STR R0,[R6,#Expand_SrcBufferPtr]
-
- ; claim the destination buffer
- MOV R0,#OBUFF
- STR R0,[R6,#Expand_DestLength]
- BL claim
- STR R0,[R6,#Expand_DestBufferPtr]
-
- ; set up reason code
- MOV R0,#0
- STR R0,[R6,#Expand_ReasonCode]
-
- ; set up output flags
- MOV R0,#OUTPUT_LINEAR
- STR R0,[R6,#Expand_OutputFlags]
-
- ; open source file
- MOV R0,#&4C
- ADR R1,infile
- SWI OS_Find
- MOVS R8,R0 ; input handle
- ADREQ R0,openinerror
- SWIEQ OS_GenerateError
-
- ; open destination file
- MOV R7,#0
- MOV R0,#&8C
- ADR R1,outfile
- SWI XOS_Find
- BVS close_and_error
- MOVS R7,R0 ; output handle
- ADREQ R0,openinerror
- BEQ close_and_error
-
- mainloop
- ; call Expand
- STMFD R13!,{R11,R12,R7,R8,R6}
- BL Expand
- LDMFD R13!,{R11,R12,R7,R8,R6}
-
- ; process reason code
- ; r0 = reason code
- CMP R0,#9
- ADDCC PC,PC,R0,LSL #2
- BCS dont_recognise_code
- ; jump table
- B finished
- B src_empty
- B dest_full
- B init_done
- B dont_recognise_code
- B dont_recognise_code ; src error - shouldn't occur
- B dont_recognise_code ; dest error - shouldn't occur
- B dont_recognise_code
- B unknown_format
-
- src_empty
- ; refill source buffer
- MOV R0,#4
- MOV R1,R8
- LDR R2,[R6,#Expand_SrcBufferPtr]
- MOV R3,#IBUFF
- SWI XOS_GBPB
- BVS close_and_error
- B mainloop
-
- dest_full
- ; output destination buffer
- MOV R0,#2
- MOV R1,R7
- LDR R2,[R6,#Expand_DestBufferPtr]
- LDR R3,[R6,#Expand_BytesWritten]
- SWI XOS_GBPB
- BVS close_and_error
- B mainloop
-
- init_done
- ; output the sample period - it's an Armadeus file
- MOV R0,#2
- MOV R1,R7
- ADD R2,R6,#Expand_SamplePeriod
- MOV R3,#1
- SWI XOS_GBPB
- BVS close_and_error
- B mainloop
-
- finished
- ; close destination file
- MOV R0,#0
- MOVS R1,R7
- SWINE XOS_Find
- MOV R7,#0
-
- ; close source file
- MOV R0,#0
- MOVS R1,R8
- SWINE XOS_Find
- MOV R8,#0
-
- ; exit
- SWI OS_Exit
-
- ; --------------------------------------------------------------------------
-
- dont_recognise_code
- ADR R0,dont_recognise_error
- B close_and_error
- dont_recognise_error
- & 1
- = "Invalid reason code returned from Expand",0
- ALIGN
-
-
- unknown_format
- ADR R0,unknown_format_error
- B close_and_error
- unknown_format_error
- & 1
- = "Unrecognised file format",0
- ALIGN
-
- ; --------------------------------------------------------------------------
-
- close_and_error
- ; save error
- STMFD R13!,{R0}
-
- ; close destination file
- MOV R0,#0
- MOVS R1,R7
- SWINE XOS_Find
- MOV R7,#0
-
- ; close source file
- MOV R0,#0
- MOVS R1,R8
- SWINE XOS_Find
- MOV R8,#0
-
- ; generate error
- LDMFD R13!,{R0}
- SWI OS_GenerateError
-
- ; --------------------------------------------------------------------------
-
- infile = "RAM:$.Infile",0
- ALIGN
-
- outfile = "RAM:$.Outfile",0
- ALIGN
-
- openinerror
- & 1
- = "Unable to open input file",0
- ALIGN
-
- openouterror
- & 1
- = "Unable to open output file",0
- ALIGN
-
- ; --------------------------------------------------------------------------
-
- claim
- ; r0 = size to claim
- ; r12 = ptr to available workspace
- ; r11 = ptr to end of available workspace
- ; on exit, r0 = ptr to block claimed
- ; an error occurs if not enough memory is available
-
- ADD R12,R12,R0 ; update ptr
- SUB R0,R12,R0 ; ptr to new block
- CMP R12,R11 ; enough memory?
- MOVLE PC,R14 ; exit if so
-
- ; generate an error
- ADR R0,claim_error
- SWI OS_GenerateError
-
- claim_error
- & 1
- = "Not enough memory available",0
- ALIGN
-
-
-
- END
-