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

  1.  
  2.  
  3. ;   QUITE, QUITE not so simple ANSI/text viewer
  4. ;
  5. ;   Coded by IcEDraGoN [MiB]
  6. ;
  7.  
  8.     DOSSEG
  9.     .MODEL SMALL
  10.     .STACK 200h
  11.     .DATA
  12.  
  13. ;===- Data -===
  14.  
  15. BufferSeg   dw  0
  16.  
  17. ErrMsgOpen  db  "Error opening $"
  18. FNamePtr    dw  0
  19. FileHandle  dw  0
  20. LastPage    dd  0                       ;0 is required for filename 
  21.                                         ;(displays a space)
  22. FileSize    dd 0
  23.  
  24. Screen1     db  4000 dup(?)
  25. FileIndex   dd  0
  26. Psp         dw  0
  27. include         key.inc         
  28.  
  29. ; 00 black
  30. ; 01 blue                                          7  6  5  4  3  2  1  0
  31. ; 02 green                                         |  |  |  |  |  |  |  |
  32. ; 03 blue-green                                    |  |  |  |  |  \---------  foreground
  33. ; 04 red                                           |  |  |  |  \------------  intensity
  34. ; 05 cyan                                          |  \---------------------  background
  35. ; 06 magenta                                       \------------------------  blinking  
  36. ; 07 dark-grey
  37. ; 08 light grey
  38. ; 09 light blue
  39. ; 10 light green
  40. ; 11 light blue-green
  41. ; 12 light red
  42. ; 13 light cyan
  43. ; 14 light brown
  44. ; 15 white
  45.  
  46. StatusBar   db " ",16," ",16," ",16," ",16," ",16," ",16," ",16," ",16," ",16," ",16
  47.             db " ",24," ",24," ",24," ",24," ",24," ",24," ",24," ",24," ",24," ",24
  48.             db " ",23," ",23," ",23," ",23," ",23," ",23," ",23," ",23," ",23," ",23
  49.             db " ",31," ",31," ",31," ",31," ",31," ",31," ",31," ",31," ",31," ",31
  50.             db " ",31," ",31," ",31," ",31," ",31," ",31," ",31," ",31," ",31," ",31
  51.             db " ",23," ",23," ",23," ",23," ",23," ",23," ",23,"'",23," ",23," ",23
  52.             db " ",24," ",24," ",24," ",24," ",24," ",24," ",24," ",24," ",24," ",24
  53.             db " ",16," ",16," ",16," ",16," ",16," ",16," ",16," ",16," ",16," ",16
  54.  
  55.  
  56. StatusBar2  db "                  "
  57.             db "[aNSi-VieW 1.0- done by iCeDRaGoN/MiB '99]                      aNSi-VieW displays"
  58.             db " DOS-ANSI files, which have an additional attribute byte after each char byte."
  59.             db " You can use the tool ASTAN for converting ASCII-Text files into this format."
  60.             db "         Full source code in ASM available at the MiB-Homepage. Greetz go out"
  61.             db " to:     +CrueHead   Pero   +iNCuBuS  cTT    MEXELITE   +FraVia  ......      "
  62.             db "                                                                             ",0
  63. StatusPtr   dw 0       
  64. DelayCount  db 0
  65. ScrollMode  db 0
  66.  
  67.  
  68.  
  69.     .CODE
  70.     .386
  71.     Ideal
  72.     jumps
  73.     
  74.  
  75. extrn _Set_New_Int9:proc
  76. extrn _Set_Old_Int9:proc
  77.  
  78.  
  79. MACRO WaitVRetrace    
  80.                 LOCAL   VRetrace,NoVRetrace
  81.                 mov     dx,03dah
  82. VRetrace:       in      al,dx
  83.                 test    al,00001000b
  84.                 jnz     VRetrace
  85. NoVRetrace:     in      al,dx
  86.                 test    al,00001000b
  87.                 jz      NoVRetrace
  88. ENDM
  89.  
  90. ;===- Subroutines -===
  91.  
  92. PROC Readfirst NEAR
  93.  
  94.     push    ds
  95.     mov     ax,3d00h    ;open file (ah=3dh)
  96.     mov     dx, [FNamePtr]
  97.     mov     ds, [Psp]
  98.     int     21h
  99.     jc      OpenError
  100.     pop     ds
  101.     mov     [FileHandle],ax       ;move the file handle into bx
  102.     mov     bx, ax
  103.     mov     dx,offset Screen1
  104.     mov     ah,3fh
  105.     mov     cx,0F00h       ;read first page
  106.     int     21h
  107.  
  108.     ret
  109.  
  110. OpenError:
  111.     pop     ds
  112.     mov     ah,9
  113.     mov     dx,offset ErrMsgOpen
  114.     int     21h
  115.  
  116.     ret
  117. ENDP Readfirst
  118.  
  119. PROC ReadNext NEAR
  120.     
  121.     push    ax
  122.     push    bx
  123.     push    dx
  124.  
  125.     xor     ax, ax
  126.     mov     bx, [FileHandle]
  127.     mov     dx,offset Screen1
  128.     mov     ah,3fh
  129.     mov     cx,0F00h       ;read first page
  130.     int     21h
  131.  
  132.     pop     dx
  133.     pop     bx
  134.     pop     ax
  135.     
  136.     ret
  137. ENDP ReadNext
  138.  
  139. PROC GetFileSize NEAR
  140.  
  141.     push    ax
  142.     push    bx
  143.     push    cx
  144.     push    dx
  145.  
  146.     xor     ax, ax
  147.     mov     ah,42h      ;find out the size of the file
  148.     mov     bx,[FileHandle]
  149.     xor     cx,cx
  150.     xor     dx,dx
  151.     mov     al,2
  152.     int     21h
  153.     mov     [word low FileSize],ax
  154.     mov     [word high FileSize],dx ;load data into filesize
  155.  
  156.     mov     eax, [FileSize]
  157.  
  158.     sub     eax, 3840
  159.  
  160.     mov     [LastPage], eax
  161.     pop     dx
  162.     pop     cx
  163.     pop     bx
  164.     pop     ax
  165.  
  166.     ret
  167.  
  168. ENDP GetFileSize
  169.  
  170. PROC MovePtr NEAR
  171.  
  172.     push    ax
  173.     push    bx
  174.     push    cx
  175.     push    dx
  176.  
  177.     xor     ax, ax
  178.     mov     ah,42h      ;find out the size of the file
  179.     mov     bx,[FileHandle]
  180.     xor     cx,cx
  181.     xor     dx,dx
  182.     mov     dx,[word low FileIndex]
  183.     mov     cx,[word high FileIndex]
  184.     int     21h
  185.  
  186.     pop     dx
  187.     pop     cx
  188.     pop     bx
  189.     pop     ax
  190.  
  191.     ret
  192.  
  193. ENDP MovePtr
  194.  
  195. PROC ShowScreen NEAR
  196.  
  197.     push    ax
  198.     push    cx
  199.     push    di
  200.     push    si
  201.  
  202.     mov     ax,0b800h               ; dump status bar to screen
  203.     mov     es,ax
  204.     xor     di,di
  205.     mov     si,offset Screen1
  206.     mov     cx, 2000
  207.     rep     movsw
  208.  
  209.     mov     di, 0F00h
  210.     mov     si,offset StatusBar
  211.     mov     cx, 80
  212.     rep     movsw
  213.  
  214.     pop     si
  215.     pop     di
  216.     pop     cx
  217.     pop     ax
  218.  
  219.     ret
  220.  
  221.  
  222. ENDP ShowScreen
  223.  
  224. PROC ShowScreen2 NEAR
  225.  
  226.     push    ax
  227.     push    cx
  228.     push    di
  229.     push    si
  230.  
  231.     mov     ax,0b800h               ; dump status bar to screen
  232.     mov     es,ax
  233.     xor     di,di
  234.     mov     si,offset Screen1
  235.     mov     cx, 1920
  236.     rep     movsw
  237.  
  238.  
  239.     mov     di, 0F00h
  240.     inc     [DelayCount]
  241.     cmp     [DelayCount], 15
  242.     jne     GoAhead
  243.     mov     [DelayCount], 0
  244.     inc     [StatusPtr]
  245.  
  246. GoAhead:
  247.     mov     si, [StatusPtr]
  248.     lodsb
  249.     cmp     al, 0
  250.     jne     GoOn
  251.     mov     si, offset StatusBar2
  252.     mov     [StatusPtr], si
  253.     lodsb
  254. GoOn:
  255.     mov     cx, 80
  256. MoveLoop:
  257.     mov     [es:di], al
  258.     lodsb
  259.     cmp     al, 0
  260.     jne     GoOn2
  261.     mov     si, offset StatusBar2
  262.     lodsb
  263. GoOn2:
  264.     add     di, 2
  265.     dec     cx
  266.     cmp     cx, 0
  267.     jnz     MoveLoop
  268.  
  269.     pop     si
  270.     pop     di
  271.     pop     cx
  272.     pop     ax
  273.  
  274.     ret
  275.  
  276.  
  277. ENDP ShowScreen2
  278.  
  279. ;===- Main Program -===
  280.  
  281. START:
  282.     mov     ax, @DATA
  283.     mov     ds,ax
  284.     mov     [Psp],es                ; Save the PSP address.
  285.     call    _Set_New_Int9
  286.     mov     ax,0003h
  287.     int     10h
  288.     mov     ax,0100h                ; hide the cursor
  289.     mov     cx,0800h
  290.     int     10h
  291.     mov     ah, 03
  292.     mov     al, 05                  ;set the typematic rate/delay
  293.     mov     bh, 03                  ;set repeat delay to 1000ms
  294.     mov     bl, 1Fh                 ;set rate to 2.0
  295.     int     16h
  296.  
  297.  
  298. GetFileName:    mov     es,[Psp]                ; Parse  the Command line...
  299.                 mov     si,80h
  300.                 mov     al,[es:si]
  301.                 mov     bl,al
  302.                 xor     bh,bh
  303.                 inc     bx
  304.                 mov     [byte ptr es:si+bx],0   ; make AsciiZ filename.
  305. ScanName:       inc     si
  306.                 mov     al,[es:si]
  307.                 test    al,al
  308.                 je      Exit
  309.                 cmp     al,20h
  310.                 je      ScanName                ; scan start of name.
  311.                 mov     di,si
  312. ScanPeriod:     inc     si
  313.                 mov     al,[es:si]
  314.                 cmp     al,'.'                  ; if period NOT found,
  315.                 je      LoadFile                ; then add a .MOD extension.
  316.                 test    al,al
  317.                 jne     ScanPeriod
  318.  
  319. SetExt:         mov     [Byte Ptr es:si+0],'.'
  320.                 mov     [Byte Ptr es:si+1],'A'
  321.                 mov     [Byte Ptr es:si+2],'N'
  322.                 mov     [Byte Ptr es:si+3],'S'
  323.                 mov     [Byte Ptr es:si+4],0
  324.  
  325.  
  326. LoadFile:
  327.     mov     [FNamePtr], di
  328.     mov     [FileIndex], 0
  329.     call    Readfirst               ;read first page
  330.     call    GetFileSize             
  331.     call    MovePtr                 ;set pointer to start
  332.     call    ReadNext                ;read page
  333.     call    ShowScreen              ;display
  334.  
  335. ; check pressed keys
  336.  
  337.     get_key: 
  338.                 cmp     [cs:_keys+kSPACE],1     ; cursor up?
  339.                 je      key_space
  340.                 cmp     [cs:_keys+kUARROW],1     ; cursor up?
  341.                 je      key_up
  342.                 cmp     [cs:_keys+kKEYPAD8],1    ; cursur up?
  343.                 je      key_up
  344.                 cmp     [cs:_keys+kDARROW],1     ; cursor down?
  345.                 je      key_down
  346.                 cmp     [cs:_keys+kKEYPAD2],1    ; cursor down?
  347.                 je      key_down
  348.                 cmp     [cs:_keys+kPGUP],1       ; pgup?
  349.                 je      key_pgup
  350.                 cmp     [cs:_keys+kPGDN],1       ; pgdn?
  351.                 je      key_pgdn
  352.                 cmp     [cs:_keys+kHOME],1       ; home?
  353.                 je      key_home
  354.                 cmp     [cs:_keys+kEND],1        ; end?
  355.                 je      key_end
  356.                 cmp     [cs:_keys+kESC],1        ; esc?
  357.                 je      exit
  358.                 cmp     [ScrollMode],0
  359.                 jne     ShowStatusBar
  360.                 mov     [DelayCount],0
  361. ShowStatusBar:
  362.                 WaitVRetrace
  363.                 call    ShowScreen2
  364.                 jmp     get_key
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371. key_space:      
  372.                 cmp     [ScrollMode],1
  373.                 jne     Set1
  374.                 mov     [ScrollMode],0
  375.                 jmp     get_key
  376. Set1:
  377.                 mov     [ScrollMode],1
  378.                 jmp     get_key
  379.  
  380.  
  381.  
  382. key_up:         cmp     [FileIndex],0           ; at top?
  383.                 je      get_key                ; if so, jump
  384.                 jl      key_home
  385.                 sub     [FileIndex], 160             
  386.                 call    MovePtr
  387.                 call    ReadNext
  388.                 WaitVRetrace
  389.                 WaitVRetrace
  390.                 WaitVRetrace
  391.                 call    ShowScreen2
  392.                 jmp     get_key
  393.  
  394. key_down:
  395.                 mov     edx, [LastPage]
  396.                 cmp     [FileIndex], edx
  397.                 je      get_key
  398.                 jg      key_end
  399.                 add     [FileIndex], 160
  400.                 call    MovePtr
  401.                 call    ReadNext
  402.                 WaitVRetrace
  403.                 WaitVRetrace
  404.                 WaitVRetrace
  405.                 call    ShowScreen2
  406.                 jmp     get_key
  407.  
  408. key_pgdn:
  409.                 mov     edx, [LastPage]
  410.                 cmp     [FileIndex], edx
  411.                 je      get_key
  412.                 jg      key_end
  413.                 add     [FileIndex], 3840
  414.                 call    MovePtr
  415.                 call    ReadNext
  416.                 WaitVRetrace
  417.                 call    ShowScreen2
  418.                 jmp     get_key
  419.  
  420.  
  421. key_pgup:
  422.                 cmp     [FileIndex],0           ; at top?
  423.                 je      get_key                ; if so, jump
  424.                 jl      key_home
  425.                 sub     [FileIndex], 3840             
  426.                 call    MovePtr
  427.                 call    ReadNext
  428.                 WaitVRetrace
  429.                 call    ShowScreen2
  430.                 jmp     get_key
  431.  
  432.  
  433. key_home:       cmp     [FileIndex],0
  434.                 je      get_key
  435.                 mov     [FileIndex],0
  436.                 call    MovePtr
  437.                 call    ReadNext
  438.                 WaitVRetrace
  439.                 call    ShowScreen2
  440.                 jmp     get_key
  441.                 
  442. key_end:
  443.                 mov     edx, [LastPage]
  444.                 cmp     [FileIndex], edx
  445.                 je      get_key
  446.  
  447.                 mov     [FileIndex], edx
  448.                 call    MovePtr
  449.                 call    ReadNext
  450.                 WaitVRetrace
  451.                 call    ShowScreen2
  452.                 jmp     get_key
  453.                 
  454.                 
  455. exit:
  456.     call    _Set_Old_Int9
  457.     mov     ax,0003h                ; text mode 3
  458.     int     10h
  459.     mov     bx,[FileHandle]
  460.     mov     ah,3eh
  461.     int     21h
  462.     mov     ax,4c00h                ; exit
  463.     int     21h
  464.  
  465.  
  466.  
  467. END START
  468.