home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Misc / GXY-INF.LHA / infos / hardware_load.s < prev    next >
Encoding:
Text File  |  1996-03-09  |  7.8 KB  |  319 lines

  1. ;­­­­­­­­­­­­­­MACRO-definitions­­­­­­­­­­­­­­­­­­
  2. color:    macro
  3.     move.w    #\1,$180(a6)
  4.     endm
  5.  
  6. step:    macro
  7.     move.b    floppystatus(pc),d0
  8.     move.b    d0,d1
  9.     bclr    #0,d0        ;clear DSKSTEP after setting it...STEP!
  10.     move.b    d0,(a0)        ;a0=$bfd100 (CIA-B PRB)
  11.     nop            ;wait a little
  12.     nop
  13.     move.b    d1,(a0)        ;set DSKSTEP back to 1
  14.     bsr.l    timer        ;wait a while
  15.     endm
  16.  
  17. Amount=    12
  18. ;­amount of tracks to read - may be changed, of course!
  19. first_track=    0
  20. ;­first track to read - may be changed, too!
  21. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  22.  
  23. S:
  24.     movem.l    d0-d7/a0-a6,-(a7)
  25.  
  26.     lea    $dff000,a6    ;coustom base
  27.     lea    s(pc),a5    ;addressoffset (bootblock MUST be pc-
  28.                 ;relative)
  29.  
  30.     move.w    $01c(a6),oldint-s(a5)
  31.     ori.w    #$8000,oldint-s(a5)
  32.     move.w    $002(a6),olddma-s(a5)
  33.     ori.w    #$8000,olddma-s(a5)
  34.     move.w    $010(a6),oldadk-s(a5)
  35.     ori.w    #$8000,oldadk-s(a5)
  36.     move.w    #$7fff,d0
  37.     move.w    d0,$096(a6)    ;switch dma's off
  38.     move.w    d0,$09a(a6)    ;forbid interrupts
  39.     move.w    #$8028,$09a(a6)    ;forbid interrupts
  40. ;    move.w    d0,$09c(a6)    ;clear intreq
  41.     move.w    d0,$09e(a6)    ;clear adkcon
  42.  
  43.     color    0        ;background color while loading
  44.     move.w    #$8210,$96(a6)    ;diskdma on!
  45.  
  46. ;select DRIVE:      3210
  47.     moveq    #%0001,d0    ;set right bit for drive 0,1,2 or 3
  48.     bsr.l    select_drive    ;select drive from which you want to read
  49.  
  50.     bsr.l    motor_on    ;drivemotor on
  51.  
  52.     moveq    #0,d0        ;move track number ->d0
  53.     bsr.l    head_pos    ;move head to track 0 (orientation)
  54.  
  55.     bsr.l    init_read    ;init diskregisters
  56. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  57.     move.w    #Amount,trackct-s(a5);set trackcounter
  58. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  59.  
  60. Load_tracks:
  61.     bchg    #1,$bfe001    ;switch led on/off each cylinder
  62.     move.w    track(pc),d0    ;move head to starttrack
  63.     bsr.l    head_pos
  64.     bsr.l    test_disk    ;check if disk in drive
  65. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  66.     bsr.l    read_track    ;read track
  67.     bsr.l    decode_track    ;decode track
  68. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  69.     addq.w    #1,track-s(a5)    ;next track (add/sub=increase/decrease)
  70.     subq.w    #1,trackct-s(a5);decrease trackcounter
  71.     bne.s    load_tracks
  72. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  73.     bsr.l    Motor_off    ;drivemotor off
  74. Exit:
  75.     move.w    Olddma(pc),$096(a6)
  76.     move.w    Oldint(pc),$09a(a6)
  77.     move.w    Oldadk(pc),$09e(a6)
  78.     movem.l    (a7)+,d0-d7/a0-a6
  79.     rts
  80.  
  81. olddma:    dc.w    0
  82. oldint:    dc.w    0
  83. oldadk:    dc.w    0
  84. track:    dc.w    first_track
  85. trackct:dc.w    0        ;trackcounter
  86.  
  87. Init_Read:
  88.     clr.w    $24(a6)        ;DSKLEN->forbid diskdma and writing
  89.     move.w    #$4489,$7e(a6)    ;set standard SYNC
  90.     move.w    #$7f00,$9e(a6)    ;clear ADKCON
  91.     move.w    #$9500,$9e(a6)    ;set required bits
  92.     move.w    #$0002,$9c(a6)    ;clear DSKBLK bit
  93.     Rts
  94.  
  95. Read_Track:
  96.     clr.w    $24(a6)        ;DSKLEN->forbid diskdma
  97.     lea    trackbuff(pc),a0
  98.     move.l    a0,$20(a6)    ;set DSKPTH and DSKPTL
  99.     move.w    #$9a00,$24(a6)    ;enable diskdma and set amount of
  100.     move.w    #$9a00,$24(a6)    ;words+2 to transfer.
  101.  
  102. Wait_Dma:
  103.     btst    #1,$1f(a6)    ;DSKBLK=0 ?
  104.     beq.s   Wait_Dma    ;yeah=> wait
  105.     clr.w    $24(a6)        ;forbid writing
  106.     move.w  #$0002,$9c(a6)    ;clear DSKBLK
  107.     Rts
  108.  
  109. ;­Timer A-delay
  110. timer:                ;waits ca. 1/100 sec.
  111.     move.b    #$00,$bfde00    ;clear CRA
  112.     move.b    #$7f,$bfdd00    ;clear ICR
  113.     move.b    #$00,$bfd400    ;timer a -low
  114.     move.b    #$20,$bfd500    ;timer a -high (wait-value=$2000)
  115.     move.b    #$09,$bfde00    ;set oneshot/start
  116. wait_timer:
  117.     btst    #0,$bfdd00    ;test ta-bit/that clears ICR
  118.     beq.s    wait_timer
  119.     rts
  120.  
  121. Wait_ready:
  122.     btst    #5,$bfe001    ;wait for DRIVEREADY
  123.     bne.s    Wait_ready    ;it's useless here, because the wait-
  124.     Rts            ;loop is long enough, but......
  125.  
  126. test_disk:
  127.     btst    #2,$bfe001
  128.     beq.s    error
  129.     Rts
  130. error:    move.w    $dff006,$dff180
  131.     bra.s    error
  132.  
  133. Select_Drive:
  134.     lea    floppystatus(pc),a0
  135.     lea    motorstatus(pc),a1
  136.     moveq    #-1,d1        ;$ffffffff -> d1
  137.     lsl.w    #3,d0        ;shift selectbit to right position
  138.     eor.b    d0,d1        ;selectbit must be zero
  139.     move.b    d1,(a0)        ;save byte ->floppystatus.b
  140.     eori.b    #$80,d1        ;clear DSKMOTOR-bit
  141.     move.b    d1,(a1)        ;save byte ->motorstatus.b
  142.     Rts
  143.  
  144. Motor_On:
  145.     move.b    #$7f,$bfd100    ;Bits 0-6 HIGH/Bit 7 LOW
  146.     nop
  147.     nop
  148.     move.b    motorstatus(pc),d0
  149.     move.b    d0,$bfd100    ;DSKMOTOR and DSKSELx LOW
  150.     bsr.l    Wait_Ready
  151.     Rts
  152.  
  153. Motor_Off:
  154.     move.b    #$ff,$bfd100    ;Bits 0-7 HIGH
  155.     nop
  156.     nop
  157.     move.b    motorstatus(pc),d0
  158.     ori.b    #$80,d0        ;DSKMOTOR HIGH DSKSELx LOW
  159.     move.b    d0,$bfd100
  160.     Rts
  161.  
  162. ;This routine moves the r/w-head to a track with the number stored
  163. ;in d0. A similar routine is also used by the operating-system
  164. ;(at $fea3da)
  165.  
  166. Head_Pos:
  167.     lea    $bfd100,a0
  168.     lea    s(pc),a5
  169.     tst.w    d0            ;track number=0?
  170.     beq.l    Move_zero        ;yeah=>step to track 0
  171.     move.w    Tracknum(pc),d2        ;current track number
  172.     cmp.w    d2,d0            ;oldtrack=newtrack ?
  173.     beq.s    Head_end        ;yes=>don't move head
  174.     move.w    d0,d3
  175.     move.b    Floppystatus(pc),d1
  176.     bset    #2,d1            ;select head 0 (lower side)
  177.     btst    #0,d3            ;track number even ?
  178.     beq.s    Down_Right        ;yes=>head 0 is the right one
  179.     bclr    #2,d1            ;no, select head 1 (upper side)
  180. Down_Right:
  181.     move.b    d1,Floppystatus-s(a5)
  182.     move.b    d1,(a0)
  183.     move.w    d3,Tracknum-s(a5)    ;save new track-number
  184.     lsr.w    #1,d2            ;d2=current cylinder
  185.     lsr.w    #1,d3            ;d3=new cylinder
  186.     sub.w    d3,d2            ;make difference
  187.     bmi.s    Seek_in            ;diff. negativ=> step in
  188.     beq.s    Head_end
  189.     bra.s    Seek_out        ;diff. positiv=> step out
  190. Seek_in:
  191.     bclr    #1,d1            ;step in
  192.     move.b    d1,Floppystatus-s(a5)
  193.     neg.w    d2            ;make number positive
  194.     bra.s    Step_Ok
  195. Seek_out:
  196.     bset    #1,d1            ;step out
  197.     move.b    d1,Floppystatus-s(a5)
  198.     bra.s    Step_Ok
  199. HeadStep:
  200.     Step                ;call step-macro
  201. Step_Ok:
  202.     dbf    d2,HeadStep
  203. Head_end:
  204.     Rts    
  205.  
  206. Move_zero:                ;move head to track zero
  207.     move.b    Floppystatus(pc),d1
  208.     bset    #2,d1
  209.     bset    #1,d1
  210.     move.b    d1,Floppystatus-s(a5)
  211.     clr.w    Tracknum-s(a5)
  212. Headzero:
  213.     btst    #4,$bfe001        ;test if zero
  214.     beq.s    zero1
  215.     Step
  216.     bra.s    Headzero
  217. zero1:
  218.     bclr    #1,Floppystatus-s(a5)
  219.     Step
  220.     bset    #1,Floppystatus-s(a5)
  221.     Step
  222.     bra.s    Head_end
  223.  
  224. ;­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
  225. ;This routine decodes the block-header and checks the format-sign.
  226. ;After this it calculates the checksum from the data-block and
  227. ;compares it with the checksum wich is stored in the block-header.
  228. ;While calculating the checksum it decodes the data block, of course.
  229.  
  230. decode_track:
  231.     move.l    bufferpt(pc),a0        ;pointer to decodebuffer
  232.     lea    trackbuff(pc),a1    ;pointer to MFMbuffer
  233.     moveq    #11-1,d5        ;decode 11 blocks (-1 coz dbf)
  234.     move.l    #$55555555,d3        ;filter for tactbits
  235.  
  236. decode_all_blocks:
  237.     cmpi.w    #$4489,(a1)+        ;1st sync-word found ?
  238.     bne.s    decode_all_blocks    ;no=> go on searching
  239.  
  240. sync_found:
  241.     cmpi.w    #$4489,(a1)        ;2. sync-word found ?
  242.     bne.s    syncs_ok        ;no=> all syncs skipped
  243.     addq.w    #2,a1            ;yes=>
  244.     bra.s    sync_found        ;search for remaining syncs
  245.  
  246. syncs_ok:                ;decode infoblock
  247.     move.l    (a1)+,d0        ;odd bits
  248.     move.l    (a1)+,d1        ;even bits
  249.     and.l    d3,d0
  250.     and.l    d3,d1
  251.     add.l    d0,d0
  252.     or.l    d1,d0
  253.  
  254.     swap    d0
  255.     andi.w    #$ff00,d0        ;mask format-sign (must be $ff)
  256.     cmpi.w    #$ff00,d0        ;right value?
  257.     bne.s    formatrerror        ;no==>ERROR!
  258.     swap    d0
  259.  
  260.     andi.w    #$ff00,d0        ;mask sector number*256
  261.     add.w    d0,d0            ;d0=d0*2 (=sector number*512)
  262.     move.l    a0,a2            ;address of decodebuffer ->a2
  263.     adda.w    d0,a2            ;calc. correct destination
  264.  
  265.     adda.w    #40,a1            ;address of checksum ->a1
  266.     move.l    (a1)+,d4        ;decode checksum
  267.     move.l    (a1)+,d1
  268.     and.l    d3,d4
  269.     and.l    d3,d1
  270.     add.l    d4,d4
  271.     or.l    d1,d4            ;store checksum ->d4
  272.  
  273.     moveq    #128-1,d6        ;decode 128*2 longs to 512 bytes 
  274.     moveq    #0,d2            ;clear datachecksum
  275.  
  276. decodeblock:                ;decode datablock
  277.     move.l    512(a1),d1        ;even bits
  278.     move.l    (a1)+,d0        ;odd bits
  279.  
  280.     eor.l    d0,d2            ;calc checksum
  281.     eor.l    d1,d2            ;dito
  282.  
  283.     and.l    d3,d0            ;decode longword
  284.     and.l    d3,d1
  285.     add.l    d0,d0
  286.     or.l    d1,d0
  287.     move.l    d0,(a2)+        ;store longword in buffer
  288.     dbf    d6,decodeblock        ;decode next longword
  289.  
  290.     and.l    d3,d2            ;remove tactbits
  291.     cmp.l    d4,d2            ;checksum correct ?
  292.     bne.s    chksumerror        ;no=>ERROR!
  293.     adda.w    #512,a1            ;reach next block
  294.     dbf    d5,decode_all_blocks
  295.  
  296.     adda.w    #$1600,a0        ;bufferadr.+ 1track (5632bytes)
  297.     move.l    a0,bufferpt-s(a5)    ;store new address
  298.     Rts
  299.  
  300. chksumerror:
  301.     color        $f00        ;backgroundcolor red
  302.     st        chkflag-s(a5)    ;set errorflag to -1
  303.     Rts
  304.  
  305. formatrerror:
  306.     color        $f00        ;backgroundcolor red
  307.     st        hdrflag-s(a5)    ;set errorflag to -1
  308.     Rts
  309.  
  310. tracknum:    dc.w    0
  311. floppystatus:    dc.b    0
  312. motorstatus:    dc.b    0
  313. chkflag:    dc.b    0
  314. hdrflag:    dc.b    0
  315. bufferpt:    dc.l    $40000
  316. Even
  317. trackbuff:
  318.         ds.b    $4000
  319.