Skip to content
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

Use hardware.inc from gbdev #914

Open
vulcandth opened this issue May 1, 2022 · 13 comments
Open

Use hardware.inc from gbdev #914

vulcandth opened this issue May 1, 2022 · 13 comments
Labels

Comments

@vulcandth
Copy link
Collaborator

@ISSOtm mentioned this on discord today, that we should be using hardware.inc from https://github.com/gbdev/hardware.inc/blob/master/hardware.inc. Looking at the discord history, It sems this was discussed in the past, but I didn't see a clear definitive reason why or why not use it. A couple points on why not seemed to do with extra "noise", that it might be based on MBC5, and how pokecrystal uses more constants related to individual bits.

Anyways, I'm going to let you all who have more experience weigh in on this. I'm just opening this to start a discussion. If we decide to take action with this, i'll help out.

@mid-kid
Copy link
Member

mid-kid commented May 1, 2022

IIRC one of the issues was that it doesn't have all the defines that we need, but if we need them, then they're likely very useful to other projects as well, so we should be contributing them upstream as well. Until then it's fine to have a modified hardware.inc in this repository.

Other than that it's just porting busywork.

@vulcandth
Copy link
Collaborator Author

Would it be hard to use hardware.inc and then define new pret constants in a separate file? Although I agree, it could just be busy work.

@aaaaaa123456789
Copy link
Contributor

I've always been a strong advocate of just taking whatever you need from hardware.inc instead of polluting your namespace with lots of constants you have no intentions of using. After all, hardware.inc describes hardware that has been out of manufacturing for over 20 years; there's no chance for that hardware to change, so keeping "up to date" with changes upstream is irrelevant here.
While it would be a very bad idea to use hardware.inc's constant names for other things, I don't see the harm in leaving most of them out.

And yes, the focus on MBC5 is problematic. I have no idea of why hardware.inc makes this choice, as not even all homebrew uses MBC5. But it does, and it would collide with the MBC3+RTC cart that Pokémon Crystal uses.

@ISSOtm
Copy link
Contributor

ISSOtm commented May 2, 2022

The advantages are not much, but still exist:

  • Consistency with other projects enable easier code reuse (especially across wikis and forum posts). Many constants for the same things have different names.
  • Given that it's relied on by many other projects, it will stay up to date with breaking updates to RGBDS without needing extra attention—simply a matter of reducing the code yall are directly responsible of. This is what "keeping up-to-date" I was arguing in favor of.
  • Conversely, constants (such as the bit constants mentioned in the OP) used in pokecrystal but not currently in hardware.inc are likely to be useful to other projects as well, so the cooperation goes both ways. (I realize after typing this that this is actually exactly's mid-kid's comment, oops.)

I'm not sure what focus hardware.inc might be having? Grepping -i for MBC5 yields the cartridge types (which are obviously legitimate), and a single comment, which is technically not wrong but can be changed if you really really want.

@aaaaaa123456789
Copy link
Contributor

Keeping up to date with RGBDS is part of what I'm worried about — pokecrystal occasionally lags behind, so it's better to update those definitions along with everything else. The effort is minimal and we ensure that we can always build the repo with a single version of the toolchain. (This is not much of a concern as long as pokecrystal is part of RGBDS's CI, but we're talking about minor differences here.)

The MBC5 constants (the ones under that comment) are simply incorrect for other cart types. $3000 maps to the ROM bank, not to the "ROM bank upper byte", for instance. (And it makes no sense to speak of a "byte 0" when there's only one byte.)

What differences in constants can you find?

@mid-kid
Copy link
Member

mid-kid commented May 10, 2022

Keeping up to date with RGBDS is part of what I'm worried about — pokecrystal occasionally lags behind, so it's better to update those definitions along with everything else.

This is a non-issue. The file would be copied and checked into this repository. Even if the repository were to be a submodule (it won't), the version would be pinned.

Most of the benefit is in following community standards and contributing to how the hardware definitions are specified, as well as making it easier for users to use additional hardware that we haven't even considered adding to hardware_constants.inc (for example, MBCs), or future clarifications of or additions to the constants.

@aaaaaa123456789
Copy link
Contributor

aaaaaa123456789 commented May 10, 2022

Most of the benefit is in following community standards and contributing to how the hardware definitions are specified...

Don't we already follow standards in everything but MBC registers (where we can't, because hardware.inc doesn't implement MBC3)?

...as well as making it easier for users to use additional hardware that we haven't even considered adding to hardware_constants.inc (for example, MBCs)...

hardware.inc doesn't support anything but MBC5, and what other additional hardware are you referring to?

...or future clarifications of or additions to the constants.

I don't see much changing when we're talking about a device that has been out of manufacturing for 20 years.

If we're going to take a snapshot of the file and check it in, what's there to gain with respect to what we already have, which is essentially a snapshot with the constants we use?

@mid-kid
Copy link
Member

mid-kid commented May 10, 2022

Don't we already follow standards in everything but MBC registers

We don't

what other additional hardware are you referring to?

GB hardware and bit definitions that the game doesn't use.

what's there to gain with respect to what we already have

Keeping things in sync. If we were already using all the same constants it'd be a drop-in. It isn't.

@aaaaaa123456789
Copy link
Contributor

I think a step we can agree on is to rename our constants to match hardware.inc's names, then?

@mid-kid
Copy link
Member

mid-kid commented May 10, 2022

Yes. Although there's no reason not to use and contribute to hardware.inc at that point. Polluting the namespace with definitions relating to common gameboy hardware simply isn't a concern, and the MBC5-specific definitions can be ignored.

@ISSOtm
Copy link
Contributor

ISSOtm commented May 10, 2022

And, as I've asked in my previous post, how does hardware.inc "only" support MBC5? It does not have anything MBC-specific.

@rawr51919
Copy link
Contributor

rawr51919 commented Jun 15, 2022

Draft PR exists that has a proof-of-concept working compile and matching builds using latest RGBDS master as well as RGBDS v0.5.2 (#943)

@rawr51919
Copy link
Contributor

Said hardware.inc PR will also need companions across the whole of pret, updating their builds to use the latest hardware.inc if they use it already and refactoring them to use hardware.inc if they don't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants