; TheDraw crunched ansi on screen

.MODEL TPASCAL
.DATA
       EXTRN VIDSEG:WORD
.CODE
UNCRUNCH PROC PASCAL near IMAGEDATA_LENGTH:WORD, IMAGEDATA:DWORD
       PUBLIC UNCRUNCH

       MOV     ES, [VIDSEG]
       MOV     CX, IMAGEDATA_LENGTH
       LDS     SI, IMAGEDATA
       XOR     DI, DI

       MOV     DX, DI
       XOR     AX, AX
       CLD

LOOPA:
       LODSB
       CMP     AL, 27
       JNZ     ForeGround
       XOR     AH, 128
       JMP     SHORT NEXT

FOREGROUND:
       CMP     AL, 16
       JNC     BackGround
       AND     AH, 70H
       OR      AH, AL
       JMP     SHORT NEXT

BACKGROUND:
       CMP     AL, 24
       JZ      NEXTLINE
       JNC     MultiOutput
       SUB     AL, 16
       ADD     AL, AL
       ADD     AL, AL
       ADD     AL, AL
       ADD     AL, AL
       AND     AH, 8FH
       OR      AH, AL
       JMP     SHORT NEXT

NEXTLINE:
       ADD     DX, 160
       MOV     DI, DX
       JMP     SHORT NEXT

MULTIOUTPUT:
       CMP     AL, 25
       JNZ     NOTMULTISPACES
       LODSB
       PUSH    CX
       XOR     CH, CH
       MOV     CL, AL
       MOV     AL, 32
       JMP     SHORT STARTOUTPUT

NOTMULTISPACES:
       CMP     AL, 26
       JNZ     NORMALLETTER
       LODSB
       DEC     CX
       PUSH    CX
       XOR     CH, CH
       MOV     CL, AL
       LODSB

STARTOUTPUT:
       JCXZ    Stop
LOOPB:
       STOSW
       LOOP    LOOPB
STOP:
       POP     CX
       DEC     CX

NORMALLETTER:
       STOSW

NEXT:
       JCXZ    DONE
       LOOP    LOOPA

DONE:
       RET

UNCRUNCH  ENDP

END
