-
Notifications
You must be signed in to change notification settings - Fork 1
/
bounce.asm
187 lines (161 loc) · 4.13 KB
/
bounce.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
org 100h
pixel_amount equ 6
pixel_move times pixel_amount dw 0101b ; up, down, left, right
pixel_x times pixel_amount dw 0
pixel_y times pixel_amount dw 0
pixel_colour times pixel_amount dw 1
pixel_speed times pixel_amount dw 1
pixel_size times pixel_amount dw 6
pixel_colour_current dw 0
yes db 0
main:
; set graphics mode
mov al,13h ; graphics mode: 13h (256 colour vga)
mov ah,0 ; function number
int 10h
mov word [pixel_colour+2],2
mov word [pixel_colour+4],6
mov word [pixel_colour+6],4
mov word [pixel_colour+8],5
mov word [pixel_colour+10],9
mov si,2
mov ax,[pixel_x+si]
add ax,34
mov word [pixel_x+si],ax
mov ax,[pixel_y+si]
add ax,20
mov word [pixel_y+si],ax
add si,2
mov ax,[pixel_x+si]
add ax,90
mov word [pixel_x+si],ax
mov ax,[pixel_y+si]
add ax,70
mov word [pixel_y+si],ax
add si,2
mov ax,[pixel_x+si]
add ax,140
mov word [pixel_x+si],ax
mov ax,[pixel_y+si]
add ax,6
mov word [pixel_y+si],ax
add si,2
mov ax,[pixel_x+si]
add ax,250
mov word [pixel_x+si],ax
mov ax,[pixel_y+si]
add ax,140
mov word [pixel_y+si],ax
add si,2
mov ax,[pixel_x+si]
add ax,80
mov word [pixel_x+si],ax
mov ax,[pixel_y+si]
add ax,50
mov word [pixel_y+si],ax
loop:
mov si,0 ; reset index of current pixel
.pixel:
mov ax,[pixel_colour+si]
mov word [pixel_colour_current],ax
call pixel_draw
add si,2 ; next pixel
mov ax,pixel_amount
add ax,ax ; cheeky way of multiplying by 2
cmp si,ax ; are we on the last pixel index?
jne .pixel ; if not, draw the next pixel!
mov si,0 ; finished drawing, so reset index of current pixel
mov word [pixel_colour_current],0
; delay...
mov ecx,24000
.delay:
nop
loop .delay
.pixel_remove:
call pixel_draw
call pixel_movement
add si,2
mov ax,pixel_amount
add ax,ax
cmp si,ax
jne .pixel_remove ; we haven't reached the last pixel yet!
;mov ah,0x4c
;int 21h
jmp loop
pixel_movement:
mov cx,[pixel_speed+si]
mov dx,[pixel_move+si]
test dx,1000b ; moving up?
jz .down_skip ; if not, skip
sub word [pixel_y+si],cx ; otherwise, move it up
.down_skip:
test dx,0100b ; moving down?
jz .left_skip ; if not, skip
add word [pixel_y+si],cx ; otherwise, move it down
.left_skip:
test dx,0010b ; moving left?
jz .right_skip ; if not, skip
sub word [pixel_x+si],cx ; otherwise, move it left
.right_skip:
test dx,0001b ; moving right?
jz .end_skip ; if not, skip
add word [pixel_x+si],cx ; otherwise, move it right
.end_skip:
pixel_hit_check:
mov dx,[pixel_x+si]
mov cx,320
sub cx,[pixel_speed+si]
sub cx,[pixel_size+si]
cmp dx,cx
jb .left_skip ; if not, skip
xor byte [pixel_move+si],0011b ; if so, stop moving right
call pixel_colour_change
.left_skip:
mov cx,[pixel_speed+si]
cmp dx,cx
jae .top_skip ; if not, skip
xor byte [pixel_move+si],0011b ; if so, stop moving left
call pixel_colour_change
.top_skip:
mov dx,[pixel_y+si]
cmp dx,cx
jae .bottom_skip ; if not, skip
xor byte [pixel_move+si],1100b ; if so, stop moving up
call pixel_colour_change
.bottom_skip:
mov cx,200
sub cx,[pixel_speed+si]
sub cx,[pixel_size+si]
cmp dx,cx
jb .end_skip ; if not, skip
xor byte [pixel_move+si],1100b ; if so, stop moving down
call pixel_colour_change
.end_skip:
ret
pixel_colour_change:
inc byte [pixel_colour+si]
mov dx,[pixel_colour+si]
cmp dx,15
jb .skip
mov word [pixel_colour+si],1
.skip:
ret
pixel_draw:
mov cx,[pixel_x+si] ; x
mov dx,[pixel_y+si] ; y
.horiz_loop:
mov al,[pixel_colour_current]
mov ah,0ch ; function number
int 10h
inc cx
mov ax,cx ; copy modified pixel x to ax
sub ax,[pixel_x+si] ; difference between modified pixel x and original pixel x
cmp ax,[pixel_size+si] ; have we reached the end of the line yet? (well it's aaaaaaalright)
jb .horiz_loop ; if not, keep bustin.
inc dx ; otherwise, we've reached the end of the line, increase y and reset x
mov cx,[pixel_x+si]
mov ax,dx
sub ax,[pixel_y+si] ; difference between modified/original again...
cmp ax,[pixel_size+si] ; are we there yet?
jb .horiz_loop ; if not, keep drawing horizontally
ret