[{"data":1,"prerenderedAt":364},["ShallowReactive",2],{"project-6932711":3},{"id":4,"name":5,"line":6,"line_source":7,"title":8,"url":9,"domain":10,"maker":11,"posted_at":12,"year":13,"points":14,"comments":15,"rank_in_year":16,"shown_in_year":17,"top":18,"tier":19,"category":20,"subcategory":21,"format":22,"keywords":23,"reception":27,"sentiment":28,"stance_mix":29,"scored_comments":34,"aspects":35,"strip":42,"post_text":43,"what":44,"said":70,"maker_in_thread":136,"shape":149,"grid":154,"attempts":327,"same_week":328,"maker_shows":32,"maker_hidden":356,"reader_version":357,"card":358},"6932711","x6502","An easy-to-understand 6502 emulator in pure C","title","Show HN: I made an easy-to-understand 6502 emulator in pure C","https:\u002F\u002Fgithub.com\u002Fhaldean\u002Fx6502","github.com","haldean",1387424297,2013,88,69,271,1739,16,"notable","dev_tools","cpu emulator","library",[24,21,25,26],"6502 emulator","emulator in c","retro computing","curious",0.155,{"positive":30,"neutral":31,"mixed":32,"critical":33},5,11,1,3,20,{"design":36,"performance":38,"docs":40,"execution":41},{"positive":33,"critical":37},2,{"positive":32,"critical":39},0,{"positive":39,"critical":32},{"positive":32,"critical":39},[30,30,33,39,39,39,39,33,39,33,39,33,39,32,39,39,39,39,39,39,32,39,39,39,33,39,39,33,30,39,30,39,33,32,39,39,30,39,33,33],null,{"problem":45,"audience":43,"pricing":43,"motivation":55,"time_to_build":43,"stack":61,"openness":68,"stage":69,"team_size":69},{"value":46,"source":47,"evidence":48},"Teaching how a 6502 CPU works by emulating it readably","maker",[49,52],{"id":50,"by":11,"text":51},"6935645","Macros can satisfy that in simple cases (like the NEXT_BYTE macro in x6502), and inline functions (like set_flags, get_flag, mem_abs, etc.) can handle more complex cases. Both of…",{"id":53,"by":11,"text":54},"6933389","Thanks so much! That's a great idea; I'll write that up.",{"value":56,"source":47,"evidence":57},"Pedagogical goal: a readable emulator",[58],{"id":59,"by":11,"text":60},"6935562","oriculator is much more powerful and complex than x6502, even you ignore the non-CPU emulation bits (like video and emulated controller, which are complex and difficult). The…",[62],{"value":63,"source":47,"evidence":64},"C",[65,67],{"id":66},"post",{"id":50,"by":11,"text":51},"open_source","unknown",{"praise":71,"objections":95,"requests":107,"questions":116,"alternatives":124},[72,84],{"value":73,"source":74,"evidence":75},"Code is easy to read and well structured","commenter",[76,80],{"id":77,"by":78,"text":79},"6933362","anatoly","Good job! As promised, the code is easy to read. Your major choices all make sense to me: * you went easy on #define's, they obfuscate the code when used heavily * you have a…",{"id":81,"by":82,"text":83},"6932852","jsaxton86","One of the most interesting parts of this code to me was the switch statement in the main loop. Professionally, I have run into programs that have massive switch statements with…",{"value":85,"source":74,"evidence":86},"Switch-based opcode dispatch is a sensible choice",[87,91],{"id":88,"by":89,"text":90},"6932899","userbinator","IMHO there's no much simpler way to write a CPU emulator than as a huge switch inside a loop as that models quite well what a real CPU does. Anything more just obfuscates the…",{"id":92,"by":93,"text":94},"6933028","pcwalton","> Professionally, I have run into programs that have massive switch statements with hundreds of cases in them, which I've always considered a \"code smell\". Most optimizing…",[96],{"value":97,"source":74,"evidence":98},"Large switch statements are a code smell in maintainable code",[99,103],{"id":100,"by":101,"text":102},"6933534","Sharlin","It's still a code smell. It might be a justifiable code smell in some very specific circumstances where the performance actually matters, but a code smell nevertheless.",{"id":104,"by":105,"text":106},"6933103","brianfryer","The README is completely broken in movie devices due to everything being inside the `code` block :(",[108,112],{"value":109,"source":74,"evidence":110},"Add a guide to reading the source order in the README",[111],{"id":77,"by":78,"text":79},{"value":113,"source":74,"evidence":114},"Fix README rendering on GitHub code blocks",[115],{"id":104,"by":105,"text":106},[117],{"value":118,"source":74,"evidence":119},"How to assemble the 6502 examples on OSX",[120],{"id":121,"by":122,"text":123},"6933190","emilyst","Recommended way to assemble the 6502 examples on OSX?",[125,132],{"value":126,"source":74,"evidence":127},"libz80 Z80 emulator",[128],{"id":129,"by":130,"text":131},"6933867","ggambetta","I made something similar for the Z80: https:\u002F\u002Fgithub.com\u002Fggambetta\u002Flibz80 The interesting thing is that I wrote very little of the code by hand; instead I wrote a program that…",{"value":133,"source":47,"evidence":134},"oriculator",[135],{"id":59,"by":11,"text":60},{"comments":137,"answered":138,"key":139},14,4,[140,143,146],{"id":141,"text":142},"6933136","The problem with that method is that it's inefficient; with the switch statement, there's no hashing or significant computation involved in finding the location to jump to. With…",{"id":144,"text":145},"6933410","Yup, that's definitely true, but opcode parsing and dispatch needs to be a really tight loop. Keep in mind that function calls still involve pushing\u002Fpopping stack frames, which…",{"id":147,"text":148},"6935677","Not to nitpick, but doesn't it need to be two instructions? You first do a relative jump by the value you're switching on, which takes you to another jump that jumps you to the…",{"commenters":150,"max_depth":151,"maker_replies":137,"first_comment_mins":152,"lifespan_hours":153},34,10,44,25,[155,157,161,162,166,169,171,173,176,177,180,183,186,189,190,192,194,198,199,202,205,207,209,210,212,214,216,219,221,223,227,230,232,235,238,240,242,246,248,251,253,256,259,262,264,267,269,271,273,274,278,282,283,285,287,289,291,293,295,298,301,303,305,309,313,316,320,323,325],[81,39,30,156,82,39],"project\u002Fpositive\u002Fdesign",[158,39,39,159,160,39],"6932877","commenter\u002Fneutral\u002Fnone","alextingle",[88,39,30,156,89,39],[163,39,33,164,165,39],"6932912","project\u002Fneutral\u002Fdesign","jimmaswell",[167,39,33,164,168,39],"6933003","grapeshot",[141,39,39,170,11,32],"commenter\u002Fneutral\u002Fperformance",[172,39,39,170,165,39],"6933212",[174,39,39,170,175,39],"6933282","breckinloggins",[144,39,39,170,11,32],[178,39,39,170,179,39],"6933593","haberman",[181,39,39,159,182,39],"6933760","weland",[184,39,39,170,185,39],"6933885","csmuk",[187,39,33,188,89,39],"6934007","project\u002Fneutral\u002Fperformance",[147,39,39,170,11,32],[191,39,39,170,179,39],"6936516",[193,39,39,159,11,32],"6939895",[195,39,33,196,197,39],"6934469","maker\u002Fneutral\u002Fdesign","Keyframe",[50,39,39,196,11,32],[200,39,39,201,179,39],"6933578","commenter\u002Fneutral\u002Fdesign",[203,39,33,204,82,39],"6932964","project\u002Fmixed\u002Fdesign",[206,39,39,201,89,39],"6933009",[208,39,39,201,185,39],"6933923",[92,39,33,188,93,39],[100,39,32,211,101,39],"project\u002Fcritical\u002Fdesign",[213,39,39,201,179,39],"6933567",[215,39,39,159,101,39],"6934264",[217,39,39,201,218,39],"6935494","dalke",[220,39,39,201,179,39],"6936450",[222,39,39,164,11,32],"6935497",[224,39,39,225,226,39],"6933628","other\u002Fneutral\u002Fdesign","username42",[228,39,39,159,229,39],"6933773","mbrock",[231,39,39,201,101,39],"6934275",[233,39,39,159,234,39],"6934164","waterlion",[236,39,39,159,237,39],"6935676","dspillett",[239,39,39,156,11,32],"6933077",[104,39,32,241,105,39],"project\u002Fcritical\u002Fdocs",[243,39,39,244,245,39],"6933196","other\u002Fneutral\u002Fdocs","voltagex_",[247,39,39,244,11,32],"6935492",[249,39,39,250,11,32],"6933404","other\u002Fneutral\u002Fnone",[252,39,39,250,89,39],"6933999",[254,39,39,201,255,39],"6933548","EpicEng",[257,39,33,164,258,39],"6933696","bromagosa",[260,39,39,250,261,39],"6933727","fit2rule",[263,39,39,250,218,39],"6934455",[265,39,39,159,266,39],"6934830","diggitydoggity",[268,39,39,159,218,39],"6935196",[270,39,39,159,255,39],"6937326",[272,39,33,164,261,39],"6933715",[59,39,39,164,11,32],[275,39,30,276,277,39],"6933740","project\u002Fpositive\u002Fperformance","drblast",[279,39,39,280,281,39],"6935228","other\u002Fneutral\u002Fperformance","seanwoods",[77,32,30,156,78,39],[53,32,39,284,11,32],"project\u002Fpositive\u002Fdocs",[129,37,39,286,130,39],"other\u002Fneutral\u002Fidea",[288,37,39,250,185,39],"6933942",[290,37,33,164,89,39],"6934016",[292,37,39,225,130,39],"6934107",[294,37,32,211,89,39],"6934137",[296,33,39,286,297,39],"6933436","s-macke",[299,138,39,250,300,39],"6933359","Luc",[302,138,39,250,11,32],"6933412",[304,138,39,250,185,39],"6933961",[306,30,30,307,308,39],"6935381","project\u002Fpositive\u002Fexecution","mambodog",[310,311,39,250,312,39],"6934209",6,"euroclydon",[314,311,39,315,11,32],"6935722","project\u002Fneutral\u002Fidea",[317,318,33,188,319,39],"6934954",7,"slunk",[121,321,33,322,122,39],8,"project\u002Fneutral\u002Fdocs",[324,321,33,322,245,39],"6933217",[326,321,39,322,11,32],"6933388",[],[329,334,339,344,348,352],{"id":330,"name":331,"points":332,"category":333},"6946821","Vector",142,"languages",{"id":335,"name":336,"points":337,"category":338},"6955774","Legimon",103,"games",{"id":340,"name":341,"points":342,"category":343},"6959420","Countdown",67,"consumer_social",{"id":345,"name":346,"points":347,"category":333},"6957642","algorithm implementations",52,{"id":349,"name":350,"points":150,"category":351},"6932122","Gemba","web_saas",{"id":353,"name":354,"points":150,"category":355},"6955038","TipperCoin","finance_crypto",false,"v2",{"id":359,"name":5,"line":6,"ai":356,"cat":20,"year":13,"points":14,"comments":15,"rec":27,"s":360,"top":18,"kw":361,"maker":11,"domain":10,"tier":19,"attempts":39,"strip":362,"url":9,"mix":363,"praise":73,"objection":97,"sub":21},6932711,0.16,[24,21,25,26],"5530000303030100000010003003505031005033",[30,31,32,33],1793990900975]