@@ -118,6 +118,9 @@ public class CentralProcessingUnit extends Thread
118118 // Whether index quirks are enabled
119119 private boolean indexQuirks = false ;
120120
121+ // Whether clip quirks are enabled
122+ private boolean clipQuirks = false ;
123+
121124 CentralProcessingUnit (Memory memory , Keyboard keyboard , Screen screen ) {
122125 this .random = new Random ();
123126 this .memory = memory ;
@@ -179,6 +182,15 @@ public void setIndexQuirks(boolean enableQuirk) {
179182 indexQuirks = enableQuirk ;
180183 }
181184
185+ /**
186+ * Sets the clipQuirks to true or false.
187+ *
188+ * @param enableQuirk a boolean enabling clip quirks or disabling clip quirks
189+ */
190+ public void setClipQuirks (boolean enableQuirk ) {
191+ clipQuirks = enableQuirk ;
192+ }
193+
182194 /**
183195 * Fetch the next instruction from memory, increment the program counter
184196 * to the next instruction, and execute the instruction.
@@ -883,14 +895,16 @@ private void drawExtendedSprite(int xPos, int yPos, int bitplane, int activeInde
883895
884896 for (int xIndex = 0 ; xIndex < 8 ; xIndex ++) {
885897 int xCoord = xPos + xIndex + (xByte * 8 );
886- xCoord = xCoord % screen .getWidth ();
898+ if ((!clipQuirks ) || (xCoord < screen .getWidth ())) {
899+ xCoord = xCoord % screen .getWidth ();
887900
888- boolean turnedOn = (colorByte & mask ) > 0 ;
889- boolean currentOn = screen .getPixel (xCoord , yCoord , bitplane );
901+ boolean turnedOn = (colorByte & mask ) > 0 ;
902+ boolean currentOn = screen .getPixel (xCoord , yCoord , bitplane );
890903
891- v [0xF ] += (turnedOn && currentOn ) ? (short ) 1 : (short ) 0 ;
892- screen .drawPixel (xCoord , yCoord , turnedOn ^ currentOn , bitplane );
893- mask = (short ) (mask >> 1 );
904+ v [0xF ] += (turnedOn && currentOn ) ? (short ) 1 : (short ) 0 ;
905+ screen .drawPixel (xCoord , yCoord , turnedOn ^ currentOn , bitplane );
906+ mask = (short ) (mask >> 1 );
907+ }
894908 }
895909 } else {
896910 v [0xF ] += 1 ;
@@ -912,20 +926,22 @@ private void drawNormalSprite(int xPos, int yPos, int numBytes, int bitplane, in
912926 for (int yIndex = 0 ; yIndex < numBytes ; yIndex ++) {
913927 short colorByte = memory .read (activeIndex + yIndex );
914928 int yCoord = yPos + yIndex ;
915- yCoord = yCoord % screen .getHeight ();
916-
917- short mask = 0x80 ;
918-
919- for ( int xIndex = 0 ; xIndex < 8 ; xIndex ++) {
920- int xCoord = xPos + xIndex ;
921- xCoord = xCoord % screen .getWidth ();
929+ if ((! clipQuirks ) || ( yCoord < screen .getHeight ())) {
930+ yCoord = yCoord % screen . getHeight ();
931+ short mask = 0x80 ;
932+ for ( int xIndex = 0 ; xIndex < 8 ; xIndex ++) {
933+ int xCoord = xPos + xIndex ;
934+ if ((! clipQuirks ) || ( xCoord < screen . getWidth ())) {
935+ xCoord = xCoord % screen .getWidth ();
922936
923- boolean turnedOn = (colorByte & mask ) > 0 ;
924- boolean currentOn = screen .getPixel (xCoord , yCoord , bitplane );
937+ boolean turnedOn = (colorByte & mask ) > 0 ;
938+ boolean currentOn = screen .getPixel (xCoord , yCoord , bitplane );
925939
926- v [0xF ] |= (turnedOn && currentOn ) ? (short ) 1 : (short ) 0 ;
927- screen .drawPixel (xCoord , yCoord , turnedOn ^ currentOn , bitplane );
928- mask = (short ) (mask >> 1 );
940+ v [0xF ] |= (turnedOn && currentOn ) ? (short ) 1 : (short ) 0 ;
941+ screen .drawPixel (xCoord , yCoord , turnedOn ^ currentOn , bitplane );
942+ mask = (short ) (mask >> 1 );
943+ }
944+ }
929945 }
930946 }
931947 }
0 commit comments