
; ripped from: CONSFUCK

sh1_init_f:     mov     al, 1
                ret

sh1_open_f:     mov     cl,0cch
                call    sh1_read
                mov     shadow_state1, al
                mov     al,0c8h
                mov     cl,0cch
                call    sh1_write
                ret

sh1_close_f:    mov     cl, 0CCh
                mov     al, shadow_state1
                call    sh1_write
                retn

sh3_init_f:     mov     al, 1
                retn

sh3_open_f:     mov     cl,022h
                call    sh2_read
                mov     shadow_state1,al
                or      al,080h
                mov     cl,022h
                call    sh2_write
                retn

sh3_close_f:    mov     al,shadow_state1
                mov     cl,022h
                call    sh2_write
                ret

sh4_init_f:     mov     al, 1
                ret

sh4_open_f:     mov     cl,011h
                call    sh2_read
                mov     shadow_state1,al
                or      al,080h
                mov     cl,011h
                call    sh2_write
                retn

sh4_close_f:    mov     al,shadow_state1
                mov     cl,011h
                call    sh2_write
                retn



sh14_init_f:
                mov     cl,13h
                call    sh5_read
                mov     shadow_state1,al
                and     al,1
                ret

sh14_open_f:    mov     cl,14h
                call    sh5_read
                mov     shadow_state2,al
                and     al,0fch
                or      al,2
                call    sh5_write
                ret

sh14_close_f:   mov     al,shadow_state2
                mov     cl,14h
                call    sh5_write
                ret


sh15_init_f:
                mov     cx, 0C059h
                call    sh15_read
                mov     shadow_state2, al
                and     al, 11h
                cmp     al, 11h
                setz    al
                retn
sh15_open_f:
                mov     cx, 0C059h
                mov     al, shadow_state2
                or      al, 22h
                call    sh15_write
                retn
sh15_close_f:
                mov     cx, 0C059h
                mov     al, shadow_state2
                call    sh15_write
                retn

sh16_init_f:    mov     al, 1
                ret

sh16_open_f:    mov     cl,024h
                call    sh5_read
                mov     shadow_state1,al
                or      al,040h
                mov     cl,024h
                call    sh5_write
                ret

sh16_close_f:   mov     al,shadow_state1
                mov     cl,024h
                call    sh5_write
                ret







sh21_init_f:    mov     cx, 0C059h
                call    sh21_read
                mov     shadow_state2, al
                and     al, 10h
                cmp     al, 10h
                setz    al
                retn

sh21_open_f:    mov     cx, 0C059h
                mov     al, shadow_state2
                or      al, 22h
                call    sh21_write
                retn

sh21_close_f:   mov     cx, 0C059h
                mov     al, shadow_state2
                call    sh21_write
                retn









sh31_init_f:
                mov     cx, 59h
                call    sh31_read
                mov     shadow_state2, al
                and     al, 10h
                cmp     al, 10h
                setz    al
                retn
sh31_open_f:
                mov     cx, 59h
                mov     al, shadow_state2
                or      al, 22h
                call    sh31_write
                retn
sh31_close_f:
                mov     cx, 59h
                mov     al, shadow_state2
                call    sh31_write
                retn

sh49_init_f:    mov     al, 1
                ret

sh49_open_f:    call    sh48_read
                and     al,0efh
                call    sh48_write
                call    sh48_read
                and     al,0dfh
                call    sh48_write
                ret

sh49_close_f:   call    sh48_read
                or      al,020h
                call    sh48_write
                ret

sh49_read:      mov     al,0a0h
                out     028h,al
                jmp     short $+2
                mov     al,05
                out     028h,al
                jmp     short $+2
                mov     ax,03636h
                out     028h,al
                jmp     short $+2
                in      al,02ah
                jmp     short $+2
                retn

sh49_write:     xchg    al,ah
                out     028h,al
                jmp     short $+2
                xchg    al,ah
                jmp     short $+2
                out     02ah,al
                xchg    al,ah
                mov     al,0a5h
                out     028h,al
                ret

