Homebrew Emulation GameYob, a gameboy emulator for DS

Drenn

Well-Known Member
OP
Member
Joined
Feb 22, 2013
Messages
574
Trophies
0
XP
706
Country
Canada
Hi Drenn, dunno if youve seen this documentation for Nifi.
Maybe it can help with simulating the Game Link Cable for two player GB games.
Bookmarked. I think I'll try it out sometime soon.

Nebuleon looks to be done with his optimizations. Shantae now runs at around 45 fps, where before it ran around 30. The Pokemon Trading Card Game is very nearly fullspeed, with slight lag (57 FPS) when your opponent is thinking. Nice work!

In the meantime I've been rewriting the graphics core, lameboy-style (all on a single background). Goomba-style is very fast, since it uses the ds's tile-based hardware to its advantage, but I think lameboy-style is the way to go in the long run. It allows for better accuracy, it will be easier to make super gameboy borders (as only one background is used, as opposed to all 4) and it also allows for scaling, which already works, although without a filter (which I know nothing about). The branch isn't on github yet as it's embarassingly incomplete, and slow. I'm not giving up on the goomba-style graphics at this point because it's faster. If I can't get the lameboy-style graphics within similar speeds I might make it a toggleable option.
 

Kouen Hasuki

Coffee Addict
Member
Joined
Jan 9, 2013
Messages
1,387
Trophies
1
Age
40
Location
Behind you
XP
681
Country
Norway
With the latest version (Dropbox link)

Alone in the Dark TNN: UP from 13 to 16FPS
Resident Evil BETA: UP from 43FPS to 60FPS
Resident Evil Gaiden: UP From 46 to 60FPS*
Super Mario Land 2: Warp Pipes sound tone is lower than it should be and fireballs is a bit higher otherwise perfect

* except when 2 Zombies are after you outside battle The GBC also had Similar slowdown with this so may not be the fault with the emulator - In Game Text Now Works Fine
 

Deleted member 319809

MAH BOI/GURL
Member
Joined
Dec 22, 2012
Messages
900
Trophies
0
XP
461
Country
Canada
[This post has 3 main ideas. They are split with '----'.]

My last optimisations put a special-case on the Game Boy's accumulator register, A; I wrote the full code for anything that touched A as part of a group of 7 opcodes that touched A, B, C, D, E, H and L in turn. It's in the middle of "have code that relies on (opcode>>3) & 7 for all of them" and "have fully written-out code for all of them", because the accumulator register is used so much more often than the rest.

All operations targetting the A register twice are rewritten to use fewer ARM instructions, like 'XOR A, A' that just zeroes the A register and 'OR A, A' that does nothing. But both still update flags!

What I also tried, but ended up reducing performance by ~8% (2-3 Shantae FPS), is dead flag elimination: if an opcode set some particularly costly flags and the next one overwrote all of them without consideration to their previous value, I made it not set them. That's not in the branch right now.

----

One of my last ideas is something I don't know at all what games would benefit from it, so I want to do it separately or let Drenn try. Some time could be saved in games that don't use HALT but instead use self-jumping opcodes. The following opcodes,
Code:
6052: C3 52 60    JP 6052h
6052: E9 FE       JR -2    ; to 6052h, two bytes after the instruction then back 2
with interrupts enabled, would be equivalent to a HALT; with interrupts disabled, would be equivalent to a STOP.

Code:
6052: C2 52 60    JP NZ, 6052h
6052: 20 FE       JR NZ, -2    ; to 6052h, two bytes after the instruction then back 2
with the Z flag unset, acts as the above, with a possibility to change if the flags are not restored properly after an interrupt. Maybe that could act as a partial HALT until the next interrupt?

Code:
6052: CA 52 60    JP Z, 6052h
6052: 28 FE       JR Z, -2    ; to 6052h, two bytes after the instruction then back 2
6052: D2 52 60    JP NC, 6052h
6052: 30 FE       JR NC, -2    ; to 6052h, two bytes after the instruction then back 2
6052: DA 52 60    JP C, 6052h
6052: 38 FE       JR C, -2    ; to 6052h, two bytes after the instruction then back 2
Same.

Code:
6052: E9          JP (HL)
with HL == 6052h, acts as the above, with a possibility to change if the registers are not restored properly after an interrupt. Maybe that could act as a partial HALT until the next interrupt?

Those would be speed hacks more than optimisations. They rely on cutting the number of things that need to be emulated, not optimising the emulation itself.

----

Normmatt has one commit you may be interested in: Normmatt/GameYob/optimisations commit b328e69. It reduces the number of unnecessary palette entry conversions since it's already RGB15 that's used on the Nintendo DS, instead of RGB24 on the PC. After my testing, it gives half a Shantae FPS.

If you can cherry-pick improvements from master into asmcore which still work with it, such as moving all other functions than runOpcode to the ARM9 ITCM, I'd like to see how much performance improvement there is with asmcore now.
 
  • Like
Reactions: Drenn and Geren

Drenn

Well-Known Member
OP
Member
Joined
Feb 22, 2013
Messages
574
Trophies
0
XP
706
Country
Canada
I tried applying some of your non-cpu optimizations into asmcore, and Shantae's titlescreen runs at 40fps. Somewhat slower than the c++ core. I'm not sure how to use itcm with the asm code.
What I also tried, but ended up reducing performance by ~8% (2-3 Shantae FPS), is dead flag elimination: if an opcode set some particularly costly flags and the next one overwrote all of them without consideration to their previous value, I made it not set them. That's not in the branch right now.
Out of curiosity, did you try that for all flags or just H and N? Because H and N are very wasteful flags, they're only used for DAA (and push AF, I guess). I don't know how you went about this but maybe detecting if only those flags can be ignored would be quickest and most useful.

As for the games which use jr's instead of halt, I'd be happy to give it a try if I knew what games did that... I've used bgb's debugger a lot but I can't think of a way to find something like this.
 

Deleted member 319809

MAH BOI/GURL
Member
Joined
Dec 22, 2012
Messages
900
Trophies
0
XP
461
Country
Canada
I tried applying some of your non-cpu optimizations into asmcore, and Shantae's titlescreen runs at 40fps. Somewhat slower than the c++ core. I'm not sure how to use itcm with the asm code.
If you send your ASM into the .text section, send it to .itcm instead.

Out of curiosity, did you try that for all flags or just H and N? Because H and N are very wasteful flags, they're only used for DAA (and push AF, I guess). I don't know how you went about this but maybe detecting if only those flags can be ignored would be quickest and most useful.
I mostly ignored setting C and H, because they are the most expensive to calculate. If the current instruction wrote flags, and the next instruction didn't use the value of the flags, and overwrote them with something new, I ignored C and H for the current instruction. For that purpose, I had an array of 256 entries that told me which flags each opcode overwrites in this way. If the next instruction overwrote C and H, I would just set and clear Z and N as appropriate.

For some instructions I assumed that the flags were always needed, such as CP and BIT, so I didn't look ahead in the instruction stream.

For ADC, I assumed that the old value of C would be used, so it didn't do wasteful flag elimination.

As for the games which use jr's instead of halt, I'd be happy to give it a try if I knew what games did that... I've used bgb's debugger a lot but I can't think of a way to find something like this.
I don't know which games would do that. I assume most games would properly use HALT to improve the Game Boy's battery life.

In GameYob you could use printLog when you find an opcode whose new PC equals the instruction's location.

Something like this:
Code:
u16 oldPC = locPC - 1;
locPC = ...;
if (oldPC == locPC) {
    printLog("Self-jump to %04x (JP nn)", oldPC);
    halt = 1; // ?
    goto exit;
}
 

Drenn

Well-Known Member
OP
Member
Joined
Feb 22, 2013
Messages
574
Trophies
0
XP
706
Country
Canada
If you send your ASM into the .text section, send it to .itcm instead.
It refuses to compile when replacing .text with .itcm. Says "unknown pseudo-op: '.itcm'".
I don't know which games would do that. I assume most games would properly use HALT to improve the Game Boy's battery life.

In GameYob you could use printLog when you find an opcode whose new PC equals the instruction's location.

Something like this:
Code:
u16 oldPC = locPC - 1;
locPC = ...;
if (oldPC == locPC) {
    printLog("Self-jump to %04x (JP nn)", oldPC);
    halt = 1; // ?
    goto exit;
}
Good idea. I'll try that with some of the slower games.
 

Drenn

Well-Known Member
OP
Member
Joined
Feb 22, 2013
Messages
574
Trophies
0
XP
706
Country
Canada
Thats because its not ".itcm" its ".section .itcm,"ax",%progbits"
Thanks. It didn't make a noticeable difference as it turns out.
Nebuleon/GameYob/patch-1 commit a990a7b does self-jump tracking in the debug console. See if it's worth implementing self-jump halting for enough games. I'll also test some.
Operation C appears to use this method. It utterly spams the debug output so it's unreadable. Despite calling it a "log" it still isn't recorded anywhere... but this game runs at fullspeed anyway. None of the others in my ever-growing collection appear to do this.
 

Deleted member 319809

MAH BOI/GURL
Member
Joined
Dec 22, 2012
Messages
900
Trophies
0
XP
461
Country
Canada
Thanks. It didn't make a noticeable difference as it turns out.
I find it hard to believe that your asm opcodes are slower than C++. Are you sure you're doing the right things?:blink:

Operation C appears to use this method. It utterly spams the debug output so it's unreadable. Despite calling it a "log" it still isn't recorded anywhere... but this game runs at fullspeed anyway. None of the others in my ever-growing collection appear to do this.
That seems to be my case as well. I tried a few games before taking a break for my eyes, and none of the games I tried used self-jumps. Mainly the Zelda Oracle games, which use wavy background effects a fair bit, so I see the improvement in the hblank handler!

Most of them seem to use HALT. It's probably not worth patching the self-jumps into HALTs as described, except for battery life on the DS for those few games. Thanks for confirming the results :)
 

Drenn

Well-Known Member
OP
Member
Joined
Feb 22, 2013
Messages
574
Trophies
0
XP
706
Country
Canada
I find it hard to believe that your asm opcodes are slower than C++. Are you sure you're doing the right things?:blink:
Well the asm core was actually the first really big piece of asm code I've ever written. Most of my asm experience is from the gameboy itself which is completely different... I'm actually not so surprised that the compiler (plus your cpu optimizations) beat my asm.


Since I can't seem to stick with doing one thing, I started messing around with nifi linking. And, to my great disbelief, it's doing something on the second try! Tetris is sort of working, although the initial setup of the field is kind of slow. I'm not sure if it's supposed to take 5 seconds to start. Pokemon Yellow responds to the other game's existence, but it doesn't get farther than "please apply here" yet. Nevertheless, I thought getting it to work at all would be a huge pain...
 

Foxhounder

Banned!
Banned
Joined
Jan 20, 2013
Messages
102
Trophies
0
Age
31
XP
19
Country
United States
Well the asm core was actually the first really big piece of asm code I've ever written. Most of my asm experience is from the gameboy itself which is completely different... I'm actually not so surprised that the compiler (plus your cpu optimizations) beat my asm.


Since I can't seem to stick with doing one thing, I started messing around with nifi linking. And, to my great disbelief, it's doing something on the second try! Tetris is sort of working, although the initial setup of the field is kind of slow. I'm not sure if it's supposed to take 5 seconds to start. Pokemon Yellow responds to the other game's existence, but it doesn't get farther than "please apply here" yet. Nevertheless, I thought getting it to work at all would be a huge pain...
You sir, are awesome. Although I do have another DS, I sadly don't have another flashcart so I won't be able to use wireless. COuld I use yours? :P

However could it be possible that you could make it link to a PSP?(I doubt it but doesn't hurt to ask)
 

Drenn

Well-Known Member
OP
Member
Joined
Feb 22, 2013
Messages
574
Trophies
0
XP
706
Country
Canada
You sir, are awesome. Although I do have another DS, I sadly don't have another flashcart so I won't be able to use wireless. COuld I use yours? :P

However could it be possible that you could make it link to a PSP?(I doubt it but doesn't hurt to ask)
I don't have a PSP, so... probably not. I don't even know if the hacked libwifi would communicate with a PSP properly.

I only have one flashcart, but what I do is I start up the game on one ds, then I remove the cart and put it in my other ds. As long as the game isn't bigger than 2 megabytes it can run without accessing the filesystem. The only problem is that you can only save on one ds...
 

Foxhounder

Banned!
Banned
Joined
Jan 20, 2013
Messages
102
Trophies
0
Age
31
XP
19
Country
United States
I don't have a PSP, so... probably not. I don't even know if the hacked libwifi would communicate with a PSP properly.

I only have one flashcart, but what I do is I start up the game on one ds, then I remove the cart and put it in my other ds. As long as the game isn't bigger than 2 megabytes it can run without accessing the filesystem. The only problem is that you can only save on one ds...
that's awesome! so yellow/gold should be fine?(I know crystal wouldn't being a gbc game and all).
 

Deleted member 319809

MAH BOI/GURL
Member
Joined
Dec 22, 2012
Messages
900
Trophies
0
XP
461
Country
Canada
that's awesome! so yellow/gold should be fine?(I know crystal wouldn't being a gbc game and all).
Pokémon Crystal is 2 megabytes, so it would work. Only the ROM size counts for this comparison.

One of the games that wouldn't work if you took the card out is Yu-Gi-Oh! Dark Duel Stories, which is 4 megabytes.
 

Foxhounder

Banned!
Banned
Joined
Jan 20, 2013
Messages
102
Trophies
0
Age
31
XP
19
Country
United States
Pokémon Crystal is 2 megabytes, so it would work. Only the ROM size counts for this comparison.

One of the games that wouldn't work if you took the card out is Yu-Gi-Oh! Dark Duel Stories, which is 4 megabytes.
That's great news. And what of the Oracle series?

EIDT: I nevermind, checked myself.
 

Drenn

Well-Known Member
OP
Member
Joined
Feb 22, 2013
Messages
574
Trophies
0
XP
706
Country
Canada
I managed to get into the trading room. But the pokemon are reported incorrectly - I'm pretty sure I don't own a wartortle... or any 3trainerpokes, Pokemon Yellow's missingno. equivalent. I still can't initiate the trade, it just sits there forever. It's a strange coincidence though - my name would always give me a lot of wartortles on Cinnabar Island along with missingnos. Perhaps it read the characters of my name as pokemon...?
 
  • Like
Reactions: Coto

Kouen Hasuki

Coffee Addict
Member
Joined
Jan 9, 2013
Messages
1,387
Trophies
1
Age
40
Location
Behind you
XP
681
Country
Norway
I managed to get into the trading room. But the pokemon are reported incorrectly - I'm pretty sure I don't own a wartortle... or any 3trainerpokes, Pokemon Yellow's missingno. equivalent. I still can't initiate the trade, it just sits there forever. It's a strange coincidence though - my name would always give me a lot of wartortles on Cinnabar Island along with missingnos. Perhaps it read the characters of my name as pokemon...?
yup thats correct in a way

 

Coto

-
Member
Joined
Jun 4, 2010
Messages
2,979
Trophies
2
XP
2,565
Country
Chile
I managed to get into the trading room. But the pokemon are reported incorrectly - I'm pretty sure I don't own a wartortle... or any 3trainerpokes, Pokemon Yellow's missingno. equivalent. I still can't initiate the trade, it just sits there forever. It's a strange coincidence though - my name would always give me a lot of wartortles on Cinnabar Island along with missingnos. Perhaps it read the characters of my name as pokemon...?

http://bulbapedia.bulbagarden.net/wiki/Mew_glitch

hey drenn, i've been following this emu development silently, and i've starteed coding on asm not too long ago, gettings bits,flags,cpu registers,memory pointers,vertical blank, horizontal blank, etc stuff can be wearing, but I love machines, probably as much as both nebuleon and you do too. So i'll get into ARM ASM someday.

Well, if you check the table i've posted about mew glitch[under the ditto method], it says mew requires to have a special attack of 21 to get a "wild mew" before the trainer. So my guess is, under a certain register, (the one holding all pokemon dabatase-like data, captured by the "other trainer") is generated incorrectly, hence showing such pokemons while on wireless. I'm 99% sure pokemon statistics, pokemons hold by the trainer, stats, etc are calculated every time by a few values when you do a "change room" event.

So long story short, that wartortle to be shown requires the target pokemon/trainer to have his 1st pokemon with a special attack of 179 dec or B3 hex or 1011 0011. so if that value should be stored somewhere on a register [or it could be either calculated]

Have a nice day
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
  • SylverReZ @ SylverReZ:
    @Xdqwerty, It only shows that if you do 'View Source', right below that it'll tell you the SQL response query. I feel like a nerd lol.
  • SylverReZ @ SylverReZ:
    But for everyone, it said unexpected database error.
    +1
  • BigOnYa @ BigOnYa:
    Just said database error for me
    +2
  • Xdqwerty @ Xdqwerty:
    @BigOnYa, she said it only said "too many connections" when you view the source
    +1
  • Xdqwerty @ Xdqwerty:
    btw gonna try to actually beat touhou 6
    +1
  • SylverReZ @ SylverReZ:
    @Xdqwerty, Have fun.
    +1
  • Xdqwerty @ Xdqwerty:
    @SylverReZ, i recall playing some hard undertale fangames way before playing touhou, like the genocide asgore fangame or the mettaton neo 2.0 one
  • Xdqwerty @ Xdqwerty:
    so atleast im already kinda used to bullet hell games
  • Xdqwerty @ Xdqwerty:
    and yea i played both undertale and deltarune too although those are a piece of cake compared to any touhou game
  • Xdqwerty @ Xdqwerty:
    aaaaaaannnnnnd i already lost all my continues
  • Xdqwerty @ Xdqwerty:
    I only set three default lives btw
  • Xdqwerty @ Xdqwerty:
    cuz of score
  • Xdqwerty @ Xdqwerty:
    i think i first should focus more on beating the game rather than obtaining a high score
  • Xdqwerty @ Xdqwerty:
    good night
  • K3Nv2 @ K3Nv2:
    yawn
  • BigOnYa @ BigOnYa:
    -deleted-
  • K3Nv2 @ K3Nv2:
    Stop ctrl cing me
  • BigOnYa @ BigOnYa:
    Sorry, here ctrl-Z
  • K3Nv2 @ K3Nv2:
    Ctrl u 2 u
  • BigOnYa @ BigOnYa:
    Damn, that turned my tv channel, you got powers
  • K3Nv2 @ K3Nv2:
    The fbi will be knocking on your door soon
  • Psionic Roshambo @ Psionic Roshambo:
    They all went mad after looking at my browser history
  • BigOnYa @ BigOnYa:
    Why, cause beastiality is not legal in Florida yet?
  • K3Nv2 @ K3Nv2:
    @Psionic Roshambo, they rewrote the constitution when they saw your browser history
    K3Nv2 @ K3Nv2: @Psionic Roshambo, they rewrote the constitution when they saw your browser history