Re: LZ: A new programming question


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

Re: LZ: A new programming question



On Fri, 20 Dec 1996 12:09:16 -0700,
Nathan Adams wrote...
>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.

I would think that the easiest way to do this (remember, I'm rather brain 
dead right now and in a hurry, so I may be wrong!) would be to use the LDDR 
command.  This uses hl, de, and bc in the same role as ldir, except that de 
and hl are decreased by one each time, until bc=0.  When you know the 
address of the end of your file, you set hl equal to that location's 
address, de equal to the address of the next memory location, then set bc 
equal to the number of values to be moved (I can't think right now, so you 
can figure that one out), then just have lddr be your next command.  When 
bc equals zero, just inc hl and you have the address of the point where you 
are going to insert a character (or, whatever).  Pushes and Pops can help 
to preserve the original hl value.  To quickly find out the address of the 
end of your file, I'd recommend that you use two bytes before the file to 
state how many bytes the text takes up.

Hope it helped,
Michael Wyman - SeaHorse Software
wyma0012@gold.tc.umn.edu