Page 1 of 1

BASIC command SCREEN

Posted: Mon Apr 05, 2021 9:21 pm
by ZeroByte

The docs tell me there's a SCREEN command to set some screen modes, including SCREEN $FF to toggle between modes 0 (80col txt) and 2 (40col txt).

I've perused the Programmer's Reference, but don't see any BASIC command to GET the current value of this. I ask because my BASIC program is going to set the mode, and at the end, I'd like to return it to whatever it was when I found it. Is there such a command, or is there some memory location I should PEEK() to determine this?


BASIC command SCREEN

Posted: Mon Apr 05, 2021 11:05 pm
by kelli217

The KERNAL routine SCREEN is what you are looking for. When you call it, it returns the screen width in the X register and height in the Y register.

Calling it from BASIC:

10 SYS $FFED : X = PEEK(781) : Y = PEEK(782)


BASIC command SCREEN

Posted: Mon Apr 05, 2021 11:29 pm
by ZeroByte

Obviously, not to be confused with BASIC command SCREEN. ?



$FFED looks like a Kernal API call - how stable are the locations of X and Y after SYS calls? Is that "written in stone" by now, or "subject to change if M.Steil needs to move them around?

I guess they've gotta be read SOMEHOW. Thanks for the tip!

 


BASIC command SCREEN

Posted: Tue Apr 06, 2021 1:07 am
by Elektron72


1 hour ago, ZeroByte said:




how stable are the locations of X and Y after SYS calls?



After an SYS call, the X and Y registers are stored at 781 and 782, respectively ($030D and $030E in hex). These addresses are part of the vector area between $0300 and $0333. This area is fully backwards-compatible with the C64 (as stated in the Programmer's Reference Guide), and is not subject to any potential changes.


BASIC command SCREEN

Posted: Wed Apr 07, 2021 5:29 am
by kelli217

What @Elektron72 said is correct.

Here's a short tutorial for using SYS in BASIC 2.0:

The BASIC interpreter will first push the existing contents of the registers onto the stack, then load the A register with the value stored in location 780 ($030C), X with the value stored in location 781 ($030D), Y with the value stored in location 782 ($030E), and the status register with the value stored in location 783 ($030F). Then it will JSR to the address provided as the argument to the SYS command itself.

When (or if) the routine executes an RTS to return to BASIC, the reverse happens. The contents of A are stored in 780, etc. Finally, it will pull the previous register contents from before the SYS call back into the registers, and resume BASIC execution at the next instruction.


BASIC command SCREEN

Posted: Wed Apr 07, 2021 5:33 am
by JimmyDansbo

... and here is the c64-wiki article about it:

https://www.c64-wiki.com/wiki/SYS