home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI03.ARJ / ictari.03 / ASSEMBLY / FILES.S next >
Text File  |  1989-04-06  |  2KB  |  69 lines

  1. ;
  2. ; Loading and saving files using GEMDOS
  3. ; (c)1993 Glenn Edwards
  4. ;
  5. ; From studying this source code, you should be able to work out how
  6. ; to load and save (read and write) files in 68000.
  7. ;
  8. ; Notes: File handles are used by GEMDOS to keep track of files which
  9. ; are open. You should store handles returned to you by the f_open
  10. ; function, so that you can refer to the files later on.
  11. ;
  12. ; *** If you are using Devpac 1 then delete the line 'section bss' ***
  13. ;
  14.  
  15.     opt    o+
  16.  
  17. _read    equ    0
  18. _write    equ    1
  19. _rd_wr    equ    2
  20.  
  21. start    movem.l    d0-d7/a0-a6,-(sp)    ;Store registers
  22.     moveq.w    #_rd_wr,d0
  23.     bsr.s    open            ;Open file for read/write
  24.     bmi.s    exit            ;If error, then exit
  25.     
  26.     bsr.s    read            ;Read from file
  27.  
  28.     bsr.s    close            ;Close file
  29.     movem.l    (sp)+,d0-d7/a0-a6    ;Restore registers
  30. exit    clr.w    -(sp)            ;Exit to desktop
  31.     trap    #1
  32.  
  33. open    move.w    d0,-(sp)        ;mode passed in d0
  34.     pea    fname(pc)        ;filename address
  35.     move.w    #$3d,-(sp)        ;GEMDOS f_open
  36.     trap    #1
  37.     addq.l    #8,sp
  38.     move.w    d0,handle        ;Store file handle
  39.     rts
  40.  
  41. close    move.w    handle(pc),-(sp)    ;File handle
  42.     move.w    #$3e,-(sp)        ;GEMDOS f_close
  43.     trap    #1
  44.     addq.l    #4,sp
  45.     rts
  46.  
  47. read    pea    buffer(pc)        ;Buffer address
  48.     move.l    #150,-(sp)        ;Number of bytes = 150
  49.     move.w    handle(pc),-(sp)    ;File handle
  50.     move.w    #$3f,-(sp)        ;GEMDOS f_read
  51.     trap    #1
  52.     lea    12(sp),sp
  53.     rts
  54.  
  55. write    pea    buffer(pc)        ;Buffer address
  56.     move.l    #150,-(sp)        ;Number of bytes = 150
  57.     move.w    handle(pc),-(sp)    ;File handle
  58.     move.w    #$40,-(sp)        ;GEMDOS f_write
  59.     trap    #1
  60.     lea    12(sp),sp
  61.     rts
  62.  
  63. fname    dc.b    'b:\tips.txt',0        ;Filename
  64.  
  65.     even
  66.  
  67.     section    bss
  68. handle    ds.w    1            ;Storage for file handle
  69. buffer    ds.b    10000            ;Read/write buffer