Skip to content

Commit

Permalink
TONS of changes. Added lists of all API calls needed for Qbasic
Browse files Browse the repository at this point in the history
compatibility. Implemented a lot of those things. Converted over to
newly adopted function name-mangling scheme.
  • Loading branch information
icculus committed Oct 9, 1998
1 parent 6a9da70 commit a89e4ea
Show file tree
Hide file tree
Showing 23 changed files with 450 additions and 191 deletions.
13 changes: 10 additions & 3 deletions BASIClib/BasicLib.h
Expand Up @@ -8,6 +8,8 @@
#ifndef _INCLUDE_BASICLIB_H_
#define _INCLUDE_BASICLIB_H_

#include "RegState.h"
#include "OnOffStopType.h"
#include "Initialize.h"
#include "InternalMemManager.h"
#include "BasicString.h"
Expand All @@ -20,11 +22,16 @@
#include "ConversionFunctions.h"
#include "TimeDateFunctions.h"
#include "Threads.h"
#include "LowLevel.h"
#include "FileIOFunctions.h"
#include "LowLevelFunctions.h"
#include "BasicFileStream.h"
#include "Console.h"
#include "FileIOFunctions.h"
#include "FileSystemFunctions.h"
#include "ConsoleFunctions.h"
#include "SignalHandlers.h"
#include "PenFunctions.h"
#include "StringFunctions.h"
/* !!! #include "JoystickFunctions.h" */
/* !!! #include "
#endif
Expand Down
133 changes: 117 additions & 16 deletions BASIClib/ConsoleFunctions.c
Expand Up @@ -8,17 +8,32 @@
#include "Console.h"
#include "Initialize.h"
#include "Boolean.h"
#include "Threads.h"
#include "ErrorFunctions.h"

boolean noConsole = true;

boolean consoleAllowed = true;
boolean inGraphicsMode = false;
WINDOW *cons = NULL;
ThreadLock consoleLock = NULL;


void inline __getConsoleAccess(STATEPARAMS)
{
if (consoleAllowed == false)
__runtimeError(STATEARGS, ERR_CANNOT_CONTINUE);
} /* __getConsoleAccess */


void __initConsole(STATEPARAMS)
{
noConsole = ((__getInitFlags() & INITFLAG_NO_CONSOLE) ? true : false);
consoleAllowed = ((__getInitFlags() & INITFLAG_NO_CONSOLE) ? false : true);

if (noConsole == false)
if (consoleAllowed == true)
{
cons = initscr();
__createThreadLock(&consoleLock);
initscr();
cons = newwin(0, 0, 0, 0); /* full screen virtual window. */
keypad(cons, TRUE)
(void) nonl();
(void) cbreak();
Expand All @@ -30,36 +45,122 @@ void __initConsole(STATEPARAMS)

void __deinitConsole(STATEPARAMS)
{
if (noConsole == false)
if (consoleAllowed == true)
{
endwin();
__destroyThreadLock(&consoleLock);
} /* if */
} /* __deinitConsole */


void print(STATEPARAMS, PVariant pVar)
void vbpV_print(STATEPARAMS, PVariant pVar)
{
PBasicString str = __variantToString(pVar);
PBasicString str;
int i;
int max = str->length;
char *data = str->data;
int max;
char *data;

__getConsoleAccess(STATEARGS);

str = __variantToString(pVar);
max = str->length;
*data = str->data;

__obtainThreadLock(&consoleLock);
for (i = 0; i < max; i++)
waddch(cons, data[i]);

wrefresh(cons);
__releaseThreadLock(&consoleLock);

__freeString(str);
} /* print */
} /* vbpV_print */


void vbpii_ViewPrint(STATEPARAMS, int topRow, int bottomRow)
{
int lines;
int columns;

__getConsoleAccess(STATEARGS);

__obtainThreadLock(&consoleLock);
getmaxyx(stdscr, lines, columns);

if ( (topRow < 0) || (bottomRow < topRow) || (bottomRow > lines) )
{
__releaseThreadLock(&consoleLock);
__runtimeError(STATEARGS, ERR_ILLEGAL_FUNCTION_CALL);
} /* if */

else
{
wresize(cons, (bottomRow - topRow) + 1, columns);
mvwin(cons, topRow, 0);
} /* else */

__releaseThreadLock(&consoleLock);
} /* vbpii_viewPrint */


void vbp_ViewPrint(STATEPARAMS)
{
int lines;
int columns;

__getConsoleAccess(STATEARGS);

__obtainThreadLock(&consoleLock);
getmaxyx(stdscr, lines, columns);
mvwin(cons, 0, 0);
wresize(cons, lines, columns);
__releaseThreadLock(&consoleLock);
} /* vbp_viewPrint */


void vbp_cls(STATEPARAMS)
{
__getConsoleAccess(STATEARGS);
__obtainThreadLock(&consoleLock);
wclear(cons);
wrefresh(cons);
__releaseThreadLock(&consoleLock);
} /* vbp_cls */


int vbi_csrline(STATEPARAMS)
{
int x;
int y;

__getConsoleAccess(STATEARGS);
__obtainThreadLock(&consoleLock);
getsyx(y, x);
__releaseThreadLock(&consoleLock);
return(y);
} /* vbi_csrline */


int vbiV_pos(STATEPARAMS, PVariant pVar)
{
int x;
int y;

/* How retarded to request a variant argument for no reason! */

__getConsoleAccess(STATEARGS);
__obtainThreadLock(&consoleLock);
getsyx(y, x);
__releaseThreadLock(&consoleLock);
return(x);
} /* vbiV_pos */

/* view print x to y */
/* cls */
/* color */
/* locate */
/* write */
/* input */
/* line input */
/* INKEY$ */
/* width */
/* csrline */
/* pos */
/* key */
/* print using */
/* tab */
Expand All @@ -82,5 +183,5 @@ void print(STATEPARAMS, PVariant pVar)
/* window */


/* end of Console.c ... */
/* end of ConsoleFunctions.c ... */

16 changes: 11 additions & 5 deletions BASIClib/ConsoleFunctions.h
Expand Up @@ -4,15 +4,21 @@
* Copyright (c) 1998 Ryan Gordon and Gregory S. Read.
*/

#ifndef _INCLUDE_CONSOLE_H_
#define _INCLUDE_CONSOLE_H_
#ifndef _INCLUDE_CONSOLEFUNCTIONS_H_
#define _INCLUDE_CONSOLEFUNCTIONS_H_

#include "RegState.h"

void __initConsole(STATEPARAMS);
void __deinitConsole(STATEPARAMS);
void __initConsole(STATEPARAMS)
void __deinitConsole(STATEPARAMS)
void vbpV_print(STATEPARAMS, PVariant pVar)
void vbpii_ViewPrint(STATEPARAMS, int topRow, int bottomRow)
void vbp_ViewPrint(STATEPARAMS)
void vbp_cls(STATEPARAMS)
int vbi_csrline(STATEPARAMS)
int vbiV_pos(STATEPARAMS, PVariant pVar)

#endif

/* end of Console.h ... */
/* end of ConsoleFunctions.h ... */

29 changes: 16 additions & 13 deletions BASIClib/ConversionFunctions.c
Expand Up @@ -15,7 +15,7 @@
#include "Boolean.h"


int asc(STATEPARAMS, PBasicString pBasicStr)
int vbiS_asc(STATEPARAMS, PBasicString pBasicStr)
/*
* Get the ASCII value of the first character of (str)...
*
Expand All @@ -31,11 +31,11 @@ int asc(STATEPARAMS, PBasicString pBasicStr)
retVal = (unsigned int) pBasicStr->data[0];

return(retVal);
} /* asc */
} /* vbiS_asc */



PBasicString chr_DC_(STATEPARAMS, double asciiValue)
PBasicString vbSd_chr_DC_(STATEPARAMS, double asciiValue)
/*
* Returns a new basic string of one character length based on the ascii
* value passed.
Expand All @@ -56,11 +56,11 @@ PBasicString chr_DC_(STATEPARAMS, double asciiValue)
} /* else */

return(retVal);
} /* chr_DC_ */
} /* vbSd_chr_DC_ */



PBasicString str_DC_(STATEPARAMS, double numeric)
PBasicString vbSd_str_DC_(STATEPARAMS, double numeric)
/*
* Convert a numeric to a BASIC string. If (numeric) is positive, the
* string contains a leading blank (' ') character. If negative, that
Expand Down Expand Up @@ -127,7 +127,7 @@ PBasicString str_DC_(STATEPARAMS, double numeric)
return(__createString(STATEARGS, buffer, false));
#endif

} /* str_DC_ */
} /* vbSd_str_DC_ */



Expand Down Expand Up @@ -188,7 +188,7 @@ int __valEndOfNumberString(STATEPARAMS, PBasicString pBasicStr)



double val(STATEPARAMS, PBasicString pBasicStr)
double vbdS_val(STATEPARAMS, PBasicString pBasicStr)
/*
* Convert a BASIC string into a numeric. This function stops conversion
* at the end of the string, or when it runs into a character it can't
Expand Down Expand Up @@ -238,11 +238,11 @@ double val(STATEPARAMS, PBasicString pBasicStr)
} /* for */

return(retVal);
} /* val */
} /* vbdS_val */



PBasicString hex_DC_(STATEPARAMS, double x)
PBasicString vbSd_hex_DC_(STATEPARAMS, double x)
/*
* Convert a numeric to a string in Hexadecimal format. Numeric is rounded
* as necessary.
Expand All @@ -261,11 +261,11 @@ PBasicString hex_DC_(STATEPARAMS, double x)
sprintf(buffer, "%X", rounded);

return(__createString(STATEARGS, buffer, false));
} /* hex_DC_ */
} /* vbSd_hex_DC_ */



PBasicString oct_DC_(STATEPARAMS, double x)
PBasicString vbSd_oct_DC_(STATEPARAMS, double x)
/*
* Convert a numeric to a string in Octal format. Numeric is rounded
* as necessary.
Expand All @@ -284,7 +284,7 @@ PBasicString oct_DC_(STATEPARAMS, double x)
sprintf(buffer, "%o", rounded);

return(__createString(STATEARGS, buffer, false));
} /* oct_DC_ */
} /* vbSd_oct_DC_ */



Expand Down Expand Up @@ -427,13 +427,16 @@ PBasicString __VariantToString(STATEPARAMS, PVariant pVar, boolean byRef)
retVal = pVar->data._string;
else
__assignString(STATEARGS, &retVal, pVar->data._string);
} // if
} /* if */
else
__runtimeError(STATEARGS, ERR_ILLEGAL_FUNCTION_CALL); /* !!! Is that the right error code? */

return(retVal);
} /* __VariantToString */

/* !!! still need: */
/* cvi, cvl, etc... mkd$, mkl$, etc... */


/* end of ConversionFunctions.c ... */

Expand Down
17 changes: 11 additions & 6 deletions BASIClib/ConversionFunctions.h
Expand Up @@ -11,12 +11,17 @@
#include "BasicString.h"
#include "Variant.h"

int asc(STATEPARAMS, PBasicString pBasicStr);
PBasicString chr_DC_(STATEPARAMS, double asciiValue);
PBasicString str_DC_(STATEPARAMS, double numeric);
double val(STATEPARAMS, PBasicString pBasicStr);
PBasicString hex_DC_(STATEPARAMS, double x);
PBasicString oct_DC_(STATEPARAMS, double x);
#define cdbl(var) ((double) var)
#define cint(var) ((int) var)
#define clng(var) ((long) var)
#define csng(var) ((float) var)

int vbiS_asc(STATEPARAMS, PBasicString pBasicStr);
PBasicString vbSd_chr_DC_(STATEPARAMS, double asciiValue);
PBasicString vbSd_str_DC_(STATEPARAMS, double numeric);
double vbdS_val(STATEPARAMS, PBasicString pBasicStr);
PBasicString vbSd_hex_DC_(STATEPARAMS, double x);
PBasicString vbSd_oct_DC_(STATEPARAMS, double x);
int __VariantToInt(STATEPARAMS, PVariant var);
long __VariantToLong(STATEPARAMS, PVariant var);
float __VariantToFloat(STATEPARAMS, PVariant var);
Expand Down

0 comments on commit a89e4ea

Please sign in to comment.