Jump to content
  • 0

C64 Kernal Clear Screen Line = ?


Justin Baldock
 Share

Question

On the C64 we could clear line X on the screen using a poke and sys to a kernal function.

POKE 781,X: SYS 59903

Is there something like this for the X16? If I try it, it simply clears the entire screen.

What I am doing is printing a game "shopping list" using CHR$(!13) CHR$($11) CHR$($11) so in the middle of the screen is a table of items. Then I'm using CHR$($13) to send the cursor back to home and prompt what the player would like to buy. The 2nd line would say if they purchased it, didn't have enough money, etc. Then I was hoping to clear just the 2nd line on the screen and re-prompt them until they leave the store.

Any pointers would be cool.

Edited by Justin Baldock
Example of use
Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

59903 = $E9FF

Looking at https://www.pagetable.com/c64ref/c64disasm/ I found that address to be the start of a function called CLRLN (Clear Line).

Then I looked through the X16 source code to find the CLRLN function, but it does not exist instead I found the screen_clear_line function and looking at the .sym files I found the entry address of $C88E

Unfortunately BASIC lives in ROM bank 4 and the screen_clear_line function is in ROM bank 0 so it is not possible to call it directly without switching banks. I tried switching banks in BASIC by poking the VIA, but as soon as the bank is switched, BASIC is no longer able to run and the emulator hangs (of course).

I have written a small program that actually calls the screen_clear_line functions and ensures that the ROM banks selection is correct, but it might be just as easy to just clear the line through ordinary BASIC code.

Quote

10 DATA $9C,$60,$9F,$20,$8E,$C8,$A9,$04,$8D,$60,$9F,$60
20 FORI=$400TO$40B:READ A:POKEI,A:NEXT
30 POKE 781,2:SYS$400

Line 10 is actually a small machine language program that sets the ROM bank to 0, calls the screen_clear_line function and sets the ROM bank back to 4 before returning.

Line 20 Writes the machine language program to RAM address $400 (golden RAM)

Line 30 Sets the line that should be cleared and calls the machine language function.

This is the disassembly of the machine language program in line 10:

Quote

STZ $9F60
JSR $C88E
LDA #$04
STA $9F60
RTS

Note that when R39 of the ROM is released, this code will no longer work as the bank switching is moved down to zero-page.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 0
On 11/9/2021 at 5:38 PM, JimmyDansbo said:

I have written a small program that actually calls the screen_clear_line functions and ensures that the ROM banks selection is correct, but it might be just as easy to just clear the line through ordinary BASIC code.

That little function looks good.

Is there a way in BASIC which will do it? My googling had only turned up using the CLRLN like I used above. The other way on C64 was to poke  in to video memory. 

Link to comment
Share on other sites

  • 0

Some time ago, I made a pull request for a new BASIC command "FSYS" to invoke code in other ROM banks. That could be used for a lot of things, including to call the clear line routine @JimmyDansbo found.

However, as there has been no recent development, at least not in public, of the Kernal, I don't know if there is interest in the solution.

  • Like 1
Link to comment
Share on other sites

  • 0
On 11/9/2021 at 5:17 PM, Stefan said:

Some time ago, I made a pull request for a new BASIC command "FSYS" to invoke code in other ROM banks.

As the X16 kernal is based off of the C64 kernal, it might be an idea to look at the big-brother for how they handled banking.

Instead of an FSYS command, maybe we should implement something similar to the BANK command from BASIC 7 https://www.c64-wiki.com/wiki/BANK

According to the C128 programmers reference https://www.pagetable.com/docs/Commodore 128 Programmer's Reference Guide.pdf (page 28 / 38), SYS, PEEK, POKE and WAIT will then use the selected bank.

  • Like 2
Link to comment
Share on other sites

  • 0
On 11/9/2021 at 5:35 AM, JimmyDansbo said:

As far as I know, there is no easy way of clearing a line on the screen.

You could use PETSCII codes https://cx16.dk/cx16-petscii/ ($11,$1D,$91,$9D) to move the cursor to the correct line and then just print a line of spaces.

That's dangerous.  Printing something into the last spot on the screen will scroll the screen!  The safest way is to go to the last spot on the line, delete back to the beginning, then print a space over what used to be the last character.

  • Like 2
Link to comment
Share on other sites

  • 0
  • Super Administrators
On 11/9/2021 at 9:49 AM, Greg King said:

That's dangerous.  Printing something into the last spot on the screen will scroll the screen!  The safest way is to go to the last spot on the line, delete back to the beginning, then print a space over what used to be the last character.

Print 79 spaces, then {LEFT}{INST}{SPACE}. That can be saved as  variable early on, then used as needed. 

  • Like 1
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