News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Saving data to disc in assembler

Started by santi.ontanon, 03:35, 06 October 24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

santi.ontanon

Hi, I have been playing with saving data to disc using the BIOS routines, and I am struggling to understand what am I doing wrong:
- I have a program that seems to save the file to disc (and I can verify that with a similar program I can load it back). But...
- In some situations, even if I can save the file to disc and load it again, if I quit the emulator (I am using RVM 2.0) and open it again (or if I eject the disc in the emulator and insert it again), the disc is now unreadable. 
- This does not always happen, but I can easily trigger it happening (e.g., if I artificially insert 0s at the end of my program to make it bigger. The program saves my file in track 3 (instead of track 2, which is still empty), and this seems to mess the header up.
- I have been trying to figure out if it is me who is doing something wrong (most likely), or if it is RVM which is messing up generating the dsk file and loading it again.
- I am using RVM, as I am not on Windows, and that's an emulator that I can use and is recently updated. Any other emulator you'd recommend? (I come from the MSX world, and I am not 100% familiar with all the CPC emulators hehe).

In any case, here is a minimal example of what I am trying to do, in case it helps. Any pointer/idea is greatly appreciated!

cas_noisy:          equ #bc6b
cas_out_open:       equ #bc8c
cas_out_close:      equ #bc8f
cas_out_direct:     equ #bc98
kl_rom_walk:        equ #bccb

ams_dos_work_ram_ptr:   equ #be7d


;---------------------------------------------------------------------------
    org #4000

;------------------------------------------------------------------------
    ; store the drive number the loader was run from
    ld hl, (ams_dos_work_ram_ptr)
    ld a, (hl)
    ld (drive + 1), a  ; self-modifying code
    call kl_rom_walk  ; enable all roms
drive:
    ld a, 0
    ld hl, (ams_dos_work_ram_ptr)
    ld (hl), a

    ld a, #ff
    call cas_noisy  ; disable error messages

    ; copy data to the place where we want it to be loaded again:
    ld hl, data
    ld de, #9f00
    ld bc, data_end - data
    ldir

    ld b, filename_end - filename
    ld hl, filename
    ld ix, #9f00
    ld de, data_end - data
    call save_block

loop:
    jp loop


;------------------------------------------------------------------------
; input:
; - b: length of filename
; - hl: address of filename
; output:
; - carry: success
; - no carry: error
save_block:
    push ix
    push de
        ld de, #c000  ; temporary buffer
        call cas_out_open
    pop de
    pop hl
    ret nc  ; error
    ld b, h
    ld c, l
    ld a, 2  ; binary data
    call cas_out_direct
    ret nc
    jp cas_out_close 


;------------------------------------------------------------------------
filename:
    db "data2.bin"
filename_end:

data:
    db "writtendata", 0, 1, 2, 3, 4, 5, 6, 7
data_end:

trocoloco

#1
Hi Santi. I've done a quick test on Winape and ACE-DL saves and reads fine the file created, switching off and on on varoius ocassions, I have created DSK file using ManageDSK, no problem here.
I recommend you @roudoudou' ACE-DLs and CNGSoft's CPCEC, great emulators, recent and multi-platform also  :)



santi.ontanon

Thank you very much trocoloco!! I was able to get both emulators running, and I have been playing with ACE-DL, and indeed it all works fine! So, it must be that RVM somehow generates a corrupt .dsk file. Interesting! Let me see if I can make a bug report then :)

So, it seems all is working then! I can move on with the next stage of development haha, thank you very much again!

trocoloco

Ahh good to hear! glad it was of help. And of course thank to you for the amazing The Key!  8)

santi.ontanon

haha, thanks! And as you can imagine, all these experiments are to allow saving game to disk in the next versions of The Key :)

trocoloco

of course!  ;D  Before I finished it and then watched the chat at Juanje's channel along with Chema. It trully is meritorious the amount of details that places that takes place behind the scene to develop such game in only 64K. Looking forward to see how it progresses and always hapy to help in whatever is possible :)  

Powered by SMFPacks Menu Editor Mod