![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-12 18:43 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » [Source Code Explanation][Updated on 10-1-25] Full-color Maze - A truly colorful batch game |
| Printable Version 2,769 / 15 |
| Floor1 sl543001 | Posted 2010-01-15 22:53 |
| 中级用户 Posts 225 Credits 499 | |
|
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 ] Attachments mgtm.rar (4.01 KiB) mg.GIF (13.51 KiB) mgsy.GIF (25.02 KiB) mgtm.GIF (23.05 KiB) yzsb.GIF (26.25 KiB) |
|
| Floor2 clamber | Posted 2010-01-16 13:49 |
| 初级用户 Posts 39 Credits 46 | |
|
Not bad! It looks complicated, advanced commands.
|
|
| Floor3 sl543001 | Posted 2010-01-17 16:03 |
| 中级用户 Posts 225 Credits 499 | |
|
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. ========================================== 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 ] |
|
| Floor4 sl543001 | Posted 2010-01-17 16:15 |
| 中级用户 Posts 225 Credits 499 | |
|
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: 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 ] |
|
| Floor5 sl543001 | Posted 2010-01-18 19:55 |
| 中级用户 Posts 225 Credits 499 | |
|
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: The map decompression code of the current version is as follows: [ Last edited by sl543001 on 2010-1-20 at 21:06 ] |
|
| Floor6 sl543001 | Posted 2010-01-19 22:56 |
| 中级用户 Posts 225 Credits 499 | |
|
In Screenshot 4, we see a verification failure prompt box, which also uses the self - recognized sybc+:BK combination. The code is as follows :
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: [ Last edited by sl543001 on 2010 - 1 - 19 at 23:41 ] |
|
| Floor7 sl543001 | Posted 2010-01-20 20:41 |
| 中级用户 Posts 225 Credits 499 | |
|
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: [ Last edited by sl543001 on 2010-1-20 at 21:16 ] |
|
| Floor8 cxchcq | Posted 2010-01-21 17:33 |
| 新手上路 Posts 12 Credits 16 | |
|
Top it's very powerful
|
|
| Floor9 ccwan | Posted 2010-01-21 18:09 |
| 金牌会员 Posts 1,160 Credits 2,725 From 河北廊坊 | |
| Floor10 Jays | Posted 2010-01-22 10:31 |
| 新手上路 Posts 7 Credits 10 | |
|
Why is it incompatible with 2K3?
|
|
| Floor11 sl543001 | Posted 2010-01-23 18:10 |
| 中级用户 Posts 225 Credits 499 | |
|
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 ] |
|
| Floor12 sl543001 | Posted 2010-01-25 19:30 |
| 中级用户 Posts 225 Credits 499 | |
|
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 ] |
|
| Floor13 ldr2zjj | Posted 2010-01-28 14:29 |
| 初级用户 Posts 95 Credits 167 | |
| Floor14 ldr2zjj | Posted 2010-01-29 13:05 |
| 初级用户 Posts 95 Credits 167 | |
|
Let's give it a try~~~It looks really amazing, but my Windows 7 system can't play it~~~
|
|
| Floor15 sysplay | Posted 2010-02-01 17:55 |
| 初级用户 Posts 19 Credits 23 | |
|
Finally, I've seen what a master is.
|
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |