   10REM SAVE"$.Arabic.Source.Flip"
   20OsWrch = &FFEE
   30OsWord = &FFF1
   40OsByte = &FFF4
   50OsNewl = &FFE7
   60DIM O% &BFFF-P%
   70Q%=O%:R%=P%
   80PROCConsts
   90ExtIns = &FF00+3*Ins
  100PROCVars
  110very_temp=T%
  120KeyComEnd=99:KeyCom=90
  130CurrentState = J%
  140left=FNzp(2,"left")
  150right=FNzp(2,"right")
  160Mode = FNzp(2,"Mode")
  170oswptr=FNzp(2,"oswptr")
  180data=FNzp(2,"data:Flip")
  190HisIns = FNRmb(2)
  200ScrLines = FNRmb(1)
  210ScrBase = FNRmb(1)
  220Blocks = FNRmb(1)
  230ContextAnalyseFlag = FNRmb(1)
  240NumberReverseFlag = FNRmb(1)
  250dummy3=FNRmb(1)
  260TextDirnFlag = FNRmb(1)
  270dummy4=FNRmb(1)
  280FontDirnFlag = FNRmb(1)
  290dummy1=FNRmb(1)
  300ScreenDirnFlag = FNRmb(1)
  310dummy2=FNRmb(1)
  320osw = FNRmb(9)
  330px = FNzp(2,"px")
  340FOR Pass = 4 TO 6+L% STEP 2+L%
  350O%=Q%
  360P%=R%
  370[OPT Pass
  380.Mode3
  390  OPT FNload("Mode3",128*2)
  400.EndMode3
  410  EQUW &8000
  420.Mode012
  430  OPT FNload("Mode012",32*2)
  440.EndMode0
  450  EQUW &8000
  460.Mode45
  470  OPT FNload("Mode45",32*2)
  480.EndMode45
  490  EQUW &8000
  500.Mode6
  510  OPT FNload("Mode6",128*2)
  520.EndMode6
  530  EQUW &8000
  540.ModeBases
  550  EQUW Mode012 \ 0
  560  EQUW Mode012 \ 1
  570  EQUW Mode012 \ 2
  580  EQUW Mode3
  590  EQUW Mode45  \ 4
  600  EQUW Mode45  \ 5
  610  EQUW Mode6
  620.LineTab
  630  EQUB 31
  640  EQUB 31
  650  EQUB 31
  660  EQUB 24
  670  EQUB 31
  680  EQUB 31
  690  EQUB 24
  700.BaseTab
  710  EQUB &30
  720  EQUB &30
  730  EQUB &30
  740  EQUB &40
  750  EQUB &58
  760  EQUB &58
  770  EQUB &60
  780.BlockTab
  790  EQUB (&280 DIV 8 DIV 2)-1
  800  EQUB (&280 DIV 8 DIV 2)-1
  810  EQUB (&280 DIV 8 DIV 2)-1
  820  EQUB (&280 DIV 8 DIV 2)-1
  830  EQUB (&140 DIV 8 DIV 2)-1
  840  EQUB (&140 DIV 8 DIV 2)-1
  850  EQUB (&140 DIV 8 DIV 2)-1
  860  OPT FNAlign(256)
  870.charflip
  880.Px0346
  890  OPT FNload("Px0346",256)
  900.Px15
  910  OPT FNload("Px15",256)
  920.Px2
  930  OPT FNload("Px2",256)
  940.pxtab
  950  EQUW Px0346
  960  EQUW Px15
  970  EQUW Px2
  980  EQUW Px0346
  990  EQUW Px0346
 1000  EQUW Px15
 1010  EQUW Px0346
 1020 
 1030.FlipHandlerInit
 1040  OPT FNEnter
 1050  Lda #False:OPT FNSta(ContextAnalyseFlag):Lda #0:OPT FNSta(CurrentState)
 1060  Lda #False:OPT FNSta(NumberReverseFlag)
 1070  Lda #LeftRight:OPT FNSta(TextDirnFlag)
 1080  Lda #LeftRight:OPT FNSta(FontDirnFlag)
 1090  Lda #LeftRight:OPT FNSta(ScreenDirnFlag)
 1100\ Install interception for Insert-in-buffer to trap <FLIP> key
 1110  Lda InsV:OPT FNSta(HisIns)
 1120  Lda InsV+1:OPT FNSta(HisIns+1)
 1130  Lda #ExtIns MOD 256:Sta InsV
 1140  Lda #ExtIns DIV 256:Sta InsV+1
 1150  Lda #MyIns MOD 256:Sta &D9F+3*Ins+0
 1160  Lda #MyIns DIV 256:Sta &D9F+3*Ins+1
 1170  Lda &F4:Sta &D9F+3*Ins+2
 1180  OPT FNExit
 1190  Rts
 1200 
 1210.MyIns
 1220  PHP:PHY:PHX:PHA
 1230  Cpx #0:Bne notkeyboard
 1240  Cmp #&8B:Bne notflip
 1250  PLA:PLX:PLY:PLP
 1260  Rts
 1270.notflip
 1280.notkeyboard
 1290  PLA:PLX:PLY:PLP
 1300  OPT FNJmpI(HisIns)
 1310 
 1320.otherCountry
 1330  \ Undo any reversals
 1340  PHY:PHX:PHA
 1350  Jsr ScreenFlip_UK
 1360  Jsr FontFlip_UK
 1370  Jsr TextFlip_UK
 1380  PLA:PLX:PLY
 1390  Rts
 1400 
 1410 
 1420.FlipHandler \ ***** OSBYTE ENTRY POINT WITH A,X,Y SET UP
 1430  Cpx #21:Bne otherCountry
 1440  Cpy #0:Bne x1
 1450  Jmp CountryArabic
 1460.x1
 1470  Cpy #1:Bne x2
 1480  Jmp ScreenFlip_Other
 1490.x2
 1500  Cpy #2:Bne x3
 1510  Jmp ScreenFlip_Arabic
 1520.x3
 1530  Cpy #3:Bne x4
 1540  Jmp ScreenFlip_UK
 1550.x4
 1560  Cpy #4:Bne x5
 1570  Jmp FontFlip_Other
 1580.x5
 1590  Cpy #6:Bne x6
 1600  Jmp FontFlip_Arabic
 1610.x6
 1620  Cpy #7:Bne x7
 1630  Jmp FontFlip_UK
 1640.x7
 1650  Cpy #8:Bne x8
 1660  Jmp TextFlip_Other
 1670.x8
 1680  Cpy #10:Bne x9
 1690  Jmp TextFlip_Arabic
 1700.x9
 1710  Cpy #11:Bne x10
 1720  Jmp TextFlip_UK
 1730.x10
 1740  Cpy #14:Bne x11
 1750  Jmp Arabic_TextOn
 1760.x11
 1770  Cpy #15:Bne x12
 1780  Jmp Arabic_TextOff
 1790.x12
 1800  Cpy #18:Bne x13
 1810  Jmp Arabic_NumeralsOn
 1820.x13
 1830  Cpy #19:Bne x14
 1840  Jmp Arabic_NumeralsOff
 1850.x14
 1860  Rts
 1870 
 1880.ScreenFlip_Other
 1890  OPT FNEnter
 1900\Lda #ASC("A"):\Jsr &E7E6
 1910  Jsr ScreenFlip
 1920  Jsr TextFlipAndMoveCursor
 1930  OPT FNExit
 1940  Lda #0
 1950  Rts
 1960.ScreenFlip_Arabic
 1970  OPT FNEnter
 1980\Lda #ASC("B"):\Jsr &E7E6
 1990  OPT FNLda(ScreenDirnFlag):Cmp #LeftRight:Bne z1a
 2000\Lda #ASC("C"):\Jsr &E7E6
 2010  Jsr ScreenFlip
 2020.z1a
 2030  OPT FNLda(TextDirnFlag):Cmp #LeftRight:Bne z1
 2040\Lda #ASC("D"):\Jsr &E7E6
 2050  Jsr TextFlipAndMoveCursor
 2060.z1
 2070  OPT FNExit
 2080  Lda #0
 2090  Rts
 2100.ScreenFlip_UK
 2110  OPT FNEnter
 2120\Lda #ASC("E"):\Jsr &E7E6
 2130  OPT FNLda(ScreenDirnFlag):Cmp #RightLeft:Bne z2a
 2140\Lda #ASC("F"):\Jsr &E7E6
 2150  Jsr ScreenFlip
 2160.z2a
 2170  OPT FNLda(TextDirnFlag):Cmp #RightLeft:Bne z2
 2180\Lda #ASC("G"):\Jsr &E7E6
 2190  Jsr TextFlipAndMoveCursor
 2200.z2
 2210  OPT FNExit
 2220  Lda #0
 2230  Rts
 2240.FontFlip_Other
 2250  OPT FNEnter
 2260\Lda #ASC("H"):\Jsr &E7E6
 2270  Jsr FontFlip
 2280  OPT FNExit
 2290  Lda #0
 2300  Rts
 2310.FontFlip_Arabic
 2320  OPT FNEnter
 2330\Lda #ASC("I"):\Jsr &E7E6
 2340  OPT FNLda(FontDirnFlag):Cmp #RightLeft:Beq z3
 2350\Lda #ASC("J"):\Jsr &E7E6
 2360  Jsr FontFlip
 2370.z3
 2380  OPT FNExit
 2390  Lda #0
 2400  Rts
 2410.FontFlip_UK
 2420  OPT FNEnter
 2430\Lda #ASC("K"):\Jsr &E7E6
 2440  OPT FNLda(FontDirnFlag):Cmp #LeftRight:Beq z4
 2450\Lda #ASC("L"):\Jsr &E7E6
 2460  Jsr FontFlip
 2470.z4
 2480  OPT FNExit
 2490  Lda #0
 2500  Rts
 2510.TextFlip_Other
 2520  OPT FNEnter
 2530\Lda #ASC("M"):\Jsr &E7E6
 2540  Jsr TextFlip
 2550  OPT FNExit
 2560  Lda #0
 2570  Rts
 2580.TextFlip_UK
 2590  OPT FNEnter
 2600\Lda #ASC("N"):\Jsr &E7E6
 2610  OPT FNLda(TextDirnFlag):Cmp #LeftRight:Beq z5
 2620\Lda #ASC("O"):\Jsr &E7E6
 2630  Jsr TextFlip
 2640.z5
 2650  OPT FNExit
 2660  Lda #0
 2670  Rts
 2680.TextFlip_Arabic
 2690  OPT FNEnter
 2700\Lda #ASC("P"):\Jsr &E7E6
 2710  OPT FNLda(TextDirnFlag):Cmp #RightLeft:Beq z6
 2720\Lda #ASC("Q"):\Jsr &E7E6
 2730  Jsr TextFlip
 2740.z6
 2750  OPT FNExit
 2760  Lda #0
 2770  Rts
 2780.Arabic_TextOn
 2790  OPT FNEnter
 2800\Lda #ASC("R"):\Jsr &E7E6
 2810  Lda #True:OPT FNSta(ContextAnalyseFlag)
 2820  OPT FNExit
 2830  Lda #0
 2840  Rts
 2850.Arabic_TextOff
 2860  OPT FNEnter
 2870\Lda #ASC("S"):\Jsr &E7E6
 2880  Lda #False:OPT FNSta(ContextAnalyseFlag):Lda #0:OPT FNSta(CurrentState)
 2890  OPT FNExit
 2900  Lda #0
 2910  Rts
 2920.Arabic_NumeralsOn
 2930  OPT FNEnter
 2940\Lda #ASC("T"):\Jsr &E7E6
 2950  Lda #True:OPT FNSta(NumberReverseFlag)
 2960  OPT FNExit
 2970  Lda #0
 2980  Rts
 2990.Arabic_NumeralsOff
 3000  OPT FNEnter
 3010\Lda #ASC("U"):\Jsr &E7E6
 3020  Lda #False:OPT FNSta(NumberReverseFlag)
 3030  OPT FNExit
 3040  Lda #0
 3050  Rts
 3060 
 3070 
 3080 
 3090 
 3100.CountryArabic \ Select Keyboard and Alphabet too.
 3110 \ **** Should the *Country command issue the *Alphabet/*Keyboard commands
 3120 \      too or should they be recursively invoked by the OsByte(70) ???
 3130 \      Here we assume doing them twice will do no harm.
 3140  PHX:PHY
 3150\Lda #ASC("V"):\Jsr &E7E6
 3160  Lda #71:Ldx #21:Jsr OsByte
 3170  OPT FNEnter
 3180  Jsr FontFlip_magic \ Start up with Arabic letters reversed
 3190  OPT FNExit
 3200  Lda #71:Ldx #21+128:\Jsr OsByte   \ *** Actually, it is significant
 3210                                \ whether or not the fonts are set up
 3220                                \ BEFORE or AFTER the fontflip!
 3230  Jsr KeyBoardArabic \ Fudge because Paul hasn't supplied FX 71 correctly
 3240  Jsr FontFlip_Arabic
 3250  Jsr ScreenFlip_Arabic
 3260  OPT FNEnter
 3270  Lda #True:OPT FNSta(ContextAnalyseFlag)
 3280  Lda #True:OPT FNSta(NumberReverseFlag)
 3290  OPT FNExit
 3300  PLY:PLX
 3310  Lda #0
 3320  Rts
 3330 
 3340.KeyBoardArabic
 3350\Lda #ASC("W"):\Jsr &E7E6
 3360  Ldy #KeyComEnd-KeyCom-1
 3370.lpkey
 3380  Lda KeyCom,Y:Sta &100,Y
 3390  Dey
 3400  Bpl lpkey
 3410  Ldx #0:Ldy #1:Jsr OsCli
 3420  Rts
 3430.KeyCom
 3440  EQUS "*KEYBOARD ARABIC":EQUB 13
 3450.KeyComEnd
 3460 
 3470.ScreenFlip
 3480  Lda #0:Jsr OsWrch  \ Flush pending context analyses
 3490\Lda #ASC("X"):\Jsr &E7E6
 3500  OPT FNLda(ScreenDirnFlag): Eor #1: OPT FNSta(ScreenDirnFlag)
 3510  Lda #160:Ldx #&55:Ldy #0
 3520  Jsr &FFF4
 3530  Txa: And #7: Tax: Lda LineTab,X: PHY:OPT FNSta(ScrLines):PLY
 3540  Lda BaseTab,X:OPT FNSta(ScrBase)  \ Y corrupted!
 3550  Lda BlockTab,X:OPT FNSta(Blocks)  \ Ditto
 3560  Txa
 3570  Asl A
 3580  Tay
 3590  Lda ModeBases,Y:Sta Mode
 3600  Lda pxtab,Y:Sta px
 3610  Iny:Lda ModeBases,Y:Sta Mode+1
 3620  Lda pxtab,Y:Sta px+1
 3630  Lda #160:Ldx #&50:Ldy #0
 3640  Jsr &FFF4
 3650  Stx left:Sty left+1
 3660  Ldy #0
 3670.INK
 3680  Lda (Mode),Y:INY:Pha
 3690  Lda (Mode),Y:Tax
 3700  Bmi NotFnd
 3710  Pla:INY
 3720  Cmp left:Bne INK
 3730  Cpx left+1:Bne INK
 3740\ FOUND...
 3750  PHY:OPT FNLda(ScrLines):PLY:Tax
 3760  DEY:DEY
 3770.EachRow
 3780  Lda (Mode),Y:INY:Sta left
 3790  Lda (Mode),Y:Sta left+1
 3800  Bpl nowrp
 3810  Ldy #0
 3820  Bra EachRow
 3830.nowrp
 3840  INY
 3850  Lda (Mode),Y:INY:Sec:Sbc #8:Sta right
 3860  Lda (Mode),Y:Sbc #0:Sta right+1
 3870  DEY
 3880  Jsr FlipRow
 3890  Dex
 3900  Bpl EachRow
 3910  Rts
 3920.NotFnd
 3930  BRK:EQUB 17:EQUS "Didn't find it...":EQUB 0
 3940.FlipRow
 3950  PHX:PHY
 3960  OPT FNLda(Blocks):Tax
 3970.NextBlk
 3980  Ldy #7
 3990.lp2
 4000  Lda (left),Y
 4010  PHA
 4020  Lda (right),Y
 4030  Phy:tay:lda (px),y:ply
 4040  Sta (left),Y
 4050  PLA
 4060  Phy:tay:lda (px),y:ply
 4070  Sta (right),Y
 4080  Dey
 4090  Bpl lp2
 4100  Jsr Closer \ Corrupts Y
 4110  Dex
 4120  Bpl NextBlk
 4130  PLY:PLX
 4140  Rts
 4150 
 4160.PHEXIT
 4170  Lda left+1:Jsr PB
 4180  Lda left:Jsr PB
 4190  Lda #ASC("-"):Jsr &E7E6
 4200  Lda right+1:Jsr PB
 4210  Lda right:Jsr PB
 4220  Lda #ASC(","):Jsr &E7E6
 4230  Rts
 4240 
 4250.PB
 4260  PHA
 4270  Lsr A:Lsr A:Lsr A:Lsr A
 4280  Jsr PN
 4290  Pla
 4300.PN
 4310  And #&0F
 4320  Cmp #10
 4330  Bcc zzz1
 4340  Adc #6
 4350.zzz1
 4360  Adc #ASC("0")
 4370  Jmp &E7E6
 4380 
 4390.Closer \ we allow this to corrupt Y
 4400  Pha
 4410  Lda left:Clc:Adc #8:Sta left
 4420  Lda left+1:Adc #0:Sta left+1
 4430  Lda left:Cmp #0:Bne qq4:Lda left+1:Cmp #&80:Bne qq4
 4440  OPT FNLda(ScrBase):Sta left+1     \ Y corrupted!
 4450.qq4
 4460  Lda right:Cmp #0:Bne qq3
 4470  OPT FNLda(ScrBase): Cmp right+1:Bne qq3 \ Y again corrupted
 4480  Lda #&80:Sta right+1
 4490.qq3
 4500  Lda right:Sec:Sbc #8:Sta right
 4510  Lda right+1:Sbc #0:Sta right+1
 4520  Pla
 4530  Rts
 4540 
 4550.FontFlip_magic
 4560  Lda #128+32
 4570  Bra FontFlip_p
 4580.FontFlip
 4590\Lda #ASC("Y"):\Jsr &E7E6
 4600  OPT FNLda(FontDirnFlag): Eor #1: OPT FNSta(FontDirnFlag)
 4610\ use 'charflip' to reverse bits in byte
 4620  Lda #32
 4630.FontFlip_p
 4640.chflp
 4650  \Cmp #ASC("0"):\Bne tt1:\Lda #ASC("9")+1:\.tt1
 4660  Pha
 4670  Jsr flipch
 4680  Pla:Clc:Adc #1
 4690  Bne chflp
 4700  Rts
 4710 
 4720.flipch
 4730  PHP:SEI
 4740  Ldy oswptr:Phy
 4750  Ldy oswptr+1:Phy
 4760  Pha
 4770  Ldx &F4:Lda &DF0,X:Sta oswptr+1
 4780  Lda #osw: Sta oswptr
 4790  Pla:Sta (oswptr)
 4800  Lda #10:Ldx oswptr:Ldy oswptr+1
 4810  Jsr OsWord
 4820  Lda #23:Jsr OsWrch
 4830  Lda (oswptr):Jsr OsWrch
 4840  Ldy #1
 4850.eachfl
 4860  Lda (oswptr),Y:Tax:Lda charflip,X
 4870  Jsr OsWrch
 4880  Iny:Cpy #9:Bne eachfl
 4890  Ply:Sty oswptr+1
 4900  Ply:Sty oswptr
 4910  PLP
 4920  Rts
 4930 
 4940.TextFlipAndMoveCursor
 4950  Lda #134: Jsr OsByte: Phy: Phx \ (X,Y) -> X, Y regs
 4960  Jsr TextFlip
 4970  Lda #31: Jsr OsWrch: Pla: Jsr OsWrch: Pla: Jsr OsWrch
 4980  Rts
 4990 
 5000.TextFlip
 5010\Lda #ASC("Z"):\Jsr &E7E6
 5020  OPT FNLda(TextDirnFlag): Eor #1: OPT FNSta(TextDirnFlag)
 5030  Lda #23:Jsr OsWrch:
 5040  Lda #16:Jsr OsWrch:
 5050  Lda #1*2:Jsr OsWrch:\Lda #(255-7*2):Lda #255:Jsr OsWrch
 5060  Lda #0:Jsr OsWrch:Jsr OsWrch:Jsr OsWrch:Jsr OsWrch:Jsr OsWrch:Jsr OsWrch
 5070  Rts
 5080 
 5090]
 5100NEXT Pass
 5110C%=FlipHandler:G%=FlipHandlerInit
 5120H% = ContextAnalyseFlag:I% = NumberReverseFlag
 5130OSCLI("Save $.Arabic.Object.FlipObj "+STR$~(Q%)+" "+STR$~(O%)+" "+STR$~(R%-&8000+&3000)+"  "+STR$~(R%-&8000+&3000))
 5140CHAIN"$.Arabic.Source.StateMC"
 5150DEFFNload(F$,Size)
 5160OSCLI("Load $.Arabic.Object."+F$+" "+STR$~(O%))
 5170REMIF ((Pass AND 3)=0) AND ((P%+Size-1)DIV256 <> P%DIV256) THEN PRINT"Table ";F$;" over page boundary"
 5180O%=O%+Size:P%=P%+Size
 5190=Pass
 5200 
 5210DEFFNAlign(Boundary) : REM &40, &80, or &100
 5220Boundary=Boundary-1
 5230NewP%=(P%+Boundary) AND (NOT Boundary)
 5240O%=O%+(NewP%-P%)
 5250P%=NewP%
 5260=Pass
 5270 
 5280DEFPROCConsts
 5290REM TESTING BUG FIXdata=S%
 5300True = 0:False = 1
 5310LeftRight = 0:RightLeft = 1
 5320                                  REM MyXXX's are initialised here for
 5330                                  REM 2-pass assembly in Basic.
 5340Ins = 21   : InsV = FNVector(Ins)
 5350OsByte = &FFF4
 5360Byte = 5   : ByteV = FNVector(Byte)
 5370OsWord = &FFF1
 5380OsCli  = &FFF7
 5390OsRdCh = &FFE0
 5400RdCh = 8   : RdChV = FNVector(RdCh)
 5410OsRdSc = &FFB9
 5420OsWrCh = &FFEE
 5430OsNewl = &FFE7
 5440OsAscii = &FFE3
 5450OsWrSc = &FFB3
 5460OsFind = &FFCE
 5470OsFile = &FFDD
 5480OsArgs = &FFDA
 5490OsGbPb = &FFD1
 5500OsBPut = &FFD4
 5510OsBGet = &FFD7
 5520OsEvent = &FFBF
 5530GSInit = &FFC2
 5540GSRead = &FFC5
 5550ENDPROC
 5560 
 5570DEFFNVector(N)
 5580 = &200 + 2*N
 5590 
 5600DEFPROCVars
 5610ENDPROC
 5620 
 5630DEFFNzp(N,N$)
 5640LOCAL I
 5650  I = N%
 5660  N% = N% + N
 5670  IF N% > Z% THEN PRINT"ERROR: Using too much zero page.":END
 5671  PRINT"Zero page variable '";N$;"' at &";~I;" (";N;" byte";
 5672  IF N<>0 THEN PRINT "s";
 5673  PRINT ")"
 5680  = I
 5690 
 5700DEFFNRmb(N)
 5710LOCAL I
 5720  I = M%
 5730  M% = M% + N
 5740  = I
 5750 
 5760DEFFNEnter   : REM Called once on entry to Rom
 5770               REM Sets uplocal data area for easy access
 5780[OPT Pass
 5790  Lda data:PHA
 5800  Lda data+1:PHA
 5810  Ldx &F4:Lda &DF0,X
 5820  Sta data+1
 5830  Stz data
 5840  OPT FNStack(left)
 5850  OPT FNStack(left+1)
 5860  OPT FNStack(right)
 5870  OPT FNStack(right+1)
 5880  OPT FNStack(Mode)
 5890  OPT FNStack(Mode+1)
 5900  OPT FNStack(px)
 5910  OPT FNStack(px+1)
 5920  \Lda #ASC("<"):\Jsr &E7E6
 5930  \OPT FNLda(TextDirnFlag):\Jsr PB
 5940  \OPT FNLda(FontDirnFlag):\Jsr PB
 5950  \OPT FNLda(ScreenDirnFlag):\Jsr PB
 5960  \Lda #ASC(">"):\Jsr &E7E6
 5970]
 5980=Pass
 5990 
 6000DEFFNLda(variable_offset)
 6010[OPT Pass
 6020  Ldy #variable_offset:Lda (data),Y
 6030]
 6040=Pass
 6050 
 6060DEFFNSta(variable_offset)
 6070[OPT Pass
 6080  Ldy #variable_offset:Sta (data),Y
 6090]
 6100=Pass
 6110 
 6120DEFFNExit :REM Called once on exit from Rom
 6130[OPT Pass
 6140  \Lda #ASC("["):\Jsr &E7E6
 6150  \OPT FNLda(TextDirnFlag):\Jsr PB
 6160  \OPT FNLda(FontDirnFlag):\Jsr PB
 6170  \OPT FNLda(ScreenDirnFlag):\Jsr PB
 6180  \Lda #ASC("]"):\Jsr &E7E6
 6190  OPT FNUnstack(px+1)
 6200  OPT FNUnstack(px)
 6210  OPT FNUnstack(Mode+1)
 6220  OPT FNUnstack(Mode)
 6230  OPT FNUnstack(right+1)
 6240  OPT FNUnstack(right)
 6250  OPT FNUnstack(left+1)
 6260  OPT FNUnstack(left)
 6270  Pla: Sta data+1
 6280  Pla: Sta data
 6290]
 6300=Pass
 6310 
 6320DEFFNStack(reg)
 6330[OPT Pass
 6340  Lda reg:Pha
 6350]
 6360=Pass
 6370 
 6380DEFFNUnstack(reg)
 6390[OPT Pass
 6400  Pla:Sta reg
 6410]
 6420=Pass
 6430 
 6440DEFFNJmpI(offset)  : REM Jumps VIA private ram - indirect.
 6450IF offset >= &100 THEN =FNLongJmpI(offset)
 6460[OPT Pass
 6470  PHP:PHA:PHX
 6480  Ldx &F4:Lda &DF0,X:Sta very_temp+1:Lda #offset:Sta very_temp
 6490  Lda (very_temp):Pha:Inc very_temp:Bne P%+4:Inc very_temp+1
 6500  Lda (very_temp):Sta very_temp+1:Pla:Sta very_temp
 6510  PLX:PLA:PLP
 6520  Jmp (very_temp)
 6530]
 6540=Pass
