Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Zemyla
Aug 6, 2008

I'll take her off your hands. Pleasure doing business with you!

Pilsner posted:

Here's the full document on it:

http://www.ioccc.org/2013/cable3/hint.html

gently caress. Just incredible stuff. I wouldn't even know where to begin.

Adrian Cable posted:

Hi, First of all as its author it's great to see so many people playing with the emulator. I've been watching all the comments flying past and thought people might find it useful to hear about what went into the BIOS binary since there seem to be a lot of conjectures.
The BIOS binary is split up into 3 sections. The first section is code, the second and third are data.
The first section is very much like the BIOS code in a real PC. It's written in normal x86 assembly language, initialises the interrupt vector table and various other structures found on a real PC, loads and executes the boot sector from a disk, contains code for handling disk and video reads and writes using the normal PC interrupt interface, and that sort of thing. You can disassemble it using an x86 disassembler of your choice to see what's going on. The code starts right at the beginning of the BIOS file.
The second section contains data also similar to a real PC BIOS, things like a translation table from keyboard scancodes to ASCII, the BIOS data area table, the initial interrupt vector table, and so on.
The third section is the bit referred to in the write-up as containing tables to assist the emulator doing instruction decoding. These tables include things like a look-up table for the parities of 8-bit bytes (used to set the parity flag after arithmetic instructions), a table for decimal-to-BCD conversion, and (I think this is the "controversial" bit, although it really isn't that sneaky) what I call an "instruction translation" table which converts each one of the 256 possible 8-bit opcodes into another translated 8-bit opcode number, the aim of which is to group the multiple possible encodings of each instruction type (there are a total of around 94 of these) into a single "translated instruction number" (there are a total of around 53 of these). This helps keep the size of the emulator source down a little because, for example, the MOV instruction has a number of different encodings, and directing them all to the same piece of code in the emulator for execution saves a lot of duplicated code. This is the "simpler intermediate format" I refer to in the write-up. To generate these tables in C (rather than have them in an external file) would have taken around 200-250 additional characters of source (around 5% of the total size), so it's certainly not the case that "5% of the emulator is in the source" as was said - the other way around is much closer.
That's it, really. Everything else, including all the peripheral hardware, the instruction decoding and execution logic and so on (including the 4 special instructions described), are implemented in the C source, not in the BIOS file. There's no instruction fetching logic or microcode execution or Forth machine or anything of that nature implemented in the BIOS binary.
The IOCCC size rules (very much simplified) limit the C code to 4K and any additional data files to 1MB. At 12KB the BIOS binary is well within these limits, so no cheating there.
Hope this is informative. Enjoy!
-Adrian

I've been disassembling the BIOS to try and figure out where and what these tables are, and I haven't had much luck (though I think I'm getting closer).

Someone on Reddit posted a formatted and partly expanded version of the code. Some of the macro expansions are incomplete, but it actually kind of helps understand what the macros are doing. For instance, u(a, r, T) is kind of like a LEA instruction.

Zemyla fucked around with this message at 03:47 on Jan 10, 2014

Adbot
ADBOT LOVES YOU

Steve French
Sep 8, 2003

nananananana

code:
> function isUndefined(v) { if (v == undefined) { return true; } else { return false; } }
  undefined
> [undefined, undefined, undefined].map(isUndefined)
  [true, true, true]
> Array(3).map(isUndefined)
  [undefined × 3]

Deus Rex
Mar 5, 2005

The reason, by the way, is that the Array constructor when given one numerical argument that's a valid array length does something more or less equivalent to this:

JavaScript code:
Object.create(Array.prototype, { length: { value: 3 } });
Array.prototype.map according to the spec, does this (informal description follows) on an object O given a function f (see http://www.ecma-international.org/ecma-262/5.1/#sec-15.4.4.19):

1. Create a new array P with length O.length, as if it were constructed by Array(O.length).
2. Iterate i from 0 to O.length
3. For each i, check that the property i exists on O[i] using the internal [[HasProperty]] method.
4. If it does exist, assign f(O[i]) to the P[i]

Since the Array(n) constructor above doesn't actually set the properties 0..n on the created object, map never invokes f and never assigns anything to the numerical properties of its returned object (obviously P.length is set by the Array constructor). The array literal syntax like [undefined, undefined, undefined actually does set the properties 0, 1 and 2 to undefined so map behaves differently on that object. Apparently this is by design so sparse arrays retain their sparseness when mapped over.

JavaScript code:
Array.prototype.map.call({ length: 5 }, function (x) { return 1; });
// => [undefined × 5]
Array.prototype.map.call({ length: 5, 0: undefined }, function (x) { return 1; });
// => [1, undefined × 4]
Array.prototype.map.call({ length: 5, 4: undefined }, function (x) { return 1; });
// => [undefined × 4, 1]
Array.prototype.map.call({ length: 5, 2: undefined }, function (x) { return 1; });
// => [undefined × 2, 1, undefined × 2]

Deus Rex fucked around with this message at 08:23 on Jan 10, 2014

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

shrughes posted:

They were probably emulating Perl behavior or other old programming language behavior.

No, Javascript only has two value types: string and number. Generic operators/functions deal with value types, not duck-typed classes, and any objects passed to them are coerced to either string or number with, respectively, .toString() or .valueOf(). It's that simple. That's why NaN pops up so often in Javascript⁠: valueOf called on something that isn't a number

E: there's a wordfilter for "javascript<colon>" :cripes:. "Security"

hackbunny fucked around with this message at 12:15 on Jan 10, 2014

shrughes
Oct 11, 2008

(call/cc call/cc)

hackbunny posted:

No, Javascript only has two value types: string and number. Generic operators/functions deal with value types, not duck-typed classes, and any objects passed to them are coerced to either string or number with, respectively, .toString() or .valueOf(). It's that simple. That's why NaN pops up so often in Javascript⁠: valueOf called on something that isn't a number

You're not saying anything I didn't already know when articulating that belief and you also haven't said anything that counters the claim that they were emulating the behavior of Perl's sort function.

Comrade Gritty
Sep 19, 2011

This Machine Kills Fascists

Steve French posted:

Except that sorting an array of integers lexicographically is not sane. Maybe giving not-meaningful results when sorting a heterogeneous array when an explicit comparator is not given, as python does, is not sane either.

In Python3 instead of a not-meaningful result you get a TypeError.

hackbunny
Jul 22, 2007

I haven't been on SA for years but the person who gave me my previous av as a joke felt guilty for doing so and decided to get me a non-shitty av

shrughes posted:

You're not saying anything I didn't already know when articulating that belief and you also haven't said anything that counters the claim that they were emulating the behavior of Perl's sort function.

It's just that sorting by .toString() by default is the only sane way it could be done in Javascript, given the language design. What else are you going to do, iterate the array to see if the items are all numbers? and how would you determine if they are? just number values? include objects with Number in their prototype chain too? On the other hand, everything save for corner cases like undefined and null (?) implements toString. It's the only sane default

Jewel
May 2, 2009

hackbunny posted:

It's just that sorting by .toString() by default is the only sane way it could be done in Javascript, given the language design. What else are you going to do, iterate the array to see if the items are all numbers? and how would you determine if they are? just number values? include objects with Number in their prototype chain too? On the other hand, everything save for corner cases like undefined and null (?) implements toString. It's the only sane default

Except with the other example, it doesn't just .toString(). With mixed numbers and strings it just fucks up completely.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Jewel posted:

Except with the other example, it doesn't just .toString(). With mixed numbers and strings it just fucks up completely.

code:
>> [2, '10', '2', 10].sort()
["10", 10, 2, "2"]
Seems reasonable to me? Sorted lexicographically, with values that are "equal" according to the sort function maintaining their relative ordering?

BigRedDot
Mar 6, 2008

One place where I do like Python 3 better.
code:
bryan@laptop  ~/Desktop $ ~/anaconda/envs/py3/bin/python
Python 3.3.2 |Anaconda 1.8.0 (x86_64)| (default, Aug  5 2013, 15:07:24) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> [2, '10', '2', 10].sort()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: str() < int()

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

hackbunny posted:

It's just that sorting by .toString() by default is the only sane way it could be done in Javascript, given the language design. What else are you going to do, iterate the array to see if the items are all numbers? and how would you determine if they are? just number values? include objects with Number in their prototype chain too?
And even if you implement this check correctly, now adding a non-number to the array changes the sort order of the existing items in the array.

Steve French
Sep 8, 2003

That's a lot of concern for something that shouldn't really matter, because why are you sorting arrays with items of different types in the first place? It just seems like throwing out the baby with the bath water to me.

And really, you can't think of a better way than always iterating the array to see if the items are all numbers? Well, lets temporarily assume that that is the best way; not the end of the world really since that's an O(n) operation and the sort itself is going to be O(n log n). But that's still sorta lovely, right, since we don't want to be paying that cost all the time when we're just sorting strings, etc. So let's think of something better but still kinda hokey; just start sorting based on the type of the first object in the array, and if you encounter a different type, instead of throwing an error like other languages do, just start sorting over again based on the new information. Now you've got pretty normal sort performance for arrays of numbers and arrays of strings (the ought-to-be-common-case that you ought to care about), and worst case a constant factor penalty of about 2 for heterogeneous arrays.

Or of course the array object could just keep track of what sorts of items are in it as those items are added and removed.

Finally, saying one aspect of the language design is the only sane option given other aspects of the language design is not really a valid defense to criticisms of the language design.

I admit that it seems somewhat problematic that sub-arrays might sort differently than the whole array, but I also think it is problematic that arrays of numbers sort lexicographically. This is a lovely tradeoff imposed by the "feature" that sorting heterogenous arrays works the way it does, which does not seem like a valuable feature to me.

JawnV6
Jul 4, 2004

So hot ...

Steve French posted:

instead of throwing an error like other languages do,

I'm a big fan of the computer making GBS threads itself and calling for a human, but for some reason the web types think you should just keep chuggin'??

mjau
Aug 8, 2008
Or you could do this:

NFX posted:

Numbers sort lower than strings, "10" sorts lower than "2" (it's not a natural sort). Seems sane?

JavaScript code:
function compare (a, b)
{
    if (typeof a == "number") {
        if (typeof b == "number") {
            return a - b;
        }
        return -1;
    }
    if (typeof b == "number")
        return 1;
    a = a.toString();
    b = b.toString();
    return a == b ? 0 : a < b ? -1 : 1;
}
(I don't know javascript at all, so this is probably some kind of horror)

gonadic io
Feb 16, 2011

>>=
code:
>sort [2, 10, "10", "2"]
Couldn't match expected type `Int' with actual type `String'
In the expression: "10"
The only correct response. Anything else leads to "10" + "10" = "20" php land.

Plorkyeran
Mar 22, 2007

To Escape The Shackles Of The Old Forums, We Must Reject The Tribal Negativity He Endorsed

Steve French posted:

Finally, saying one aspect of the language design is the only sane option given other aspects of the language design is not really a valid defense to criticisms of the language design.
It is a perfectly valid defense when you're trying to defend just that one aspect and not the language as a whole. Javascript is a terrible language with terrible semantics, and making it impossible to have a sane default sort for arrays is just one of many consequences of those terrible semantics.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



I was going to say "just use < and >" but then I did this:
JavaScript code:
function sorter(a,b){
  if(a < b) return -1;
  if(a > b) return 1;
  return 0;
}

[10, '9', 8, 'seven', 6, 'all my fives', 4, '3', 2, '!!!11one', 0].sort(sorter)
// [2, 8, "!!!11one", 0, "3", "9", 10, "all my fives", "seven", 4, 6] Opera 12
// ["all my fives", 0, "!!!11one", "seven", 2, "3", 4, 6, 8, "9", 10] Chrome
// [8, "9", 10, "seven", 6, "all my fives", 2, "3", 4, "!!!11one", 0] FF
// [2, "3", 8, "9", 10, "seven", 6, "all my fives", 4, "!!!11one", 0] IE
so :psyduck:

I guess it could be fun to try to reverse engineer their sort functions this way

E: I just want to mention that all browsers report that 'seven' < 4 is false

Munkeymon fucked around with this message at 19:57 on Jan 10, 2014

rjmccall
Sep 7, 2007

no worries friend
Fun Shoe

hackbunny posted:

Definitely not, I have personal experience with this. Turns out the Java stack is untyped, and the same location can hold an object or an integer or a boolean, and optimizing compilers will reuse stack locations, and decompilers don't have the faintest idea how to handle that and will produce horrible broken code that doesn't even compile

Which just goes back to something we've covered before, which is that decompilers are usually written by incompetents, because despite being logically "untyped" in a function-global sense, the JVM operand stack is required to have a consistent depth and typing at any given place in a function, and in fact JVMs are required to verify that for every method in a class before reporting that it's been successfully loaded.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Munkeymon posted:

I was going to say "just use < and >" but then I did this:
JavaScript code:
function sorter(a,b){
  if(a < b) return -1;
  if(a > b) return 1;
  return 0;
}

[10, '9', 8, 'seven', 6, 'all my fives', 4, '3', 2, '!!!11one', 0].sort(sorter)
// [2, 8, "!!!11one", 0, "3", "9", 10, "all my fives", "seven", 4, 6] Opera 12
// ["all my fives", 0, "!!!11one", "seven", 2, "3", 4, 6, 8, "9", 10] Chrome
// [8, "9", 10, "seven", 6, "all my fives", 2, "3", 4, "!!!11one", 0] FF
// [2, "3", 8, "9", 10, "seven", 6, "all my fives", 4, "!!!11one", 0] IE
so :psyduck:

I guess it could be fun to try to reverse engineer their sort functions this way

E: I just want to mention that all browsers report that 'seven' < 4 is false

You should try 'seven' > 4 as well. It doesn't return true. You can't really expect a meaningful output from a sorting algorithm when you're giving it an inconsistent comparison function.

That said, trying to reverse-engineer a sorting algorithm by having it use an inconsistent comparison function and then just feeding it different inputs does seem like an interesting challenge.

Stubb Dogg
Feb 16, 2007

loskat naamalle
Crossposting this from Rocksmith 2014 thread:

quote:

1/9/2014 - Steam (PC/Mac) Patch Notes
- Fixed Age Entry issue when signing up for Uplay – The user can now enter their DOB, even if it falls before January 1st, 1970.

Tad Naff
Jul 8, 2004

I told you you'd be sorry buying an emoticon, but no, you were hung over. Well look at you now. It's not catching on at all!
:backtowork:

Stubb Dogg posted:

Crossposting this from Rocksmith 2014 thread:

Ha, I got that game (and a bass) for my dad who's always wanted to play bass guitar. But I set it up for him. Lucky I was born in September of that year.

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Stubb Dogg posted:

Crossposting this from Rocksmith 2014 thread:

Really, they're just jumping the gun by thirty or so years, because at some point you will be able to represent at least all living humans' birth dates with a unix time

Deus Rex
Mar 5, 2005

Thirty years? Did you know people can and often do live past the age of 74? :confused:

Dessert Rose
May 17, 2004

awoken in control of a lucid deep dream...

Deus Rex posted:

Thirty years? Did you know people can and often do live past the age of 74? :confused:

I'm sorry my random, round number of years "or so" wasn't up to your high standards of accuracy.

NFX
Jun 2, 2008

Fun Shoe

Stubb Dogg posted:

Crossposting this from Rocksmith 2014 thread:

My account name on my computer is Firstname Lastname. When I installed Uplay it created a file in C:\Users\ just called "Firstname". Here's the entire file contents:

C:\Users\Firstname posted:

C:\Program Files (x86)\Ubisoft\Ubisoft Game Launcher\Uplay.exe Lastname\UninstalString2.txt

How does that even happen? Shell piping gone wrong? From an installer!

omeg
Sep 3, 2012

How dare you use spaces in your strings!

piratepilates
Mar 28, 2004

So I will learn to live with it. Because I can live with it. I can live with it.



Stubb Dogg posted:

Crossposting this from Rocksmith 2014 thread:

This is the saddest coding horror I've ever read.

astr0man
Feb 21, 2007

hollyeo deuroga

piratepilates posted:

This is the saddest coding horror I've ever read.

It is funny though, and you can understand why that particular issue might have never come up in QA. I doubt any of their playtesters were over the age of 40 :v:

zergstain
Dec 15, 2005

Dessert Rose posted:

Really, they're just jumping the gun by thirty or so years, because at some point you will be able to represent at least all living humans' birth dates with a unix time

It's supposed to be a signed integer, so unless there's someone alive that was born before 1901 or so, you can with 32 bits.

Tesseraction
Apr 5, 2009

zergstain posted:

It's supposed to be a signed integer, so unless there's someone alive that was born before 1901 or so, you can with 32 bits.

There's quite a few still living, but they're unlikely to be playing RockSmith really. Fun fact: there's still about three living subjects of Queen Victoria.

FlapYoJacks
Feb 12, 2009
I just picked up coding in Javascript and PHP today coming from the land of ASM and C.

Wtf is this poo poo? String + String = newstring? Just make everything a var? No mallocs?


WHY have I not done coding in these languages before? This is amazing!

QuarkJets
Sep 8, 2008

ratbert90 posted:

I just picked up coding in Javascript and PHP today coming from the land of ASM and C.

Wtf is this poo poo? String + String = newstring? Just make everything a var? No mallocs?


WHY have I not done coding in these languages before? This is amazing!

You should try Python next

Look Around You
Jan 19, 2009

ratbert90 posted:

I just picked up coding in Javascript and PHP today coming from the land of ASM and C.

Wtf is this poo poo? String + String = newstring? Just make everything a var? No mallocs?


WHY have I not done coding in these languages before? This is amazing!

Yeah try like Python or Ruby or something. Javascript isn't great (it's got a lot of weird corners), but PHP is absolute garbage and you do not want to start loving it because it makes stuff easy, because it makes doing stuff correctly a lot harder.

e: Python would be pretty good for you to look into in all honesty, it's more C-like than Ruby is (in terms of control flow and general program structure; it's a lot less DSL-y), and it's got a poo poo load of libraries. And also its community is not a bunch of programming hipsters.

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

ratbert90 posted:

I just picked up coding in Javascript and PHP today coming from the land of ASM and C.

Wtf is this poo poo? String + String = newstring? Just make everything a var? No mallocs?


WHY have I not done coding in these languages before? This is amazing!

String concatenation is a feature of a lot of languages, including C++ (well...) and Java. You haven't come across it because you've been writing very low level code in C and ASM, and have effectively been living in the 70s.

Like, almost any modern language has string concatenation and garbage collection. "Just use a var" is weak typing, and has it's own problems if you're not careful.

Bognar
Aug 4, 2011

I am the queen of France
Hot Rope Guy

Polio Vax Scene
Apr 5, 2009



Ha ha, enjoy your sharepoint sucker.

Zaphod42
Sep 13, 2012

If there's anything more important than my ego around, I want it caught and shot now.

ratbert90 posted:

I just picked up coding in Javascript and PHP today coming from the land of ASM and C.

Wtf is this poo poo? String + String = newstring? Just make everything a var? No mallocs?


WHY have I not done coding in these languages before? This is amazing!

You are the horror.

Try out the sex that is Python or Perl (or even Java/C# for that matter if you've been living in ASM and C) and get the gently caress away from Javascript.

Its like the worst language there is after esoteric poo poo like brainfuck or malbolge.

Zaphod42 fucked around with this message at 17:01 on Jan 14, 2014

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug

Zaphod42 posted:

You are the horror.

Try out the sex that is Python or Perl (or even Java/C# for that matter if you've been living in ASM and C) and get the gently caress away from Javascript.

Yeah, don't learn the language that is absolutely loving key for any job that involves web development. That entire web thing is just a fad anyway.

Seriously though, I go to a dev conference every year. Two years ago, there were a handful of JS talks. Last year, there were significantly more. This year, it seemed like all anyone was talking about was JS and various JS frameworks, testing JS, SOLID design for JS, etc.

On an unrelated note, two years ago there were tons of JVM-focused talks (Clojure, Groovy, Scala, etc). Almost none this year. The number of .NET talks diminished somewhat, although less drastically.

I'm not debating that JavaScript is tough to do well and encourages you to shoot yourself in the foot on a regular basis, but it's definitely a key language to be familiar with.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
I'm more productive in JavaScript than any other language.

Most of my new projects are all in JavaScript.

Adbot
ADBOT LOVES YOU

Jewel
May 2, 2009

Suspicious Dish posted:

I'm more productive in JavaScript than any other language.

Most of my new projects are all in JavaScript.

You like JavaScript because you can prototype graphical stuff instantly in the browser with no compilation. Ratbert likes JavaScript because they can indiscriminately make everything "var" and add strings together and basically just have freedom (perhaps too much, probably leading to messier code than normal). There's different motives here, and while you're in the right for liking JavaScript for your preferred hobby, I don't think Ratbert is. Python definitely seems like the better option for them.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply