Author Topic: [Z80] Jump to a specific point in an edit buffer  (Read 3877 times)

0 Members and 1 Guest are viewing this topic.

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
[Z80] Jump to a specific point in an edit buffer
« 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.
« Last Edit: January 08, 2012, 12:57:47 am by Runer112 »

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: [Z80] Jump to a specific point in an edit buffer
« Reply #1 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?
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: [Z80] Jump to a specific point in an edit buffer
« Reply #2 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.
« Last Edit: January 08, 2012, 01:00:22 am by Runer112 »

Offline ZippyDee

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 729
  • Rating: +83/-8
  • Why not zoidberg?
    • View Profile
Re: [Z80] Jump to a specific point in an edit buffer
« Reply #3 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.
There's something about Tuesday...


Pushpins 'n' stuff...


Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: [Z80] Jump to a specific point in an edit buffer
« Reply #4 on: January 08, 2012, 01:05:53 am »
I know Axe has a method of doing it for errors at least. I believe this 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.

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: [Z80] Jump to a specific point in an edit buffer
« Reply #5 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

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: [Z80] Jump to a specific point in an edit buffer
« Reply #6 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.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Runer112

  • Moderator
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: [Z80] Jump to a specific point in an edit buffer
« Reply #7 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:

  • While the program editor is open, save the edit buffer's state
  • Move all the edit buffer data to one end
  • Parse the (now gapless) data
  • Restore the program editor to its original state like nothing ever happened

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.
« Last Edit: January 08, 2012, 04:24:04 am by Runer112 »