.phase 2d00h ; SET ORIGIN begin: ld sp,stack+8 ; INTIALIZE STACK ld de,(sbot) ; BOTTOM OF SOURCE ; D,E=SBOT=(B) ld hl,(sstrt) ; H,L=SSTRT=(A) ld c,l ld b,h ; SAVE IN B,C call comph ; COMPLIMENT(A) & ADD 1 add hl,de ; H,L=(B)-(A)=BLOCKSIZE push hl ; SAVE ON STACK ld de,(dtop) ; TOP OF DESTINATION ; D,E=DTOP=(C) ld l,c ld h,b ; H,L=SSTRT call comph add hl,de ; H,L=(C)-(A)=DISPL ld (displ),hl ; SAVE DISPLACEMENT push af ; HAS SIGN OF DISPL ld a,(func) ; CHECK FOR MOVE or a jr z,step2 ; IF 0 FIX REF. ONLY pop af jr c,down ; (C)>(A) IF CARRY SET ; IF COME HERE DESTINATION IS ABOVE SOURCE ; SO MOVE IS DONE HEAD-TO-HEAD up: ex de,hl ; H,L=D,E=DTOP pop de ; D,E=BLKSIZE x: ld a,(bc) ; B,C=SSTRT=SOURCE PTR. ld (hl),a ; MOVE TO NEW LOC. ld a,d ; CHECK IF THRU or e jr z,test ; IF D,E=0 THEN MOVE DONE inc hl ; INCR DEST. PTR. TO NEXT inc bc ; INCR SOURCE PTR. dec de ; COUNT DOWN BLKSIZE jr x ; CONTINUE ; IF COME HERE DESTINATION IS BELOW SOURCE ; SO MOVE IS DONE TAIL-TO-TAIL down: ex de,hl ; H,L=D,E=DTOP pop de ; D,E=BLKSIZE push de ; SAVE ON STACK add hl,de ; H,L=DBOT=DTOP+BLKSIZE ex de,hl ; D,E=DBOT:H,L=BLKSIZE add hl,bc ; H,L=SSTRT+BLKSIZE=SBOT ex de,hl ; D,E=SBOT:H,L=DBOT pop bc ; B,C=BLKSIZE xx: ld a,(de) ; D,E=SOURCE PTR. ld (hl),a ; MOVE TO NEW LOC. ld a,b ; CHECK IF THRU or c jr z,test ; B,C=0,MOVE DONE dec hl ; PT. TO NEXT DEST. dec de ; PT. TO NEXT SOURCE dec bc ; COUNT DOWN BLKSIZE jr xx ; CONTINUE test: ld a,(func) ; =02 IF MOVE ONLY cp 02h jr z,done ; COME HERE TO DO REFERENCE FIXING. ; NECESSARY ONLY FOR 3 BYTE OP CODES step2: ld bc,tabl3 ; B,C= TABLE PTR ld hl,(sbot) ; NEED TO ADD 1 TO SBOT inc hl ld (sbot),hl ld de,(start) ; D,E=MEMORY PTR. chekf: ld hl,(sstp) ; CHECK FOR END OF FILE call comph ; D,E-MEM. PTR. add hl,de ; D,E-H,L=DIFF. jr c,done ; DIFF.>=0,CARRY SET next: ld a,(de) ; LOAD MEM. USING D,E ld h,a ; SAVE IN H xor a ; ZERO ACCUM. ld l,a ; SET UP CNTR. comp3: inc l ; BUMP CNTR ld a,l cp 27d ; CHECK FOR END OF TABLE jr z,again ; IF THRU..LOOK @ 2 BYT OPS ld a,(bc) ; LOAD TABLE ENTRY sub h ; COMP. WITH CURR. MEM. jr z,mtch3 ; JMP IF MATCH inc bc ; ELSE BUMP TABLE PTR. jr comp3 ; LOOK AGAIN again: ld bc,tabl2 ; NOW,LOOK AT 2 BYTE OPS xor a ; ZERO ACCUM. ld l,a ; SET CTR. comp2: inc l ; BUMP CTR. ld a,l cp 19d ; CHECK FOR END TABLE jr z,out1 ; NO MATCH 2 OR 3 BYTE OPS ld a,(bc) ; LOAD TABLE ENTRY sub h ; COMP. WITH CURRENT MEM. jr z,out2 ; JMP IF MATCH inc bc ; ELSE BUMP TABLE PTR. jr comp2 ; LOOK AGAIN mtch3: ld hl,(sbot) ; FOUND 3 BYTE OP CODE call comph ; IS ADDR. IN RANGE? inc de ; GET LO ADDR. BYTE ld a,(de) ; LOAD IN ACC. ld c,a ; STORE IN C inc de ; GET HI ADDR. BYTE ld a,(de) ; LOAD ACC. ld b,a ; PUT IN B add hl,bc ; H,L=MEM.ADDR.-SBOT jr c,out1 ; MEM.ADDR.>=SBOT+1,C SET ld hl,(sstrt) ; LESS THAM (A)? call comph add hl,bc ; H,L=MEM.ADDR.-SSTRT jr nc,out1 ; MEM.ADDR. < SSTRT,C=0 fixr: ld hl,(displ) ; IF COME HERE,IN RANGE. add hl,bc ; H,L=MEM.ADDR.+DISPL ld a,h ld (de),a ; STORE NEW HI ADDR. dec de ; PT. AT LO ADDR. BYTE ld a,l ld (de),a ; STORE NEW LO ADDR. BYTE out2: inc de out1: inc de ; ADV. PTR. TO NEXT OP ld bc,tabl3 ; RESET TABLE PTR. jr chekf ; CONTINUE done: rst 8*07 ; FINIS,RETURN TO DDT ; ***** SUBROUTINE ***** comph: ld a,h ; SUBROUTINE USED TO cpl ; FIND 2'S COMPLIMENT ld h,a ; REPRESENTATION OF ld a,l ; H,L REGISTER PAIR cpl ld l,a inc hl ret ; ***** TABLES AND CONSTANTS ***** tabl2: db 06h,0eh,16h ; TABLE OF 2 BYTE db 1eh,26h,2eh ; OP CODES db 36h,3eh,0c6h db 0ceh,0deh,0d6h db 0dbh,0deh,0e6h db 0eeh,0f6h,0feh tabl3: db 01h,11h,21h ; TABLE OF 3 BYTE db 22h,2ah,31h ; OP CODES db 32h,3ah,0c2h db 0c3h,0c4h,0cah db 0cch,0cdh,0d2h db 0d4h,0dah,0dch db 0e2h,0e4h,0eah db 0ech,0f2h,0f4h db 0fah,0fch sstrt: ds 02h ; SOURCE TOP(A) sbot: ds 02h ; SOURCE BOTTOM(B) dtop: ds 02h ; DESTINATION TOP(C) start: ds 02h ; START OF REF. FIXING(D) sstp: ds 02h ; END OF REF. FIXING(E) func: ds 01h ; 00=REF. FIX ONLY (F) ; 02=MOVE ONLY ; 01=MOVE & FIX displ: ds 02h ; DISPLACEMENT stack: ds 08h ; MEM. SPACE FOR STACK .dephase end