Is SBASIC programming on SMSQE difficult?

Anything QL Software or Programming Related.
User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: Is SBASIC programming on SMSQE difficult?

Post by Andrew »

tofro wrote:The (double) tilde sign (~~) acts as a bitwise NOT
Thank you, tofro. Thank you for actually writing 'tilde' - In Dilwyn's example I was seeing -minus (-)! I need new glasses!

But now I have another question:
Why ~~1 is -2 and not 254?

Code: Select all

x%=~~1: print  x%, bin$(x%,8), bin('11111110')
gives
-2     11111110      254


User avatar
NormanDunbar
Forum Moderator
Posts: 2251
Joined: Tue Dec 14, 2010 9:04 am
Location: Leeds, West Yorkshire, UK
Contact:

Re: Is SBASIC programming on SMSQE difficult?

Post by NormanDunbar »

I had about three original QLs with similar problems. Dead keys all over the place. I suspect a new membrane would have fixed the problems though! :D Is your's a Mac of some kind by any chance?


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: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Is SBASIC programming on SMSQE difficult?

Post by tofro »

NormanDunbar wrote:I had about three original QLs with similar problems. Dead keys all over the place. I suspect a new membrane would have fixed the problems though! :D Is your's a Mac of some kind by any chance?
Thats a common fault of keyboards for continental people: They're so stubborn, they press most of the keys twice anyways ;)


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: Is SBASIC programming on SMSQE difficult?

Post by Andrew »

I ask again, brcause I really do not understand:
But now I have another question:
Why ~~1 is -2 and not 254?

Code: Select all

x%=~~1: print  x%, bin$(x%,8), bin('11111110')
gives
-2     11111110      254
I see that negating any positive number the rsult is a negative number :o
Bitwise NOT N = ~~N + 256


martyn_hill
Aurora
Posts: 909
Joined: Sat Oct 25, 2014 9:53 am

Re: Is SBASIC programming on SMSQE difficult?

Post by martyn_hill »

Hi Andrew!

The reason why bitwise NOT produced a negative result can be better understood when we remember that integers in QDOS are 16-bit 'signed' quantities according to the "two's complement" paradigm and thus, if the most-significant bit - the so-called 'sign-bit' - is '1', the result is interpreted as negative when printed out.

If as in this case, you take a small positive integer, the top few bits will be '0', i.e. '00000000 00000001'

Apply bitwise NOT and any such bits - including the 'sign-bit' - will be inverted and the resultant number will thereafter be regarded as a negative number by QDOS, thus '11111111 11111110' - which, in two's complement arithmentic, is the representation of -2.

If instead treated solely as an 8-bit number (as per BIN '11111110'), then to QDOS, the top 8 bits are again 0 and thus remain positive '00000000 11111110', resulting in the printed value 254.

There are better ways to explain this behaviour, but does that help at all?


User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: Is SBASIC programming on SMSQE difficult?

Post by Andrew »

martyn_hill wrote:There are better ways to explain this behaviour, but does that help at all?
Thank you Martyn, now it's clear.
It also explains some erratic behaviour in the program i'm working on


Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Re: Is SBASIC programming on SMSQE difficult?

Post by Tinyfpga »

Thanks for all the replies. There is quite a lot to take in. Once I have grasped it all, I will be back with more thoughts and questions on programming and programming in Qlib BASIC.

I have been slowly writing programs designed to test BASIC instructions, such that I can see what I can do with them.

I have also started writing some vaguely useful programs the most ambitious being a kind of programmable grid system. I have used this to produce a copy of a text entry Excel calculator I use on my PCs.

On the matter of my questions 3 and 4, I have tried pjw's suggestion of using a timeout of 0. On my laptop this creates a delay of approximately 50 micro seconds. Looped 5 times this creates a delay of 0.25 msecs. It is the smallest delay that ameliorates the performance problems mentioned in my post.

I like the sound of pjw's SUSJB but it also creates a minimum delay of 20msecs whereas for animation I need a lot less than this. Can SUSJB be altered to have a resolution of 1/1000th of a second?

Has no one else experienced the effects I mention when executing animation programs in the foreground?
Last edited by Tinyfpga on Mon Jan 10, 2022 11:42 pm, edited 1 time in total.


stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: Is SBASIC programming on SMSQE difficult?

Post by stevepoole »

Hi Tiny,

An easy way to slow a program is to include a delay loop :

500 delay=9999999: For wait=1 to delay: waste_time=1

Depending on your system speed, this will pause your program temporarily, by delays a small as you wish.

But the delay means incompatibility between systems, unless each owner modifies the delay variable to suit.

Otherwise, gold_card and smsq/e users have the SLUG n commmand available to experiment with. SLUG 0 is slug off.

Hope this helps,
Steve.
___________________


User avatar
pjw
QL Wafer Drive
Posts: 1286
Joined: Fri Jul 11, 2014 8:44 am
Location: Norway
Contact:

Re: Is SBASIC programming on SMSQE difficult?

Post by pjw »

Tinyfpga wrote:<>
On the matter of my questions 3 and 4, I have tried pjw's suggestion of using a timeout of 0. On my laptop this creates a delay of approximately 50 micro seconds. Looped 5 times this creates a delay of 0.25 msecs. It is the smallest delay that ameliorates the performance problems mentioned in my post.

I like the sound of pjw's SUSJB but it also creates a minimum delay of 20msecs whereas for animation I need a lot less than this. Can SUSJB be altered to have a resolution of 1/1000th of a second?

Has no one else experienced the effects I mention when executing animation programs in the foreground?
Im never quite sure of when you refer to your Q68 and SMSQ/E or your SMS2 system, and since I have no experience with SMS2, I cant tell which facilities are available..

Does your SMS2 system have the command IO_PRIORITY? If you do, have you played with it? The syntax is IO_PRIORITY <level>, with levels running from 1 (QDOS levels of response, higher crude performance) to ca 1000 (Maximum response, the performance depends on the number of jobs waiting for input.) Perhaps fiddling with that may prevent the foreground task hogging the system?

Delay loops: I think its probably better to involve the scheduler in some form rather than just creating friction by loops and calculation. This allows more opportunity for the system to get on with other things meanwhile. Please someone correct me if Im wrong, but any traps that would normally invoke the scheduler, even with a timeout of 0, allows jobs to be rescheduled, no? Thus SUSJB -1, 0 would be useful in any delay loops where SUSJB -1, 1 is too slow. A simple AT#ch; 0,0 or similar, where appropriate, might also do.


Per
dont be happy. worry
- ?
stevepoole
Super Gold Card
Posts: 712
Joined: Mon Nov 24, 2014 2:03 pm

Re: Is SBASIC programming on SMSQE difficult?

Post by stevepoole »

Hi Per,

You remarked :<< Does your SMS2 system have the command IO_PRIORITY? If you do, have you played with it? >>

There is also the TURBO command SET_PRIORITY, ( described in the Turbo Manual 4.6.2.2).
SET_PRIORITY 0,0,16 reduces basic's priority by half, as 32 is the default. (Do not try to set basic to priority 0,0,0 !)
SET_PRIORITY 1 sets the calling job to 1, (priorities range from 0 to 127).

'SUSPEND_TASK delay' acts with the same timeout as 'PAUSE delay', not very useful if only BASIC is running.

All this means you have to know the job's task numbers, which makes things even more complicated.
According to the manual, task priority is automatically reduced by a job when waiting for key entries !
Hence, for beginners, the simplest solution is to use DIY delay loops.....

Steve.
___________________


Post Reply