osbyte 40 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; > $.Source.PMF.osbyte
; New version of OSBYTE which claims the ByteV(ector) properly
; PMF 18/9/86
; Updates:
; Kernel
; Version  Date        Who  Why
; 2.01     15-June-90  JSR  Change OS_Byte 124/125/126 to update the CallBack_Flag byte
;                            correctly, rather than setting it to 1. The bug caused vector
;                            callbacks to be delayed over much when escape was pressed.
Neil Turton's avatar
Neil Turton committed
24 25
; ????     08-Feb-95   WT   Change OS_Byte 106 to support the new cursor storage method
;                            introduced for Stork LCD support.
Neil Turton's avatar
Neil Turton committed
26 27 28

OsbyteLowLimit * &6A    ; osbytes lower than this get Y set to 0
OsbyteVeryLow  * &1A    ; osbytes lower than this are all recognised
29
OsbyteKeyStatus * &CA   ; only OS_Byte variable which isn't pure any more!
Neil Turton's avatar
Neil Turton committed
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52

; *****************************************************************************

        MACRO
        MyOsbyte $cond
        B$cond  GoMyOsbyte
        MEND

        MACRO
        MyOsWord $cond
        B$cond  GoMyOsword
        MEND

        MACRO
        Unused  $cond
        MOV$cond PC, R14 ; just return and let the next person have a go
        MEND

        MACRO
        ByteReturnV $cond
        ASSERT  "$cond"="" :LOR: "$cond"="VS"

        [ "$cond"=""
Jeffrey Lee's avatar
Jeffrey Lee committed
53
        LDRVC   R0,[R13]
Neil Turton's avatar
Neil Turton committed
54
        ]
Jeffrey Lee's avatar
Jeffrey Lee committed
55 56 57 58
        ADD$cond R13,R13,#4
        LDR$cond R3,[R13],#8 ; pull r3, junk r14
        LDR$cond PC,[R13],#4

Neil Turton's avatar
Neil Turton committed
59 60 61 62 63 64
        MEND

; Main OSbyte entry point
; R0,R1,R2 are parameters

OsByte
Kevin Bracey's avatar
Kevin Bracey committed
65
        Push    "R0, R3, R14"
Neil Turton's avatar
Neil Turton committed
66 67 68 69 70
        BL      OsByteGo                        ; Call the subsid entry pt.
        Pull    "R0,R3"
        Push    "R0-R4"
        LDMIA   R13, {R2-R4}                    ; R2=A, R3=X, R4=Y
        MOV     R1, #Service_UKByte             ; osbyte service reason
Robert Sprowson's avatar
Robert Sprowson committed
71
        BL      Issue_Service
Neil Turton's avatar
Neil Turton committed
72 73 74 75 76 77
        TEQ     R1, #0
        STMEQIA R13, {R2-R4}                    ; if claimed, then update
                                                ; returned R0-R2
        CLRPSR  V_bit, R3                       ; clear V flag

        Pull    R0
78
        ADRNE   R0, ErrorBlock_BadCommand       ; not claimed, R0 -> error
Neil Turton's avatar
Neil Turton committed
79 80 81 82
      [ International
        BLNE    TranslateError
      ]
        SWINE   XOS_GenerateError               ; set V if not claimed
Jeffrey Lee's avatar
Jeffrey Lee committed
83 84 85
        Pull    "R1-R4"
        ADD     SP,SP,#4
        Pull    "PC"
Neil Turton's avatar
Neil Turton committed
86

87
        MakeErrorBlock BadCommand
Neil Turton's avatar
Neil Turton committed
88 89 90

GoMyOsbyte
        CLRPSR  V_bit, R3
Jeffrey Lee's avatar
Jeffrey Lee committed
91 92 93
        Pull    "R0,R3"                 ; pull the world AND the PC to return
        ADD     SP,SP,#4
        Pull    "PC"
Neil Turton's avatar
Neil Turton committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140


; *****************************************************************************

OsByteGo ROUT
        AND     R0, R0, #&FF            ; no funny business!
        SUBS    R3, R0, #OsbyteLowLimit ; is it a low one ?
        BCS     HiOsbyte
        MOV     R2, #0                  ; lo one, so set Y to 0
        CMP     R0, #OsbyteVeryLow      ; is it one we recognise ?
10
        ADDCC   PC, PC, R0, LSL #2      ; then go thru despatch table
        B       TryInternational        ; else issue unknown osbyte service
20
        ASSERT  %BT20-%BT10 = 8

        BAL     Osbyte00
        BAL     Osbyte01
        BAL     Osbyte02
        BAL     Osbyte03
        BAL     Osbyte04
        BAL     Osbyte05
        BAL     Osbyte06
        BAL     Osbyte07

        BAL     Osbyte08
        BAL     Osbyte09
        BAL     Osbyte0A
        BAL     Osbyte0B
        BAL     Osbyte0C
        BAL     Osbyte0D
        BAL     Osbyte0E
        BAL     Osbyte0F

        BAL     Osbyte10
        BAL     Osbyte11
        BAL     Osbyte12
        BAL     Osbyte13
        BAL     Osbyte14
        BAL     Osbyte15
        BAL     Osbyte16
        BAL     Osbyte17

        BAL     Osbyte18
        BAL     Osbyte19

HiOsbyte
141
        CMP     R0, #OsByte_BaseOfOSByteVarTable ; is it a variable ?
Neil Turton's avatar
Neil Turton committed
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
30
        ADDCC   PC, PC, R3, LSL #2
        B       DoOsbyteVar             ; yes, then do variable mangling
40
        ASSERT  %BT40-%BT30=8

        BAL     Osbyte6A
        BAL     Osbyte6B
        BAL     Osbyte6C
        BAL     Osbyte6D
        BAL     Osbyte6E
        BAL     Osbyte6F

        BAL     Osbyte70
        BAL     Osbyte71
        BAL     Osbyte72
        BAL     Osbyte73
        BAL     Osbyte74
        BAL     Osbyte75
        BAL     Osbyte76
        BAL     Osbyte77

        BAL     Osbyte78
        BAL     Osbyte79
        BAL     Osbyte7A
        BAL     Osbyte7B
        BAL     Osbyte7C
        BAL     Osbyte7D
        BAL     Osbyte7E
        BAL     Osbyte7F

        BAL     Osbyte80
        BAL     Osbyte81
        BAL     Osbyte82
        BAL     Osbyte83
        BAL     Osbyte84
        BAL     Osbyte85
        BAL     Osbyte86
        BAL     Osbyte87

        BAL     Osbyte88
        BAL     Osbyte89
        BAL     Osbyte8A
        BAL     Osbyte8B
        BAL     Osbyte8C
        BAL     Osbyte8D
        BAL     Osbyte8E
        BAL     Osbyte8F

        BAL     Osbyte90
        BAL     Osbyte91
        BAL     Osbyte92
        BAL     Osbyte93
        BAL     Osbyte94
        BAL     Osbyte95
        BAL     Osbyte96
        BAL     Osbyte97

        BAL     Osbyte98
        BAL     Osbyte99
        BAL     Osbyte9A
        BAL     Osbyte9B
        BAL     Osbyte9C
        BAL     Osbyte9D
        BAL     Osbyte9E
        BAL     Osbyte9F

        BAL     OsbyteA0
        BAL     OsbyteA1
        BAL     OsbyteA2
        BAL     OsbyteA3
        BAL     OsbyteA4
        BAL     OsbyteA5

TryInternational                        ; special ones in the middle
217
        TEQ     R0, #OsByte_Country
Neil Turton's avatar
Neil Turton committed
218
        BEQ     DoOsbyteSetCountry
219
        TEQ     R0, #OsByte_Alphabet
Neil Turton's avatar
Neil Turton committed
220 221 222 223 224 225 226 227 228 229 230 231 232 233
        BEQ     DoOsbyteSetAlphKey
        MOV     PC, R14

; *****************************************************************************

; The Osbyte routines themselves


; Mos version number and title string
; R1 = 0 -> give an error with and string MosTitle
; R1 <>0 -> RETURN with R1 = MosVer

; R2 is Preserved

234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
; MosVer values clients might expect to read are as follows:
; (ref: http://beebwiki.mdfs.net/OSBYTE_%2600 )
;                            Volume  Directory  Extension
; Electron              0  \
; BBC A/B               1  |
; BBC B+                2  |
; Master 128            3  |  :d.    .          /
; Master ET             4  |
; Master Compact        5  |
; Arthur/RISC OS        6  |
; Springboard           7  /
; Unix                  8  \
; 6809/6309             9  |  N/A    /          .
; Mac OS X             10  /
; 6809/6309            17     :d.    .          /
; Commodore 64/128     28  \
; TI calculator        29  |  d:     N/A        .
; Amstrad CPC          30  |
; Sinclair ZX Spectrum 31  /
; DOS/Windows          32  \  d:\    \          .
; 6809/6309            39  /

Neil Turton's avatar
Neil Turton committed
256 257 258 259
Osbyte00 ROUT
        TEQ     R1, #0
        MOVNE   R1, #MosVer
        MyOsbyte NE
260 261 262 263 264 265
      [ UseNewFX0Error
        LDR     R0, =NewFX0Error
        LDR     LR, [R0]
        CMP     LR, #0
        ADREQ   R0, FX0Error ; Fall back to hardcoded string if new one isn't ready yet
      |
Neil Turton's avatar
Neil Turton committed
266
        ADR     R0, FX0Error
267
      ]
Neil Turton's avatar
Neil Turton committed
268 269 270
        SWI     XOS_GenerateError
        ByteReturnV

271 272 273
      [ UseNewFX0Error
InitNewFX0Error ROUT
        Push    "r0-r4,lr"
274
        MOV     r0, #ExtROMFooter_BuildDate
275 276 277 278 279 280 281 282 283 284 285
        BL      ExtendedROMFooter_FindTag
        CMP     r0, #0
        BEQ     %FT10
        MOV     r1, r0
        MOV     r0, #-1
        LDR     r2, =NewFX0Error+4
        MOV     r3, #?NewFX0Error - 4
        ADR     r4, NewFX0ErrorFormat
        SWI     XTerritory_ConvertDateAndTime
        ; Fill in error number on success
        LDRVC   r2, =NewFX0Error
286
        MOVVC   r3, #ErrorNumber_FX0
287 288 289 290 291
        STRVC   r3, [r2]
10
        Pull    "r0-r4,pc"
      ]

Neil Turton's avatar
Neil Turton committed
292
FX0Error
293
        &       ErrorNumber_FX0
294
        =       "$SystemName $VersionNo",0
295 296 297 298
      [ UseNewFX0Error
NewFX0ErrorFormat
        =       "$SystemName $VString (%dy %m3 %ce%yr)",0
      ]
Neil Turton's avatar
Neil Turton committed
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
        ALIGN

; *****************************************************************************

; Write User Flag
Osbyte01
V2B156
        ADD     R0, R0, #&F0            ; convert 1,5,6 to &F1,&F5,&F6
        B       DoOsbyteVar

; Select input stream
Osbyte02 ROUT
        AND     R0, R1, #1              ; new buffer id
        TEQ     R1, #0                  ; 0 => disable RXI
        Push    "r0"
        BNE     %FT10                   ; [enabling serial]

; disable serial by closing stream

        LDRB    r1, SerialInHandle
        TEQ     r1, #0
        MOVNE   r0, #0                  ; close file if handle non-zero
        STRNEB  r0, SerialInHandle      ; zero handle first
        SWINE   XOS_Find
        B       %FT20

; enable serial by opening stream

10
        LDRB    r0, SerialInHandle
        TEQ     r0, #0                  ; if a stream open already
        BNE     %FT20                   ; then skip

332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
        SUB     sp, sp, #64
        MOV     r3, sp
        ADR     r1, SerialInFilename

12
        LDRB    r0, [r1], #1
        CMP     r0, #0
        STRNEB  r0, [r3], #1
        BNE     %BT12

        MOV     r0, #SerialOp_GetDeviceName
        SWI     XOS_SerialOp
        ; r1 should now be correct device name or preserved on error
        ; i.e. left pointing at our default name
        ADD     lr, sp, #63
14
        SUBS    r0, r1, lr                      ; Basic buffer overflow check
        LDRNEB  r0, [r1], #1
        CMPNE   r0, #0
        STRB    r0, [r3], #1
        BNE     %BT14

Neil Turton's avatar
Neil Turton committed
354
        MOV     r0, #open_read + open_mustopen
355
        MOV     r1, sp                  ; open serial stream for input
Neil Turton's avatar
Neil Turton committed
356 357 358
        SWI     XOS_Find
        STRVCB  r0, SerialInHandle      ; if did open then store handle
                                        ; (may store same value if already open, but who cares?)
359
        ADD     sp, sp, #64
Neil Turton's avatar
Neil Turton committed
360 361 362 363 364 365 366 367 368
20
        Pull    "r0"
        LDRB    R1, InputStream         ; old input stream
        STRB    R0, InputStream
        MyOsbyte

        LTORG

SerialInFilename
369
        =       "Devices#Buffer1:$.", 0, "Serial", 0
Neil Turton's avatar
Neil Turton committed
370 371 372 373 374 375 376 377 378 379 380 381 382
        ALIGN

; Select output stream
Osbyte03

Osbyte04                                ; select cursor keys actions
V2B34
        ADD     R0, R0, #&E9            ; convert 3,4 to &EC,&ED
        B       DoOsbyteVar

; Write Printer driver type
Osbyte05 ROUT
        BL      MakePrinterDormant      ; for netprint
Kevin Bracey's avatar
Kevin Bracey committed
383
        SavePSR R14                     ; for restoring I afterwards
Neil Turton's avatar
Neil Turton committed
384
10
Kevin Bracey's avatar
Kevin Bracey committed
385
        CLRPSR  I_bit, R3
Jeffrey Lee's avatar
Jeffrey Lee committed
386
 [ InterruptDelay
Kevin Bracey's avatar
Kevin Bracey committed
387 388 389 390 391 392 393
        NOP
        NOP
        NOP
        NOP
        NOP
 ]
        RestPSR R14                     ; restore old I
Neil Turton's avatar
Neil Turton committed
394

395
        LDR     R3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428
        LDRB    R3, [R3, #ESC_Status]
        TST     R3, #&40
        MyOsbyte NE                     ; ESCAPE, so don't change

        LDR     R3, PrinterActive
        TEQ     R3, #0
        BNE     %BT10                   ; still active, then loop

; insert code here to notify UPTVEC of change

        B       V2B156                  ; R0 = 5, update variable

; Write Printer Ignore Character
Osbyte06
        STRB    R2, NoIgnore            ; (R2=0) allow chars to be ignored
        B       V2B156

; Write RS423 receive rate
; Write RS432 transmit rate
Osbyte07
Osbyte08
        SUB     r0, r0, #2              ; 7 -> 5; 8 -> 6
        SWI     XOS_SerialOp
        MyOsbyte

; Write First Flash Time
Osbyte09
        MOV     R2, #1
; and drop thru to ...

; Write Second Flash Time
Osbyte0A                                        ; (R2=0)
Osbyte910
429 430 431 432
      [ ZeroPage <> 0
        LDR     R0, =ZeroPage
        ADD     R2, R2, R0
      ]
Neil Turton's avatar
Neil Turton committed
433 434 435 436 437 438 439 440 441
        MOV     R0, R1                          ; new period
        LDRB    R1, [R2, #OsbyteVars + :INDEX: SpacPeriod] ; get old state
        STRB    R0, [R2, #OsbyteVars + :INDEX: SpacPeriod] ; store new

        LDRB    R3, FlashCount
        TEQ     R3, #0                          ; are we frozen ?
        MyOsbyte NE                             ; no, then finish

        STRB    R0, FlashCount                  ; kick the counter
442
        ASSERT  (ZeroPage :AND: 255) = 0
Neil Turton's avatar
Neil Turton committed
443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
        STRB    R2, FlashState                  ; force new state

        VDWS    WsPtr

        TEQ     R2, #0
        BEQ     ForceSecondState

        Push    "R1,R2"
        BL      DoFirstFlash
        Pull    "R1,R2"
        MyOsbyte

ForceSecondState
        Push    "R1,R2"
        BL      DoSecondFlash
        Pull    "R1,R2"
        MyOsbyte


; Write Keyboard Delay
Osbyte0B
V2BBC
        ADD     R0, R0, #(&C4-&0B)
        B       DoOsbyteVar

; Write Keyboard Rate
Osbyte0C
        TEQ     R1, #0
        BNE     V2BBC
        CLRPSR  I_bit, R0       ; this may take some time
        BL      ReadKeyDefaults
        MyOsbyte

; *****************************************************************************

; Disable / Enable Events
; R1 = Event number. Decrement/Increment semaphore for this event

Osbyte0D ROUT
Osbyte0E ROUT
        CMP     R1, #32                 ; if illegal event number
Ben Avison's avatar
Ben Avison committed
484
        MOVCS   R2, #&FF                ; then return + say was enabled
Neil Turton's avatar
Neil Turton committed
485 486 487 488 489 490 491 492 493
        BCS     %FT10

        ADD     R3, WsPtr, #:INDEX: EventSemaphores
        LDRB    R2, [R3, R1]            ; get semaphore for this event

        CMP     R0, #13                 ; 13 => disable, 14 => enable
        SUBEQ   R0, R2, #1              ; decrement semaphore
        ADDNE   R0, R2, #1              ; increment semaphore

Ben Avison's avatar
Ben Avison committed
494 495
        CMP     R2, #&FF                ; Z=1 => already saturated, so don't store back
        STRNEB  R0, [R3, R1]
Neil Turton's avatar
Neil Turton committed
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
10
        MOV     R1, R2                  ; R1 = R2 = old semaphore
        MyOsbyte

; *****************************************************************************

; Flush Buffer
Osbyte0F ROUT
        TEQ     R1, #0
        BNE     FlushInput
        BL      FlushAll
        MyOsbyte

; flush all buffers

FlushAll
        Push    R14
        MOV     R1, #(NBuffers-1)
10
        BL      FlushThis
        SUBS    R1, R1, #1
        BPL     %BT10
        Pull    PC

; flush input buffer

FlushInput
        LDROSB  R1, InputStream         ; get buffer id of input stream
        BL      FlushThis
        MyOsbyte

; *****************************************************************************

; Clear out the softkeys
Osbyte12 ROUT
        MOV     R0, #0
        STRB    R0, SoftKeyLen          ; purge current expansion
533
        LDR     R11, =ZeroPage+KeyWorkSpace ; can corrupt R11
Neil Turton's avatar
Neil Turton committed
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553
        Push    R4
        MOV     R1, #15
10
        MOV     R3, R1
        BL      SetupKeyName            ; exits with R0 -> SoftKeyName
        MOV     R2, #-1                 ; destroy variable
        MOV     R3, #0                  ; context pointer 0
        MOV     R4, #0                  ; type irrelevant
        SWI     XOS_SetVarVal           ; V will be set if not present
        SUBS    R1, R1, #1
        BPL     %BT10
        Pull    R4
        MyOsbyte

; *****************************************************************************

; Wait for Vsync

Osbyte13 ROUT

Jeffrey Lee's avatar
Jeffrey Lee committed
554 555 556 557 558 559 560 561 562 563
        ; Bail immediately if we're in an IRQ handler.
        ; (it's bad form for IRQ handlers to take too much time, and
        ; depending on various factors, it may be impossible for us to
        ; receive VSync IRQs from within a handler)
        ; https://www.riscosopen.org/tracker/tickets/424
        LDR     R3, =ZeroPage+IRQsema
        LDR     R3, [R3]
        CMP     R3, #0
        MyOsbyte NE

564
        MRS     R3, CPSR                ; Interrupts disabled at the moment
565
        LDRB    R2, CFStime
Neil Turton's avatar
Neil Turton committed
566

567
10
Neil Turton's avatar
Neil Turton committed
568 569 570 571 572 573 574
        ; bug fix for MED-03165. Having a DPMS-blanked screen stopped printing.
        ; The reason is that HSyncs stop and VSyncs stop as a consequence,
        ; but the Hourglass module uses this call to wait for the next VSync
        ; before animating the hourglass.
        ; When the screen is DPMS-blanked this osbyte will now return
        ; immediately. This is equivalent to the operation of the DPMSUtils
        ; module shipped with OS 3.50.
Jeffrey Lee's avatar
Jeffrey Lee committed
575 576 577
        ; For RISC OS 5, we've now extended it to also skip the wait if DPMS
        ; has turned off VSyncs, since it's plausible that hardware/drivers
        ; won't generate VSync interrupts in that state either.
Neil Turton's avatar
Neil Turton committed
578

579
        VDWS    LR
Neil Turton's avatar
Neil Turton committed
580

581 582
        LDRB    R0, [LR,#ScreenBlankFlag]
        LDRB    R1, [LR,#ScreenBlankDPMSState]
Neil Turton's avatar
Neil Turton committed
583 584

        TEQ     R0, #0                  ; NE => blanked
Jeffrey Lee's avatar
Jeffrey Lee committed
585
        TSTNE   R1, #3                  ; NE => blanked and DPMS turned off HSync or VSync
586
        MyOsbyte NE                     ; if true exit immediately
Neil Turton's avatar
Neil Turton committed
587

588 589
        ; Also, exit now if we don't have a driver active, or there's no
        ; mode programmed
590
        LDR     R0, [LR,#CurrentGraphicsVDriver]
591
        CMP     R0, #GraphicsVInvalid
592
        CMPEQ   R1, #255
593 594
        MyOsbyte EQ

595 596 597 598 599 600 601 602
; It is actually better to call Idle with interrupts disabled as it stops the interrupt
; going off on the way through the SWI dispatch and accidentally waiting for the next
; interrupt... The Idle will return when an interrupt is pending - it will be handled below
        LDR     R0, =ZeroPage
        LDRB    R0, [R0, #PortableFlags]
        TST     R0, #PortableFeature_Idle
        SWINE   XPortable_Idle

Kevin Bracey's avatar
Kevin Bracey committed
603
        BIC     R1, R3, #I32_bit
604
        MSR     CPSR_c, R1              ; CLI
605

Neil Turton's avatar
Neil Turton committed
606 607
   ;StrongARM core will not see interrupt unless disable is cleared for at least 5 cycles,
   ;in order to fill synchroniser pipe
Jeffrey Lee's avatar
Jeffrey Lee committed
608
 [ InterruptDelay
Neil Turton's avatar
Neil Turton committed
609 610 611 612 613 614
        NOP
        NOP
        NOP
        NOP
        NOP
 ]
615
        MSR     CPSR_c, R3              ; SEI
Neil Turton's avatar
Neil Turton committed
616
        LDRB    R1, CFStime
617
        TEQ     R1, R2
618 619
        MyOsbyte NE
        B       %BT10
Neil Turton's avatar
Neil Turton committed
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727

; *****************************************************************************

; Restore font definitions
Osbyte14
        MOV     R1, #1                  ; start at character 1*32
        MOV     R2, #3                  ; do 3 pages
        B       ResetPartFont

; *****************************************************************************

; Flush Selected Buffer
Osbyte15        ROUT
;
; TMD 24-Apr-92: Don't check buffer number, as this prevents the flushing
; of buffer manager buffers.
;
;        CMP     R1, #NBuffers
;        BCS     %FT10                   ; invalid buffer number
        BL      FlushThis
;10
        MyOsbyte


FlushThis

; code inserted here to zero PrinterActive iff you are flushing the printer
; buffer and the print destination is not a stream one

        CMP     R1, #Buff_RS423Out      ; is it an input buffer ? (not mouse)
        BCS     %FT20                   ; no, then branch

        MOV     R0, #0
        STRB    R0, SoftKeyLen          ; kill soft key expansion
        STRB    R0, VDUqueueItems       ; flush VDU queue
20
        SETV                            ; indicate purge not count
        B       CnpEntry

; Reset Group of font definitions
Osbyte19 ROUT
        CMP     R1, #8
        MyOsbyte CS                     ; not in range 0..7, ignore
        TEQ     R1, #0

        MOVEQ   R1, #1                  ; if 0 then start at 1*32, do 7 pages
        MOVEQ   R2, #7

        MOVNE   R2, #1                  ; else start at n*32, do 1 page
ResetPartFont

; first offer to International module

        Push    "R1, R2, R4, R5"
        MOV     R4, R1, LSL #5          ; R4 = start character
        ADD     R5, R4, R2, LSL #5      ; R5 = end character+1
        SUB     R5, R5, #1              ; R5 = end character
        LDRB    R3, Alphabet
        MOV     R2, #Inter_Define
        BL      OfferInternationalService
        Pull    "R1, R2, R4, R5"
        MyOsbyte EQ                     ; if claimed, don't use hard font

        ByteToNosbod DoResetFont
        MyOsbyte

; *****************************************************************************

; Set country number
; in:   R1 = country number

DoOsbyteSetCountry ROUT
        TEQ     R1, #&7F                ; if 127, just read country
        LDREQB  R1, Country
        MyOsbyte EQ

        BL      GetCountry
        Push    R4
        BL      ConvertCNoToANo         ; convert country no. to alphabet no.
        Pull    R4, NE
        MOVNE   R1, #0                  ; if not claimed, return with X=0
        MyOsbyte NE

; was claimed, so have country number in R1 and R3, alphabet no. in R4

        LDRB    R1, Country             ; save old country
        STRB    R3, Country             ; store new country
        STRB    R4, Alphabet            ; and new alphabet
        BL      NewKeyboard             ; R3=new keyboard, R4=alphabet for it
        BL      SetAlphabet
        Pull    R4
        MyOsbyte

SetAlphabet
        Push    "R1,R5,R14"
        MOV     R2, #Inter_Define       ; now redefine the chars
        MOV     R3, R4
        MOV     R4, #32
        MOV     R5, #255
        BL      OfferInternationalService
        Pull    "R1,R5,PC"

ConvertCNoToANo
        MOV     R3, R1                  ; put country no. in R3
        MOV     R2, #Inter_CNoToANo
OfferInternationalService
        Push    R14
        MOV     R1, #Service_International
Robert Sprowson's avatar
Robert Sprowson committed
728
        BL      Issue_Service
Neil Turton's avatar
Neil Turton committed
729 730 731 732 733 734 735 736 737 738 739
        TEQ     R1, #0                  ; set Z flag if claimed
        Pull    PC

; Notify keyboard handler of new keyboard

NewKeyboard
        Push    "R1,R4,R14"
        STRB    R3, Keyboard
        STRB    R4, KeyAlphabet
        MOV     R2, #Inter_Keyboard
        BL      OfferInternationalService
Kevin Bracey's avatar
Kevin Bracey committed
740
        Pull    "R1,R4,PC"
Neil Turton's avatar
Neil Turton committed
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806

; *****************************************************************************

; Set keyboard/alphabet for a particular country

DoOsbyteSetAlphKey ROUT
        TST     R1, #&80                ; if set then setting keyboard
        BNE     %FT10                   ; [setting keyboard]

; setting alphabet

        TEQ     R1, #&7F                ; 127 => just read alphabet
        LDREQB  R1, Alphabet
        MyOsbyte EQ

; 20/8/87 added code to do setting of default alphabet

        BL      GetCountry
        Push    R4
        BL      ConvertCNoToANo         ; try to convert R1 to alphabet number
        MOVNE   R4, R3                  ; if failed, try without converting
        BL      SetAlphabet             ; try to set this alphabet
        Pull    R4
        MOVNE   R1, #0                  ; if not claimed, return with X=0
        MyOsbyte NE

        LDRB    R1, Alphabet
        STRB    R3, Alphabet
        MyOsbyte

; setting keyboard

10
        AND     R1, R1, #&7F
        TEQ     R1, #&7F                ; 127 => just read keyboard
        LDREQB  R1, Keyboard
        MyOsbyte EQ

        BL      GetCountry
        Push    R4
        BL      ConvertCNoToANo         ; validating country no.
        Pull    R4, NE
        MOVNE   R1, #0                  ; if not claimed, return with X=0
        MyOsbyte NE

        LDRB    R1, Keyboard            ; load old keyboard
        BL      NewKeyboard             ; R3=new keyboard, R4=alphabet for it
        Pull    R4
        MyOsbyte

; *****************************************************************************

; All osbytes from &1A to &69 are unused (apart from international ones!)

; End of unused block

; Write pointer shape number, mouse linkage
;
; R1 = 0        => pointer off
; R1 = 1..4     => use pointer shape 1..4, linked to mouse
; R1 = &81..&84 => use pointer shape 1..4, unlinked
;
Osbyte6A
        VDWS    R0
        LDRB    R3, [R0, #PointerShapeNumber]   ; get old shape number
        AND     R2, R1, #&7F                    ; allow 0..4, &80..&84
Kevin Bracey's avatar
Kevin Bracey committed
807 808 809 810
        CMP     R2, #4
        BHI     %FT90                           ; ignore change if too high

        TEQ     R1, R3
811
        BEQ     %FT90                           ; same as old
Kevin Bracey's avatar
Kevin Bracey committed
812

813
        STRB    R1, [R0, #PointerShapeNumber]   ; will take effect on next vsync (UpdatePointer)
Kevin Bracey's avatar
Kevin Bracey committed
814 815

90      MOV     R1, R3
Neil Turton's avatar
Neil Turton committed
816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
        MyOsbyte

; Set vdu driver's screen number
Osbyte70
        ByteToNosbod DoSetDriverBank
        MyOsbyte

; Set displayed screen number
Osbyte71
        ByteToNosbod DoSetDisplayBank
        MyOsbyte

; *SHADOW
Osbyte72
        MOV     R0, #&EF                ; redirect to shadow variable
        MOV     R2, #0
        B       DoOsbyteVar

; *****************************************************************************

; Read VDU Status
Osbyte75
        Push    R2
        ByteToNosbod DoReadVDUStatus
        Pull    R2
        MyOsbyte

; Reflect Keyboard Status In LEDs
Osbyte76
845
        LDR     R11, =ZeroPage+KeyWorkSpace
Neil Turton's avatar
Neil Turton committed
846 847 848 849 850 851 852 853
        BL      UpdateLEDs
        MyOsbyte

; Write Keys Pressed Info
Osbyte78
        BL      WriteKeysDown
        MyOsbyte

854
; Perform Keyboard Scan from 15
Neil Turton's avatar
Neil Turton committed
855
Osbyte7A
856
        MOV     R1, #&0F
Neil Turton's avatar
Neil Turton committed
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
; and drop thru to ...

; Perform Keyboard Scan
Osbyte79
        BL      BBCScanKeys
        MyOsbyte

; Inform OS Printer Driver going Dormant
Osbyte7B
        BL      MakePrinterDormant
        ByteReturnV

; Clear Escape Condition
Osbyte7C
        BL      DoOsbyte7C
        MyOsbyte

; Set Escape Condition
Osbyte7D
        BL      DoOsbyte7D
        MyOsbyte

DoOsbyte7C
        Push    "R11, R14"
        MOV     R11, #0
        B       Osbyte7C7D

DoOsbyte7D
        Push    "R11, R14"
        MOV     R11, #&FF
Osbyte7C7D
888
        LDR     R12, =ZeroPage+EscHan_ws
Neil Turton's avatar
Neil Turton committed
889 890 891 892 893 894 895
        STRB    R11, [R12, #ESC_Status-EscHan_ws]   ; set escape flag
        MOV     R14, PC
        LDMIA   R12, {R12, PC}
Exit7D
        TEQ     R12, #1
        Pull    "R11, PC", NE

896
        MRS     R11, CPSR                       ; Preserve old processor state
Neil Turton's avatar
Neil Turton committed
897
        ORR     R12, R11, #SVC_mode             ; Switch to SVC mode preserving IRQ_bit
898
        MSR     CPSR_c, R12
Neil Turton's avatar
Neil Turton committed
899 900 901
        Push    R14                             ; Preserve SVC_R14
        SWI     XOS_SetCallBack
        Pull    R14                             ; Restore SVC_R14
902
        MSR     CPSR_c, R11                     ; Switch back to original mode, with V_bit intact from SWI
Neil Turton's avatar
Neil Turton committed
903 904 905 906 907

        Pull    "R11, PC"

; Acknowledge ESCAPE
Osbyte7E ROUT
908
        LDR     R3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
        LDRB    R3, [R3, #ESC_Status]
        TST     R3, #&40
        BEQ     NoESCToAck                      ; escape flag clear

        LDRB    R0, ESCeffect
        TEQ     R0, #0
        BNE     NoESCToAck                      ; escape effects disabled

        CLRPSR  I_bit, R0               ; enable interrupts (doing SOUNDs and
                                        ; closing files may take some time!)

        SWI     XSound_QInit
        BVS     %FT99                           ; no noises anyway!
        LDR     R0, =&01010008                  ; channel 8, amplitude &101
        MOV     R1, #&00010000                  ; pitch 0, duration 1
10
        SWI     XSound_ControlPacked
        BVS     %FT99                           ; (R0 would be corrupted)
        SUB     R0, R0, #1                      ; decrement channel
        TST     R0, #&FF                        ; if channel <> 0 then loop
        BNE     %BT10
99
        MOV     R0, #0

        STRB    R0, PageModeLineCount           ; zero line count

        LDRB    R1, ExecFileH
        CMP     R1, #0                          ; is EXEC file open (and V:=0)
        STRNEB  R0, ExecFileH                   ; if so, zero handle and close
                                                ; (will enable IRQs for me)
        SWINE   XOS_Find                        ; (R0=0, R1=handle)
        ByteReturnV VS                          ; if error then bomb out

        BL      FlushAll

NoESCToAck
        BL      DoOsbyte7C
        ANDS    R1, R3, #&40                    ; set R1 to 0 if wasn't escape,
        MOVNE   R1, #&FF                        ; &FF if was
        MyOsbyte


; Check for EOF
Osbyte7F
        MOV     R0, #OSArgs_EOFCheck
        SWI     XOS_Args                        ; result comes back in R2
        MOV     R1, R2
        ByteReturnV

; *****************************************************************************

; Read ADC or buffer status
Osbyte80
        AND     R1, R1, #&FF            ; no funny business

        TST     R1, #&80                ; is it ADVAL(-n)
        BEQ     AdvalPositive           ; no, then do adval(+ve)
        EOR     R1, R1, #&FF            ; convert to buffer number
        CLC                             ; (C:=0 and V:=0)
        TEQ     R1, #Buff_Mouse         ; is it mouse (only input buf >= 2) ?
        CMPNE   R1, #Buff_RS423Out ; C=1 <=> output buffer, so count spaces
                                        ; V=0, so will do count not purge

        ADR     R14, MyOsbyte80
CnpEntry
        Push    "R10,R12,R14"
        MOV     R10, #CNPV
        B       GoVec

MyOsbyte80
        MyOsbyte

AdvalPositive ROUT
        TEQ     R1, #7
        TEQNE   R1, #8
        Unused  NE

        Push    R11

        MOV     R11, R1                 ; save adval number
        SWI     XOS_Mouse
        Pull    R11, VS
        ByteReturnV VS

        TEQ     R11, #7
        MOVEQ   R1, R0                  ; R1 is required value

        MOV     R2, R1, LSR #8          ; put lo in R1, hi in R2
        AND     R1, R1, #&FF
        AND     R2, R2, #&FF

        Pull    R11
        MyOsbyte

; *****************************************************************************

; Perform INKEY operation
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022

; OSVersionID values clients might expect to read include the following:
; (ref: http://beebwiki.mdfs.net/OSBYTE_%2681 )
; Arthur 1.20    &A0
; RISC OS 2.00   &A1
; RISC OS 2.01   &A2
; RISC OS 3.0x   &A3
; RISC OS 3.1x   &A4
; RISC OS 3.50   &A5
; RISC OS 3.60   &A6
; RISC OS 3.7x   &A7
; RISC OS 4.0x   &A8
; RISC OS 4.3x   &A9
; RISC OS 5.xx   &AA
; Pyromaniac     &AE
; Springboard    &AF

Neil Turton's avatar
Neil Turton committed
1023 1024 1025 1026
Osbyte81 ROUT
        TST     R2, #&80        ; is it negative inkey ?
        BEQ     %FT10           ; no, then not INKEY-256
        ANDS    R1, R1, #&FF    ; zero => INKEY(-256)
1027
        MOVEQ   R1, #OSVersionID        ; then X := OS version number
Neil Turton's avatar
Neil Turton committed
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072
        MOVEQ   R2, #0                  ; and  Y := 0
        MyOsbyte EQ             ; if was INKEY-256 then claim
10
        Push    R14             ; save return address for if passing on
        ADR     R14, My81
        Push    R14             ; stack 'claiming' return address
        BL      DoInkeyOp       ; R14 = 'passing on' return address
NotMy81                         ; DoInkeyOp passed it on

        Pull    "R3,R14"        ; Throw away 'claiming' return address
                                ; and restore real passing on return address
        Unused                  ; else pass it on still

My81
        Pull    R14             ; throw away real passing on address
        ByteReturnV


; *****************************************************************************

; Read Machine High Order Address
Osbyte82
        MOV     R1, #&FF                ; Pretend we're an I/O processor !
        MOV     R2, #&FF
        MyOsbyte

; *****************************************************************************

; Read OSHWM
Osbyte83
        LDRB    R2, OSHWM               ; Read from silly variable
        MOV     R1, #0                  ; lo-byte is 0
        MyOsbyte

; *****************************************************************************

; Read Text Cursor Position (input cursor if split)
Osbyte86
        ByteToNosbod DoReadPOSVPOSI     ; Results in R1, R2 (i.e. POS, VPOS)
        MyOsbyte

; *****************************************************************************

; Read Screen Mode and Character at text cursor position
Osbyte87
Kevin Bracey's avatar
Kevin Bracey committed
1073 1074 1075 1076
 [ {FALSE}
 ; The user's PSR is no longer there. In fact, it never was (or hasn't been
 ; for a long time), because the return address passed to the vector always
 ; had the I bit set.
Neil Turton's avatar
Neil Turton committed
1077 1078 1079 1080
        LDR     R3, [R13, #StackOffset] ; get user's psr
        ANDS    R3, R3, #I_bit          ; EQ => irqs were on
        CLRPSR  I_bit, R3, EQ           ; so clear I_bit now
 ]
Kevin Bracey's avatar
Kevin Bracey committed
1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
 ; However, the SPSR _should_ have the user's interrupt state. If he had
 ; IRQs off, we will not have turned them back on, so neither we nor an
 ; interrupt routine will have called a a SWI, so SPSR will still be the
 ; SPSR from the original OS_Byte, with I set.
 ;
 ; If someone else is on ByteV, and passed it on, the rules say that they
 ; mustn't have enabled interrupts either, in which case any corrupted SPSR
 ; must still have I set.
 ;
 ; If the caller had interrupts enabled, an interrupt may have corrupted SPSR
 ; the worst effect of this is that we may not enable interrupts. So...
1092
        MRS     R3, SPSR
Kevin Bracey's avatar
Kevin Bracey committed
1093
        TST     R3, #I32_bit            ; EQ => IRQs were on
1094
        MSREQ   CPSR_c, #SVC2632        ; so turn them on
Neil Turton's avatar
Neil Turton committed
1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
        ByteToNosbod DoOSBYTE87         ; Results in R1, R2 (i.e. char, mode)
        MyOsbyte

; *****************************************************************************

; Insert Character Into Buffer
Osbyte8A
        BL      INSERT
        MyOsbyte

; *****************************************************************************

; Write Filing System Options : *OPT
Osbyte8B
Robert Sprowson's avatar
Robert Sprowson committed
1109
        MOV     R0, #FSControl_Opt
Neil Turton's avatar
Neil Turton committed
1110 1111 1112 1113 1114 1115 1116
        SWI     XOS_FSControl
        ByteReturnV

; *****************************************************************************

; Issue Paged ROM Service Request
Osbyte8F
Robert Sprowson's avatar
Robert Sprowson committed
1117
        BL      Issue_Service
Neil Turton's avatar
Neil Turton committed
1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
        MyOsbyte

; *****************************************************************************

; Select vertical screen shift and interlace option :*TV
Osbyte90
        LDRB    R0, TVVertical
        STRB    R1, TVVertical
        MOV     R1, R0                  ; old vertical in R1

        AND     R0, R2, #1
        LDRB    R2, TVInterlace         ; old interlace in R2
        STRB    R0, TVInterlace

        MyOsbyte

; *****************************************************************************

; Get Character From Buffer
Osbyte91
        CLRV                                    ; remove not examine
RemVEntry
        ADR     R14, MyOsbyte80
REMOVE
        Push    "R10,R12,R14"
        MOV     R10, #REMV
        B       GoVec

; *****************************************************************************

; Examine Buffer Status
Osbyte98
        SETV                                    ; examine not remove
        B       RemVEntry

; *****************************************************************************

; Insert Character Code Into buffer checking for ESCAPE
Osbyte99
        BL      DoInsertESC
        MyOsbyte

; *****************************************************************************

; Update pseudo 6850 control register and soft copy

Osbyte9C
1165
        MOV     r0, #SerialOp_Modify6850        ; OS_SerialOp to modify 6850 control register
Neil Turton's avatar
Neil Turton committed
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
        SWI     XOS_SerialOp
        MyOsbyte

; *****************************************************************************

; 'Fast TUBE BPUT'

Osbyte9D
        MOV     R0, R1                  ; R0 := character
        MOV     R1, R2                  ; R1 := handle
        SWI     XOS_BPut
        ByteReturnV

; *****************************************************************************

; Read VDU Variable (0..15 implemented)
OsbyteA0
        ByteToNosbod DoReadVDUVariable
        MyOsbyte

; *****************************************************************************

; Read CMOS RAM
OsbyteA1    ; R1 = address , R2 = result
        CLRPSR  I_bit, R0       ; this may take some time
        MOV     R0, R1
        BL      Read            ; Read CMOS ram at address <R0>
        MOV     R2, R0          ; Result in R0, return in R2
        MyOsbyte

; Write CMOS RAM
OsbyteA2
        CLRPSR  I_bit, R0       ; this may take some time
Robert Sprowson's avatar
Robert Sprowson committed
1199
        MOVS    R0, R1
Neil Turton's avatar
Neil Turton committed
1200
        [ ProtectStationID
1201
        ASSERT  NetStnCMOS = 0
Neil Turton's avatar
Neil Turton committed
1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
        MyOsbyte EQ
        ]
        MOV     R1, R2
        BL      Write
        MOV     R1, R0          ; R1 is supposed to be preserved
        MyOsbyte

; *****************************************************************************

; OsByte 163,... applications call
OsbyteA3 ROUT
        TEQ     R1, #242
        Unused  NE                      ; not 242 - pass it on
        BL      %FT10
        MyOsbyte                        ; if come to here, has been claimed

10
        Push    R14
        ByteToNosbod DoOsbyte163_242
        Pull    R14                     ; if come to here, wasn't claimed
        Unused

; *****************************************************************************

; Read Output cursor Position
OsbyteA5
        ByteToNosbod DoReadPOSVPOSO     ; Result in R1,R2   (Horiz,vert)
        MyOsbyte

; *****************************************************************************
;
; All calls &A6 to &FF are implemented together.
; <NEW VALUE> = (<OLD VALUE> AND R2 ) EOR R1
; The old value is returned in R1 and the next location is returned in R2
;
; *****************************************************************************

DoOsbyteVar
1240
        SUB     R0, R0, #OsByte_BaseOfOSByteVarTable
Neil Turton's avatar
Neil Turton committed
1241 1242 1243 1244
        LDRB    R3, [WsPtr, R0]         ; Load the byte
        AND     R11, R3, R2             ; Mangle it as required by the law
        EOR     R11, R11, R1            ; ................................
        MOV     R1, R3                  ; Return old value in R1
1245 1246 1247 1248

        TEQ     R0, #OsbyteKeyStatus - OsByte_BaseOfOSByteVarTable
        BEQ     DoOsbyteKeyStatus       ; sorry - it's not pure any more, mea culpa. KJB.

Neil Turton's avatar
Neil Turton committed
1249 1250 1251 1252
        STRB    R11, [R0, WsPtr]!       ; R0 +:= WsPtr
        LDRB    R2, [R0, #1]            ; Return contents of next loc in R2
        MyOsbyte

1253
; Keyboard status (OS_Byte 202).
1254
; on entry: R0 = OsbyteKeyStatus - OsByte_BaseOfOSByteVarTable
1255 1256 1257
;           R1 = old value
;           R11 = new value
DoOsbyteKeyStatus ROUT
1258 1259
        Push    "R0-R3,R10"
        MOV     R10,#UpCallV            ; (Can't use OS_UpCall - it enables IRQs and we're documented as not doing so)
1260 1261 1262 1263
        MOV     R3,R11                  ; R3 = new value
        MOV     R2,R1                   ; R2 = old value
        MOV     R1,#0                   ; pre-change
        MOV     R0,#UpCall_KeyboardStatus
1264
        BL      CallVector              ; go on then, interfere     (Corrupts R10 & WsPtr)
1265 1266

        LDR     R0, [R13]               ; get back original R0
1267
      [ ZeroPage = 0
1268
        STRB    R3, [R0, #OsbyteVars]!  ; R0 +:= WsPtr
1269 1270 1271 1272
      |
        LDR     R14, =ZeroPage+OsbyteVars
        STRB    R3, [R0, R14]!          ; R0 +:= WsPtr
      ]
1273 1274 1275 1276 1277
        LDRB    R14, [R0, #1]           ; Return contents of next loc in R2
        STR     R14, [R13, #8]          ; by popping it on the stack

        TEQ     R2, R3                  ; don't bother with UpCall if it didn't change...

1278
        MOVNE   R10,#UpCallV
1279 1280
        MOVNE   R1,#1                   ; post-change
        MOVNE   R0,#UpCall_KeyboardStatus
1281 1282 1283
        BLNE    CallVector              ; can't do anything about it now...

        Pull    "R0-R3,R10"
1284 1285
        MyOsbyte

Neil Turton's avatar
Neil Turton committed
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
        LTORG

; All the unused OS_Byte calls

; ADC stuff
Osbyte10 ROUT
Osbyte11 ROUT
; Incr/Decr Polling Int
Osbyte16
Osbyte17
; Unused
Osbyte18
; Write 1MHz bus selection
Osbyte6B
; Write Usage of Shadow memory for normal access
Osbyte6C
; Make temporary filing system permanent
Osbyte6D
; &6E and &6F are reserved by 3rd parties
Osbyte6E
Osbyte6F
; &73 and &74 reserved for Electron
Osbyte73
Osbyte74
; Close SPOOL(ON) & EXEC files
Osbyte77
; Read top of USER RAM
Osbyte84
; Read top of user RAM for given mode
Osbyte85
; *CODE
Osbyte88
; *MOTOR
Osbyte89
; *TAPE
Osbyte8C
;  *ROM
Osbyte8D
; Enter Language ROM
Osbyte8E
; Access Mem.Map.IO &92..&97
Osbyte92
Osbyte93
Osbyte94
Osbyte95
Osbyte96
Osbyte97
; Write to VidULA & COPY
Osbyte9A
Osbyte9B
; Old Style Speech
Osbyte9E
Osbyte9F
; Check Processor Type
OsbyteA4
        Unused

; *****************************************************************************
;
;       GetCountry - Read country
;
; in:   R1 = country number or alphabet number
;
; out:  IF R1=0 THEN
;         R1:=Configured Country
;         IF R1=0 THEN
;           R1:=LastKbId
;           IF R1>=&20 THEN R1:=0
;         ENDIF
;       ENDIF
;
;       R0 undefined
;

GetCountry ROUT
        TEQ     R1, #0                          ; if not setting default, exit
        MOVNE   PC, R14

        Push    R14
        MOV     R0, #CountryCMOS                ; read configured country
        BL      Read
        MOVS    R1, R0                          ; if not Country Default, exit
        Pull    PC, NE

1370
        LDR     R0, =ZeroPage+KeyWorkSpace
Neil Turton's avatar
Neil Turton committed
1371 1372 1373 1374 1375 1376
        LDRB    R1, [R0, #:INDEX: LastKbId]     ; read last valid keyboard id
        CMP     R1, #&20                        ; if <&20 then use this
        MOVCS   R1, #0                          ; else set to 0
        Pull    PC

        END