' ë 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4²0    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Þ 5èB .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6ˆK    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8†K .SpaceTable  EQUB &20-&20 : EQUB &CD-&20 : EQUB &CE-&20 : EQUB &CF-&208�K .CtrlTable   EQUB 0       : EQUB 0       : EQUB &00-&00 : EQUB &E0-&008šK .CtrlMTable  EQUB 0       : EQUB 0       : EQUB &C0-&0D : EQUB &ED-&0D8¤K .ZeroTable   EQUB &30-&30 : EQUB &30-&30 : EQUB &C8-&30 : EQUB &D0-&308®E .AtSignTable EQUB &40-&40 : EQUB &CC-&40 : EQUB 0       : EQUB 08¸K .NumberTable EQUB &30-&30 : EQUB &20-&20 : EQUB &D0-&30 : EQUB &D0-&208ÂK .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8þ9 .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 í9€h ÿ ("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$ÿ