Using the Arithmetic Stack from a job, not S*BASIC

Anything QL Software or Programming Related.
Post Reply
User avatar
NormanDunbar
Forum Moderator
Posts: 2470
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Using the Arithmetic Stack from a job, not S*BASIC

Post by NormanDunbar »

My mind has gone on this matter, and I'm unable to find anything helpful in either the old QDOS manuals, Pennel, Dickins etc, or the new SMSQ/E Manual from Wolfgang.

I'm writing a task for the next edition of the eMagazine, and I need to be able to use the maths stack and arithmetic package to do various things. For the life of me I can't remember if (a) this is permitted and (b) how the hell to do it!

If anyone can give me a prod in the right direction, I'd be grateful. I'm looking to convert a string of ASCII digits to an value on the maths stack using CN_DTOF (QDOS) aka CV.DECFP (SMSQ).

Entry:

D7.L = pointer 1 past the end of the (input) buffer (relative A6)
A0.L = pointer to the input buffer (relative A6)
A1.L = Pointer to maths stack (relative A6)

And, is it ok to grab the current maths stack pointer from BV_CHRIX (QDOS) ???? (SMSQ) as I would normally do in a SuperBASIC extension?

I need a drink! ;) (Or maybe that's the problem!)

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Using the Arithmetic Stack from a job, not S*BASIC

Post by mk79 »

Just provide your own stack with enough space and make that relative to A6 (whether subtracting A6 from A1 or setting A6 to 0 is your choice). DON‘T grab the Basic stack, it‘s not yours to use!


User avatar
NormanDunbar
Forum Moderator
Posts: 2470
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: Using the Arithmetic Stack from a job, not S*BASIC

Post by NormanDunbar »

Interesting, that's what I would have done. I did it before in QL Today when I "created" something along these lines, but got a right telling off from George Gwilt, and others, about using my own space for the maths stack!

Unfortunately, the SMSQ/E manual doesn't go into much detail about how much space is required for "working out". It's fine for telling me how much the stack pointer will change for each operation. Never mind, this is exactly what trial an error is all about! EDIT: The SMSQ manual mentions 30 bytes required, my mistake.

Many thanks.

Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
tofro
Font of All Knowledge
Posts: 3097
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Using the Arithmetic Stack from a job, not S*BASIC

Post by tofro »

Norman,

Note some routines (graphics, for example, that take their parameters from the RI stack) may use a lot more than the mentioned 30 bytes (The manual says 240).

And even if it might look tempting, no, QA.RESRI cannot be used to allocate space on your private RI stack. Use standard memory allocation routines, make sure you allocate an even amount and let a1,a6 point to the top of the allocated area (I normally use a1 to point to the base and have a6 hold the length - or vice versa, that makes it easy to check for overflow) - And leave the S*BASIC variables that point to "the" a1,a6 stack alone.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
NormanDunbar
Forum Moderator
Posts: 2470
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: Using the Arithmetic Stack from a job, not S*BASIC

Post by NormanDunbar »

Thanks ToFro.

I don't "do" graphics, so no problems there. And yes, I'll not be using space allocation routines. I'll probably end up using some of the job's data space.

Appreciate the responses from both of you, thanks.


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
NormanDunbar
Forum Moderator
Posts: 2470
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: Using the Arithmetic Stack from a job, not S*BASIC

Post by NormanDunbar »

And after all that, it turns out that the routine I thought was there, isn't! I was looking to print a signed long integer and needed to convert it to ASCII for printing. Turns out that while I can do this with word integers and floats, I can't do it easily, with a vector, for long words. Of course, I can stack the long integer as a float and print that, I suppose, but then again, there's a difference between QDOS and SMSQ where the latter has an easy method of converting the long integer on TOS into a float, QDOS needs the old fashioned manual conversion routine. Sigh!

I wonder why there was never a long integer printing vector in QDOS and why it remains "missing" in SMSQ? Seems a little strange given the amount of long words flying around the system. I suspect it was "easier" to convert to a float and print that.

C'est la vie, as they say in Wales! ;)

Cheers,
Norm.

PS. I already have a "print long integer" routine from a past life that I can use, but I was hoping for a simple life!


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
User avatar
mk79
QL Wafer Drive
Posts: 1349
Joined: Sun Feb 02, 2014 10:54 am
Location: Esslingen/Germany
Contact:

Re: Using the Arithmetic Stack from a job, not S*BASIC

Post by mk79 »

NormanDunbar wrote:I wonder why there was never a long integer printing vector in QDOS and why it remains "missing" in SMSQ?
Pure speculation, but SuperBasic never had a real concept of long integers, so the routine wasn't needed. Also, there is no full 32-bit divide function in the 68008, so the word-to-ascii function would be bigger and slower without a good reason (binary and hex, which do exist in long forms, more or less only need different loop counters). SMSQ/E on the other hand has a real 32-bit to ASCII function and it only sign extends any 16-bit calls. It's not vectorized however, maybe because there is no good place to put it.

Marcel


User avatar
dilwyn
Mr QL
Posts: 3075
Joined: Wed Dec 01, 2010 10:39 pm

Re: Using the Arithmetic Stack from a job, not S*BASIC

Post by dilwyn »

NormanDunbar wrote: C'est la vie, as they say in Wales! ;)
??
Sorry, I don't speak Leeds Scottish....


User avatar
NormanDunbar
Forum Moderator
Posts: 2470
Joined: Tue Dec 14, 2010 9:04 am
Location: Buckie, Scotland
Contact:

Re: Using the Arithmetic Stack from a job, not S*BASIC

Post by NormanDunbar »

mk79 wrote:Pure speculation, but SuperBasic never had a real concept of long integers,.......
Thanks Marcel, that makes more sense than my suspicions. Shame there's nowhere to put the "vector" in SMSQ, it would be handy. I doubt there's an easy way to (a) find it and (b) call it without much messing around?
Dilwyn wrote:???
Sorry Dilwyn, everyone else says "... as they say in France", I just changed it to Wales to see if anyone was listening. Nobody yet, until now, has mentioned it. Well spotted!


Cheers,
Norm.


Why do they put lightning conductors on churches?
Author of Arduino Software Internals
Author of Arduino Interrupts

No longer on Twitter, find me on https://mastodon.scot/@NormanDunbar.
Post Reply