Pages: 1
Author Topic: Access to variables  (19,227 Views)
Offline (Unknown gender) FroggestSpirit

Member
Joined: Mar 2013
Posts: 79
View profile
Posted on: March 02, 2015, 08:54:58 PM
In making a GameBoy emulator, I want to know if possible how to access 2 char variables as one?
I have registers a,b,c,d,e,f,h,l. They are all unsigned chars right now, but they can be paired up to form af, bc, de, and hl.
Those 4 pairs would need to be accessed as an unsigned short, where reading/writing to them would write to the individuals accordingly.
For example, if I ran the code bc=$3589, then b should be $35 and c should be $89. similarly, reading from bc should return $3589 (or the dec value of that).
This won't be necessary to get things going, but it would be nice for optimization.
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #1 Posted on: March 02, 2015, 10:27:55 PM
That would involve binary operations. Operation like "bc=$3589" changing both "b" and "c" is not possible in EDL. You can do that in C++ using unions. You could make a function bc($3589) inside of which you would set b and c. Like this works for me in ENIGMA:
Code (edl) Select

unsigned char b[2];
b[0] = ($3589 & $FF00) >> 8;
b[1] = ($3589 & $00FF);
draw_text(10,10,b[0]);
draw_text(10,30,b[1]);

Where b[0] will print 53 which is decimal for 0x35 and b[1] will print 137 which is decimal for 0x89.
Pages: 1