norbert_kehrer Posted April 1, 2015 Share Posted April 1, 2015 Hi, like I did already with Asteroids and Astro Fighter, I made an automatized port of Atari's original arcade game Centipede to JavaScript (with the HTML5 Canvas element). The JavaScript version was created by applying the method of static binary translation to the original binary program code. The program code originally written in the machine language of the 6502 CPU of the Centipede machine was converted in a one-to-one manner to JavaScript. The translation was automized by a Prolog program, which generates semantically equivalent JavaScript code for each 6502 instruction and then applies some optimization techniques (e.g., removal of redundant flag calculations). The outcome is an exact simulation of the original arcade game. Sound is still missing, though. Try it out on my homepage: http://members.aon.at/nkehrer/index.html Norbert 6 Quote Link to comment Share on other sites More sharing options...
Torr Posted April 1, 2015 Share Posted April 1, 2015 Automatized, Automized, Simulation... it all equals emulation in the end now matter what buzzword you use. It may be beyond my programming skills, but is hardly anything new... Also, I don't know how you can say it's "an exact simulation of the original arcade game" followed by "Sound is still missing"... "Similar to original Arcade Game" would be a more honest and accurate statement. Keep at it though. Quote Link to comment Share on other sites More sharing options...
Pixelboy Posted April 2, 2015 Share Posted April 2, 2015 Automatized, Automized, Simulation... it all equals emulation in the end now matter what buzzword you use. It may be beyond my programming skills, but is hardly anything new... It's impressive in the sense that he's got Centipede running in a browser. This kind of thing has been done before, but not that often, especially not with this level of care for detail. 4 Quote Link to comment Share on other sites More sharing options...
+nanochess Posted April 2, 2015 Share Posted April 2, 2015 Pretty nice! I liked specially your Asteroids port because of sound. Besides it doesn't load a hefty framework like JSMESS to make its magic and it runs softly 1 Quote Link to comment Share on other sites More sharing options...
+LS650 Posted April 2, 2015 Share Posted April 2, 2015 Those who can, do. Those who can't, well, criticize... 1 Quote Link to comment Share on other sites More sharing options...
+Random Terrain Posted April 2, 2015 Share Posted April 2, 2015 It would be cool if the mouse worked with it. Also, is the game running faster than normal? Quote Link to comment Share on other sites More sharing options...
Torr Posted April 2, 2015 Share Posted April 2, 2015 (edited) This kind of thing has been done before, but not that often, especially not with this level of care for detail. I don't know, I think about another thread on here where people are talking about homebrewers/home programmers aren't getting appropriate criticization. Again, it's more than "I" could ever do, but I look at it and see: A centipede that doesn't move one pixel at a time, it's moving one segment at a time, it's almost like an LCD game where the last segment of the centipede disappears and the next segment appears as though it's not really scrolling pixel by pixel but sprite by sprite. Maybe I'm using the wrong terminology, but hopefully I'm getting my point across. Anyone who has played the game and this browser version would have to notice that the centipede is moving way too fast for the first wave. It's moving too fast because it's it's not moving ahead one pixel at a time but one centipede segment at a time. Which is odd, because the shots and the spider seem to be moving fairly fluidly. So I can retract my use of the word "emulation" because it appears to be an actual re-programming. However the Centipede itself needs BETTER re-programming. Plus we kinda need sound. Sound doesn't make the game more fun, but sound and an accurately moving centipede WILL make a more honest statement of "EXACT simulation of the original arcade game". Edited April 2, 2015 by Torr Quote Link to comment Share on other sites More sharing options...
goldenegg Posted April 2, 2015 Share Posted April 2, 2015 Automatized, Automized, Simulation... it all equals emulation in the end now matter what buzzword you use. It may be beyond my programming skills, but is hardly anything new... Also, I don't know how you can say it's "an exact simulation of the original arcade game" followed by "Sound is still missing"... "Similar to original Arcade Game" would be a more honest and accurate statement. Keep at it though. Well someone definitely has a stick that requires immediate removal. No, this isn't emulation. It's a port, which the OP specifically stated in his post. It's also a port that has been automatically generated through an process of converting the original program's code to JavaScript. This is not something you come across every day and deserves better than the kick in the face you provided. 4 Quote Link to comment Share on other sites More sharing options...
Kurt_Woloch Posted April 2, 2015 Share Posted April 2, 2015 OK, I think I know what's the problem here... basically, it does seem to run a translation of the original arcade code. However, the screen update only takes place at a fixed framerate which is lower than 60 Hz. The centipede in theory does move more fluidly, but you can't see it doing so. You can see it on the player's shots as well which on the arcade machine would cover every given row, but here they visually jump up multiple rows at a time. The collision detection is still there, but you can't see the shots' movement because of the screen update problem. However, since this is Javascript, you can take a peek at the code... there's a variable set with "frameskip=3", you could try to set that to 0 to make it move more smoothly. I'm running this in Firefox, and it doesn't take up many CPU cycles, so I think it should still run at full speed with a 60 Hz frame rate. 1 Quote Link to comment Share on other sites More sharing options...
roland p Posted April 2, 2015 Share Posted April 2, 2015 (edited) Nice! I just looked at the code. function 'exec' contains all the translated code? I wonder if you could do the translation on-the-fly, like in dynamic recompilation. Edited April 2, 2015 by roland p Quote Link to comment Share on other sites More sharing options...
norbert_kehrer Posted April 2, 2015 Author Share Posted April 2, 2015 OK, I think I know what's the problem here... However, since this is Javascript, you can take a peek at the code... there's a variable set with "frameskip=3", you could try to set that to 0 to make it move more smoothly. I'm running this in Firefox, and it doesn't take up many CPU cycles, so I think it should still run at full speed with a 60 Hz frame rate. Thanks to all of you for the feedback on the program and on the bugs. Kurt, you are absolutely right. I had the frameskip variable set to 3, and now changed it to 1, and it should move more smoothly now and hopefully still be fast enough. Of course, I agree, that the simulation quality is not as good as, e.g., the one of MAME or other programs. This is mainly due to my missing programming skills. It is the method of static binary recompilation that I found really interesting, because one can learn so much about compiler code generation and optimization techniques. So, I wanted to share the result. I am still trying to add a Pokey sound chip emulator for Centipede's sound. Norbert Quote Link to comment Share on other sites More sharing options...
Kurt_Woloch Posted May 30, 2015 Share Posted May 30, 2015 I think I have spotted a small bug... as far as I can see, you're rewriting the high-score table, but something goes wrong with it. In the arcade version, you can enter your initials whenever you make the top 5, however in your Javascript version you only get to enter your name if you make the top spot of the list, displaying the previous top-spot owner instead of pushing him one row down. Also, I think there could be made some optimizations to the code. One thing that occurs to me is the cycle counting. Often the cycles get counted up mutiple times in a string of commands (until a break occurs). This counting could be folded down to one statement. E.g. the following sequence: case 8209:cycles+=2;flagI=0;cycles+=6;mem[256|regS]=32;regS=regS-1&255;mem[256|regS]=21;regS=regS-1&255;regPC=11612;break; could be changed to: case 8209:cycles+=8;flagI=0;mem[256|regS]=32;regS=regS-1&255;mem[256|regS]=21;regS=regS-1&255;regPC=11612;break; Also, but this is more complicated, there are places where the A register's content is irrelevant because it immediately gets overwritten, so some assignments could be short-circuited. For instance, the following sequence: cycles+=4;regA=mem[437];cycles+=2;regA=(regA^255)&255;cycles+=4;mem[437]=regA;cycles+=2;regA=61;cycles+=3;mem[249]=regA;cycles+=2;regA=0;cycles+=3;mem[250]=regA; to the same effect could be shortened to: cycles+=20;mem[437]=(mem[437]^255)&255;mem[249]=61;regA=0;mem[250]=regA; (5 instructions instead of 14) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.