.nolist #include "joeti83.inc" #define real_loc statvars+39 .list .org $9327 ;-----> Start of program ccf jr start_of_program .dw 0 ; this prog can't use libs since it edits them! .dw sos_description sos_description: .db "Install v1.1 Run me first!",0 start_of_program: ld de,real_loc ld hl,real_start ld bc,end_of_program-real_start ldir jp real_loc real_start: ;=-=-=-=-=-=-=-= The following runs at statvars+39 =-=-=-=-=-=-=-=-=-= ; up to about 500 bytes ;-----> Copy SOS back where it belongs pop hl ; pop call to program pop hl ; pop ptr1 pop de ; pop ptr2 pop bc ; pop size swap_sos: dec hl dec de call $9171 ; swap jr nz,swap_sos ;-----> Start rewritting all libraries restart: ld hl,(fat) prog_loop: ld (tmp-real_start+real_loc),hl ld a,(hl) and %00011111 dec a ; 1 jr z,list_rel sub 5-1 ; 5 jr z,list_rel ; don't protect an unprotected! dec a ; 6 jr z,check_program cp $0D-6 ; $0D list_rel: jp z,list-real_start+real_loc all_done: ld hl,my_name-real_start+real_loc call store_hl_op1-real_start+real_loc call chksysvar call nc,delvar jp $9327 ; SOS should already be there! check_program: dec hl ; skip type ld c,(hl) dec hl ; skip msb of loc ld b,(hl) push bc inc bc inc bc inc bc ld a,(bc) cp $28 jr nz,not_uninstalled ld a,$18 ld (bc),a not_uninstalled: pop bc push bc ; save file location dec hl ; skip lsb of loc ld a,(hl) ; length of name ld b,a ld (other_len-real_start+real_loc),a dec hl ; ptr to first byte of name ld a,(hl) cp 'Z' ; first char must be a 'Z' jr nz,skip2 inc hl ; move back to before 'Z' ld de,other_name+1-real_start+real_loc ; skip prog type ($06) load_name: dec hl ld a,(hl) ld (de),a inc de djnz load_name ; copy the name xor a ld (de),a ; 0 terminate pop hl ; get loc but keep it on the stack push hl call ldhlind ; get size push hl ; save size xor a ld de,768 ; size of sram (max size of lib) sbc hl,de jr nc,skip3 ; skip it if greater than sram pop bc ; pop size pop hl ; pop loc inc hl inc hl ; move to data push bc ; keep the size ld de,sram ; place to copy the program ldir ; save the program in sram ld hl,other_name-real_start+real_loc call store_hl_op1-real_start+real_loc xor a call chksysvar call nc,delvar ; clear it out! pop hl ; hl holds length push hl call createprog inc de inc de ld hl,sram ; program data pop bc ldir ; re-save the data ld hl,other_name-real_start+real_loc call store_hl_op1-real_start+real_loc call chksysvar ld a,6 ; protect it ld (hl),a ld a,(other_len-real_start+real_loc) ld c,a ld hl,other_name+1-real_start+real_loc ld de,first_name-real_start+real_loc ld a,(first_len-real_start+real_loc) cp c jr nz,check_done ld b,a check_loop: ld a,(de) cp (hl) jr nz,not_first inc hl inc de djnz check_loop jp all_done-real_start+real_loc check_done: ld a,(de) or a jr nz,not_first ld a,c ld (first_len-real_start+real_loc),a ld b,0 ldir ; load name not_first: jp restart-real_start+real_loc skip3: pop hl skip2: pop hl skip: ld hl,(tmp-real_start+real_loc) list: dec hl dec hl dec hl ld b,(hl) nogdlp: dec hl djnz nogdlp dec hl jp prog_loop-real_start+real_loc store_hl_op1: ld bc,9 ld de,op1 ldir ret ;-----> Variables tmp: .dw $0000 other_name: .db 6,0,0,0,0,0,0,0,0,0 other_len: .db 0 first_name: .db 0,0,0,0,0,0,0,0 first_len: .db 0 my_name: .db 6,"INSTALL",0 end_of_program: .end END