Is SBASIC programming on SMSQE difficult?

Anything QL Software or Programming Related.
Post Reply
Tinyfpga
Gold Card
Posts: 252
Joined: Thu Sep 27, 2018 1:59 am

Is SBASIC programming on SMSQE difficult?

Post by Tinyfpga »

The very short answer according to google is yes. I agree with this, whereas tofro and Norm do not.

For some time I have been trying to learn to write programs in Qliberated BASIC on/in? SMSQE because as mk79 wrote "I actually like to do this stuff" or as he also wrote, its like doing "a 10000 pieces puzzle", or In my case a 100 piece puzzle.

I have to say that if I had the skills of mk I might have (if it had been possible) been tempted to carry on developing Stella et al.

I was not surprised to see that the internauts have a fair amount to say on the general question "is programming difficult". I found the following article a fair read:- https://www.thinkful.com/blog/why-learn ... damn-hard/. According to this article's first graph, I have probably reached "The Cliff of Confusion"

Recently Norm asked:- "what's bugging you? What are you trying to do? What's going wrong? What's working? What advice do you need?", which is kind of him. The answer to all those questions is, a lot.

I have in the past asked questions in a rather oblique manner and have received some useful replies, but I have delayed asking more detailed questions because I felt that I should do so only after having read as many manuals as I could bear.

I have so much to ask that I run the grave risk of being boring, so to start with I will just state that I was, still am, an SMS2 user. Programming on SMS2 is not quite the same as on SMSQE. I also program on SMSQE with a modified PEROM-SMS2 setup that runs on an a MIST FPGA.

I have three SMSQE setups:- QPC2, SMSQmuator and Q68.
I have two SMS2 setups:- On PC via Steem and on MIST.

I write my programs in an ancient version of QD linked to the SMS2 BASIC Parser so that they run on all of the above at resolutions >= 1024x768 without modification. I do not use line numbers, GOTOs, PEEKs, POKEs, 16bit colours, Easyptr or anything else that might cause problems.

As this is a QL and not an SMS2 forum I am not surprised that I regularly have to modify SBASIC source code so that it will compile on my setup. Much of the software I download from Dilwyn's site does not run properly or run at all on my SMSQE configuration. I have no idea why this is and in reality most of the stuff I like I can get to work well enough.

The only exception to this is unZIPing. I use an SMS2 unZIP thing which works really well but cannot ZIP. Instead I post small zipped QPC win files.

Anyway;
1. I am currently struggling to understand OPERATORS. In particular I cannot the understand the bitwise operators &&, ||, ^^ and ~. What does bitwise mean, for example?
I have written a program to test various operators and I would like an explanation for the the expression n&&2 with n=0 to 9
eg. O&&2 =0
For 1 it is 0 : 2 is 2 : 3 is 2 : 4 is 0 : 5 is 0 : 6 is 2 : 7 is 2 : 8 is 0 : 9 is 0

2. What is the maximum no. of parameters that can be passed to a Procedure in Qlib.

3. Sometimes, actually nearly always, a free running loop writing to the screen brings SMSQE to its knees until it is
partially or fully covered by another program. Why?
By free running I mean something such as:-

Open #1,con_ : Outln #1,300,300,50,50 etc.
Rep p
n=n+1
At #1,4,4 : Print #1,n
End rep p

4. I use a WAIT (from SMS2), PAUSE or INKEY$ instruction to solve 3. but the minimum delay for these instructions is
20 msecs. This is often much too long. Is there not an instruction that delays the program flow in micro seconds?
I have used wasted loops to create delays but they are not really satisfactory.

5. Is it true that the maximum number of channels that can be open at the same time in an Qlib SBASIC program is 16?

6. Can anyone provide me with a coded example of the use of the History device?


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 »

Tinyfpg,
here's my penny's worth:

1. Use BIN$(x%, 8) to see the results of your actions:

Code: Select all

cls: print bin$(-2, 8): for x% = 0 to 9: print x%! bin$(x%, 8), x% && -2! bin$(x% && -2, 8)
Do this for other operators and conditions, and youll soon get the hang of it.

2. The exact answer to your question is: Many more than you should ever need! In other words, if you need to ask this question you probably should re-write your code.

3. Are you able to load toolkits into SMS2? If so there is, for example SUSJB - Suspend a Job (Knoware.no/toolkits), which has a resolution of 1/50th second. But doesnt INKEY$ offer you a timeout, eg INKEY$(#channel; 1)? Even a timeout of 0 would slow things down a little.

4.

5. The answer is similar to #2, above.

6. Experiment!

Code: Select all

ch = FOPEN("history_test")
INPUT#ch; a$
IF a$ = '' THEN
 PRINT#ch; '3 ' & DATE$ \ '2 def'\ '1 xyz'
 PRINT 'No history'
ELSE
 INPUT#ch; b$, c$
 CLOSE#ch
 DELETE 'history_test'
 PRINT a$, b$, c$
END IF
PAUSE
QUIT
HTH


Per
dont be happy. worry
- ?
User avatar
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: Is SBASIC programming on SMSQE difficult?

Post by Andrew »

Tinyfpga wrote: 1. I am currently struggling to understand OPERATORS. In particular I cannot the understand the bitwise operators &&, ||, ^^ and ~. What does bitwise mean, for example?
I have written a program to test various operators and I would like an explanation for the the expression n&&2 with n=0 to 9
eg. O&&2 =0
For 1 it is 0 : 2 is 2 : 3 is 2 : 4 is 0 : 5 is 0 : 6 is 2 : 7 is 2 : 8 is 0 : 9 is 0
Bitwise: operation between A and B is performed bit by bit
&& = bitwise AND
^^ = bitwise XOR
|| = bitwise OR
I think this explains it clearly: https://en.wikipedia.org/wiki/Bitwise_operation


User avatar
RalfR
Aurora
Posts: 870
Joined: Fri Jun 15, 2018 8:58 pm

Re: Is SBASIC programming on SMSQE difficult?

Post by RalfR »

pjw wrote:3. Are you able to load toolkits into SMS2?
Yes, it is done in the CLI with "REXT win1_mytool_bin". Even the QLib tools and the Runtimes have to be loaded :)


4E75 7000
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 »

Bitwise operators operate at the bit level. You know something about electronics so I assume you are familiar with the various logic gates used in digital electronics? Well, the same truth tables apply here too.

For your examples of n && 2 for n = 0 to 9, this is worked out, in number base 2, as:

Code: Select all

Value 0 = 0000 0000
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0000 = 0

Value 1 = 0000 0001
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0000 = 0

Value 2 = 0000 0010
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0010 = 2

Value 3 = 0000 0011
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0010 = 2

Value 4 = 0000 0100
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0000 = 0

Value 5 = 0000 0101
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0000 = 0

Value 6 = 0000 0110
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0010 = 2

Value 7 = 0000 0111
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0010 = 2

Value 8 = 0000 1000
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0000 = 0

Value 9 = 0000 1001
Value 2 = 0000 0010
-------------------
0 AND 2 = 0000 0000 = 0
In an AND gate, a 0 AND n is 0, while 1 AND n is n. The same applies to the bitwise && operator. The other bitwise operators act in a similar manner to their logic gate equivalents. In Summary:

AND

0 && n = 0
1 && n = n

Where 0, 1 and n are single bits.

OR

0 || n = n
1 || n = 1

Where 0, 1 and n are single bits.

XOR

0 ^^ 0 = 0
0 ^^ 1 = 1

1 ^^ 0 = 1
1 ^^ 1 = 0

Where 0, 1 and n are single bits.

NOT

~~0 = 1
~~1 = 0

Where 0, 1 and n are single bits.

Talking of bits and base 2, the BIN$ function will convert a number to a certain number of bits:

Code: Select all

PRINT BIN$(255, 8) : REMark prints 11111111
PRINT BIN$(170, 8) : REMark prints 10101010
PRINT BIN$(85, 8) : REMark prints 01010101
PRINT BIN$(201, 8) : REMark prints 11001001
PRINT BIN$(7, 8) : REMark prints 00000111
HTH

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
Andrew
Aurora
Posts: 786
Joined: Tue Jul 17, 2018 9:10 pm

Re: Is SBASIC programming on SMSQE difficult?

Post by Andrew »

NormanDunbar wrote: NOT

~~0 = 1
~~1 = 0
Does QDOS / SMSQE have an operator for bitwise NOT ?
I know about logical NOT, but could not find a bitwise not.


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 »

The (double) tilde sign (~~) acts as a bitwise NOT
Last edited by tofro on Mon Jan 10, 2022 4:32 pm, edited 1 time in total.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
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 »

According to https://superbasic-manual.readthedocs.i ... -operators, it does, yes. I tested:

Code: Select all

PRINT ~~10
PRINT BIN$(10,8)\BIN$(~~10,8)
The results were:

Code: Select all

-11
00001010
11110101
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: 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 »

tofro wrote:The tilde sign (~) acts as a bitwise NOT
But you need two of them, to avoid an "invalid syntax" error. ;)

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:
tofro wrote:The tilde sign (~) acts as a bitwise NOT
But you need two of them, to avoid an "invalid syntax" error. ;)
I know. But unfortunately, the tilde is a "dead key" on my keyboard (needs to be pressed 4 times to get 2 characters) ;)


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Post Reply