![]() |
Forum Index : Microcontroller and PC projects : WIP: CMM2 NES Emulator
![]() ![]() ![]() ![]() |
|||||
Author | Message | ||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10008 |
You are measuring the print time and on the later runs the screen is having to scroll |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4245 |
Thank you. Table lookup is still marginally faster ![]() MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10008 |
Atomizer_Zero If you download V5.05.05b4 you will find that a new graphics mode is available. Mode 6 is 256x240 - seem familiar? ![]() |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
Thanks guys lol Should make a test program that times how long it takes to return the completed value.... option default integer option milliseconds on dim integer starttime dim integer B%=&B11100001 ? bin$(b%) timer = 0 starttime=timer ? "bytereverse start time: " ; starttime bytereverse b%, c% ? bin$(c%) ? "end time: " ; : ? (timer - starttime) ? ? b% = &B11100001 ? bin$(b%) timer = 0 starttime = timer ? "flipbyte start time: " ; starttime flipbyte(b%) ? bin$(c%) ? "end time: " ; : ? (timer - starttime) CSUB bytereverse 00000000 7802B4F0 18942300 0503EB43 EA4302AB 02A25394 416B1912 EA45051D 05143512 416B1912 E9D5A50C 40224500 0218402B EA400216 023D6712 6516EA45 19A40234 042F417D 4714EA47 19A40426 18A4417D 700D415D 4770BCF0 84422110 00000008 End CSUB sub flipByte(b%) b% = ((b% And &HF0) >> 4) Or ((b% And &H0F) << 4) b% = ((b% And &HCC) >> 2) Or ((b% And &H33) << 2) b% = ((b% And &HAA) >> 1) Or ((b% And &H55) << 1) c% = b% end sub RESULTS: > RUN 11100001 bytereverse start time: 0 10000111 end time: 0.371 11100001 flipbyte start time: 0 10000111 end time: 0.391 could probably write that 10 times nicer, but still xD |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
Oooooo I'll check it out. Thanks! |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4245 |
Hi, Your benchmarking is iffy because you are including the Print statements in the timed section (same mistake I made). You should find that Peter and my approaches are approximately the same, and 5x faster than the original approach. Also I don't know what this was meant to be: sub flipByte(b%) b% = ((b% And &HF0) >> 4) Or ((b% And &H0F) << 4) b% = ((b% And &HCC) >> 2) Or ((b% And &H33) << 2) b% = ((b% And &HAA) >> 1) Or ((b% And &H55) << 1) c% = b% <-- *** HUH? *** end sub Variables are passed by reference, try this: Dim b%=&b11100001 ? b% flipByte(b%) ? b% flipByte(b%) ? b% flipByte(b%) ? b% sub flipByte(b%) b% = ((b% And &HF0) >> 4) Or ((b% And &H0F) << 4) b% = ((b% And &HCC) >> 2) Or ((b% And &H33) << 2) b% = ((b% And &HAA) >> 1) Or ((b% And &H55) << 1) end sub Regards, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10008 |
If you want to flip the variable without a copy like the lookup this one is a bit faster b%=&B11100001 bytereverse b% ? bin$(b%) ' CSUB bytereverse 00000000 0FF0E92D A000F890 0B00F04F 0A0AEB1A 0B0BEB4B 268AEA4F 278BEA4F 060AEB16 579AEA47 5206EA4F 070BEB47 EA43053B 18B63316 0B50F20F AB00E9DB EA0A415F EA0B0A06 EA4F0B07 EA4F220A 0214210B 631AEA41 EA4F18A4 EA4F2503 EA454804 415D6512 4905EA4F 4914EA49 0408EB14 0509EB45 0A04EB1A 0B05EB4B B000F880 0FF0E8BD BF004770 84422110 00000008 End CSUB Edited 2020-08-04 00:42 by matherp |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
You know, it's because I'm not a very good programmer lol. I'm learning, getting a bit better all the time... long way to go though.. I always stress that something might get "lost" when im doing stuff like that, so I end up overthinking it and being overly safe or something, I dunno. |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4245 |
I'm not sure "not very good programmers" get nearly as far as you have with your NES emulator ![]() Regards, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
so... i rewrote the ppu logic... ![]() Colours are working properly now but... well thats supposed to be the donkey kong title screen. also, mode 6 works great. I need to figure out a way to offset the position of the rendering to the left by 16 pixels or so... any ideas? |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
![]() FINALLY! But of course, still a problem. No Sprites are loading. The little Selection sprite icon isn't there. But this is a win in my book. its running about 2 scanline a second, which is unplayable, but still a nice proof of concept. |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
![]() still cant figure out the sprite issues yet. The little > triangle next to start is actually a background tile that gets drawn over the top of the background, which is interesting. Uses tile priority to draw on top. They could have easily used a sprite for it (like donkey kong does). It's also interesting to see bomberman running at all, considering it's a mapper 0 game has has horizontal scrolling. |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
NES_EMU_CMM2.zip Releasing an early 0.0.1a version of it for everyone to have a look at and laugh at and poke at. Make sure you read the readme.txt included (can read on cmm2 if you want, just highlight the file and hit F4). It's set with Debug=0, Option Console Screen, to get the most out of the cmm2 speed (screen makes a differnce right?). That means you'll need to use a keyboard attached to the CMM2 in order to type in the rom name. One more thing. No roms are included. There are free public domain roms out there, just make sure theyre mapper 0... If nothing happens after 15 minutes after loading a rom, then it aint working (probably). Just remember, this is super slow man. so have some patience. Edited 2020-08-05 02:52 by Atomizer_Zero |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
I dont believe it. I've found the error. I had a typo. Basically, one variable name instead of another. It was enough of a problem that all sprites were being drawn transparent. This OF COURSE AS USUAL introduced another bug. The sprite data is garbled. It's wrong and just wherever it wants to be on the screen. I think I know the reason for this though. Hopefully I'll be able to show a screenshot of game with actual sprites on soon. The question is though.... from there, what next? Its obviously too slow to play, so.. maybe we can work together (if there's any interest) and try to slim the code down and do some clever tricks and things to speed up data manipulation? Rewrite some of the code to be csubs? we already have one for byteflipping. I'm open to suggestions, critisism and whatever else. |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
And just like that. I've fixed it ![]() that little pink star is a SPRITE. :D |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4245 |
Very impressive. The real question is are you up for rewriting it in "C" with probably just the top-level skeleton in BASIC ? I've taken a brief look at the code you published previously and it looks like there is a fair amount of scope to optimise the BASIC, but even if you get it x10 or x100 times faster it sounds like it is still going to be unplayable, is that correct ? Regards, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
I'm not surprised if there's a ton of optimisation that can be done. The code is very close to my Java code. So, I don't really know of any decent way to time how long it takes for a complete NES frame. But I did this DO WHILE RUNNING timing = timer ?timing DO WHILE BOOLFRAMECOMPLETE = 0 KEYINPUT() BUSCLOCK() LOOP BOOLFRAMECOMPLETE = 0 elapsedtime = timer - timing ?elapsedtime LOOP 513222 ' thats the start time of the timer 149208 ' thats the result of elapsed time after one complete frame. so around 150 seconds for a basic frame where nothing happens but the screen fills with grey. Im sure this will double by the time it gets to the title screen. but even so, 150 for 1 frame. So, multiply that by 60 (60 FPS) and you get 9000 seconds. which is 150 minutes. O_O So.. it will do 60 frames per 150 minutes. so we need a 9000% increase in speed to get full speed, right? lol Its a pipe dream. It wont happen on the CMM2, with this code. Not without some wizardry with some hard data crunching. The stuff that "Bisquit" does on youtube for example (he wrote a NES emulator in QB64 with compiled basic). BTW, my math might not be correct, and maybe the timing isn't accurate or something, but i think it's accurate enough to give some kind of idea of what needs to happen ... |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4245 |
EDIT: This was written before the post immediately above, but that only makes me more convinced by the approach I outline below. ... if your ultimate goal is to provide an NES emulator for the CMM2 then you are probably best going back to JavidX9's original C++ source instead of continuing from your BASIC port. ... it looks like it is barely C++ so it shouldn't be any great difficulty to turn it into vanilla C. Then you just need to worry about interfacing with the CMM2 firmware for the I/O which even should you run across stumbling blocks they are unlikely to be showstopper's given Peter's (matherp) responsiveness. Having already ported JavidX9's code to Java and BASIC I don't imagine this will prove all that challenging to you ... but it will obviously take a considerable amount of work. Regards, Tom Edited 2020-08-06 04:13 by thwill MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
Atomizer_Zero Senior Member ![]() Joined: 04/07/2020 Location: United KingdomPosts: 134 |
It's an interesting proposal. I don't know much c or c++, so it'd be a lot learning in that first. I'm actually considering leaving this emulator here as is for now. I want to make other stuff on the CMM2 (which i'll probably need to create a thread about as I'm confused about images already ¬_¬ ) We'll see what happens in the future... |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4245 |
I can understand that. I've just been thinking about future projects myself and when it comes to "porting" an existing widely available work to the CMM2 then IMHO it really only makes sense: 1) for the journey, and/or 2) for the bragging rights for having done it in BASIC* .. which means if you need to use lots of CSUBs you've already "lost" * And I think a fair proportion of those bragging rights actually belong to ARM, Geoff and Peter. YMMV, Tom MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures |
||||
![]() ![]() ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |