UZEM & SD card emulation

The Uzebox now have a fully functional emulator! Download and discuss it here.
CunningFellow
Posts: 1192
Joined: Mon Feb 11, 2013 8:08 am
Location: Brisbane, Australia

Re: UZEM & SD card emulation

Post by CunningFellow » Thu Aug 01, 2013 10:30 am

Sorry Uze, I think you have completely over estimated my skills.

I have had a look and I reckon I am out of my depth. Lunatic seems to be on fire though with his NTSC filter work. Ho obv. knows how to delve into foreign C code and patch stuff together.

I will for the moment stick to ASM trickery. I have much optimizing work to get Tempest going and will stick to that.

User avatar
lunatic
Posts: 49
Joined: Sun Jul 28, 2013 12:29 am
Location: Horten, Norway
Contact:

Re: UZEM & SD card emulation

Post by lunatic » Thu Aug 01, 2013 10:54 am

Hi,

I could probably look a bit at the SD code. But I do not own a real uzebox yet. So I do not know if my SD card is actually working. Which is a bad start for tryting to find the problem with the SD card reading in uzem.

I have tested uzem with a SD card formated to fat16 and added a few files, and the SDTester.hex and musicplayer both see some data, but they can't seem to find any files.
But I could try to just compare the raw data from my sd card to the raw data in sdtester. To see if there is some mismatch there.

User avatar
lunatic
Posts: 49
Joined: Sun Jul 28, 2013 12:29 am
Location: Horten, Norway
Contact:

Re: UZEM & SD card emulation

Post by lunatic » Fri Aug 16, 2013 8:08 pm

So, now that I have a real uzebox to test with. I have gotten a SD card with audio files to load correctly. (I am having some problems not getting fragmented files even when formatting with a mac)

Then I tried to load the same SD card with the emulator. And it actually works. But somehow the mouse cursor is missing in uzeamp.

So on at least linux and mac I guess the SD reader in the emulator works. As long as you have access to the raw device. (to get this, either start uzem as root, or have the root user give your user access to the disk drive, using file permissions)

In linux this would be:
sudo uzem --img /dev/sdx uzeamp.uze

or mac:
sudo uzem --img /dev/rdiskx uzeamp.uze

Where x must be replaced with the correct number or letter corresponding to your SD card reader.

But we really should have a block-device emulator in the emulator, so that we can just give uzem a directory. Which would be much more portable, and would not require any super privileges.
I will think a bit about this.

User avatar
uze6666
Site Admin
Posts: 4487
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: UZEM & SD card emulation

Post by uze6666 » Fri Aug 16, 2013 11:16 pm

So, now that I have a real uzebox to test with.
Pretty decent shipping time!

So the SD interface actually works in uzem?? :shock: Or you made it work? Otherwise...Essh, and to say I always thought it was incomplete... :oops:
...so that we can just give uzem a directory. Which would be much more portable, and would not require any super privileges.
I will think a bit about this.
Totally agree, that would be much user friendly and faster to develop too. Though I think there's was something done on the Windows side on that front, check out the sources.

User avatar
lunatic
Posts: 49
Joined: Sun Jul 28, 2013 12:29 am
Location: Horten, Norway
Contact:

Re: UZEM & SD card emulation

Post by lunatic » Sat Aug 17, 2013 10:39 pm

uze6666 wrote:Pretty decent shipping time!
Sure. Not the worst I have encountered. Thanks by the way. It was preloaded with uzebox, so I didn't need to burn it :D But a package from China came a week before the uzebox, and it was sent just a day before I think ;P
The bad part is that the postal service here made me pay toll + tax for it, even if it was marked as gift.

Btw uze6666: Some of the games/demos does not work. Specifically the uzebox demo. The led is barely lit, and the screen stays black.
uze6666 wrote:So the SD interface actually works in uzem?? :shock: Or you made it work? Otherwise...Essh, and to say I always thought it was incomplete... :oops:
As I said. I thought the code looked pretty done. And I was right. It works out of the box on mac/linux, as long as you have root access to the devices, or give it a raw dump of your sd card.

What probably isn't done, is the windows part, I would guess. Because windows won't let you read the whole card raw.
uze6666 wrote:Totally agree, that would be much user friendly and faster to develop too. Though I think there's was something done on the Windows side on that front, check out the sources.
Faster to develop? Do you mean the emulator part? Or faster to develop games/apps for uzebox when the filesystem is local?

Anyways. Today I have been wrapping my brain around FAT16, and the MBR partition table, and sectors/clusters/etc. And I have come as far as having written a very KISS directory-lister that reads a raw file, and spits out the corresponding info about files, and where they reside on the card. And it works! I can also see where the file is fragmented etc. (using the 'FAT')

The reason I have done this, is to understand how FAT16 really works, so that I can emulate it, given just a directory.

The MBR is already done; uzem has already functionality added for emulating this. It's just a simple partition table. So the next part is adding a fake FAT16 boot sector with as simple parameters as possible, and populate a FAT table, and a root directory. I say "a root directory" instead of "directories", because I guess my first version will only have a root dir, and no sub-folders. This to simplify the project, so I will get it done, before overwhelming myself :P But you would be able to have as many files as you want. As long as you keep below the 2GB limit.

I will try to make the emulation as good as possible. I know uzeamp doesn't read the FAT table, as it expects no fragmentation, but I will add fat table support :) Even though there will never be any fragmentation in the emulation.

I am no expert in C++. I am more used to C. So this will be a project to learn more about C++. Not that I will use any hard core features in c++. Probably just pretty simple c++, just as the uzem emulator. Just the basics.

So far I have created a struct for the root directory entries, and the boot sector. So the only thing left, is to populate the directory contents, and make a superfancy "readSD" function to fake data from the FAT, root dir, actual data, and the mbr.

The file-table will only be re-read each time you reload the emulator. I could maybe make support for reloading if there is some soft-reset. But I am unsure if the emulator even supports soft-reset? I don't think the watchdog code is done. Is there any other way to soft-reset it? jump to 0?

User avatar
lunatic
Posts: 49
Joined: Sun Jul 28, 2013 12:29 am
Location: Horten, Norway
Contact:

Re: UZEM & SD card emulation

Post by lunatic » Sun Aug 18, 2013 11:39 pm

So here's a progress report!

I start uzem with a folder. For example a folder named "files", that has both wav files and uze files in it.
It then emulates a minimalistic fat16 filesystem.
Screen Shot 2013-08-19 at 12.33.35 AM.png
Screen Shot 2013-08-19 at 12.33.35 AM.png (36.17 KiB) Viewed 3037 times
So, as you can see. Uzeamp correctly reads the filesystem, and has access to the files in it.

But I am having some problems getting uzeamp and my emulator to agree on where the first cluster starts :P
I have also not finished the FAT table, but uzeamp ignores it, so that part is not the most important right now. Do we have a SD/Fat lib that handles fragmented files? (hence reads the fat table)

But the cool thing is that I am getting flawless audio, when it finds the correct start of the cluster. So I just have to find out where my math is wrong :o)

Funny thing is; I spent hours trying to find out why uzeamp did not find my files, even though I could see my directory-entities being sent correctly. But it turns out that I forgot to upper-case the filenames. So uzeamp did not find my "wav" files, when it searched for "WAV" :roll:

User avatar
lunatic
Posts: 49
Joined: Sun Jul 28, 2013 12:29 am
Location: Horten, Norway
Contact:

Re: UZEM & SD card emulation

Post by lunatic » Mon Aug 19, 2013 12:16 am

Ok. Writing the previous post seems to be the pause I needed to get my math straight :P

I had forgot to subtract two from the cluster start in all the right places.

So now IT WORKS! :D (Flawlessly in uzeamp at least)
I tested movieplayer.hex, but I only get a white screen with only pixels in a column in the middle of the screen. And the audio does not seem correct either.

Does anyone else have any games/demos that uses the SD card?

I will just need to clean up the code a bit before committing it to trunk.
Also, I need to get an answer to the following question: Is it okey to remove all previous SD code that uses images/direct access? And just use this single method where you give it a folder instead?
It makes uzem a lot more portable to just read files from a folder. But if we decide this, we need to update the emulator if we need support for FAT32/other filesystems, etc.
It also makes my job of cleaning up the code, a lot easier.

Here's a screenshot where you see it has been able to read the extra info from the wav header. All the files are playable. :)
Screen Shot 2013-08-19 at 12.47.37 AM.png
Screen Shot 2013-08-19 at 12.47.37 AM.png (35.28 KiB) Viewed 3031 times

User avatar
uze6666
Site Admin
Posts: 4487
Joined: Tue Aug 12, 2008 9:13 pm
Location: Montreal, Canada
Contact:

Re: UZEM & SD card emulation

Post by uze6666 » Mon Aug 19, 2013 1:44 am

Awesome work!! You're the man! :mrgreen: Can't wait to get home to test that out. I don't see why we should keep the old image file code if directory loading works. So I totally agree you remove it if that makes the sources cleaner.

Don't forget to bump up the emulator version (it's in one of the header files I think)
Does anyone else have any games/demos that uses the SD card?
There's the uze8 chip8 emulator and the Mario game for the UCC2013. There's also Harty's thermometer demo. Btw does the bootloader run?

User avatar
lunatic
Posts: 49
Joined: Sun Jul 28, 2013 12:29 am
Location: Horten, Norway
Contact:

Re: UZEM & SD card emulation

Post by lunatic » Mon Aug 19, 2013 6:43 am

Hi,

I have tested uze8 and mario now. Seems like they both have some problems with the SD SPI interface, that uzeamp does not have.
Probably some kind of initialization check that is not present in uzeamp.

In uze8, it sends CMD0 (init), and then halts forever. So seems like it doesn't see that the card is initialized.

In mario demo, it sends CMD0 in a loop, so it seems like it is somehting of the same problem.

User avatar
lunatic
Posts: 49
Joined: Sun Jul 28, 2013 12:29 am
Location: Horten, Norway
Contact:

Re: UZEM & SD card emulation

Post by lunatic » Mon Aug 19, 2013 7:14 pm

I have commited the changes to trunk now. :)

I have also compiled it for windows, and added to the download page on the google code page, for those lazy ones of you :P

Currently, it seems like only Uzeamp successfully uses the SD emulation. There seems to be some initialization problem with for example uze8 and the mario clone from UCC2013. They never get to the next operation after CMD0 (initialization of SD card). I will have to look more into this. Its very weird. Because the SD emulator sends back 0x01 as the status, and that should be enough.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest