China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-29 11:28
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » With everyone's effort, batch files can say goodbye to choice DigestI View 15,159 Replies 45
Original Poster Posted 2008-12-09 11:37 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Improved version is on the 26th floor:
Let's all improve it together!

@echo off
call inc 2>nul
if %errorlevel%==1 (
>inc.src echo ecs:100 B8 00 01 CD 16 B8 00 00 74 02 CD 16 B4 4C CD 21
>>inc.src echo rcx
>>inc.src echo 10
>>inc.src echo w
>>inc.src echo q
debug inc.com < inc.src 2>nul 1>nul
del inc.src
)
:loop
inc
if not %errorlevel%==0 (
echo %errorlevel%
if %errorlevel%==81 goto :eof ::q or Q exit
if %errorlevel%==113 goto :eof
)
ping -n 2 127.1>nul
goto loop


[ Last edited by wangff on 2008-12-11 at 10:34 ]
Recent Ratings for This Post ( 4 in total) Click for details
RaterScoreTime
Helloworld +1 2008-12-09 13:34
s11ss +11 2008-12-09 19:31
wxcute +4 2008-12-10 13:46
523066680 +15 2008-12-13 10:56
Floor 2 Posted 2008-12-09 16:09 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
@echo off
call inc 2>nul
if %errorlevel%==1 ( ::create inc if it doesn't exist
>inc.src echo ecs:100 A0 5D 00 3C 20 75 09 B4 01 CD 16 B8 00 00 74 02 CD 16 B4 4C CD 21
>>inc.src echo rcx
>>inc.src echo 16
>>inc.src echo w
>>inc.src echo q
debug inc.com < inc.src 2>nul 1>nul
del inc.src
)
set/p =input:<nul
inc i ::with a parameter (any) waits for one character of input, returned via errorlevel
echo %errorlevel%
:loop
inc ::without parameters checks whether a key has been pressed no:errorlevel=0 yes:errorlevel=key value can be used to detect keypresses dynamically while running
echo %errorlevel%
if not %errorlevel%==0 (
if %errorlevel%==81 goto :eof ::q or Q exit
if %errorlevel%==113 goto :eof
)
ping -n 2 127.1>nul
goto loop


[ Last edited by wangff on 2008-12-10 at 21:35
Floor 3 Posted 2008-12-09 19:33 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Brother wangff, could you explain how function 1 of int 16 is used?
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
xxi +2 2009-06-25 02:33
Floor 4 Posted 2008-12-09 20:58 ·  中国 福建 泉州 电信
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Keyboard Service (Keyboard Service—INT 16H)
Author: anonymous Source: collected and organized by China Self-Study Programming Net Release date: 2007-09-27

00H, 10H — read a character from the keyboard 03H — set repeat rate
01H, 11H — read keyboard status 04H — set keyboard click
02H, 12H — read keyboard flags 05H — push character and its scan code onto the stack
(1), Functions 00H and 10H
Function description: read a character from the keyboard
Input parameters: AH=00H——read keyboard
=10H——read extended keyboard, whether the extended keyboard is valid can be judged from the contents of memory location 0000:0496H
Output parameters: AH=keyboard scan code
AL=character ASCII code
(2), Functions 01H and 11H
Function description: read keyboard status
Input parameters: AH=01H——check standard keyboard
=11H——check extended keyboard
Output parameters: ZF=1——no character input, otherwise, AH=keyboard scan code, AL=ASCII code.
(3), Functions 02H and 12H
Function description: read keyboard flags
Input parameters: AH=02H——shift flags of the standard keyboard
=12H——shift flags of the extended keyboard
Output parameters: AL=keyboard flags (valid for both 02H and 12H), when each bit has the value 1, the meanings are as follows: bit 7—INS on state bit 3—ALT key pressed
bit 6—CAPS LOCK on state bit 2—CTRL key pressed
bit 5—NUM LOCK on state bit 1—left SHIFT key pressed
bit 4—SCROLL LOCK on state bit 0—right SHIFT key pressed
AH=extended keyboard flags (valid for 12H), when each bit has the value 1, the meanings are as follows:
bit 7—SysReq key pressed bit 3—right ALT key pressed
bit 6—CAPS LOCK key pressed bit 2—right CTRL key pressed
bit 5—NUM LOCK key pressed bit 1—left ALT key pressed
bit 4—SCROLL key pressed bit 0—left CTRL key pressed
(4), Function 03H
Function description: set repeat rate
Input parameters: AH=03H For PC/AT and PS/2: AL=05H
BH=repeat delay
BL=repeat rate
For PCjr: AL=00H——load default rate and delay
=01H——increase initial delay
=02H——halve the repeat frequency
=03H——increase delay and halve the repeat frequency
=04H——turn off keyboard repeat function
Output parameters: none
(5), Function 04H
Function description: set keyboard click
Input parameters: AH=04H AL=00H——turn off keyboard click function
=01H——turn on keyboard click function
Output parameters: none
(6), Function 05H
Function description: push character and its scan code onto the stack
Input parameters: AH=05H
CH=character description code
CL=character ASCII code
Output parameters: CF=1——operation successful, AL=00H, otherwise, AL=01H
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
HAT +4 2008-12-09 21:04
s11ss +3 2008-12-09 21:05
Floor 5 Posted 2008-12-09 21:04 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Sorry, this doesn't count as an explanation, does it? At least give one or two examples to illustrate it :)
Floor 6 Posted 2008-12-09 21:28 ·  中国 福建 泉州 电信
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
(2), Function 01H
Function description: read keyboard status
Input parameters: AH=01H——check standard keyboard
Output parameters: ZF=1——no character input, otherwise, AH=keyboard scan code, AL=ASCII code.

mov     ah,1     ;check whether a key is pressed
int 16h
mov ax,0 ;ah=0 read key, clear al
jz ret ;zf=1 no key pressed, return 0
int 16h ;if a key is pressed, the read ASCII is in al

ret:
mov ah,4ch ;return al to errorleve
int 21h


Not sure whether I made it clear? I type very slowly, please forgive me.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
s11ss +3 2008-12-09 22:04
Floor 7 Posted 2008-12-09 22:03 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
mov ah,0
int 16

Aren't the two lines above just reading input? Then what is function 1 for?
Floor 8 Posted 2008-12-09 22:15 ·  中国 福建 泉州 电信
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Originally posted by s11ss at 2008-12-9 22:03:
mov ah,0
int 16

Aren't the two lines above just reading input? Then what is function 1 for?



ah=0: waits for input ah=1: only checks, does not read (it remains in the keyboard buffer), if there is input you still have to use ah=0 to read it out

[ Last edited by wangff on 2008-12-9 at 22:17 ]
Floor 9 Posted 2008-12-09 22:20 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by wangff at 2008-12-9 10:15 PM:



ah=0: waits for input ah=1: only checks, does not read (it remains in the keyboard buffer), if there is input you still have to use ah=0 to read it out

[ Last edited by wangff on 2008-12-9 at 22:17 ]




C:\>debug
-a
0B22:0100 mov ah,0
0B22:0102 int 16
0B22:0104
-t

AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B22 ES=0B22 SS=0B22 CS=0B22 IP=0102 NV UP EI PL NZ NA PO NC
0B22:0102 CD16 INT 16
-p
(the input here is a)
AX=1E61 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0B22 ES=0B22 SS=0B22 CS=0B22 IP=0104 NV UP EI PL NZ NA PO NC
0B22:0104 381C CMP ,BL DS:0000=CD
-

I still think using function 0 is enough

[ Last edited by s11ss on 2008-12-9 at 22:22 ]
Floor 10 Posted 2008-12-09 22:36 ·  中国 福建 泉州 电信
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
The example on the 2nd floor:
inc i ::with a parameter (any parameter), wait for one character of input and return it through errorlevel

uses only ah=0

But:
inc ::without parameters, detect whether there is a keypress; none:errorlevel=0, if yes then errorlevel=key value, can be used to dynamically detect keypresses while running

then ah=1 must be used
Floor 11 Posted 2008-12-09 22:48 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Originally posted by wangff at 2008-12-9 10:36 PM:
The example on the 2nd floor:
inc i ::with a parameter (any parameter), wait for one character of input and return it through errorlevel

uses only ah=0

But:
inc ::without parameters, detect whether there is a keypress; none:errorlevel=0, if yes then errorlevel=key value, can be used to dynamically detect keypresses while running

then ah=1 must be used


By no keypress, do you mean directly pressing Enter? If only function 0 is used, then al is 0d
Floor 12 Posted 2008-12-09 23:02 ·  中国 福建 泉州 电信
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
@echo off

:loop
for /f "tokens=*" %%a in ('ping -n 1 127.1 ^| findstr /i "Request Reply"') do echo.%%a
inc ::without parameters, detect whether there is a keypress; none:errorlevel=0, if yes then errorlevel=key value, can be used to dynamically detect keypresses while running
if not %errorlevel%==0 (
if %errorlevel%==112 pause ::input p or P pause
if %errorlevel%==90 pause
if %errorlevel%==81 goto :eof ::input q or Q exit
if %errorlevel%==113 goto :eof
)
ping -n 2 127.1>nul
goto loop



This example shows it: using only ah=0 cannot achieve this effect

[ Last edited by wangff on 2008-12-9 at 23:06 ]
Floor 13 Posted 2008-12-09 23:30 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
I'll take my time to understand it, much obliged, brother wangff
Floor 14 Posted 2008-12-09 23:59 ·  中国 北京 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
In ecs:100 A0 5D 00 3C 20 75 09 B4 01 CD 16 B8 00 00 74 02 CD 16 B4 4C CD 21 CD 21 CD 21 on the 2nd floor, why are there 3 int 21s?
Floor 15 Posted 2008-12-10 08:22 ·  中国 福建 泉州 移动
初级用户
★★
Credits 134
Posts 54
Joined 2008-11-19 11:47
17-year member
UID 131429
Gender Male
Status Offline
Originally posted by s11ss at 2008-12-9 23:59:
In ecs:100 A0 5D 00 3C 20 75 09 B4 01 CD 16 B8 00 00 74 02 CD 16 B4 4C CD 21 CD 21 CD 21 on the 2nd floor, why are there 3 int 21s?


Thanks to s11ss for being so careful. They were extra bytes copied from debug. Because of the 16h length limit they weren't saved into inc.com, so they didn't affect usage. I've corrected it.
Forum Jump: