-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.asm
158 lines (122 loc) · 2.23 KB
/
main.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
[BITS 16]
%define VGA_WIDTH (640 / 8)
%define VGA_HEIGHT 480
%define BASEVELOCITY 1
struc rectdef
.x: resw 1
.y: resw 1
endstruc
mov bp, sp
mov ax, 0011h
int 0x10
push 0xA0000 / 16 ; x86 segment
pop es ; to vram
draw_loop:
; sleep
mov al, 0
mov ah, 0x86
mov dx, 0xAFFF
mov cx, 0x0
int 0x15
; this barely works half of the time
mov dx, 0x03DA
.ret1:
in al, dx
test al, 8
jz .ret1
.ret2:
in al, dx
test al, 8
jnz .ret2
; clear drawn portion
mov bl, 0
call draw_rect
; add velocities to position
mov ax, word [velocity.x]
add word [rect + rectdef.x], ax
mov ax, word [velocity.y]
add word [rect + rectdef.y], ax
; draw image
mov bl, 1
call draw_rect
jmp draw_loop
velocity.x: dw BASEVELOCITY
velocity.y: dw BASEVELOCITY * 8
; %define IMAGE_SCANLINE_AMT 16
; %define SCANLINE_BYTE_LEN 10 ; index by 10 for each x scanline
; %define IMAGE_RECT_WIDTH 5
rect:
istruc rectdef
at rectdef.x, dw VGA_WIDTH / 2
at rectdef.y, dw VGA_HEIGHT / 2
iend
; AX: (*rect)
; BL: clear?
draw_rect:
mov bp, sp
mov ax, [rect + rectdef.x]
add ax, IMAGE_RECT_WIDTH
push ax
mov cx, [rect + rectdef.x]
sub cx, IMAGE_RECT_WIDTH
push cx
cmp ax, VGA_WIDTH
jge .s1
cmp cx, 0
jnle .s2
mov word [velocity.x], BASEVELOCITY
jmp .s2
.s1:
mov word [velocity.x], -BASEVELOCITY
.s2:
mov ax, [rect + rectdef.y]
add ax, IMAGE_SCANLINE_AMT
push ax
mov cx, [rect + rectdef.y]
sub cx, IMAGE_SCANLINE_AMT
push cx
cmp ax, VGA_HEIGHT
jge .s3
cmp cx, 0
jnle .s4
mov word [velocity.y], (BASEVELOCITY * 8)
jmp .s4
.s3:
mov word [velocity.y], (-BASEVELOCITY * 8)
.s4:
; bp - 2 | x + w
; bp - 4 | x - w
; bp - 6 | y + h
; bp - 8 | y - h
mov ax, 0
mov dx, [bp - 8]
vloop:
mov di, dx
imul di, VGA_WIDTH
add di, [bp - 4]
imul si, ax, SCANLINE_BYTE_LEN - 1 ; the negative one might cause issues but it's good for now
add si, image_dvd
hloop:
mov cx, SCANLINE_BYTE_LEN - 1
test bl, bl
je .zero
rep movsb
jmp .next
.zero:
push ax
mov ax, 0
rep stosd
pop ax
.next:
inc ax
inc dx
cmp dx, [bp - 6]
jne vloop
mov sp, bp
ret
image_dvd:
incbin "dvd/rawdvdbytes"
image_dvd_end:
%if $-$$ > 510
%error ----- exeeded 512 bytes -----
%endif