pokeb help

Programming, for all ages and all languages.
Post Reply
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

pokeb help

Post 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
Last edited by matias_beretta on Wed Dec 19, 2007 12:49 pm, edited 1 time in total.
Matías Beretta
SpooK
Member
Member
Posts: 260
Joined: Sun Jun 18, 2006 7:21 pm

Re: pokeb help

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

char far *
far pointers?! Are you by any chance using Turbo C?

(if so, use the MK_FP macro)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
matias_beretta
Member
Member
Posts: 101
Joined: Mon Feb 26, 2007 3:39 pm

reply

Post 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 |...
Matías Beretta
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
Post Reply