01-31-2010, 12:21 AM
These items do seem to be quite high on a few people's wish list. I hope they help!
Right now I only know how to use FASTCALL with a single parameter. If anyone knows how standard multi parameter calls work when we get into m/c please let me know. For the moment, these work and are pretty fast, even though AND and OR cheat a little.
Binary NOT (8 bit version)
USAGE: bNOT(byte value or ubyte value)
Binary NOT (16 bit version)
USAGE: bNOT(uInteger value)
How about this as a compromise: A NOT function that does an 8 bit not for any value that fits in 8 bits, a 16 bit NOT for any value that fits in 16 bits, and a 32 bit NOT for any larger value.
Binary AND (8 bit)
USAGE bAND (byte value1, byte value2)
NOTE: Yes, this is one function that calls another. It cheats by putting two 8 bit values into a 16 bit. It's definitely possible to have something better optimized, and if I learn how standard calls work, I'll use that.
In the meantime, this does work.
Binary OR (8 bit)
NOTE: This uses the same sneaky methods as bAND. I'm sure better code will turn up later.
USAGE bOR(byte value,byte value)
Right now I only know how to use FASTCALL with a single parameter. If anyone knows how standard multi parameter calls work when we get into m/c please let me know. For the moment, these work and are pretty fast, even though AND and OR cheat a little.
Binary NOT (8 bit version)
Code:
FUNCTION FASTCALL bNOT (sentIn as uByte) as uByte
asm
CPL
end asm
END FUNCTION
USAGE: bNOT(byte value or ubyte value)
Binary NOT (16 bit version)
Code:
FUNCTION FASTCALL bNOT (sentIn as uInteger) as uInteger
asm
LD a,h
CPL
ld h,a
ld a,l
CPL
ld l,a
end ASM
END FUNCTION
USAGE: bNOT(uInteger value)
How about this as a compromise: A NOT function that does an 8 bit not for any value that fits in 8 bits, a 16 bit NOT for any value that fits in 16 bits, and a 32 bit NOT for any larger value.
Code:
FUNCTION FASTCALL bNOT(sentIn as uLONG) as uLONG
asm
LD A,D
OR E
JR Z,word ; if DE = 0, assume it's NOT a long!
LD A, D
CPL
LD D, A
LD A,E
CPL
LD E,A
word:
LD A,H
AND A ; if H=0 assume it's not 16 bit.
JR Z, byte
CPL
LD H,A
byte:
LD A,L
CPL
LD L,A
END asm
END Function
Binary AND (8 bit)
Code:
FUNCTION bAND (byte1 as uByte, byte2 as uByte) as uByte
return bANDHL(byte1*256+byte2)
END function
FUNCTION FASTCALL bANDHL (HL as uInteger) as uByte
asm
LD a,h
AND l
end asm
END FUNCTION
USAGE bAND (byte value1, byte value2)
NOTE: Yes, this is one function that calls another. It cheats by putting two 8 bit values into a 16 bit. It's definitely possible to have something better optimized, and if I learn how standard calls work, I'll use that.
In the meantime, this does work.
Binary OR (8 bit)
NOTE: This uses the same sneaky methods as bAND. I'm sure better code will turn up later.
Code:
FUNCTION bOR (byte1 as uByte, byte2 as uByte) as uByte
return bORHL(byte1*256+byte2)
END function
FUNCTION FASTCALL bORHL (HL as uInteger) as uByte
asm
LD a,h
OR l
end asm
END FUNCTION