Skip to content

Instantly share code, notes, and snippets.

@lpproj
Created July 23, 2015 06:11
Show Gist options
  • Save lpproj/633ec6abda82d33f176b to your computer and use it in GitHub Desktop.
Save lpproj/633ec6abda82d33f176b to your computer and use it in GitHub Desktop.
%if 0
np2sense.sys : ad hoc MS-DOS driver to fix mounting 2DD(640/720K) disk for NP2
Copyright (C) 2015 sava (t.ebisawa)
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
(in short term: `under the ZLIB license')
To build:
$ nasm -f bin -o np2sense.sys np2sense.nas
Description(日本語):
np2 で MS-DOS を(2DD フロッピー以外から)起動すると 2DD ディスクを
マウントしても認識してくれない。
とりあえず BIOS の SENSE コマンドだけダマくらかせば認識できるようなので
それらしいデバイスドライバを作った。
インストール:
PC-98 用 MS-DOS の config.sys に device=np2sense.sys とか書いて導入。
np2 以外の環境ではインストールされません。
(なお、2重インストールのチェックなどはしていません)
やっていること:
2HDドライブに SENSE コマンドが発行され、No Data エラーが返された場合
デバイスユニット番号を 2DD にしてもう一度 SENSE コマンドを発行する、だけ。
%endif
BITS 16
CPU 8086
%ifndef NP2PORT
%define NP2PORT 07efh
%endif
ORG 0
dd -1
dw 8000h
dw Strategy
dw Init_Commands
db '$NP2I1B$'
align 4
reqhdr dd 0
org1b dd 0
pad_ax dw 0
New1b:
pushf
push ax
and ax, 0f1ch
cmp ax, 0410h ; ah = 04h (SENSE), al = FD daua?
je .new1b_fdsense
.new1b_chain:
pop ax
popf
jmp far [cs: org1b]
.new1b_fdsense:
pop ax ; try first, as is
mov [cs: pad_ax], ax
call far [cs: org1b]
jc .fdsense_l2
retf 2 ; return if no err
.fdsense_l2:
push ax
and ah, 0fh
cmp ah, 0c0h ; if "No Data" (0Cxh) ?
jne .fdsense_l3
.fdsense_errret:
pop ax
stc
retf 2
.fdsense_l3: ; if 2HD(or 1.44M) drive...
mov ax, [cs: pad_ax]
and al, 0f0h
cmp al, 90h
je .fdsense_l4
cmp al, 30h
jne .fdsense_errret
.fdsense_l4:
pop ax
mov ax, [cs: pad_ax]
and al, 0fh ; try again but 2DD
or al, 10h
jmp far [cs: org1b]
Strategy:
mov word [cs:reqhdr], bx
mov word [cs:reqhdr + 2], es
retf
; just a stub...
Commands:
push bx
push ds
lds bx, [cs:reqhdr]
mov word [bx + 3], 8103h
pop ds
pop bx
retf
align 16
Bottom:
;
; check if NP2...
; zf=1: running on NP2
; zf=0: not on NP2
;
IsNP2:
cli
mov dx, NP2PORT
mov si, .np2mark
mov cx, .np2mark_end - .np2mark
push cx
push si
.lp_send:
lodsb ; (rep outsb...)
out dx, al
loop .lp_send
pop si
pop cx
.lp:
in al, dx
cmp al, [si]
jne .isnp2_exit ; zf = 0 on error
inc si
loop .lp
xor al, al ; zf = 1 if np2
.isnp2_exit:
sti
ret
.np2mark:
db 'NP2'
.np2mark_end:
dos_ver dw 0
Init_Commands:
push ax
push bx
push cx
push dx
push ds
push si
push di
push es
cld
mov word [cs: 0008h], Commands ; Release Init_Commands
push cs
pop ds
mov ah, 30h
int 21h
xchg ah, al
mov [dos_ver], ax
mov dx, msg_opening
mov ah, 09h
int 21h
call IsNP2
je .loc_tsr
mov dx, err_nonp2
mov ah, 09h
int 21h
lds bx, [cs: reqhdr]
mov byte [bx + 13], 0
mov word [bx + 14], 0
mov word [bx + 16], cs
cmp word [cs: dos_ver], 0300h + 20
jae .cmd_exit
; kludge for DOS 3.1 or below
mov word [cs: 0004h], 0 ; fake as block device
mov byte [cs: 000ah], 0
jmp short .cmd_exit
.loc_tsr:
mov ax, 351bh
int 21h
mov word [org1b], bx
mov word [org1b + 2], es
mov dx, New1b
mov ax, 251bh
int 21h
lds bx, [cs: reqhdr]
mov byte [bx + 13], 1
mov word [bx + 14], Bottom
mov word [bx + 16], cs
.cmd_exit:
pop es
pop ds
pop di
pop si
pop dx
pop cx
pop bx
pop ax
retf
msg_opening db 'np2sense by sava/LP-Project.', 13, 10, '$'
err_nonp2 db 'np2sense: Not on NP2.', 13, 10, '$'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment