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

Quirks

* You run a risk of problems if you do file operations on the same files
simultaneously because there is no file sharing/locking mechanism.  Generally,
the last write wins.

* When using FAT32, TempleOS does not generate unique short-entry names, the
ones with the ~s.  Not all FAT32 filenames are valid TempleOS names and it will
complain.  Do not access FAT32 drives not dedicated to TempleOS.  Disable them
with DrvEnable(OFF), or they will generate error messages.  FAT32 involves a
long and short name for each file.

* The stk does not grow because virtual mem is not used.  I recommend allocating
large local vars from the heap.  You can change MEM_DFT_STK and recompile Kernel
or request more when doing a Spawn().

* The syntax highlighting occassionally glitches.  The compiler doesn't.

* Call DskChg() when you insert a new removable media.

* Accessing CD/DVD's is flacky.  Try Drv() or DskChg() twice.

* You can only extern something once.  There is a varient called _extern which
binds a HolyC definition to a asm sym.  This, too, can only be done once.

* A terminal task has a CDoc document structure that remains active even when
you change Fs->draw_it.  To prevent links in the CDoc from being activated when
the user clicks in the window, do one of three things:

  A) DocBottom() followed by DocClear() to clear the CDoc so it has no active
  widgets.

  B) Disable window mgr bttn click checking with Fs->win_inhibit set to mask
  WIF_SELF_MS_L|WIF_FOCUS_TASK_MS_L_D|WIF_SELF_MS_R|WIF_FOCUS_TASK_MS_R_D.  This
  inhibits window mgr operations but still generates messages from bttn clicks.

* switch/case stmts alloc a single jump table--do not use with wide, sparse
ranges of case values.

* Don't do a goto out of a try{}.

* A goto label name must not match a global scope object's name.  (It's not
worth slowing-down the compiler to handle this case.)

* MemCpy() only goes fwd.

* A Cd() cmd must be followed by two semicolons if a #include is after it.  This
is because the preprocessor processes the next token ahead.

* The assembler's error msgs are often off by a line and undefines are cryptic.

* The last semicolon on the cmd line is converted to a dbl semicolon because the
compiler looks ahead before doing a cmd.  This normally has no negative effect,
but when entering if stmts with else clauses it presents problems.

* You can do a class fwd reference by using extern on the first declaration, but
you can only do ptr references to the class.

* When doing something like
    U0 Main()
    {
      U16 *_w=0xA0000;
      *_w|=0x8000;
    }
  The |= will be coded as a U32 Bts inst resulting in a U32 access instead of a
  U16 access.  This affects some hardware operations.

* Compiler warning or error message line numbers will be off if you have a block
of word-wrapped comments.  You might press <CTRL-t> before doing an editor
goto-line-number command.

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

Quirks

* You run a risk of problems if you do file operations on the same files
simultaneously because there is no file sharing/locking mechanism.  Generally,
the last write wins.

* When using FAT32, TempleOS does not generate unique short-entry names, the
ones with the ~s.  Not all FAT32 filenames are valid TempleOS names and it will
complain.  Do not access FAT32 drives not dedicated to TempleOS.  Disable them
with DrvEnable(OFF), or they will generate error messages.  FAT32 involves a
long and short name for each file.

* The stk does not grow because virtual mem is not used.  I recommend allocating
large local vars from the heap.  You can change MEM_DFT_STK and recompile Kernel
or request more when doing a Spawn().

* The syntax highlighting occassionally glitches.  The compiler doesn't.

* Call DskChg() when you insert a new removable media.

* Accessing CD/DVD's is flacky.  Try Drv() or DskChg() twice.

* You can only extern something once.  There is a varient called _extern which
binds a HolyC definition to a asm sym.  This, too, can only be done once.

* A terminal task has a CDoc document structure that remains active even when
you change Fs->draw_it.  To prevent links in the CDoc from being activated when
the user clicks in the window, do one of three things:

  A) DocBottom() followed by DocClear() to clear the CDoc so it has no active
  widgets.

  B) Disable window mgr bttn click checking with Fs->win_inhibit set to mask
  WIF_SELF_MS_L|WIF_FOCUS_TASK_MS_L_D|WIF_SELF_MS_R|WIF_FOCUS_TASK_MS_R_D.  This
  inhibits window mgr operations but still generates messages from bttn clicks.

* switch/case stmts alloc a single jump table--do not use with wide, sparse
ranges of case values.

* Don't do a goto out of a try{}.

* A goto label name must not match a global scope object's name.  (It's not
worth slowing-down the compiler to handle this case.)

* MemCpy() only goes fwd.

* A Cd() cmd must be followed by two semicolons if a #include is after it.  This
is because the preprocessor processes the next token ahead.

* The assembler's error msgs are often off by a line and undefines are cryptic.

* The last semicolon on the cmd line is converted to a dbl semicolon because the
compiler looks ahead before doing a cmd.  This normally has no negative effect,
but when entering if stmts with else clauses it presents problems.

* You can do a class fwd reference by using extern on the first declaration, but
you can only do ptr references to the class.

* When doing something like
    U0 Main()
    {
      U16 *_w=0xA0000;
      *_w|=0x8000;
    }
  The |= will be coded as a U32 Bts inst resulting in a U32 access instead of a
  U16 access.  This affects some hardware operations.

* Compiler warning or error message line numbers will be off if you have a block
of word-wrapped comments.  You might press <CTRL-t> before doing an editor
goto-line-number command.


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

#help_index "Snd"

#define SE_NOISE        0
#define SE_SWEEP        1

class CSoundEffectFrame
{
  I32   type;
  I8    ona1,ona2;
  F64   duration;
};

U0 SoundEffectEndTaskCB()
{
  Free(FramePtr("CSoundEffectFrame"));
  music.mute--;
  SndTaskEndCB;
}

U0 SoundEffectTask(CSoundEffectFrame *ns)
{
  I64 i,ona;
  F64 t0=tS,t,timeout=t0+ns->duration;
  FramePtrAdd("CSoundEffectFrame",ns);
  Fs->task_end_cb=&SoundEffectEndTaskCB;
  switch (ns->type) {
    case SE_NOISE:
      i=MaxI64(ns->ona2-ns->ona1,1);
      while (tS<timeout) {
        ona=RandU16%i+ns->ona1;
        Snd(ona);
        t=Clamp(3000.0/Ona2Freq(ona),1.0,50.0);
        if (t+tS>timeout)
          t=timeout-tS;
        Sleep(t);
      }
      break;
    case SE_SWEEP:
      while (tS<timeout) {
        t=(tS-t0)/ns->duration;
        ona=(1.0-t)*ns->ona1+t*ns->ona2;
        Snd(ona);
        t=Clamp(3000.0/Ona2Freq(ona),1.0,50.0);
        if (t+tS>timeout)
          t=timeout-tS;
        Sleep(t);
      }
      break;
  }
}

public CTask *Noise(I64 mS,F64 min_ona,F64 max_ona)
{//Make white noise for given number of mS.
  CSoundEffectFrame *ns;
  if (mS>0) {
    ns=MAlloc(sizeof(CSoundEffectFrame));
    ns->type=SE_NOISE;
    ns->duration=mS/1000.0;
    ns->ona1=min_ona;
    ns->ona2=max_ona;
    music.mute++;
    return Spawn(&SoundEffectTask,ns,"Noise",,Fs);
  } else
    return NULL;
}

public CTask *Sweep(I64 mS,F64 ona1,F64 ona2)
{//Sweep through freq range in given number of mS.
  CSoundEffectFrame *ns;
  if (mS>0) {
    ns=MAlloc(sizeof(CSoundEffectFrame));
    ns->type=SE_SWEEP;
    ns->duration=mS/1000.0;
    ns->ona1=ona1;
    ns->ona2=ona2;
    music.mute++;
    return Spawn(&SoundEffectTask,ns,"Noise",,Fs);
  } else
    return NULL;
}

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

#help_index "Snd"

#define SE_NOISE        0
#define SE_SWEEP        1

class CSoundEffectFrame
{
  I32   type;
  I8    ona1,ona2;
  F64   duration;
};

U0 SoundEffectEndTaskCB()
{
  Free(FramePtr("CSoundEffectFrame"));
  music.mute--;
  SndTaskEndCB;
}

U0 SoundEffectTask(CSoundEffectFrame *ns)
{
  I64 i,ona;
  F64 t0=tS,t,timeout=t0+ns->duration;
  FramePtrAdd("CSoundEffectFrame",ns);
  Fs->task_end_cb=&SoundEffectEndTaskCB;
  switch (ns->type) {
    case SE_NOISE:
      i=MaxI64(ns->ona2-ns->ona1,1);
      while (tS<timeout) {
        ona=RandU16%i+ns->ona1;
        Snd(ona);
        t=Clamp(3000.0/Ona2Freq(ona),1.0,50.0);
        if (t+tS>timeout)
          t=timeout-tS;
        Sleep(t);
      }
      break;
    case SE_SWEEP:
      while (tS<timeout) {
        t=(tS-t0)/ns->duration;
        ona=(1.0-t)*ns->ona1+t*ns->ona2;
        Snd(ona);
        t=Clamp(3000.0/Ona2Freq(ona),1.0,50.0);
        if (t+tS>timeout)
          t=timeout-tS;
        Sleep(t);
      }
      break;
  }
}

public CTask *Noise(I64 mS,F64 min_ona,F64 max_ona)
{//Make white noise for given number of mS.
  CSoundEffectFrame *ns;
  if (mS>0) {
    ns=MAlloc(sizeof(CSoundEffectFrame));
    ns->type=SE_NOISE;
    ns->duration=mS/1000.0;
    ns->ona1=min_ona;
    ns->ona2=max_ona;
    music.mute++;
    return Spawn(&SoundEffectTask,ns,"Noise",,Fs);
  } else
    return NULL;
}

public CTask *Sweep(I64 mS,F64 ona1,F64 ona2)
{//Sweep through freq range in given number of mS.
  CSoundEffectFrame *ns;
  if (mS>0) {
    ns=MAlloc(sizeof(CSoundEffectFrame));
    ns->type=SE_SWEEP;
    ns->duration=mS/1000.0;
    ns->ona1=ona1;
    ns->ona2=ona2;
    music.mute++;
    return Spawn(&SoundEffectTask,ns,"Noise",,Fs);
  } else
    return NULL;
}


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

#help_index "Snd/Snd Files"
#define SNDFILE_SAMPLE_RATE     8000
//Header for a ".SND" file
class CFileSND
{//big endian
  U32 signature;    //0x646e732e
  U32 offset;      //24
  U32 data_size;
  U32 coding;      //3=16bit uncompressed
  U32 sample_rate;  //Hz
  U32 channels;    //1=mono
  I16 body[1];
};

//Windows media constraint.
//#define SND_FILE_DATA_MAX     0x0007FF00
#define SND_FILE_DATA_MAX       0x7FFFFF00

public I64 SndFileCreate(U8 *base_filename,F64 normalized_vol=1.0,
        F64 averaging=0.0,I64 waveform=WF_SQUARE,
        F64 reverb_delay=0,F64 reverb_intensity=0,F64 time_shift=0)
{//Use "snd.record" flag to start or stop recording, then call this routine.
//Averaging should be a num from 0.0 to 0.999.
  //Vol should be from 0.0 to 1.0.
  //Set reverb_delay to like 0.3 sec and reverb_intensity to like 0.4.
  I64 i,k,cnt,cnt2,level,file_num;
  F64 avg,dt;
  CFileSND *s;
  CSndWaveCtrl *swc=SndWaveCtrlNew(SNDFILE_SAMPLE_RATE,16,1);
  CSndData *d,*d1;
  U8 *name,*name2;

  snd.record=FALSE;

  dt=snd.record_head.last->time-snd.record_head.next->time;
  if (!dt) return 0;
  cnt=dt*SNDFILE_SAMPLE_RATE;
  cnt++; //Terminator

  name=StrNew(base_filename);
  FileExtRem(name);

  s=CAlloc(offset(CFileSND.body)+cnt*sizeof(I16));
  s->signature=0x646e732e;
  s->offset=EndianU32(offset(CFileSND.body));
  s->coding=EndianU32(3);
  s->sample_rate=EndianU32(SNDFILE_SAMPLE_RATE);
  s->channels=EndianU32(1);

  if (time_shift) {
    d=snd.record_head.next;
    d->time-=time_shift;
    while (d->next!=&snd.record_head) {
      d1=d->next;
      dt=d1->time-d->time;
      if (dt<0) {
        QueRem(d1);
        Free(d1);
      } else
        break;
    }
  }

  d=snd.record_head.next;
  k=0;
  while (d->next!=&snd.record_head) {
    d1=d->next;
    dt=d1->time-d->time;
    cnt2=dt*SNDFILE_SAMPLE_RATE;
    SndWaveAddBuf(swc,&s->body[k],cnt2,
          Ona2Freq(d->ona),waveform,normalized_vol);
    k+=cnt2;
    QueRem(d);
    Free(d);
    d=d1;
  }

  //Average
  if (averaging) {
    avg=0;
    for (i=0;i<cnt-1;i++)
      s->body[i]=avg=LowPass1(averaging,avg,s->body[i],1.0);
  }

  //Reverb
  if (reverb_intensity) {
    if (dt=reverb_delay*SNDFILE_SAMPLE_RATE)
      for (i=dt;i<cnt;i++)
        s->body[i]+=reverb_intensity*s->body[i-dt];
  }

  //Get rid of D.C. component
  for (k=0;k<3;k++) {
    level=0;
    for (i=0;i<cnt-1;i++)
      level+=s->body[i];
    level/=cnt-1;
    for (i=0;i<cnt-1;i++)
      s->body[i]=ClampI64(s->body[i]-level,I16_MIN,I16_MAX);
  }

  for (i=0;i<cnt-1;i++)
    s->body[i]=EndianU16(s->body[i]);

  s->body[cnt-1]=0;

  d=snd.record_head.next;
  while (d!=&snd.record_head) {
    d1=d->next;
    QueRem(d);
    Free(d);
    d=d1;
  }

  name2=MAlloc(StrLen(name)+3+1+3+1);
  cnt2=cnt;
  file_num=0;
  while (cnt2>0) {
    i=cnt2;
    if (i>SND_FILE_DATA_MAX)
      i=SND_FILE_DATA_MAX;
    s->data_size=EndianU32(i*sizeof(I16));
    MemCpy(s->body,&s->body[file_num*SND_FILE_DATA_MAX],i*sizeof(I16));
    StrPrint(name2,"%s%03d.SND",name,file_num++);
    FileWrite(name2,s,offset(CFileSND.body)+i*sizeof(I16));
    cnt2-=i;
  }
  Free(s);
  Free(name);
  Free(name2);

  SndWaveCtrlDel(swc);
  return cnt;
}

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

#help_index "Snd/Snd Files"
#define SNDFILE_SAMPLE_RATE     8000
//Header for a ".SND" file
class CFileSND
{//big endian
  U32 signature;    //0x646e732e
  U32 offset;      //24
  U32 data_size;
  U32 coding;      //3=16bit uncompressed
  U32 sample_rate;  //Hz
  U32 channels;    //1=mono
  I16 body[1];
};

//Windows media constraint.
//#define SND_FILE_DATA_MAX     0x0007FF00
#define SND_FILE_DATA_MAX       0x7FFFFF00

public I64 SndFileCreate(U8 *base_filename,F64 normalized_vol=1.0,
        F64 averaging=0.0,I64 waveform=WF_SQUARE,
        F64 reverb_delay=0,F64 reverb_intensity=0,F64 time_shift=0)
{//Use "snd.record" flag to start or stop recording, then call this routine.
//Averaging should be a num from 0.0 to 0.999.
  //Vol should be from 0.0 to 1.0.
  //Set reverb_delay to like 0.3 sec and reverb_intensity to like 0.4.
  I64 i,k,cnt,cnt2,level,file_num;
  F64 avg,dt;
  CFileSND *s;
  CSndWaveCtrl *swc=SndWaveCtrlNew(SNDFILE_SAMPLE_RATE,16,1);
  CSndData *d,*d1;
  U8 *name,*name2;

  snd.record=FALSE;

  dt=snd.record_head.last->time-snd.record_head.next->time;
  if (!dt) return 0;
  cnt=dt*SNDFILE_SAMPLE_RATE;
  cnt++; //Terminator

  name=StrNew(base_filename);
  FileExtRem(name);

  s=CAlloc(offset(CFileSND.body)+cnt*sizeof(I16));
  s->signature=0x646e732e;
  s->offset=EndianU32(offset(CFileSND.body));
  s->coding=EndianU32(3);
  s->sample_rate=EndianU32(SNDFILE_SAMPLE_RATE);
  s->channels=EndianU32(1);

  if (time_shift) {
    d=snd.record_head.next;
    d->time-=time_shift;
    while (d->next!=&snd.record_head) {
      d1=d->next;
      dt=d1->time-d->time;
      if (dt<0) {
        QueRem(d1);
        Free(d1);
      } else
        break;
    }
  }

  d=snd.record_head.next;
  k=0;
  while (d->next!=&snd.record_head) {
    d1=d->next;
    dt=d1->time-d->time;
    cnt2=dt*SNDFILE_SAMPLE_RATE;
    SndWaveAddBuf(swc,&s->body[k],cnt2,
          Ona2Freq(d->ona),waveform,normalized_vol);
    k+=cnt2;
    QueRem(d);
    Free(d);
    d=d1;
  }

  //Average
  if (averaging) {
    avg=0;
    for (i=0;i<cnt-1;i++)
      s->body[i]=avg=LowPass1(averaging,avg,s->body[i],1.0);
  }

  //Reverb
  if (reverb_intensity) {
    if (dt=reverb_delay*SNDFILE_SAMPLE_RATE)
      for (i=dt;i<cnt;i++)
        s->body[i]+=reverb_intensity*s->body[i-dt];
  }

  //Get rid of D.C. component
  for (k=0;k<3;k++) {
    level=0;
    for (i=0;i<cnt-1;i++)
      level+=s->body[i];
    level/=cnt-1;
    for (i=0;i<cnt-1;i++)
      s->body[i]=ClampI64(s->body[i]-level,I16_MIN,I16_MAX);
  }

  for (i=0;i<cnt-1;i++)
    s->body[i]=EndianU16(s->body[i]);

  s->body[cnt-1]=0;

  d=snd.record_head.next;
  while (d!=&snd.record_head) {
    d1=d->next;
    QueRem(d);
    Free(d);
    d=d1;
  }

  name2=MAlloc(StrLen(name)+3+1+3+1);
  cnt2=cnt;
  file_num=0;
  while (cnt2>0) {
    i=cnt2;
    if (i>SND_FILE_DATA_MAX)
      i=SND_FILE_DATA_MAX;
    s->data_size=EndianU32(i*sizeof(I16));
    MemCpy(s->body,&s->body[file_num*SND_FILE_DATA_MAX],i*sizeof(I16));
    StrPrint(name2,"%s%03d.SND",name,file_num++);
    FileWrite(name2,s,offset(CFileSND.body)+i*sizeof(I16));
    cnt2-=i;
  }
  Free(s);
  Free(name);
  Free(name2);

  SndWaveCtrlDel(swc);
  return cnt;
}


// Source: D:\TempleOS-Projects\html\savour-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("5qFCeE4A5E4A5qDeCE4qBA",
            "This \0 \0 \0 \0 \0 \0sand\0wich \0is \0bland.\n\0 \0");
      Play("5eCCqDeDDqE4eA5ECECE4qA",
            "God \0 \0damn, \0my \0 \0tastes \0 \0 \0 \0"
            "sure \0 \0are \0grand.\n\0");
      Play("M6/8");
      Play("5FE4BGsA5GeCqE",
            "Ho \0hum.  \0 \0 \0 \0How \0 \0rude!\n\0");
      Play("5FE4BGsA5GeCqE",
            "That \0bum \0 \0 \0 \0likes \0his \0food.\n\0");
      Play("4GsA5GeDqGFE4B",
            " \0 \0Likes \0his \0food!\n\0 \0 \0 \0");
      Play("4GsAA5eEqD4G5sD4B5D4BeGG");
      Play("4A5sED4qAeAsB5GE4B5E4BqG5sD4B5D4B");
      Play("4eGGA5sED4qAeAsB5GE4B5E4B");
    }
  } 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\savour-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("5qFCeE4A5E4A5qDeCE4qBA",
            "This \0 \0 \0 \0 \0 \0sand\0wich \0is \0bland.\n\0 \0");
      Play("5eCCqDeDDqE4eA5ECECE4qA",
            "God \0 \0damn, \0my \0 \0tastes \0 \0 \0 \0"
            "sure \0 \0are \0grand.\n\0");
      Play("M6/8");
      Play("5FE4BGsA5GeCqE",
            "Ho \0hum.  \0 \0 \0 \0How \0 \0rude!\n\0");
      Play("5FE4BGsA5GeCqE",
            "That \0bum \0 \0 \0 \0likes \0his \0food.\n\0");
      Play("4GsA5GeDqGFE4B",
            " \0 \0Likes \0his \0food!\n\0 \0 \0 \0");
      Play("4GsAA5eEqD4G5sD4B5D4BeGG");
      Play("4A5sED4qAeAsB5GE4B5E4BqG5sD4B5D4B");
      Play("4eGGA5sED4qAeAsB5GE4B5E4B");
    }
  } catch
    PutExcept;
  Snd;
}

Song;


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

U0 ICFOpEqu(CCmpCtrl *cc,CIntermediateCode *tmpi,I64 op,U8 *buf2,I64 rip)
{//for ADD,SUB,DIV,MUL
  CICArg *arg1=&tmpi->arg1,
        *arg2=&tmpi->arg2;
  Bool dont_push_float,dont_pop_float,p1_mem;
  I64 rsp_size=0,builtin2=0,
        t1,r1,d1,t2,r2,d2;

  if (cc->flags&CCF_AOT_COMPILE)
    buf2=cc->aotc->rip;

  CmpSetFloatOpPushPop(cc,tmpi,&dont_push_float,&dont_pop_float);
  if (dont_pop_float)
    throw('Compiler');

  if (tmpi->ic_flags & ICF_BY_VAL) {
    p1_mem=FALSE;
    if (dont_push_float) {
      if (tmpi->arg1_type_pointed_to!=RT_F64) {
        ICMov(tmpi,MDF_REG+RT_I64,REG_RAX,0,
              arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
              arg1->reg,arg1->disp,rip);
        ICFCvt2(cc,tmpi,REG_RAX,MDF_REG+RT_I64,REG_RAX,0,FALSE,rip);
        ICPush(tmpi,MDF_REG+RT_I64,REG_RAX,0,rip);
        t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=0;
        rsp_size+=8;
      } else {
        if (tmpi->arg1_type_pointed_to>=RT_I64 && arg1->type&MDG_DISP_SIB_RIP) {
          t1=arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to;
          r1=arg1->reg;
          d1=arg1->disp;
          p1_mem=TRUE;
        } else {
          ICPush(tmpi,arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
                arg1->reg,arg1->disp,rip);
          t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=0;
          rsp_size+=8;
        }
      }
    } else {
      if (tmpi->arg1_type_pointed_to!=RT_F64 || arg1->type&MDF_STK) {
        ICMov(tmpi,MDF_REG+RT_I64,REG_RAX,0,arg2->type,
              arg2->reg,arg2->disp,rip);
        ICMov(tmpi,MDF_REG+RT_I64,REG_RDX,0,
              arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
              arg1->reg,arg1->disp,rip);
        if (tmpi->arg1_type_pointed_to!=RT_F64)
          ICFCvt2(cc,tmpi,REG_RDX,MDF_REG+RT_I64,REG_RDX,0,FALSE,rip);
        ICU16(tmpi,0x5052);     //PUSH EDX PUSH EAX
        rsp_size=16;
        t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=8;
        t2=MDF_SIB+RT_I64; r2=REG_RSP+REG_RSP<<8; d2=0;
      } else {
        if (arg2->type.raw_type>=RT_I64 && arg2->type&MDG_DISP_SIB_RIP) {
          t2=arg2->type;
          r2=arg2->reg;
          d2=arg2->disp;
        } else {
          if (arg2->type&MDF_IMM) {
            if (!(builtin2=ICBuiltInFloatConst(arg2->disp(F64)))) {
              t2=MDF_RIP_DISP32+RT_I64;
              r2=REG_RIP;
              d2=COCFloatConstFind(cc,arg2->disp(F64))+buf2;
            }
          } else {
            ICPush(tmpi,arg2->type,arg2->reg,arg2->disp,rip);
            t2=MDF_SIB+RT_I64; r2=REG_RSP+REG_RSP<<8; d2=0;
            rsp_size+=8;
          }
        }
        if (tmpi->arg1_type_pointed_to>=RT_I64 && arg1->type&MDG_DISP_SIB_RIP) {
          t1=arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to;
          r1=arg1->reg;
          d1=arg1->disp;
          p1_mem=TRUE;
        } else {
          ICPush(tmpi,arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
                arg1->reg,arg1->disp,rip);
          t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=0;
          rsp_size+=8;
          if (r2==REG_RSP+REG_RSP<<8)
            d2+=8;
        }
      }
    }
    if (!rsp_size && !(p1_mem && tmpi->arg1_type_pointed_to==RT_F64)) {
      rsp_size=8;
      ICAddRSP(tmpi,-8);
    }
    if (!dont_push_float) {
      if (builtin2)
        ICU16(tmpi,builtin2);
      else
        ICSlashOp(tmpi,t2,r2,d2,SLASH_OP_FLD,rip);
    }
    switch (op.u8[0]) {
      case 4: op=SLASH_OP_FSUBR; break;
      case 6: op=SLASH_OP_FDIVR; break;
    }
    ICSlashOp(tmpi,t1,r1,d1,op,rip);
    CmpNoteFloatOp(cc,tmpi,TRUE,FALSE,CN_INST);
    if (p1_mem && tmpi->arg1_type_pointed_to==RT_F64) {
      ICSlashOp(tmpi,t1,r1,d1,SLASH_OP_FSTP,rip);
      if (rsp_size)
        ICAddRSP(tmpi,rsp_size);
    } else {
      if (rsp_size==8)
        ICSlashOp(tmpi,MDF_SIB+RT_I64,REG_RSP+REG_RSP<<8,0,SLASH_OP_FSTP,rip);
      else if (rsp_size>8) {
        ICSlashOp(tmpi,MDF_SIB+RT_I64,REG_RSP+REG_RSP<<8,rsp_size-8,
              SLASH_OP_FSTP,rip);
        ICAddRSP(tmpi,rsp_size-8);
      }
      if (tmpi->arg1_type_pointed_to!=RT_F64) {
        ICPop(tmpi,MDF_REG+RT_I64,REG_RAX,0,rip);
        ICFCvt2(cc,tmpi,REG_RAX,MDF_REG+RT_I64,REG_RAX,0,TRUE,rip);
        ICMov(tmpi,arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,arg1->reg,
              arg1->disp,MDF_REG+RT_I64,REG_RAX,0,rip);
      } else
        ICPop(tmpi,arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
              arg1->reg,arg1->disp,rip);
    }
    if (tmpi->res.type.mode)
      ICMov(tmpi,tmpi->res.type,tmpi->res.reg,tmpi->res.disp,
            arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
            arg1->reg,arg1->disp,rip);
  } else {
    if (tmpi->arg1_type_pointed_to>=RT_I64)
      p1_mem=TRUE;
    else
      p1_mem=FALSE;
    if (dont_push_float) {
      ICMov(tmpi,MDF_REG+RT_I64,REG_RCX,0,arg1->type,arg1->reg,arg1->disp,rip);
      if (tmpi->arg1_type_pointed_to!=RT_F64) {
        ICMov(tmpi,MDF_REG+RT_I64,REG_RAX,0,
              MDF_DISP+tmpi->arg1_type_pointed_to,REG_RCX,0,rip);
        ICFCvt2(cc,tmpi,REG_RAX,MDF_REG+RT_I64,REG_RAX,0,FALSE,rip);
        ICPush(tmpi,MDF_REG+RT_I64,REG_RAX,0,rip);
      } else
        ICPush(tmpi,MDF_DISP+tmpi->arg1_type_pointed_to,REG_RCX,0,rip);
      t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=0;
      rsp_size+=8;
    } else {
      if (tmpi->arg1_type_pointed_to!=RT_F64 || arg1->type&MDF_STK) {
        ICMov(tmpi,MDF_REG+RT_I64,REG_RAX,0,arg2->type,
              arg2->reg,arg2->disp,rip);
        ICMov(tmpi,MDF_REG+RT_I64,REG_RCX,0,arg1->type,
              arg1->reg,arg1->disp,rip);
        ICMov(tmpi,MDF_REG+RT_I64,REG_RDX,0,
              MDF_DISP+tmpi->arg1_type_pointed_to,REG_RCX,0,rip);
        if (tmpi->arg1_type_pointed_to!=RT_F64)
          ICFCvt2(cc,tmpi,REG_RDX,MDF_REG+RT_I64,REG_RDX,0,FALSE,rip);
        ICU16(tmpi,0x5052);     //PUSH EDX PUSH EAX
        rsp_size=16;
        t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=8;
        t2=MDF_SIB+RT_I64; r2=REG_RSP+REG_RSP<<8; d2=0;
      } else {
        if (arg2->type.raw_type>=RT_I64 && arg2->type&

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

U0 ICFOpEqu(CCmpCtrl *cc,CIntermediateCode *tmpi,I64 op,U8 *buf2,I64 rip)
{//for ADD,SUB,DIV,MUL
  CICArg *arg1=&tmpi->arg1,
        *arg2=&tmpi->arg2;
  Bool dont_push_float,dont_pop_float,p1_mem;
  I64 rsp_size=0,builtin2=0,
        t1,r1,d1,t2,r2,d2;

  if (cc->flags&CCF_AOT_COMPILE)
    buf2=cc->aotc->rip;

  CmpSetFloatOpPushPop(cc,tmpi,&dont_push_float,&dont_pop_float);
  if (dont_pop_float)
    throw('Compiler');

  if (tmpi->ic_flags & ICF_BY_VAL) {
    p1_mem=FALSE;
    if (dont_push_float) {
      if (tmpi->arg1_type_pointed_to!=RT_F64) {
        ICMov(tmpi,MDF_REG+RT_I64,REG_RAX,0,
              arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
              arg1->reg,arg1->disp,rip);
        ICFCvt2(cc,tmpi,REG_RAX,MDF_REG+RT_I64,REG_RAX,0,FALSE,rip);
        ICPush(tmpi,MDF_REG+RT_I64,REG_RAX,0,rip);
        t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=0;
        rsp_size+=8;
      } else {
        if (tmpi->arg1_type_pointed_to>=RT_I64 && arg1->type&MDG_DISP_SIB_RIP) {
          t1=arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to;
          r1=arg1->reg;
          d1=arg1->disp;
          p1_mem=TRUE;
        } else {
          ICPush(tmpi,arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
                arg1->reg,arg1->disp,rip);
          t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=0;
          rsp_size+=8;
        }
      }
    } else {
      if (tmpi->arg1_type_pointed_to!=RT_F64 || arg1->type&MDF_STK) {
        ICMov(tmpi,MDF_REG+RT_I64,REG_RAX,0,arg2->type,
              arg2->reg,arg2->disp,rip);
        ICMov(tmpi,MDF_REG+RT_I64,REG_RDX,0,
              arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
              arg1->reg,arg1->disp,rip);
        if (tmpi->arg1_type_pointed_to!=RT_F64)
          ICFCvt2(cc,tmpi,REG_RDX,MDF_REG+RT_I64,REG_RDX,0,FALSE,rip);
        ICU16(tmpi,0x5052);     //PUSH EDX PUSH EAX
        rsp_size=16;
        t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=8;
        t2=MDF_SIB+RT_I64; r2=REG_RSP+REG_RSP<<8; d2=0;
      } else {
        if (arg2->type.raw_type>=RT_I64 && arg2->type&MDG_DISP_SIB_RIP) {
          t2=arg2->type;
          r2=arg2->reg;
          d2=arg2->disp;
        } else {
          if (arg2->type&MDF_IMM) {
            if (!(builtin2=ICBuiltInFloatConst(arg2->disp(F64)))) {
              t2=MDF_RIP_DISP32+RT_I64;
              r2=REG_RIP;
              d2=COCFloatConstFind(cc,arg2->disp(F64))+buf2;
            }
          } else {
            ICPush(tmpi,arg2->type,arg2->reg,arg2->disp,rip);
            t2=MDF_SIB+RT_I64; r2=REG_RSP+REG_RSP<<8; d2=0;
            rsp_size+=8;
          }
        }
        if (tmpi->arg1_type_pointed_to>=RT_I64 && arg1->type&MDG_DISP_SIB_RIP) {
          t1=arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to;
          r1=arg1->reg;
          d1=arg1->disp;
          p1_mem=TRUE;
        } else {
          ICPush(tmpi,arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
                arg1->reg,arg1->disp,rip);
          t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=0;
          rsp_size+=8;
          if (r2==REG_RSP+REG_RSP<<8)
            d2+=8;
        }
      }
    }
    if (!rsp_size && !(p1_mem && tmpi->arg1_type_pointed_to==RT_F64)) {
      rsp_size=8;
      ICAddRSP(tmpi,-8);
    }
    if (!dont_push_float) {
      if (builtin2)
        ICU16(tmpi,builtin2);
      else
        ICSlashOp(tmpi,t2,r2,d2,SLASH_OP_FLD,rip);
    }
    switch (op.u8[0]) {
      case 4: op=SLASH_OP_FSUBR; break;
      case 6: op=SLASH_OP_FDIVR; break;
    }
    ICSlashOp(tmpi,t1,r1,d1,op,rip);
    CmpNoteFloatOp(cc,tmpi,TRUE,FALSE,CN_INST);
    if (p1_mem && tmpi->arg1_type_pointed_to==RT_F64) {
      ICSlashOp(tmpi,t1,r1,d1,SLASH_OP_FSTP,rip);
      if (rsp_size)
        ICAddRSP(tmpi,rsp_size);
    } else {
      if (rsp_size==8)
        ICSlashOp(tmpi,MDF_SIB+RT_I64,REG_RSP+REG_RSP<<8,0,SLASH_OP_FSTP,rip);
      else if (rsp_size>8) {
        ICSlashOp(tmpi,MDF_SIB+RT_I64,REG_RSP+REG_RSP<<8,rsp_size-8,
              SLASH_OP_FSTP,rip);
        ICAddRSP(tmpi,rsp_size-8);
      }
      if (tmpi->arg1_type_pointed_to!=RT_F64) {
        ICPop(tmpi,MDF_REG+RT_I64,REG_RAX,0,rip);
        ICFCvt2(cc,tmpi,REG_RAX,MDF_REG+RT_I64,REG_RAX,0,TRUE,rip);
        ICMov(tmpi,arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,arg1->reg,
              arg1->disp,MDF_REG+RT_I64,REG_RAX,0,rip);
      } else
        ICPop(tmpi,arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
              arg1->reg,arg1->disp,rip);
    }
    if (tmpi->res.type.mode)
      ICMov(tmpi,tmpi->res.type,tmpi->res.reg,tmpi->res.disp,
            arg1->type&MDG_MASK+tmpi->arg1_type_pointed_to,
            arg1->reg,arg1->disp,rip);
  } else {
    if (tmpi->arg1_type_pointed_to>=RT_I64)
      p1_mem=TRUE;
    else
      p1_mem=FALSE;
    if (dont_push_float) {
      ICMov(tmpi,MDF_REG+RT_I64,REG_RCX,0,arg1->type,arg1->reg,arg1->disp,rip);
      if (tmpi->arg1_type_pointed_to!=RT_F64) {
        ICMov(tmpi,MDF_REG+RT_I64,REG_RAX,0,
              MDF_DISP+tmpi->arg1_type_pointed_to,REG_RCX,0,rip);
        ICFCvt2(cc,tmpi,REG_RAX,MDF_REG+RT_I64,REG_RAX,0,FALSE,rip);
        ICPush(tmpi,MDF_REG+RT_I64,REG_RAX,0,rip);
      } else
        ICPush(tmpi,MDF_DISP+tmpi->arg1_type_pointed_to,REG_RCX,0,rip);
      t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=0;
      rsp_size+=8;
    } else {
      if (tmpi->arg1_type_pointed_to!=RT_F64 || arg1->type&MDF_STK) {
        ICMov(tmpi,MDF_REG+RT_I64,REG_RAX,0,arg2->type,
              arg2->reg,arg2->disp,rip);
        ICMov(tmpi,MDF_REG+RT_I64,REG_RCX,0,arg1->type,
              arg1->reg,arg1->disp,rip);
        ICMov(tmpi,MDF_REG+RT_I64,REG_RDX,0,
              MDF_DISP+tmpi->arg1_type_pointed_to,REG_RCX,0,rip);
        if (tmpi->arg1_type_pointed_to!=RT_F64)
          ICFCvt2(cc,tmpi,REG_RDX,MDF_REG+RT_I64,REG_RDX,0,FALSE,rip);
        ICU16(tmpi,0x5052);     //PUSH EDX PUSH EAX
        rsp_size=16;
        t1=MDF_SIB+RT_I64; r1=REG_RSP+REG_RSP<<8; d1=8;
        t2=MDF_SIB+RT_I64; r2=REG_RSP+REG_RSP<<8; d2=0;
      } else {
        if (arg2->type.raw_type>=RT_I64 && arg2->type&


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

#help_index "Install;File/Cmd Line (Typically);Cmd Line (Typically);"
public I64 Mount(Bool repartition=FALSE)
{
  I64 cnt,res=0,num_hints,drv_let,type,unit,prt_num;
  U8 blks_buf[STR_LEN],addr_buf[STR_LEN],base0_buf[STR_LEN],base1_buf[STR_LEN],
        *filename=NULL,*filename2=NULL;
  CATARep *head=NULL,*tmpha;
  Bool whole_drv;
  CBlkDev *bd;
  do {
    cnt=0;
    DrvRep;
    "\n****** Mount Drives ******\n"
          "A-B are RAM drives.\n"
          "C-L are ATA hard drives.\n"
          "M-P are ISO file read drives.\n"
          "Q-S are ISO file write drives.\n"
          "T-Z are ATAPI CD/DVD drives.\n"
          "\nDrive Letter (<ENTER> to exit):";
    drv_let=Let2Let(GetChar);
    '\n';
    if (type=Let2BlkDevType(drv_let)) {
      whole_drv=FALSE;
      unit=0;
      prt_num=I64_MIN;
      switch (type) {
        case BDT_RAM:
          "Addr of RAM disk (<ENTER> to MAlloc):";
          GetS(addr_buf,STR_LEN);
        case BDT_ISO_FILE_WRITE:
          "Blks of 512 bytes:";
          GetS(blks_buf,STR_LEN);
          break;
        case BDT_ISO_FILE_READ:
          filename=GetStr("File Name:");
          break;
        case BDT_ATA:
          prt_num=GetI64("Partition Num (Default=All):",prt_num);
        case BDT_ATAPI:
          num_hints=ATARep(,,&head);
          do {
            if (num_hints)
              "Enter dev number or\nport with 0x prefix.\n"
                    "I/O Port Base0:\n";
            else
              "Include 0x prefix.\nI/O Port Base0:\n";
            GetS(base0_buf,STR_LEN);
          } while (!Str2I64(base0_buf));
          if (1<=Str2I64(base0_buf)<=num_hints) {
            tmpha=ATARepFind(head,Str2I64(base0_buf));
            StrPrint(base0_buf,"0x%X",tmpha->base0);
            StrPrint(base1_buf,"0x%X",tmpha->base1);
            unit=tmpha->unit;
          } else if (type!=BDT_ATAPI || *base0_buf) {
            if (type==BDT_ATAPI)
              StrCpy(base1_buf,"0");
            else
              do {
                "I/O Port Base1:\n";
                GetS(base1_buf,STR_LEN);
              } while (!Str2I64(base1_buf));
            do {
              "\t0=Master\n\t1=Slave\nUnit:";
              unit=GetChar-'0';
            } while (!(0<=unit<=1));
            '\n';
          }
          LinkedLstDel(head);
          break;
      }
      bd=BlkDevNextFreeSlot(drv_let,type);
      bd->unit=unit;
      switch (type) {
        case BDT_RAM:
          if (!*addr_buf)
            bd->RAM_dsk=0;
          else
            bd->RAM_dsk=Str2I64(addr_buf);
        case BDT_ISO_FILE_WRITE:
          if (!*blks_buf)
            bd->max_blk=-1;
          else
            bd->max_blk=Str2I64(blks_buf)-1;
          bd->drv_offset=19<<2+(DVD_BLK_SIZE*2+DVD_BOOT_LOADER_SIZE)/BLK_SIZE;
          break;
        case BDT_ISO_FILE_READ:
          filename2=FileNameAbs(filename);
          bd->file_dsk_name=AStrNew(filename2);
          bd->drv_offset=19<<2+(DVD_BLK_SIZE*2+DVD_BOOT_LOADER_SIZE)/BLK_SIZE;
          break;
        case BDT_ATA:
        case BDT_ATAPI:
          bd->base0=Str2I64(base0_buf);
          bd->base1=Str2I64(base1_buf);
          if (type==BDT_ATA && repartition) {
            "\nReformat WHOLE drive!";
            whole_drv=YorN;
          }
          break;
      }
      if ((cnt=BlkDevAdd(bd,prt_num,whole_drv,TRUE)) && whole_drv)
        ExePrint("DskPrt('%C');\n",drv_let);
    }
    res+=cnt;
  } while (cnt);
  Free(filename);
  Free(filename2);
  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\DbgMount-Sup1-Sup1Distro-Home.html
// Date: unknown-date
// Language: HolyC

#help_index "Install;File/Cmd Line (Typically);Cmd Line (Typically);"
public I64 Mount(Bool repartition=FALSE)
{
  I64 cnt,res=0,num_hints,drv_let,type,unit,prt_num;
  U8 blks_buf[STR_LEN],addr_buf[STR_LEN],base0_buf[STR_LEN],base1_buf[STR_LEN],
        *filename=NULL,*filename2=NULL;
  CATARep *head=NULL,*tmpha;
  Bool whole_drv;
  CBlkDev *bd;
  do {
    cnt=0;
    DrvRep;
    "\n****** Mount Drives ******\n"
          "A-B are RAM drives.\n"
          "C-L are ATA hard drives.\n"
          "M-P are ISO file read drives.\n"
          "Q-S are ISO file write drives.\n"
          "T-Z are ATAPI CD/DVD drives.\n"
          "\nDrive Letter (<ENTER> to exit):";
    drv_let=Let2Let(GetChar);
    '\n';
    if (type=Let2BlkDevType(drv_let)) {
      whole_drv=FALSE;
      unit=0;
      prt_num=I64_MIN;
      switch (type) {
        case BDT_RAM:
          "Addr of RAM disk (<ENTER> to MAlloc):";
          GetS(addr_buf,STR_LEN);
        case BDT_ISO_FILE_WRITE:
          "Blks of 512 bytes:";
          GetS(blks_buf,STR_LEN);
          break;
        case BDT_ISO_FILE_READ:
          filename=GetStr("File Name:");
          break;
        case BDT_ATA:
          prt_num=GetI64("Partition Num (Default=All):",prt_num);
        case BDT_ATAPI:
          num_hints=ATARep(,,&head);
          do {
            if (num_hints)
              "Enter dev number or\nport with 0x prefix.\n"
                    "I/O Port Base0:\n";
            else
              "Include 0x prefix.\nI/O Port Base0:\n";
            GetS(base0_buf,STR_LEN);
          } while (!Str2I64(base0_buf));
          if (1<=Str2I64(base0_buf)<=num_hints) {
            tmpha=ATARepFind(head,Str2I64(base0_buf));
            StrPrint(base0_buf,"0x%X",tmpha->base0);
            StrPrint(base1_buf,"0x%X",tmpha->base1);
            unit=tmpha->unit;
          } else if (type!=BDT_ATAPI || *base0_buf) {
            if (type==BDT_ATAPI)
              StrCpy(base1_buf,"0");
            else
              do {
                "I/O Port Base1:\n";
                GetS(base1_buf,STR_LEN);
              } while (!Str2I64(base1_buf));
            do {
              "\t0=Master\n\t1=Slave\nUnit:";
              unit=GetChar-'0';
            } while (!(0<=unit<=1));
            '\n';
          }
          LinkedLstDel(head);
          break;
      }
      bd=BlkDevNextFreeSlot(drv_let,type);
      bd->unit=unit;
      switch (type) {
        case BDT_RAM:
          if (!*addr_buf)
            bd->RAM_dsk=0;
          else
            bd->RAM_dsk=Str2I64(addr_buf);
        case BDT_ISO_FILE_WRITE:
          if (!*blks_buf)
            bd->max_blk=-1;
          else
            bd->max_blk=Str2I64(blks_buf)-1;
          bd->drv_offset=19<<2+(DVD_BLK_SIZE*2+DVD_BOOT_LOADER_SIZE)/BLK_SIZE;
          break;
        case BDT_ISO_FILE_READ:
          filename2=FileNameAbs(filename);
          bd->file_dsk_name=AStrNew(filename2);
          bd->drv_offset=19<<2+(DVD_BLK_SIZE*2+DVD_BOOT_LOADER_SIZE)/BLK_SIZE;
          break;
        case BDT_ATA:
        case BDT_ATAPI:
          bd->base0=Str2I64(base0_buf);
          bd->base1=Str2I64(base1_buf);
          if (type==BDT_ATA && repartition) {
            "\nReformat WHOLE drive!";
            whole_drv=YorN;
          }
          break;
      }
      if ((cnt=BlkDevAdd(bd,prt_num,whole_drv,TRUE)) && whole_drv)
        ExePrint("DskPrt('%C');\n",drv_let);
    }
    res+=cnt;
  } while (cnt);
  Free(filename);
  Free(filename2);
  return res;
}


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

//Now, we use 1 Gig page table entries.

//See ./Mem2Meg.HC

Cd(__DIR__);;
#include "Mem2Meg"

#define SAMPLE_SIZE     100000
U0 TimeIns()
{
  I64 i,start,end;
  I64 *cached_I64=MAlloc(sizeof(I64)),
        shared_blks,*uncached_I64;
  CBlkPool *bp;
  CHeapCtrl *hc;

  "$RED$Now, this demo seems broken, perhaps,\n"
        "because I run in a virtual machine.$FG$\n\n";
  CPURep;

  shared_blks=1;
  bp=Mem2MegUncachedAlloc(&shared_blks);
  hc=HeapCtrlBPInit(bp,shared_blks<<12);
  uncached_I64=MAlloc(sizeof(I64),hc);

  //Measure cached time
  start=GetTSC;
  for (i=0;i<SAMPLE_SIZE;i++)
    *cached_I64=i;
  end=GetTSC;
  "  Cached Cycles: %10,d\n",end-start;

  //Measure uncached time
  start=GetTSC;
  for (i=0;i<SAMPLE_SIZE;i++)
    *uncached_I64=i;
  end=GetTSC;
  "Uncached Cycles: %10,d\n",end-start;

  "$GREEN$The difference is even greater because the loop "
        "overhead was not subtracted.$FG$\n\n";
  Free(cached_I64);
  Free(uncached_I64);
  Mem2MegFree(bp,shared_blks);
}

TimeIns;
TimeIns;

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

//Now, we use 1 Gig page table entries.

//See ./Mem2Meg.HC

Cd(__DIR__);;
#include "Mem2Meg"

#define SAMPLE_SIZE     100000
U0 TimeIns()
{
  I64 i,start,end;
  I64 *cached_I64=MAlloc(sizeof(I64)),
        shared_blks,*uncached_I64;
  CBlkPool *bp;
  CHeapCtrl *hc;

  "$RED$Now, this demo seems broken, perhaps,\n"
        "because I run in a virtual machine.$FG$\n\n";
  CPURep;

  shared_blks=1;
  bp=Mem2MegUncachedAlloc(&shared_blks);
  hc=HeapCtrlBPInit(bp,shared_blks<<12);
  uncached_I64=MAlloc(sizeof(I64),hc);

  //Measure cached time
  start=GetTSC;
  for (i=0;i<SAMPLE_SIZE;i++)
    *cached_I64=i;
  end=GetTSC;
  "  Cached Cycles: %10,d\n",end-start;

  //Measure uncached time
  start=GetTSC;
  for (i=0;i<SAMPLE_SIZE;i++)
    *uncached_I64=i;
  end=GetTSC;
  "Uncached Cycles: %10,d\n",end-start;

  "$GREEN$The difference is even greater because the loop "
        "overhead was not subtracted.$FG$\n\n";
  Free(cached_I64);
  Free(uncached_I64);
  Mem2MegFree(bp,shared_blks);
}

TimeIns;
TimeIns;


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

#define VR_ONE_FRIENDLY_UNIT    0
#define VR_UPDATE_FRIENDLY_UNIT 1
#define VR_FRIENDLY_UNIT_DIED   3
#define VR_ONE_ENEMY_UNIT       4
#define VR_ALL_UNITS            5

class MPCtrl1
{
  I64 mode,lo,hi;
  Unit *tmpu;
};

class MPCtrl2
{
  I64 lo,hi,row,col;
};

U0 VRSetUp(I64 player)
{
  I64 i;
  Unit *ut0,*ut1;
  ut0=&units[player][0];
  ut1=&units[player^1][0];
  for (i=0;i<UNITS_NUM;i++,ut0++,ut1++) {
    LBtr(&ut1->vis[player],0);
    LBEqu(&ut0->vis[player],0,ut0->life>0);
  }
}

U0 VRMerge(I64 player)
{
  I64 i,j;
  Unit *ut1;
  U8 *dst,*src,*mask=CAlloc((UNITS_NUM+7)>>3);
  for (j=0;j<UNITS_NUM;j++) {//p0
    src=&vis_unit_bitmap[player][(((UNITS_NUM+7)&~7)*j)>>3];
    dst=mask;
    for (i=0;i<(UNITS_NUM+7)>>3;i++) //player1
      *dst++|=*src++;
  }
  ut1=&units[player^1][0];
  for (j=0;j<UNITS_NUM;j++,ut1++)
    LBEqu(&ut1->vis[player],0,Bt(mask,j) && ut1->life>0);
  Free(mask);
}

Bool MPVisRecalc(MPCtrl1 *job)
{
  Bool res=FALSE,seen;
  I64 i,j,row,col;
  F64 x1,y1,x2,y2,dd,range;
  Unit *ut0,*ut1;
  ut0=&units[cur_player][job->lo];
  ut1=&units[enemy_player][job->lo];
  if (job->tmpu) {
    row=job->tmpu->row;
    col=job->tmpu->col;
    range=job->tmpu->range*2*HEX_RADIUS;
    range*=range;
  }
  switch (job->mode) {
    case VR_UPDATE_FRIENDLY_UNIT:
    case VR_ONE_FRIENDLY_UNIT:
      if (job->mode==VR_UPDATE_FRIENDLY_UNIT)
        range=F64_MAX;
      RowCol2XY(&x1,&y1,row,col);
      for (i=job->lo;i<job->hi;i++,ut1++) {
        seen=FALSE;
        if (ut1->life>0 &&
              LOS(row,col,ut1->row,ut1->col)) {
          RowCol2XY(&x2,&y2,ut1->row,ut1->col);
          dd=Sqr(x2-x1)+Sqr(y2-y1);
          if (dd<range) {
            seen=TRUE;
            LBts(&ut1->vis[cur_player],0);
          }
        }
        if (job->mode==VR_UPDATE_FRIENDLY_UNIT)
          LBEqu(&vis_unit_bitmap[cur_player],
                i+job->tmpu->num*((UNITS_NUM+7)&~7),seen);
      }
      break;
    case VR_ONE_ENEMY_UNIT:
      RowCol2XY(&x1,&y1,row,col);
      for (i=job->lo;i<job->hi;i++,ut1++)
        if (ut1->life>0 &&
              LOS(row,col,ut1->row,ut1->col)) {
          LBts(&vis_unit_bitmap[enemy_player],
                job->tmpu->num+i*((UNITS_NUM+7)&~7));
          res=TRUE;
        } else
          LBtr(&vis_unit_bitmap[enemy_player],
                job->tmpu->num+i*((UNITS_NUM+7)&~7));
      break;
    case VR_ALL_UNITS:
      ut0=&units[cur_player][0];
      for (i=0;i<UNITS_NUM;i++,ut0++)
        if (ut0->life>0) {
          RowCol2XY(&x1,&y1,ut0->row,ut0->col);
          ut1=&units[enemy_player][job->lo];
          for (j=job->lo;j<job->hi;j++,ut1++) {
            if (ut1->life>0 &&
                  LOS(ut0->row,ut0->col,ut1->row,ut1->col)) {
              LBts(&ut1->vis[cur_player],0);
              LBts(&vis_unit_bitmap[cur_player],j+i*((UNITS_NUM+7)&~7));
            } else
              LBtr(&vis_unit_bitmap[cur_player],j+i*((UNITS_NUM+7)&~7));
          }
        } else
          for (j=job->lo;j<job->hi;j++)
            LBtr(&vis_unit_bitmap[cur_player],j+i*((UNITS_NUM+7)&~7));
      ut0=&units[enemy_player][0];
      for (i=0;i<UNITS_NUM;i++,ut0++)
        if (ut0->life>0) {
          RowCol2XY(&x1,&y1,ut0->row,ut0->col);
          ut1=&units[cur_player][job->lo];
          for (j=job->lo;j<job->hi;j++,ut1++) {
            if (ut1->life>0 &&
                  LOS(ut0->row,ut0->col,ut1->row,ut1->col)) {
              LBts(&ut1->vis[enemy_player],0);
              LBts(&vis_unit_bitmap[enemy_player],j+i*((UNITS_NUM+7)&~7));
            } else
              LBtr(&vis_unit_bitmap[enemy_player],j+i*((UNITS_NUM+7)&~7));
          }
        } else
          for (j=job->lo;j<job->hi;j++)
            LBtr(&vis_unit_bitmap[enemy_player],j+i*((UNITS_NUM+7)&~7));
      break;
  }
  return res;
}

Bool VisRecalc(I64 mode,Unit *tmpu=NULL)
{
  I64 i,hi,k,cnt;
  Bool res;
/*The compiler doesn't go out of it's way
to know if something is const.;-)  This
just compiles with the val at compile
time, an advantage of just-in-time over
AOT binaries.  TempleOS has a limited
stk size, so don't get in the habit.
MAlloc() would probably be the better choice.
*/
  MPCtrl1 job[mp_cnt];
  CJob *cmd[mp_cnt];

  if (mode==VR_FRIENDLY_UNIT_DIED) {
    MemSet((&vis_unit_bitmap[enemy_player])(U8 *)+
          (tmpu->num*((UNITS_NUM+7)&~7))>>3,0,(UNITS_NUM+7)>>3);
    VRMerge(enemy_player);
    return 0; //Return any value--don't care
  }

  cnt=mp_cnt; //Cores
  hi=UNITS_NUM;
  if (mode==VR_ONE_ENEMY_UNIT) {
    for (hi--;hi>=0;hi--)
      if (units[enemy_player][hi].life>0)
        break;
    hi++;
  }
  k=hi;
  if (hi/mp_cnt<2)
    cnt=1;
  for (i=0;i<cnt;i++) {
    job[i].mode=mode;
    job[i].tmpu=tmpu;
    job[i].hi=k;
    k-=hi/cnt;
    if (k<0) k=0;
    if (i==cnt-1) k=0;
    job[i].lo=k;
  }

  res=FALSE;
  for (i=0;i<cnt;i++)
    cmd[i]=JobQue(&MPVisRecalc,&job[i],i,0);
  for (i=0;i<cnt;i++)
    if (JobResGet(cmd[i]))
      res=TRUE;
  if (mode==VR_UPDATE_FRIENDLY_UNIT)
    VRMerge(cur_player);
  return res;
}

U0 MPVisRecalcMap(MPCtrl2 *job)
{
  I64 i,j;
  for (j=job->lo;j<job->hi;j++)
    for (i=0;i<map_cols;i++)
      if (LOS(job->row,job->col,j,i))
        vis_map[j][i]=TRUE;
      else
        vis_map[j][i]=FALSE;
}

U0 VisRecalcMap(I64 row,I64 col)
{
  I64 i,hi,k,cnt;
  MPCtrl2 job[mp_cnt];
  CJob *cmd[mp_cnt];

  cnt=mp_cnt; //Cores
  hi=map_rows;
  k=hi;
  if (hi/mp_cnt<2)
    cnt=1;
  for (i=0;i<cnt;i++) {
    job[i].row=row;
    job[i].col=col;
    job[i].hi=k;
    k-=hi/cnt;
    if (k<0) k=0;
    if (i==cnt-1) k=0;
    job[i].lo=k;
  }
  for (i=0;i<cnt;i++)
    cmd[i]=JobQue(&MPVisRecalcMap,&job[i],i,0);
  for (i=0;i<cnt;i++)
    JobResGet(cmd[i]);
}

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

#define VR_ONE_FRIENDLY_UNIT    0
#define VR_UPDATE_FRIENDLY_UNIT 1
#define VR_FRIENDLY_UNIT_DIED   3
#define VR_ONE_ENEMY_UNIT       4
#define VR_ALL_UNITS            5

class MPCtrl1
{
  I64 mode,lo,hi;
  Unit *tmpu;
};

class MPCtrl2
{
  I64 lo,hi,row,col;
};

U0 VRSetUp(I64 player)
{
  I64 i;
  Unit *ut0,*ut1;
  ut0=&units[player][0];
  ut1=&units[player^1][0];
  for (i=0;i<UNITS_NUM;i++,ut0++,ut1++) {
    LBtr(&ut1->vis[player],0);
    LBEqu(&ut0->vis[player],0,ut0->life>0);
  }
}

U0 VRMerge(I64 player)
{
  I64 i,j;
  Unit *ut1;
  U8 *dst,*src,*mask=CAlloc((UNITS_NUM+7)>>3);
  for (j=0;j<UNITS_NUM;j++) {//p0
    src=&vis_unit_bitmap[player][(((UNITS_NUM+7)&~7)*j)>>3];
    dst=mask;
    for (i=0;i<(UNITS_NUM+7)>>3;i++) //player1
      *dst++|=*src++;
  }
  ut1=&units[player^1][0];
  for (j=0;j<UNITS_NUM;j++,ut1++)
    LBEqu(&ut1->vis[player],0,Bt(mask,j) && ut1->life>0);
  Free(mask);
}

Bool MPVisRecalc(MPCtrl1 *job)
{
  Bool res=FALSE,seen;
  I64 i,j,row,col;
  F64 x1,y1,x2,y2,dd,range;
  Unit *ut0,*ut1;
  ut0=&units[cur_player][job->lo];
  ut1=&units[enemy_player][job->lo];
  if (job->tmpu) {
    row=job->tmpu->row;
    col=job->tmpu->col;
    range=job->tmpu->range*2*HEX_RADIUS;
    range*=range;
  }
  switch (job->mode) {
    case VR_UPDATE_FRIENDLY_UNIT:
    case VR_ONE_FRIENDLY_UNIT:
      if (job->mode==VR_UPDATE_FRIENDLY_UNIT)
        range=F64_MAX;
      RowCol2XY(&x1,&y1,row,col);
      for (i=job->lo;i<job->hi;i++,ut1++) {
        seen=FALSE;
        if (ut1->life>0 &&
              LOS(row,col,ut1->row,ut1->col)) {
          RowCol2XY(&x2,&y2,ut1->row,ut1->col);
          dd=Sqr(x2-x1)+Sqr(y2-y1);
          if (dd<range) {
            seen=TRUE;
            LBts(&ut1->vis[cur_player],0);
          }
        }
        if (job->mode==VR_UPDATE_FRIENDLY_UNIT)
          LBEqu(&vis_unit_bitmap[cur_player],
                i+job->tmpu->num*((UNITS_NUM+7)&~7),seen);
      }
      break;
    case VR_ONE_ENEMY_UNIT:
      RowCol2XY(&x1,&y1,row,col);
      for (i=job->lo;i<job->hi;i++,ut1++)
        if (ut1->life>0 &&
              LOS(row,col,ut1->row,ut1->col)) {
          LBts(&vis_unit_bitmap[enemy_player],
                job->tmpu->num+i*((UNITS_NUM+7)&~7));
          res=TRUE;
        } else
          LBtr(&vis_unit_bitmap[enemy_player],
                job->tmpu->num+i*((UNITS_NUM+7)&~7));
      break;
    case VR_ALL_UNITS:
      ut0=&units[cur_player][0];
      for (i=0;i<UNITS_NUM;i++,ut0++)
        if (ut0->life>0) {
          RowCol2XY(&x1,&y1,ut0->row,ut0->col);
          ut1=&units[enemy_player][job->lo];
          for (j=job->lo;j<job->hi;j++,ut1++) {
            if (ut1->life>0 &&
                  LOS(ut0->row,ut0->col,ut1->row,ut1->col)) {
              LBts(&ut1->vis[cur_player],0);
              LBts(&vis_unit_bitmap[cur_player],j+i*((UNITS_NUM+7)&~7));
            } else
              LBtr(&vis_unit_bitmap[cur_player],j+i*((UNITS_NUM+7)&~7));
          }
        } else
          for (j=job->lo;j<job->hi;j++)
            LBtr(&vis_unit_bitmap[cur_player],j+i*((UNITS_NUM+7)&~7));
      ut0=&units[enemy_player][0];
      for (i=0;i<UNITS_NUM;i++,ut0++)
        if (ut0->life>0) {
          RowCol2XY(&x1,&y1,ut0->row,ut0->col);
          ut1=&units[cur_player][job->lo];
          for (j=job->lo;j<job->hi;j++,ut1++) {
            if (ut1->life>0 &&
                  LOS(ut0->row,ut0->col,ut1->row,ut1->col)) {
              LBts(&ut1->vis[enemy_player],0);
              LBts(&vis_unit_bitmap[enemy_player],j+i*((UNITS_NUM+7)&~7));
            } else
              LBtr(&vis_unit_bitmap[enemy_player],j+i*((UNITS_NUM+7)&~7));
          }
        } else
          for (j=job->lo;j<job->hi;j++)
            LBtr(&vis_unit_bitmap[enemy_player],j+i*((UNITS_NUM+7)&~7));
      break;
  }
  return res;
}

Bool VisRecalc(I64 mode,Unit *tmpu=NULL)
{
  I64 i,hi,k,cnt;
  Bool res;
/*The compiler doesn't go out of it's way
to know if something is const.;-)  This
just compiles with the val at compile
time, an advantage of just-in-time over
AOT binaries.  TempleOS has a limited
stk size, so don't get in the habit.
MAlloc() would probably be the better choice.
*/
  MPCtrl1 job[mp_cnt];
  CJob *cmd[mp_cnt];

  if (mode==VR_FRIENDLY_UNIT_DIED) {
    MemSet((&vis_unit_bitmap[enemy_player])(U8 *)+
          (tmpu->num*((UNITS_NUM+7)&~7))>>3,0,(UNITS_NUM+7)>>3);
    VRMerge(enemy_player);
    return 0; //Return any value--don't care
  }

  cnt=mp_cnt; //Cores
  hi=UNITS_NUM;
  if (mode==VR_ONE_ENEMY_UNIT) {
    for (hi--;hi>=0;hi--)
      if (units[enemy_player][hi].life>0)
        break;
    hi++;
  }
  k=hi;
  if (hi/mp_cnt<2)
    cnt=1;
  for (i=0;i<cnt;i++) {
    job[i].mode=mode;
    job[i].tmpu=tmpu;
    job[i].hi=k;
    k-=hi/cnt;
    if (k<0) k=0;
    if (i==cnt-1) k=0;
    job[i].lo=k;
  }

  res=FALSE;
  for (i=0;i<cnt;i++)
    cmd[i]=JobQue(&MPVisRecalc,&job[i],i,0);
  for (i=0;i<cnt;i++)
    if (JobResGet(cmd[i]))
      res=TRUE;
  if (mode==VR_UPDATE_FRIENDLY_UNIT)
    VRMerge(cur_player);
  return res;
}

U0 MPVisRecalcMap(MPCtrl2 *job)
{
  I64 i,j;
  for (j=job->lo;j<job->hi;j++)
    for (i=0;i<map_cols;i++)
      if (LOS(job->row,job->col,j,i))
        vis_map[j][i]=TRUE;
      else
        vis_map[j][i]=FALSE;
}

U0 VisRecalcMap(I64 row,I64 col)
{
  I64 i,hi,k,cnt;
  MPCtrl2 job[mp_cnt];
  CJob *cmd[mp_cnt];

  cnt=mp_cnt; //Cores
  hi=map_rows;
  k=hi;
  if (hi/mp_cnt<2)
    cnt=1;
  for (i=0;i<cnt;i++) {
    job[i].row=row;
    job[i].col=col;
    job[i].hi=k;
    k-=hi/cnt;
    if (k<0) k=0;
    if (i==cnt-1) k=0;
    job[i].lo=k;
  }
  for (i=0;i<cnt;i++)
    cmd[i]=JobQue(&MPVisRecalcMap,&job[i],i,0);
  for (i=0;i<cnt;i++)
    JobResGet(cmd[i]);
}


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

U0 LoadOneImport(U8 **_src,U8 *module_base,I64 ld_flags)
{
  U8 *src=*_src,*ptr2,*st_ptr;
  I64 i,etype;
  CHashExport *tmpex=NULL;
  CHashImport *tmpiss;
  Bool first=TRUE;

  while (etype=*src++) {
    i=*src(U32 *)++;
    st_ptr=src;
    src+=StrLen(st_ptr)+1;
    if (*st_ptr) {
      if (!first) {
        *_src=st_ptr-5;
        return;
      } else {
        first=FALSE;
        if (!(tmpex=HashFind(st_ptr,
              Fs->hash_table,HTG_ALL-HTT_IMPORT_SYS_SYM))) {
          if (!(ld_flags & LDF_SILENT))
            "Unresolved Reference:%s\n",st_ptr;
          tmpiss=CAlloc(sizeof(CHashImport));
          tmpiss->str=StrNew(st_ptr);
          tmpiss->type=HTT_IMPORT_SYS_SYM;
          tmpiss->module_header_entry=st_ptr-5;
          tmpiss->module_base=module_base;
          HashAdd(tmpiss,Fs->hash_table);
        }
      }
    }
    if (tmpex) {
      ptr2=module_base+i;
      if (tmpex->type & HTT_FUN)
        i=tmpex(CHashFun *)->exe_addr;
      else if (tmpex->type & HTT_GLBL_VAR)
        i=tmpex(CHashGlblVar *)->data_addr;
      else
        i=tmpex->val;
      switch (etype) {
        case IET_REL_I8:  *ptr2(U8 *) =i-ptr2-1; break;
        case IET_IMM_U8:  *ptr2(U8 *) =i;  break;
        case IET_REL_I16: *ptr2(U16 *)=i-ptr2-2; break;
        case IET_IMM_U16: *ptr2(U16 *)=i; break;
        case IET_REL_I32: *ptr2(U32 *)=i-ptr2-4; break;
        case IET_IMM_U32: *ptr2(U32 *)=i; break;
        case IET_REL_I64: *ptr2(I64 *)=i-ptr2-8; break;
        case IET_IMM_I64: *ptr2(I64 *)=i; break;
      }
    }
  }
  *_src=src-1;
}

U0 SysSymImportsResolve(U8 *st_ptr,I64 ld_flags)
{
  CHashImport *tmpiss;
  U8 *ptr;
  while (tmpiss=HashSingleTableFind(st_ptr,
        Fs->hash_table,HTT_IMPORT_SYS_SYM)) {
    ptr=tmpiss->module_header_entry;
    LoadOneImport(&ptr,tmpiss->module_base,ld_flags);
    tmpiss->type=HTT_INVALID;
  }
}

U0 LoadPass1(U8 *src,U8 *module_base,I64 ld_flags)
{
  U8 *ptr2,*ptr3,*st_ptr;
  I64 i,j,cnt,etype;
  CHashExport *tmpex=NULL;
  while (etype=*src++) {
    i=*src(U32 *)++;
    st_ptr=src;
    src+=StrLen(st_ptr)+1;
    switch (etype) {
      case IET_REL32_EXPORT:
      case IET_IMM32_EXPORT:
      case IET_REL64_EXPORT:
      case IET_IMM64_EXPORT:
        tmpex=CAlloc(sizeof(CHashExport));
        tmpex->str=StrNew(st_ptr);
        tmpex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
        if (etype==IET_IMM32_EXPORT||etype==IET_IMM64_EXPORT)
          tmpex->val=i;
        else
          tmpex->val=i+module_base;
        HashAdd(tmpex,Fs->hash_table);
        SysSymImportsResolve(st_ptr,ld_flags);
        break;
      case IET_REL_I0...IET_IMM_I64:
        src=st_ptr-5;
        LoadOneImport(&src,module_base,ld_flags);
        break;
      case IET_ABS_ADDR:
        if (ld_flags & LDF_NO_ABSS)
          src+=i*sizeof(U32);
        else {
          cnt=i;
          for (j=0;j<cnt;j++) {
            ptr2=module_base+*src(U32 *)++;
            *ptr2(U32 *)+=module_base;
          }
        }
        break;

      start:
        case IET_CODE_HEAP:
          ptr3=MAlloc(*src(I32 *)++,Fs->code_heap);
          break;
        case IET_ZEROED_CODE_HEAP:
          ptr3=CAlloc(*src(I32 *)++,Fs->code_heap);
          break;
      end:
        if (*st_ptr) {
          tmpex=CAlloc(sizeof(CHashExport));
          tmpex->str=StrNew(st_ptr);
          tmpex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
          tmpex->val=ptr3;
          HashAdd(tmpex,Fs->hash_table);
        }
        cnt=i;
        for (j=0;j<cnt;j++) {
          ptr2=module_base+*src(U32 *)++;
          *ptr2(I32 *)+=ptr3;
        }
        break;

      start:
        case IET_DATA_HEAP:
          ptr3=MAlloc(*src(I64 *)++);
          break;
        case IET_ZEROED_DATA_HEAP:
          ptr3=CAlloc(*src(I64 *)++);
          break;
      end:
        if (*st_ptr) {
          tmpex=CAlloc(sizeof(CHashExport));
          tmpex->str=StrNew(st_ptr);
          tmpex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
          tmpex->val=ptr3;
          HashAdd(tmpex,Fs->hash_table);
        }
        cnt=i;
        for (j=0;j<cnt;j++) {
          ptr2=module_base+*src(U32 *)++;
          *ptr2(I64 *)+=ptr3;
        }
        break;
    }
  }
}

U0 LoadPass2(U8 *src,U8 *module_base,I64)
{
  U8 *st_ptr;
  I64 i,etype;
  while (etype=*src++) {
    i=*src(U32 *)++;
    st_ptr=src;
    src+=StrLen(st_ptr)+1;
    switch (etype) {
      case IET_MAIN:
        Call(i+module_base);
        break;
      case IET_ABS_ADDR:
        src+=sizeof(U32)*i;
        break;
      case IET_CODE_HEAP:
      case IET_ZEROED_CODE_HEAP:
        src+=4+sizeof(U32)*i;
        break;
      case IET_DATA_HEAP:
      case IET_ZEROED_DATA_HEAP:
        src+=8+sizeof(U32)*i;
        break;
    }
  }
}

CBinFile *Load(U8 *filename,I64 ld_flags=0,CBinFile *bfh_addr=INVALID_PTR)
{//Load a .BIN file module into memory.
//bfh_addr==INVALID_PTR means don't care what load addr.
  U8 *fbuf,*module_base,*absname;
  I64 size,module_align,misalignment;
  CBinFile *bfh;

  fbuf=ExtDft(filename,"BIN.Z");
  if (!(bfh=FileRead(fbuf,&size))) {
    Free(fbuf);
    return NULL;
  }

  //See Patch Table Generation
  module_align=1<<bfh->module_align_bits;
  if (!module_align || bfh->bin_signature!=BIN_SIGNATURE_VAL) {
    Free(bfh);
    Free(fbuf);
    throw('BinModul');
  }

  if (bfh_addr==INVALID_PTR) {
    if (bfh->org==INVALID_PTR) {
      misalignment=module_align-sizeof(CBinFile);
      if (misalignment<0)
        misalignment&=module_align-1;
      if (Fs->code_heap!=Fs->data_heap) {
        if (module_align<16)
          module_align=16;
        bfh_addr=MAllocAligned(size,module_align,Fs->code_heap,misalignment);
      } else if (module_align>8)
        bfh_addr=MAllocAligned(size,module_align,,misalignment);
      else {//Less than 2Gig system memory
        bfh_addr=bfh;
        goto lo_skip; //File is already in code heap area, don't copy.
      }
    } else
      bfh_addr=bfh->org;
  }
  MemCpy(bfh_addr,bfh,size);
  Free(bfh);

  lo_skip:
  module_base=bfh_addr(U8 *)+sizeof(CBinFile);

  absname=FileNameAbs(fbuf);
  Free(fbuf);
  fbuf=StrNew(absname);
  FileExtRem(fbuf);
  if (fbuf[1]==':' && StrLen(fbuf)>2)
    HashGenericAdd(fbuf+2,HTT_MODULE|HTF_PUBLIC,bfh_addr);
  LoadPass1(bfh_addr(U8 *)+bfh_addr->patch_table_offset,module_base,ld_flags);
  if (!(ld_flags&LDF_JUST_LOAD))
    LoadPass2(bfh_addr(U8 *)+bfh_addr->patch_table_offset,module_base,ld_flags);
  Free(absname);
  Free(fbuf);
  return bfh_addr;
}

U0 LoadKernel()
{
  HashGenericAdd(KERNEL_MODULE_NAME,HTT_MODULE|HTF_PUBLIC,
        mem_boot_base-sizeof(CBinFile));

  //Abs patches done here CPatchTableAbsAddr.
  LoadPass1(sys_boot_patch_table_base,mem_boot_base,LDF_NO_ABSS|LDF_SILENT);

  //No main routines
  //  LoadPass2(sys_boot_patch_table_base,mem_boot_base,0);
}

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

U0 LoadOneImport(U8 **_src,U8 *module_base,I64 ld_flags)
{
  U8 *src=*_src,*ptr2,*st_ptr;
  I64 i,etype;
  CHashExport *tmpex=NULL;
  CHashImport *tmpiss;
  Bool first=TRUE;

  while (etype=*src++) {
    i=*src(U32 *)++;
    st_ptr=src;
    src+=StrLen(st_ptr)+1;
    if (*st_ptr) {
      if (!first) {
        *_src=st_ptr-5;
        return;
      } else {
        first=FALSE;
        if (!(tmpex=HashFind(st_ptr,
              Fs->hash_table,HTG_ALL-HTT_IMPORT_SYS_SYM))) {
          if (!(ld_flags & LDF_SILENT))
            "Unresolved Reference:%s\n",st_ptr;
          tmpiss=CAlloc(sizeof(CHashImport));
          tmpiss->str=StrNew(st_ptr);
          tmpiss->type=HTT_IMPORT_SYS_SYM;
          tmpiss->module_header_entry=st_ptr-5;
          tmpiss->module_base=module_base;
          HashAdd(tmpiss,Fs->hash_table);
        }
      }
    }
    if (tmpex) {
      ptr2=module_base+i;
      if (tmpex->type & HTT_FUN)
        i=tmpex(CHashFun *)->exe_addr;
      else if (tmpex->type & HTT_GLBL_VAR)
        i=tmpex(CHashGlblVar *)->data_addr;
      else
        i=tmpex->val;
      switch (etype) {
        case IET_REL_I8:  *ptr2(U8 *) =i-ptr2-1; break;
        case IET_IMM_U8:  *ptr2(U8 *) =i;  break;
        case IET_REL_I16: *ptr2(U16 *)=i-ptr2-2; break;
        case IET_IMM_U16: *ptr2(U16 *)=i; break;
        case IET_REL_I32: *ptr2(U32 *)=i-ptr2-4; break;
        case IET_IMM_U32: *ptr2(U32 *)=i; break;
        case IET_REL_I64: *ptr2(I64 *)=i-ptr2-8; break;
        case IET_IMM_I64: *ptr2(I64 *)=i; break;
      }
    }
  }
  *_src=src-1;
}

U0 SysSymImportsResolve(U8 *st_ptr,I64 ld_flags)
{
  CHashImport *tmpiss;
  U8 *ptr;
  while (tmpiss=HashSingleTableFind(st_ptr,
        Fs->hash_table,HTT_IMPORT_SYS_SYM)) {
    ptr=tmpiss->module_header_entry;
    LoadOneImport(&ptr,tmpiss->module_base,ld_flags);
    tmpiss->type=HTT_INVALID;
  }
}

U0 LoadPass1(U8 *src,U8 *module_base,I64 ld_flags)
{
  U8 *ptr2,*ptr3,*st_ptr;
  I64 i,j,cnt,etype;
  CHashExport *tmpex=NULL;
  while (etype=*src++) {
    i=*src(U32 *)++;
    st_ptr=src;
    src+=StrLen(st_ptr)+1;
    switch (etype) {
      case IET_REL32_EXPORT:
      case IET_IMM32_EXPORT:
      case IET_REL64_EXPORT:
      case IET_IMM64_EXPORT:
        tmpex=CAlloc(sizeof(CHashExport));
        tmpex->str=StrNew(st_ptr);
        tmpex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
        if (etype==IET_IMM32_EXPORT||etype==IET_IMM64_EXPORT)
          tmpex->val=i;
        else
          tmpex->val=i+module_base;
        HashAdd(tmpex,Fs->hash_table);
        SysSymImportsResolve(st_ptr,ld_flags);
        break;
      case IET_REL_I0...IET_IMM_I64:
        src=st_ptr-5;
        LoadOneImport(&src,module_base,ld_flags);
        break;
      case IET_ABS_ADDR:
        if (ld_flags & LDF_NO_ABSS)
          src+=i*sizeof(U32);
        else {
          cnt=i;
          for (j=0;j<cnt;j++) {
            ptr2=module_base+*src(U32 *)++;
            *ptr2(U32 *)+=module_base;
          }
        }
        break;

      start:
        case IET_CODE_HEAP:
          ptr3=MAlloc(*src(I32 *)++,Fs->code_heap);
          break;
        case IET_ZEROED_CODE_HEAP:
          ptr3=CAlloc(*src(I32 *)++,Fs->code_heap);
          break;
      end:
        if (*st_ptr) {
          tmpex=CAlloc(sizeof(CHashExport));
          tmpex->str=StrNew(st_ptr);
          tmpex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
          tmpex->val=ptr3;
          HashAdd(tmpex,Fs->hash_table);
        }
        cnt=i;
        for (j=0;j<cnt;j++) {
          ptr2=module_base+*src(U32 *)++;
          *ptr2(I32 *)+=ptr3;
        }
        break;

      start:
        case IET_DATA_HEAP:
          ptr3=MAlloc(*src(I64 *)++);
          break;
        case IET_ZEROED_DATA_HEAP:
          ptr3=CAlloc(*src(I64 *)++);
          break;
      end:
        if (*st_ptr) {
          tmpex=CAlloc(sizeof(CHashExport));
          tmpex->str=StrNew(st_ptr);
          tmpex->type=HTT_EXPORT_SYS_SYM|HTF_IMM;
          tmpex->val=ptr3;
          HashAdd(tmpex,Fs->hash_table);
        }
        cnt=i;
        for (j=0;j<cnt;j++) {
          ptr2=module_base+*src(U32 *)++;
          *ptr2(I64 *)+=ptr3;
        }
        break;
    }
  }
}

U0 LoadPass2(U8 *src,U8 *module_base,I64)
{
  U8 *st_ptr;
  I64 i,etype;
  while (etype=*src++) {
    i=*src(U32 *)++;
    st_ptr=src;
    src+=StrLen(st_ptr)+1;
    switch (etype) {
      case IET_MAIN:
        Call(i+module_base);
        break;
      case IET_ABS_ADDR:
        src+=sizeof(U32)*i;
        break;
      case IET_CODE_HEAP:
      case IET_ZEROED_CODE_HEAP:
        src+=4+sizeof(U32)*i;
        break;
      case IET_DATA_HEAP:
      case IET_ZEROED_DATA_HEAP:
        src+=8+sizeof(U32)*i;
        break;
    }
  }
}

CBinFile *Load(U8 *filename,I64 ld_flags=0,CBinFile *bfh_addr=INVALID_PTR)
{//Load a .BIN file module into memory.
//bfh_addr==INVALID_PTR means don't care what load addr.
  U8 *fbuf,*module_base,*absname;
  I64 size,module_align,misalignment;
  CBinFile *bfh;

  fbuf=ExtDft(filename,"BIN.Z");
  if (!(bfh=FileRead(fbuf,&size))) {
    Free(fbuf);
    return NULL;
  }

  //See Patch Table Generation
  module_align=1<<bfh->module_align_bits;
  if (!module_align || bfh->bin_signature!=BIN_SIGNATURE_VAL) {
    Free(bfh);
    Free(fbuf);
    throw('BinModul');
  }

  if (bfh_addr==INVALID_PTR) {
    if (bfh->org==INVALID_PTR) {
      misalignment=module_align-sizeof(CBinFile);
      if (misalignment<0)
        misalignment&=module_align-1;
      if (Fs->code_heap!=Fs->data_heap) {
        if (module_align<16)
          module_align=16;
        bfh_addr=MAllocAligned(size,module_align,Fs->code_heap,misalignment);
      } else if (module_align>8)
        bfh_addr=MAllocAligned(size,module_align,,misalignment);
      else {//Less than 2Gig system memory
        bfh_addr=bfh;
        goto lo_skip; //File is already in code heap area, don't copy.
      }
    } else
      bfh_addr=bfh->org;
  }
  MemCpy(bfh_addr,bfh,size);
  Free(bfh);

  lo_skip:
  module_base=bfh_addr(U8 *)+sizeof(CBinFile);

  absname=FileNameAbs(fbuf);
  Free(fbuf);
  fbuf=StrNew(absname);
  FileExtRem(fbuf);
  if (fbuf[1]==':' && StrLen(fbuf)>2)
    HashGenericAdd(fbuf+2,HTT_MODULE|HTF_PUBLIC,bfh_addr);
  LoadPass1(bfh_addr(U8 *)+bfh_addr->patch_table_offset,module_base,ld_flags);
  if (!(ld_flags&LDF_JUST_LOAD))
    LoadPass2(bfh_addr(U8 *)+bfh_addr->patch_table_offset,module_base,ld_flags);
  Free(absname);
  Free(fbuf);
  return bfh_addr;
}

U0 LoadKernel()
{
  HashGenericAdd(KERNEL_MODULE_NAME,HTT_MODULE|HTF_PUBLIC,
        mem_boot_base-sizeof(CBinFile));

  //Abs patches done here CPatchTableAbsAddr.
  LoadPass1(sys_boot_patch_table_base,mem_boot_base,LDF_NO_ABSS|LDF_SILENT);

  //No main routines
  //  LoadPass2(sys_boot_patch_table_base,mem_boot_base,0);
}


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

/*
Char graphics are how games on the C64 were made.  You don't need to do it
this way, unless for fun.  You can just make device context bigger than
the scrn and scroll around.

See  ::/Demo/Games/RawHide.HC or ::/Demo/Games/BigGuns.HC.

The nice thing about character graphics are the animations.
*/

#define MAP_WIDTH       (TEXT_COLS*2)
#define MAP_HEIGHT      (TEXT_ROWS*2)

#define CH_WATER        '^'
#define CH_LAND         CH_SPACE
#define CH_TREE         '*'

U16 map[MAP_HEIGHT][MAP_WIDTH];

I64 scrn_pix_x,scrn_pix_y;

U0 DrawIt(CTask *task,CDC *)
{
  U16 *ptr;
  I64 i,j,y=scrn_pix_y>>3;
  gr.hide_col=gr.hide_row=TRUE;
  gr.pan_text_x=7-scrn_pix_x&7;
  gr.pan_text_y=7-scrn_pix_y&7;
  for (i=0;i<task->win_height;i++) {
    ptr=&map[y++][scrn_pix_x>>3];
    for (j=0;j<task->win_width;j++)
        //By the time you clip to window and handle Fs->scroll_x,Fs->scroll_y,
        //it is too much trouble to do raw access to gr.text_base like we do
        //in ::/Demo/Games/Maze.HC.
      TextChar(task,FALSE,j,i,*ptr++);
  }
}

U8 *old_font=text.font;
U64 waves[4]={
0x0011AA440011AA44,0x0022558800225588,
0x0044AA110044AA11,0x0088552200885522};

U0 AnimateEndCB()
{
  text.font=old_font;
  Exit;
}

U0 AnimateTask(I64)
{
  I64 i;
  U64 *font=MAlloc(256*8);
  Fs->task_end_cb=&AnimateEndCB;
  MemCpy(font,text.font,256*8);
  text.font=font;
  font[CH_TREE]=0x18187E7E3C3C18;
  while (TRUE) {
    font[CH_WATER]=waves[i++&0x3];
    Sleep(200);
    Refresh;
  }
}

U0 ScrollTaskX(I64 sign)
{
  I64 i;
  for (i=0;i<32;i++) {
    scrn_pix_x=ClampI64(scrn_pix_x+sign,0,
          (MAP_WIDTH-TEXT_COLS+1)*FONT_WIDTH);
    Refresh;
  }
}

U0 ScrollTaskY(I64 sign)
{
  I64 i;
  for (i=0;i<32;i++) {
    scrn_pix_y=ClampI64(scrn_pix_y+sign,0,
          (MAP_HEIGHT-TEXT_ROWS+2)*FONT_HEIGHT);
    Refresh;
  }
}

U0 Init()
{
  I64 i,j,x,y;
  scrn_pix_x=(MAP_WIDTH-TEXT_COLS)>>1*FONT_WIDTH;
  scrn_pix_y=(MAP_HEIGHT-TEXT_ROWS)>>1*FONT_HEIGHT;

  MemSetU16(map,CH_WATER+(BLUE<<4+LTBLUE)<<8,MAP_WIDTH*MAP_HEIGHT);
  for (i=1;i<MAP_WIDTH-1;i++)
    map[0][i]=map[MAP_HEIGHT-1][i]='.'+(BLUE<<4+RED)<<8;
  for (i=1;i<MAP_HEIGHT-1;i++)
    map[i][0]=map[i][MAP_WIDTH-1]='.'+(BLUE<<4+RED)<<8;
  map[0][0]                     ='.'+(BLUE<<4+RED)<<8;
  map[0][MAP_WIDTH-1]           ='.'+(BLUE<<4+RED)<<8;
  map[MAP_HEIGHT-1][0]          ='.'+(BLUE<<4+RED)<<8;
  map[MAP_HEIGHT-1][MAP_WIDTH-1]='.'+(BLUE<<4+RED)<<8;

  for (i=0;i<20;i++) {
    x=MAP_WIDTH*Rand;
    y=MAP_HEIGHT*Rand;
    for (j=0;j<1000;j++) {
      map[y][x]=CH_LAND+(YELLOW<<4+BLACK)<<8;
      x=ClampI64(x+RandU16%3-1,0,MAP_WIDTH-1);
      y=ClampI64(y+RandU16%3-1,0,MAP_HEIGHT-1);
    }
  }
  for (i=0;i<100;i++) {
    do {
      x=MAP_WIDTH*Rand;
      y=MAP_HEIGHT*Rand;
    } while (map[y][x].u8[0]!=CH_LAND);
    for (j=0;j<100;j++) {
      map[y][x]=CH_TREE+(YELLOW<<4+GREEN)<<8;
      x=ClampI64(x+RandU16%3-1,0,MAP_WIDTH-1);
      y=ClampI64(y+RandU16%3-1,0,MAP_HEIGHT-1);
    }
  }
}

U0 CleanUp()
{
  gr.pan_text_x=gr.pan_text_y=0;
  gr.hide_col=gr.hide_row=FALSE;
}

U0 CharDemo()
{
  I64 sc;
  SettingsPush; //See SettingsPush
  Fs->text_attr=YELLOW<<4+BLUE;
  AutoComplete;
  WinBorder;
  WinMax;
  DocCursor;

  MenuPush(
        "File {"
        "  Abort(,CH_SHIFT_ESC);"
        "  Exit(,CH_ESC);"
        "}"
        "Play {"
        "  Restart(,'\n');"
        "  Left(,,SC_CURSOR_LEFT);"
        "  Right(,,SC_CURSOR_RIGHT);"
        "  Up(,,SC_CURSOR_UP);"
        "  Down(,,SC_CURSOR_DOWN);"
        "}"
        );
  Init;
  Fs->animate_task=Spawn(&AnimateTask,NULL,"Animate",,Fs);
  Fs->draw_it=&DrawIt;
  try {
    while (TRUE) {
      switch (GetKey(&sc)) {
        case 0:
          switch (sc.u8[0]) {
            case SC_CURSOR_LEFT:
              Spawn(&ScrollTaskX,-1,"Scroll",,Fs);
              break;
            case SC_CURSOR_RIGHT:
              Spawn(&ScrollTaskX,1,"Scroll",,Fs);
              break;
            case SC_CURSOR_UP:
              Spawn(&ScrollTaskY,-1,"Scroll",,Fs);
              break;
            case SC_CURSOR_DOWN:
              Spawn(&ScrollTaskY,1,"Scroll",,Fs);
              break;
          }
          break;
        case '\n':
          CleanUp;
          Init;
          break;
        case CH_SHIFT_ESC:
        case CH_ESC:
          goto sq_done;
      }
    }
sq_done: //Don't goto out of try
  } catch
    PutExcept;
  SettingsPop;
  CleanUp;
  MenuPop;
}

CharDemo;

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

/*
Char graphics are how games on the C64 were made.  You don't need to do it
this way, unless for fun.  You can just make device context bigger than
the scrn and scroll around.

See  ::/Demo/Games/RawHide.HC or ::/Demo/Games/BigGuns.HC.

The nice thing about character graphics are the animations.
*/

#define MAP_WIDTH       (TEXT_COLS*2)
#define MAP_HEIGHT      (TEXT_ROWS*2)

#define CH_WATER        '^'
#define CH_LAND         CH_SPACE
#define CH_TREE         '*'

U16 map[MAP_HEIGHT][MAP_WIDTH];

I64 scrn_pix_x,scrn_pix_y;

U0 DrawIt(CTask *task,CDC *)
{
  U16 *ptr;
  I64 i,j,y=scrn_pix_y>>3;
  gr.hide_col=gr.hide_row=TRUE;
  gr.pan_text_x=7-scrn_pix_x&7;
  gr.pan_text_y=7-scrn_pix_y&7;
  for (i=0;i<task->win_height;i++) {
    ptr=&map[y++][scrn_pix_x>>3];
    for (j=0;j<task->win_width;j++)
        //By the time you clip to window and handle Fs->scroll_x,Fs->scroll_y,
        //it is too much trouble to do raw access to gr.text_base like we do
        //in ::/Demo/Games/Maze.HC.
      TextChar(task,FALSE,j,i,*ptr++);
  }
}

U8 *old_font=text.font;
U64 waves[4]={
0x0011AA440011AA44,0x0022558800225588,
0x0044AA110044AA11,0x0088552200885522};

U0 AnimateEndCB()
{
  text.font=old_font;
  Exit;
}

U0 AnimateTask(I64)
{
  I64 i;
  U64 *font=MAlloc(256*8);
  Fs->task_end_cb=&AnimateEndCB;
  MemCpy(font,text.font,256*8);
  text.font=font;
  font[CH_TREE]=0x18187E7E3C3C18;
  while (TRUE) {
    font[CH_WATER]=waves[i++&0x3];
    Sleep(200);
    Refresh;
  }
}

U0 ScrollTaskX(I64 sign)
{
  I64 i;
  for (i=0;i<32;i++) {
    scrn_pix_x=ClampI64(scrn_pix_x+sign,0,
          (MAP_WIDTH-TEXT_COLS+1)*FONT_WIDTH);
    Refresh;
  }
}

U0 ScrollTaskY(I64 sign)
{
  I64 i;
  for (i=0;i<32;i++) {
    scrn_pix_y=ClampI64(scrn_pix_y+sign,0,
          (MAP_HEIGHT-TEXT_ROWS+2)*FONT_HEIGHT);
    Refresh;
  }
}

U0 Init()
{
  I64 i,j,x,y;
  scrn_pix_x=(MAP_WIDTH-TEXT_COLS)>>1*FONT_WIDTH;
  scrn_pix_y=(MAP_HEIGHT-TEXT_ROWS)>>1*FONT_HEIGHT;

  MemSetU16(map,CH_WATER+(BLUE<<4+LTBLUE)<<8,MAP_WIDTH*MAP_HEIGHT);
  for (i=1;i<MAP_WIDTH-1;i++)
    map[0][i]=map[MAP_HEIGHT-1][i]='.'+(BLUE<<4+RED)<<8;
  for (i=1;i<MAP_HEIGHT-1;i++)
    map[i][0]=map[i][MAP_WIDTH-1]='.'+(BLUE<<4+RED)<<8;
  map[0][0]                     ='.'+(BLUE<<4+RED)<<8;
  map[0][MAP_WIDTH-1]           ='.'+(BLUE<<4+RED)<<8;
  map[MAP_HEIGHT-1][0]          ='.'+(BLUE<<4+RED)<<8;
  map[MAP_HEIGHT-1][MAP_WIDTH-1]='.'+(BLUE<<4+RED)<<8;

  for (i=0;i<20;i++) {
    x=MAP_WIDTH*Rand;
    y=MAP_HEIGHT*Rand;
    for (j=0;j<1000;j++) {
      map[y][x]=CH_LAND+(YELLOW<<4+BLACK)<<8;
      x=ClampI64(x+RandU16%3-1,0,MAP_WIDTH-1);
      y=ClampI64(y+RandU16%3-1,0,MAP_HEIGHT-1);
    }
  }
  for (i=0;i<100;i++) {
    do {
      x=MAP_WIDTH*Rand;
      y=MAP_HEIGHT*Rand;
    } while (map[y][x].u8[0]!=CH_LAND);
    for (j=0;j<100;j++) {
      map[y][x]=CH_TREE+(YELLOW<<4+GREEN)<<8;
      x=ClampI64(x+RandU16%3-1,0,MAP_WIDTH-1);
      y=ClampI64(y+RandU16%3-1,0,MAP_HEIGHT-1);
    }
  }
}

U0 CleanUp()
{
  gr.pan_text_x=gr.pan_text_y=0;
  gr.hide_col=gr.hide_row=FALSE;
}

U0 CharDemo()
{
  I64 sc;
  SettingsPush; //See SettingsPush
  Fs->text_attr=YELLOW<<4+BLUE;
  AutoComplete;
  WinBorder;
  WinMax;
  DocCursor;

  MenuPush(
        "File {"
        "  Abort(,CH_SHIFT_ESC);"
        "  Exit(,CH_ESC);"
        "}"
        "Play {"
        "  Restart(,'\n');"
        "  Left(,,SC_CURSOR_LEFT);"
        "  Right(,,SC_CURSOR_RIGHT);"
        "  Up(,,SC_CURSOR_UP);"
        "  Down(,,SC_CURSOR_DOWN);"
        "}"
        );
  Init;
  Fs->animate_task=Spawn(&AnimateTask,NULL,"Animate",,Fs);
  Fs->draw_it=&DrawIt;
  try {
    while (TRUE) {
      switch (GetKey(&sc)) {
        case 0:
          switch (sc.u8[0]) {
            case SC_CURSOR_LEFT:
              Spawn(&ScrollTaskX,-1,"Scroll",,Fs);
              break;
            case SC_CURSOR_RIGHT:
              Spawn(&ScrollTaskX,1,"Scroll",,Fs);
              break;
            case SC_CURSOR_UP:
              Spawn(&ScrollTaskY,-1,"Scroll",,Fs);
              break;
            case SC_CURSOR_DOWN:
              Spawn(&ScrollTaskY,1,"Scroll",,Fs);
              break;
          }
          break;
        case '\n':
          CleanUp;
          Init;
          break;
        case CH_SHIFT_ESC:
        case CH_ESC:
          goto sq_done;
      }
    }
sq_done: //Don't goto out of try
  } catch
    PutExcept;
  SettingsPop;
  CleanUp;
  MenuPop;
}

CharDemo;


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

#help_index "Graphics"

public Bool GrClamp(CDC *dc=gr.dc,I64 *left,I64 *top,I64 *right,I64 *bottom,
        I64 width=0,I64 height=0)
{//Returns scrn, not window coordinates.
  CTask *win_task;
  *left=0;
  *top=0;
  *right=dc->width-1;
  *bottom=dc->height-1;
  if (dc->flags & DCF_SCRN_BITMAP) {
    win_task=dc->win_task;
    if (GR_WIDTH-1<*right)
      *right=GR_WIDTH-1;
    if (GR_HEIGHT-1<*bottom)
      *bottom=GR_HEIGHT-1;
    if (win_task->pix_left>*left)
      *left=win_task->pix_left;
    if (win_task->pix_top>*top)
      *top=win_task->pix_top;
    if (win_task->pix_right<*right)
      *right=win_task->pix_right;
    if (win_task->pix_bottom<*bottom)
      *bottom=win_task->pix_bottom;
  }
  *left-=width;
  *right+=width;
  *top-=height;
  *bottom+=height;
  return *left<=*right && *top<=*bottom;
}

Bool DCClipLine(CDC *dc=gr.dc,I64 *x1,I64 *y1,I64 *x2,I64 *y2,
        I64 width=0,I64 height=0)
{//Also converts window to scrn coordinates
  I64 left,top,right,bottom;
  CTask *win_task;
  if (GrClamp(dc,&left,&top,&right,&bottom,width,height)) {
    if (dc->flags & DCF_SCRN_BITMAP) {
      win_task=dc->win_task;
      *x1+=win_task->pix_left+win_task->scroll_x;
      *y1+=win_task->pix_top+win_task->scroll_y;
      *x2+=win_task->pix_left+win_task->scroll_x;
      *y2+=win_task->pix_top+win_task->scroll_y;
    }
    return ClipLine(x1,y1,x2,y2,left,top,right,bottom);
  } else
    return FALSE;
}

public Bool GrPlot(CDC *dc=gr.dc,I64 x,I64 y)
{//2D. Clipping but No transformation or thick.
  I32 *db=dc->depth_buf;
  CTask *win_task;
  CColorROPU32 old_color;
  dc->depth_buf=NULL;
  if (dc->brush) {
    old_color=dc->color;
    if (dc->color.c0.rop!=ROPB_COLLISION)
      dc->color.c0.rop=ROPB_MONO;
    GrBlot(dc,x,y,dc->brush);
    dc->color=old_color;
  } else if (dc->flags & DCF_SCRN_BITMAP) {
    win_task=dc->win_task;
    x+=win_task->pix_left+win_task->scroll_x;
    y+=win_task->pix_top+win_task->scroll_y;
    if (win_task->pix_left<=x<=win_task->pix_right &&
          win_task->pix_top<=y<=win_task->pix_bottom &&
          0<=x<dc->width && 0<=y<dc->height &&
          (win_task->next_task==sys_winmgr_task ||
          dc->flags&DCF_ON_TOP ||
          !IsPixCovered0(win_task,x,y)))
      GrPlot0(dc,x,y);
  } else
    if (0<=x<dc->width && 0<=y<dc->height)
      GrPlot0(dc,x,y);
  dc->depth_buf=db;
  return TRUE;
}

Bool GrPlot1(CDC *dc=gr.dc,I64 x,I64 y)
{//Clipping but No transformation or thick, called with db_z set
  CTask *win_task;
  CColorROPU32 old_color;
  if (dc->brush) {
    old_color=dc->color;
    if (dc->color.c0.rop!=ROPB_COLLISION)
      dc->color.c0.rop=ROPB_MONO;
    if (dc->depth_buf)
      GrBlot3(dc,x,y,dc->db_z,dc->brush);
    else
      GrBlot(dc,x,y,dc->brush);
    dc->color=old_color;
  } else if (dc->flags & DCF_SCRN_BITMAP) {
    win_task=dc->win_task;
    x+=win_task->pix_left+win_task->scroll_x;
    y+=win_task->pix_top+win_task->scroll_y;
    if (win_task->pix_left<=x<=win_task->pix_right &&
          win_task->pix_top <=y<=win_task->pix_bottom &&
          0<=x<dc->width && 0<=y<dc->height &&
          (win_task->next_task==sys_winmgr_task ||
          dc->flags&DCF_ON_TOP ||
          !IsPixCovered0(win_task,x,y)))
      GrPlot0(dc,x,y);
  } else
    if (0<=x<dc->width && 0<=y<dc->height)
      GrPlot0(dc,x,y);
  return TRUE;
}

public I64 GrPeek(CDC *dc=gr.dc,I64 x,I64 y)
{//2D. Clipping but no transformation.
//Returns pix color or -1 if off-scrn or covered.
  CTask *win_task;
  if (dc->flags & DCF_SCRN_BITMAP) {
    win_task=dc->win_task;
    x+=win_task->pix_left+win_task->scroll_x;
    y+=win_task->pix_top+win_task->scroll_y;
    if (!(win_task->pix_left<=x<=win_task->pix_right)  ||
          !(win_task->pix_top <=y<=win_task->pix_bottom) ||
          !(0<=x<dc->width) || !(0<=y<dc->height) ||
          win_task->next_task!=sys_winmgr_task &&
          !(dc->flags&DCF_ON_TOP) &&
          IsPixCovered0(win_task,x,y))
      return -1;
  } else
    if (!(0<=x<dc->width) || !(0<=y<dc->height))
      return -1;
  return GrPeek0(dc,x,y);
}

/*

This is an easier to understand
version of the nonrecursive routine below.
I64 GrFloodFillRay(CDC *dc,I64 x,I64 y,I64 z,I32 *db)
{
  I64 res,j,x1,ray_len,ray_len2;

  if (UnusedStk<0x80)
    Panic("Stk Overflow",Fs);

  res=ray_len=GrRayLen(dc,&x,y,z,db);
  y--;
  j=ray_len;
  x1=x;
  while (j>0) {
    if (ray_len2=GrRayLenMinus(dc,x1,y))
      res+=GrFloodFillRay(dc,x1,y,z,db);
    j-=ray_len2+1;
    x1-=ray_len2+1;
  }
  y+=2;
  j=ray_len;
  x1=x;
  while (j>0) {
    if (ray_len2=GrRayLenMinus(dc,x1,y))
      res+=GrFloodFillRay(dc,x1,y,z,db);
    j-=ray_len2+1;
    x1-=ray_len2+1;
  }
  return res;
}
*/

class CFFRay
{
  I64 state,x,y,j,x1,ray_len,ray_len2;
};

I64 GrFloodFillRay(CDC *dc,I64 x,I64 y,I64 z,I32 *db)
{//See the above commented-out routine for an easier to understand version.
//Returns cnt of pixs changed
  I64 res=0;
//We don't dynamically calculate the size to avoid
  //fragmentation of memory.
  CFFRay *f_dc=MAlloc(sizeof(CFFRay)*0x80000),*f=f_dc;
  f->x=x;
  f->y=y;
  f->state=0;
  do {
    switch [f->state] {
      case 0:
        f->state++;
        res+=f->ray_len=GrRayLen(dc,&f->x,f->y,z,db);
        f->y--;
        f->j=f->ray_len;
        f->x1=f->x;
        break;
      case 1:
        if (f->j>0) {
          f->state++;
          if (f->ray_len2=GrRayLenMinus(dc,f->x1,f->y)) {
            f[1].x=f->x1;
            f[1].y=f->y;
            f[1].state=0;
            f++;
          }
        } else
          f->state+=2;
        break;
      case 2:
        f->state--;
        f->j-=f->ray_len2+1;
        f->x1-=f->ray_len2+1;
        break;
      case 3:
        f->state++;
        f->y+=2;
        f->j=f->ray_len;
        f->x1=f->x;
        break;
      case 4:
        if (f->j>0) {
          f->state++;
          if (f->ray_len2=GrRayLenMinus(dc,f->x1,f->y)) {
            f[1].x=f->x1;
            f[1].y=f->y;
            f[1].state=0;
            f++;
          }
        } else
          f->state+=2;
        bre

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

#help_index "Graphics"

public Bool GrClamp(CDC *dc=gr.dc,I64 *left,I64 *top,I64 *right,I64 *bottom,
        I64 width=0,I64 height=0)
{//Returns scrn, not window coordinates.
  CTask *win_task;
  *left=0;
  *top=0;
  *right=dc->width-1;
  *bottom=dc->height-1;
  if (dc->flags & DCF_SCRN_BITMAP) {
    win_task=dc->win_task;
    if (GR_WIDTH-1<*right)
      *right=GR_WIDTH-1;
    if (GR_HEIGHT-1<*bottom)
      *bottom=GR_HEIGHT-1;
    if (win_task->pix_left>*left)
      *left=win_task->pix_left;
    if (win_task->pix_top>*top)
      *top=win_task->pix_top;
    if (win_task->pix_right<*right)
      *right=win_task->pix_right;
    if (win_task->pix_bottom<*bottom)
      *bottom=win_task->pix_bottom;
  }
  *left-=width;
  *right+=width;
  *top-=height;
  *bottom+=height;
  return *left<=*right && *top<=*bottom;
}

Bool DCClipLine(CDC *dc=gr.dc,I64 *x1,I64 *y1,I64 *x2,I64 *y2,
        I64 width=0,I64 height=0)
{//Also converts window to scrn coordinates
  I64 left,top,right,bottom;
  CTask *win_task;
  if (GrClamp(dc,&left,&top,&right,&bottom,width,height)) {
    if (dc->flags & DCF_SCRN_BITMAP) {
      win_task=dc->win_task;
      *x1+=win_task->pix_left+win_task->scroll_x;
      *y1+=win_task->pix_top+win_task->scroll_y;
      *x2+=win_task->pix_left+win_task->scroll_x;
      *y2+=win_task->pix_top+win_task->scroll_y;
    }
    return ClipLine(x1,y1,x2,y2,left,top,right,bottom);
  } else
    return FALSE;
}

public Bool GrPlot(CDC *dc=gr.dc,I64 x,I64 y)
{//2D. Clipping but No transformation or thick.
  I32 *db=dc->depth_buf;
  CTask *win_task;
  CColorROPU32 old_color;
  dc->depth_buf=NULL;
  if (dc->brush) {
    old_color=dc->color;
    if (dc->color.c0.rop!=ROPB_COLLISION)
      dc->color.c0.rop=ROPB_MONO;
    GrBlot(dc,x,y,dc->brush);
    dc->color=old_color;
  } else if (dc->flags & DCF_SCRN_BITMAP) {
    win_task=dc->win_task;
    x+=win_task->pix_left+win_task->scroll_x;
    y+=win_task->pix_top+win_task->scroll_y;
    if (win_task->pix_left<=x<=win_task->pix_right &&
          win_task->pix_top<=y<=win_task->pix_bottom &&
          0<=x<dc->width && 0<=y<dc->height &&
          (win_task->next_task==sys_winmgr_task ||
          dc->flags&DCF_ON_TOP ||
          !IsPixCovered0(win_task,x,y)))
      GrPlot0(dc,x,y);
  } else
    if (0<=x<dc->width && 0<=y<dc->height)
      GrPlot0(dc,x,y);
  dc->depth_buf=db;
  return TRUE;
}

Bool GrPlot1(CDC *dc=gr.dc,I64 x,I64 y)
{//Clipping but No transformation or thick, called with db_z set
  CTask *win_task;
  CColorROPU32 old_color;
  if (dc->brush) {
    old_color=dc->color;
    if (dc->color.c0.rop!=ROPB_COLLISION)
      dc->color.c0.rop=ROPB_MONO;
    if (dc->depth_buf)
      GrBlot3(dc,x,y,dc->db_z,dc->brush);
    else
      GrBlot(dc,x,y,dc->brush);
    dc->color=old_color;
  } else if (dc->flags & DCF_SCRN_BITMAP) {
    win_task=dc->win_task;
    x+=win_task->pix_left+win_task->scroll_x;
    y+=win_task->pix_top+win_task->scroll_y;
    if (win_task->pix_left<=x<=win_task->pix_right &&
          win_task->pix_top <=y<=win_task->pix_bottom &&
          0<=x<dc->width && 0<=y<dc->height &&
          (win_task->next_task==sys_winmgr_task ||
          dc->flags&DCF_ON_TOP ||
          !IsPixCovered0(win_task,x,y)))
      GrPlot0(dc,x,y);
  } else
    if (0<=x<dc->width && 0<=y<dc->height)
      GrPlot0(dc,x,y);
  return TRUE;
}

public I64 GrPeek(CDC *dc=gr.dc,I64 x,I64 y)
{//2D. Clipping but no transformation.
//Returns pix color or -1 if off-scrn or covered.
  CTask *win_task;
  if (dc->flags & DCF_SCRN_BITMAP) {
    win_task=dc->win_task;
    x+=win_task->pix_left+win_task->scroll_x;
    y+=win_task->pix_top+win_task->scroll_y;
    if (!(win_task->pix_left<=x<=win_task->pix_right)  ||
          !(win_task->pix_top <=y<=win_task->pix_bottom) ||
          !(0<=x<dc->width) || !(0<=y<dc->height) ||
          win_task->next_task!=sys_winmgr_task &&
          !(dc->flags&DCF_ON_TOP) &&
          IsPixCovered0(win_task,x,y))
      return -1;
  } else
    if (!(0<=x<dc->width) || !(0<=y<dc->height))
      return -1;
  return GrPeek0(dc,x,y);
}

/*

This is an easier to understand
version of the nonrecursive routine below.
I64 GrFloodFillRay(CDC *dc,I64 x,I64 y,I64 z,I32 *db)
{
  I64 res,j,x1,ray_len,ray_len2;

  if (UnusedStk<0x80)
    Panic("Stk Overflow",Fs);

  res=ray_len=GrRayLen(dc,&x,y,z,db);
  y--;
  j=ray_len;
  x1=x;
  while (j>0) {
    if (ray_len2=GrRayLenMinus(dc,x1,y))
      res+=GrFloodFillRay(dc,x1,y,z,db);
    j-=ray_len2+1;
    x1-=ray_len2+1;
  }
  y+=2;
  j=ray_len;
  x1=x;
  while (j>0) {
    if (ray_len2=GrRayLenMinus(dc,x1,y))
      res+=GrFloodFillRay(dc,x1,y,z,db);
    j-=ray_len2+1;
    x1-=ray_len2+1;
  }
  return res;
}
*/

class CFFRay
{
  I64 state,x,y,j,x1,ray_len,ray_len2;
};

I64 GrFloodFillRay(CDC *dc,I64 x,I64 y,I64 z,I32 *db)
{//See the above commented-out routine for an easier to understand version.
//Returns cnt of pixs changed
  I64 res=0;
//We don't dynamically calculate the size to avoid
  //fragmentation of memory.
  CFFRay *f_dc=MAlloc(sizeof(CFFRay)*0x80000),*f=f_dc;
  f->x=x;
  f->y=y;
  f->state=0;
  do {
    switch [f->state] {
      case 0:
        f->state++;
        res+=f->ray_len=GrRayLen(dc,&f->x,f->y,z,db);
        f->y--;
        f->j=f->ray_len;
        f->x1=f->x;
        break;
      case 1:
        if (f->j>0) {
          f->state++;
          if (f->ray_len2=GrRayLenMinus(dc,f->x1,f->y)) {
            f[1].x=f->x1;
            f[1].y=f->y;
            f[1].state=0;
            f++;
          }
        } else
          f->state+=2;
        break;
      case 2:
        f->state--;
        f->j-=f->ray_len2+1;
        f->x1-=f->ray_len2+1;
        break;
      case 3:
        f->state++;
        f->y+=2;
        f->j=f->ray_len;
        f->x1=f->x;
        break;
      case 4:
        if (f->j>0) {
          f->state++;
          if (f->ray_len2=GrRayLenMinus(dc,f->x1,f->y)) {
            f[1].x=f->x1;
            f[1].y=f->y;
            f[1].state=0;
            f++;
          }
        } else
          f->state+=2;
        bre


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

//5 has graphics

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

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

F64 t0=Beat;

U0 DrawIt(CTask *,CDC *dc)
{
  F64 theta,dt=Beat-t0;
  if (dt>12) dt=12;
  theta=0.2*FullTri(dt,4);
  Sprite3ZB(dc,140+30*Sin(dt),40,0,<1>,theta);
  Sprite3(dc,170,15,0,<2>);
}

U0 Song()
{
  CTask *task;
  Fs->task_end_cb=&SndTaskEndCB;
  Fs->draw_it=&DrawIt;
  MusicSettingsRst;
  music.tempo= 2.500;
  music.stacatto_factor= 0.900;
  try {
    task=PopUpViewPrint("Revelation,22:18\n");
    TaskWait(task);
    WinHorz(Fs->win_left,TEXT_COLS-10,task);
    WinVert(Fs->win_bottom+3,Fs->win_bottom+15,task);
    "$WW+H,1$";
    while (!ScanKey) {
      t0=Beat;
      Play("4qB5RE4sG5C4G5CeCFqEeG4AsRGRG",
            "The \0 \0quill\n\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0");
      Play("4qB5RE4sG5C4G5CeCFqEeG4AsRGRG",
            "is \0 \0still\n\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0");
      Play("5qE4RetA5CGqF4G5etD4G5F4B5F4G5DRF",
            " \0 \0God's \0 \0 \0word \0for \0all \0 \0"
            "his \0 \0hap\0 \0py \0 \0peo\0");
      Play("5qE4RetA5CGqF4G5etD4G5F4B5F4G5DRF",
            "ple.\n\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0");
      "$GREEN$Gutenberg invented the printing"
            " press and made Bibles.  Until then, "
            "I wonder how many man-hours for one word in the Bible!\n$FG$";
    }
  } 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\gutenberg-Sup1-Sup1Hymns-Home.html
// Date: unknown-date
// Language: HolyC

//5 has graphics

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

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

F64 t0=Beat;

U0 DrawIt(CTask *,CDC *dc)
{
  F64 theta,dt=Beat-t0;
  if (dt>12) dt=12;
  theta=0.2*FullTri(dt,4);
  Sprite3ZB(dc,140+30*Sin(dt),40,0,<1>,theta);
  Sprite3(dc,170,15,0,<2>);
}

U0 Song()
{
  CTask *task;
  Fs->task_end_cb=&SndTaskEndCB;
  Fs->draw_it=&DrawIt;
  MusicSettingsRst;
  music.tempo= 2.500;
  music.stacatto_factor= 0.900;
  try {
    task=PopUpViewPrint("Revelation,22:18\n");
    TaskWait(task);
    WinHorz(Fs->win_left,TEXT_COLS-10,task);
    WinVert(Fs->win_bottom+3,Fs->win_bottom+15,task);
    "$WW+H,1$";
    while (!ScanKey) {
      t0=Beat;
      Play("4qB5RE4sG5C4G5CeCFqEeG4AsRGRG",
            "The \0 \0quill\n\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0");
      Play("4qB5RE4sG5C4G5CeCFqEeG4AsRGRG",
            "is \0 \0still\n\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0");
      Play("5qE4RetA5CGqF4G5etD4G5F4B5F4G5DRF",
            " \0 \0God's \0 \0 \0word \0for \0all \0 \0"
            "his \0 \0hap\0 \0py \0 \0peo\0");
      Play("5qE4RetA5CGqF4G5etD4G5F4B5F4G5DRF",
            "ple.\n\0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0 \0");
      "$GREEN$Gutenberg invented the printing"
            " press and made Bibles.  Until then, "
            "I wonder how many man-hours for one word in the Bible!\n$FG$";
    }
  } catch
    PutExcept;
  Snd;
}

Song;


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

RegDft("MyCompany/MyApp","F64 best_score=9999;\n");
RegExe("MyCompany/MyApp");

U0 Main()
{
  GetChar;
  RegWrite("MyCompany/MyApp","F64 best_score=%5.4f;\n",best_score);
}

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

RegDft("MyCompany/MyApp","F64 best_score=9999;\n");
RegExe("MyCompany/MyApp");

U0 Main()
{
  GetChar;
  RegWrite("MyCompany/MyApp","F64 best_score=%5.4f;\n",best_score);
}

Main;


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

#define MODULE_SIZE             2*BLK_SIZE
#define BOOT_HIGH_LOC_MHD2      ((BOOT_RAM_LIMIT-\
                                (BOOT_STK_SIZE+MODULE_SIZE))>>4)

DefinePrint(
  "DD_BOOT_HIGH_LOC_MHD2","%08X",BOOT_HIGH_LOC_MHD2<<4);

asm {
USE16
BMHD2_START::
        MOV     U32 FS:[0],'B'+0x2000+('2'+0x2000)<<16

        MOV     AX,BOOT_HIGH_LOC_MHD2
        MOV     ES,AX
//This copies this bootloader's code to 0x00096A00
        MOV     AX,CS
        MOV     DS,AX
        MOV     U32 [BMHD2_OLD_CS_RIP-BMHD2_START],EBX
        MOV     U8 [BMHD2_BIOS_DRV_NUM-BMHD2_START],DL

        MOV     CX,MODULE_SIZE
        XOR     SI,SI
        XOR     DI,DI
        REP_MOVSB

        MOV     AX,BOOT_HIGH_LOC_MHD2
        MOV     DS,AX

//My assembler doesn't support 16-bit very well.
        DU8     0xEA;   //JMP BOOT_HIGH_LOC_MHD2:BMHD2_HISTART
        DU16    BMHD2_HISTART-BMHD2_START,BOOT_HIGH_LOC_MHD2;

BMHD2_BOOT_MSG::
        DU8     256 DUP(0);

BMHD2_BIOS_DRV_NUM:     DU8     0;
BMHD2_PAGE:             DU8     0;
BMHD2_BLK_ARRAY::       DU64 8 DUP(0);

BMHD2_DAP:              DU8     16,0,1,0; //One blk at a time
BMHD2_DAP_BUF:          DU16    0,0;
BMHD2_DAP_BLK:: //64-bit
BMHD2_DAP_BLK_LO:       DU32    0;
BMHD2_DAP_BLK_HI:       DU32    0;

BMHD2_PUT_CHAR::
        MOV     AH,0xE
        MOV     BL,7 //Might be foreground color on some BIOS's
        MOV     BH,U8 [BMHD2_PAGE-BMHD2_START]
        INT     0x10
BMHD2_RET::
        RET
BMHD2_PUTS::
@@1:    LODSB
        TEST    AL,AL
        JZ      BMHD2_RET
        CALL    BMHD2_PUT_CHAR
        JMP     @@1

BMHD2_GETCHAR:
        XOR     AH,AH
        INT     0x16
        PUSH    AX
        MOV     AH,0x0E
        MOV     BX,0x07
        INT     0x10
        POP     AX
        RET

BMHD2_HISTART:
        MOV     AH,0xF
        INT     0x10
        MOV     U8 [BMHD2_PAGE-BMHD2_START],BH //Video page

        MOV     U32 FS:[0],0
@@5:    MOV     SI,BMHD2_BOOT_MSG-BMHD2_START
        CALL    BMHD2_PUTS
        CALL    BMHD2_GETCHAR
        CMP     AL,'0'
        JB      @@5
        CMP     AL,'8'
        JAE     @@5
        AND     EAX,7

        MOV     EBX,U32 BMHD2_BLK_ARRAY-BMHD2_START[EAX*8]
        MOV     EAX,U32 BMHD2_BLK_ARRAY+4-BMHD2_START[EAX*8]

        TEST    EBX,EBX
        JNZ     @@10
        TEST    EAX,EAX
        JZ      @@5

@@10:   MOV     U32 [BMHD2_DAP_BLK_LO-BMHD2_START],EBX
        MOV     U32 [BMHD2_DAP_BLK_HI-BMHD2_START],EAX

        MOV     AX,U16 [BMHD2_OLD_CS_RIP-BMHD2_START]
        SHR     AX,4
        ADD     AX,U16 [BMHD2_OLD_CS_RIP+2-BMHD2_START]
        MOV     U16 [BMHD2_DAP_BUF+2-BMHD2_START],AX //ES:0000
        MOV     SI,BMHD2_DAP-BMHD2_START //DS:SI=DAP
        MOV     DL,U8 [BMHD2_BIOS_DRV_NUM-BMHD2_START]
        MOV     AH,0x42
        INT     0x13

        POP     EBP
        POP     EDX
        POP     EBX
        POP     ECX
        XOR     EAX,EAX
        POP     GS
        POP     FS
        POP     ES
        POP     DS
        POPFW

//My assembler doesn't support 16-bit very well.
        DU8     0xEA;   //JMP xxxx:yyyy
BMHD2_OLD_CS_RIP:
        DU16    0,0;
BMHD2_END::
//Continues here ::/Adam/Opt/Boot/BootHD.HC
#assert BMHD2_END-BMHD2_START<MODULE_SIZE
}

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

#define MODULE_SIZE             2*BLK_SIZE
#define BOOT_HIGH_LOC_MHD2      ((BOOT_RAM_LIMIT-\
                                (BOOT_STK_SIZE+MODULE_SIZE))>>4)

DefinePrint(
  "DD_BOOT_HIGH_LOC_MHD2","%08X",BOOT_HIGH_LOC_MHD2<<4);

asm {
USE16
BMHD2_START::
        MOV     U32 FS:[0],'B'+0x2000+('2'+0x2000)<<16

        MOV     AX,BOOT_HIGH_LOC_MHD2
        MOV     ES,AX
//This copies this bootloader's code to 0x00096A00
        MOV     AX,CS
        MOV     DS,AX
        MOV     U32 [BMHD2_OLD_CS_RIP-BMHD2_START],EBX
        MOV     U8 [BMHD2_BIOS_DRV_NUM-BMHD2_START],DL

        MOV     CX,MODULE_SIZE
        XOR     SI,SI
        XOR     DI,DI
        REP_MOVSB

        MOV     AX,BOOT_HIGH_LOC_MHD2
        MOV     DS,AX

//My assembler doesn't support 16-bit very well.
        DU8     0xEA;   //JMP BOOT_HIGH_LOC_MHD2:BMHD2_HISTART
        DU16    BMHD2_HISTART-BMHD2_START,BOOT_HIGH_LOC_MHD2;

BMHD2_BOOT_MSG::
        DU8     256 DUP(0);

BMHD2_BIOS_DRV_NUM:     DU8     0;
BMHD2_PAGE:             DU8     0;
BMHD2_BLK_ARRAY::       DU64 8 DUP(0);

BMHD2_DAP:              DU8     16,0,1,0; //One blk at a time
BMHD2_DAP_BUF:          DU16    0,0;
BMHD2_DAP_BLK:: //64-bit
BMHD2_DAP_BLK_LO:       DU32    0;
BMHD2_DAP_BLK_HI:       DU32    0;

BMHD2_PUT_CHAR::
        MOV     AH,0xE
        MOV     BL,7 //Might be foreground color on some BIOS's
        MOV     BH,U8 [BMHD2_PAGE-BMHD2_START]
        INT     0x10
BMHD2_RET::
        RET
BMHD2_PUTS::
@@1:    LODSB
        TEST    AL,AL
        JZ      BMHD2_RET
        CALL    BMHD2_PUT_CHAR
        JMP     @@1

BMHD2_GETCHAR:
        XOR     AH,AH
        INT     0x16
        PUSH    AX
        MOV     AH,0x0E
        MOV     BX,0x07
        INT     0x10
        POP     AX
        RET

BMHD2_HISTART:
        MOV     AH,0xF
        INT     0x10
        MOV     U8 [BMHD2_PAGE-BMHD2_START],BH //Video page

        MOV     U32 FS:[0],0
@@5:    MOV     SI,BMHD2_BOOT_MSG-BMHD2_START
        CALL    BMHD2_PUTS
        CALL    BMHD2_GETCHAR
        CMP     AL,'0'
        JB      @@5
        CMP     AL,'8'
        JAE     @@5
        AND     EAX,7

        MOV     EBX,U32 BMHD2_BLK_ARRAY-BMHD2_START[EAX*8]
        MOV     EAX,U32 BMHD2_BLK_ARRAY+4-BMHD2_START[EAX*8]

        TEST    EBX,EBX
        JNZ     @@10
        TEST    EAX,EAX
        JZ      @@5

@@10:   MOV     U32 [BMHD2_DAP_BLK_LO-BMHD2_START],EBX
        MOV     U32 [BMHD2_DAP_BLK_HI-BMHD2_START],EAX

        MOV     AX,U16 [BMHD2_OLD_CS_RIP-BMHD2_START]
        SHR     AX,4
        ADD     AX,U16 [BMHD2_OLD_CS_RIP+2-BMHD2_START]
        MOV     U16 [BMHD2_DAP_BUF+2-BMHD2_START],AX //ES:0000
        MOV     SI,BMHD2_DAP-BMHD2_START //DS:SI=DAP
        MOV     DL,U8 [BMHD2_BIOS_DRV_NUM-BMHD2_START]
        MOV     AH,0x42
        INT     0x13

        POP     EBP
        POP     EDX
        POP     EBX
        POP     ECX
        XOR     EAX,EAX
        POP     GS
        POP     FS
        POP     ES
        POP     DS
        POPFW

//My assembler doesn't support 16-bit very well.
        DU8     0xEA;   //JMP xxxx:yyyy
BMHD2_OLD_CS_RIP:
        DU16    0,0;
BMHD2_END::
//Continues here ::/Adam/Opt/Boot/BootHD.HC
#assert BMHD2_END-BMHD2_START<MODULE_SIZE
}