-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbfx_256a.asm
174 lines (149 loc) · 3.21 KB
/
bfx_256a.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
[org 0x100]
mov ax, 13h ; Modus 13h laden
int 10h ; BIOS Video Services aufrufen
; PALLETTE
xor cl, cl
pallette_loop:
mov dx, 3C8h ; Indexregister for color palette (0x3C8)
mov al, cl
out dx, al ; init color for redefine
inc dx
out dx, al ; red = counter
shr al, 1
out dx, al ; green = red >> 1
shr al, 1
out dx, al ; blue = green >> 1
loop pallette_loop
game_loop:
mov ax, si
call sqCos
mov dx, ax
mov ax, si
call sqSin
mov cx, ax
sub cx, 64
sub dx, 96
shl cx, 1
shl dx, 1
mov di, 0xA000
test si, 512 + 256
jnz doRoto
fireScreen:
pusha
mov es, di
mov di, 65535 - 321
next:
xor bx, bx
mov al, byte [es:di]
mov bl, byte [es:di+320]
add ax, bx
shr ax, 1
mov [es:di], al
dec di
jnz next
popa
jmp WaitForNextFrame
doRoto:
; calculate start position
add [xPos], cx
sub [yPos], dx
mov ax, [xPos]
mov bx, [yPos]
loop_y:
mov es, di
mov di, 320
push ax
push bx
loop_x:
add ax, cx
add bx, dx
;PaintPixel
pusha
xor ah, bh
test ah, 4
jz noPaint
cmp ah, 64
jl doPaint
mov ax, di
sub ax, si
call sqSin
mov bh, al
mov ax, es
add ax, si
shr ax, 2
call sqSin
add al, bh
add ax, di
call sqSin
mov ah, al
shr ah, 2
add ah, 64
doPaint:
mov [es:di], ah
noPaint:
popa
afterPaintPixel:
dec di
jns loop_x ; Do next pixel in row
pop bx
pop ax
add bx, cx
sub ax, dx
mov di, es
add di, 20
cmp di, 44960
jl loop_y
; Wait until Retrace
WaitForNextFrame:
inc si
and si, 1023
mov dx, 0x03da
WaitNotVSync:
in al, dx
and al, 0x08
jnz WaitNotVSync
WaitVSync:
in al, dx
and al, 0x08
jz WaitVSync
wait_for_esc:
in al, 60h ; read scan code from keyboard
dec al ; == 1 ?
jnz game_loop
found_esc:
; exit
ret
sqCos:
add al, 64
sqSin:
push bx
; int i = cnt & 255;
xor ah, ah
; boolean big = (i & 128) != 0;
mov bl, al
; i &= 127;
and al, 127
; i -= 64;
sub ax, 64
; int val = 128 - (i * i) / 32;
imul ax, ax
shr ax, 5
sub ax, 128
neg ax
; if (big) {
; val = -val;
; }
test bl, 128
jz sqSin_no_neg
neg ax
sqSin_no_neg:
add ax, 128
pop bx
or ah, ah
jz sqSin_ret
dec ax
sqSin_ret:
ret
xPos db 0x07, 0x30;
yPos db 0x02, 0x05;
weWereHere db 66, 70, 88 ; "BFX"