Preserve or Restore Values

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Preserve or Restore Values

Post by GreyGhost »

Hey all,

A program I am working on alters memory, screen location and size, and character set location(36864,36865,36866,36867,36869,52,56,644, and 648. Is there a magic SYS call that I can use to restore all of these locations and continue to run my program without a reset, or should I just save the values I change to variables and recall them back when I need too?

Later,
Rob
User avatar
Wilson
Vic 20 Enthusiast
Posts: 190
Joined: Mon Sep 28, 2009 7:19 am
Location: Brooklyn, NY

Post by Wilson »

Yup, there's a SYS for that. 58811 initializes the VIC registers from the ROM table. If you also wish to reset the cursor to the home position use 58805.
Bacon
for breakfast
Posts: 578
Joined: Mon Apr 19, 2004 8:07 am

Post by Bacon »

Sounds like a tip that should be in the "ROM calls" sticky thread.
Bacon
-------------------------------------------------------
Das rubbernecken Sichtseeren keepen das cotton-pickenen Hands in die Pockets muss; relaxen und watschen die Blinkenlichten.
User avatar
Wilson
Vic 20 Enthusiast
Posts: 190
Joined: Mon Sep 28, 2009 7:19 am
Location: Brooklyn, NY

Post by Wilson »

Bacon wrote:Sounds like a tip that should be in the "ROM calls" sticky thread.
Good idea.
FD22
Vic 20 Hobbyist
Posts: 148
Joined: Mon Feb 15, 2010 12:31 pm

Post by FD22 »

It might be worth noting that an application that is trying to be well-behaved by resetting the VIC registers after completion to their prior values, should not make the assumption that those values were the ROM-initialised ones...

I guess it depends on the objective - to reset the VIC to it's warm-start state (which is what that ROM routine does) or to reset it to the way it was before the app made any changes during it's execution. So, for example, an app that is a 'helper' in some way (maybe running on an IRQ or from CHARGOT) should definitely put any VIC registers back to how they were before it ran, not how they were after warm-start.

On the other hand, an app that is the 'main' task (a game, utility, etc) that does not reasonably expect to co-exist with other apps, could legitimately reset the VIC to it's warm-start values when exiting.
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Post by GreyGhost »

I guess I'll get into the meat of it. Maybe there is a better way to do what I want. The program I am working on is a loader that displays a 128x128 pixel picture, waits a few seconds and then loads the main program. The main program doesn't take into account for the screen size change, so I was trying to restore the video before the main program was loaded. The SYS calls above work as expected, but leave the display looking at some area of RAM not the intended 7680 location I was expecting. I even POKEd 30 back into location 648 to try to fix this to no avail. Can I maybe do a warm start and use the dynamic keyboard technique or something like that? Or use the input buffer?

Any ideas?
Rob
User avatar
Wilson
Vic 20 Enthusiast
Posts: 190
Joined: Mon Sep 28, 2009 7:19 am
Location: Brooklyn, NY

Post by Wilson »

The values stored in the KERNAL's table for $9005 (and bit 7 of $9002 I believe) do indeed position the video matrix elsewhere. Presumably to the positions for the expanded Vic-20, but I haven't verified this myself.
For some reason this didn't occur to me before. My apologies.

I haven't tested it, but, try 58648. It initializes IO, clears the screen, positions the cursor HOME, and sets the screen pointers. It only touches $9005 and $9002, so you'll still want to call the previously mentioned SYS to reinitialize the others. The two routines are actually located right next to each other. :)
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Post by GreyGhost »

Thanks. I'll give it a shot and let you know how it works.

It is a stand alone game I have been working on and assumes a freshly turned on unexpanded Vic.
Last edited by GreyGhost on Sun Aug 21, 2011 9:06 am, edited 1 time in total.
Rob
User avatar
GreyGhost
Vic 20 Nerd
Posts: 525
Joined: Wed Oct 05, 2005 11:10 pm

Post by GreyGhost »

Ok, this combination seems to leave me where I want to be:

POKE648,30:SYS58811:SYS58648

Thanks for the help.
Rob
User avatar
Wilson
Vic 20 Enthusiast
Posts: 190
Joined: Mon Sep 28, 2009 7:19 am
Location: Brooklyn, NY

Post by Wilson »

Yeah, 648 is set after the RAM test on start up and afaik nowhere else in the KERNAL. Obviously that will wipe your memory in the process. As long as the POKE works, that's not too ugly of a solution I guess.
Post Reply