kyuusaku wrote:
That's what comments are for; you could explain what's going on with shorter mnemonics in even less space than your definitions and it doesn't require a preprocessor.
In my current example my preprocessors are long because I like them to be verbose enough but it's a little bit extreme, I do agree about that. I'm still trying to find names that are verbose enough but shorter, I didn't find the perfect ones yet.
Comments, it depends how you look at it. If I write a comment for:
Code:
lda %10011001 ; Set NMI, pattern table 1 for background and increment 32
ok, I have a comment but how much can I trust that comment (like Tepple said)? And which flag is which? If I ask someone else to edit that code and he doesn't know about the flags, how much chance does he have to put one flag by accident? If you program alone, you may get away with it but when you program with a group of people that may have a different level of experience, every little things like this that can make you save time later are important.
By using those constants, you don't need to know that bit 7 is for NMI, you just want to set the NMI flag. Once that constant is defined, you don't have to worry about it anymore. Don't you agree?
And if you could have an editor that would have some auto-completion functionality for your constants, you don't even have to remember them.
Celius wrote:
For some reason, I just have never used things like these. Though it's a good idea I start, because I'm always going back and forth between docs for registers to see which bit is which. Though I'd hate to look at a long line like that in front of LDA.
Yes, they are long. I want to make them smaller but still clear. But how many time do you change all 8 flags in one shot? Maybe not often. So the code become more self documented that way when another programmer uses it.
tepples wrote:
I guess my preference for register names just comes from my GBA background, where there are about an order of magnitude more PPU registers, some of them organized into arrays of registers.
My background is not GBA but from C based languages and this is what I was trying to do.
I like your constants, they are simple. I almost based mine on yours (I think you were using them in Tetramino, am I correct?) but I just wanted to make then more verbose.
I'm sure that BG_ON could be verbose enough but if I'm a new programmer, BG_ON for what? That's why I put PPU_CTRL_BG_ON in front of it. Maybe I'm overdoing it, quite possible, I'm just trying to find a way that I'm comfortable with.
But one of my goal is to define some constants that could be useful for beginners. This kind of information is useful and often lacking when you start to program and I would have loved to have them when I started. I hope I can find a way to make them more "user friendly" and contribute them back to the community.
But I'm still learning how to program for the 6502 so I'm testing all kind of possibilities and try to find out which one works best for me.
Roth wrote:
Man, this is the kind of thing that can change the way I code haha I might have to ease myself into it so I don't get carried away : P
Do get carried away
This is how you will learn what works best for you. If you don't like it after, you just drop it and try something new. At least you will know how much it brought to your project and made you think differently on how to approach your code.