Block save / load

Discussion about ZX80 / ZX81 Software
dr beep
Posts: 2132
Joined: Thu Jun 16, 2011 8:35 am
Location: Boxmeer

Re: Block save / load

Post by dr beep »

DEC DE does not set any flag.
User avatar
marste
Posts: 266
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: Block save / load

Post by marste »

dr beep wrote: Thu May 02, 2024 7:36 pm DEC DE does not set any flag.
my z80 asm is rusted :mrgreen:
then 2 bytes more needed to set flags

BUT

a trick can be to put in the saved code, in the exact memory position of the target "call IN_BYTE", a call with the low address of the routine to be started, and then, when the load loop will overwrite this part, the call will be to 0x43 + this low byte... probably this was your suggestion some post before!! (PS: I've seen and confirm, just you used "ret", while this with "call rewrite" might save another two additional bytes at the expense of having a starting address in the 0x43xx area -> with 11 bytes load loop we are at 1013 byte of useful load! :))
Last edited by marste on Fri May 03, 2024 6:02 am, edited 6 times in total.
User avatar
marste
Posts: 266
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: Block save / load

Post by marste »

Then the new code looks like this (corrected also an error in preparing hl):

Code: Select all

MEMORY_END equ 0x4400    ; 1k

SET_FAST equ 0x2E7       ; ROM routines
IN_BYTE equ 0x34C        ;  /
GET_BITS equ 0x385       ; /

START:
    call SET_FAST        ; load operations to be managed in FAST mode
    ld   hl, 0x4400      ; cleanup and put stack at the very end of memory
    ld   sp, hl          ; /
    ld   hl, LOAD_LOOP   ; relocate loader to end of memory
    ld   de, 0x4400 + LOAD_LOOP - RELOCATE_END ; /
    push de              ;                      /
    ld   bc, RELOCATE_END - LOAD_LOOP ;        /
    ldir                 ;                   _/
    pop  hl              ; the inital GET-BIT ret will be inside the loop
    inc  hl              ; skipping the first call IN_BYTE to avoid
    inc  hl              ; timeout problems
    inc  hl              ; 
    push hl              ; return address for the GET-BIT (that will load a full byte)
    ld   hl, 0x4000      ; start loading data at 4000h
    ld   c, $01          ; prepare (for ROM) an eight counter 00000001
    ld   b, $00          ; and set counter to 256
WAIT:                    ; wait signal to avoid ROM timeout
    ld   a, $7F          ; read tape bit 
    in   a, ($FE)        ; /
    rla                  ; test tape bit.
    jp   C, GET_BITS     ; if detected go to GET-BIT (return will be in the load loop)
    jp   WAIT            ; else loop back infinitely

LOAD_LOOP: ; this 11 bytes block will be relocated at the end of the memory
    call IN_BYTE         ; ROM routine IN-BYTE loads a byte
    ld   (hl), c         ; insert assembled byte in memory
    inc  hl
    jr   LOAD_LOOP       ; loop until the loaded code will overwrite the "call IN_BYTE" 
                         ; with the target address that need to be 0x43xx (just lower byte will be load)
    db   0, 0, 0, 0      ; stack space (for the call and push de inside IN_BYTE)
RELOCATE_END:            ; end of the relocated block (this label will be at 0x440)
Last edited by marste on Sat May 04, 2024 10:38 am, edited 7 times in total.
User avatar
marste
Posts: 266
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: Block save / load

Post by marste »

dr beep wrote: Sun Apr 28, 2024 10:41 am I had hoped to have a small loader that would allow loading more data in a 1K machine. Now bound on around 949 bytes.
Hope your dreams might have come true... Let us dream your new reaches if so!! 8-)
User avatar
marste
Posts: 266
Joined: Sun Aug 10, 2014 9:58 pm
Location: Italy
Contact:

Re: Block save / load

Post by marste »

PS: for the conversion of an assembled file to an audio file the program here can be used: viewtopic.php?f=6&t=4023

Just use the "-80" parameters (the output should not contain the filename) and do not pass a ".p" file (rename in case to something else) since the intelligent extension detection has unfortunately priority on the parameter.

To recap: pass to the converter a binary file long 1016 bytes with the last instruction (3 bytes) be a call to the address of the label to start the program that should be in the 0x43xx area. The program at this point is still in "FAST" mode.
Post Reply