Move to the new build environment

This commit is contained in:
Jeremy Rand 2017-09-11 23:14:06 -04:00
parent 46bbabc8f9
commit e49487532a
124 changed files with 6119 additions and 6 deletions

BIN
.DS_Store vendored

Binary file not shown.

6
.gitignore vendored
View File

@ -1,6 +0,0 @@
.*.swp
*.o
*.r
*.root
abCalc
abCalcNDA

21
abCalc/Makefile Normal file
View File

@ -0,0 +1,21 @@
all:
make -f nda.mk gen
make -f nda.mk build
make -f shell.mk gen
make -f shell.mk build
gen:
make -f nda.mk gen
make -f shell.mk gen
build:
make -f nda.mk build
make -f shell.mk build
clean:
make -f shell.mk clean
make -f nda.mk clean
execute:
make -f nda.mk execute
# make -f shell.mk execute

75
abCalc/abCError.c Normal file
View File

@ -0,0 +1,75 @@
/*
abCError.c
By: Jeremy Rand
*/
#include <stdio.h>
#include <stdlib.h>
#include "abCError.h"
static char *gErrorStrings[abCalcErrorTypeMax];
static abCalcErrorType gCurrErrorType = abCalcNoError;
static char *gCurrErrorOpName = NULL;
char gErrorBuffer[128];
void abCalcErrorInit(void)
{
gErrorStrings[abCalcNoError] = NULL;
gErrorStrings[abCalcSyntaxError] = "Syntax Error";
gErrorStrings[abCalcBadArgTypeError] = "Bad Argument Type";
gErrorStrings[abCalcBadArgValueError] = "Bad Argument Value";
gErrorStrings[abCalcTooFewArgsError] = "Too Few Arguments";
gErrorStrings[abCalcStackFullError] = "Stack Full";
gErrorStrings[abCalcInfiniteResultError] = "Infinite Result";
gErrorStrings[abCalcComplexResultError] = "Complex Result";
}
void abCalcRaiseError(abCalcErrorType type, char *opName)
{
if ((type < abCalcErrorTypeMin) ||
(type >= abCalcErrorTypeMax))
return;
if (gCurrErrorType == abCalcNoError) {
gCurrErrorType = type;
gCurrErrorOpName = opName;
}
}
char *abCalcGetError(void)
{
char *errorString;
if ((gCurrErrorType < abCalcErrorTypeMin) ||
(gCurrErrorType >= abCalcErrorTypeMax))
return NULL;
errorString = gErrorStrings[gCurrErrorType];
if (errorString == NULL)
return NULL;
if (gCurrErrorOpName != NULL) {
sprintf(gErrorBuffer, "%s Error: %s", gCurrErrorOpName, gErrorStrings[gCurrErrorType]);
} else {
sprintf(gErrorBuffer, "Error: %s", gErrorStrings[gCurrErrorType]);
}
return gErrorBuffer;
}
void abCalcClearError(void)
{
gCurrErrorType = abCalcNoError;
gCurrErrorOpName = NULL;
}

35
abCalc/abCError.h Normal file
View File

@ -0,0 +1,35 @@
/*
abCError.h
By: Jeremy Rand
*/
#ifndef ABCERROR_H
#define ABCERROR_H
typedef enum abCalcErrorType {
abCalcErrorTypeMin = 0,
abCalcNoError,
abCalcSyntaxError,
abCalcBadArgTypeError,
abCalcBadArgValueError,
abCalcTooFewArgsError,
abCalcStackFullError,
abCalcInfiniteResultError,
abCalcComplexResultError,
abCalcErrorTypeMax
} abCalcErrorType;
void abCalcErrorInit(void);
void abCalcRaiseError(abCalcErrorType type, char *opName);
char *abCalcGetError(void);
void abCalcClearError(void);
#endif

47
abCalc/abCMode.c Normal file
View File

@ -0,0 +1,47 @@
/*
abCMode.c
By: Jeremy Rand
*/
#include "abCMode.h"
static abCalcModeIntBase gBase = abCalcModeDecBase;
static int gIntWidth = AB_CALC_EXPR_MAX_INT_WIDTH;
void abCalcModeInit(void)
{
}
abCalcModeIntBase abCalcModeGetBase(void)
{
return gBase;
}
void abCalcModeSetBase(abCalcModeIntBase base)
{
if ((base >= abCalcModeIntBaseMin) &&
(base < abCalcModeIntBaseMax)) {
gBase = base;
}
}
int abCalcModeGetIntWidth(void)
{
return gIntWidth;
}
void abCalcModeSetIntWidth(int width)
{
if ((width > 0) &&
(width <= AB_CALC_EXPR_MAX_INT_WIDTH)) {
gIntWidth = width;
}
}

37
abCalc/abCMode.h Normal file
View File

@ -0,0 +1,37 @@
/*
abCMode.h
By: Jeremy Rand
*/
#ifndef ABCMODE_H
#define ABCMODE_H
#include "expr/abCExpr.h"
typedef enum abCalcModeIntBase
{
abCalcModeIntBaseMin = 0,
abCalcModeBinBase = 0,
abCalcModeOctBase,
abCalcModeDecBase,
abCalcModeHexBase,
abCalcModeIntBaseMax
} abCalcModeIntBase;
void abCalcModeInit(void);
abCalcModeIntBase abCalcModeGetBase(void);
void abCalcModeSetBase(abCalcModeIntBase base);
int abCalcModeGetIntWidth(void);
void abCalcModeSetIntWidth(int width);
#endif

103
abCalc/abCStack.c Normal file
View File

@ -0,0 +1,103 @@
/*
abCStack.c
By: Jeremy Rand
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "abCStack.h"
#include "abCError.h"
abCalcExpr gStack[AB_CALC_STACK_DEPTH];
static int gStackNumItems = 0;
void abCalcStackInit(void)
{
}
abCalcExpr *abCalcStackExprPush(abCalcExpr *expr)
{
abCalcExpr *result = NULL;
if (gStackNumItems >= AB_CALC_STACK_DEPTH) {
abCalcRaiseError(abCalcStackFullError, NULL);
return NULL;
}
if ((gStackNumItems < AB_CALC_STACK_DEPTH) &&
(expr != NULL)) {
result = &(gStack[gStackNumItems]);
memcpy(result, expr, sizeof(*expr));
gStackNumItems++;
}
return result;
}
abCalcExpr *abCalcStackExprPop(abCalcExpr *expr)
{
abCalcExpr *result = NULL;
if (gStackNumItems < 1)
return NULL;
gStackNumItems--;
if (expr != NULL) {
result = expr;
memcpy(expr, &(gStack[gStackNumItems]), sizeof(*expr));
}
return result;
}
int abCalcStackNumItems(void)
{
return gStackNumItems;
}
abCalcExpr *abCalcStackExprAt(int depth)
{
abCalcExpr *result = NULL;
if (depth < gStackNumItems) {
result = &(gStack[gStackNumItems - 1 - depth]);
}
return result;
}
char *abCalcStackExprStringAt(int depth, char *buffer, int addPrefix)
{
static char tmpBuffer[AB_CALC_EXPR_STRING_MAX];
if (buffer == NULL)
return NULL;
if (addPrefix) {
sprintf(buffer, "%3d: ", depth + 1);
} else {
buffer[0] = '\0';
}
if (depth < gStackNumItems) {
if (abCalcFormatExpr(&(gStack[gStackNumItems - 1 - depth]), tmpBuffer) != NULL) {
strcat(buffer, tmpBuffer);
}
}
return buffer;
}
void abCalcStackClear(void)
{
gStackNumItems = 0;
}

32
abCalc/abCStack.h Normal file
View File

@ -0,0 +1,32 @@
/*
abCStack.h
By: Jeremy Rand
*/
#ifndef ABCSTACK_H
#define ABCSTACK_H
#include "expr/abCExpr.h"
#define AB_CALC_STACK_DEPTH 128
void abCalcStackInit(void);
abCalcExpr *abCalcStackExprPush(abCalcExpr *expr);
abCalcExpr *abCalcStackExprPop(abCalcExpr *expr);
abCalcExpr *abCalcStackExprAt(int depth);
char *abCalcStackExprStringAt(int depth, char *buffer, int addPrefix);
int abCalcStackNumItems(void);
void abCalcStackClear(void);
#endif

32
abCalc/abCalc.c Normal file
View File

@ -0,0 +1,32 @@
/*
abCalc.c
By: Jeremy Rand
*/
#include "abCMode.h"
#include "abCStack.h"
#include "abCError.h"
#include "expr/abCExpr.h"
#include "expr/abCExprInt.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
void abCalcInit(void)
{
abCalcExprInit();
abCalcExprRealInit();
abCalcExprIntInit();
abCalcModeInit();
abCalcStackInit();
abCalcOpInit();
abCalcErrorInit();
}

14
abCalc/abCalc.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCalc.h
By: Jeremy Rand
*/
#ifndef ABCALC_H
#define ABCALC_H
void abCalcInit(void);
#endif

File diff suppressed because one or more lines are too long

217
abCalc/expr/abCExpReal.c Normal file
View File

@ -0,0 +1,217 @@
/*
abCExpReal.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "expr/abCExpr.h"
static abCalcExpr *abCalcExprRealParse(abCalcExpr *expr, char *buffer);
static char *abCalcExprRealFormat(abCalcExpr *expr, char *buffer);
static abCalcExprCallbacks gRealCallbacks = {
abCalcExprRealParse,
abCalcExprRealFormat
};
void abCalcExprRealInit(void)
{
abCalcRegisterExprType(abCalcExprTypeReal, &gRealCallbacks);
}
abCalcExpr *abCalcExprRealParse(abCalcExpr *expr, char *buffer)
{
int offset;
int expOffset = -1;
int periodOffset = -1;
int len;
int numOffset = -1;
/* First validate */
if (buffer == NULL)
return NULL;
if (expr == NULL)
return NULL;
len = strlen(buffer);
for (offset = 0; offset < len; offset++) {
switch (buffer[offset]) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
numOffset = offset;
break;
case '.':
if (periodOffset != -1)
return NULL;
if (expOffset != -1)
return NULL;
periodOffset = offset;
break;
case '-':
if (offset == 0)
break;
/* Fallthrough */
case '+':
if ((expOffset == -1) ||
((expOffset + 1) != offset))
return NULL;
break;
case 'e':
case 'E':
if (expOffset != -1)
return NULL;
expOffset = offset;
numOffset = -1;
break;
default:
return NULL;
}
}
if (numOffset == -1)
return NULL;
expr->type = abCalcExprTypeReal;
expr->u.real = atof(buffer);
return expr;
}
char *abCalcExprRealFormat(abCalcExpr *expr, char *buffer)
{
abCalcRealType exp;
abCalcRealType value;
static char format[16];
int numDecDigits;
int periodPos = -1;
int zerosStart = -1;
int spaceStart = -1;
int expPos = -1;
int len;
int i;
if (expr == NULL)
return NULL;
if (buffer == NULL)
return NULL;
if (expr->type != abCalcExprTypeReal)
return NULL;
value = expr->u.real;
if (value == 0.0) {
exp = 0.0;
} else {
exp = floor(log10(fabs(value)));
}
if (exp >= 0)
exp++;
if ((exp > 12) ||
(exp < -12)) {
strcpy(format, "%-25.11E");
} else if (exp <= -2) {
double shiftedValue = value * 1.0e12;
if (shiftedValue == floor(shiftedValue)) {
strcpy(format, "%-18.12f");
} else {
strcpy(format, "%-25.11E");
}
} else {
int numDecDigits = (int)(12 - exp);
if (numDecDigits > 12) {
numDecDigits = 12;
}
sprintf(format, "%%-28.%df", numDecDigits);
}
sprintf(buffer, format, value);
len = strlen(buffer);
for (i = 0; i < len; i++) {
switch (buffer[i]) {
case '.':
periodPos = i;
break;
case '0':
if (expPos != -1) {
break;
}
if ((periodPos != -1) &&
(zerosStart == -1)) {
if (periodPos == i - 1) {
zerosStart = periodPos;
} else {
zerosStart = i;
}
}
break;
case 'E':
expPos = i;
break;
case ' ':
spaceStart = i;
break;
default:
if (expPos == -1)
zerosStart = -1;
break;
}
if (spaceStart != -1)
break;
}
if (spaceStart != -1) {
buffer[spaceStart] = '\0';
len = spaceStart;
}
if (zerosStart != -1) {
if (expPos != -1) {
memmove(&buffer[zerosStart], &buffer[expPos], len - expPos + 1);
len = expPos - zerosStart;
}
else {
buffer[zerosStart] = '\0';
}
}
return buffer;
}
void abCalcExprRealSet(abCalcExpr *expr, abCalcRealType value)
{
if (expr == NULL)
return;
expr->type = abCalcExprTypeReal;
expr->u.real = value;
}

17
abCalc/expr/abCExpReal.h Normal file
View File

@ -0,0 +1,17 @@
/*
abCExpReal.h
By: Jeremy Rand
*/
#ifndef ABCEXPREAL_H
#define ABCEXPREAL_H
struct abCalcExpr;
void abCalcExprRealInit(void);
void abCalcExprRealSet(struct abCalcExpr *expr, abCalcRealType value);
#endif

61
abCalc/expr/abCExpr.c Normal file
View File

@ -0,0 +1,61 @@
/*
abCExpr.c
By: Jeremy Rand
*/
#include <stdlib.h>
#include "expr/abCExpr.h"
static abCalcExprCallbacks *gCallbacks[abCalcExprTypeMax];
#define AB_CALC_EXPR_TYPE_INVALID(type) (((type) < abCalcExprTypeMin) || ((type) >= abCalcExprTypeMax))
void abCalcExprInit(void)
{
abCalcExprType type;
for (type = abCalcExprTypeMin; type < abCalcExprTypeMax; type++) {
gCallbacks[type] = NULL;
}
}
void abCalcRegisterExprType(abCalcExprType type, abCalcExprCallbacks *callbacks)
{
if (AB_CALC_EXPR_TYPE_INVALID(type))
return;
gCallbacks[type] = callbacks;
}
abCalcExpr *abCalcParseExpr(abCalcExpr *expr, char *buffer)
{
abCalcExpr *result = NULL;
abCalcExprType type;
for (type = abCalcExprTypeMin; type < abCalcExprTypeMax; type++) {
if (gCallbacks[type] != NULL) {
result = (gCallbacks[type]->parseExpr)(expr, buffer);
if (result != NULL)
return result;
}
}
return result;
}
char *abCalcFormatExpr(abCalcExpr *expr, char *buffer)
{
if (AB_CALC_EXPR_TYPE_INVALID(expr->type))
return NULL;
if (gCallbacks[expr->type] == NULL)
return NULL;
return (gCallbacks[expr->type]->formatExpr(expr, buffer));
}

51
abCalc/expr/abCExpr.h Normal file
View File

@ -0,0 +1,51 @@
/*
abCExpr.h
By: Jeremy Rand
*/
#ifndef ABCEXPR_H
#define ABCEXPR_H
typedef enum abCalcExprType {
abCalcExprTypeMin = 0,
abCalcExprTypeReal = 0,
abCalcExprTypeInt,
abCalcExprTypeMax
} abCalcExprType;
typedef double abCalcRealType;
typedef unsigned long abCalcIntType;
#define AB_CALC_EXPR_MAX_INT_WIDTH ((sizeof(abCalcIntType) * 8))
#define AB_CALC_EXPR_STRING_MAX (AB_CALC_EXPR_MAX_INT_WIDTH + 8)
typedef struct abCalcExpr {
abCalcExprType type;
union {
abCalcRealType real;
abCalcIntType integer;
} u;
} abCalcExpr;
typedef struct abCalcExprCallbacks {
abCalcExpr * (*parseExpr)(abCalcExpr *expr, char *buffer);
char * (*formatExpr)(abCalcExpr *expr, char *buffer);
} abCalcExprCallbacks;
void abCalcExprInit(void);
void abCalcRegisterExprType(abCalcExprType type, abCalcExprCallbacks *callbacks);
abCalcExpr *abCalcParseExpr(abCalcExpr *expr, char *buffer);
char *abCalcFormatExpr(abCalcExpr *expr, char *buffer);
#endif

272
abCalc/expr/abCExprInt.c Normal file
View File

@ -0,0 +1,272 @@
/*
abCExprInt.c
By: Jeremy Rand
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "abCMode.h"
#include "expr/abCExpr.h"
static abCalcExpr *abCalcExprIntParse(abCalcExpr *expr, char *buffer);
static char *abCalcExprIntFormat(abCalcExpr *expr, char *buffer);
static abCalcExprCallbacks gIntCallbacks = {
abCalcExprIntParse,
abCalcExprIntFormat
};
void abCalcExprIntInit(void)
{
abCalcRegisterExprType(abCalcExprTypeInt, &gIntCallbacks);
}
abCalcExpr *abCalcExprIntParse(abCalcExpr *expr, char *buffer)
{
abCalcModeIntBase base = abCalcModeGetBase();
abCalcIntType value = 0;
int len;
int offset = 1;
if (buffer == NULL)
return NULL;
if (expr == NULL)
return NULL;
len = strlen(buffer);
if (len < 2)
return NULL;
if (buffer[0] == '$') {
base = abCalcModeHexBase;
} else if ((buffer[0] == '0') &&
(buffer[1] == 'x')) {
base = abCalcModeHexBase;
offset = 2;
} else if (buffer[0] != '#')
return NULL;
switch (base) {
case abCalcModeBinBase:
for ( ; offset < len; offset++) {
value <<= 1;
switch (buffer[offset]) {
case '1':
value++;
break;
case '0':
break;
default:
return NULL;
}
}
break;
case abCalcModeOctBase:
for ( ; offset < len; offset++) {
value <<= 3;
switch (buffer[offset]) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
value += (buffer[offset] - '0');;
break;
default:
return NULL;
}
}
break;
case abCalcModeDecBase:
for ( ; offset < len; offset++) {
value *= 10;
switch (buffer[offset]) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
value += (buffer[offset] - '0');;
break;
default:
return NULL;
}
}
break;
case abCalcModeHexBase:
for ( ; offset < len; offset++) {
value <<= 4;
switch (buffer[offset]) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
value += (buffer[offset] - '0');;
break;
case 'a':
case 'A':
value += 10;
break;
case 'b':
case 'B':
value += 11;
break;
case 'c':
case 'C':
value += 12;
break;
case 'd':
case 'D':
value += 13;
break;
case 'e':
case 'E':
value += 14;
break;
case 'f':
case 'F':
value += 15;
break;
default:
return NULL;
}
}
break;
default:
return NULL;
}
expr->type = abCalcExprTypeInt;
expr->u.integer = value;
return expr;
}
char *abCalcExprIntFormat(abCalcExpr *expr, char *buffer)
{
abCalcModeIntBase base = abCalcModeGetBase();
int width = abCalcModeGetIntWidth();
abCalcIntType value;
char *ptr;
int gotFirstOne;
int i;
if (expr == NULL)
return NULL;
if (buffer == NULL)
return NULL;
if (expr->type != abCalcExprTypeInt)
return NULL;
value = expr->u.integer;
if (width < AB_CALC_EXPR_MAX_INT_WIDTH) {
value &= ((1l << width) - 1);
}
switch (base) {
case abCalcModeBinBase:
gotFirstOne = 0;
ptr = buffer;
*ptr = '#';
ptr++;
for (i = width - 1; i >= 0; i--) {
if ((value >> i) & 1) {
*ptr = '1';
ptr++;
gotFirstOne = 1;
} else {
if (gotFirstOne) {
*ptr = '0';
ptr++;
}
}
}
if (!gotFirstOne) {
*ptr = '0';
ptr++;
}
*ptr = ' ';
ptr++;
*ptr = 'b';
ptr++;
*ptr = '\0';
break;
case abCalcModeOctBase:
sprintf(buffer, "#%lo o", value);
break;
case abCalcModeDecBase:
sprintf(buffer, "#%lu d", value);
break;
case abCalcModeHexBase:
sprintf(buffer, "#%lX h", value);
break;
default:
return NULL;
}
return buffer;
}
void abCalcExprIntSet(abCalcExpr *expr, abCalcIntType value)
{
int width;
if (expr == NULL)
return;
width = abCalcModeGetIntWidth();
expr->type = abCalcExprTypeInt;
expr->u.integer = value;
if (width < AB_CALC_EXPR_MAX_INT_WIDTH) {
expr->u.integer &= ((1l << width) - 1);
}
}

19
abCalc/expr/abCExprInt.h Normal file
View File

@ -0,0 +1,19 @@
/*
abCExprInt.h
By: Jeremy Rand
*/
#ifndef ABCEXPRINT_H
#define ABCEXPRINT_H
struct abCalcExpr;
void abCalcExprIntInit(void);
void abCalcExprIntSet(struct abCalcExpr *expr, abCalcIntType value);
#endif

46
abCalc/make/config.txt Normal file
View File

@ -0,0 +1,46 @@
# GSplus configuration file version 0.13
s5d1 =
s5d2 =
s6d1 =
s6d2 =
s7d1 = ../abCalcNDA.2mg
g_limit_speed = 0
bram1[00] = 00 00 00 01 00 00 0d 06 02 01 01 00 01 00 00 00
bram1[10] = 00 00 07 06 02 01 01 00 00 00 0f 06 06 00 05 06
bram1[20] = 01 00 00 00 00 00 00 01 00 00 00 00 03 02 02 02
bram1[30] = 00 00 00 00 00 00 00 00 08 00 01 02 03 04 05 06
bram1[40] = 07 0a 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d
bram1[50] = 0e 0f ff ff ff ff ff ff ff 00 ff ff ff ff ff 81
bram1[60] = ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
bram1[70] = ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
bram1[80] = ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
bram1[90] = ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
bram1[a0] = ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
bram1[b0] = ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
bram1[c0] = ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
bram1[d0] = ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
bram1[e0] = ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
bram1[f0] = ff ff ff ff ff ff ff ff ff ff ff ff 52 06 f8 ac
bram3[00] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[10] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[20] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[30] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[40] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[50] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[60] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[70] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[80] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[90] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[a0] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[b0] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[c0] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[d0] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[e0] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
bram3[f0] = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00

109
abCalc/make/createDiskImage Executable file
View File

@ -0,0 +1,109 @@
#!/bin/sh
set -x
MOUNTDIR=/tmp/a2gs_mount.$$
TMPDISKIMAGE=/tmp/a2gs_diskimage_$$.2mg
TEMPLATEDISKIMAGE=make/system601.2mg
if [ $# -lt 3 ]
then
echo USAGE: $0 diskimage file directory
exit 1
fi
DISKIMAGE="$1"
shift
FILE="$1"
shift
DISKIMAGEDEST="$1"
shift
DEST="${MOUNTDIR}/${DISKIMAGEDEST}"
COPYDIRS=$*
cleanupAndExit()
{
umount "$MOUNTDIR" 2> /dev/null
rm -f "$TMPDISKIMAGE" 2> /dev/null
rm -f "$DISKIMAGE" 2> /dev/null
rmdir "$MOUNTDIR" 2> /dev/null
exit 1
}
if [ ! -f "$TEMPLATEDISKIMAGE" ]
then
echo Unable to find the template disk image, $TEMPLATEDISKIMAGE
cleanupAndExit
fi
cp "$TEMPLATEDISKIMAGE" "$TMPDISKIMAGE"
if [ $? != 0 ]
then
echo Unable to copy template disk image.
cleanupAndExit
fi
mkdir "$MOUNTDIR"
if [ $? != 0 ]
then
echo Unable to create the mount directory.
cleanupAndExit
fi
profuse -orw "$TMPDISKIMAGE" "$MOUNTDIR"
if [ $? != 0 ]
then
echo Unable to mount the disk image.
cleanupAndExit
fi
cp "$FILE" "$DEST"
if [ $? != 0 ]
then
echo Unable to copy the file to the disk image.
cleanupAndExit
fi
OLDDIR=`pwd`
for COPYDIR in $COPYDIRS
do
cd "$COPYDIR"
if [ $? != 0 ]
then
echo Unable to find $COPYDIR
cleanupAndExit
fi
find . -print | while read FILEORDIR
do
if [ -d "$FILEORDIR" ]
then
mkdir -p "${MOUNTDIR}/$FILEORDIR"
elif [ -f "$FILEORDIR" ]
then
cp "$FILEORDIR" "${MOUNTDIR}/$FILEORDIR"
fi
done
cd "$OLDDIR"
done
umount "$MOUNTDIR"
if [ $? != 0 ]
then
echo Unable to unmount the disk image.
cleanupAndExit
fi
cp "$TMPDISKIMAGE" "$DISKIMAGE"
if [ $? != 0 ]
then
echo Unable to copy the disk image to the destination.
cleanupAndExit
fi
rm -f "$TMPDISKIMAGE"
rmdir "$MOUNTDIR"
exit 0

52
abCalc/make/head.mk Normal file
View File

@ -0,0 +1,52 @@
#
# head.mk
#
ORCA_HOME := $(HOME)/orca
ORCA_BINDIR = /usr/local/bin
export ORCA=$(ORCA_BINDIR)/orca
AC=make/AppleCommander.jar
TARGETTYPE=shell
SRCDIRS=.
COMPILE=make/orca-cc
CFLAGS= -P -I
ROOTCFILE=main.c
DEFINES=
INCLUDE_PATHS=
REZ=make/orca-rez
REZFLAGS=
MACGEN=make/orca-macgen
MACGENFLAGS=-P
MACGENMACROS=13/ORCAInclude/m=
ASSEMBLE=make/orca-asm
ASMFLAGS=-P
LINK=$(ORCA) link
LDFLAGS=-P
CHTYP=$(ORCA) chtyp
RM=rm -f
CP=cp
GSPLUS=/Applications/GSplus.app/Contents/MacOS/gsplus
GSPORT=/Applications/GSport/GSport.app/Contents/MacOS/GSport
export GSPLUS
export GSPORT
.PHONY: all gen genclean
all:
@make gen
@make build

29
abCalc/make/launchEmulator Executable file
View File

@ -0,0 +1,29 @@
#!/bin/sh
if [ ! -z "$GSPLUS" ] && [ -x "$GSPLUS" ]
then
EMULATORPATH="$GSPLUS"
elif [ ! -z "$GSPORT" ] && [ -x "$GSPORT" ]
then
EMULATORPATH="$GSPORT"
fi
if [ -z "$EMULATORPATH" ]
then
echo Unable to find GSplus or GSport at these locations.
echo " GSPLUS=$GSPLUS"
echo " GSPORT=$GSPORT"
exit 1
fi
cd make
# This magic ensure that clicking stop in Xcode results in the emulator terminating.
$EMULATORPATH &
PID=$!
trap 'kill $PID' SIGTERM SIGINT SIGHUP EXIT
wait
exit 0

18
abCalc/make/orca-asm Executable file
View File

@ -0,0 +1,18 @@
#!/bin/bash
FILENAME="$1"
shift
if echo $FILENAME | grep -v '\.s$' > /dev/null
then
echo Expected first argument to be a *.s file but got $FILENAME
exit 1
fi
DIRNAME=`dirname $FILENAME`
BASENAME=`basename $FILENAME .s`
cd "$DIRNAME"
$ORCA assemble $* keep="${BASENAME}" "${BASENAME}.s"
RESULT=$?
exit $RESULT

66
abCalc/make/orca-cc Executable file
View File

@ -0,0 +1,66 @@
#!/bin/bash
TMPFILE=/tmp/orca-cc.$$
FILENAME="$1"
shift
if echo $FILENAME | grep -v '\.c$' > /dev/null
then
echo Expected first argument to be a *.c file but got $FILENAME
exit 1
fi
CCARGS=""
COMPILEARGS=""
for ARG in $*
do
if echo $ARG | grep '^-[id]' > /dev/null
then
CCARGS="$CCARGS cc=$ARG"
else
COMPILEARGS="$COMPILEARGS $ARG"
fi
done
BASENAME=`echo $FILENAME | sed 's/\.c$//'`
DEPSNAME="${BASENAME}.d"
OBJSNAME="${BASENAME}.a"
ROOTNAME="${BASENAME}.root"
$ORCA --trace-gsos compile $COMPILEARGS "$FILENAME" keep="${BASENAME}" $CCARGS 2> $TMPFILE
RESULT=$?
sed '/^[A-Za-z][A-Za-z]*(.*)$/d' $TMPFILE >&2
if [ "$RESULT" -ne 0 ]
then
rm -f $TMPFILE
rm -f $OBJSNAME
rm -f $ROOTNAME
exit $RESULT
fi
DEPS=`awk '
/^FastFileLoad/ {
sub(/^FastFileLoad\(/, "");
sub(/\)$/, "");
print}' $TMPFILE | sort -u | while read FILE
do
if [ -f "$FILE" ]
then
echo $FILE
fi
done | tr '\012' ' '`
rm -f $TMPFILE
# We add a dependency for both the .o and the .root file. If this is the
# main.c file being compiled, we need the dependency on the .root file.
cat > $DEPSNAME << EOF
$OBJSNAME: $DEPS
$ROOTNAME: $DEPS
EOF
exit 0

50
abCalc/make/orca-macgen Executable file
View File

@ -0,0 +1,50 @@
#!/bin/bash
TMPFILE=/tmp/orca-macgen.$$
MACGENFLAGS="$1"
FILENAME="$2"
shift
shift
if echo $FILENAME | grep -v '\.s$' > /dev/null
then
echo Expected second argument to be a *.s file but got $FILENAME
exit 1
fi
BASENAME=`echo $FILENAME | sed 's/\.s$//'`
MACROSNAME="${BASENAME}.macros"
DEPSNAME="${MACROSNAME}.d"
$ORCA --trace-gsos macgen $MACGENFLAGS "$FILENAME" $* < /dev/null 2> $TMPFILE
RESULT=$?
sed '/^[A-Za-z][A-Za-z]*(.*)$/d' $TMPFILE >&2
if [ "$RESULT" -ne 0 ]
then
rm -f $TMPFILE
rm -f $MACROSNAME
exit $RESULT
fi
DEPS=`awk '
/^FastFileLoad/ {
sub(/^FastFileLoad\(/, "");
sub(/\)$/, "");
print}' $TMPFILE | sort -u | while read FILE
do
if [ -f "$FILE" ]
then
echo $FILE
fi
done | tr '\012' ' '`
rm -f $TMPFILE
cat > $DEPSNAME << EOF
$MACROSNAME: $DEPS
EOF
exit 0

45
abCalc/make/orca-rez Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
TMPFILE=/tmp/orca-rez.$$
FILENAME="$1"
shift
if echo $FILENAME | grep -v '\.rez$' > /dev/null
then
echo Expected first argument to be a *.rez file but got $FILENAME
exit 1
fi
BASENAME=`echo $FILENAME | sed 's/\.rez$//'`
DEPSNAME="${BASENAME}.rez.d"
OBJSNAME="${BASENAME}.r"
$ORCA --trace-gsos compile $* keep="${OBJSNAME}" "$FILENAME" 2> $TMPFILE
RESULT=$?
sed '/^[A-Za-z][A-Za-z]*(.*)$/d' $TMPFILE >&2
if [ "$RESULT" -ne 0 ]
then
rm -f $TMPFILE
rm -f $OBJSNAME
exit $RESULT
fi
DEPS=`awk '
/^FastFileLoad/ {
sub(/^FastFileLoad\(/, "");
sub(/\)$/, "");
print}' $TMPFILE | sort -u | while read FILE
do
if [ -f "$FILE" ]
then
echo $FILE
fi
done`
echo $OBJSNAME: $DEPS > $DEPSNAME
rm -f $TMPFILE
exit 0

BIN
abCalc/make/system601.2mg Normal file

Binary file not shown.

155
abCalc/make/tail.mk Normal file
View File

@ -0,0 +1,155 @@
#
# tail.mk
#
export PATH := $(PATH):$(ORCA_BIN)
CWD=$(shell pwd)
DISKIMAGE=$(PGM).2mg
BUILDTARGET=$(DISKIMAGE)
EXECTARGET=executeGUI
DISKIMAGEDEST=.
ifeq ($(TARGETTYPE),shell)
FILETYPE=exe
EXECTARGET=executeShell
BUILDTARGET=$(PGM)
else ifeq ($(TARGETTYPE),desktop)
FILETYPE=s16
else ifeq ($(TARGETTYPE),cda)
FILETYPE=cda
DISKIMAGEDEST=System/Desk.Accs
else ifeq ($(TARGETTYPE),cdev)
BINTARGET=$(PGM).bin
FILETYPE=199
DISKIMAGEDEST=System/CDevs
else ifeq ($(TARGETTYPE),nba)
FILETYPE=exe
BUILDTARGET=$(PGM)
else ifeq ($(TARGETTYPE),nda)
FILETYPE=nda
DISKIMAGEDEST=System/Desk.Accs
else ifeq ($(TARGETTYPE),xcmd)
FILETYPE=exe
BUILDTARGET=$(PGM)
endif
ifeq ($(wildcard $(ROOTCFILE)),)
ROOTCFILE=
endif
C_ROOTS=$(ROOTCFILE:.c=.root)
C_SRCS+=$(filter-out $(ROOTCFILE), $(patsubst ./%, %, $(wildcard $(addsuffix /*.c, $(SRCDIRS)))))
C_OBJS=$(C_SRCS:.c=.a)
C_DEPS=$(ROOTCFILE:.c=.d) $(C_SRCS:.c=.d)
ASM_SRCS=$(patsubst ./%, %, $(wildcard $(addsuffix /*.s, $(SRCDIRS))))
ASM_MACROS=$(ASM_SRCS:.s=.macros)
ASM_DEPS=$(ASM_SRCS:.s=.macros.d)
ASM_ROOTS=$(ASM_SRCS:.s=.ROOT)
ASM_OBJS=$(ASM_SRCS:.s=.a)
REZ_SRCS=$(patsubst ./%, %, $(wildcard $(addsuffix /*.rez, $(SRCDIRS))))
REZ_DEPS=$(REZ_SRCS:.rez=.rez.d)
REZ_OBJS=$(REZ_SRCS:.rez=.r)
ifneq ($(firstword $(REZ_SRCS)), $(lastword $(REZ_SRCS)))
$(error Only a single resource file supported, found $(REZ_SRCS))
endif
BUILD_OBJS=$(C_ROOTS) $(C_OBJS) $(ASM_ROOTS)
ifeq ($(BINTARGET),)
BUILD_OBJS+=$(REZ_OBJS)
endif
BUILD_OBJS_NOSUFFIX=$(C_ROOTS:.root=) $(C_OBJS:.a=) $(ASM_ROOTS:.ROOT=)
ALL_OBJS=$(C_ROOTS:.root=.a) $(C_OBJS) $(ASM_OBJS) $(REZ_OBJS)
ALL_ROOTS=$(C_ROOTS) $(C_OBJS:.a=.root) $(ASM_ROOTS)
ALL_DEPS=$(C_DEPS) $(ASM_DEPS) $(REZ_DEPS)
EXECCMD=
.PHONY: build execute executeShell executeGUI clean
.PRECIOUS: $(ASM_MACROS)
build: $(BUILDTARGET)
clean: genclean
$(RM) "$(PGM)" $(BINTARGET)
$(RM) $(ALL_OBJS)
$(RM) $(ALL_ROOTS)
$(RM) $(ALL_DEPS)
$(RM) $(ASM_MACROS)
$(RM) "$(DISKIMAGE)"
createPackage:
pkg/createPackage
cleanMacCruft:
rm -rf pkg
ifeq ($(BINTARGET),)
# This is a standard build where we generate the resources if any and then link
# the binary over that same file creating the resource fork first and the data
# fork second.
$(PGM): $(BUILD_OBJS)
ifneq ($(REZ_OBJS),)
$(RM) $(PGM)
$(CP) $(REZ_OBJS) $(PGM)
endif
$(LINK) $(LDFLAGS) $(BUILD_OBJS_NOSUFFIX) --keep=$(PGM)
$(CHTYP) -t $(FILETYPE) $(PGM)
else
# This is a special build for CDevs (maybe others also?) where we build the binary
# into a $(PGM).bin file and then build the resources into the $(PGM) target. The
# resource compile will read the $(PGM).bin binary and load it into the resources
# also.
$(BINTARGET): $(BUILD_OBJS)
$(LINK) $(LDFLAGS) $(BUILD_OBJS_NOSUFFIX) --keep=$(BINTARGET)
$(REZ_OBJS): $(BINTARGET)
$(PGM): $(REZ_OBJS)
$(RM) $(PGM)
$(CP) $(REZ_OBJS) $(PGM)
$(CHTYP) -t $(FILETYPE) $(PGM)
endif
$(DISKIMAGE): $(PGM)
make/createDiskImage "$(DISKIMAGE)" "$(PGM)" "$(DISKIMAGEDEST)" $(COPYDIRS)
execute: $(EXECTARGET)
executeGUI: all
make/launchEmulator -doit
executeShell: all
$(ORCA) ./$(PGM)
%.a: %.c
$(COMPILE) $< $(CFLAGS) --noroot
%.root: %.c
$(COMPILE) $< $(CFLAGS)
%.macros: %.s
$(MACGEN) "$(MACGENFLAGS)" $< $@ $(MACGENMACROS)
%.ROOT: %.macros
$(ASSEMBLE) $(<:.macros=.s) $(ASMFLAGS)
%.r: %.rez
$(REZ) $< $(REZFLAGS)
$(OBJS): Makefile
# Include the C and rez dependencies which were generated from the last build
# so we recompile correctly on .h file changes.
-include $(ALL_DEPS)

99
abCalc/nda.mk Normal file
View File

@ -0,0 +1,99 @@
#
# Makefile
# Apple //GS Build Engine for ORCA
#
include make/head.mk
# Customize this file to control what kind of project you are working on,
# where to find files, etc.
# The name of your system or binary file to build goes here:
PGM=abCalcNDA
# Set the target type you would like to build. The options are:
# shell - A shell command for ORCA, GNO or other GS shell
# desktop - A full desktop application
# cda - A classic desk accessory
# cdev - A control panel device
# nba - A HyperStudio new button action
# nda - A new desk accessory
# xcmd - A HyperCard XCMD or XCFN
#
# TARGETTYPE=shell
# TARGETTYPE=desktop
# TARGETTYPE=cda
# TARGETTYPE=cdev
# TARGETTYPE=nba
TARGETTYPE=nda
# TARGETTYPE=xcmd
# Add any other directories where you are putting C or assembly source
# files to this list:
# SRCDIRS+=
SRCDIRS+=nda expr ops
# If you put your main entry point for your project in a file called main.c
# Then you don't need to change this value. If you want to call your entry
# point something other than main.c, set this variable to point to this file.
ROOTCFILE=nda/abCalcNDA.c
# Add any arguments you want passed to the C compiler to this variable:
CFLAGS+=-dABCALC_GSOS
# Add any arguments you want passed to the resource compiler to this variable:
REZFLAGS+=
# Add any arguments you want passed to the macro generator to this variable:
MACGENFLAGS+=
# Add any other macro libraries to include in this variable:
MACGENMACROS+=
# Add any arguments you want passed to the assembler to this variable:
ASMFLAGS+=
# Add any arguments you want passed to the linker to this variable:
LDFLAGS+=
# Uncomment the following line if you want to build against the GNO libraries
# export ORCA=$(ORCA_BINDIR)/gno
# If you want to copy one or more files or directories to the target disk
# image, add the root directory to this variable. Any directories under
# the source directory which don't exist in the target disk image will be
# created. All files will be copied from the source to the target using
# the same path from the source.
#
# For example, if you set COPYDIRS to dir and in your project you have
# the following files:
# dir/System/mySystemFile
# dir/newDir/anotherFile
# Then, during the copy phase, mySystemFile will be copied into the System
# folder and a folder newDir will be created and anotherFile will be copied
# into there.
COPYDIRS=copydir
# By default, the build expects that you have GSplus in the path:
# /Applications/GSplus.app/Contents/MacOS/gsplus
# If you have it in a different location, specify that here.
# GSPLUS=/Applications/GSplus.app/Contents/MacOS/gsplus
# By default, the build expects that you have GSport in the path:
# /Applications/GSport/GSport.app/Contents/MacOS/GSport
# If you have it in a different location, specify that here.
# GSPORT=/Applications/GSport/GSport.app/Contents/MacOS/GSport
# Add any rules you want to execute before any compiles or assembly
# commands are called here, if any. You can generate .c, .s or .h
# files for example. You can generate data files. Whatever you
# might need.
gen:
# For any files you generated in the gen target above, you should
# add rules in genclean to remove those generated files when you
# clean your build.
genclean:
# Do not change anything else below here...
include make/tail.mk

764
abCalc/nda/abCalcNDA.c Normal file
View File

@ -0,0 +1,764 @@
/*
abCalcNDA.c
By: Jeremy Rand
*/
#pragma nda NDAOpen NDAClose NDAAction NDAInit -1 0xFFFF " abCalc\\H**"
#include <orca.h>
#include <GSOS.h>
#include <Locator.h>
#include <QuickDraw.h>
#include <Window.h>
#include <Desk.h>
#include <Resources.h>
#include <Memory.h>
#include <Loader.h>
#include <Control.h>
#include <Event.h>
#include <List.h>
#include <Sane.h>
#include <LineEdit.h>
#include <Scrap.h>
#include <string.h>
#include <stdlib.h>
#include "nda/abCalcNDA.h"
#include "abCalc.h"
#include "abCStack.h"
#include "abCError.h"
#include "expr/abCExpr.h"
#include "ops/abCOp.h"
#define MIN_STACK_ITEMS 4
void UpdateStack(void);
typedef struct listElement {
char *memPtr;
Byte memFlag;
} listElement;
static BOOLEAN gListStarted = FALSE;
static Handle gSANEDirectPage = NULL;
static BOOLEAN gCalcActive = FALSE;
static GrafPortPtr gCalcWinPtr = NULL;
static unsigned int gUserId;
static unsigned int gResourceId;
listElement *gOpList = NULL;
listElement gStackList[AB_CALC_STACK_DEPTH];
abCalcExpr gNDAExpr;
static Str255 gStrBuf;
static int gSelectedStackItem = -1;
char *gBuffer = NULL;
void NDAClose(void)
{
int i;
if (gCalcActive) {
CloseWindow(gCalcWinPtr);
gCalcWinPtr = NULL;
gCalcActive = FALSE;
}
if (gBuffer != NULL) {
free(gBuffer);
gBuffer = NULL;
}
if (gOpList != NULL) {
free(gOpList);
gOpList = NULL;
}
for (i = 0; i < AB_CALC_STACK_DEPTH; i++) {
if (gStackList[i].memPtr != NULL) {
free(gStackList[i].memPtr);
gStackList[i].memPtr = NULL;
}
}
CloseResourceFile(gResourceId);
ResourceShutDown();
}
void NDAInit(int code)
{
int i;
if (code) {
gCalcActive = FALSE;
gUserId = MMStartUp();
if (!ListStatus()) {
LoadOneTool(0x1c, 0);
ListStartUp();
gListStarted = TRUE;
}
if (!SANEStatus()) {
LoadOneTool(0x0a, 0);
gSANEDirectPage = NewHandle(256, gUserId,
attrBank | attrFixed | attrLocked | attrPage, NULL);
SANEStartUp((Word) *gSANEDirectPage);
}
abCalcInit();
for (i = 0; i < AB_CALC_STACK_DEPTH; i++) {
gStackList[i].memPtr = NULL;
}
} else {
if (gSANEDirectPage) {
SANEShutDown();
DisposeHandle(gSANEDirectPage);
UnloadOneTool(0x0a);
gSANEDirectPage = NULL;
}
if (gListStarted) {
ListShutDown();
UnloadOneTool(0x1c);
gListStarted = FALSE;
}
}
}
#pragma databank 1
void DrawContents(void)
{
PenNormal();
DrawControls(GetPort());
}
#pragma databank 0
GrafPortPtr NDAOpen(void)
{
Pointer pathToSelf;
unsigned int oldResourceApp;
LevelRecGS levelDCB;
unsigned int oldLevel;
SysPrefsRecGS prefsDCB;
unsigned int oldPrefs;
int numOps;
int i;
Handle opListCtl;
if (gCalcActive)
return NULL;
oldResourceApp = GetCurResourceApp();
ResourceStartUp(gUserId);
pathToSelf = LGetPathname2(gUserId, 1);
levelDCB.pCount = 2;
GetLevelGS(&levelDCB);
oldLevel = levelDCB.level;
levelDCB.level = 0;
SetLevelGS(&levelDCB);
prefsDCB.pCount = 1;
GetSysPrefsGS(&prefsDCB);
oldPrefs = prefsDCB.preferences;
prefsDCB.preferences = (prefsDCB.preferences & 0x1fff) | 0x8000;
SetSysPrefsGS(&prefsDCB);
gResourceId = OpenResourceFile(readEnable, NULL, pathToSelf);
gCalcWinPtr = NewWindow2("\p abCalc ", 0, DrawContents, NULL, refIsResource,
abCalcWinNum, rWindParam1);
SetSysWindow(gCalcWinPtr);
ShowWindow(gCalcWinPtr);
SelectWindow(gCalcWinPtr);
SetPort(gCalcWinPtr);
if (gOpList == NULL) {
numOps = abCalcOpNumOps();
gOpList = malloc(sizeof(*gOpList) * numOps);
for (i = 0; i < numOps; i++) {
gOpList[i].memPtr = abCalcOpNth(i)->name;
gOpList[i].memFlag = 0;
}
}
opListCtl = (Handle)GetCtlHandleFromID(gCalcWinPtr, abCalcOpList);
NewList2(NULL, 1, (Ref)gOpList, 0, numOps, opListCtl);
UpdateStack();
gCalcActive = TRUE;
prefsDCB.preferences = oldPrefs;
SetSysPrefsGS(&prefsDCB);
levelDCB.level = oldLevel;
SetLevelGS(&levelDCB);
SetCurResourceApp(oldResourceApp);
return gCalcWinPtr;
}
void UpdateStack(void)
{
Handle stackListCtl;
int i;
int numToDisplay = abCalcStackNumItems();
if (numToDisplay < MIN_STACK_ITEMS) {
numToDisplay = MIN_STACK_ITEMS;
}
stackListCtl = (Handle)GetCtlHandleFromID(gCalcWinPtr, abCalcStackList);
for (i = numToDisplay - 1; i >= 0; i--) {
if (gStackList[i].memPtr == NULL) {
gStackList[i].memPtr = malloc(AB_CALC_EXPR_STRING_MAX + 8);
}
abCalcStackExprStringAt(numToDisplay - i - 1, gStackList[i].memPtr,
TRUE);
gStackList[i].memFlag = 0;
}
NewList2(NULL, numToDisplay - 3, (Ref)gStackList, 0, numToDisplay, stackListCtl);
gSelectedStackItem = -1;
}
BOOLEAN ErrorRaised(void)
{
char *errorString = abCalcGetError();
if (errorString == NULL) {
return FALSE;
}
AlertWindow(awCString+awResource, (Pointer)&errorString, abCalcErrorAlert);
abCalcClearError();
return TRUE;
}
void PushCalcEntry(CtlRecHndl entryBox)
{
abCalcOp *op;
GetLETextByID(gCalcWinPtr, abCalcEntryBox, &gStrBuf);
if (gStrBuf.textLength > 0) {
gStrBuf.text[gStrBuf.textLength] = '\0';
op = abCalcOpLookup(gStrBuf.text);
if (op != NULL) {
op->execute();
} else if (abCalcParseExpr(&gNDAExpr, gStrBuf.text) != NULL) {
abCalcStackExprPush(&gNDAExpr);
} else {
LERecHndl leHandle;
HLock((Handle)entryBox);
leHandle = (LERecHndl)(*entryBox)->ctlData;
HUnlock((Handle)entryBox);
LESetSelect(0, gStrBuf.textLength, leHandle);
abCalcRaiseError(abCalcSyntaxError, NULL);
return;
}
gStrBuf.textLength = 0;
SetLETextByID(gCalcWinPtr, abCalcEntryBox, &gStrBuf);
}
}
void ExecCalcCmd(char *cmd)
{
abCalcOp *op = abCalcOpLookup(cmd);
CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox);
PushCalcEntry(entryBox);
if ((!ErrorRaised()) &&
(op != NULL)) {
op->execute();
}
ErrorRaised();
UpdateStack();
}
void InsertChar(CtlRecHndl entryBox, char ch)
{
LERecHndl leHandle;
HLock((Handle)entryBox);
leHandle = (LERecHndl)(*entryBox)->ctlData;
HUnlock((Handle)entryBox);
LEDelete(leHandle);
LEInsert(&ch, 1, leHandle);
}
void ExecMinusButton(void)
{
int i;
char aChar;
BOOLEAN doCmd = FALSE;
BOOLEAN dotSeen = FALSE;
CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox);
GetLETextByID(gCalcWinPtr, abCalcEntryBox, &gStrBuf);
if (gStrBuf.textLength > 0) {
doCmd = TRUE;
gStrBuf.text[gStrBuf.textLength] = '\0';
aChar = gStrBuf.text[gStrBuf.textLength - 1];
if (((aChar == 'e') ||
(aChar == 'E')) &&
(gStrBuf.textLength > 1)) {
doCmd = FALSE;
for (i = 0; i < gStrBuf.textLength - 1; i++) {
switch (gStrBuf.text[i]) {
case '-':
if (i != 0) {
doCmd = TRUE;
}
break;
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
break;
case '.':
if (dotSeen) {
doCmd = TRUE;
} else {
dotSeen = TRUE;
}
break;
default:
doCmd = TRUE;
break;
}
if (doCmd)
break;
}
}
}
if (doCmd) {
ExecCalcCmd("-");
} else {
InsertChar(entryBox, '-');
}
return;
}
void HandleEntryBox(void)
{
Handle stackListCtl = (Handle)GetCtlHandleFromID(gCalcWinPtr, abCalcStackList);
if (gSelectedStackItem != -1) {
ResetMember2(stackListCtl);
DrawMember2(gSelectedStackItem, stackListCtl);
gSelectedStackItem = -1;
}
}
void HandleStackClick(void)
{
Handle stackListCtl = (Handle)GetCtlHandleFromID(gCalcWinPtr, abCalcStackList);
int nthOp;
int numStackItems = abCalcStackNumItems();
int numDisplayed = numStackItems;
int selectedStackItem = -1;
nthOp = NextMember2(0, stackListCtl);
if (nthOp == gSelectedStackItem) {
ResetMember2(stackListCtl);
DrawMember2(gSelectedStackItem, stackListCtl);
gSelectedStackItem = -1;
nthOp = NextMember2(0, stackListCtl);
}
if (nthOp == 0)
return;
if (numDisplayed < MIN_STACK_ITEMS)
numDisplayed = MIN_STACK_ITEMS;
selectedStackItem = numDisplayed + 1 - nthOp;
if (selectedStackItem > numStackItems) {
ResetMember2(stackListCtl);
DrawMember2(nthOp, stackListCtl);
gSelectedStackItem = -1;
} else {
gSelectedStackItem = nthOp;
}
}
void HandleOpClick(void)
{
Handle opListCtl = (Handle)GetCtlHandleFromID(gCalcWinPtr, abCalcOpList);
int nthOp = ResetMember2(opListCtl);
abCalcOp *op;
if (nthOp > 0) {
nthOp--;
op = abCalcOpNth(nthOp);
if (op != NULL) {
CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox);
PushCalcEntry(entryBox);
if (!ErrorRaised()) {
op->execute();
}
ErrorRaised();
UpdateStack();
}
DrawMember2(nthOp + 1, opListCtl);
}
}
void HandleControl(EventRecord *event)
{
CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox);
SetPort(gCalcWinPtr);
switch (event->wmTaskData4) {
case abCalcBtn0:
InsertChar(entryBox, '0');
break;
case abCalcBtn1:
InsertChar(entryBox, '1');
break;
case abCalcBtn2:
InsertChar(entryBox, '2');
break;
case abCalcBtn3:
InsertChar(entryBox, '3');
break;
case abCalcBtn4:
InsertChar(entryBox, '4');
break;
case abCalcBtn5:
InsertChar(entryBox, '5');
break;
case abCalcBtn6:
InsertChar(entryBox, '6');
break;
case abCalcBtn7:
InsertChar(entryBox, '7');
break;
case abCalcBtn8:
InsertChar(entryBox, '8');
break;
case abCalcBtn9:
InsertChar(entryBox, '9');
break;
case abCalcBtnEnter:
PushCalcEntry(entryBox);
ErrorRaised();
UpdateStack();
break;
case abCalcBtnDot:
InsertChar(entryBox, '.');
break;
case abCalcBtnNum:
InsertChar(entryBox, '#');
break;
case abCalcBtnAdd:
ExecCalcCmd("+");
break;
case abCalcBtnSub:
ExecMinusButton();
break;
case abCalcBtnMult:
ExecCalcCmd("*");
break;
case abCalcBtnDiv:
ExecCalcCmd("/");
break;
case abCalcBtnPow:
ExecCalcCmd("^");
break;
case abCalcBtnA:
InsertChar(entryBox, 'A');
break;
case abCalcBtnB:
InsertChar(entryBox, 'B');
break;
case abCalcBtnC:
InsertChar(entryBox, 'C');
break;
case abCalcBtnD:
InsertChar(entryBox, 'D');
break;
case abCalcBtnE:
InsertChar(entryBox, 'E');
break;
case abCalcBtnF:
InsertChar(entryBox, 'F');
break;
case abCalcEntryBox:
HandleEntryBox();
break;
case abCalcStackList:
HandleStackClick();
break;
case abCalcOpList:
HandleOpClick();
break;
}
}
void DoCut(void)
{
LERecHndl leHandle;
CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox);
HLock((Handle)entryBox);
leHandle = (LERecHndl)(*entryBox)->ctlData;
HUnlock((Handle)entryBox);
LECut(leHandle);
LEToScrap();
}
void DoCopy(void)
{
Handle stackListCtl = (Handle)GetCtlHandleFromID(gCalcWinPtr, abCalcStackList);
LERecHndl leHandle;
CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox);
int numStackItems = abCalcStackNumItems();
int numDisplayed = numStackItems;
int selectedStackItem;
if (gSelectedStackItem == -1) {
HLock((Handle)entryBox);
leHandle = (LERecHndl)(*entryBox)->ctlData;
HUnlock((Handle)entryBox);
LECopy(leHandle);
LEToScrap();
return;
}
if (numDisplayed < MIN_STACK_ITEMS)
numDisplayed = MIN_STACK_ITEMS;
selectedStackItem = numDisplayed - gSelectedStackItem;
if (gBuffer == NULL) {
gBuffer = malloc(AB_CALC_EXPR_STRING_MAX);
}
if ((selectedStackItem >= 0) &&
(selectedStackItem < numStackItems) &&
(abCalcStackExprStringAt(selectedStackItem, gBuffer, FALSE) != NULL)) {
ZeroScrap();
PutScrap(strlen(gBuffer), textScrap, gBuffer);
}
SetPort(gCalcWinPtr);
ResetMember2(stackListCtl);
DrawMember2(gSelectedStackItem, stackListCtl);
gSelectedStackItem = -1;
}
void DoPaste(void)
{
LERecHndl leHandle;
CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox);
HLock((Handle)entryBox);
leHandle = (LERecHndl)(*entryBox)->ctlData;
HUnlock((Handle)entryBox);
LEFromScrap();
LEPaste(leHandle);
}
void DoClear(void)
{
LERecHndl leHandle;
CtlRecHndl entryBox = GetCtlHandleFromID(gCalcWinPtr, abCalcEntryBox);
HLock((Handle)entryBox);
leHandle = (LERecHndl)(*entryBox)->ctlData;
HUnlock((Handle)entryBox);
LEDelete(leHandle);
}
void HandleMenu(int menuItem)
{
SetPort(gCalcWinPtr);
switch (menuItem) {
case cutAction:
DoCut();
break;
case copyAction:
DoCopy();
break;
case pasteAction:
DoPaste();
break;
case clearAction:
DoClear();
break;
default:
break;
}
}
void HandleKey(EventRecord *event)
{
BOOLEAN appleKeyPressed = ((event->modifiers & appleKey) != 0);
char key = (event->message & 0xff);
if (!appleKeyPressed)
return;
switch (key) {
case 'C':
case 'c':
DoCopy();
break;
case 'X':
case 'x':
DoCut();
break;
case 'V':
case 'v':
DoPaste();
break;
}
}
BOOLEAN NDAAction(EventRecord *sysEvent, int code)
{
int event;
static EventRecord localEvent;
unsigned int eventCode;
BOOLEAN result = FALSE;
switch (code) {
case runAction:
return result;
case eventAction:
BlockMove((Pointer)sysEvent, (Pointer)&localEvent, 16);
localEvent.wmTaskMask = 0x001FFFFF;
eventCode = TaskMasterDA(0, &localEvent);
switch(eventCode) {
case updateEvt:
BeginUpdate(gCalcWinPtr);
DrawContents();
EndUpdate(gCalcWinPtr);
break;
case wInControl:
HandleControl(&localEvent);
break;
case keyDownEvt:
case autoKeyEvt:
HandleKey(&localEvent);
break;
}
break;
case cutAction:
case copyAction:
case pasteAction:
case clearAction:
result = TRUE;
HandleMenu(code);
break;
}
return result;
}

115
abCalc/nda/abCalcNDA.h Normal file
View File

@ -0,0 +1,115 @@
/* */
/* abCalcNDA.defs */
/* By: Jeremy Rand */
/* */
#define abCalcWinNum 1001
#define abCalcLinedColors 1002
#define abCalcControlList 1003
#define abCalcBtn0 2001
#define abCalcBtn0Str 2002
#define abCalcBtn1 2003
#define abCalcBtn1Str 2004
#define abCalcBtn2 2005
#define abCalcBtn2Str 2006
#define abCalcBtn3 2007
#define abCalcBtn3Str 2008
#define abCalcBtn4 2009
#define abCalcBtn4Str 2010
#define abCalcBtn5 2011
#define abCalcBtn5Str 2012
#define abCalcBtn6 2013
#define abCalcBtn6Str 2014
#define abCalcBtn7 2015
#define abCalcBtn7Str 2016
#define abCalcBtn8 2017
#define abCalcBtn8Str 2018
#define abCalcBtn9 2019
#define abCalcBtn9Str 2020
#define abCalcBtnEnter 2021
#define abCalcBtnEnterStr 2022
#define abCalcBtnDot 2023
#define abCalcBtnDotStr 2024
#define abCalcBtnNum 2025
#define abCalcBtnNumStr 2026
#define abCalcBtnAdd 2027
#define abCalcBtnAddStr 2028
#define abCalcBtnSub 2029
#define abCalcBtnSubStr 2030
#define abCalcBtnMult 2031
#define abCalcBtnMultStr 2032
#define abCalcBtnDiv 2033
#define abCalcBtnDivStr 2034
#define abCalcBtnA 2035
#define abCalcBtnAStr 2036
#define abCalcBtnB 2037
#define abCalcBtnBStr 2038
#define abCalcBtnC 2039
#define abCalcBtnCStr 2040
#define abCalcBtnD 2041
#define abCalcBtnDStr 2042
#define abCalcBtnE 2043
#define abCalcBtnEStr 2044
#define abCalcBtnF 2045
#define abCalcBtnFStr 2046
#define abCalcBtnPow 2047
#define abCalcBtnPowStr 2048
#define abCalcEntryBox 3001
#define abCalcStackList 3002
#define abCalcOpList 3003
#define abCalcErrorAlert 4001
#define abCalcWinX 10
#define abCalcWinY 25
#define abCalcWinWidth 300
#define abCalcWinHeight 170
#define abCalcBtnSpaceX 5
#define abCalcBtnSpaceY 2
#define abCalcBtnWidth 39
#define abCalcBtnHeight 14
#define abCalcBtnRow0 abCalcWinHeight-abCalcBtnSpaceY-abCalcBtnHeight
#define abCalcBtnRow1 abCalcBtnRow0-abCalcBtnSpaceY-abCalcBtnHeight
#define abCalcBtnRow2 abCalcBtnRow1-abCalcBtnSpaceY-abCalcBtnHeight
#define abCalcBtnRow3 abCalcBtnRow2-abCalcBtnSpaceY-abCalcBtnHeight
#define abCalcBtnRow4 abCalcBtnRow3-abCalcBtnSpaceY-abCalcBtnHeight
#define abCalcBtnRow5 abCalcBtnRow4-abCalcBtnSpaceY-abCalcBtnHeight
#define abCalcBtnRow6 abCalcBtnRow5-abCalcBtnSpaceY-abCalcBtnHeight
#define abCalcBtnRow7 abCalcBtnRow6-abCalcBtnSpaceY-abCalcBtnHeight
#define abCalcBtnCol0 abCalcBtnSpaceX
#define abCalcBtnCol1 abCalcBtnCol0+abCalcBtnSpaceX+abCalcBtnWidth
#define abCalcBtnCol2 abCalcBtnCol1+abCalcBtnSpaceX+abCalcBtnWidth
#define abCalcBtnCol3 abCalcBtnCol2+abCalcBtnSpaceX+abCalcBtnWidth
#define abCalcOpCol abCalcBtnCol3+abCalcBtnSpaceX+abCalcBtnWidth

462
abCalc/nda/abCalcNDA.rez Normal file
View File

@ -0,0 +1,462 @@
/* */
/* abCalcNDA.h */
/* By: Jeremy Rand */
/* */
#include "types.rez"
#include "nda/abCalcNda.h"
resource rWindParam1 (abCalcWinNum) {
$C0A5, /* wFrameBits */
nil, /* wTitle */
0, /* wRefCon */
{0,0,0,0}, /* ZoomRect */
abCalcLinedColors, /* wColor ID */
{0,0}, /* Origin */
{0,0}, /* data size */
{0,0}, /* max height-width */
{0,0}, /* scroll ver hors */
{0,0}, /* page ver horiz */
0, /* winfoRefcon */
0, /* wInfoHeight */
{abCalcWinY,abCalcWinX,abCalcWinY+abCalcWinHeight,abCalcWinX+abCalcWinWidth}, /* wposition */
infront, /* wPlane */
abCalcControlList, /* wStorage */
$0809 /* wInVerb */
};
resource rWindColor (abCalcLinedColors) {
0x0000, /* frameColor */
0x0F00, /* titleColor */
0x020F, /* tbarColor */
0xF0F0, /* growColor */
0x00F0, /* infoColor */
};
resource rControlList (abCalcControlList) {
{
abCalcBtn0,
abCalcBtn1,
abCalcBtn2,
abCalcBtn3,
abCalcBtn4,
abCalcBtn5,
abCalcBtn6,
abCalcBtn7,
abCalcBtn8,
abCalcBtn9,
abCalcBtnEnter,
abCalcBtnDot,
abCalcBtnNum,
abCalcBtnAdd,
abCalcBtnSub,
abCalcBtnMult,
abCalcBtnDiv,
abCalcBtnPow,
abCalcBtnA,
abCalcBtnB,
abCalcBtnC,
abCalcBtnD,
abCalcBtnE,
abCalcBtnF,
abCalcEntryBox,
abCalcStackList,
abCalcOpList
}
};
resource rControlTemplate (abCalcBtn0) {
abCalcBtn0,
{abCalcBtnRow0, abCalcBtnCol0, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn0Str,
0,
{"0","",0,0}
}};
};
resource rPString (abCalcBtn0Str, noCrossBank) { "0" };
resource rControlTemplate (abCalcBtnDot) {
abCalcBtnDot,
{abCalcBtnRow0, abCalcBtnCol1, abCalcBtnRow0+abCalcBtnHeight, abCalcBtnCol1+abCalcBtnWidth},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnDotStr,
0,
{".","",0,0}
}};
};
resource rPString (abCalcBtnDotStr, noCrossBank) { "." };
resource rControlTemplate (abCalcBtnNum) {
abCalcBtnNum,
{abCalcBtnRow0, abCalcBtnCol2, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnNumStr,
0,
{"#","",0,0}
}};
};
resource rPString (abCalcBtnNumStr, noCrossBank) { "#" };
resource rControlTemplate (abCalcBtn1) {
abCalcBtn1,
{abCalcBtnRow1, abCalcBtnCol0, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn1Str,
0,
{"1","",0,0}
}};
};
resource rPString (abCalcBtn1Str, noCrossBank) { "1" };
resource rControlTemplate (abCalcBtn2) {
abCalcBtn2,
{abCalcBtnRow1, abCalcBtnCol1, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn2Str,
0,
{"2","",0,0}
}};
};
resource rPString (abCalcBtn2Str, noCrossBank) { "2" };
resource rControlTemplate (abCalcBtn3) {
abCalcBtn3,
{abCalcBtnRow1, abCalcBtnCol2, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn3Str,
0,
{"3","",0,0}
}};
};
resource rPString (abCalcBtn3Str, noCrossBank) { "3" };
resource rControlTemplate (abCalcBtn4) {
abCalcBtn4,
{abCalcBtnRow2, abCalcBtnCol0, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn4Str,
0,
{"4","",0,0}
}};
};
resource rPString (abCalcBtn4Str, noCrossBank) { "4" };
resource rControlTemplate (abCalcBtn5) {
abCalcBtn5,
{abCalcBtnRow2, abCalcBtnCol1, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn5Str,
0,
{"5","",0,0}
}};
};
resource rPString (abCalcBtn5Str, noCrossBank) { "5" };
resource rControlTemplate (abCalcBtn6) {
abCalcBtn6,
{abCalcBtnRow2, abCalcBtnCol2, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn6Str,
0,
{"6","",0,0}
}};
};
resource rPString (abCalcBtn6Str, noCrossBank) { "6" };
resource rControlTemplate (abCalcBtn7) {
abCalcBtn7,
{abCalcBtnRow3, abCalcBtnCol0, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn7Str,
0,
{"7","",0,0}
}};
};
resource rPString (abCalcBtn7Str, noCrossBank) { "7" };
resource rControlTemplate (abCalcBtn8) {
abCalcBtn8,
{abCalcBtnRow3, abCalcBtnCol1, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn8Str,
0,
{"8","",0,0}
}};
};
resource rPString (abCalcBtn8Str, noCrossBank) { "8" };
resource rControlTemplate (abCalcBtn9) {
abCalcBtn9,
{abCalcBtnRow3, abCalcBtnCol2, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtn9Str,
0,
{"9","",0,0}
}};
};
resource rPString (abCalcBtn9Str, noCrossBank) { "9" };
resource rControlTemplate (abCalcBtnEnter) {
abCalcBtnEnter,
{abCalcBtnRow4, abCalcBtnCol0, abCalcBtnRow4+abCalcBtnHeight, abCalcBtnCol2+abCalcBtnWidth},
SimpleButtonControl {{
$0003,
$3002,
0,
abCalcBtnEnterStr,
0,
{"\n","",0,0}
}};
};
resource rPString (abCalcBtnEnterStr, noCrossBank) { "Enter" };
resource rControlTemplate (abCalcBtnPow) {
abCalcBtnPow,
{abCalcBtnRow4, abCalcBtnCol3, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnPowStr,
0,
{"^","",0,0}
}};
};
resource rPString (abCalcBtnPowStr, noCrossBank) { "^" };
resource rControlTemplate (abCalcBtnAdd) {
abCalcBtnAdd,
{abCalcBtnRow0, abCalcBtnCol3, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnAddStr,
0,
{"+","",0,0}
}};
};
resource rPString (abCalcBtnAddStr, noCrossBank) { "+" };
resource rControlTemplate (abCalcBtnSub) {
abCalcBtnSub,
{abCalcBtnRow1, abCalcBtnCol3, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnSubStr,
0,
{"-","",0,0}
}};
};
resource rPString (abCalcBtnSubStr, noCrossBank) { "-" };
resource rControlTemplate (abCalcBtnMult) {
abCalcBtnMult,
{abCalcBtnRow2, abCalcBtnCol3, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnMultStr,
0,
{"*","",0,0}
}};
};
resource rPString (abCalcBtnMultStr, noCrossBank) { "x" };
resource rControlTemplate (abCalcBtnDiv) {
abCalcBtnDiv,
{abCalcBtnRow3, abCalcBtnCol3, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnDivStr,
0,
{"/","",0,0}
}};
};
resource rPString (abCalcBtnDivStr, noCrossBank) { "/" };
resource rControlTemplate (abCalcBtnA) {
abCalcBtnA,
{abCalcBtnRow5, abCalcBtnCol0, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnAStr,
0,
{"A","",0,0}
}};
};
resource rPString (abCalcBtnAStr, noCrossBank) { "A" };
resource rControlTemplate (abCalcBtnB) {
abCalcBtnB,
{abCalcBtnRow5, abCalcBtnCol1, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnBStr,
0,
{"B","",0,0}
}};
};
resource rPString (abCalcBtnBStr, noCrossBank) { "B" };
resource rControlTemplate (abCalcBtnC) {
abCalcBtnC,
{abCalcBtnRow5, abCalcBtnCol2, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnCStr,
0,
{"C","",0,0}
}};
};
resource rPString (abCalcBtnCStr, noCrossBank) { "C" };
resource rControlTemplate (abCalcBtnD) {
abCalcBtnD,
{abCalcBtnRow6, abCalcBtnCol0, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnDStr,
0,
{"D","",0,0}
}};
};
resource rPString (abCalcBtnDStr, noCrossBank) { "D" };
resource rControlTemplate (abCalcBtnE) {
abCalcBtnE,
{abCalcBtnRow6, abCalcBtnCol1, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnEStr,
0,
{"E","",0,0}
}};
};
resource rPString (abCalcBtnEStr, noCrossBank) { "E" };
resource rControlTemplate (abCalcBtnF) {
abCalcBtnF,
{abCalcBtnRow6, abCalcBtnCol2, 0, 0},
SimpleButtonControl {{
$0002,
$3002,
0,
abCalcBtnFStr,
0,
{"F","",0,0}
}};
};
resource rPString (abCalcBtnFStr, noCrossBank) { "F" };
resource rControlTemplate (abCalcStackList) {
abCalcStackList, /* control ID */
{1, abCalcBtnSpaceX, 41, abCalcWinWidth-abCalcBtnSpaceX}, /* control rect */
ListControl {{
$0000, /* flags */
$1400, /* more flags */
0, /* refcon */
0, /* list size */
4, /* List View */
$0007, /* List Type */
0, /* List Start */
10, /* ListMemHeight */
5, /* List Mem Size */
0, /* List Ref */
0 /* Color Ref */
}};
};
resource rControlTemplate (abCalcOpList) {
abCalcOpList, /* control ID */
{abCalcBtnRow7, abCalcOpCol, abCalcWinHeight-(3*abCalcBtnSpaceY), abCalcWinWidth-abCalcBtnSpaceX}, /* control rect */
ListControl {{
$0000, /* flags */
$1400, /* more flags */
0, /* refcon */
0, /* list size */
12, /* List View */
$0007, /* List Type */
0, /* List Start */
10, /* ListMemHeight */
5, /* List Mem Size */
0, /* List Ref */
0 /* Color Ref */
}};
};
resource rControlTemplate (abCalcEntryBox) {
abCalcEntryBox, /* control ID */
{abCalcBtnRow7, abCalcBtnCol0, abCalcBtnRow7+abCalcBtnHeight, abCalcBtnCol3+abCalcBtnWidth}, /* control rect */
editLineControl {{
$0000, /* flags */
$7000, /* more flags */
0, /* refcon */
34, /* Max size */
0 /* text Ref */
}};
};
resource rAlertString (abCalcErrorAlert) {
"23/"
"*0"
"/^#0\$00"
};

177
abCalc/ops/abCOp.c Normal file
View File

@ -0,0 +1,177 @@
/*
abCOp.c
By: Jeremy Rand
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "ops/abCOp.h"
#include "ops/abCOpAdd.h"
#include "ops/abCOpSubtr.h"
#include "ops/abCOpMult.h"
#include "ops/abCOpDiv.h"
#include "ops/abCOpChs.h"
#include "ops/abCOpInv.h"
#include "ops/abCOpSq.h"
#include "ops/abCOpSqrt.h"
#include "ops/abCOpPower.h"
#include "ops/abCOpDrop.h"
#include "ops/abCOpSwap.h"
#include "ops/abCOpClear.h"
#include "ops/abCOpPi.h"
#include "ops/abCOpSin.h"
#include "ops/abCOpCos.h"
#include "ops/abCOpTan.h"
#include "ops/abCOpAsin.h"
#include "ops/abCOpAcos.h"
#include "ops/abCOpAtan.h"
#include "ops/abCOpLog.h"
#include "ops/abCOpAlog.h"
#include "ops/abCOpLn.h"
#include "ops/abCOpExp.h"
#include "ops/abCOpSinh.h"
#include "ops/abCOpCosh.h"
#include "ops/abCOpTanh.h"
#include "ops/abCOpR2B.h"
#include "ops/abCOpB2R.h"
#include "ops/abCOpAnd.h"
#include "ops/abCOpOr.h"
#include "ops/abCOpXor.h"
#include "ops/abCOpNot.h"
#include "ops/abCOpSl.h"
#include "ops/abCOpRl.h"
#include "ops/abCOpSr.h"
#include "ops/abCOpRr.h"
#include "ops/abCOpAsr.h"
#include "ops/abCOpBin.h"
#include "ops/abCOpOct.h"
#include "ops/abCOpDec.h"
#include "ops/abCOpHex.h"
#include "ops/abCOpStws.h"
#include "ops/abCOpRcws.h"
#define AB_CALC_MAX_OPS 128
abCalcOp gOps[AB_CALC_MAX_OPS];
static int gNumOps = 0;
void abCalcOpInit(void)
{
gNumOps = 0;
memset(gOps, 0, sizeof(gOps));
abCalcOpAddInit();
abCalcOpSubtrInit();
abCalcOpMultInit();
abCalcOpDivInit();
abCalcOpChsInit();
abCalcOpInvInit();
abCalcOpSqInit();
abCalcOpSqrtInit();
abCalcOpPowerInit();
abCalcOpDropInit();
abCalcOpSwapInit();
abCalcOpClearInit();
abCalcOpPiInit();
abCalcOpSinInit();
abCalcOpCosInit();
abCalcOpTanInit();
abCalcOpAsinInit();
abCalcOpAcosInit();
abCalcOpAtanInit();
abCalcOpLogInit();
abCalcOpAlogInit();
abCalcOpLnInit();
abCalcOpExpInit();
abCalcOpSinhInit();
abCalcOpCoshInit();
abCalcOpTanhInit();
abCalcOpR2BInit();
abCalcOpB2RInit();
abCalcOpAndInit();
abCalcOpOrInit();
abCalcOpXorInit();
abCalcOpNotInit();
abCalcOpSlInit();
abCalcOpRlInit();
abCalcOpSrInit();
abCalcOpRrInit();
abCalcOpAsrInit();
abCalcOpBinInit();
abCalcOpOctInit();
abCalcOpDecInit();
abCalcOpHexInit();
abCalcOpStwsInit();
abCalcOpRcwsInit();
}
void abCalcOpRegister(char *name, void (*execute)(void))
{
if (gNumOps >= AB_CALC_MAX_OPS) {
fprintf(stderr, "Operation registration overflow");
return;
}
gOps[gNumOps].name = name;
gOps[gNumOps].execute = execute;
gNumOps++;
}
abCalcOp *abCalcOpLookup(char *name)
{
int i;
for (i = 0; i < gNumOps; i++) {
#ifdef ABCALC_GSOS
if (stricmp(gOps[i].name, name) == 0) {
#else
if (strcasecmp(gOps[i].name, name) == 0) {
#endif
return &gOps[i];
}
}
return NULL;
}
abCalcOp *abCalcOpNth(int n)
{
if ((n < 0) ||
(n >= gNumOps))
return NULL;
return &gOps[n];
}
int abCalcOpNumOps(void)
{
return gNumOps;
}

44
abCalc/ops/abCOp.h Normal file
View File

@ -0,0 +1,44 @@
/*
abCOp.h
By: Jeremy Rand
*/
#ifndef ABCOP_H
#define ABCOP_H
#define AB_CALC_OP_ONE_ARG(opName) \
abCalcExpr *expr; \
if (abCalcStackNumItems() < 1) { \
abCalcRaiseError(abCalcTooFewArgsError, opName); \
return; \
} \
expr = abCalcStackExprAt(0);
#define AB_CALC_OP_TWO_ARGS(opName) \
abCalcExpr *expr1, *expr2; \
if (abCalcStackNumItems() < 2) { \
abCalcRaiseError(abCalcTooFewArgsError, opName); \
return; \
} \
expr1 = abCalcStackExprAt(0); \
expr2 = abCalcStackExprAt(1);
typedef struct abCalcOp {
char *name;
void (*execute)(void);
} abCalcOp;
void abCalcOpInit(void);
void abCalcOpRegister(char *name, void (*execute)(void));
abCalcOp *abCalcOpLookup(char *name);
abCalcOp *abCalcOpNth(int n);
int abCalcOpNumOps(void);
#endif

52
abCalc/ops/abCOpAcos.c Normal file
View File

@ -0,0 +1,52 @@
/*
abCOpAcos.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpAcos.h"
#define ACOS_NAME "ACOS"
static void acosExecute(void);
void abCalcOpAcosInit(void)
{
abCalcOpRegister(ACOS_NAME, acosExecute);
}
void acosExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(ACOS_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, ACOS_NAME);
return;
}
if ((expr->u.real < -1.0) ||
(expr->u.real > 1.0)) {
abCalcRaiseError(abCalcComplexResultError, ACOS_NAME);
return;
}
abCalcExprRealSet(&result, acos(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpAcos.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpAcos.h
By: Jeremy Rand
*/
#ifndef ABCOPACOS_H
#define ABCOPACOS_H
void abCalcOpAcosInit(void);
#endif

69
abCalc/ops/abCOpAdd.c Normal file
View File

@ -0,0 +1,69 @@
/*
abCOpAdd.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpAdd.h"
#define ADD_NAME "+"
static void addExecute(void);
void abCalcOpAddInit(void)
{
abCalcOpRegister(ADD_NAME, addExecute);
}
void addExecute(void)
{
abCalcExpr result;
char expr1Real = 0;
char expr2Real = 0;
AB_CALC_OP_TWO_ARGS(ADD_NAME);
if (expr1->type == abCalcExprTypeReal) {
expr1Real = 1;
} else if (expr1->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, ADD_NAME);
return;
}
if (expr2->type == abCalcExprTypeReal) {
expr2Real = 1;
} else if (expr2->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, ADD_NAME);
return;
}
if ((expr1Real) && (expr2Real)) {
abCalcExprRealSet(&result, expr2->u.real + expr1->u.real);
} else {
if (expr1Real) {
abCalcExprIntSet(&result, expr2->u.integer + (abCalcIntType)expr1->u.real);
} else if (expr2Real) {
abCalcExprIntSet(&result, (abCalcIntType)expr2->u.real + expr1->u.integer);
} else {
abCalcExprIntSet(&result, expr2->u.integer + expr1->u.integer);
}
}
abCalcStackExprPop(NULL);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpAdd.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpAdd.h
By: Jeremy Rand
*/
#ifndef ABCOPADD_H
#define ABCOPADD_H
void abCalcOpAddInit(void);
#endif

46
abCalc/ops/abCOpAlog.c Normal file
View File

@ -0,0 +1,46 @@
/*
abCOpAlog.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpAlog.h"
#define ALOG_NAME "ALOG"
static void alogExecute(void);
void abCalcOpAlogInit(void)
{
abCalcOpRegister(ALOG_NAME, alogExecute);
}
void alogExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(ALOG_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, ALOG_NAME);
return;
}
abCalcExprRealSet(&result, pow(10.0, expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpAlog.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpAlog.h
By: Jeremy Rand
*/
#ifndef ABCOPALOG_H
#define ABCOPALOG_H
void abCalcOpAlogInit(void);
#endif

51
abCalc/ops/abCOpAnd.c Normal file
View File

@ -0,0 +1,51 @@
/*
abCOpAnd.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpAnd.h"
#define AND_NAME "AND"
static void andExecute(void);
void abCalcOpAndInit(void)
{
abCalcOpRegister(AND_NAME, andExecute);
}
void andExecute(void)
{
abCalcExpr result;
AB_CALC_OP_TWO_ARGS(AND_NAME);
if (expr1->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, AND_NAME);
return;
}
if (expr2->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, AND_NAME);
return;
}
abCalcExprIntSet(&result, expr2->u.integer & expr1->u.integer);
abCalcStackExprPop(NULL);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpAnd.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpAnd.h
By: Jeremy Rand
*/
#ifndef ABCOPAND_H
#define ABCOPAND_H
void abCalcOpAndInit(void);
#endif

52
abCalc/ops/abCOpAsin.c Normal file
View File

@ -0,0 +1,52 @@
/*
abCOpAsin.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpAsin.h"
#define ASIN_NAME "ASIN"
static void asinExecute(void);
void abCalcOpAsinInit(void)
{
abCalcOpRegister(ASIN_NAME, asinExecute);
}
void asinExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(ASIN_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, ASIN_NAME);
return;
}
if ((expr->u.real < -1.0) ||
(expr->u.real > 1.0)) {
abCalcRaiseError(abCalcComplexResultError, ASIN_NAME);
return;
}
abCalcExprRealSet(&result, asin(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpAsin.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpAsin.h
By: Jeremy Rand
*/
#ifndef ABCOPASIN_H
#define ABCOPASIN_H
void abCalcOpAsinInit(void);
#endif

51
abCalc/ops/abCOpAsr.c Normal file
View File

@ -0,0 +1,51 @@
/*
abCOpAsr.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCMode.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpAsr.h"
#define ASR_NAME "ASR"
static void asrExecute(void);
void abCalcOpAsrInit(void)
{
abCalcOpRegister(ASR_NAME, asrExecute);
}
void asrExecute(void)
{
abCalcExpr result;
int width;
abCalcIntType upperBit;
AB_CALC_OP_ONE_ARG(ASR_NAME);
if (expr->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, ASR_NAME);
return;
}
width = abCalcModeGetIntWidth();
upperBit = (expr->u.integer & (1 << (width - 1)));
abCalcExprIntSet(&result, ((expr->u.integer >> 1) | upperBit));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpAsr.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpAsr.h
By: Jeremy Rand
*/
#ifndef ABCOPASR_H
#define ABCOPASR_H
void abCalcOpAsrInit(void);
#endif

46
abCalc/ops/abCOpAtan.c Normal file
View File

@ -0,0 +1,46 @@
/*
abCOpAtan.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpAtan.h"
#define ATAN_NAME "ATAN"
static void atanExecute(void);
void abCalcOpAtanInit(void)
{
abCalcOpRegister(ATAN_NAME, atanExecute);
}
void atanExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(ATAN_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, ATAN_NAME);
return;
}
abCalcExprRealSet(&result, atan(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpAtan.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpAtan.h
By: Jeremy Rand
*/
#ifndef ABCOPATAN_H
#define ABCOPATAN_H
void abCalcOpAtanInit(void);
#endif

48
abCalc/ops/abCOpB2R.c Normal file
View File

@ -0,0 +1,48 @@
/*
abCOpB2R.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpB2R.h"
#define B2R_NAME "B2R"
static void b2rExecute(void);
void abCalcOpB2RInit(void)
{
abCalcOpRegister(B2R_NAME, b2rExecute);
}
void b2rExecute(void)
{
abCalcExpr result;
int width;
int topBit;
AB_CALC_OP_ONE_ARG(B2R_NAME);
if (expr->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, B2R_NAME);
return;
}
abCalcExprRealSet(&result, (abCalcRealType)expr->u.integer);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpB2R.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpB2R.h
By: Jeremy Rand
*/
#ifndef ABCOPB2R_H
#define ABCOPB2R_H
void abCalcOpB2RInit(void);
#endif

30
abCalc/ops/abCOpBin.c Normal file
View File

@ -0,0 +1,30 @@
/*
abCOpBin.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCMode.h"
#include "ops/abCOp.h"
#include "ops/abCOpBin.h"
#define BIN_NAME "BIN"
static void binExecute(void);
void abCalcOpBinInit(void)
{
abCalcOpRegister(BIN_NAME, binExecute);
}
void binExecute(void)
{
abCalcModeSetBase(abCalcModeBinBase);
}

14
abCalc/ops/abCOpBin.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpBin.h
By: Jeremy Rand
*/
#ifndef ABCOPBIN_H
#define ABCOPBIN_H
void abCalcOpBinInit(void);
#endif

46
abCalc/ops/abCOpChs.c Normal file
View File

@ -0,0 +1,46 @@
/*
abCOpChs.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpChs.h"
#define CHS_NAME "CHS"
static void chsExecute(void);
void abCalcOpChsInit(void)
{
abCalcOpRegister(CHS_NAME, chsExecute);
}
void chsExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(CHS_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, CHS_NAME);
return;
}
abCalcExprRealSet(&result, -1.0 * expr->u.real);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpChs.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpChs.h
By: Jeremy Rand
*/
#ifndef ABCOPCHS_H
#define ABCOPCHS_H
void abCalcOpChsInit(void);
#endif

31
abCalc/ops/abCOpClear.c Normal file
View File

@ -0,0 +1,31 @@
/*
abCOpClear.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCStack.h"
#include "ops/abCOp.h"
#include "ops/abCOpClear.h"
#define CLEAR_NAME "CLEAR"
static void clearExecute(void);
void abCalcOpClearInit(void)
{
abCalcOpRegister(CLEAR_NAME, clearExecute);
}
void clearExecute(void)
{
abCalcStackClear();
}

14
abCalc/ops/abCOpClear.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpClean.h
By: Jeremy Rand
*/
#ifndef ABCOPCLEAR_H
#define ABCOPCLEAR_H
void abCalcOpClearInit(void);
#endif

46
abCalc/ops/abCOpCos.c Normal file
View File

@ -0,0 +1,46 @@
/*
abCOpCos.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpCos.h"
#define COS_NAME "COS"
static void cosExecute(void);
void abCalcOpCosInit(void)
{
abCalcOpRegister(COS_NAME, cosExecute);
}
void cosExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(COS_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, COS_NAME);
return;
}
abCalcExprRealSet(&result, cos(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpCos.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpCos.h
By: Jeremy Rand
*/
#ifndef ABCOPCOS_H
#define ABCOPCOS_H
void abCalcOpCosInit(void);
#endif

46
abCalc/ops/abCOpCosh.c Normal file
View File

@ -0,0 +1,46 @@
/*
abCOpCosh.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpCosh.h"
#define COSH_NAME "COSH"
static void coshExecute(void);
void abCalcOpCoshInit(void)
{
abCalcOpRegister(COSH_NAME, coshExecute);
}
void coshExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(COSH_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, COSH_NAME);
return;
}
abCalcExprRealSet(&result, cosh(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpCosh.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpCosh.h
By: Jeremy Rand
*/
#ifndef ABCOPCOSH_H
#define ABCOPCOSH_H
void abCalcOpCoshInit(void);
#endif

30
abCalc/ops/abCOpDec.c Normal file
View File

@ -0,0 +1,30 @@
/*
abCOpDec.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCMode.h"
#include "ops/abCOp.h"
#include "ops/abCOpDec.h"
#define DEC_NAME "DEC"
static void decExecute(void);
void abCalcOpDecInit(void)
{
abCalcOpRegister(DEC_NAME, decExecute);
}
void decExecute(void)
{
abCalcModeSetBase(abCalcModeDecBase);
}

14
abCalc/ops/abCOpDec.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpDec.h
By: Jeremy Rand
*/
#ifndef ABCOPDEC_H
#define ABCOPDEC_H
void abCalcOpDecInit(void);
#endif

77
abCalc/ops/abCOpDiv.c Normal file
View File

@ -0,0 +1,77 @@
/*
abCOpDiv.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpDiv.h"
#define DIV_NAME "/"
static void divExecute(void);
void abCalcOpDivInit(void)
{
abCalcOpRegister(DIV_NAME, divExecute);
}
void divExecute(void)
{
abCalcExpr result;
char expr1Real = 0;
char expr2Real = 0;
AB_CALC_OP_TWO_ARGS(DIV_NAME);
if (expr1->type == abCalcExprTypeReal) {
expr1Real = 1;
if (expr1->u.real == 0.0) {
abCalcRaiseError(abCalcInfiniteResultError, DIV_NAME);
return;
}
} else if (expr1->type == abCalcExprTypeInt) {
if (expr1->u.integer == 0l) {
abCalcRaiseError(abCalcInfiniteResultError, DIV_NAME);
return;
}
} else {
abCalcRaiseError(abCalcBadArgTypeError, DIV_NAME);
return;
}
if (expr2->type == abCalcExprTypeReal) {
expr2Real = 1;
} else if (expr2->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, DIV_NAME);
return;
}
if ((expr1Real) && (expr2Real)) {
abCalcExprRealSet(&result, expr2->u.real / expr1->u.real);
} else {
if (expr1Real) {
abCalcExprIntSet(&result, expr2->u.integer / (abCalcIntType)expr1->u.real);
} else if (expr2Real) {
abCalcExprIntSet(&result, (abCalcIntType)expr2->u.real / expr1->u.integer);
} else {
abCalcExprIntSet(&result, expr2->u.integer / expr1->u.integer);
}
}
abCalcStackExprPop(NULL);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpDiv.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpDiv.h
By: Jeremy Rand
*/
#ifndef ABCOPDIV_H
#define ABCOPDIV_H
void abCalcOpDivInit(void);
#endif

36
abCalc/ops/abCOpDrop.c Normal file
View File

@ -0,0 +1,36 @@
/*
abCOpDrop.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "ops/abCOp.h"
#include "ops/abCOpDrop.h"
#define DROP_NAME "DROP"
static void dropExecute(void);
void abCalcOpDropInit(void)
{
abCalcOpRegister(DROP_NAME, dropExecute);
}
void dropExecute(void)
{
AB_CALC_OP_ONE_ARG(DROP_NAME);
abCalcStackExprPop(NULL);
}

14
abCalc/ops/abCOpDrop.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpDrop.h
By: Jeremy Rand
*/
#ifndef ABCOPDROP_H
#define ABCOPDROP_H
void abCalcOpDropInit(void);
#endif

46
abCalc/ops/abCOpExp.c Normal file
View File

@ -0,0 +1,46 @@
/*
abCOpExp.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpExp.h"
#define EXP_NAME "EXP"
static void expExecute(void);
void abCalcOpExpInit(void)
{
abCalcOpRegister(EXP_NAME, expExecute);
}
void expExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(EXP_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, EXP_NAME);
return;
}
abCalcExprRealSet(&result, exp(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpExp.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpExp.h
By: Jeremy Rand
*/
#ifndef ABCOPEXP_H
#define ABCOPEXP_H
void abCalcOpExpInit(void);
#endif

30
abCalc/ops/abCOpHex.c Normal file
View File

@ -0,0 +1,30 @@
/*
abCOpHex.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCMode.h"
#include "ops/abCOp.h"
#include "ops/abCOpHex.h"
#define HEX_NAME "HEX"
static void hexExecute(void);
void abCalcOpHexInit(void)
{
abCalcOpRegister(HEX_NAME, hexExecute);
}
void hexExecute(void)
{
abCalcModeSetBase(abCalcModeHexBase);
}

14
abCalc/ops/abCOpHex.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpHex.h
By: Jeremy Rand
*/
#ifndef ABCOPHEX_H
#define ABCOPHEX_H
void abCalcOpHexInit(void);
#endif

51
abCalc/ops/abCOpInv.c Normal file
View File

@ -0,0 +1,51 @@
/*
abCOpInv.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpInv.h"
#define INV_NAME "INV"
static void invExecute(void);
void abCalcOpInvInit(void)
{
abCalcOpRegister(INV_NAME, invExecute);
}
void invExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(INV_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, INV_NAME);
return;
}
if (expr->u.real == 0.0) {
abCalcRaiseError(abCalcInfiniteResultError, INV_NAME);
return;
}
abCalcExprRealSet(&result, 1.0 / expr->u.real);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpInv.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpInv.h
By: Jeremy Rand
*/
#ifndef ABCOPINV_H
#define ABCOPINV_H
void abCalcOpInvInit(void);
#endif

55
abCalc/ops/abCOpLn.c Normal file
View File

@ -0,0 +1,55 @@
/*
abCOpLn.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpLn.h"
#define LN_NAME "LN"
static void lnExecute(void);
void abCalcOpLnInit(void)
{
abCalcOpRegister(LN_NAME, lnExecute);
}
void lnExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(LN_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, LN_NAME);
return;
}
if (expr->u.real == 0.0) {
abCalcRaiseError(abCalcInfiniteResultError, LN_NAME);
return;
}
if (expr->u.real < 0.0) {
abCalcRaiseError(abCalcComplexResultError, LN_NAME);
return;
}
abCalcExprRealSet(&result, log(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpLn.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpLn.h
By: Jeremy Rand
*/
#ifndef ABCOPLN_H
#define ABCOPLN_H
void abCalcOpLnInit(void);
#endif

55
abCalc/ops/abCOpLog.c Normal file
View File

@ -0,0 +1,55 @@
/*
abCOpLog.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpLog.h"
#define LOG_NAME "LOG"
static void logExecute(void);
void abCalcOpLogInit(void)
{
abCalcOpRegister(LOG_NAME, logExecute);
}
void logExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(LOG_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, LOG_NAME);
return;
}
if (expr->u.real == 0.0) {
abCalcRaiseError(abCalcInfiniteResultError, LOG_NAME);
return;
}
if (expr->u.real < 0.0) {
abCalcRaiseError(abCalcComplexResultError, LOG_NAME);
return;
}
abCalcExprRealSet(&result, log10(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpLog.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpLog.h
By: Jeremy Rand
*/
#ifndef ABCOPLOG_H
#define ABCOPLOG_H
void abCalcOpLogInit(void);
#endif

68
abCalc/ops/abCOpMult.c Normal file
View File

@ -0,0 +1,68 @@
/*
abCOpMult.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpMult.h"
#define MUL_NAME "*"
static void multExecute(void);
void abCalcOpMultInit(void)
{
abCalcOpRegister(MUL_NAME, multExecute);
}
void multExecute(void)
{
abCalcExpr result;
char expr1Real = 0;
char expr2Real = 0;
AB_CALC_OP_TWO_ARGS(MUL_NAME);
if (expr1->type == abCalcExprTypeReal) {
expr1Real = 1;
} else if (expr1->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, MUL_NAME);
return;
}
if (expr2->type == abCalcExprTypeReal) {
expr2Real = 1;
} else if (expr2->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, MUL_NAME);
return;
}
if ((expr1Real) && (expr2Real)) {
abCalcExprRealSet(&result, expr2->u.real * expr1->u.real);
} else {
if (expr1Real) {
abCalcExprIntSet(&result, expr2->u.integer * (abCalcIntType)expr1->u.real);
} else if (expr2Real) {
abCalcExprIntSet(&result, (abCalcIntType)expr2->u.real * expr1->u.integer);
} else {
abCalcExprIntSet(&result, expr2->u.integer * expr1->u.integer);
}
}
abCalcStackExprPop(NULL);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpMult.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpMult.h
By: Jeremy Rand
*/
#ifndef ABCOPMULT_H
#define ABCOPMULT_H
void abCalcOpMultInit(void);
#endif

45
abCalc/ops/abCOpNot.c Normal file
View File

@ -0,0 +1,45 @@
/*
abCOpNot.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpNot.h"
#define NOT_NAME "NOT"
static void notExecute(void);
void abCalcOpNotInit(void)
{
abCalcOpRegister(NOT_NAME, notExecute);
}
void notExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(NOT_NAME);
if (expr->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, NOT_NAME);
return;
}
abCalcExprIntSet(&result, ~(expr->u.integer));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpNot.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpNot.h
By: Jeremy Rand
*/
#ifndef ABCOPNOT_H
#define ABCOPNOT_H
void abCalcOpNotInit(void);
#endif

30
abCalc/ops/abCOpOct.c Normal file
View File

@ -0,0 +1,30 @@
/*
abCOpOct.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCMode.h"
#include "ops/abCOp.h"
#include "ops/abCOpOct.h"
#define OCT_NAME "OCT"
static void octExecute(void);
void abCalcOpOctInit(void)
{
abCalcOpRegister(OCT_NAME, octExecute);
}
void octExecute(void)
{
abCalcModeSetBase(abCalcModeOctBase);
}

14
abCalc/ops/abCOpOct.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpOct.h
By: Jeremy Rand
*/
#ifndef ABCOPOCT_H
#define ABCOPOCT_H
void abCalcOpOctInit(void);
#endif

51
abCalc/ops/abCOpOr.c Normal file
View File

@ -0,0 +1,51 @@
/*
abCOpOr.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpOr.h"
#define OR_NAME "OR"
static void orExecute(void);
void abCalcOpOrInit(void)
{
abCalcOpRegister(OR_NAME, orExecute);
}
void orExecute(void)
{
abCalcExpr result;
AB_CALC_OP_TWO_ARGS(OR_NAME);
if (expr1->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, OR_NAME);
return;
}
if (expr2->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, OR_NAME);
return;
}
abCalcExprIntSet(&result, expr2->u.integer | expr1->u.integer);
abCalcStackExprPop(NULL);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpOr.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpOr.h
By: Jeremy Rand
*/
#ifndef ABCOPOR_H
#define ABCOPOR_H
void abCalcOpOrInit(void);
#endif

42
abCalc/ops/abCOpPi.c Normal file
View File

@ -0,0 +1,42 @@
/*
abCOpPi.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpPi.h"
#define PI_NAME "PI"
static void piExecute(void);
void abCalcOpPiInit(void)
{
abCalcOpRegister(PI_NAME, piExecute);
}
void piExecute(void)
{
abCalcExpr result;
#ifdef ABCALC_GSOS
abCalcExprRealSet(&result, 2.0 * asin(1.0));
#else
abCalcExprRealSet(&result, M_PI);
#endif
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpPi.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpPi.h
By: Jeremy Rand
*/
#ifndef ABCOPPI_H
#define ABCOPPI_H
void abCalcOpPiInit(void);
#endif

73
abCalc/ops/abCOpPower.c Normal file
View File

@ -0,0 +1,73 @@
/*
abCOpPower.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpPower.h"
#define POWER_NAME "^"
static void powerExecute(void);
void abCalcOpPowerInit(void)
{
abCalcOpRegister(POWER_NAME, powerExecute);
}
void powerExecute(void)
{
abCalcExpr result;
double integral;
AB_CALC_OP_TWO_ARGS(POWER_NAME);
if (expr1->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, POWER_NAME);
return;
}
if (expr2->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, POWER_NAME);
return;
}
if (expr2->u.real == 0.0) {
if (expr1->u.real < 0.0) {
abCalcRaiseError(abCalcInfiniteResultError, POWER_NAME);
return;
}
if (expr1->u.real == 0.0) {
abCalcExprRealSet(&result, 1.0);
} else {
abCalcExprRealSet(&result, 0.0);
}
} else {
if (expr2->u.real < 0.0) {
modf(expr1->u.real, &integral);
if (expr1->u.real != integral) {
abCalcRaiseError(abCalcComplexResultError, POWER_NAME);
return;
}
}
abCalcExprRealSet(&result, pow(expr2->u.real, expr1->u.real));
}
abCalcStackExprPop(NULL);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpPower.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpPower.h
By: Jeremy Rand
*/
#ifndef ABCOPPOWER_H
#define ABCOPPOWER_H
void abCalcOpPowerInit(void);
#endif

48
abCalc/ops/abCOpR2B.c Normal file
View File

@ -0,0 +1,48 @@
/*
abCOpR2B.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpR2B.h"
#define R2B_NAME "R2B"
static void r2bExecute(void);
void abCalcOpR2BInit(void)
{
abCalcOpRegister(R2B_NAME, r2bExecute);
}
void r2bExecute(void)
{
abCalcExpr result;
int width;
int topBit;
AB_CALC_OP_ONE_ARG(R2B_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, R2B_NAME);
return;
}
abCalcExprIntSet(&result, (abCalcIntType)expr->u.real);
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpR2B.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpR2B.h
By: Jeremy Rand
*/
#ifndef ABCOPR2B_H
#define ABCOPR2B_H
void abCalcOpR2BInit(void);
#endif

38
abCalc/ops/abCOpRcws.c Normal file
View File

@ -0,0 +1,38 @@
/*
abCOpRcws.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCStack.h"
#include "abCMode.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpRcws.h"
#define RCWS_NAME "RCWS"
static void rcwsExecute(void);
void abCalcOpRcwsInit(void)
{
abCalcOpRegister(RCWS_NAME, rcwsExecute);
}
void rcwsExecute(void)
{
abCalcExpr result;
abCalcExprRealSet(&result, (abCalcRealType)abCalcModeGetIntWidth());
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpRcws.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpRcws.h
By: Jeremy Rand
*/
#ifndef ABCOPRCWS_H
#define ABCOPRCWS_H
void abCalcOpRcwsInit(void);
#endif

51
abCalc/ops/abCOpRl.c Normal file
View File

@ -0,0 +1,51 @@
/*
abCOpRl.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCMode.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpRl.h"
#define RL_NAME "RL"
static void rlExecute(void);
void abCalcOpRlInit(void)
{
abCalcOpRegister(RL_NAME, rlExecute);
}
void rlExecute(void)
{
abCalcExpr result;
int width;
int topBit;
AB_CALC_OP_ONE_ARG(RL_NAME);
if (expr->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, RL_NAME);
return;
}
width = abCalcModeGetIntWidth();
topBit = ((expr->u.integer >> (width - 1)) & 1);
abCalcExprIntSet(&result, ((expr->u.integer << 1) | topBit));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpRl.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpRl.h
By: Jeremy Rand
*/
#ifndef ABCOPRL_H
#define ABCOPRL_H
void abCalcOpRlInit(void);
#endif

51
abCalc/ops/abCOpRr.c Normal file
View File

@ -0,0 +1,51 @@
/*
abCOpRr.c
By: Jeremy Rand
*/
#include <stdio.h>
#include "abCError.h"
#include "abCMode.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExprInt.h"
#include "ops/abCOp.h"
#include "ops/abCOpRr.h"
#define RR_NAME "RR"
static void rrExecute(void);
void abCalcOpRrInit(void)
{
abCalcOpRegister(RR_NAME, rrExecute);
}
void rrExecute(void)
{
abCalcExpr result;
int width;
abCalcIntType bottomBit;
AB_CALC_OP_ONE_ARG(RR_NAME);
if (expr->type != abCalcExprTypeInt) {
abCalcRaiseError(abCalcBadArgTypeError, RR_NAME);
return;
}
width = abCalcModeGetIntWidth();
bottomBit = (expr->u.integer & 1);
abCalcExprIntSet(&result, ((expr->u.integer >> 1) | (bottomBit << (width - 1))));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpRr.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpRr.h
By: Jeremy Rand
*/
#ifndef ABCOPRR_H
#define ABCOPRR_H
void abCalcOpRrInit(void);
#endif

46
abCalc/ops/abCOpSin.c Normal file
View File

@ -0,0 +1,46 @@
/*
abCOpSin.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpSin.h"
#define SIN_NAME "SIN"
static void sinExecute(void);
void abCalcOpSinInit(void)
{
abCalcOpRegister(SIN_NAME, sinExecute);
}
void sinExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(SIN_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, SIN_NAME);
return;
}
abCalcExprRealSet(&result, sin(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpSin.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpSin.h
By: Jeremy Rand
*/
#ifndef ABCOPSIN_H
#define ABCOPSIN_H
void abCalcOpSinInit(void);
#endif

46
abCalc/ops/abCOpSinh.c Normal file
View File

@ -0,0 +1,46 @@
/*
abCOpSinh.c
By: Jeremy Rand
*/
#include <math.h>
#include <stdio.h>
#include "abCError.h"
#include "abCStack.h"
#include "expr/abCExpr.h"
#include "expr/abCExpReal.h"
#include "ops/abCOp.h"
#include "ops/abCOpSinh.h"
#define SINH_NAME "SINH"
static void sinhExecute(void);
void abCalcOpSinhInit(void)
{
abCalcOpRegister(SINH_NAME, sinhExecute);
}
void sinhExecute(void)
{
abCalcExpr result;
AB_CALC_OP_ONE_ARG(SINH_NAME);
if (expr->type != abCalcExprTypeReal) {
abCalcRaiseError(abCalcBadArgTypeError, SINH_NAME);
return;
}
abCalcExprRealSet(&result, sinh(expr->u.real));
abCalcStackExprPop(NULL);
abCalcStackExprPush(&result);
}

14
abCalc/ops/abCOpSinh.h Normal file
View File

@ -0,0 +1,14 @@
/*
abCOpSinh.h
By: Jeremy Rand
*/
#ifndef ABCOPSINH_H
#define ABCOPSINH_H
void abCalcOpSinhInit(void);
#endif

Some files were not shown because too many files have changed in this diff Show More