TempleOSCD_140715.ISO
This commit is contained in:
1 parent
7ef616a20e
commit
64f679eeb9
1095 files changed
+24814
-221011
No files matched your search
@@ -1,2 +0,0 @@
|
||||
#exe {ImportHashTable(adam_task->hash_table);};
|
||||
|
||||
+2483
-2299
File diff suppressed because it is too large.
Load diff
+191
-240
@@ -1,288 +1,239 @@
|
||||
/*
|
||||
In this file, syms defined Kernel assembly
|
||||
files are given C+ definitions. This file
|
||||
is included when you compile the kernel, after
|
||||
the assembly files have been assembled, making
|
||||
the HolyC definitions available for the HolyC Kernel
|
||||
files. It is also included as part of booting.
|
||||
|
||||
The assembly global labels are stored as HTT_EXPORT_SYS_SYM
|
||||
entries in the hash table. These symols are placed
|
||||
into the Kernel binary module and added to the
|
||||
sym hash table at boot before this file
|
||||
gets #included during boot.
|
||||
|
||||
See
|
||||
$LK,"Adam1b",A="FF:::/Kernel/Kernel.PRJ,Adam1b"$ for where it is included during compiling the kernel.
|
||||
$LK,"Adam1b",A="FF:::/Kernel/Adam1.CPP,Adam1b"$ for where it is included during boots.
|
||||
$LK,"LoadKernel",A="FF:::/Kernel/KEnd.CPP,LoadKernel"$ for where the Kernel syms are added to the hash tables.
|
||||
|
||||
/* Kernel ASM symbols.
|
||||
$LK,"Adam1b",A="FF:::/Kernel/Kernel.PRJ,Adam1b"$ Kernel.PRJ
|
||||
$LK,"Adam1b",A="FF:::/Compiler/Compiler.PRJ,Adam1b"$ Compiler.PRJ
|
||||
$LK,"Adam1b",A="FF:::/Kernel/Adam1.CPP,Adam1b"$ Adam1.CPP
|
||||
*/
|
||||
|
||||
#help_index "Misc;Messages"
|
||||
public _extern SYS_FOCUS_TASK CTask *sys_focus_task;
|
||||
|
||||
#help_index "Graphics/Screen"
|
||||
//This is the INT 0x10 mode number.
|
||||
public _extern SYS_BIOS_GR_MODE U16 bios_gr_mode;
|
||||
#help_index "PCI"
|
||||
public _extern SYS_PCI_BUSSES U16 sys_pci_busses;
|
||||
#help_index "Misc"
|
||||
public _extern SYS_CTRL_ALT_FLAGS I64 sys_ctrl_alt_flags[1];
|
||||
public _extern SYS_COMPILE_TIME CDate sys_compile_time;
|
||||
#help_index "Bit"
|
||||
#help_file "::/Doc/Bit"
|
||||
public _intern IC_BSF I64 Bsf(I64 bit_field_val);//Scan fwd from lowest for 1st set. -1 if not found.
|
||||
public _intern IC_BSR I64 Bsr(I64 bit_field_val);//Scan rev from highest for 1st set. -1 if not found.
|
||||
public _intern IC_BT Bool Bt(U8 *bit_field,I64 bit); //Bit test.
|
||||
public _intern IC_BTC Bool Btc(U8 *bit_field,I64 bit); //Bit test and complement (same as xor with 1).
|
||||
public _intern IC_BTR Bool Btr(U8 *bit_field,I64 bit); //Bit test and reset to zero.
|
||||
public _intern IC_BTS Bool Bts(U8 *bit_field,I64 bit); //Bit test and set to one.
|
||||
public _intern IC_LBTC Bool LBtc(U8 *bit_field,I64 bit); //Locked Bit test and complement (same as xor with 1).
|
||||
public _intern IC_LBTR Bool LBtr(U8 *bit_field,I64 bit); //Locked Bit test and reset to zero.
|
||||
public _intern IC_LBTS Bool LBts(U8 *bit_field,I64 bit); //Locked Bit test and set to one.
|
||||
public _extern _BEQU Bool BEqu(U8 *bit_field,I64 bit,Bool val);//Set bit equal to val.
|
||||
public _extern _BIT_FIELD_EXTRACT_U32 U32 BFieldExtU32(U8 *bit_field,I64 bit,I64 size); //Extract U32 from bit field.
|
||||
public _extern _BIT_FIELD_OR_U32 U0 BFieldOrU32(U8 *bit_field,I64 bit,U32 pattern); //Or U32 into bit field.
|
||||
public _extern _LBEQU Bool LBEqu(U8 *bit_field,I64 bit,Bool val); //Locked Set bit equal to val.
|
||||
|
||||
#help_index "Boot"
|
||||
_extern SYS_BOOT_BASE U32 sys_boot_base;
|
||||
_extern SYS_BOOT_CODE U32 sys_boot_code;
|
||||
_extern SYS_RUN_LEVEL U32 sys_run_level;
|
||||
_extern SYS_BOOT_PATCH_TABLE_BASE U32 sys_boot_patch_table_base;
|
||||
_extern SYS_RUN_LEVEL U32 sys_run_level;
|
||||
|
||||
#help_index "Misc/Progress Bars"
|
||||
public _extern SYS_PROGRESSES CProgress sys_progresses[NUM_PROGRESS_BARS];
|
||||
public _extern SYS_PROGRESS1 I64 progress1;
|
||||
public _extern SYS_PROGRESS1_MAX I64 progress1_max;
|
||||
public _extern SYS_PROGRESS1_DESC U8 progress1_desc[PROGRESS_DESC_LEN+1];
|
||||
public _extern SYS_PROGRESS2 I64 progress2;
|
||||
public _extern SYS_PROGRESS2_MAX I64 progress2_max;
|
||||
public _extern SYS_PROGRESS2_DESC U8 progress2_desc[PROGRESS_DESC_LEN+1];
|
||||
public _extern SYS_PROGRESS3 I64 progress3;
|
||||
public _extern SYS_PROGRESS3_MAX I64 progress3_max;
|
||||
public _extern SYS_PROGRESS3_DESC U8 progress3_desc[PROGRESS_DESC_LEN+1];
|
||||
public _extern SYS_PROGRESS4 I64 progress4;
|
||||
public _extern SYS_PROGRESS4_MAX I64 progress4_max;
|
||||
public _extern SYS_PROGRESS4_DESC U8 progress4_desc[PROGRESS_DESC_LEN+1];
|
||||
|
||||
#help_index "Bit"
|
||||
#help_file "::/Doc/Bit"
|
||||
public _intern IC_BT Bool Bt(U8 *bit_field,I64 bit);
|
||||
public _intern IC_BTS Bool Bts(U8 *bit_field,I64 bit);
|
||||
public _intern IC_BTR Bool Btr(U8 *bit_field,I64 bit);
|
||||
public _intern IC_BTC Bool Btc(U8 *bit_field,I64 bit);
|
||||
public _extern _BEQU Bool BEqu(U8 *bit_field,I64 bit,Bool val);
|
||||
#help_index "Call"
|
||||
public _extern _CALL I64 Call(U8 *s); //Call addr with no args.
|
||||
public _extern _CALLEXTSTR I64 CallExtStr(/*argpop*/ U8 *name,...); //Search sym table for fun name and pass it args.
|
||||
//Can have any fixed number of arguments.
|
||||
public _extern _CALLIND I64 CallInd(/*argpop*/I64 (*fp_addr)(...),...); //Call with any fixed number of arguments.
|
||||
|
||||
//Locked for (for multitple CPU's)
|
||||
public _intern IC_LBTS Bool LBts(U8 *bit_field,I64 bit);
|
||||
public _intern IC_LBTR Bool LBtr(U8 *bit_field,I64 bit);
|
||||
public _intern IC_LBTC Bool LBtc(U8 *bit_field,I64 bit);
|
||||
public _extern _LBEQU Bool LBEqu(U8 *bit_field,I64 bit,Bool val);
|
||||
#help_index "Call/System Extern Num"
|
||||
public _extern SYS_EXTERN_TABLE /*argpop*/ I64 (**ext)(...); //Array of fun ptrs. See $LK,"Extern Num Definitions",A="MN:EXT_NUM_ENTRIES"$
|
||||
public _extern _CALLEXTNUM I64 CallExtNum(I64 num,...); //Call ext num with any fixed number of args.
|
||||
|
||||
//Scan I64 sized item fwd for first set bit, starting at lowest.
|
||||
//Return -1 if not found.
|
||||
public _intern IC_BSF I64 Bsf(I64 bit_field_val);
|
||||
#help_index "Char/Conversion"
|
||||
public _intern IC_TOUPPER I64 ToUpper(U8 ch); //Cvt char to upper case.
|
||||
|
||||
//Scan I64 sized item reverse for first set bit, starting at highest.
|
||||
//Return -1 if not found.
|
||||
public _intern IC_BSR I64 Bsr(I64 bit_field_val);
|
||||
|
||||
public _extern _BIT_FIELD_OR_U32 U0 BFieldOrU32(
|
||||
U8 *bit_field,I64 bit,U32 pattern);
|
||||
public _extern _BIT_FIELD_EXTRACT_U32 U32 BFieldExtU32(
|
||||
U8 *bit_field,I64 bit,I64 size);
|
||||
#help_index "Char/Operations"
|
||||
public _intern IC_STRLEN I64 StrLen(U8 *st); //String length.
|
||||
|
||||
#help_index "Data Types/Circular Queue"
|
||||
#help_file "::/Doc/Que"
|
||||
public _intern IC_QUE_INIT U0 QueInit(CQue *root);
|
||||
//Ins item into que after predicessor.
|
||||
public _intern IC_QUE_INS U0 QueIns(CQue *entry,CQue *pred);
|
||||
//Reversed insert into que. Ins
|
||||
//item into que before successor.
|
||||
public _intern IC_QUE_INS_REV U0 QueInsRev(CQue *entry,CQue *succ);
|
||||
//Remove item from que.
|
||||
public _intern IC_QUE_REM U0 QueRem(CQue *entry);
|
||||
public _intern IC_QUE_INIT U0 QueInit(CQue *root); //Init queue root links.
|
||||
public _intern IC_QUE_INS U0 QueIns(CQue *entry,CQue *pred);//Ins item into que after predecessor.
|
||||
public _intern IC_QUE_INS_REV U0 QueInsRev(CQue *entry,CQue *succ);//Reversed insert into que.
|
||||
//Ins item into que before successor.
|
||||
public _intern IC_QUE_REM U0 QueRem(CQue *entry); //Remove Item from queue.
|
||||
|
||||
#help_index "Task"
|
||||
public _intern IC_PREEMPT Bool Preempt(Bool val);
|
||||
#help_index "Graphics/Screen"
|
||||
public _extern SYS_BIOS_GR_MODE U16 sys_bios_gr_mode; //INT 0x10 mode number.
|
||||
|
||||
#help_index "I/O;Processor/IO Port"
|
||||
public _intern IC_IN_U8 I64 InU8(I64 port);
|
||||
public _intern IC_IN_U16 I64 InU16(I64 port);
|
||||
public _intern IC_IN_U32 I64 InU32(I64 port);
|
||||
public _intern IC_OUT_U8 U0 OutU8(I64 port, I64 val);
|
||||
public _intern IC_OUT_U16 U0 OutU16(I64 port, I64 val);
|
||||
public _intern IC_OUT_U32 U0 OutU32(I64 port, I64 val);
|
||||
public _extern _REP_IN_U8 U0 RepInU8(U8 *buf,I64 cnt,I64 port);
|
||||
public _extern _REP_IN_U16 U0 RepInU16(U8 *buf,I64 cnt,I64 port);
|
||||
public _extern _REP_IN_U32 U0 RepInU32(U8 *buf,I64 cnt,I64 port);
|
||||
public _extern _REP_OUT_U8 U0 RepOutU8(U8 *buf,I64 cnt,I64 port);
|
||||
public _extern _REP_OUT_U16 U0 RepOutU16(U8 *buf,I64 cnt,I64 port);
|
||||
public _extern _REP_OUT_U32 U0 RepOutU32(U8 *buf,I64 cnt,I64 port);
|
||||
public _intern IC_IN_U16 I64 InU16(I64 port); //Read U16 from I/O port.
|
||||
public _intern IC_IN_U32 I64 InU32(I64 port); //Read U32 from I/O port.
|
||||
public _intern IC_IN_U8 I64 InU8(I64 port); //Read U8 from I/O port.
|
||||
public _intern IC_OUT_U16 U0 OutU16(I64 port, I64 val); //Write U16 to I/O port.
|
||||
public _intern IC_OUT_U32 U0 OutU32(I64 port, I64 val); //Write U32 to I/O port.
|
||||
public _intern IC_OUT_U8 U0 OutU8(I64 port, I64 val); //Write U8 to I/O port.
|
||||
public _extern _REP_IN_U16 U0 RepInU16(U8 *buf,I64 cnt,I64 port); //Repeated read U16 from I/O port.
|
||||
public _extern _REP_IN_U32 U0 RepInU32(U8 *buf,I64 cnt,I64 port); //Repeated read U32 from I/O port.
|
||||
public _extern _REP_IN_U8 U0 RepInU8(U8 *buf,I64 cnt,I64 port); //Repeated read U8 from I/O port.
|
||||
public _extern _REP_OUT_U16 U0 RepOutU16(U8 *buf,I64 cnt,I64 port); //Repeated write U16 to I/O port.
|
||||
public _extern _REP_OUT_U32 U0 RepOutU32(U8 *buf,I64 cnt,I64 port); //Repeated write U32 to I/O port.
|
||||
public _extern _REP_OUT_U8 U0 RepOutU8(U8 *buf,I64 cnt,I64 port); //Repeated write U8 to I/O port.
|
||||
|
||||
#help_index "Math"
|
||||
public _intern IC_ATAN F64 ATan(F64 d); //Arc Tan (Inverse Tan).
|
||||
public _intern IC_ABS F64 Abs(F64 d); //Absolute F64.
|
||||
public _intern IC_ABS_I64 I64 AbsI64(I64 i); //Absolute I64.
|
||||
public _intern IC_COS F64 Cos(F64 d); //Cosine.
|
||||
public _intern IC_MAX_I64 I64 MaxI64(I64 n1,I64 n2); //Max of two I64s.
|
||||
public _intern IC_MAX_U64 U64 MaxU64(U64 n1,U64 n2); //Max of two U64s.
|
||||
public _intern IC_MIN_I64 I64 MinI64(I64 n1,I64 n2); //Min of two I64s.
|
||||
public _intern IC_MIN_U64 U64 MinU64(U64 n1,U64 n2); //Min of two U64s.
|
||||
public _intern IC_MOD_U64 U64 ModU64(U64 *q,U64 d); //Divide and return U64 Modulo.
|
||||
public _intern IC_SIGN_I64 I64 SignI64(I64 i); //Sign of I64: -1,0,1.
|
||||
public _intern IC_SIN F64 Sin(F64 d); //Sine.
|
||||
public _intern IC_SQR F64 Sqr(F64 d); //Square of F64.
|
||||
public _intern IC_SQR_I64 I64 SqrI64(I64 i); //Square of I64.
|
||||
public _intern IC_SQR_U64 U64 SqrU64(U64 i); //Square of U64.
|
||||
public _intern IC_SQRT F64 Sqrt(F64 d); //Square root of F64.
|
||||
public _intern IC_SWAP_I64 U0 SwapI64(I64 *n1,I64 *n2); //Swap two I64s. Not atomic.
|
||||
public _intern IC_SWAP_U16 U0 SwapU16(U16 *n1,U16 *n2); //Swap two U16s. Not atomic.
|
||||
public _intern IC_SWAP_U32 U0 SwapU32(U32 *n1,U32 *n2); //Swap two U32s. Not atomic.
|
||||
public _intern IC_SWAP_U8 U0 SwapU8(U8 *n1,U8 *n2); //Swap two U8s. Not atomic.
|
||||
public _intern IC_TAN F64 Tan(F64 d); //Tangent.
|
||||
public _intern IC_TO_BOOL Bool ToBool(I64 i); //Convert to Boolean.
|
||||
public _intern IC_TO_F64 F64 ToF64(I64 i); //Convert to F64.
|
||||
public _intern IC_TO_I64 I64 ToI64(F64 d); //Convert to I64. Truncates.
|
||||
public _extern _ARG F64 Arg(F64 x,F64 y); //Polar coordinate angle.
|
||||
public _extern _CEIL F64 Ceil(F64 d); //Ceiling of F64.
|
||||
public _extern _CLAMP_I64 I64 ClampI64(I64 p,I64 lo,I64 hi); //Clamp to I64 [] range.
|
||||
public _extern _CLAMP_U64 U64 ClampU64(U64 p,U64 lo,U64 hi); //Clamp to U64 [] range.
|
||||
public _extern _EXP F64 Exp(F64 d); //Exponential function.
|
||||
_extern _FCLEX U0 Fclex();
|
||||
_extern _FLDCW U0 Fldcw(U16 w);
|
||||
public _extern _FLOOR F64 Floor(F64 d); //Floor of F64.
|
||||
_extern _FSTCW U16 Fstcw();
|
||||
_extern _FSTSW U16 Fstsw();
|
||||
_extern _FXRSTOR U0 Fxrstor(CFPU *fpu_mmx);
|
||||
_extern _FXSAVE U0 Fxsave(CFPU *fpu_mmx);
|
||||
public _extern _LN F64 Ln(F64 d); //Logarithm.
|
||||
public _extern _LOG10 F64 Log10(F64 d); //Log base 10.
|
||||
public _extern _LOG2 F64 Log2(F64 d); //Log base 2.
|
||||
public _extern _POW F64 Pow(F64 base,F64 power); //F64 base to a power.
|
||||
public _extern _POW10 F64 Pow10(F64 d); //Ten to the dth power.
|
||||
public _extern _ROUND F64 Round(F64 d); //Round F64 to whole number.
|
||||
public _extern _SIGN F64 Sign(F64 d); //Sign of F64: -1,0,1
|
||||
public _extern _TRUNC F64 Trunc(F64 d); //Truncate F64.
|
||||
|
||||
#help_index "Math/CD3"
|
||||
#help_file "::/Doc/D3"
|
||||
public _extern _D3_ADD CD3 *D3Add(CD3 *d1,CD3 *d2,CD3 *sum); //d1+d2 -->sum
|
||||
public _extern _D3_ADD_EQU CD3 *D3AddEqu(CD3 *sum,CD3 *d); //sum+=d
|
||||
public _extern _D3_COPY CD3 *D3Copy(CD3 *dst,CD3 *src); //dst=src
|
||||
public _extern _D3_CROSS CD3 *D3Cross(CD3 *d1,CD3 *d2,CD3 *prod); //d1 x d2 -->prod
|
||||
public _extern _D3_DIST F64 D3Dist(CD3 *d1,CD3 *d2); //Dist between d1 & d2
|
||||
public _extern _D3_DIST_SQR F64 D3DistSqr(CD3 *d1,CD3 *d2); //Dist Squared between d1 & d2
|
||||
public _extern _D3_DIV CD3 *D3Div(F64 s,CD3 *d,CD3 *quot); //1/s * d -->quot
|
||||
public _extern _D3_DIV_EQU CD3 *D3DivEqu(CD3 *quot,F64 s); //quot *= 1/s
|
||||
public _extern _D3_DOT F64 D3Dot(CD3 *d1,CD3 *d2); //d1 dot d2
|
||||
public _extern _D3_EQU CD3 *D3Equ(CD3 *dst,F64 x,F64 y,F64 z); // dst=x,y,z
|
||||
public _extern _D3_MUL CD3 *D3Mul(F64 s,CD3 *d,CD3 *prod); //s * d -->prod
|
||||
public _extern _D3_MUL_EQU CD3 *D3MulEqu(CD3 *prod,F64 s); //prod *= s
|
||||
public _extern _D3_NORM F64 D3Norm(CD3 *d); //Norm d
|
||||
public _extern _D3_NORM_SQR F64 D3NormSqr(CD3 *d); //Norm Squared d
|
||||
public _extern _D3_SUB CD3 *D3Sub(CD3 *d1,CD3 *d2,CD3 *diff); //d1-d2 -->diff
|
||||
public _extern _D3_SUB_EQU CD3 *D3SubEqu(CD3 *diff,CD3 *d); //diff-=d
|
||||
public _extern _D3_UNIT CD3 *D3Unit(CD3 *d); //Convert to unit vect
|
||||
public _extern _D3_ZERO CD3 *D3Zero(CD3 *dst); //Convert to zero
|
||||
|
||||
#help_index "Memory"
|
||||
//Only goes fwd.
|
||||
public _extern _MEMCPY U8 *MemCpy(U8 *dst,U8 *src,I64 cnt);
|
||||
public _extern _MEMCMP I64 MemCmp(U8 *ptr1,U8 *ptr2,I64 cnt);
|
||||
public _extern _MEMSET U8 *MemSet(U8 *dst,I64 val,I64 cnt);
|
||||
public _extern _MEMSET U8 *MemSetU8(U8 *dst,I64 val,I64 U8cnt);
|
||||
public _extern _MEMSET_U16 U16 *MemSetU16(U16 *dst,I64 val,I64 U16cnt);
|
||||
public _extern _MEMSET_U32 U32 *MemSetU32(U32 *dst,I64 val,I64 U32cnt);
|
||||
public _extern _MEMSET_U64 U64 *MemSetU64(U64 *dst,I64 val,I64 U64cnt);
|
||||
public _extern SYS_CODE_BP CBlkPool *sys_code_bp;
|
||||
public _extern SYS_DATA_BP CBlkPool *sys_data_bp;
|
||||
public _extern SYS_HEAP_BASE U8 *sys_heap_base;
|
||||
public _extern SYS_HEAP_LIMIT U8 *sys_heap_limit;
|
||||
|
||||
public _extern _MEMCMP I64 MemCmp(U8 *ptr1,U8 *ptr2,I64 cnt); //Compare chunk of memory.
|
||||
public _extern _MEMCPY U8 *MemCpy(U8 *dst,U8 *src,I64 cnt); //Copy chunk of memory. Only goes fwd.
|
||||
public _extern _MEMSET U8 *MemSet(U8 *dst,I64 val,I64 cnt); //Set chunk of U8s to value.
|
||||
public _extern _MEMSET_I64 I64 *MemSetI64(I64 *dst,I64 val,I64 I64cnt); //Set chunk of I64s to value.
|
||||
public _extern _MEMSET_U16 U16 *MemSetU16(U16 *dst,I64 val,I64 U16cnt); //Set chunk of U16s to value.
|
||||
public _extern _MEMSET_U32 U32 *MemSetU32(U32 *dst,I64 val,I64 U32cnt); //Set chunk of U32s to value.
|
||||
public _extern _MEMSET U8 *MemSetU8(U8 *dst,I64 val,I64 U8cnt); //Set chunk of U8s to value.
|
||||
_extern SYS_HEAP_DBG_FLAG U8 sys_heap_dbg;
|
||||
_extern SYS_HEAP_INIT_FLAG U8 sys_heap_init_flag;
|
||||
_extern SYS_HEAP_INIT_VAL U8 sys_heap_init_val;
|
||||
_extern SYS_MEM_INIT_FLAG U8 sys_mem_init_flag;
|
||||
_extern SYS_MEM_INIT_VAL U8 sys_mem_init_val;
|
||||
_extern SYS_VAR_INIT_FLAG U8 sys_var_init_flag;
|
||||
_extern SYS_VAR_INIT_VAL U8 sys_var_init_val;
|
||||
_extern SYS_HEAP_DBG_FLAG U8 sys_heap_dbg;
|
||||
|
||||
#help_index "Char/Conversion"
|
||||
public _intern IC_TOUPPER I64 ToUpper(U8 ch);
|
||||
#help_index "Char/Operations"
|
||||
public _intern IC_STRLEN I64 StrLen(U8 *st);
|
||||
#help_index "Memory/Blk Pool"
|
||||
public _extern SYS_CODE_BP CBlkPool *sys_code_bp; //System's blk pool for code.
|
||||
public _extern SYS_DATA_BP CBlkPool *sys_data_bp; //System's blk pool for data.
|
||||
|
||||
#help_index "Processor"
|
||||
public _extern _CPUID U0 CPUId(U32 rax,CRAXRBCRCXRDX *result);
|
||||
public _intern IC_SET_RAX U0 SetRAX(I64 d);
|
||||
public _intern IC_GET_RAX I64 GetRAX();
|
||||
public _extern _SYS_HLT U0 SysHlt(); //Loops
|
||||
#help_index "Memory/Info"
|
||||
_extern SYS_HEAP_BASE U8 *sys_heap_base;
|
||||
_extern SYS_HEAP_LIMIT U8 *sys_heap_limit;
|
||||
|
||||
public _intern IC_POP I64 Pop();
|
||||
public _intern IC_PUSH U0 Push(I64 d);
|
||||
public _intern IC_GET_RFLAGS I64 GetRFlags();
|
||||
public _intern IC_CARRY I64 Carry();
|
||||
public _intern IC_SET_RFLAGS U0 SetRFlags(I64 d);
|
||||
public _intern IC_GET_RSP U8 *GetRSP();
|
||||
public _intern IC_SET_RSP U0 SetRSP(U8 *d);
|
||||
public _intern IC_GET_RBP U8 *GetRBP();
|
||||
public _intern IC_SET_RBP U0 SetRBP(U8 *d);
|
||||
public _extern SYS_CACHE_LINE_WIDTH I64 sys_cache_line_width;
|
||||
_extern SYS_GDT CGDT sys_gdt;
|
||||
public _extern _XCHG_U64 U64 XchgU64(U64 *dst,U64 d);
|
||||
public _extern _XCHG_U32 U64 XchgU32(U32 *dst,U32 d);
|
||||
public _extern _XCHG_U16 U64 XchgU16(U16 *dst,U16 d);
|
||||
public _extern _XCHG_U8 U64 XchgU8 (U8 *dst,U8 d);
|
||||
public _extern _LXCHG_U64 U64 LXchgU64(U64 *dst,U64 d);
|
||||
public _extern _LXCHG_U32 U64 LXchgU32(U32 *dst,U32 d);
|
||||
public _extern _LXCHG_U16 U64 LXchgU16(U16 *dst,U16 d);
|
||||
public _extern _LXCHG_U8 U64 LXchgU8(U8 *dst,U8 d);
|
||||
#help_index "Misc"
|
||||
public _extern SYS_COMPILE_TIME CDate sys_compile_time; //Date and time kernel was compiled.
|
||||
_extern SYS_CTRL_ALT_FLAGS I64 sys_ctrl_alt_flags[1]; //Should be semiphores?
|
||||
|
||||
//Model Specific Reg
|
||||
//See $LK,"MSRs",A="MN:IA32_EFER"$
|
||||
public _extern _SET_MSR U0 SetMSR(I64 model_specific_reg,I64 val);
|
||||
#help_index "Misc/Progress Bars"
|
||||
public _extern SYS_PROGRESS1 I64 progress1; //Current progress 1.
|
||||
public _extern SYS_PROGRESS1_DESC U8 progress1_desc[PROGRESS_DESC_LEN+1]; //Progress 1 desc.
|
||||
public _extern SYS_PROGRESS1_MAX I64 progress1_max; //Max progress 1.
|
||||
public _extern SYS_PROGRESS2 I64 progress2; //Current progress 2.
|
||||
public _extern SYS_PROGRESS2_DESC U8 progress2_desc[PROGRESS_DESC_LEN+1]; //Progress 2 desc.
|
||||
public _extern SYS_PROGRESS2_MAX I64 progress2_max; //Max progress 2.
|
||||
public _extern SYS_PROGRESS3 I64 progress3; //Current progress 3.
|
||||
public _extern SYS_PROGRESS3_DESC U8 progress3_desc[PROGRESS_DESC_LEN+1]; //Progress 3 desc.
|
||||
public _extern SYS_PROGRESS3_MAX I64 progress3_max; //Max progress 3.
|
||||
public _extern SYS_PROGRESS4 I64 progress4; //Current progress 4.
|
||||
public _extern SYS_PROGRESS4_DESC U8 progress4_desc[PROGRESS_DESC_LEN+1]; //Progress 4 desc.
|
||||
public _extern SYS_PROGRESS4_MAX I64 progress4_max; //Max progress 4.
|
||||
public _extern SYS_PROGRESSES CProgress sys_progresses[NUM_PROGRESS_BARS]; //All progress bars.
|
||||
|
||||
#help_index "Processor/Cache;Memory/Cache"
|
||||
public _intern IC_INVLPG U0 InvlPg(U8 *a);
|
||||
//Flush cache line.
|
||||
public _intern IC_CLFLUSH U0 CLFlush(U8 *a);
|
||||
#help_index "Misc;Messages"
|
||||
public _extern SYS_FOCUS_TASK CTask *sys_focus_task; //Current focus task.
|
||||
|
||||
#help_index "MultiCore"
|
||||
#help_file "::/Doc/MultiCore"
|
||||
public _extern SYS_MP_CNT I64 mp_cnt;
|
||||
public _extern SYS_CPU_STRUCTS CCPU *cpu_structs;//$LK,"Gs",A="MN:Gs"$ points to cur $LK,"CCPU",A="MN:CCPU"$.
|
||||
public _extern SYS_MP_CNT I64 mp_cnt; //Count of cores
|
||||
_extern SYS_MP_CNT_INITIAL I64 mp_cnt_initial; //only used during $LK,"MPStart",A="MN:MPStart"$
|
||||
_extern SYS_MP_CNT_LOCK I64 mp_cnt_lock;
|
||||
public _extern SYS_CPU_STRUCTS CCPU *cpu_structs;
|
||||
_extern SYS_SEMAS CSema sys_semas[NUM_SYS_SEMAS];
|
||||
|
||||
#help_index "MultiCore;Processor"
|
||||
//This points to the current $LK,"CCPU",A="MN:CCPU"$ structure.
|
||||
//It returns the val in the GS segment reg.
|
||||
public _intern IC_GS CCPU *Gs();
|
||||
public _intern IC_GS CCPU *Gs(); //GS points to current $LK,"CCPU",A="MN:CCPU"$.
|
||||
|
||||
#help_index "Time/CPU Cycles"
|
||||
public _intern IC_RDTSC I64 GetTSC(); //Time Stamp Counter
|
||||
#help_index "PCI"
|
||||
public _extern SYS_PCI_BUSSES U16 sys_pci_busses; //Number of PCI busses.
|
||||
|
||||
#help_index "Time/HPET"
|
||||
public _intern IC_HPET I64 HPET();
|
||||
#help_index "Processor"
|
||||
public _intern IC_CARRY I64 Carry(); //See $LK,"::/Demo/Carry.CPP"$
|
||||
public _intern IC_GET_RAX I64 GetRAX(); //Get RAX register value.
|
||||
public _intern IC_GET_RBP U8 *GetRBP(); //Get RBP register value.
|
||||
public _intern IC_GET_RFLAGS I64 GetRFlags(); //Get RFlags register value.
|
||||
public _intern IC_GET_RSP U8 *GetRSP(); //Get RSP register value.
|
||||
public _intern IC_POP I64 Pop(); //Pop value from stk.
|
||||
public _intern IC_PUSH U0 Push(I64 d); //Push value on stk.
|
||||
public _intern IC_SET_RAX U0 SetRAX(I64 d); //Set RAX register value.
|
||||
public _intern IC_SET_RBP U0 SetRBP(U8 *d); //Set RBP register value.
|
||||
public _intern IC_SET_RFLAGS U0 SetRFlags(I64 d); //Set RFlags register value.
|
||||
public _intern IC_SET_RSP U0 SetRSP(U8 *d); //Set RSP register value.
|
||||
public _extern _CPUID U0 CPUId(U32 rax,CRAXRBCRCXRDX *result); //Do CPUID instruction.
|
||||
public _extern _LXCHG_I64 I64 LXchgI64(I64 *dst,I64 d); //Locked eXchange I64s.
|
||||
public _extern _LXCHG_U16 U64 LXchgU16(U16 *dst,U16 d); //Locked eXchange U16s.
|
||||
public _extern _LXCHG_U32 U64 LXchgU32(U32 *dst,U32 d); //Locked eXchange U32s.
|
||||
public _extern _LXCHG_U8 U64 LXchgU8(U8 *dst,U8 d); //Locked eXchange U8s.
|
||||
public _extern _SET_MSR U0 SetMSR(I64 model_specific_reg,I64 val); //Model Specific Reg See $LK,"MSRs",A="MN:IA32_EFER"$.
|
||||
public _extern _SYS_HLT U0 SysHlt(); //Loops doing HLT instruction.
|
||||
public _extern _XCHG_I64 I64 XchgI64(I64 *dst,I64 d); //eXchange I64s.
|
||||
public _extern _XCHG_U16 U64 XchgU16(U16 *dst,U16 d); //eXchange U16s.
|
||||
public _extern _XCHG_U32 U64 XchgU32(U32 *dst,U32 d); //eXchange U32s.
|
||||
public _extern _XCHG_U8 U64 XchgU8(U8 *dst,U8 d); //eXchange U8s.
|
||||
public _extern SYS_CACHE_LINE_WIDTH I64 sys_cache_line_width; //CPU's Cache line width.
|
||||
_extern SYS_GDT CGDT sys_gdt;
|
||||
|
||||
#help_index "Time/Jiffies"
|
||||
#help_file "::/Doc/TimeJiffy"
|
||||
_extern SYS_TIMER I64 sys_timer;
|
||||
public _extern SYS_JIFFIES I64 sys_jiffies;
|
||||
|
||||
#help_index "Math"
|
||||
public _intern IC_TO_I64 I64 ToI64(F64 d); //This truncates
|
||||
public _intern IC_TO_F64 F64 ToF64(I64 i);
|
||||
public _intern IC_TO_BOOL Bool ToBool(I64 i);
|
||||
public _intern IC_ABS_I64 I64 AbsI64(I64 i);
|
||||
public _intern IC_SIGN_I64 I64 SignI64(I64 i);
|
||||
public _intern IC_SQR_I64 I64 SqrI64(I64 i);
|
||||
public _intern IC_SQR_U64 U64 SqrU64(U64 i);
|
||||
public _intern IC_SWAP_U8 U0 SwapU8(U8 *n1,U8 *n2);
|
||||
public _intern IC_SWAP_U16 U0 SwapU16(U16 *n1,U16 *n2);
|
||||
public _intern IC_SWAP_U32 U0 SwapU32(U32 *n1,U32 *n2);
|
||||
public _intern IC_SWAP_U64 U0 SwapU64(U64 *n1,U64 *n2);
|
||||
public _intern IC_MIN_I64 I64 MinI64(I64 n1,I64 n2);
|
||||
public _intern IC_MAX_I64 I64 MaxI64(I64 n1,I64 n2);
|
||||
public _intern IC_MIN_U64 U64 MinU64(U64 n1,U64 n2);
|
||||
public _intern IC_MAX_U64 U64 MaxU64(U64 n1,U64 n2);
|
||||
public _intern IC_MOD_U64 U64 ModU64(U64 *q,U64 d);
|
||||
public _intern IC_SQR F64 Sqr(F64 d);
|
||||
public _intern IC_ABS F64 Abs(F64 d);
|
||||
public _intern IC_SQRT F64 Sqrt(F64 d);
|
||||
public _intern IC_SIN F64 Sin(F64 d);
|
||||
public _intern IC_COS F64 Cos(F64 d);
|
||||
public _intern IC_TAN F64 Tan(F64 d);
|
||||
public _intern IC_ATAN F64 ATan(F64 d);
|
||||
|
||||
public _extern _CLAMP_I64 I64 ClampI64(I64 p,I64 lo,I64 hi);
|
||||
public _extern _CLAMP_U64 U64 ClampU64(U64 p,U64 lo,U64 hi);
|
||||
public _extern _SIGN F64 Sign(F64 d);
|
||||
public _extern _ARG F64 Arg(F64 x,F64 y);
|
||||
public _extern _ROUND F64 Round(F64 d);
|
||||
public _extern _TRUNC F64 Trunc(F64 d);
|
||||
public _extern _FLOOR F64 Floor(F64 d);
|
||||
public _extern _CEIL F64 Ceil(F64 d);
|
||||
public _extern _POW F64 Pow(F64 base,F64 power);
|
||||
public _extern _POW10 F64 Pow10(F64 d);
|
||||
public _extern _LOG2 F64 Log2(F64 d);
|
||||
public _extern _LOG10 F64 Log10(F64 d);
|
||||
public _extern _LN F64 Ln(F64 d);
|
||||
public _extern _EXP F64 Exp(F64 d);
|
||||
_extern _FLDCW U0 Fldcw(U16 w);
|
||||
_extern _FCLEX U0 Fclex();
|
||||
_extern _FSTCW U16 Fstcw();
|
||||
_extern _FSTSW U16 Fstsw();
|
||||
_extern _FXSAVE U0 Fxsave(CFPU *fpu_mmx);
|
||||
_extern _FXRSTOR U0 Fxrstor(CFPU *fpu_mmx);
|
||||
|
||||
#help_index "Math/CD3;ODE/CD3"
|
||||
#help_file "::/Doc/D3"
|
||||
public _extern _D3_EQU CD3 *D3Equ(CD3 *dst,F64 x,F64 y,F64 z);
|
||||
public _extern _D3_ZERO CD3 *D3Zero(CD3 *dst);
|
||||
public _extern _D3_COPY CD3 *D3Copy(CD3 *dst,CD3 *src);
|
||||
public _extern _D3_NORM F64 D3Norm(CD3 *d);
|
||||
public _extern _D3_SQR_NORM F64 D3SqrNorm(CD3 *d);
|
||||
public _extern _D3_ADD CD3 *D3Add(CD3 *d1,CD3 *d2,CD3 *sum);
|
||||
public _extern _D3_SUB CD3 *D3Sub(CD3 *d1,CD3 *d2,CD3 *diff);
|
||||
public _extern _D3_MUL CD3 *D3Mul(F64 c,CD3 *d,CD3 *prod);
|
||||
public _extern _D3_DIV CD3 *D3Div(F64 c,CD3 *d,CD3 *quot);
|
||||
public _extern _D3_ADD_EQU CD3 *D3AddEqu(CD3 *sum,CD3 *d);
|
||||
public _extern _D3_SUB_EQU CD3 *D3SubEqu(CD3 *diff,CD3 *d);
|
||||
public _extern _D3_MUL_EQU CD3 *D3MulEqu(CD3 *prod,F64 c);
|
||||
public _extern _D3_DIV_EQU CD3 *D3DivEqu(CD3 *quot,F64 c);
|
||||
public _extern _D3_DIST F64 D3Dist(CD3 *d1,CD3 *d2);
|
||||
public _extern _D3_SQR_DIST F64 D3SqrDist(CD3 *d1,CD3 *d2);
|
||||
//Dot Product
|
||||
public _extern _D3_DOT F64 D3Dot(CD3 *d1,CD3 *d2);
|
||||
//Cross Product
|
||||
public _extern _D3_CROSS CD3 *D3Cross(CD3 *d1,CD3 *d2,CD3 *prod);
|
||||
//Convert to unit vect
|
||||
public _extern _D3_UNIT CD3 *D3Unit(CD3 *d);
|
||||
#help_index "Processor/Cache;Memory/Cache"
|
||||
public _intern IC_CLFLUSH U0 CLFlush(U8 *a); //Flush cache line.
|
||||
public _intern IC_INVLPG U0 InvlPg(U8 *a); //Invalidate page at addr.
|
||||
|
||||
#help_index "Task"
|
||||
public _intern IC_PREEMPT Bool Preempt(Bool val); //Turn mutli-tasking preemption OFF/ON.
|
||||
|
||||
#help_index "Task;Processor"
|
||||
//This points to the current $LK,"CTask",A="MN:CTask"$ structure.
|
||||
//It returns the val in the FS segment reg.
|
||||
public _intern IC_FS CTask *Fs();
|
||||
public _intern IC_FS CTask *Fs(); //FS seg reg points to the current $LK,"CTask",A="MN:CTask"$.
|
||||
|
||||
#help_index "Call"
|
||||
public _extern _CALL I64 Call(U8 *s);
|
||||
#help_index "Time/CPU Cycles"
|
||||
public _intern IC_RDTSC I64 GetTSC(); //Get time stamp counter.
|
||||
|
||||
//fp_addr can have any fixed number of arguments.
|
||||
public _extern _CALLIND I64 CallInd(/*argpop*/I64 (*fp_addr)(...),...);
|
||||
|
||||
//This is just an array of ptrs to funs.
|
||||
//See $LK,"Extern Num Definitions",A="MN:EXT_NUM_ENTRIES"$
|
||||
public _extern SYS_EXTERN_TABLE /*argpop*/ I64 (**ext)(...);
|
||||
//Can have any fixed number of arguments.
|
||||
public _extern _CALLEXTNUM I64 CallExtNum(I64 num,...);
|
||||
|
||||
//Search sym table for fun name and pass it args.
|
||||
//Can have any fixed number of arguments.
|
||||
public _extern _CALLEXTSTR I64 CallExtStr(/*argpop*/ U8 *name,...);
|
||||
#help_index "Time/HPET"
|
||||
#help_file "::/Doc/TimeHPET"
|
||||
public _intern IC_HPET I64 HPET(); //Get high precision event timer.
|
||||
|
||||
#help_index ""
|
||||
+670
-750
File diff suppressed because it is too large.
Load diff
+14
-17
@@ -54,9 +54,6 @@ SYS_BIOS32_SERVICE_CALL:: DU32 0;
|
||||
@@05: MOV U32 [SYS_PCI_SERVICES],0
|
||||
RET
|
||||
|
||||
|
||||
|
||||
|
||||
USE64
|
||||
C32_EAX:: DU32 0;
|
||||
C32_EBX:: DU32 0;
|
||||
@@ -166,12 +163,10 @@ _extern C32_EDI U32 c32_edi;
|
||||
_extern C32_EFLAGS U32 c32_eflags;
|
||||
_extern SYS_PCI_SERVICES U32 sys_pci_services;
|
||||
|
||||
//Not reentrant--used to call BIOS32
|
||||
//Takes like, 250uS.
|
||||
_extern _FAR_CALL32 Bool FarCall32(U0 (*fp_addr)());
|
||||
_extern _FAR_CALL32 Bool FarCall32(U0 (*fp_addr)()); //Not reentrant used to call BIOS32. Takes 250uS.
|
||||
|
||||
U8 PCIReadU8(I64 bus,I64 dev,I64 fun,I64 rg)
|
||||
{
|
||||
{//Read U8 in PCI configspace at bus,dev,fun,reg.
|
||||
I64 result;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -190,7 +185,7 @@ U8 PCIReadU8(I64 bus,I64 dev,I64 fun,I64 rg)
|
||||
}
|
||||
|
||||
U16 PCIReadU16(I64 bus,I64 dev,I64 fun,I64 rg)
|
||||
{
|
||||
{//Read U16 in PCI configspace at bus,dev,fun,reg.
|
||||
I64 result;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -209,7 +204,7 @@ U16 PCIReadU16(I64 bus,I64 dev,I64 fun,I64 rg)
|
||||
}
|
||||
|
||||
U32 PCIReadU32(I64 bus,I64 dev,I64 fun,I64 rg)
|
||||
{
|
||||
{//Read U32 in PCI configspace at bus,dev,fun,reg.
|
||||
I64 result;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -228,7 +223,7 @@ U32 PCIReadU32(I64 bus,I64 dev,I64 fun,I64 rg)
|
||||
}
|
||||
|
||||
U0 PCIWriteU8(I64 bus,I64 dev,I64 fun,I64 rg,I64 val)
|
||||
{
|
||||
{//Write U8 in PCI configspace at bus,dev,fun,reg.
|
||||
PUSHFD
|
||||
CLI
|
||||
while (LBts(&sys_semas[SYS_SEMA_FAR_CALL32],0))
|
||||
@@ -243,7 +238,7 @@ U0 PCIWriteU8(I64 bus,I64 dev,I64 fun,I64 rg,I64 val)
|
||||
}
|
||||
|
||||
U0 PCIWriteU16(I64 bus,I64 dev,I64 fun,I64 rg,I64 val)
|
||||
{
|
||||
{//Write U16 in PCI configspace at bus,dev,fun,reg.
|
||||
PUSHFD
|
||||
CLI
|
||||
while (LBts(&sys_semas[SYS_SEMA_FAR_CALL32],0))
|
||||
@@ -258,7 +253,7 @@ U0 PCIWriteU16(I64 bus,I64 dev,I64 fun,I64 rg,I64 val)
|
||||
}
|
||||
|
||||
U0 PCIWriteU32(I64 bus,I64 dev,I64 fun,I64 rg,I64 val)
|
||||
{
|
||||
{//Write U32 in PCI configspace at bus,dev,fun,reg.
|
||||
PUSHFD
|
||||
CLI
|
||||
while (LBts(&sys_semas[SYS_SEMA_FAR_CALL32],0))
|
||||
@@ -273,11 +268,13 @@ U0 PCIWriteU32(I64 bus,I64 dev,I64 fun,I64 rg,I64 val)
|
||||
}
|
||||
|
||||
I64 PCIClassFind(I64 class_code,I64 n)
|
||||
{
|
||||
//class_code is low three bytes
|
||||
//n is index starting at zero
|
||||
//Returns: -1 not found
|
||||
// else bus,dev,fun.
|
||||
{/*Find bus,dev,fun of Nth class_code dev.
|
||||
|
||||
class_code is low three bytes
|
||||
n is index starting at zero
|
||||
Return: -1 not found
|
||||
else bus,dev,fun.
|
||||
*/
|
||||
I64 result;
|
||||
PUSHFD
|
||||
CLI
|
||||
|
||||
+7
-11
@@ -109,9 +109,7 @@ I64 ArcDetermineCompressionType(U8 *src,I64 size)
|
||||
}
|
||||
|
||||
U0 ArcCompressBuf(CArcCtrl *c)
|
||||
//Use $LK,"CompressBuf",A="MN:CompressBuf"$() unless you are doing
|
||||
//more than one buffer.
|
||||
{
|
||||
{//Use $LK,"CompressBuf",A="MN:CompressBuf"$() unless doing more than one buf.
|
||||
CArcEntry *temp,*temp1;
|
||||
I64 ch,basecode;
|
||||
U8 *src_ptr,*src_limit;
|
||||
@@ -156,7 +154,7 @@ ac_done:
|
||||
}
|
||||
|
||||
U0 ArcFinishCompression(CArcCtrl *c)
|
||||
{
|
||||
{//Do closing touch on archivew ctrl struct.
|
||||
if (c->dst_pos+c->cur_bits_in_use<=c->dst_size) {
|
||||
BFieldOrU32(c->dst_buf,c->dst_pos,c->saved_basecode);
|
||||
c->dst_pos+=c->next_bits_in_use;
|
||||
@@ -164,9 +162,7 @@ U0 ArcFinishCompression(CArcCtrl *c)
|
||||
}
|
||||
|
||||
U0 ArcExpandBuf(CArcCtrl *c)
|
||||
//Use $LK,"ExpandBuf",A="MN:ExpandBuf"$() unless you know what
|
||||
//you're doing.
|
||||
{
|
||||
{//Use $LK,"ExpandBuf",A="MN:ExpandBuf"$() unless you know what you're doing.
|
||||
U8 *dst_ptr,*dst_limit;
|
||||
I64 basecode,lastcode,code;
|
||||
CArcEntry *temp,*temp1;
|
||||
@@ -222,7 +218,7 @@ U0 ArcExpandBuf(CArcCtrl *c)
|
||||
}
|
||||
|
||||
CArcCtrl *ArcCtrlNew(Bool expand,Bool seven_bit)
|
||||
{
|
||||
{//MAlloc archive ctrl struct.
|
||||
CArcCtrl *c;
|
||||
c=CAlloc(sizeof(CArcCtrl));
|
||||
if (expand) {
|
||||
@@ -245,13 +241,13 @@ CArcCtrl *ArcCtrlNew(Bool expand,Bool seven_bit)
|
||||
}
|
||||
|
||||
U0 ArcCtrlDel(CArcCtrl *c)
|
||||
{
|
||||
{//Free archive ctrl struct.
|
||||
Free(c->stk_base);
|
||||
Free(c);
|
||||
}
|
||||
|
||||
CArcCompress *CompressBuf(U8 *src,I64 size,I64 flags=0,CTask *mem_task=NULL)
|
||||
{
|
||||
{//See $LK,"::/Demo/Dsk/SerializeTree.CPP"$.
|
||||
CArcCompress *result;
|
||||
I64 size_out;
|
||||
Bool seven_bit=ArcDetermineCompressionType(src,size)==CT_7_BIT;
|
||||
@@ -286,7 +282,7 @@ CArcCompress *CompressBuf(U8 *src,I64 size,I64 flags=0,CTask *mem_task=NULL)
|
||||
}
|
||||
|
||||
U8 *ExpandBuf(CArcCompress *r,CTask *mem_task=NULL)
|
||||
{
|
||||
{//See $LK,"::/Demo/Dsk/SerializeTree.CPP"$.
|
||||
CArcCtrl *c;
|
||||
Bool seven_bit;
|
||||
U8 *result=MAlloc(r->expanded_size+1,mem_task);
|
||||
|
||||
+29
-29
@@ -1,5 +1,5 @@
|
||||
U0 LinkedLstDel(U8 **_lst)
|
||||
{
|
||||
{//Free entire linked-list.
|
||||
U8 **templ;
|
||||
while (_lst) {
|
||||
templ=*_lst;
|
||||
@@ -9,7 +9,7 @@ U0 LinkedLstDel(U8 **_lst)
|
||||
}
|
||||
|
||||
U8 *LinkedLstCopy(U8 **_lst,CTask *mem_task=NULL)
|
||||
{
|
||||
{//MAlloc identical copy of entire linked-list.
|
||||
U8 *result=NULL,**templ=&result;
|
||||
while (_lst) {
|
||||
templ=*templ=MAllocIdentical(_lst,mem_task);
|
||||
@@ -19,7 +19,7 @@ U8 *LinkedLstCopy(U8 **_lst,CTask *mem_task=NULL)
|
||||
}
|
||||
|
||||
I64 LinkedLstCnt(U8 **_lst)
|
||||
{
|
||||
{//Count of nodes in linked-list.
|
||||
I64 result=0;
|
||||
while (_lst) {
|
||||
result++;
|
||||
@@ -29,7 +29,7 @@ I64 LinkedLstCnt(U8 **_lst)
|
||||
}
|
||||
|
||||
I64 LinkedLstSize(U8 **_lst)
|
||||
{
|
||||
{//Mem size of all nodes in linked-list.
|
||||
I64 result=0;
|
||||
while (_lst) {
|
||||
result+=MSize2(_lst);
|
||||
@@ -38,8 +38,8 @@ I64 LinkedLstSize(U8 **_lst)
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 QueDel(CQue *root,Bool querem=FALSE) //Does not delete root
|
||||
{
|
||||
U0 QueDel(CQue *root,Bool querem=FALSE)
|
||||
{//Free entrie queue, not root.
|
||||
CQue *tempq=root->next,*tempq1;
|
||||
while (tempq!=root) {
|
||||
tempq1=tempq->next;
|
||||
@@ -51,7 +51,7 @@ U0 QueDel(CQue *root,Bool querem=FALSE) //Does not delete root
|
||||
}
|
||||
|
||||
CQue *QueCopy(CQue *root,CTask *mem_task=NULL)
|
||||
{
|
||||
{//MAlloc identical copy of entire queue and root.
|
||||
CQue *result=MAllocIdentical(root,mem_task),*tempq=root->next,*tempq1;
|
||||
QueInit(result);
|
||||
while (tempq!=root) {
|
||||
@@ -62,8 +62,8 @@ CQue *QueCopy(CQue *root,CTask *mem_task=NULL)
|
||||
return result;
|
||||
}
|
||||
|
||||
I64 QueCnt(CQue *root) //Does not include root
|
||||
{
|
||||
I64 QueCnt(CQue *root)
|
||||
{//Count of nodes in queue, not root.
|
||||
CQue *tempq=root->next;
|
||||
I64 result=0;
|
||||
while (tempq!=root) {
|
||||
@@ -73,8 +73,8 @@ I64 QueCnt(CQue *root) //Does not include root
|
||||
return result;
|
||||
}
|
||||
|
||||
I64 QueSize(CQue *root) //Does not include root
|
||||
{
|
||||
I64 QueSize(CQue *root)
|
||||
{//Mem size of all nodes in queue, not root.
|
||||
CQue *tempq=root->next;
|
||||
I64 result=0;
|
||||
while (tempq!=root) {
|
||||
@@ -85,7 +85,7 @@ I64 QueSize(CQue *root) //Does not include root
|
||||
}
|
||||
|
||||
CQueVectU8 *QueVectU8New(I64 min_index=0)
|
||||
{
|
||||
{//Create new queue vecter.
|
||||
CQueVectU8 *result=MAlloc(sizeof(CQueVectU8));
|
||||
result->next=result->last=result;
|
||||
result->total_cnt=result->node_cnt=0;
|
||||
@@ -94,7 +94,7 @@ CQueVectU8 *QueVectU8New(I64 min_index=0)
|
||||
}
|
||||
|
||||
U0 QueVectU8Put(CQueVectU8 *v,I64 index,U8 ch)
|
||||
{
|
||||
{//Put U8 at index i.
|
||||
CQueVectU8 *tempv;
|
||||
index-=v->min_index;
|
||||
if (index<0) return;
|
||||
@@ -130,7 +130,7 @@ U0 QueVectU8Put(CQueVectU8 *v,I64 index,U8 ch)
|
||||
}
|
||||
|
||||
U0 QueVectU8Del(CQueVectU8 *v)
|
||||
{
|
||||
{//Free entire queue vector.
|
||||
if (v) {
|
||||
QueDel(v);
|
||||
Free(v);
|
||||
@@ -138,7 +138,7 @@ U0 QueVectU8Del(CQueVectU8 *v)
|
||||
}
|
||||
|
||||
I64 QueVectU8Get(CQueVectU8 *v,I64 index)
|
||||
{
|
||||
{//Get U8 at index i.
|
||||
CQueVectU8 *tempv;
|
||||
index-=v->min_index;
|
||||
if (!(0<=index<v->total_cnt)) return 0;
|
||||
@@ -153,7 +153,7 @@ I64 QueVectU8Get(CQueVectU8 *v,I64 index)
|
||||
}
|
||||
|
||||
CFifoU8 *FifoU8New(I64 size,CTask *mem_task=NULL)
|
||||
{
|
||||
{//Create new fifo.
|
||||
CFifoU8 *f;
|
||||
if (!mem_task) mem_task=Fs;
|
||||
f=MAlloc(sizeof(CFifoU8),mem_task);
|
||||
@@ -165,13 +165,13 @@ CFifoU8 *FifoU8New(I64 size,CTask *mem_task=NULL)
|
||||
}
|
||||
|
||||
U0 FifoU8Del(CFifoU8 *f)
|
||||
{
|
||||
{//Free fifo.
|
||||
Free(f->buf);
|
||||
Free(f);
|
||||
}
|
||||
|
||||
Bool FifoU8Ins(CFifoU8 *f,U8 b)
|
||||
{
|
||||
{//Insert U8 into fifo.
|
||||
I64 new_in_ptr;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -188,7 +188,7 @@ Bool FifoU8Ins(CFifoU8 *f,U8 b)
|
||||
}
|
||||
|
||||
Bool FifoU8Rem(CFifoU8 *f,U8 *_b)
|
||||
{
|
||||
{//Remove U8 from fifo.
|
||||
PUSHFD
|
||||
CLI
|
||||
if (f->in_ptr==f->out_ptr) {
|
||||
@@ -203,7 +203,7 @@ Bool FifoU8Rem(CFifoU8 *f,U8 *_b)
|
||||
}
|
||||
|
||||
Bool FifoU8Peek(CFifoU8 *f,U8 *_b)
|
||||
{
|
||||
{//Peek at front of fifo and don't remove.
|
||||
PUSHFD
|
||||
CLI
|
||||
if (f->in_ptr==f->out_ptr) {
|
||||
@@ -217,7 +217,7 @@ Bool FifoU8Peek(CFifoU8 *f,U8 *_b)
|
||||
}
|
||||
|
||||
U0 FifoU8Flush(CFifoU8 *f)
|
||||
{
|
||||
{//Flush fifo getting rid of all U8's.
|
||||
PUSHFD
|
||||
CLI
|
||||
f->out_ptr=f->in_ptr;
|
||||
@@ -225,7 +225,7 @@ U0 FifoU8Flush(CFifoU8 *f)
|
||||
}
|
||||
|
||||
I64 FifoU8Cnt(CFifoU8 *f)
|
||||
{
|
||||
{//Count of U8's in fifo.
|
||||
I64 result;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -238,7 +238,7 @@ I64 FifoU8Cnt(CFifoU8 *f)
|
||||
}
|
||||
|
||||
CFifoI64 *FifoI64New(I64 size,CTask *mem_task=NULL)
|
||||
{
|
||||
{//Create new fifo.
|
||||
CFifoI64 *f;
|
||||
if (!mem_task) mem_task=Fs;
|
||||
f=MAlloc(sizeof(CFifoI64),mem_task);
|
||||
@@ -250,13 +250,13 @@ CFifoI64 *FifoI64New(I64 size,CTask *mem_task=NULL)
|
||||
}
|
||||
|
||||
U0 FifoI64Del(CFifoI64 *f)
|
||||
{
|
||||
{//Free fifo.
|
||||
Free(f->buf);
|
||||
Free(f);
|
||||
}
|
||||
|
||||
Bool FifoI64Ins(CFifoI64 *f,I64 q)
|
||||
{
|
||||
{//Insert I64 into fifo.
|
||||
I64 new_in_ptr;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -273,7 +273,7 @@ Bool FifoI64Ins(CFifoI64 *f,I64 q)
|
||||
}
|
||||
|
||||
Bool FifoI64Rem(CFifoI64 *f,I64 *_q)
|
||||
{
|
||||
{//Remove I64 from fifo.
|
||||
PUSHFD
|
||||
CLI
|
||||
if (f->in_ptr==f->out_ptr) {
|
||||
@@ -288,7 +288,7 @@ Bool FifoI64Rem(CFifoI64 *f,I64 *_q)
|
||||
}
|
||||
|
||||
Bool FifoI64Peek(CFifoI64 *f,I64 *_q)
|
||||
{
|
||||
{//Peek at front of fifo and don't remove.
|
||||
PUSHFD
|
||||
CLI
|
||||
if (f->in_ptr==f->out_ptr) {
|
||||
@@ -302,7 +302,7 @@ Bool FifoI64Peek(CFifoI64 *f,I64 *_q)
|
||||
}
|
||||
|
||||
U0 FifoI64Flush(CFifoI64 *f)
|
||||
{
|
||||
{//Flush fifo getting rid of all I64's.
|
||||
PUSHFD
|
||||
CLI
|
||||
f->out_ptr=f->in_ptr;
|
||||
@@ -310,7 +310,7 @@ U0 FifoI64Flush(CFifoI64 *f)
|
||||
}
|
||||
|
||||
I64 FifoI64Cnt(CFifoI64 *f)
|
||||
{
|
||||
{//Count of I64's in fifo.
|
||||
I64 result;
|
||||
PUSHFD
|
||||
CLI
|
||||
|
||||
+16
-85
@@ -6,13 +6,13 @@ U16 mon_start_days2[12]={
|
||||
0,31,60,91,121,152,182,213,244,274,305,335};
|
||||
|
||||
I64 YearStartDate(I64 year)
|
||||
{
|
||||
{//32-bit day since AD 0, given year number.
|
||||
I64 y1=year-1,yd4000=y1/4000,yd400=y1/400,yd100=y1/100,yd4=y1/4;
|
||||
return year*365+yd4-yd100+yd400-yd4000;
|
||||
}
|
||||
|
||||
CDate Struct2Date(CDateStruct *_ds)
|
||||
{
|
||||
{//Cvt CDateStruct to CDate.
|
||||
CDate cdt;
|
||||
I64 i1,i2;
|
||||
i1=YearStartDate(_ds->year);
|
||||
@@ -27,7 +27,7 @@ CDate Struct2Date(CDateStruct *_ds)
|
||||
}
|
||||
|
||||
I64 DayOfWeek(I64 i)
|
||||
{
|
||||
{//Day of week, given 32-bit day since AD 0.
|
||||
i+=CDATE_BASE_DAY_OF_WEEK;
|
||||
if (i>=0)
|
||||
return i % 7;
|
||||
@@ -36,7 +36,7 @@ I64 DayOfWeek(I64 i)
|
||||
}
|
||||
|
||||
U0 Date2Struct(CDateStruct *_ds,CDate cdt)
|
||||
{
|
||||
{//Cvt CDate to CDateStruct.
|
||||
I64 i,k,date=cdt.date;
|
||||
_ds->day_of_week=DayOfWeek(date);
|
||||
_ds->year=(date+1)*100000/CDATE_YEAR_DAYS_INT;
|
||||
@@ -68,7 +68,7 @@ U0 Date2Struct(CDateStruct *_ds,CDate cdt)
|
||||
}
|
||||
|
||||
I64 FirstDayOfMon(I64 i)
|
||||
{
|
||||
{//First day of month, given 32-bit day since AD 0.
|
||||
CDateStruct ds;
|
||||
CDate cdt=0;
|
||||
cdt.date=i;
|
||||
@@ -79,7 +79,7 @@ I64 FirstDayOfMon(I64 i)
|
||||
}
|
||||
|
||||
I64 LastDayOfMon(I64 i)
|
||||
{
|
||||
{//Last day of month, given 32-bit day since AD 0.
|
||||
CDateStruct ds;
|
||||
CDate cdt=0;
|
||||
cdt.date=i;
|
||||
@@ -95,7 +95,7 @@ I64 LastDayOfMon(I64 i)
|
||||
}
|
||||
|
||||
I64 FirstDayOfYear(I64 i)
|
||||
{
|
||||
{//First day of year, given 32-bit day since AD 0.
|
||||
CDateStruct ds;
|
||||
CDate cdt=0;
|
||||
cdt.date=i;
|
||||
@@ -107,7 +107,7 @@ I64 FirstDayOfYear(I64 i)
|
||||
}
|
||||
|
||||
I64 LastDayOfYear(I64 i)
|
||||
{
|
||||
{//Last day of year, given 32-bit day since AD 0.
|
||||
CDateStruct ds;
|
||||
CDate cdt=0;
|
||||
cdt.date=i;
|
||||
@@ -119,7 +119,6 @@ I64 LastDayOfYear(I64 i)
|
||||
return cdt.date-1;
|
||||
}
|
||||
|
||||
|
||||
I64 Bcd2Bin(U64 b)
|
||||
{
|
||||
I64 i,result=0;
|
||||
@@ -130,8 +129,7 @@ I64 Bcd2Bin(U64 b)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
U0 GetDateTimeStruct(CDateStruct *_ds)
|
||||
U0 NowDateTimeStruct(CDateStruct *_ds)
|
||||
{
|
||||
I64 i;
|
||||
U8 *b=_ds;
|
||||
@@ -179,86 +177,19 @@ U0 GetDateTimeStruct(CDateStruct *_ds)
|
||||
for (i=2;i<9;i++)
|
||||
b[i]=Bcd2Bin(b[i]);
|
||||
|
||||
if (_ds->year>255) _ds->year=255;
|
||||
if (_ds->year>255) _ds->year=255;
|
||||
_ds->year+=2000;
|
||||
if (_ds->mon>12) _ds->mon=12;
|
||||
if (_ds->mon>12) _ds->mon=12;
|
||||
if (_ds->day_of_mon>31) _ds->day_of_mon=31;
|
||||
if (_ds->day_of_week>6) _ds->day_of_week=6;
|
||||
if (_ds->hour>23) _ds->hour=23;
|
||||
if (_ds->min>59) _ds->min=59;
|
||||
if (_ds->sec>59) _ds->sec=59;
|
||||
if (_ds->hour>23) _ds->hour=23;
|
||||
if (_ds->min>59) _ds->min=59;
|
||||
if (_ds->sec>59) _ds->sec=59;
|
||||
}
|
||||
|
||||
CDate Now()
|
||||
{
|
||||
{//Current datetime.
|
||||
CDateStruct ds;
|
||||
GetDateTimeStruct(&ds);
|
||||
NowDateTimeStruct(&ds);
|
||||
return Struct2Date(&ds)-local_time_offset;
|
||||
}
|
||||
|
||||
I64 Second(CDate cdt=MIN_I64)
|
||||
{
|
||||
CDateStruct ds;
|
||||
if (cdt==MIN_I64) cdt=Now;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
return ds.sec;
|
||||
}
|
||||
|
||||
I64 Minute(CDate cdt=MIN_I64)
|
||||
{
|
||||
CDateStruct ds;
|
||||
if (cdt==MIN_I64) cdt=Now;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
return ds.min;
|
||||
}
|
||||
|
||||
I64 Hour12(CDate cdt=MIN_I64)
|
||||
{
|
||||
CDateStruct ds;
|
||||
if (cdt==MIN_I64) cdt=Now;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
if (ds.hour>=12)
|
||||
return ds.hour-12;
|
||||
else
|
||||
return ds.hour;
|
||||
}
|
||||
|
||||
I64 Hour24(CDate cdt=MIN_I64)
|
||||
{
|
||||
CDateStruct ds;
|
||||
if (cdt==MIN_I64) cdt=Now;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
return ds.hour;
|
||||
}
|
||||
|
||||
I64 Day(CDate cdt=MIN_I64)
|
||||
{
|
||||
CDateStruct ds;
|
||||
if (cdt==MIN_I64) cdt=Now;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
return ds.day_of_mon;
|
||||
}
|
||||
|
||||
I64 WeekDay(CDate cdt=MIN_I64)
|
||||
{
|
||||
CDateStruct ds;
|
||||
if (cdt==MIN_I64) cdt=Now;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
return ds.day_of_week;
|
||||
}
|
||||
|
||||
I64 Month(CDate cdt=MIN_I64)
|
||||
{ //Jan is 1
|
||||
CDateStruct ds;
|
||||
if (cdt==MIN_I64) cdt=Now;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
return ds.mon;
|
||||
}
|
||||
|
||||
I64 Year(CDate cdt=MIN_I64)
|
||||
{
|
||||
CDateStruct ds;
|
||||
if (cdt==MIN_I64) cdt=Now;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
return ds.year;
|
||||
}
|
||||
+100
-114
@@ -1,5 +1,5 @@
|
||||
Bool ChkPtr(U8 *ptr)
|
||||
{
|
||||
{//Check if addr is valid ptr.
|
||||
if (sys_heap_base<=ptr<=MEM_MAPPED_SPACE) {
|
||||
if (*MemPageTable(ptr)&1)
|
||||
return TRUE;
|
||||
@@ -14,7 +14,7 @@ Bool ChkPtr(U8 *ptr)
|
||||
}
|
||||
|
||||
Bool ChkCodePtr(U8 *ptr)
|
||||
{
|
||||
{//Check if addr is valid code addr.
|
||||
if (sys_heap_base<=ptr<=sys_heap_limit) {
|
||||
if (*MemPageTable(ptr)&1)
|
||||
return TRUE;
|
||||
@@ -29,7 +29,7 @@ Bool ChkCodePtr(U8 *ptr)
|
||||
}
|
||||
|
||||
Bool ChkOnStk(U8 *ptr,CTask *task=NULL)
|
||||
{
|
||||
{//Check if addr is valid stk addr.
|
||||
Bool result=FALSE;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -43,7 +43,7 @@ Bool ChkOnStk(U8 *ptr,CTask *task=NULL)
|
||||
}
|
||||
|
||||
I64 UnusedStk(CTask *task=NULL)
|
||||
{
|
||||
{//Count of usused bytes in task's stk.
|
||||
I64 result;
|
||||
if (!task) task=Fs;
|
||||
PUSHFD
|
||||
@@ -57,10 +57,8 @@ I64 UnusedStk(CTask *task=NULL)
|
||||
}
|
||||
|
||||
U8 *Caller(I64 num=1)
|
||||
//Returns the addr of the fun
|
||||
//which called this one, or the caller
|
||||
//of the caller, etc.
|
||||
{
|
||||
{//Returns the addr of the fun which called this one,
|
||||
//or the caller of the caller, etc.
|
||||
U8 **rbp=GetRBP,**ptr;
|
||||
while (num--) {
|
||||
if (rbp>=*rbp)
|
||||
@@ -74,7 +72,7 @@ U8 *Caller(I64 num=1)
|
||||
}
|
||||
|
||||
U8 *TaskCaller(CTask *task=NULL,I64 num=0,Bool saved_context=FALSE)
|
||||
{
|
||||
{//Fetches addr of Nth caller on task's stk.
|
||||
U8 **ptr,**rbp,**rsp;
|
||||
if (!task) task=Fs;
|
||||
if (!saved_context && task==Fs)
|
||||
@@ -103,8 +101,7 @@ U8 *TaskCaller(CTask *task=NULL,I64 num=0,Bool saved_context=FALSE)
|
||||
#define STK_REP_LEN 32
|
||||
|
||||
U0 StkRep(CTask *task=NULL)
|
||||
//Reports whats on the stk
|
||||
{
|
||||
{//Reports whats on the stk.
|
||||
I64 i,j,addr,
|
||||
**rbp,**rsp,*my_rsp[STK_REP_LEN];
|
||||
CHashTable *old_hash=Fs->hash_table;
|
||||
@@ -146,13 +143,12 @@ U0 StkRep(CTask *task=NULL)
|
||||
"$$RED$$";
|
||||
"%P$$FG$$\n",my_rsp[i];
|
||||
}
|
||||
NewLine;
|
||||
'\n';
|
||||
Fs->hash_table=old_hash;
|
||||
}
|
||||
|
||||
U0 CallerRep(U8 **rbp=NULL,CTask *task=NULL)
|
||||
//Prints a report of calling routines
|
||||
{
|
||||
{//Prints a report of calling routines.
|
||||
I64 **ptr;
|
||||
if (!task) task=Fs;
|
||||
if (!rbp) {
|
||||
@@ -172,9 +168,8 @@ U0 CallerRep(U8 **rbp=NULL,CTask *task=NULL)
|
||||
}
|
||||
|
||||
U0 D(U8 *addr,I64 cnt=0x80,Bool show_offset=TRUE)
|
||||
//Dump mem, showing offsets.
|
||||
{//Dump mem, showing offsets.
|
||||
//See $LK,"DocD",A="MN:DocD"$() for a live dump.
|
||||
{
|
||||
I64 i,j,ch;
|
||||
U8 *ptr=addr;
|
||||
while (cnt) {
|
||||
@@ -198,21 +193,19 @@ U0 D(U8 *addr,I64 cnt=0x80,Bool show_offset=TRUE)
|
||||
if (ch=='$$')
|
||||
'' ch;
|
||||
}
|
||||
NewLine;
|
||||
'\n';
|
||||
cnt-=j;
|
||||
ptr+=j;
|
||||
}
|
||||
}
|
||||
|
||||
U0 Dm(U8 *addr,I64 cnt=0x80)
|
||||
//Show mem addr, not offsets
|
||||
{
|
||||
{//Show mem addr, not offsets.
|
||||
D(addr,cnt,FALSE);
|
||||
}
|
||||
|
||||
U0 Da(U8 **addr,I64 cnt=0x10)
|
||||
//Dump mem, showing symbolic addresses
|
||||
{
|
||||
{//Dump mem, showing symbolic addresses.
|
||||
while (cnt-->0) {
|
||||
"%08X:%08X,%P\n",addr,*addr,*addr;
|
||||
addr++;
|
||||
@@ -220,11 +213,9 @@ U0 Da(U8 **addr,I64 cnt=0x10)
|
||||
}
|
||||
|
||||
U0 RawPrint(I64 mS=100,U8 *fmt,...)
|
||||
//Print using $LK,"Raw",A="MN:Raw"$ screen
|
||||
//output for a length of time.
|
||||
{//Print using $LK,"Raw",A="MN:Raw"$ screen output for a length of time.
|
||||
//$BK,1$Your heap must be good.$BK,0$
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
Bool old_raw,old_input_filter;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -239,10 +230,9 @@ U0 RawPrint(I64 mS=100,U8 *fmt,...)
|
||||
}
|
||||
|
||||
U0 RawD(I64 mS=100,U8 *addr,I64 cnt=0x80)
|
||||
//Dumps a block of mem using $LK,"Raw",A="MN:Raw"$
|
||||
{//Dumps a block of mem using $LK,"Raw",A="MN:Raw"$
|
||||
//screen output for a fixed length
|
||||
//of time.
|
||||
{
|
||||
Bool old_raw,old_input_filter;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -256,10 +246,9 @@ U0 RawD(I64 mS=100,U8 *addr,I64 cnt=0x80)
|
||||
}
|
||||
|
||||
U0 RawDm(I64 mS=100,U8 *addr,I64 cnt=0x80)
|
||||
//Dumps a block of mem using $LK,"Raw",A="MN:Raw"$
|
||||
{//Dumps a block of mem using $LK,"Raw",A="MN:Raw"$
|
||||
//screen output for a fixed length
|
||||
//of time.
|
||||
{
|
||||
Bool old_raw,old_input_filter;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -299,38 +288,38 @@ I64 *TaskRegAddr(CTask *task,I64 reg_num)
|
||||
|
||||
U0 RawDr(CTask *task=NULL)
|
||||
{
|
||||
I64 i,j,old_col=sys_raw_col;
|
||||
I64 i,j,old_col=text.raw_col;
|
||||
Bool old_raw=Raw(ON);
|
||||
U8 buf[200];
|
||||
|
||||
if (!task) task=Fs;
|
||||
|
||||
for (i=0;i<16;i++) {
|
||||
sys_raw_col=i*text_cols+RAWDR_COL;
|
||||
text.raw_col=i*text.cols+RAWDR_COL;
|
||||
"º%3Z:%016X\n",i,"ST_U64_REGS",*TaskRegAddr(task,i);
|
||||
}
|
||||
|
||||
sys_raw_col=i++*text_cols+RAWDR_COL;
|
||||
text.raw_col=i++*text.cols+RAWDR_COL;
|
||||
"ºRIP:%016X\n",task->rip;
|
||||
|
||||
sys_raw_col=i++*text_cols+RAWDR_COL;
|
||||
"º%-*tp\n",text_cols-(RAWDR_COL+1)-1,Fs->rip;
|
||||
text.raw_col=i++*text.cols+RAWDR_COL;
|
||||
"º%-*tp\n",text.cols-(RAWDR_COL+1)-1,Fs->rip;
|
||||
|
||||
sys_raw_col=i++*text_cols+RAWDR_COL;
|
||||
text.raw_col=i++*text.cols+RAWDR_COL;
|
||||
'º';
|
||||
if (Bt(&sys_run_level,RLf_COMPILER)) {
|
||||
j=Fs->rip;
|
||||
Ui(buf,&j,,,TRUE);
|
||||
"%s",buf;
|
||||
} else
|
||||
NewLine;
|
||||
'\n';
|
||||
|
||||
sys_raw_col=i*text_cols+RAWDR_COL;
|
||||
text.raw_col=i*text.cols+RAWDR_COL;
|
||||
'È';
|
||||
for (j=0;j<text_cols-RAWDR_COL-1;j++)
|
||||
for (j=0;j<text.cols-RAWDR_COL-1;j++)
|
||||
'Í';
|
||||
|
||||
sys_raw_col=old_col;
|
||||
text.raw_col=old_col;
|
||||
Raw(old_raw);
|
||||
}
|
||||
|
||||
@@ -350,7 +339,7 @@ U0 OverRideSingleUserSwap()
|
||||
SingleUser(old_single);
|
||||
}
|
||||
|
||||
U8 *SysMGetS(I64)
|
||||
U8 *SysGetStr2(I64)
|
||||
{
|
||||
U8 buf[512];
|
||||
GetS(buf,512,FALSE);
|
||||
@@ -382,7 +371,7 @@ CBpt *BptFind(U8 *needle_addr,CTask *haystack_task=NULL,Bool rem=FALSE)
|
||||
}
|
||||
|
||||
Bool BptS(U8 *addr,CTask *task=NULL,Bool live=TRUE)
|
||||
{//Set breakpoint
|
||||
{//Set breakpoint.
|
||||
CBpt *tempb;
|
||||
Bool result=TRUE;
|
||||
if (!task) task=Fs;
|
||||
@@ -403,7 +392,7 @@ Bool BptS(U8 *addr,CTask *task=NULL,Bool live=TRUE)
|
||||
}
|
||||
|
||||
Bool BptR(U8 *addr,CTask *task=NULL,Bool live=TRUE,Bool rem=TRUE)
|
||||
{//Rem breakpoint
|
||||
{//Rem breakpoint.
|
||||
CBpt *tempb;
|
||||
Bool result=FALSE;
|
||||
if (!task) task=Fs;
|
||||
@@ -421,8 +410,8 @@ Bool BptR(U8 *addr,CTask *task=NULL,Bool live=TRUE,Bool rem=TRUE)
|
||||
}
|
||||
|
||||
Bool B(U8 *addr,CTask *task=NULL,Bool live=TRUE)
|
||||
{//Toggle breakpoint
|
||||
//Returns TRUE if removed
|
||||
{//Toggle breakpoint.
|
||||
//Return: TRUE if removed.
|
||||
Bool result=FALSE;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -436,8 +425,8 @@ Bool B(U8 *addr,CTask *task=NULL,Bool live=TRUE)
|
||||
}
|
||||
|
||||
I64 B2(CTask *task=NULL,Bool live=TRUE)
|
||||
{ //Rem all breakpoints
|
||||
//Returns cnt of removed
|
||||
{//Rem all breakpoints.
|
||||
//Return: cnt of removed.
|
||||
I64 result=0;
|
||||
CBpt *tempb,*tempb1;
|
||||
if (!task) task=Fs;
|
||||
@@ -458,17 +447,16 @@ I64 B2(CTask *task=NULL,Bool live=TRUE)
|
||||
}
|
||||
|
||||
U0 G(U8 *ip=INVALID_PTR,CTask *task=NULL)
|
||||
//Go
|
||||
{
|
||||
{//Go
|
||||
if (!task) task=Fs;
|
||||
if (ip!=INVALID_PTR) task->rip=ip;
|
||||
if (BptFind(task->rip,task))
|
||||
"\nDo one of the following, first:\n"
|
||||
">S;\t\t\t//Single step\n"
|
||||
">B2;\t\t\t//Clear all break points\n"
|
||||
">G2;\t\t\t//Clear all break points and Go\n\n"
|
||||
"After resuming, <CTRL-ALT-T> changes focus task\n"
|
||||
"After resuming, <CTRL-ALT-F> flushes screen VGA cache\n";
|
||||
"\nDo one of the following, first:\n"
|
||||
">S;\t\t\t//Single step\n"
|
||||
">B2;\t\t\t//Clear all break points\n"
|
||||
">G2;\t\t\t//Clear all break points and Go\n\n"
|
||||
"After resuming, <CTRL-ALT-t> changes focus task\n"
|
||||
"After resuming, <CTRL-ALT-f> flushes screen VGA cache\n";
|
||||
else {
|
||||
LBtr(&task->task_flags,TASKf_DISABLE_BPTS);
|
||||
LBtr(&task->rflags,RFLAGf_TRAP);//No single step
|
||||
@@ -484,18 +472,17 @@ U0 G(U8 *ip=INVALID_PTR,CTask *task=NULL)
|
||||
}
|
||||
|
||||
U0 G2(U8 *ip=INVALID_PTR,CTask *task=NULL)
|
||||
//Rem all breakpoints and Go.
|
||||
{
|
||||
{//Rem all breakpoints and Go.
|
||||
if (!task) task=Fs;
|
||||
B2(task);
|
||||
if (ext[EXT_WIN_FOCUS])
|
||||
CallExtNum(EXT_WIN_FOCUS,sys_dbg_focus_task);
|
||||
CallExtNum(EXT_WIN_FOCUS,dbg.focus_task);
|
||||
VGAFlush;
|
||||
G(ip,task);
|
||||
}
|
||||
|
||||
public U0 S(U8 *ip=INVALID_PTR,CTask *task=NULL) //Single-step.
|
||||
{ //Single step
|
||||
{//Single step.
|
||||
if (!task) task=Fs;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -515,43 +502,43 @@ public U0 S(U8 *ip=INVALID_PTR,CTask *task=NULL) //Single-step.
|
||||
|
||||
U0 DbgHelp()
|
||||
{
|
||||
"\n"
|
||||
"The cmd line is basically the same as normal. Here are some common\n"
|
||||
"debugging commands.\n\n"
|
||||
">EdLite(\"FileName\");\t\t//Edit file.\n"
|
||||
">D(0x100000);\t\t\t//Dump page tables.\n"
|
||||
">Dm(0x100000);\t\t\t//Dump page tables.\n"
|
||||
">Dm(Fs,sizeof(CTask));\t\t//Dump current task record.\n"
|
||||
">ClassRep(Fs,\"CTask\",1);\t//Dump current task record.\n"
|
||||
">ClassRep(Fs,,1);\t\t//(It knows lastclass.)\n"
|
||||
">CallerRep;\t\t\t//Stack trace report.\n"
|
||||
">Da(_RSP);\t\t\t//Dump stk.\n"
|
||||
">Dr;\t\t\t\t//Dump Regs.\n"
|
||||
">1+2*3+&Print;\t\t\t//Show calculation result.\n"
|
||||
">*(0x70000)(I64 *)=0x123456789;\t//Assign value to 0x70000-0x70007.\n"
|
||||
">_RAX=0x1234;\t\t\t//Set RAX to 0x1234.\n"
|
||||
">_RIP=&SysThrowBreak;\t\t//Set RIP.\n"
|
||||
">I64 i;\t\t\t\t//Declare variable.\n"
|
||||
">i=_RCX+_RDX;\t\t\t//Assign to variable.\n"
|
||||
">U(&Print+0x8);\t\t\t//Unassemble Print.\n"
|
||||
">Uf(\"Print\");\t\t\t//Unassembler function \"Print\".\n"
|
||||
">Man(\"Print\");\t\t\t//Edit Src for \"Print\".\n"
|
||||
">E(_RIP);\t\t\t//Edit Src Code.\n"
|
||||
">Fix;\t\t\t\t//Edit Last Err Src Code.\n"
|
||||
">B(&Main+0x20);\t\t\t//Toggle break point.\n"
|
||||
">B2;\t\t\t\t//Clear all break points.\n"
|
||||
">S;\t\t\t\t//Single step.\n"
|
||||
">G;\t\t\t\t//Resume execution.\n"
|
||||
">G2;\t\t\t\t//B2;VGAFlush;WinFocus;G;\n"
|
||||
">Exit;\t\t\t\t//Exit (kill) task.\n\n"
|
||||
"After resuming, <CTRL-ALT-T> changes focus task.\n"
|
||||
"After resuming, <CTRL-ALT-F> flushes screen VGA cache.\n\n";
|
||||
"\n"
|
||||
"The cmd line is basically the same as normal. Here are some common\n"
|
||||
"debugging commands.\n\n"
|
||||
">EdLite(\"FileName\");\t\t//Edit file.\n"
|
||||
">D(0x100000);\t\t\t//Dump page tables.\n"
|
||||
">Dm(0x100000);\t\t\t//Dump page tables.\n"
|
||||
">Dm(Fs,sizeof(CTask));\t\t//Dump current task record.\n"
|
||||
">ClassRep(Fs,\"CTask\",1);\t//Dump current task record.\n"
|
||||
">ClassRep(Fs,,1);\t\t//(It knows lastclass.)\n"
|
||||
">CallerRep;\t\t\t//Stack trace report.\n"
|
||||
">Da(_RSP);\t\t\t//Dump stk.\n"
|
||||
">Dr;\t\t\t\t//Dump Regs.\n"
|
||||
">1+2*3+&Print;\t\t\t//Show calculation result.\n"
|
||||
">*(0x70000)(I64 *)=0x123456789;\t//Assign value to 0x70000-0x70007.\n"
|
||||
">_RAX=0x1234;\t\t\t//Set RAX to 0x1234.\n"
|
||||
">_RIP=&SysThrowBreak;\t\t//Set RIP.\n"
|
||||
">I64 i;\t\t\t\t//Declare variable.\n"
|
||||
">i=_RCX+_RDX;\t\t\t//Assign to variable.\n"
|
||||
">U(&Print+0x8);\t\t\t//Unassemble Print.\n"
|
||||
">Uf(\"Print\");\t\t\t//Unassembler function \"Print\".\n"
|
||||
">Man(\"Print\");\t\t\t//Edit Src for \"Print\".\n"
|
||||
">E(_RIP);\t\t\t//Edit Src Code.\n"
|
||||
">Fix;\t\t\t\t//Edit Last Err Src Code.\n"
|
||||
">B(&Main+0x20);\t\t\t//Toggle break point.\n"
|
||||
">B2;\t\t\t\t//Clear all break points.\n"
|
||||
">S;\t\t\t\t//Single step.\n"
|
||||
">G;\t\t\t\t//Resume execution.\n"
|
||||
">G2;\t\t\t\t//B2;VGAFlush;WinFocus;G;\n"
|
||||
">Exit;\t\t\t\t//Exit (kill) task.\n\n"
|
||||
"After resuming, <CTRL-ALT-t> changes focus task.\n"
|
||||
"After resuming, <CTRL-ALT-f> flushes screen VGA cache.\n\n";
|
||||
}
|
||||
|
||||
U0 Dbg2()
|
||||
{
|
||||
Bool old_win_inhibit,old_waiting_msg;
|
||||
I64 i,old_dbg_mgets;
|
||||
I64 i,old_getstr2;
|
||||
U8 buf[200];
|
||||
if (IsRaw) {
|
||||
i=Fs->rip;
|
||||
@@ -563,13 +550,13 @@ U0 Dbg2()
|
||||
old_win_inhibit=Fs->win_inhibit;
|
||||
Fs->win_inhibit=WIG_USER_TASK_DFT;
|
||||
sys_focus_task=Fs;
|
||||
sys_cur_scan_code=0;
|
||||
old_dbg_mgets=fp_mgets;
|
||||
fp_mgets=&SysMGetS;
|
||||
while (!mouse_install_attempts)
|
||||
kbd.scan_code=0;
|
||||
old_getstr2=fp_getstr2;
|
||||
fp_getstr2=&SysGetStr2;
|
||||
while (!mouse.install_attempts)
|
||||
OverRideSingleUserSwap;
|
||||
UserTaskCont;
|
||||
fp_mgets=old_dbg_mgets;
|
||||
fp_getstr2=old_getstr2;
|
||||
Fs->win_inhibit=old_win_inhibit;
|
||||
LBEqu(&Fs->task_flags,TASKf_AWAITING_MSG,old_waiting_msg);
|
||||
}
|
||||
@@ -581,12 +568,12 @@ U0 Fault3(I64 fault_num,I64 fault_err_code)
|
||||
PUSHFD
|
||||
CLI
|
||||
was_in_dbg=InDbg(ON);
|
||||
if (Gs->num && mp_crash) {
|
||||
if (Gs->num && dbg.mp_crash) {
|
||||
mp_cnt=1;
|
||||
mp_crash->cpu_num=Gs->num;
|
||||
mp_crash->task=Fs;
|
||||
mp_crash->msg=sys_dbg_msg;
|
||||
mp_crash->msg_num=sys_dbg_msg_num;
|
||||
dbg.mp_crash->cpu_num=Gs->num;
|
||||
dbg.mp_crash->task=Fs;
|
||||
dbg.mp_crash->msg=dbg.msg;
|
||||
dbg.mp_crash->msg_num=dbg.msg_num;
|
||||
MPInt(I_MP_CRASH,0);
|
||||
SysHlt;
|
||||
}
|
||||
@@ -594,10 +581,10 @@ U0 Fault3(I64 fault_num,I64 fault_err_code)
|
||||
">Help;\t//For help.\n\n";
|
||||
Beep(500,TRUE);
|
||||
if (fault_num==I_DBG) {
|
||||
if (sys_dbg_msg) {
|
||||
"\n!!! %s",sys_dbg_msg;
|
||||
if (sys_dbg_msg_num)
|
||||
"%016X",sys_dbg_msg_num;
|
||||
if (dbg.msg) {
|
||||
"\n!!! %s",dbg.msg;
|
||||
if (dbg.msg_num)
|
||||
"%016X",dbg.msg_num;
|
||||
" !!!\n\n";
|
||||
}
|
||||
}
|
||||
@@ -607,24 +594,24 @@ U0 Fault3(I64 fault_num,I64 fault_err_code)
|
||||
POPFD
|
||||
}
|
||||
|
||||
U0 Fault2(I64 fault_num,I64 fault_err_code) //Called from $LK,"Fault2",A="FF:::/Kernel/Interrupts.CPP,Fault2"$
|
||||
{
|
||||
U0 Fault2(I64 fault_num,I64 fault_err_code)
|
||||
{//Called from $LK,"Fault2",A="FF:::/Kernel/Ints.CPP,Fault2"$.
|
||||
//$BK,1$Be careful not to swap-out and ruin the saved context$BK,0$
|
||||
Bool was_raw,was_single_user,was_silent;
|
||||
I64 i,old_raw_flags=sys_raw_flags;
|
||||
I64 i,old_raw_flags=text.raw_flags;
|
||||
if (fault_num==I_DIVIDE_BY_ZERO) {
|
||||
"RIP:%P\n",Fs->rip;
|
||||
throw('DivZero');
|
||||
}
|
||||
was_single_user=SingleUser(ON);
|
||||
if (!IsDbg)
|
||||
sys_dbg_focus_task=sys_focus_task;
|
||||
dbg.focus_task=sys_focus_task;
|
||||
sys_focus_task=NULL;
|
||||
if (fault_num==I_BPT)
|
||||
Fs->rip--;
|
||||
was_raw=Raw(ON);
|
||||
was_silent=Silent(OFF);
|
||||
sys_raw_flags|=RWF_SHOW_DOLLAR|RWF_SCROLL;
|
||||
text.raw_flags|=RWF_SHOW_DOLLAR|RWF_SCROLL;
|
||||
|
||||
"Task \"";
|
||||
"%s",Fs->task_title;
|
||||
@@ -641,19 +628,18 @@ U0 Fault2(I64 fault_num,I64 fault_err_code) //Called from $LK,"Fault2",A="FF:::/
|
||||
|
||||
Silent(was_silent);
|
||||
Raw(was_raw);
|
||||
sys_raw_flags=old_raw_flags;
|
||||
text.raw_flags=old_raw_flags;
|
||||
SingleUser(was_single_user);
|
||||
if (LBtr(&Fs->task_flags,TASKf_KILL_AFTER_DBG))
|
||||
Exit;
|
||||
}
|
||||
|
||||
U0 Dbg(U8 *msg=NULL,I64 msg_num=0)
|
||||
//Enters the debugger. Can be used as a panic.
|
||||
{
|
||||
{//Enters the debugger. Can be used as a panic.
|
||||
PUSHFD
|
||||
CLI
|
||||
sys_dbg_msg=msg;
|
||||
sys_dbg_msg_num=msg_num;
|
||||
dbg.msg=msg;
|
||||
dbg.msg_num=msg_num;
|
||||
INT I_DBG
|
||||
POPFD
|
||||
}
|
||||
+89
-18
@@ -1,23 +1,23 @@
|
||||
CHashDefineStr *DefineLoad(U8 *name,U8 *st)
|
||||
{
|
||||
{//Create DEFINE hash entry with string.
|
||||
CHashDefineStr *temph=CAlloc(sizeof(CHashDefineStr));
|
||||
temph->type=HTT_DEFINE_STR;
|
||||
temph->str=StrNew(name);
|
||||
temph->data=StrNew(st);
|
||||
temph->cnt=-1;
|
||||
temph->src_link=MPrint("AD:0x%X",Caller);
|
||||
temph->src_link=MStrPrint("AD:0x%X",Caller);
|
||||
HashAdd(temph,Fs->hash_table);
|
||||
return temph;
|
||||
}
|
||||
|
||||
CHashDefineStr *DefineLstLoad(U8 *name,U8 *st)
|
||||
{ //Not especially efficient but handy.
|
||||
{//Create DEFINE list. Not efficient, but handy.
|
||||
I64 cnt=0;
|
||||
U8 *ptr,**lst;
|
||||
CHashDefineStr *temph=CAlloc(sizeof(CHashDefineStr));
|
||||
temph->type=HTT_DEFINE_STR;
|
||||
temph->str=StrNew(name);
|
||||
temph->src_link=MPrint("AD:0x%X",Caller);
|
||||
temph->src_link=MStrPrint("AD:0x%X",Caller);
|
||||
ptr=st;
|
||||
while (*ptr) {
|
||||
if (*ptr!='@')
|
||||
@@ -47,7 +47,7 @@ U0 UndefinedDefine(U8 *name)
|
||||
}
|
||||
|
||||
U8 *Define(U8 *name)
|
||||
{
|
||||
{//Look for DEFINE named in hash table, return ptr string.
|
||||
CHashDefineStr *temph;
|
||||
if (temph=HashFind(name,Fs->hash_table,HTT_DEFINE_STR))
|
||||
return temph->data;
|
||||
@@ -58,7 +58,7 @@ U8 *Define(U8 *name)
|
||||
}
|
||||
|
||||
U8 *DefineSub(I64 sub,U8 *name)
|
||||
{
|
||||
{//Return DEFINE list entry indexed by number.
|
||||
CHashDefineStr *temph;
|
||||
if (temph=HashFind(name,Fs->hash_table,HTT_DEFINE_STR)) {
|
||||
if (0<=sub<temph->cnt)
|
||||
@@ -72,7 +72,7 @@ U8 *DefineSub(I64 sub,U8 *name)
|
||||
}
|
||||
|
||||
I64 DefineCnt(U8 *name)
|
||||
{
|
||||
{//Return cnt of entries in define list.
|
||||
CHashDefineStr *temph;
|
||||
if (temph=HashFind(name,Fs->hash_table,HTT_DEFINE_STR))
|
||||
return temph->cnt;
|
||||
@@ -83,13 +83,13 @@ I64 DefineCnt(U8 *name)
|
||||
}
|
||||
|
||||
I64 DefineMatch(U8 *needle,U8 *haystack_lst_name,I64 flags=0)
|
||||
{
|
||||
{//Find match for string in define list.
|
||||
return LstMatch(needle,Define(haystack_lst_name),flags);
|
||||
}
|
||||
|
||||
U0 DefinePrint(U8 *name,U8 *src,...)
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,src,argc,argv);
|
||||
{//Create DEFINE entry with $LK,"Print",A="FI:::/Doc/Print.TXT"$()ed string.
|
||||
U8 *buf=StrPrintJoin(NULL,src,argc,argv);
|
||||
DefineLoad(name,buf);
|
||||
Free(buf);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ U0 SysDefinesLoad()
|
||||
"Thursday\0Friday\0Saturday\0");
|
||||
DefineLstLoad("ST_MONTHS","January\0February\0March\0April\0May\0"
|
||||
"June\0July\0August\0September\0October\0November\0December\0");
|
||||
DefineLstLoad("ST_FILE_ATTRS","R\0H\0S\0V\0D\0A\0 \0 \0X\0Y\0T\0Z\0C\0F\0");
|
||||
DefineLstLoad("ST_FILE_ATTRS","R\0H\0S\0V\0D\0A\0 \0 \0X\0T\0Z\0C\0F\0");
|
||||
DefineLstLoad("ST_FILE_UTIL_FLAGS","r\0d\0i\0a\0c\0R\0p\0m\0x\0s\0"
|
||||
"D\0F\0T\0S\0A\0J\0G\0Z\0O\0P\0f\0l\0lb\0la\0");
|
||||
DefineLstLoad("ST_BLKDEV_TYPES","NULL\0RAM\0ATA\0ATAPI\0");
|
||||
@@ -124,22 +124,93 @@ U0 SysDefinesLoad()
|
||||
"MP Crash\0Wake\0Dbg\0");
|
||||
}
|
||||
|
||||
U8 *Color2Text(U8 *buf,CColorROPU32 c)
|
||||
{
|
||||
U8 *Color2Str(U8 *buf,CColorROPU32 c)
|
||||
{//$LK,"CColorROPU32",A="MN:CColorROPU32"$ with flags to $LK,"GrLighting",A="MN:GrLighting"$ str.
|
||||
*buf=0;
|
||||
if (c.c0.rop&ROPBF_TWO_SIDED)
|
||||
CatPrint(buf,"TWO|");
|
||||
if (c.c0.rop&ROPBF_HALF_RANGE_COLOR)
|
||||
CatPrint(buf,"HALF|");
|
||||
if (0<=c.c0.color<16)
|
||||
StrCpy(buf,DefineSub(c.c0.color,"ST_COLORS"));
|
||||
else if (c.c0.color==COLOR_TRANSPARENT)
|
||||
StrCpy(buf,"TRANSPARENT");
|
||||
CatPrint(buf,DefineSub(c.c0.color,"ST_COLORS"));
|
||||
else if (c.c0.color==TRANSPARENT)
|
||||
CatPrint(buf,"TRANSPARENT");
|
||||
else
|
||||
StrCpy(buf,"INVALID");
|
||||
CatPrint(buf,"INVALID");
|
||||
if (c&ROPF_DITHER) {
|
||||
CatPrint(buf,"/");
|
||||
if (c.c1.rop&ROPBF_TWO_SIDED)
|
||||
CatPrint(buf,"TWO|");
|
||||
if (c.c1.rop&ROPBF_HALF_RANGE_COLOR)
|
||||
CatPrint(buf,"HALF|");
|
||||
if (0<=c.c1.color<16)
|
||||
CatPrint(buf,DefineSub(c.c1.color,"ST_COLORS"));
|
||||
else if (c.c1.color==COLOR_TRANSPARENT)
|
||||
else if (c.c1.color==TRANSPARENT)
|
||||
CatPrint(buf,"TRANSPARENT");
|
||||
else
|
||||
CatPrint(buf,"INVALID");
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
CColorROPU16 Str2ColorU16(U8 *st)
|
||||
{//$LK,"GrLighting",A="MN:GrLighting"$ color str with flags to $LK,"CColorROPU16",A="MN:CColorROPU16"$.
|
||||
CColorROPU16 result=COLOR_INVALID;
|
||||
I64 i;
|
||||
U8 *ptr,*ptr2,*st2;
|
||||
if (!st) return COLOR_INVALID;
|
||||
while (TRUE) {
|
||||
if (!*st||StrOcc("/,)}>",*st))
|
||||
return result;
|
||||
if (Bt(chars_bitmap_alpha,*st)) {
|
||||
ptr=st;
|
||||
while (Bt(chars_bitmap_alpha_numeric,*ptr))
|
||||
ptr++;
|
||||
st2=ptr2=MAlloc(ptr-st+1);
|
||||
while (st<ptr)
|
||||
*ptr2++=*st++;
|
||||
*ptr2++=0;
|
||||
if (!StrICmp(st2,"TWO"))
|
||||
result.rop|=ROPBF_TWO_SIDED;
|
||||
else if (!StrICmp(st2,"HALF"))
|
||||
result.rop|=ROPBF_HALF_RANGE_COLOR;
|
||||
else if ((i=DefineMatch(st2,"ST_COLORS",LMF_IGNORE_CASE))>=0)
|
||||
result.color=i;
|
||||
else if (!StrICmp(st2,"TRANSPARENT"))
|
||||
result.color=TRANSPARENT;
|
||||
else {
|
||||
Free(st2);
|
||||
return COLOR_INVALID;
|
||||
}
|
||||
Free(st2);
|
||||
} else if (*st=='+'||*st=='|'||Bt(chars_bitmap_white_space,*st))
|
||||
st++;
|
||||
else if ('0'<=*st<='9') {
|
||||
i=Str2I64(st,10,&ptr);
|
||||
if (0<=i<=0xFF) {
|
||||
result.color=i;
|
||||
st=ptr;
|
||||
} else
|
||||
return COLOR_INVALID;
|
||||
} else
|
||||
return COLOR_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
CColorROPU32 Str2ColorU32(U8 *st)
|
||||
{//$LK,"GrLighting",A="MN:GrLighting"$ color str with flags to $LK,"CColorROPU32",A="MN:CColorROPU32"$.
|
||||
U8 *st2;
|
||||
CColorROPU32 result=0;
|
||||
if (!st) return COLOR_INVALID;
|
||||
st2=MAlloc(StrLen(st)+1);
|
||||
StrFirstRem(st,"/,)}>",st2);
|
||||
result.c0=Str2ColorU16(st2);
|
||||
if (*st) {
|
||||
result.c1=Str2ColorU16(st);
|
||||
result|=ROPF_DITHER;
|
||||
}
|
||||
if (result.c0.color==COLOR_INVALID||result.c1.color==COLOR_INVALID)
|
||||
return COLOR_INVALID;
|
||||
else
|
||||
return result;
|
||||
}
|
||||
+48
-199
@@ -1,105 +1,101 @@
|
||||
U0 RawPutChar(I64 ch)
|
||||
{
|
||||
/* This is for RAW output during boot
|
||||
before the window mgr is running
|
||||
and for the debugger.
|
||||
{/*For RAW output during boot and in debugger.
|
||||
|
||||
See $LK,"GrUpdateForegroundOfText",A="MN:GrUpdateForegroundOfText"$ for
|
||||
See $LK,"GrUpdateTextFG",A="MN:GrUpdateTextFG"$ for
|
||||
the normal screen text output routine.
|
||||
|
||||
See also $LK,"GrUpdateScreen",A="MN:GrUpdateScreen"$().
|
||||
|
||||
*/
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
I64 i,row,col;
|
||||
U8 *ptr,*ptr1,*ptr2;
|
||||
|
||||
if (!(sys_raw_flags&RWF_SHOW_DOLLAR)) {
|
||||
if (!(text.raw_flags&RWF_SHOW_DOLLAR)) {
|
||||
if (ch=='$$') {
|
||||
if (sys_raw_flags&RWF_IN_DOLLAR) {
|
||||
sys_raw_flags&=~RWF_IN_DOLLAR;
|
||||
if (!(sys_raw_flags & RWF_LAST_DOLLAR)) {
|
||||
sys_raw_flags&=~RWF_LAST_DOLLAR;
|
||||
if (text.raw_flags&RWF_IN_DOLLAR) {
|
||||
text.raw_flags&=~RWF_IN_DOLLAR;
|
||||
if (!(text.raw_flags & RWF_LAST_DOLLAR)) {
|
||||
text.raw_flags&=~RWF_LAST_DOLLAR;
|
||||
Preempt(old_preempt);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
sys_raw_flags|=RWF_IN_DOLLAR|RWF_LAST_DOLLAR;
|
||||
text.raw_flags|=RWF_IN_DOLLAR|RWF_LAST_DOLLAR;
|
||||
Preempt(old_preempt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
sys_raw_flags&=~RWF_LAST_DOLLAR;
|
||||
if (sys_raw_flags&RWF_IN_DOLLAR) {
|
||||
text.raw_flags&=~RWF_LAST_DOLLAR;
|
||||
if (text.raw_flags&RWF_IN_DOLLAR) {
|
||||
Preempt(old_preempt);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (ch=='\t') {
|
||||
RawPutChar(CH_SPACE);
|
||||
while (sys_raw_col & 7)
|
||||
while (text.raw_col & 7)
|
||||
RawPutChar(CH_SPACE);
|
||||
} else if (ch==CH_BACKSPACE) {
|
||||
sys_raw_col--;
|
||||
text.raw_col--;
|
||||
RawPutChar(CH_SPACE);
|
||||
sys_raw_col--;
|
||||
text.raw_col--;
|
||||
} else if (ch=='\n') {
|
||||
RawPutChar(CH_SPACE);
|
||||
while (sys_raw_col % text_cols)
|
||||
while (text.raw_col % text.cols)
|
||||
RawPutChar(CH_SPACE);
|
||||
|
||||
} else if (Bt(chars_bitmap_displayable,ch)) {
|
||||
row=sys_raw_col/text_cols%text_rows;
|
||||
col=sys_raw_col%text_cols;
|
||||
if (text_mode) {
|
||||
if (sys_raw_flags&RWF_SCROLL && sys_raw_col && !row && !col) {
|
||||
MemCpy(VGA_TEXT_MEM_BASE,VGA_TEXT_MEM_BASE+text_cols,
|
||||
text_cols*(text_rows-1)*2);
|
||||
MemSet(VGA_TEXT_MEM_BASE+text_cols*(text_rows-1)*2,0,text_cols*2);
|
||||
sys_raw_col-=text_cols;
|
||||
row=text_rows-1;
|
||||
row=text.raw_col/text.cols%text.rows;
|
||||
col=text.raw_col%text.cols;
|
||||
if (!sys_bios_gr_mode) { //if text mode
|
||||
if (text.raw_flags&RWF_SCROLL && text.raw_col && !row && !col) {
|
||||
MemCpy(VGA_TEXT_MEM_BASE,VGA_TEXT_MEM_BASE+text.cols,
|
||||
text.cols*(text.rows-1)*2);
|
||||
MemSet(VGA_TEXT_MEM_BASE+text.cols*(text.rows-1)*2,0,text.cols*2);
|
||||
text.raw_col-=text.cols;
|
||||
row=text.rows-1;
|
||||
}
|
||||
ptr=VGA_TEXT_MEM_BASE+(row*text_cols+col)*2;
|
||||
ptr=VGA_TEXT_MEM_BASE+(row*text.cols+col)*2;
|
||||
ptr[0]=ch;
|
||||
ptr[1]=BLACK<<4+WHITE;
|
||||
} else {
|
||||
OutU8(VGA_SC_INDEX,VGA_MAP_MASK);
|
||||
OutU8(VGA_SC_DATA,0x0F); //All planes -- WHITE
|
||||
if (sys_raw_flags&RWF_SCROLL && sys_raw_col && !row && !col) {
|
||||
if (text.raw_flags&RWF_SCROLL && text.raw_col && !row && !col) {
|
||||
//Scroll cached image
|
||||
MemCpy(sys_raw_screen_image,sys_raw_screen_image+gr_width*FONT_HEIGHT>>3,
|
||||
gr_width*(gr_height-FONT_HEIGHT)>>3);
|
||||
MemSet(sys_raw_screen_image+gr_width*(gr_height-FONT_HEIGHT)>>3,0,gr_width*FONT_HEIGHT>>3);
|
||||
MemCpy(text.raw_screen_image,text.raw_screen_image+GR_WIDTH*FONT_HEIGHT>>3,
|
||||
GR_WIDTH*(GR_HEIGHT-FONT_HEIGHT)>>3);
|
||||
MemSet(text.raw_screen_image+GR_WIDTH*(GR_HEIGHT-FONT_HEIGHT)>>3,0,GR_WIDTH*FONT_HEIGHT>>3);
|
||||
|
||||
MemCpy(VGA_GRAPHIC_MEM_BASE,sys_raw_screen_image,gr_width*gr_height>>3);
|
||||
sys_raw_col-=text_cols;
|
||||
row=text_rows-1;
|
||||
MemCpy(VGA_GRAPHIC_MEM_BASE,text.raw_screen_image,GR_WIDTH*GR_HEIGHT>>3);
|
||||
text.raw_col-=text.cols;
|
||||
row=text.rows-1;
|
||||
}
|
||||
PUSHFD
|
||||
CLI
|
||||
ptr=ptr1=col+row*gr_width;
|
||||
ptr=ptr1=col+row*GR_WIDTH*FONT_HEIGHT>>3;
|
||||
ptr+=VGA_GRAPHIC_MEM_BASE;
|
||||
ptr1+=sys_raw_screen_image; //Write to cached image as well
|
||||
ptr2=&gr_font[(ch&255)*FONT_HEIGHT];
|
||||
ptr1+=text.raw_screen_image; //Write to cached image as well
|
||||
ptr2=&text.font[(ch&255)*FONT_HEIGHT];
|
||||
for (i=0;i<FONT_HEIGHT;i++) {
|
||||
*ptr=*ptr1=reverse_bits_table[*ptr2++];
|
||||
ptr+=gr_width>>3;
|
||||
ptr1+=gr_width>>3;
|
||||
ptr+=GR_WIDTH>>3;
|
||||
ptr1+=GR_WIDTH>>3;
|
||||
}
|
||||
POPFD
|
||||
}
|
||||
sys_raw_col++;
|
||||
text.raw_col++;
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
}
|
||||
|
||||
U0 VGAFlush()
|
||||
{
|
||||
{//Flush winmgr vga cache, so updates whole screen.
|
||||
LBts(&sys_semas[SYS_SEMA_FLUSH_VGA_IMAGE],0);
|
||||
}
|
||||
|
||||
U0 WinDerivedValsUpdate(CTask *task=NULL)
|
||||
{
|
||||
{//Those things calculated from other variables.
|
||||
if (!task) task=Fs;
|
||||
|
||||
//Assert: This is called with TASKLf_TASK_LOCK set
|
||||
@@ -110,170 +106,23 @@ U0 WinDerivedValsUpdate(CTask *task=NULL)
|
||||
|
||||
//Inside the Border
|
||||
task->pix_left =FONT_WIDTH*task->win_left;
|
||||
task->pix_right =FONT_WIDTH*(task->win_right+1)-1;
|
||||
task->pix_width =task->pix_right-task->pix_left+1;
|
||||
task->pix_top =FONT_HEIGHT*task->win_top;
|
||||
task->pix_bottom=FONT_HEIGHT*(task->win_bottom+1)-1;
|
||||
task->pix_height=task->pix_bottom-task->pix_top+1;
|
||||
task->pix_right =FONT_WIDTH*(task->win_right+1)-1;
|
||||
task->pix_width =task->pix_right-task->pix_left+1;
|
||||
task->pix_top =FONT_HEIGHT*task->win_top;
|
||||
task->pix_bottom =FONT_HEIGHT*(task->win_bottom+1)-1;
|
||||
task->pix_height =task->pix_bottom-task->pix_top+1;
|
||||
|
||||
//Outside the border
|
||||
if (Bt(&task->display_flags,DISPLAYf_NO_BORDER)) {
|
||||
task->border_pix_left =task->pix_left;
|
||||
task->border_pix_right =task->pix_right;
|
||||
task->border_pix_right =task->pix_right;
|
||||
task->border_pix_top =task->pix_top;
|
||||
task->border_pix_bottom=task->pix_bottom;
|
||||
task->border_pix_bottom =task->pix_bottom;
|
||||
} else {
|
||||
task->border_pix_left =task->pix_left-FONT_WIDTH;
|
||||
task->border_pix_right =task->pix_right+FONT_WIDTH;
|
||||
task->border_pix_right =task->pix_right+FONT_WIDTH;
|
||||
task->border_pix_top =task->pix_top-FONT_HEIGHT;
|
||||
task->border_pix_bottom=task->pix_bottom+FONT_HEIGHT;
|
||||
task->border_pix_bottom =task->pix_bottom+FONT_HEIGHT;
|
||||
}
|
||||
POPFD
|
||||
}
|
||||
|
||||
Bool KDRawDisplayPutKey(I64 ch,I64)
|
||||
{
|
||||
if (IsRaw) {
|
||||
RawPutChar(ch);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Bool KDRawDisplayPutS(U8 *st)
|
||||
{
|
||||
I64 ch;
|
||||
if (IsRaw) {
|
||||
while (ch=*st++)
|
||||
RawPutChar(ch);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Bool KDInputFilterPutKey(I64 ch,I64 scancode)
|
||||
{
|
||||
Bool old_preempt;
|
||||
if (Bt(&Fs->task_flags,TASKf_INPUT_FILTER_TASK)) {
|
||||
old_preempt=Preempt(OFF);
|
||||
Msg(MSG_KEY_DOWN,ch,scancode);
|
||||
Preempt(old_preempt);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Bool KDInputFilterPutS(U8 *st)
|
||||
{
|
||||
I64 ch;
|
||||
Bool old_preempt;
|
||||
if (Bt(&Fs->task_flags,TASKf_INPUT_FILTER_TASK)) {
|
||||
old_preempt=Preempt(OFF);
|
||||
while (ch=*st++)
|
||||
Msg(MSG_KEY_DOWN,ch,0);
|
||||
Preempt(old_preempt);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
U0 PutKey(I64 ch=0,I64 sc=0)
|
||||
{ //See $LK,"PutKeyHandling",A="FA:::/Doc/KeyBoard.TXT,PutKeyHandling"$
|
||||
CKeyDev *tempp;
|
||||
if (ch||sc) {
|
||||
tempp=sys_put_key_root.next;
|
||||
if (!Bt(&Fs->display_flags,DISPLAYf_SILENT)) {
|
||||
if (sys_cur_scan_code & SCF_SCROLL && sys_focus_task==Fs)
|
||||
while (sys_cur_scan_code & SCF_SCROLL)
|
||||
Yield; //Wait on SCROLL LOCK Key
|
||||
while (tempp!=&sys_put_key_root) {
|
||||
if ((!(sc & SCF_KEY_DESC) || tempp->flags & KDF_HAS_DESCS) &&
|
||||
(*tempp->put_key)(ch,sc))
|
||||
break;
|
||||
tempp=tempp->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 PutChars(U64 ch)
|
||||
{ //You can pack multiple chars into a U64.
|
||||
while (ch) {
|
||||
PutKey(ch&255,0);
|
||||
ch>>=8;
|
||||
}
|
||||
}
|
||||
|
||||
U0 PutS(U8 *st)
|
||||
{ //Use $LK,"Print",A="MN:Print"$(). See $LK,"PutKeyHandling",A="FA:::/Doc/KeyBoard.TXT,PutKeyHandling"$
|
||||
I64 ch;
|
||||
U8 *ptr;
|
||||
Bool cont=TRUE;
|
||||
if (!st) return;
|
||||
CKeyDev *tempp=sys_put_key_root.next;
|
||||
if (!Bt(&Fs->display_flags,DISPLAYf_SILENT)) {
|
||||
if (sys_cur_scan_code & SCF_SCROLL && sys_focus_task==Fs)
|
||||
while (sys_cur_scan_code & SCF_SCROLL)
|
||||
Yield;
|
||||
while (cont && tempp!=&sys_put_key_root) {
|
||||
if (tempp->put_s) {
|
||||
if ((*tempp->put_s)(st))
|
||||
break;
|
||||
} else {
|
||||
ptr=st;
|
||||
while (ch=*ptr++)
|
||||
if ((*tempp->put_key)(ch,0))
|
||||
cont=FALSE;
|
||||
}
|
||||
tempp=tempp->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 SetKeyDesc(U8 *fmt,...)
|
||||
{
|
||||
I64 i;
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
StrCpy(key_desc,buf);
|
||||
key_handler=Caller;
|
||||
Free(buf);
|
||||
for (i=0;i<5;i++)
|
||||
Yield; //This makes KeyMap work better
|
||||
}
|
||||
|
||||
U0 SetCtrlAltLetCB(U8 ch,U0 (*fp_handler)(I64 sc),U8 *desc,Bool in_irq=FALSE)
|
||||
{
|
||||
ch=ToUpper(ch)-'A';
|
||||
if (ch<26) {
|
||||
fp_ctrl_alt_let_cbs[ch]=fp_handler;
|
||||
Free(ctrl_alt_let_descs[ch]);
|
||||
ctrl_alt_let_descs[ch]=AStrNew(desc);
|
||||
BEqu(&ctrl_alt_let_in_irq_flags,ch,in_irq);
|
||||
}
|
||||
}
|
||||
|
||||
CKeyDev *KeyDevAdd(Bool (*fp_put_key)(I64 ch,I64 sc),Bool (*fp_puts)(U8 *st),I64 priority,Bool key_descs=FALSE)
|
||||
//Places hook in StdOut chain
|
||||
{ //See $LK,"PutKeyHandling",A="FA:::/Doc/KeyBoard.TXT,PutKeyHandling"$
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
CKeyDev *tempp,*tempp1=sys_put_key_root.last;
|
||||
tempp=ACAlloc(sizeof(CKeyDev));
|
||||
tempp->put_key=fp_put_key;
|
||||
tempp->put_s=fp_puts;
|
||||
tempp->priority=priority;
|
||||
if (key_descs)
|
||||
tempp->flags|=KDF_HAS_DESCS;
|
||||
while (tempp1->priority>priority)
|
||||
tempp1=tempp1->last;
|
||||
QueIns(tempp,tempp1);
|
||||
Preempt(old_preempt);
|
||||
return tempp;
|
||||
}
|
||||
|
||||
U0 KeyDevRem(CKeyDev *tempp)
|
||||
{
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
QueRem(tempp);
|
||||
Preempt(old_preempt);
|
||||
Free(tempp);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
//See $LK,"::/Doc/Acknowledgements.TXT"$.
|
||||
|
||||
#define ATA_NOP 0x00
|
||||
#define ATA_DEV_RST 0x08
|
||||
#define ATA_PACKET 0xA0
|
||||
#define ATA_READ_NATIVE_MAX 0xF8
|
||||
#define ATA_READ_NATIVE_MAX_EXT 0x27
|
||||
#define ATA_SET_MAX 0xF9
|
||||
#define ATA_SET_MAX_EXT 0x37
|
||||
#define ATA_READ_MULTI 0xC4
|
||||
#define ATA_READ_MULTI_EXT 0x29
|
||||
#define ATA_WRITE_MULTI 0xC5
|
||||
#define ATA_WRITE_MULTI_EXT 0x39
|
||||
#define ATA_ID_DEV 0xEC
|
||||
|
||||
#define ATAS_ERR 0x01
|
||||
#define ATAS_DRQ 0x08
|
||||
#define ATAS_DF 0x20
|
||||
#define ATAS_DRDY 0x40
|
||||
#define ATAS_BSY 0x80
|
||||
|
||||
#define ATAR0_DATA 0
|
||||
#define ATAR0_FEAT 1
|
||||
#define ATAR0_NSECT 2
|
||||
#define ATAR0_SECT 3
|
||||
#define ATAR0_LCYL 4
|
||||
#define ATAR0_HCYL 5
|
||||
#define ATAR0_SELECT 6
|
||||
#define ATAR0_STAT 7
|
||||
#define ATAR0_CMD 7
|
||||
#define ATAR1_CTRL 2
|
||||
+36
-41
@@ -1,5 +1,5 @@
|
||||
Bool BlkDevLock(CBlkDev *bdev)
|
||||
{
|
||||
{//Make this task have exclusive access to BlkDev.
|
||||
BlkDevChk(bdev);
|
||||
while (bdev->lock_fwding)
|
||||
bdev=bdev->lock_fwding;
|
||||
@@ -13,7 +13,7 @@ Bool BlkDevLock(CBlkDev *bdev)
|
||||
}
|
||||
|
||||
Bool PrtLock(CPrt *p)
|
||||
{
|
||||
{//Make this task have exclusive access to Prt & BlkDev.
|
||||
PrtChk(p);
|
||||
BlkDevLock(p->bdev);
|
||||
if (!Bt(&p->locked_flags,Plf_LOCKED) || p->owning_task!=Fs) {
|
||||
@@ -26,7 +26,7 @@ Bool PrtLock(CPrt *p)
|
||||
}
|
||||
|
||||
Bool BlkDevUnlock(CBlkDev *bdev,Bool rst=FALSE)
|
||||
{
|
||||
{//Release exclusive lock on access to BlkDev.
|
||||
BlkDevChk(bdev);
|
||||
while (bdev->lock_fwding)
|
||||
bdev=bdev->lock_fwding;
|
||||
@@ -42,7 +42,7 @@ Bool BlkDevUnlock(CBlkDev *bdev,Bool rst=FALSE)
|
||||
}
|
||||
|
||||
Bool PrtUnlock(CPrt *p,Bool rst=FALSE)
|
||||
{
|
||||
{//Release exclusive lock on access to Prt & BlkDev.
|
||||
PrtChk(p);
|
||||
if (Bt(&p->locked_flags,Plf_LOCKED) && p->owning_task==Fs) {
|
||||
BlkDevUnlock(p->bdev,rst);
|
||||
@@ -84,8 +84,8 @@ Bool BlkDevInit(CBlkDev *bdev)
|
||||
//0xFFFF*4 is too big for my taste
|
||||
bdev->max_reads=0x800*4;
|
||||
//max of maybe a quarter of disk cache
|
||||
if (bdev->max_reads>sys_dsk_cache_size/BLK_SIZE/4)
|
||||
bdev->max_reads=sys_dsk_cache_size/BLK_SIZE/4 & ~3;
|
||||
if (bdev->max_reads>dsk.cache_size/BLK_SIZE/4)
|
||||
bdev->max_reads=dsk.cache_size/BLK_SIZE/4 & ~3;
|
||||
if (bdev->max_reads<128)
|
||||
bdev->max_reads=128;
|
||||
bdev->max_writes=0xFFFF*4;
|
||||
@@ -103,46 +103,48 @@ Bool BlkDevInit(CBlkDev *bdev)
|
||||
}
|
||||
|
||||
U0 BlkDevsRelease()
|
||||
{
|
||||
{//When task dies, release all owned BlkDevs.
|
||||
I64 i;
|
||||
CBlkDev *bdev;
|
||||
for (i=0;i<NUM_BLKDEVS;i++) {
|
||||
bdev=&sys_blkdevs[i];
|
||||
bdev=&dsk.blkdevs[i];
|
||||
if (bdev->owning_task==Fs && bdev->bd_signature==BD_SIGNATURE_VAL)
|
||||
BlkDevUnlock(bdev,TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
U0 PrtsRelease()
|
||||
{
|
||||
{//When task dies, release all owned Prts.
|
||||
I64 i;
|
||||
CPrt *p;
|
||||
for (i=0;i<NUM_PRTS;i++) {
|
||||
p=&sys_prts[i];
|
||||
p=&dsk.prts[i];
|
||||
if (p->owning_task==Fs && p->pt_signature==PRT_SIGNATURE_VAL)
|
||||
PrtUnlock(p,TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
CPrt *PrtMakeFree(U8 drv_let)
|
||||
{//!!! drv is not a remapped prt.
|
||||
{//Make a slot free for a new partition, like during $LK,"Mount",A="MN:Mount"$().
|
||||
//!!! drv_let is not a $LK,"remapped",A="MN:MapDrv"$ prt.
|
||||
I64 i=ToUpper(drv_let)-'A';
|
||||
CPrt *result;
|
||||
if (!(0<=i<NUM_PRTS))
|
||||
throw('Prt');
|
||||
result=&sys_prts[i];
|
||||
result=&dsk.prts[i];
|
||||
MemSet(result,0,sizeof(CPrt));
|
||||
result->drv_let='A'+i;
|
||||
return result;
|
||||
}
|
||||
|
||||
CPrt *PrtNextFree(U8 first_drv_let='C')
|
||||
{//!!! first_drv_let is not a remapped prt.
|
||||
{//Locate free slot for new partition, like during $LK,"Mount",A="MN:Mount"$().
|
||||
//!!! first_drv_let is not a $LK,"remapped",A="MN:MapDrv"$ prt.
|
||||
I64 i=ToUpper(first_drv_let)-'A';
|
||||
if (!(0<=i<NUM_PRTS))
|
||||
throw('Prt');
|
||||
do
|
||||
if (sys_prts[i].pt_signature!=PRT_SIGNATURE_VAL)
|
||||
if (dsk.prts[i].pt_signature!=PRT_SIGNATURE_VAL)
|
||||
return PrtMakeFree(i+'A');
|
||||
while (++i<NUM_PRTS);
|
||||
throw('Prt');
|
||||
@@ -150,11 +152,11 @@ CPrt *PrtNextFree(U8 first_drv_let='C')
|
||||
}
|
||||
|
||||
CBlkDev *BlkDevNextFree(U8 first_drv_let,I64 type)
|
||||
{
|
||||
{//Locate free slot for new BlkDev, like during $LK,"Mount",A="MN:Mount"$().
|
||||
I64 i=0;
|
||||
CBlkDev *result;
|
||||
do {
|
||||
result=&sys_blkdevs[i];
|
||||
result=&dsk.blkdevs[i];
|
||||
if (result->bd_signature!=BD_SIGNATURE_VAL) {
|
||||
MemSet(result,0,sizeof(CBlkDev));
|
||||
result->first_drv_let=first_drv_let;
|
||||
@@ -192,7 +194,6 @@ U0 MapBufAlloc(CPrt *p,I64 num_blks)
|
||||
RBlks(p,p->cur_map_blk,p->map1,p->num_buffered_map_blks);
|
||||
}
|
||||
|
||||
|
||||
U0 CleanMAPBuf(CPrt *p,I64 MAP_select=-1)
|
||||
{
|
||||
I64 i;
|
||||
@@ -227,7 +228,7 @@ U0 SetFSBuf(CPrt *p,I64 c,I64 map_select=-1)
|
||||
|
||||
#define ZERO_BUF_SIZE 2048
|
||||
U0 WZeroBlks(CPrt *p,I64 blk,I64 cnt)
|
||||
{
|
||||
{//Fill blk cnt with zeros in Prt.
|
||||
I64 n;
|
||||
U8 *z=CAlloc(ZERO_BUF_SIZE<<BLK_SIZE_BITS);
|
||||
Bool show_progress;
|
||||
@@ -255,9 +256,8 @@ U0 WZeroBlks(CPrt *p,I64 blk,I64 cnt)
|
||||
}
|
||||
}
|
||||
|
||||
//Very dangerous
|
||||
Bool SetDrvType(U8 drv_let,I64 type=PT_REDSEA)
|
||||
{
|
||||
{//Very dangerous
|
||||
I64 i,j,ext_base,prt_num,offset,cur_type;
|
||||
CMasterBoot mbr;
|
||||
CBlkDev *bdev=Drv2BlkDev(drv_let);
|
||||
@@ -309,7 +309,7 @@ Bool SetDrvType(U8 drv_let,I64 type=PT_REDSEA)
|
||||
}
|
||||
|
||||
Bool RBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
{
|
||||
{//Read blk cnt from Prt to buf.
|
||||
Bool result=TRUE,unlock;
|
||||
CBlkDev *bdev=p->bdev;
|
||||
if (cnt<=0) return TRUE;
|
||||
@@ -319,7 +319,6 @@ Bool RBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
BlkDevInit(bdev);
|
||||
if (p->offset && blk<p->offset || blk+cnt>p->offset+p->size)
|
||||
throw('Prt');
|
||||
blk+=bdev->offset;
|
||||
|
||||
if (bdev->flags & BDF_READ_CACHE)
|
||||
RCache(p,&buf,&blk,&cnt);
|
||||
@@ -346,7 +345,7 @@ Bool RBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
}
|
||||
|
||||
Bool WBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
{
|
||||
{//Write blk cnt from buf to Prt.
|
||||
Bool result=TRUE,unlock;
|
||||
CBlkDev *bdev=p->bdev;
|
||||
if (cnt<=0) return TRUE;
|
||||
@@ -359,7 +358,6 @@ Bool WBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
throw('BlkDev');
|
||||
if (p->offset && blk<p->offset || blk+cnt>p->offset+p->size)
|
||||
throw('Prt');
|
||||
blk+=bdev->offset;
|
||||
if (cnt>0) {
|
||||
switch (bdev->type) {
|
||||
case BDT_RAM:
|
||||
@@ -382,9 +380,8 @@ Bool WBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
U0 DskCacheInvalidate(CPrt *p)
|
||||
{
|
||||
{//Needed for removable media. Called by $LK,"ChgDsk",A="MN:ChgDsk"$().
|
||||
Bool unlock;
|
||||
CBlkDev *bdev=p->bdev;
|
||||
PrtChk(p);
|
||||
@@ -406,7 +403,7 @@ U0 DskCacheInvalidate(CPrt *p)
|
||||
}
|
||||
|
||||
U0 ChgDsk(U8 drv_let=0)
|
||||
{ //This is needed for removable media
|
||||
{//Change disk. (Needed for removable media.)
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
CBlkDev *bdev=p->bdev;
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
@@ -420,7 +417,7 @@ U0 ChgDsk(U8 drv_let=0)
|
||||
}
|
||||
|
||||
U8 *DrvSerialNum(U8 drv_let=0)
|
||||
{ //20 bytes max.
|
||||
{//20 bytes max.
|
||||
CBlkDev *bdev=Drv2BlkDev(drv_let);
|
||||
U16 *st,*result=NULL;
|
||||
I64 i;
|
||||
@@ -435,7 +432,7 @@ U8 *DrvSerialNum(U8 drv_let=0)
|
||||
}
|
||||
|
||||
U8 *DrvModelNum(U8 drv_let=0)
|
||||
{ //40 bytes max.
|
||||
{//40 bytes max.
|
||||
CBlkDev *bdev=Drv2BlkDev(drv_let);
|
||||
U16 *st,*result=NULL;
|
||||
I64 i;
|
||||
@@ -450,13 +447,13 @@ U8 *DrvModelNum(U8 drv_let=0)
|
||||
}
|
||||
|
||||
U0 PrtRep()
|
||||
{ //Partition report
|
||||
{//Partition report.
|
||||
CPrt *p;
|
||||
CBlkDev *bdev;
|
||||
I64 i,drv_let;
|
||||
U8 *st;
|
||||
"\nDefined Partitions:\n\n";
|
||||
for (i=0,p=sys_prts;i<NUM_PRTS;i++,p++) {
|
||||
for (i=0,p=dsk.prts;i<NUM_PRTS;i++,p++) {
|
||||
if (p->pt_signature==PRT_SIGNATURE_VAL) {
|
||||
bdev=p->bdev;
|
||||
drv_let=Prt2Drv(p);
|
||||
@@ -485,7 +482,7 @@ U0 PrtRep()
|
||||
}
|
||||
|
||||
I64 ClusterNumNext(CPrt *p,I64 c,I64 cnt=1)
|
||||
{
|
||||
{//Return next cnt'th cluster in chain.
|
||||
Bool unlock;
|
||||
PrtChk(p);
|
||||
if (cnt<=0) return c;
|
||||
@@ -515,15 +512,14 @@ I64 ClusterNumNext(CPrt *p,I64 c,I64 cnt=1)
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
I64 Cluster2Blk(CPrt *p,I64 c)
|
||||
{
|
||||
{//Prt cluster num to blk num.
|
||||
PrtChk(p);
|
||||
return p->data+c*p->spc;
|
||||
}
|
||||
|
||||
I64 RClustersBlks(CPrt *p,U8 *buf,I64 c,I64 blks)
|
||||
{ //This accepts blk count, so padding on last cluster is not read.
|
||||
{//Accepts blk count, so padding on last cluster is not read.
|
||||
I64 i;
|
||||
Bool unlock;
|
||||
PrtChk(p);
|
||||
@@ -561,7 +557,7 @@ I64 RClustersBlks(CPrt *p,U8 *buf,I64 c,I64 blks)
|
||||
}
|
||||
|
||||
I64 RClusters(CPrt *p,U8 *buf,I64 c,I64 cnt)
|
||||
{
|
||||
{//Read cluster cnt from Prt to buf.
|
||||
return RClustersBlks(p,buf,c,cnt*p->spc);
|
||||
}
|
||||
|
||||
@@ -663,9 +659,8 @@ I64 Name2ParentDirCluster(CPrt *p,U8 *dirname)
|
||||
return cur_dir_cluster2;
|
||||
}
|
||||
|
||||
|
||||
I64 WClustersBlks(CPrt *p,U8 *buf,I64 c,I64 blks)
|
||||
{ //This accepts blk count, so padding on last cluster is not written.
|
||||
{//Accepts blk count, so padding on last cluster is not written.
|
||||
I64 i;
|
||||
Bool unlock;
|
||||
PrtChk(p);
|
||||
@@ -702,13 +697,13 @@ I64 WClustersBlks(CPrt *p,U8 *buf,I64 c,I64 blks)
|
||||
}
|
||||
|
||||
I64 WClusters(CPrt *p,U8 *buf,I64 c,I64 cnt)
|
||||
{
|
||||
{//Write cluster cnt from buf to Prt.
|
||||
return WClustersBlks(p,buf,c,cnt*p->spc);
|
||||
}
|
||||
|
||||
//c=0 means first cluster in chain
|
||||
I64 ClustersAlloc(CPrt *p,I64 c=0,I64 cnt=1,Bool contiguous=FALSE)
|
||||
{
|
||||
{//Alloc cluster cnt into chain.
|
||||
//c=0 means first cluster in chain
|
||||
PrtChk(p);
|
||||
if (cnt<=0) return c;
|
||||
switch (p->type) {
|
||||
|
||||
+27
-37
@@ -1,8 +1,8 @@
|
||||
Bool MapDrv(U8 drv_let,CPrt *p)
|
||||
{
|
||||
{//Make drive letter map to another.
|
||||
drv_let=ToUpper(drv_let);
|
||||
if ('A'<=drv_let<='Z') {
|
||||
drv_to_prt[drv_let-'A']=p;
|
||||
dsk.drv_to_prt[drv_let-'A']=p;
|
||||
p->drv_let=drv_let;
|
||||
return TRUE;
|
||||
} else
|
||||
@@ -10,7 +10,7 @@ Bool MapDrv(U8 drv_let,CPrt *p)
|
||||
}
|
||||
|
||||
Bool Drv(U8 drv_let)
|
||||
{
|
||||
{//Set drive. You can set drive with $LK,"Cd",A="MN:Cd"$() as well.
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
CBlkDev *bdev=p->bdev;
|
||||
BlkDevChk(bdev);
|
||||
@@ -35,7 +35,7 @@ Bool Drv(U8 drv_let)
|
||||
}
|
||||
|
||||
Bool Cd(U8 *dirname,Bool make_dirs=FALSE)
|
||||
{//Optionally, will create the directories if they don't exist.
|
||||
{//Change directory. Optionally, make directories, too.
|
||||
I64 maxlen,cur_dir_cluster=0;
|
||||
U8 *chg_to_buf,*new_cur_dir,*buf;
|
||||
CPrt *p;
|
||||
@@ -114,7 +114,7 @@ Bool Cd(U8 *dirname,Bool make_dirs=FALSE)
|
||||
}
|
||||
|
||||
U0 FileAccessDel(CFileAccess *fa)
|
||||
{
|
||||
{//Change back to old cur_dir and prt.
|
||||
CBlkDev *bdev;
|
||||
if (!fa) return;
|
||||
bdev=fa->old_prt->bdev;
|
||||
@@ -134,7 +134,7 @@ U0 FileAccessDel(CFileAccess *fa)
|
||||
}
|
||||
|
||||
CFileAccess *FileAccessNew(U8 *_mask,Bool make_mask=FALSE,Bool make_dirs=FALSE,Bool no_mask=FALSE)
|
||||
{
|
||||
{//Save cur_dir and prt. Change to new dir.
|
||||
Bool valid=TRUE,old_silent;
|
||||
U8 *buf,*mask,*temp_mask;
|
||||
CFileAccess *fa=CAlloc(sizeof(CFileAccess));
|
||||
@@ -190,22 +190,13 @@ CFileAccess *FileAccessNew(U8 *_mask,Bool make_mask=FALSE,Bool make_dirs=FALSE,B
|
||||
}
|
||||
|
||||
CDirEntry *FilesFind(U8 *files_find_mask,I64 fuf_flags=0)
|
||||
{
|
||||
/*
|
||||
Flags:
|
||||
$LK,"FUF_RECURSE",A="MN:FUF_RECURSE"$ +r Recurse
|
||||
$LK,"FUF_SINGLE",A="MN:FUF_SINGLE"$ +s Single File (Optimization for one file in mask.)
|
||||
$LK,"FUF_FLATTEN_TREE",A="MN:FUF_FLATTEN_TREE"$ +f $BK,1$use with '+F'$BK,0$. Just use +F, probably.
|
||||
$LK,"FUF_JUST_DIRS",A="MN:FUF_JUST_DIRS"$ +D just directories
|
||||
$LK,"FUF_JUST_FILES",A="MN:FUF_JUST_FILES"$ +F just files (Flattens trees)
|
||||
$LK,"FUF_CLUSTER_ORDER",A="MN:FUF_CLUSTER_ORDER"$ +O sort by cluster (move head one direction)
|
||||
$LK,"FUF_JUST_TXT",A="MN:FUF_JUST_TXT"$ +T just text files : $LK,"FILEMASK_TXT",A="MN:FILEMASK_TXT"$
|
||||
$LK,"FUF_JUST_SRC",A="MN:FUF_JUST_SRC"$ +S just src files : $LK,"FILEMASK_SRC",A="MN:FILEMASK_SRC"$
|
||||
$LK,"FUF_JUST_AOT",A="MN:FUF_JUST_AOT"$ +A just aot files : $LK,"FILEMASK_AOT",A="MN:FILEMASK_AOT"$
|
||||
$LK,"FUF_JUST_JIT",A="MN:FUF_JUST_JIT"$ +J just jit files : $LK,"FILEMASK_JIT",A="MN:FILEMASK_JIT"$
|
||||
$LK,"FUF_JUST_GRA",A="MN:FUF_JUST_GRA"$ +G just graphic files : $LK,"FILEMASK_GRA",A="MN:FILEMASK_GRA"$
|
||||
{/* See $LK,"::/Doc/FileUtils.TXT"$.
|
||||
|
||||
Find files and make a directory tree in memory.
|
||||
|
||||
When done, you free with $LK,"DirEntryDel",A="MN:DirEntryDel"$(),$LK,"DirEntryDel2",A="MN:DirEntryDel2"$(),
|
||||
$LK,"DirTreeDel",A="MN:DirTreeDel"$() or $LK,"DirTreeDel2",A="MN:DirTreeDel2"$().
|
||||
|
||||
See $LK,"ST_FILE_UTIL_FLAGS",A="MN:ST_FILE_UTIL_FLAGS"$ when used in calling program taking text flags.
|
||||
*/
|
||||
CDirEntry *result;
|
||||
CFileAccess *fa;
|
||||
@@ -226,8 +217,8 @@ See $LK,"ST_FILE_UTIL_FLAGS",A="MN:ST_FILE_UTIL_FLAGS"$ when used in calling pro
|
||||
}
|
||||
|
||||
Bool IsDir(U8 *dir_name)
|
||||
{
|
||||
U8 *mask=MPrint("%s/*",dir_name);
|
||||
{//Is a str a valid, existing Dir?
|
||||
U8 *mask=MStrPrint("%s/*",dir_name);
|
||||
Bool result,old_silent=Silent(ON);
|
||||
CFileAccess *fa;
|
||||
if (fa=FileAccessNew(mask)) {
|
||||
@@ -241,7 +232,7 @@ Bool IsDir(U8 *dir_name)
|
||||
}
|
||||
|
||||
I64 Dir(U8 *files_find_mask="*",Bool full=FALSE)
|
||||
{
|
||||
{//List directory.
|
||||
I64 result;
|
||||
CFileAccess *fa;
|
||||
if (fa=FileAccessNew(files_find_mask,TRUE)) {
|
||||
@@ -252,9 +243,8 @@ I64 Dir(U8 *files_find_mask="*",Bool full=FALSE)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
I64 Del(U8 *files_find_mask,Bool print_msg=TRUE)
|
||||
{
|
||||
{//Delete files.
|
||||
I64 result=0;
|
||||
CFileAccess *fa;
|
||||
if (fa=FileAccessNew(files_find_mask)) {
|
||||
@@ -277,7 +267,7 @@ I64 Del(U8 *files_find_mask,Bool print_msg=TRUE)
|
||||
}
|
||||
|
||||
U8 *FileRead(U8 *filename,I64 *_size=NULL,I64 *_attr=NULL,Bool raw=FALSE)
|
||||
{
|
||||
{//Read whole file from disk.
|
||||
CHashGeneric *temph;
|
||||
U8 *absname,*altname,*curname,*result=NULL;
|
||||
I64 i,size=0,attr=0;
|
||||
@@ -346,10 +336,10 @@ U8 *FileRead(U8 *filename,I64 *_size=NULL,I64 *_attr=NULL,Bool raw=FALSE)
|
||||
"%s ",filename;
|
||||
PrintErr("File not found.\n");
|
||||
}
|
||||
if (result && !raw && attr & _ATTR_RESIDENT)
|
||||
if (result && !raw && attr & RS_ATTR_RESIDENT)
|
||||
HashGenericAdd(curname,HTT_FILE,AMAllocIdentical(result),size,0,adam_task);
|
||||
}
|
||||
if (result && !raw && attr & _ATTR_COMPRESSED) {
|
||||
if (result && !raw && attr & RS_ATTR_COMPRESSED) {
|
||||
ac=result;
|
||||
size=ac->expanded_size;
|
||||
result=ExpandBuf(ac);
|
||||
@@ -363,8 +353,8 @@ U8 *FileRead(U8 *filename,I64 *_size=NULL,I64 *_attr=NULL,Bool raw=FALSE)
|
||||
}
|
||||
|
||||
Bool FileFind(U8 *filename,CDirEntry *_de=NULL,I64 fuf_flags=0)
|
||||
{ //$LK,"FUF_JUST_DIRS",A="MN:FUF_JUST_DIRS"$, $LK,"FUF_JUST_FILES",A="MN:FUF_JUST_FILES"$, $LK,"FUF_Z_OR_NOT_Z",A="MN:FUF_Z_OR_NOT_Z"$, $LK,"FUF_SCAN_PARENTS",A="MN:FUF_SCAN_PARENTS"$
|
||||
//If you pass _de, you must Free(_de->full_name);
|
||||
{//$LK,"FUF_JUST_DIRS",A="MN:FUF_JUST_DIRS"$, $LK,"FUF_JUST_FILES",A="MN:FUF_JUST_FILES"$, $LK,"FUF_Z_OR_NOT_Z",A="MN:FUF_Z_OR_NOT_Z"$, $LK,"FUF_SCAN_PARENTS",A="MN:FUF_SCAN_PARENTS"$
|
||||
//If you pass _de, you must Free(_de->full_name);
|
||||
I64 i,j,cur_dir_cluster;
|
||||
U8 *altname,*curname,*full_name=NULL;
|
||||
CDirEntry de;
|
||||
@@ -399,7 +389,7 @@ Bool FileFind(U8 *filename,CDirEntry *_de=NULL,I64 fuf_flags=0)
|
||||
PrintErr("File System Not Supported\n");
|
||||
}
|
||||
if (result && _de)
|
||||
full_name=MPrint("%C:%s/%s",Fs->cur_prt->drv_let,Fs->cur_dir,de.name);
|
||||
full_name=MStrPrint("%C:%s/%s",Fs->cur_prt->drv_let,Fs->cur_dir,de.name);
|
||||
FileAccessDel(fa);
|
||||
}
|
||||
}
|
||||
@@ -428,7 +418,7 @@ Bool FileFind(U8 *filename,CDirEntry *_de=NULL,I64 fuf_flags=0)
|
||||
}
|
||||
}
|
||||
if (result && _de)
|
||||
full_name=MPrint("%C:%s/%s",Fs->cur_prt->drv_let,Fs->cur_dir,de.name);
|
||||
full_name=MStrPrint("%C:%s/%s",Fs->cur_prt->drv_let,Fs->cur_dir,de.name);
|
||||
FileAccessDel(fa);
|
||||
}
|
||||
}
|
||||
@@ -445,14 +435,14 @@ Bool FileFind(U8 *filename,CDirEntry *_de=NULL,I64 fuf_flags=0)
|
||||
|
||||
I64 FileWrite(U8 *filename,U8 *fbuf,
|
||||
I64 size,CDate cdt=0,I64 attr=0,Bool raw=FALSE)
|
||||
{
|
||||
{//Write whole file to disk.
|
||||
I64 c=0;
|
||||
CHashGeneric *temph;
|
||||
CFileAccess *fa;
|
||||
U8 *fbuf2,*absname=FileNameAbs(filename);
|
||||
if (fa=FileAccessNew(filename,FALSE,TRUE)) {
|
||||
attr=FileAttr(fa->mask,attr);
|
||||
if (attr&_ATTR_COMPRESSED && !raw) {
|
||||
if (attr&RS_ATTR_COMPRESSED && !raw) {
|
||||
fbuf=CompressBuf(fbuf,size);
|
||||
size=fbuf(CArcCompress *)->compressed_size;
|
||||
fbuf2=fbuf;
|
||||
@@ -473,13 +463,13 @@ I64 FileWrite(U8 *filename,U8 *fbuf,
|
||||
PrintErr("File System Not Supported\n");
|
||||
}
|
||||
if (temph=HashFind(absname,adam_task->hash_table,HTT_FILE)) {
|
||||
if (!raw && attr & _ATTR_RESIDENT) {
|
||||
if (!raw && attr & RS_ATTR_RESIDENT) {
|
||||
Free(temph->user_data0);
|
||||
temph->user_data0=AMAllocIdentical(fbuf);
|
||||
temph->user_data1=size;
|
||||
} else
|
||||
HashRemDel(temph,adam_task->hash_table);
|
||||
} else if (!raw && attr & _ATTR_RESIDENT)
|
||||
} else if (!raw && attr & RS_ATTR_RESIDENT)
|
||||
HashGenericAdd(absname,HTT_FILE,AMAllocIdentical(fbuf),size,0,adam_task);
|
||||
Free(fbuf2);
|
||||
FileAccessDel(fa);
|
||||
|
||||
+15
-13
@@ -25,7 +25,7 @@ Bool CopySingle(U8 *f1,U8 *f2) //Just one file
|
||||
U8 *absf1=FileNameAbs(f1),*absf2=FileNameAbs(f2),*buf;
|
||||
I64 cnt,n,size,attr1=FileAttr(f1),attr2=FileAttr(f2),i,j;
|
||||
CFile *in_file=NULL,*out_file=NULL;
|
||||
if (!StrCmp(absf1,absf2)) { //onto self?
|
||||
if (!StrCmp(absf1,absf2)) {//onto self?
|
||||
Free(absf1);
|
||||
Free(absf2);
|
||||
return FALSE;
|
||||
@@ -35,14 +35,14 @@ Bool CopySingle(U8 *f1,U8 *f2) //Just one file
|
||||
if (attr1!=attr2)
|
||||
return CopySingleZ(f1,f2);
|
||||
buf=MAlloc(COPY_BUF_BLKS<<BLK_SIZE_BITS);
|
||||
if (attr1 & _ATTR_CONTIGUOUS)
|
||||
if (attr1 & RS_ATTR_CONTIGUOUS)
|
||||
in_file=FOpen(f1,"rc");
|
||||
else
|
||||
in_file=FOpen(f1,"r");
|
||||
if (in_file) {
|
||||
size=FSize(in_file);
|
||||
cnt=(size+BLK_SIZE-1)>>BLK_SIZE_BITS;
|
||||
if (attr2 & _ATTR_CONTIGUOUS)
|
||||
if (attr2 & RS_ATTR_CONTIGUOUS)
|
||||
out_file=FOpen(f2,"wc",cnt);
|
||||
else
|
||||
out_file=FOpen(f2,"w",cnt);
|
||||
@@ -80,7 +80,7 @@ Bool CopySingle(U8 *f1,U8 *f2) //Just one file
|
||||
}
|
||||
|
||||
Bool MkDir(U8 *filename)
|
||||
{
|
||||
{//Make directory. $LK,"Cd",A="MN:Cd"$() can also make directories.
|
||||
U8 *name;
|
||||
CFileAccess *fa;
|
||||
Bool result=FALSE;
|
||||
@@ -138,8 +138,12 @@ I64 SysDel(U8 *wild,Bool make_mask) //this is dangerous
|
||||
}
|
||||
|
||||
U0 Fmt(I64 drv_let,Bool quick=TRUE,Bool confirm=TRUE,I64 type=PT_FAT32)
|
||||
{//See $LK,"PT_FAT32",A="MN:PT_FAT32"$ for a lst of supported file system types.
|
||||
|
||||
{//Format hard drive or RAM drive.
|
||||
//$BK,1$Warning:$BK,0$ Destroys all previous info.
|
||||
//quick=FALSE means fill entire drive
|
||||
//with zeros.
|
||||
//Choose $LK,"PT_FAT32",A="MN:PT_FAT32"$ or $LK,"PT_REDSEA",A="MN:PT_REDSEA"$.
|
||||
//You don't format a CD-ROM with this.
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
Bool old_silent=IsSilent;
|
||||
if (confirm && !AreYouSure)
|
||||
@@ -173,9 +177,8 @@ U0 Fmt(I64 drv_let,Bool quick=TRUE,Bool confirm=TRUE,I64 type=PT_FAT32)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U0 CDImageRead(U8 cd_drv_let,U8 *out_name)
|
||||
{
|
||||
{//Read entire CD/DVD image into ISO file.
|
||||
CBlkDev *bdev=Drv2BlkDev(cd_drv_let);
|
||||
CPrt *p=Drv2Prt(cd_drv_let);
|
||||
U8 *buf=MAlloc(COPY_BUF_BLKS<<BLK_SIZE_BITS),
|
||||
@@ -186,7 +189,7 @@ U0 CDImageRead(U8 cd_drv_let,U8 *out_name)
|
||||
if (bdev->type!=BDT_ATAPI)
|
||||
throw('BlkDev');
|
||||
if (!out_name)
|
||||
out_name=sys_dft_iso_name;
|
||||
out_name=dsk.dft_iso_filename;
|
||||
cnt=CeilU64(p->size,spc);
|
||||
while (cnt>0) {
|
||||
if (cnt>COPY_BUF_BLKS)
|
||||
@@ -222,14 +225,13 @@ class CDualBuf
|
||||
CBlkDev *CD_bdev;
|
||||
};
|
||||
|
||||
|
||||
U0 CDImageWriteTask(CDualBuf *d)
|
||||
{
|
||||
U8 *buf;
|
||||
I64 n,blk=0,cnt=d->cnt;
|
||||
CFile *f;
|
||||
Preempt(ON);
|
||||
if (FileAttr(d->filename)&_ATTR_CONTIGUOUS)
|
||||
if (FileAttr(d->filename)&RS_ATTR_CONTIGUOUS)
|
||||
f=FOpen(d->filename,"rc");
|
||||
else
|
||||
f=FOpen(d->filename,"r");
|
||||
@@ -255,7 +257,7 @@ U0 CDImageWriteTask(CDualBuf *d)
|
||||
}
|
||||
|
||||
U0 CDImageWrite(U8 cd_drv_let,U8 *in_name=NULL,I64 media_type=MT_CD)
|
||||
{
|
||||
{//Write CD/DVD ISO file to disk.
|
||||
CDualBuf *d=CAlloc(sizeof(CDualBuf));
|
||||
U8 *buf,*in_name2,*in_name3;
|
||||
I64 i,n,spc,blk=0,cnt;
|
||||
@@ -266,7 +268,7 @@ U0 CDImageWrite(U8 cd_drv_let,U8 *in_name=NULL,I64 media_type=MT_CD)
|
||||
CFile *f;
|
||||
|
||||
if (!in_name)
|
||||
in_name=sys_dft_iso_name;
|
||||
in_name=dsk.dft_iso_filename;
|
||||
in_name3=DftExt(in_name,"ISO");
|
||||
in_name2=FileNameAbs(in_name3);
|
||||
f=FOpen(in_name2,"r");
|
||||
|
||||
+26
-26
@@ -127,7 +127,6 @@ Bool ATAPISetMaxSpeed(CBlkDev *bdev)
|
||||
return ATAWaitNotBUSY(bdev,0);
|
||||
}
|
||||
|
||||
|
||||
Bool ATAPISeek(CBlkDev *bdev,I64 native_blk)
|
||||
{
|
||||
if (bdev->flags & BDF_EXT_SIZE)
|
||||
@@ -185,7 +184,7 @@ I64 ATAGetDevId(CBlkDev *bdev,F64 timeout,U16 **_id_record)
|
||||
}
|
||||
|
||||
I64 ATAReadNativeMax(CBlkDev *bdev,F64 timeout)
|
||||
{ //returns zero on err
|
||||
{//Returns zero on err
|
||||
I64 result=0;
|
||||
Bool okay=TRUE;
|
||||
|
||||
@@ -251,7 +250,7 @@ I64 ATAReadNativeMax(CBlkDev *bdev,F64 timeout)
|
||||
}
|
||||
|
||||
I64 ATAPIReadCapacity(CBlkDev *bdev,I64 *_blk_size=NULL)
|
||||
{ //Supposedly this can return a result +/- 75 sects.
|
||||
{//Supposedly this can return a result +/- 75 sects.
|
||||
//Error might just be for music.
|
||||
Bool unlock=BlkDevLock(bdev);
|
||||
U32 buf[2];
|
||||
@@ -366,7 +365,7 @@ retry:
|
||||
throw('BlkDev');
|
||||
}
|
||||
|
||||
sys_dsk_reads+=(cnt*bdev->blk_size)>>BLK_SIZE_BITS;
|
||||
dsk.read_cnt+=(cnt*bdev->blk_size)>>BLK_SIZE_BITS;
|
||||
if (unlock) BlkDevUnlock(bdev);
|
||||
}
|
||||
|
||||
@@ -400,7 +399,7 @@ Bool ATAPIReadBlks2(CBlkDev *bdev,F64 timeout,U8 *buf, I64 native_blk, I64 cnt,B
|
||||
if (ATAPIWritePktWord(bdev,timeout,0xA800,
|
||||
native_blk.u16[1],native_blk,cnt.u16[1],cnt,0) &&
|
||||
ATAGetResult(bdev,timeout,buf,cnt*bdev->blk_size,0,FALSE)) {
|
||||
sys_dsk_reads+=(cnt*bdev->blk_size)>>BLK_SIZE_BITS;
|
||||
dsk.read_cnt+=(cnt*bdev->blk_size)>>BLK_SIZE_BITS;
|
||||
result=TRUE;
|
||||
}
|
||||
}
|
||||
@@ -457,10 +456,9 @@ Bool ATARBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//This is for low level disk access
|
||||
//Call WBlks() instead
|
||||
U0 ATAWriteBlks(CBlkDev *bdev,U8 *buf, I64 blk, I64 cnt)
|
||||
{
|
||||
{//For low level disk access.
|
||||
//Use WBlks() instead.
|
||||
I64 i,U32s_avail,sects_avail,retries=3;
|
||||
F64 timeout;
|
||||
Bool unlock=BlkDevLock(bdev);
|
||||
@@ -519,9 +517,8 @@ Bool ATAPISync(CBlkDev *bdev)
|
||||
}
|
||||
|
||||
U0 ATAPIClose(CBlkDev *bdev,I64 close_field=0x200,I64 track=0)
|
||||
{
|
||||
//0x200 CD/DVD part 1
|
||||
//0x300 DVD part 2
|
||||
{//0x200 CD/DVD part 1
|
||||
// 0x300 DVD part 2
|
||||
if (bdev->flags & BDF_EXT_SIZE)
|
||||
OutU8(bdev->base0+ATAR0_SELECT,0xEF|bdev->unit<<4);
|
||||
else
|
||||
@@ -571,7 +568,7 @@ U0 ATAPIWriteBlks(CBlkDev *bdev,U8 *buf, I64 native_blk, I64 cnt)
|
||||
if (U32s_avail) {
|
||||
RepOutU32(buf,U32s_avail,bdev->base0+ATAR0_DATA);
|
||||
buf+=U32s_avail<<2;
|
||||
sys_dsk_writes+=U32s_avail>>(BLK_SIZE_BITS-2);
|
||||
dsk.write_cnt+=U32s_avail>>(BLK_SIZE_BITS-2);
|
||||
}
|
||||
}
|
||||
ATAWaitNotBUSY(bdev,0);
|
||||
@@ -598,7 +595,7 @@ Bool ATAWBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
buf+=n<<BLK_SIZE_BITS;
|
||||
blk+=n;
|
||||
cnt-=n;
|
||||
sys_dsk_writes+=n;
|
||||
dsk.write_cnt+=n;
|
||||
}
|
||||
if (bdev->type==BDT_ATAPI) {
|
||||
ATAPISync(bdev);
|
||||
@@ -618,7 +615,7 @@ Bool BootCdProbe(CBlkDev *bdev)
|
||||
" ATAPI";
|
||||
if (ATAPIStartStop(bdev,tS+5.0,TRUE)) {
|
||||
" Started";
|
||||
for (i=0;i<2;i++) { //Retry
|
||||
for (i=0;i<2;i++) {//Retry
|
||||
if (ATAPIReadBlks2(bdev,tS+7.0,img,sys_boot_code.u16[1],1,FALSE)) {
|
||||
if (img->compile_time==sys_compile_time) {
|
||||
" Found";
|
||||
@@ -736,7 +733,7 @@ Bool ATARepExitAllApplications()
|
||||
}
|
||||
|
||||
public I64 ATARep(Bool pmt=TRUE,Bool just_ide=FALSE,CATARep **_root=NULL)
|
||||
{
|
||||
{//Report possible ATA devices by probing. Hard disks and CD/DVDs.
|
||||
I64 d1,d2,d3,i,j,k,cnt=0,unlock_flags=0,num_hints=0;
|
||||
#assert NUM_BLKDEVS<=64
|
||||
Bool old_preempt;
|
||||
@@ -748,9 +745,9 @@ public I64 ATARep(Bool pmt=TRUE,Bool just_ide=FALSE,CATARep **_root=NULL)
|
||||
|
||||
old_preempt=Preempt(OFF);
|
||||
for (i=0;i<NUM_BLKDEVS;i++)
|
||||
if (sys_blkdevs[i].bd_signature==BD_SIGNATURE_VAL)
|
||||
if (dsk.blkdevs[i].bd_signature==BD_SIGNATURE_VAL)
|
||||
BEqu(&unlock_flags,i,
|
||||
BlkDevLock(&sys_blkdevs[i]));
|
||||
BlkDevLock(&dsk.blkdevs[i]));
|
||||
|
||||
if (!just_ide)
|
||||
for (k=0;k<256;k++) {
|
||||
@@ -795,16 +792,17 @@ public I64 ATARep(Bool pmt=TRUE,Bool just_ide=FALSE,CATARep **_root=NULL)
|
||||
ATARepEntry(d1,d2,0,d3,"Secondary IDE",_root,&num_hints);
|
||||
ATARepEntry(d1,d2,1,d3,"Secondary IDE",_root,&num_hints);
|
||||
}
|
||||
NewLine(2);
|
||||
'\n\n';
|
||||
for (i=0;i<NUM_BLKDEVS;i++)
|
||||
if (Bt(&unlock_flags,i))
|
||||
BlkDevUnlock(&sys_blkdevs[i]);
|
||||
BlkDevUnlock(&dsk.blkdevs[i]);
|
||||
Preempt(old_preempt);
|
||||
return num_hints;
|
||||
}
|
||||
|
||||
CATARep *ATAIDDrvs(CATARep *root,U8 _sys_acct_drv,CATARep **_ata_drv,CATARep **_atapi_drv)
|
||||
{
|
||||
{//When trying to sort-out main hard drives
|
||||
//and CD-ROM drives, this is needed.
|
||||
CATARep *result=NULL,*tempha=root,*ata_drv=NULL,*atapi_drv=NULL;
|
||||
CBlkDev *bdev;
|
||||
Bool was_silent=Silent(ON);
|
||||
@@ -858,30 +856,32 @@ CBlkDev *ATAMount(U8 first_drv_let,I64 type,I64 base0,I64 base1,I64 unit)
|
||||
}
|
||||
|
||||
I64 AutoMountIDE()
|
||||
{
|
||||
{//Try to mount hard drive and CD/DVD, automatically. (Kernel.Cfg option).
|
||||
//It uses 'C' and 'T' as first drive letters or whatever you set
|
||||
//in config when compiling Kernel.BIN.
|
||||
I64 result=0;
|
||||
CATARep *root=NULL,*ata_drv=NULL,*atapi_drv=NULL,*tempha;
|
||||
ATARep(FALSE,TRUE,&root);
|
||||
ATAIDDrvs(root,*sys_acct,&ata_drv,&atapi_drv);
|
||||
if (ata_drv && ATAMount(sys_first_hd_drv_let,BDT_ATA,
|
||||
if (ata_drv && ATAMount(dsk.first_hd_drv_let,BDT_ATA,
|
||||
ata_drv->base0,ata_drv->base1,ata_drv->unit))
|
||||
result++;
|
||||
if (atapi_drv && ATAMount(sys_first_cd_drv_let,BDT_ATAPI,
|
||||
if (atapi_drv && ATAMount(dsk.first_cd_drv_let,BDT_ATAPI,
|
||||
atapi_drv->base0,atapi_drv->base1,atapi_drv->unit))
|
||||
result++;
|
||||
tempha=root;
|
||||
while (tempha) {
|
||||
if (tempha!=ata_drv && tempha!=atapi_drv) {
|
||||
if (tempha->type==BDT_ATA && ATAMount(sys_first_hd_drv_let,BDT_ATA,
|
||||
if (tempha->type==BDT_ATA && ATAMount(dsk.first_hd_drv_let,BDT_ATA,
|
||||
tempha->base0,tempha->base1,tempha->unit))
|
||||
result++;
|
||||
else if (tempha->type==BDT_ATAPI && ATAMount(sys_first_cd_drv_let,BDT_ATAPI,
|
||||
else if (tempha->type==BDT_ATAPI && ATAMount(dsk.first_cd_drv_let,BDT_ATAPI,
|
||||
tempha->base0,tempha->base1,tempha->unit))
|
||||
result++;
|
||||
}
|
||||
tempha=tempha->next;
|
||||
}
|
||||
LinkedLstDel(root);
|
||||
sys_auto_mount_ide_cnt=result;
|
||||
dsk.auto_mount_ide_cnt=result;
|
||||
return result;
|
||||
}
|
||||
+27
-34
@@ -8,7 +8,7 @@ U0 SetBlkDevLockFwding(CBlkDev *bdev)
|
||||
case BDT_ATA:
|
||||
case BDT_ATAPI:
|
||||
for (i=0;i<NUM_BLKDEVS;i++) {
|
||||
bdev1=&sys_blkdevs[i];
|
||||
bdev1=&dsk.blkdevs[i];
|
||||
if (bdev1->bd_signature==BD_SIGNATURE_VAL && bdev!=bdev1 &&
|
||||
(bdev1->type==BDT_ATAPI || bdev1->type==BDT_ATA) &&
|
||||
bdev1->base0==bdev->base0) {
|
||||
@@ -148,10 +148,8 @@ I64 BlkDevAdd(CBlkDev *bdev,Bool one_prt,Bool make_free)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Bool DrvEnable(U8 drv_let,Bool val)
|
||||
{//This can be used to unmount a drive or remount,
|
||||
//but not mount the first time.
|
||||
{//Can unmount or remount, but not mount the first time.
|
||||
CPrt *p;
|
||||
Bool result=FALSE;
|
||||
try {
|
||||
@@ -173,7 +171,7 @@ CATARep *ATARepFind(CATARep *haystack_root,I64 needle_num)
|
||||
}
|
||||
|
||||
U0 Mount(Bool repartition=FALSE)
|
||||
{
|
||||
{//Mount a drive.
|
||||
CBlkDev *bdev;
|
||||
I64 first_prt_num,type,unit,num_hints;
|
||||
U8 blks_buf[128],addr_buf[128],base0_buf[128],base1_buf[128];
|
||||
@@ -190,12 +188,12 @@ U0 Mount(Bool repartition=FALSE)
|
||||
"they will be lettered in sequence.\n"
|
||||
"\nFirst Drive Letter ($$PURPLE$$<ENTER>$$FG$$ to exit):";
|
||||
first_prt_num=ToUpper(GetChar)-'A';
|
||||
NewLine;
|
||||
'\n';
|
||||
if (0<=first_prt_num<NUM_PRTS) {
|
||||
"\t$$PURPLE$$1$$FG$$=RAM\n\t$$PURPLE$$2$$FG$$=ATA(Harddisk)\n"
|
||||
"\t$$PURPLE$$3$$FG$$=ATAPI(CD-ROM)\nType:";
|
||||
type=GetChar-'0';
|
||||
NewLine;
|
||||
'\n';
|
||||
|
||||
unit=0;
|
||||
if (type==BDT_ATA || type==BDT_ATAPI) {
|
||||
@@ -207,11 +205,11 @@ U0 Mount(Bool repartition=FALSE)
|
||||
else
|
||||
"Include $$PURPLE$$0x$$FG$$ prefix.\nI/O Port Base0:\n";
|
||||
GetS(base0_buf,128);
|
||||
} while (!A2I64(base0_buf));
|
||||
if (1<=A2I64(base0_buf)<=num_hints) {
|
||||
tempha=ATARepFind(root,A2I64(base0_buf));
|
||||
SPrint(base0_buf,"0x%X",tempha->base0);
|
||||
SPrint(base1_buf,"0x%X",tempha->base1);
|
||||
} while (!Str2I64(base0_buf));
|
||||
if (1<=Str2I64(base0_buf)<=num_hints) {
|
||||
tempha=ATARepFind(root,Str2I64(base0_buf));
|
||||
StrPrint(base0_buf,"0x%X",tempha->base0);
|
||||
StrPrint(base1_buf,"0x%X",tempha->base1);
|
||||
unit=tempha->unit;
|
||||
} else {
|
||||
if (type==BDT_ATAPI)
|
||||
@@ -220,12 +218,12 @@ U0 Mount(Bool repartition=FALSE)
|
||||
do {
|
||||
"I/O Port Base1:\n";
|
||||
GetS(base1_buf,128);
|
||||
} while (!A2I64(base1_buf));
|
||||
} while (!Str2I64(base1_buf));
|
||||
do {
|
||||
"\t$$PURPLE$$0$$FG$$=Master\n\t$$PURPLE$$1$$FG$$=Slave\nUnit:";
|
||||
unit=GetChar-'0';
|
||||
} while (!(0<=unit<=1));
|
||||
NewLine;
|
||||
'\n';
|
||||
}
|
||||
LinkedLstDel(root);
|
||||
}
|
||||
@@ -241,13 +239,13 @@ U0 Mount(Bool repartition=FALSE)
|
||||
bdev->unit=unit;
|
||||
if (type==BDT_RAM) {
|
||||
if (!*addr_buf) StrCpy(addr_buf,"0");
|
||||
bdev->RAM_dsk=A2I64(addr_buf);
|
||||
bdev->max_blk=A2I64(blks_buf)-1;
|
||||
bdev->RAM_dsk=Str2I64(addr_buf);
|
||||
bdev->max_blk=Str2I64(blks_buf)-1;
|
||||
}
|
||||
if (type==BDT_ATA ||
|
||||
type==BDT_ATAPI) {
|
||||
bdev->base0=A2I64(base0_buf);
|
||||
bdev->base1=A2I64(base1_buf);
|
||||
bdev->base0=Str2I64(base0_buf);
|
||||
bdev->base1=Str2I64(base1_buf);
|
||||
}
|
||||
add=TRUE;
|
||||
if (type==BDT_ATA && repartition) {
|
||||
@@ -268,18 +266,14 @@ U0 Mount(Bool repartition=FALSE)
|
||||
} while (0<=first_prt_num<NUM_PRTS);
|
||||
}
|
||||
|
||||
I64 SysPmtI64()
|
||||
I64 SysGetI64()
|
||||
{
|
||||
U8 st[136];
|
||||
StrCpy(st,"0x");
|
||||
GetS(st+2,134,FALSE);
|
||||
if (!st[2])
|
||||
return 0;
|
||||
else
|
||||
return A2I64(st);
|
||||
GetS(st,136,FALSE);
|
||||
return Str2I64(st,16);
|
||||
}
|
||||
|
||||
Bool PmtBaseUnit(CBlkDev *bdev)
|
||||
Bool GetBaseUnit(CBlkDev *bdev)
|
||||
{
|
||||
I64 ch;
|
||||
Bool probe;
|
||||
@@ -299,7 +293,7 @@ Bool PmtBaseUnit(CBlkDev *bdev)
|
||||
"'IDE', 'ATA' or 'SATA'.\n"
|
||||
"\n\nEnter 4-digit hex I/O Port number.\n"
|
||||
"CD-ROM I/O Port Base0: 0x";
|
||||
bdev->base0=SysPmtI64;
|
||||
bdev->base0=SysGetI64;
|
||||
bdev->base1=0;
|
||||
bdev->unit =0;
|
||||
if (bdev->base0) {
|
||||
@@ -308,10 +302,10 @@ Bool PmtBaseUnit(CBlkDev *bdev)
|
||||
while (!('0'<=ch<='1'));
|
||||
'' ch;
|
||||
bdev->unit=ch-'0';
|
||||
cdrom_boot_is_good=BootCdProbe(bdev);
|
||||
dsk.cdrom_boot_is_good=BootCdProbe(bdev);
|
||||
return TRUE;
|
||||
} else {
|
||||
cdrom_boot_is_good=FALSE;
|
||||
dsk.cdrom_boot_is_good=FALSE;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
@@ -322,11 +316,11 @@ U0 BlkDevsInitAll()
|
||||
{
|
||||
CBlkDev *bdev;
|
||||
I64 i;
|
||||
sys_blkdevs=CAlloc(sizeof(CBlkDev)*NUM_BLKDEVS);
|
||||
sys_prts=CAlloc(sizeof(CPrt)*NUM_PRTS);
|
||||
dsk.blkdevs=CAlloc(sizeof(CBlkDev)*NUM_BLKDEVS);
|
||||
dsk.prts=CAlloc(sizeof(CPrt)*NUM_PRTS);
|
||||
for (i=0;i<NUM_PRTS;i++)
|
||||
drv_to_prt[i]=&sys_prts[i];
|
||||
sys_raw_col=0;
|
||||
dsk.drv_to_prt[i]=&dsk.prts[i];
|
||||
text.raw_col=0;
|
||||
#exe {
|
||||
if (kernel_cfg->opts[CFG_AUTO_MOUNT_IDE])
|
||||
StreamPrint("AutoMountIDE;");
|
||||
@@ -336,4 +330,3 @@ U0 BlkDevsInitAll()
|
||||
};
|
||||
PrtRep;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
I64 FSize(CFile *f)
|
||||
{
|
||||
{//Report size of opened file in bytes.
|
||||
if (f)
|
||||
return f->de.size;
|
||||
else
|
||||
@@ -7,8 +7,8 @@ I64 FSize(CFile *f)
|
||||
}
|
||||
|
||||
CFile *FOpen(U8 *filename,U8 *flags,I64 cnt=0)
|
||||
{ //allows flags "r","w","w+". Include a "c" for contiguous.
|
||||
//(It uses $LK,"StrOcc",A="MN:StrOcc"$() for 'w', 'r', '+', 'c')
|
||||
{//Allows flags "r","w","w+". "c" for contiguous.
|
||||
//(It uses $LK,"StrOcc",A="MN:StrOcc"$() for 'w', 'r', '+', 'c')
|
||||
CFile *f=CAlloc(sizeof(CFile));
|
||||
CFileAccess *fa;
|
||||
U8 *full_name;
|
||||
@@ -27,7 +27,7 @@ CFile *FOpen(U8 *filename,U8 *flags,I64 cnt=0)
|
||||
contiguous=TRUE;
|
||||
if (contiguous) {
|
||||
f->flags|=FF_CONTIGUOUS;
|
||||
if (f->p->type!=PT_REDSEA && !(FileAttr(filename) & _ATTR_CONTIGUOUS))
|
||||
if (f->p->type!=PT_REDSEA && !(FileAttr(filename) & RS_ATTR_CONTIGUOUS))
|
||||
throw('File');
|
||||
}
|
||||
f->cluster_buf=CAlloc(f->p->spc<<BLK_SIZE_BITS);
|
||||
@@ -46,7 +46,7 @@ CFile *FOpen(U8 *filename,U8 *flags,I64 cnt=0)
|
||||
f->flags|=FF_NEW_FILE;
|
||||
if (fa=FileAccessNew(full_name)) {
|
||||
StrCpy(f->de.name,fa->mask);
|
||||
if (cnt>0) { //We pre-alloc the whole thing.
|
||||
if (cnt>0) {//We pre-alloc the whole thing.
|
||||
f->de.cluster=ClustersAlloc(f->p,0,
|
||||
(cnt+f->p->spc-1)/f->p->spc,contiguous);
|
||||
f->de.size=cnt<<BLK_SIZE_BITS;
|
||||
@@ -71,7 +71,7 @@ CFile *FOpen(U8 *filename,U8 *flags,I64 cnt=0)
|
||||
}
|
||||
|
||||
U0 FClose(CFile *f)
|
||||
{
|
||||
{//Close CFile, updating directory.
|
||||
CFileAccess *fa;
|
||||
if (f) {
|
||||
if (f->flags & FF_BUF_DIRTY) {
|
||||
@@ -127,7 +127,7 @@ I64 FSetCluster(CFile *f,I64 c,I64 blk,Bool read)
|
||||
}
|
||||
|
||||
Bool FRBlks(CFile *f,U8 *buf,I64 blk=FFB_NEXT_BLK,I64 cnt=1)
|
||||
{
|
||||
{//Read [nth,n+cnt) blks of file.
|
||||
CPrt *p=f->p;
|
||||
I64 spc=p->spc,i,j,c=f->de.cluster;
|
||||
if (!f || !p) return FALSE;
|
||||
@@ -179,7 +179,7 @@ Bool FRBlks(CFile *f,U8 *buf,I64 blk=FFB_NEXT_BLK,I64 cnt=1)
|
||||
}
|
||||
|
||||
Bool FWBlks(CFile *f,U8 *buf,I64 blk=FFB_NEXT_BLK,I64 cnt=1)
|
||||
{
|
||||
{//Write [nth,n+cnt) blks of file.
|
||||
CPrt *p=f->p;
|
||||
I64 spc=p->spc,i,j,c=f->de.cluster,c1;
|
||||
if (!f || !p) return FALSE;
|
||||
|
||||
+24
-24
@@ -5,31 +5,31 @@ U0 DskCacheInit(I64 size_in_U8s)
|
||||
|
||||
while (LBts(&sys_semas[SYS_SEMA_DSK_CACHE],0))
|
||||
Yield;
|
||||
Free(sys_dsk_cache_ctrl);
|
||||
Free(sys_dsk_cache_base);
|
||||
Free(sys_dsk_cache_hash_table);
|
||||
Free(dsk.cache_ctrl);
|
||||
Free(dsk.cache_base);
|
||||
Free(dsk.cache_hash_table);
|
||||
if (size_in_U8s<0x2000) {
|
||||
sys_dsk_cache_ctrl=NULL;
|
||||
sys_dsk_cache_base=NULL;
|
||||
sys_dsk_cache_hash_table=NULL;
|
||||
dsk.cache_ctrl=NULL;
|
||||
dsk.cache_base=NULL;
|
||||
dsk.cache_hash_table=NULL;
|
||||
} else {
|
||||
sys_dsk_cache_ctrl=ACAlloc(offset(CCacheBlk.body));
|
||||
sys_dsk_cache_base=AMAlloc(size_in_U8s);
|
||||
QueInit(sys_dsk_cache_ctrl);
|
||||
dsk.cache_ctrl=ACAlloc(offset(CCacheBlk.body));
|
||||
dsk.cache_base=AMAlloc(size_in_U8s);
|
||||
QueInit(dsk.cache_ctrl);
|
||||
|
||||
cnt=MSize(sys_dsk_cache_base)/sizeof(CCacheBlk);
|
||||
sys_dsk_cache_size=cnt*BLK_SIZE;
|
||||
cnt=MSize(dsk.cache_base)/sizeof(CCacheBlk);
|
||||
dsk.cache_size=cnt*BLK_SIZE;
|
||||
for (i=0;i<cnt;i++) {
|
||||
tempc=sys_dsk_cache_base+i;
|
||||
QueIns(tempc,sys_dsk_cache_ctrl->last_lru);
|
||||
tempc=dsk.cache_base+i;
|
||||
QueIns(tempc,dsk.cache_ctrl->last_lru);
|
||||
tempc->next_hash=tempc->last_hash=tempc;
|
||||
tempc->p=NULL;
|
||||
tempc->blk=0;
|
||||
}
|
||||
|
||||
sys_dsk_cache_hash_table=AMAlloc(DSK_CACHE_HASH_SIZE*sizeof(U8 *)*2);
|
||||
dsk.cache_hash_table=AMAlloc(DSK_CACHE_HASH_SIZE*sizeof(U8 *)*2);
|
||||
for (i=0;i<DSK_CACHE_HASH_SIZE;i++) {
|
||||
tempc=sys_dsk_cache_hash_table(U8 *)+i*sizeof(U8 *)*2-offset(CCacheBlk.next_hash);
|
||||
tempc=dsk.cache_hash_table(U8 *)+i*sizeof(U8 *)*2-offset(CCacheBlk.next_hash);
|
||||
tempc->next_hash=tempc->last_hash=tempc;
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ U0 DskCacheInit(I64 size_in_U8s)
|
||||
I64 DskCacheHash(I64 blk)
|
||||
{
|
||||
I64 i=blk & (DSK_CACHE_HASH_SIZE-1);
|
||||
return sys_dsk_cache_hash_table(U8 *)+i<<4-offset(CCacheBlk.next_hash);
|
||||
return dsk.cache_hash_table(U8 *)+i<<4-offset(CCacheBlk.next_hash);
|
||||
}
|
||||
|
||||
U0 DskCacheQueRem(CCacheBlk *tempc)
|
||||
@@ -52,7 +52,7 @@ U0 DskCacheQueRem(CCacheBlk *tempc)
|
||||
U0 DskCacheQueIns(CCacheBlk *tempc)
|
||||
{
|
||||
CCacheBlk *temp_n,*temp_l;
|
||||
QueIns(tempc,sys_dsk_cache_ctrl->last_lru);
|
||||
QueIns(tempc,dsk.cache_ctrl->last_lru);
|
||||
temp_l=DskCacheHash(tempc->blk);
|
||||
temp_n=temp_l->next_hash;
|
||||
tempc->last_hash=temp_l;
|
||||
@@ -75,12 +75,12 @@ CCacheBlk *DskCacheFind(CPrt *p,I64 blk)
|
||||
U0 DskCacheAdd(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
{
|
||||
CCacheBlk *tempc;
|
||||
if (sys_dsk_cache_base) {
|
||||
if (dsk.cache_base) {
|
||||
while (LBts(&sys_semas[SYS_SEMA_DSK_CACHE],0))
|
||||
Yield;
|
||||
while (cnt-->0) {
|
||||
if (!(tempc=DskCacheFind(p,blk)))
|
||||
tempc=sys_dsk_cache_ctrl->next_lru;
|
||||
tempc=dsk.cache_ctrl->next_lru;
|
||||
DskCacheQueRem(tempc);
|
||||
MemCpy(&tempc->body,buf,BLK_SIZE);
|
||||
tempc->p=p;
|
||||
@@ -96,18 +96,18 @@ U0 DskCacheAdd(CPrt *p,U8 *buf, I64 blk, I64 cnt)
|
||||
U0 DskCacheInvalidate2(CPrt *p)
|
||||
{
|
||||
CCacheBlk *tempc,*tempc1;
|
||||
if (sys_dsk_cache_base) {
|
||||
if (dsk.cache_base) {
|
||||
while (LBts(&sys_semas[SYS_SEMA_DSK_CACHE],0))
|
||||
Yield;
|
||||
tempc=sys_dsk_cache_ctrl->last_lru;
|
||||
while (tempc!=sys_dsk_cache_ctrl) {
|
||||
tempc=dsk.cache_ctrl->last_lru;
|
||||
while (tempc!=dsk.cache_ctrl) {
|
||||
tempc1=tempc->last_lru;
|
||||
if (tempc->p==p) {
|
||||
DskCacheQueRem(tempc);
|
||||
tempc->p=NULL;
|
||||
tempc->blk=0;
|
||||
tempc->next_hash=tempc->last_hash=tempc;
|
||||
QueIns(tempc,sys_dsk_cache_ctrl->last_lru);
|
||||
QueIns(tempc,dsk.cache_ctrl->last_lru);
|
||||
}
|
||||
tempc=tempc1;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ U0 DskCacheInvalidate2(CPrt *p)
|
||||
U0 RCache(CPrt *p,U8 **_buf, I64 *_blk, I64 *_cnt)
|
||||
{
|
||||
CCacheBlk *tempc;
|
||||
if (sys_dsk_cache_base) {
|
||||
if (dsk.cache_base) {
|
||||
while (LBts(&sys_semas[SYS_SEMA_DSK_CACHE],0))
|
||||
Yield;
|
||||
//fetch leading blks from cache
|
||||
|
||||
+44
-30
@@ -1,5 +1,5 @@
|
||||
Bool DirNew(CPrt *p,U8 *cur_dir,CDirEntry *tempde,Bool free_old_chain=TRUE)
|
||||
{
|
||||
{//Makes a directory entry in the directory from a $LK,"CDirEntry",A="MN:CDirEntry"$ node.
|
||||
switch (p->type) {
|
||||
case PT_REDSEA:
|
||||
return RedSeaFSDirNew(p,cur_dir,tempde,free_old_chain);
|
||||
@@ -15,7 +15,8 @@ Bool DirNew(CPrt *p,U8 *cur_dir,CDirEntry *tempde,Bool free_old_chain=TRUE)
|
||||
}
|
||||
|
||||
U0 DirEntryDel(CDirEntry *tempde)
|
||||
{ //Doesn't Free user_data
|
||||
{//Free node returned from $LK,"FilesFind",A="MN:FilesFind"$(). Doesn't Free user_data.
|
||||
//Does not change the directory on disk.
|
||||
if (tempde) {
|
||||
Free(tempde->full_name);
|
||||
Free(tempde);
|
||||
@@ -23,7 +24,8 @@ U0 DirEntryDel(CDirEntry *tempde)
|
||||
}
|
||||
|
||||
U0 DirEntryDel2(CDirEntry *tempde)
|
||||
{ //Frees user_data
|
||||
{//Free node returned from $LK,"FilesFind",A="MN:FilesFind"$(). Frees user_data
|
||||
//Does not change the directory on disk.
|
||||
if (tempde) {
|
||||
Free(tempde->full_name);
|
||||
Free(tempde->user_data);
|
||||
@@ -31,25 +33,27 @@ U0 DirEntryDel2(CDirEntry *tempde)
|
||||
}
|
||||
}
|
||||
|
||||
U0 DirLstDel(CDirEntry *tempde)
|
||||
{ //Doesn't Free user_data
|
||||
U0 DirTreeDel(CDirEntry *tempde)
|
||||
{//Free tree returned from $LK,"FilesFind",A="MN:FilesFind"$(). Doesn't Free user_data.
|
||||
//Does not change the directory on disk.
|
||||
CDirEntry *tempde2;
|
||||
while (tempde) {
|
||||
tempde2=tempde->next;
|
||||
if (tempde->sub)
|
||||
DirLstDel(tempde->sub);
|
||||
DirTreeDel(tempde->sub);
|
||||
DirEntryDel(tempde);
|
||||
tempde=tempde2;
|
||||
}
|
||||
}
|
||||
|
||||
U0 DirLstDel2(CDirEntry *tempde)
|
||||
{ //Frees user_data
|
||||
U0 DirTreeDel2(CDirEntry *tempde)
|
||||
{//Free tree returned from $LK,"FilesFind",A="MN:FilesFind"$(). Frees user_data
|
||||
//Does not change the directory on disk.
|
||||
CDirEntry *tempde2;
|
||||
while (tempde) {
|
||||
tempde2=tempde->next;
|
||||
if (tempde->sub)
|
||||
DirLstDel2(tempde->sub);
|
||||
DirTreeDel2(tempde->sub);
|
||||
DirEntryDel2(tempde);
|
||||
tempde=tempde2;
|
||||
}
|
||||
@@ -60,9 +64,9 @@ I64 DirEntryCompareName(CDirEntry *e1,CDirEntry *e2)
|
||||
U8 buf1[CDIR_FILENAME_LEN],buf2[CDIR_FILENAME_LEN],
|
||||
buf3[CDIR_FILENAME_LEN],buf4[CDIR_FILENAME_LEN];
|
||||
I64 d1=0,d2=0;
|
||||
if (e1->attr & _ATTR_DIR)
|
||||
if (e1->attr & RS_ATTR_DIR)
|
||||
d1=1;
|
||||
if (e2->attr & _ATTR_DIR)
|
||||
if (e2->attr & RS_ATTR_DIR)
|
||||
d2=1;
|
||||
if (d1!=d2)
|
||||
return d2-d1;
|
||||
@@ -134,13 +138,13 @@ U0 DirFilesSort(CDirEntry **_tempde,I64 key)
|
||||
}
|
||||
|
||||
CDirEntry *DirFilesFlatten(CDirEntry *tempde,CDirEntry **_result,I64 fuf_flags)
|
||||
{ //returns last node
|
||||
{//Returns last node
|
||||
CDirEntry *tempde1;
|
||||
Bool del;
|
||||
if (tempde)
|
||||
while (TRUE) {
|
||||
tempde1=tempde->next;
|
||||
if (!(tempde->attr&_ATTR_DIR)||!(fuf_flags&FUF_JUST_FILES)) {
|
||||
if (!(tempde->attr&RS_ATTR_DIR)||!(fuf_flags&FUF_JUST_FILES)) {
|
||||
_result=*_result=tempde;
|
||||
del=FALSE;
|
||||
} else
|
||||
@@ -190,7 +194,7 @@ CDirEntry *SysFilesFind(U8 *files_find_mask,I64 fuf_flags)
|
||||
}
|
||||
|
||||
U0 PutFileLink(U8 *filename,I64 line=0,Bool plain_text=FALSE)
|
||||
{
|
||||
{//Put $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT.Z"$ file,line link to StdOut, $LK,"DocPut",A="MN:DocPut"$.
|
||||
U8 *buf;
|
||||
if (!filename) return;
|
||||
if (IsRaw) {
|
||||
@@ -199,24 +203,32 @@ U0 PutFileLink(U8 *filename,I64 line=0,Bool plain_text=FALSE)
|
||||
else
|
||||
"%s",filename;
|
||||
} else {
|
||||
buf=FileNameAbs(filename);
|
||||
if (plain_text) {
|
||||
if (line)
|
||||
"$$LK,\"%s,%04d\",A=\"PL:%s,%d\"$$",filename,line,buf,line;
|
||||
//LK_DOC,LK_DOC_ANCHOR,LK_DOC_FIND,LK_DOC_LINE
|
||||
if (filename[0]=='A'&&filename[2]==':') {
|
||||
if (line) //See $LK,"SpriteEdText",A="MN:SpriteEdText"$()
|
||||
"$$LK,\"%s,%04d\",A=\"AL:%s,%d\"$$",filename+3,line,filename+3,line;
|
||||
else
|
||||
"$$LK,\"%s\",A=\"PI:%s\"$$",filename,buf;
|
||||
"$$LK,\"%s\",A=\"AI:%s\"$$",filename+3,filename+3;
|
||||
} else {
|
||||
if (line)
|
||||
"$$LK,\"%s,%04d\",A=\"FL:%s,%d\"$$",filename,line,buf,line;
|
||||
else
|
||||
"$$LK,\"%s\",A=\"FI:%s\"$$",filename,buf;
|
||||
buf=FileNameAbs(filename);
|
||||
if (plain_text) {
|
||||
if (line)
|
||||
"$$LK,\"%s,%04d\",A=\"PL:%s,%d\"$$",filename,line,buf,line;
|
||||
else
|
||||
"$$LK,\"%s\",A=\"PI:%s\"$$",filename,buf;
|
||||
} else {
|
||||
if (line)
|
||||
"$$LK,\"%s,%04d\",A=\"FL:%s,%d\"$$",filename,line,buf,line;
|
||||
else
|
||||
"$$LK,\"%s\",A=\"FI:%s\"$$",filename,buf;
|
||||
}
|
||||
Free(buf);
|
||||
}
|
||||
Free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
U0 PutDirLink(U8 *dirname)
|
||||
{
|
||||
{//Put $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT.Z"$ dir macro to StdOut, $LK,"DocPut",A="MN:DocPut"$.
|
||||
U8 *buf;
|
||||
if (!dirname) return;
|
||||
if (IsRaw)
|
||||
@@ -232,6 +244,7 @@ I64 Dir2(U8 *files_find_mask,I64 fuf_flags,Bool full)
|
||||
{
|
||||
CDirEntry *tempde1=NULL,*tempde2;
|
||||
U8 *st;
|
||||
CDateStruct ds;
|
||||
I64 csize=0xFFFF,c=0xFFFF,result=0;
|
||||
tempde1=SysFilesFind(files_find_mask,fuf_flags);
|
||||
if (!(st=CurDir))
|
||||
@@ -262,16 +275,17 @@ I64 Dir2(U8 *files_find_mask,I64 fuf_flags,Bool full)
|
||||
if (full)
|
||||
"%D %T %0*tX %0*tX ",tempde1->datetime,tempde1->datetime,
|
||||
csize,tempde1->size,c,tempde1->cluster;
|
||||
else
|
||||
"%02d/%02d %02d:%02d %0*tX ",Month(tempde1->datetime),Day(tempde1->datetime),
|
||||
Hour24(tempde1->datetime),Minute(tempde1->datetime),
|
||||
else {
|
||||
Date2Struct(&ds,tempde1->datetime+local_time_offset);
|
||||
"%02d/%02d %02d:%02d %0*tX ",ds.mon,ds.day_of_mon,ds.hour,ds.min,
|
||||
csize,tempde1->size;
|
||||
if (tempde1->attr & _ATTR_DIR)
|
||||
}
|
||||
if (tempde1->attr & RS_ATTR_DIR)
|
||||
PutDirLink(tempde1->name);
|
||||
else
|
||||
PutFileLink(tempde1->name);
|
||||
|
||||
NewLine;
|
||||
'\n';
|
||||
DirEntryDel(tempde1);
|
||||
tempde1=tempde2;
|
||||
}
|
||||
|
||||
+36
-28
@@ -1,5 +1,5 @@
|
||||
U8 *FileExtDot(U8 *src)
|
||||
{
|
||||
{//Find dot char in name.
|
||||
I64 ch;
|
||||
while (ch=*src++)
|
||||
if (ch=='.' && *src!='/' && *src!='.')
|
||||
@@ -8,7 +8,7 @@ U8 *FileExtDot(U8 *src)
|
||||
}
|
||||
|
||||
U8 *FileExtRem(U8 *src,U8 *dst=NULL)
|
||||
{
|
||||
{//Remove filename extension from str.
|
||||
U8 *ptr;
|
||||
if (ptr=FileExtDot(src)) {
|
||||
if (dst)
|
||||
@@ -20,7 +20,7 @@ U8 *FileExtRem(U8 *src,U8 *dst=NULL)
|
||||
}
|
||||
|
||||
Bool IsDotZ(U8 *filename)
|
||||
{
|
||||
{//Does name end in .Z?
|
||||
I64 i=StrLen(filename);
|
||||
if (i>6 && filename[i-1]=='Z' && filename[i-2]=='.' && filename[i-6]=='.')
|
||||
return TRUE;
|
||||
@@ -29,7 +29,7 @@ Bool IsDotZ(U8 *filename)
|
||||
}
|
||||
|
||||
Bool IsDotC(U8 *filename)
|
||||
{
|
||||
{//Does name end in .C?
|
||||
I64 i=StrLen(filename);
|
||||
if (i>6 && filename[i-1]=='C' && filename[i-2]=='.' && filename[i-6]=='.')
|
||||
return TRUE;
|
||||
@@ -38,7 +38,7 @@ Bool IsDotC(U8 *filename)
|
||||
}
|
||||
|
||||
Bool FilesFindMatch(U8 *test_filename,U8 *files_find_mask,I64 fuf_flags=0)
|
||||
{
|
||||
{//Does filename meet $LK,"Files Find",A="FI:::/Doc/FileUtils.TXT"$ mask?
|
||||
U8 *st1=StrNew(files_find_mask),
|
||||
*st2=MAlloc(StrLen(files_find_mask)+1);
|
||||
Bool result=FALSE;
|
||||
@@ -80,13 +80,13 @@ Bool FilesFindMatch(U8 *test_filename,U8 *files_find_mask,I64 fuf_flags=0)
|
||||
}
|
||||
|
||||
U0 PrtChk(CPrt *p)
|
||||
{
|
||||
{//Check for valid partition. Throw exception.
|
||||
if (!p || p->pt_signature!=PRT_SIGNATURE_VAL)
|
||||
throw('Prt');
|
||||
}
|
||||
|
||||
U8 Prt2Drv(CPrt *p=NULL)
|
||||
{
|
||||
{//Prt ptr to Drv letter.
|
||||
if (!p)
|
||||
p=Fs->cur_prt;
|
||||
PrtChk(p);
|
||||
@@ -94,28 +94,31 @@ U8 Prt2Drv(CPrt *p=NULL)
|
||||
}
|
||||
|
||||
CPrt *Drv2Prt(U8 drv_let=0)
|
||||
{
|
||||
{//Drv letter to Prt ptr.
|
||||
CPrt *p;
|
||||
if (!drv_let)
|
||||
p=Fs->cur_prt;
|
||||
else {
|
||||
if (drv_let==':')
|
||||
drv_let=*sys_acct;
|
||||
p=drv_to_prt[ToUpper(drv_let)-'A'];
|
||||
drv_let=ToUpper(drv_let);
|
||||
if (!('A'<=drv_let<='Z'))
|
||||
throw('Prt');
|
||||
p=dsk.drv_to_prt[drv_let-'A'];
|
||||
}
|
||||
PrtChk(p);
|
||||
return p;
|
||||
}
|
||||
|
||||
U0 BlkDevChk(CBlkDev *bdev)
|
||||
{
|
||||
{//Check for valid BlkDev. Throw exception.
|
||||
if (!bdev || bdev->bd_signature!=BD_SIGNATURE_VAL ||
|
||||
!(BDT_NULL<bdev->type<BDT_NUM_TYPES))
|
||||
throw('BlkDev');
|
||||
}
|
||||
|
||||
CBlkDev *Drv2BlkDev(U8 drv_let=0)
|
||||
{
|
||||
{//Drv letter to BlkDev ptr.
|
||||
CPrt *p=Drv2Prt(drv_let);
|
||||
CBlkDev *bdev=p->bdev;
|
||||
BlkDevChk(bdev);
|
||||
@@ -123,7 +126,7 @@ CBlkDev *Drv2BlkDev(U8 drv_let=0)
|
||||
}
|
||||
|
||||
Bool IsDrvWritable(U8 drv_let=0)
|
||||
{
|
||||
{//Is drive writable?
|
||||
CBlkDev *bdev=Drv2BlkDev(drv_let);
|
||||
if (bdev->flags & BDF_READ_ONLY)
|
||||
return FALSE;
|
||||
@@ -132,7 +135,7 @@ Bool IsDrvWritable(U8 drv_let=0)
|
||||
}
|
||||
|
||||
U8 *CurDir(CTask *task=NULL,CTask *mem_task=NULL)
|
||||
{
|
||||
{//MAlloc copy of cur dir with partition letter.
|
||||
U8 *st;
|
||||
if (!task) task=Fs;
|
||||
if (!task->cur_dir)
|
||||
@@ -145,7 +148,7 @@ U8 *CurDir(CTask *task=NULL,CTask *mem_task=NULL)
|
||||
}
|
||||
|
||||
U8 *DirNameAbs(U8 *_dirname)
|
||||
{
|
||||
{//MAlloc absolute dir string with partition letter.
|
||||
I64 maxlen;
|
||||
U8 drv[3],*cur_dir,*buf2,*buf3,*buf,*dirname,*temp_name;
|
||||
if (!Fs->cur_dir || !*Fs->cur_dir)
|
||||
@@ -210,7 +213,7 @@ U8 *DirNameAbs(U8 *_dirname)
|
||||
}
|
||||
|
||||
U8 *FileNameAbs(U8 *_filename,I64 fuf_flags=0)
|
||||
{//$LK,"FUF_Z_OR_NOT_Z",A="MN:FUF_Z_OR_NOT_Z"$, $LK,"FUF_SCAN_PARENTS",A="MN:FUF_SCAN_PARENTS"$
|
||||
{//Absolute filename. Accepts $LK,"FUF_Z_OR_NOT_Z",A="MN:FUF_Z_OR_NOT_Z"$, $LK,"FUF_SCAN_PARENTS",A="MN:FUF_SCAN_PARENTS"$.
|
||||
U8 *buf,*buf2,*buf3,*filename,*temp_name,*temp_buf;
|
||||
CDirEntry de;
|
||||
filename=MStrUtil(_filename,SUF_REM_LEADING|SUF_REM_TRAILING|SUF_REM_CTRL_CHARS);
|
||||
@@ -243,7 +246,7 @@ U8 *FileNameAbs(U8 *_filename,I64 fuf_flags=0)
|
||||
}
|
||||
|
||||
U8 *ChgExt(U8 *filename,U8 *extension)
|
||||
{//Change filename extension
|
||||
{//Change filename extension.
|
||||
U8 *result=MAlloc(StrLen(filename)+1+StrLen(extension)+1);
|
||||
StrCpy(result,filename);
|
||||
if (FileExtDot(filename))
|
||||
@@ -280,16 +283,16 @@ CDirEntry *Cd2DirEntry(CDirEntry *tempde,U8 *abs_name)
|
||||
I64 FileAttr(U8 *name,I64 attr=0)
|
||||
{
|
||||
if (IsDotZ(name))
|
||||
attr|=_ATTR_COMPRESSED;
|
||||
attr|=RS_ATTR_COMPRESSED;
|
||||
else
|
||||
attr&=~_ATTR_COMPRESSED;
|
||||
attr&=~RS_ATTR_COMPRESSED;
|
||||
if (IsDotC(name))
|
||||
attr|=_ATTR_CONTIGUOUS;
|
||||
attr|=RS_ATTR_CONTIGUOUS;
|
||||
return attr;
|
||||
}
|
||||
|
||||
Bool FileNameChk(U8 *filename)
|
||||
{
|
||||
{//Return check for valid filename, not checking existence.
|
||||
U8 *ptr=filename;
|
||||
if (!filename) return FALSE;
|
||||
if (!*ptr) return FALSE;
|
||||
@@ -305,20 +308,20 @@ Bool FileNameChk(U8 *filename)
|
||||
}
|
||||
|
||||
U8 *DirFile(U8 *dirname,U8 *name=NULL,U8 *_extension=NULL)
|
||||
{/*
|
||||
Strips file from dirname, scans for file upward until found or returns default.
|
||||
{/*Strips file from dirname, scans for file upward until found or
|
||||
returns default.
|
||||
|
||||
("/Kernel/Hash1a.CPP.Z",NULL,NULL) returns "D:/Kernel"
|
||||
("/Kernel",NULL,"PRJ.Z") returns "D:/Kernel/Kernel.PRJ.Z"
|
||||
("/Kernel/Dsk",NULL,"PRJ.Z") returns "D:/Kernel/Kernel.PRJ.Z"
|
||||
("/Apps/MusicOrgan","Load","CPP.Z") returns "D:/Apps/MusicOrgan/Load.CPP.Z"
|
||||
("/Apps/Psalmody","Load","CPP.Z") returns "D:/Apps/Psalmody/Load.CPP.Z"
|
||||
*/
|
||||
U8 *st=DirNameAbs(dirname),*st2,*st3,*result,*dft=NULL,*ext;
|
||||
if (_extension && *_extension) {
|
||||
if (*_extension=='.')
|
||||
ext=StrNew(_extension);
|
||||
else
|
||||
ext=MPrint(".%s",_extension);
|
||||
ext=MStrPrint(".%s",_extension);
|
||||
} else
|
||||
ext=StrNew("");
|
||||
while (StrOcc(st,'/')&&!IsDir(st))
|
||||
@@ -329,10 +332,10 @@ Strips file from dirname, scans for file upward until found or returns default.
|
||||
StrLastRem(st2,"/",st3);
|
||||
|
||||
if (name)
|
||||
result=MPrint("%s/%s%s",st,name,ext);
|
||||
result=MStrPrint("%s/%s%s",st,name,ext);
|
||||
else {
|
||||
if (*ext)
|
||||
result=MPrint("%s/%s%s",st,st3,ext);
|
||||
result=MStrPrint("%s/%s%s",st,st3,ext);
|
||||
else
|
||||
result=StrNew(st);
|
||||
}
|
||||
@@ -356,12 +359,17 @@ Strips file from dirname, scans for file upward until found or returns default.
|
||||
}
|
||||
|
||||
U8 *ToggleZorNotZ(U8 *name)
|
||||
{
|
||||
{//MAlloc name with Z if not Z or vice versa.
|
||||
U8 *result;
|
||||
if (IsDotZ(name)) {
|
||||
result=StrNew(name);
|
||||
result[StrLen(name)-2]=0;
|
||||
} else
|
||||
result=MPrint("%s.Z",name);
|
||||
result=MStrPrint("%s.Z",name);
|
||||
return result;
|
||||
}
|
||||
|
||||
U8 *FileNameTempTxt()
|
||||
{//Make pretty-safe temp filename in home dir.
|
||||
return MStrPrint("HOME/SysTemp%X.TXT.Z",GetTSC>>8&0xFFFFFFFF);
|
||||
}
|
||||
+28
-34
@@ -131,7 +131,6 @@ U0 FAT32Fmt(U8 drv_let,Bool quick=TRUE)
|
||||
Free(fis);
|
||||
}
|
||||
|
||||
|
||||
Bool FATNameTo(U8 *dst,U8 *src)
|
||||
{
|
||||
I64 i;
|
||||
@@ -228,7 +227,6 @@ Bool DirLongNameFill(CDirEntry *tempde,CFAT32DirEntryLong *de,I64 *xsum)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
Bool FAT32CDirFill(CDirEntry *tempde,CFAT32DirEntry *de)
|
||||
{
|
||||
Bool result;
|
||||
@@ -244,7 +242,7 @@ Bool FAT32CDirFill(CDirEntry *tempde,CFAT32DirEntry *de)
|
||||
}
|
||||
|
||||
Bool FAT32DirFill(CFAT32DirEntry *de,CDirEntry *tempde,I64 *_de_cnt=NULL)
|
||||
{ //Fill up to 3 entries and store cnt of entries.
|
||||
{//Fill up to 3 entries and store cnt of entries.
|
||||
I64 de_cnt=0,i,l,xsum,ord;
|
||||
U8 *ptr,dname[16];
|
||||
CFAT32DirEntryLong *ld=de;
|
||||
@@ -259,7 +257,7 @@ Bool FAT32DirFill(CFAT32DirEntry *de,CDirEntry *tempde,I64 *_de_cnt=NULL)
|
||||
if ((l=StrLen(tempde->name))>13) {
|
||||
ptr=&ld[de_cnt];
|
||||
MemSet(ptr,0,sizeof(CFAT32DirEntryLong));
|
||||
ld[de_cnt].attr=_ATTR_LONG_NAME;
|
||||
ld[de_cnt].attr=RS_ATTR_LONG_NAME;
|
||||
ld[de_cnt].xsum=xsum;
|
||||
ld[de_cnt].ord=0x42;
|
||||
for (i=13;i<l;i++)
|
||||
@@ -273,7 +271,7 @@ Bool FAT32DirFill(CFAT32DirEntry *de,CDirEntry *tempde,I64 *_de_cnt=NULL)
|
||||
}
|
||||
ptr=&de[de_cnt];
|
||||
MemSet(ptr,0,sizeof(CFAT32DirEntryLong));
|
||||
ld[de_cnt].attr=_ATTR_LONG_NAME;
|
||||
ld[de_cnt].attr=RS_ATTR_LONG_NAME;
|
||||
ld[de_cnt].xsum=xsum;
|
||||
ld[de_cnt].ord=ord;
|
||||
for (i=0;i<l;i++)
|
||||
@@ -287,7 +285,7 @@ Bool FAT32DirFill(CFAT32DirEntry *de,CDirEntry *tempde,I64 *_de_cnt=NULL)
|
||||
}
|
||||
de[de_cnt].cluster_lo=tempde->cluster.u16[0];
|
||||
de[de_cnt].cluster_hi=tempde->cluster.u16[1];
|
||||
if (!(tempde->attr&_ATTR_DIR))
|
||||
if (!(tempde->attr&RS_ATTR_DIR))
|
||||
de[de_cnt].size=tempde->size;
|
||||
de[de_cnt].attr=tempde->attr;
|
||||
if (!tempde->datetime)
|
||||
@@ -298,9 +296,8 @@ Bool FAT32DirFill(CFAT32DirEntry *de,CDirEntry *tempde,I64 *_de_cnt=NULL)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Bool FAT32FileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fuf_flags=0)
|
||||
{ //$LK,"FUF_JUST_DIRS",A="MN:FUF_JUST_DIRS"$, $LK,"FUF_JUST_FILES",A="MN:FUF_JUST_FILES"$
|
||||
{//$LK,"FUF_JUST_DIRS",A="MN:FUF_JUST_DIRS"$, $LK,"FUF_JUST_FILES",A="MN:FUF_JUST_FILES"$
|
||||
Bool result=FALSE,unlock;
|
||||
CFAT32DirEntry *buf;
|
||||
I64 xsum=0,attr,cur_dir_entry,entries_per_cluster;
|
||||
@@ -325,16 +322,16 @@ Bool FAT32FileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 f
|
||||
while (ch=*buf[cur_dir_entry].name) {
|
||||
attr=buf[cur_dir_entry].attr;
|
||||
if (ch!=0xE5) {
|
||||
if (attr&_ATTR_LONG_NAME_MASK==_ATTR_LONG_NAME)
|
||||
if (attr&RS_ATTR_LONG_NAME_MASK==RS_ATTR_LONG_NAME)
|
||||
DirLongNameFill(&long_name,&buf[cur_dir_entry],&xsum);
|
||||
else {
|
||||
if (!(attr&_ATTR_VOL_ID)) {
|
||||
if (!(attr&RS_ATTR_VOL_ID)) {
|
||||
if (xsum==FATNameXSum(buf[cur_dir_entry].name))
|
||||
MemCpy(_result,&long_name,sizeof(CDirEntry));
|
||||
else
|
||||
MemSet(_result,0,sizeof(CDirEntry));
|
||||
if (!(fuf_flags&FUF_JUST_DIRS && !(attr & _ATTR_DIR)) &&
|
||||
!(fuf_flags&FUF_JUST_FILES && attr & _ATTR_DIR) &&
|
||||
if (!(fuf_flags&FUF_JUST_DIRS && !(attr & RS_ATTR_DIR)) &&
|
||||
!(fuf_flags&FUF_JUST_FILES && attr & RS_ATTR_DIR) &&
|
||||
FAT32CDirFill(_result,&buf[cur_dir_entry]) &&
|
||||
!StrCmp(dname,_result->name)) {
|
||||
result=TRUE;
|
||||
@@ -412,7 +409,6 @@ Bool FAT32Cd(U8 *name,I64 cur_dir_cluster)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
U0 FAT32FreeClusters(CPrt *p,I64 c)
|
||||
{
|
||||
I64 next,saved_c=c;
|
||||
@@ -514,7 +510,6 @@ I64 FAT32AllocClusters(CPrt *p,I64 c,I64 cnt)
|
||||
return first;
|
||||
}
|
||||
|
||||
|
||||
I64 FAT32AllocContiguousClusters(CPrt *p,I64 cnt)
|
||||
{
|
||||
I64 i,first=1;
|
||||
@@ -600,7 +595,7 @@ Bool FAT32DirNew(CPrt *p,U8 *cur_dir,CDirEntry *tempde,Bool free_old_chain)
|
||||
cur_dir_entry=0;
|
||||
while (ch=*buf[cur_dir_entry].name) {
|
||||
attr=buf[cur_dir_entry].attr;
|
||||
if (ch!=0xE5 && attr&_ATTR_LONG_NAME_MASK==_ATTR_LONG_NAME)
|
||||
if (ch!=0xE5 && attr&RS_ATTR_LONG_NAME_MASK==RS_ATTR_LONG_NAME)
|
||||
DirLongNameFill(&long_name,&buf[cur_dir_entry],&xsum);
|
||||
else {
|
||||
avail_cnt=FAT32_ENTRIES_PER_BLK-cur_dir_entry & (FAT32_ENTRIES_PER_BLK-1);
|
||||
@@ -617,7 +612,7 @@ Bool FAT32DirNew(CPrt *p,U8 *cur_dir,CDirEntry *tempde,Bool free_old_chain)
|
||||
+cur_dir_entry>>FAT32_ENTRIES_BITS,1);
|
||||
cur_dir_entry+=de_cnt-1; //gets inc'ed
|
||||
written=TRUE;
|
||||
} else if (ch!=0xE5 && !(attr&_ATTR_VOL_ID)) {
|
||||
} else if (ch!=0xE5 && !(attr&RS_ATTR_VOL_ID)) {
|
||||
if (xsum!=FATNameXSum(buf[cur_dir_entry].name))
|
||||
MemSet(&long_name,0,sizeof(CDirEntry));
|
||||
if (!*long_name.name)
|
||||
@@ -637,7 +632,7 @@ Bool FAT32DirNew(CPrt *p,U8 *cur_dir,CDirEntry *tempde,Bool free_old_chain)
|
||||
*buf[cur_dir_entry].name=0xE5;
|
||||
i=1;
|
||||
while (i<=cur_dir_entry &&
|
||||
buf[cur_dir_entry-i].attr&_ATTR_LONG_NAME_MASK==_ATTR_LONG_NAME)
|
||||
buf[cur_dir_entry-i].attr&RS_ATTR_LONG_NAME_MASK==RS_ATTR_LONG_NAME)
|
||||
*buf[cur_dir_entry-i++].name=0xE5;
|
||||
i--;
|
||||
WBlks(p,&buf[(cur_dir_entry-i)&-FAT32_ENTRIES_PER_BLK],
|
||||
@@ -647,7 +642,7 @@ Bool FAT32DirNew(CPrt *p,U8 *cur_dir,CDirEntry *tempde,Bool free_old_chain)
|
||||
if (i==cur_dir_entry && 0<last_dir_cluster<0x0FFFFFF8) {
|
||||
i=1;
|
||||
while (i<=entries_per_cluster &&
|
||||
last_buf[entries_per_cluster-i].attr&_ATTR_LONG_NAME_MASK==_ATTR_LONG_NAME)
|
||||
last_buf[entries_per_cluster-i].attr&RS_ATTR_LONG_NAME_MASK==RS_ATTR_LONG_NAME)
|
||||
*last_buf[entries_per_cluster-i++].name=0xE5;
|
||||
if (--i>0)
|
||||
WBlks(p,&buf[(entries_per_cluster-i)&-FAT32_ENTRIES_PER_BLK],
|
||||
@@ -746,23 +741,23 @@ I64 FAT32FilesDel(CPrt *p,U8 *cur_dir,U8 *files_find_mask,I64 fuf_flags,
|
||||
while (ch=*buf[cur_dir_entry].name) {
|
||||
attr=buf[cur_dir_entry].attr;
|
||||
if (ch!=0xE5 && ch!='.') {
|
||||
if (attr&_ATTR_LONG_NAME_MASK==_ATTR_LONG_NAME)
|
||||
if (attr&RS_ATTR_LONG_NAME_MASK==RS_ATTR_LONG_NAME)
|
||||
DirLongNameFill(&long_name,&buf[cur_dir_entry],&xsum);
|
||||
else {
|
||||
if (!(attr & _ATTR_VOL_ID) &&
|
||||
(del_dir || !(attr & _ATTR_DIR))) {
|
||||
if (!(attr & RS_ATTR_VOL_ID) &&
|
||||
(del_dir || !(attr & RS_ATTR_DIR))) {
|
||||
if (xsum!=FATNameXSum(buf[cur_dir_entry].name))
|
||||
MemSet(&long_name,0,sizeof(CDirEntry));
|
||||
if (!*long_name.name)
|
||||
FATFromName(long_name.name,buf[cur_dir_entry].name);
|
||||
if (FilesFindMatch(long_name.name,files_find_mask,fuf_flags)) {
|
||||
if (!(attr & _ATTR_DIR)) result++;
|
||||
if (!(attr & RS_ATTR_DIR)) result++;
|
||||
if (print_msg)
|
||||
"Del %s\n",long_name.name;
|
||||
*buf[cur_dir_entry].name=0xE5;
|
||||
i=1;
|
||||
while (i<=cur_dir_entry &&
|
||||
buf[cur_dir_entry-i].attr&_ATTR_LONG_NAME_MASK==_ATTR_LONG_NAME)
|
||||
buf[cur_dir_entry-i].attr&RS_ATTR_LONG_NAME_MASK==RS_ATTR_LONG_NAME)
|
||||
*buf[cur_dir_entry-i++].name=0xE5;
|
||||
i--;
|
||||
WBlks(p,&buf[(cur_dir_entry-i)&-FAT32_ENTRIES_PER_BLK],
|
||||
@@ -772,7 +767,7 @@ I64 FAT32FilesDel(CPrt *p,U8 *cur_dir,U8 *files_find_mask,I64 fuf_flags,
|
||||
if (i==cur_dir_entry && last_dir_cluster!=INVALID_CLUSTER) {
|
||||
i=1;
|
||||
while (i<=entries_per_cluster &&
|
||||
last_buf[entries_per_cluster-i].attr&_ATTR_LONG_NAME_MASK==_ATTR_LONG_NAME)
|
||||
last_buf[entries_per_cluster-i].attr&RS_ATTR_LONG_NAME_MASK==RS_ATTR_LONG_NAME)
|
||||
*last_buf[entries_per_cluster-i++].name=0xE5;
|
||||
if (--i>0)
|
||||
WBlks(p,&buf[(entries_per_cluster-i)&-FAT32_ENTRIES_PER_BLK],
|
||||
@@ -823,7 +818,7 @@ I64 FAT32FileWrite(CPrt *p,U8 *cur_dir,U8 *name,U8 *buf,I64 size,
|
||||
PrintErr("Invalid FileName.\n");
|
||||
else {
|
||||
FAT32FilesDel(p,cur_dir,de.name,0,FALSE,FALSE);
|
||||
if (attr & _ATTR_CONTIGUOUS)
|
||||
if (attr & RS_ATTR_CONTIGUOUS)
|
||||
contiguous=TRUE;
|
||||
else
|
||||
contiguous=FALSE;
|
||||
@@ -864,10 +859,10 @@ CDirEntry *FAT32FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NU
|
||||
while (ch=*buf[cur_dir_entry].name) {
|
||||
attr=buf[cur_dir_entry].attr;
|
||||
if (ch!=0xE5) {
|
||||
if (attr&_ATTR_LONG_NAME_MASK==_ATTR_LONG_NAME)
|
||||
if (attr&RS_ATTR_LONG_NAME_MASK==RS_ATTR_LONG_NAME)
|
||||
DirLongNameFill(&long_name,&buf[cur_dir_entry],&xsum);
|
||||
else {
|
||||
if (!(attr&_ATTR_VOL_ID)) {
|
||||
if (!(attr&RS_ATTR_VOL_ID)) {
|
||||
tempde=MAlloc(sizeof(CDirEntry));
|
||||
if (xsum==FATNameXSum(buf[cur_dir_entry].name))
|
||||
MemCpy(tempde,&long_name,sizeof(CDirEntry));
|
||||
@@ -875,7 +870,7 @@ CDirEntry *FAT32FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NU
|
||||
MemSet(tempde,0,sizeof(CDirEntry));
|
||||
if (FAT32CDirFill(tempde,&buf[cur_dir_entry])) {
|
||||
tempde->parent=parent;
|
||||
if (Bt(&fuf_flags,FUf_RECURSE) && attr&_ATTR_DIR && *tempde->name!='.') {
|
||||
if (Bt(&fuf_flags,FUf_RECURSE) && attr&RS_ATTR_DIR && *tempde->name!='.') {
|
||||
tempde->next=result;
|
||||
result=tempde;
|
||||
tempde->full_name=DirNameAbs(tempde->name);
|
||||
@@ -886,8 +881,8 @@ CDirEntry *FAT32FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NU
|
||||
Cd("..");
|
||||
}
|
||||
PrtLock(p);
|
||||
} else if ((attr&_ATTR_DIR || !Bt(&fuf_flags,FUf_JUST_DIRS)) &&
|
||||
!(Bt(&fuf_flags,FUf_RECURSE) && *tempde->name=='.' && attr&_ATTR_DIR) &&
|
||||
} else if ((attr&RS_ATTR_DIR || !Bt(&fuf_flags,FUf_JUST_DIRS)) &&
|
||||
!(Bt(&fuf_flags,FUf_RECURSE) && *tempde->name=='.' && attr&RS_ATTR_DIR) &&
|
||||
FilesFindMatch(tempde->name,files_find_mask,fuf_flags)) {
|
||||
tempde->next=result;
|
||||
result=tempde;
|
||||
@@ -921,7 +916,6 @@ CDirEntry *FAT32FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NU
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Bool FAT32MkDir(CPrt *p,U8 *cur_dir,U8 *name)
|
||||
{
|
||||
I64 size=p->spc<<BLK_SIZE_BITS,c,
|
||||
@@ -933,9 +927,9 @@ Bool FAT32MkDir(CPrt *p,U8 *cur_dir,U8 *name)
|
||||
|
||||
try {
|
||||
unlock_break=BreakLock;
|
||||
c=FileWrite(name,buf,size,0,_ATTR_DIR,FALSE);
|
||||
c=FileWrite(name,buf,size,0,RS_ATTR_DIR,FALSE);
|
||||
MemSet(&d_native,0,sizeof(CDirEntry));
|
||||
d_native.attr=_ATTR_DIR;
|
||||
d_native.attr=RS_ATTR_DIR;
|
||||
*d_native.name='.';
|
||||
d_native.name[1]=0;
|
||||
d_native.cluster=c;
|
||||
@@ -945,7 +939,7 @@ Bool FAT32MkDir(CPrt *p,U8 *cur_dir,U8 *name)
|
||||
dFAT++;
|
||||
|
||||
MemSet(&d_native,0,sizeof(CDirEntry));
|
||||
d_native.attr=_ATTR_DIR;
|
||||
d_native.attr=RS_ATTR_DIR;
|
||||
*d_native.name='.';
|
||||
d_native.name[1]='.';
|
||||
d_native.name[2]=0;
|
||||
|
||||
@@ -121,13 +121,13 @@ Bool ISO1CDirFill(CDirEntry *tempde,CISO1DirEntry *de)
|
||||
tempde->size=de->size.little;
|
||||
tempde->attr=FileAttr(tempde->name);
|
||||
if (de->flags & ISO1_ATTR_DIR)
|
||||
tempde->attr|=_ATTR_DIR;
|
||||
tempde->attr|=RS_ATTR_DIR;
|
||||
tempde->datetime=ISO1DateStruct2CDate(&de->date);
|
||||
return result;
|
||||
}
|
||||
|
||||
Bool ISO1FileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fuf_flags=0)
|
||||
{ //$LK,"FUF_JUST_DIRS",A="MN:FUF_JUST_DIRS"$, $LK,"FUF_JUST_FILES",A="MN:FUF_JUST_FILES"$
|
||||
{//$LK,"FUF_JUST_DIRS",A="MN:FUF_JUST_DIRS"$, $LK,"FUF_JUST_FILES",A="MN:FUF_JUST_FILES"$
|
||||
CISO1DirEntry *isoptr,*buf;
|
||||
U8 dname[CDIR_FILENAME_LEN];
|
||||
Bool result=FALSE,unlock;
|
||||
@@ -142,7 +142,7 @@ Bool ISO1FileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fu
|
||||
unlock=PrtLock(p);
|
||||
isoptr=MAlloc(p->spc<<BLK_SIZE_BITS);
|
||||
RClusters(Fs->cur_prt,isoptr,cur_dir_cluster,1);
|
||||
if (isoptr->name_len==1 && !isoptr->name) { //curdir
|
||||
if (isoptr->name_len==1 && !isoptr->name) {//curdir
|
||||
i=(isoptr->size.little+p->spc<<BLK_SIZE_BITS-1)/p->spc<<BLK_SIZE_BITS;
|
||||
buf=MAlloc(p->spc<<BLK_SIZE_BITS*i);
|
||||
RClusters(Fs->cur_prt,buf,cur_dir_cluster,i);
|
||||
@@ -163,8 +163,8 @@ Bool ISO1FileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fu
|
||||
if (!StrCmp(name,dname)) {
|
||||
result=ISO1CDirFill(_result,isoptr);
|
||||
if (result &&
|
||||
!(fuf_flags&FUF_JUST_DIRS && !(_result->attr & _ATTR_DIR)) &&
|
||||
!(fuf_flags&FUF_JUST_FILES && _result->attr & _ATTR_DIR) )
|
||||
!(fuf_flags&FUF_JUST_DIRS && !(_result->attr & RS_ATTR_DIR)) &&
|
||||
!(fuf_flags&FUF_JUST_FILES && _result->attr & RS_ATTR_DIR) )
|
||||
goto exit_this;
|
||||
else
|
||||
result=FALSE;
|
||||
@@ -237,7 +237,7 @@ CDirEntry *ISO1FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NUL
|
||||
throw('FUF');
|
||||
isoptr=MAlloc(p->spc<<BLK_SIZE_BITS);
|
||||
RClusters(Fs->cur_prt,isoptr,cur_dir_cluster,1);
|
||||
if (isoptr->name_len==1 && !isoptr->name) { //curdir
|
||||
if (isoptr->name_len==1 && !isoptr->name) {//curdir
|
||||
i=(isoptr->size.little+p->spc<<BLK_SIZE_BITS-1)/p->spc<<BLK_SIZE_BITS;
|
||||
buf=MAlloc(p->spc<<BLK_SIZE_BITS*i);
|
||||
RClusters(Fs->cur_prt,buf,cur_dir_cluster,i);
|
||||
@@ -256,7 +256,7 @@ CDirEntry *ISO1FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NUL
|
||||
tempde=MAlloc(sizeof(CDirEntry));
|
||||
if (ISO1CDirFill(tempde,buf)) {
|
||||
tempde->parent=parent;
|
||||
if (Bt(&fuf_flags,FUf_RECURSE) && tempde->attr&_ATTR_DIR && *tempde->name!='.') {
|
||||
if (Bt(&fuf_flags,FUf_RECURSE) && tempde->attr&RS_ATTR_DIR && *tempde->name!='.') {
|
||||
tempde->next=result;
|
||||
result=tempde;
|
||||
tempde->full_name=DirNameAbs(tempde->name);
|
||||
@@ -264,8 +264,8 @@ CDirEntry *ISO1FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NUL
|
||||
tempde->sub=ISO1FilesFind(files_find_mask,fuf_flags,tempde);
|
||||
Cd("..");
|
||||
}
|
||||
} else if ((tempde->attr & _ATTR_DIR || !Bt(&fuf_flags,FUf_JUST_DIRS)) &&
|
||||
!(Bt(&fuf_flags,FUf_RECURSE) && *tempde->name=='.' && tempde->attr&_ATTR_DIR) &&
|
||||
} else if ((tempde->attr & RS_ATTR_DIR || !Bt(&fuf_flags,FUf_JUST_DIRS)) &&
|
||||
!(Bt(&fuf_flags,FUf_RECURSE) && *tempde->name=='.' && tempde->attr&RS_ATTR_DIR) &&
|
||||
FilesFindMatch(tempde->name,files_find_mask,fuf_flags)) {
|
||||
tempde->next=result;
|
||||
result=tempde;
|
||||
|
||||
@@ -130,7 +130,7 @@ U0 RedSeaFSFmt(U8 drv_let,Bool quick=TRUE)
|
||||
|
||||
d_native=root_dir-offset(CDirEntry.start);
|
||||
|
||||
d_native->attr=_ATTR_DIR|_ATTR_CONTIGUOUS;
|
||||
d_native->attr=RS_ATTR_DIR|RS_ATTR_CONTIGUOUS;
|
||||
*d_native->name='.';
|
||||
d_native->cluster=br->root_cluster;
|
||||
d_native->size=BLK_SIZE;
|
||||
@@ -140,7 +140,7 @@ U0 RedSeaFSFmt(U8 drv_let,Bool quick=TRUE)
|
||||
|
||||
*d_native->name='.';
|
||||
d_native->name[1]='.';
|
||||
d_native->attr=_ATTR_DIR|_ATTR_CONTIGUOUS;
|
||||
d_native->attr=RS_ATTR_DIR|RS_ATTR_CONTIGUOUS;
|
||||
d_native->cluster=br->root_cluster;
|
||||
d_native->datetime=Now;
|
||||
|
||||
@@ -154,7 +154,7 @@ U0 RedSeaFSFmt(U8 drv_let,Bool quick=TRUE)
|
||||
}
|
||||
|
||||
Bool RedSeaFSFileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fuf_flags=0)
|
||||
{ //$LK,"FUF_JUST_DIRS",A="MN:FUF_JUST_DIRS"$, $LK,"FUF_JUST_FILES",A="MN:FUF_JUST_FILES"$
|
||||
{//$LK,"FUF_JUST_DIRS",A="MN:FUF_JUST_DIRS"$, $LK,"FUF_JUST_FILES",A="MN:FUF_JUST_FILES"$
|
||||
CDirEntry *buf,*buf2,*ptr;
|
||||
U8 dname[CDIR_FILENAME_LEN];
|
||||
I64 ch;
|
||||
@@ -184,9 +184,9 @@ Bool RedSeaFSFileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I6
|
||||
while (TRUE) {
|
||||
if (!(ch=*ptr->name))
|
||||
break;
|
||||
else if (!(ptr->attr & _ATTR_DELETED) &&
|
||||
!(fuf_flags&FUF_JUST_DIRS && !(ptr->attr & _ATTR_DIR)) &&
|
||||
!(fuf_flags&FUF_JUST_FILES && ptr->attr & _ATTR_DIR) &&
|
||||
else if (!(ptr->attr & RS_ATTR_DELETED) &&
|
||||
!(fuf_flags&FUF_JUST_DIRS && !(ptr->attr & RS_ATTR_DIR)) &&
|
||||
!(fuf_flags&FUF_JUST_FILES && ptr->attr & RS_ATTR_DIR) &&
|
||||
!StrCmp(dname,ptr->name)) {
|
||||
MemCpy(&_result->attr,&ptr->attr,CDIR_SIZE);
|
||||
result=TRUE;
|
||||
@@ -204,8 +204,6 @@ exit_this:
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
U8 *RedSeaFSFileRead(CPrt *p,U8 *cur_dir,U8 *filename,I64 *_size,I64 *_attr)
|
||||
{
|
||||
U8 *buf=NULL;
|
||||
@@ -351,7 +349,6 @@ I64 RedSeaFSAllocClusters(CPrt *p,I64 cnt)
|
||||
return first;
|
||||
}
|
||||
|
||||
|
||||
Bool RedSeaFSDirNew(CPrt *p,U8 *cur_dir,CDirEntry *de,Bool free_old_chain)
|
||||
{
|
||||
CDirEntry *buf,*buf2,*ptr,de2;
|
||||
@@ -361,7 +358,7 @@ Bool RedSeaFSDirNew(CPrt *p,U8 *cur_dir,CDirEntry *de,Bool free_old_chain)
|
||||
U8 *temp,*parent_dir;
|
||||
try {
|
||||
unlock_break=BreakLock;
|
||||
de->attr|=_ATTR_CONTIGUOUS;
|
||||
de->attr|=RS_ATTR_CONTIGUOUS;
|
||||
unlock=PrtLock(p);
|
||||
cur_dir_cluster=Name2DirCluster(p,cur_dir);
|
||||
buf2=MAlloc(BLK_SIZE);
|
||||
@@ -419,7 +416,7 @@ Bool RedSeaFSDirNew(CPrt *p,U8 *cur_dir,CDirEntry *de,Bool free_old_chain)
|
||||
}
|
||||
}
|
||||
break;
|
||||
} else if (ptr->attr & _ATTR_DELETED) {
|
||||
} else if (ptr->attr & RS_ATTR_DELETED) {
|
||||
if (!written) {
|
||||
MemCpy(&ptr->start,&de->start,CDIR_SIZE);
|
||||
WBlks(p,buf(U8 *)+j<<BLK_SIZE_BITS,p->data+cur_dir_cluster+j,1);
|
||||
@@ -433,7 +430,7 @@ Bool RedSeaFSDirNew(CPrt *p,U8 *cur_dir,CDirEntry *de,Bool free_old_chain)
|
||||
if (!written)
|
||||
MemCpy(&ptr->start,&de->start,CDIR_SIZE);
|
||||
else
|
||||
ptr->attr|=_ATTR_DELETED;
|
||||
ptr->attr|=RS_ATTR_DELETED;
|
||||
WBlks(p,buf(U8 *)+j<<BLK_SIZE_BITS,p->data+cur_dir_cluster+j,1);
|
||||
break;
|
||||
}
|
||||
@@ -482,13 +479,13 @@ I64 RedSeaFSFilesDel(CPrt *p,U8 *cur_dir,U8 *files_find_mask,I64 fuf_flags,
|
||||
while (TRUE) {
|
||||
if (!(ch=*ptr->name))
|
||||
break;
|
||||
else if (!(ptr->attr & _ATTR_DELETED) && ch!='.' && (del_dir ||
|
||||
!(ptr->attr & _ATTR_DIR)) &&
|
||||
else if (!(ptr->attr & RS_ATTR_DELETED) && ch!='.' && (del_dir ||
|
||||
!(ptr->attr & RS_ATTR_DIR)) &&
|
||||
FilesFindMatch(ptr->name,files_find_mask,fuf_flags)) {
|
||||
if (!(ptr->attr & _ATTR_DIR)) result++;
|
||||
if (!(ptr->attr & RS_ATTR_DIR)) result++;
|
||||
if (print_msg)
|
||||
"Del %s\n",ptr->name;
|
||||
ptr->attr|=_ATTR_DELETED;
|
||||
ptr->attr|=RS_ATTR_DELETED;
|
||||
WBlks(p,buf(U8 *)+j<<BLK_SIZE_BITS,p->data+cur_dir_cluster+j,1);
|
||||
RedSeaFSFreeClusters(p,ptr->cluster,(ptr->size+BLK_SIZE-1)>>BLK_SIZE_BITS);
|
||||
}
|
||||
@@ -529,7 +526,7 @@ I64 RedSeaFSFileWrite(CPrt *p,U8 *cur_dir,U8 *name,U8 *buf,I64 size,
|
||||
else
|
||||
c=INVALID_CLUSTER;
|
||||
de.cluster=c;
|
||||
de.attr=attr|_ATTR_CONTIGUOUS;
|
||||
de.attr=attr|RS_ATTR_CONTIGUOUS;
|
||||
de.datetime=cdt;
|
||||
if (blk_cnt)
|
||||
WClustersBlks(p,buf,c,blk_cnt);
|
||||
@@ -565,11 +562,11 @@ CDirEntry *RedSeaFSFilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent
|
||||
while (TRUE) {
|
||||
if (!(ch=*ptr->name))
|
||||
break;
|
||||
else if (!(ptr->attr & _ATTR_DELETED)) {
|
||||
else if (!(ptr->attr & RS_ATTR_DELETED)) {
|
||||
tempde=CAlloc(sizeof(CDirEntry));
|
||||
MemCpy(&tempde->start,&ptr->start,CDIR_SIZE);
|
||||
tempde->parent=parent;
|
||||
if (Bt(&fuf_flags,FUf_RECURSE) && tempde->attr&_ATTR_DIR && *tempde->name!='.') {
|
||||
if (Bt(&fuf_flags,FUf_RECURSE) && tempde->attr&RS_ATTR_DIR && *tempde->name!='.') {
|
||||
tempde->next=result;
|
||||
result=tempde;
|
||||
tempde->full_name=DirNameAbs(tempde->name);
|
||||
@@ -579,8 +576,8 @@ CDirEntry *RedSeaFSFilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent
|
||||
Cd("..");
|
||||
}
|
||||
PrtLock(p);
|
||||
} else if ((tempde->attr&_ATTR_DIR || !Bt(&fuf_flags,FUf_JUST_DIRS)) &&
|
||||
!(Bt(&fuf_flags,FUf_RECURSE) && *tempde->name=='.' && tempde->attr&_ATTR_DIR) &&
|
||||
} else if ((tempde->attr&RS_ATTR_DIR || !Bt(&fuf_flags,FUf_JUST_DIRS)) &&
|
||||
!(Bt(&fuf_flags,FUf_RECURSE) && *tempde->name=='.' && tempde->attr&RS_ATTR_DIR) &&
|
||||
FilesFindMatch(tempde->name,files_find_mask,fuf_flags)) {
|
||||
tempde->next=result;
|
||||
result=tempde;
|
||||
@@ -606,15 +603,15 @@ Bool RedSeaFSMkDir(CPrt *p,U8 *cur_dir,U8 *name)
|
||||
|
||||
try {
|
||||
unlock_break=BreakLock;
|
||||
c=FileWrite(name,buf,size,0,_ATTR_DIR,FALSE);
|
||||
d_native->attr=_ATTR_DIR|_ATTR_CONTIGUOUS;
|
||||
c=FileWrite(name,buf,size,0,RS_ATTR_DIR,FALSE);
|
||||
d_native->attr=RS_ATTR_DIR|RS_ATTR_CONTIGUOUS;
|
||||
StrCpy(d_native->name,name);
|
||||
d_native->cluster=c;
|
||||
d_native->size=size;
|
||||
d_native->datetime=Now;
|
||||
d_native(U8 *)+=CDIR_SIZE;
|
||||
|
||||
d_native->attr=_ATTR_DIR|_ATTR_CONTIGUOUS;
|
||||
d_native->attr=RS_ATTR_DIR|RS_ATTR_CONTIGUOUS;
|
||||
*d_native->name='.';
|
||||
d_native->name[1]='.';
|
||||
d_native->name[2]=0;
|
||||
|
||||
+26
-28
@@ -10,11 +10,11 @@ U0 EdLiteUpdate(CLine *root,CLine *cur_line,I64 cur_col,I64 line_start_col)
|
||||
U8 *st;
|
||||
CLine *templ=cur_line;
|
||||
Bool done_eof=FALSE;
|
||||
sys_raw_col=0;
|
||||
for (i=0;i<text_rows/2;i++)
|
||||
text.raw_col=0;
|
||||
for (i=0;i<text.rows/2;i++)
|
||||
if (templ->last!=root)
|
||||
templ=templ->last;
|
||||
for (i=0;i<text_rows;i++) {
|
||||
for (i=0;i<text.rows;i++) {
|
||||
if (cursor_row<0 && templ==cur_line) {
|
||||
k=0;
|
||||
for (j=0;j<cur_col;j++)
|
||||
@@ -34,46 +34,44 @@ U0 EdLiteUpdate(CLine *root,CLine *cur_line,I64 cur_col,I64 line_start_col)
|
||||
k2=(k+8)&~7;
|
||||
else
|
||||
k2=k+1;
|
||||
if (line_start_col<=k<line_start_col+text_cols) {
|
||||
if (line_start_col<=k<line_start_col+text.cols) {
|
||||
'' ch;
|
||||
j=k2-line_start_col;
|
||||
}
|
||||
k=k2;
|
||||
}
|
||||
if (j<text_cols)
|
||||
NewLine;
|
||||
if (j<text.cols)
|
||||
'\n';
|
||||
templ=templ->next;
|
||||
} else {
|
||||
if (!done_eof) {
|
||||
"<EOF>";
|
||||
done_eof=TRUE;
|
||||
}
|
||||
NewLine;
|
||||
'\n';
|
||||
}
|
||||
}
|
||||
sys_raw_col=text_cols*cursor_row+cursor_col-line_start_col;
|
||||
text.raw_col=text.cols*cursor_row+cursor_col-line_start_col;
|
||||
RawPutChar(0x7F);
|
||||
}
|
||||
|
||||
|
||||
U0 EdLite(U8 *filename,I64 num=1)
|
||||
{
|
||||
//Light weight text editor for debugging
|
||||
{//Light weight text editor for debugging.
|
||||
U8 *src,*src2,*src3,*dst,*buf,*bin_data=NULL;
|
||||
I64 i,cnt=0,ch,sc,size,bin_size=0,line_start_col=0,cur_col=0,
|
||||
old_raw_flags=sys_raw_flags;
|
||||
old_raw_flags=text.raw_flags;
|
||||
CLine root,*templ,*templ1,*cur_line;
|
||||
Bool old_raw=Raw(ON),
|
||||
old_debug=InDbg(ON),
|
||||
old_single=SingleUser(ON);
|
||||
|
||||
if (!filename) filename=sys_temp_filename;
|
||||
if (!filename) filename=dsk.temp_filename;
|
||||
buf=FileRead(filename,&size);
|
||||
|
||||
PUSHFD
|
||||
CLI
|
||||
sys_raw_flags=sys_raw_flags&~RWF_SCROLL|RWF_SHOW_DOLLAR;
|
||||
sys_cur_scan_code=0;
|
||||
text.raw_flags=text.raw_flags&~RWF_SCROLL|RWF_SHOW_DOLLAR;
|
||||
kbd.scan_code=0;
|
||||
QueInit(&root);
|
||||
root.line=StrNew("");
|
||||
|
||||
@@ -120,7 +118,7 @@ U0 EdLite(U8 *filename,I64 num=1)
|
||||
cur_col=0;
|
||||
while (cur_col-line_start_col<0)
|
||||
line_start_col-=8;
|
||||
while (cur_col-line_start_col>=text_cols)
|
||||
while (cur_col-line_start_col>=text.cols)
|
||||
line_start_col+=8;
|
||||
EdLiteUpdate(&root,cur_line,cur_col,line_start_col);
|
||||
switch (ch=GetKey(&sc,FALSE,TRUE)) {
|
||||
@@ -161,7 +159,7 @@ U0 EdLite(U8 *filename,I64 num=1)
|
||||
}
|
||||
break;
|
||||
case SC_PAGE_UP:
|
||||
for (i=1;i<text_rows;i++) {
|
||||
for (i=1;i<text.rows;i++) {
|
||||
if (cur_line->last!=&root)
|
||||
cur_line=cur_line->last;
|
||||
if (cur_col>StrLen(cur_line->line))
|
||||
@@ -169,7 +167,7 @@ U0 EdLite(U8 *filename,I64 num=1)
|
||||
}
|
||||
break;
|
||||
case SC_PAGE_DOWN:
|
||||
for (i=1;i<text_rows;i++) {
|
||||
for (i=1;i<text.rows;i++) {
|
||||
if (cur_line!=&root)
|
||||
cur_line=cur_line->next;
|
||||
if (cur_col>StrLen(cur_line->line))
|
||||
@@ -180,7 +178,7 @@ U0 EdLite(U8 *filename,I64 num=1)
|
||||
if (cur_col==StrLen(cur_line->line)) {
|
||||
templ=cur_line->next;
|
||||
if (cur_line!=&root && templ!=&root) {
|
||||
src=MPrint("%s%s",cur_line->line,templ->line);
|
||||
src=MStrPrint("%s%s",cur_line->line,templ->line);
|
||||
Free(cur_line->line);
|
||||
Free(templ->line);
|
||||
cur_line->line=src;
|
||||
@@ -207,7 +205,7 @@ U0 EdLite(U8 *filename,I64 num=1)
|
||||
cur_col--;
|
||||
} else if (cur_line!=&root && cur_line->last!=&root) {
|
||||
templ=cur_line->last;
|
||||
src=MPrint("%s%s",templ->line,cur_line->line);
|
||||
src=MStrPrint("%s%s",templ->line,cur_line->line);
|
||||
cur_col=StrLen(templ->line);
|
||||
Free(cur_line->line);
|
||||
Free(templ->line);
|
||||
@@ -285,18 +283,18 @@ U0 EdLite(U8 *filename,I64 num=1)
|
||||
Raw(old_raw);
|
||||
InDbg(old_debug);
|
||||
SingleUser(old_single);
|
||||
sys_raw_flags=sys_raw_flags&~RWF_SHOW_DOLLAR|old_raw_flags&RWF_SHOW_DOLLAR;
|
||||
text.raw_flags=text.raw_flags&~RWF_SHOW_DOLLAR|old_raw_flags&RWF_SHOW_DOLLAR;
|
||||
POPFD
|
||||
}
|
||||
|
||||
U0 ToFileLine(U8 *_fl_file_line,U8 **_filename,I64 *_linenum)
|
||||
{
|
||||
{//"FI:D:/Dir/File.CPP,123" to "D:/Dir/File.CPP" and 123.
|
||||
U8 *st,*fl_file_line=StrNew(_fl_file_line);
|
||||
I64 linenum;
|
||||
StrFirstRem(fl_file_line,":");
|
||||
st=StrNew(fl_file_line);
|
||||
StrLastRem(fl_file_line,",",st);
|
||||
linenum=A2I64(st);
|
||||
linenum=Str2I64(st);
|
||||
Free(st);
|
||||
*_filename=fl_file_line;
|
||||
*_linenum=linenum;
|
||||
@@ -313,21 +311,21 @@ U0 EdLiteFileLine(U8 *fl_file_line)
|
||||
|
||||
U0 SetFix(U8 *filename,I64 line)
|
||||
{//Compiler calls this to set file line for Fix
|
||||
U8 *st=MPrint("FL:%s,%d",filename,line);
|
||||
U8 *st=MStrPrint("FL:%s,%d",filename,line);
|
||||
while (LBts(&sys_semas[SYS_SEMA_FIX],0))
|
||||
Yield;
|
||||
Free(sys_fix_file_line);
|
||||
sys_fix_file_line=AStrNew(st);
|
||||
Free(dbg.fix_file_line);
|
||||
dbg.fix_file_line=AStrNew(st);
|
||||
LBtr(&sys_semas[SYS_SEMA_FIX],0);
|
||||
}
|
||||
|
||||
U0 Fix()
|
||||
{//Fix last compile err
|
||||
{//Jump to last err src code to fix it.
|
||||
U8 *st;
|
||||
|
||||
while (LBts(&sys_semas[SYS_SEMA_FIX],0))
|
||||
Yield;
|
||||
st=StrNew(sys_fix_file_line);
|
||||
st=StrNew(dbg.fix_file_line);
|
||||
LBtr(&sys_semas[SYS_SEMA_FIX],0);
|
||||
|
||||
if (st) {
|
||||
|
||||
+7
-7
@@ -44,7 +44,7 @@ _extern _TAKE_EXCEPT U0 TakeExcept();
|
||||
_extern _SAVE_EXCEPT_REGS U0 SaveExceptRegs(CExcept *t);
|
||||
|
||||
U0 PutExcept(Bool catch_it=TRUE)
|
||||
{
|
||||
{//Print exception msg and catch exception.
|
||||
"Except:%c:%P:%P\n",Fs->except_ch,Fs->except_caller1,Fs->except_caller2;
|
||||
Fs->catch_except=catch_it;
|
||||
}
|
||||
@@ -80,7 +80,8 @@ U0 SysUntry()
|
||||
}
|
||||
|
||||
U0 throw(I64 ch=0,Bool no_log=FALSE)
|
||||
{
|
||||
{//ch can be up to 8 chars like $LK,"PutChars",A="MN:PutChars"$().
|
||||
//In the catcher, fetch ch from Fs->except_ch.
|
||||
CExcept *tempt=Fs->last_except;
|
||||
Bool was_raw;
|
||||
Fs->except_ch=ch;
|
||||
@@ -111,7 +112,7 @@ U0 SysThrowBreak()
|
||||
{
|
||||
if (Bt(&Fs->task_flags,TASKf_BREAK_TO_SHIFT_ESC))
|
||||
Msg(MSG_KEY_DOWN,CH_SHIFT_ESC,0x20100000201);
|
||||
else { //TODO: Might want lock
|
||||
else {//TODO: Might want lock
|
||||
Fs->wake_jiffy=0;
|
||||
TaskRstAwaitingMsg;
|
||||
PrtsRelease();
|
||||
@@ -121,9 +122,8 @@ U0 SysThrowBreak()
|
||||
}
|
||||
}
|
||||
|
||||
//This can be used to exit an app, but not a task.
|
||||
U0 ThrowBreak(CTask *task=NULL)
|
||||
{
|
||||
{//Can be used to exit an app, but not a task.
|
||||
if (task && task!=Fs) {
|
||||
if (!TaskValidate(task)) return;
|
||||
//TODO: Might want lock
|
||||
@@ -134,13 +134,13 @@ U0 ThrowBreak(CTask *task=NULL)
|
||||
}
|
||||
|
||||
Bool BreakLock(CTask *task=NULL)
|
||||
{ //This disables CTRL-ALT-C
|
||||
{//Disables <CTRL-ALT-c>.
|
||||
if (!task) task=Fs;
|
||||
return !LBts(&task->task_flags,TASKf_BREAK_LOCKED);
|
||||
}
|
||||
|
||||
Bool BreakUnlock(CTask *task=NULL)
|
||||
{
|
||||
{//Reenables <CTRL-ALT-c> and issues any pending breaks.
|
||||
Bool result;
|
||||
if (!task) task=Fs;
|
||||
result=LBtr(&task->task_flags,TASKf_BREAK_LOCKED);
|
||||
|
||||
Binary file not shown.
+105
-74
@@ -1,5 +1,5 @@
|
||||
I64 HashTypeNum(CHash *temph)
|
||||
{
|
||||
{//Return bit num of hash type, limited to just types.
|
||||
if (temph)
|
||||
return Bsf(temph->type&HTG_TYPE_MASK);
|
||||
else
|
||||
@@ -7,7 +7,7 @@ I64 HashTypeNum(CHash *temph)
|
||||
}
|
||||
|
||||
I64 HashVal(CHash *temph)
|
||||
{
|
||||
{//Returns most likely desired value.
|
||||
nobound_switch (HashTypeNum(temph)) {
|
||||
case HTt_EXPORT_SYS_SYM:
|
||||
return temph(CHashExport *)->val;
|
||||
@@ -48,17 +48,17 @@ I64 HashVal(CHash *temph)
|
||||
}
|
||||
|
||||
CHashTable *HashTableNew(I64 size,CTask *mem_task=NULL)
|
||||
{
|
||||
CHashTable *tempht;
|
||||
tempht=CAlloc(sizeof(CHashTable),mem_task);
|
||||
tempht->body=CAlloc(size<<3,mem_task);
|
||||
tempht->mask=size-1;
|
||||
tempht->next_added=tempht->last_added=tempht;
|
||||
return tempht;
|
||||
{//New hash table, power-of-two in size.
|
||||
CHashTable *table;
|
||||
table=CAlloc(sizeof(CHashTable),mem_task);
|
||||
table->body=CAlloc(size<<3,mem_task);
|
||||
table->mask=size-1;
|
||||
table->next_added=table->last_added=table;
|
||||
return table;
|
||||
}
|
||||
|
||||
U0 HashDel(CHashSrcSym *temph)
|
||||
{
|
||||
{//Free a std TempleOS system hash entry.
|
||||
if (!temph) return;
|
||||
if (!(temph->type&HTT_DICT_WORD))
|
||||
Free(temph->str);
|
||||
@@ -68,7 +68,7 @@ U0 HashDel(CHashSrcSym *temph)
|
||||
Free(temph->import_name);
|
||||
LinkedLstDel(temph->ie_lst);
|
||||
if (temph->type & (HTT_FUN | HTT_EXPORT_SYS_SYM))
|
||||
Free(temph->debug);
|
||||
Free(temph->dbg_info);
|
||||
if (temph->type & (HTT_FUN | HTT_CLASS))
|
||||
//Assumes code not on heap, so doesn't Free.
|
||||
//$LK,"MemberLstDel",A="MN:MemberLstDel"$() is an import to the Kernel module
|
||||
@@ -87,29 +87,29 @@ U0 HashDel(CHashSrcSym *temph)
|
||||
Free(temph);
|
||||
}
|
||||
|
||||
U0 HashTableDel(CHashTable *tempht)
|
||||
{
|
||||
U0 HashTableDel(CHashTable *table)
|
||||
{//Free std system hash table, calling $LK,"HashDel",A="MN:HashDel"$() on entries.
|
||||
CHashSrcSym *temph,*temph1;
|
||||
if (!tempht) return;
|
||||
temph=tempht->next_added;
|
||||
while (temph!=tempht) {
|
||||
if (!table) return;
|
||||
temph=table->next_added;
|
||||
while (temph!=table) {
|
||||
temph1=temph->next_added;
|
||||
HashDel(temph);
|
||||
temph=temph1;
|
||||
}
|
||||
Free(tempht->body);
|
||||
Free(tempht);
|
||||
Free(table->body);
|
||||
Free(table);
|
||||
}
|
||||
|
||||
I64 HashTablePurge(CHashTable *tempht)
|
||||
{
|
||||
I64 HashTablePurge(CHashTable *table)
|
||||
{//Eliminate ExportSysSyms that have been usurped.
|
||||
I64 result=0;
|
||||
CHashSrcSym *temph,*temph1,*temph2;
|
||||
if (!tempht) return 0;
|
||||
if (!table) return 0;
|
||||
PUSHFD
|
||||
CLI //Precaution
|
||||
temph=tempht->next_added;
|
||||
while (temph!=tempht) {
|
||||
temph=table->next_added;
|
||||
while (temph!=table) {
|
||||
temph1=temph->next_added; //We delete only older ones
|
||||
if (temph->type&(HTT_FUN|HTT_GLBL_VAR)) {
|
||||
temph2=temph->next; //Older always later in chain
|
||||
@@ -118,7 +118,7 @@ I64 HashTablePurge(CHashTable *tempht)
|
||||
!StrCmp(temph2->str,temph->str)) {
|
||||
if (temph2->type&HTG_TYPE_MASK==HTT_INVALID)
|
||||
temph2->type=HTT_KEYWORD;//Won't delete HTT_INVALID
|
||||
HashRemDel(temph2,tempht);
|
||||
HashRemDel(temph2,table);
|
||||
result++;
|
||||
break;
|
||||
}
|
||||
@@ -132,7 +132,7 @@ I64 HashTablePurge(CHashTable *tempht)
|
||||
}
|
||||
|
||||
CHashGeneric *HashGenericAdd(U8 *name,I64 type,I64 u0=0,I64 u1=0,I64 u2=0,CTask *task=NULL)
|
||||
{
|
||||
{//Add any type to task hash_table, 3 user_data values.
|
||||
if (!task) task=Fs;
|
||||
CHashGeneric *result=CAlloc(sizeof(CHashGeneric),task);
|
||||
result->type=type;
|
||||
@@ -144,20 +144,24 @@ CHashGeneric *HashGenericAdd(U8 *name,I64 type,I64 u0=0,I64 u1=0,I64 u2=0,CTask
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 SetSrcFileInfo(CLex *lx,CHashSrcSym *h)
|
||||
{
|
||||
U0 SetSrcFileInfo(CLex *lx,CHashSrcSym *h,I64 line_num_offset=0)
|
||||
{//Set $LK,"CHashSrcSym",A="MN:CHashSrcSym"$ link and help_index by cur lx pos.
|
||||
CLexFile *tempf=lx->cur_lfn;
|
||||
h->src_link=MPrint("FL:%s,%d",tempf->name,tempf->line_num);
|
||||
I64 line_num=tempf->line_num+line_num_offset;
|
||||
if (line_num<1) line_num=1;
|
||||
Free(h->src_link);
|
||||
h->src_link=MStrPrint("FL:%s,%d",tempf->name,line_num);
|
||||
if (Bt(&lx->opts,OPTf_KEEP_PRIVATE))
|
||||
h->type|=HTF_PRIVATE;
|
||||
if (lx->cur_index)
|
||||
h->index=StrNew(lx->cur_index);
|
||||
Free(h->index);
|
||||
if (lx->cur_help_index)
|
||||
h->index=StrNew(lx->cur_help_index);
|
||||
else
|
||||
h->index=NULL;
|
||||
}
|
||||
|
||||
CHashGeneric *HashPublic(U8 *st,I64 mask,Bool val=TRUE)
|
||||
{
|
||||
{//Mark a hash entry as public and $LK,"SetSrcFileInfo",A="MN:SetSrcFileInfo"$().
|
||||
CHashGeneric *result;
|
||||
if (result=HashFind(st,Fs->hash_table,mask)) {
|
||||
if (val)
|
||||
@@ -193,7 +197,7 @@ I64 HashLstAdd(U8 *lst,I64 type,CHashTable *table)
|
||||
}
|
||||
|
||||
I64 HashDefineLstAdd(U8 *name,I64 type,CHashTable *table)
|
||||
{//Add a define list to a hash table.
|
||||
{//Add define list to a hash table. See $LK,"::/Adam/DolDoc/DocInit.CPP",A="FF:::/Adam/DolDoc/DocInit.CPP,HashDefineLstAdd"$.
|
||||
CHashDefineStr *temph;
|
||||
if (temph=HashFind(name,Fs->hash_table,HTT_DEFINE_STR))
|
||||
return HashLstAdd(temph->data,type,table);
|
||||
@@ -202,7 +206,7 @@ I64 HashDefineLstAdd(U8 *name,I64 type,CHashTable *table)
|
||||
}
|
||||
|
||||
I64 FramePtr(U8 *name,CTask *task=NULL)
|
||||
{
|
||||
{//Find entry in task->hash_table, Return user_data.
|
||||
CHashGeneric *temph;
|
||||
if (!task) task=Fs;
|
||||
if (temph=HashFind(name,task->hash_table,HTT_FRAME_PTR))
|
||||
@@ -212,22 +216,22 @@ I64 FramePtr(U8 *name,CTask *task=NULL)
|
||||
}
|
||||
|
||||
CHashGeneric *FramePtrAdd(U8 *name,I64 val,CTask *task=NULL)
|
||||
{
|
||||
{//Add named value to task->hash_table.
|
||||
return HashGenericAdd(name,HTT_FRAME_PTR,val,0,0,task);
|
||||
}
|
||||
|
||||
I64 FramePtrSet(U8 *name,I64 val,CTask *task=NULL)
|
||||
{
|
||||
{//Find hash entry in task->hash_table. Change user_data0.
|
||||
CHashGeneric *temph;
|
||||
if (!task) task=Fs;
|
||||
if (temph=HashFind(name,task->hash_table,HTT_FRAME_PTR))
|
||||
return LXchgU64(&temph->user_data0,val);
|
||||
return LXchgI64(&temph->user_data0,val);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
I64 FramePtrDel(U8 *name,CTask *task=NULL)
|
||||
{
|
||||
{//Remove entry and delete.
|
||||
CHashGeneric *temph;
|
||||
I64 result=0;
|
||||
if (!task) task=Fs;
|
||||
@@ -312,19 +316,21 @@ U0 LoadPass1(U8 *src,U8 *module_base,I64 ld_flags)
|
||||
st_ptr=src;
|
||||
src+=StrLen(st_ptr)+1;
|
||||
switch (etype) {
|
||||
case EIT_REL_EXPORT:
|
||||
case EIT_IMM_EXPORT:
|
||||
case EIT_REL32_EXPORT:
|
||||
case EIT_IMM32_EXPORT:
|
||||
case EIT_REL64_EXPORT:
|
||||
case EIT_IMM64_EXPORT:
|
||||
tempex=CAlloc(sizeof(CHashExport));
|
||||
tempex->str=StrNew(st_ptr);
|
||||
tempex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
|
||||
if (etype==EIT_IMM_EXPORT)
|
||||
if (etype==EIT_IMM32_EXPORT||etype==EIT_IMM64_EXPORT)
|
||||
tempex->val=i;
|
||||
else
|
||||
tempex->val=i+module_base;
|
||||
HashAdd(tempex,Fs->hash_table);
|
||||
SysSymImportsResolve(st_ptr,ld_flags);
|
||||
break;
|
||||
case EIT_REL_I8...EIT_IMM_U64:
|
||||
case EIT_REL_I0...EIT_IMM_U64:
|
||||
src=st_ptr-5;
|
||||
LoadOneImport(&src,module_base,ld_flags);
|
||||
break;
|
||||
@@ -339,9 +345,15 @@ U0 LoadPass1(U8 *src,U8 *module_base,I64 ld_flags)
|
||||
}
|
||||
}
|
||||
break;
|
||||
case EIT_HEAP_GLBL:
|
||||
ptr3=MAlloc(*src(I64 *)++);
|
||||
|
||||
sub_switch_start:
|
||||
case EIT_CODE_HEAP:
|
||||
ptr3=MAlloc(*src(I32 *)++,Fs->code_heap);
|
||||
break;
|
||||
case EIT_ZEROED_CODE_HEAP:
|
||||
ptr3=CAlloc(*src(I32 *)++,Fs->code_heap);
|
||||
break;
|
||||
sub_switch_end:
|
||||
if (*st_ptr) {
|
||||
tempex=CAlloc(sizeof(CHashExport));
|
||||
tempex->str=StrNew(st_ptr);
|
||||
@@ -349,7 +361,28 @@ U0 LoadPass1(U8 *src,U8 *module_base,I64 ld_flags)
|
||||
tempex->val=ptr3;
|
||||
HashAdd(tempex,Fs->hash_table);
|
||||
}
|
||||
cnt=i;
|
||||
for (j=0;j<cnt;j++) {
|
||||
ptr2=module_base+*src(U32 *)++;
|
||||
*ptr2(I32 *)+=ptr3;
|
||||
}
|
||||
break;
|
||||
|
||||
sub_switch_start:
|
||||
case EIT_DATA_HEAP:
|
||||
ptr3=MAlloc(*src(I64 *)++);
|
||||
break;
|
||||
case EIT_ZEROED_DATA_HEAP:
|
||||
ptr3=CAlloc(*src(I64 *)++);
|
||||
break;
|
||||
sub_switch_end:
|
||||
if (*st_ptr) {
|
||||
tempex=CAlloc(sizeof(CHashExport));
|
||||
tempex->str=StrNew(st_ptr);
|
||||
tempex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
|
||||
tempex->val=ptr3;
|
||||
HashAdd(tempex,Fs->hash_table);
|
||||
}
|
||||
cnt=i;
|
||||
for (j=0;j<cnt;j++) {
|
||||
ptr2=module_base+*src(U32 *)++;
|
||||
@@ -360,7 +393,6 @@ U0 LoadPass1(U8 *src,U8 *module_base,I64 ld_flags)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U0 LoadPass2(U8 *src,U8 *module_base,I64)
|
||||
{
|
||||
U8 *st_ptr;
|
||||
@@ -376,7 +408,12 @@ U0 LoadPass2(U8 *src,U8 *module_base,I64)
|
||||
case EIT_ABS_ADDR:
|
||||
src+=sizeof(U32)*i;
|
||||
break;
|
||||
case EIT_HEAP_GLBL:
|
||||
case EIT_CODE_HEAP:
|
||||
case EIT_ZEROED_CODE_HEAP:
|
||||
src+=4+sizeof(U32)*i;
|
||||
break;
|
||||
case EIT_DATA_HEAP:
|
||||
case EIT_ZEROED_DATA_HEAP:
|
||||
src+=8+sizeof(U32)*i;
|
||||
break;
|
||||
}
|
||||
@@ -384,45 +421,38 @@ U0 LoadPass2(U8 *src,U8 *module_base,I64)
|
||||
}
|
||||
|
||||
U8 *Load(U8 *filename,I64 ld_flags=0,CBinFile *bfh_addr=INVALID_PTR)
|
||||
{ //See $LK,"BinRep",A="MN:BinRep"$().
|
||||
//bfh_addr==INVALID_PTR means don't care what load addr.
|
||||
{//Load a .BIN file module into memory.
|
||||
//bfh_addr==INVALID_PTR means don't care what load addr.
|
||||
U8 *fbuf,*module_base,*absname;
|
||||
I64 size,module_alignment,module_org;
|
||||
I64 size,module_align;
|
||||
CBinFile *bfh;
|
||||
CBinFilePatchTableWithOrg *bfpt;
|
||||
|
||||
fbuf=DftExt(filename,"BIN.Z");
|
||||
if (!(bfh=FileRead(fbuf,&size))) {
|
||||
Free(fbuf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//See $LK,"Loader Patch Table Generation",A="FF:::/Compiler/CmpMain.CPP,EIT_MODULE_ALIGNMENT"$
|
||||
bfpt=bfh(U8 *)+bfh->loader_patch_table_offset;
|
||||
module_alignment=bfpt->module_alignment;
|
||||
if (bfpt->eit_module_org==EIT_MODULE_ORG)
|
||||
module_org=bfpt->module_org;
|
||||
else
|
||||
module_org=INVALID_PTR;
|
||||
|
||||
if (!module_alignment || Bsf(module_alignment)!=Bsr(module_alignment))
|
||||
//See $LK,"Patch Table Generation",A="FF:::/Compiler/CmpMain.CPP,EIT_ABS_ADDR"$
|
||||
module_align=1<<bfh->module_align_bits;
|
||||
if (!module_align || bfh->bin_signature!=BIN_SIGNATURE_VAL) {
|
||||
Free(bfh);
|
||||
Free(fbuf);
|
||||
throw('BinModul');
|
||||
|
||||
#assert sizeof(CBinFile)==16
|
||||
|
||||
}
|
||||
if (bfh_addr==INVALID_PTR) {
|
||||
if (module_org==INVALID_PTR) {
|
||||
if (bfh->module_org==INVALID_PTR) {
|
||||
if (Fs->code_heap!=Fs->data_heap) {
|
||||
if (module_alignment<16)
|
||||
module_alignment=16;
|
||||
bfh_addr=MAllocAligned(size,module_alignment,Fs->code_heap,module_alignment-sizeof(CBinFile));
|
||||
} else if (module_alignment>8)
|
||||
bfh_addr=MAllocAligned(size,module_alignment,NULL,module_alignment-sizeof(CBinFile));
|
||||
else { //Less than 2Gig system memory
|
||||
if (module_align<16)
|
||||
module_align=16;
|
||||
bfh_addr=MAllocAligned(size,module_align,Fs->code_heap,module_align-sizeof(CBinFile));
|
||||
} else if (module_align>8)
|
||||
bfh_addr=MAllocAligned(size,module_align,,module_align-sizeof(CBinFile));
|
||||
else {//Less than 2Gig system memory
|
||||
bfh_addr=bfh;
|
||||
goto lo_skip; //File is already in code heap area, don't copy.
|
||||
}
|
||||
} else
|
||||
bfh_addr=module_org;
|
||||
bfh_addr=bfh->module_org;
|
||||
}
|
||||
MemCpy(bfh_addr,bfh,size);
|
||||
Free(bfh);
|
||||
@@ -436,12 +466,13 @@ lo_skip:
|
||||
FileExtRem(fbuf);
|
||||
if (fbuf[1]==':' && StrLen(fbuf)>2)
|
||||
HashGenericAdd(fbuf+2,HTT_MODULE|HTF_PUBLIC,bfh_addr);
|
||||
Free(fbuf);
|
||||
|
||||
LoadPass1(bfh_addr(U8 *)+bfh_addr->loader_patch_table_offset,module_base,ld_flags);
|
||||
LoadPass1(bfh_addr(U8 *)+bfh_addr->patch_table_offset,module_base,ld_flags);
|
||||
if (!(ld_flags&LDF_JUST_LOAD))
|
||||
LoadPass2(bfh_addr(U8 *)+bfh_addr->loader_patch_table_offset,module_base,ld_flags);
|
||||
LoadPass2(bfh_addr(U8 *)+bfh_addr->patch_table_offset,module_base,ld_flags);
|
||||
|
||||
Free(absname);
|
||||
Free(fbuf);
|
||||
return bfh_addr;
|
||||
}
|
||||
|
||||
@@ -449,7 +480,7 @@ U0 LoadKernel()
|
||||
{
|
||||
HashGenericAdd(KERNEL_MODULE_NAME,HTT_MODULE|HTF_PUBLIC,sys_boot_base-sizeof(CBinFile));
|
||||
|
||||
//Abs patches done here $LK,"CBinFilePatchTableWithoutOrg",A="FF:D:/Kernel/KStart.CPP,CBinFilePatchTableWithoutOrg"$.
|
||||
//Abs patches done here $LK,"CPatchTableAbsAddr",A="FF:D:/Kernel/KStart.CPP,CPatchTableAbsAddr"$.
|
||||
LoadPass1(sys_boot_patch_table_base,sys_boot_base,LDF_NO_ABSS|LDF_SILENT);
|
||||
|
||||
//No main routines
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
asm {
|
||||
USE64
|
||||
SYS_MP_CRASH_HANDLER_ADDR:: //forward reference to work around compiler
|
||||
SYS_MP_CRASH_HANDLER_ADDR:: //Forward reference to work around compiler
|
||||
DU32 &MPCrash;
|
||||
|
||||
SYS_WAKE_HANDLER::
|
||||
@@ -10,21 +10,19 @@ SYS_WAKE_HANDLER::
|
||||
POP RAX
|
||||
IRET
|
||||
|
||||
//I_TIMER
|
||||
SYS_TIMER_HANDLER::
|
||||
CALL TASK_CONTEXT_SAVE //PREEMPTIVE
|
||||
SYS_TIMER_HANDLER:: //I_TIMER
|
||||
CALL TASK_CONTEXT_SAVE //PREEMPTIVE
|
||||
CLD
|
||||
MOV RBP,RSP
|
||||
MOV RBX,U64 [RBP]
|
||||
MOV U64 CTask.rip[RSI],RBX
|
||||
MOV RAX,U64 16[RBP]
|
||||
|
||||
MOV RAX,U64 [RSP]
|
||||
MOV U64 CTask.rip[RSI],RAX
|
||||
MOV RAX,U64 16[RSP]
|
||||
MOV U64 CTask.rflags[RSI],RAX
|
||||
MOV RAX,U64 24[RBP]
|
||||
MOV RAX,U64 24[RSP]
|
||||
MOV U64 CTask.rsp[RSI],RAX
|
||||
|
||||
XOR RAX,RAX
|
||||
MOV RDI,U64 GS:CCPU.addr[RAX]
|
||||
|
||||
LOCK
|
||||
INC U64 CCPU.total_jiffies[RDI]
|
||||
|
||||
@@ -33,11 +31,11 @@ SYS_TIMER_HANDLER::
|
||||
LOCK
|
||||
INC U64 CCPU.idle_pt_hits[RDI]
|
||||
|
||||
@@05: MOV RAX,U64 CCPU.timer_irq_chain[RDI]
|
||||
@@05: MOV RAX,U64 CCPU.profiler_timer_irq[RDI]
|
||||
TEST RAX,RAX
|
||||
JZ @@10
|
||||
PUSH RSI
|
||||
CALL RAX
|
||||
CALL RAX //See $LK,"ProfTimerInt",A="MN:ProfTimerInt"$().
|
||||
JMP @@15
|
||||
@@10: ADD RSP,8
|
||||
@@15: CLI
|
||||
@@ -49,25 +47,23 @@ SYS_TIMER_HANDLER::
|
||||
MOV U32 [RAX],0
|
||||
JMP @@25
|
||||
|
||||
@@20: MOV AL,0x20 //ACKNOWLEDGE INTERRUPT
|
||||
OUT 0x20,AL
|
||||
@@20: CALL &IntCore0TimerHandler //Only Core 0 calls this.
|
||||
|
||||
@@25: TEST U8 [SYS_SEMAS+SYS_SEMA_SINGLE_USER*SEMA_STRUCT_SIZE],1
|
||||
JNZ @@30
|
||||
BT U64 CTask.task_flags[RSI],TASKf_PREEMPT
|
||||
JC I32 RESTORE_NEXT_RSI_TASK
|
||||
@@30: JMP I32 RESTORE_RSI_NO_PREEMPT_TASK
|
||||
|
||||
// ************************************
|
||||
//************************************
|
||||
SYS_IRQ_FAULT::
|
||||
PUSH RBX
|
||||
MOV RBX,U64 8[RSP]
|
||||
PUSH RAX
|
||||
MOV BL,U8 16[RSP] //We pushed fault_num $LK,"IntFaultHandlersNew",A="MN:IntFaultHandlersNew"$().
|
||||
XOR RAX,RAX
|
||||
MOV FS:U32 CTask.fault_num[RAX],EBX
|
||||
MOV FS:U8 CTask.fault_num[RAX],BL
|
||||
POP RAX
|
||||
POP RBX
|
||||
ADD RSP,8
|
||||
ADD RSP,8 //Pop fault_num
|
||||
|
||||
CALL TASK_CONTEXT_SAVE
|
||||
|
||||
@@ -78,19 +74,17 @@ SYS_IRQ_FAULT::
|
||||
JNC @@1
|
||||
POP U64 CTask.fault_err_code[RSI]
|
||||
|
||||
@@1: MOV RBP,RSP
|
||||
MOV RAX,U64 [RBP]
|
||||
@@1: MOV RAX,U64 [RSP]
|
||||
MOV U64 CTask.rip[RSI],RAX
|
||||
MOV RAX,U64 16[RBP]
|
||||
MOV RAX,U64 16[RSP]
|
||||
MOV U64 CTask.rflags[RSI],RAX
|
||||
MOV RAX,U64 24[RBP]
|
||||
MOV U64 CTask.rsp[RSI],RAX
|
||||
MOV RSP,RAX
|
||||
MOV RSP,U64 24[RSP]
|
||||
MOV U64 CTask.rsp[RSI],RSP
|
||||
MOV RBP,CTask.rbp[RSI]
|
||||
PUSH U64 CTask.fault_err_code[RSI]
|
||||
PUSH U64 CTask.fault_num[RSI]
|
||||
MOV RSI,CTask.rsi[RSI]
|
||||
CALL &Fault2 //See $LK,"Fault2",A="FF:::/Kernel/Dbg1a.CPP,Fault2"$
|
||||
CALL &Fault2 //See $LK,"Fault2",A="FF:::/Kernel/Dbg1a.CPP,Fault2"$
|
||||
JMP I32 RESTORE_FS_TASK_WITH_KEY_CHECK
|
||||
|
||||
SYS_FAULT_ERR_CODE_BITMAP::
|
||||
@@ -98,10 +92,10 @@ SYS_FAULT_ERR_CODE_BITMAP::
|
||||
}
|
||||
|
||||
U8 *IntEntryGet(I64 irq)
|
||||
{
|
||||
{//Get interrupt vector.
|
||||
U8 *result;
|
||||
I64 *src;
|
||||
src=sys_idt(U8 *)+irq*16;
|
||||
src=dev.idt(U8 *)+irq*16;
|
||||
result(I64).u16[0]=*src(U16 *);
|
||||
src(U8 *)+=6;
|
||||
result(I64).u16[1]=*src(U16 *)++;
|
||||
@@ -110,14 +104,13 @@ U8 *IntEntryGet(I64 irq)
|
||||
}
|
||||
|
||||
U8 *IntEntrySet(I64 irq,U0 (*fp_new_handler)(),I64 type=IDTET_IRQ,I64 dpl=0)
|
||||
{
|
||||
//See $LK,"IDTET_IRQ",A="MN:IDTET_IRQ"$
|
||||
//See $LK,"::/Demo/Lectures/InterruptDemo.CPP"$
|
||||
//See $LK,"::/Demo/MultiCore/Interrupts.CPP"$
|
||||
{//Set interrupt vector. See $LK,"IDTET_IRQ",A="MN:IDTET_IRQ"$.
|
||||
//See $LK,"::/Demo/Lectures/InterruptDemo.CPP"$.
|
||||
//See $LK,"::/Demo/MultiCore/Interrupts.CPP"$.
|
||||
I64 fp=fp_new_handler;
|
||||
U8 *result,*dst;
|
||||
result=IntEntryGet(irq);
|
||||
dst=sys_idt(U8 *)+irq*16;
|
||||
dst=dev.idt(U8 *)+irq*16;
|
||||
PUSHFD
|
||||
CLI
|
||||
*dst(U16 *)++=fp.u16[0];
|
||||
@@ -131,8 +124,7 @@ U8 *IntEntrySet(I64 irq,U0 (*fp_new_handler)(),I64 type=IDTET_IRQ,I64 dpl=0)
|
||||
}
|
||||
|
||||
U0 IntsInit()
|
||||
{
|
||||
//Init 8259
|
||||
{//Init 8259
|
||||
OutU8(0x20,0x11); //IW1
|
||||
OutU8(0xA0,0x11); //IW1
|
||||
OutU8(0x21,0x20); //IW2
|
||||
@@ -141,12 +133,12 @@ U0 IntsInit()
|
||||
OutU8(0xA1,0x02); //IW3
|
||||
OutU8(0x21,0x0D); //IW4
|
||||
OutU8(0xA1,0x09); //IW4
|
||||
OutU8(0x21,0xFA); //Mask all but IRQ0 (timer) and IRQ2 Cascade
|
||||
OutU8(0x21,0xFA); //Mask all but IRQ0 (timer) and IRQ2 Cascade.
|
||||
OutU8(0xA1,0xFF);
|
||||
}
|
||||
|
||||
interrupt U0 IntNop()
|
||||
{ //Make unplanned IRQs stop by all means!
|
||||
{//Make unplanned IRQs stop by all means!
|
||||
OutU8(0xA0,0x20);
|
||||
OutU8(0x20,0x20);
|
||||
*LAPIC_EOI(U32 *)=0;
|
||||
@@ -155,10 +147,10 @@ interrupt U0 IntNop()
|
||||
U8 *IntFaultHandlersNew()
|
||||
{
|
||||
I64 i;
|
||||
U8 *result=MAlloc(256*10,Fs->code_heap),*dst=result;
|
||||
U8 *result=MAlloc(256*7,Fs->code_heap),*dst=result;
|
||||
for (i=0;i<256;i++) {
|
||||
*dst++=0x68; //PUSH I32 xxxxxxxx
|
||||
*dst(I32 *)++=i;
|
||||
*dst++=0x6A; //PUSH I8 xx
|
||||
*dst(I8 *)++=i;
|
||||
*dst++=0xE9; //JMP I32 xxxxxxxx
|
||||
*dst(I32 *)=SYS_IRQ_FAULT-dst-4;
|
||||
dst+=4;
|
||||
@@ -167,31 +159,30 @@ U8 *IntFaultHandlersNew()
|
||||
}
|
||||
|
||||
U0 IntInit1()
|
||||
{ //Interrupt descriptor table part1
|
||||
{//Interrupt descriptor table part1.
|
||||
I64 i,temp_ptr[2];
|
||||
U32 *ptr;
|
||||
if (!Gs->num) { //Gs cur $LK,"CCPU",A="MN:CCPU"$ struct
|
||||
sys_idt=CAlloc(16*256);
|
||||
if (!Gs->num) {//Gs cur $LK,"CCPU",A="MN:CCPU"$ struct
|
||||
dev.idt=CAlloc(16*256);
|
||||
for (i=0;i<256;i++)
|
||||
IntEntrySet(i,&IntNop);
|
||||
}
|
||||
ptr=temp_ptr;
|
||||
*ptr(U16 *)++=256*16-1; //Typecasting is postfix
|
||||
*ptr(I64 *)++=sys_idt;
|
||||
*ptr(I64 *)++=dev.idt;
|
||||
*ptr(U16 *)=0;
|
||||
SetRAX(temp_ptr);
|
||||
LIDT U64 [RAX]
|
||||
}
|
||||
|
||||
U0 IntInit2()
|
||||
{ //Interrupt descriptor table part2: Core 0 Only
|
||||
{//Interrupt descriptor table part2: Core 0 Only.
|
||||
I64 i;
|
||||
PUSHFD
|
||||
CLI
|
||||
for (i=0;i<0x20;i++)
|
||||
IntEntrySet(i,&sys_fault_handlers_code[10*i]);
|
||||
/*
|
||||
In theory, we use the PIC mask reg to insure we don't get
|
||||
IntEntrySet(i,&dbg.fault_handlers_code[7*i]);
|
||||
/*In theory, we use the PIC mask reg to insure we don't get
|
||||
anything but keyboard, mouse and timer IRQs. In practice, I've
|
||||
gotten IRQ 0x27, perhaps because I didn't initialize the APIC.
|
||||
I go ahead and ACK PIC in $LK,"IntNop",A="MN:IntNop"$().
|
||||
@@ -201,6 +192,6 @@ I have no idea why I got a IRQ 0x27.
|
||||
IntEntrySet(I_TIMER,SYS_TIMER_HANDLER);
|
||||
IntEntrySet(I_MP_CRASH,*SYS_MP_CRASH_HANDLER_ADDR(U32 *));
|
||||
IntEntrySet(I_WAKE,SYS_WAKE_HANDLER);
|
||||
IntEntrySet(I_DBG,&sys_fault_handlers_code[10*I_DBG]);
|
||||
IntEntrySet(I_DBG,&dbg.fault_handlers_code[7*I_DBG]);
|
||||
POPFD
|
||||
}
|
||||
+38
-47
@@ -1,29 +1,26 @@
|
||||
//This is run in a #exe{}.
|
||||
//This is run in a $LK,"#exe",A="FF:::/Kernel/Kernel.PRJ,KCfg"${}.
|
||||
|
||||
U8 *kernel_cfg_options="MemInit\0HeapInit\0VarInit\0"
|
||||
"NoMP\0TextMode\0GrMode\0DontProbe\0AutoMountIDE\0BootDrv\0Help\0";
|
||||
"NoMP\0TextMode\0DontProbe\0AutoMountIDE\0BootRescueDrv\0Help\0";
|
||||
|
||||
#define CFG_MEM_INIT 0
|
||||
#define CFG_HEAP_INIT 1
|
||||
#define CFG_VAR_INIT 2
|
||||
#define CFG_NO_MP 3
|
||||
#define CFG_TEXT_MODE 4
|
||||
#define CFG_GR_MODE 5
|
||||
#define CFG_DONT_PROBE 6
|
||||
#define CFG_AUTO_MOUNT_IDE 7
|
||||
#define CFG_BOOT_DRV 8
|
||||
#define CFG_NUM_OPTIONS 9
|
||||
|
||||
#define CFG_HELP 9
|
||||
#define CFG_DONT_PROBE 5
|
||||
#define CFG_AUTO_MOUNT_IDE 6
|
||||
#define CFG_BOOT_RESCUE_DRV 7
|
||||
#define CFG_NUM_OPTIONS 8
|
||||
|
||||
#define CFG_HELP 8
|
||||
|
||||
class CKernelCfg
|
||||
{
|
||||
I64 bios_gr_mode;
|
||||
U8 *acct_name;
|
||||
U8 *dsk_cache_size_exp;
|
||||
CDoc *add_dev;
|
||||
U8 *boot_drv_file,*boot_drv_start;
|
||||
U8 *boot_rescue_drv_file,*boot_rescue_drv_start;
|
||||
Bool opts[CFG_NUM_OPTIONS];
|
||||
U8 mem_init_val,heap_init_val,var_init_val,
|
||||
sys_acct_drv,auto_mount_ide_hd_let,auto_mount_ide_cd_let;
|
||||
@@ -59,12 +56,12 @@ CDoc *KernelCfgAddDev(CKernelCfg *c)
|
||||
"they will be lettered in sequence.\n"
|
||||
"\nFirst Drive Letter ($$PURPLE$$<ENTER>$$FG$$ to exit):";
|
||||
first_prt_num=ToUpper(GetChar)-'A';
|
||||
NewLine;
|
||||
'\n';
|
||||
if (0<=first_prt_num<NUM_PRTS) {
|
||||
"\t$$PURPLE$$1$$FG$$=RAM\n\t$$PURPLE$$2$$FG$$=ATA(Harddisk)\n"
|
||||
"\t$$PURPLE$$3$$FG$$=ATAPI(CD-ROM)\nType:";
|
||||
type=GetChar-'0';
|
||||
NewLine;
|
||||
'\n';
|
||||
|
||||
unit=0;
|
||||
if (type==BDT_RAM) {
|
||||
@@ -91,11 +88,11 @@ CDoc *KernelCfgAddDev(CKernelCfg *c)
|
||||
else
|
||||
"Include $$PURPLE$$0x$$FG$$ prefix.\nI/O Port Base0:\n";
|
||||
GetS(base0_buf,128);
|
||||
} while (!A2I64(base0_buf));
|
||||
if (1<=A2I64(base0_buf)<=num_hints) {
|
||||
tempha=ATARepFind(root,A2I64(base0_buf));
|
||||
SPrint(base0_buf,"0x%X",tempha->base0);
|
||||
SPrint(base1_buf,"0x%X",tempha->base1);
|
||||
} while (!Str2I64(base0_buf));
|
||||
if (1<=Str2I64(base0_buf)<=num_hints) {
|
||||
tempha=ATARepFind(root,Str2I64(base0_buf));
|
||||
StrPrint(base0_buf,"0x%X",tempha->base0);
|
||||
StrPrint(base1_buf,"0x%X",tempha->base1);
|
||||
unit=tempha->unit;
|
||||
} else if (type!=BDT_ATAPI || *base0_buf) {
|
||||
if (type==BDT_ATAPI)
|
||||
@@ -104,12 +101,12 @@ CDoc *KernelCfgAddDev(CKernelCfg *c)
|
||||
do {
|
||||
"I/O Port Base1:\n";
|
||||
GetS(base1_buf,128);
|
||||
} while (!A2I64(base1_buf));
|
||||
} while (!Str2I64(base1_buf));
|
||||
do {
|
||||
"\t$$PURPLE$$0$$FG$$=Master\n\t$$PURPLE$$1$$FG$$=Slave\nUnit:";
|
||||
unit=GetChar-'0';
|
||||
} while (!(0<=unit<=1));
|
||||
NewLine;
|
||||
'\n';
|
||||
}
|
||||
LinkedLstDel(root);
|
||||
}
|
||||
@@ -125,7 +122,7 @@ CDoc *KernelCfgAddDev(CKernelCfg *c)
|
||||
if (type==BDT_ATA || type==BDT_ATAPI) {
|
||||
if (type==BDT_ATAPI && !*base0_buf) {
|
||||
c->cdrom_ports_pmt=TRUE;
|
||||
DocPrint(doc,"boot_drv_pmt=PmtBaseUnit(bdev);");
|
||||
DocPrint(doc,"dsk.boot_rescue_drv_pmt=GetBaseUnit(bdev);");
|
||||
if (first_prt_num+'A'==c->sys_acct_drv)
|
||||
make_free=TRUE;
|
||||
} else
|
||||
@@ -151,7 +148,7 @@ U0 KernelCfgOptions(CKernelCfg *c)
|
||||
for (i=0;i<CFG_NUM_OPTIONS;i++)
|
||||
"$$PURPLE$$%13tz$$FG$$:%Z\n",i,kernel_cfg_options,c->opts[i],"ST_OFF_ON";
|
||||
"\nType '$$PURPLE$$Help$$FG$$' for help.\n";
|
||||
st=PmtStr("Option ($$PURPLE$$<ENTER>$$FG$$ when done):","");
|
||||
st=GetStr("Option ($$PURPLE$$<ENTER>$$FG$$ when done):","");
|
||||
i=LstMatch(st,kernel_cfg_options,LMF_IGNORE_CASE);
|
||||
if (i==CFG_HELP)
|
||||
"\n"
|
||||
@@ -160,10 +157,9 @@ U0 KernelCfgOptions(CKernelCfg *c)
|
||||
"$$PURPLE$$VarInit$$FG$$ Initializes glbl var memory to a val.\n"
|
||||
"$$PURPLE$$NoMP$$FG$$ No multicore.\n"
|
||||
"$$PURPLE$$TextMode$$FG$$ Text Mode (requires hard reboot).\n"
|
||||
"$$PURPLE$$GrMode$$FG$$ Graphics Mode (requires hard reboot).\n"
|
||||
"$$PURPLE$$DontProbe$$FG$$ Just prompt CD-ROM ports, don't probe.\n"
|
||||
"$$PURPLE$$AutoMountIDE$$FG$$ AutoMount IDE drives to 'C' and 'T'.\n"
|
||||
"$$PURPLE$$BootDrv$$FG$$ Include RAM Drv in Kernel.BIN.\n"
|
||||
"$$PURPLE$$BootRescueDrv$$FG$$ Include RAM Drv in Kernel.BIN.\n"
|
||||
"\n";
|
||||
else
|
||||
if (0<=i<CFG_NUM_OPTIONS) {
|
||||
@@ -171,22 +167,15 @@ U0 KernelCfgOptions(CKernelCfg *c)
|
||||
switch (i) {
|
||||
case CFG_MEM_INIT:
|
||||
if (state)
|
||||
c->mem_init_val=PmtI64("Val (0-255):",255,0,255);
|
||||
c->mem_init_val=GetI64("Val (0-255):",255,0,255);
|
||||
break;
|
||||
case CFG_HEAP_INIT:
|
||||
if (state)
|
||||
c->heap_init_val=PmtI64("Val (0-255):",255,0,255);
|
||||
c->heap_init_val=GetI64("Val (0-255):",255,0,255);
|
||||
break;
|
||||
case CFG_VAR_INIT:
|
||||
if (state)
|
||||
c->var_init_val=PmtI64("Val (0-255):",255,0,255);
|
||||
break;
|
||||
case CFG_GR_MODE:
|
||||
if (state)
|
||||
c->bios_gr_mode=PmtI64(
|
||||
"0x12 640x480x4\n"
|
||||
"0x6A 800x600x4\n\n"
|
||||
"BIOS Graphic Mode (0x%0X):",c->bios_gr_mode);
|
||||
c->var_init_val=GetI64("Val (0-255):",255,0,255);
|
||||
break;
|
||||
case CFG_AUTO_MOUNT_IDE:
|
||||
if (state) {
|
||||
@@ -194,7 +183,7 @@ U0 KernelCfgOptions(CKernelCfg *c)
|
||||
c->auto_mount_ide_hd_let=ToUpper(GetChar);
|
||||
if (!('A'<=c->auto_mount_ide_hd_let<='Z'))
|
||||
c->auto_mount_ide_hd_let=0;
|
||||
NewLine;
|
||||
'\n';
|
||||
if (c->auto_mount_ide_hd_let)
|
||||
"First HD Drive:%C\n",c->auto_mount_ide_hd_let;
|
||||
else
|
||||
@@ -204,7 +193,7 @@ U0 KernelCfgOptions(CKernelCfg *c)
|
||||
c->auto_mount_ide_cd_let=ToUpper(GetChar);
|
||||
if (!('A'<=c->auto_mount_ide_cd_let<='Z'))
|
||||
c->auto_mount_ide_cd_let=0;
|
||||
NewLine;
|
||||
'\n';
|
||||
if (c->auto_mount_ide_cd_let)
|
||||
"First CD Drive:%C\n",c->auto_mount_ide_cd_let;
|
||||
else
|
||||
@@ -214,13 +203,13 @@ U0 KernelCfgOptions(CKernelCfg *c)
|
||||
c->auto_mount_ide_cd_let=0;
|
||||
}
|
||||
break;
|
||||
case CFG_BOOT_DRV:
|
||||
Free(c->boot_drv_file);
|
||||
c->boot_drv_file=0;
|
||||
c->boot_drv_start=0;
|
||||
case CFG_BOOT_RESCUE_DRV:
|
||||
Free(c->boot_rescue_drv_file);
|
||||
c->boot_rescue_drv_file=0;
|
||||
c->boot_rescue_drv_start=0;
|
||||
if (state) {
|
||||
c->boot_drv_file=PmtStr("Boot Drv File:");
|
||||
c->boot_drv_start=PmtI64("Boot Drv Start:");
|
||||
c->boot_rescue_drv_file=GetStr("Boot Rescue Drv File:");
|
||||
c->boot_rescue_drv_start=GetI64("Boot Rescue Drv Start:");
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -234,10 +223,12 @@ CKernelCfg *KernelCfgNew()
|
||||
CKernelCfg *c=CAlloc(sizeof(CKernelCfg));
|
||||
|
||||
c->add_dev=KernelCfgAddDev(c);
|
||||
c->acct_name=PmtStr("Start-up Acct ($$PURPLE$$<ENTER>$$FG$$ will prompt):");
|
||||
c->dsk_cache_size_exp=PmtStr("Disk Cache Size in Bytes, gets rounded-up funny, ($$PURPLE$$<ENTER>$$FG$$ will use default of $$PURPLE$$%s$$FG$$ Bytes):",
|
||||
"Scale2Mem(0x80000,0x8000000)");
|
||||
c->bios_gr_mode=0x12; //0x12=640x480x4 0x6A=800x600x4
|
||||
c->acct_name=GetStr("Start-up Acct ($$PURPLE$$<ENTER>$$FG$$ will prompt):");
|
||||
c->dsk_cache_size_exp=GetStr(
|
||||
"Disk Cache Size in Bytes,\n"
|
||||
"gets rounded-up funny,\n"
|
||||
"($$PURPLE$$<ENTER>$$FG$$ will use default.):",
|
||||
"Scale2Mem(0x80000,0x8000000)");
|
||||
KernelCfgOptions(c);
|
||||
return c;
|
||||
}
|
||||
@@ -245,7 +236,7 @@ CKernelCfg *KernelCfgNew()
|
||||
U0 KernelCfgDel(CKernelCfg *c)
|
||||
{
|
||||
DocDel(c->add_dev);
|
||||
Free(c->boot_drv_file);
|
||||
Free(c->boot_rescue_drv_file);
|
||||
Free(c->acct_name);
|
||||
Free(c->dsk_cache_size_exp);
|
||||
Free(c);
|
||||
|
||||
+58
-81
@@ -6,40 +6,34 @@ U0 SysGlblsInit()
|
||||
|
||||
CPUId(0x1,&ee);
|
||||
sys_cache_line_width=ee.rbx.u8[1]*8;
|
||||
QueInit(&sys_pci_dev_root);
|
||||
sys_rnd_seed = 93186752^GetTSC;
|
||||
|
||||
sys_rnd_seed =93186752^GetTSC;
|
||||
sys_focus_task=Fs;
|
||||
QueInit(&sys_macro_root);
|
||||
sys_dft_iso_name="::/Temp/CDDVD.ISO";
|
||||
MemSet(mp_apic_ids,0,MP_MAX_PROCESSORS*sizeof(U8));
|
||||
|
||||
dsk.dft_iso_filename="::/Temp/CDDVD.ISO";
|
||||
StrCpy(dsk.temp_filename,"HOME/Temp.TXT.Z");
|
||||
dsk.cdrom_boot_is_good=TRUE;
|
||||
#exe {
|
||||
if (!kernel_cfg->auto_mount_ide_hd_let) kernel_cfg->auto_mount_ide_hd_let='C';
|
||||
if (!kernel_cfg->auto_mount_ide_cd_let) kernel_cfg->auto_mount_ide_cd_let='T';
|
||||
StreamPrint("dsk.first_hd_drv_let=%d;",kernel_cfg->auto_mount_ide_hd_let);
|
||||
StreamPrint("dsk.first_cd_drv_let=%d;",kernel_cfg->auto_mount_ide_cd_let);
|
||||
}
|
||||
|
||||
InDbg(ON);
|
||||
reverse_bits_table=CAlloc(256);
|
||||
reverse_bits_table =CAlloc(256);
|
||||
set_bits_table =CAlloc(256);
|
||||
for (i=0;i<256;i++)
|
||||
for (j=0;j<8;j++)
|
||||
if (Bt(&i,7-j))
|
||||
LBts(reverse_bits_table+i,j);
|
||||
set_bits_table=CAlloc(256);
|
||||
for (i=0;i<256;i++)
|
||||
for (j=0;j<8;j++)
|
||||
if (Bt(&i,j))
|
||||
set_bits_table[i]++;
|
||||
for (j=0;j<8;j++) {
|
||||
if (Bt(&i,7-j)) LBts(reverse_bits_table+i,j);
|
||||
if (Bt(&i,j)) set_bits_table[i]++;
|
||||
}
|
||||
|
||||
ext=CAlloc(EXT_NUM_ENTRIES*sizeof(U8 *));
|
||||
fp_mgets=&SysMGetS;
|
||||
fp_getstr2=&SysGetStr2;
|
||||
KeyDevInit;
|
||||
|
||||
fp_ctrl_alt_let_cbs=CAlloc(26*sizeof(U8 *));
|
||||
ctrl_alt_let_descs=CAlloc(26*sizeof(U8 *));
|
||||
ctrl_alt_let_in_irq_flags=0;
|
||||
|
||||
psect_cache=CAlloc(PSECT_CACHE_SIZE*sizeof(CPSectCache));
|
||||
psect_cache_index=0;
|
||||
|
||||
StrCpy(sys_temp_filename,"HOME/Temp.TXT.Z");
|
||||
MemSet(&sys_put_key_root,0,sizeof(CKeyDev));
|
||||
QueInit(&sys_put_key_root);
|
||||
KeyDevAdd(&KDInputFilterPutKey,&KDInputFilterPutS,0x40000000,FALSE);
|
||||
KeyDevAdd(&KDRawDisplayPutKey,&KDRawDisplayPutS,0x60000000,FALSE);
|
||||
#exe {
|
||||
if (*kernel_cfg->acct_name)
|
||||
StreamPrint("sys_acct=StrNew(\"%C:/Accts/%s\");",kernel_cfg->sys_acct_drv,kernel_cfg->acct_name);
|
||||
@@ -49,60 +43,44 @@ U0 SysGlblsInit()
|
||||
StreamPrint("DskCacheInit(%s);",kernel_cfg->dsk_cache_size_exp);
|
||||
StreamPrint("#exe{OptOn(OPTf_WARN_PAREN);}");
|
||||
};
|
||||
|
||||
pow10_I64=CAlloc(sizeof(F64)*(308+308+1));
|
||||
for (i=-308;i<309;i++)
|
||||
pow10_I64[i+309]=Pow10(i);
|
||||
|
||||
QueInit(&snd_record_root);
|
||||
snd_record_root.freq=0;
|
||||
QueInit(&snd.record_root);
|
||||
snd.record_root.time=tS;
|
||||
|
||||
snd_record_root.time_stamp=tS;
|
||||
ProgressBarsRst;
|
||||
|
||||
//$AN,"Independent Heap Ctrl Example",A="Independent Heap Ctrl Example"$
|
||||
i=1; //Rqst 1 blk, we might get more.
|
||||
m=MemBlksUncachedAlloc(&i,sys_code_bp);
|
||||
sys_uncached_heap=HeapCtrlBPInit(m,i*0x200000/0x200);
|
||||
ProgressBarsRst;
|
||||
sys_fault_handlers_code=IntFaultHandlersNew;
|
||||
dev.uncached_heap=HeapCtrlBPInit(m,i*0x200000/0x200);
|
||||
QueInit(&dev.pci_root);
|
||||
dev.mem64_ptr=MEM_MAPPED_SPACE;
|
||||
|
||||
dbg.psect_cache=CAlloc(PSECT_CACHE_SIZE*sizeof(CPSectCache));
|
||||
dbg.fault_handlers_code=IntFaultHandlersNew;
|
||||
}
|
||||
|
||||
U0 SysGrInit()
|
||||
{
|
||||
//See $LK,"SYS_BIOS_GR_MODE",A="FF:D:/Kernel/KStart.CPP,SYS_BIOS_GR_MODE:2"$
|
||||
//See $LK,"GR_WIDTH",A="FF:::/Adam/Gr/GrGlbls.CPP.Z,GR_WIDTH"$
|
||||
gr_font=sys_font_8x8;
|
||||
if (bios_gr_mode==0x12 || bios_gr_mode==0x6A) {
|
||||
text_mode=FALSE;
|
||||
|
||||
/*
|
||||
Mode must be multiple of 32 wide
|
||||
$LK,"GrUpdateLine32",A="MN:GrUpdateLine32"$().
|
||||
*/
|
||||
|
||||
if (bios_gr_mode==0x6A) {
|
||||
gr_width =800;
|
||||
gr_height=600;
|
||||
} else {
|
||||
gr_width =640;
|
||||
gr_height=480;
|
||||
}
|
||||
text_cols=gr_width/FONT_WIDTH;
|
||||
text_rows=gr_height/FONT_HEIGHT;
|
||||
{//See $LK,"SYS_BIOS_GR_MODE",A="FF:D:/Kernel/KStart.CPP,SYS_BIOS_GR_MODE:2"$
|
||||
text.font=sys_font_8x8;
|
||||
if (sys_bios_gr_mode==0x12) { //if 640x480 16 color
|
||||
text.cols=GR_WIDTH/FONT_WIDTH;
|
||||
text.rows=GR_HEIGHT/FONT_HEIGHT;
|
||||
OutU8(VGA_SC_INDEX,VGA_MAP_MASK);
|
||||
OutU8(VGA_SC_DATA,0x0F);
|
||||
MemSet(VGA_GRAPHIC_MEM_BASE,0,gr_width*gr_height>>3);
|
||||
sys_raw_screen_image=CAlloc(gr_width*gr_height/8);
|
||||
MemSet(VGA_GRAPHIC_MEM_BASE,0,GR_WIDTH*GR_HEIGHT>>3);
|
||||
text.raw_screen_image=CAlloc(GR_WIDTH*GR_HEIGHT/8);
|
||||
} else {
|
||||
text_mode=TRUE;
|
||||
gr_width =640;
|
||||
gr_height=480;
|
||||
text_cols=80;
|
||||
text_rows=25;
|
||||
MemSet(VGA_TEXT_MEM_BASE,0,text_rows*text_cols<<1);
|
||||
text.cols=80;
|
||||
text.rows=25;
|
||||
MemSet(VGA_TEXT_MEM_BASE,0,text.rows*text.cols<<1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U0 TimersInit()
|
||||
{
|
||||
I64 i,*_q;
|
||||
@@ -113,8 +91,7 @@ U0 TimersInit()
|
||||
OutU8(0x40,SYS_TIMER0_PERIOD>>8);
|
||||
|
||||
// High Precision Event Timer
|
||||
|
||||
if (PCIReadU16(0,31,0,0)==0x8086) { //Intel?
|
||||
if (PCIReadU16(0,31,0,0)==0x8086) {//Intel?
|
||||
//D31 F0, cfg 0xF0=RCBA of PCI-LPC Bridge
|
||||
_d=PCIReadU32(0,31,0,0xF0)(U8 *)&~0x3FFF+0x3404; //HPET cfg
|
||||
//7 enable
|
||||
@@ -125,20 +102,20 @@ U0 TimersInit()
|
||||
_q=HPET_GCAP_ID;
|
||||
i=*_q; //i.u32[1]= period in femtoS (10e-15)
|
||||
if (100000<i.u32[1]<1000000000) {
|
||||
HPET_freq =1000000000000000/i.u32[1];
|
||||
HPET_kHz_freq=1000000000000/i.u32[1];
|
||||
cnts.HPET_freq =1000000000000000/i.u32[1];
|
||||
cnts.HPET_kHz_freq=1000000000000/i.u32[1];
|
||||
_q=HPET_GEN_CONF;
|
||||
*_q|=1; //Enable counting
|
||||
HPET_initial=HPET;
|
||||
cnts.HPET_initial=HPET;
|
||||
} else {
|
||||
HPET_freq=0;
|
||||
HPET_kHz_freq=0;
|
||||
HPET_initial=0;
|
||||
cnts.HPET_freq=0;
|
||||
cnts.HPET_kHz_freq=0;
|
||||
cnts.HPET_initial=0;
|
||||
}
|
||||
}
|
||||
|
||||
U0 Reboot()
|
||||
{
|
||||
{//Hardware reset.
|
||||
U16 *_w=0x472;
|
||||
CLI
|
||||
if (mp_cnt>1)
|
||||
@@ -153,7 +130,7 @@ U0 Reboot()
|
||||
}
|
||||
|
||||
U0 KernelMain()
|
||||
{ //Continued from $LK,"Kernel",A="FF:::/Kernel/KStart.CPP,I32 &Kernel"$
|
||||
{//Continued from $LK,"Kernel",A="FF:::/Kernel/KStart.CPP,I32 &Kernel"$
|
||||
adam_task=Fs;
|
||||
HeapsInit;
|
||||
LBts(&sys_run_level,RLf_FULL_HEAP);
|
||||
@@ -166,7 +143,7 @@ U0 KernelMain()
|
||||
StrCpy(Fs->task_name,"Adam Task CPU#0");
|
||||
StrCpy(Fs->task_title,Fs->task_name);
|
||||
Fs->title_src=TTS_TASK_NAME;
|
||||
Fs->win_right=text_cols-2;
|
||||
Fs->win_right=text.cols-2;
|
||||
Fs->win_top++;
|
||||
TaskDerivedValsUpdate;
|
||||
|
||||
@@ -195,9 +172,9 @@ U0 KernelMain()
|
||||
#exe {
|
||||
if (!kernel_cfg->opts[CFG_NO_MP])
|
||||
StreamPrint("\"MultiCore Start\\n\\n\";"
|
||||
"MPStart;");
|
||||
"MPStart;"
|
||||
"LBts(&sys_run_level,RLf_MP);");
|
||||
};
|
||||
LBts(&sys_run_level,RLf_MP);
|
||||
|
||||
KbdMouseVarsInit;
|
||||
IPVarsInit;
|
||||
@@ -212,7 +189,7 @@ U0 KernelMain()
|
||||
"BlkDevsInitAll Done\n";
|
||||
#exe {
|
||||
if (kernel_cfg->cdrom_ports_pmt)
|
||||
StreamPrint("if (boot_drv_pmt) \"%%S\",\"ST_CDROM_PORTS_PMT2\";");
|
||||
StreamPrint("if (dsk.boot_rescue_drv_pmt) \"%%S\",\"ST_CDROM_PORTS_PMT2\";");
|
||||
};
|
||||
ChgDsk(':');
|
||||
LBts(&sys_run_level,RLf_DSK);
|
||||
@@ -223,7 +200,7 @@ U0 KernelMain()
|
||||
LBts(&sys_run_level,RLf_COMPILER);
|
||||
|
||||
InDbg(OFF);
|
||||
time_stamp_freq_initial=TimeStampFreqCal;
|
||||
cnts.time_stamp_freq_initial=TimeStampFreqCal;
|
||||
Cd("/Kernel");
|
||||
try
|
||||
ExeFile("Adam1"); //Continues $LK,"/Kernel/Adam1.CPP",A="FL:/Kernel/Adam1.CPP,1"$
|
||||
@@ -240,9 +217,9 @@ U0 KernelMain()
|
||||
asm { ALIGN 16,OC_NOP
|
||||
SYS_KERNEL_END::
|
||||
#exe {
|
||||
if (kernel_cfg->opts[CFG_BOOT_DRV]) {
|
||||
StreamPrint("DU8 0x%X-(SYS_KERNEL_END-SYS_KERNEL_START1+0x7C10) DUP (0);"
|
||||
"BINFILE \"%s\";",kernel_cfg->boot_drv_start,kernel_cfg->boot_drv_file);
|
||||
}
|
||||
if (kernel_cfg->opts[CFG_BOOT_RESCUE_DRV])
|
||||
StreamPrint("DU8 0x%X-(SYS_KERNEL_END-SYS_KERNEL_START1+"
|
||||
"BOOT_RAM_BASE+sizeof(CBinFile)) DUP (0);"
|
||||
"BINFILE \"%s\";",kernel_cfg->boot_rescue_drv_start,kernel_cfg->boot_rescue_drv_file);
|
||||
};
|
||||
}
|
||||
+73
-79
@@ -4,96 +4,90 @@ before import is resolved, you can use
|
||||
"import". Otherwise, use a fun pointer
|
||||
var and check it before calling.
|
||||
*/
|
||||
import U0 MemberLstDel(CHashClass *tempc);
|
||||
import I64 ExePrint(U8 *fmt,...);
|
||||
import I64 ExeFile(U8 *name,Bool just_load=FALSE);
|
||||
import Bool DocUnlock(CDoc *doc);
|
||||
import Bool Ed(U8 *link_st,I64 ed_flags=0);
|
||||
import Bool Ed(U8 *link_st,I64 edf_dof_flags=0);
|
||||
import I64 ExeFile(U8 *name,Bool just_load=FALSE);
|
||||
import I64 ExePrint(U8 *fmt,...);
|
||||
import U0 MemberLstDel(CHashClass *tempc);
|
||||
import I64 PopUp(U8 *msg,CTask *parent=NULL,CTask **_pu_task=NULL);
|
||||
|
||||
extern U0 throw(I64 ch=0,Bool no_log=FALSE);
|
||||
extern U8 *FileNameAbs(U8 *name,I64 fuf_flags=0);
|
||||
extern U8 *DftExt(U8 *name,U8 *extension);
|
||||
extern Bool Cd(U8 *name,Bool make_dirs=FALSE);
|
||||
extern Bool MkDir(U8 *filename);
|
||||
extern U0 Msg(I64 code,I64 p1,I64 p2,I64 flags=0);
|
||||
extern Bool BlkDevLock(CBlkDev *bdev);
|
||||
extern Bool BlkDevUnlock(CBlkDev *bdev,Bool rst=FALSE);
|
||||
extern Bool RBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt);
|
||||
extern Bool WBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt);
|
||||
extern U0 DskCacheInvalidate(CPrt *p);
|
||||
extern Bool Drv(U8 drv_let);
|
||||
extern U0 BlkDevsRelease();
|
||||
extern U0 PrtsRelease();
|
||||
extern CBlkDev *BlkDevNextFree(U8 first_drv_let,I64 type);
|
||||
extern U0 AdamErr(U8 *fmt,...);
|
||||
extern U0 AdamLog(U8 *fmt,...);
|
||||
extern I64 BlkDevAdd(CBlkDev *bdev,Bool one_prt,Bool make_free);
|
||||
extern Bool IsRaw();
|
||||
extern U0 MPInt(I64 num,I64 cpu_num=1);
|
||||
extern U0 XTalk(CTask *task,U8 *fmt,...);
|
||||
extern Bool Suspend(CTask *task=NULL,Bool state=TRUE);
|
||||
extern U0 SrvCmdDel(CSrvCmd *tempc);
|
||||
extern U0 SrvCmdQueDel(CSrvCmd *root);
|
||||
extern U0 SrvCtrlInit(CSrvCtrl *ctrl);
|
||||
extern Bool TaskValidate(CTask *task);
|
||||
|
||||
extern U8 *FileExtRem(U8 *src,U8 *dst=NULL);
|
||||
extern Bool IsDir(U8 *dir_name);
|
||||
extern Bool FileFind(U8 *filename,CDirEntry *_de=NULL,I64 fuf_flags=0);
|
||||
extern Bool ISOPrtInit(CPrt *p,I64 blk);
|
||||
extern Bool ISO1FileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fuf_flags=0);
|
||||
extern CDirEntry *ISO1FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NULL);
|
||||
extern U0 RedSeaFSFreeFreeLst(CPrt *p);
|
||||
extern U0 RedSeaFSPrtInit(CPrt *p);
|
||||
extern U0 FAT32PrtInit(CPrt *p);
|
||||
extern Bool RedSeaFSDrvValidate(U8 drv_let);
|
||||
extern U0 RedSeaFSFmt(U8 drv_let,Bool quick=TRUE);
|
||||
extern Bool RedSeaFSFileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fuf_flags=0);
|
||||
extern Bool FAT32FileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fuf_flags=0);
|
||||
extern U8 *FileRead(U8 *filename,I64 *_size=NULL,I64 *_attr=NULL,Bool raw=FALSE);
|
||||
extern I64 RedSeaFSAllocClusters(CPrt *p,I64 cnt);
|
||||
extern Bool BlkDevLock(CBlkDev *bdev);
|
||||
extern CBlkDev *BlkDevNextFree(U8 first_drv_let,I64 type);
|
||||
extern Bool BlkDevUnlock(CBlkDev *bdev,Bool rst=FALSE);
|
||||
extern U0 BlkDevsRelease();
|
||||
extern Bool BptS(U8 *addr,CTask *task=NULL,Bool live=TRUE);
|
||||
extern U8 *Caller(I64 num=1);
|
||||
extern U8 *CatPrint(U8 *dst,U8 *fmt,...);
|
||||
extern Bool Cd(U8 *name,Bool make_dirs=FALSE);
|
||||
extern U0 Dbg(U8 *msg=NULL,I64 msg_num=0);
|
||||
extern U0 DbgHelp();
|
||||
extern U8 *Define(U8 *name);
|
||||
extern I64 DefineMatch(U8 *needle,U8 *haystack_lst_name,I64 flags=0);
|
||||
extern U8 *DefineSub(I64 sub,U8 *name);
|
||||
extern U8 *DftExt(U8 *name,U8 *extension);
|
||||
extern Bool Drv(U8 drv_let);
|
||||
extern U0 DskCacheInvalidate(CPrt *p);
|
||||
extern U0 Exit();
|
||||
extern I64 FAT32AllocClusters(CPrt *p,I64 c,I64 cnt);
|
||||
extern I64 FAT32AllocContiguousClusters(CPrt *p,I64 cnt);
|
||||
extern Bool RedSeaFSDirNew(CPrt *p,U8 *cur_dir,CDirEntry *tempdee,Bool free_old_chain);
|
||||
extern Bool FAT32DirNew(CPrt *p,U8 *cur_dir,CDirEntry *tempdee,Bool free_old_chain);
|
||||
extern CDirEntry *RedSeaFSFilesFind (U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NULL);
|
||||
extern Bool FAT32FileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fuf_flags=0);
|
||||
extern CDirEntry *FAT32FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NULL,I64 *_dir_size=NULL);
|
||||
extern U0 FAT32PrtInit(CPrt *p);
|
||||
extern U8 *FileExtRem(U8 *src,U8 *dst=NULL);
|
||||
extern Bool FileFind(U8 *filename,CDirEntry *_de=NULL,I64 fuf_flags=0);
|
||||
extern U8 *FileNameAbs(U8 *name,I64 fuf_flags=0);
|
||||
extern U8 *FileRead(U8 *filename,I64 *_size=NULL,I64 *_attr=NULL,Bool raw=FALSE);
|
||||
extern I64 FileWrite(U8 *filename,U8 *fbuf,
|
||||
I64 size,CDate cdt=0,I64 attr=0,Bool raw=FALSE);
|
||||
|
||||
extern U0 Exit();
|
||||
extern U0 AdamLog(U8 *fmt,...);
|
||||
extern U0 Dbg(U8 *msg=NULL,I64 msg_num=0);
|
||||
extern Bool BptS(U8 *addr,CTask *task=NULL,Bool live=TRUE);
|
||||
extern U0 DbgHelp();
|
||||
extern U8 *Caller(I64 num=1);
|
||||
extern CTask *SpawnQue(U0 (*fp_addr)(U8 *data),U8 *data=NULL,
|
||||
U8 *task_name=NULL,
|
||||
I64 target_cpu,
|
||||
CTask *parent=NULL, //NULL means adam
|
||||
I64 stk_size=0,I64 flags=1<<SVCf_ADD_TO_QUE);
|
||||
extern CTask *SpawnUser(U8 *fmt=NULL,...);
|
||||
extern U0 TaskRstAwaitingMsg(CTask *task=NULL);
|
||||
extern CSrvCmd *TaskMsg(CTask *_srv,CTask *master,
|
||||
I64 code,I64 p1,I64 p2,I64 flags);
|
||||
extern U0 TaskWait(CTask *task=NULL);
|
||||
extern I64 SrvCmdsHandler(CTask *task=NULL);
|
||||
extern U0 Print(U8 *fmt,...);
|
||||
extern U8 *SPrint(U8 *dst,U8 *fmt,...);
|
||||
extern U8 *MPrint(U8 *fmt,...);
|
||||
extern U8 *Define(U8 *name);
|
||||
extern U8 *DefineSub(I64 sub,U8 *name);
|
||||
extern I64 DefineMatch(U8 *needle,U8 *haystack_lst_name,I64 flags=0);
|
||||
extern U0 PutS(U8 *st); //Use $LK,"Print",A="MN:Print"$()
|
||||
extern U0 PutChars(U64 ch);
|
||||
extern I64 GetChar(I64 *scancode=NULL,Bool echo=TRUE,Bool raw_cursor=FALSE);
|
||||
extern Bool IsDbg();
|
||||
I64 size,CDate cdt=0,I64 attr=0,Bool raw=FALSE);
|
||||
extern I64 FlushMsgs(CTask *task=NULL);
|
||||
extern U0 SetMouseIP(I64 x,I64 y,I64 z,I64 l,I64 r,I64 c);
|
||||
extern U0 SPrintPSect(U8 *buf,I64 addr,I64 field_len);
|
||||
extern U8 *CatPrint(U8 *dst,U8 *fmt,...);
|
||||
extern I64 GetChar(I64 *scan_code=NULL,Bool echo=TRUE,Bool raw_cursor=FALSE);
|
||||
extern I64 GetS(U8 *buf,I64 size,Bool allow_ext=TRUE);
|
||||
extern Bool ISO1FileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fuf_flags=0);
|
||||
extern CDirEntry *ISO1FilesFind(U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NULL);
|
||||
extern Bool ISOPrtInit(CPrt *p,I64 blk);
|
||||
extern Bool IsDbg();
|
||||
extern Bool IsDir(U8 *dir_name);
|
||||
extern Bool IsRaw();
|
||||
extern U0 MPInt(I64 num,I64 cpu_num=1);
|
||||
extern U8 *MStrPrint(U8 *fmt,...);
|
||||
extern Bool MkDir(U8 *filename);
|
||||
extern U0 Msg(I64 code,I64 a1,I64 a2,I64 flags=0);
|
||||
extern U0 Print(U8 *fmt,...);
|
||||
extern U0 PrtsRelease();
|
||||
extern U0 PutChars(U64 ch);
|
||||
extern U0 PutS(U8 *st); //Use $LK,"Print",A="MN:Print"$()
|
||||
extern Bool RBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt);
|
||||
extern I64 RedSeaFSAllocClusters(CPrt *p,I64 cnt);
|
||||
extern Bool RedSeaFSDirNew(CPrt *p,U8 *cur_dir,CDirEntry *tempdee,Bool free_old_chain);
|
||||
extern Bool RedSeaFSDrvValidate(U8 drv_let);
|
||||
extern Bool RedSeaFSFileFind(CPrt *p,I64 cur_dir_cluster,U8 *name,CDirEntry *_result,I64 fuf_flags=0);
|
||||
extern CDirEntry *RedSeaFSFilesFind (U8 *files_find_mask,I64 fuf_flags,CDirEntry *parent=NULL);
|
||||
extern U0 RedSeaFSFmt(U8 drv_let,Bool quick=TRUE);
|
||||
extern U0 RedSeaFSFreeFreeLst(CPrt *p);
|
||||
extern U0 RedSeaFSPrtInit(CPrt *p);
|
||||
extern U0 SetMouseIP(I64 x,I64 y,I64 z,I64 l,I64 r);
|
||||
extern CTask *SpawnQue(U0 (*fp_addr)(U8 *data),U8 *data=NULL,
|
||||
U8 *task_name=NULL,I64 target_cpu,CTask *parent=NULL, //NULL means adam
|
||||
I64 stk_size=0,I64 flags=1<<SVCf_ADD_TO_QUE);
|
||||
extern CTask *SpawnUser(U8 *fmt=NULL,...);
|
||||
extern U0 SrvCmdDel(CSrvCmd *tempc);
|
||||
extern U0 SrvCmdQueDel(CSrvCmd *root);
|
||||
extern I64 SrvCmdsHandler(CTask *task=NULL);
|
||||
extern U0 SrvCtrlInit(CSrvCtrl *ctrl);
|
||||
extern U8 *StrPrint(U8 *dst,U8 *fmt,...);
|
||||
extern U0 StrPrintPSect(U8 *buf,I64 addr,I64 field_len);
|
||||
extern Bool Suspend(CTask *task=NULL,Bool state=TRUE);
|
||||
extern CSrvCmd *TaskMsg(CTask *_srv,CTask *master,I64 code,I64 a1,I64 a2,I64 flags);
|
||||
extern U0 TaskRstAwaitingMsg(CTask *task=NULL);
|
||||
extern Bool TaskValidate(CTask *task);
|
||||
extern U0 TaskWait(CTask *task=NULL);
|
||||
extern U0 UserTaskCont();
|
||||
|
||||
extern Bool WBlks(CPrt *p,U8 *buf, I64 blk, I64 cnt);
|
||||
extern U0 XTalk(CTask *task,U8 *fmt,...);
|
||||
extern U0 throw(I64 ch=0,Bool no_log=FALSE);
|
||||
#exe {
|
||||
OptOn(OPTf_KEEP_PRIVATE);
|
||||
OptOn(OPTf_EXTERNS_TO_IMPORTS);
|
||||
|
||||
+27
-126
@@ -1,132 +1,33 @@
|
||||
U8 sys_temp_filename[136];
|
||||
//Compiler initializes glbls in AOT bin modules to zero.
|
||||
|
||||
CSrvCmd sys_macro_root;
|
||||
CKeyDev sys_put_key_root;
|
||||
CTask *sys_macro_util_task=NULL,
|
||||
*sys_dbg_focus_task=NULL;
|
||||
U8 *sys_dbg_msg=NULL;
|
||||
I64 sys_dbg_msg_num=0;
|
||||
|
||||
CMPCrash *mp_crash=NULL;
|
||||
U8 mp_apic_ids[MP_MAX_PROCESSORS];
|
||||
I64 *sys_idt=NULL;
|
||||
CTask *adam_task;
|
||||
I64 sys_num_spawned_tasks=0;
|
||||
|
||||
U8 *sys_fault_handlers_code;
|
||||
|
||||
CCacheBlk *sys_dsk_cache_base=NULL,*sys_dsk_cache_ctrl=NULL;
|
||||
CCacheBlk **sys_dsk_cache_hash_table=NULL;
|
||||
I64 sys_dsk_cache_size;
|
||||
|
||||
I64 sys_raw_col=0,sys_raw_flags=0;
|
||||
U8 *sys_raw_screen_image;
|
||||
Bool text_mode;
|
||||
I64 text_rows,text_cols, //Use TEXT_ROWS,TEXT_COLS
|
||||
gr_width,gr_height; //Use GR_WIDTH,GR_HEIGHT
|
||||
U8 *gr_font;
|
||||
U8 *sys_fix_file_line=NULL;
|
||||
|
||||
CTask *sys_winmgr_task=NULL,
|
||||
*sys_task_being_screen_updated=NULL;
|
||||
I64 sys_rnd_seed;
|
||||
CTask *sys_macro_util_task;
|
||||
CDoc *sys_clipboard_doc;
|
||||
U8 *sys_dft_iso_name;
|
||||
I64 sys_dsk_reads,sys_dsk_writes;
|
||||
CBlkDev *sys_blkdevs;
|
||||
CPrt *sys_prts;
|
||||
I64 sys_auto_mount_ide_cnt=0;
|
||||
#exe {
|
||||
if (!kernel_cfg->auto_mount_ide_hd_let)
|
||||
kernel_cfg->auto_mount_ide_hd_let='C';
|
||||
if (!kernel_cfg->auto_mount_ide_cd_let)
|
||||
kernel_cfg->auto_mount_ide_cd_let='T';
|
||||
StreamPrint("U8 sys_first_hd_drv_let=%d,sys_first_cd_drv_let=%d;",
|
||||
kernel_cfg->auto_mount_ide_hd_let,kernel_cfg->auto_mount_ide_cd_let);
|
||||
}
|
||||
Bool boot_drv_pmt=FALSE,cdrom_boot_is_good=TRUE;
|
||||
CPrt *drv_to_prt[32];
|
||||
U8 *sys_acct;
|
||||
U8 *reverse_bits_table,*set_bits_table;
|
||||
U0 (**fp_ctrl_alt_let_cbs)(I64 sc);
|
||||
I64 ctrl_alt_let_in_irq_flags;
|
||||
I64 **ctrl_alt_let_ret_addr; //addr of ret addr on stack in kbd irq
|
||||
U8 **ctrl_alt_let_descs;
|
||||
|
||||
CTask *adam_task;
|
||||
I64 sys_num_spawned_tasks;
|
||||
|
||||
CTask *sys_winmgr_task,*sys_task_being_screen_updated;
|
||||
I64 sys_rnd_seed;
|
||||
U8 *sys_acct; // "D:/Acct/User"
|
||||
U8 *reverse_bits_table, //Table with U8 bits reversed
|
||||
*set_bits_table; //Table with count of set bits in a U8
|
||||
CDate local_time_offset=0;
|
||||
Bool time_stamp_freq_calibrated=FALSE;
|
||||
I64 HPET_freq=0,HPET_kHz_freq=0,HPET_initial=0,
|
||||
time_stamp_freq=2676302000,
|
||||
time_stamp_kHz_freq=2676302,
|
||||
time_stamp_freq_initial=2676302000,
|
||||
mouse_evt_time=0,kbd_evt_time=0,mouse_pkt_size=3;
|
||||
I64 sys_cur_scan_code=0;
|
||||
|
||||
U8 key_desc[128];
|
||||
Bool kbd_irqs_working;
|
||||
U8 *key_handler;
|
||||
|
||||
CPCIDev sys_pci_dev_root;
|
||||
CMemRange sys_mem32_dev_root;
|
||||
U8 *sys_mem64_dev_ptr=MEM_MAPPED_SPACE;
|
||||
|
||||
F64 snd_freq=0;
|
||||
Bool snd_record=FALSE;
|
||||
|
||||
F64 *pow10_I64;
|
||||
|
||||
CHeapCtrl *sys_uncached_heap;
|
||||
CSndGlbls snd;
|
||||
CCntsGlbls cnts={1,0,2676302000,2676302,2676302000,0,0,0,FALSE};
|
||||
CIPStateGlbls ip,ip_last;
|
||||
CGridGlbls ip_grid;
|
||||
CMouseStateGlbls mouse,mouse_last;
|
||||
CKbdStateGlbls kbd;
|
||||
CKeyDevGlbls keydev;
|
||||
CDevGlbls dev;
|
||||
CTextGlbls text;
|
||||
CDbgGlbls dbg;
|
||||
CDskGlbls dsk;
|
||||
|
||||
|
||||
I64 ipx,ipy,ipz,ip_throttle,ip_throttle_step; //Throttle is [MIN_I32,MAX_I32]
|
||||
I64 ipx_presnap,ipy_presnap,ipz_presnap;
|
||||
I64 ipx_offset,ipy_offset,ipz_offset;
|
||||
F64 ipx_scale,ipy_scale,ipz_scale;
|
||||
F64 ip_speed;
|
||||
I64 ip_dev;
|
||||
I64 iptx,ipty;
|
||||
Bool ip_on, //Show or hide cursor
|
||||
ip_lb_last,ip_cb_last,ip_rb_last,
|
||||
ip_lb,ip_cb,ip_rb;
|
||||
Bool ip_has_wheel;
|
||||
F64 ip_last_move_time;
|
||||
CGrid ip_grid;
|
||||
|
||||
F64 mxx_scale,myy_scale,mzz_scale;
|
||||
|
||||
//These are the coordinates before
|
||||
//they get scaled.
|
||||
I64 mxx_prescale,myy_prescale,mzz_prescale;
|
||||
I64 mxx,myy,mzz;
|
||||
F64 mouse_speed;
|
||||
I64 old_mxx,old_myy,old_mzz;
|
||||
Bool mouse_buttons[5];
|
||||
|
||||
Bool mouse_has_wheel,
|
||||
mouse_has_ext_buttons,
|
||||
mouse_evt,
|
||||
mouse_installed,
|
||||
mouse_install_attempt_in_progress,
|
||||
kbdmouse_rst,
|
||||
mouse_irqs_working;
|
||||
CFifoI64 *scan_code_fifo;
|
||||
CFifoU8 *kbd_fifo,*kbd2_fifo,
|
||||
*mouse_fifo,*mouse2_fifo;
|
||||
I64 sys_key_cnt,
|
||||
sys_last_down_scan_code,
|
||||
mouse_install_attempts,
|
||||
mouse_last_evt_time;
|
||||
|
||||
//BitTest, $LK,"Bt",A="MN:Bt"$(), with a merged scan code.
|
||||
//(Left and right shift merged, for example.)
|
||||
U32 key_down_bitmap[8];
|
||||
//BitTest, $LK,"Bt",A="MN:Bt"$(), with an unmerged scan code.
|
||||
U32 key_down_bitmap2[8];
|
||||
|
||||
CSndData snd_record_root;
|
||||
|
||||
U8 *(*fp_mgets)(I64 flags=0)=NULL;
|
||||
U0 (*fp_update_ctrls)(CTask *task)=NULL;
|
||||
CDoc *(*fp_doc_put)(CTask *task=NULL)=NULL;
|
||||
U0 (*fp_set_std_palette)()=NULL;
|
||||
|
||||
CPSectCache *psect_cache;
|
||||
I64 psect_cache_index;
|
||||
U8 *(*fp_getstr2)(I64 flags=0);
|
||||
U0 (*fp_update_ctrls)(CTask *task);
|
||||
CDoc *(*fp_doc_put)(CTask *task=NULL);
|
||||
U0 (*fp_set_std_palette)();
|
||||
+17
-44
@@ -18,14 +18,14 @@ USE16
|
||||
SYS_KERNEL_START1:: //This must match $LK,"CKernel",A="MN:CKernel"$.
|
||||
JMP U16 SYS_KERNEL_START2
|
||||
|
||||
// ************************************
|
||||
//************************************
|
||||
// ASM Global vars required for 16-bit start-up
|
||||
ALIGN 4,OC_NOP
|
||||
SYS_BOOT_BASE:: DU32 0; //Fixed offset from start used by reboot
|
||||
SYS_BOOT_PATCH_TABLE_BASE:: DU32 0;
|
||||
#exe {StreamPrint("SYS_COMPILE_TIME:: DU64 0x%X;",Now);}
|
||||
//See $LK,"BootCdProbe",A="MN:BootCdProbe"$
|
||||
#assert SYS_COMPILE_TIME+8+16<CD_BLK_SIZE
|
||||
#assert SYS_COMPILE_TIME+8+sizeof(CBinFile)<CD_BLK_SIZE
|
||||
|
||||
SYS_OS_32START:: DU32 SYS_INIT_OS;
|
||||
SYS_BOOT_CODE:: DU32 0xFF;
|
||||
@@ -53,9 +53,9 @@ SYS_PCI_BUSSES:: DU16 0;
|
||||
SYS_RUN_LEVEL:: DU32 0;
|
||||
SYS_TEMP_PTR:: DU16 0;
|
||||
DU64 0;
|
||||
// ************************************
|
||||
//EBX is SYS_BOOT_CODE (val passed from boot blk)
|
||||
//************************************
|
||||
SYS_KERNEL_START2::
|
||||
//EBX is SYS_BOOT_CODE (val passed from boot blk)
|
||||
MOV AX,(BOOT_RAM_LIMIT-BOOT_STK_SIZE)/16
|
||||
MOV SS,AX
|
||||
MOV SP,BOOT_STK_SIZE
|
||||
@@ -81,42 +81,18 @@ TEMPLEOS_CONT_START:
|
||||
|
||||
MOV U32 [SYS_RUN_LEVEL],RLF_16BIT
|
||||
|
||||
#exe {StreamPrint("MOV BX,%d\n",kernel_cfg->bios_gr_mode);};
|
||||
MOV BX,0x12 //640x480 16 color
|
||||
MOV U16 [SYS_BIOS_GR_MODE],BX
|
||||
MOV AX,0x4F02
|
||||
#exe {
|
||||
if (!kernel_cfg->opts[CFG_TEXT_MODE])
|
||||
StreamPrint("INT 0x10"); //Enable VGA
|
||||
StreamPrint("INT 0x10"); //Enable VGA
|
||||
};
|
||||
CMP AX,0x004F
|
||||
JE @@10
|
||||
MOV U16 [SYS_BIOS_GR_MODE],0 //failed
|
||||
@@10:
|
||||
|
||||
/**** This doesn't help
|
||||
//Enable mouse
|
||||
MOV AX,0xC200 //Enable
|
||||
MOV BX,0x0100
|
||||
INT 0x15
|
||||
MOV AX,0xC201 //Rst
|
||||
INT 0x15
|
||||
MOV AX,0xC200 //Enable
|
||||
MOV BX,0x0100
|
||||
INT 0x15
|
||||
MOV AX,0xC202 //Sample
|
||||
MOV BX,0x0500 //100
|
||||
INT 0x15
|
||||
MOV AX,0xC203 //Resolution
|
||||
MOV BX,0x0300 //8 per mm
|
||||
INT 0x15
|
||||
MOV AX,0xC205 //pkt size
|
||||
MOV BX,0x0300
|
||||
INT 0x15
|
||||
MOV AX,0xC200 //Enable
|
||||
MOV BX,0x0100
|
||||
INT 0x15
|
||||
****/
|
||||
|
||||
//Get mem maps
|
||||
MOV AX,0xE801
|
||||
INT 0x15
|
||||
@@ -184,12 +160,12 @@ TEMPLEOS_CONT_START:
|
||||
POP U32 [SYS_BOOT_CODE]
|
||||
|
||||
MOV BX,CS
|
||||
DEC BX
|
||||
#assert sizeof(CBinFile)==16
|
||||
SUB BX,sizeof(CBinFile)/16
|
||||
#assert !(sizeof(CBinFile)&15)
|
||||
MOV GS,BX
|
||||
MOV EBX,U32 GS:[CBinFile.loader_patch_table_offset]
|
||||
MOV EBX,U32 GS:[CBinFile.patch_table_offset]
|
||||
ADD EAX,EBX
|
||||
SUB EAX,16
|
||||
SUB EAX,sizeof(CBinFile)
|
||||
MOV U32 [SYS_BOOT_PATCH_TABLE_BASE],EAX
|
||||
|
||||
MOV U32 [GDT_BOOT_DS],0x0000FFFF
|
||||
@@ -200,8 +176,7 @@ TEMPLEOS_CONT_START:
|
||||
ADD U32 [GDT_BOOT_DS+2],EAX
|
||||
ADD U32 [GDT_BOOT_CS+2],EAX
|
||||
|
||||
// Set-up ptr to limit and base
|
||||
//of GDT.
|
||||
//Set-up ptr to limit and base of GDT.
|
||||
MOV U16 [SYS_TEMP_PTR],sizeof(CGDT)-1
|
||||
MOV EAX,U32 [SYS_BOOT_BASE]
|
||||
ADD EAX,SYS_GDT
|
||||
@@ -226,7 +201,7 @@ the code segment with a far jump.
|
||||
|
||||
#assert $$+16<=0xFFFF
|
||||
USE32
|
||||
// ************************************
|
||||
//************************************
|
||||
// ASM Global vars not required for 16-bit start-up
|
||||
ALIGN 8,OC_NOP
|
||||
SYS_HEAP_BASE:: DU64 SYS_FIXED_AREA+sizeof(CSysFixedArea);
|
||||
@@ -268,8 +243,6 @@ SYS_PROGRESS4_DESC:: DU8 PROGRESS_DESC_LEN+1 DUP(0);
|
||||
#assert $$-SYS_PROGRESSES==sizeof(CProgress)*4
|
||||
|
||||
SYS_FOCUS_TASK:: DU64 0;
|
||||
SYS_TIMER:: DU64 0;
|
||||
SYS_JIFFIES:: DU64 1;
|
||||
SYS_CPU_STRUCTS:: DU64 0;
|
||||
SYS_MP_CNT:: DU64 1;
|
||||
SYS_MP_CNT_INITIAL:: DU64 1;
|
||||
@@ -279,7 +252,7 @@ SYS_MP_CNT_LOCK:: DU64 1;
|
||||
SYS_CACHE_LINE_WIDTH:: DU64 DFT_CACHE_LINE_WIDTH;
|
||||
DU8 DFT_CACHE_LINE_WIDTH-sizeof(CBinFile)-8 DUP(0);
|
||||
SYS_SEMAS:: DU8 NUM_SYS_SEMAS*SEMA_STRUCT_SIZE DUP(0);
|
||||
// ************************************
|
||||
//************************************
|
||||
ALIGN 16,OC_NOP
|
||||
SYS_INIT_OS:: //Entry point for RAM reboots.
|
||||
PUSH U32 SYS_START_RFLAGS
|
||||
@@ -303,8 +276,8 @@ SYS_INIT_OS:: //Entry point for RAM reboots.
|
||||
MOV DS,AX
|
||||
MOV ES,AX
|
||||
|
||||
MOV ECX,U32 CBinFilePatchTableWithoutOrg.abs_addres_cnt[ESI]
|
||||
LEA ESI,U32 CBinFilePatchTableWithoutOrg.abs_addres[ESI]
|
||||
MOV ECX,U32 CPatchTableAbsAddr.abs_addres_cnt[ESI]
|
||||
LEA ESI,U32 CPatchTableAbsAddr.abs_addres[ESI]
|
||||
@@05: LODSD
|
||||
ADD EAX,EDI
|
||||
ADD U32 [EAX],EDI
|
||||
@@ -378,7 +351,7 @@ USE64
|
||||
|
||||
JMP I32 &KernelMain
|
||||
|
||||
// ************************************
|
||||
//************************************
|
||||
USE32
|
||||
INIT_EM64T:
|
||||
MOV_EAX_CR4
|
||||
@@ -405,7 +378,7 @@ USE64
|
||||
EM64T_PART3:
|
||||
RET
|
||||
|
||||
// ************************************
|
||||
//************************************
|
||||
SYS_RESTART_KERNEL::
|
||||
XOR RDI,RDI
|
||||
MOV EDI,U32 SYS_BOOT_BASE
|
||||
|
||||
@@ -1,70 +1,67 @@
|
||||
U0 GridInit()
|
||||
{
|
||||
{//Init input pointer grid struct.
|
||||
ip_grid.x=ip_grid.y=ip_grid.z=8;
|
||||
ip_grid.x_offset=ip_grid.y_offset=ip_grid.z_offset=0;
|
||||
ip_grid.x_speed =ip_grid.y_speed =ip_grid.z_speed =1;
|
||||
ip_grid.show=ip_grid.snap=FALSE;
|
||||
}
|
||||
|
||||
U0 IPVarsUpdate(I64 x,I64 y,I64 z,Bool l,Bool c,Bool r)
|
||||
U0 IPVarsUpdate(I64 x,I64 y,I64 z,Bool l,Bool r)
|
||||
{
|
||||
ipx_presnap=ToI64(ipx_scale*x)+ipx_offset;
|
||||
ipy_presnap=ToI64(ipy_scale*y)+ipy_offset;
|
||||
ipz_presnap=ToI64(ipz_scale*z)+ipz_offset;
|
||||
ip.presnap.x=ToI64(ip.scale.x*x)+ip.offset.x;
|
||||
ip.presnap.y=ToI64(ip.scale.y*y)+ip.offset.y;
|
||||
ip.presnap.z=ToI64(ip.scale.z*z)+ip.offset.z;
|
||||
if (ip_grid.snap) {
|
||||
ipx=Trunc(ipx_presnap/ip_grid.x)*ip_grid.x+ip_grid.x_offset;
|
||||
ipy=Trunc(ipy_presnap/ip_grid.y)*ip_grid.y+ip_grid.y_offset;
|
||||
ipz=Trunc(ipz_presnap/ip_grid.z)*ip_grid.z+ip_grid.z_offset;
|
||||
ip.pos.x=Trunc(ip.presnap.x/ip_grid.x)*ip_grid.x+ip_grid.x_offset;
|
||||
ip.pos.y=Trunc(ip.presnap.y/ip_grid.y)*ip_grid.y+ip_grid.y_offset;
|
||||
ip.pos.z=Trunc(ip.presnap.z/ip_grid.z)*ip_grid.z+ip_grid.z_offset;
|
||||
} else {
|
||||
ipx=ipx_presnap;
|
||||
ipy=ipy_presnap;
|
||||
ipz=ipz_presnap;
|
||||
ip.pos.x=ip.presnap.x;
|
||||
ip.pos.y=ip.presnap.y;
|
||||
ip.pos.z=ip.presnap.z;
|
||||
}
|
||||
|
||||
ipx=ClampI64(ipx,0,gr_width-1);
|
||||
ipy=ClampI64(ipy,0,gr_height-1);
|
||||
ip_throttle=ClampI64(ip_throttle,MIN_I32,MAX_I32);
|
||||
iptx=ipx/FONT_WIDTH;
|
||||
if (iptx>=text_cols) {
|
||||
iptx=text_cols-1;
|
||||
ipx=text_cols*FONT_WIDTH-1;
|
||||
ip.pos.x=ClampI64(ip.pos.x,0,GR_WIDTH-1);
|
||||
ip.pos.y=ClampI64(ip.pos.y,0,GR_HEIGHT-1);
|
||||
ip.throttle=ClampI64(ip.throttle,MIN_I32,MAX_I32);
|
||||
ip.pos_text.x=ip.pos.x/FONT_WIDTH;
|
||||
if (ip.pos_text.x>=text.cols) {
|
||||
ip.pos_text.x=text.cols-1;
|
||||
ip.pos.x=text.cols*FONT_WIDTH-1;
|
||||
}
|
||||
ipty=ipy/FONT_HEIGHT;
|
||||
if (ipty>=text_rows) {
|
||||
ipty=text_rows-1;
|
||||
ipy=text_rows*FONT_HEIGHT-1;
|
||||
ip.pos_text.y=ip.pos.y/FONT_HEIGHT;
|
||||
if (ip.pos_text.y>=text.rows) {
|
||||
ip.pos_text.y=text.rows-1;
|
||||
ip.pos.y=text.rows*FONT_HEIGHT-1;
|
||||
}
|
||||
ip_lb=l;
|
||||
ip_cb=c;
|
||||
ip_rb=r;
|
||||
LBEqu(&sys_cur_scan_code,SCf_IP_L_DOWN,ip_lb);
|
||||
LBEqu(&sys_cur_scan_code,SCf_IP_R_DOWN,ip_rb);
|
||||
ip.lb=l;
|
||||
ip.rb=r;
|
||||
LBEqu(&kbd.scan_code,SCf_IP_L_DOWN,ip.lb);
|
||||
LBEqu(&kbd.scan_code,SCf_IP_R_DOWN,ip.rb);
|
||||
}
|
||||
|
||||
U0 SetIP(I64 x=MAX_I64,I64 y=MAX_I64,I64 z=MAX_I64,I64 l=MAX_I64,I64 r=MAX_I64,I64 c=MAX_I64)
|
||||
{ //Note: Generates a message.
|
||||
U0 SetIP(I64 x=MAX_I64,I64 y=MAX_I64,I64 z=MAX_I64,I64 l=MAX_I64,I64 r=MAX_I64)
|
||||
{//Note: Generates a message.
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
if (!(0<=x<gr_width))
|
||||
x=ipx;
|
||||
if (!(0<=y<gr_height))
|
||||
y=ipy;
|
||||
if (!(0<=x<GR_WIDTH))
|
||||
x=ip.pos.x;
|
||||
if (!(0<=y<GR_HEIGHT))
|
||||
y=ip.pos.y;
|
||||
if (z==MAX_I64)
|
||||
z=ipz;
|
||||
z=ip.pos.z;
|
||||
|
||||
if (!(FALSE<=l<=TRUE))
|
||||
l=ip_lb;
|
||||
if (!(FALSE<=c<=TRUE))
|
||||
c=ip_cb;
|
||||
l=ip.lb;
|
||||
if (!(FALSE<=r<=TRUE))
|
||||
r=ip_rb;
|
||||
r=ip.rb;
|
||||
|
||||
x=(x-ipx_offset)/ipx_scale;
|
||||
y=(y-ipy_offset)/ipy_scale;
|
||||
z=(z-ipz_offset)/ipz_scale;
|
||||
IPVarsUpdate(x,y,z,l,c,r);
|
||||
switch (ip_dev) {
|
||||
x=(x-ip.offset.x)/ip.scale.x;
|
||||
y=(y-ip.offset.y)/ip.scale.y;
|
||||
z=(z-ip.offset.z)/ip.scale.z;
|
||||
IPVarsUpdate(x,y,z,l,r);
|
||||
switch (ip.dev) {
|
||||
case IP_MOUSE:
|
||||
SetMouseIP(x,y,z,l,c,r);
|
||||
SetMouseIP(x,y,z,l,r);
|
||||
break;
|
||||
}
|
||||
Preempt(old_preempt);
|
||||
@@ -72,28 +69,18 @@ U0 SetIP(I64 x=MAX_I64,I64 y=MAX_I64,I64 z=MAX_I64,I64 l=MAX_I64,I64 r=MAX_I64,I
|
||||
|
||||
U0 IPVarsInit()
|
||||
{
|
||||
ipx=0;
|
||||
ipy=0;
|
||||
ipz=0;
|
||||
ip_throttle=0;
|
||||
ip_throttle_step=(MAX_I32+1)>>3;
|
||||
ipx_offset=0;
|
||||
ipy_offset=0;
|
||||
ipz_offset=0;
|
||||
ipx_scale=1.0;
|
||||
ipy_scale=1.0;
|
||||
ipz_scale=1.0;
|
||||
ip_speed=0;
|
||||
ip_dev=IP_NULL;
|
||||
iptx=ipx/FONT_WIDTH;
|
||||
ipty=ipy/FONT_HEIGHT;
|
||||
ip_on=TRUE;
|
||||
ip_lb_last=FALSE;
|
||||
ip_rb_last=FALSE;
|
||||
ip_lb=FALSE;
|
||||
ip_cb=FALSE;
|
||||
ip_rb=FALSE;
|
||||
ip_has_wheel=FALSE;
|
||||
ip_last_move_time=tS;
|
||||
MemSet(&ip,0,sizeof(CIPStateGlbls));
|
||||
MemSet(&ip_last,0,sizeof(CIPStateGlbls));
|
||||
ip.throttle=0;
|
||||
ip.throttle_step=(MAX_I32+1)>>3;
|
||||
ip.offset.x=ip.offset.y=ip.offset.z=0;
|
||||
ip.scale.x=ip.scale.y=ip.scale.z=1.0;
|
||||
ip.dev=IP_NULL;
|
||||
ip.pos_text.x=ip.pos_text.y=ip.pos_text.z=0;
|
||||
ip.has_wheel=FALSE;
|
||||
ip.show=TRUE;
|
||||
ip.speed=0;
|
||||
ip.timestamp=GetTSC;
|
||||
ip.dbl_time=0.350;
|
||||
GridInit;
|
||||
}
|
||||
@@ -81,7 +81,7 @@ U0 KbdMouseCmdAck(U8 val)
|
||||
}
|
||||
|
||||
U0 SetTypeMatic(U8 delay)
|
||||
{
|
||||
{//Set speed of repeated keys.
|
||||
try {
|
||||
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse
|
||||
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard
|
||||
@@ -94,8 +94,8 @@ U0 SetTypeMatic(U8 delay)
|
||||
}
|
||||
}
|
||||
|
||||
I64 A2ScanCode(I64 ch,I64 sc_flags=0)
|
||||
{ //ASCII val to scan code (Slow)
|
||||
I64 Char2ScanCode(I64 ch,I64 sc_flags=0)
|
||||
{//ASCII val to scan code (Slow).
|
||||
I64 i;
|
||||
U8 *table;
|
||||
if (sc_flags) {
|
||||
@@ -130,9 +130,8 @@ I64 A2ScanCode(I64 ch,I64 sc_flags=0)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U8 ScanCode2A(I64 sc)
|
||||
{//Scan Code to ASCII val
|
||||
U8 ScanCode2Char(I64 sc)
|
||||
{//Scan code to ASCII val.
|
||||
U8 *table=NORMAL_KEY_SCAN_DECODE_TABLE;
|
||||
if (sc & SCF_E0_PREFIX)
|
||||
return 0;
|
||||
@@ -172,7 +171,6 @@ U8 scan_code_map[0x100]={
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
};
|
||||
|
||||
|
||||
U8 num_lock_map[0x100]={
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
@@ -193,8 +191,8 @@ U8 num_lock_map[0x100]={
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
};
|
||||
|
||||
U8 *A2KeyName(I64 ch,Bool include_ctrl=TRUE)
|
||||
{//ASCII val to key name
|
||||
U8 *Char2KeyName(I64 ch,Bool include_ctrl=TRUE)
|
||||
{//ASCII val to key name.
|
||||
I64 i;
|
||||
U8 buf[136];
|
||||
if (ch<=CH_SPACE) {
|
||||
@@ -241,7 +239,7 @@ U8 *A2KeyName(I64 ch,Bool include_ctrl=TRUE)
|
||||
}
|
||||
|
||||
U8 *ScanCode2KeyName(I64 sc)
|
||||
{
|
||||
{//Scan code to key name.
|
||||
I64 ch;
|
||||
U8 buf[136],*st;
|
||||
*buf=0;
|
||||
@@ -251,8 +249,8 @@ U8 *ScanCode2KeyName(I64 sc)
|
||||
CatPrint(buf,"ALT ");
|
||||
if (sc&SCF_SHIFT)
|
||||
CatPrint(buf,"SHIFT ");
|
||||
if (ch=ScanCode2A(sc&255)) {
|
||||
st=A2KeyName(ch,FALSE);
|
||||
if (ch=ScanCode2Char(sc&255)) {
|
||||
st=Char2KeyName(ch,FALSE);
|
||||
StrCpy(buf+StrLen(buf),st);
|
||||
Free(st);
|
||||
} else {
|
||||
@@ -319,41 +317,41 @@ I64 KbdBuildSC(U8 raw_byte,U8 *_last_raw_byte,I64 *_last_sc,
|
||||
|
||||
if (sc&SCF_KEY_UP)
|
||||
switch (sc&~SCF_KEY_UP) {
|
||||
case SC_SHIFT: sc_flags&=~SCF_SHIFT; goto new_key_done;
|
||||
case SC_CTRL: sc_flags&=~SCF_CTRL; goto new_key_done;
|
||||
case SC_ALT: sc_flags&=~SCF_ALT; goto new_key_done;
|
||||
case SC_DELETE: sc_flags&=~SCF_DELETE; goto new_key_done;
|
||||
case SC_INS: sc_flags&=~SCF_INS; goto new_key_done;
|
||||
case SC_SHIFT: sc_flags&=~SCF_SHIFT; goto kb_new_key_done;
|
||||
case SC_CTRL: sc_flags&=~SCF_CTRL; goto kb_new_key_done;
|
||||
case SC_ALT: sc_flags&=~SCF_ALT; goto kb_new_key_done;
|
||||
case SC_DELETE: sc_flags&=~SCF_DELETE; goto kb_new_key_done;
|
||||
case SC_INS: sc_flags&=~SCF_INS; goto kb_new_key_done;
|
||||
case SC_CAPS:
|
||||
sc_flags^=SCF_CAPS;
|
||||
*_set_LEDs=TRUE;
|
||||
goto new_key_done;
|
||||
goto kb_new_key_done;
|
||||
case SC_NUM:
|
||||
sc_flags^=SCF_NUM;
|
||||
*_set_LEDs=TRUE;
|
||||
goto new_key_done;
|
||||
goto kb_new_key_done;
|
||||
case SC_SCROLL:
|
||||
sc_flags^=SCF_SCROLL;
|
||||
*_set_LEDs=TRUE;
|
||||
goto new_key_done;
|
||||
goto kb_new_key_done;
|
||||
}
|
||||
else
|
||||
switch (sc) {
|
||||
case SC_SHIFT: sc_flags|=SCF_SHIFT; goto new_key_done;
|
||||
case SC_CTRL: sc_flags|=SCF_CTRL; goto new_key_done;
|
||||
case SC_ALT: sc_flags|=SCF_ALT; goto new_key_done;
|
||||
case SC_DELETE: sc_flags|=SCF_DELETE; goto new_key_done;
|
||||
case SC_INS: sc_flags|=SCF_INS; goto new_key_done;
|
||||
case SC_CAPS: goto new_key_done;
|
||||
case SC_NUM: goto new_key_done;
|
||||
case SC_SCROLL: goto new_key_done;
|
||||
case SC_SHIFT: sc_flags|=SCF_SHIFT; goto kb_new_key_done;
|
||||
case SC_CTRL: sc_flags|=SCF_CTRL; goto kb_new_key_done;
|
||||
case SC_ALT: sc_flags|=SCF_ALT; goto kb_new_key_done;
|
||||
case SC_DELETE: sc_flags|=SCF_DELETE; goto kb_new_key_done;
|
||||
case SC_INS: sc_flags|=SCF_INS; goto kb_new_key_done;
|
||||
case SC_CAPS: goto kb_new_key_done;
|
||||
case SC_NUM: goto kb_new_key_done;
|
||||
case SC_SCROLL: goto kb_new_key_done;
|
||||
}
|
||||
|
||||
if (sc_flags & SCF_CTRL && sc_flags & SCF_ALT) {
|
||||
sc_flags&=~SCF_NEW_KEY;
|
||||
*_ctrl_alt=TRUE;
|
||||
} else {
|
||||
new_key_done:
|
||||
kb_new_key_done:
|
||||
sc_flags|=SCF_NEW_KEY;
|
||||
}
|
||||
return *_last_sc=sc_flags|sc|(sc_flags|sc_raw)<<32;
|
||||
@@ -367,9 +365,9 @@ U0 KbdPktRead()
|
||||
I64 ch,sc;
|
||||
Bool set_LEDs,ctrl_alt;
|
||||
|
||||
if (GetTSC>kbd_evt_time+time_stamp_freq>>3)
|
||||
FifoU8Flush(kbd_fifo);
|
||||
kbd_evt_time=GetTSC;
|
||||
if (GetTSC>kbd.timestamp+cnts.time_stamp_freq>>3)
|
||||
FifoU8Flush(kbd.fifo);
|
||||
kbd.timestamp=GetTSC;
|
||||
raw_byte=InU8(KBD_PORT);
|
||||
sc=KbdBuildSC(raw_byte,&last_raw_byte,&last_sc,&set_LEDs,&ctrl_alt);
|
||||
if (ctrl_alt && sc) {
|
||||
@@ -382,25 +380,25 @@ U0 KbdPktRead()
|
||||
else if (sc&255==SC_TAB)
|
||||
ch='t';
|
||||
else
|
||||
ch=ScanCode2A(sc&255);
|
||||
if ('a'<=ch<='z' && fp_ctrl_alt_let_cbs[ch-'a'] &&
|
||||
Bt(&ctrl_alt_let_in_irq_flags,ch-'a')) {
|
||||
(*fp_ctrl_alt_let_cbs[ch-'a'])(last_sc);
|
||||
ch=ScanCode2Char(sc&255);
|
||||
if ('a'<=ch<='z' && keydev.fp_ctrl_alt_let_cbs[ch-'a'] &&
|
||||
Bt(&keydev.ctrl_alt_let_in_irq_flags,ch-'a')) {
|
||||
(*keydev.fp_ctrl_alt_let_cbs[ch-'a'])(last_sc);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!FifoU8Cnt(kbd_fifo)) {
|
||||
FifoU8Ins(kbd_fifo,raw_byte);
|
||||
if (!FifoU8Cnt(kbd.fifo)) {
|
||||
FifoU8Ins(kbd.fifo,raw_byte);
|
||||
if (raw_byte!=0xE0) {
|
||||
while (FifoU8Rem(kbd_fifo,&raw_byte))
|
||||
FifoU8Ins(kbd2_fifo,raw_byte);
|
||||
while (FifoU8Rem(kbd.fifo,&raw_byte))
|
||||
FifoU8Ins(kbd.fifo2,raw_byte);
|
||||
}
|
||||
} else {
|
||||
FifoU8Ins(kbd_fifo,raw_byte);
|
||||
while (FifoU8Rem(kbd_fifo,&raw_byte))
|
||||
FifoU8Ins(kbd2_fifo,raw_byte);
|
||||
FifoU8Ins(kbd.fifo,raw_byte);
|
||||
while (FifoU8Rem(kbd.fifo,&raw_byte))
|
||||
FifoU8Ins(kbd.fifo2,raw_byte);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,15 +406,26 @@ interrupt U0 KbdIntHandler()
|
||||
{
|
||||
CLD
|
||||
OutU8(0x20,0x20);
|
||||
kbd_irqs_working=TRUE;
|
||||
if (mouse_install_attempt_in_progress) {
|
||||
kbdmouse_rst=TRUE;
|
||||
kbd.irqs_working=TRUE;
|
||||
if (mouse.install_in_progress) {
|
||||
kbd.rst=TRUE;
|
||||
return;
|
||||
}
|
||||
ctrl_alt_let_ret_addr=GetRBP()(I64)+8;
|
||||
keydev.ctrl_alt_let_ret_addr=GetRBP()(I64)+8;
|
||||
KbdPktRead;
|
||||
}
|
||||
|
||||
U0 SetCtrlAltLetCB(U8 ch,U0 (*fp_handler)(I64 sc),U8 *desc,Bool in_irq=FALSE)
|
||||
{//Set callback for <CTRL-ALT-letter>.
|
||||
ch=ToUpper(ch)-'A';
|
||||
if (ch<26) {
|
||||
keydev.fp_ctrl_alt_let_cbs[ch]=fp_handler;
|
||||
Free(keydev.ctrl_alt_let_descs[ch]);
|
||||
keydev.ctrl_alt_let_descs[ch]=AStrNew(desc);
|
||||
BEqu(&keydev.ctrl_alt_let_in_irq_flags,ch,in_irq);
|
||||
}
|
||||
}
|
||||
|
||||
U0 KbdInit()
|
||||
{
|
||||
try {
|
||||
@@ -425,7 +434,7 @@ U0 KbdInit()
|
||||
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard
|
||||
KbdCmdSend(KBD_PORT,0xF0);
|
||||
KbdCmdSend(KBD_PORT,0x02);
|
||||
KbdSetLEDs(sys_cur_scan_code);
|
||||
KbdSetLEDs(kbd.scan_code);
|
||||
} catch {
|
||||
KbdCmdFlush;
|
||||
Fs->catch_except=TRUE;
|
||||
@@ -449,13 +458,13 @@ U0 KbdHandler()
|
||||
Bool set_LEDs,ctrl_alt;
|
||||
I64 ch,sc;
|
||||
|
||||
FifoU8Rem(kbd2_fifo,&raw_byte);
|
||||
sc=KbdBuildSC(raw_byte,&last_raw_byte,&sys_cur_scan_code,&set_LEDs,&ctrl_alt);
|
||||
FifoU8Rem(kbd.fifo2,&raw_byte);
|
||||
sc=KbdBuildSC(raw_byte,&last_raw_byte,&kbd.scan_code,&set_LEDs,&ctrl_alt);
|
||||
if (set_LEDs)
|
||||
KbdSetLEDs(sc);
|
||||
if (raw_byte==0xE0) {
|
||||
FifoU8Rem(kbd2_fifo,&raw_byte);
|
||||
sc=KbdBuildSC(raw_byte,&last_raw_byte,&sys_cur_scan_code,&set_LEDs,&ctrl_alt);
|
||||
FifoU8Rem(kbd.fifo2,&raw_byte);
|
||||
sc=KbdBuildSC(raw_byte,&last_raw_byte,&kbd.scan_code,&set_LEDs,&ctrl_alt);
|
||||
if (set_LEDs)
|
||||
KbdSetLEDs(sc);
|
||||
}
|
||||
@@ -466,42 +475,40 @@ U0 KbdHandler()
|
||||
else if (sc&255==SC_TAB)
|
||||
ch='t';
|
||||
else
|
||||
ch=ScanCode2A(sc&255);
|
||||
if ('a'<=ch<='z' && fp_ctrl_alt_let_cbs[ch-'a'] &&
|
||||
!Bt(&ctrl_alt_let_in_irq_flags,ch-'a'))
|
||||
(*fp_ctrl_alt_let_cbs[ch-'a'])(sys_cur_scan_code);
|
||||
ch=ScanCode2Char(sc&255);
|
||||
if ('a'<=ch<='z' && keydev.fp_ctrl_alt_let_cbs[ch-'a'] &&
|
||||
!Bt(&keydev.ctrl_alt_let_in_irq_flags,ch-'a'))
|
||||
(*keydev.fp_ctrl_alt_let_cbs[ch-'a'])(kbd.scan_code);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (Btr(&sys_cur_scan_code,SCf_NEW_KEY)) {
|
||||
Btr(&sys_cur_scan_code,32+SCf_NEW_KEY);
|
||||
FifoI64Ins(scan_code_fifo,sys_cur_scan_code);
|
||||
sys_key_cnt++;
|
||||
if (!(sys_cur_scan_code&SCF_KEY_UP)) {
|
||||
sys_last_down_scan_code=sys_cur_scan_code;
|
||||
Bts(key_down_bitmap,sys_cur_scan_code.u8[0]);
|
||||
Bts(key_down_bitmap2,sys_cur_scan_code.u8[4]);
|
||||
if (Btr(&kbd.scan_code,SCf_NEW_KEY)) {
|
||||
Btr(&kbd.scan_code,32+SCf_NEW_KEY);
|
||||
FifoI64Ins(kbd.scan_code_fifo,kbd.scan_code);
|
||||
kbd.cnt++;
|
||||
if (!(kbd.scan_code&SCF_KEY_UP)) {
|
||||
kbd.last_down_scan_code=kbd.scan_code;
|
||||
Bts(kbd.down_bitmap,kbd.scan_code.u8[0]);
|
||||
Bts(kbd.down_bitmap2,kbd.scan_code.u8[4]);
|
||||
} else {
|
||||
Btr(key_down_bitmap,sys_cur_scan_code.u8[0]);
|
||||
Btr(key_down_bitmap2,sys_cur_scan_code.u8[4]);
|
||||
Btr(kbd.down_bitmap,kbd.scan_code.u8[0]);
|
||||
Btr(kbd.down_bitmap2,kbd.scan_code.u8[4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
I64 KbdMsgsQue()
|
||||
{
|
||||
I64 p1,p2,msg_code=MSG_NULL;
|
||||
I64 a1,a2,msg_code=MSG_NULL;
|
||||
CTask *task_focus;
|
||||
if (task_focus=sys_focus_task) {
|
||||
while (FifoI64Rem(scan_code_fifo,&p2)) {
|
||||
p1=ScanCode2A(p2);
|
||||
if (p2 & SCF_KEY_UP) {
|
||||
TaskMsg(task_focus,0,
|
||||
MSG_KEY_UP,p1,p2,0);
|
||||
while (FifoI64Rem(kbd.scan_code_fifo,&a2)) {
|
||||
a1=ScanCode2Char(a2);
|
||||
if (a2 & SCF_KEY_UP) {
|
||||
TaskMsg(task_focus,0,MSG_KEY_UP,a1,a2,0);
|
||||
msg_code=MSG_KEY_UP;
|
||||
} else {
|
||||
TaskMsg(task_focus,0,
|
||||
MSG_KEY_DOWN,p1,p2,0);
|
||||
TaskMsg(task_focus,0,MSG_KEY_DOWN,a1,a2,0);
|
||||
msg_code=MSG_KEY_DOWN;
|
||||
}
|
||||
}
|
||||
@@ -510,9 +517,9 @@ I64 KbdMsgsQue()
|
||||
}
|
||||
|
||||
I64 KbdMouseEvtTime()
|
||||
{
|
||||
if (mouse_evt_time>kbd_evt_time)
|
||||
return mouse_evt_time;
|
||||
{//Timestamp of last key or mouse event.
|
||||
if (mouse.timestamp>kbd.timestamp)
|
||||
return mouse.timestamp;
|
||||
else
|
||||
return kbd_evt_time;
|
||||
return kbd.timestamp;
|
||||
}
|
||||
+66
-42
@@ -36,8 +36,13 @@ U0 InputFilterTask()
|
||||
SetRFlags(old_flags);
|
||||
}
|
||||
|
||||
I64 ScanMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
|
||||
{
|
||||
I64 ScanMsg(I64 *_a1=NULL,I64 *_a2=NULL,I64 mask=~1,CTask *task=NULL)
|
||||
{/*Check for a message of type specified by a one in the mask.
|
||||
Throw-out messages not in mask.
|
||||
If no message fit mask, return NULL immediately.
|
||||
Remove desired message, return $LK,"msg_code",A="MN:MSG_CMD"$.
|
||||
Note: This delivers messages from parent down to pop-up.
|
||||
*/
|
||||
I64 result,old_flags;
|
||||
CSrvCmd *tempc,*tempc1;
|
||||
if (!task) task=Fs;
|
||||
@@ -55,10 +60,10 @@ I64 ScanMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
|
||||
QueRem(tempc);
|
||||
SetRFlags(old_flags);
|
||||
result=tempc->msg_code;
|
||||
if (_p1)
|
||||
*_p1=tempc->aux1;
|
||||
if (_p2)
|
||||
*_p2=tempc->aux2;
|
||||
if (_a1)
|
||||
*_a1=tempc->aux1;
|
||||
if (_a2)
|
||||
*_a2=tempc->aux2;
|
||||
SrvCmdDel(tempc);
|
||||
if ((result!=MSG_KEY_DOWN || !(tempc->aux2&SCF_KEY_DESC) ||
|
||||
Bt(&mask,MSGF_ALLOW_KEY_DESC)) && Bt(&mask,result))
|
||||
@@ -68,13 +73,13 @@ I64 ScanMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
|
||||
SetRFlags(old_flags);
|
||||
}
|
||||
result=MSG_NULL;
|
||||
if (_p1)
|
||||
*_p1=0;
|
||||
if (_p2)
|
||||
*_p2=0;
|
||||
if (_a1)
|
||||
*_a1=0;
|
||||
if (_a2)
|
||||
*_a2=0;
|
||||
if (task->parent_task&&task->parent_task->popup_task==task) {
|
||||
SetRFlags(old_flags);
|
||||
return ScanMsg(_p1,_p2,mask,task->parent_task);
|
||||
return ScanMsg(_a1,_a2,mask,task->parent_task);
|
||||
}
|
||||
sm_done:
|
||||
SetRFlags(old_flags);
|
||||
@@ -82,20 +87,22 @@ sm_done:
|
||||
}
|
||||
|
||||
I64 FlushMsgs(CTask *task=NULL)
|
||||
{
|
||||
I64 result=0,p1,p2;
|
||||
while (ScanMsg(&p1,&p2,~1,task))
|
||||
{//Throw away all messages. Return count.
|
||||
I64 result=0,a1,a2;
|
||||
while (ScanMsg(&a1,&a2,~1,task))
|
||||
result++;
|
||||
return result;
|
||||
}
|
||||
|
||||
I64 GetMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
|
||||
{
|
||||
I64 GetMsg(I64 *_a1=NULL,I64 *_a2=NULL,I64 mask=~1,CTask *task=NULL)
|
||||
{//Wait for a message of type specified by a one in the mask.
|
||||
//Throw-out all messages not in mask.
|
||||
//Returns $LK,"msg_code",A="MN:MSG_CMD"$. See $LK,"::/Demo/MsgLoop.CPP"$.
|
||||
I64 result;
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
if (!task) task=Fs;
|
||||
LBtr(&task->task_flags,TASKf_IDLE);
|
||||
while (!(result=ScanMsg(_p1,_p2,mask,task))) {
|
||||
while (!(result=ScanMsg(_a1,_a2,mask,task))) {
|
||||
LBts(&task->task_flags,TASKf_IDLE);
|
||||
Yield;
|
||||
}
|
||||
@@ -105,42 +112,49 @@ I64 GetMsg(I64 *_p1=NULL,I64 *_p2=NULL,I64 mask=~1,CTask *task=NULL)
|
||||
}
|
||||
|
||||
I64 ScanChar()
|
||||
{
|
||||
I64 p1a,p2a,p1b,p2b;
|
||||
if (!ScanMsg(&p1a,&p2a,1<<MSG_KEY_DOWN)||!p1a)
|
||||
{//Checks for $LK,"MSG_KEY_DOWN",A="MN:MSG_KEY_DOWN"$ and returns 0 immediately if no key.
|
||||
//Waits for $LK,"MSG_KEY_UP",A="MN:MSG_KEY_UP"$ of non-zero $LK,"ASCII",A="MN:CH_CTRLA"$ key and returns $LK,"ASCII",A="MN:CH_CTRLA"$ if key.
|
||||
//$LK,"ScanMsg",A="MN:ScanMsg"$() throws away other message types.
|
||||
I64 a1a,a2a,a1b,a2b;
|
||||
if (!ScanMsg(&a1a,&a2a,1<<MSG_KEY_DOWN)||!a1a)
|
||||
return 0;
|
||||
else
|
||||
do GetMsg(&p1b,&p2b,1<<MSG_KEY_UP);
|
||||
while (!p1b);
|
||||
return p1a;
|
||||
do GetMsg(&a1b,&a2b,1<<MSG_KEY_UP);
|
||||
while (!a1b); //Be careful of $LK,"SC_SHIFT",A="MN:SC_SHIFT"$ and $LK,"SC_CTRL",A="MN:SC_CTRL"$, etc.
|
||||
return a1a;
|
||||
}
|
||||
|
||||
Bool ScanKey(I64 *_ch=NULL,I64 *_scancode=NULL,Bool echo=FALSE)
|
||||
{
|
||||
Bool ScanKey(I64 *_ch=NULL,I64 *_scan_code=NULL,Bool echo=FALSE)
|
||||
{//Checks for $LK,"MSG_KEY_DOWN",A="MN:MSG_KEY_DOWN"$ and returns FALSE immediately if no key.
|
||||
//Sets $LK,"ASCII",A="MN:CH_CTRLA"$ and $LK,"scan_code",A="FI:::/Doc/CharOverview.TXT"$.
|
||||
//Removes key message and returns TRUE.
|
||||
//$LK,"ScanMsg",A="MN:ScanMsg"$() throws away other message types.
|
||||
I64 ch=0,sc=0;
|
||||
if (ScanMsg(&ch,&sc,1<<MSG_KEY_DOWN)) {
|
||||
if (_ch) *_ch=ch;
|
||||
if (_scancode) *_scancode=sc;
|
||||
if (_scan_code) *_scan_code=sc;
|
||||
if (echo)
|
||||
PutKey(ch,sc);
|
||||
return TRUE;
|
||||
} else {
|
||||
if (_ch) *_ch=0;
|
||||
if (_scancode) *_scancode=0;
|
||||
if (_scan_code) *_scan_code=0;
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
I64 GetKey(I64 *_scancode=NULL,Bool echo=FALSE,Bool raw_cursor=FALSE)
|
||||
{
|
||||
I64 GetKey(I64 *_scan_code=NULL,Bool echo=FALSE,Bool raw_cursor=FALSE)
|
||||
{//Waits for $LK,"MSG_KEY_DOWN",A="MN:MSG_KEY_DOWN"$ message and returns $LK,"ASCII",A="MN:CH_CTRLA"$.
|
||||
//Sets $LK,"scan_code",A="FI:::/Doc/CharOverview.TXT"$.
|
||||
//$LK,"ScanKey",A="MN:ScanKey"$() throws away other message types.
|
||||
I64 ch,sc;
|
||||
Bool old_preempt=Preempt(OFF),cursor_on=FALSE;
|
||||
while (!ScanKey(&ch,&sc,FALSE)) {
|
||||
if (IsRaw && raw_cursor) {
|
||||
if (!cursor_on && ToI64(GetTSC*5/time_stamp_freq)&1) {
|
||||
if (!cursor_on && ToI64(GetTSC*5/cnts.time_stamp_freq)&1) {
|
||||
'Û';
|
||||
cursor_on=TRUE;
|
||||
} else if (cursor_on && !(ToI64(GetTSC*5/time_stamp_freq)&1)) {
|
||||
} else if (cursor_on && !(ToI64(GetTSC*5/cnts.time_stamp_freq)&1)) {
|
||||
'' CH_BACKSPACE;
|
||||
cursor_on=FALSE;
|
||||
}
|
||||
@@ -168,34 +182,44 @@ I64 GetKey(I64 *_scancode=NULL,Bool echo=FALSE,Bool raw_cursor=FALSE)
|
||||
Preempt(old_preempt);
|
||||
if (echo)
|
||||
PutKey(ch,sc);
|
||||
if (_scancode) *_scancode=sc;
|
||||
if (_scan_code) *_scan_code=sc;
|
||||
return ch;
|
||||
}
|
||||
|
||||
I64 GetChar(I64 *_scancode=NULL,Bool echo=TRUE,Bool raw_cursor=FALSE)
|
||||
{
|
||||
I64 GetChar(I64 *_scan_code=NULL,Bool echo=TRUE,Bool raw_cursor=FALSE)
|
||||
{//Waits for non-zero $LK,"ASCII",A="MN:CH_CTRLA"$ key.
|
||||
//Sets $LK,"scan_code",A="FI:::/Doc/CharOverview.TXT"$.
|
||||
I64 ch1;
|
||||
do ch1=GetKey(_scancode,FALSE,raw_cursor);
|
||||
do ch1=GetKey(_scan_code,FALSE,raw_cursor);
|
||||
while (!ch1);
|
||||
if (echo)
|
||||
"$$PT$$%c$$FG$$",ch1;
|
||||
return ch1;
|
||||
}
|
||||
|
||||
U8 *MGetS(I64 flags=0)
|
||||
//$LK,"Flags",A="MN:GETSF_SHIFT_ESC_EXIT"$
|
||||
{
|
||||
//Returns a $LK,"MAlloc",A="MN:MAlloc"$()ed prompted string.
|
||||
return (*fp_mgets)(flags);
|
||||
U8 *GetStr(U8 *msg=NULL,U8 *dft=NULL,I64 flags=0)
|
||||
{//Returns a $LK,"MAlloc",A="MN:MAlloc"$()ed prompted string. See $LK,"Flags",A="MN:GSF_SHIFT_ESC_EXIT"$.
|
||||
U8 *st;
|
||||
if (msg)
|
||||
"" msg,dft;
|
||||
st=(*fp_getstr2)(flags);
|
||||
if (!*st) {
|
||||
Free(st);
|
||||
if (dft)
|
||||
return StrNew(dft);
|
||||
else
|
||||
return StrNew("");
|
||||
}
|
||||
return st;
|
||||
}
|
||||
|
||||
I64 GetS(U8 *buf,I64 size,Bool allow_ext=TRUE)
|
||||
{
|
||||
{//Prompt into fixed length string. Size must include terminator.
|
||||
U8 *st;
|
||||
I64 ch,i=0;
|
||||
if (!size || !buf) return 0;
|
||||
if (allow_ext) {
|
||||
st=MGetS;
|
||||
st=GetStr;
|
||||
if (StrLen(st)>size-1) {
|
||||
MemCpy(buf,st,size-1);
|
||||
buf[size-1]=0;
|
||||
|
||||
+99
-120
@@ -1,13 +1,13 @@
|
||||
U0 MousePktRead()
|
||||
{
|
||||
U8 j;
|
||||
if (GetTSC>mouse_evt_time+time_stamp_freq>>3)
|
||||
FifoU8Flush(mouse_fifo);
|
||||
mouse_evt_time=GetTSC;
|
||||
FifoU8Ins(mouse_fifo,InU8(KBD_PORT));
|
||||
if (FifoU8Cnt(mouse_fifo)==mouse_pkt_size)
|
||||
while (FifoU8Rem(mouse_fifo,&j))
|
||||
FifoU8Ins(mouse2_fifo,j);
|
||||
if (GetTSC>mouse.timestamp+cnts.time_stamp_freq>>3)
|
||||
FifoU8Flush(mouse.fifo);
|
||||
mouse.timestamp=GetTSC;
|
||||
FifoU8Ins(mouse.fifo,InU8(KBD_PORT));
|
||||
if (FifoU8Cnt(mouse.fifo)==mouse.pkt_size)
|
||||
while (FifoU8Rem(mouse.fifo,&j))
|
||||
FifoU8Ins(mouse.fifo2,j);
|
||||
}
|
||||
|
||||
interrupt U0 MouseIntHandler()
|
||||
@@ -15,9 +15,9 @@ interrupt U0 MouseIntHandler()
|
||||
CLD
|
||||
OutU8(0xA0,0x20);
|
||||
OutU8(0x20,0x20);
|
||||
mouse_irqs_working=TRUE;
|
||||
if (mouse_install_attempt_in_progress || !mouse_installed) {
|
||||
kbdmouse_rst=TRUE;
|
||||
mouse.irqs_working=TRUE;
|
||||
if (mouse.install_in_progress || !mouse.installed) {
|
||||
kbd.rst=TRUE;
|
||||
return;
|
||||
}
|
||||
MousePktRead;
|
||||
@@ -29,9 +29,9 @@ U0 MouseGetDevType()
|
||||
KbdMouseCmdAck(0xF2);
|
||||
b=KbdCmdRead;
|
||||
if (b==3)
|
||||
mouse_has_wheel=TRUE;
|
||||
mouse.has_wheel=TRUE;
|
||||
else if (b==4)
|
||||
mouse_has_ext_buttons=TRUE;
|
||||
mouse.has_ext_buttons=TRUE;
|
||||
}
|
||||
|
||||
Bool MouseRst()
|
||||
@@ -41,8 +41,8 @@ Bool MouseRst()
|
||||
F64 timeout;
|
||||
Bool result=FALSE,present;
|
||||
|
||||
mouse_has_wheel=FALSE;
|
||||
mouse_has_ext_buttons=FALSE;
|
||||
mouse.has_wheel=FALSE;
|
||||
mouse.has_ext_buttons=FALSE;
|
||||
|
||||
_w=0x40E;
|
||||
present=MemPagePresentMark(_w,TRUE);
|
||||
@@ -115,10 +115,10 @@ Bool MouseRst()
|
||||
KbdCmdSend(KBD_CTRL,0xAE); //Enable Keyboard
|
||||
catch
|
||||
Fs->catch_except=TRUE;
|
||||
if (mouse_has_wheel || mouse_has_ext_buttons)
|
||||
mouse_pkt_size=4;
|
||||
if (mouse.has_wheel || mouse.has_ext_buttons)
|
||||
mouse.pkt_size=4;
|
||||
else
|
||||
mouse_pkt_size=3;
|
||||
mouse.pkt_size=3;
|
||||
if (!result)
|
||||
try
|
||||
KbdCmdSend(KBD_CTRL,0xA7); //Disable Mouse
|
||||
@@ -127,50 +127,48 @@ Bool MouseRst()
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
U0 SetMouseSpeed()
|
||||
{
|
||||
I64 dd,temp;
|
||||
if ((dd=SqrI64(old_mxx-mxx)+SqrI64(old_myy-myy)) &&
|
||||
(temp=mouse_evt_time-mouse_last_evt_time))
|
||||
mouse_speed=Sqrt(dd)*time_stamp_freq/temp;
|
||||
mouse_last_evt_time=mouse_evt_time;
|
||||
if ((dd=SqrI64(mouse_last.pos.x-mouse.pos.x)+SqrI64(mouse_last.pos.y-mouse.pos.y)) &&
|
||||
(temp=mouse.timestamp-mouse_last.timestamp))
|
||||
mouse.speed=Sqrt(dd)*cnts.time_stamp_freq/temp;
|
||||
mouse_last.timestamp=mouse.timestamp;
|
||||
}
|
||||
|
||||
U0 MouseUpdatePre(Bool *old_buttons)
|
||||
U0 MouseUpdatePre()
|
||||
{
|
||||
I64 i;
|
||||
old_mxx=mxx; old_myy=myy; old_mzz=mzz;
|
||||
for (i=0;i<5;i++)
|
||||
old_buttons[i]=mouse_buttons[i];
|
||||
I64 old_timestamp=mouse_last.timestamp;
|
||||
MemCpy(&mouse_last,&mouse,sizeof(CMouseStateGlbls));
|
||||
mouse_last.timestamp=old_timestamp;
|
||||
}
|
||||
|
||||
U0 MouseUpdatePost(Bool *old_buttons)
|
||||
U0 MouseUpdatePost()
|
||||
{
|
||||
I64 i;
|
||||
mxx=mxx_prescale*mxx_scale*ip_grid.x_speed;
|
||||
myy=myy_prescale*myy_scale*ip_grid.y_speed;
|
||||
mzz=mzz_prescale*mzz_scale*ip_grid.z_speed;
|
||||
mouse.pos.x=mouse.prescale.x*mouse.scale.x*ip_grid.x_speed;
|
||||
mouse.pos.y=mouse.prescale.y*mouse.scale.y*ip_grid.y_speed;
|
||||
mouse.pos.z=mouse.prescale.z*mouse.scale.z*ip_grid.z_speed;
|
||||
|
||||
i=Trunc(ipx_scale*mxx/ip_grid.x)*ip_grid.x+ipx_offset; //TODO ip_grid.x_offset?
|
||||
i=Trunc(ip.scale.x*mouse.pos.x/ip_grid.x)*ip_grid.x+ip.offset.x; //TODO ip_grid.x_offset?
|
||||
if (i<0)
|
||||
ipx_offset-=i;
|
||||
else if (i>=gr_width)
|
||||
ipx_offset+=gr_width-1-i;
|
||||
ip.offset.x-=i;
|
||||
else if (i>=GR_WIDTH)
|
||||
ip.offset.x+=GR_WIDTH-1-i;
|
||||
|
||||
i=Trunc(ipy_scale*myy/ip_grid.y)*ip_grid.y+ipy_offset;
|
||||
i=Trunc(ip.scale.y*mouse.pos.y/ip_grid.y)*ip_grid.y+ip.offset.y;
|
||||
if (i<0)
|
||||
ipy_offset-=i;
|
||||
else if (i>=gr_height)
|
||||
ipy_offset+=gr_height-1-i;
|
||||
ip.offset.y-=i;
|
||||
else if (i>=GR_HEIGHT)
|
||||
ip.offset.y+=GR_HEIGHT-1-i;
|
||||
|
||||
if (mxx!=old_mxx||myy!=old_myy||mzz!=old_mzz) {
|
||||
mouse_evt=TRUE;
|
||||
if (mouse.pos.x!=mouse_last.pos.x || mouse.pos.y!=mouse_last.pos.y || mouse.pos.z!=mouse_last.pos.z) {
|
||||
mouse.evt=TRUE;
|
||||
SetMouseSpeed;
|
||||
} else
|
||||
for (i=0;i<5;i++)
|
||||
if (mouse_buttons[i]!=old_buttons[i]) {
|
||||
mouse_evt=TRUE;
|
||||
if (mouse.buttons[i]!=mouse_last.buttons[i]) {
|
||||
mouse.evt=TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -179,21 +177,19 @@ U0 MouseHandler()
|
||||
{
|
||||
I64 i,dx,dy,dz;
|
||||
U8 mouse_buf[4];
|
||||
Bool old_buttons[5];
|
||||
|
||||
MouseUpdatePre(old_buttons);
|
||||
|
||||
MouseUpdatePre;
|
||||
for (i=0;i<4;i++)
|
||||
mouse_buf[i]=0;
|
||||
for (i=0;i<mouse_pkt_size;i++)
|
||||
if (!FifoU8Rem(mouse2_fifo,&mouse_buf[i]))
|
||||
for (i=0;i<mouse.pkt_size;i++)
|
||||
if (!FifoU8Rem(mouse.fifo2,&mouse_buf[i]))
|
||||
mouse_buf[i]=0;
|
||||
|
||||
mouse_buttons[0] = mouse_buf[0] & 1;
|
||||
mouse_buttons[1] = (mouse_buf[0] & 2) >> 1;
|
||||
mouse_buttons[2] = (mouse_buf[0] & 4) >> 2;
|
||||
mouse_buttons[3] = (mouse_buf[3] & 0x10) >> 4;
|
||||
mouse_buttons[4] = (mouse_buf[3] & 0x20) >> 5;
|
||||
mouse.buttons[0] = mouse_buf[0] & 1;
|
||||
mouse.buttons[1] = (mouse_buf[0] & 2) >> 1;
|
||||
mouse.buttons[2] = (mouse_buf[0] & 4) >> 2;
|
||||
mouse.buttons[3] = (mouse_buf[3] & 0x10) >> 4;
|
||||
mouse.buttons[4] = (mouse_buf[3] & 0x20) >> 5;
|
||||
if (mouse_buf[0] & 0x10)
|
||||
dx=mouse_buf[1]-256;
|
||||
else
|
||||
@@ -207,35 +203,33 @@ U0 MouseHandler()
|
||||
else
|
||||
dz=mouse_buf[3]&7;
|
||||
|
||||
mxx_prescale+=dx;
|
||||
myy_prescale+=dy;
|
||||
mzz_prescale+=dz;
|
||||
mouse.prescale.x+=dx;
|
||||
mouse.prescale.y+=dy;
|
||||
mouse.prescale.z+=dz;
|
||||
|
||||
MouseUpdatePost(old_buttons);
|
||||
MouseUpdatePost;
|
||||
}
|
||||
|
||||
U0 SetMouseIP(I64 x,I64 y,I64 z,I64 l,I64 r,I64 c)
|
||||
U0 SetMouseIP(I64 x,I64 y,I64 z,I64 l,I64 r)
|
||||
{
|
||||
Bool old_buttons[5];
|
||||
mouse_evt_time=GetTSC;
|
||||
MouseUpdatePre(old_buttons);
|
||||
mxx_prescale=x/mxx_scale/ip_grid.x_speed;
|
||||
myy_prescale=y/myy_scale/ip_grid.y_speed;
|
||||
mzz_prescale=z/mzz_scale/ip_grid.z_speed;
|
||||
mouse_buttons[0]=l;
|
||||
mouse_buttons[1]=r;
|
||||
mouse_buttons[2]=c; //unsure which one
|
||||
MouseUpdatePost(old_buttons);
|
||||
mouse.timestamp=GetTSC;
|
||||
MouseUpdatePre;
|
||||
mouse.prescale.x=x/mouse.scale.x/ip_grid.x_speed;
|
||||
mouse.prescale.y=y/mouse.scale.y/ip_grid.y_speed;
|
||||
mouse.prescale.z=z/mouse.scale.z/ip_grid.z_speed;
|
||||
mouse.buttons[0]=l;
|
||||
mouse.buttons[1]=r;
|
||||
MouseUpdatePost;
|
||||
}
|
||||
|
||||
U0 KbdMouseRst()
|
||||
{
|
||||
KbdCmdFlush;
|
||||
FifoU8Flush(kbd2_fifo);
|
||||
FifoU8Flush(mouse2_fifo);
|
||||
FifoI64Flush(scan_code_fifo);
|
||||
sys_cur_scan_code=0;
|
||||
kbdmouse_rst=FALSE;
|
||||
FifoU8Flush(kbd.fifo2);
|
||||
FifoU8Flush(mouse.fifo2);
|
||||
FifoI64Flush(kbd.scan_code_fifo);
|
||||
kbd.scan_code=0;
|
||||
kbd.rst=FALSE;
|
||||
}
|
||||
|
||||
Bool MouseDriverInstall(I64 dummy=0) //can be spawned
|
||||
@@ -244,34 +238,34 @@ Bool MouseDriverInstall(I64 dummy=0) //can be spawned
|
||||
I64 i;
|
||||
Bool old_preempt=IsPreempt;
|
||||
Preempt(ON);
|
||||
mouse_install_attempt_in_progress=TRUE;
|
||||
mouse.install_in_progress=TRUE;
|
||||
OutU8(0xA1,InU8(0xA1)|0x10);
|
||||
mouse_installed=mouse_irqs_working=FALSE;
|
||||
mouse.installed=mouse.irqs_working=FALSE;
|
||||
IntEntrySet(0x2C,&MouseIntHandler);
|
||||
for(i=0;i<5;i++)
|
||||
mouse_buttons[i]=0;
|
||||
mouse.buttons[i]=0;
|
||||
if (i=MouseRst)
|
||||
OutU8(0xA1,InU8(0xA1)&~0x10);
|
||||
KbdMouseRst;
|
||||
mouse_install_attempts++;
|
||||
mouse_installed=mouse_evt=i;
|
||||
mouse_install_attempt_in_progress=FALSE;
|
||||
mouse.install_attempts++;
|
||||
mouse.installed=mouse.evt=i;
|
||||
mouse.install_in_progress=FALSE;
|
||||
Preempt(old_preempt);
|
||||
return mouse_installed;
|
||||
return mouse.installed;
|
||||
}
|
||||
|
||||
U0 KbdMouseHandler(Bool poll_kbd,Bool poll_mouse)
|
||||
{
|
||||
if (mouse_install_attempt_in_progress) {
|
||||
if (mouse.install_in_progress) {
|
||||
Yield;
|
||||
return;
|
||||
}
|
||||
if (kbdmouse_rst)
|
||||
if (kbd.rst)
|
||||
KbdMouseRst;
|
||||
else {
|
||||
if (poll_mouse &&
|
||||
mouse_installed &&
|
||||
!mouse_irqs_working) {
|
||||
mouse.installed &&
|
||||
!mouse.irqs_working) {
|
||||
PUSHFD
|
||||
CLI
|
||||
while (InU8(KBD_CTRL)&1)
|
||||
@@ -283,13 +277,13 @@ U0 KbdMouseHandler(Bool poll_kbd,Bool poll_mouse)
|
||||
while (InU8(KBD_CTRL)&1)
|
||||
KbdPktRead;
|
||||
|
||||
if (kbdmouse_rst)
|
||||
if (kbd.rst)
|
||||
KbdMouseRst;
|
||||
else {
|
||||
while (FifoU8Cnt(kbd2_fifo))
|
||||
while (FifoU8Cnt(kbd.fifo2))
|
||||
KbdHandler;
|
||||
while (FifoU8Cnt(mouse2_fifo))
|
||||
if (mouse_installed)
|
||||
while (FifoU8Cnt(mouse.fifo2))
|
||||
if (mouse.installed)
|
||||
MouseHandler;
|
||||
else
|
||||
KbdMouseRst;
|
||||
@@ -299,36 +293,21 @@ U0 KbdMouseHandler(Bool poll_kbd,Bool poll_mouse)
|
||||
|
||||
U0 KbdMouseVarsInit()
|
||||
{
|
||||
sys_key_cnt=0;
|
||||
scan_code_fifo=FifoI64New(128);
|
||||
kbd_fifo=FifoU8New(8);
|
||||
kbd2_fifo=FifoU8New(64);
|
||||
mouse_fifo=FifoU8New(8);
|
||||
mouse2_fifo=FifoU8New(64);
|
||||
MemSet(key_down_bitmap,0,256/8);
|
||||
MemSet(key_down_bitmap2,0,256/8);
|
||||
sys_last_down_scan_code=0;
|
||||
sys_cur_scan_code=0;
|
||||
kbdmouse_rst=FALSE;
|
||||
kbd_irqs_working=FALSE;
|
||||
mouse_irqs_working=FALSE;
|
||||
mxx_scale=0.5;
|
||||
myy_scale=0.5;
|
||||
mzz_scale=1.0;
|
||||
mxx_prescale=gr_width/mxx_scale/2.0;
|
||||
myy_prescale=gr_height/myy_scale/2.0;
|
||||
mzz_prescale=0/mzz_scale;
|
||||
mxx=gr_width>>1;
|
||||
myy=gr_height>>1;
|
||||
mzz=0;
|
||||
mouse_speed=0.0;
|
||||
old_mxx=mxx;
|
||||
old_myy=myy;
|
||||
old_mzz=mzz;
|
||||
mouse_installed=FALSE;
|
||||
mouse_install_attempts=0;
|
||||
mouse_last_evt_time=0;
|
||||
mouse_has_wheel=FALSE;
|
||||
mouse_has_ext_buttons=FALSE;
|
||||
mouse_evt=FALSE;
|
||||
MemSet(&kbd,0,sizeof(CKbdStateGlbls));
|
||||
kbd.fifo=FifoU8New(8);
|
||||
kbd.fifo2=FifoU8New(64);
|
||||
kbd.scan_code_fifo=FifoI64New(128);
|
||||
kbd.irqs_working=FALSE;
|
||||
MemSet(&mouse,0,sizeof(CMouseStateGlbls));
|
||||
mouse.fifo=FifoU8New(8);
|
||||
mouse.fifo2=FifoU8New(64);
|
||||
mouse.scale.x=0.5;
|
||||
mouse.scale.y=0.5;
|
||||
mouse.scale.z=1.0;
|
||||
mouse.prescale.x=GR_WIDTH/mouse.scale.x/2.0;
|
||||
mouse.prescale.y=GR_HEIGHT/mouse.scale.y/2.0;
|
||||
mouse.prescale.z=0/mouse.scale.z;
|
||||
mouse.pos.x=GR_WIDTH>>1;
|
||||
mouse.pos.y=GR_HEIGHT>>1;
|
||||
MemCpy(&mouse_last,&mouse,sizeof(CMouseStateGlbls));
|
||||
}
|
||||
+3219
-3307
File diff suppressed because it is too large.
Load diff
+5
-6
@@ -1,6 +1,5 @@
|
||||
//You should compile this by calling
|
||||
//$LK,"MakeOSPrtBootInstall",A="MN:MakeOSPrtBootInstall"$(), not doing it directly.
|
||||
//See $LK,"Cmp(\"Kernel\")",A="FF:::/Adam/Boot/InsBoot.CPP,Cmp(\"Kernel\""$.
|
||||
//Compile this by calling $LK,"MakeOSPrtBootInstall",A="MN:MakeOSPrtBootInstall"$().
|
||||
//Don't do it directly. See $LK,"Cmp(\"Kernel\")",A="FF:::/Adam/Boot/InsBoot.CPP,Cmp(\"Kernel\""$.
|
||||
|
||||
#exe {
|
||||
OptOn(OPTf_WARN_PAREN);
|
||||
@@ -22,12 +21,12 @@ kernel_cfg=KernelCfgNew;
|
||||
#include "KGlbls"
|
||||
#include "Mem1b"
|
||||
#include "Math1b"
|
||||
#include "Scheduler"
|
||||
#include "Sched"
|
||||
#include "Mem1c"
|
||||
#include "Font8x8"
|
||||
#include "Hash1a"
|
||||
#include "Str1b"
|
||||
#include "Interrupts"
|
||||
#include "Ints"
|
||||
#include "DataTypes1a"
|
||||
#include "Compress"
|
||||
#include "Hash1b"
|
||||
@@ -36,6 +35,7 @@ kernel_cfg=KernelCfgNew;
|
||||
#include "StrScan"
|
||||
#include "Define1a"
|
||||
#include "Display"
|
||||
#include "KeyDev"
|
||||
#include "Misc1a"
|
||||
#include "Dbg1a"
|
||||
#include "Except"
|
||||
@@ -52,7 +52,6 @@ kernel_cfg=KernelCfgNew;
|
||||
#exe {Cd("Dsk");};
|
||||
#include "DskStr"
|
||||
#include "DskCache"
|
||||
#include "ATADef.HPP"
|
||||
#include "DskATA"
|
||||
#include "Dsk1a"
|
||||
#include "DskAddDev"
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
U0 PutKey(I64 ch=0,I64 sc=0)
|
||||
{//See $LK,"Keyboard Devices",A="HI:Keyboard Devices/System"$.
|
||||
CKeyDevEntry *tempp;
|
||||
if (ch||sc) {
|
||||
tempp=keydev.put_key_root.next;
|
||||
if (!Bt(&Fs->display_flags,DISPLAYf_SILENT)) {
|
||||
if (kbd.scan_code & SCF_SCROLL && sys_focus_task==Fs)
|
||||
while (kbd.scan_code & SCF_SCROLL)
|
||||
Yield; //Wait on SCROLL LOCK Key
|
||||
while (tempp!=&keydev.put_key_root) {
|
||||
if ((!(sc & SCF_KEY_DESC) || tempp->flags & KDF_HAS_DESCS) &&
|
||||
(*tempp->put_key)(ch,sc))
|
||||
break;
|
||||
tempp=tempp->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 PutChars(U64 ch)
|
||||
{//Output chars. Can pack multiple chars into a single U64.
|
||||
while (ch) {
|
||||
PutKey(ch&255,0);
|
||||
ch>>=8;
|
||||
}
|
||||
}
|
||||
|
||||
U0 PutS(U8 *st)
|
||||
{//Use $LK,"Print",A="MN:Print"$(). See $LK,"Keyboard Devices",A="HI:Keyboard Devices/System"$.
|
||||
I64 ch;
|
||||
U8 *ptr;
|
||||
Bool cont=TRUE;
|
||||
if (!st) return;
|
||||
CKeyDevEntry *tempp=keydev.put_key_root.next;
|
||||
if (!Bt(&Fs->display_flags,DISPLAYf_SILENT)) {
|
||||
if (kbd.scan_code & SCF_SCROLL && sys_focus_task==Fs)
|
||||
while (kbd.scan_code & SCF_SCROLL)
|
||||
Yield;
|
||||
while (cont && tempp!=&keydev.put_key_root) {
|
||||
if (tempp->put_s) {
|
||||
if ((*tempp->put_s)(st))
|
||||
break;
|
||||
} else {
|
||||
ptr=st;
|
||||
while (ch=*ptr++)
|
||||
if ((*tempp->put_key)(ch,0))
|
||||
cont=FALSE;
|
||||
}
|
||||
tempp=tempp->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 SetKeyDesc(U8 *fmt,...)
|
||||
{//Call this from key handler to report desc in $LK,"KeyMap",A="MN:KeyMap"$().
|
||||
I64 i;
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
StrCpy(keydev.desc,buf);
|
||||
keydev.handler=Caller;
|
||||
Free(buf);
|
||||
for (i=0;i<5;i++)
|
||||
Yield; //Makes KeyMap work better.
|
||||
}
|
||||
|
||||
CKeyDevEntry *KeyDevAdd(Bool (*fp_put_key)(I64 ch,I64 sc),Bool (*fp_puts)(U8 *st),I64 priority,Bool key_descs=FALSE)
|
||||
{//Places hook in StdOut chain. See $LK,"Keyboard Devices",A="HI:Keyboard Devices/System"$.
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
CKeyDevEntry *tempp,*tempp1=keydev.put_key_root.last;
|
||||
tempp=ACAlloc(sizeof(CKeyDevEntry));
|
||||
tempp->put_key=fp_put_key;
|
||||
tempp->put_s=fp_puts;
|
||||
tempp->priority=priority;
|
||||
if (key_descs)
|
||||
tempp->flags|=KDF_HAS_DESCS;
|
||||
while (tempp1->priority>priority)
|
||||
tempp1=tempp1->last;
|
||||
QueIns(tempp,tempp1);
|
||||
Preempt(old_preempt);
|
||||
return tempp;
|
||||
}
|
||||
|
||||
U0 KeyDevRem(CKeyDevEntry *tempp)
|
||||
{//Remove StdOut hook and free.
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
QueRem(tempp);
|
||||
Preempt(old_preempt);
|
||||
Free(tempp);
|
||||
}
|
||||
|
||||
Bool KDRawPutKey(I64 ch,I64)
|
||||
{
|
||||
if (IsRaw) {
|
||||
RawPutChar(ch);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Bool KDRawPutS(U8 *st)
|
||||
{
|
||||
I64 ch;
|
||||
if (IsRaw) {
|
||||
while (ch=*st++)
|
||||
RawPutChar(ch);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Bool KDInputFilterPutKey(I64 ch,I64 scan_code)
|
||||
{
|
||||
Bool old_preempt;
|
||||
if (Bt(&Fs->task_flags,TASKf_INPUT_FILTER_TASK)) {
|
||||
old_preempt=Preempt(OFF);
|
||||
Msg(MSG_KEY_DOWN,ch,scan_code);
|
||||
Preempt(old_preempt);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
Bool KDInputFilterPutS(U8 *st)
|
||||
{
|
||||
I64 ch;
|
||||
Bool old_preempt;
|
||||
if (Bt(&Fs->task_flags,TASKf_INPUT_FILTER_TASK)) {
|
||||
old_preempt=Preempt(OFF);
|
||||
while (ch=*st++)
|
||||
Msg(MSG_KEY_DOWN,ch,0);
|
||||
Preempt(old_preempt);
|
||||
return TRUE;
|
||||
} else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
U0 KeyDevInit()
|
||||
{
|
||||
keydev.fp_ctrl_alt_let_cbs =CAlloc(26*sizeof(U8 *));
|
||||
keydev.ctrl_alt_let_descs =CAlloc(26*sizeof(U8 *));
|
||||
keydev.ctrl_alt_let_in_irq_flags=0;
|
||||
MemSet(&keydev.put_key_root,0,sizeof(CKeyDevEntry));
|
||||
QueInit(&keydev.put_key_root);
|
||||
KeyDevAdd(&KDInputFilterPutKey,&KDInputFilterPutS,0x40000000,FALSE);
|
||||
KeyDevAdd(&KDRawPutKey,&KDRawPutS,0x60000000,FALSE);
|
||||
}
|
||||
+40
-40
@@ -1,6 +1,6 @@
|
||||
asm {
|
||||
USE64
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_NORM::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -18,8 +18,8 @@ _D3_NORM::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
_D3_SQR_NORM::
|
||||
//************************************
|
||||
_D3_NORM_SQR::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV RDX,U64 SF_ARG1[RBP]
|
||||
@@ -35,7 +35,7 @@ _D3_SQR_NORM::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_DIST::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -57,8 +57,8 @@ _D3_DIST::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
_D3_SQR_DIST::
|
||||
//************************************
|
||||
_D3_DIST_SQR::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV RDX,U64 SF_ARG1[RBP]
|
||||
@@ -78,7 +78,7 @@ _D3_SQR_DIST::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_CROSS::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -109,7 +109,7 @@ _D3_CROSS::
|
||||
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_DOT::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -127,7 +127,7 @@ _D3_DOT::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_ADD::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -145,7 +145,7 @@ _D3_ADD::
|
||||
FSTP U64 16[RAX]
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_SUB::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -163,7 +163,7 @@ _D3_SUB::
|
||||
FSTP U64 16[RAX]
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_MUL::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -180,7 +180,7 @@ _D3_MUL::
|
||||
FSTP U64 16[RAX]
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_DIV::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -197,7 +197,7 @@ _D3_DIV::
|
||||
FSTP U64 16[RAX]
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_ZERO::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -208,7 +208,7 @@ _D3_ZERO::
|
||||
MOV U64 16[RAX],RDX
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_COPY::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -222,7 +222,7 @@ _D3_COPY::
|
||||
MOV U64 16[RAX],RDX
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_EQU::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -235,7 +235,7 @@ _D3_EQU::
|
||||
MOV U64 16[RAX],RDX
|
||||
POP RBP
|
||||
RET1 32
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_ADD_EQU::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -252,7 +252,7 @@ _D3_ADD_EQU::
|
||||
FSTP U64 16[RAX]
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_SUB_EQU::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -269,7 +269,7 @@ _D3_SUB_EQU::
|
||||
FSTP U64 16[RAX]
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_MUL_EQU::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -285,7 +285,7 @@ _D3_MUL_EQU::
|
||||
FSTP U64 16[RAX]
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_DIV_EQU::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -301,7 +301,7 @@ _D3_DIV_EQU::
|
||||
FSTP U64 16[RAX]
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_D3_UNIT::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -333,7 +333,7 @@ _D3_UNIT::
|
||||
FINCSTP
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_SQR::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -343,7 +343,7 @@ _SQR::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_SIGN::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -362,7 +362,7 @@ _SIGN::
|
||||
MOV RAX,-1.0
|
||||
@@05: POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_ARG::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -376,7 +376,7 @@ _ARG::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_ROUND::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -396,7 +396,7 @@ _ROUND::
|
||||
FLDCW U16 -6[RBP]
|
||||
LEAVE
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_TRUNC::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -416,7 +416,7 @@ _TRUNC::
|
||||
FLDCW U16 -6[RBP]
|
||||
LEAVE
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_FLOOR::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -437,7 +437,7 @@ _FLOOR::
|
||||
FLDCW U16 -6[RBP]
|
||||
LEAVE
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_CEIL::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -458,7 +458,7 @@ _CEIL::
|
||||
FLDCW U16 -6[RBP]
|
||||
LEAVE
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
SYS_POW::
|
||||
// RAX=RDX`RAX
|
||||
PUSH RBP
|
||||
@@ -511,7 +511,7 @@ SYS_POW::
|
||||
MOV RAX,U64 -8[RBP]
|
||||
@@20: LEAVE
|
||||
RET
|
||||
// ************************************
|
||||
//************************************
|
||||
_POW::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -520,7 +520,7 @@ _POW::
|
||||
CALL SYS_POW
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_POW10::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -554,7 +554,7 @@ _POW10::
|
||||
MOV RAX,U64 -16[RBP]
|
||||
LEAVE
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_EXP::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -588,7 +588,7 @@ _EXP::
|
||||
MOV RAX,U64 -16[RBP]
|
||||
LEAVE
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_LOG10::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -599,7 +599,7 @@ _LOG10::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_LOG2::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -610,7 +610,7 @@ _LOG2::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_LN::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -621,14 +621,14 @@ _LN::
|
||||
MOV RAX,U64 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_FLDCW::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
FLDCW U16 SF_ARG1[RBP]
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_FSTCW::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -637,16 +637,16 @@ _FSTCW::
|
||||
MOVZX RAX,U16 -8[RBP]
|
||||
LEAVE
|
||||
RET
|
||||
// ************************************
|
||||
//************************************
|
||||
_FSTSW::
|
||||
XOR RAX,RAX
|
||||
FSTSW
|
||||
RET
|
||||
// ************************************
|
||||
//************************************
|
||||
_FCLEX::
|
||||
FCLEX
|
||||
RET
|
||||
// ************************************
|
||||
//************************************
|
||||
_FXSAVE::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -654,7 +654,7 @@ _FXSAVE::
|
||||
FXSAVE U64 [RAX]
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_FXRSTOR::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
|
||||
+48
-48
@@ -1,5 +1,5 @@
|
||||
F64 Clamp(F64 num,F64 lo,F64 hi)
|
||||
{
|
||||
{//Clamp to F64 [] range.
|
||||
if (num<lo)
|
||||
return lo;
|
||||
if (num>hi)
|
||||
@@ -8,7 +8,7 @@ F64 Clamp(F64 num,F64 lo,F64 hi)
|
||||
}
|
||||
|
||||
F64 Min(F64 n1,F64 n2)
|
||||
{
|
||||
{//Min of two F64s.
|
||||
if (n1<=n2)
|
||||
return n1;
|
||||
else
|
||||
@@ -16,7 +16,7 @@ F64 Min(F64 n1,F64 n2)
|
||||
}
|
||||
|
||||
F64 Max(F64 n1,F64 n2)
|
||||
{
|
||||
{//Max of two F64s.
|
||||
if (n1>=n2)
|
||||
return n1;
|
||||
else
|
||||
@@ -24,7 +24,7 @@ F64 Max(F64 n1,F64 n2)
|
||||
}
|
||||
|
||||
F64 Pow10I64(I64 i)
|
||||
{
|
||||
{//F64 integer powers of ten.
|
||||
if (i>308)
|
||||
return ì;
|
||||
else if (i<-308)
|
||||
@@ -34,23 +34,23 @@ F64 Pow10I64(I64 i)
|
||||
}
|
||||
|
||||
U64 FloorU64(U64 num,U64 to)
|
||||
{
|
||||
{//Integer multiples of num.
|
||||
return num-num%to;
|
||||
}
|
||||
|
||||
U64 CeilU64(U64 num,U64 to)
|
||||
{
|
||||
{//Integer multiples of num.
|
||||
num+=to-1;
|
||||
return num-num%to;
|
||||
}
|
||||
|
||||
I64 RoundI64(I64 num,I64 to)
|
||||
{
|
||||
{//Integer multiples of num.
|
||||
return num-num%to;
|
||||
}
|
||||
|
||||
I64 FloorI64(I64 num,I64 to)
|
||||
{
|
||||
{//Integer multiples of num.
|
||||
if (num>=0)
|
||||
return num-num%to;
|
||||
else {
|
||||
@@ -60,7 +60,7 @@ I64 FloorI64(I64 num,I64 to)
|
||||
}
|
||||
|
||||
I64 CeilI64(I64 num,I64 to)
|
||||
{
|
||||
{//Integer multiples of num.
|
||||
if (num>=0) {
|
||||
num+=to-1;
|
||||
return num-num%to;
|
||||
@@ -71,48 +71,48 @@ I64 CeilI64(I64 num,I64 to)
|
||||
}
|
||||
|
||||
//See $LK,"::/Doc/Acknowledgements.TXT"$.
|
||||
U16 RandU16()
|
||||
{
|
||||
sys_rnd_seed.i32[0]=(1664525*sys_rnd_seed.i32[0]+1013904223)^GetTSC>>4;
|
||||
return sys_rnd_seed.u16[0];
|
||||
}
|
||||
|
||||
I16 RandI16()
|
||||
{
|
||||
{//Random I16. Xor with TimsStamp.
|
||||
sys_rnd_seed.i32[0]=(1664525*sys_rnd_seed.i32[0]+1013904223)^GetTSC>>4;
|
||||
return sys_rnd_seed.i16[0];
|
||||
}
|
||||
|
||||
U32 RandU32()
|
||||
{
|
||||
U16 RandU16()
|
||||
{//Random U16. Xor with TimsStamp.
|
||||
sys_rnd_seed.i32[0]=(1664525*sys_rnd_seed.i32[0]+1013904223)^GetTSC>>4;
|
||||
return sys_rnd_seed.u32[0];
|
||||
return sys_rnd_seed.u16[0];
|
||||
}
|
||||
|
||||
I32 RandI32()
|
||||
{
|
||||
{//Random I32. Xor with TimsStamp.
|
||||
sys_rnd_seed.i32[0]=(1664525*sys_rnd_seed.i32[0]+1013904223)^GetTSC>>4;
|
||||
return sys_rnd_seed.i32[0];
|
||||
}
|
||||
|
||||
U64 RandU64()
|
||||
{
|
||||
U64 result;
|
||||
result.u32[0]=sys_rnd_seed.i32[0]=(1664525*sys_rnd_seed.i32[0]+1013904223)^GetTSC>>4;
|
||||
result.u32[1]=sys_rnd_seed.i32[0]= 1664525*sys_rnd_seed.i32[0]+1013904223;
|
||||
return result;
|
||||
U32 RandU32()
|
||||
{//Random U32. Xor with TimsStamp.
|
||||
sys_rnd_seed.i32[0]=(1664525*sys_rnd_seed.i32[0]+1013904223)^GetTSC>>4;
|
||||
return sys_rnd_seed.u32[0];
|
||||
}
|
||||
|
||||
I64 RandI64()
|
||||
{
|
||||
{//Random I64. Xor with TimsStamp.
|
||||
I64 result;
|
||||
result.u32[0]=sys_rnd_seed.i32[0]=(1664525*sys_rnd_seed.i32[0]+1013904223)^GetTSC>>4;
|
||||
result.u32[1]=sys_rnd_seed.i32[0]= 1664525*sys_rnd_seed.i32[0]+1013904223;
|
||||
return result;
|
||||
}
|
||||
|
||||
U64 RandU64()
|
||||
{//Random U64. Xor with TimsStamp.
|
||||
U64 result;
|
||||
result.u32[0]=sys_rnd_seed.i32[0]=(1664525*sys_rnd_seed.i32[0]+1013904223)^GetTSC>>4;
|
||||
result.u32[1]=sys_rnd_seed.i32[0]= 1664525*sys_rnd_seed.i32[0]+1013904223;
|
||||
return result;
|
||||
}
|
||||
|
||||
F64 Rand()
|
||||
{ //0.0<=x<1.0
|
||||
{//Random F64. Xor with TimsStamp. 0.0<=x<1.0
|
||||
I64 result;
|
||||
result.u32[0]=sys_rnd_seed.i32[0]=(1664525*sys_rnd_seed.i32[0]+1013904223)^GetTSC>>4;
|
||||
result.u32[1]=sys_rnd_seed.i32[0]= 1664525*sys_rnd_seed.i32[0]+1013904223;
|
||||
@@ -120,48 +120,48 @@ F64 Rand()
|
||||
return result/ToF64(0x4000000000000000);
|
||||
}
|
||||
|
||||
U16 Rand2U16()
|
||||
{
|
||||
Fs->rnd_seed.i32[0]=1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
return Fs->rnd_seed.u16[0];
|
||||
}
|
||||
|
||||
I16 Rand2I16()
|
||||
{
|
||||
{//Random I16. No time input.
|
||||
Fs->rnd_seed.i32[0]=1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
return Fs->rnd_seed.i16[0];
|
||||
}
|
||||
|
||||
U32 Rand2U32()
|
||||
{
|
||||
U16 Rand2U16()
|
||||
{//Random U16. No time input.
|
||||
Fs->rnd_seed.i32[0]=1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
return Fs->rnd_seed.u32[0];
|
||||
return Fs->rnd_seed.u16[0];
|
||||
}
|
||||
|
||||
I32 Rand2I32()
|
||||
{
|
||||
{//Random I32. No time input.
|
||||
Fs->rnd_seed.i32[0]=1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
return Fs->rnd_seed.i32[0];
|
||||
}
|
||||
|
||||
U64 Rand2U64()
|
||||
{
|
||||
U64 result;
|
||||
result.u32[0]=Fs->rnd_seed.i32[0]= 1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
result.u32[1]=Fs->rnd_seed.i32[0]= 1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
return result;
|
||||
U32 Rand2U32()
|
||||
{//Random U32. No time input.
|
||||
Fs->rnd_seed.i32[0]=1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
return Fs->rnd_seed.u32[0];
|
||||
}
|
||||
|
||||
I64 Rand2I64()
|
||||
{
|
||||
{//Random I64. No time input.
|
||||
I64 result;
|
||||
result.u32[0]=Fs->rnd_seed.i32[0]= 1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
result.u32[1]=Fs->rnd_seed.i32[0]= 1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
return result;
|
||||
}
|
||||
|
||||
U64 Rand2U64()
|
||||
{//Random U64. No time input.
|
||||
U64 result;
|
||||
result.u32[0]=Fs->rnd_seed.i32[0]= 1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
result.u32[1]=Fs->rnd_seed.i32[0]= 1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
return result;
|
||||
}
|
||||
|
||||
F64 Rand2()
|
||||
{ //0.0<=x<1.0
|
||||
{//Random F64. No time input. 0.0<=x<1.0
|
||||
I64 result;
|
||||
result.u32[0]=Fs->rnd_seed.i32[0]= 1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
result.u32[1]=Fs->rnd_seed.i32[0]= 1664525*Fs->rnd_seed.i32[0]+1013904223;
|
||||
@@ -170,7 +170,7 @@ F64 Rand2()
|
||||
}
|
||||
|
||||
U0 Randomize(I64 seed=0)
|
||||
{ //Randomizes seed.
|
||||
{//Randomizes $LK,"CTask",A="MN:CTask"$ seed.
|
||||
if (seed)
|
||||
Fs->rnd_seed=seed;
|
||||
else
|
||||
|
||||
+43
-55
@@ -1,7 +1,6 @@
|
||||
asm {
|
||||
/*
|
||||
See $LK,"::/Doc/Acknowledgements.TXT"$.
|
||||
See $LK,"::/Doc/Mem.TXT"$
|
||||
/*See $LK,"::/Doc/Acknowledgements.TXT"$.
|
||||
See $LK,"::/Doc/MemOverview.TXT"$
|
||||
*/
|
||||
|
||||
USE32
|
||||
@@ -25,8 +24,7 @@ SYS_INIT_MEM::
|
||||
ADC EDX,0
|
||||
LOOP @@05
|
||||
|
||||
//video ram=write through
|
||||
//0xA0000-0xBFFFF
|
||||
//0xA0000-0xBFFFF: video ram=write through
|
||||
MOV EAX,0xF
|
||||
XOR EDX,EDX
|
||||
MOV EDI,SYS_FIXED_AREA+CSysFixedArea.pml1+0xA0*8
|
||||
@@ -62,8 +60,7 @@ SYS_INIT_MEM::
|
||||
ADC EDX,0
|
||||
LOOP @@20
|
||||
|
||||
//PCI Devs
|
||||
//0xE0000000-0xFFFFFFFF
|
||||
//0xE0000000-0xFFFFFFFF: PCI Devs
|
||||
MOV EAX,0x17 //Cache disabled
|
||||
XOR EDX,EDX
|
||||
MOV EDI,SYS_FIXED_AREA+CSysFixedArea.pml2+8*0x700
|
||||
@@ -164,7 +161,7 @@ U0 SysBadMAlloc(I64 *ptr)
|
||||
}
|
||||
|
||||
I64 MemPageSize(U8 *a)
|
||||
{
|
||||
{//Size of page table at addr. Either 4K or 2Meg.
|
||||
if (a<MEM_NUM_PML1*0x1000*0x200)
|
||||
return 0x1000;
|
||||
else
|
||||
@@ -172,7 +169,7 @@ I64 MemPageSize(U8 *a)
|
||||
}
|
||||
|
||||
I64 *MemPageTable(U8 *a)
|
||||
{
|
||||
{//Point to page table entry for addr.
|
||||
if (a<MEM_NUM_PML1*0x1000*0x200)
|
||||
return SYS_FIXED_AREA+offset(CSysFixedArea.pml1)+a>>12*8;
|
||||
else
|
||||
@@ -180,7 +177,7 @@ I64 *MemPageTable(U8 *a)
|
||||
}
|
||||
|
||||
Bool MemPagePresentMark(U8 *a,Bool val)
|
||||
{
|
||||
{//Mark an addr's page present or not-present.
|
||||
I64 *pte=MemPageTable(a);
|
||||
Bool result=*pte&1;
|
||||
if (val)
|
||||
@@ -191,17 +188,14 @@ Bool MemPagePresentMark(U8 *a,Bool val)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
U8 *MemBlksIndependentAlloc(I64 *_pages512,CBlkPool *bp=NULL)
|
||||
//This will allocate a 512 byte pages from
|
||||
//and not link them to any task. (Linking to a task
|
||||
//means it will be freed when the task
|
||||
//dies.)
|
||||
//It might give you more than you asked for
|
||||
//so a ptr to a page count is passed.
|
||||
//
|
||||
//Returns NULL if out of memory
|
||||
{
|
||||
{/*Alloc 512Byte pages from bp. Don't link to task.
|
||||
(Linking to a task means it will be freed when the task dies.)
|
||||
It might give you more than you asked for
|
||||
so a ptr to a page count is passed.
|
||||
|
||||
Return: NULL if out of memory.
|
||||
*/
|
||||
CMemBlk *result=NULL,*m;
|
||||
I64 i,num=*_pages512;
|
||||
if (!bp) bp=sys_code_bp;
|
||||
@@ -268,7 +262,7 @@ at_done:
|
||||
}
|
||||
|
||||
U0 MemBlksNonTaskFree(CMemBlk *m,I64 pages512,CBlkPool *bp=NULL)
|
||||
{
|
||||
{//Return nontask 512Byte pages(s) to bp.
|
||||
I64 i;
|
||||
if (m) {
|
||||
if (!bp) bp=sys_code_bp;
|
||||
@@ -299,15 +293,13 @@ U0 MemBlksNonTaskFree(CMemBlk *m,I64 pages512,CBlkPool *bp=NULL)
|
||||
}
|
||||
|
||||
U8 *MemBlks2MegAlloc(I64 *_pages2Meg,CBlkPool *bp=NULL)
|
||||
//This will allocate 2Meg pages and not
|
||||
//link it to any task. (Linking to a task
|
||||
//means they will be freed when the task
|
||||
//dies.)
|
||||
//It might give you more than you asked for
|
||||
//so a ptr to a page count is passed.
|
||||
//
|
||||
//Returns NULL if out of memory
|
||||
{
|
||||
{/*Alloc 2Meg pages from bp. Don't link to task.
|
||||
(Linking to a task means they will be freed when the task dies.)
|
||||
It might give you more than you asked for
|
||||
so a ptr to a page count is passed.
|
||||
|
||||
Return: NULL if out of memory.
|
||||
*/
|
||||
I64 i,j,*pte,num=*_pages2Meg;
|
||||
CMemBlk *result=NULL,*m,*m1;
|
||||
|
||||
@@ -406,15 +398,13 @@ am_done:
|
||||
}
|
||||
|
||||
U8 *MemBlksUncachedAlloc(I64 *_pages2Meg,CBlkPool *bp=NULL)
|
||||
//This will allocate 2Meg pages from
|
||||
//and not link them to any task. (Linking to a task
|
||||
//means it will be freed when the task
|
||||
//dies.) It will be marked uncached.
|
||||
//It might give you more than you asked for
|
||||
//so a ptr to a page count is passed.
|
||||
//
|
||||
//Returns NULL if out of memory
|
||||
{
|
||||
{/*Alloc 2Meg pages from bp. Don't link to task.
|
||||
(Linking to a task means it will be freed when the task dies.)
|
||||
It will be marked uncached. It might give you more than you asked for
|
||||
so a ptr to a page count is passed.
|
||||
|
||||
Return: NULL if out of memory.
|
||||
*/
|
||||
CMemBlk *result,*m,*m1;
|
||||
I64 num=*_pages2Meg,*pte;
|
||||
if (result=MemBlks2MegAlloc(_pages2Meg,bp)) {
|
||||
@@ -432,15 +422,13 @@ U8 *MemBlksUncachedAlloc(I64 *_pages2Meg,CBlkPool *bp=NULL)
|
||||
}
|
||||
|
||||
U8 *MemBlksWriteThroughAlloc(I64 *_pages2Meg,CBlkPool *bp=NULL)
|
||||
//This will allocate 2Meg pages from
|
||||
//and not link them to any task. (Linking to a task
|
||||
//means they will be freed when the task
|
||||
//dies.) It will be marked write-through.
|
||||
//It might give you more than you asked for
|
||||
//so a ptr to a page count is passed.
|
||||
//
|
||||
//Returns NULL if out of memory
|
||||
{
|
||||
{/*Alloc 2Meg pages from bp. Don't link to task.
|
||||
(Linking to a task means they will be freed when the task dies.)
|
||||
It will be marked write-through. It might give you more than you asked for
|
||||
so a ptr to a page count is passed.
|
||||
|
||||
Return: NULL if out of memory.
|
||||
*/
|
||||
CMemBlk *result,*m,*m1;
|
||||
I64 num=*_pages2Meg,*pte;
|
||||
if (result=MemBlks2MegAlloc(_pages2Meg,bp)) {
|
||||
@@ -458,7 +446,7 @@ U8 *MemBlksWriteThroughAlloc(I64 *_pages2Meg,CBlkPool *bp=NULL)
|
||||
}
|
||||
|
||||
U0 MemBlks2MegFree(CMemBlk *m,I64 pages2Meg,CBlkPool *bp=NULL)
|
||||
{
|
||||
{//Return 2Meg page(s) to bp.
|
||||
I64 *pte;
|
||||
CMemBlk *m1,*m2;
|
||||
if (m) {
|
||||
@@ -486,11 +474,11 @@ U0 MemBlks2MegFree(CMemBlk *m,I64 pages2Meg,CBlkPool *bp=NULL)
|
||||
}
|
||||
|
||||
CMemBlk *MemBlksAlloc(I64 *_pages512,CHeapCtrl *hc)
|
||||
{
|
||||
//hc must be locked. Interrupts should probably be off
|
||||
//Currently, this is only called from $LK,"MAlloc",A="MN:MAlloc"$().
|
||||
//
|
||||
//Returns NULL if out of memory
|
||||
{/*hc must be locked. Interrupts should probably be off
|
||||
Currently, this is only called from $LK,"MAlloc",A="MN:MAlloc"$().
|
||||
|
||||
Return: NULL if out of memory.
|
||||
*/
|
||||
CMemBlk *result;
|
||||
I64 threshold,cnt,size;
|
||||
CMemUnusedAllocated *uum,**_uum,**_ptr;
|
||||
@@ -525,7 +513,7 @@ CMemBlk *MemBlksAlloc(I64 *_pages512,CHeapCtrl *hc)
|
||||
}
|
||||
|
||||
U0 MemBlksFree(CMemBlk *m,CHeapCtrl *hc)
|
||||
{ //hc must be locked
|
||||
{//hc must be locked
|
||||
if (m) {
|
||||
PUSHFD
|
||||
CLI
|
||||
|
||||
+18
-20
@@ -1,8 +1,8 @@
|
||||
asm {
|
||||
USE64
|
||||
// ************************************
|
||||
// Throws 'OutMem'
|
||||
//************************************
|
||||
_MALLOC::
|
||||
// Throws 'OutMem'
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
PUSH RSI
|
||||
@@ -130,7 +130,6 @@ _MALLOC::
|
||||
|
||||
@@70: ADD RSI,U64 CMemUnusedAllocated.size[RSI]
|
||||
|
||||
|
||||
MALLOC_ALMOST_DONE:
|
||||
//RSI=result-CMemUsedAllocated.size
|
||||
//RAX=size+CMemUsedAllocated.size
|
||||
@@ -206,7 +205,7 @@ MALLOC_FINAL_EXIT:
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
//************************************
|
||||
_FREE::
|
||||
//Be aware of $LK,"heap_hash",A="FF:::/Kernel/Mem1b.CPP,heap_hash"$ in $LK,"MemBlksAlloc",A="MN:MemBlksAlloc"$().
|
||||
PUSH RBP
|
||||
@@ -319,7 +318,7 @@ FREE_DONE:
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_MSIZE::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -335,7 +334,7 @@ _MSIZE::
|
||||
@@05: SUB RAX,CMemUsedAllocated.start
|
||||
@@10: POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_MSIZE2::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -350,7 +349,7 @@ _MSIZE2::
|
||||
@@05: MOV RAX,U64 CMemUsedAllocated.size-CMemUsedAllocated.start[RBX]
|
||||
@@10: POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
//************************************
|
||||
_MHEAP_CTRL::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -367,16 +366,15 @@ _MHEAP_CTRL::
|
||||
RET1 8
|
||||
}
|
||||
|
||||
_extern _FREE U0 Free(U8 *addr);
|
||||
_extern _MSIZE I64 MSize(U8 *src); //size of heap object
|
||||
_extern _MSIZE2 I64 MSize2(U8 *src); //Internal size
|
||||
_extern _MHEAP_CTRL CHeapCtrl *MHeapCtrl(U8 *src); //$LK,"CHeapCtrl",A="MN:CHeapCtrl"$ of object
|
||||
|
||||
//Accepts a $LK,"CTask",A="MN:CTask"$ or $LK,"CHeapCtrl",A="MN:CHeapCtrl"$. NULL allocs off current task's heap.
|
||||
_extern _MALLOC U8 *MAlloc(I64 size,CTask *mem_task=NULL);
|
||||
_extern _FREE U0 Free(U8 *addr); //Free $LK,"MAlloc",A="MN:MAlloc"$()ed memory chunk.
|
||||
_extern _MSIZE I64 MSize(U8 *src); //Size of heap object.
|
||||
_extern _MSIZE2 I64 MSize2(U8 *src); //Internal size of heap object.
|
||||
_extern _MHEAP_CTRL CHeapCtrl *MHeapCtrl(U8 *src); //$LK,"CHeapCtrl",A="MN:CHeapCtrl"$ of object.
|
||||
_extern _MALLOC U8 *MAlloc(I64 size,CTask *mem_task=NULL); //Allocate memory chunk.
|
||||
//Accepts a $LK,"CTask",A="MN:CTask"$ or $LK,"CHeapCtrl",A="MN:CHeapCtrl"$. NULL allocs off current task's heap.
|
||||
|
||||
U8 *AMAlloc(I64 size)
|
||||
{
|
||||
{//Allocate memory in Adam's heap.
|
||||
return MAlloc(size,adam_task);
|
||||
}
|
||||
|
||||
@@ -388,7 +386,7 @@ U8 *CAlloc(I64 size,CTask *mem_task=NULL)
|
||||
}
|
||||
|
||||
U8 *ACAlloc(I64 size)
|
||||
{
|
||||
{//Allocate and set to zero memory in Adam's heap.
|
||||
return CAlloc(size,adam_task);
|
||||
}
|
||||
|
||||
@@ -404,12 +402,12 @@ U8 *MAllocIdentical(U8 *src,CTask *mem_task=NULL)
|
||||
}
|
||||
|
||||
U8 *AMAllocIdentical(U8 *src)
|
||||
{
|
||||
{//Allocate in Adam's heap, identical copy of heap node.
|
||||
return MAllocIdentical(src,adam_task);
|
||||
}
|
||||
|
||||
U8 *MAllocAligned(I64 size,I64 alignment,CTask *mem_task=NULL,I64 misalignment=0)
|
||||
{ //only powers of two alignment. This is awful.
|
||||
{//Only powers of two alignment. This is awful.
|
||||
I64 mask=alignment-1;
|
||||
U8 *ptr=MAlloc(size+mask+sizeof(I64)+misalignment,mem_task),
|
||||
*result=(ptr+sizeof(I64)+mask)&~mask+misalignment;
|
||||
@@ -419,7 +417,7 @@ U8 *MAllocAligned(I64 size,I64 alignment,CTask *mem_task=NULL,I64 misalignment=0
|
||||
}
|
||||
|
||||
U8 *CAllocAligned(I64 size,I64 alignment,CTask *mem_task=NULL,I64 misalignment=0)
|
||||
{ //only powers of two alignment. This is awful.
|
||||
{//Only powers of two alignment. This is awful.
|
||||
I64 mask=alignment-1;
|
||||
U8 *ptr=MAlloc(size+mask+sizeof(I64)+misalignment,mem_task),
|
||||
*result=(ptr+sizeof(I64)+mask)&~mask+misalignment;
|
||||
@@ -445,6 +443,6 @@ U8 *StrNew(U8 *buf,CTask *mem_task=NULL)
|
||||
}
|
||||
|
||||
U8 *AStrNew(U8 *buf)
|
||||
{
|
||||
{//Allocate copy of string in Adam's heap.
|
||||
return StrNew(buf,adam_task);
|
||||
}
|
||||
+31
-29
@@ -1,5 +1,5 @@
|
||||
U0 BlkPoolAdd(CBlkPool *bp,CMemBlk *m,I64 pages512)
|
||||
{
|
||||
{//Add memory to blk pool.
|
||||
if (sys_mem_init_flag)
|
||||
MemSet(m,sys_mem_init_val,pages512*512);
|
||||
PUSHFD
|
||||
@@ -16,19 +16,18 @@ U0 BlkPoolAdd(CBlkPool *bp,CMemBlk *m,I64 pages512)
|
||||
}
|
||||
|
||||
U0 BlkPoolInit(CBlkPool *bp,I64 pages512)
|
||||
{
|
||||
{//Make memory chunk into a blk pool.
|
||||
I64 num;
|
||||
CMemBlk *m;
|
||||
MemSet(bp,0,sizeof(CBlkPool));
|
||||
m=(bp(U8 *)+sizeof(CBlkPool)+PAGE_SIZE-1)&~(PAGE_SIZE-1);
|
||||
num=(bp(U8 *)+pages512<<PAGE_BITS-m(U8 *))>>PAGE_BITS;
|
||||
bp->size=pages512-num; //compensate before num added.
|
||||
bp->size=pages512-num; //Compensate before num added.
|
||||
BlkPoolAdd(bp,m,num);
|
||||
}
|
||||
|
||||
CHeapCtrl *HeapCtrlInit(CHeapCtrl *hc=NULL,CTask *task=NULL,CBlkPool *bp)
|
||||
{
|
||||
//$LK,"Adam Task",A="FF:::/Kernel/KStart.CPP,CHeapCtrl.bp"$
|
||||
{//Called by $LK,"Adam Task",A="FF:::/Kernel/KStart.CPP,CHeapCtrl.bp"$.
|
||||
if (!hc)
|
||||
hc=ACAlloc(sizeof(CHeapCtrl));
|
||||
hc->hc_signature=HEAP_CTRL_SIGNATURE_VAL;
|
||||
@@ -40,7 +39,7 @@ CHeapCtrl *HeapCtrlInit(CHeapCtrl *hc=NULL,CTask *task=NULL,CBlkPool *bp)
|
||||
}
|
||||
|
||||
CHeapCtrl *HeapCtrlBPInit(CBlkPool *bp,I64 pages512)
|
||||
{
|
||||
{//Make memory chunk into heap ctrl and blk pool.
|
||||
I64 num;
|
||||
CMemBlk *m;
|
||||
CHeapCtrl *hc;
|
||||
@@ -54,7 +53,7 @@ CHeapCtrl *HeapCtrlBPInit(CBlkPool *bp,I64 pages512)
|
||||
}
|
||||
|
||||
U0 HeapCtrlDel(CHeapCtrl *hc)
|
||||
{
|
||||
{//Free all blks alloced to a heap ctrl.
|
||||
CMemBlk *m,*m1;
|
||||
if (hc) {
|
||||
PUSHFD
|
||||
@@ -75,8 +74,8 @@ U0 HeapCtrlDel(CHeapCtrl *hc)
|
||||
|
||||
Bool Mem32DevIns(CMemRange *tempmr)
|
||||
{
|
||||
CMemRange *tempmr1=sys_mem32_dev_root.next,*tempmr2;
|
||||
while (tempmr1!=&sys_mem32_dev_root) {
|
||||
CMemRange *tempmr1=dev.mem32_root.next,*tempmr2;
|
||||
while (tempmr1!=&dev.mem32_root) {
|
||||
if (!tempmr1->type && tempmr->base>=tempmr1->base &&
|
||||
tempmr->base+tempmr->size<=tempmr1->base+tempmr1->size) {
|
||||
if (tempmr->base>tempmr1->base) {
|
||||
@@ -107,14 +106,14 @@ U0 Mem32DevInit()
|
||||
CMemRange *tempmr;
|
||||
CMemE820 *m20=SYS_MEM_E820;
|
||||
|
||||
QueInit(&sys_mem32_dev_root);
|
||||
QueInit(&dev.mem32_root);
|
||||
tempmr=AMAlloc(sizeof(CMemRange));
|
||||
tempmr->type=MRT_UNUSED;
|
||||
tempmr->flags=0;
|
||||
//Maybe !!! Change this to 0xE0000000 !!!
|
||||
tempmr->base=0xF0000000;
|
||||
tempmr->size=0x10000000;
|
||||
QueIns(tempmr,sys_mem32_dev_root.last);
|
||||
QueIns(tempmr,dev.mem32_root.last);
|
||||
|
||||
if (m20->type) {
|
||||
while (m20->type) {
|
||||
@@ -131,7 +130,8 @@ U0 Mem32DevInit()
|
||||
}
|
||||
|
||||
Bool MemLowPagesProtect(Bool val=TRUE)
|
||||
{ //FALSE if any were not protected
|
||||
{//Mark low memory not present. Catch NULL deref.
|
||||
//Returns: FALSE if any were not protected.
|
||||
U8 *a=0;
|
||||
Bool result=TRUE;
|
||||
while (a<=MEM_PROTECTED_LOW_LIMIT) {
|
||||
@@ -163,13 +163,15 @@ U0 MemPagesNotPresentMark()
|
||||
}
|
||||
|
||||
U8 *Mem32DevAlloc(I64 size,I64 alignment)
|
||||
{//This doesn't work
|
||||
{//Alloc 32-bit addr space for device. (Doesn't work.) Not used.
|
||||
//For this to work the BIOS E820 map must be searched for gaps in
|
||||
//the 32-bit range and the pool initialized to the gaps.
|
||||
U8 *base,*limit;
|
||||
CMemRange *tempmr,*tempmr1;
|
||||
while (LBts(&sys_semas[SYS_SEMA_DEV_MEM],0))
|
||||
Yield;
|
||||
tempmr1=sys_mem32_dev_root.next;
|
||||
while (tempmr1!=&sys_mem32_dev_root) {
|
||||
tempmr1=dev.mem32_root.next;
|
||||
while (tempmr1!=&dev.mem32_root) {
|
||||
base=(tempmr1->base+alignment-1)&~(alignment-1);
|
||||
limit=base+size-1;
|
||||
if (!tempmr1->type &&
|
||||
@@ -194,13 +196,13 @@ U8 *Mem32DevAlloc(I64 size,I64 alignment)
|
||||
}
|
||||
|
||||
U0 Mem32DevFree(U8 *base)
|
||||
{
|
||||
{//Free 32-bit device address space.
|
||||
CMemRange *tempmr;
|
||||
if (!base) return;
|
||||
while (LBts(&sys_semas[SYS_SEMA_DEV_MEM],0))
|
||||
Yield;
|
||||
tempmr=sys_mem32_dev_root.next;
|
||||
while (tempmr!=&sys_mem32_dev_root) {
|
||||
tempmr=dev.mem32_root.next;
|
||||
while (tempmr!=&dev.mem32_root) {
|
||||
if (tempmr->base==base) {
|
||||
tempmr->type=MRT_UNUSED;
|
||||
break;
|
||||
@@ -211,29 +213,29 @@ U0 Mem32DevFree(U8 *base)
|
||||
}
|
||||
|
||||
U8 *Mem64DevAlloc(I64 *_pages2Meg)
|
||||
{
|
||||
{//Alloc 64-bit addr space for device.
|
||||
U8 *result;
|
||||
I64 i=*_pages2Meg,*pte;
|
||||
while (LBts(&sys_semas[SYS_SEMA_DEV_MEM],0))
|
||||
Yield;
|
||||
while (i--) {
|
||||
sys_mem64_dev_ptr-=0x200000;
|
||||
pte=MemPageTable(sys_mem64_dev_ptr);
|
||||
dev.mem64_ptr-=0x200000;
|
||||
pte=MemPageTable(dev.mem64_ptr);
|
||||
*pte=*pte&~0x18 |0x11; //Uncached and present
|
||||
InvlPg(sys_mem64_dev_ptr);
|
||||
InvlPg(dev.mem64_ptr);
|
||||
}
|
||||
result=sys_mem64_dev_ptr;
|
||||
result=dev.mem64_ptr;
|
||||
LBtr(&sys_semas[SYS_SEMA_DEV_MEM],0);
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 Mem64DevFree(U8 *base,I64 pages2Meg)
|
||||
{
|
||||
{//Free 64-bit device address space.
|
||||
if (!base) return;
|
||||
while (LBts(&sys_semas[SYS_SEMA_DEV_MEM],0))
|
||||
Yield;
|
||||
if (base==sys_mem64_dev_ptr)
|
||||
sys_mem64_dev_ptr+=pages2Meg*0x200000;
|
||||
if (base==dev.mem64_ptr)
|
||||
dev.mem64_ptr+=pages2Meg*0x200000;
|
||||
//else not freed
|
||||
LBtr(&sys_semas[SYS_SEMA_DEV_MEM],0);
|
||||
}
|
||||
@@ -302,9 +304,9 @@ U0 HeapsInit()
|
||||
}
|
||||
|
||||
I64 Scale2Mem(I64 min,I64 max,I64 limit=2*1024*1024*1024)
|
||||
//This function is nice for scaling-back allocations if less than 2048 Meg.
|
||||
//Disk cache and RAM Drive expressions can include this function.
|
||||
{
|
||||
{//Helps pick DiskCache and RAMDisk sizes.
|
||||
//Can be used in $LK,"MakeOSPrtBootInstall",A="MN:MakeOSPrtBootInstall"$() config scripts.
|
||||
//Scale-back allocations if less than 2048 Meg.
|
||||
I64 i=sys_code_bp->size<<PAGE_BITS;
|
||||
if (i>=limit)
|
||||
return max;
|
||||
|
||||
+69
-69
@@ -1,13 +1,11 @@
|
||||
U0 PortNop()
|
||||
{
|
||||
InU8(0x21); //This is an innoculous (reads IRQ Mask)
|
||||
//access which should take
|
||||
//fixed time because it's an ISA-bus standard.
|
||||
//It takes 1.0uS-2.0uS
|
||||
{//Innoculous (reads IRQ Mask) which should take fixed time
|
||||
//because it's an ISA-bus standard. It takes 1.0uS-2.0uS.
|
||||
InU8(0x21);
|
||||
}
|
||||
|
||||
U16 EndianU16(U16 d)
|
||||
{
|
||||
{//Swap big<-->little endian.
|
||||
I64 result=0;
|
||||
result.u8[1]=d.u8[0];
|
||||
result.u8[0]=d.u8[1];
|
||||
@@ -15,7 +13,7 @@ U16 EndianU16(U16 d)
|
||||
}
|
||||
|
||||
U32 EndianU32(U32 d)
|
||||
{
|
||||
{//Swap big<-->little endian.
|
||||
I64 result=0;
|
||||
result.u8[3]=d.u8[0];
|
||||
result.u8[2]=d.u8[1];
|
||||
@@ -24,8 +22,8 @@ U32 EndianU32(U32 d)
|
||||
return result;
|
||||
}
|
||||
|
||||
U64 EndianU64(U64 d)
|
||||
{
|
||||
I64 EndianI64(I64 d)
|
||||
{//Swap big<-->little endian.
|
||||
U64 result;
|
||||
result.u8[7]=d.u8[0];
|
||||
result.u8[6]=d.u8[1];
|
||||
@@ -39,28 +37,29 @@ U64 EndianU64(U64 d)
|
||||
}
|
||||
|
||||
I64 BCnt(I64 d)
|
||||
{
|
||||
{//Count set bits in I64.
|
||||
I64 result=0,i;
|
||||
for (i=0;i<8;i++)
|
||||
result+=set_bits_table[d.u8[i]];
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 IntSimpleTimer(CTask *)
|
||||
{
|
||||
U0 IntCore0TimerHandler(CTask *)
|
||||
{//Called from $LK,"IntCore0TimerHandler",A="FF:::/Kernel/Ints.CPP,IntCore0TimerHandler"$
|
||||
I64 i;
|
||||
if (mp_cnt>1)
|
||||
while (LBts(&sys_semas[SYS_SEMA_SYS_TIMER],0))
|
||||
PAUSE
|
||||
lock sys_jiffies++;
|
||||
sys_timer+=SYS_TIMER0_PERIOD+1;
|
||||
lock cnts.jiffies++;
|
||||
cnts.timer+=SYS_TIMER0_PERIOD+1;
|
||||
LBtr(&sys_semas[SYS_SEMA_SYS_TIMER],0);
|
||||
for (i=1;i<mp_cnt;i++)
|
||||
MPInt(I_TIMER,i);
|
||||
OutU8(0x20,0x20); //Acknowledge PIC Interrupt
|
||||
}
|
||||
|
||||
I64 SysTimerRead()
|
||||
{
|
||||
{//System timer count with overflow already handled.
|
||||
I64 i,result;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -72,14 +71,14 @@ I64 SysTimerRead()
|
||||
if (InU8(0x20) & 1)
|
||||
i=-1;
|
||||
}
|
||||
result=sys_timer+SYS_TIMER0_PERIOD-i;
|
||||
result=cnts.timer+SYS_TIMER0_PERIOD-i;
|
||||
LBtr(&sys_semas[SYS_SEMA_SYS_TIMER],0);
|
||||
POPFD
|
||||
return result;
|
||||
}
|
||||
|
||||
I64 TaskTotalTime()
|
||||
{
|
||||
{//Total CPU cycles given to current task.
|
||||
return GetTSC-Fs->time_slice_start+Fs->total_time;
|
||||
}
|
||||
|
||||
@@ -91,22 +90,24 @@ I64 TimeStampFreqCal()
|
||||
PUSHFD
|
||||
CLI
|
||||
if (HPET_start) {
|
||||
time_stamp_freq=HPET_freq*(GetTSC-time_stamp_start);
|
||||
cnts.time_stamp_freq=cnts.HPET_freq*(GetTSC-time_stamp_start);
|
||||
i=HPET-HPET_start;
|
||||
} else {
|
||||
time_stamp_freq=SYS_TIMER_FREQ*(GetTSC-time_stamp_start);
|
||||
cnts.time_stamp_freq=SYS_TIMER_FREQ*(GetTSC-time_stamp_start);
|
||||
i=SysTimerRead-timer_start;
|
||||
}
|
||||
if (!i)
|
||||
Dbg("Timer Cal Error");
|
||||
time_stamp_freq/=i;
|
||||
time_stamp_kHz_freq=time_stamp_freq/1000;
|
||||
AdamErr("Timer Cal Error");
|
||||
else {
|
||||
cnts.time_stamp_freq/=i;
|
||||
cnts.time_stamp_kHz_freq=cnts.time_stamp_freq/1000;
|
||||
cnts.time_stamp_calibrated=TRUE;
|
||||
}
|
||||
POPFD
|
||||
time_stamp_freq_calibrated=TRUE;
|
||||
}
|
||||
PUSHFD
|
||||
CLI
|
||||
if (HPET_freq) {
|
||||
if (cnts.HPET_freq) {
|
||||
timer_start=0;
|
||||
HPET_start=HPET;
|
||||
} else {
|
||||
@@ -115,36 +116,32 @@ I64 TimeStampFreqCal()
|
||||
}
|
||||
time_stamp_start=GetTSC;
|
||||
POPFD
|
||||
return time_stamp_freq;
|
||||
return cnts.time_stamp_freq;
|
||||
}
|
||||
|
||||
F64 tS()
|
||||
//Time since boot in seconds as a float
|
||||
{ //This is slow, but accurate even if no HPET.
|
||||
if (HPET_freq)
|
||||
return ToF64(HPET-HPET_initial)/HPET_freq;
|
||||
{//Time since boot in seconds as a float.
|
||||
if (cnts.HPET_freq)
|
||||
return ToF64(HPET-cnts.HPET_initial)/cnts.HPET_freq;
|
||||
else
|
||||
return SysTimerRead/ToF64(SYS_TIMER_FREQ);
|
||||
}
|
||||
|
||||
Bool Blink(F64 Hz=2.5)
|
||||
{
|
||||
{//Return TRUE, then FALSE, then TRUE at given frequency.
|
||||
if (!Hz) return 0;
|
||||
return ToI64(sys_jiffies*2*Hz/JIFFY_FREQ)&1;
|
||||
return ToI64(cnts.jiffies*2*Hz/JIFFY_FREQ)&1;
|
||||
}
|
||||
|
||||
U0 BusyWait(I64 æS) //Loosely timed
|
||||
{
|
||||
U0 BusyWait(I64 æS)
|
||||
{//Loosely timed.
|
||||
I64 i;
|
||||
for (i=0;i<æS;i++)
|
||||
PortNop;
|
||||
}
|
||||
|
||||
U0 SleepUntil(I64 wake_jiffy)
|
||||
//This routine is not for power-saving
|
||||
//it is to make a program pause without
|
||||
//hogging the CCPU.
|
||||
{
|
||||
{//Not for power-saving. It is to make a program pause without hogging the CPU.
|
||||
Bool old_idle=LBts(&Fs->task_flags,TASKf_IDLE);
|
||||
Fs->wake_jiffy=wake_jiffy;
|
||||
Yield;
|
||||
@@ -152,24 +149,21 @@ U0 SleepUntil(I64 wake_jiffy)
|
||||
}
|
||||
|
||||
U0 Sleep(I64 mS)
|
||||
//This routine is not for power-saving
|
||||
//it is to make a program pause without
|
||||
//hogging the CCPU.
|
||||
{
|
||||
{//Not for power-saving. It is to make a program pause without hogging the CPU.
|
||||
if (!mS)
|
||||
Yield;
|
||||
else
|
||||
SleepUntil(sys_jiffies+mS*JIFFY_FREQ/1000);
|
||||
SleepUntil(cnts.jiffies+mS*JIFFY_FREQ/1000);
|
||||
}
|
||||
|
||||
U0 Snd(F64 freq)
|
||||
{
|
||||
{//Play freq. Zero means off.
|
||||
I64 p;
|
||||
CSndData *d;
|
||||
if (!Bt(&sys_semas[SYS_SEMA_MUTE],0) &&
|
||||
!LBts(&sys_semas[SYS_SEMA_SND],0)) {
|
||||
if (freq!=snd_freq) {
|
||||
snd_freq=freq;
|
||||
if (freq!=snd.freq) {
|
||||
snd.freq=freq;
|
||||
if (0<freq<=20000) {
|
||||
p=SYS_TIMER_FREQ/freq;
|
||||
OutU8(0x43,0xB6);
|
||||
@@ -179,18 +173,18 @@ U0 Snd(F64 freq)
|
||||
} else
|
||||
OutU8(0x61,InU8(0x61)&~3);
|
||||
}
|
||||
if (!IsDbg && snd_record) {
|
||||
if (!IsDbg && snd.record) {
|
||||
d=ACAlloc(sizeof(CSndData));
|
||||
d->freq=freq;
|
||||
d->time_stamp=tS;
|
||||
QueIns(d,snd_record_root.last);
|
||||
d->time=tS;
|
||||
QueIns(d,snd.record_root.last);
|
||||
}
|
||||
LBtr(&sys_semas[SYS_SEMA_SND],0);
|
||||
}
|
||||
}
|
||||
|
||||
U0 Beep(I64 freq=500,Bool busy=FALSE)
|
||||
{
|
||||
{//Make beep at given freq.
|
||||
Snd(freq);
|
||||
if (busy)
|
||||
BusyWait(500000);
|
||||
@@ -204,7 +198,7 @@ U0 Beep(I64 freq=500,Bool busy=FALSE)
|
||||
}
|
||||
|
||||
Bool Mute(Bool val)
|
||||
{
|
||||
{//Turn-off or on sound.
|
||||
Bool result;
|
||||
if (val) {
|
||||
PUSHFD
|
||||
@@ -217,59 +211,65 @@ Bool Mute(Bool val)
|
||||
return result;
|
||||
}
|
||||
|
||||
Bool IsMute() {
|
||||
Bool IsMute()
|
||||
{//Return is-mute flag.
|
||||
return Bt(&sys_semas[SYS_SEMA_MUTE],0);
|
||||
}
|
||||
|
||||
Bool Silent(Bool val) {
|
||||
//This turns-off console output, not sound.
|
||||
Bool Silent(Bool val)
|
||||
{//Turns-off StdOut console text output, not sound.
|
||||
return LBEqu(&Fs->display_flags,DISPLAYf_SILENT,val);
|
||||
}
|
||||
|
||||
Bool IsSilent() {
|
||||
Bool IsSilent()
|
||||
{//Is StdOut turned-off?
|
||||
return Bt(&Fs->display_flags,DISPLAYf_SILENT);
|
||||
}
|
||||
|
||||
Bool IsPreempt() {
|
||||
Bool IsPreempt()
|
||||
{
|
||||
return Bt(&Fs->task_flags,TASKf_PREEMPT);
|
||||
}
|
||||
|
||||
Bool SysDbg(Bool val) {
|
||||
//Sets or rsts a bit which you can
|
||||
//use while debugging.
|
||||
Bool SysDbg(Bool val)
|
||||
{//Sets or resets sysdbg bit you can use while debugging.
|
||||
return LBEqu(&sys_semas[SYS_SEMA_DEBUG],0,val);
|
||||
}
|
||||
|
||||
Bool IsSysDbg() {
|
||||
Bool IsSysDbg()
|
||||
{//Is sysdbg bit set?
|
||||
return Bt(&sys_semas[SYS_SEMA_DEBUG],0);
|
||||
}
|
||||
|
||||
Bool Raw(Bool val) {
|
||||
//Switches to direct screen output
|
||||
//mode for when you don't have
|
||||
//a working window.
|
||||
Bool Raw(Bool val)
|
||||
{//Switches to direct screen, non-windowed output.
|
||||
if (!val)
|
||||
VGAFlush;
|
||||
return !LBEqu(&Fs->task_flags,TASKf_NOT_RAW,!val);
|
||||
}
|
||||
|
||||
Bool IsRaw() {
|
||||
Bool IsRaw()
|
||||
{//Are we in BLACK & WHITE raw screen mode?
|
||||
return !Bt(&Fs->task_flags,TASKf_NOT_RAW);
|
||||
}
|
||||
|
||||
Bool SingleUser(Bool val) {
|
||||
Bool SingleUser(Bool val)
|
||||
{//Sets or resets single-user mode bit.
|
||||
return LBEqu(&sys_semas[SYS_SEMA_SINGLE_USER],0,val);
|
||||
}
|
||||
|
||||
Bool IsSingleUser() {
|
||||
Bool IsSingleUser()
|
||||
{//Are we in single-user mode?
|
||||
return Bt(&sys_semas[SYS_SEMA_SINGLE_USER],0);
|
||||
}
|
||||
|
||||
Bool InDbg(Bool val) {
|
||||
Bool InDbg(Bool val)
|
||||
{//Set in-debugger flag.
|
||||
return LBEqu(&sys_semas[SYS_SEMA_IN_DEBUGGER],0,val);
|
||||
}
|
||||
|
||||
Bool IsDbg() {
|
||||
Bool IsDbg()
|
||||
{//Return in-debugger flag.
|
||||
return Bt(&sys_semas[SYS_SEMA_IN_DEBUGGER],0);
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ U0 CtrlAltD(I64)
|
||||
if (Fs==Gs->idle_task)
|
||||
BptS(sys_winmgr_task->rip,sys_winmgr_task);
|
||||
else
|
||||
BptS(*ctrl_alt_let_ret_addr);
|
||||
BptS(*keydev.ctrl_alt_let_ret_addr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+34
-41
@@ -49,7 +49,6 @@ MP_INIT_OS:
|
||||
LOCK
|
||||
BTR U32 [SYS_MP_CNT_LOCK],0
|
||||
|
||||
|
||||
CMP ESI,MP_MAX_PROCESSORS
|
||||
JAE I32 _SYS_HLT
|
||||
|
||||
@@ -75,7 +74,7 @@ USE64
|
||||
}
|
||||
|
||||
U0 TSSBusy(I64 tr,Bool val=OFF)
|
||||
{ //See $LK,"::/Demo/Lectures/Ring3.CPP"$.
|
||||
{//See $LK,"::/Demo/Lectures/Ring3.CPP"$.
|
||||
LBEqu((&sys_gdt)(U8 *)+tr+4,9,val);
|
||||
}
|
||||
|
||||
@@ -120,13 +119,11 @@ CTSS *TSSNew(I64 cpu_num)
|
||||
}
|
||||
|
||||
CCPU *CPUStructInit(I64 num,CCPU *c,CTask *seth_task)
|
||||
{//seth is null when called by adam on CSysFixedArea.boot_cpu0
|
||||
{//Seth is null when called by adam on CSysFixedArea.boot_cpu0
|
||||
MemSet(c,0,sizeof(CCPU));
|
||||
c->addr=c;
|
||||
c->num=num;
|
||||
c->idle_factor=0.01;
|
||||
if (!num)
|
||||
c->timer_irq_chain=&IntSimpleTimer;
|
||||
if (Bt(&sys_run_level,RLf_BOOT_HEAP)) {
|
||||
c->idle_task=Spawn(0,NULL,"Idle Task",,Fs,,0);
|
||||
Bts(&c->idle_task->task_flags,TASKf_IDLE);
|
||||
@@ -137,7 +134,7 @@ CCPU *CPUStructInit(I64 num,CCPU *c,CTask *seth_task)
|
||||
}
|
||||
|
||||
U0 MPInt(U8 num,I64 cpu_num=1)
|
||||
{
|
||||
{//Generate interrupt for specified core.
|
||||
if (cpu_num>=mp_cnt) {
|
||||
if (!Bt(&sys_run_level,RLf_MP))
|
||||
return;
|
||||
@@ -145,18 +142,18 @@ U0 MPInt(U8 num,I64 cpu_num=1)
|
||||
throw('MultCore');
|
||||
}
|
||||
PUSHFD
|
||||
CLI //multitasking safe because each core has a local apic and IRQ's are off
|
||||
CLI //Multitasking safe because each core has a local apic and IRQ's are off
|
||||
while (*LAPIC_ICR_LOW(U32 *)&0x1000)
|
||||
PAUSE
|
||||
*LAPIC_ICR_HIGH(U32 *)=mp_apic_ids[cpu_num]<<24;
|
||||
*LAPIC_ICR_HIGH(U32 *)=dev.mp_apic_ids[cpu_num]<<24;
|
||||
*LAPIC_ICR_LOW(U32 *)=0x4000+num;
|
||||
POPFD
|
||||
}
|
||||
|
||||
U0 MPIntAll(U8 num)
|
||||
{ //(All but self)
|
||||
{//Generate interrupt for all but own core.
|
||||
PUSHFD
|
||||
CLI //multitasking safe because each core has a local apic and IRQ's are off
|
||||
CLI //Multitasking safe because each core has a local apic and IRQ's are off
|
||||
while (*LAPIC_ICR_LOW(U32 *)&0x1000)
|
||||
PAUSE
|
||||
*LAPIC_ICR_LOW(U32 *)=0xC4800+num;
|
||||
@@ -164,19 +161,19 @@ U0 MPIntAll(U8 num)
|
||||
}
|
||||
|
||||
U0 MPNMInt()
|
||||
{
|
||||
{//Generate nonmaskable interrupt.
|
||||
*LAPIC_ICR_LOW(U32 *)=0xC4400;
|
||||
}
|
||||
|
||||
U0 MPHalt()
|
||||
{
|
||||
{//Halt all other cores.
|
||||
mp_cnt=1;
|
||||
MPNMInt; //Hlt All other processors
|
||||
MPNMInt;
|
||||
BusyWait(10000);
|
||||
}
|
||||
|
||||
U0 MPWake(I64 target_cpu)
|
||||
{
|
||||
{//Send wake-up interupt to core.
|
||||
if (0<=target_cpu<mp_cnt) {
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -194,18 +191,17 @@ U0 MPWake(I64 target_cpu)
|
||||
}
|
||||
|
||||
U0 MPAPICInit()
|
||||
{ //Called by adam during start-up
|
||||
//and other cores during initialization
|
||||
//after $LK,"MPStart",A="MN:MPStart"$().
|
||||
{//Called by adam during start-up
|
||||
//and other cores during initialization
|
||||
//after $LK,"MPStart",A="MN:MPStart"$().
|
||||
*LAPIC_SVR(U32 *)|=LAPICF_APIC_ENABLED;
|
||||
mp_apic_ids[Gs->num]=*LAPIC_APIC_ID(U32 *)>>24;
|
||||
*LAPIC_LDR(U32 *)=mp_apic_ids[Gs->num]<<24;
|
||||
dev.mp_apic_ids[Gs->num]=*LAPIC_APIC_ID(U32 *)>>24;
|
||||
*LAPIC_LDR(U32 *)=dev.mp_apic_ids[Gs->num]<<24;
|
||||
*LAPIC_DFR(U32 *)=0xF0000000;
|
||||
/*
|
||||
MemSet(LAPIC_IRR,0,0x20);
|
||||
MemSet(LAPIC_ISR,0,0x20);
|
||||
MemSet(LAPIC_TMR,0,0x20);
|
||||
*/
|
||||
|
||||
// MemSet(LAPIC_IRR,0,0x20);
|
||||
// MemSet(LAPIC_ISR,0,0x20);
|
||||
// MemSet(LAPIC_TMR,0,0x20);
|
||||
|
||||
SetRAX(Gs->tss->tr);
|
||||
LTR AX
|
||||
@@ -242,9 +238,9 @@ U0 MPSethServerTask()
|
||||
CSrvCmd *JobQue(I64 (*fp_addr)(U8 *data),U8 *data=NULL,
|
||||
I64 target_cpu=1,I64 flags=1<<SVCf_FREE_ON_COMPLETE,
|
||||
I64 cmd_code=SVCT_CALL,U8 *aux_str=NULL,I64 aux1=0,I64 aux2=0)
|
||||
//This is to queue multicore jobs, handled by Seth tasks.
|
||||
{//Queue multicore jobs, handled by Seth tasks.
|
||||
//Set flags to zero if you wish to get the result.
|
||||
{
|
||||
//See $LK,"::/Demo/MultiCore/Lock.CPP"$
|
||||
CSrvCtrl *ctrl;
|
||||
CSrvCmd *tempc;
|
||||
if (!(0<=target_cpu<mp_cnt))
|
||||
@@ -301,8 +297,8 @@ CTask *SpawnQue(U0 (*fp_addr)(U8 *data),U8 *data=NULL,
|
||||
}
|
||||
|
||||
U0 MPCPUTaskInit()
|
||||
{ //Called by multicore's seth task after $LK,"MPStart",A="MN:MPStart"$()
|
||||
//as the first thing a CPU does before waiting for jobs
|
||||
{//Called by multicore's seth task after $LK,"MPStart",A="MN:MPStart"$()
|
||||
//as the first thing a CPU does before waiting for jobs.
|
||||
MPAPICInit;
|
||||
Fs->rip=&MPSethServerTask;
|
||||
Fs->time_slice_start=GetTSC;
|
||||
@@ -310,10 +306,7 @@ U0 MPCPUTaskInit()
|
||||
}
|
||||
|
||||
U0 MPStart()
|
||||
{ //Called by adam during start-up
|
||||
//and can be called again to rst multicores.
|
||||
//Doesn't always work when rstting. Kill all tasks, first.
|
||||
//Must be called from core#0.
|
||||
{//Called by adam during $LK,"start-up",A="FF:::/Kernel/KEnd.CPP,MPStart"$.
|
||||
CTask *task;
|
||||
U8 buf[128];
|
||||
CMPMain *mp=MP_VECT_ADDR;
|
||||
@@ -366,7 +359,7 @@ U0 MPStart()
|
||||
my_mp_cnt=MP_MAX_PROCESSORS;
|
||||
|
||||
for (i=1;i<my_mp_cnt;i++) {
|
||||
SPrint(buf,"Seth Task CPU#%d",i);
|
||||
StrPrint(buf,"Seth Task CPU#%d",i);
|
||||
task=Spawn(&MPCPUTaskInit,NULL,buf,,,SETH_STK,0);
|
||||
task->rflags=SYS_START_RFLAGS;
|
||||
//$LK,"CTask",A="MN:CTask"$ allocated off this core's seth_task's heap (Which is Adam)
|
||||
@@ -387,20 +380,20 @@ U0 MPStart()
|
||||
}
|
||||
|
||||
U0 MPInit()
|
||||
{ //Called by adam during start-up
|
||||
{//Called by adam during start-up
|
||||
CRAXRBCRCXRDX ee;
|
||||
CPUId(0x1,&ee);
|
||||
|
||||
mp_cnt_initial=mp_cnt=1;
|
||||
mp_cnt_lock=0;
|
||||
|
||||
mp_crash=ACAlloc(sizeof(CMPCrash));
|
||||
dbg.mp_crash=ACAlloc(sizeof(CMPCrash));
|
||||
|
||||
//Must be in code heap because init code uses 32 bit addr of cpu_struct
|
||||
adam_task->gs=cpu_structs=CAlloc(sizeof(CCPU)*MP_MAX_PROCESSORS,Fs->code_heap);
|
||||
adam_task->time_slice_start=GetTSC;
|
||||
CPUStructInit(0,cpu_structs,adam_task);
|
||||
asm { //RAX has GS
|
||||
asm {//RAX has GS
|
||||
IMPORT SET_GS_BASE;
|
||||
CALL SET_GS_BASE
|
||||
}
|
||||
@@ -412,12 +405,12 @@ U0 MPInit()
|
||||
}
|
||||
|
||||
U0 MPCrash()
|
||||
{ //Entering the debugger from another core causes an interrupt on core#0
|
||||
//Which calls this routine.
|
||||
{//Entering the debugger from another core causes an interrupt on core#0
|
||||
//Which calls this routine.
|
||||
*LAPIC_EOI(U32 *)=0;
|
||||
mp_cnt=1;
|
||||
Raw(ON);
|
||||
sys_raw_flags|=RWF_SHOW_DOLLAR;
|
||||
"MP Crash CPU#%02X Task:%08X\n",mp_crash->cpu_num,mp_crash->task;
|
||||
Dbg(mp_crash->msg,mp_crash->msg_num);
|
||||
text.raw_flags|=RWF_SHOW_DOLLAR;
|
||||
"MP Crash CPU#%02X Task:%08X\n",dbg.mp_crash->cpu_num,dbg.mp_crash->task;
|
||||
Dbg(dbg.mp_crash->msg,dbg.mp_crash->msg_num);
|
||||
}
|
||||
+37
-40
@@ -8,7 +8,7 @@ I64 HasLower(U8 *src)
|
||||
}
|
||||
|
||||
CHash *PSectFind(U8 *addr,I64 *_offset)
|
||||
{ //See $LK,"::/Kernel/Hash1a.CPP",A="FL:::/Kernel/Hash1a.CPP,1"$
|
||||
{//See $LK,"::/Kernel/Hash1a.CPP",A="FL:::/Kernel/Hash1a.CPP,1"$.
|
||||
CHash *result=NULL;
|
||||
CHashExport *tempex;
|
||||
Bool has_lower=FALSE;
|
||||
@@ -58,18 +58,18 @@ CHash *PSectFind(U8 *addr,I64 *_offset)
|
||||
U0 PSectCacheAdd(CHash *temps,U8 *addr)
|
||||
{
|
||||
I64 i;
|
||||
CDbgInfo *dbg;
|
||||
CDbgInfo *dbg_info;
|
||||
Bool old_preempt;
|
||||
CPSectCache *temppc;
|
||||
if (temps && temps->type&HTT_FUN &&
|
||||
(dbg=temps(CHashFun *)->debug)) {
|
||||
(dbg_info=temps(CHashFun *)->dbg_info)) {
|
||||
old_preempt=Preempt(OFF);
|
||||
lock {i=psect_cache_index++;}
|
||||
temppc=&psect_cache[i&(PSECT_CACHE_SIZE-1)];
|
||||
temppc->base=dbg->body[0];
|
||||
lock {i=dbg.psect_cache_index++;}
|
||||
temppc=&dbg.psect_cache[i&(PSECT_CACHE_SIZE-1)];
|
||||
temppc->base=dbg_info->body[0];
|
||||
if (addr<temppc->base)
|
||||
temppc->base=addr;
|
||||
temppc->limit=dbg->body[dbg->max_line+1-dbg->min_line];
|
||||
temppc->limit=dbg_info->body[dbg_info->max_line+1-dbg_info->min_line];
|
||||
if (addr>=temppc->limit)
|
||||
temppc->limit=addr+1;
|
||||
i=MinI64(StrLen(temps->str),PSECT_CACHE_STR_LEN-1);
|
||||
@@ -84,7 +84,7 @@ U8 *PSectCacheFind(U8 *addr,I64 *_offset)
|
||||
{
|
||||
I64 i;
|
||||
F64 timeout;
|
||||
CPSectCache *temppc=psect_cache;
|
||||
CPSectCache *temppc=dbg.psect_cache;
|
||||
if (addr==SYS_IDLE_PT) {
|
||||
*_offset=0;
|
||||
return "SYS_IDLE_PT";
|
||||
@@ -100,7 +100,7 @@ U8 *PSectCacheFind(U8 *addr,I64 *_offset)
|
||||
}
|
||||
}
|
||||
|
||||
U0 SPrintPSect(U8 *buf,I64 addr,I64 field_len)
|
||||
U0 StrPrintPSect(U8 *buf,I64 addr,I64 field_len)
|
||||
{
|
||||
I64 offset;
|
||||
CHashExport *tempex;
|
||||
@@ -121,40 +121,39 @@ U0 SPrintPSect(U8 *buf,I64 addr,I64 field_len)
|
||||
if (str) {
|
||||
if (offset>0xFFFF) offset=0xFFFF;
|
||||
if (is_fun) {
|
||||
str2=MPrint("&%s",str);
|
||||
str2=MStrPrint("&%s",str);
|
||||
if (field_len>7)
|
||||
SPrint(buf,"%*ts+0x%04X",field_len-7,str2,offset);
|
||||
StrPrint(buf,"%*ts+0x%04X",field_len-7,str2,offset);
|
||||
else
|
||||
SPrint(buf,"%s+0x%04X",str2,offset);
|
||||
StrPrint(buf,"%s+0x%04X",str2,offset);
|
||||
Free(str2);
|
||||
} else {
|
||||
if (field_len>7)
|
||||
SPrint(buf,"%*ts+0x%04X",field_len-7,str,offset);
|
||||
StrPrint(buf,"%*ts+0x%04X",field_len-7,str,offset);
|
||||
else
|
||||
SPrint(buf,"%s+0x%04X",str,offset);
|
||||
StrPrint(buf,"%s+0x%04X",str,offset);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (field_len)
|
||||
SPrint(buf,"%*tX",field_len,addr);
|
||||
StrPrint(buf,"%*tX",field_len,addr);
|
||||
else
|
||||
SPrint(buf,"%X",addr);
|
||||
StrPrint(buf,"%X",addr);
|
||||
}
|
||||
|
||||
|
||||
I64 SrcLineNum(U8 *addr,I64 cnt=1)
|
||||
{
|
||||
{//linenum for src of addr.
|
||||
CHashSrcSym *temph;
|
||||
I64 cur_line,first_line,last_line,num_lines,offset;
|
||||
CDbgInfo *dbg;
|
||||
CDbgInfo *dbg_info;
|
||||
U32 *body;
|
||||
U8 *src,*src2;
|
||||
if (temph=PSectFind(addr,&offset)) {
|
||||
if (temph->type&(HTT_FUN|HTT_EXPORT_SYS_SYM)) {
|
||||
if (dbg=temph->debug) {
|
||||
num_lines=dbg->max_line-dbg->min_line+1;
|
||||
body=dbg->body;
|
||||
if (dbg_info=temph->dbg_info) {
|
||||
num_lines=dbg_info->max_line-dbg_info->min_line+1;
|
||||
body=dbg_info->body;
|
||||
|
||||
//find first nonzero
|
||||
first_line=0;
|
||||
@@ -182,13 +181,13 @@ I64 SrcLineNum(U8 *addr,I64 cnt=1)
|
||||
cur_line++;
|
||||
|
||||
if (addr<body[cur_line]+cnt)
|
||||
return cur_line+dbg->min_line;
|
||||
return cur_line+dbg_info->min_line;
|
||||
|
||||
} else if (temph->src_link) {
|
||||
src =StrNew(temph->src_link);
|
||||
src2=StrNew(temph->src_link);
|
||||
StrLastRem(src,",",src2);
|
||||
cur_line=A2I64(src2);
|
||||
cur_line=Str2I64(src2);
|
||||
Free(src);
|
||||
Free(src2);
|
||||
return cur_line;
|
||||
@@ -199,17 +198,17 @@ I64 SrcLineNum(U8 *addr,I64 cnt=1)
|
||||
}
|
||||
|
||||
U8 *SrcFileName(U8 *addr,I64 cnt=1,CTask *mem_task=NULL)
|
||||
{
|
||||
{//MAlloc filename for src of addr.
|
||||
CHashSrcSym *temph;
|
||||
I64 i,j,ii,offset,best=NULL,d,best_d;
|
||||
U32 *body;
|
||||
CDbgInfo *dbg;
|
||||
CDbgInfo *dbg_info;
|
||||
U8 *src;
|
||||
if ((temph=PSectFind(addr,&offset)) &&
|
||||
temph->type&(HTT_FUN|HTT_EXPORT_SYS_SYM)) {
|
||||
if (dbg=temph->debug) {
|
||||
j=dbg->max_line-dbg->min_line+1;
|
||||
body=dbg->body;
|
||||
if (dbg_info=temph->dbg_info) {
|
||||
j=dbg_info->max_line-dbg_info->min_line+1;
|
||||
body=dbg_info->body;
|
||||
best_d=MAX_I64;
|
||||
for (i=0;i<j;i++) {
|
||||
if (0<body[i]<=addr<body[i]+cnt) {
|
||||
@@ -238,14 +237,14 @@ U8 *SrcFileName(U8 *addr,I64 cnt=1,CTask *mem_task=NULL)
|
||||
}
|
||||
|
||||
U8 *SrcEdLink(U8 *addr,I64 cnt=1,CTask *mem_task=NULL)
|
||||
{
|
||||
{//MAlloc file,line link to src of addr.
|
||||
U8 *filename,*st,*st2;
|
||||
I64 linenum;
|
||||
if (filename=SrcFileName(addr,cnt)) {
|
||||
linenum=SrcLineNum(addr,cnt);
|
||||
if (linenum<1)
|
||||
linenum=1;
|
||||
st2=MPrint("FL:%s,%d",filename,linenum);
|
||||
st2=MStrPrint("FL:%s,%d",filename,linenum);
|
||||
Free(filename);
|
||||
st=StrNew(st2,mem_task);
|
||||
Free(st2);
|
||||
@@ -254,13 +253,12 @@ U8 *SrcEdLink(U8 *addr,I64 cnt=1,CTask *mem_task=NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Bool PutSrcLink(U8 *addr,I64 cnt=1,U8 *buf=NULL)
|
||||
{
|
||||
{//Put to StdOut a $LK,"DolDoc",A="FI:::/Doc/DolDocOverview.TXT.Z"$ file,line link to src of addr.
|
||||
U8 *src;
|
||||
if (src=SrcEdLink(addr,cnt)) {
|
||||
if (buf)
|
||||
SPrint(buf,"$$LK,\"%p\",A=\"%s\"$$",addr,src);
|
||||
StrPrint(buf,"$$LK,\"%p\",A=\"%s\"$$",addr,src);
|
||||
else
|
||||
"$$LK,\"%p\",A=\"%s\"$$",addr,src;
|
||||
Free(src);
|
||||
@@ -270,28 +268,27 @@ Bool PutSrcLink(U8 *addr,I64 cnt=1,U8 *buf=NULL)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
U0 E(U8 *addr,I64 cnt=512,I64 ed_flags=0)
|
||||
{//Edit src at addr
|
||||
U0 E(U8 *addr,I64 cnt=512,I64 edf_dof_flags=0)
|
||||
{//Edit src at addr.
|
||||
U8 *st;
|
||||
if (st=SrcEdLink(addr,cnt)) {
|
||||
if (IsRaw)
|
||||
EdLiteFileLine(st);
|
||||
else
|
||||
Ed(st,ed_flags);
|
||||
Ed(st,edf_dof_flags);
|
||||
Free(st);
|
||||
}
|
||||
}
|
||||
|
||||
U0 Man(U8 *st)
|
||||
//Edit src code for sym
|
||||
{
|
||||
{//Owner's manual for symbol. Edit src code for symbol.
|
||||
U8 **st2;
|
||||
CHashSrcSym *temph;
|
||||
if (IsRaw) {
|
||||
if ((temph=HashFind(st,Fs->hash_table,HTG_SRC_SYM)) && temph->src_link)
|
||||
EdLiteFileLine(temph->src_link);
|
||||
} else {
|
||||
st2=MPrint("MN:%s",st);
|
||||
st2=MStrPrint("MN:%s",st);
|
||||
Ed(st2);
|
||||
Free(st2);
|
||||
}
|
||||
|
||||
+21
-35
@@ -1,9 +1,9 @@
|
||||
U0 QSortI64(I64 *base,I64 num, I64 (*fp_compare)(I64 e1,I64 e2))
|
||||
{/*
|
||||
For assending strings: Compare can return StrCmp(e1,e2);
|
||||
{/*Quick Sort for width==8.
|
||||
fp_compare() passes by value instead of ref.
|
||||
|
||||
For assending ints : Compare can return e1-e2;
|
||||
Don't use e1-e2 if numbers can overflow, return -1,0 or 1 with if's.
|
||||
For assending strings: return StrCmp(e1,e2);
|
||||
For assending ints : return e1-e2;
|
||||
|
||||
Maybe, look at $LK,"::/Demo/MultiCore/RadixSort.CPP"$.
|
||||
*/
|
||||
@@ -18,20 +18,18 @@ Maybe, look at $LK,"::/Demo/MultiCore/RadixSort.CPP"$.
|
||||
less++;
|
||||
else {
|
||||
greater--;
|
||||
SwapU64(less,greater);
|
||||
SwapI64(less,greater);
|
||||
}
|
||||
}
|
||||
i=less-base;
|
||||
if (i==num) { //All less or equal to pivot
|
||||
|
||||
if (i==num) {//All less or equal to pivot
|
||||
//Point greater to first less
|
||||
do greater--;
|
||||
while (--i && !(*fp_compare)(*greater,pivot));
|
||||
|
||||
if (i) {
|
||||
less=base+num/2; //Pivot was not moved, point to it
|
||||
if (less<greater)
|
||||
SwapU64(less,greater);
|
||||
SwapI64(less,greater);
|
||||
num=i;
|
||||
} else //All equal
|
||||
break;
|
||||
@@ -47,9 +45,9 @@ Maybe, look at $LK,"::/Demo/MultiCore/RadixSort.CPP"$.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U0 QSort2a(U8 **_base,I64 num,I64 (*fp_compare)(U8 **_e1,U8 **_e2))
|
||||
{//Not public, for case of width=size(U8 *)
|
||||
{//Not public. For case of width==size(U8 *)==8.
|
||||
//fp_compare() passes by ref.
|
||||
I64 i;
|
||||
U8 **_less,**_greater,*pivot;
|
||||
do {
|
||||
@@ -61,20 +59,18 @@ U0 QSort2a(U8 **_base,I64 num,I64 (*fp_compare)(U8 **_e1,U8 **_e2))
|
||||
_less++;
|
||||
else {
|
||||
_greater--;
|
||||
SwapU64(_less,_greater);
|
||||
SwapI64(_less,_greater);
|
||||
}
|
||||
}
|
||||
i=_less-_base;
|
||||
if (i==num) { //All less or equal to pivot
|
||||
|
||||
if (i==num) {//All less or equal to pivot
|
||||
//Point greater to first less
|
||||
do _greater--;
|
||||
while (--i && !(*fp_compare)(_greater,&pivot));
|
||||
|
||||
if (i) {
|
||||
_less=_base+num/2; //Pivot was not moved, point to it
|
||||
if (_less<_greater)
|
||||
SwapU64(_less,_greater);
|
||||
SwapI64(_less,_greater);
|
||||
num=i;
|
||||
} else //All equal
|
||||
break;
|
||||
@@ -91,7 +87,6 @@ U0 QSort2a(U8 **_base,I64 num,I64 (*fp_compare)(U8 **_e1,U8 **_e2))
|
||||
} while (num>1);
|
||||
}
|
||||
|
||||
|
||||
U0 QSort2b(U8 *base,I64 num, I64 width, I64 (*fp_compare)(U8 *e1,U8 *e2),U8 *temp)
|
||||
{//Not public
|
||||
I64 i;
|
||||
@@ -112,12 +107,10 @@ U0 QSort2b(U8 *base,I64 num, I64 width, I64 (*fp_compare)(U8 *e1,U8 *e2),U8 *tem
|
||||
}
|
||||
}
|
||||
i=(less-base)/width;
|
||||
if (i==num) { //All less or equal to pivot
|
||||
|
||||
if (i==num) {//All less or equal to pivot
|
||||
//Point greater to first less
|
||||
do greater-=width;
|
||||
while (--i && !(*fp_compare)(greater,pivot));
|
||||
|
||||
if (i) {
|
||||
less=base+num/2*width; //Pivot was not moved, point to it
|
||||
if (less<greater) {
|
||||
@@ -141,13 +134,12 @@ U0 QSort2b(U8 *base,I64 num, I64 width, I64 (*fp_compare)(U8 *e1,U8 *e2),U8 *tem
|
||||
} while (num>1);
|
||||
}
|
||||
|
||||
|
||||
U0 QSort(U8 *base,I64 num, I64 width, I64 (*fp_compare)(U8 *e1,U8 *e2))
|
||||
{/*
|
||||
For assending strings: Compare can return StrCmp(*e1,*e2);
|
||||
{/*Quick Sort: fp_compare() passes by ref.
|
||||
|
||||
For assending ints : Compare can return *e1-*e2;
|
||||
Don't use e1-e2 if numbers can overflow, return -1,0 or 1 with if's.
|
||||
For assending strings: return StrCmp(*e1,*e2);
|
||||
For assending ints : return *e1-*e2;
|
||||
Don't return e1-e2 if numbers can overflow, return -1,0 or 1.
|
||||
|
||||
Maybe, look at $LK,"::/Demo/MultiCore/RadixSort.CPP"$.
|
||||
*/
|
||||
@@ -164,20 +156,18 @@ Maybe, look at $LK,"::/Demo/MultiCore/RadixSort.CPP"$.
|
||||
less+=sizeof(U8 *);
|
||||
else {
|
||||
greater-=sizeof(U8 *);
|
||||
SwapU64(less,greater);
|
||||
SwapI64(less,greater);
|
||||
}
|
||||
}
|
||||
i=(less-base)/sizeof(U8 *);
|
||||
if (i==num) { //All less or equal to pivot
|
||||
|
||||
if (i==num) {//All less or equal to pivot
|
||||
//Point greater to first less
|
||||
do greater-=sizeof(U8 *);
|
||||
while (--i && !(*fp_compare)(greater,&pivot));
|
||||
|
||||
if (i) {
|
||||
less=base+num/2*sizeof(U8 *); //Pivot was not moved, point to it
|
||||
if (less<greater)
|
||||
SwapU64(less,greater);
|
||||
SwapI64(less,greater);
|
||||
num=i;
|
||||
} else //All equal
|
||||
break;
|
||||
@@ -210,12 +200,10 @@ Maybe, look at $LK,"::/Demo/MultiCore/RadixSort.CPP"$.
|
||||
}
|
||||
}
|
||||
i=(less-base)/width;
|
||||
if (i==num) { //All less or equal to pivot
|
||||
|
||||
if (i==num) {//All less or equal to pivot
|
||||
//Point greater to first less
|
||||
do greater-=width;
|
||||
while (--i && !(*fp_compare)(greater,pivot));
|
||||
|
||||
if (i) {
|
||||
less=base+num/2*width; //Pivot was not moved, point to it
|
||||
if (less<greater) {
|
||||
@@ -241,5 +229,3 @@ Maybe, look at $LK,"::/Demo/MultiCore/RadixSort.CPP"$.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
/*
|
||||
See $LK,"TempleOS MultiTasking",A="FI:::/Doc/MultiTasking.TXT"$.
|
||||
/*See $LK,"TempleOS MultiTasking",A="FI:::/Doc/MultiTasking.TXT"$.
|
||||
|
||||
Tasks are ordered in a circular queue
|
||||
by front-to-back window stack order with
|
||||
the window mgr as the head (paints
|
||||
the wallpaper). The scheduler is
|
||||
round-robin. It checking if a task
|
||||
round-robin. It checks if a task
|
||||
is ready and runs it or skips it.
|
||||
Swapping tasks just involves storing and
|
||||
restoring regs (no disk I/O for virtual
|
||||
@@ -19,19 +18,19 @@ on a message and skips if not ready.
|
||||
A task runs until it voluntarily yields
|
||||
ctrl with a call to $LK,"Yield",A="MN:Yield"$() or gets
|
||||
preempted by the fixed 1kHz $LK,"JIFFY_FREQ",A="MN:JIFFY_FREQ"$
|
||||
timer interrupt. See $LK,"SYS_TIMER_HANDLER",A="MN:SYS_TIMER_HANDLER"$.
|
||||
timer interrupt. See $LK,"SYS_TIMER_HANDLER",A="MN:SYS_TIMER_HANDLER"$.
|
||||
Tasks can ask not to be preempted with
|
||||
$LK,"Preempt",A="MN:Preempt"$(ON/OFF). Tasks waiting on I/O
|
||||
$LK,"Preempt",A="MN:Preempt"$(ON/OFF). Tasks waiting on I/O
|
||||
often loop, checking for a status and
|
||||
$LK,"Yield",A="MN:Yield"$ing. This does not really degrade
|
||||
performance, but pegs the CPU Load.
|
||||
|
||||
The scheduler checks for a few critical
|
||||
key-strokes such as <CTRL-ALT-X>, which
|
||||
kills a task; <CTRL-ALT-DEL>, which reboots;
|
||||
<CTRL-ALT-T>, which changes focus and
|
||||
<CTRL-ALT-C>, which breaks execution
|
||||
of a program.
|
||||
The scheduler checks for a few keys:
|
||||
|
||||
<CTRL-ALT-x> kill a task.
|
||||
<CTRL-ALT-DEL> reboots.
|
||||
<CTRL-ALT-t> changes focus to next task.
|
||||
<CTRL-ALT-c> breaks execution of a program.
|
||||
|
||||
Each core has its own circular task queue.
|
||||
For AP processors, they have a "Seth" task
|
||||
@@ -41,7 +40,7 @@ $HL,1$*/
|
||||
|
||||
asm {
|
||||
USE64
|
||||
// ************************************
|
||||
//************************************
|
||||
TASK_CONTEXT_SAVE::
|
||||
//OUT: RSI=FS
|
||||
PUSH RSI
|
||||
@@ -52,8 +51,7 @@ TASK_CONTEXT_SAVE::
|
||||
POP U64 CTask.rsi[RSI]
|
||||
MOV U64 CTask.rax[RSI],RAX
|
||||
|
||||
/*
|
||||
We divert the stk to the Task memory
|
||||
/*Divert the stk to the Task memory
|
||||
and push onto it and divert it back.
|
||||
It's a little faster.
|
||||
*/
|
||||
@@ -92,7 +90,7 @@ It's a little faster.
|
||||
MOV RDX,U64 CBpt.next[RDX]
|
||||
JMP @@05
|
||||
@@10: RET
|
||||
// ************************************
|
||||
//************************************
|
||||
_TASK_CONTEXT_RESTORE::
|
||||
XOR RAX,RAX
|
||||
INC U64 GS:CCPU.swap_cnter[RAX]
|
||||
@@ -145,7 +143,7 @@ _TASK_CONTEXT_RESTORE::
|
||||
PUSH U64 CTask.rip[RSI]
|
||||
MOV RSI,U64 CTask.rsi[RSI]
|
||||
IRET
|
||||
// ************************************
|
||||
//************************************
|
||||
END_RSI_TASK:
|
||||
MOV RAX,RSI
|
||||
CALL SET_FS_BASE
|
||||
@@ -176,7 +174,7 @@ _YIELD::
|
||||
JNE @@15 //Jmp if not just one task on core.
|
||||
|
||||
PUSH RAX
|
||||
MOV RAX,U64 [SYS_JIFFIES]
|
||||
MOV RAX,U64 [&cnts.jiffies]
|
||||
CMP U64 CTask.wake_jiffy[RSI],RAX
|
||||
JG @@10 //If needs to sleep, jmp and swap-out.
|
||||
|
||||
@@ -208,7 +206,7 @@ RESTORE_RSI_TASK_NO_KEY_CHECK:
|
||||
TEST U64 CTask.task_flags[RSI],1<<TASKf_AWAITING_MSG|1<<TASKf_SUSPENDED
|
||||
JNZ @@25
|
||||
|
||||
MOV RAX,U64 [SYS_JIFFIES]
|
||||
MOV RAX,U64 [&cnts.jiffies]
|
||||
CMP U64 CTask.wake_jiffy[RSI],RAX
|
||||
JG @@25 //Jmp if not ready, yet.
|
||||
|
||||
@@ -272,7 +270,7 @@ BREAK_FOCUS_USER:
|
||||
MOV RSI,U64 [SYS_FOCUS_TASK]
|
||||
TEST RSI,RSI
|
||||
JZ SWAP_IN_SETH_TASK_IF_READY
|
||||
BT U64 CTask.win_inhibit[RSI],WIf_FOCUS
|
||||
BT U64 CTask.win_inhibit[RSI],WIf_SELF_FOCUS
|
||||
JC I32 RESTORE_RSI_TASK_NO_KEY_CHECK
|
||||
LOCK
|
||||
BTR U64 CTask.task_flags[RSI],TASKf_BREAK_LOCKED
|
||||
@@ -286,7 +284,7 @@ BREAK_FOCUS_USER:
|
||||
BT U64 CTask.task_flags[RSI],TASKf_BREAK_TO_SHIFT_ESC
|
||||
JC @@15
|
||||
|
||||
//We do these two now, in case interrupt happens
|
||||
//Do these now, in case interrupt happens.
|
||||
MOV U64 CTask.wake_jiffy[RSI],0
|
||||
PUSH RSI
|
||||
CALL &TaskRstAwaitingMsg
|
||||
@@ -303,7 +301,7 @@ END_FOCUS_USER:
|
||||
JZ I32 SWAP_IN_SETH_TASK_IF_READY
|
||||
MOV RAX,RSI
|
||||
CALL SET_FS_BASE
|
||||
BT U64 CTask.win_inhibit[RSI],WIf_FOCUS
|
||||
BT U64 CTask.win_inhibit[RSI],WIf_SELF_FOCUS
|
||||
JC I32 RESTORE_RSI_TASK_WITH_KEY_CHECK
|
||||
LOCK
|
||||
BTS U64 CTask.task_flags[RSI],TASKf_KILL_TASK
|
||||
@@ -320,7 +318,7 @@ FOCUS_RSI_NEXT_USER:
|
||||
MOV ESI,U32 SYS_FIXED_AREA+CSysFixedArea.adam
|
||||
@@20: MOV RDI,RSI
|
||||
MOV RSI,U64 CTask.next_task[RSI]
|
||||
@@25: BT U64 CTask.win_inhibit[RSI],WIf_FOCUS
|
||||
@@25: BT U64 CTask.win_inhibit[RSI],WIf_SELF_FOCUS
|
||||
JC @@30
|
||||
CMP U64 [SYS_FOCUS_TASK],RSI
|
||||
JE @@30
|
||||
@@ -341,9 +339,9 @@ FOCUS_RSI_NEXT_USER:
|
||||
|
||||
}
|
||||
|
||||
_extern _TASK_CONTEXT_RESTORE U0 TaskContextRestore();
|
||||
_extern _YIELD U0 Yield();
|
||||
_extern _TASK_END_NOW U0 TaskEndNow();
|
||||
_extern _TASK_CONTEXT_RESTORE U0 TaskContextRestore(); //Restore a task context.
|
||||
_extern _YIELD U0 Yield(); //Yield cpu to next task.
|
||||
_extern _TASK_END_NOW U0 TaskEndNow(); //Terminate current task.
|
||||
|
||||
U0 TaskQueIns(CTask *task,CTask *pred=NULL)
|
||||
{//Insert a task in the scheduler running task queue.
|
||||
+52
-66
@@ -1,5 +1,5 @@
|
||||
U0 SrvCmdDel(CSrvCmd *tempc)
|
||||
{
|
||||
{//Free one cmd node.
|
||||
Free(tempc->aux_str);
|
||||
Free(tempc);
|
||||
}
|
||||
@@ -23,7 +23,7 @@ U0 SrvCtrlInit(CSrvCtrl *ctrl)
|
||||
}
|
||||
|
||||
U0 TaskRstAwaitingMsg(CTask *task=NULL)
|
||||
{ //Pop-ups get parent messages so wake-up our pop-ups if we got a msg.
|
||||
{//Pop-ups get parent messages so wake-up our pop-ups if we got a msg.
|
||||
if (!task) task=Fs;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -37,7 +37,7 @@ U0 TaskRstAwaitingMsg(CTask *task=NULL)
|
||||
}
|
||||
|
||||
CSrvCmd *TaskExe(CTask *srv,CTask *master,U8 *data,I64 flags)
|
||||
{//This queues a request to compile and execute text.
|
||||
{//Queues a request to compile and execute text.
|
||||
CSrvCmd *result;
|
||||
if (!data || !TaskValidate(srv) ||
|
||||
master && !TaskValidate(master) ||
|
||||
@@ -72,9 +72,8 @@ CSrvCmd *TaskExe(CTask *srv,CTask *master,U8 *data,I64 flags)
|
||||
return result;
|
||||
}
|
||||
|
||||
CSrvCmd *TaskText(CTask *srv,CTask *master,
|
||||
U8 *data,I64 flags)
|
||||
{
|
||||
CSrvCmd *TaskText(CTask *srv,CTask *master,U8 *data,I64 flags)
|
||||
{//Post text to servant task. Tell who the master task is.
|
||||
CSrvCmd *result;
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
CTask *task;
|
||||
@@ -122,9 +121,9 @@ CSrvCmd *TaskText(CTask *srv,CTask *master,
|
||||
return result;
|
||||
}
|
||||
|
||||
CSrvCmd *TaskMsg(CTask *_srv,CTask *master,
|
||||
I64 msg_code,I64 p1,I64 p2,I64 flags)
|
||||
{
|
||||
CSrvCmd *TaskMsg(CTask *_srv,CTask *master,I64 msg_code,I64 a1,I64 a2,I64 flags)
|
||||
{//Post message to servant task. Tell who the master task is.
|
||||
//See $LK,"flags",A="MN:SVCf_WAKE_MASTER"$ and $LK,"msg_code",A="MN:MSG_CMD"$.
|
||||
CSrvCmd *tempc1,*tempc;
|
||||
CTask *srv=_srv;
|
||||
if (!TaskValidate(srv) ||
|
||||
@@ -135,8 +134,8 @@ CSrvCmd *TaskMsg(CTask *_srv,CTask *master,
|
||||
tempc->master_task=master;
|
||||
tempc->cmd_code=SVCT_MSG;
|
||||
tempc->msg_code=AbsI64(msg_code); //negative means do a down and up
|
||||
tempc->aux1=p1;
|
||||
tempc->aux2=p2;
|
||||
tempc->aux1=a1;
|
||||
tempc->aux2=a2;
|
||||
tempc->flags=flags;
|
||||
PUSHFD
|
||||
if (Bt(&sys_semas[SYS_SEMA_RECORD_MACRO],0) &&
|
||||
@@ -164,12 +163,12 @@ CSrvCmd *TaskMsg(CTask *_srv,CTask *master,
|
||||
}
|
||||
POPFD
|
||||
if (msg_code<0) //Down-Up
|
||||
TaskMsg(_srv,master,-msg_code+1,p1,p2,flags);
|
||||
TaskMsg(_srv,master,-msg_code+1,a1,a2,flags);
|
||||
return tempc;
|
||||
}
|
||||
|
||||
Bool ScanResult(CSrvCmd *rqst=NULL,I64 *_result=NULL)
|
||||
{
|
||||
{//Check rqst complete, return with or without.
|
||||
CSrvCtrl *ctrl;
|
||||
CSrvCmd *tempc,*tempc1;
|
||||
if (!rqst || Bt(&rqst->flags,SVCf_DONE)) {
|
||||
@@ -204,7 +203,7 @@ Bool ScanResult(CSrvCmd *rqst=NULL,I64 *_result=NULL)
|
||||
}
|
||||
|
||||
I64 GetResult(CSrvCmd *rqst=NULL)
|
||||
{
|
||||
{//See $LK,"::/Demo/MultiCore/Lock.CPP"$
|
||||
I64 result;
|
||||
CSrvCmd *tempc1;
|
||||
if (!rqst) {
|
||||
@@ -226,7 +225,7 @@ I64 GetResult(CSrvCmd *rqst=NULL)
|
||||
}
|
||||
|
||||
U0 TaskWait(CTask *task=NULL)
|
||||
{//Wait for idle
|
||||
{//Wait for idle.
|
||||
CTask *task1;
|
||||
CSrvCmd *tempc1;
|
||||
if (!task) task=Fs;
|
||||
@@ -245,26 +244,28 @@ U0 TaskWait(CTask *task=NULL)
|
||||
}
|
||||
}
|
||||
|
||||
U0 PostMsg(CTask *task,I64 msg_code,I64 p1,I64 p2,I64 flags=0)
|
||||
{
|
||||
U0 PostMsg(CTask *task,I64 msg_code,I64 a1,I64 a2,I64 flags=0)
|
||||
{//Post a message and return immediately. See $LK,"msg_code",A="MN:MSG_CMD"$.
|
||||
if (TaskValidate(task)) {
|
||||
if (Bt(&task->task_flags,TASKf_INPUT_FILTER_TASK))
|
||||
TaskMsg(task->last_input_filter_task,NULL,msg_code,p1,p2,
|
||||
TaskMsg(task->last_input_filter_task,NULL,msg_code,a1,a2,
|
||||
flags|1<<SVCf_DONT_FILTER);
|
||||
else
|
||||
TaskMsg(task,NULL,msg_code,p1,p2,flags);
|
||||
TaskMsg(task,NULL,msg_code,a1,a2,flags);
|
||||
}
|
||||
}
|
||||
|
||||
U0 SendMsg(CTask *task,I64 msg_code,I64 p1,I64 p2,I64 flags=0)
|
||||
{
|
||||
PostMsg(task,msg_code,p1,p2,flags);
|
||||
U0 SendMsg(CTask *task,I64 msg_code,I64 a1,I64 a2,I64 flags=0)
|
||||
{//Post a message to a task and wait until it is delivered
|
||||
//and the task becomes idle. See $LK,"msg_code",A="MN:MSG_CMD"$.
|
||||
PostMsg(task,msg_code,a1,a2,flags);
|
||||
TaskWait(task);
|
||||
}
|
||||
|
||||
U0 Msg(I64 msg_code,I64 p1,I64 p2,I64 flags=0)
|
||||
{
|
||||
PostMsg(Fs,msg_code,p1,p2,flags);
|
||||
U0 Msg(I64 msg_code,I64 a1,I64 a2,I64 flags=0)
|
||||
{//Post a message to the current task and return immediately.
|
||||
//See $LK,"msg_code",A="MN:MSG_CMD"$.
|
||||
PostMsg(Fs,msg_code,a1,a2,flags);
|
||||
}
|
||||
|
||||
#define SCR_DONE 0
|
||||
@@ -333,7 +334,7 @@ I64 SrvCmdRun(CSrvCmd *tempc,I64 old_flags)
|
||||
SetRFlags(old_flags);
|
||||
}
|
||||
if (Bt(&flags,SVCf_FOCUS_MASTER) &&
|
||||
!Bt(&master->win_inhibit,WIf_FOCUS))
|
||||
!Bt(&master->win_inhibit,WIf_SELF_FOCUS))
|
||||
sys_focus_task=master;
|
||||
if (Bt(&flags,SVCf_WAKE_MASTER))
|
||||
Suspend(master,FALSE);
|
||||
@@ -355,7 +356,7 @@ I64 SrvCmdRun(CSrvCmd *tempc,I64 old_flags)
|
||||
}
|
||||
|
||||
I64 SrvCmdsHandler(CTask *task=NULL)
|
||||
{
|
||||
{//Handle all waiting cmds and return.
|
||||
I64 cnt=0,old_flags=GetRFlags;
|
||||
CSrvCmd *tempc,*tempc1;
|
||||
if (!task) task=Fs;
|
||||
@@ -385,10 +386,8 @@ sch_done:
|
||||
}
|
||||
|
||||
I64 SrvUser(U8 *fmt,...)
|
||||
//Spawns a visible task and sends text
|
||||
//which gets compiled and run.
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
{//Spawns a visible task and sends text which gets compiled and run.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
I64 result=0;
|
||||
CSrvCmd *tempc;
|
||||
CTask *task=Spawn(&SrvUserCmdLine,NULL,"Servant",,Fs);
|
||||
@@ -402,11 +401,9 @@ I64 SrvUser(U8 *fmt,...)
|
||||
}
|
||||
|
||||
I64 Adam(U8 *fmt,...)
|
||||
//Sends text to the adam task which gets
|
||||
//compiled and run.
|
||||
{
|
||||
{//Sends text to the adam task which gets compiled and run.
|
||||
I64 result;
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
Bool old_preempt=Preempt(OFF);
|
||||
CSrvCmd *tempc;
|
||||
if (Fs==adam_task) {
|
||||
@@ -423,10 +420,8 @@ I64 Adam(U8 *fmt,...)
|
||||
}
|
||||
|
||||
U0 AdamLog(U8 *fmt,...)
|
||||
//Sends text to the adam task which gets
|
||||
//displayed.
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
{//Sends text to the adam task which gets displayed.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
if (Fs==adam_task)
|
||||
"%s",buf;
|
||||
else if (!IsSingleUser)
|
||||
@@ -435,11 +430,9 @@ U0 AdamLog(U8 *fmt,...)
|
||||
}
|
||||
|
||||
U0 AdamErr(U8 *fmt,...)
|
||||
//Sends text to the adam task which gets
|
||||
//displayed as red and blinking.
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv),
|
||||
*st=MPrint(ST_ERR_ST "%s",buf);
|
||||
{//Sends text to the adam task which gets displayed as red and blinking.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv),
|
||||
*st=MStrPrint(ST_ERR_ST "%s",buf);
|
||||
if (Fs==adam_task)
|
||||
"%s",st;
|
||||
else if (!IsSingleUser)
|
||||
@@ -449,20 +442,18 @@ U0 AdamErr(U8 *fmt,...)
|
||||
}
|
||||
|
||||
U0 XTalk(CTask *task,U8 *fmt,...)
|
||||
//Sends text to another task's input
|
||||
//buffer.
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv),*st=AStrNew(buf),
|
||||
*st2=MPrint("\"%%s\",%d;Free(%d);",st,st);
|
||||
{//Sends text to other task. See $LK,"::/Misc/OSTestSuite.CPP"$.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv),*st=AStrNew(buf),
|
||||
*st2=MStrPrint("\"%%s\",%d;Free(%d);",st,st);
|
||||
TaskText(task,0,st2,0);
|
||||
Free(st2);
|
||||
Free(buf);
|
||||
}
|
||||
|
||||
U0 XTalkWait(CTask *task,U8 *fmt,...)
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv),*st=AStrNew(buf),
|
||||
*st2=MPrint("\"%%s\",%d;Free(%d);",st,st);
|
||||
{//Send text to other task and wait for it to idle.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv),*st=AStrNew(buf),
|
||||
*st2=MStrPrint("\"%%s\",%d;Free(%d);",st,st);
|
||||
TaskText(task,0,st2,0);
|
||||
Free(st2);
|
||||
Free(buf);
|
||||
@@ -470,10 +461,8 @@ U0 XTalkWait(CTask *task,U8 *fmt,...)
|
||||
}
|
||||
|
||||
U0 AutoStr(U8 *fmt,...)
|
||||
//Sends text in the nature of an AutoFile to one's
|
||||
//own input buffer.
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
{//Send AutoFile code to self.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
if (Bt(&Fs->task_flags,TASKf_INPUT_FILTER_TASK))
|
||||
ExePrint("%s",buf);
|
||||
else
|
||||
@@ -482,32 +471,29 @@ U0 AutoStr(U8 *fmt,...)
|
||||
}
|
||||
|
||||
U0 AutoFile(U8 *filename)
|
||||
{
|
||||
{//Send AutoFile code file to self.
|
||||
U8 *name=DftExt(filename,"AUT.Z");
|
||||
AutoStr("%F",name);
|
||||
Free(name);
|
||||
}
|
||||
|
||||
U0 Auto(U8 *fmt,...)
|
||||
//Sends text to one's own input buffer
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv),*st=AStrNew(buf);
|
||||
{//Send text to own input buffer. See $LK,"::/Demo/AcctExample/TSDistro.CPP"$.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv),*st=AStrNew(buf);
|
||||
AutoStr("\"%%s\",%d;Free(%d);",st,st);
|
||||
Free(buf);
|
||||
}
|
||||
|
||||
//This sends text of an AutoFile nature to a
|
||||
//task's input buffer.
|
||||
U0 XTalkStr(CTask *task,U8 *fmt,...)
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
{//Send AutoFile code to other task.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
TaskText(task,0,buf,0);
|
||||
Free(buf);
|
||||
}
|
||||
|
||||
U0 XTalkStrWait(CTask *task,U8 *fmt,...)
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
{//Send AutoFile code to other task and wait for it to idle.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
TaskText(task,0,buf,0);
|
||||
Free(buf);
|
||||
TaskWait(task);
|
||||
|
||||
+84
-80
@@ -1,26 +1,24 @@
|
||||
U8 hex_digits[16]="0123456789ABCDEF";
|
||||
U8 *Bin2Hex(U8 *dst,I64 n;I64 width)
|
||||
U8 *StrPrintHex(U8 *dst,I64 num;I64 width)
|
||||
{
|
||||
U8 *result=dst+width;
|
||||
dst=result;
|
||||
while (width--) {
|
||||
*--dst=hex_digits[n&15];
|
||||
n>>=4;
|
||||
*--dst="0123456789ABCDEF"(U8 *)[num&15];
|
||||
num>>=4;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 PutHex(I64 n,I64 width)
|
||||
U0 PutHex(I64 num,I64 width)
|
||||
{
|
||||
U8 buf[17];
|
||||
if (width>16) width=16;
|
||||
*Bin2Hex(buf,n,width)=0;
|
||||
*StrPrintHex(buf,num,width)=0;
|
||||
"%s",buf;
|
||||
}
|
||||
|
||||
asm {
|
||||
USE64
|
||||
// ************************************
|
||||
// IN: RAX=NUM TO PRINT
|
||||
PUT_HEX_U64::
|
||||
PUSH_C_REGS
|
||||
@@ -29,7 +27,6 @@ PUT_HEX_U64::
|
||||
CALL &PutHex
|
||||
POP_C_REGS
|
||||
RET
|
||||
PUT_HEX::
|
||||
PUT_HEX_U32::
|
||||
PUSH_C_REGS
|
||||
PUSH 8
|
||||
@@ -51,7 +48,6 @@ PUT_HEX_U8::
|
||||
CALL &PutHex
|
||||
POP_C_REGS
|
||||
RET
|
||||
// ************************************
|
||||
PUT_CHARS::
|
||||
// IN: RAX=Char
|
||||
PUSH_C_REGS
|
||||
@@ -66,7 +62,6 @@ PUT_STR::
|
||||
CALL &PutS
|
||||
POP_C_REGS
|
||||
RET
|
||||
// ************************************
|
||||
_STRCPY::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -88,7 +83,6 @@ _STRCPY::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
_STRCMP::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -113,7 +107,6 @@ _STRCMP::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
TO_UPPER::
|
||||
CMP AL,'a'
|
||||
JB @@05
|
||||
@@ -121,7 +114,6 @@ TO_UPPER::
|
||||
JA @@05
|
||||
ADD AL,'A'-'a'
|
||||
@@05: RET
|
||||
// ************************************
|
||||
_STRICMP::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -159,7 +151,6 @@ _STRICMP::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
_STRNCMP::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -189,7 +180,6 @@ _STRNCMP::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_STRNICMP::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -230,7 +220,6 @@ _STRNICMP::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_STRMATCH::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -270,7 +259,6 @@ _STRMATCH::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
_STRIMATCH::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -318,79 +306,94 @@ _STRIMATCH::
|
||||
POP RBP
|
||||
RET1 16
|
||||
}
|
||||
_extern _STRCMP I64 StrCmp(U8 *st1,U8 *st2);
|
||||
_extern _STRICMP I64 StrICmp(U8 *st1,U8 *st2);
|
||||
_extern _STRNCMP I64 StrNCmp(U8 *st1,U8 *st2,I64 n);
|
||||
_extern _STRNICMP I64 StrNICmp(U8 *st1,U8 *st2,I64 n);
|
||||
_extern _STRMATCH U8 *StrMatch(U8 *needle,U8 *haystack_str);
|
||||
_extern _STRIMATCH U8 *StrIMatch(U8 *needle,U8 *haystack_str);
|
||||
_extern _STRCPY U0 StrCpy(U8 *dst,U8 *src);
|
||||
_extern _STRCMP I64 StrCmp(U8 *st1,U8 *st2); //Compare two strings.
|
||||
_extern _STRICMP I64 StrICmp(U8 *st1,U8 *st2); //Compare two strings, ignoring case.
|
||||
_extern _STRNCMP I64 StrNCmp(U8 *st1,U8 *st2,I64 n); //Compare N bytes in two strings.
|
||||
_extern _STRNICMP I64 StrNICmp(U8 *st1,U8 *st2,I64 n); //Compare N bytes in two strings, ignoring case.
|
||||
_extern _STRMATCH U8 *StrMatch(U8 *needle,U8 *haystack_str); //Scan for string in string.
|
||||
_extern _STRIMATCH U8 *StrIMatch(U8 *needle,U8 *haystack_str); //Scan for string in string, ignoring case.
|
||||
_extern _STRCPY U0 StrCpy(U8 *dst,U8 *src); //Copy string.
|
||||
|
||||
/*
|
||||
These bitmaps go to 0-511 so that
|
||||
/*These bitmaps go to 0-511 so that
|
||||
$LK,"Lex",A="MN:Lex"$() can use them with $LK,"Token Codes",A="MN:TK_EOF"$.
|
||||
*/
|
||||
U32 chars_bitmap_alpha[16]=
|
||||
{0x0000000,0x00000000,0x87FFFFFF,0x07FFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_alpha_numeric[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_alpha_numeric[16]=
|
||||
{0x0000000,0x03FF0000,0x87FFFFFF,0x07FFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_alpha_numeric_no_at[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_alpha_numeric_no_at[16]=
|
||||
{0x0000000,0x03FF0000,0x87FFFFFE,0x07FFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_word[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_word[16]=
|
||||
{0x0000000,0x03FF0080,0x87FFFFFE,0x07FFFFFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_filename[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_filename[16]=
|
||||
{0x0000000,0x03FF73FB,0xEFFFFFFF,0x2FFFFFFF,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_dec_numeric[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_dec_numeric[16]=
|
||||
{0x0000000,0x03FF0000,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_hex_numeric[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_hex_numeric[16]=
|
||||
{0x0000000,0x03FF0000,0x7E,0x7E,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_white_space[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_white_space[16]=
|
||||
{0x80003600,1,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_non_eol_white_space[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_non_eol_white_space[16]=
|
||||
{0x80001200,1,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_zero_cr_nl_cursor[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_zero_cr_nl_cursor[16]=
|
||||
{0x00002421,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_zero_tab_ff_cr_nl_cursor[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_zero_tab_ff_cr_nl_cursor[16]=
|
||||
{0x00003621,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_zero_tab_ff_cr_nl_cursor_dollar[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_zero_tab_ff_cr_nl_cursor_dollar[16]=
|
||||
{0x00003621,0x10,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_getkey[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_getkey[16]=
|
||||
{0x80002600,0xFFFFFFFF,0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_printable[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_printable[16]=
|
||||
{0x80003600,0xFFFFFFFF,0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_displayable[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_displayable[16]=
|
||||
{0x80000000,0xFFFFFFFF,0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0,0,0,0,0,0,0,0};
|
||||
U32 chars_bitmap_safe_dollar[16]=
|
||||
0,0,0,0,0,0,0,0},
|
||||
|
||||
chars_bitmap_safe_dollar[16]=
|
||||
{0x80000000,0xFFFFFFEF,0xFFFFFFFF,0x7FFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0,0,0,0,0,0,0,0};//same but no dollar sign
|
||||
U32 chars_bitmap_non_eol[16]=
|
||||
0,0,0,0,0,0,0,0},//same but no dollar sign
|
||||
|
||||
chars_bitmap_non_eol[16]=
|
||||
{0xFFFFDBFE,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,
|
||||
0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF,0xFFFFFFFF};
|
||||
|
||||
U8 *LstSub(I64 sub, U8 *lst)
|
||||
{//Point to lst entry.
|
||||
//Not especially efficient but handy. Use an array of U8*'s for efficiency.
|
||||
//Not efficient. Use an array of U8 ptrs for efficiency.
|
||||
if (!lst) return NULL;
|
||||
while (*lst && sub>0) {
|
||||
while (*lst) // Advance to end of cur entry.
|
||||
while (*lst) //Advance to end of cur entry.
|
||||
lst++;
|
||||
lst++; // Skip trailing zero
|
||||
if (*lst=='@') // Check for '@' alias lst entry
|
||||
lst++; //Skip trailing zero.
|
||||
if (*lst=='@') //Check for '@' alias lst entry.
|
||||
lst++;
|
||||
else
|
||||
sub--;
|
||||
@@ -402,15 +405,16 @@ U8 *LstSub(I64 sub, U8 *lst)
|
||||
}
|
||||
|
||||
I64 LstMatch(U8 *needle, U8 *haystack_lst,I64 flags=0)
|
||||
// RETURNS: -2 if Ambiguous, -1 if not found, else entry num
|
||||
{ //Not especially efficient but handy. Use hash tables for efficiency.
|
||||
{//-2 if Ambiguous
|
||||
// -1 if not found
|
||||
// Not efficient. Use hash tables for efficiency.
|
||||
I64 n,sub=0,result=-1;
|
||||
U8 *ptr;
|
||||
Bool exact_match=FALSE;
|
||||
if (!haystack_lst) return -1;
|
||||
n=StrLen(needle);
|
||||
while (*haystack_lst) {
|
||||
if (*haystack_lst=='@') { //Check for '@' alias haystack_lst entry
|
||||
if (*haystack_lst=='@') { //Check for '@' alias haystack_lst entry
|
||||
sub--;
|
||||
haystack_lst++;
|
||||
}
|
||||
@@ -425,29 +429,29 @@ I64 LstMatch(U8 *needle, U8 *haystack_lst,I64 flags=0)
|
||||
ptr++;
|
||||
haystack_lst++;
|
||||
}
|
||||
if (!*ptr) { // Did we reach end of needle
|
||||
if (!*haystack_lst) // Did we reach end of haystack_lst entrycount
|
||||
return sub; // Found Exact match
|
||||
if (!*ptr) { //Did we reach end of needle?
|
||||
if (!*haystack_lst) //Did we reach end of haystack_lst?
|
||||
return sub; //Found Exact match
|
||||
else {
|
||||
if (result!=-1) {
|
||||
if (!exact_match)
|
||||
result=-2; // AMBIGUOUS RESPONSE unless later exact match
|
||||
result=-2; //Ambiguous unless later exact match.
|
||||
} else {
|
||||
if (!(flags & LMF_EXACT))
|
||||
result=sub;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (*haystack_lst) // Advance to end of cur entry.
|
||||
while (*haystack_lst) //Advance to end of cur entry.
|
||||
haystack_lst++;
|
||||
haystack_lst++; // Skip trailing zero
|
||||
haystack_lst++; //Skip trailing zero
|
||||
sub++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
I64 StrOcc(U8 *src, I64 ch)
|
||||
{
|
||||
{//Count occurrences of a char.
|
||||
I64 i=0;
|
||||
if (!src) return 0;
|
||||
while (*src)
|
||||
@@ -457,7 +461,7 @@ I64 StrOcc(U8 *src, I64 ch)
|
||||
}
|
||||
|
||||
I64 Spaces2Tabs(U8 *dst,U8 *src)
|
||||
{
|
||||
{//Src buf with spaces to dst buf without.
|
||||
U8 *src2;
|
||||
I64 chged=0,space_cnt,space_cnt2,col=0;
|
||||
if (*src)
|
||||
@@ -504,7 +508,7 @@ I64 Spaces2Tabs(U8 *dst,U8 *src)
|
||||
}
|
||||
|
||||
U8 *StrUtil(U8 *_src,I64 flags)
|
||||
{//See $LK,"flags",A="MN:SUF_REM_SPACES"$
|
||||
{//See $LK,"flags",A="MN:SUF_REM_SPACES"$ for all the options.
|
||||
U8 *src=_src,*dst=_src;
|
||||
I64 ch;
|
||||
|
||||
@@ -552,7 +556,7 @@ U8 *StrUtil(U8 *_src,I64 flags)
|
||||
}
|
||||
|
||||
U8 *StrFirstOcc(U8 *src,U8 *marker)
|
||||
{
|
||||
{//Point to 1st occurrence of marker set in str.
|
||||
I64 ch;
|
||||
while ((ch=*src++) && !StrOcc(marker,ch));
|
||||
if (ch)
|
||||
@@ -562,7 +566,7 @@ U8 *StrFirstOcc(U8 *src,U8 *marker)
|
||||
}
|
||||
|
||||
U8 *StrFirstRem(U8 *src,U8 *marker,U8 *dst=NULL)
|
||||
{
|
||||
{//Remove first str segment and place in dst buf or NULL.
|
||||
I64 ch;
|
||||
U8 *ptr=src,*result=dst;
|
||||
if (dst) {
|
||||
@@ -579,7 +583,7 @@ U8 *StrFirstRem(U8 *src,U8 *marker,U8 *dst=NULL)
|
||||
}
|
||||
|
||||
U8 *StrLastOcc(U8 *src,U8 *marker)
|
||||
{
|
||||
{//Point to last occurrence of market set in str.
|
||||
I64 ch;
|
||||
U8 *result=NULL;
|
||||
while (ch=*src++)
|
||||
@@ -589,7 +593,7 @@ U8 *StrLastOcc(U8 *src,U8 *marker)
|
||||
}
|
||||
|
||||
U8 *StrLastRem(U8 *src,U8 *marker,U8 *dst=NULL)
|
||||
{
|
||||
{//Remove last str segment and place in dst buf or NULL.
|
||||
U8 *ptr;
|
||||
if (ptr=StrLastOcc(src,marker)) {
|
||||
if (dst)
|
||||
@@ -604,7 +608,7 @@ U8 *StrLastRem(U8 *src,U8 *marker,U8 *dst=NULL)
|
||||
}
|
||||
|
||||
U8 *StrFind(U8 *needle,U8 *haystack_str,I64 flags=0)
|
||||
{
|
||||
{//Find needle_str in haystack_str with options.
|
||||
Bool cont;
|
||||
U8 *saved_haystack_str=haystack_str;
|
||||
I64 plen=StrLen(needle);
|
||||
@@ -639,7 +643,7 @@ U8 *StrFind(U8 *needle,U8 *haystack_str,I64 flags=0)
|
||||
}
|
||||
|
||||
Bool WildMatch(U8 *test_str,U8 *wild_str)
|
||||
{
|
||||
{//Wildcard match with '*' and '?'.
|
||||
I64 ch1,ch2;
|
||||
U8 *fall_back_src=NULL,*fall_back_wild=NULL;
|
||||
while (TRUE) {
|
||||
|
||||
+46
-53
@@ -1,5 +1,5 @@
|
||||
U8 *Tabs2Spaces(U8 *src)
|
||||
{
|
||||
{//MAlloc str with tabs to spaces.
|
||||
I64 ch,i,j,l=StrLen(src)<<1+2,col=0;
|
||||
U8 *dst=MAlloc(l),*temp;
|
||||
while (ch=*src++) {
|
||||
@@ -33,7 +33,7 @@ U8 *Tabs2Spaces(U8 *src)
|
||||
}
|
||||
|
||||
U8 *ScaleIndent(U8 *src,F64 indent_scale_factor)
|
||||
{
|
||||
{//MAlloced str. 8*0.25-->2 or 8*2.0-->16
|
||||
I64 ch,i,col=0;
|
||||
U8 *dst,*dst2;
|
||||
while (ch=*src++) {
|
||||
@@ -56,8 +56,7 @@ U8 *ScaleIndent(U8 *src,F64 indent_scale_factor)
|
||||
}
|
||||
|
||||
U8 *MStrUtil(U8 *src,I64 flags,F64 indent_scale_factor=0)
|
||||
//Return a $LK,"MAlloc",A="MN:MAlloc"$()ed result from StrUtil
|
||||
{
|
||||
{//MAlloc $LK,"StrUtil",A="MN:StrUtil"$().
|
||||
U8 *dst=StrNew(src),*dst2,*temp;
|
||||
StrUtil(dst,flags);
|
||||
if (flags & SUF_T2S) {
|
||||
@@ -68,16 +67,16 @@ U8 *MStrUtil(U8 *src,I64 flags,F64 indent_scale_factor=0)
|
||||
if (flags & SUF_SCALE_INDENT)
|
||||
dst2=ScaleIndent(dst,indent_scale_factor);
|
||||
else
|
||||
dst2=StrNew(dst); //Shorten
|
||||
dst2=StrNew(dst); //Shorten to just right size.
|
||||
Free(dst);
|
||||
return dst2;
|
||||
}
|
||||
|
||||
U0 GetOutOfDollar()
|
||||
{
|
||||
{//If a $$ has been printed, print another $$ to exit mode.
|
||||
CDoc *doc;
|
||||
if (IsRaw) {
|
||||
if (sys_raw_flags&RWF_IN_DOLLAR)
|
||||
if (text.raw_flags&RWF_IN_DOLLAR)
|
||||
'$$';
|
||||
} else {
|
||||
if (fp_doc_put && (doc=(*fp_doc_put)(Fs)) && doc->flags&DOCF_IN_DOLLAR)
|
||||
@@ -85,20 +84,8 @@ U0 GetOutOfDollar()
|
||||
}
|
||||
}
|
||||
|
||||
U0 NewLine(I64 cnt=1)
|
||||
{
|
||||
while (cnt-->0)
|
||||
'\n';
|
||||
}
|
||||
|
||||
U0 Spaces(I64 cnt=1)
|
||||
{
|
||||
while (cnt-->0)
|
||||
'' CH_SPACE;
|
||||
}
|
||||
|
||||
Bool YorN()
|
||||
{
|
||||
{//Wait for user to answer Y or N.
|
||||
I64 ch;
|
||||
"(y or n)? ";
|
||||
while (TRUE) {
|
||||
@@ -114,73 +101,79 @@ Bool YorN()
|
||||
}
|
||||
|
||||
I64 PressAKey()
|
||||
{
|
||||
{//Print "Press a key" and wait for non-zero $LK,"ASCII",A="MN:CH_CTRLA"$ key.
|
||||
"$$BK,1$$PRESS A KEY$$BK,0$$\n";
|
||||
return GetChar(,FALSE);
|
||||
}
|
||||
|
||||
Bool AreYouSure()
|
||||
{
|
||||
{//Print "Are you sure" and waits for Y or N.
|
||||
"ARE YOU SURE ";
|
||||
return YorN;
|
||||
}
|
||||
|
||||
U0 Help()
|
||||
{
|
||||
{//Dbg help or master help index file.
|
||||
if (IsDbg)
|
||||
DbgHelp;
|
||||
else
|
||||
PopUp("Type(\"::/Doc/HelpIndex.TXT\");DocHome;View;");
|
||||
PopUp("Type(\"::/Doc/HelpIndex.TXT\");DocTop;View;");
|
||||
}
|
||||
|
||||
U0 ScanFlags(U8 *_dst_flags,U8 *lst,U8 *src)
|
||||
{/*More than 64 flags. Flags passed by ref.
|
||||
|
||||
U0 ScanFlags(U8 *f,U8 *lst,U8 *st)
|
||||
{
|
||||
Examples:
|
||||
$LK,"ScanFlags",A="FF:::/Adam/Utils/Diff.CPP,ScanFlags:2"$(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
|
||||
|
||||
I64 flags=0;
|
||||
ScanFlags(&flags,"R\0L\0Dump\0Scan\0","+Dump-R"); //Sets Bit#2, Clears Bit#0.
|
||||
*/
|
||||
I64 i;
|
||||
U8 *st2,*ptr;
|
||||
if (st) {
|
||||
st2=MAlloc(StrLen(st)+1);
|
||||
while (*st) {
|
||||
while (*st && *st!='+' && *st!='-')
|
||||
st++;
|
||||
if (*st=='+') {
|
||||
st++;
|
||||
if (*st) {
|
||||
ptr=st2;
|
||||
while (*st && *st!='+' && *st!='-' && *st!=CH_SPACE && *st!=CH_SHIFT_SPACE)
|
||||
*ptr++=*st++;
|
||||
U8 *buf,*ptr;
|
||||
if (src) {
|
||||
buf=MAlloc(StrLen(src)+1);
|
||||
while (*src) {
|
||||
while (*src && *src!='+' && *src!='-')
|
||||
src++;
|
||||
if (*src=='+') {
|
||||
src++;
|
||||
if (*src) {
|
||||
ptr=buf;
|
||||
while (*src && *src!='+' && *src!='-' && *src!=CH_SPACE && *src!=CH_SHIFT_SPACE)
|
||||
*ptr++=*src++;
|
||||
*ptr=0;
|
||||
i=LstMatch(st2,lst);
|
||||
i=LstMatch(buf,lst);
|
||||
if (i>=0)
|
||||
LBts(f,i);
|
||||
LBts(_dst_flags,i);
|
||||
else {
|
||||
Free(st2);
|
||||
Free(buf);
|
||||
throw('ScanFlag');
|
||||
}
|
||||
}
|
||||
} else if (*st=='-') {
|
||||
st++;
|
||||
if (*st) {
|
||||
ptr=st2;
|
||||
while (*st && *st!='+' && *st!='-' && *st!=CH_SPACE && *st!=CH_SHIFT_SPACE)
|
||||
*ptr++=*st++;
|
||||
} else if (*src=='-') {
|
||||
src++;
|
||||
if (*src) {
|
||||
ptr=buf;
|
||||
while (*src && *src!='+' && *src!='-' && *src!=CH_SPACE && *src!=CH_SHIFT_SPACE)
|
||||
*ptr++=*src++;
|
||||
*ptr=0;
|
||||
i=LstMatch(st2,lst);
|
||||
i=LstMatch(buf,lst);
|
||||
if (i>=0)
|
||||
LBtr(f,i);
|
||||
LBtr(_dst_flags,i);
|
||||
else {
|
||||
Free(st2);
|
||||
Free(buf);
|
||||
throw('ScanFlag');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Free(st2);
|
||||
Free(buf);
|
||||
}
|
||||
}
|
||||
|
||||
U8 *SPrintFlags(U8 *dst,U8 *lst,I64 flags)
|
||||
{
|
||||
U8 *StrPrintFlags(U8 *dst,U8 *lst,I64 flags)
|
||||
{//Only 64 flags. Flags passed by value.
|
||||
I64 i;
|
||||
*dst=0;
|
||||
while (flags) {
|
||||
|
||||
+100
-98
@@ -5,11 +5,11 @@
|
||||
#define SPF_DOLLAR 0x010
|
||||
#define SPF_SLASH 0x020
|
||||
#define SPF_QUESTION 0x040
|
||||
#define SPF_SUB_FMT 0x080
|
||||
#define SPF_AUX_FMT_NUM 0x080
|
||||
#define SPF_DECIMAL 0x100
|
||||
#define SPF_NEG 0x200
|
||||
#define SPF_NEG_E 0x400
|
||||
#define SPF_NEG_SUB_FMT 0x800
|
||||
#define SPF_NEG_AUX_FMT_NUM 0x800
|
||||
|
||||
U0 SPutChar(U8 **_dst,U8 ch,U8 **_buf)
|
||||
{
|
||||
@@ -55,14 +55,14 @@ U8 *MPrintTime(CDate cdt)
|
||||
{
|
||||
CDateStruct ds;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
return MPrint("%02d:%02d:%02d",ds.hour,ds.min,ds.sec);
|
||||
return MStrPrint("%02d:%02d:%02d",ds.hour,ds.min,ds.sec);
|
||||
}
|
||||
|
||||
U8 *MPrintDate(CDate cdt)
|
||||
{
|
||||
CDateStruct ds;
|
||||
Date2Struct(&ds,cdt+local_time_offset);
|
||||
return MPrint("%02d/%02d/%02d",ds.mon,ds.day_of_mon,ds.year%100);
|
||||
return MStrPrint("%02d/%02d/%02d",ds.mon,ds.day_of_mon,ds.year%100);
|
||||
}
|
||||
|
||||
U8 *MPrintQ(U8 *ptr,I64 flags)
|
||||
@@ -244,22 +244,23 @@ U8 *sys_pos_powers_lets=" KMGTPEZY",
|
||||
#define TEMP_BUF_LEN 256
|
||||
#define SLOP 8
|
||||
|
||||
U8 *SPrintJoin(U8 *dst,U8 *src,I64 argc,I64 *argv)
|
||||
{//$LK,"Print Extended Codes",A="FA:::/Doc/HolyC.TXT,SPrintCodes"$
|
||||
// In float formatting, do not exceed 18-digits
|
||||
// before or after the decimal point
|
||||
// because the numbers before and after
|
||||
// the decimal point are stored
|
||||
// in 64-bits. Use exponentiated forms
|
||||
// to avoid this.
|
||||
U8 *StrPrintJoin(U8 *dst,U8 *src,I64 argc,I64 *argv)
|
||||
{/*$LK,"Print(\"\") Fmt Strings",A="FI:::/Doc/Print.TXT"$
|
||||
In float formatting, do not exceed 18-digits
|
||||
before or after the decimal point
|
||||
because the numbers before and after
|
||||
the decimal point are stored
|
||||
in 64-bits. Use exponentiated forms
|
||||
to avoid this.
|
||||
*/
|
||||
I64 i,j,l,ch,k,k0,n,n0,len,dec_len,flags,
|
||||
sub_fmt,comma_cnt,comma_fmt_cnt,cur_arg=0;
|
||||
aux_fmt_num,comma_cnt,comma_fmt_cnt,cur_arg=0;
|
||||
U64 m;
|
||||
F64 d,d1;
|
||||
U8 *ptr,**_buf,*buf,**_dst,temp_buf[TEMP_BUF_LEN],temp_buf2[TEMP_BUF_LEN*2];
|
||||
|
||||
if (!src)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
if (dst) {
|
||||
_buf=NULL;
|
||||
buf=dst;
|
||||
@@ -287,7 +288,7 @@ U8 *SPrintJoin(U8 *dst,U8 *src,I64 argc,I64 *argv)
|
||||
if (*src=='*') {
|
||||
src++;
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
len=argv[cur_arg++];
|
||||
}
|
||||
dec_len=0;
|
||||
@@ -298,12 +299,13 @@ U8 *SPrintJoin(U8 *dst,U8 *src,I64 argc,I64 *argv)
|
||||
if (*src=='*') {
|
||||
src++;
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
dec_len=argv[cur_arg++];
|
||||
}
|
||||
flags|=SPF_DECIMAL;
|
||||
}
|
||||
|
||||
aux_fmt_num=0;
|
||||
while (TRUE) {
|
||||
switch (*src) {
|
||||
sub_switch_start:
|
||||
@@ -325,64 +327,62 @@ U8 *SPrintJoin(U8 *dst,U8 *src,I64 argc,I64 *argv)
|
||||
src++;
|
||||
break;
|
||||
|
||||
default:
|
||||
goto sp_in_sub_fmt;
|
||||
}
|
||||
}
|
||||
|
||||
sp_in_sub_fmt:
|
||||
sub_fmt=0;
|
||||
if (*src=='h') {
|
||||
src++;
|
||||
flags|=SPF_SUB_FMT;
|
||||
if (*src=='?') {
|
||||
src++;
|
||||
flags|=SPF_QUESTION;
|
||||
} else {
|
||||
if (*src=='*') {
|
||||
case 'h':
|
||||
src++;
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
sub_fmt=argv[cur_arg++];
|
||||
} else {
|
||||
if (*src=='-') {
|
||||
flags|=SPF_AUX_FMT_NUM;
|
||||
if (*src=='?') {
|
||||
src++;
|
||||
flags|=SPF_NEG_SUB_FMT;
|
||||
flags|=SPF_QUESTION;
|
||||
} else {
|
||||
if (*src=='*') {
|
||||
src++;
|
||||
if (cur_arg>=argc)
|
||||
throw('StrPrint');
|
||||
aux_fmt_num=argv[cur_arg++];
|
||||
} else {
|
||||
if (*src=='-') {
|
||||
src++;
|
||||
flags|=SPF_NEG_AUX_FMT_NUM;
|
||||
}
|
||||
while ('0'<=*src<='9')
|
||||
aux_fmt_num=aux_fmt_num*10+ *src++ -'0';
|
||||
if (flags&SPF_NEG_AUX_FMT_NUM)
|
||||
aux_fmt_num=-aux_fmt_num;
|
||||
}
|
||||
}
|
||||
while ('0'<=*src<='9')
|
||||
sub_fmt=sub_fmt*10+ *src++ -'0';
|
||||
if (flags&SPF_NEG_SUB_FMT)
|
||||
sub_fmt=-sub_fmt;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
goto sp_arg;
|
||||
}
|
||||
}
|
||||
|
||||
sp_arg:
|
||||
k=0;
|
||||
switch (*src++) {
|
||||
sub_switch_start:
|
||||
case 'F':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
ptr=FileRead(argv[cur_arg++]);
|
||||
break;
|
||||
case 'Q':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
ptr=MPrintQ(argv[cur_arg++],flags);
|
||||
break;
|
||||
case 'q':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
ptr=MPrintq(argv[cur_arg++],flags);
|
||||
break;
|
||||
case 'D':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
ptr=MPrintDate(argv[cur_arg++]);
|
||||
break;
|
||||
case 'T':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
ptr=MPrintTime(argv[cur_arg++]);
|
||||
break;
|
||||
sub_switch_end:
|
||||
@@ -393,23 +393,23 @@ sp_in_sub_fmt:
|
||||
sub_switch_start:
|
||||
case 's':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
ptr=argv[cur_arg++];
|
||||
break;
|
||||
case 'S':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
ptr=Define(argv[cur_arg++]);
|
||||
break;
|
||||
case 'z':
|
||||
if (cur_arg+1>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
ptr=LstSub(argv[cur_arg],argv[cur_arg+1]);
|
||||
cur_arg=cur_arg+2;
|
||||
break;
|
||||
case 'Z':
|
||||
if (cur_arg+1>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
ptr=DefineSub(argv[cur_arg],argv[cur_arg+1]);
|
||||
cur_arg=cur_arg+2;
|
||||
break;
|
||||
@@ -420,13 +420,13 @@ sp_in_sub_fmt:
|
||||
sub_switch_start:
|
||||
case 'c':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
temp_buf[0](I64)=argv[cur_arg++];
|
||||
temp_buf[8]=0;
|
||||
break;
|
||||
case 'C':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
temp_buf[0](I64)=argv[cur_arg++];
|
||||
temp_buf[8]=0;
|
||||
ptr=temp_buf;
|
||||
@@ -435,27 +435,31 @@ sp_in_sub_fmt:
|
||||
ptr++;
|
||||
}
|
||||
break;
|
||||
case 'p':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
if (flags&SPF_TRUNCATE)
|
||||
SPrintPSect(temp_buf,argv[cur_arg++],len);
|
||||
else
|
||||
SPrintPSect(temp_buf,argv[cur_arg++],0);
|
||||
break;
|
||||
sub_switch_end:
|
||||
OutStr(temp_buf,_buf,_dst,len,flags);
|
||||
if (!(flags&SPF_AUX_FMT_NUM))
|
||||
aux_fmt_num=1;
|
||||
while (aux_fmt_num-->0)
|
||||
OutStr(temp_buf,_buf,_dst,len,flags);
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
if (cur_arg>=argc)
|
||||
throw('StrPrint');
|
||||
if (flags&SPF_TRUNCATE)
|
||||
StrPrintPSect(temp_buf,argv[cur_arg++],len);
|
||||
else
|
||||
StrPrintPSect(temp_buf,argv[cur_arg++],0);
|
||||
OutStr(temp_buf,_buf,_dst,len,flags);
|
||||
break;
|
||||
case 'P':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
if (flags&SPF_TRUNCATE)
|
||||
SPrintPSect(temp_buf,argv[cur_arg],len);
|
||||
StrPrintPSect(temp_buf,argv[cur_arg],len);
|
||||
else
|
||||
SPrintPSect(temp_buf,argv[cur_arg],0);
|
||||
StrPrintPSect(temp_buf,argv[cur_arg],0);
|
||||
if (!IsRaw || !_buf) {
|
||||
SPrint(temp_buf2,"$$LK,\"%s\",A=\"AD:0x%X\"$$",temp_buf,argv[cur_arg]);
|
||||
StrPrint(temp_buf2,"$$LK,\"%s\",A=\"AD:0x%X\"$$",temp_buf,argv[cur_arg]);
|
||||
OutStr(temp_buf2,_buf,_dst,len,flags);
|
||||
} else
|
||||
OutStr(temp_buf,_buf,_dst,len,flags);
|
||||
@@ -463,14 +467,14 @@ sp_in_sub_fmt:
|
||||
break;
|
||||
case 'd':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
m=argv[cur_arg++];
|
||||
if (m(I64)<0) {
|
||||
flags|=SPF_NEG;
|
||||
m=-m;
|
||||
}
|
||||
sp_out_dec:
|
||||
if (flags&SPF_SUB_FMT) {
|
||||
if (flags&SPF_AUX_FMT_NUM) {
|
||||
if (!len) len=12;
|
||||
d=m;
|
||||
goto sp_out_eng;
|
||||
@@ -548,12 +552,12 @@ sp_out_num:
|
||||
break;
|
||||
case 'u':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
m=argv[cur_arg++];
|
||||
goto sp_out_dec;
|
||||
case 'f':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
d=argv[cur_arg++](F64);
|
||||
if (d<0) {
|
||||
flags|=SPF_NEG;
|
||||
@@ -582,7 +586,7 @@ sp_out_inf:
|
||||
break;
|
||||
}
|
||||
|
||||
sp_out_f:
|
||||
sp_out_f:
|
||||
if (dec_len<0)
|
||||
dec_len=0;
|
||||
n=Log10(d);
|
||||
@@ -660,7 +664,7 @@ sp_out_inf:
|
||||
flags|=SPF_TRUNCATE;
|
||||
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
d=argv[cur_arg++](F64);
|
||||
if (d<0) {
|
||||
flags|=SPF_NEG;
|
||||
@@ -668,7 +672,6 @@ sp_out_inf:
|
||||
}
|
||||
if (d==ì) goto sp_out_inf;
|
||||
|
||||
|
||||
if (d)
|
||||
n=Floor(Log10(d));
|
||||
else
|
||||
@@ -716,7 +719,7 @@ sp_out_e:
|
||||
if (!len) len=12;
|
||||
flags|=SPF_TRUNCATE;
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
d=argv[cur_arg++](F64);
|
||||
if (d<0) {
|
||||
flags|=SPF_NEG;
|
||||
@@ -735,7 +738,7 @@ sp_out_e:
|
||||
if (!len) len=12;
|
||||
flags|=SPF_TRUNCATE;
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
d=argv[cur_arg++](F64);
|
||||
if (d<0) {
|
||||
flags|=SPF_NEG;
|
||||
@@ -753,7 +756,7 @@ sp_out_eng: //Engineering notation
|
||||
n=-n;
|
||||
flags|=SPF_NEG_E;
|
||||
}
|
||||
if (flags&SPF_SUB_FMT && -24<=n<=24) {
|
||||
if (flags&SPF_AUX_FMT_NUM && -24<=n<=24) {
|
||||
if (flags&SPF_QUESTION) {
|
||||
if (flags&SPF_NEG_E)
|
||||
i=-n/3;
|
||||
@@ -762,11 +765,11 @@ sp_out_eng: //Engineering notation
|
||||
j=0;
|
||||
} else {
|
||||
if (flags&SPF_NEG_E)
|
||||
j=-n-sub_fmt;
|
||||
j=-n-aux_fmt_num;
|
||||
else
|
||||
j=n-sub_fmt;
|
||||
j=n-aux_fmt_num;
|
||||
d*=Pow10I64(j);
|
||||
i=sub_fmt/3;
|
||||
i=aux_fmt_num/3;
|
||||
}
|
||||
if (i<0)
|
||||
temp_buf[k++]=sys_neg_powers_lets[-i];
|
||||
@@ -818,7 +821,7 @@ sp_out_eng: //Engineering notation
|
||||
goto sp_out_f;
|
||||
case 'X':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
m=argv[cur_arg++];
|
||||
if (flags&SPF_COMMA) {
|
||||
comma_fmt_cnt=comma_cnt=4;
|
||||
@@ -845,7 +848,7 @@ sp_out_eng: //Engineering notation
|
||||
}
|
||||
case 'x':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
m=argv[cur_arg++];
|
||||
if (flags&SPF_COMMA) {
|
||||
comma_fmt_cnt=comma_cnt=4;
|
||||
@@ -873,7 +876,7 @@ sp_out_eng: //Engineering notation
|
||||
case 'b':
|
||||
case 'B':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
m=argv[cur_arg++];
|
||||
if (flags&SPF_COMMA) {
|
||||
comma_fmt_cnt=comma_cnt=4;
|
||||
@@ -897,7 +900,7 @@ sp_out_eng: //Engineering notation
|
||||
case 'o':
|
||||
case 'O':
|
||||
if (cur_arg>=argc)
|
||||
throw('SPrint');
|
||||
throw('StrPrint');
|
||||
m=argv[cur_arg++];
|
||||
if (flags&SPF_COMMA) {
|
||||
comma_fmt_cnt=comma_cnt=3;
|
||||
@@ -929,47 +932,46 @@ sp_out_eng: //Engineering notation
|
||||
return buf;
|
||||
}
|
||||
|
||||
U8 *SPrint(U8 *dst,U8 *fmt,...)
|
||||
{ //See $LK,"SPrintJoin",A="MN:SPrintJoin"$()
|
||||
return SPrintJoin(dst,fmt,argc,argv);
|
||||
U8 *StrPrint(U8 *dst,U8 *fmt,...)
|
||||
{//See $LK,"StrPrintJoin",A="MN:StrPrintJoin"$().
|
||||
return StrPrintJoin(dst,fmt,argc,argv);
|
||||
}
|
||||
|
||||
U8 *CatPrint(U8 *_dst,U8 *fmt,...)
|
||||
{ //StrCat(). See $LK,"SPrintJoin",A="MN:SPrintJoin"$()
|
||||
{//StrCat(). See $LK,"StrPrintJoin",A="MN:StrPrintJoin"$().
|
||||
U8 *dst=_dst;
|
||||
while (*dst)
|
||||
dst++;
|
||||
SPrintJoin(dst,fmt,argc,argv);
|
||||
StrPrintJoin(dst,fmt,argc,argv);
|
||||
return _dst;
|
||||
}
|
||||
|
||||
U0 Print(U8 *fmt,...)
|
||||
{//$LK,"Print Extended Codes",A="FA:::/Doc/HolyC.TXT,SPrintCodes"$
|
||||
//See $LK,"SPrintJoin",A="MN:SPrintJoin"$()
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
{//$LK,"Print(\"\") Fmt Strings",A="FI:::/Doc/Print.TXT"$. See $LK,"StrPrintJoin",A="MN:StrPrintJoin"$().
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
PutS(buf);
|
||||
Free(buf);
|
||||
}
|
||||
|
||||
U8 *MPrint(U8 *fmt,...)
|
||||
{ //See $LK,"SPrintJoin",A="MN:SPrintJoin"$()
|
||||
U8 *result,*buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
U8 *MStrPrint(U8 *fmt,...)
|
||||
{//MAlloc StrPrint. See $LK,"StrPrintJoin",A="MN:StrPrintJoin"$().
|
||||
U8 *result,*buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
result=StrNew(buf);
|
||||
Free(buf);
|
||||
return result;
|
||||
}
|
||||
|
||||
U0 PrintErr(U8 *fmt,...)
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
{//Print "Err:" and msg in blinking red.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
GetOutOfDollar;
|
||||
ST_ERR_ST "%s",buf;
|
||||
Free(buf);
|
||||
}
|
||||
|
||||
U0 PrintWarn(U8 *fmt,...)
|
||||
{
|
||||
U8 *buf=SPrintJoin(NULL,fmt,argc,argv);
|
||||
{//Print "Warn:" and msg in blinking red.
|
||||
U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
GetOutOfDollar;
|
||||
ST_WARN_ST "%s",buf;
|
||||
Free(buf);
|
||||
|
||||
+46
-61
@@ -1,7 +1,7 @@
|
||||
I64 A2I64(U8 *st,I64 radix=10,U8 **_end_ptr=NULL)
|
||||
{//ASCII to I64. Similar to strtoul().
|
||||
I64 Str2I64(U8 *st,I64 radix=10,U8 **_end_ptr=NULL)
|
||||
{//String to I64. Similar to strtoul().
|
||||
//Allows radix change with "0x20" "0b1010" "0d123" "0o18".
|
||||
//Be careful of A2I64("0b101",16)-->0xB101.
|
||||
//Be careful of Str2I64("0b101",16)-->0xB101.
|
||||
Bool neg=FALSE;
|
||||
I64 ch,result=0;
|
||||
if (!st || !(2<=radix<=36)) {
|
||||
@@ -53,8 +53,8 @@ ai_cont:
|
||||
return result;
|
||||
}
|
||||
|
||||
F64 A2F64(U8 *src,U8 **_end_ptr=NULL)
|
||||
{/*ASCII string to F64.
|
||||
F64 Str2F64(U8 *src,U8 **_end_ptr=NULL)
|
||||
{/*String to F64.
|
||||
Does not allow more than 18-digits
|
||||
before or after the decimal point
|
||||
because the numbers before and after
|
||||
@@ -136,13 +136,8 @@ a2f_end:
|
||||
return d;
|
||||
}
|
||||
|
||||
/*
|
||||
A2Date()
|
||||
This routine recognizes the following formats:
|
||||
1) "*+nnnn" "*-nnnn"
|
||||
2) mm/dd
|
||||
3) mm/dd/yy
|
||||
|
||||
CDate Str2Date(U8 *_src)
|
||||
{/*"*+nnnn", "*-nnnn", "mm/dd", "mm/dd/yy"
|
||||
It also supports some funs
|
||||
SM() start of mon
|
||||
EM() end of mon
|
||||
@@ -153,54 +148,51 @@ but you can do stuff like SM(*-7)+3
|
||||
and it will return the 3rd day after
|
||||
the start of mon for seven days before
|
||||
today.
|
||||
|
||||
*/
|
||||
CDate A2Date(U8 *_src)
|
||||
//ASCII date to CDate
|
||||
{
|
||||
CDate result=0;
|
||||
CDateStruct ds;
|
||||
CDateStruct ds,ds_now;
|
||||
U8 *src=MStrUtil(_src,SUF_REM_SPACES|SUF_TO_UPPER),
|
||||
*v=StrNew(src),
|
||||
*p1=src;
|
||||
*ptr=src;
|
||||
Bool start_mon=FALSE,end_mon=FALSE,
|
||||
start_year=FALSE,end_year=FALSE;
|
||||
|
||||
MemSet(&ds,0,sizeof(CDateStruct));
|
||||
if (!StrNCmp(p1,"SM(",3)) {
|
||||
p1+=3;
|
||||
if (!StrNCmp(ptr,"SM(",3)) {
|
||||
ptr+=3;
|
||||
start_mon=TRUE;
|
||||
} else if (!StrNCmp(p1,"EM(",3)) {
|
||||
p1+=3;
|
||||
} else if (!StrNCmp(ptr,"EM(",3)) {
|
||||
ptr+=3;
|
||||
end_mon=TRUE;
|
||||
} else if (!StrNCmp(p1,"SY(",3)) {
|
||||
p1+=3;
|
||||
} else if (!StrNCmp(ptr,"SY(",3)) {
|
||||
ptr+=3;
|
||||
start_year=TRUE;
|
||||
} else if (!StrNCmp(p1,"EY(",3)) {
|
||||
p1+=3;
|
||||
} else if (!StrNCmp(ptr,"EY(",3)) {
|
||||
ptr+=3;
|
||||
end_year=TRUE;
|
||||
}
|
||||
if (*p1=='*') {
|
||||
p1++;
|
||||
if (*p1=='+' || *p1=='-')
|
||||
result.date=A2I64(p1,,&p1);
|
||||
if (*ptr=='*') {
|
||||
ptr++;
|
||||
if (*ptr=='+' || *ptr=='-')
|
||||
result.date=Str2I64(ptr,,&ptr);
|
||||
result+=Now+local_time_offset;
|
||||
} else {
|
||||
StrFirstRem(p1,"/",v); //Put mon into v
|
||||
ds.mon=A2I64(v);
|
||||
if (StrOcc(p1,'/')) {
|
||||
StrFirstRem(p1,"/",v); //Put day into v leaving year in p1
|
||||
ds.day_of_mon=A2I64(v);
|
||||
ds.year=A2I64(p1,,&p1);
|
||||
StrFirstRem(ptr,"/",v); //Put mon into v
|
||||
ds.mon=Str2I64(v);
|
||||
if (StrOcc(ptr,'/')) {
|
||||
StrFirstRem(ptr,"/",v); //Put day into v leaving year in ptr
|
||||
ds.day_of_mon=Str2I64(v);
|
||||
ds.year=Str2I64(ptr,,&ptr);
|
||||
if (ds.year<100) //if not 4 digit year
|
||||
ds.year+=2000;
|
||||
} else {
|
||||
ds.day_of_mon=A2I64(p1,,&p1);
|
||||
ds.year=Year;
|
||||
ds.day_of_mon=Str2I64(ptr,,&ptr);
|
||||
Date2Struct(&ds_now,Now+local_time_offset);
|
||||
ds.year=ds_now.year;
|
||||
}
|
||||
result=Struct2Date(&ds);
|
||||
}
|
||||
if (*p1==')') p1++;
|
||||
if (*ptr==')') ptr++;
|
||||
|
||||
if (start_mon)
|
||||
result.date=FirstDayOfMon(result.date);
|
||||
@@ -211,21 +203,22 @@ CDate A2Date(U8 *_src)
|
||||
else if (end_year)
|
||||
result.date=LastDayOfYear(result.date);
|
||||
|
||||
if (*p1=='+' || *p1=='-')
|
||||
result.date+=A2I64(p1);
|
||||
if (*ptr=='+' || *ptr=='-')
|
||||
result.date+=Str2I64(ptr);
|
||||
Free(src);
|
||||
Free(v);
|
||||
return result-local_time_offset;
|
||||
}
|
||||
|
||||
U8 *ScanJoin(U8 *src,U8 *fmt,I64i argc,I64i *argv)
|
||||
//Pass ptr to data,
|
||||
//For %s pass ptr to ptr (be careful because addr
|
||||
//of array is the same as array--create ptr to array and take addr
|
||||
{
|
||||
U8 ch,*buf,*ptr,**pptr;
|
||||
U8 *StrScan(U8 *src,U8 *fmt,...)
|
||||
{/*Opposite of sprintf(). Pass ptrs to data to be scanned-in.
|
||||
For "%s", pass ptr to ptr (be careful because addr
|
||||
of array is the same as array--create ptr to array
|
||||
and take addr.
|
||||
*/
|
||||
U8 *buf,*ptr,**pptr;
|
||||
Bool left_justify=FALSE;
|
||||
I64 cur_arg=0,i,len,*i_ptr,dec_len;
|
||||
I64 ch,cur_arg=0,i,len,*i_ptr,dec_len;
|
||||
F64 *d_ptr;
|
||||
if (!fmt)
|
||||
throw('Scan');
|
||||
@@ -308,19 +301,19 @@ U8 *ScanJoin(U8 *src,U8 *fmt,I64i argc,I64i *argv)
|
||||
if (cur_arg>=argc)
|
||||
throw('Scan');
|
||||
i_ptr=argv[cur_arg++];
|
||||
*i_ptr=A2I64(buf);
|
||||
*i_ptr=Str2I64(buf);
|
||||
break;
|
||||
case 'X':
|
||||
if (cur_arg>=argc)
|
||||
throw('Scan');
|
||||
i_ptr=argv[cur_arg++];
|
||||
*i_ptr=A2I64(buf,16);
|
||||
*i_ptr=Str2I64(buf,16);
|
||||
break;
|
||||
case 'b':
|
||||
if (cur_arg>=argc)
|
||||
throw('Scan');
|
||||
i_ptr=argv[cur_arg++];
|
||||
*i_ptr=A2I64(buf,2);
|
||||
*i_ptr=Str2I64(buf,2);
|
||||
break;
|
||||
case 'e':
|
||||
case 'f':
|
||||
@@ -329,13 +322,13 @@ U8 *ScanJoin(U8 *src,U8 *fmt,I64i argc,I64i *argv)
|
||||
if (cur_arg>=argc)
|
||||
throw('Scan');
|
||||
d_ptr=argv[cur_arg++];
|
||||
*d_ptr=A2F64(buf);
|
||||
*d_ptr=Str2F64(buf);
|
||||
break;
|
||||
case 'D':
|
||||
if (cur_arg>=argc)
|
||||
throw('Scan');
|
||||
i_ptr=argv[cur_arg++];
|
||||
*i_ptr=A2Date(buf);
|
||||
*i_ptr=Str2Date(buf);
|
||||
break;
|
||||
}
|
||||
Free(buf);
|
||||
@@ -345,11 +338,3 @@ U8 *ScanJoin(U8 *src,U8 *fmt,I64i argc,I64i *argv)
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
U8 *Scan(U8 *src,U8 *fmt,...)
|
||||
//Pass ptr to data,
|
||||
//For %s pass ptr to ptr (be careful because addr
|
||||
//of array is the same as array--create ptr to array and take addr
|
||||
{
|
||||
return ScanJoin(src,fmt,argc,argv);
|
||||
}
|
||||
+26
-35
@@ -1,5 +1,5 @@
|
||||
U0 Exit()
|
||||
{
|
||||
{//Terminate own task.
|
||||
if (Fs==sys_focus_task && IsDbg) {
|
||||
LBts(&Fs->task_flags,TASKf_KILL_AFTER_DBG);
|
||||
G;
|
||||
@@ -17,7 +17,7 @@ U0 Exit()
|
||||
}
|
||||
|
||||
Bool TaskValidate(CTask *task)
|
||||
{
|
||||
{//return TRUE if task looks valid.
|
||||
if (!(0<task<=MAX_I32) || task->addr!=task ||
|
||||
task->task_signature(I64)!=TASK_COMBINED_SIGNATURE_VAL)
|
||||
return FALSE;
|
||||
@@ -26,7 +26,7 @@ Bool TaskValidate(CTask *task)
|
||||
}
|
||||
|
||||
U0 Kill(CTask *task,Bool wait=TRUE)
|
||||
{
|
||||
{//Terminate other task.
|
||||
I64 i;
|
||||
CCPU *c;
|
||||
Bool found,old_preempt=Preempt(OFF);
|
||||
@@ -52,7 +52,7 @@ U0 Kill(CTask *task,Bool wait=TRUE)
|
||||
}
|
||||
|
||||
Bool Suspend(CTask *task=NULL,Bool state=TRUE)
|
||||
{
|
||||
{//Tell scheduler to skip task.
|
||||
Bool result;
|
||||
if (!task) task=Fs;
|
||||
PUSHFD
|
||||
@@ -83,11 +83,9 @@ CTaskStk *TaskStkNew(I64 stk_size,CTask *task)
|
||||
return temps;
|
||||
}
|
||||
|
||||
|
||||
#exe {OptOn(OPTf_NO_REG_VAR);};
|
||||
//fp_addr can have any fixed number of arguments.
|
||||
argpop I64 CallStkGrow(I64 stk_size_threshold,I64 stk_size,/*argpop*/I64 (*fp_addr)(...),...)
|
||||
{
|
||||
{//Grow stk in call with any fixed num of args.
|
||||
CTaskStk *temps,*temps2,**_stk;
|
||||
I64 result,*rsp,*rsp2,*old_stk;
|
||||
|
||||
@@ -157,7 +155,7 @@ asm {
|
||||
#exe {OptOff(OPTf_NO_REG_VAR);};
|
||||
|
||||
I64 TaskInit(CTask *task,I64 stk_size)
|
||||
{ //Returns Fs of task
|
||||
{//Returns Fs of task
|
||||
CTaskStk *temps;
|
||||
|
||||
QueInit(&task->code_heap->next_mem_blk);
|
||||
@@ -172,7 +170,6 @@ I64 TaskInit(CTask *task,I64 stk_size)
|
||||
|
||||
task->rflags=SYS_NORMAL_RFLAGS;
|
||||
task->win_inhibit=WIG_TASK_DFT;
|
||||
task->win_max_refresh=WIN_DFT_MAX_REFRESH;
|
||||
|
||||
task->next_child_task=task->last_child_task=
|
||||
(&task->next_child_task)(U8 *)-offset(CTask.next_sibling_task);
|
||||
@@ -205,18 +202,17 @@ I64 TaskInit(CTask *task,I64 stk_size)
|
||||
task->stk=temps=TaskStkNew(stk_size,task);
|
||||
task->rsp=(&temps->stk_base)(U8 *)+temps->stk_size;
|
||||
|
||||
task->answers_displayed=1; //from 0-3
|
||||
task->text_attr =TERM_ATTR_TEXT;
|
||||
task->border_attr =TERM_ATTR_BORDER;
|
||||
task->border_src =BDS_CONST;
|
||||
task->title_src =TTS_CONST;
|
||||
task->win_left =1;
|
||||
task->win_right =text_cols-2;
|
||||
task->win_right =text.cols-2;
|
||||
task->win_top =13;
|
||||
task->win_bottom =text_rows-2;
|
||||
task->win_bottom =text.rows-2;
|
||||
|
||||
//Beware Adam $LK,"TaskInit",A="FF:::/Kernel/KStart.CPP,TaskInit"$ gets NULL. Okay, I guess, until $LK,"ChgDsk",A="FF:::/Kernel/KEnd.CPP,ChgDsk"$().
|
||||
task->cur_prt=drv_to_prt[ToUpper(*sys_acct)-'A'];
|
||||
task->cur_prt=dsk.drv_to_prt[ToUpper(*sys_acct)-'A'];
|
||||
task->cur_dir=StrNew(sys_acct+2,task);
|
||||
|
||||
return task;
|
||||
@@ -224,13 +220,13 @@ I64 TaskInit(CTask *task,I64 stk_size)
|
||||
|
||||
CTask *Spawn(U0 (*fp_start_addr)(U8 *data),U8 *data=NULL,
|
||||
U8 *task_name=NULL,
|
||||
I64 target_cpu=-1, //-1 means current CPU
|
||||
I64 target_cpu=-1, //-1 means current CPU. See $LK,"multi-core",A="FI:::/Demo/MultiCore/LoadTest.CPP"$.
|
||||
CTask *parent=NULL, //NULL means adam
|
||||
I64 stk_size=0, //0=default
|
||||
I64 flags=1<<SVCf_ADD_TO_QUE)
|
||||
{
|
||||
//We alloc from code heap so addr will be short
|
||||
//Could be allocated off of data heap
|
||||
{//Create task on core running at address.
|
||||
//Alloc $LK,"CTask",A="MN:CTask"$ structure from code heap so addr will be short.
|
||||
//Could be allocated off of data heap.
|
||||
CTask *task;
|
||||
if (target_cpu>=0)
|
||||
return SpawnQue(fp_start_addr,data,task_name,target_cpu,parent,stk_size,flags);
|
||||
@@ -267,7 +263,7 @@ CTask *Spawn(U0 (*fp_start_addr)(U8 *data),U8 *data=NULL,
|
||||
}
|
||||
|
||||
U0 TaskDerivedValsUpdate(CTask *task=NULL,Bool update_z_buf=TRUE)
|
||||
{
|
||||
{//Those things calculated from other variables.
|
||||
if (!task) task=Fs;
|
||||
PUSHFD
|
||||
CLI
|
||||
@@ -283,8 +279,8 @@ U0 TaskDerivedValsUpdate(CTask *task=NULL,Bool update_z_buf=TRUE)
|
||||
}
|
||||
|
||||
I64 ExeCmdLine(CLex *lx)
|
||||
{
|
||||
I64 result=0,i,type,old_title_src=Fs->title_src;
|
||||
{//Terminal JIT-compile-and-execute loop for CLex.
|
||||
I64 result=0,type,old_title_src=Fs->title_src;
|
||||
U8 *ptr,*ptr2,*ptr3,*ex,*old_task_title=StrNew(Fs->task_title);
|
||||
F64 t0;
|
||||
CDocEntry *doc_e;
|
||||
@@ -324,14 +320,9 @@ I64 ExeCmdLine(CLex *lx)
|
||||
if (!(lx->flags&LF_JUST_LOAD)) {
|
||||
t0=tS;
|
||||
result=Call(ex);
|
||||
for (i=2;i>=0;i--) {
|
||||
Fs->answers[i+1]=Fs->answers[i];
|
||||
Fs->answer_types[i+1]=Fs->answer_types[i];
|
||||
Fs->answer_times[i+1]=Fs->answer_times[i];
|
||||
}
|
||||
Fs->answers[0]=result;
|
||||
Fs->answer_types[0]=type;
|
||||
Fs->answer_times[0]=tS-t0;
|
||||
Fs->answer=result;
|
||||
Fs->answer_type=type;
|
||||
Fs->answer_time=tS-t0;
|
||||
}
|
||||
if (!(lx->flags&LF_HAS_MISC_DATA))
|
||||
Free(ex);
|
||||
@@ -352,7 +343,7 @@ I64 ExeCmdLine(CLex *lx)
|
||||
}
|
||||
|
||||
U0 UserTaskCont()
|
||||
{
|
||||
{//Terminal key-input-execute loop.
|
||||
CLex *lx;
|
||||
CDoc *doc;
|
||||
Bool cont=TRUE;
|
||||
@@ -385,12 +376,12 @@ U0 UserCmdLine(I64 dummy=0)
|
||||
}
|
||||
|
||||
CTask *SpawnUser(U8 *fmt=NULL,...)
|
||||
{
|
||||
{//Create user term task.
|
||||
U8 *st;
|
||||
CTask *task=Spawn(&UserCmdLine);
|
||||
TaskWait(task);
|
||||
if (fmt) {
|
||||
st=SPrintJoin(NULL,fmt,argc,argv);
|
||||
st=StrPrintJoin(NULL,fmt,argc,argv);
|
||||
XTalk(task,st);
|
||||
Free(st);
|
||||
}
|
||||
@@ -398,7 +389,7 @@ CTask *SpawnUser(U8 *fmt=NULL,...)
|
||||
}
|
||||
|
||||
U0 SrvTaskCont()
|
||||
{
|
||||
{//Act as server task in a loop handling commands.
|
||||
FlushMsgs;
|
||||
while (TRUE) {
|
||||
if (SrvCmdsHandler && Fs->title_src==TTS_TASK_NAME)
|
||||
@@ -420,7 +411,7 @@ U0 SrvUserCmdLine(I64 dummy=0)
|
||||
}
|
||||
|
||||
U0 TaskFinishOff(CTask *task)
|
||||
{ //We delay freeing in case lingering ptr to reincarnated.
|
||||
{//We delay freeing in case lingering ptr to reincarnated.
|
||||
HeapCtrlDel(task->code_heap);
|
||||
if (task->data_heap!=task->code_heap)
|
||||
HeapCtrlDel(task->data_heap);
|
||||
@@ -428,7 +419,7 @@ U0 TaskFinishOff(CTask *task)
|
||||
}
|
||||
|
||||
I64 TaskEnd()
|
||||
{ //called with irq's off
|
||||
{//Called with irq's off.
|
||||
CTask *task=Fs,*tempt,*tempt1;
|
||||
if (task==sys_task_being_screen_updated) {
|
||||
LBts(&task->task_flags,TASKf_KILL_TASK);
|
||||
@@ -516,7 +507,7 @@ I64 TaskEnd()
|
||||
U0 TaskFinishOffDying()
|
||||
{//Called by Seth tasks. Delay freeing in case lingering ptr to reincarnated.
|
||||
CTask *task1,*task2;
|
||||
if (task1=XchgU64(&Gs->dying_task_lst,NULL)) {
|
||||
if (task1=XchgI64(&Gs->dying_task_lst,NULL)) {
|
||||
do {
|
||||
task2=task1->next_task;
|
||||
TaskFinishOff(task1);
|
||||
|
||||
+3
-28
@@ -1,6 +1,5 @@
|
||||
asm {
|
||||
USE64
|
||||
// ************************************
|
||||
_MEMSET::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -14,7 +13,6 @@ _MEMSET::
|
||||
POP RDI
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_MEMSET_U16::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -28,7 +26,6 @@ _MEMSET_U16::
|
||||
POP RDI
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_MEMSET_U32::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -42,8 +39,7 @@ _MEMSET_U32::
|
||||
POP RDI
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_MEMSET_U64::
|
||||
_MEMSET_I64::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
PUSH RDI
|
||||
@@ -56,7 +52,6 @@ _MEMSET_U64::
|
||||
POP RDI
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_MEMCPY::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -72,7 +67,6 @@ _MEMCPY::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_MEMCMP::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -92,7 +86,6 @@ _MEMCMP::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_BEQU::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -108,7 +101,6 @@ _BEQU::
|
||||
@@10: ADC AL,0
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_LBEQU::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -126,7 +118,6 @@ _LBEQU::
|
||||
@@10: ADC AL,0
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_CLAMP_I64::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -139,7 +130,6 @@ _CLAMP_I64::
|
||||
CMOVG RAX,RDX
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_CLAMP_U64::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -152,7 +142,6 @@ _CLAMP_U64::
|
||||
CMOVA RAX,RDX
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_CALL::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -162,7 +151,6 @@ _CALL::
|
||||
CALL RAX
|
||||
@@05: POP RBP
|
||||
RET1 8
|
||||
// ************************************
|
||||
_BIT_FIELD_OR_U32::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -176,7 +164,6 @@ _BIT_FIELD_OR_U32::
|
||||
OR U64 [RBX],RAX
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_BIT_FIELD_EXTRACT_U32::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -194,8 +181,7 @@ _BIT_FIELD_EXTRACT_U32::
|
||||
AND RAX,RDX
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_XCHG_U64::
|
||||
_XCHG_I64::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV RDX,U64 SF_ARG1[RBP]
|
||||
@@ -228,7 +214,7 @@ _XCHG_U8::
|
||||
POP RBP
|
||||
RET1 16
|
||||
|
||||
_LXCHG_U64::
|
||||
_LXCHG_I64::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
MOV RDX,U64 SF_ARG1[RBP]
|
||||
@@ -264,7 +250,6 @@ _LXCHG_U8::
|
||||
XCHG U8 [RDX],AL
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
_REP_IN_U32::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -276,7 +261,6 @@ _REP_IN_U32::
|
||||
POP RDI
|
||||
POP RBP
|
||||
RET1 24
|
||||
|
||||
_REP_IN_U16::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -288,7 +272,6 @@ _REP_IN_U16::
|
||||
POP RDI
|
||||
POP RBP
|
||||
RET1 24
|
||||
|
||||
_REP_IN_U8::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -300,7 +283,6 @@ _REP_IN_U8::
|
||||
POP RDI
|
||||
POP RBP
|
||||
RET1 24
|
||||
|
||||
_REP_OUT_U32::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -312,7 +294,6 @@ _REP_OUT_U32::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
|
||||
_REP_OUT_U16::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -324,7 +305,6 @@ _REP_OUT_U16::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
|
||||
_REP_OUT_U8::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -336,7 +316,6 @@ _REP_OUT_U8::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 24
|
||||
// ************************************
|
||||
_CPUID::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -351,7 +330,6 @@ _CPUID::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET1 16
|
||||
// ************************************
|
||||
_CALLIND::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -381,7 +359,6 @@ _CALLIND::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET
|
||||
// ************************************
|
||||
_CALLEXTNUM::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -413,7 +390,6 @@ _CALLEXTNUM::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET
|
||||
// ************************************
|
||||
_CALLEXTSTR::
|
||||
PUSH RBP
|
||||
MOV RBP,RSP
|
||||
@@ -455,7 +431,6 @@ _CALLEXTSTR::
|
||||
POP RSI
|
||||
POP RBP
|
||||
RET
|
||||
// ************************************
|
||||
SET_GS_BASE::
|
||||
PUSH RAX
|
||||
PUSH RCX
|
||||
|
||||
Reference in new issue
Block a user