Elementary BASIC question - loading another file [message #126220] |
Mon, 29 August 2005 16:34 |
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 |
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 |
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 |
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 #126265 is a reply to message #126254] |
Tue, 30 August 2005 11:14 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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/ **
|
|
|
|
|