.TITLE CRUUCR .IDENT /X01.00/ ; ; Author: Gilbert J. DeLeeuw ; Date: May 3, 1984 ; Name: Compress and Restore Utility ; Function: Uncompress a record ; ; Algorithm: Data file compression uses imbedded control bytes which ; contain a character count and bit flag which indicates ; whether the byte following is repeated, or whether the ; byte(s) following are data values. Any time there are ; three or more successive identical bytes in the uncompressed ; record, they are converted to a control byte plus one byte ; to contain the value. ; ; ; Parameters: ; ; R2 - Size of input record ; R3 - Address of input record ; R4 - Size of work buffer ; R5 - Address of work buffer ; ; Output ; R2 - Size of output record ; R3 - Address of output record ; ; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ; Uncompress record CRUUCR:: TST R2 ;TEST FOR VALID LENGTH BEQ 70$ ;ZERO LENGTH RECORD BLT 90$ ;INVALID LENGTH? ; ; Set up stack MOV R5,-(SP) ;SAVE STARTING ADDRESS MOV R4,-(SP) ;SAVE LENGTH CLR R0 ;INITIALIZE OUTPUT COUNT ; ; Decrement input count for control byte 10$: DEC R2 ;DECREMENT INPUT COUNTER BLT 80$ ;ERROR FOUND ; ; Get count and flag MOVB (R3)+,R4 ;GET COUNT AND FLAG BLT 30$ ;BIT 7 SET MEANS REPEAT COUNT ; ; Check buffers to avoid overflow 15$: SUB R4,R2 ;SUBTRACT FROM INPUT COUNT BGE 16$ ;NO OVERFLOW ADD R2,R4 ;MOVE ONLY AVAILABLE CHARACTERS BLE 80$ ;NONE AVAILABLE CLR R2 ;INPUT COUNT WILL BE ZERO ; ; Check output buffer 16$: ADD R4,R0 ;ADD TO OUTPUT COUNT CMP (SP),R0 ;TEST FOR RECORD TOO BIG BLT 80$ ;RECORD TOO BIG ERROR ; ; Move characters from input buffer to output 20$: MOVB (R3)+,(R5)+ ;MOVE A CHARACTER SOB R4,20$ ;LOOP UNTIL COMPLETE BR 50$ ; ; Repeat character specified 30$: BIC #177600,R4 ;CLEAR REPEAT FLAG BEQ 80$ ;NOT MUCH CHANCE, BUT CHECK ANYWAY ; ; Make sure input character is in input buffer DEC R2 ;DECREMENT INPUT LENGTH BLT 80$ ;ERROR ONLY IF NEGATIVE ; ; Copy character to R5 for efficiency MOVB (R3)+,R1 ;COPY REPEAT CHARACTER ; ; Check for output buffer overflow ADD R4,R0 ;ADD TO OUTPUT COUNT CMP (SP),R0 ;RECORD TOO BIG? BLT 80$ ;NO OVERFLOW ; ; Generate characters in output buffer 40$: MOVB R1,(R5)+ ;COPY REPEAT CHARACTER TO OUTPUT SOB R4,40$ ;LOOP UNTIL COMPLETE ; ; Test for more in input buffer 50$: TST R2 ;TEST COUNTER BGT 10$ ;MORE FOUND ; ; Reset registers TST (SP)+ ;POP OUTPUT REC SIZ FROM STACK MOV R0,R2 ;OUTPUT COUNT MOV (SP)+,R3 ;OUTPUT ADDRESS 70$: RTS PC ;AND BACK TO CALLER ; ; Error 80$: ADD #4,SP ;POP VARIABLES FROM STACK 90$: SEC ;SHOW ERROR RTS PC ;RETURN .END