-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.asm
107 lines (87 loc) · 1.29 KB
/
test.asm
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
org 0x20000
bits 32
pix: equ 0x40000
screen_size: equ 0x10000
input: equ 0x50000
header: db '#!/usr/bin/env b8', 0x0a
times 32-$+header db 0x0
jmp [state_fun]
state_fun dd init
init:
; set initial screen
mov ecx, screen_size
.loop:
push cx
call colorize
pop cx
mov byte [ecx + pix], al
loop .loop
mov dword [state_fun], f
ret
f:
; update coords
mov eax, 0
mov al, byte [input]
mov edx, [coords]
.check_left:
mov cl, 1b
and cl, al
jz .check_right
sub dx, 1
.check_right:
mov cl, 10b
and cl, al
jz .check_up
add dx, 1
.check_up:
mov cl, 100b
and cl, al
jz .check_down
sub dx, 0x100
.check_down:
mov cl, 1000b
and cl, al
jz .check_end
add dx, 0x100
.check_end:
mov [coords], edx
; get color
mov ecx, [coords]
mov eax, screen_size-1
sub eax, ecx
push ax
call colorize
add esp, 2
mov edx, [coords]
mov byte [pix+edx], al
ret
colorize:
mov al, 0
mov dx, 0
mov cx, [esp+4] ; get fun argument
;red part
mov dl, cl
and dl, 01110000b
sal dl, 1
and dl, 11100000b
or al, dl
;green part
mov dl, ch
and dl, 01110000b
sar dl, 1
sar dl, 1
and dl, 00011100b
or al, dl
;dlue part
and ch, 10000000b
mov dl, ch
and cl, 10000000b
sar cl, 1
and cl, 01000000b
or dl, cl
mov cl, 6
sar dl, cl
and dl, 00000011b
or al, dl
ret
coords: dd 0x8080