Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!rutgers!usc!snorkelwacker.mit.edu!bloom-beacon!eru!hagbard!sunic!mcsun!ukc!warwick!covpoly!csg019 From: csg019@cck.cov.ac.uk (Z*A*P*H*O*D) Newsgroups: comp.sys.amiga.tech Subject: MFM coding/protection. Message-ID: <1990Nov27.113820.28055@cck.cov.ac.uk> Date: 27 Nov 90 11:38:20 GMT Organization: Coventry Polytechnic, Coventry, UK Lines: 241 Hi peeps, i seem to recall someone asking for some code to read disks, and some info on MFM coding. Well, we'll start at the begining, the amiga uses 11 sectors per track, 2 sides, and 80 tracks, it stores the information on the disks using a method of encryption called MFM coding. This method helps to detect errors, and allows the track to be split into the 11 sectors. Each sector has a sector header (64 bytes) which is coded slightly differently from the rest of the track. There are actually 22 sectors on one side of a DOS disk, but these are combined to produce one sector. The coding of the sectors requires the first longword of sector 1 to be decoded with the first long word of the next sector (1 sector = 512 ($200) bytes)). To further complecate things, each track has a gap that contains no useable data. To cut a long story short, here is an assemly language program to read DOS disks using MFM coding. It was written in DEVPAC II but should be compatable with other assemblers like Argasm (nice little plug there eh FUZZZ???) Hope this helps the guy from London a bit! To protect you own software you should write a track with just one long sector of a strange length and have a custome routine on the bootblock to load it. I'm not a cracker and i am just just trying to help so no flames! Well i suppose i'm in for a flaming from all thos Americans that thing that games should multitask with 400 drives and 9 gigabytes of RAM, but still here goes..... * CODE WRITTEN BY ZAPHOD OF INTUITION * SECTION disk_map,code_c num_tracks = 10 Number of tracks -1 to read step_wait = 3000 Delay for track movement *Make program an exception for super mode start move.l $80,trap_save move.l #program_start,$80 trap #0 move.l trap_save,$80 rts program_start bsr save_status Set system bsr motor_on bsr seek_zero move.w #num_tracks,d4 read_more bsr read_track bsr decode bsr seek_80 Read tracks dbra d4,read_more bsr motor_off bsr restore_status rte *Track in until 0 is found seek_zero btst #4,$bfe001 beq found_0 bset #1,$bfd100 bclr #0,$bfd100 bset #0,$bfd100 bsr stepper_delay bra seek_zero found_0 rts seek_80 bclr #1,$bfd100 bclr #0,$bfd100 bset #0,$bfd100 bsr stepper_delay rts stepper_delay move.w #step_wait,d1 wait dbra d1,wait wait_command btst.b #5,$bfe001 bne.s wait_command rts read_track *Read block header move.w #$8210,$dff096 move.w #$4000,$dff024 move.w #$4489,$dff07e move.w #$8400,$dff09e move.l #$60000,$dff020 move.w #$8000+16,$dff024 move.w #$8000+16,$dff024 bsr wait_dma Wait for block done bsr clear_ints Clear interupts *Decode header move.l $60002,d0 move.l $60006,d1 andi.l #$55555555,d0 andi.l #$55555555,d1 lsl.l #1,d0 or.l d1,d0 cmp.b #1,d0 Next sector is gap? bne.s read_track No, read next sector lsr.w #8,d0 Yep, then get this sector numer cmp.b #10,d0 bne not_10 move.b #0,d0 bra.s doner not_10 add.b #1,d0 move.b d0,sector_number Store it doner move.w #$8210,$dff096 move.w #$4000,$dff024 move.w #$4489,$dff07e move.w #$8400,$dff09e move.l #$60000,$dff020 move.w #$8000+($220*11),$dff024 move.w #$8000+($220*11),$dff024 bsr wait_dma bsr clear_ints rts motor_delay move.w #$b000,d0 md dbra d0,md rts decode moveq.l #0,d0 move.b sector_number,d0 move.l d0,d1 mulu.w #512,d1 move.l #10,d2 sub.l d0,d2 lea $60000+58,a0 lea $60000+512+58,a2 lea $70000,a1 add.l d1,a1 dl2 move.w #(512/4)-1,d6 dl move.l (a0)+,d0 move.l (a2)+,d1 andi.l #$55555555,d0 andi.l #$55555555,d1 lsl.l #1,d0 or.l d1,d0 move.l d0,(a1)+ dbra d6,dl add.l #$240,a0 add.l #$240,a2 dbra d2,dl2 cmp.b #0,sector_number beq dones clr.l d2 move.b sector_number,d2 sub.w #1,d2 lea $70000,a1 dl3 move.w #(512/4)-1,d6 dl4 move.l (a0)+,d0 move.l (a2)+,d1 andi.l #$55555555,d0 andi.l #$55555555,d1 lsl.l #1,d0 or.l d1,d0 move.l d0,(a1)+ dbra d6,dl4 add.l #$240,a0 add.l #$240,a2 dbra d2,dl3 rts dones move.w #$fff,$dff180 rts save_status move.w $dff01c,saveints Save interupt stat move.w $dff002,savedma Save dma stat. move.w #$7fff,$dff09c Clear interupts rts motor_on move.b #%01111111,$bfd100 move.b #%11110011,$bfd100 bsr motor_delay rts motor_off move.b #$fd,$bfd100 nop nop move.b #%01111111,$bfd100 move.b #%11111111,$bfd100 bsr motor_delay rts restore_status move.w saveints,d0 or.w #$c000,d0 move.w d0,$dff01c move.w savedma,d0 or.w #$8100,d0 move.w d0,$dff096 rts wait_dma btst #1,$dff01f beq.s wait_dma rts clear_ints move.w #$4000,$dff024 move.w #$7fff,$dff09c rts saveints dc.w 0 savedma dc.w 0 trap_save dc.l 0 sector_number dc.b 0 -- *********/// O O **A member of S.H.I.T. (Super High Intelegence Team)**///*** * /// u Fight, defeat and kill organized laming. /// * * \\\ /// --- Zaphod of Intuition csg019@uk.ac.cov.cck ok? \\\ /// * ****\\X//**********************************************************\\X//******