em00k / NextBuild

NextBuild : A suite of tools based on Boriel's ZX Basic Compiler targetting the ZX Spectrum Next
60 stars 6 forks source link

Possible error in NextLib SaveSD method when file not exist #7

Closed Duefectu closed 3 years ago

Duefectu commented 3 years ago

In SaveSD method, after "fileopen" label loads b register with 158 ($9e), but this value isn't a valid, or at least documented value. In ZEsarUX emulator don't work if the file not exist.

fileopen:       

    ld b,158                    ; mode write
    ;db 33                      ; open 
    ;ld b,$0c
    push ix
    pop hl
;   ld a,42
    rst $08
    db $9a                      ; F_OPEN 
    ld (filehandle),a
    ret

Changing "ld b,158" by "ld b,$0e" works in ZEsarUX and CSpect emulators and in ZX-DOS+/GomaDOS+ devices.

fileopen:       

    ld b,$0e                    ; mode write
    ;db 33                      ; open 
    ;ld b,$0c
    push ix
    pop hl
;   ld a,42
    rst $08
    db $9a                      ; F_OPEN 
    ld (filehandle),a
    ret

Don't know if there is a hidden feature or really is a bug.

em00k commented 3 years ago

Thanks - $9e is write mode, but if this fixes zesaruxooo then I will commit the change. Thanks

em00k commented 3 years ago

updated.

chernandezba commented 3 years ago

This is not an issue with "zesaruxooo", it's a bug in your code

According to esxdos and nextzxos api:

F_OPEN ($9a)

B= access modes, a combination of:

any/all of: esx_mode_read $01 esx_mode_write $02 esx_mode_user_header $40

plus one of: esx_mode_open_exist $00 esx_mode_open_creat $08 esx_mode_creat_noexist $04 esx_mode_creat_trunc $0c

Your "ld b,158 (9EH)" does not match any of these modes combinations. Probably it's working on CSpect and real Next probably because they look only at bits of the value, not at the absolute value. But on ZEsarUX (using the esxdos handler, not on mmc emulation) I do look at the absolute value, to avoid mistakes and bugs like this

$9e is NOT a "write mode" for B register. You are confusing this B mode with the F_WRITE call ($9e)

Cheers

em00k commented 3 years ago

Thanks for that Cesar ;)

On Wed, 9 Dec 2020 at 13:40, Cesar Hernandez notifications@github.com wrote:

This is not an issue with "zesaruxooo", it's a bug in your code

According to esxdos and nextzxos api:

F_OPEN ($9a)

B= access modes, a combination of:

any/all of: esx_mode_read $01 esx_mode_write $02 esx_mode_user_header $40

plus one of: esx_mode_open_exist $00 esx_mode_open_creat $08 esx_mode_creat_noexist $04 esx_mode_creat_trunc $0c

Your "ld b,158 (9EH)" does not match any of these modes combinations. Probably it's working on CSpect and real Next probably because they look only at bits of the value, not at the absolute value. But on ZEsarUX (using the esxdos handler, not on mmc emulation) I do look at the absolute value, to avoid mistakes and bugs like this

$9e is NOT a "write mode" for B register. You are confusing this B mode with the F_WRITE call ($9e)

Cheers

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/em00k/NextBuild/issues/7#issuecomment-741777581, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFJNITANO3MKJCSCKSVIELDST546FANCNFSM4USSC7CA .

-- Cheers,

David

David Saphier david.saphier@gmail.com