| 
 | 
!BAT by sratlf 0416 
clear 
if not exist debug set debug=off 
debug %debug% 
terminal console 
checkrange 20110128:-1 read 0x8278 || clear && pause Need grub4dos-0.4.5b-2011-01-28 or above. && exit 1 
delmod -l %~nx0 || insmod %~0 
if not exist runs set runs=%~nx0 
if not exist usrpath set usrpath=(bd)/BOOT/IMGS/ 
calc *0x8280&0xff-0x21 || pxe keep 
calc *0x8280&0xff-0x23 || set bd=(ud) && goto :fbinst 
calc *0x8280&0xff-0x80 || set bd=(hd) && goto :hddzip 
if not exist bd && set /A bd=*0x8280&0xff 
if not %bd:~,1%==( && set bd=(%bd%) 
 
:start 
if "%~1"=="" goto :input 
set m=%~1 && set /a lenm=*0x4cb00 
if %m:~,2%==-- && goto :c%lenm% || goto :other 
if "%~x1"=="" goto :chain || goto :%~x1 || goto :err 
 
:fbinst 
calc *0x82b9&0xff-0x80 || set hdd=1 && goto :hdd 
calc *0x82b9&0xff || goto :zip 
:hddzip 
calc *0x82a0&0xff-0x80 || set hdd=1 && goto :hdd 
calc *0x82a0&0xff || goto :zip 
:hdd 
set /A hd1=*0x8280&0xff 
set /A hd2=*0x8208>>16&0xffff 
set bd=(%hd1%,%hd2%) 
set hd1= && set hd2= 
goto :start 
:zip 
map (0) (hd) 
map --hook 
goto :start 
 
:c4 
if /i %~1==--pe goto :pe 
if /i %~1==--nt goto :nt 
goto :err 
:c5 
if /i %~1==--mem goto :mem 
if /i %~1==--top goto :top 
if /i %~1==--lst goto :lstfile 
goto :err 
:c6 
if /i %~1==--swap goto :swap 
if /i %~1==--fira goto :firadisk 
if /i %~1==--wvbk goto :winvblock 
if /i %~1==--help goto :help 
goto :err 
:c7 
if /i %~1==--nomem goto :nomem 
if /i %~1==--ramos goto :ramos 
goto :err 
:c8 
if /i %~1==--noswap goto :noswap 
goto :err 
:c10 
if /i %~1==--automenu goto :automenu 
goto :err 
:c13 
if /i %~1==--fira-nodisk goto :firadisk 
if /i %~1==--wvbk-nodisk goto :winvblock 
goto :err 
:other 
if /i %m:~,6%==--fira goto :firadisk 
if /i %m:~,6%==--wvbk goto :winvblock 
:err 
echo -e \n Command error, or File not found: $[0004]%~1 
:help 
echo -e \n RUN Usage: 
echo -e \n RUN file.iso$[0003]|$[0007].img$[0003]|$[0007].ima$[0003]|$[0007].gz$[0003]|$[0007].bin$[0003]|$[0007].lst$[0003]|$[0007].0pe$[0003]|$[0007].usr 
echo -e \n RUN $[0005]--automenu $[0007][/path/] 
echo -e \n RUN $[0005]--pe$[0003]|$[0005]--nt$[0003]|$[0005]--lst $[0007]/file.* 
echo -e \n RUN $[0005]--swap$[0003]|$[0005]--mem$[0003]|$[0005]--nomem $[0007]etc. 
echo -e \n RUN $[0005]--ramos $[0007]/hdd.* [/ldrfile] 
echo -e \n RUN $[0005]--fira$[0003]|$[0005]--wvbk$[0007][$[0002]-nodisk$[0007]][:/img.*] [$[0002]fd1$[0007][:/img.*]] [$[0002]iso=$[0007]/file.iso$[0003]|$[0002]disk=$[0007]/hdd.*] 
goto :input 
exit 
 
:find 
if "%~1"=="%~nx1" && set path=%usrpath% ! set path=%~p1 
if %path:~,1%==( && call :_find %path%%%~nx1 ! call :_find %bd%%%path%%%~nx1 
goto :eof 
:_find 
set loadpath=%~pnx1 
call :chdis 
echo -e \n $[0004]Loading $[0101]%root%$[0003]%~p1$[0002]%~nx1$[0007]... 
if exist %~pnx1 set loadfile=%root%%%~pnx1 && goto :eof 
rootnoverify %~d1 && if exist %~pnx1 && goto :find 
if exist bd && rootnoverify %bd% 
if not exist %~pnx1 && find --set-root --ignore-floppies %~pnx1 || find --set-root --devices=f %~pnx1 || goto :err 
goto :find 
 
:chdis 
debug 1 
find --set-root | set root= 
debug %debug% 
goto :eof 
 
:kernel 
kernel %loadfile% 
boot 
exit 
 
:.img 
:.ima 
:.gz 
:imgfile 
set mem=--mem 
if %memset%==1 && set mem=--mem ! if %memset%==0 && set mem= 
call :find %~1 
cat --locate=\xEB --length=4 --number=1 %loadfile% || goto :kernel 
map %mem% %loadfile% (fd0) 
map --hook 
if "%~2"=="" && goto :_img 
shift 
if /i "%~1"=="--dts-ext" && call :dtsext %* 
if /i "%~1"=="--max-ext" && call :maxext %* 
:_img 
rootnoverify (fd0) 
if not exist (0)/menu.lst chainloader (0)+1 || configfile (0)/menu.lst 
boot || echo -n 
exit 
 
:dtsext 
shift 
write --offset=120 (fd0)/config.sys %~1,0 
write --offset=370 (fd0)/config.sys %~2,0 
write --offset=232 (fd0)/autoexec.bat %~3 %~4 %~5 %~6 %~7 %~8 %~9 
goto :eof 
 
:maxext 
shift 
if not exist (0)/CONFIG.SYS exit 
if not exist (0)/AUTOEXEC.BAT exit 
cat --locate="default=" --replace="default=1,0" --number=1 (0)/CONFIG.SYS 
cat --locate="call" --replace="Call" (0)/AUTOEXEC.BAT 
cat --locate="CALL" --replace="Call" (0)/AUTOEXEC.BAT 
cat --locate="m.bat" --replace="M.BAT" (0)/AUTOEXEC.BAT 
cat --locate="M.bat" --replace="M.BAT" (0)/AUTOEXEC.BAT 
cat --locate="m.BAT" --replace="M.BAT" (0)/AUTOEXEC.BAT 
debug 1 
cat --locate="Call M.BAT" --number=1 (0)/AUTOEXEC.BAT | set offset= 
debug %debug% 
write --offset=0x%offset% (0)/AUTOEXEC.BAT %* \r M.BAT \r 
goto :eof 
 
:.iso 
:isofile 
set mem1=--mem 
if %memset%==1 && set mem=--mem ! if %memset%==0 && set mem1= 
call :find %~1 
map %mem% %loadfile% (0xff) || map %mem1% %loadfile% (0xff) 
map --hook 
chainloader (0xff) 
boot 
exit 
 
:.0 
:.bin 
:.sys 
:chain 
calc *0x8280&0xff-0x21 || chainloader --force --raw (pd)%~pnx2 && boot && exit 1 
if not %swap%==1 if %hdd%==1 set con=1 && call :swap 
call :find %~1 
cat --locate=\xEB --length=4 --number=1 %loadfile% || goto :kernel 
chainloader %loadfile% || chainloader --force %loadfile% 
boot 
exit 
 
:pe 
shift 
call :find %~1 
map --in-place ()+1 (hd0) 
map --hook 
chainloader --force %loadfile% 
boot 
exit 
 
:nt 
shift 
call :find %~1 
checkrange 0x21 read 0x8280 && chainloader --force --raw (pd)%loadpath% && boot && exit 
if not %hdd%==1 && goto :_nt 
map () (hd0) 
map (hd0) () 
map --rehook 
call :find %loadfile% 
:_nt 
chainloader %loadfile% || chainloader --force %loadfile% 
dd if=()+1 of=(md)0x3E+1 
boot 
exit 
 
:lstfile 
shift 
:.lst 
:.0pe 
:.usr 
:.diy 
call :find %~1 
if /i %~nx1==menu.0pe && call :0pe %2 %3 
configfile %loadfile% 
exit 
 
:0pe 
if #%1==# exit || calc %~1 && write 0x60300 0x60300 && write 0x60100 %~1 
if /i not "%~x2"==".iso" exit 
if "%~2"=="%~nx2" set /u tmp=%usrpath%%%~nx2 || set /u tmp=%~pnx2 
write (md)0x301+1 %tmp% 
set tmp=%tmp% 
set /a tmp=*0x4CB00 
write 0x60360 %tmp% 
set tmp= 
exit 
 
:ramos 
shift 
call :find %~1 
set mem=--mem 
if %memset%==1 && set mem=--mem ! if %memset%==0 && set mem= 
if %topset%==1 && set top=--top ! set top= 
map %mem% %top% %loadfile% (hd) 
map --hook 
map (hd-1) (hd0) 
map (hd0) (hd-1) 
map --rehook 
if not "%~2"=="" && goto :_ramos 
rootnoverify (hd0) 
chainloader +1 
boot 
exit 
:_ramos 
rootnoverify (hd0,0) 
chainloader %~2 
boot 
exit 
 
:mem 
set memset=1 
goto :next 
 
:nomem 
set memset=0 
goto :next 
 
:top 
set topset=1 
goto :next 
 
:noswap 
set swap=1 
goto :next 
 
:next 
shift 
goto :start 
 
:swap 
if not %hdd%==1 && echo -e \n You are not booting from HDD, no need for swapping the HDD. 
if /i %~1==--swap && goto :movebegin 
if %swap%==1 && echo -e \n You have already swapped the HDD. && goto :next 
echo -e \n Press $[0004]"S" $[0007]in $[0004]5 $[0007]seconds to swap HDD (if only you are booting from USB-HDD) 
echo -e \n OR press any other key to $[0004]continue, nothing to do.\n 
checkrange 0x73,0x53 pause --wait=5 || goto :moveend 
:movebegin 
set /a hd=*0x475&0xff+0x7f 
checkrange 0x7f calc %hd% && goto :next 
set /a hdm=%hd%+1 
map (hd0) (%hdm%) 
map --hook 
:move 
set /a hd1=%hd%+1 
map (%hd1%) (%hd%) 
set /a hd=%hd%-1 
checkrange 0x7f calc %hd% || goto :move 
map --unmap=%hdm% 
map --rehook 
::rootnoverify (hd0,0) 
echo -e \n Success for swapping the HDD 
:moveend 
set swap=1 
if %con%==1 && set con= && goto :eof 
set con= 
goto :next 
 
:input 
echo -e \n Please input the command, use $[0005]--help $[0007]or "$[0104]H$[0007]" for RUN usage. 
echo -e \n OR press Enter to use $[0005]--fira $[0002]iso=/WIN$.ISO$[0007] as default. 
echo -e \n You can also Input "$[0104]M$[0007]" to $[0003]Main Menu $[0007]or "$[0104]C$[0007]" To $[0003]Commandline. 
set path= 
set /p path=>Input Command: 
if not exist menu && set menu=(md)4+8 
if /i %path%==m && configfile %menu% 
if /i %path%==c && commandline 
if /i %path%==h && goto :help 
if not exist path && echo -e \n Use $[0005]--fira $[0002]iso=/WIN$.ISO$[0007] as default. && set path=--fira iso=/WIN$.ISO 
call :start %path% 
exit 
 
:firadisk 
set dflag=fira 
goto :floppy 
 
:winvblock 
set dflag=wvbk 
goto :floppy 
 
:floppy 
if /i %m:~7,6%==nodisk && set nodisk=1 
if %nodisk%==1 && set fd0path=%m:~14% ! set fd0path=%m:~7% 
if not exist fd0path && if %dflag%==fira set fd0path=FIRADISK.IMG || if %dflag%==wvbk set fd0path=WINVBLOCK.IMG 
set tmp=%~2 
if /i %tmp:~,3%==fd1 || goto :choise 
set fd1path=%tmp:~4% 
if "%fd1path%"=="" && set fd1path=/IASTOR.IMG 
shift 
:choise 
if /i %~2==disk set noiso=1 && goto :loaddisk 
set mem1=--mem 
if %memset%==1 && set mem=--mem ! if %memset%==0 && set mem1= 
if exist fd1path && goto :loadfloppy1 
call :find %fd0path% 
if %dflag%==fira && set floppy1=floppy,vmem=find:%loadpath%; 
map %mem% %loadfile% (fd1) || map %mem1% %loadfile% (fd1) 
map --mem (md)+2880 (fd0) 
map --hook 
dd if=(fd1) of=(fd0) count=1 
goto :load_choise 
:loadfloppy1 
call :find %fd1path% 
if %dflag%==fira && set floppy1=floppy,vmem=find:%loadpath%; 
map %mem% %loadfile% (fd1) || map %mem1% %loadfile% (fd1) 
call :find %fd0path% 
if %dflag%==fira && set floppy0=floppy,vmem=find:%loadpath%; 
map %mem% %loadfile% (fd0) || map %mem1% %loadfile% (fd0) 
map --hook 
:load_choise 
if /i %~2==disk set noiso=1 && goto :loaddisk 
if /i not %~2==iso && goto :next 
shift 
if %dflag%==fira && map --heads=2 --sectors-per-track=18 --mem (md)0x800+4 (99) 
call :find %~2 
if %dflag%==fira && set cdrom=cdrom,vmem=find:%loadpath%; 
map %mem% %loadfile% (0xff) || map %mem1% %loadfile% (0xff) 
map --hook 
shift 
if /i %~2==disk && goto :loaddisk 
if %nodisk%==1 && goto :iso_step1 
call :cd_or_hdd 
checkrange 0x69,0x49 pause --wait=10 && goto :iso_step1 
goto :iso_step2 
 
:iso_step1 
if %dflag%==fira && write (99) [FiraDisk]\nStartOptions=%cdrom%%%floppy1%%%floppy0%\n\0 
if not %nodisk%==1 if not %swap%==1 if %hdd%==1 set con=1 && call :swap 
chainloader (0xff) 
boot 
exit 
 
:iso_step2 
if %dflag%==fira && write (99) [FiraDisk]\nStartOptions=%cdrom%\n\0 
find --set-root --devices=h /WIN_NT$.~BT/SETUPLDR.BIN && chainloader ()/WIN_NT$.~BT/SETUPLDR.BIN && boot && exit 
find --set-root --devices=h /NTLDR if exist /NTDETECT.COM || echo -e \x20System installation failed, press any key to back && pause && exit 
chainloader /NTLDR 
boot 
exit 
 
:loaddisk 
shift 
if %dflag%==fira && map --heads=2 --sectors-per-track=18 --mem (md)0x800+4 (99) 
if %dflag%==wvbk && map --rd-size=2048 && map --mem (rd)+4 (0x55) 
call :find %~2 
if %dflag%==fira && set disk=disk,vmem=find:%loadpath%; 
if %memset%==1 && set mem=--mem ! set mem= 
map --heads=255 --sectors-per-track=63 %mem% %loadfile% (hd) 
map --hook 
map (hd-1) (hd0) 
map (hd0) (hd-1) 
map --rehook 
if %noiso%==1 && goto :disk_step2 
call :cd_or_hdd 
checkrange 0x69,0x49 pause --wait=10 && goto :disk_step1 
goto :disk_step2 
 
:disk_step1 
if %dflag%==fira && write (99) [FiraDisk]\nStartOptions=%disk%%%cdrom%%%floppy1%%%floppy0%\n\0 
if %dflag%==wvbk && write (0x55) #GRUB4DOS\x00v=1\x00%loadpath:~1%\x00\x80\x00 
chainloader (0xff) 
boot 
exit 
 
:disk_step2 
if %dflag%==fira && write (99) [FiraDisk]\nStartOptions=%disk%%%cdrom%\n\0 
if %dflag%==wvbk && write (0x55) #GRUB4DOS\x00v=1\x00%loadpath:~1%\x00\x80\x00 
rootnoverify (hd0) 
chainloader +1 
boot 
exit 
 
:cd_or_hdd 
echo -e \n Press $[0004]"I" $[0007]in $[0004]10 $[0007]seconds to boot from ISO 
echo -e \n OR press any other key to $[0004]continue System Installation$[0007] (boot from harddisk).\n 
goto :eof 
 
:automenu 
shift 
set i=1001 
if "%~1"=="" && set path=/BOOT/IMGS/ ! rootnoverify %~d1 && set path=%~p1 
find --set-root --ignore-floppies ls %path% clear || find --set-root --devices=f ls %path% clear || goto :err 
call :chdis 
if not exist font if not exist image && set image=color white/blue blue/yellow light-red/blue 10 
echo -e %font%\n%image%\ndefault 1\ntimeout 10 > (md)0x3000+0x10 
echo -e \ntitle                             Automenu for %root%%%path% \\n \nclear\n >> (md)0x3000+0x10 
ls %path% | call :makemenu %0 || echo -n 
if not exist menu set menu=(md)4+8 
echo -e title [%i:~-2%] Back to Main Menu \\n configfile %menu%\nconfigfile %menu%\n >> (md)0x3000+0x10 
set i= 
set tmp= 
configfile (md)0x3000+0x10 
exit 
 
:makemenu 
shift 
if #%1==# exit 
set tmp=%~n1 
if /i not #%~x1==#.TXT if not #%~x1==# if not "%tmp:~-2,1%"=="~" if /i not "%~n1"=="firadisk" if /i not "%~n1"=="winvblock" || goto :makemenu 
if exist %path%%%~n1.TXT && set file=%path%%%~n1.TXT && call :read_txt %file% 
if not exist title set title=%~nx1 
if not %next1:~,2%==-- && set next1= ! if "%next1%"=="%front1%" && set next1= 
if not %front1:~,2%==-- && set front1= ! if "%front1%"=="%title%" && set front1= 
echo -n title [%i:~-2%] RUN %title% \n %~nx1 >> (md)0x3000+0x10 
if not exist front1 if not exist next1 && set front1=%front% && set next1=%next% 
echo -e \n%runs% %front1% %path%%%~1 %next1%\nboot\n >> (md)0x3000+0x10 
set title= && set front1= && set next1= 
set /a i=%i%+1 
goto :makemenu 
exit 
 
:read_txt 
call :read_line %file% title=1  
call :read_line %file% front1=2  
call :read_line %file% next1=3  
goto :eof 
 
:read_line 
set _start=0 
set _end=0 
cat --locate=\xA --number=%3 %1 | call :get_last_line 
set /a _end=%_end%-%_start% 
cat --skip=%_start% --length=%_end% %1 | set %2=  
set _start= 
set _end= 
goto :eof 
 
:get_last_line 
if "%1"=="" exit 
if "%2"=="" && set /a _end=0x%1 ! if "%3"=="" && set /a _start=0x%1+1 
shift 
goto :get_last_line |   
 
 
 
 |