diff --git a/FindThatMine/README.md b/FindThatMine/README.md new file mode 100644 index 0000000..46be2f5 --- /dev/null +++ b/FindThatMine/README.md @@ -0,0 +1,74 @@ +# Find That Mine! + +A MineSweeper clon game for CP/M + +VT100 color version by Anna Christina Naß +Based on v2.0 - 07 April 2020. + +Copyright (c) 2012-2020 Miguel Garcia / FloppySoftware, Spain. + +The original repository can be found here: +https://github.com/MiguelVis/ftm + +## Introduction + +This is a clone (yes, one more!) of MineSweeper for CP/M with supported CRTs, +derived from the plain CP/M version (and itself from the Amstrad PCW +& Samaruc GUI version). + +It should run in any version of the CP/M operating system and a Z80 CPU. + +This version is patched to work with a VT100 terminal only and it uses +color ANSI codes. + +## The game + +The aim of the game is to find all the mines on the board, putting a flag on +them and uncovering the other squares. + +If you uncover a mine, you lose the game. + +There are three different levels: +* Level 1 : 08 x 08 squares, 08 mines +* Level 2 : 08 x 12 squares, 12 mines +* Level 3 : 08 x 16 squares, 16 mines + + +## How to play + +In the board, a number on a square means the quantity of mines around it. + +To uncover a square, you must enter a command telling its position as row and column - ie: +``` +1C +``` + +To put or remove a flag on a square, you must append a F character to the command - ie: +``` +3DF +``` + +## Technical notes + +To compile, use MESCC, "Mike's Enhanced Small C Compiler". +All files neccessary (and only these) to compile the game are included. +The complete package of MESCC can be found in its repository: + +See: https://github.com/MiguelVis/mescc + +Compile it using: + + CC FTM + CCOPT FTM + ZSM FTM + HEXTOCOM FTM + +## License + +This software is copyright of Miguel Garcia / FloppySoftware, Spain. All rights +reserved. + +This program is freeware, and it's licensed under the GNU General Public License. + +See the license file for more details. + diff --git a/FindThatMine/ftm.c b/FindThatMine/ftm.c new file mode 100644 index 0000000..567b5be --- /dev/null +++ b/FindThatMine/ftm.c @@ -0,0 +1,766 @@ +/* FIND THAT MINE! + + A MineSweeper clone for CRTs and CP/M. + + Derived from the plain CP/M version. + + Copyright (c) 2012-2020 Miguel Garcia / FloppySoftware, Spain. + + VT100 color version by Anna Christina Naß + + 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 + Free Software Foundation; either version 3, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + + To compile with MESCC: + + cc ftm + ccopt ftm + zsm ftm + hextocom ftm + + Notes: + + LEVELS: 1 2 3 NOTES + + ROWS: 8 8 8 + COLS: 8 12 16 + SQUARES: 64 96 128 ROWS * COLS + MINES: 8 12 16 SQUARES / 8 (1 MINES EACH 8 SQUARES) +*/ + +/* Do you want debug tools? +*/ +#define DEBUG_MINES 0 + +/* MESCC libraries +*/ +#include +#include +#include +#include + +/* KS library +*/ +#include "ks.h" + +/* DEFs for BOARD +*/ +#define MAX_ROWS 8 /* Max. number of rows */ +#define MAX_COLS 16 /* Max. number of columns */ +#define MAX_SQ 128 /* Max. number of squares (MAX_ROWS * MAX_COLS) */ +#define MAX_BUF 512 /* MAX_SQ * 4 */ + +/* DEFs for SPRITES +*/ +#define SPR_MINE '*' /* Mine */ +#define SPR_FLAG 'P' /* Flag */ +#define SPR_UNK '?' /* Unknown */ +#define SPR_ERR 'X' /* Flag error */ +#define SPR_BLANK ' ' /* Blank */ + +/* Global variables +*/ +int brd_rows, /* Board size in rows */ + brd_cols; /* Board size in columns */ + +WORD mines_row[MAX_ROWS], /* Map for mines */ + visib_row[MAX_ROWS], /* Map for visible squares */ + flags_row[MAX_ROWS], /* Map for squares with flag */ + count_row[MAX_ROWS]; /* Map for counters */ + +BYTE sq_buf[MAX_BUF]; /* Buffer to hold the above maps */ + +int row_off[8], /* Array to help in calculation */ + col_off[8]; /* of adjacent squares */ + +int gameover, /* NZ if game is over */ + dead, /* NZ if player is dead */ + level, /* Current level */ + viscnt, /* Number of visible squares in board */ + flgcnt, /* Number of flags in board */ + squares, /* Number of squares in board */ + mines, /* Number of mines in board */ + random; /* Random number */ + +/* Code starts here +*/ +main(argc, argv) +int argc, argv[]; /* char *argv[] - unsupported by MESCC */ +{ + int i; + int tty_n; + int *tty_s; /* char *[] */ + + /* Init KS + */ + KsHello(0); + + /* Setup + */ + Setup(); + + /* Play game + */ + Play(); + + /* The end + */ + PrStr("\n\n\tBye, bye!\n\n\n"); +} + +/* Setup program +*/ +Setup() +{ + + int i; BYTE *p; + + /* Build array to help in calculation of adjacent squares + */ + row_off[0]=-1; col_off[0]= 0; /* Up */ + row_off[1]=-1; col_off[1]=+1; /* Upper Right */ + row_off[2]= 0; col_off[2]=+1; /* Right */ + row_off[3]=+1; col_off[3]=+1; /* Lower Right */ + row_off[4]=+1; col_off[4]= 0; /* Down */ + row_off[5]=+1; col_off[5]=-1; /* Lower Left */ + row_off[6]= 0; col_off[6]=-1; /* Left */ + row_off[7]=-1; col_off[7]=-1; /* Upper Left */ + + /* Setup maps + */ + p = sq_buf; + + for(i = 0; i < MAX_ROWS; ++i) + { + mines_row[i]=p; p+=MAX_COLS; + visib_row[i]=p; p+=MAX_COLS; + flags_row[i]=p; p+=MAX_COLS; + count_row[i]=p; p+=MAX_COLS; + } + + /* Other + */ + random = 0; +} + +/* Show copyright, etc. +*/ +Copyright() +{ + int r; + char str[80]; + + KsClear(); + + sprintf(str, "%sFind %sThat %sMine%s!%s\n", FGBRED, FGBCYN, FGBBLU, FGBYEL, RESET); + KsPosCursor(r = 0, 32); + KsPutStr(str); + //KsCenterStr(r = 0, "Find That Mine!\n"); + KsCenterStr(++r , "v2.0 for CP/M & Z80\n\n"); + ++r; + KsCenterStr(++r ,"A minesweeper type game.\n"); + ++r; + KsCenterStr(++r ,"(c) 2012-2020 Miguel Garcia / Floppy Software, Spain.\n"); + KsCenterStr(++r ,"www.floppysoftware.es\n"); + KsCenterStr(++r ,"VT100 color version by acn@acn.wtf\n\n"); +} + +/* Select and play a level +*/ +Play() +{ + int run; char buf[2]; + + run = 1; + + while(run) + { + Copyright(); + + PrStr("\t1 > Level 1 : 08 x 08 squares, 08 mines\n"); + PrStr("\t2 > Level 2 : 08 x 12 squares, 12 mines\n"); + PrStr("\t3 > Level 3 : 08 x 16 squares, 16 mines\n"); + PrStr("\tQ > Quit game\n\n"); + + PrStr("\t? "); + + ReadLine(buf, 1); + + switch(*buf) + { + case '1' : SetLevel(1); RunLevel(); break; + case '2' : SetLevel(2); RunLevel(); break; + case '3' : SetLevel(3); RunLevel(); break; + case 'Q' : run = 0; break; + default : break; + } + } +} + +/* Setup level +*/ +SetLevel(lev) +int lev; +{ + /* I'm thinking... + */ + PrStr("\n\n\tI'm thinking... "); + + /* Setup level values + */ + level = lev; brd_rows = 8; + + switch(level) + { + case 1 : brd_cols = 8; break; + case 2 : brd_cols = 12; break; + case 3 : brd_cols = 16; break; + } + + squares = brd_rows * brd_cols; + + mines = squares / 8; + + gameover = dead = viscnt = flgcnt = 0; + + /* Setup board + */ + ClrBoard(); + + /* Setup counters + */ + ClrCounts(); +} + +/* Play level +*/ +RunLevel() +{ + int row, col; char buf[4]; + + for(;;) + { + ShowBoard(); + + if(gameover) { + PrStr("\tRETURN > Quit level\n\n\t? "); + ReadLine(buf, 0); + break; + } + + PrStr("\trc > Select (ie 0B)\n"); + PrStr("\trcF > Set/remove flag (ie: 3DF)\n"); + PrStr("\tQ > Quit level\n\n"); + PrStr("\t? "); + + ReadLine(buf, 3); + + if(buf[0] >= '0' && buf[0] < '0' + brd_cols) + { + row = buf[0] - '0'; + + if(buf[1] >= 'A' && buf[1] < 'A' + brd_cols) + { + col = buf[1] - 'A'; + + if(!buf[2]) + Choice(row, col); + else if(buf[2] == 'F' && !buf[3]) + ChoiceFlag(row, col); + } + } + else if(buf[0] == 'Q' && !buf[1]) + gameover = 1; + } +} + +/* Test if player has win the game +*/ +TestIfWin() +{ + + if(flgcnt == mines && flgcnt + viscnt == squares) + gameover = 1; +} + +/* Set or remove a flag in a square +*/ +ChoiceFlag(row, col) +int row, col; +{ + if(!TstVis(row, col)) + { + if(TstFlag(row, col)) + { + SetFlag(row, col, 0); --flgcnt; + } + else + { + SetFlag(row, col, 1); ++flgcnt; + + TestIfWin(); + } + } +} + +/* Select a square +*/ +Choice(row, col) +int row, col; +{ + if(!TstVis(row, col) && !TstFlag(row, col)) + { + if(TstMine(row, col)) + { + gameover = dead = 1; return; + } + + /* Make visible this square. + */ + SetVis(row, col, 1); ++viscnt; + + /* Make visible the adjacent squares, if there are not mines around. + */ + if(!GetCount(row, col)) + VisAdj(row, col); + + TestIfWin(); + } +} + +/* Get square counter +*/ +GetCount(row, col) +int row, col; +{ + BYTE *p; + + p = count_row[row]; + + return p[col]; +} + +/* Set square counter +*/ +SetCount(row, col, val) +int row, col, val; +{ + BYTE *p; + + p=count_row[row]; + + p[col]=val; +} + +/* Return 1 if there is a mine in the square, else 0 +*/ +TstMine(row, col) +int row, col; +{ + BYTE *p; + + p=mines_row[row]; + + return p[col] ? 1 : 0; +} + +/* Set/remove a mine in a square +*/ +SetMine(row, col, val) +int row, col, val; +{ + BYTE *p; + + p=mines_row[row]; + + p[col]=val; +} + +/* Return 1 if there is a flag in the square, else 0 +*/ +TstFlag(row, col) +int row, col; +{ + BYTE *p; + + p=flags_row[row]; + + return p[col] ? 1 : 0; +} + +/* Set/remove a flag in a square +*/ +SetFlag(row, col, val) +int row, col, val; +{ + BYTE *p; + + p=flags_row[row]; + + p[col]=val; +} + +/* Return 1 if it is a visible square, else 0 +*/ +TstVis(row, col) +int row, col; +{ + BYTE *p; + + p=visib_row[row]; + + return p[col] ? 1 : 0; +} + +/* Set square to visible or invisible +*/ +SetVis(row, col, val) +int row, col, val; +{ + BYTE *p; + + p=visib_row[row]; + + p[col]=val; +} + +/* Return the number of mines in adjacent squares +*/ +FindAdj(row, col) +int row, col; +{ + int mines, rn, cn, i; + + for((mines = i = 0); i < 8; ++i) + { + rn = row + row_off[i]; + cn = col + col_off[i]; + + if(rn >= 0 && rn < brd_rows && cn >= 0 && cn < brd_cols) + if(TstMine(rn, cn)) + ++mines; + } + + return mines; +} + +/* Set adjacent squares visible - recursively +*/ +VisAdj(row, col) +int row, col; +{ + int rn, cn, i; + + for(i=0; i < 8; ++i) + { + rn = row + row_off[i]; + cn = col + col_off[i]; + + if(rn >= 0 && rn < brd_rows && cn >= 0 && cn < brd_cols) + { + if(!TstVis(rn, cn) && !TstFlag(rn, cn)) + { + SetVis(rn, cn, 1); ++viscnt; + + if(!GetCount(rn, cn)) + VisAdj(rn, cn); + } + } + } +} + +/* Display board +*/ +ShowBoard() +{ + int r, c; + + KsClear(); + + PrStr("\t "); + for(c = 0; c < brd_cols; ++c) { + PrCh(' '); PrCh('A' + c); + } + PrCh('\n'); + + PrStr(FGBGRY); + PrStr("\t "); PrCh(201); + PrChTimes(205, brd_cols + brd_cols + 1); + PrCh(187); PrCh('\n'); + PrStr(RESET); + + for(r = 0; r < brd_rows; ++r) + { + PrCh('\t'); PrCh('0' + r); PrStr(FGBGRY); PrCh(186); PrStr(RESET); + + for(c = 0; c < brd_cols; ++c) + { + PrCh(' '); + + if(TstVis(r, c)) + { + if(GetCount(r, c)) { + switch(GetCount(r, c)) + { + case 1: PrStr(FGBBLU); break; + case 2: PrStr(FGGRN); break; + case 3: PrStr(FGBRED); break; + case 4: PrStr(FGBLU); break; + case 5: PrStr(FGRED); break; + default: PrStr(FGCYN); break; + } + PrCh('0' + GetCount(r, c)); + PrStr(RESET); + } + else { + PrCh(SPR_BLANK); + } + } + else if(gameover) + { + if(TstMine(r, c)) { + if(TstFlag(r, c)) { + PrStr(FGRED); PrCh(SPR_FLAG); PrStr(RESET); + } + else { + PrStr(FGRED); PrCh(SPR_MINE); PrStr(RESET); + } + } + else { + if(TstFlag(r, c)) + PrCh(SPR_ERR); + else + PrStr(FGBGRY); PrCh(SPR_UNK); PrStr(RESET); + } + } + else + { +#if DEBUG_MINES + if(TstFlag(r, c)) + PrCh(SPR_FLAG); + else if(TstMine(r, c)) + PrCh(SPR_MINE); + else + PrCh(SPR_UNK); +#else + if(TstFlag(r, c)) { + PrStr(FGRED); PrCh(SPR_FLAG); PrStr(RESET); + } + else { + PrStr(FGBGRY); PrCh(SPR_UNK); PrStr(RESET); + } +#endif + } + } + + PrCh(' '); PrStr(FGBGRY); PrCh(186); PrStr(RESET); PrCh('0' + r); + + switch(r) + { + case 0 : + PrStr(" FIND THAT MINE!"); + break; + case 2 : + if(gameover) { + PrStr(" GAME OVER"); + } + else { + PrStr(" Level: "); PrNumber(level); + } + break; + case 4 : + if(gameover) { + if(dead) { + PrStr(" YOU'RE DEAD"); + } + else if(flgcnt + viscnt == squares) { + PrStr(" YOU WIN"); + } + else { + PrStr(" SEE YOU LATER"); + } + } + else { + PrStr(" Mines: "); PrNumber(mines); + } + break; + case 6 : + if(!gameover) { + PrStr(" Flags: "); PrNumber(flgcnt); + } + break; + } + + PrCh('\n'); + } + + PrStr(FGBGRY); + PrStr("\t "); PrCh(200); + PrChTimes(205, brd_cols + brd_cols + 1); + PrCh(188); PrCh('\n'); + PrStr(RESET); + + PrStr("\t "); + for(c = 0; c < brd_cols; ++c) { + PrCh(' '); PrCh('A' + c); + } + PrCh('\n'); + + PrCh('\n'); +} + + +/* Setup board. + All squares without mines, invisibles and without flags. + Set the mines randomly. +*/ +extern char RandStr[]; + +ClrBoard() +{ + int r, c; char *p; + + /* + */ + p = RandStr + 8 * (random & 0x0F); + + for(r = 0; r < brd_rows; ++r) + { + for(c = 0; c < brd_cols; ++c) + { + /* Set square + */ + SetVis(r, c, 0); + SetFlag(r, c, 0); + SetMine(r, c, *p == '@' ? 1 : 0); + + /* Update next value + */ + if((*++p)=='$') + p = RandStr; + } + } +} + +/* Setup counters of adjacent squares +*/ +ClrCounts() +{ + int r, c; char *p; + + for(r = 0; r < brd_rows; ++r) + for(c = 0; c < brd_cols; ++c) + SetCount(r, c, FindAdj(r, c)); +} + +/* String to setup board randomly (total of 128 bytes). 1 mine each 8 bytes. +*/ +#asm + +RandStr: + + ; v-------v-------v-------v------- + + defb '----@---@-------------@----@----' + defb '-@-----------@----@----------@--' + defb '--@---------@----------@--@-----' + defb '----@----@-----------@---@------' + defb '$' + +#endasm + +/* Read line from keyboard. + Setup random number. +*/ +ReadLine(buf, width) +char *buf; +int width; +{ + int len; char ch; + + len = 0; + + while(!KsGetKb()) + ++random; + + while(1) + { + switch(ch = KsGetCh()) + { + case 8 : + case 127 : + if(len) + { + PrCh(8); PrCh(' '); PrCh(8); --len; + } + break; + + case '\r' : + case '\n' : + buf[len] = 0; + return; + + default : + if(ch >= ' ' && len < width) + PrCh(buf[len++] = toupper(ch)); + } + } +} + +/* Print character. Supports simple '\t'. +*/ +PrCh(c) +int c; +{ + if(c != '\t') { + KsPutCh(c); + } + else { + PrChTimes(' ', 8); + } +} + +/* Print string +*/ +PrStr(s) +char *s; +{ + while(*s) { + PrCh(*s++); + } +} + +/* Print character X times +*/ +PrChTimes(ch, n) +int ch, n; +{ + while(n--) { + PrCh(ch); + } +} + +/* Print decimal number +*/ +PrNumber(n) +int n; +{ + int s[7]; + + sprintf(s, "%d", n); + + PrStr(s); +} + + diff --git a/FindThatMine/ftm.com b/FindThatMine/ftm.com new file mode 100644 index 0000000..587de7b Binary files /dev/null and b/FindThatMine/ftm.com differ diff --git a/FindThatMine/gpl-3.0.txt b/FindThatMine/gpl-3.0.txt new file mode 100644 index 0000000..94a9ed0 --- /dev/null +++ b/FindThatMine/gpl-3.0.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + 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 Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/FindThatMine/ks.h b/FindThatMine/ks.h new file mode 100644 index 0000000..4b8a9e0 --- /dev/null +++ b/FindThatMine/ks.h @@ -0,0 +1,398 @@ +/** + * KSvt100 + * + * This library offers a common interface for keyboard and screen devices + * using VT100 control codes + * + * This is a stripped down version of KS to only support VT100, but includes + * color codes + */ + +/* ks.h + + Keyboard & screen functions library for CP/M & MESCC - Mike's Enhanced Small C Compiler. + + Stripped down version for VT100+color by Anna Christina Naß + + Copyright (c) 2016, 2017 Miguel I. Garcia Lopez / FloppySoftware, Spain + + 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 + Free Software Foundation; either version 3, or (at your option) any + later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +int xks_rows = 25; // Screen rows +int xks_cols = 80; // Screen columns +BYTE *xks_clrscr = "\e[H\e[J"; // Clear screen +BYTE *xks_poscur = "\e[%r;%cH"; // Position cursor +BYTE *xks_shwcur = "\e[?25h"; // Show cursor +BYTE *xks_hidcur = "\e[?25l"; // Hide cursor +BYTE *xks_yrever = "\e[7m"; // Reverse on +BYTE *xks_nrever = "\e[m"; // Reverse off +BYTE *xks_yuline = "\e[4m"; // Underline on +BYTE *xks_nuline = "\e[m"; // Underline off + +#define RESET "\e[0m" // reset all attributes +#define FGBLK "\e[30m" // black +#define FGRED "\e[31m" // red +#define FGGRN "\e[32m" // green +#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 + + +/** + * @fn int KsHello(char *tty_name) + * @brief Initialize the KS library. + * Call this function before any other function (with a few exceptions). + * @param code - TTY code + * @return 0 on success, -1 on failure + */ +KsHello(code) +int code; +{ + // Setup BIOS jumps, etc. + xKsInit(); + return 0; +} + +/** + * @fn void KsBye(void) + * @brief Reset the KS library. + * Call this function before you stop your program, in order to reset the TTY. + */ +KsBye() +{ + // Nothing yet +} + +/** + * @fn int KsGetCode(char *name) + * @brief Get the code for a TTY name. + * This function can be called before KsHello(). + * @param name - TTY name + * @return TTY code if found, or -1 on unknown name + */ +KsGetCode(name) +char *name; +{ + if(strcmp(name, "VT100")) { + return 0; + } + else { + return -1; + } +} + +/** + * @fn int KsGetName(int code) + * @brief Get the name for a TTY code. + * This function can be called before KsHello(). + * @param code - TTY code + * @return TTY name, or NULL on unknown code + */ +KsGetName(code) +int code; +{ + if(code==0) { + return "VT100"; + } + else { + return NULL; + } +} + +/** + * @fn char **KsGetNames(void) + * @brief Get all supported TTY names. + * This function can be called before KsHello(). + * @return Pointer to an array of pointers to char + */ +KsGetNames() +{ + WORD xks_names[1]; + xks_names[0] = "VT100"; + return xks_names; +} + +/** + * @fn int KsGetHowMany(void) + * @brief Get the number of supported TTYs. + * This function can be called before KsHello(). + * @return Number of supported TTYs + */ +KsGetHowMany() +{ + return 1; +} + +/** + * @fn void KsClear(void) + * @brief Clear the screen and move the cursor to 0,0. + */ +KsClear() +{ + KsPutRawStr(xks_clrscr); +} + +/** + * @fn void KsPosCursor(int row, int col) + * @brief Move the cursor on screen. + * @param row - screen row from 0 + * @param col - screen column from 0 + */ +KsPosCursor(row, col) +int row, col; +{ + char *p; int v; + + for(p = xks_poscur; *p; ++p) { + if(*p != '%') { + KsPutRawCh(*p); + } + else { + v = (*(++p) == 'r' ? row : col); + xKsPutDec(1 + v); + } + } +} + +/** + * @fn void KsSetCursor(int toggle) + * @brief Show or hide the cursor on screen. + * @param toggle - 0 to hide, other to show + */ +KsSetCursor(toggle) +int toggle; +{ + if(xks_shwcur) { + KsPutRawStr(toggle ? xks_shwcur : xks_hidcur); + } +} + +/** + * @fn void KsUnderline(int toggle) + * @brief Set or reset underline text. + * If the TTY does not have this capability, does nothing. + * @param toggle - 0 to reset, other to set + */ +KsUnderline(toggle) +int toggle; +{ + if(xks_yuline) { + KsPutRawStr(toggle ? xks_yuline : xks_nuline); + } +} + +/** + * @fn void KsReverse(int toggle) + * @brief Set or reset reverse text. + * If the TTY does not have this capability, does nothing. + * @param toggle - 0 to reset, other to set + */ +KsReverse(toggle) +int toggle; +{ + if(xks_yrever) { + KsPutRawStr(toggle ? xks_yrever : xks_nrever); + } +} + +/** + * @fn int KsGetRows(void) + * @brief Get TTY rows. + * @return TTY rows. + */ +KsGetRows() +{ + return xks_rows; +} + +/** + * @fn int KsGetCols(void) + * @brief Get TTY columns. + * @return TTY columns. + */ +KsGetCols() +{ + 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) + * @brief Send a character to the TTY. + * @param ch - character + */ +#asm +KsPutRawCh + ld c,l + jp xKsConOut +#endasm + +/** + * @fn void KsPutRawStr(char *s) + * @brief Send a string to the TTY using KsPutRawCh(). + * @param s - string + */ +KsPutRawStr(s) +char *s; +{ + while(*s) { + KsPutRawCh(*s++); + } +} + +/** + * @fn void KsPutCh(int ch) + * @brief Send a character to the TTY. + * This functions performs the following translations: + * - '\n' to '\r' + '\n' + * @param ch - character + */ +#asm +KsPutCh + ld a,l + cp 10 + jp nz,KsPutRawCh + ld l,13 + call KsPutRawCh + ld l,10 + jp KsPutRawCh +#endasm + +/** + * @fn void KsPutStr(char *s) + * @brief Send a string to the TTY using KsPutCh(). + * @param s - string + */ +KsPutStr(s) +char *s; +{ + while(*s) { + KsPutCh(*s++); + } +} + +/** + * @fn int KsGetKb(void) + * @brief Check if there is an input character from the keyboard. + * @return 0 for NO, other for YES + */ +#asm +KsGetKb: + call xKsConInSt + ld h,a + ld l,a + ret +#endasm + +/** + * @fn int KsGetCh(void) + * @brief Get character from the keyboard, waiting for one if necessary. + * @return character + */ +#asm +KsGetCh + call xKsConIn + ld h,0 + ld l,a + ret +#endasm + +/* Private functions + ----------------- +*/ + +// void xKsInit(void) : Set BIOS JUMPs. +#asm +xKsInit + ld hl,(1) + inc hl + inc hl + inc hl + ld de,xKsConInSt + ld bc,9 + ldir + ret + +xKsConInSt + jp 0 ; BIOS ConSt +xKsConIn + jp 0 ; BIOS ConIn +xKsConOut + jp 0 ; BIOS ConOut +#endasm + +// void xKsPutDec(int num) : Send positive decimal number to TTY. +xKsPutDec(num) +int num; +{ +#ifdef SPRINTF_H + char buf[6]; + + sprintf(buf, "%d", num); + + KsPutRawStr(buf); +#else + char buf[6]; + int i; + + for(i = 0; i < 6; ++i) { + if(num > 9) { + buf[i] = num % 10; + num /= 10; + } + else { + buf[i++] = num; + break; + } + } + + do { + KsPutRawCh('0' + buf[--i]); + } while(i); +#endif +} + + diff --git a/FindThatMine/mescc/CCOPT.COM b/FindThatMine/mescc/CCOPT.COM new file mode 100644 index 0000000..1566fe5 Binary files /dev/null and b/FindThatMine/mescc/CCOPT.COM differ diff --git a/FindThatMine/mescc/HEXTOCOM.COM b/FindThatMine/mescc/HEXTOCOM.COM new file mode 100644 index 0000000..202be89 Binary files /dev/null and b/FindThatMine/mescc/HEXTOCOM.COM differ diff --git a/FindThatMine/mescc/ZSM.COM b/FindThatMine/mescc/ZSM.COM new file mode 100644 index 0000000..5ce1976 Binary files /dev/null and b/FindThatMine/mescc/ZSM.COM differ diff --git a/FindThatMine/mescc/cc.com b/FindThatMine/mescc/cc.com new file mode 100644 index 0000000..e9d6115 Binary files /dev/null and b/FindThatMine/mescc/cc.com differ diff --git a/FindThatMine/mescc/conio.h b/FindThatMine/mescc/conio.h new file mode 100644 index 0000000..895a683 --- /dev/null +++ b/FindThatMine/mescc/conio.h @@ -0,0 +1,252 @@ +/** + * @file conio.h + * @brief Console I/O. + * @author Miguel I. Garcia Lopez / FloppySoftware + * + * Console I/O functions, for MESCC (Mike's Enhanced + * Small C Compiler for Z80 & CP/M). + * + * Supports following #defines: + * - CC_STDIO Support for stdin, stdout & stderr. + * - CC_CONIO_BIOS Support for direct console I/O. + * + * Revisions: + * - 22 Jan 2001 : Last revision. + * - 16 Apr 2007 : GPL'd. + * - 21 Apr 2007 : Changed puts for ANSI compatibility. + * - 15 May 2007 : Bug solved - added LF output to puts. + * - 13 Jul 2014 : Added kbhit(). + * - 08 Dec 2014 : Added support for stdin, stdout & stderr. + * - 31 Dec 2014 : Solved bug in putstr when characters are > 0x7F. + * - 20 Dec 2015 : Added macro CC_CONIO_BIOS to support direct console I/O using BIOS, instead of BDOS. + * - 08 Jan 2015 : Modified getch() when access BDOS (fn. 6 instead of 1). + * - 10 Dec 2016 : Documented. GPL v3. + * + * Copyright (c) 1999-2016 Miguel I. Garcia Lopez / FloppySoftware. + * + * Licensed under the GNU General Public License v3. + * + * http://www.floppysoftware.es + * floppysoftware@gmail.com + */ +#ifndef CONIO_H + +#define CONIO_H + +/** + * @fn int putch(int ch) + * @brief Send character to the console. + * @param ch - character + * @return ch + */ +#ifdef CC_CONIO_BIOS +#asm + +putch + PUSH HL + LD C,L + LD E,9 + CALL xbios + POP HL + RET + +xbios + LD HL,(1) + LD D,0 + ADD HL,DE + JP (HL) + +#endasm +#else +#asm + +putch + PUSH HL + LD C,2 + LD E,L + CALL 5 + POP HL + RET +#endasm +#endif + +/** + * @fn int getch(void) + * @brief Get character from the console without echo. + * + * Waits until a character is available. + * + * @return character + */ +#ifdef CC_CONIO_BIOS +#asm + +getch + LD E,6 + CALL xbios + LD H,0 + LD L,A + RET + +#endasm +#else +#asm + +getch + LD C,6 + LD E,255 + CALL 5 + OR A + JR Z,getch + LD H,0 + LD L,A + RET +#endasm +#endif + +/** + * @fn int kbhit(void) + * @brief Tests console input status. + * @return != 0 if a character is available, else 0. + */ +#ifdef CC_CONIO_BIOS +#asm + +kbhit + LD E, 3 + CALL xbios + LD H,A + LD L,A + RET + +#endasm +#else +#asm + +kbhit + LD C,11 + CALL 5 + LD H,A + LD L,A + RET +#endasm +#endif + +/** + * @fn int getchar(void) + * @brief Get character from the console or stdin. + * + * Waits until a character is available. + * + * #ifdef CC_STDIO: Returns a character from stdin, or EOF on end of file or error. + * #ifndef CC_STDIO: Returns a character from the console. Echoes the character. + * + * @return character on success, else EOF. + */ +getchar() +{ + +#ifdef CC_STDIO + + return fgetc(stdin); + +#else + + return putchar(getch()); + +#endif + +} + +/** + * @fn int putchar(int ch) + * @brief Send character to the console or stdout. + * + * #ifdef CC_STDIO: Returns ch, or EOF on error. + * #ifndef CC_STDIO: Returns ch. + * + * @param ch - character + * @return ch on success, else EOF. + */ +putchar(ch) +int ch; +{ + +#ifdef CC_STDIO + + return fputc(ch, stdout); + +#else + + if(ch == '\n') + putch('\r'); + + return putch(ch); + +#endif + +} + +/** + * @fn int putstr(char *s) + * @brief Send string to the console or stdout. + * + * #ifdef CC_STDIO: Returns the number of characters sent, or EOF on error. + * #ifndef CC_STDIO: Returns a non-negative value to indicate success. + * + * @param s - string + * @return number of characters sent on success, else EOF. + */ +putstr(s) +char *s; +{ + +#ifdef CC_STDIO + + /* FIXME : Better if call to fputs (if available) */ + + int i, c; + + i = 0; + + while(*s) + { + /* FIXME : -1 hardcoded -- < 0 causes strange + behaviour if ch > 0x7F */ + + if((c = putchar(*s++)) == -1) + return c; + ++i; + } + + return i; +#else + while(*s) + putchar(*s++); + + return 0; +#endif + +} + +/** + * @fn int puts(char *s) + * @brief Send string + '\n' to the console or stdout. + * + * #ifdef CC_STDIO: Returns the number of characters sent, or EOF on error. + * #ifndef CC_STDIO: Returns a non-negative value to indicate success. + * + * @param s - string + * @return number of characters sent on success, else EOF. + */ +puts(s) +char *s; +{ + putstr(s); + + return putchar('\n'); /* FIXME */ +} + +#endif + + \ No newline at end of file diff --git a/FindThatMine/mescc/ctype.h b/FindThatMine/mescc/ctype.h new file mode 100644 index 0000000..bad2be9 --- /dev/null +++ b/FindThatMine/mescc/ctype.h @@ -0,0 +1,203 @@ +/** + * @file ctype.h + * @brief Character tests and conversion functions. + * @author Miguel I. Garcia Lopez / FloppySoftware + * + * Character tests and conversion functions, for MESCC (Mike's Enhanced + * Small C Compiler for Z80 & CP/M). + * + * Revisions: + * - 19 Dec 2000 : Last revision. + * - 16 Apr 2007 : GPL'd. + * - 15 Aug 2016 : Documented. GPL v3. + * + * Copyright (c) 1999-2016 Miguel I. Garcia Lopez / FloppySoftware. + * + * Licensed under the GNU General Public License v3. + * + * http://www.floppysoftware.es + * floppysoftware@gmail.com + */ +#ifndef CTYPE_H + +#define CTYPE_H + +/** + * @fn int isalpha(char ch) + * @brief Test if ch is a letter. + * @param ch - character to test + * @return true or false + */ +#asm + +isalpha + ld a,l + ld hl,0 + cp 'A' + ret c + cp 'Z'+1 + jr c,isalpha1 + cp 'a' + ret c + cp 'z'+1 + ret nc +isalpha1 + inc l + ret + +#endasm + +/** + * @fn int isdigit(char ch) + * @brief Test if ch is a decimal digit. + * @param ch - character to test + * @return true or false + */ +#asm + +isdigit + ld a,l + ld hl,0 + cp '0' + ret c + cp '9'+1 + ret nc + inc l + ret + +#endasm + +/** + * @fn int isxdigit(char ch) + * @brief Test if ch is an hexadecimal digit. + * @param ch - character to test + * @return true or false + */ +#asm + +isxdigit + LD C,L + CALL isdigit + RET C + LD HL,0 + LD A,C + CP 'A' + RET C + CP 'G' + JR C,isxdigit1 + CP 'a' + RET C + CP 'g' + RET NC +isxdigit1 + INC L + RET + +#endasm + +/** + * @fn int isalnum(char ch) + * @brief Test if ch is a letter or a decimal digit. + * @param ch - character to test + * @return true or false + */ +#asm + +isalnum + LD C,L + CALL isdigit + RET C + LD L,C + JP isalpha + +#endasm + +/** + * @fn int isupper(char ch) + * @brief Test if ch is a letter in uppercase. + * @param ch - character to test + * @return true or false + */ +#asm + +isupper + ld a,l + ld hl,0 + cp 'A' + ret c + cp 'Z'+1 + ret nc + inc l + ret + +#endasm + +/** + * @fn int islower(char ch) + * @brief Test if ch is a letter in lowercase. + * @param ch - character to test + * @return true or false + */ +#asm + +islower + ld a,l + ld hl,0 + cp 'a' + ret c + cp 'z'+1 + ret nc + inc l + ret + +#endasm + +/** + * @fn int toupper(char ch) + * @brief Convert letter to uppercase. + * + * If ch is not a letter in lowercase, returns ch unchanged. + * + * @param ch - character to convert + * @return ch in uppercase + */ +#asm + +toupper + ld a,l + cp 'a' + ret c + cp 'z'+1 + ret nc + sub 20h + ld l,a + ret + +#endasm + +/** + * @fn int tolower(char ch) + * @brief Convert letter to lowercase. + * + * If ch is not a letter in uppercase, returns ch unchanged. + * + * @param ch - character to convert + * @return ch in lowercase + */ +#asm + +tolower + ld a,l + cp 'A' + ret c + cp 'Z'+1 + ret nc + add 20h + ld l,a + ret + +#endasm + +#endif + + \ No newline at end of file diff --git a/FindThatMine/mescc/mescc.h b/FindThatMine/mescc/mescc.h new file mode 100644 index 0000000..d826374 --- /dev/null +++ b/FindThatMine/mescc/mescc.h @@ -0,0 +1,945 @@ +/** + * @file mescc.h + * @brief Runtime library. + * @author Miguel I. Garcia Lopez / FloppySoftware + * + * Runtime library for MESCC (Mike's Enhanced + * Small C Compiler for Z80 & CP/M). + * + * This library file must be included first! + * + * Need following EQU's (generated by the compiler): + * - ccSTACKSIZE : Stack size in bytes. + * + * Supports following #defs: + * - #define CC_STDIO Support for stdin, stdout & stderr. + * - #define CC_REDIR Support for stdin & stdout redirection + * in command line (needs CC_STDIO). + * - #define CC_NO_MUL To exclude MULTIPLICATION code. + * - #define CC_NO_DIV To exclude DIVISION & MODULUS code. + * - #define CC_NO_SWITCH To exclude SWITCH code. + * - #define CC_NO_ARGS To exclude ARGC & ARGV code. + * - #define CC_NO_ORG To exclude ORG 0100H code. + * + * Sets the following #defines: + * + * - BYTE + * - WORD + * - BOOL + * - NULL + * - TRUE + * - FALSE + * - SIZEOF_CHAR + * - SIZEOF_INT + * - SIZEOF_PTR + * + * Revisions: + * - 16 Jan 2001 : Last revision. + * - 23 Mar 2007 : Expand ccladr1 and ccladr2 for more speed. + * - 16 Apr 2007 : GPL'd. + * - 26 Aug 2012 : Added standard defs. + * - 08 Dec 2014 : Minor changes. + * - 09 Dec 2014 : Added support for stdin, stdout & stderr with CC_STDIO. + * - 12 Dec 2014 : Added support for stdin & stdout redirection in command line with CC_REDIR. + * - 16 Jan 2015 : Added SIZEOF_??? definitions. + * - 16 Feb 2015 : Modified / added code in cctmpw, ccxpb2, ccxpb, ccxpb3, ccxpw2 + * ccxpw, ccxpw3, ccladr2sv, ccladr2, ccladr1sv, ccladr1, + * to avoid use of IX register. + * - 20 Mar 2015 : Added support for CC_NO_MUL, CC_NO_DIV, CC_NO_SWITCH, CC_NO_ARGS. + * - 12 Apr 2015 : Removed ccDEFARGS code. + * - 14 Jul 2015 : Modified code for << and >>, because a shift of 0 positions, + * resulted in a wrong value (they assumed a shift > 0) - ie: 128 >> 0 resulted in 0. + * - 19 Oct 2015 : Improved multiplication algorithm (ccmul & ccumul). + * - 05 Nov 2015 : Modified ccsxt. + * - 30 Nov 2015 : Added support for atexit(). + * - 24 Jan 2016 : Added support for CC_NO_ORG. + * - 10 Dec 2016 : Documented. GPL v3. + * + * Copyright (c) 1999-2016 Miguel I. Garcia Lopez / FloppySoftware. + * + * Licensed under the GNU General Public License v3. + * + * http://www.floppysoftware.es + * floppysoftware@gmail.com + */ + +/* STANDARD DEFs + ------------- +*/ + +#define BYTE unsigned char +#define WORD unsigned int +#define BOOL char +#define NULL 0 +#define TRUE 1 +#define FALSE 0 + +#define SIZEOF_CHAR 1 /* [unsigned] char */ +#define SIZEOF_INT 2 /* [unsigned] int */ +#define SIZEOF_PTR 2 /* pointer */ + +/* RUNTIME CODE + ------------ +*/ + +#ifndef CC_NO_ORG + +#asm +; Start at TPA + + ORG 0100H + +#endasm + +#endif + +#asm +; Runtime address + +ccrtadr: + +; Set stack under BDOS (xx00h) + + LD HL,(6) + LD L,0 + LD SP,HL + +; Leave space for stack and init. variables + + LD DE,ccSTACKSIZE + OR A + SBC HL,DE + DEC HL + LD (ccfreelast),HL + LD DE,ccfreemem + LD (ccfreefirst),DE + OR A + SBC HL,DE + INC HL + LD (ccfreebytes),HL + JR NC,ccargs + +; Error, no memory for stack + + LD C,9 + LD DE,ccerrstack + CALL 5 + JP 0 + +ccerrstack + DEFB 'Runtime Error - No stack$' + +; Setup command line arguments + +ccargs + +#endasm + +#ifndef CC_NO_ARGS + +#asm +; Copy command line + + LD HL,81H + LD DE,ccmdbuf + LD BC,127 + LDIR + + LD A,(80H) + LD B,0 + LD C,A + LD HL,ccmdbuf + ADD HL,BC + LD (HL),0 + +; Init. argc & argv + + LD DE,cchptr + LD HL,ccmdbuf - 1 + LD BC,1 +ccspc + INC HL + LD A,(HL) + OR A + JR Z,ccarg + CP ' ' + JR Z,ccspc + LD A,L + LD (DE),A + LD A,H + INC DE + LD (DE),A + INC DE + INC C +ccpar + INC HL + LD A,(HL) + OR A + JR Z,ccarg + CP ' ' + JR NZ,ccpar + LD (HL),0 + JR ccspc + +ccarg + LD HL,cchptr - 2 + PUSH BC ;argc + PUSH HL ;argv +#endasm + +#endif + +#ifdef CC_REDIR + +#asm + CALL redir ;FIXME - Check errors + POP DE + POP BC + PUSH HL ;argc + PUSH DE ;argv +#endasm + +#endif + +#asm + +; Execute program + + CALL main +#endasm + +/** + * @fn void exit(int code) + * @brief Exit to CP/M. + * + * FixMe: Return code is lost! + */ +#asm + +; Exit to CP/M + +exit + NOP ; Patch for atexit() -- 3 bytes. + NOP + NOP +#endasm + +#ifdef CC_STDIO + +BYTE *stdin, *stdout, *stderr; /* Sorry, no available FILE here */ + +#asm + LD HL,(stdin) + CALL ccflush + LD HL,(stdout) + CALL ccflush + + JP 0 + +ccflush + LD A,H + OR L + RET Z + PUSH HL + CALL fclose + POP BC + RET +#endasm + +#else + +#asm + JP 0 +#endasm + +#endif + +#asm + +; Variables for memory functions + +ccfreefirst + DEFW 0 ;Adr. first free byte +ccfreelast + DEFW 0 ;Adr. last free byte +ccfreebytes + DEFW 0 ;Number of free bytes + +#endasm + +#ifndef CC_NO_ARGS + +#asm +; Variables for command line arguments + +ccmdbuf + DEFS 128 ;Command line buffer + + DEFW ccNULL ;Pointers table for argv +cchptr + DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL + DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL + DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL + DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL + DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL + +ccNULL + DEFB 0 ;Null pointer +#endasm + +#endif + +#asm + +; Basic routines + +; Call formats to access locals: +; +; Format 1: CALL routine +; DEFB SpOffset +; +; Format 2: CALL routine +; DEFW SpOffset + +; HL = unsigned char from local (format 2) + +ccxgb2 + CALL ccladr2 + JR ccxgb3 + +; HL = unsigned char from local (format 1) + +ccxgb + CALL ccladr1 +ccxgb3 + LD L,(HL) + LD H,0 + RET + +; HL = signed char from local (format 2) + +ccxgc2 + CALL ccladr2 + JR ccgc + +; HL = signed char from local (format 1) + +ccxgc + CALL ccladr1 + +; HL = signed char from (HL) + +ccgc + LD A,(HL) + +; HL = signed char from A + +ccsxt + LD L,A + RLCA + SBC A + LD H,A + RET + +; LD H,0 +; LD L,A +; AND 128 +; RET Z +; DEC H +; RET + +; HL = word from local (format 2) + +ccxgw2 + CALL ccladr2 + JR ccgw + +; HL = word from local (format 1) + +ccxgw + CALL ccladr1 + +; HL = word from (HL) + +ccgw + LD A,(HL) + INC HL + LD H,(HL) + LD L,A + RET + +; char local = HL (format 2) + +ccxpb2 + CALL ccladr2sv + JR ccxpb3 + +; char local = HL (format 1) + +ccxpb + CALL ccladr1sv +ccxpb3 + LD DE,(cctmpw) + LD (HL),E + EX DE,HL + RET + +; int/ptr local = HL (format 2) + +ccxpw2 + CALL ccladr2sv + JR ccxpw3 + +; int/ptr local = HL (format 1) + +ccxpw + CALL ccladr1sv +ccxpw3 + LD DE,(cctmpw) + LD (HL),E + INC HL + LD (HL),D + EX DE,HL + RET + +; Copy 1 word from HL to (DE) + +ccpw + LD A,L + LD (DE),A + INC DE + LD A,H + LD (DE),A + RET + +; Calc. local adress + +cctmpw DEFW 0 + +ccladr2sv + LD (cctmpw),HL + +ccladr2 + POP DE + POP HL + LD C,(HL) + INC HL + LD B,(HL) + INC HL + PUSH HL + PUSH DE + LD HL,4 + ADD HL,BC + ADD HL,SP + RET + +ccladr1sv + LD (cctmpw),HL + +ccladr1 + POP DE + POP HL + LD B,0 + LD C,(HL) + INC HL + PUSH HL + PUSH DE + LD HL,4 + ADD HL,BC + ADD HL,SP + RET + +; OR HL = HL | DE + +ccor + LD A,L + OR E + LD L,A + LD A,H + OR D + LD H,A + RET + +; XOR HL = HL ^ DE + +ccxor + LD A,L + XOR E + LD L,A + LD A,H + XOR D + LD H,A + RET + +; AND HL = HL & DE + +ccand + LD A,L + AND E + LD L,A + LD A,H + AND D + LD H,A + RET + +; LOGIC OR HL = DE || HL + +cclgor + LD A,H + OR L + OR D + OR E + LD L,A + RET + + ;LD A,H + ;OR L + ;RET NZ + ;LD A,D + ;OR E + ;RET Z + ;INC L + ;RET + +; LOGIC AND HL = DE && HL + +cclgand + LD A,H + OR L + RET Z + LD A,D + OR E + RET NZ + JP ccfalse + +; HL = HL == DE + +cceq + OR A + SBC HL,DE + +; LOGIC NOT HL = !HL + +cclgnot + LD A,H + OR L + JP NZ,ccfalse + INC L + RET + +; HL = HL != DE + +ccne + OR A + SBC HL,DE + RET + +; HL = DE > HL (SIGNED) + +ccgt + EX DE,HL + +; HL = DE < HL (SIGNED) + +cclt + CALL cccmp + RET C + DEC L + RET + +; HL = DE <= HL (SIGNED) + +ccle + CALL cccmp + RET Z + RET C + DEC L + RET + +; HL = DE >= HL (SIGNED) + +ccge + CALL cccmp + RET NC + DEC L + RET + +; Compare DE with HL, and return: (SIGNED) +; +; CARRY if DE < HL +; ZERO if DE == HL +; HL = 1 + +cccmp + LD A,E + SUB L + LD E,A + LD A,D + SBC H + LD HL,1 + JP M,cccmp1 + OR E + RET + +cccmp1 + OR E + SCF + RET + +; HL = DE <= HL (UNSIGNED) + +ccule + CALL ccucmp + RET Z + RET C + DEC L + RET + +; HL = DE >= HL (UNSIGNED) + +ccuge + CALL ccucmp + RET NC + DEC L + RET + +; HL = DE > HL (UNSIGNED) + +ccugt + EX DE,HL + +; HL = DE < HL (UNSIGNED) + +ccult + CALL ccucmp + RET C + DEC L + RET + +; Compare DE with HL, and return: (UNSIGNED) +; +; CARRY if DE < HL +; ZERO if DE == HL +; HL = 1 + +ccucmp + LD A,D + CP H + JR NZ,ccucmp1 + LD A,E + CP L + +ccucmp1 + LD HL,1 + RET + +; HL = DE >> HL (UNSIGNED) + +ccuasr + EX DE,HL + LD A,E +ccuasr1 + OR A + RET Z + DEC A + SRL H + RR L + JR ccuasr1 + +; HL = DE >> HL (ARITMETIC) + +ccasr + EX DE,HL + LD A,E +ccasr1 + OR A + RET Z + DEC A + SRA H + RR L + JR ccasr1 + +; HL = DE << HL (UNSIGNED) + +ccuasl + +; HL = DE << HL (ARITMETIC) + +ccasl + EX DE,HL + LD A,E +ccasl1 + OR A + RET Z + DEC A + ADD HL,HL + JR ccasl1 + +; HL = DE - HL + +ccsub + EX DE,HL + OR A + SBC HL,DE + RET + +; HL = ~HL (1 COMPLEMENT) + +cccom + LD A,H + CPL + LD H,A + LD A,L + CPL + LD L,A + RET + +; HL = -HL (2 COMPLEMENT) + +ccneg + LD A,H + CPL + LD H,A + LD A,L + CPL + LD L,A + INC HL + RET + +#endasm + +#ifndef CC_NO_MUL + +#asm + +; HL = DE * HL (UNSIGNED) + +ccumul + +; HL = DE * HL (SIGNED) + +ccmul + LD A,H + LD C,L + LD HL,0 + LD B,16 +ccmul0 + ADD HL,HL + SLA C + RL A + JR NC,ccmul1 + ADD HL,DE +ccmul1 + DJNZ ccmul0 + RET + +#endasm + +#endif + +#ifndef CC_NO_DIV + +#asm + +; HL = DE % HL (SIGNED) + +ccmod + CALL ccdiv + EX DE,HL + RET + +; HL = DE / HL (SIGNED) +; DE = DE % HL (SIGNED) + +ccdiv + LD B,H + LD C,L + LD A,D + XOR B + PUSH AF + LD A,D + OR A + CALL M,ccdivdeneg + LD A,B + OR A + + JP P,ccdiv0 + + LD A,B + CPL + LD B,A + LD A,C + CPL + LD C,A + INC BC + +ccdiv0 + EX DE,HL + LD DE,0 + LD A,16 + +ccdiv1 + PUSH AF + + ADD HL,HL + + RL E + RL D + LD A,D + OR E + + JR Z,ccdiv2 + + LD A,E + SUB C + LD A,D + SBC B + + JP M,ccdiv2 + LD A,L + OR 1 + LD L,A + LD A,E + SUB C + LD E,A + LD A,D + SBC B + LD D,A + +ccdiv2 + POP AF + DEC A + JR NZ,ccdiv1 + POP AF + RET P + + CALL ccneg + +ccdivdeneg + LD A,D + CPL + LD D,A + LD A,E + CPL + LD E,A + INC DE + RET + +; HL = DE % HL (UNSIGNED) + +ccumod + CALL ccudiv + EX DE,HL + RET + +; HL = DE / HL (UNSIGNED) +; DE = DE % HL (UNSIGNED) + +ccudiv + LD (ccudiv_tmp),HL + LD HL,ccudiv_cnt + LD (HL),17 + LD BC,0 + PUSH BC + XOR A + +ccudiv0 + RL E + RL D + DEC (HL) + POP HL + JR Z,ccudiv2 + LD A,0 + ADC 0 + ADD HL,HL + LD B,H + ADD L + LD HL,(ccudiv_tmp) + SUB L + LD C,A + LD A,B + SBC H + LD B,A + PUSH BC + JR NC,ccudiv1 + ADD HL,BC + EX (SP),HL + +ccudiv1 + LD HL,ccudiv_cnt + CCF + JR ccudiv0 + +ccudiv2 + EX DE,HL + RET + +ccudiv_tmp + DEFW 0 +ccudiv_cnt + DEFB 0 + +#endasm + +#endif + +#ifndef CC_NO_SWITCH + +#asm + +; Switch, on entry: +; +; DE = Table address +; HL = Where to go if value was not found in table +; B = Number of entries in table + +ccswtch + EX (SP),HL + EX DE,HL + +ccswch1 + LD A,E + CP (HL) + INC HL + JR NZ,ccswch2 + LD A,D + CP (HL) + JR NZ,ccswch2 + INC HL + LD E,(HL) + INC HL + LD D,(HL) + EX DE,HL + POP BC + JP (HL) + +ccswch2 + INC HL + INC HL + INC HL + DJNZ ccswch1 + EX (SP),HL + POP BC + JP (HL) + +#endasm + +#endif + +#asm + +; HL = TRUE + +cctrue + LD L,1 + RET + +; HL = FALSE + +ccfalse + LD HL,0 + RET + +#endasm + + \ No newline at end of file diff --git a/FindThatMine/mescc/sprintf.h b/FindThatMine/mescc/sprintf.h new file mode 100644 index 0000000..00fa6a5 --- /dev/null +++ b/FindThatMine/mescc/sprintf.h @@ -0,0 +1,104 @@ +/** + * @file sprintf.h + * @brief Library for sprintf() function. + * @author Miguel I. Garcia Lopez / FloppySoftware + * + * Implementation of sprintf() function, for MESCC (Mike's Enhanced + * Small C Compiler for Z80 & CP/M). + * + * Revisions: + * - 20 Oct 2000 : Last revision. + * - 16 Apr 2007 : GPL'd. + * - 14 Apr 2015 : Ammended a bad closed comment. + * - 25 Aug 2016 : Documented. GPL v3. + * + * Copyright (c) 1999-2016 Miguel I. Garcia Lopez / FloppySoftware. + * + * Licensed under the GNU General Public License v3. + * + * http://www.floppysoftware.es + * floppysoftware@gmail.com + */ +#ifndef SPRINTF_H + +#define SPRINTF_H + +// Dependencies +// ------------ + +#ifndef XPRINTF_H + #include +#endif + +/** + * @fn int sprintf(char *dst, char *fmt, arg1, arg2, ...) + * @brief Formatted output to memory. + * + * See the documentation for xprintf.h to learn about the string format. + * + * @param dst - destination + * @param fmt - string format + * @param arg1 - argument #1 + * @param arg? - argument #? + * @return number or characters written, or -1 on failure (currently always #). + */ +#asm + +sprintf: + ADD HL,HL + ADD HL,SP ;HL=Adr. fmt + + LD DE,xspfout + PUSH DE + LD DE,xspfend + PUSH DE + PUSH HL + + INC HL + INC HL ;HL=Adr. dst + LD A,(HL) + INC HL + LD H,(HL) + LD L,A + LD (xspfout+2),HL + + CALL xprintf + + POP BC + POP BC + POP BC + + RET +#endasm + +// int xspfout(char ch) : output ch to memory; return 0 on success, !=0 on failure (currently always returns 0). + +#asm + +xspfout: + LD A,L + LD HL,0 ;Adr. + LD (HL),A + + INC HL + LD (xspfout+2),HL + + LD HL,0 + + RET +#endasm + +// void xspfend(void) : end formatted output; writes a trailing zero byte. + +#asm + +xspfend: + LD HL,(xspfout+2) + LD (HL),0 + RET + +#endasm + +#endif + + \ No newline at end of file diff --git a/FindThatMine/mescc/string.h b/FindThatMine/mescc/string.h new file mode 100644 index 0000000..0cca902 --- /dev/null +++ b/FindThatMine/mescc/string.h @@ -0,0 +1,249 @@ +/** + * @file string.h + * @brief String functions. + * @author Miguel I. Garcia Lopez / FloppySoftware + * + * String functions, for MESCC (Mike's Enhanced + * Small C Compiler for Z80 & CP/M). + * + * Revisions: + * - 19 Mar 2001 : Last revision. + * - 16 Apr 2007 : GPL'd. + * - 15 Aug 2016 : Documented. GPL v3. + * + * Copyright (c) 1999-2016 Miguel I. Garcia Lopez / FloppySoftware. + * + * Licensed under the GNU General Public License v3. + * + * http://www.floppysoftware.es + * floppysoftware@gmail.com + */ +#ifndef STRING_H + +#define STRING_H + +/** + * @fn int strlen(char *str) + * @brief Return string length. + * @param str - string + * @return length in characters + */ +#asm +strlen: + LD D,H + LD E,L + LD BC,0FFFFH + XOR A + CPIR + OR A + SBC HL,DE + DEC HL + RET +#endasm + +/** + * @fn char *strcpy(char *dst, char *src) + * @brief Copy string. + * @param dst - destination string + * @param src - source string + * @return pointer to dst + */ +#asm +strcpy: + POP BC + POP HL + POP DE + PUSH DE + PUSH HL + PUSH BC + + PUSH DE + +strcpy2: + LD A,(HL) + LD (DE),A + INC HL + INC DE + OR A + JR NZ,strcpy2 + POP HL + RET +#endasm + +/** + * @fn char *strcat(char *dst, char *src) + * @brief Copy string at the end of another string. + * @param dst - destination string + * @param src - source string + * @return pointer to dst + */ +#asm +strcat: + POP BC + POP HL + POP DE + PUSH DE + PUSH HL + PUSH BC + + PUSH DE + +strcat2 + LD A,(DE) + OR A + JR Z,strcpy2 + INC DE + JR strcat2 +#endasm + +/** + * @fn int strcmp(char *str1, char *str2) + * @brief Compare two strings. + * @param str1 - a string + * @param str2 - a string + * @return <0 on str1 < str2; =0 on str1 == str2; >0 on str1 > str2 + */ +#asm +strcmp + POP BC + POP HL + POP DE + PUSH DE + PUSH HL + PUSH BC +strcmp1 + LD A,(DE) + CP (HL) + JR NZ,strcmp2 + + OR A + JR Z,strcmp2 + + INC DE + INC HL + JR strcmp1 + +strcmp2 + LD HL,0 + RET Z + JR NC,strcmp3 + DEC HL + RET +strcmp3 + INC L + RET +#endasm + +/** + * @fn char *strchr(char *str, char ch) + * @brief Search a character in a string. + * @param str - the string where to search + * @param ch - the character to find + * @return pointer to ch in the string, or NULL on failure + */ +#asm +strchr + POP BC + POP DE + POP HL + PUSH HL + PUSH DE + PUSH BC + + +strchr2 + LD A,(HL) + CP E + RET Z + + INC HL + OR A + JR NZ,strchr2 + + LD H,A + LD L,A + RET +#endasm + +/** + * @fn char *strupr(char *str) + * @brief Convert a string to upper case. + * @param str - a string + * @return pointer to str + */ +#asm +strupr + POP BC + POP HL + PUSH HL + PUSH BC + + PUSH HL + +strupr1 + LD A,(HL) + OR A + JR Z,strupr3 + + CP 'a' + JR C,strupr2 + CP 'z'+1 + JR NC,strupr2 + SUB 32 + LD (HL),A + +strupr2 + INC HL + JR strupr1 + +strupr3 + POP HL + RET +#endasm + +/** + * @fn int atoi(char *s) + * @brief Convert string to a integer. + * + * This function parses a string, interpreting its content as + * a decimal integer number, until the end of the string, or + * a non decimal digit: + * + * [+|-][[0..9]...][ZERO|NON_DECIMAL_DIGIT] + * + * Examples: + * - "-256" == -256 + * - "64" == 64 + * - "1024 bytes" == 1024 + * - "what?" == 0 + * + * @param s - a string + * @return integer value + */ +atoi(s) +char *s; +{ + int sign, val; + + if(*s == '+') + { + ++s; sign = 1; + } + else if(*s == '-') + { + ++s; sign = -1; + } + else + sign = 1; + + val=0; + + while(*s >= '0' && *s <= '9') + val = val * 10 + (*s++ - '0'); + + return val * sign; +} + +#endif + + \ No newline at end of file diff --git a/FindThatMine/mescc/xprintf.h b/FindThatMine/mescc/xprintf.h new file mode 100644 index 0000000..2a22a4b --- /dev/null +++ b/FindThatMine/mescc/xprintf.h @@ -0,0 +1,365 @@ +/** + * @file xprintf.h + * @brief Support library for formatted output. + * @author Miguel I. Garcia Lopez / FloppySoftware + * + * Support library for formatted output, + * for MESCC (Mike's Enhanced Small C Compiler for Z80 & CP/M). + * + * All functions with formatted output like printf(), fprintf() + * and sprintf() call some private functions in this order: + * - pf_sf() + * - pf_s() + * - pf_out() + * + * Revisions: + * - 19 Mar 2001 : Last revision. + * - 16 Apr 2007 : GPL'd. + * - 09 Dec 2016 : Documented. Optimized. GPL v3. + * - 02 Aug 2017 : Output '%%' as '%'. + * + * Copyright (c) 1999-2016 Miguel I. Garcia Lopez / FloppySoftware. + * + * Licensed under the GNU General Public License v3. + * + * http://www.floppysoftware.es + * floppysoftware@gmail.com + */ +#ifndef XPRINTF_H + +#define XPRINTF_H + +// Dependencies +// ------------ + +#ifndef STRING_H + #include +#endif + +// Private globals +// --------------- + +BYTE xpf_err; // True on error + +extern WORD xpf_out; // Output function +extern WORD xpf_end; // End function + +int xpf_fw; // Field width +BYTE xpf_fa; // Field alignment: 0=left, 1=right +BYTE xpf_fz; // True on zero filling + +int xpf_cnt; // # of characters sent + +/** + * @fn int xprintf(WORD funout, WORD funend, WORD adrpars) + * @brief Formatted output. + * + * This function performs formatted output. It is used + * by printf(), fprintf() and sprintf() functions. + * + * The format is indicated in the string as follows: + * + * %[-][0][w]t + * + * | - : Left align (default: right align). + * | 0 : Zero filling on right align. + * | w : Width for alignment. If the specified width + * | is lower than the argument length, output is + * | done without aligment. Care with sprinf()! + * | t : d = Signed decimal integer. + * | u = Unsigned decimal integer. + * | x = Hexadecimal integer. + * | s = String. + * | c = Character. + * + * The pair %% outputs a single %. + * + * @param funout - function to output a character + * @param funend - function to end output + * @param adrpars - arguments addresses + * @return # of characters sent on sucess, -1 on failure + */ +xprintf(funout, funend, adrpars) +WORD funout, funend; +WORD *adrpars; +{ + WORD *parg; // Pointer to arguments + char *pfor; // Pointer to formatted string + int ivalue; + char ch; + + // Setup + xpf_out = funout; + xpf_end = funend; + + pfor = *adrpars; + parg = --adrpars; + + xpf_err = xpf_cnt = 0; + + // Loop + while((ch = *pfor++)) + { + if(ch == '%') + { + // Character % + if(*pfor == '%') + { + pf_out(ch); + ++pfor; + + continue; + } + + // Align + if(*pfor == '-') + { + xpf_fa = 0; // Left align + ++pfor; + } + else + xpf_fa = 1; // Right align + + // Zero filling + if(*pfor == '0') + { + xpf_fz = 1; // Zero filling + ++pfor; + } + else + xpf_fz = 0; + + // Width + xpf_fw = 0; + + while(*pfor >= '0' && *pfor <= '9') + xpf_fw = xpf_fw * 10 + (*pfor++) - '0'; + + // Type + switch(ch = *pfor++) + { + case 'd' : + ivalue = *parg--; + pf_dec(ivalue); + break; + case 'u' : + ivalue = *parg--; + pf_udec(ivalue); + break; + case 'x' : + ivalue = *parg--; + pf_hex(ivalue); + break; + case 'c' : + pf_cf(*parg--); + break; + case 's' : + pf_sf(*parg--); + break; + case '\0' : + --pfor; + // P'abajo + default : + pf_out('!'); + break; + } + } + else + pf_out(ch); + + if(xpf_err) + break; + } + + pf_end(); + + return xpf_err ? -1 : xpf_cnt; +} + +// void pf_sf(char *s) : output formatted string. + +pf_sf(s) +char *s; +{ + int len; + char fill; + + if(xpf_fw) + { + if((len = strlen(s)) < xpf_fw) + { + xpf_fw = xpf_fw-len; + + if(xpf_fa) + { + // Left align + fill = (xpf_fz ? '0' : ' '); + + while(xpf_fw--) + pf_out(fill); + pf_s(s); + } + else + { + // Right align + pf_s(s); + + while(xpf_fw--) + pf_out(' '); + } + + return; + } + } + + pf_s(s); +} + +// void pf_cf(char c) : output formatted character. + +pf_cf(c) +char c; +{ + char tmp[2]; + + tmp[0] = c; tmp[1] = '\0'; + + pf_sf(tmp); +} + +unsigned char xpf_dst[7]; // Buffer for numbers +unsigned char *xpf_dpt; // Buffer pointer + +// void pf_dec(int i) : output signed decimal integer. + +pf_dec(i) +int i; +{ + xpf_dpt = xpf_dst; + + if(i < 0) + { + *xpf_dpt++ = '-'; i = -i; + } + + pf_dec2(i); + + *xpf_dpt = '\0'; + + pf_sf(xpf_dst); +} + +// void pf_dec2(int i) : helper for pf_dec(). + +pf_dec2(i) +int i; +{ + int n; + + if(n = i / 10) + pf_dec2(n); + + *xpf_dpt++ = i % 10 + '0'; +} + +// void pf_udec(unsigned int i) : output unsigned decimal integer. + +pf_udec(i) +unsigned i; +{ + xpf_dpt = xpf_dst; + + pf_udec2(i); + + *xpf_dpt = '\0'; + + pf_sf(xpf_dst); +} + +// void pf_udec2(unsigned int i) : helper for pf_udec(). + +pf_udec2(i) +unsigned i; +{ + unsigned n; + + if(n = i / 10) + pf_udec2(n); + + *xpf_dpt++ = i % 10 + '0'; +} + +// void pf_hex(unsigned int i) : output hexadecimal integer. + +pf_hex(i) +unsigned i; +{ + xpf_dpt = xpf_dst; + + pf_hex2(i); + + *xpf_dpt = '\0'; + + pf_sf(xpf_dst); +} + +// void pf_hex2(unsigned int i) : helper for pf_hex(). + +pf_hex2(i) +unsigned i; +{ + unsigned n; + + if(n = i / 16) + pf_hex2(n); + + i %= 16; + + *xpf_dpt++ = i < 10 ? '0' + i : 'A' + i - 10; +} + +// void pf_s(char *s) : output string. + +pf_s(s) +char *s; +{ + while(*s) + pf_out(*s++); +} + +// void pf_out(char c) : output character. + +#asm +pf_out: + PUSH HL + DEFB 0CDH +xpf_out: + DEFW 0 + POP BC + + EX DE,HL + + LD HL,(xpf_cnt) + INC HL + LD (xpf_cnt),HL + + LD A,D + OR E + RET Z +;; LD A,255 + LD (xpf_err),A + RET +#endasm + +// void pf_end(void) : end output. + +#asm +pf_end: + DEFB 0C3H +xpf_end: + DEFW 0 +#endasm + +#endif + + \ No newline at end of file diff --git a/README.md b/README.md index e92b0da..a8a5256 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ See this repository: https://git.imzadi.de/acn/backgammon-vt100 * [Battleships](Battleships/) * [Blocks](Blocks/) * [Robots](Robots/) +* [FindThatMine](FindThatMine/) ## More Games on the Interwebs