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-08-12 19:46
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Source Code Explanation][Updated on 10-1-25] Full-color Maze - A truly colorful batch game View 2,771 Replies 15
Original Poster Posted 2010-01-15 22:53 ·  中国 河北 廊坊 联通
中级用户
★★
Credits 499
Posts 225
Joined 2008-12-30 22:09
17-year member
UID 135392
Gender Male
Status Offline
A color batch script based on a micro external command , the basic part has been basically completed! The entire code is controlled within 10KB.
This is the basic test version. More creative game modes will be added in the future. Everyone is welcome to provide opinions and suggestions!

New development: Developing a new external command to improve the development speed!
Complete a demo file using the new external command SYBN dll
http://www.cn-dos.net/forum/viewthread.php?tid=50188&fpage=1

-------------------------------------------------------------------------------------
This is a technical post, so there must be content. I will add and modify code explanations from time to time!
『Building 3』: Explanation: Color output of the sybc command
『Building 4』: Explanation: Keyboard input of sybc and DEBUG calling binary program
『Building 5』: Explanation: Map compression
『Building 6』: Explanation: Map verification
『Building 7』: Explanation: Random map generation
『Building 11』: Explanation: Reasons for incompatibility with 2K3
『Building 12』: Explanation: About DEBUD
......Wait for the future, add more explanations......
Other code explanations will be attached later. If you have any questions, please reply!
Recent development: Recently busy with final exams, and am preparing to separate the basic functions and make them into a library-like form. Then when writing other scripts, I can just insert it all at once and use it.
Another mood: I find that writing explanations is much easier than writing code. It may not be possible to squeeze out a few lines of code after thinking hard for hours. In the end, an optimization may make it even fewer lines - -! Writing code explanations is much easier, and it comes out in a few minutes!
Of course, my code first prioritizes reducing the size , and does not consider readability, so there are no comments at all. It may be more difficult to read. If you have questions, please reply. If there are no questions, please also reply to support, hehehe!

[ Last edited by sl543001 on 2010-2-5 at 16:29 ]
Recent Ratings for This Post ( 4 in total) Click for details
RaterScoreTime
moniuming +15 2010-01-16 21:42
netbenton +15 2010-01-18 23:09
ccwan +20 2010-01-21 18:10
zh159 +20 2010-01-29 15:58
Attachments
mgtm.rar (4.01 KiB, Downloads: 88)
mg.GIF
mgsy.GIF
mgtm.GIF
yzsb.GIF
Floor 2 Posted 2010-01-16 13:49 ·  中国 重庆 移动
初级用户
Credits 46
Posts 39
Joined 2008-11-02 22:24
17-year member
UID 129819
Gender Male
Status Offline
Not bad! It looks complicated, advanced commands.
Floor 3 Posted 2010-01-17 16:03 ·  中国 河北 廊坊 联通
中级用户
★★
Credits 499
Posts 225
Joined 2008-12-30 22:09
17-year member
UID 135392
Gender Male
Status Offline
sybc.com is only 240B in size, integrated in the script, generated when the script is executed. It originates from modifying the output of tit.com to produce colorful characters, relying on the 16-bit subsystem "command" and combining with the :bk subroutine based on the same command. It can achieve beautiful effects with less code:
Only the following code can achieve the "Figure 1" in the top post, the level selection screen.

::":bk" is used to draw colorful rectangles or lines, and draw some interesting shapes through custom styles
::Draw a vertical line, starting position 10008 , 25 lines, 1 column, color f1 , style 2
call :bk 10008 25 1 f1 2
::Draw a horizontal line, starting position 12000 , 1 line, 40 columns, color f1 , style 2
call :bk 12000 1 40 f1 2
::Draw graphics at the intersection of the two lines
sybc 11908f1╬
sybc 12006f1╬╬╬
sybc 12108f1╬
sybc 12108f1╬
::Display level selection information on the screen
sybc 10322f1%JBM% {20100115A Test Version}
sybc 10622f2Press up key $f0Previous level $f8
sybc 10722f2Press down key $f0Next level $f8
sybc 10822f2Press left key $f0Synchronize map $f8
sybc 10922f2Press right key $f0Modify verification $f8
sybc 11022f2Press enter key $f0Enable echo $f8
sybc 11222f2Spacebar $f0Random map game
sybc 11322f2Letter key $f0Built-in map game

==========================================
The parameter format of SYBC is as follows
sybc ...
5 digits, the first one is a placeholder digit, the size doesn't matter, , because the script may have errors with numbers starting with 0, so add a digit to make it a 5-digit number, avoid numbers starting with 0, and save the code of the script
the same as the parameter of color
the text to display, cannot contain the symbol "$", because it will be used later
use the symbol "$" to end the output of a colorful string, so that you can continue to write the next colorful string, so as to continuously output characters of multiple colors without calling sybc multiple times, save code and improve speed. The last end symbol can be omitted
Note: The parameter format of sybc in future versions may change!

[ Last edited by sl543001 on 2010-1-18 at 20:53 ]
Floor 4 Posted 2010-01-17 16:15 ·  中国 河北 廊坊 联通
中级用户
★★
Credits 499
Posts 225
Joined 2008-12-30 22:09
17-year member
UID 135392
Gender Male
Status Offline
The sybc command also integrates a keyboard input interception function similar to choice, but it does not support delay.
It supports 2 types of return values
Using the "sybc" command without parameters can obtain the keycode
Using the "sybn a" command can obtain the character internal code

Attach the debug code of sybc:
set a=A100;E8A 80 CD89 C581 81 F980 7F06 CD09 8016 1F9 687F 64EB 83BE E800 65 5AE3 73E8;3C00 7F18 8853 E8C6 57 4CE3 65E8 3C00 7F4F 8845 B0C2 F602 50E2 A0B0 E6F6 15F;E8C7 3D 32E3 C387 393C 27E 904 FB80 7E39 8003 9C3 F24 E380 C00F 4E0 D808;B850 B800 750 295A 89F5 EBE9 AC46 ACAC ACAC F7E2 4CB4 21CD FAEB E088 4CB4;21CD ACAC 203C 475 F9E2 9EB C388 3CAC 7520 E202 C3F9 C387 302C EB80 B430;F60A E4 C3D8 5953 4E42 DED0 C4B8 3032 3930 3231 3631 AC24 243C A74 88AA AAD0;F5E2 B4EB B2EB E349 49AF ACE3 B6E8 E3FF 87A7 3CC3 7E39 402 8009 39FB 37E;C380 2409 800F FE3 10B2 E2F6 D800 C288 C7E2 86EB
set b=;RCX;F0;N SYBC.COM;W;Q;
(ECHO.%a:;=&ECHO.DW %&ECHO.%b:;=&ECHO.%)|DEBUG

Using debug can add the binary program to the script, but at the cost of more than 2.5 times the file size
The following code has been specially optimized, and no more code-saving method has been found for the time being, which makes it inconvenient to integrate large binary programs in the script
In addition, the method of generating and then calling the binary program is used here.
For situations where it is not commonly used or it is inconvenient to generate files, etc., you can directly run "set b=;RCX;F0;G;Q;" without generating the file.
And this cannot add parameters, but you can also use "set b=A80;DB 03 00 54 30 01;RCX;F0;G;Q;"
=============================================
Note: SYBC.com is a 16-bit program synthesized by disassembling and modifying tit.com. It inherits some bugs and deficiencies of the original tit.com.
Although I have tried very hard to eliminate these bugs and deficiencies, the effect is limited so far, and I have to bypass them for the time being, but there is no exclusion that these bugs and deficiencies will act up again in the future!
The known bugs and deficiencies are reflected as follows:
1. Garbled code, in some cases, Chinese characters are partially garbled, which has no major impact.
2. No display, in some cases, the content that should be overwritten is not overwritten, which has no major impact.
3. Does not support Windows 2003. Due to compatibility issues, sybc does not support some operating systems, which is reflected as nothing is displayed, which has a greater impact, and no solution has been found for the time being!

[ Last edited by sl543001 on 2010-1-20 at 21:31 ]
Floor 5 Posted 2010-01-18 19:55 ·  中国 河北 廊坊 联通
中级用户
★★
Credits 499
Posts 225
Joined 2008-12-30 22:09
17-year member
UID 135392
Gender Male
Status Offline
A complete map needs to contain information for 21*40 grids. The format of each grid is roughly "f1■$", so the map size can be calculated as 21*40*5=4200B, approximately 4KB.

For scripts, execution efficiency is inversely proportional to file size. A script larger than 10kb with many jumps may be as slow as a snail.

Unfortunately, most game - related scripts basically contain a large number of jumps, so it is necessary to control the file size!

There are two aspects of solutions: first, optimize and compress the code; second, split into multiple files; both hands need to be抓, both hands need to be hard!

Since there is currently only one map, it is barely not necessary to split files, so we first compress the map code!

The compression algorithm is as follows:
===============================================
1. Replace each map grid with a letter. For example, "f1■$" is replaced with the letter D. To distinguish, we use the variable DKD to represent "f1■$", and directly use the letter D in the map.
Variables D K* are defined at the beginning of the script: DKA = F2∷$; DKB = F4·$; DKD = F1■$; DKE = F0¤$; DKQ = F0■$; DKV = F5∷$; DKW = F5:D$; DKX = F2☆$
In addition, in the game's map module or map file, the above definitions can be added or modified.
===============================================
2. Use the method of the script push - box http://www.cn-dos.net/forum/viewthread.php?tid=48603&fpage=1
Replace repeated plots with numbers. For example, replace "AAAAAAA" with "A7", which can immediately save a lot of map code.
===============================================
3. After the above two steps, the map file is reduced by 10 times but is still larger than 400B. A single map is naturally no problem, but considering that there may be many maps in the future, further code compression is needed.
To further reduce the code, continue to use unused letters in the map to replace repeated parts in different positions, and save the replacement list to an extra variable .
===============================================
Finally, the size of a single map is controlled within 300B, and it is completely possible to add several maps in the current script without greatly increasing the file size.
Of course, this is not the optimal method. Maybe a better method can be found to replace it in the future!
The final map format is as follows:
SET DTM1=AMHE8AHHMK8O5QEME5ADKOEN2PO2DE6MQON9PN3QN2QEJONHAOEN2O2N3PEJONO7A2PNON2QOEJONHAP2NDE8AEJ3N9PQNKEMOE4DKP3ONHEMOK4NOE5ANQO4EMHE4AN9IO2OEMK4ODE8AIE4AEME3AHAN3QOI6AM3P9IPIE4AEJODKOE3AOIOAOEJOKAQQPP4EJHE6AE5APE6JK6O7PE$ 
SET DTS1=DTBH=7;DTBL=29;DTMY=-AMDANEAOOOPO3QE9HNPIMPJ9AK

The map decompression code of the current version is as follows:

SET TC=ABCDEFGHIJKLMNOPQRSTUVWXYZ
SET DTMY=
SET /A TN=123456789,N=1,M=1,DTMYC=10,WZH=1,WZL=1
::::::::::::::::::::::::::::::::::::::::::::
::Insert or read map information into corresponding variables here, for example, insert the above code here
::::::::::::::::::::::::::::::::::::::::::::
SET A=!DTS%GS%:;=$!
SET %A:$=&SET %
FOR /L %%A IN (1,1,%DTMYC%) DO SET /A LSBL1=%%A*3-3 &&SET /A LSBL2=%%A*3-1 &&(FOR /F "TOKENS=1,2" %%B IN ("!LSBL1! !LSBL2!") DO IF NOT "%%C" == "" SET dtJ%%A=!DTMY:~%%B,2! && SET DTY%%A=!DTMY:~%%C,1!)
for /l %%A in (%DTMYC%,-1,1) do for /f "tokens=1,2" %%B in ("!DTY%%A! !DTJ%%A!") DO SET DTM%GS%=!DTM%GS%:%%B=%%C!
ECHO %DTM1% >DTM1.TXT
FOR /L %%A IN (0,1,999) DO (SET /A T=%%A+1
FOR %%B IN (!T!) DO (FOR /F "TOKENS=1-3 DELIMS=/" %%1 IN ("!DTM%GS%:~%%A,1!/!DTM%GS%:~%%B,1!/!N!") DO (
IF "!TC:%%1=!" NEQ "!TC!" (IF "!TN:%%2=!" NEQ "!TN!" (SET K=%%2) ELSE (SET K=1)
FOR /L %%K IN (1,1,!K!) DO SET DT!N!.!M!=!DK%%1!&&SET /A M+=1
) ELSE (IF "%%1" EQU "-" SET /A N+=1,M=1)&&IF "!TN:%%2=!" == "$" GOTO ZRDTW)))
: ZRDTW
SET DT%DTBH%.%DTBL%=%DKX%


[ Last edited by sl543001 on 2010-1-20 at 21:06 ]
Floor 6 Posted 2010-01-19 22:56 ·  中国 河北 廊坊 联通
中级用户
★★
Credits 499
Posts 225
Joined 2008-12-30 22:09
17-year member
UID 135392
Gender Male
Status Offline
In Screenshot 4, we see a verification failure prompt box, which also uses the self - recognized sybc+:BK combination. The code is as follows :
call :BK 10824 15 4 81 3
SYBC 10926CF×$85 Verification failed! $87
SYBC 1102680 Map unavailable, remaking map!

It is the prompt after the script fails the verification of the random map's availability, that is, it appears when there is no way to go forever.
Its algorithm is relatively crude. When encountering the situation on the left below, it will replace the map with the situation on the right, and repeat the cycle until it cannot be changed or the map exit is encountered.
■■■■■■■■■ ■■■■■■■■■ ■■■■■■■■■
■○∷∷∷∷∷∷■ ■○○∷∷∷∷∷■ ■○○○∷∷∷∷■
■∷■■■■■∷■ ■○■■■■■∷■ ■○■■■■■∷■
■∷■∷∷∷■∷■ ■∷■∷∷∷■∷■ ■○■∷∷∷■∷■
■∷■∷■■■∷■ ■∷■∷■■■∷■ ■∷■∷■■■∷■
■∷■∷∷∷∷∷■ ■∷■∷∷∷∷∷■ ■∷■∷∷∷∷∷■
■■■■■■■■■ ■■■■■■■■■ ■■■■■■■■■
It can be seen from the figure that we check whether there is ∷ around ○. If there is, we replace it with ○ (in the actual script, a dot · is used. For the sake of beauty, a circle ○ is used instead because of the forum font).
Starting from the first grid in the upper left, we check row by row until the final result in the lower right will be the following figure
■■■■■■■■■
■○○○○○○○■
■○■■■■■○■
■○■∷∷∷■○■
■○■∷■■■○■
■○■∷∷∷○○■
■■■■■■■■■
It can be seen from the figure that many squares will be omitted after one execution, so we need to check again.
In order to prevent extreme situations such as the left figure below, we cannot always check from the upper left to the lower right. Instead, we need to change directions continuously. In the script, 4 directions are used to check in turn.
■■■■■■■■■ ■■■■■■■■■ ■■■■■■■■■
■○■∷∷∷■∷■ ■○■∷∷∷■∷■ ■○■∷∷∷■∷■
■○■∷■∷■∷■ ■○■∷■∷■∷■ ■○■∷■∷■∷■
■○■∷■∷■∷■ ■○■∷■∷■∷■ ■○■○■∷■∷■
■○■∷■∷■∷■ ■○■○■∷■∷■ ■○■○■∷■∷■
■○○○■∷∷∷■ ■○○○■∷∷∷■ ■○○○■∷∷∷■
■■■■■■■■■ ■■■■■■■■■ ■■■■■■■■■

===================================
Attachment: Verification part of the code:
: YZDT
IF %YZMS% == %YzM2% GOTO OK
IF %YZMS% == %YzM1% IF %SJDT% == 0 GOTO OK
TITLE %JBM% Verification map
IF "%LSBLL%" == "180" GOTO NN
SET YZTG=NO
SET A=DT1.1=%DKB%;LSBLN=%LSBLM%;YZA5=^^^!YZA4^^^!;YZA4=^^^!YZA3^^^!;YZA3=^^^!YZA2^^^!;YZA2=^^^!YZA1^^^!;YZA1=^^^!YZA5^^^!;YZB5=^^^!YZB4^^^!;YZB4=^^^!YZB3^^^!;YZB3=^^^!YZB2^^^!;YZB2=^^^!YZB1^^^!;YZB1=^^^!YZB5^^^!
SET %A:;=&SET %
FOR /L %%A IN (%YZA2%) DO FOR /L %%B IN (%YZB2%) DO IF !DT%%A.%%B! == %DKB% (
SET /A YZH=%%A-1,YZL=%%B
FOR /F %%C IN ("^!DT!YZH!.!YZL!^!") DO SET B=%%C
IF !B! == %DKA% SET DT!YZH!.!YZL!=%DKB%&SET /A LSBLM+=1
IF !B! == %DKX% GOTO OK
SET /A YZH=%%A,YZL=%%B-1
FOR /F %%C IN ("^!DT!YZH!.!YZL!^!") DO SET B=%%C
IF !B! == %DKA% SET DT!YZH!.!YZL!=%DKB%&SET /A LSBLM+=1
IF !B! == %DKX% GOTO OK
SET /A YZL=%%B+1
FOR /F %%C IN ("^!DT!YZH!.!YZL!^!") DO SET B=%%C
IF !B! == %DKA% SET DT!YZH!.!YZL!=%DKB%&SET /A LSBLM+=1
IF !B! == %DKX% GOTO OK
SET /A YZH=%%A+1,YZL=%%B
FOR /F %%C IN ("^!DT!YZH!.!YZL!^!") DO SET B=%%C
IF !B! == %DKA% SET DT!YZH!.!YZL!=%DKB%&SET /A LSBLM+=1
IF !B! == %DKX% GOTO OK
)
SET /A LSBLL=LSBLL+1
IF "%LSBLM%" == "%LSBLN%" GOTO NN
GOTO YZDT
: OK
TITLE %JBM% Maze Exploration
SET /A WZH=1,WZL=1,YZTG=0
FOR /L %%A IN (1,1,20) DO FOR /L %%B IN (1,1,39) DO IF !DT%%A.%%B! == %DKB% SET DT%%A.%%B=%DKA%
goto :eof
: NN
CALL :XS
call :BK 10824 15 4 81 3
SYBC 10926CF×$85 Verification failed! $87
SYBC 1102680 Map unavailable, remaking map!
SET /A NANDU-=10,YZTG=1
IF %NANDU% LSS 10 SET NANDU=20
goto :eof


[ Last edited by sl543001 on 2010 - 1 - 19 at 23:41 ]
Floor 7 Posted 2010-01-20 20:41 ·  中国 河北 廊坊 联通
中级用户
★★
Credits 499
Posts 225
Joined 2008-12-30 22:09
17-year member
UID 135392
Gender Male
Status Offline
Without a large number of built-in maps, using random maps is the only way out!
The initially used random maps were completely irregular random layouts, and the final maps were very ugly.
Later, under the suggestion of classmate HEXIN., we switched to using a method of 1/4 permanent walls, 1/4 permanent spaces, and 1/2 random to generate relatively neat random maps.
==============================================
The current random map generation algorithm is still very crude, divided into 3 steps:
1. Make the map border, generate a graph similar to the following:
■■■■■■■■■■■
■∷∷∷∷∷∷∷∷∷■
■∷∷∷∷∷∷∷∷∷■
■∷∷∷∷∷∷∷∷∷■
■∷∷∷∷∷∷∷∷∷■
■∷∷∷∷∷∷∷∷∷■
■∷∷∷∷∷∷∷∷∷■
■∷∷∷∷∷∷∷∷∷■
■■■■■■■■■■■
2. Add ■ in even rows and even columns, generate a graph similar to the following:
■■■■■■■■■■■
■∷∷∷∷∷∷∷∷∷■
■∷■∷■∷■∷■∷■
■∷∷∷∷∷∷∷∷∷■
■∷■∷■∷■∷■∷■
■∷∷∷∷∷∷∷∷∷■
■∷■∷■∷■∷■∷■
■∷∷∷∷∷∷∷∷∷■
■■■■■■■■■■■
3. If it is an odd row, randomly generate ■ in even columns; if it is an even row, randomly generate ■ in odd columns
■■■■■■■■■■■
■∷○∷○∷○∷○∷■ ○ is the position of even columns in odd rows
■◎■◎■◎■◎■◎■ ◎ is the position of odd columns in even rows
■∷○∷○∷○∷○∷■
■◎■◎■◎■◎■◎■ Randomly generate ■ in the above positions repeatedly
■∷○∷○∷○∷○∷■ The number of randomness is controlled by variable NANDU
■◎■◎■◎■◎■◎■
■∷○∷○∷○∷○∷■
■■■■■■■■■■■
Add the randomly generated exit, and the finally generated map is similar to the following:
■■■■■■■■■■■
■∷∷∷■∷■∷∷∷■
■∷■■■∷■■■∷■
■∷∷∷■∷∷∷∷∷■
■■■∷■∷■∷■■■
■∷■∷∷∷■∷■∷■
■■■■■☆■∷■■■
■∷■∷∷∷■∷∷∷■
■■■■■■■■■■■
Then it is handed over to the map verification module upstairs for verification!
=========================
Attached is the part of the map generation code:
:SJ
SET /A SJDT=1,LSBL=1
FOR /L %%A IN (2,2,19) DO FOR /L %%B IN (2,2,38) DO SET DT%%A.%%B=%DKE%
: SJ1
SET /A LSBL+=1,sjh=%random%%%19+1,sjl=%random%%%19*2+2,sjhj=sjh/2,sjho=(sjh+1)/2
if %sjhj% == %sjho% set /a sjl-=1
SET DT%SJH%.%SJL%=%DKE%
IF %LSBL% LSS %NANDU% GOTO SJ1
: SJ2
SET /A sjh=%random%%%19+1,sjl=%random%%%19*2+2,A=(SJL+4)*(SJH+4)
IF %A% LSS 100 GOTO SJ2
SET A=DT1.2=%DKA%;DT2.1=%DKA%;DT2.3=%DKA%;DT3.2=%DKA%;DT4.3=%DKA%;DT3.4=%DKA%;DT%SJH%.%SJL%=%DKX%
SET %A:;=&SET %
GOTO :EOF


[ Last edited by sl543001 on 2010-1-20 at 21:16 ]
Floor 8 Posted 2010-01-21 17:33 ·  中国 广东 深圳 电信
新手上路
Credits 16
Posts 12
Joined 2010-01-19 17:37
16-year member
UID 159003
Gender Male
Status Offline
Top it's very powerful
Floor 9 Posted 2010-01-21 18:09 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 10 Posted 2010-01-22 10:31 ·  中国 福建 泉州 晋江市 电信
新手上路
Credits 10
Posts 7
Joined 2006-10-31 00:03
19-year member
UID 68926
Gender Male
Status Offline
Why is it incompatible with 2K3?
Floor 11 Posted 2010-01-23 18:10 ·  中国 河北 廊坊 联通
中级用户
★★
Credits 499
Posts 225
Joined 2008-12-30 22:09
17-year member
UID 135392
Gender Male
Status Offline
The COM program used for colorful output of scripts is a 16-bit DOS program. To run it under a non-DOS system, a simulation system is needed. Systems like Windows 98/2000/XP/2003... use command.exe to run 16-bit DOS programs. Starting from Windows 2000, the default shell is changed to the 32-bit cmd.exe, and from then on, the extension of the script is changed from bat to cmd. In Windows 2000/XP, once a 16-bit DOS program is used, the system will automatically switch from cmd.exe to command.exe and will not switch back automatically. While in Windows 2003, when a 16-bit DOS program is used, the system will automatically switch from cmd.exe to command.exe and then automatically switch back to cmd.exe.
==========================================
Why is that? Because command.exe does not support Chinese by default. Otherwise, why would we add chcp 437 graftabl 936 at the beginning of the script to force it to display in Chinese. Microsoft is phasing out 16-bit programs on purpose, and this is just the first step!
Of course, Microsoft has its reasons. It might say, "You see! The maximum width of your cmd window is at most 80, but after getting rid of 16-bit DOS programs, your cmd window can be stretched!"
Of course, the real reason behind it won't be told to you! It is recommended that everyone learn about the "WINter" alliance.

[ Last edited by sl543001 on 2010-1-23 at 18:17 ]
Floor 12 Posted 2010-01-25 19:30 ·  中国 河北 廊坊 联通
中级用户
★★
Credits 499
Posts 225
Joined 2008-12-30 22:09
17-year member
UID 135392
Gender Male
Status Offline
In the Windows series, DEBUG is a debugging tool for 16-bit subsystems, that is to say, it is only effective for the 16-bit subsystem . It seems that there is no connection between different cmd windows running DEBUG simultaneously. In this way, the great god DEBUG in the DOS era has limited uses in systems after 2000. However, we can still use it to make contributions.
===============================================
DUGUG's currently relatively commonly used function in scripts is to output com programs.
We use instructions such as a+db or a+dw or e to input assembly source code or hexadecimal code into DEBUG. Then use the W instruction to output the file, and then run the file. This process can create a "pseudo-single-file" script. Of course, changing W to G can skip the step of generating the file and create a "true single-file" script. In addition, DEBUG can also be used for simple hexadecimal editing and text modification.
Of course, there are still many ways waiting for us to explore!
===============================================
First, explain the DEBUG instructions such as a, dw, db, e
: The a instruction allows us to write assembly instructions to memory at a specified position
-----------------------------------------------
a 100
mov ah,4c
int 21

-----------------------------------------------
: a+db instruction to write single-byte hexadecimal data to memory
-----------------------------------------------
a 100
db b4 4c cd 21

-----------------------------------------------
: a+dw instruction to write double-byte hexadecimal data to memory
-----------------------------------------------
a 100
dw 4cb4 21cd

-----------------------------------------------
: e instruction to write single-byte hexadecimal data to memory
-----------------------------------------------
e 100 b4 4c cd 21
-----------------------------------------------
Note 1: The final effects of the above four examples are the same!
Note 2: There is an empty line at the end of the first three examples, which cannot be omitted.

Discovery: It seems that the e instruction is the most code-saving, and then a+dw. But if the code is relatively long, there seems to be a change. dw has a space every 4 hexadecimal numbers, while db and e have a space every 2 hexadecimal numbers. A little more code and db will exceed e! So the e is easy to use for less code and dw is more code-saving for more code.
===============================================
The above introduced input to memory, and then explain output to file N W R
N is to specify the final output file name, for example: sybc.com, note that the 8.3 rule is used, and in some cases it may be case-sensitive.
R CX is used to specify the file size, which is very important, note that write in hexadecimal in the next line
W is to save, no parameters are needed
: Save example
-----------------------------------------------
a 100
db b4 4c cd 21

r cx
4
n sybc.com
w

-----------------------------------------------
In addition, if you don't want to output the file and directly run, you need to use the G instruction
: G run
-----------------------------------------------
a 100
db b4 4c cd 21

r cx
4
g

-----------------------------------------------
===============================================
Other commonly used DEBUG instructions
F batch write repeated content
L read file to memory
You can go to the help document or Baidu to understand these things by yourself, and I won't introduce them in detail.
===============================================
Finally, how to get so many lines into the cmd? Just echo all and put them in parentheses and finally use the pipe symbol to get into DEBUG.
: Insert into cmd
-----------------------------------------------
(echo a 100&echo db b4 4c cd 21&echo.&echo r cx&echo 4&echo g&echo.)|DEBUG
-----------------------------------------------
In addition, there is an immature semi-finished product plan, which also has a good effect, that is, it must be placed at the beginning.
: Semi-finished product plan inserted into cmd
-----------------------------------------------
@echo off&color f2&title ...&goto begain
a 100
db b4 4c cd 21

r cx
4
g

:begain
debug <%0 >nul
-----------------------------------------------
===============================================
Final optimization: Some small tricks can further optimize the code
a 100 can be a100
e 100 can be e100
r cx can be rcx
That is, the space after instructions such as a, e, r can be saved, but only this
Spaces like db, dw cannot be saved.
Use preprocessing to simplify repeated code
For example:
(echo a 100&echo db b4 4c cd 21&echo.&echo r cx&echo 4&echo g&echo.)|DEBUG
Can be simplified to
set a=a 100;db b4 4c cd 21;;rcx;4; g;
(ECHO.%a:;=&ECHO. %)|debug
Of course, I believe everyone can find more and better ways to continue to optimize.

[ Last edited by sl543001 on 2010-1-25 at 19:32 ]
Floor 13 Posted 2010-01-28 14:29 ·  中国 广东 江门 电信
初级用户
★★
Credits 167
Posts 95
Joined 2007-05-06 09:19
19-year member
UID 87628
Gender Male
Status Offline
Floor 14 Posted 2010-01-29 13:05 ·  中国 广东 江门 电信
初级用户
★★
Credits 167
Posts 95
Joined 2007-05-06 09:19
19-year member
UID 87628
Gender Male
Status Offline
Let's give it a try~~~It looks really amazing, but my Windows 7 system can't play it~~~
Floor 15 Posted 2010-02-01 17:55 ·  中国 湖南 湘潭 电信
初级用户
Credits 23
Posts 19
Joined 2009-07-10 07:01
17-year member
UID 149125
Gender Male
Status Offline
Finally, I've seen what a master is.
Forum Jump: