wok-tiny view bootbricks/stuff/bricks.asm @ rev 180

Add boot-man, bootbricks, bootfbird, bootinvaders, bootmine, bootpillman, bootris, bootsokoban
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Sep 20 13:08:44 2023 +0000 (12 months ago)
parents
children bbb34fe4904d
line source
1 ;
2 ; Bricks game in one boot sector
3 ;
4 ; by Oscar Toledo G.
5 ;
6 ; Creation date: Nov/02/2019.
7 ;
9 cpu 8086
11 ;
12 ; Press Left Shift to start the game
13 ; Press Left Ctrl to move the paddle to the left
14 ; Press Left Alt to move the paddle to the right
15 ;
17 old_time: equ 16 ; Old time
18 ball_x: equ 14 ; X-coordinate of ball (8.8 fraction)
19 ball_y: equ 12 ; Y-coordinate of ball (8.8 fraction)
20 ball_xs: equ 10 ; X-speed of ball (8.8 fraction)
21 ball_ys: equ 8 ; Y-speed of ball (8.8 fraction)
22 beep: equ 6 ; Frame count to turn off sound
23 bricks: equ 4 ; Remaining bricks
24 score: equ 2 ; Current score
25 balls: equ 0 ; Remaining balls
27 ;
28 ; Start of the game
29 ;
30 start:
31 mov ax,0x0002 ; Text mode 80x25x16 colors
32 int 0x10 ; Setup
33 mov ax,0xb800 ; Address of video screen
34 mov ds,ax ; Setup DS
35 mov es,ax ; Setup ES
36 sub sp,32
37 xor ax,ax
38 push ax ; Reset score
39 mov al,4
40 push ax ; Balls remaining
41 mov bp,sp ; Setup stack frame for globals
42 ;
43 ; Start another level
44 ;
45 another_level:
46 mov word [bp+bricks],273 ; 273 bricks on screen
47 xor di,di
48 mov ax,0x01b1 ; Draw top border
49 mov cx,80
50 cld
51 rep stosw
52 mov cl,24 ; 24 rows
53 .1:
54 stosw ; Draw left border
55 mov ax,0x20 ; No bricks on this row
56 push cx
57 cmp cl,23
58 jnb .2
59 sub cl,15
60 jbe .2
61 mov al,0xdb ; Bricks on this row
62 mov ah,cl
63 .2:
64 mov cl,39 ; 39 bricks per row
65 .3:
66 stosw
67 stosw
68 inc ah ; Increase attribute color
69 cmp ah,0x08
70 jne .4
71 mov ah,0x01
72 .4:
73 loop .3
74 pop cx
76 mov ax,0x01b1 ; Draw right border
77 stosw
78 loop .1
80 ;
81 ; Start another ball
82 ;
83 mov di,0x0f4a ; Position of paddle
84 another_ball:
85 mov byte [bp+ball_x+1],0x28 ; Center X
86 mov byte [bp+ball_y+1],0x14 ; Center Y
87 xor ax,ax
88 mov [bp+ball_xs],ax ; Static on screen
89 mov [bp+ball_ys],ax
90 mov byte [bp+beep],0x01
92 mov si,0x0ffe ; Don't erase ball yet
93 game_loop:
94 call wait_frame ; Wait 1/18.2 secs.
96 mov word [si],0x0000 ; Erase ball
98 call update_score ; Update score
100 mov ah,0x02 ; Read modifier keys
101 int 0x16
102 test al,0x04 ; Left ctrl
103 je .1
104 mov byte [di+6],0 ; Erase right side of paddle
105 mov byte [di+8],0
106 sub di,byte 4 ; Move paddle to left
107 cmp di,0x0f02 ; Limit
108 ja .1
109 mov di,0x0f02
110 .1:
111 test al,0x08 ; Left alt
112 je .2
113 xor ax,ax ; Erase left side of paddle
114 stosw
115 stosw ; DI increased automatically
116 cmp di,0x0f94 ; Limit
117 jb .2
118 mov di,0x0f94
119 .2:
120 test al,0x02 ; Left shift
121 je .15
122 mov ax,[bp+ball_xs] ; Ball moving?
123 add ax,[bp+ball_ys]
124 jne .15 ; Yes, jump
125 ; Setup movement of ball
126 mov word [bp+ball_xs],0xff40
127 mov word [bp+ball_ys],0xff80
128 .15:
129 mov ax,0x0adf ; Paddle graphic and color
130 push di
131 stosw ; Draw paddle
132 stosw
133 stosw
134 stosw
135 stosw
136 pop di
138 mov bx,[bp+ball_x] ; Draw ball
139 mov ax,[bp+ball_y]
140 call locate_ball ; Locate on screen
141 test byte [bp+ball_y],0x80 ; Y-coordinate half fraction?
142 mov ah,0x60 ; Interchange colors for smooth mov.
143 je .12
144 mov ah,0x06
145 .12: mov al,0xdc ; Graphic
146 mov [bx],ax ; Draw
147 push bx
148 pop si
150 .14:
151 mov bx,[bp+ball_x] ; Ball position
152 mov ax,[bp+ball_y]
153 add bx,[bp+ball_xs] ; Add movement speed
154 add ax,[bp+ball_ys]
155 push ax
156 push bx
157 call locate_ball ; Locate on screen
158 mov al,[bx]
159 cmp al,0xb1 ; Touching borders
160 jne .3
161 mov cx,5423 ; 1193180 / 220
162 call speaker ; Generate sound
163 pop bx
164 pop ax
165 cmp bh,0x4f
166 je .8
167 test bh,bh
168 jne .7
169 .8:
170 neg word [bp+ball_xs] ; Negate X-speed if it touches a side
171 .7:
172 test ah,ah
173 jnz .9
174 neg word [bp+ball_ys] ; Negate Y-speed if it touches a side
175 .9: jmp .14
177 .3:
178 cmp al,0xdf ; Touching paddle
179 jne .4
180 sub bx,di ; Subtract paddle position
181 sub bx,byte 4
182 mov cl,6 ; Multiply by 64
183 shl bx,cl
184 mov [bp+ball_xs],bx ; New X speed for ball
185 mov word [bp+ball_ys],0xff80 ; Update Y speed for ball
186 mov cx,2711 ; 1193180 / 440
187 call speaker ; Generate sound
188 pop bx
189 pop ax
190 jmp .14
192 .4:
193 cmp al,0xdb ; Touching brick
194 jne .5
195 mov cx,1355 ; 1193180 / 880
196 call speaker ; Generate sound
197 test bl,2 ; Aligned with brick?
198 jne .10 ; Yes, jump
199 dec bx ; Align
200 dec bx
201 .10: xor ax,ax ; Erase brick
202 mov [bx],ax
203 mov [bx+2],ax
204 inc word [bp+score] ; Increase score
205 neg word [bp+ball_ys] ; Negate Y speed (rebound)
206 pop bx
207 pop ax
208 dec word [bp+bricks] ; One brick less on screen
209 jne .14 ; Fully completed? No, jump.
210 jmp another_level ; Start another level
212 .5:
213 pop bx
214 pop ax
215 .6:
216 mov [bp+ball_x],bx ; Update ball position
217 mov [bp+ball_y],ax
218 cmp ah,0x19 ; Ball exited through bottom?
219 je ball_lost ; Yes, jump
220 jmp game_loop ; No, repeat game loop
222 ;
223 ; Ball lost
224 ;
225 ball_lost:
226 mov cx,10846 ; 1193180 / 110
227 call speaker ; Generate sound
229 mov word [si],0 ; Erase ball
230 dec byte [bp+balls] ; One ball less
231 js .1 ; All finished? Yes, jump
232 jmp another_ball ; Start another ball
234 .1: call wait_frame.2 ; Turn off sound
235 exit:
236 mov ax,0x0003 ; Text mode 80x25x16 colors
237 int 0x10 ; Setup
238 int 0x20 ; Exit to DOS / bootOS
239 jmp start
241 wait_frame:
242 .0:
243 mov ah,0x00 ; Read ticks
244 int 0x1a ; Call BIOS
245 cmp dx,[bp+old_time] ; Wait for change
246 je .0
247 mov [bp+old_time],dx
249 dec byte [bp+beep] ; Decrease time to turn off beep
250 jne .1
251 .2:
252 in al,0x61
253 and al,0xfc ; Turn off
254 out 0x61,al
255 .1:
257 ret
259 ;
260 ; Generate sound on PC speaker
261 ;
262 speaker:
263 mov al,0xb6 ; Setup timer 2
264 out 0x43,al
265 mov al,cl ; Low byte of timer count
266 out 0x42,al
267 mov al,ch ; High byte of timer count
268 out 0x42,al
269 in al,0x61
270 or al,0x03 ; Connect PC speaker to timer 2
271 out 0x61,al
272 mov byte [bp+beep],3 ; Duration
273 ret
275 ;
276 ; Locate ball on screen
277 ;
278 locate_ball:
279 mov al,0xa0
280 mul ah ; AH = Y coordinate (row)
281 mov bl,bh ; BH = X coordinate (column)
282 mov bh,0
283 shl bx,1
284 add bx,ax
285 ret
287 ;
288 ; Update score indicator (from bootRogue)
289 ;
290 update_score:
291 mov bx,0x0f98 ; Point to bottom right corner
292 mov ax,[bp+score]
293 call .1
294 mov al,[bp+balls]
295 .1:
296 xor cx,cx ; CX = Quotient
297 .2: inc cx
298 sub ax,10 ; Division by subtraction
299 jnc .2
300 add ax,0x0a3a ; Convert remainder to ASCII digit + color
301 call .3 ; Put on screen
302 xchg ax,cx
303 dec ax ; Quotient is zero?
304 jnz .1 ; No, jump to show more digits.
306 .3: mov [bx],ax
307 dec bx
308 dec bx
309 ret
311 times 510-($-$$) db 0x4f
312 db 0x55,0xaa ; Make it a bootable sector