Jump to content
  • 0

Writing a "panel" drawing routine


rje
 Share

Question

I've started assembly that draws a beveled box in PETSCII on the screen.  The user POKEs in left,top,right,bottom, and the code does the work.

I just remembered that there are KERNAL routines to position the cursor on the screen.  I should use those, shouldn't I?

 

The routine starts by pre-computing the height and width, and then it positions the cursor:

Quote

ldy top

jsr print_y_down

ldx left

jsr print_x_spaces

Then, it prints the top line:

Quote

lda #213 ; curve top-left

jsr chrout

ldx width

jsr horiz_bar

lda #201 ; curve top-right

jsr chrout

That's what I have so far.  Next steps are to print the vertical bars and the bottom of the panel frame.

Now for the print_x_spaces I have:

Quote

print_x_spaces: beq done

                lda #29         ; right

                jsr chrout

                dex

                bne print_x_spaces

                rts

And for the horizontal bar, I have:

Quote

horiz_bar:      beq done

                lda #195        ; horiz bar

                jsr chrout

                dex

                bne horiz

                rts

 

I guess I want to verify I'm doing things correctly, if there's a better way, and perhaps if this has already been done.

 

Edited by rje
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

You want to use the PLOT routine in the Kernal to move the cursor. Just be aware that it confusingly switches the X and Y registers from what you'd expect. Put the row in X and the column in Y, and you're all set, no need to put out a bunch of spaces.

Alternatively, you can just poke the characters into VRAM, along with color info for each one. That will usually be the fastest method for rendering characters.

  • Thanks 1
Link to comment
Share on other sites

  • 0
2 hours ago, fraggintarget said:

Will using the chrout routine cause screen scrolling when you print to the bottom right position of the panel at the bottom right position of the screen and the cursor is advanced to the next position?

 

Yes. CHROUT behaves the same as the BASIC PRINT statement. It will scroll, wrap, and honor terminal sequences (ie: cursor, color, etc.) For performance and control, I'd suggest pushing characters directly to VERA, rather than using the KERNAL. 

Also - yes, if you're using CHROUT, you should be using the PLOT function to move the cursor. Just bear in mind that Commodore did something really dumb and swapped the meaning of X and Y. The X register takes the row and the Y register takes the column of the cursor position. If you are writing directly to VERA, you should not use PLOT. Instead, write the column and row values to $9f20 and $9f21, and write $10 to $9f22 (increment by 1).

With that setting, you can write an entire row of the same character with a simple loop and, more imporantly, without having to reset the character position:
  LDA #char
- LDX #count
  STA $9f23
  DEX 
  BNE -

 

Edited by TomXP411
Link to comment
Share on other sites

  • 0

One note about this, you can mix the two concepts (writing to VERA some of the time, using PLOT and CHROUT others) but, speaking from experience, I would say don't 🙂 VERA does require doing some additional work but it does seem work it and opens up some cool stuff. Once you have some basic functions to do what you want, it's not tooo bad. Having to convert to/from screencodes is one landmine to be aware of as well as the fact your graphic area is larger than the screen (which you can exploit by scrolling the display around). Then there's having to handle keyboard input and displaying it on the screen. I looked at Petdraw for inspiration in how to do some of that which was helpful.

Initially VERA is more work but it is indeed quite fast. I don't think I'd be able to do my pattern scrolling in my tracker without leveraging VERA here (in my case I write out the part of the pattern that can be seen to VERA, then use the scroll routines). Even if I could, it'd likely consume precious CPU that I need for other things.

At some point, I think (I hope) there can be some reasonable helper routines that can be shared amongst apps. Things like drawing boxes, moving the cursor to X/Y (ie a replacement for PLOT), converting screencodes, etc. are all things I'd imagine lots of apps will want to do.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use