Passing a flag to language ROM entry point

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
tom_seddon
Posts: 226
Joined: Mon Aug 29, 2005 11:42 pm
Contact:

Passing a flag to language ROM entry point

Post by tom_seddon » Sat Jun 30, 2018 9:35 pm

Suppose you'd like to have multiple * commands that activate a language ROM, and have each * command do something rather different. In effect, you'd like to pass an argument to the language ROM entry point - nothing fancy, probably just 1 byte would be sufficient. But what's a good way of doing this? It needs to work in the second processor, which is the reason for using the language entry point for doing this in the first place, rather than just doing it as a service call like normal people...

My current plan is to store a value in the ROM relative workspace table at &DF0. (This ROM doesn't use relative workspace, so this value is otherwise unused.) Then on entry, use OSBYTE 252 to figure out the ROM slot of the language, then OSWORD 6 to read &DF0+x.

One thing you can do in the second processor, that could cause problems with this, is just *RUN the ROM, which leaves the current language ROM unchanged. Ideally, that ought to work, or at least not break unnecessarily, so I suppose pick a value for &DFx that's unlikely to be a valid relative workspace page. That's not going to be 100% foolproof, but I bet it will work often enough to be useful...

Better suggestions sought! :)

--Tom
Last edited by tom_seddon on Sat Jun 30, 2018 9:36 pm, edited 1 time in total.

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

Re: Passing a flag to language ROM entry point

Post by jgharston » Sat Jun 30, 2018 10:39 pm

The way to do this is to use OSBYTE 1. Your *command writes its data to OSBYTE 1, and your language startup reads it.

.L8000:JMP Language
.L8003:JMP Service
...
.Service4
\ Gets to...
.mycommand
JSR ParseNumber:TAX:\ X=8-bit parameter
LDA #1:JSR OBYTE :\ Set user/return code
LDX &F4 :\ X=my ROM number
LDA #142:JMP OSBYTE :\ Enter me as a language
...
.Language
LDX #0:LDA #1:JSR OSBYTE :\ Read user/return code
\ X has the parameter you used with your *command

You can also use OSBYTE 1 to return a return code when a program returns to a caller.
Last edited by jgharston on Sat Jun 30, 2018 10:41 pm, edited 2 times in total.

Code: Select all

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

tom_seddon
Posts: 226
Joined: Mon Aug 29, 2005 11:42 pm
Contact:

Re: Passing a flag to language ROM entry point

Post by tom_seddon » Sat Jun 30, 2018 11:04 pm

I was a bit put off by the lack of clarity in the AUG about what exactly that flag is for ("this OSBYTE is left free for user applications"), and the NAUG is vaguer yet :)

But it it's only ever been used for this purpose in practice, then I'm happy to just follow suit.

I suppose a change of language means all bets are off anyway.

--Tom
Last edited by tom_seddon on Sat Jun 30, 2018 11:05 pm, edited 1 time in total.

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

Re: Passing a flag to language ROM entry point

Post by jgharston » Sat Jun 30, 2018 11:12 pm

Just typed up for the Wiki.

I've observed this method used in about a dozen ROM languages. There's also a more complicated method that lets your language read a free-form parameter line, but I'll have to dig out some disassembled source to get it right.

Code: Select all

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

Post Reply