项目环境
编译环境:搭建一个nasm2.8 的编译环境。
镜像文件:采用winhex_18.2 刷入编码。
虚拟机:采用Bochs-2.4.5 。
项目软件
运行结果
自定义颜色块
; 编制自定义颜色
editcolor:
; 设置颜色号接口0x3c8 , RGB分量接口0x3c9
mov dx, 0x3c8
mov al, [ si]
out dx, al
mov dx, 0x3c9
mov al, [ si+ 1 ]
out dx, al
mov al, [ si+ 2 ]
out dx, al
mov al, [ si+ 3 ]
out dx, al
add si, 4
ret
程序源码(.asm)
org 0x7c00
; CS, DS, ES, SS默认的段基址为0000
; 利用jmp指令跳过段数据的定义部分
jmp start
; 其中0 号默认为背景色
; [ 1 , + ] 为前景色
; XXX, 笔画数为8 , 8 , 12 , 取公倍数160 , 160 , 240
; si
color: db 0 , 255 , 255 , 255
db 2 , 0 , 0 , 0
; bx
startP: dw 0
dw 319
dw 63680
dw 0
; ax
endP: dw 319
dw 63999
dw 63999
dw 63680
; 主函数入口地址
start:
; 进入13 号320 * 200 256 色的图形模式
mov ah, 00 h
mov al, 13 h
int 10 h
mov si, color; 赋值底色
call editcolor
mov si, color; 赋值黑色
call editcolor
; 0xb800 为显存的段基址
mov ax, 0xa000
mov es, ax
; 整体框线1 -- -- -
mov bx, [ ds: startP]
mov ax, [ ds: endP]
call DrawLineOfH
; 整体框线2 |
mov bx, [ ds: startP]
mov ax, [ ds: endP]
call DrawLineOfV
; 整体框线3 -- -- -
mov bx, [ ds: startP]
mov ax, [ ds: endP]
call DrawLineOfH
; 整体框线4 |
mov bx, [ ds: startP]
mov ax, [ ds: endP]
call DrawLineOfV
e: jmp $
; 编制自定义颜色
editcolor:
; 设置颜色号接口0x3c8 , RGB分量接口0x3c9
mov dx, 0x3c8
mov al, [ si]
out dx, al
mov dx, 0x3c9
mov al, [ si+ 1 ]
out dx, al
mov al, [ si+ 2 ]
out dx, al
mov al, [ si+ 3 ]
out dx, al
add si, 4
ret
; 横线
DrawLineOfH:
cmp bx, ax
ja DrawLineOfHExit
mov byte [ es: bx] , 2
inc bx
jmp DrawLineOfH
DrawLineOfHExit:
mov cx, word[ ds: startP+ 2 ]
mov word[ ds: startP] , cx
mov cx, word[ ds: endP+ 2 ]
mov word[ ds: endP] , cx
ret
; 竖线
DrawLineOfV:
cmp bx, ax
ja DrawLineOfVExit
mov byte [ es: bx] , 2
add bx, 320
jmp DrawLineOfV
DrawLineOfVExit:
mov cx, word[ ds: startP+ 2 ]
mov word[ ds: startP] , cx
mov cx, word[ ds: endP+ 2 ]
mov word[ ds: endP] , cx
ret