Is Anyone Willing to Explain This C++ Code?

You can talk about almost anything that you want to on this board.

Moderator: Moderators

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Is Anyone Willing to Explain This C++ Code?

Post by Drew Sebastino » Fri Apr 03, 2015 6:39 am

Okay, I know what you're all thinking: Why don't you learn C++ yourself? Well, If you find a tutorial that isn't a thousand pages long and is not in book form, then I might consider. (I think koitsu might have showed me something on C? If he did, I don't know where it is.) Basically, this is an extension of the Irem M92 thread, but it's main focus is on translating this, which admittedly, doesn't look like any small task: https://github.com/OpenEmu/UME-Core/blo ... ideo/m92.c I would be offering money, but I'm 99% sure my mother won't let me...
Last edited by Drew Sebastino on Fri Apr 03, 2015 7:18 am, edited 2 times in total.

User avatar
Dwedit
Posts: 4275
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Is Anyone Willing to Explain This C Code?

Post by Dwedit » Fri Apr 03, 2015 7:16 am

That's C++ code, not C code. Looks like it's filled with macros, so you could run it through a preprocessor to get the actual code.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Is Anyone Willing to Explain This C Code?

Post by Drew Sebastino » Fri Apr 03, 2015 7:17 am

Oops... :lol: I'll change the title... I've always wondered, is there such a thing as C+?

Edit: What the heck is a preprocessor? And are the macros just like they are in ASM, but instead they use C++, meaning they exist so you don't need to write the same or nearly the same code over and over again?

User avatar
Dwedit
Posts: 4275
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Is Anyone Willing to Explain This C++ Code?

Post by Dwedit » Fri Apr 03, 2015 7:26 am

If you're building with GCC, you can run CPP (c preprocessor) on it and see the result of all Preprocessor directives. This will perform all the #includes and everything, so you might have to cut all that stuff out first before reading it. I think that will also remove the comments as well.

I think you invoke it by "cpp file.c > output.txt" or something like that. You need GCC (mingw or cygwin) installed.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 492
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Is Anyone Willing to Explain This C++ Code?

Post by Jarhmander » Fri Apr 03, 2015 7:34 am

Hmm, the paletteram_xBBBBBGGGGGRRRRR_word_w would score quite high as the longest function name. Hopefully it's used only once.
((λ (x) (x x)) (λ (x) (x x)))

User avatar
Dwedit
Posts: 4275
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: Is Anyone Willing to Explain This C++ Code?

Post by Dwedit » Fri Apr 03, 2015 7:48 am

C++ mangled function names make that look short.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Is Anyone Willing to Explain This C++ Code?

Post by Drew Sebastino » Fri Apr 03, 2015 7:50 am

Well, at least we now it uses the same color setup as the SNES. :wink:

Oh, you know, one thing I don't understand is how there was no real reference used in the making of this. Wouldn't it have been easier to make a sheet with all the hardware info before making this? Do you think that maybe I should email the author of the page to see if he made one as a reference?

Edit: Oh, a random observation: When System 16 said the Irem M107 had twice as many colors, it must have meant colors total instead of color palettes because it has the same number of color palettes as the M92. It would probably have been a lot easier to do that instead of increasing the color palettes, seeing that every color in CGRAM (or whatever it's called here) has an unused bit for every color. I wonder if it's like the Neo Geo in that it has a half brightness bit, or if it has an extra green. I personally like the half brightness better.

Edit: I emailed the author of the page. We'll see what happens...

User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 492
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: Is Anyone Willing to Explain This C++ Code?

Post by Jarhmander » Fri Apr 03, 2015 9:21 am

Dwedit wrote:C++ mangled function names make that look short.
Well yeah, when you look at nested templates, the result is quite surprising!
((λ (x) (x x)) (λ (x) (x x)))

Drag
Posts: 1293
Joined: Mon Sep 27, 2004 2:57 pm
Contact:

Re: Is Anyone Willing to Explain This C++ Code?

Post by Drag » Fri Apr 03, 2015 11:51 am

Jarhmander wrote:
Dwedit wrote:C++ mangled function names make that look short.
Well yeah, when you look at nested templates, the result is quite surprising!
Yep! So thank god we have the mangled names so we don't have to look at those really long names, huh?

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Is Anyone Willing to Explain This C++ Code?

Post by Drew Sebastino » Sat Apr 04, 2015 12:49 pm

Good news! I've contacted the person who made that code, so I'm at least one step closer to figuring this whole thing out. He showed me this: https://github.com/OpenEmu/UME-Core/blo ... vers/m92.c which helps explain things a ton. I've been looking at 80186 related stuff, and I found this which I think is what I'm looking for. It's supposed to be the instruction set for it.
IntelCodeTable.pdf
(146.9 KiB) Downloaded 179 times
If this is correct, it actually doesn't look that bad! It actually seems to share quite a bit of similarities (at least compared to ARM. I actually looked at the 68000 and it left my head spinning.) with the 65816 instruction set. Well, at least I don't have to deal with things like this anyway! (I now know why x86 is considered a mess.)
Wikipedia wrote:Instruction: VFMADDSUBPD xmm0, xmm1, xmm2, xmm3
Opcode: C4E3 WvvvvL01 5D /r /is4
Meaning: Fused Multiply-Alternating Add/Subtract of Packed Double-Precision Floating-Point Values
One thing though, do I need to find a special 80186 assembler, or will any x86 assembler do as long as I don't use any instructions that come after? (By judging instruction earlier, I don't think I'd even want to.)

Joe
Posts: 437
Joined: Mon Apr 01, 2013 11:17 pm

Re: Is Anyone Willing to Explain This C++ Code?

Post by Joe » Sat Apr 04, 2015 1:54 pm

Why are you linking to the OpenEmu copy of MAME instead of... actual MAME? :? (There probably aren't any significant differences between the two, but...)

That instruction set isn't very complete. It's missing a few instructions, like movsb and movsw, and it doesn't cover addressing modes or segmentation at all. If someone made the same chart for 68000, you'd think it looked like 65816 too.

As far as assemblers go, I recommend NASM or YASM. They can easily be configured to generate only valid 80186 opcodes.

lidnariq
Posts: 9138
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Is Anyone Willing to Explain This C++ Code?

Post by lidnariq » Sat Apr 04, 2015 2:02 pm

Espozo wrote:
Wikipedia wrote:Instruction: VFMADDSUBPD xmm0, xmm1, xmm2, xmm3
Opcode: C4E3 WvvvvL01 5D /r /is4
Meaning: Fused Multiply-Alternating Add/Subtract of Packed Double-Precision Floating-Point Values
I told you to ignore things newer than 8086 ;p
MMX and SSE instructions are ... really an entirely different universe than the older ones.
One thing though, do I need to find a special 80186 assembler, or will any x86 assembler do as long as I don't use any instructions that come after?
Almost all assemblers have a directive that will specify the instruction set. (e.g. nasm has "CPU 80186"). One almost-unusable instruction present in the original 8088/8086 that they removed from later cores is POP CS.

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Is Anyone Willing to Explain This C++ Code?

Post by Drew Sebastino » Sat Apr 04, 2015 2:06 pm

Joe wrote:Why are you linking to the OpenEmu copy of MAME instead of... actual MAME? (There probably aren't any significant differences between the two, but...)
The guy who made it pointed me to it. I don't think a document like this is even on actual mame.
Joe wrote:That instruction set isn't very complete. It's missing a few instructions, like movsb and movsw, and it doesn't cover addressing modes or segmentation at all. If someone made the same chart for 68000, you'd think it looked like 65816 too.
Ok. It looked rather small. (One can dream. :roll: ) I guess I should just stick with this? http://en.wikipedia.org/wiki/X86_instruction_listings
Joe wrote:As far as assemblers go, I recommend NASM or YASM. They can easily be configured to generate only valid 80186 opcodes.
I'm going to take a look...

Oh yeah, and lidnariq, the thing is so preposterously large, I almost though someone put it in the webpage as a joke, until I saw other ones just like it... The instruction is so complex, that even when I read the description, I still understand what it does.

lidnariq
Posts: 9138
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Is Anyone Willing to Explain This C++ Code?

Post by lidnariq » Sat Apr 04, 2015 2:11 pm

The wikipedia reference isn't very good for actually programming...
I'd try a few of the other search results for "8086 instruction set", such as
http://www.gabrielececchetti.it/Teachin ... on_set.pdf
http://www.ing.unlp.edu.ar/electrotecni ... on_set.pdf
http://mai.kvk.uni-obuda.hu/documents/t ... erview.pdf

User avatar
Drew Sebastino
Formerly Espozo
Posts: 3503
Joined: Mon Sep 15, 2014 4:35 pm
Location: Richmond, Virginia

Re: Is Anyone Willing to Explain This C++ Code?

Post by Drew Sebastino » Sat Apr 04, 2015 2:22 pm

The one thing though is that I'm looking at the 80816, so there are a bit more instructions, but I could still probably use those. I looked at NASM, but after I opened the rar file, a billion files spewed out, and I couldn't even find the exe/bat file. I then got YASM, and it was only one file. I think you know which one I chose. :wink:

Post Reply