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

#help_index "Windows"

class CWallPaperGlbls
{
  I64   last_calc_idle_cnt,last_swap_cnter[MP_PROCESSORS_NUM];
  F64   last_calc_idle_delta_time;
  U8    top_line[STR_LEN];
  Bool  record;
} *wall=CAlloc(sizeof(CWallPaperGlbls));
wall->last_calc_idle_delta_time=1.0;

class CTaskWallPaperData
{
  I64   alloced_u8s,used_u8s;
  U8    caller_stk[STR_LEN-$];
};

U0 WallPaper(CTask *_task)
{
  I64 i,j,l=TEXT_ROWS-1;
  CTask *task;
  CTaskWallPaperData *wpd;
  CHashTable *old_hash=Fs->hash_table;
  CCPU *c;
  CDateStruct ds;
  U8 *st;
  _task->text_attr=BLUE<<4+WHITE;
  if (sys_data_bp) {
    TextPrint(Fs,0,l--,BLUE<<4+YELLOW,
          "%010X/%010X %010X/%010X%12td%12td%12td",
          sys_data_bp->used_u8s,sys_data_bp->alloced_u8s,
          sys_code_bp->used_u8s,sys_code_bp->alloced_u8s,
          cmp.compiled_lines,blkdev.read_cnt,blkdev.write_cnt);
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,
          "______Data_Heap______ ______Code_Heap______ "
          "___Lines___ ___Reads___ __Writes___");
  } else {
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,
          "%010X/%010X%12td%12td%12td",
          sys_code_bp->used_u8s,sys_code_bp->alloced_u8s,
          cmp.compiled_lines,blkdev.read_cnt,blkdev.write_cnt);
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,
          "____CodeData_Heap____ "
          "___Lines___ ___Reads___ ___Writes__");
  }
  TextPrint(Fs,0,l--,BLUE<<4+WHITE,"ProgressBars:%016X %016X %016X %016X",
        progress1,progress2,progress3,progress4);
  for (i=0;i<mp_cnt;i++) {
    c=&cpu_structs[i];
    if (winmgr.t->calc_idle_cnt!=wall->last_calc_idle_cnt) {
      wall->last_calc_idle_delta_time=winmgr.t->calc_idle_delta_time;
      wall->last_swap_cnter[i]=winmgr.t->last_swap_cnter[i];
      winmgr.t->last_swap_cnter[i]=c->swap_cnter;
    }

    task=c->seth_task;
    do {
      wpd=&task->wallpaper_data;
      if (!TaskValidate(task)) break;
      if (!(winmgr.updates&31)) {
        if (c==Gs)
          Fs->hash_table=task->hash_table;
        else //precaution
          Fs->hash_table=old_hash;
        StrPrint(wpd->caller_stk,"    %-18tp %-18tp %-18tp %-18tp",
              TaskCaller(task,0),TaskCaller(task,1),
              TaskCaller(task,2),TaskCaller(task,3));
      }
      TextPrint(Fs,0,l--,BLUE<<4+YELLOW,wpd->caller_stk);
      j=UnusedStk(task);
      if (j<0)
        Panic("Stk Overflow",task);
      if (!(winmgr.updates&31)) {
        wpd->alloced_u8s=TaskMemAlloced(task);
        wpd->used_u8s   =TaskMemUsed(task);
      }
      TextPrint(Fs,0,l--,BLUE<<4+BROWN,
            "  %-18ts #%08X %010X %010X/%010X %04X:%02tX:%08X",
            task->task_title,task,j,wpd->used_u8s,wpd->alloced_u8s,
            task->task_flags,task->display_flags,task->win_inhibit);
      if (!TaskValidate(task)) break;
      task=task->next_task;
    } while (task!=c->seth_task);
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,"CPU%02X %2tf%% ContextSwaps/s:%9,d",i,
          100.0*(1.0-c->idle_factor),ToI64((winmgr.t->last_swap_cnter[i]
          -wall->last_swap_cnter[i])/wall->last_calc_idle_delta_time));
  }
  TextPrint(Fs,0,l--,BLUE<<4+WHITE,
        "  ___Description____ #__Task__ UnusedStk_ _UsedMem__/_AllocMem_ "
        "______Flags_____");

  if (!(winmgr.updates&31) || !*wall->top_line) {
    Date2Struct(&ds,Now+local_time_offset);
    i=sys_code_bp->alloced_u8s-sys_code_bp->used_u8s;
    if (sys_data_bp)
      i+=sys_data_bp->alloced_u8s-sys_data_bp->used_u8s;
    StrPrint(wall->top_line,
          "%3tZ %02d/%02d %02d:%02d:%02d FPS:%2tf Mem:%010X CPU",
          ds.day_of_week,"ST_DAYS_OF_WEEK",ds.mon,ds.day_of_mon,
          ds.hour,ds.min,ds.sec,winmgr.fps,i);
  }
  TextPrint(Fs,0,0,BLUE<<4+WHITE,wall->top_line);

  if (wall->record)
    TextPrint(Fs,44-4,0,BLUE<<4+RED,"*");
  for (i=0;i<mp_cnt;i++) {
    c=&cpu_structs[i];
    if (i&1)
      TextPrint(Fs,44+i*2,0,BLUE<<4+WHITE,"%2tf",100.0*(1.0-c->idle_factor));
    else
      TextPrint(Fs,44+i*2,0,BLUE<<4+YELLOW,"%2tf",100.0*(1.0-c->idle_factor));
  }

  st=ScanCode2KeyName(kbd.last_down_scan_code);
  TextPrint(Fs,80-18,0,BLUE<<4+YELLOW,"%18ts",st);
  Free(st);

  Fs->hash_table=old_hash;
  wall->last_calc_idle_cnt=winmgr.t->calc_idle_cnt;
}

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

U0 DrawTermBttn(CDC *dc,CCtrl *c)
{
  if (Blink)
    Sprite3(dc,c->left,c->top,0,<1>);
}

U0 LeftClickTermBttn(CCtrl *,I64,I64,Bool down)
{
  if (down)
    User;
}

CCtrl *TermBttnNew()
{
  I64 min_x,max_x,min_y,max_y;
  CCtrl *c=ACAlloc(sizeof(CCtrl));

  c->win_task=sys_winmgr_task;
  c->flags=CTRLF_SHOW;
  c->type=CTRLT_GENERIC;
  c->draw_it=&DrawTermBttn;
  c->left_click=&LeftClickTermBttn;

  SpriteExtents(<1>,&min_x,&max_x,&min_y,&max_y);
//min must be zero
  c->left=sys_winmgr_task->pix_width-(max_x-min_x+1);
  c->right=c->left+(max_x-min_x+1)-1;
  c->top=sys_winmgr_task->pix_height-(max_y-min_y+1);
  c->bottom=c->top+(max_y-min_y+1)-1;

  QueIns(c,sys_winmgr_task->last_ctrl);
  TaskDerivedValsUpdate(sys_winmgr_task);

  return c;
}

U0 WallPaperInit()
{
  TermBttnNew;
  gr.fp_wall_paper=&WallPaper;
}

[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\WallPaper-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Windows"

class CWallPaperGlbls
{
  I64   last_calc_idle_cnt,last_swap_cnter[MP_PROCESSORS_NUM];
  F64   last_calc_idle_delta_time;
  U8    top_line[STR_LEN];
  Bool  record;
} *wall=CAlloc(sizeof(CWallPaperGlbls));
wall->last_calc_idle_delta_time=1.0;

class CTaskWallPaperData
{
  I64   alloced_u8s,used_u8s;
  U8    caller_stk[STR_LEN-$];
};

U0 WallPaper(CTask *_task)
{
  I64 i,j,l=TEXT_ROWS-1;
  CTask *task;
  CTaskWallPaperData *wpd;
  CHashTable *old_hash=Fs->hash_table;
  CCPU *c;
  CDateStruct ds;
  U8 *st;
  _task->text_attr=BLUE<<4+WHITE;
  if (sys_data_bp) {
    TextPrint(Fs,0,l--,BLUE<<4+YELLOW,
          "%010X/%010X %010X/%010X%12td%12td%12td",
          sys_data_bp->used_u8s,sys_data_bp->alloced_u8s,
          sys_code_bp->used_u8s,sys_code_bp->alloced_u8s,
          cmp.compiled_lines,blkdev.read_cnt,blkdev.write_cnt);
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,
          "______Data_Heap______ ______Code_Heap______ "
          "___Lines___ ___Reads___ __Writes___");
  } else {
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,
          "%010X/%010X%12td%12td%12td",
          sys_code_bp->used_u8s,sys_code_bp->alloced_u8s,
          cmp.compiled_lines,blkdev.read_cnt,blkdev.write_cnt);
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,
          "____CodeData_Heap____ "
          "___Lines___ ___Reads___ ___Writes__");
  }
  TextPrint(Fs,0,l--,BLUE<<4+WHITE,"ProgressBars:%016X %016X %016X %016X",
        progress1,progress2,progress3,progress4);
  for (i=0;i<mp_cnt;i++) {
    c=&cpu_structs[i];
    if (winmgr.t->calc_idle_cnt!=wall->last_calc_idle_cnt) {
      wall->last_calc_idle_delta_time=winmgr.t->calc_idle_delta_time;
      wall->last_swap_cnter[i]=winmgr.t->last_swap_cnter[i];
      winmgr.t->last_swap_cnter[i]=c->swap_cnter;
    }

    task=c->seth_task;
    do {
      wpd=&task->wallpaper_data;
      if (!TaskValidate(task)) break;
      if (!(winmgr.updates&31)) {
        if (c==Gs)
          Fs->hash_table=task->hash_table;
        else //precaution
          Fs->hash_table=old_hash;
        StrPrint(wpd->caller_stk,"    %-18tp %-18tp %-18tp %-18tp",
              TaskCaller(task,0),TaskCaller(task,1),
              TaskCaller(task,2),TaskCaller(task,3));
      }
      TextPrint(Fs,0,l--,BLUE<<4+YELLOW,wpd->caller_stk);
      j=UnusedStk(task);
      if (j<0)
        Panic("Stk Overflow",task);
      if (!(winmgr.updates&31)) {
        wpd->alloced_u8s=TaskMemAlloced(task);
        wpd->used_u8s   =TaskMemUsed(task);
      }
      TextPrint(Fs,0,l--,BLUE<<4+BROWN,
            "  %-18ts #%08X %010X %010X/%010X %04X:%02tX:%08X",
            task->task_title,task,j,wpd->used_u8s,wpd->alloced_u8s,
            task->task_flags,task->display_flags,task->win_inhibit);
      if (!TaskValidate(task)) break;
      task=task->next_task;
    } while (task!=c->seth_task);
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,"CPU%02X %2tf%% ContextSwaps/s:%9,d",i,
          100.0*(1.0-c->idle_factor),ToI64((winmgr.t->last_swap_cnter[i]
          -wall->last_swap_cnter[i])/wall->last_calc_idle_delta_time));
  }
  TextPrint(Fs,0,l--,BLUE<<4+WHITE,
        "  ___Description____ #__Task__ UnusedStk_ _UsedMem__/_AllocMem_ "
        "______Flags_____");

  if (!(winmgr.updates&31) || !*wall->top_line) {
    Date2Struct(&ds,Now+local_time_offset);
    i=sys_code_bp->alloced_u8s-sys_code_bp->used_u8s;
    if (sys_data_bp)
      i+=sys_data_bp->alloced_u8s-sys_data_bp->used_u8s;
    StrPrint(wall->top_line,
          "%3tZ %02d/%02d %02d:%02d:%02d FPS:%2tf Mem:%010X CPU",
          ds.day_of_week,"ST_DAYS_OF_WEEK",ds.mon,ds.day_of_mon,
          ds.hour,ds.min,ds.sec,winmgr.fps,i);
  }
  TextPrint(Fs,0,0,BLUE<<4+WHITE,wall->top_line);

  if (wall->record)
    TextPrint(Fs,44-4,0,BLUE<<4+RED,"*");
  for (i=0;i<mp_cnt;i++) {
    c=&cpu_structs[i];
    if (i&1)
      TextPrint(Fs,44+i*2,0,BLUE<<4+WHITE,"%2tf",100.0*(1.0-c->idle_factor));
    else
      TextPrint(Fs,44+i*2,0,BLUE<<4+YELLOW,"%2tf",100.0*(1.0-c->idle_factor));
  }

  st=ScanCode2KeyName(kbd.last_down_scan_code);
  TextPrint(Fs,80-18,0,BLUE<<4+YELLOW,"%18ts",st);
  Free(st);

  Fs->hash_table=old_hash;
  wall->last_calc_idle_cnt=winmgr.t->calc_idle_cnt;
}

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

U0 DrawTermBttn(CDC *dc,CCtrl *c)
{
  if (Blink)
    Sprite3(dc,c->left,c->top,0,<1>);
}

U0 LeftClickTermBttn(CCtrl *,I64,I64,Bool down)
{
  if (down)
    User;
}

CCtrl *TermBttnNew()
{
  I64 min_x,max_x,min_y,max_y;
  CCtrl *c=ACAlloc(sizeof(CCtrl));

  c->win_task=sys_winmgr_task;
  c->flags=CTRLF_SHOW;
  c->type=CTRLT_GENERIC;
  c->draw_it=&DrawTermBttn;
  c->left_click=&LeftClickTermBttn;

  SpriteExtents(<1>,&min_x,&max_x,&min_y,&max_y);
//min must be zero
  c->left=sys_winmgr_task->pix_width-(max_x-min_x+1);
  c->right=c->left+(max_x-min_x+1)-1;
  c->top=sys_winmgr_task->pix_height-(max_y-min_y+1);
  c->bottom=c->top+(max_y-min_y+1)-1;

  QueIns(c,sys_winmgr_task->last_ctrl);
  TaskDerivedValsUpdate(sys_winmgr_task);

  return c;
}

U0 WallPaperInit()
{
  TermBttnNew;
  gr.fp_wall_paper=&WallPaper;
}


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

#help_index "DolDoc/Output;StdOut/DolDoc"

CDocEntry *DocPutS(CDoc *doc,U8 *st)
{//Don't use this.  Use DocPrint().
//Does not handle partial Doc entries.
  //Returns last newly created dollar-sign CDocEntry or NULL.
  U8 *ptr=st,*ptr2,*st2,*ptr3,*ptr4,*src,
        *char_bmp;
  Bool unlock;
  I64 ch,j;
  CDocEntry *doc_e=NULL,*res=NULL,*doc_ce;
  if (!st || !doc && !(doc=DocPut) || doc->doc_signature!=DOC_SIGNATURE_VAL)
    return NULL;
  unlock=DocLock(doc);
  if (doc->flags & DOCF_PLAIN_TEXT_TABS)
    char_bmp=char_bmp_zero_cr_nl_cursor;
  else if (doc->flags & DOCF_PLAIN_TEXT)
    char_bmp=char_bmp_zero_tab_cr_nl_cursor;
  else
    char_bmp=char_bmp_zero_tab_cr_nl_cursor_dollar;
  doc_ce=doc->cur_entry;
  while (*ptr) {
    ptr2=ptr;
    do ch=*ptr++;
    while (!Bt(char_bmp,ch) || ch==CH_CURSOR && doc->flags&DOCF_NO_CURSOR);
    ptr--;
    if (!ch) {
      if (j=ptr-ptr2) {
        doc_e=DocEntryNewBase(doc,
              DOCT_TEXT|doc->settings_head.dft_text_attr<<8);
        if (doc->flags & DOCF_NO_CURSOR) {
          src=MAlloc(j+1);
          MemCpy(src,ptr2,j+1);
          StrUtil(src,SUF_REM_CTRL_CHARS);
          j=StrLen(src);
        } else
          src=ptr2;
        doc_e->tag=MAlloc(j+1,doc->mem_task);
        MemCpy(doc_e->tag,src,j+1);
        doc_e->max_col=j;
        DocInsEntry(doc,doc_e);
        if (doc->flags & DOCF_NO_CURSOR)
          Free(src);
      }
    } else {
      if (j=ptr-ptr2) {
        *ptr=0;
        doc_e=DocEntryNewBase(doc,
              DOCT_TEXT|doc->settings_head.dft_text_attr<<8);
        if (doc->flags & DOCF_NO_CURSOR) {
          src=MAlloc(j+1);
          MemCpy(src,ptr2,j+1);
          ptr3=src;
          ptr4=src;
          while (*ptr3)
            if (*ptr3!=CH_CURSOR)
              *ptr4++=*ptr3++;
            else
              ptr3++;
          *ptr4=0;
          j=ptr4-src;
        } else
          src=ptr2;
        doc_e->tag=MAlloc(j+1,doc->mem_task);
        MemCpy(doc_e->tag,src,j+1);
        doc_e->max_col=j;
        DocInsEntry(doc,doc_e);
        if (doc->flags & DOCF_NO_CURSOR)
          Free(src);
        *ptr=ch;
      }
      switch (ch) {
        case CH_CURSOR:
          doc_e=DocEntryNewBase(doc,
                DOCT_CURSOR|doc->settings_head.dft_text_attr<<8);
          DocInsEntry(doc,doc_e);
          ptr++;
          break;
        case '\t':
          doc_e=DocEntryNewBase(doc,
                DOCT_TAB|doc->settings_head.dft_text_attr<<8);
          DocInsEntry(doc,doc_e);
          ptr++;
          break;
        case '$':
          ptr++; //skip first dollar
          ptr2=ptr;
          while (*ptr && *ptr!='$')
            ptr++;
          if (*ptr) {
            *ptr=0; //zero second dollar
            if (ptr-1==ptr2 && *ptr2==CH_CURSOR) {
              doc_e=DocEntryNewBase(doc,
                    DOCT_CURSOR|doc->settings_head.dft_text_attr<<8);
              DocInsEntry(doc,doc_e);
              ptr2++;
            }
            if (ptr==ptr2) {
              doc_e=DocEntryNewBase(doc,
                    DOCT_TEXT|doc->settings_head.dft_text_attr<<8);
              doc_e->max_col=1;
              if (doc->flags & DOCF_DBL_DOLLARS)
                doc_e->tag=StrNew("$$",doc->mem_task);
              else
                doc_e->tag=StrNew("$",doc->mem_task);
              DocInsEntry(doc,doc_e);
            } else {
              st2=MAlloc(ptr-ptr2+1);
              ptr3=ptr2;
              ptr4=st2;
              while (ch=*ptr3++) {
                if (ch==CH_CURSOR) {
                  doc_e=DocEntryNewBase(doc,
                        DOCT_CURSOR|doc->settings_head.dft_text_attr<<8);
                  DocInsEntry(doc,doc_e);
                } else
                  *ptr4++=ch;
              }
              *ptr4=0;
              if (doc_e=PrsDollarCmd(doc,st2)) {
                res=doc_e;
                DocInsEntry(doc,doc_e);
              }
              Free(st2);
            }
            *ptr++='$';
          }
          break;
        default:
          doc_e=DocEntryNewBase(doc,
                DOCT_NEW_LINE|doc->settings_head.dft_text_attr<<8);
          DocInsEntry(doc,doc_e);
          if (ch=='\r')
            while (*ptr=='\r')
              ptr++;
          if (*ptr=='\n')
            ptr++;
          while (*ptr=='\r')
            ptr++;
      }
    }
  }
  if (unlock)
    DocUnlock(doc);
  return res;
}

public CDocEntry *DocPrint(CDoc *doc=NULL,U8 *fmt,...)
{//You must not print partial doc cmds.
//Returns last newly created dollar-sign CDocEntry or NULL.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  CDocEntry *res=DocPutS(doc,buf);
  Free(buf);
  return res;
}

public U0 DocPrintPartial(CDoc *doc=NULL,U8 *fmt,...)
{//Lets you print half a doc cmd, if you like.
  U8 *buf,*st,*src,*dst,*ptr,*ptr2;
  Bool unlock;
  CDocEntry *doc_ce,*doc_ne;
  I64 ch,i,j;
  if (!doc && !(doc=DocPut))
    return;
  buf=StrPrintJoin(NULL,fmt,argc,argv);
  ptr=buf;
  if (doc->user_put_s && (*doc->user_put_s)(doc,doc->user_put_data,buf)) {
    Free(buf);
    return;
  }
  unlock=DocLock(doc);
  if (doc->cur_entry->type_u8==DOCT_DATA)
    while (ch=*ptr++)
      DocPutKey(doc,ch,0);
  else
    while (ch=*ptr) {
      if (!Bt(char_bmp_safe_dollar,ch) ||
            doc->flags & (DOCF_OVERSTRIKE|DOCF_IN_DOLLAR)) {
        DocPutKey(doc,ch,0);
        ptr++;
      } else {
        ptr2=ptr++;
        while (TRUE) {
          ch=*ptr++;
          if (!Bt(char_bmp_safe_dollar,ch))
            break;
        }
        ptr--;
        *ptr=0;
        doc_ce=doc->cur_entry;
        j=ptr-ptr2;
        if (IsEditableText(doc_ce)) {
          dst=st=MAlloc(doc_ce->max_col+j+1,doc->mem_task);
          src=doc_ce->tag;
          i=doc->cur_col;
          doc->cur_col+=j;
          doc_ce->max_col+=j;
          while (i-->0)
            *dst++=*src++;
          while (j-->0)
            *dst++=*ptr2++;
          while (*dst++=*src++);
          Free(doc_ce->tag);
          doc_ce->tag=st;
        } else {
          doc_ne=DocEntryNewTag(doc,doc_ce,ptr2);

[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\DocPutS-DolDoc-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "DolDoc/Output;StdOut/DolDoc"

CDocEntry *DocPutS(CDoc *doc,U8 *st)
{//Don't use this.  Use DocPrint().
//Does not handle partial Doc entries.
  //Returns last newly created dollar-sign CDocEntry or NULL.
  U8 *ptr=st,*ptr2,*st2,*ptr3,*ptr4,*src,
        *char_bmp;
  Bool unlock;
  I64 ch,j;
  CDocEntry *doc_e=NULL,*res=NULL,*doc_ce;
  if (!st || !doc && !(doc=DocPut) || doc->doc_signature!=DOC_SIGNATURE_VAL)
    return NULL;
  unlock=DocLock(doc);
  if (doc->flags & DOCF_PLAIN_TEXT_TABS)
    char_bmp=char_bmp_zero_cr_nl_cursor;
  else if (doc->flags & DOCF_PLAIN_TEXT)
    char_bmp=char_bmp_zero_tab_cr_nl_cursor;
  else
    char_bmp=char_bmp_zero_tab_cr_nl_cursor_dollar;
  doc_ce=doc->cur_entry;
  while (*ptr) {
    ptr2=ptr;
    do ch=*ptr++;
    while (!Bt(char_bmp,ch) || ch==CH_CURSOR && doc->flags&DOCF_NO_CURSOR);
    ptr--;
    if (!ch) {
      if (j=ptr-ptr2) {
        doc_e=DocEntryNewBase(doc,
              DOCT_TEXT|doc->settings_head.dft_text_attr<<8);
        if (doc->flags & DOCF_NO_CURSOR) {
          src=MAlloc(j+1);
          MemCpy(src,ptr2,j+1);
          StrUtil(src,SUF_REM_CTRL_CHARS);
          j=StrLen(src);
        } else
          src=ptr2;
        doc_e->tag=MAlloc(j+1,doc->mem_task);
        MemCpy(doc_e->tag,src,j+1);
        doc_e->max_col=j;
        DocInsEntry(doc,doc_e);
        if (doc->flags & DOCF_NO_CURSOR)
          Free(src);
      }
    } else {
      if (j=ptr-ptr2) {
        *ptr=0;
        doc_e=DocEntryNewBase(doc,
              DOCT_TEXT|doc->settings_head.dft_text_attr<<8);
        if (doc->flags & DOCF_NO_CURSOR) {
          src=MAlloc(j+1);
          MemCpy(src,ptr2,j+1);
          ptr3=src;
          ptr4=src;
          while (*ptr3)
            if (*ptr3!=CH_CURSOR)
              *ptr4++=*ptr3++;
            else
              ptr3++;
          *ptr4=0;
          j=ptr4-src;
        } else
          src=ptr2;
        doc_e->tag=MAlloc(j+1,doc->mem_task);
        MemCpy(doc_e->tag,src,j+1);
        doc_e->max_col=j;
        DocInsEntry(doc,doc_e);
        if (doc->flags & DOCF_NO_CURSOR)
          Free(src);
        *ptr=ch;
      }
      switch (ch) {
        case CH_CURSOR:
          doc_e=DocEntryNewBase(doc,
                DOCT_CURSOR|doc->settings_head.dft_text_attr<<8);
          DocInsEntry(doc,doc_e);
          ptr++;
          break;
        case '\t':
          doc_e=DocEntryNewBase(doc,
                DOCT_TAB|doc->settings_head.dft_text_attr<<8);
          DocInsEntry(doc,doc_e);
          ptr++;
          break;
        case '$':
          ptr++; //skip first dollar
          ptr2=ptr;
          while (*ptr && *ptr!='$')
            ptr++;
          if (*ptr) {
            *ptr=0; //zero second dollar
            if (ptr-1==ptr2 && *ptr2==CH_CURSOR) {
              doc_e=DocEntryNewBase(doc,
                    DOCT_CURSOR|doc->settings_head.dft_text_attr<<8);
              DocInsEntry(doc,doc_e);
              ptr2++;
            }
            if (ptr==ptr2) {
              doc_e=DocEntryNewBase(doc,
                    DOCT_TEXT|doc->settings_head.dft_text_attr<<8);
              doc_e->max_col=1;
              if (doc->flags & DOCF_DBL_DOLLARS)
                doc_e->tag=StrNew("$$",doc->mem_task);
              else
                doc_e->tag=StrNew("$",doc->mem_task);
              DocInsEntry(doc,doc_e);
            } else {
              st2=MAlloc(ptr-ptr2+1);
              ptr3=ptr2;
              ptr4=st2;
              while (ch=*ptr3++) {
                if (ch==CH_CURSOR) {
                  doc_e=DocEntryNewBase(doc,
                        DOCT_CURSOR|doc->settings_head.dft_text_attr<<8);
                  DocInsEntry(doc,doc_e);
                } else
                  *ptr4++=ch;
              }
              *ptr4=0;
              if (doc_e=PrsDollarCmd(doc,st2)) {
                res=doc_e;
                DocInsEntry(doc,doc_e);
              }
              Free(st2);
            }
            *ptr++='$';
          }
          break;
        default:
          doc_e=DocEntryNewBase(doc,
                DOCT_NEW_LINE|doc->settings_head.dft_text_attr<<8);
          DocInsEntry(doc,doc_e);
          if (ch=='\r')
            while (*ptr=='\r')
              ptr++;
          if (*ptr=='\n')
            ptr++;
          while (*ptr=='\r')
            ptr++;
      }
    }
  }
  if (unlock)
    DocUnlock(doc);
  return res;
}

public CDocEntry *DocPrint(CDoc *doc=NULL,U8 *fmt,...)
{//You must not print partial doc cmds.
//Returns last newly created dollar-sign CDocEntry or NULL.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  CDocEntry *res=DocPutS(doc,buf);
  Free(buf);
  return res;
}

public U0 DocPrintPartial(CDoc *doc=NULL,U8 *fmt,...)
{//Lets you print half a doc cmd, if you like.
  U8 *buf,*st,*src,*dst,*ptr,*ptr2;
  Bool unlock;
  CDocEntry *doc_ce,*doc_ne;
  I64 ch,i,j;
  if (!doc && !(doc=DocPut))
    return;
  buf=StrPrintJoin(NULL,fmt,argc,argv);
  ptr=buf;
  if (doc->user_put_s && (*doc->user_put_s)(doc,doc->user_put_data,buf)) {
    Free(buf);
    return;
  }
  unlock=DocLock(doc);
  if (doc->cur_entry->type_u8==DOCT_DATA)
    while (ch=*ptr++)
      DocPutKey(doc,ch,0);
  else
    while (ch=*ptr) {
      if (!Bt(char_bmp_safe_dollar,ch) ||
            doc->flags & (DOCF_OVERSTRIKE|DOCF_IN_DOLLAR)) {
        DocPutKey(doc,ch,0);
        ptr++;
      } else {
        ptr2=ptr++;
        while (TRUE) {
          ch=*ptr++;
          if (!Bt(char_bmp_safe_dollar,ch))
            break;
        }
        ptr--;
        *ptr=0;
        doc_ce=doc->cur_entry;
        j=ptr-ptr2;
        if (IsEditableText(doc_ce)) {
          dst=st=MAlloc(doc_ce->max_col+j+1,doc->mem_task);
          src=doc_ce->tag;
          i=doc->cur_col;
          doc->cur_col+=j;
          doc_ce->max_col+=j;
          while (i-->0)
            *dst++=*src++;
          while (j-->0)
            *dst++=*ptr2++;
          while (*dst++=*src++);
          Free(doc_ce->tag);
          doc_ce->tag=st;
        } else {
          doc_ne=DocEntryNewTag(doc,doc_ce,ptr2);


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

TourPut(
"$RED$$TX+L+PU+UL,\"F\",A=\"MN:F\"$$FG$() is a handy function.  "
"It is a wrapper around $RED$$TX+L+PU+UL,\"Find\",A=\"MN:Find\"$$FG$().  "
"It searches for a sym.\n",TRUE);

TourPut("Press $GREEN$<ENTER>$FG$.\n");

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

"F(\"RED\");";
InGetStr("\n");
Sleep(2000);

TourPut("Notice the number of matches.\n",TRUE);

TourPut(
"Try it with the $GREEN$+l$FG$ flag.  This limits to whole labels, not "
"partials.\n",TRUE);

TourPut("Press $GREEN$<ENTER>$FG$.\n");

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

"F(\"RED\",\"+l\");";
InGetStr("\n");
Sleep(2000);

TourPut("Notice the number of matches.\n",TRUE);

TourPut(
"Try it with the $GREEN$+l-i$FG$ flag.  This does not ignore case and "
"limits to whole labels, not partials.\n",TRUE);

TourPut("Press $GREEN$<ENTER>$FG$.\n");

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

"F(\"RED\",\"+l-i\");";
InGetStr("\n");
Sleep(2000);

TourPut("Notice the number of matches.\n",TRUE);

TourPut(
"The wrapper function is in your $RED$~/HomeWrappers.HC.Z$FG$ file.  "
"There is a function $RED$$TX+L+PU+UL,\"R\",A=\"MN:R\"$$FG$() for "
"find and replace.  Feel free to customize.\n",TRUE);

TourPut("Press $GREEN$<ENTER>$FG$.\n");

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

"Ed(\"~/HomeWrappers.HC.Z\");";
InGetStr("\n");

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the source code.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"$GREEN$+lb$FG$ is whole label just before.\n"
"$GREEN$+la$FG$ is whole label just after.\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\Tour7-Tour-Misc.html
// Date: unknown-date
// Language: HolyC

TourPut(
"$RED$$TX+L+PU+UL,\"F\",A=\"MN:F\"$$FG$() is a handy function.  "
"It is a wrapper around $RED$$TX+L+PU+UL,\"Find\",A=\"MN:Find\"$$FG$().  "
"It searches for a sym.\n",TRUE);

TourPut("Press $GREEN$<ENTER>$FG$.\n");

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

"F(\"RED\");";
InGetStr("\n");
Sleep(2000);

TourPut("Notice the number of matches.\n",TRUE);

TourPut(
"Try it with the $GREEN$+l$FG$ flag.  This limits to whole labels, not "
"partials.\n",TRUE);

TourPut("Press $GREEN$<ENTER>$FG$.\n");

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

"F(\"RED\",\"+l\");";
InGetStr("\n");
Sleep(2000);

TourPut("Notice the number of matches.\n",TRUE);

TourPut(
"Try it with the $GREEN$+l-i$FG$ flag.  This does not ignore case and "
"limits to whole labels, not partials.\n",TRUE);

TourPut("Press $GREEN$<ENTER>$FG$.\n");

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

"F(\"RED\",\"+l-i\");";
InGetStr("\n");
Sleep(2000);

TourPut("Notice the number of matches.\n",TRUE);

TourPut(
"The wrapper function is in your $RED$~/HomeWrappers.HC.Z$FG$ file.  "
"There is a function $RED$$TX+L+PU+UL,\"R\",A=\"MN:R\"$$FG$() for "
"find and replace.  Feel free to customize.\n",TRUE);

TourPut("Press $GREEN$<ENTER>$FG$.\n");

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

"Ed(\"~/HomeWrappers.HC.Z\");";
InGetStr("\n");

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the source code.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut(
"$GREEN$+lb$FG$ is whole label just before.\n"
"$GREEN$+la$FG$ is whole label just after.\n",TRUE);


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

U0 MyRead(U8 *filename)
{
  CCmpCtrl *cc=CmpCtrlNew(MStrPrint("#include \"%s\"",filename));
  while (Lex(cc)) {
    "%03d:",cc->token;
    switch (cc->token) {
        case TK_IDENT:          "IDENT:%s",cc->cur_str; break;
        case TK_STR:            "STR:%s",cc->cur_str;   break;
        case TK_CHAR_CONST:     "CHAR:%d",cc->cur_i64;  break;
        case TK_I64:            "I64:%d",cc->cur_i64;   break;
        case TK_F64:            "F64:%d",cc->cur_f64;   break;
    }
    '\n';
  }
  CmpCtrlDel(cc);
}

[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\Lex1-Templates-Demo.html
// Date: unknown-date
// Language: HolyC

U0 MyRead(U8 *filename)
{
  CCmpCtrl *cc=CmpCtrlNew(MStrPrint("#include \"%s\"",filename));
  while (Lex(cc)) {
    "%03d:",cc->token;
    switch (cc->token) {
        case TK_IDENT:          "IDENT:%s",cc->cur_str; break;
        case TK_STR:            "STR:%s",cc->cur_str;   break;
        case TK_CHAR_CONST:     "CHAR:%d",cc->cur_i64;  break;
        case TK_I64:            "I64:%d",cc->cur_i64;   break;
        case TK_F64:            "F64:%d",cc->cur_f64;   break;
    }
    '\n';
  }
  CmpCtrlDel(cc);
}


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

/* To run this, do a directory, right click on
this file's name and sel "InFile".
Or, type InFile(filename);
See InFile in the glossary for more info.
*/

I64 i;
for (i=0;i<3;i++)
  "Dir;\n";

"$RED$//Press a letter to complete the mask$FG$\n";
"Dir(\"*.";
I64 ch=GetChar(,FALSE); //Prompt for first digit of mask
"%c*\");\n",ch;

[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\InDir-InFile-Demo.html
// Date: unknown-date
// Language: HolyC

/* To run this, do a directory, right click on
this file's name and sel "InFile".
Or, type InFile(filename);
See InFile in the glossary for more info.
*/

I64 i;
for (i=0;i<3;i++)
  "Dir;\n";

"$RED$//Press a letter to complete the mask$FG$\n";
"Dir(\"*.";
I64 ch=GetChar(,FALSE); //Prompt for first digit of mask
"%c*\");\n",ch;


[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\WallPaper-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Windows"

class CWallPaperGlbls
{
  I64   last_calc_idle_cnt,last_swap_cnter[MP_PROCESSORS_NUM];
  F64   last_calc_idle_delta_time;
  U8    top_line[STR_LEN];
  Bool  record;
} *wall=CAlloc(sizeof(CWallPaperGlbls));
wall->last_calc_idle_delta_time=1.0;

class CTaskWallPaperData
{
  I64   alloced_u8s,used_u8s;
  U8    caller_stk[STR_LEN-$];
};

U0 WallPaper(CTask *_task)
{
  I64 i,j,l=TEXT_ROWS-1;
  CTask *task;
  CTaskWallPaperData *wpd;
  CHashTable *old_hash=Fs->hash_table;
  CCPU *c;
  CDateStruct ds;
  U8 *st;
  _task->text_attr=BLUE<<4+WHITE;
  if (sys_data_bp) {
    TextPrint(Fs,0,l--,BLUE<<4+YELLOW,
          "%010X/%010X %010X/%010X%12td%12td%12td",
          sys_data_bp->used_u8s,sys_data_bp->alloced_u8s,
          sys_code_bp->used_u8s,sys_code_bp->alloced_u8s,
          cmp.compiled_lines,blkdev.read_cnt,blkdev.write_cnt);
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,
          "______Data_Heap______ ______Code_Heap______ "
          "___Lines___ ___Reads___ __Writes___");
  } else {
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,
          "%010X/%010X%12td%12td%12td",
          sys_code_bp->used_u8s,sys_code_bp->alloced_u8s,
          cmp.compiled_lines,blkdev.read_cnt,blkdev.write_cnt);
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,
          "____CodeData_Heap____ "
          "___Lines___ ___Reads___ ___Writes__");
  }
  TextPrint(Fs,0,l--,BLUE<<4+WHITE,"ProgressBars:%016X %016X %016X %016X",
        progress1,progress2,progress3,progress4);
  for (i=0;i<mp_cnt;i++) {
    c=&cpu_structs[i];
    if (winmgr.t->calc_idle_cnt!=wall->last_calc_idle_cnt) {
      wall->last_calc_idle_delta_time=winmgr.t->calc_idle_delta_time;
      wall->last_swap_cnter[i]=winmgr.t->last_swap_cnter[i];
      winmgr.t->last_swap_cnter[i]=c->swap_cnter;
    }

    task=c->seth_task;
    do {
      wpd=&task->wallpaper_data;
      if (!TaskValidate(task)) break;
      if (!(winmgr.updates&31)) {
        if (c==Gs)
          Fs->hash_table=task->hash_table;
        else //precaution
          Fs->hash_table=old_hash;
        StrPrint(wpd->caller_stk,"    %-18tp %-18tp %-18tp %-18tp",
              TaskCaller(task,0),TaskCaller(task,1),
              TaskCaller(task,2),TaskCaller(task,3));
      }
      TextPrint(Fs,0,l--,BLUE<<4+YELLOW,wpd->caller_stk);
      j=UnusedStk(task);
      if (j<0)
        Panic("Stk Overflow",task);
      if (!(winmgr.updates&31)) {
        wpd->alloced_u8s=TaskMemAlloced(task);
        wpd->used_u8s   =TaskMemUsed(task);
      }
      TextPrint(Fs,0,l--,BLUE<<4+BROWN,
            "  %-18ts #%08X %010X %010X/%010X %04X:%02tX:%08X",
            task->task_title,task,j,wpd->used_u8s,wpd->alloced_u8s,
            task->task_flags,task->display_flags,task->win_inhibit);
      if (!TaskValidate(task)) break;
      task=task->next_task;
    } while (task!=c->seth_task);
    TextPrint(Fs,0,l--,BLUE<<4+WHITE,"CPU%02X %2tf%% ContextSwaps/s:%9,d",i,
          100.0*(1.0-c->idle_factor),ToI64((winmgr.t->last_swap_cnter[i]
          -wall->last_swap_cnter[i])/wall->last_calc_idle_delta_time));
  }
  TextPrint(Fs,0,l--,BLUE<<4+WHITE,
        "  ___Description____ #__Task__ UnusedStk_ _UsedMem__/_AllocMem_ "
        "______Flags_____");

  if (!(winmgr.updates&31) || !*wall->top_line) {
    Date2Struct(&ds,Now+local_time_offset);
    i=sys_code_bp->alloced_u8s-sys_code_bp->used_u8s;
    if (sys_data_bp)
      i+=sys_data_bp->alloced_u8s-sys_data_bp->used_u8s;
    StrPrint(wall->top_line,
          "%3tZ %02d/%02d %02d:%02d:%02d FPS:%2tf Mem:%010X CPU",
          ds.day_of_week,"ST_DAYS_OF_WEEK",ds.mon,ds.day_of_mon,
          ds.hour,ds.min,ds.sec,winmgr.fps,i);
  }
  TextPrint(Fs,0,0,BLUE<<4+WHITE,wall->top_line);

  if (wall->record)
    TextPrint(Fs,44-4,0,BLUE<<4+RED,"*");
  for (i=0;i<mp_cnt;i++) {
    c=&cpu_structs[i];
    if (i&1)
      TextPrint(Fs,44+i*2,0,BLUE<<4+WHITE,"%2tf",100.0*(1.0-c->idle_factor));
    else
      TextPrint(Fs,44+i*2,0,BLUE<<4+YELLOW,"%2tf",100.0*(1.0-c->idle_factor));
  }

  st=ScanCode2KeyName(kbd.last_down_scan_code);
  TextPrint(Fs,80-18,0,BLUE<<4+YELLOW,"%18ts",st);
  Free(st);

  Fs->hash_table=old_hash;
  wall->last_calc_idle_cnt=winmgr.t->calc_idle_cnt;
}

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

U0 DrawTermBttn(CDC *dc,CCtrl *c)
{
  if (Blink)
    Sprite3(dc,c->left,c->top,0,<1>);
}

U0 LeftClickTermBttn(CCtrl *,I64,I64,Bool down)
{
  if (down)
    User;
}

CCtrl *TermBttnNew()
{
  I64 min_x,max_x,min_y,max_y;
  CCtrl *c=ACAlloc(sizeof(CCtrl));

  c->win_task=sys_winmgr_task;
  c->flags=CTRLF_SHOW;
  c->type=CTRLT_GENERIC;
  c->draw_it=&DrawTermBttn;
  c->left_click=&LeftClickTermBttn;

  SpriteExtents(<1>,&min_x,&max_x,&min_y,&max_y);
//min must be zero
  c->left=sys_winmgr_task->pix_width-(max_x-min_x+1);
  c->right=c->left+(max_x-min_x+1)-1;
  c->top=sys_winmgr_task->pix_height-(max_y-min_y+1);
  c->bottom=c->top+(max_y-min_y+1)-1;

  QueIns(c,sys_winmgr_task->last_ctrl);
  TaskDerivedValsUpdate(sys_winmgr_task);

  return c;
}

U0 WallPaperInit()
{
  TermBttnNew;
  gr.fp_wall_paper=&WallPaper;
}


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

U0 Date2ISO1(CISO1Date *dst,CDate cdt)
{
  CDateStruct ds;
  Date2Struct(&ds,cdt);
  dst->year=ds.year-ISO1_BASE_YEAR;
  dst->mon=ds.mon;
  dst->day=ds.day_of_mon;
  dst->hour=ds.hour;
  dst->min=ds.min;
  dst->sec=ds.sec;
  dst->sec100=ds.sec100;
}

CDate ISO1DateStruct2CDate(CISO1Date *dt)
{
  CDateStruct ds;
  MemSet(&ds,0,sizeof(CDateStruct));
  ds.day_of_mon=dt->day;
  ds.mon=dt->mon;
  ds.year=dt->year+ISO1_BASE_YEAR;
  ds.sec100=dt->sec100;
  ds.sec=dt->sec;
  ds.min=dt->min;
  ds.hour=dt->hour;
  return Struct2Date(&ds);
}

Bool ISO1FromName(U8 *dst,U8 *src)
{
  I64 i,j,n;
  MemSet(dst,0,CDIR_FILENAME_LEN);
  n=*src++;
  if (n==1 && !*src) {
    *dst='.';
  } else if (n==1 && *src==1) {
    *dst='.';
    dst[1]='.';
  } else {
    n>>=1;
    j=0;
    for (i=0;i<n;i++) {
      src++;
      if (*src==';')
        break;
      if (Bt(char_bmp_filename,*src)) {
        if (j>=CDIR_FILENAME_LEN-1)
          return FALSE;
        dst[j++]=*src++;
      } else
        return FALSE;
    }
  }
  return FileNameChk(dst);
}

Bool ISO1CDirFill(CDirEntry *tmpde,CISO1DirEntry *de)
{
  Bool res;
  MemSet(tmpde,0,sizeof(CDirEntry));
  res=ISO1FromName(tmpde->name,&de->name_len);
  tmpde->clus=de->loc.little;
  tmpde->size=de->size.little;
  tmpde->attr=FileAttr(tmpde->name);
  if (de->flags & ISO1_ATTR_DIR)
    tmpde->attr|=RS_ATTR_DIR;
  tmpde->datetime=ISO1DateStruct2CDate(&de->date);
  return res;
}

Bool ISO1FileFind(CDrv *dv,I64 cur_dir_clus,U8 *name,
        CDirEntry *_res,I64 fuf_flags=0)
{//FUF_JUST_DIRS, FUF_JUST_FILES
  CISO1DirEntry *isoptr,*buf;
  U8 dname[CDIR_FILENAME_LEN];
  Bool res=FALSE,unlock;
  I64 i;
  if (fuf_flags&~FUG_FILE_FIND)
    throw('FUF');
  DrvChk(dv);
  if (dv->fs_type!=FSt_ISO9660)
    PrintErr("Not ISO9660 Drv\n");
  else
    try {
      unlock=DrvLock(dv);
      isoptr=MAlloc(dv->spc<<BLK_SIZE_BITS);
      ClusRead(dv,isoptr,cur_dir_clus,1);
      if (isoptr->name_len==1 && !isoptr->name) {//curdir
        i=(isoptr->size.little+dv->spc<<BLK_SIZE_BITS-1)/dv->spc<<BLK_SIZE_BITS;
        buf=MAlloc(dv->spc<<BLK_SIZE_BITS*i);
        ClusRead(dv,buf,cur_dir_clus,i);
        Free(isoptr);
      } else {
        buf=isoptr;
        i=1;
      }
      i*=dv->spc<<BLK_SIZE_BITS;
      isoptr=buf;
      while (i>0) {
        if (!isoptr->len) {
          isoptr(U8 *)++;
          i--;
        } else {
          ISO1FromName(dname,&isoptr->name_len);
          if (*dname) {
            if (!StrCmp(name,dname)) {
              res=ISO1CDirFill(_res,isoptr);
              if (res &&
                    !(fuf_flags&FUF_JUST_DIRS &&
                    !(_res->attr & RS_ATTR_DIR)) &&
                    !(fuf_flags&FUF_JUST_FILES && _res->attr & RS_ATTR_DIR) )
                goto iff_done;
              else
                res=FALSE;
            }
          }
          i-=isoptr->len;
          isoptr(U8 *)+=isoptr->len;
        }
      }
iff_done:
      Free(buf);
      if (unlock)
        DrvUnlock(dv);
    } catch
      if (unlock)
        DrvUnlock(dv);
  return res;
}

U8 *ISO1FileRead(CDrv *dv,U8 *cur_dir,U8 *filename,I64 *_size,I64 *_attr)
{
  U8 *buf=NULL;
  CDirEntry de;
  I64 c,blk_cnt,cur_dir_clus;
  DrvChk(dv);
  *_size=0;
  *_attr=0;
  if (dv->fs_type!=FSt_ISO9660)
    PrintErr("Not ISO9660 Drv\n");
  else
    try {
      DrvLock(dv);
      cur_dir_clus=Name2DirClus(dv,cur_dir);
      if (ISO1FileFind(dv,cur_dir_clus,filename,&de,FUF_JUST_FILES)) {
        blk_cnt=(de.size+BLK_SIZE-1)>>BLK_SIZE_BITS;
        buf=MAlloc(blk_cnt<<BLK_SIZE_BITS+1);
        c=de.clus;
        c=ClusBlkRead(dv,buf,c,blk_cnt);
        buf[de.size]=0; //Terminate
        *_size=de.size;
        *_attr=FileAttr(de.name,de.attr);
      }
      DrvUnlock(dv);
    } catch
      DrvUnlock(dv);
  return buf;
}

Bool ISO1Cd(U8 *name,I64 cur_dir_clus)
{
  CDirEntry de;
  if (Fs->cur_dv->fs_type!=FSt_ISO9660)
    PrintErr("Not ISO9660 Drv\n");
  else if (ISO1FileFind(Fs->cur_dv,cur_dir_clus,name,&de,FUF_JUST_DIRS))
    return TRUE;
  else
    PrintErr("File not found: \"%s\".\n",name);
  return FALSE;
}

CDirEntry *ISO1FilesFind(U8 *files_find_mask,
        I64 fuf_flags,CDirEntry *parent=NULL)
{
  CDrv *dv=Fs->cur_dv;
  CISO1DirEntry *buf,*buf2,*isoptr;
  I64 i,cur_dir_clus=Name2DirClus(dv,Fs->cur_dir);
  CDirEntry *res=NULL,*tmpde;
  if (fuf_flags&~FUG_FILES_FIND)
    throw('FUF');
  isoptr=MAlloc(dv->spc<<BLK_SIZE_BITS);
  ClusRead(dv,isoptr,cur_dir_clus,1);
  if (isoptr->name_len==1 && !isoptr->name) {//curdir
    i=(isoptr->size.little+dv->spc<<BLK_SIZE_BITS-1)/dv->spc<<BLK_SIZE_BITS;
    buf=MAlloc(dv->spc<<BLK_SIZE_BITS*i);
    ClusRead(dv,buf,cur_dir_clus,i);
    Free(isoptr);
  } else {
    buf=isoptr;
    i=1;
  }
  buf2=buf;
  i*=dv->spc<<BLK_SIZE_BITS;
  while (i>0) {
    if (!buf->len) {
      buf(U8 *)++;
      i--;
    } else {
      tmpde=MAlloc(sizeof(CDirEntry));
      if (ISO1CDirFill(tmpde,buf)) {
        tmpde->parent=parent;
        if (Bt(&fuf_flags,FUf_RECURSE) && tmpde->attr&RS_ATTR_DIR &&
              *tmpde->name!='.') {
          tmpde->next=res;
          res=tmpde;
          tmpde->full_name=DirNameAbs(tmpde->name);
          if (Cd(tmpde->name)) {
            tmpde->sub=ISO1FilesFind(files_find_mask,fuf_flags,tmpde);
            Cd("..");
          }
        } else {
          tmpde->full_name=FileNameAbs(tmpde->name);
          if ((tmpde->attr & RS_ATTR_DIR ||
                !Bt(&fuf_flags,FUf_JUST_DIRS)) &&
                !(Bt(&fuf_flags,FUf_RECURSE) &&
                *tmpde->name=='.' && tmpde->attr&RS_ATTR_DIR) &&
                FilesFindMatch(tmpde->full_name,files_find_mask,fuf_flags)) {
            tmpde->next=res;
            res=tmpde;
          } else
            DirEntryDel(tmpde);
        }
      } else
        DirEntryDel(tmpde);
      i-=buf->len;
      buf(U8 *)+=buf->len;
    }
  }
  Free(buf2);
  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\FileSysISO-BlkDev-Kernel.html
// Date: unknown-date
// Language: HolyC

U0 Date2ISO1(CISO1Date *dst,CDate cdt)
{
  CDateStruct ds;
  Date2Struct(&ds,cdt);
  dst->year=ds.year-ISO1_BASE_YEAR;
  dst->mon=ds.mon;
  dst->day=ds.day_of_mon;
  dst->hour=ds.hour;
  dst->min=ds.min;
  dst->sec=ds.sec;
  dst->sec100=ds.sec100;
}

CDate ISO1DateStruct2CDate(CISO1Date *dt)
{
  CDateStruct ds;
  MemSet(&ds,0,sizeof(CDateStruct));
  ds.day_of_mon=dt->day;
  ds.mon=dt->mon;
  ds.year=dt->year+ISO1_BASE_YEAR;
  ds.sec100=dt->sec100;
  ds.sec=dt->sec;
  ds.min=dt->min;
  ds.hour=dt->hour;
  return Struct2Date(&ds);
}

Bool ISO1FromName(U8 *dst,U8 *src)
{
  I64 i,j,n;
  MemSet(dst,0,CDIR_FILENAME_LEN);
  n=*src++;
  if (n==1 && !*src) {
    *dst='.';
  } else if (n==1 && *src==1) {
    *dst='.';
    dst[1]='.';
  } else {
    n>>=1;
    j=0;
    for (i=0;i<n;i++) {
      src++;
      if (*src==';')
        break;
      if (Bt(char_bmp_filename,*src)) {
        if (j>=CDIR_FILENAME_LEN-1)
          return FALSE;
        dst[j++]=*src++;
      } else
        return FALSE;
    }
  }
  return FileNameChk(dst);
}

Bool ISO1CDirFill(CDirEntry *tmpde,CISO1DirEntry *de)
{
  Bool res;
  MemSet(tmpde,0,sizeof(CDirEntry));
  res=ISO1FromName(tmpde->name,&de->name_len);
  tmpde->clus=de->loc.little;
  tmpde->size=de->size.little;
  tmpde->attr=FileAttr(tmpde->name);
  if (de->flags & ISO1_ATTR_DIR)
    tmpde->attr|=RS_ATTR_DIR;
  tmpde->datetime=ISO1DateStruct2CDate(&de->date);
  return res;
}

Bool ISO1FileFind(CDrv *dv,I64 cur_dir_clus,U8 *name,
        CDirEntry *_res,I64 fuf_flags=0)
{//FUF_JUST_DIRS, FUF_JUST_FILES
  CISO1DirEntry *isoptr,*buf;
  U8 dname[CDIR_FILENAME_LEN];
  Bool res=FALSE,unlock;
  I64 i;
  if (fuf_flags&~FUG_FILE_FIND)
    throw('FUF');
  DrvChk(dv);
  if (dv->fs_type!=FSt_ISO9660)
    PrintErr("Not ISO9660 Drv\n");
  else
    try {
      unlock=DrvLock(dv);
      isoptr=MAlloc(dv->spc<<BLK_SIZE_BITS);
      ClusRead(dv,isoptr,cur_dir_clus,1);
      if (isoptr->name_len==1 && !isoptr->name) {//curdir
        i=(isoptr->size.little+dv->spc<<BLK_SIZE_BITS-1)/dv->spc<<BLK_SIZE_BITS;
        buf=MAlloc(dv->spc<<BLK_SIZE_BITS*i);
        ClusRead(dv,buf,cur_dir_clus,i);
        Free(isoptr);
      } else {
        buf=isoptr;
        i=1;
      }
      i*=dv->spc<<BLK_SIZE_BITS;
      isoptr=buf;
      while (i>0) {
        if (!isoptr->len) {
          isoptr(U8 *)++;
          i--;
        } else {
          ISO1FromName(dname,&isoptr->name_len);
          if (*dname) {
            if (!StrCmp(name,dname)) {
              res=ISO1CDirFill(_res,isoptr);
              if (res &&
                    !(fuf_flags&FUF_JUST_DIRS &&
                    !(_res->attr & RS_ATTR_DIR)) &&
                    !(fuf_flags&FUF_JUST_FILES && _res->attr & RS_ATTR_DIR) )
                goto iff_done;
              else
                res=FALSE;
            }
          }
          i-=isoptr->len;
          isoptr(U8 *)+=isoptr->len;
        }
      }
iff_done:
      Free(buf);
      if (unlock)
        DrvUnlock(dv);
    } catch
      if (unlock)
        DrvUnlock(dv);
  return res;
}

U8 *ISO1FileRead(CDrv *dv,U8 *cur_dir,U8 *filename,I64 *_size,I64 *_attr)
{
  U8 *buf=NULL;
  CDirEntry de;
  I64 c,blk_cnt,cur_dir_clus;
  DrvChk(dv);
  *_size=0;
  *_attr=0;
  if (dv->fs_type!=FSt_ISO9660)
    PrintErr("Not ISO9660 Drv\n");
  else
    try {
      DrvLock(dv);
      cur_dir_clus=Name2DirClus(dv,cur_dir);
      if (ISO1FileFind(dv,cur_dir_clus,filename,&de,FUF_JUST_FILES)) {
        blk_cnt=(de.size+BLK_SIZE-1)>>BLK_SIZE_BITS;
        buf=MAlloc(blk_cnt<<BLK_SIZE_BITS+1);
        c=de.clus;
        c=ClusBlkRead(dv,buf,c,blk_cnt);
        buf[de.size]=0; //Terminate
        *_size=de.size;
        *_attr=FileAttr(de.name,de.attr);
      }
      DrvUnlock(dv);
    } catch
      DrvUnlock(dv);
  return buf;
}

Bool ISO1Cd(U8 *name,I64 cur_dir_clus)
{
  CDirEntry de;
  if (Fs->cur_dv->fs_type!=FSt_ISO9660)
    PrintErr("Not ISO9660 Drv\n");
  else if (ISO1FileFind(Fs->cur_dv,cur_dir_clus,name,&de,FUF_JUST_DIRS))
    return TRUE;
  else
    PrintErr("File not found: \"%s\".\n",name);
  return FALSE;
}

CDirEntry *ISO1FilesFind(U8 *files_find_mask,
        I64 fuf_flags,CDirEntry *parent=NULL)
{
  CDrv *dv=Fs->cur_dv;
  CISO1DirEntry *buf,*buf2,*isoptr;
  I64 i,cur_dir_clus=Name2DirClus(dv,Fs->cur_dir);
  CDirEntry *res=NULL,*tmpde;
  if (fuf_flags&~FUG_FILES_FIND)
    throw('FUF');
  isoptr=MAlloc(dv->spc<<BLK_SIZE_BITS);
  ClusRead(dv,isoptr,cur_dir_clus,1);
  if (isoptr->name_len==1 && !isoptr->name) {//curdir
    i=(isoptr->size.little+dv->spc<<BLK_SIZE_BITS-1)/dv->spc<<BLK_SIZE_BITS;
    buf=MAlloc(dv->spc<<BLK_SIZE_BITS*i);
    ClusRead(dv,buf,cur_dir_clus,i);
    Free(isoptr);
  } else {
    buf=isoptr;
    i=1;
  }
  buf2=buf;
  i*=dv->spc<<BLK_SIZE_BITS;
  while (i>0) {
    if (!buf->len) {
      buf(U8 *)++;
      i--;
    } else {
      tmpde=MAlloc(sizeof(CDirEntry));
      if (ISO1CDirFill(tmpde,buf)) {
        tmpde->parent=parent;
        if (Bt(&fuf_flags,FUf_RECURSE) && tmpde->attr&RS_ATTR_DIR &&
              *tmpde->name!='.') {
          tmpde->next=res;
          res=tmpde;
          tmpde->full_name=DirNameAbs(tmpde->name);
          if (Cd(tmpde->name)) {
            tmpde->sub=ISO1FilesFind(files_find_mask,fuf_flags,tmpde);
            Cd("..");
          }
        } else {
          tmpde->full_name=FileNameAbs(tmpde->name);
          if ((tmpde->attr & RS_ATTR_DIR ||
                !Bt(&fuf_flags,FUf_JUST_DIRS)) &&
                !(Bt(&fuf_flags,FUf_RECURSE) &&
                *tmpde->name=='.' && tmpde->attr&RS_ATTR_DIR) &&
                FilesFindMatch(tmpde->full_name,files_find_mask,fuf_flags)) {
            tmpde->next=res;
            res=tmpde;
          } else
            DirEntryDel(tmpde);
        }
      } else
        DirEntryDel(tmpde);
      i-=buf->len;
      buf(U8 *)+=buf->len;
    }
  }
  Free(buf2);
  return res;
}


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

Bool app_done;
I64 app_done_ack;

U0 Job1(I64)
{//Compile Compiler
  Silent;
  while (!app_done) {
    Cd("::/Compiler");
    Cmp("Compiler");
  }
  lock {app_done_ack--;}
}

U0 Job2(I64)
{//Log a file
  while (!app_done) {
    AdamLog("%F","::/Demo/MultiCore/LoadTest.HC");
    Yield;
  }
  lock {app_done_ack--;}
}

U0 Job3(I64)
{//Log a file
  while (!app_done) {
    Cd("::/Compiler");
    AdamLog("%F","Compiler.PRJ.Z");
    Yield;
  }
  lock {app_done_ack--;}
}

U0 Main()
{
  app_done=FALSE;
  "Running MultiCore Test...\n";
  Spawn(&Job1,,,1); //core #1
  Spawn(&Job2,,,1);
  Spawn(&Job3,,,1);
  PressAKey;
//We don't want to yank code from under MP cores.
  app_done_ack=3;
  app_done=TRUE;
  while (app_done_ack)
    Yield;
}

Main;

[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\LoadTest-MultiCore-Demo.html
// Date: unknown-date
// Language: HolyC

Bool app_done;
I64 app_done_ack;

U0 Job1(I64)
{//Compile Compiler
  Silent;
  while (!app_done) {
    Cd("::/Compiler");
    Cmp("Compiler");
  }
  lock {app_done_ack--;}
}

U0 Job2(I64)
{//Log a file
  while (!app_done) {
    AdamLog("%F","::/Demo/MultiCore/LoadTest.HC");
    Yield;
  }
  lock {app_done_ack--;}
}

U0 Job3(I64)
{//Log a file
  while (!app_done) {
    Cd("::/Compiler");
    AdamLog("%F","Compiler.PRJ.Z");
    Yield;
  }
  lock {app_done_ack--;}
}

U0 Main()
{
  app_done=FALSE;
  "Running MultiCore Test...\n";
  Spawn(&Job1,,,1); //core #1
  Spawn(&Job2,,,1);
  Spawn(&Job3,,,1);
  PressAKey;
//We don't want to yank code from under MP cores.
  app_done_ack=3;
  app_done=TRUE;
  while (app_done_ack)
    Yield;
}

Main;


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

Bool OptIC4(CIntermediateCode *tmpi)
{
  I64 i;
  CIntermediateCode *tmpil1,*tmpil2;

  if (tmpi->ic_code<IC_IMM_I64) return FALSE;

  tmpil1=tmpi;
  if (!(tmpil2=OptLag1(tmpil1)))
    return FALSE;

  if (tmpil2->res.type&MDF_STK && !(tmpil2->ic_flags&ICF_PUSH_RES)) {
    if (tmpil1->ic_code==IC_ADD_CONST && tmpil1->arg1.type&MDF_STK) {
      if ((tmpil2->ic_code==IC_REG || tmpil2->ic_code==IC_MOV) &&
            tmpil2->arg1.type&MDF_REG) {
        i=tmpil1->ic_data;
        if (I32_MIN<=i<=I32_MAX &&
              !Bt(&cmp.non_ptr_vars_mask,tmpil2->arg1.reg)) {
          tmpil1->ic_flags|=tmpil2->ic_flags&ICG_NO_CVT_MASK;
          tmpil1->ic_code=IC_LEA;
          tmpil1->arg1.type=MDF_DISP+tmpil1->arg1.type.raw_type;
          tmpil1->arg1.reg=tmpil2->arg1.reg;
          tmpil1->arg1.disp=i;
          OptFree(tmpil2);
          return TRUE;
        }
      } else if (tmpil2->ic_code==IC_SHL_CONST && tmpil2->arg1.type&MDF_REG) {
        i=tmpil1->ic_data;
        if (I32_MIN<=i<=I32_MAX && tmpil2->arg1.reg!=REG_RSP &&
              1<=tmpil2->ic_data<=3) {
          tmpil1->ic_flags|=tmpil2->ic_flags&ICG_NO_CVT_MASK;
          tmpil1->ic_code=IC_LEA;
          tmpil1->arg1.type=MDF_SIB+tmpil1->arg1.type.raw_type;
          tmpil1->arg1.reg=tmpil2->arg1.reg<<8+REG_NONE;
          if (tmpil2->ic_data==1)
            tmpil1->arg1.reg|=0x4000;
          else if (tmpil2->ic_data==2)
            tmpil1->arg1.reg|=0x8000;
          else
            tmpil1->arg1.reg|=0xC000;
          tmpil1->arg1.disp=i;
          OptFree(tmpil2);
          return TRUE;
        }
      }
    }
    if (tmpil2->ic_code==IC_MOV || tmpil2->ic_code==IC_REG) {
      if (tmpil1->arg2.type&MDF_STK) {
        if (tmpil2->ic_flags & ICF_RES_TO_INT) {
          if (tmpil2->arg1.type&MDF_IMM)
            tmpil2->arg1.disp=tmpil2->arg1.disp(F64);
          else
            tmpil1->ic_flags|=ICF_ARG2_TO_INT;
        } else if (tmpil2->ic_flags&ICF_RES_TO_F64) {
          if (tmpil2->arg1.type&MDF_IMM)
            tmpil2->arg1.disp(F64)=tmpil2->arg1.disp;
          else
            tmpil1->ic_flags|=ICF_ARG2_TO_F64;
        }
        tmpil1->arg2.type=tmpil2->arg1.type&MDG_MASK+
              MinI64(tmpil1->arg2.type.raw_type,
              MinI64(tmpil2->res.type.raw_type,tmpil2->arg1.type.raw_type));
        tmpil1->arg2.reg=tmpil2->arg1.reg;
        tmpil1->arg2.disp=tmpil2->arg1.disp;
        tmpil1->ic_flags|=tmpil2->ic_flags&ICG_NO_CVT_MASK;
        OptSetNOP2(tmpil2);
        return TRUE;
      }
      if (tmpil1->arg1.type&MDF_STK) {
        if (tmpil2->ic_flags & ICF_RES_TO_INT) {
          if (tmpil2->arg1.type&MDF_IMM)
            tmpil2->arg1.disp=tmpil2->arg1.disp(F64);
          else
            tmpil1->ic_flags|=ICF_ARG1_TO_INT;
        } else if (tmpil2->ic_flags&ICF_RES_TO_F64) {
          if (tmpil2->arg1.type&MDF_IMM) {
            if (tmpil2->arg1.type&RTF_UNSIGNED)
              tmpil2->arg1.disp(F64)=tmpil2->arg1.disp(U64);
            else
              tmpil2->arg1.disp(F64)=tmpil2->arg1.disp(I64);
          } else
            tmpil1->ic_flags|=ICF_ARG1_TO_F64;
        }
        tmpil1->arg1.type=tmpil2->arg1.type&MDG_MASK+
              MinI64(tmpil1->arg1.type.raw_type,
              MinI64(tmpil2->res.type.raw_type,tmpil2->arg1.type.raw_type));
        CmpMinTypePointed(tmpil1,tmpil2->arg1_type_pointed_to);
        tmpil1->arg1.reg=tmpil2->arg1.reg;
        tmpil1->arg1.disp=tmpil2->arg1.disp;
        tmpil1->ic_flags|=tmpil2->ic_flags&ICG_NO_CVT_MASK;
        OptSetNOP2(tmpil2);
        return TRUE;
      }
    }
    if (tmpil1->ic_code==IC_DEREF) {
      if (tmpil2->ic_code==IC_ADD_CONST && tmpil2->arg1.type&MDF_REG &&
            tmpil1->arg1.type&MDF_STK) {
        i=tmpil2->ic_data;
        if (I32_MIN<=i<=I32_MAX &&
              !Bt(&cmp.non_ptr_vars_mask,tmpil2->arg1.reg)) {
          tmpil1->ic_flags|=tmpil2->ic_flags;
          tmpil1->ic_code=IC_MOV;
          tmpil1->arg1.type=MDF_DISP+tmpil1->arg1_type_pointed_to;
          tmpil1->arg1.reg=tmpil2->arg1.reg;
          tmpil1->arg1.disp=i;
          OptSetNOP2(tmpil2,-1);
          return TRUE;
        }
      }
      if (tmpil2->ic_code==IC_LEA && tmpil1->arg1.type&MDF_STK) {
        tmpil1->ic_flags|=tmpil2->ic_flags;
        tmpil1->ic_code=IC_MOV;
        tmpil1->arg1.type=tmpil2->arg1.type&MDG_MASK+
              tmpil1->arg1_type_pointed_to;
        tmpil1->arg1.reg=tmpil2->arg1.reg;
        tmpil1->arg1.disp=tmpil2->arg1.disp;
        OptFree(tmpil2);
        return TRUE;
      }
    }
  }
  if (tmpil1->ic_code==IC_DEREF) {
    if (tmpil1->arg1.type&MDF_REG) {
      tmpil1->arg1.type=MDF_DISP+tmpil1->arg1_type_pointed_to;
      tmpil1->arg1.disp=0;
      tmpil1->ic_code=IC_MOV;
      return TRUE;
    }
  }
  return FALSE;
}

U0 OptPass4(CCmpCtrl *cc,COptReg *reg_offsets,I64 *_type)
{
  CHashClass *tmpc,*tmpc1,*tmpc2;
  CIntermediateCode *tmpi,*tmpi1,*tmpi2,*tmpil1,*tmpil2,*tmpil3,
        *tmpi_next;
  I64 code,i;
  Bool dead_code=FALSE;
  CCodeMisc *lb;
  CPrsStk *ps=cc->ps;
  ps->ptr=0;
  ps->ptr2=0;

  if (_type)
    *_type=RT_I64;

  tmpi=cc->coc.coc_head.next;
  while (code=tmpi->ic_code) {
    tmpi_next=tmpi->next;
    if (dead_code&&code!=IC_LABEL) {
      if (code==IC_JMP||code==IC_SUB_CALL) {
        lb=OptLabelFwd(tmpi->ic_data);
        if (lb->use_cnt>0)
          lb->use_cnt--;
      }
      tmpi=OptFree(tmpi);
    } else {
      tmpc=tmpi->ic_class;
      tmpi1=tmpi2=&cmp.ic_nop;
      if (tmpil1=OptLag2(tmpi)) {
        if (tmpil2=OptLag2(tmpil1)) {
          if (!(tmpil3=OptLag2(tmpil2)))
            tmpil3=&cmp.ic_nop;
        } else
          tmpil2=tmpil3=&cmp.ic_nop;
      } else
        tmpil1=tmpil2=tmpil3=&cmp.ic_nop;
      switch [intermediate_code_table[code].arg_cnt] {
        case IS_V_ARG:
          ps->ptr-=tmpi->ic_data>>3;
          break;
        case IS_2_ARG:
          tmpi2=PrsPop(ps);
          tmpc2=tmpi2->ic_class;
        case IS_1_ARG:
          tmpi1=PrsPop(ps);
          tmpc1=tmpi1->ic_class;
          break;
        case IS_

[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\OptPass4-Compiler.html
// Date: unknown-date
// Language: HolyC

Bool OptIC4(CIntermediateCode *tmpi)
{
  I64 i;
  CIntermediateCode *tmpil1,*tmpil2;

  if (tmpi->ic_code<IC_IMM_I64) return FALSE;

  tmpil1=tmpi;
  if (!(tmpil2=OptLag1(tmpil1)))
    return FALSE;

  if (tmpil2->res.type&MDF_STK && !(tmpil2->ic_flags&ICF_PUSH_RES)) {
    if (tmpil1->ic_code==IC_ADD_CONST && tmpil1->arg1.type&MDF_STK) {
      if ((tmpil2->ic_code==IC_REG || tmpil2->ic_code==IC_MOV) &&
            tmpil2->arg1.type&MDF_REG) {
        i=tmpil1->ic_data;
        if (I32_MIN<=i<=I32_MAX &&
              !Bt(&cmp.non_ptr_vars_mask,tmpil2->arg1.reg)) {
          tmpil1->ic_flags|=tmpil2->ic_flags&ICG_NO_CVT_MASK;
          tmpil1->ic_code=IC_LEA;
          tmpil1->arg1.type=MDF_DISP+tmpil1->arg1.type.raw_type;
          tmpil1->arg1.reg=tmpil2->arg1.reg;
          tmpil1->arg1.disp=i;
          OptFree(tmpil2);
          return TRUE;
        }
      } else if (tmpil2->ic_code==IC_SHL_CONST && tmpil2->arg1.type&MDF_REG) {
        i=tmpil1->ic_data;
        if (I32_MIN<=i<=I32_MAX && tmpil2->arg1.reg!=REG_RSP &&
              1<=tmpil2->ic_data<=3) {
          tmpil1->ic_flags|=tmpil2->ic_flags&ICG_NO_CVT_MASK;
          tmpil1->ic_code=IC_LEA;
          tmpil1->arg1.type=MDF_SIB+tmpil1->arg1.type.raw_type;
          tmpil1->arg1.reg=tmpil2->arg1.reg<<8+REG_NONE;
          if (tmpil2->ic_data==1)
            tmpil1->arg1.reg|=0x4000;
          else if (tmpil2->ic_data==2)
            tmpil1->arg1.reg|=0x8000;
          else
            tmpil1->arg1.reg|=0xC000;
          tmpil1->arg1.disp=i;
          OptFree(tmpil2);
          return TRUE;
        }
      }
    }
    if (tmpil2->ic_code==IC_MOV || tmpil2->ic_code==IC_REG) {
      if (tmpil1->arg2.type&MDF_STK) {
        if (tmpil2->ic_flags & ICF_RES_TO_INT) {
          if (tmpil2->arg1.type&MDF_IMM)
            tmpil2->arg1.disp=tmpil2->arg1.disp(F64);
          else
            tmpil1->ic_flags|=ICF_ARG2_TO_INT;
        } else if (tmpil2->ic_flags&ICF_RES_TO_F64) {
          if (tmpil2->arg1.type&MDF_IMM)
            tmpil2->arg1.disp(F64)=tmpil2->arg1.disp;
          else
            tmpil1->ic_flags|=ICF_ARG2_TO_F64;
        }
        tmpil1->arg2.type=tmpil2->arg1.type&MDG_MASK+
              MinI64(tmpil1->arg2.type.raw_type,
              MinI64(tmpil2->res.type.raw_type,tmpil2->arg1.type.raw_type));
        tmpil1->arg2.reg=tmpil2->arg1.reg;
        tmpil1->arg2.disp=tmpil2->arg1.disp;
        tmpil1->ic_flags|=tmpil2->ic_flags&ICG_NO_CVT_MASK;
        OptSetNOP2(tmpil2);
        return TRUE;
      }
      if (tmpil1->arg1.type&MDF_STK) {
        if (tmpil2->ic_flags & ICF_RES_TO_INT) {
          if (tmpil2->arg1.type&MDF_IMM)
            tmpil2->arg1.disp=tmpil2->arg1.disp(F64);
          else
            tmpil1->ic_flags|=ICF_ARG1_TO_INT;
        } else if (tmpil2->ic_flags&ICF_RES_TO_F64) {
          if (tmpil2->arg1.type&MDF_IMM) {
            if (tmpil2->arg1.type&RTF_UNSIGNED)
              tmpil2->arg1.disp(F64)=tmpil2->arg1.disp(U64);
            else
              tmpil2->arg1.disp(F64)=tmpil2->arg1.disp(I64);
          } else
            tmpil1->ic_flags|=ICF_ARG1_TO_F64;
        }
        tmpil1->arg1.type=tmpil2->arg1.type&MDG_MASK+
              MinI64(tmpil1->arg1.type.raw_type,
              MinI64(tmpil2->res.type.raw_type,tmpil2->arg1.type.raw_type));
        CmpMinTypePointed(tmpil1,tmpil2->arg1_type_pointed_to);
        tmpil1->arg1.reg=tmpil2->arg1.reg;
        tmpil1->arg1.disp=tmpil2->arg1.disp;
        tmpil1->ic_flags|=tmpil2->ic_flags&ICG_NO_CVT_MASK;
        OptSetNOP2(tmpil2);
        return TRUE;
      }
    }
    if (tmpil1->ic_code==IC_DEREF) {
      if (tmpil2->ic_code==IC_ADD_CONST && tmpil2->arg1.type&MDF_REG &&
            tmpil1->arg1.type&MDF_STK) {
        i=tmpil2->ic_data;
        if (I32_MIN<=i<=I32_MAX &&
              !Bt(&cmp.non_ptr_vars_mask,tmpil2->arg1.reg)) {
          tmpil1->ic_flags|=tmpil2->ic_flags;
          tmpil1->ic_code=IC_MOV;
          tmpil1->arg1.type=MDF_DISP+tmpil1->arg1_type_pointed_to;
          tmpil1->arg1.reg=tmpil2->arg1.reg;
          tmpil1->arg1.disp=i;
          OptSetNOP2(tmpil2,-1);
          return TRUE;
        }
      }
      if (tmpil2->ic_code==IC_LEA && tmpil1->arg1.type&MDF_STK) {
        tmpil1->ic_flags|=tmpil2->ic_flags;
        tmpil1->ic_code=IC_MOV;
        tmpil1->arg1.type=tmpil2->arg1.type&MDG_MASK+
              tmpil1->arg1_type_pointed_to;
        tmpil1->arg1.reg=tmpil2->arg1.reg;
        tmpil1->arg1.disp=tmpil2->arg1.disp;
        OptFree(tmpil2);
        return TRUE;
      }
    }
  }
  if (tmpil1->ic_code==IC_DEREF) {
    if (tmpil1->arg1.type&MDF_REG) {
      tmpil1->arg1.type=MDF_DISP+tmpil1->arg1_type_pointed_to;
      tmpil1->arg1.disp=0;
      tmpil1->ic_code=IC_MOV;
      return TRUE;
    }
  }
  return FALSE;
}

U0 OptPass4(CCmpCtrl *cc,COptReg *reg_offsets,I64 *_type)
{
  CHashClass *tmpc,*tmpc1,*tmpc2;
  CIntermediateCode *tmpi,*tmpi1,*tmpi2,*tmpil1,*tmpil2,*tmpil3,
        *tmpi_next;
  I64 code,i;
  Bool dead_code=FALSE;
  CCodeMisc *lb;
  CPrsStk *ps=cc->ps;
  ps->ptr=0;
  ps->ptr2=0;

  if (_type)
    *_type=RT_I64;

  tmpi=cc->coc.coc_head.next;
  while (code=tmpi->ic_code) {
    tmpi_next=tmpi->next;
    if (dead_code&&code!=IC_LABEL) {
      if (code==IC_JMP||code==IC_SUB_CALL) {
        lb=OptLabelFwd(tmpi->ic_data);
        if (lb->use_cnt>0)
          lb->use_cnt--;
      }
      tmpi=OptFree(tmpi);
    } else {
      tmpc=tmpi->ic_class;
      tmpi1=tmpi2=&cmp.ic_nop;
      if (tmpil1=OptLag2(tmpi)) {
        if (tmpil2=OptLag2(tmpil1)) {
          if (!(tmpil3=OptLag2(tmpil2)))
            tmpil3=&cmp.ic_nop;
        } else
          tmpil2=tmpil3=&cmp.ic_nop;
      } else
        tmpil1=tmpil2=tmpil3=&cmp.ic_nop;
      switch [intermediate_code_table[code].arg_cnt] {
        case IS_V_ARG:
          ps->ptr-=tmpi->ic_data>>3;
          break;
        case IS_2_ARG:
          tmpi2=PrsPop(ps);
          tmpc2=tmpi2->ic_class;
        case IS_1_ARG:
          tmpi1=PrsPop(ps);
          tmpc1=tmpi1->ic_class;
          break;
        case IS_


// Source: D:\TempleOS-Projects\html\Mouse-Doc.html
// Date: unknown-date
// Language: HolyC

ms.pos.x and ms.pos.y can be used to access the x and y coordinates of the
mouse.  They are relative to the scrn, not window.  These can be used if you
don't want to use msg passing.  ms.pos.z is the wheel.

ms.pos_text.x and ms.pos_text.y are the text column and row.  See
::/Demo/Games/Maze.HC.

See CMsStateGlbls and CMsHardStateGlbls.

The hard designation, as in ms_hard, represents hardware layer items before the
application of an abstraction layer.

//****
ms_hard.pos.x=ms_hard.prescale.x*ms_hard.scale.x*ms_grid.x_speed;
ms.presnap.x=ToI64(ms.scale.x*ms_hard.pos.x)+ms.offset.x;
if (ms_grid.snap)
  ms.pos.x=Trunc(ms.presnap.x/ms_grid.x)*ms_grid.x+ms_grid.x_offset;
else
  ms.pos.x=ms.presnap.x;
//****

[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\Mouse-Doc.html
// Date: unknown-date
// Language: HolyC

ms.pos.x and ms.pos.y can be used to access the x and y coordinates of the
mouse.  They are relative to the scrn, not window.  These can be used if you
don't want to use msg passing.  ms.pos.z is the wheel.

ms.pos_text.x and ms.pos_text.y are the text column and row.  See
::/Demo/Games/Maze.HC.

See CMsStateGlbls and CMsHardStateGlbls.

The hard designation, as in ms_hard, represents hardware layer items before the
application of an abstraction layer.

//****
ms_hard.pos.x=ms_hard.prescale.x*ms_hard.scale.x*ms_grid.x_speed;
ms.presnap.x=ToI64(ms.scale.x*ms_hard.pos.x)+ms.offset.x;
if (ms_grid.snap)
  ms.pos.x=Trunc(ms.presnap.x/ms_grid.x)*ms_grid.x+ms_grid.x_offset;
else
  ms.pos.x=ms.presnap.x;
//****


// Source: D:\TempleOS-Projects\html\advantage-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("5eC4sAA5eC4sAA5eD4AB5RCqE4sBB5eEDFE",
            "Bill \0 \0 \0Gates... \0 \0 \0 \0 \0"
            " \0 \0 \0 \0 \0 \0 \0Life's \0not \0fair.\n\0");
      Play("5C4A5qCsDD4AAeB5RCDsCC4BB5eE4A5FsEE",
            "Heavy \0 \0weights... \0 \0 \0 \0 \0"
            " \0 \0 \0 \0 \0 \0 \0 \0 \0Done \0my \0share!\n\0 \0");
      Play("5G4G5G4G5qG4eBBB5FsD4G5eD4sBGBGeBA5sGF4eG",
            "God's \0 \0 \0 \0World?  \0 \0 \0 \0"
            "Per\0fect\0 \0ly \0 \0 \0 \0 \0 \0 \0just.\n\0 \0 \0");
      Play("5sG4G5G4G5qG4eBBB5FsD4G5eD4sBGBGeBA5sGF4eG",
            "Thank's \0 \0 \0 \0Bill, \0 \0 \0 \0"
            "but \0God \0 \0we \0 \0 \0 \0 \0 \0 \0trust.\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\advantage-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("5eC4sAA5eC4sAA5eD4AB5RCqE4sBB5eEDFE",
            "Bill \0 \0 \0Gates... \0 \0 \0 \0 \0"
            " \0 \0 \0 \0 \0 \0 \0Life's \0not \0fair.\n\0");
      Play("5C4A5qCsDD4AAeB5RCDsCC4BB5eE4A5FsEE",
            "Heavy \0 \0weights... \0 \0 \0 \0 \0"
            " \0 \0 \0 \0 \0 \0 \0 \0 \0Done \0my \0share!\n\0 \0");
      Play("5G4G5G4G5qG4eBBB5FsD4G5eD4sBGBGeBA5sGF4eG",
            "God's \0 \0 \0 \0World?  \0 \0 \0 \0"
            "Per\0fect\0 \0ly \0 \0 \0 \0 \0 \0 \0just.\n\0 \0 \0");
      Play("5sG4G5G4G5qG4eBBB5FsD4G5eD4sBGBGeBA5sGF4eG",
            "Thank's \0 \0 \0 \0Bill, \0 \0 \0 \0"
            "but \0God \0 \0we \0 \0 \0 \0 \0 \0 \0trust.\n\0 \0 \0");
    }
  } catch
    PutExcept;
  Snd;
}

Song;


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

#help_index "Registry"
#define REGISTRY_FILENAME "~/Registry.HC.Z"
CDoc *sys_registry_doc=NULL;
I64 sys_msg_flags[1]={0};
F64 registry_version;

Bool RegCache()
{
  Bool old_silent;
  if (!sys_registry_doc) {
    old_silent=Silent;
    sys_registry_doc=DocRead(REGISTRY_FILENAME);
    Silent(old_silent);
    return FALSE;
  } else
    return TRUE;
}

public Bool RegDft(U8 *path,U8 *val,Bool is_adam_entry=FALSE)
{//Add code doc tree branch to registry.
  Bool res,unlock_doc;
  RegCache;
  unlock_doc=DocLock(sys_registry_doc);
  if (!DocTreeFind(sys_registry_doc,path)) {
    DocTreeMake(sys_registry_doc,path);
    DocPrint(sys_registry_doc,"%s",val);
    if (is_adam_entry) {
      if (Fs==adam_task)
        ExePrint("%s",val);
      else
        Adam("%s",val);
    }
    if (DrvIsWritable(*sys_registry_doc->filename.name))
      DocWrite(sys_registry_doc);
    res=FALSE;
  } else
    res=TRUE;
  if (unlock_doc)
    DocUnlock(sys_registry_doc);
  return res;
}

public I64 RegExe(U8 *path)
{//Execute doc tree branch in registry.
  RegCache;
  return DocTreeExe(sys_registry_doc,path);
}

public Bool RegWrite(U8 *path,U8 *fmt,...)
{//Rewrite doc tree branch in registry.
  Bool res;
  RegCache;
  res=DocTreeWriteJoin(sys_registry_doc,path,TRUE,fmt,argc,argv);
  return res;
}

public I64 RegCnt(U8 *path)
{//Tree branch cnt in registry.
  I64 res=0;
  CDocEntry *tree_branch,*start_indent,*end_indent;
  Bool unlock_doc=DocLock(sys_registry_doc);
  if (DocTreeFind(sys_registry_doc,path,
        &tree_branch,&start_indent,&end_indent)) {
    end_indent=end_indent->next;
    while (start_indent!=end_indent) {
      res++;
      start_indent=start_indent->next;
    }
  }
  if (unlock_doc)
    DocUnlock(sys_registry_doc);
  return res;
}

public Bool RegAppend(U8 *path,U8 *fmt,...)
{//Append to doc tree branch in registry.
  Bool res;
  RegCache;
  res=DocTreeAppendJoin(sys_registry_doc,path,TRUE,fmt,argc,argv);
  return res;
}

public Bool OneTimePopUp(U8 *_flags,I64 flag_num,U8 *msg)
{//See ::/Apps/X-Caliber/X-Caliber.HC.
  Bool res=FALSE;
  CDoc *doc=DocNew;
  CDocEntry *doc_e;
  if (!Bt(_flags,flag_num)) {
    if (msg) DocPrint(doc,"%s",msg);
    doc_e=DocPrint(doc,"\n$CB,\"Do not show this msg again.\",LE=1$");
    DocPrint(doc,"$CM+CX,0,4$$BT,\"OKAY\",LE=1$\n");
    if (PopUpMenu(doc)==1 && doc_e->de_flags&DOCEF_CHECKED_COLLAPSED) {
      LBts(_flags,flag_num);
      res=TRUE;
    }
    DocDel(doc);
  }
  return res;
}

U0 RegOneTimePopUp(I64 flag_num,U8 *msg)
{//You're not supposed to make system pop-up flags, only me.
  if (OneTimePopUp(sys_msg_flags,flag_num,msg))
    RegWrite("Adam/SysMsgFlags","sys_msg_flags[0]=0x%X;\n",
          sys_msg_flags[0]);
}

U0 RegInit()
{
  U8 buf[STR_LEN];
  Bool version_present;
  RegDft("Adam/SysMsgFlags","sys_msg_flags[0]=0;\n",TRUE);
  StrPrint(buf,"registry_version=%4.3f;\n",sys_os_version);
  version_present=RegDft("Adam/SysRegVer",buf,TRUE);
  RegExe("Adam");
  if (registry_version!=sys_os_version) {
    RegWrite("Adam/SysRegVer",buf);
    RegExe("Adam");
  }
}

#help_index "Boot/Once;Registry/Once"
#help_file "::/Doc/Once"

public U0 AOnceFlush()
{//Flush AOnce() buf.
  RegWrite("Once/Adam","");
}

public U0 OnceFlush()
{//Flush Once() buf.
  RegWrite("Once/User","");
}

public U0 AOnce(U8 *fmt,...)
{//Add Adam code to ~/Registry.HC, executed next boot.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  if (!Bt(&sys_run_level,RLf_ONCE_ADAM))
    AOnceFlush;
  RegAppend("Once/Adam","%s\n",buf);
  Free(buf);
}

public U0 Once(U8 *fmt,...)
{//Add User code to ~/Registry.HC, executed next boot.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  if (!Bt(&sys_run_level,RLf_ONCE_USER))
    OnceFlush;
  RegAppend("Once/User","%s\n",buf);
  Free(buf);
}

public U0 AOnceDrv(U8 drv_let=0,U8 *fmt,...)
{//Add Adam code to drv ~/Registry.HC, executed next boot.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  I64 old_drv_let=*sys_registry_doc->filename.name;
  if (drv_let)
    *sys_registry_doc->filename.name=drv_let;
  if (!Bt(&sys_run_level,RLf_ONCE_ADAM))
    AOnceFlush;
  RegAppend("Once/Adam","%s\n",buf);
  Free(buf);
  *sys_registry_doc->filename.name=old_drv_let;
}

public U0 OnceDrv(U8 drv_let=0,U8 *fmt,...)
{//Add User code to drv ~/Registry.HC, executed next boot.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  I64 old_drv_let=*sys_registry_doc->filename.name;
  if (drv_let)
    *sys_registry_doc->filename.name=drv_let;
  if (!Bt(&sys_run_level,RLf_ONCE_USER))
    OnceFlush;
  RegAppend("Once/User","%s\n",buf);
  Free(buf);
  *sys_registry_doc->filename.name=old_drv_let;
}

public U0 OnceExe()
{//Execute Once code. Call goes in ~/Once.HC.
  try {

    RegDft("Once/Adam","");
    if (RegCnt("Once/Adam")>2) {
      Adam("RegExe(\"Once/Adam\");");
      AOnceFlush;
    }
    LBts(&sys_run_level,RLf_ONCE_ADAM);

    RegDft("Once/User","");
    if (RegCnt("Once/User")>2) {
      RegExe("Once/User");
      OnceFlush;
    }
    LBts(&sys_run_level,RLf_ONCE_USER);

  } catch {
    AOnceFlush;
    LBts(&sys_run_level,RLf_ONCE_ADAM);
    OnceFlush;
    LBts(&sys_run_level,RLf_ONCE_USER);
  }
}

[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\ARegistry-Adam.html
// Date: unknown-date
// Language: HolyC

#help_index "Registry"
#define REGISTRY_FILENAME "~/Registry.HC.Z"
CDoc *sys_registry_doc=NULL;
I64 sys_msg_flags[1]={0};
F64 registry_version;

Bool RegCache()
{
  Bool old_silent;
  if (!sys_registry_doc) {
    old_silent=Silent;
    sys_registry_doc=DocRead(REGISTRY_FILENAME);
    Silent(old_silent);
    return FALSE;
  } else
    return TRUE;
}

public Bool RegDft(U8 *path,U8 *val,Bool is_adam_entry=FALSE)
{//Add code doc tree branch to registry.
  Bool res,unlock_doc;
  RegCache;
  unlock_doc=DocLock(sys_registry_doc);
  if (!DocTreeFind(sys_registry_doc,path)) {
    DocTreeMake(sys_registry_doc,path);
    DocPrint(sys_registry_doc,"%s",val);
    if (is_adam_entry) {
      if (Fs==adam_task)
        ExePrint("%s",val);
      else
        Adam("%s",val);
    }
    if (DrvIsWritable(*sys_registry_doc->filename.name))
      DocWrite(sys_registry_doc);
    res=FALSE;
  } else
    res=TRUE;
  if (unlock_doc)
    DocUnlock(sys_registry_doc);
  return res;
}

public I64 RegExe(U8 *path)
{//Execute doc tree branch in registry.
  RegCache;
  return DocTreeExe(sys_registry_doc,path);
}

public Bool RegWrite(U8 *path,U8 *fmt,...)
{//Rewrite doc tree branch in registry.
  Bool res;
  RegCache;
  res=DocTreeWriteJoin(sys_registry_doc,path,TRUE,fmt,argc,argv);
  return res;
}

public I64 RegCnt(U8 *path)
{//Tree branch cnt in registry.
  I64 res=0;
  CDocEntry *tree_branch,*start_indent,*end_indent;
  Bool unlock_doc=DocLock(sys_registry_doc);
  if (DocTreeFind(sys_registry_doc,path,
        &tree_branch,&start_indent,&end_indent)) {
    end_indent=end_indent->next;
    while (start_indent!=end_indent) {
      res++;
      start_indent=start_indent->next;
    }
  }
  if (unlock_doc)
    DocUnlock(sys_registry_doc);
  return res;
}

public Bool RegAppend(U8 *path,U8 *fmt,...)
{//Append to doc tree branch in registry.
  Bool res;
  RegCache;
  res=DocTreeAppendJoin(sys_registry_doc,path,TRUE,fmt,argc,argv);
  return res;
}

public Bool OneTimePopUp(U8 *_flags,I64 flag_num,U8 *msg)
{//See ::/Apps/X-Caliber/X-Caliber.HC.
  Bool res=FALSE;
  CDoc *doc=DocNew;
  CDocEntry *doc_e;
  if (!Bt(_flags,flag_num)) {
    if (msg) DocPrint(doc,"%s",msg);
    doc_e=DocPrint(doc,"\n$CB,\"Do not show this msg again.\",LE=1$");
    DocPrint(doc,"$CM+CX,0,4$$BT,\"OKAY\",LE=1$\n");
    if (PopUpMenu(doc)==1 && doc_e->de_flags&DOCEF_CHECKED_COLLAPSED) {
      LBts(_flags,flag_num);
      res=TRUE;
    }
    DocDel(doc);
  }
  return res;
}

U0 RegOneTimePopUp(I64 flag_num,U8 *msg)
{//You're not supposed to make system pop-up flags, only me.
  if (OneTimePopUp(sys_msg_flags,flag_num,msg))
    RegWrite("Adam/SysMsgFlags","sys_msg_flags[0]=0x%X;\n",
          sys_msg_flags[0]);
}

U0 RegInit()
{
  U8 buf[STR_LEN];
  Bool version_present;
  RegDft("Adam/SysMsgFlags","sys_msg_flags[0]=0;\n",TRUE);
  StrPrint(buf,"registry_version=%4.3f;\n",sys_os_version);
  version_present=RegDft("Adam/SysRegVer",buf,TRUE);
  RegExe("Adam");
  if (registry_version!=sys_os_version) {
    RegWrite("Adam/SysRegVer",buf);
    RegExe("Adam");
  }
}

#help_index "Boot/Once;Registry/Once"
#help_file "::/Doc/Once"

public U0 AOnceFlush()
{//Flush AOnce() buf.
  RegWrite("Once/Adam","");
}

public U0 OnceFlush()
{//Flush Once() buf.
  RegWrite("Once/User","");
}

public U0 AOnce(U8 *fmt,...)
{//Add Adam code to ~/Registry.HC, executed next boot.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  if (!Bt(&sys_run_level,RLf_ONCE_ADAM))
    AOnceFlush;
  RegAppend("Once/Adam","%s\n",buf);
  Free(buf);
}

public U0 Once(U8 *fmt,...)
{//Add User code to ~/Registry.HC, executed next boot.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  if (!Bt(&sys_run_level,RLf_ONCE_USER))
    OnceFlush;
  RegAppend("Once/User","%s\n",buf);
  Free(buf);
}

public U0 AOnceDrv(U8 drv_let=0,U8 *fmt,...)
{//Add Adam code to drv ~/Registry.HC, executed next boot.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  I64 old_drv_let=*sys_registry_doc->filename.name;
  if (drv_let)
    *sys_registry_doc->filename.name=drv_let;
  if (!Bt(&sys_run_level,RLf_ONCE_ADAM))
    AOnceFlush;
  RegAppend("Once/Adam","%s\n",buf);
  Free(buf);
  *sys_registry_doc->filename.name=old_drv_let;
}

public U0 OnceDrv(U8 drv_let=0,U8 *fmt,...)
{//Add User code to drv ~/Registry.HC, executed next boot.
  U8 *buf=StrPrintJoin(NULL,fmt,argc,argv);
  I64 old_drv_let=*sys_registry_doc->filename.name;
  if (drv_let)
    *sys_registry_doc->filename.name=drv_let;
  if (!Bt(&sys_run_level,RLf_ONCE_USER))
    OnceFlush;
  RegAppend("Once/User","%s\n",buf);
  Free(buf);
  *sys_registry_doc->filename.name=old_drv_let;
}

public U0 OnceExe()
{//Execute Once code. Call goes in ~/Once.HC.
  try {

    RegDft("Once/Adam","");
    if (RegCnt("Once/Adam")>2) {
      Adam("RegExe(\"Once/Adam\");");
      AOnceFlush;
    }
    LBts(&sys_run_level,RLf_ONCE_ADAM);

    RegDft("Once/User","");
    if (RegCnt("Once/User")>2) {
      RegExe("Once/User");
      OnceFlush;
    }
    LBts(&sys_run_level,RLf_ONCE_USER);

  } catch {
    AOnceFlush;
    LBts(&sys_run_level,RLf_ONCE_ADAM);
    OnceFlush;
    LBts(&sys_run_level,RLf_ONCE_USER);
  }
}


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

PopUp("ACInit(\"::/*;!*/Bible.TXT*\");");
AutoComplete(ON);
Sleep(3500);

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

TourPut(
"AutoComplete is a feature which also lets you jump to source code of "
"symbols.  The function keys jump to code, while the number keys jump to "
"dictionary definitions.\n\n"
"We will now place some text on the command line and jump to source code.\n",
TRUE);

"BootHD";

TourPut(
"Look at the $GREEN$BootHDIns$FG$ entry in the AutoComplete "
"window.  Notice it is underlined.  This means a source code link is "
"available.\n\n"
"Press $GREEN$<CTRL-SHIFT-F1>$FG$ to jump to source code.\n");
InGetKey(SC_F1|SCF_CTRL|SCF_SHIFT);
Sleep(500);
WinToTop;//Kludge

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the source code.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut("Press $GREEN$<CTRL-F1>$FG$ to autocomplete.\n");
InGetKey(SC_F1|SCF_CTRL);
Sleep(500);

Msg(MSG_KEY_DOWN,'\n',SCF_CTRL|SCF_SHIFT);
"\n";

TourPut(
"Tip: You can restart the AutoComplete window if you have closed it by "
"pressing $GREEN$<CTRL-F1>$FG$.\n",TRUE);

TourPut(
"You can also use the $GREEN$Man()$FG$ function to jump to source code.  "
"(I use AutoComplete.)  The $GREEN$Man()$FG$ is good for short symbol "
"names or when inside the debugger.\n",TRUE);
InPrint(,"Man(\"U\");");
Sleep(1500);
"\n";

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the source code.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);

[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\Tour6-Tour-Misc.html
// Date: unknown-date
// Language: HolyC

PopUp("ACInit(\"::/*;!*/Bible.TXT*\");");
AutoComplete(ON);
Sleep(3500);

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

TourPut(
"AutoComplete is a feature which also lets you jump to source code of "
"symbols.  The function keys jump to code, while the number keys jump to "
"dictionary definitions.\n\n"
"We will now place some text on the command line and jump to source code.\n",
TRUE);

"BootHD";

TourPut(
"Look at the $GREEN$BootHDIns$FG$ entry in the AutoComplete "
"window.  Notice it is underlined.  This means a source code link is "
"available.\n\n"
"Press $GREEN$<CTRL-SHIFT-F1>$FG$ to jump to source code.\n");
InGetKey(SC_F1|SCF_CTRL|SCF_SHIFT);
Sleep(500);
WinToTop;//Kludge

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the source code.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);

TourPut("Press $GREEN$<CTRL-F1>$FG$ to autocomplete.\n");
InGetKey(SC_F1|SCF_CTRL);
Sleep(500);

Msg(MSG_KEY_DOWN,'\n',SCF_CTRL|SCF_SHIFT);
"\n";

TourPut(
"Tip: You can restart the AutoComplete window if you have closed it by "
"pressing $GREEN$<CTRL-F1>$FG$.\n",TRUE);

TourPut(
"You can also use the $GREEN$Man()$FG$ function to jump to source code.  "
"(I use AutoComplete.)  The $GREEN$Man()$FG$ is good for short symbol "
"names or when inside the debugger.\n",TRUE);
InPrint(,"Man(\"U\");");
Sleep(1500);
"\n";

TourPut("Press $GREEN$<SHIFT-ESC>$FG$ to abort the source code.\n");
InUntilChar(CH_ESC,CH_SHIFT_ESC);


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

Cd(__DIR__);;
#include "BootDVDIns"
#include "BootHDIns"
#include "BootMHDIns"
#include "BootRAM"
Cd("..");;

[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\MakeBoot-Opt-Boot-Adam.html
// Date: unknown-date
// Language: HolyC

Cd(__DIR__);;
#include "BootDVDIns"
#include "BootHDIns"
#include "BootMHDIns"
#include "BootRAM"
Cd("..");;


// 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\Span-Span-Apps.html
// Date: unknown-date
// Language: HolyC

#define SPAN_VERSION    1.0

class SpanHeader
{
F64 version;
I32 num_masses,num_springs;
};

class MyMass:CMass
{
F64 radius,cost,load_t;
CColorROPU32 color;
} *cursor_mass;

class MySpring:CSpring
{
F64 compression_strength,tensile_strength,cost;
F64 base_compression_strength,base_tensile_strength,
base_const,base_cost;

CColorROPU32 color;
I32 thick;
};

CMathODE *ode=NULL;

CCtrlBttnState run_bttn,mode_bttn;

CColorROPU32 run_colors[2]={RED,GREEN};

#define MD_MASS         0
#define MD_CONCRETE     1
#define MD_STEEL        2
#define MD_WIRE         3
#define MD_MOVE         4
#define MD_DELETE       5
#define MD_MODES_NUM    6
CColorROPU32 mode_colors[MD_MODES_NUM]=
{BROWN,LTGRAY,DKGRAY,RED,PURPLE,RED};
  DefineLstLoad("ST_SPAN_MODES","Mass\0Concrete\0Steel\0Wire\0Move\0Delete\0");

  class SpanAnimateStruct
          {
    U8 *saved_ode;
  F64 elapsed_t,start_wall_t;
} a;

extern MyMass *PlaceMass(I64 x, I64 y);
extern F64 SpanTime();

[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\Span-Span-Apps.html
// Date: unknown-date
// Language: HolyC

#define SPAN_VERSION    1.0

class SpanHeader
{
F64 version;
I32 num_masses,num_springs;
};

class MyMass:CMass
{
F64 radius,cost,load_t;
CColorROPU32 color;
} *cursor_mass;

class MySpring:CSpring
{
F64 compression_strength,tensile_strength,cost;
F64 base_compression_strength,base_tensile_strength,
base_const,base_cost;

CColorROPU32 color;
I32 thick;
};

CMathODE *ode=NULL;

CCtrlBttnState run_bttn,mode_bttn;

CColorROPU32 run_colors[2]={RED,GREEN};

#define MD_MASS         0
#define MD_CONCRETE     1
#define MD_STEEL        2
#define MD_WIRE         3
#define MD_MOVE         4
#define MD_DELETE       5
#define MD_MODES_NUM    6
CColorROPU32 mode_colors[MD_MODES_NUM]=
{BROWN,LTGRAY,DKGRAY,RED,PURPLE,RED};
  DefineLstLoad("ST_SPAN_MODES","Mass\0Concrete\0Steel\0Wire\0Move\0Delete\0");

  class SpanAnimateStruct
          {
    U8 *saved_ode;
  F64 elapsed_t,start_wall_t;
} a;

extern MyMass *PlaceMass(I64 x, I64 y);
extern F64 SpanTime();


// Source: D:\TempleOS-Projects\html\PageTableEntries-Sup1-Sup1CodeScraps-Mem-Home.html
// Date: unknown-date
// Language: HolyC

I64 *addr=text.vga_alias,
   *pte_addr=MemPageTable(addr),
   err_code=0,
   *reported_fault_addr;
/*
  0[RBP]=old base ptr
  8[RBP]=err code
  16[RBP]=RIP
  24[RBP]=RIP_SELECTOR
  32[RBP]=RFLAGS
  40[RBP]=RSP
  48[RBP]=STK_SELECTOR
*/

interrupt haserrcode U0 IntPageFault()
{
  I64 reg *rbp=GetRBP;
  *pte_addr|=1;
  InvlPg(addr);
  err_code=rbp[1];
  MOV_RAX_CR2
  reported_fault_addr=GetRAX;
}

U0 PageTableDemo()
{
  U8 *old_idte=IntEntrySet(I_PAGE_FAULT,&IntPageFault,IDTET_IRQ);
  err_code=0;
  *pte_addr &=~1; //Not present
  InvlPg(addr);
  Refresh; //wait for VGA update
  Refresh;
  IntEntrySet(I_PAGE_FAULT,old_idte,IDTET_IRQ);
  "Err Code:%X Addr:%X\n",err_code,reported_fault_addr;
}

PageTableDemo;

[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\PageTableEntries-Sup1-Sup1CodeScraps-Mem-Home.html
// Date: unknown-date
// Language: HolyC

I64 *addr=text.vga_alias,
   *pte_addr=MemPageTable(addr),
   err_code=0,
   *reported_fault_addr;
/*
  0[RBP]=old base ptr
  8[RBP]=err code
  16[RBP]=RIP
  24[RBP]=RIP_SELECTOR
  32[RBP]=RFLAGS
  40[RBP]=RSP
  48[RBP]=STK_SELECTOR
*/

interrupt haserrcode U0 IntPageFault()
{
  I64 reg *rbp=GetRBP;
  *pte_addr|=1;
  InvlPg(addr);
  err_code=rbp[1];
  MOV_RAX_CR2
  reported_fault_addr=GetRAX;
}

U0 PageTableDemo()
{
  U8 *old_idte=IntEntrySet(I_PAGE_FAULT,&IntPageFault,IDTET_IRQ);
  err_code=0;
  *pte_addr &=~1; //Not present
  InvlPg(addr);
  Refresh; //wait for VGA update
  Refresh;
  IntEntrySet(I_PAGE_FAULT,old_idte,IDTET_IRQ);
  "Err Code:%X Addr:%X\n",err_code,reported_fault_addr;
}

PageTableDemo;


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

//Press <CTRL-t>.

                                /* Graphics Not Rendered in HTML */

//The sprite was created with <CTRL-r>.

U0 ElephantWalk()
{
  I64 sc,
        x=Fs->pix_width>>1,y=Fs->pix_height>>1, //Fs is current CTask struct.
        x_last=x;
  AutoComplete;
  WinBorder;
  WinMax;
  DocClear;
  while (TRUE) {
    DCFill;
    if (x>x_last) {
      DCSymmetrySet(,x,y,x,y-1);
      gr.dc->flags|=DCF_SYMMETRY|DCF_JUST_MIRROR;
    } else
      gr.dc->flags&=~(DCF_SYMMETRY|DCF_JUST_MIRROR);
    x_last=x;
    Sprite3ZB(gr.dc,x,y,0,<1>,Sin(8*tS)/4);//Use <CTRL-r> "Ptr to Sprite"
    switch (GetKey(&sc)) {
      case 0:
        switch (sc.u8[0]) {//Scan code lowest byte
          case SC_CURSOR_UP:
            y-=32;
            if (y<0)
              y=Fs->pix_height;
            break;
          case SC_CURSOR_DOWN:
            y+=32;
            if (y>Fs->pix_height)
              y=0;
            break;
          case SC_CURSOR_LEFT:
            x-=32;
            if (x<0)
              x=Fs->pix_width;
            break;
          case SC_CURSOR_RIGHT:
            x+=32;
            if (x>Fs->pix_width)
              x=0;
            break;
        }
        break;
      case CH_ESC:
      case CH_SHIFT_ESC:
        goto ew_done;
    }
  }
ew_done:
  DCFill;
}

ElephantWalk;

[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\ElephantWalk-Games-Demo.html
// Date: unknown-date
// Language: HolyC

//Press <CTRL-t>.

                                /* Graphics Not Rendered in HTML */

//The sprite was created with <CTRL-r>.

U0 ElephantWalk()
{
  I64 sc,
        x=Fs->pix_width>>1,y=Fs->pix_height>>1, //Fs is current CTask struct.
        x_last=x;
  AutoComplete;
  WinBorder;
  WinMax;
  DocClear;
  while (TRUE) {
    DCFill;
    if (x>x_last) {
      DCSymmetrySet(,x,y,x,y-1);
      gr.dc->flags|=DCF_SYMMETRY|DCF_JUST_MIRROR;
    } else
      gr.dc->flags&=~(DCF_SYMMETRY|DCF_JUST_MIRROR);
    x_last=x;
    Sprite3ZB(gr.dc,x,y,0,<1>,Sin(8*tS)/4);//Use <CTRL-r> "Ptr to Sprite"
    switch (GetKey(&sc)) {
      case 0:
        switch (sc.u8[0]) {//Scan code lowest byte
          case SC_CURSOR_UP:
            y-=32;
            if (y<0)
              y=Fs->pix_height;
            break;
          case SC_CURSOR_DOWN:
            y+=32;
            if (y>Fs->pix_height)
              y=0;
            break;
          case SC_CURSOR_LEFT:
            x-=32;
            if (x<0)
              x=Fs->pix_width;
            break;
          case SC_CURSOR_RIGHT:
            x+=32;
            if (x>Fs->pix_width)
              x=0;
            break;
        }
        break;
      case CH_ESC:
      case CH_SHIFT_ESC:
        goto ew_done;
    }
  }
ew_done:
  DCFill;
}

ElephantWalk;


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

#define DB_FILENAME     "~/DataBaseDemo.BIN"
#define DB_ACCT_MAX     100
#define DB_ACCT_BLKS    1

class Acct
{//Use <CTRL-l> to help generate formats.
  U8 name[32] format "$DA-P,LEN=32,A=\"Name:%s\"$\n";
  U8 addr[64] format "$DA-P,LEN=64,A=\"Addr:%s\"$\n";
  U8 pad[DB_ACCT_BLKS*BLK_SIZE-64-32];
};

U0 InitDatabase()
{ //Write new contiguous file
  CFile *f=FOpen(DB_FILENAME,"w",DB_ACCT_MAX*DB_ACCT_BLKS);
  FClose(f);
}

U0 WriteAcct()
{
  CFile *f;
  Acct a;
  I64 acctnum;

  acctnum=GetI64("Acct #",-1);
  if (0<=acctnum<DB_ACCT_MAX) {
    MemSet(&a,0,BLK_SIZE);
    if (DocForm(&a)) {
      f=FOpen(DB_FILENAME,"w+");
      FBlkWrite(f,&a,acctnum*DB_ACCT_BLKS,DB_ACCT_BLKS);
      FClose(f);
    }
  }
}

U0 ReadAcct()
{
  CFile *f;
  Acct a;
  I64 acctnum;

  acctnum=GetI64("Acct #",-1);
  if (0<=acctnum<DB_ACCT_MAX) {
    f=FOpen(DB_FILENAME,"r");
    FBlkRead(f,&a,acctnum*DB_ACCT_BLKS,DB_ACCT_BLKS);
    FClose(f);
    ClassRep(&a);
  }
}

U0 DatabaseDemo()
{
  I64 ch;
  if (!FileFind(DB_FILENAME))
    InitDatabase;
  do {
    "$GREEN$R$FG$ead acct, $GREEN$W$FG$rite acct or $GREEN$<SHIFT-ESC>$FG$:";
    ch=ToUpper(GetChar);
    '\n';
    if (ch=='R') ReadAcct;
    if (ch=='W') WriteAcct;
  } while (ch!=CH_SHIFT_ESC && ch!=CH_ESC);
}

DatabaseDemo;

[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\DataBase-Dsk-Demo.html
// Date: unknown-date
// Language: HolyC

#define DB_FILENAME     "~/DataBaseDemo.BIN"
#define DB_ACCT_MAX     100
#define DB_ACCT_BLKS    1

class Acct
{//Use <CTRL-l> to help generate formats.
  U8 name[32] format "$DA-P,LEN=32,A=\"Name:%s\"$\n";
  U8 addr[64] format "$DA-P,LEN=64,A=\"Addr:%s\"$\n";
  U8 pad[DB_ACCT_BLKS*BLK_SIZE-64-32];
};

U0 InitDatabase()
{ //Write new contiguous file
  CFile *f=FOpen(DB_FILENAME,"w",DB_ACCT_MAX*DB_ACCT_BLKS);
  FClose(f);
}

U0 WriteAcct()
{
  CFile *f;
  Acct a;
  I64 acctnum;

  acctnum=GetI64("Acct #",-1);
  if (0<=acctnum<DB_ACCT_MAX) {
    MemSet(&a,0,BLK_SIZE);
    if (DocForm(&a)) {
      f=FOpen(DB_FILENAME,"w+");
      FBlkWrite(f,&a,acctnum*DB_ACCT_BLKS,DB_ACCT_BLKS);
      FClose(f);
    }
  }
}

U0 ReadAcct()
{
  CFile *f;
  Acct a;
  I64 acctnum;

  acctnum=GetI64("Acct #",-1);
  if (0<=acctnum<DB_ACCT_MAX) {
    f=FOpen(DB_FILENAME,"r");
    FBlkRead(f,&a,acctnum*DB_ACCT_BLKS,DB_ACCT_BLKS);
    FClose(f);
    ClassRep(&a);
  }
}

U0 DatabaseDemo()
{
  I64 ch;
  if (!FileFind(DB_FILENAME))
    InitDatabase;
  do {
    "$GREEN$R$FG$ead acct, $GREEN$W$FG$rite acct or $GREEN$<SHIFT-ESC>$FG$:";
    ch=ToUpper(GetChar);
    '\n';
    if (ch=='R') ReadAcct;
    if (ch=='W') WriteAcct;
  } while (ch!=CH_SHIFT_ESC && ch!=CH_ESC);
}

DatabaseDemo;