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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| ;=============================================================================
; 32-bit Assembly LES3
;=============================================================================
IDEAL
P386
MODEL FLAT, C
ASSUME cs:_TEXT,ds:FLAT,es:FLAT,fs:FLAT,gs:FLAT
;=============================================================================
; CODE
;=============================================================================
CODESEG
PROC setVideoMode
ARG mode RETURNS eax
mov eax, [mode]
int 10h
ret
ENDP setVideoMode
PROC waitKey
mov eax, 0
int 16h
ret
ENDP waitKey
; Draw a rectangle at the center of the screen.
; W, H passed on stack.
PROC drawRect
ARG w:dword, h:dword
USES eax, ebx, ecx, edx, esi, edi
; Calculate posX
mov eax, [w]
neg eax
add eax, 320
shr eax, 1
mov ebx, eax ; posX is in EBX now
; Calculate posY
mov eax, [h]
neg eax
add eax, 200
shr eax, 1 ; and posY is in EAX
; Calculate offset of top-left corner
mov edx, 320
mul edx ; EAX = posY * SCREENW
add eax, ebx ; EAX now conatins start offset of rectangle
add eax, 0a0000h
push eax ; store for left vertical line drawing
; Draw upper horizontal line
mov edi, eax
mov ecx, [w] ; rect W
mov al, 1 ; color
rep stosb ; draw
dec edi
mov ebx, edi ; EBX now contains the start of the right vertical line
; Draw left vertical line
pop edi
push ebx ; store EBX for drawing the right vertical line
mov ecx, [h] ; rect H
@@loopLeftLine:
mov [edi], al ; set pixel
add edi, 320 ; jump to next pixel (on next line)
dec ecx
jnz @@loopLeftLine
sub edi, 320
mov ebx, edi ; EBX now conatins the start of the bottom horizontal line
; Draw right vertical line
pop edi
push ebx ; store EBX for drawing bottom horizontal line
mov ecx, [h] ; rect H
@@loopRightLine:
mov [edi], al ; set pixel
add edi, 320 ; jump to next pixel (on next line)
dec ecx
jnz @@loopRightLine
; Draw bottom horizontal line
pop edi
mov ecx, [w] ; rect W
rep stosb ; draw
; done
ret
ENDP drawRect
; ================
; Start of program
; ================
PROC main
sti ; set The Interrupt Flag
cld ; clear The Direction Flag
push ds
pop es
call setVideoMode, 13h
mov edi, 0a0000h
; setup colors
mov esi, offset pal ; set the palette (DAC) address
mov ecx, 2 * 3 ; set color 0 and 1 (2 indexes in total, 2 * 3 bytes)
mov dx, 03c8h ; VGA DAC set port
mov al, 0 ; set start color index
out dx, al
inc dx
rep outsb
; draw
add edi, 320*10 + 160
mov [byte ptr edi], 1
call drawRect, 82, 162
; wait
call waitKey
call setVideoMode, 3h
mov eax, 4c00h ; AH = 4Ch - Exit To DOS
int 21h ; DOS INT 21h
ENDP main
;=============================================================================
; DATA
;=============================================================================
DATASEG
pal db 63, 0, 0, 63, 63, 63
;=============================================================================
; STACK
;=============================================================================
STACK 10000h
END main |
Partager