Re: LZ: A new programming question


[Prev][Next][Index][Thread]

Re: LZ: A new programming question



At 16:56 12/20/96 -0800, you wrote:
>Nathan Adams wrote:
>> 
>> At 16:18 12/18/96 -0800, you wrote:
>> >There is one asm command you could use, ldir.  It means load hl into de
>> >while increasing addresses until bc equals 0.  so...
>> >
>> >ld hl,$80E1    ;source of stuff
>> >ld de,$80E0    ;destination of stuff
>> >ld bc,$0003    ;amount of stuff, or bytes you want to move
>> >ldir
>> >
>> >By the way, there is no chance of overlapping problems.  This routine is
>> >especially good if you're moving lots and lots of bytes, like some
>> >programs do to load pictures from graph mem to video mem.  You can have
>> >the fun of working out the other things, like how to calculate bc(bytes
>> >to move), and stuff like that.
>> >
>> >--
>> >Compliments of:
>> >_-_-_-_-_-_-_-_
>> >  Alan Bailey
>> >  mailto:bailala@mw.sisna.com
>> >  IRC:Abalone
>> >  Web:http://www.mw.sisna.com/users/bailala/home.htm
>> >
>> OK, I've been trying to get this to work but I haven't been able to yet.  I
>> am writing a text editor and I need to be able to insert text.  When I call
>> the subroutine for ldir, hl points to the next byte in memory to be written.
>> The memory will look something like this after some text like abcde has been
>> entered:
>> 
>> $80DF = $01
>> $80E0 = a
>> $80E1 = b
>> $80E2 = c
>> $80E3 = d
>> $80E4 = e
>> $80E5 = $02
>> 
>> $01 is the code for the start of the file
>> $02 is the code for the end of the file
>> 
>> Now say I wanted to insert a letter between b & c. hl would point to $80E2.
>> I need a routine that I could call that would increment the memory and leave
>> hl pointing to the same address that it did when the routine was called.
>> Usually I can figure these things out on my own but I think I'm becoming
>> lazy.  Anyway, any help would be greatly appreciated.
>> Nathan Adams
>> nathana@goodnet.com
>> "It is better to remain silent and be thought a fool,
>> than to speak out and remove all doubt."
>
>What you did last time was ldir, and this time, cause you're moving stuff 
>in the other direction, you need to use yet another command...lddr.  
>What you probably did, or what you might try to do, is use ldir.  Say it 
>takes C out of $80E2 and puts it in $80E3.  The next thing ldir does is 
>take D out of $80E3 and put it in $80E4.  But see, $80E3 was overwritten 
>the previous time.  This eventually makes everything equal to C, which I 
>dont' think you want.  (But it brings to mind a great way to make a large 
>space of memory equal to one value)  So, lddr.  You have to start at 
>$80E5 and lddr moves it toward C.  Got it?, same thing, just different 
>direction.  Just remember this when there is a chance for overlappation 
>(nice word) :
>
>|when hl < de, use ldDr.	(hl is start of data, de is the end)
>|when de < hl, use ldIr.
>
>Specifically for your prog, when inserting, use ldDr, when deleting, use 
>ldIr.
>
>About keeping the same value in hl, you can just push hl before ldir or 
>lddr and pop it afterwards.
>
>Hope I didn't make a mistake :)
>
>-- 
>Compliments of:
>_-_-_-_-_-_-_-_
>  Alan Bailey
>  mailto:bailala@mw.sisna.com
>  IRC:Abalone
>  Web:http://www.mw.sisna.com/users/bailala/home.htm
>
One more question for now.  This will set hl and de equal right?

push hl
pop de
add hl,de

Or is there a faster way?
Thanks for your help.
Nathan Adams
nathana@goodnet.com
"It is better to remain silent and be thought a fool,
than to speak out and remove all doubt."


Follow-Ups: