home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Mib / ANSI.ZIP / ASTAN.ASM < prev    next >
Assembly Source File  |  1999-01-26  |  6KB  |  319 lines

  1.     DOSSEG
  2.     .MODEL SMALL
  3.     .STACK 200h
  4.     .DATA
  5.  
  6. ;===- Data -===
  7.  
  8. BufferSeg    dw  0
  9.  
  10. ErrMsgOpen   db  "Error opening `"
  11. AsciiName    db  "ANSI.TXT",0,8,"'$"     ;8 is a delete character
  12. ErrMsgWrite  db  "Error writing file","$"
  13. AnsiName     db  "ANSI.ans",0
  14. ErrMsgCreate db  "Error creating file","$"
  15. FileHandle   dw  0
  16. FileHandle2  dw  0
  17. LastPage     dw  0
  18. WriteByte    db  0
  19. ReadByte     db  0
  20. ColorByte    db  0Fh
  21. FileSize     dw  0
  22. CharsLeft    db  0
  23.  
  24. Screen1      db  4000 dup(?)
  25. FileIndex    dw  0
  26. FileIndex2   dw  0
  27.  
  28. include         key.inc         
  29.  
  30. ; 00 black
  31. ; 01 blue                                          7  6  5  4  3  2  1  0
  32. ; 02 green                                         |  |  |  |  |  |  |  |
  33. ; 03 blue-green                                    |  |  |  |  |  \---------  foreground
  34. ; 04 red                                           |  |  |  |  \------------  intensity
  35. ; 05 cyan                                          |  \---------------------  background
  36. ; 06 magenta                                       \------------------------  blinking  
  37. ; 07 light grey
  38. ; 08 dark-grey
  39. ; 09 light blue
  40. ; 10 light green
  41. ; 11 light blue-green
  42. ; 12 light red
  43. ; 13 light cyan
  44. ; 14 light brown
  45. ; 15 white
  46.  
  47.  
  48.  
  49.     .CODE
  50.     Ideal
  51.     jumps
  52.  
  53.  
  54.  
  55. MACRO WaitVRetrace    
  56.                 LOCAL   VRetrace,NoVRetrace
  57.                 mov     dx,03dah
  58. VRetrace:       in      al,dx
  59.                 test    al,00001000b
  60.                 jnz     VRetrace
  61. NoVRetrace:     in      al,dx
  62.                 test    al,00001000b
  63.                 jz      NoVRetrace
  64. ENDM
  65.  
  66. ;===- Subroutines -===
  67.  
  68. PROC OpenFile NEAR
  69.  
  70.     mov     ax,3d00h    ;open file (ah=3dh)
  71.     mov     dx,offset AsciiName
  72.     int     21h
  73.     jc      OpenError
  74.     mov     [FileHandle],ax       ;move the file handle into bx
  75.  
  76.  
  77. ;    mov     ah,3eh
  78. ;    int     21h             ;close the file
  79.  
  80.     ret
  81.  
  82. OpenError:
  83.     mov     ah,9
  84.     mov     dx,offset ErrMsgOpen
  85.     int     21h
  86.  
  87.     ret
  88. ENDP OpenFile
  89.  
  90. PROC WriteFile NEAR
  91.  
  92.     mov     bx,[FileHandle2]
  93.     mov     dx,offset WriteByte
  94.     mov     ah,40h
  95.     mov     cx,01h
  96.     int     21h
  97.     cmp     [CharsLeft], 64
  98.     jl      Test1
  99.     mov     [ColorByte], 08
  100.     jmp     WriteColor
  101.  
  102. Test1:
  103.     cmp     [CharsLeft], 48
  104.     jl      Test2
  105.     mov     [ColorByte], 07 
  106.     jmp     WriteColor
  107.  
  108. Test2:
  109.     cmp     [CharsLeft], 32
  110.     jl      Test3
  111.     mov     [ColorByte], 15 
  112.     jmp     WriteColor
  113.  
  114. Test3:
  115.     cmp     [CharsLeft], 16
  116.     jl      Test4
  117.     mov     [ColorByte], 07 
  118.     jmp     WriteColor
  119.                           
  120. Test4:
  121.     mov     [ColorByte], 08 
  122.  
  123. WriteColor:
  124.     mov     bx,[FileHandle2]
  125.     mov     dx,offset ColorByte
  126.     mov     ah,40h
  127.     mov     cx,01h
  128.     int     21h
  129.  
  130.     cmp     cx,ax
  131.     jne     WriteError
  132.     ret
  133.  
  134. WriteError:
  135.     mov     ah,9
  136.     mov     dx,offset ErrMsgWrite
  137.     int     21h
  138.     ret
  139.  
  140.  
  141.  
  142. ENDP WriteFile
  143.  
  144. PROC CreateFile
  145.  
  146.     mov     ah,3ch
  147.     mov     dx,offset AnsiName
  148.     mov     cx,0        ;no attributes
  149.     int     21h
  150.     jc      CreateError
  151.  
  152.     mov     [FileHandle2],ax
  153.  
  154.     ret
  155.  
  156. CreateError:
  157.     mov     ah,9
  158.     mov     dx,offset ErrMsgCreate
  159.     int     21h
  160.     ret
  161.  
  162. ENDP CreateFile
  163.  
  164.  
  165.  
  166.  
  167.  
  168. PROC ReadNext NEAR
  169.     
  170.     push    bx
  171.     push    dx
  172.  
  173.     xor     ax, ax
  174.     mov     bx, [FileHandle]
  175.     mov     dx,offset ReadByte
  176.     mov     ah,3fh
  177.     mov     cx,01h       ;read byte
  178.     int     21h
  179.  
  180.     pop     dx
  181.     pop     bx
  182.     
  183.     ret
  184. ENDP ReadNext
  185.  
  186. PROC MovePtr1 NEAR
  187.  
  188.     push    ax
  189.     push    bx
  190.     push    cx
  191.     push    dx
  192.  
  193.     xor     ax, ax
  194.     mov     ah,42h     
  195.     mov     bx,[FileHandle]
  196.     xor     cx,cx
  197.     xor     dx,dx
  198.     add     dx, [FileIndex]
  199.     int     21h
  200.  
  201.     pop     dx
  202.     pop     cx
  203.     pop     bx
  204.     pop     ax
  205.  
  206.     ret
  207.  
  208. ENDP MovePtr1
  209.  
  210. PROC MovePtr2 NEAR
  211.  
  212.     push    ax
  213.     push    bx
  214.     push    cx
  215.     push    dx
  216.  
  217.     xor     ax, ax
  218.     mov     ah,42h     
  219.     mov     bx,[FileHandle2]
  220.     xor     cx,cx
  221.     xor     dx,dx
  222.     add     dx, [FileIndex2]
  223.     int     21h
  224.  
  225.     pop     dx
  226.     pop     cx
  227.     pop     bx
  228.     pop     ax
  229.     ret
  230.  
  231. ENDP MovePtr2
  232.  
  233.  
  234. ;===- Main Program -===
  235.  
  236. START:
  237.     mov     ax, @DATA
  238.     mov     ds,ax
  239.  
  240.     call OpenFile
  241.     call CreateFile
  242.     mov  [CharsLeft], 80
  243.     
  244. ReadLoop:
  245.     call ReadNext
  246.     cmp  ax, 0h
  247.     je   exit
  248.  
  249. ;check for 0d 0a
  250.     cmp  [ReadByte], 020h
  251.     jge  IsChar
  252.  
  253.     cmp  [ReadByte], 0Dh
  254.     jne  NextRead
  255.  
  256.     call ReadNext
  257.     cmp  ax, 0h
  258.     je   exit
  259.  
  260.     cmp  [ReadByte], 0Ah
  261.     jne  NextRead
  262.  
  263.     mov  [WriteByte], 020h
  264.     xor  cx, cx
  265.     mov  cl, [CharsLeft]
  266. FillLine:
  267.     push cx
  268.     call WriteFile
  269.     pop  cx
  270.     dec  cl
  271.     cmp  cl, 0 
  272.     jnz  FillLine
  273.     mov  [CharsLeft], 80
  274.     jmp  ReadLoop
  275.  
  276.  
  277. IsChar:
  278.     mov  al, [ReadByte]
  279.     mov  [WriteByte], al
  280.     jmp  Write
  281.  
  282.  
  283. Write:
  284.     call WriteFile
  285.     dec  [CharsLeft]
  286.     cmp  [CharsLeft], 0
  287.     jnz  NextRead
  288.     mov  [CharsLeft], 80
  289.  
  290. NextRead:
  291.     jmp  ReadLoop
  292.                 
  293.                 
  294. exit:
  295.     mov  [WriteByte], 020h
  296.     xor  cx, cx
  297.     mov  cl, [CharsLeft]
  298. FillLine2:
  299.     push cx
  300.     call WriteFile
  301.     pop  cx
  302.     dec  cl
  303.     cmp  cl, 0 
  304.     jnz  FillLine2
  305.  
  306.     mov     bx,[FileHandle]
  307.     mov     ah,3eh
  308.     int     21h
  309.     mov     bx,[FileHandle2]
  310.     mov     ah,3eh
  311.     int     21h
  312.  
  313.     mov     ax,4c00h                ; exit
  314.     int     21h
  315.  
  316.  
  317.  
  318. END START
  319.