The MASM Forum

Projects => ObjAsm => Topic started by: Biterider on March 04, 2025, 08:38:50 PM

Title: New Editor
Post by: Biterider on March 04, 2025, 08:38:50 PM
Hello
A long time ago I started coding an editor that I wanted to extend with an internal automation engine for addins. My intention was to use LUA.
Other things got in the way and I only got back to it a few weeks ago.
It was much more complicated than I expected. In particular, synchronising all the editor features is a real challenge. Hats off to those who have managed it. For some features I used RadAsm and Notepad++ as a reference.

Current features are:
Caret management
Scrolling
Insertion and deletion
Drag and Drop
Load/Save/SaveAs file
Syntax Highlithing
Configuration (ini-file) and precoded defaults
Multiple synchronized Views of a single file
Zoom in and out
Line numbering
Copy/Paste/Replace
Undo/Redo
Window management

Not yet implemented:
Interlisense
LUA

Project management
Addins management
etc.


Regards, Biterider


Title: Re: New Editor
Post by: daydreamer on March 04, 2025, 09:24:48 PM
Good luck Biterider  :thumbsup:
Editors I use has "undo/redo" menu text
Numbers of undo/redo only limited by memory or like image program setting of max memory to use for undo/redo? Or max number of undo/redo limited to 32, 64?
Title: Re: New Editor
Post by: Biterider on March 05, 2025, 08:00:13 AM
Hi
I have a question for those who have played with UTF-8 as input for ML/UASM.
Is there anything to be aware of?
For this project, I'm coding the editor code buffer using WIDE chars (Unicode/UTF-16). Now, when I save the content, I want to save it as UTF-8 and pass it to the assembler.
Does this work or are there any pitfalls?

Regards, Biterider
Title: Re: New Editor
Post by: jj2007 on March 05, 2025, 08:08:30 AM
Quote from: Biterider on March 05, 2025, 08:00:13 AMI have a question for those who have played with UTF-8 as input for ML/UASM

Masm, UAsm & friends don't care what you use, as long as it doesn't have nullbytes in it, like Utf-16 does. So just send Utf-8 without a BOM. No pitfalls. The assembler simply doesn't know about that "encoding" stuff ;-)

Example:
Quoteinclude \masm32\MasmBasic\MasmBasic.inc
  Init
  PrintLine "Введите текст здесь"   ; "Enter text here" in Russian
  PrintLine "Нажмите на эту кнопку"   ; "Click on this button" in Russian
EndOfCode

Now this is RTF, but have a look at the attached plain text source.
Title: Re: New Editor
Post by: zedd on March 05, 2025, 08:17:53 AM
Quote from: jj2007 on March 05, 2025, 08:08:30 AMUtf-8 without a BOM
That is key. UTF8 without a BOM looks like, tastes like and smells like a plain,  ordinary ANSI ascii text file. You can see this in a hex editor.

On Win 10, Notepad saves as UTF8 (no BOM) by default, and examining the file in a hex editor it looks exactly as if were saved as ANSI ascii. And I spent a lot of time selecting "ANSI" to save with Notepad, until I found this out. Hope this helps...

Saving as UTF8 with BOM in notepad, it appends hex bytes "EF", "BB", BF" to the file. It still opens though with qeditor and when saving, qeditor does not retain the 3 hex bytes.

Now after saving an .asm file as utf8 WITH BOM in notepad, "error A2044: invalid character in file" upon assembling (or trying to) it with ml.exe
For utf8 without BOM, it assembles fine with ml.exe.
Title: Re: New Editor
Post by: jj2007 on March 05, 2025, 09:00:56 AM
Quote from: zedd151 on March 05, 2025, 08:17:53 AMOn Win 10, Notepad saves as UTF8 (no BOM) by default

Indeed, the source above looks right in a Win10 Notepad, but not (yet) in RichMasm and other editors.

Notepad opens both attached files correctly. One is Utf8, the other uses my local codepage. There is no fool-proof way to find out the encoding, so apparently Notepad uses some heuristic method...
Title: Re: New Editor
Post by: Biterider on March 07, 2025, 05:59:59 AM
Hi
Deciding which file format is best is a case-by-case decision. 
UTF-8/16, ANSI are valid options for a good editor. I'll add some entries to the ini file to automatically select the best choice based on the file extension.

One cool feature suggested by HSE is to offset the line numbering on a given line to track macro error messages. It can also be used for other tasks, such as simple item counting.

For testing purposes, I implemented this by right-clicking on the selection bar at the vertical position of the zero line number. A second click resets to normal operation (see attached image).

Regards, Biterider
Title: Re: New Editor
Post by: Biterider on March 10, 2025, 07:44:15 AM
Hi
Here we go!
In the first post I attached the first binary (alpha release).
Source code can be downloaded from Github.

For those who want to experiment, open the zip file and extract the 2 files into the same folder.
At the moment the files are opened and saved in UTF-8 format. The 2 windows on the left have no functionality yet.

Any feedback is very welcome.

Regards, Biterider
Title: Re: New Editor
Post by: jj2007 on March 11, 2025, 06:46:47 AM
Quote from: Biterider on March 10, 2025, 07:44:15 AMSource code can be downloaded from Github

Link?

The editor runs but I don't see the window. Quick test:
include \masm32\MasmBasic\MasmBasic.inc
  SetGlobals hWin, rc:RECT
  Init
  .if WinByTitle("Assembler Development Environment")
mov hWin, eax
invoke GetWindowRect, hWin, addr rc
deb 4, "The window", rc.left, rc.top, rc.right, rc.bottom
invoke MoveWindow, hWin, 27, 27, 1200, 666, 0
invoke ShowWindow, hWin, SW_MINIMIZE
invoke ShowWindow, hWin, SW_RESTORE
  .endif
EndOfCode
The window
rc.left        32767
rc.top          32767
rc.right        34067
rc.bottom      33507

Is there somewhere a shr in the source that should have been sar?

Attached an exe to make it visible. Looks good :thumbsup:
Title: Re: New Editor
Post by: Biterider on March 11, 2025, 07:38:14 AM
Hi JJ
Thank you for giving it a try  :thumbsup:
The sources are here https://github.com/ObjAsm/ObjAsm-C.2/tree/master/Projects/X/AsmDevEnv (https://github.com/ObjAsm/ObjAsm-C.2/tree/master/Projects/X/AsmDevEnv), but keep in mind that this is an alpha release. There is still a long way to go.

The effect you see is because I fixed the window size to my screen resolution while testing the application. I simply forgot to reset it back to the normal operation.

Regards, Biterider

Title: Re: New Editor
Post by: Biterider on April 09, 2025, 06:37:24 AM
Hi
I'm making some progress with the ASM-IDE and the code editor. I managed to add some functionality but the project is still in alpha state.
If anyone wants to take a look and test it, I have updated the binary in the first post. The source code is also updated on GitHub.
Feedback is welcome.

Added feature list:

Regards, Biterider
Title: Re: New Editor
Post by: guga on April 09, 2025, 07:01:59 AM
I really liked the interface style.
Title: Re: New Editor
Post by: jj2007 on April 09, 2025, 07:18:54 AM
Quote from: Biterider on April 09, 2025, 06:37:24 AMSEH protection

What's that?

Hmmmm....: Error: Unknown file format for ADE.asm
Title: Re: New Editor
Post by: Biterider on April 09, 2025, 07:22:41 AM
Hi
I forgot to add the 2 ini files. Without them, you only see the defaults.
All files are now in the first post. Sorry.

Biterider
Title: Re: New Editor
Post by: Biterider on April 09, 2025, 07:27:42 AM
Hi JJ
As for the SEH protection, I only added a Structured Exception Handling frame to a few critical code paths to prevent total loss in case of a crash. 
Still not everywhere - alpha code  :rolleyes:

Biterider
Title: Re: New Editor
Post by: TimoVJL on April 09, 2025, 03:53:12 PM
Can't run it in Windows 7 x64
Title: Re: New Editor
Post by: Biterider on April 09, 2025, 04:36:12 PM
Hi Timo
What is the problem you are seeing running it on Win7? 

Biterider
Title: Re: New Editor
Post by: jj2007 on April 09, 2025, 05:03:28 PM
Quote from: Biterider on April 09, 2025, 07:27:42 AMAs for the SEH protection, I only added a Structured Exception Handling frame to a few critical code paths to prevent total loss in case of a crash.

So what happens if user has coded some kBytes and suddenly the electricity goes off? Or he gets a BSOD, etc? When simulating a crash by killing ADE.exe from Task Manager, the edits are apparently lost.

With RichMasm what happens is that on next launch user will be asked "You may have had a crash. Use last saved version?"

Actually, it's not the last saved version. It is what was on the screen before it crashed. RichMasm does nothing if you type like a madman, but if you stop typing for more than 5 seconds, it saves a mylastsource.tmp file.  When you save and exit, the tmp file gets deleted.

Now when you restart RichMasm, and it finds mylastsource.tmp in the folder of that source, it recognises that there was a crash and offers to restore the latest version.

I rarely see crashes, but in some cases (forced logoff...) this little feature saved me ;-)
Title: Re: New Editor
Post by: TimoVJL on April 09, 2025, 05:58:51 PM
Quote from: Biterider on April 09, 2025, 04:36:12 PMHi Timo
What is the problem you are seeing running it on Win7?

Biterider
AMD CPU
(https://i.postimg.cc/XGMxr6yB/Clipboard-04-09-2025-01.png) (https://postimg.cc/XGMxr6yB)

(https://i.postimg.cc/YLM3xNRp/Clipboard-04-09-2025-02.png) (https://postimg.cc/YLM3xNRp)
Title: Re: New Editor
Post by: Biterider on April 09, 2025, 06:55:10 PM
Hi Timo
These screenshots helped a lot. The problem seems to be that the CPU or this particular version of Win7 does not support AVX instructions. Win7 starting with SP1 does support them, but I think the problem is the old CPU.

I can step down with the supported instruction set and only use e.g. SSE/SSE2.

Biterider
Title: Re: New Editor
Post by: Biterider on April 09, 2025, 09:03:25 PM
Hi Timo
Here is the same version as in the first post, but without AVX or SSE support, which is not a big deal for this application. I hope it works for you now.

Biterider
Title: Re: New Editor
Post by: TimoVJL on April 09, 2025, 09:16:00 PM
Thanks, now it works.

Toolbar tooltips could be useful.
Title: Re: New Editor
Post by: Biterider on April 09, 2025, 10:04:54 PM
Hi JJ
Quote from: jj2007 on April 09, 2025, 05:03:28 PMbut if you stop typing for more than 5 seconds, it saves a mylastsource.tmp file.
This is certainly an interesting and good feature that can be added without much effort.

There are 2 messages for closing a session: WM_QUERYENDSESSION (https://learn.microsoft.com/en-us/windows/win32/shutdown/wm-queryendsession)/WM_ENDSESSION (https://learn.microsoft.com/en-us/windows/win32/shutdown/wm-endsession)
I have used the former in the past to trigger such data storage tasks.
Note: The editor does not do this yet

Biterider
Title: Re: New Editor
Post by: Biterider on April 09, 2025, 10:08:28 PM
Hi Timo
Quote from: TimoVJL on April 09, 2025, 09:16:00 PMToolbar tooltips could be useful.
The code is there, but I do not have all the translations for the supported languages. I decided to leave that until I have all the code in place and know all the messages I need to display.

Biterider
Title: Re: New Editor
Post by: Biterider on April 11, 2025, 06:43:34 AM
Hi
I have implemented a few more features:


Update on the first post.

I think it is time to implement the Undo/Redo feature. ATM I have no good idea how to implement it. Has anyone done this before?

Regards, Biterider

Title: Re: New Editor
Post by: jj2007 on April 11, 2025, 06:07:57 PM
Quote from: Biterider on April 11, 2025, 06:43:34 AMI think it is time to implement the Undo/Redo feature

What do you mean? The RichEdit control does it automagically...
Title: Re: New Editor
Post by: Biterider on April 11, 2025, 07:06:50 PM
Hi JJ
Im not using the RichEdit control. The editor is coded in pure asm!

Biterider
Title: Re: New Editor
Post by: jj2007 on April 11, 2025, 08:09:46 PM
You are courageous :thup:
Title: Re: New Editor
Post by: TimoVJL on April 11, 2025, 08:50:55 PM
ADE open sqlite3.c in blink of eyes  :thumbsup:
sqlite3.c size was just 9 MB  :biggrin:
So great wiewer for big files  :thumbsup:
Title: Re: New Editor
Post by: ognil on April 11, 2025, 10:35:51 PM
QuoteI think it is time to implement the Undo/Redo feature.  ATM I have no good idea how to implement it. Has anyone done this before?...

I did it in a very special "my" way, but you will have to wait until I finish and publish my Template64 project for more details.

Quote"What do you mean? The RichEdit control does it automagically..."

You know very well that it is almost impossible to implement Do/Undo together with syntax highlighting. That is why your editor does not have syntax highlighting. :smiley:
Title: Re: New Editor
Post by: zedd on April 12, 2025, 12:00:35 AM
Quote from: TimoVJL on April 11, 2025, 08:50:55 PMADE open sqlite3.c in blink of eyes  :thumbsup:
sqlite3.c size was just 9 MB  :biggrin:
So great wiewer for big files  :thumbsup:
Some stats for you Biterider... by merging many many multiples of windows.inc from masm32 SDK.

I have made a huge file... not that I would expect any assembly source codes to be that large but who knows?  :tongue:

21521600 lines of text
781929600 bytes filesize

On my computer running an i7,
1. Using ADE, around 7 seconds for file to be displayed. Scrollable in full (even to the bottom), immediately after the file is displayed.  :thumbsup:  Big Huge improvement over programs that do use RichEdit.

2. Using qeditor, around 13 seconds to display the file, but still loading in the background. Not scrollable until fully loaded. Even then, scrolling to the bottom is nigh impossible.  :thdn:

3. Using Notepad, the program still loading after 30 seconds. Had to close via Task Manager.  :thdn:  :thdn:  :thdn:  I didn't explore Notepad any further.  :biggrin:

Side note:
Some time ago, I had experimented with using a couple of smaller buffers (1000 lines I think) which rotated and streamed the text into a RichEdit control from either of the two small buffers.  That was even much faster than streaming into the RichEdit control in one pass. I forget a lot of the details, but do remember it was tricky to implement and get it right, as well as work transparently to the user. I may still have that code somewhere buried in my archives.

Later: I remember now, I was playing around with making a hex editor back then... custom coded ascii hex byte selection, and corresponding ascii selection (if ascii text file was open) at the same time iirc, big phun.

I looked for it btw, everything that I had before 2019 is lost. I forgot about that, too. Long story about a 64 GB micro SD card... that I used for backups, old files etc. I never found the tiny thing.
Title: Re: New Editor
Post by: zedd on April 12, 2025, 04:37:01 AM
I finally had a chance to actually look at your IDE in operation.

Looks nice, but I found a minor issue.

WHen selecting a series of spaces in the whitespace, there appear to be some sort of beige highlighting the same size as the selection but elsewhere in the editor. It doesn't appear to have any effects other than looking odd.

Example the selection I made is in green:
(https://i.postimg.cc/h4rVcr3z/untitled4.png)

There are a couple more images in the attachment.
Title: Re: New Editor
Post by: Biterider on April 12, 2025, 04:44:53 AM
Hi Zedd
These are the things I'm interested in. The caret logic is a tricky one and needs a lot of attention.
Besides the screenshots, I'll need the file that's causing the problem. Is that OK?

Biterider
Title: Re: New Editor
Post by: zedd on April 12, 2025, 04:49:46 AM
Quote from: Biterider on April 12, 2025, 04:44:53 AMI'll need the file that's causing the problem. Is that OK?

3 different files in the zip, corresponding to the images zipped and attached already above.

Attachment removed as it has served its intended purpose.

Title: Re: New Editor
Post by: Biterider on April 12, 2025, 03:47:02 PM
Thanks Zedd  :thumbsup:
I found the problem. It was a logic error in the selection check in the highlighting implementation.
This feature highlights text in the view when a word is selected, for example when you double-click on a word. This allows you to immediately see other occurrences in a procedure. This is very useful when examining or refactoring code.
The fixed version is in the first post.

Regards, Biterider

Title: Re: New Editor
Post by: zedd on April 12, 2025, 06:46:24 PM
You're welcome.
Title: Re: New Editor
Post by: Biterider on April 12, 2025, 06:51:58 PM
Hi
After reading what other coders have done to implement undo/redo for editors, I came up with some ideas on how it could be done.
The interesting thing is that it can be done by tracking changes on each editor separately, or globally.
This means that in the latter case, if you make changes to different files (editors) and you can undo them seamlessly. The downside is that in this case you can't just undo the changes in a particular editor and leave the rest untouched.

For now, I think I'll go with the global approach.

Biterider
Title: Re: New Editor
Post by: ognil on April 12, 2025, 11:58:01 PM
Admin EDIT:
In 'approving' this rather 'Cryptic' informationless post, I thought it perhaps useful to include further information.
The provided 'link', points to an article called "Piece Chains", being a seemingly good and informative article on Editors by a chap called James Brown; https://www.catch22.net/about/ (https://www.catch22.net/about/)
A LESS Cryptic and perhaps more helpully descriptive 'link' than that posted by the member:
https://www.catch22.net/tuts/neatpad/piece-chains/ (https://www.catch22.net/tuts/neatpad/piece-chains/)


->? (https://www.catch22.net/tuts/neatpad/piece-chains/)   Original 'link' ??? I mean honestly,.. ???  :rolleyes:
NB: As Many people here are often (and very possibly rightly-so), cautious about merely opening, Non Described 'links'. May I suggest if your'e intention is to provide useful and helpful information, it surely can't hurt to spend just a small amount of time and effort to provide some information regarding What the 'link' is about etc.
Title: Re: New Editor - String table translation
Post by: Biterider on April 13, 2025, 11:22:06 PM
Hi
As my string tables are growing fast, I decided to try ChatGPT to do the job for me. Basically, I provide the English string table in the resources section, from which all displayed texts in the application come.
The idea: all other languages supported by the application should be translated by an LLM.

As a short example, I want to translate this into German, where some lines should only be partially translated:
  IDLANG_ENGLISH + 00, "&File|File commands"
  IDLANG_ENGLISH + 01, "&New|Create a new file"
  IDLANG_ENGLISH + 02, "&Open...~Ctrl+O|Open a file"
  IDLANG_ENGLISH + 03, "&Save~Ctrl+S|Save to file"
...
  IDLANG_ENGLISH + 40, "&Language|Language selection"
  IDLANG_ENGLISH + 41, "&English|English language"
  IDLANG_ENGLISH + 42, "&Deutsch|German language"
  IDLANG_ENGLISH + 43, "&Italiano|Italian language"
...

Using this ChatGPT prompt:
Translate the following lines to german following these rules:
For lines containing a number between 41 and 45 (inclusive), keep the text between the first quotation mark and the "|" character unchanged, and only translate the text after the "|" character to German.
Replace every occurrence of IDLANG_ENGLISH with IDLANG_GERMAN.
Ensure the final result is grammatically correct.

the result can be directly be pasted into the .rc file  :thumbsup:

  IDLANG_GERMAN + 00, "&Datei|Dateibefehle"
  IDLANG_GERMAN + 01, "&Neu|Neue Datei erstellen"
  IDLANG_GERMAN + 02, "&Öffnen...~Strg+O|Datei öffnen"
  IDLANG_GERMAN + 03, "&Speichern~Strg+S|In Datei speichern"
...
  IDLANG_GERMAN  + 40, "&Sprache|Sprachauswahl"
  IDLANG_GERMAN  + 41, "&English|Englische Sprache"
  IDLANG_GERMAN  + 42, "&Deutsch|Deutsche Sprache"
  IDLANG_GERMAN  + 43, "&Italiano|Italienische Sprache"
...

I have done this for German, Italian, Russian and Spanish and it works like a charm.  :bgrin:

Regards, Biterider
Title: Re: New Editor
Post by: Biterider on April 16, 2025, 02:37:00 AM
Hi
I now have a concept and strategy for implementing the Undo/Redo feature. :cool:

Initially, I was on the wrong track, thinking that Undo/Redo should be a global feature across all open editor instances.
However, if you look at modern and advanced editors, they implement this feature per editor instance—meaning each editor tracks its own changes. 
This approach is much simpler!

That said, what seems simple now can become quite complex when it comes to caret manipulation. 
One possible solution might be to disable caret handling after an Undo/Redo operation and require the user to manually re-position it.

Biterider

Title: Re: New Editor
Post by: zedd on April 16, 2025, 04:10:31 AM
Quote from: Biterider on April 16, 2025, 02:37:00 AMInitially, I was on the wrong track, thinking that Undo/Redo should be a global feature across all open editor instances.

However, if you look at modern and advanced editors, they implement this feature per editor instance—meaning each editor tracks its own changes.
:thumbsup:  Yes. Trying to track changes across several instances globally would be a monumental feat, and undoubtedly lead to hard to track bugs.

Still, even doing it per editor instance is a very ambitious plan, to do it without the benefit of any aids like RichEdits built-in Undo/Redo capacity. I applaud your determination.
Title: Re: New Editor
Post by: Biterider on April 19, 2025, 06:02:03 AM
Hi
Finally, I was able to implement the undo/redo feature, which was not as complicated as I expected, but not trivial either.
It boils down to having some basic insert and delete routines for characters and lines in a way that they complement each other. For example, you can undo the insert routine with the delete routine and vice versa.
Once that is in place, it is a matter of keeping track of the changes and sending them to the right routines to undo or redo an action.

A key element is the grouping and aggregation of actions. For example, deleting several lines at once needs to be perceived as a single action, not as deleting one line at a time. The solution is to group all these deletions together and process them together.

Aggregation is slightly different because it groups together single actions, such as keystrokes when typing a word. The whole sequence of keystrokes must also be perceived as a single action.

After implementing all this, I uploaded the new binary in the first post. I also added indentation/outdentation and comment/uncomment to the toolbars, and disabled SEH for the time being to make it easier to find the bugs.

Regards, Biterider

Title: Re: New Editor
Post by: Biterider on April 19, 2025, 06:12:47 PM
Hi
Having done "most" of the core work, there is still the project management code to do.
In this respect, I would like to know what the general preferences are. 


Regards, Biterider



Title: Re: New Editor
Post by: TimoVJL on April 20, 2025, 02:33:20 AM
As i am a Pelles C user, so i like to see project files in tree view.
Project files should be in form, where every object files are in their own folders.
So 32 / 64 bits and release and debug having own result folders
Title: Re: New Editor
Post by: Biterider on April 20, 2025, 03:06:55 AM
Hi
Thanks Timo. :thumbsup:
Lets see what other people here think.

There is one thing I haven't mentioned. That is code folding.
For those who use it, I have seen it done for other modern languages by simply using indentation.
Compared to using folding rules, this can be a big advantage for asm. With indentation, the coder can manage what he wants to see and what he does not want to see.
Similar to the way rules work, you have a trigger line at a lower indentation with a + or - square to show or hide the more indented lines.
I like this way because it gives a lot of flexibility.

Regards, Biterider