1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-07-02 03:50:36 +00:00

Move all executable code out of common.cpp; rename to common.h

This commit is contained in:
Luke Ceddia 2018-01-05 21:22:36 +11:00
parent adeda29619
commit 3a0e1ae320
5 changed files with 164 additions and 187 deletions

View file

@ -132,33 +132,6 @@ struct qbs{
qbs_field *field;
};
//substitute functionality
#ifdef QB64_WINDOWS
inline void SDL_Delay(uint32 milliseconds){//redefine SDL_Delay to call Sleep
Sleep(milliseconds);
}
#else
inline void SDL_Delay(uint32 milliseconds){//redefine SDL_Delay to call Sleep
static uint64 sec,nsec;
sec=milliseconds/1000;
nsec=(milliseconds%1000)*1000000;
static timespec ts;
ts.tv_sec = sec;
ts.tv_nsec = nsec;
nanosleep (&ts, NULL);
}
inline void Sleep(uint32 milliseconds){
SDL_Delay(milliseconds);
}
inline uint32 _lrotl(uint32 word,uint32 shift){
return (word << shift) | (word >> (32 - shift));
}
inline void ZeroMemory(void *ptr,int64 bytes){
memset(ptr,0,bytes);
}
#endif
struct img_struct{
void *lock_offset;
int64 lock_id;
@ -205,125 +178,6 @@ struct img_struct{
#define IMG_SCREEN 2 //img is linked to other screen pages
#define IMG_FREEMEM 4 //if set, it means memory must be freed
#ifdef QB64_NOT_X86
inline int64 qbr(long double f){
int64 i; int temp=0;
if (f>9223372036854775807) {temp=1;f=f-9223372036854775808u;} //if it's too large for a signed int64, make it an unsigned int64 and return that value if possible.
if (f<0) i=f-0.5f; else i=f+0.5f;
if (temp) return i|0x8000000000000000;//+9223372036854775808;
return i;
}
inline uint64 qbr_longdouble_to_uint64(long double f){if (f<0) return(f-0.5f); else return(f+0.5f);}
inline int32 qbr_float_to_long(float f){if (f<0) return(f-0.5f); else return(f+0.5f);}
inline int32 qbr_double_to_long(double f){if (f<0) return(f-0.5f); else return(f+0.5f);}
#else
//QBASIC compatible rounding via FPU:
#ifdef QB64_MICROSOFT
inline int64 qbr(long double f){
int64 i; int temp=0;
if (f>9223372036854775807) {temp=1;f=f-9223372036854775808u;} //if it's too large for a signed int64, make it an unsigned int64 and return that value if possible.
__asm{
fld f
fistp i
}
if (temp) return i|0x8000000000000000;//+9223372036854775808;
return i;
}
inline uint64 qbr_longdouble_to_uint64(long double f){
uint64 i;
__asm{
fld f
fistp i
}
return i;
}
inline int32 qbr_float_to_long(float f){
int32 i;
__asm{
fld f
fistp i
}
return i;
}
inline int32 qbr_double_to_long(double f){
int32 i;
__asm{
fld f
fistp i
}
return i;
}
#else
//FLDS=load single
//FLDL=load double
//FLDT=load long double
inline int64 qbr(long double f){
int64 i; int temp=0;
if (f>9223372036854775807) {temp=1;f=f-9223372036854775808u;} //if it's too large for a signed int64, make it an unsigned int64 and return that value if possible.
__asm__ (
"fldt %1;"
"fistpll %0;"
:"=m" (i)
:"m" (f)
);
if (temp) return i|0x8000000000000000;// if it's an unsigned int64, manually set the bit flag
return i;
}
inline uint64 qbr_longdouble_to_uint64(long double f){
uint64 i;
__asm__ (
"fldt %1;"
"fistpll %0;"
:"=m" (i)
:"m" (f)
);
return i;
}
inline int32 qbr_float_to_long(float f){
int32 i;
__asm__ (
"flds %1;"
"fistpl %0;"
:"=m" (i)
:"m" (f)
);
return i;
}
inline int32 qbr_double_to_long(double f){
int32 i;
__asm__ (
"fldl %1;"
"fistpl %0;"
:"=m" (i)
:"m" (f)
);
return i;
}
#endif
#endif //x86 support
//bit-array access functions (note: used to be included through 'bit.cpp')
static int64 bmask;
static uint64 *bptr64;
static int64 bval64;
inline uint64 getubits(uint32 bsize,uint8 *base,ptrszint i){
bmask=~(-(((int64)1)<<bsize));
i*=bsize;
return ((*(uint64*)(base+(i>>3)))>>(i&7))&bmask;
}
inline int64 getbits(uint32 bsize,uint8 *base,ptrszint i){
bmask=~(-(((int64)1)<<bsize));
i*=bsize;
bval64=((*(uint64*)(base+(i>>3)))>>(i&7))&bmask;
if (bval64&(((int64)1)<<(bsize-1))) return bval64|(~bmask);
return bval64;
}
inline void setbits(uint32 bsize,uint8 *base,ptrszint i,int64 val){
bmask=(((uint64)1)<<bsize)-1;
i*=bsize;
bptr64=(uint64*)(base+(i>>3));
*bptr64=(*bptr64&( ( (bmask<<(i&7)) ^-1) )) | ((val&bmask)<<(i&7));
}
//QB64 internal variable type flags (internally referenced by some C functions)
#define ISSTRING 1073741824
@ -409,17 +263,6 @@ struct device_struct{
#define DEVICETYPE_KEYBOARD 2
#define DEVICETYPE_MOUSE 3
struct mem_block{
ptrszint offset;
ptrszint size;

View file

@ -1,4 +1,4 @@
#include "common.cpp"
#include "common.h"
#include "libqb.h"
#ifdef QB64_GUI
@ -34,6 +34,147 @@
int32 disableEvents=0;
//This next block used to be in common.cpp; put here until I can find a better
//place for it (LC, 2018-01-05)
#ifndef QB64_WINDOWS
void Sleep(uint32 milliseconds){
static uint64 sec,nsec;
sec=milliseconds/1000;
nsec=(milliseconds%1000)*1000000;
static timespec ts;
ts.tv_sec = sec;
ts.tv_nsec = nsec;
nanosleep (&ts, NULL);
}
uint32 _lrotl(uint32 word,uint32 shift){
return (word << shift) | (word >> (32 - shift));
}
void ZeroMemory(void *ptr,int64 bytes){
memset(ptr,0,bytes);
}
#endif
#ifdef QB64_NOT_X86
int64 qbr(long double f){
int64 i; int temp=0;
if (f>9223372036854775807) {temp=1;f=f-9223372036854775808u;} //if it's too large for a signed int64, make it an unsigned int64 and return that value if possible.
if (f<0) i=f-0.5f; else i=f+0.5f;
if (temp) return i|0x8000000000000000;//+9223372036854775808;
return i;
}
uint64 qbr_longdouble_to_uint64(long double f){if (f<0) return(f-0.5f); else return(f+0.5f);}
int32 qbr_float_to_long(float f){if (f<0) return(f-0.5f); else return(f+0.5f);}
int32 qbr_double_to_long(double f){if (f<0) return(f-0.5f); else return(f+0.5f);}
#else
//QBASIC compatible rounding via FPU:
#ifdef QB64_MICROSOFT
int64 qbr(long double f){
int64 i; int temp=0;
if (f>9223372036854775807) {temp=1;f=f-9223372036854775808u;} //if it's too large for a signed int64, make it an unsigned int64 and return that value if possible.
__asm{
fld f
fistp i
}
if (temp) return i|0x8000000000000000;//+9223372036854775808;
return i;
}
uint64 qbr_longdouble_to_uint64(long double f){
uint64 i;
__asm{
fld f
fistp i
}
return i;
}
int32 qbr_float_to_long(float f){
int32 i;
__asm{
fld f
fistp i
}
return i;
}
int32 qbr_double_to_long(double f){
int32 i;
__asm{
fld f
fistp i
}
return i;
}
#else
//FLDS=load single
//FLDL=load double
//FLDT=load long double
int64 qbr(long double f){
int64 i; int temp=0;
if (f>9223372036854775807) {temp=1;f=f-9223372036854775808u;} //if it's too large for a signed int64, make it an unsigned int64 and return that value if possible.
__asm__ (
"fldt %1;"
"fistpll %0;"
:"=m" (i)
:"m" (f)
);
if (temp) return i|0x8000000000000000;// if it's an unsigned int64, manually set the bit flag
return i;
}
uint64 qbr_longdouble_to_uint64(long double f){
uint64 i;
__asm__ (
"fldt %1;"
"fistpll %0;"
:"=m" (i)
:"m" (f)
);
return i;
}
int32 qbr_float_to_long(float f){
int32 i;
__asm__ (
"flds %1;"
"fistpl %0;"
:"=m" (i)
:"m" (f)
);
return i;
}
int32 qbr_double_to_long(double f){
int32 i;
__asm__ (
"fldl %1;"
"fistpl %0;"
:"=m" (i)
:"m" (f)
);
return i;
}
#endif
#endif //x86 support
//bit-array access functions (note: used to be included through 'bit.cpp')
uint64 getubits(uint32 bsize,uint8 *base,ptrszint i){
int64 bmask;
bmask=~(-(((int64)1)<<bsize));
i*=bsize;
return ((*(uint64*)(base+(i>>3)))>>(i&7))&bmask;
}
int64 getbits(uint32 bsize,uint8 *base,ptrszint i){
int64 bmask, bval64;
bmask=~(-(((int64)1)<<bsize));
i*=bsize;
bval64=((*(uint64*)(base+(i>>3)))>>(i&7))&bmask;
if (bval64&(((int64)1)<<(bsize-1))) return bval64|(~bmask);
return bval64;
}
void setbits(uint32 bsize,uint8 *base,ptrszint i,int64 val){
int64 bmask;
uint64 *bptr64;
bmask=(((uint64)1)<<bsize)-1;
i*=bsize;
bptr64=(uint64*)(base+(i>>3));
*bptr64=(*bptr64&( ( (bmask<<(i&7)) ^-1) )) | ((val&bmask)<<(i&7));
}
#ifdef QB64_LINUX
#include <pthread.h>
@ -8219,6 +8360,7 @@ qbs *f2string(long double v){ static qbs *tqbs; tqbs=qbs_new(32,1); memset(tqbs-
qbs *bit2string(uint32 bsize,int64 v){
static qbs* tqbs;
tqbs=qbs_new(8,1);
int64 bmask;
bmask=~(-(((int64)1)<<bsize));
*((int64*)(tqbs->chr))=v&bmask;
tqbs->len=(bsize+7)>>3;
@ -8226,7 +8368,7 @@ qbs *bit2string(uint32 bsize,int64 v){
}
qbs *ubit2string(uint32 bsize,uint64 v){
static qbs* tqbs;
int64 bmask;
tqbs=qbs_new(8,1);
bmask=~(-(((int64)1)<<bsize));
*((uint64*)(tqbs->chr))=v&bmask;
@ -8246,11 +8388,13 @@ float string2s(qbs*str){ if (str->len<4) {error(5); return 0;} else {return *((f
double string2d(qbs*str){ if (str->len<8) {error(5); return 0;} else {return *((double*)str->chr);} }
long double string2f(qbs*str){ if (str->len<32) {error(5); return 0;} else {return *((long double*)str->chr);} }
uint64 string2ubit(qbs*str,uint32 bsize){
int64 bmask;
if (str->len<((bsize+7)>>3)) {error(5); return 0;}
bmask=~(-(((int64)1)<<bsize));
return (*(uint64*)str->chr)&bmask;
}
int64 string2bit(qbs*str,uint32 bsize){
int64 bmask, bval64;
if (str->len<((bsize+7)>>3)) {error(5); return 0;}
bmask=~(-(((int64)1)<<bsize));
bval64=(*(uint64*)str->chr)&bmask;
@ -13920,13 +14064,12 @@ void qbs_input(int32 numvariables,uint8 newline){
if (chr=='\n') chr=13;
qbs_set(key,qbs_new_txt(" "));
key->chr[0]=chr;
}else{SDL_Delay(10);}
}else{Sleep(10);}
}else{
SDL_Delay(10);
Sleep(10);
qbs_set(key,qbs_inkey());
disableEvents=1;//we don't want the ON TIMER bound version of VKUPDATE to fire during a call to itself!
//SDL_Delay(10);
SUB_VKUPDATE();
disableEvents=0;
@ -21622,12 +21765,12 @@ int32 func__loadfont(qbs *f,int32 size,qbs *requirements,int32 passed){
int sec=7;
while(sec--){
evnt(1);
SDL_Delay(1000);
Sleep(1000);
qbs_print(qbs_new_txt("."),0);
}
sec=3;
while(sec--){
SDL_Delay(1000);
Sleep(1000);
evnt(1);
}
@ -21659,7 +21802,7 @@ int32 func__loadfont(qbs *f,int32 size,qbs *requirements,int32 passed){
static uint32 qbs_tmp_base;
qbs_tmp_base=qbs_tmp_list_nexti;
while(qbs_cleanup(qbs_tmp_base,qbs_notequal(qbs_inkey(),qbs_new_txt("")))){
SDL_Delay(0);
Sleep(0);
}
//6. Enable autodisplay
autodisplay=1;

View file

@ -1,6 +1,6 @@
#ifndef INC_LIBQB_H
#define INC_LIBQB_H
#include "common.cpp"
#include "common.h"
void error(int32 error_number);
extern uint32 new_error;

View file

@ -1,4 +1,4 @@
#include "common.cpp"
#include "common.h"
#ifdef QB64_MACOSX
#include <ApplicationServices/ApplicationServices.h>
@ -604,8 +604,18 @@ extern uint64 string2ui64(qbs*str);
extern float string2s(qbs*str);
extern double string2d(qbs*str);
extern long double string2f(qbs*str);
#ifndef QB64_WINDOWS
extern void Sleep(uint32 milliseconds);
extern void ZeroMemory(void *ptr,int64 bytes);
#endif
extern int64 qbr(long double f);
extern uint64 qbr_longdouble_to_uint64(long double f);
extern int32 qbr_float_to_long(float f);
extern int32 qbr_double_to_long(double f);
extern uint64 getubits(uint32 bsize,uint8 *base,ptrszint i);
extern int64 getbits(uint32 bsize,uint8 *base,ptrszint i);
extern void setbits(uint32 bsize,uint8 *base,ptrszint i,int64 val);

View file

@ -21865,25 +21865,6 @@ END FUNCTION
SUB xend
'1. locate bottomline,1
'PRINT #12, "display_page->cursor_y=print_holding_cursor=0; qbg_cursor_x=1; qbg_cursor_y=qbg_height_in_characters;"
'2. print a message in the screen's width
'PRINT #12, "if (qbg_width_in_characters==80){"
'PRINT #12, "qbs_print(qbs_new_txt(" + CHR$(34) + "Press any key to continue" + SPACE$(80 - 25) + CHR$(34) + "),0);"
'PRINT #12, "}else{"
'PRINT #12, "qbs_print(qbs_new_txt(" + CHR$(34) + "Press any key to continue" + SPACE$(40 - 25) + CHR$(34) + "),0);"
'PRINT #12, "}"
'3. wait for a key to be pressed
'PRINT #12, "do{"
'PRINT #12, "SDL_Delay(0);"
'PRINT #12, "if (stop_program) end();"
'PRINT #12, "}while(qbs_cleanup(qbs_tmp_base,qbs_equal(qbs_inkey(),
' qbs_new_txt(" + CHR$(34) + CHR$(34) + "))));"
'4. quit
'PRINT #12, "close_program=1;"
'PRINT #12, "end();"
PRINT #12, "sub_end();"
END SUB