'  7' VersionNumber = &0113'$ :'. hostAddress = &2900'8& hostMaximum = &3000 - hostAddress'B :'L  codeBuffer hostMaximum'V :'`5 Zp          = &80 :  Two byte Zero page pointer'j OsByte      = &FFF4't :'~ ReflectedWrchXCode = &01' InterruptXCode     = &02' :' InterruptV  = &0204' InsertV     = &022A' UserOsWordV = &0200' KeyBoardV   = &0228' EventV      = &0220' WrchV       = &020E' :' EditorOswordCode   = &F0' EventNumber        = 5' :(  TerminateCode      = 0(
 ShiftLockCode      = 1( ReflectWrchCode    = 2( NewTranslationCode = 3(( :(2  Pass=4  7  2(<& P% = hostAddress: O% = codeBuffer(F [OPT Pass(P .Translation(Z :(dE EQUS Bytes( "00,01,02,03,04,05,06,07,08,09,0A,0B,0C,0D,0E,0F" )(nE EQUS Bytes( "10,11,12,13,14,15,16,17,18,19,1A,1B,1C,1D,1E,1F" )(xE EQUS Bytes( "20,21,22,23,24,25,26,27,28,29,2A,2B,2C,2D,2E,2F" )(E EQUS Bytes( "30,31,32,33,34,35,36,37,38,39,3A,3B,3C,3D,3E,3F" )(E EQUS Bytes( "40,41,42,43,44,45,46,47,48,49,4A,4B,4C,4D,4E,4F" )(E EQUS Bytes( "50,51,52,53,54,55,56,57,58,59,5A,5B,5C,5D,5E,5F" )(E EQUS Bytes( "60,61,62,63,64,65,66,67,68,69,6A,6B,6C,6D,6E,6F" )(E EQUS Bytes( "70,71,72,73,74,75,76,77,78,79,7A,7B,7C,7D,7E,7F" )(E EQUS Bytes( "80,81,82,83,84,85,86,87,88,89,8A,8B,8C,8D,8E,8F" )(E EQUS Bytes( "90,91,92,93,94,95,96,97,98,99,9A,9B,9C,9D,9E,9F" )(E EQUS Bytes( "A0,A1,A2,A3,A4,A5,A6,A7,A8,A9,AA,AB,AC,AD,AE,AF" )(E EQUS Bytes( "B0,B1,B2,B3,B4,B5,B6,B7,B8,B9,BA,BB,BC,BD,BE,BF" )(E EQUS Bytes( "C0,C1,C2,C3,C4,C5,C6,C7,C8,C9,CA,CB,CC,20,20,20" )(E EQUS Bytes( "D0,D1,D2,D3,D4,D5,D6,D7,D8,D9,DA,DB,DC,DD,DE,DF" )(E EQUS Bytes( "E0,E1,E2,E3,E4,E5,E6,E7,E8,E9,EA,EB,EC,ED,EE,EF" )(E EQUS Bytes( "F0,F1,F2,F3,F4,F5,F6,F7,F8,F9,FA,FB,FC,FD,FE,FF" )) :)2 .Start \Hostcode entry (initialization) point) \)"    Php),    Sei)6	    \)@@    \Hostcode is invoked with *code, XY = old USERV contents)J	    \)T    Stx OldUserOsWordV)^    Sty OldUserOsWordV+1)h    Ldx #DoUserOsWord  256)r    Ldy #DoUserOsWord  256)|    Stx UserOsWordV)    Sty UserOsWordV+1)    Ldx WrchV)    Ldy WrchV+1)    Stx OldWrchV)    Sty OldWrchV+1)    Ldx #EditWrch  256)    Ldy #EditWrch  256)    Stx WrchV)    Sty WrchV+1)    Lda #0)    Sta Index) .SetupOsByteLoop)    Ldx Index*&    Cpx #OsByteXTable-OsByteATable*    Beq SetupComplete*    Ldy OsByteATable,X*&    Lda OsByteXTable,X*0    Tax*:    Tya*D    Ldy #&00*N    Jsr OsByte*X    Txa*b    Ldx Index*l    Sta OldOsByteValue,X*v    Inc Index*    Bne SetupOsByteLoop* .SetupComplete*    Ldx InsertV*    Ldy InsertV+1*    Stx OldInsertV*    Sty OldInsertV+1*    Ldx #DoInsertV  256*    Ldy #DoInsertV  256*    Stx InsertV*    Sty InsertV+1*    Plp* *    Rts+ + .OsByteATable+7  EQUS Bytes( "DB,DD,DE,DF,E0,E1,E2,E3,E4,E5,ED" )+  .OsByteXTable+*7  EQUS Bytes( "8A,C0,D0,E0,F0,80,90,A0,B0,01,02" )+4 +> .DoNewTranslation+H    Ldx (&F0),Y \ X = P0+R    Iny+\    Lda (&F0),Y \ A = P1+f    Sta Translation,X+p    Ldx &F0+z    Ldy &F1+    Plp+    Rts+ + .DoUserOsWord+    Php+    Cmp #EditorOswordCode+    Bne NotEditorOsword+    Sei+    Ldy #0+     Lda #VersionNumber  256+    Sta (&F0),Y+    Iny+     Lda #VersionNumber  256,    Sta (&F0),Y,    Iny,;    Lda (&F0),Y    \ &F0,&F1 point at Osword parameters,$    Iny,.    Cmp #ShiftLockCode,8    Beq DoShiftLockFudges,B    Cmp #TerminateCode,L    Beq DoTerminate,V    Cmp #NewTranslationCode,`    Beq DoNewTranslation,j .UserOswordDone,t    Ldx &F0,~    Ldy &F1,    Plp,    Rts, , .NotEditorOsword,    Plp,    Jmp (OldUserOsWordV), , .DoShiftLockFudges,    Lda (&F0),Y \ A = P0,    Beq DoRestoreShiftLock,    Ldx InterruptV,    Ldy InterruptV+1-     Cpy #DoInterrupt  256-
-    Beq UserOswordDone   \ Already Active-    Stx OldInterruptV-    Sty OldInterruptV+1-(    Ldx #DoInterrupt  256-2    Ldy #DoInterrupt  256-<    Stx InterruptV-F    Sty InterruptV+1-P     Bne UserOswordDone \ Jmp-Z .DoRestoreShiftLock-d    Ldx OldInterruptV-n    Ldy OldInterruptV+1-x    Beq UserOswordDone-    Stx InterruptV-    Sty InterruptV+1-    Ldy #0-    Sty OldInterruptV+1-     Beq UserOswordDone \ Jmp- - .DoTerminate-    Lda #0-    Sta Index- .RestoreOsByteLoop-    Ldx Index-&    Cpx #OsByteXTable-OsByteATable-    Beq RestoreOsByteDone.    Ldy OsByteATable,X.    Lda OsByteXTable,X.    Lda OldOsByteValue,X."    Tax.,    Tya.6    Ldy #&00.@    Jsr OsByte.J    Inc Index.T    Bne RestoreOsByteLoop.^ .RestoreOsByteDone.h    Sei.r    Ldx OldUserOsWordV.|    Ldy OldUserOsWordV+1.    Stx UserOsWordV.    Sty UserOsWordV+1.    Ldx OldInterruptV.    Ldy OldInterruptV+1.    Beq DoRestoreInsertV.    Stx InterruptV.    Sty InterruptV+1. .DoRestoreInsertV.    Sei.    Ldx OldInsertV.    Ldy OldInsertV+1.    Beq RestoreDone.    Stx InsertV/    Sty InsertV+1/ .RestoreDone/    Ldx OldWrchV/&    Ldy OldWrchV+1/0    Stx WrchV/:    Sty WrchV+1/D    Plp/N    Rts/X /b .DoInterrupt/l    Php/v    Pha/    Txa/    Pha/    Tya/    Pha/    Lda #&CA/    Ldx #&20/    Ldy #&DF/$    Jsr OsByte \Clear shift lock/    Pla/    Tay/    Pla/    Tax/    Pla0    Plp0    Jmp (OldInterruptV)0 0  .MakeInterrupt0*    Tya04    Pha0>    Ldx #InterruptXCode0H    Sei0R    Jsr MakeEvent0\    Ldx SaveX0f    Pla0p    Tay0z    Plp0    Rts0 0 .DoInsertV0    Php0    Cpx #00    Bne InsertBuffer0    Cmp #&0D0    Beq GetReturnInfo0    Cmp #&1B0    Beq GetEscapeInfo0    Cmp #&7F0    Beq GetDeleteInfo0    Cmp #&201    Beq GetSpaceInfo1    Bcc GetCtrlInfo1    Cmp #&2C1$    Bcc GetNumberInfo1.    Cmp #&3018    Beq GetZeroInfo1B    Bcc GetCommaEtcInfo1L    Cmp #&3C1V    Bcc GetNumberInfo1`    Cmp #&401j    Beq GetAtSignInfo1t    Bcc GetCommaEtcInfo1~    Stx SaveX1 .InsertChar1    Cmp InterruptChar1    Beq MakeInterrupt1    Tax1    Lda Translation,X1    Ldx SaveX1 .InsertBuffer1    Plp1    Jmp (OldInsertV)1 1 .GetReturnInfo1    Sei2     Stx SaveX2
    Ldx #&B62    Jsr InKey2    Bcc GetCtrlMInfo2(    Jsr GetInfo22    Adc ReturnTable,X2<    Bne GotInfo2F 2P .GetCtrlMInfo2Z    Jsr GetInfo2d    Adc CtrlMTable,X2n    Bne GotInfo2x 2 .GetEscapeInfo2    Sei2    Stx SaveX2    Ldx #&8F2    Jsr InKey2    Bcc GetCtrlInfo2    Jsr GetInfo2    Adc EscapeTable,X2    Bne GotInfo2 2 .GetDeleteInfo2    Jsr GetInfo2    Adc DeleteTable,X3    Bne GotInfo3 3 .GetSpaceInfo3"    Jsr GetInfo3,    Adc SpaceTable,X36    Bne GotInfo3@ 3J .GetCtrlInfo3T    Jsr GetInfo3^    Adc CtrlTable,X3h    Jmp GotInfo3r 3| .GetZeroInfo3   Jsr GetInfo3   Adc ZeroTable,X3   Bne GotInfo3 3 .GetAtSignInfo3   Jsr GetInfo3   Adc AtSignTable,X3   Bne GotInfo3 3 .GetNumberInfo3   Jsr GetInfo3   Adc NumberTable,X3   Bne GotInfo4 4 .GetCommaEtcInfo4   Jsr GetInfo4&   Adc CommaTable,X40   Bne GotInfo4: 4D .GotInfo4N    Ldy SaveY4X    Jmp InsertChar4b 4l .GetInfo4v    Sta SaveA4    Stx SaveX4    Sty SaveY4    Lda #&CA4    Ldx #&004    Ldy #&FF40    Jsr OsByte    \ Get Keyboard Status info4    Txa4    Eor #&204    Bit CtrlBit4    Beq NoCtrl4    Ldx #24    Bne TestShift4 .NoCtrl5    Ldx #05 .TestShift5    Bit ShiftBits5     Beq NoShift5*    Inx54 .NoShift5>    Lda SaveA5H    Clc5R    Rts5\ 5f .InKey5p    Sta SaveA5z    Sty SaveY5    Lda #&815    Ldy #&FF5,    Jsr OsByte    \ Is the key Pressed ?5    Txa5    Rol A5    Lda SaveA5)    Ldx SaveX   \ Was saved by caller5    Ldy SaveY5    Rts5 5B .EditWrch \Characters prefixed by &7F output in inverse video5    Bit DeletePending5    Bmi InverseWrch6    Cmp #&7F6    Beq PossibleDelete6    Jmp (OldWrchV)6$ .PossibleDelete6.    Txa68    Pha6B    Tya6L    Pha6V    Php6`    Sei6j    Lda #&DA6t    Ldx #06~    Ldy #&FF6K    Jsr OsByte \X = No. of bytes required for completion of  command  6    Plp6    Txa6    Bne WasNotDelete6    Dec DeletePending6    Bne WasDelete6 .WasNotDelete6    Lda #&7F6    Jsr Wrch6 .WasDelete6    Pla6    Tay7     Pla7
    Tax7    Rts7 7(0 .InverseWrch \ Here after &7F,Code sequence72%    Inc DeletePending \ Back to 07<    Pha7F    Lda #177P    Jsr Wrch7Z    Lda #&877d    Jsr Wrch7n    Lda #177x    Jsr Wrch7    Lda #07    Jsr Wrch7    Pla7    Pha7    Jsr Wrch7    Lda #177    Jsr Wrch7    Lda #&807    Jsr Wrch7    Lda #177    Jsr Wrch7    Lda #77    Jsr Wrch8    Pla8    Rts8 8" .MakeEvent8,    Lda #EventNumber86    Jmp (EventV)8@ 8J
 .Wrch8T    Jmp (OldWrchV)8^ 8hK .ReturnTable EQUB &0D-&0D : EQUB &C1-&0D : EQUB &C2-&0D : EQUB &C3-&0D8rK .EscapeTable EQUB &C4-&1B : EQUB &C5-&1B : EQUB &C6-&1B : EQUB &C7-&1B8|K .DeleteTable EQUB &7F-&7F : EQUB &C9-&7F : EQUB &CA-&7F : EQUB &CB-&7F8K .SpaceTable  EQUB &20-&20 : EQUB &CD-&20 : EQUB &CE-&20 : EQUB &CF-&208K .CtrlTable   EQUB 0       : EQUB 0       : EQUB &00-&00 : EQUB &E0-&008K .CtrlMTable  EQUB 0       : EQUB 0       : EQUB &C0-&0D : EQUB &ED-&0D8K .ZeroTable   EQUB &30-&30 : EQUB &30-&30 : EQUB &C8-&30 : EQUB &D0-&308E .AtSignTable EQUB &40-&40 : EQUB &CC-&40 : EQUB 0       : EQUB 08K .NumberTable EQUB &30-&30 : EQUB &20-&20 : EQUB &D0-&30 : EQUB &D0-&208K .CommaTable  EQUB &20-&20 : EQUB &30-&30 : EQUB &D0-&20 : EQUB &D0-&308 8 .ShiftBits EQUB &288 .CtrlBit   EQUB &408 8 .Index          EQUB 089 .OldOsByteValue EQUS OsByteXTable-OsByteATable,".")9 .OldUserOsWordV EQUW 09 .OldInsertV     EQUW 09 .OldInterruptV  EQUW 09& .OldWrchV       EQUW 090 .SaveA          EQUB 09: .SaveX          EQUB 09D .SaveY          EQUB 09N .DeletePending  EQUB 09X= .InterruptChar  EQUB &C7 \  Initially CTRL-SHIFT-Escape9b 9l ]9v 9h  ("save _bbc.Ed6502 "+~codeBuffer+" "+~O%+" "+~(&FFFF0000+Start)+" "+~(&FFFF0000+hostAddress))9 9 :9  Bytes(S$)9
 R$=""9  R$=R$+(("&"+S$,2)))9  S$=S$,4)9  S$=""9 =R$