TI99 Environment

CALL_HCHARSPRITE


Syntax

CALL_HCHARSPRITE(sprite-number,row,column)

Description

The HCHARSPRITE function converts parameters row and column into sprite Y and X respectively and places the sprite represented by sprite-number at those coordinates.

A value of 1 for row indicates the top of the screen. A value of 24 is the bottom of the screen.
A value of 1 for column indicates the left side of the screen. A value of 32 is the right side of the screen.

  Example Code
TYPE ChessBoardType
    ChessAlgebraRow as integer    ` 1-8
    ChessAlgebraCol as string     ` A-H
    ChessPieceNum as integer      ` 1 = w pawn, 2 = w knight, 3 = w bishop, 4 = w rook, 5 = w queen, 6 = w king, (+ 6 = black pieces)    
    ChessPieceColor as integer    ` 0 = no piece, 1 = white, 2 = black
ENDTYPE

Type ChessPieceType
   ChessPieceName as string      ` P-Pawn, N-Knight, B-Bishop, R-Rook, Q-Queen, K-King
   ChessPieceValue as integer    ` 1 = pawn, 3 = knight/bishop,  5 = rook, 9 = queen, 99 = king
ENDTYPE
`
global boardrow = 4
global boardcol = 8
global style = 0 
`
global arrowrow = boardrow  : global arrowy = 0 
global arrowcol = boardcol : global arrowx = 0 
global squarerow = boardrow
global squarecol = boardcol

Dim ChessBoard(8,8) as ChessBoardType

gosub _CreateGraphics
gosub _InitChessBoard
ChessDisplayBoard(boardrow,boardcol,style)
tiwaitkey()
end

_CreateGraphics:
`Defines graphic images and colors for chess pieces and board
call_magnify(3)
Pawn$="00000000000103070301030303070F00000000000080C0E0C080C0C0C0E0F000"
Knight$="00000406070D1F372F190307070F1F0000004060E0F0F0F0F0F0F0F0F8FCFC00"
Bishop$="00000103070D0E0F07030303070F1F0000000080C0E0E060C0808080C0E0F000"
Rook$="00000D0D0F0F0F0606070606070F1F000000B0B0F0F0F06060E06060E0F0F800"
Queen$="000A0F0F0F0703071F0F07070F1F3F0000A0E0E0E0C080C0F0E0C0C0E0F0F800"
King$="00010301070F0F071F070303070F1F000080C080E0F0F0E0F8E0C0C0E0F0F800"
square$="FF8080808080808080808080808080FFFF0101010101010101010101010101FF"
arrow$="007C70785C4E06"
PawnChar=128 
KnightChar=132 
BishopChar=136 
RookChar=140 
QueenChar=144
KingChar=148 
global WSquareChar = 152 
global BSquareChar = 156 
global arrowchar=160 : global arrowcolor = 7 : global arrowsprite = 1
global squarechar = 164 : global squareorigcolor = 14 : global squarecolor = squareorigcolor : global squaresprite = 41 : global squarealtcolor = 4`highlight square 
global WSquareColor = 16 : global BSquareColor = 5
`
call_char(PawnChar,Pawn$)      
call_char(KnightChar,Knight$)   
call_char(BishopChar,Bishop$) 
call_char(RookChar,Rook$)
call_char(QueenChar,Queen$)
call_char(KingChar,King$)       
call_char(arrowchar,arrow$)      
call_char(squarechar,square$)
`
call_char(WSquareChar,rpt$("f",64)) : 
call_char(BSquareChar,rpt$("f",64)) 
for i = 0 to 3
   call_colorchar(WSquareChar + i,WSquareColor,1) `White square
   call_colorchar(BSquareChar + i,BSquareColor,1)  `Black square
next i

return
`
_InitChessBoard:
`Places chess pieces in array
WPawn = 1 : BPawn = 7
WKnight = 2 : BKnight = 8
WBishop = 3 : BBishop = 9
WRook = 4 : BRook = 10
WQueen = 5 : BQueen = 11
WKing = 6 : BKing = 12

WPieceColor = 15
BPieceColor = 2

TopRow = 1
TopPawnRow = 2
BottomRow = 8
BottomPawnRow = 7
` Initialize Pieces on Board
`Top Row Pieces
ChessBoard(TopRow,1).ChessPieceNum = BRook
ChessBoard(TopRow,2).ChessPieceNum = BKnight
ChessBoard(TopRow,3).ChessPieceNum = BBishop
ChessBoard(TopRow,4).ChessPieceNum = BQueen
ChessBoard(TopRow,5).ChessPieceNum = BKing
ChessBoard(TopRow,6).ChessPieceNum = BBishop
ChessBoard(TopRow,7).ChessPieceNum = BKnight
ChessBoard(TopRow,8).ChessPieceNum = BRook

// `Bottom Row Pieces
ChessBoard(BottomRow,1).ChessPieceNum = WRook
ChessBoard(BottomRow,2).ChessPieceNum = WKnight
ChessBoard(BottomRow,3).ChessPieceNum = WBishop
ChessBoard(BottomRow,4).ChessPieceNum = WQueen
ChessBoard(BottomRow,5).ChessPieceNum = WKing
ChessBoard(BottomRow,6).ChessPieceNum = WBishop
ChessBoard(BottomRow,7).ChessPieceNum = WKnight
ChessBoard(BottomRow,8).ChessPieceNum = WRook

`Black and White Pawns
for c = 1 to 8
   ChessBoard(TopPawnRow,c).ChessPieceNum = BPawn
   ChessBoard(BottomPawnRow,c).ChessPieceNum = WPawn
next c

`Initialize rest of the board with empty spaces
for r = 3 to 6
  for c = 1 to 8
`     ChessBoard(r,c).ChessPieceColor = 0
     ChessBoard(r,c).ChessPieceNum = 0      
     ChessBoard(r,c).ChessAlgebraRow = 0   
     ChessBoard(r,c).ChessAlgebraCol = ""    
  next c
next r 
spritechess = 2
for r = 1 to 8
   for c = 1 to 8
      if ChessBoard(r,c).ChessPieceNum > 0
         if ChessBoard(r,c).ChessPieceNum > 0 and ChessBoard(r,c).ChessPieceNum < 7 then  piececolor = WPieceColor
         if ChessBoard(r,c).ChessPieceNum > 6 then piececolor = BPieceColor
         if ChessBoard(r,c).ChessPieceNum = WPawn or ChessBoard(r,c).ChessPieceNum = BPawn then spritechar = PawnChar
         if ChessBoard(r,c).ChessPieceNum = WKnight or ChessBoard(r,c).ChessPieceNum = BKnight then spritechar = KnightChar
         if ChessBoard(r,c).ChessPieceNum = WBishop or ChessBoard(r,c).ChessPieceNum = BBishop then spritechar = BishopChar
         if ChessBoard(r,c).ChessPieceNum = WRook or ChessBoard(r,c).ChessPieceNum = BRook then spritechar = RookChar
         if ChessBoard(r,c).ChessPieceNum = WQueen or ChessBoard(r,c).ChessPieceNum = BQueen then spritechar = QueenChar
         if ChessBoard(r,c).ChessPieceNum = WKing or ChessBoard(r,c).ChessPieceNum = BKing then spritechar = KingChar 
         call_sprite(spritechess,spritechar,piececolor,1,1,0,0)
         CALL_HCHARSPRITE(spritechess,boardrow + (r - 1) * 2,boardcol + (c - 1) * 2)
         inc spritechess
      endif
   next c
next r
return
`
function ChessDisplayBoard(row,col,style)
for r = 0 to 15 step 4 : for c = 0 to 15 step 4
   call_hchar(row+r, col + c, WSquareChar, 2)
   call_hchar(row+r+1, col + c, WSquareChar, 2)
   
   call_hchar(row+r + 2, col + c, BSquareChar, 2)
   call_hchar(row+r + 3, col + c, BSquareChar, 2)
   
   call_hchar(row+r, col + c + 2, BSquareChar, 2)
   call_hchar(row+r + 1, col + c + 2, BSquareChar, 2)
   
   call_hchar(row+r + 2, col + c + 2, WSquareChar, 2)
   call_hchar(row+r + 3, col + c + 2, WSquareChar, 2)

next c : next r
arrowy = arrowrow * 8 - 7
arrowx = arrowcol * 8 - 7
position mouse arrowx + 1,arrowy + 1
call_sprite(arrowsprite,arrowchar,arrowcolor,arrowy,arrowx,0,0)
Call_sprite(squaresprite,squarechar,squarecolor,arrowy,arrowx,0,0)
ti_sync()
endfunction


Go back to ...

TI99E Commands Menu
Main Menu

Copyright © Carlos Santiago Lebron - TI99 Environment 2020