Using memory below &0E00 from BASIC

Discuss all aspects of programming here. From 8-bit through to modern architectures.
User avatar
sydney
Posts: 1985
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Using memory below &0E00 from BASIC

Postby sydney » Mon Sep 25, 2017 3:11 pm

I'm currently writing a program in BASIC and it's likely to be too large for a standard beeb or electron but a Master will be fine since I can use the shadow screen modes leaving me approx 27.5k. Instead of using DIM to create large (and wasteful) arrays I'm using DIM to allocate some memory and using the ? operator to access it. What I'd like to do is utilise some of the lesser used memory below &0E00 for some of my tables which might save me enough RAM to make it work on a standard beeb/elk. Looking at allmem.txt on mdfs.net you can see pages &0A, &0B and &0C are set aside for things which are not going to be in use while my program is running. Am I likely to run into problems if I use this memory from BASIC?

Page &0A (10) - Serial input, transient command buffer
======================================================
&0A00-&0AFF Cassette/RS423 input buffer (nb: *not* used by LOAD)


Page &0B (11) - Soft key, Econet workspace
==========================================
BBC, Electron: Soft key definitions at &0B00-&0BFF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
&0B00-&0B10 Soft key pointers
&0B11-&0BFF Soft key definitions

Master: Econet workspace at &0B00-&0BFF
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
&0B01 Station number
&0B02 File server station number
&0B03 File server network number
&0B18 Print server type string


Page &0C (12) - Character definitions, Econet workspace
=======================================================
&0C00-&0CFF BBC, Electron: Font for ASCII 128-159
&0C00-&0CFF Master: Econet workspace

User avatar
kieranhj
Posts: 525
Joined: Sat Sep 19, 2015 10:11 pm
Location: Farnham, Surrey, UK

Re: Using memory below &0E00 from BASIC

Postby kieranhj » Mon Sep 25, 2017 3:36 pm

This doesn't answer your question (sorry!) but don't forget that on a machine with DFS and PAGE=&1900 you can safely use everything above &1100 if you have no files open.
Bitshifters Collective | Retro Code & Demos for BBC Micro & Acorn computers | https://bitshifters.github.io/

duikkie
Posts: 2689
Joined: Fri Feb 07, 2014 3:28 pm

Re: Using memory below &0E00 from BASIC

Postby duikkie » Mon Sep 25, 2017 3:36 pm

learn 6502 code then you have more memory to use. in basic you can use a,b,c even d if you don't use disc interrupt

User avatar
Rich Talbot-Watkins
Posts: 1117
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: Using memory below &0E00 from BASIC

Postby Rich Talbot-Watkins » Mon Sep 25, 2017 3:38 pm

I think page 9's fair game too, plus page 7 (used by BASIC as a immediate command line buffer). You could also try &380-&3E0, and the bottom of page 1 if you dare (should be OK provided you don't have a deep call stack).

User avatar
sydney
Posts: 1985
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Using memory below &0E00 from BASIC

Postby sydney » Mon Sep 25, 2017 3:43 pm

kieranhj wrote:This doesn't answer your question (sorry!) but don't forget that on a machine with DFS and PAGE=&1900 you can safely use everything above &1100 if you have no files open.

It doesn't help with that particular problem but it does potentially give me an extra &800 bytes! I'm actually writing the game in chunks which load each other to keep memory usage down. What is meant by 'no files open'? Would I be able to simply set PAGE to &1100 and load a BASIC program from disk or would this count as an open file?

duikkie wrote:learn 6502 code then you have more memory to use. in basic you can use a,b,c even d if you don't use disc interrupt

I'm able to program in 6502 but I want the challenge of doing it is BASIC as I've not done much BBC BASIC programming for more than 25 years!

duikkie
Posts: 2689
Joined: Fri Feb 07, 2014 3:28 pm

Re: Using memory below &0E00 from BASIC

Postby duikkie » Mon Sep 25, 2017 3:51 pm

if you use more then 1 file to load your lower pa.=&1200

User avatar
lurkio
Posts: 1283
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Using memory below &0E00 from BASIC

Postby lurkio » Mon Sep 25, 2017 5:01 pm

sydney wrote:What is meant by 'no files open'? Would I be able to simply set PAGE to &1100 and load a BASIC program from disk or would this count as an open file?

I think I'm right in saying that in this context "open files" refers to files that are being read from with INPUT# or written to with PRINT#.

I don't think it refers to files that are loaded or saved with LOAD, SAVE, *LOAD or *SAVE.

Correct me if I'm wrong, anyone!

More info here:

:idea:

User avatar
flaxcottage
Posts: 2794
Joined: Thu Dec 13, 2012 8:46 pm
Location: Derbyshire

Re: Using memory below &0E00 from BASIC

Postby flaxcottage » Mon Sep 25, 2017 5:45 pm

From examining a lot of BBC BASIC programs (educational mostly) pages &09, &0A, &0B, &0C were used extensively BITD as long as no soft key definitions were used and no characters needed re-designing. Pages &09 and &0A are very rarely used so that they amount to 'free' memory.

In DFS systems PAGE can be safely set to &1100 as long as your program does not read/write more than one file. Notts CC had a database program, INFORM, which used PAGE=&1100 to allow a largish program in MODE6 to work.

Another technique you could use is to set up an overlay area so that rarely-used procedures/functions can be loaded before use and over-written by another procedure after use. This technique is explained in one of the Beebug magazines and was used by the above-mentioned Inform program.

BBC BASIC has a lot of fascinating hacks that can be accessed by the adventurous programmer. 8) :D
- John

Currently running Level 4 Econet with BBC B, BBC B+ 128K, Master 128K, 4Mb A3000, 4Mb A3020, 4Mb A4000, 4Mb A5000 dual FDD; UK101; HP41CX setup; Psion 3a, 3mx and 5mx; Z88; TI-58c, TI-59 and printer, HP-16C programmer's calculator

crj
Posts: 315
Joined: Thu May 02, 2013 4:58 pm

Re: Using memory below &0E00 from BASIC

Postby crj » Tue Sep 26, 2017 2:05 am

flaxcottage wrote:Another technique you could use is to set up an overlay area so that rarely-used procedures/functions can be loaded before use and over-written by another procedure after use.

As I recall, it doesn't actually take much explaining:
  • Load the main program, sans overlay
  • T%=TOP
  • Raise LOMEM by the size of the largest overlay you want to load
  • For the sake of your sanity, if nothing else, start line numbers in the overlays above the last line number of the main program
  • When you want to use an overlay, load it at T%-2
I wrote a membership database for my school's computer society that was blindingly quick: it kept the database itself in RAM and had literally dozens of little overlays it could load to perform various administrative tasks.

User avatar
sydney
Posts: 1985
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Using memory below &0E00 from BASIC

Postby sydney » Tue Sep 26, 2017 9:08 am

sydney wrote:
kieranhj wrote:This doesn't answer your question (sorry!) but don't forget that on a machine with DFS and PAGE=&1900 you can safely use everything above &1100 if you have no files open.

It doesn't help with that particular problem but it does potentially give me an extra &800 bytes! I'm actually writing the game in chunks which load each other to keep memory usage down. What is meant by 'no files open'? Would I be able to simply set PAGE to &1100 and load a BASIC program from disk or would this count as an open file?


Since PAGE is &0E00 on a master I tried the following in the loader for my game:

Code: Select all

IF PAGE<>&0E00 THEN PAGE=&1100


This worked fine on a master but on a beeb I get the following:

Code: Select all

Disk read only at line 9


Line 9 is "9A$=GET$" in a loop waiting for a keypress to load the next program, line 11 is a CHAIN command so I'm guessing DFS doesn't like loading BASIC programs with PAGE at &1100. I'll experiment with other values and post my findings here.

User avatar
sydney
Posts: 1985
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Using memory below &0E00 from BASIC

Postby sydney » Tue Sep 26, 2017 9:13 am

duikkie wrote:if you use more then 1 file to load your lower pa.=&1200

Yes! It seems quite happy with PAGE=&1200 so I'll stick with that for now.

User avatar
lurkio
Posts: 1283
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Using memory below &0E00 from BASIC

Postby lurkio » Tue Sep 26, 2017 12:18 pm

sydney wrote:Since PAGE is &0E00 on a master I tried the following in the loader for my game:

Code: Select all

IF PAGE<>&0E00 THEN PAGE=&1100

This worked fine on a master but on a beeb I get the following:

Code: Select all

Disk read only at line 9

Line 9 is "9A$=GET$" in a loop waiting for a keypress to load the next program, line 11 is a CHAIN command so I'm guessing DFS doesn't like loading BASIC programs with PAGE at &1100.

It does if you do it like this:

:idea:

User avatar
Rich Talbot-Watkins
Posts: 1117
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: Using memory below &0E00 from BASIC

Postby Rich Talbot-Watkins » Tue Sep 26, 2017 12:42 pm

I believe the problem is that the !BOOT file is still somehow open when it CHAINs the program, and reducing PAGE before it's closed leads to workspace corruption and weird errors like that.

Try running your program manually instead of Shift+Break and see if it works OK. If so, maybe create a stub loader program, which just does this:

Code: Select all

10 *FX 119
20 PAGE=&1100
30 CHAIN "whatever"

User avatar
sydney
Posts: 1985
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne

Re: Using memory below &0E00 from BASIC

Postby sydney » Tue Sep 26, 2017 1:28 pm

Rich Talbot-Watkins wrote:I believe the problem is that the !BOOT file is still somehow open when it CHAINs the program, and reducing PAGE before it's closed leads to workspace corruption and weird errors like that.

Try running your program manually instead of Shift+Break and see if it works OK. If so, maybe create a stub loader program, which just does this:

Code: Select all

10 *FX 119
20 PAGE=&1100
30 CHAIN "whatever"


This is likely to be the problem so I added *FX119 as the first line in the loader and all is well.

User avatar
lurkio
Posts: 1283
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Using memory below &0E00 from BASIC

Postby lurkio » Tue Sep 26, 2017 2:34 pm

Rich Talbot-Watkins wrote:

Code: Select all

10 *FX 119
20 PAGE=&1100
30 CHAIN "whatever"

Incidentally (and assuming that no files are open), if a BASIC program changes the value of PAGE, what can subsequent lines of BASIC code in that same program do if they are to avoid crashing it?

I've done a few quick tests, and it looks like you have to avoid using GOTO and RUN, at least.

:?:

User avatar
Rich Talbot-Watkins
Posts: 1117
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: Using memory below &0E00 from BASIC

Postby Rich Talbot-Watkins » Tue Sep 26, 2017 3:05 pm

I'd assume anything which requires the interpreter to scan through the program from the start, e.g. calling a PROC for the first time (whose address hasn't yet been cached).

Here's another question: at what point is the !BOOT *EXEC file closed after it CHAINs the loader? Is it just left open indefinitely? (or, rather, until a game inevitably does a *TAPE and relocates itself to lower memory).

User avatar
lurkio
Posts: 1283
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Using memory below &0E00 from BASIC

Postby lurkio » Tue Sep 26, 2017 3:10 pm

Rich Talbot-Watkins wrote:I'd assume anything which requires the interpreter to scan through the program from the start, e.g. calling a PROC for the first time (whose address hasn't yet been cached).

Right, so anything else is fair game, then? A program could change PAGE and then run indefinitely as long as it didn't trigger a memory-scan with GOTO or an uncached PROC, etc.? (Not that you'd want to, of course! Just curious.)

Rich Talbot-Watkins wrote:Here's another question: at what point is the !BOOT *EXEC file closed after it CHAINs the loader? Is it just left open indefinitely? (or, rather, until a game inevitably does a *TAPE and relocates itself to lower memory).

I was asking exactly the same question the other day! I don't know the answer. But because of the undesirable effects of leaving an EXEC file open, all the !BOOTs on bbcmicro.co.uk do this:

    Code: Select all

    *BASIC
    *FX21,0
    CLOSE#0:CHAIN "loader"
Some games just won't run without the CLOSE#0.

:idea:

User avatar
flaxcottage
Posts: 2794
Joined: Thu Dec 13, 2012 8:46 pm
Location: Derbyshire

Re: Using memory below &0E00 from BASIC

Postby flaxcottage » Tue Sep 26, 2017 3:51 pm

RUN can be used if PAGE is changed provided OLD is issued before executing RUN.

It is possible to have several BASIC programs in memory starting at different PAGE values and use PAGE=&nnnn:OLD:RUN to switch between them. It is usual to place the command in the keyboard buffer or on a soft key and then send the soft key code to the keyboard buffer. That is what most of the Sherston programs do.

Memory locations &12,&13 hold the current value of PAGE I believe.

!BOOT if activated with *EXEC is never closed. That has given me many a headache when trying to 'crack' educational titles.
- John

Currently running Level 4 Econet with BBC B, BBC B+ 128K, Master 128K, 4Mb A3000, 4Mb A3020, 4Mb A4000, 4Mb A5000 dual FDD; UK101; HP41CX setup; Psion 3a, 3mx and 5mx; Z88; TI-58c, TI-59 and printer, HP-16C programmer's calculator

User avatar
Rich Talbot-Watkins
Posts: 1117
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: Using memory below &0E00 from BASIC

Postby Rich Talbot-Watkins » Tue Sep 26, 2017 4:20 pm

I'm turning this into a BBC BASIC quirks thread. Oh well...

So, for some reason BBC BASIC makes a distinction between 'immediate commands' like LIST, SAVE, etc, and the rest. You can't execute them in a program (they yield "Syntax error"), unlike most other BASICs. I'm not sure where it is but there's obviously an explicit check for this somewhere in the BASIC ROM, and I wonder why they didn't just allow it. Might've saved them a few bytes.

crj
Posts: 315
Joined: Thu May 02, 2013 4:58 pm

Re: Using memory below &0E00 from BASIC

Postby crj » Tue Sep 26, 2017 5:35 pm

flaxcottage wrote:!BOOT if activated with *EXEC is never closed. That has given me many a headache when trying to 'crack' educational titles.

Gosh, really? I never noticed that!

I'd always assumed it closed once you'd read the last character from it. Or, at the very least, the first time you tried to read a character and discovered there wasn't one.

(Is it worth a quick *DUMP just to check there are no extraneous characters after the final &0D in !Boot, by the way?)

User avatar
ctr
Posts: 94
Joined: Wed Jul 16, 2014 2:53 pm

Re: Using memory below &0E00 from BASIC

Postby ctr » Tue Sep 26, 2017 8:04 pm

Rich Talbot-Watkins wrote:So, for some reason BBC BASIC makes a distinction between 'immediate commands' like LIST, SAVE, etc, and the rest. You can't execute them in a program (they yield "Syntax error"), unlike most other BASICs. I'm not sure where it is but there's obviously an explicit check for this somewhere in the BASIC ROM, and I wonder why they didn't just allow it. Might've saved them a few bytes.

The interpreter already has to distinguish tokenised commands from tokenised functions and so on. It does this by splitting the various kinds of thing into different token number ranges. The "immediate commands" occupy their own token number range so it doesn't cost anything to ignore them at run-time.

User avatar
Rich Talbot-Watkins
Posts: 1117
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: Using memory below &0E00 from BASIC

Postby Rich Talbot-Watkins » Tue Sep 26, 2017 8:19 pm

But I assume it's the same code which executes BASIC as an immediate command or in a program, so there must be something which is checking that, and emitting 'syntax error' in the latter case. Most BASICs I've encountered would let you LIST, NEW, SAVE etc as a command inside a program, and back in the day I even remember wanting to be able to LIST myself (although I can't possibly imagine why now).

User avatar
lurkio
Posts: 1283
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Using memory below &0E00 from BASIC

Postby lurkio » Tue Sep 26, 2017 8:59 pm

Apropos of PAGE-whacking, I thought this was quite amusing:

Code: Select all

10 REPEAT
20 INPUT "PAGE=&" P$
30 PAGE=EVAL("&"+P$)
40 PRINT "PAGE=&";STR$~PAGE'
50 UNTIL 0

http://bbc.godbolt.org/?autoboot&disc=https://dl.dropboxusercontent.com/s/2rgnije5ik923gy/PAGEtest2.ssd

:idea:

User avatar
1024MAK
Posts: 6786
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...

Re: Using memory below &0E00 from BASIC

Postby 1024MAK » Tue Sep 26, 2017 9:12 pm

Rich Talbot-Watkins wrote:But I assume it's the same code which executes BASIC as an immediate command or in a program, so there must be something which is checking that, and emitting 'syntax error' in the latter case. Most BASICs I've encountered would let you LIST, NEW, SAVE etc as a command inside a program, and back in the day I even remember wanting to be able to LIST myself (although I can't possibly imagine why now).

I have used LLIST on a Spectrum before to print out part of a program under development. IIRC it was part of a subroutine.
I also found it useful to be able to use SAVE in a program, so that the program could save itself. Again mainly as part of the development code.
Being able to use NEW was useful as well. Gives a nice clean exit...

As good as BBC BASIC is, I always found the I/O device handling in BBC BASIC a bit odd.

Oh dear, this thread is going seriously off topic...

If anyone thinks a thread spit is warranted, shout out :wink:

Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki‬ - for answers to many questions...

User avatar
jgharston
Posts: 2756
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield

Re: Using memory below &0E00 from BASIC

Postby jgharston » Thu Sep 28, 2017 3:09 am

1024MAK wrote:As good as BBC BASIC is, I always found the I/O device handling in BBC BASIC a bit odd.

There is no device handing in BBC BASIC, all and any I/O handing is entirely and universally dealt with by the MOS. Otherwise, how on earth could anything other than BASIC do any I/O if BASIC handled the I/O?

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
1024MAK
Posts: 6786
Joined: Mon Apr 18, 2011 4:46 pm
Location: Looking forward to summer in Somerset, UK...

Re: Using memory below &0E00 from BASIC

Postby 1024MAK » Thu Sep 28, 2017 11:25 am

jgharston wrote:
1024MAK wrote:As good as BBC BASIC is, I always found the I/O device handling in BBC BASIC a bit odd.

There is no device handing in BBC BASIC, all and any I/O handing is entirely and universally dealt with by the MOS.

Exactly! (Well, apart from "PRINT", "INPUT", "INKEY" which send/receive data to the relevant OS calls...).

Mark
For a "Complete BBC Games Archive" visit www.bbcmicro.co.uk NOW!
BeebWiki‬ - for answers to many questions...

User avatar
Rich Talbot-Watkins
Posts: 1117
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: Using memory below &0E00 from BASIC

Postby Rich Talbot-Watkins » Thu Sep 28, 2017 12:25 pm

And it's surprising that there's no way of listing a program to the printer without getting the BASIC '>' prompt at the end, or a leading newline (LIST <Ctrl+B> <Return> <Ctrl+C>). Trying to type VDU2:LIST:VDU3 doesn't work because LIST doesn't execute commands after colons.

Obviously they ran out of keyword tokens (and ROM space), something which was rectified in BASIC V, but the lack of I/O commands made BBC BASIC quite unreadable to a novice. VDU 23;8202;0;0;0; Wossat then? Oh, turns the cursor off. Of course.

crj
Posts: 315
Joined: Thu May 02, 2013 4:58 pm

Re: Using memory below &0E00 from BASIC

Postby crj » Thu Sep 28, 2017 7:58 pm

I think you're judging the BBC Micro by quite harsh standards, there.

While "VDU 23;8202;0;0;0;" may look obtuse, it's still way better than poking at screen hardware directly, and way better than what most 8-bit microcomputer systems offered. Especially if you're on a second processor. Meanwhile, you do get the MOVE, DRAW and PLOT commands as convenient front-ends onto rather more important and frequently-used VDU runes.

There's a pretty tight limit to what a 16Kbyte BASIC interpreter can offer in the way of syntactic sugar!

User avatar
Rich Talbot-Watkins
Posts: 1117
Joined: Thu Jan 13, 2005 5:20 pm
Location: Palma, Mallorca

Re: Using memory below &0E00 from BASIC

Postby Rich Talbot-Watkins » Thu Sep 28, 2017 8:56 pm

Yeah, I'm being really harsh, I know! BBC BASIC was fantastic, with named PROCs/FNs, the indirection operators, and the built-in assembler among other cool features. But so it ought to have been! Most computers of the era had to share their 16k of ROM with the OS.

If I could have chosen, I'd probably have got rid of certain things which were peculiar to BBC BASIC but never used by anyone, e.g. COUNT and WIDTH spring to mind. Also CLG, which may just as well be VDU 16 (or whatever it is). I never used the TRACE stuff either, but that was a standard BASIC thing (TRON/TROFF). That could've made a bit of extra space for ON and OFF for the cursor at least - something virtually every program uses.

Just nitpicking really, because it's curious to pick it apart all these years later and find the odd quirks.

crj
Posts: 315
Joined: Thu May 02, 2013 4:58 pm

Re: Using memory below &0E00 from BASIC

Postby crj » Thu Sep 28, 2017 9:24 pm

COUNT is useful for doing tab-stops. WIDTH 132 was invaluable for wide-carriage dot matrix printers.

TRON and TROFF appear... not to exist?

On further reflection, I suspect a secondary reason cursor control has no dedicated keyword in BASIC is that it was added after OS 0.1?

(Incidentally, VDU23,1,0| and VDU23,1,1| are rather tidier ways of turning the cursor on and off than prodding the 6845 directly via VDU23,0 !)

Yes, BBC BASIC has the luxury of 16K all to itself when BASIC in the Spectrum, for example, had to share with the OS. On the other hand, I suspect that BASIC is the lion's share of that 16K in the Spectrum, with the OS being tiny. The depth and breadth of stuff in the BBC Micro OS, the modularity and extensibility, was staggering for that era and class of computer.


Return to “programming”

Who is online

Users browsing this forum: No registered users and 1 guest