⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syscall.inc

📁 一个从底层支持中文显示的操作系统的源代码,以及目标IMG文件,可在VMWare下运行.
💻 INC
字号:
;===========================================================
;
;	WarmOS
;	by HotHeart(xujiwei)
;	Email: vipxjw@163.com
;
;	History:
;	2005.08.29	finished function
;				putchar,getchar,movecursor,clearscr,printnum
;				getcursor
;	2005.08.27	finished function printf
;	2005.08.26	file created
;
;===========================================================

;===========================================================
;	syscall serve table
;===========================================================
align	4
serve_table:
	dw	printf				; 0 - print a string to screen
	dw	putchar				; 1 - print a char in bx
	dw	movecursor			; 2 - move cursor
	dw	clearscr			; 3 - cls
	dw	printnum			; 4 - print number
	dw	getchar				; 5 - get char
	dw	getcursor			; 6 - get cursor pos
	dw	readfile			; 7 - load file from floppy
serve_table_end:

;===========================================================
;	Syscall
;===========================================================
align	4
serve_addr	dw	0
sys_call:
		cmp		ax,-1
		jne		.no_exit_process
		mov		ds,[CS:REGS_DS]
		mov		es,[CS:REGS_ES]
		mov		fs,[CS:REGS_FS]
		mov		gs,[CS:REGS_GS]
		mov		ss,[CS:REGS_SS]
		mov		sp,[CS:REGS_SP]
		add		sp,4
		mov		ax,1
		mov		bx,13
		int		0x40
		push	word [CS:REGS_CS]
		push	word [CS:REGS_IP]
		ret
	.no_exit_process:
		cmp		ax,(serve_table_end-serve_table)/2
		jge		.done
		push	ax
		push	bx
		mov		bx,ax
		shl		bx,1
		mov		ax,[cs:bx+serve_table]
		mov		[cs:serve_addr],ax
		pop		bx
		pop		ax
		call	word[cs:serve_addr]
	.done:
		iret

;===========================================================
;	printf
;	in	ax 0
;		bx string address
;	out nothing
;===========================================================
align	4
printf_x	dw	0
printf_y	dw	0
printf:
		pusha
		push	ds
		push	es
		mov		si,bx
	.next:
		lodsb
		or		al,al
		je		.done
		cmp		al,13
		je		.nextline
		cmp		al,9
		je		.tab
		test	al,0x80
		jz		.draw_en
		cmp		[si],byte 0
		je		.draw_en
		test	[si],byte 0x80
		jz		.draw_en
		mov		ah,al
		lodsb
		call	printf_draw_cn
		jmp		.next
	.draw_en:
		call	printf_draw_en
		jmp		.next
	.nextline:
		push	ds
		mov		cx,cs
		mov		ds,cx
		inc		word[printf_y]
		mov		word[printf_x],0
		inc		si
		call	printf_check_pos
		pop		ds
		jmp		.next
	.tab:
		push	ds
		mov		cx,cs
		mov		ds,cx
		mov		ax,[printf_x]
		add		ax,4
		and		ax,0xFFFC
		mov		[printf_x],ax
		call	printf_check_pos
		pop		ds
		jmp		.next
	.done:
		pop		es
		pop		ds
		popa
		ret
;===========================================================
;	putchar
;	in	ax 1
;		bx ascii code in bl or chinese code
;	out nothing
;===========================================================
align	4
putchar:
		pusha
		push	ds
		mov		cx,cs
		mov		ds,cx
		cmp		bh,0
		jne		.draw_cn
		cmp		bl,13
		je		.newline
		mov		al,bl
		call	printf_draw_en
		jmp		.done
	.newline:
		mov		word[printf_x],0
		inc		word[printf_y]
		call	printf_check_pos
		jmp		.done
	.draw_cn:
		call	printf_draw_cn
	.done:
		pop		ds
		popa
		ret

;===========================================================
;	draw en
;	in	al ascii code
;	out nothing
;===========================================================
align	4
printf_draw_en:
		pusha
		push	es
		push	ds
		mov		bx,cs
		mov		ds,bx
		movzx	si,al
		shl		si,4
		add		si,font_en
		mov		di,[printf_y]
		imul	di,80*16
		add		di,[printf_x]
		mov		ax,0xA000
		mov		es,ax
		mov		cx,16
		cld
	.loop:
		movsb
		add		di,79
		loop	.loop
	.done:
		inc		word[printf_x]
		call	printf_check_pos
		pop		ds
		pop		es
		popa
		ret

;===========================================================
;	draw cn
;	in	ax char code
;	out nothing
;===========================================================
align	4
printf_draw_cn:
		pusha
		push	es
		push	ds
		mov		bx,cs
		mov		ds,bx
		cmp		word[printf_x],78
		jbe		.calc_char_pos
		inc		word[printf_x]
		call	printf_check_pos
	.calc_char_pos:
		mov		di,[printf_y]
		imul	di,80*16
		add		di,[printf_x]
		sub		ax,0xA1A1
		movzx	bx,ah
		imul	bx,94*2
		mov		cx,ds
		add		cx,bx
		mov		ds,cx
		movzx	si,al
		shl		si,5
		add		si,font_cn
	.print:
		mov		ax,0xA000
		mov		es,ax
		mov		cx,16
	.loop:
		movsw
		add		di,78
		loop	.loop
	.done:
		mov		bx,cs
		mov		ds,bx
		add		word[printf_x],2
		call	printf_check_pos
		pop		ds
		pop		es
		popa
		ret

;===========================================================
;	check pos
;	in	nothing
;	out nothing
;===========================================================
align	4
printf_check_pos:
		push	ax
		push	bx
		push	ds
		mov		ax,cs
		mov		ds,ax
		mov		ax,[printf_x]
		mov		bx,[printf_y]
	.chkright:
		cmp		ax,79
		jbe		.chkbottom
		mov		ax,0
		inc		bx
	.chkbottom:
		cmp		bx,29
		jbe		.done
	.scroll_screen:
		push	ds
		push	es
		pusha
		mov		ax,0xA000
		mov		ds,ax
		mov		es,ax
		mov		si,80*16
		mov		di,0
		mov		cx,(80*16*29)/2
		cld
		rep		movsw
		mov		di,80*16*29
		xor		ax,ax
		mov		cx,80*16
		cld
		rep		stosw
		popa
		pop		es
		pop		ds
		dec		bx
	.done:
		mov		[printf_x],ax
		mov		[printf_y],bx
		pop		ds
		pop		bx
		pop		ax
		ret

;===========================================================
;	move cursor
;	in	ax 2
;		bh = new x
;		bl = new y
;	out nothing
;===========================================================
align	4
movecursor:
		pusha
		push	ds
		mov		ax,cs
		mov		ds,ax
		and		bx,0x7F7F
	.chk_x:
		cmp		bh,80
		jbe		.chk_y
		mov		bh,80
	.chk_y:
		cmp		bl,30
		jbe		.chk_x_0
		mov		bl,30
	.chk_x_0:
		cmp		bh,0
		jne		.chk_y_0
		inc		bh
	.chk_y_0:
		cmp		bl,0
		jne		.done
		inc		bl
	.done:
		sub		bx,0x0101
		movzx	ax,bh
		and		bx,0xF
		mov		[printf_x],ax
		mov		[printf_y],bx
		pop		ds
		popa
		ret

;===========================================================
;	clear screen
;	in	ax 3
;	out nothing
;===========================================================
align	4
clearscr:
		pusha
		push	es
		push	ds
	.cls:
		mov		ax,0xA000
		mov		es,ax
		mov		di,0
		mov		cx,80*480/2
		xor		ax,ax
		cld
		rep		stosw
	.set_cur:
		mov		ax,cs
		mov		ds,ax
		mov		[printf_x],word 0
		mov		[printf_y],word 0
	.done:
		pop		ds
		pop		es
		popa
		ret

;===========================================================
;	print number
;	in	ax 4
;		bx number to print
;	out nothing
;===========================================================
align	4
NUM_TEMP	db	'00000',0
printnum:
		pusha
		push	ds
		mov		ax,cs
		mov		ds,ax
		mov		cx,5
		mov		si,NUM_TEMP+4
		mov		ax,bx
	.pms_loop:
		xor		dx,dx
		mov		bx,10
		div		bx
		add		dl,0x30
		mov		[si],dl
		dec		si
		loop	.pms_loop
		mov		cx,4
		mov		bx,NUM_TEMP
	.ignore_0:
		cmp		[bx],byte '0'
		jne		.pr
		inc		bx
		loop	.ignore_0
	.pr:
		call	printf
	.pe:
		pop		ds
		popa
		ret


;===========================================================
;	get char
;	in	ax 5
;	out bh = 0
;			bl = ASCII
;		bx = chinese
;===========================================================
align	4
IME_CURRENT			dw	0
IME_TABLE:
	dw	IME_ENGLISH
IME_TABLE_END:

getchar:
		push	ds
		push	bx
		mov		ax,cs
		mov		ds,ax
		mov		bx,[IME_CURRENT]
		shl		bx,1
		call	word[bx+IME_TABLE]
		pop		bx
		pop		ds
		ret

;===========================================================
;	english input method
;	in	none
;	out	al	ascii code
;===========================================================
align	4
IME_ENGLISH:
		mov		ah,0
		int		0x16
		and		ax,0xFF
		ret

;===========================================================
;	get cursor postion
;	in	ax 6
;	out bh = x
;		bl = y
;===========================================================
align	4
getcursor:
		push	ds
		mov		ax,cs
		mov		ds,ax
		mov		ax,[printf_x]
		shl		ax,8
		add		ax,[printf_y]
		pop		ds
		ret

;===========================================================
;	load file from floppy
;	in	ax	7
;		bx	filename, end with 0
;	out ax	0 success
;			other fail
;===========================================================
align	4
szLF_BUF	times	12	db	0
readfile:
		push	si
		push	di
		push	ds
		push	es
		push	bp
		mov		bp,sp
;		mov		ax,cs
;		mov		es,ax
;		mov		bx,si
;		mov		di,szLF_BUF
;		call	FD_Expand
;		mov		es,[bp+2]
		call	FD_LoadFile
	.done:
		pop		bp
		pop		es
		pop		ds
		pop		di
		pop		si
		ret

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -