Thanks, everyone, for helping me try to see what was going on with the OSBYTE calls. I'm still not sure I completely get it, but that's entirely my fault.

Anyway, the reason I asked the initial question is that I was trying to disassemble, annotate, and understand a Mode 7 text scroller that I found on some PD disc and shamelessly nicked.

Here it is, for what it's worth. I've kind of sidestepped the keyboard buffer flush-fail issues by using Escape as the exit key, which doesn't seem to present any of the problems we've been discussing in this thread! So, er, sorry for wasting your time!

Code: Select all

```
20MODE7
30M$="Lorem ipsum dolor sit amet, consectetuer adipiscing elit. "
40S%=TOP+LEN(M$)+&100:PRINT"Enter starting addr (&";STR$~(S%);" or higher):"'"&";:INPUT""S$:IFS$=""S$="0"
50start%=EVAL("&"+S$):IF start%<S% start%=S%
60PRINT'"Assembling at &";STR$~(start%);"..."'
70oswrch=&FFEE:oscli=&FFF7:osbyte=&FFF4
80FORO%=0TO2STEP2
90P%=start%
100[OPT O%
110EQUB text MOD 256
120EQUB text DIV 256
130EQUB (end-&3E8) MOD 256
140EQUB (end-&3E8) DIV 256
150\*FX229,1
160LDA#229:LDX#1:LDY#0
170JSR osbyte
180STX &76
190\VDU22,7:
200LDA #&16
210JSR oswrch
220LDA #&07
230JSR oswrch
240\*KEY0:
250LDX #k0 MOD 256
260LDY #k0 DIV 256
270JSR oscli
280\cursor off:
290LDA #&17
300JSR oswrch
310LDA #&01
320JSR oswrch
330LDX #&08
340LDA #&00
350.vduloop
360JSR oswrch
370DEX
380CPX #&00
390BNE vduloop
400\flush all buffers:
410LDA #&0F
420LDX #&00
430JSR osbyte
440\keybd autorpt delay = 0.01s (normally 0.1s):
450LDA #&0C
460LDX #&01
470JSR osbyte
480\current pos in &74-5:
490LDA start%
500STA &74
510LDA start%+1
520STA &75
530.preblatt
540LDA &74
550STA &70
560LDA &75
570STA &71
580\wait for vsync:
590LDA #&13
600JSR osbyte
610LDX #&04
620LDA #&7C
630STA &73
640LDA #&00
650STA &72
660.outerblatt
670LDY #&00
680.blatt
690LDA (&70),Y
700STA (&72),Y
710INY
720BNE blatt
730INC &73
740INC &71
750DEX
760BNE outerblatt
770.scankey
780LDY #&FF
790LDX #&C6
800LDA #&81
810JSR osbyte
820CPY #&FF
830BEQ cursorup
840LDY #&FF
850LDX #&D6
860LDA #&81
870JSR osbyte
880CPY #&FF
890BEQ cursordown
900LDY #&FF
910LDX #&8F
920LDA #&81
930JSR osbyte
940CPY #&FF
950BEQ fin
960BNE scankey
970.cursorup
980LDA &75
990CMP start%+1
1000BNE scrollup
1010LDA &74
1020CMP start%
1030BNE scrollup
1040BEQ scankey
1050.scrollup
1060LDA &74
1070SEC
1080SBC #&28
1090STA &74
1100LDA &75
1110SBC #&00
1120STA &75
1130JMP preblatt
1140.cursordown
1150LDA &75
1160CMP start%+3
1170BNE scrolldown
1180LDA &74
1190CMP start%+2
1200BNE scrolldown
1210BEQ scankey
1220.scrolldown
1230LDA &74
1240CLC
1250ADC #&28
1260STA &74
1270LDA &75
1280ADC #&00
1290STA &75
1300JMP preblatt
1310.fin
1320\flush all buffers:
1330LDX #&00
1340LDA #&0F
1350JSR osbyte
1360\*FX138,0,128:
1370LDA #&8A
1380LDX #&00
1390LDY #&80
1400JMP osbyte
1410\*KEY0:
1420.k0 EQUS"*K.0MODE7|MREMÜFinal BASIC commands go here|M*FX229|M"
1430EQUB &0D
1440.text
1450]
1460T%=P%
1470N%=(1000DIVLEN(M$))*4
1480FORI%=1TON%:$P%=M$:P%=P%+LEN($P%):NEXT
1490$P%=STRING$(40-((P%-T%)MOD40),"-"):P%=P%+LEN($P%):?P%=0
1500[OPT O%
1510.end
1520]
1530NEXT
1540PRINT"&";STR$~(start%);" contains the text start-address (lo-byte first). &";STR$~(start%+2);" contains text endaddress minus &3E7."''"Arrow keys scroll, ESCAPE exits."'
1550PRINT"Press RETURN to run code":REPEAT:*FX21,0
1560UNTILGET=13:*FX21,0
1570CALL(start%+4)
```