Jump to content

Zach's Projects

  • entries
    53
  • comments
    535
  • views
    67,115

Alternate Chess Kernel Solved

Sign in to follow this  
Guest

1,510 views

post-2572-1091144615_thumb.jpg

post-3928-1098333398_thumb.jpg

post-2572-1091144616_thumb.jpg

 

In my last attempt at a chess kernel with playfield graphics, I came up with a technique that would only work with about 27K of code. Since then I've made some advances that make a 4K kernel possible. One trick I developed was a new 32 pixel asymmetrical playfield configuration that takes four loads and six stores. (I believe it's new at least.)

 

The playfield remains transposed rather than reflected, but unlike before I load the same byte for the right PF0 and PF2 data. The high nybble goes to PF0 and the low nybble goes to PF2. The byte is stored to PF0 first, is AND'ed with #$0F and then stored to PF2. Setting X to #$0F and using the SAX instruction, which stores the value A & X, saves a couple cycles. I already had set X to white for my color changes, and by a fortunate coincidence white is #$0F. In additon, this value can be used to clear PF0 on the left side. This playfield configuration uses a few more cycles than the simple 32 pixel reflection, but the timing is more flexible and frees time to do all the color changes.

 

; X = #$0F (White) 
; Y = #$00 (Black)
;dynamic_code; starts on cycle 3 
  pla			 ; load PF2 left side			
  sta PF2-15,X	; left side. Use index to spend a cycle
  pla			 ; load PF0 and PF2 for right side				
  stx PF0,Y	   ; clears PF0 on left side
  sta temp-15,X   ; use indexed addressing to spend an extra cycle
  stx COLUPF	  ; color piece 1
  sta PF0		 ; right side
  stx COLUPF	  ; color piece 2
  lda pf1_right   ; load PF1 right side. The operand is inc'd below.
  stx COLUPF	  ; color piece 3
  sta PF1		 ; right side  
  stx COLUPF	  ; color piece 4
  stx COLUPF+64,Y ; color piece 5; COLUPF+64 mirrors COLUPF
  lda #$00		; <-- temp is the address of the operand here.		  
  sty COLUPF+64-15,X; color piece 6   
  sax PF2		 ; right side
  stx COLUPF	  ; color piece 7
  stx COLUPF+64,Y ; color piece 8
  pla			 ; load PF1 left side	  
  sta PF1		 ; left side   
  inc pf1_right_addr		
  bne dynamic_code; last byte for pf1_right must be $ff	   
  brk					 

 

The RAM can be allocated as follows:

32 bytes to store the board position (1 nybble for each square)

42 bytes of self-modifying code (includes temp variable)

52 bytes for temporary storage of playfield data

2 bytes for everything else

Sign in to follow this  


29 Comments


Recommended Comments



I have played chess for a long time and only seen the 3 move repetition rule used once.  As long as people know it's not part of the game's makeup I don't think it's a huge deal if you leave it out.  Maybe you could spit out notation as you go along (not to be stored) that a serious player could write down and refer back to if they cared that much.

 

I suppose one could also argue that unless time pressure is a factor the triple-repetition rule won't generally matter if the 50 move rule is enforced. If a position kept recurring, the 50-move rule will eventually kick in even if the repetition rule did not. If either player could expect to win by breaking the repetition he would do so; if neither player has such an expectation the game draws.

Share this comment


Link to comment
Any further development here?

I'm pleasantly surprised to see growing interest in this project, since this thread was dormant for a while at the beginning. Chess is #6 on my to-do list. When I need a break from my current projects, I might get the cursor working.

 

BTW I don't think it's worth worrying about the repetition rule.

Share this comment


Link to comment
I suppose one could also argue that unless time pressure is a factor the triple-repetition rule won't generally matter if the 50 move rule is enforced.  If a position kept recurring, the 50-move rule will eventually kick in even if the repetition rule did not.  If either player could expect to win by breaking the repetition he would do so; if neither player has such an expectation the game draws.

 

Actually, yes... and this may not even be that hard to do. Just have a small subroutine where you track a variable (such as Fifty_Move_Check). Each time white (or black) makes a move, you incriment this by one. If a pawn moves or a piece is captured, this number is set back to zero. You could even make another subroutine where if the variable reaches say 46 or 47, the game could decide whether it was ahead, even, or behind in value and make a "decision" whether or not to accept/play for a draw based on cost of forcing this this variable to be reset. If this doesn't make sense (as I often don't), I'd be happy to explain further.

 

-JD

Share this comment


Link to comment

(Bump)

 

I added a cursor and made the pieces movable this week. Be sure to hold down the trigger while moving a piece.

 

Because the RAM is basically max'd out I had to do a lot of bit manipulation to squeeze everything in. It took careful planning to organize everything:

  • 32 bytes for the board position (1 nybble for each square)
    42 bytes of self-modifying code (includes temp variable)
    52 bytes for temporary storage of playfield data
    1 byte: 4 bits for cursor shape and color, 4 bits for piece underneath cursor
    1 byte: 5 bits cursor position plus 3 bits for row counter
     
    1 bit from SM code, STA PF2-15,X or STA PF2,Y for 6th bit of cursor position
     
    4 bits from SM code for joystick speed control:
    • 1 bit stx PF0,Y or sta PF0+64,Y
      1 bit stx COLUPF or sta COLUPF+64
      1 bit sta PF0 or sta PF0+64
      1 bit stx COLUPF or sta COLUPF+64

8 bits from timer for cursor blinking

I am confident that enough memory can be dug out to store the rest of the data needed to define the game state. It won't exactly be fun to code all the rules of chess, but I hate to see this kernel go to waste. I'll just keep working on it from time to time. :)

Share this comment


Link to comment

Guest
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...