home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / TEXT / UTILITY / UNBOX.ZIP / UNBOX.ASM next >
Encoding:
Assembly Source File  |  1990-06-09  |  3.7 KB  |  131 lines

  1. ; Program to swap IBM PC text graphics
  2. ; characters for something more printable.
  3. ; Much code cribbed from PC Magazine's PRSWAP.ASM (V4N19),
  4. ; but we use StdIn and StdOut instead of printer output.
  5.  
  6. CSEG    SEGMENT PUBLIC PARA 'CODE'
  7.     ASSUME    CS:CSEG, DS:CSEG,ES:CSEG, SS:NOTHING
  8.  
  9.     org    100h            ; COM program format
  10. ;
  11. Unbox    PROC    NEAR
  12.     jmp    Start            ;skip over runtime data
  13. ;
  14. ; Swap table to translate (XLAT) characters to be printed
  15. ;
  16. swap_table    db    '&'             ; Char 176      Graphic Fill
  17.         db    '%'             ; Char 177      Graphic Fill
  18.         db    '@'             ; Char 178      Graphic Fill
  19.         db    4 dup ('|')     ; Char 179-182  Vertical
  20.         db    2 dup ('*')     ; Char 183-184  Corner
  21.         db    2 dup ('|')     ; Char 185-186  Vertical
  22.         db    6 dup ('*')     ; Char 187-192  Corner
  23.         db    2 dup ('-')     ; Char 193-194  Horizontal
  24.         db    '|'             ; Char 195      Vertical
  25.         db    '-'             ; Char 196      Horizontal
  26.         db    '+'             ; Char 197      Intersection
  27.         db    2 dup ('|')     ; Char 198-199  Vertical
  28.         db    2 dup ('*')     ; Char 200-201  Corner
  29.         db    2 dup ('-')     ; Char 202-203  Horizontal
  30.         db    '|'             ; Char 204      Vertical
  31.         db    '-'             ; Char 205      Horizontal
  32.         db    '+'             ; Char 206      Intersection
  33.         db    4 dup ('-')     ; Char 207-210  Horizontal
  34.         db    4 dup ('*')     ; Char 211-214  Corner
  35.         db    2 dup ('+')     ; Char 215-216  Intersection
  36.         db    2 dup ('*')     ; Char 217-218  Corner
  37.         db    '#'             ; Char 219      Graphic Fill
  38.         db    '.'             ; Char 220      Graphic Fill
  39.         db    '{'             ; Char 221      Graphic Fill
  40.         db    '}'             ; Char 222      Graphic Fill
  41.         db    '^'             ; Char 223      Graphic Fill
  42.  
  43. eofflag    db    0
  44.  
  45. ; Miscellaneous equates
  46. ;
  47. LOWEST_CHAR    equ    176        ; Lowest graphic char in table
  48. HIGHEST_CHAR    equ    223        ; Highest graphic char in table
  49. LOZENGE     equ    254        ; Lozenge character position
  50.  
  51. STDIN    EQU    0
  52. STDOUT    EQU    1
  53.  
  54. Unbox    ENDP
  55.  
  56. Start    PROC    NEAR
  57.  
  58.     mov    dx,offset buff        ;read/write buff
  59.  
  60. FileLup:
  61.     cmp    eofflag,0        ;last read an EOF?
  62.     jnz    HitEof            ;yep
  63.  
  64.     mov    cx,BUFFSIZE
  65.     xor    bx,bx    ;0        ;read from StdIn
  66.     mov    ah,3FH            ;read from file/device
  67.     int    21H
  68.     jb    FilError        ;read error, close down
  69.  
  70.     cmp    ax,cx            ;read all we asked for?
  71.     adc    eofflag,0        ;if not, EOF flag is set
  72.     mov    cx,ax            ;bytes read into CX
  73.     jcxz    Done            ;all done
  74.  
  75.     call    Swap            ;convert the buffer
  76.     mov    dx,offset buff
  77.     mov    cx,di            ;last byte processed +1
  78.     sub    cx,dx            ;- start = bytes processed
  79.     mov    bx,STDOUT        ;write to StdOut
  80.     mov    ah,40H            ;write to file/device
  81.     int    21H
  82.     jnb    FileLup            ;next buffer, please
  83.     jmp    short FilError        ;write error, die
  84.  
  85. HitEof:
  86.     xor    al,al            ;errorlevel 0
  87. Done:
  88. FilError:
  89.     mov    ah,4CH            ;terminate, ERRORLEVEL in AL
  90.     int    21H
  91.  
  92. Start    ENDP
  93.  
  94.  
  95. Swap    PROC    NEAR
  96.  
  97.     mov    si,dx            ;read/write buffer
  98.     mov    di,si            ;align output with source
  99.     mov    bx,offset swap_table    ; Point to translate table with BX
  100.     mov    dx,(HIGHEST_CHAR SHL 8) + LOWEST_CHAR
  101.     mov    ah,LOZENGE        ;last possible test constant
  102.  
  103. SwapLup:
  104.     lodsb
  105.     cmp    al,dl    ;LOWEST_CHAR    ; Is char to print below table range?
  106.     jb    NoSwap            ;yep, forget it
  107.     cmp    al,dh    ;HIGHEST_CHAR     ; Is char to print above table range
  108.     ja    Check_Lozenge        ; Yes, check for lozenge char
  109.      sub    al,dl    ;LOWEST_CHAR    ; Adjust AL for bias into table
  110.      xlat                ; Translate to PrSwap's character
  111.      jmp    short Swapped
  112.  
  113. Check_Lozenge:                ; Check for char 254
  114.     cmp    al,ah    ;LOZENGE    ; Is char to print the lozenge?
  115.     jne    NoSwap            ; nope, forget it
  116.      mov    al,'='                  ; Make it a '='
  117. Swapped:
  118.     mov    [di],al            ;stuff swapped char
  119. NoSwap:
  120.     inc    di            ;bump to coincide with SI
  121.     loop    SwapLup
  122.     ret
  123.  
  124. Swap    ENDP
  125.  
  126. buff    label    byte            ;dynamic buffer from here on
  127. BUFFSIZE    EQU    60000        ;likely size
  128.  
  129. CSEG    ENDS
  130.     END    Unbox
  131.