Finding HIMEM on the Tube

Discuss all aspects of programming here. From 8-bit through to modern architectures.
User avatar
hjalfi
Posts: 70
Joined: Sat May 13, 2017 10:17 pm
Location: Zürich, Switzelrand
Contact:

Finding HIMEM on the Tube

Postby hjalfi » Mon Sep 25, 2017 10:40 pm

The docs say I can use OSBYTE 0x84 to read the top of user memory, a.k.a. HIMEM. This works fine on a normal B or Master, returning either the base of video memory or 0x8000.

On the Tube, it (according to the manual) returns the load address of the currently running program; which is normally 0x8000 for Basic or &B800 for HiBasic.

The problem is... *RUN programs count as programs for the purposes of OSBYTE 0x84. So this happens:

Code: Select all

*GO F800
*INFO COW/OUT
COW/OUT    00000800 00000800 000004F7
*COW/OUT
LOMEM is: 0x0D26
HIMEM is: 0x0800


I could just detect that I'm on the Tube and use a hardcoded value of 0xF800 instead of calling OSBYTE 0x84, but that seems antisocial. Is there a better way to do this?

(Incidentally, VDFS always loads into the I/O memory, regardless of how the high bits of the address are set. This can cause Hilarious Results when the program runs if it happens to stomp over the sound and envelope workspace. Ask me how I know!)

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

Re: Finding HIMEM on the Tube

Postby crj » Tue Sep 26, 2017 1:37 am

I guess the "official" answer is that you ought to be assembling your program to run at &F300 instead of &800. Then HIMEM is a sensible value and all is well.

Is there any reason for you not to do this? I mean, if you're assembling to load at &800, you've already committed to running on a second processor!

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

Re: Finding HIMEM on the Tube

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

hjalfi wrote:The docs say I can use OSBYTE 0x84 to read the top of user memory, a.k.a. HIMEM. This works fine on a normal B or Master, returning either the base of video memory or 0x8000.
On the Tube, it (according to the manual) returns the load address edit: execution address of the currently running program; which is normally 0x8000 for Basic or &B800 for HiBasic.
The problem is... edit: any *RUN programs count as programs for the purposes of OSBYTE 0x84. So this happens:

Yeah, that's an annoying bug. I use this code to deal with it:

Code: Select all

  .start
  TSX:LDY &102,X:INY:CPY #&F9   :\ Check if on second processor
  BCC start2
  LDA &103,X:STA &EE:STA &F2    :\ Restore caller's environment
  LDA &104,X:STA &EF:STA &F3
  .start2

See Writing machine code utilities that interact with BASIC.

Code: Select all

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


Return to “programming”

Who is online

Users browsing this forum: No registered users and 1 guest