diff --git a/Makefile b/Makefile index c91d8fa..57c37fc 100644 --- a/Makefile +++ b/Makefile @@ -149,11 +149,11 @@ TARGETOBJDIR := $(OBJDIR)/$(TARGETS) # Default emulator commands and options for particular targets. # Set EMUCMD to override. -c64_EMUCMD := $(VICE_HOME)x64 -kernal kernal -VICIIdsize -autostart +c64_EMUCMD := $(VICE_HOME)x64sc -kernal kernal -VICIIdsize -autostart c128_EMUCMD := $(VICE_HOME)x128 -kernal kernal -VICIIdsize -autoload vic20_EMUCMD := $(VICE_HOME)xvic -kernal kernal -VICdsize -autoload pet_EMUCMD := $(VICE_HOME)xpet -Crtcdsize -autoload -plus4_EMUCMD := $(VICE_HOME)xplus4 -TEDdsize -autoload +plus4_EMUCMD := $(VICE_HOME)xplus4 -TEDdsize -autostart # So far there is no x16 emulator in VICE (why??) so we have to use xplus4 with -memsize option c16_EMUCMD := $(VICE_HOME)xplus4 -ramsize 16 -TEDdsize -autoload cbm510_EMUCMD := $(VICE_HOME)xcbm2 -model 510 -VICIIdsize -autoload diff --git a/readme.txt b/readme.txt index f0454a8..a7442c7 100644 --- a/readme.txt +++ b/readme.txt @@ -1,5 +1,6 @@ 0. Updates +* Oct 2023 - Added a version for the Plus4. * Jul 2020 - Added a version for the Atari. * May 2020 - Advanced Build instructions at XI. * May 2020 - I created a version for the Commander X16 (R37). diff --git a/src/plus4/chessPlus4.cfg b/src/plus4/chessPlus4.cfg new file mode 100644 index 0000000..b7199e0 --- /dev/null +++ b/src/plus4/chessPlus4.cfg @@ -0,0 +1,43 @@ +FEATURES { + STARTADDRESS: default = $1001; +} +SYMBOLS { + __LOADADDR__: type = import; + __EXEHDR__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __HIMEM__: type = weak, value = $FD00; +} +MEMORY { + ZP: file = "", define = yes, start = $0002, size = $001A; + LOADADDR: file = %O, start = %S - 2, size = $0002; + HEADER: file = %O, define = yes, start = %S, size = $000D; + MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __MAIN_START__ - __STACKSIZE__; +} +SEGMENTS { + ZEROPAGE: load = ZP, type = zp; + LOADADDR: load = LOADADDR, type = ro; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + ONCE: load = MAIN, type = ro, optional = yes; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = bss; + BSS: load = MAIN, type = bss, define = yes; +} +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = ONCE; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; +} diff --git a/src/plus4/dataPlus4.c b/src/plus4/dataPlus4.c new file mode 100644 index 0000000..04e1b2c --- /dev/null +++ b/src/plus4/dataPlus4.c @@ -0,0 +1,202 @@ +/* + * dataPlus4.c + * cc65 Chess + * + * Created by Stefan Wessels, February 2014. + * + */ + +#include "../types.h" +#include "dataPlus4.h" + +/*-----------------------------------------------------------------------*/ +// Plus4 (C64) specific graphics for the chess pieces + +// The comment shows an icon 16x24 +// The data is 24 chars & 24 chars (2 * 8x24). The second set of 24 +// is the right-hand side 8-bits of the icon + +// 96 = 4 cols * 3 rows * 8 byte / col +const char gfxTiles[PAWN][2][96] = +{ + { + { + 0x00, 0x00, 0x00, 0x03, 0x02, 0x02, 0x02, 0x02, + 0x00, 0x00, 0x00, 0xC7, 0x44, 0x44, 0x7C, 0x00, + 0x00, 0x00, 0x00, 0xC7, 0x44, 0x44, 0x7C, 0x00, + 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x80, 0x5F, 0x60, 0x20, 0x20, 0x20, 0x20, + 0x01, 0x02, 0xF4, 0x0C, 0x08, 0x08, 0x08, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x00, + 0x20, 0x40, 0x80, 0xBF, 0x00, 0xFF, 0xFF, 0x00, + 0x08, 0x04, 0x02, 0xFA, 0x01, 0xFF, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x03, + 0x00, 0x00, 0x00, 0xC7, 0xC7, 0xC7, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0xC7, 0xC7, 0xC7, 0xFF, 0xFF, + 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0x7F, 0x40, 0x3F, 0x3F, 0x3F, 0x3F, + 0xFF, 0xFE, 0xFC, 0x04, 0xF8, 0xF8, 0xF8, 0xF8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x00, + 0x3F, 0x7F, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, + 0xF8, 0xFC, 0xFE, 0xFE, 0x01, 0xFF, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, + }, + }, + { + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x15, 0x21, 0x20, 0x40, + 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x02, 0x02, 0x01, 0x00, + 0x44, 0x40, 0x80, 0x00, 0x00, 0x1E, 0x21, 0xC2, + 0x28, 0x28, 0x34, 0x14, 0x04, 0x04, 0x16, 0x1A, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x08, 0x10, 0x20, 0x5F, 0x40, 0x7F, 0x00, + 0x09, 0x05, 0x01, 0x00, 0xFE, 0x00, 0xFF, 0x00, + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x08, 0x15, 0x3E, 0x3F, 0x7F, + 0x00, 0x00, 0x00, 0x80, 0x40, 0xE0, 0xF0, 0xF8, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x01, 0x00, + 0x7B, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xE1, 0xC3, + 0xD8, 0xD8, 0xCC, 0xEC, 0xFC, 0xFC, 0xEE, 0xE6, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x0F, 0x1F, 0x3F, 0x40, 0x7F, 0x7F, 0x00, + 0xF7, 0xFB, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, + 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, + }, + }, + { + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0x08, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x20, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x21, 0x2F, 0x41, 0x41, 0x41, 0x21, 0x20, 0x10, + 0x08, 0xE8, 0x04, 0x04, 0x04, 0x08, 0x08, 0x10, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x0F, 0x08, 0x08, 0x07, 0x20, 0xFF, 0xFF, 0x00, + 0xE0, 0x20, 0x20, 0xC0, 0x08, 0xFE, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0x0F, 0x1E, + 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x3E, 0x30, 0x7E, 0x7E, 0x7E, 0x3E, 0x3F, 0x1F, + 0xF8, 0x18, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, + 0x08, 0x0F, 0x0F, 0x07, 0x3F, 0x80, 0xFF, 0x00, + 0x20, 0xE0, 0xE0, 0xC0, 0xF8, 0x02, 0xFF, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, + { + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x04, 0xE4, 0x12, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x40, 0x4E, 0x91, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x02, 0x02, 0x02, 0x02, 0x02, 0x01, 0x01, 0x00, + 0x14, 0x28, 0x00, 0x21, 0x33, 0x1F, 0x0F, 0x80, + 0x50, 0x28, 0x00, 0x08, 0x98, 0xF1, 0xE1, 0x02, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x80, 0xBF, 0x40, 0x40, 0x40, 0x60, 0x3F, 0x00, + 0x02, 0xFA, 0x04, 0x04, 0x04, 0x0C, 0xF8, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x03, 0x07, 0xE7, 0xF3, + 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xCE, 0x9F, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x00, + 0xF7, 0xEF, 0xFF, 0xDE, 0xCC, 0xE0, 0xF0, 0xFF, + 0xDF, 0xEF, 0xFF, 0xF7, 0x67, 0x0F, 0x1F, 0xFE, + 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xFF, 0xC0, 0x7F, 0x7F, 0x7F, 0x7F, 0x3F, 0x00, + 0xFE, 0x06, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, + { + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x02, 0x0E, 0x0C, 0x32, + 0x00, 0x00, 0x00, 0x80, 0x80, 0xE0, 0x60, 0x98, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x02, 0x01, + 0x4A, 0x86, 0x02, 0x24, 0x42, 0x41, 0x21, 0x10, + 0xA4, 0xC2, 0x81, 0x49, 0x84, 0x04, 0x08, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x80, 0x9F, 0x40, 0x40, 0x60, 0x3F, 0x00, + 0x21, 0x02, 0xF2, 0x04, 0x04, 0x0C, 0xF8, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x02, 0x0E, 0x0C, 0x32, + 0x00, 0x00, 0x00, 0x80, 0x80, 0xE0, 0x60, 0x98, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x01, 0x01, 0x03, 0x03, 0x03, 0x01, + 0x7A, 0xFE, 0xFC, 0xDA, 0xBC, 0xBE, 0xDF, 0xEF, + 0xBC, 0xFE, 0x7F, 0xB7, 0x7B, 0xFB, 0xF7, 0xEF, + 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x00, + 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xF7, 0xFF, 0xC0, 0x7F, 0x7F, 0x7F, 0x3F, 0x00, + 0xDF, 0xFE, 0x06, 0xFC, 0xFC, 0xFC, 0xF8, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, + { + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x04, 0x08, 0x08, 0x08, 0x04, 0x03, 0x04, 0x04, + 0x40, 0x20, 0x20, 0x20, 0x40, 0x80, 0x40, 0x40, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0C, 0x04, 0x04, 0x0F, 0x10, 0x3F, 0x3F, 0x00, + 0x60, 0x40, 0x40, 0xE0, 0x10, 0xF8, 0xF8, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x07, 0x0F, 0x0F, 0x0F, 0x07, 0x03, 0x07, 0x07, + 0xC0, 0xE0, 0xE0, 0xE0, 0xC0, 0x80, 0xC0, 0xC0, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x0F, 0x07, 0x07, 0x0F, 0x10, 0x3F, 0x3F, 0x00, + 0xE0, 0xC0, 0xC0, 0xE0, 0x10, 0xF8, 0xF8, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + }, + }, +}; diff --git a/src/plus4/dataPlus4.h b/src/plus4/dataPlus4.h new file mode 100644 index 0000000..cc4fc78 --- /dev/null +++ b/src/plus4/dataPlus4.h @@ -0,0 +1,14 @@ +/* + * dataPlus4.h + * cc65 Chess + * + * Created by Stefan Wessels, February 2014. + * + */ + +#ifndef _DATA_H_ +#define _DATA_H_ + +extern const char gfxTiles[PAWN][2][96]; + +#endif //_DATA_H_ \ No newline at end of file diff --git a/src/plus4/genpieces.cpp b/src/plus4/genpieces.cpp new file mode 100644 index 0000000..d731a15 --- /dev/null +++ b/src/plus4/genpieces.cpp @@ -0,0 +1,360 @@ +/* + * genPieces.cpp + * cc65 Chess + * + * Created by Oliver Schmidt, January 2020. + * Pieces designed by Frank Gebhart, 1980s. + * Modified for C64 by S. Wessels, May 2020. + * + */ + +#include +#ifdef _WIN32 +#include +#else +#include +#endif + +#include +#include + +char pieces[]= +" " +" " +" **** ***** **** " +" * * * * * * " +" * * * * * * " +" * ***** ***** * " +" * * " +" * * " +" * * " +" * ********* * " +" ** ** " +" * * " +" * * " +" * * " +" * * " +" * * " +" * * " +" * * " +" * *********** * " +" * * " +" ******************* " +" ******************* " +" " +" " +" " +" " +" **** ***** **** " +" **** ***** **** " +" **** ***** **** " +" ******************* " +" ******************* " +" ***************** " +" *************** " +" ************* " +" * * " +" *********** " +" *********** " +" *********** " +" *********** " +" *********** " +" ************* " +" *************** " +" *************** " +" * * " +" ******************* " +" ******************* " +" " +" " +" " +" " +" * * " +" * * * * " +" * * * " +" * * " +" * * " +" * * * * " +" * * * " +" * ** * " +" * * * " +" * * " +" * **** * " +" * * * * ** " +" ** * ** * " +" * * * " +" * * * " +" * ** " +" * * " +" * ************ * " +" * * " +" **************** " +" " +" " +" " +" " +" * * " +" * * * * " +" ***** *** " +" ********** " +" ************ " +" **** **** ** " +" ********* ** " +" ********** ** " +" ************ ** " +" **************** " +" **************** " +" **** **** *** " +" ** ***** ** " +" ******* *** " +" ********* ** " +" ************** " +" *************** " +" * * " +" **************** " +" **************** " +" " +" " +" " +" " +" " +" *** " +" * * " +" * * " +" * * * " +" * * * " +" * ******* * " +" * * * " +" * * * " +" * * * " +" * * * " +" * * " +" * * " +" ******* " +" * * " +" * * " +" ***** " +" * * " +" *************** " +" ***************** " +" " +" " +" " +" " +" " +" *** " +" ***** " +" ******* " +" **** **** " +" ***** ***** " +" ** ** " +" ****** ****** " +" ****** ****** " +" ****** ****** " +" ***** ***** " +" *********** " +" ********* " +" * * " +" ******* " +" ******* " +" ***** " +" *********** " +" * * " +" ***************** " +" " +" " +" " +" " +" " +" *** " +" * * " +" *** * * *** " +" * * * * * * " +" * * * * * * " +" * * * * * * " +" * * " +" * * * * * " +" * ** *** ** * " +" * ********* * " +" * ******* * " +" * * " +" * * " +" * *********** * " +" * * " +" * * " +" * * " +" ** ** " +" *********** " +" " +" " +" " +" " +" " +" *** " +" ***** " +" *** ***** *** " +" ***** *** ***** " +" ****** ***** ****** " +" ***** ******* ***** " +" ******************* " +" **** **** **** **** " +" **** ** ** **** " +" **** **** " +" ***** ***** " +" *************** " +" *************** " +" ** ** " +" ************* " +" ************* " +" ************* " +" ************* " +" *********** " +" " +" " +" " +" " +" *** " +" * * " +" *** *** " +" ** ** " +" ** * * ** " +" * * * * * * " +" * ** ** * " +" * * * * " +" * * * * * * " +" * * * * * * " +" * * * * * " +" * * * * * " +" * * * * " +" * * * * " +" * * " +" * ********* * " +" * * " +" * * " +" ** ** " +" *********** " +" " +" " +" " +" " +" *** " +" * * " +" *** *** " +" ** ** " +" ** * * ** " +" **** * * **** " +" ******* ******* " +" ******* ******* " +" *** ** * * ** *** " +" *** **** **** *** " +" *** ***** ***** *** " +" **** ********* **** " +" **** ******* **** " +" ***** ***** ***** " +" *************** " +" ** ** " +" ************* " +" ************* " +" ************* " +" *********** " +" " +" " +" " +" " +" " +" " +" " +" " +" *** " +" * * " +" * * " +" * * " +" * * " +" * * " +" *** " +" * * " +" * * " +" ** ** " +" * * " +" * * " +" ******* " +" * * " +" *********** " +" *********** " +" " +" " +" " +" " +" " +" " +" " +" " +" *** " +" ***** " +" ******* " +" ******* " +" ******* " +" ***** " +" *** " +" ***** " +" ***** " +" ******* " +" ***** " +" ***** " +" ******* " +" * * " +" *********** " +" *********** " +" " +" " +; + +int main(void) +{ + int i, j, k; + unsigned int c[8] ; + + memset(c,0,sizeof(c)); + j = k = 0; + printf("const char gfxTiles[PAWN][2][96] = \n{\n"); + for(i=0; i> (8*(3-x))) & 0xff; + printf("0x%02X, ", v); + } + } + printf("\n\t\t},\n"); + if(2==k) + { + printf("\t},\n"); + k = 0; + } + j = 0; + for(y=0;y<8;y++) + { + c[y] = 0; + } + } + } + } + printf("};\n"); + + return 0; +} diff --git a/src/plus4/hiresPlus4.s b/src/plus4/hiresPlus4.s new file mode 100644 index 0000000..112f554 --- /dev/null +++ b/src/plus4/hiresPlus4.s @@ -0,0 +1,395 @@ + +; hiresPlus4.s +; cc65 Chess +; +; Created by Stefan Wessels, May 2020. +; +;----------------------------------------------------------------------- + +.include "zeropage.inc" + +;----------------------------------------------------------------------- +.export _plat_gfxFill, _plat_showStrXY, _plat_showPiece, _plat_colorStringXY, _plat_colorFill +.import popa + +;----------------------------------------------------------------------- +.define BITMAP_ADDRESS $A000 +.define LUMINANCE_ADDERSS $0800 +.define COLOR_ADDERSS LUMINANCE_ADDERSS+$0400 +.define CHARMAP_RAM BITMAP_ADDRESS+$2000 + +;----------------------------------------------------------------------- +.code + +;----------------------------------------------------------------------- +; Utility - Turn tmp2 (y) and tmp3 (x) into a pointer in ptr2 that points +; in BITMAP_ADDRESS with x, y being col and row with col and row being +; 8 pixels +.proc plat_ptr2AtHgrXY + + lda tmp2 ; load y + asl ; ptr2 points at start with 320 = 256 + 64 so + asl ; y in hi + 64 * y in lo/hi + COLOR_ADDERSS hi = address + asl + asl + rol ptr2 + 1 + asl + rol ptr2 + 1 + asl + rol ptr2 + 1 + sta ptr2 + lda tmp2 ; add y in hi + adc ptr2 + 1 + adc #>(BITMAP_ADDRESS) ; and vic ram in hi (vic ram aligned, lo = 0) + sta ptr2 + 1 ; ptr2 now points at the correct row + + stx tmp2 ; re-use tmp2, clear for possible carry + lda tmp3 ; x * 8 is offset into row where this col starts + asl + asl + asl + rol tmp2 + adc ptr2 + sta ptr2 + lda tmp2 + adc ptr2 + 1 + sta ptr2 + 1 ; ptr2 now points at the start address on-screen, incl. x + + rts + +.endproc + +;----------------------------------------------------------------------- +; Utility - Turn tmp2 (y) and ptr1 (x) into a pointer in ptr1 that points +; at COLOR_ADDERSS[x+y*40] +.proc plat_ptr2AtScrXY + + lda tmp2 ; load y + asl ; * 32 + asl + asl + asl + rol ptr1 + 1 + asl + rol ptr1 + 1 + adc ptr1 ; add x in + sta ptr1 + bcc :+ + inc ptr1 + 1 +: + lda tmp2 ; start with y + asl ; 8 * + 32 * = 40 * + asl + asl + adc ptr1 + sta ptr1 + lda ptr1 + 1 + adc #>(COLOR_ADDERSS) ; add screen ram hi as lo is $0 (aligned) + sta ptr1 + 1 + + rts + +.endproc + +;----------------------------------------------------------------------- +; void plat_gfxFill(char fill, char x, char y, char w, char h) +; where y & h are multiples of 8 and x and w are in columns (i.e. +; bytes not pixels). Fill the 8x8 aligned rectangle with fill. +.proc _plat_gfxFill + + sta tmp1 ; h + + ldx #0 + stx ptr1 + 1 ; prep ptr1 hi for possible carry + stx ptr2 + 1 ; prep ptr2 hi for possible carry + + jsr popa ; w + asl ; w * 8 - w in cols and 8 bytes per col till next col + asl + asl + rol ptr1 + 1 ; ptr1 now contains number of bytes to fill per row + sta ptr1 + + jsr popa + sta tmp2 ; y in tmp2 + jsr popa + sta tmp3 ; x in tmp3 + jsr plat_ptr2AtHgrXY + + sec ; calculate (320 - width) as the "stride" + lda #$40 + sbc ptr1 + sta tmp2 + lda #1 + sbc ptr1 + 1 + sta tmp3 + + jsr popa ; fill + sta tmp4 + + ; sei ; stop interrupts + ; lda 1 ; kernel out + ; and #$FD + ; sta 1 + +loop: + lda tmp4 + ldy ptr1 + 1 ; check hi byte of width to fill + beq low ; width totals less than 256 bytes, no hi copy + ldy #0 ; fill 256 bytes +: + sta (ptr2), y + dey + bne :- + inc ptr2 + 1 ; adjust the write pointer by 256 bytes + +low: + ldy ptr1 ; get the low bytes top copy + beq rowdone ; if none left to copy then row is done +: + dey + sta (ptr2), y ; write the block of bytes < 256 + bne :- + +rowdone: + dec tmp1 ; one more row done + beq done ; when wrap all rows are done + clc + lda ptr1 + adc ptr2 + bcc :+ + inc ptr2 + 1 + clc +: + adc tmp2 ; add stride to get to next row + sta ptr2 + lda tmp3 + adc ptr2 + 1 + sta ptr2 + 1 + bne loop ; bra + +done: + ; lda 1 ; kernel in + ; ora #$02 + ; sta 1 + ; cli ; resume interrupts + + rts + +.endproc + +;----------------------------------------------------------------------- +; void plat_colorFill(char color, char x, char y, char w, char h) +; Fills a rectangle in COLOR_ADDERSS with color. +.proc _plat_colorFill + + sta tmp1 ; h + + lda #0 + sta ptr1 + 1 ; prep ptr2 hi for possible carry + + jsr popa ; w + sta tmp3 + + jsr popa + sta tmp2 ; y in tmp2 + jsr popa + sta ptr1 ; x in tmp3 + jsr plat_ptr2AtScrXY + + jsr popa ; color + sta tmp2 + +loop: + lda tmp2 + ldy tmp3 ; get the low bytes top copy + beq rowdone ; if none left to copy then row is done +: + dey + sta (ptr1), y ; write the color + bne :- + +rowdone: + dec tmp1 ; one more row done + beq done ; when wrap all rows are done + lda ptr1 + adc #$28 + sta ptr1 + bcc loop + inc ptr1 + 1 + clc + bne loop ; bra + +done: + rts +.endproc + +;----------------------------------------------------------------------- +; void plat_showStrXY(char x, char Y, char *str) +; Display the string pointed at by str in hires using the character set +; which must be located at CHARACTER_RAM. This must be Set 2 which +; includes lower case characters +.proc _plat_showStrXY + + sta ptr1 + stx ptr1 + 1 + + ldx #0 + stx ptr2 + 1 ; init hi value for possibly shifting carry into + + jsr popa + sta tmp2 ; y in tmp2 + jsr popa + sta tmp3 ; x in tmp3 + jsr plat_ptr2AtHgrXY + + ; sei ; stop interrupts + ; lda 1 ; kernel out + ; and #$FD + ; sta 1 + + ldy #0 + sty tmp2 +loop: + ldy tmp2 + lda (ptr1), y ; character + beq done + cmp #'z' + bpl :+ + and #63 +: + and #127 + ldy #7 + ldx #0 + stx read + 2 + asl ; *8 for bytes + rol read + 2 + asl + rol read + 2 + asl + rol read + 2 + sta read + 1 + lda #>(CHARMAP_RAM) + adc read + 2 + sta read + 2 +read: + lda $ffff, y + sta (ptr2), y + dey + bpl read + lda ptr2 + adc #8 + sta ptr2 + bcc :+ + inc ptr2 + 1 + clc +: + inc tmp2 + bne loop + +done: + ; lda 1 ; kernel in + ; ora #$02 + ; sta 1 + ; cli ; resume interrupts + rts + +.endproc + +;----------------------------------------------------------------------- +; void plat_colorStringXY(char color, char x, char y, char *str) +; Uses str only for length. Writes color into COLOR_ADDERSS at +; COLOR_ADDERSS[i+x+y*40] where i iterates the string [while(str[i]) i++]. +.proc _plat_colorStringXY + + sta ptr2 ; store the str pointer in ptr2 + stx ptr2 + 1 + + lda #0 ; clear ptr1 hi for carry + sta ptr1 + 1 + + jsr popa ; y + sta tmp2 ; save y in tmp 2 + jsr popa ; x + sta ptr1 ; save x in ptr1 lo + jsr plat_ptr2AtScrXY + + jsr popa ; get the color + tax ; save it in x + ldy #0 ; start at 0 +: + lda (ptr2), y + beq done ; as long as string has a valid character + txa ; put color in a + sta (ptr1), y ; and write to COLOR_ADDERSS + iny + bne :- + +done: + rts + +.endproc + +;----------------------------------------------------------------------- +; void plat_showPiece(char x, char Y, const char *src) +; copies 3 * 32 consecutive bytes from src to a rectangle in VIC RAM at x, y +; The rect is 4 bytes by 24 bytes (rows) so 96 bytes total +.proc _plat_showPiece + + sta ptr1 ; store the pointer to the piece + stx ptr1 + 1 + + ldx #0 ; plat_ptr2AtHgrXY assumes x = 0 + stx ptr2 + 1 ; init hi value for possibly shifting carry into + + jsr popa + sta tmp2 ; y in tmp2 + jsr popa + sta tmp3 ; x in tmp3 + jsr plat_ptr2AtHgrXY ; calculate offset into ptr2 + + ; sei ; stop interrupts + ; lda 1 ; kernel out + ; and #$FD + ; sta 1 + + lda #3 ; need to do 3 loops for a whole piece + sta tmp1 + +loop: + ldy #31 ; 32 bytes to copy +: + lda (ptr1), y ; load src + eor (ptr2), y ; merge with dest + sta (ptr2), y ; save at dest + dey + bpl :- ; do all 32 + + dec tmp1 ; another 3rd done + beq done ; all done? + + lda ptr1 ; more to do - move src data ptr along by 32 + adc #32 + sta ptr1 + bcc :+ + clc + inc ptr1 + 1 +: + lda ptr2 ; move graphics pointer along by 320 (row down) + adc #<320 + sta ptr2 + lda ptr2 + 1 + adc #>320 + sta ptr2 + 1 + bne loop ; bra + +done: + ; lda 1 ; kernel in + ; ora #$02 + ; sta 1 + ; cli ; resume interrupts + + rts + +.endproc + diff --git a/src/plus4/platPlus4.c b/src/plus4/platPlus4.c new file mode 100644 index 0000000..013ba99 --- /dev/null +++ b/src/plus4/platPlus4.c @@ -0,0 +1,566 @@ +/* + * platPlus4.c + * cc65 Chess + * + * Created by Stefan Wessels, February 2014. + * + */ + +#include +#include +#include +#include +#include "../types.h" +#include "../globals.h" +#include "../undo.h" +#include "../frontend.h" +#include "../plat.h" +#include "dataPlus4.h" + +/*-----------------------------------------------------------------------*/ +// System locations +#define BITMAP_ADDRESS (0xA000) +#define LUMINANCE_ADDERSS (0x0800) +#define COLOR_ADDERSS (LUMINANCE_ADDERSS + 0x0400) +#define CHARMAP_ROM (0xD400) +#define CHARMAP_RAM (BITMAP_ADDRESS + 0x2000) + +/*-----------------------------------------------------------------------*/ +#define BOARD_PIECE_WIDTH 4 +#define BOARD_PIECE_HEIGHT 3 +#define SCREEN_WIDTH 40 +#define SCREEN_HEIGHT 25 +#define COLOR_OFFSET 0 +#define SCROLL_SPEED 0x00f0 + +/*-----------------------------------------------------------------------*/ +// Internal function Prototype +char plat_TimeExpired(unsigned int aTime, char *timerInit); + +/*-----------------------------------------------------------------------*/ +// Function Prototype for functions in hires.s +void plat_gfxFill(char fill, char x, char y, char w, char h); +void plat_colorFill(char color, char x, char y, char w, char h); +void plat_showStrXY(char x, char y, char *str); +void plat_colorStringXY(char color, char x, char y, char *str); +void plat_showPiece(char x, char Y, const char *src); + +/*-----------------------------------------------------------------------*/ +// Local storage +static char t_bcol, t_bgco, t_colo, t_vscr, t_hscr, t_misc, t_vide; +char textStr[41]; +static char subMenu; + +/*-----------------------------------------------------------------------*/ +// Called one-time to set up the platform (or computer or whatever) +void plat_Init() +{ + // Clearly something I don't understand here. If I make the loop counter an + // int, or even another char I define, this all stops working. + char a, b, c; + for(gReturnToOS = 0; gReturnToOS < 255; gReturnToOS++) { + TED.enable_rom = 1; + a = *((char*)(CHARMAP_ROM+gReturnToOS)); + b = *((char*)(CHARMAP_ROM+256+gReturnToOS)); + c = *((char*)(CHARMAP_ROM+512+gReturnToOS)); + TED.enable_ram = 0; + *((char*)(CHARMAP_RAM+gReturnToOS)) = a; + *((char*)(CHARMAP_RAM+256+gReturnToOS)) = b; + *((char*)(CHARMAP_RAM+512+gReturnToOS)) = c; + } + + // Setting this to 0 will not show the "Quit" option in the main menu + gReturnToOS = 1; + + if(gReturnToOS) + { + // Save these values so they can be restored + t_bcol = TED.bordercolor; + t_bgco = TED.bgcolor; + t_colo = TED.color1; + t_vscr = TED.vscroll; + t_hscr = TED.hscroll; + t_misc = TED.misc; + t_vide = TED.video_addr; + } + + // Move the cursor to the lower right since cursor(0) doesn't seem to work. + gotoxy(39,24); + // This doesn't appear to work + cursor(0); + + TED.bordercolor = COLOR_GREEN; + TED.bgcolor = BCOLOR_GREEN | CATTR_LUMA4; + TED.color1 = BCOLOR_BLACK; + TED.vscroll &= ~0b00010000; + + // Set the location of the bitmap + TED.misc = (TED.misc & 0b11000001) | (BITMAP_ADDRESS >> 0x0A); + // Set the location of the luminance and color + TED.video_addr = (TED.video_addr & 0b00000111) | (LUMINANCE_ADDERSS >> 0x08); + + // Clear all pixels on the screen + plat_gfxFill(0,0,0,40,25); + + // set the base screen color on green + // memset(SCREEN_RAM, COLOR_WHITE<<4|COLOR_GREEN, 0x400); + memset((char*)LUMINANCE_ADDERSS, CATTR_LUMA3 | CATTR_LUMA7>>4, 0x400); + memset((char*)COLOR_ADDERSS, BCOLOR_WHITE<<4 | BCOLOR_GREEN, 0x400); + + // Show the welcome text + strcpy(textStr, "Commodore 64 graphics version, 2020."); + plat_showStrXY(2,SCREEN_HEIGHT/2-1, gszAbout); + plat_showStrXY(2,SCREEN_HEIGHT/2+1,textStr); + plat_colorStringXY(COLOR_BLACK<<4|COLOR_GREEN,2,SCREEN_HEIGHT/2+1,textStr); + + // Set the color for the black king + plat_colorFill(COLOR_BLACK<<4|COLOR_GREEN ,SCREEN_WIDTH/2 - 1, SCREEN_HEIGHT/2 - 6, 4, 3); + // Show the welcome kings (black and white, solid versions) + plat_showPiece(SCREEN_WIDTH/2 - 1, SCREEN_HEIGHT/2 - 6, gfxTiles[KING-1][1]); + plat_showPiece(SCREEN_WIDTH/2 - 1, SCREEN_HEIGHT/2 + 4, gfxTiles[KING-1][1]); + + // hack to make the menu not flash (no when dimming into sub-menus) + subMenu = 0; + + // Un-blank the screen + TED.vscroll |= 0b00110000; + + plat_ReadKeys(1); +} + +/*-----------------------------------------------------------------------*/ +// This is not needed on the C64 +void plat_UpdateScreen() +{ +} + +/*-----------------------------------------------------------------------*/ +// Very simple menu with a heading and a scrolling banner as a footer +char plat_Menu(char **menuItems, char height, char *scroller) +{ + static char *prevScroller, *pScroller, *pEnd; + int keyMask; + char i, sx, sy, numMenuItems, timerInit = 0, maxLen = 0; + + // Darken the chessboard so the menu "pops" + if(!subMenu++) + plat_colorFill(COLOR_GRAY1<<4,1,1,32,24); + + // If the scroller message chages, cache the new one + if(prevScroller != scroller) + { + prevScroller = scroller; + pScroller = scroller; + pEnd = scroller + strlen(scroller); + } + + // Find the longest entry + for(numMenuItems=0; menuItems[numMenuItems]; ++numMenuItems) + { + char len = strlen(menuItems[numMenuItems]); + if(len > maxLen) + maxLen = len; + } + + // Centre on the screen + sy = MAX_SIZE(0, (SCREEN_HEIGHT / 2) - (height / 2) - 1); + sx = MAX_SIZE(0, (SCREEN_WIDTH / 2) - (maxLen / 2) - 1); + maxLen = MIN_SIZE(SCREEN_WIDTH-2, maxLen); + + // Draw and color a frame + plat_gfxFill(0xAA , sx-1 , sy-1 , maxLen+4 , 1 ); + plat_gfxFill(0xAA , sx-1 , sy , 1 , height+3 ); + plat_gfxFill(0xAA , sx+maxLen+2, sy , 1 , height+3 ); + plat_gfxFill(0xAA , sx , sy+height+2, maxLen+2 , 1 ); + + plat_colorFill(COLOR_YELLOW<<4, sx-1 , sy-1 , maxLen+4 , 1 ); + plat_colorFill(COLOR_YELLOW<<4, sx-1 , sy , 1 , height+3 ); + plat_colorFill(COLOR_YELLOW<<4, sx+maxLen+2, sy , 1 , height+3 ); + plat_colorFill(COLOR_YELLOW<<4, sx , sy+height+2, maxLen+2 , 1 ); + + + // Show the title + sprintf(textStr, " %.*s ",38, menuItems[0]); + plat_showStrXY(sx, sy, textStr); + plat_colorStringXY(COLOR_YELLOW<<4|COLOR_BLUE, sx, sy, textStr); + + // Leave a blank line + sprintf(textStr, "%-*s", maxLen+2," "); + plat_showStrXY(sx, ++sy, textStr); + plat_colorStringXY(COLOR_BLUE, sx, sy, textStr); + + // Show all the menu items + for(i=1; i%.*s<",maxLen, menuItems[i]); + plat_showStrXY(sx, sy+i, textStr); + plat_colorStringXY(COLOR_WHITE<<4|COLOR_BLUE, sx, sy+i, textStr); + + // Look for user input + keyMask = plat_ReadKeys(0); + + if(keyMask & INPUT_MOTION) + { + // selection changes so de-highlight the selected item + sprintf(textStr, " %.*s ",maxLen, menuItems[i]); + plat_showStrXY(sx, sy+i, textStr); + plat_colorStringXY(COLOR_GRAY2<<4|COLOR_BLUE, sx, sy+i, textStr); + + // see if the selection goes up or down + switch(keyMask & INPUT_MOTION) + { + case INPUT_UP: + if(!--i) + i = numMenuItems-1; + break; + + case INPUT_DOWN: + if(numMenuItems == ++i) + i = 1; + break; + } + } + keyMask &= (INPUT_SELECT | INPUT_BACKUP); + + // Show the scroller + sprintf(textStr, " %.*s ",maxLen, pScroller); + plat_showStrXY(sx, sy+height, textStr); + + // Wrap the message if needed + if((pEnd - pScroller) < maxLen-1) + { + sprintf(textStr, " %.*s ",maxLen-(pEnd - pScroller)-1, scroller); + plat_showStrXY(sx+(pEnd-pScroller)+1, sy+height, textStr); + } + + // Only update the scrolling when needed + if(plat_TimeExpired(SCROLL_SPEED, &timerInit)) + { + ++pScroller; + if(!*pScroller) + pScroller = scroller; + } + } while(keyMask != INPUT_SELECT && keyMask != INPUT_BACKUP); + + // if backing out of the menu, return 0 + if(keyMask & INPUT_BACKUP) + return 0; + + // return the selection + return i; +} + +/*-----------------------------------------------------------------------*/ +// Draw the chess board and possibly clear the log section +void plat_DrawBoard(char clearLog) +{ + char i; + + // Not in a menu when drawBoard is called + subMenu = 0; + + if(clearLog) + { + // Clear the log area pixels and color to green + plat_gfxFill(0,33,0,7,25); + plat_colorFill(COLOR_GREEN,33,0,7,25); + } + + // set the left and top margin row/col to clear & green + plat_colorFill(COLOR_GREEN,0,0,33,1); + plat_colorFill(COLOR_GREEN,0,0,1,25); + + // redraw all tiles + for(i=0; i<64; ++i) + { + plat_DrawSquare(i); + } + + // Add the A..H and 1..8 tile-keys + for(i=0; i<8; ++i) + { + // Print the letters and numbers in Black on Green + sprintf(textStr, "%c",'A'+i); + plat_showStrXY(2+i*BOARD_PIECE_WIDTH, 0, textStr); + plat_colorStringXY(COLOR_BLACK<<4|COLOR_GREEN,2+i*BOARD_PIECE_WIDTH, 0, textStr); + + sprintf(textStr, "%d",8-i); + plat_showStrXY(0, 2+i*BOARD_PIECE_HEIGHT, textStr); + plat_colorStringXY(COLOR_BLACK<<4|COLOR_GREEN,0, 2+i*BOARD_PIECE_HEIGHT, textStr); + } +} + +/*-----------------------------------------------------------------------*/ +// Draw a tile with background and piece on it for positions 0..63 +void plat_DrawSquare(char position) +{ + char index; + char piece, color; + char y = position / 8, x = position & 7; + char blackWhite = !((x & 1) ^ (y & 1)); + + // Draw the boatrd square + plat_gfxFill(blackWhite ? 0xff : 0x0, 1 + x * BOARD_PIECE_WIDTH, 1 + y * BOARD_PIECE_HEIGHT, BOARD_PIECE_WIDTH, BOARD_PIECE_HEIGHT); + plat_colorFill(COLOR_WHITE<<4 , 1 + x * BOARD_PIECE_WIDTH, 1 + y * BOARD_PIECE_HEIGHT, BOARD_PIECE_WIDTH, BOARD_PIECE_HEIGHT); + + // Get the piece data to draw the piece over the tile + piece = gChessBoard[y][x]; + color = piece & PIECE_WHITE; + piece &= PIECE_DATA; + + if(piece) + { + index = 1; + if((color && blackWhite) || (!color && !blackWhite)) + index = 0; + plat_showPiece(1 + x * BOARD_PIECE_WIDTH, y * BOARD_PIECE_HEIGHT + 1, gfxTiles[piece-1][index]); + } + + // Show the attack numbers + if(gShowAttackBoard) + { + char piece_value = (gChessBoard[y][x] & 0x0f); + char piece_color = (gChessBoard[y][x] & PIECE_WHITE) >> 7; + + // Attackers (bottom left) + sprintf(textStr, "%d",(gpAttackBoard[giAttackBoardOffset[position][0]])); + plat_showStrXY(1+x*BOARD_PIECE_WIDTH,(y+1)*BOARD_PIECE_HEIGHT, textStr); + plat_colorStringXY((piece_color ? COLOR_RED : COLOR_GREEN)<<4,1+x*BOARD_PIECE_WIDTH,(y+1)*BOARD_PIECE_HEIGHT, textStr); + + // Defenders (bottom right) + sprintf(textStr, "%d",(gpAttackBoard[giAttackBoardOffset[position][1]])); + plat_showStrXY(1+x*BOARD_PIECE_WIDTH+3,(y+1)*BOARD_PIECE_HEIGHT, textStr); + plat_colorStringXY((!piece_color ? COLOR_RED : COLOR_GREEN)<<4,1+x*BOARD_PIECE_WIDTH+3,(y+1)*BOARD_PIECE_HEIGHT, textStr); + + // Color (0 is black, 128 is white) and piece value (1=ROOK, 2=KNIGHT, 3=BISHOP, 4=QUEEN, 5=KING, 6=PAWN) + sprintf(textStr, "%0d",piece_value); + plat_showStrXY(1+x*BOARD_PIECE_WIDTH,1+y*BOARD_PIECE_HEIGHT, textStr); + plat_colorStringXY(COLOR_PURPLE<<4,1+x*BOARD_PIECE_WIDTH,1+y*BOARD_PIECE_HEIGHT, textStr); + + // Color + sprintf(textStr, "%d",piece_color); + plat_showStrXY(1+x*BOARD_PIECE_WIDTH+3,1+y*BOARD_PIECE_HEIGHT, textStr); + plat_colorStringXY((piece_color ? COLOR_WHITE : COLOR_GRAY1)<<4,1+x*BOARD_PIECE_WIDTH+3,1+y*BOARD_PIECE_HEIGHT, textStr); + } +} + +/*-----------------------------------------------------------------------*/ +void plat_ShowSideToGoLabel(char side) +{ + // Show Black or White + sprintf(textStr, "%s",gszSideLabel[side]); + plat_showStrXY(2+8*BOARD_PIECE_WIDTH, 0, textStr); + plat_colorStringXY((side ? COLOR_WHITE : COLOR_BLACK)<<4|COLOR_GREEN, 2+8*BOARD_PIECE_WIDTH, 0, textStr); +} + +/*-----------------------------------------------------------------------*/ +void plat_Highlight(char position, char color, char) +{ + char y = position / 8, x = position & 7; + char white = !((x & 1) ^ (y & 1)); + + // White pieces need the foreground color set, black the background color + if(white) + color <<= 4; + + // turn position into a board based offset + x *= BOARD_PIECE_WIDTH; + y *= BOARD_PIECE_HEIGHT; + + // The board is 1 line down from the top + y++; + + // Draw the two vertical bars - the "cursor" + plat_colorFill(color, x + 1 , y, 1, BOARD_PIECE_HEIGHT); + plat_colorFill(color, x + BOARD_PIECE_WIDTH, y, 1, BOARD_PIECE_HEIGHT); + +} + +/*-----------------------------------------------------------------------*/ +void plat_ShowMessage(char *str, char) +{ + // Always an error message - illegal move or no more undo/redo + sprintf(textStr, "%.*s",SCREEN_WIDTH-1-(8*BOARD_PIECE_WIDTH),str); + plat_showStrXY(1+(8*BOARD_PIECE_WIDTH), SCREEN_HEIGHT-1, textStr); + plat_colorStringXY(COLOR_RED<<4|COLOR_GREEN, 1+(8*BOARD_PIECE_WIDTH), SCREEN_HEIGHT-1, textStr); +} + +/*-----------------------------------------------------------------------*/ +void plat_ClearMessage() +{ + // Erase the message from ShowMessage + sprintf(textStr, "%-*s",SCREEN_WIDTH-1-8*BOARD_PIECE_WIDTH," "); + plat_showStrXY((8*BOARD_PIECE_WIDTH)+1, (8*BOARD_PIECE_HEIGHT), textStr); +} + +/*-----------------------------------------------------------------------*/ +void plat_AddToLogWin() +{ + char bot = (8*BOARD_PIECE_HEIGHT)-2, y = 1, x = 2+(8*BOARD_PIECE_WIDTH); + char i = 0; + + // Show a log of the moves that have been played + for(; y<=bot; ++y) + { + if(undo_FindUndoLine(bot-y)) + { + frontend_FormatLogString(); + sprintf(textStr, "%-6s",gLogStrBuffer); + plat_showStrXY(x, y, textStr); + plat_colorStringXY((gColor[0] ? COLOR_WHITE : COLOR_BLACK)<<4|COLOR_GREEN, x, y, textStr); + } + else + { + sprintf(textStr, "%-*s",SCREEN_WIDTH-x," "); + plat_showStrXY(x, y, textStr); + } + } +} + +/*-----------------------------------------------------------------------*/ +// Important note about this function is that it alters the gTile... +// global data trackers so beware when calling it +void plat_AddToLogWinTop() +{ + // This redraws the whole log window so just call it + plat_AddToLogWin(); +} + +/*-----------------------------------------------------------------------*/ +// Use timer 1 to time a duration +char plat_TimeExpired(unsigned int aTime, char *timerInit) +{ + static unsigned int h = 0xffff; + unsigned int t = *(int*)&TED.t1_lo; + if(!*timerInit || t < aTime || t > h) + { + *timerInit = 1; + + TED.t1_lo = 0xFF; + TED.t1_hi = 0xFF; + h = 0xffff; + + return 1; + } + else + { + h = t; + } + return 0; +} + +/*-----------------------------------------------------------------------*/ +int plat_ReadKeys(char blocking) +{ + char key = 0; + int keyMask = 0; + + if(blocking || kbhit()) + key = cgetc(); + else + return 0; + + switch(key) + { + case 145: // Up + keyMask |= INPUT_UP; + break; + + case 29: // Right + keyMask |= INPUT_RIGHT; + break; + + case 17: // Down + keyMask |= INPUT_DOWN; + break; + + case 157: // Left + keyMask |= INPUT_LEFT; + break; + + case 3: // Esc + keyMask |= INPUT_BACKUP; + break; + + case 65: // 'a' - Show Attackers + keyMask |= INPUT_TOGGLE_A; + break; + + case 66: // 'b' - Board attacks - Show all attacks + keyMask |= INPUT_TOGGLE_B; + break; + + case 68: // 'd' - Show Defenders + keyMask |= INPUT_TOGGLE_D; + break; + + case 77: // 'm' - Menu + keyMask |= INPUT_MENU; + break; + + case 13: // Enter + keyMask |= INPUT_SELECT; + break; + + case 82: + keyMask |= INPUT_REDO; + break; + + case 85: + keyMask |= INPUT_UNDO; + break; + + // default: // Debug - show key code + // { + // char s[] = "Key:000"; + // s[4] = (key/100)+'0'; + // key -= (s[4] - '0') * 100; + // s[5] = (key/10)+'0'; + // s[6] = (key%10)+'0'; + // plat_ShowMessage(s,COLOR_RED); + // } + break; + } + + return keyMask; +} + +/*-----------------------------------------------------------------------*/ +// Only gets called if gReturnToOS is true, which it isn't +void plat_Shutdown() +{ + // restore Plus4 specific hardware values + TED.bordercolor = t_bcol; + TED.bgcolor = t_bgco; + TED.color1 = t_colo; + TED.vscroll = t_vscr; + TED.hscroll = t_hscr; + TED.misc = t_misc; + TED.video_addr = t_vide; + clrscr(); + + // Bank in the ROM + TED.enable_rom = 1; + cursor(1); +}