[Mybusinessbasic-devel] mybb utilities.c,1.4,1.5
Status: Alpha
Brought to you by:
mikecurry1974
|
From: <mik...@us...> - 2003-12-30 03:52:32
|
Update of /cvsroot/mybusinessbasic/mybb
In directory sc8-pr-cvs1:/tmp/cvs-serv16434
Modified Files:
utilities.c
Log Message:
Repaired
Index: utilities.c
===================================================================
RCS file: /cvsroot/mybusinessbasic/mybb/utilities.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** utilities.c 30 Dec 2003 02:31:41 -0000 1.4
--- utilities.c 30 Dec 2003 03:52:28 -0000 1.5
***************
*** 2,6 ****
* MyBB(r) - My Business Basic Interpreter *
* ------------------------------------------------------------------- *
! * Program: utilities.c *
************************************************************************/
--- 2,6 ----
* MyBB(r) - My Business Basic Interpreter *
* ------------------------------------------------------------------- *
! * Program: utilities.c *
************************************************************************/
***************
*** 137,146 ****
short BigShort(short l)
{
- /* byte flip for a word... no need for temp variables in asm */
- __asm("mov ax,word [l]"); /* so store word in a register */
- __asm("xchg al,ah"); /* swap the bytes in that register */
- __asm("retn"); /* return that register */
-
- /*
byte b1, b2;
--- 137,140 ----
***************
*** 149,153 ****
return (b1 << 8) + b2;
- */
}
--- 143,146 ----
***************
*** 168,179 ****
long BigLong(long l)
{
- /* byte flip for a dword... if we had 486 for sure we could use BSWAP, but this works on 386 too (though is a bit slower) */
- __asm("mov eax,dword [l]");
- __asm("xchg al,ah"); /* byte flip for low word */
- __asm("ror eax,0x10"); /* word flip for a dword */
- __asm("xchg al,ah"); /* byte flip for high word (whichs now low) */
- __asm("retn");
-
- /*
byte b1, b2, b3, b4;
--- 161,164 ----
***************
*** 184,188 ****
return ((long)b1 << 24) + ((long)b2 << 16) + ((long)b3 << 8) + b4;
- */
}
--- 169,172 ----
***************
*** 203,211 ****
float BigFloat(float l)
{
- /* i'd recomed using
- tmp = (float)BigLong((long)l);
- instead, it does the same thing... and we don't want to waste memory too
- casting takes no execution, it just tells the compiler not to raise an error
- */
union {
byte b[4];
--- 187,190 ----
***************
*** 224,243 ****
char *strLeft(char *str,int n)
{
- /* now hope i got this right; i'm not very failiar with the functions */
- char tmp[n+1]; /* this should alloc n+1 bytes */
- __asm("mov esi,dword [str]");
- __asm("lea edi,[tmp]");
- __asm("push edi"); /* trick: store ptr so we don't hafta recalculate it*/
- __asm("xor ecx,ecx") /* define n as long to get rid of this. note that you hafta also alter the next line*/
- __asm("mov cx,word [n]");
- __asm("cld");
- __asm("rep");
- __asm("movsb"); /* string copy */
- __asm("xor al,al");
- __asm("stosb") /* insert zero terminator */
- __asm("pop eax");
- __asm("retn"); /* return ptr */
-
- /*
char *tmp;
tmp = strdup(str);
--- 203,206 ----
***************
*** 245,249 ****
return tmp;
- */
}
--- 208,211 ----
***************
*** 318,344 ****
int itoh(byte num, char *pt)
{
- /* this one's much faster in asm */
- __asm("mov edi,dword [pt]");
- __asm("mov al,byte [num]");
- __asm("push ax"); /* store num or second round */
- __asm("shr al,0x04"); /* take high nibble */
- __asm("call near itoh_3"); /* use our subfunction located below */
- __asm("pop ax") /* reget num */
- __asm("and al,0x0F"); /* take low nibble */
- __asm("call near itoh_3"); /* use our subfunction located below */
- __asm("xor ax,ax");
- __asm("retn"); /* return zero word */
-
- /* this one is a function that converts low nibble in al to hex stores it with stosb
- does look weird if you don't know assembly */
- __asm("itoh_3: cmp al,0x0A");
- __asm("jnc itoh_1");
- __asm("add al,0x30"); /* add either 0x30... */
- __asm("jmp itoh_2");
- __asm("itoh_1: add al,0x37"); /* ...or 0x37 */
- __asm("itoh_2: stosb"); /* store character */
- __asm("retn"); /* get back */
-
- /*
unsigned char nm[2];
--- 280,283 ----
***************
*** 373,377 ****
*(pt+1)=(char)nm[1];
return(0);
- */
}
--- 312,315 ----
***************
*** 993,1007 ****
void *SafeMalloc(long size)
{
- /* you can optimize even simple code like this */
- __asm("push dword [size]");
- __asm("call near malloc"); /* call normally, NOTE: this is a stdcall, may bug on other call systems */
- __asm("or eax,0x00000000");
- __asm("jz SafeMalloc_1"); /* if we got zero */
- __asm("retn");
- __asm("SafeMalloc_1: push dword ERR_MEMORY_CAPACITY");
- __asm("leave");
- __asm("jmp rterror"); /* skip double retn, NOTE: not 100% sure about this - i should test it, it depends how compiler assembles a function frame */
-
- /*
void *ptr;
--- 931,934 ----
***************
*** 1012,1016 ****
return ptr;
- */
}
--- 939,942 ----
|