Sunday 4 October 2020

How to install MinGW GCC for 64 & 32 bit on Windows 10

1. Download latest MinGW from http://mingw-w64.org/doku.php/download


2. Install and ensure to select 64 or 32 bit architecture during install based on which version you want. Run the install twice to install both


3. Create a user system variable MinGW pointing to the mingw64 or mingw32 installation folder (bin is a sub folder)

Control Panel > System and Security > System > Advanced System Settings > Environment Variables

or

just search for environment in the W10 search bar

 

4. Add %MinGW%\bin to the user system path


5. Test by running 'g++ --version' from powershell or command prompt



Saturday 3 October 2020

Mandlebrot set in Go

 

 

Mandlebrot

 

Mandlebrot set program in Go based on original ps5.js program by Codingtrain

package main

import (
    "fmt"
    "image"
    "image/png"
    "image/color"
    "os"
)

func main() {
    
    // set image width and height in pixels
    image_width := 1000
    image_height := 1000

    // Create a blank image
    myImage := image.NewRGBA(image.Rect(0, 0, image_width, image_height))

    
    // set (w)idth and (h)eight. Set h based on w scaled by image ratio
    w := 3.0
    h := (w * float64(image_height)) / float64(image_width)
    

    // start at negative half the width and height
    xmin := -w/2
    ymin := -h/2
    
    // maximum number of iterations for each point on the complex plane
    // if we dont reach infinty in maxiterations then assume we never will
    maxiterations := 100;
    
    // x goes from xmin to xmax
    xmax := xmin + w
    
    // y goes from ymin to ymax
    ymax := ymin + h
    
    // calculate amount we increment x, y for each pixel
    dx := (xmax - xmin) / float64(image_width)
    dy := (ymax - ymin) / float64(image_height)
    
    
    //start y
    y := ymin
    
    for j:=0; j < image_height; j++ {
        // start x
        x := xmin
       
        for i:=0; i < image_width; i++ {
           
            //now we test, as we iteate z = z^2 + cm does z tend towards infinity?
           
            a := x
            b := y
            n := 0
           
            for n < maxiterations {
                aa := a * a
                bb := b * b
                twoab := 2.0 * a * b
                a = aa - bb + x
                b = twoab + y
                // infintiy in our finite world is simple, let's just consider it 16
                if (a*a + b*b) > 16 {
                    break
                }
                n++
            }
           
            if (n==maxiterations) {
                myImage.Set(i, j, color.RGBA{0, 0, 0, 255})
            } else {
                myImage.Set(i, j, color.RGBA{uint8(n)*16, 0, 0, 255})
            }
            x += dx
        }
        y += dy
    }
    
    // outputFile is a File type which satisfies Writer interface
    outputFile, err := os.Create("test.png")
    if err != nil {
        // Handle error
    }

    // Encode takes a writer interface and an image interface
    // We pass it the File and the RGBA
    png.Encode(outputFile, myImage)

    // Don't forget to close files
    outputFile.Close()   
}


Thursday 10 September 2020

Mount Synology NFS shared drive in Linux

How to create a NFS share on a Synology NAS and mount it on a linux client machine using the guest account for all users.

Synology NAS steps

  1. Enable NFS in control panel > file services
  2. Create share in Control Panel > Shared Folder e.g, public
  3. Set NFS Permissions
    •     Hostname * (allow all hosts to connect)
    •     Privilege Read/Write
    •     Squash map all users to guest
    •     security sys
    •     Enable asynchronus
    •     Allow connections from non-privileged ports
  4. Enable the guest user account and ensure it has r/w access to the share

 

Linux client steps

 Install the nfs client if not already installed
  1.  sudo apt update
  2. sudo apt install nfs-common 
 Create a mount point directory
  1. mkdir /mnt/public

Mount the drive. NB use the share path as shown in the control panel e.g. /volume1/public

  1. sudo mount -t nfs 192.168.76.38:/volume1/public /mnt/public

Saturday 28 March 2020

How to update APU2 pfSense firewall BIOS


First in the pfSense web UI check the system type and current BIOS version.
pfSense Web UI System Information

1. Install flashrom

In pfSense web UI, go to Diagnostics -> Command Prompt
Under "Execute Shell Command" type and execute
 
pkg install -y flashrom

2. Check flashrom 

 To check whether flashrom knows about your chipset and ROM chip, run flashrom -p internal

Example output:
flashrom v1.1 on FreeBSD 11.3-STABLE (amd64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 4, resolution: 2ns).
coreboot table found at 0xdffae000.
Found chipset "AMD FCH".
Enabling flash write... OK.
Found Winbond flash chip "W25Q64.V" (8192 kB, SPI) mapped at physical address 0x00000000ff800000.
No operations were specified.
 

3. Backup the current bios


Run flashrom -p internal -r /tmp/backup.bin and copy the file to your PC for safekeeping

Example output:
flashrom v1.1 on FreeBSD 11.3-STABLE (amd64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 4, resolution: 2ns).
coreboot table found at 0xdffae000.
Found chipset "AMD FCH".
Enabling flash write... OK.
Found Winbond flash chip "W25Q64.V" (8192 kB, SPI) mapped at physical address 0x00000000ff800000.
Reading flash... done.
 
 
Use download file to copy the file /tmp/backup.bin to your computer.
 

4. Download latest BIOS from pcengines


Get the bios file for your APU2 from here: https://pcengines.github.io/
Now upload the file from your computer to the pfsense using "Upload File" under Diagnostics -> Command Prompt
Notice your file will be uploaded to /tmp/
 

5. Upload BIOS to APU2

Use the upload file to copy the latest BIOS file from your computer to the APU. Not the file will be uploaded to /tmp/

6. Flash BIOS

Now Under "Execute Shell Command" type (replace file name with name of the ROM)
flashrom -p internal -w /tmp/apu2_v4.11.0.4.rom
You may need to force the update with  -p internal:boardmismatch=force.

Example output:
flashrom v1.1 on FreeBSD 11.3-STABLE (amd64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 4, resolution: 2ns).
coreboot table found at 0xdffae000.
Found chipset "AMD FCH".
Enabling flash write... OK.
Found Winbond flash chip "W25Q64.V" (8192 kB, SPI) mapped at physical address 0x00000000ff800000.
This coreboot image (PC Engines:apu2) does not appear to
be correct for the detected mainboard (PC Engines:PCEngines apu2).
Aborting. You can override this with -p internal:boardmismatch=force.
 
Example output:
flashrom v1.1 on FreeBSD 11.3-STABLE (amd64)
flashrom is free software, get the source code at https://flashrom.org

Using clock_gettime for delay loops (clk_id: 4, resolution: 2ns).
coreboot table found at 0xdffae000.
Found chipset "AMD FCH".
Enabling flash write... OK.
Found Winbond flash chip "W25Q64.V" (8192 kB, SPI) mapped at physical address 0x00000000ff800000.
This coreboot image (PC Engines:apu2) does not appear to
be correct for the detected mainboard (PC Engines:PCEngines apu2).
Proceeding anyway because user forced us to.
Reading old flash chip contents... done.
Erasing and writing flash chip... Erase/write done.
Verifying flash... VERIFIED.

 

Sunday 16 February 2020

ZX Spectrum Hello World! Assembler on Windows


1. Download the PASMO Z80 cross assembler.

2. Download and install the FUSE ZX Spectrum emulator

2. Save the following hello world! program to 'helloworld.txt'

; hello-world.z80
CHAN_OPEN   equ  5633
PRINT       equ  8252

            org  32512

            ld   a, 2                ; 3E 02
            call CHAN_OPEN           ; CD 01 16
            ld   de, text            ; 11 0E 7F
            ld   bc, textend-text    ; 01 0E 00
            jp   PRINT               ; C3 3C 20

text        defb 'Hello, World!'     ; 48 65 6C 6C 6F 2C 20 57
                                     ; 6F 72 6C 64 21
            defb 13                  ; 0D

textend     equ  $


3.  Compile the programme into a TAP file with basic loader
.\pasmo -1 --tapbas '..\Zx Spectrum\helloworld.txt' prog.tap >> debug.txt

-1 (digit 'one') Show debug info during both passes of assembly.

With the --tapbas option a tap file is generated with two parts: a Basic loader and a code block with the object code. The Basic loader does a CLEAR before the initial address of the code, loads the code, and executes it if a entry point is defined (see the END directive). That way you can directly launch the code in a emulator, or transfer it to a tape for use in a real Spectrum. 

4.  Open the prog.tap file in Fuse

Fuse will load the first part of the TAP file which is the basic loader programme

The Basic loader program
5. Run the assembler program by issuing the the command

RANDOMIZE  USR 32512

To type this on a spectrum 48K keyboard

type T to enter the RANDOMIZE command then
press Shift+Ctrl (to enter Extended keyboard mode - flashing E cursor) and type 'L' for USR
then type 32512 and press return to execute




* alternatively add the directive END 32512 to the end of the helloworld program and PASMO will include the basic command to run the assembly code automatically.