Skip to Content
Amiga Assembly Library v41.21 — Motorola 68020 shared library for Commodore Amiga

Save

Synopsis

len = Save(filename, buffer, len) D0 A0 A1 D0

C Prototype

ULONG Save(STRPTR filename, APTR buffer, ULONG len);

Description

Opens an output channel to a device. It operates in the inverse manner of Load().

This command was designed for writing a file to disk, but its output can be redirected to any available peripheral (device).

The file is opened in MODE_READWRITE, so if the filename already exists on the device, it will be overwritten without any warning. The responsibility of checking for the pre-existence of the file is left to the task; CheckFile() can be used for this purpose.

Inputs

  • filename — Address of a string containing the name of the file to write. This can be preceded by RAM:, PRT:, CON:, etc.
  • buffer — Pointer to the data buffer. This is the data that will be written to the device.
  • len — Number of bytes to transfer to the device. This parameter can be NULL when the buffer was acquired via Load() and Load() was responsible for allocating the buffer. Only in this case can len be NULL; otherwise it must be specified.

Result

  • len — Number of bytes written. If NULL, an error occurred.

Example

/* Load and Save example.c */ APTR mybuffer = Load("Work:page.txt", NULL, MEMF_PUBLIC); /* Your READ or WRITE operation */ ULONG len = Save("Work:page.txt", mybuffer, NULL);

See Also

CheckFile, Load

Implementation

The original 68020 assembly implementation:

; (15-Feb-1995) --- Save(filename,buffer,len) (a0/a1/d0) _LVOSave movem.l d2-d4/a2/a6,-(sp) move.l a1,a2 ; Save Pointer to buffer move.l d0,d3 ; Save byte len... move.l ab_DosBase(a6),a6 move.l a0,d1 lea MODE_READWRITE.W,a0 move.l a0,d2 jsr _LVOOpen(a6) tst.l d0 beq.s NSSEXIT move.l d0,d4 ; Save BCPL handle tst.l d3 bne.s UseThis move.l -4(a2),d3 ; byte TOT subq.l #4,d3 ; byte data to write UseThis move.l d4,d1 ; handle move.l a2,d2 jsr _LVOWrite(a6) move.l d4,d1 jsr _LVOClose(a6) move.l d3,d0 NSSEXIT movem.l (sp)+,d2-d4/a2/a6 rts
Last updated on