
A question for the emulator writers out there. How do you correctly emulate arithmetic errors like overflow in add?

@mark.warren Handling overflows is one of the most mind-wrangling task, when it comes to writing emulators… But if you follow blindly the CPU specs, I guess it goes well.

The hardest thing I had to write was the Decimal Adjust A (DAA) operation

@jerome.martin.dev True, but what I am trying to work out is, if you are using racket to add 2 numbers it will work fine, but if you are emulating an 8 bit cpu, adding 255 and 2 will overflow, do you detect that just by checking if it over 255 or is there some better way?

Oh, for that, I used 8bit+
or 8bit-
custom methods

Lemme see if I can find the code…

Cool


I made a macro called define/rollover
: https://github.com/euhmeuh/virtual-mpu/blob/master/utils.rkt#L73

Which just does (remainder <body> limit)

And then I define 8bit+
as (define/rollover 256 (8bit+ . values) (apply + values))

At that point, I don’t care at all about performance

I don’t have a single clue about whether this is fast or not

@jerome.martin.dev Thanks I’ll have a look at that.

To set the overflow flag, I do that at a completely different place, where I do the naive “hardware implementation” of the check: (overflow! (x y [c 0])
(overflow (xor (> (+ (bitwise-and x #b01111111)
(bitwise-and y #b01111111)
c)
127)
(> (+ x y c) 255))))

Nice

Tip of the day: use "``` lang-lisp" (without the quotes) on stackoverflow to get an syntax-highlighter that doesn’t treat ’ as a string delimiter.

If anyone is looking for a project, add support for Racket to Google Prettify. https://github.com/google/code-prettify

Thank you @mbutterick :grinning::+1:

@btauro has joined the channel

@briantauro7 has joined the channel

So: StackOverflow uses code-prettifier.
GitHub uses semantics.
What do GitHub Markdown and Slack use?



Oh yes, I somehow thought that this and semantics are the same thing. (Of course I do remember it, we did the syntax highlight for Scheme lang together!)

Yeah - nice to get that fixed.

having support in semantics
for Racket would be awesome tho

I know the author of semantics
via another slack, coincidentally

Project link?


Oh yeah, this person robrix who follows me on twitter looks like he contributes a lot to it

looks really interesting, could be very useful for certain applications (e.g., thinking of doing cheat detection for a grade server).