Function causing Beeb to crash

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
vela025
Posts: 198
Joined: Tue Jun 16, 2020 4:48 pm
Contact:

Function causing Beeb to crash

Post by vela025 »

Hi everyone,
I'm trying to resurect Rob O'Donnells OBBS https://www.stardot.org.uk/forums/viewtopic.php?t=28297, everything is going great guns; however there is still the occasional crash (on my end) seemingly at random. The only commonality is it occurs when awaiting input (either menu selection, typing a message or answering a survey). The only function that all these have in common is below:

Code: Select all

 
DEFFNu(capslock,length):LOCALA,A$:A$="":REPEAT:A=GETAND127:IF A=13 THENPRINT:UNTILTRUE:=A$
IFA=21ORA=24PRINTSTRING$(LENA$,CHR$8);:A$="":UNTILFALSE
IF(A=8ORA=127)ANDLENA$>1A$=LEFT$(A$,LENA$-1):VDU8:UNTILFALSE
IF(A=8ORA=127)ANDLENA$=1A$="":VDU8:UNTILFALSE
IFA=127ORA<32UNTILFALSE
IFcapslockANDA>96ANDA<123A=A-32
IFLENA$+1>ABSlengthVDU7:UNTILFALSE
A$=A$+CHR$A:IFlength<0VDU42:UNTILFALSE:ELSEVDUA:UNTILFALSE
I would say it happens to around 1 in 10 callers, and seemingly seems to happen to the same callers frequently; where as other callers expereince no issues. Also seems more likely to happen when the connection is coming from a real Beeb via tcpser. All I can think is that something is being recieved (although I'm not sure what that could be) that isn't meeting any of the above criteria causing an infinate loop, any ideas how I could make the above more robust avoiding this issue?

Thanks again,
Ed
BBC Master 128, PiTubeDirect, RGB2HDMI, Twin 5 1/4" & GoTek, BeebSCSI, Retroclinic Datacentre (E), Oki Microline 280, Sony TCM-737, Miracle WS2000 Modem, WE Mouse. BeeBS BBS - http://beebs.ddns.net
User avatar
BeebMaster
Posts: 7380
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Function causing Beeb to crash

Post by BeebMaster »

Seems to work here, though I haven't tested it extensively.

If you put TRACE ON then it will tell you which line number it gets stuck at or goes round infinitely.
Image
vela025
Posts: 198
Joined: Tue Jun 16, 2020 4:48 pm
Contact:

Re: Function causing Beeb to crash

Post by vela025 »

BeebMaster wrote: Sun Jan 14, 2024 6:16 pm Seems to work here, though I haven't tested it extensively.

If you put TRACE ON then it will tell you which line number it gets stuck at or goes round infinitely.
As in the BBS works for you or the excerpt of code does? With the BBS people can be on there for 40min leaving messages, sending emails and downloading files where nothing will go wrong, where as sometimes after 5 min in it all hangs. Tcpser shows data coming in, but (due to the interference I get through the speaker) I can hear the beeb isn't accepting it and it locks up. When it hangs the only way to exit is to press break, would TRACE ON work in this scenario? Where would it show me the line number?
BBC Master 128, PiTubeDirect, RGB2HDMI, Twin 5 1/4" & GoTek, BeebSCSI, Retroclinic Datacentre (E), Oki Microline 280, Sony TCM-737, Miracle WS2000 Modem, WE Mouse. BeeBS BBS - http://beebs.ddns.net
User avatar
BeebMaster
Posts: 7380
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Function causing Beeb to crash

Post by BeebMaster »

As in the code excerpt seemed to work, I've never used the BBS.

If that code is part of a program running on a Beeb, waiting for remote input, then I think TRACE ON before running the program should work and will print every line number encountered. So when it stops either you will see the last line number encountered, or if it's getting stuck in an infinite loop, an endless series of repeated line numbers will be printed.

If the only way out is to press BREAK, and ESCAPE doesn't work and hasn't been disabled, then that suggests something more serious is happening which is messing up the BASIC interpreter.
Image
User avatar
BeebMaster
Posts: 7380
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Function causing Beeb to crash

Post by BeebMaster »

Or instead could you use OSWORD 0 to get the line of input from the current input stream (which could include RS423)? This call allows you to set the string length, maximum and minimum ASCII codes to accept, and would allow CTRL-U to delete the current line (but not CTRL-X which also does the same thing here).
Image
User avatar
BeebMaster
Posts: 7380
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Function causing Beeb to crash

Post by BeebMaster »

Mmm OSWORD 0 might not be any good. It will accept, and print, characters out of range, but doesn't include them in the string.
Image
vela025
Posts: 198
Joined: Tue Jun 16, 2020 4:48 pm
Contact:

Re: Function causing Beeb to crash

Post by vela025 »

BeebMaster wrote: Sun Jan 14, 2024 7:46 pm If the only way out is to press BREAK, and ESCAPE doesn't work and hasn't been disabled, then that suggests something more serious is happening which is messing up the BASIC interpreter.
Escape has been disabled to prevent remote connections accidentally stopping obbs running whilst they're logged in. Thanks for the help I'll try with trace on and see what happens. The bbs is online right now so I can't test it on there, but I did just try it using last night backup in beebem, once it detects a connection it stops printing the line numbers (despite the system still carrying on as usual) so it doesn't look like I'm going to be able to see exactly where it's crashing using Trace on :( .
BeebMaster wrote: Sun Jan 14, 2024 8:11 pm Or instead could you use OSWORD 0 to get the line of input from the current input stream (which could include RS423)? This call allows you to set the string length, maximum and minimum ASCII codes to accept, and would allow CTRL-U to delete the current line (but not CTRL-X which also does the same thing here).
Unfortunately this is beyond my understanding, but I'll have a go and see how I get on. I was hoping to just patch up what was already there, but again thank you for the suggestion :)

Many thanks,
Ed
BBC Master 128, PiTubeDirect, RGB2HDMI, Twin 5 1/4" & GoTek, BeebSCSI, Retroclinic Datacentre (E), Oki Microline 280, Sony TCM-737, Miracle WS2000 Modem, WE Mouse. BeeBS BBS - http://beebs.ddns.net
User avatar
BeebMaster
Posts: 7380
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Function causing Beeb to crash

Post by BeebMaster »

This is an example of using OSWORD 0 I just did, but probably no use if rejected keypresses aren't supposed to show up at all:

Code: Select all

  100REM OSWORD 0
  200DIM osblock 5,string 64
  300C%=FNinput(32,32,96)
  400PRINT"String input was terminated by ";:IFC%=0 PRINT"RETURN"ELSEPRINT"ESCAPE"
  500PRINT"String is: [";$string;"]"
  600END
  700DEFFNinput(len,low,hi)
  800A%=0:REM OSWORD 0
  900X%=osblock
 1000Y%=X% DIV256
 1100!osblock=string:REM Storage for string
 1200osblock?2=len:REM Max string length
 1300osblock?3=low:REM Lowest ASCII code accepted
 1400osblock?4=hi:REM Highest ASCII code accepted
 1500=(USR&FFF1 DIV&1000000)AND 1
What I haven't worked out yet is how you can ever get an escape condition returned, as pressing ESCAPE breaks out of the OSWORD call, and disabling ESCAPE disables ESCAPE! Possibly this would work from serial input though, or using machine code instead of BASIC.
Image
vela025
Posts: 198
Joined: Tue Jun 16, 2020 4:48 pm
Contact:

Re: Function causing Beeb to crash

Post by vela025 »

BeebMaster wrote: Sun Jan 14, 2024 8:45 pm What I haven't worked out yet is how you can ever get an escape condition returned, as pressing ESCAPE breaks out of the OSWORD call, and disabling ESCAPE disables ESCAPE! Possibly this would work from serial input though, or using machine code instead of BASIC.
Thanks so much for taking the time to do that, I really appreciate it. What does the last line of code do?

Code: Select all

=(USR&FFF1 DIV&1000000)AND 1
Yes OBBS loads up some machine code first which deals with a pace modem, stripping out lower case and bbc mode 7 control codes for terminals that don't support it. This bit might be the escape key handling:

Code: Select all

1150 .escape
 1160 LDA#&79:LDX#0:LDY#0:JSR&FFF4
 1170  CPX#&70:BNE return2
 1180 LDA#125:LDX#0:LDY#0:JSR&FFF4
 1190  LDA#0:STAFLAG:JMPreturn2
For the user who is connecting Escape is disabled, but for the machine running Obbs pressing escape allows you to "drop in to chat" with the connected user.
BBC Master 128, PiTubeDirect, RGB2HDMI, Twin 5 1/4" & GoTek, BeebSCSI, Retroclinic Datacentre (E), Oki Microline 280, Sony TCM-737, Miracle WS2000 Modem, WE Mouse. BeeBS BBS - http://beebs.ddns.net
User avatar
jgharston
Posts: 5321
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Function causing Beeb to crash

Post by jgharston »

vela025 wrote: Mon Jan 15, 2024 7:49 am Thanks so much for taking the time to do that, I really appreciate it. What does the last line of code do?

Code: Select all

=(USR&FFF1 DIV&1000000)AND 1
That's the wrong way around. Consider what will happen if USR &FFF1 returns a negative number. You need to mask first, divide after.

Code: Select all

=(USR&FFF1 AND &1000000) DIV &1000000
or, even simpler:

Code: Select all

=(USR&FFF1 AND &1000000)<>0
Bits 24-31 of the returned value from USR when calling 6502 code is the 6502 flags register. Bit 24 is thereby the Carry flag. See link.

Code: Select all

DEFFNu(capslock,length):LOCALA,A$:A$="":REPEAT:A=GETAND127:IF A=13 THENPRINT:UNTILTRUE:=A$
IFA=21ORA=24PRINTSTRING$(LENA$,CHR$8);:A$="":UNTILFALSE
IF(A=8ORA=127)ANDLENA$>1A$=LEFT$(A$,LENA$-1):VDU8:UNTILFALSE
IF(A=8ORA=127)ANDLENA$=1A$="":VDU8:UNTILFALSE
IFA=127ORA<32UNTILFALSE
IFcapslockANDA>96ANDA<123A=A-32
IFLENA$+1>ABSlengthVDU7:UNTILFALSE
A$=A$+CHR$A:IFlength<0VDU42:UNTILFALSE:ELSEVDUA:UNTILFALSE
The 3rd and 4th lines are redundant there. Just replace both of them with:

Code: Select all

IF(A=8 OR A=127) AND LENA$>0:A$=LEFT$(A$,LENA$-1):VDU 8:UNTIL FALSE

Code: Select all

1150 .escape
 1160 LDA#&79:LDX#0:LDY#0:JSR&FFF4
 1170  CPX#&70:BNE return2
 1180 LDA#125:LDX#0:LDY#0:JSR&FFF4
 1190  LDA#0:STAFLAG:JMPreturn2
For the user who is connecting Escape is disabled, but for the machine running Obbs pressing escape allows you to "drop in to chat" with the connected user.
That's testing to see if the physical Escape key is being pressed by calling the low-level keyboard scan code. If it is, then the Escape state is set and FLAG is set to 0. Both OSBYTE calls redundently set Y, all OSBYTE calls <128 ignore Y and it is implicitly set to 0, so it's pointless setting Y before calling, it gets ignored/set to zero /anyway/, and OSBYTE 125 does no take any parameters at all, so it's redundant setting X and it is ignored. Also, the OSBYTE &79 call won't see the Escape key if a lower-numbered key is being pressed at the same time. Escape being key &70 there are 59 other keys that will be spotted first that will stop the scan findng the Escape key!

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
User avatar
BeebMaster
Posts: 7380
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Function causing Beeb to crash

Post by BeebMaster »

jgharston wrote: Mon Jan 15, 2024 11:05 am
vela025 wrote: Mon Jan 15, 2024 7:49 am Thanks so much for taking the time to do that, I really appreciate it. What does the last line of code do?

Code: Select all

=(USR&FFF1 DIV&1000000)AND 1
That's the wrong way around. Consider what will happen if USR &FFF1 returns a negative number. You need to mask first, divide after.

Code: Select all

=(USR&FFF1 AND &1000000) DIV &1000000
or, even simpler:

Code: Select all

=(USR&FFF1 AND &1000000)<>0
Bits 24-31 of the returned value from USR when calling 6502 code is the 6502 flags register. Bit 24 is thereby the Carry flag. See link.
Mmm I copied that from some OSGBPB code I had, which also uses the carry flag for a status bit, so that's wrong as well!
Image
User avatar
jgharston
Posts: 5321
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Function causing Beeb to crash

Post by jgharston »

BeebMaster wrote: Mon Jan 15, 2024 11:37 am Mmm I copied that from some OSGBPB code I had, which also uses the carry flag for a status bit, so that's wrong as well!
I remember trying to divide negative numbers biting me way back in the '80s. (&FFFFFF00 DIV 65536) AND 255 just wouldn't give me 255! Oh wait.... -256 DIV 65536..... yeah.... :)

ProgTip: I managed to wrangle some code together to do left-shifts on pre-32bit BASIC:
((num%AND&3FFFFFFF)*2)OR(((num%AND&40000000)<>0)AND&80000000)

I thought I'd done a similar right shift, but can't find it. Let's think....
((num%AND&7FFFFFFF)DIV2)OR(&40000000 AND (num%<0))

Better put these on the wiki.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
User avatar
BeebMaster
Posts: 7380
Joined: Sun Aug 02, 2009 5:59 pm
Location: Lost in the BeebVault!
Contact:

Re: Function causing Beeb to crash

Post by BeebMaster »

I definitely definitely need to finally sort out in my head (and in BBC BASIC) how to do all byte-wise and bit-wise masking operations correctly! Perhaps this will be my belated new year's resolution!
Image
User avatar
jgharston
Posts: 5321
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: Function causing Beeb to crash

Post by jgharston »

jgharston wrote: Mon Jan 15, 2024 1:38 pm ProgTip: I managed to wrangle some code together to do left-shifts on pre-32bit BASIC:
((num%AND&3FFFFFFF)*2)OR(((num%AND&40000000)<>0)AND&80000000)

I thought I'd done a similar right shift, but can't find it. Let's think....
((num%AND&7FFFFFFF)DIV2)OR(&40000000 AND (num%<0))

Better put these on the wiki.
...and in typing them up to make into a library, I ended up optimising them and built the full set of 5 shift/rots. ;)
mdfs.net/blib/Shift when I get around to uploading it.

(I''ve been isolating, and through the boredom have been going through loads of unsorted code snippets and tidying them up and documenting them.)

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.45
(C) Copyright J.G.Harston 1989,2005-2024
>_
Post Reply

Return to “programming”