News for hackers. Stuff that matters.
Re:GateBoy – A gate-level simulation of the original Game Bo... by warning26 on Thursday September 02, 2021 @05:40PM (#28397715)
> Is GateBoy a perfect simulation of a Game Boy?

> Actually no, for complicated reasons. The Game Boy chip has a handful of logic gates that operate independently of the master clock and whose exact behavior depends on things like gate delay. These gates create glitches that depend heavily on the physical placement of the gates, the silicon process used to make them, and other weird things like temperature and voltage.

This is fascinating, I previously would have assumed that a gate-level simulation would necessarily be perfect by definition.

Re:GateBoy – A gate-level simulation of the original Game Bo... by aappleby on Thursday September 02, 2021 @05:42PM (#28397734)
And incredibly annoying as the developer - so much work translating and debugging gates, and it's still not "correct" for some definition of correct ;)
Re:GateBoy – A gate-level simulation of the original Game Bo... by BoxOfRain on Friday September 03, 2021 @06:13AM (#28402353)
Reminds me of hearing about how Crash Bandicoot was developed, as well as being something of a masterpiece in itself they successfully debugged an issue that caused the memory card to get corrupted when the controller was touched in a certain way. I can't remember the precise reason but they eventually discovered that running one of the chips at a higher frequency introduced subtle electrical interference with nearby components on the board. This was after much debugging for a supposed software issue in the memory card logic. I often think of that when I have a tricky bug to sort out.
Re:GateBoy – A gate-level simulation of the original Game Bo... by williamdclt on Friday September 03, 2021 @06:37AM (#28402488)
Re:GateBoy – A gate-level simulation of the original Game Bo... by TheJoeMan on Friday September 03, 2021 @07:33AM (#28402807)
“ This is the only time in my entire programming life that I've debugged a problem caused by quantum mechanics “

Who knows, we may be running into this more literally in our lifetime.

Re:GateBoy – A gate-level simulation of the original Game Bo... by BoxOfRain on Friday September 03, 2021 @10:03AM (#28404374)
I suppose all problems of this world are caused by quantum mechanics in a sense.
Re:GateBoy – A gate-level simulation of the original Game Bo... by hbn on Friday September 03, 2021 @09:08AM (#28403655)
If you want a great and long read, Andy Gavin has a pretty extensive series about Crash Bandicoot on his blog, some entries more technical than others. I've never even played the games for more than a few minutes, but I had a great time reading through these

https://all-things-andy-gavin.com/video-games/making-crash/

Re:GateBoy – A gate-level simulation of the original Game Bo... by deelowe on Thursday September 02, 2021 @06:24PM (#28398140)
Don't be too annoyed. There are significant differences across models and even batches within the same generation of system. There is no completely correct definition of a system.
Re:GateBoy – A gate-level simulation of the original Game Bo... by mattcurrie on Friday September 03, 2021 @12:11AM (#28400335)
Some of these differences are CPU observable, so I made this ROM to identify different Game Boy models and revisions: https://github.com/mattcurrie/which.gb
Re:GateBoy – A gate-level simulation of the original Game Bo... by deelowe on Friday September 03, 2021 @10:15AM (#28404509)
Very cool!
Re:GateBoy – A gate-level simulation of the original Game Bo... by grp000 on Friday September 03, 2021 @02:27AM (#28401039)
So is this saying that a possible modern day commercial for a Game Boy might feature: "The artisanal properties of the Nintendo Game Boy make each and every one a unique playing experience!"?
Re:GateBoy – A gate-level simulation of the original Game Bo... by ceronman on Friday September 03, 2021 @04:42AM (#28401799)
I guess it's impossible to ever have it correct. The gates are just another level of abstraction. You could also simulate the silicon atoms and the electrons flowing and use that to have transistors and then gates. And so on.
Re:GateBoy – A gate-level simulation of the original Game Bo... by p4bl0 on Friday September 03, 2021 @06:42AM (#28402516)
This is also the reason why it is so hard to protect against side channel leakage. During my PhD I worked on a solution that would be theoretically perfect (and is formally proved so), but is not in practice because of exactly that.

You can find the paper (Formally Proved Security of Assembly Code Against Power Analysis) and presentation slides on my web page: https://pablo.rauzy.name/research.html#rauzy2014formaldpl

Re:GateBoy – A gate-level simulation of the original Game Bo... by flatiron on Thursday September 02, 2021 @07:00PM (#28398422)
If you simulate cycle accuracy you don’t need to simulate each gate. Think of pins on your cpu and the trillions of gates. If you simulated your cpu you just care what’s at the pins. Not at the gates.
Re:GateBoy – A gate-level simulation of the original Game Bo... by zamadatix on Thursday September 02, 2021 @07:09PM (#28398488)
This assumes the gate level implementation doesn't have any side effects that are related to more than an instantaneous state. Seemingly unlikely as that is a larger class than the group of side effects mentioned in the quote above.
Re:GateBoy – A gate-level simulation of the original Game Bo... by flatiron on Thursday September 02, 2021 @07:38PM (#28398721)
You are right. You buy nothing other than research for gate level. For accuracy you simply need cycle level (which is nothing easy mind you)
Re:GateBoy – A gate-level simulation of the original Game Bo... by deelowe on Thursday September 02, 2021 @06:22PM (#28398117)
I read this as well. I'm definitely referencing this in the future when someone mentions how "FPGAs directly simulate the system hardware."
Re:GateBoy – A gate-level simulation of the original Game Bo... by aappleby on Thursday September 02, 2021 @06:25PM (#28398151)
As I understand it asynchronous logic stopped being a common thing decades ago, so those sorts of glitches aren't possible (or less possible?) now. The hard stuff in simulation now is probably handling multiple clock domains.
Re:GateBoy – A gate-level simulation of the original Game Bo... by photojosh on Thursday September 02, 2021 @07:50PM (#28398817)
Still out there, but only used in special situations. The ARM microcontroller I'm working with has an asynchronous prescaler on the real-time clock crystal input before it gets fed into a second synchronous prescaler which you can then read the output of directly.

This is all about reducing power consumption down in the nA range when the CPU is turned off but the RTC keeps ticking over.

Multiple clock domains definitely tricky though!

Re:GateBoy – A gate-level simulation of the original Game Bo... by jasonjayr on Thursday September 02, 2021 @08:57PM (#28399296)
As a software-only guy .... multiple clock domains sounds like the same class of problem as multi threaded + parallel programming, right?
Re:GateBoy – A gate-level simulation of the original Game Bo... by aappleby on Thursday September 02, 2021 @09:30PM (#28399496)
Sort of? It's almost more equivalent to networking or distributed processing - circuits in different clock domains can't just send a wire to another domain, they have to go through a synchronizer and do some handshaking and other stuff that's vaguely similar to RPCs. I'm stretching here, it's slightly beyond what I've worked with so far.
Re:GateBoy – A gate-level simulation of the original Game Bo... by sizeofchar on Thursday September 02, 2021 @10:02PM (#28399661)
Seems like the same as in multithreaded programming, in which you can’t let threads share memory without synchronizing else you get data races and corruption.
Re:GateBoy – A gate-level simulation of the original Game Bo... by naikrovek on Thursday September 02, 2021 @10:53PM (#28399921)
it's more like two simple computers talking over serial, and the serial connection bitrate can't be faster than the clock of the slowest of the two computers.
Re:GateBoy – A gate-level simulation of the original Game Bo... by photojosh on Saturday September 04, 2021 @07:01AM (#28413969)
Yep! The microcontroller reference manual is full of warnings to ensure clock rates are compatible by being within a certain range of each other.
Re:GateBoy – A gate-level simulation of the original Game Bo... by deelowe on Thursday September 02, 2021 @09:35PM (#28399530)
Sort of. You have to be careful when signals cross clock domains because they can become asynchronous. So anytime you go from one domain to another, you have to be sure to synchronize the data. This is often accomplished via flip flop.
Re:GateBoy – A gate-level simulation of the original Game Bo... by Teknoman117 on Friday September 03, 2021 @11:37AM (#28405599)
This is my absolute favorite paper on the topic:

http://www.sunburst-design.com/papers/CummingsSNUG2008Boston...

Re:GateBoy – A gate-level simulation of the original Game Bo... by deelowe on Thursday September 02, 2021 @07:25PM (#28398632)
I’ve only ever seen behavioral solutions for newer systems. At a certain point, logic level designs become unreasonable.
Re:GateBoy – A gate-level simulation of the original Game Bo... by matheusmoreira on Friday September 03, 2021 @04:50AM (#28401848)
> These gates create glitches

What sort of glitches? Which effects could they produce on outputs?

I wish there was a concrete example.

Re:GateBoy – A gate-level simulation of the original Game Bo... by gambiting on Friday September 03, 2021 @04:59AM (#28401911)
There are examples on the github page, literally right below that sentence - have you stopped reading just before that point??

"For example, there's a glitch in the external address bus logic that causes internal bus addresses like 0xFF20 to appear on the external bus even though the logic should prevent that. Due to gate delays, not all of the inputs to gate LOXO (page 8 in Furrtek's schematics) arrive at the same time. This causes LOXO to produce a glitch pulse that in turn causes latch ALOR to make a copy of one bit of the internal bus address. ALOR then drives that bit onto the external bus (through a few more gates) where it can be seen with an oscilloscope or logic analyzer."

Re:GateBoy – A gate-level simulation of the original Game Bo... by Anunayj on Friday September 03, 2021 @01:37PM (#28407086)
Btw I'm a little confused, So are these "glitches" reliably same across all game boys or can this differ from chip to chip?
Re:GateBoy – A gate-level simulation of the original Game Bo... by randomswede on Monday September 06, 2021 @04:24AM (#28431612)
They can differ from gameboy to gameboy. And from day to day (as some of them are apparently temperature dependent).
Re:GateBoy – A gate-level simulation of the original Game Bo... by rot13xor on Friday September 03, 2021 @05:01AM (#28401927)
Latches or a ring oscillator to generate true randomness. There could also be bugs in the design that cause metastability.