Control-N - page mode query

Discuss all aspects of programming here. From 8-bit through to modern architectures.
Post Reply
fuzzel
Posts: 512
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Control-N - page mode query

Post by fuzzel » Tue Sep 17, 2019 5:38 pm

I wonder if anyone can help with this query. I'm writing my text adventure game and for locations where there's a lot of text and potentially objects also dropped in the location I'm going to insert a VDU14 (Control N) before printing text and then VDU15 (Control O) afterwards to resume.
To the uninitiated it will look as though the program has hung, is there a way, when the screen printing is suspended awaiting shift press, to insert some text at the bottom of the screen or under the text stating "<PRESS SHIFT>" ? I think I've seen this done in some games.

julie_m
Posts: 107
Joined: Wed Jul 24, 2019 8:53 pm
Location: Derby, UK
Contact:

Re: Control-N - page mode query

Post by julie_m » Tue Sep 17, 2019 6:58 pm

The CAPS LOCK and SHIFT LOCK LEDs will both light when the screen is full, as the standard prompt to press SHIFT to continue.

User avatar
jgharston
Posts: 3801
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Control-N - page mode query

Post by jgharston » Tue Sep 17, 2019 7:28 pm

fuzzel wrote:
Tue Sep 17, 2019 5:38 pm
I wonder if anyone can help with this query. I'm writing my text adventure game and for locations where there's a lot of text and potentially objects also dropped in the location I'm going to insert a VDU14 (Control N) before printing text and then VDU15 (Control O) afterwards to resume.
To the uninitiated it will look as though the program has hung, is there a way, when the screen printing is suspended awaiting shift press, to insert some text at the bottom of the screen or under the text stating "<PRESS SHIFT>" ? I think I've seen this done in some games.
VDU 26,12:PRINT TAB(0,24);SPC8"PRESS <SHIFT> TO SCROLL";:VDU 28,0,23,39,0,30,14

For MODE 7, adjust coords for other modes.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

moogthedog
Posts: 20
Joined: Wed Feb 10, 2016 6:22 pm
Contact:

Re: Control-N - page mode query

Post by moogthedog » Sun Sep 22, 2019 4:41 pm

This is very weird, as I've just come up with a requirement for something very similar... Unfortunately, mine's a little more complicated, but the (sort of) answer may help others who end up on this thread and want to play with paged mode in naughty ways.

I'm also looking to detect when a Beeb has paused text scrolling, and then (hopefully - not working yet) insert a SHIFT into the keyboard scan to continue scrolling once I've diddled with MODE 7 screen memory a bit. It's a long story.

I've found OSBYTE &75 (117), that on first glance would appear to do what I want - It's *supposed* to tell the status of the VDU driver, with bit 2 of the X response saying whether the page mode is enabled, and bit 1 is shown in the advanced programmers guide as being 'Scrolling disabled', which I took to mean that the scroll had been halted due to page mode. But it's not. I tried reading the value in an event-driven bit of assembler, and it sticks with just bit 2 set. As it's not that, does anyone know what bit 1 is actually for...?

I also looked at OSBYTE &D9 (217) that allows the direct read of the number of lines written since the last halt. This showed more promise, as it increased during the scroll and then stuck at a value when it halted. (Again, I wrote some event-driven assembler to write the value and repetition count to a circular buffer in memory whenever it changed, which I then examined after the action). The value it stops at varies dependent on the vertical screen position the cursor was at when the long text output started (It always stops at the bottom of the initial screen, and then scrolls a set amount from then on), but by noting when the repetition value *and* the line count is non-zero, you can trigger code that does stuff when the screen is paused.

Unfortunately, whether you can actually output *anything* to the screen from BASIC at that point is probably a no (even a VDU15?)... for the OP, the suggestion of printing the instructions beforehand in a text window would appear to be the best way forward.

fuzzel
Posts: 512
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Control-N - page mode query

Post by fuzzel » Sun Sep 22, 2019 6:00 pm

This is getting quite interesting. My own reason for having the text "PRESS SHIFT" displayed once page mode has been activated while printing a long piece of text is that it's easy to be caught out and think the program has crashed (I know because its happened to me, I think while playing Escape from Enthar Seven by Robico as some of the room location descriptions are quite verbose). This is not my field but couldn't a temporary interrupt, commenced on printing text and ending on completion, check for page mode being activated and a shift being awaited, in which case a text window could pop up with the requisite message?
Last edited by fuzzel on Sun Sep 22, 2019 6:00 pm, edited 1 time in total.

User avatar
jgharston
Posts: 3801
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Control-N - page mode query

Post by jgharston » Sun Sep 22, 2019 6:03 pm

moogthedog wrote:
Sun Sep 22, 2019 4:41 pm
I'm also looking to detect when a Beeb has paused text scrolling, and then (hopefully - not working yet) insert a SHIFT into the keyboard scan to continue scrolling once I've diddled with MODE 7 screen memory a bit. It's a long story.
You can't "insert a SHIFT into the keyboard scan". SHIFT (and CTRL) aren't keys that cause an action, they are modifier keys. The VDU driver examines the state of them via KEYV, so you would have to hang onto KEYV and on the "modifier keys" call (CC, VC) return "SHIFT=On".

The VDU pauses scrolling when the scroll counter is non-negative and 75%-ish of the screen height, and when it decides it needs to do a LineFeed, either an explicit VDU 10 or an implicit one from wrapping past the right of the screen. Nothing is flagged to indicate that the VDU driver is in this state, it simply enters a tight loop calling KEYV and polling ESCFLG. Possibly the simplest way to implement what you're trying to do is hook into KEYV and when the scroll counter is greater than a certain number return SHIFT=On.
I've found OSBYTE &75 (117), that on first glance would appear to do what I want - It's *supposed* to tell the status of the VDU driver, with bit 2 of the X response saying whether the page mode is enabled, and bit 1 is shown in the advanced programmers guide as being 'Scrolling disabled', which I took to mean that the scroll had been halted due to page mode. But it's not. I tried reading the value in an event-driven bit of assembler, and it sticks with just bit 2 set. As it's not that, does anyone know what bit 1 is actually for...?
Scroll Disabled is what happens in VDU 5 mode - text wraps off the bottom of the screen and back onto the top of the screen.
(It (the scroll counter) always stops at the bottom of the initial screen, and then scrolls a set amount from then on), but by noting when the repetition value *and* the line count is non-zero, you can trigger code that does stuff when the screen is paused.

Unfortunately, whether you can actually output *anything* to the screen from BASIC at that point is probably a no (even a VDU15?)... for the OP, the suggestion of printing the instructions beforehand in a text window would appear to be the best way forward.
Your interupt routine can't do any VDU action at that point as the VDU driver itself is in a tight loop in the middle of the VDU driver. Calling it would be calling it from the middle of itself when it hasn't yet tidied itself up for exiting to the original caller. You can't call the VDU driver again until the VDU driver has finished what it is doing and has exited. Even forcing a VDU 15 either by crossing your fingers and calling OSWRCH or by writing to the VDU Status flag won't do anything as the VDU driver is in that tight loop checking the SHIFT key, not checking the VDU Status byte.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
jgharston
Posts: 3801
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Control-N - page mode query

Post by jgharston » Sun Sep 22, 2019 6:13 pm

fuzzel wrote:
Sun Sep 22, 2019 6:00 pm
This is not my field but couldn't a temporary interrupt, commenced on printing text and ending on completion, check for page mode being activated and a shift being awaited, in which case a text window could pop up with the requisite message?
It wouldn't be an interrupt, it would be hanging onto KEYV and waiting for a 'modifier keys' call with CC and VC. The problem then is deciding if you've been called from the VDU driver looking for SHIFT to scroll in paged mode, or from the VDU driver looking for CTRL+SHIFT to pause output, or from RESET testing for Shift-Break, or from the keyboard driver deciding how to modify a keypress, or from anywhere else just wanting to know if SHIFT or CTRL are being pressed.

And, you get into the problem of re-entering the VDU driver from the middle of the VDU driver - plus, where would you pop up the text window without obscruring the text that has paused to allow you to read it? The obvious answer is: somewhere that would not obscure what you're trying to read - so you may was well put it there permanently outside the text window.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

fuzzel
Posts: 512
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Control-N - page mode query

Post by fuzzel » Sun Sep 22, 2019 7:02 pm

Oh dear! Complicated or what? I think I'll boot up Enthar Seven and remind myself how they do it again. Perhaps the message flashes up briefly when the text is printed and is then deleted once the text has been fully displayed.

moogthedog
Posts: 20
Joined: Wed Feb 10, 2016 6:22 pm
Contact:

Re: Control-N - page mode query

Post by moogthedog » Sun Sep 22, 2019 7:31 pm

jgharston wrote:
Sun Sep 22, 2019 6:03 pm
You can't "insert a SHIFT into the keyboard scan". SHIFT (and CTRL) aren't keys that cause an action, they are modifier keys. The VDU driver examines the state of them via KEYV, so you would have to hang onto KEYV and on the "modifier keys" call (CC, VC) return "SHIFT=On".
Putting aside the VDU-tight-loopyness, OSBYTE &78 says it's "Write current keys pressed information", and has data for Shift and Control. If I needed to fake up some modifier keys otherwise, would that do the job if (say) a BASIC program was using INKEY(-1) to detect it?
The VDU pauses scrolling when the scroll counter is non-negative and 75%-ish of the screen height, and when it decides it needs to do a LineFeed, either an explicit VDU 10 or an implicit one from wrapping past the right of the screen. Nothing is flagged to indicate that the VDU driver is in this state,
Awww. :(
it simply enters a tight loop calling KEYV and polling ESCFLG. Possibly the simplest way to implement what you're trying to do is hook into KEYV and when the scroll counter is greater than a certain number return SHIFT=On.
That is all epically useful information! Thank you!
As it's not that, does anyone know what bit 1 is actually for...?
Scroll Disabled is what happens in VDU 5 mode - text wraps off the bottom of the screen and back onto the top of the screen.
Ah, makes sense :)
Your interupt routine can't do any VDU action at that point as the VDU driver itself is in a tight loop in the middle of the VDU driver. Calling it would be calling it from the middle of itself when it hasn't yet tidied itself up for exiting to the original caller. You can't call the VDU driver again until the VDU driver has finished what it is doing and has exited. Even forcing a VDU 15 either by crossing your fingers and calling OSWRCH or by writing to the VDU Status flag won't do anything as the VDU driver is in that tight loop checking the SHIFT key, not checking the VDU Status byte.
That's fine. I just need to look at each screenful and search for a particular string. There are much more elegant solutions available for what I'm attempting, but I'm very much in a 'I wanna see if I can do it this way' mood at the moment... :)

User avatar
jgharston
Posts: 3801
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Control-N - page mode query

Post by jgharston » Mon Sep 23, 2019 1:03 am

I've written up what a keyboard driver should do on KEYV on the WIki.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
jgharston
Posts: 3801
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Control-N - page mode query

Post by jgharston » Mon Sep 23, 2019 1:19 am

moogthedog wrote:
Sun Sep 22, 2019 7:31 pm
Putting aside the VDU-tight-loopyness, OSBYTE &78 says it's "Write current keys pressed information", and has data for Shift and Control. If I needed to fake up some modifier keys otherwise, would that do the job if (say) a BASIC program was using INKEY(-1) to detect it?
No, OSBYTE &78 writes to the workspace of the n-key-rollover keypress characters being put into the keyboard buffer through the repeating-key process*. Negative INKEY scans the hardware (via KEYV).

SHIFT and CTRL aren't keypresses, they are modifier keys. The n-key rollover processing processes keypresses, modified by the modifier keys. The modifier keys are read via KEYV from the hardware at the point in the keypress processing at the very point that it needs to check. You can see this by, eg, holding 6 and then pressing and releasing SHIFT. The SHIFT action occurs at the point you press it, not at the start of the keypress processing.

Similarly, at the hardware level SHIFT and CTRL aren't keypresses in that they are not connected to the keyboard interupt line, only keypress keys cause an interupt. If you look through the numbering of negative INKEY numbers or look at the keyboard matrix you can see that modifier keys are all on a row of their own seperate from keypress keys.

*In fact, if you write the key numbers of modifier keys into the n-key-rollover workspace, you'll get odd characters entered into the keyboard buffer as the keyboard map only has entries for keys 16 to 127, the keypress keys. In fact, it's really hard to get OSBYTE &78 to do anything useful as you need to write to other bits of keyboard workspace as well as the rollover workspace to get anything useful done.

(Can you tell I was elbows deep in this last year when writing the USB keyboard driver, and when updating Brandy's keyboard driver? :D )

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

User avatar
jgharston
Posts: 3801
Joined: Thu Sep 24, 2009 11:22 am
Location: Whitby/Sheffield
Contact:

Re: Control-N - page mode query

Post by jgharston » Mon Sep 23, 2019 1:24 am

moogthedog wrote:
Sun Sep 22, 2019 7:31 pm
That's fine. I just need to look at each screenful and search for a particular string.
If you're in control of the text being displayed, then you could manually implement pause and resume. Eg something like:
REPEAT
char=whatever
IF char=0 THEN PRINT "PRESS SPACE TO CONTINUE";:REPEAT UNTIL GET=32:PRINT CHR$13;SPC23;CHR$13; ELSE VDU char
UNTIL finished

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.25
(C) Copyright J.G.Harston 1989,2005-2015
>_

moogthedog
Posts: 20
Joined: Wed Feb 10, 2016 6:22 pm
Contact:

Re: Control-N - page mode query

Post by moogthedog » Mon Sep 23, 2019 6:52 am

Oooh, thanks for the wiki link - That's going to be useful.
jgharston wrote:
Mon Sep 23, 2019 1:19 am
In fact, if you write the key numbers of modifier keys into the n-key-rollover workspace, you'll get odd characters entered into the keyboard buffer as the keyboard map only has entries for keys 16 to 127, the keypress keys. In fact, it's really hard to get OSBYTE &78 to do anything useful as you need to write to other bits of keyboard workspace as well as the rollover workspace to get anything useful done.
Ah, this explains why there's a separate OSBYTE call for a keyboard scan that starts at 16...?
(Can you tell I was elbows deep in this last year when writing the USB keyboard driver, and when updating Brandy's keyboard driver? :D )
I love that someone else uses 'Elbows deep' when referring to complex code :)

This is a follow up to my Datacentre USB catalogue menu program (which I think you also gave some valuable assistance with - thank you). The OSWRCH-capture version (listing the USB directory to a memory buffer, as SPOOL doesn't do it, and the standard DFS calls to read the catalogue aren't supported) is working well, but I wanted to see if I *could* have done a screen-scraping version instead - and the barrier to that was always that the screen scrolling would lose references to files before I'd got to them. Paged mode is the obvious answer, but it halts all output while it's paused, which is also obviously a problem...

This looks like it may work, although hooking into the keyboard driver *and* event-driven studies of VDU values means it's probably going to be too messy to actually be usable - but that's never stopped me trying stuff before :)

Post Reply