home *** CD-ROM | disk | FTP | other *** search
/ Dream 44 / Amiga_Dream_44.iso / Amiga / workbench / pilotes / pcmcia / cnetdevice.lha / cnetdevice / src / cnetconfig.asm next >
Assembly Source File  |  1997-07-29  |  7KB  |  310 lines

  1. ;===========================================================================
  2. ;                             cnetconfig
  3. ;===========================================================================
  4. ;
  5. ;  creates config file for cnet.devcie (in s:cnetdev.config)
  6. ;
  7. ;  NOTE: The file "s:config.dev" is used by cnet.device ONLY if it cannot
  8. ;        detect PCMCIA attribute memory ie. if the card did NOT power up
  9. ;        properly. Therefore cnetconfig should only be run when the card
  10. ;        IS working properly, so that a valid configuration can be saved!
  11. ;
  12. ; History:
  13. ;
  14. ; 8-7-97  v0.0 created by Bruce Abbott  (bhabbott@inhb.co.nz)
  15. ;
  16. ;
  17.  
  18. VERSION  = 0
  19. REVISION = 0
  20.  
  21.  opt i+,d+
  22.  
  23.  output ram:cnetconfig
  24.  
  25.  
  26.  include start.i    ; Amiga includes and startup code
  27.  
  28.  include pcmcia.i             ; card.resourse etc.
  29.  include sanaii.i             ; the essential network stuff
  30.  include cnet.i               ; CNet CN40BC hardware specs
  31.  include printf.i
  32.  
  33.  
  34. ; flags
  35.  
  36. MYB_DEVOPENED = 0
  37. MYB_CONSOLE   = 1
  38.  
  39.  
  40. _main:
  41.    move.l  WBenchMsg(pc),d0
  42.    beq.s   .cli
  43.    lea     consolename(pc),a0
  44.    move.l  a0,d1
  45.    move.l  #MODE_NEWFILE,d2
  46.    dos     open                 ; open console window
  47.    move.l  d0,ohandle
  48.    bls     done
  49.    bset    #MYB_CONSOLE,flags
  50.    bra     .getdev
  51. .cli:
  52.    dos     output               ; get CLI output handle
  53.    move.l  d0,ohandle
  54.    beq     done
  55. .getdev:
  56.    move.l  execbase(pc),a3
  57.    move.l  devicelist(a3),a0
  58.    lea     devname(pc),a1
  59.    exec    findname             ; find device in exec resident list
  60.    move.l  d0,a2
  61.    tst.l   d0
  62.    bne     found
  63. notfound:
  64.    bsr     createport           ; create msgport for iorequest
  65.    move.l  d0,port
  66.    move.l  d0,a0
  67.    move.l  #IOS2_SIZE,d0
  68.    bsr     createio             ; create iorequest for opendev
  69.    move.l  d0,ior
  70.    move.l  ior(pc),a1
  71.    lea     devname(pc),a0
  72.    moveq   #0,d0
  73.    moveq   #0,d1
  74.    exec    opendevice           ; open "cnet.device" unit 0
  75.    tst.l   d0
  76.    beq.s   opened
  77.    move.l  ior(pc),a1
  78.    lea     fulldevname(pc),a0
  79.    moveq   #0,d0
  80.    moveq   #0,d1
  81.    exec    opendevice           ; open "devs:networks/cnet.device"
  82.    tst.l   d0
  83.    beq.s   opened
  84.    printf  <10,"Could not open '%s'!",10>,devname
  85.    bra     done
  86. opened:
  87.    bset    #MYB_DEVOPENED,flags
  88.    move.l  ior(pc),a1
  89.    move.l  io_device(a1),a2
  90. found:
  91.    move.l  dd_cardres(a2),a6
  92.    lea     dd_cardhandle(a2),a1
  93.    lea     tuple(pc),a0
  94.    moveq   #CISTPL_CONF_MAP,d1
  95.    moveq   #40,d0
  96.    jsr     _LVOCopyTuple(a6)            ; read config map tuple
  97.    tst.l   d0
  98.    beq     carderror
  99.    moveq   #0,d3
  100.    move.b  tuple+5(pc),d3
  101.    lsl.w   #8,d3
  102.    move.b  tuple+4(pc),d3
  103.    printf  <10,"Configuration Register = $%04lx",10>,d3
  104.    lea     dd_cardhandle(a2),a1
  105.    lea     tuple(pc),a0
  106.    moveq   #CISTPL_CONFIG,d1
  107.    moveq   #40,d0
  108.    jsr     _LVOCopyTuple(a6)            ; read 1st config tuple
  109.    tst.l   d0
  110.    beq     carderror
  111.    moveq   #0,d4
  112.    move.b  tuple+2(pc),d4
  113.    and.b   #$3f,d4
  114.    printf  <10,"Card Configuration ID  = $%02lx",10>,d4
  115.    move.l  dd_romstationaddress(a2),d5
  116.    moveq   #0,d6
  117.    move.w  dd_romstationaddress+4(a2),d6
  118.    printf  <10,"ROM Station Address    = %08lx%04lx",10,10>,d5,d6
  119.    lea     filename(pc),a0
  120.    move.l  a0,d1
  121.    move.l  #MODE_NEWFILE,d2
  122.    DOS     Open
  123.    tst.l   d0
  124.    ble     file_error
  125.    move.l  ohandle(pc),d7                ; remember console output handle
  126.    move.l  d0,ohandle
  127.    printf  <"$%04lx=$%02lx",10,"@%08lx%04lx",10>,d3,d4,d5,d6
  128.    move.l  ohandle(pc),d1
  129.    DOS     Close
  130.    move.l  d7,ohandle                    ; restore console output handle
  131.    lea     filename(pc),a0
  132.    printf  <10,"Created '%s'",10,10>,a0
  133.    bra     done
  134. file_error:
  135.    lea     filename(pc),a0
  136.    printf  <10,"Could NOT create '%s'!",10,10>,a0
  137.    bra     done
  138. carderror:
  139.    printf  <10,10,"Warning: Attribute memory NOT detected!",10,10>
  140.    move.l  dd_romstationaddress(a2),d4
  141.    moveq   #0,d5
  142.    move.w  dd_romstationaddress+4(a2),d5
  143.    printf  <"ROM Station Address  = %08lx%04lx",10,10>,d4,d5
  144.    move.l  dd_stationaddress(a2),d4
  145.    moveq   #0,d5
  146.    move.w  dd_stationaddress+4(a2),d5
  147.    printf  <"Station Address used = %08lx%04lx",10,10>,d4,d5
  148. done:
  149.    btst    #MYB_DEVOPENED,flags(pc)
  150.    beq.s   .devclosed
  151.    move.l  ior(pc),a1
  152.    exec    closedevice                   ; close device
  153. .devclosed:
  154.    move.l  ior(pc),a0
  155.    move.l  #IOS2_SIZE,d0
  156.    bsr     deleteio                      ; delete iorequest
  157.    move.l  port(pc),a0
  158.    bsr     deleteport                    ; delete msgport
  159.    btst    #MYB_CONSOLE,flags(pc)
  160.    beq.s   .noconsole
  161.    move.l  #50*10,d1                     ; wait 10 seconds
  162.    dos     delay
  163.    move.l  ohandle(pc),d1
  164.    dos     close                         ; close console window
  165. .noconsole:
  166.    moveq   #0,d0
  167.    rts
  168.  
  169. ;***********************************
  170. ;*  Create Signalling Message Port *
  171. ;***********************************
  172. ;
  173. ; Port = CreatePort()
  174. ;  d0
  175. ;
  176. CreatePort:
  177.   movem.l d2/a2,-(sp)
  178.   moveq.l #-1,d0
  179.   exec    AllocSignal
  180.   move.l  d0,d2
  181.   bmi.s   .error
  182.  
  183.   move.b  d0,d2
  184.   moveq.l #MP_SIZE,d0
  185.   move.l  #MEMF_PUBLIC|MEMF_CLEAR,d1
  186.   exec    AllocMem
  187.   move.l  d0,a2
  188.   beq.s   .error
  189.  
  190.   sub.l   a1,a1
  191.   exec    FindTask
  192.  
  193.   move.l  d0,MP_SIGTASK(a2)
  194.   move.b  d2,MP_SIGBIT(a2)
  195.   move.b  #NT_MSGPORT,LN_TYPE(a2)
  196.   move.b  #PA_SIGNAL,MP_FLAGS(a2)
  197.   lea     MP_MSGLIST(a2),a1
  198.  
  199.   move.l  a1,lh_head(a1)              ;Newlist a1
  200.   addq.l  #4,lh_head(a1)
  201.   clr.l   lh_tail(a1)
  202.   move.l  a1,lh_tailpred(a1)
  203.   move.l  a2,d0                       ; D0 = port
  204.   bra.s   .done
  205. .error:
  206.   move.l  a2,a1
  207.   bsr.s   DeletePort
  208.   moveq   #0,d0
  209. .done:
  210.   movem.l (sp)+,d2/a2
  211.   rts
  212.  
  213.  
  214. ;***************************
  215. ;*   Delete Message Port   *
  216. ;***************************
  217. ; DeletePort(port)
  218. ;             a0
  219. ;
  220. DeletePort:
  221.   move.l  a2,-(sp)
  222.   move.l  a0,d0
  223.   beq.s   .done
  224.   move.l  d0,a1
  225.   moveq   #0,d0
  226.   move.b  MP_SIGBIT(a1),d0
  227.   bmi.s   .nosignal
  228.   move.l  a1,a2
  229.   exec    FreeSignal
  230.   move.l  a2,a1
  231. .nosignal:
  232.   moveq   #MP_SIZE,d0
  233.   exec    FreeMem
  234. .done:
  235.   move.l (sp)+,a2
  236.   rts
  237.  
  238.  
  239.  
  240. ;********************************
  241. ;*     Create IORequest         *
  242. ;********************************
  243. ;
  244. ; ioreq = CreateIO(port,size)
  245. ;  d0               a0   d0
  246. ;
  247. CreateIO:
  248.   movem.l d2/a2,-(sp)
  249.   move.l  a0,a2
  250.   move.l  d0,d2
  251.   move.l  #MEMF_PUBLIC|MEMF_CLEAR,d1
  252.   exec    AllocMem
  253.   tst.l   d0
  254.   beq.s   .done
  255.   move.l  d0,a0
  256.   move.l  a2,MN_REPLYPORT(a0)
  257.   move.b  #NT_MESSAGE,LN_TYPE(a0)
  258.   move.w  d2,MN_LENGTH(a0)
  259. .done:
  260.   movem.l (sp)+,d2/a2
  261.   rts
  262.  
  263.  
  264. ;*********************
  265. ;* Delete IO Request *
  266. ;*********************
  267. ;  DeleteIO(ioreq,size)
  268. ;             a0   d0
  269. ;
  270. DeleteIO:
  271.   move.l  a0,d1
  272.   beq.s   .done
  273.   move.l  d1,a1
  274.   exec    FreeMem
  275. .done:
  276.   rts
  277.  
  278. port:
  279.   dc.l 0
  280.  
  281. ior:
  282.   dc.l 0
  283.  
  284. tuple:
  285.   ds.b   48         ; buffer to read tuple into
  286.  
  287. flags:
  288.   dc.b   0
  289.   even
  290.  
  291. fulldevname:
  292.  dc.b "devs:networks/"
  293. devname:
  294.  dc.b "cnet.device",0
  295.  even
  296.  
  297. filename:
  298.  dc.b  "s:cnetdev.config",0
  299.  even
  300.  
  301. consolename:
  302.  dc.b  "CON:60/60/480/120/ cnetconfig ",0
  303.  even
  304.  
  305.  dc.b    "$VER: cnetconfig "
  306.  dc.b    (VERSION+"0"),".",(REVISION+"0")," "
  307.  dc.b    __DATE
  308.  dc.b    " by Bruce Abbott (bhabbott@inhb.co.nz)",10,0
  309.  even
  310.