Jose's Read Only Forum 2023

IT-Consultant: Charles Pegge => OxygenBasic => Topic started by: Chris Chancellor on November 09, 2018, 06:10:26 AM

Title: Equivalent of PB HI() and LO() functions
Post by: Chris Chancellor on November 09, 2018, 06:10:26 AM
Hello Charles

in PB they have  HI() and LO() functions  , what would be the equivalent functions in O2 ?

for the HI()  function, you can refer to  http://www.manmrk.net/tutorials/basic/PowerBASIC/PBW10/html/HI_function.html (http://www.manmrk.net/tutorials/basic/PowerBASIC/PBW10/html/HI_function.html)

and the LO() function ,  http://www.manmrk.net/tutorials/basic/PowerBASIC/PBW10/html/LO_function.html (http://www.manmrk.net/tutorials/basic/PowerBASIC/PBW10/html/LO_function.html)

i have converted  PB
HI(WORD,lparam)   

  successfully to  O2
HIWORD(lparam) 


but i'm not sure about  converting  PB 
HI(Integer, wparam)

as there is no equivalent in C++  literature in the internet.

hope that you can give some advice on this

Thanxx








Title: Re: Equivalent of PB HI() and LO() functions
Post by: Charles Pegge on November 09, 2018, 03:56:54 PM
Hi Chris,

We already have some defined as core macros:


def lobyte ((%1) and 0xff)
def loword ((%1) and 0xffff)
def hibyte (((%1)>>8) and 0xff)
def hiword (((%1)>>16) and 0xffff)


I think hi(..) lo(..) is not advantageous.
Title: Re: Equivalent of PB HI() and LO() functions
Post by: Chris Chancellor on November 09, 2018, 04:30:18 PM
Thanxx a lot Charles

what is the name of the include file which contains these macros ?
so that i can use it

also,

does  HIbyte(wparam)     is  equivalent to  HI(Integer, wparam)  ?
Title: Re: Equivalent of PB HI() and LO() functions
Post by: Charles Pegge on November 09, 2018, 05:48:29 PM
They are already available.

All the core language definitions were in source-file: o2keyw.bas, but will be in lang.inc.

hi(int,wParam) doesn't quite make sense to me - since it is dual-platform.

However, if you wanted the upper/lower bits of a 64bit:

def HiDword(((%1)>>32) and 0xffffffff)

def LoDword((%1) and 0xffffffff)


You can invent others :)

Title: Re: Equivalent of PB HI() and LO() functions
Post by: Patrice Terrier on November 09, 2018, 07:18:31 PM
I would recommend to use INT rather than DWORD, especially if you are dealing with mouse coordinates, or window locations that could be negative.

#define LOINT(a) ((SHORT)(a))
#define HIINT(a) ((SHORT)(((DWORD)(a) >> 16) & 0xFFFF))
Title: Re: Equivalent of PB HI() and LO() functions
Post by: Charles Pegge on November 09, 2018, 07:44:58 PM
Hi Patrice,

Fortunately, these o2 macros do not interfere with the type-cast or the sign bits, so it would be safe to use them on any type of integer.
Title: Re: Equivalent of PB HI() and LO() functions
Post by: Chris Chancellor on November 10, 2018, 06:32:40 AM
Thanxx a lot Charles and Patrice
Title: Re: Equivalent of PB HI() and LO() functions
Post by: Brian Alvarez on November 19, 2018, 07:34:42 PM
I need to emulate HIINT, how can i cast it?

def hiint(((%1)>>32) and 0xffffffff) ' doesnt work
print str(hiint(221134)) ' returns 2221134
Title: Re: Equivalent of PB HI() and LO() functions
Post by: Charles Pegge on November 20, 2018, 01:19:28 PM
Hi Brian,

Yes, I see the 32bit shift does not work in 32bit mode

This will work in 64bit mode, but you have to use a quad variable, not a number.


$filename "c.exe"
uses ..\rtl64
def hiint((%1)>>32)
quad a,b
a=0x12345678*0x100
b=hiint(a)
print hex b '12


But this method avoids the bit-shifting problem, and will work on both platforms:


function hiint(quad*q) as int
=============================
int i at @q+4
return i
end function

quad a=0x12345678*0x100
print hex hiint a '12

Title: Re: Equivalent of PB HI() and LO() functions
Post by: Brian Alvarez on November 20, 2018, 11:53:25 PM
perfect! thanks Charles. :)
Title: Re: Equivalent of PB HI() and LO() functions
Post by: Chris Chancellor on November 22, 2018, 03:13:55 AM
Thanxx a lot Charles