Page 1 of 1

New demo uploaded: 8-BitCoin Miner

Posted: Sun May 02, 2021 3:28 pm
by CX16UserSteveC



8-BitCoin Miner




View File






The Commander X16 8-BitCoin Miner application supports the mining of a notional crypto currency which I refer to as 8-BitCoin which has no monetary value but perhaps you can gain a bit of notoriety by posting snapshots of rare results on the Commander X16 Facebook page, and perhaps this application will inspire those unfamiliar with BitCoin to learn a bit more about it.

The Commander X16 8-BitCoin Miner application is based on Bitcoin Miner 64 by YTM/Elysium (https://github.com/ytmytm/c64-bitcoin-miner) which was inspired by stacksmasher's GameBoy miner (https://www.youtube.com/watch?v=4ckjr9x214c). Bitcoin Miner 64 supports a demo mode as well as a cooperative mining mode which interfaces to an eternal process running ntgbtminer (https://github.com/ytmytm/c64-ntgbtminer). I don't know of any way of communicating with an external process from an application running on the Commander X16 emulator, so I removed the cooperative mining mode and focused on enhancing the standalone demo mode in the port to the Commander X16. Enhancements include the ability to randomize the block data, keep track of total number of hashes and associated 8-BitCoin value earned, display the best and last hash results and associated nonces and 8-BitCoin values, and to load and save state which allows a user to restore their data between sessions.

I've created and posted a C64 version as well as a CX16 version. For the CX16 version a single penny is earned for the first leading zero in the binary representation of the hash result and each subsequent leading zero increases in value by a 2x factor. When the first one is detected in the binary representation of the hash result, each subsequent zero decreases in value by a 2x factor until the value is less than a single penny. Since the CX16 clock rate is approximately 8x the C64 clock rate, the earned value for the C64 version is calculated by multiplying the earned value for the CX16 version by a factor of 8.

When the 8-BitCoin Miner application is started a title screen is displayed at which point the user can press any key to advance to the main menu.

At the main menu the user can randomize the block data, start mining, and save and load the mining state via the R, M, S, and L keys respectively. When the block data is randomized any previous best and current hash results are cleared but the total hash count and associated earned value are retained.

The best and last hash results are cleared and the total hash count and associated earned value are initialized to zero when the 8-BitCoin Miner application is started, but loading a previously saved state will restore the best and last hash results and the total hash count and associated earned value. There's a single "BITMINER.DAT" save file, so be aware saving will overwrite any previous existing version of this file. Likewise when you perform a load command you will lose any results accumulated since the last save operation. If you want to save and load state you'll probably have to download the application because I doubt that these features will work properly with the online emulator associated with the "Try it now" feature (since there's the possibility of multiple simultaneous users and only a single save file which doesn't seem to be retained between on-line emulator sessions).

When mining the user may return to the main menu by pressing the M key.

I tested the CX16 version on the CX16 emulator revision R38 and I briefly tested the C64 version on the VICE C64 emulator and the C64 mini. The save and load functions seem to work on the VICE C64 emulator but not on the C64 mini. However, you can use the save and load functions provided by the C64 mini to save and restore the state between mining sessions.

Here's some C source code which is equivalent to the implementation and intended to clarify calculation of the earned value from the hash result. The calculation of hashWord is not shown but occurs in the ... portion between the variable declaration and subsequent code.

    uint32_t hashWord, value, bitMask, deltaValue;

    .

    .

    .

        value=0;

        bitMask=0x80000000;

        deltaValue=1;

        while((bitMask!=0) && ((bitMask & hashWord)==0))

            {

            value+=deltaValue;

            bitMask=bitMask>>1;

            deltaValue=deltaValue<<1;

            }

        bitMask=bitMask>>1;

        deltaValue=deltaValue>>1;

        while((bitMask!=0) && (deltaValue!=0))

            {

            if ((bitMask & hashWord)==0)

                value+=deltaValue;

            bitMask=bitMask>>1;

            deltaValue=deltaValue>>1;

            }

#ifdef C64

        // multiply value by 8 for C64 version

        value=value<<3;

#endif