-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Memory usage #8
Comments
Not quite sure what you are attempting but MEMORY_RANGE is a constant value set at 1MB so those 5 data structures require 5MB memory. The emualtor only emulates 640K to 1MB system. This repo is very old and no longer updated. See my fork for all the latest updates and releases. |
Faux86-remake is base on Fake86 or XTulator? |
I know MEMORY_RANGE is 1 MB, but |
This repo is not abandoned, I just haven't made any updates for a couple of years. I intend to get back to it. I tend to project-hop a lot. I've actually done an MCU port of this already and it required a bit of restructuring for the memory and ports stuff of course. I'm on my phone at the moment, but I'll come back later and share how I did it. As it is, it makes sense on a desktop PC because it's fast and memory isn't an issue, but yeah not good for an MCU. |
Both. I merged and updated code from Fake86, Faux86 and XTulator ro create Faux86-remake. |
Sorry didn't say it was abandoned, only not recently updated. Yes, the XTulator is coded for desktop PC use but my port with Fake86/Faux86 is ported and tuned for RPi. |
Yes, you are correct they are pointer arrays so 4 x MEMORY_RANGE. Maybe you could dynamically create them and use some kind of memory or file cached array. No idea really how you can reduce the size of a static pointer array. I don't think the full 1MB of memory is used anyway so at most only 640KB is required. |
Yes, we can't usually use those huge static arrays on an embedded system. When I did an Arduino port, my memory.c file looked more like this: I made a struct with the required data to specify a memory area, made an array of 16 of them (which is overkill) and looked through the arrays on RAM accesses. Maybe there's some faster way to do this. You'll have to modify this code depending on exactly how you're accessing your memory. I was using an Arduino with SPI RAM. You'll need to supply your own memory_ramRead and memory_ramWrite functions. I did something similar with the struct arrays in the ports.c file. Hopefully this gets you started. |
You'd have to a memory mapped page file to get round this if the MCU does not have enough memory to map the full address ranges. That's if you do have access to file based storage on the MCU i.e flash or memory card. |
Right, or something like SPI RAM ideally. He says he has 8 MB PSRAM so that should be good. If the MCU doesn't have enough native RAM, then yeah it'll be slow and there's no way around it really. I actually used this same concept to build a 16-bit DOS version (lol) and it uses as much real RAM as the system can allocate, but then hits a swap file when it needs to access more. I've never seen your fork before by the way, I'm looking at it now. Very good stuff! I'm at work now but will dig deeper this weekend. |
THANKS. I took alot of code from your XTulator and I've noticed I did not give any credit in the readme files. I will update it tonight to highlight your code was used for part of the remake. I spent a good few weeks tweaking code from all repo's that I could find. |
@mikechambers84, is your MCU project runnable now? On which platform? |
Since the MCU resource is very limited, is it become simpler if I only hard code to a specific hardware setting? |
I am developing something like this: Someone already success on Fake86 before, may be I dig into it first. |
@mikechambers84, I followed your code and have much imporvement:
But still need to locate another memory eater... |
I can run XTulator in ESP32-S3 now after use malloc for the vga_framebuffer. But I found it is noticeable slower than fake86/faux86 since loading bios and vga initiazation. Any hint I can tune? |
Don't know why it simply too slow, here are the booting video: |
Hi, are you rendering the screen in the same thread that that's doing the CPU emulation? That would take up a lot of CPU cycles. When I did an ESP32 port, I ran another thread on the second core that was dedicated to screen rendering. |
Display should not the reason, because it still slow even I set force FPS to 1. |
I don't really have any other ideas without seeing the code of your port and how you're handling everything. Either way, I'd highly recommend making the screen render on second core. |
My working code is at: https://github.com/moononournation/arduino-XTulator |
It might be faster if you just get rid of all of the memory map code and do some if-else statements like if (addr32< 0xA0000) { The way it's searching now for the memory map on each read/write might just be too heavy for an MCU to do quickly. These memory and port maps help make it more easily modular with inserting hardware into the virtual system on startup based on the configuration desired. It's very fast on a PC because there's enough RAM where I can have those big arrays and just do a simple array lookup for the memory/port handler based on address. On this memory limited system, we're having to make some smaller structures and for-loop through them to find the right one, so I guess that's just too slow. I was using a very fast ARM MCU running at 800+ MHz so it wasn't an issue there, but the ESP32 is more limited. |
I still not yet locate why XTulator run slower than Faux86-remake. |
that's not how switch cases work. They are usually implemented via jump tables, and a case per opcode is an extremely common method in emulation. |
Indeed, once I've encountered a Z80 emulation written in C using array of function pointers. I modified that (with the intent of optimization) to use a big switch statement handling all opcodes, and it run faster after that, in fact it was something like twice as fast in average (IIRC ...). Most (all?) modern C compilers optimizes switch statements into jump tables if the cases are "well behavioured" (like, there are many cases and all/most of them are continuous), which is always faster than referencing function pointers also with the cost of calling subroutine then. Of course random switch/case statements with non-continuous/"random" cases are different stories. |
I would like to try porting the XTulator to a MCU like ESP32.
I found the memory not enough for memory.h:
ESP32 can have 8 MB PSRAM but the about structure requires 2x MB to emulate 1 MB RAM. Any hint to reduce the memory usage?
The text was updated successfully, but these errors were encountered: