本篇为APP篇,介绍使用x86汇编编写的用户进程。由于APP的结构非标准,只能同前两篇中的代码一同使用。前篇的core代码在load用户APP时,会在APP最前部写入四个系统调用的接口数据,用户APP将调用这四个接口来使用core提供的系统功能。
用户APP的结构非常简单,前24个字节用于存放系统调用接口,后面直接是执行代码。用户APP一共有两个:task.asm和task1.asm。task.asm编译出的bin文件需要写入逻辑硬盘的第100个扇区,task1.asm编译出的bin文件需要写入逻辑硬盘的第200个扇区。两个APP存放扇区的起始编号都写在core代码中,因此不能随意修改。
task.asm代码如下:
;===============================================================================
;=== 本程序为用户程序,在屏幕右下角不断闪烁显示矩形 ===
;===============================================================================
;===============================================================================
;=== 该处开始用户代码 ===
;===============================================================================
SECTION core vstart=0x0
[bits 32]
show_caller dd 0x0 ;偏移(不用)
dw 0x0 ;选择子
back_caller dd 0x0 ;偏移(不用)
dw 0x0 ;选择子
rect_caller dd 0x0 ;偏移(不用)
dw 0x0 ;选择子
cmd_caller dd 0x0 ;偏移(不用)
dw 0x0 ;选择子
;rect_caller的输入参数是:
;EAX-低16位为Y值,高16位为Y的高度
;EBX-低16位为X值,高16位为X的宽度
;CL=颜色
mov cl, [_color]
mov eax, 0x640064
mov ebx, 0xa000a0
_draw_rectangle:
call far [rect_caller]
mov edx, eax
shr edx, 16
sub edx, 8
shl edx, 16
and eax, 0xffff
add eax, 4
or eax, edx
mov edx, ebx
shr edx, 16
sub edx, 8
shl edx, 16
and ebx, 0xffff
add ebx, 4
or ebx, edx
inc cl
cmp cl, 14
jb _next_rectangle
mov cl, 1
mov eax, 0x640064
mov ebx, 0xa000a0
_next_rectangle:
push eax
mov eax, 16 ;休眠160毫秒
call far [back_caller]
pop eax
push eax
call far [cmd_caller]
cmp al, 0x55
jnz _go_on
pop eax
mov cl, 1
mov eax, 0x640064
mov ebx, 0xa000a0
jmp _draw_rectangle
_go_on:
pop eax
jmp _draw_rectangle
;-------------------------------------------------------------------------------
;-------------------------------------------------------------------------------
_color db 1,0,0,0
_x_ dd 160 ;x坐标
_y_ dd 100 ;y坐标
_cmd db 0,0,0,0
;-------------------------------------------------------------------------------
SECTION core_trail
;-------------------------------------------------------------------------------
core_end:
task1.asm的代码如下:
;===============================================================================
;=== 本程序为用户程序,在屏幕左下角显示八个不同颜色的矩形块 ===
;===============================================================================
;===============================================================================
;=== 该处开始用户代码 ===
;===============================================================================
SECTION core vstart=0x0
[bits 32]
show_caller dd 0x0 ;偏移(不用)
dw 0x0 ;选择子
back_caller dd 0x0 ;偏移(不用)
dw 0x0 ;选择子
rect_caller dd 0x0 ;偏移(不用)
dw 0x0 ;选择子
cmd_caller dd 0x0 ;偏移(不用)
dw 0x0 ;选择子
mov edx, show_block1
_draw_rectangle:
call edx
mov eax, 8 ;休眠80毫秒
call far [back_caller]
call far [cmd_caller]
cmp al, 0x55
jnz _draw_rectangle
cmp edx, show_block1
jz _change_handle
mov edx, show_block1
jmp _draw_rectangle
_change_handle:
mov edx, show_block2
jmp _draw_rectangle
;-------------------------------------------------------------------------------
show_block1:
;rect_caller的输入参数是:
;EAX-低16位为Y值,高16位为Y的高度
;EBX-低16位为X值,高16位为X的宽度
;CL=颜色
mov cl, 1
mov eax, 0x320064
mov ebx, 0x280000
call far [rect_caller]
mov cl, 2
mov eax, 0x320064
mov ebx, 0x280028
call far [rect_caller]
mov cl, 3
mov eax, 0x320064
mov ebx, 0x280050
call far [rect_caller]
mov cl, 4
mov eax, 0x320064
mov ebx, 0x280078
call far [rect_caller]
mov cl, 5
mov eax, 0x320096
mov ebx, 0x280000
call far [rect_caller]
mov cl, 6
mov eax, 0x320096
mov ebx, 0x280028
call far [rect_caller]
mov cl, 7
mov eax, 0x320096
mov ebx, 0x280050
call far [rect_caller]
mov cl, 8
mov eax, 0x320096
mov ebx, 0x280078
call far [rect_caller]
ret
;-------------------------------------------------------------------------------
show_block2:
;rect_caller的输入参数是:
;EAX-低16位为Y值,高16位为Y的高度
;EBX-低16位为X值,高16位为X的宽度
;CL=颜色
mov cl, 9
mov eax, 0x320064
mov ebx, 0x280000
call far [rect_caller]
mov cl, 10
mov eax, 0x320064
mov ebx, 0x280028
call far [rect_caller]
mov cl, 11
mov eax, 0x320064
mov ebx, 0x280050
call far [rect_caller]
mov cl, 12
mov eax, 0x320064
mov ebx, 0x280078
call far [rect_caller]
mov cl, 13
mov eax, 0x320096
mov ebx, 0x280000
call far [rect_caller]
mov cl, 14
mov eax, 0x320096
mov ebx, 0x280028
call far [rect_caller]
mov cl, 15
mov eax, 0x320096
mov ebx, 0x280050
call far [rect_caller]
mov cl, 0
mov eax, 0x320096
mov ebx, 0x280078
call far [rect_caller]
ret
;-------------------------------------------------------------------------------
_color db 0,0,0,0
_x_ dd 0 ;x坐标
_y_ dd 100 ;y坐标
_cmd db 0,0,0,0
;-------------------------------------------------------------------------------
SECTION core_trail
;-------------------------------------------------------------------------------
core_end:
整体系统运行起来后,界面显示如下图所示:
1. 最上排的从左向右移动的线由Core绘制;
2.中间的红点为鼠标点,通过移动鼠标将移动到不同的地方;
3.左下角由task1.asm用户进程绘制,当鼠标移动到该区域并点击时,八个方块会改变颜色;
4.右下角由task.asm用户进程绘制,这些矩形将从外向内闪烁。当鼠标移动到该区域并点击时,矩形会重新绘制;