Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Runer112 on January 08, 2012, 12:55:40 am

Title: [Z80] Jump to a specific point in an edit buffer
Post by: Runer112 on January 08, 2012, 12:55:40 am
The subject line mostly explains what I want to do. Inside of the OS program editor, I'm wondering what the easiest way is to "jump" to a point in the edit buffer. I don't want any scrolling, any adjusting of the cursor position on the screen, really any noticeable changes to the user. I just need the edit pointers to be adjusted and for the data in the edit buffer to be moved around properly. I probably explained that awfully, so let me sketch it out. I want to be able to start with a program in the edit buffer like it was just loaded:

X...............
................
.........XXXXXXX
XXXXXXXXXXXXXXXX


And "scroll" to a certain byte:

XXXXXXXXXXXXXXXX
XXX............
................
...........XXXXX



I feel like there's some easy way to do this involving a bcall or two instead of having to do the copying and pointer updating myself, but I don't know what it is. Sort of like an instant goto, but without any actual displaying. If you can only think of a way to do it with the displaying, that might be acceptable as well, so feel free to suggest whatever comes to mind.
Title: Re: [Z80] Jump to a specific point in an edit buffer
Post by: ZippyDee on January 08, 2012, 12:57:20 am
Is it that difficult to use a ldir and update the pointers? I don't think there's really anything else that needs to be done, is there?
Title: Re: [Z80] Jump to a specific point in an edit buffer
Post by: Runer112 on January 08, 2012, 12:59:58 am
That works, but I feel that there's some OS routine that will do it for me and save me 10 or 20 bytes.
Title: Re: [Z80] Jump to a specific point in an edit buffer
Post by: ZippyDee on January 08, 2012, 01:03:02 am
None that I know of...I thoroughly looked over all the edit buffer routines that I found when I was working with some edit buffers before, and I don't recall anything like that. I think I just wrote my own to do that.
Title: Re: [Z80] Jump to a specific point in an edit buffer
Post by: Runer112 on January 08, 2012, 01:05:53 am
I know Axe has a method of doing it for errors at least. I believe this (http://ourl.ca/4057/268211) is how Axe currently instantly scrolls to errors, and it does no manual copying or edit pointer updating. So that makes me think there's something similar that I can do for my purpose of simply adjusting the edit buffer.
Title: Re: [Z80] Jump to a specific point in an edit buffer
Post by: FloppusMaximus on January 08, 2012, 02:39:04 am
I don't think there is any routine to do exactly what you're saying.

CursorToOffset (BC 494B) will scroll the editor to a given offset; i.e., it rewinds to the start of the buffer, then moves forward by (errOffset) bytes, displaying tokens as it goes (using the large or small font depending on the API flags.)  It then calls DispEOW to display the remainder of the screen after the cursor.  BC 4CD8 does the same as CursorToOffset except without the DispEOW.

(Displaying tokens one at a time is, as far as I know, the only way the OS ever handles scrolling.)

If you want to use one of these routines, you need to set curRow/curCol to the initial cursor position beforehand (e.g., for the program editor, you'd want to start at row 1, column 0, and display a colon character), and of course winTop and winBtm need to be correct.

To move to a given position without displaying anything, you could do something like this (untested):
Code: [Select]
B_CALL BufToBtm
ld hl, (editTop)
push hl
ld bc, (errOffset)
add hl, bc

ld de, (editCursor)
sbc hl, de
add hl, de
jr c, offset_invalid

ld (editTop), hl

B_CALL BufToTop
pop hl
ld (editTop), hl
Title: Re: [Z80] Jump to a specific point in an edit buffer
Post by: Quigibo on January 08, 2012, 03:53:54 am
I think the ldir is the best route.  I mean you'd save less than 10 bytes if a bcall did exist, and plus its faster.  The one you linked to is not the version Axe uses, it had the same bug as my previous attempts.  The fixed version I posted on cemetech here (http://www.cemetech.net/forum/viewtopic.php?t=7172).
Title: Re: [Z80] Jump to a specific point in an edit buffer
Post by: Runer112 on January 08, 2012, 04:09:18 am
That is a great approach, FloppusMaximus! The best part is that your solution perfectly fits my more general goal, though I didn't even tell you what it was:


The B_CALL(_BufToBtm) at the start of your routine perfectly takes care of step two. And since the position I'm jumping to is just a saved (editCursor), calculating and validating the jump point can be completely cut out! So for my purposes, everything I need to do boils down to just this:

Code: [Select]
ld hl,(editTop)
push hl
ld hl,(editCursor)
push hl
B_CALL(_BufToBtm)
call ParseProgram
pop hl
ld (editTop),hl
B_CALL(_BufToTop)
pop hl
ld (editTop),hl


Excellent thinking, FloppusMaximus. :thumbsup: I may end up just trying to parse the data without removing the edit gap if if the code to do so is smaller overall, but for the question I asked, you've given what must surely be the best answer.