home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 13 / AACD13.ISO / AACD / System / ScalosPrefs / examples / ASM / multiple.s < prev    next >
Text File  |  1980-08-02  |  6KB  |  229 lines

  1. ;APS00000000000000000000000000000000000000000000000000000000000000000000000000000000
  2. ; Simple example of multiple data items per tag
  3.  
  4.     incdir    include:
  5.     include    exec/types.i
  6.     include    lvo/dos_lib.i
  7.     include    lvo/exec_lib.i
  8.     include    lvo/preferences_lib.i
  9.     include    libraries/iffparse.i
  10.     include    scalos/preferences.i
  11.  
  12.  
  13. start:    movem.l    d1-d7/a0-a6,-(a7)
  14.     move.l    4.w,a6            ; Get pointer to execbase
  15.  
  16.     lea    doslibname(pc),a1    ; SPRPTR "dos.library" -> a1
  17.     moveq.l    #36,d0            ; 36 (version to open) -> d0
  18.     jsr    _LVOOpenLibrary(a6)    ; Open dos.library
  19.     move.l    d0,dosbase        ; store/check pointer to dos.library base
  20.     beq    .nodoslib        ; if NULL, branch to end of program
  21.     
  22.     lea    prefslibname(pc),a1    ; STRPTR "preferences.library" -> a1
  23.     moveq.l    #39,d0            ; 39 (version to open) -> d0
  24.     jsr    _LVOOpenLibrary(a6)    ; Open preferences.library
  25.     move.l    d0,prefsbase        ; store/check pointer to prefsbase
  26.     beq    .noprefslib        ; if NULL, branch to end of program
  27.  
  28. ;    First we need to allocate a PrefsHandle by name
  29.     move.l    d0,a6            ; pointer to prefsbase
  30.     lea    prefname(pc),a0        ; Get name to refer to this PrefsHandle -> a1
  31.     jsr    _LVOAllocPrefsHandle(a6); try to allocate preferences handle
  32.     move.l    d0,prefhandle        ; store/check pointer to PrefsHandle
  33.     beq    .noph            ; if NULL, wasn't allocated so quit
  34.  
  35.     move.l    dosbase(pc),a6        ; dos.library base -> a6
  36.     move.l    #phallocok,d1        ; pointer to string -> d1
  37.     jsr    _LVOPutStr(a6)        ; print string to CLI (just to say we allocated PrefsHandle OK)
  38.  
  39. ;    We need an ID and a Tag value to refer to a specific preference item
  40. ;    Remember that the ID must be made from 4 ASCII characters and the Tag
  41. ;    value must not be 0
  42.     move.l    #'MAIN',d6        ; Set the ID (stored in d6) to 4 char ascii string "MAIN"
  43.     moveq.l    #2,d7            ; Set the Tag to 2 (imaginative, huh? ;)
  44.  
  45.  
  46.     moveq.l    #0,d5            ; Set the current entry number to 0
  47. .loop:                    ; loop to allow user to enter strings of data as the preference data
  48.     move.l    dosbase(pc),a6        ; Print a prompt for the user
  49.     move.l    #str_prompt,d1
  50.     jsr    _LVOPutStr(a6)
  51.  
  52.     move.l    #255,d0            ; Get a string from the user
  53.     lea    temp(pc),a0
  54.     jsr    gets
  55.  
  56.  
  57.     lea    temp(pc),a0        ; check length of string. if 0 we
  58.     jsr    strlen            ; want to quit this loop
  59.     tst.l    d0
  60.     beq    .nostr
  61.  
  62.     addq.l    #1,d0            ; increase length of string by 1 so we store the NULL terminator
  63.     move.l    d0,d2            ; size of buffer to store into d2
  64.     move.l    d6,d0            ; ID
  65.     move.l    d7,d1            ; Tag
  66.     lea    temp(pc),a1        ; buffer to store
  67.     move.l    prefhandle(pc),a0    ; PrefsHandle
  68.     move.l    prefsbase(pc),a6    ; prefsbase
  69.     move.l    d5,d3            ; entry number
  70.     jsr    _LVOSetEntry(a6)    ; SetEntry
  71.  
  72.     addq.l    #1,d5            ; increase entry number
  73.     bra    .loop
  74. .nostr:    
  75.  
  76.  
  77. ;    Now we will show each data item in turn as well as removing it,
  78. ;    this means we do not need to play around with entry numbers here
  79. .loop2:    move.l    prefsbase(pc),a6
  80.     move.l    d6,d0            ; ID
  81.     move.l    d7,d1            ; Tag
  82.     move.l    #255,d2
  83.     moveq.l    #0,d3    
  84.     move.l    prefhandle(pc),a0
  85.     lea    temp(pc),a1
  86.     jsr    _LVOGetEntry(a6)
  87.     tst.l    d0
  88.     beq    .endloop2
  89.  
  90.  
  91. ;    Print some info and the contents of what was retrieved
  92.     move.l    dosbase(pc),a6
  93.     move.l    #str_retreive,d1
  94.     jsr    _LVOPutStr(a6)
  95.     move.l    #temp,d1
  96.     jsr    _LVOPutStr(a6)
  97.     move.l    #str_newline,d1
  98.     jsr    _LVOPutStr(a6)
  99.  
  100.     
  101. ;    Remove the entry from the list and print a message to indicate success or failure
  102.     move.l    prefsbase(pc),a6
  103.     move.l    d6,d0
  104.     move.l    d7,d1
  105.     moveq.l    #0,d2
  106.     move.l    prefhandle(pc),a0
  107.     jsr    _LVORemEntry(a6)
  108.     tst.l    d0
  109.     beq    .remfailed
  110.  
  111.     move.l    dosbase(pc),a6
  112.     move.l    #str_removed,d1
  113.     jsr    _LVOPutStr(a6)
  114.     bra    .loop2
  115. .remfailed:
  116.     move.l    dosbase(pc),a6
  117.     move.l    #str_notremoved,d1
  118.     jsr    _LVOPutStr(a6)
  119.     bra    .loop2
  120.  
  121. .endloop2:
  122.  
  123. ;    Finally we free the PrefsHandle when we no longer need it
  124.     move.l    prefsbase(pc),a6    ; prefsbase pointer -> a6
  125.     move.l    prefhandle(pc),a0    ; PrefsHandle pointer -> a0
  126.     jsr    _LVOFreePrefsHandle(a6)    ; Free preferences handle
  127.  
  128. .noph:
  129.     move.l    4.w,a6            ; execbase pointer -> a6
  130.     move.l    prefsbase(pc),a1    ; prefsbase pointer -> a1
  131.     jsr    _LVOCloseLibrary(a6)    ; close preferences.library
  132.  
  133. .noprefslib:
  134.     move.l    dosbase(pc),a1        ; pointer to dos.library base -> a1
  135.     jsr    _LVOCloseLibrary(a6)    ; close dos.library
  136.  
  137. .nodoslib:    
  138.     movem.l    (a7)+,d1-d7/a0-a6
  139.     moveq.l    #0,d0
  140.     rts
  141.     
  142.  
  143. ; Length of string
  144. ; a0 = STRPTR
  145. strlen:
  146.     moveq.l    #0,d0        ; clear count of length of string
  147. .loop:    tst.b    (a0)+        ; check char in string for NULL and move onto next
  148.     beq    .endloop    ; if NULL, skip to end of loop
  149.     addq.l    #1,d0        ; otherwise increase length of string
  150.     bra    .loop        ; repeat loop
  151. .endloop:
  152.     rts
  153.  
  154.  
  155. ; C-like sprintf (from autodocs)
  156. ; parameters on stack from right to left
  157. ; (except the data items, they are on from left to right)
  158. ; output, format [, data]
  159. sprintf:
  160.     movem.l    a2/a3/a6,-(a7)
  161.  
  162.     move.l    16(a7),a3
  163.     move.l    20(a7),a0
  164.     lea    24(a7),a1
  165.     lea    stuffChar(pc),a2
  166.     move.l    4.w,a6
  167.     jsr    _LVORawDoFmt(a6)
  168.  
  169.     movem.l    (a7)+,a2/a3/a6
  170.     rts
  171.  
  172. stuffChar:
  173.     move.b    d0,(a3)+
  174.     rts
  175.     
  176.  
  177. ; gets() like function which uses dos.library FGets but strips the newline (if present)
  178. ; from the current input stream rather than a file
  179. ; a0 = buffer
  180. ; d0 = buffer size
  181. gets:
  182.     movem.l    d3/a2,-(a7)
  183.     move.l    d0,d3
  184.     move.l    a0,a2
  185.  
  186.     move.l    dosbase(pc),a6
  187.     jsr    _LVOOutput(a6)
  188.     move.l    d0,d1
  189.     jsr    _LVOFlush(a6)
  190.     jsr    _LVOInput(a6)
  191.     move.l    d0,d1
  192.     jsr    _LVOFlush(a6)
  193.     jsr    _LVOInput(a6)
  194.  
  195.     move.l    d0,d1
  196.     move.l    a2,d2
  197.     jsr    _LVOFGets(a6)
  198.     tst.l    d0
  199.     beq    .error
  200.  
  201. .loop:    move.b    (a2)+,d0
  202.     beq    .error
  203.     cmp.b    #10,d0
  204.     bne    .loop
  205.     move.b    #0,-(a2)
  206.     
  207. .error:    
  208.     movem.l    (a7)+,d3/a2
  209.     rts
  210.  
  211. ; Storage space for variables/strings etc
  212. ;execbase:    dc.l    0    ; exec.library base
  213. dosbase:    dc.l    0    ; dos.library base
  214. prefsbase:    dc.l    0    ; Pointer to preferences.library base
  215.  
  216. prefhandle:    dc.l    0    ; Pointer to our PrefsHandle
  217. temp:        ds.b    256    ; Temporary area for storing preferences and working with strings
  218.  
  219. doslibname:    dc.b    "dos.library",0
  220. prefslibname:    dc.b    "preferences.library",0
  221. prefname:    dc.b    "Example",0        
  222. phallocok:    dc.b    "PrefsHandle allocated OK",10,0
  223. str_prompt:    dc.b    "Enter a string or leave blank to quit and press return:",10,0
  224. str_retreive:    dc.b    "Retreived: ",0
  225. str_removed:    dc.b    "Entry removed",10,0
  226. str_notremoved:    dc.b    "Entry NOT removed",10,0
  227. str_newline:    dc.b    10,0
  228.         cnop    0,4
  229.