[riscosfr] C from BASIC

  • From: Rick Murray <heyrick@xxxxxxxxx>
  • To: riscosfr@xxxxxxxxxxxxx
  • Date: Sun, 07 Jan 2018 20:45:37 +0100

Salut!
Please excuse the English, it's a quick message to David that might be of 
interest to others...
Following a brief mention here about calling C code from BASIC, so since the 
weather was unpleasant, I decided to waste this afternoon seeing what was 
actually involved in getting something working in order that one might be able 
to:   PROCprintf("\""This is silly!\""\n")or the like.
Well, the first thing you need is to have around 11K of data (jump tables, 
static data tables, and a "workspace" big enough to hold the initial stack 
chunk (4K)).
But, and here's the kicker. You cannot call kernel_init() because that sets up 
a lot of state and environment handlers that utterly trash BASIC. You CANNOT 
return to BASIC after calling this, and attempting to undo the damage (by 
saving/restoring all of the low level handlers) stiffs the machine. C'est 
génial!
The solution is to manually set up the static data tables - which means delving 
deep into CLib's code to figure out what is going on. And, of course, there's 
all the stuff with offsets of -540 and -536 so C functions can find their 
data/workspace.
After three hours and countless time staring at the sources (ie 
kernel.s.k_body), I gave up. I think we can say that there's a reason why other 
people haven't already worked out clever ways to call CLib functions from BASIC.
Oh well. Had nothing better to do. Now I'll go watch Citrus.

Amicalement,
Rick.

null

Other related posts: