Skip to content

Commit

Permalink
Update to long double and add 10 to the X
Browse files Browse the repository at this point in the history
  • Loading branch information
HadrianFinch committed Oct 17, 2021
1 parent 7947500 commit 5e1f243
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 61 deletions.
Binary file modified HP11C.obj
Binary file not shown.
Binary file modified MainWindow.obj
Binary file not shown.
Binary file modified bin/HP11C.exe
Binary file not shown.
Binary file modified bin/HP11C.ilk
Binary file not shown.
Binary file modified bin/HP11C.pdb
Binary file not shown.
Binary file modified button.obj
Binary file not shown.
Binary file modified buttonTypes.obj
Binary file not shown.
Binary file modified decode.obj
Binary file not shown.
Binary file modified files.obj
Binary file not shown.
Binary file modified function.obj
Binary file not shown.
Binary file modified layerWindow.obj
Binary file not shown.
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ HP11C is a calculator app for windows that uses Reverse Polish Notation for calc
Download the [latest GitHub release](https://github.com/HadrianFinch/HP11C/releases) and run the installer, or download the standalone .exe from [here](https://github.com/HadrianFinch/HP11C/releases)

## Usage
Launch the app from the Start menu or type `hpcalc` in a command prompt or Run window. Or, if you have the standalone, run the.exe by double-clicking it.
Launch the app from the Start menu or type `hpcalc` in a command prompt or Run window. Or, if you have the standalone, run the.exe by long double-clicking it.

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Expand Down
Binary file modified registers.obj
Binary file not shown.
18 changes: 9 additions & 9 deletions src/HP11C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ HINSTANCE g_hInstance = NULL;
IWICImagingFactory* g_pWICFactory = nullptr;
PCWSTR HKEY_PROJECT_TARGET = L"SOFTWARE\\BlueDragon\\HP11C";

double stack[4] = {};
long double stack[4] = {};
wstring stackString;
bool inEditMode = false;

Expand Down Expand Up @@ -35,10 +35,10 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
return HRESULT_CODE(hr);
}

SetX(LoadDoubleFromRegister(L"Stack0", 0));
stack[1] = LoadDoubleFromRegister(L"Stack1", 0);
stack[2] = LoadDoubleFromRegister(L"Stack2", 0);
stack[3] = LoadDoubleFromRegister(L"Stack3", 0);
SetX(LoadlongdoubleFromRegister(L"Stack0", 0));
stack[1] = LoadlongdoubleFromRegister(L"Stack1", 0);
stack[2] = LoadlongdoubleFromRegister(L"Stack2", 0);
stack[3] = LoadlongdoubleFromRegister(L"Stack3", 0);

CreateMainWindow();

Expand All @@ -50,8 +50,8 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
DispatchMessage(&msg);
}

SaveDoubleToRegister(L"Stack0", stack[0]);
SaveDoubleToRegister(L"Stack1", stack[1]);
SaveDoubleToRegister(L"Stack2", stack[2]);
SaveDoubleToRegister(L"Stack3", stack[3]);
SavelongdoubleToRegister(L"Stack0", stack[0]);
SavelongdoubleToRegister(L"Stack1", stack[1]);
SavelongdoubleToRegister(L"Stack2", stack[2]);
SavelongdoubleToRegister(L"Stack3", stack[3]);
}
2 changes: 1 addition & 1 deletion src/HP11C.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "resources.h"
#include "window.h"

extern double stack[4];
extern long double stack[4];
extern std::wstring stackString;
extern bool inEditMode;

Expand Down
15 changes: 2 additions & 13 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ void GetMonitorDPI(Window* pThis, WPARAM wParam, LPARAM lParam);
void KeyboardInputController(Window* pThis, WPARAM wParam, LPARAM lParam);

EditBox* pDisplayBox;
EditBox* pHeightInches;
EditBox* pWidthPixels;
EditBox* pHeightPixels;

Window* pButtonBackground;
EditBox* pDPIBox;

void CreateMainWindow()
{
Expand Down Expand Up @@ -75,6 +70,7 @@ void CreateMainWindow()
buttons[20]->OnClick(ChangeSignKeyPress);
buttons[16]->OnClick(OneOverX);
buttons[12]->OnClick(YtotheX);
buttons[8]->OnClick(TenTotheX);

// Other Keys
buttons[18]->OnClick(BackspaceKeyPress);
Expand Down Expand Up @@ -105,7 +101,7 @@ void CreateMainWindow()
// add the button background
rc.Size({488, 204});
rc.Point({7, 94});
pButtonBackground = Window::Create(rc, WindowType_Layered, IMG_BUTTON_BACKGROUND, pMainWindow);
Window* pButtonBackground = Window::Create(rc, WindowType_Layered, IMG_BUTTON_BACKGROUND, pMainWindow);
pButtonBackground->SetWindowPos(HWND_TOP, rc, 0);

// add the button overlay
Expand Down Expand Up @@ -210,13 +206,6 @@ void KeyboardInputController(Window* pThis, WPARAM keycode, LPARAM lParam)

void UpdateDisplay(void)
{
// WCHAR text[50] = {};
// StringCchPrintf(
// text,
// _countof(text),
// L"%.2f",
// stack[0]);

stack[0] = _wtof(stackString.c_str());
pDisplayBox->SetText(stackString);
}
76 changes: 47 additions & 29 deletions src/function.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "framework.h"
#include "HP11C.h"

void SetX(double val)
void SetX(long double val)
{
WCHAR formatSeed[10] = L"%.";
WCHAR formatString[10] = {};
Expand Down Expand Up @@ -147,8 +147,8 @@ void PlusKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();

double x = stack[0];
double y = stack[1];
long double x = stack[0];
long double y = stack[1];

SetX(y + x);

Expand All @@ -163,8 +163,8 @@ void MinusKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();

double x = stack[0];
double y = stack[1];
long double x = stack[0];
long double y = stack[1];

SetX(y - x);

Expand All @@ -179,8 +179,8 @@ void TimesKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();

double x = stack[0];
double y = stack[1];
long double x = stack[0];
long double y = stack[1];

SetX(y * x);

Expand All @@ -195,8 +195,8 @@ void DevideKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();

double x = stack[0];
double y = stack[1];
long double x = stack[0];
long double y = stack[1];

SetX(y / x);

Expand All @@ -218,7 +218,7 @@ void SqrtKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
GkeyActive = false;
ExitEditMode();

double square = stack[0] * stack[0];
long double square = stack[0] * stack[0];
SetX(square);

UpdateDisplay();
Expand All @@ -227,7 +227,7 @@ void SqrtKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();

double root = sqrt(stack[0]);
long double root = sqrt(stack[0]);
SetX(root);

UpdateDisplay();
Expand All @@ -245,14 +245,14 @@ void YtotheX(Window* pThis, WPARAM wParam, LPARAM lParam)
{
GkeyActive = false;

double precent = stack[0] / 100;
long double precent = stack[0] / 100;
SetX(precent);

UpdateDisplay();
}
else
{
double result = pow(stack[1], stack[0]);
long double result = pow(stack[1], stack[0]);
SetX(result);

UpdateDisplay();
Expand All @@ -275,6 +275,13 @@ void ChangeSignKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
UpdateDisplay();
}

void TenTotheX(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();
SetX(pow(10.0, stack[0]));
UpdateDisplay();
}

void OneOverX(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();
Expand All @@ -287,24 +294,35 @@ void OneOverX(Window* pThis, WPARAM wParam, LPARAM lParam)
void EnterKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();

stack[3] = stack[2];
stack[2] = stack[1];
stack[1] = stack[0];

if (stackString.find('.') == wstring::npos)
if (FkeyActive) // Orange
{
FkeyActive = false;
SetX((long double)rand() / (long double)RAND_MAX);
UpdateDisplay();
}
else if (GkeyActive) // Blue
{
stackString += L".";
for (int i = 0; i < f_fix; i++)
GkeyActive = false;
}
else
{
stack[3] = stack[2];
stack[2] = stack[1];
stack[1] = stack[0];

if (stackString.find('.') == wstring::npos)
{
stackString += L"0";
stackString += L".";
for (int i = 0; i < f_fix; i++)
{
stackString += L"0";
}
}

}

shiftStackOnEditMode = false;
shiftStackOnEditMode = false;

UpdateDisplay();
UpdateDisplay();
}
}

void BackspaceKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
Expand All @@ -323,7 +341,7 @@ void BackspaceKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
void XYReverseKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();
double x = stack[0];
long double x = stack[0];
SetX(stack[1]);
stack[1] = x;

Expand All @@ -341,7 +359,7 @@ void RollDown(Window* pThis, WPARAM wParam, LPARAM lParam)
GkeyActive = false;
ExitEditMode();

double stored = stack[3];
long double stored = stack[3];

stack[3] = stack[2];
stack[2] = stack[1];
Expand All @@ -354,7 +372,7 @@ void RollDown(Window* pThis, WPARAM wParam, LPARAM lParam)
{
ExitEditMode();

double x = stack[0];
long double x = stack[0];

SetX(stack[1]);

Expand Down
3 changes: 2 additions & 1 deletion src/function.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "framework.h"

class Window;
void SetX(double val);
void SetX(long double val);

// Numerical Keys
void Key0Press(Window* pThis, WPARAM wParam, LPARAM lParam);
Expand All @@ -24,6 +24,7 @@ void DevideKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam);
void SqrtKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam);
void ChangeSignKeyPress(Window* pThis, WPARAM wParam, LPARAM lParam);
void OneOverX(Window* pThis, WPARAM wParam, LPARAM lParam);
void TenTotheX(Window* pThis, WPARAM wParam, LPARAM lParam);
void YtotheX(Window* pThis, WPARAM wParam, LPARAM lParam);

// Other keys
Expand Down
10 changes: 5 additions & 5 deletions src/registers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ HRESULT SaveLongToRegister(PCWSTR registerName, long dataToSave)
return S_OK;
}

HRESULT SaveDoubleToRegister(PCWSTR registerName, double dataToSave)
HRESULT SavelongdoubleToRegister(PCWSTR registerName, long double dataToSave)
{
HKEY hkey = NULL;
auto result = RegCreateKeyEx(
Expand All @@ -194,7 +194,7 @@ HRESULT SaveDoubleToRegister(PCWSTR registerName, double dataToSave)
0,
REG_BINARY,
reinterpret_cast<LPBYTE>(&dataToSave),
sizeof(double));
sizeof(long double));
}

if (hkey != NULL)
Expand All @@ -209,12 +209,12 @@ HRESULT SaveDoubleToRegister(PCWSTR registerName, double dataToSave)
return S_OK;
}

double LoadDoubleFromRegister(PCWSTR registerName, double defaultValue)
long double LoadlongdoubleFromRegister(PCWSTR registerName, long double defaultValue)
{
HKEY hkey = NULL;
bool loaded = false;

double output = 0;
long double output = 0;

auto result = RegOpenKeyEx(
HKEY_CURRENT_USER,
Expand All @@ -225,7 +225,7 @@ double LoadDoubleFromRegister(PCWSTR registerName, double defaultValue)
if (result == ERROR_SUCCESS)
{
DWORD dwType;
DWORD cbData = sizeof(double);
DWORD cbData = sizeof(long double);

result = RegQueryValueEx(
hkey,
Expand Down
4 changes: 2 additions & 2 deletions src/registers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ PCWSTR LoadStringFromRegister(PCWSTR registerName, PCWSTR defaultValue);
HRESULT SaveStringToRegister(PCWSTR registerName, PCWSTR dataToSave);
long LoadlongFromRegister(PCWSTR registerName, long defaultValue);
HRESULT SaveLongToRegister(PCWSTR registerName, long dataToSave);
double LoadDoubleFromRegister(PCWSTR registerName, double defaultValue);
HRESULT SaveDoubleToRegister(PCWSTR registerName, double dataToSave);
long double LoadlongdoubleFromRegister(PCWSTR registerName, long double defaultValue);
HRESULT SavelongdoubleToRegister(PCWSTR registerName, long double dataToSave);
Binary file modified vc140.pdb
Binary file not shown.
Binary file modified window.obj
Binary file not shown.

0 comments on commit 5e1f243

Please sign in to comment.