/*   getfont.s  : font library for gcc on FM-TOWNS
 *
 * 		(C) Copyright    Makoto Sakai
 * 			 	    Nifty:    ムンパッパ (MHB02550)     
 *			 	    junet:    sakai@sra.co.jp
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation for any purpose and without fee is hereby granted,
 * provided that the above copyright notice appear in all copies and that
 * both that copyright notice and this permission notice appear in
 * supporting documentation.
 */
	.data
	.text
	.globl _s2jis
	.globl _getfnt

/*
	(char *) s2jis(int sjiscode) 
*/
	.align 4
_s2jis:
	movl  %ebx,%eax
	movw  4(%esp),%bx
	push  %fs
	pushl %eax
	movb  $2,%ah

	pushl $0x0110
	pop   %fs

	lcall %fs:(0xa0)
	and   %ah,%ah
	jz    normal

	movl  $0xffffffff,%eax
	popl  %ebx
	popl  %fs
	ret

normal:
	movl  %ebx,%eax
	popl  %ebx
	popl  %fs
	ret

/*
	(char *) getkfnt(int flag, int jiscode, int index) 
		flag 0:hankaku, 1:kanji
*/
	.align 4
_getfnt:
	movl  %ebp,%eax
	movl  %esp,%ebp
	pushl %eax
	push  %fs
	pushl %ebx
	pushl %ecx
	pushl %edx

	movw  4(%ebp),%ax
	movw  8(%ebp),%bx
	movl  12(%ebp),%ecx

	andw  %ax,%ax
	jz    hankaku

	movw  $0x0100,%ax	/* kinou code :1  number :0(addr) */
	movw  $0x1010,%dx       /* 16x16 dot */ 
	jmp   gf1

hankaku:
	movw  $0x0000,%ax	/* kinou code :0  number :0(addr) */
	movw  $0x0810,%dx       /* 8x16 dot */ 

gf1:
	pushl %ds 
	pushl %esi
	pushl %ecx

	pushl $0x0110
	pop   %fs
	lcall %fs:(0xa0)
	popl  %ecx
	and   %ah,%ah
	jz    gf2

	movl  $0xffffffff,%eax
	jp    exit
	
gf2:
	xorl  %eax,%eax
	addl  %ecx,%esi
	movb  %ds:(%esi),%al
exit:
	popl  %esi
	popl  %ds

	popl  %edx
	popl  %ecx
	popl  %ebx
	pop   %fs
	popl  %ebp

	ret
