Team Ai
Datasetpublic

hschumann2/TempleOS-Source-Code

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes847downloads
GrScrn.txt425 linesDownload Raw Back to Gr
1 2#help_index "Graphics/Scrn"3 4U0 GrUpdateTaskODEs(CTask *task)5{6  sys_task_being_scrn_updated=task;7  try8    ODEsUpdate(task);9  catch {10    LBts(&task->win_inhibit,WIf_SELF_ODE);11    "Exception in WinMgr: Update Task ODEs\n";12    PutExcept;13    Sleep(3000);14    VGAFlush;15  }16  sys_task_being_scrn_updated=NULL;17}18 19U0 GrUpdateTaskWin(CTask *task)20{ //Draw a win.  Only Core0 tasks have a win.21  CDC *dc;22  CD3I64 saved_scroll;23  sys_task_being_scrn_updated=task;24  try {25    if (!Bt(&task->display_flags,DISPLAYf_NO_BORDER))26      TextBorder(Fs,task->win_left,task->win_right,task->win_top,27            task->win_bottom,task->border_attr,task==sys_focus_task);28    TextRect(task->win_left,task->win_right,29          task->win_top,task->win_bottom,task->text_attr<<8);30    if (task==sys_winmgr_task) {31      if (gr.fp_wall_paper)32        (*gr.fp_wall_paper)(task);33    } else if (!(task->win_inhibit&WIF_SELF_DOC))34      DocUpdateTaskDocs(task);35    if (TaskValidate(task)) {36      if (task->draw_it) {37        dc=DCAlias(gr.dc2,task);38        (*task->draw_it)(task,dc);39        DCDel(dc);40      }41      if (TaskValidate(task)) {42        WinScrollNull(task,&saved_scroll);43        DrawCtrls(task);44        WinScrollRestore(task,&saved_scroll);45      }46    }47  } catch {48    if (task!=Fs && TaskValidate(task)) {49      LBtr(&task->display_flags,DISPLAYf_SHOW);50      "Exception in WinMgr: Update Task Win\n";51      PutExcept;52      Sleep(3000);53      VGAFlush;54    }55  }56  sys_task_being_scrn_updated=NULL;57}58 59U0 GrUpdateTasks()60{//Only called by WinMgr61  I64 i;62  CTask *task,*task1;63  try {64    winmgr.ode_time=0;65    if (Bt(&sys_semas[SEMA_UPDATE_WIN_Z_BUF],0))66      WinZBufUpdate;67    task1=task=sys_winmgr_task;68    do { //Loop through Core0 tasks.69      if (!TaskValidate(task)) break;70      if (Bt(&task->display_flags,DISPLAYf_SHOW) &&71            Bt(gr.win_uncovered_bitmap,task->win_z_num))72        GrUpdateTaskWin(task);73      if (!TaskValidate(task)) break;74      task=task->next_task;75    } while (task!=task1);76 77    for (i=0;i<mp_cnt;i++) { //Loop through all cores.78      task1=task=cpu_structs[i].seth_task;79      do {80        if (!TaskValidate(task)) break;81        GrUpdateTaskODEs(task);82        if (!TaskValidate(task)) break;83        task=task->next_task;84      } while (task!=task1);85    }86  } catch {87    PutExcept(FALSE);88    Dbg("Exception in WinMgr");89  }90  winmgr.last_ode_time=winmgr.ode_time;91  ode_alloced_factor=LowPass1(0.1,ode_alloced_factor,92        Clamp(Gs->idle_factor-0.1,0.2,0.8),1/winmgr.fps);93  sys_task_being_scrn_updated=NULL;94}95 96U0 GrFixZoomScale()97{98  gr.scrn_zoom=ClampI64(gr.scrn_zoom,1,GR_SCRN_ZOOM_MAX);99  if (gr.scrn_zoom==1) {100    gr.sx=0;101    gr.sy=0;102  } else {103    gr.sx=ClampI64(gr.sx,0,GR_WIDTH-GR_WIDTH/gr.scrn_zoom)&~7;104    gr.sy=ClampI64(gr.sy,0,GR_HEIGHT-GR_HEIGHT/gr.scrn_zoom);105  }106}107 108public U0 GrScaleZoom(F64 scale)109{//Multiply zoom factor larger or smaller.110  F64 s=gr.scrn_zoom;111  gr.scrn_zoom=gr.scrn_zoom*scale;112  GrFixZoomScale;113  s/=gr.scrn_zoom;114  ms.scale.x*=s;115  ms.scale.y*=s;116  ms.scale.z*=s;117  ms.offset.x=ms.pos.x-(ms.pos.x-ms.offset.x)*s;118  ms.offset.y=ms.pos.y-(ms.pos.y-ms.offset.y)*s;119  ms.offset.z=ms.pos.z-(ms.pos.z-ms.offset.z)*s;120  gr.sx=ms.pos.x-gr.zoomed_dc->width >>1/gr.scrn_zoom;121  gr.sy=ms.pos.y-gr.zoomed_dc->height>>1/gr.scrn_zoom;122  GrFixZoomScale;123}124 125U0 GrZoomInScrn()126{127  GrFixZoomScale;128  I64 plane,row,col,k,l,129        d2=gr.zoomed_dc->width>>3/gr.scrn_zoom,130        d4=gr.zoomed_dc->width_internal>>3,131        d5=d4-d2*gr.scrn_zoom,132        d3=gr.zoomed_dc->height/gr.scrn_zoom,133        d6=(gr.zoomed_dc->height-d3)*gr.dc1->width_internal>>3,134        d7=gr.zoomed_dc->height%gr.scrn_zoom*d4;135  U8 *src,*src2,*dst,*src3,*map=gr.scrn_zoom_tables[gr.scrn_zoom];136 137  src=gr.dc1->body+gr.sx>>3+gr.sy*gr.dc1->width_internal>>3;138  dst=gr.zoomed_dc->body;139  for (plane=1;plane<0x10;plane<<=1) {140    row=d3;141    while (row--) {142      k=gr.scrn_zoom;143      while (k--) {144        src2=src;145        col=d2;146        while (col--) {147          src3=&map[*src2++];148          l=gr.scrn_zoom;149          while (l--) {150            *dst++=*src3;151            src3+=256;152          }153        }154        l=d5;155        while (l--)156          *dst++=0;157      }158      src+=d4;159    }160    l=d7;161    while (l--)162      *dst++=0;163    src+=d6;164  }165}166 167U0 GrUpdateTextBG()168{169  I64 reg RSI *dst=gr.dc2->body,reg R13 c,row,col,170        num_rows=TEXT_ROWS,num_cols=TEXT_COLS,i,j,cur_ch,171        reg R12 w1=gr.dc2->width_internal,w2=-7*w1+8,w3=7*w1,w4=0;172  U32 *src=gr.text_base;173  Bool blink_flag=Blink;174  U8 *dst2=dst;175 176  if (gr.pan_text_x||gr.hide_col) {177    gr.pan_text_x=ClampI64(gr.pan_text_x,-7,7);178    j=AbsI64(gr.pan_text_x)/FONT_WIDTH+1;179    num_cols-=j;180    if (gr.pan_text_x<0) {181      src+=j;182      i=FONT_WIDTH*j+gr.pan_text_x;183    } else184      i=gr.pan_text_x;185    dst2=dst(U8 *)+i;186    w4=j;187    w3+=j*FONT_WIDTH;188 189    j*=FONT_WIDTH;190    dst(U8 *)=gr.dc2->body;191    for (row=num_rows*FONT_HEIGHT;row--;) {192      for (col=i;col--;)193        *dst(U8 *)++=0;194      dst(U8 *)+=w1-i-j;195      for (col=j;col--;)196        *dst(U8 *)++=0;197    }198  }199  dst=dst2;200 201  if (gr.pan_text_y||gr.hide_row) {202    gr.pan_text_y=ClampI64(gr.pan_text_y,-7,7);203    j=AbsI64(gr.pan_text_y)/FONT_HEIGHT+1;204    num_rows-=j;205    if (gr.pan_text_y<0) {206      src+=w1/FONT_WIDTH*j;207      i=w1*(FONT_HEIGHT*j+gr.pan_text_y);208    } else209      i=w1*gr.pan_text_y;210    dst2=dst(U8 *)+i;211 212    j*=w1*FONT_HEIGHT;213    dst(U8 *)=gr.dc2->body;214    for (row=i;row--;)215      *dst(U8 *)++=0;216    dst(U8 *)=gr.dc2->body+TEXT_ROWS*TEXT_COLS*FONT_HEIGHT*FONT_WIDTH-j;217    for (row=j;row--;)218      *dst(U8 *)++=0;219  }220  dst=dst2;221 222  for (row=num_rows;row--;) {223    for (col=num_cols;col--;) {224      cur_ch=*src++;225      if (cur_ch & (ATTRF_SEL|ATTRF_INVERT|ATTRF_BLINK)) {226        if (cur_ch & ATTRF_SEL)227          cur_ch.u8[1]=cur_ch.u8[1]^0xFF;228        if (cur_ch & ATTRF_INVERT)229          cur_ch.u8[1]=cur_ch.u8[1]<<4+cur_ch.u8[1]>>4;230        if (cur_ch & ATTRF_BLINK && blink_flag)231          cur_ch.u8[1]=cur_ch.u8[1]<<4+cur_ch.u8[1]>>4;232      }233      c=gr.to_8_colors[cur_ch.u8[1]>>4];234      MOV       U64 [RSI],R13235      ADD       RSI,R12236      MOV       U64 [RSI],R13237      ADD       RSI,R12238      MOV       U64 [RSI],R13239      ADD       RSI,R12240      MOV       U64 [RSI],R13241      ADD       RSI,R12242      MOV       U64 [RSI],R13243      ADD       RSI,R12244      MOV       U64 [RSI],R13245      ADD       RSI,R12246      MOV       U64 [RSI],R13247      ADD       RSI,R12248      MOV       U64 [RSI],R13249      dst(U8 *)+=w2;250    }251    src+=w4;252    dst(U8 *)+=w3;253  }254}255 256U0 GrUpdateTextFG()257{//See TextBase Layer.258  U32 *src=gr.text_base;259  I64 i,j,cur_ch,*dst=gr.dc2->body,260        w1=gr.dc2->width_internal,w2=7*w1,w4=0,261        num_rows=TEXT_ROWS,num_cols=TEXT_COLS,row,col;262  U8 *dst_start=gr.dc2->body,*dst_end=dst_start+w1*gr.dc2->height-7*w1-8;263  Bool blink_flag=Blink;264 265  if (gr.pan_text_x||gr.hide_col) {266    gr.pan_text_x=ClampI64(gr.pan_text_x,-7,7);267    j=AbsI64(gr.pan_text_x)/FONT_WIDTH+1;268    num_cols-=j;269    if (gr.pan_text_x<0) {270      src+=j;271      dst(U8 *)+=FONT_WIDTH*j;272    }273    w4=j;274    w2+=j*FONT_WIDTH;275  }276 277  if (gr.pan_text_y||gr.hide_row) {278    gr.pan_text_y=ClampI64(gr.pan_text_y,-7,7);279    j=AbsI64(gr.pan_text_y)/FONT_HEIGHT+1;280    num_rows-=j;281    if (gr.pan_text_y<0) {282      src+=w1/FONT_WIDTH*j;283      dst(U8 *)+=w1*FONT_HEIGHT*j;284    }285  }286 287  for (row=num_rows;row--;) {288    for (col=num_cols;col--;) {289      cur_ch=*src++;290      if (cur_ch & (ATTRF_UNDERLINE|ATTRF_SEL|ATTRF_INVERT|ATTRF_BLINK)) {291        if (cur_ch & ATTRF_SEL)292          cur_ch.u8[1]=cur_ch.u8[1]^0xFF;293        if (cur_ch & ATTRF_INVERT)294          cur_ch.u8[1]=cur_ch.u8[1]<<4+cur_ch.u8[1]>>4;295        if (cur_ch & ATTRF_BLINK && blink_flag)296          cur_ch.u8[1]=cur_ch.u8[1]<<4+cur_ch.u8[1]>>4;297      }298      if (i=cur_ch.u16[1]&0x3FF+gr.pan_text_x+gr.pan_text_y<<5) {299        j=i&0x1F;300        if (j&0x10) j|=~0x1F;301        i>>=5;302        if (i&0x10) i|=~0x1F;303        i=w1*i+j;304        if (dst_start<=dst(U8 *)+i<dst_end)305          GrRopEquU8NoClipping(cur_ch&(ATTRF_UNDERLINE+0xFFF),dst(U8 *)+i,w1);306      } else307        GrRopEquU8NoClipping(cur_ch&(ATTRF_UNDERLINE+0xFFF),dst,w1);308      dst(U8 *)+=8;309    }310    src+=w4;311    dst(U8 *)+=w2;312  }313}314 315U0 DCBlotColor8(CDC *dc,CDC *img)316{317  U8  *src=img->body,*b0=dc->body;318  I64 j,k,d0=img->width_internal*img->height;319  for (k=0;k<d0;k++) {320    j=*src++;321    if (j!=TRANSPARENT)322      *b0++=j;323    else324      b0++;325  }326}327 328U0 GrUpdateTextModeText()329{330  U32 *src=gr.text_base;331  I64 cur_ch,i=TEXT_COLS*TEXT_ROWS;332  U16 *dst=text.vga_text_alias,*dst2=gr.vga_text_cache;333  Bool blink_flag=Blink;334  if (LBtr(&sys_semas[SEMA_FLUSH_VGA_IMAGE],0)) {335    while (i--) {336      cur_ch=*src++;337      if (cur_ch & ATTRF_SEL)338        cur_ch.u8[1]=cur_ch.u8[1]^0xFF;339      if (cur_ch & ATTRF_INVERT)340        cur_ch.u8[1]=cur_ch.u8[1]<<4+cur_ch.u8[1]>>4;341      if (cur_ch & ATTRF_BLINK)342        if (blink_flag)343          cur_ch.u8[1]=cur_ch.u8[1]<<4+cur_ch.u8[1]>>4;344      *dst++=*dst2++=cur_ch&0x7FFF;345    }346  } else {347    while (i--) {348      cur_ch=*src++;349      if (cur_ch & ATTRF_SEL)350        cur_ch.u8[1]=cur_ch.u8[1]^0xFF;351      if (cur_ch & ATTRF_INVERT)352        cur_ch.u8[1]=cur_ch.u8[1]<<4+cur_ch.u8[1]>>4;353      if (cur_ch & ATTRF_BLINK)354        if (blink_flag)355          cur_ch.u8[1]=cur_ch.u8[1]<<4+cur_ch.u8[1]>>4;356      cur_ch&=0x7FFF;357      if (*dst2!=cur_ch)358        *dst++=*dst2++=cur_ch;359      else {360        dst++;361        dst2++;362      }363    }364  }365}366 367U0 GrUpdateVGAGraphics()368{//Update Graphic Card369  I64 row,plane,d=gr.zoomed_dc->width_internal>>6;370  U32 *src,*vga,*dst;371  if (gr.scrn_zoom==1)372    src=gr.dc1->body;373  else {374    GrZoomInScrn;375    src=gr.zoomed_dc->body;376  }377  dst=gr.scrn_image->body;378  if (LBtr(&sys_semas[SEMA_FLUSH_VGA_IMAGE],0)) {379    for (plane=1;plane<0x10;plane<<=1) {380      OutU8(VGAP_IDX,VGAR_MAP_MASK);381      OutU8(VGAP_DATA,plane);382      vga=text.vga_alias;383      row=gr.zoomed_dc->height;384      while (row--)385        GrUpdateLine64FlushCache(&vga,&src,d,&dst);386    }387  } else {388    for (plane=1;plane<0x10;plane<<=1) {389      OutU8(VGAP_IDX,VGAR_MAP_MASK);390      OutU8(VGAP_DATA,plane);391      vga=text.vga_alias;392      row=gr.zoomed_dc->height;393      while (row--)394        GrUpdateLine64(&vga,&src,d,&dst);395    }396  }397}398 399U0 GrUpdateScrn()400{//Called by the Window Manager HERE, 30 times a second.401  CDC *dc;402  if (!Bt(&sys_run_level,RLf_VGA)) //if text mode403    GrUpdateTasks;404  else {405    GrUpdateTextBG;406    GrUpdateTextFG;407    GrUpdateTasks;408    DCBlotColor8(gr.dc2,gr.dc);409  }410 411  dc=DCAlias(gr.dc2,Fs);412  dc->flags|=DCF_ON_TOP;413  if (gr.fp_final_scrn_update)414    (*gr.fp_final_scrn_update)(dc);415  DCDel(dc);416 417  if (!Bt(&sys_run_level,RLf_VGA)) //if text mode418    GrUpdateTextModeText;419  else {420    DCBlotColor4(gr.dc1->body,gr.dc2->body,gr.dc_cache->body,421          gr.dc2->height*gr.dc2->width_internal>>3);422    GrUpdateVGAGraphics;423  }424}425