wok-tiny diff bootbricks/stuff/bricks.asm @ rev 186

Add bootlife
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Feb 04 18:02:38 2024 +0000 (3 months ago)
parents 61c76233911e
children
line diff
     1.1 --- a/bootbricks/stuff/bricks.asm	Wed Oct 04 13:13:17 2023 +0000
     1.2 +++ b/bootbricks/stuff/bricks.asm	Sun Feb 04 18:02:38 2024 +0000
     1.3 @@ -14,32 +14,52 @@
     1.4  	; Press Left Alt to move the paddle to the right
     1.5  	;
     1.6  
     1.7 -old_time:	equ 16	; Old time 
     1.8 +old_time:	equ 16	; word: Old time 
     1.9  ball_x:		equ 14	; X-coordinate of ball (8.8 fraction)
    1.10  ball_y:		equ 12	; Y-coordinate of ball (8.8 fraction)
    1.11  ball_xs:	equ 10	; X-speed of ball (8.8 fraction)
    1.12  ball_ys:	equ 8	; Y-speed of ball (8.8 fraction)
    1.13 -beep:		equ 6	; Frame count to turn off sound
    1.14 -bricks:		equ 4	; Remaining bricks
    1.15 -score:         equ 2	; Current score
    1.16 -balls:         equ 0	; Remaining balls
    1.17 +beep:		equ 6	; byte: Frame count to turn off sound
    1.18 +bricks:		equ 4	; word: Remaining bricks
    1.19 +score:   	equ 2	; word: Current score
    1.20 +balls:    	equ 0	; byte: Remaining balls
    1.21 +
    1.22 +%define MDA_SUPPORT
    1.23  
    1.24  	;
    1.25  	; Start of the game
    1.26  	;
    1.27  start:
    1.28 +	cld
    1.29  	sti			; Allow interrupts
    1.30 -	mov ax,0xb800		; Address of video screen
    1.31 -	mov ds,ax		; Setup DS
    1.32 -	mov es,ax		; Setup ES
    1.33 -	sub sp,32
    1.34 -	cbw
    1.35 +        push cs
    1.36 +        pop ss
    1.37 +	mov sp,0xb800		; Address of video screen
    1.38 +.set_segments:
    1.39 +	mov ds,sp		; Setup DS
    1.40 +	mov es,sp		; Setup ES
    1.41 +%ifdef MDA_SUPPORT
    1.42 +	xor di,di
    1.43 +	mov sp,0xb000		; Address of video screen
    1.44 +	inc word [di]
    1.45 +	jz .set_segments
    1.46 +	xchg ax,di
    1.47 +%else
    1.48 +	xor ax,ax
    1.49 +%endif
    1.50  	push ax			; Reset score
    1.51  	mov al,4		
    1.52  	push ax			; Balls remaining
    1.53  	mov bp,sp		; Setup stack frame for globals
    1.54  	mov al,0x02		; Text mode 80x25x16 colors
    1.55  	int 0x10		; Setup
    1.56 +%if 0
    1.57 +        ; Disable VGA text mode cursor
    1.58 +        ; https://wiki.osdev.org/Text_Mode_Cursor#Disabling_the_Cursor
    1.59 +        mov ah, 0x01
    1.60 +        mov ch, 0x3f
    1.61 +        int 0x10
    1.62 +%endif
    1.63  	;
    1.64  	; Start another level 
    1.65  	;
    1.66 @@ -48,7 +68,6 @@
    1.67  	xor di,di
    1.68  	mov ax,0x01b1		; Draw top border
    1.69  	mov cx,80
    1.70 -	cld
    1.71  	rep stosw
    1.72  	mov cl,24		; 24 rows
    1.73  .1:
    1.74 @@ -64,13 +83,17 @@
    1.75  .2:
    1.76  	mov cl,39		; 39 bricks per row
    1.77  .3:
    1.78 +	test ah,0x07
    1.79 +	jne .4
    1.80 +%ifdef MDA_SUPPORT
    1.81 +	mov ah,0x02
    1.82 +%else
    1.83 +	mov ah,0x01
    1.84 +%endif
    1.85 +.4:
    1.86  	stosw
    1.87  	stosw
    1.88  	inc ah			; Increase attribute color
    1.89 -	cmp ah,0x08
    1.90 -	jne .4
    1.91 -	mov ah,0x01
    1.92 -.4:
    1.93  	loop .3
    1.94  	pop cx
    1.95  
    1.96 @@ -85,9 +108,8 @@
    1.97  another_ball:
    1.98  	mov byte [bp+ball_x+1],0x28	; Center X
    1.99  	mov byte [bp+ball_y+1],0x14	; Center Y
   1.100 -	xor ax,ax
   1.101 -	mov [bp+ball_xs],ax	; Static on screen
   1.102 -	mov [bp+ball_ys],ax
   1.103 +	and word [bp+ball_xs],0	; Static on screen
   1.104 +	and word [bp+ball_ys],0
   1.105  	mov byte [bp+beep],0x01
   1.106  
   1.107  	mov si,0x0ffe		; Don't erase ball yet
   1.108 @@ -172,7 +194,7 @@
   1.109  	mov al,[bx]
   1.110  	cmp al,0xb1		; Touching borders
   1.111  	jne .3
   1.112 -	mov cx,5423		; 1193180 / 220
   1.113 +	mov cl,5423/256		; 1193180 / 220
   1.114  	call speaker		; Generate sound
   1.115  	pop bx
   1.116  	pop ax
   1.117 @@ -197,30 +219,29 @@
   1.118  	shl bx,cl
   1.119  	mov [bp+ball_xs],bx	; New X speed for ball
   1.120  	mov word [bp+ball_ys],0xff80	; Update Y speed for ball
   1.121 -	mov cx,2711		; 1193180 / 440
   1.122 +	mov cl,2711/256		; 1193180 / 440
   1.123  	call speaker		; Generate sound
   1.124 -	pop bx
   1.125 +.16:	pop bx
   1.126  	pop ax
   1.127  	jmp .14
   1.128  
   1.129  .4:
   1.130  	cmp al,0xdb		; Touching brick
   1.131  	jne .5
   1.132 -	mov cx,1355		; 1193180 / 880
   1.133 +	mov cl,1355/256		; 1193180 / 880
   1.134  	call speaker		; Generate sound
   1.135  	test bl,2		; Aligned with brick?
   1.136  	jne .10			; Yes, jump
   1.137  	dec bx			; Align
   1.138  	dec bx
   1.139 -.10:	xor ax,ax		; Erase brick
   1.140 -	mov [bx],ax
   1.141 -	mov [bx+2],ax
   1.142 +.10:	and word [bx],0		; Erase brick
   1.143 +	and word [bx+2],0
   1.144  	inc word [bp+score]	; Increase score
   1.145  	neg word [bp+ball_ys]	; Negate Y speed (rebound)
   1.146 +	dec word [bp+bricks]	; One brick less on screen
   1.147 +	jne .16			; Fully completed? No, jump.
   1.148  	pop bx
   1.149  	pop ax
   1.150 -	dec word [bp+bricks]	; One brick less on screen
   1.151 -	jne .14			; Fully completed? No, jump.
   1.152  	jmp another_level	; Start another level
   1.153  
   1.154  .5:
   1.155 @@ -237,7 +258,7 @@
   1.156  	; Ball lost
   1.157  	; 
   1.158  ball_lost:
   1.159 -	mov cx,10846		; 1193180 / 110
   1.160 +	mov cl,10846/256	; 1193180 / 110
   1.161  	call speaker		; Generate sound
   1.162  
   1.163  	and word [si],0		; Erase ball
   1.164 @@ -257,31 +278,27 @@
   1.165  	je .0
   1.166  	mov [bp+old_time],dx
   1.167  
   1.168 -	dec byte [bp+beep]		; Decrease time to turn off beep
   1.169 -	jne .1
   1.170 +	dec byte [bp+beep]	; Decrease time to turn off beep
   1.171 +	jne speaker.2
   1.172  .2:
   1.173  	in al,0x61
   1.174  	and al,0xfc		; Turn off
   1.175 -	out 0x61,al
   1.176 -.1:
   1.177 -
   1.178 -	ret
   1.179 +	jmp speaker.1
   1.180  
   1.181  	;
   1.182  	; Generate sound on PC speaker
   1.183  	;
   1.184  speaker:
   1.185 +	mov byte [bp+beep],3	; Duration
   1.186  	mov al,0xb6		; Setup timer 2
   1.187  	out 0x43,al
   1.188 -	mov al,cl		; Low byte of timer count
   1.189 -	out 0x42,al
   1.190 -	mov al,ch		; High byte of timer count
   1.191 +	out 0x42,al		; Low byte of timer count
   1.192 +	xchg ax,cx		; High byte of timer count
   1.193  	out 0x42,al
   1.194  	in al,0x61
   1.195  	or al,0x03		; Connect PC speaker to timer 2
   1.196 -	out 0x61,al
   1.197 -	mov byte [bp+beep],3	; Duration
   1.198 -	ret
   1.199 +.1:	out 0x61,al
   1.200 +.2:	ret
   1.201  
   1.202  	;
   1.203  	; Locate ball on screen
   1.204 @@ -291,7 +308,7 @@
   1.205  	mul ah			; AH = Y coordinate (row)
   1.206  	mov bl,bh		; BH = X coordinate (column)
   1.207  	mov bh,0
   1.208 -	shl bx,1
   1.209 +	add bx,bx
   1.210  	add bx,ax
   1.211  	ret
   1.212