# Rogalian's Notes

## Microsoft Surface Go 2 - Debian

1. Repository here: https://github.com/linux-surface/linux-surface/wiki/Package-Repositories
2. Packages to install: linux-image-surface linux-headers-surface linux-surface-secureboot-mok surface-control libwacom-surface thermald libcamera-tools maliit-keyboard
3. nano -w /etc/environment
    QT_QUICK_CONTROLS_STYLE="org.kde.desktop"

## Retroid Pocket Mini V2

### RetroArch

* Video driver: vulkan
* Scaling
    * Aspect Ratio: Core provided
    * Crop Overscan: Off
* Global Shader: crt-easymode-halation.slangp
    * Gamma Input: 3.00
    * Sharpness Horizontal: 0.00
    * Sharpness Vertical: 1.00
    * Mask Type: 6.00
    * Mask Strength Min: 0.50
    * Mask Strength Max: 0.50
    * Geom Warp: 0.01
    * Geom Corner Size: 0.02
    
#### SNES (bsnes)

* Core Options: Video
    * Preferred Aspect Ratio: 1:1 PAR
    * Crop Vertical Overscan: 12 lines
    * Filter: NTSC (RF)
* Core Options: HD Mode 7
    * Scale: 720p
    * Perspective Correction: On
    * Supersampling: On
    * HD->SD Mosaic: On
    
#### Game Boy (Gambatte)

* Scaling
    * Aspect Ratio: Custom
    * Custom Aspect Ratio (Width): 1280 (8x)
    * Custom Aspect Ratio (Height): 1152 (8x)
    * Viewport Anchor Bias X: 0.30
    * Viewport Anchor Bias Y: 0.30

* Shader: handheld/console_border/dmg.slangp
    * Shader Passes: 5
    * Baseline Alpha: 0.20
    * LCD Response Time: 0.42
        * (Tested with Z.A.S.)
    * Video Scale: 7.00
    * Ambient Screen Light: 0.90
    * Shadow Opacity: 1.00
    * Shadow Offset Horiz: -3.00
    * Shadow Offset Vert: 3.00
    * Screen Offset Horiz: 3.00
    * Screen Offset Vert: 5.00
    
#### Game Boy Color (Gambatte)

* Shader: authentic_gbc.slangp

#### PC Engine (Beetle PCE)

* Core Options: Video
    * Initial Scanline: 8
    * Last Scanline: 236

#### NES (Mesen)

* Core Options: Video
    * NTSC Filter: Composite (Blarg)
    * Left Overscan: 12px
    * Right Overscan: 12px
    * Top Overscan: 16px
    * Bottom Overscan: 16px



#### Master System (Genesis Plus GX)
* Core Options: Video
    * Preferred Aspect Ratio: 4:3
    * Hide Master System Borders: Left & Right Borders
    * Blarg NTSC Filter: Composite

----

## PowKiddy RGB30

* Scaling
    * Crop Overscan: Off

### Shaders

#### CRT systems

* Shader: crt/fakelottes
* Shader parameters:
    * Shadow Mask: 3.00
    * Scanline Intensity: 0.00
    * Warp X: 0.00
    * Warp Y: 0.00
    * Mask Dark: 0.50
    * Mask Light: 1.50
    * CRT Gamma: 2.50
    * Monitor Gamma: 2.20
    * Scanline Sine Comp A: 0.00
    * Scanline Base Brightness: 0.95
    
#### LCD systems
* Shader: handheld/lcd3x

### Core Settings

#### Game Boy (Color) - Gambatte

* GB Colorization: Intenal
* Internal Palette: GB - DMG
* Color Correction: GBC Only
* Colour Correction Mode: Accurate
* Interframe Blending: LCD Ghosting (Accurate)

#### Game Boy Advance - mGBA

* Color Correction: Auto
* Interframe Blending: Off
    * Personal preference - GBA benefits from less blur

#### Game Gear - Genesis Plus GX

* Borders: Off

#### Master System - Genesis Plus GX

* Scaling
    * Aspect Ratio: Custom
    * Custom Aspect Ratio (X Position): -30
    * Custom Aspect Ratio (Y Position): 76
    * Custom Aspect Ratio (Width): 756
    * Custom Aspect Ratio (Height): 567

* Video
    * Borders: Off
    * Hide Master System Side Borders: Off
    * Blarg NTSC Filter: Composite

#### Nintendo Entertainment System - FCEUmm

* Scaling
    * Aspect Ratio: Custom
    * Custom Aspect Ratio (X Position): -38
    * Custom Aspect Ratio (Y Position): 0
    * Custom Aspect Ratio (Width): 794
    * Custom Aspect Ratio (Height): 720

* Video
    * Crop Horizontal Left Overscan: 0
    * Crop Horizontal Right Overscan: 0
    * Crop Vertical Left Overscan: 0
    * Crop Vertical Right Overscan: 0
    * NTSC Filter: Composite
* Audio
    * Sound quality: Very High
    * Audio RF Filter: On
    
#### Mega Drive - Genesis Plus GX

* Scaling
    * Aspect Ratio: Custom
    * Custom Aspect Ratio (X Position): -24
    * Custom Aspect Ratio (Y Position): 72
    * Custom Aspect Ratio (Width): 768
    * Custom Aspect Ratio (Height): 538
    
* Video
    * Blarg NTSC Filter: Composite

#### PC Engine - Beetle PCE Fast

* Scaling
    * Aspect Ratio: Custom
    * Custom Aspect Ratio (X Position): -24
    * Custom Aspect Ratio (Y Position): -8
    * Custom Aspect Ratio (Width): 768
    * Custom Aspect Ratio (Height): 728
    
* Video
    * Color Palette: Composite
    * Initial Scanline: 0
    * Last Scanline: 242
    
#### Super Nintendo - Snes9x

* Scaling
    * Aspect Ratio: Custom
    * Custom Aspect Ratio (X Position): -24
    * Custom Aspect Ratio (Y Position): 24
    * Custom Aspect Ratio (Width): 768
    * Custom Aspect Ratio (Height): 672

* Video
    * Crop Overscan: Off
    * Blarg NTSC Filter: Composite

----
    
## 8BitDo M30 2.4g

Hold button combinations for 5 seconds. LED will blink in red to indicate
success.

* Home + Up: X-input
* Home + Left: Nintendo Switch
* Home + Down: D-input (Genesis mini)
* Select + Up: Set Dpad as Dpad
* Select + Left: Set Dpad as left analogue stick
* Select + Right: Set Dpad as right analogue stick
* Select + Down: Swap A/B and X/Y mapping (on Switch mode only)

----

## Irkenlabs JAMMA Expander

From <https://github.com/misteraddons/mistercade_mappings>

1. Add the following section to the end of to the file downloader.ini that
   should be found in the root of the SD

    ```ini
    [misteraddons/mistercade_mappings]
    db_url = https://raw.githubusercontent.com/misteraddons/mistercade_mappings/db/db.json.zip
    ```

2. Run update_all.sh
3. Via SSH, run the following to rename the MiSTerCade
   input mapping for the JAMMA Expander VID/PID:

    ```sh
    cd /media/fat/config/inputs
    shopt -s nocaseglob
    for file in *16d0_10be_v3.map ; do cp $file ${file//16d0_10be/8282_3201} ; done
    shopt -u caseglob
    ```

3. MiSTer main menu > Define joystick buttons
4. Switch JAMMA Expander from Keyboard to gamepad input
5. Press left on Joystick
6. Use JAMMA Expander to input keypress for Space, twice (skipping Joystick detection)
5. Press inputs in this order
    1. Joystick Right
    2. Joystick Left
    3. Joystick Down
    4. Joystick Up
    5. Button 1 (A)
    6. Button 2 (B)
    7. Button 3 (X)
    8. Button 4 (Y)
    9. Button 5 (L)
    10. Button 6 (R)
    11. Coin (Select)
    12. Start (Start)
6. Use JAMMA Expander to input keypresses for Space to skip all other inputs

----

## Useful Shell (bash/zsh) One-liners

### Hyundai i30 USB flash drive format - needs to be FAT32 and small sector size
`mkfs.fat -S 512 /dev/sda1`

### Directly image a block device from a compressed image
`gunzip -c < "image_name_here.img.gz" | sudo dd of=/dev/mmcblk0 bs=10M conv=fsync status=progress`

### Delete duplicate files
`fdupes -rtdN . `

### Zip all sub directories individually
`for i in */; do zip -r "${i%/}.zip" "$i"; done`

### Zip all files individually
`for i in *.*; do zip -r "${i%.*}.zip" "$i"; done`

### Rename photos using EXIF metadata
`exiftool '-filename<CreateDate' -d ~/Pictures/photos/%Y/%Y-%m/%Y%m%d-%H%M%S%%-c.%%le -r -ext cr2 -ext dng -ext jpg -ext JPG -ext Jpg .`

### Remove empty folders
`find . -type d -empty -delete`

### Move all files in subdirectories to current directory
`find . -type f -exec mv {} . \;`

### Convert all WAV files in subdirectories to FLAC. Needs bash shell installed
`find . -type f -name '*.wav' -exec bash -c 'ffmpeg -y -i "$1" -compression_level 12 "${1%.wav}".flac' - '{}' \;`

### Convert VOBs to MKV losslessly, retaining audio and subtitle streams
`ffmpeg -fflags +genpts -analyzeduration 100M -probesize 100M -i "concat:$(echo VTS_03*.VOB|tr \  \|)" -y -dn -map 0:v -map -0:a -map 0:s -c copy -f dvd VTS_03.mkv`

### Rename music in current (subfolders) using ID3 tags
```sh
exiftool -r -P -ext mp3 -ext m4a \
 '-filename<~/Music/${Artist;} (${Year;DateFmt("%Y")}) ${Album;}/${track;$_=sprintf("%02d",$_)} ${Artist;} - ${Title;}.%e' \
 '-filename<~/Music/${Artist;} (${Year;DateFmt("%Y")}) ${Album;}/${PartOfSet;}${track;$_=sprintf("%02d",$_)} ${Artist;} - ${Title;}.%e' \
 '-filename<~/Music/${Band;} (${Year;DateFmt("%Y")}) ${Album;}/${track;$_=sprintf("%02d",$_)} ${Artist;} - ${Title;}.%e' \
 '-filename<~/Music/${Band;} (${Year;DateFmt("%Y")}) ${Album;}/${PartOfSet;}${track;$_=sprintf("%02d",$_)} ${Artist;} - ${Title;}.%e' .
```
```sh
exiftool -r -P -ext flac \
 '-filename<~/Music/${Artist;} (${Date;DateFmt("%Y")}) ${Album;} [LL]/${TrackNumber;$_=sprintf("%02d",$_)} ${Artist;} - ${Title;}.%e' \
 '-filename<~/Music/${Artist;} (${Date;DateFmt("%Y")}) ${Album;} [LL]/${Discnumber;}${TrackNumber;$_=sprintf("%02d",$_)} ${Artist;} - ${Title;}.%e' \
 '-filename<~/Music/${AlbumArtist;} (${Date;DateFmt("%Y")}) ${Album;} [LL]/${TrackNumber;$_=sprintf("%02d",$_)} ${Artist;} - ${Title;}.%e' \
 '-filename<~/Music/${AlbumArtist;} (${Date;DateFmt("%Y")}) ${Album;} [LL]/${Discnumber;}${TrackNumber;$_=sprintf("%02d",$_)} ${Artist;} - ${Title;}.%e' .
```
### Copy directory structure
`rsync -av -f"+ */" -f"- *" ~/Music_FLAC/ ~/Music/`

### Convert all FLAC files into MP3 preserving directory structure and metadata, scaling cover art. Runs across all CPU cores. Run in parent folder!
`fd -t f -e flac -x ffmpeg -i "{}" -c:v mjpeg -vf scale=600:600 -q:a 0 -map_metadata 0 -id3v2_version 3 "~/Music/{.}.mp3"`

### Convert all FLAC files into MP3 preserving metadata, scaling cover art. Runs across all CPU cores. Run in parent folder!
`find . -type f -name "*.flac" -exec bash -c 'NAME="{}" && ffmpeg -i "$NAME" -c:v mjpeg -vf scale=600:600 -q:a 0 -map_metadata 0 -id3v2_version 3 "${NAME/.flac/.mp3}"' \;`

### 2 pass reencode all MKV in subdirectories to MP4 480p 512MB per hour, do not overwrite existing files.
`find . -type f -name '*.mkv' -exec bash -c 'ffmpeg -y -i "$1" -pix_fmt yuv420p -tune film -vf scale=-8:480 -c:v libx264 -preset:v veryslow -b:v 980k -pass 1 -an -f mp4 -map_metadata -1 /dev/null && ffmpeg -i "$1" -pix_fmt yuv420p -tune film -vf scale=-8:480 -c:v libx264 -preset:v veryslow -b:v 980k -pass 2 -af aresample=async=1:min_hard_comp=0.100000:first_pts=0 -c:a aac -b:a 128k -ac 2 -f mp4 -map_metadata -1 ~/Movies_Portable/"${1%.mkv}"-480p.mp4' - '{}' \;`

### Reencode all MKV in directory to MP4 in parent directory for playback LG SmartShare TV. Overwriting existing.
`find . -type f -name '*.mkv' -exec bash -c 'ffmpeg -y -i "$1" -c:v libx264 -tune animation -pix_fmt yuv420p -strict strict -profile:v high -af aresample=async=1:min_hard_comp=0.100000:first_pts=0 -c:a aac -ac 2 -f mp4 -map_metadata -1 "../${1%.mkv}".mp4' - '{}' \;`

### Reencode all MP4 in directory, scale to 1920 wide, film preset
`find . -type f -name '*.mp4' -exec bash -c 'ffmpeg -y -i "$1" -c:v libx264 -vf scale=1920:-8 -tune film -pix_fmt yuv420p -strict strict -profile:v high -af aresample=async=1:min_hard_comp=0.100000:first_pts=0 -c:a aac -ac 2 -f mp4 -map_metadata -1 "${1%.mp4}"NEW.mp4' - '{}' \;`

### Make thumbnails of MKV files
`find . -type f -name '*.mkv' -exec bash -c 'ffmpegthumbnailer -i "$1" -o "${1%.mkv}".jpg -s0 -m' - '{}' \;`

### Max compression settings for 7z
`7z a file.7z -mx9 -mmt 2 -md1024m files_to_compress`

### Strip unnecessary metadata from mp4 files - change mp4 to required extension as appropriate
`find . -type f -name '*.mp4' -exec bash -c 'ffmpeg -y -i "$1" -map_metadata -1 -c copy "${1%.mp4}"new.mp4 && mv -v "${1%.mp4}"new.mp4 "$1"' - '{}' \; `

----
