Megalextoria
Retro computing and gaming, sci-fi books, tv and movies and other geeky stuff.

Home » Digital Archaeology » Computer Arcana » Commodore » Commodore 8-bit » Elementary BASIC question - loading another file
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Elementary BASIC question - loading another file [message #126220] Mon, 29 August 2005 16:34 Go to next message
Leif Bloomquist is currently offline  Leif Bloomquist
Messages: 1065
Registered: January 2012
Karma: 0
Senior Member
Hi all,

[Yes, I asked this on #c64friends a couple of weeks ago, but am still
looking for a tidier answer]

I'm writing a BASIC program and want to use a custom character set. The
character set is nominally located at $3000 (12288 decimal) which is smack
in the middle of the BASIC area on the 64 but still leaves lots of room for
my program and variables. I also want to load it in from disk as that will
be much faster than DATA statements (especially on an IDE64, the intended
platform).

So, when loading in some binary data in BASIC, it's usual practice to do
this, because the BASIC program restarts.

10 IF A=0 THEN A=1:LOAD"FILE",8,1

It is also usual practice to protect parts of memory from BASIC by lowering
the "top of data", i.e.

10 POKE 55,0: POKE 56,48:CLR

However - these two aren't compatible! Simply because the CLR statement
will wipe out the value of A.

Several of the suggestions offered previously involved SYS's to kernal
routines to load the file, but I couldn't get them to work. As a workaround
I suppose I could POKE a flag somewhere in memory unaffected by BASIC
instead of using a variable.

What's the correct/standard way to go about this?

Thanks
Leif

(Still having newbie moments after 15 years ;-)

--
Leif Bloomquist
leif (at) schema factor (dot) com
http://home.ica.net/~leifb/
Re: Elementary BASIC question - loading another file [message #126221 is a reply to message #126220] Mon, 29 August 2005 17:12 Go to previous messageGo to next message
Payton Byrd is currently offline  Payton Byrd
Messages: 1198
Registered: December 2011
Karma: 0
Senior Member
Leif Bloomquist wrote:

> Hi all,
>
> [Yes, I asked this on #c64friends a couple of weeks ago, but am still
> looking for a tidier answer]
>
> I'm writing a BASIC program and want to use a custom character set. The
> character set is nominally located at $3000 (12288 decimal) which is smack
> in the middle of the BASIC area on the 64 but still leaves lots of room for
> my program and variables. I also want to load it in from disk as that will
> be much faster than DATA statements (especially on an IDE64, the intended
> platform).
>
> So, when loading in some binary data in BASIC, it's usual practice to do
> this, because the BASIC program restarts.
>
> 10 IF A=0 THEN A=1:LOAD"FILE",8,1
>
> It is also usual practice to protect parts of memory from BASIC by lowering
> the "top of data", i.e.
>
> 10 POKE 55,0: POKE 56,48:CLR
>
> However - these two aren't compatible! Simply because the CLR statement
> will wipe out the value of A.
>
> Several of the suggestions offered previously involved SYS's to kernal
> routines to load the file, but I couldn't get them to work. As a workaround
> I suppose I could POKE a flag somewhere in memory unaffected by BASIC
> instead of using a variable.
>
> What's the correct/standard way to go about this?
>
> Thanks
> Leif
>
> (Still having newbie moments after 15 years ;-)
>
>
>
See if this code works:

10 IF A=0 THEN POKE 55,0: POKE 56,48: CLR
20 IF A=0 THEN A=1: LOAD"FILE",8,1

If you do this does the top of data stay the same? I'm assuming that
locations 55 and 56 won't change when line 20 causes the program to restart.

Can you manually configure the the memory correctly, then save the
memory contents to a file to load at the normal start of Basic? I know
this would be a pain during development, but you could just do this for
your release code.

--
Payton Byrd
Homepage - <http://www.paytonbyrd.com>
Blog - <http://blogs.ittoolbox.com/visualbasic/dotnet/>
Auctions - <http://search.ebay.com/_W0QQsassZpaytonQ2ebyrd>
Re: Elementary BASIC question - loading another file [message #126236 is a reply to message #126220] Mon, 29 August 2005 22:10 Go to previous messageGo to next message
Anton Treuenfels is currently offline  Anton Treuenfels
Messages: 105
Registered: December 2011
Karma: 0
Senior Member
"Leif Bloomquist" <spam@127.0.0.1301> wrote in message
news:11h6sats736j96d@news.supernews.com...
>
>
> I'm writing a BASIC program and want to use a custom character set. The
> character set is nominally located at $3000 (12288 decimal) which is smack
> in the middle of the BASIC area on the 64 but still leaves lots of room
for
> my program and variables. I also want to load it in from disk as that
will
> be much faster than DATA statements (especially on an IDE64, the intended
> platform).

You have to re-set the VIC-II chip to look at your new character set in any
case, right? So you could put that character set on pretty much any 2K
boundary - including under the BASIC or Kernel ROMs, I believe. Then you
wouldn't have to mess with changing the top of BASIC RAM.

> So, when loading in some binary data in BASIC, it's usual practice to do
> this, because the BASIC program restarts.
>
> 10 IF A=0 THEN A=1:LOAD"FILE",8,1
>
> It is also usual practice to protect parts of memory from BASIC by
lowering
> the "top of data", i.e.
>
> 10 POKE 55,0: POKE 56,48:CLR
>
> However - these two aren't compatible! Simply because the CLR statement
> will wipe out the value of A.
>
> Several of the suggestions offered previously involved SYS's to kernal
> routines to load the file, but I couldn't get them to work. As a
workaround
> I suppose I could POKE a flag somewhere in memory unaffected by BASIC
> instead of using a variable.
>

Hmm. One possible flag might be the value found in location 56:

10 IF PEEK(56)<>48 THEN POKE55,0: POKE56,48:CLR:LOAD"FILE",8,1

- Anton Treuenfels
Re: Elementary BASIC question - loading another file [message #126253 is a reply to message #126236] Tue, 30 August 2005 10:16 Go to previous messageGo to next message
Cameron Kaiser is currently offline  Cameron Kaiser
Messages: 1622
Registered: December 2011
Karma: 0
Senior Member
"Anton Treuenfels" <atreuenfels@earthlink.net> writes:

> 10 IF PEEK(56)<>48 THEN POKE55,0: POKE56,48:CLR:LOAD"FILE",8,1

Why is everyone still using LOAD?

10 poke55,0:poke56,48:clr:sys57812"file",8,1:poke780,0:sys65493

--
Cameron Kaiser * ckaiser@floodgap.com * posting with a Commodore 128
personal page: http://www.armory.com/%7Espectre/
** Computer Workshops: games, productivity software and more for C64/128! **
** http://www.armory.com/%7Espectre/cwi/ **
Re: Elementary BASIC question - loading another file [message #126254 is a reply to message #126253] Tue, 30 August 2005 10:28 Go to previous messageGo to next message
Etienne von Wettingfe[1] is currently offline  Etienne von Wettingfe[1]
Messages: 180
Registered: December 2004
Karma: 0
Senior Member
On 2005-08-30, Cameron Kaiser <ckaiser@floodgap.com> wrote:

> Why is everyone still using LOAD?
>
> 10 poke55,0:poke56,48:clr:sys57812"file",8,1:poke780,0:sys65493

I didn't know SYS could also load a file. This works on a stock
C64?

--
Etienne von Wettingfeld
Re: Elementary BASIC question - loading another file [message #126265 is a reply to message #126254] Tue, 30 August 2005 11:14 Go to previous messageGo to next message
iAN CooG is currently offline  iAN CooG
Messages: 613
Registered: April 2012
Karma: 0
Senior Member
Etienne von Wettingfeld <etienne@xs4none.nl.invalid> wrote:
> On 2005-08-30, Cameron Kaiser <ckaiser@floodgap.com> wrote:
>> 10 poke55,0:poke56,48:clr:sys57812"file",8,1:poke780,0:sys65493
>
> I didn't know SYS could also load a file.

Every Basic command have an entry point to rom routines. The 1st sys
57812 sets the filename and the device, the poke 780,0 instructs the 2nd
sys 65493 to perform a LOAD (with 1 would do a VERIFY)
This allows loading without the forced basic restart caused by LOAD
command.

> This works on a stock C64?

Of course.

--
-=[]=---iAN CooG/HokutoForce+TWT---=[]=-
Re: Elementary BASIC question - loading another file [message #126267 is a reply to message #126265] Tue, 30 August 2005 15:40 Go to previous messageGo to next message
Etienne von Wettingfe[1] is currently offline  Etienne von Wettingfe[1]
Messages: 180
Registered: December 2004
Karma: 0
Senior Member
On 2005-08-30, iAN CooG <iancoog@despammed.com> wrote:

>> I didn't know SYS could also load a file.
>
> Every Basic command have an entry point to rom routines. The 1st sys
> 57812 sets the filename and the device, the poke 780,0 instructs the 2nd
> sys 65493 to perform a LOAD (with 1 would do a VERIFY)
> This allows loading without the forced basic restart caused by LOAD
> command.

The standard manual doesn't mention this, it even states SYS does
not accept anything else but a decimal number. The USR function
does allow to pass a parameter, although I have never seen this
function used.

It's not to say I don't believe your SYS explantion, it's just
weird I've never come acros its use like this.

Digging in to the old manuals does raise the urge to set up
my system again. :-)

- -
Etienne von Wettingfeld

Opperdoes: Wat is Qemu?
Chaos_One: Een Google parameter.
Re: Elementary BASIC question - loading another file [message #126268 is a reply to message #126267] Tue, 30 August 2005 16:17 Go to previous messageGo to next message
dfevans is currently offline  dfevans
Messages: 50
Registered: July 2003
Karma: 0
Member
In article <slrndh9dg4.d2j.etienne@noddy.wettingfeld.nl>,
Etienne von Wettingfeld <etienne@xs4none.nl.invalid> wrote:
> The standard manual doesn't mention this, it even states SYS does
> not accept anything else but a decimal number.

Correct. However, in the code pointed to by the SYS, one is of
course free to parse as much of the following program text as one
pleases. There are mechanisms to do this within the BASIC ROM that are
used by the code that implements each command and function.

> The USR function
> does allow to pass a parameter, although I have never seen this
> function used.
>

USR can be kind of a pain, so people often just avoid it. It's easier
to use the scheme presented here, once you know how.

--
David Evans
Faculty of Computer Science dfevans@bbcr.uwaterloo.ca
Dalhousie University, Halifax, Canada http://bbcr.uwaterloo.ca/~dfevans/
Re: Elementary BASIC question - loading another file [message #126275 is a reply to message #126267] Tue, 30 August 2005 21:20 Go to previous messageGo to next message
Jerry Kurtz is currently offline  Jerry Kurtz
Messages: 244
Registered: June 2012
Karma: 0
Senior Member
Etienne von Wettingfeld wrote:
> On 2005-08-30, iAN CooG <iancoog@despammed.com> wrote:
>
>>> I didn't know SYS could also load a file.
>>
>> Every Basic command have an entry point to rom routines. The 1st sys
>> 57812 sets the filename and the device, the poke 780,0 instructs the 2nd
>> sys 65493 to perform a LOAD (with 1 would do a VERIFY)
>> This allows loading without the forced basic restart caused by LOAD
>> command.
>
> The standard manual doesn't mention this, it even states SYS does
> not accept anything else but a decimal number. The USR function
> does allow to pass a parameter, although I have never seen this
> function used.
>
> It's not to say I don't believe your SYS explantion, it's just
> weird I've never come acros its use like this.
>
> Digging in to the old manuals does raise the urge to set up
> my system again. :-)
>
> - -
> Etienne von Wettingfeld
>
> Opperdoes: Wat is Qemu?
> Chaos_One: Een Google parameter.

Just because its not mentioned in a manual doesn't mean it doesn't
work. It does work...
Re: Elementary BASIC question - loading another file [message #126277 is a reply to message #126268] Tue, 30 August 2005 21:41 Go to previous messageGo to next message
Cameron Kaiser is currently offline  Cameron Kaiser
Messages: 1622
Registered: December 2011
Karma: 0
Senior Member
dfevans@bcr10.uwaterloo.ca (David Evans) writes:

>> The standard manual doesn't mention this, it even states SYS does
>> not accept anything else but a decimal number.

> Correct. However, in the code pointed to by the SYS, one is of
> course free to parse as much of the following program text as one
> pleases. There are mechanisms to do this within the BASIC ROM that are
> used by the code that implements each command and function.

Couldn't have said it better myself. In this case, it's jumping directly
to the common portion of file operations in BASIC ROM that gets parameters
(accepts a filename, device and secondary address), as if it were preceded
by a LOAD keyword in this case.

>> The USR function
>> does allow to pass a parameter, although I have never seen this
>> function used.

> USR can be kind of a pain, so people often just avoid it. It's easier
> to use the scheme presented here, once you know how.

USR has its uses, um, no pun intended. I use it to implement routines where
I need to pass back data and I'd rather not use the "expense" of having to
assemble a value from PEEKs and multiplies.

For that matter, for EvW's benefit, USR() can be "made" to accept additional
values, such as X=USR(5),3,"XYZ" just by parsing additional BASIC text in
the same way. The first parameter is obligatory and placed in the floating
point accumulator, but the rest can be read in dynamically in the same way
you'd do for SYS.

--
Cameron Kaiser * ckaiser@floodgap.com * posting with a Commodore 128
personal page: http://www.armory.com/%7Espectre/
** Computer Workshops: games, productivity software and more for C64/128! **
** http://www.armory.com/%7Espectre/cwi/ **
Re: Elementary BASIC question - loading another file [message #126278 is a reply to message #126277] Tue, 30 August 2005 21:44 Go to previous messageGo to next message
dfevans is currently offline  dfevans
Messages: 50
Registered: July 2003
Karma: 0
Member
In article <43150a30$0$206$bb4e3ad8@newscene.com>,
Cameron Kaiser <ckaiser@floodgap.com> wrote:
> dfevans@bcr10.uwaterloo.ca (David Evans) writes:
>
>> USR can be kind of a pain, so people often just avoid it. It's easier
>> to use the scheme presented here, once you know how.
>
> USR has its uses, um, no pun intended. I use it to implement routines where
> I need to pass back data and I'd rather not use the "expense" of having to
> assemble a value from PEEKs and multiplies.
>

Oh, sure, I agree. And if you want to do floating point it can be
very handy.

--
David Evans
Faculty of Computer Science dfevans@bbcr.uwaterloo.ca
Dalhousie University, Halifax, Canada http://bbcr.uwaterloo.ca/~dfevans/
Re: Elementary BASIC question - loading another file [message #126284 is a reply to message #126253] Wed, 31 August 2005 00:29 Go to previous messageGo to next message
Rod Gasson is currently offline  Rod Gasson
Messages: 35
Registered: January 2005
Karma: 0
Member
"Cameron Kaiser" <ckaiser@floodgap.com> wrote in message
news:431469c1$0$283$bb4e3ad8@newscene.com...
> "Anton Treuenfels" <atreuenfels@earthlink.net> writes:
>
>> 10 IF PEEK(56)<>48 THEN POKE55,0: POKE56,48:CLR:LOAD"FILE",8,1
>
> Why is everyone still using LOAD?

Because it is a heck of a lot easier to remember than........

> 10 poke55,0:poke56,48:clr:sys57812"file",8,1:poke780,0:sys65493

Cheers
Rod
Re: Elementary BASIC question - loading another file [message #126305 is a reply to message #126284] Wed, 31 August 2005 08:58 Go to previous messageGo to next message
Cameron Kaiser is currently offline  Cameron Kaiser
Messages: 1622
Registered: December 2011
Karma: 0
Senior Member
"Rod Gasson" <rod@videocam.net.au> writes:

>>> 10 IF PEEK(56)<>48 THEN POKE55,0: POKE56,48:CLR:LOAD"FILE",8,1

>> Why is everyone still using LOAD?

> Because it is a heck of a lot easier to remember than........

>> 10 poke55,0:poke56,48:clr:sys57812"file",8,1:poke780,0:sys65493

Not necessarily -- I did that from memory. Once you know how ... ;)

I don't use naked LOADs in program text anymore because of all its
quirks and disadvantages. I only use them from direct mode, or in a
dynamic keyboard situation (essentially direct mode also).

--
Cameron Kaiser * ckaiser@floodgap.com * posting with a Commodore 128
personal page: http://www.armory.com/%7Espectre/
** Computer Workshops: games, productivity software and more for C64/128! **
** http://www.armory.com/%7Espectre/cwi/ **
Re: Elementary BASIC question - loading another file [message #126306 is a reply to message #126305] Wed, 31 August 2005 09:34 Go to previous messageGo to next message
Stealth is currently offline  Stealth
Messages: 164
Registered: June 2005
Karma: 0
Senior Member
Thus spoke Cameron Kaiser:
> I don't use naked LOADs in program text anymore because of all its
> quirks and disadvantages. I only use them from direct mode, or in a
> dynamic keyboard situation (essentially direct mode also).

Er, what exactly are the quirks and disadvantages of using a bare LOAD?
Re: Elementary BASIC question - loading another file [message #126307 is a reply to message #126284] Wed, 31 August 2005 10:40 Go to previous messageGo to next message
Jim Brain is currently offline  Jim Brain
Messages: 962
Registered: August 2012
Karma: 0
Senior Member
Rod Gasson wrote:
> "Cameron Kaiser" <ckaiser@floodgap.com> wrote in message
> news:431469c1$0$283$bb4e3ad8@newscene.com...
>
>> "Anton Treuenfels" <atreuenfels@earthlink.net> writes:
>>
>>
>>> 10 IF PEEK(56)<>48 THEN POKE55,0: POKE56,48:CLR:LOAD"FILE",8,1
>>
>> Why is everyone still using LOAD?
>
>
> Because it is a heck of a lot easier to remember than........
>
>
>> 10 poke55,0:poke56,48:clr:sys57812"file",8,1:poke780,0:sys65493

I second that.

Jim


--
Jim Brain, Brain Innovations
brain@jbrain.com http://www.jbrain.com
Dabbling in WWW, Embedded Systems, Old CBM computers, and Good Times!
Re: Elementary BASIC question - loading another file [message #126319 is a reply to message #126306] Wed, 31 August 2005 23:09 Go to previous messageGo to next message
Cameron Kaiser is currently offline  Cameron Kaiser
Messages: 1622
Registered: December 2011
Karma: 0
Senior Member
"Stealth" <protostealth@*spamblocker*hotmail.com> writes:

>> I don't use naked LOADs in program text anymore because of all its
>> quirks and disadvantages. I only use them from direct mode, or in a
>> dynamic keyboard situation (essentially direct mode also).

> Er, what exactly are the quirks and disadvantages of using a bare LOAD?

- Program insists on starting from the beginning. Although this behaviour
is useful for chaining (which was the rationale for it doing so),
- you can only chain programs that are smaller than the first, so as a
launcher, it's useless, and
- handling disk errors is less graceful because your program simply starts
over if a disk error occurs, so extra weird logic is needed for that, and
- you have to resort to convoluted nonsense like this if you use it to
LOAD ML routines because of it as well.

If you learn the "magic incantation" and use this formula as a primitive
BLOAD, then you can still program sequentially and maintain things in a
sensible order.

--
Cameron Kaiser * ckaiser@floodgap.com * posting with a Commodore 128
personal page: http://www.armory.com/%7Espectre/
** Computer Workshops: games, productivity software and more for C64/128! **
** http://www.armory.com/%7Espectre/cwi/ **
Re: Elementary BASIC question - loading another file [message #126322 is a reply to message #126319] Wed, 31 August 2005 23:38 Go to previous messageGo to next message
alan[1][2] is currently offline  alan[1][2]
Messages: 102
Registered: December 2004
Karma: 0
Senior Member
No Message Body
Re: Elementary BASIC question - loading another file [message #126402 is a reply to message #126220] Fri, 02 September 2005 19:51 Go to previous message
White Flame \(aka Dav is currently offline  White Flame \(aka Dav
Messages: 246
Registered: July 2003
Karma: 0
Senior Member
"Leif Bloomquist" <spam@127.0.0.1301> wrote in message
news:11h6sats736j96d@news.supernews.com...
> It is also usual practice to protect parts of memory from BASIC by
lowering
> the "top of data", i.e.
>
> 10 POKE 55,0: POKE 56,48:CLR

The top of BASIC space is where strings go, so you don't have to worry about
changing that address until right before you start using strings. If the
LOAD is storing data to $4000 or whatever, and your program code and the
variables you used before the LOAD don't reach there, nothing should go
wrong with setting the top-of-BASIC and doing the CLR after the LOAD.

--
White Flame (aka David Holz)
http://www.white-flame.com/
(spamblock in effect)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: What is the difference between 1084S-D1 and 1084S-D2?
Next Topic: Unexpected prog lift (SID music)
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Tue Apr 23 16:09:47 EDT 2024

Total time taken to generate the page: 0.20799 seconds