Computer Basic-Graphic And Assembly Basic

大一课程计算机基础,蛮有意思的就整理了一下笔记

Imagine methods

pixel 像素

screen resolution 屏幕像素

  • Raster graphics 栅格图像
  • Vector Graphics
  • Fractal

Color Model

  • RGB - red, green and blue
  • CMYK
  • HSL & HSV - hue, saturation & lightness / value

Graphics Adapters

Components mounted on a video card:

  • GPU - graphics processing unit
  • video BIOS
  • heatvideo memory
  • RAMDAC
  • heat sink
  • output interfaces
  • power supply

A graphics adapter is an electronic board that transform graphic data (text, pictures,video) into a video signal for a monitor.

Memory organization in graphics adapters

CGA - Color Graphic Adapter 彩色图形适配器

EGA - Enhanced Graphic Adapter 增强图形适配器

1
2
3
4
5
6
7
; fill the screen with bright white color 
MOV AX, 0A000h ; start address of the video memory
MOV ES, AX
XOR DI, DI ; clearing the index register
MOV CX, 8000 ; program sequence counter
MOV AL, 0Fh ; set the code into white
REP STOSB

VGA - Video Graphics Array 视频图形阵列

GDI

Graphics Device Interface

GDI + kernel + Windows API -> Microsoft Windows user interface

DC Device Context

HDC Handle DC

Assembly Basic

EAX Accumulator 累加寄存器

EBX Base 基地址寄存器

ECX Counter 计数寄存器

EDX Data 数据寄存器

Index and pointer registers

ESI - Source index 源变址寄存器

EDI - Destination index 目的变址寄存器

EBP - Extended Base Pointer 栈指针寄存器,永远指向系统栈最上面的一个栈帧的栈顶

ESP - Extended Stack Pointer 基址指针寄存器,永远指向系统栈最上面的一个栈帧的栈底

EIP - Index Pointer Register

Segment Registers

● CS - the code segment register 代码段寄存器用于存放代码

● DS - the data segment register 数据段寄存器存放数据

● SS - the stack segment register 栈段寄存器,相当于堆栈段的首地址

● ES, FG, GS - Some string operations use an optional segment register to control memory addressing.

Variable types

db data byte - memory allocation for 1 byte data

dw data word - memory allocation for 2 byte data

dd double word - memory allocation for 4 byte data

df double word - memory allocation for 6 byte data

dq double word - memory allocation for 8 byte data

FASM

一个例子

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
format PE GUI 4 . 0
//声明二进制文件的类型

entry s t a r t

include ’win32ax.inc’

struct GdiplusStartupInput
GdiplusVers ion dd ?
DebugEventCallback dd ?
SuppressBackgroundThread dd ?
SuppressExternalCodecs dd ?
ends

library gdi , ’GDI.DLL’, \
gdiplus , ’GDIPLUS.DLL’,\
kernel32 , ’KERNEL32.DLL’,\
user32 , ’USER32.DLL’

wc WNDCLASS 0, WindowProc, 0, 0,NULL,NULL,NULL,COLORBTNFACE+1,NULL, class
//注册一个windows类

msg MSG

invoke GetModuleHandle , 0

mov [ wc.hInstance ], eax

invoke LoadCursor , 0 ,IDCARROW

invoke GdiplusStartup , token , input , Null
//初始化Windows GDI+
//token参数指向一个DW变量的指针,用于接受GDI+的TOKEN.TOKEN,该参数在后期结束释放GDI+资源时使用GdiplusShutdown用到
//input, output参数是指向两个结构体变量的指针:input中包括GDC+版本、指向debug callback函数的指针、压缩相关指令等等

test eax , eax
//test用于将两个操作数进行逻辑与运算,并根据结果设置标志位
jnz error

invoke BeginPaint [ hwnd ], paintStructVariable
//为指定窗口进行绘图工作的准备,并将相关信息填充到paintStructVarible结构中

stdcall draw, EAX, $FF000000

invoke GdipCreateFromHDC , [ hdc ] , addr pGraphics
//创建相对应的绘图区域

invoke GdipCreatePen1 , [ color ] , 3 .0 , 2 , addr pPen

invoke GdipSetSmoothingMode , [ pGraphics ] , 2
//确定渲染质量

invoke GdipDrawLineI , [ pGraphics ] , [ pPen ] ,
addr 0+ebx ∗8 , addr 100+ebx ∗8 ,
addr 700+ebx ∗8 , addr 400+ebx∗8
//GdipDrawLineI函数用于在两点之间画线
//[pGraphics]参数是指向对象的指针
//[pPen]参数是指向画线的“笔”的指针
//后面参数用于定位起始点和终止点

GetModuleHandle 用于获取一个应用程序或动态链接库的模块句柄,前提是目的模块已映射到调用该函数的进程内

LoadCursor 从一个与相关的可执行文件中载入指定的光标资源

ARGB - Alpha(transparency) + RGB

参考资料:
Windows API GDI+官方文档
[关于Gdi+和GdiplusStartup](