File size: 6,035 Bytes
806d4b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241

#help_index "Misc/TOS"

#define VIDEO_FRAME_RATE        29.97

#define FG_JUST_AUDIO   0
#define FG_BOOT_DRV     1
#define FG_RAM_DRV      2
I64     fg_mode=FG_RAM_DRV;
Bool    fg_on =FALSE;

U0 FrameGrabberTask(I64)
{//#!/bin/bash
//for f in ./ScrnShots/*.Z; do ./Bin/TOSZ $f; done
  //ffmpeg -r 8 -i VID%05d.BMP -y Movie.avi
  I64 frame_num=0;
  U8  buf[STR_LEN],buf2[STR_LEN],*st_dir;
  F64 end_time=tS;
  Silent;       //no output to scrn
  if (fg_mode==FG_RAM_DRV)
    st_dir="B:/Tmp/ScrnShots";
  else
    st_dir="::/Tmp/ScrnShots";
  DirMk(st_dir);
  while (fg_on) {
    StrPrint(buf,"%s/VID%05d.BMP.Z",st_dir,frame_num++);
    StrCpy(buf2,buf);
    BMPScrnCapture(buf);
    while (TRUE) {
      end_time+=1.0/VIDEO_FRAME_RATE;
      if (end_time<tS) {
        StrPrint(buf,"%s/VID%05d.BMP.Z",st_dir,frame_num++);
        Copy(buf2,buf);
      } else
        break;
    }
    SleepUntil(cnts.jiffies+(end_time-tS)*JIFFY_FREQ);
  }
}

I64 CopyVideo()
{
  I64 res=0;
  Del("D:/Tmp/*.SND");
  if (fg_mode==FG_JUST_AUDIO)
    SndFileCreate("D:/Tmp/Audio",0.115,0.0,WF_SQUARE,0.45,0.35,2.5);
  else {
    SndFileCreate("D:/Tmp/Audio",0.115,0.0,WF_SQUARE,0.45,0.35);
    DelTree("D:/Tmp/ScrnShots");
    if (fg_mode==FG_RAM_DRV) {
      res=CopyTree("B:/Tmp/ScrnShots","D:/Tmp/ScrnShots");
      "Unused Space: %12.6fMeg\n",DrvUnused('B')/1024.0/1024.0;
    } else
      res=CopyTree("::/Tmp/ScrnShots","D:/Tmp/ScrnShots");
    "$BK,1$Files Copied:%d$BK,0$ Time:%8.3fm\n",
          res,res/60.0/VIDEO_FRAME_RATE;
  }
  return res;
}

public U0 FrameGrabberToggle()
{//The frame grabber saves BMP files to D:/Tmp/ScrnShots.
  static F64 last_time=0;
  if (tS-last_time>3.0) {
    last_time=tS;
    if (fg_on) {
      fg_on=FALSE;
      Snd;
      wall->record=snd.record=FALSE;
      Sleep(1000);
      User("CopyVideo;Exit;\n");
    } else {
      fg_on=TRUE;
      if (fg_mode!=FG_JUST_AUDIO)
        Spawn(&FrameGrabberTask,NULL,"Frame Grabber");
      wall->record=snd.record=TRUE;
      Snd;
    }
  }
}

public U0 JukeSong(I64 num,I64 passes=2)
{//Make movie of one song.
  if (!fg_on)
    FrameGrabberToggle;
  JukeSongsPuppet("~/Sup1/Sup1Hymns",passes,num,num+1);
  if (fg_on)
    FrameGrabberToggle;
}

public U0 JukeLines(I64 start_line,I64 end_line)
{//Make movie of many lines of songs.
  if (!fg_on)
    FrameGrabberToggle;
  JukeSongsPuppet("~/Sup1/Sup1Hymns",,start_line*5,end_line*5);
  if (fg_on)
    FrameGrabberToggle;
}

public U0 DskChkAll()
{//DskChk on C & D.
  U8 *ptr=TOS_HDS;
  while (*ptr)
    DskChk(*ptr++);
}

public CDoc *DC2Doc(CDC *dc,I64 dx=0,I64 dy=0,I64 *_total_score=NULL)
{//Use OCR to make a text DolDoc from CDC.
  U8 byte_bit_cnts[256];
  I64 i,j,*ptr,row,col,ch,best_ch,score,best_score,
        cur_char_image,diff_image,total_score=0;
  CDoc *doc=DocNew;

  MemSet(byte_bit_cnts,0,sizeof(byte_bit_cnts));
  for (i=0;i<256;i++)
    for (j=0;j<7;j++)
      if (Bt(&i,j))
        byte_bit_cnts[i]++;

  for (row=0;row<dc->height/FONT_HEIGHT;row++) {
    for (col=0;col<dc->width/FONT_WIDTH;col++) {

      cur_char_image=0;
      for (i=0;i<FONT_HEIGHT;i++)
        for (j=0;j<FONT_WIDTH;j++)
          if (GrPeek(dc,col*FONT_WIDTH+j+dx,row*FONT_HEIGHT+i+dy)!=WHITE)
            LBts(&cur_char_image,i*8+j);

      best_score=I64_MAX;
      best_ch=0;
      ptr=&text.font[32];
      for (ch=32;ch<127;ch++) {
        diff_image=*ptr++ ^ cur_char_image;
        score=0;
        for (i=0;i<8;i++)
          score+=byte_bit_cnts[diff_image.u8[i]];
        if (score<best_score) {
          best_score=score;
          best_ch=ch;
        }
      }
      if (best_ch=='$')
        DocPrint(doc,"$$");
      else
        DocPrint(doc,"%c",best_ch);
      total_score+=best_score;
    }
    DocPrint(doc,"\n");
  }
  if (_total_score) *_total_score=total_score;
  return doc;
}

public U0 BMP2Doc(U8 *_in_name,U8 *_out_name=NULL)
{//Use OCR to make a text DolDoc from BMP file.
  U8 *in_name,*out_name;
  I64 dx,dy,score,best_score=I64_MAX;
  CDC *dc;
  CDoc *doc;
  in_name=ExtDft(_in_name,"BMP");
  if (_out_name)
    out_name=ExtDft(_out_name,"DD.Z");
  else
    out_name=ExtChg(_in_name,"DD.Z");
  if (dc=BMPRead(in_name)) {
    for (dy=-3;dy<=4;dy++)
      for (dx=-3;dx<=4;dx++) {
        doc=DC2Doc(dc,dx,dy,&score);
        if (score<best_score) {
          best_score=score;
          StrCpy(&doc->filename.name,out_name);
          DocWrite(doc);
        }
        DocDel(doc);
      }
  }
  Free(in_name);
  Free(out_name);
}

U0 TOSTheme()
{
  if (!fg_on)
    PopUp("Sleep(50);FrameGrabberToggle;");
  ExeFile("~/Sup1/Sup1Graphics/TOS/TOSTheme.HC");
  DocClear;
}

#define MEM_TEST_SIZE   1024*1024
U0 MemTest()
{
  U8 *b;
  while (sys_data_bp->alloced_u8s-sys_data_bp->used_u8s>0x1000000) {
    b=MAlloc(MEM_TEST_SIZE,Fs->data_heap);
    MemSet(b,0x88,MSize(b));
    "Data:%X\n",sys_data_bp->alloced_u8s-sys_data_bp->used_u8s;
    Yield;
  }
  while (sys_code_bp->alloced_u8s-sys_code_bp->used_u8s>0x1000000) {
    b=MAlloc(MEM_TEST_SIZE,Fs->code_heap);
    MemSet(b,0x88,MSize(b));
    "Code:%X\n",sys_code_bp->alloced_u8s-sys_code_bp->used_u8s;
    Yield;
  }
}

public I64 Profanity(
        U8 *needle_filename="~/Sup1/Sup1Blog/Profanity.DD.Z",
        U8 *files_find_mask="/*",U8 *fu_flags=NULL)
{//Scan for profanity.
  CCmpCtrl *cc;
  I64 res=0;
  if (FileFind(needle_filename)) {
    cc=CmpCtrlNew(MStrPrint("#include \"%s\"",needle_filename));
    while (Lex(cc))
      if (cc->token==TK_IDENT)
        res+=Find(cc->cur_str,files_find_mask,fu_flags);
    CmpCtrlDel(cc);
  }
  return res;
}

U0 TOSChgLog2()
{
  InStr("\"Ed(\\\"::/Doc/ChgLog.DD.Z\\\");\n\";
  Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_UP|SCF_CTRL);
  Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN);
  Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN);
  Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN);
  Msg(MSG_KEY_DOWN_UP,0,SC_CURSOR_DOWN);
  Msg(MSG_KEY_DOWN_UP,CH_CTRLY,0);
  Msg(MSG_KEY_DOWN_UP,0,SC_F6|SCF_ALT);
  Msg(MSG_KEY_DOWN_UP,CH_ESC,0);"
  "\"Exit;\n\";");
}

public U0 TOSChgLog()
{//Opdate ChgLog file.
  User("TOSChgLog2;\n");
}