home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / Games / WHDLoad / Src / programs / ITD.asm < prev    next >
Assembly Source File  |  1999-01-17  |  9KB  |  419 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    ITD.asm
  3. ;  :Contents.    Image To Disk
  4. ;  :Author.    Bert Jahn
  5. ;  :EMail.    wepl@kagi.com
  6. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  7. ;  :Version.    $Id: ITD.asm 0.17 1999/01/17 14:18:31 jah Exp jah $
  8. ;  :History.    29.10.97 start, based on DIC source
  9. ;        24.11.98 some messages fixed when writing files larger than device
  10. ;        17.01.99 recompile because error.i changed
  11. ;  :Requires.    OS V37+
  12. ;  :Copyright.    © 1997,1998 Bert Jahn, All Rights Reserved
  13. ;  :Language.    68000 Assembler
  14. ;  :Translator.    Barfly V1.130
  15. ;  :To Do.
  16. ;---------------------------------------------------------------------------*
  17. ;##########################################################################
  18.  
  19.     INCDIR    Includes:
  20.     INCLUDE    lvo/exec.i
  21.     INCLUDE    exec/execbase.i
  22.     INCLUDE    exec/io.i
  23.     INCLUDE    exec/memory.i
  24.     INCLUDE    lvo/dos.i
  25.     INCLUDE    dos/dos.i
  26.     INCLUDE    devices/trackdisk.i
  27.  
  28.     INCLUDE    macros/ntypes.i
  29.     INCLUDE    macros/mulu32.i
  30.  
  31. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  32.  
  33.     STRUCTURE    Globals,0
  34.         APTR    gl_execbase
  35.         APTR    gl_dosbase
  36.         APTR    gl_rdargs
  37.         LABEL    gl_rdarray
  38.         ULONG    gl_rd_file
  39.         ULONG    gl_rd_device
  40.         ULONG    gl_rd_format
  41.     ;    ULONG    gl_rd_force
  42.         ULONG    gl_rc
  43.         ALIGNLONG
  44.         LABEL    gl_SIZEOF
  45.  
  46. BREAKCOUNT    = 1000
  47. MAXFILENAMESIZE    = 30        ;31 with the termination zero
  48. MAXDISKSIZE    = 2000000    ;security -> max size file/device
  49.  
  50. ;##########################################################################
  51.  
  52. GL    EQUR    A4        ;a4 ptr to Globals
  53. LOC    EQUR    A5        ;a5 for local vars
  54. CPU    =    68000
  55.  
  56. Version     = 0
  57. Revision = 17
  58.  
  59.     PURE
  60.     OUTPUT    C:ITD
  61.  
  62.     IFND    .passchk
  63.     DOSCMD    "WDate >T:date"
  64. .passchk
  65.     ENDC
  66.  
  67. VER    MACRO
  68.         sprintx    "ITD %ld.%ld ",Version,Revision
  69.     INCBIN    "T:date"
  70.     ENDM
  71.  
  72.         bra    .start
  73.         dc.b    0,"$VER: "
  74.         VER
  75.         dc.b    0
  76.     EVEN
  77. .start
  78.  
  79. ;##########################################################################
  80.  
  81.         move.l    #gl_SIZEOF,d0
  82.         move.l    #MEMF_CLEAR,d1
  83.         move.l    (4).w,a6
  84.         jsr    (_LVOAllocMem,a6)
  85.         tst.l    d0
  86.         beq    .nostrucmem
  87.         move.l    d0,GL
  88.         move.l    a6,(gl_execbase,GL)
  89.         move.l    #20,(gl_rc,GL)
  90.  
  91.         move.l    #37,d0
  92.         lea    (_dosname),a1
  93.         move.l    (gl_execbase,GL),a6
  94.         jsr    _LVOOpenLibrary(a6)
  95.         move.l    d0,(gl_dosbase,GL)
  96.         beq    .nodoslib
  97.  
  98.         lea    (_ver),a0
  99.         bsr    _Print
  100.  
  101.         lea    (_defdev),a0
  102.         move.l    a0,(gl_rd_device,GL)
  103.  
  104.         lea    (_template),a0
  105.         move.l    a0,d1
  106.         lea    (gl_rdarray,GL),a0
  107.         move.l    a0,d2
  108.         moveq    #0,d3
  109.         move.l    (gl_dosbase,GL),a6
  110.         jsr    (_LVOReadArgs,a6)
  111.         move.l    d0,(gl_rdargs,GL)
  112.         bne    .argsok
  113.         lea    (_readargs),a0
  114.         bsr    _PrintErrorDOS
  115.         bra    .noargs
  116. .argsok
  117.         bsr    _Main
  118.  
  119.         move.l    (gl_rdargs,GL),d1
  120.         move.l    (gl_dosbase,GL),a6
  121.         jsr    (_LVOFreeArgs,a6)
  122. .noargs
  123.         move.l    (gl_dosbase,GL),a1
  124.         move.l    (gl_execbase,GL),a6
  125.         jsr    (_LVOCloseLibrary,a6)
  126. .nodoslib
  127.         move.l    (gl_rc,GL),d7
  128.  
  129.         move.l    #gl_SIZEOF,d0
  130.         move.l    GL,a1
  131.         move.l    (gl_execbase,GL),a6
  132.         jsr    (_LVOFreeMem,a6)
  133.  
  134.         move.l    d7,d0
  135.         rts
  136.  
  137. .nostrucmem    moveq    #20,d0
  138.         rts
  139.  
  140. ;##########################################################################
  141.  
  142.     INCDIR    Sources:
  143.     INCLUDE    dosio.i
  144.         PrintLn
  145.         PrintArgs
  146.         Print
  147.         CheckBreak
  148.     INCLUDE    files.i
  149.         LoadFileMsg
  150.     INCLUDE    devices.i
  151.         GetDeviceInfo
  152.     INCLUDE    error.i
  153.         PrintErrorTD
  154.  
  155. ;##########################################################################
  156.  
  157.     NSTRUCTURE    local_main,0
  158.         NSTRUCT    lm_di,devi_SIZEOF            ;DeviceInfo
  159.         NSTRUCT    lm_devname,DEVNAMELEN            ;devicename without ":"
  160.         NLABEL    lm_SIZEOF
  161.  
  162. _Main        link    LOC,#lm_SIZEOF
  163.  
  164.         move.l    (gl_rd_file,GL),a0
  165.         bsr    _LoadFileMsg
  166.         move.l    d0,d7                    ;D7 = file
  167.         beq    .nofile
  168.         move.l    d1,d6                    ;D6 = file length
  169.         beq    .nofile
  170.         
  171.         cmp.l    #MAXDISKSIZE,d6
  172.         blo    .fsizeok
  173.         lea    (_bigfsize),a0
  174.         bsr    _Print
  175.         bra    .bigfsize
  176. .fsizeok
  177.         move.l    (gl_rd_device,GL),a0
  178.         lea    (lm_devname,LOC),a1
  179.         moveq    #DEVNAMELEN-1,d0
  180. .c        move.b    (a0)+,(a1)+
  181.         dbeq    d0,.c
  182.         clr.b    -(a1)
  183.         move.b    -(a1),d0
  184.         cmp.b    #":",d0
  185.         bne    .1
  186.         clr.b    (a1)
  187. .1
  188.         lea    (lm_devname,LOC),a0
  189.         lea    (lm_di,LOC),a1
  190.         bsr    _GetDeviceInfo
  191.         tst.l    d0
  192.         beq    .nodevi
  193.  
  194.         lea    (_m_writedisk),a0
  195.         move.l    (lm_di+devi_Unit,LOC),-(a7)
  196.         pea    (lm_di+devi_Device,LOC)
  197.         pea    (lm_devname,LOC)
  198.         move.l    a7,a1
  199.         bsr    _PrintArgs
  200.         add.w    #12,a7
  201.  
  202.         move.l    (lm_di+devi_HighCyl,LOC),d0
  203.         sub.l    (lm_di+devi_LowCyl,LOC),d0
  204.         addq.l    #1,d0                    ;cylinders
  205.         move.l    (lm_di+devi_Surfaces,LOC),d1
  206.         mulu32    d1,d0                    ;tracks
  207.         move.l    (lm_di+devi_BlocksPerTrack,LOC),d1
  208.         mulu32    d1,d0                    ;blocks
  209.         move.l    (lm_di+devi_SizeBlock,LOC),d1
  210.         mulu32    d1,d0                    ;disksize
  211.         move.l    d0,d5                    ;D5 = disk size
  212.         
  213.         lea    (_m_diskgeo),a0
  214.         move.l    d5,-(a7)
  215.         move.l    (lm_di+devi_HighCyl,LOC),-(a7)
  216.         move.l    (lm_di+devi_LowCyl,LOC),-(a7)
  217.         move.l    (lm_di+devi_BlocksPerTrack,LOC),-(a7)
  218.         move.l    (lm_di+devi_Surfaces,LOC),-(a7)
  219.         move.l    (lm_di+devi_SizeBlock,LOC),-(a7)
  220.         move.l    a7,a1
  221.         bsr    _PrintArgs
  222.         add.w    #6*4,a7
  223.         
  224.         cmp.l    #MAXDISKSIZE,d5
  225.         blo    .dsizeok
  226.         lea    (_bigdsize),a0
  227.         bsr    _Print
  228.         bra    .bigdsize
  229. .dsizeok
  230.         cmp.l    d5,d6
  231.         beq    .equal
  232.         blo    .small
  233.         move.l    d5,d6
  234.         lea    (_tobig),a0
  235.         bra    .p
  236. .small        lea    (_tosmall),a0
  237. .p        bsr    _Print
  238. .equal
  239.         move.l    (gl_rd_device,GL),d1
  240.         moveq    #-1,d2
  241.         move.l    (gl_dosbase,GL),a6
  242.         jsr    (_LVOInhibit,a6)
  243.         
  244.         move.l    (gl_execbase,GL),a6            ;A6 = execbase !!!
  245.         jsr    (_LVOCreateMsgPort,a6)
  246.         move.l    d0,d4                    ;D4 = msgport
  247.         bne    .portok
  248.         moveq    #0,d0
  249.         lea    (_noport),a0
  250.         sub.l    a1,a1
  251.         bsr    _PrintError
  252.         bra    .noport
  253. .portok        
  254.         move.l    d4,a0
  255.         move.l    #IOTD_SIZE,d0
  256.         jsr    (_LVOCreateIORequest,a6)
  257.         move.l    d0,a2                    ;A2 = ioreq
  258.         tst.l    d0
  259.         bne    .ioreqok
  260.         moveq    #0,d0
  261.         lea    (_noioreq),a0
  262.         sub.l    a1,a1
  263.         bsr    _PrintError
  264.         bra    .noioreq
  265. .ioreqok
  266.         lea    (lm_di+devi_Device,LOC),a0
  267.         move.l    (lm_di+devi_Unit,LOC),d0
  268.         move.l    a2,a1                    ;ioreq
  269.         move.l    #0,d1                    ;flags
  270.     move.l    d3,-(a7)                ;BUG in fucking mfm.device
  271.         jsr    (_LVOOpenDevice,a6)
  272.     move.l    (a7)+,d3                ;BUG in fucking mfm.device
  273.         tst.l    d0
  274.         beq    .deviceok
  275.         move.b    (IO_ERROR,a2),d0
  276.         lea    (_opendevice),a0
  277.         bsr    _PrintErrorTD
  278.         bra    .nodevice
  279. .deviceok
  280.         move.l    a2,a1
  281.         move.w    #TD_CHANGENUM,(IO_COMMAND,a2)
  282.         jsr    (_LVODoIO,a6)
  283.         move.l    (IO_ACTUAL,a2),(IOTD_COUNT,a2)        ;the diskchanges
  284.  
  285.         move.l    (lm_di+devi_BlocksPerTrack,LOC),d5
  286.         move.l    (lm_di+devi_SizeBlock,LOC),d1
  287.         mulu32    d1,d5                    ;D5 = track size
  288.         
  289.         moveq    #0,d2                    ;D2 = actual track
  290.  
  291.         move.l    d6,d3
  292.         add.l    d5,d3
  293.         subq.l    #1,d3
  294.         divu    d5,d3
  295.         ext.l    d3                    ;D3 = tracks to write
  296.  
  297.         move.l    d7,(IO_DATA,a2)                ;buffer
  298.         clr.l    (IO_OFFSET,a2)                ;begin on disk (offset)
  299.         move.l    d5,(IO_LENGTH,a2)            ;bytes per track
  300.         
  301.         bsr    _PrintLn
  302. .loop        lea    (_diskprogress),a0            ;output progress
  303.         move.l    d3,-(a7)
  304.         subq.l    #1,(a7)
  305.         move.l    d2,-(a7)
  306.         move.l    a7,a1
  307.         bsr    _PrintArgs
  308.         addq.l    #8,a7
  309.         
  310.         bsr    _CheckBreak                ;check for CTRL-C
  311.         tst.l    d0
  312.         bne    .readbreak
  313.         
  314.         tst.l    (gl_rd_format,GL)
  315.         beq    .write
  316. .format
  317.         move.w    #ETD_FORMAT,(IO_COMMAND,a2)
  318.         move.l    a2,a1                    ;read one track
  319.         jsr    (_LVODoIO,a6)
  320.         move.b    (IO_ERROR,a2),d0
  321.         bne    .readerr
  322.         bra    .verify
  323. .write
  324.         move.w    #ETD_WRITE,(IO_COMMAND,a2)
  325.         move.l    a2,a1                    ;read one track
  326.         jsr    (_LVODoIO,a6)
  327.         move.b    (IO_ERROR,a2),d0
  328.         bne    .readerr
  329. .verify
  330.         addq.l    #1,d2
  331.         subq.l    #1,d3
  332.         beq    .readok
  333.         add.l    d5,(IO_OFFSET,a2)            ;begin on disk (offset)
  334.         add.l    d5,(IO_DATA,a2)                ;buffer
  335.         bra    .loop
  336.  
  337. .readok        clr.l    (gl_rc,GL)                ;success
  338.         bra    .update
  339.  
  340. .readerr    lea    (_writedisk),a0
  341.         bsr    _PrintErrorTD
  342. .readbreak
  343. .update
  344.         move.l    a2,a1
  345.         move.w    #ETD_UPDATE,(IO_COMMAND,a1)
  346.         jsr    (_LVODoIO,a6)
  347.  
  348.         move.l    a2,a1
  349.         move.l    #0,(IO_LENGTH,a1)
  350.         move.w    #ETD_MOTOR,(IO_COMMAND,a1)
  351.         jsr    (_LVODoIO,a6)
  352.  
  353.         move.l    a2,a1
  354.         jsr    (_LVOCloseDevice,a6)
  355. .nodevice
  356.         move.l    a2,a0
  357.         jsr    (_LVODeleteIORequest,a6)
  358. .noioreq
  359.         move.l    d4,a0
  360.         jsr    (_LVODeleteMsgPort,a6)
  361. .noport
  362.         move.l    (gl_rd_device,GL),d1
  363.         moveq    #0,d2
  364.         move.l    (gl_dosbase,GL),a6
  365.         jsr    (_LVOInhibit,a6)
  366. .bigdsize
  367. .nodevi
  368. .bigfsize
  369.         move.l    d7,a1
  370.         move.l    (gl_execbase,GL),a6
  371.         jsr    (_LVOFreeVec,a6)
  372.  
  373. .nofile        unlk    LOC
  374.         rts
  375.  
  376. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  377.  
  378. _defdev        dc.b    "DF0:",0
  379.  
  380. ;Messages
  381. _m_writedisk    dc.b    "write to ",155,"1m%s",155,"22m: (%s %ld)",10,0
  382. _m_diskgeo    dc.b    "(blksize=%ld heads=%ld blktrk=%ld lcyl=%ld hcyl=%ld) size=%ld",10,0
  383. _diskprogress    dc.b    11,"writing track %ld left %ld  ",10,0
  384.  
  385. ; Errors
  386. _nomem        dc.b    "not enough free store",0
  387. _noport        dc.b    "can't create MessagePort",0
  388. _noioreq    dc.b    "can't create IO-Request",0
  389. _nodev        dc.b    "device doesn't exist",0
  390. _baddev        dc.b    "cannot handle this device",0
  391. _bigfsize    dc.b    "file is to large",10,0
  392. _bigdsize    dc.b    "device is to large",10,0
  393. _tosmall    dc.b    "WARNING file is smaller than device",10,0
  394. _tobig        dc.b    "WARNING file is bigger than device",10,0
  395.  
  396. ; Operationen
  397. _readargs    dc.b    "read arguments",0
  398. _writedisk    dc.b    "write disk",0
  399. _getdevinfo    dc.b    "get dev info",0
  400. _opendevice    dc.b    "open device",0
  401.  
  402. ;subsystems
  403. _dosname    DOSNAME
  404.  
  405. _template    dc.b    "FILE/A"        ;file write to disk
  406.         dc.b    ",DEVICE"        ;name of device (default "DF0:)
  407.         dc.b    ",FORMAT/S"        ;format device
  408.     ;    dc.b    ",FORCE/S"        ;power !
  409.         dc.b    0
  410.  
  411. _ver        VER
  412.         dc.b    " ",155,"1mI",155,"22mmage ",155,"1mT",155,"22mo ",155,"1mD",155,"22misk by Bert Jahn"
  413.         dc.b    10,0
  414.  
  415. ;##########################################################################
  416.  
  417.     END
  418.  
  419.