Page 1 of 1
pokeb help
Posted: Tue Dec 18, 2007 5:36 pm
by matias_beretta
Hello, i'm trying to make a pokeb procedure without using inline assembly:
Code: Select all
void pokeb(unsigned segment, unsigned offset, char value)
{
char far *ptr;
ptr = (char far *)(segment * 16 + offset);
*ptr = value;
}
but this isn't working and i can't work out a solution
Re: pokeb help
Posted: Tue Dec 18, 2007 10:48 pm
by SpooK
matias_beretta wrote:Hello, i'm trying to make a pokeb procedure without using inline assembly:
void pokeb(unsigned segment, unsigned offset, char value)
{
char far *ptr;
ptr = (char far *)(segment * 16 + offset);
*ptr = value;
}
but this isn't working and i can't work out a solution
Perhaps just "ptr = value" or maybe even "ptr[0] = value" since
ptr is already casted as a pointer?
Posted: Wed Dec 19, 2007 2:46 am
by Combuster
char far *
far pointers?! Are you by any chance using Turbo C?
(if so, use the MK_FP macro)
reply
Posted: Wed Dec 19, 2007 7:15 am
by matias_beretta
I'm using Turbo C++ 3.0, and i know it has pokeb and mk_fp. but i want to make my own includes.
I tested using ptr[0] or ptr instead of *ptr but it doesn't work...
I've seen that many people use: ptr = (char far *)(segment << 16) | offset);
but i don't understand why they use << 16 (to multiply the segment by 16 its possible to use segment << 4) and i don't understand why the use |...
Posted: Wed Dec 19, 2007 4:51 pm
by Combuster
I don't have TC3 installed anymore, so I can't check. But it seems that if you cast a 32-bit int into a far pointer it will split it for you into a seg:off pair (2x16 bits = 32 bits)
Nevertheless, pokeb, MK_FP etc, are TC-specific macros (and are portable), so there's no need to reinvent the wheel when its given to you on a silver plate.