home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FreeWare Collection 2
/
FreeSoftwareCollection2pd199x-jp.img
/
ms_dos
/
esc98
/
esc98.asm
next >
Wrap
Assembly Source File
|
1990-06-14
|
17KB
|
949 lines
page 60,80
.286c
.sall
;
; PC98ESCシーケンスシミュレータ
;
; esc98 ver 0.15 1989.05.02
;
; by とくさん
;
;
MODE equ 1
DISP equ 1
ON equ 1
SYSTEM equ 20h
LINES equ 40h
CURSOR equ 80h
GR_MODE equ 80h
FM_MODE equ 10h
CHECK equ 01h
DOS equ 21h
CR equ 0dh
LF equ 0ah
;
; メモリコントロールブロック定義
;
mcb_stru struc
mcb_id db ?
psp_seg dw ?
mcb_len dw ?
mcb_stru ends
;
code segment
assume cs:code,ds:code,es:code,ss:code
org 80h
int29 dd ?
intff dd ? ; for DEBUG
save_sp dw ?
save_ss dw ?
attribute_area db ?
attribute db ?
color dw ?
flag_lo db 0
flag_hi db 0
skip db 0
db 0
len dw 0
buffer db ?
org 100h
start:
jmp main
xcolor_tab db 0,2,4,6,1,3,5,7
xcolor_tab2 db 0,2,1,3,4,6,5,7
xattr_tab db 0,20h,4,2,80h,10h,1,8,40h
jump_tab dw _1st,_2nd,_3rd,_4th,_5th,above_5th
int29_entry:
push ds
push cs
pop ds
mov save_sp,sp
mov save_ss,ss
push cs
pop ss
mov sp,offset stack
mov bp,sp
pusha
sti
dec bp
dec bp ; ss:[bp] = AX
test flag_hi,CHECK
jnz test_mode
mov bx,len
cmp bx,6
jb int29_entry1
mov bx,5
int29_entry1:
shl bx,1
add bx,offset jump_tab
jmp word ptr [bx]
;
; テストモード
;
test_mode:
and flag_hi,not CHECK
jmp int29_ret
;
; バッファに格納
;
put_buffer:
cmp byte ptr len,128
ja out_buffer
put_buffer1:
mov di,offset buffer
mov bx,len
mov [di+bx],al
inc byte ptr len
;
; 復帰
;
int29_ret:
popa
mov ss,save_ss
mov sp,save_sp
pop ds
iret
;
; バッファクリアにして復帰
;
int29_ret0:
mov len,0
jmp int29_ret
;
; バッファの文字列出力
;
out_buffer:
mov flag_lo,0
mov cx,len
jcxz int29_quit
mov si,offset buffer
out_buffer_loop:
cld
lodsb
pushf
cli
call dword ptr [int29]
loop out_buffer_loop
mov len,cx
int29_quit:
cli
popa
mov ss,save_ss
mov sp,save_sp
pop ds
jmp dword ptr cs:[int29]
;
; 1文字目(ESCのチェック)
;
_1st:
cmp skip,0
jz chk_ESC
dec skip
jmp int29_quit
chk_ESC:
cmp al,1bh
je put_buffer
cmp al,' '
ja chk_graph
call is_ctrl
jmp int29_quit
chk_graph:
call is_kanji
jmp int29_quit
;
; 2文字目のチェック
; D / E / M …代替シーケンス出力(0→len)
; G / . …skip 設定(0→len)
; ) …モードフラグセット(len++)
; ] …継続(len++)
;
_2nd:
cmp al,'.'
jne chk_G
mov skip,2
jmp out_buffer
chk_G:
cmp al,'G'
jne chk_D
mov skip,1
jmp out_buffer
chk_D:
cmp al,'D'
jne chk_M
mov al,1fh ; ↓
jmp short _2nd_quit
chk_M:
cmp al,'M'
jne chk_E
mov al,1eh ; ↑
jmp short _2nd_quit
chk_E:
cmp al,'E'
jne chk_MODE
test flag_hi,FM_MODE
jnz out_buffer
mov al,0dh
pushf
cli
call dword ptr [int29]
mov al,1fh
_2nd_quit:
mov len,0
mov [bp],ax
jmp int29_quit
;
chk_MODE:
cmp al,')'
jne chk_continue
or flag_lo,MODE
_2nd_quit1:
jmp put_buffer
chk_continue:
cmp al,'['
je _2nd_quit1
cmp al,1bh
jne chk_continue1
test flag_hi,FM_MODE
jnz chk_continue1
jmp int29_ret0
chk_continue1:
jmp out_buffer
;
; 3文字目のチェック
; MODE & '0'~'9'…モード設定(0→len)
; > …モードフラグセット(len++)
; '0'~'9' …継続(len++)
;
_3rd:
test flag_lo,MODE
jz chk_DISP
mov flag_lo,0
cmp al,'3'
jne set_MODE
or flag_hi,GR_MODE
jmp int29_ret0
set_MODE:
cmp al,'0'
jne _3rd_quit
and flag_hi,not GR_MODE
set_MODE1:
jmp int29_ret0
chk_DISP:
call is_numeric1
jnc chk_DISP0
cmp al,'>'
jne chk_DISP1
or flag_lo,DISP
chk_DISP0:
jmp put_buffer
chk_DISP1:
call move_line
jnc set_MODE1
chk_DISP3:
cmp al,';'
jne _3rd_quit
test flag_hi,FM_MODE
jz chk_DISP0
_3rd_quit:
jmp out_buffer
;
; 4文字のチェック
; '0'~'9' & DISP …該当フラグセット
; '0'~'9' / ';' …継続
; 'm' …属性の変更
;
_4th:
test flag_lo,DISP
jz chk_attr
mov flag_lo,0
cmp al,'1'
jne chk_width
or flag_lo,SYSTEM
jmp short chk_disp_quit
chk_width:
cmp al,'3'
jne chk_cursor
or flag_lo,LINES
jmp short chk_disp_quit
chk_cursor:
cmp al,'5'
jne _3rd_quit
or flag_lo,CURSOR
chk_disp_quit:
jmp put_buffer
chk_attr:
call is_numeric1
jnc chk_disp_quit
chk_disp_error:
cmp al,';'
jne chk_disp_error1
test flag_hi,FM_MODE
jnz _3rd_quit
chk_disp_error1:
call move_line
jc _3rd_quit
jmp int29_ret0
;
; 5文字目のチェック
; (SYSTEM | LINES | CURSOR) & ('h' | 'l')…各種設定
; 'm' …属性変更
; '0'~'9' | ';' …継続
;
_5th:
test flag_lo,SYSTEM or LINES or CURSOR
jz above_5th
cmp al,'h'
je set_SYSTEM
cmp al,'l'
jne chk_disp_error
or flag_lo,ON
set_SYSTEM:
test flag_lo,SYSTEM
jz set_WIDTH
mov ax,1bc2h
test flag_lo,ON
jnz set_SYSTEM1
mov al,082h
set_SYSTEM1:
int 91h
set_DISP_quit:
mov flag_lo,0
jmp int29_ret0
set_WIDTH:
test flag_lo,LINES
jz set_CURSOR
mov dx,25*256+80
test flag_lo,ON
jz set_width1
mov dh,20
set_width1:
mov ah,03h
int 91h
jmp set_DISP_quit
set_CURSOR:
mov ax,0b01h
test flag_lo,ON
jz set_cursor1
xor al,al
set_cursor1:
int 91h
jmp set_DISP_quit
;
; 6文字目以降のチェック
; '0'~'9' | ';' …継続
; 'm' …属性変更
;
above_5th:
call is_numeric
jc chk_line
jmp put_buffer
chk_line:
call move_line
jc chk_m
jmp int29_ret0
chk_m:
cmp al,'m'
je set_attribute
jmp out_buffer
;
;
set_attribute:
mov si,offset buffer
mov di,offset attribute
mov bx,len
xor dx,dx
mov [si+bx],dx
inc si
inc si
mov byte ptr [di],dl
mov word ptr [di+1],7
cld
set_attr_loop1:
xor bx,bx
cmp [si],bl
jz set_attr_quit
set_attr_loop2:
lodsb
call is_numeric1
jc set_attr_0
sub al,'0'
shl bl,1
mov bh,bl
shl bl,2
add bl,bh
add bl,al
jmp set_attr_loop2
set_attr_0:
mov al,bl
cmp al,16
jb set_attr6
cmp al,40
jb set_attr1
cmp al,47
ja set_attr_loop1
or dl,08h ; Reverse
sub al,40
jmp short set_attr2_0
set_attr1:
cmp al,30
jae set_attr2
sub al,10h
mov bx,offset xcolor_tab2
jmp short set_attr2_1
set_attr2:
sub al,30
set_attr2_0:
mov bx,offset xcolor_tab
set_attr2_1:
cmp al,7
ja set_attr_loop1
xlat
mov dh,al
set_attr3:
jmp set_attr_loop1
set_attr6:
mov bx,offset xattr_tab
cmp al,8
ja set_attr8
xlat
or al,al
jz set_attr7
or dl,al
jmp set_attr_loop1
set_attr7:
xor dl,dl
set_attr8:
jmp set_attr_loop1
set_attr_quit:
mov flag_lo,bl
mov word ptr [di],dx
dec di
mov ah,11h
int 91h
jmp int29_ret0
;
; 行削除/行挿入シーケンス
;
move_line proc near
cmp al,'L'
je ins_line
cmp al,'M'
je del_line
stc
ret
ins_line:
mov byte ptr flag_lo,1
jmp short count_line
del_line:
mov byte ptr flag_lo,0
count_line:
mov si,offset buffer+2
mov cx,word ptr len
sub cx,2
xor bx,bx
jcxz check_zero1
count_line_loop:
lodsb
call is_numeric1
jnc count_line1
ret
count_line1:
sub al,'0'
shl bl,1
mov ah,bl
shl bl,2
add bl,ah
add bl,al
loop count_line_loop
check_zero:
or bl,bl
jnz check_zero2
check_zero1:
mov bl,1
check_zero2:
mov ah,0eh
int 91h
mov dl,1
mov cx,bx
mov bx,24*256+80
mov al,flag_lo
mov ah,1ah
int 91h
mov flag_lo,0
clc
ret
move_line endp
;
; パラメータのチェック
;
is_numeric proc near
cmp al,';'
je numeric_ok
is_numeric1:
cmp al,'0'
jb numeric_no
cmp al,'9'
ja numeric_no
numeric_ok:
clc
ret
numeric_no:
stc
ret
is_numeric endp
;
; グラフィックキャラクタのチェック
;
is_kanji proc near
cmp al,080h
jb kanji_no
cmp al,0a0h
jb kanji_yes
cmp al,0e0h
jb kanji_no
kanji_yes:
test flag_hi,GR_MODE
jz kanji_no
mov al,1bh
pushf
call dword ptr [int29]
kanji_no:
ret
is_kanji endp
;
; コントロールキャラクタの変換
;
is_ctrl proc near
cmp al,1ah
jne is_ctrl1
mov al,0ch
jmp short is_ctrl_ret
is_ctrl1:
test flag_hi,FM_MODE
jnz is_ctrl_ret
cmp al,0bh
jne is_ctrl2
mov al,1eh
jmp short is_ctrl_ret
is_ctrl2:
cmp al,0ch
jne is_ctrl3
mov al,1ch
jmp short is_ctrl_ret
is_ctrl3:
cmp al,1eh
jne is_ctrl_ret1
mov al,0bh
is_ctrl_ret:
mov [bp],ax
is_ctrl_ret1:
ret
is_ctrl endp
int29_end label byte
db 126 dup (?)
stack dw ?
int29_ofs dw ?
int29_seg dw ?
intff_ofs dw ?
intff_seg dw ?
save_ds dw ?
flag1 db 0
flag2 db 0
EXIST equ 1
REMOVE equ 10h
FM equ 20h
opening_msg db 'PC9801 ',1bh,'[32mESC ',1bh,'[msequence Simulater for FM16β/FMR - Version 0.15 - by tokusan 1989',CR,LF,LF,'$'
mcb_error_msg db 9,'MCB error!!',CR,LF,'$'
title_release db 'Release>>$'
release_error_msg1 db 2,7,'ESC98 is not resident!!',CR,LF,'$'
release_error_msg2 db 3,7,'Memory deallocation error!!',CR,LF,'$'
release_error_msg4 db 5,7,'INT29 vector is re-re-hooked ... can''t remove!!',CR,LF,'$'
release_msg db 0,'ESC98 is active ... Release.',CR,LF,'$'
release_msg2 db 0,'ESC98 is not active ... Release.',CR,LF,'$'
release_msg3 db 7,'INT29 vector is re-hooked. Sure?(Y/N) > $'
title_install db 'Install>>$'
install_error_msg1 db 0,'ESC98 is active ... Change mode.',CR,LF,'$'
install_error_msg2 db 0,'ESC98 is not active ... Reinstall.',CR,LF,'$'
install_msg db 0,'ESC98 is not resident ... Install.',CR,LF,'$'
install_mode_msg db 'Set ESC sequence mode to $'
nec_msg db 1bh,'[32mNEC',1bh,'[m',CR,LF,'$'
fm_msg db 1bh,'[32mFUJITSU',1bh,'[m',CR,LF,'$'
yes_msg db 1bh,'[32mYes',1bh,'[m',CR,LF,'$'
no_msg db 0,1bh,'[32mNo',1bh,'[m',CR,LF,'$'
usage db 1,7,'Usage : esc98 [f|r]',CR,LF
db '=========== ==============================',CR,LF
db ' nothing install or change mode or',CR,LF
db ' reinstall in NEC mode',CR,LF
db '----------- ------------------------------',CR,LF
db ' f install or change mode or',CR,LF
db ' reinstall in FUJITSU mode',CR,LF
db '----------- ------------------------------',CR,LF
db ' r remove memory-resident ESC98',CR,LF
db ' from memory',CR,LF
db '=========== ==============================',CR,LF,'$'
main:
cld
mov dx,offset opening_msg
call print
call chk_exist
check_param:
mov si,80h
lodsb
or al,al
jz install_program
call chk_param
test flag1,REMOVE
jz install_program
call release_program
quit:
mov bx,dx
inc dx
mov ah,09h
int DOS
mov al,[bx]
mov ah,4ch
int DOS
install_program:
mov dx,offset title_install
call print
mov dx,offset install_mode_msg
call print
mov dx,offset nec_msg
test flag1,FM
jz install0
mov dx,offset fm_msg
install0:
call print
test flag1,EXIST
jz stay_program
install_program1:
test flag1,ACTIVE
jnz change_mode
call reinstall
jmp quit
change_mode:
call change
jmp quit
stay_program:
mov di,80h
mov cx,64
push ds
pop es
xor ax,ax
rep stosw
test flag1,FM
jz stay1
mov flag_hi,FM_MODE
stay1:
les ax,dword ptr int29_ofs
mov word ptr int29,ax
mov word ptr int29+2,es
mov es,word ptr ds:[02ch]
mov ah,49h
int DOS
mov dx,offset install_msg
call print
mov dx,offset int29_entry
mov ax,2529h
int DOS
mov ax,offset stack
add ax,0fh
shr ax,4
mov dx,ax
mov ax,3100h
int DOS
stay_error:
mov dx,offset install_error_msg1
jmp quit
;
; 常駐しているESC98の削除及びメモリの解放
;
release_program proc near
mov dx,offset title_release
call print
test flag1,EXIST
jnz release1
mov dx,offset release_error_msg1
ret
release1:
mov es,save_ds
mov dx,offset release_msg2
test flag1,ACTIVE
jz release3
test flag1,RELEASE
jnz release2
call remove_rehooked
jz release3
ret
release2:
lds dx,es:[int29]
mov ax,2529h
int DOS
push cs
pop ds
mov dx,offset release_msg
release3:
mov ah,49h
int DOS
jc release_error2
ret
release_error2:
mov dx,offset release_error_msg2
ret
release_program endp
;
; ジャンプアドレスの書き換え
;
public remove_rehooked,found
remove_rehooked proc near
mov dx,offset release_msg3
call print
mov ah,7
int DOS
and al,0dfh
mov dx,offset no_msg
cmp al,'Y'
jne remove_rehooked_quit
mov dx,offset yes_msg
call print
mov es,save_ds
les ax,es:[int29]
mov intff_ofs,ax
mov intff_seg,es
mov bx,word ptr [int29_seg]
dec bx
mov es,bx
mov cx,es:[mcb_len]
mov dx,cx
shr dx,12
shl cx,4
inc bx
mov es,bx
mov bx,save_ds
mov ax,offset int29_entry
search_loop:
xor di,di
search_loop1:
repne scasb
jne search_next
cmp ah,es:[di]
jne search_loop1
cmp bx,es:[di+1]
jne search_loop1
dec di
mov si,offset intff_ofs
cli
movsw
movsw
sti
jmp short found
search_next:
dec dx
jns search_loop
mov dx,offset release_error_msg4
jmp short remove_rehooked_quit
found:
cmp al,al
mov es,save_ds
mov dx,offset release_msg
remove_rehooked_quit:
ret
remove_rehooked endp
;
; 常駐チェック
;
MCB_EXIST equ 1
ACTIVE equ 2
RELEASE equ 4
INT29_EQ_ESC98 equ 10h
INT29_EQ_PSP equ 20h
INT29_NE_SAVE equ 40h
;
public chk_exist
chk_exist proc near
mov ax,3529h
int DOS
mov int29_ofs,bx
mov int29_seg,es
mov save_ds,ds
mov ah,52h
int DOS
dec bx
dec bx
mov ax,es:[bx]
mov es,ax
mov bx,ds
check_search:
cmp byte ptr es:[mcb_id],'Z'
je check_exist_on
cmp byte ptr es:[mcb_id],'M'
jne check_error
mov dx,word ptr es:[psp_seg]
or dx,dx
jz check_next
cmp bx,dx ; 自分自身か?
je check_next ; 自分より後に常駐してるかも
cmp dx,int29_seg
jne check_search1
or flag2,INT29_EQ_PSP
check_search1:
mov es,dx
mov cx,offset int29_end - offset int29_entry
mov di,offset int29_entry
mov si,di
repe cmpsb ; キーワードのチェック
jne check_next
mov save_ds,es
or flag1,MCB_EXIST
test flag1,INT29_EQ_PSP
jnz check_exist_on1
check_next:
mov es,ax
add ax,word ptr es:[mcb_len]
inc ax
mov es,ax
jmp check_search
check_error:
mov dx,offset mcb_error_msg
jmp quit
check_exist_on:
test flag1,MCB_EXIST
jz check_not_exist
test flag2,INT29_EQ_PSP
jz check_not_exist
check_exist_on1:
mov es,save_ds
mov bx,int29_seg
cmp bx,word ptr es:[int29+2]
je check_not_exist
cmp bx,save_ds
jne check_exit_on2
or flag1,RELEASE
check_exit_on2:
or byte ptr es:[flag_hi],CHECK
xor ax,ax
int 29h
test byte ptr es:[flag_hi],CHECK
jnz check_not_exist
or flag1,ACTIVE
check_not_exist:
push ds
pop es
check_exist_exit:
ret
chk_exist endp
;
;
;
chk_param proc near
chk_param_loop:
call skip_space
cmp al,CR
je chk_param3
and al,0dfh
cmp al,'R'
jne chk_param1
or flag1,REMOVE
jmp short chk_param3
chk_param1:
cmp al,'F'
je chk_param2
chk_param_error:
mov dx,offset usage
jmp quit
chk_param2:
or flag1,FM
chk_param3:
ret
chk_param endp
;
;
;
reinstall proc near
mov es,save_ds
mov di,offset int29
mov si,offset int29_ofs
movsw
movsw
mov dx,offset int29_entry
push es
pop ds
mov ax,2529h
int DOS
push cs
pop ds
mov dx,offset install_error_msg2
jmp short change1
reinstall endp
;
; モード変更
;
change proc near
mov dx,offset install_error_msg1
change1:
mov es,save_ds
test flag1,FM
jnz set_FM_MODE
and es:flag_hi,not FM_MODE
jmp short change_mode_quit
set_FM_MODE:
or es:flag_hi,FM_MODE
change_mode_quit:
ret
change endp
;
;
;
print proc near
mov ah,9
int DOS
ret
print endp
skip_space proc near
lodsb
cmp al,' '
je skip_space
cmp al,09h
je skip_space
ret
skip_space endp
code ends
end start