wok-tiny view bootfbird/stuff/fbird.asm @ rev 183

linux: fix bundle.S
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Sep 26 17:09:38 2023 +0000 (7 months ago)
parents bbb34fe4904d
children 34a0a4406539
line source
1 ;
2 ; F-bird text game in a bootsector
3 ;
4 ; by Oscar Toledo G.
5 ; http://nanochess.org/
6 ;
7 ; Creation date: Jun/04/2017. A messy unoptimized thing.
8 ; Revision date: Jun/05/2017. Better usage of graphic charset.
9 ; Removed a non-8088 long jump. Added
10 ; sound. Solved bug when overwriting
11 ; previous score.
12 ;
14 use16
15 cpu 8086
17 restart:
18 mov ax,0x0002 ; Set 80x25 text mode
19 int 0x10 ; Call BIOS
20 ;
21 ; Game restart
22 ;
23 fb21: cld ; Reset direction flag (so stosw increments registers)
24 sti ; Allow interrupts
25 mov ax,0xb800 ; Point to video segment
26 mov ds,ax ; Both the source (common access)
27 mov es,ax ; and target segments
28 mov di,pipe ; Init variables in video segment (saves big bytes)
29 cbw
30 stosw ; pipe
31 stosw ; score
32 stosw ; grav
33 mov al,0xa0
34 stosw ; next
35 mov al,0x60
36 stosw ; bird
38 mov di,0x004a ; Game title
39 mov ax,0x0f46 ; 'F' in white, good old ASCII
40 stosw
41 mov al,0x2d ; '-'
42 stosw
43 mov al,0x42 ; 'B'
44 stosw
45 mov al,0x49 ; 'I'
46 stosw
47 mov al,0x52 ; 'R'
48 stosw
49 mov al,0x44 ; 'D'
50 stosw
51 mov bp,80 ; Introduce 80 columns of scenery
52 fb1: call scroll_scenery
53 dec bp
54 jnz fb1
56 fb23: mov ah,0x01 ; Check if key pressed
57 int 0x16
58 pushf
59 xor ax,ax ; Wait for a key
60 int 0x16
61 popf
62 jnz fb23 ; Jump if key was accumulated, if not already waited for key ;)
64 ;
65 ; Main loop
66 ;
67 fb12: mov si,bird
68 lodsw ; Bird falls...
69 add al,[grav] ; ...because of gravity...
70 mov [bird],al ; ...into new position.
71 and al,0xf8 ; Row is a 5.3 fraction, nullify fraction
72 mov ah,0x14 ; Given integer is x8, multiply by 20 to get 160 per line
73 mul ah ; Row into screen
74 add ax,$0020 ; Fixed column
75 xchg ax,di ; Pass to DI (AX cannot be used as pointer)
76 lodsb ; mov al,[frame]
77 and al,4 ; Wing movement each 4 frames
78 jz fb15
79 mov al,[di-160] ; Get character below
80 mov word [di-160],$0d1e ; Draw upper wing
81 add al,[di] ; Add another character below
82 shr al,1 ; Normalize
83 mov word [di],$0d14 ; Draw body
84 jmp short fb16
86 fb15: mov al,[di] ; Get character below
87 mov word [di],$0d1f ; Draw body
88 fb16: add al,[di+2] ; Get character below head
89 mov word [di+2],$0d10 ; Draw head
90 cmp al,0x40 ; Collision with scenery?
91 jz fb19
92 ;
93 ; Stars and game over
94 ;
95 mov byte [di],$2a ; '*' Asterisks to indicate crashing
96 mov byte [di+2],$2a
97 mov di,0x07CA
98 mov ax,0x0f42 ; 'B' in white, good old ASCII
99 stosw
100 mov al,0x4F ; 'O'
101 stosw
102 mov al,0x4E ; 'N'
103 stosw
104 mov al,0x4B ; 'K'
105 stosw
106 mov al,0x21 ; '!'
107 stosw
108 mov bp,100 ; Wait 100 frames
109 fb20: call wait_frame
110 dec bp
111 jnz fb20
112 jmp fb21 ; Restart
114 fb19: call wait_frame ; Wait for frame
115 mov al,[frame]
116 and al,7 ; 8 frames have passed?
117 jnz fb17 ; No, jump
118 inc word [grav] ; Increase gravity
119 fb17:
120 mov al,$20
121 mov [di-160],al ; Delete bird from screen
122 mov [di+2],al
123 stosb
124 call scroll_scenery ; Scroll scenery
125 call scroll_scenery ; Scroll scenery
126 cmp byte [0x00a0],0xb0 ; Passed a column?
127 jz fb27
128 cmp byte [0x00a2],0xb0 ; Passed a column?
129 fb27: jnz fb24
130 inc word [score] ; Increase score
131 mov ax,[score]
132 mov di,0x008e ; Show current score
133 fb25: xor dx,dx ; Extend AX to 32 bits
134 mov bx,10 ; Divisor is 10
135 div bx ; Divide
136 add dx,0x0c30 ; Convert remaining 0-9 to ASCII, also put color
137 xchg ax,dx
138 std
139 stosw
140 mov byte [di],0x20 ; Clean at least one character of prev. score
141 cld
142 xchg ax,dx
143 or ax,ax ; Score digits still remain?
144 jnz fb25 ; Yes, jump
145 fb24: mov ah,0x01 ; Any key pressed?
146 int 0x16
147 jz fb26 ; No, go to main loop
148 mov ah,0x00
149 int 0x16 ; Get key
150 dec ah ; Escape key?
151 jne fb4 ; No, jump
152 mov al,3
153 int 0x10
154 int 0x20 ; Exit to DOS or to oblivion (boot sector)
155 int 0x19
156 fb4: mov ax,[bird]
157 sub ax,0x10 ; Move bird two rows upward
158 cmp ax,0x08 ; Make sure the bird doesn't fly free outside screen
159 jb fb18
160 mov [bird],ax
161 fb18: mov byte [grav],0 ; Reset gravity
162 mov al,0xb6 ; Flap sound
163 out (0x43),al
164 mov al,0x90
165 out (0x42),al
166 mov al,0x4a
167 out (0x42),al
168 in al,(0x61)
169 or al,0x03 ; Turn on sound
170 out (0x61),al
171 fb26: jmp fb12
173 ;
174 ; Scroll scenery one column at a time
175 ;
176 scroll_scenery:
177 ;
178 ; Move whole screen
179 ;
180 mov si,0x00a2 ; Point to row 1, column 1 in SI
181 mov di,0x00a0 ; Point to row 1, column 0 in DI
182 fb2: mov cx,79 ; 79 columns
183 repz ; Scroll!!!
184 movsw
185 mov ax,0x0e20 ; Clean last character
186 stosw
187 lodsw ; Advance source to keep pair source/target
188 cmp si,0x0fa2 ; All scrolled?
189 jnz fb2 ; No, jump
190 ;
191 ; Insert houses
192 ;
193 mov word [0x0f9e],0x02df ; Terrain
194 in al,(0x40) ; Get "random" number
195 and al,0x70
196 jz fb5
197 mov bx,0x0408 ; House of one floor
198 mov [0x0efe],bx
199 mov di,0x0e5e
200 and al,0x20 ; Check "random" number
201 jz fb3
202 mov [di],bx ; House of two floors
203 sub di,0x00a0
204 fb3: mov word [di],0x091e ; Add roof
205 ;
206 ; Check if it's time to insert a column
207 ;
208 fb5: dec word [next] ; Decrease time (column really) for next pipe
209 mov bx,[next]
210 cmp bx,0x03 ; bx = 3,2,1,0 for the four columns making the pipe
211 ja fb6
212 jne fb8
213 in al,(0x40) ; Get "random" number
214 and ax,0x0007 ; Between 0 and 7
215 add al,0x04 ; Between 4 and 11
216 mov [tall],ax ; This will tell how tall the pipe is
217 fb8: mov cx,[tall]
218 or bx,bx ; Rightmost?
219 mov dl,0xb0
220 jz fb7 ; Yes, jump
221 mov dl,0xdb
222 cmp bx,0x03 ; Leftmost?
223 jb fb7 ; No, jump
224 mov dl,0xb1
225 fb7: mov di,0x013e ; Start from top of screen
226 mov ah,0x0a
227 mov al,dl
228 mov dx,0x009e
229 fb9: stosw
230 add di,dx
231 loop fb9
232 mov al,0xc4
233 stosw
234 add di,0x009e*6+10
235 mov al,0xdf
236 stosw
237 add di,dx
238 fb10: mov al,dl
239 stosw
240 add di,dx
241 cmp di,0x0f00
242 jb fb10
243 or bx,bx
244 jnz fb6
245 mov ax,[pipe]
246 inc ax ; Increase total pipes shown
247 mov [pipe],ax
248 mov cl,3
249 shr ax,cl
250 mov ah,0x50 ; Decrease distance between pipes
251 sub ah,al
252 cmp ah,0x10
253 ja fb11
254 mov ah,0x10
255 fb11: mov [next],ah ; Time for next pipe
256 fb6: ret
258 ;
259 ; Wait for a frame
260 ;
261 wait_frame:
263 mov bx, tick
264 fb14: hlt ; Wait for clock interrupt
265 mov ah,0x00 ; Use base clock tick
266 int 0x1a
267 cmp dx,[bx]
268 jz fb14
269 mov [bx],dx
270 inc word [bx+frame-tick] ; Increase frame count
271 in al,(0x61)
272 and al,0xfc ; Turn off sound
273 out (0x61),al
274 ret
276 times 507 - ($-$$) db 0 ; pad remaining 507 bytes with zeroes
278 db "OTG" ; 3 unused bytes
280 db 0x55,0xaa ; Bootable signature
282 pipe: equ 0x0fa0
283 score: equ 0x0fa2
284 grav: equ 0x0fa4
285 next: equ 0x0fa6
286 bird: equ 0x0fa8
287 frame: equ 0x0faa
288 tall: equ 0x0fac
289 tick: equ 0x0fae