home *** CD-ROM | disk | FTP | other *** search
- ;
- ; wch.asm
- ;
- .286
- code segment
- org 100h
- assume cs:code, ds:code
- begin: jmp start
- ;
- CSver db 'CHCS 1.0'
- ;
- Psp dw ?
- Env dw ?
- db 0
- ;
- wHas db 0
- uHas db 0
- ;
- ; ---------------------------------------
- ;
- PageSize equ 1024
- ; ------------------------------------------------
- xHandle dw ?
- xEntry dd 0
- ; ------------------------------------------------
- xStruc label word
- Count dw ? ; Transfer Bytes
- dw 0
- sHandle dw ? ; Source Handle
- sOffset dd ? ; Source Offset
- dHandle dw ? ; Destinate Handle
- dOffset dd ? ; Destinate Offset
- ; ------------------------------------------------
- xStruc2 label word
- Count2 dw 512 ; Transfer Bytes
- dw 0
- sHandle2 dw ? ; Source Handle
- sOffset2 dw ? ; Source Offset
- dw 0
- dHandle2 dw 0 ; Destinate Handle
- dOffset2 dd ? ; Destinate Offset
- ; ------------------------------------------------
- ;
- TSREnd dw ?
- wEnd dw ?
- wSize dw ?
- nPage db ?
- eSize dw ?
- ;
- cPage db 0
- cSize dw PageSize
- cPntr dw ?
- ccPage db 0
- ;
- ; ---------------------------------------
- ;
- WordProc proc far
- ;
- sti
- cmp ah, 39h
- je toCC1
- cmp ah, 3ah
- je toWord
- cmp ah, 3eh
- je toUnLib
- retf
- ;
- toCC1: call GetWordCC1
- retf
- ;
- toWord: call GetWord
- retf
- ;
- toUnLib: call UnInstallWLib
- retf
- WordProc endp
- ; ----------------------------
- GetWordCC1 proc near
- ;
- ; IN: ah = 39h
- ; al = 0 ... Get WLib First CC
- ; al = 1 ... Get WLib Next CC
- ; OUT: ah = 0 ... Ok
- ; dx = CC
- ; ah != 0 .. Fail
- ; dx = 0
- ;
- push ds
- push si
- push bx
- push cx
- mov si, cs
- mov ds, si
- ;
- cmp wHas, 1
- jne toCCRetn
- cmp al, 1
- je toGetNextCC
- ja toCCRetn
- ;
- mov si, wStart
- mov cPntr, si
- cmp nPage, 0
- je ccCont0
- mov cPage, 0
- mov ccPage, 0
- call MapPage
- jmp ccCont0
- ;
- toCCRetn: jmp GetCCRetn
- ;
- toGetNextCC: cmp nPage, 0
- je ccCont0
- mov bl, ccPage
- cmp bl, cPage
- je ccCont0
- mov cPage, bl
- call MapPage
- ccCont0: mov si, wStart
- mov bx, cPntr
- mov cx, bx
- sub cx, si
- jb GetCCRetn
- shr cx, 1
- ;
- cmp nPage, 0
- je GetCCLoop0
- xor al, al
- mov ah, cPage
- shl ax, 1
- add cx, ax
- jmp GetCCLoop0
- ;
- toNextPage: cmp nPage, 0
- je GetCCRetn
- inc cPage
- call MapPage
- mov bl, cPage
- mov ccPage, bl
- mov bx, wStart
- ;
- GetCCLoop0: cmp bx, wEnd
- jae toNextPage
- cmp cx, 3755
- jae toGetCCW2
- cmp word ptr [bx], 0
- jne isFoundCC
- inc cx
- inc bx
- inc bx
- jmp GetCCLoop0
- ;
- toGetCCW2: mov dx, [bx]
- cmp dx, 0ffffh
- jne isFoundCC2
- mov word ptr cPntr, 0
- ;
- GetCCRetn: mov ax, 8080h
- xor dx, dx
- pop cx
- pop bx
- pop si
- pop ds
- ret
- ;
- isFoundCC2: add bx, 4
- cmp word ptr [bx], 0ffffh
- jne SkipRePntr
- xor bx, bx
- SkipRePntr: mov cPntr, bx
- xchg dl, dh
- xor ax, ax
- pop cx
- pop bx
- pop si
- pop ds
- ret
- ;
- isFoundCC: mov ax, bx
- inc bx
- inc bx
- mov cPntr, bx
- sub ax, si
- shr ax, 1
- mov dl, 94
- cmp nPage, 0
- je ccSkip0
- ;
- mov bh, cPage
- xor bl, bl
- shl bx, 1
- add ax, bx
- ;
- ccSkip0: div dl
- mov dx, ax
- xchg dl, dh
- add dx, 0b0a1h
- xor ax, ax
- pop cx
- pop bx
- pop si
- pop ds
- ret
- GetWordCC1 endp
- ; ----------------------------
- GetWord proc near
- ;
- ; IN: ah = 3ah
- ; al = 0 ... Get First WORD of Specify CC
- ; dx = CC
- ; al = 1 ... Get Next
- ; al = 2 ... Get StdCWLib Addr
- ; al = 3 ... Get UsrCWLib Addr
- ;
- ; es:bx = buffer
- ; OUT: ah = 0 ... Ok
- ; es:bx = CCWord String
- ; cx = CC Num
- ; ah != 80h ... Fail
- ; es:bx = &StdCWlib (IN: al = 2)
- ; es:bx = &UsrCWlib (IN: al = 3)
- ; cx = CWLibLen (IN: al = 2/3)
- ;
- xor cx, cx
- cmp al, 2
- jae toGetuStart
- cmp cs:wHas, 1
- jne toGetCWRetn
- cmp al, 1
- je GetWordCont0
- cmp dh, 0b0h
- jb toGetCWRetn
- cmp dl, 0a0h
- ja GetWordCont0
- toGetCWRetn: mov ax, 8080h
- ret
- ;
- toGetuStart: cmp al, 3
- ja toGetCWRetn
- jb toGetStdAddr
- cmp cs:uHas, 1
- jne toGetCWRetn
- mov bx, cs
- mov es, bx
- lea bx, cs:uStart
- mov cx, cs:uLen
- xor ax, ax
- ret
- ;
- toGetStdAddr: cmp cs:wHas, 1
- jne toGetCWRetn
- cmp nPage, 0
- jne toGetCWRetn
- mov bx, cs
- mov es, bx
- mov bx, cs:wStart
- mov cx, cs:wLen
- xor ax, ax
- ret
- ;
- wPntr dw 0
- wEntry dw 0
- ;
- GetWordCont0: push ds
- push si
- push bx
- mov si, cs
- mov ds, si
- mov si, wStart
- cmp al, 1
- je toNextWord
- push bx
- cmp dh, 0d8h
- jae toGet2ndCW
- sub dx, 0b0a1h
- mov al, 94
- mul dh
- xor dh, dh
- add ax, dx
- shl ax, 1
- add si, ax
- cmp nPage, 0
- je GetWordCont1
- shr ah, 1
- shr ah, 1
- cmp ah, cPage
- je cwSkipMap
- ;
- mov cPage, ah
- call MapPage
- ;
- cwSkipMap: xor al, al
- shl ah, 1
- shl ah, 1
- sub si, ax
- jmp GetWordCont1
- ;
- toNextWord: jmp toGetNextWord
- ;
- toGet2ndCW: add si, 3755*2
- cmp nPage, 0
- je GetCW2Loop0
- mov si, wStart
- add si, (3755 MOD 512) * 2
- cmp cPage, 7
- je GetCW2Loop0
- mov cPage, 7
- call MapPage
- GetCW2Loop0: cmp dx, [si]
- je isFoundCW
- cmp word ptr [si], 0ffffh
- je trunNoCW
- add si, 4
- jmp GetCW2Loop0
- ;
- isFoundCW: add si, +2
- GetWordCont1: pop bx
- mov ax, [si]
- or ax, ax
- jz trunAbort
- mov si, ax
- ;
- call ReadCWord
- ;
- mov wPntr, si
- mov wEntry, si
- toGetNextWord: mov si, wEntry
- or si, si
- jz trunAbort
- cld
- GetCWLoop: lodsw
- mov dx, ax
- or dx, 8080h
- mov es:[bx], dx
- inc bx
- inc bx
- inc cx
- test ah, 80h
- je toGetCWEnd
- test al, 80h
- je GetCWLoop
- cmp si, wPntr
- jbe GetCWLoop
- jmp toGetCWEnd1
- ;
- trunNoCW: pop bx
- trunAbort: pop bx
- pop si
- pop ds
- ret
- ;
- toGetCWEnd: test al, 80h
- jne GetCWSkip0
- xor si, si
- GetCWSkip0: mov wEntry, si
- toGetCWEnd1: mov byte ptr es:[bx], 0
- mov wPntr, si
- xor ax, ax
- pop bx
- pop si
- pop ds
- ret
- ;
- GetWordRetn: mov wEntry, 0
- mov wPntr, 0
- mov ax, 8080h
- pop bx
- pop si
- pop ds
- ret
- GetWord endp
- ; ----------------------------
- UnInstallWLib proc near
- ;
- ; IN: ah = 3eh
- ; al = 0 ... uninstall StdWLib
- ; al = 1 ... uninstall UsrWLib
- ; OUT: ax = 0 ... Ok
- ; ax != 0 .. Fail
- ;
- push es
- push ds
- push cs
- pop ds
- cmp al, 1
- ja UnInsWRetn
- je UnInsUsrWLib
- cmp wHas, 1
- jne UnInsWRetn
- ;
- mov wHas, 0
- cmp nPage, 0
- je UnInsWCont
- mov ah, 0ah
- mov dx, xHandle
- call dword ptr xEntry
- ;
- UnInsWCont: cmp uHas, 1
- je UnInsWRet0
- mov es, Psp
- mov ah, 49h
- int 21h
- jmp UnInsWRet0
- ;
- UnInsUsrWLIb: cmp uHas, 1
- jne UnInsWRetn
- mov uHas, 0
- ;
- cmp wHas, 1
- je UnInsWRet0
- mov es, Psp
- mov ah, 49h
- int 21h
- ;
- UnInsWRet0: xor ax, ax
- UnInsWExit: pop ds
- pop es
- ret
- ;
- UnInsWRetn: mov ax, 8080h
- jmp UnInsWExit
- UnInstallWLib endp
- ; -------------------------------
- ReadCWord proc near
- ;
- ; IN: si = Offset of CWord Lib
- ;
- cmp nPage, 0
- je toSetAddr
- pusha
- mov word ptr sOffset2, si
- lea si, xStruc2
- mov ah, 0bh
- call dword ptr xEntry
- popa
- mov si, wEnd
- ret
- ;
- toSetAddr: add si, wStart
- ret
- ReadCWord endp
- ; -------------------------------
- MapPage proc near
- ;
- ; IN: cPage = to be Mapped
- ;
- pusha
- push ds
- mov ax, cs
- mov ds, ax
- xor ah, ah
- mov al, cPage
- mov cx, PageSize
- mul cx
- mov word ptr sOffset, ax
- lea si, xStruc
- mov ah, 0bh
- call dword ptr xEntry
- pop ds
- popa
- ret
- ;
- inPage db 0
- MapPage endp
- ;
- ; -------------------------------
- ;
- CWMax equ 0f000h
- ;
- CwordVer dw ?
- wStart dw ?
- wBuffer dw ?
- ;
- wLen dw ?
- uLen dw ?
- db 'CWord Lib : '
- ;
- uStart db CWMax dup(0ffh)
- ;
- ; -------------------------------
- ;
- MoveToXMS proc near
- ;
- cmp word ptr xEntry+2, 0
- jne toXMS
- ;
- SetNoXMS: mov nPage, 0
- mov ax, wEnd
- mov TSREnd, ax
- ret
- ;
- toXMS: mov dx, wLen
- test dx, 03ffh
- jz noInc
- add dx, 400h
- noInc: mov dl, dh
- xor dh, dh
- shr dx, 1
- shr dx, 1
- ;
- mov ah, 9
- call dword ptr xEntry
- cmp bl, 0
- jne SetNoXMS
- mov xHandle, dx
- ;
- mov dHandle, dx
- mov ax, wLen
- mov Count, ax
- mov sHandle, 0
- mov ax, wStart
- mov word ptr sOffset, ax
- mov ax, cs
- mov word ptr sOffset+2, ax
- mov word ptr dOffset, 0
- mov word ptr dOffset+2, 0
- mov ah, 0bh
- lea si, xStruc
- call dword ptr xEntry
- cmp bl, 0
- je MoveSucceed
- ;
- mov ah, 0ah
- mov dx, xHandle
- call dword ptr xEntry
- jmp SetNoXMS
- ;
- MoveSucceed: mov Count, PageSize
- mov ax, xHandle
- mov sHandle, ax
- mov word ptr sOffset+2, 0
- mov ax, wStart
- mov word ptr dOffset, ax
- mov ax, cs
- mov word ptr dOffset+2, ax
- mov dHandle, 0
- ;
- mov ax, xHandle
- mov sHandle2, ax
- mov ax, wStart
- add ax, PageSize
- mov word ptr dOffset2, ax
- mov ax, cs
- mov word ptr dOffset2+2, ax
- ;
- mov bx, PageSize
- mov cSize, bx
- mov ax, wStart
- add ax, bx
- mov wEnd, ax
- add ax, 512
- mov TSREnd, ax
- mov ax, wLen
- xor dx, dx
- div bx
- mov nPage, al
- mov eSize, dx
- mov cPage, 0
- ret
- MoveToXMS endp
- ;
- ; -------------------------------
- ;
- Path db 80 dup(?)
- StCW db 'xisch.dat', 0
- UsrCW db 'usrch.dat', 0
- ;
- CSMark db 13, 10, 9, 'CHCS'
- noCHCS db 7, 'wch: CHCS/CHIS not installed !', 0dh,0ah, '$'
- BadVer db 7, 'wch: ░µ▒╛║┼▓╗╢╘', 0dh, 0ah, '$'
- BadFile db 7, 'wch: ┤φ╬≤┤╩┐Γ╕±╩╜╗≥░µ▒╛║┼▓╗╢╘', 0dh,0ah, '$'
- ReInst db 'wch: ┤╩┐Γ╥╤╫░╚δ !', 0dh,0ah, '$'
- noFile db 7, 'wch: ╬┤─▄┤≥┐¬┤╩┐Γ╬─╝■ !', 0dh,0ah, '$'
- ;
- Handle dw ?
- NameOff dw ?
- ;
- db 100h dup(0)
- rStack label byte
- ;
- start: mov ax, 3f00h
- int 16h
- mov di, bx
- lea si, CSMark
- mov cx, 5
- cld
- repz cmpsb
- jz iCont00
- lea dx, noCHCS
- jmp PrError
- ;
- iCont00: cmp ax, 0100h
- je iCont01
- lea dx, BadVer
- jmp PrError
- ;
- ; Test XMS memory
- ;
- iCont01: mov ax, 4300h
- int 2fh
- cmp al, 80h
- jne iNoXMS
- mov ax, 4310h
- int 2fh
- mov word ptr xEntry, bx
- mov word ptr xEntry+2, es
- ;
- iNoXMS: push cs
- pop es
- lea ax, rStack
- mov sp, ax
- mov ax, ds
- mov Psp, ax
- mov ax, ds:[2ch]
- mov Env, ax
- xor si, si
- mov ds, ax
- iLoop0: cmp word ptr [si], 0
- je iEnd0
- inc si
- jmp iLoop0
- iEnd0: add si, +4
- lea di, Path
- iLoop1: lodsb
- stosb
- or al, al
- jz iEnd1
- cmp al, '\'
- jne iLoop1
- mov es:NameOff, di
- jmp iLoop1
- iEnd1: mov ax, cs
- mov ds, ax
- mov di, NameOff
- lea si, UsrCW
- iLoop2: lodsb
- stosb
- cmp al, 0
- jne iLoop2
- ;
- mov ax, 3d00h
- lea dx, UsrCW
- int 21h
- jnc iCont
- mov ax, 3d00h
- lea dx, Path
- int 21h
- jnc iCont
- jmp toLoadST
- ;
- toErr: lea dx, noFile
- jmp PrError
- ;
- iCont: mov bx, ax
- mov ah, 3fh
- mov cx, 3000h
- lea dx, uStart
- int 21h
- jc toErr
- mov uLen, ax
- mov ah, 3eh
- int 21h
- ;
- mov uHas, 1
- mov ax, 3c01h
- lea bx, WordProc
- mov cx, uLen
- push cs
- pop es
- int 16h
- or ax, ax
- jz iContu
- ;
- toLoadST: mov word ptr uLen, 2
- mov byte ptr uHas, 0
- iContu: lea ax, uStart
- add ax, uLen
- mov word ptr CwordVer, ax
- add ax, 0010h
- mov word ptr wStart, ax
- ;
- mov bx, NameOff
- mov byte ptr [bx], 'X'
- mov byte ptr [bx+1], 'I'
- mov byte ptr [bx+2], 'S'
- lea dx, Path
- mov ax, 3d00h
- int 21h
- jc toErr
- mov bx, ax
- mov ah, 3fh
- mov dx, CwordVer
- mov cx, CWMax
- sub cx, uLen
- int 21h
- pushf
- and al, 0feh
- mov wLen, ax
- mov wSize, ax
- add ax, wStart
- mov wEnd, ax
- mov TSREnd, ax
- mov ah, 3eh
- int 21h
- popf
- jnc iConti
- jmp toErr
- ;
- iConti: mov nPage, 0
- ;
- lea si, CSVer
- mov di, CwordVer
- mov cx, 8
- push cs
- pop es
- cld
- repz cmpsb
- jz iContIn
- lea dx, BadFile
- jmp PrError
- ;
- iContIn: mov wHas, 1
- mov ax, 3c00h
- lea bx, WordProc
- mov cx, wLen
- push cs
- pop es
- int 16h
- or ax, ax
- jz iContw
- mov wHas, 0
- mov wLen, 0
- mov wSize, 0
- jmp iContw1
- ;
- iContw: cmp word ptr xEntry+2, 0
- je iContw1
- ;
- call MoveToXMS
- ;
- iContw1: cmp wHas, 1
- je toTSR
- cmp uHas, 1
- je toTSR
- lea dx, ReInst
- jmp PrError
- ;
- toTSR: mov dx, TSREnd
- inc dx
- inc dx
- push dx
- mov es, Env
- mov ah, 49h ; Free Environment
- int 21h
- pop dx
- mov cl, 4
- shr dx, cl
- inc dx
- mov ax, 3100h
- int 21h
- ;
- PrError: mov ah, 09h
- int 21h
- mov ax, 4c01h
- int 21h
- ;
- code ends
- end begin
-