Skip to content

Commit

Permalink
Change default options, add undo, and update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
watamario15 committed Oct 27, 2022
1 parent 59a0d22 commit 001eb89
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 30 deletions.
4 changes: 4 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ static LRESULT CALLBACK wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
case IDM_FILE_EXIT:
SendMessageW(hWnd, WM_CLOSE, 0, 0);
break;

case IDM_EDIT_UNDO:
ui::undo();
break;

case IDM_EDIT_CUT:
ui::cut();
Expand Down
13 changes: 8 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Brainfuck interpreter for SHARP Brain
This piece of software is an Brainfuck interpreter for SHARP Brain. This interpreter is "nice" in terms of [this](http://www.muppetlabs.com/~breadbox/bf/standards.html) specification.
# Brain fuck

![](running.png)

**Brain fuck** is a **Brain**fuck interpreter for [SHARP **Brain**](https://jp.sharp/edictionary/). This interpreter is "nice" in terms of [this specification](http://www.muppetlabs.com/~breadbox/bf/standards.html).

## Specs
Default settings are shown in **bold** typeface. For I/O charset, UTF-8 is default for input and ASCII is default for output.
Default options are shown in **bold** typeface. For I/O charset, UTF-8 is default for input and ASCII is default for output.

|Item|Detail|
|Item|Spec|
|:-:|:-:|
|Memory type|**8-bit integer (0 to 255)**, 8-bit two's-complement integer (-128 to 127)|
|Memory type|**8-bit two's-complement integer (-128 to 127)**, 8-bit integer (0 to 255)|
|Memory length|**infinity (your device's memory capacity)**|
|I/O charset|**ASCII, UTF-8**, Shift\_JIS|
|Input error|**input 0**, input FF, error|
Expand Down
9 changes: 5 additions & 4 deletions resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
#define IDM_FILE_SAVE 120
#define IDM_FILE_SAVE_AS 130
#define IDM_FILE_EXIT 140
#define IDM_EDIT_CUT 200
#define IDM_EDIT_COPY 210
#define IDM_EDIT_PASTE 220
#define IDM_EDIT_SELALL 230
#define IDM_EDIT_UNDO 200
#define IDM_EDIT_CUT 210
#define IDM_EDIT_COPY 220
#define IDM_EDIT_PASTE 230
#define IDM_EDIT_SELALL 240
#define IDM_BF_MEMTYPE_SIGNED 300
#define IDM_BF_MEMTYPE_UNSIGNED 301
#define IDM_BF_OUTPUT_ASCII 310
Expand Down
1 change: 1 addition & 0 deletions resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ menu MENU
}
POPUP "&Edit"
{
MENUITEM "&Undo", IDM_EDIT_UNDO
MENUITEM "Cu&t", IDM_EDIT_CUT
MENUITEM "&Copy", IDM_EDIT_COPY
MENUITEM "&Paste", IDM_EDIT_PASTE
Expand Down
Binary file added running.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 48 additions & 18 deletions ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static int topPadding = 0, scrX = 480, scrY = 320;
static unsigned int memViewStart = 0;
static wchar_t *retEditBuf = NULL, *retInBuf = NULL;
static std::wstring wstrFileName;
static bool withBOM = false, wordwrap = false;
static bool withBOM = false, wordwrap = true;
static enum newline_t newLine = NEWLINE_CRLF;
#ifdef UNDER_CE
static HWND hCmdBar;
Expand All @@ -81,7 +81,7 @@ static int dpi = 96, sysDPI = 96;
#endif

enum state_t state = STATE_INIT;
bool signedness = true, wrapInt = true, breakpoint = false, debug = false, dark = true;
bool signedness = true, wrapInt = true, breakpoint = false, debug = true, dark = true;
int speed = 10, outCharSet = IDM_BF_OUTPUT_ASCII, inCharSet = IDM_BF_INPUT_UTF8;
enum Brainfuck::noinput_t noInput = Brainfuck::NOINPUT_ZERO;
HWND hWnd;
Expand Down Expand Up @@ -341,13 +341,12 @@ void onSize() {
SendMessageW(hScrKB[i], WM_SETFONT, (WPARAM)newBtnFont, MAKELPARAM(TRUE, 0));
curX += adjust(30);
}
MoveWindow(hEditor, 0, topPadding + adjust(32), scrX, scrY - adjust(32) - adjust(64) - adjust(64),
TRUE);
MoveWindow(hEditor, 0, topPadding + adjust(32), scrX, scrY - adjust(32) - adjust(64) * 2, TRUE);
SendMessageW(hEditor, WM_SETFONT, (WPARAM)newEditFont, MAKELPARAM(TRUE, 0));
MoveWindow(hInput, 0, scrY + topPadding - adjust(64) - adjust(64), scrX / 2, adjust(64), TRUE);
MoveWindow(hInput, 0, scrY + topPadding - adjust(64) * 2, scrX / 2, adjust(64), TRUE);
SendMessageW(hInput, WM_SETFONT, (WPARAM)newEditFont, MAKELPARAM(TRUE, 0));
MoveWindow(hOutput, scrX / 2, scrY + topPadding - adjust(64) - adjust(64), scrX - scrX / 2,
adjust(64), TRUE);
MoveWindow(hOutput, scrX / 2, scrY + topPadding - adjust(64) * 2, scrX - scrX / 2, adjust(64),
TRUE);
SendMessageW(hOutput, WM_SETFONT, (WPARAM)newEditFont, MAKELPARAM(TRUE, 0));
MoveWindow(hMemView, 0, scrY + topPadding - adjust(64), scrX, adjust(64), TRUE);
SendMessageW(hMemView, WM_SETFONT, (WPARAM)newEditFont, MAKELPARAM(TRUE, 0));
Expand Down Expand Up @@ -405,9 +404,12 @@ void onInitMenuPopup() {
// Options -> Word wrap
CheckMenuItem(hMenu, IDM_OPT_WORDWRAP, MF_BYCOMMAND | wordwrap ? MF_CHECKED : MF_UNCHECKED);

bool undoable = SendMessageW(hEditor, EM_CANUNDO, 0, 0) != 0;

if (state == STATE_INIT) {
enableMenus(IDM_FILE_NEW, true);
enableMenus(IDM_FILE_OPEN, true);
enableMenus(IDM_EDIT_UNDO, undoable);
enableMenus(IDM_BF_MEMTYPE_UNSIGNED, true);
enableMenus(IDM_BF_OUTPUT_HEX, true);
enableMenus(IDM_BF_INPUT_HEX, true);
Expand All @@ -422,6 +424,7 @@ void onInitMenuPopup() {
} else if (state == STATE_RUN) {
enableMenus(IDM_FILE_NEW, false);
enableMenus(IDM_FILE_OPEN, false);
enableMenus(IDM_EDIT_UNDO, false);
enableMenus(IDM_BF_MEMTYPE_UNSIGNED, false);
enableMenus(IDM_BF_OUTPUT_HEX, false);
enableMenus(IDM_BF_INPUT_HEX, false);
Expand All @@ -436,6 +439,7 @@ void onInitMenuPopup() {
} else if (state == STATE_PAUSE || state == STATE_FINISH) {
enableMenus(IDM_FILE_NEW, false);
enableMenus(IDM_FILE_OPEN, false);
enableMenus(IDM_EDIT_UNDO, false);
enableMenus(IDM_BF_MEMTYPE_UNSIGNED, false);
enableMenus(IDM_BF_OUTPUT_HEX, false);
enableMenus(IDM_BF_INPUT_HEX, false);
Expand Down Expand Up @@ -482,32 +486,57 @@ void paste() { SendMessageW(hFocused, WM_PASTE, 0, 0); }

void selAll() { SendMessageW(hFocused, EM_SETSEL, 0, -1); }

void undo() { SendMessageW(hEditor, EM_UNDO, 0, 0); }

int messageBox(HWND _hWnd, const wchar_t *_lpText, const wchar_t *_lpCaption, unsigned int _uType) {
#ifdef UNDER_CE
return MessageBoxW(_hWnd, _lpText, _lpCaption, _uType);
#else
#ifndef UNDER_CE
if (taskDialog) {
int buttons = (_uType & 0xF) == MB_OK ? 1 : 14, result;
// Tests whether _uType uses some features that TaskDialog doesn't support.
if (_uType & ~(MB_ICONMASK | MB_TYPEMASK)) goto mbfallback;

int buttons;
switch (_uType & MB_TYPEMASK) {
case MB_OK:
buttons = 1;
break;
case MB_OKCANCEL:
buttons = 1 + 8;
break;
case MB_RETRYCANCEL:
buttons = 16 + 8;
break;
case MB_YESNO:
buttons = 2 + 4;
break;
case MB_YESNOCANCEL:
buttons = 2 + 4 + 8;
break;
default: // Not supported by TaskDialog.
goto mbfallback;
}

wchar_t *icon;
switch (_uType & 0xF0) {
switch (_uType & MB_ICONMASK) {
case 0:
icon = NULL;
break;
case MB_ICONWARNING:
case MB_ICONWARNING: // Same value as MB_ICONEXCLAMATION.
icon = MAKEINTRESOURCEW(-1);
break;
case MB_ICONERROR:
case MB_ICONERROR: // Same value as MB_ICONSTOP and MB_ICONHAND.
icon = MAKEINTRESOURCEW(-2);
break;
default:
default: // Fallbacks everything else for Information icon.
icon = MAKEINTRESOURCEW(-3);
}

int result;
taskDialog(_hWnd, hInst, _lpCaption, L"", _lpText, buttons, icon, &result);
return result;
} else {
return MessageBoxW(_hWnd, _lpText, _lpCaption, _uType);
}
mbfallback:
#endif
return MessageBoxW(_hWnd, _lpText, _lpCaption, _uType);
}

// Hook window procedure for the edit control in the memory view options dialog.
Expand Down Expand Up @@ -936,7 +965,8 @@ void openFile(bool _newFile, const wchar_t *_fileName) {
delete[] fileBuf;
return;
}
wchar_t *wcFileBuf = new wchar_t[length + 1]();
wchar_t *wcFileBuf = new wchar_t[length + 1];
wcFileBuf[length] = 0;
MultiByteToWideChar(CP_UTF8, 0, fileBuf + padding, readLen - padding, wcFileBuf, length);
delete[] fileBuf;

Expand Down
12 changes: 9 additions & 3 deletions ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ void cut();
void copy();
void paste();
void selAll();

// Shows a message box. Uses TaskDialog if available, and if not, falls back to MessageBoxW.
// Supports only MB_OK, MB_YESNOCANCEL, MB_ICONWARNING, MB_ICONINFORMATION, and MB_ICONERROR.
void undo();

// Shows a message box with TaskDialog or MessageBoxW.
//
// When the system this program is running on supports TaskDialog, and no features that are
// MessageBoxW specific (MB_ABORTRETRYIGNORE, MB_CANCELTRYCONTINUE, MB_HELP, default selection, etc)
// is used, this function uses TaskDialog. In other cases, uses MessageBoxW.
// This function substitutes MB_ICONQUESTION with MB_ICONINFORMATION on TaskDialog, as it doesn't
// support it.
int messageBox(HWND _hWnd, const wchar_t *_lpText, const wchar_t *_lpCaption, unsigned int _uType);

// Sets a UI state.
Expand Down

0 comments on commit 001eb89

Please sign in to comment.