1
0

changed ks/ftm to be more compliant with KS system

This commit is contained in:
acn 2020-04-21 16:16:06 +02:00
parent f5dda5d74d
commit 2266b9497c
3 changed files with 432 additions and 113 deletions

View File

@ -5,8 +5,7 @@
Derived from the plain CP/M version. Derived from the plain CP/M version.
Copyright (c) 2012-2020 Miguel Garcia / FloppySoftware, Spain. Copyright (c) 2012-2020 Miguel Garcia / FloppySoftware, Spain.
Color version by Anna Christina Naß <acn@acn.wtf>
VT100 color version by Anna Christina Naß <acn@acn.wtf>
This program is free software; you can redistribute it and/or modify it This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the under the terms of the GNU General Public License as published by the
@ -22,6 +21,12 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
Author's contact:
www.floppysoftware.es
cpm-connections.blogspot.com
floppysoftware@gmail.com
To compile with MESCC: To compile with MESCC:
cc ftm cc ftm
@ -29,6 +34,20 @@
zsm ftm zsm ftm
hextocom ftm hextocom ftm
Usage:
ftm [tty_name]
If no tty_name is given, VT100COL is
Revisions:
11 Sep 2012 : v1.0 : Initial version for Amstrad PCW & Samaruc GUI.
26 Jul 2013 : v1.2 : Adapted to Samaruc v1.5.
16 Feb 2014 : v1.3 : Adapted to last changes in Samaruc.
09 Jul 2014 : v1.4 : CP/M version.
07 Apr 2020 : v2.0 : Adapted to KS library for CP/M.
21 Apr 2020 : v2.1 : Added color option (by Anna Christina Naß <acn@acn.wtf>
Notes: Notes:
LEVELS: 1 2 3 NOTES LEVELS: 1 2 3 NOTES
@ -50,7 +69,7 @@
#include <ctype.h> #include <ctype.h>
#include <sprintf.h> #include <sprintf.h>
/* KS library /* KS libraries
*/ */
#include "ks.h" #include "ks.h"
@ -104,7 +123,32 @@ int argc, argv[]; /* char *argv[] - unsupported by MESCC */
/* Init KS /* Init KS
*/ */
KsHello(0); if(argc == 1) {
KsHello(KS_VT100COL);
}
else {
if(strcmp(argv[1], "/?")==0) {
tty_s = KsGetNames();
tty_n = KsGetHowMany();
puts("Usage: ftm [tty_name]\n");
puts("Supported TTY names:");
for(i = 0; i < tty_n; ++i) {
putchar('\t'); puts(tty_s[i]);
}
puts("If no tty_name is given, VT100COL (VT100 with color) is used.");
return;
}
else {
if(KsHello(KsGetCode(argv[1])) == -1) {
puts("Unknown TTY name.\n\nRun 'ftm' to know supported TTYs.\n");
return;
}
}
}
/* Setup /* Setup
*/ */
@ -123,7 +167,6 @@ int argc, argv[]; /* char *argv[] - unsupported by MESCC */
*/ */
Setup() Setup()
{ {
int i; BYTE *p; int i; BYTE *p;
/* Build array to help in calculation of adjacent squares /* Build array to help in calculation of adjacent squares
@ -159,21 +202,25 @@ Setup()
Copyright() Copyright()
{ {
int r; int r;
char str[80]; char str[100];
KsClear(); KsClear();
sprintf(str, "%sFind %sThat %sMine%s!%s\n", FGBRED, FGBCYN, FGBBLU, FGBYEL, RESET); if(KsCan(KS_CAN_COLOR)) {
KsPosCursor(r = 0, 32); //sprintf(str, "%sFind %sThat %sMine%s!%s\n", KsFgCol(RED), KsFgCol(CYN), KsFgCol(BLU), KsFgCol(YEL), KsResetAttr());
KsPutStr(str); KsPosCursor(r = 2, 32);
//KsCenterStr(r = 0, "Find That Mine!\n"); KsFgCol(BRED); KsPutStr("Find "); KsFgCol(BCYN); KsPutStr("That "); KsFgCol(BBLU); KsPutStr("Mine"); KsFgCol(BYEL); KsPutStr("!\n"); KsResetAttr();
KsCenterStr(++r , "v2.0 for CP/M & Z80\n\n"); }
else {
KsCenterStr(r = 2, "Find That Mine!\n");
}
KsCenterStr(++r , "v2.1 for CP/M & Z80\n\n");
++r; ++r;
KsCenterStr(++r ,"A minesweeper type game.\n"); KsCenterStr(++r ,"A minesweeper type game.\n");
++r; ++r;
KsCenterStr(++r ,"(c) 2012-2020 Miguel Garcia / Floppy Software, Spain.\n"); KsCenterStr(++r ,"(c) 2012-2020 Miguel Garcia / Floppy Software, Spain.\n");
KsCenterStr(++r ,"www.floppysoftware.es\n"); KsCenterStr(++r ,"www.floppysoftware.es\n");
KsCenterStr(++r ,"VT100 color version by acn@acn.wtf\n\n"); KsCenterStr(++r ,"color version by acn@acn.wtf\n\n");
} }
/* Select and play a level /* Select and play a level
@ -485,8 +532,11 @@ int row, col;
ShowBoard() ShowBoard()
{ {
int r, c; int r, c;
int col;
col = KsCan(KS_CAN_COLOR);
KsClear(); KsClear();
PrStr("\n\n");
PrStr("\t "); PrStr("\t ");
for(c = 0; c < brd_cols; ++c) { for(c = 0; c < brd_cols; ++c) {
@ -494,15 +544,20 @@ ShowBoard()
} }
PrCh('\n'); PrCh('\n');
PrStr(FGBGRY); if(col) KsFgCol(BBLK);
PrStr("\t "); PrCh(201); PrStr("\t +");
PrChTimes(205, brd_cols + brd_cols + 1); PrChTimes('-', brd_cols + brd_cols + 1);
PrCh(187); PrCh('\n'); PrCh('+'); PrCh('\n');
PrStr(RESET); if(col) KsResetAttr();
for(r = 0; r < brd_rows; ++r) for(r = 0; r < brd_rows; ++r)
{ {
PrCh('\t'); PrCh('0' + r); PrStr(FGBGRY); PrCh(186); PrStr(RESET); PrCh('\t'); PrCh('0' + r);
if(col) {
KsFgCol(BBLK); PrCh('|'); KsResetAttr();
}
else
PrCh('|');
for(c = 0; c < brd_cols; ++c) for(c = 0; c < brd_cols; ++c)
{ {
@ -511,37 +566,55 @@ ShowBoard()
if(TstVis(r, c)) if(TstVis(r, c))
{ {
if(GetCount(r, c)) { if(GetCount(r, c)) {
switch(GetCount(r, c)) if(col) {
{ switch(GetCount(r, c))
case 1: PrStr(FGBBLU); break; {
case 2: PrStr(FGGRN); break; case 1: KsFgCol(BBLU); break;
case 3: PrStr(FGBRED); break; case 2: KsFgCol(GRN); break;
case 4: PrStr(FGBLU); break; case 3: KsFgCol(BRED); break;
case 5: PrStr(FGRED); break; case 4: KsFgCol(BLU); break;
default: PrStr(FGCYN); break; case 5: KsFgCol(RED); break;
default: KsFgCol(CYN); break;
}
PrCh('0' + GetCount(r, c));
KsResetAttr();
} }
PrCh('0' + GetCount(r, c)); else
PrStr(RESET); PrCh('0' + GetCount(r, c));
} }
else { else
PrCh(SPR_BLANK); PrCh(SPR_BLANK);
}
} }
else if(gameover) else if(gameover)
{ {
if(TstMine(r, c)) { if(TstMine(r, c))
{
if(TstFlag(r, c)) { if(TstFlag(r, c)) {
PrStr(FGRED); PrCh(SPR_FLAG); PrStr(RESET); if(col) {
KsFgCol(RED);
PrCh(SPR_FLAG);
KsResetAttr();
} else
PrCh(SPR_FLAG);
} }
else { else {
PrStr(FGRED); PrCh(SPR_MINE); PrStr(RESET); if(col) {
KsFgCol(RED);
PrCh(SPR_MINE);
KsResetAttr();
} else
PrCh(SPR_MINE);
} }
} }
else if(TstFlag(r, c))
PrCh(SPR_ERR);
else { else {
if(TstFlag(r, c)) if(col) {
PrCh(SPR_ERR); KsFgCol(BBLK);
else PrCh(SPR_UNK);
PrStr(FGBGRY); PrCh(SPR_UNK); PrStr(RESET); KsResetAttr();
} else
PrCh(SPR_UNK);
} }
} }
else else
@ -555,16 +628,25 @@ ShowBoard()
PrCh(SPR_UNK); PrCh(SPR_UNK);
#else #else
if(TstFlag(r, c)) { if(TstFlag(r, c)) {
PrStr(FGRED); PrCh(SPR_FLAG); PrStr(RESET); if(col) KsFgCol(RED);
PrCh(SPR_FLAG);
if(col) KsResetAttr();
} }
else { else {
PrStr(FGBGRY); PrCh(SPR_UNK); PrStr(RESET); if(col) KsFgCol(BBLK);
PrCh(SPR_UNK);
if(col) KsResetAttr();
} }
#endif #endif
} }
} }
PrCh(' '); PrStr(FGBGRY); PrCh(186); PrStr(RESET); PrCh('0' + r); if(col) {
PrCh(' '); KsFgCol(BBLK); PrCh('|'); KsResetAttr(); PrCh('0' + r);
}
else {
PrCh(' '); PrCh('|'); PrCh('0' + r);
}
switch(r) switch(r)
{ {
@ -605,11 +687,11 @@ ShowBoard()
PrCh('\n'); PrCh('\n');
} }
PrStr(FGBGRY); if(col) KsFgCol(BBLK);
PrStr("\t "); PrCh(200); PrStr("\t +");
PrChTimes(205, brd_cols + brd_cols + 1); PrChTimes('-', brd_cols + brd_cols + 1);
PrCh(188); PrCh('\n'); PrCh('+'); PrCh('\n');
PrStr(RESET); if(col) KsResetAttr();
PrStr("\t "); PrStr("\t ");
for(c = 0; c < brd_cols; ++c) { for(c = 0; c < brd_cols; ++c) {

Binary file not shown.

View File

@ -1,18 +1,27 @@
/** /**
* KSvt100 * @file
* @brief Keyboard & screen functions library for CP/M & MESCC.
* *
* This library offers a common interface for keyboard and screen devices * This library offers a common interface for keyboard and screen devices
* using VT100 control codes * under CP/M.
* *
* This is a stripped down version of KS to only support VT100, but includes * Supported TTYs:
* color codes * - KS_VT52 for generic VT52 80x24
* - KS_VT100 for generic VT100 80x25
* - KS_PCW for Amstrad PCW 90x31
* - KS_CPC for Amstrad CPC 24x80 under CP/M Plus
* - KS_SPECTRUM for Spectrum +3 51x23
* - KS_KAYPRO for Kaypro 24x80
*
* Capabilities:
* - KS_CAN_HIDE can hide & show cursor
* - KS_CAN_REVERSE can reverse text
* - KS_CAN_UNDERLINE can underline text
*/ */
/* ks.h /* ks.h
Keyboard & screen functions library for CP/M & MESCC - Mike's Enhanced Small C Compiler. Keyboard & screen functions library for CP/M & MESCC - Mike's Enhanced Small C Compiler.
Stripped down version for VT100+color by Anna Christina Naß <acn@acn.wtf>
Copyright (c) 2016, 2017 Miguel I. Garcia Lopez / FloppySoftware, Spain Copyright (c) 2016, 2017 Miguel I. Garcia Lopez / FloppySoftware, Spain
@ -29,45 +38,82 @@
You should have received a copy of the GNU General Public License You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
Author's contact:
www.floppysoftware.es
cpm-connections.blogspot.com
floppysoftware@gmail.com
Revisions:
03 Sep 2016 : Work begins.
29 Sep 2016 : Rename functions.
03 Oct 2016 : Reworked KsInit() and others. Added support for reverse and underline.
14 Jul 2017 : Added TTY names.
07 Apr 2020 : TTY names in uppercase.
08 Apr 2020 : Added KsGetNames(), KsGetHowMany().
*/ */
int xks_rows = 25; // Screen rows /* Public defines
int xks_cols = 80; // Screen columns --------------
BYTE *xks_clrscr = "\e[H\e[J"; // Clear screen */
BYTE *xks_poscur = "\e[%r;%cH"; // Position cursor #define KS_VT52 0
BYTE *xks_shwcur = "\e[?25h"; // Show cursor #define KS_VT100 1
BYTE *xks_hidcur = "\e[?25l"; // Hide cursor #define KS_PCW 2
BYTE *xks_yrever = "\e[7m"; // Reverse on #define KS_CPC 3
BYTE *xks_nrever = "\e[m"; // Reverse off #define KS_SPECTRUM 4
BYTE *xks_yuline = "\e[4m"; // Underline on #define KS_KAYPRO 5
BYTE *xks_nuline = "\e[m"; // Underline off #define KS_VT100COL 6
#define RESET "\e[0m" // reset all attributes #define KS_CAN_HIDE 0 // Can hide & show cursor
#define FGBLK "\e[30m" // black #define KS_CAN_REVERSE 1 // Can reverse text
#define FGRED "\e[31m" // red #define KS_CAN_UNDERLINE 2 // Can underline text
#define FGGRN "\e[32m" // green #define KS_CAN_COLOR 3 // Can display color
#define FGYEL "\e[33m" // yellow
#define FGBLU "\e[34m" // blue
#define FGMAG "\e[35m" // magenta
#define FGCYN "\e[36m" // cyan
#define FGWHT "\e[37m" // white/gray
#define FGBGRY "\e[30;1m" // gray ("bright black")
#define FGBRED "\e[31;1m" // bright red
#define FGBGRN "\e[32;1m" // bright green
#define FGBYEL "\e[33;1m" // bright yellow
#define FGBBLU "\e[34;1m" // bright blue
#define FGBMAG "\e[35;1m" // bright magenta
#define FGBCYN "\e[36;1m" // bright cyan
#define FGBWHT "\e[37;1m" // bright white
#define BGBLK "\e[40m" // black
#define BGRED "\e[41m" // red
#define BGGRN "\e[42m" // green
#define BGYEL "\e[43m" // yellow
#define BGBLU "\e[44m" // blue
#define BGMAG "\e[45m" // magenta
#define BGCYN "\e[46m" // cyan
#define BGWHT "\e[47m" // white
/* Define color numbers
--------------------
*/
// usable as foreground + background colors:
#define BLK 0 // black
#define RED 1 // red
#define GRN 2 // green
#define YEL 3 // yellow
#define BLU 4 // blue
#define MAG 5 // magenta
#define CYN 6 // cyan
#define WHT 7 // gray
// the following colors are "bright" colors, these do not work as background colors
#define BBLK 8 // dark gray ("bright black")
#define BRED 9 // bright red
#define BGRN 10 // bright green
#define BYEL 11 // bright yellow
#define BBLU 12 // bright blue
#define BMAG 13 // bright magenta
#define BCYN 14 // bright cyan
#define BWHT 15 // bright white
/* Private defines
---------------
*/
#define XKS_TTYS 7 // Number of supported TTYs
/* Private globals
---------------
*/
WORD xks_names[XKS_TTYS]; // TTY names by code -- char *xks_names[]
int xks_rows; // Screen rows
int xks_cols; // Screen columns
BYTE *xks_clrscr; // Clear screen
BYTE *xks_poscur; // Position cursor
BYTE *xks_shwcur; // Show cursor
BYTE *xks_hidcur; // Hide cursor
BYTE *xks_yrever; // Reverse on
BYTE *xks_nrever; // Reverse off
BYTE *xks_yuline; // Underline on
BYTE *xks_nuline; // Underline off
int xks_color; // TTY can display color
/** /**
* @fn int KsHello(char *tty_name) * @fn int KsHello(char *tty_name)
@ -81,6 +127,73 @@ int code;
{ {
// Setup BIOS jumps, etc. // Setup BIOS jumps, etc.
xKsInit(); xKsInit();
xks_color = FALSE;
// Setup TTY
switch(code) {
case KS_VT52 :
xKsInit24x80();
xks_clrscr = "\eH\eJ";
xks_poscur = "A\eY%r%c";
break;
case KS_VT100 :
xks_rows = 25;
xks_cols = 80;
xks_clrscr = "\e[H\e[J";
xks_poscur = "B\e[%r;%cH";
xks_yrever = "\e[7m";
xks_nrever = "\e[m";
xks_yuline = "\e[4m";
xks_nuline = "\e[m";
break;
case KS_PCW :
xks_rows = 31;
xks_cols = 90;
xKsInitAmstrad();
break;
case KS_CPC :
xKsInit24x80();
xKsInitAmstrad();
break;
case KS_SPECTRUM :
xks_rows = 23;
xks_cols = 51;
xKsInitAmstrad();
KsPutRawCh('\e'); KsPutRawCh('3'); KsPutRawCh(1);
break;
case KS_KAYPRO :
xKsInit24x80();
xks_clrscr = "?"; *xks_clrscr = 26; // ^Z
xks_poscur = "A\e=%r%c";
break;
case KS_VT100COL :
xks_rows = 25;
xks_cols = 80;
xks_clrscr = "\e[H\e[J";
xks_poscur = "B\e[%r;%cH";
xks_shwcur = "\e[?25h";
xks_hidcur = "\e[?25l";
xks_yrever = "\e[7m";
xks_nrever = "\e[m";
xks_yuline = "\e[4m";
xks_nuline = "\e[m";
xks_color = TRUE;
break;
default :
// Unknown tty code
return -1;
}
// Success
return 0; return 0;
} }
@ -104,12 +217,21 @@ KsBye()
KsGetCode(name) KsGetCode(name)
char *name; char *name;
{ {
if(strcmp(name, "VT100")) { int i;
return 0;
} if(!xks_names[0]) {
else { xKsNames();
return -1;
} }
for(i = 0; i < XKS_TTYS; ++i) {
if(!strcmp(name, xks_names[i])) {
// Found
return i;
}
}
// Unknown tty name
return -1;
} }
/** /**
@ -122,12 +244,17 @@ char *name;
KsGetName(code) KsGetName(code)
int code; int code;
{ {
if(code==0) { if(!xks_names[0]) {
return "VT100"; xKsNames();
} }
else {
return NULL; if(code >= 0 && code < XKS_TTYS) {
// Found
return xks_names[code];
} }
// Unknown tty code
return NULL;
} }
/** /**
@ -138,8 +265,10 @@ int code;
*/ */
KsGetNames() KsGetNames()
{ {
WORD xks_names[1]; if(!xks_names[0]) {
xks_names[0] = "VT100"; xKsNames();
}
return xks_names; return xks_names;
} }
@ -151,7 +280,7 @@ KsGetNames()
*/ */
KsGetHowMany() KsGetHowMany()
{ {
return 1; return XKS_TTYS;
} }
/** /**
@ -174,17 +303,44 @@ int row, col;
{ {
char *p; int v; char *p; int v;
for(p = xks_poscur; *p; ++p) { for(p = xks_poscur + 1; *p; ++p) {
if(*p != '%') { if(*p != '%') {
KsPutRawCh(*p); KsPutRawCh(*p);
} }
else { else {
v = (*(++p) == 'r' ? row : col); v = (*(++p) == 'r' ? row : col);
xKsPutDec(1 + v);
if(*xks_poscur == 'A') {
// A
KsPutRawCh(32 + v);
}
else {
// B
xKsPutDec(1 + v);
}
} }
} }
} }
/**
* @fn int KsCan(int cap)
* @brief Check if the TTY has a capability.
* @param cap - capatility code
* @return 0 on NO, other on YES
*/
KsCan(cap)
int cap;
{
switch(cap) {
case KS_CAN_HIDE : return xks_shwcur != NULL;
case KS_CAN_REVERSE : return xks_yrever != NULL;
case KS_CAN_UNDERLINE : return xks_yuline != NULL;
case KS_CAN_COLOR : return xks_color;
}
return 0;
}
/** /**
* @fn void KsSetCursor(int toggle) * @fn void KsSetCursor(int toggle)
* @brief Show or hide the cursor on screen. * @brief Show or hide the cursor on screen.
@ -226,6 +382,68 @@ int toggle;
} }
} }
/**
* @fn char *KsFgCol(int color)
* @brief Set foreground color
* If the TTY does not have this capability, does nothing.
* @param color - color number, see #defines
*/
KsFgCol(color)
int color;
{
char rc[12];
if(xks_color) {
if(color<8) {
sprintf(rc, "\e[3%dm", color);
KsPutStr(rc);
}
if(color>=8) {
sprintf(rc, "\e[3%d;1m", color-8); // bright colors begin at 8
KsPutStr(rc);
}
}
}
/**
* @fn void KsBgCol(int color)
* @brief Set background color
* If the TTY does not have this capability, does nothing.
* @param color - color number, see #defines
*/
KsBgCol(color)
int color;
{
char str[6];
if(xks_color) {
sprintf(str, "\e[4%dm", color);
KsPutStr(str);
}
}
/**
* @fn void KsResetAttr()
* If the TTY does not support color, does nothing
* @brief Resets all attributes
*/
KsResetAttr()
{
if(xks_color)
KsPutStr("\e[m");
}
/**
* @fn void KsCenterStr(int row, char *s)
* @brief Print a string centered on screen.
* @param row - screen row
* @param s - string
*/
KsCenterStr(row, s)
int row; char *s;
{
KsPosCursor(row, (KsGetCols() - strlen(s)) / 2);
KsPutStr(s);
}
/** /**
* @fn int KsGetRows(void) * @fn int KsGetRows(void)
* @brief Get TTY rows. * @brief Get TTY rows.
@ -246,19 +464,6 @@ KsGetCols()
return xks_cols; return xks_cols;
} }
/**
* @fn void KsCenterStr(int row, char *s)
* @brief Print a string centered on screen.
* @param row - screen row
* @param s - string
*/
KsCenterStr(row, s)
int row; char *s;
{
KsPosCursor(row, (KsGetCols() - strlen(s)) / 2);
KsPutStr(s);
}
/** /**
* @fn void KsPutRawCh(int ch) * @fn void KsPutRawCh(int ch)
* @brief Send a character to the TTY. * @brief Send a character to the TTY.
@ -364,6 +569,38 @@ xKsConOut
jp 0 ; BIOS ConOut jp 0 ; BIOS ConOut
#endasm #endasm
// void xKsNames(void) : Set TTY names.
xKsNames()
{
xks_names[KS_VT52] = "VT52";
xks_names[KS_VT100] = "VT100";
xks_names[KS_PCW] = "PCW";
xks_names[KS_CPC] = "CPC";
xks_names[KS_SPECTRUM] = "SPECTRUM";
xks_names[KS_KAYPRO] = "KAYPRO";
xks_names[KS_VT100COL] = "VT100COL";
}
// void xKsInit24x80(void) : Set TTY to 24 rows and 80 columns.
xKsInit24x80()
{
xks_rows = 24;
xks_cols = 80;
}
// void xKsInitAmstrad(void) : Set generic Amstrad mode.
xKsInitAmstrad()
{
xks_clrscr = "\eH\eE";
xks_poscur = "A\eY%r%c";
xks_shwcur = "\ee";
xks_hidcur = "\ef";
xks_yrever = "\ep";
xks_nrever = "\eq";
xks_yuline = "\er";
xks_nuline = "\eu";
}
// void xKsPutDec(int num) : Send positive decimal number to TTY. // void xKsPutDec(int num) : Send positive decimal number to TTY.
xKsPutDec(num) xKsPutDec(num)
int num; int num;