PUSH DIR & POP DIR IN CBM BASIC

For posting library code and examples.
Post Reply
User avatar
ahenry3068
Posts: 1131
Joined: Tue Apr 04, 2023 9:57 pm

PUSH DIR & POP DIR IN CBM BASIC

Post by ahenry3068 »

This example program in ROM BASLOAD format has 5 very useful GOSUBS and a useful FUNCTION.

In this code the "Directory Stack" is a Bank of Hi-Ram. I'm using 63 in this example code but it could
be any available Bank. Contained in the Variable Dir.Stack

If your code needs to access multiple devices its also written so you could swap out Stacks You would need to save the values of the variables DEVICE, Dir.Stack, and Dir.Ptr and Dir.Level (all REAL numbers). Set Dir.Stack to a different Bank, Set Dir.Level to 0. and set DEVICE to the New Device #. Call GetCWD again. Then you have another Stack for the New Device. You should call GetCWD after each DEVICE Swap


DEF FN SW(X) Takes X between -32768 and 65535 and converts it to the corresponding "Signed Value" between -32768 and 32767 so that AND & OR can be used on it or it can be assigned to an INTEGER. Bitwise ANDs and ORs only work in BASIC correctly on signed values in that range. Error if X<-32768 or X>65535 GOSUB GetCWD Populates the variable CWD$ with the Current Working Directory. GOSUB PUSHDIR GetCWD needs to be called prior to first call to PUSHDIR. If using this procedure you need to use ONLY this procedure and POPDIR to navigate the Directory tree. Prior to calling PUSHDIR, set the variable New.Dir$ to contain the Directory to CD to. Upon calling it saves the Current Directory position on the "Stack" and CD's to New.Dir$. CWD$ is correctly populated before RETURN. GOSUB POPDIR "POPS" The previous Directory off the "Stack". CWD$ is correctly populated before RETURN GOSUB POKE.STRING Stores the String Variable S$ at the address contained in Variable SAddr Stores the string Data "Pascal" style with length byte followed by string data. GOSUB PEEK.STRING Returns the String at SAddr (previously stored with POKE.STRING (or possibly other PASCAL style string)) returns the value in S$


HERES THE CODE:
PUSHPOP.zip
(4.25 KiB) Downloaded 121 times
Post Reply