   10REM SAVE"$.Arabic.Source.OsBytes"
   20FlipHandler = C%: AlphabetHandler = K%
   30                        REM else can get in between loading and using.
   40PROCConsts
   50PROCVars
   51data = FNzp(2)
   60DIM O% &BFFF-P%
   70R%=P%:Q%=O%
   80FOR Pass=4 TO 6+L% STEP 2+L%
   90P%=R%:O%=Q%
  100[OPT Pass
  110.ArabicByteHandler
  120  PHP
  130   Cmp #71:Beq mightbeus
  140   Cmp #70:Bne notus
  150   \ May want to accept other *COUNTRYs here to undo screenflip
  160   Cpx #21:\Bne notus  Indeed we do...
  170  PLP
  180  \ All Arabic osbytes enter here...
  190  Jsr FlipHandler
  200  Rts
  210.notus
  220  PLP
  230  Rts
  240.keyboard
  250  Cpx #21+128:Bne notus \ Undo Paul's cock-up...
  260  Ldx #10+128:Bra notus
  270.mightbeus
  280  Cpx #0:Bmi keyboard
  290  \ May want to intercept other *ALPHABETs here later to undo table lookup
  300  \Cpx #21:\Bne notus \ not *ALPHABET Arabic
  310  PLP
  320  Jsr AlphabetHandler
  330  Rts
  340.PHEX \ Here for debugging - may be removed if you need the space
  350      \ Any Ram code calling this MUST ensure this rom is switched in.
  360  PHA
  370  Lsr A:Lsr A:Lsr A:Lsr A
  380  Jsr PN
  390  Pla
  400.PN
  410  And #&0F
  420  Cmp #10
  430  Bcc noc
  440  Adc #6
  450.noc Adc #ASC("0")
  460  Jmp OsWrCh
  470]
  480NEXT Pass
  490F%=ArabicByteHandler
  500OSCLI("Save $.Arabic.Object.OsBytes "+STR$~(Q%)+" "+STR$~(O%)+" "+STR$~(R%-&8000+&3000)+"  "+STR$~(R%-&8000+&3000))
  510CHAIN"$.Arabic.Source.Last"
  520 
  530DEFFNRelocate(from, to, ram)
  540IF (ram+to-from)>=&100 THEN =FNLongRelocate(from, to, ram)
  550[OPT Pass
  560  Ldx #0:Ldy #ram   \ Y is pointer, X is counter
  570.copy
  580  Lda from,X: Sta (data),Y
  590  Iny
  600  Inx:Cpx #to-from:Bne copy
  610]
  620=Pass
  630 
  640DEFFNAddr(offset)
  650IF offset >= &100 THEN =FNLongAddr(offset)
  660[OPT Pass
  670  PHP:PHA:Ldx &F4:Lda &DF0,X:Tay:Ldx #offset:PLA:PLP
  680]
  690=Pass
  700 
  710DEFFNJmp(offset)  : REM Jumps to private ram - absolute NOT indirect.
  720IF offset >= &100 THEN =FNLongJmp(offset)
  730[OPT Pass
  740  PHP:PHA:PHX
  750  Ldx &F4:Lda &DF0,X:Sta very_temp+1:Lda #offset:Sta very_temp
  760  PLX:PLA:PLP
  770  Jmp (very_temp)
  780]
  790=Pass
  800 
  810DEFFNJmpI(offset)  : REM Jumps VIA private ram - indirect.
  820IF offset >= &100 THEN =FNLongJmpI(offset)
  830[OPT Pass
  840  PHP:PHA:PHX
  850  Ldx &F4:Lda &DF0,X:Sta very_temp+1:Lda #offset:Sta very_temp
  860  Lda (very_temp):Pha:Inc very_temp:Bne P%+4:Inc very_temp+1
  870  Lda (very_temp):Sta very_temp+1:Pla:Sta very_temp
  880  PLX:PLA:PLP
  890  Jmp (very_temp)
  900]
  910=Pass
  920 
  930DEFPROCConsts
  960                                  REM MyXXX's are initialised here for
  970                                  REM 2-pass assembly in Basic.
  980Ins = 21   : InsV = FNVector(Ins)
  990OsByte = &FFF4
 1000Byte = 5   : ByteV = FNVector(Byte)
 1010OsWord = &FFF1
 1020OsCli  = &FFF7
 1030OsRdCh = &FFE0
 1040RdCh = 8   : RdChV = FNVector(RdCh)
 1050OsRdSc = &FFB9
 1060OsWrCh = &FFEE
 1070OsNewl = &FFE7
 1080OsAscii = &FFE3
 1090OsWrSc = &FFB3
 1100OsFind = &FFCE
 1110OsFile = &FFDD
 1120OsArgs = &FFDA
 1130OsGbPb = &FFD1
 1140OsBPut = &FFD4
 1150OsBGet = &FFD7
 1160OsEvent = &FFBF
 1170GSInit = &FFC2
 1180GSRead = &FFC5
 1190ENDPROC
 1200 
 1210DEFFNVector(N)
 1220 = &200 + 2*N
 1230 
 1240DEFPROCVars
 1250ENDPROC
 1260 
 1270DEFFNzp(N)
 1280LOCAL I
 1290  I = N%
 1300  N% = N% + N
 1310  IF N% > Z% THEN PRINT"ERROR: Using too much zero page.":END
 1320  = I
 1330 
 1340DEFFNRmb(N)
 1350LOCAL I
 1360  I = M%
 1370  M% = M% + N
 1380  = I
 1390 
 1400DEFFNEnter   : REM Called once on entry to Rom
 1410               REM Sets uplocal data area for easy access
 1420[OPT Pass
 1430  Lda data:PHA
 1440  Lda data+1:PHA
 1450  Ldx &F4:Lda &DF0,X
 1460  Sta data+1
 1470  Stz data
 1500]
 1510=Pass
 1520 
 1530DEFFNLda(variable_offset)
 1540[OPT Pass
 1550  Ldy #variable_offset:Lda (data),Y
 1560]
 1570=Pass
 1580 
 1590DEFFNSta(variable_offset)
 1600[OPT Pass
 1610  Ldy #variable_offset:Sta (data),Y
 1620]
 1630=Pass
 1640 
 1650DEFFNExit :REM Called once on exit from Rom
 1660[OPT Pass
 1690  Pla: Sta data+1
 1700  Pla: Sta data
 1710]
 1720=Pass
