Skip to content

Commit abe2a5f

Browse files
authored
Matt toolkit (#164)
* 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
1 parent afe1e32 commit abe2a5f

34 files changed

+1274
-159
lines changed

.github/workflows/clang-format.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ jobs:
1111
- uses: DoozyX/[email protected]
1212
with:
1313
source: '.'
14-
exclude: './libffi* ./portaudio ./Packages ./Resources ./Drivers'
14+
exclude: './libffi* ./portaudio ./Packages ./Resources ./Drivers ./Toolkit/TFLSampleScripts.cpp ./Toolkit/TFLSampleScripts.h'
1515
extensions: 'h,cpp,t,mm,c'
1616
clangFormatVersion: 13

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ DerivedData/
3636
/app/FLTK/TFLAppUI.h
3737
/app/FLTK/TFLSettingsUI.cpp
3838
/app/FLTK/TFLSettingsUI.h
39+
/app/FLTK/TFLRexImage.h
40+
/app/FLTK/TFLRexImage.cpp
3941
/Toolkit/TFLToolkitUI.cpp
4042
/Toolkit/TFLToolkitUI.h
43+
/Toolkit/TFLSampleScripts.cpp
44+
/Toolkit/TFLSampleScripts.h
4145
/Drivers/packages/MemDumper
4246
/Drivers/EinsteinPortEnabler/portenabler.ntkc
43-
/app/FLTK/TFLRexImage.h
44-
/app/FLTK/TFLRexImage.cpp
4547
/_Build_/AndroidStudioNative/einstein/signingConfigRelease.properties

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
cmake_minimum_required(VERSION 3.13)
99

10-
project( "Einstein" VERSION "2022.4.17" )
10+
project( "Einstein" VERSION "2022.4.18" )
1111

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

Emulator/JIT/Generic/TJITGenericROMPatch.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,12 @@ TJITGenericPatch timeBase4(0x30F088, kROMPatchVoid, kROMPatchVoid, kROMPatchVoid
176176
TJITGenericPatch ignoreSettingTime(0x0008A20C, kROMPatchVoid, kROMPatchVoid, kROMPatchVoid,
177177
0xe1a0f00e, "Ignore setting time"); // mov pc, lr
178178

179+
// Disable the Schlumberger signature verification for Watson ROMs.
180+
TJITGenericPatch watsonSig1(kROMPatchVoid, kROMPatchVoid, kROMPatchVoid, 0x007F3284,
181+
0xE3A00000, "Disable Watson Signature Check (1/2)"); // mov r0, #0
182+
TJITGenericPatch watsonSig3(kROMPatchVoid, kROMPatchVoid, kROMPatchVoid, 0x007F3288,
183+
0xE1A0f00E, "Disable Watson Signature Check (2/2)"); // mov pc, lr
184+
179185
// ========================================================================== //
180186
// MARK: -
181187
// TJITGenericPatchManager
@@ -319,7 +325,7 @@ TJITGenericPatchObject::GetOffsetInROM(KSInt32 inROMId)
319325

320326
/**
321327
\brief Create and add a new patch
322-
\param inAddr0, inAddr1, inAddr2 patch address for MP2100US, MP2100D, and eMate ROMs
328+
\param inAddr0, inAddr1, inAddr2, inAddr3 patch address for MP2100US, MP2100D, eMate ROMs, and Watson
323329
\param value a new value for that address, can be data or instructions
324330
\param name a name for this patch
325331
*/

Monitor/TFLMonitor.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,20 @@ TFLMonitor::DrawScreen()
6363
{
6464
if (!IsLastScreenHalted())
6565
{
66-
// Clear the terminal.
67-
// mwTerminal->clear();
66+
mwTerminal->clear();
6867
theResult = true;
6968
}
7069
SetLastScreenHalted(true);
71-
if (!(GetEmulator()->IsRunning() == 0 && GetEmulator()->IsPaused() == 0))
72-
DrawScreenHalted();
70+
DrawScreenHalted();
7371
} else
7472
{
7573
if (IsLastScreenHalted())
7674
{
77-
// Clear the terminal.
78-
// mwTerminal->clear();
75+
mwTerminal->clear();
7976
theResult = true;
8077
}
8178
SetLastScreenHalted(false);
82-
if (!(GetEmulator()->IsRunning() == 0 && GetEmulator()->IsPaused() == 0))
83-
DrawScreenRunning();
79+
DrawScreenRunning();
8480
}
8581
mwTerminal->redraw();
8682
return theResult;

Monitor/TMonitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ class TMonitor : public TMonitorCore
138138
}
139139

140140
#if TARGET_UI_FLTK
141-
// no support for signalling yet
141+
// no support for signaling yet
142142
#else
143143
///
144144
/// Get monitor socket (notified of state changes).

Toolkit/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,16 @@ list (APPEND app_sources
2222
Toolkit/TFLInspectorPanel.h
2323
Toolkit/TFLTerminalPanel.cpp
2424
Toolkit/TFLTerminalPanel.h
25+
Toolkit/TFLSampleScripts.cpp
26+
Toolkit/TFLSampleScripts.h
27+
Toolkit/TFLSampleScripts.fl
2528
Toolkit/TFLScriptPanel.cpp
2629
Toolkit/TFLScriptPanel.h
30+
Toolkit/TToolkitPlatform.cpp
31+
Toolkit/TToolkitPlatform.h
2732
Toolkit/TToolkitPrototypes.cpp
2833
Toolkit/TToolkitPrototypes.h
2934
)
3035

3136
build_with_fluid( TFLToolkitUI Toolkit )
37+
build_with_fluid( TFLSampleScripts Toolkit )

Toolkit/SampleScripts/HelloWorld.ns

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// NewtonScript example: Hello, World!
3+
//
4+
5+
kAppName := "Hello:WONKO";
6+
kAppSymbol := '|Hello:WONKO|;
7+
kAppLabel := "Hello";
8+
9+
newt.theForm := {
10+
viewBounds: {
11+
left: 0, top: 50, right: 200, bottom: 120
12+
},
13+
_proto: protoFloatNGo
14+
};
15+
16+
helloButton := {
17+
text: "Say Hello",
18+
viewBounds: {
19+
left: 50, top: 25, right: 150, bottom: 50
20+
},
21+
buttonClickScript: func()
22+
begin
23+
ModalConfirm(
24+
"Hello World of NewtonScript.\r\rHow exciting to see you!",
25+
[ "OK" ]
26+
);
27+
end,
28+
_proto: protoTextButton
29+
};
30+
AddStepForm( newt.theForm, helloButton);
31+
StepDeclare( newt.theForm, helloButton, 'helloButton);
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//
2+
// NewtonScript example: Native Call
3+
//
4+
// How to write ARM machine code within NewtonScript.
5+
//
6+
7+
kAppName := "Hello:WONKO";
8+
kAppSymbol := '|Hello:WONKO|;
9+
kAppLabel := "Hello";
10+
11+
newt.theForm := {
12+
viewBounds: {
13+
left: 0, top: 50, right: 200, bottom: 120
14+
},
15+
_proto: protoFloatNGo
16+
};
17+
18+
mathFunction := {
19+
_proto: protoStaticText,
20+
text: "4+8 =",
21+
viewBounds: RelBounds(50, 25, 30, 20)
22+
};
23+
AddStepForm(newt.theForm, mathFunction);
24+
StepDeclare(newt.theForm, mathFunction, 'mathFunction);
25+
26+
mathResult := {
27+
_proto: protoStaticText,
28+
nativeMath: {
29+
class : 'BinCFunction,
30+
numArgs: 2,
31+
offset: 0,
32+
code: MakeBinaryFromARM("
33+
ldr r1, [r1] @ Unref the first argument
34+
ldr r1, [r1] @ Get the integer object
35+
mov r1, r1, lsr #2 @ convert it into an integer
36+
ldr r2, [r2]
37+
ldr r2, [r2] @ do the same with the second arg
38+
mov r2, r2, lsr #2
39+
add r0, r1, r2 @ add both integers
40+
mov r0, r0, lsl #2 @ convert the result into an integer object
41+
mov pc, lr @ return to the interpreter
42+
")
43+
},
44+
newtonScriptMath: func(a, b) begin
45+
return a+b;
46+
end,
47+
ViewSetupFormScript: func() begin
48+
SetValue(self, 'text, NumberStr( self:nativeMath(4, 8) ) );
49+
end,
50+
text: "Result",
51+
viewBounds: RelBounds(80, 25, 80, 20)
52+
};
53+
AddStepForm(newt.theForm, mathResult);
54+
StepDeclare(newt.theForm, mathResult, 'mathResult);
55+

Toolkit/TFLInspectorPanel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// File: TFLInspectorPanel.cp
33
// Project: Einstein
44
//
5-
// Copyright 2003-2020 by Paul Guyot and Matthias Melcher.
5+
// Copyright 2003-2022 by Paul Guyot and Matthias Melcher.
66
//
77
// This program is free software; you can redistribute it and/or modify
88
// it under the terms of the GNU General Public License as published by

Toolkit/TFLInspectorPanel.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// File: TFLInspectorPanel.h
33
// Project: Einstein
44
//
5-
// Copyright 2003-2020 by Paul Guyot and Matthias Melcher.
5+
// Copyright 2003-2022 by Paul Guyot and Matthias Melcher.
66
//
77
// This program is free software; you can redistribute it and/or modify
88
// it under the terms of the GNU General Public License as published by

Toolkit/TFLSampleScripts.fl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# data file for the Fltk User Interface Designer (fluid)
2+
version 1.0400
3+
avoid_early_includes
4+
header_name {.h}
5+
code_name {.cpp}
6+
data kToolkitSampleScriptHelloWorld {selected public local filename {SampleScripts/HelloWorld.ns} textmode
7+
}
8+
9+
data kToolkitSampleScriptNativeFunction {public local filename {SampleScripts/NativeFunction.ns} textmode
10+
}

Toolkit/TFLScriptPanel.cpp

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// File: TFLScriptPanel.cpp
33
// Project: Einstein
44
//
5-
// Copyright 2003-2020 by Paul Guyot and Matthias Melcher.
5+
// Copyright 2003-2022 by Paul Guyot and Matthias Melcher.
66
//
77
// This program is free software; you can redistribute it and/or modify
88
// it under the terms of the GNU General Public License as published by
@@ -24,6 +24,7 @@
2424
#include "TFLScriptPanel.h"
2525

2626
#include "TTkScript.h"
27+
#include "TToolkit.h"
2728

2829
#include <cstdlib>
2930
#include <ctype.h>
@@ -68,28 +69,75 @@ TFLScriptPanel::DupSourceCode()
6869
return mEditor->buffer()->text();
6970
}
7071

72+
/**
73+
Replace the current script with new text.
74+
\param sourcecode new script in utf8 ecoding.
75+
*/
7176
void
7277
TFLScriptPanel::SetSourceCode(const char* sourcecode)
7378
{
7479
mEditor->buffer()->text(sourcecode);
7580
}
7681

82+
/**
83+
Mark script dirty.
84+
*/
7785
void
7886
TFLScriptPanel::SetDirty()
7987
{
8088
mScript->SetDirty();
8189
}
8290

91+
/**
92+
Mark script clean.
93+
*/
8394
void
8495
TFLScriptPanel::ClearDirty()
8596
{
8697
mScript->ClearDirty();
8798
}
8899

100+
/**
101+
Create a Frame for the given proto.
102+
\param protoName name of the proto
103+
\todo find a good place for adding the template (next free line?, after "\n};*\n", after "STepDeclare", leave it to the user?)
104+
\todo how much text should we actually generate for which proto
105+
\todo how can we mark text that needs to be modified by the user
106+
*/
107+
void
108+
TFLScriptPanel::AddProtoTemplate(const char* protoName)
109+
{
110+
if (!protoName)
111+
return;
112+
// get a short version of the proto name
113+
char name[64];
114+
strcpy(name, "my");
115+
if (strncmp(protoName, "cl", 2) == 0)
116+
{
117+
strcat(name, protoName + 2);
118+
} else if (strncmp(protoName, "proto", 5) == 0)
119+
{
120+
strcat(name, protoName + 5);
121+
} else
122+
{
123+
strcat(name, protoName);
124+
}
125+
// Trust the user with the text insert postion
126+
char buf[2048];
127+
snprintf(buf, sizeof(buf),
128+
"%s := {\n\t_proto: %s,\n\tviewBounds: RelBounds(10, 10, 100, 20)\n};\n"
129+
"AddStepForm(newt.theForm, %s);\n"
130+
"StepDeclare(newt.theForm, %s, '%s);\n\n",
131+
name, protoName, name, name, name);
132+
auto crsr = mEditor->insert_position();
133+
mEditor->insert(buf);
134+
mEditor->insert_position(crsr);
135+
}
136+
89137
// MARK: - TFLScriptEditor -
90138

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

94142
// Syntax highlighting stuff...
95143

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

572+
// MARK: - TFLMenuBar -
573+
574+
/**
575+
Handle menu item activation before the menus pop up.
576+
\param event
577+
\return 1 if the event was handled here
578+
*/
579+
int
580+
TFLMenuBar::handle(int event)
581+
{
582+
if (event == FL_PUSH)
583+
{
584+
// update visibility based on the selected proto
585+
gToolkit->UpdateMenuBar();
586+
}
587+
return Fl_Menu_Bar::handle(event);
588+
}
589+
524590
// ============================================================================ //
525591
// NewtonScript
526592
//

Toolkit/TFLScriptPanel.h

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// File: TFLScriptPanel.h
33
// Project: Einstein
44
//
5-
// Copyright 2003-2020 by Paul Guyot and Matthias Melcher.
5+
// Copyright 2003-2022 by Paul Guyot and Matthias Melcher.
66
//
77
// This program is free software; you can redistribute it and/or modify
88
// it under the terms of the GNU General Public License as published by
@@ -28,6 +28,7 @@
2828
#include "app/FLTK/TFLApp.h"
2929

3030
#include <FL/Fl_Group.H>
31+
#include <FL/Fl_Menu_Bar.H>
3132
#include <FL/Fl_Text_Buffer.H>
3233
#include <FL/Fl_Text_Editor.H>
3334

@@ -38,7 +39,7 @@ class TFLScriptBuffer;
3839
class TTkScript;
3940

4041
/**
41-
* This class provides and FLTK UI to edit NewtonScript source code.
42+
* This class provides an FLTK UI to edit NewtonScript source code.
4243
*/
4344
class TFLScriptPanel : public Fl_Group
4445
{
@@ -63,6 +64,8 @@ class TFLScriptPanel : public Fl_Group
6364
void SetDirty();
6465
void ClearDirty();
6566

67+
void AddProtoTemplate(const char* protoName);
68+
6669
private:
6770
TFLScriptEditor* mEditor = nullptr;
6871
TTkScript* mScript = nullptr;
@@ -106,6 +109,18 @@ class TFLScriptEditor : public Fl_Text_Editor
106109
static void style_unfinished_cb(int, void*);
107110
};
108111

112+
class TFLMenuBar : public Fl_Menu_Bar
113+
{
114+
public:
115+
TFLMenuBar(int x, int y, int w, int h, const char* label = nullptr) :
116+
Fl_Menu_Bar(x, y, w, h, label)
117+
{
118+
}
119+
120+
protected:
121+
int handle(int e);
122+
};
123+
109124
#endif
110125
// _T_FL_SCRIPT_PANEL_H
111126

0 commit comments

Comments
 (0)