Home Page
Posted By: Ensjo Suggestion: "special" copying and pasting - 11/09/10 01:56 AM
Hello, all.

Before contributing to the MESS MC-1000 emulation, I worked with another MC-1000 emulation implemented as a Java applet. To it I added some clipboard operations that have been proving very useful: 1) Copying/pasting a (plain text) BASIC program from/to the RAM (where it is tokenized). 2) Copying/pasting blocks of bytes from/to the RAM (or VRAM). 3) Copying/pasting the content of the text screen.

The ability to "inject" program and data directly from the clipboard, without resort to "tape" files, is very helpful while you are developing a new program.

What do you think?
Posted By: Kale Re: Suggestion: "special" copying and pasting - 11/09/10 02:15 AM
Isn't that already supported?
You can already paste as if you were typing it in. However it only works properly on some computers. Others produce gibberish.
Tafoid filed a bugzilla entry for the copy/paste problem with some systems (I think it depends on the delay some machines expect between sequential inputs)

concerning the original post, I think that he talks about something different. However:
1. copying and pasting RAM content requires some sort of snapshot format to be created, and however I think you can already use the debugger for that
2. BASIC tokens manipulation can be added to imgtool (I think coco supports this already if you need an example)
3. copying the screen content is something that I have no idea how could be implemented across the various different systems: one should probably intercept all the accesses to the RAM/VRAM and select the specific ones (it also reminds me too much the old hack used for c64 floppies, so that thinking to it already gives me nightmares... wink )
Posted By: Ensjo Re: Suggestion: "special" copying and pasting - 11/09/10 06:35 PM
Originally Posted By robbbert
You can already paste as if you were typing it in. However it only works properly on some computers. Others produce gibberish.

I know the pasting functionality that MESS has. It wasn't working well for MC-1000, then I recoded the keyboard input code and fixed it. Now it works almost properly, but the frequency of the pseudo-keystrokes is a bit too fast for pasting a long BASIC program, or one that has long lines, for instance. The time needed to process the input after every ENTER (tokenize the line and add it to the end of the program in RAM) causes the loss of the next keystroke (the first digit of the line number of the next line). I don't know if the frequency of these pseudo-keystrokes is adjustable in MESS.

Anyway, a long program still takes a lot of seconds to be inserted by this "pseudo-typed" pasting. The "injection" of data is immediate, and much more convenient. You can prepare a program in a text editor and paste it to the emulator every now and then for quick tests.

Originally Posted By etabeta78
concerning the original post, I think that he talks about something different.

Yes. smile

Originally Posted By etabeta78
However:
1. copying and pasting RAM content requires some sort of snapshot format to be created,

For BASIC programs, the format would be the program in text form. (Some escaping method could be considered to represent non-ASCII characters that many machines have.)

For generic RAM data, the format would be the same as in the Debugger's Memory Window: each line starts with an address, followed by a series of bytes to be inserted from that point on. (All hexadecimal, of course.) Example:
Code:
3000 00 00 00 00 00 00 00 00 10 10 10 10 10 00 10 00
3010 28 28 28 00 00 00 00 00 28 28 7c 28 7c 28 28 00
3020 10 3c 50 38 14 78 10 00 60 64 08 10 20 4c 0c 00
3030 20 50 50 20 54 48 34 00

Some tagging convention could identify specific pieces/banks of RAM:
Code:
[bank 1]
0000 00 00 00 00 00 00 00 00 10 10 10 10 10 00 10 00

[bank 2]
0000 00 40 40 48 43 20 30 33 34 4f 3b 20 20 20 20 20

Originally Posted By etabeta78
and however I think you can already use the debugger for that

Eh? I looked and found no copying or pasting feature in the debugger. Only direct typing.

Originally Posted By etabeta78
2. BASIC tokens manipulation can be added to imgtool (I think coco supports this already if you need an example)

Ugh, that stills involves creating a file (disk image?) in your system and loading it into the computer. And the machine emulated must have its disk capabilities implemented in MESS, which not all do.

Originally Posted By etabeta78
3. copying the screen content is something that I have no idea how could be implemented across the various different systems: one should probably intercept all the accesses to the RAM/VRAM and select the specific ones (it also reminds me too much the old hack used for c64 floppies, so that thinking to it already gives me nightmares... wink )

As it is the case with (de)tokenizing BASIC programs to/from the clipboard, that feature would need to be programmed independenty for each machine, with direct access to the (V)RAM.

Different machines have different BASIC dialects, with different tokens, stored in different formats at different points of memory. Internal pointers must be properly so that the machine knows the size of the program area.

As for the text screen, different machines have different screen sizes, different character sets, and so on... Some don't even have a "text" screen at all. In ZX Spectrum, for instance, characters shapes are stamped on a graphical screen, and the machine doesn't differentiate them from any line or dot plotted. It would be needed to compare every 8-byte-high screen square with the shapes in ROM to recognize the "text" content of the screen. For other machines, as those based on MC6847 like MC-1000 and the CoCo, it would be very trivial.
Posted By: Ensjo Re: Suggestion: "special" copying and pasting - 11/13/10 02:54 PM
It seems that my suggestion didn't rise much interest, at least here in the forums. frown

1. Is there a (more) proper channel to submit suggestions of change to the MESS core?

2. Is there any resource offered by the current core by which I could have read/write access the clipboard or a UI text box?
I would suggest you instead fix the existing paste functionality to support a longer delay at the end of each line first.

Direct RAM save/load is best done in MESS as a "snapshot" - look at other drivers implementing snapshots for guidance.

Scraping RAM or VRAM is a terribly ugly kludge and I would push for rejection of patches implementing it on any system in MESS.
Posted By: Kale Re: Suggestion: "special" copying and pasting - 11/13/10 05:03 PM
Or adding a "common" keyboard sub-routine for MCU-based keyboards on which we don't have a dump for.
Quote:
It seems that my suggestion didn't rise much interest, at least here in the forums.


I am interested, especially for exotic computers with rare or nonexistent software.
The only way is then to type for your self a language listing to run.
Posted By: Ensjo Re: Suggestion: "special" copying and pasting - 11/13/10 08:04 PM
Originally Posted By R. Belmont
I would suggest you instead fix the existing paste functionality to support a longer delay at the end of each line first.

I'm willing to do so, but... is it configurable on a per-driver base? How? (I'm still a newbie at programming for MESS, so more guidance is very welcome.) frown

Originally Posted By R. Belmont
Scraping RAM or VRAM is a terribly ugly kludge and I would push for rejection of patches implementing it on any system in MESS.

Forgive me, but why is that so? It's not obvious to me. As I said in the opening post, this feature is implemented in another MC-1000 emulator and it have been very, very useful. Editing a BASIC program in a text editor is much more comfortable that doing so in the machine, real or emulated, where I'm restricted to slow typing, one-line editing with slow cursor movement, no cut-and-paste, and so on.

(Don't take me bad. I am fond of the original machine, and programming in it is fun when you are in the mood to do so. But sometimes I just want to use a few minutes between my other occupations to try or improve a program for the machine to post on the wiki I set up for it, and doing that the usual way is just too time-comsuming.)

Even with a fully functional pasting feature, it is still "painful" to wait for long seconds (even minutes!) of beep-beep-beep-beep to get a full program in memory. And you don't have it the other way back: You can't (promptly) retrieve a program that you have typed in the machine after you edited it there.

Originally Posted By R. Belmont
Direct RAM save/load is best done in MESS as a "snapshot" - look at other drivers implementing snapshots for guidance.

Beyond the fact that a snapshot involves a file, it is originated in the machine. I get the status of the machine and save it so I can resume to that state later. People don't create snapshots outside of the machine. And (I suppose) it's generated in binary format, reflecting the RAM content, so the BASIC program is stored there in tokenized format, not text-only. Still, I can't (easily) use snapshots to insert an all-new program into the machine, and to retreive the source code of a BASIC program originally typed in the machine.

Given that, what is it that makes direct (V)RAM copying/pasting such an un-welcome feature?
Posted By: Haze Re: Suggestion: "special" copying and pasting - 11/13/10 08:16 PM
Quote:

Given that, what is it that makes direct (V)RAM copying/pasting such an un-welcome feature?


because it's an ugly hack...

it belongs as part of something like the cheat system at best..
Posted By: Ensjo Re: Suggestion: "special" copying and pasting - 11/13/10 08:19 PM
Originally Posted By Anna Wu
Quote:
It seems that my suggestion didn't rise much interest, at least here in the forums.


I am interested, especially for exotic computers with rare or nonexistent software.
The only way is then to type for your self a language listing to run.


Yes, that feature has helped me a lot to adapt BASIC programs made for other computers. In a text editor I can easily change all the CLS into HOME, for example, and make quick running tests as the adaption work goes on.
Posted By: Haze Re: Suggestion: "special" copying and pasting - 11/13/10 08:30 PM
Originally Posted By Haze
Quote:

Given that, what is it that makes direct (V)RAM copying/pasting such an un-welcome feature?


because it's an ugly hack...

it belongs as part of something like the cheat system at best..


(which btw isn't as far-fetched as it seems, the cheat system afaik is scriptable, and can access ram / rom etc. Give it access to the host clipboard, improve the scripting capabilities, and you might even be able to have copy / paste 'cheats' without having to pollute the driver at all)

Posted By: Ensjo Re: Suggestion: "special" copying and pasting - 11/13/10 09:40 PM
Originally Posted By Haze
Originally Posted By Ensjo

Given that, what is it that makes direct (V)RAM copying/pasting such an un-welcome feature?

because it's an ugly hack...

This just re-stated what I was asking clarification for. frown

Originally Posted By Haze
it belongs as part of something like the cheat system at best..

Hm... Am I correct to think that the main objection relates to the possibility to inject ad hoc RAM chunks?

What if the copy/paste feature were restricted only to BASIC programs and VRAM text content? Would this render the suggestion acceptable?
The main objection relates to the fact that MESS emulates the behavior of the real hardware, and the real hardware does not behave in this manner. (Indeed, it's likely not possible on the real hardware to do it even with added hardware).

Also, any such hacks will be by nature very fragile and will break each time we update the emulation core in the future.
Posted By: Ensjo Re: Suggestion: "special" copying and pasting - 11/14/10 03:32 AM
Originally Posted By R. Belmont
The main objection relates to the fact that MESS emulates the behavior of the real hardware, and the real hardware does not behave in this manner. (Indeed, it's likely not possible on the real hardware to do it even with added hardware).

I understand that, and being a cultist of one specific vintage machine I agree that the machines should be emulated as accurately as possible.

Anyway, MESS already offers a bunch of capabilities ulterior to the original behavior of most of the emulated machines: state (snapshot) saving and loading; generation of .WAV file for cassette output (instead of just the sound); pausing; usage of keyboard as joystick; the very ability to paste text into the emulator as fast typing; selecting or disabling color artifacting effect; changing of RAM bytes (via the debugger); and so on.

What I am proposing (at least the part of it that relates to BASIC programs) is nothing so alien to the machines' behavior. It's just a more (much more!) convenient way to inserting and retrieving a program into/from the machine.

I have analyzed the cassette output of MC-1000 and created tools for the PC to generate a .WAV file from a text file containing an BASIC program and vice-versa. But the process of saving the text file, switching to the Command Prompt, run the converter, switching to MESS, type "LOAD" <enter>, mount the .WAV file,
play it and wait for the program to load... although much faster than typing it directly into the machine, is still very time consuming for my busy days. frown

Originally Posted By R. Belmont
Also, any such hacks will be by nature very fragile and will break each time we update the emulation core in the future.

How so? As I imagine it, for pasting, the MESS core would interact with the operating system and get the contents of the clipboard, and only pass a string to the driver; the driver (who owns the know-how) then tokenizes the program and puts it in the right place of RAM. For copying, the driver would produce a string with the source code of the program and pass it to the MESS core, that would simply pass it to the operating system's clipboard.

Since the core is just a "pipe" in the copy/paste process (as envisaged above), and this "pipe" function is independent of the rest of the emulation, I don't see how a change in other core functions would affect this feature.
I'm sorry, but no. This transcends all of the listed capabilities in that it is a gross disgusting kludge that requires intimate knowledge of the operating system on the emulated computer. It's simply ugly, and as I said it will be fragile by nature and will shatter each time the core changes.

Use the fast-forward key (insert on Windows, page down on Linux/Mac) to make tapes load much quicker.
Posted By: Haze Re: Suggestion: "special" copying and pasting - 11/14/10 01:47 PM
and as I've said, given some improvements to the cheat / debug engine I'm pretty sure half of this could be implemented in external scripts. I believe this to be the better long-term solution, and will allow the drivers to remain clean and the actual MESS core to concentrate on the actual emulation of the system.

For copy, parameters could be read out of ram, acted upon, data could be read out ram, processed, and placed on the clipboard.

The reverse could be done for paste.

If scripted, rather than hacked into the drivers, I imagine it will be a lot less fragile too.

The feature could work if implemented *properly*, but being hacked into drivers / core is not a proper solution. Direct RAM access is still ugly, but, it's a feature which exists for cheats etc. and if it's external to the actual driver source code it's far less ugly. Nobody is saying it isn't a useful feature, but the existing methods to support it are gross.
Right. I'm fine with doing it in external scripts, I just don't want to see one line of driver code facilitating it.

Maybe if someone can get ShimaPong to submit his purportedly massively improved cheat system?
Posted By: Haze Re: Suggestion: "special" copying and pasting - 11/14/10 01:55 PM
Originally Posted By R. Belmont
Right. I'm fine with doing it in external scripts, I just don't want to see one line of driver code facilitating it.

Maybe if someone can get ShimaPong to submit his purportedly massively improved cheat system?


ShimaPong won't ever submit it, he just has the typical 'my dick is bigger than yours' emulation attitude which seems common with Japanese devs and PCB owners. In this case he's trying to show how useless Pugsy is, by being equally useless himself.

You're about as likely to see Xacro give the Neo Protos to MAME ;-)
Posted By: Ensjo Re: Suggestion: "special" copying and pasting - 11/15/10 01:50 AM
OK then, suggestion as originally stated withdrawn. smile

I hope that clipboard-enabled, scriptable debug engine appears in a non very distant future.
© Forums