Skip to content

Commit

Permalink
Merge pull request #18 from medvecky/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
medvecky authored Jul 4, 2024
2 parents c3932ea + 10a6f0e commit cb982c1
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [v2.0.0] 2024-07-04

## Added

- CP/M support


# [v1.0.1] 2024-06-28

## Changed
Expand Down
23 changes: 15 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# This is the name of your final .nex file without the .nex extension
EXEC_OUTPUT=build/multicalc
EXEC_OUTPUT=build/calc

# List all your source files here
SOURCES = multicalc.c \
Expand All @@ -13,16 +13,21 @@ SOURCES = multicalc.c \
modules/history_helper.c

# Maybe you'll need to edit this
CRT=1

# ZX Spectrum
# CRT=1

#CP/M
CRT=3

# You don't need to edit below here, have a nice day.

MKDIR = mkdir -p
CC=docker run --platform linux/amd64 -v .:/src/ -it z88dk/z88dk zcc
AS=docker run --platform linux/amd64 -v .:/src/ -it z88dk/z88dk zcc
# TARGET=+zxn -subtype=nex -lndos
TARGET=+zx -lndos -lm -DAMALLOC
# TARGET=+cpm -lndos
# TARGET=+zx -lndos -lm -DAMALLOC
TARGET=+cpm -lndos -lzxcpm -lm -DAMALLOC -D__CPM__
VERBOSITY=-vn
OUT_DIR=build bin
PRAGMA_FILE=zpragma.inc
Expand All @@ -32,15 +37,17 @@ OBJS=$(patsubst %, src/%, $(OBJECTS))

C_OPT_FLAGS=-SO3 --max-allocs-per-node200000 --opt-code-size

CFLAGS=$(TARGET) $(VERBOSITY) -c $(C_OPT_FLAGS) -compiler sdcc -clib=ansi -pragma-define:ansicolumns=42 -pragma-redirect:CRT_FONT=_font_8x8_zx_clairsys
CFLAGS=$(TARGET) $(VERBOSITY) -c $(C_OPT_FLAGS) -compiler sdcc
# -clib=ansi -pragma-define:ansicolumns=42 -pragma-redirect:CRT_FONT=_font_8x8_zx_clairsys
#-pragma-include:$(PRAGMA_FILE)
LDFLAGS=$(TARGET) $(VERBOSITY) --list -m -s -clib=ansi -pragma-define:ansicolumns=42 -pragma-redirect:CRT_FONT=_font_8x8_clairsys
LDFLAGS=$(TARGET) $(VERBOSITY) --list -m -s
# -clib=ansi -pragma-define:ansicolumns=42 -pragma-redirect:CRT_FONT=_font_8x8_clairsys
#-pragma-include:$(PRAGMA_FILE)
ASFLAGS=$(TARGET) $(VERBOSITY) -c --list -m -s

# EXEC=$(EXEC_OUTPUT).nex
EXEC=$(EXEC_OUTPUT).tap
# EXEC=$(EXEC_OUTPUT).com
# EXEC=$(EXEC_OUTPUT).tap
EXEC=$(EXEC_OUTPUT).com

%.o: %.c $(PRAGMA_FILE)
$(CC) $(CFLAGS) -o $@ $<
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ git clone https://github.com/medvecky/ZXSpectrum-multi-functional-calculator.git
make install
```

The calculator binary, named multicalc.tap, is located in the /bin directory.
The calculator binary, named calc.tap (calc.com for CP/M), is located in the /bin directory.

By modifying the Makefile, the app can be built as a ZX Spectrum TAP file or a CP/M COM file.

## Operating Manual

Expand Down
37 changes: 33 additions & 4 deletions src/modules/history_helper.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

#include <conio.h>
#include <stdio.h>
#include <cpm.h>

#include "adt_queue.h"
#include "misc_helper.h"
#include "history_helper.h"
#include "system_helper.h"

extern Queue * queuePtr;
extern size_t yPosition;
Expand Down Expand Up @@ -72,7 +74,12 @@ void historyEditAndExecute( void )
char * nthElement = NULL;

size_t queueSize = Queue_getSize( queuePtr );

#ifdef __CPM__
cls();
#else
clrscr();
#endif

Queue_print_raw( queuePtr );

Expand Down Expand Up @@ -100,7 +107,12 @@ static void editHistoryEntry( char * entryString )
size_t cursorYPosition = 0;

printf( "%s]", entryString );

#ifdef __CPM__
cursorYPosition = a_cury();
#else
cursorYPosition = wherey();
#endif

cursorHandler( cursorYPosition, entryString );
}
Expand All @@ -111,7 +123,7 @@ static void cursorHandler( size_t cursorYPosition, char * entryString )
size_t entryLength = strlen( entryString );
size_t currentCursorPosition = entryLength - 1;

if ( entryLength > 41 && cursorYPosition < 23 )
if ( entryLength > SCREEN_WIDTH && cursorYPosition < SCREEN_HEIGHT )
{
cursorYPosition--;
}
Expand All @@ -120,21 +132,31 @@ static void cursorHandler( size_t cursorYPosition, char * entryString )
{
switch ( currentKey )
{
#ifdef __CPM__
case 0x01:
#else
case 0x08:
#endif
if ( currentCursorPosition > 0 )
{
currentCursorPosition--;
}
break;

#ifdef __CPM__
case 0x06:
#else
case 0x09:
#endif
if ( currentCursorPosition < entryLength - 1 )
{
currentCursorPosition++;
}
break;

#ifdef __CPM__
case 0x08:
#else
case 0x0c:
#endif
handleBackspace( entryString, &cursorYPosition, &currentCursorPosition );
break;

Expand All @@ -148,14 +170,21 @@ static void cursorHandler( size_t cursorYPosition, char * entryString )
default:
break;
}

#ifdef __CPM__
gotoyx( cursorYPosition, 0 );
#else
gotoxy( 0, cursorYPosition );
#endif
rewriteString( entryString, currentCursorPosition );
currentKey = cgetc();
entryLength = strlen( entryString );
}

#ifdef __CPM__
gotoyx( cursorYPosition, 0 );
#else
gotoxy( 0, cursorYPosition );
#endif
printf( "%s ", entryString );
}

Expand Down
10 changes: 9 additions & 1 deletion src/modules/misc_helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,20 @@ extern Queue * queuePtr;

void header( void )
{
#ifdef __CPM__
gotoyx( 0, 36 );
#else
gotoxy( 13, 0 );
#endif
puts( "CALCULATOR" );
#ifdef __CPM__
gotoyx( 2, 0 );
puts( "Enter an expression for RPN calculation or 'q' for exit" );
#else
gotoxy( 0, 2 );
puts( "Enter an expression for RPN calculation" );
puts( "or 'q' for exit" );
#endif
puts( "" );
puts( "" );
}
Expand All @@ -41,7 +50,6 @@ void getUserInput( char * argumentString )
{
puts( "Error reading input" );
cgetc();
// resetDefaultScreen();
exit( EXIT_FAILURE );
}

Expand Down
29 changes: 28 additions & 1 deletion src/modules/system_helper.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
#include <conio.h>

#include "system_helper.h"

void setUpScreen( void )
{
#ifdef __CPM__
cls();
cursorOff();
#else
clrscr();
}
#endif
}

#ifdef __CPM__

void cls()
{
gotoyx( 0, 0 );
printf( "\x1BJ" );
}

void gotoyx( int row, int col )
{
printf ( "\x1BY%c%c", ' ' + row, ' ' + col );
}

void cursorOff()
{
printf( "\x1Bf" );
}

#endif
15 changes: 14 additions & 1 deletion src/modules/system_helper.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
void setUpScreen( void );
void resetDefaultScreen( void );
void resetDefaultScreen( void );
#ifdef __CPM__
void cls();
void gotoyx( int row, int col );
void cursorOff();
#endif

#ifdef __CPM__
#define SCREEN_WIDTH 79
#else
#define SCREEN_WIDTH 41
#endif

#define SCREEN_HEIGHT 23
2 changes: 0 additions & 2 deletions src/multicalc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@ int main( void )
quitFlag = argumentString[ 0 ];
}

// resetDefaultScreen();

return EXIT_SUCCESS;
}

0 comments on commit cb982c1

Please sign in to comment.