4 ms·
Is there an ELI5 for this? How could something so small possibly be an 8080 emulator?
by nsxwolf 3y ago
Is there an ELI5 for this? How could something so small possibly be an 8080 emulator?
- bombcar 3y agoThe 8080 is a simple processor, the "how to program" manual is only 60 pages. Most of the instructions are changing registers in various ways, which is pretty simple. The Appendix A has all of them: https://altairclone.com/downloads/manuals/8080%20Programmers%20Manual.pdf https://altairclone.com/downloads/manuals/8080%20Programmers...
- tromp 3y agoI am more amazed you can fit a (pretty large subset of) Haskell compiler/runtime in about twice the size [1]. [1] https://www.ioccc.org/2019/lynn/hint.html https://www.ioccc.org/2019/lynn/hint.html
- anthk 3y agoWell, an a complete lisp system on that size, for sure. And forth environment.
- ngcc_hk 3y agoExample? I meant under 8080. Seems to have sector size using x86?
- anthk 3y agoThe former meant under x86, and that's easy even for IOCCC.With awk you can write an RPN calculator in 10 lines or such...
- anthk 3y agoI found a Forth for x86 under the IOCCC contest of 1992: the Buzzward.2 entry. https://www.ioccc.org/1992/1992.tar.bz2 https://www.ioccc.org/1992/1992.tar.bz2 You need to edit the CFLAGS (or just comment that line), and by using gcc or even tcc will work fine.
- none_to_remain 3y agoI went too far and ran into the printed hexadecimal-decimal lookup table for every number from 0x0-0xFFF
- dekhn 3y agoah yes, I had that poster on my wall as a kid... https://twitter.com/JBrooksBSI/status/952291667041599488/photo/1 https://twitter.com/JBrooksBSI/status/952291667041599488/pho...
- bombcar 3y agoNow I'm having fond memories of discovering the IBM box drawing characters above 128 as a kid, and doing fancy text files.
- belter 3y agoIt's the Toledo family. All is possible. https://news.ycombinator.com/item?id=28337064 https://news.ycombinator.com/item?id=28337064
- msla 3y agoGiven the number of lies on the company's website, I'm not inclined to believe them about other things.
- anthk 3y agoThe articles on the browser tech are horribily outdated, and ditto with TLS libraries. But if they used something like mbedtls/bearssl and Gemini/Gopher, they would be still useful.
- philomath_mn 3y agoWow, that sent me down a rabbit hole -- but this line from the homepage makes it sound like he is _not_ part of that family? > If you're looking for information about the Mexican scientist Oscar Toledo Esteva, then please go to the History page of the Familia Toledo organization site. https://nanochess.org/index.html https://nanochess.org/index.html
- emi2k01 3y agoI believe they are father and son. The `Books` section on the Toledo family website links to books written by Oscar Toledo G.
- philomath_mn 3y agoGood catch -- those same books show up on the nanochess site: https://nanochess.org/author.html https://nanochess.org/author.html Odd that he doesn't mention the "scientist" people may be looking for is his father, but everything else lines up.
- kqr2 3y ago
- slily 3y agoThe 8080 instruction set opcodes have logical bit patterns, so you can identify the operation and operands through bit masking instead of requiring a huge LUT. Beyond that you can simplify a lot by sacrificing timing accuracy.
- zabzonk 3y agoyou can also write one using a 256-byte switch, which ain't so big. i wrote an 8080 emulator in fortran77 on a dec10 that way, back in the 1980s. but of course size wasn't an issue. it did prove to be quite portable - to vax and ibm vm/cms. we used it for teaching assembler programming.
- RetroTechie 3y agoThe 8080 has ~5k transistors. There's only so much complexity one can build with those.
- xcv123 3y agoAfter simplifying and reducing the code as far as possible, it is rewritten in a compressed format using macros and without whitespace. Look at the #define statements.
- nanochess 3y agoThe simplest emulator in the world would be like this one: unsigned char memory[65536]; int reg[8]; int main(void) { int pc = 0; /* In this point you read something into memory */ while (1) { instruction = memory[pc]; if (instruction == 0x76) break; /* HLT */ pc = (pc + 1) & 0xffff; if ((instruction & 0xc0) == 0x40) /* Handle MOV r,r (opcodes 0x40-0x7f) */ reg[(instruction >> 3) & 7] = reg[instruction & 7]; } return 0; } What it does? It simply reads each instruction from memory (PC is the Program Counter), and increments PC continuously limiting it to 16-bit. It does a comparison for each possible instruction, for this example I only handled the most basic one of 8080 (MOV r,r) and HLT, but this is already 64 cases of the 256 possible! Then I added iteratively chunks of opcodes to emulate and used language C macros to reduce the code size. For example, there is #define d(e) to join two 8-bit registers into a 16-bit value, and #define Q to read the accumulator. In the end, to stay inside the size limit of the IOCCC, I removed the tree of 'if' statements and replaced it with a tree of trinary operators ?: (a way of doing 'if' inside an expression) and this is what the macros C and S does.