Month: June 2020

Benchmarking my Raspberry Pi

Benchmarking my Raspberry Pi

hardinfo running on Raspberry PiI played with a couple of free packages today. I can recommend hardinfo. (sudo apt install hardinfo to install then hardinfo to run ) though less about the benchmarks than the information it gives on your system.

I’ve got both 32-bit Raspbian and 64-bit Raspberry Pi OS on two sd cards and intend to run both and compare benchmarks just to see the difference.

Another benchmark utility that looks interesting is sysbench (sudo apt install sysbench to install). It runs from the terminal and lets you run benchmarks against file io, cpu, memory threads, mutex and oltp.  Just type sysbench and you’ll get a list of commands.

 

How to install VSCodium on a Raspberry Pi.

How to install VSCodium on a Raspberry Pi.

64-bit VSCodium running on a 64-bit PI.It was very easy.  This was onto my Pi 4 running 64-bit Raspberry Pi OS.

Go to the releases page on the vsCodium website, it’s on GitHub.  If you are running 32-bit Pi OS then you need the codium_1.46.0-1591900344_armhf.deb file (the number will most likely have changed).  For the 64-bit one, you need the codium_1.46.0-1591900344_arm64.deb.

When you click on the link it will download and ask if you want to keep it. It will then give you the option of opening it and select the archiver. That will install it for you.

After that, to run it from the command line just type codium.

Or as I just discovered. Look on the pull down menu, go onto accessories and you should see (probably near the bottom) VSCodium. Move the mouse over and right-click.You’ll see a popup menu with Add to Desktop and Properties. If you click the former, you get an icon on your desktop.

Raspberry Pi IconsScreenshots were captured with the Flameshot utility. It’s installed with sudo apt install flameshot. That’s the VSCodium and Flameshot icons.

 

Creative computing games

Creative computing games

Hammurabi BASIC listYesterday’s post reminded me of one of the joys of my youth. The Creative Computing magazines’ “BASIC Computer games” book and it’s sequel “More BASIC Computer games.” . I bought these in 1982, and they weren’t cheap then- about £20 each.

Of course over the years they got lost but I bought them again a few years back. Some of the games in here are classics- A simple Star Trek game, Hammurabi, mugwump, golf, various landers. Of course they are all in BASIC but relatively easy to convert to C.

You don’t have to buy the books (they are pretty expensive on Amazon and no I’m not selling mine!) as many of the games are available online. One source is this classic BASIC games web page. Here’s another link  with more games but they are scans of the pages.

I promise I won’t be putting any more BASIC listings up. These are just an  inspiration to create small games in C or adapt these.

While at Uni in my first year, I adapted a copy of the Star Trek game adding in a whole lot of new features. It doesn’t say much about the interactive mainframe there that with just four people playing the game, the mainframe was brought to its knees!

Browsing the source code of old and commercial games

Browsing the source code of old and commercial games

 

Archive photos
Image by Pexels from Pixabay

This page on a website called WikiZero has a long and very extensive list of games whose source code is available. That doesn’t always mean you can build the game. Many games are very old and in BASIC or assembly (.g. Elite is available in various forms).

It might have been created for a different platform or more likely the source code is available but the graphics and sound assets aren’t, unless you have bought the game, perhaps from sites like gog.com and so have them.

One thing to be aware of, many of the links on WikiZero go to the excellent wayback machine which is part of archive.org. This is under threat by some commercial publishers because they have lent ebooks during the Covid lockdown period without any limitation.  So if you are interested in anything I suggest you check it out sooner rather than later, just in case.

For instance here is the C source code for a TRS-80 game from 1979 called Paravia. It looks like a much expanded version of the Classic Computer game Hammurabi.  Note the wayback machine can take a few seconds to retrieve a webpage. They have a very large chunk of the web’s websites in there…

Goto is considered bad programming in C but

Goto is considered bad programming in C but

goto exit signThere is one case for using goto when you have nested loops and you’d like to jump all the way out. The goto statement was very popular in BASIC but often resulted in programs being like spaghetti with gotos all over the place.

Here’s a contrived example where I have used a goto.

#include <stdio.h> 

int array[10][10][10];
int main() {
    // Populate array
    for (int y=0;y<10;y++)
      for (int x=0;x<10;x++) 
        for (int z=0;z<10;z++) {
          if (array[x][y][z]==0)
            goto exit;
    }
exit:;
}

In my C programs, for-loops are the most popular followed by while-loops, do-while loops and gotos are hardly ever used at all.

My trial by Windows Defender is over

My trial by Windows Defender is over

EXpression opf irritation!
Image by prettysleepy1 from Pixabay

There’s nothing wrong with this short C program, which is in my ebook and which I was compiling to test it.

#include <stdio.h>

int main() {

	int a = 10;
	for (int i = 0; i < 5; i++) {
		a--;
		printf("i = %d\n", i);
		if (a == 8) break;
	}
}

Nothing wrong, except Windows Defender went ape-shit every time I compiled it! Talk about annoying. This was in Visual Studio. I’m fairly scrupulous about keeping nasties off my PC but if you believed Defender I had some weird Trojan.

I did a search and found an unanswered question on StackOverflow from someone with the same reported trojan. So I answered it!

Thankfully there was an update from Windows Defender last night and they have quashed this false positive. If the worst came to the worst, I’d hop on to Hyper-V and compile it in Ubuntu or Raspberry Pi OS with clang. But still a bit irritating!

Another Visual Studio Code source – VSCodium

Another Visual Studio Code source – VSCodium

VSCodiumAs they say “This is not a fork. This is a repository of scripts to automatically build Microsoft’s vscode repository into freely-licensed binaries with a community-driven default configuration.”

Microsoft’s code includes telemetry and tracking code. The code built here is the same as Microsoft’s but with that telemetry and tracking code removed. Also it includes builds for both ARM (32 and 64-bit) which you don’t get from Microsoft.

The Docs page provides info on how to copy JSON bindings from Visual Studio Code to VSCodium. I shall be giving this a try. Much as I like the code.headmelted.com Visual Studio Code, it doesn’t appear to be updated very often whereas VSCodium seems to be built every night.

 

 

My raspberry Pi touchscreen arrived but it wasn’t smooth going

My raspberry Pi touchscreen arrived but it wasn’t smooth going

I bought the Longruner (no, not a typo!) 7″ touch screen and it turned up after a few days. It’s nicely made and similar to this, though it looks slightly different. That hand must be a dolls hand!

It doesn’t have any documentation but there was a DVD with three MS Word documents which I opened on my Windows PC (It comes in useful sometimes!). One of them the “7inch HDMI Display user Manual(En).docx” has a photo of the three ports.

There’s a full size HDMI socket and a USB to Android (Micro USB-B I believe) cable is included that plugs into a USB port and either of the Android type ports. You can either have power and touch screen with the port nearest the HDMI as I did or just power alone, if you want to use it as a monitor. The two green squares show the USB and touch/power cables.

When I switched it on, it just sat there saying no HDMI signal. That MS Word document included instructions to edit the config.txt in \boot. Of course I had no display but the Pi was plugged into the network and I ran WinSCP which logged in and let me view files. I don’t think you can edit files as root with WinSCP, and that config.txt file needs root access to edit it.

However I am a long time user of Putty. (You can also get putty from putty.org but I don’t know if that is also an official one). After that I could ssh into the pi, do a sudo -s command to switch in root and then nano /boot/config.txt to edit config.txt.

longruner touchscreen being touchedHere’s a photo of my fat finger moving the cursor round the screen. It works surprisingly well, and the display is lovely though my photos probably do not do it justice.

These are the lines you paste into the end of the config.txt, save it out and reboot.

max_usb_curren=1
hdmi_force_hotplug=1
config_hdmi_boost=7
hdmi_group=2
hdmi_mode=87
hdmi_drive=1
display_rotate=0
hdmi_cvt 1024 600 60 6 0 0 0

Now I just have to figure out how to use it in my games. The display is 1024 x 600 btw.

Plugging in a second monitor worked fine as this photo shows. The blacks are darker on the touchscreen but that’s just because the gammas don’t match and I was too lazy to change them!

Touchscreen and 2nd monitor on Raspberry Pi

Playing with 64-bit Raspberry Pi OS

Playing with 64-bit Raspberry Pi OS

Binary digits
From Pixabay.com

So after deciding I was going to wait until the 64-bit Pi OS was tested and ready for use, I changed my mind and downloaded the beta and installed it.

It ran ok, though as with any Beta there are bound to be little glitches. There’s a survey where they are interested in what the PI is being used for and it showed UNDEFINED for my Pi’s serial number, though

cat /proc/cpuinfo

worked fine and displayed it.

The display utility let me change my display to 75 HZ at 1920 x 1080 and then promptly crashed. After reboot though it was at 75 HZ.

My main reason for trying it out though, I was curious about development tools, particularly IDES. I had forgotten that code.headmelted.com, the alternative source for Visual Studio Code (my favourite) supported arm64 which is what the 64-bit runs.  I was able to install VS Code from there without any problems.

64-bit vs 32-bit

32-bit has the memory limitation of 3 GB (in both Windows and Linux)  whereas 64-bit offers any amount of RAM up to what’s available. It’s not that big  thing with a 4 GB PI but with 8 GB it can make a big difference.  This article (Sorry that the link is to an article on Medium.com which offers a few free articles then paid) suggests that 64-bit Debian (which Raspberry Pi OS is) is quite a bit faster than 32-bit.  My impression is that it feels a bit snappier but that could be wishful thinking n my part!

I’ll put Asteroids on and see what fps I can get though that may not be a great way to compare them as the GPU plays a big part and I can’t see it making any difference, but I could be completely wrong on that. More as I investigate further.

C Amalgamation – for SQLite

C Amalgamation – for SQLite

SQLite Logo
Image by CopyrightFreePictures from Pixabay

If I were to use a database in a game, it’s likely that it would be SQLite. It’s an open source SQL database that is 102 different C files and 32 others. Of those 102, 75% are C and the remainder header files.

Unlike many other SQL databases (for example MySQL, SQL Server, PostgreSQL) it doesn’t need to run as a separate server. It compiles directly into your application, adding a whopping 400 KB! (I’ve seen bigger picture files…)  It’s fast and very well tested. For every line of code there are 644 lines of test code! Details of testing here.

You wouldn’t use SQLite in an arcade game as it would be a bit of an overkill just to hold a high-score table, but in something like a Rogue or Mud game, I could easily see it being used to store rooms, corridors, treasures etc. SQLite is also very easy to use.

The word amalgamation means that all the 102 source files have been combined (amalgamated) into one file called SQLite3.c. So building it is a single command.

SQLite is probably the worlds most popular database. It’s found in most operating systems and is used in every smartphone.