Skip to content

Commit

Permalink
Matt toolkit (#164)
Browse files Browse the repository at this point in the history
* Adding comments to all toolkit methods.

Adding pulldown menu for prototypes.

* Starting support for generating patches.

Starting context sensitive menus that should make
writing NewtonScript much easier. Much like NTK.

* Added machine code function sample code.

* Formatting.

* Easier way to integrate sample scripts.

* Use NS PatchFileFromARM to patch a ROM file

using ARM instructions.

* Disable Schlumberger Signature check.

* Setting new version 2022.4.18

* Formatting

* More formatting

* Updating gitignore

* Formatting autogenerated code.

* Removing generated UI files

* Linux complaints fixed.

* Fix for MSWindows

* More fixes for MSWindow
  • Loading branch information
MatthiasWM authored Mar 26, 2022
1 parent afe1e32 commit abe2a5f
Show file tree
Hide file tree
Showing 34 changed files with 1,274 additions and 159 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/clang-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
- uses: DoozyX/[email protected]
with:
source: '.'
exclude: './libffi* ./portaudio ./Packages ./Resources ./Drivers'
exclude: './libffi* ./portaudio ./Packages ./Resources ./Drivers ./Toolkit/TFLSampleScripts.cpp ./Toolkit/TFLSampleScripts.h'
extensions: 'h,cpp,t,mm,c'
clangFormatVersion: 13
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,12 @@ DerivedData/
/app/FLTK/TFLAppUI.h
/app/FLTK/TFLSettingsUI.cpp
/app/FLTK/TFLSettingsUI.h
/app/FLTK/TFLRexImage.h
/app/FLTK/TFLRexImage.cpp
/Toolkit/TFLToolkitUI.cpp
/Toolkit/TFLToolkitUI.h
/Toolkit/TFLSampleScripts.cpp
/Toolkit/TFLSampleScripts.h
/Drivers/packages/MemDumper
/Drivers/EinsteinPortEnabler/portenabler.ntkc
/app/FLTK/TFLRexImage.h
/app/FLTK/TFLRexImage.cpp
/_Build_/AndroidStudioNative/einstein/signingConfigRelease.properties
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

cmake_minimum_required(VERSION 3.13)

project( "Einstein" VERSION "2022.4.17" )
project( "Einstein" VERSION "2022.4.18" )

# ---- Configuration for all targets on all platforms

Expand Down
8 changes: 7 additions & 1 deletion Emulator/JIT/Generic/TJITGenericROMPatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ TJITGenericPatch timeBase4(0x30F088, kROMPatchVoid, kROMPatchVoid, kROMPatchVoid
TJITGenericPatch ignoreSettingTime(0x0008A20C, kROMPatchVoid, kROMPatchVoid, kROMPatchVoid,
0xe1a0f00e, "Ignore setting time"); // mov pc, lr

// Disable the Schlumberger signature verification for Watson ROMs.
TJITGenericPatch watsonSig1(kROMPatchVoid, kROMPatchVoid, kROMPatchVoid, 0x007F3284,
0xE3A00000, "Disable Watson Signature Check (1/2)"); // mov r0, #0
TJITGenericPatch watsonSig3(kROMPatchVoid, kROMPatchVoid, kROMPatchVoid, 0x007F3288,
0xE1A0f00E, "Disable Watson Signature Check (2/2)"); // mov pc, lr

// ========================================================================== //
// MARK: -
// TJITGenericPatchManager
Expand Down Expand Up @@ -319,7 +325,7 @@ TJITGenericPatchObject::GetOffsetInROM(KSInt32 inROMId)

/**
\brief Create and add a new patch
\param inAddr0, inAddr1, inAddr2 patch address for MP2100US, MP2100D, and eMate ROMs
\param inAddr0, inAddr1, inAddr2, inAddr3 patch address for MP2100US, MP2100D, eMate ROMs, and Watson
\param value a new value for that address, can be data or instructions
\param name a name for this patch
*/
Expand Down
12 changes: 4 additions & 8 deletions Monitor/TFLMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,20 @@ TFLMonitor::DrawScreen()
{
if (!IsLastScreenHalted())
{
// Clear the terminal.
// mwTerminal->clear();
mwTerminal->clear();
theResult = true;
}
SetLastScreenHalted(true);
if (!(GetEmulator()->IsRunning() == 0 && GetEmulator()->IsPaused() == 0))
DrawScreenHalted();
DrawScreenHalted();
} else
{
if (IsLastScreenHalted())
{
// Clear the terminal.
// mwTerminal->clear();
mwTerminal->clear();
theResult = true;
}
SetLastScreenHalted(false);
if (!(GetEmulator()->IsRunning() == 0 && GetEmulator()->IsPaused() == 0))
DrawScreenRunning();
DrawScreenRunning();
}
mwTerminal->redraw();
return theResult;
Expand Down
2 changes: 1 addition & 1 deletion Monitor/TMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class TMonitor : public TMonitorCore
}

#if TARGET_UI_FLTK
// no support for signalling yet
// no support for signaling yet
#else
///
/// Get monitor socket (notified of state changes).
Expand Down
6 changes: 6 additions & 0 deletions Toolkit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,16 @@ list (APPEND app_sources
Toolkit/TFLInspectorPanel.h
Toolkit/TFLTerminalPanel.cpp
Toolkit/TFLTerminalPanel.h
Toolkit/TFLSampleScripts.cpp
Toolkit/TFLSampleScripts.h
Toolkit/TFLSampleScripts.fl
Toolkit/TFLScriptPanel.cpp
Toolkit/TFLScriptPanel.h
Toolkit/TToolkitPlatform.cpp
Toolkit/TToolkitPlatform.h
Toolkit/TToolkitPrototypes.cpp
Toolkit/TToolkitPrototypes.h
)

build_with_fluid( TFLToolkitUI Toolkit )
build_with_fluid( TFLSampleScripts Toolkit )
31 changes: 31 additions & 0 deletions Toolkit/SampleScripts/HelloWorld.ns
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// NewtonScript example: Hello, World!
//

kAppName := "Hello:WONKO";
kAppSymbol := '|Hello:WONKO|;
kAppLabel := "Hello";

newt.theForm := {
viewBounds: {
left: 0, top: 50, right: 200, bottom: 120
},
_proto: protoFloatNGo
};

helloButton := {
text: "Say Hello",
viewBounds: {
left: 50, top: 25, right: 150, bottom: 50
},
buttonClickScript: func()
begin
ModalConfirm(
"Hello World of NewtonScript.\r\rHow exciting to see you!",
[ "OK" ]
);
end,
_proto: protoTextButton
};
AddStepForm( newt.theForm, helloButton);
StepDeclare( newt.theForm, helloButton, 'helloButton);
55 changes: 55 additions & 0 deletions Toolkit/SampleScripts/NativeFunction.ns
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// NewtonScript example: Native Call
//
// How to write ARM machine code within NewtonScript.
//

kAppName := "Hello:WONKO";
kAppSymbol := '|Hello:WONKO|;
kAppLabel := "Hello";

newt.theForm := {
viewBounds: {
left: 0, top: 50, right: 200, bottom: 120
},
_proto: protoFloatNGo
};

mathFunction := {
_proto: protoStaticText,
text: "4+8 =",
viewBounds: RelBounds(50, 25, 30, 20)
};
AddStepForm(newt.theForm, mathFunction);
StepDeclare(newt.theForm, mathFunction, 'mathFunction);

mathResult := {
_proto: protoStaticText,
nativeMath: {
class : 'BinCFunction,
numArgs: 2,
offset: 0,
code: MakeBinaryFromARM("
ldr r1, [r1] @ Unref the first argument
ldr r1, [r1] @ Get the integer object
mov r1, r1, lsr #2 @ convert it into an integer
ldr r2, [r2]
ldr r2, [r2] @ do the same with the second arg
mov r2, r2, lsr #2
add r0, r1, r2 @ add both integers
mov r0, r0, lsl #2 @ convert the result into an integer object
mov pc, lr @ return to the interpreter
")
},
newtonScriptMath: func(a, b) begin
return a+b;
end,
ViewSetupFormScript: func() begin
SetValue(self, 'text, NumberStr( self:nativeMath(4, 8) ) );
end,
text: "Result",
viewBounds: RelBounds(80, 25, 80, 20)
};
AddStepForm(newt.theForm, mathResult);
StepDeclare(newt.theForm, mathResult, 'mathResult);

2 changes: 1 addition & 1 deletion Toolkit/TFLInspectorPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// File: TFLInspectorPanel.cp
// Project: Einstein
//
// Copyright 2003-2020 by Paul Guyot and Matthias Melcher.
// Copyright 2003-2022 by Paul Guyot and Matthias Melcher.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Toolkit/TFLInspectorPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// File: TFLInspectorPanel.h
// Project: Einstein
//
// Copyright 2003-2020 by Paul Guyot and Matthias Melcher.
// Copyright 2003-2022 by Paul Guyot and Matthias Melcher.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand Down
10 changes: 10 additions & 0 deletions Toolkit/TFLSampleScripts.fl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# data file for the Fltk User Interface Designer (fluid)
version 1.0400
avoid_early_includes
header_name {.h}
code_name {.cpp}
data kToolkitSampleScriptHelloWorld {selected public local filename {SampleScripts/HelloWorld.ns} textmode
}

data kToolkitSampleScriptNativeFunction {public local filename {SampleScripts/NativeFunction.ns} textmode
}
72 changes: 69 additions & 3 deletions Toolkit/TFLScriptPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// File: TFLScriptPanel.cpp
// Project: Einstein
//
// Copyright 2003-2020 by Paul Guyot and Matthias Melcher.
// Copyright 2003-2022 by Paul Guyot and Matthias Melcher.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -24,6 +24,7 @@
#include "TFLScriptPanel.h"

#include "TTkScript.h"
#include "TToolkit.h"

#include <cstdlib>
#include <ctype.h>
Expand Down Expand Up @@ -68,28 +69,75 @@ TFLScriptPanel::DupSourceCode()
return mEditor->buffer()->text();
}

/**
Replace the current script with new text.
\param sourcecode new script in utf8 ecoding.
*/
void
TFLScriptPanel::SetSourceCode(const char* sourcecode)
{
mEditor->buffer()->text(sourcecode);
}

/**
Mark script dirty.
*/
void
TFLScriptPanel::SetDirty()
{
mScript->SetDirty();
}

/**
Mark script clean.
*/
void
TFLScriptPanel::ClearDirty()
{
mScript->ClearDirty();
}

/**
Create a Frame for the given proto.
\param protoName name of the proto
\todo find a good place for adding the template (next free line?, after "\n};*\n", after "STepDeclare", leave it to the user?)
\todo how much text should we actually generate for which proto
\todo how can we mark text that needs to be modified by the user
*/
void
TFLScriptPanel::AddProtoTemplate(const char* protoName)
{
if (!protoName)
return;
// get a short version of the proto name
char name[64];
strcpy(name, "my");
if (strncmp(protoName, "cl", 2) == 0)
{
strcat(name, protoName + 2);
} else if (strncmp(protoName, "proto", 5) == 0)
{
strcat(name, protoName + 5);
} else
{
strcat(name, protoName);
}
// Trust the user with the text insert postion
char buf[2048];
snprintf(buf, sizeof(buf),
"%s := {\n\t_proto: %s,\n\tviewBounds: RelBounds(10, 10, 100, 20)\n};\n"
"AddStepForm(newt.theForm, %s);\n"
"StepDeclare(newt.theForm, %s, '%s);\n\n",
name, protoName, name, name, name);
auto crsr = mEditor->insert_position();
mEditor->insert(buf);
mEditor->insert_position(crsr);
}

// MARK: - TFLScriptEditor -

// FIXME: the syntax highlighting was taken from the FLTK "C" editor demo and needs to be updated to NewtonScript
// FIXME: actually, lex and yacc could be used for syntax highlighting... .
// TODO: the syntax highlighting was taken from the FLTK "C" editor demo and needs to be updated to NewtonScript
// TODO: actually, lex and yacc could be used for syntax highlighting... .

// Syntax highlighting stuff...

Expand Down Expand Up @@ -521,6 +569,24 @@ TFLScriptEditor::style_update(int pos, // I - Position of update
free(style);
}

// MARK: - TFLMenuBar -

/**
Handle menu item activation before the menus pop up.
\param event
\return 1 if the event was handled here
*/
int
TFLMenuBar::handle(int event)
{
if (event == FL_PUSH)
{
// update visibility based on the selected proto
gToolkit->UpdateMenuBar();
}
return Fl_Menu_Bar::handle(event);
}

// ============================================================================ //
// NewtonScript
//
Expand Down
19 changes: 17 additions & 2 deletions Toolkit/TFLScriptPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// File: TFLScriptPanel.h
// Project: Einstein
//
// Copyright 2003-2020 by Paul Guyot and Matthias Melcher.
// Copyright 2003-2022 by Paul Guyot and Matthias Melcher.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
Expand All @@ -28,6 +28,7 @@
#include "app/FLTK/TFLApp.h"

#include <FL/Fl_Group.H>
#include <FL/Fl_Menu_Bar.H>
#include <FL/Fl_Text_Buffer.H>
#include <FL/Fl_Text_Editor.H>

Expand All @@ -38,7 +39,7 @@ class TFLScriptBuffer;
class TTkScript;

/**
* This class provides and FLTK UI to edit NewtonScript source code.
* This class provides an FLTK UI to edit NewtonScript source code.
*/
class TFLScriptPanel : public Fl_Group
{
Expand All @@ -63,6 +64,8 @@ class TFLScriptPanel : public Fl_Group
void SetDirty();
void ClearDirty();

void AddProtoTemplate(const char* protoName);

private:
TFLScriptEditor* mEditor = nullptr;
TTkScript* mScript = nullptr;
Expand Down Expand Up @@ -106,6 +109,18 @@ class TFLScriptEditor : public Fl_Text_Editor
static void style_unfinished_cb(int, void*);
};

class TFLMenuBar : public Fl_Menu_Bar
{
public:
TFLMenuBar(int x, int y, int w, int h, const char* label = nullptr) :
Fl_Menu_Bar(x, y, w, h, label)
{
}

protected:
int handle(int e);
};

#endif
// _T_FL_SCRIPT_PANEL_H

Expand Down
Loading

0 comments on commit abe2a5f

Please sign in to comment.