MDV Low Level Routines

Anything QL Software or Programming Related.
Martin_Head
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

Re: MDV Low Level Routines

Post by Martin_Head »

tcat wrote:Tobias, Martin,

Thank you, now to the last block allocated, FDFD value in the map, does not seem right, or perhaps I cannot interpret it correctly?

I can also imagine, that some copy protection may obfuscate this value?

Many thanks
Tomas
I think it's just one byte of the last word in the map that is used (not sure if it's the upper, or lower byte).

So if file 05 was the last one written, I would have expected either $4D00 or $004D in the last word of the map.

You might want to look at some other image files to see if they make sense.

I suppose, in theory, the operating system would not need to actually write out that last word of the map to the microdrive cartridge. But I can't think why it would not.

Martin Head


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: MDV Low Level Routines

Post by tcat »

Hi,

I am now toying with dumping, the reverse task to MDV copying. My code seems doing things, but I am looking into ways of possible optimisation of the two assembly snippets down here, in the hope to get shorter execution in between gaps.

ONE

Code: Select all

sec_cont suba.l   #514,a1           ;Point Image Ptr to File-Blk
         move.b   d1,(a1)+          ;Record File Number
         move.b   d2,(a1)+          ;Record Block Number
         adda.l   #514,a1           ;Reset Image Ptr
                                    ;Make room for check sum
         jsr      cnt_dwn           ;Count down and read next
         bra.s    sec_loop
TWO

Code: Select all

red_fail movea.l  bad,a0            ;Recover Bad Ptr list
         move.b   d7,(a0)           ;Mark failing sector
         lea      bad,a0            ;Increment Bad Ptr
         addq.l   #$01,(a0)
         movea.l  image,a1          ;Reset Image Ptr
         bra.s    sec_loop          ;Read next sector
Many thanks in advance
Tomas


RWAP
RWAP Master
Posts: 2834
Joined: Sun Nov 28, 2010 4:51 pm
Location: Stone, United Kingdom
Contact:

Re: MDV Low Level Routines

Post by RWAP »

Just a couple of things spring to mind (bearing in mind I could not find my book which has the time taken to undertake each command):

a) Suba and Adda are quite slow - you are better storing the value of A1 temporarily
b) Can you not combine D1 and D2 and write a word to (A1)+ - that is quicker than two MOVE.B commands with post increment


User avatar
M68008
Trump Card
Posts: 223
Joined: Sat Jan 29, 2011 1:55 am
Contact:

Re: MDV Low Level Routines

Post by M68008 »

If for 'gaps' you mean the Microdrive gap, they are relatively long. 2.8 ms according to the "QL advanced guide", probably enough for at least a thousand instructions at 7.5 MHz


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: MDV Low Level Routines

Post by tcat »

Hi,

Thank you all for your suggestions, while I might be well within gap timings, I wish to learn to write a neater code.

Can this work with negative offset?

ONE (a)

Code: Select all

sec_cont move.w   #-514,d3          ;Offset(-) to File-Blk
         move.b   d1,$00(a1,d3.w)   ;Record File Number
         move.b   d2,$01(a1,d3.w)   ;Record Block Number
         addq.l   #$02,a1           ;Make room for check sum

         jsr      cnt_dwn           ;Count down and read next
         bra.s    sec_loop

ONE (b)

Code: Select all

sec_cont move.w   #-514,d3          ;Offset(-) to File-Blk
         lsl.w    #8,d1             ;d1=File-no
         or.w     d1,d2             ;d2=File-no+Blk-No
         move.w   d2,$00(a1,d3.w)   ;Record File-no+Blk-No
         addq.l   #$02,a1           ;Make room for check sum

         jsr      cnt_dwn           ;Count down and read next
         bra.s    sec_loop
Tomas


Martin_Head
Aurora
Posts: 847
Joined: Tue Dec 17, 2013 1:17 pm

Re: MDV Low Level Routines

Post by Martin_Head »

In the first example, If you kept a register always pointing at the start of the buffer/sector, say A5. Then you would not have to keep resetting your image pointer

Code: Select all

sec_cont  move.b   d1,15(a5)
          move.b   d2,16(a5)
          jsr      cnt_dwn 
          bra.s    sec_loop
(The offsets I used may not be right for you)


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: MDV Low Level Routines

Post by mk79 »

tcat wrote:Hi,
ONE (b)

Code: Select all

sec_cont move.w   #-514,d3          ;Offset(-) to File-Blk
         lsl.w    #8,d1             ;d1=File-no
         or.w     d1,d2             ;d2=File-no+Blk-No
         move.w   d2,$00(a1,d3.w)   ;Record File-no+Blk-No
         addq.l   #$02,a1           ;Make room for check sum

         jsr      cnt_dwn           ;Count down and read next
         bra.s    sec_loop
Tomas
You can leave out the move.w completely:

Code: Select all

sec_cont lsl.w    #8,d1             ;d1=File-no
         or.w     d1,d2             ;d2=File-no+Blk-No
         move.w   d2,-514(a1)      ;Record File-no+Blk-No
         addq.l   #$02,a1           ;Make room for check sum

         jsr      cnt_dwn           ;Count down and read next
         bra.s    sec_loop
I guess variant B with only one memory access is probably faster.

Marcel


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: MDV Low Level Routines

Post by tcat »

Hi,

Thank you, this helps.
How about the snippet TWO, any room for optimisation?

Coded in C language

*bad++ = d7;

Code: Select all

red_fail movea.l  bad,a0            ;Recover Bad Ptr list
         move.b   d7,(a0)           ;Mark failing sector
         lea      bad,a0            ;Increment Bad Ptr
         addq.l   #$01,(a0)
         
         movea.l  image,a1          ;Reset Image Ptr
         bra.s    sec_loop          ;Read next sector

Tomas


User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: MDV Low Level Routines

Post by mk79 »

tcat wrote:Hi,

Thank you, this helps.
How about the snippet TWO, any room for optimisation?

Coded in C language

*bad++ = d7;

Code: Select all

red_fail movea.l  bad,a0            ;Recover Bad Ptr list
         move.b   d7,(a0)           ;Mark failing sector
         lea      bad,a0            ;Increment Bad Ptr
         addq.l   #$01,(a0)
         
         movea.l  image,a1          ;Reset Image Ptr
         bra.s    sec_loop          ;Read next sector

Code: Select all

red_fail movea.l  bad,a0            ;Recover Bad Ptr list
         move.b   d7,(a0)+           ;Mark failing sector
         move.l   a0,bad
         
         movea.l  image,a1          ;Reset Image Ptr
         bra.s    sec_loop          ;Read next sector
Of course it would help even more if you can keep the bad-pointer in a register somewhere, any memory access is having a big impact. But snippet for snippet I think this is at least slightly better.

Cheers, Marcel


tcat
Super Gold Card
Posts: 633
Joined: Fri Jan 18, 2013 5:27 pm
Location: Prague, Czech Republic

Re: MDV Low Level Routines

Post by tcat »

Hi Marcel,

I am afraid on MC68008, storing values to effective address is not possible, as the effective address has to be loaded first. While I believe on later MC processors it is allowed.

Code: Select all

         move.l   a0,bad
on MC68008 above come as two instructions

Code: Select all

         lea     bad,a1
         move.l  a0,(a1)
Tomas


Post Reply