Monday, July 15, 2019

Check if a screen is turned on in Windows 10

To check that a monitor is powered on in Windows 10, here is the command-line:


C:\Users\Vikram>wmic path win32_desktopmonitor GET Availability,Caption
Availability  Caption
8             LCD 1280x800
3             Default Monitor


It returns a line with column headers and a single row for each monitor you have. The column 'Availability' tells you whether the monitor is turned on or not. 8 means turned off, 3 means ON.

In the above output, I have an actual display LCD 128x800, which is off, and a virtual display called 'Default Monitor' (from Microsoft Remote Desktop) that is turned on.

You can get the full object as well, showing useful info like DPI, monitor size, etc:


C:\Users\Vikram>wmic path win32_desktopmonitor


Availability  Bandwidth  Caption          ConfigManagerErrorCode  ConfigManagerUserConfig  CreationClassName     Description      DeviceID         DisplayType  ErrorCleared  ErrorDescription  InstallDate  IsLocked  LastErrorCode  MonitorManufacturer  MonitorType      Name             PixelsPerXLogicalInch  PixelsPerYLogicalInch  PNPDeviceID                               PowerManagementCapabilities  PowerManagementSupported  ScreenHeight  ScreenWidth  Status  StatusInfo  SystemCreationClassName  SystemName
8                        LCD 1280x800     0                       FALSE                    Win32_DesktopMonitor  LCD 1280x800     DesktopMonitor1                                                                                     Lenovo               LCD 1280x800     LCD 1280x800     96                     96                     DISPLAY\LEN4010\4&3A89619C&0&UID67568640                                                                                    OK                  Win32_ComputerSystem     DESKTOP-DNTB7R7
3                        Default Monitor                                                   Win32_DesktopMonitor  Default Monitor  DesktopMonitor2                                                                                                          Default Monitor  Default Monitor  96                     96                                                                                                                      800           1280         OK                  Win32_ComputerSystem     DESKTOP-DNTB7R7

Friday, March 29, 2019

Untrusted: A superb programming game

I recently came across a wonderful programming game: Untrusted.

It is not a game you install, you just play it on your web browser. You don't need to buy it, you don't need any in-app currency. It requires some knowledge of programming.

It's a weird game. You edit code to finish a level, and very few instructions are provided.  The games require some critical thinking, and some brute-force. Some of the levels are cunning.



Do try it! It is one of the most innovative and brilliant games I have played recently.



Screenshot of the ending. It's the journey, not the destination.


Sunday, March 03, 2019

Unix from 1972... on a Raspberry Pi 3

Want to run Unix on a PDP 11, and all you have is a Raspberry Pi 2/3 handy?


Here's a Docker image I created with the first version of Unix, and SIMH (a CPU level simulator) that simulates a real PDP-11. Once you have Docker, getting it to work on Raspberry Pi is trivial:

docker run  -it youngelf/unix-72-raspi3:1.0

That should download the image, and run simh. The user is 'root', no password. Yes, this is very secure.

It is a fun system to play with. No vi (Bill Joy hadn't written it yet), but there is 'ed'. There is a C compiler which is 4k in size. The original Unix paper talks about the system.

The system is ancient: no backspace support, no command history, no control characters (Ctrl-p, Ctrl-n, Ctrl-a). Pipes on the shell have not been invented yet, though the system supports them. Redirection with > works, but the name of the file has to come immediately after the '>' character. Spaces aren't allowed between them. You have to be sure of yourself.


It is a full CPU emulator, so you can write PDP-11 assembly on this computer and assemble it.


Take a moment to think of the magic that brings you this: 
  1. The Raspberry Pi: A $35 computer.
  2. SIMH software emulating a 1970s PDP-11.
  3. Old source code for Unix, which was made available.
  4. Docker, a system to allow pre-packaged software to run with minimal effort.
  5. The Internet, that moves all these bits around.
  6. Linux, that runs on the Raspberry Pi and is available free of charge.

Many of these systems are built, powered, or influenced by Unix.


This builds on top of bahamat's git repository, which had to be recompiled for arm32.