home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1998 January (DVD) / VPR980100.ISO / OLS / DOS / MILD7130 / MILD7130.LZH / SOURCE.LZH / MILD7.ASM < prev   
Assembly Source File  |  1994-04-22  |  27KB  |  1,129 lines

  1. ;      MILD7 - Video7 Emulator
  2.  
  3. ;    Copyright (c) 1993, 1994, Kyosuke Tokoro
  4. ;       All rights reserved
  5.  
  6. VER    equ    '1.30'
  7.  
  8. ;================================================================
  9. ; Ver       Note
  10. ;----------------------------------------------------------------
  11. ; 0.99    Pre-released test program
  12. ; 1.00    Added Video7 functions (AH=6Fh)
  13. ; 1.01    Added /unload switch for remove resident from memory
  14. ;    No check BX when entering function 6F00h
  15. ; 1.02    Optimized for size
  16. ;    Purge null functions (AX=6F05h, 6F07h)
  17. ;    Changed some messages
  18. ;    Added more stack area
  19. ;    Change algorithm of checking installation
  20. ; 1.10    Can install as a device driver
  21. ; 1.20    Added mode chage feature
  22. ; 1.21    Added help (/?) option
  23. ;    Change algorithm of main driver interrupt routine
  24. ; 1.22    Check DBCS vector befor video mode setting
  25. ;    Fix bug in error handling during video mode setting
  26. ; 1.23    Fix bug in function 1Bh of video BIOS
  27. ; 1.24    No clear the screen if the high bit of video mode is set
  28. ; 1.25    Added ON/OFF swich
  29. ;    Support video modes 41h and 5Bh
  30. ; 1.30    Automatic disable when starts MS-Windows
  31. ;    Fix bug that can't recognize vmode when loading high
  32. ;================================================================
  33.     .286
  34.     include macros.inc
  35. ;======================
  36. ; VGA Port Definitions
  37. ;======================
  38. VGAMiscW equ    3C2h    ;(Write) Miscellaneous Output Register
  39. BWStat1  equ    3BAh    ;(Read)  Status Register 0 (in monochrome mode)
  40. VGAStat1 equ    3DAh    ;(Read)  Status Register 0 (in color emulation)
  41. VGAMiscR equ    3CCh    ;(Read)  Miscellaneous Output Register
  42. CRTC     equ    3D4h    ;(R/W)     Display Controller
  43. ;-----------------------
  44. ; CRTC Initialize Value
  45. ; for 80x60 Text Mode
  46. ;-----------------------
  47. VertTatal    equ    523    ;Vertical Total
  48. StrtVertBlank    equ    487    ;Start Vertical Blank
  49. VertRetrStrt    equ    490    ;Vertical Retrace Start
  50. VertRetrEnd    equ    492    ;Vertical Retrace End
  51. EndVertBlank    equ    516    ;End Vertical Blank
  52. ;===================
  53. ; BIOS Data Segment
  54. ;===================
  55. bios       segment at 0'BIOS'
  56.        org    449h
  57. VideoMode  db    ?    ;Video current mode
  58. VideoCols label byte
  59. columns    dw    ?    ;Video columns on screen
  60. RegenSize  dw    ?    ;Video page (regen buffer) size in bytes
  61.        org    462h
  62. VideoPage  db    ?    ;Video current page number
  63.        org    484h
  64. VideoRows  db    ?    ;Video rows on screen minus one
  65. VideoScan label byte
  66. CharHeight dw    ?    ;Video character height in scan-lines
  67.        db    ?
  68. VGASw       db    ?    ;Video VGA switches
  69. ModeOption db    ?    ;Video MCGA/VGA mode-set option control
  70. bios       ends
  71. ;===========================
  72. ; Program Code/Data Segment
  73. ;===========================
  74. code    segment word public'CODE'
  75. top    label
  76. ;======================
  77. ; Device Driver Header
  78. ;======================
  79.     dd      -1        ;Link to next driver (-1 for none)
  80.     dw    8000h        ;Device attributes
  81.     dw    strategy    ;Strategy-routine offset
  82. dhCmd    dw    command        ;Interrupt-routine offset
  83.     db    'MILD7VGA'    ;Logical-device name
  84. sign    db    VER        ;Version signature
  85. ;==========================
  86. ; Request Packet Structure
  87. ;==========================
  88. ;*** Request Packet Header ***
  89. RqHeader struc
  90.     db    ?        ;Length of record, in bytes
  91.     db    ?        ;(not for the charecter device)
  92.  rhFunc db    ?        ;Function number
  93.  rhStat dw    ?        ;Status
  94.     db    8 dup(?)    ;(reserved)
  95. RqHeader ends
  96.  
  97. ;*** Intialize Request Packet ***
  98. InitReq struc
  99.     RqHeader<>
  100.     db    ?        ;(not for the charecter device)
  101.  irEnd    dd    ?        ;INPUT:  end available driver memory
  102.                 ;OUTPUT: end resident code
  103.  irParam dd    ?        ;INPUT:  addr CONFIG.SYS device= line
  104.                 ;OUTPUT: (not for the charecter device)
  105.     db    ?        ;(not for the charecter device)
  106.  irMsgFlag dw    ?        ;OUTPUT: error-message flag
  107. InitReq ends
  108. ;====================
  109. ; Resident Work Area
  110. ;====================
  111. ;*** Instance Item ***
  112.      even
  113. instance dd    InstTop        ;Address of instance data
  114.      dw    InstSize    ;Size of instance data
  115.      dd    0        ;End of array
  116.  
  117. ;*** Startup Information ***
  118. StartInfo db    3     ;Major version of info structure
  119.       db    0     ;Minor version of info structure
  120. NextInfo  dd    ?     ;Pointer to next startup info structure or 0000h:0000h
  121.       dd    0     ;Pointer to ASCIZ name of VxD file or 0000h:0000h
  122.       dd    0     ;virtual device reference (only used if above nonzero)
  123. InstItem  dd    instance ;Pointer to instance data records
  124.  
  125. ;***
  126.     irp    i,<10h,2Fh>
  127. _org&i    dd    ?    ;Original int i vector
  128.     endm
  129. psp    dw    0    ;Segment address of PSP (valid only initialized as TSR)
  130. request dd    ?
  131.  
  132. InstTop label
  133. ReqMode dw    ?    ;Required video mode
  134. SubCmd    db    ?    ;Subcommand for load rom character pattern
  135. ;------------------
  136. ; Status flag bits
  137. ;------------------
  138. SBAVAIL equ    80h    ;Statback is valid flag
  139. ACTIVE    equ    40h    ;MILD7 BIOS active flag
  140. EmuStat  db    ACTIVE
  141. InstSize equ    $-InstTop
  142. StatBack db    ACTIVE
  143. ;======================
  144. ; CRTC Bit Programming
  145. ;======================
  146. ;      DX = CRTC port address
  147. ;      AL = index
  148. ;      CL = data
  149. ;      CH = mask
  150. ; Return: AL = output value
  151.  
  152.     assume    cs:code
  153. bitCRTC proc    near
  154.     cli
  155.     out    dx,al
  156.     inc    dx
  157.     in    al,dx
  158.     and    al,ch
  159.     or    al,cl
  160.     out    dx,al
  161.     dec    dx
  162.     ret
  163. bitCRTC endp
  164. ;================
  165. ; Unprotect CRTC
  166. ;================
  167. ;      DX = CRTC port address
  168. ; Return: AX = value for protect
  169.  
  170. unprotect proc    near
  171.     push    cx
  172.     mov    ax,1111h    ;AH = AL = 11h (Index to vertical retrace end)
  173.     mov    cx,7000h+(VertRetrEnd and 0Fh)
  174.     call    bitCRTC
  175.     pop    cx
  176.     or    al,80h        ;Make value for protect CRTC
  177.     xchg    al,ah        ;
  178.     ret
  179. unprotect endp
  180. ;========================
  181. ; CRTC 5 bit Porgramming
  182. ;========================
  183. ;      DX = CRTC port address
  184. ;      AL = index
  185. ;      CL = data (bit 7-5 must be 0)
  186. ; Return: AL = AL + 1
  187. ;      CL = CL - 1
  188.  
  189. CRTC5bit proc    near
  190.     dec    cl
  191. CRTC5bit0 proc
  192.     mov    ch,0E0h
  193.     push    ax
  194.     call    bitCRTC
  195.     pop    ax
  196.     inc    ax
  197.     ret
  198. CRTC5bit0 endp
  199. CRTC5bit endp
  200. ;========================
  201. ; Call Int 10h in Mode 3
  202. ;========================
  203. ;      DS = bios
  204. ;      AH = function code
  205.  
  206.     assume    ds:bios
  207. org10h    proc    near
  208.     push    word ptr VideoMode
  209.     mov    VideoMode,3
  210.     int    10h
  211.     pop    word ptr VideoMode
  212.     ret
  213. org10h    endp
  214. ;=========================
  215. ; Video BIOS Trap Handler
  216. ;=========================
  217. ;------------------
  218. ; Function 6F01h
  219. ; Get Monitor Info
  220. ;------------------
  221. ;      AX = 6F01h
  222. ; Return: AH = status register information
  223. ;           bit  0 = display enable
  224. ;              0 = display enabled
  225. ;              1 = vertical or horizontal retrace in progress
  226. ;           bit  1 = 0 (reserved as light pen flip flop status)
  227. ;           bit  2 = 0 (reserved as light pen switch activation status)
  228. ;           bit  3 = vertical sync
  229. ;           bit  4 = 0 (reserved as monitor resolution status)
  230. ;           bit  5 = 0 (reserved as display type)
  231. ;           bits6,7= 0 (reserved as diagnostic bits)
  232. ; Note:   Bits 0-3 are the same as the VGA status register bit 0-3
  233.  
  234.     assume    ds:nothing
  235. _6F01h: push    dx
  236.     mov    dx,VGAMiscR
  237.     in    al,dx
  238.     mov    dl,low BWStat1
  239.     testif    al,1,z,_6F01h0
  240.     mov    dl,low VGAStat1
  241. _6F01h0:in    al,dx
  242.     pop    dx
  243.     and    al,0Fh
  244.     mov    ah,al
  245.     mov    al,1        ;Restore caller's AL value
  246.     iret
  247. ;--------------------------------
  248. ; Function 6F04h
  249. ; Get Mode and Screen Resolution
  250. ;--------------------------------
  251. ;      AX = 6F04h
  252. ; Return: AL = current video mode
  253. ;      BX = horizontal columns
  254. ;      CX = vertical columns
  255.  
  256.     assume    ds:bios
  257. _6F04h: push    ds
  258.     xor    bx,bx
  259.     mov    ds,bx
  260.     mov    al,VideoMode
  261.     mov    bx,columns
  262.     mov    cl,VideoRows
  263.     xor    ch,ch
  264.     inc    cx
  265.     pop    ds
  266.     iret
  267. ;--------------------
  268. ; Function 6F00h
  269. ; Installation Check
  270. ;--------------------
  271. ;      AX = 6F00h
  272. ; Return: BX = 5637h ('V7')
  273.  
  274.     assume    ds:nothing
  275. _6F00h: testif    EmuStat,ACTIVE,z,DoOrg10h
  276.     mov    bx,5637h
  277.     iret
  278. ;-----------------------
  279. ; Function 6Fh
  280. ; Video7 BIOS Emulation
  281. ;-----------------------
  282. _6Fh:    if_    al,b,1,_6F00h
  283.     je    _6F01h
  284.     if_    al,b,4,DoOrg10h
  285.     je    _6F04h
  286.     if_    al,e,5,_6F05h
  287.     if_    al,ne,3Fh,DoOrg10h
  288. ;----------------------
  289. ; Function 6F3Fh
  290. ; Get Resident Segment
  291. ;----------------------
  292. ;      AX = 6F3Fh
  293. ; Return: AX = 3F6Fh
  294. ;      ES = Resident segment address
  295.  
  296. _6F3Fh: movp    es,cs
  297.     xchg    al,ah
  298.     iret
  299. ;----------------
  300. ; Function 6F05h
  301. ; Set Video Mode
  302. ;----------------
  303. ;      AX = 6F05h
  304. ;      BL = mode
  305.  
  306. _6F05h: push    ax
  307.     xor    ah,ah    ;Set video mode
  308.     mov    al,bl    ;
  309.     int    10h    ;
  310.     pop    ax
  311.     iret
  312. ;---------------------------------
  313. ; Function 1Bh
  314. ; Functionality/State Information
  315. ;---------------------------------
  316. ;      AH = 1Bh
  317. ;      BX = implementation type
  318. ;          0000h return funtionality/state information
  319. ;      ES:DI -> 64-byte buffer for state information (see below)
  320. ; Return: AL = 1Bh if function supported
  321. ;          ES:DI buffer filled with state information
  322.  
  323. ; Format of state information:
  324. ; Offset  Size      Description
  325. ;  00h      DWORD   address of static funtionality table
  326. ;  04h      BYTE      video mode in effect
  327. ;  05h      WORD      number of columns
  328. ;  07h      WORD      length of regen buffer in bytes
  329. ;  09h      WORD      starting address of regen buffer
  330. ;  0Bh      WORD      cursor position for page 0
  331. ;  0Dh      WORD      cursor position for page 1
  332. ;  0Fh      WORD      cursor position for page 2
  333. ;  11h      WORD      cursor position for page 3
  334. ;  13h      WORD      cursor position for page 4
  335. ;  15h      WORD      cursor position for page 5
  336. ;  17h      WORD      cursor position for page 6
  337. ;  19h      WORD      cursor position for page 7
  338. ;  1Bh      WORD      cursor type
  339. ;  1Dh      BYTE      active display page
  340. ;  1Eh      WORD      CRTC port address
  341. ;  20h      BYTE      current setting of register (3?8)
  342. ;  21h      BYTE      current setting of register (3?9)
  343. ;  22h      BYTE      number of rows
  344. ;  23h      WORD      bytes/character
  345. ;  25h      BYTE      display combination code of active display
  346. ;  26h      BYTE      DCC of alternate display
  347. ;  27h      WORD      number of colors supported in current mode
  348. ;  29h      BYTE      number of pages supported in current mode
  349. ;  2Ah      BYTE      number of scan lines active
  350. ;          (0,1,2,3) = (200,350,400,480)
  351. ;  2Bh      BYTE      primary character block
  352. ;  2Ch      BYTE      secondary character block
  353. ;  2Dh      BYTE      miscellaneous flags
  354. ;  2Eh    3 BYTEs   reserved (00h)
  355. ;  31h      BYTE      video memory available
  356. ;          00h = 64K, 01h = 128K, 02h = 192K, 03h = 256K
  357. ;  32h      BYTE      save pointer state flags
  358. ;  33h 13 BYTEs   reserved (00h)
  359.  
  360.     assume    ds:bios
  361. _1Bh:    if_    al,ne,ah,_1BhQ
  362.     jbxnz    _1BhQ
  363.     mov    al,VideoMode
  364.     and    al,7Fh
  365.     mov    byte ptr es:[di+4],al
  366.     mov    word ptr es:[di+29h],303h
  367.     mov    al,ah
  368. _1BhQ:    iret
  369. ;--------------------
  370. ; Int 10h Main Entry
  371. ;--------------------
  372.     assume    ds:nothing
  373. int10h    proc    far
  374.     jahz    _00h
  375.     if_    ah,e,0Fh,_0Fh
  376.     if_    ah,e,6Fh,_6Fh
  377.  
  378.     assume    ds:bios
  379.     push    ds
  380.     movp    ds,bios
  381.     irp    i,<41h,43h,5Bh>
  382.     if_    VideoMode,e,i,SetMode3
  383.     endm
  384. DoOrg10h0:pop    ds
  385. _0Fh:
  386. DoOrg10h:jmp    _org10h
  387.  
  388. SetMode3:if_    ah,ne,11h,?1Bh
  389.     jmp    _11h
  390.  
  391. ?1Bh:    cmp    ah,1Bh
  392.     pushf
  393.     call    org10h
  394.     pops    <f,ds>
  395.     je    _1Bh
  396.     iret
  397. ;----------------
  398. ; Function 00h
  399. ; Set Video Mode
  400. ;----------------
  401. ;      AH = 00h
  402. ;      AL = mode
  403. ;          41h 80x34 text mode (Diamond Speedstar 24X, WD90C)
  404. ;          43h 80x60 text mode (Video7, VEGA, Tatung)
  405. ;          5Bh 80x30 text mode (ATI VGA Wonder)
  406.  
  407.     assume    ds:nothing
  408. _00h:    push    ax
  409.     and    al,7Fh
  410.  
  411.     mov    ah,11h        ; 8x14 font
  412.     if_    al,e,41h,_00h0    ;80x34 text
  413.  
  414.     inc    ah        ; 8x 8 font
  415.     if_    al,e,43h,_00h0    ;80x60 text
  416.  
  417.     mov    ah,14h        ; 8x16 font
  418.     if_    al,e,5Bh,_00h0    ;80x30 text
  419.  
  420.     pop    ax
  421.     jmp    DoOrg10h
  422.  
  423. _00h0:    mov    SubCmd,ah
  424.     pop    ReqMode
  425.  
  426.     assume    ds:bios
  427.     push    ds
  428.     xor    ax,ax
  429.     mov    ds,ax
  430.     push    word ptr VGASw
  431.     push    bx
  432.     mov    ax,1201h    ;Select vertical resolution
  433.     mov    bl,30h        ; 350 scan lines
  434.     int    10h        ;
  435.     pop    bx
  436.     mov    ax,ReqMode    ;Set video mode
  437.     and    al,80h        ;
  438.     or    al,3        ;
  439.     int    10h        ;
  440.     pop    word ptr VGASw
  441.     pop    ds
  442.  
  443.     assume    ds:nothing
  444.     push    dx
  445.     mov    dx,VGAMiscW
  446.     mov    al,11100011b
  447. ;           |||||||+----- I/O Address Select = 3DXh for CGA Emulation
  448. ;           ||||||+------ Enable RAM
  449. ;           ||||++------- Selects 25.175 MHz clock for 640 Horz PELs
  450. ;           |||+--------- Reserved = 0
  451. ;           ||+---------- Page Bit for Odd/Even
  452. ;           ++----------- 480 lines
  453.     out    dx,al
  454.  
  455.     mov    dl,low CRTC
  456.     call    unprotect
  457.  
  458. outcrtc macro    index,value
  459.     mov    ax,(low value)*100h+index
  460.     out    dx,ax
  461.     endm
  462.  
  463.     outcrtc 6,VertTatal
  464. overflow=    ((VertTatal shr 4)and 20h)or((high VertTatal)and 1)
  465. OflMask =    0DEh
  466.  
  467.     outcrtc 10h,VertRetrStrt
  468. overflow=    overflow or((VertRetrStrt shr 2)and 80h) \
  469.         or((VertRetrStrt shr 6)and 4)
  470. OflMask =    OflMask and 7Bh
  471.  
  472.     outcrtc 15h,StrtVertBlank
  473. overflow=    overflow or((StrtVertBlank shr 5)and 8)
  474. OflMask =    OflMask and 0F7h
  475.  
  476.     outcrtc 16h,EndVertBlank
  477.  
  478.     push    cx
  479.     mov    al,7
  480.     mov    cx,(OflMask shl 8)+overflow
  481.     call    bitCRTC
  482.  
  483.     mov    al,9
  484.     mov    cx,0DF00h+((StrtVertBlank shr 4)and 20h)
  485.     call    bitCRTC
  486.     pops    <cx,dx>
  487.  
  488.     assume    ds:bios
  489.     push    ds
  490.     xor    ax,ax
  491.     mov    ds,ax
  492.     mov    al,byte ptr ReqMode
  493.     mov    VideoMode,al
  494.     pop    ds
  495.  
  496.     assume    ds:nothing
  497.     push    bx
  498.     mov    ah,11h        ;Load ROM character
  499.     mov    al,SubCmd
  500.     xor    bl,bl        ;to block 0
  501.     int    10h        ;
  502.     pop    bx
  503.     mov    ax,ReqMode    ;Restore caller's AX value
  504.     iret
  505. ;-----------------------------------------
  506. ; Function 11h
  507. ; Text-Mode Character Generator Functions
  508. ;-----------------------------------------
  509. ;      AH = 11h
  510. ;      The following functions will cause a mode set, completely resetting
  511. ;      the video environment, but without clearing the video buffer
  512. ;      AL = 00h, 10h: load user-specified patterns
  513. ;          ES:BP -> user table
  514. ;          CX    = count of patterns to store
  515. ;          DX    = character offset into map 2 block
  516. ;          BL    = block to load in map 2
  517. ;          BH    = number of bytes per character pattern
  518. ;      AL = 01h, 11h: load ROM monochrome patterns (8 by 14)
  519. ;          BL    = block to load
  520. ;      AL = 02h, 12h: load ROM 8 by 8 double-dot patterns
  521. ;          BL    = block to load
  522. ;      AL = 04h, 14h: load ROM 8x16 character set
  523. ;          BL  = block to load
  524. ; Notes:  The routines called with AL=1xh are designed to be called only
  525. ;      immediately after a mode set and are similar to the routines called
  526. ;      with AL=0xh, except that:
  527. ;        Page 0 must be active.
  528. ;        Bytes/character is recalculated.
  529. ;        Max character rows is recalculated.
  530. ;        CRT buffer length is recalculated.
  531. ;        CRTC registers are reprogrammed as follows:
  532. ;               R09 = bytes/char-1 ; max scan line
  533. ;               R0A = bytes/char-2 ; cursor start
  534. ;               R0B = 0          ; cursor end
  535. ;               R12 = ((rows+1)*(bytes/char))-1 ; vertical display end
  536. ;               R14 = bytes/char   ; underline loc
  537.  
  538.     assume    ds:bios
  539. _11h:    if_    al,nb,10h,_11h0
  540. xDoOrg10h0:jmp    DoOrg10h0
  541.  
  542. _11h0:    if_    al,e,13h,xDoOrg10h0
  543.     if_    al,a,14h,xDoOrg10h0
  544.  
  545. ; Do load font
  546.     call    org10h
  547.  
  548. ; Unprotect CRTC
  549.     pushs    <ax,cx,dx>
  550.     mov    dx,CRTC
  551.     call    unprotect
  552.     push    ax        ;Save AX value for protect CRTC
  553.  
  554. ; Recalculate max character rows
  555. ; but doesn't save
  556.     mov    ax,480
  557.     div    byte ptr CharHeight
  558.     push    ax        ;Save for after use
  559.  
  560. ; Reprogramme CRTC register 12
  561. ; (vertical display end)
  562.     mov    al,ah        ;AX = 480 modulo [CharHeight]
  563.     cbw            ;
  564.     neg    ax
  565.     add    ax,480-1
  566.     mov    cl,ah
  567.     mov    ah,al
  568.     mov    al,12h
  569.     out    dx,ax        ;+--CH--+ +--CL--+
  570.                 ;      FEDCBA98
  571.     shl    cl,1        ;      EDCBA98.
  572.     mov    ch,cl        ;EDCBA98. EDCBA98.
  573.     and    cx,402h        ;.....9.. ......8.
  574.     shl    ch,4        ;.9...... ......8.
  575.     or    cl,ch        ;      .9....8.
  576.     mov    ch,0BDh        ;x.xxxx.x
  577.     mov    al,7
  578.     call    bitCRTC
  579.  
  580. ; Recalculate CRT buffer length
  581.     pop    ax
  582.     push    ax
  583.     mul    VideoCols
  584.     shl    ax,1
  585.     add    ax,0FFh
  586.     xor    al,al
  587.     mov    RegenSize,ax
  588.  
  589. ; Save max character rows
  590.     pop    ax
  591.     dec    ax
  592.     mov    VideoRows,al
  593.  
  594. ; Protect CRTC
  595.     pop    ax
  596.     out    dx,ax
  597.     pops    <dx,cx,ax,ds>
  598.     iret
  599. int10h    endp
  600. ;=================
  601. ; Int 2Fh Handler
  602. ;=================
  603.     assume    ds:nothing
  604. int2Fh    proc    far
  605.     if_    ax,e,1605h,InitDOSX
  606.     if_    ax,e,1606h,ExitWin
  607.     if_    ax,e,4B05h,IdInst
  608. DoOrg2Fh:jmp    _org2Fh
  609. ;-----------------------------------------------
  610. ; Function 1606h
  611. ; MS Windows Enhanced Mode Begin Exit Broadcast
  612. ;-----------------------------------------------
  613. ;      AX = 1606h
  614.  
  615. ExitWin:testif    EmuStat,SBAVAIL,z,DoOrg2Fh
  616.     push    ax
  617.     mov    al,StatBack
  618.     mov    EmuStat,al
  619.     pop    ax
  620.     jmp    DoOrg2Fh
  621. ;-----------------------------------------------
  622. ; Function 1605h / 4B05h
  623. ; MS Windows Enh Mode Init Broadcast
  624. ; DOS 5+ Task Switcher - Identify Instance Data
  625. ;-----------------------------------------------
  626. ;      AX = 1605h (Task Switcher)
  627. ;           4B05h (Windows)
  628. ;      ES:BX = 0000h:0000h
  629. ;      DS:SI = 0000h:0000h            (Windows only)
  630. ;      CX:DX -> task switcher entry point    (Task Switcher only)
  631. ;      CX = 0000h                (Windows only)
  632. ;      DX = flags
  633. ;          bit 0 = 0 if Windows enhanced-mode initialization
  634. ;          bit 0 = 1 if Microsoft 286 DOS extender initialization
  635. ;          bits 1-15 reserved
  636. ;      DI = version number            (Windows only)
  637.  
  638. ; Return: CX                    (Windows only)
  639. ;       = 0000h if okay for Windows to load
  640. ;       = FFFFh (other registers unchanged) if Windows in standard mode
  641. ;       <> 0 if Windows should not load
  642.  
  643. ;      ES:BX -> startup info structure
  644. ;      DS:SI -> virtual86 mode enable/disable callback (Windows only)
  645. ;           or 0000h:0000h
  646.  
  647. InitDOSX:
  648. IdInst: pushf            ;Simulate 'int' operation
  649.     call    _org2Fh        ;
  650.  
  651.     if_    ax,e,4B05h,LinkInst
  652.  
  653.     jcxnz    _iret
  654.  
  655.     push    ax
  656.     mov    al,EmuStat
  657.     mov    StatBack,al
  658.     and    al,not ACTIVE
  659.     or    al,SBAVAIL
  660.     mov    EmuStat,al
  661.     pop    ax
  662.  
  663. LinkInst:movd    NextInfo,es,bx
  664.     mov    bx,offset StartInfo    ;ES:BX -> startup information structure
  665.     movp    es,cs            ;
  666. _iret:    iret
  667. int2Fh    endp
  668. TSRSize equ    $-top        ;Resident size (installed as a TSR)
  669. ;==================
  670. ; Device Driver
  671. ; Strategy Routine
  672. ;==================
  673. strategy proc    far
  674.     movd    request,es,bx
  675.     ret
  676. strategy endp
  677. ;===================
  678. ; Device Driver
  679. ; Interrupt Routine
  680. ;===================
  681. _command proc    far
  682.     pushs    <ds,bx>
  683.     lds    bx,request
  684. CmdFail:mov    [bx].rhStat,810Ch    ;General failure
  685. CmdQ:    pops    <bx,ds>
  686.     ret
  687. _command endp
  688. DrvEnd    label    far
  689.  
  690. command proc    far
  691.     pushs    <ds,bx>
  692.     lds    bx,request
  693.     if_    [bx].rhFunc,ne,0,CmdFail
  694.     call    hello
  695.     call    GetVect
  696.     call    install
  697.     mov    word ptr dhCmd,offset _command
  698.     movd    [bx].irEnd,cs,<offset DrvEnd>
  699.     mov    [bx].rhStat,100h    ;Done
  700.     jmp    CmdQ
  701. command endp
  702. ;=================
  703. ; Message Strings
  704. ;=================
  705. MsgHello    db    13,10,'More Information Lines on your Display - Version '
  706.         db    VER,' -',13,10,'Copyright (c) 1993, 1994, Kyosuke Tokoro.  '
  707.         db    'All rights reserved.',13,10,10,'$'
  708. MsgHelp     db    'Usage:',9,' MILD7',9,'/UNLOAD',9,9,'Remove from memory.',13,10
  709.         db    10,9,' MILD7',9,'screen_mode',9,'Change screen mode.',13,10
  710.         db    9,9,9,9,'80x25, 80x30, 80x34, 80x43, 80x50 or 80x60',13,10,10
  711.         db    9,' MILD7',9,'OFF',9,9,'Disable Video7 BIOS emulation.',13,10
  712.         db    10,9,' MILD7',9,'ON',9,9,'Enable Video7 BIOS emulation.',13,10
  713.         db    '$'
  714. MsgBadVideo db    'Warnning: Unknown parameter specified is ignored.',13,10,10
  715.         db    '$'
  716. MsgNoUSMode db    '注意: MILD7の画面モード設定機能はDBCS環境では利用できません.'
  717.         db    13,10,10,'$'
  718. MsgInvSw    db    'Invalid switch - /'
  719. MsgInvSw0   db    ?,'.',13,10,'$'
  720. MsgAlready  db    'Error:',9,'Video7 BIOS is in this system.  '
  721.         db    'No MILD7 emulation is not required.',13,10
  722.         db    9,'Or a old version of MILD7 is already stayed in memory.'
  723.         db    13,10,'$'
  724. MsgNotInst  db    'Error:',9,'Cannot unload.  MILD7 is not installed.',13,10
  725.         db    9,'Or resident MILD7 is a old version.',13,10,'$'
  726. MsgBadVect  db    'Error: Int 10h vector is traped by another progrem.  '
  727.         db    'Cannot unload.',13,10,'$'
  728. MsgUnload   db    'Successfuly unloaded.',13,10,'$'
  729. MsgNoTSR    db    'Error: Cannot unload resident which was installed as a device'
  730.         db    ' driver.',13,10,'$'
  731. MsgInst     db    'Successfuly installed.',13,10,'$'
  732. MsgBadVer   db    'Error: Resident MILD7 is a different version.',13,10,'$'
  733.  
  734. MsgStat db    '  Video7 emulation:  '
  735. MsgEmu    db    'ON ',13,10
  736.     db    'Video current mode:  '
  737. MsgMode db    '00h    Page: '
  738. MsgPage db    '00h',13,10
  739.     db    '    Columns x Rows: '
  740. MsgCols db    ' 00 x'
  741. MsgRows db    ' 00 characters',13,10
  742.     db    '  Character height: '
  743. MsgScan db    '  0 scan lines / a character',13,10,'$'
  744. ;=====================
  745. ; Transient Work Area
  746. ;=====================
  747.     even
  748. fcb    dw    6Ch+1    ;Normaly 5Ch+1
  749. resident dw    0    ;Segment address of resident code
  750. ;========================
  751. ; Video Mode Table
  752. ; for _SetMode Procedure
  753. ;========================
  754. ModeTable dw       2    ;80x25
  755.     dw    1400h    ;80x30
  756.     dw    1201h    ;80x43
  757.     dw    1202h    ;80x50
  758.     dw       0    ;80x60
  759. ;        ||++---- Required scan lines:  0= 480;    1= 350;  2= 400
  760. ;==========    ++------ Font to load:    0= default;  12h= 8x8;    14= 8x16
  761. ; Greeting
  762. ;==========
  763.     assume    ds:code
  764. hello    proc    near
  765.     pushs    <ax,dx>
  766.     mov    dx,offset MsgHello
  767.     call    puts
  768.     pops    <dx,ax>
  769. HelloQ: ret
  770. hello    endp
  771. ;======================
  772. ; Get Interrupt Vector
  773. ;======================
  774.     assume    ds:nothing
  775. GetVect proc    near
  776.     pushs    <es,ax,bx>
  777.     irp    i,<10h,2Fh>
  778.     mov    ax,35&i        ;Get int i vector
  779.     int    21h            ;
  780.     movd    _org&i,es,bx
  781.     endm
  782.     pops    <bx,ax,es>
  783.     ret
  784. GetVect endp
  785. ;======================
  786. ; Get Resident Address
  787. ;======================
  788. GetResident proc near
  789.     push    es
  790.     mov    ax,6F3Fh
  791.     int    10h
  792.     if_    ax,ne,3F6Fh,GRQuit
  793.  
  794.     assume    es:code
  795.     mov    dx,offset MsgBadVer
  796.  
  797.     mov    si,offset sign
  798.     mov    di,si
  799.     cld
  800.     rept    2
  801.     cmps    word ptr cs:sign,word ptr sign
  802.     jne    xxPutRC1
  803.     endm
  804.  
  805.     mov    cs:resident,es
  806.  
  807. GRQuit: pop    es
  808.     ret
  809.  
  810. xxPutRC1:jmp    PutRC1
  811. GetResident endp
  812. ;=========
  813. ; Install
  814. ;=========
  815.     assume    ds:code,es:nothing
  816. install proc    near
  817.     pushs    <ax,dx,ds>
  818.     movp    ds,cs
  819.     irp    i,<10h,2Fh>
  820.     mov    ax,25&i
  821.     mov    dx,offset int&i
  822.     int    21h        ;Set interrupt vector
  823.     endm
  824.     pops    <ds,dx,ax>
  825.     ret
  826. install endp
  827. ;================
  828. ; Enable/Disable
  829. ;================
  830. ;      DS = segment address of program segment prefix
  831. ;      CX = resident code segment
  832. ; Return: CF if no valid paramter found
  833.  
  834.     assume    ds:nothing,es:code    ;ES = resident code segment
  835. OnOff    proc    near
  836.     push    es
  837.     mov    es,cx
  838.     mov    bx,cs:fcb
  839.     inc    bx
  840.     mov    ax,[bx]
  841.     if_    ax,e,'FF',off
  842.     if_    al,ne,'N',NoParam0
  843.     or    es:EmuStat,ACTIVE
  844.     jmp    short OnOff0
  845.  
  846. NoParam0:pop    es
  847.     stc
  848.     ret
  849.  
  850. off:    and    es:EmuStat,not ACTIVE
  851. OnOff0: pop    es
  852. ;======================
  853. ; Display Video Status
  854. ;======================
  855.     assume    ds:code,es:nothing
  856. x2c    macro    func,value,IncReq
  857.     mov    di,offset Msg&value
  858.     mov    al,Video&value
  859.     if    IncReq
  860.     inc    ax
  861.     endif
  862.     call    func
  863.     endm
  864.  
  865. PutStat proc    near
  866.     pushs    <ds,es>
  867.     mov    ds,cs:resident
  868.     testif    EmuStat,ACTIVE,nz,PutStat0
  869.     mov    word ptr cs:MsgEmu+1,'FF'
  870.  
  871.     assume    ds:bios,es:code
  872. PutStat0:xor    ax,ax
  873.     mov    ds,ax
  874.     movp    es,cs
  875.     cld
  876.     x2c    h2c,Mode,0
  877.     x2c    h2c,Page,0
  878.     x2c    d2c,Cols,0
  879.     x2c    d2c,Rows,1
  880.     x2c    d2c,Scan,0
  881.     mov    dx,offset MsgStat
  882.     pops    <es,ds>
  883.     assume    ds:code,es:nothing
  884. puts    proc
  885.     push    ds
  886.     mov    ah,9            ;Write string to standard output
  887.     movp    ds,cs            ;
  888.     int    21h            ;
  889.     pop    ds
  890.     clc
  891.     ret
  892. puts    endp
  893.  
  894.     assume    ds:bios,es:code
  895. _d2c    proc    near
  896.     xor    ah,ah
  897.     div    dl
  898.     jalz    _d2cQ
  899.     add    al,'0'
  900.     mov    es:[di],al
  901. _d2cQ:    mov    al,ah
  902.     inc    di
  903.     ret
  904. _d2c    endp
  905.  
  906. d2c    proc    near
  907.     irp    i,<100,10>
  908.     mov    dl,i
  909.     call    _d2c
  910.     endm
  911.     add    es:[di],ah
  912.     ret
  913. d2c    endp
  914.  
  915. h2c    proc    near
  916.     push    ax
  917.     shr    al,4
  918.     call    h2c0
  919.     pop    ax
  920. h2c0    proc    near
  921.     push    ax
  922.     and    al,0Fh
  923.     if_    al,le,9,h2c1
  924.     add    al,'A'-'0'-10
  925. h2c1:    add    al,'0'
  926.     stosb
  927.     pop    ax
  928.     ret
  929. h2c0    endp
  930. h2c    endp
  931. PutStat endp
  932. OnOff    endp
  933. ;================
  934. ; Set Video Mode
  935. ;================
  936. ;      DS = segment address of program segment prefix
  937. ; Return: CF if no valid paramter found
  938.  
  939.     assume    ds:nothing,es:nothing
  940. SetMode proc    near
  941.     mov    dx,offset MsgBadVideo
  942.     mov    bx,fcb
  943.     mov    ax,[bx+3]
  944.     if_    al,e,' ',SetModeErr
  945.     if_    ah,e,'4',Set80x34
  946.     if_    al,a,'7',PutsErr
  947.     sub    al,'2'
  948.     jb    PutsErr
  949.     cbw
  950.     shl    ax,1
  951.     mov    bx,ax
  952.     mov    ax,ModeTable[bx]
  953.     mov    bh,ah
  954.     jmp    short SetMode0
  955.  
  956. Set80x34:xor    al,al    ;80x34 (480 scan lines with 8x14 dot font)
  957.     mov    bh,11h    ;
  958.  
  959. SetMode0:pushs    <ds,es,ax,bx>
  960.     mov    ax,6300h        ;Get DBCS vector
  961.     int    21h            ;
  962.     cmp    word ptr[si],0
  963.     pops    <bx,ax,es,ds>
  964.     mov    dx,offset MsgNoUSMode
  965.     je    _SetMode
  966. PutsErr:call    puts            ;Don't a MILD7's mode in DBCS env.
  967. SetModeErr:stc
  968.     ret
  969. ;---
  970. ;      AL = vertical resolution
  971. ;           00h 480 scan lines
  972. ;           01h 350 scan lines
  973. ;           02h 400 scan lines
  974. ;      BH = character set to load
  975. ;           00h default font
  976. ;           11h 8x14
  977. ;           12h 8x 8
  978. ;           14h 8x16
  979.  
  980. _SetMode:jalz    SetMode43h
  981.     mov    ah,12h        ;Select vertical resolution
  982.     mov    bl,30h        ;
  983.     int    10h        ;
  984.     mov    ax,3
  985.     jmp    short DoSetMode
  986.  
  987. SetMode43h:mov    ax,43h
  988. DoSetMode:int    10h        ;Set video mode
  989.     jbhz    SetModeQ
  990.     mov    ah,11h        ;Text-mode character generator functions
  991.     mov    al,bh        ;
  992.     xor    bl,bl        ;
  993.     int    10h        ;
  994. SetModeQ:clc
  995.     ret
  996. SetMode endp
  997. ;================
  998. ; Main Transient
  999. ;================
  1000.     assume    ss:stacks
  1001. init    proc    far
  1002.     mov    psp,ds
  1003.  
  1004.     mov    bx,5Ch+1
  1005.     if_    <word ptr[bx]>,e,'IM',init0
  1006.     mov    fcb,bx
  1007.  
  1008. init0:    call    hello
  1009.     call    GetVect
  1010.     call    GetResident
  1011.  
  1012.     mov    di,81h
  1013.     mov    cl,[di-1]
  1014.     xor    ch,ch
  1015.     jcxz    ChkInst
  1016.     mov    al,'/'
  1017.     cld
  1018.   repne scasb
  1019.     jne    ChkInst
  1020.     mov    al,[di]
  1021.     mov    dx,offset MsgHelp    ;If /? then display help and
  1022.     if_    al,e,'?',PutRC        ;exit with RC=0
  1023.     or    al,20h            ;Convert to upper case letter
  1024.     if_    al,e,'u',unload
  1025.  
  1026.     mov    MsgInvSw0,al
  1027.     assume    ds:code
  1028.     mov    dx,offset MsgInvSw
  1029. PutRC1: stc
  1030. PutRC:    pushf
  1031.     call    puts
  1032.     popf
  1033. RetRC:    mov    ax,4C00h        ;Terminate with return code
  1034.     adc    al,al            ;
  1035.     int    21h            ;
  1036. ;---------
  1037. ; Install
  1038. ;---------
  1039.     assume    ds:nothing
  1040. ChkInst:mov    cx,resident        ;Is MILD7 installed?
  1041.     jcxz    ChkInst0        ; No...
  1042.     callif    OnOff,nc,RetRC
  1043.     callif    SetMode,nc,RetRC
  1044.     call    PutStat
  1045.     clc
  1046.     jmp    RetRC
  1047.  
  1048. ChkInst0:mov    ax,6F00h        ;Video 7 Installation check
  1049.     xor    bx,bx            ;
  1050.     int    10h            ;
  1051.     mov    dx,offset MsgAlready
  1052.     if_    bx,e,5637h,PutRC1
  1053.  
  1054.     mov    ah,49h            ;Free memory
  1055.     mov    es,ds:[2Ch]        ; Segment of environment for process
  1056.     int    21h            ;
  1057.  
  1058.     call    install
  1059.     callif    OnOff,nc,TermStay
  1060.     callif    SetMode,c,TermStay
  1061.  
  1062.     call    hello
  1063.  
  1064. TermStay:mov    dx,offset MsgInst
  1065.     call    puts
  1066.  
  1067.     mov    dx,(TSRSize+1Fh)/10h+code
  1068.     sub    dx,psp
  1069.     mov    ax,3100h        ;Terminate and stay resident
  1070.     int    21h            ;
  1071. ;--------
  1072. ; Unload
  1073. ;--------
  1074.     even
  1075. HelloInd dw    HelloQ
  1076.  
  1077. xPutRC1:jmp    PutRC1
  1078.  
  1079. unload: mov    cx,resident
  1080.     mov    dx,offset MsgNotInst
  1081.     jcxz    PutRC1
  1082.  
  1083.     mov    si,offset int10h
  1084.     les    di,_org10h
  1085.     mov    ax,es
  1086.     mov    dx,offset MsgBadVect
  1087.     if_    ax,ne,cx,xPutRC1
  1088.  
  1089.     assume    es:code            ;ES -> segment of resident
  1090.     mov    dx,offset MsgNoTSR
  1091.     if_    es:psp,e,0,xPutRC1    ;Branch if installed as a driver
  1092.  
  1093.     mov    ah,0Fh            ;Get current video mode
  1094.     int    10h            ;
  1095.     if_    al,e,41h,unload0
  1096.     if_    al,e,43h,unload0
  1097.     if_    al,ne,5Bh,unload1
  1098.  
  1099. unload0:mov    cs:HelloInd,offset hello
  1100.  
  1101.     mov    al,2            ;400 scan lines
  1102.     xor    bh,bh            ;Load default font
  1103.     call    _SetMode
  1104.  
  1105. unload1:irp    i,<10h,2Fh>
  1106.     mov    ax,25&i        ;Set int i vector
  1107.     lds    dx,es:_org&i    ;
  1108.     int    21h            ;
  1109.     endm
  1110.  
  1111.     mov    ah,49h            ;Free memory
  1112.     mov    es,es:psp        ;
  1113.     assume    es:nothing        ;
  1114.     int    21h            ;
  1115.  
  1116.     call    HelloInd
  1117.     mov    dx,offset MsgUnload
  1118.     clc
  1119.     jmp    PutRC
  1120. init    endp
  1121. code    ends
  1122. ;===============
  1123. ; Stack Segment
  1124. ;===============
  1125. stacks    segment word stack'STACK'
  1126.     dw    384 dup(?)
  1127. stacks    ends
  1128.     end    init
  1129.