home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 10: Diskmags / nf_archive_10.iso / MAGS / ST_USER / 1990 / USERJA90.MSA / LISTINGS_CONVERT.S < prev    next >
Text File  |  1989-10-26  |  11KB  |  480 lines

  1. * PROGRAM TO CONVERT STANDARD ATARI FORMATTED DISCS TO FAST FORMAT *
  2. * BY PHIL LAWSON FOR ATARI ST USER (C)1989 *
  3. * IT WILL ALSO KILL ANY VIRUS PRESENT *
  4.  
  5. ***************************************
  6. * TO CALL THE PRINT ROUTINE:          *
  7. *    A6=ADDRESS OF STRING TO PRINT *
  8. ***************************************
  9.  
  10. ***************************************
  11. * TO CALL THE GET KEY ROUTINE:        *
  12. *    D6=SCANCODE VALUE OF KEY1        *
  13. *    D7=SCANCODE VALUE OF KEY2        *
  14. * THE PRESSED KEY IS RETURNED IN D5   *
  15. ***************************************
  16.  
  17.     jmp start
  18.  
  19. cls    dc.b 27,'H',27,'E'
  20.     dc.b 0
  21. mess1    dc.b 'Which disc drive [A] or [B]?',10,13
  22.     dc.b 0
  23.     even
  24. driva    dc.b 'Insert disc into drive A',10,13
  25.     dc.b 0
  26.     even
  27. drivb    dc.b 'Insert disc into drive B',10,13
  28.     dc.b 0
  29.     even
  30. spbar    dc.b 'Press the spacebar to continue.',10,13
  31.     dc.b 0
  32.     even
  33. vir    dc.b 'This disc may have a VIRUS on it.',10,13
  34.     dc.b 'Shall I get rid of it for you? [Y] or [N]',13,10
  35.     dc.b 0
  36.     even
  37. final    dc.b 10,13,'About to convert disc.',10,13
  38.     dc.b 'Continue or Return? [C] or [R]',10,13
  39.     dc.b 0
  40.     even
  41. done    dc.b 10,13,'Finished. Returning to desktop',10,13
  42.     dc.b 0
  43.     even
  44. error    dc.b 'An error has occurred while reading the disc.',10,13
  45.     dc.b 'Returning to the desktop',10,13
  46.     dc.b 0
  47.     even
  48. wrong    dc.b 'The drive is single sided,',10,13
  49.     dc.b 'and the disc is double sided.',10,13
  50.     dc.b 'Returning to desktop.',10,13
  51.     dc.b 0
  52.     even
  53. strd    dc.b 'This disc is not 9 sectors, or',10,13
  54.     dc.b 'not 80 or 81 or 82 tracks.',10,13
  55.     dc.b 'Returning to desktop.',10,13
  56.     dc.b 0
  57.     even
  58.  
  59. drivs    dc.b 0;        How many drives 0 or 1
  60.     even
  61. sides    dc.b 0;        How many sides on disc
  62.     even
  63. virus    dc.b 0;        =1 if a virus is to be killed
  64.     even
  65. tracks    dc.b 79;    =79,80 or 81 tracks (+1)
  66.     even
  67. sects    dc.b 9;        =9 sectors
  68.     even
  69.  
  70. sperd    dc.w 0;        Sectors per disc
  71.     even
  72.  
  73. ***************************************
  74. *     FIND THE END OF THE PROGRAM     *
  75. *                                     *
  76. *     SET THE FOLLOWING REGISTERS     *
  77. *  A4=BUFFER FOR READ/WRITE SECTORS   *
  78. *   A5=BUFFER FOR FORMATTING DISC     *
  79. ***************************************
  80. start
  81.     move.l a7,a5
  82.     move.l 4(a5),a5
  83.     move.l 12(a5),d0
  84.     add.l 20(a5),d0
  85.     add.l 28(a5),d0
  86.     add.l #$400+$100,d0
  87.     move.l d0,d1
  88.     add.l a5,d1
  89.     and.l #-2,d1
  90.     move.l d1,a4
  91.     move.l d1,a5
  92.     add.l #10000,a5
  93.     add.l #20000,d1
  94.     move.l d1,a7
  95.  
  96.  
  97. ***************************************
  98. *        NOW CLEAR THE SCREEN          *
  99. ***************************************
  100.  
  101.     move.l #cls,a6
  102.     jsr print_it
  103.  
  104.  
  105. ***************************************
  106. *  FIND OUT HOW MANY DRIVES ATTACHED  *
  107. ***************************************
  108.  
  109.     move.w #10,-(a7)
  110.     trap #13
  111.     add.l #2,a7
  112.  
  113.     add.b #-1,d0
  114.     lsr.b #1,d0
  115.     move.b d0,(drivs);    If one drive (%01) else if two (%11)
  116.     cmp.b #0,d0
  117.     beq put_in_disc;    If one drive dont ask which one
  118.  
  119.  
  120. ***************************************
  121. *      ASK WHICH DRIVE TO USE         *
  122. ***************************************
  123.  
  124.     move.l #mess1,a6
  125.     jsr print_it
  126.  
  127.     move.b #30,d6;    scancode for A
  128.     move.b #48,d7;    scancode for B
  129.     jsr get_key
  130.  
  131.     move.b d5,(drivs);        Drive A=0, Drive B=1
  132.  
  133.  
  134. ***************************************
  135. *       PUT DISC IN DRIVE A/B         *
  136. ***************************************
  137. put_in_disc
  138.     move.l #driva,a6
  139.     move.b (drivs),d0;    Which drive 0 or 1
  140.     cmp.b #0,d0
  141.     beq got_it;        Already pointing to DRIVE A message
  142.     move.l #drivb,a6
  143. got_it    jsr print_it;        Put disc in drive A/B
  144.     move.l #spbar,a6
  145.     jsr print_it;        Press spacebar
  146.     move.b #57,d6;        Scancode for spacebar
  147.     move.b #57,d7;           "      "      "
  148.     jsr get_key
  149.  
  150. ***************************************
  151. ***************************************
  152. ** THE DISC IS NOW IN THE RIGHT DRIVE**
  153. ***************************************
  154. ***************************************
  155.  
  156.  
  157. ***************************************
  158. *    CHECK IF EVERYTHING IS CORRECT   *
  159. ***************************************
  160.  
  161. ;get the number of sectors per track
  162.  
  163.     move.w #0,d7;        Side number zero
  164.     move.w #0,d6;        Track number zero
  165.     move.l a4,a6;        Buffer to store data
  166.     move.l #0,d3
  167.     move.b (drivs),d3
  168.     jsr read_track
  169.  
  170. ;Now get the number of tracks on disc
  171.  
  172. get_tracks
  173.     move.l #0,d0;        Make sure these are
  174.     move.l d0,d1;        completely zero.
  175.     move.b 19(a6),d0;    Sectors per disc are stored
  176.     move.b 20(a6),d1;    in bytes 19 and 20 of boot sector.
  177.     lsl.w #8,d1;        x256
  178.     add.w d1,d0;        D0=SECTORS PER DISC
  179.     move.w d0,(sperd)
  180.  
  181. ***************************************
  182. *get sides of disc from no. of sectors*
  183. ***************************************
  184.     move.l d0,d2
  185.     divu.w #1000,d2
  186.     move.b d2,(sides)
  187.  
  188.     move.w #0,d1
  189.     move.b (sects),d1;    Sectors per track
  190.     divu.w d1,d0;        Sectors per disc
  191.     move.b (sides),d2
  192.     lsr.w d2,d0
  193.     add.b #-1,d0
  194.     move.b d0,(tracks);    TRACKS PER DISC  = D0/D1
  195.  
  196.  
  197. ***************************************
  198. * ONLY WORKS ON DISCS WITH 80,81 OR 82*
  199. *               TRACKS                *
  200. ***************************************
  201.     cmp.b #79,d0
  202.     beq check_disc
  203.     cmp.b #80,d0
  204.     beq check_disc
  205.     cmp.b #81,d0
  206.     beq check_disc
  207.     bne not_standard
  208.  
  209.  
  210. ***************************************
  211. *   ONLY WORKS ON DISCS WITH 9 OR 10  *
  212. *          SECTORS PER TRACK          *
  213. ***************************************
  214. check_disc
  215.     move.b (sects),d0
  216.     cmp.b #9,d0
  217.     bne not_standard
  218.  
  219. so_far_so_good
  220.  
  221. ;Try reading first track of disc from specified drive
  222. ;If double sided then read from side two
  223.  
  224.     move.b (sides),d7
  225.     move.w #0,d6
  226.     move.l a4,a6
  227.     move.l #0,d3
  228.     move.b (drivs),d3
  229.     jsr read_track
  230.     cmp.l #0,d0
  231.     bne wrong_selections
  232.  
  233.  
  234. ***************************************
  235. *           CHECK FOR VIRUS           *
  236. ***************************************
  237. check_virus
  238.     move.w (a6),d0
  239.     cmp.w #0,d0;    If these bytes are not zero
  240.     beq convert;    the disc may have a virus on it.
  241.     jsr found_virus
  242.  
  243.  
  244. ***************************************
  245. ***************************************
  246. *        NOW CONVERT THE DISC         *
  247. ***************************************
  248. ***************************************
  249. convert
  250.     move.l #final,a6
  251.     jsr print_it
  252.     move.b #46,d6;        scancode for C
  253.     move.b #19,d7;        Scancode for R
  254.     jsr get_key
  255.     cmp #0,d5
  256.     beq go_ahead
  257.     move.w #0,-(a7);    Pressed R for return
  258.     trap #1;        so return to desktop
  259.  
  260.  
  261. go_ahead
  262.     move.l a5,a3
  263.     move.l a4,a6
  264.     move.b (tracks),d6
  265.     move.l #0,d3
  266.     move.b (drivs),d3
  267. loop1    move.w #0,d7
  268.     move.b (sides),d7
  269. loop2    jsr read_track
  270.     cmp.l #0,d0;        If a read error has occurred
  271.     bne read_error;        tell the user and return to desktop
  272.  
  273.     cmp.b #0,d6;        Track zero is the one containing the
  274.     beq track_zero;        offset to any virus present
  275. back2    jsr format_track
  276.     jsr write_track
  277.     dbra d7,loop2
  278.     dbra d6,loop1    
  279.  
  280. ***************************************
  281. *    CONVERSION PROCESS COMPLETED     *
  282. ***************************************
  283.  
  284. ;return to desktop
  285.     move.l #done,a6
  286.     jsr print_it
  287. out    move.l #spbar,a6
  288.     jsr print_it
  289.     move.b #57,d6
  290.     move.b #57,d7
  291.     jsr get_key;        wait until spacebar pressed
  292.     move.w #0,-(a7)
  293.     trap #1;        back to desktop
  294.  
  295.  
  296. read_error
  297.     move.l #error,a6
  298.     jsr print_it
  299.     bra out
  300.  
  301.  
  302. ***************************************
  303. *    GET RID OF THE VIRUS OFFSET      *
  304. ***************************************
  305. track_zero
  306.     cmp.b #0,d7;        Are we on side zero?
  307.     bne back2
  308.     move.w (a6),d0;        get first two bytes of sector
  309.     cmp.w #0,d0;         If zero then no virus present
  310.     beq back2
  311.     move.b (virus),d0;    If zero then get rid of virus
  312.     cmp.b #1,d0;        else if 1 then dont
  313.     beq back2
  314.  
  315.     move.w #0,d0
  316.     move.w d0,(a6);        Remove virus offset
  317.     bra back2
  318.  
  319.     
  320.  
  321. ***************************************
  322. * TO USE THE READ TRACK ROUTINE:      *
  323. *    A6=ADDRESS OF BUFFER             *
  324. *    D7=SIDE 0 or 1                   *
  325. *    D6=TRACK NUMBER                  *
  326. ***************************************
  327. read_track
  328.     move.w #9,-(a7);    nine sectors
  329.     move.w d7,-(a7);    which side
  330.     move.w d6,-(a7);    which track
  331.     move.w #1,-(a7);    start at sector 1
  332.     move.w d3,-(a7);    which drive 0 or 1
  333.     move.l #0,-(a7);    unused bytes
  334.     move.l a6,-(a7);    buffer to store data
  335.     move.w #8,-(a7);    function number
  336.     trap #14
  337.     add.w #20,a7
  338.     rts
  339.  
  340. ***************************************
  341. * TO USE THE FORMAT TRACK ROUTINE:    *
  342. *    A3=ADDRESS OF BUFFER             *
  343. *    D7=SIDE 0 or 1                   *
  344. *    D6=TRACK NUMBER                  *
  345. ***************************************
  346. format_track
  347.     move.w #$E5E5,-(a7);        Format code
  348.     move.l #$87654321,-(a7);    Magic number
  349.     move.w #11,-(a7);        Interleave factor
  350.     move.w d7,-(a7)
  351.     move.w d6,-(a7)
  352.     move.w #9,-(a7);        Sectors to format
  353.     move.w d3,-(a7);        Which drive to format
  354.     move.l #0,-(a7);        Unused bytes
  355.     move.l a3,-(a7);        Buffer for formatting
  356.     move.w #10,-(a7);        function number
  357.     trap #14
  358.     add.w #26,a7
  359.     rts
  360.  
  361. ***************************************
  362. * TO USE THE WRITE TRACK ROUTINE:     *
  363. *    A6=ADDRESS OF BUFFER             *
  364. *    D7=SIDE 0 or 1                   *
  365. *    D6=TRACK NUMBER                  *
  366. ***************************************
  367. write_track
  368.     move.w #9,-(a7);    nine sectors
  369.     move.w d7,-(a7);    which side
  370.     move.w d6,-(a7);    which track
  371.     move.w #1,-(a7);    start at sector 1
  372.     move.w d3,-(a7);    which drive 0 or 1
  373.     move.l #0,-(a7);    unused bytes
  374.     move.l a6,-(a7);    buffer to get data from
  375.     move.w #9,-(a7);    function number
  376.     trap #14
  377.     add.w #20,a7
  378.     rts
  379.  
  380. ***************************************
  381. ***************************************    
  382.  
  383. wrong_selections
  384.     move.l #wrong,a6
  385.     jsr print_it
  386.     move.l #spbar,a6
  387.     move.b #57,d6
  388.     move.b #57,d7
  389.     jsr get_key
  390.     move.w #0,-(a7)
  391.     trap #1
  392.  
  393. ***************************************
  394. ***************************************
  395. not_standard
  396.     move.l #strd,a6
  397.     jsr print_it
  398.     move.l #spbar,a6
  399.     jsr print_it
  400.     move.b #57,d6
  401.     move.b #57,d7
  402.     jsr get_key
  403.     move.w #0,-(a7)
  404.     trap #1
  405.  
  406.  
  407.  
  408.  
  409.  
  410.  
  411. ***************************************
  412. *    ROUTINE TO PRINT STRING AT A6    *
  413. ***************************************
  414. print_it
  415.     move.l a6,-(a7)
  416.     move.w #9,-(a7)
  417.     trap #1
  418.     add.w #6,a7
  419.     rts
  420.  
  421. ***************************************
  422. *  FOUND A VIRUS. GET RID OF IT Y/N   *
  423. ***************************************
  424. found_virus
  425.     move.l #vir,a6;        Found virus message
  426.     jsr print_it
  427.     move.b #21,d6;        Scancode for Y
  428.     move.b #49,d7;        Scancode for N
  429.     jsr get_key
  430.     move.b d5,(virus)
  431.     rts
  432.  
  433.  
  434. ***************************************
  435. *    GET A KEYPRESS FROM KEYBOARD     *
  436. * KEYS TO LOOK FOR STORED IN D6 & D7  *
  437. *                                     *
  438. *    KEY PRESSED IS RETURNED IN D5    *
  439. ***************************************
  440. get_key
  441.     move.l #255,d2
  442. loop3    move.w #255,-(a7);    Wait until
  443.     move.w #6,-(a7);    the user
  444.     trap #1;        is not
  445.     add.w #4,a7;        pressing the
  446.     swap d0;        keyboard
  447.     and d2,d0
  448.     cmp.l #0,d0
  449.     bne loop3
  450.  
  451. loop4    move.w #255,-(a7)
  452.     move.w #6,-(a7)
  453.     trap #1
  454.     add.w #4,a7
  455.     swap d0
  456.     and d2,d0;        Wait until
  457.     cmp.l #0,d0;        a key has
  458.     beq loop4;        been pressed
  459.  
  460. ; check if pressed key is one of those wanted
  461.  
  462. ; The required keys are stored in D6 and D7
  463.  
  464.     cmp.b d6,d0
  465.     beq got_the_key
  466.     cmp.b d7,d0
  467.     bne loop4
  468.  
  469. got_the_key
  470.  
  471. ; if the pressed key is D6 then return value of zero
  472. ; in d5, otherwise the pressed key was in D7, so
  473. ; return the value of one
  474.  
  475.     move.b #0,d5
  476.     cmp.b d6,d0
  477.     beq return
  478.     add.b #1,d5
  479. return    rts
  480.