Author Topic: CPCBox, your CPC emulator in Javascript  (Read 105956 times)

0 Members and 1 Guest are viewing this topic.

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #50 on: 12:27, 07 October 10 »
First line was not needed, second could have been worded better.
If you had a bad day, don't bring it here.
I felt aggressed by that autoquote from TFM/FS that started it all.
You have to note that at that time, he had already received a clear and proper answer from mahlemiut.

Even the first message from TFM/FS looked suspicious and aggressive to me. Why was he talking about his $4000 laptop not being able to run CPCBox at all ?
Is there any relationship between how much he spent on his computer and CPCBox being broken ?
« Last Edit: 14:02, 07 October 10 by phi2x »
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #51 on: 13:58, 07 October 10 »
I see things did calm down in the end, so if I may, I will say a couple of words to commemorate this and then, if you agree, I'll delete the problematic posts.
Personally, I feel no need to sweep things that happened under the rug. But I will respect your decision.
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #52 on: 15:54, 07 October 10 »
Btw.: @ phi2x:
The emulator indeed runs very slow only.
With ~20 fps on my system.
The biggest problem I see is, that also the complete emulation slows down here.
Can this improved by adding an auto-frameskip?
(JEMU by Executioner and also JavaCPC (which is based on JEMU) use this. You still have full CPC speed also when the frames per second are limited down)

Well, I don't know, why your emulator is so slow, but when this is because gatearray emulation or painting the screen itself, it could be a solution.

Edit: Also a disabled wait for vsync could improve speed.

Well, pretty much all emulation parts are slow with current Javascript engines. But yes, using auto-frameskip would alleviate lots of time-consuming computations.
But I'm not sure I'm wanting to implement such a feature in CPCBox.  Underpowered emulation giving slower emulation results sounds acceptable to me. It would most probably be a source of confusion for users otherwise (ie: why CPCBox output is so choppy on my computer ? and things like that).
 
Indeed, Javascript engines are going faster every day and experts in the field say there are still lots of low hanging fruits that will make Javascript engines go faster. So hopefully, time will sort it out in the longer run.
 
For PC vsync, I have no control at all over it in Javascript. All I do is pushing the canvas every time I finished rendering a frame and the rest is automagically taken care of by the browser.
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline Grim

  • CPC6128
  • ****
  • Posts: 202
  • Country: gp
  • La pak ba, bèf ka pasé
    • THERE IS NO GAME
  • Liked: 133
  • Likes Given: 67
Re: CPCBox, your CPC emulator in Javascript
« Reply #53 on: 15:57, 07 October 10 »
I'm using Opera on a 6yo laptop here, and it works quite nicely for what it is (~17fps).

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1011
  • Likes Given: 926
Re: CPCBox, your CPC emulator in Javascript
« Reply #54 on: 18:31, 07 October 10 »
All I do is pushing the canvas every time I finished rendering a frame and the rest is automagically taken care of by the browser.

So simple:
Add code, which prevents a "update image" until previous image has not been painted.
(I mean: Also don't do a internal vsync/gatearray render update until last paint hasn't finished yet)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #55 on: 19:03, 07 October 10 »
So simple:
Add code, which prevents a "update image" until previous image has not been painted.
(I mean: Also don't do a internal vsync/gatearray render update until last paint hasn't finished yet)

Nope that won't work either. Canvas API provides no access to the actual state of the rendering process.  :o

You can check the specs of interface CanvasRenderingContext2D here: http://dev.w3.org/html5/canvas-api/canvas-2d-api.html#canvasrenderingcontext2d
All you can do is call putImageData() and cross your fingers for everything to be actually rendered before the next call. ;)
« Last Edit: 19:11, 07 October 10 by phi2x »
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 15.183
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 3010
  • Likes Given: 5356
Re: CPCBox, your CPC emulator in Javascript
« Reply #56 on: 09:33, 17 October 10 »
Finally got to try  the last version.

Athlon II 635 @2.9GHz,
Windows 7 Ultimate 64x,
Opera 10.70.34.77

Seems to be working with no issues at 40fps with tons of other windows open. Now waiting for sound implementation... ;)

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #57 on: 21:32, 17 October 10 »
Sure, sound would be a nice addition to CPCBox. The problem is that there is no HTML standard yet for sound synthesis output :(

In fact, W3C is just beginning to think of how it would eventually materialize one day.  :o
But hey, at least they recognize the need developers have for an "Audio Canvas"!

The Audio incubator group at W3C will go on discussions about that stuff until mid-2011.
There is some description about the scope of that brainstorming group here: http://www.w3.org/2005/Incubator/audio/charter
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 15.183
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 3010
  • Likes Given: 5356
Re: CPCBox, your CPC emulator in Javascript
« Reply #58 on: 10:42, 18 October 10 »
But, wait, I thought that there are HTML-based video players that also play audio?

Otherwise, I find it strange that they'd design something as powerful as this without any sound support...?

Offline andycadley

  • Supporter
  • 6128 Plus
  • *
  • Posts: 853
  • Liked: 409
  • Likes Given: 72
Re: CPCBox, your CPC emulator in Javascript
« Reply #59 on: 15:27, 18 October 10 »
But, wait, I thought that there are HTML-based video players that also play audio?
The HTML5 video tag will let you play back videos with audio, but it's a whole different kettle of fish if you want to generate audio programmatically

Offline robcfg

  • Supporter
  • 6128 Plus
  • *
  • Posts: 2.242
  • Country: se
  • 8-Bit Technomancer
    • index.php?action=treasury
  • Liked: 992
  • Likes Given: 2285
Re: CPCBox, your CPC emulator in Javascript
« Reply #60 on: 17:10, 18 October 10 »
It shouldn't be that different.


You have to decode the audio stream of the video file somewhere. And that place is the same where you should have to put your programatically created audio data.


Edit: The "Media" interface from which the "Audio" object inherits seems to have a nice set of functions for controlling the media and its rendering. I don't now if it's a must to write a codec for the media type or you can do it on the fly.
« Last Edit: 17:59, 18 October 10 by robcfg »

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #61 on: 18:59, 18 October 10 »
With the HTML5 audio tag, audio is loaded only from a file or server stream, only few codecs are supported, and the decoding process is taken care of by the browser himself.
With Javascript, you only have limited control access to it (play, pause, volume, fast forward or backward).
Yes, that allows you to make an audio file or radio player in Javascript. But that's pretty much all you can do with it.

To make an analogy in the graphics world, it's the same difference that you have between watching a CPC gameplay video on youtube and playing a game with CPCBox.
« Last Edit: 19:17, 18 October 10 by phi2x »
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline robcfg

  • Supporter
  • 6128 Plus
  • *
  • Posts: 2.242
  • Country: se
  • 8-Bit Technomancer
    • index.php?action=treasury
  • Liked: 992
  • Likes Given: 2285
Re: CPCBox, your CPC emulator in Javascript
« Reply #62 on: 19:24, 18 October 10 »
Do you know if there is some kind of communication between the codec and the HTML5 code running?


If some info could be sent to the codec, it would appear to the browser like a streamed file but under control of the code.


Of course it's only a crazy idea, but It seems too odd for me that you can make palette rotation in an image canvas and not something similar for audio...

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #63 on: 19:42, 18 October 10 »
Nope, there is no way to cheat the audio tag to feed it with Javascript generated sound AFAIK.
If someone know how to do it, please enlighten me. :o

With gaming in mind, the best you can do actually is store small sound files to be played programatically as sound effects in predefined games like the Google Pacman doodle did. No help there for CPCBox.

To be complete about that stuff, there are other options that can be considered, but nothing respectful to standards at all:

1) The most used way to play Javascript generated audio is via a Flash audio output frontend, with communication between Javascript and Flash. Perhaps that trick is possible with other technologies like Silverlight or QuickTime plugin but I don't heard about it.

2) Mozilla is currently writing a proprietary experimental audio canvas API (named Audio Data API) to toy around the idea and feed the W3C. It's there on the latest beta of Firefox 4 and will ship with the final release of Firefox 4.
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1011
  • Likes Given: 926
Re: CPCBox, your CPC emulator in Javascript
« Reply #64 on: 20:11, 18 October 10 »
Another problem I see here is:
The emulator does not run with 100% speed!
So a probably emulated sound would make a crap output.
Sad, the timing does not depend much on painting the image, because if not, phi2x could simply skip 3 frames and have less fps but faster emulation.
(Add manual frameskip could be a solution with radiocheckboxes to choose how many frames should be skipped)

But until the emu does not reach 100% speed it also makes not much sense to emulate sound.
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #65 on: 20:21, 18 October 10 »
But until the emu does not reach 100% speed it also makes not much sense to emulate sound.
And that's not even mentioning the fact that, due to the added computations, AY sound emulation would slowdown CPCBox even more  :(
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1011
  • Likes Given: 926
Re: CPCBox, your CPC emulator in Javascript
« Reply #66 on: 20:34, 18 October 10 »
And that's not even mentioning the fact that, due to the added computations, AY sound emulation would slowdown CPCBox even more  :(

Well, only a 1mhz device more to emulate  :P
(But I think you already emulate it partially to enable keyboard input)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline robcfg

  • Supporter
  • 6128 Plus
  • *
  • Posts: 2.242
  • Country: se
  • 8-Bit Technomancer
    • index.php?action=treasury
  • Liked: 992
  • Likes Given: 2285
Re: CPCBox, your CPC emulator in Javascript
« Reply #67 on: 21:42, 18 October 10 »
I think you can play an audio file within the audio tag with a different speed, that would made it work like a tracker (in  some way).


Could it be possible to use a sample of a square wave and play it looped altering the volume and pitch to match the desired sound?

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #68 on: 22:13, 18 October 10 »
I think you can play an audio file within the audio tag with a different speed, that would made it work like a tracker (in  some way).

Could it be possible to use a sample of a square wave and play it looped altering the volume and pitch to match the desired sound?
Oh gosh! :o I can't believe what I just read ;D
Makes some sense in *theory* but really i don't think it's anywhere realistic a thing to do.

But i'd love if someone would go that way and make a YM player or something with that rendering method you explained.
Don't count on me though.
« Last Edit: 22:15, 18 October 10 by phi2x »
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline robcfg

  • Supporter
  • 6128 Plus
  • *
  • Posts: 2.242
  • Country: se
  • 8-Bit Technomancer
    • index.php?action=treasury
  • Liked: 992
  • Likes Given: 2285
Re: CPCBox, your CPC emulator in Javascript
« Reply #69 on: 23:17, 18 October 10 »
Ok, it's a bit of a  longshot but the theory is sound, hehehe  :P


Maybe I'll be trying it just for curiosity... maybe...

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1011
  • Likes Given: 926
Re: CPCBox, your CPC emulator in Javascript
« Reply #70 on: 23:27, 18 October 10 »
A YM player is simple to code  8)
It only took me 1-2 hours to get some sound of the AY-emulation from JavaCPC (JEMU).
Then another 1-2 days to build the GUI and improve some things...
You only need is:
- AY emulation
- Timers
- PPI emulation + IO
- some crap
- and a few cans of coffee
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #71 on: 01:34, 22 October 10 »
I have rolled out a new update to CPCBox.

Here is the changelog:
- Implemented partial address decoding.
- IRQs were issued 2 rasterlines too early. Fixed.
- Fixed writing to PSG registers.
- Fixed z80 timings in numerous instructions.
« Last Edit: 10:28, 22 October 10 by phi2x »
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #72 on: 19:27, 30 October 10 »
I'm sure that some are worried about Firefox performance with CPCBox.
So, check out this tweet from David Mandelin here:
http://twitter.com/dmandelin/status/26577934037 :)

For those who don't know who that guy is, he's one of the technical gurus @ Mozilla Corp.  8)
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 15.183
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 3010
  • Likes Given: 5356
Re: CPCBox, your CPC emulator in Javascript
« Reply #73 on: 19:32, 30 October 10 »
So I can now play at full speed on my netbook?? ;)

Offline PhilZeVibe

  • 464 Plus
  • *****
  • Posts: 468
  • Country: fr
    • CPCBox - CPC emulator in JavaScript
  • Liked: 162
  • Likes Given: 187
Re: CPCBox, your CPC emulator in Javascript
« Reply #74 on: 19:41, 30 October 10 »
CPCBox on a netbook ... ouch!!! That's ambitious  ;D
Atwood's law (2007): "Any application that can be written in JavaScript, will eventually be written in JavaScript."