Jump to content


Photo
- - - - -

The AND, OR and XOR instructions


42 replies to this topic

#41 IRF

IRF

    Advanced Member

  • Contributor
  • 4,458 posts

Posted 08 June 2020 - 03:39 PM

I have taken the liberty of editing the title of this topic from 'The AND instruction' [as it was when started by jetsetdanny] to 'The AND, OR and XOR instructions', to reflect more inclusively the discussions of the use of those instructions in the thread as a whole.

 

This is a good place to mention a cunning use of the OR command - namely something which Norman Sword came up with, to fix the bug in the original Manic Miner game engine whereby crumbling cells can sometimes leave ghosts.

 

The original MM engine clears the bottom pixel-row of a crumbly cell when Willy stands on it, then shifts all the pixel-rows above down by one pixel-row, and then checks the bottom pixel-row - and if it is empty, the program considers that cell to be cleared and replaces the crumbly colour-attribute with the air cell attribute for the current cavern.  The problem with that approach is if you have a crumbly cell pixel pattern with a clear (inkless) pixel-row halfway down the cell, with some infilled pixels in the pixel-rows above that blank row - then the program is fooled into turning the crumbly cell to air prematurely, leaving a 'ghost' of the uncleared pixels in the top part of the (now air) cell.

 

Norman Sword rewrote the crumbling cell routine (as discussed elsewhere), so that all eight pixel-rows of a crumbly cell are OR'd together whenever Willy stands on the cell.  After clearing the Accumulator (A register), a loop is set up to apply the OR command to all eight bytes representing the bitmaps for each pixel-row of the crumbly cell.  (i.e. pixel-row 1 OR pixel-row 2 OR row 3 OR row 4 OR row 5 OR row 6 OR row 7 OR row 8).  If a single pixel is infilled in any one of those pixel-rows, then the Zero flag will not be set at the end of the loop.  Only if all eight crumbly rows are clear (all eight bytes which are OR'd together hold the value 00) will the Z flag be set - with the outcome that the crumbly cell gets changed to air [by changing the cell's attribute].

 

In Manic Mixup, I adapted Norman's code, based on the OR command, to be used both in underfoot crumbly cells, and also whenever Willy uses his hard hat to headbutt away an overhead earth block (which causes the pixel-rows to be cleared in the opposite direction i.e. the rows are shifted from the bottom upwards).



#42 jetsetdanny

jetsetdanny

    Advanced Member

  • Contributor
  • 2,250 posts

Posted 14 June 2020 - 12:24 AM

A cunning use of the OR command, indeed! :)


Edited by jetsetdanny, 14 June 2020 - 12:24 AM.


#43 andrewbroad

andrewbroad

    Advanced Member

  • Contributor
  • 79 posts

Posted 15 June 2020 - 12:14 AM

I've seen some cunning uses of the Boolean operators in JavaScript, where they have some quirky behaviour when their operands are non-Boolean.


Dr Andrew Broad





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users