Initial (manual) import
This commit is contained in:
1 parent
f39611c506
commit
895fe109de
661 files changed
+245862
No files matched your search
@@ -0,0 +1,11 @@
|
||||
$FG,6$JOB
|
||||
$FG,1$BANK
|
||||
$FG,4$CREDIT
|
||||
$FG,2$CASH
|
||||
$FG,0$RENT
|
||||
CAR
|
||||
UTILITIES
|
||||
MISC
|
||||
CLOTHS
|
||||
HEALTH
|
||||
CHARITY
|
||||
@@ -0,0 +1,83 @@
|
||||
U0 BgtAcctsUpdate()
|
||||
{
|
||||
CBgtEntry *tmpb;
|
||||
CBgtTemplate *tmpt;
|
||||
tmpb=b_head.next;
|
||||
while (tmpb!=&b_head) {
|
||||
if (tmpb->type!=BE_TEMPLATE_COPY) {
|
||||
tmpb->credit_idx=StrFileAdd(tmpb->credit,
|
||||
&accts_table_strs,accts_table);
|
||||
tmpb->debit_idx =StrFileAdd(tmpb->debit,
|
||||
&accts_table_strs,accts_table);
|
||||
}
|
||||
tmpb=tmpb->next;
|
||||
}
|
||||
tmpt=t_head.next;
|
||||
while (tmpt!=&t_head) {
|
||||
tmpt->b.credit_idx=StrFileAdd(tmpt->b.credit,
|
||||
&accts_table_strs,accts_table);
|
||||
tmpt->b.debit_idx =StrFileAdd(tmpt->b.debit,
|
||||
&accts_table_strs,accts_table);
|
||||
tmpt=tmpt->next;
|
||||
}
|
||||
}
|
||||
|
||||
U0 BgtAcctsWrite()
|
||||
{
|
||||
BgtAcctsUpdate;
|
||||
StrFileWrite(BGT_ACCTS_FILE,accts_table,TRUE);
|
||||
}
|
||||
|
||||
U0 BgtAcctsRead()
|
||||
{
|
||||
I64 i,max_num;
|
||||
U8 *colors,**s=StrFileRead(BGT_ACCTS_FILE,&max_num,&colors,TRUE);
|
||||
StrFileDel(accts_table);
|
||||
accts_table=HashTableNew(512);
|
||||
accts_table_strs=0;
|
||||
for (i=0;i<=max_num;i++)
|
||||
if (s[i])
|
||||
StrFileAdd(s[i],&accts_table_strs,accts_table,colors[i]);
|
||||
StrFileArrDel(s,max_num);
|
||||
Free(colors);
|
||||
}
|
||||
|
||||
I64 BgtAcctColor(U8 *st)
|
||||
{
|
||||
CHashGeneric *tmph;
|
||||
if (tmph=HashFind(st,accts_table,SFT_GENERIC))
|
||||
return tmph->user_data1;
|
||||
else
|
||||
return BLACK;
|
||||
}
|
||||
|
||||
U8 *BgtPopUpAcct(U8 *header=NULL,U8 *dft=NULL)
|
||||
{
|
||||
I64 i;
|
||||
U8 *res;
|
||||
CDoc *doc=DocNew;
|
||||
CDocEntry *doc_e,*doc_dft=NULL;
|
||||
CHashGeneric *tmph;
|
||||
|
||||
if (header)
|
||||
DocPrint(doc,"%s",header);
|
||||
|
||||
for (i=0;i<=accts_table->mask;i++) {
|
||||
tmph=accts_table->body[i];
|
||||
while (tmph) {
|
||||
doc_e=DocPrint(doc,"$$FG,%d$$$$MU-UL,\"%s\",LE=0x%X$$\n",
|
||||
tmph->user_data1,tmph->str,tmph->str);
|
||||
if (dft && !StrCmp(dft,tmph->str))
|
||||
doc_dft=doc_e;
|
||||
tmph=tmph->next;
|
||||
}
|
||||
}
|
||||
|
||||
if (doc_dft) {
|
||||
doc->cur_entry=doc_dft;
|
||||
doc->cur_col=0;
|
||||
}
|
||||
res=PopUpMenu(doc,DOF_DONT_HOME);
|
||||
DocDel(doc);
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
U0 BgtEntryDel2(CBgtEntry *tmpb)
|
||||
{
|
||||
if (tmpb->type!=BE_TEMPLATE_COPY) {
|
||||
Free(tmpb->credit);
|
||||
Free(tmpb->debit);
|
||||
Free(tmpb->desc);
|
||||
}
|
||||
}
|
||||
|
||||
CBgtEntry *BgtEntryCopy(CBgtEntry *tmpb,Bool periodic_copy)
|
||||
{
|
||||
CBgtEntry *res=MAlloc(sizeof(CBgtEntry));
|
||||
MemCpy(res,tmpb,sizeof(CBgtEntry));
|
||||
if (periodic_copy) {
|
||||
res->credit=StrNew(tmpb->credit);
|
||||
res->debit =StrNew(tmpb->debit);
|
||||
res->desc =StrNew(tmpb->desc);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
U0 BgtEntryDel(CBgtEntry *tmpb)
|
||||
{
|
||||
BgtEntryDel2(tmpb);
|
||||
Free(tmpb);
|
||||
}
|
||||
|
||||
U0 BgtIns(CBgtEntry *tmpb)
|
||||
{
|
||||
CBgtEntry *tmpb1=b_head.next;
|
||||
while (tmpb1!=&b_head && tmpb1->date<tmpb->date)
|
||||
tmpb1=tmpb1->next;
|
||||
QueIns(tmpb,tmpb1->last);
|
||||
}
|
||||
|
||||
class CBgtEntryForm
|
||||
{
|
||||
U8 date[512] fmtstr "$$DA-P,A=\"Date :%s\"$$\n";
|
||||
F64 amount fmtstr "Amount $$$$$$DA,A=\"%10.2f\"$$\n";
|
||||
U8 credit[512] fmtstr "$$DA-P,A=\"Credit (from) Acct:%s\"$$\n";
|
||||
U8 debit [512] fmtstr "$$DA-P,A=\"Debit (to) Acct:%s\"$$\n";
|
||||
U8 desc [512] fmtstr "$$DA-P,A=\"Desc :%s\"$$\n";
|
||||
};
|
||||
|
||||
CBgtEntry *BgtEntryPmt(CBgtEntry *dft=NULL)
|
||||
{
|
||||
CBgtEntryForm b;
|
||||
CBgtEntry *tmpb;
|
||||
U8 *st;
|
||||
MemSet(&b,0,sizeof(CBgtEntryForm));
|
||||
StrCpy(&b.date,"*");
|
||||
if (dft) {
|
||||
StrPrint(b.date,"%D",dft->date);
|
||||
b.amount=dft->amount;
|
||||
StrCpy(b.credit,dft->credit);
|
||||
StrCpy(b.debit ,dft->debit);
|
||||
StrCpy(b.desc ,dft->desc);
|
||||
}
|
||||
while (TRUE)
|
||||
if (PopUpForm(&b)) {
|
||||
if (!*b.credit) {
|
||||
st=BgtPopUpAcct("Credit Acct\n\n");
|
||||
if (st!=DOCM_CANCEL)
|
||||
StrCpy(b.credit,st);
|
||||
} else if (!*b.debit) {
|
||||
st=BgtPopUpAcct("Debit Acct\n\n");
|
||||
if (st!=DOCM_CANCEL)
|
||||
StrCpy(b.debit,st);
|
||||
} else {
|
||||
tmpb=CAlloc(sizeof(CBgtEntry));
|
||||
tmpb->date =Str2Date(b.date);
|
||||
tmpb->amount=b.amount;
|
||||
tmpb->credit=StrNew(b.credit);
|
||||
tmpb->debit =StrNew(b.debit);
|
||||
tmpb->desc =StrNew(b.desc);
|
||||
tmpb->type =BE_NORMAL;
|
||||
StrFileAdd(tmpb->credit,&accts_table_strs,accts_table);
|
||||
StrFileAdd(tmpb->debit,&accts_table_strs,accts_table);
|
||||
return tmpb;
|
||||
}
|
||||
} else
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
U0 BgtDataRead()
|
||||
{
|
||||
CBgtEntry *tmpb;
|
||||
CBgtTemplate *tmpt;
|
||||
I64 i,cnt,size;
|
||||
U8 *b,*ptr;
|
||||
I64 max_num;
|
||||
U8 **s=StrFileRead(BGT_STRINGS_FILE,&max_num);
|
||||
|
||||
MemSet(&b_head,0,sizeof(CBgtEntry));
|
||||
QueInit(&b_head);
|
||||
b_head.date=Now;
|
||||
MemSet(&t_head,0,sizeof(CBgtTemplate));
|
||||
QueInit(&t_head);
|
||||
t_head.b.date=Now;
|
||||
|
||||
if (ptr=b=FileRead(BGT_DATA_FILE,&size)) {
|
||||
cnt=*ptr(I64 *)++;
|
||||
for (i=0;i<cnt;i++) {
|
||||
tmpb=CAlloc(sizeof(CBgtEntry));
|
||||
MemCpy(&tmpb->start,ptr,BE_SIZE);
|
||||
tmpb->credit=StrNew(s[tmpb->credit_idx]);
|
||||
tmpb->debit =StrNew(s[tmpb->debit_idx]);
|
||||
tmpb->desc =StrNew(s[tmpb->desc_idx]);
|
||||
QueIns(tmpb,b_head.last);
|
||||
ptr+=BE_SIZE;
|
||||
}
|
||||
|
||||
cnt=*ptr(I64 *)++;
|
||||
for (i=0;i<cnt;i++) {
|
||||
tmpt=CAlloc(sizeof(CBgtTemplate));
|
||||
MemCpy(&tmpt->start,ptr,BT_SIZE);
|
||||
ptr+=BT_SIZE;
|
||||
MemCpy(&tmpt->b.start,ptr,BE_SIZE);
|
||||
ptr+=BE_SIZE;
|
||||
tmpt->b.credit=StrNew(s[tmpt->b.credit_idx]);
|
||||
tmpt->b.debit =StrNew(s[tmpt->b.debit_idx]);
|
||||
tmpt->b.desc =StrNew(s[tmpt->b.desc_idx]);
|
||||
QueIns(tmpt,t_head.last);
|
||||
}
|
||||
}
|
||||
|
||||
StrFileArrDel(s,max_num);
|
||||
Free(b);
|
||||
|
||||
BgtAcctsUpdate;
|
||||
}
|
||||
|
||||
U0 BgtDataWrite()
|
||||
{
|
||||
I64 i,num=0,size,cnt1,cnt2;
|
||||
CHashTable *table=HashTableNew(1024);
|
||||
CBgtEntry *tmpb;
|
||||
CBgtTemplate *tmpt;
|
||||
CHashGeneric *tmph;
|
||||
U8 *buf,*ptr;
|
||||
|
||||
for (i=0;i<=accts_table->mask;i++) {
|
||||
tmph=accts_table->body[i];
|
||||
while (tmph) {
|
||||
StrFileAdd(tmph->str,&num,table); //Cosmetics -- make accts appear first.
|
||||
tmph=tmph->next;
|
||||
}
|
||||
}
|
||||
|
||||
tmpb=b_head.next;
|
||||
cnt1=0;
|
||||
while (tmpb!=&b_head) {
|
||||
if (tmpb->type!=BE_TEMPLATE_COPY) {
|
||||
tmpb->credit_idx =StrFileAdd(tmpb->credit,&num,table);
|
||||
tmpb->debit_idx =StrFileAdd(tmpb->debit,&num,table);
|
||||
tmpb->desc_idx =StrFileAdd(tmpb->desc,&num,table);
|
||||
cnt1++;
|
||||
}
|
||||
tmpb=tmpb->next;
|
||||
}
|
||||
|
||||
tmpt=t_head.next;
|
||||
cnt2=0;
|
||||
while (tmpt!=&t_head) {
|
||||
tmpt->b.credit_idx =StrFileAdd(tmpt->b.credit,&num,table);
|
||||
tmpt->b.debit_idx =StrFileAdd(tmpt->b.debit,&num,table);
|
||||
tmpt->b.desc_idx =StrFileAdd(tmpt->b.desc,&num,table);
|
||||
cnt2++;
|
||||
tmpt=tmpt->next;
|
||||
}
|
||||
StrFileWrite(BGT_STRINGS_FILE,table);
|
||||
StrFileDel(table);
|
||||
|
||||
size=sizeof(I64)*2+cnt1*BE_SIZE+cnt2*(BT_SIZE+BE_SIZE);
|
||||
buf=ptr=MAlloc(size);
|
||||
|
||||
MemCpy(ptr,&cnt1,sizeof(I64));
|
||||
ptr+=sizeof(I64);
|
||||
tmpb=b_head.next;
|
||||
while (tmpb!=&b_head) {
|
||||
if (tmpb->type!=BE_TEMPLATE_COPY) {
|
||||
MemCpy(ptr,&tmpb->start,BE_SIZE);
|
||||
ptr+=BE_SIZE;
|
||||
}
|
||||
tmpb=tmpb->next;
|
||||
}
|
||||
|
||||
MemCpy(ptr,&cnt2,sizeof(I64));
|
||||
ptr+=sizeof(I64);
|
||||
tmpt=t_head.next;
|
||||
while (tmpt!=&t_head) {
|
||||
MemCpy(ptr,&tmpt->start,BT_SIZE);
|
||||
ptr+=BT_SIZE;
|
||||
MemCpy(ptr,&tmpt->b.start,BE_SIZE);
|
||||
ptr+=BE_SIZE;
|
||||
tmpt=tmpt->next;
|
||||
}
|
||||
|
||||
FileWrite(BGT_DATA_FILE,buf,size);
|
||||
Free(buf);
|
||||
}
|
||||
|
||||
U0 BgtDel()
|
||||
{
|
||||
CBgtEntry *tmpb,*tmpb1;
|
||||
CBgtTemplate *tmpt,*tmpt1;
|
||||
tmpb=b_head.next;
|
||||
while (tmpb!=&b_head) {
|
||||
tmpb1=tmpb->next;
|
||||
BgtEntryDel2(tmpb);
|
||||
Free(tmpb);
|
||||
tmpb=tmpb1;
|
||||
}
|
||||
tmpt=t_head.next;
|
||||
while (tmpt!=&t_head) {
|
||||
tmpt1=tmpt->next;
|
||||
BgtEntryDel2(&tmpt->b);
|
||||
Free(tmpt);
|
||||
tmpt=tmpt1;
|
||||
}
|
||||
StrFileDel(accts_table);
|
||||
accts_table=NULL;
|
||||
accts_table_strs=0;
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
extern U0 BgtRegen();
|
||||
|
||||
Bool BgtPutKey(CDoc *doc,U8 *,I64 ch,I64 sc)
|
||||
{//ch=ASCII; sc=scan_code
|
||||
no_warn sc;
|
||||
CBgtEntry *tmpb,*tmpb1;
|
||||
CBgtTemplate *tmpt,*tmpt1;
|
||||
CDocEntry *doc_ce;
|
||||
U8 *st;
|
||||
switch (ch) {
|
||||
case '\n':
|
||||
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
|
||||
doc_ce->type_u8==DOCT_MENU_VAL) {
|
||||
tmpb=doc_ce->user_data;
|
||||
if (tmpt=tmpb->template) {
|
||||
if (tmpt1=BgtTemplatePmt(tmpt)) {
|
||||
QueRem(tmpt);
|
||||
BgtTemplatePurge(tmpt);
|
||||
BgtEntryDel2(&tmpt->b);
|
||||
Free(tmpt);
|
||||
QueIns(tmpt1,t_head.last);
|
||||
BgtTemplateExpand(tmpt1);
|
||||
BgtRegen;
|
||||
}
|
||||
} else {
|
||||
if (tmpb1=BgtEntryPmt(tmpb)) {
|
||||
QueRem(tmpb);
|
||||
BgtEntryDel(tmpb);
|
||||
BgtIns(tmpb1);
|
||||
BgtRegen;
|
||||
}
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
case CH_CTRLY:
|
||||
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
|
||||
doc_ce->type_u8==DOCT_MENU_VAL) {
|
||||
tmpb=doc_ce->user_data;
|
||||
if (tmpt=tmpb->template) {
|
||||
QueRem(tmpt);
|
||||
BgtTemplateDel(tmpt);
|
||||
} else {
|
||||
QueRem(tmpb);
|
||||
BgtEntryDel(tmpb);
|
||||
}
|
||||
BgtRegen;
|
||||
}
|
||||
return TRUE;
|
||||
case 'a':
|
||||
PopUpOk( "Set the name and color of your accounts.\n"
|
||||
"To delete accounts, manually edit\n"
|
||||
"$$GREEN$$~/Budget/Accts.DD.Z$$FG$$.");
|
||||
if (PopUpEd(BGT_ACCTS_FILE,Fs)) {
|
||||
BgtAcctsRead;
|
||||
BgtRegen;
|
||||
}
|
||||
return TRUE;
|
||||
case 'v':
|
||||
if ((st=BgtPopUpAcct("View Acct\n\n",view_acct))>=0) {
|
||||
StrCpy(view_acct,st);
|
||||
BgtRegen;
|
||||
}
|
||||
return TRUE;
|
||||
case 'n':
|
||||
if (tmpb1=BgtEntryPmt) {
|
||||
BgtIns(tmpb1);
|
||||
BgtRegen;
|
||||
}
|
||||
return TRUE;
|
||||
case 't':
|
||||
if (tmpt1=BgtTemplatePmt) {
|
||||
QueIns(tmpt1,t_head.last);
|
||||
BgtTemplateExpand(tmpt1);
|
||||
BgtRegen;
|
||||
}
|
||||
return TRUE;
|
||||
case 'c':
|
||||
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
|
||||
doc_ce->type_u8==DOCT_MENU_VAL)
|
||||
tmpb=doc_ce->user_data;
|
||||
else
|
||||
tmpb=NULL;
|
||||
if (tmpb1=BgtEntryPmt(tmpb)) {
|
||||
BgtIns(tmpb1);
|
||||
BgtRegen;
|
||||
}
|
||||
return TRUE;
|
||||
case 'p':
|
||||
if ((doc_ce=doc->cur_entry) && doc_ce!=doc &&
|
||||
doc_ce->type_u8==DOCT_MENU_VAL) {
|
||||
tmpb=doc_ce->user_data;
|
||||
if (tmpt1=BgtTemplatePmt(,tmpb)) {
|
||||
BgtTemplateExpand(tmpt1,TRUE);
|
||||
BgtTemplateDel(tmpt1);
|
||||
BgtRegen;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
U0 BgtRegen()
|
||||
{
|
||||
I64 timeout_jiffy,c,color=COLOR_INVALID;
|
||||
F64 balance=0;
|
||||
CDoc *doc,*pdoc,*ddoc;
|
||||
CDocEntry *doc_ce;
|
||||
CBgtEntry *tmpb=b_head.next,*tmpb_ce;
|
||||
doc=DocNew;
|
||||
doc->flags|=DOCF_FORM;
|
||||
while (tmpb!=&b_head) {
|
||||
if (!StrCmp(view_acct,tmpb->credit))
|
||||
balance-=tmpb->amount;
|
||||
if (!StrCmp(view_acct,tmpb->debit))
|
||||
balance+=tmpb->amount;
|
||||
c=BgtAcctColor(tmpb->credit);
|
||||
if (c!=color) {
|
||||
color=c;
|
||||
DocPrint(doc,"$$FG,%d$$",color);
|
||||
}
|
||||
tmpb->doc_e=DocPrint(doc,
|
||||
"$$MU-UL,\"%D %8ts %8ts:%8.2f %8.2f:%$$Q\",U=0x%X$$\n",
|
||||
tmpb->date,tmpb->credit,tmpb->debit,balance,
|
||||
tmpb->amount,tmpb->desc,tmpb);
|
||||
tmpb=tmpb->next;
|
||||
}
|
||||
DocRecalc(doc);
|
||||
|
||||
if (pdoc=Fs->put_doc) {
|
||||
DocLock(pdoc);
|
||||
//Now, we want to preserve old position in doc, using ugly brute force.
|
||||
//It's tricky -- can't use old line num because of editor filters.
|
||||
|
||||
//The price we pay for using the standard document editor is this kludge.
|
||||
//When I originally wrote my budget program, I did not have separate budget
|
||||
//and line entries, so we never had to resync.
|
||||
|
||||
doc_ce=pdoc->cur_entry;
|
||||
timeout_jiffy=cnts.jiffies+JIFFY_FREQ; //Max one second.
|
||||
while (doc_ce!=pdoc && cnts.jiffies<timeout_jiffy) {
|
||||
while (doc_ce->type_u8!=DOCT_MENU_VAL || !(tmpb_ce=doc_ce->user_data)) {
|
||||
doc_ce=doc_ce->next;
|
||||
if (doc_ce==pdoc) goto br_cont;
|
||||
}
|
||||
tmpb=b_head.next;
|
||||
while (tmpb!=&b_head) {
|
||||
if (tmpb==tmpb_ce) {
|
||||
doc->cur_entry=tmpb->doc_e;
|
||||
doc->cur_col=0;
|
||||
DocCenter(doc);
|
||||
goto br_cont;
|
||||
}
|
||||
tmpb=tmpb->next;
|
||||
}
|
||||
doc_ce=doc_ce->next;
|
||||
}
|
||||
}
|
||||
|
||||
br_cont:
|
||||
ddoc=Fs->display_doc;
|
||||
Fs->put_doc =doc;
|
||||
Fs->display_doc=doc;
|
||||
DocDel(pdoc);
|
||||
if (pdoc!=ddoc)
|
||||
DocDel(ddoc);
|
||||
doc->user_put_key=&BgtPutKey;
|
||||
}
|
||||
|
||||
U0 Budget()
|
||||
{
|
||||
CDoc *pdoc,*ddoc,*old_put,*old_display;
|
||||
BgtAcctsRead;
|
||||
BgtDataRead;
|
||||
CBgtTemplatesExpand;
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
AutoComplete;
|
||||
WinBorder;
|
||||
WinMax;
|
||||
MenuPush(
|
||||
"File {"
|
||||
" Abort(,CH_SHIFT_ESC);"
|
||||
" Exit(,CH_ESC);"
|
||||
"}"
|
||||
"Edit {"
|
||||
" NewEntry(,'n');"
|
||||
" CopyEntry(,'c');"
|
||||
" PeriodicEntry(,'p');"
|
||||
" EditEntry(,'\n');"
|
||||
" DeleteEntry(,CH_CTRLY);"
|
||||
" NewTemplate(,'t');"
|
||||
" AcctsFile(,'a');"
|
||||
"}"
|
||||
"View {"
|
||||
" ViewAcct(,'v');"
|
||||
"}"
|
||||
);
|
||||
StrCpy(view_acct,"BANK");
|
||||
DocMax;
|
||||
old_put =Fs->put_doc;
|
||||
old_display =Fs->display_doc;
|
||||
Fs->put_doc =NULL;
|
||||
Fs->display_doc=NULL;
|
||||
BgtRegen;
|
||||
try
|
||||
if (View) {
|
||||
BgtDataWrite;
|
||||
BgtAcctsWrite;
|
||||
}
|
||||
catch
|
||||
PutExcept;
|
||||
|
||||
pdoc=Fs->put_doc;
|
||||
ddoc=Fs->display_doc;
|
||||
Fs->put_doc =old_put;
|
||||
Fs->display_doc=old_display;
|
||||
DocDel(pdoc);
|
||||
if (pdoc!=ddoc)
|
||||
DocDel(ddoc);
|
||||
|
||||
SettingsPop;
|
||||
BgtDel;
|
||||
MenuPop;
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
#define SFT_GENERIC 1
|
||||
|
||||
public U8 **StrFileRead(U8 *name,I64 *_max_num=NULL,
|
||||
U8 **_colors=NULL,Bool no_nums=FALSE)
|
||||
{
|
||||
CDoc *doc=DocRead(name,DOCF_DBL_DOLLARS|DOCF_NO_CURSOR);
|
||||
CDocEntry *doc_e=doc->head.next;
|
||||
I64 i,max_num=0;
|
||||
U8 *ptr,**res,*colors;
|
||||
|
||||
while (doc_e!=doc) {
|
||||
if (doc_e->type_u8==DOCT_TEXT) {
|
||||
if (no_nums)
|
||||
i=++max_num;
|
||||
else {
|
||||
i=Str2I64(doc_e->tag,,&ptr);
|
||||
if (i>max_num) max_num=i;
|
||||
if (*ptr==',') ptr++;
|
||||
ptr=StrNew(ptr);
|
||||
Free(doc_e->tag);
|
||||
doc_e->tag=ptr;
|
||||
}
|
||||
doc_e->user_data=i;
|
||||
}
|
||||
doc_e=doc_e->next;
|
||||
}
|
||||
|
||||
res=CAlloc(sizeof(U8 *)*(max_num+1));
|
||||
colors=CAlloc(sizeof(U8)*(max_num+1));
|
||||
doc_e=doc->head.next;
|
||||
while (doc_e!=doc) {
|
||||
if (doc_e->type_u8==DOCT_TEXT && 0<=doc_e->user_data<=max_num) {
|
||||
res[doc_e->user_data]=doc_e->tag;
|
||||
doc_e->tag=NULL;
|
||||
colors[doc_e->user_data]=doc_e->type.u8[1]&15;
|
||||
}
|
||||
doc_e=doc_e->next;
|
||||
}
|
||||
|
||||
DocDel(doc);
|
||||
if (_max_num) *_max_num=max_num;
|
||||
if (_colors)
|
||||
*_colors=colors;
|
||||
else
|
||||
Free(colors);
|
||||
return res;
|
||||
}
|
||||
|
||||
public U0 StrFileArrDel(U8 **a,I64 max_num)
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<=max_num;i++)
|
||||
Free(a[i]);
|
||||
Free(a);
|
||||
}
|
||||
|
||||
public I64 StrFileAdd(U8 *st,I64 *_num,
|
||||
CHashTable *table,I64 color=COLOR_INVALID)
|
||||
{
|
||||
CHashGeneric *tmph;
|
||||
if (!st) return 0;
|
||||
if (!(tmph=HashFind(st,table,SFT_GENERIC))) {
|
||||
tmph=CAlloc(sizeof(CHashGeneric));
|
||||
tmph->type=SFT_GENERIC;
|
||||
tmph->str=StrNew(st);
|
||||
tmph->user_data0=(*_num)++;
|
||||
HashAdd(tmph,table);
|
||||
}
|
||||
if (color!=COLOR_INVALID)
|
||||
tmph->user_data1=color;
|
||||
return tmph->user_data0;
|
||||
}
|
||||
|
||||
I64 StrEntriesCompare(CHashGeneric *h1,CHashGeneric *h2)
|
||||
{
|
||||
return h1->user_data0-h2->user_data0;
|
||||
}
|
||||
|
||||
public U0 StrFileWrite(U8 *name,CHashTable *table,Bool no_nums=FALSE)
|
||||
{
|
||||
I64 i,j,cnt,color=BLACK;
|
||||
CDoc *doc=DocNew(name);
|
||||
CHashGeneric *tmph,**a;
|
||||
if (table) {
|
||||
cnt=0; //Count Strings
|
||||
for (i=0;i<=table->mask;i++)
|
||||
cnt+=LinkedLstCnt(table->body[i]);
|
||||
a=MAlloc(cnt*sizeof(CHashGeneric *));
|
||||
j=0; //Load Strings
|
||||
for (i=0;i<=table->mask;i++) {
|
||||
tmph=table->body[i];
|
||||
while (tmph) {
|
||||
a[j++]=tmph;
|
||||
tmph=tmph->next;
|
||||
}
|
||||
}
|
||||
QSortI64(a,cnt,&StrEntriesCompare);
|
||||
for (i=0;i<cnt;i++) {
|
||||
tmph=a[i];
|
||||
if (tmph->user_data1&15!=color) {
|
||||
DocPrint(doc,"$$FG,%d$$",tmph->user_data1&15);
|
||||
color=tmph->user_data1&15;
|
||||
}
|
||||
if (no_nums)
|
||||
DocPrint(doc,"%s\n",tmph->str);
|
||||
else
|
||||
DocPrint(doc,"%d,%s\n",tmph->user_data0,tmph->str);
|
||||
}
|
||||
Free(a);
|
||||
}
|
||||
doc->flags|=DOCF_NO_CURSOR;
|
||||
DocWrite(doc);
|
||||
DocDel(doc);
|
||||
}
|
||||
|
||||
public U0 StrFileDel(CHashTable *table)
|
||||
{
|
||||
I64 i;
|
||||
CHashGeneric *tmph,*tmph1;
|
||||
if (!table) return;
|
||||
for (i=0;i<=table->mask;i++) {
|
||||
tmph=table->body[i];
|
||||
while (tmph) {
|
||||
tmph1=tmph->next;
|
||||
Free(tmph->str);
|
||||
Free(tmph);
|
||||
tmph=tmph1;
|
||||
}
|
||||
}
|
||||
Free(table->body);
|
||||
Free(table);
|
||||
}
|
||||
@@ -0,0 +1,182 @@
|
||||
U0 BgtTemplatePurge(CBgtTemplate *tmpt)
|
||||
{
|
||||
CBgtEntry *tmpb,*tmpb1;
|
||||
tmpb=b_head.next;
|
||||
while (tmpb!=&b_head) {
|
||||
tmpb1=tmpb->next;
|
||||
if (tmpb->template==tmpt) {
|
||||
QueRem(tmpb);
|
||||
BgtEntryDel2(tmpb);
|
||||
Free(tmpb);
|
||||
}
|
||||
tmpb=tmpb1;
|
||||
}
|
||||
}
|
||||
|
||||
U0 BgtTemplateDel(CBgtTemplate *tmpt)
|
||||
{
|
||||
BgtTemplatePurge(tmpt);
|
||||
BgtEntryDel2(&tmpt->b);
|
||||
Free(tmpt);
|
||||
}
|
||||
|
||||
U0 BgtTemplateExpand(CBgtTemplate *tmpt,Bool periodic_copy=FALSE)
|
||||
{
|
||||
CDate d,start,end;
|
||||
CDateStruct ds;
|
||||
CBgtEntry *tmpb;
|
||||
Bool first=TRUE;
|
||||
|
||||
start=MyStr2Date(tmpt->start_date);
|
||||
end =MyStr2Date(tmpt->end_date);
|
||||
tmpt->b.template=tmpt;
|
||||
switch (tmpt->type) {
|
||||
case BT_INTERVAL:
|
||||
d=start;
|
||||
while (d<=end) {
|
||||
if (!first || !periodic_copy) {
|
||||
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
|
||||
tmpb->date=d;
|
||||
if (periodic_copy)
|
||||
tmpb->template=NULL;
|
||||
else
|
||||
tmpb->type=BE_TEMPLATE_COPY;
|
||||
BgtIns(tmpb);
|
||||
}
|
||||
d+=tmpt->period*0x100000000;
|
||||
first=FALSE;
|
||||
}
|
||||
break;
|
||||
case BT_MONTHLY:
|
||||
Date2Struct(&ds,start);
|
||||
while (TRUE) {
|
||||
d=Struct2Date(&ds);
|
||||
if (d<=end) {
|
||||
if (!first || !periodic_copy) {
|
||||
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
|
||||
tmpb->date=d;
|
||||
if (periodic_copy)
|
||||
tmpb->template=NULL;
|
||||
else
|
||||
tmpb->type=BE_TEMPLATE_COPY;
|
||||
BgtIns(tmpb);
|
||||
}
|
||||
} else
|
||||
break;
|
||||
if (++ds.mon>12) {
|
||||
ds.mon=1;
|
||||
ds.year++;
|
||||
}
|
||||
first=FALSE;
|
||||
}
|
||||
break;
|
||||
case BT_BIMONTHLY:
|
||||
Date2Struct(&ds,start);
|
||||
while (TRUE) {
|
||||
d=Struct2Date(&ds);
|
||||
if (d<=end) {
|
||||
if (!first || !periodic_copy) {
|
||||
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
|
||||
tmpb->date=d;
|
||||
if (periodic_copy)
|
||||
tmpb->template=NULL;
|
||||
else
|
||||
tmpb->type=BE_TEMPLATE_COPY;
|
||||
BgtIns(tmpb);
|
||||
}
|
||||
} else
|
||||
break;
|
||||
ds.mon+=2;
|
||||
if (ds.mon>12) {
|
||||
ds.mon-=12;
|
||||
ds.year++;
|
||||
}
|
||||
first=FALSE;
|
||||
}
|
||||
break;
|
||||
case BT_SEMIANNUAL:
|
||||
Date2Struct(&ds,start);
|
||||
while (TRUE) {
|
||||
d=Struct2Date(&ds);
|
||||
if (d<=end) {
|
||||
if (!first || !periodic_copy) {
|
||||
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
|
||||
tmpb->date=d;
|
||||
if (periodic_copy)
|
||||
tmpb->template=NULL;
|
||||
else
|
||||
tmpb->type=BE_TEMPLATE_COPY;
|
||||
BgtIns(tmpb);
|
||||
}
|
||||
} else
|
||||
break;
|
||||
ds.mon+=6;
|
||||
if (ds.mon>12) {
|
||||
ds.mon-=12;
|
||||
ds.year++;
|
||||
}
|
||||
first=FALSE;
|
||||
}
|
||||
break;
|
||||
case BT_ANNUAL:
|
||||
Date2Struct(&ds,start);
|
||||
while (TRUE) {
|
||||
d=Struct2Date(&ds);
|
||||
if (d<=end) {
|
||||
if (!first || !periodic_copy) {
|
||||
tmpb=BgtEntryCopy(&tmpt->b,periodic_copy);
|
||||
tmpb->date=d;
|
||||
if (periodic_copy)
|
||||
tmpb->template=NULL;
|
||||
else
|
||||
tmpb->type=BE_TEMPLATE_COPY;
|
||||
BgtIns(tmpb);
|
||||
}
|
||||
} else
|
||||
break;
|
||||
ds.year++;
|
||||
first=FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
U0 CBgtTemplatesExpand()
|
||||
{
|
||||
CBgtTemplate *tmpt=t_head.next;
|
||||
while (tmpt!=&t_head) {
|
||||
BgtTemplateExpand(tmpt);
|
||||
tmpt=tmpt->next;
|
||||
}
|
||||
}
|
||||
|
||||
CBgtTemplate *BgtTemplatePmt(CBgtTemplate *dft_t=NULL,CBgtEntry *dft_b=NULL)
|
||||
{
|
||||
CBgtTemplate t,*tmpt;
|
||||
CBgtEntry *tmpb;
|
||||
MemSet(&t,0,sizeof(CBgtTemplate));
|
||||
if (dft_t) {
|
||||
MemCpy(&t.start,&dft_t->start,BT_SIZE);
|
||||
dft_b=&dft_t->b;
|
||||
} else {
|
||||
t.type=BT_INTERVAL;
|
||||
if (dft_b)
|
||||
StrPrint(&t.start_date,"%D",dft_b->date);
|
||||
else
|
||||
StrCpy(&t.start_date,"[");
|
||||
StrCpy(&t.end_date,"]");
|
||||
}
|
||||
while (TRUE)
|
||||
if (PopUpForm(&t) && ((t.type==BT_INTERVAL && t.period>0) ||
|
||||
t.type>BT_INTERVAL)) {
|
||||
if (tmpb=BgtEntryPmt(dft_b)) {
|
||||
tmpt=CAlloc(sizeof(CBgtTemplate));
|
||||
MemCpy(&tmpt->start,&t.start,BT_SIZE);
|
||||
MemCpy(&tmpt->b,tmpb,sizeof(CBgtEntry));
|
||||
Free(tmpb);
|
||||
return tmpt;
|
||||
}
|
||||
} else
|
||||
break;
|
||||
return NULL;
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
#define BGT_STRINGS_FILE "~/Budget/Strs.DD.Z"
|
||||
#define BGT_ACCTS_FILE "~/Budget/Accts.DD.Z"
|
||||
#define BGT_DATA_FILE "~/Budget/Bgt.DATA.Z"
|
||||
|
||||
#define BE_NORMAL 0
|
||||
#define BE_GAS 1
|
||||
#define BE_ANNIVERSARY 2
|
||||
#define BE_PRICE 3
|
||||
#define BE_TEMPLATE_COPY 4
|
||||
|
||||
extern class CBgtTemplate;
|
||||
|
||||
class CBgtEntry
|
||||
{
|
||||
CBgtEntry *next,*last;
|
||||
|
||||
U0 start;
|
||||
CDate date;
|
||||
U16 type,flags;
|
||||
U32 credit_idx,debit_idx,desc_idx;
|
||||
F64 amount;
|
||||
U0 end;
|
||||
|
||||
U8 *credit,*debit,*desc;
|
||||
CBgtTemplate *template;
|
||||
CDocEntry *doc_e;
|
||||
} b_head;
|
||||
#define BE_SIZE (offset(CBgtEntry.end)-offset(CBgtEntry.start))
|
||||
|
||||
#define BT_NULL 0
|
||||
#define BT_INTERVAL 1
|
||||
#define BT_MONTHLY 2
|
||||
#define BT_BIMONTHLY 3
|
||||
#define BT_SEMIANNUAL 4
|
||||
#define BT_ANNUAL 5
|
||||
|
||||
DefineLstLoad("ST_BGT_TEMPLATE_TYPES",
|
||||
"Null\0Interval\0Monthly\0Bimonthly\0Semiannual\0Annual\0");
|
||||
|
||||
class CBgtTemplate
|
||||
{
|
||||
CBgtTemplate *next,*last;
|
||||
|
||||
U0 start;
|
||||
U16 type fmtstr "$$LS,D=\"ST_BGT_TEMPLATE_TYPES\"$$\n";
|
||||
U16 flags;
|
||||
U8 start_date[16] fmtstr "$$DA-P,A=\"Start Date:%s\"$$\n";
|
||||
U8 end_date[16] fmtstr "$$DA-P,A=\"End Date :%s\"$$\n";
|
||||
F64 period fmtstr "$$DA,A=\"Period :%8.2f\"$$\n";
|
||||
U0 end;
|
||||
|
||||
CBgtEntry b;
|
||||
} t_head;
|
||||
#define BT_SIZE (offset(CBgtTemplate.end)-offset(CBgtTemplate.start))
|
||||
|
||||
U8 view_acct[512];
|
||||
CHashTable *accts_table=NULL;
|
||||
I64 accts_table_strs=0;
|
||||
|
||||
CDate MyStr2Date(U8 *st)
|
||||
{
|
||||
CDateStruct ds;
|
||||
CDate res;
|
||||
if (st&&*st) {
|
||||
if (StrOcc(st,'['))
|
||||
res=b_head.next->date;
|
||||
else if (StrOcc(st,']'))
|
||||
res=b_head.last->date;
|
||||
else
|
||||
res=Str2Date(st);
|
||||
} else
|
||||
res=Now;
|
||||
Date2Struct(&ds,res);
|
||||
if (ds.year>2050)
|
||||
ds.year-=100;
|
||||
return Struct2Date(&ds);
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
Cd(__DIR__);;
|
||||
if (!FileFind("~/Budget",,FUF_JUST_DIRS)) {
|
||||
MkDir("~/Budget");
|
||||
Copy("Accts.DD.Z","~/Budget");
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
#help_index "Finance"
|
||||
|
||||
Cd(__DIR__);;
|
||||
#include "BgtStrs"
|
||||
#include "Budget"
|
||||
#include "BgtAccts"
|
||||
#include "BgtEntry"
|
||||
#include "BgtTemplate"
|
||||
#include "BgtFile"
|
||||
#include "BgtMain"
|
||||
|
||||
#help_index ""
|
||||
@@ -0,0 +1,4 @@
|
||||
Cd(__DIR__);;
|
||||
#include "Load"
|
||||
#include "Install" //Might as well always install
|
||||
Budget;
|
||||
@@ -0,0 +1,128 @@
|
||||
//Makes a mesh ball.
|
||||
|
||||
#define VERTICES_NUM 1024
|
||||
#define TRIS_NUM 1024
|
||||
|
||||
class Ball
|
||||
{
|
||||
I32 vertex_cnt;
|
||||
I32 tri_cnt;
|
||||
CD3I32 v[VERTICES_NUM];
|
||||
CMeshTri t[TRIS_NUM];
|
||||
} *b;
|
||||
|
||||
class BallDefineStruct
|
||||
{
|
||||
F64 radius fmtstr "$$DA-TRM,A=\"Radius :%8.3f\"$$\n";
|
||||
I64 n_longitude fmtstr "$$DA-TRM,A=\"Longitude Faces:%5d\"$$\n";
|
||||
I64 n_lattitude fmtstr "$$DA-TRM,A=\"Lattitude Rings:%5d\"$$\n";
|
||||
};
|
||||
|
||||
U0 BDInit(BallDefineStruct *bd)
|
||||
{
|
||||
MemSet(bd,0,sizeof(BallDefineStruct));
|
||||
bd->n_longitude=16;
|
||||
bd->n_lattitude=8;
|
||||
bd->radius =20.0;
|
||||
}
|
||||
|
||||
U0 BDCorrect(BallDefineStruct *bd)
|
||||
{
|
||||
bd->n_longitude=(bd->n_longitude+1)/2;
|
||||
bd->n_lattitude=(bd->n_lattitude+1)/2;
|
||||
}
|
||||
|
||||
I64 AddVertex(BallDefineStruct *,I64 x,I64 y,I64 z)
|
||||
{
|
||||
I64 i;
|
||||
for (i=0;i<b->vertex_cnt;i++)
|
||||
if (b->v[i].x==x && b->v[i].y==y && b->v[i].z==z)
|
||||
return i;
|
||||
i=b->vertex_cnt++;
|
||||
b->v[i].x=x;
|
||||
b->v[i].y=y;
|
||||
b->v[i].z=z;
|
||||
return i;
|
||||
}
|
||||
|
||||
I64 AddTri(BallDefineStruct *,I64 c,I64 n0,I64 n1,I64 n2)
|
||||
{
|
||||
I64 res=b->tri_cnt++;
|
||||
b->t[res].color=c;
|
||||
b->t[res].nums[0]=n0;
|
||||
b->t[res].nums[1]=n1;
|
||||
b->t[res].nums[2]=n2;
|
||||
return res;
|
||||
}
|
||||
|
||||
U8 *Ball2CSprite()
|
||||
{
|
||||
//See $LK,"::/Adam/Gr/GrSpritePlot.HC",A="FL:::/Adam/Gr/GrSpritePlot.HC,1"$ for how CSprite are stored.
|
||||
U8 *res=MAlloc(sizeof(CSpriteMeshU8s)+
|
||||
b->vertex_cnt*sizeof(CD3I32)+b->tri_cnt*sizeof(CMeshTri)
|
||||
+sprite_elem_base_sizes[SPT_END]),
|
||||
*dst=res;
|
||||
*dst++ =SPT_MESH;
|
||||
*dst(I32 *)++ =b->vertex_cnt;
|
||||
*dst(I32 *)++ =b->tri_cnt;
|
||||
MemCpy(dst,&b->v,b->vertex_cnt*sizeof(CD3I32));
|
||||
dst+=b->vertex_cnt*sizeof(CD3I32);
|
||||
MemCpy(dst,&b->t,b->tri_cnt*sizeof(CMeshTri));
|
||||
dst+=b->tri_cnt*sizeof(CMeshTri);
|
||||
*dst++ =SPT_END;
|
||||
return res;
|
||||
}
|
||||
|
||||
public U8 *BallGen()
|
||||
{
|
||||
U8 *res;
|
||||
I64 i,j,n,m,c,p1,p2,p3,p4;
|
||||
BallDefineStruct bd1,bd2;
|
||||
F64 r,r1,r2,z1,z2,d_a1,d_a2;
|
||||
|
||||
BDInit(&bd1);
|
||||
|
||||
while (TRUE) {
|
||||
if (!DocForm(&bd1))
|
||||
return NULL;
|
||||
MemCpy(&bd2,&bd1,sizeof(BallDefineStruct));
|
||||
BDCorrect(&bd2);
|
||||
|
||||
c=PopUpColorLighting;
|
||||
if (c<0) return NULL;
|
||||
|
||||
b=CAlloc(sizeof(Ball));
|
||||
r=bd2.radius;
|
||||
n=bd2.n_lattitude;
|
||||
m=bd2.n_longitude;
|
||||
d_a1=2*ã/n/4;
|
||||
d_a2=2*ã/m/2;
|
||||
for (j=-n;j<n;j++) {
|
||||
r1=r*Cos( j *d_a1);
|
||||
r2=r*Cos((j+1)*d_a1);
|
||||
z1=r*Sin( j *d_a1);
|
||||
z2=r*Sin((j+1)*d_a1);
|
||||
for (i=0;i<m;i++) {
|
||||
p1=AddVertex(&bd2,r1*Cos((2*i +j)*d_a2),r1*Sin((2*i +j)*d_a2),z1);
|
||||
p2=AddVertex(&bd2,r1*Cos((2*i+2+j)*d_a2),r1*Sin((2*i+2+j)*d_a2),z1);
|
||||
p3=AddVertex(&bd2,r2*Cos((2*i+1+j)*d_a2),r2*Sin((2*i+1+j)*d_a2),z2);
|
||||
p4=AddVertex(&bd2,r2*Cos((2*i+3+j)*d_a2),r2*Sin((2*i+3+j)*d_a2),z2);
|
||||
AddTri(&bd2,c,p1,p2,p3);
|
||||
AddTri(&bd2,c,p3,p2,p4);
|
||||
}
|
||||
}
|
||||
|
||||
res=Ball2CSprite;
|
||||
"%h7c",'\n';
|
||||
Sprite(res,"\t\t$$SP,\"<1>\",BI=%d$$");
|
||||
"%h7c",'\n';
|
||||
"Vertices:%d\n",b->vertex_cnt;
|
||||
Free(b);
|
||||
"Do another";
|
||||
if (YorN)
|
||||
Free(res);
|
||||
else
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#help_index "Misc"
|
||||
|
||||
Cd(__DIR__);;
|
||||
#include "ManGen"
|
||||
#include "BallGen"
|
||||
#include "Models"
|
||||
|
||||
#help_index ""
|
||||
@@ -0,0 +1,320 @@
|
||||
//Makes a mesh man.
|
||||
|
||||
#define VERTICES_NUM 1024
|
||||
#define TRIS_NUM 1024
|
||||
|
||||
class Man
|
||||
{
|
||||
I32 vertex_cnt;
|
||||
I32 tri_cnt;
|
||||
CD3I32 v[VERTICES_NUM];
|
||||
CMeshTri t[TRIS_NUM];
|
||||
} *m;
|
||||
|
||||
class ManDefineStruct
|
||||
{
|
||||
F64 head_rad fmtstr
|
||||
"$$DA-TRM,A=\"Head Radius :%8.3f\"$$\n";
|
||||
|
||||
F64 torso_len fmtstr
|
||||
"$$DA-TRM,A=\"Torso Length :%8.3f\"$$\n";
|
||||
F64 arm_len fmtstr
|
||||
"$$DA-TRM,A=\"Arm Length :%8.3f\"$$\n";
|
||||
F64 hand_len fmtstr
|
||||
"$$DA-TRM,A=\"Hand Length :%8.3f\"$$\n";
|
||||
F64 leg_len fmtstr
|
||||
"$$DA-TRM,A=\"Leg Length :%8.3f\"$$\n";
|
||||
F64 foot_len fmtstr
|
||||
"$$DA-TRM,A=\"Foot Length :%8.3f\"$$\n";
|
||||
F64 torso_width fmtstr
|
||||
"$$DA-TRM,A=\"Torso Width :%8.3f\"$$\n";
|
||||
F64 torso_depth fmtstr
|
||||
"$$DA-TRM,A=\"Torso Depth :%8.3f\"$$\n";
|
||||
F64 arm_rad fmtstr
|
||||
"$$DA-TRM,A=\"Arm Radius :%8.3f\"$$\n";
|
||||
F64 hand_rad fmtstr
|
||||
"$$DA-TRM,A=\"Hand Radius :%8.3f\"$$\n";
|
||||
F64 leg_rad fmtstr
|
||||
"$$DA-TRM,A=\"Leg Radius :%8.3f\"$$\n";
|
||||
F64 foot_rad fmtstr
|
||||
"$$DA-TRM,A=\"Foot Radius :%8.3f\"$$\n\n";
|
||||
|
||||
F64 r_shoulder_a1 fmtstr
|
||||
"$$DA-TRM,A=\"R.Shoulder Front/Back Angle:%8.3f\"$$\n";
|
||||
F64 l_shoulder_a1 fmtstr
|
||||
"$$DA-TRM,A=\"L.Shoulder Front/Back Angle:%8.3f\"$$\n";
|
||||
F64 r_hip_a1 fmtstr
|
||||
"$$DA-TRM,A=\"R.Hip Front/Back Angle :%8.3f\"$$\n";
|
||||
F64 l_hip_a1 fmtstr
|
||||
"$$DA-TRM,A=\"L.Hip Front/Back Angle :%8.3f\"$$\n";
|
||||
|
||||
F64 r_shoulder_a2 fmtstr
|
||||
"$$DA-TRM,A=\"R.Shoulder Side Angle :%8.3f\"$$\n";
|
||||
F64 l_shoulder_a2 fmtstr
|
||||
"$$DA-TRM,A=\"L.Shoulder Side Angle :%8.3f\"$$\n";
|
||||
F64 r_hip_a2 fmtstr
|
||||
"$$DA-TRM,A=\"R.Hip Side Angle :%8.3f\"$$\n";
|
||||
F64 l_hip_a2 fmtstr
|
||||
"$$DA-TRM,A=\"L.Hip Side Angle :%8.3f\"$$\n";
|
||||
|
||||
F64 r_elbow_a fmtstr
|
||||
"$$DA-TRM,A=\"R.Elbow Angle :%8.3f\"$$\n";
|
||||
F64 l_elbow_a fmtstr
|
||||
"$$DA-TRM,A=\"L.Elbow Angle :%8.3f\"$$\n";
|
||||
F64 r_knee_a fmtstr
|
||||
"$$DA-TRM,A=\"R.Knee Angle :%8.3f\"$$\n";
|
||||
F64 l_knee_a fmtstr
|
||||
"$$DA-TRM,A=\"L.Knee Angle :%8.3f\"$$\n";
|
||||
|
||||
F64 r_wrist_a fmtstr
|
||||
"$$DA-TRM,A=\"R.Wrist Angle :%8.3f\"$$\n";
|
||||
F64 l_wrist_a fmtstr
|
||||
"$$DA-TRM,A=\"L.Wrist Angle :%8.3f\"$$\n";
|
||||
F64 r_ankle_a fmtstr
|
||||
"$$DA-TRM,A=\"R.Ankle Angle :%8.3f\"$$\n";
|
||||
F64 l_ankle_a fmtstr
|
||||
"$$DA-TRM,A=\"L.Ankle Angle :%8.3f\"$$\n";
|
||||
|
||||
};
|
||||
|
||||
U0 MDInit(ManDefineStruct *md)
|
||||
{
|
||||
MemSet(md,0,sizeof(ManDefineStruct));
|
||||
|
||||
md->head_rad =5.0;
|
||||
|
||||
md->torso_len =35.0;
|
||||
md->arm_len =30.0;
|
||||
md->hand_len =8.0;
|
||||
md->leg_len =32.0;
|
||||
md->foot_len =16.0;
|
||||
md->torso_width=20.0;
|
||||
md->torso_depth=10.0;
|
||||
md->arm_rad =3.5;
|
||||
md->hand_rad =2.0;
|
||||
md->leg_rad =4.0;
|
||||
md->foot_rad =3.0;
|
||||
|
||||
md->r_shoulder_a1 =30;
|
||||
md->l_shoulder_a1 =-30;
|
||||
md->r_hip_a1 =-45;
|
||||
md->l_hip_a1 =45;
|
||||
|
||||
md->r_shoulder_a2 =10;
|
||||
md->l_shoulder_a2 =10;
|
||||
md->r_hip_a2 =-5;
|
||||
md->l_hip_a2 =-5;
|
||||
|
||||
md->r_elbow_a =30;
|
||||
md->l_elbow_a =0;
|
||||
md->r_knee_a =0;
|
||||
md->l_knee_a =30;
|
||||
|
||||
md->r_wrist_a =0;
|
||||
md->l_wrist_a =0;
|
||||
md->r_ankle_a =0;
|
||||
md->l_ankle_a =0;
|
||||
}
|
||||
|
||||
U0 MDCorrect(ManDefineStruct *md)
|
||||
{
|
||||
md->r_ankle_a =-md->r_ankle_a;
|
||||
md->l_ankle_a =-md->l_ankle_a;
|
||||
md->r_knee_a =-md->r_knee_a;
|
||||
md->l_knee_a =-md->l_knee_a;
|
||||
md->r_hip_a2 =-md->r_hip_a2;
|
||||
md->r_shoulder_a2=-md->r_shoulder_a2;
|
||||
md->r_ankle_a+=90;
|
||||
md->l_ankle_a+=90;
|
||||
|
||||
md->foot_len-=md->leg_rad;
|
||||
|
||||
md->r_elbow_a+=md->r_shoulder_a1;
|
||||
md->l_elbow_a+=md->l_shoulder_a1;
|
||||
md->r_knee_a+=md->r_hip_a1;
|
||||
md->l_knee_a+=md->l_hip_a1;
|
||||
|
||||
md->r_wrist_a+=md->r_elbow_a;
|
||||
md->l_wrist_a+=md->l_elbow_a;
|
||||
md->r_ankle_a+=md->r_knee_a;
|
||||
md->l_ankle_a+=md->l_knee_a;
|
||||
}
|
||||
|
||||
I64 AddVertex(ManDefineStruct *md,I64 x,I64 y,I64 z)
|
||||
{
|
||||
I64 res=m->vertex_cnt++;
|
||||
m->v[res].x=-x;
|
||||
m->v[res].y=-y-md->leg_len-md->foot_rad*2;
|
||||
m->v[res].z=-z;
|
||||
return res;
|
||||
}
|
||||
|
||||
I64 AddTri(ManDefineStruct *,I64 c,I64 n0,I64 n1,I64 n2)
|
||||
{
|
||||
I64 res=m->tri_cnt++;
|
||||
m->t[res].color=c;
|
||||
m->t[res].nums[0]=n1;
|
||||
m->t[res].nums[1]=n0;
|
||||
m->t[res].nums[2]=n2;
|
||||
return res;
|
||||
}
|
||||
|
||||
U0 AddBox(ManDefineStruct *md,I64 c,I64 x1,I64 y1,I64 z1,
|
||||
F64 w,F64 h,F64 d,F64 h2,F64 h3,F64 az,F64 ay,F64 ax,
|
||||
I64 *ox,I64 *oy,I64 *oz)
|
||||
{
|
||||
I64 *r;
|
||||
I64 p1a,p2a,p3a,p4a;
|
||||
I64 p1b,p2b,p3b,p4b;
|
||||
I64 wx=w/2,wy=0,wz=0,hx=0,hy=h,hz=0,h2x=0,h2y=h2,h2z=0,
|
||||
h3x=0,h3y=h3,h3z=0,dx=0,dy=0,dz=d/2;
|
||||
|
||||
r=Mat4x4IdentNew;
|
||||
Mat4x4RotZ(r,az*ã/180.0);
|
||||
Mat4x4RotY(r,ay*ã/180.0);
|
||||
Mat4x4RotX(r,ax*ã/180.0);
|
||||
Mat4x4MulXYZ(r,&wx,&wy,&wz);
|
||||
Mat4x4MulXYZ(r,&hx,&hy,&hz);
|
||||
Mat4x4MulXYZ(r,&h2x,&h2y,&h2z);
|
||||
Mat4x4MulXYZ(r,&h3x,&h3y,&h3z);
|
||||
Mat4x4MulXYZ(r,&dx,&dy,&dz);
|
||||
|
||||
p1a=AddVertex(md,x1+dx -wx+h2x,y1+dy -wy+h2y,z1+dz -wz+h2z);
|
||||
p2a=AddVertex(md,x1+dx +wx+h2x,y1+dy +wy+h2y,z1+dz +wz+h2z);
|
||||
p3a=AddVertex(md,x1+dx+hx-wx ,y1+dy+hy-wy ,z1+dz+hz-wz);
|
||||
p4a=AddVertex(md,x1+dx+hx+wx ,y1+dy+hy+wy ,z1+dz+hz+wz);
|
||||
AddTri(md,c,p1a,p2a,p3a);
|
||||
AddTri(md,c,p4a,p3a,p2a);
|
||||
|
||||
p1b=AddVertex(md,x1-dx -wx+h2x,y1-dy -wy+h2y,z1-dz -wz+h2z);
|
||||
p2b=AddVertex(md,x1-dx +wx+h2x,y1-dy +wy+h2y,z1-dz +wz+h2z);
|
||||
p3b=AddVertex(md,x1-dx+hx-wx ,y1-dy+hy-wy ,z1-dz+hz-wz);
|
||||
p4b=AddVertex(md,x1-dx+hx+wx ,y1-dy+hy+wy ,z1-dz+hz+wz);
|
||||
AddTri(md,c,p1b,p2b,p3b);
|
||||
AddTri(md,c,p4b,p3b,p2b);
|
||||
|
||||
AddTri(md,c,p1a,p2a,p1b);
|
||||
AddTri(md,c,p2b,p1b,p2a);
|
||||
AddTri(md,c,p3a,p4a,p3b);
|
||||
AddTri(md,c,p4b,p3b,p4a);
|
||||
AddTri(md,c,p1a,p3a,p1b);
|
||||
AddTri(md,c,p3b,p1b,p3a);
|
||||
AddTri(md,c,p2a,p4a,p2b);
|
||||
AddTri(md,c,p4b,p2b,p4a);
|
||||
|
||||
*ox=x1+hx-h3x;
|
||||
*oy=y1+hy-h3y;
|
||||
*oz=z1+hz-h3z;
|
||||
|
||||
Free(r);
|
||||
}
|
||||
|
||||
U8 *Man2CSprite()
|
||||
{
|
||||
//See $LK,"::/Adam/Gr/GrSpritePlot.HC",A="FL:::/Adam/Gr/GrSpritePlot.HC,1"$ for how CSprite are stored.
|
||||
U8 *res=MAlloc(sizeof(CSpriteMeshU8s)+
|
||||
m->vertex_cnt*sizeof(CD3I32)+m->tri_cnt*sizeof(CMeshTri)+
|
||||
sprite_elem_base_sizes[SPT_END]),
|
||||
*dst=res;
|
||||
*dst++ =SPT_MESH;
|
||||
*dst(I32 *)++ =m->vertex_cnt;
|
||||
*dst(I32 *)++ =m->tri_cnt;
|
||||
MemCpy(dst,&m->v,m->vertex_cnt*sizeof(CD3I32));
|
||||
dst+=m->vertex_cnt*sizeof(CD3I32);
|
||||
MemCpy(dst,&m->t,m->tri_cnt*sizeof(CMeshTri));
|
||||
dst+=m->tri_cnt*sizeof(CMeshTri);
|
||||
*dst++ =SPT_END;
|
||||
return res;
|
||||
}
|
||||
|
||||
public U8 *ManGen()
|
||||
{
|
||||
U8 *res;
|
||||
I64 x,y,z,c1,c2,c3,c4;
|
||||
ManDefineStruct md1,md2;
|
||||
MDInit(&md1);
|
||||
|
||||
while (TRUE) {
|
||||
if (!DocForm(&md1))
|
||||
return NULL;
|
||||
MemCpy(&md2,&md1,sizeof(ManDefineStruct));
|
||||
MDCorrect(&md2);
|
||||
|
||||
c1=PopUpColorLighting("$$BK,1$$Shirt$$BK,0$$\n");
|
||||
if (c1<0) return NULL;
|
||||
c2=PopUpColorLighting("$$BK,1$$Pants$$BK,0$$\n");
|
||||
if (c2<0) return NULL;
|
||||
c3=PopUpColorLighting("$$BK,1$$Skin$$BK,0$$\n");
|
||||
if (c3<0) return NULL;
|
||||
c4=PopUpColorLighting("$$BK,1$$Shoes$$BK,0$$\n");
|
||||
if (c4<0) return NULL;
|
||||
|
||||
m=CAlloc(sizeof(Man));
|
||||
|
||||
//Head
|
||||
AddBox(&md2,c3,0,md2.torso_len+md2.head_rad*2,0,
|
||||
md2.head_rad*2,-md2.head_rad*2,md2.head_rad*2,0,0, 0,0,0,
|
||||
&x,&y,&z);
|
||||
|
||||
//Torso
|
||||
AddBox(&md2,c1,0,md2.torso_len,0,
|
||||
md2.torso_width,-md2.torso_len,md2.torso_depth,0,0, 0,0,0,
|
||||
&x,&y,&z);
|
||||
|
||||
//Right Arm
|
||||
AddBox(&md2,c1,-md2.torso_width/2-md2.arm_rad,md2.torso_len-md2.arm_rad,0,
|
||||
md2.arm_rad*2,-md2.arm_len/2,md2.arm_rad*2,md2.arm_rad,0,
|
||||
md2.r_shoulder_a2,0,md2.r_shoulder_a1,&x,&y,&z);
|
||||
AddBox(&md2,c3,x,y,z,
|
||||
md2.arm_rad*2,-md2.arm_len/2,md2.arm_rad*2,0,0,
|
||||
md2.r_shoulder_a2,0,md2.r_elbow_a,&x,&y,&z);
|
||||
AddBox(&md2,c3,x,y,z,
|
||||
md2.arm_rad*2,-md2.hand_len,md2.hand_rad*2,0,0,
|
||||
md2.r_shoulder_a2,0,md2.r_wrist_a,&x,&y,&z);
|
||||
|
||||
//Left Arm
|
||||
AddBox(&md2,c1,md2.torso_width/2+md2.arm_rad,md2.torso_len-md2.arm_rad,0,
|
||||
md2.arm_rad*2,-md2.arm_len/2,md2.arm_rad*2,md2.arm_rad,0,
|
||||
md2.l_shoulder_a2,0,md2.l_shoulder_a1,&x,&y,&z);
|
||||
AddBox(&md2,c3,x,y,z,
|
||||
md2.arm_rad*2,-md2.arm_len/2,md2.arm_rad*2,0,0,
|
||||
md2.l_shoulder_a2,0,md2.l_elbow_a,&x,&y,&z);
|
||||
AddBox(&md2,c3,x,y,z,
|
||||
md2.arm_rad*2,-md2.hand_len,md2.hand_rad*2,0,0,
|
||||
md2.l_shoulder_a2,0,md2.l_wrist_a,&x,&y,&z);
|
||||
|
||||
//Right Leg
|
||||
AddBox(&md2,c2,-md2.torso_width/2+md2.leg_rad,0,0,
|
||||
md2.leg_rad*2,-md2.leg_len/2,md2.leg_rad*2,0,0,
|
||||
md2.r_hip_a2,0,md2.r_hip_a1,&x,&y,&z);
|
||||
AddBox(&md2,c3,x,y,z,
|
||||
md2.leg_rad*2,-md2.leg_len/2,md2.leg_rad*2,0,md2.foot_rad,
|
||||
md2.r_hip_a2,0,md2.r_knee_a,&x,&y,&z);
|
||||
AddBox(&md2,c4,x,y,z,
|
||||
md2.leg_rad*2,-md2.foot_len,md2.foot_rad*2,md2.leg_rad,0,
|
||||
md2.r_hip_a2,0,md2.r_ankle_a,&x,&y,&z);
|
||||
|
||||
//Left Leg
|
||||
AddBox(&md2,c2,md2.torso_width/2-md2.leg_rad,0,0,
|
||||
md2.leg_rad*2,-md2.leg_len/2,md2.leg_rad*2,0,0,
|
||||
md2.l_hip_a2,0,md2.l_hip_a1,&x,&y,&z);
|
||||
AddBox(&md2,c3,x,y,z,
|
||||
md2.leg_rad*2,-md2.leg_len/2,md2.leg_rad*2,0,md2.foot_rad,
|
||||
md2.l_hip_a2,0,md2.l_knee_a,&x,&y,&z);
|
||||
AddBox(&md2,c4,x,y,z,
|
||||
md2.leg_rad*2,-md2.foot_len,md2.foot_rad*2,md2.leg_rad,0,
|
||||
md2.l_hip_a2,0,md2.l_ankle_a,&x,&y,&z);
|
||||
|
||||
res=Man2CSprite;
|
||||
"%h7c",'\n';
|
||||
Sprite(res,"\t\t$$SP,\"<1>\",BI=%d$$");
|
||||
"%h7c",'\n';
|
||||
Free(m);
|
||||
"Do another";
|
||||
if (YorN)
|
||||
Free(res);
|
||||
else
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#define T_MAN 0
|
||||
#define T_BALL 1
|
||||
|
||||
U0 Models()
|
||||
{
|
||||
I64 i;
|
||||
Bool old_form=LBts(&(DocPut)->flags,DOCf_FORM);
|
||||
DocClear;
|
||||
"Make a CSprite model. Then, cut-and-Paste it.\n\n";
|
||||
"$$LM,4$$";
|
||||
"\n\n$$BT,\"Man\",LE=T_MAN$$\n\n";
|
||||
"\n\n$$BT,\"Ball\",LE=T_BALL$$\n\n";
|
||||
"$$LM,0$$";
|
||||
i=DocMenu(DocPut);
|
||||
LBEqu(&(DocPut)->flags,DOCf_FORM,old_form);
|
||||
DocBottom;
|
||||
switch (i) {
|
||||
case T_MAN:
|
||||
ManGen;
|
||||
break;
|
||||
case T_BALL:
|
||||
BallGen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
Cd(__DIR__);;
|
||||
#include "Load"
|
||||
Models;
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,6 @@
|
||||
#help_index "Games"
|
||||
|
||||
Cd(__DIR__);;
|
||||
#include "KeepAway"
|
||||
|
||||
#help_index ""
|
||||
@@ -0,0 +1,3 @@
|
||||
Cd(__DIR__);;
|
||||
#include "Load"
|
||||
KeepAway;
|
||||
@@ -0,0 +1,6 @@
|
||||
#help_index "Misc"
|
||||
|
||||
Cd(__DIR__);;
|
||||
#include "Logic"
|
||||
|
||||
#help_index ""
|
||||
@@ -0,0 +1,592 @@
|
||||
#define TABLE_SIZE_MAX 0x10000
|
||||
|
||||
I64 output_found,passes,table_size;
|
||||
|
||||
U8 *gate_type_table =NULL,
|
||||
*displayed_design=NULL,
|
||||
*added_this_pass =NULL;
|
||||
|
||||
U16 *input1_table=NULL,
|
||||
*input2_table=NULL,
|
||||
*input3_table=NULL;
|
||||
|
||||
#define CONNECT_WIDTH 16
|
||||
#define GATE_WIDTH 37
|
||||
|
||||
$ID,6$
|
||||
$SP,"",BI=1$
|
||||
|
||||
|
||||
$SP,"",BI=2$
|
||||
|
||||
|
||||
$SP,"",BI=3$
|
||||
|
||||
|
||||
$SP,"",BI=4$
|
||||
|
||||
|
||||
$SP,"",BI=5$
|
||||
|
||||
|
||||
$SP,"",BI=6$
|
||||
|
||||
|
||||
$SP,"",BI=7$
|
||||
|
||||
|
||||
|
||||
$SP,"",BI=8$
|
||||
|
||||
|
||||
|
||||
$SP,"",BI=9$
|
||||
|
||||
|
||||
|
||||
$SP,"",BI=10$
|
||||
|
||||
$ID,-6$
|
||||
U8 *gate_type_lst="NULL\0OUTPUT\0INPUT\0"
|
||||
"NOT\0AND\0OR\0NAND\0NOR\0XOR\0AND3\0OR3\0NAND3\0NOR3\0";
|
||||
|
||||
#define GT_NULL 0 //Specifies that table entry has not been filled-in
|
||||
#define GT_OUTPUT 1 //Specifies the table entry is a desired output
|
||||
#define GT_INPUT 2 //Specifies that table entry comes from an input signal
|
||||
|
||||
#define GT_FIRST_REAL_GATE 3
|
||||
#define GT_NOT 3
|
||||
#define GT_AND 4
|
||||
#define GT_OR 5
|
||||
#define GT_NAND 6
|
||||
#define GT_NOR 7
|
||||
#define GT_XOR 8
|
||||
#define GT_AND3 9
|
||||
#define GT_OR3 10
|
||||
#define GT_NAND3 11
|
||||
#define GT_NOR3 12
|
||||
#define GT_ENTRIES_NUM 13
|
||||
|
||||
#define SEL_GATES_NUM 128
|
||||
|
||||
U8 *imgs[GT_ENTRIES_NUM]={NULL,NULL,NULL,
|
||||
$IB,"<NOT>",BI=1$,$IB,"<AND>",BI=2$,$IB,"<OR>",BI=3$,$IB,"<NAND>",BI=4$,$IB,"<NOR>",BI=5$,$IB,"<XOR>",BI=6$,$IB,"<AND3>",BI=7$,$IB,"<OR3>",BI=8$,$IB,"<NAND3>",BI=9$,$IB,"<NOR3>",BI=10$};
|
||||
|
||||
I64 num_inputs_entered,num_outputs_entered;
|
||||
I64 num_sel_gates,
|
||||
sel_gates[SEL_GATES_NUM];
|
||||
|
||||
U0 GetGates()
|
||||
{
|
||||
I64 i;
|
||||
U8 *st;
|
||||
|
||||
"\nEnter the available gate types in the order you prefer them to be used.\n"
|
||||
"Your choices are:\n";
|
||||
for (i=GT_FIRST_REAL_GATE;i<GT_ENTRIES_NUM;i++)
|
||||
"%z ",i,gate_type_lst;
|
||||
'\n';
|
||||
|
||||
num_sel_gates=0;
|
||||
while (num_sel_gates<GT_ENTRIES_NUM) {
|
||||
"%d",num_sel_gates;
|
||||
st=GetStr(" Gate: ");
|
||||
if (!*st) {
|
||||
Free(st);
|
||||
return;
|
||||
}
|
||||
i=LstMatch(st,gate_type_lst,LMF_IGNORE_CASE);
|
||||
Free(st);
|
||||
if (i<GT_FIRST_REAL_GATE)
|
||||
"Invalid response\n";
|
||||
else
|
||||
sel_gates[num_sel_gates++]=i;
|
||||
}
|
||||
}
|
||||
|
||||
U0 Init()
|
||||
{
|
||||
I64 i;
|
||||
|
||||
do {
|
||||
table_size=GetI64("\nTable size in hex (3 input=0x100,4=0x10000): ",0);
|
||||
if (table_size>TABLE_SIZE_MAX)
|
||||
"Too large\n";
|
||||
else if (table_size<1) {
|
||||
"No table specified, aborting.\n";
|
||||
throw;
|
||||
}
|
||||
} while (table_size>TABLE_SIZE_MAX);
|
||||
|
||||
gate_type_table =CAlloc(table_size*sizeof(U8));
|
||||
displayed_design=MAlloc((table_size+7)/8);
|
||||
added_this_pass =MAlloc((table_size+7)/8);
|
||||
input1_table =MAlloc(table_size*sizeof(U16));
|
||||
input2_table =MAlloc(table_size*sizeof(U16));
|
||||
input3_table =MAlloc(table_size*sizeof(U16));
|
||||
|
||||
"\nEnter the hex truth table column values of inputs.\n";
|
||||
if (table_size<=0x100)
|
||||
"For example, enter A=0xF0, B=0xCC and C=0xAA.\n";
|
||||
else
|
||||
"For example, enter A=0xFF00, B=0xF0F0, C=0xCCCC and D=0xAAAA.\n";
|
||||
num_inputs_entered=0;
|
||||
while (TRUE) {
|
||||
"Input %C: ",'A'+num_inputs_entered;
|
||||
i=GetI64("",-1);
|
||||
if (i<0) break;
|
||||
if (i>table_size)
|
||||
"Too large\n";
|
||||
else {
|
||||
if (gate_type_table[i])
|
||||
"Duplicate\n";
|
||||
else {
|
||||
gate_type_table[i]=GT_INPUT;
|
||||
input1_table[i]=num_inputs_entered++;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!num_inputs_entered) {
|
||||
"No inputs specified, aborting.\n";
|
||||
throw;
|
||||
}
|
||||
|
||||
"\nEnter the hex truth table columns values of the outputs.\n";
|
||||
num_outputs_entered=0;
|
||||
while (TRUE) {
|
||||
"Output %C: ",'A'+num_outputs_entered;
|
||||
i=GetI64("",-1);
|
||||
if (i<0) break;
|
||||
if (i>table_size)
|
||||
"Too large\n";
|
||||
else {
|
||||
if (gate_type_table[i]==GT_INPUT)
|
||||
"To produce this output, connect to input %C\n",
|
||||
'A'+input1_table[i];
|
||||
else if (gate_type_table[i]==GT_OUTPUT)
|
||||
"Duplicate\n";
|
||||
else {
|
||||
gate_type_table[i]=GT_OUTPUT;
|
||||
input1_table[i]=num_outputs_entered++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!num_outputs_entered) {
|
||||
"No output specified, aborting.\n";
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
U0 DrawDesign(CDC *dc,I64 *_y,I64 output,I64 depth,I64 *_x_out,I64 *_y_out)
|
||||
{
|
||||
I64 y=*_y,type=gate_type_table[output],
|
||||
xx=(passes-depth)*(GATE_WIDTH+CONNECT_WIDTH),yy=y,
|
||||
x1,y1,x2,y2,x3,y3;
|
||||
if (_x_out) *_x_out=xx;
|
||||
if (_y_out) *_y_out=yy;
|
||||
if (Bt(displayed_design,output) && type!=GT_INPUT) {
|
||||
dc->color=GREEN;
|
||||
GrPrint(dc,xx-FONT_WIDTH*3,y-4,"Dup");
|
||||
y+=10;
|
||||
} else
|
||||
switch (type) {
|
||||
case GT_INPUT:
|
||||
dc->color=GREEN;
|
||||
GrPrint(dc,xx-FONT_WIDTH-4,y-4,"%C",'A'+input1_table[output]);
|
||||
y+=10;
|
||||
break;
|
||||
case GT_NOT:
|
||||
if (!Bt(displayed_design,output)) {
|
||||
y+=16;
|
||||
DrawDesign(dc,&y,input1_table[output],depth+1,&x1,&y1);
|
||||
yy=y1;
|
||||
|
||||
dc->color=BLUE;
|
||||
Sprite3(dc,xx,yy,0,imgs[type]);
|
||||
|
||||
dc->color=RED;
|
||||
GrLine(dc,xx-GATE_WIDTH,yy,x1,y1);
|
||||
if (_y_out) *_y_out=yy;
|
||||
}
|
||||
break;
|
||||
case GT_AND:
|
||||
case GT_OR:
|
||||
case GT_NAND:
|
||||
case GT_NOR:
|
||||
case GT_XOR:
|
||||
if (!Bt(displayed_design,output)) {
|
||||
y+=24;
|
||||
DrawDesign(dc,&y,input1_table[output],depth+1,&x1,&y1);
|
||||
DrawDesign(dc,&y,input2_table[output],depth+1,&x2,&y2);
|
||||
yy=(y1+y2)/2;
|
||||
|
||||
dc->color=BLUE;
|
||||
Sprite3(dc,xx,yy,0,imgs[type]);
|
||||
|
||||
dc->color=RED;
|
||||
GrLine(dc,xx-GATE_WIDTH,yy-4,x1,y1);
|
||||
GrLine(dc,xx-GATE_WIDTH,yy+4,x2,y2);
|
||||
if (_y_out) *_y_out=yy;
|
||||
}
|
||||
break;
|
||||
case GT_AND3:
|
||||
case GT_OR3:
|
||||
case GT_NAND3:
|
||||
case GT_NOR3:
|
||||
if (!Bt(displayed_design,output)) {
|
||||
y+=32;
|
||||
DrawDesign(dc,&y,input1_table[output],depth+1,&x1,&y1);
|
||||
DrawDesign(dc,&y,input2_table[output],depth+1,&x2,&y2);
|
||||
DrawDesign(dc,&y,input3_table[output],depth+1,&x3,&y3);
|
||||
yy=(y1+y2+y3)/3;
|
||||
|
||||
dc->color=BLUE;
|
||||
Sprite3(dc,xx,yy,0,imgs[type]);
|
||||
|
||||
dc->color=RED;
|
||||
GrLine(dc,xx-GATE_WIDTH,yy-8,x1,y1);
|
||||
GrLine(dc,xx-GATE_WIDTH,yy ,x2,y2);
|
||||
GrLine(dc,xx-GATE_WIDTH,yy+8,x3,y3);
|
||||
if (_y_out) *_y_out=yy;
|
||||
}
|
||||
break;
|
||||
}
|
||||
dc->color=BLACK;
|
||||
GrPrint(dc,xx,yy+3,"%04X",output);
|
||||
Bts(displayed_design,output);
|
||||
if (_y) *_y=y;
|
||||
}
|
||||
|
||||
U0 DrawIt(CTask *,CDC *dc)
|
||||
{
|
||||
I64 y=0;
|
||||
MemSet(displayed_design,0,(table_size+7)/8*sizeof(Bool));
|
||||
DrawDesign(dc,&y,output_found,0,NULL,NULL);
|
||||
}
|
||||
|
||||
U0 FillNot(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i)) {
|
||||
progress1=i;
|
||||
j= (~i) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_NOT;
|
||||
input1_table[j]=i;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FillAnd(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,k,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i))
|
||||
for (k=0;k<table_size;k++)
|
||||
if (gate_type_table[k]>GT_OUTPUT && !Bt(added_this_pass,k)) {
|
||||
progress1=i;
|
||||
j= (i & k) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_AND;
|
||||
input1_table[j]=i;
|
||||
input2_table[j]=k;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FillOr(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,k,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i))
|
||||
for (k=0;k<table_size;k++)
|
||||
if (gate_type_table[k]>GT_OUTPUT && !Bt(added_this_pass,k)) {
|
||||
progress1=i;
|
||||
j= (i | k) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_OR;
|
||||
input1_table[j]=i;
|
||||
input2_table[j]=k;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FillNAnd(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,k,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i))
|
||||
for (k=0;k<table_size;k++)
|
||||
if (gate_type_table[k]>GT_OUTPUT && !Bt(added_this_pass,k)) {
|
||||
progress1=i;
|
||||
j= (~ (i & k)) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_NAND;
|
||||
input1_table[j]=i;
|
||||
input2_table[j]=k;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FillNOr(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,k,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i))
|
||||
for (k=0;k<table_size;k++)
|
||||
if (gate_type_table[k]>GT_OUTPUT && !Bt(added_this_pass,k)) {
|
||||
progress1=i;
|
||||
j= (~ (i | k)) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_NOR;
|
||||
input1_table[j]=i;
|
||||
input2_table[j]=k;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FillXor(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,k,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i))
|
||||
for (k=0;k<table_size;k++)
|
||||
if (gate_type_table[k]>GT_OUTPUT && !Bt(added_this_pass,k)) {
|
||||
progress1=i;
|
||||
j= (i ^ k) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_XOR;
|
||||
input1_table[j]=i;
|
||||
input2_table[j]=k;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FillAnd3(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,k,l,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i))
|
||||
for (k=0;k<table_size;k++)
|
||||
if (gate_type_table[k]>GT_OUTPUT && !Bt(added_this_pass,k))
|
||||
for (l=0;l<table_size;l++)
|
||||
if (gate_type_table[l]>GT_OUTPUT && !Bt(added_this_pass,l)) {
|
||||
progress1=i;
|
||||
j= (i & k & l) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_AND3;
|
||||
input1_table[j]=i;
|
||||
input2_table[j]=k;
|
||||
input3_table[j]=l;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FillOr3(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,k,l,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i))
|
||||
for (k=0;k<table_size;k++)
|
||||
if (gate_type_table[k]>GT_OUTPUT && !Bt(added_this_pass,k))
|
||||
for (l=0;l<table_size;l++)
|
||||
if (gate_type_table[l]>GT_OUTPUT && !Bt(added_this_pass,l)) {
|
||||
progress1=i;
|
||||
j= (i | k | l) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_OR3;
|
||||
input1_table[j]=i;
|
||||
input2_table[j]=k;
|
||||
input3_table[j]=l;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FillNAnd3(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,k,l,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i))
|
||||
for (k=0;k<table_size;k++)
|
||||
if (gate_type_table[k]>GT_OUTPUT && !Bt(added_this_pass,k))
|
||||
for (l=0;l<table_size;l++)
|
||||
if (gate_type_table[l]>GT_OUTPUT && !Bt(added_this_pass,l)) {
|
||||
progress1=i;
|
||||
j= (~(i & k & l)) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_NAND3;
|
||||
input1_table[j]=i;
|
||||
input2_table[j]=k;
|
||||
input3_table[j]=l;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
U0 FillNOr3(Bool *chged,I64 *num_outputs_found)
|
||||
{
|
||||
I64 i,j,k,l,old_type;
|
||||
for (i=0;i<table_size;i++)
|
||||
if (gate_type_table[i]>GT_OUTPUT && !Bt(added_this_pass,i))
|
||||
for (k=0;k<table_size;k++)
|
||||
if (gate_type_table[k]>GT_OUTPUT && !Bt(added_this_pass,k))
|
||||
for (l=0;l<table_size;l++)
|
||||
if (gate_type_table[l]>GT_OUTPUT && !Bt(added_this_pass,l)) {
|
||||
progress1=i;
|
||||
j= (~(i | k | l)) & (table_size-1);
|
||||
old_type=gate_type_table[j];
|
||||
if (old_type<GT_INPUT) {
|
||||
gate_type_table[j]=GT_NOR3;
|
||||
input1_table[j]=i;
|
||||
input2_table[j]=k;
|
||||
input3_table[j]=l;
|
||||
Bts(added_this_pass,j);
|
||||
*chged=TRUE;
|
||||
if (old_type==GT_OUTPUT) {
|
||||
if (output_found<0) output_found=j;
|
||||
*num_outputs_found=*num_outputs_found+1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
I64 FillGateTable()
|
||||
{
|
||||
I64 current_gate,num_outputs_found=0;
|
||||
Bool chged=TRUE;
|
||||
passes=1;
|
||||
output_found=-1;
|
||||
ProgressBarsRst;
|
||||
progress1_max=table_size;
|
||||
'\n';
|
||||
while (num_outputs_found<num_outputs_entered && chged) {
|
||||
"Pass : %d\n",passes++;
|
||||
chged=FALSE;
|
||||
MemSet(added_this_pass,0,(table_size+7)/8);
|
||||
for (current_gate=0;current_gate<num_sel_gates &&
|
||||
num_outputs_found<num_outputs_entered;current_gate++) {
|
||||
switch (sel_gates[current_gate]) {
|
||||
case GT_NOT: FillNot (&chged,&num_outputs_found); break;
|
||||
case GT_AND: FillAnd (&chged,&num_outputs_found); break;
|
||||
case GT_OR: FillOr (&chged,&num_outputs_found); break;
|
||||
case GT_NAND: FillNAnd (&chged,&num_outputs_found); break;
|
||||
case GT_NOR: FillNOr (&chged,&num_outputs_found); break;
|
||||
case GT_XOR: FillXor (&chged,&num_outputs_found); break;
|
||||
case GT_AND3: FillAnd3 (&chged,&num_outputs_found); break;
|
||||
case GT_OR3: FillOr3 (&chged,&num_outputs_found); break;
|
||||
case GT_NAND3: FillNAnd3(&chged,&num_outputs_found); break;
|
||||
case GT_NOR3: FillNOr3 (&chged,&num_outputs_found); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ProgressBarsRst;
|
||||
return num_outputs_found;
|
||||
}
|
||||
|
||||
U0 CleanUp()
|
||||
{
|
||||
Free(gate_type_table);
|
||||
Free(displayed_design);
|
||||
Free(added_this_pass);
|
||||
Free(input1_table);
|
||||
Free(input2_table);
|
||||
Free(input3_table);
|
||||
}
|
||||
|
||||
U0 DigitalLogic()
|
||||
{
|
||||
gate_type_table =NULL;
|
||||
displayed_design=NULL;
|
||||
added_this_pass =NULL;
|
||||
input1_table =NULL;
|
||||
input2_table =NULL;
|
||||
input3_table =NULL;
|
||||
|
||||
SettingsPush; //See $LK,"SettingsPush",A="MN:SettingsPush"$
|
||||
AutoComplete;
|
||||
WinBorder(ON);
|
||||
WinMax;
|
||||
DocClear;
|
||||
GetGates;
|
||||
try {
|
||||
Init;
|
||||
if (FillGateTable) {
|
||||
DocCursor;
|
||||
DocClear;
|
||||
Fs->draw_it=&DrawIt;
|
||||
GetChar;
|
||||
DocClear;
|
||||
Refresh(2,TRUE);
|
||||
DocBottom;
|
||||
}
|
||||
} catch
|
||||
PutExcept;
|
||||
SettingsPop;
|
||||
CleanUp;
|
||||
}
|
||||
| ||||