Welcome, Guest. Please login or register.


Author Topic: JavaScript EP Emulator (Read 31491 times)

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
JavaScript EP Emulator
« on: 2014.September.21. 18:09:27 »
Good!, JLB. Works flawlesly with a 31 fps on my Asus laptop.....

Have you put a better keyboard recognition?. but I can't press the colon ":" to change the path. can you add something to assign the keys?

Offline lgb

  • EP addict
  • *
  • Posts: 3563
  • Country: hu
  • æðsta yfirmaður
    • http://lgb.hu/
Re: JavaScript EP Emulator
« Reply #1 on: 2014.September.21. 22:13:13 »
Quote from: gflorez
Have you put a better keyboard recognition?. but I can't press the colon ":" to change the path. can you add something to assign the keys?

Always an issue with a javascript stuff trying to emulate lower level thing :) Mapping is try to be familiar layout as an UK EP's keyboard layout. So keys are A S D F G H J K L ; : (etc) in the corresponding visible EP key row (not the keyboard matrix, but what you can see on an EP keyboard). As I have to use position mapping (and not symbolic, it's quite hard with high level keyboard layer JavaScript can provide with good cross-browser compatibility, and also problems, like shifted on real EP but not shited on PC keybaord and vice versa) starting with the US PC keyboard layout. So in nutshell, in your (US layout) PC keyboard you should press ; to get ; on the EP, and to press ' to get : on the EP. But as it turned out, it's kinda hard to create good keyboard emulation in JavaScript throughout the different browsers/OSes even if you assume a fixed host (PC) keyboard layout and strict positional mapping ...

Btw, you can get more information (not on this issue but in general on my JavaScript based Enterprise-128 emulator) if you click on the "homepage" link at the top of the page, after text "Enterprise-128 JavaScript Emulator".

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: JavaScript EP Emulator
« Reply #2 on: 2014.September.21. 22:53:36 »
Ok no problem, I only have to find the right key, it is there....

Offline lgb

  • EP addict
  • *
  • Posts: 3563
  • Country: hu
  • æðsta yfirmaður
    • http://lgb.hu/
Re: JavaScript EP Emulator
« Reply #3 on: 2014.September.21. 23:07:29 »
Quote from: gflorez
Ok no problem, I only have to find the right key, it is there....

Well, the problem exists, since the current solution is not straightforward, layout-dependent, ugly JS code, etc :) But anyway it can be used _somehow_ at least :-P

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: JavaScript EP Emulator
« Reply #4 on: 2014.September.21. 23:10:06 »
Now your emulator works with the virtual keyboard of Android, even touching the screen acts like the Enter key and  I can pass the ENTERPRISE logo only with the finger!


Edit: is strange, the screen acts as fire, but the space doesn`t....
« Last Edit: 2014.September.21. 23:38:04 by gflorez »

Offline lgb

  • EP addict
  • *
  • Posts: 3563
  • Country: hu
  • æðsta yfirmaður
    • http://lgb.hu/
Re: JavaScript EP Emulator
« Reply #5 on: 2014.September.22. 09:04:16 »
Quote from: gflorez
Now your emulator works with the virtual keyboard of Android, even touching the screen acts like the Enter key and  I can pass the ENTERPRISE logo only with the finger! Edit: is strange, the screen acts as fire, but the space doesn`t....

Actually, my Enterprise-128 JS emulator does not play too well with mobile devices, ie there could be much more specific support, I must admit (the current state of JSep is a really ugly, big mess, I am still planning a full rewrite for clean-up, more mobile devices support, and the ability to easy use for anyone to use it in their own web pages, which is not so possible currently). Besides the keyboard, there was a request from a friend from this EP forum to be able to "press" a single key (it was space or enter, I can't remember now) with a screen touch event on the EP "window" (canvas html element). Well, as far as I remember at least :) I often forget even works I did, ehhhh .... Btw there are two different JSep versions, the base URLs are:

http://ep.lgb.hu/jsep/demo/
http://ep.lgb.hu/jsep/demo.new/

The second one (with "demo.new") should be faster (optimized canvas refresh JS typedarray access, etc, according to guys tested, it's about 10% faster or so) and there can be minor differences. The reason to have two versions that I am still not sure I haven't introduced new bugs with some modifications I did with the ".new" version ... But in general, if you have an URL for my web based emulator, and you see /demo/ in the URL, you can always try to replace that part of the URL with /demo.new/

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: JavaScript EP Emulator
« Reply #6 on: 2014.September.22. 13:33:57 »
But you must be proud of the speed achieved...Now your emulator only lacks some easy configuration.

Offline lgb

  • EP addict
  • *
  • Posts: 3563
  • Country: hu
  • æðsta yfirmaður
    • http://lgb.hu/
Re: JavaScript EP Emulator
« Reply #7 on: 2014.September.22. 16:37:41 »
Quote from: gflorez
But you must be proud of the speed achieved...Now your emulator only lacks some easy configuration.

Well, it's matter of taste. Since it's a web bases stuff, my primary idea was to present some EP software on your own webpage (it's another question that currently it's not so well suited exactly for that purpose), so to be natural to the web techniques, simply the URL holds the configuration so you can include a single URL with any configuration. If you treat JSep as a general emulator comparable eg with ep128emu, then you're right :) But I always thought that a native application (like ep128emu) is a better solution for accurate emulation and general purposes and JSep can be useful for web presentation and not so much for a generic emulation solution. But anyway: if I have time and willpower for the full rewrite, JSep can be downloaded and can be easily integrated by anyone into their web pages, and also, it will provide interface to create a simple web page at a fixed URL with suitable controls for easy configuration if you want to use it as a regular emulator. Currently I have an unfinished project for an "online EP128 assembler" project: it uses codemirror web based editor, and the server side component does the compilation creating an ep128emu compatible snapshot (which can be used with JSep) which is used by JSep then to "run" the program with almost no time spent for "booting" the Enterprise because of the snapshot technique used. I am not sure how useful this project though :)

The speed: it's not my merit, but the unbelievable JavaScript performance of modern web browsers (+ modern JS/web features like typed array and canvas element) especially compared to the situation was some years ago :) An emulator like this was quite unlikely even some years ago with decent speed ...
« Last Edit: 2014.September.22. 17:01:53 by lgb »

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: JavaScript EP Emulator
« Reply #8 on: 2015.October.29. 10:00:13 »
As I still need a portable EP emulator(like everybody...), I've returned to see the advances on this great LGB project.

I'm testing it with an Android tablet running at 2,2Mhz and 4 nucleus and the counter of FPS sometimes reach 90!

Now there is a new download link to put some needed files(mainly the web page file and JS files) inside the device. You can run the emulator locally only clicking to the downloaded HTML file. But still you need to download the Roms and disc image from the JSEP page.

Once downloaded  you can switch off Wifi and have it running for days...

One of the drawbacks JSEP had was its generic keyboard definition, that doesn't coincide with my Bluetooth keyboard, but now you have locally access to keyboard.js, the file where that definitions are made. I want to adapt it as I don't find the ":" symbol.

The file that recalls the remote files is Enterprise.js. I´ve downloaded the needed files from LGB's page, put them on the tablet and changed the URL it calls to my Android partition, but it refuses to charge them. I have to do more test on this.

Not a big problem if I can have the Firefox page waiting there for months, but it could be fantastic to make the emulator completely stand-alone.







Offline lgb

  • EP addict
  • *
  • Posts: 3563
  • Country: hu
  • æðsta yfirmaður
    • http://lgb.hu/
Re: JavaScript EP Emulator
« Reply #9 on: 2015.October.29. 12:41:36 »
Honestly, the major problem with my Javascript based EP128 emulator (JSep) that it is (or "was") a "learning material" for me to learn Javascript better than the basic skills only for homepage decoration purposes :) So the code is really ugly, and I don't have the mood to really modify now because of this issue. I really have to to rewrite it now, in a more sane way, from the view point of programming :) Modern Javascript standards allows funny things on a mobile device, like sensing the movement of the device and acceleration, thus it's even possible to map these events as joystick events for the emulated EP128. I don't know if it's useful at all, but it sounds fun in my opinion :) Generally it's surprising how fast javascript is, especially compared to the old times. Also mobile devices are fast enough now, on my first smart phone it ran JSep with about 1FPS only :) And still browser's javascript engines are getting faster and faster, also the hardware, so maybe soon there is not even need for native applications to gain a usable speed even on "said-to-be-limited" devices like a smart phone is (or "was").

I had the plan to port my native-C emulator (Xep128) to Android, as SDL (what Xep128 uses) is available for Android too. But now I am thinking if it's really needed, with today's hardware and browser JS engine speeds ... It took enough time for me, to try to write Xep128 for two different platforms already (Windows and Linux), though SDL is almost completely free of platform specific problems, there are other areas which can be problematic, especially the upcoming EPNET emulation for networking.

The "loading time" issue is not too much about loading the base HTML and various JS files. Ok, those are too, but I guess, the major download size is about the ROM package and the disk image (if any) for example. If the latter is the issue, it can be solved ie with using webstorage feature of modern browsers, though I should write the support for it. Then, it's possible to use the locally stored version of data files instead of downloading them all the time when you want to use JSep.

If you try to use JSep as "offline" the best way currently to check the html file out at:

http://ep.lgb.hu/jsep/demo.new/

and also downloading all js files the html refers to (btw, there is a /demo/ and /demo.new/ version, you should use the second, it should be faster, and have some extra fixes etc ... I really should replace the /demo/ with the new version just there were some issues if I remember correctly, that I didn't want to make it as the default one).

Yes, keyboard definition is fixed in keyboard.js, but of course feel free to modify. Of course it's not the best and user-friendly way for configuring the emulator, I know :) My basic idea with keyboard layout to use "positional" mapping as much as possible, ie try to lay keys out in a "shape" it would be on a real EP (so no "symbolic" mapping which does this in a way to use the native meaning of keys on the OS which runs the emulator - also symbolic mapping has some interesting challenges, like if you have shifted key on your device for a key event which is not shifted on an EP128, or vice versa). For positional mapping I use the layout of the US keyboard. These two things putting once means, that the key would be right to key 'L' is the ';' and the next key is ':'. I mean, _if_ the keyboard use the US layout.

Of course any suggestion and feedback is warmly welcome about JSep, the real issue here that I don't know when I have time/mood :) to continue its development, especially because - as I've written above - I should rewrite the whole stuff first ...

And a major problem: the sound, which should be done. There is _some_ limited sound (digi and basic Dave channels though without modulation, filter, distortion and other tricks, also there is no noise), but it must be "asked" in the URL, also it's not synchronised at all, causing clicks, repeats and other sound anomalies. It also makes the emulation to somewhat slower. I really need to learn more about webaudio, it was just a "quick" attempt to do something, but it's completely unusable at the moment. But for a test (it's really awful, I warn everybody ...):

http://ep.lgb.hu/jsep/demo.new/?sound=yes

Another interesting problem with audio, that it seems some browsers and/or OSes (like iOS) does not even allow a javascript produces sound without an "interaction" to prevent users have something audible on a webpage. In this case maybe audio can be initiated from an event handler, like first keypress etc, then browser treat audio request as based on user interaction and not "automatically". So there are interesting problems sometimes :)
« Last Edit: 2015.October.29. 13:19:51 by lgb »

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: JavaScript EP Emulator
« Reply #10 on: 2015.October.29. 15:48:33 »
I understand that sound on Enterprie emulators is a complicate thing, but by now it is not an important aspect for me.

On Enterprise.js I have changed "http://ep.lgb.hu/jsep/data/" path with "file:///storage/emulated/0/" and it gave me the error "Access to restricted URI denied" because loading local files it's not permitted on Firefox JS.

Also that is not important with my actual "necessities".

I wanted an "approximation" to a stock Enterprise running stand-alone on my tablet, and yours is near perfect...

I only have to put hands on defining the keyboard.





Offline lgb

  • EP addict
  • *
  • Posts: 3563
  • Country: hu
  • æðsta yfirmaður
    • http://lgb.hu/
Re: JavaScript EP Emulator
« Reply #11 on: 2015.October.29. 16:36:48 »
I'm not sure, but maybe this ugly stuff can help:

http://ep.lgb.hu/jsep/demo/keytest.html

Try to press keys after page is loaded. Maybe you can use the information from here then, to modify keyboard.js for your needs. Or you can find - I guess - better pages than this for this purpose :)

Well, I can't say too much about the URL change to file:// Since data is loaded with AJAX calls maybe it's really a security policy by the browser itself. I mean, AJAX is not the very same as using resources (ie, a file or js script) referring file:// URLs, AJAX is checked more in modern browsers to avoid some kind of attacks, the "same origin" policy, that a javascript can only issue ajax calls to URLs in the same domain as the script originated from. In JSep this is handled that server of lgb.hu emits a special http header that it's OK to be used from other domain too, even if it's not needed, if you use JSep from ep.lgb.hu directly. The problem that file:// URLs does not have too much the same domain or even the "domain" notion, as you can see. As far as I know, google chrome allows (or allowed in the past when I tried this?) this with a special command line (!!) option: --allow-file-access-from-files but I have no idea about firefox (I more often use firefox, but I always use my lgb.hu server).

If you have enough knowledge on Javascript and you _dare_ to dig into my super ugly JS code (used to learn JS, as I've told, shame on me, really ugly!) you may create a solution to build an JS file from the ROMs (I mean simply an "js array" of bytes) and use that instead of the JS AJAX loading stuff madness :) A somewhat better solution as I've told: modify JSep to use localstorage feature of browsers to store information locally, maybe even a way as it would be cache (ie only download from the Net if it cannot be found in localstorage).

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: JavaScript EP Emulator
« Reply #12 on: 2015.October.29. 20:01:49 »
Ì have zero knowledge on JS, but can learn if pressed.....

I will try.

Offline lgb

  • EP addict
  • *
  • Posts: 3563
  • Country: hu
  • æðsta yfirmaður
    • http://lgb.hu/
Re: JavaScript EP Emulator
« Reply #13 on: 2015.October.29. 20:16:56 »
Ì have zero knowledge on JS, but can learn if pressed.....

I will try.

Well, if you have only plans to modify keyboard.js then it'is relative simple to do, even without any JS knowledge. You can find the keyboard mapping in keyboard.js, a typical line is:

Code: [Select]
81: {row: 2, mask: 0x02},
"81" here is the keyboard event in JS, about the same you would get with the keytest.html page I mentioned. For regular ASCII chars, they are often the same as ASCII values for the given character but not always. Note, that shift is like any key! So the difference between Q and q does not exist, as the same key is pressed just with shift or without meanwhile. That is exactly what makes it hard to create a mapping where key is shifted in EP but not on your PC keybaord or vice versa, as I've already mentioned. Also, because eg ';' and ':' is unshifted on EP, you can't create mapping if it's shifted on the PC keyboard (when I say PC here, I mean the OS which runs the browser which runs JSep ... it can be Android, Mac, etc too of course - PC is just a single example). So you have the idea ...

The "2" after row: shows the enterprise keyboard matrix row position for the given key, and "mask" is the mask for column, ie 1 for col 0 (2^0), 2 for col 1 (2^1), 4 for col 2 (2^2), etc till col 7 for 128 (0x80 in hex, 2^7, "^" here is of course the power math function).

It's also worth to read comments in the table, and also look at "function keyPreTrans(evt)" you can see some workarounds there, too.

I'm afraid, it's not free enough for you maybe, because of the restrictions of nature of positional mapping, ie the shift constraint between the two platforms (the emulated - ep128 - and the "host" platforms). But I also don't know what is your exact goal with the modify :) You can try to assign new key code for ':' for example though.

Ooooops, I forgot to note, that JSep - below the status line (where FPS info is shown as well)  - shows the current key event. So you can use that information too, to modify keyboard.js, no need for the keytest.html I suggested.
« Last Edit: 2015.October.30. 00:19:52 by lgb »

Offline gflorez

  • EP addict
  • *
  • Posts: 3615
  • Country: es
    • Támogató Támogató
Re: JavaScript EP Emulator
« Reply #14 on: 2015.October.30. 08:30:47 »
I've assigned the missing keys. It was easy with your well documented code. Overall I needed ":" to access EXDOS and EXOS.

Some keys give 00 code and are not assignable, but I managed to have all EP keys.

But sometimes the keys give strange results and I have to reset the JSEP. Maybe some error on the correction subroutines, not a big problem by now.

If I get better performance I will put here the modifications made.