hschumann2/TempleOS-Source-Code
0838
1 2#help_index "Misc/TOS"3 4#define VIDEO_FRAME_RATE 29.975 6#define FG_JUST_AUDIO 07#define FG_BOOT_DRV 18#define FG_RAM_DRV 29I64 fg_mode=FG_RAM_DRV;10Bool fg_on =FALSE;11 12U0 FrameGrabberTask(I64)13{//#!/bin/bash14//for f in ./ScrnShots/*.Z; do ./Bin/TOSZ $f; done15 //ffmpeg -r 8 -i VID%05d.BMP -y Movie.avi16 I64 frame_num=0;17 U8 buf[STR_LEN],buf2[STR_LEN],*st_dir;18 F64 end_time=tS;19 Silent; //no output to scrn20 if (fg_mode==FG_RAM_DRV)21 st_dir="B:/Tmp/ScrnShots";22 else23 st_dir="::/Tmp/ScrnShots";24 DirMk(st_dir);25 while (fg_on) {26 StrPrint(buf,"%s/VID%05d.BMP.Z",st_dir,frame_num++);27 StrCpy(buf2,buf);28 BMPScrnCapture(buf);29 while (TRUE) {30 end_time+=1.0/VIDEO_FRAME_RATE;31 if (end_time<tS) {32 StrPrint(buf,"%s/VID%05d.BMP.Z",st_dir,frame_num++);33 Copy(buf2,buf);34 } else35 break;36 }37 SleepUntil(cnts.jiffies+(end_time-tS)*JIFFY_FREQ);38 }39}40 41I64 CopyVideo()42{43 I64 res=0;44 Del("D:/Tmp/*.SND");45 if (fg_mode==FG_JUST_AUDIO)46 SndFileCreate("D:/Tmp/Audio",0.115,0.0,WF_SQUARE,0.45,0.35,2.5);47 else {48 SndFileCreate("D:/Tmp/Audio",0.115,0.0,WF_SQUARE,0.45,0.35);49 DelTree("D:/Tmp/ScrnShots");50 if (fg_mode==FG_RAM_DRV) {51 res=CopyTree("B:/Tmp/ScrnShots","D:/Tmp/ScrnShots");52 "Unused Space: %12.6fMeg\n",DrvUnused('B')/1024.0/1024.0;53 } else54 res=CopyTree("::/Tmp/ScrnShots","D:/Tmp/ScrnShots");55 "$BK,1$Files Copied:%d$BK,0$ Time:%8.3fm\n",56 res,res/60.0/VIDEO_FRAME_RATE;57 }58 return res;59}60 61public U0 FrameGrabberToggle()62{//The frame grabber saves BMP files to D:/Tmp/ScrnShots.63 static F64 last_time=0;64 if (tS-last_time>3.0) {65 last_time=tS;66 if (fg_on) {67 fg_on=FALSE;68 Snd;69 wall->record=snd.record=FALSE;70 Sleep(1000);71 User("CopyVideo;Exit;\n");72 } else {73 fg_on=TRUE;74 if (fg_mode!=FG_JUST_AUDIO)75 Spawn(&FrameGrabberTask,NULL,"Frame Grabber");76 wall->record=snd.record=TRUE;77 Snd;78 }79 }80}81 82public U0 JukeSong(I64 num,I64 passes=2)83{//Make movie of one song.84 if (!fg_on)85 FrameGrabberToggle;86 JukeSongsPuppet("~/Sup1/Sup1Hymns",passes,num,num+1);87 if (fg_on)88 FrameGrabberToggle;89}90 91public U0 JukeLines(I64 start_line,I64 end_line)92{//Make movie of many lines of songs.93 if (!fg_on)94 FrameGrabberToggle;95 JukeSongsPuppet("~/Sup1/Sup1Hymns",,start_line*5,end_line*5);96 if (fg_on)97 FrameGrabberToggle;98}99 100public U0 DskChkAll()101{//DskChk on C & D.102 U8 *ptr=TOS_HDS;103 while (*ptr)104 DskChk(*ptr++);105}106 107public CDoc *DC2Doc(CDC *dc,I64 dx=0,I64 dy=0,I64 *_total_score=NULL)108{//Use OCR to make a text DolDoc from CDC.109 U8 byte_bit_cnts[256];110 I64 i,j,*ptr,row,col,ch,best_ch,score,best_score,111 cur_char_image,diff_image,total_score=0;112 CDoc *doc=DocNew;113 114 MemSet(byte_bit_cnts,0,sizeof(byte_bit_cnts));115 for (i=0;i<256;i++)116 for (j=0;j<7;j++)117 if (Bt(&i,j))118 byte_bit_cnts[i]++;119 120 for (row=0;row<dc->height/FONT_HEIGHT;row++) {121 for (col=0;col<dc->width/FONT_WIDTH;col++) {122 123 cur_char_image=0;124 for (i=0;i<FONT_HEIGHT;i++)125 for (j=0;j<FONT_WIDTH;j++)126 if (GrPeek(dc,col*FONT_WIDTH+j+dx,row*FONT_HEIGHT+i+dy)!=WHITE)127 LBts(&cur_char_image,i*8+j);128 129 best_score=I64_MAX;130 best_ch=0;131 ptr=&text.font[32];132 for (ch=32;ch<127;ch++) {133 diff_image=*ptr++ ^ cur_char_image;134 score=0;135 for (i=0;i<8;i++)136 score+=byte_bit_cnts[diff_image.u8[i]];137 if (score<best_score) {138 best_score=score;139 best_ch=ch;140 }141 }142 if (best_ch=='$')143 DocPrint(doc,"$$");144 else145 DocPrint(doc,"%c",best_ch);146 total_score+=best_score;147 }148 DocPrint(doc,"\n");149 }150 if (_total_score) *_total_score=total_score;151 return doc;152}153 154public U0 BMP2Doc(U8 *_in_name,U8 *_out_name=NULL)155{//Use OCR to make a text DolDoc from BMP file.156 U8 *in_name,*out_name;157 I64 dx,dy,score,best_score=I64_MAX;158 CDC *dc;159 CDoc *doc;160 in_name=ExtDft(_in_name,"BMP");161 if (_out_name)162 out_name=ExtDft(_out_name,"DD.Z");163 else164 out_name=ExtChg(_in_name,"DD.Z");165 if (dc=BMPRead(in_name)) {166 for (dy=-3;dy<=4;dy++)167 for (dx=-3;dx<=4;dx++) {168 doc=DC2Doc(dc,dx,dy,&score);169 if (score<best_score) {170 best_score=score;171 StrCpy(&doc->filename.name,out_name);172 DocWrite(doc);173 }174 DocDel(doc);175 }176 }177 Free(in_name);178 Free(out_name);179}180 181U0 TOSTheme()182{183 if (!fg_on)184 PopUp("Sleep(50);FrameGrabberToggle;");185 ExeFile("~/Sup1/Sup1Graphics/TOS/TOSTheme.HC");186 DocClear;187}188 189#define MEM_TEST_SIZE 1024*1024190U0 MemTest()191{192 U8 *b;193 while (sys_data_bp->alloced_u8s-sys_data_bp->used_u8s>0x1000000) {194 b=MAlloc(MEM_TEST_SIZE,Fs->data_heap);195 MemSet(b,0x88,MSize(b));196 "Data:%X\n",sys_data_bp->alloced_u8s-sys_data_bp->used_u8s;197 Yield;198 }199 while (sys_code_bp->alloced_u8s-sys_code_bp->used_u8s>0x1000000) {200 b=MAlloc(MEM_TEST_SIZE,Fs->code_heap);201 MemSet(b,0x88,MSize(b));202 "Code:%X\n",sys_code_bp->alloced_u8s-sys_code_bp->used_u8s;203 Yield;204 }205}206 207public I64 Profanity(208 U8 *needle_filename="~/Sup1/Sup1Blog/Profanity.DD.Z",209 U8 *files_find_mask="/*",U8 *fu_flags=NULL)210{//Scan for profanity.211 CCmpCtrl *cc;212 I64 res=0;213 if (FileFind(needle_filename)) {214 cc=CmpCtrlNew(MStrPrint("#include \"%s\"",needle_filename));215 while (Lex(cc))216 if (cc->token==TK_IDENT)217 res+=Find(cc->cur_str,files_find_mask,fu_flags);218 CmpCtrlDel(cc);219 }220 return res;221}222 223U0 TOSChgLog2()224{225 InStr("\"Ed(\\\"::/Doc/ChgLog.DD.Z\\\");\n\";226 Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_UP|SCF_CTRL);227 Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN);228 Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN);229 Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN);230 Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN);231 Msg(MSG_KEY_DOWN_UP,CH_CTRLY,0);232 Msg(MSG_KEY_DOWN_UP,0,SC_F6|SCF_ALT);233 Msg(MSG_KEY_DOWN_UP,CH_ESC,0);"234 "\"Exit;\n\";");235}236 237public U0 TOSChgLog()238{//Opdate ChgLog file.239 User("TOSChgLog2;\n");240}241 