News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_EgoTrip

[CPCTelera] Can't use Firmware File routines with Disc

Started by EgoTrip, 15:26, 22 February 22

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

EgoTrip

I have tried to use the Firmware file routines to save and load from disc, and I am running into issues. Firmware is enabled. It shows up the "Press REC and PLAY then any key" prompt, then shows "Saving <file.bin> block 1" and hangs. I assume that CPCtelera is disabling the disc jumpblock somehow, and if so how do I re-enable it? Or, and this would be preferable so as not to rely on firmware, can anyone share any routines I can use to save and load to disc? Not tape. Thanks.


This is my code in case I went wrong with this and I can't see the error.


void filesave() {
__asm
ld b,#0x0c //length of filename
ld hl,#0x7000 //address of filename
ld de,#0x0000 //address of 2k buffer (unused)
call #0xbc8c //cas_out_open
ld hl,#0x700d //load address
ld de,#0x0100 //length
ld bc,#0x0000 //execution address
ld a,#02 //file type (2=binary)
call #0xbc98 //cas_out_direct
call #0xbc8f //cas_out_close
__endasm;
}


teopl

@EgoTrip  Not sure about saving, but this is what I used for loading when I experimented and it works very well: (sorry for GPL  ;D )

This loads invisible (if you set all colors to background color in that part) chunks of data to bottom screen which is a good trick to have extra memory.

Used it like this (before firmware was disabled)


    __asm__("call teopl_load_from_disc_asm");
    _firmware = cpct_disableFirmware(); // not to interfere with code

...
...
...

Header:


void teopl_load_from_disc_asm() __z88dk_callee __naked;


C-source:



// ########################## BEGIN GPL LICENSE BLOCK #############################
//    This file is part of legend of steel.
//
//    Legend of steel is free software : you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Legend of steel is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Legend of steel.If not, see < https://www.gnu.org/licenses/>.
//
//    Developed for the CPCRetrodev contest 2018 edition.
//
//     Developers                           Contact
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//     Castillo Zaragoza, Juan Miguel       jmczaragoza13@gmail.com
//     Pérez Pérez, Luis Fernando           luisfernandodos2@hotmail.com
//     Ponsoda Montiel, Daniel              dponsoda@gmail.com
//
// ############################ END GPL LICENSE BLOCK #############################


// slightly modified my teopl to load all assets to different (screen) locations


// REMARK: must be called with firmware enabled
void teopl_load_from_disc() __naked {

__asm
; binary_compressed_special
.equ destination_special00, #60752
.equ destination_special01, #60793
.equ destination_special02, #61132
.equ destination_special03, #56736
__endasm;



__asm


.equ destination00, #50592
.equ destination01, #51005
.equ destination02, #52640
.equ destination03, #52906
.equ destination04, #54688
.equ destination05, #54807
assetFile00: .asciz "lvle1.00"
assetFile01: .asciz "lvle2.00"
assetFile02: .asciz "lvle2.01"
assetFile03: .asciz "lvle3.00"
assetFile04: .asciz "lvle3.01"
assetFile05: .asciz "lvle4.00"


; binary_compressed_specialassetFile_special00: .asciz "M.BIN"
assetFile_special01: .asciz "G.bin"
assetFile_special02: .asciz "F.BIN"
assetFile_special03: .asciz "B.BIN"


.equ kl_rom_walk, 0xBCCB
.equ cas_in_open, 0xBC77
.equ cas_in_close, 0xBC7A
.equ cas_in_char, 0xBC80
.equ cas_in_direct, 0xBC83


.equ scr_set_border, 0xBC38
.equ scr_set_ink, 0xBC32


teopl_load_from_disc_asm::


push de
push hl
ld bc, #0x0000;; |
call scr_set_border;; Set border to black(using firmware)


ld a, #0;; |
setPaleteLoop:;; |
    ld bc, #0x0000;; |
    push af;; |
    call scr_set_ink;; |
    pop af;; |
    inc a;; |
    cp #15;; |
    jp nz, setPaleteLoop;; Set all inks to black(using firmware)


    pop hl
    pop de


    call kl_rom_walk;; Reenable all roms(including disc rom)


    ; binary_compressed_special
    ld hl, #destination_special00
    ld bc, #assetFile_special00
    call cpct_loadFromDisc_asm


    ld hl, #destination_special01
    ld bc, #assetFile_special01
    call cpct_loadFromDisc_asm


    ld hl, #destination_special02
    ld bc, #assetFile_special02
    call cpct_loadFromDisc_asm


    ld hl, #destination_special03
    ld bc, #assetFile_special03
    call cpct_loadFromDisc_asm


;GENERATED_LINES_MARKER_DONT_CHANGE
ld hl, #destination00 ;GENERATED_LINE_END
ld bc, #assetFile00 ;GENERATED_LINE_END
call cpct_loadFromDisc_asm ;GENERATED_LINE_END
ld hl, #destination01 ;GENERATED_LINE_END
ld bc, #assetFile01 ;GENERATED_LINE_END
call cpct_loadFromDisc_asm ;GENERATED_LINE_END
ld hl, #destination02 ;GENERATED_LINE_END
ld bc, #assetFile02 ;GENERATED_LINE_END
call cpct_loadFromDisc_asm ;GENERATED_LINE_END
ld hl, #destination03 ;GENERATED_LINE_END
ld bc, #assetFile03 ;GENERATED_LINE_END
call cpct_loadFromDisc_asm ;GENERATED_LINE_END
ld hl, #destination04 ;GENERATED_LINE_END
ld bc, #assetFile04 ;GENERATED_LINE_END
call cpct_loadFromDisc_asm ;GENERATED_LINE_END
ld hl, #destination05 ;GENERATED_LINE_END
ld bc, #assetFile05 ;GENERATED_LINE_END
call cpct_loadFromDisc_asm ;GENERATED_LINE_END


ret


    ;; ================================================ =
    ;; Read a file byte - by - byte
    ;;
    ;; Input:
    ;; HL = address to load file data
    ;; BC = zero terminated string containing the filename
    ;; ================================================ =
    cpct_loadFromDisc_asm:
   
        ld(ph_loadAddress + 1), hl
        ld(ph_filename + 1), bc


        ld d, #  - 1


    charCountLoop:
        ld a, (bc)
        inc bc
        inc d
        cp #0
        jp nz, charCountLoop
        ld b, d;; b = filename length


    ph_filename :
        ld hl, #0x0000
        call cas_in_open;; Open file for reading


    ph_loadAddress :
        ld hl, #0x0000
            call cas_in_direct
            call cas_in_close


        ret
__endasm;
}

EgoTrip

Thanks for the replies I will let you know how I get on.

EgoTrip

@teopl Thanks for the example but I don't fully understand it, it seems like you have code in this for your game. I need something more generic and I need to be able to save too.

@SRS I tried the one you linked to but it either resets the computer or garbles up the display.

teopl

@EgoTrip

I removed extra lines and left only needed for example:

You have 2 lines:

.equ destination00, #50592
assetFile00: .asciz "lvle1.00"

This means that content of file "lvl1.00" will be copied to memory started from memory address 50592. 

You can modify this to your game.

Sorry because I don't know example to write to file, but reading works very well.

// ########################## BEGIN GPL LICENSE BLOCK #############################
//    This file is part of legend of steel.
//
//    Legend of steel is free software : you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    Legend of steel is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with Legend of steel.If not, see < https://www.gnu.org/licenses/>.
//
//    Developed for the CPCRetrodev contest 2018 edition.
//
//    Developers                          Contact
// = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
//    Castillo Zaragoza, Juan Miguel      jmczaragoza13@gmail.com
//    Pérez Pérez, Luis Fernando          luisfernandodos2@hotmail.com
//    Ponsoda Montiel, Daniel              dponsoda@gmail.com
//
// ############################ END GPL LICENSE BLOCK #############################


// slightly modified my teopl to load all assets to different (screen) locations


// REMARK: must be called with firmware enabled
void teopl_load_from_disc() __naked {

__asm
.equ destination00, #50592
assetFile00: .asciz "lvle1.00"

.equ kl_rom_walk, 0xBCCB
.equ cas_in_open, 0xBC77
.equ cas_in_close, 0xBC7A
.equ cas_in_char, 0xBC80
.equ cas_in_direct, 0xBC83

.equ scr_set_border, 0xBC38
.equ scr_set_ink, 0xBC32

teopl_load_from_disc_asm::

push de
push hl
ld bc, #0x0000;; |
call scr_set_border;; Set border to black(using firmware)

ld a, #0;; |
setPaleteLoop:;; |
    ld bc, #0x0000;; |
    push af;; |
    call scr_set_ink;; |
    pop af;; |
    inc a;; |
    cp #15;; |
    jp nz, setPaleteLoop;; Set all inks to black(using firmware)

    pop hl
    pop de

    call kl_rom_walk;; Reenable all roms(including disc rom)

ld hl, #destination00
ld bc, #assetFile00
call cpct_loadFromDisc_asm

ret

    ;; ================================================ =
    ;; Read a file byte - by - byte
    ;;
    ;; Input:
    ;; HL = address to load file data
    ;; BC = zero terminated string containing the filename
    ;; ================================================ =
    cpct_loadFromDisc_asm:
 
        ld(ph_loadAddress + 1), hl
        ld(ph_filename + 1), bc


        ld d, #  - 1


    charCountLoop:
        ld a, (bc)
        inc bc
        inc d
        cp #0
        jp nz, charCountLoop
        ld b, d;; b = filename length


    ph_filename :
        ld hl, #0x0000
        call cas_in_open;; Open file for reading


    ph_loadAddress :
        ld hl, #0x0000
            call cas_in_direct
            call cas_in_close

        ret
__endasm;
}

EgoTrip

I tried to modify it replacing the cas_in routines with the cas_out equivalents but it just resets. I guess this is never going to work.

Arnaud

Here working example for saving file with firmware.

Asm code is not great.

teopl

Quote from: EgoTrip on 13:56, 25 February 22I tried to modify it replacing the cas_in routines with the cas_out equivalents but it just resets. I guess this is never going to work.
Does the read work for you? I am not sure if I extracted the function correctly.

Arnaud

HI @EgoTrip,
Quote from: Arnaud on 20:00, 25 February 22Here working example for saving file with firmware.

Asm code is not great.

Does my code work on your project ?

EgoTrip

Quote from: Arnaud on 09:45, 05 March 22HI @EgoTrip,
Quote from: Arnaud on 20:00, 25 February 22Here working example for saving file with firmware.

Asm code is not great.

Does my code work on your project ?
The test file works, I have not yet tried it with the project but it seems to be good. Will the load version be as simple as swapping the CAS_OUT for the CAS_IN equivalent? I still would like a non-firmware version though because my project doesn't use firmware at all and switching it back on can cause issues.

Powered by SMFPacks Menu Editor Mod