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.

Monday, October 15, 2018

DOS for kids

Find out why my kid is learning DOS in 2018...

There are many great options to learn how to use computers. You could get any excellent Linux distribution, and install it on a spare machine. You could teach a child Python or Basic256. My kids use Linux laptops, and that works out well for most of their needs.

Recently, my son took an interest in other operating systems. His hard disk is going bad after years of use, and we started experimenting with alternate operating systems on USB sticks. He saw me reading about Haiku; we booted it up and played with it. We already used Dosbox to play a game that I really enjoyed as a child, so we installed Freedos on an SD card to play with it.

He loved FreeDOS better than I had expected. It is a very simple system: single user, no access control, no hidden or magic directories. Everything is right there in front of you. We installed QuickBasic and a typing tutor, and he loves the system. He even loves the spartan look of the default editor, which looks like edit.com.

Today, he practiced typing on a typing tutor from 1992.  Then we wrote a simple Basic program together, and compiled it to an EXE file. He loved every minute.


That made me reconsider tech's love of the new. The computing world is a slave to hot trends: Artificial Intelligence, Machine Learning, Virtual Reality, Augmented Reality, Internet of Things, Blockchain, ... Everyone wants to learn about new technologies, the old is an embarrassing relic.

But are new systems always the best to learn?


There are scores of videos showing how old systems booted up faster, and got the job done just as well. There's a hint of truth to that.
FreeDOS boots on a decade-old computer in less than a second. Quickbasic probably takes a second to start up. Compilation is quick. Everything is instant. Fast. No clutter. No notifications, no icons, no buttons, bars. The whole interface has been run through an optimizing compiler.

The system cannot connect to a network, so everything is child-safe. And there is no chance of my kid goofing off and playing a game, or being distracted by some pictures. My son said that FreeDOS was "an Xterm that became your full computer."

And to top it up, my son can modify whatever he likes and experiment to his heart's content. When he ends up messing up the system, we can reinstall FreeDOS in a minute by wiping the SDcard clean, and copying again. I have a stack of old SD cards.

All the knowledge gained is valuable in today's world: hierarchical file systems, writing source files, compiling, touch-typing. It is a simple system and a person can truly understand the fundamentals. Learning DOS might be easier than learning a very complicated architecture like Linux, where there is a kernel, but also userland utilities, X-Windows, browsers, multiple users, access control...

In the past few days of playing with FreeDOS my son has asked insightful questions, which make this experiment very satisfying for me.




Image: Courtesy Me.

Saturday, September 22, 2018

Autobiographies ...

I haven't read a lot of autobiographies, but here are a few that I've read in the last couple of years that made an impression.

Books about high-altitude mountaineering are exciting by definition.  But there's more to this one than just that.  It's the story of a woman who wants to climb high mountains in a time when it's mostly men who do that sort of a thing.

2. Tender at the Bone by Ruth Reichl
Ruth Reichl is a restaurant critic / cookbook author.  This is the story of her unusual childhood (dysfunctional family included), and her love of cooking.  It's peppered with recipes that I didn't really want, but I loved the story.

3. God's Hotel by Victoria Sweet
The author writes about her years working at San Francisco's Laguna Honda Hospital, which is one of the last few almshouses (a free hospital for poor and often chronically ill people) in the country. Dr. Sweet also talks about her research of pre-modern medicine (and be warned - those sections are not as interesting).  But overall, I found this book to be very insightful and very fun to read.

The three books above were all surprise finds.  I picked them up at the library and brought them home because I liked what it said on the back cover.  Didn't have them recommended to me by a friend.  Didn't look up the Amazon reviews.  What joy to run into a good book accidentally like that!

Tuesday, February 13, 2018

Game Review: TIS-100

TIS is a new game by Zachtronics. tl:dr; Geek? Buy it.

Earlier, I had written about the lack of diversity in games. The world doesn't need another action adventure first person shooter. What it needs is creative games, games that make you evaluate, to think new thoughts. I loved a game that made you burn stuff, and a gem by Zachtronics called Space Chem. I have been interested in Zachtronics' catalog since SpaceChem. For background, SpaceChem was about splitting and combining atoms to make new molecules.

TIS-100 is about parallel programming. But that's as vacuous as saying Chess is about moving wooden pieces on a board. TIS is about writing good code, about making magic with very little, about learning how best to utilize a small instruction set.

It is about reliving 80s computing: complete with a ratty manual, an uncertainty about what to make. Walk away with an appreciation that you can do a lot. Learn the system, and you can bend it to your will.

You write assembly language programs for a computer that has multiple stream processors, where multi-processor communication is a one-cycle primitive, and you choose how to achieve the objective.

You don't need to know assembly, you don't need to know programming. You don't need knowledge of Chemistry for SpaceChem, you don't need to know programming for TIS-100.

But at the end of it, you appreciate programming and you learn how much fun programming can be.

TIS is an absolutely amazing game. A game that I will be recommending to many friends, and their young kids.


Here's a video showing the different processors (little square boxes). The highlights are on executing lines, and the left side shows inputs and expected outputs.


Video courtesy: me.