Jump to content











Photo
* * * * * 1 votes

chenall grub4dos undocumented features

grub4dos commands syntax

  • Please log in to reply
19 replies to this topic

#1 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 15 May 2013 - 03:13 PM

*
POPULAR

I thought I might start a thread about features not officially documented.

 

Here is one, did you know that grub4dos can prompt for a string with a timeout...

 

set name=
set /p:3 name=Please enter your name within 3 seconds : 
if "%name%"=="" pause --wait=2 Sorry - not quick enough && halt
echo Well done %name%!

I think this has been in the chenall build for quite a while (I have not checked older builds).


  • ilko, saddlejib and Holmes.Sherlock like this

#2 Holmes.Sherlock

Holmes.Sherlock

    Gold Member

  • Team Reboot
  • 1444 posts
  • Location:Santa Barbara, California
  •  
    United States

Posted 17 May 2013 - 02:23 PM

How did you discover it? Code walkthrough?



#3 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 17 May 2013 - 02:26 PM

yes



#4 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 16 October 2013 - 11:20 AM

You may be familiar with the && and || operators, but are you aware of the ! operator

 

The difference between the || and ! operators
 
|| acts on the first test in a compound commandline whereas ! is only relevant for the last test
if %e%>=10 if %e%<=90 && echo fred  ! echo doris             Nothing is displayed
set e=9! must be used after && or ||  (see chenall's explanation below)
 
Think of || adding parentheses like this:
if %e%>=10 if %e%<=90 && echo fred  || echo doris            'doris' is displayed

and ! adding parentheses around just the last test like this:if %e%>=10 (if %e%<=90 echo fred)  || echo doris

 if %e%>=10 if %e%<=90 (echo fred  ! echo doris)



#5 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 16 October 2013 - 12:15 PM

Printing coloured text to the console window

 

Grub4dos does not allow you to specify the text (foreground) colour and the background colour separately.

 

[Edit] For colours 1-F you can use  echo $[Bn0T]  where n=1 for bright colour and T is colour 0-F. B=1 for blink if in text mode (e.g. graphicsmode 3)[/Edit]

 

This causes problems if you don't already know what the current colour settings are:

Say we want to write coloured text to the console window but then want to restore the original colours - e.g.

 

message1

message2

WARNING: some warning

message3

 

we will need to know the current foreground/background colours so we can restore them after writing the red text.

Also we may not want to change the background colour but we don't know what it is at the moment.

 

Chenall has shown me a way to get the current colours from internal variables.

 

It also means that we can find the current background colour and therefore write our text message in any colour we like and keep the current background colour the same and then restore the current colours again to whatever they were before.

# 64-bit background color , e.g. 0xCCCC00 
calc 44<<2 + *0x8304 > nul ;; read %@retval% ;; set /A stdhb=%@retval%

#64-bit foreground TEXT color , e.g. 0x123456
calc 43<<2 + *0x8304 > nul ;; read %@retval%  > nul ;; set /A stdhf=%@retval% > nul

#32-bit color current colour, e.g.  0x15
calc 42<<2 + *0x8304  > nul ;; read %@retval% > nul ;; set /A color_32=%@retval% > nul

#get foreground and background 4-bit color values
set  stdb=%color_32:~2,1% ;; set stdf=%color_32:~3,1% ;; if "%stdf%"=="" set stdf=%stdb% && set stdb=0


#6 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 16 October 2013 - 12:23 PM

New Improved Hotkey support!

 

At my request, chenall has modified the hotkey utility. Now you can specify a hotkey and it's actions using the hotkey utility - e.g.

/dir/hotkey [F8] "halt" > nul
/dir/hotkey [F9] "echo This is going to reboot ;; pause --wait=5 Going to reboot in 5 seconds... > nul ;; reboot" > nul

This means we do not have to have a menu entry in a grub4dos menu to use a hotkey.

 

To undo the hotkey do not specify a commandline...

hotkey [F9]

To remove all hotkey settings, uninstall hotkey and re-install

hotkey -u
hotkey

  • DavidB likes this

#7 DavidB

DavidB

    Silver Member

  • Developer
  • 611 posts

Posted 16 October 2013 - 02:51 PM

Cool :)
Thank you.

Is this the modified hotkey utility...?
And does is work with all grub4dos versions >= 0.4.5c-2013-03-03 or just with the latest...?



#8 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 16 October 2013 - 03:11 PM

Hi

That is the correct version. I have only tested it with 0.4.5c 25.07.2013 but it should work with all versions.

There is a problem with 24.07.2013 and previous versions when trying to use echo with a global hotkey - it doesn't display any text if the menu is in graphics mode.

 

e.g. 

hotkey [F9] "echo Can you see this ;; pause"

When you press F9, it clears the menu and you just see a single blank highlighted line with no text.

 

Chenall has done a small fix which is not yet released but is in grldr in q11 here. This clears the screen and writes 'Hotket Boot: ' and then the command line is echo'd and then the command is run, so use 

hotkey [F9] "clear ;; echo Can you see this ;; pause"

If you don't want the debug text displayed.

 

 

P.S. hotkey doesn't work with GFXBoot/GFXMenu.



#9 chenall

chenall

    Member

  • Members
  • 60 posts
  •  
    China

Posted 17 October 2013 - 07:23 AM

 

Printing coloured text to the console window

 

Grub4dos does not allow you to specify the text (foreground) colour and the background colour separately. This causes problems if you don't already know what the current colour settings are:

Say we want to write coloured text to the console window but then want to restore the original colours - e.g.

 

message1

message2

WARNING: some warning

message3

 

we will need to know the current foreground/background colours so we can restore them after writing the red text.

Also we may not want to change the background colour but we don't know what it is at the moment.

 

Chenall has shown me a way to get the current colours from internal variables.

 

It also means that we can find the current background colour and therefore write our text message in any colour we like and keep the current background colour the same and then restore the current colours again to whatever they were before.

# 64-bit background color , e.g. 0xCCCC00 
calc 44<<2 + *0x8304 > nul ;; read %@retval% ;; set /A stdhb=%@retval%

#64-bit foreground TEXT color , e.g. 0x123456
calc 43<<2 + *0x8304 > nul ;; read %@retval%  > nul ;; set /A stdhf=%@retval% > nul

#32-bit color current colour, e.g.  0x15
calc 42<<2 + *0x8304  > nul ;; read %@retval% > nul ;; set /A color_32=%@retval% > nul

#get foreground and background 4-bit color values
set  stdb=%color_32:~2,1% ;; set stdf=%color_32:~3,1% ;; if "%stdf%"=="" set stdf=%stdb% && set stdb=0

Why not using echo??

 

e.g.

 

echo -e $[0xA]test\n$[0xb]ABCD

 

echo $[0x12] test 


Edited by chenall, 17 October 2013 - 07:27 AM.


#10 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 17 October 2013 - 08:07 AM

echo changes the background colour (my batch file preserves the background colour) and echo only supports 0-F for text colours.

 

I wanted to print a coloured text message but keep the background colour the same (which could be any colour as set by a user .cfg file).



#11 chenall

chenall

    Member

  • Members
  • 60 posts
  •  
    China

Posted 17 October 2013 - 12:09 PM

echo changes the background colour (my batch file preserves the background colour) and echo only supports 0-F for text colours.

 

I wanted to print a coloured text message but keep the background colour the same (which could be any colour as set by a user .cfg file).

 

echo does not change color。and also supports 64bit color.the hight 32bit is background color.

 

echo $[0x00FF00FF00FFFF00] Test Text

 

a 8bit color [0-0xff] is compatibility better.Because it can used under console or graphics mode.


Edited by chenall, 17 October 2013 - 12:11 PM.


#12 chenall

chenall

    Member

  • Members
  • 60 posts
  •  
    China

Posted 17 October 2013 - 12:27 PM

 

You may be familiar with the && and || operators, but are you aware of the ! operator

 

The difference between the || and ! operators
|| means 'or else' whereas '!' means 'if not'
 
|| acts on the first test in a compound commandline whereas ! is only relevant for the last test

 

 

 

the ! operator like  `else` and must use with '&&' or '||'

 

it will execute When "&&" or "| |" return false.

 

e.g.

1. if a==b && echo abcd ! echo test

   display test

 

2. if a==b || echo abcd ! echo test

   display abcd

3.if a==c || echo aa && if b==c && echo abcd ! echo test

   display aa\ntest

 

sorry for my english,hope you can understand.


Edited by chenall, 17 October 2013 - 12:29 PM.


#13 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 17 October 2013 - 12:39 PM

I don't quite follow you...

If a user has set blue screen with white text, how do I print a message in red text (for example) but keep the same background colour  (assuming I do not know what colour the user has set the background colour to?).

 

Is there a command that just sets the Text colour?

e.g.

graphicsmode 3
set /A r=%@random%/2047
set r=%r:~2,1%
color 0x%r%F
clear
echo Line 1
echo Line 2 print this in red without changing the background colour
echo Line 3 same colours as Line 1
graphicsmode 0x112
set /A r=%@random%/2047
set r=%r:~2,1%
color 0x%r%F
clear
echo Line 1
echo Line 2 print this in red without changing the background colour
echo Line 3 same colours as Line 1


#14 chenall

chenall

    Member

  • Members
  • 60 posts
  •  
    China

Posted 17 October 2013 - 02:24 PM

 

I don't quite follow you...

If a user has set blue screen with white text, how do I print a message in red text (for example) but keep the same background colour  (assuming I do not know what colour the user has set the background colour to?).

 

Is there a command that just sets the Text colour?

e.g.

graphicsmode 3
set /A r=%@random%/2047
set r=%r:~2,1%
color 0x%r%F
clear
echo Line 1
echo Line 2 print this in red without changing the background colour
echo Line 3 same colours as Line 1
graphicsmode 0x112
set /A r=%@random%/2047
set r=%r:~2,1%
color 0x%r%F
clear
echo Line 1
echo Line 2 print this in red without changing the background colour
echo Line 3 same colours as Line 1

 

using 
echo $[ABCD] TEXT
A blink-, B light-, C BG, D FG.
 
just set C with 0.
e.g.
 
set /A r=%@random%/2047
set r=%r:~2,1%
color 0x%r%F
clear
echo Line 1
echo $[0004] Line 2 print this in red without changing the background colour
echo Line 3 same colours as Line 1


#15 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 17 October 2013 - 03:06 PM

Thanks, so you cannot echo with a black background using $[ABCD] ???



#16 chenall

chenall

    Member

  • Members
  • 60 posts
  •  
    China

Posted 17 October 2013 - 03:10 PM

Thanks, so you cannot echo with a black background using $[ABCD] ???

Yes,If you want to echo with a black background  using $[0xY] 



#17 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 17 October 2013 - 03:36 PM

Yes, understood. Thanks!  :good:



#18 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 20 October 2013 - 06:55 PM

beep!

 

If you computer is fitted with a small internal speaker or 'beeper', you may be able to get it to 'beep' using grub4dos.

 

try:

 

graphicsmode 3

call Fn.2 7

 

If you just see a character displayed and don't hear anything then you are out of luck. If you hear a 'beep' then you are in luck.

 

This can be used for blind and partially sighted people who need to know when the menu is displayed on boot and thus when the timeout countdown begins.

 

For instance you can add this to the top of the menu.lst to show an all-white screen and beep 3 times...

color standard 0xF1 && clear && call Fn.2 7 && call Fn.2 7 && call Fn.2 7 && color standard 0xf && clear

P.S. This will only work on real hardware, not VMs.

 

If you want the white screen for longer (it will be very quick if beep is not supported) then add

 

&& pause --wait=3 > nul 

 

after the last call Fn.2 7

 

 

Note: This only works in text mode (i.e. fresh boot when not switched to hi-res graphics mode) - graphicsmode 3.

 

If you want to make a beep in any graphics mode, you will need to add the bios executable from here and then use this command for each beep

/bios int=0x10 eax=0xe07 ebx=0x0 > nul


#19 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 13480 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 20 October 2013 - 07:02 PM

beep!


Nice :).
Cross-linking to:
http://reboot.pro/to...keys-and-beeps/

:cheers:
Wonko

#20 steve6375

steve6375

    Platinum Member

  • Developer
  • 6557 posts
  • Location:UK
  • Interests:computers, programming (masm,vb6,C,vbs), photography,TV,films,guitars
  •  
    United Kingdom

Posted 20 October 2013 - 07:14 PM

bump. Added info for hi-res mode beep too!







Also tagged with one or more of these keywords: grub4dos, commands, syntax

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users