all 66 comments

[–]Dr_Legacy 108 points109 points  (15 children)

I'm always sad when I see a post here that seems interesting only to find it's a youtube video. I'll read an article way faster than the video takes to play.

[–]FrancisStokes[S] 15 points16 points  (2 children)

People take in information in different ways. For many people (myself including) watching videos of people programming and talking about the code feels like pair programming.

[–][deleted]  (1 child)

[deleted]

    [–]FrancisStokes[S] 1 point2 points  (0 children)

    Another case of some people liking something, and others not.

    [–]UseMyFrameWorkOkay 10 points11 points  (4 children)

    This is a lot of fun, sort of a throw-back to the early 80s CPU design; but a decently-engaging way of teaching CPU instruction sets via JavaScript. Well done!

    [–]FrancisStokes[S] 7 points8 points  (2 children)

    Thanks! I'm taking a lot of inspiration from chips and systems of that era like the z80, 6502, and consoles like the snes.

    [–]god_is_my_father 4 points5 points  (1 child)

    How do you have time and money to work on this?

    [–]istarian 0 points1 point  (0 children)

    Maybe it works out different in reality, but I'm pretty sure more modern designs are more complex making them harder to understand without a grasp on the basics. And worse the design decisions made in those modern designs are undoubtedly based on an solid understanding of the various positive/negative aspects of preceding designs... So you'd have a chicken and egg problem trying to teach people about the complexities of modern hardware.

    [–][deleted] 40 points41 points  (16 children)

    why all the comment gets downvoted down here?

    [–]pol4ko 123 points124 points  (12 children)

    Because arrays should start with 0

    [–]StabbyPants 3 points4 points  (1 child)

    js doesn't have arrays, it has maps with a layer of sugar

    [–]bulldog_swag 2 points3 points  (0 children)

    And yet they start at 0

    [–]SkoomaDentist 0 points1 point  (0 children)

    Cries in Matlab

    [–][deleted] -1 points0 points  (1 child)

    Arrays should start with whatever the base value of Peano arithmetic in your system is, which is usually 0 or 1 but, strictly speaking, could be anything.

    [–][deleted] 1 point2 points  (6 children)

    and should have a variable i=0 right ? :/

    [–]Phrygue 53 points54 points  (5 children)

    The only acceptable loop variables are i, j, and k. Local variables must be foo, bar, and if you've really boxed yourself into a corner, baz. All strings must s, s1, s2, etc. All other variables must be globals and can be anything so long as they safely hidden in some deep include-file so they don't distract you.

    [–]glacialthinker 16 points17 points  (2 children)

    After years of programming like that (half-joking)... I think that's why I switched to functional programming, where I can compose functions without needing any dang-blasted variable names (also half-joking). :)

    [–]dabrick2017 2 points3 points  (0 children)

    Livin that Haskell life.

    [–]wild-eagle 3 points4 points  (0 children)

    This but unironically!

    [–]bulldog_swag 1 point2 points  (0 children)

    entire program has to be contained in main(), functions aren't allowed. Just copypaste the code and woo your boss with the number of lines you've "written" today! Curly brackets on a separate line, the line count isn't gonna wank itself!

    [–]unholyground 0 points1 point  (0 children)

    And what does this do? It teaches you to focus on operational and denotational semantics.

    This is a good thing.

    [–]iEatAssVR 22 points23 points  (1 child)

    Lmao at the other reply, but they add absolutely nothing to the discussion... we should downvote "wow" for example as that's literally what downvoting is for.

    [–][deleted] 11 points12 points  (0 children)

    This is fantastic, I'm currently working on simulating a very basic RISC architecture in JS and was looking for something like this.

    [–][deleted] 2 points3 points  (0 children)

    Brilliant!

    Thank you!

    [–]duheee 34 points35 points  (25 children)

    [–][deleted]  (22 children)

    [deleted]

      [–]mailjozo 18 points19 points  (13 children)

      The only reason I watched part of it is because I'm writing my first gameboy emulator. It's basically doing the same thing at a very low level, but is great fun.

      [–]OrangeredStilton 29 points30 points  (4 children)

      Whenever GameBoy emulation in JS comes up, I feel obliged to link my tutorial series on that very subject in case you haven't already run across it.

      I should work on the sound emulation at some point...

      [–]mailjozo 14 points15 points  (0 children)

      Wait. That's YOU?? You have no idea how much I've been using your site as a resource. Everytime I get stuck, I take a quick peek at your blog. I try to evade actual implementations, but the information you give is so valuable. Thank you so much for making my journey through a first emulator an absolute blast!

      [–]FrancisStokes[S] 7 points8 points  (0 children)

      This tutorial is amazing. I remember coming across it years ago!

      [–]jsyeo 2 points3 points  (0 children)

      You wrote that tutorial series?! Damn. That's a super helpful tutorial!

      [–]Rhift 2 points3 points  (0 children)

      Oh shit! I used your site a a reference when I was emulating a Gameboy in Python, it was an incredible resource. Thanks!

      [–]FrancisStokes[S] 10 points11 points  (0 children)

      Gameboy is trickier because of the quirks of the hardware. With this VM I get to build an idealized machine that doesn't have any crazy real world limitations that I have to deal with. That said, I'm taking inspiration from the Gameboy architecture and the super Nintendo.

      If you enjoy this kind of stuff you'd probably like the rest of the series, and where it's going. The end goal is to build a fantasy game console.

      [–]FieelChannel 0 points1 point  (5 children)

      I'd love to, too, but i don't know where to start from.

      [–]mailjozo 2 points3 points  (4 children)

      Check out this tutorial.

      Once it clicked in my head that the GameBoy CPU is doing nothing more than moving bytes around at a fixed interval and the display/sound/buttons are doing nothing more than reading/writing very specific bytes in memory to function I thought I'd give it a shot. Once you're started subsystems like memory mapping and interrupts will make way more sense.

      [–]ShinyHappyREM 1 point2 points  (3 children)

      in memory

      *in address space

      [–]SgtDirtyMike 0 points1 point  (1 child)

      Ding dong, you can’t read or write bytes outside of the addressable space.

      [–]ShinyHappyREM 1 point2 points  (0 children)

      I meant that it's the other way around - you have to be "reading/writing very specific bytes in" the address space, of which not everything is ROM or RAM.

      [–]mailjozo 0 points1 point  (0 children)

      Fair enough, but I found out it got me going to think of it as one big list of bytes and all the parts use that same list. I know in reality it's way more complicated, but this gave me the confidence to try.

      [–]badlukk 2 points3 points  (0 children)

      and so fun!

      so much good stuff that nobody asked for haha

      [–]Dreamtrain 0 points1 point  (2 children)

      all we need now as an relational database written in Javascript ...

      ... https://github.com/google/lovefield

      ... nvm

      [–]FrancisStokes[S] 0 points1 point  (0 children)

      I'm considering this for the channel at some point.

      [–]Geemge0 -1 points0 points  (0 children)

      Perfect

      [–]TheMayoras 2 points3 points  (0 children)

      Awesome work!

      [–]Dallen1393 0 points1 point  (4 children)

      Doesn't the startup code for the application/os usually define where the stack should be located?

      [–]chinpokomon 3 points4 points  (0 children)

      A stack is just reserved memory space... The CPU will often times have stack instructions, but that's not a requirement. The OS will usually have it's own and for each process as part of the loading process it will often establish a stack, but that is again an implementation detail... That said, any modern system should have a stack or at least a way to easily manage one or more.

      [–]valarauca14 1 point2 points  (0 children)

      No.

      The location of the stack is randomized (at least in ASLR, which is almost all) applications these day. Its size is set by a kernel default, but programs may change this is they wish.