REMV API

bbc micro/electron/atom/risc os coding queries and routines
Post Reply
SteveF
Posts: 955
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

REMV API

Post by SteveF »

I'm getting myself seriously confused about how REMV works, can someone please clarify this for me?

The Advanced User Guide (p263) says:
  • V is set to indicate examination only
    • In this case, A on exit is the next character to be removed. (No explicit mention of Y on exit; the New Advanced User Guide (p137) says Y is undefined.)
  • V is clear to indicate a character should be removed from the buffer.
    • In this case, Y on exit is the character removed and A is undefined.
Looking at https://tobylobster.github.io/mos/mos/S-s14.html, "OSBYTE 145 - Get byte from buffer" calls REMV with V clear:

Code: Select all

.osbyte145EntryPoint
    CLV
    JMP (.vectorREMV)
and the documentation on this OSBYTE is consistent with what the AUG says. So far so good.

But looking at the printer driver code in OS 1.20 at https://tobylobster.github.io/mos/mos/S-s13.html:

Code: Select all

    JSR .osbyte145EntryPoint                            read a byte from the printer buffer
    ROR .printerBufferEmptyFlag                         rotate carry into bit 7 of the
                                                        printer buffer empty flag
    BMI .exit17
    LDY #%10000010                                      enable interrupt 1 of the user VIA
    STY .userVIAInterruptEnableRegister                 this is triggered by the printer
                                                        when it is ready to receive a new
                                                        character
    STA .userVIARegisterA                               pass byte to the Centronics port
it looks to me as though a character returned in Y by the JSR to .osbyte145EntryPoint will immediately be trampled on by the LDY #%10000010, and the character actually needs to be returned in A.

In the past I have simply taken the easy option and always returned the character in both A and Y from REMV whether V is set or clear; is this in fact *required* for things to work correctly, or am I missing something?
User avatar
jgharston
Posts: 4369
Joined: Thu Sep 24, 2009 12:22 pm
Location: Whitby/Sheffield
Contact:

Re: REMV API

Post by jgharston »

SteveF wrote:
Sun May 02, 2021 12:18 am
But looking at the printer driver code in OS 1.20 at https://tobylobster.github.io/mos/mos/S-s13.html:

Code: Select all

    JSR .osbyte145EntryPoint                            read a byte from the printer buffer
    ROR .printerBufferEmptyFlag                         rotate carry into bit 7 of the
                                                        printer buffer empty flag
    BMI .exit17
    LDY #%10000010                                      enable interrupt 1 of the user VIA
    STY .userVIAInterruptEnableRegister                 this is triggered by the printer
                                                        when it is ready to receive a new
                                                        character
    STA .userVIARegisterA                               pass byte to the Centronics port
it looks to me as though a character returned in Y by the JSR to .osbyte145EntryPoint will immediately be trampled on by the LDY #%10000010, and the character actually needs to be returned in A.
Yes, this is a known oddity in OSBYTE 145 related to a known bug in OSBYTE 152 in MOS 1.20, making it useless. It actually returns the byte in A, so on return from the OSBYTE handler will have been trampled on by restoring the calling A. It is fixed by MOS 2.00 and later. OSBYTE 145 correctly passes the return value from A to Y to return to the OSBYTE caller, but the printer driver code bypasses the OSBYTE handler and calls the code direct, so knows the code has ended with TAY so A will be the same as Y.
In the past I have simply taken the easy option and always returned the character in both A and Y from REMV whether V is set or clear; is this in fact *required* for things to work correctly, or am I missing something?
That's the safest option, especially for code being called by the MOS. Similarly, KEYV specifies that SHIFT and CTRL are returned in the flags, but there are two bits of the VDU code that rely on them being returned in A. Simple enough, end the code with PHP:PLA ;)

The documentation seems to have been written from the point of what you can test for after calling, not from the persepective of what you should return for callers to test.

Code: Select all

$ bbcbasic
PDP11 BBC BASIC IV Version 0.36
(C) Copyright J.G.Harston 1989,2005-2020
>_
SteveF
Posts: 955
Joined: Fri Aug 28, 2015 9:34 pm
Contact:

Re: REMV API

Post by SteveF »

Brilliant, thanks Jonathan!
Post Reply

Return to “programming”