BREV

Display

(HP-41CX, Hewlett Packard 1983 and DM41X, SwissMicros 2020)
 

Overview
Programs BREVB and BREVD are binary reversi games. The user must flip the bits such that all 9 bits will be 0 whilst applying the least number of flips. Although both programs do the same, the implementations differ.
Program BREVB does a binary flip of each bit. That means, if the value is 0 make it 1 and if it is 1 make it 0. This is done in the loop around LBL 04. This version does not use a decimal separator.
Program BREVD does a decimal flip of each bit and uses a decimal separator for each group of 3 bits. It adds 1’s to the bits [ii] in the original number [i] and truncates the 2’s (sum of a bit with value 1 and the mask with value 1). Here is an example with number of flips equals 6 with a given pattern [i] 100.111.001:

  1. to swap the last 6 bits, the user enters the value 6 which will generate a value of six 1’s, in the loop around LBL 01, giving:
             111.111 [ii]

  2. this flip value (ii) will be added to the decimal patterns, i.e.:
         100.111.001 [i]
             111.111 [ii]
         ----------- +
         100.222.112 [iii]

  3. locate where the 2’s are and generate a subtract value, which in this case is:
             222.002 [iv]

  4. subtract the updated 2’s mask (iv) from (iii) which will give the new (i)’:
         100.222.112 [iii]
             222.002 [iv]
         ----------- -
         100.000.110 [i]’

  5. the game ends when [i]’ is 0.

The display uses flag 29 to show the thousands separator. However, it should not show the last decimal separator when “1E 9” is there to keep the leading zeros. This is done by adding three alpha characters, rotating them including the decimal separator and remove the first 6 alpha characters from the alpha register, in LBL 05, specifically lines 32-40.
In program BREVD the random number generator checks for each of the nine 10x values whether it should be added and delivers a number between 0-111.111.1111.
Both programs carry out a game-over test is all bits have the value 0.
Program BREVB is more efficient with handling the bits during the generation of the pattern as well as flipping the bits. It does not provide decimal separators for ease of use.
Flipping bits is counted from right to left.
 

Example 1, BREVB

 

Example 2, BREVD

 

Program Listing
The listing of the programs is given below with 2 XROM functions SEED and RNDM on lines 6 and 9 resp. 9 and 15. These can be taken as explicit calls to other programs in memory or to XROM functions, for example the CCD module. If replaced by these XROM functions (as in the RAW and TXT file) the total number of byte savings is 8. So, program BREVB would be 94 instead of 102 bytes and program BREVD would be 162 instead of 170 bytes. If not available, programs must be in place for these functions.

The listing of program BREVB (“binary” flip) is given below:

 
and for BREVD (“decimal” flip) shown here:

 

Registers, Labels and Flags

 

Downloads
PDF format of program BREV.
RAW/TXT format of program BREV (in zip file).
 

This program is copyright and is supplied without representation or warranty of any kind. The author assumes no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof

© 1999-2023 by Auke Hoekstra

 
Don`t copy text!