am I understanding the pragmas correctly?
#pragma bss-name(push, "ZEROPAGE")
#pragma data-name(push,"ZEROPAGE")
//put global zeropage variables here
#pragma bss-name (push,"BSS")
#pragma data-name(push,"BSS")
//not in zeropage here
and does data-name mean you put tables in zeropage?
does this do anything?
/*{pal:"nes",layout:"nes"}*/
or just a comment?
and most important, how do you create a two byte variable and reference the bytes individually?
do you create an int and use masks?
if you add to an int will it add to the first byte
and if it rolls over add 1 to the second byte?
I want to do gravity and smooth speed up and slow down
something like this
int player0x
player0x += 128 //would add one to the second byte every other frame?
then use the second byte as player0x position??
Lots of questions
Moderator: Moderators
Re: Lots of questions
The data segment, in C, is for BSS variables that aren't initialized to zero.
https://www.geeksforgeeks.org/memory-la ... c-program/
int var;
(char) var
will get the low byte. however, you can't cast an lvalue like this, I don't think.
*((unsigned char*)&var)
will do the same, by casting to a char pointer, and then dereferencing
*((unsigned char*)&var+1)
will get the high byte, by casting to a char pointer, adding 1 to that address, and dereferencing
here's the macros I use
#define high_byte(a) *((unsigned char*)&a+1)
#define low_byte(a) *((unsigned char*)&a)
note, these are compile time, aka preprocessor macros. The compiler will convert this into very short neat asm code.
https://www.geeksforgeeks.org/memory-la ... c-program/
Declare the variable as an int or unsigned int. Then use casting to access individual bytes, which you can hide with clever use of macros.how do you create a two byte variable and reference the bytes individually?
int var;
(char) var
will get the low byte. however, you can't cast an lvalue like this, I don't think.
*((unsigned char*)&var)
will do the same, by casting to a char pointer, and then dereferencing
*((unsigned char*)&var+1)
will get the high byte, by casting to a char pointer, adding 1 to that address, and dereferencing
here's the macros I use
#define high_byte(a) *((unsigned char*)&a+1)
#define low_byte(a) *((unsigned char*)&a)
note, these are compile time, aka preprocessor macros. The compiler will convert this into very short neat asm code.
nesdoug.com -- blog/tutorial on programming for the NES
-
- Posts: 20
- Joined: Sat Jul 04, 2020 5:27 pm
Re: Lots of questions
Thanks!!! That's very neat, and works exactly like I wanted!!
-
- Posts: 20
- Joined: Sat Jul 04, 2020 5:27 pm
Re: Lots of questions
How do you use bits?
I started with this
unsigned char flags;
const unsigned char jumpRestrainer = 1 << 0; // 0000 0001
const unsigned char jumping = 1 << 1; // 0000 0010
const unsigned char leftSlide = 1 << 2; // 0000 0100
const unsigned char rightSlide = 1 << 3; // 0000 1000
const unsigned char mask4= 1 << 4 ; // 0001 0000
const unsigned char mask5= 1 << 5 ; // 0010 0000
const unsigned char mask6= 1 << 6 ; // 0100 0000
const unsigned char mask7= 1 << 7 ; // 1000 0000
It worked but it was alot of assembly when I checked
so tried doing it like how the controller is read
#define jumpRestrainer 0x80
#define jumping 0x40
#define leftSlide 0x20
#define rightSlide 0x10
#define mask4 0x08
#define mask5 0x04
#define mask6 0x02
#define mask7 0x01
but didn't work, this is how I use them
#define ON |=
#define OFF &= ~
#define FLIP ^=
flags OFF jumping;
flags ON jumpRestrainer;
if (!flags & jumpRestrainer)
if (flags & jumping)
I started with this
unsigned char flags;
const unsigned char jumpRestrainer = 1 << 0; // 0000 0001
const unsigned char jumping = 1 << 1; // 0000 0010
const unsigned char leftSlide = 1 << 2; // 0000 0100
const unsigned char rightSlide = 1 << 3; // 0000 1000
const unsigned char mask4= 1 << 4 ; // 0001 0000
const unsigned char mask5= 1 << 5 ; // 0010 0000
const unsigned char mask6= 1 << 6 ; // 0100 0000
const unsigned char mask7= 1 << 7 ; // 1000 0000
It worked but it was alot of assembly when I checked
so tried doing it like how the controller is read
#define jumpRestrainer 0x80
#define jumping 0x40
#define leftSlide 0x20
#define rightSlide 0x10
#define mask4 0x08
#define mask5 0x04
#define mask6 0x02
#define mask7 0x01
but didn't work, this is how I use them
#define ON |=
#define OFF &= ~
#define FLIP ^=
flags OFF jumping;
flags ON jumpRestrainer;
if (!flags & jumpRestrainer)
if (flags & jumping)