Wednesday, August 31, 2022

Linux Setup Cheat Sheet III

In the previous post, we set up Ubuntu Linux on Windows and Mac OS/X using VirtualBox. Now we focus our set up on dedicated Ubuntu Linux workstation or Windows PC that has dual boot with Ubuntu Linux installed.

Let's check it out!

Account
Typically, during the installation process, an admin account is prompted to be created with username and password. However, follow these instructions to add new user account with admin access on Ubuntu Linux.
 adduser stevepro
 usermod -aG sudo stevepro
 id stevepro
 su - stevepro

Alternatively, manage user accounts from Settings | Users user interface to add new user account. Initially, the account user will use the default icon. Consider changing via Settings | Users | Picture | Select File.

Login
If, whenever you attempt to login, you get the Ubuntu black screen with flashing cursor then attempt this fix: Reboot computer and login as recovery mode. Once logged in again, download and install NVIDIA.run.

Checkout here and here how to install nVidia driver on Ubuntu Linux e.g. NVIDIA-Linux-x86_64-460.84.run
 sudo su
 cd Downloads
 ./NVIDIA.run

IMPORTANT
If you are running X server then you may get an error when trying to install NVIDIA.run while still logged in:
 Ensure you are logged out!
 sudo service lightdm stop
 sudo init 3
 ./NVIDIA...run
 sudo service lightdm start

In, Software Updater | Additional Drivers, ensure NVidia is set "Using X.Org X server" as alternative driver.


Graphics
Initially, video file formats like mp4 may result in black screen. If so then install all the Multimedia Codecs:
 sudo apt-get update
 sudo apt install ubuntu-restricted-extras

Ubuntu
Confirm the version of Ubuntu Linux installed on terminal with lsb_release -a. Upgrade now accordingly:
 sudo apt update && sudo apt upgrade
 sudo reboot command
 sudo apt install update-manager-core
 sudo do-release-upgrade
 sudo reboot
 lsb_release -a

Kernel
Mainline is graphical tool to install the latest mainline kernel in Ubuntu Linux. Install Mainline from Terminal:
 sudo add-apt-repository ppa:cappelikan/ppa
 sudo apt update
 sudo apt install mainline
 mainline --check
 mainline --list
Start | Ubuntu Mainline. From the User Interface now install / uninstall Ubuntu Linux versions seemlessly. Once Ubuntu Linux kernel has been updated confirm kernel new version with uname -r.

Diff Tools
On Windows PC, Tortoise Merge is handy tool to compare 2x files whereas WinMerge is handy tool that can compare 2x directories. Meld + KDiff3 are alternatives for Linux both installed from Ubuntu Software Center.

Meld
File | New Comparison. File comparison navigate to file 1. Directory comparison navigate to file 2. Compare.

KDiff3
Similar to WinMerge: A. Directory navigate to directory 1. B. Directory navigate to directory 2. Compare OK.

Disk Space
Use Ubuntu Linux Disk Analyzer utility to identify common locations which can be used to free up disk space:
 rm -rf ~/.local/share/Trash/*
 du -sh ~/.cache/thumbnails
 sudo du -h /var/lib/snapd/snaps
 sudo du -sh /var/cache/apt
 sudo apt-get autoclean
 sudo apt-get clean
 sudo journalctl --disk-usage
 sudo journalctl --vacuum-time=3d
Other utilities to identify excess storage include ncud and bleachbit both which can be sudo apt install[ed].

Find
Here are some simple but effective uses of the find command e.g. find all text in file that follows predicate:
 find -L . -type f -exec grep -HniI 'g++' {} \; > ~/Steven/gpp.txt

Another useful example is how to find all of the distinct file extensions in a particular folder hierarchy:
 find . -type f | perl -ne 'print $1 if m/\.([^.\/]+)$/' | sort -u

Shortcuts
 General  Minimize all windows  Ctrl + Alt + D
 gedit  Move prev tab  Ctrl + Alt + PgUp
 gedit  Move next tab  Ctrl + Alt + PgDown

SSH
Secure SHell [SSH] may not be enabled after Ubuntu Linux is installed. Therefore you may get the following:
 ssh stevepro@192.168.15.50
 ssh: connect to host 192.168.15.50 port 22: Connection refused

Server
Here is how to fix the Connection refused issue on port 22. On the destination server set up the following:
 # Make sure OpenSSH is installed
 # Install SSH
 # Check SSH service
 # Start SSH service
 sudo apt list --installed | grep openssh-server
 sudo apt install openssh-server
 sudo service ssh status
 sudo service ssh start

Client
On source client connect to Files | Other Locations | Connect to Server sftp://stevepro@192.168.15.50.
Also, ssh stevepro@192.168.15.50 should now work!

Mouse Scroll
After setting up new blue tooth mouse the default scroll was too slow. Therefore, install and set up lmwheel:
 sudo apt-get install imwheel

Create mouse.sh. Integrate the following shell script. Set execute permissions. Configure using ./mouse.sh.
#!/bin/bash
if [ ! -f ~/.imwheelrc ]
then
cat >~/.imwheelrc<<EOF
".*"
None,      Up,   Button4, 1
None,      Down, Button5, 1
Control_L, Up,   Control_L|Button4
Control_L, Down, Control_L|Button5
Shift_L,   Up,   Shift_L|Button4
Shift_L,   Down, Shift_L|Button5
EOF
fi
CURRENT_VALUE=$(awk -F 'Button4,' '{print $2}' ~/.imwheelrc)
NEW_VALUE=$(zenity --scale --window-icon=info --ok-label=Apply --title="Wheelies" --text "Mouse wheel speed:" --min-value=1 --max-value=100 --value="$CURRENT_VALUE" --step 1)
if [ "$NEW_VALUE" == "" ];
then exit 0
fi
sed -i "s/\($TARGET_KEY *Button4, *\).*/\1$NEW_VALUE/" ~/.imwheelrc # find the string Button4, and write new value.
sed -i "s/\($TARGET_KEY *Button5, *\).*/\1$NEW_VALUE/" ~/.imwheelrc # find the string Button5, and write new value.
cat ~/.imwheelrc
imwheel -kill

VNC Viewer
If you are transitioning from Windows to Linux you may like to remote desktop from Windows to Linux box.

Linux
Follow all instructions. Change Ubuntu desktop manager from GNOME to LightDM. Install X11VNC as service on Ubuntu. Launch Terminal and enter the following. When prompted, ensure you choose lightdm not gdm3:
sudo apt-get update
sudo apt-get install lightdm
sudo reboot
sudo apt-get install x11vnc

After installing LightDM, rebooting and installing X11VNC, configure x11vnc.service. Replace your password!
sudo gedit /lib/systemd/system/x11vnc.service

[Unit]
Description=x11vnc service
After=display-manager.service network.target syslog.target

[Service]
Type=simple
ExecStart=/usr/bin/x11vnc -forever -display :0 -auth guess -passwd REPLACE_WITH_YOUR_LOGIN_PASSWORD
ExecStop=/usr/bin/killall x11vnc
Restart=on-failure

[Install]
WantedBy=multi-user.target

Finally, after configuring x11vnc.service, enter the following commands to complete the VNC Viewer setup.
systemctl daemon-reload
systemctl enable x11vnc.service
systemctl start x11vnc.service

systemctl status x11vnc.service
ip addr | grep 192                        # NOTE the IP address 192.168.1.X

IMPORTANT
Don't lock the screen as you won't be able to VNC back in! Change Settings | Privacy | Screen Lock to this:
Windows
Download and install VNC Viewer. Launch VNC Viewer. Setup Team. Choose File | New Connection. Enter the IP address from above on port 5000 for VNC Server e.g. 192.168.1.X:5900. Enter friendly name + Connect.

When prompted choose Continue. Enter password | Check Remember password. Unfortunately not all keys may work e.g. Caps Lock. Also, you may have to disable and re-enable Repeat Keys from Universal Access.

Summary
Now we have a dedicated Ubuntu Linux workstation set up we are all set for cloud computing development!

Thursday, August 4, 2022

Skazka Code Complete

Skazka is a Slavic RGP Adventure game originally written in BASIC for Sega SC-3000 and posted to SC-3000 Survivors Facebook group. The source code is now ported to C using devkitSMS for the Sega Master System.

Let's check it out!

Note: Skazka development based on devkitSMS Programming Setup and devkitSMS Programming Sample.
Download source code here.


Instructions
Skazka captures the core mechanics of old school RPG experience: Kill monsters | level up | upgrade gear. There are 5x different enemies in increasing order: Razboynik, Hungry Wolf, Kikimora, Leshy, Baby Yaga. Defeat final boss Koschey to beat the game!

Tools
Here is a list of Tools and frameworks that were used in the development of this project:
 KEY  VALUE
 Programming  devkitSMS
 Compiler  sdcc 3.6.9
 Assembler  WLA-DX
 IDE  Visual Studio 2015 / Visual Studio Code
 Languages  C / Z80
 Graphics  BMP2Tile 0.43 / BMP Converter / GIMP 2
 Music  pcmenc / vgm2psg
 Emulators  Emulicious / Fusion / Meka
 Debugger  Emulicious Debugger

ROM Hacking
You can hack this ROM! Download and dump Skazka into Hex Editor, e.g. HxD, and modify bytes:
 ADDRESS  VARIABLE  DESCRIPTION
 0x019E  Delay  Used to speed through any game delay.
 0x019F  Invincible  Non-zero value enables invincibility.
 0x01A0  Current XP  Non-zero sets current experience pts.
 0x01A1  Current HP  Non-zero sets default healthy points.
 0x01A2  Set Gold  Non-zero sets current gold available.
 0x01A3  Set Weapon  Set value to 1 or 2 for stock else 0.
 0x01A4  Set Armor  Set value to 1 or 2 for armor else 0.
 0x01A5  Add Life  Set value to 1=Life otherwise 0=None.
 0x01A6  Village Talk  Set value to 1=repeat villagers talk.
 0x01A7  Music Off  Set 0=Music to play otherwise silent.
 0x01A8  Sound Off  Set 0=Sound to play otherwise silent.

Hints
  • Try to buy weapon "Sword" or armor "Tegilay" with your initial gold before entering any forest fights.
  • After completing each forest fight, ensure you "Rest" at the main screen to replenish all health points.
  • In the shop when you buy items you already have then will be deducted unconditionally so be aware!
  • Get "+1 Life" just in case you lose a fight or the final boss battle so you do not have to restart game.
  • Maximize HP + XP + get the best weapon "Axe" and best armor "Kolchuga" before fighting the boss.
  • Fight boss when you have > 60 XP because your weapon and armor may be slightly more powerful!

Cheats
  • On title screen, hold fire2 to skip intro music. Same applies on boss and over screens.
  • On title screen, hold fire2 after intro music completes to reveal hidden credits screen.
  • On stats screen, move joystick left or right to skip over the flashing arrows indication.
  • In Easy mode forest screen, press fire2 to "Run away" without risking losing any HPs.

Debugging
  • On Windows you can debug the source code directly from in Visual Studio Code after pressing F5.
  • On Linux you can debug source code directly from Visual Studio Code but launch Emulicious first.

Credits
Extra special thanks to sverx for the devkitSMS. Plus StevePro Studios would like to thank Calindro all for his 24/7 Tech Support. Plus shout out to Mojon Twins na_th_an in which I found lots of some cool sound effects.

Update
Skazka V1.0 was initially a text-based RPG adventure game. However, after collaboration with Kagesan from SMS Power!, graphics were added for all screens for V2.0 which is the most up-to-date version of the game.



Summary
Despite the fact that Skazka was a simple text-based RPG adventure with limited game play, the cool aspect was collaborating with original developer and working together to port the game to the Sega Master System.

Skazka was entered in the SMS Power! 2022 competition to connect the Sega SC-3000 Facebook group and the SMS Power! community with the goal to spread Sega 8-bit preservation and fanaticism. That's awesome!