
; ripped from: SFONT

shadow_state1   db      ?
shadow_state2   db      ?
shadow_state3   db      ?

sh1_init_c:
                mov     cl, 0CDh
                call    sh1_read
                mov     shadow_state2, al
                test    al, 0C0h
                jz      loc_0_449B
                test    al, 30h
                setnz   al
                retn
loc_0_449B:
                xor     al, al
                retn
sh1_open_c:
                mov     cl, 0CDh
                mov     al, shadow_state2
                or      al, 0F0h
                call    sh1_write
                retn
sh1_close_c:
                mov     cl, 0CDh
                mov     al, shadow_state2
                call    sh1_write
                retn
sh2_init_c:
                mov     cl, 9Dh
                call    sh2_read
                mov     shadow_state1, al
                and     al, 3
                cmp     al, 3
                setz    al
                retn
sh2_open_c:
                mov     cl, 9Eh
                call    sh2_read
                mov     shadow_state2, al
                and     al, 0FCh
                mov     cl, 9Eh
                call    sh2_write
                retn
sh2_close_c:
                mov     cl, 9Eh
                mov     al, shadow_state2
                call    sh2_write
                retn
sh3_init_c:
                mov     cl, 26h
                call    sh2_read
                mov     shadow_state2, al
                and     al, 3
                cmp     al, 3
                setz    al
                retn
sh3_open_c:
                mov     cl, 27h
                call    sh2_read
                mov     shadow_state1, al
                or      al, 10h
                mov     cl, 27h
                call    sh2_write
                mov     al, shadow_state2
                and     al, 0DFh
                or      al, 40h
                mov     cl, 26h
                call    sh2_write
                retn
sh3_close_c:
                mov     al, shadow_state2
                mov     cl, 26h
                call    sh2_write
                mov     al, shadow_state1
                mov     cl, 27h
                call    sh2_write
                retn
sh4_init_c:
                mov     cl, 15h
                call    sh2_read
                mov     shadow_state2, al
                and     al, 3
                cmp     al, 3
                setz    al
                retn
sh4_open_c:
                mov     al, shadow_state2
                and     al, 0DFh
                or      al, 40h
                mov     cl, 15h
                call    sh2_write
                retn
sh4_close_c:
                mov     al, shadow_state2
                mov     cl, 15h
                call    sh2_write
                retn
sh5_init_c:
                mov     cl, 83h
                call    sh5_read
                mov     shadow_state2, al
                and     al, 0C0h
                cmp     al, 0C0h
                setz    al
                retn
sh5_open_c:
                mov     al, shadow_state2
                and     al, 0F3h
                mov     cl, 83h
                call    sh5_write
                retn
sh5_close_c:
                mov     al, shadow_state2
                mov     cl, 83h
                call    sh5_write
                retn
sh6_init_c:
                mov     cl, 13h
                mov     al, 0C5h
                call    sh5_write
                mov     cl, 14h
                call    sh5_read
                mov     shadow_state2, al
                mov     cl, 13h
                xor     al, al
                call    sh5_write
                mov     al, shadow_state2
                and     al, 1
                retn
sh6_open_c:
                mov     cl, 13h
                mov     al, 0C5h
                call    sh5_write
                mov     cl, 14h
                mov     al, 2
                call    sh5_write
                mov     cl, 13h
                xor     al, al
                call    sh5_write
                retn
sh6_close_c:
                mov     cl, 13h
                mov     al, 0C5h
                call    sh5_write
                mov     cl, 14h
                mov     al, shadow_state2
                call    sh5_write
                mov     cl, 13h
                xor     al, al
                call    sh5_write
                retn
sh7_init_cf:
                mov     cl, 52h
                call    sh5_read
                mov     shadow_state2, al
                and     al, 1
                retn
sh7_open_cf:
                mov     al, shadow_state2
                and     al, 0BFh
                mov     cl, 52h
                call    sh5_write
                retn
sh7_close_cf:
                mov     al, shadow_state2
                mov     cl, 52h
                call    sh5_write
                retn
sh8_init_c:
                mov     cl, 22h
                call    sh5_read
                mov     shadow_state2, al
                and     al, 0Ah
                cmp     al, 0Ah
                setz    al
                retn
sh8_open_c:
                mov     al, shadow_state2
                and     al, 0FAh
                mov     cl, 22h
                call    sh5_write
                retn
sh8_close_c:
                mov     al, shadow_state2
                mov     cl, 22h
                call    sh5_write
                retn
sh9_init_c:
                mov     cl, 0Bh
                call    sh5_read
                mov     shadow_state1, al
                and     al, 1
                retn
sh9_open_c:
                mov     cl, 9
                call    sh5_read
                mov     shadow_state2, al
                or      al, 30h
                call    sh5_write
                retn
sh9_close_c:
                mov     al, shadow_state2
                mov     cl, 9
                call    sh5_write
                retn
sh10_init_c:
                mov     cl, 62h
                call    sh10_read
                mov     shadow_state2, al
                and     al, 1
                retn
sh10_open_c:
                mov     al, shadow_state2
                and     al, 0BFh
                or      al, 81h
                mov     cl, 62h
                call    sh10_write
                retn
sh10_close_c:
                mov     al, shadow_state2
                mov     cl, 62h
                call    sh10_write
                retn
sh11_init_c:
                mov     cl, 31h
                call    sh11_read
                mov     shadow_state1, al
                test    al, 0C0h
                jz      loc_0_4643
                test    al, 30h
                setnz   al
                retn
loc_0_4643:
                xor     al, al
                retn
sh11_open_c:
                mov     cl, 33h
                call    sh11_read
                mov     shadow_state2, al
                and     al, 3Fh
                call    sh11_write
                retn
sh11_close_c:
                mov     al, shadow_state2
                mov     cl, 33h
                call    sh11_write
                retn
sh12_init_c:
                mov     cl, 1Ah
                call    sh12_read
                mov     shadow_state2, al
                test    al, 3
                setnz   al
                retn
sh12_open_c:
                mov     cl, 1Ah
                mov     al, shadow_state2
                and     al, 0FCh
                or      al, 2
                call    sh12_write
                retn
sh12_close_c:
                mov     al, shadow_state2
                mov     cl, 1Ah
                call    sh12_write
                retn
sh13_init_c:
                mov     dx, 0FCA4h
                in      al, dx
                mov     shadow_state1, al
                jmp     short $+2
                jmp     short $+2
                and     al, 1
                retn
sh13_open_c:
                mov     dx, 0FCA0h
                in      al, dx
                jmp     short $+2
                jmp     short $+2
                mov     shadow_state2, al
                and     al, 0CFh
                or      al, 20h
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                retn
sh13_close_c:
                mov     al, shadow_state2
                mov     dx, 0FCA0h
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                retn
sh14_init_c:
                mov     cl, 13h
                call    sh5_read
                mov     shadow_state1, al
                and     al, 1
                retn
sh14_open_c:
                mov     cl, 14h
                call    sh5_read
                mov     shadow_state2, al
                and     al, 0FCh
                or      al, 2
                call    sh5_write
                retn
sh14_close_c:
                mov     al, shadow_state2
                mov     cl, 14h
                call    sh5_write
                retn
sh15_init_c:
                mov     cx, 0C05Ah
                call    sh15_read
                mov     shadow_state2, al
                and     al, 11h
                cmp     al, 11h
                setz    al
                retn
sh15_open_c:
                mov     cx, 0C05Ah
                mov     al, shadow_state2
                or      al, 22h
                call    sh15_write
                retn
sh15_close_c:
                mov     cx, 0C05Ah
                mov     al, shadow_state2
                call    sh15_write
                retn
sh16_init_c:
                mov     cl, 22h
                call    sh5_read
                mov     shadow_state2, al
                and     al, 3
                cmp     al, 3
                setz    al
                retn
sh16_open_c:
                mov     al, shadow_state2
                and     al, 0EFh
                mov     cl, 22h
                call    sh5_write
                retn
sh16_close_c:
                mov     al, shadow_state2
                mov     cl, 22h
                call    sh5_write
                retn
sh17_init_c:
                mov     cx, 56h
                call    sh17_read
                mov     shadow_state1, al
                and     al, 0C0h
                cmp     al, 0C0h
                setz    al
                retn
sh17_open_c:
                mov     cx, 53h
                call    sh17_read
                mov     shadow_state2, al
                and     al, 9Fh
                or      al, 40h
                mov     cl, 53h
                call    sh17_write
                retn
sh17_close_c:
                mov     al, shadow_state2
                mov     cl, 53h
                call    sh17_write
                retn
sh18_init_c:
                mov     cl, 3Ah
                call    sh5_read
                mov     shadow_state2, al
                and     al, 1
                retn
sh18_open_c:
                mov     al, shadow_state2
                or      al, 40h
                mov     cl, 3Ah
                call    sh5_write
                retn
sh18_close_c:
                mov     al, shadow_state2
                mov     cl, 3Ah
                call    sh5_write
                retn
sh19_init_c:
                mov     cl, 2Eh
                call    sh25_read
                mov     shadow_state2, al
                test    al, 0Ch
                jz      loc_0_477D
                test    al, 3
                setnz   al
                retn
loc_0_477D:
                xor     al, al
                retn
sh19_open_c:
                mov     al, shadow_state2
                and     al, 0F0h
                or      al, 5
                mov     cl, 2Eh
                call    sh25_write
                retn
sh19_close_c:
                mov     al, shadow_state2
                mov     cl, 2Eh
                call    sh25_write
                retn
sh20_init_cf:
                mov     cx, 8054h
                call    sh17_read
                test    al, 2
                setnz   al
                retn
sh20_open_cf:
                mov     cx, 8055h
                call    sh17_read
                mov     shadow_state1, al
                and     al, 0BFh
                mov     cx, 8055h
                call    sh17_write
                retn
sh20_close_cf:
                mov     al, shadow_state1
                mov     cx, 8055h
                call    sh17_write
                retn

sh21_init_c:    mov     cx, 0C05Ah
                call    sh21_read
                mov     shadow_state2, al
                and     al, 11h
                cmp     al, 11h
                setz    al
                retn

sh21_open_c:    mov     cx, 0C05Ah
                mov     al, shadow_state2
                or      al, 22h
                call    sh21_write
                retn

sh21_close_c:   mov     cx, 0C05Ah
                mov     al, shadow_state2
                call    sh21_write
                retn

sh22_init_c:
                mov     cl, 4
                call    sh2_read
                mov     shadow_state2, al
                test    al, 3
                jz      loc_0_47F7
                test    al, 0Ch
                setnz   al
                retn
loc_0_47F7:
                xor     al, al
                retn
sh22_open_c:
                mov     al, shadow_state2
                and     al, 0F0h
                or      al, 0Ah
                mov     cl, 4
                call    sh2_write
                retn
sh22_close_c:
                mov     al, shadow_state2
                mov     cl, 4
                call    sh2_write
                retn
sh23_init_c:
                mov     cl, 0Fh
                call    sh23_read
                mov     shadow_state2, al
                test    al, 3
                jz      loc_0_4822
                test    al, 0Ch
                setnz   al
                retn
loc_0_4822:
                xor     al, al
                retn
sh23_open_c:
                mov     al, shadow_state2
                or      al, 5
                mov     cl, 0Fh
                call    sh24_write
                retn
sh23_close_c:
                mov     al, shadow_state2
                mov     cl, 0Fh
                call    sh24_write
                retn
sh24_init_c:
                mov     cl, 18h
                call    sh12_read
                mov     shadow_state2, al
                test    al, 3
                setnz   al
                retn
sh24_open_c:
                mov     cl, 18h
                mov     al, shadow_state2
                and     al, 0FCh
                or      al, 2
                call    sh12_write
                retn
sh24_close_c:
                mov     al, shadow_state2
                mov     cl, 18h
                call    sh12_write
                retn
sh25_init_c:
                mov     cl, 40h
                call    sh25_read
                mov     shadow_state1, al
                mov     cl, 30h
                call    sh25_read
                mov     shadow_state2, al
                test    al, 0Ch
                jz      loc_0_4877
                test    al, 3
                setnz   al
                retn
loc_0_4877:
                xor     al, al
                retn
sh25_open_c:
                mov     al, shadow_state1
                and     al, 7Fh
                mov     cl, 40h
                call    sh25_write
                mov     al, shadow_state2
                and     al, 0F0h
                or      al, 5
                mov     cl, 30h
                call    sh25_write
                retn
sh25_close_c:
                mov     al, shadow_state1
                mov     cl, 40h
                call    sh25_write
                mov     al, shadow_state2
                mov     cl, 30h
                call    sh25_write
                retn
sh26_init_c:
                mov     cl, 18h
                call    sh25_read
                mov     shadow_state2, al
                test    al, 0Ch
                jz      loc_0_48B4
                test    al, 3
                setnz   al
                retn
loc_0_48B4:
                xor     al, al
                retn
sh26_open_c:
                mov     al, shadow_state2
                and     al, 0F0h
                or      al, 5
                mov     cl, 18h
                call    sh25_write
                retn
sh26_close_c:
                mov     al, shadow_state2
                mov     cl, 18h
                call    sh25_write
                retn
sh27_init_cf:
                mov     cx, 2844h
                call    sh17_read
                mov     shadow_state1, al
                and     al, 1
                retn
sh27_open_cf:
                mov     cx, 2845h
                call    sh17_read
                mov     shadow_state2, al
                and     al, 0FEh
                mov     cx, 2845h
                call    sh17_write
                retn
sh27_close_cf:
                mov     al, shadow_state2
                mov     cx, 2845h
                call    sh17_write
                retn
sh28_init_c:
                mov     al, 3
                mov     cl, 0A6h
                call    sh28_write
                mov     al, 4
                mov     cl, 0A7h
                call    sh28_write
                xor     al, al
                mov     cl, 0AAh
                call    sh28_write
                mov     cl, 0A4h
                call    sh28_read
                and     al, 1
                retn
sh28_open_c:
                mov     cl, 0A4h
                call    sh28_read
                mov     shadow_state2, al
                and     al, 40h
                mov     cl, 0A4h
                call    sh28_write
                mov     ah, 38h
                or      ah, 4
                mov     cl, 0ABh
                call    sh28_write
                retn
sh28_close_c:
                mov     cl, 0ABh
                xor     al, al
                call    sh28_write
                mov     cl, 0A4h
                mov     al, shadow_state2
                call    sh28_write
                retn
sh29_init_c:
                mov     cl, 0Eh
                call    sh5_read
                mov     shadow_state1, al
                and     al, 3
                setz    al
                retn
sh29_open_c:
                mov     cl, 9
                call    sh5_read
                mov     shadow_state2, al
                and     al, 7Fh
                mov     cl, 9
                call    sh5_write
                retn
sh29_close_c:
                mov     al, shadow_state2
                mov     cl, 9
                call    sh5_write
                retn
sh30_init_c:
                mov     cl, 19h
                call    sh5_read
                mov     shadow_state2, al
                and     al, 3
                cmp     al, 3
                setz    al
                retn
sh30_open_c:
                mov     al, shadow_state2
                and     al, 0FCh
                mov     cl, 19h
                call    sh5_write
                mov     cl, 1Ah
                call    sh5_read
                mov     shadow_state1, al
                or      al, 3
                mov     cl, 1Ah
                call    sh5_write
                retn
sh30_close_c:
                mov     al, shadow_state2
                mov     cl, 19h
                call    sh5_write
                mov     al, shadow_state1
                mov     cl, 1Ah
                call    sh5_write
                retn
sh31_init_c:
                mov     cx, 5Ah
                call    sh31_read
                mov     shadow_state2, al
                and     al, 11h
                cmp     al, 11h
                setz    al
                retn
sh31_open_c:
                mov     cx, 5Ah
                mov     al, shadow_state2
                or      al, 22h
                call    sh31_write
                retn
sh31_close_c:
                mov     cx, 5Ah
                mov     al, shadow_state2
                call    sh31_write
                retn
sh32_init_c:
                mov     cl, 13h
                call    sh2_read
                mov     shadow_state2, al
                and     al, 3
                cmp     al, 3
                setz    al
                retn
sh32_open_c:
                mov     cl, 11h
                call    sh2_read
                mov     shadow_state1, al
                and     al, 0FEh
                mov     cl, 11h
                call    sh2_write
                retn
sh32_close_c:
                mov     al, shadow_state1
                mov     cl, 11h
                call    sh2_write
                retn
sh33_init_c:
                mov     cl, 33h
                call    sh33_read
                mov     shadow_state2, al
                and     al, 0C0h
                cmp     al, 0C0h
                setz    al
                retn
sh33_open_c:
                mov     al, shadow_state2
                and     al, 3Fh
                mov     cl, 33h
                call    sh33_write
                retn
sh33_close_c:
                mov     al, shadow_state2
                mov     cl, 33h
                call    sh33_write
                retn
sh34_init_c:
                mov     cl, 62h
                call    sh5_read
                mov     shadow_state2, al
                and     al, 1
                retn
sh34_open_c:
                mov     al, shadow_state2
                and     al, 3Fh
                mov     cl, 62h
                call    sh5_write
                retn
sh34_close_c:
                mov     al, shadow_state2
                mov     cl, 62h
                call    sh5_write
                retn
sh35_init_c:
                mov     cx, 80h
                call    sh17_read
                mov     shadow_state2, al
                and     al, 88h
                cmp     al, 88h
                setz    al
                retn
sh35_open_c:
                mov     cx, 80h
                mov     al, shadow_state2
                or      al, 22h
                call    sh17_write
                retn
sh35_close_c:
                mov     al, shadow_state2
                mov     cx, 80h
                call    sh17_write
                retn
sh36_init_e:
                mov     cl, 15h
                call    sh5_read
                mov     shadow_state2, al
                test    al, 20h
                setnz   al
                retn
sh36_open_e:
                mov     cl, 15h
                mov     al, shadow_state2
                and     al, 0EFh
                call    sh5_write
                retn
sh36_close_e:
                mov     al, shadow_state2
                mov     cl, 15h
                call    sh5_write
                retn
sh37_init_c:
                mov     cl, 74h
                call    sh2_read
                mov     shadow_state2, al
                mov     cl, 72h
                call    sh2_read
                mov     shadow_state1, al
                and     al, 1
                retn
sh37_open_c:
                mov     cl, 74h
                call    sh2_read
                mov     shadow_state1, al
                or      al, 30h
                mov     cl, 74h
                call    sh2_write
                mov     cl, 72h
                call    sh2_read
                mov     shadow_state1, al
                and     al, 80h
                or      al, 10h
                mov     cl, 72h
                call    sh2_write
                retn
sh37_close_c:
                mov     al, shadow_state2
                mov     cl, 74h
                call    sh2_write
                mov     al, shadow_state1
                mov     cl, 72h
                call    sh2_write
                retn
sh38_open_e_real:
                push    ax
                push    dx
                cli
loc_0_4AC2:
                mov     ax, 8000h
                out     23h, al
                xchg    al, ah
                out     22h, al
                out     22h, ax
                in      ax, 22h
                test    ax, 1
                jz      loc_0_4AC2
                in      ax, 22h
                and     ax, 0FFE3h
                or      ax, 2
                out     22h, ax
                mov     dx, 700h
                in      ax, dx
                xor     ah, 3Fh
                in      ax, 22h
                and     ax, 0FFE3h
                or      ax, 0Ah
                out     22h, ax
                mov     ax, 0FFFFh
                mov     dx, 308h
                call    sh38_open_e_real_sub1
                pop     dx
                pop     ax
                retn
sh38_close_e_real:
                push    ax
                push    dx
                in      ax, 22h
                and     ax, 0FFFDh
                out     22h, ax
                or      ax, 100h
                out     22h, ax
                pop     dx
                pop     ax
                sti
                retn
sh38_open_e_real_sub1:
                pushf
                out     dx, ax
                inc     dx
                inc     dx
                out     dx, ax
                popf
                retn
sh38_init_e:
                mov     al, 1
                retn
sh38_open_e:
                call    sh38_open_e_real
                retn
sh38_close_e:
                call    sh38_close_e_real
                retn
sh39_init_c:
                mov     cl, 4
                call    sh2_read
                mov     shadow_state2, al
                test    al, 3
                setnz   al
                retn
sh39_open_c:
                mov     al, shadow_state2
                and     al, 0FCh
                or      al, 3
                mov     cl, 4
                call    sh2_write
                retn
sh39_close_c:
                mov     al, shadow_state2
                mov     cl, 4
                call    sh2_write
                retn
sh40_init_c:
                mov     cl, 3
                mov     al, 0C5h
                call    sh5_write
                mov     cl, 13h
                call    sh5_read
                mov     shadow_state1, al
                mov     cl, 3
                mov     al, 0
                call    sh5_write
                mov     al, shadow_state1
                and     al, 1
                retn
sh40_open_c:
                mov     cl, 3
                mov     al, 0C5h
                call    sh5_write
                mov     cl, 14h
                call    sh5_read
                mov     shadow_state2, al
                and     al, 0FCh
                mov     cl, 14h
                or      al, 3
                call    sh5_write
                mov     cl, 3
                mov     al, 0
                call    sh5_write
                retn
sh40_close_c:
                mov     cl, 3
                mov     al, 0C5h
                call    sh5_write
                mov     al, shadow_state2
                mov     cl, 14h
                call    sh5_write
                mov     cl, 3
                mov     al, 0
                call    sh5_write
                retn
sh41_init_c:
                mov     cl, 13h
                call    sh41_read
                mov     shadow_state2, al
                and     al, 3
                cmp     al, 3
                setz    al
                retn
sh41_open_c:
                mov     cl, 14h
                call    sh41_read
                mov     shadow_state1, al
                or      al, 20h
                mov     cl, 14h
                call    sh41_write
                retn
sh41_close_c:
                mov     al, shadow_state1
                mov     cl, 14h
                call    sh41_write
                retn
sh42_init_e:
                mov     cl, 13h
                mov     al, 0C5h
                call    sh5_write
                mov     cl, 15h
                call    sh5_read
                mov     shadow_state2, al
                mov     cl, 13h
                mov     al, 0
                call    sh5_write
                mov     al, shadow_state2
                and     al, 5
                cmp     al, 5
                setz    al
                retn
sh42_open_e:
                mov     cl, 13h
                mov     al, 0C5h
                call    sh5_write
                mov     cl, 15h
                call    sh5_read
                and     al, 0F0h
                or      al, 0Ah
                mov     cl, 15h
                call    sh5_write
                mov     cl, 13h
                mov     al, 0
                call    sh5_write
                retn
sh42_close_e:
                mov     cl, 13h
                mov     al, 0C5h
                call    sh5_write
                mov     al, shadow_state2
                mov     cl, 15h
                call    sh5_write
                mov     cl, 13h
                mov     al, 0
                call    sh5_write
                retn
sh43_init_e:
                mov     cl, 36h
                call    sh2_read
                mov     shadow_state1, al
                mov     cl, 32h
                call    sh2_read
                mov     shadow_state2, al
                mov     cl, 33h
                call    sh2_read
                mov     shadow_state3, al
                mov     al, 1
                retn
sh43_open_e:
                mov     cl, 36h
                call    sh2_read
                or      al, 40h
                call    sh2_write
                mov     cl, 32h
                call    sh2_read
                or      al, 28h
                and     al, 0F7h
                call    sh2_write
                mov     cl, 33h
                call    sh2_read
                or      al, 0F0h
                call    sh2_write
                retn
sh43_close_e:
                mov     cl, 33h
                mov     al, shadow_state3
                call    sh2_write
                mov     cl, 36h
                mov     al, shadow_state1
                call    sh2_write
                mov     cl, 32h
                mov     al, shadow_state2
                call    sh2_write
                retn
sh44_init_e:
                mov     cl, 2
                call    sh44_read
                mov     shadow_state2, al
                mov     al, 1
                retn
sh44_open_e:
                mov     cl, 2
                call    sh44_read
                or      al, 8
                mov     cl, 2
                call    sh44_write
                retn
sh44_close_e:
                mov     cl, 2
                mov     al, shadow_state2
                call    sh44_write
                retn
sh45_init_c:
                mov     cx, 61h
                call    sh17_read
                mov     shadow_state2, al
                and     al, 0Ah
                cmp     al, 0Ah
                setz    al
                retn
sh45_open_c:
                mov     cx, 61h
                mov     al, shadow_state2
                or      al, 0Fh
                call    sh17_write
                retn
sh45_close_c:
                mov     cx, 61h
                mov     al, shadow_state2
                call    sh17_write
                retn
sh46_init_c:
                mov     cl, 13h
                call    sh5_read
                mov     shadow_state2, al
                and     al, 3
                cmp     al, 3
                setz    al
                retn
sh46_open_c:
                mov     cl, 12h
                call    sh5_read
                mov     shadow_state1, al
                and     al, 0FEh
                mov     cl, 12h
                call    sh5_write
                retn
sh46_close_c:
                mov     al, shadow_state1
                mov     cl, 12h
                call    sh5_write
                retn
sh47_init_e:
                mov     cl, 11h
                call    sh47_read
                mov     shadow_state2, al
                and     al, 0AAh
                cmp     al, 0AAh
                setz    al
                retn
sh47_open_e:
                mov     cl, 11h
                mov     al, 0FFh
                call    sh47_write
                mov     cl, 11h
                call    sh47_read
                mov     shadow_state1, al
                retn
sh47_close_e:
                mov     cl, 11h
                mov     al, shadow_state2
                call    sh47_write
                retn
sh48_init_c:
                mov     cx, 70h
                call    sh17_read
                mov     shadow_state2, al
                and     al, 88h
                cmp     al, 88h
                setz    al
                retn
sh48_open_c:
                mov     cx, 70h
                mov     al, shadow_state2
                or      al, 22h
                call    sh17_write
                retn
sh48_close_c:
                mov     al, shadow_state2
                mov     cx, 70h
                call    sh17_write
                retn
sh28_read:
                mov     al, cl
                out     24h, al
                jmp     short $+2
                jmp     short $+2
                in      al, 25h
                jmp     short $+2
                jmp     short $+2
                retn
sh28_write:
                push    ax
                mov     al, cl
                out     24h, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                out     25h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh2_read:
                mov     al, cl
                out     22h, al
                jmp     short $+2
                jmp     short $+2
                in      al, 24h
                jmp     short $+2
                jmp     short $+2
                retn
sh2_write:
                push    ax
                mov     al, cl
                out     22h, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                out     24h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh5_read:
                mov     al, cl
                out     22h, al
                jmp     short $+2
                jmp     short $+2
                in      al, 23h
                jmp     short $+2
                jmp     short $+2
                retn
sh5_write:
                push    ax
                mov     al, cl
                out     22h, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                out     23h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh41_read:
                mov     al, 3
                out     22h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, 0C5h
                out     23h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, cl
                out     22h, al
                jmp     short $+2
                jmp     short $+2
                in      al, 23h
                jmp     short $+2
                jmp     short $+2
                retn
sh41_write:
                push    ax
                mov     al, 3
                out     22h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, 0C5h
                out     23h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, cl
                out     22h, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                out     23h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh12_read:
                mov     al, cl
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                in      al, 29h
                jmp     short $+2
                jmp     short $+2
                retn
sh12_write:
                push    ax
                mov     al, cl
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                out     29h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh33_read:
                mov     al, cl
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                in      al, 2Ah
                jmp     short $+2
                jmp     short $+2
                retn
sh33_write:
                push    ax
                mov     al, cl
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                out     2Ah, al
                jmp     short $+2
                jmp     short $+2
                retn
sh25_read:
                mov     al, cl
                out     0A8h, al
                jmp     short $+2
                jmp     short $+2
                in      al, 0A9h
                jmp     short $+2
                jmp     short $+2
                retn
sh25_write:
                push    ax
                mov     al, cl
                out     0A8h, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                out     0A9h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh10_read:
                push    dx
                mov     dx, 0C18h
                mov     al, cl
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                mov     dx, 0C1Ch
                in      al, dx
                pop     dx
                retn
sh10_write:
                push    dx
                push    ax
                mov     dx, 0C18h
                mov     al, cl
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                mov     dx, 0C1Ch
                out     dx, al
                pop     dx
                retn
sh23_read:
                mov     al, cl
                out     0FBh, al
                jmp     short $+2
                jmp     short $+2
                out     0ECh, al
                jmp     short $+2
                jmp     short $+2
                in      al, 0EDh
                jmp     short $+2
                jmp     short $+2
                out     0F9h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh24_write:
                out     0FBh, al
                jmp     short $+2
                jmp     short $+2
                out     0ECh, al
                push    ax
                mov     al, cl
                jmp     short $+2
                jmp     short $+2
                out     0EDh, al
                pop     ax
                jmp     short $+2
                jmp     short $+2
                out     0F9h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh47_read:
                mov     al, 1Ah
                out     0FBh, al
                jmp     short $+2
                jmp     short $+2
                mov     al, cl
                out     0ECh, al
                jmp     short $+2
                jmp     short $+2
                in      al, 0EDh
                jmp     short $+2
                jmp     short $+2
                out     0F9h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh47_write:
                push    ax
                mov     al, 1Ah
                out     0FBh, al
                jmp     short $+2
                jmp     short $+2
                mov     al, cl
                out     0ECh, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                out     0EDh, al
                jmp     short $+2
                jmp     short $+2
                out     0F9h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh44_read:
                mov     al, cl
                out     0F2h, al
                jmp     short $+2
                jmp     short $+2
                in      al, 0F3h
                jmp     short $+2
                jmp     short $+2
                retn
sh44_write:
                push    ax
                mov     al, cl
                out     0F2h, al
                jmp     short $+2
                jmp     short $+2
                pop     ax
                out     0F3h, al
                jmp     short $+2
                jmp     short $+2
                retn
sh1_read:
                push    dx
                mov     dx, 8022h
                mov     al, 0A0h
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                mov     al, 5
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                mov     al, cl
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                inc     dx
                inc     dx
                in      al, dx
                jmp     short $+2
                jmp     short $+2
                dec     dx
                dec     dx
                mov     ah, al
                xor     al, al
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                mov     al, ah
                pop     dx
                retn
sh1_write:
                push    dx
                mov     dx, 8022h
                mov     ah, al
                mov     al, 0A0h
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                mov     al, 5
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                mov     al, ah
                xchg    cl, al
                out     dx, al
                xchg    cl, al
                inc     dx
                inc     dx
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                dec     dx
                dec     dx
                mov     ah, al
                xor     al, al
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                mov     al, ah
                pop     dx
                retn
sh11_read:
                mov     al, 0A0h
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, 5
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, cl
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                in      al, 2Ah
                jmp     short $+2
                jmp     short $+2
                mov     ah, al
                mov     al, 0A5h
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, ah
                retn
sh11_write:
                mov     ah, al
                mov     al, 0A0h
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, 5
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, ah
                xchg    cl, al
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                xchg    cl, al
                out     2Ah, al
                jmp     short $+2
                jmp     short $+2
                mov     ah, al
                mov     al, 0A5h
                out     28h, al
                jmp     short $+2
                jmp     short $+2
                mov     al, ah
                retn
sh21_write:
                xchg    ch, al
                mov     eax, 80002800h
                mov     al, cl
                and     al, 0FCh
                mov     dx, 0CF8h
                out     dx, eax
                add     dl, 4
                mov     al, cl
                and     al, 3
                add     dl, al
                xchg    ch, al
                out     dx, al
                and     eax, 0FFFFh
                mov     dx, 0CF8h
                out     dx, eax
                retn
sh21_read:
                mov     eax, 80002800h
                mov     al, cl
                and     al, 0FCh
                mov     dx, 0CF8h
                out     dx, eax
                add     dl, 4
                mov     ch, cl
                and     ch, 3
                add     dl, ch
                in      al, dx
                and     eax, 0FFFFh
                mov     dx, 0CF8h
                out     dx, eax
                retn
sh15_read:
                mov     dx, 0CF8h
                xchg    ah, al
                mov     al, 10h
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                xchg    ah, al
                xchg    dx, cx
                in      al, dx
                jmp     short $+2
                jmp     short $+2
                xchg    dx, cx
                mov     dx, 0CF8h
                xchg    ah, al
                xor     al, al
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                xchg    ah, al
                retn
sh15_write:
                mov     dx, 0CF8h
                xchg    ah, al
                mov     al, 10h
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                xchg    ah, al
                xchg    dx, cx
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                xchg    dx, cx
                mov     dx, 0CF8h
                xchg    ah, al
                xor     al, al
                out     dx, al
                jmp     short $+2
                jmp     short $+2
                xchg    ah, al
                retn
sh31_read:
                mov     eax, 80000000h
                mov     ax, cx
                and     al, 0FCh
                mov     dx, 0CF8h
                out     dx, eax
                add     dl, 4
                mov     al, cl
                and     al, 3
                add     dl, al
                in      al, dx
                retn
sh31_write:
                xchg    ax, cx
                and     eax, 8000FFFFh
                or      eax, 80000000h
                mov     ch, al
                and     al, 0FCh
                mov     dx, 0CF8h
                out     dx, eax
                mov     al, ch
                add     dl, 4
                and     ch, 3
                add     dl, ch
                xchg    ax, cx
                out     dx, al
                retn
sh17_read:
                push    dx
                mov     eax, 80000000h
                mov     ax, cx
                and     al, 0FCh
                mov     dx, 0CF8h
                out     dx, eax
                add     dl, 4
                mov     al, cl
                and     al, 3
                add     dl, al
                in      al, dx
                pop     dx
                retn
sh17_write:
                push    dx
                xchg    ax, cx
                shl     ecx, 10h
                xchg    ax, cx
                mov     eax, 80000000h
                mov     ax, cx
                and     al, 0FCh
                mov     dx, 0CF8h
                out     dx, eax
                add     dl, 4
                mov     al, cl
                and     al, 3
                add     dl, al
                shr     ecx, 10h
                mov     ax, cx
                out     dx, al
                pop     dx
                retn
