$200-$258 BASIC Input Buffer and other useful memory

Basic and Machine Language

Moderator: Moderators

Robbie
Vic 20 Dabbler
Posts: 84
Joined: Tue Aug 11, 2020 4:36 am
Location: England

$200-$258 BASIC Input Buffer and other useful memory

Post by Robbie »

$200-$258 BASIC Input Buffer

Simple question - It is 'Input' as in the basic command INPUT? It looks like a reasonable chunk of useful memory.

Chysn - I see wAx uses $230-$258 for commands and breakpoints (free for the ML use when assembled). Is $200-$229 free while tinkering in wAx?

Is there anywhere else that's a useful chunk of usable memory if you're not using BASIC? It seems, from other threads, there are loads of Zero Page addresses I can use.

Chysn - As wAx is a 'wedge' assembler, do I need to leave these BASIC Zero Page addresses alone when developing?
Robbie
Vic 20 Dabbler
Posts: 84
Joined: Tue Aug 11, 2020 4:36 am
Location: England

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by Robbie »

...and I guess I can use screen and colour memory as temporary storage if I'm doing some heavy lifting...
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by chysn »

Robbie wrote: Tue Oct 13, 2020 3:11 pm Chysn - I see wAx uses $230-$258 for commands and breakpoints (free for the ML use when assembled). Is $200-$229 free while tinkering in wAx?
***
Chysn - As wAx is a 'wedge' assembler, do I need to leave these BASIC Zero Page addresses alone when developing?
This whole area, $200 to $258, is where BASIC temporarily stores stuff that you enter from the BASIC editor (including direct mode, BASIC code, and the INPUT statement) and, having that function, it's extremely volatile. Unless you're cutting BASIC out of the picture entirely, it's not a really good place to store code, whether you're using wAx or not.

You can use it for program data storage without any problems*. Just keep in mind that BASIC itself is going to clobber that space whenever you enter any kind of command.
Is there anywhere else that's a useful chunk of usable memory if you're not using BASIC? It seems, from other threads, there are loads of Zero Page addresses I can use.
Zero page is $00 to $FF, and there are lots of good zero page locations. Most of the time you won't put code there, but rather use it for pointers and little values that you use a lot. Appendix B of the wAx manual shows which memory locations wAx uses, but they can pretty much all be used during the course of your programs without causing any trouble. Perhaps the only exception is $05/$06 if you're using a plug-in tool, because that's the vector to it.

There are some good non-zero page locations for code. $33C to $3FF is popular. $2A1to $2FF is also good, but wAx optionally uses this area for its symbol table. If you don't use symbols, this area will be left untouched.

I'd recommend finding yourself a PDF of Mapping the VIC. It does a really good job of identifying usable locations.
Robbie wrote: Tue Oct 13, 2020 3:17 pm ...and I guess I can use screen and colour memory as temporary storage if I'm doing some heavy lifting...
There are almost always better alternatives, but I've used screen memory as usable space in my VIC-20 Brainf@*k interpreter. Keep in mind that color memory won't store entire bytes, only half-bytes (nybbles).

* In most cases, anyway. If you point BASIC's PRTSTR ($CB1E) routine at $02xx to print text, it'll copy that text to the BASIC variable storage area, which has caused much cursing on my part until I understood BASIC's hangup with that page.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
MCes
Vic 20 Afficionado
Posts: 458
Joined: Fri Jul 24, 2015 1:19 am
Location: Italy

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by MCes »

could be useful? (the "USEFUL MEMORY LOCATIONS" chapter...)
http://www.zimmers.net/cbmpics/cbm/vic/memorymap.txt
"Two things are infinite, the universe and human stupidity, and I am not yet completely sure about the universe." (Albert Einstein)
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by chysn »

VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by Mike »

Hi, Robbie,

as pointed out by chysn, there's room for small routines in $02A1..$02FF (the so-called program indirects) and $033C..$03FF (tape buffer).

Zero page usage is divided between BASIC ($00..$8F) and KERNAL ($90..$FA), $FB..$FE are unused by both. $FF is clobbered by float->string conversions and so also 'belongs' to BASIC.

$0100..$013F in the stack are used by the float->string conversion and the tape routines. If you're somewhat adventurous, you can use the stack area beginning at $0140 to hold short routines - the stack grows from $01FB downwards and it is up to your estimated stack usage how much space is available. ;)
Robbie wrote:$200-$258 BASIC Input Buffer
$0200..$0258 gets overwritten by the BASIC interpreter on practically each and every time input is read: BASIC line entry, INPUT, READ. MINIMON also uses this buffer for its own command line, but: a) doesn't use any routines in the BASIC interpreter at all, and b) limits the command line length to 64 characters, which frees the remaining 25 bytes for workspace use by MINIMON. :mrgreen:

For anything beyond small transient tools, you'd normally either reserve BASIC memory at bottom or top, or put the machine code into a program with BASIC stub. With a full RAM expansion, the +3K RAM at $0400..$0FFF and BLK5 ($A000..$BFFF) are blocked from BASIC use and these are also sensible places for medium size tools.

Greetings,

Michael
User avatar
Noizer
Vic 20 Devotee
Posts: 297
Joined: Tue May 15, 2018 12:00 pm
Location: Europa

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by Noizer »

Mike wrote: Wed Oct 14, 2020 11:15 am Hi, Robbie,
as pointed out by chysn, there's room for small routines in $02A1..$02FF (the so-called program indirects) and $033C..$03FF (tape buffer).
All right here and having sometimes 8 bytes more can save the day, so don‘t hesitate to place code starting from $0334 😅
Valid rule today as earlier: 1 Byte = 8 Bits
-._/classes instead of masses\_.-
Robbie
Vic 20 Dabbler
Posts: 84
Joined: Tue Aug 11, 2020 4:36 am
Location: England

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by Robbie »

It's a bit like our spare room - there's always another little corner that you can get squeeze more stuff in!

I've got no interest in BASIC beyond being able to use wAx with line numbers while developing and, I guess, using SYS to start the final ML build. Does that mean I can use BASIC ($00..$8F) for whatever I like, or will that mess things up for wAx? I suppose the final build will be ok there, but life will be a lot easier during development if I can use the real, final addresses.

I've just ordered the COMPUTE book from Lulu - postage to the UK is only about $3.44, which was a real surprise. Perhaps they have a print shop here too.
User avatar
aitsch
Vic 20 Amateur
Posts: 51
Joined: Sun Mar 08, 2020 12:54 pm
Location: Germany NS

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by aitsch »

I'm not sure that every location up to $8f can be used.
For example:
$cb stores the pressed key or $64 for no key.
Stored information will be lost here. I don't know if there other addresses which also used in ml.

aitsch
User avatar
chysn
Vic 20 Scientist
Posts: 1205
Joined: Tue Oct 22, 2019 12:36 pm
Website: http://www.beigemaze.com
Location: Michigan, USA
Occupation: Software Dev Manager

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by chysn »

Robbie wrote: Wed Oct 14, 2020 1:16 pm Does that mean I can use BASIC ($00..$8F) for whatever I like, or will that mess things up for wAx? I suppose the final build will be ok there, but life will be a lot easier during development if I can use the real, final addresses.
There are no memory locations you can use that will mess things up for wAx. Obviously, this is a lie, because there are things you can do that will stop BASIC from functioning properly. But wAx is specifically made to be unobtrusive, and the locations it uses are documented, and most of the time you don't need to think about it, aside from what I said above.

Messing things up for BASIC is a different story. Some of those zero page locations can make BASIC an inhospitable environment upon return. For example, the CHRGET routine lives from $73 to $8a, and if you break it, BASIC is dead until you reset. There are other locations that'll destabilize BASIC.

Even if you never plan on returning to BASIC, it's a good idea to stay off its lawn. For my games, I redirect the NMI vector to sort of "lock" the user into the game, and have the RESTORE key go back to the title screen. But, I don't do that until the game is completely done, and I'm careful to play by BASIC's rules to ease development.
I've just ordered the COMPUTE book from Lulu - postage to the UK is only about $3.44, which was a real surprise. Perhaps they have a print shop here too.
I think you'll get a lot out of this.
VIC-20 Projects: wAx Assembler, TRBo: Turtle RescueBot, Helix Colony, Sub Med, Trolley Problem, Dungeon of Dance, ZEPTOPOLIS, MIDI KERNAL, The Archivist, Ed for Prophet-5

WIP: MIDIcast BASIC extension

he/him/his
User avatar
Mike
Herr VC
Posts: 4841
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by Mike »

aitsch wrote:I'm not sure that every location up to $8f can be used.
For example:
$cb stores the pressed key or $64 for no key.
$CB is not in the range $00..$8F. ;) Also, "no key" is 64 decimal in that location, not $64.
Stored information will be lost here.
That's an issue with all addresses that might be changed by a background process or interrupt. They're "lost" for any storage by the foreground process.
I don't know if there other addresses which also used in ml.
TBH, there's always a machine code program running - even if it is the BASIC interpreter which handles the BASIC program as data input to process, no?

...

The main issue at hand is something other: is the program supposed to execute on its own, or is it supposed to run alongside other (BASIC) programs, or is it a "language" in the broadest sense (i.e. doesn't use any BASIC routines), or does it completely take over the hardware and doesn't even use any KERNAL routines or interrupts?

One important thing to know is: the BASIC interpreter calls some KERNAL routines to perform its work, but conversely the KERNAL *never* calls routines in the BASIC interpreter to do things. The sole two exceptions are BASIC cold- and warmstart but there the KERNAL then hands control over to BASIC and doesn't expect to "regain" control.

That means: if you only ever call KERNAL routines, and don't use any routines of the BASIC interpreter, $00..$8F are *completely* free for your program! There is no way $00..$8F will ever be changed by KERNAL calls, as there are never any side-effects from BASIC routines.

The converse is not true, that means: if you use BASIC routines, you not only have to take care what you're using of $00..$8F, but the routines of the BASIC interpreter might also call KERNAL routines, so $90..$FA are not a save place either.

Usually, the best bet for extra ZP variables/pointers are the locations shared between tape and RS232 operations. As long as neither of the two operate, you can use them for your own program with no issues. When a tape or RS232 operation is started, the KERNAL does not expect certain values there, it rather (re-)initialises them as necessary anyway - which also means there's no need to save and restore these locations. You'll find a good list of those elsewhere here in Denial. :)

...

Again, for bigger programs you'll have to reserve storage from the BASIC memory anyway, by lowering the roof in 55/56 (best for unexpanded or +3K) or raising the BASIC start in 43/44 (best for +8K or more). For example, MINIGRAFIK raises the BASIC start by 5 KB and thus reserves 4 KB for the bitmap and 1 KB for its own code. Putting MG into any of the small buffers obviously never would have worked.
Robbie
Vic 20 Dabbler
Posts: 84
Joined: Tue Aug 11, 2020 4:36 am
Location: England

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by Robbie »

Understood.

Is the console part of BASIC? The bit where you type on screen, and move the cursor around etc.
User avatar
srowe
Vic 20 Scientist
Posts: 1340
Joined: Mon Jun 16, 2014 3:19 pm

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by srowe »

Robbie wrote: Thu Oct 15, 2020 6:54 am Is the console part of BASIC? The bit where you type on screen, and move the cursor around etc.
The core key input and screen line handling are in the KERNAL, the BASIC line editing is in BASIC.
User avatar
aitsch
Vic 20 Amateur
Posts: 51
Joined: Sun Mar 08, 2020 12:54 pm
Location: Germany NS

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by aitsch »

Mike wrote: Thu Oct 15, 2020 3:49 am
aitsch wrote:I'm not sure that every location up to $8f can be used.
For example:
$cb stores the pressed key or $64 for no key.
$CB is not in the range $00..$8F. ;) Also, "no key" is 64 decimal in that location, not $64.
Ups!
This is what happens when you lie on the sofa in the evening and answer threads. :roll:
User avatar
aitsch
Vic 20 Amateur
Posts: 51
Joined: Sun Mar 08, 2020 12:54 pm
Location: Germany NS

Re: $200-$258 BASIC Input Buffer and other useful memory

Post by aitsch »

Mike wrote: Wed Oct 14, 2020 11:15 am Hi, Robbie,

as pointed out by chysn, there's room for small routines in $02A1..$02FF (the so-called program indirects) ...
94 bytes more for my current project sounds good.
i've tried to place this small test routine in this area (starts at $02a1):

Code: Select all

*=$1001
!byte $0b,$08, $e2,$07, $9e, $20, $36, $37, $33, $00,$00, $00 

*=$02a1			; starting at $02a1

  ldy #0
.loop
  tya
  sta $1e00,y
  lda #0
  sta $9600,y
  dey
  bne .loop
  rts
but for me programs in this location won't work.

why?

aitsch
Post Reply