home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / asm / SMODE.ZIP / R.ASM < prev    next >
Encoding:
Assembly Source File  |  1988-05-02  |  15.5 KB  |  524 lines

  1.                 .SEQ
  2. CODE            Segment WORD PUBLIC 'CODE'
  3. CODE            EndS
  4.  
  5. include vga.inc
  6.  
  7. CODE            Segment
  8.                 Assume  CS:Code, DS:ABS40
  9.  
  10.                 Org     2Ch
  11. EnvironSeg      Label   Word
  12.                 Org     80h
  13. ArgumentCount   Label   Byte
  14.                 Org     81h
  15. Arguments       Label   Byte
  16.  
  17.                 Assume  CS:Code, DS:Code
  18.                 
  19.                 Org     100h
  20. Start:          Mov     Bx, Offset EndCode
  21.                 Add     Bx, 20Fh; add space for stack and rounding
  22.                 And     Bx, 0FFF0h; Round to a paragraph
  23.  
  24.                 Mov     Sp, Bx; Move stack
  25.                 Sub     Sp, 2
  26.  
  27.                 Shr     Bx, 1;  Convert from bytes to paragraphs
  28.                 Shr     Bx, 1
  29.                 Shr     Bx, 1
  30.                 Shr     Bx, 1
  31.                 Mov     Ah, 4Ah; Adjust memory use to minimum
  32.                 Int     21h;    Assumes ES is as on entry
  33.  
  34.  
  35.  
  36.                 Mov     Bl, 10h
  37.                 Mov     Ah, 12h;        Test for VGA/EGA
  38.                 Int     10h
  39.                 Cmp     Bl, 10h
  40.                 Jne     VGA_EGA_Found;            Neither VGA/EGA
  41.  
  42.                 Mov     Dx, Offset BadCard
  43.                 Mov     Ah, 9
  44.                 Int     21h
  45.                 Mov     Al, 1
  46.                 Mov     Ah, 4Ch
  47.                 Int     21h
  48.  
  49. BadCard         Db      'R requires a VGA/EGA card to function.',0Dh,0Ah,'$'
  50.  
  51.  
  52.                 Assume  CS:Code, DS:ABS40
  53.  
  54. VGA_EGA_Found:  Push    Ds
  55.                 Mov     Ax, 40h
  56.                 Mov     Ds, Ax
  57.                 Cmp     video_rows, 25
  58.                 Jbe     RunStd
  59.                 Pop     Ds
  60.  
  61.                 Assume  CS:Code, DS:Code
  62.  
  63.                 Call    SetStdMode
  64.  
  65.                 Call    RunProg
  66.  
  67.                 Push    Ax; save returncode
  68.  
  69.                 Call    SetHiMode
  70.  
  71.                 Pop     Ax; Get returncode
  72.  
  73.                 Mov     Ah, 4Ch
  74.                 Int     21h
  75.  
  76. RunStd:         Pop     Ds
  77.                 Call    RunProg
  78.                 
  79.                 Mov     Ah, 4Ch
  80.                 Int     21h
  81.  
  82. SaveRows        db      ?
  83. CurPosition     dw      ?
  84. CurChar         dw      ?
  85. ScrollCount     db      ?
  86.  
  87.                 Assume  CS:Code, DS:ABS40
  88.  
  89. SetStdMode      Proc    Near
  90.                 Push    Ds
  91.                 Push    Es
  92.                 Mov     Ax, 40h
  93.                 Mov     Ds, Ax
  94.                 Mov     Al, video_rows
  95.                 Mov     SaveRows, Al
  96.  
  97.                 Call    Near Ptr GetCurrentChar
  98.                 Mov     CurChar, Ax
  99.                 Mov     CurPosition, Dx
  100.                 
  101.                 Inc     Dh
  102.                 Cmp     Dh, video_rows
  103.                 Ja      NoClear
  104.  
  105.                 Mov     Cx, Dx
  106.                 Mov     Dh, video_rows
  107.                 Mov     Dl, Byte Ptr crt_cols
  108.                 Dec     Dl
  109.                 Mov     Bx, CurChar
  110.                 Mov     Ax, 0600h
  111.                 Int     10h
  112.                 
  113. NoClear:        Xor     Cx, Cx
  114.                 Mov     Dx, CurPosition
  115.                 Mov     Dl, Byte Ptr crt_cols
  116.                 Dec     Dl
  117.                 Mov     Bx, CurChar
  118.                 Mov     Ah, 06h
  119.                 Mov     Al, Dh
  120.                 Sub     Al, 24
  121.                 Jle     NoScroll
  122.                 Mov     ScrollCount, Al
  123.                 Int     10h
  124.                 Jmp     ChangeTo_Std
  125.  
  126. NoScroll:       Xor     Al, Al
  127.                 Mov     ScrollCount, Al
  128.  
  129. ChangeTo_Std:   Mov     Ax, 1A00h; Check Vga/Ega
  130.                 Int     10h
  131.                 Cmp     Al, 1Ah
  132.                 Jne     Ega_8x14
  133.  
  134.                 Mov     Ax, 1114h; Load 9x16 charset, program controller
  135.                 Mov     Bl, 0
  136.                 Int     10h
  137.  
  138.                 Mov     Ax, 1200h;  Enable cursor emulation
  139.                 Mov     Bl, 34h
  140.                 Int     10h
  141.                 Jmp     SetCursor_Std
  142.  
  143. Ega_8x14:       Mov     Ax, 1111h; Load 8x14 charset, program controller
  144.                 Mov     Bl, 0
  145.                 Int     10h
  146.                 And     info, 0FEh
  147.  
  148. SetCursor_Std:  Mov     Ah, 1;  Set cursor type
  149.                 Mov     Cx, 0707h
  150.                 Int     10h
  151.  
  152.                 Mov     Ah, 2;  Move cursor
  153.                 Mov     Bh, active_page
  154.                 Mov     Dx, CurPosition
  155.                 Sub     Dh, ScrollCount
  156.                 Int     10h
  157.  
  158.                 Pop     Es
  159.                 Pop     Ds
  160.                 Ret
  161. SetStdMode      EndP
  162.  
  163. SetHiMode       Proc    Near
  164.                 Push    Ds
  165.                 Push    Es
  166.                 Mov     Ax, 40h
  167.                 Mov     Ds, Ax
  168.                 Mov     Al, video_rows
  169.                 Mov     SaveRows, Al
  170.                 Call    Near Ptr GetCurrentChar
  171. ; the line below is commented out.  In this case, I want
  172. ; the value saved when setting std mode to be used
  173. ;                Mov     CurChar, Ax
  174.                 Mov     CurPosition, Dx
  175.                 Mov     Ax, 1112h; Load 8x8 charset; program controller
  176.                 Mov     Bl, 0
  177.                 Int     10h
  178.  
  179.                 Mov     Ax, 1200h; Select alternate print screen routine
  180.                 Mov     Bl, 20h
  181.                 Int     10h
  182.                 
  183.                 Mov     Ax, 1A00h; Check Vga/Ega
  184.                 Int     10h
  185.                 Cmp     Al, 01Ah
  186.                 Jne     Ega_8x8
  187.  
  188.                 Mov     Ax, 1201h;  Disable cursor emulation
  189.                 Mov     Bl, 34h
  190.                 Int     10h
  191.                 Jmp     SetCursor_8x8
  192.  
  193. Ega_8x8:        Or      info, 1   
  194.  
  195. SetCursor_8x8:  Mov     Ah, 1;  Set cursor type
  196.                 Mov     Cx, 0707h
  197.                 Int     10h
  198.  
  199.                 Mov     Ah, 2;  Position cursor
  200.                 Mov     Bh, active_page
  201.                 Mov     Dx, CurPosition
  202.                 Int     10h
  203.  
  204.                 Mov     Cx, CurPosition
  205.                 Inc     Ch
  206.                 Cmp     Ch, video_rows
  207.                 Ja      NoClearExcess
  208.  
  209.                 Xor     Cl, Cl
  210.                 Mov     Dh, video_rows
  211.                 Mov     Dl, Byte Ptr crt_cols
  212.                 Dec     Dl
  213.                 Mov     Bx, CurChar
  214.                 Mov     Ax, 0600h
  215.                 Int     10h
  216.  
  217. NoClearExcess:  Pop     Es
  218.                 Pop     Ds
  219.                 Ret
  220. SetHiMode       EndP
  221.  
  222. ;      Returns: Ax - current char & attribute
  223. ;               Dx - current position
  224.  
  225.  
  226. GetCurrentChar  Proc    Near
  227.  
  228.                 Mov     Ax, crt_start
  229.                 Shr     Ax, 1
  230.                 Shr     Ax, 1
  231.                 Shr     Ax, 1
  232.                 Shr     Ax, 1
  233.                 Mov     Ah, 0B8h
  234.                 Mov     Es, Ax
  235.  
  236.                 Xor     Bx, Bx
  237.                 Mov     Bl, active_page
  238.                 Shl     Bx, 1
  239.                 Mov     Dx, cursor_posn[Bx]
  240.  
  241.                 Xor     Bx, Bx
  242.                 Mov     Bl, Dl
  243.                 Shl     Bx, 1
  244.                 Mov     Al, Byte Ptr crt_cols
  245.                 Mul     Dh
  246.                 Add     Bx, Ax
  247.                 Mov     Ax, Es:[Bx]
  248.  
  249.                 Ret
  250.  
  251. GetCurrentChar  EndP
  252.  
  253. ProgPathName    db      128 dup(0)
  254.  
  255. ParamBlock      dw      0
  256. CmdLine         dw      080h, 0
  257. Fcb1            dw      05Ch, 0
  258. Fcb2            dw      06Ch, 0
  259.  
  260. Errors          dw      UnknErr
  261.                 dw      Err1
  262.                 dw      Err2
  263.                 dw      UnknErr
  264.                 dw      UnknErr
  265.                 dw      UnknErr
  266.                 dw      UnknErr
  267.                 dw      UnknErr
  268.                 dw      Err8
  269.                 dw      UnknErr
  270.                 dw      Err10
  271.                 dw      Err11
  272.  
  273. UnknErr         db      'Unknown Error.',0Dh,0Ah,'$'
  274. Err1            db      'Invalid function.',0Dh,0Ah,'$'
  275. Err2            db      'File not found.',0Dh,0Ah,'$'
  276. Err8            db      'Not enough memory.',0Dh,0Ah,'$'
  277. Err10           db      'Bad environment.',0Dh,0Ah,'$'
  278. Err11           db      'Bad format.',0Dh,0Ah,'$'
  279.  
  280. NoProgError     db      'No program named.',0Dh,0Ah,'$'
  281. NotFoundError   db      'Program not found.',0Dh,0Ah,'$'
  282.  
  283. PathStr         db      'PATH='
  284. ComSuffix       db      '.COM',0
  285. ExeSuffix       db      '.EXE',0
  286.  
  287. NoSuffixAdded   db      0; false, 1=true
  288. PathGiven       db      0; false, 1=true
  289. PathPtr         dw      0
  290. ProgName        db      128 dup(0)
  291. EndProgName     dw      0
  292. EndPathName     dw      0
  293.  
  294. RunProg         Proc    Near
  295.                 Mov     Ax, Cs
  296.                 Mov     Ds, Ax
  297.  
  298.                 Assume  Cs:Code, Ds:Code
  299.  
  300.                 Mov     Si, Offset ArgumentCount
  301.                 Mov     Cl, [Si]
  302.                 Inc     Si
  303.                 Xor     Ch, Ch
  304.                 Jcxz    NoProg
  305.                 Mov     Di, Offset ProgName
  306.                 Jmp     SkipInitBlks
  307.  
  308. NoProg:         Mov     Dx, Offset NoProgError
  309.                 Mov     Ah, 9
  310.                 Int     21h
  311.                 Mov     Al, 1
  312.                 Ret
  313.  
  314. SkipInitBlks:   Lodsb
  315.                 Cmp     Al, ' '
  316.                 Jne     CopyProgName10
  317.                 Loop    SkipInitBlks
  318.                 Jmp     NoProg
  319.  
  320. CopyProgName:   Lodsb
  321.                 Cmp     Al, ' '
  322.                 Je      CopyArgs
  323.                 Cmp     Al, '.'; Suffix given?
  324.                 Jne     CopyProgName10; Not here anyway
  325.                 Mov     NoSuffixAdded, 1; Yes, mark the fact
  326.                 Jmp     CopyProgName20
  327.  
  328. CopyProgName10: Cmp     Al, '\'; Path given?
  329.                 Jne     CopyProgName20; Not here anyway
  330.                 Mov     PathGiven, 1; Yes, mark the fact
  331.  
  332. CopyProgName20: Stosb
  333.                 Loop    CopyProgName
  334.                 Mov     ArgumentCount, 0; No Args
  335.                 Mov     EndProgName, Di
  336.                 Jmp     ProcessProgName
  337.  
  338. CopyArgs:       Dec     Cx
  339.                 Mov     ArgumentCount, Cl
  340.                 Mov     EndProgName, Di
  341.                 Jcxz    ProcessProgName
  342.                 Mov     Di, Offset Arguments
  343.             Rep Movsb
  344.  
  345. ProcessProgName:Mov     Si, Offset ProgName
  346.                 Mov     Di, Offset ProgPathName
  347.                 Mov     Cx, EndProgName
  348.                 Sub     Cx, Si
  349.             Rep Movsb
  350.                 Mov     EndPathName, Di
  351.                 Xor     Al, Al
  352.                 Stosb
  353.  
  354.                 Cmp     ProgName+1, ':'; Is the disc given?
  355.                 Jne     StartSearch;    no
  356.                 Mov     PathGiven, 1;   yes, mark it as a limited search
  357.  
  358. StartSearch:    Cmp     PathGiven, 0;   Was a path or disc given?
  359.                 Je      TryPathes;      No, setup for trying pathes
  360.                 Jmp     TryFirstOpen;   Yes, limit the search
  361.  
  362. TryPathes:      Mov     Es, EnvironSeg
  363.                 Mov     Di, 0
  364. FindPathes:     Cmp     Byte Ptr Es:[Di], 0
  365.                 Je      NoPathes
  366.                 Push    Di
  367.                 Mov     Si, Offset PathStr
  368.                 Mov     Cx, 5
  369.            Repe Cmpsb
  370.                 Je      PathesFound
  371.                 Pop     Di
  372.                 Xor     Al, Al
  373.                 Mov     Cx, -1
  374.           Repne Scasb
  375.                 Jmp     FindPathes
  376.  
  377. NoPathes:       Mov     PathPtr, Di
  378.                 Mov     Ax, Cs
  379.                 Mov     Es, Ax
  380.                 Jmp     TryFirstOpen; try current disc/dir first
  381.  
  382. PathesFound:    Mov     Ax, Cs
  383.                 Mov     Es, Ax
  384.                 Pop     Dx
  385.                 Mov     PathPtr, Di
  386.                 Jmp     TryFirstOpen; first try current disc/directory
  387.  
  388. NextPath:       Mov     Si, PathPtr
  389.                 Mov     Di, Offset ProgPathName
  390.                 Mov     Ds, EnvironSeg
  391.                 Cmp     Byte Ptr[Si], 0
  392.                 Jne     CopyPath
  393.                 Mov     Ax, Cs
  394.                 Mov     Ds, Ax
  395.                 Jmp     NotFound
  396.  
  397. CopyPath:       Lodsb
  398.                 Cmp     Al,';'; end of this path
  399.                 Je      CopyName;   Yes
  400.                 Cmp     Al, 0; end of all pathes
  401.                 Je      LastPath
  402.                 Stosb
  403.                 Jmp     CopyPath
  404.  
  405. LastPath:       Dec     Si;     save adr of null
  406. CopyName:       Mov     Ax, Cs
  407.                 Mov     Ds, Ax
  408.                 Mov     PathPtr, Si
  409.                 Cmp     Byte Ptr -1[Di], '\'
  410.                 Je      CopyName10
  411.                 Mov     Al, '\'
  412.                 Stosb
  413.  
  414. CopyName10:     Mov     Si, Offset ProgName
  415.                 Mov     Cx, EndProgName
  416.                 Sub     Cx, Si
  417.             Rep Movsb
  418.                 Mov     EndPathName, Di
  419.                 Xor     Al, Al
  420.                 Stosb
  421.                 Jmp     TryFirstOpen
  422.  
  423. TryFirstOpen:   Cmp     NoSuffixAdded, 0
  424.                 Jne     TryOnlyOpen
  425.                 Mov     Si, Offset ExeSuffix
  426.                 Mov     Di, EndPathName
  427.                 Mov     Cx, 5
  428.             Rep Movsb
  429.                 Call    TryOpen
  430.                 Jc      TrySecondOpen
  431.                 Jmp     Run
  432.  
  433. TrySecondOpen:  Mov     Si, Offset ComSuffix
  434.                 Mov     Di, EndPathName
  435.                 Mov     Cx, 5
  436.             Rep Movsb
  437.                 Call    TryOpen
  438.                 Jc      CheckForNext
  439.                 Jmp     Run
  440.  
  441. TryOnlyOpen:    Call    TryOpen
  442.                 Jc      CheckForNext
  443.                 Jmp     Run
  444.  
  445. CheckForNext:   Cmp     PathGiven, 0; Was a path or disc given?
  446.                 Jne     NotFound;       Yes, the search is limited.
  447.                 Jmp     NextPath;       No, try next path if any
  448.  
  449. NotFound:       Mov     Ah, 9
  450.                 Mov     Dx, Offset NotFoundError
  451.                 Int     21h
  452.                 Mov     Al, 1
  453.                 Ret
  454.  
  455. Run:            Mov     CmdLine+2, Cs
  456.                 Mov     Fcb1+2, Cs
  457.                 Mov     Fcb2+2, Cs
  458.  
  459. ; now that the program's name was eliminated from out
  460. ; run string, we need to reparse the rest of the line to
  461. ; setup the FCB's properly in case called program uses them
  462.  
  463.                 Mov     Si, Offset Arguments
  464.                 Mov     Di, 05Ch; First FCB
  465.                 Mov     Ax, 2901h; skip leading separators, default rest
  466.  
  467.                 Mov     Di, 06Ch; Second FCB
  468.                 Mov     Ax, 2901h; same as before
  469.  
  470.                 Mov     Ax, 4B00h
  471.                 Mov     Bx, Offset ParamBlock
  472.                 Mov     Dx, Offset ProgPathName
  473.                 Int     21h
  474.  
  475.                 Mov     Bx, Cs
  476.                 Mov     Ds, Bx
  477.                 Mov     Es, Bx
  478.  
  479.                 Jnc     Done; no error
  480.  
  481.                 Mov     Bx, Offset Errors
  482.                 Add     Bx, Ax
  483.                 Add     Bx, Ax
  484.                 Cmp     Ax, 11
  485.                 Jbe     ReportError
  486.                 Mov     Bx, Offset Errors
  487.  
  488. ReportError:    Mov     Dx, [Bx]
  489.                 Mov     Ah, 9
  490.                 Int     21h
  491.                 Mov     Al, 1
  492.                 Ret
  493.  
  494. Done:           Mov     Ah, 4Dh
  495.                 Int     21h
  496.  
  497.                 Ret
  498.  
  499. RunProg         EndP                
  500.  
  501.  
  502. TryOpen         Proc    Near
  503.                 Mov     Ax, 3D00h
  504.                 Mov     Dx, Offset ProgPathName
  505.                 Int     21h
  506.                 Jc      TryOpenFail
  507.                 Mov     Bx, Ax
  508.                 Mov     Ah, 3Eh
  509.                 Int     21h;            Found file, now close it again
  510.                 Clc     ;               Mark success
  511. TryOpenFail:    Ret
  512. TryOpen         EndP
  513.  
  514. EndCode         Label   Near
  515.  
  516. CODE            Ends                
  517.  
  518.                 End     Start
  519.  
  520.                 Assume  Cs:Code,Ds:Code,Es:Code
  521.  
  522.  
  523.  
  524.