From fb2242116670a4c60e8ace16df4bfb8c9ffc5a27 Mon Sep 17 00:00:00 2001 From: Leo C Date: Mon, 17 Jun 2019 23:22:58 +0200 Subject: [PATCH] New relocator --- Makefile | 33 ++++++++++---------- ddt180.z80 | 90 ++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 84 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 0d11916..4fb0f3e 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,11 @@ ifneq ($(CPM),0) else SUFFIX := 180 endif +CURCPM := $(shell awk -e '/CPM/ {print $$3}' config.inc 2>/dev/null) +ifneq ($(CPM),$(CURCPM)) + $(shell printf " CPM equ $(CPM)\r\n\032" > config.inc) +endif + EXTRA_DIST := autorevision.cache version.inc @@ -26,23 +31,26 @@ ZIP := zip AS_OPT := MFSX -.phony: all -all: $(PROG).com +.PHONY: all +all: $(PROG).com prl2offz -.intermediate: $(PROG).180 +.INTERMEDIATE: $(PROG).180 $(PROG).180: $(PROG).z80 cp $< $@ -$(PROG).com: $(PROG).prl Makefile - @# Remove the PRL header record (256 bytes) - dd status=none bs=256 skip=1 if=$< of=$@ +$(PROG).com: $(PROG).prl Makefile prl2offz + @# Convert relocation bitmap to compressed list of offsets + ./prl2offz $< $@ $(PROG).prl: $(OBJ) $(LINK) -'$(PROG)[op]' $(PROG).rel: config.inc version.inc +prl2offz: prl2offz.c + gcc -Wall -Wextra -O2 -g -o $@ $< + $(foreach X,$(subst =,:=,$(subst ",,$(filter VCS_%,\ $(shell autorevision -t sh -o $(CURDIR)/autorevision.cache)))),$(eval $X)) @@ -58,20 +66,13 @@ ifeq ($(VCS_WC_MODIFIED),1) VERS := $(VERS)-dirty endif - - version.inc: autorevision.cache @echo update $@ to $(VERS) @printf "defvers macro\r\n\ db '$(VERS)'\r\n\ endm\r\n\032" > $@ -config.inc: Makefile - @printf "\ - CPM equ $(CPM)\r\n\ - \032" > $@ - -.phony: dist +.PHONY: dist dist: $(PROG).com version.inc $(GIT) archive --format=zip --prefix=$(PREFIX)/ -9 -o $(DIST_NAME) HEAD^{tree} @mkdir -p $(PREFIX) @@ -79,7 +80,7 @@ dist: $(PROG).com version.inc $(ZIP) -r -9 $(DIST_NAME) $(PREFIX) $(PROG).com @$(RM) -r $(PREFIX) -.phony: clean +.PHONY: clean clean: rm -f $(PROG).com $(PROG).180 *.rel *.lst *.prl @@ -90,7 +91,7 @@ clean: define cpm-asm = COMMAND="$(ASM) -$(basename $<)/$(AS_OPT)"; \ OUTPUT=$$(mktemp); echo $${COMMAND}; \ -$${COMMAND} > $${OUTPUT}; \ +$${COMMAND} > $${OUTPUT} < $<; \ grep -q '^ 0 Error(s) Detected' $${OUTPUT}; ERROR=$$? ; \ if [ "$${ERROR}" != "0" ]; then cat $${OUTPUT}; rm -f $@; \ else awk -f filter-unref.awk ddt180.lst; fi ; \ diff --git a/ddt180.z80 b/ddt180.z80 index adbe46f..fd16076 100644 --- a/ddt180.z80 +++ b/ddt180.z80 @@ -54,6 +54,20 @@ signon: defvers dc ' (' +;------------------------------------------------------------------------------- + +reloc_getbit macro + local nextbit + exx + djnz nextbit + ld b,8 ;reload bit counter + ld e,(hl) ;get next 8 relocation bits + inc hl +nextbit: + sla e + exx + endm + ;------------------------------------------------------------------------------- ; Clear old position @@ -98,27 +112,49 @@ wearehere: ei ld hl,ddtz_end ;start of reloc bitmap add hl,de - push hl exx pop hl - ld bc,0108h ;init bit counter b (c==reload val) + ld b,1 ;init bit counter b exx LD HL,ddtz_base add hl,de ;--> ddtz_base - ld bc,prog_size + reloc_lp: - EXX - djnz reloc_nl - ld b,c ;reload bit counter - LD e,(HL) ;get next 8 relocation bits - INC HL -reloc_nl: - sla e - EXX - JR NC,reloc_next - DEC HL + push de + push hl + + ld de,4 + ld a,2 + ld hl,0 +reloc_l: + reloc_getbit + jr nc,reloc_got + cp 16 + jr z,reloc_done + add hl,de + ld b,a + ex de,hl +reloc_l1: + add hl,hl + djnz reloc_l1 + ex de,hl + add a,a + jr reloc_l +reloc_got: + ex de,hl + ld hl,0 + ld b,a +reloc_bitloop: + reloc_getbit + adc hl,hl + djnz reloc_bitloop + add hl,de + pop de + add hl,de + pop de + LD A,(HL) ADD A,E LD (HL),A @@ -126,13 +162,11 @@ reloc_nl: LD A,(HL) ADC A,D LD (HL),A -reloc_next: inc hl - dec bc - ld a,b - or c - jr nz,reloc_lp - + jr reloc_lp +reloc_done: + exx + ld (bitmap_end),hl ;------------------------------------------------------------------------------- @@ -181,8 +215,8 @@ ini_sign: call out_hl call pstr_inl dc ' - ' - ld de,prog_size+bitmap_size-1 - add hl,de + ld hl,(bitmap_end) + dec hl call out_hl call pstr_inl dc ')',CR,LF @@ -1591,7 +1625,14 @@ cmd_E: push af call get_arg_final - ld bc,prog_size+bitmap_size + ex de,hl + ld hl,(bitmap_end) + ld bc,ddtz_base + or a + sbc hl,bc + ld b,h + ld c,l + ex de,hl pop af jr nz,cmde_bottom sbc hl,bc @@ -2639,7 +2680,7 @@ i.storebyte: call cp_hl_de jr nc,ist_1 - ld de,ddtz_end+bitmap_size-1 + ld de,(bitmap_end) call cp_hl_de jr nc,error2 ist_1: @@ -4004,6 +4045,9 @@ last_L: pbl_loop_adr: dw 0addeh +bitmap_end: + dw 0 + ;------------------------------------------------------------------------------- conbuf: -- 2.39.2