mark.warren
2019-9-19 08:08:54

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


jerome.martin.dev
2019-9-19 08:12:03

@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.


jerome.martin.dev
2019-9-19 08:13:33

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


mark.warren
2019-9-19 08:15:44

@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?


jerome.martin.dev
2019-9-19 08:16:11

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


jerome.martin.dev
2019-9-19 08:16:54

Lemme see if I can find the code…


mark.warren
2019-9-19 08:17:02

Cool



jerome.martin.dev
2019-9-19 08:20:57

jerome.martin.dev
2019-9-19 08:21:27

Which just does (remainder <body> limit)


jerome.martin.dev
2019-9-19 08:22:01

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


jerome.martin.dev
2019-9-19 08:22:21

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


jerome.martin.dev
2019-9-19 08:22:35

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


mark.warren
2019-9-19 08:23:29

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


jerome.martin.dev
2019-9-19 08:28:56

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))))


mark.warren
2019-9-19 08:32:33

Nice


soegaard2
2019-9-19 10:45:03

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.


soegaard2
2019-9-19 10:46:25

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


spdegabrielle
2019-9-19 15:18:23

Thank you @mbutterick :grinning::+1:


btauro
2019-9-19 15:23:52

@btauro has joined the channel


briantauro7
2019-9-19 15:26:27

@briantauro7 has joined the channel


sorawee
2019-9-19 17:17:23

So: StackOverflow uses code-prettifier.

GitHub uses semantics.

What do GitHub Markdown and Slack use?


soegaard2
2019-9-19 17:18:08

soegaard2
2019-9-19 17:18:52

sorawee
2019-9-19 17:19:43

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!)


soegaard2
2019-9-19 17:20:26

Yeah - nice to get that fixed.


samth
2019-9-19 17:21:28

having support in semantics for Racket would be awesome tho


notjack
2019-9-19 18:30:49

I know the author of semantics via another slack, coincidentally


soegaard2
2019-9-19 18:31:55

Project link?


notjack
2019-9-19 18:35:07

krismicinski
2019-9-20 04:49:11

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


krismicinski
2019-9-20 04:49:34

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