It is currently Sun May 28, 2017 3:34 am



Welcome
Welcome to rfobasic

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. In addition, registered members also see less advertisements. Registration is fast, simple, and absolutely free, so please, join our community today. **You are not required to provide truthful information to any registration questions. Be whomever you wish to be.!


Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: display mode manager
Unread postPosted: Fri Oct 23, 2015 5:04 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 440
One of the frustrations I have with BASIC! is managing the display modes.. I can't keep track of what's open and closed.
These functions I made today do a lot of the work with some limitaions. You first call dinit() to initialize it to console mode then
whenever you want to change a mode you do dmode(m$) where m$=console, html or gr.. It's a little messy because it uses the file mode.txt to keep track of the current setting and things will get screwed up if you use any open or close commands outside of it.

Still a nice thing about it is that it will automatically close the old mode, open the new one or not bother if it's the same. Seems to work pretty well so far.



Code:
FN.DEF writeln(f$, msg$)
TEXT.OPEN w, fh, f$
TEXT.WRITELN fh, msg$
TEXT.CLOSE fh
FN.END

FN.DEF readln$(f$)
FILE.EXISTS isoldfile, f$
IF isoldfile
  TEXT.OPEN r,fh3,f$
  TEXT.READLN fh3, a$
ELSE
  LET A$=""
ENDIF
FN.RTN a$
FN.END


! init display mode manager
fn.def dinit()
writeln("mode.txt","0")
fn.end

! change display mode to console, html or gr(aphics)
fn.def dmode(m$)
if m$="console" then m=0
if m$="html" then m=1
if m$="gr" then m=2

oldm=val(readln$("mode.txt"))
if val(readln$("mode.txt"))=m
fn.rtn m
endif
writeln("mode.txt",int$(m))
if oldm=1
html.close
endif
if oldm=2
  gr.close
endif
if m=1
  html.open 0
  pause 500
endif
if m=2
gr.open 255,0,0,0,0
pause 500
endif
fn.end




Another thing you might want to do is trap for errors with ONERROR:

Code:
ONERROR:
dmode("console")
err$ = "The following error occurred: "+CHR$(10)
err$ += GETERROR$()
DIALOG.MESSAGE , err$, q, "OK"
EXIT


Top
 Profile  
 
 Post subject: Re: display mode manager
Unread postPosted: Wed Oct 28, 2015 6:38 am 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2797
Location: Colorado, U.S.
cterp wrote:
things will get screwed up if you use any open or close commands outside of it.
Why's that, cterp? I thought you could have lots of files open at once.

- Marc


Top
 Profile  
 
 Post subject: Re: display mode manager
Unread postPosted: Wed Oct 28, 2015 10:53 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 440
No I meant HTML and GR open and close


Top
 Profile  
 
 Post subject: Re: display mode manager
Unread postPosted: Sat Oct 31, 2015 11:32 pm 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2797
Location: Colorado, U.S.
Ah, I see. Sorry.

Would it be useful to have a command that tells you the current mode? To fix bugs in v01.88 I had to add a ContextManager that does approximately what your program does -- not to set modes but to keep track of them.

- Marc


Top
 Profile  
 
 Post subject: Re: display mode manager
Unread postPosted: Sun Nov 01, 2015 3:27 pm 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 440
That would be great!


Top
 Profile  
 
 Post subject: Re: display mode manager
Unread postPosted: Tue Dec 29, 2015 6:26 am 
Offline

Joined: Wed Apr 15, 2015 3:57 am
Posts: 440
I just learned about the global bundle trick... this seems faster I think:


Code:
BUNDLE.CREATE global %' 'global' bundle pointer = #1
BUNDLE.PUT global, "mode", "html"

! init display mode manager
FN.DEF dinit()
let s$="<html><body style=\"background-color:black\"></body></html>"
HTML.OPEN 0
html.load.string s$
bundle.put 1,"mode","html"
FN.END


! change display mode to console,html or gr(aphics)
FN.DEF dmode(m$)
bundle.get 1,"mode",oldm$
IF oldm$=m$ THEN FN.RTN 0
bundle.put 1,"mode",m$
IF oldm$="html" then HTML.CLOSE
IF oldm$="gr" then GR.CLOSE
IF m$="html" THEN HTML.OPEN 0
IF m$="gr" then GR.OPEN 255,0,0,0,0,1
pause 300
FN.END



Top
 Profile  
 
 Post subject: Re: display mode manager
Unread postPosted: Mon Jan 04, 2016 8:29 am 
Offline

Joined: Thu Jan 31, 2013 7:51 am
Posts: 76
Dear Marc,

I can't find the ContextManager that you wrote about in your post (at least not in the documentation for 1.88). Has it been added? And if not, would it be possible to add it in a later version?

All the best,

**örn


Top
 Profile  
 
 Post subject: Re: display mode manager
Unread postPosted: Mon Jan 18, 2016 2:26 am 
Offline

Joined: Wed Oct 03, 2012 9:53 am
Posts: 2797
Location: Colorado, U.S.
**örn, the ContextManager is not visible to a BASIC! program, so I did not put it in the documentation.

A command to return the current "mode" (Console, Graphics, or HTML) would get its information from the ContextManager.

Is there something else you want to do with the ContextManager?

- Marc


Top
 Profile  
 
 Post subject: Re: display mode manager
Unread postPosted: Tue Jan 19, 2016 3:22 am 
Offline

Joined: Thu Jan 31, 2013 7:51 am
Posts: 76
No, that is just what I want to use it for :)

What is the command for getting the mode from the ContextManager?

/**örn


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
suspicion-preferred