BASIC command SCREEN

Chat about anything CX16 related that doesn't fit elsewhere
Post Reply
ZeroByte
Posts: 714
Joined: Wed Feb 10, 2021 2:40 pm

BASIC command SCREEN

Post 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?

kelli217
Posts: 541
Joined: Sun Jul 05, 2020 11:27 pm

BASIC command SCREEN

Post 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)

ZeroByte
Posts: 714
Joined: Wed Feb 10, 2021 2:40 pm

BASIC command SCREEN

Post 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!

 

Elektron72
Posts: 137
Joined: Tue Jun 30, 2020 3:47 pm

BASIC command SCREEN

Post 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.

kelli217
Posts: 541
Joined: Sun Jul 05, 2020 11:27 pm

BASIC command SCREEN

Post 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.

User avatar
JimmyDansbo
Posts: 476
Joined: Sun Apr 26, 2020 8:10 pm
Location: Denmark
Contact:

BASIC command SCREEN

Post by JimmyDansbo »


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

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

Visit my Github repo
or my personal site with CX16/C64/6502 related information.
Feel free to contact me regarding any of my projects or even about meeting up somewhere near Denmark
Post Reply