osbyte 37.9 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 29 30

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

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

        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
55
        LDRVC   R0,[R13]
Neil Turton's avatar
Neil Turton committed
56
        ]
Jeffrey Lee's avatar
Jeffrey Lee committed
57 58 59 60
        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
61 62 63 64 65 66
        MEND

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

OsByte
Kevin Bracey's avatar
Kevin Bracey committed
67
        Push    "R0, R3, R14"
Neil Turton's avatar
Neil Turton committed
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
        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
        IssueService
        TEQ     R1, #0
        STMEQIA R13, {R2-R4}                    ; if claimed, then update
                                                ; returned R0-R2
        CLRPSR  V_bit, R3                       ; clear V flag

        Pull    R0
        ADRNE   R0, BadCommandError             ; not claimed, R0 -> error
      [ International
        BLNE    TranslateError
      ]
        SWINE   XOS_GenerateError               ; set V if not claimed
Jeffrey Lee's avatar
Jeffrey Lee committed
85 86 87
        Pull    "R1-R4"
        ADD     SP,SP,#4
        Pull    "PC"
Neil Turton's avatar
Neil Turton committed
88 89 90 91 92

BadCommandError MakeErrorBlock BadCommand

GoMyOsbyte
        CLRPSR  V_bit, R3
Jeffrey Lee's avatar
Jeffrey Lee committed
93 94 95
        Pull    "R0,R3"                 ; pull the world AND the PC to return
        ADD     SP,SP,#4
        Pull    "PC"
Neil Turton's avatar
Neil Turton committed
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 141 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 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239


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

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
        CMP     R0, #MainVars           ; is it a variable ?
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
        TEQ     R0, #OsbyteSetCountry
        BEQ     DoOsbyteSetCountry
        TEQ     R0, #OsbyteSetAlphKey
        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

Osbyte00 ROUT
        TEQ     R1, #0
        MOVNE   R1, #MosVer
        MyOsbyte NE
240 241 242 243 244 245
      [ 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
246
        ADR     R0, FX0Error
247
      ]
Neil Turton's avatar
Neil Turton committed
248 249 250
        SWI     XOS_GenerateError
        ByteReturnV

251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
      [ UseNewFX0Error
InitNewFX0Error ROUT
        Push    "r0-r4,lr"
        MOV     r0, #0
        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
266
        MOVVC   r3, #ErrorNumber_FX0
267 268 269 270 271
        STRVC   r3, [r2]
10
        Pull    "r0-r4,pc"
      ]

Neil Turton's avatar
Neil Turton committed
272
FX0Error
273
        &       ErrorNumber_FX0
Neil Turton's avatar
Neil Turton committed
274
        =       "$MosTitle",0
275 276 277 278
      [ UseNewFX0Error
NewFX0ErrorFormat
        =       "$SystemName $VString (%dy %m3 %ce%yr)",0
      ]
Neil Turton's avatar
Neil Turton committed
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 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 332 333 334 335 336 337 338 339
        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

        MOV     r0, #open_read + open_mustopen
        ADR     r1, SerialInFilename    ; open serial stream for input
        SWI     XOS_Find
        STRVCB  r0, SerialInHandle      ; if did open then store handle
                                        ; (may store same value if already open, but who cares?)
20
        Pull    "r0"
        LDRB    R1, InputStream         ; old input stream
        STRB    R0, InputStream
        MyOsbyte

        LTORG

SerialInFilename
        =       "Serial#Buffer1:", 0
        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
340
        SavePSR R14                     ; for restoring I afterwards
Neil Turton's avatar
Neil Turton committed
341
10
Kevin Bracey's avatar
Kevin Bracey committed
342 343 344 345 346 347 348 349 350
        CLRPSR  I_bit, R3
 [ StrongARM
        NOP
        NOP
        NOP
        NOP
        NOP
 ]
        RestPSR R14                     ; restore old I
Neil Turton's avatar
Neil Turton committed
351

Jeffrey Lee's avatar
Jeffrey Lee committed
352
        LDR     R3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
        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
Jeffrey Lee's avatar
Jeffrey Lee committed
386 387 388 389
      [ ZeroPage <> 0
        LDR     R0, =ZeroPage
        ADD     R2, R2, R0
      ]
Neil Turton's avatar
Neil Turton committed
390 391 392 393 394 395 396 397 398
        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
Jeffrey Lee's avatar
Jeffrey Lee committed
399
        ASSERT  (ZeroPage :AND: 255) = 0
Neil Turton's avatar
Neil Turton committed
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 429 430 431 432 433 434 435 436 437 438 439 440
        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
441
        MOVCS   R2, #&FF                ; then return + say was enabled
Neil Turton's avatar
Neil Turton committed
442 443 444 445 446 447 448 449 450
        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
451 452
        CMP     R2, #&FF                ; Z=1 => already saturated, so don't store back
        STRNEB  R0, [R3, R1]
Neil Turton's avatar
Neil Turton committed
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 484 485 486 487 488 489
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
Jeffrey Lee's avatar
Jeffrey Lee committed
490
        LDR     R11, =ZeroPage+KeyWorkSpace ; can corrupt R11
Neil Turton's avatar
Neil Turton committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510
        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

511
        MRS     R3, CPSR                ; Interrupts disabled at the moment
Neil Turton's avatar
Neil Turton committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527

        ; 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.

        VDWS    R2

        LDRB    R0, [R2,#ScreenBlankFlag]
        LDRB    R1, [R2,#ScreenBlankDPMSState]

        TEQ     R0, #0                  ; NE => blanked
        TSTNE   R1, #1                  ; NE => blanked and DPMS turned off HSyncs
528
        MyOsbyte NE                     ; if true exit immediately
Neil Turton's avatar
Neil Turton committed
529

530
        LDRB    R2, CFStime
Neil Turton's avatar
Neil Turton committed
531
10
Kevin Bracey's avatar
Kevin Bracey committed
532
        BIC     R1, R3, #I32_bit
533
        MSR     CPSR_c, R1              ; CLI
534

Neil Turton's avatar
Neil Turton committed
535 536
   ;StrongARM core will not see interrupt unless disable is cleared for at least 5 cycles,
   ;in order to fill synchroniser pipe
537
 [ StrongARM
Neil Turton's avatar
Neil Turton committed
538 539 540 541 542 543
        NOP
        NOP
        NOP
        NOP
        NOP
 ]
544
        MSR     CPSR_c, R3              ; SEI
Neil Turton's avatar
Neil Turton committed
545
        LDRB    R1, CFStime
546
        TEQ     R1, R2
547 548 549
        MyOsbyte NE

 [ StorkPowerSave
550
; It is actually better to call Idle with interrupts disabled as it stops the interrupt
551 552 553
; 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 when
; we branch back up and enable interrupts.
Jeffrey Lee's avatar
Jeffrey Lee committed
554
        LDR     R0, =ZeroPage
555 556 557 558 559
        LDRB    R0, [R0, #PortableFlags]
        TST     R0, #PortableFeature_Idle
        SWINE   XPortable_Idle
 ]
        B       %BT10
Neil Turton's avatar
Neil Turton committed
560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 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

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

; 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
        IssueService
        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
680
        Pull    "R1,R4,PC"
Neil Turton's avatar
Neil Turton committed
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 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746

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

; 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
747 748 749 750
        CMP     R2, #4
        BHI     %FT90                           ; ignore change if too high

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

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

90      MOV     R1, R3
Neil Turton's avatar
Neil Turton committed
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
        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
Jeffrey Lee's avatar
Jeffrey Lee committed
785
        LDR     R11, =ZeroPage+KeyWorkSpace
Neil Turton's avatar
Neil Turton committed
786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828
        MOV     R12, #IOC
        BL      UpdateLEDs
        MyOsbyte

; Write Keys Pressed Info
Osbyte78
        BL      WriteKeysDown
        MyOsbyte

; Perform Keyboard Scan from 16
Osbyte7A
        MOV     R1, #&10
; 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
Jeffrey Lee's avatar
Jeffrey Lee committed
829
        LDR     R12, =ZeroPage+EscHan_ws
Neil Turton's avatar
Neil Turton committed
830 831 832 833 834 835 836 837
        STRB    R11, [R12, #ESC_Status-EscHan_ws]   ; set escape flag
        MOV     R14, PC
        LDMIA   R12, {R12, PC}
Exit7D
        TEQ     R12, #1
 [ Version >= 201
        Pull    "R11, PC", NE

838
        MRS     R11, CPSR                       ; Preserve old processor state
Neil Turton's avatar
Neil Turton committed
839
        ORR     R12, R11, #SVC_mode             ; Switch to SVC mode preserving IRQ_bit
840
        MSR     CPSR_c, R12
Neil Turton's avatar
Neil Turton committed
841 842 843
        Push    R14                             ; Preserve SVC_R14
        SWI     XOS_SetCallBack
        Pull    R14                             ; Restore SVC_R14
844
        MSR     CPSR_c, R11                     ; Switch back to original mode, with V_bit intact from SWI
Neil Turton's avatar
Neil Turton committed
845 846 847 848 849 850 851 852 853

        Pull    "R11, PC"
 |
        STREQB  R12, [R12, #IRQ_CallBack_Flag-1]
 ]
        Pull    "R11, PC"

; Acknowledge ESCAPE
Osbyte7E ROUT
Jeffrey Lee's avatar
Jeffrey Lee committed
854
        LDR     R3, =ZeroPage
Neil Turton's avatar
Neil Turton committed
855 856 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 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 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
        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
Osbyte81 ROUT
        TST     R2, #&80        ; is it negative inkey ?
        BEQ     %FT10           ; no, then not INKEY-256
        ANDS    R1, R1, #&FF    ; zero => INKEY(-256)
956
        MOVEQ   R1, #OSVersionID        ; then X := OS version number
Neil Turton's avatar
Neil Turton committed
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
        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
1002 1003 1004 1005
 [ {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
1006 1007 1008 1009
        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
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020
 ; 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...
1021
        MRS     R3, SPSR
Kevin Bracey's avatar
Kevin Bracey committed
1022
        TST     R3, #I32_bit            ; EQ => IRQs were on
1023
        MSREQ   CPSR_c, #SVC2632        ; so turn them on
Neil Turton's avatar
Neil Turton committed
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
        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
1038
        MOV     R0, #FSControl_Opt
Neil Turton's avatar
Neil Turton committed
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 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127
        SWI     XOS_FSControl
        ByteReturnV

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

; Issue Paged ROM Service Request
Osbyte8F
        IssueService
        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
        MOV     r0, #7                          ; OS_SerialOp to modify 6850 control register
        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
1128
        MOVS    R0, R1
Neil Turton's avatar
Neil Turton committed
1129 1130
        [ ProtectStationID
        MyOsbyte EQ
Neil Turton's avatar
Neil Turton committed
1131
        ]
1132
        [ STB :LAND: :DEF: ObsoleteNC1CMOS
Neil Turton's avatar
Neil Turton committed
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143
        ; Protect machine address CMOS (if not corrupt)
        ASSERT  EtherCheckCMOS = EtherAddrCMOS+6
        CMP     r0, #EtherAddrCMOS
        BLT     %FT10
        CMP     r0, #EtherCheckCMOS
        BGT     %FT10
        Push    "r0,r1"
        BL      GetMachineAddressCMOS
        Pull    "r0,r1"
        MyOsbyte EQ             ; don't allow write if address is valid
10
Neil Turton's avatar
Neil Turton committed
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185
        ]
        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
        SUB     R0, R0, #MainVars       ; Point to this block starting at &A6
        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
1186 1187
        TEQ     R0, #OsbyteKeyStatus - MainVars    ; sorry - it's not pure any more.
        BEQ     DoOsbyteKeyStatus                  ; mea culpa. KJB.
Neil Turton's avatar
Neil Turton committed
1188 1189 1190 1191
        STRB    R11, [R0, WsPtr]!       ; R0 +:= WsPtr
        LDRB    R2, [R0, #1]            ; Return contents of next loc in R2
        MyOsbyte

1192 1193 1194 1195 1196
; Keyboard status (OS_Byte 202).
; on entry: R0 = OsbyteKeyStatus - MainVars
;           R1 = old value
;           R11 = new value
DoOsbyteKeyStatus ROUT
1197 1198
        Push    "R0-R3,R10"
        MOV     R10,#UpCallV            ; (Can't use OS_UpCall - it enables IRQs and we're documented as not doing so)
1199 1200 1201 1202
        MOV     R3,R11                  ; R3 = new value
        MOV     R2,R1                   ; R2 = old value
        MOV     R1,#0                   ; pre-change
        MOV     R0,#UpCall_KeyboardStatus
1203
        BL      CallVector              ; go on then, interfere     (Corrupts R10 & WsPtr)
1204 1205

        LDR     R0, [R13]               ; get back original R0
Jeffrey Lee's avatar
Jeffrey Lee committed
1206
      [ ZeroPage = 0
1207
        STRB    R3, [R0, #OsbyteVars]!  ; R0 +:= WsPtr
Jeffrey Lee's avatar
Jeffrey Lee committed
1208 1209 1210 1211
      |
        LDR     R14, =ZeroPage+OsbyteVars
        STRB    R3, [R0, R14]!          ; R0 +:= WsPtr
      ]
1212 1213 1214 1215 1216
        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...

1217
        MOVNE   R10,#UpCallV
1218 1219
        MOVNE   R1,#1                   ; post-change
        MOVNE   R0,#UpCall_KeyboardStatus
1220 1221 1222
        BLNE    CallVector              ; can't do anything about it now...

        Pull    "R0-R3,R10"
1223 1224
        MyOsbyte

Neil Turton's avatar
Neil Turton committed
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
        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

Jeffrey Lee's avatar
Jeffrey Lee committed
1309
        LDR     R0, =ZeroPage+KeyWorkSpace
Neil Turton's avatar
Neil Turton committed
1310 1311 1312 1313 1314 1315
        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