

                ORG 100H
                VAR 69,HIGHWAY2.COM
CONT            LD SP,STACK
                LD HL,HIBA
                LD (0BFF8H),HL
                LD A,4
                OUT (191),A
                LD BC,100H+28
                LD D,255
                EXOS 16
                CALL VID
                JP NZ,HIBA
                LD A,C
                CP 255
                JP Z,HIBA
                LD (FDH),A
                LD DE,0
                RRA
                RR D
                RRA
                RR D
                LD (VIDCIM1),DE
                CALL VID
                JR Z,NEMHIBA
                CP 7FH
                JP NZ,HIBA
                LD DE,16D6H
                EXOS 23
                JP NZ,HIBA
                LD C,255
NEMHIBA         LD A,C
                LD (FCH),A
                LD DE,0
                RRA
                RR D
                RRA
                RR D
                LD (VIDCIM2),DE
                CALL SZEG
                LD (FAH),A
                OUT (0B2H),A
                CALL SZEG
                LD (FBH),A
                OUT (0B3H),A
                LD A,(FCH)
                OUT (0B1H),A
                LD A,192
                LD DE,4000H
                EXX
                LD DE,(VIDCIM1)
                LD IX,VIDCIM1
                LD HL,4004H
                LD BC,13
L1              EX AF,AF'
                EXX
                LD HL,LINE
                LD BC,16
                LDIR
                EXX
                LD (HL),E
                INC HL
                LD A,D
                RRA
                RRA
                RRA
                AND 3
                OR 18H
                OR (IX+1)
                LD (HL),A
                INC HL
                LD (HL),E
                INC HL
                LD (HL),D
                ADD HL,BC
                INC D
                LD A,D
                AND 7
                JR NZ,L2
                LD A,E
                ADD A,32
                LD E,A
                CCF
                SBC A,A
                AND 0F8H
                ADD A,D
                LD D,A
L2              EX AF,AF'
                DEC A
                JR NZ,L1
                EXX
                LD HL,SYNC
                LD BC,HOSSZ
                LDIR
                LD A,(FDH)
                OUT (0B1H),A
                XOR A
                LD DE,NEV
                EXOS 1
                JP NZ,HIBA
                LD DE,6000H
                LD BC,2134
                EXOS 6
                JP NZ,HIBA
                DI
                LD HL,6000H
                LD DE,4000H
                LD B,0
                CALL UPCK
                XOR A
                OUT (82H),A
                LD A,0C0H
                LD HL,VIDCIM2+1
                RLD
                OUT (83H),A
                LD (LPT2),A
                LD HL,CIMKE
                LD DE,1000H
                LD BC,256
                LDIR
                CALL VARBIL
                LD HL,5800H
                LD DE,5801H
                LD BC,2DFH
                LD (HL),L
                LDIR
                EI
                CALL SCR
                XOR A
                LD DE,5B00H
                LD BC,0A228H
                EXOS 6
                JP NZ,HIBA
                EXOS 3
                DI
                LD A,1FH
                OUT (0A7H),A
                LD A,48
                OUT (0B4H),A
                LD A,255
                OUT (0B2H),A
                LD A,(FAH)
                OUT (0B2H),A
                LD A,0C3H
                LD HL,PORTFE
                LD (0),A
                LD (1),HL
                LD HL,ALLKEY
                LD (3),A
                LD (4),HL
                LD HL,JOY
                LD (8),A
                LD (9),HL
                LD HL,KONV
                LD (10H),A
                LD (11H),HL
                LD HL,KONV2
                LD (18H),A
                LD (19H),HL
                LD HL,KONV4
                LD (20H),A
                LD (21H),HL
                LD HL,KONV5
                LD (28H),A
                LD (29H),HL
                LD HL,ISR
                LD (38H),A
                LD (39H),HL
               ;LD A,(FCH)
               ;OUT (0B3H),A
               ;XOR A
               ;CALL 0CC80H
               ;LD A,(FBH)
               ;OUT (0B3H),A
                LD A,201
                LD (CIMECSKE),A
               ;LD (39411),A
                LD A,30H
                OUT (0B4H),A
                CALL VARBIL
                JR H8083H
VARBIL          DI
                LD A,8
                OUT (0B5H),A
                IN A,(0B5H)
                INC A
                RET NZ
                EI
                HALT
                JR VARBIL
H8083H          LD A,0C3H
                LD (CIMECSKE),A
START           LD HL,87ABH
                EXX
                LD A,80H
                LD R,A
                EXX
                JP (HL)

HIBA            LD SP,3FFFH
                LD A,255
                OUT (0B2H),A
                LD HL,HIBA
                LD (0BFF8H),HL
                LD A,90H
                OUT (82H),A
                LD A,0CFH
                OUT (83H),A
                LD A,0F5H
                LD HL,1837H
                LD (38H),A
                LD (39H),HL
                LD HL,F9H
                LD B,5
REND            PUSH BC
                LD C,(HL)
                INC HL
                EXOS 25
                POP BC
                DJNZ REND
                LD A,6
                EX AF,AF'
                LD A,1
                LD HL,0C00DH
                JP 0B217H
SZEG            EXOS 24
                JR NZ,HIBA
                LD A,C
                RET
VID             LD HL,STACK
                LD (HL),0
KER             EXOS 24
                JR Z,NAMIVAN
                CP 7FH
                JR NZ,HIBA
NAMIVAN         EX AF,AF'
                LD A,C
                CP 0FCH
                JR NC,NEMKER
                INC HL
                LD (HL),C
                JR KER
NEMKER          EX AF,AF'
                PUSH BC
                PUSH AF
VISSZA          LD C,(HL)
                EXOS 25
                DEC HL
                JR Z,VISSZA
VEGE            POP AF
                POP BC
                OR A
                RET
PORTFE          LD (HLP),HL
                POP HL
                PUSH AF
                LD A,(HL)
                LD (AR),A
                POP AF
                INC HL
                PUSH HL
                PUSH AF
                LD A,(AR)
                CP 0D3H
                JR NZ,NEMOUT
                POP AF
                PUSH AF
                LD L,A
                XOR A
                BIT 4,L
                JR Z,NEM1
                LD A,3FH
NEM1            OUT (0A8H),A
                OUT (0ACH),A
                XOR A
                SRL L
                RLA
                SRL L
                RLA
                SRL L
                RLA
                PUSH IX
                LD IX,TABL
                LD (CIM+2),A
CIM             LD A,(IX+0)
                OUT (81H),A
                POP IX
                POP AF
                LD HL,(HLP)
                RET
NEMOUT          CP 0EDH
                JR NZ,NEMED
                CALL BIL
                POP HL
                LD HL,(HLP)
                RET
NEMED           POP AF
                PUSH BC
                LD B,A
                CALL BIL
                POP BC
                LD HL,(HLP)
                RET
KEY             EX (SP),HL
                LD A,(HL)
                INC HL
                EX (SP),HL
                OUT (0B5H),A
                IN A,(0B5H)
                RET
ALLKEY          PUSH BC
                LD BC,0AFFH
A1              LD A,B
                DEC A
                OUT (0B5H),A
                IN A,(0B5H)
                AND C
                LD C,A
                DJNZ A1
                POP BC
                RET
JOY             PUSH BC
                LD B,0
                CALL JOY1
                LD A,C
                LD (JOY2+1),A
                CALL JOY1
                LD A,C
JOY2            OR 0
                POP BC
                RET
JOY1            LD C,8
JOY3            LD A,B
                INC B
                OUT (0B5H),A
                IN A,(0B6H)
                RRA
                CCF
                RL C
                JR NC,JOY3
                RET
ISR             DI
                PUSH AF
                PUSH BC
                LD A,48
                OUT (0B4H),A
               ;LD A,4
               ;OUT (0B5H),A
               ;IN A,(0B5H)
               ;LD BC,(MUS)
               ;BIT 0,A
               ;JR NZ,NEMF4
               ;LD A,12
               ;OUT (191),A
               ;JR NEMF2
 ;NEMF4           BIT 3,A
               ;JR NZ,NEMF6
               ;LD A,14
               ;OUT (191),A
               ;JR NEMF2
 ;NEMF6           BIT 7,A
               ;JR NZ,NEMF1
               ;LD C,0
 ;NEMF1           BIT 6,A
               ;JR NZ,NEMF2
               ;LD C,1
 ;NEMF2           LD (MUS),BC
               ;LD A,C
               ;OR A
               ;CALL Z,MUSIK
               ;CALL NZ,NOMUSIK
                POP BC
                POP AF
                RET
CIMECSKE        JP 0E274H
NOMUSIK         LD A,1FH
                OUT (0A7H),A
                RET
MUSIK           PUSH AF
                PUSH BC
                PUSH DE
                PUSH HL
                PUSH IX
                PUSH IY
                LD (SPHELY),SP
                LD SP,3FFFH
                LD A,(FCH)
                OUT (0B3H),A
                CALL 0CC83H
                LD A,(FBH)
                OUT (0B3H),A
                LD SP,(SPHELY)
                POP IY
                POP IX
                POP HL
                POP DE
                POP BC
                POP AF
                RET
MUS             DW 0
SPHELY          DW 0
BIL             LD A,255
                PUSH DE
                BIT 0,B
                CALL Z,SOR0
                BIT 1,B
                CALL Z,SOR1
                BIT 2,B
                CALL Z,SOR2
                BIT 3,B
                CALL Z,SOR3
                BIT 4,B
                CALL Z,SOR4
                BIT 5,B
                CALL Z,SOR5
                BIT 6,B
                CALL Z,SOR6
                BIT 7,B
                CALL Z,SOR7
                OR 0E0H
                POP DE
                RET
SOR0            PUSH AF
                XOR A
                OUT (0B5H),A
                IN A,(0B5H)
                     ;LS Z X V C B \ N
                     ;* * * * * * * *
                RLCA ;Z X V C B \ N LS C=LS
                RLCA ;X V C B \ N LS Z C=Z
                RLCA ;V C B \ N LS Z X C=X
                RLCA ;C B \ N LS Z X V C=V
                RL D ;* * * * * * * V  C=*
                RLCA ;B \ N LS Z X V C C=C
                RL D ;* * * * * * V C  C=*
                RRCA ;C B \ N LS Z X V C=C
                RRCA ;V C B \ N LS Z X C=V
                RRCA ;X V C B \ N LS Z C=X
                RL D ;* * * * * V C X  C=*
                RRCA ;Z X V C B \ N LS C=Z
                RL D ;* * * * V C X Z  C=*
                RRCA ;LS Z X V C B \ N C=LS
                RL D ;* * * V C X Z CS C=*
                POP AF
                AND D
                RET
SOR1            PUSH AF
                LD A,1
                OUT (0B5H),A
                IN A,(0B5H)
                     ;CT A S F D G LC H
                     ;* * * * * * * *
                RRCA ;H CT A S F D G LC C=H
                RRCA ;LC H CT A S F D G C=LC
                RRCA ;G LC H CT A S F D C=G
                RL D ;* * * * * * * G   C=*
                RRCA ;D G LC H CT A S F C=D
                RL D ;* * * * * * G D  C=*
               RRC D ;D * * * * * * G  C=D
                RRCA ;F D G LC H CT A S C=F
                RL D ;* * * * * * G F   C=D
                RL D ;* * * * * G F D   C=*
                RRCA ;S F D G LC H CT A C=S
                RL D ;* * * * G F D S   C=*
                RRCA ;A S F D G LC H CT C=A
                RL D ;* * * G F D S A   C=*
                POP AF
                AND D
                RET
SOR2            PUSH AF
                LD A,2
                OUT (0B5H),A
                IN A,(0B5H)
                     ;TB W E T R Y Q U
                     ;* * * * * * * *
                RRCA ;U TB W E T R Y Q C=U
                LD E,A
                RRCA ;Q U TB W E T R Y C=Q
                RRCA ;Y Q U TB W E T R C=Y
                RRCA ;T Y Q U TB W E T C=R
                RR D ;R * * * * * * *  C=*
                RRCA ;T R Y Q U TB W E C=T
                RL D ;* * * * * * * T  C=R
                RL D ;* * * * * * T R  C=*
                RRCA ;E T R Y Q U TB W C=E
                RL D ;* * * * * T R E  C=*
                RRCA ;W E T R Y Q U TB C=W
                RL D ;* * * * T R E W  C=*
               LD A,E ;U TB W E T R Y Q
                RRCA ;Q U TB W E T R Y C=Q
                RL D ;* * * T R E W Q  C=*
                POP AF
                AND D
                RET
SOR3            PUSH AF
                LD A,3
                OUT (0B5H),A
                IN A,(0B5H)
                     ;EC 2 3 5 4 6 1 7
                     ;* * * * * * * *
                RRCA ;7 EC 2 3 5 4 6 1 C=7
                LD E,A
                RRCA ;1 7 EC 2 3 5 4 6 C=1
                RRCA ;6 1 7 EC 2 3 5 4 C=6
                RRCA ;4 6 1 7 EC 2 3 5 C=4
                RR D ;4 * * * * * * *  C=*
                RRCA ;5 4 6 1 7 EC 2 3 C=5
                RL D ;* * * * * * * 5  C=4
                RL D ;* * * * * * 5 4  C=*
                RRCA ;3 5 4 6 1 7 EC 2 C=3
                RL D ;* * * * * 5 4 3  C=*
                RRCA ;2 3 5 4 6 1 7 EC C=2
                RL D ;* * * * 5 4 3 2  C=*
                LD A,E ;7 EC 2 3 5 4 6 1
                RRCA ;1 7 EC 2 3 5 4 6 C=1
                RL D ;* * * 5 4 3 2 1  C=*
                POP AF
                AND D
                RET
SOR4            PUSH AF
                LD A,3
                OUT (0B5H),A
                IN A,(0B5H)
                     ;EC 2 3 5 4 6 1 7
                     ;* * * * * * * *
                RRCA ;7 EC 2 3 5 4 6 1 C=7
                RR D ;7 * * * * * * *  C=*
                RRCA ;1 7 EC 2 3 5 4 6 C=1
                RRCA ;6 1 7 EC 2 3 5 4 C=6
                RL D ;* * * * * * * 6  C=7
                RL D ;* * * * * * 6 7  C=*
                LD A,5
                OUT (0B5H),A
                IN A,(0B5H)
                     ;* ER ^ 0 - 9 * 8
                     ;* * * * * * 6 7
                RRCA ;8 * ER ^ 0 - 9 * C=8
                RL D ;* * * * * 6 7 8  C=*
                RRCA ;* 8 * ER ^ 0 - 9 C=*
                RRCA ;9 * 8 * ER ^ 0 - C=9
                RL D ;* * * * 6 7 8 9  C=*
                RRCA ;- 9 * 8 * ER ^ 0 C=-
                RRCA ;0 - 9 * 8 * ER ^ C=0
                RL D ;* * * 6 7 8 9 0  C=*
                LD A,7
                OUT (0B5H),A
                IN A,(0B5H)
                BIT 5,A
                JR NZ,NEMBAL
                RES 4,D
NEMBAL          BIT 2,A
                JR NZ,NEMJOBB
                RES 3,D
NEMJOBB         BIT 1,A
                JR NZ,NEMLE
                RES 2,D
NEMLE           BIT 3,A
                JR NZ,NEMFEL
                RES 1,D
NEMFEL          BIT 7,A
                JR NZ,NEMALT
                RES 0,D
NEMALT          POP AF
                AND D
                RET
SOR5            PUSH AF
                LD A,2
                OUT (0B5H),A
                IN A,(0B5H)
                     ;TB W E T R Y Q U
                     ;* * * * * * * *
                RRCA ;U TB W E T R Y Q C=U
                RR D ;U * * * * * * *  C=*
                RRCA ;Q U TB W E T R Y C=Q
                RRCA ;Y Q U TB W E T R C=Y
                RL D ;* * * * * * * Y  C=U
                RL D ;* * * * * * Y U  C=*
                LD A,9
                OUT (0B5H),A
                IN A,(0B5H)
                     ;* * [ P @ O * I
                     ;* * * * * * Y U
                RRCA ;I * * [ P @ O * C=I
                RL D ;* * * * * Y U I C=*
                RRCA ;* I * * [ P @ O C=*
                RRCA ;O * I * * [ P @ C=O
                RL D ;* * * * Y U I O C=*
                RRCA ;@ O * I * * [ P C=@
                RRCA ;P @ O * I * * [ C=P
                RL D ;* * * Y U I O P C=*
                POP AF
                AND D
                RET
SOR6            PUSH AF
                LD A,1
                OUT (0B5H),A
                IN A,(0B5H)
                     ;CT A S F D G LC H
                     ;* * * * * * * *
                RRCA ;H CT A S F D G LC C=H
                RL D ;* * * * * * * H   C=*
                LD A,6
                OUT (0B5H),A
                IN A,(0B5H)
                     ;* ] : L ; K * J
                     ;* * * * * * * H
                RRCA ;J * ] : L ; K * C=J
                RL D ;* * * * * * H J C=*
                RRCA ;* J * ] : L ; K C=*
                RRCA ;K * J * ] : L ; C=K
                RL D ;* * * * * H J K C=*
                RRCA ;; K * J * ] : L C=;
                RRCA ;L ; K * J * ] : C=L
                RL D ;* * * * H J K L C=*
                LD A,7
                OUT (0B5H),A
                IN A,(0B5H)
                     ;AL EN LF HD UP RG ST
                     ;* * * * H J K L
                RLCA ;EN LF HD UP RG ST AL C=AL
                RLCA ;LF HD UP RG ST AL EN C=EN
                RL D ;* * * H J K L EN C=*
                POP AF
                AND D
                RET
SOR7            PUSH AF
                XOR A
                OUT (0B5H),A
                IN A,(0B5H)
                     ;LS Z X V C B \ N
                     ;* * * * * * * *
                RRCA ;N LS Z X V C B \ C=N
                RR D ;N * * * * * * *  C=*
                RRCA ;\ N LS Z X V C B C=\
                RRCA ;B \ N LS Z X V C C=B
                RL D ;* * * * * * * B  C=N
                RL D ;* * * * * * B N  C=*
                LD A,8
                OUT (0B5H),A
                IN A,(0B5H)
                     ;IN SP RS . / , DL M
                     ;* * * * * * B N
                RRCA ;M IN SP RS . / , DL C=M
                RL D ;* * * * * B N M     C=*
                RRCA ;DL M IN SP RS . / , C=DL
                RRCA ;, DL M IN SP RS . / C=,
                RRCA ;/ , DL M IN SP RS . C=/
                RRCA ;. / , DL M IN SP RS C=.
                RRCA ;RS . / , DL M IN SP C=RS
                RL D ;* * * * B N M SS    C=*
                RRCA ;SP RS . / , DL M IN C=SP
                RL D ;* * * B N M SS SP
                POP AF
                AND D
                RET
HLP             DW 0
AR              DB 0
LINE            DB 255,14H,15,2FH,0,0,0,0
TABL            DB 0,36,121,88,130,182,219,63
SYNC            DB 0F5H,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB 247,8,11,73H,0B8H,0FEH,0E9H,1,0,216,216,0,0,0,0,0
                DB 217,12H,63,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB 253,16,63,0,0,0,0,0,0,0,0,0,0,0,0,0
                DB 252,16,6,63,0,0,0,0,0,0,0,0,0,0,0,0
                DB 255,90H,63,32,0,0,0,0,0,0,0,0,0,0,0,0
                DB 252,12H,6,63,0,0,0,0,0,0,0,0,0,0,0,0
                DB 207,13H,63,0,0,0,0,0,0,0,0,0,0,0,0,0
HOSSZ           EQU $-SYNC
KONV2           PUSH AF
                LD A,B
                CALL KONV
                POP AF
                RET

KONV            LD (CIMK2+1),A
CIMK2           LD A,(1000H)
                LD (HL),A
                RET
KONV4           PUSH AF
IOYGFTY         LD A,(HL)
                INC HL
                LD (CIMK0+1),A
CIMK0           LD A,(1000H)
                LD (DE),A
                INC DE
                DEC BC
                LD A,B
                OR C
                JR NZ,IOYGFTY
                POP AF
                RET
KONV5           PUSH AF
IOGFT           LD A,(HL)
                DEC HL
                LD (CIMK7+1),A
CIMK7           LD A,(1000H)
                LD (DE),A
                DEC DE
                DEC BC
                LD A,B
                OR C
                JR NZ,IOGFT
                POP AF
                RET

KONVERTAL       PUSH HL
                PUSH BC
                LD   HL,5800H
                LD   BC,300H
L7952           LD   A,(HL)
                LD   (CIMK+1),A
CIMK            LD   A,(1000H)
                LD   (HL),A
                DEC BC
                INC  HL
                LD   A,B
                OR C
                JR   NZ,L7952
                POP BC
                POP HL
                RET
CIMKE
        DB   0,4,2,3,4,5,6,7,16,17,18,19,20,21,22,23
        DB   32,36,34,35,36,37,38,39,48,49,50,51,52,53,54,55
        DB   "@ABCDEFGPQRSTUVW"
        DB   "`abcdefgpqrstuvw"
        DB   "",0,12,9,13,10,14,11,15,200,204,201,205,202,206,203,207
        DB   152,156,153,157,154,158,155,159,216,220,217,221,218,222,219,223
        DB   168,172,169,173,170,174,171,175,232,236,233,237,234,238,235,239
        DB   184,188,185,189,186,190,187,191,248,252,249,253,250,254,251,255
        DB   0,1,2,3,4,5,6,7,16,17,18,19,20,21,22,23
        DB   32,33,34,35,36,37,38,39,48,49,50,51,52,53,54,55
        DB   "@ABCDEFGPQRSTUVW"
        DB   "`abcdefgpqrstuvw"
        DB   "",0,12,9,13,10,14,11,15,200,204,201,205,202,206,203,207
        DB   152,156,153,157,154,158,155,159,216,220,217,221,218,222,219,223
        DB   168,172,169,173,170,174,171,175,232,236,233,237,234,238,235,239
        DB   184,188,185,189,186,190,187,191,248,252,249,253,250,254,251,255
NEV             DB 12,"HIGHWAY2.PRG"
SCR             LD HL,623
SCR3            LD A,H
                OR A
                JR NZ,SCR2
                LD A,L
                CP 32
                JR NC,SCR2
                LD B,3
                JR VARAK
SCR2            LD B,1
VARAK           HALT
                DJNZ VARAK
                PUSH HL
                CALL SCHAR
                POP HL
                DEC HL
                LD A,H
                OR L
                JR NZ,SCR3
                RET
SCHAR           XOR A
                EXOS 5
                JP NZ,HIBA
                LD A,B
                EX AF,AF'
                XOR A
                EXOS 5
                JP NZ,HIBA
                LD H,B
                EX AF,AF'
                LD L,A
                LD B,8
FF42            PUSH BC
                XOR A
                EXOS 5
                JP  NZ,HIBA
                LD A,B
                POP BC
                LD (HL),A
                INC H
                DJNZ FF42
                LD A,H
                SUB 8
                RRA
                RRA
                RRA
                AND 3
                OR 58H
                LD H,A
                XOR A
                EXOS 5
                JP NZ,HIBA
                CALL KONV2
                RET

 ;HL=honnan DE=hova B=0
UPCK:     LD A,(HL)
          INC HL
          OR A
          RET Z
          JP M,UPCK10
          CP 2
          LD C,A
          CALL Z,UPCKRUT
          LDI
          PUSH HL
          LD H,D
          LD L,E
          DEC HL
          LDIR
          POP HL
          JR UPCK
UPCK10:   SUB 128
          LD C,A
          CALL Z,UPCKRUT
          LDIR
          JR UPCK
UPCKRUT:  LD C,(HL)
          INC HL
          LD B,(HL)
          INC HL
          RET

F9H             DB 0
FAH             DB 0
FBH             DB 0
FDH             DB 0
FCH             DB 0
VIDCIM1         DW 0
VIDCIM2         DW 0
KS              DB 0
LPT2            DB 0
STACK           EQU $+200H
                END

