home *** CD-ROM | disk | FTP | other *** search
- PROGRAM bindscrn(Input, Output);
-
-
- TYPE
- Str8 = STRING[8];
- Str64 = String[64];
-
- CONST
- Max_Screens = 25;
- VAR
- In_file,Out_file,
- Do_file,HomeDir,legal,
- In_path, Out_path : Str64;
- Scrn_counter,Retval : Integer;
- Scrn_list,Proc_list : Array[1..Max_Screens] of Str8;
- Scrn_Process,newpath : Boolean;
-
-
-
- {------------------------------------------------------------------------}
- { GETFIELD: }
- { Read in a field of data into IBUF, only allowing characters found }
- { in LEGAL, until SIZE characters have been entered, with the last }
- { key code returned in KEYVAL. The field will be placed at position }
- { ROW,COL with colors specified in ATTRIB. }
- {------------------------------------------------------------------------}
- type
- Option_Type = set of 0..7;
-
- procedure GetField(var KeyVal : integer;
- var Legal : str64;
- var Ibuf : str64;
- Atrib,
- Row,Col,Size : integer;
- Options : Option_Type);
-
- external 'GETFIELD.BIN';
-
- {*******************************************************************}
- function Scrn_name(Base_name : Str64): Str64;
-
- begin
- if length(Base_name) = 8 then
- Scrn_name := 'X' + copy(Base_name,1,7)
- else
- Scrn_name := 'X' + Base_name
- end;
-
- Procedure GetPath(row,col : integer; VAR pathname : Str64);
-
- const
- blank : Str64 = ' ';
- function dir_exists(path : Str64) : boolean;
-
- var
- result : boolean;
- {$I-}
- begin
- chdir(path);
- if IOResult = 0 then
- begin
- chdir(HomeDir);
- result := TRUE
- end
- else
- begin
-
- GoToXY(col,row); Write('Not a valid directory');
- delay(2000);
- result := FALSE
- end;
- {$I+}
- dir_exists := result
- end;
- begin
- repeat
- GotoXY(col,row);
- write(blank);
- pathname := ' ';
- gotoxy(col,row);
- read(pathname);
- If length(pathname)>1 then
- If copy(pathname,length(pathname),1 ) = '\' then
- pathname := copy(pathname,1,length(pathname)-1)
- until dir_exists(pathname) or (length(pathname) = 0);
- pathname := pathname + '\'; { make sure the path ends properly }
- if length(pathname) = 1 then
- begin
- pathname := homedir+'\';
- gotoxy(col,row); write(pathname)
- end
- end;
-
- function file_exists(var thefile : Str64) : boolean;
- type
- Registertype = record
- AX,BX,CX,DX,
- BP,SI,DI,DS,ES,flags: integer;
- end;
-
- var
- registers:registertype;
-
- begin
- thefile := thefile + #0;
- with registers do
- begin
- ds := seg(thefile);
- dx := ofs(thefile)+1;
- ax := $4E00;
- cx := $0000
- end;
- intr($21,registers);
- file_exists := not ((registers.flags and $0001) = $0001)
- end;
-
- Procedure Primary_screen; external 'bindscrn.sqz';
-
-
- {==========================================================================}
- Procedure Convt_screen(Base_name : Str64);
-
- Type
- hexval = STRING [4];
-
- CONST
- Base_Overhd = 259.0; { result is going to be Real }
- Incremental_Overhd = 65.0; { to allow for > 32767 }
-
- VAR
- outval: ARRAY [1..4096] OF hexval;
- Scrn_file: FILE OF BYTE;
- Dat_file: TEXT;
- inchar: BYTE;
- inname, outname: Str64;
- counter, x: INTEGER;
- Out_size : Real;
- dbsize: STRING [4];
- outstr: STRING [127];
-
-
- FUNCTION to_hex(inval: BYTE): hexval;
- {convert the byte to its hex string
- equivilent }
-
- CONST
- hex: ARRAY [0..15] OF CHAR = '0123456789ABCDEF';
-
- VAR
- lchar, rchar: CHAR;
-
- BEGIN
- IF inval < 16 THEN
- BEGIN
- lchar := '0';
- rchar := hex[inval]
- END
- ELSE
- BEGIN
- rchar := hex[inval MOD 16];
- lchar := hex[((inval DIV 16) MOD 16)]
- END;
- IF lchar IN ['A'..'F'] THEN
- to_hex := '0' + lchar + rchar + 'H'
- ELSE
- to_hex := lchar + rchar + 'H';
- END;
-
- BEGIN {convt_scrn}
- inname := In_path+Base_name + '.SQZ';
- outname := Out_path + Scrn_name(Base_name) + '.DAT';
- Assign(Scrn_file, inname);
- Reset(Scrn_file);
- {open the input file}
- Assign(Dat_file, outname);
- Rewrite(Dat_file); {create and open the output file }
- counter := 0;
- WHILE NOT Eof(Scrn_file) DO
- BEGIN
- {loading the screen file into a hex text file
- to merge into an assembly language source file}
- counter := counter + 1;
- Read(Scrn_file, inchar);
- outval[counter] := to_hex(inchar)
- END;
- Close(Scrn_file);
- if Scrn_counter = 1 then
- Out_size := Base_Overhd + counter
- else
- Out_size := Out_size + Incremental_Overhd + counter;
- GotoXY(68,23); write(Out_size:5:0);
-
- { it's all in the array, now send it out in assembler compatible
- format}
- outstr := Scrn_name(Base_name) + #9 + 'DB' + #9;
- {label first time only}
- x := 1;
- WHILE x < counter DO {no comma after the last one}
- BEGIN
- { Writeln(outval[x]); }
- IF (x MOD 10 <> 0) THEN {string them together 10 at a time}
- outstr := outstr + outval[x] + ','
- ELSE { it's long enough - send it out }
- BEGIN
- outstr := outstr + outval[x];
- {no comma on this last one }
- Writeln(Dat_file, outstr);
- outstr := #9 + 'DB' + #9
- {tab + asm directive + tab}
- END;
- x := x + 1
- END;
- outstr := outstr + outval[counter];
- Writeln(Dat_file, outstr); {send the last one out}
- Writeln(Dat_file, '; End of ', Scrn_name(Base_name), ' data');
- Flush(Dat_file);
- Close(Dat_file);
- END; {Convt_scrn}
-
- Procedure gen_head_file;
-
- TYPE
- Str127 = String[127];
-
- CONST
- Padblank = ' ';
-
-
- VAR
- i : Integer;
- Out_Str : Str127;
- LEA_Str : Str8;
- Asm_file : Text;
- begin
- i := 1;
- Assign(Asm_file, Out_file);
- Rewrite(Asm_file); {create and open the output file }
- if Scrn_Counter > 1 then
- begin
- Repeat { make each screen name a 'public name'}
- Out_Str := ' PUBLIC ';
- While (i < Scrn_Counter) and ((length(Out_Str) + length(Proc_list[i+1]) + 1) < 119) do
- begin
- Out_Str := Out_Str + Proc_list[i] + ', ';
- i := i + 1
- end;
- Out_Str := Out_Str + Proc_list[i]; { no comma on the last element in a line }
- i := i + 1; { set counter for next pass (or exit) }
- WriteLn(Asm_file,Out_Str);
- Until i >= Scrn_Counter
- end
- else
- WriteLn(Asm_file,' PUBLIC ',Proc_list[1]);
- { Now write the rest of the initial portion of
- the header file }
- WriteLn(Asm_file,' EXTRN _RET:FAR');
- WriteLn(Asm_file,'_PROG SEGMENT BYTE');
- WriteLn(Asm_file,' ASSUME CS:_PROG');
- WriteLn(Asm_file,'COMMA EQU '',''');
- WriteLn(Asm_file,';************************ local subroutines ***************************');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,'; ===================== the "main (sub)routine" =======================');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,'MAIN: MOV BX,OFFSET STORAGE ; put the offset of the screen data into ax');
- WriteLn(Asm_file,' MOV SI,10 ; set the index to the end of the');
- WriteLn(Asm_file,' ; string area because well do the');
- WriteLn(Asm_file,' ; conversion backwards');
- WriteLn(Asm_file,' CALL TO_ASC ; convert the offset to a string');
- WriteLn(Asm_file,' MOV [BX][SI],BYTE PTR COMMA ; put the comma into the string');
- WriteLn(Asm_file,' DEC SI ; back up the pointer again');
- WriteLn(Asm_file,'; now get the segment and convert it');
- WriteLn(Asm_file,' MOV AX,CS ; get the segment address into ax');
- WriteLn(Asm_file,' CALL TO_ASC ; convert the segment to a string');
- WriteLn(Asm_file,'; now we have the string assembled as SEG,OFS');
- WriteLn(Asm_file,'; it resides at the label "STORAGE" plus any value remaining in SI');
- WriteLn(Asm_file,'; send the command string to vidpop');
- WriteLn(Asm_file,' CALL POPCOMMD');
- WriteLn(Asm_file,' RET ; to proc');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,'; ============= convert hex value in DX to ascii char =================');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,'TO_ASC: MOV BP,10 ; set divisor to 10');
- WriteLn(Asm_file,' XOR DX,DX ; clear the high word');
- WriteLn(Asm_file,'AGAIN: DIV BP ; div AX by BP put remainder into DX');
- WriteLn(Asm_file,' OR DX,30H ; convert remainder to ASCII digit');
- WriteLn(Asm_file,' MOV [BX][SI],DL ; move the char into the string (STORAGE) backwards');
- WriteLn(Asm_file,' XOR DX,DX ; clear the remainder for next divide');
- WriteLn(Asm_file,' DEC SI ; adjust pointer for next char ');
- WriteLn(Asm_file,' OR AX,AX ; all done with the offset?');
- WriteLn(Asm_file,' JNZ AGAIN ; no, go get next char from the dividend');
- WriteLn(Asm_file,' RET ; yes, go back to main');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,'; ================= send the commands to vidpop =======================');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,'POPCOMMD: ; Using Straight Line code because it works');
- WriteLn(Asm_file,' MOV AH,14 ; set up for INT 10 function "TTY"');
- WriteLn(Asm_file,' MOV AL,255 ; VIDPOP"s wake up character');
- WriteLn(Asm_file,' INT 10H');
- WriteLn(Asm_file,' INT 10H ; send it twice to awaken vidpop');
- WriteLn(Asm_file,' MOV AL,''C''');
- WriteLn(Asm_file,' INT 10H ');
- WriteLn(Asm_file,' MOV AL,''S''');
- WriteLn(Asm_file,' INT 10H ');
- WriteLn(Asm_file,' MOV AL,'' ''');
- WriteLn(Asm_file,' INT 10H ');
- WriteLn(Asm_file,' MOV AL,''L''');
- WriteLn(Asm_file,' INT 10H ');
- WriteLn(Asm_file,' MOV AL,''O''');
- WriteLn(Asm_file,' INT 10H ');
- WriteLn(Asm_file,' MOV AL,''A''');
- WriteLn(Asm_file,' INT 10H ');
- WriteLn(Asm_file,' MOV AL,''D''');
- WriteLn(Asm_file,' INT 10H ');
- WriteLn(Asm_file,' MOV AL,'' ''');
- WriteLn(Asm_file,' INT 10H ; the end of the fixed part of the command ');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,'; now send out the converted string');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,' ; in the conversion, SI was decremented');
- WriteLn(Asm_file,' ; to a position one char before the');
- WriteLn(Asm_file,' ; start of SEG,OFS so now we will');
- WriteLn(Asm_file,' INC SI ; move it back one to point properly');
- WriteLn(Asm_file,' ADD SI,BX ; to get pointer for output string');
- WriteLn(Asm_file,' MOV AL,[SI] ; move the character into al');
- WriteLn(Asm_file,'MORE: INT 10h ; send it out');
- WriteLn(Asm_file,' INC SI ; increment the pointer');
- WriteLn(Asm_file,' MOV AL,[SI] ; get the next char');
- WriteLn(Asm_file,' CMP AL,0 ; see it we"re past the end ');
- WriteLn(Asm_file,' JNZ MORE ; no, go get another char');
- WriteLn(Asm_file,' ; yes, finish up');
- WriteLn(Asm_file,' MOV AL,''/'' ; and terminate the command to vidpop');
- WriteLn(Asm_file,' INT 10H');
- WriteLn(Asm_file,' RET');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,';*********************** end of local subroutines **************************');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,'STORAGE: DB 12 DUP (0) ; a place to store the string SEG,OFS');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,';********************** begin screen procs *********************************');
- { now write the individual procedures }
- for i := 1 to Scrn_Counter do
- begin
- Out_Str := Proc_list[i];
- LEA_Str := Scrn_list[i];
- if length(Out_Str) <8 then
- Out_Str := Out_Str + copy(Padblank,1,7-length(Out_Str));
- WriteLn(Asm_file,Out_Str,' PROC FAR');
- WriteLn(Asm_file,' PUSH SS ; save registers and set up per Clipper');
- WriteLn(Asm_file,' PUSH ES');
- WriteLn(Asm_file,' PUSH BP ');
- WriteLn(Asm_file,' PUSH DS');
- WriteLn(Asm_file,';');
- WriteLn(Asm_file,' LEA AX,',LEA_Str,' ; load the address of the screen data');
- WriteLn(Asm_file,' CALL MAIN ');
- WriteLn(Asm_file,'; now clean up the stack and ...');
- WriteLn(Asm_file,' POP DS ');
- WriteLn(Asm_file,' POP BP');
- WriteLn(Asm_file,' POP ES');
- WriteLn(Asm_file,' POP SS ');
- WriteLn(Asm_file,' CALL _RET ;Clipper stack check');
- WriteLn(Asm_file,' RET ; go back to Clipper');
- WriteLn(Asm_file,Out_Str,' ENDP');
- WriteLn(Asm_file,';*********************************************************************')
- end; { for i - write procedures }
- { now add the INCLUDE directives }
- for i := 1 to Scrn_Counter do
- begin
- WriteLn(Asm_file,'INCLUDE ',Scrn_list[i],'.DAT');
- Writeln(Asm_file,' DB 0')
- end; { for i - write include directives }
- Writeln(Asm_file,'_PROG ENDS');
- Writeln(Asm_file,'END');
- Flush(Asm_file);
- Close(Asm_file)
-
- end; { gen_head_file }
-
- begin {main}
- ClrScr;
- {Init variables}
- In_path :='';
- Out_path := '';
- Scrn_counter := 0;
- Scrn_Process := TRUE;
- legal := '';
- Out_file :='';
- GetDir(0,HomeDir); { Where are we now?)
- { Call in the main screen }
- writeln(chr(255),chr(255),'CS LOAD ',cseg,',',ofs(Primary_screen),'/');
- { Get constant data for source and target paths and Output file name }
- getpath(12,10,In_path); {the initial source directory}
- getpath(12,50,out_path); { the target directory for all output files }
- repeat
- GetField(RetVal,legal,Out_file,$30,13,54,8,[1]) { the name for the '.ASM' file }
- until length(Out_file)>0;
- Out_file := Out_path + Out_file+ '.ASM';
- While Scrn_Process do begin
- repeat
- newpath := FALSE;
- In_file := '';
- GetField(RetVal,legal,In_file,$30,13,11,8,[1]); { the name for the screen }
- if RetVal=27 then { and '.DAT' file }
- begin
- newpath := TRUE;
- getpath(12,10,In_path)
- end;
- if (length(In_file) = 0) and not newpath then
- Scrn_Process := FALSE
- else
- Do_file := In_path + In_file + '.SQZ'{Put the path and file together}
- until file_exists(Do_file) or not Scrn_Process;
- if scrn_Process then
- begin
- Scrn_Counter := Scrn_Counter + 1;
- GotoXY(67,22); write(Scrn_Counter);
- Scrn_list[Scrn_Counter] := Scrn_name(In_file);
- Proc_list[Scrn_Counter] := In_file;
- Convt_screen(In_file);
- if Scrn_Counter = Max_Screens then
- Scrn_Process := FALSE;
- end;
- end; { Scrn_Process }
- { Now that all of the screens are converted we
- must write the controlling assembler file }
- if Scrn_Counter > 0 then
- gen_head_file;
- ClrScr
- END.