// Source: D:\TempleOS-Projects\html\BgtMain-Budget-Apps.html
// Date: unknown-date
// Language: HolyC

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(U8 *dirname="~/Budget")
{
  CDoc *pdoc,*ddoc,*old_put,*old_display;

  Cd(dirname);
  bgt_string_file       =FileNameAbs("Strs.DD.Z");
  bgt_accts_file        =FileNameAbs("Accts.DD.Z");
  bgt_data_file         =FileNameAbs("Bgt.DATA.Z");

  BgtAcctsRead;
  BgtDataRead;
  CBgtTemplatesExpand;
  SettingsPush; //See 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;
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\BgtMain-Budget-Apps.html
// Date: unknown-date
// Language: HolyC

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(U8 *dirname="~/Budget")
{
  CDoc *pdoc,*ddoc,*old_put,*old_display;

  Cd(dirname);
  bgt_string_file       =FileNameAbs("Strs.DD.Z");
  bgt_accts_file        =FileNameAbs("Accts.DD.Z");
  bgt_data_file         =FileNameAbs("Bgt.DATA.Z");

  BgtAcctsRead;
  BgtDataRead;
  CBgtTemplatesExpand;
  SettingsPush; //See 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;
}


// Source: D:\TempleOS-Projects\html\CvtSprite300-Sup1-Sup1Utils-Home.html
// Date: unknown-date
// Language: HolyC

I64 CvtSprite300Sprite(U8 *elems)
{
  I64 res=0,size;
  CSprite *tmpg=elems-offset(CSprite.start);
  while (tmpg->type) {
    size=SpriteElemSize(tmpg);
    if (tmpg->type==SPT_ELLIPSE||
          tmpg->type==SPT_POLYGON||
          tmpg->type==SPT_BITMAP) {
      "IN :W%d H%d (%d,%d)\n",
            tmpg->pwhu.width,tmpg->pwhu.height,tmpg->pwhu.x1,tmpg->pwhu.y1;
      SwapU32(&tmpg->pwhu.x1,&tmpg->pwhu.width);
      SwapU32(&tmpg->pwhu.y1,&tmpg->pwhu.height);
      "OUT:(%d,%d) W%d H%d\n",
            tmpg->pwhu.width,tmpg->pwhu.height,tmpg->pwhu.x1,tmpg->pwhu.y1;
      res++;
    }
    tmpg(U8 *)+=size;
  }
  return res;
}

I64 CvtSprite300Doc(CDoc *doc)
{
  Bool unlock=DocLock(doc);
  CDocBin *b;
  I64 res=0;
  DocRecalc(doc);
  b=doc->bin_head.next;
  while (b!=&doc->bin_head) {
    res+=CvtSprite300Sprite(b->data);
    b=b->next;
  }
  DocRecalc(doc);
  if (unlock)
    DocUnlock(doc);
  return res;
}

I64 CvtSprite300File(U8 *filename)
{
  I64 res;
  CDoc *doc=DocRead(filename);
  if (res=CvtSprite300Doc(doc)) {
    "-%d:%s\n",res,doc->filename.name;
    DocWrite(doc);
  }
  DocDel(doc);
  return res;
}
I64 CvtSprite300Lst(CDirEntry *tmpde)
{
  I64 res=0;
  CDirEntry *tmpde1;
  while (tmpde) {
    tmpde1=tmpde->next;
    if (tmpde->attr & RS_ATTR_DIR) {
      if (tmpde->sub) {
        "Scanning Directory: %s\n",tmpde->full_name;
        res+=CvtSprite300Lst(tmpde->sub);
      }
    } else
      res+=CvtSprite300File(tmpde->full_name);
    DirEntryDel(tmpde);
    tmpde=tmpde1;
  }
  return res;
}
public I64 CvtSprite300(U8 *files_find_mask="*",U8 *fu_flags=NULL)
{
  I64 f=0;
  ScanFlags(&f,Define("ST_FILE_UTIL_FLAGS"),"+r+$");
  ScanFlags(&f,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  return CvtSprite300Lst(FilesFind(files_find_mask,f));
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\CvtSprite300-Sup1-Sup1Utils-Home.html
// Date: unknown-date
// Language: HolyC

I64 CvtSprite300Sprite(U8 *elems)
{
  I64 res=0,size;
  CSprite *tmpg=elems-offset(CSprite.start);
  while (tmpg->type) {
    size=SpriteElemSize(tmpg);
    if (tmpg->type==SPT_ELLIPSE||
          tmpg->type==SPT_POLYGON||
          tmpg->type==SPT_BITMAP) {
      "IN :W%d H%d (%d,%d)\n",
            tmpg->pwhu.width,tmpg->pwhu.height,tmpg->pwhu.x1,tmpg->pwhu.y1;
      SwapU32(&tmpg->pwhu.x1,&tmpg->pwhu.width);
      SwapU32(&tmpg->pwhu.y1,&tmpg->pwhu.height);
      "OUT:(%d,%d) W%d H%d\n",
            tmpg->pwhu.width,tmpg->pwhu.height,tmpg->pwhu.x1,tmpg->pwhu.y1;
      res++;
    }
    tmpg(U8 *)+=size;
  }
  return res;
}

I64 CvtSprite300Doc(CDoc *doc)
{
  Bool unlock=DocLock(doc);
  CDocBin *b;
  I64 res=0;
  DocRecalc(doc);
  b=doc->bin_head.next;
  while (b!=&doc->bin_head) {
    res+=CvtSprite300Sprite(b->data);
    b=b->next;
  }
  DocRecalc(doc);
  if (unlock)
    DocUnlock(doc);
  return res;
}

I64 CvtSprite300File(U8 *filename)
{
  I64 res;
  CDoc *doc=DocRead(filename);
  if (res=CvtSprite300Doc(doc)) {
    "-%d:%s\n",res,doc->filename.name;
    DocWrite(doc);
  }
  DocDel(doc);
  return res;
}
I64 CvtSprite300Lst(CDirEntry *tmpde)
{
  I64 res=0;
  CDirEntry *tmpde1;
  while (tmpde) {
    tmpde1=tmpde->next;
    if (tmpde->attr & RS_ATTR_DIR) {
      if (tmpde->sub) {
        "Scanning Directory: %s\n",tmpde->full_name;
        res+=CvtSprite300Lst(tmpde->sub);
      }
    } else
      res+=CvtSprite300File(tmpde->full_name);
    DirEntryDel(tmpde);
    tmpde=tmpde1;
  }
  return res;
}
public I64 CvtSprite300(U8 *files_find_mask="*",U8 *fu_flags=NULL)
{
  I64 f=0;
  ScanFlags(&f,Define("ST_FILE_UTIL_FLAGS"),"+r+$");
  ScanFlags(&f,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  return CvtSprite300Lst(FilesFind(files_find_mask,f));
}


// Source: D:\TempleOS-Projects\html\KDefine-Kernel.html
// Date: unknown-date
// Language: HolyC

CHashDefineStr *DefineLoad(U8 *dname,U8 *st)
{//Create DEFINE hash entry with string.
  CHashDefineStr *tmph=CAlloc(sizeof(CHashDefineStr));
  tmph->type=HTT_DEFINE_STR;
  tmph->str=StrNew(dname);
  tmph->data=StrNew(st);
  tmph->cnt=-1;
  tmph->src_link=MStrPrint("AD:0x%X",Caller);
  HashAdd(tmph,Fs->hash_table);
  return tmph;
}

CHashDefineStr *DefineLstLoad(U8 *dname,U8 *lst)
{//Create DEFINE list. Not efficient, but handy.
  I64 cnt=0;
  U8 *ptr,**idx;
  CHashDefineStr *tmph=CAlloc(sizeof(CHashDefineStr));
  tmph->type=HTT_DEFINE_STR;
  tmph->str=StrNew(dname);
  tmph->src_link=MStrPrint("AD:0x%X",Caller);
  ptr=lst;
  while (*ptr) {
    if (*ptr!='@')
      cnt++;
    while (*ptr++);
  }
  tmph->data=MAlloc(ptr+1-lst);
  MemCpy(tmph->data,lst,ptr+1-lst);
  tmph->cnt=cnt;

  idx=tmph->sub_idx=MAlloc(cnt*sizeof(U8 *));
  ptr=lst;
  while (*ptr) {
    if (*ptr!='@')
      *idx++=ptr;
    while (*ptr++);
  }

  HashAdd(tmph,Fs->hash_table);
  return tmph;
}

U0 UndefinedDefine(U8 *dname)
{
  ST_ERR_ST "Undefined Define: '%s'.\n",dname;
  throw('UndefDef');
}

U8 *Define(U8 *dname)
{//Look for DEFINE named in hash table, return ptr string.
  CHashDefineStr *tmph;
  if (tmph=HashFind(dname,Fs->hash_table,HTT_DEFINE_STR))
    return tmph->data;
  else if (dname)
    UndefinedDefine(dname);
  else
    return NULL;
}

U8 *DefineSub(I64 sub,U8 *dname)
{//Return DEFINE list entry indexed by number.
  CHashDefineStr *tmph;
  if (tmph=HashFind(dname,Fs->hash_table,HTT_DEFINE_STR)) {
    if (0<=sub<tmph->cnt)
      return tmph->sub_idx[sub];
    else
      return NULL;
  } else if (dname)
    UndefinedDefine(dname);
  else
    return NULL;
}

I64 DefineCnt(U8 *dname)
{//Return cnt of entries in define list.
  CHashDefineStr *tmph;
  if (tmph=HashFind(dname,Fs->hash_table,HTT_DEFINE_STR))
    return tmph->cnt;
  else if (dname)
    UndefinedDefine(dname);
  else
    return -1;
}

I64 DefineMatch(U8 *needle,U8 *haystack_lst_dname,I64 flags=0)
{//Find match for string in define list.
  return LstMatch(needle,Define(haystack_lst_dname),flags);
}

U0 DefinePrint(U8 *dname,U8 *src,...)
{//Create DEFINE entry with Print()ed string.
  U8 *buf=StrPrintJoin(NULL,src,argc,argv);
  DefineLoad(dname,buf);
  Free(buf);
}

U0 SysDefinesLoad()
{
  DefineLstLoad("ST_OFF_ON","Off\0On\0");
  DefineLstLoad("ST_HTT_TYPES","ExportSysSym\0ImportSysSym\0DefineStr\0GlbVar\0"
        "Class\0IntType\0Funct\0Word\0DictWord\0KeyWord\0AsmKeyWord\0OpCode\0"
        "Reg\0File\0Module\0HelpFile\0Frame Ptr\0 \0 \0 \0 \0 \0 \0Private\0"
        "Public\0Export\0Import\0Imm\0Goto\0Res\0Unres\0Local\0");
  DefineLstLoad("ST_DAYS_OF_WEEK","Sunday\0Monday\0Tuesday\0Wednesday\0"
        "Thursday\0Friday\0Saturday\0");
  DefineLstLoad("ST_MONTHS","January\0February\0March\0April\0May\0"
        "June\0July\0August\0September\0October\0November\0December\0");
  DefineLstLoad("ST_FILE_ATTRS","R\0H\0S\0V\0D\0A\0 \0 \0X\0T\0Z\0C\0F\0");
  DefineLstLoad("ST_FILE_UTIL_FLAGS","r\0d\0i\0a\0c\0R\0p\0m\0x\0s\0"
        "D\0F\0T\0$\0S\0A\0J\0G\0Z\0O\0P\0f\0l\0lb\0la\0");
  DefineLstLoad("ST_BLKDEV_TYPES",
        "NULL\0RAM\0ATA\0FILE_READ\0FILE_WRITE\0ATAPI\0");
  DefineLstLoad("ST_DRV_TYPES",
        "NULL\0REDSEA\0FAT32\0ISO9660\0ISO13490\0ISO13346\0NTFS\0UNKNOWN\0");
  DefineLstLoad("ST_COLORS","BLACK\0BLUE\0GREEN\0CYAN\0"
        "RED\0PURPLE\0BROWN\0LTGRAY\0DKGRAY\0LTBLUE\0LTGREEN\0"
        "LTCYAN\0LTRED\0LTPURPLE\0YELLOW\0WHITE\0");
  DefineLstLoad("ST_INT_NAMES","Divide Error\0SingleStep\0NMI\0Breakpoint\0"
        "Overflow\0BOUND Range Exceeded\0Invalid Opcode\0No Math Coprocessor\0"
        "Double Fault\0Coprocessor Segment Fault\0Invalid TASK\0"
        "Segment Not Present\0Stk Segment Fault\0General Protection\0"
        "Page Fault\0 \0Math Fault\0Alignment Check\0Machine Check\0"
        "SIMD Exception\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0"
        " \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0MP Crash\0Wake\0Dbg\0");
}

U8 *Color2Str(U8 *buf,CColorROPU32 c)
{//CColorROPU32 with flags to DCLighting str.
  *buf=0;
  if (c.c0.rop&ROPBF_TWO_SIDED)
    CatPrint(buf,"TWO|");
  if (c.c0.rop&ROPBF_HALF_RANGE_COLOR)
    CatPrint(buf,"HALF|");
  if (0<=c.c0.color<16)
    CatPrint(buf,DefineSub(c.c0.color,"ST_COLORS"));
  else if (c.c0.color==TRANSPARENT)
    CatPrint(buf,"TRANSPARENT");
  else
    CatPrint(buf,"INVALID");
  if (c&ROPF_DITHER) {
    CatPrint(buf,"/");
    if (c.c1.rop&ROPBF_TWO_SIDED)
      CatPrint(buf,"TWO|");
    if (c.c1.rop&ROPBF_HALF_RANGE_COLOR)
      CatPrint(buf,"HALF|");
    if (0<=c.c1.color<16)
      CatPrint(buf,DefineSub(c.c1.color,"ST_COLORS"));
    else if (c.c1.color==TRANSPARENT)
      CatPrint(buf,"TRANSPARENT");
    else
      CatPrint(buf,"INVALID");
  }
  return buf;
}

U8 *str2color_lst="/,)}>";

CColorROPU16 Str2ColorU16(U8 *st)
{//DCLighting color str with flags to CColorROPU16.
  CColorROPU16 res=COLOR_INVALID;
  I64 i;
  U8 *ptr,*ptr2,*st2;
  if (!st) return COLOR_INVALID;
  while (TRUE) {
    if (!*st||StrOcc(str2color_lst,*st))
      return res;
    if (Bt(char_bmp_alpha,*st)) {
      ptr=st;
      while (Bt(char_bmp_alpha_numeric,*ptr))
        ptr++;
      st2=ptr2=MAlloc(ptr-st+1);
      while (st<ptr)
        *ptr2++=*st++;
      *ptr2++=0;
      if (!StrICmp(st2,"TWO"))
        res.rop|=ROPBF_TWO_SIDED;
      else if (!StrICmp(st2,"HALF"))
        res.rop|=ROPBF_HALF_RANGE_COLOR;
      else if ((i=DefineMatch(st2,"ST_COLORS",LMF_IGNORE_CASE))>=0)
        res.color=i;
      else if (!StrICmp(st2,"TRANSPARENT"))
        res.color=TRANSPARENT;
      else {
        Free(st2);
        return COLOR_INVALID;
      }
      Free(st2);
    } else if (*st=='+'||*st=='|'||Bt(char_bmp_white_space,*st))
      st++;
    else if ('0'<=*st<='9') {
      i=Str2I64(st,10,&ptr);
      if (0<=i<=0xFF) {
        res.color=i;
        st=ptr;
      } else
        return COLOR_INVALID;
    } else
      return COLOR_INVALID;
  }
}

CColorROPU32 Str2ColorU32(U8 *st)
{//DCLighting color str with flags to CColorROPU32.
  U8 *st2;
  CColorROPU32 res=0;
  if (!st) return COLOR_INVALID;
  st2=MAlloc(StrLen(st)+1);
  StrFirstRem(st,str2color_lst,st2);
  res.c0=Str2ColorU16(st2);
  if (*st) {
    res.c1=Str2ColorU16(st);
    res|=ROPF_DITHER;
  }
  if (res.c0.color==COLOR_INVALID||res.c1.color==COLOR_INVALID)
    return COLOR_INVALID;
  else
    return res;
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\KDefine-Kernel.html
// Date: unknown-date
// Language: HolyC

CHashDefineStr *DefineLoad(U8 *dname,U8 *st)
{//Create DEFINE hash entry with string.
  CHashDefineStr *tmph=CAlloc(sizeof(CHashDefineStr));
  tmph->type=HTT_DEFINE_STR;
  tmph->str=StrNew(dname);
  tmph->data=StrNew(st);
  tmph->cnt=-1;
  tmph->src_link=MStrPrint("AD:0x%X",Caller);
  HashAdd(tmph,Fs->hash_table);
  return tmph;
}

CHashDefineStr *DefineLstLoad(U8 *dname,U8 *lst)
{//Create DEFINE list. Not efficient, but handy.
  I64 cnt=0;
  U8 *ptr,**idx;
  CHashDefineStr *tmph=CAlloc(sizeof(CHashDefineStr));
  tmph->type=HTT_DEFINE_STR;
  tmph->str=StrNew(dname);
  tmph->src_link=MStrPrint("AD:0x%X",Caller);
  ptr=lst;
  while (*ptr) {
    if (*ptr!='@')
      cnt++;
    while (*ptr++);
  }
  tmph->data=MAlloc(ptr+1-lst);
  MemCpy(tmph->data,lst,ptr+1-lst);
  tmph->cnt=cnt;

  idx=tmph->sub_idx=MAlloc(cnt*sizeof(U8 *));
  ptr=lst;
  while (*ptr) {
    if (*ptr!='@')
      *idx++=ptr;
    while (*ptr++);
  }

  HashAdd(tmph,Fs->hash_table);
  return tmph;
}

U0 UndefinedDefine(U8 *dname)
{
  ST_ERR_ST "Undefined Define: '%s'.\n",dname;
  throw('UndefDef');
}

U8 *Define(U8 *dname)
{//Look for DEFINE named in hash table, return ptr string.
  CHashDefineStr *tmph;
  if (tmph=HashFind(dname,Fs->hash_table,HTT_DEFINE_STR))
    return tmph->data;
  else if (dname)
    UndefinedDefine(dname);
  else
    return NULL;
}

U8 *DefineSub(I64 sub,U8 *dname)
{//Return DEFINE list entry indexed by number.
  CHashDefineStr *tmph;
  if (tmph=HashFind(dname,Fs->hash_table,HTT_DEFINE_STR)) {
    if (0<=sub<tmph->cnt)
      return tmph->sub_idx[sub];
    else
      return NULL;
  } else if (dname)
    UndefinedDefine(dname);
  else
    return NULL;
}

I64 DefineCnt(U8 *dname)
{//Return cnt of entries in define list.
  CHashDefineStr *tmph;
  if (tmph=HashFind(dname,Fs->hash_table,HTT_DEFINE_STR))
    return tmph->cnt;
  else if (dname)
    UndefinedDefine(dname);
  else
    return -1;
}

I64 DefineMatch(U8 *needle,U8 *haystack_lst_dname,I64 flags=0)
{//Find match for string in define list.
  return LstMatch(needle,Define(haystack_lst_dname),flags);
}

U0 DefinePrint(U8 *dname,U8 *src,...)
{//Create DEFINE entry with Print()ed string.
  U8 *buf=StrPrintJoin(NULL,src,argc,argv);
  DefineLoad(dname,buf);
  Free(buf);
}

U0 SysDefinesLoad()
{
  DefineLstLoad("ST_OFF_ON","Off\0On\0");
  DefineLstLoad("ST_HTT_TYPES","ExportSysSym\0ImportSysSym\0DefineStr\0GlbVar\0"
        "Class\0IntType\0Funct\0Word\0DictWord\0KeyWord\0AsmKeyWord\0OpCode\0"
        "Reg\0File\0Module\0HelpFile\0Frame Ptr\0 \0 \0 \0 \0 \0 \0Private\0"
        "Public\0Export\0Import\0Imm\0Goto\0Res\0Unres\0Local\0");
  DefineLstLoad("ST_DAYS_OF_WEEK","Sunday\0Monday\0Tuesday\0Wednesday\0"
        "Thursday\0Friday\0Saturday\0");
  DefineLstLoad("ST_MONTHS","January\0February\0March\0April\0May\0"
        "June\0July\0August\0September\0October\0November\0December\0");
  DefineLstLoad("ST_FILE_ATTRS","R\0H\0S\0V\0D\0A\0 \0 \0X\0T\0Z\0C\0F\0");
  DefineLstLoad("ST_FILE_UTIL_FLAGS","r\0d\0i\0a\0c\0R\0p\0m\0x\0s\0"
        "D\0F\0T\0$\0S\0A\0J\0G\0Z\0O\0P\0f\0l\0lb\0la\0");
  DefineLstLoad("ST_BLKDEV_TYPES",
        "NULL\0RAM\0ATA\0FILE_READ\0FILE_WRITE\0ATAPI\0");
  DefineLstLoad("ST_DRV_TYPES",
        "NULL\0REDSEA\0FAT32\0ISO9660\0ISO13490\0ISO13346\0NTFS\0UNKNOWN\0");
  DefineLstLoad("ST_COLORS","BLACK\0BLUE\0GREEN\0CYAN\0"
        "RED\0PURPLE\0BROWN\0LTGRAY\0DKGRAY\0LTBLUE\0LTGREEN\0"
        "LTCYAN\0LTRED\0LTPURPLE\0YELLOW\0WHITE\0");
  DefineLstLoad("ST_INT_NAMES","Divide Error\0SingleStep\0NMI\0Breakpoint\0"
        "Overflow\0BOUND Range Exceeded\0Invalid Opcode\0No Math Coprocessor\0"
        "Double Fault\0Coprocessor Segment Fault\0Invalid TASK\0"
        "Segment Not Present\0Stk Segment Fault\0General Protection\0"
        "Page Fault\0 \0Math Fault\0Alignment Check\0Machine Check\0"
        "SIMD Exception\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0"
        " \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0MP Crash\0Wake\0Dbg\0");
}

U8 *Color2Str(U8 *buf,CColorROPU32 c)
{//CColorROPU32 with flags to DCLighting str.
  *buf=0;
  if (c.c0.rop&ROPBF_TWO_SIDED)
    CatPrint(buf,"TWO|");
  if (c.c0.rop&ROPBF_HALF_RANGE_COLOR)
    CatPrint(buf,"HALF|");
  if (0<=c.c0.color<16)
    CatPrint(buf,DefineSub(c.c0.color,"ST_COLORS"));
  else if (c.c0.color==TRANSPARENT)
    CatPrint(buf,"TRANSPARENT");
  else
    CatPrint(buf,"INVALID");
  if (c&ROPF_DITHER) {
    CatPrint(buf,"/");
    if (c.c1.rop&ROPBF_TWO_SIDED)
      CatPrint(buf,"TWO|");
    if (c.c1.rop&ROPBF_HALF_RANGE_COLOR)
      CatPrint(buf,"HALF|");
    if (0<=c.c1.color<16)
      CatPrint(buf,DefineSub(c.c1.color,"ST_COLORS"));
    else if (c.c1.color==TRANSPARENT)
      CatPrint(buf,"TRANSPARENT");
    else
      CatPrint(buf,"INVALID");
  }
  return buf;
}

U8 *str2color_lst="/,)}>";

CColorROPU16 Str2ColorU16(U8 *st)
{//DCLighting color str with flags to CColorROPU16.
  CColorROPU16 res=COLOR_INVALID;
  I64 i;
  U8 *ptr,*ptr2,*st2;
  if (!st) return COLOR_INVALID;
  while (TRUE) {
    if (!*st||StrOcc(str2color_lst,*st))
      return res;
    if (Bt(char_bmp_alpha,*st)) {
      ptr=st;
      while (Bt(char_bmp_alpha_numeric,*ptr))
        ptr++;
      st2=ptr2=MAlloc(ptr-st+1);
      while (st<ptr)
        *ptr2++=*st++;
      *ptr2++=0;
      if (!StrICmp(st2,"TWO"))
        res.rop|=ROPBF_TWO_SIDED;
      else if (!StrICmp(st2,"HALF"))
        res.rop|=ROPBF_HALF_RANGE_COLOR;
      else if ((i=DefineMatch(st2,"ST_COLORS",LMF_IGNORE_CASE))>=0)
        res.color=i;
      else if (!StrICmp(st2,"TRANSPARENT"))
        res.color=TRANSPARENT;
      else {
        Free(st2);
        return COLOR_INVALID;
      }
      Free(st2);
    } else if (*st=='+'||*st=='|'||Bt(char_bmp_white_space,*st))
      st++;
    else if ('0'<=*st<='9') {
      i=Str2I64(st,10,&ptr);
      if (0<=i<=0xFF) {
        res.color=i;
        st=ptr;
      } else
        return COLOR_INVALID;
    } else
      return COLOR_INVALID;
  }
}

CColorROPU32 Str2ColorU32(U8 *st)
{//DCLighting color str with flags to CColorROPU32.
  U8 *st2;
  CColorROPU32 res=0;
  if (!st) return COLOR_INVALID;
  st2=MAlloc(StrLen(st)+1);
  StrFirstRem(st,str2color_lst,st2);
  res.c0=Str2ColorU16(st2);
  if (*st) {
    res.c1=Str2ColorU16(st);
    res|=ROPF_DITHER;
  }
  if (res.c0.color==COLOR_INVALID||res.c1.color==COLOR_INVALID)
    return COLOR_INVALID;
  else
    return res;
}


// Source: D:\TempleOS-Projects\html\InterruptDemo-Lectures-Demo.html
// Date: unknown-date
// Language: HolyC

//This is the software interrupt num
//we will use.  See Software Int's for
//picking a num.  Nums are subject to change.

#define I_F_UNARY_MINUS I_USER

asm {

//This changes the sign of the floating
//point val in RAX
F_UNARY_MINUS_INT::
        PUSH    RAX
        FLD     U64 [RSP]
        FCHS
        FSTP    U64 [RSP]
        POP     RAX
        IRET

//This does the same thing, but not as
//an interrupt.
F_UNARY_MINUS_CALL::
        PUSH    RAX
        FLD     U64 [RSP]
        FCHS
        FSTP    U64 [RSP]
        POP     RAX
        RET

//This invokes the interrupt version
//with a C callable function.
_F_UM_INT::
        PUSH    RBP
        MOV     RBP,RSP
        MOV     RAX,SF_ARG1[RBP]
        INT     I_F_UNARY_MINUS
        POP     RBP
        RET1    8

//This invokes the call version
//with a C callable function.
_F_UM_CALL::
        PUSH    RBP
        MOV     RBP,RSP
        MOV     RAX,SF_ARG1[RBP]
        CALL    F_UNARY_MINUS_CALL
        POP     RBP
        RET1    8
}

_extern _F_UM_INT F64 UnaryMinusInt(F64 d);
_extern _F_UM_CALL F64 UnaryMinusCall(F64 d);

#define SAMPLE_SIZE     1000000
U0 TimeIns()
{
  I64 start,end;
  I64 i,old_irq;

  CPURep;
  old_irq=IntEntrySet(I_F_UNARY_MINUS,F_UNARY_MINUS_INT,IDTET_TRAP);

  //Measure interrupt time
  start=GetTSC;
  for (i=0;i<SAMPLE_SIZE;i++)
    UnaryMinusInt(pi);
  end=GetTSC;
  "Interrupt Cycles: %10.5f\n",ToF64(end-start)/SAMPLE_SIZE;

  //Measure call time
  start=GetTSC;
  for (i=0;i<SAMPLE_SIZE;i++)
    UnaryMinusCall(pi);
  end=GetTSC;
  "Call      Cycles: %10.5f\n",ToF64(end-start)/SAMPLE_SIZE;

  IntEntrySet(I_F_UNARY_MINUS,old_irq,IDTET_IRQ);
}

TimeIns;

/*  Program Output
6 Cores 3.395GHz
Interrupt Cycles:  573.98543
Call      Cycles:    9.74349
*/

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\InterruptDemo-Lectures-Demo.html
// Date: unknown-date
// Language: HolyC

//This is the software interrupt num
//we will use.  See Software Int's for
//picking a num.  Nums are subject to change.

#define I_F_UNARY_MINUS I_USER

asm {

//This changes the sign of the floating
//point val in RAX
F_UNARY_MINUS_INT::
        PUSH    RAX
        FLD     U64 [RSP]
        FCHS
        FSTP    U64 [RSP]
        POP     RAX
        IRET

//This does the same thing, but not as
//an interrupt.
F_UNARY_MINUS_CALL::
        PUSH    RAX
        FLD     U64 [RSP]
        FCHS
        FSTP    U64 [RSP]
        POP     RAX
        RET

//This invokes the interrupt version
//with a C callable function.
_F_UM_INT::
        PUSH    RBP
        MOV     RBP,RSP
        MOV     RAX,SF_ARG1[RBP]
        INT     I_F_UNARY_MINUS
        POP     RBP
        RET1    8

//This invokes the call version
//with a C callable function.
_F_UM_CALL::
        PUSH    RBP
        MOV     RBP,RSP
        MOV     RAX,SF_ARG1[RBP]
        CALL    F_UNARY_MINUS_CALL
        POP     RBP
        RET1    8
}

_extern _F_UM_INT F64 UnaryMinusInt(F64 d);
_extern _F_UM_CALL F64 UnaryMinusCall(F64 d);

#define SAMPLE_SIZE     1000000
U0 TimeIns()
{
  I64 start,end;
  I64 i,old_irq;

  CPURep;
  old_irq=IntEntrySet(I_F_UNARY_MINUS,F_UNARY_MINUS_INT,IDTET_TRAP);

  //Measure interrupt time
  start=GetTSC;
  for (i=0;i<SAMPLE_SIZE;i++)
    UnaryMinusInt(pi);
  end=GetTSC;
  "Interrupt Cycles: %10.5f\n",ToF64(end-start)/SAMPLE_SIZE;

  //Measure call time
  start=GetTSC;
  for (i=0;i<SAMPLE_SIZE;i++)
    UnaryMinusCall(pi);
  end=GetTSC;
  "Call      Cycles: %10.5f\n",ToF64(end-start)/SAMPLE_SIZE;

  IntEntrySet(I_F_UNARY_MINUS,old_irq,IDTET_IRQ);
}

TimeIns;

/*  Program Output
6 Cores 3.395GHz
Interrupt Cycles:  573.98543
Call      Cycles:    9.74349
*/


// Source: D:\TempleOS-Projects\html\Tour3-Tour-Misc.html
// Date: unknown-date
// Language: HolyC

//Puts the cursor at the bottom.
Msg(MSG_KEY_DOWN,0,SC_CURSOR_DOWN|SCF_CTRL);
"\n";

TourPut(
"Now, we're going to demonstrate how to work "
"with programs.  We'll change to the "
"$GREEN$/Demo/Games$FG$ directory.\n\n"
"Note that directories are specified with "
"a forward slash, not a backslash.  "
"Drives can be specified in a $GREEN$Cd()$FG$ command "
"and the boot drive is specified with \"$GREEN$::$FG$\".\n\n"
"$GREEN$<ENTER>$FG$ to complete the command.\n");

InPrint(25,"Cd(\"::/Demo/Games\");Dir;");
InGetStr("\n");

TourPut(
"Now, we're going to edit a file.  Normally, "
"you'll probably left-click on a directory "
"listing to edit a file, but we're going to "
"type it on the command line.\n\n"
"$GREEN$<ENTER>$FG$ to complete the command.\n");

InPrint(25,"Ed(\"CastleFrankenstein.HC.Z\");");
InGetStr("\n");
Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_UP|SCF_CTRL);

Sleep(1000);
Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN|SCF_CTRL);
TourPut(
"This is a first-person-shooter.\n\n"
"There is no \"$GREEN$main()$FG$\" function in TempleOS "
"programs.  Any program stmts outside "
"functions get executed when you $GREEN$#include$FG$ "
"them at the command line.\n\n"
"The \"$GREEN$CastleFrankenstein;$FG$\" stmt at the "
"bottom will run the program when we "
"$GREEN$#include$FG$ it.\n",TRUE);

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the editor.\n");

InGetChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"Now, run the CastleFrankenstein.HC.Z program.  Press $GREEN$<ENTER>$FG$.\n");

InPrint(25,"#include \"CastleFrankenstein\";");
InGetStr("\n");
TourPut(
"Move around with cursor keys and press $GREEN$<SHIFT-ESC>$FG$ when you "
"are done.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"The program is still in memory and we can start it again by typing "
"\"$GREEN$CastleFrankenstein;$FG$\".\n\n"
"Press $GREEN$<ENTER>$FG$ at the command line to run it again.\n");

InPrint(25,"CastleFrankenstein;");
InGetStr("\n");
TourPut(
"Move around with cursor keys and press $GREEN$<SHIFT-ESC>$FG$ when you "
"are done.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"$GREEN$<CTRL-ALT-a>$FG$\tExtended ASCII.\n"
"$GREEN$<CTRL-ALT-c>$FG$\tBreak(interrupt) program.\n"
"$GREEN$<CTRL-ALT-m>$FG$\tMutes sound.\n"
"$GREEN$<CTRL-ALT-n>$FG$\tNext tasks.\n"
"$GREEN$<CTRL-ALT-t>$FG$\tTerminal window.\n"
"$GREEN$<CTRL-ALT-x>$FG$\tKill task (window).\n",TRUE);

InPrint(50,"Ed(\"CastleFrankenstein.HC.Z\");\n");

TourPut("Press $GREEN$<F5>$FG$ in the editor to run the file being edited.\n");

InGetKey(SC_F5);
Sleep(1000);
CTask *task=sys_focus_task;

TourPut(
"Press $GREEN$<SHIFT-ESC>$FG$ to abort the application.  "
"Then, press $GREEN$<CTRL-ALT-x>$FG$ to kill the task.\n");
WinToTop(task);
DeathWait(&task);

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the editor.\n");

InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"Explore the $RED$DemoIndex$FG$.  "
"You'll find it on your menu.  It's arranged by difficulty.  "
"Hit $GREEN$<SPACE>$FG$ on a demo index listing "
"and $GREEN$<F5>$FG$ to run from the editor.\n",TRUE);

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\Tour3-Tour-Misc.html
// Date: unknown-date
// Language: HolyC

//Puts the cursor at the bottom.
Msg(MSG_KEY_DOWN,0,SC_CURSOR_DOWN|SCF_CTRL);
"\n";

TourPut(
"Now, we're going to demonstrate how to work "
"with programs.  We'll change to the "
"$GREEN$/Demo/Games$FG$ directory.\n\n"
"Note that directories are specified with "
"a forward slash, not a backslash.  "
"Drives can be specified in a $GREEN$Cd()$FG$ command "
"and the boot drive is specified with \"$GREEN$::$FG$\".\n\n"
"$GREEN$<ENTER>$FG$ to complete the command.\n");

InPrint(25,"Cd(\"::/Demo/Games\");Dir;");
InGetStr("\n");

TourPut(
"Now, we're going to edit a file.  Normally, "
"you'll probably left-click on a directory "
"listing to edit a file, but we're going to "
"type it on the command line.\n\n"
"$GREEN$<ENTER>$FG$ to complete the command.\n");

InPrint(25,"Ed(\"CastleFrankenstein.HC.Z\");");
InGetStr("\n");
Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_UP|SCF_CTRL);

Sleep(1000);
Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN|SCF_CTRL);
TourPut(
"This is a first-person-shooter.\n\n"
"There is no \"$GREEN$main()$FG$\" function in TempleOS "
"programs.  Any program stmts outside "
"functions get executed when you $GREEN$#include$FG$ "
"them at the command line.\n\n"
"The \"$GREEN$CastleFrankenstein;$FG$\" stmt at the "
"bottom will run the program when we "
"$GREEN$#include$FG$ it.\n",TRUE);

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the editor.\n");

InGetChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"Now, run the CastleFrankenstein.HC.Z program.  Press $GREEN$<ENTER>$FG$.\n");

InPrint(25,"#include \"CastleFrankenstein\";");
InGetStr("\n");
TourPut(
"Move around with cursor keys and press $GREEN$<SHIFT-ESC>$FG$ when you "
"are done.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"The program is still in memory and we can start it again by typing "
"\"$GREEN$CastleFrankenstein;$FG$\".\n\n"
"Press $GREEN$<ENTER>$FG$ at the command line to run it again.\n");

InPrint(25,"CastleFrankenstein;");
InGetStr("\n");
TourPut(
"Move around with cursor keys and press $GREEN$<SHIFT-ESC>$FG$ when you "
"are done.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"$GREEN$<CTRL-ALT-a>$FG$\tExtended ASCII.\n"
"$GREEN$<CTRL-ALT-c>$FG$\tBreak(interrupt) program.\n"
"$GREEN$<CTRL-ALT-m>$FG$\tMutes sound.\n"
"$GREEN$<CTRL-ALT-n>$FG$\tNext tasks.\n"
"$GREEN$<CTRL-ALT-t>$FG$\tTerminal window.\n"
"$GREEN$<CTRL-ALT-x>$FG$\tKill task (window).\n",TRUE);

InPrint(50,"Ed(\"CastleFrankenstein.HC.Z\");\n");

TourPut("Press $GREEN$<F5>$FG$ in the editor to run the file being edited.\n");

InGetKey(SC_F5);
Sleep(1000);
CTask *task=sys_focus_task;

TourPut(
"Press $GREEN$<SHIFT-ESC>$FG$ to abort the application.  "
"Then, press $GREEN$<CTRL-ALT-x>$FG$ to kill the task.\n");
WinToTop(task);
DeathWait(&task);

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the editor.\n");

InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"Explore the $RED$DemoIndex$FG$.  "
"You'll find it on your menu.  It's arranged by difficulty.  "
"Hit $GREEN$<SPACE>$FG$ on a demo index listing "
"and $GREEN$<F5>$FG$ to run from the editor.\n",TRUE);


// Source: D:\TempleOS-Projects\html\vengeance-Sup1-Sup1Hymns-Home.html
// Date: unknown-date
// Language: HolyC

//5 has graphics

     <1>/* Graphics Not Rendered in HTML */

F64 t0=0;

U0 DrawIt(CTask *,CDC *dc)
{
  F64 dt=Beat-t0-6.0;
  if (t0 && 0<=dt<1.0) {
    dc->flags|=DCF_TRANSFORMATION;
    Mat4x4RotZ(dc->r,5.0*(dt-0.5));
    Mat4x4RotX(dc->r,1.5-2.0*dt);
    DCMat4x4Set(dc,dc->r);
    Sprite3B(dc,200,55,0,<1>);
  }
}

U0 Song()
{
  CTask *task;
  SettingsPush; //See SettingsPush
  Fs->draw_it=&DrawIt;
  Fs->task_end_cb=&SndTaskEndCB;
  MusicSettingsRst;
  music.tempo=2.5;
  try {
    task=PopUpViewPrint(
          "Romans,12:19\n"
          "Matthew,5:38\n");
    TaskWait(task);
    WinHorz(Fs->win_left,TEXT_COLS-10,task);
    WinVert(Fs->win_bottom+3,Fs->win_bottom+15,task);
    while (!ScanKey) {
      Play("5etFD4A5qD4qAqA5qDqCeEGeDC",
            "Leave \0it \0to \0God.\n\0");
      Play("5etFD4A5qD4qAqA5qDqCeEGeDC",
            "Leave \0it \0to \0God.\n\0");
      t0=Beat;
      Play("5qDqFqGqCqEqCetDG4AeAA",
            " \0 \0 \0 \0Stand \0back.\n\0");
      t0=Beat;
      Play("5qDqFqGqCqEqCetDG4AeAA",
            " \0 \0 \0 \0Stand \0back.\n\0");
      t0=0;
    }
  } catch
    PutExcept;
  SettingsPop;
}

Song;

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\vengeance-Sup1-Sup1Hymns-Home.html
// Date: unknown-date
// Language: HolyC

//5 has graphics

     <1>/* Graphics Not Rendered in HTML */

F64 t0=0;

U0 DrawIt(CTask *,CDC *dc)
{
  F64 dt=Beat-t0-6.0;
  if (t0 && 0<=dt<1.0) {
    dc->flags|=DCF_TRANSFORMATION;
    Mat4x4RotZ(dc->r,5.0*(dt-0.5));
    Mat4x4RotX(dc->r,1.5-2.0*dt);
    DCMat4x4Set(dc,dc->r);
    Sprite3B(dc,200,55,0,<1>);
  }
}

U0 Song()
{
  CTask *task;
  SettingsPush; //See SettingsPush
  Fs->draw_it=&DrawIt;
  Fs->task_end_cb=&SndTaskEndCB;
  MusicSettingsRst;
  music.tempo=2.5;
  try {
    task=PopUpViewPrint(
          "Romans,12:19\n"
          "Matthew,5:38\n");
    TaskWait(task);
    WinHorz(Fs->win_left,TEXT_COLS-10,task);
    WinVert(Fs->win_bottom+3,Fs->win_bottom+15,task);
    while (!ScanKey) {
      Play("5etFD4A5qD4qAqA5qDqCeEGeDC",
            "Leave \0it \0to \0God.\n\0");
      Play("5etFD4A5qD4qAqA5qDqCeEGeDC",
            "Leave \0it \0to \0God.\n\0");
      t0=Beat;
      Play("5qDqFqGqCqEqCetDG4AeAA",
            " \0 \0 \0 \0Stand \0back.\n\0");
      t0=Beat;
      Play("5qDqFqGqCqEqCetDG4AeAA",
            " \0 \0 \0 \0Stand \0back.\n\0");
      t0=0;
    }
  } catch
    PutExcept;
  SettingsPop;
}

Song;


// Source: D:\TempleOS-Projects\html\DskRaw-Dsk-Demo.html
// Date: unknown-date
// Language: HolyC

U0 RawAccess(I64 drv_let=0)
{
  CDrv *dv=Let2Drv(drv_let);
  CBlkDev *bd=Let2BlkDev(drv_let);
  I64 blk,old_offset,old_size;
  U8 *buf=MAlloc(BLK_SIZE);

  DrvRep;
  PressAKey;

  ClassRep(dv);
  PressAKey;

  ClassRep(bd);
  PressAKey;

  //Temporarily change partition range to full device.
  //Normally, you are limited to just your partition.
  //This is obviously dangerous!
  old_offset=dv->drv_offset;
  old_size  =dv->size;
  dv->drv_offset=0;
  dv->size=bd->max_blk+1;

  try {
    blk=GetI64("Blk to Read: ",old_offset,0,bd->max_blk);
    BlkRead(dv,buf,blk,1);
    D(buf,BLK_SIZE);
  } catch
    PutExcept;

  dv->drv_offset=old_offset;
  dv->size  =old_size;

  Free(buf);
}

RawAccess;

//See BlkRead(), BlkWrite(), DrvLock(), DrvUnlock()
//DBlk(), DClus(), BlkDevLock() and BlkDevUnlock().

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\DskRaw-Dsk-Demo.html
// Date: unknown-date
// Language: HolyC

U0 RawAccess(I64 drv_let=0)
{
  CDrv *dv=Let2Drv(drv_let);
  CBlkDev *bd=Let2BlkDev(drv_let);
  I64 blk,old_offset,old_size;
  U8 *buf=MAlloc(BLK_SIZE);

  DrvRep;
  PressAKey;

  ClassRep(dv);
  PressAKey;

  ClassRep(bd);
  PressAKey;

  //Temporarily change partition range to full device.
  //Normally, you are limited to just your partition.
  //This is obviously dangerous!
  old_offset=dv->drv_offset;
  old_size  =dv->size;
  dv->drv_offset=0;
  dv->size=bd->max_blk+1;

  try {
    blk=GetI64("Blk to Read: ",old_offset,0,bd->max_blk);
    BlkRead(dv,buf,blk,1);
    D(buf,BLK_SIZE);
  } catch
    PutExcept;

  dv->drv_offset=old_offset;
  dv->size  =old_size;

  Free(buf);
}

RawAccess;

//See BlkRead(), BlkWrite(), DrvLock(), DrvUnlock()
//DBlk(), DClus(), BlkDevLock() and BlkDevUnlock().


// Source: D:\TempleOS-Projects\html\CvtCmp-Sup1-Sup1Utils-Home.html
// Date: unknown-date
// Language: HolyC

Cd(__DIR__);;
#include "FileRaw"

class CArcCompress1
{
  U32   compressed_size,expanded_size;
  U32   compression_type,xsum,pad[4];
  U0    body;
};

public U0 CvtCmp1(U8 *in_name,U8 *out_name)
{//Compression V1.0 --> V3.0
  I64 size;
  CArcCompress1 *in_buf=FileReadRaw(in_name,&size);
  CArcCompress  *out_buf=MAlloc(size);
  out_buf->compressed_size=in_buf->compressed_size+
        sizeof(CArcCompress)-sizeof(CArcCompress1);
  out_buf->expanded_size=in_buf->expanded_size;
  out_buf->compression_type=in_buf->compression_type+1;
  MemCpy(&out_buf->body,&in_buf->body,
        out_buf->compressed_size-sizeof(CArcCompress));
  FileWriteRaw(out_name,out_buf,out_buf->compressed_size);
  Free(in_buf);
  Free(out_buf);
}

public U0 CvtCmp2(U8 *in_name,U8 *out_name)
{//Compression V2.0 --> V3.0
  I64 size;
  U8 *in_buf=FileReadRaw(in_name,&size),*out_buf=MAlloc(size-3);
  MemCpy(out_buf,in_buf,sizeof(CArcCompress));
  out_buf(CArcCompress *)->compressed_size-=3;
  out_buf(CArcCompress *)->compression_type++;
  MemCpy(&out_buf(CArcCompress *)->body,
        (&in_buf(CArcCompress *)->body)(U8 *)+3,
        size-sizeof(CArcCompress)-3);
  FileWriteRaw(out_name,out_buf,size-3);
  Free(in_buf);
  Free(out_buf);
}

public U0 UnzipCmp150(U8 *files_find_mask="*z",U8 *fu_flags=NULL)
{
  U8 name[STR_LEN],ext[STR_LEN];
  CDirEntry *tmpde,*tmpde1;
  I64 i,fuf_flags=0;
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+O");
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  tmpde=tmpde1=FilesFind(files_find_mask,fuf_flags);
  while (tmpde) {
    "%s\n",tmpde->full_name;
    StrCpy(name,tmpde->full_name);
    StrLastRem(name,".",ext);
    i=LstMatch(ext,"asz\0cpz\0hpz\0dtz\0biz\0mpz\0muz\0txz\0auz\0glz\0");
    if (i>=0) {
      CatPrint(name,".%s.Z",
            LstSub(i,"ASM\0CPP\0HPP\0DAT\0BIN\0MAP\0TXT\0TXT\0AUT\0TXT\0"));
      "$BLACK$%s$FG$\n",name;
      if (FileFind(name))
        "$RED$Collision:%s$FG$\n",name;
      else {
        CvtCmp1(tmpde->full_name,name);
        Del(tmpde->full_name);
      }
    } else {
      i=LstMatch(ext,"bic\0");
      if (i>=0) {
        CatPrint(name,".%s",LstSub(i,"BIN\0"));
        "$BLACK$%s$FG$\n",name;
        if (FileFind(name))
          "$RED$Collision:%s$FG$\n",name;
        else {
          Move(tmpde->full_name,name);
          Del(tmpde->full_name);
        }
      } else
        "$RED$%s$FG$\n",tmpde->full_name;
    }
    tmpde=tmpde->next;
  }
  DirTreeDel(tmpde1);
}

public U0 UnzipCmp250(U8 *files_find_mask="*z",U8 *fu_flags=NULL)
{
  U8 name[STR_LEN],ext[STR_LEN];
  CDirEntry *tmpde,*tmpde1;
  I64 i,fuf_flags=0;
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+O");
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  tmpde=tmpde1=FilesFind(files_find_mask,fuf_flags);
  while (tmpde) {
    "%s\n",tmpde->full_name;
    StrCpy(name,tmpde->full_name);
    StrLastRem(name,".",ext);
    i=LstMatch(ext,"asz\0cpz\0hpz\0dtz\0biz\0mpz\0muz\0txz\0"
          "auz\0glz\0apz\0spz\0");
    if (i>=0) {
      CatPrint(name,".%s.Z",
            LstSub(i,"ASM\0CPP\0HPP\0DAT\0BIN\0MAP\0TXT\0TXT\0"
            "IN\0TXT\0CPP\0CPP\0"));
      "$BLACK$%s$FG$\n",name;
      if (FileFind(name))
        "$RED$Collision:%s$FG$\n",name;
      else {
        CvtCmp2(tmpde->full_name,name);
        Del(tmpde->full_name);
      }
    } else {
      i=LstMatch(ext,"bic\0dat\0");
      if (i>=0) {
        CatPrint(name,".%s",LstSub(i,"BIN\0DAT\0"));
        "$BLACK$%s$FG$\n",name;
        if (FileFind(name))
          "$RED$Collision:%s$FG$\n",name;
        else {
          Move(tmpde->full_name,name);
          Del(tmpde->full_name);
        }
      } else
        "$RED$%s$FG$\n",tmpde->full_name;
    }
    tmpde=tmpde->next;
  }
  DirTreeDel(tmpde1);
}

Bool IsDotz(U8 *filename)
{//Does name end in .Z?
  I64 i=StrLen(filename);
  if (i>6 && filename[i-1]=='z' && filename[i-2]=='.' && filename[i-6]=='.')
    return TRUE;
  else
    return FALSE;
}

public U0 UnzipCmp270(U8 *files_find_mask="*.Z",U8 *fu_flags=NULL)
{
  U8 buf[STR_LEN],name[STR_LEN];
  CDirEntry *tmpde,*tmpde1;
  I64 fuf_flags=0;
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+O");
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  tmpde=tmpde1=FilesFind(files_find_mask,fuf_flags);
  while (tmpde) {
    StrCpy(buf,tmpde->full_name);
    StrLastRem(buf,"/",name);
    StrUtil(name,SUF_TO_UPPER);
    CatPrint(buf,"/%s",name);
    "%s\n",tmpde->full_name;
    if (FileFind(buf))
      "$RED$Collision:%s$FG$\n",buf;
    else if (IsDotz(tmpde->full_name)) {
      "$BLACK$%s$FG$\n",buf;
      CvtCmp2(tmpde->full_name,buf);
      Del(tmpde->full_name);
    } else {
      "$BLACK$%s$FG$\n",buf;
      Move(tmpde->full_name,buf);
    }
    tmpde=tmpde->next;
  }
  DirTreeDel(tmpde1);
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\CvtCmp-Sup1-Sup1Utils-Home.html
// Date: unknown-date
// Language: HolyC

Cd(__DIR__);;
#include "FileRaw"

class CArcCompress1
{
  U32   compressed_size,expanded_size;
  U32   compression_type,xsum,pad[4];
  U0    body;
};

public U0 CvtCmp1(U8 *in_name,U8 *out_name)
{//Compression V1.0 --> V3.0
  I64 size;
  CArcCompress1 *in_buf=FileReadRaw(in_name,&size);
  CArcCompress  *out_buf=MAlloc(size);
  out_buf->compressed_size=in_buf->compressed_size+
        sizeof(CArcCompress)-sizeof(CArcCompress1);
  out_buf->expanded_size=in_buf->expanded_size;
  out_buf->compression_type=in_buf->compression_type+1;
  MemCpy(&out_buf->body,&in_buf->body,
        out_buf->compressed_size-sizeof(CArcCompress));
  FileWriteRaw(out_name,out_buf,out_buf->compressed_size);
  Free(in_buf);
  Free(out_buf);
}

public U0 CvtCmp2(U8 *in_name,U8 *out_name)
{//Compression V2.0 --> V3.0
  I64 size;
  U8 *in_buf=FileReadRaw(in_name,&size),*out_buf=MAlloc(size-3);
  MemCpy(out_buf,in_buf,sizeof(CArcCompress));
  out_buf(CArcCompress *)->compressed_size-=3;
  out_buf(CArcCompress *)->compression_type++;
  MemCpy(&out_buf(CArcCompress *)->body,
        (&in_buf(CArcCompress *)->body)(U8 *)+3,
        size-sizeof(CArcCompress)-3);
  FileWriteRaw(out_name,out_buf,size-3);
  Free(in_buf);
  Free(out_buf);
}

public U0 UnzipCmp150(U8 *files_find_mask="*z",U8 *fu_flags=NULL)
{
  U8 name[STR_LEN],ext[STR_LEN];
  CDirEntry *tmpde,*tmpde1;
  I64 i,fuf_flags=0;
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+O");
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  tmpde=tmpde1=FilesFind(files_find_mask,fuf_flags);
  while (tmpde) {
    "%s\n",tmpde->full_name;
    StrCpy(name,tmpde->full_name);
    StrLastRem(name,".",ext);
    i=LstMatch(ext,"asz\0cpz\0hpz\0dtz\0biz\0mpz\0muz\0txz\0auz\0glz\0");
    if (i>=0) {
      CatPrint(name,".%s.Z",
            LstSub(i,"ASM\0CPP\0HPP\0DAT\0BIN\0MAP\0TXT\0TXT\0AUT\0TXT\0"));
      "$BLACK$%s$FG$\n",name;
      if (FileFind(name))
        "$RED$Collision:%s$FG$\n",name;
      else {
        CvtCmp1(tmpde->full_name,name);
        Del(tmpde->full_name);
      }
    } else {
      i=LstMatch(ext,"bic\0");
      if (i>=0) {
        CatPrint(name,".%s",LstSub(i,"BIN\0"));
        "$BLACK$%s$FG$\n",name;
        if (FileFind(name))
          "$RED$Collision:%s$FG$\n",name;
        else {
          Move(tmpde->full_name,name);
          Del(tmpde->full_name);
        }
      } else
        "$RED$%s$FG$\n",tmpde->full_name;
    }
    tmpde=tmpde->next;
  }
  DirTreeDel(tmpde1);
}

public U0 UnzipCmp250(U8 *files_find_mask="*z",U8 *fu_flags=NULL)
{
  U8 name[STR_LEN],ext[STR_LEN];
  CDirEntry *tmpde,*tmpde1;
  I64 i,fuf_flags=0;
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+O");
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  tmpde=tmpde1=FilesFind(files_find_mask,fuf_flags);
  while (tmpde) {
    "%s\n",tmpde->full_name;
    StrCpy(name,tmpde->full_name);
    StrLastRem(name,".",ext);
    i=LstMatch(ext,"asz\0cpz\0hpz\0dtz\0biz\0mpz\0muz\0txz\0"
          "auz\0glz\0apz\0spz\0");
    if (i>=0) {
      CatPrint(name,".%s.Z",
            LstSub(i,"ASM\0CPP\0HPP\0DAT\0BIN\0MAP\0TXT\0TXT\0"
            "IN\0TXT\0CPP\0CPP\0"));
      "$BLACK$%s$FG$\n",name;
      if (FileFind(name))
        "$RED$Collision:%s$FG$\n",name;
      else {
        CvtCmp2(tmpde->full_name,name);
        Del(tmpde->full_name);
      }
    } else {
      i=LstMatch(ext,"bic\0dat\0");
      if (i>=0) {
        CatPrint(name,".%s",LstSub(i,"BIN\0DAT\0"));
        "$BLACK$%s$FG$\n",name;
        if (FileFind(name))
          "$RED$Collision:%s$FG$\n",name;
        else {
          Move(tmpde->full_name,name);
          Del(tmpde->full_name);
        }
      } else
        "$RED$%s$FG$\n",tmpde->full_name;
    }
    tmpde=tmpde->next;
  }
  DirTreeDel(tmpde1);
}

Bool IsDotz(U8 *filename)
{//Does name end in .Z?
  I64 i=StrLen(filename);
  if (i>6 && filename[i-1]=='z' && filename[i-2]=='.' && filename[i-6]=='.')
    return TRUE;
  else
    return FALSE;
}

public U0 UnzipCmp270(U8 *files_find_mask="*.Z",U8 *fu_flags=NULL)
{
  U8 buf[STR_LEN],name[STR_LEN];
  CDirEntry *tmpde,*tmpde1;
  I64 fuf_flags=0;
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),"+r+f+F+O");
  ScanFlags(&fuf_flags,Define("ST_FILE_UTIL_FLAGS"),fu_flags);
  tmpde=tmpde1=FilesFind(files_find_mask,fuf_flags);
  while (tmpde) {
    StrCpy(buf,tmpde->full_name);
    StrLastRem(buf,"/",name);
    StrUtil(name,SUF_TO_UPPER);
    CatPrint(buf,"/%s",name);
    "%s\n",tmpde->full_name;
    if (FileFind(buf))
      "$RED$Collision:%s$FG$\n",buf;
    else if (IsDotz(tmpde->full_name)) {
      "$BLACK$%s$FG$\n",buf;
      CvtCmp2(tmpde->full_name,buf);
      Del(tmpde->full_name);
    } else {
      "$BLACK$%s$FG$\n",buf;
      Move(tmpde->full_name,buf);
    }
    tmpde=tmpde->next;
  }
  DirTreeDel(tmpde1);
}


// Source: D:\TempleOS-Projects\html\DskPrt-ABlkDev-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Install;File/Cmd Line (Typically);Cmd Line (Typically)"

#define ROUND_DRV_TO    (63*255)
#define DRV_HEADER      63

class CPlannedDrv
{
  CPlannedDrv *next,*last;
  I64 size;
  Bool pri;
};

public I64 DskPrt(U8 drv_let=0,...)
{/*Partition the disk containing partition drv_let.

drv_let=0 means add new drive that is not already mounted.

>DskPrt('C',0.5,0.25,0.25); //Make three.  50% C, 25% D, 25% E, round-up to blk.

*/
  CBlkDev *bd;
  CPlannedDrv head,*tmppp;
  CMasterBoot mbr;
  Bool pri=TRUE;
  I64 ext_base,drv_let2,pri_cnt=0,i,start_offset,offset,
        total,remaining,cur_arg=0;
  "This command does not play well\n"
        "with other operating systems.\n"
        "You really should use another\n"
        "operating system's partitioner.\n"
        "If you use this, it may, in fact,\n"
        "make your hard drive impossible\n"
        "to repartition with other operating\n"
        "until you set block zero to zero\n"
        "with $LK,\"BootMHDZero\",\"MN:BootMHDZero\"$()\n\n\n"
        "Continue";
  if (argc<=cur_arg && !YorN)
    return 0;
  '\n';

  if (drv_let && !Let2BlkDev(drv_let,FALSE))
    drv_let=0;
  if (!drv_let && !(drv_let=Mount(TRUE)) ||
        !(bd=Let2BlkDev(drv_let,FALSE)) || bd->type!=BDT_ATA)
    return 0;

  total=bd->max_blk+1;
  QueInit(&head);
  drv_let2=bd->first_drv_let;
  remaining=FloorU64(bd->max_blk+1,ROUND_DRV_TO);
  while (FloorU64(remaining,ROUND_DRV_TO)>=ROUND_DRV_TO) {
    tmppp=MAlloc(sizeof(CPlannedDrv));
    do {
      "$RED$Partition %C$FG$\n",drv_let2;
      tmppp->pri=FALSE;
      if (pri) {
        "Primary Partition";
        if (argc>cur_arg || YorN) {
          pri_cnt++;
          tmppp->pri=TRUE;
          if (pri_cnt==3)
            pri=FALSE;
        } else
          pri=FALSE;
      }
      "\nBlocks Remaining:%d (0x%X)\n",
            remaining-DRV_HEADER,remaining-DRV_HEADER;
      if (argc>cur_arg)
        tmppp->size=MinI64(CeilU64(MaxI64(remaining,DRV_HEADER),ROUND_DRV_TO),
              CeilU64(argv[cur_arg++](F64)*total,ROUND_DRV_TO));
      else
        tmppp->size=CeilU64(GetI64("Size in Blocks  :",
              remaining-DRV_HEADER)+DRV_HEADER,ROUND_DRV_TO);
    } while (!(ROUND_DRV_TO<=tmppp->size<=FloorU64(remaining,ROUND_DRV_TO)));
    QueIns(tmppp,head.last);
    remaining-=tmppp->size;
    drv_let2++;
  }

  "\n\n!!! Repartition Drive !!!\n\n";
  tmppp=head.next;
  drv_let2=bd->first_drv_let;
  while (tmppp!=&head) {
    "Drive %C:%08X ",drv_let2,tmppp->size;
    if (tmppp->pri)
      "Primary\n";
    else
      "Logical\n";
    tmppp=tmppp->next;
    drv_let2++;
  }
  if (!argc && !AreYouSure)
    goto pd_done;

  remaining=FloorU64(bd->max_blk+1,ROUND_DRV_TO)-ROUND_DRV_TO;
  tmppp=head.next;
  MemSet(&mbr,0,BLK_SIZE);
  mbr.signature=0xAA55;
  offset=0;
  for (i=0;i<pri_cnt;i++) {
    mbr.p[i].active=0x80;
    mbr.p[i].start_head=0;
    mbr.p[i].start_cyl=0x101;
    mbr.p[i].type=1; //Will get set different.
    mbr.p[i].end_head=0xFE;
    mbr.p[i].end_cyl=0xFFFF;
    mbr.p[i].offset=DRV_HEADER+offset;
    mbr.p[i].size=tmppp->size-DRV_HEADER;
    offset+=tmppp->size;
    remaining-=tmppp->size;
    tmppp=tmppp->next;
  }
  if (!i) i++;
  if (tmppp!=&head) {
    mbr.p[i].active=0x80;
    mbr.p[i].start_head=0;
    mbr.p[i].start_cyl=0x101;
    mbr.p[i].type=0xF;
    mbr.p[i].end_head=0xFE;
    mbr.p[i].end_cyl=0xFFFF;
    mbr.p[i].offset=offset;
    mbr.p[i].size=remaining;
    ext_base=offset;
  }
  ATAWriteBlks(bd,&mbr,0,1);

  while (tmppp!=&head) {
    start_offset=offset;
    MemSet(&mbr,0,BLK_SIZE);
    mbr.signature=0xAA55;

    mbr.p[0].active=0x80;
    mbr.p[0].start_head=1;
    mbr.p[0].start_cyl=0x101;
    mbr.p[0].type=1; //Will get set different.
    mbr.p[0].end_head=0xFE;
    mbr.p[0].end_cyl=0xFFFF;
    mbr.p[0].offset=DRV_HEADER;
    mbr.p[0].size=tmppp->size-DRV_HEADER;
    offset+=tmppp->size;
    tmppp=tmppp->next;
    if (tmppp!=&head) {
      mbr.p[1].active=0x80;
      mbr.p[1].start_head=0;
      mbr.p[1].start_cyl=0x101;
      mbr.p[1].type=5;
      mbr.p[1].end_head=0xFE;
      mbr.p[1].end_cyl=0xFFFF;
      mbr.p[1].offset=offset-ext_base;
      mbr.p[1].size=tmppp->size;
    }
    ATAWriteBlks(bd,&mbr,start_offset,1);
  }

  bd->flags&=~(BDF_INITIALIZED | BDF_INIT_IN_PROGRESS);
  BlkDevAdd(bd,,FALSE,TRUE);
  for (i=bd->first_drv_let;i<drv_let2;i++)
    Fmt(i,,FALSE);

    pd_done:
  while (head.next!=&head) {
    tmppp=head.next;
    QueRem(tmppp);
    Free(tmppp);
  }
  return total;
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\DskPrt-ABlkDev-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Install;File/Cmd Line (Typically);Cmd Line (Typically)"

#define ROUND_DRV_TO    (63*255)
#define DRV_HEADER      63

class CPlannedDrv
{
  CPlannedDrv *next,*last;
  I64 size;
  Bool pri;
};

public I64 DskPrt(U8 drv_let=0,...)
{/*Partition the disk containing partition drv_let.

drv_let=0 means add new drive that is not already mounted.

>DskPrt('C',0.5,0.25,0.25); //Make three.  50% C, 25% D, 25% E, round-up to blk.

*/
  CBlkDev *bd;
  CPlannedDrv head,*tmppp;
  CMasterBoot mbr;
  Bool pri=TRUE;
  I64 ext_base,drv_let2,pri_cnt=0,i,start_offset,offset,
        total,remaining,cur_arg=0;
  "This command does not play well\n"
        "with other operating systems.\n"
        "You really should use another\n"
        "operating system's partitioner.\n"
        "If you use this, it may, in fact,\n"
        "make your hard drive impossible\n"
        "to repartition with other operating\n"
        "until you set block zero to zero\n"
        "with $LK,\"BootMHDZero\",\"MN:BootMHDZero\"$()\n\n\n"
        "Continue";
  if (argc<=cur_arg && !YorN)
    return 0;
  '\n';

  if (drv_let && !Let2BlkDev(drv_let,FALSE))
    drv_let=0;
  if (!drv_let && !(drv_let=Mount(TRUE)) ||
        !(bd=Let2BlkDev(drv_let,FALSE)) || bd->type!=BDT_ATA)
    return 0;

  total=bd->max_blk+1;
  QueInit(&head);
  drv_let2=bd->first_drv_let;
  remaining=FloorU64(bd->max_blk+1,ROUND_DRV_TO);
  while (FloorU64(remaining,ROUND_DRV_TO)>=ROUND_DRV_TO) {
    tmppp=MAlloc(sizeof(CPlannedDrv));
    do {
      "$RED$Partition %C$FG$\n",drv_let2;
      tmppp->pri=FALSE;
      if (pri) {
        "Primary Partition";
        if (argc>cur_arg || YorN) {
          pri_cnt++;
          tmppp->pri=TRUE;
          if (pri_cnt==3)
            pri=FALSE;
        } else
          pri=FALSE;
      }
      "\nBlocks Remaining:%d (0x%X)\n",
            remaining-DRV_HEADER,remaining-DRV_HEADER;
      if (argc>cur_arg)
        tmppp->size=MinI64(CeilU64(MaxI64(remaining,DRV_HEADER),ROUND_DRV_TO),
              CeilU64(argv[cur_arg++](F64)*total,ROUND_DRV_TO));
      else
        tmppp->size=CeilU64(GetI64("Size in Blocks  :",
              remaining-DRV_HEADER)+DRV_HEADER,ROUND_DRV_TO);
    } while (!(ROUND_DRV_TO<=tmppp->size<=FloorU64(remaining,ROUND_DRV_TO)));
    QueIns(tmppp,head.last);
    remaining-=tmppp->size;
    drv_let2++;
  }

  "\n\n!!! Repartition Drive !!!\n\n";
  tmppp=head.next;
  drv_let2=bd->first_drv_let;
  while (tmppp!=&head) {
    "Drive %C:%08X ",drv_let2,tmppp->size;
    if (tmppp->pri)
      "Primary\n";
    else
      "Logical\n";
    tmppp=tmppp->next;
    drv_let2++;
  }
  if (!argc && !AreYouSure)
    goto pd_done;

  remaining=FloorU64(bd->max_blk+1,ROUND_DRV_TO)-ROUND_DRV_TO;
  tmppp=head.next;
  MemSet(&mbr,0,BLK_SIZE);
  mbr.signature=0xAA55;
  offset=0;
  for (i=0;i<pri_cnt;i++) {
    mbr.p[i].active=0x80;
    mbr.p[i].start_head=0;
    mbr.p[i].start_cyl=0x101;
    mbr.p[i].type=1; //Will get set different.
    mbr.p[i].end_head=0xFE;
    mbr.p[i].end_cyl=0xFFFF;
    mbr.p[i].offset=DRV_HEADER+offset;
    mbr.p[i].size=tmppp->size-DRV_HEADER;
    offset+=tmppp->size;
    remaining-=tmppp->size;
    tmppp=tmppp->next;
  }
  if (!i) i++;
  if (tmppp!=&head) {
    mbr.p[i].active=0x80;
    mbr.p[i].start_head=0;
    mbr.p[i].start_cyl=0x101;
    mbr.p[i].type=0xF;
    mbr.p[i].end_head=0xFE;
    mbr.p[i].end_cyl=0xFFFF;
    mbr.p[i].offset=offset;
    mbr.p[i].size=remaining;
    ext_base=offset;
  }
  ATAWriteBlks(bd,&mbr,0,1);

  while (tmppp!=&head) {
    start_offset=offset;
    MemSet(&mbr,0,BLK_SIZE);
    mbr.signature=0xAA55;

    mbr.p[0].active=0x80;
    mbr.p[0].start_head=1;
    mbr.p[0].start_cyl=0x101;
    mbr.p[0].type=1; //Will get set different.
    mbr.p[0].end_head=0xFE;
    mbr.p[0].end_cyl=0xFFFF;
    mbr.p[0].offset=DRV_HEADER;
    mbr.p[0].size=tmppp->size-DRV_HEADER;
    offset+=tmppp->size;
    tmppp=tmppp->next;
    if (tmppp!=&head) {
      mbr.p[1].active=0x80;
      mbr.p[1].start_head=0;
      mbr.p[1].start_cyl=0x101;
      mbr.p[1].type=5;
      mbr.p[1].end_head=0xFE;
      mbr.p[1].end_cyl=0xFFFF;
      mbr.p[1].offset=offset-ext_base;
      mbr.p[1].size=tmppp->size;
    }
    ATAWriteBlks(bd,&mbr,start_offset,1);
  }

  bd->flags&=~(BDF_INITIALIZED | BDF_INIT_IN_PROGRESS);
  BlkDevAdd(bd,,FALSE,TRUE);
  for (i=bd->first_drv_let;i<drv_let2;i++)
    Fmt(i,,FALSE);

    pd_done:
  while (head.next!=&head) {
    tmppp=head.next;
    QueRem(tmppp);
    Free(tmppp);
  }
  return total;
}


// Source: D:\TempleOS-Projects\html\silver-Sup1-Sup1Hymns-Home.html
// Date: unknown-date
// Language: HolyC

//5 has words
U0 Song()
{
  Fs->task_end_cb=&SndTaskEndCB;
  MusicSettingsRst;
  music.tempo= 2.480;
  music.stacatto_factor= 0.902;
  try {
    while (!ScanKey) {
      Play("5qF4GsGGGG5GFGF4qA5eD4G5etD4B5EsFCFC",
            "Love \0 \0 \0 \0 \0 \0ev\0 \0ery \0 \0sec\0ond.\n\0"
            " \0 \0 \0 \0 \0 \0 \0 \0");
      Play("5qF4GsGGGG5GFGF4qA5eD4G5etD4B5EsFCFC",
            "World -- \0 \0 \0 \0 \0 \0all \0 \0that \0 \0beck\0ons.\n\0"
            " \0 \0 \0 \0 \0 \0 \0 \0");
      Play("4qB5GFsE4A5E4A5qEFGeFC",
            " \0Life \0is \0too \0 \0 \0 \0prec\0i\0ous.\n\0 \0 \0");
      Play("4qB5GFsE4A5E4A5qEFGeFC",
            " \0Can \0be \0 \0 \0 \0 \0worr\0i\0ous.\n\0 \0 \0");
    }
  } catch
    PutExcept;
  Snd;
}

Song;

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\silver-Sup1-Sup1Hymns-Home.html
// Date: unknown-date
// Language: HolyC

//5 has words
U0 Song()
{
  Fs->task_end_cb=&SndTaskEndCB;
  MusicSettingsRst;
  music.tempo= 2.480;
  music.stacatto_factor= 0.902;
  try {
    while (!ScanKey) {
      Play("5qF4GsGGGG5GFGF4qA5eD4G5etD4B5EsFCFC",
            "Love \0 \0 \0 \0 \0 \0ev\0 \0ery \0 \0sec\0ond.\n\0"
            " \0 \0 \0 \0 \0 \0 \0 \0");
      Play("5qF4GsGGGG5GFGF4qA5eD4G5etD4B5EsFCFC",
            "World -- \0 \0 \0 \0 \0 \0all \0 \0that \0 \0beck\0ons.\n\0"
            " \0 \0 \0 \0 \0 \0 \0 \0");
      Play("4qB5GFsE4A5E4A5qEFGeFC",
            " \0Life \0is \0too \0 \0 \0 \0prec\0i\0ous.\n\0 \0 \0");
      Play("4qB5GFsE4A5E4A5qEFGeFC",
            " \0Can \0be \0 \0 \0 \0 \0worr\0i\0ous.\n\0 \0 \0");
    }
  } catch
    PutExcept;
  Snd;
}

Song;


// Source: D:\TempleOS-Projects\html\Run-Sup1-Sup1Games-AfterEgypt-Home.html
// Date: unknown-date
// Language: HolyC

Cd(__DIR__);;
#include "Load"
AfterEgypt;

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\Run-Sup1-Sup1Games-AfterEgypt-Home.html
// Date: unknown-date
// Language: HolyC

Cd(__DIR__);;
#include "Load"
AfterEgypt;


// Source: D:\TempleOS-Projects\html\KHashA-Kernel.html
// Date: unknown-date
// Language: HolyC

asm {
//************************************
SYS_HASH_STR::
// IN:  RSI=Addr of string
// OUT: RAX
        XOR     RAX,RAX
        TEST    RSI,RSI
        JZ      @@15

        PUSH    RSI
        PUSH    RBX
        XOR     RBX,RBX
        JMP     @@10

@@05:   SHL1    RBX
        ADC     RBX,RAX
@@10:   LODSB
        TEST    AL,AL
        JNZ     @@05

        MOV     RAX,RBX
        SHR     RBX,16
        ADC     RAX,RBX
        POP     RBX
        POP     RSI

@@15:   RET
//************************************
SYS_HASH_SINGLE_TABLE_FIND1::
// IN:  RAX=HASHED STRING VAL
//      RSI=STR
//      RBX=TYPE MASK
//      RDI=TABLE
//      RCX=INSTANCE, NOT ZERO
// OUT: RAX=ENTRY OR ZERO NOT FOUND
//      RDX=POINTER TO POINTER TO ENTRY
//      RCX IF NOT FOUND ENOUGH, DECREMENTED BY NUM MATCHES
//      ZERO FLAG SET NOT FOUND
        MOV     RCX,1
SYS_HASH_SINGLE_TABLE_FIND::
        TEST    RCX,RCX
        JNZ     @@05
        XOR     RAX,RAX
        RET
@@05:   AND     RAX,U64 CHashTable.mask[RDI]
        MOV     RDX,U64 CHashTable.body[RDI]
        LEA     RDX,U64 [RDX+RAX*8]
@@10:   MOV     RAX,U64 [RDX]
        TEST    RAX,RAX
        JNZ     @@15
        RET

@@15:   TEST    U32 CHash.type[RAX],EBX
        JZ      @@30
        PUSH    RAX
        PUSH    RDI
        PUSH    RSI
        MOV     RDI,U64 CHash.str[RAX]
@@20:   LODSB
        CMP     U8 [RDI],AL
        JNE     @@25
        INC     RDI
        TEST    AL,AL
        JNZ     @@20
        POP     RSI
        POP     RDI
        POP     RAX
        LOOP    @@30
        INC     U32 CHash.use_cnt[RAX]
        TEST    RAX,RAX
        RET

@@25:   POP     RSI
        POP     RDI
        POP     RAX

@@30:   LEA     RDX,U64 CHash.next[RAX]
        JMP     @@10
//************************************
SYS_HASH_FIND1::
// IN:  RSI=STR
//      RBX=TYPE MASK
//      RDI=TABLE
//      RCX=INSTANCE NUM
// OUT: RAX=ENTRY OR ZERO NOT FOUND
//      ZERO FLAG SET NOT FOUND
        MOV     RCX,1
SYS_HASH_FIND::
        PUSH    RDI
        CALL    SYS_HASH_STR

@@05:   PUSH    RAX
        CALL    SYS_HASH_SINGLE_TABLE_FIND
        JNZ     @@15
        POP     RAX
@@10:   MOV     RDI,U64 CHashTable.next[RDI]
        TEST    RDI,RDI
        JNZ     @@05
        POP     RDI
        XOR     RAX,RAX
        RET

@@15:   ADD     RSP,8
        POP     RDI
        TEST    RAX,RAX
        RET
//************************************
SYS_HASH_BUCKET_FIND::
// IN:  RSI=STR
//      RDI=TABLE
// OUT: RAX=BUCKET
        PUSH    RDX
        CALL    SYS_HASH_STR
        AND     RAX,U64 CHashTable.mask[RDI]
        MOV     RDX,U64 CHashTable.body[RDI]
        LEA     RAX,U64 [RDX+RAX*8]
        POP     RDX
        RET
_HASH_STR::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        MOV     RSI,U64 SF_ARG1[RBP]
        CALL    SYS_HASH_STR
        POP     RSI
        POP     RBP
        RET1    8
_HASH_FIND::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RSI,U64 SF_ARG1[RBP]
        MOV     RDI,U64 SF_ARG2[RBP]
        MOV     RBX,U64 SF_ARG3[RBP]
        MOV     RCX,U64 SF_ARG4[RBP]
        CALL    SYS_HASH_FIND
        POP     RDI
        POP     RSI
        POP     RBP
        RET1    32
_HASH_SINGLE_TABLE_FIND::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RSI,U64 SF_ARG1[RBP]
        MOV     RDI,U64 SF_ARG2[RBP]
        MOV     RBX,U64 SF_ARG3[RBP]
        MOV     RCX,U64 SF_ARG4[RBP]
        CALL    SYS_HASH_STR
        CALL    SYS_HASH_SINGLE_TABLE_FIND
        POP     RDI
        POP     RSI
        POP     RBP
        RET1    32
_HASH_BUCKET_FIND::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RSI,U64 SF_ARG1[RBP]
        MOV     RDI,U64 SF_ARG2[RBP]
        CALL    SYS_HASH_BUCKET_FIND
        POP     RDI
        POP     RSI
        POP     RBP
        RET1    16
_HASH_ADD::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RCX,U64 SF_ARG1[RBP]
        MOV     RSI,U64 CHash.str[RCX]
        MOV     RDI,U64 SF_ARG2[RBP]
        CALL    SYS_HASH_BUCKET_FIND
        MOV     RCX,U64 SF_ARG1[RBP]
        PUSHFD
        CLI
        MOV     RBX,U64 [RAX]
        MOV     U64 CHash.next[RCX],RBX
        MOV     U64 [RAX],RCX

        POPFD
        POP     RDI
        POP     RSI
        POP     RBP
        RET1    16
_HASH_ADD_AFTER::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RDI
        MOV     RCX,U64 SF_ARG1[RBP]
        MOV     RDI,U64 SF_ARG3[RBP]
        PUSHFD
        CLI
        MOV     RAX,SF_ARG2[RBP]
        MOV     RBX,U64 [RAX]
        MOV     U64 CHash.next[RCX],RBX
        MOV     U64 [RAX],RCX

        POPFD
        POP     RDI
        POP     RBP
        RET1    24
_HASH_REM_DEL::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RCX,U64 SF_ARG1[RBP]
        TEST    RCX,RCX
        JZ      @@10
        MOV     RSI,U64 CHash.str[RCX]
        XOR     RBX,RBX
        MOV     EBX,U32 CHash.type[RCX]
        AND     EBX,~HTG_FLAGS_MASK&0xFFFFFFFF
        MOV     RDI,U64 SF_ARG2[RBP]
        MOV     RCX,U64 SF_ARG3[RBP]
        CALL    SYS_HASH_STR

        PUSHFD
        CLI
        CALL    SYS_HASH_SINGLE_TABLE_FIND
        JZ      @@05
        CMP     RAX,U64 SF_ARG1[RBP]
        JNE     @@05

        MOV     RBX,U64 CHash.next[RAX]
        MOV     U64 [RDX],RBX

        POPFD

        PUSH_C_REGS
        PUSH    RAX
        CALL    &HashDel
        POP_C_REGS

        POP     RDI
        POP     RSI
        MOV     RAX,1
        POP     RBP
        RET1    24

@@05:   POPFD
@@10:   POP     RDI
        POP     RSI
        XOR     RAX,RAX
        POP     RBP
        RET1    24
}

_extern _HASH_STR I64 HashStr(U8 *st); //Hash a string.
_extern _HASH_FIND CHash *HashFind(U8 *needle_str,CHashTable *haystack_table,
        I64 mask,I64 instance=1);//Find string in hash table.
_extern _HASH_SINGLE_TABLE_FIND CHash *HashSingleTableFind(U8 *needle_str,
        CHashTable *haystack_table,
        I64 mask,I64 instance=1);//Find string in single hash table.
_extern _HASH_BUCKET_FIND CHash **HashBucketFind(U8 *needle_str,
        CHashTable *haystack_table); //Find hash bucket.
_extern _HASH_ADD U0 HashAdd(CHash *tmph,
        CHashTable *table); //Add entry to hash table.
_extern _HASH_REM_DEL Bool HashRemDel(CHash *tmph,CHashTable *table,
        I64 instance=1);//Remove hash entry and del. Instance must match.

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\KHashA-Kernel.html
// Date: unknown-date
// Language: HolyC

asm {
//************************************
SYS_HASH_STR::
// IN:  RSI=Addr of string
// OUT: RAX
        XOR     RAX,RAX
        TEST    RSI,RSI
        JZ      @@15

        PUSH    RSI
        PUSH    RBX
        XOR     RBX,RBX
        JMP     @@10

@@05:   SHL1    RBX
        ADC     RBX,RAX
@@10:   LODSB
        TEST    AL,AL
        JNZ     @@05

        MOV     RAX,RBX
        SHR     RBX,16
        ADC     RAX,RBX
        POP     RBX
        POP     RSI

@@15:   RET
//************************************
SYS_HASH_SINGLE_TABLE_FIND1::
// IN:  RAX=HASHED STRING VAL
//      RSI=STR
//      RBX=TYPE MASK
//      RDI=TABLE
//      RCX=INSTANCE, NOT ZERO
// OUT: RAX=ENTRY OR ZERO NOT FOUND
//      RDX=POINTER TO POINTER TO ENTRY
//      RCX IF NOT FOUND ENOUGH, DECREMENTED BY NUM MATCHES
//      ZERO FLAG SET NOT FOUND
        MOV     RCX,1
SYS_HASH_SINGLE_TABLE_FIND::
        TEST    RCX,RCX
        JNZ     @@05
        XOR     RAX,RAX
        RET
@@05:   AND     RAX,U64 CHashTable.mask[RDI]
        MOV     RDX,U64 CHashTable.body[RDI]
        LEA     RDX,U64 [RDX+RAX*8]
@@10:   MOV     RAX,U64 [RDX]
        TEST    RAX,RAX
        JNZ     @@15
        RET

@@15:   TEST    U32 CHash.type[RAX],EBX
        JZ      @@30
        PUSH    RAX
        PUSH    RDI
        PUSH    RSI
        MOV     RDI,U64 CHash.str[RAX]
@@20:   LODSB
        CMP     U8 [RDI],AL
        JNE     @@25
        INC     RDI
        TEST    AL,AL
        JNZ     @@20
        POP     RSI
        POP     RDI
        POP     RAX
        LOOP    @@30
        INC     U32 CHash.use_cnt[RAX]
        TEST    RAX,RAX
        RET

@@25:   POP     RSI
        POP     RDI
        POP     RAX

@@30:   LEA     RDX,U64 CHash.next[RAX]
        JMP     @@10
//************************************
SYS_HASH_FIND1::
// IN:  RSI=STR
//      RBX=TYPE MASK
//      RDI=TABLE
//      RCX=INSTANCE NUM
// OUT: RAX=ENTRY OR ZERO NOT FOUND
//      ZERO FLAG SET NOT FOUND
        MOV     RCX,1
SYS_HASH_FIND::
        PUSH    RDI
        CALL    SYS_HASH_STR

@@05:   PUSH    RAX
        CALL    SYS_HASH_SINGLE_TABLE_FIND
        JNZ     @@15
        POP     RAX
@@10:   MOV     RDI,U64 CHashTable.next[RDI]
        TEST    RDI,RDI
        JNZ     @@05
        POP     RDI
        XOR     RAX,RAX
        RET

@@15:   ADD     RSP,8
        POP     RDI
        TEST    RAX,RAX
        RET
//************************************
SYS_HASH_BUCKET_FIND::
// IN:  RSI=STR
//      RDI=TABLE
// OUT: RAX=BUCKET
        PUSH    RDX
        CALL    SYS_HASH_STR
        AND     RAX,U64 CHashTable.mask[RDI]
        MOV     RDX,U64 CHashTable.body[RDI]
        LEA     RAX,U64 [RDX+RAX*8]
        POP     RDX
        RET
_HASH_STR::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        MOV     RSI,U64 SF_ARG1[RBP]
        CALL    SYS_HASH_STR
        POP     RSI
        POP     RBP
        RET1    8
_HASH_FIND::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RSI,U64 SF_ARG1[RBP]
        MOV     RDI,U64 SF_ARG2[RBP]
        MOV     RBX,U64 SF_ARG3[RBP]
        MOV     RCX,U64 SF_ARG4[RBP]
        CALL    SYS_HASH_FIND
        POP     RDI
        POP     RSI
        POP     RBP
        RET1    32
_HASH_SINGLE_TABLE_FIND::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RSI,U64 SF_ARG1[RBP]
        MOV     RDI,U64 SF_ARG2[RBP]
        MOV     RBX,U64 SF_ARG3[RBP]
        MOV     RCX,U64 SF_ARG4[RBP]
        CALL    SYS_HASH_STR
        CALL    SYS_HASH_SINGLE_TABLE_FIND
        POP     RDI
        POP     RSI
        POP     RBP
        RET1    32
_HASH_BUCKET_FIND::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RSI,U64 SF_ARG1[RBP]
        MOV     RDI,U64 SF_ARG2[RBP]
        CALL    SYS_HASH_BUCKET_FIND
        POP     RDI
        POP     RSI
        POP     RBP
        RET1    16
_HASH_ADD::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RCX,U64 SF_ARG1[RBP]
        MOV     RSI,U64 CHash.str[RCX]
        MOV     RDI,U64 SF_ARG2[RBP]
        CALL    SYS_HASH_BUCKET_FIND
        MOV     RCX,U64 SF_ARG1[RBP]
        PUSHFD
        CLI
        MOV     RBX,U64 [RAX]
        MOV     U64 CHash.next[RCX],RBX
        MOV     U64 [RAX],RCX

        POPFD
        POP     RDI
        POP     RSI
        POP     RBP
        RET1    16
_HASH_ADD_AFTER::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RDI
        MOV     RCX,U64 SF_ARG1[RBP]
        MOV     RDI,U64 SF_ARG3[RBP]
        PUSHFD
        CLI
        MOV     RAX,SF_ARG2[RBP]
        MOV     RBX,U64 [RAX]
        MOV     U64 CHash.next[RCX],RBX
        MOV     U64 [RAX],RCX

        POPFD
        POP     RDI
        POP     RBP
        RET1    24
_HASH_REM_DEL::
        PUSH    RBP
        MOV     RBP,RSP
        PUSH    RSI
        PUSH    RDI
        MOV     RCX,U64 SF_ARG1[RBP]
        TEST    RCX,RCX
        JZ      @@10
        MOV     RSI,U64 CHash.str[RCX]
        XOR     RBX,RBX
        MOV     EBX,U32 CHash.type[RCX]
        AND     EBX,~HTG_FLAGS_MASK&0xFFFFFFFF
        MOV     RDI,U64 SF_ARG2[RBP]
        MOV     RCX,U64 SF_ARG3[RBP]
        CALL    SYS_HASH_STR

        PUSHFD
        CLI
        CALL    SYS_HASH_SINGLE_TABLE_FIND
        JZ      @@05
        CMP     RAX,U64 SF_ARG1[RBP]
        JNE     @@05

        MOV     RBX,U64 CHash.next[RAX]
        MOV     U64 [RDX],RBX

        POPFD

        PUSH_C_REGS
        PUSH    RAX
        CALL    &HashDel
        POP_C_REGS

        POP     RDI
        POP     RSI
        MOV     RAX,1
        POP     RBP
        RET1    24

@@05:   POPFD
@@10:   POP     RDI
        POP     RSI
        XOR     RAX,RAX
        POP     RBP
        RET1    24
}

_extern _HASH_STR I64 HashStr(U8 *st); //Hash a string.
_extern _HASH_FIND CHash *HashFind(U8 *needle_str,CHashTable *haystack_table,
        I64 mask,I64 instance=1);//Find string in hash table.
_extern _HASH_SINGLE_TABLE_FIND CHash *HashSingleTableFind(U8 *needle_str,
        CHashTable *haystack_table,
        I64 mask,I64 instance=1);//Find string in single hash table.
_extern _HASH_BUCKET_FIND CHash **HashBucketFind(U8 *needle_str,
        CHashTable *haystack_table); //Find hash bucket.
_extern _HASH_ADD U0 HashAdd(CHash *tmph,
        CHashTable *table); //Add entry to hash table.
_extern _HASH_REM_DEL Bool HashRemDel(CHash *tmph,CHashTable *table,
        I64 instance=1);//Remove hash entry and del. Instance must match.


// Source: D:\TempleOS-Projects\html\OptPass5-Compiler.html
// Date: unknown-date
// Language: HolyC

U0 OptPass5(CCmpCtrl *cc)
{
  CIntermediateCode *tmpi,*tmpi1;
  I64 code,i;
  CPrsStk *ps=cc->ps;
  ps->ptr=0;
  ps->ptr2=0;

  tmpi=cc->coc.coc_head.next;
  while (code=tmpi->ic_code) {
    if (code>IC_NOP2) {
      if (tmpi->ic_flags&ICF_PASS_TRACE) {
        if (Bt(&cc->saved_pass_trace,5)) {
          "%2d:",ps->ptr;
          ICPut(cc,tmpi);
        }
      }
      if (intermediate_code_table[code].arg_cnt==IS_V_ARG)
        ps->ptr-=tmpi->ic_data>>3;
      if (code==IC_PUSH_REGS) {
        for (i=0;i<REG_REGS_NUM;i++)
          if (Bt(&tmpi->ic_data,i))
            ps->ptr++;
      } else if (code==IC_POP_REGS) {
        for (i=0;i<REG_REGS_NUM;i++)
          if (Bt(&tmpi->ic_data,i))
            ps->ptr--;
      }
      if (tmpi->arg2.type&MDF_STK) {
        tmpi1=PrsPop(ps);
        if (tmpi1->ic_code==IC_MOV || tmpi1->ic_code==IC_REG) {
          if (tmpi1->ic_flags & ICF_RES_TO_INT) {
            if (tmpi1->arg1.type&MDF_IMM)
              tmpi1->arg1.disp=tmpi1->arg1.disp(F64);
            else
              tmpi->ic_flags|=ICF_ARG2_TO_INT;
          } else if (tmpi1->ic_flags&ICF_RES_TO_F64) {
            if (tmpi1->arg1.type&MDF_IMM)
              tmpi1->arg1.disp(F64)=tmpi1->arg1.disp;
            else
              tmpi->ic_flags|=ICF_ARG2_TO_F64;
          }
          tmpi->arg2.type=tmpi1->arg1.type&MDG_MASK+
                MinI64(tmpi->arg2.type.raw_type,
                MinI64(tmpi1->res.type.raw_type,tmpi1->arg1.type.raw_type));
          tmpi->arg2.reg=tmpi1->arg1.reg;
          tmpi->arg2.disp=tmpi1->arg1.disp;
          tmpi->ic_flags|=tmpi1->ic_flags&ICG_NO_CVT_MASK;
          OptSetNOP2(tmpi1);
        }
      }

      if (tmpi->arg1.type&MDF_STK) {
        tmpi1=PrsPop(ps);
        if (tmpi1->ic_code==IC_MOV || tmpi1->ic_code==IC_REG) {
          if (tmpi1->ic_flags & ICF_RES_TO_INT) {
            if (tmpi1->arg1.type&MDF_IMM)
              tmpi1->arg1.disp=tmpi1->arg1.disp(F64);
            else
              tmpi->ic_flags|=ICF_ARG1_TO_INT;
          } else if (tmpi1->ic_flags&ICF_RES_TO_F64) {
            if (tmpi1->arg1.type&MDF_IMM) {
              if (tmpi1->arg1.type&RTF_UNSIGNED)
                tmpi1->arg1.disp(F64)=tmpi1->arg1.disp(U64);
              else
                tmpi1->arg1.disp(F64)=tmpi1->arg1.disp(I64);
            } else
              tmpi->ic_flags|=ICF_ARG1_TO_F64;
          }
          tmpi->arg1.type=tmpi1->arg1.type&MDG_MASK+
                MinI64(tmpi->arg1.type.raw_type,
                MinI64(tmpi1->res.type.raw_type,tmpi1->arg1.type.raw_type));
          CmpMinTypePointed(tmpi,tmpi1->arg1_type_pointed_to);
          tmpi->arg1.reg=tmpi1->arg1.reg;
          tmpi->arg1.disp=tmpi1->arg1.disp;
          tmpi->ic_flags|=tmpi1->ic_flags&ICG_NO_CVT_MASK;
          OptSetNOP2(tmpi1);
        }
      }
      if (tmpi->res.type&MDF_STK &&
            !(tmpi->ic_flags&ICF_RES_NOT_USED))
        PrsPush(ps,tmpi);
    }
    tmpi=tmpi->next;
  }
  if (ps->ptr>2) {
    "Pass:%d Stk:%08X\n",cc->pass,ps->ptr;
    LexExcept(cc,"Compiler Optimization Error at ");
  }
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\OptPass5-Compiler.html
// Date: unknown-date
// Language: HolyC

U0 OptPass5(CCmpCtrl *cc)
{
  CIntermediateCode *tmpi,*tmpi1;
  I64 code,i;
  CPrsStk *ps=cc->ps;
  ps->ptr=0;
  ps->ptr2=0;

  tmpi=cc->coc.coc_head.next;
  while (code=tmpi->ic_code) {
    if (code>IC_NOP2) {
      if (tmpi->ic_flags&ICF_PASS_TRACE) {
        if (Bt(&cc->saved_pass_trace,5)) {
          "%2d:",ps->ptr;
          ICPut(cc,tmpi);
        }
      }
      if (intermediate_code_table[code].arg_cnt==IS_V_ARG)
        ps->ptr-=tmpi->ic_data>>3;
      if (code==IC_PUSH_REGS) {
        for (i=0;i<REG_REGS_NUM;i++)
          if (Bt(&tmpi->ic_data,i))
            ps->ptr++;
      } else if (code==IC_POP_REGS) {
        for (i=0;i<REG_REGS_NUM;i++)
          if (Bt(&tmpi->ic_data,i))
            ps->ptr--;
      }
      if (tmpi->arg2.type&MDF_STK) {
        tmpi1=PrsPop(ps);
        if (tmpi1->ic_code==IC_MOV || tmpi1->ic_code==IC_REG) {
          if (tmpi1->ic_flags & ICF_RES_TO_INT) {
            if (tmpi1->arg1.type&MDF_IMM)
              tmpi1->arg1.disp=tmpi1->arg1.disp(F64);
            else
              tmpi->ic_flags|=ICF_ARG2_TO_INT;
          } else if (tmpi1->ic_flags&ICF_RES_TO_F64) {
            if (tmpi1->arg1.type&MDF_IMM)
              tmpi1->arg1.disp(F64)=tmpi1->arg1.disp;
            else
              tmpi->ic_flags|=ICF_ARG2_TO_F64;
          }
          tmpi->arg2.type=tmpi1->arg1.type&MDG_MASK+
                MinI64(tmpi->arg2.type.raw_type,
                MinI64(tmpi1->res.type.raw_type,tmpi1->arg1.type.raw_type));
          tmpi->arg2.reg=tmpi1->arg1.reg;
          tmpi->arg2.disp=tmpi1->arg1.disp;
          tmpi->ic_flags|=tmpi1->ic_flags&ICG_NO_CVT_MASK;
          OptSetNOP2(tmpi1);
        }
      }

      if (tmpi->arg1.type&MDF_STK) {
        tmpi1=PrsPop(ps);
        if (tmpi1->ic_code==IC_MOV || tmpi1->ic_code==IC_REG) {
          if (tmpi1->ic_flags & ICF_RES_TO_INT) {
            if (tmpi1->arg1.type&MDF_IMM)
              tmpi1->arg1.disp=tmpi1->arg1.disp(F64);
            else
              tmpi->ic_flags|=ICF_ARG1_TO_INT;
          } else if (tmpi1->ic_flags&ICF_RES_TO_F64) {
            if (tmpi1->arg1.type&MDF_IMM) {
              if (tmpi1->arg1.type&RTF_UNSIGNED)
                tmpi1->arg1.disp(F64)=tmpi1->arg1.disp(U64);
              else
                tmpi1->arg1.disp(F64)=tmpi1->arg1.disp(I64);
            } else
              tmpi->ic_flags|=ICF_ARG1_TO_F64;
          }
          tmpi->arg1.type=tmpi1->arg1.type&MDG_MASK+
                MinI64(tmpi->arg1.type.raw_type,
                MinI64(tmpi1->res.type.raw_type,tmpi1->arg1.type.raw_type));
          CmpMinTypePointed(tmpi,tmpi1->arg1_type_pointed_to);
          tmpi->arg1.reg=tmpi1->arg1.reg;
          tmpi->arg1.disp=tmpi1->arg1.disp;
          tmpi->ic_flags|=tmpi1->ic_flags&ICG_NO_CVT_MASK;
          OptSetNOP2(tmpi1);
        }
      }
      if (tmpi->res.type&MDF_STK &&
            !(tmpi->ic_flags&ICF_RES_NOT_USED))
        PrsPush(ps,tmpi);
    }
    tmpi=tmpi->next;
  }
  if (ps->ptr>2) {
    "Pass:%d Stk:%08X\n",cc->pass,ps->ptr;
    LexExcept(cc,"Compiler Optimization Error at ");
  }
}


// Source: D:\TempleOS-Projects\html\TOS-Opt-Utils-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Misc/TOS"

U0 TOSStaffIns()
{//Completes TOS install from TempleOSStaff.ISO
  SettingsPush; //See SettingsPush
  AutoComplete;
  WinBorder;
  WinMax;
  DocClear;
  "$PURPLE$$TX+CX,\"Complete TOS install from TempleOSStaff.ISO\"$$FG$\n\n\n\n";
  InsRereg;

  "\nDownload TempleOSSup1.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSBooks1.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSBooks2.ISO.C\tfrom http://www.templeos.org AppStore.\n\n";

  if (PressAKey!=CH_SHIFT_ESC) {
    if (HostChgDsk("/home/tad/TempleOSSup1.ISO.C"))
      CopyTree("T:/","~/Sup1");
    if (HostChgDsk("/home/tad/TempleOSBooks1.ISO.C"))
      CopyTree("T:/","~/Books1");
    if (HostChgDsk("/home/tad/TempleOSBooks2.ISO.C"))
      CopyTree("T:/","~/Books2");

    Once("TOSBootHDIns;");
    "\nDo you wish to run >TOSRegen; to generate\n the "
    "distro ISO's and the website image, D:/Wb ";
    if (YorN) {
      Once("TOSRegen;");
      BootRAM("C:/" KERNEL_BIN_C); //Boot so TOSRegen cmd is available.
    } else {
      "\nReboot ";
      if (YorN)
        Reboot;
    }
  }
  SettingsPop;
}

public U0 TOSStdIns()
{//Completes TOS install from TempleOSCD.ISO
  SettingsPush; //See SettingsPush
  AutoComplete;
  WinBorder;
  WinMax;
  DocClear;
  "$PURPLE$$TX+CX,\"Complete TOS install from TempleOSCD.ISO\"$$FG$\n\n\n\n";
  InsRereg;

  "\nDownload TempleOSSup1.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSWeb.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSBooks1.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSBooks2.ISO.C\tfrom http://www.templeos.org AppStore.\n\n";

  if (PressAKey!=CH_SHIFT_ESC) {
    if (FileFind("/Demo/AcctExample"))
      CopyTree("::/Demo/AcctExample","~");
    if (HostChgDsk("/home/tad/Downloads/TempleOSSup1.ISO.C"))
      CopyTree("T:/","~/Sup1");
    if (HostChgDsk("/home/tad/Downloads/TempleOSWeb.ISO.C"))
      CopyTree("T:/","~/Web");
    if (HostChgDsk("/home/tad/Downloads/TempleOSBooks1.ISO.C"))
      CopyTree("T:/","~/Books1");
    if (HostChgDsk("/home/tad/Downloads/TempleOSBooks2.ISO.C"))
      CopyTree("T:/","~/Books2");

    Once("TOSBootHDIns;");
    "\nDo you wish to run >TOSRegen; to generate\n the "
    "distro ISO's and the website image, D:/Wb ";
    if (YorN) {
      Once("TOSRegen;");
      BootRAM("C:/" KERNEL_BIN_C); //Boot so TOSRegen cmd is available.
    } else {
      "\nReboot ";
      if (YorN)
        Reboot;
    }
  }
  SettingsPop;
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\TOS-Opt-Utils-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Misc/TOS"

U0 TOSStaffIns()
{//Completes TOS install from TempleOSStaff.ISO
  SettingsPush; //See SettingsPush
  AutoComplete;
  WinBorder;
  WinMax;
  DocClear;
  "$PURPLE$$TX+CX,\"Complete TOS install from TempleOSStaff.ISO\"$$FG$\n\n\n\n";
  InsRereg;

  "\nDownload TempleOSSup1.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSBooks1.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSBooks2.ISO.C\tfrom http://www.templeos.org AppStore.\n\n";

  if (PressAKey!=CH_SHIFT_ESC) {
    if (HostChgDsk("/home/tad/TempleOSSup1.ISO.C"))
      CopyTree("T:/","~/Sup1");
    if (HostChgDsk("/home/tad/TempleOSBooks1.ISO.C"))
      CopyTree("T:/","~/Books1");
    if (HostChgDsk("/home/tad/TempleOSBooks2.ISO.C"))
      CopyTree("T:/","~/Books2");

    Once("TOSBootHDIns;");
    "\nDo you wish to run >TOSRegen; to generate\n the "
    "distro ISO's and the website image, D:/Wb ";
    if (YorN) {
      Once("TOSRegen;");
      BootRAM("C:/" KERNEL_BIN_C); //Boot so TOSRegen cmd is available.
    } else {
      "\nReboot ";
      if (YorN)
        Reboot;
    }
  }
  SettingsPop;
}

public U0 TOSStdIns()
{//Completes TOS install from TempleOSCD.ISO
  SettingsPush; //See SettingsPush
  AutoComplete;
  WinBorder;
  WinMax;
  DocClear;
  "$PURPLE$$TX+CX,\"Complete TOS install from TempleOSCD.ISO\"$$FG$\n\n\n\n";
  InsRereg;

  "\nDownload TempleOSSup1.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSWeb.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSBooks1.ISO.C\tfrom http://www.templeos.org AppStore.\n"
  "Download TempleOSBooks2.ISO.C\tfrom http://www.templeos.org AppStore.\n\n";

  if (PressAKey!=CH_SHIFT_ESC) {
    if (FileFind("/Demo/AcctExample"))
      CopyTree("::/Demo/AcctExample","~");
    if (HostChgDsk("/home/tad/Downloads/TempleOSSup1.ISO.C"))
      CopyTree("T:/","~/Sup1");
    if (HostChgDsk("/home/tad/Downloads/TempleOSWeb.ISO.C"))
      CopyTree("T:/","~/Web");
    if (HostChgDsk("/home/tad/Downloads/TempleOSBooks1.ISO.C"))
      CopyTree("T:/","~/Books1");
    if (HostChgDsk("/home/tad/Downloads/TempleOSBooks2.ISO.C"))
      CopyTree("T:/","~/Books2");

    Once("TOSBootHDIns;");
    "\nDo you wish to run >TOSRegen; to generate\n the "
    "distro ISO's and the website image, D:/Wb ";
    if (YorN) {
      Once("TOSRegen;");
      BootRAM("C:/" KERNEL_BIN_C); //Boot so TOSRegen cmd is available.
    } else {
      "\nReboot ";
      if (YorN)
        Reboot;
    }
  }
  SettingsPop;
}


// Source: D:\TempleOS-Projects\html\AMem-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Memory/Task"
public I64 TaskMemAlloced(CTask *task=NULL,Bool override_validate=FALSE)
{//Count of bytes alloced to a task, used+unused.
  I64 res;
  if (!task) task=Fs;
  if (override_validate || TaskValidate(task)) {
    res=task->code_heap->alloced_u8s;
    if (task->code_heap!=task->data_heap)
      res+=task->data_heap->alloced_u8s;
    return res;
  } else
    return 0;
}

public I64 TaskMemUsed(CTask *task=NULL,Bool override_validate=FALSE)
{//Count of bytes alloced to a task and in use.
  I64 res;
  if (!task) task=Fs;
  if (override_validate || TaskValidate(task)) {
    res=task->code_heap->used_u8s;
    if (task->data_heap!=task->code_heap)
      res+=task->data_heap->used_u8s;
    return res;
  } else
    return 0;
}

#help_index "Memory/Task;Debugging/Heap;Memory/Debugging"
public Bool HeapRep(CTask *task)
{//Report status of task's heap.
  I64 i,cnt;
  CMemUnused *uum;

  if (!task || task==Fs) {
    "Task can't HeapRep on self.\n";
    return FALSE;
  }
  if (!TaskValidate(task)) return FALSE;

  PUSHFD
  CLI
  while (LBts(&task->code_heap->locked_flags,HClf_LOCKED))
    PAUSE
  if (task->data_heap!=task->code_heap)
    while (LBts(&task->data_heap->locked_flags,HClf_LOCKED))
      PAUSE

  for (i=0;i<MEM_HEAP_HASH_SIZE>>3;i++) {
    cnt=0;
    uum=task->code_heap->heap_hash[i];
    while (uum) {
      cnt+=uum->size;
      uum=uum->next;
    }
    if (task->data_heap!=task->code_heap) {
      uum=task->data_heap->heap_hash[i];
      while (uum) {
        cnt+=uum->size;
        uum=uum->next;
      }
    }
    if (cnt)
      "%03X:%08X\n",i<<3,cnt;
  }
  '\n';

  uum=task->code_heap->malloc_free_lst;
  while (uum) {
    "%X, ",uum->size;
    uum=uum->next;
  }
  if (task->data_heap!=task->code_heap) {
    uum=task->data_heap->malloc_free_lst;
    while (uum) {
      "%X, ",uum->size;
      uum=uum->next;
    }
  }

  if (task->data_heap!=task->code_heap)
    LBtr(&task->data_heap->locked_flags,HClf_LOCKED);
  LBtr(&task->code_heap->locked_flags,HClf_LOCKED);
  POPFD

  '\n';
}

#help_index "Memory/HeapCtrl;Debugging/Heap;Memory/Debugging"
public Bool IsInHeapCtrl(U8 *a,CHeapCtrl *hc,Bool lock=TRUE)
{//Check addr if in HeapCtrl.
  CMemBlk *m;
  PUSHFD
  CLI
  if (lock)
    while (LBts(&hc->locked_flags,HClf_LOCKED))
      PAUSE
  m=hc->next_mem_blk;
  while (m!=&hc->next_mem_blk) {
    if (a>=m && a<m(U8 *)+m->pags<<MEM_PAG_BITS) {
      if (lock)
        LBtr(&hc->locked_flags,HClf_LOCKED);
      POPFD
      return TRUE;
    }
    m=m->next;
  }
  if (lock)
    LBtr(&hc->locked_flags,HClf_LOCKED);
  POPFD
  return FALSE;
}

public Bool HeapCtrlWalk(CHeapCtrl *hc)
{//Check integrity of HeapCtrl.
  I64 i;
  CMemUnused *uum;

  PUSHFD
  CLI
  while (LBts(&hc->locked_flags,HClf_LOCKED))
    PAUSE

  for (i=0;i<MEM_HEAP_HASH_SIZE>>3;i++) {
    uum=hc->heap_hash[i];
    while (uum) {
      if (!IsInHeapCtrl(uum,hc,FALSE))
        goto hc_false;
      uum=uum->next;
    }
  }
  uum=hc->malloc_free_lst;
  while (uum) {
    if (!IsInHeapCtrl(uum,hc,FALSE))
      goto hc_false;
    uum=uum->next;
  }

  #if _CFG_HEAP_DBG
  CMemUsed *um,*um1;
  um1=(&hc->next_um)(U8 *)-offset(CMemUsed.next);
  um=um1->next;
  while (um!=um1) {
    if (!IsInHeapCtrl(um,hc,FALSE))
      goto hc_false;
    um=um->next;
  }
#endif

  LBtr(&hc->locked_flags,HClf_LOCKED);
  POPFD
  return TRUE;

  hc_false:
  LBtr(&hc->locked_flags,HClf_LOCKED);
  POPFD
  return FALSE;
}

#help_index "Memory/Task;Debugging/Heap;Memory/Debugging"
public Bool IsInHeap(U8 *a,CTask *task=NULL,Bool lock=TRUE)
{//Check addr if in task's heaps.
  if (!task) task=Fs;
  if (TaskValidate(task) && (IsInHeapCtrl(a,task->code_heap,lock)||
        task->data_heap!=task->code_heap &&
        IsInHeapCtrl(a,task->data_heap,lock)))
    return TRUE;
  else
    return FALSE;
}

public Bool HeapWalk(CTask *task=NULL)
{//Check integrity of task's heaps.
  if (!task) task=Fs;
  if (!TaskValidate(task) || !HeapCtrlWalk(task->code_heap) ||
        task->data_heap!=task->code_heap && !HeapCtrlWalk(task->data_heap))
    return FALSE;
  else
    return TRUE;
}

[System] You are Terry Davis, the creator of TempleOS. Write HolyC code in your unique style.

[User] Please write some HolyC code.

[Assistant]
// Source: D:\TempleOS-Projects\html\AMem-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Memory/Task"
public I64 TaskMemAlloced(CTask *task=NULL,Bool override_validate=FALSE)
{//Count of bytes alloced to a task, used+unused.
  I64 res;
  if (!task) task=Fs;
  if (override_validate || TaskValidate(task)) {
    res=task->code_heap->alloced_u8s;
    if (task->code_heap!=task->data_heap)
      res+=task->data_heap->alloced_u8s;
    return res;
  } else
    return 0;
}

public I64 TaskMemUsed(CTask *task=NULL,Bool override_validate=FALSE)
{//Count of bytes alloced to a task and in use.
  I64 res;
  if (!task) task=Fs;
  if (override_validate || TaskValidate(task)) {
    res=task->code_heap->used_u8s;
    if (task->data_heap!=task->code_heap)
      res+=task->data_heap->used_u8s;
    return res;
  } else
    return 0;
}

#help_index "Memory/Task;Debugging/Heap;Memory/Debugging"
public Bool HeapRep(CTask *task)
{//Report status of task's heap.
  I64 i,cnt;
  CMemUnused *uum;

  if (!task || task==Fs) {
    "Task can't HeapRep on self.\n";
    return FALSE;
  }
  if (!TaskValidate(task)) return FALSE;

  PUSHFD
  CLI
  while (LBts(&task->code_heap->locked_flags,HClf_LOCKED))
    PAUSE
  if (task->data_heap!=task->code_heap)
    while (LBts(&task->data_heap->locked_flags,HClf_LOCKED))
      PAUSE

  for (i=0;i<MEM_HEAP_HASH_SIZE>>3;i++) {
    cnt=0;
    uum=task->code_heap->heap_hash[i];
    while (uum) {
      cnt+=uum->size;
      uum=uum->next;
    }
    if (task->data_heap!=task->code_heap) {
      uum=task->data_heap->heap_hash[i];
      while (uum) {
        cnt+=uum->size;
        uum=uum->next;
      }
    }
    if (cnt)
      "%03X:%08X\n",i<<3,cnt;
  }
  '\n';

  uum=task->code_heap->malloc_free_lst;
  while (uum) {
    "%X, ",uum->size;
    uum=uum->next;
  }
  if (task->data_heap!=task->code_heap) {
    uum=task->data_heap->malloc_free_lst;
    while (uum) {
      "%X, ",uum->size;
      uum=uum->next;
    }
  }

  if (task->data_heap!=task->code_heap)
    LBtr(&task->data_heap->locked_flags,HClf_LOCKED);
  LBtr(&task->code_heap->locked_flags,HClf_LOCKED);
  POPFD

  '\n';
}

#help_index "Memory/HeapCtrl;Debugging/Heap;Memory/Debugging"
public Bool IsInHeapCtrl(U8 *a,CHeapCtrl *hc,Bool lock=TRUE)
{//Check addr if in HeapCtrl.
  CMemBlk *m;
  PUSHFD
  CLI
  if (lock)
    while (LBts(&hc->locked_flags,HClf_LOCKED))
      PAUSE
  m=hc->next_mem_blk;
  while (m!=&hc->next_mem_blk) {
    if (a>=m && a<m(U8 *)+m->pags<<MEM_PAG_BITS) {
      if (lock)
        LBtr(&hc->locked_flags,HClf_LOCKED);
      POPFD
      return TRUE;
    }
    m=m->next;
  }
  if (lock)
    LBtr(&hc->locked_flags,HClf_LOCKED);
  POPFD
  return FALSE;
}

public Bool HeapCtrlWalk(CHeapCtrl *hc)
{//Check integrity of HeapCtrl.
  I64 i;
  CMemUnused *uum;

  PUSHFD
  CLI
  while (LBts(&hc->locked_flags,HClf_LOCKED))
    PAUSE

  for (i=0;i<MEM_HEAP_HASH_SIZE>>3;i++) {
    uum=hc->heap_hash[i];
    while (uum) {
      if (!IsInHeapCtrl(uum,hc,FALSE))
        goto hc_false;
      uum=uum->next;
    }
  }
  uum=hc->malloc_free_lst;
  while (uum) {
    if (!IsInHeapCtrl(uum,hc,FALSE))
      goto hc_false;
    uum=uum->next;
  }

  #if _CFG_HEAP_DBG
  CMemUsed *um,*um1;
  um1=(&hc->next_um)(U8 *)-offset(CMemUsed.next);
  um=um1->next;
  while (um!=um1) {
    if (!IsInHeapCtrl(um,hc,FALSE))
      goto hc_false;
    um=um->next;
  }
#endif

  LBtr(&hc->locked_flags,HClf_LOCKED);
  POPFD
  return TRUE;

  hc_false:
  LBtr(&hc->locked_flags,HClf_LOCKED);
  POPFD
  return FALSE;
}

#help_index "Memory/Task;Debugging/Heap;Memory/Debugging"
public Bool IsInHeap(U8 *a,CTask *task=NULL,Bool lock=TRUE)
{//Check addr if in task's heaps.
  if (!task) task=Fs;
  if (TaskValidate(task) && (IsInHeapCtrl(a,task->code_heap,lock)||
        task->data_heap!=task->code_heap &&
        IsInHeapCtrl(a,task->data_heap,lock)))
    return TRUE;
  else
    return FALSE;
}

public Bool HeapWalk(CTask *task=NULL)
{//Check integrity of task's heaps.
  if (!task) task=Fs;
  if (!TaskValidate(task) || !HeapCtrlWalk(task->code_heap) ||
        task->data_heap!=task->code_heap && !HeapCtrlWalk(task->data_heap))
    return FALSE;
  else
    return TRUE;
}