aksommerville/akfceu
Folders and files
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Repository files navigation
akfceu
15 March 2015
Andy Sommerville: a k sommerville at g mail dot com
I'm trying to rewrite FCEU from version 0.98.13 to something clean and portable.
0.98.13 is the last version I'm aware of before the onerous ports to C++.
I want to maintain clear separation between the core emulator, general services, and host services.
Having ported this very code to Wii, Linux, and iOS (albeit sloppily), I know that the code itself is OK.
OK, but very dirty.
26 December 2018
Picking it back up.
Let's go for broke and build it...
src/fceu/fds.c:627:20: error: comparison of unsigned expression >= 0 is always true [-Werror,-Wtautological-compare]
src/fceu/fds.c:649:21: error: comparison of unsigned expression < 0 is always false [-Werror,-Wtautological-compare]
src/fceu/fceu.c:190:4: error: implicit declaration of function 'FCEUD_NetworkClose' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
src/fceu/fir/toh.c:5:1: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int]
src/fceu/drivers/pc/dos-sound.c:24:10: fatal error: 'sys/farptr.h' file not found
Deleted from drivers: sexyal, pc, win
src/fceu/unzip.c:1024:43: error: equality comparison with extraneous parentheses [-Werror,-Wparentheses-equality]
src/fceu/state.c:234:9: error: '__builtin___memset_chk' will always overflow destination buffer [-Werror,-Wbuiltin-memcpy-chk-size]
src/fceu/state.c:236:27: error: use of undeclared identifier 'FCEU_VERSION_NUMERIC'
src/fceu/soundexp.c:3:10: fatal error: 'vorbis/vorbisfile.h' file not found
Deleted soundexp.c (Sound Export), was not referenced anywhere.
src/fceu/mbshare/maxicart.c:22:10: fatal error: 'mapsafe.h' file not found
maxicart.c is apparently not used; commented it out
**************************************************************************
***** This one might be a real problem, and I'm not sure I fixed it. *****
src/fceu/mappers/69.c:55:28: error: if statement has empty body [-Werror,-Wempty-body]
Mapper 69 is "Sunsoft FME-7", used by: Batman: Return of the Joker, Hebereke [per fceultra.html]
src/fceu/file.c:157:20: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:157:20: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:157:20: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:157:20: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:532:10: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:532:10: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:532:10: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:532:10: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:552:12: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:552:12: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:552:12: error: member reference base type 'void' is not a structure or union
src/fceu/file.c:552:12: error: member reference base type 'void' is not a structure or union
...need cast to gzFile from zlib.h
src/fceu/general.c:69:12: error: static declaration of 'asprintf' follows non-static declaration
...define HAVE_ASPRINTF
src/fceu/general.c:90:42: error: expected ')'
[and many more]
...define PSS_STYLE=1
src/fceu/palettes/conv.c:63:1: error: type specifier missing, defaults to 'int' [-Werror,-Wimplicit-int]
...disabled file (helper tool)
Now we fail to link due to (presumably) things implemented under 'driver':
"_FCEUD_GetPalette", referenced from:
"_FCEUD_Message", referenced from:
"_FCEUD_NetworkClose", referenced from:
"_FCEUD_PrintError", referenced from:
"_FCEUD_SendData", referenced from:
"_FCEUD_SetPalette", referenced from:
"_FCEUD_UTF8fopen", referenced from:
Implementing these in src/opt/macos/fceu_driver_macos.c
OK it all builds and links and does nothing. We need main().
---------------
27 December 2018
Got my interface stuff running, copied from Minten.
Setting up the FCEU driver, mostly by selective copying from drivers/pc/main.c.
!!! Very real error !!!
ines.c:230: Including "ines-bad.h", and we will iterate over this until (name) is false, but the sentinel entry is missing!
Easily fixed, but are there other cases like this?
Also, what the hell is up with looking for hashes of specific ROM files? We shouldn't have to do that.
There is a call to FCEUI_Initialize() in main.c:CLImain. Do we need that?
...yes
Failing somewhere in FCEUI_Emulate...
...add FCEUI_PowerNES() at load.
...add FCEUI_Initialize() at init (before load).
That's a bingo!
[X] FCEUD_PrintError: WRAM file "/sav/zelda.9d1a36d1c5233d55499b8484262ac6ab.sav" cannot be written to.
[X] Some sprites rendering incorrectly: Obvious in the Zelda "All of Treasures".
Is this a byte order thing?
Is it a faulty ROM file?
...there is a macro LSB_FIRST which is read but apparently never defined.
...That fixed it.
Got it running, looks good, eating 12-15% CPU.
[X] Audio
Naively writing and reading from a shared circular buffer works pretty good but they go out of sync periodically.
I think we need audio to drive the master timing... What does it take to disable video timing?
[context flushBuffer] in mn_macwm_window.m blocks for video refresh (unless window is fully occluded).
Can we disable that? [context setValues:&v forParameter:NSOpenGLCPSwapInterval]; Whoo! Benny Hill mode!
Timing seems good. Played a few minutes with neither kerfuffle nor tearing.
[X] Horizontal squish? ...added aspect correction to video
[X] Save and snap files.
FCEUI_SetBaseDirectory()
[X] Joysticks.
[ ] Aspect correction and cropping, make configurable.
13:30: Looking good, fullscreen toggle, audio never skips, 2-player support.
Consider mapper 69...
Batman: Return of the Joker
...dude, I'd forgotten this game. It fucking rules.
Seems OK with the blind fix I made yesterday.
Funny, I can't see any difference with that line enabled or disabled. Digging in with some logging...
...seems that that line is never hit.
~/proj/akfceu> grep -nr Mapper69_SWH src
src/fceu/mappers/69.c:50:static DECLFW(Mapper69_SWH)
src/fceu/mappers/69.c:234: SetWriteHandler(0xe000,0xffff,Mapper69_SWH);
src/fceu/mappers/69.c:246: SetWriteHandler(0xe000,0xffff,Mapper69_SWH); <-- this does happen
...Not seeing it. I'll leave the line disabled, with a log entry after, in case we ever find a ROM that invokes it.
[X] Is there anything we can do about the sprite flickering? I see it in most games.
Easily reproducible with Chip N Dale's Rescue Rangers, enter 2-player mode and just stand next to each other.
Sprites are drawn per scanline at ppu.c:1116, CopySprites().
ppu.c:988: RefreshSprites() draws one scanline of sprites only, which is then composited onto the framebuffer.
Seems the vanished sprites are missing from "SPRBUF"...
um.
Looks like this is already known. Just call FCEUI_DisableSpriteLimitation(1) during init.
[X] Finder: "akfceu can not open files of this type". Can we? Hell yeah we can.
21:31: A few hours of play have confirmed that this works really good.
Mmmmmm, might need a few hours more.
But first I'll start reviewing FCEU code for things we don't need.
---------------------------------
28 December 2018
Things are working. Reviewing 4-player games...
[x] This happened when unplugging headphones. What can we do?
Audio timing panic.
macioc:FATAL: Error -1 updating application.
...changed "panic" in sleep_until_audio_available.
At (10), launch failed 10 of 10 times.
At (1000), launch succeeded 10 of 10 times.
At its previous value (100), got 1 of 2.
Left at (1000), ie 1 second.
---------------------------------------
26 December 2019
Picking up again after about a year away.
[x] Launching a new game via Romassist reliably freezes akfceu.
I've worked around it by always terminating before launching a new one -- good policy anyway -- but can we fix this?
[x] What's the simplest way to replicate it?
make && src/test/auto/20191226-double-launch-freeze.sh
Uses romassist via curl
Add some logs around romassist_update() in akfceu_main.c and it goes away. Must be some timing thing then.
- ra_client.c was older than the one in romassist. Updated but still broken.
[x] Launch in some way that we can see the logs.
Launch first with "open" and --redirect-tty=REGULAR_FILE
[x] It fails when I do two curl launches but not when I launch with 'open' first.
Add "--reopen-tty=/dev/ttys000" to the Romassist launch command and it does not fail.
Must be blocking on stdin or stdout somewhere.
Does /dev/null work? NO it freezes
After changing printf to fprintf(stderr), I can't make it happen anymore.
So.... didn't really fix anything, but change all printf() to fprintf(stderr,...).
[ ] Revisit the Romassist IPC protocol, clean up whatever needs it.
[x] Screen capture
[ ] Pause, resume, step.
[ ] Debugger controls. Dump registers and RAM generically. Poke them too.
[ ] Generic controls deliverable via Romassist UI, defined by emulator.
eg from emulator [{ "key":123, "name":"Frame skip", "min":0, "max":60, "default":0, "value":0, "desc":"Skip frames." }]
[ ] Logging
[x] Long-term plan is to move all the high-level into shared libraries owned by Romassist. Are we positioned to support that?
Everything in src/opt should move to RA libs. Easy.
Most of src/main should go too. About 2k lines, will be hairy.
[x] Better test scaffold, like ffutil and romassist. Can we share some of this via Romassist?
[x] Enable keyboard input
--------------------------------------
18 August 2020
Picking up again, on Linux this time.
[x] Compiles and everything, and the emulator is running (partially?). Black screen and no audio.
[x] Tried -m32 in both Romassist and akfceu as a test; no difference. Left it that way for now -- revert if it wasn't needed.
Same build for MacOS works.
Tracing PC in x6502.c. Mac goes 0000,ff51. Linux goes 0000,fff0.
At the very first instruction (x6502.c:680), Mac pbackus=ff50 b1=78. Linux pbackus=0000 b1=00.
First cycle, Mac _IRQlow=32, Linux _IRQlow=0
FCEU_IQRESET=0x020, set only at X6502_Reset() -- we're hot on the trail!
x6502.c:451
X6502_Power()
fceu.c:374
...at the end of PowerNES(), X.IRQlow is indeed 32 on Linux.
Linux is making a call to X6502_Init() that Mac doesn't make, after "Launch complete."
...FCEUI_Initialize()
fceu.c:323
ResetNES() -- not called
...Mac is calling akfceu_main_init() then akfceu_main_load_rom(), which makes sense.
...Linux is calling akfceu_main_load_rom() first. *************** This is wrong! Don't do anything before init!
Fixed in Romassist -- initial rom file will be delivered only after init.
[x] `make test` freezes the terminal to where I can't even abort.
...now that's what i call a test failure!
It was linking MAINOFILES instead of TESTOFILES.
Works now, but there actually aren't any tests.
[ ] Big cleanup inside fceu.
With the main goal of better understanding how it all works.
[ ] Remove compression
This will take a lot of untangling.
Locate places that read and write files, and rephrase them to operate on memory only.
[ ] Limit access to files -- none would be ideal. (see compression)
[ ] Remove everything that prints to the framebuffer. All of our OOB UI will be thru config files, command line, or remote comm.
[ ] Consistent formatting? Probly not worth a lot of effort
[ ] Unit tests.
xxx Why is the audio buffer out of FCEUI_Emulate() 32-bit? Can we drop it to 16? ...yes but no
SexyFilter (soundq<1) clamps to 16-bit anyway.
Trying 16-bit... beware that this might break NeoFilter.
See moocow() in mappers/emu2413.c -- Yeah, pretty sure we're breaking NeoFilter
...tried it and it worked, for Ninja Gaiden at least, but this is too risky. backing it out.