LTCD_060719.ISO

This commit is contained in:
Terry A. Davis authored and minexew committed 2018-09-08 21:45:17 +02:00
commit f86e69648b
156 files changed
+49537

No files matched your search

+67
View File
@@ -0,0 +1,67 @@
#include "AdamExt"
#include "IncCompress"
#include "MATH"
#include "ODE"
Load("ADAMASM");
#include "ADAMASM.HPZ"
#include "GRMODE3"
#include "MUSIC"
#include "DISK10"
#include "FIFO"
#include "COMM"
#include "INPTR"
#include "GRELEM"
#include "LTF"
#include "UTILS"
#include "MOUSE"
#include "JOY"
#include "WINDOW"
#include "EDIT"
#include "LOGIN"
#include "WORDSTAT"
BoolU4 initial_user_tasks_startup_complete=FALSE;
public void DuelUsers()
{
I1 buf[80];
TssStruct *tss,*tss1;
tss=Spawn(&UserCmdLine);
while (!Bt(&tss->task_flags,TSSf_IDLE))
SwapInNext;
tss->window_top=2;
tss->window_right=(SCREEN_COLS-2)<<1;
tss1=tss;
tss=Spawn(&UserCmdLine);
while (!Bt(&tss->task_flags,TSSf_IDLE))
SwapInNext;
tss->window_top=2;
tss->window_left=SCREEN_COLS<<2>>1;
WindowToTop(tss1);
ws_task=Spawn(&WsTsk,"WORDSTAT");
SPrintF(buf,"Boot Time:%h17Ts\r\n",BootTime);
AdamLog(buf);
initial_user_tasks_startup_complete=TRUE;
}
Preempt(ON);
UseConsoleLtf(NULL);
adam_tss->window_top=2;
adam_tss->window_bottom=10;
update_screen_tss=Spawn(&WindowManagerTsk,"WINDOW MANAGER");
CollectAccntList;
Bts(&Fs->crt_flags,CRTf_SHOW);
if (!(Fs->account=FindSysAccnt(sys_startup_account)))
Fs->account=PopUpGetSysAccnt;
WsInit(wordstat_mask);
//This must be spawned because start-up files
// may invoke the Adam() cmd.
Spawn(&DuelUsers,"SPAWNUSERS");
coutln "\r\nOS Compile Time:",sys_compile_time;
Binary file not shown.
Binary file not shown.
+10
View File
@@ -0,0 +1,10 @@
public LTextern CP_PLOT_SCREEN_I1 BoolU4 PlotScreenChar(U8 w,I8 x,I8 y);
public LTextern CP_PLOT_WINDOW_I1 BoolU4 PlotWindowChar(U8 w,I8 x,I8 y);
public LTextern CP_PLOT_BORDER_I1 BoolU4 PlotBorderChar(U8 w,I8 x,I8 y);
LTextern REVERSE_BITS_TABLE U1 reverse_bits_table[256];
LTextern GR_XOR_LINE void GrXorLine(U4 **dst3,U4 **src,U4 **src2,U8 d5,U4 **vga);
LTextern GR_PLOT_CHAR void GrPlotChar(U1 *font_ptr,U1 attr,U1 **dst2,U8 d1,U8 d2);
LTextern GR_PLOT_BACKGROUND void GrPlotBackground(U1 attr,U1 **dst,U8 d1,U8 d2);
LTextern GR_UPDATE_WINDOWS void GrUpdateWindows();
//The callback is void Plot(aux_data,x,y,z)
Binary file not shown.
+32
View File
@@ -0,0 +1,32 @@
extern I8 PopUp(I1 *msg,TssStruct *parent=NULL);
extern U8 LtfPutChar(Ltf *l,I8 ch, U8 sc,BoolU4 old_preempt);
extern void LeftClickLink(Ltf *l,LtfEntry *cl,BoolU4 old_preempt2);
extern void RightClickLink(Ltf *l,LtfEntry *cl,BoolU4 old_preempt2);
extern U8 GetMsg(I8 *param1,I8 *param2,U8 mask=-2,TssStruct *tss=NULL);
extern U8 GetMsgNoWait(I8 *param1,I8 *param2,U8 mask=-2,TssStruct *tss=NULL);
extern void LtfInsert(Ltf *l,LtfEntry *ll);
extern LtfEntry *LtfPutS(Ltf *l,I1 *st);
extern I8 PopUpMenu(Ltf *l,I1 *help=NULL);
extern Ltf *LtfNew();
extern void LtfDel(Ltf *l,BoolU4 root_mem=FALSE);
extern LtfEntry *LtfPrintF(Ltf *l,I1 *src,...);
extern void DrawBorder(BoolU4 solid,I8 l,I8 r,I8 t,I8 b,U1 attr,BoolU4 clip);
extern void EditInsertLtf(Ltf *l,Ltf *b);
extern Ltf *LtfRead(I1 *name,U8 flags=0);
extern BoolU4 View();
extern BoolU4 IsPixelCovered(TssStruct *tss,I8 x,I8 y);
extern void PlotInputPointer();
extern void GrCircle(GrBitMap *base,I8 cx,I8 cy,I8 radius,
I8 step=1,double start_rad=0,double len_rad=pi2);
extern void GrPlot0(GrBitMap *base,I8 x,I8 y);
extern void ClearAllBpts(Ltf *l);
extern void ToggleBpt(Ltf *l,I8 line_offset=0,U8 flags=SBPTF_BPT);
extern void LtfGo();
extern void LtfStep(Ltf *l);
extern void Lpt1PutChar(U1 ch);
extern void WsFillin(I8 n);
extern void WsMan(I8 n,TssStruct *parent=NULL);
extern void WsTsk();
extern TssStruct *ws_task;
extern void Edit(I1 *filename);
+800
View File
@@ -0,0 +1,800 @@
#define CH_XOFF 0x13
#define CH_XON 0x11
#define UART_THR 0
#define UART_RDR 0
#define UART_BRDL 0
#define UART_IER 1
#define UART_BRDH 1
#define UART_IIR 2
#define UART_LCR 3
#define UART_MCR 4
#define UART_LSR 5
#define UART_MSR 6
#define COMMf_INCOMING_XOFFED 0
#define COMMf_OUTGOING_XOFFED 1
#define COMMf_TX_XOFF 2
#define COMMf_TX_XON 3
#define RMT_MAX_PKT_LEN 64 //Must be less then PKT_SYNC
#define RMT_PKT_ACK 0xA5
#define RMT_PKT_NACK 0x5A
#define RMT_PKT_SYNC 0xA3
#define RMT_PKT_SYNC2 0xA7
#define RMT_PKT_CHAR 0xA4
#define RMT_PKT_REQUEST 0xA6
#define RMT_PKT_CLOSE 0xA8
#define RMT_RQST_NONE 0x00
#define RMT_RQST_GETMSG 0x01
#define RMT_RQST_TX_FILE 0x02
#define RMT_RQST_RX_FILE 0x03
#define RMT_RQST_TX_BUF 0x04
#define RMT_RQST_RX_BUF 0x05
#define RMT_RQST_EXE_LOCAL 0x06
#define RMT_RQST_PUTS_CNT 0x07
#define RMT_RQST_MAX 0x07
U8 comm_base[5]={0,0x3F8,0x2F8,0x3E8,0x2E8};
U1Fifo *comm_Rx_fifos[5]={NULL,NULL,NULL,NULL,NULL};
U1Fifo *comm_Tx_fifos[5]={NULL,NULL,NULL,NULL,NULL};
U8 comm_flags[5]={0,0,0,0,0};
LTChnl *comm_chnls[5]={NULL,NULL,NULL,NULL,NULL};
public void RxClose(LTChnl *chnl)
{
U8 base;
U8 old_flags=GetFlags;
if (!chnl || !chnl->type) return;
if (chnl->type==LCT_COMM) {
base=comm_base[chnl->port];
OutP(base+UART_IER,0);
Cli;
if (comm_Rx_fifos[chnl->port]) {
DelU1Fifo(comm_Rx_fifos[chnl->port]);
comm_Rx_fifos[chnl->port]=NULL;
}
if (comm_Tx_fifos[chnl->port]) {
DelU1Fifo(comm_Tx_fifos[chnl->port]);
comm_Tx_fifos[chnl->port]=NULL;
}
comm_chnls[chnl->port]=NULL;
SetFlags(old_flags);
}
AFree(chnl);
}
public void CommPutChar(U8 port,U1 b)
{
U8 old_flags=GetFlags;
U8 base=comm_base[port];
Cli;
if (b==CH_XOFF)
Bts(&comm_flags[port],COMMf_TX_XOFF);
else if (b==CH_XON)
Bts(&comm_flags[port],COMMf_TX_XON);
else {
if (U1FifoCnt(comm_Tx_fifos[port])>comm_Tx_fifos[port]->mask-4) {
SetFlags(old_flags);
while (U1FifoCnt(comm_Tx_fifos[port])>comm_Tx_fifos[port]->mask-4)
SwapInNext;
Cli;
}
if (Bt(&comm_flags[port],COMMf_OUTGOING_XOFFED)) {
SetFlags(old_flags);
while (Bt(&comm_flags[port],COMMf_OUTGOING_XOFFED))
SwapInNext;
Cli;
}
if (comm_Tx_fifos[port])
U1FifoInsert(comm_Tx_fifos[port],b);
}
OutP(base+UART_IER,3); //Enable TX & RX IRQ
SetFlags(old_flags);
BusyWait(300);
}
public void RmtFlushRxFifo(LTChnl *chnl)
{
if (!chnl || !chnl->type) return;
U1FifoFlush(comm_Rx_fifos[chnl->port]);
if (Bt(&comm_flags[chnl->port],COMMf_INCOMING_XOFFED))
chnl->PutChar(chnl,CH_XON);
}
public void RmtFlushTxFifo(LTChnl *chnl)
{
U8 base=comm_base[chnl->port];
if (!chnl || !chnl->type) return;
U1FifoFlush(comm_Tx_fifos[chnl->port]);
while (!(InP(base+UART_LSR) & 0x20))
SwapInNext;
}
public void RmtPrintF(LTChnl *chnl,I1 *src,...)
{
I1 *buf,*ptr;
if (!chnl || !chnl->type) return;
buf=SPrintFJoin(NULL,src,argc,argv);
ptr=buf;
while (*ptr)
chnl->PutChar(chnl,*ptr++);
Free(buf);
}
public void CommPrintF(U8 port,I1 *src,...)
{
RmtPrintF(comm_chnls[port],src,argc,argv);
}
void CommRxTxChar(U8 port)
{
U8 ch=0,irq,base=comm_base[port];
BoolU4 have_one;
if (comm_Rx_fifos[port] &&
comm_Tx_fifos[port]) {
while (TRUE) {
irq=InP(base+UART_IIR);
if ((irq & 0x07)==4) { //RX IRQ
ch=InP(base+UART_RDR);
if (ch==CH_XOFF)
Bts(&comm_flags[port],COMMf_OUTGOING_XOFFED);
else if (ch==CH_XON)
Btr(&comm_flags[port],COMMf_OUTGOING_XOFFED);
else {
U1FifoInsert(comm_Rx_fifos[port],ch);
if (U1FifoCnt(comm_Rx_fifos[port])>comm_Rx_fifos[port]->mask>>1)
CommPutChar(port,CH_XOFF);
}
} else if ((irq & 0x07)==2) { //TX IRQ
have_one=TRUE;
if (Btr(&comm_flags[port],COMMf_TX_XOFF))
ch=CH_XOFF;
else if (Btr(&comm_flags[port],COMMf_TX_XON))
ch=CH_XON;
else if (!U1FifoRemove(comm_Tx_fifos[port],&ch))
have_one=FALSE;
if (have_one) {
if (ch==CH_XOFF)
Bts(&comm_flags[port],COMMf_INCOMING_XOFFED);
else if (ch==CH_XON)
Btr(&comm_flags[port],COMMf_INCOMING_XOFFED);
OutP(base+UART_THR,ch);
}
if (!U1FifoCnt(comm_Tx_fifos[port]))
OutP(base+UART_IER,1); //Enable RX IRQ
} else
break;
}
}
}
public I8 RmtRxFifoCnt(LTChnl *chnl)
{
if (!chnl || !chnl->type) return 0;
return U1FifoCnt(comm_Rx_fifos[chnl->port]);
}
public I8 RmtTxFifoCnt(LTChnl *chnl)
{
if (!chnl || !chnl->type) return 0;
return U1FifoCnt(comm_Tx_fifos[chnl->port]);
}
public void RmtWaitTxDone(LTChnl *chnl)
{
U8 base=comm_base[chnl->port];
if (!chnl || !chnl->type) return;
while (RmtTxFifoCnt(chnl))
SwapInNext;
while (!(InP(base+UART_LSR) & 0x20))
SwapInNext;
}
void Irq03Handler()
{
CommRxTxChar(2);
CommRxTxChar(4);
}
void Irq04Handler()
{
CommRxTxChar(1);
CommRxTxChar(3);
}
public U1 CommGetChar(U8 port)
{
U8 ch=0;
while (!U1FifoRemove(comm_Rx_fifos[port],&ch))
SwapInNext;
if (Bt(&comm_flags[port],COMMf_INCOMING_XOFFED) &&
U1FifoCnt(comm_Rx_fifos[port])<comm_Rx_fifos[port]->mask>>2)
CommPutChar(port,CH_XON);
return ch;
}
public U1 RmtGetChar(LTChnl *chnl)
{
if (!chnl || !chnl->type)
return 0;
return CommGetChar(chnl->port);
}
public BoolU4 CommScanChar(U8 port,U1 *ch)
{
U8 ch1=0;
if (U1FifoPeek(comm_Rx_fifos[port],&ch1)) {
U1FifoRemove(comm_Rx_fifos[port],&ch1);
*ch=ch1;
if (Bt(&comm_flags[port],COMMf_INCOMING_XOFFED) &&
U1FifoCnt(comm_Rx_fifos[port])<comm_Rx_fifos[port]->mask>>2)
CommPutChar(port,CH_XON);
return TRUE;
} else
return FALSE;
}
public BoolU4 RmtScanChar(LTChnl *chnl,U1 *ch)
{
if (!chnl || !chnl->type)
return 0;
return CommScanChar(chnl->port,ch);
}
void CommRmtPutChar(LTChnl *chnl,U1 b)
{
CommPutChar(chnl->port,b);
}
U1 CommRmtGetChar(LTChnl *chnl)
{
return CommGetChar(chnl->port);
}
BoolU4 CommRmtScanChar(LTChnl *chnl,U1 *ch)
{
return CommScanChar(chnl->port,ch);
}
public LTChnl *CommOpen8N1(U8 port=1,U8 baud=38400)
{
LTChnl *chnl=NULL;
U8 old_flags=GetFlags,base=comm_base[port];
Cli;
if (!port || port>4 || comm_chnls[port])
goto co_exit;
chnl=AMAllocZ(sizeof(LTChnl));
comm_chnls[port]=chnl;
chnl->type=LCT_COMM;
base=comm_base[port];
chnl->port=port;
chnl->baud=baud;
chnl->PutChar=&CommRmtPutChar;
chnl->GetChar=&CommRmtGetChar;
chnl->ScanChar=&CommRmtScanChar;
if (comm_Rx_fifos[chnl->port])
DelU1Fifo(comm_Rx_fifos[chnl->port]);
if (comm_Tx_fifos[chnl->port])
DelU1Fifo(comm_Tx_fifos[chnl->port]);
comm_flags[chnl->port]=0;
comm_Rx_fifos[chnl->port]=NewU1Fifo(0x2000); //must be power of 2
comm_Tx_fifos[chnl->port]=NewU1Fifo(0x2000); //must be power of 2
OutP(base+UART_LCR,0); //Set for IER
OutP(base+UART_IER,0);
OutP(base+UART_LCR,0x80); //Enable baud rate control
OutP(base+UART_BRDL,(0x180/(baud/300)) & 0xFF); //LSB
OutP(base+UART_BRDH,(0x180/(baud/300)) / 256); //MSB
OutP(base+UART_LCR,3); // 8-none-1
InP(base+UART_RDR); //read garbage
InP(base+UART_LSR);
OutP(base+UART_MCR,4);
OutP(base+UART_IER,0); //DIsable all IRQ
OutP(base+UART_MCR,0xA); //out2 and rts
OutP(base+UART_IER,1); //Enable RX IRQ
co_exit:
SetFlags(old_flags);
return chnl;
}
public void CommClose(U8 port)
{
LTChnl *chnl=comm_chnls[port];
RxClose(chnl);
}
ext[EXT_IRQ03]=&Irq03Handler;
ext[EXT_IRQ04]=&Irq04Handler;
U8 RmtTxPktU1(LTChnl *chnl,U1 b)
{
if (!chnl || !chnl->type) return 0;
if (b==CH_XOFF || b==CH_XON ||
b==CH_ESC || b==RMT_PKT_CHAR ||
b==RMT_PKT_REQUEST ||
b==RMT_PKT_CLOSE) {
chnl->PutChar(chnl,CH_ESC);
chnl->PutChar(chnl,b^0x80);
return 2;
} else {
chnl->PutChar(chnl,b);
return 1;
}
}
BoolU4 RmtRxPktU1(LTChnl *chnl,U1 *b,
U8 timeout_jiffies,BoolU4 *esc=NULL)
{
U1 b1;
U8 timeout;
*b=RMT_PKT_NACK;
if (esc)
*esc=FALSE;
if (!chnl || !chnl->type)
return FALSE;
timeout=jiffies+timeout_jiffies;
while (jiffies<timeout) {
if (chnl->ScanChar(chnl,&b1)) {
if (b1==CH_ESC) {
timeout=jiffies+timeout_jiffies;
while (jiffies<timeout) {
if (chnl->ScanChar(chnl,&b1)) {
*b=b1^0x80;
if (esc) *esc=TRUE;
return TRUE;
}
SwapInNext;
}
return FALSE;
} else {
if (b1==RMT_PKT_CLOSE) {
Fs->rmt_chnl=NULL;
throw;
}
*b=b1;
return TRUE;
}
}
SwapInNext;
}
return FALSE;
}
void RmtTxPkt(LTChnl *chnl,U1 *p,U8 size,U8 rqst=RMT_RQST_NONE)
{
U1 b,xsum;
U8 i;
if (!chnl || !chnl->type) return;
if (rqst) {
rt_err1:
RmtFlushTxFifo(chnl);
chnl->PutChar(chnl,RMT_PKT_REQUEST);
RmtWaitTxDone(chnl);
RmtFlushRxFifo(chnl);
RmtTxPktU1(chnl,rqst);
RmtWaitTxDone(chnl);
RmtRxPktU1(chnl,&b,JIFFY_FREQ/50);
if (b!=RMT_PKT_ACK)
goto rt_err1;
} else if (size==1) {
rt_err2:
RmtFlushTxFifo(chnl);
chnl->PutChar(chnl,RMT_PKT_CHAR);
RmtWaitTxDone(chnl);
RmtFlushRxFifo(chnl);
RmtTxPktU1(chnl,p[0]);
RmtWaitTxDone(chnl);
RmtRxPktU1(chnl,&b,JIFFY_FREQ/50);
if (b!=RMT_PKT_ACK)
goto rt_err2;
} else {
rt_err3:
RmtFlushTxFifo(chnl);
RmtTxPktU1(chnl,RMT_PKT_SYNC);
RmtWaitTxDone(chnl);
RmtFlushRxFifo(chnl);
RmtTxPktU1(chnl,RMT_PKT_SYNC2);
RmtWaitTxDone(chnl);
RmtRxPktU1(chnl,&b,JIFFY_FREQ/50);
if (b!=RMT_PKT_ACK)
goto rt_err3;
RmtTxPktU1(chnl,size);
RmtWaitTxDone(chnl);
RmtRxPktU1(chnl,&b,JIFFY_FREQ/50);
if (b!=RMT_PKT_ACK)
goto rt_err3;
xsum=0x3A;
for (i=0;i<size;i++) {
b=p[i];
RmtTxPktU1(chnl,b);
xsum^=b;
}
while (RmtTxFifoCnt(chnl)) {
if (RmtRxFifoCnt(chnl)) {
if (RmtScanChar(chnl,&b)) {
if (b==RMT_PKT_NACK) {
RmtFlushRxFifo(chnl);
goto rt_err3;
}
}
}
SwapInNext;
}
RmtTxPktU1(chnl,xsum);
RmtWaitTxDone(chnl);
RmtRxPktU1(chnl,&b,JIFFY_FREQ/50);
if (b!=RMT_PKT_ACK)
goto rt_err3;
}
}
void RmtRxPkt(LTChnl *chnl,U1 *p,U8 *size=NULL,U8 *rqst=NULL)
{
U1 b,b1,xsum;
U8 i,s,r;
BoolU4 esc;
if (!chnl || !chnl->type) {
if (size) *size=0;
if (rqst) *rqst=0;
return;
}
rr_start:
RmtFlushTxFifo(chnl);
if (RmtRxFifoCnt(chnl)>2)
RmtFlushRxFifo(chnl);
s=0;
r=0;
RmtRxPktU1(chnl,&b,JIFFY_FREQ);
RmtRxPktU1(chnl,&b1,JIFFY_FREQ/50,&esc);
rr_cont:
if (b==RMT_PKT_REQUEST) {
if (b1>RMT_RQST_MAX) {
if (b1==RMT_PKT_REQUEST && !esc)
goto rr_cont;
else
goto rr_err;
}
r=b1;
s=0;
goto rr_exit;
} else if (b==RMT_PKT_CHAR) {
if (b1==RMT_PKT_CHAR && !esc)
goto rr_cont;
*p=b1;
s=1;
goto rr_exit;
} else if (b==RMT_PKT_SYNC) {
if (b1!=RMT_PKT_SYNC2) {
if (b1==RMT_PKT_SYNC)
goto rr_cont;
else
goto rr_err;
}
RmtTxPktU1(chnl,RMT_PKT_ACK);
RmtWaitTxDone(chnl);
RmtRxPktU1(chnl,&s,JIFFY_FREQ/50);
if (s>RMT_MAX_PKT_LEN)
goto rr_err;
RmtTxPktU1(chnl,RMT_PKT_ACK);
RmtWaitTxDone(chnl);
xsum=0x3A;
for (i=0;i<s;i++) {
if (!RmtRxPktU1(chnl,&p[i],JIFFY_FREQ/50))
goto rr_err;
xsum^=p[i];
}
RmtRxPktU1(chnl,&b,JIFFY_FREQ/50);
if (b!=xsum)
goto rr_err;
goto rr_exit;
}
rr_err:
RmtTxPktU1(chnl,RMT_PKT_NACK);
RmtWaitTxDone(chnl);
goto rr_start;
rr_exit:
RmtTxPktU1(chnl,RMT_PKT_ACK);
RmtWaitTxDone(chnl);
if (size) *size=s;
if (rqst) *rqst=r;
}
public void RmtTxBlk(LTChnl *chnl,U1 *buf,I8 cnt)
{
U1 b[RMT_MAX_PKT_LEN];
U8 size;
if (!chnl || !chnl->type) return;
while (cnt>0) {
if (cnt<RMT_MAX_PKT_LEN)
size=cnt;
else
size=RMT_MAX_PKT_LEN;
MemCpy(b,buf,size);
RmtTxPkt(chnl,b,size);
cnt-=size;
buf+=size;
progress1=cnt;
}
}
public U1 *RmtRxBlk(LTChnl *chnl,I8 cnt)
{
U1 *result,*buf;
U1 b[RMT_MAX_PKT_LEN];
U8 size=0;
if (!chnl || !chnl->type) return NULL;
result=MAlloc(cnt);
buf=result;
while (cnt>0) {
RmtRxPkt(chnl,b,&size);
MemCpy(buf,b,size);
cnt-=size;
buf+=size;
progress1=cnt;
}
return result;
}
public U8 RmtGetMsg(LTChnl *chnl,I8 *p1,I8 *p2)
{
U8 cmd,d,size;
U1 b[RMT_MAX_PKT_LEN];
*p1=0;
*p2=0;
if (!chnl || !chnl->type)
return 0;
if (jiffies<chnl->null_msg_jiffy)
return 0;
else {
RmtTxPkt(chnl,NULL,0,RMT_RQST_GETMSG);
RmtRxPkt(chnl,b,&size);
if (size!=sizeof(U8)*3)
return 0;
cmd=b[0]><(U8);
*p1=b[8]><(U8);
*p2=b[16]><(U8);
if (!cmd)
chnl->null_msg_jiffy=jiffies+JIFFY_FREQ/50;
}
return cmd;
}
public void RmtSendMsg(LTChnl *chnl,U8 cmd,I8 p1,I8 p2)
{
U1 b[RMT_MAX_PKT_LEN];
if (!chnl || !chnl->type) return;
if (cmd) {
b[0]><(U8)=cmd;
b[8]><(U8)=p1;
b[16]><(U8)=p2;
RmtTxPkt(chnl,b,sizeof(U8)*3);
} else
RmtTxPkt(chnl,b,1);
}
public void RmtPutCharSC(LTChnl *chnl,I8 ch,U8 sc)
{
if (!chnl || !chnl->type) return;
if (ch)
RmtTxPkt(chnl,&ch,1);
}
public void RmtTxBuf(LTChnl *chnl,U1 *buf,U8 size)
{
if (!chnl || !chnl->type) return;
if (buf) {
RmtTxBlk(chnl,&size,sizeof(U8));
RmtTxBlk(chnl,buf,size);
}
}
public U1 *RmtRxBuf(LTChnl *chnl,U8 *size=NULL)
{
U1 *buf;
U8 *size2;
if (size) *size=0;
if (!chnl || !chnl->type) return NULL;
size2=RmtRxBlk(chnl,sizeof(U8));
buf=RmtRxBlk(chnl,*size2);
if (size) *size=*size2;
Free(size2);
return buf;
}
public void RmtTxFile(LTChnl *chnl,I1 *filename,
BoolU4 raw=TRUE)
{
U8 size;
U1 *buf;
if (!chnl || !chnl->type) return;
buf=ReadFile(filename,&size,NULL,raw);
if (buf) {
RmtTxBuf(chnl,buf,size);
Free(buf);
}
}
public U8 RmtRxFile(LTChnl *chnl,I1 *filename,
BoolU4 raw=TRUE)
{
U8 size;
U1 *buf;
if (!chnl || !chnl->type) return 0;
if (buf=RmtRxBuf(chnl,&size)) {
WriteFile(filename,buf,size,0,0,raw);
Free(buf);
}
return size;
}
public void RmtTxPutS(LTChnl *chnl,I1 *st)
{
U8 len;
if (!chnl || !chnl->type) return;
if (st) {
len=StrLen(st);
if (len) {
if (len>RMT_MAX_PKT_LEN) {
RmtTxPkt(chnl,NULL,0,RMT_RQST_PUTS_CNT);
RmtTxBuf(chnl,st,len+1);
} else
RmtTxBlk(chnl,st,len);
}
}
}
public void RmtTxPutChar(LTChnl *chnl,I8 ch)
{
if (!chnl || !chnl->type) return;
if (ch)
RmtTxPkt(chnl,&ch,1);
}
public I1 *RmtRxPutS(LTChnl *chnl,U8 *rqst=NULL)
{
U1 b[RMT_MAX_PKT_LEN];
U8 size;
U1 *buf=NULL;
if (!chnl || !chnl->type) return NULL;
if (RmtRxFifoCnt(chnl)>=2) {
RmtRxPkt(chnl,b,&size,rqst);
if (size) {
buf=MAlloc(size+1);
MemCpy(buf,b,size);
buf[size]=0;
} else
buf=MAllocZ(1);
}
return buf;
}
/***************
public U1 *RmtRqstTxBuf(U8 *size=NULL)
{
LTChnl *chnl=Fs->rmt_chnl;
if (!chnl || !chnl->type) return NULL;
RmtTxPkt(chnl,NULL,0,RMT_RQST_TX_BUF);
return RmtRxBuf(chnl,size);
}
public void RmtRqstRxBuf(U1 *buf,U8 size)
{
LTChnl *chnl=Fs->rmt_chnl;
if (!chnl || !chnl->type) return;
RmtTxPkt(chnl,NULL,0,RMT_RQST_RX_BUF);
RmtTxBuf(chnl,buf,size);
}
*************/
public void RmtRqstTxFile(I1 *dst_local_filename,I1 *src_remote_filename)
{
LTChnl *chnl=Fs->rmt_chnl;
if (!chnl || !chnl->type) return;
RmtTxPkt(chnl,NULL,0,RMT_RQST_TX_FILE);
RmtTxBuf(chnl,src_remote_filename,StrLen(src_remote_filename)+1);
RmtRxFile(chnl,dst_local_filename);
}
public void RmtRqstRxFile(I1 *src_local_filename,I1 *dst_remote_filename)
{
LTChnl *chnl=Fs->rmt_chnl;
if (!chnl || !chnl->type) return;
RmtTxPkt(chnl,NULL,0,RMT_RQST_RX_FILE);
RmtTxBuf(chnl,dst_remote_filename,StrLen(dst_remote_filename)+1);
RmtTxFile(chnl,src_local_filename);
}
public void RmtRqstExeLocal(I1 *st)
{
LTChnl *chnl=Fs->rmt_chnl;
if (!chnl || !chnl->type) return;
RmtTxPkt(chnl,NULL,0,RMT_RQST_EXE_LOCAL);
RmtTxBuf(chnl,st,StrLen(st)+1);
}
void TelnetHostOpen(LTChnl *chnl)
{
if (!chnl || !chnl->type) return;
Fs->rmt_chnl=chnl;
}
void TelnetHostClose(LTChnl *chnl)
{
Fs->rmt_chnl=NULL;
}
void TelnetGuestOpen(LTChnl *chnl)
{
U8 i,cmd,p1,p2,rqst;
U1 *st,*st2;
if (!chnl || !chnl->type) return;
coutln "CTRL-ALT-C to exit";
try
while (TRUE) {
if (st2=RmtRxPutS(chnl,&rqst)) {
switch (rqst) {
case RMT_RQST_NONE:
PutS(st2);
break;
case RMT_RQST_GETMSG:
cmd=GetMsgNoWait(&p1,&p2,
1<<MSG_KEY_DOWN|
1<<MSG_CMD|
1<<MSG_KEY_UP);
RmtSendMsg(chnl,cmd,p1,p2);
break;
case RMT_RQST_TX_FILE:
st=RmtRxBuf(chnl);
RmtTxFile(chnl,st);
Free(st);
break;
case RMT_RQST_RX_FILE:
st=RmtRxBuf(chnl);
RmtRxFile(chnl,st);
Free(st);
break;
/***********
case RMT_RQST_TX_BUF:
break;
case RMT_RQST_RX_BUF:
RmtRxBuf(chnl);
break;
************/
case RMT_RQST_EXE_LOCAL:
st=RmtRxBuf(chnl);
ExecuteString(st);
Free(st);
break;
case RMT_RQST_PUTS_CNT:
Free(st2);
st2=RmtRxBuf(chnl);
PutS(st2);
break;
}
Free(st2);
st2=NULL;
}
SwapInNext;
}
catch
Fs->catch_except=TRUE;
for (i=0;i<5;i++) {
chnl->PutChar(chnl,RMT_PKT_CLOSE);
chnl->PutChar(chnl,RMT_PKT_CLOSE);
Sleep(50);
}
}
ext[EXT_RMT_PUTCHAR]=&RmtTxPutChar;
ext[EXT_RMT_PUTS]=&RmtTxPutS;
ext[EXT_RMT_LTFPUTCHAR]=&RmtPutCharSC;
ext[EXT_RMT_GETMSG]=&RmtGetMsg;
+821
View File
@@ -0,0 +1,821 @@
public BoolU4 Copy(I1 *f1,I1 *f2=".")
{
BoolU4 result=TRUE;
LTFileAccess *fa;
LTDirEntry *tempm,*tempm1;
U8 my_flags=0;
if (!(tempm=FindFiles(f1,&my_flags)))
return FALSE;
if (IsDir(f2)) {
fa=NewLTFileAccess(f2,TRUE);
if (fa) {
while (tempm) {
tempm1=tempm->next;
if (!(tempm->attr & LT_ATTR_DIR)) {
if (!CopySingle(tempm->full_name,tempm->name))
result=FALSE;
}
DelLTDirEntry(tempm);
tempm=tempm1;
}
DelLTFileAccess(fa);
}
return result;
} else
return CopySingle(f1,f2);
}
public BoolU4 Move(I1 *f1,I1 *f2)
{
if (Copy(f1,f2)) {
Del(f1);
return TRUE;
}
return FALSE;
}
U8 PutCopyTree(LTDirEntry *tempm,U8 src_dir_len,U8 dst_dir_len,I1 *dst_dir)
{
U8 result=0;
I1 *st;
while (tempm) {
st=MAlloc(StrLen(tempm->full_name)+dst_dir_len+2);
MemCpy(st,dst_dir,dst_dir_len);
StrCpy(st+dst_dir_len,tempm->full_name+src_dir_len);
if (tempm->attr & LT_ATTR_DIR) {
MkDir(st);
if (IsDir(st) && tempm->sub)
result+=PutCopyTree(tempm->sub,src_dir_len,dst_dir_len,dst_dir);
} else
if (CopySingle(tempm->full_name,st))
result++;
Free(st);
tempm=tempm->next;
}
return result;
}
public U8 CopyTree(I1 *src_mask,I1 *dst_mask)
{ //returns count of copied files (not dirs)
LTFileAccess *fa;
LTDirEntry *tempm=NULL;
U8 result=0,i1,i2,my_flags=(1<<FUf_RECURSE);
I1 *st1,*st2;
fa=NewLTFileAccess(src_mask,TRUE);
if (fa) {
tempm=SysFindFiles(fa->mask,&my_flags);
st1=CurDir;
DelLTFileAccess(fa);
i1=StrLen(st1);
if (i1==3) i1--;
fa=NewLTFileAccess(dst_mask,TRUE,TRUE);
if (fa) {
st2=CurDir;
i2=StrLen(st2);
if (i2==3) i2--;
result=PutCopyTree(tempm,i1,i2,st2);
DelLTFileAccess(fa);
Free(st2);
}
DelLTDirList(tempm);
Free(st1);
}
return result;
}
void DoDelTree(LTDirEntry *tempm1)
{
U8 result=0;
LTDirEntry *tempm2;
while (tempm1) {
tempm2=tempm1->next;
if (tempm1->attr & LT_ATTR_DIR) {
if (tempm1->sub)
result+=DoDelTree(tempm1->sub);
SysDel(tempm1->full_name,TRUE);
}
DelLTDirEntry(tempm1);
tempm1=tempm2;
}
}
public BoolU4 DelTree(I1 *mask)
{
U8 my_flags=(1<<FUf_RECURSE);
if (!IsDir(mask)) {
coutln "Not a Directory";
return FALSE;
}
DoDelTree(FindFiles(mask,&my_flags));
SysDel(mask,TRUE);
SysDel(mask,FALSE);
return TRUE;
}
void DoDelMask(LTDirEntry *tempm1)
{
LTDirEntry *tempm2;
while (tempm1) {
tempm2=tempm1->next;
if (tempm1->attr & LT_ATTR_DIR) {
if (tempm1->sub)
DoDelMask(tempm1->sub);
} else
Del(tempm1->full_name);
DelLTDirEntry(tempm1);
tempm1=tempm2;
}
}
public BoolU4 DelMask(I1 *mask)
{ //Purges select filetypes from tree
U8 my_flags=(1<<FUf_RECURSE);
if (IsDir(mask)) {
coutln "Not a Mask";
return FALSE;
}
DoDelMask(FindFiles(mask,&my_flags));
return TRUE;
}
void TouchFile(I1 *filename,I1 *attr) //LTust one file
{
U1 *temp_st=NewString(filename),
*cur_dir=NewString(filename);
LTPartition *p=DriveToPartition(*filename);
FlagsStruct f;
LTDirEntry de;
I1 buf[64];
if (FindFile(filename,&de,FALSE,TRUE)) {
if (!StrCmp(attr,"+?"))
PrintF("%-32ts %s\r\n",filename,SPrintFFlags(buf,"ST_FILE_ATTRS",de.attr));
else {
GetFFlags(&f,"ST_FILE_ATTRS",attr);
RemoveFirstSeg(cur_dir,":",temp_st);
RemoveLastSeg(cur_dir,"/",temp_st);
if (!*cur_dir)
StrCpy(cur_dir,"/");
de.attr=de.attr&f.off|f.on;
de.datetime=GetCurTimeLTDate;
NewLTDirEntry(p,cur_dir,&de,FALSE);
}
} else PutSysText("ST_FILE_NOT_FOUND");
}
void TouchList(LTDirEntry *tempm1,I1 *attr)
{
LTDirEntry *tempm2;
while (tempm1) {
tempm2=tempm1->next;
if (tempm1->attr & LT_ATTR_DIR) {
if (tempm1->sub) {
coutln SysText("ST_SCANNING_DIRECTORY"),tempm1->full_name;
TouchList(tempm1->sub,attr);
}
} else
TouchFile(tempm1->full_name,attr);
DelLTDirEntry(tempm1);
tempm1=tempm2;
}
}
//Attr "+?" =show
// "+T" = resident
//flags "+r"=recurse
public void Touch(I1 *wild,I1 *attr="+?",I1 *flags="")
{
FlagsStruct f;
GetFFlags(&f,"ST_FILE_UTIL_FLAGS",flags);
TouchList(FindFiles(wild,&f.on),attr);
}
void FillBigEndianU2(U2 *dst,U2 w)
{
U2 *src=&w;
dst->u1[0]=src->u1[1];
dst->u1[1]=src->u1[0];
}
void FillBigEndianU4(U4 *dst,U8 d)
{
U8 *src=&d;
dst->u1[0]=src->u1[3];
dst->u1[1]=src->u1[2];
dst->u1[2]=src->u1[1];
dst->u1[3]=src->u1[0];
}
void FillU2Palindrome(U2Palindrome *dst,U2 w)
{
FillBigEndianU2(&dst->big,w);
dst->little=w;
}
void FillU4Palindrome(U4Palindrome *dst,U8 d)
{
FillBigEndianU4(&dst->big,d);
dst->little=d;
}
class CCdUserData
{
U8 location,path_entry_num,
short_dir_blks,long_dir_blks;
};
U8 DoCreateCDFile(LTFile *out_file,LTDirEntry *tempm,
ISODirEntry *tempi,ISODirEntry *tempi2,
U8 *cur_blk,
LTDirEntry *parent,BoolU4 write)
{
CCdUserData *tempc;
LTDirEntry *tempm1,*tempm2;
LTFile *in_file;
U1 *buf=MAlloc(CD_BLK_SIZE),*ptr1,*ptr2;
ISODirEntry *dir_blk_buf=MAllocZ(CD_BLK_SIZE*128),
*de=dir_blk_buf,*de1;
ISODirEntry *dir_blk_buf2=MAllocZ(CD_BLK_SIZE*128),
*de2=dir_blk_buf2,*de12;
U8 i,l;
tempc=parent->user_data;
de->length=sizeof(ISODirEntry)-1;
de->ext_attr_length=0;
FillU2Palindrome(&de->volume_sequence_num,1);
LTDateToISO(&de->date,tempm->datetime);
de->flags=ISO_ATTR_DIR;
de->name_len=1;
de->name=0;
de->length+=de->name_len;
de+=de->length;
de->length=sizeof(ISODirEntry)-1;
de->ext_attr_length=0;
FillU4Palindrome(&de->location,tempc->location);
FillU4Palindrome(&de->size,tempc->short_dir_blks*CD_BLK_SIZE);
FillU2Palindrome(&de->volume_sequence_num,1);
LTDateToISO(&de->date,parent->datetime);
de->flags=ISO_ATTR_DIR;
de->name_len=1;
de->name=1;
de->length+=de->name_len;
de+=de->length;
de2->length=sizeof(ISODirEntry)-1;
de2->ext_attr_length=0;
FillU2Palindrome(&de2->volume_sequence_num,1);
LTDateToISO(&de2->date,tempm->datetime);
de2->flags=ISO_ATTR_DIR;
de2->name_len=1;
de2->name=0;
de2->length=de2->length+de2->name_len;
de2+=de2->length;
de2->length=sizeof(ISODirEntry)-1;
de2->ext_attr_length=0;
FillU4Palindrome(&de2->location,tempc->location+tempc->short_dir_blks);
FillU4Palindrome(&de2->size,tempc->long_dir_blks*CD_BLK_SIZE);
FillU2Palindrome(&de2->volume_sequence_num,1);
LTDateToISO(&de2->date,parent->datetime);
de2->flags=ISO_ATTR_DIR;
de2->name_len=1;
de2->name=1;
de2->length+=de2->name_len;
de2+=de2->length;
tempm1=tempm->sub;
while (tempm1) {
tempm2=tempm1->next;
if (!write) tempm1->user_data=MAllocZ(sizeof(CCdUserData));
de1=de;
de12=de2;
if (tempm1->attr & LT_ATTR_DIR) {
l=DoCreateCDFile(out_file,tempm1,de,de2,cur_blk,tempm,write);
de+=sizeof(ISODirEntry)-1+l;
de2+=sizeof(ISODirEntry)-1+l<<1;
} else {
tempc=tempm1->user_data;
de->length=sizeof(ISODirEntry)-1;
de->ext_attr_length=0;
FillU4Palindrome(&de->location,*cur_blk);
tempc->location=*cur_blk;
if (write)
coutln *cur_blk,":",tempm1->full_name;
FillU4Palindrome(&de->size,tempm1->size);
FillU2Palindrome(&de->volume_sequence_num,1);
LTDateToISO(&de->date,tempm1->datetime);
de->flags=0;
de->name_len=StrLen(tempm1->name);
StrCpy(&de->name,tempm1->name);
de->length=de->length+de->name_len;
de+=de->length;
de2->length=sizeof(ISODirEntry)-1;
de2->ext_attr_length=0;
FillU4Palindrome(&de2->location,*cur_blk);
FillU4Palindrome(&de2->size,tempm1->size);
FillU2Palindrome(&de2->volume_sequence_num,1);
LTDateToISO(&de2->date,tempm1->datetime);
de2->flags=0;
de2->name_len=StrLen(tempm1->name)<<1;
ptr1=&de2->name;
ptr2=&tempm1->name;
for (i=0;i<de2->name_len;i=i+2) {
ptr1++;
*ptr1++=*ptr2++;
}
de2->length+=de2->name_len;
de2+=de2->length;
in_file=FOpen(tempm1->full_name,"r");
for (i=0;i<(FSize(in_file)+CD_BLK_SIZE-1)/CD_BLK_SIZE;i++) {
l=4;
if ((i+1)<<2>(FSize(in_file)+BLK_SIZE-1)/BLK_SIZE) {
l=((FSize(in_file)+BLK_SIZE-1)/BLK_SIZE)%4;
MemSet(buf,0,CD_BLK_SIZE);
}
if (write) {
FRBlks(in_file,buf,i<<2,l);
FWBlks(out_file,buf,(*cur_blk)<<2,l);
}
*cur_blk+=1;
}
FClose(in_file);
}
if ((de1-dir_blk_buf)/CD_BLK_SIZE!=
(de -dir_blk_buf)/CD_BLK_SIZE) {
i=de1->length;
MemCpy(buf,de1,i);
MemSet(de1,0,i);
de=dir_blk_buf+((de-dir_blk_buf)/CD_BLK_SIZE)*CD_BLK_SIZE;
MemCpy(de,buf,i);
de+=i;
}
if ((de12-dir_blk_buf2)/CD_BLK_SIZE!=
(de2 -dir_blk_buf2)/CD_BLK_SIZE) {
i=de12->length;
MemCpy(buf,de12,i);
MemSet(de12,0,i);
de2=dir_blk_buf2+((de2-dir_blk_buf2)/CD_BLK_SIZE)*CD_BLK_SIZE;
MemCpy(de2,buf,i);
de2+=i;
}
tempm1=tempm2;
}
tempc=tempm->user_data;
tempi->length=sizeof(ISODirEntry)-1;
tempi->ext_attr_length=0;
tempi->flags=ISO_ATTR_DIR;
if (!tempm->name[0]) {
tempi->name_len=1;
tempi->name=1;
} else {
tempi->name_len=StrLen(tempm->name);
StrCpy(&tempi->name,tempm->name);
}
tempi->length+=tempi->name_len;
l=de+1-dir_blk_buf;
l=(l+CD_BLK_SIZE-1)/CD_BLK_SIZE;
FillU4Palindrome(&tempi->size,l*CD_BLK_SIZE);
FillU4Palindrome(&tempi->location,*cur_blk);
tempc->short_dir_blks=l;
tempc->location=*cur_blk;
FillU4Palindrome(&dir_blk_buf->size,l*CD_BLK_SIZE);
FillU4Palindrome(&dir_blk_buf->location,*cur_blk);
FillU2Palindrome(&tempi->volume_sequence_num,1);
LTDateToISO(&tempi->date,tempm->datetime);
if (write)
coutln *cur_blk,":",tempm->full_name;
if (write)
FWBlks(out_file,dir_blk_buf,(*cur_blk)<<2,l<<2);
*cur_blk+=l;
tempi2->length=sizeof(ISODirEntry)-1;
tempi2->ext_attr_length=0;
tempi2->flags=ISO_ATTR_DIR;
if (!tempm->name[0]) {
tempi2->name_len=1;
tempi->name=1;
} else {
tempi2->name_len=StrLen(tempm->name)<<1;
ptr1=&tempi2->name;
ptr2=&tempm->name;
for (i=0;i<tempi2->name_len;i=i+2) {
ptr1++;
*ptr1++=*ptr2++;
}
}
tempi2->length+=tempi2->name_len;
l=de2+1-dir_blk_buf2;
l=(l+CD_BLK_SIZE-1)/CD_BLK_SIZE;
FillU4Palindrome(&tempi2->size,l*CD_BLK_SIZE);
FillU4Palindrome(&tempi2->location,*cur_blk);
tempc->long_dir_blks=l;
FillU4Palindrome(&dir_blk_buf2->size,l*CD_BLK_SIZE);
FillU4Palindrome(&dir_blk_buf2->location,*cur_blk);
FillU2Palindrome(&tempi2->volume_sequence_num,1);
LTDateToISO(&tempi2->date,tempm->datetime);
if (write)
coutln *cur_blk,":",tempm->full_name;
if (write)
FWBlks(out_file,dir_blk_buf2,(*cur_blk)<<2,l<<2);
*cur_blk+=l;
Free(dir_blk_buf);
Free(dir_blk_buf2);
Free(buf);
return tempi->name_len;
}
U8 CDTableLength(LTDirEntry *tempm,U8 *size1,U8 *size2,U8 cur_depth)
//returns depth
{
LTDirEntry *tempm1=tempm->sub;
U8 max_depth=cur_depth,i;
while (tempm1) {
if (tempm1->attr & LT_ATTR_DIR) {
*size1+=sizeof(ISOPathTableEntry)-2+((StrLen(tempm1->name)+1) & -0x2);
*size2+=sizeof(ISOPathTableEntry)-2+StrLen(tempm1->name)<<1;
i=CDTableLength(tempm1,size1,size2,cur_depth+1);
if (i>max_depth) max_depth=i;
}
tempm1=tempm1->next;
}
return max_depth;
}
void CDFillPathTable(LTDirEntry *tempm,
ISOPathTableEntry *itabbuf,ISOPathTableEntry *itabbuf2,
U8 parent_entry_num,BoolU4 big_endian,U8 *first_free,I8 cur_level,I8 output_level)
{
I1 *ptr1,*ptr2;
U8 i;
ISOPathTableEntry *tabbuf=*itabbuf;
ISOPathTableEntry *tabbuf2=*itabbuf2;
LTDirEntry *tempm1=tempm->sub,*tempm2;
CCdUserData *tempc;
if (cur_level==output_level) {
while (tempm1) {
if (tempm1->attr & LT_ATTR_DIR) {
tempc=tempm1->user_data;
tempc->path_entry_num=*first_free;
tabbuf->name_len=StrLen(tempm1->name);
if (big_endian) {
FillBigEndianU4(&tabbuf->blk,tempc->location);
FillBigEndianU2(&tabbuf->parent_entry_num,parent_entry_num);
} else {
tabbuf->blk=tempc->location;
tabbuf->parent_entry_num=parent_entry_num;
}
StrCpy(&tabbuf->name,tempm1->name);
tabbuf+=sizeof(ISOPathTableEntry)-2+
((StrLen(tempm1->name)+1) & -0x2);
tabbuf2->name_len=StrLen(tempm1->name)<<1;
if (big_endian) {
FillBigEndianU4(&tabbuf2->blk,tempc->location+tempc->short_dir_blks);
FillBigEndianU2(&tabbuf2->parent_entry_num,parent_entry_num);
} else {
tabbuf2->blk=tempc->location+tempc->short_dir_blks;
tabbuf2->parent_entry_num=parent_entry_num;
}
ptr1=&tabbuf2->name;
ptr2=&tempm1->name;
for (i=0;i<tabbuf2->name_len;i=i+2) {
ptr1++;
*ptr1++=*ptr2++;
}
tabbuf2+=sizeof(ISOPathTableEntry)-2+
StrLen(tempm1->name)<<1;
*first_free+=1;
}
tempm1=tempm1->next;
}
*itabbuf=tabbuf;
*itabbuf2=tabbuf2;
}
tempm1=tempm->sub;
while (tempm1) {
tempm2=tempm1->next;
if (tempm1->attr & LT_ATTR_DIR) {
tempc=tempm1->user_data;
CDFillPathTable(tempm1,itabbuf,itabbuf2,tempc->path_entry_num,
big_endian,first_free,cur_level+1,output_level);
}
tempm1=tempm2;
}
}
class ElTorito
{
U2 w[16];
U1 bootable; //88=bootable 00=not bootable
U1 media_type; //0=no emulation 4=hard disk
U2 load_seg; //0000->07C0
U1 sys_type;
U1 zero;
U2 sector_cnt;
U4 load_rba; //start address of virtual disk
U1 zero2[20];
};
public U8 CreateCDFile(I1 *filename,I1 src_drive,
I1 *bootfile=NULL)
{
ISOPrimaryDescriptor *iso =MAllocZ(CD_BLK_SIZE),
*iso1=MAllocZ(CD_BLK_SIZE),
*iso2=MAllocZ(CD_BLK_SIZE),
*iso3=MAllocZ(CD_BLK_SIZE);
LTDirEntry *rootdir=MAllocZ(sizeof(LTDirEntry));
U8 my_flags=(1<<FUf_RECURSE);
U8 cur_blk=0,bsize,tabsize,tabsize2,first_free,max_depth;
U4 *d;
I1 mask[8];
I1 *filename2=DefaultExtension(filename,"ISO");
ElTorito *et=MAllocZ(CD_BLK_SIZE);
U1 *buf=MAllocZ(CD_BLK_SIZE),
*bootfile_buf=NULL;
ISOPathTableEntry *tabbuf=NULL,*tabbuf2=NULL,
*itabbuf,*itabbuf2;
BoolU4 okay=TRUE;
U8 i,j;
LTFile *out_file=NULL;
ISODirEntry *tempi;
CCdUserData *tempc;
SPrintF(mask,"%c:/*",src_drive);
if (bootfile)
bootfile_buf=ReadFile(bootfile,&bsize);
rootdir->attr=LT_ATTR_DIR;
rootdir->sub=FindFiles(mask,&my_flags);
rootdir->datetime=GetCurTimeLTDate;
rootdir->user_data=MAllocZ(sizeof(CCdUserData));
tempc=rootdir->user_data;
tempc->path_entry_num=1;
if (okay) {
cur_blk=CD_FILE_OFFSET>>2;
if (bootfile_buf)
cur_blk+=2;
DoCreateCDFile(out_file,rootdir,
&iso->root_directory_record,
&iso2->root_directory_record,
&cur_blk,rootdir,FALSE);
tabsize=sizeof(ISOPathTableEntry);
tabsize2=sizeof(ISOPathTableEntry);
max_depth=CDTableLength(rootdir,&tabsize,&tabsize2,1);
FillU4Palindrome(&iso->path_table_size,tabsize);
FillU4Palindrome(&iso2->path_table_size,tabsize2);
tabsize=(tabsize+CD_BLK_SIZE-1)/CD_BLK_SIZE;
cur_blk+=tabsize<<1;
tabsize2=(tabsize2+CD_BLK_SIZE-1)/CD_BLK_SIZE;
cur_blk+=tabsize2<<1;
}
if (okay) {
if (FileAttr(filename2) & LT_ATTR_CONTIGUOUS)
out_file=FOpen(filename2,"wc",cur_blk<<2);
else
out_file=FOpen(filename2,"w",cur_blk<<2);
if (!out_file)
okay=FALSE;
}
if (okay) {
cur_blk=0;
while (cur_blk<CD_FILE_OFFSET>>2) {
FWBlks(out_file,buf,cur_blk<<2,4);
cur_blk++;
}
iso->type=ISOT_PRIMARY_VOLUME_DESC;
StrCpy(iso->id,"CD001");
iso->version=1;
FillU2Palindrome(&iso->volume_set_size,1);
FillU2Palindrome(&iso->volume_sequence_number,1);
FillU2Palindrome(&iso->logical_block_size,CD_BLK_SIZE);
iso->file_structure_version=1;
iso2->type=ISOT_SUPPLEMENTARY_DESC;
StrCpy(iso2->id,"CD001");
iso2->version=1;
FillU2Palindrome(&iso2->volume_set_size,1);
FillU2Palindrome(&iso2->volume_sequence_number,1);
FillU2Palindrome(&iso2->logical_block_size,CD_BLK_SIZE);
iso2->file_structure_version=1;
iso1->type=ISOT_BOOT_RECORD;
StrCpy(iso1->id,"CD001");
iso1->version=1;
StrCpy(iso1+7,"EL TORITO SPECIFICATION");
cur_blk=CD_FILE_OFFSET>>2;
if (bootfile_buf) {
d=iso1+0x47;
*d=cur_blk;
et->w[0]=1;
StrCpy(&et->w[2],"LoseThos");
et->w[15]=0xAA55;
j=0;
for (i=0;i<16;i++) //Checksum
j+=et->w[i];
et->w[14]=-j;
if (bootfile_buf)
et->bootable=0x88;
et->media_type=0; //0=no emu 2=1.44meg 4=hard drive
et->sector_cnt=4;
et->load_rba=cur_blk+1;
coutln cur_blk,": Pre Boot Blk";
FWBlks(out_file,et,cur_blk<<2,4);
cur_blk++;
coutln cur_blk,": Boot Blk";
FWBlks(out_file,bootfile_buf,cur_blk<<2,4);
cur_blk++;
}
DoCreateCDFile(out_file,rootdir,
&iso->root_directory_record,
&iso2->root_directory_record,
&cur_blk,rootdir,TRUE);
tabbuf=MAllocZ(tabsize*CD_BLK_SIZE);
iso->type_l_path_table=cur_blk;
tabbuf->name_len=2; //Fill-in adam entry
tempi=&iso->root_directory_record;
tabbuf->blk=tempi->location.little;
tabbuf->parent_entry_num=1;
tabbuf2=MAllocZ(tabsize2*CD_BLK_SIZE);
iso2->type_l_path_table=cur_blk+tabsize;
tabbuf2->name_len=2; //Fill-in adam entry
tempi=&iso2->root_directory_record;
tabbuf2->blk=tempi->location.little;
tabbuf2->parent_entry_num=1;
itabbuf=tabbuf+sizeof(ISOPathTableEntry);
itabbuf2=tabbuf2+sizeof(ISOPathTableEntry);
first_free=2;
for (i=1;i<=max_depth;i++)
CDFillPathTable(rootdir,&itabbuf,&itabbuf2,
1,FALSE,&first_free,1,i);
coutln cur_blk,": Path Table 0";
FWBlks(out_file,tabbuf,cur_blk<<2,tabsize<<2);
cur_blk+=tabsize;
coutln cur_blk,": Path Table 1";
FWBlks(out_file,tabbuf2,cur_blk<<2,tabsize2<<2);
cur_blk+=tabsize2;
MemSet(tabbuf,0,tabsize*CD_BLK_SIZE);
FillBigEndianU4(&iso->type_m_path_table,cur_blk);
tabbuf->name_len=2; //Fill-in adam entry
tempi=&iso->root_directory_record;
tabbuf->blk=tempi->location.big;
FillBigEndianU2(&tabbuf->parent_entry_num,1);
MemSet(tabbuf2,0,tabsize2*CD_BLK_SIZE);
FillBigEndianU4(&iso2->type_m_path_table,cur_blk+tabsize);
tabbuf2->name_len=2; //Fill-in adam entry
tempi=&iso2->root_directory_record;
tabbuf2->blk=tempi->location.big;
FillBigEndianU2(&tabbuf2->parent_entry_num,1);
itabbuf=tabbuf+sizeof(ISOPathTableEntry);
itabbuf2=tabbuf2+sizeof(ISOPathTableEntry);
first_free=2;
for (i=1;i<=max_depth;i++)
CDFillPathTable(rootdir,&itabbuf,&itabbuf2,
1,TRUE,&first_free,1,i);
coutln cur_blk,": Path Table 2";
FWBlks(out_file,tabbuf,cur_blk<<2,tabsize<<2);
cur_blk+=tabsize;
coutln cur_blk,": Path Table 3";
FWBlks(out_file,tabbuf2,cur_blk<<2,tabsize2<<2);
cur_blk+=tabsize2;
DelLTDirList(rootdir); //TODO: Free user_data
FillU4Palindrome(&iso->volume_space_size,cur_blk);
FillU4Palindrome(&iso2->volume_space_size,cur_blk);
FWBlks(out_file,iso,16<<2,4);
iso3->type=ISOT_TERMINATOR;
StrCpy(iso3->id,"CD001");
iso3->version=1;
if (bootfile_buf) {
FWBlks(out_file,iso1,17<<2,4);
FWBlks(out_file,iso2,18<<2,4);
FWBlks(out_file,iso3,19<<2,4);
} else {
FWBlks(out_file,iso2,17<<2,4);
FWBlks(out_file,iso3,18<<2,4);
}
} else
cur_blk=0;
FClose(out_file);
Free(tabbuf);
Free(tabbuf2);
Free(et);
Free(bootfile_buf);
Free(iso);
Free(iso1);
Free(iso2);
Free(iso3);
Free(filename2);
return cur_blk;
}
public void SetDriveTextAttr(I1 drive=0,U1 attr)
{
LTPartition *p;
try {
p=DriveToPartition(drive);
p->text_attr=attr;
} catch {
Fs->catch_except=TRUE;
}
}
public void PrintFDriveTextAttr(I1 drive=0)
{
LTPartition *p=DriveToPartition(drive);
U1 fg=p->text_attr&0xF,bg=p->text_attr>>4;
if (fg!=bg)
PrintF("$$FG,%d$$$$BG,%d$$",fg,bg);
}
U8 SizeFlattenLTDirTree(LTDirEntry *tempm)
{
U8 result=0;
while (tempm) {
result+=sizeof(LTDirEntry)-offset(LTDirEntry.start)+1;
if (tempm->attr & LT_ATTR_DIR)
result+=SizeFlattenLTDirTree(tempm->sub);
tempm=tempm->next;
}
return result+1;
}
U8 FillFlattenLTDirTree(LTDirEntry *tempm,U1 *dst)
{
U8 result=0,i;
while (tempm) {
*dst++=1;
result++;
i=sizeof(LTDirEntry)-offset(LTDirEntry.start);
MemCpy(dst,&tempm->start,i);
dst+=i;
result+=i;
if (tempm->attr & LT_ATTR_DIR) {
i=FillFlattenLTDirTree(tempm->sub,dst);
dst+=i;
result+=i;
}
tempm=tempm->next;
}
*dst=0;
return result+1;
}
public U1 *FlattenLTDirTree(LTDirEntry *tempm,U8 *size=NULL)
{
U8 i=SizeFlattenLTDirTree(tempm);
U1 *buf=MAlloc(i);
FillFlattenLTDirTree(tempm,buf);
if (*size) *size=i;
return buf;
}
U1 *DoUnflattenLTDirTree(U1 *src,LTDirEntry **tempm)
{
U8 i;
LTDirEntry *tempm1;
if (*src++) {
tempm1=MAllocZ(sizeof(LTDirEntry));
*tempm=tempm1;
i=sizeof(LTDirEntry)-offset(LTDirEntry.start);
MemCpy(&tempm1->start,src,i);
src+=i;
if (tempm1->attr & LT_ATTR_DIR)
src=DoUnflattenLTDirTree(src,&tempm1->sub);
src=DoUnflattenLTDirTree(src,&tempm1->next);
} else
*tempm=NULL;
return src;
}
public LTDirEntry *UnflattenLTDirTree(U1 *src)
{
LTDirEntry *tempm=NULL;
DoUnflattenLTDirTree(src,&tempm);
return tempm;
}
+3346
View File
File diff suppressed because it is too large. Load diff
+69
View File
@@ -0,0 +1,69 @@
$FG,2$$WW,1$'^'$FG$ Means the Control Key
$MA+A+LA+S,"Toggle Plain Text ^T","Msg(2,0x14,0x41400000414);"$
Select Text SHIFT CURSOR
$MA+A+LA,"Cut to Clipboard SHIFT DEL","Msg(2,0,0x3D300000253);"$
$MA+A+LA,"Copy to Clipboard ^INS","Msg(2,0,0x4D200000452);"$
$MA+A+LA,"Paste from Clipboard SHIFT INS","Msg(2,0,0x2D200000252);"$
$MA+A+LA,"Del Line ^Y","Msg(2,0x19,0x41500000415);"$
Begin/End of Line ^Left/^Right
Begin/End of File ^Up/^Down
$MA+A+LA,"Indent In ^N","Msg(2,0xE,0x43100000431);"$
$MA+A+LA,"Indent Out ^SHIFT N","Msg(2,0xE,0x63100000631);"$
$MA+A+LA,"Word Wrap On ^W","Msg(2,0x17,0x41100000411);"$
$MA+A+LA,"Word Wrap Off ^SHIFT W","Msg(2,0x17,0x61100000611);"$
$MA+A+LA,"Underline On ^U","Msg(2,0x15,0x41600000416);"$
$MA+A+LA,"Underline Off ^SHIFT U","Msg(2,0x15,0x61600000616);"$
$MA+A+LA,"Blink On ^B","Msg(2,2,0x43000000430);"$
$MA+A+LA,"Blink Off ^SHIFT B","Msg(2,2,0x63000006300);"$
$MA+A+LA,"Invert Color On ^Z","Msg(2,0x1A,0x42C0000042C);"$
$MA+A+LA,"Invert Color Off ^SHIFT Z","Msg(2,0x1A,0x62C0000062C);"$
$MA+A+LA,"Superscript ^P","Msg(2,0x10,0x41900000419);"$
$MA+A+LA,"Normal ^SHIFT P","Msg(2,0x10,0x61900000619);"$
$MA+A+LA,"Subscript ^ALT P","Msg(2,0x10,0xC1900000C19);"$
$MA+A+LA,"Insert Dollar Cmd ^L","Msg(2,0xC,0x42600000426);"$
$MA+A+LA,"Insert Graphic Cmd ^R","Msg(2,0x12,0x41300000413);"$
$MA+A+LA,"Macro Capture and Play F2","Msg(2,0,0x3C0000003C);"$
$MA+A+LA,"Page Break ^ENTER","Msg(2,0xD,0x41C0000041C);"$
$MA+A+LA,"Print PrintScreen","Msg(2,0,0xB7000000B7);"$
$MA+A+LA,"Goto Favorites ^SHIFT F","Msg(2,6,0x62100000621);"$
$MA+A+LA,"Find/Replace ^F","Msg(2,6,0x42100000421);"$
$MA+A+LA,"Find Next F3","Msg(2,0,0x3D0000003D);"$
$MA+A+LA,"Go to Line ^G","Msg(2,7,0x42200000422);"$
$MA+A+LA,"Save ^S","Msg(2,0x13,0x41F0000041F);"$
$MA+A+LA,"Save As ^A","Msg(2,1,0x41E0000041E);"$
$MA+A+LA,"Quit No Save ^Q","Msg(2,0x11,0x41000000410);"$
$MA+A+LA,"Quit and Save ESC","Msg(2,0x1B,0x0100000001);"$
$TR,"Cmd Line Issues"$
$ID,2$$FG$* CTRL-SHIFT-ENTER can be used to insert a carriage return without issuing a cmd. This is useful when you have scrolled-up and wish to enter a cmd on a blank line.
* The last semicolon on the line is converted to a double semicolon because the compiler looks ahead before doing a cmd. This normally has no negative effect, but when entering "if" statements with "else" clauses it presents problems.
$ID,-2$$TR,"Hot Keys"$
$ID,2$$FG,9$CTRL ALT DEL$FG$ Reboots
$FG,9$CTRL ALT ESC$FG$ Spawns new task
$FG,9$CTRL ALT TAB$FG$ Switches tasks
$FG,9$CTRL ALT X$FG$ Kills current task
$FG,9$$FG,9$CTRL ALT C$FG$ Breaks current program
$FG,9$WINDOWS KEY$FG$ Activates Menu/Help/Macro area
$FG,9$CTRL FUNCTION KEY$FG$ Enters autocomplete word
$FG,9$CTRL SHIFT-FUNCTION KEY$FG$ Does man page on symbol
$ID,-2$$TR,"Debugging"$
$ID,2$F9 Toggle Breakpoint
SHIFT-F9 Clear ALL Breakpoints
F5 Go
SHIFT-F5 Single-Step
$ID,-2$
* If "MENU" appears on the title bar, you can click it with a mouse.
+172
View File
@@ -0,0 +1,172 @@
public class U1Fifo
{
U1 *buf;
U8 mask,in_ptr,out_ptr;
};
public U1Fifo *NewU1Fifo(U8 size)
{
U1Fifo *f;
f=MAlloc(sizeof(U1Fifo));
f->buf=MAlloc(size);
f->mask=size-1;
f->in_ptr=0;
f->out_ptr=0;
return f;
}
public void DelU1Fifo(U1Fifo *f)
{
Free(f->buf);
Free(f);
}
public BoolU4 U1FifoInsert(U1Fifo *f,U1 ch)
{
U8 old_flags=GetFlags,
new_in_ptr;
Cli;
new_in_ptr=(f->in_ptr+1)&f->mask;
if (new_in_ptr==f->out_ptr) {
SetFlags(old_flags);
return FALSE;
} else {
f->buf[f->in_ptr]=ch;
f->in_ptr=new_in_ptr;
SetFlags(old_flags);
return TRUE;
}
}
public BoolU4 U1FifoRemove(U1Fifo *f,U1 *ch)
{
U8 old_flags=GetFlags;
Cli;
if (f->in_ptr==f->out_ptr) {
SetFlags(old_flags);
return FALSE;
} else {
*ch=f->buf[f->out_ptr];
f->out_ptr=(f->out_ptr+1)&f->mask;
SetFlags(old_flags);
return TRUE;
}
}
public BoolU4 U1FifoPeek(U1Fifo *f,U1 *ch)
{
U8 old_flags=GetFlags;
Cli;
if (f->in_ptr==f->out_ptr) {
SetFlags(old_flags);
return FALSE;
} else {
*ch=f->buf[f->out_ptr];
SetFlags(old_flags);
return TRUE;
}
}
public void U1FifoFlush(U1Fifo *f)
{
f->out_ptr=f->in_ptr;
}
public U8 U1FifoCnt(U1Fifo *f)
{
U8 result,old_flags=GetFlags;
Cli;
if (f->out_ptr>f->in_ptr)
result=f->mask+1-(f->out_ptr-f->in_ptr);
else
result=f->in_ptr-f->out_ptr;
SetFlags(old_flags);
return result;
}
public class U4Fifo
{
U4 *buf;
U8 mask,in_ptr,out_ptr;
};
public U4Fifo *NewU4Fifo(U8 size)
{
U4Fifo *f;
f=MAlloc(sizeof(U4Fifo));
f->buf=MAlloc(size*sizeof(U4));
f->mask=size-1;
f->in_ptr=0;
f->out_ptr=0;
return f;
}
public void DelU4Fifo(U4Fifo *f)
{
Free(f->buf);
Free(f);
}
public BoolU4 U4FifoInsert(U4Fifo *f,U4 d)
{
U8 old_flags=GetFlags,
new_in_ptr;
Cli;
new_in_ptr=(f->in_ptr+1)&f->mask;
if (new_in_ptr==f->out_ptr) {
SetFlags(old_flags);
return FALSE;
} else {
f->buf[f->in_ptr]=d;
f->in_ptr=new_in_ptr;
SetFlags(old_flags);
return TRUE;
}
}
public BoolU4 U4FifoRemove(U4Fifo *f,U4 *d)
{
U8 old_flags=GetFlags;
Cli;
if (f->in_ptr==f->out_ptr) {
SetFlags(old_flags);
return FALSE;
} else {
*d=f->buf[f->out_ptr];
f->out_ptr=(f->out_ptr+1)&f->mask;
SetFlags(old_flags);
return TRUE;
}
}
public BoolU4 U4FifoPeek(U1Fifo *f,U4 *d)
{
U8 old_flags=GetFlags;
Cli;
if (f->in_ptr==f->out_ptr) {
SetFlags(old_flags);
return FALSE;
} else {
*d=f->buf[f->out_ptr];
SetFlags(old_flags);
return TRUE;
}
}
public void U4FifoFlush(U4Fifo *f)
{
f->out_ptr=f->in_ptr;
}
public U8 U4FifoCnt(U4Fifo *f)
{
U8 result,old_flags=GetFlags;
Cli;
if (f->out_ptr>f->in_ptr)
result=f->mask+1-(f->out_ptr-f->in_ptr);
else
result=f->in_ptr-f->out_ptr;
SetFlags(old_flags);
return result;
}
+834
View File
@@ -0,0 +1,834 @@
I8 PopUpGrElemType(BoolU4 new_picture)
{
I8 i;
Ltf *l=LtfNew;
LtfPutS(l,"$$MU,\"Color (4-bit)\" GRET_COLOR4$$\r\n");
LtfPutS(l,"$$MU,\"Width\" GRET_WIDTH$$\r\n");
LtfPutS(l,"$$MU,\"Point\" GRET_POINT$$\r\n");
LtfPutS(l,"$$MU,\"Line\" GRET_LINE$$\r\n");
LtfPutS(l,"$$MU,\"PolyLine\" GRET_POLYLINE$$\r\n");
LtfPutS(l,"$$MU,\"PolyPoint\" GRET_POLYPOINT$$\r\n");
LtfPutS(l,"$$MU,\"BSpline2\" GRET_BSPLINE2$$\r\n");
LtfPutS(l,"$$MU,\"BSpline3\" GRET_BSPLINE3$$\r\n");
LtfPutS(l,"$$MU,\"BSpline2 Closed\" GRET_BSPLINE2_CLOSED$$\r\n");
LtfPutS(l,"$$MU,\"BSpline3 Closed\" GRET_BSPLINE3_CLOSED$$\r\n");
LtfPutS(l,"$$MU,\"End\" GRET_END$$\r\n");
if (new_picture)
LtfPutS(l,"$$MU,\"Cancel\" -1$$\r\n");
LtfPutS(l,"\r\nNote: Right-Click to get back to this menu.\r\n"
"Press ESC to Exit, CTRL-Q to abort.\r\n");
i=PopUpMenu(l);
LtfDel(l);
return i;
}
public I8 PopUpColor()
{
I8 i;
Ltf *l=LtfNew;
for (i=0;i<16;i++)
LtfPrintF(l,"$$BM %d$$$$MU,\"________________\" %d$$\r\n",i,i);
LtfPutS(l,"$$BM WHITE$$$$MU,\"DEFAULT\" -1$$");
i=PopUpMenu(l);
LtfDel(l);
return i;
}
public I8 PopUpWidth()
{
I8 i;
Ltf *l=LtfNew;
for (i=0;i<16;i++)
LtfPrintF(l,"$$MU,\"%d\" %d$$\r\n",i,i);
i=PopUpMenu(l);
LtfDel(l);
return i;
}
I8 GrXOffsets[8]={-1,0,1,-1,1,-1,0,1},
GrYOffsets[8]={-1,-1,-1,0,0,1,1,1};
U8 GrElemBaseSize(I8 type,BoolU4 queue=TRUE)
{
U8 i=(queue) ? offset(GrElem.start):0;
switch (type) {
case GRET_COLOR4:
i+=1+offset(GrElem.color4)-offset(GrElem.start);
break;
case GRET_COLOR24:
i+=3+offset(GrElem.color24)-offset(GrElem.start);
break;
case GRET_WIDTH:
i+=offset(GrElem.y1)-offset(GrElem.start);
break;
case GRET_POINT:
i+=offset(GrElem.x2)-offset(GrElem.start);
break;
case GRET_LINE:
i+=sizeof(GrElem)-offset(GrElem.start);
break;
case GRET_POLYLINE:
case GRET_POLYPOINT:
case GRET_BSPLINE2:
case GRET_BSPLINE3:
case GRET_BSPLINE2_CLOSED:
case GRET_BSPLINE3_CLOSED:
i+=offset(GrElem.y1)-offset(GrElem.start);
break;
case GRET_SHIFT:
i+=offset(GrElem.x2)-offset(GrElem.start);
break;
case GRET_END:
i+=offset(GrElem.x1)-offset(GrElem.start);
break;
}
return i;
}
U8 GrElemSize(GrElem *tempg,BoolU4 queue=TRUE)
{
U8 i=GrElemBaseSize(tempg->type,queue);
switch (tempg->type) {
case GRET_POLYLINE:
i+=tempg->num<<1*sizeof(I4);
break;
case GRET_POLYPOINT:
i+=sizeof(I4)<<1+(tempg->num*3+7)>>3;
break;
case GRET_BSPLINE2:
case GRET_BSPLINE3:
case GRET_BSPLINE2_CLOSED:
case GRET_BSPLINE3_CLOSED:
i+=tempg->num*sizeof(P3I4);
break;
}
return i;
}
//If you do not enter a color or width into
//a GrElem, you can pass a color and width
//when you plot it. "colorbase" is the color of
//the background you are drawing on.
public void GrElemsPlot(GrBitMap *base,I8 x,I8 y,I8 z,U1 *elems,U8 colorbase)
{
GrElem *tempg=elems-offset(GrElem.start);
U8 i,j;
I8 x1,y1,x2,y2;
I4 *ptr;
I8 cur_sub_GrElem_num=0;
P3I4 *p;
while (tempg->type) {
base->cur_sub_GrElem=cur_sub_GrElem_num++;
switch (tempg->type) {
case GRET_COLOR4:
base->color=colorbase^tempg->color4;
break;
case GRET_COLOR24:
base->color=colorbase^tempg->color24;
break;
case GRET_WIDTH:
base->pen_width=tempg->width;
break;
case GRET_POINT:
GrPlot3(base,tempg->x1+x,tempg->y1+y,0);
break;
case GRET_SHIFT:
x+=tempg->x1;
y+=tempg->y1;
break;
case GRET_LINE:
GrLine3(base,tempg->x1+x,tempg->y1+y,0,tempg->x2+x,tempg->y2+y,0);
break;
case GRET_POLYLINE:
ptr=&tempg->y1;
x1=ptr[0];
y1=ptr[1];
for (i=1;i<tempg->num;i++) {
x2=ptr[i<<1];
y2=ptr[i<<1+1];
GrLine3(base,x1+x,y1+y,0,x2+x,y2+y,0);
x1=x2;y1=y2;
}
break;
case GRET_POLYPOINT:
ptr=&tempg->y1;
x1=ptr[0];
y1=ptr[1];
ptr=ptr+sizeof(I4)<<1;
for (i=0;i<tempg->num;i++) {
GrPlot3(base,x1+x,y1+y,0);
j=Bt(ptr,i*3)+Bt(ptr,i*3+1)<<1+Bt(ptr,i*3+2)<<2;
x1+=GrXOffsets[j];
y1+=GrYOffsets[j];
}
break;
case GRET_BSPLINE2:
p=&tempg->y1;
for (i=0;i<tempg->num;i++) {
p[i].x+=x;
p[i].y+=y;
}
Gr2BSpline3(base,p,tempg->num,FALSE);
for (i=0;i<tempg->num;i++) {
p[i].x-=x;
p[i].y-=y;
}
break;
case GRET_BSPLINE3:
p=&tempg->y1;
for (i=0;i<tempg->num;i++) {
p[i].x+=x;
p[i].y+=y;
}
Gr3BSpline3(base,p,tempg->num,FALSE);
for (i=0;i<tempg->num;i++) {
p[i].x-=x;
p[i].y-=y;
}
break;
case GRET_BSPLINE2_CLOSED:
p=&tempg->y1;
for (i=0;i<tempg->num;i++) {
p[i].x+=x;
p[i].y+=y;
}
Gr2BSpline3(base,p,tempg->num,TRUE);
for (i=0;i<tempg->num;i++) {
p[i].x-=x;
p[i].y-=y;
}
break;
case GRET_BSPLINE3_CLOSED:
p=&tempg->y1;
for (i=0;i<tempg->num;i++) {
p[i].x+=x;
p[i].y+=y;
}
Gr3BSpline3(base,p,tempg->num,TRUE);
for (i=0;i<tempg->num;i++) {
p[i].x-=x;
p[i].y-=y;
}
break;
}
tempg+=GrElemSize(tempg,FALSE);
}
}
public void GrSetOrigin(GrElem *root,I8 dx,I8 dy,I8 dz)
{
U8 i;
I4 *ptr;
P3I4 *p;
GrElem *tempg=root->next;
while (tempg!=root) {
switch (tempg->type) {
case GRET_POINT:
tempg->x1+=dx;
tempg->y1+=dy;
break;
case GRET_LINE:
tempg->x1+=dx;
tempg->y1+=dy;
tempg->x2+=dx;
tempg->y2+=dy;
break;
case GRET_POLYLINE:
ptr=&tempg->y1;
ptr[0]+=dx;
ptr[1]+=dy;
for (i=1;i<tempg->num;i++) {
ptr[i<<1]+=dx;
ptr[i<<1+1]+=dy;
}
break;
case GRET_POLYPOINT:
ptr=&tempg->y1;
ptr[0]+=dx;
ptr[1]+=dy;
break;
case GRET_BSPLINE2:
case GRET_BSPLINE3:
case GRET_BSPLINE2_CLOSED:
case GRET_BSPLINE3_CLOSED:
p=&tempg->y1;
for (i=0;i<tempg->num;i++) {
p[i].x+=dx;
p[i].y+=dy;
}
break;
}
tempg=tempg->next;
}
}
void GrPolyPointPlot(GrElem *root,I8 x,I8 y,I8 z)
{
GrElem *tempg;
tempg=MAllocZ(GrElemBaseSize(GRET_POINT));
tempg->type=GRET_POINT;
tempg->x1=x;
tempg->y1=y;
InsQue(tempg,root->last);
}
void GrElemsDel(GrElem *root)
{
GrElem *tempg,*tempg1;
tempg=root->next;
while (tempg!=root) {
tempg1=tempg->next;
Free(tempg);
tempg=tempg1;
}
}
GrElem *GrElemsFromQueue(GrElem *root,U4 *size=NULL)
{
U8 s,my_size=GrElemBaseSize(GRET_END,FALSE);
GrElem *tempg,*result,*dst;
tempg=root->next;
while (tempg!=root) {
my_size+=GrElemSize(tempg,FALSE);
tempg=tempg->next;
}
result=MAlloc(my_size);
dst=result;
tempg=root->next;
while (tempg!=root) {
s=GrElemSize(tempg,FALSE);
MemCpy(dst,&tempg->type,s);
dst+=s;
tempg=tempg->next;
}
*dst=GRET_END;
if (size) *size=my_size;
return result;
}
GrElem *GrElemsToQueue(GrElem *elems)
{
U8 s;
GrElem *result=MAllocZ(sizeof(GrElem)),
*tempg=elems-offset(GrElem.start),
*tempg1;
result->next=result;
result->last=result;
while (tempg->type) {
tempg1=MAlloc(GrElemSize(tempg,TRUE));
s=GrElemSize(tempg,FALSE);
MemCpy(&tempg1->type,&tempg->type,s);
InsQue(tempg1,result->last);
tempg+=s;
}
return result;
}
public I4 PopUpPickGrElem(GrElem *root)
{
Ltf *l=LtfNew;
GrElem *tempg;
I4 cur_num=0;
tempg=root->next;
while (tempg!=root) {
LtfPrintF(l,"$$MU,\"%Z\",%d$$\r\n",
tempg->type,"ST_GRELEM_TYPES",cur_num++);
tempg=tempg->next;
}
LtfPrintF(l,"$$MU,\"END\",%d$$\r\n",cur_num);
cur_num=PopUpMenu(l);
LtfDel(l);
return cur_num;
}
#define GED_PICK_TEXT 1
#define GED_PICK_GRAPHICALLY 2
#define GED_SET_ORIGIN 3
#define GED_SHIFT_ORIGIN 4
#define GED_INSERT 5
#define GED_DELETE 6
#define GED_EDIT 7
#define GED_END 8
#define GED_CANCEL -1
I8 PopUpGrElemsEditChoice()
{
I8 i;
Ltf *l=LtfNew;
LtfPutS(l,"$$MU,\"Pick from text\",GED_PICK_TEXT$$\r\n");
LtfPutS(l,"$$MU,\"Pick graphically\",GED_PICK_GRAPHICALLY$$\r\n");
LtfPutS(l,"$$MU,\"Set Origin\",GED_SET_ORIGIN$$\r\n");
LtfPutS(l,"$$MU,\"Insert Shift Origin\",GED_SHIFT_ORIGIN$$\r\n");
LtfPutS(l,"$$MU,\"Insert\",GED_INSERT$$\r\n");
LtfPutS(l,"$$MU,\"Delete\",GED_DELETE$$\r\n");
// LtfPutS(l,"$$MU,\"Edit\",GED_EDIT$$\r\n");
LtfPutS(l,"$$MU,\"End\",GED_END$$\r\n");
LtfPutS(l,"$$MU,\"Cancel\",GED_CANCEL$$\r\n");
i=PopUpMenu(l);
LtfDel(l);
return i;
}
GrElem *GrNumToQueue(GrElem *root,I8 num,I8 *x=NULL,I8 *y=NULL)
{
I8 xx=0,yy=0;
GrElem *result=root->next;
while (result!=root && num--) {
if (result->type==GRET_SHIFT) {
xx+=result->x1;
yy+=result->y1;
}
result=result->next;
}
if (x) *x=xx;
if (y) *y=yy;
return result;
}
void GrEditUpdate(LtfBinEntry *tempb,GrElem *root)
{
BoolU4 old_preempt=Preempt(OFF);
Free(tempb->data);
tempb->data=GrElemsFromQueue(root,&tempb->size);
Preempt(old_preempt);
}
I4 GrElOffset[9]={0,1,2,3,0,4,5,6,7};
BoolU4 GrElemsInsert(LtfBinEntry *tempb,I8 *cur_num,GrElem *root,I8 x,I8 y,BoolU4 new_picture)
{
I8 i,j,cmd,x1,y1,x2,y2,x3,y3,p1,p2;
I4 *ptr;
U8 color=ROP_EQU^GR_BLACK^((Fs->text_attribute>>4)&15);
BoolU4 old_ip_double=Bts(&Fs->crt_flags,CRTf_NO_DOUBLE_CLICK);
I8 eletype=-2;
GrElem root2,*tempg,*tempg1,*tempg2,*insert_point;
U8 num;
BoolU4 old_inhibit=ip_inhibit_win_operations;
GrBitMap *base=GrNew(grbase);
I8 width=1;
P3I4 *p;
insert_point=GrNumToQueue(root,*cur_num,&x1,&y1);
x+=x1; y+=y1;
ip_inhibit_win_operations=TRUE;
while (TRUE) {
GrClear;
if (eletype==-2) {
ip_inhibit_win_operations=FALSE;
i=PopUpGrElemType(new_picture);
if (i>=-1)
eletype=i;
ip_inhibit_win_operations=TRUE;
}
switch (eletype) {
case GRET_COLOR4:
ip_inhibit_win_operations=FALSE;
i=PopUpColor;
if (i>=0) {
color=ROP_EQU|i;
tempg=MAlloc(GrElemBaseSize(GRET_COLOR4));
tempg->type=GRET_COLOR4;
tempg->color4=color;
InsQue(tempg,insert_point->last);
GrEditUpdate(tempb,root);
*cur_num=*cur_num+1;
}
ip_inhibit_win_operations=TRUE;
eletype=-2;
color^=((Fs->text_attribute>>4)&15);
base->color=color;
break;
case GRET_COLOR24:
eletype=-2;
break;
case GRET_WIDTH:
ip_inhibit_win_operations=FALSE;
i=PopUpWidth;
if (i>=1) {
width=i;
tempg=MAlloc(GrElemBaseSize(GRET_WIDTH));
tempg->type=GRET_WIDTH;
tempg->width=width;
InsQue(tempg,insert_point->last);
GrEditUpdate(tempb,root);
*cur_num=*cur_num+1;
base->pen_width=width;
}
ip_inhibit_win_operations=TRUE;
eletype=-2;
break;
}
if (eletype!=-2) {
cmd=0;p1=0;p2=0;
if (eletype!=GRET_END && eletype!=-1) {
cmd=GetMsg(&p1,&p2,
(1<<MSG_KEY_DOWN)+(1<<MSG_IP_L_DOWN)+
(1<<MSG_IP_R_UP));
if (cmd==MSG_IP_R_UP)
eletype=-2;
}
if (eletype==GRET_END || eletype==-1
|| cmd==MSG_KEY_DOWN) {
if (eletype==GRET_END || eletype==-1
|| p1==CH_CTRLQ || p1==CH_ESC) {
AssignBit(&Fs->crt_flags,CRTf_NO_DOUBLE_CLICK,old_ip_double);
ip_inhibit_win_operations=old_inhibit;
GrDel(base);
return eletype==GRET_END || p1==CH_ESC;
}
} else {
switch (eletype) {
case GRET_LINE:
x1=p1; y1=p2;
x2=p1; y2=p2;
do {
base->color=color&0xFFFFFF|ROP_OR;
GrLine3(base,x1,y1,0,x2,y2,0);
cmd=GetMsg(&p1,&p2,
(1<<MSG_IP_L_UP)+(1<<MSG_IP_MOVE));
base->color=color&0xFFFFFF|ROP_NAND;
GrLine3(base,x1,y1,0,x2,y2,0);
x2=p1; y2=p2;
} while (cmd!=MSG_IP_L_UP);
base->color=color&0xFFFFFF|ROP_EQU;
GrLine3(base,x1,y1,0,x2,y2,0);
tempg=MAlloc(GrElemBaseSize(GRET_LINE));
tempg->type=GRET_LINE;
tempg->x1=x1-x;
tempg->y1=y1-y;
tempg->x2=x2-x;
tempg->y2=y2-y;
InsQue(tempg,insert_point->last);
GrEditUpdate(tempb,root);
*cur_num=*cur_num+1;
break;
case GRET_POINT:
x1=p1; y1=p2;
base->color=color;
GrPlot3(base,x1,y1,0);
tempg=MAlloc(GrElemBaseSize(GRET_POINT));
tempg->type=GRET_POINT;
tempg->x1=x1-x;
tempg->y1=y1-y;
InsQue(tempg,insert_point->last);
GrEditUpdate(tempb,root);
*cur_num=*cur_num+1;
break;
case GRET_POLYLINE:
root2.next=&root2;
root2.last=&root2;
num=0;
x3=p1-x; y3=p2-y;
x1=p1; y1=p2;
x2=p1; y2=p2;
do {
do {
base->color=color&0xFFFFFF|ROP_OR;
GrLine3(base,x1,y1,0,x2,y2,0);
cmd=GetMsg(&p1,&p2,
(1<<MSG_IP_L_UP)+(1<<MSG_IP_MOVE)+
(1<<MSG_IP_R_UP));
base->color=color&0xFFFFFF|ROP_NAND;
GrLine3(base,x1,y1,0,x2,y2,0);
x2=p1; y2=p2;
} while (cmd!=MSG_IP_L_UP && cmd!=MSG_IP_R_UP);
base->color=color&0xFFFFFF|ROP_EQU;
if (cmd==MSG_IP_L_UP) {
GrLine3(base,x1,y1,0,x2,y2,0);
tempg=MAlloc(GrElemBaseSize(GRET_POINT));
tempg->type=GRET_POINT;
tempg->x1=x2-x;
tempg->y1=y2-y;
InsQue(tempg,root2.last);
x1=x2;y1=y2;
num++;
}
} while (cmd!=MSG_IP_R_UP);
if (num) {
tempg2=MAllocZ(GrElemBaseSize(GRET_POLYLINE)+
(num+1)<<1*sizeof(I4));
ptr=&tempg2->y1;
tempg=root2.next;
ptr[0]=x3;
ptr[1]=y3;
ptr+=sizeof(I4)<<1;
for (i=0;i<num;i++) {
tempg1=tempg->next;
ptr[i<<1]=tempg->x1;
ptr[i<<1+1]=tempg->y1;
Free(tempg);
tempg=tempg1;
}
tempg2->type=GRET_POLYLINE;
tempg2->num=num+1;
InsQue(tempg2,insert_point->last);
GrEditUpdate(tempb,root);
*cur_num=*cur_num+1;
}
break;
case GRET_POLYPOINT:
root2.next=&root2;
root2.last=&root2;
x3=p1-x; y3=p2-y;
x1=p1; y1=p2;
x2=p1; y2=p2;
base->color=color&0xFFFFFF|ROP_EQU;
do {
cmd=GetMsg(&p1,&p2,
(1<<MSG_IP_L_UP)+(1<<MSG_IP_MOVE));
x2=p1; y2=p2;
GrLine3(base,x1,y1,0,x2,y2,0);
Line(&root2,x1-x,y1-y,0,x2-x,y2-y,0,&GrPolyPointPlot);
x1=x2;y1=y2;
num++;
} while (cmd!=MSG_IP_L_UP);
num=0;
tempg=root2.next;
x1=x3;y1=y3;
while (tempg!=&root2) {
tempg1=tempg->next;
if (tempg->x1==x1 && tempg->y1==y1) {
RemQue(tempg);
Free(tempg);
} else {
num++;
x1=tempg->x1;
y1=tempg->y1;
}
tempg=tempg1;
}
tempg2=MAllocZ(GrElemBaseSize(GRET_POLYPOINT)+
sizeof(I4)*2+(num*3+7)>>3);
ptr=&tempg2->y1;
tempg=root2.next;
ptr[0]=x3;
ptr[1]=y3;
ptr+=sizeof(I4)<<1;
x1=x3;y1=y3;
for (i=0;i<num;i++) {
tempg1=tempg->next;
j=GrElOffset[SignI8(tempg->x1-x1)+1+3*(SignI8(tempg->y1-y1)+1)];
x1=tempg->x1;y1=tempg->y1;
if (j&1) Bts(ptr,i*3);
if (j&2) Bts(ptr,i*3+1);
if (j&4) Bts(ptr,i*3+2);
Free(tempg);
tempg=tempg1;
}
tempg2->type=GRET_POLYPOINT;
tempg2->num=num+1;
InsQue(tempg2,insert_point->last);
GrEditUpdate(tempb,root);
*cur_num=*cur_num+1;
break;
case GRET_BSPLINE2:
case GRET_BSPLINE3:
case GRET_BSPLINE2_CLOSED:
case GRET_BSPLINE3_CLOSED:
root2.next=&root2;
root2.last=&root2;
num=0;
x3=p1-x; y3=p2-y;
x1=p1; y1=p2;
x2=p1; y2=p2;
do {
do {
base->color=color&0xFFFFFF|ROP_OR;
GrLine3(base,x1,y1,0,x2,y2,0);
cmd=GetMsg(&p1,&p2,
(1<<MSG_IP_L_UP)+(1<<MSG_IP_MOVE)+
(1<<MSG_IP_R_UP));
base->color=color&0xFFFFFF|ROP_NAND;
GrLine3(base,x1,y1,0,x2,y2,0);
x2=p1; y2=p2;
} while (cmd!=MSG_IP_L_UP && cmd!=MSG_IP_R_UP);
base->color=color&0xFFFFFF|ROP_EQU;
if (cmd==MSG_IP_L_UP) {
GrLine3(base,x1,y1,0,x2,y2,0);
tempg=MAlloc(GrElemBaseSize(GRET_POINT));
tempg->type=GRET_POINT;
tempg->x1=x2-x;
tempg->y1=y2-y;
InsQue(tempg,root2.last);
x1=x2;y1=y2;
num++;
}
} while (cmd!=MSG_IP_R_UP);
if (num) {
tempg2=MAllocZ(GrElemBaseSize(GRET_POLYLINE)+
(num+1)*sizeof(P3I4));
p=&tempg2->y1;
tempg=root2.next;
p[0].x=x3;
p[0].y=y3;
p+=sizeof(P3I4);
for (i=0;i<num;i++) {
tempg1=tempg->next;
p[i].x=tempg->x1;
p[i].y=tempg->y1;
Free(tempg);
tempg=tempg1;
}
tempg2->type=eletype;
tempg2->num=num+1;
InsQue(tempg2,insert_point->last);
GrEditUpdate(tempb,root);
*cur_num=*cur_num+1;
}
break;
}
}
}
}
}
void EditInsertGraphic(Ltf *l,I8 x,I8 y)
{
BoolU4 old_preempt=Preempt(OFF);
LtfEntry *ll;
LtfBinEntry *tempb;
I8 cur_num=0;
GrElem *root;
tempb=MAllocZ(sizeof(LtfBinEntry));
tempb->type=LTFBT_ELEMENT_GRAPH;
tempb->size=GrElemBaseSize(GRET_END,FALSE);
tempb->data=MAllocZ(tempb->size);
ll=MAllocZ(sizeof(LtfEntry));
ll->display=NewString("");
ll->plain_text=MSPrintF("PI %d",l->cur_bin_num);
ll->bin_num=l->cur_bin_num;
tempb->num=l->cur_bin_num++;
ll->type=LTFT_PICTURE;
ll->flags=LTFLF_HAS_BIN;
ll->bin_data=tempb;
InsQue(tempb,l->bin_root.last);
LtfInsert(l,ll);
Preempt(old_preempt);
root=GrElemsToQueue(tempb->data);
if (!GrElemsInsert(tempb,&cur_num,root,x,y,TRUE)) {
Preempt(OFF);
RemQue(ll);
Free(ll);
Free(ll->display);
Free(ll->plain_text);
RemQue(tempb);
Free(tempb->data);
Preempt(old_preempt);
}
GrElemsDel(root);
}
public void LtfPutGrElem(Ltf *l,U1 *elems,U8 size)
{
BoolU4 old_preempt=Preempt(OFF);
LtfEntry *ll;
LtfBinEntry *tempb;
tempb=MAllocZ(sizeof(LtfBinEntry),l->mem_tss);
tempb->type=LTFBT_ELEMENT_GRAPH;
tempb->size=size;
tempb->data=MAlloc(size,l->mem_tss);
MemCpy(tempb->data,elems,size);
ll=MAllocZ(sizeof(LtfEntry),l->mem_tss);
ll->display=NewString("",l->mem_tss);
ll->plain_text=MSPrintF("PI %d",l->cur_bin_num); //TODO:mem_tss
ll->bin_num=l->cur_bin_num;
tempb->num=l->cur_bin_num++;
ll->type=LTFT_PICTURE;
ll->flags=LTFLF_HAS_BIN;
ll->bin_data=tempb;
InsQue(tempb,l->bin_root.last);
LtfInsert(l,ll);
Preempt(old_preempt);
}
public void PutGrElem(U1 *elems,U8 size)
{
Ltf *l=Fs->cur_ltf;
if (l)
LtfPutGrElem(l,elems,size);
}
void EditExistingGraphic(Ltf *l,I8 x,I8 y)
{
BoolU4 *old_preempt=Preempt(OFF);
LtfEntry *ll=l->cur_entry;
LtfBinEntry *tempb=ll->bin_data;
I8 i,cur_num=0,cmd,p1,p2,old_size=tempb->size,xx,yy;
GrElem *cur_elem,*old_GrElem=tempb->data,
*root=GrElemsToQueue(old_GrElem),*tempg,*insert_point;
BoolU4 old_inhibit=ip_inhibit_win_operations;
BoolU4 old_ip_double=Bt(&Fs->crt_flags,CRTf_NO_DOUBLE_CLICK);
tempb->data=MAllocIdentical(old_GrElem);
Preempt(old_preempt);
do {
i=PopUpGrElemsEditChoice;
switch (i) {
case GED_PICK_TEXT:
cur_num=PopUpPickGrElem(root);
break;
case GED_PICK_GRAPHICALLY:
l->cur_GrElem=tempb->data;
GetMsg(&p1,&p2,1<<MSG_IP_L_UP);
cur_num=l->cur_sub_GrElem;
l->cur_GrElem=NULL;
break;
case GED_SET_ORIGIN:
GetMsg(&p1,&p2,1<<MSG_IP_L_UP);
GrSetOrigin(root,x-p1,y-p2,0);
GrEditUpdate(tempb,root);
break;
case GED_SHIFT_ORIGIN:
ip_inhibit_win_operations=TRUE;
Bts(&Fs->crt_flags,CRTf_NO_DOUBLE_CLICK);
insert_point=GrNumToQueue(root,cur_num);
tempg=MAlloc(GrElemBaseSize(GRET_SHIFT));
tempg->type=GRET_SHIFT;
tempg->x1=0;
tempg->y1=0;
InsQue(tempg,insert_point->last);
GetMsg(&p1,&p2,1<<MSG_IP_L_DOWN);
xx=p1; yy=p2;
do {
cmd=GetMsg(&p1,&p2,
(1<<MSG_IP_L_UP)+(1<<MSG_IP_MOVE));
tempg->x1=p1-xx;
tempg->y1=p2-yy;
GrEditUpdate(tempb,root);
} while (cmd!=MSG_IP_L_UP);
AssignBit(&Fs->crt_flags,CRTf_NO_DOUBLE_CLICK,old_ip_double);
ip_inhibit_win_operations=old_inhibit;
break;
case GED_INSERT:
GrElemsInsert(tempb,&cur_num,root,x,y,FALSE);
break;
case GED_DELETE:
cur_elem=GrNumToQueue(root,cur_num);
if (cur_elem!=root) {
RemQue(cur_elem);
Free(cur_elem);
GrEditUpdate(tempb,root);
}
break;
case GED_EDIT:
break;
}
} while (i!=GED_CANCEL && i!=GED_END);
Preempt(OFF);
if (i==GED_END)
Free(old_GrElem);
else {
Free(tempb->data);
tempb->data=old_GrElem;
tempb->size=old_size;
}
Preempt(old_preempt);
GrElemsDel(root);
}
+425
View File
@@ -0,0 +1,425 @@
ALIGN 8,0x90
REVERSE_BITS_TABLE::
$FG$$BG$ DU1 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0;
DU1 0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0;
DU1 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8;
DU1 0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8;
DU1 0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4;
DU1 0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4;
DU1 0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC;
DU1 0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC;
DU1 0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2;
DU1 0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2;
DU1 0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA;
DU1 0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA;
DU1 0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6;
DU1 0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6;
DU1 0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE;
DU1 0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE;
DU1 0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1;
DU1 0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1;
DU1 0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9;
DU1 0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9;
DU1 0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5;
DU1 0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5;
DU1 0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED;
DU1 0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD;
DU1 0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3;
DU1 0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3;
DU1 0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB;
DU1 0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB;
DU1 0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7;
DU1 0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7;
DU1 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF;
DU1 0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF;
$FU$$FG$$BG$$FU$$FG$$BG$
MSG_DRAW_TASK_BORDER: DU1 "DrawTaskBorder",0;
MSG_UPDATE_ODES: DU1 "UpdateOdes",0;
////**************************PROCEDURE*************************
ALIGN 8,0x90
CP_PLOT_SCREEN_I1::
PUSH EBP
MOV EBP,ESP
MOV EBX,SF_PARAM2[EBP]
MOV EAX,SF_PARAM3[EBP]
OR EBX,EBX
JS @@100
OR EAX,EAX
JS @@100
CMP EBX,U4 FS:[TSS_CRT_WIDTH]
JGE @@100
CMP EAX,U4 FS:[TSS_CRT_HEIGHT]
JGE @@100
IMUL U4 FS:[TSS_CRT_WIDTH]
ADD EAX,U4 [SYS_TEXTBASE]
ADD EBX,EAX
MOV EAX,U4 SF_PARAM1[EBP]
MOV U4 [EBX],EAX
POP EBP
XOR EDX,EDX
MOV EAX,1
RET
@@100: POP EBP
XOR EDX,EDX
XOR EAX,EAX
RET
////**************************PROCEDURE*************************
ALIGN 8,0x90
CP_PLOT_WINDOW_I1::
PUSH EBP
MOV EBP,ESP
MOV EBX,U4 SF_PARAM2[EBP]
MOV EAX,U4 SF_PARAM3[EBP]
OR EBX,EBX
JS @@100
ADD EBX,U4 FS:[TSS_WINDOW_LEFT]
CMP EBX,U4 FS:[TSS_WINDOW_RIGHT]
JG @@100
OR EBX,EBX
JS @@100
CMP EBX,U4 FS:[TSS_CRT_WIDTH]
JGE @@100
OR EAX,EAX
JS @@100
ADD EAX,U4 FS:[TSS_WINDOW_TOP]
CMP EAX,U4 FS:[TSS_WINDOW_BOTTOM]
JG @@100
OR EAX,EAX
JS @@100
CMP EAX,U4 FS:[TSS_CRT_HEIGHT]
JGE @@100
IMUL U4 FS:[TSS_CRT_WIDTH]
ADD EAX,U4 [SYS_TEXTBASE]
ADD EBX,EAX
MOV EAX,U4 SF_PARAM1[EBP]
MOV U4 [EBX],EAX
POP EBP
XOR EDX,EDX
MOV EAX,1
RET
@@100: POP EBP
XOR EDX,EDX
XOR EAX,EAX
RET
////**************************PROCEDURE*************************
ALIGN 8,0x90
CP_PLOT_BORDER_I1::
PUSH EBP
MOV EBP,ESP
MOV EBX,U4 SF_PARAM2[EBP]
MOV EAX,U4 SF_PARAM3[EBP]
MOV EDX,-4
CMP EBX,EDX
JL @@100
ADD EBX,U4 FS:[TSS_WINDOW_LEFT]
MOV EDX,U4 FS:[TSS_WINDOW_RIGHT]
ADD EDX,4
CMP EBX,EDX
JG @@100
OR EBX,EBX
JS @@100
CMP EBX,U4 FS:[TSS_CRT_WIDTH]
JGE @@100
MOV EDX,-1
CMP EAX,EDX
JL @@100
ADD EAX,U4 FS:[TSS_WINDOW_TOP]
MOV EDX,U4 FS:[TSS_WINDOW_BOTTOM]
INC EDX
CMP EAX,EDX
JG @@100
OR EAX,EAX
JS @@100
CMP EAX,U4 FS:[TSS_CRT_HEIGHT]
JGE @@100
IMUL U4 FS:[TSS_CRT_WIDTH]
ADD EAX,U4 [SYS_TEXTBASE]
ADD EBX,EAX
MOV EAX,U4 SF_PARAM1[EBP]
MOV U4 [EBX],EAX
POP EBP
XOR EDX,EDX
MOV EAX,1
RET
@@100: POP EBP
XOR EDX,EDX
XOR EAX,EAX
RET
////**************************PROCEDURE*************************
ALIGN 8,0x90
GR_UPDATE_WINDOWS::
PUSHAD //-****
MOV ESI,U4 FS:[TSS_ABSOLUTE_ADDRESS]
MOV EDI,ESI
JMP @@1
@@10: MOV EAX,U4 TSS_FS[EDI]
MOV FS,AX
PUSH ESI
MOV ESI,MSG_UPDATE_ODES
CALL FIND_EXTERN
JZ @@11
CALL ESI
@@11: POP ESI
BT U4 FS:[TSS_CRT_FLAGS],CRTf_SHOW
JNC @@2
PUSH ESI
MOV ESI,MSG_DRAW_TASK_BORDER
CALL FIND_EXTERN
JZ @@12
CALL ESI
@@12: POP ESI
BT U4 [SYS_FLAGS],SYSf_TASK_LINKS_ALTERED
JC @@100
@@1: MOV EAX,U4 FS:[TSS_UPDATE_WINDOW]
OR EAX,EAX
JZ @@2
CALL EAX
@@2: BT U4 [SYS_FLAGS],SYSf_TASK_LINKS_ALTERED
JC @@100
MOV EDI,U4 FS:[TSS_NEXT_TSS]
CMP ESI,EDI
JNE @@10
@@100: MOV EAX,U4 TSS_FS[ESI]
MOV FS,AX
POPAD //+****
RET
////**************************PROCEDURE*************************
ALIGN 8,0x90
/*
GrXorLine(&dst3,&src,&src2,d5,vga_image);
for (col=0;col<d5;col++) {
*dst3=*src^*src2;
dst3+=4;
src+=4;
src2+=4;
}
*/
GR_XOR_LINE::
PUSH EBP
MOV EBP,ESP
PUSH ESI
PUSH EDI
MOV EAX,SF_PARAM2[EBP]
MOV EDX,U4 [EAX]
MOV EAX,SF_PARAM3[EBP]
MOV ESI,U4 [EAX]
MOV ECX,SF_PARAM4[EBP]
MOV EAX,SF_PARAM5[EBP]
MOV EDI,U4 [EAX]
@@5: MOV EAX,U4 [ESI]
XOR EAX,U4 [EDX]
MOV U4 [ESI],EAX
CMP U4 [EDI],EAX
JNE @@7
STOSD
ADD ESI,4
ADD EDX,4
LOOP @@5
MOV EAX,SF_PARAM5[EBP]
MOV U4[EAX],EDI
MOV EAX,SF_PARAM1[EBP]
MOV EDI,U4 [EAX]
MOV ECX,SF_PARAM4[EBP]
ADD EDI,ECX
ADD EDI,ECX
ADD EDI,ECX
ADD EDI,ECX
JMP @@100
@@6: MOV EAX,U4 [ESI]
XOR EAX,U4 [EDX]
MOV U4 [ESI],EAX
@@7: STOSD
ADD ESI,4
ADD EDX,4
LOOP @@6
MOV EAX,SF_PARAM5[EBP]
MOV U4[EAX],EDI
MOV EBX,REVERSE_BITS_TABLE
MOV EAX,SF_PARAM3[EBP]
MOV ESI,U4 [EAX]
MOV ECX,SF_PARAM4[EBP]
MOV EAX,SF_PARAM1[EBP]
MOV EDI,U4 [EAX]
@@10: LODSD
XLATB
ROR EAX,8
XLATB
ROR EAX,8
XLATB
ROR EAX,8
XLATB
ROR EAX,8
STOSD
LOOP @@10
@@100: MOV EAX,SF_PARAM3[EBP]
MOV U4[EAX],ESI
MOV EAX,SF_PARAM1[EBP]
MOV U4[EAX],EDI
MOV EAX,SF_PARAM2[EBP]
MOV U4[EAX],EDX
POP EDI
POP ESI
POP EBP
RET
////**************************PROCEDURE*************************
ALIGN 8,0x90
/*
GrPlotChar(font_ptr,cur_ch.u1[1],&dst2,d1,d2);
for (plane=0x01;plane!=0x10;plane<<=1) {
font_ptr2=font_ptr;
if (cur_ch.u1[1] & plane) {
for (ch_line=0;ch_line<FONT_HEIGHT;ch_line++) {
*dst2|=*font_ptr2++;
dst2+=d1;
}
} else {
for (ch_line=0;ch_line<FONT_HEIGHT;ch_line++) {
*dst2&=~*font_ptr2++;
dst2+=d1;
}
}
dst2+=d2;
}
*/
GR_PLOT_CHAR::
PUSH EBP
MOV EBP,ESP
PUSH ESI
PUSH EDI
MOV EDX,1 //EDX=plane
MOV EBX,U4 SF_PARAM4[EBP] //EBX=d1
MOV EAX,U4 SF_PARAM3[EBP] //EDI=dst2
MOV EDI,U4 [EAX] //EDI=dst2
@@10: MOV ESI,U4 SF_PARAM1[EBP] //ESI=font_ptr2
TEST U4 SF_PARAM2[EBP],EDX
JZ @@30
@@20: LODSD
OR U1 [EDI],AL
ADD EDI,EBX
OR U1 [EDI],AH
ADD EDI,EBX
ROR EAX,16
OR U1 [EDI],AL
ADD EDI,EBX
OR U1 [EDI],AH
ADD EDI,EBX
LODSD
OR U1 [EDI],AL
ADD EDI,EBX
OR U1 [EDI],AH
ADD EDI,EBX
ROR EAX,16
OR U1 [EDI],AL
ADD EDI,EBX
OR U1 [EDI],AH
ADD EDI,EBX
JMP @@40
@@30: LODSD
NOT EAX
AND U1 [EDI],AL
ADD EDI,EBX
AND U1 [EDI],AH
ADD EDI,EBX
ROR EAX,16
AND U1 [EDI],AL
ADD EDI,EBX
AND U1 [EDI],AH
ADD EDI,EBX
LODSD
NOT EAX
AND U1 [EDI],AL
ADD EDI,EBX
AND U1 [EDI],AH
ADD EDI,EBX
ROR EAX,16
AND U1 [EDI],AL
ADD EDI,EBX
AND U1 [EDI],AH
ADD EDI,EBX
@@40: ADD EDI,U4 SF_PARAM5[EBP]
SHL1 EDX
CMP EDX,0x10
JNE @@10
MOV EAX,SF_PARAM3[EBP]
MOV U4[EAX],EDI
POP EDI
POP ESI
POP EBP
RET
////**************************PROCEDURE*************************
ALIGN 8,0x90
/*
GrPlotBackground(cur_ch.u1[1],&dst,d1,d2);
for (plane=0x10;plane!=0x100;plane=plane<<1) {
d=(cur_ch.u1[1] & plane) ? 0xFF:0x00;
for (ch_line=0;ch_line<FONT_HEIGHT;ch_line++) {
*dst=d;
dst+=d1;
}
dst+=d2;
}
*/
GR_PLOT_BACKGROUND::
PUSH EBP
MOV EBP,ESP
PUSH EDI
MOV EDX,0x10 //EDX=plane
MOV EBX,U4 SF_PARAM3[EBP] //EBX=d1
MOV EAX,U4 SF_PARAM2[EBP] //EDI=dst
MOV EDI,U4 [EAX] //EDI=dst
@@10: XOR EAX,EAX
TEST U4 SF_PARAM1[EBP],EDX
JZ @@20
DEC EAX
@@20: MOV U1 [EDI],AL
ADD EDI,EBX
MOV U1 [EDI],AL
ADD EDI,EBX
MOV U1 [EDI],AL
ADD EDI,EBX
MOV U1 [EDI],AL
ADD EDI,EBX
MOV U1 [EDI],AL
ADD EDI,EBX
MOV U1 [EDI],AL
ADD EDI,EBX
MOV U1 [EDI],AL
ADD EDI,EBX
MOV U1 [EDI],AL
ADD EDI,EBX
ADD EDI,U4 SF_PARAM4[EBP]
SHL1 EDX
CMP EDX,0x100
JNE @@10
MOV EAX,SF_PARAM2[EBP]
MOV U4[EAX],EDI
POP EDI
POP EBP
RET
+1228
View File
File diff suppressed because it is too large. Load diff
+14
View File
@@ -0,0 +1,14 @@
#define IP_NULL 0
#define IP_JOYSTICK0 1
#define IP_JOYSTICK1 2
#define IP_MOUSE 3
public I8 ipx=-100,ipy=-100,ipz=0;
public I8 ip_speed=0;
public I8 ip_pointer_type=IP_NULL;
public I8 iptx=ipx/FONT_WIDTH,ipty=ipy/FONT_HEIGHT;
public BoolU4 ip_on=TRUE, //Show or hide cursor
ip_lb_last=FALSE,ip_rb_last=FALSE,
ip_lb=FALSE,ip_cb=FALSE,ip_rb=FALSE; //Left/center/right buttons
public BoolU4 ip_has_wheel=FALSE;
public LTDate last_ip_move_time=BootTime;
+304
View File
@@ -0,0 +1,304 @@
#define ICT_U2 1
#define ICT_U4 2
#define ICT_U8 3
class IncCompressStructU2
{
U2 match_start;
U2 match_size;
U2 diff_size;
U0 diff_data;
};
class IncCompressStructU4
{
U4 match_start;
U2 match_size;
U2 diff_size;
U0 diff_data;
};
class IncCompressStructU8
{
U8 match_start;
U2 match_size;
U2 diff_size;
U0 diff_data;
};
class IntermediateIncCompressStruct
{
IntermediateIncCompressStruct *next,*last;
U8 match_start_ref,match_start,match_size;
};
void IncCompressRange(U1 *ref,U8 ref_size,U1 *b,U8 range_start,U8 range_end,
IntermediateIncCompressStruct *root,U8 type_size)
{
I8 i,j,k,l,best_k=0,best_j,best_i;
IntermediateIncCompressStruct *tempc;
//$BK,1$TODO: improve this algorithm$BK,0$
for (i=range_start;i<range_end;i++) {
for (j=0;j<ref_size;j++) {
k=0;
l=(ref_size-j<range_end-i) ? ref_size-j:range_end-i;
while (ref[j+k]==b[i+k] && k<l)
k++;
if (k>best_k) {
best_k=k;
best_j=j;
best_i=i;
}
}
}
if (best_k>type_size) {
if (range_start+type_size<best_i)
IncCompressRange(ref,ref_size,b,range_start,best_i,root,type_size);
tempc=MAlloc(sizeof(IntermediateIncCompressStruct));
tempc->match_start_ref=best_j;
tempc->match_start=best_i;
tempc->match_size=best_k;
InsQue(tempc,root->last);
if (best_i+best_k+type_size<range_end)
IncCompressRange(ref,ref_size,b,best_i+best_k,range_end,root,type_size);
}
}
public IncCompressStructU2 *IncCompress(U1 *ref,U8 ref_size,U1 *b,U8 size)
{
U8 i,j=0,l=0,m=0,ic_type;
U1 *u1,*result;
U2 *u2;
U4 *u4;
U8 *u8;
IntermediateIncCompressStruct root,*tempc,*tempc1;
IncCompressStructU2 *tempi2;
IncCompressStructU4 *tempi4;
IncCompressStructU8 *tempi8;
root.next=&root;
root.last=&root;
if (ref_size<=0xFFFF && size<=0xFFFF) {
ic_type=ICT_U2;
i=sizeof(U1)+size+2*sizeof(U2);
IncCompressRange(ref,ref_size,b,0,size,&root,sizeof(IncCompressStructU2));
if (root.next==&root)
i+=sizeof(IncCompressStructU2);
else {
tempc=root.next;
while (tempc!=&root) {
i-=tempc->match_size-sizeof(IncCompressStructU2);
tempc=tempc->next;
}
}
} else if (ref_size<=0xFFFFFFFF && size<=0xFFFFFFFF) {
ic_type=ICT_U4;
i=sizeof(U1)+size+2*sizeof(U4);
IncCompressRange(ref,ref_size,b,0,size,&root,sizeof(IncCompressStructU4));
if (root.next==&root)
i+=sizeof(IncCompressStructU4);
else {
tempc=root.next;
while (tempc!=&root) {
i-=tempc->match_size-sizeof(IncCompressStructU4);
tempc=tempc->next;
}
}
} else {
ic_type=ICT_U8;
i=sizeof(U1)+size+2*sizeof(U8);
IncCompressRange(ref,ref_size,b,0,size,&root,sizeof(IncCompressStructU8));
if (root.next==&root)
i+=sizeof(IncCompressStructU8);
else {
tempc=root.next;
while (tempc!=&root) {
i-=tempc->match_size-sizeof(IncCompressStructU8);
tempc=tempc->next;
}
}
}
result=MAlloc(i);
u1=result;
*u1=ic_type;
switch (ic_type) {
case ICT_U2:
u2=result+sizeof(U1);
*u2=i;
u2+=sizeof(U2);
*u2=size;
tempi2=u2+sizeof(U2);
tempc=root.next;
while (tempc!=&root) {
tempc1=tempc->next;
if (l || tempc->match_start-(j+l)) {
tempi2->match_start=m;
tempi2->match_size=l;
tempi2->diff_size=tempc->match_start-(j+l);
if (tempi2->diff_size)
MemCpy(&tempi2->diff_data,b+j+l,tempi2->diff_size);
tempi2+=sizeof(IncCompressStructU2)+tempi2->diff_size;
}
m=tempc->match_start_ref;
j=tempc->match_start;
l=tempc->match_size;
Free(tempc);
tempc=tempc1;
}
tempi2->match_start=m;
tempi2->match_size=l;
tempi2->diff_size=size-(j+l);
if (tempi2->diff_size)
MemCpy(&tempi2->diff_data,b+j+l,tempi2->diff_size);
break;
case ICT_U4:
u4=result+sizeof(U1);
*u4=i;
u4+=sizeof(U4);
*u4=size;
tempi4=u4+sizeof(U4);
//$BK,1$TODO: deal with >65536 matches and differences$BK,0$
tempc=root.next;
while (tempc!=&root) {
tempc1=tempc->next;
if (l || tempc->match_start-(j+l)) {
tempi4->match_start=m;
tempi4->match_size=l;
tempi4->diff_size=tempc->match_start-(j+l);
if (tempi4->diff_size)
MemCpy(&tempi4->diff_data,b+j+l,tempi4->diff_size);
tempi4+=sizeof(IncCompressStructU4)+tempi4->diff_size;
}
m=tempc->match_start_ref;
j=tempc->match_start;
l=tempc->match_size;
Free(tempc);
tempc=tempc1;
}
tempi4->match_start=m;
tempi4->match_size=l;
tempi4->diff_size=size-(j+l);
if (tempi4->diff_size)
MemCpy(&tempi4->diff_data,b+j+l,tempi4->diff_size);
break;
case ICT_U8:
u8=result+sizeof(U1);
*u8=i;
u8+=sizeof(U8);
*u8=size;
tempi8=u8+sizeof(U8);
//$BK,1$TODO: deal with >65536 matches and differences$BK,0$
tempc=root.next;
while (tempc!=&root) {
tempc1=tempc->next;
if (l || tempc->match_start-(j+l)) {
tempi8->match_start=m;
tempi8->match_size=l;
tempi8->diff_size=tempc->match_start-(j+l);
if (tempi8->diff_size)
MemCpy(&tempi8->diff_data,b+j+l,tempi8->diff_size);
tempi8+=sizeof(IncCompressStructU8)+tempi8->diff_size;
}
m=tempc->match_start_ref;
j=tempc->match_start;
l=tempc->match_size;
Free(tempc);
tempc=tempc1;
}
tempi8->match_start=m;
tempi8->match_size=l;
tempi8->diff_size=size-(j+l);
if (tempi8->diff_size)
MemCpy(&tempi8->diff_data,b+j+l,tempi8->diff_size);
break;
}
return result;
}
public U1 *IncExpand(U1 *ref,IncCompressStructU2 *b,U8 *size=NULL)
{
U1 *result,*dst,*u1=b,*b_end;
U2 *u2;
U4 *u4;
U8 *u8=b,s,ic_type;
IncCompressStructU2 *tempi2;
IncCompressStructU4 *tempi4;
IncCompressStructU8 *tempi8;
ic_type=*u1;
switch (ic_type) {
case ICT_U2:
u2=b+sizeof(U1);
b_end=b+*u2;
u2+=sizeof(U2);
s=*u2;
break;
case ICT_U4:
u4=b+sizeof(U1);
b_end=b+*u4;
u4+=sizeof(U4);
s=*u4;
break;
case ICT_U8:
u8=b+sizeof(U1);
b_end=b+*u8;
u8+=sizeof(U8);
s=*u8;
break;
}
result=MAlloc(s);
if (size) *size=s;
dst=result;
switch (ic_type) {
case ICT_U2:
tempi2=b+sizeof(U1)+2*sizeof(U2);
while (tempi2<b_end) {
if (tempi2->match_size) {
MemCpy(dst,ref+tempi2->match_start,tempi2->match_size);
dst+=tempi2->match_size;
}
if (tempi2->diff_size) {
MemCpy(dst,&tempi2->diff_data,tempi2->diff_size);
dst+=tempi2->diff_size;
}
tempi2+=sizeof(IncCompressStructU2)+tempi2->diff_size;
}
break;
case ICT_U4:
tempi4=b+sizeof(U1)+2*sizeof(U4);
while (tempi4<b_end) {
if (tempi4->match_size) {
MemCpy(dst,ref+tempi4->match_start,tempi4->match_size);
dst+=tempi4->match_size;
}
if (tempi4->diff_size) {
MemCpy(dst,&tempi4->diff_data,tempi4->diff_size);
dst+=tempi4->diff_size;
}
tempi4+=sizeof(IncCompressStructU4)+tempi4->diff_size;
}
break;
case ICT_U8:
tempi8=b+sizeof(U1)+2*sizeof(U8);
while (tempi8<b_end) {
if (tempi8->match_size) {
MemCpy(dst,ref+tempi8->match_start,tempi8->match_size);
dst+=tempi8->match_size;
}
if (tempi8->diff_size) {
MemCpy(dst,&tempi8->diff_data,tempi8->diff_size);
dst+=tempi8->diff_size;
}
tempi8+=sizeof(IncCompressStructU8)+tempi8->diff_size;
}
break;
}
return result;
}
+136
View File
@@ -0,0 +1,136 @@
#define JOY_CAL_FILE "::/LT/ADAM/JOY.DTZ"
#define LTPORT 0x201
#define CMAX 0x800
public I8 joyv[4],joymax[4],joymin[4],joyrest[4];
public BoolU4 joyb[4],joy_calibrated=FALSE,joy_being_calibrated=FALSE;
public I8 joysat=100,joynx=0,joyny=0; //Normalized
public I8 joycx=grwidth>>1,joycy=grheight>>1,joycvx=0,joycvy=0;
public I8 joytx=0,joyty=0; //Text row & col
void PollJoystick()
{
I8 i, j;
I8 mask = 15;
I8 scale2=24;
BoolU4 old_preempt=Preempt(OFF);
for (i=0;i<4;i++)
joyv[i]=0;
OutP(LTPORT, 0);
for (i=1; mask && i < CMAX; i++) {
j = InP(LTPORT) ^ mask;
if (j & 1) { joyv[0] = i; mask = mask ^ 1; }
if (j & 2) { joyv[1] = i; mask = mask ^ 2; }
if (j & 4) { joyv[2] = i; mask = mask ^ 4; }
if (j & 8) { joyv[3] = i; mask = mask ^ 8; }
}
Preempt(old_preempt);
j = InP(LTPORT);
joyb[0] = !(j & 0x10);
joyb[1] = !(j & 0x20);
joyb[2] = !(j & 0x40);
joyb[3] = !(j & 0x80);
if (joy_calibrated) {
joynx=joysat*(joyv[0]-joyrest[0])/(joymax[0]-joymin[0]+1);
if (AbsI8(joynx)<15)
joycvx=0;
else
joycvx+=joynx-SignI8(joynx)*15;
joyny=joysat*(joyv[1]-joyrest[1])/(joymax[1]-joymin[1]+1);
if (AbsI8(joyny)<15)
joycvy=0;
else
joycvy+=joyny-SignI8(joyny)*15;
joycx+=joycvx/scale2;
joycvx=70*joycvx/100;
joycy+=joycvy/scale2;
joycvy=70*joycvy/100;
if (joycx < 0) joycx=0;
if (joycx>=grwidth) joycx=grwidth-1;
if (joycy < 0) joycy=0;
if (joycy>=grheight) joycy=grheight-1;
joytx=joycx/FONT_WIDTH;
joyty=joycy/FONT_HEIGHT;
}
}
public void JoyCalibration()
{
I8 i,x,y;
I8 buf[3<<2];
I8 old_ip=ip_pointer_type;
joy_calibrated=FALSE;
ip_pointer_type=IP_JOYSTICK0;
GrBitMap *base=GrNew(grbase);
base->color=ROP_XOR|GR_WHITE;
for (i=0;i<4;i++)
joyb[i]=0;
coutln "$$CL$$Leave joystick and throttle centered\r\n and press button.";
while (!(joyb[0] || joyb[1])) {
SwapInNext;
}
for (i=0;i<4;i++) {
joyrest[i]=joyv[i];
joymax[i]=joyv[i];
joymin[i]=joyv[i];
}
while (joyb[0] || joyb[1]) {
SwapInNext;
}
coutln "$$CL$$Move all about including throttle and press button.";
while (!(joyb[0] || joyb[1])) {
x=joyv[0]>>1; y=joyv[1]>>1;
if (x<3) x=3;
if (y<3) y=3;
GrLine3(base,x-3,y-3,0,x+3,y+3,0);
GrLine3(base,x+3,y-3,0,x-3,y+3,0);
x=joyv[2]>>1; y=joyv[3]>>1;
if (x<3) x=3;
if (y<3) y=3;
GrLine3(base,x-3,y-3,0,x+3,y+3,0);
GrLine3(base,x+3,y-3,0,x-3,y+3,0);
for (i=0;i<4;i++) {
if (joyv[i]>joymax[i]) joymax[i]=joyv[i];
if (joyv[i]<joymin[i]) joymin[i]=joyv[i];
}
SwapInNext;
}
GrClear;
joy_calibrated=TRUE;
//Save
for (i=0;i<4;i++) {
buf[i*3+0]=joymin[i];
buf[i*3+1]=joymax[i];
buf[i*3+2]=joyrest[i];
}
if (DriveIsWritable(':'))
WriteFile(JOY_CAL_FILE,buf,sizeof(I8)*3<<2);
ip_pointer_type=old_ip;
GrDel(base);
}
BoolU4 LoadJoystickCalibration()
{
U8 size,i;
I8 *ptr,*buf=ReadFile(JOY_CAL_FILE,&size);
joy_being_calibrated=TRUE;
if (!size)
JoyCalibration;
else {
ptr=buf;
for (i=0;i<4;i++) {
joymin[i]=ptr[0];
joymax[i]=ptr[1];
joyrest[i]=ptr[2];
ptr=ptr+3*sizeof(I8);
joy_calibrated=TRUE;
}
Free(buf);
}
joy_being_calibrated=FALSE;
PollJoystick;
}
+58
View File
@@ -0,0 +1,58 @@
void CollectAccntList()
{
LTDirEntry *tempm1;
SysAccntStruct *tempa;
U8 my_flags=0;
sys_accounts.next=&sys_accounts;
sys_accounts.last=&sys_accounts;
tempm1=FindFiles("/LT/ACCOUNTS/*",&my_flags);
while (tempm1) {
if ((tempm1->attr & LT_ATTR_DIR) && tempm1->name[0]!='.') {
tempa=MAlloc(sizeof(SysAccntStruct));
StrCpy(tempa->name,tempm1->name);
tempa->flags=0;
InsQue(tempa,sys_accounts.last);
}
tempm1=tempm1->next;
}
DelLTDirList(tempm1);
}
public SysAccntStruct *FindSysAccnt(I1 *name)
{
SysAccntStruct *tempa;
tempa=sys_accounts.next;
while (tempa!=&sys_accounts) {
if (!StrCmp(tempa->name,name))
return tempa;
tempa=tempa->next;
}
return NULL;
}
public SysAccntStruct *PopUpGetSysAccnt()
{
Ltf *l=LtfNew;
SysAccntStruct *tempa;
LtfPutS(l,"Select Account.\r\nCursor down and press SPACE.\r\n");
tempa=sys_accounts.next;
while (tempa!=&sys_accounts) {
LtfPrintF(l,"$$CM +LX 2,3$$$$BT, \"%s\" %d$$",tempa->name,tempa);
tempa=tempa->next;
}
tempa=PopUpMenu(l);
LtfDel(l);
return tempa;
}
void LoadAdam3()
{
SysAccntStruct *tempa=Fs->account;
if (!Bts(&tempa->flags,SACTf_ADAM3_LOADED)) {
Adam("ExecuteFile(\"::/LT/ACCOUNTS/%s/ADAM3.CPZ\");;",
tempa->name);
}
}
+2240
View File
File diff suppressed because it is too large. Load diff
+72
View File
@@ -0,0 +1,72 @@
public double Abs(double i)
{
if (i<0)
return -i;
else
return i;
}
public double Sign(double i)
{
if (i<0)
return -1.0;
else if (!i)
return 0.0;
else
return 1.0;
}
public double Sqr(double d)
{
return d*d;
}
public void R2P(double *mag,double *arg,double x,double y)
{ //Rect to polar
*arg=Arg(x,y);
*mag=Sqrt(x*x+y*y);
}
public void P2R(double *x,double *y,double mag,double arg)
{ //Polar to Rect
*x=mag*Cos(arg);
*y=mag*Sin(arg);
}
public double Unwrap(double theta,double base=-pi)
{
double result=theta%pi2;
if (result<base) result+=pi2;
if (result>base+pi2) result-=pi2;
return result;
}
public I8 AbsI8(I8 i)
{
if (i<0)
return -i;
else
return i;
}
public I8 SignI8(I8 i)
{
if (i<0)
return -1;
else if (!i)
return 0;
else
return 1;
}
public I8 SqrI8(I8 i)
{
return MulI8(i,i);
}
public I8 DistI8(I8 x1,I8 y1,I8 x2,I8 y2)
{
I8 dx=x1-x2,dy=y1-y2;
return MulI8(dx,dx)+MulI8(dy,dy);
}
+189
View File
@@ -0,0 +1,189 @@
I8 mxx=grwidth>>1,
myy=grheight>>1,
mzz=0;
BoolU4 mouse_buttons[5];
U8 last_mouse_jiffy=0;
BoolU4 mouse_installed=FALSE;
BoolU4 mouse_has_wheel=FALSE;
BoolU4 mouse_has_ext_buttons=FALSE;
BoolU4 mouse_evt=FALSE;
BoolU4 mouse_irqs_working=FALSE;
U8 mouse_evt_time;
void MouseGetDeviceType()
{
U1 b;
KbdMouseCmdAck(0xF2);
b=KbdCmdRead;
if (b==3)
mouse_has_wheel=TRUE;
else if (b==4)
mouse_has_ext_buttons=TRUE;
}
void MouseReset()
{
KbdCmdFlush;
KbdCmdSend(KEYB_CTRL,0xA8); //Enable Mouse
KbdCmdFlush;
KbdCmdSend(KEYB_CTRL,0xA9); //check for mouse
KbdCmdFlush;
KbdMouseCmdAck(0xFF); //Reset
KbdCmdRead;
KbdCmdRead;
KbdMouseCmdAck(0xFF); //Reset
KbdCmdRead;
KbdCmdRead;
KbdMouseCmdAck(0xF3);
KbdMouseCmdAck(200);
KbdMouseCmdAck(0xF3); // enable Mouse
KbdMouseCmdAck(100); // Set Rate
KbdMouseCmdAck(0xF3);
KbdMouseCmdAck(80); //Resolution
MouseGetDeviceType; // enable Mouse
KbdMouseCmdAck(0xF3);
KbdMouseCmdAck(10);
MouseGetDeviceType; // enable Mouse
KbdMouseCmdAck(0xE8); //Resolution
KbdMouseCmdAck(0x03);
KbdMouseCmdAck(0xE6);
KbdMouseCmdAck(0xF3); // Set Rate
//if your mouse doesn't work, try this
// KbdMouseCmdAck(40);
KbdMouseCmdAck(100);
KbdMouseCmdAck(0xF4); // enable Mouse
}
void MouseHandler()
{
I8 i,j,dx,dy,dz,
old_mxx=mxx,old_myy=myy,old_mzz=mzz;
BoolU4 evt=FALSE,old_buttons[5];
U1 mouse_buf[4];
U8 evt_time=BootTime;
try {
for (i=0;i<5;i++)
old_buttons[i]=mouse_buttons[i];
for (i=0;i<3;i++) {
j=KbdCmdRead;
if (j<0)
throw;
else
mouse_buf[i]=j;
}
if (mouse_has_wheel || mouse_has_ext_buttons) {
j=KbdCmdRead;
if (j<0)
throw;
else
mouse_buf[3]=j;
} else
mouse_buf[3]=0;
Sti;
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
dx=mouse_buf[1];
if (mouse_buf[0] & 0x20)
dy=256-mouse_buf[2];
else
dy=-mouse_buf[2];
if (mouse_buf[3] & 0x08)
dz=(mouse_buf[3]&7)-8;
else
dz=mouse_buf[3]&7;
mxx+=dx;
myy+=dy;
mzz+=dz;
if (mxx < 0) mxx=0;
if (mxx>=grwidth) mxx=grwidth-1;
if (myy < 0) myy=0;
if (myy>=grheight) myy=grheight-1;
} catch {
Fs->catch_except=TRUE;
KbdCmdFlush;
}
for (i=0;i<5;i++)
if (old_buttons[i]!=mouse_buttons[i])
evt=TRUE;
if (old_mxx!=mxx || old_myy!=myy || old_mzz!=mzz)
evt=TRUE;
if (evt) {
mouse_evt_time=evt_time;
last_mouse_jiffy=jiffies;
mouse_evt=TRUE;
}
}
void MouseIrqHandler()
{
mouse_irqs_working=TRUE;
MouseHandler;
}
void PollMouse()
{ //I can't get IRQ's working on some computers
U8 old_flags=GetFlags;
if (mouse_irqs_working) return;
// Cli;
if (!Bt(&sys_irq_flags,1)) {//not in keybd IRQ
if (InP(KEYB_CTRL) & 1) {
KbdCmdSend(KEYB_CTRL,0x60);
KbdCmdSend(KEYB_PORT,0x51); //disable kbd
MouseHandler;
KbdCmdSend(KEYB_CTRL,0x60);
KbdCmdSend(KEYB_PORT,0x41); //enable kbd
}
}
SetFlags(old_flags);
}
BoolU4 InstallMouseDriver()
{
BoolU4 result;
I8 i;
// U8 old_flags=GetFlags;
// Cli;
ext[EXT_IRQ0C]=NULL;
mouse_evt=FALSE;
for(i=0;i<5;i++)
mouse_buttons[i]=0;
mouse_has_wheel=FALSE;
mouse_has_ext_buttons=FALSE;
try {
MouseReset;
result=TRUE;
mouse_evt=TRUE;
ext[EXT_IRQ0C]=&MouseIrqHandler;
} catch {
Fs->catch_except=TRUE;
result=FALSE;
}
mouse_installed=result;
// SetFlags(old_flags);
return result;
}
Spawn(&InstallMouseDriver);
+82
View File
@@ -0,0 +1,82 @@
I1 *cur_song=NULL;
TssStruct *cur_song_tss=NULL;
U8 music_octive;
double music_note_len;
U1 music_note_map[7]={0,2,3,5,7,8,10};
public double music_tempo,music_stacatto_factor=1.0;
I1 *MusicSetOctive(I1 *st)
{
I1 ch=*st++;
while (ch>='0' && ch<='9') {
music_octive=ch-'0';
ch=*st++;
}
return --st;
}
I1 *MusicSetNoteLen(I1 *st)
{
BoolU4 cont=TRUE;
do {
switch (*st++) {
case 'w': music_note_len=4.0; break;
case 'h': music_note_len=2.0; break;
case 'q': music_note_len=1.0; break;
case 'e': music_note_len=0.5; break;
case 's': music_note_len=0.25; break;
case 't': music_note_len=2.0*music_note_len/3.0; break;
case '.': music_note_len=1.5*music_note_len; break;
default:
st--;
cont=FALSE;
}
} while (cont);
return st;
}
public void Play(I1 *st,I1 *words=NULL)
{
I1 *word;
U8 note,i=0;
double f;
while (*st) {
st=MusicSetOctive(st);
st=MusicSetNoteLen(st);
st=MusicSetOctive(st);
if (!*st) break;
note=*st++-'A';
if (note<7) {
note=music_note_map[note];
if (*st=='b') {
note--;
st++;
} else if (*st=='#') {
note++;
st++;
}
f=2.0`(6+music_octive+(note-3)/12.0);
} else
f=0;
if (words) {
if (word=PointAtListEntry(i++,words))
if (StrCmp(word," "))
PutS(word);
}
Sound(f);
Sleep(1000*music_stacatto_factor*music_note_len/music_tempo);
Sound(0);
Sleep(1000*(1.0-music_stacatto_factor)*music_note_len/music_tempo);
}
}
void ResetMusicSettings()
{
music_stacatto_factor=1.0;
music_tempo=2.5;
music_octive=3;
music_note_len=1.0;
}
ResetMusicSettings;
+171
View File
@@ -0,0 +1,171 @@
//This is taken from the book, $UL,1$Numeric Recipies in C$UL,0$
Ode *OdeNew(U8 n)
{
Ode *o=MAllocZ(sizeof(Ode));
o->n=n;
o->state=MAllocZ(n*sizeof(double));
o->base_t=ReadSysTimer*1.0/SYS_TIMER_FREQ;
o->h=1.0e-6;
o->DstateDt=MAllocZ(n*sizeof(double));
o->state_scale=MAllocZ(n*sizeof(double));
o->initial_state=MAllocZ(n*sizeof(double));
o->tolerance_start=1.0e-6;
o->temp0=MAllocZ(n*sizeof(double));
o->temp1=MAllocZ(n*sizeof(double));
o->temp2=MAllocZ(n*sizeof(double));
o->temp3=MAllocZ(n*sizeof(double));
o->temp4=MAllocZ(n*sizeof(double));
o->temp5=MAllocZ(n*sizeof(double));
o->temp6=MAllocZ(n*sizeof(double));
o->temp7=MAllocZ(n*sizeof(double));
return o;
}
void OdeDel(Ode *o)
{
Free(o->state);
Free(o->DstateDt);
Free(o->state_scale);
Free(o->initial_state);
Free(o->temp0);
Free(o->temp1);
Free(o->temp2);
Free(o->temp3);
Free(o->temp4);
Free(o->temp5);
Free(o->temp6);
Free(o->temp7);
Free(o);
}
void OdeOneStep(Ode *o)
{
I8 i;
o->derivative(o,o->t+o->base_t,o->state,o->DstateDt);
for (i=0;i<o->n;i++)
o->state[i]+=o->h*o->DstateDt[i];
o->t+=o->h;
}
void OdeRK4OneStep(Ode *o)
{
I8 i,n=o->n;
double xh,hh,h6;
double *dym,*dyt,*yt,*DstateDt;
dym =o->temp0;
dyt =o->temp1;
yt =o->temp2;
DstateDt=o->temp3;
hh =0.5*o->h;
h6 =o->h / 6.0;
xh =o->t +o->base_t+ hh;
o->derivative(o,o->t+o->base_t,o->state,o->DstateDt);
for (i=0;i<n;i++)
yt[i]=o->state[i]+hh*DstateDt[i];
o->derivative(o,xh,yt,dyt);
for (i=0;i<n;i++)
yt[i]=o->state[i]+hh*dyt[i];
o->derivative(o,xh,yt,dym);
for (i=0;i<n;i++) {
yt[i]=o->state[i]+o->h*dym[i];
dym[i]+=dyt[i];
}
o->t+=o->h;
o->derivative(o,o->t+o->base_t,yt,dyt);
for (i=0;i<n;i++)
o->state[i]+=h6*(DstateDt[i]+dyt[i]+2.0*dym[i]);
}
double ODEa2=0.2, ODEa3=0.3, ODEa4=0.6, ODEa5=1.0, ODEa6=0.875, ODEb21=0.2,
ODEb31=3.0/40.0, ODEb32=9.0/40.0, ODEb41=0.3, ODEb42=-0.9, ODEb43=1.2,
ODEb51=-11.0/54.0, ODEb52=2.5, ODEb53=-70.0/27.0, ODEb54=35.0/27.0,
ODEb61=1631.0/55296.0, ODEb62=175.0/512.0, ODEb63=575.0/13824.0,
ODEb64=44275.0/110592.0, ODEb65=253.0/4096.0, ODEc1=37.0/378.0,
ODEc3=250.0/621.0, ODEc4=125.0/594.0, ODEc6=512.0/1771.0,
ODEdc1=37.0/378.0 -2825.0/27648.0,
ODEdc3=250.0/621.0-18575.0/48384.0,
ODEdc4=125.0/594.0-13525.0/55296.0,
ODEdc5=-277.0/14336.0,
ODEdc6=512.0/1771.0-0.25;
void OdeCashKarp(Ode *o)
{
I8 i,n=o->n;
double h=o->h,*state=o->state,*DstateDt=o->DstateDt,*ak2,*ak3,*ak4,*ak5,*ak6,*tempstate,*stateerr,*outstate;
ak2=o->temp0;
ak3=o->temp1;
ak4=o->temp2;
ak5=o->temp3;
ak6=o->temp4;
tempstate=o->temp5;
outstate=o->temp6;
stateerr=o->temp7;
for (i=0;i<n;i++)
tempstate[i]=state[i]+ODEb21*h*DstateDt[i];
o->derivative(o,o->t+o->base_t+ODEa2*h,tempstate,ak2);
for (i=0;i<n;i++)
tempstate[i]=state[i]+h*(ODEb31*DstateDt[i]+ODEb32*ak2[i]);
o->derivative(o,o->t+o->base_t+ODEa3*h,tempstate,ak3);
for (i=0;i<n;i++)
tempstate[i]=state[i]+h*(ODEb41*DstateDt[i]+ODEb42*ak2[i]+ODEb43*ak3[i]);
o->derivative(o,o->t+o->base_t+ODEa4*h,tempstate,ak4);
for (i=0;i<n;i++)
tempstate[i]=state[i]+h*(ODEb51*DstateDt[i]+ODEb52*ak2[i]+ODEb53*ak3[i]+ODEb54*ak4[i]);
o->derivative(o,o->t+o->base_t+ODEa5*h,tempstate,ak5);
for (i=0;i<n;i++)
tempstate[i]=state[i]+h*(ODEb61*DstateDt[i]+ODEb62*ak2[i]+ODEb63*ak3[i]+ODEb64*ak4[i]+ODEb65*ak5[i]);
o->derivative(o,o->t+o->base_t+ODEa6*h,tempstate,ak6);
for (i=0;i<n;i++)
outstate[i]=state[i]+h*(ODEc1*DstateDt[i]+ODEc3*ak3[i]+ODEc4*ak4[i]+ODEc6*ak6[i]);
for (i=0;i<n;i++)
stateerr[i]=h*(ODEdc1*DstateDt[i]+ODEdc3*ak3[i]+ODEdc4*ak4[i]+ODEdc5*ak5[i]+ODEdc6*ak6[i]);
}
#define SAFETY (0.9)
#define PGROW (-0.2)
#define PSHRNK (-0.25)
#define ERRCON (1.89e-4)
void OdeRK5OneStep(Ode *o)
{
I8 i;
double errmax,temp;
double *tempstate=o->temp6,*stateerr=o->temp7;
while (TRUE) {
OdeCashKarp(o);
errmax=0.0;
for (i=0;i<o->n;i++) {
temp=Abs(stateerr[i]/o->state_scale[i]);
if (temp>errmax)
errmax=temp;
}
errmax/=o->tolerance;
if (errmax>1.0 && o->h>1.0e-64) {
temp=o->h*SAFETY*errmax`PSHRNK;
if (temp<0.1*o->h)
o->h*=0.1;
else
o->h=temp;
} else {
o->t+=o->h;
if (errmax>ERRCON)
o->h*=SAFETY*errmax`PGROW;
else
o->h*=5.0;
if (o->h>1.0e32)
o->h=1.0e32;
MemCpy(o->state,tempstate,sizeof(double)*o->n);
break;
}
}
}
BIN
View File
Binary file not shown.
+442
View File
@@ -0,0 +1,442 @@
public void LtfDm(U1 *buf,U8 cnt=0x80)
{
LtfEntry *ll;
BoolU4 old_preempt=Preempt(OFF);
Ltf *l=Fs->cur_ltf;
ll=LtfPrintF(l,"$$HX -Z %d 16$$",cnt);
ll->data=buf;
l->cur_entry=ll->next;
LtfRecalc(l);
Preempt(old_preempt);
}
public void LtfD(U1 *buf,U8 cnt=0x80)
{
LtfEntry *ll;
BoolU4 old_preempt=Preempt(OFF);
Ltf *l=Fs->cur_ltf;
ll=LtfPrintF(l,"$$HX %d 16$$",cnt);
ll->data=buf;
l->cur_entry=ll->next;
LtfRecalc(l);
Preempt(old_preempt);
}
public U1 *PatchBlk(U8 blk,BoolU4 write=FALSE)
{
U1 *buf=MAlloc(BLK_SIZE);
RBlks(Fs->cur_partition,buf,blk,1,TRUE);
LtfD(buf,BLK_SIZE);
if (write) {
coutln "Edit and press ESC to write or ^Q";
if (View) {
coutln "Write";
WBlks(Fs->cur_partition,buf,blk,1,TRUE);
}
}
return buf;
}
public U1 *Patch(U8 c,U8 cnt=0,BoolU4 write=FALSE)
{
U1 *buf=MAlloc(BLK_SIZE*Fs->cur_partition->spc);
if (cnt)
c=NextClusterNum(Fs->cur_partition,c,cnt,TRUE);
RClusters(Fs->cur_partition,buf,c,1,TRUE);
coutln "Cluster:",c;
LtfD(buf,BLK_SIZE*Fs->cur_partition->spc);
if (write) {
coutln "Edit and press ESC to write or ^Q";
if (View) {
coutln "Write";
WClusters(Fs->cur_partition,buf,c,1,TRUE);
}
}
return buf;
}
public U8 UnusedSysMem()
{
MemBlk *tempm;
U8 i,result=0,old_flags=GetFlags;
Cli;
tempm=mem_free_list;
while (tempm) {
result=result+tempm->pages;
tempm=tempm->next;
}
for (i=0;i<FREE_PAGE_HASH_SIZE;i++) {
tempm=free_page_hash[i];
while (tempm) {
result+=tempm->pages;
tempm=tempm->next;
}
}
for (i=0;i<32;i++) {
tempm=free_page_hash2[i];
while (tempm) {
result+=tempm->pages;
tempm=tempm->next;
}
}
SetFlags(old_flags);
return result*PAGE_SIZE;
}
public U8 TaskAllocatedMem(TssStruct *tss=NULL)
{
MemBlk *m;
U8 result=0,old_flags=GetFlags;
if (!tss) tss=Fs;
m=tss->next_mem_blk;
Cli;
while (m!=&tss->next_mem_blk) {
result+=m->pages*PAGE_SIZE-sizeof(MemBlk);
m=m->next;
}
SetFlags(old_flags);
return result;
}
public U8 TaskUnusedAllocatedMem(TssStruct *tss=NULL)
{
U8 result=0,i,old_flags=GetFlags;
UnusedAllocatedMem *u;
if (!tss) tss=Fs;
Cli;
for (i=0;i<HEAP_HASH_SIZE>>2;i++) {
u=tss->heap_hash[i];
while (u) {
result+=u->size;
u=u->next;
}
}
u=tss->malloc_free_list;
while (u) {
result+=u->size;
u=u->next;
}
SetFlags(old_flags);
return result;
}
I8 CompareUamPtrs(UnusedAllocatedMem **e1,
UnusedAllocatedMem **e2)
{
return *e1-*e2;
}
I8 CompareUamSize(UnusedAllocatedMem **e1,
UnusedAllocatedMem **e2)
{
return (*e2)->size-(*e1)->size;
}
public void HeapRep(TssStruct *tss=NULL)
{
I8 i,cnt;
UnusedAllocatedMem *u;
U8 old_flags=GetFlags;
if (!tss) tss=Fs;
Cli;
for (i=0;i<HEAP_HASH_SIZE>>2;i++) {
cnt=0;
u=tss->heap_hash[i];
while (u) {
cnt+=u->size;
u=u->next;
}
if (cnt)
PrintF("%03X:%08X\r\n",i<<2,cnt);
}
u=tss->malloc_free_list;
while (u) {
PrintF("%08X\r\n",u->size);
u=u->next;
}
SetFlags(old_flags);
}
public BoolU4 IsInHeap(U1 *a,TssStruct *tss=NULL)
{
MemBlk *m;
U8 old_flags=GetFlags;
if (!tss) tss=Fs;
m=tss->next_mem_blk;
Cli;
while (m!=&tss->next_mem_blk) {
if (a>=m && a<m+m->pages*PAGE_SIZE) {
SetFlags(old_flags);
return TRUE;
}
m=m->next;
}
SetFlags(old_flags);
return FALSE;
}
public BoolU4 HeapChk(TssStruct *tss=NULL)
//This just detects one type of error--
// when a freed value is not valid.
{
I8 i;
UnusedAllocatedMem *u;
BoolU4 result=TRUE;
U8 old_flags=GetFlags;
if (!tss) tss=Fs;
Cli;
for (i=0;i<HEAP_HASH_SIZE>>2;i++) {
u=tss->heap_hash[i];
while (u) {
if (!IsInHeap(u,tss))
result=FALSE;
u=u->next;
}
}
u=tss->malloc_free_list;
while (u) {
if (!IsInHeap(u,tss))
result=FALSE;
u=u->next;
}
SetFlags(old_flags);
return result;
}
//TODO:Crashes
///More of a heap check at the moment
void CollectFreedAllocatedMem(TssStruct *tss=NULL)
{
I8 i,cnt;
//I8 j;
UnusedAllocatedMem *u,**sort_buf;
U8 old_flags=GetFlags;
// U4 *dd;
if (!tss) tss=Fs;
Cli;
cnt=0;
for (i=0;i<HEAP_HASH_SIZE>>2;i++) {
u=tss->heap_hash[i];
while (u) {
cnt++;
u=u->next;
}
}
u=tss->malloc_free_list;
while (u) {
cnt++;
u=u->next;
}
SetFlags(old_flags);
//We might disturb the Free list and irq's might Free some
sort_buf=MAlloc(((cnt+512)&-0x100)*PTR_SIZE);
Cli;
cnt=0;
for (i=0;i<HEAP_HASH_SIZE>>2;i++) {
u=tss->heap_hash[i];
while (u) {
sort_buf[cnt++]=u;
u=u->next;
}
tss->heap_hash[i]=NULL;
}
u=tss->malloc_free_list;
while (u) {
sort_buf[cnt++]=u;
u=u->next;
}
tss->malloc_free_list=NULL;
for (i=0;i<FREE_PAGE_HASH_SIZE;i++)
free_page_hash[i]=NULL;
for (i=0;i<32;i++)
free_page_hash2[i]=NULL;
SetFlags(old_flags);
QSort(sort_buf,cnt,PTR_SIZE,&CompareUamPtrs);
for (i=0;i<cnt;i++) {
if (sort_buf[i]+sort_buf[i]->size>sort_buf[i+1])
cout "****";
coutln sort_buf[i]," ",sort_buf[i]->size;
}
/*
j=0;
for (i=0;i<cnt;i++) {
if (sort_buf[i]==sort_buf[j]+sort_buf[j]->size &&
sort_buf[j]->size+sort_buf[i]->size<HEAP_HASH_SIZE)
sort_buf[j]->size=sort_buf[j]->size+
sort_buf[i]->size;
else
sort_buf[++j]=sort_buf[i];
}
if (cnt) {
j++;
QSort(sort_buf,j,PTR_SIZE,&CompareUamSize);
for (i=0;i<j;i++) {
sort_buf[i]->next=sort_buf[i]->size;
Free(sort_buf[i]+4,tss);
}
}
*/
Free(sort_buf);
}
void TaskRepTask(TssStruct *tss,I8 indent)
{
TssStruct *tss1;
I1 *st,*desc=MSPrintF("%Q",tss->task_descriptor);
st=MSPrintF("$$MA+A,\"%08X\",\"Kill(0x%X);\r\",$$",tss,tss,tss);
PrintF("%*s%s $$TX+SCX,\"%Q...\",16$$ %08X %04X %04X %02X\r\n",
indent,"",st,desc,
TaskAllocatedMem(tss),
tss->task_flags,tss->crt_flags,
ExceptDepth(tss));
Free(st);
Free(desc);
tss1=tss->next_child_tss;
while (tss1!=tss+&tss->next_child_tss-&tss->next_sibling_tss) {
TaskRepTask(tss1,indent+2);
tss1=tss1->next_sibling_tss;
}
}
public void TaskRep()
{
U8 old_flags=GetFlags;
Cli;
TaskRepTask(adam_tss,0);
SetFlags(old_flags);
}
SysBpt *FindBpt(TssStruct *tss,U1 *a,U8 flags=-1,BoolU4 remove=FALSE)
{//Removes
SysBpt *result=NULL;
U8 old_flags=GetFlags;
SysBpt *tempb,*tempb1,*tempb2;
Cli;
tempb1=&tss->bpt_list;
tempb=tss->bpt_list;
while (tempb) {
tempb2=tempb->next;
if (tempb->address==a && tempb->flags & flags) {
result=tempb;
if (remove)
tempb1->next=tempb2;
else
tempb1=&tempb->next;
} else
tempb1=&tempb->next;
tempb=tempb2;
}
SetFlags(old_flags);
return result;
}
public BoolU4 SBpt(TssStruct *tss,U1 *a,U8 flags=SBPTF_BPT) //set Bpt
{
U8 old_flags=GetFlags;
BoolU4 result=TRUE;
SysBpt *tempb;
Cli;
if (!(tempb=FindBpt(tss,a,flags,FALSE))) {
tempb=MAlloc(sizeof(SysBpt),tss);
tempb->address=a;
tempb->b=*a;
tempb->flags=flags;
result=FALSE;
tempb->next=tss->bpt_list;
tss->bpt_list=tempb;
if (tss==Fs)
*a=0xCC;
}
SetFlags(old_flags);
return result;
}
public BoolU4 RBpt(TssStruct *tss,U1 *a,U8 flags=-1)
{ //remove one Bpt
U8 old_flags=GetFlags;
BoolU4 result=FALSE;
SysBpt *tempb;
Cli;
if (tempb=FindBpt(tss,a,flags,TRUE)) {
result=TRUE;
Free(tempb,tss);
}
SetFlags(old_flags);
return result;
}
BoolU4 DBpt(TssStruct *tss,U1 *a,U8 flags=-1) //disable one Bpt
{ //used for continuing after a bpt
U8 old_flags=GetFlags;
BoolU4 result=FALSE;
SysBpt *tempb;
Cli;
if (tempb=FindBpt(tss,a,flags,FALSE)) {
Bts(&tempb->flags,SBPTf_DISABLE);
result=TRUE;
}
SetFlags(old_flags);
return result;
}
public void CBpt(TssStruct *tss,U8 flags=-1) //clear Bpts
{
U1 *a;
U8 old_flags=GetFlags;
SysBpt *tempb,*tempb1,*tempb2;
Cli;
tempb=tss->bpt_list;
tempb1=&tss->bpt_list;
while (tempb) {
tempb2=tempb->next;
if (tempb->flags & flags) {
a=tempb->address;
if (tss==Fs)
*a=tempb->b;
Free(tempb,tss);
tempb1->next=tempb2;
} else
tempb1=&tempb->next;
tempb=tempb2;
}
SetFlags(old_flags);
}
public BoolU4 IsTextFile(I1 *filename)
{
return WildFileNameList(TEXT_FILE_MASK,filename);
}
public BoolU4 IsSourceFile(I1 *filename)
{
return WildFileNameList(SOURCE_FILE_MASK,filename);
}
public BoolU4 IsCFile(I1 *filename)
{
return WildFileNameList(C_FILE_MASK,filename);
}
public BoolU4 IsAsmFile(I1 *filename)
{
return WildFileNameList(ASM_FILE_MASK,filename);
}
+1043
View File
File diff suppressed because it is too large. Load diff
+769
View File
@@ -0,0 +1,769 @@
public class WsHashEntry
{
WsHashEntry *next;
I1 *word;
U4 type,use_cnt;
I1 *source_link;
DbgInfo *debug;
I4 num;
U4 hits;
U2 last_vowel,last_consonant;
I1 *glossary;
};
class WsSubstruct
{
I4 hits,
repeats;
};
#define WS_SUBSTRUCTS_PER_STRUCT 8
class WsStruct
{
WsStruct *next,*last;
I4 substructs, //-1 means WsMatrixSide
entries;
WsSubstruct subs[WS_SUBSTRUCTS_PER_STRUCT];
};
class WsMatrixSide
{
WsStruct *next,*last;
I4 const_minus_one, //-1 used to header in queue
row_hits,col_hits;
};
#define WS_MAX_MATRIX_WORDS 0x8000
public class WsMatrix
{
I4 n;
WsMatrixSide side[WS_MAX_MATRIX_WORDS];
};
public I4 ws_num_words,ws_num_matrix_words;
SysHashTable *ws_hash_table=NewHashTable(4096);
public I1 *ws_cur_word;
public BoolU4 ws_disable=TRUE;
#define NUM_WS_MATRICES 1
public WsMatrix ws_matrices[NUM_WS_MATRICES];
public WsHashEntry **ws_sorted_words;
TssStruct *ws_task=NULL;
class WsFilemaskEntry
{
WsFilemaskEntry *next;
I1 *mask;
LTDirEntry *flist;
};
WsFilemaskEntry *ws_filemask_list=NULL,
*ws_gloss_filemask_list=NULL;
void WsPutMatrix(WsMatrix *m)
{
I8 i,j;
WsMatrixSide *ms;
WsStruct *tempw;
coutln "n:",m->n;
for (i=0;i<ws_num_matrix_words;i++) {
ms=&m->side[i];
coutln "col:",i," rhits:",ms->row_hits," chits:",ms->col_hits;
tempw=ms->next;
while (tempw!=ms) {
coutln " substructs:",tempw->substructs,
" entries:",tempw->entries;
for (j=0;j<tempw->substructs;j++) {
PrintF("(%04X %04X) ",
tempw->subs[j].hits,
tempw->subs[j].repeats);
}
CrLf;
tempw=tempw->next;
}
}
View;
}
WsHashEntry *WsAddHash(I1 *w)
{
WsHashEntry **tempw1,*tempw=FindHashEntry(w,ws_hash_table,HTT_WORD);
if (tempw) {
tempw->hits++;
return tempw;
}
tempw1=FindHashBucket(w,ws_hash_table);
tempw=AMAllocZ(sizeof(WsHashEntry));
tempw->word=ANewString(w);
tempw->type=HTT_WORD;
tempw->use_cnt=1;
tempw->hits=1;
tempw->num=-1;
tempw->next=*tempw1;
*tempw1=tempw;
ws_num_words++;
return tempw;
}
void WsInitSides(WsMatrix *m)
{
I8 i;
WsStruct *tempa;
m->n=0;
for (i=0;i<WS_MAX_MATRIX_WORDS;i++) {
m->side[i].next=&m->side[i].next;
m->side[i].last=&m->side[i].next;
m->side[i].const_minus_one=-1;
m->side[i].row_hits=0;
m->side[i].col_hits=0;
tempa=AMAlloc(sizeof(WsStruct));
tempa->subs[0].hits=0;
tempa->subs[0].repeats=ws_num_matrix_words;
tempa->entries=ws_num_matrix_words;
tempa->substructs=1;
InsQue(tempa,m->side[i].last);
}
}
WsStruct *WsFindStruct(WsMatrix *m,I8 col,I8 row,
I4 *row_base,I4 *substruct)
{
WsStruct *tempa;
if (row>=ws_num_matrix_words ||
col>=ws_num_matrix_words)
return NULL;
if (row<ws_num_matrix_words>>1) {
tempa=m->side[col].next;
*row_base=0;
while (row>=tempa->entries) {
row-=tempa->entries;
*row_base+=tempa->entries;
tempa=tempa->next;
}
for (*substruct=0;row>=tempa->subs[*substruct].repeats;*substruct=*substruct+1) {
row-=tempa->subs[*substruct].repeats;
*row_base+=tempa->subs[*substruct].repeats;
}
} else {
row=ws_num_matrix_words-row;
tempa=m->side[col].last;
*row_base=ws_num_matrix_words;
while (row>tempa->entries) {
row-=tempa->entries;
*row_base-=tempa->entries;
tempa=tempa->last;
}
for (*substruct=tempa->substructs-1;row>tempa->subs[*substruct].repeats;
*substruct=*substruct-1) {
row-=tempa->subs[*substruct].repeats;
*row_base-=tempa->subs[*substruct].repeats;
}
*row_base-=tempa->subs[*substruct].repeats;
}
return tempa;
}
public I8 WsGetHits(WsMatrix *m,I8 col,I8 row)
{
I8 row_base,substruct;
if (row>=ws_num_matrix_words ||
col>=ws_num_matrix_words)
return 0;
WsStruct *tempa=WsFindStruct(m,col,row,
&row_base,&substruct);
return tempa->subs[substruct].hits;
}
WsSubstruct *WsNext(WsSubstruct *s,WsStruct **parent)
{
I8 i=(s-&(*parent)->subs)/sizeof(WsSubstruct)+1;
if (i>=(*parent)->substructs) {
i=0;
*parent=(*parent)->next;
if ((*parent)->substructs==-1)
return NULL;
}
return (*parent)->subs+i*sizeof(WsSubstruct);
}
WsSubstruct *WsLast(WsSubstruct *s,WsStruct **parent)
{
I8 i=(s-&(*parent)->subs)/sizeof(WsSubstruct)-1;
if (i<0) {
*parent=(*parent)->last;
if ((*parent)->substructs==-1)
return NULL;
i=(*parent)->substructs-1;
}
return (*parent)->subs+i*sizeof(WsSubstruct);
}
void WsRemove(WsSubstruct *s,WsStruct *parent)
{
I8 i=(s-&parent->subs)/sizeof(WsSubstruct);
if (i<0 || i>=WS_SUBSTRUCTS_PER_STRUCT || parent->substructs<1)
return;
if (parent->substructs==1) {
RemQue(parent);
AFree(parent);
} else {
parent->entries-=s->repeats;
parent->substructs--;
MemCpy(&parent->subs[i],&parent->subs[i+1],
(parent->substructs-i)*sizeof(WsSubstruct));
}
}
WsSubstruct *WsInsert(WsSubstruct *s,WsStruct **parent,WsSubstruct *last)
{
WsStruct *tempa,*p=*parent;
I8 j,k,i=(last-&p->subs)/sizeof(WsSubstruct)+1;
if (i>=WS_SUBSTRUCTS_PER_STRUCT) {
i=0;
p=p->next;
*parent=p;
if (p->substructs==-1) {
tempa=AMAlloc(sizeof(WsStruct));
InsQue(tempa,p->last);
p=tempa;
*parent=p;
tempa->entries=0;
tempa->substructs=0;
}
}
if (p->substructs==WS_SUBSTRUCTS_PER_STRUCT) {
tempa=p->next;
if (tempa->substructs==-1 || tempa->substructs==WS_SUBSTRUCTS_PER_STRUCT) {
tempa=AMAlloc(sizeof(WsStruct));
tempa->entries=0;
tempa->substructs=0;
InsQue(tempa,p);
k=0;
for (j=i;j<p->substructs;j++) {
MemCpy(&tempa->subs[k],&p->subs[j],sizeof(WsSubstruct));
tempa->entries+=tempa->subs[k++].repeats;
tempa->substructs++;
}
p->entries-=tempa->entries;
p->substructs-=tempa->substructs;
} else {
for (j=tempa->substructs-1;j>=0;j--)
MemCpy(&tempa->subs[j+1],&tempa->subs[j],sizeof(WsSubstruct));
MemCpy(&tempa->subs[0],
&p->subs[WS_SUBSTRUCTS_PER_STRUCT-1],
sizeof(WsSubstruct));
p->entries-=tempa->subs[0].repeats;
p->substructs--;
tempa->entries+=tempa->subs[0].repeats;
tempa->substructs++;
for (j=WS_SUBSTRUCTS_PER_STRUCT-2;j>=i;j--)
MemCpy(&p->subs[j+1],
&p->subs[j],sizeof(WsSubstruct));
}
} else {
for (j=p->substructs-1;j>=i;j--)
MemCpy(&p->subs[j+1],
&p->subs[j],sizeof(WsSubstruct));
}
p->entries+=s->repeats;
p->substructs++;
MemCpy(&p->subs[i],s,sizeof(WsSubstruct));
return &p->subs[i];
}
WsSubstruct *WsCondense(WsSubstruct *s,WsStruct **parent)
{
WsSubstruct *temps,*temps_l,*temps_n;
WsStruct *tempa_l,*tempa_n;
if ((*parent)->substructs==-1)
return NULL;
temps=s;
tempa_l=*parent;
temps_l=WsLast(temps,&tempa_l);
if (temps_l && temps_l->hits==temps->hits) {
temps_l->repeats+=temps->repeats;
tempa_l->entries+=temps->repeats;
WsRemove(temps,*parent);
*parent=tempa_l;
temps=temps_l;
}
tempa_n=*parent;
temps_n=WsNext(temps,&tempa_n);
if (temps_n && temps_n->hits==temps->hits) {
temps->repeats=temps->repeats+temps_n->repeats;
(*parent)->entries=(*parent)->entries+temps_n->repeats;
WsRemove(temps_n,tempa_n);
}
return temps;
}
I8 WsIncHits(WsMatrix *m,I8 col,I8 row)
{
I8 row_base,substruct,repeats;
WsSubstruct sn,*temps,*temps1,*temps_l;
WsStruct *tempa,*tempa1,*tempa_l;
if (row>=ws_num_matrix_words ||
col>=ws_num_matrix_words)
return 0;
tempa=WsFindStruct(m,col,row,&row_base,&substruct);
temps=&tempa->subs[substruct];
repeats=temps->repeats;
if (repeats==1) {
temps->hits++;
temps=WsCondense(temps,&tempa);
} else {
if (row==row_base) {
temps->repeats--;
tempa->entries--;
sn.hits=1;
sn.repeats=1;
tempa_l=tempa;
if (!(temps_l=WsLast(&tempa->subs[substruct],&tempa_l))) {
tempa_l=tempa->last; //header
temps_l=&tempa_l->subs[WS_SUBSTRUCTS_PER_STRUCT-1];
}
temps=WsInsert(&sn,&tempa_l,temps_l);
temps=WsCondense(temps,&tempa_l);
} else if (row==repeats-1+row_base) {
temps->repeats--;
tempa->entries--;
sn.hits=1;
sn.repeats=1;
temps=WsInsert(&sn,&tempa,temps);
temps=WsCondense(temps,&tempa);
} else {
tempa->entries-=repeats;
sn.hits=temps->hits+1;
sn.repeats=1;
tempa1=tempa;
temps1=temps;
temps=WsInsert(&sn,&tempa1,temps1);
temps1->repeats=row-row_base;
tempa->entries+=temps1->repeats;
sn.repeats=row_base+repeats-(row+1);
sn.hits=temps1->hits;
WsInsert(&sn,&tempa1,temps);
}
}
m->n++;
m->side[col].col_hits++;
m->side[row].row_hits++;
return temps->hits;
}
#define WS_FIFO_SIZE 2048
void WsAddSingleFile(LTDirEntry *tempd,BoolU4 compile)
{
I1 ch,ch1,*buf,*ptr,*ptr2;
WsHashEntry **f_ptr,**f_ptr2,
**fifo=MAllocZ(WS_FIFO_SIZE*sizeof(U4));
I8 i,j,fp=0,k=0;
buf=ReadTextFile(tempd->full_name);
ptr=buf;
while (ch=*ptr++) {
while (ch && !Bt(alpha_numeric_bitmap,ch))
ch=*ptr++;
if (!ch) break;
ptr--;
ptr2=ptr;
do ch=*ptr2++;
while (Bt(alpha_numeric_bitmap,ch));
ptr2--;
ch1=*ptr2;
*ptr2=0;
if (*ptr) {
if (!compile)
WsAddHash(ptr);
else {
f_ptr=fifo+fp<<2;
*f_ptr=FindHashEntry(ptr,ws_hash_table,HTT_WORD);
if ((*f_ptr)->num<0)
*f_ptr=NULL;
else {
for (i=0;i<NUM_WS_MATRICES;i++) {
for (j=0;j<1<<(i<<1);j++) {
f_ptr2=fifo+((fp-j-1)&(WS_FIFO_SIZE-1))<<2;
if (*f_ptr2)
WsIncHits(&ws_matrices[i],(*f_ptr2)->num,(*f_ptr)->num);
}
}
}
fp=(fp+1)&(WS_FIFO_SIZE-1);
}
ptr=ptr2+1;
}
if (!ch1) break;
*ptr2=ch1;
}
Free(fifo);
Free(buf);
}
void WsAddGlossFile(LTDirEntry *tempd)
{
LtfEntry *ll;
WsHashEntry *temph;
Ltf *l=LtfRead(tempd->full_name);
I1 *temp;
ll=l->dummy.next;
while (ll!=l) {
if (ll->btype==LTFT_ANCHOR) {
if (temph=FindHashEntry(ll->aux_string,
ws_hash_table,HTT_WORD)) {
temp=MSPrintF("FA:%s,%s",
tempd->full_name,ll->aux_string);
AFree(temph->glossary);
temph->glossary=ANewString(temp);
Free(temp);
}
}
ll=ll->next;
}
LtfDel(l);
}
I8 WsSort(WsHashEntry **e1,WsHashEntry **e2)
{
I8 r;
if (!(r=(*e2)->hits - (*e1)->hits))
r=StrCmp((*e1)->word,(*e2)->word);
return r;
}
void WsAddFileList(LTDirEntry *tempm1,BoolU4 compile,BoolU4 gloss)
{
while (tempm1) {
coutln tempm1->full_name;
if (tempm1->attr & LT_ATTR_DIR) {
if (tempm1->sub)
WsAddFileList(tempm1->sub,compile,gloss);
} else {
if (gloss)
WsAddGlossFile(tempm1);
else
WsAddSingleFile(tempm1,compile);
}
tempm1=tempm1->next;
}
}
I8 WsSkipCrap(I1 *src,I8 len)
{
I8 j;
j=len-1;
while (j>=0) {
if (Bt(alpha_numeric_bitmap,src[j]))
break;
else
j--;
}
return j+1;
}
I8 WsPriorWordInString(I1 *src,I1 *dst,I8 len,I8 buf_size)
{
I8 i,j=0,k;
BoolU4 cont=TRUE;
i=len-1;
while (i>=0 && cont) {
if (!Bt(alpha_numeric_bitmap,src[i]))
cont=FALSE;
else
i--;
}
if (i>=-1 && len>0)
for (k=i+1;k<len && j<buf_size-1;k++)
dst[j++]=src[k];
dst[j]=0;
return i+1;
}
BoolU4 WsPartialMatch(I1 *partial,I1 *complete)
{
I8 i,l=StrLen(partial);
for (i=0;i<l;i++)
if (partial[i]!=complete[i])
return FALSE;
return TRUE;
}
#define MAX_FILLINS 10
I8 ws_partial_len=0,fillin_matches[MAX_FILLINS+1];
I8 ws_num_fillins=0,fillin_scores[MAX_FILLINS+1],fillin_hits[MAX_FILLINS+1];
void WsFillin(I8 n)
{
I1 *s;
I8 len;
n--;
if (n>=0 && n<ws_num_fillins) {
s=ws_sorted_words[fillin_matches[n]]->word;
len=StrLen(s);
if (len>ws_partial_len)
Auto(s+ws_partial_len);
}
}
void WsMan(I8 n,TssStruct *parent=NULL)
{
I1 *buf;
WsHashEntry *tempw;
SysHashEntry *temph;
BoolU4 old_preempt=Preempt(OFF);
n--;
if (n>=0 && n<ws_num_fillins) {
if (tempw=ws_sorted_words[fillin_matches[n]]) {
buf=tempw->glossary;
if (temph=FindHashEntry(tempw->word,Fs->hash_table,HTT_ALL)) {
if (temph->source_link)
buf=temph->source_link;
}
if (buf) {
buf=MSPrintF("Edit(\"%s\");",buf);
Preempt(old_preempt);
PopUp(buf,parent);
Free(buf);
}
}
}
Preempt(old_preempt);
}
void WsAddFillin(I8 i,I8 j,I8 old_num_fillins)
{
BoolU4 cont;
I8 k;
if (ws_num_fillins<MAX_FILLINS || i>fillin_scores[ws_num_fillins-1] ||
i==fillin_scores[ws_num_fillins-1] && ws_sorted_words[j]->hits>fillin_hits[ws_num_fillins-1]) {
cont=TRUE;
for (k=ws_num_fillins-1;k>=old_num_fillins && cont;k--)
if (i<=fillin_scores[k] || i==fillin_scores[k] && ws_sorted_words[j]->hits<=fillin_hits[k]) {
cont=FALSE;
k++; //offset k--
} else {
fillin_scores[k+1]=fillin_scores[k];
fillin_matches[k+1]=fillin_matches[k];
fillin_hits[k+1]=fillin_hits[k];
}
if (ws_num_fillins<MAX_FILLINS)
ws_num_fillins++;
fillin_scores[k+1]=i;
fillin_hits[k+1]=ws_sorted_words[j]->hits;
fillin_matches[k+1]=j;
}
}
void WsPutChoices(Ltf *l,Ltf *aux,Ltf *focus_l,LtfEntry *ll)
{
I8 i,j,k,data_col;
I1 ch=0,*buf,*buf1,*src=NULL,*st;
WsHashEntry *w2;
U8 timeout_jiffies=jiffies+JIFFY_FREQ*20/1000;
SysHashEntry *temph;
TssStruct *tss;
src=LtfGetLine(focus_l,ll,&data_col);
i=StrLen(src);
buf=MAlloc(i+1);
buf1=MAlloc(i+1);
if (data_col==-1)
data_col=StrLen(i);
data_col=WsPriorWordInString(src,buf,data_col,256);
ws_partial_len=StrLen(buf);
data_col=WsSkipCrap(src,data_col);
data_col=WsPriorWordInString(src,buf1,data_col,256);
AFree(ws_cur_word);
ws_cur_word=ANewString(buf);
if (StrLen(buf1))
w2=FindHashEntry(buf1,ws_hash_table,HTT_WORD);
else
w2=NULL;
Free(src);
ws_num_fillins=0;
if (w2 && w2->num<ws_num_matrix_words)
for (j=0;j<ws_num_matrix_words && jiffies<timeout_jiffies;j++)
if (WsPartialMatch(buf,ws_sorted_words[j]->word)) {
i=WsGetHits(&ws_matrices[0],w2->num,ws_sorted_words[j]->num);
WsAddFillin(i,j,0);
}
k=ws_num_fillins;
for (j=0;j<ws_num_words && jiffies<timeout_jiffies;j++)
if (WsPartialMatch(buf,ws_sorted_words[j]->word))
WsAddFillin(0,j,k);
if (ws_num_fillins) {
LtfReset(l,TRUE);
l->flags|=LTFF_MIN_SIZE;
l->text_attribute=(LTBLUE<<4)+BLACK;
aux->text_attribute=(LTBLUE<<4)+BLACK;
Fs->text_attribute=l->text_attribute;
Fs->border_attribute=l->text_attribute;
LtfPrintF(l,"Word:%-20ts\r\n",ws_cur_word);
for (i=0;i<ws_num_fillins;i++) {
st=ws_sorted_words[fillin_matches[i]]->word;
if (ws_sorted_words[fillin_matches[i]]->glossary)
ch='#';
else
ch=CH_SPACE;
if (tss=sys_cur_focus_task) {
temph=FindHashEntry(st,tss->hash_table,HTT_ALL);
if (temph) {
if (temph->source_link)
ch='*';
}
}
LtfPrintF(l,"%cF%02d %-20ts\r\n",ch,i+1,st);
}
LtfRecalc(l);
Bts(&Fs->crt_flags,CRTf_SHOW);
WindowToTop(Fs);
}
Free(buf);
Free(buf1);
}
void WsTsk()
{
TssStruct *focus_tss;
U8 sc,ch;
Ltf *l;
LtfEntry *ll;
Preempt(OFF);
InitLocalTask;
UseConsoleLtf(NULL);
Fs->window_left=200;
Fs->window_bottom=30;
do {
Sleep(500);
if (!ws_disable) {
focus_tss=sys_cur_focus_task;
if (focus_tss) {
l=focus_tss->cur_ltf;
if (l && focus_tss!=Fs) {
LtfRecalc(l); //TODO: is this needed?
ll=l->cur_entry;
if (ll) {
if (ll==l) ll=ll->last;
while (ll->last!=l && (ll->btype==LTFT_CR ||
ll->btype==LTFT_SOFT_CR))
ll=ll->last;
while ((ll->last->btype)!=LTFT_CR && ll->last!=l)
ll=ll->last;
if (!ws_disable)
WsPutChoices(Fs->cur_ltf,Fs->aux_ltf,l,ll);
}
}
}
}
} while (!ScanChar(&sc,&ch));
ws_task=NULL;
}
void WsAdd(I1 *wild=TEXT_FILE_MASK,BoolU4 gloss)
{
WsFilemaskEntry *tempfm=AMAlloc(sizeof(WsFilemaskEntry));
if (gloss) {
tempfm->next=ws_gloss_filemask_list;
ws_gloss_filemask_list=tempfm;
} else {
tempfm->next=ws_filemask_list;
ws_filemask_list=tempfm;
}
tempfm->mask=ANewString(wild);
tempfm->flist=NULL;
}
void WsTraverseFilelist(BoolU4 compile,BoolU4 gloss)
{
WsFilemaskEntry *tempfm;
U8 my_flags=(1<<FUf_RECURSE);
if (gloss)
tempfm=ws_gloss_filemask_list;
else
tempfm=ws_filemask_list;
while (tempfm) {
if (!compile)
tempfm->flist=FindFiles(tempfm->mask,&my_flags);
WsAddFileList(tempfm->flist,compile,gloss);
tempfm=tempfm->next;
}
}
public void WsInit(I1 *mask)
{
I1 *buf,buf2[512];
I8 i,j=0;
WsHashEntry *tempw;
ws_disable=TRUE;
//TODO:free old wordstat data
ws_num_words=0;
ws_num_matrix_words=0;
MemSet(&ws_hash_table->body,0,sizeof(U4)*(ws_hash_table->mask+1));
ws_cur_word=NULL;
ws_filemask_list=NULL;
ws_gloss_filemask_list=NULL;
buf=NewString(mask);
do {
RemoveFirstSeg(buf,";",buf2);
if (*buf2) {
StrCat(buf2,"/" TEXT_FILE_MASK);
WsAdd(buf2,FALSE);
}
} while (*buf2);
Free(buf);
coutln "\r\n\r\nPass #1";
WsTraverseFilelist(FALSE,FALSE);
ws_sorted_words=AMAlloc(PTR_SIZE*ws_num_words);
for (i=0;i<=ws_hash_table->mask;i++) {
tempw=ws_hash_table->body[i];
while (tempw) {
ws_sorted_words[j++]=tempw;
tempw=tempw->next;
}
}
QSort(ws_sorted_words,ws_num_words,PTR_SIZE,&WsSort);
for (i=0;i<ws_num_words;i++)
ws_sorted_words[i]->num=i;
if (ws_num_words<=WS_MAX_MATRIX_WORDS)
ws_num_matrix_words=ws_num_words;
else
ws_num_matrix_words=WS_MAX_MATRIX_WORDS;
for (i=0;i<NUM_WS_MATRICES;i++)
WsInitSides(&ws_matrices[i]);
coutln "\r\n\r\nPass #2";
WsTraverseFilelist(TRUE,FALSE);
buf=NewString(mask);
do {
RemoveFirstSeg(buf,";",buf2);
if (*buf2) {
StrCat(buf2,"/*.GL?");
WsAdd(buf2,TRUE);
}
} while (*buf2);
Free(buf);
coutln "\r\n\r\nGlossary Pass";
WsTraverseFilelist(FALSE,TRUE);
ws_disable=FALSE;
}