home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 508.lha / IO_Expansion_Board / loadprefs / loadprefs.asm < prev   
Assembly Source File  |  1991-05-06  |  2KB  |  119 lines

  1. ;loadprefs.asm - loads prefs into memory
  2. ;place in startup sequence
  3. ;by Dan Babcock, March 1991
  4.  
  5.     exeobj
  6.     objfile    'loadprefs'
  7.  
  8.     move.l    (4).w,a6
  9.     moveq    #0,d7
  10.  
  11.     lea    (MagicPortName,pc),a1
  12.     SYS    FindPort
  13.     move.l    d0,a4
  14.     tst.l    d0
  15.     beq.b    .NotFound
  16.     moveq    #1,d7
  17.     bra.b    .PortFound
  18.  
  19. .NotFound:
  20.     move.l    #MEMF_CLEAR+MEMF_PUBLIC,d1
  21.     move.l    #MP_SIZE+32+PortNameLength,d0
  22.     SYS    AllocMem
  23.     tst.l    d0
  24.     beq.b    Error
  25.     move.l    d0,a4
  26.  
  27. ;Copy name string
  28.     lea    (MP_SIZE+32,a4),a3
  29.     move.l    a3,a0
  30.     lea    (MagicPortName,pc),a1
  31.     move.w    #PortNameLength-1,d0
  32. ..    move.b    (a1)+,(a0)+
  33.     dbra    d0,..
  34.  
  35. .PortFound:
  36.     lea    (DosName,pc),a1
  37.     SYS    OldOpenLibrary
  38.     move.l    d0,a6
  39.     move.l    #MODE_OLDFILE,d2
  40.     move.l    #FileName,d1
  41.     SYS    Open
  42.     tst.l    d0
  43.     beq.b    Error
  44.     move.l    d0,a5    ;file handle
  45.     move.l    a5,d1
  46.     move.l    a4,d2
  47.     add.l    #MP_SIZE,d2
  48.     moveq    #32,d3
  49.     SYS    Read
  50.     tst.l    d0
  51.     bmi    Error
  52.  
  53.     move.l    a5,d1
  54.     SYS    Close
  55.  
  56.     move.l    a6,a5
  57.     move.l    (4).w,a6
  58.     tst.l    d7
  59.     bne.b    .CloseUp
  60.     move.l    a3,(LN_NAME,a4)
  61.     move.l    a4,a1
  62.     SYS    AddPort
  63.  
  64. .CloseUp:
  65.     move.l    a5,a1
  66.     SYS    CloseLibrary
  67.     moveq    #0,d0
  68.     rts
  69.  
  70. Error:
  71.     lea    (WrongMsg,pc),a0
  72.     bsr.b    Print
  73.     moveq    #100,d0
  74.     rts
  75.  
  76. Print:
  77. ;Output a string to the CLI
  78. ;Enter with pointer to a zero-terminated string in a0
  79. ;All registers are preserved
  80.  
  81.     movem.l    d0-d7/a0-a6,-(sp)
  82.     movea.l    a0,a5
  83.     movea.l    (4).w,a6
  84.     lea    (DosName,pc),a1
  85.     SYS    OldOpenLibrary
  86.     tst.l    d0
  87.     beq.b    .PrintEnd
  88.     movea.l    d0,a6
  89.     movea.l    a5,a0
  90.     movea.l    a5,a4
  91. .PrintLine:
  92.     tst.b    (a5)+
  93.     bne.b    .PrintLine
  94.     subq.l    #1,a5
  95.     suba.l    a0,a5
  96.     SYS    Output
  97.     move.l    d0,d1  
  98.     move.l    a4,d2
  99.     move.l    a5,d3
  100.     SYS    Write
  101.     movea.l    a6,a1
  102.     movea.l    (4).w,a6
  103.     SYS    CloseLibrary
  104. .PrintEnd:
  105.     movem.l    (sp)+,d0-d7/a0-a6
  106.     rts
  107.  
  108. MagicPortName:    dc.b    'newser_prefs',0
  109. PortNameLength    equ    *-MagicPortName
  110.     even
  111. FileName:    dc.b    's:serial-preferences',0
  112.     even
  113. WrongMsg:    dc.b    'Couldn''t load s:serial-preferences !',$a,0
  114.     even
  115. DosName:    dc.b    'dos.library',0
  116.     even
  117.  
  118.     END
  119.