Casio Calculator Program Library

Program name: Chess (v. 1.01)  --(Back to Index)--

CTF file name: chess.ctf
Author: Tom Lynn
Date: 1997?-1998
Models: 9700 (9800, 9750, 9850, 9950)?

Screenshot:

[screenshot]


Description:

   A working chess board for two players.
   Move the pointer to the piece, press [EXE], move it where you want,
   press [EXE].  It's not touch-move; move onto one of your own pieces
   to take back a move (this requires redrawing the whole screen though!).
   Queening and castling work too.
   
   This was designed for the fx-9700.  It has also been tested on a 9850.
   It should work on a later model, but I haven't tested it.  If you try
   to use it with another model, make sure it is a widescreen model, or
   you will need to change all of the graphical commands to centre the
   image without changing the aspect ratio. 
   
   This was really only done to prove that it could be.  It's very very slow.
   
   The screenshot was taken using Martin Poupe's excellent calculator emulator,
   freely available at http://pages.whowhere.com/computers/martin.poupe/.
   The .cas files needed to run Chess on this emulator are available in zipped
   form in chess.zip.  Run the emulator on ~chess.cas from whichever
   directory you extract the files into.
              
Program source code:
Program "~CHESS" [Main routine]

   "   \*\*\* Chess \*\*\*"
   0->N
   1->Y
   "Continue game [Y\/N]"?->G
   G<>0=>Goto 0
   1->P
   Prog C
   Lbl 0
   Prog "CHGRID"
   Lbl 1
   Prog "CHPLMOVE"
   Goto 1
              
Program "CHCD" [Draw pieces on black squares]

   Prog D
   27+7T->R
   70-7U->S
   'Quicker Game
   'Prog "CHCD2"
   'Goto Z
   Frac (.5(T+U))=0=>Prog "CHCD2"
   Frac (.5(T+U))=0=>Goto Z
   'Black Squares
   V=0=>Goto C
   V=1=>Goto 1
   V=2=>Goto 2
   V=3=>Goto 3
   V=4=>Goto 4
   V=5=>Goto 5
   V=6=>Goto 6
   V=7=>Goto 7
   V=8=>Goto 8
   V=9=>Goto 9
   V=10=>Goto 0
   V=11=>Goto A
   V=12=>Goto B
   Lbl C
   'Empty Black square
   (-)7->W
   Lbl E
   Plot R,S-7-W
   Plot R+6,Y
   Line
   Isz W
   Goto E
   Goto Z
   Lbl 1
   'White Pawn
   Plot R+1,S-1
   Plot X,S-6
   Line
   Plot R+2,S-1
   Plot X,S-3
   Plot X,S-4
   Plot X,S-6
   Plot R+6,Y
   Line
   Plot X,S
   Line
   Plot R,S
   Line
   Plot R,S-6
   Line
   Plot R+5,Y
   Plot X,S-1
   Line
   Plot R+4,Y
   Plot X,S-3
   Plot X,S-4
   Goto Z
   Lbl 2
   'White Knight
   Plot R,S-6
   Plot R,S
   Line
   Plot R+6,S
   Line
   Plot X,S-6
   Line
   Plot R+1,Y
   Line
   Plot X,S-1
   Line
   Plot R+3,Y
   Line
   Plot R+5,Y
   Plot R+2,S-3
   Plot R+3,Y
   Plot R+2,S-4
   Plot R+5,Y
   Goto Z
   Lbl 3
   Plot R,S
   Plot R,S-6
   Line
   Plot R+6,Y
   Line
   Plot X,S
   Line
   Plot R+4,S
   Line
   Plot R+5,S-1
   Plot R+2,S-4
   Plot R+5,Y
   Plot R+1,S
   Line
   Plot X,S-5
   Line
   Plot R+2,S
   Goto Z
   Lbl 5
   Plot R,S
   Plot R+6,S
   Line
   Plot X,S-1
   Plot R+4,Y
   Line
   Plot R+2,S-1
   Plot R,Y
   Line
   Plot R+1,S-2
   Plot R+2,Y
   Plot X,S-3
   Plot R+4,S-2
   Plot R+5,S-2
   Plot R+4,S-3
   Plot R,Y
   Plot R,S-6
   Line
   Plot R+6,Y
   Line
   Plot X,S-3
   Line
   Plot R+5,S-4
   Plot X,S-5
   Plot R+1,S-4
   Plot X,S-5
   Goto Z
   Lbl 6
   Plot R,S-6
   Plot R,S
   Line
   Plot R+6,S
   Plot X,S-6
   Line
   Prog "CHCD2"
   Goto Z
   Lbl 7
   Plot R,S-6
   Plot R,S
   Line
   Plot R+6,S
   Line
   Plot X,S-6
   Line
   Plot R+1,S-1
   Plot R+5,Y
   Plot R+1,S-3
   Plot X,S-4
   Plot R+5,S-3
   Plot X,S-4
   Prog "CHCD2"
   Goto Z
   Lbl 8
   Plot R,S-6
   Plot R,S
   Line
   Plot R+6,S
   Line
   Plot R+1,S-1
   Plot R+6,Y
   Plot R+1,S-6
   Plot R+6,Y
   Prog "CHCD2"
   Goto Z
   Lbl 4
   Plot R,S
   Plot R+6,S
   Line
   Plot X,S-6
   Line
   Plot R,Y
   Line
   Plot R,S
   Line
   Plot R+1,S-3
   Plot X,S-4
   Plot R+5,S-3
   Plot X,S-4
   Plot R+2,S-1
   Plot R+4,Y
   Goto Z
   Lbl 9
   Plot R+1,S-6
   Plot R,Y
   Plot R,S
   Line
   Plot R+1,S
   Plot R+6,S
   Plot X,S-6
   Prog "CHCD2"
   Goto Z
   Lbl 0
   Plot R,S
   Plot R+6,S
   Plot X,S-6
   Plot R,Y
   Prog "CHCD2"
   Goto Z
   Lbl A
   Plot R+1,S-1
   Plot R,Y
   Plot R,S
   Plot R+6,S
   Line
   Plot X,S-1
   Plot R+5,Y
   Plot R+6,S-5
   Plot X,S-6
   Plot R,Y
   Plot R,S-5
   Prog "CHCD2"
   Goto Z
   Lbl B
   Plot R,S-6
   Plot R,S-5
   Plot R,S-1
   Plot R,S
   Plot R+6,S
   Line
   Plot X,S-1
   Plot X,S-5
   Plot X,S-6
   Prog "CHCD2"
   Lbl Z
   Plot 0,0
   Plot 0,0
   Line
              
Program "CHCD2" [Draw pieces on white squares]

   'White Squares
   V=0=>Goto Z
   V=1=>Goto 1
   V=2=>Goto 2
   V=3=>Goto 3
   V=4=>Goto 4
   V=5=>Goto 5
   V=6=>Goto 6
   V=7=>Goto 7
   V=8=>Goto 8
   V=9=>Goto 9
   V=10=>Goto 0
   V=11=>Goto B
   V=12=>Goto B
   Goto Z
   Lbl 1
   'White Pawn
   Plot R+2,S-1
   Plot R+1,S-2
   Plot R+2,S-3
   Plot X,S-4
   Plot R+1,S-5
   Plot X,S-6
   Plot R+5,Y
   Line
   Plot X,S-5
   Plot R+4,S-4
   Plot X,S-3
   Plot R+5,S-2
   Plot R+4,S-1
   Goto Z
   Lbl 2
   'White Knight
   Plot R+4,S
   Plot R+6,S-2
   Line
   Plot X,S-6
   Line
   Plot R+1,Y
   Line
   Plot X,S-5
   Plot R+3,S-3
   Line
   Plot R+2,Y
   Plot R+1,S-2
   Plot R+2,S-1
   Plot R+3,Y
   Plot R+5,S-4
   Goto Z
   Lbl 3
   'White Bishop
   Plot R+2,S
   Plot X,S-1
   Plot R+6,S-5
   Line
   Plot X,S-1
   Line
   Plot R+5,Y
   Plot X,S
   Plot R+4,S
   Plot R+1,S-1
   Plot X,S-5
   Line
   Plot R+2,S-4
   Plot X,S-6
   Plot R+5,Y
   Line
   Goto Z
   Lbl 4
   'White Rook
   Plot R+1,S
   Plot R+5,S
   Line
   Plot R+6,S-1
   Plot X,S-5
   Line
   Plot R+5,S-6
   Plot R+1,Y
   Line
   Plot R,S-5
   Plot R,S-1
   Line
   Plot R+2,Y
   Plot R+4,Y
   Plot R+1,S-3
   Plot X,S-4
   Plot R+5,S-3
   Plot X,S-4
   Goto Z
   Lbl 5
   'White Queen
   Plot R+2,S-3
   Plot X,S-1
   Line
   Plot R+4,Y
   Line
   Plot X,S-3
   Line
   Plot R+5,S-2
   Plot R+6,Y
   Plot X,S-4
   Line
   Plot R+5,Y
   Plot X,S-6
   Line
   Plot R+1,Y
   Line
   Plot X,S-4
   Line
   Plot R,Y
   Plot R,S-2
   Line
   Plot R+1,Y
   Goto Z
   Lbl 6
   'White King
   Plot R+1,S-6
   Plot X,S-5
   Plot R,Y
   Plot R,S-3
   Line
   Plot R+1,Y
   Plot X,S
   Line
   Plot R+2,S-4
   Plot X,S-2
   Plot X,S
   Plot R+4,S
   Plot X,S-2
   Plot X,S-4
   Plot R+5,S
   Plot X,S-3
   Line
   Plot R+6,Y
   Plot X,S-5
   Line
   Plot R+5,Y
   Plot X,S-6
   Goto Z
   Lbl 7
   'Black Pawn
   Plot R+3,S-1
   Plot X,S-5
   Line
   Plot R+2,S-2
   Plot R+4,Y
   Plot R+2,S-5
   Plot R+4,Y
   Goto Z
   Lbl 8
   'Black Knight
   Plot R+4,S-1
   Plot X,S-5
   Line
   Plot R+5,Y
   Plot R+2,Y
   Line
   Plot R+5,S-2
   Line
   Plot R+2,Y
   Line
   Plot R+5,S-3
   Plot R+4,Y
   Goto Z
   Lbl 9
   'Black Bishop
   Plot R+2,S-5
   Plot R+5,Y
   Line
   Plot R+3,S-4
   Plot R+2,S-3
   Plot X,S-2
   Plot R+4,S-4
   Line
   Plot R+5,S-3
   Plot R+3,S-1
   Line
   Plot R+3,S
   Plot R+5,S-2
   Line
   Goto Z
   Lbl 0
   'Black Rook
   Plot R+1,S-5
   Plot R+5,Y
   Line
   Plot R+2,S-4
   Plot R+4,Y
   Line
   Plot R+2,S-3
   Plot R+4,Y
   Line
   Plot R+1,S-2
   Plot R+5,Y
   Line
   Plot R+1,S-1
   Plot R+3,Y
   Plot R+5,Y
   Goto Z
   Lbl A
   Plot R+3,S-2
   Goto Z
   Lbl B
   'King and Queen
   Plot R+2,S-5
   Plot R+4,Y
   Line
   Plot R+2,S-4
   Plot R+4,Y
   Line
   Plot R+1,S-3
   Plot R+3,Y
   Plot R+5,Y
   V=11=>Goto A
   Plot R+2,S-2
   Plot R+4,Y
   Goto Z
   Lbl Z
   Plot 0,0
   Plot 0,0
   Line
              
Program "CHGRID" [Draws the outline of the board]

   Range 1,127,0,1,63,0
   Plot 33,8
   Plot 33,Ymax
   Line
   Plot 90,Ymax
   Plot 90,8
   Line
   1->T~U
   Lbl 0
   Prog "CHCD"
   Isz T
   T<=8=>Goto 0
   Isz U
   1->T
   U<=8=>Goto 0
              
Program "CHPLMOVE" [Get and carry out player's move]

   P<>1=>Goto 6
   Plot 95,15
   Plot X,21
   Line
   Plot 93,19
   Plot 95,21
   Line
   Plot 97,19
   Line
   Goto 5
   Lbl 6
   Plot 95,56
   Plot X,50
   Line
   Plot 93,52
   Plot 95,50
   Line
   Plot 97,52
   Line
   Lbl 5
   0->A
   5->C~D
   Lbl 0
   Isz A
   Plot 7C+30,67-7D_
   Int ((X-27)/7->T
   Int ((70-Y)/7->U
   Prog D
   V<>0=>P(V-2\pi)<0=>A=2=>Goto 8
   A=2=>Goto 1
   V->B
   B=0=>Goto 5
   P(B-2\pi)>0=>Goto 5
   T->C
   U->D
   11->T
   Prog "CHCD"
   Goto 0
   Lbl 1
   T->E
   U->F
   Abs (B-4)<>3=>Goto 2
   F<>.5(9-7P=>Goto 2
   'Queening routine
   1->A
   Lbl 3
   B+5-A->V
   (-)1->T
   A->U
   Prog "CHCD"
   Isz A
   A<=4=>Goto 3
   Lbl 4
   Plot 19,60_
   Int ((70-Y)/7->T
   T>4=>Goto 4
   B+5-T->B
   Goto 7
   Lbl 2
   V<>0=>Goto 7
   Abs (B-9)<>3=>Goto 7
   C<>5=>Goto 7
   F<>D=>Goto 7
   F<>.5(9+7P=>Goto 7
   Abs (E-C)<>2=>Goto 7
   (7E-17)/4->T
   F->U
   Prog D
   Abs (V-7)<>3=>Goto 7
   P(V-7)>0=>Goto 7
   .5(E+5->T
   Prog D
   V<>0=>Goto 7
   2->T
   Prog D
   E=3=>V<>0=>Goto 7
   'Castling routine
   0->T
   (7E-17)/4+.5\i(9+7P->U
   Prog E
   7-3P->T
   \iImP U+.5(E+5->U
   Prog E
   Lbl 7
   0->T
   C+D\i->U
   Prog E
   B->T
   E+F\i->U
   Prog E
   (-)P->P
   Lbl 8
   Prog "CHGRID"
              
Program C (MATRIX) [Set up board]

   'CHINIT
   # *** ALL ONE LINE ***
   [[10,8,9,11,12,9,8,10][7,7,7,7,7,7,7,7][0,0,0,0,0,0,0,0][0,0,0,0,0,0,0,0]
     ...[0,0,0,0,0,0,0,0][0,0,0,0,0,0,0,0][1,1,1,1,1,1,1,1][4,2,3,5,6,3,2,4]]
     ...->Mat Z
   # ********************
              
Program D (MATRIX) [Find which piece is at position (T,U)]

   'CHGET
   U>=1=>U<=8=>T>=1=>T<=8=>Mat Z[U,T]->V
              
Program E (MATRIX) [Set piece at (ImP U, ReP U) to T]

   'CHSET
   T->Mat Z[ImP U,ReP U]
              


This page was created by Tom Lynn (tom-calcs@mythic-beasts.com).
This page last updated: Friday, 30 April, 1999

Written in notepad and compiled with WTA, for clean, consistent HTML.
Part of the Casio Graphical Calculator Encyclopaedia.

Best Viewed With Any Browser