Accès fichier via gemdos

Accès fichier via gemdos

Messagede sporniket » Lun 22 Juin 2009 21:34

Pour compléter la réponse de lp060 à mon problème, j'ai complété son squelette de code avec les appels GEMDOS adequat, et rajouté un peu de doc. (bon en fait, j'ai nommé les fonction d'après leur nom gemdos (? ou c ?))

Code: Tout sélectionner
'########################################################
'!BEGIN package stdio__
'
'Encapsulate Gemdos calls to reproduce the file stdio calls.
'
'=== Reminder : error codes ===
'-34 : file (file path ?) not found
'-35 : too much opened files
'-36 : access denied
'-37 : incorrect handle.
'
'(c)David SPORN
'--------------------------------------------------------
'
'**
'* Create file.
'*
'* @param filepath
'*        path to the file to create
'*
'* @param mode
'*        bitmap
'*        bit 0 : read only
'*        bit 1 : hidden file
'*        bit 2 : system file
'*        bit 3 : floppy name
'*
'* @return
'*        error code : -34, -35, -36
'*        otherwise  : success
'*
'* @see GEMDOS 60
'**
function stdio__fcreate(filepath$, mode%)
    local c_filepath$
    c_filepath$ = filepath$ + chr$(0)
    return gemdos(60, L:(v:c_filepath$), W:mode%)
endfunc
'
'--------------------------------------------------------
'
'**
'* Open file.
'*
'* @param filepath
'*        path to the file to open
'*
'* @param mode
'*        0 : read only
'*        1 : write only
'*        2 : read and write
'*
'* @return
'*        error code : -34, -35, -36
'*        otherwise  : file handle
'*
'* @see GEMDOS 61
'**
function stdio__fopen(filepath$, mode%)
    local c_filepath$
    c_filepath$ = filepath$ + chr$(0)
    return gemdos(61, L:(v:c_filepath$), W:mode%)
endfunc
'
'--------------------------------------------------------
'
'**
'* Close file.
'*
'* @param file
'*        file handle
'*
'* @return
'*        error code : -37
'*        otherwise  : 0 ?
'*
'* @see GEMDOS 62
'**
function stdio__fclose(file%)
    return gemdos(62, W:file%)
endfunc
'
'
'--------------------------------------------------------
'
'**
'* Set the position in the file.
'*
'* @param file
'*        file handle
'*
'* @param mode
'*        0 : starting from the start
'*        1 : starting offset from the current position
'*        2 : starting offset from the end
'*
'* @param offset
'*        number of byte to skip
'*
'* @return
'*        error code : -32 or -37
'*        otherwise  : >0 ?
'*
'* @see GEMDOS 62
'**
function stdio__fseek(file%, mode&, offset%)
    return gemdos(66, L:offset%, W:file%, W:mode&)
endfunc
'
'--------------------------------------------------------
'
'**
'* Try to read a byte sequence.
'*
'* @param file
'*        file handle
'*
'* @param length
'*        number of byte to read
'*
'* @param buffer
'*        address of a memory buffer in which read bytes
'*        will be stored. (length should not exceed the
'*        buffer size !)
'*
'* @return
'*        error code : -37
'*        otherwise  : number of byte read (<= length)
'*
'* @see GEMDOS 63
'**
function stdio__fread(file%, length%, buffer%)
    return gemdos(63, W:file%, L:length%, L:buffer%)
endfunc
'
'--------------------------------------------------------
'
'**
'* Try to write a byte sequence.
'*
'* @param file
'*        file handle
'*
'* @param length
'*        number of byte to write
'*
'* @param buffer
'*        address of a memory buffer containing the byte
'*        sequence to write.
'*
'* @return
'*        error code : -36, -37
'*        otherwise  : number of byte written (<= length)
'*
'* @see GEMDOS 64
'**
function stdio__fwrite(file%, length%, buffer%)
    return gemdos(64, W:file%, L:length%, L:buffer%)
endfunc
'
'--------------------------------------------------------
'--------------------------------------------------------
'!END package stdio__
'########################################################
Dernière édition par sporniket le Mer 5 Aoû 2009 00:45, édité 1 fois.
----
Fonte Sporniket Nostalgie Sans v9.08
Sporniket

Busy coding... lib gfx−60% ; streams−34%
Avatar de l’utilisateur
sporniket
 
Messages: 112
Inscription: Dim 23 Nov 2008 23:00
Localisation: paris

Re: Accès fichier via gemdos

Messagede sporniket » Dim 12 Juil 2009 16:53

J'ai corrigé le code, la référence du fichier doit être transmise en tant que mot (W:value%) au lieu de mot long (L:value%).
----
Fonte Sporniket Nostalgie Sans v9.08
Sporniket

Busy coding... lib gfx−60% ; streams−34%
Avatar de l’utilisateur
sporniket
 
Messages: 112
Inscription: Dim 23 Nov 2008 23:00
Localisation: paris

Re: Accès fichier via gemdos

Messagede sporniket » Mer 5 Aoû 2009 00:46

Rajout de la fonction fcreate (gemdos 60)
----
Fonte Sporniket Nostalgie Sans v9.08
Sporniket

Busy coding... lib gfx−60% ; streams−34%
Avatar de l’utilisateur
sporniket
 
Messages: 112
Inscription: Dim 23 Nov 2008 23:00
Localisation: paris


Retourner vers Programmation GEM/Aranym

Qui est en ligne

Utilisateurs parcourant ce forum: Aucun utilisateur enregistré et 1 invité

cron