wok-tiny rev 185

bootbricks, bootinvaders, bootmine, bootris: exit with ESC key and restart on end of game
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Oct 04 13:13:17 2023 +0000 (6 months ago)
parents 5d44015ce878
children 34a0a4406539
files bootbricks/stuff/bricks.asm bootinvaders/stuff/invaders.asm bootmine/stuff/mine.asm bootris/stuff/tetranglix.asm
line diff
     1.1 --- a/bootbricks/stuff/bricks.asm	Wed Sep 27 17:13:33 2023 +0000
     1.2 +++ b/bootbricks/stuff/bricks.asm	Wed Oct 04 13:13:17 2023 +0000
     1.3 @@ -104,7 +104,12 @@
     1.4  	cbw			; Eat key
     1.5  	int 0x16
     1.6  	cmp al,27		; ESC key ?
     1.7 -	je exit
     1.8 +	jnz .0
     1.9 +	call wait_frame.2	; Turn off sound
    1.10 +	mov ax,0x0003		; Text mode 80x25x16 colors
    1.11 +	int 0x10		; Setup
    1.12 +	int 0x20		; Exit to DOS / bootOS
    1.13 +	int 0x19
    1.14  .0:	
    1.15  	mov ah,0x02		; Read modifier keys
    1.16  	int 0x16
    1.17 @@ -241,16 +246,6 @@
    1.18  	jmp another_ball	; Start another ball
    1.19  
    1.20  .1:	call wait_frame.2	; Turn off sound
    1.21 -	stc
    1.22 -exit:
    1.23 -	pushf
    1.24 -	mov ax,0x0003		; Text mode 80x25x16 colors
    1.25 -	int 0x10		; Setup
    1.26 -	int 0x20		; Exit to DOS / bootOS
    1.27 -	popf
    1.28 -	jc .1
    1.29 -	int 0x19
    1.30 -.1:
    1.31  	jmp start
    1.32  
    1.33  wait_frame:
     2.1 --- a/bootinvaders/stuff/invaders.asm	Wed Sep 27 17:13:33 2023 +0000
     2.2 +++ b/bootinvaders/stuff/invaders.asm	Wed Oct 04 13:13:17 2023 +0000
     2.3 @@ -31,8 +31,8 @@
     2.4          ;                        Lock. Used the extra bytes to implement
     2.5          ;                        barriers that stop the invaders' bullets.
     2.6          ;                        (suggested in Reddit by nils-m-holm).
     2.7 -        ; Revision: Sep/13/2023. Fix bootsector end of game. Position
     2.8 -        ;                        independant code.
     2.9 +        ; Revision: Sep/13/2023. Fix bootsector end of game. To exit you 
    2.10 +        ;                        press ESC. Position independant code.
    2.11          ;
    2.12  
    2.13          cpu 8086
    2.14 @@ -68,11 +68,9 @@
    2.15          int 0x10        ; Call BIOS
    2.16          sti             ; Allow interrupts
    2.17          cld
    2.18 -        mov ax,0xa000   ; Point to screen memory
    2.19 -        mov ds,ax       ; Both DS...
    2.20 -        mov es,ax       ; ...and ES
    2.21 -        mov ah,0x04
    2.22 -        mov [level],ax  ; Level = 0, Lives = 4
    2.23 +        mov sp,0xa000   ; Point to screen memory
    2.24 +        mov ds,sp       ; Both DS...
    2.25 +        mov es,sp       ; ...and ES
    2.26          mov cx,level/2  ; Clear screen and variables (except level/lives)
    2.27          xor di,di
    2.28          mul di          ; Clear ax and dx
    2.29 @@ -82,10 +80,8 @@
    2.30          ;
    2.31          ; Setup descend state
    2.32          ;
    2.33 -        mov ax,[di]     ; al now contains level, ah contains lives
    2.34 -        inc ax          ; Increase by 2 (so invaders descend correctly)
    2.35 -        inc ax
    2.36 -        stosw           ; Advance level
    2.37 +        mov ax,0x0402   ; Level = 2 (so invaders descend correctly), Lives = 4
    2.38 +        stosw           ; Store level
    2.39          mov ah,al
    2.40          xchg ax,dx      ; Shouldn't damage DX starting here
    2.41  
    2.42 @@ -176,7 +172,6 @@
    2.43          and bp,7                ; Each 8 invaders
    2.44          push dx
    2.45          push si
    2.46 -        push bp
    2.47          mov si,shots                    ; Point to shots list
    2.48          jne in12
    2.49  in22:
    2.50 @@ -204,8 +199,7 @@
    2.51          jc in30                         ; No, jump
    2.52          push si
    2.53          push di
    2.54 -        mov ah,SPRITE_SIZE              ; The pixel indicates the...
    2.55 -        mul ah                          ; ...invader hit.
    2.56 +        mul cl                          ; The pixel indicates the...invader hit. (SPRITE_SIZE=4)
    2.57          add si,ax
    2.58          lodsw
    2.59          xchg ax,di
    2.60 @@ -259,16 +253,40 @@
    2.61          jne in42                        ; Finished? No, jump
    2.62          mov ah,SPACESHIP_COLOR          ; Restore color (sprite already)
    2.63          dec byte [si-2-sprites+lives]   ; Remove one life
    2.64 -        js in10                         ; Exit if all used
    2.65 +        js restart                      ; Exit if all used
    2.66  in42:   mov [si-2],ax                   ; Save new frame / color
    2.67          mov di,[si]                     ; Load position
    2.68          call draw_sprite                ; Draw sprite (spaceship)
    2.69          jne in43                        ; Jump if still explosion
    2.70  
    2.71 -        mov ah,0x02                     ; BIOS Get Keyboard Flags 
    2.72 +%ifdef USE_ARROW_KEYS
    2.73 +        mov ah,0x01
    2.74 +        int 0x16                        ; BIOS Got key
    2.75 +        jz in35                         ; No, jump
    2.76 +        mov ah,0x00
    2.77 +        int 0x16                        ; BIOS Get key
    2.78 +        dec ah                          ; Escape key ?
    2.79 +        je in10
    2.80 +        cmp ah,0x4d-1                   ; Left arrow key ?
    2.81 +        jnz in17a
    2.82 +        inc di                          ; Move 2 pixels to left
    2.83 +        inc di
    2.84 +in17a:  cmp ah,0x4b-1                   ; Right arrow key ?
    2.85 +        jnz in17b
    2.86 +        dec di                          ; Move 2 pixels to right
    2.87 +        dec di
    2.88 +in17b:  cmp al,0x20                     ; Space key ?
    2.89 +        jne in35                        ; No, jump
    2.90 +%else
    2.91 +        mov ah,0x01
    2.92 +        int 0x16                        ; BIOS Got key
    2.93 +        jz in17a                        ; No, jump
    2.94 +        mov ah,0x00
    2.95 +        int 0x16                        ; BIOS Get key
    2.96 +        dec ah                          ; Escape key ?
    2.97 +        je in10
    2.98 +in17a:  mov ah,0x02                     ; BIOS Get Keyboard Flags 
    2.99          int 0x16
   2.100 -        test al,0x10                    ; Test for Scroll Lock and exit
   2.101 -        jnz in10
   2.102  
   2.103          mov bx,12                       ; Ctrl/Alt key?
   2.104          and bl,al
   2.105 @@ -277,7 +295,8 @@
   2.106  in17:
   2.107          test al,0x03                    ; Shift keys?
   2.108          jz in35                         ; No, jump
   2.109 -        cmp word [shots],bx             ; Bullet available?
   2.110 +%endif
   2.111 +        cmp word [si-2-sprites+shots],bx ; Bullet available?
   2.112          ja in35                         ; No, jump
   2.113          lea ax,[di+(0x04*2)]            ; Offset from spaceship
   2.114          mov [shots],ax                  ; Start bullet
   2.115 @@ -289,7 +308,6 @@
   2.116          je in43
   2.117  in19:   mov [si],ax                     ; Update position
   2.118  in43:
   2.119 -        pop bp
   2.120          pop si
   2.121          pop dx
   2.122  
   2.123 @@ -300,11 +318,13 @@
   2.124          add ax,0x0280           ; Go down by 2 pixels
   2.125          cmp ax,0x55*0x280       ; Reaches Earth?
   2.126          jc in8                  ; No, jump
   2.127 +restart:
   2.128 +        jmp restart_game
   2.129  in10:
   2.130 -        mov ax,0x0003           ; Restore text mode
   2.131 +        mov al,0x03             ; Restore text mode
   2.132          int 0x10
   2.133          int 0x20                ; Exit to DOS
   2.134 -        jmp restart_game
   2.135 +        int 0x19                ; or reboot
   2.136  
   2.137  in9:    dec ax                  ; Moving to left
   2.138          dec ax
     3.1 --- a/bootmine/stuff/mine.asm	Wed Sep 27 17:13:33 2023 +0000
     3.2 +++ b/bootmine/stuff/mine.asm	Wed Oct 04 13:13:17 2023 +0000
     3.3 @@ -4,6 +4,7 @@
     3.4  %define CGA_DISPLAY
     3.5  %define DOS_QUIT
     3.6  %define FAT_BOOT
     3.7 +%define RESTART_ON_ANY_KEY
     3.8  
     3.9  cpu 8086
    3.10  
    3.11 @@ -324,8 +325,6 @@
    3.12    db 'GAME WIN'
    3.13  
    3.14  ;; Wait for restart key to be pressed, then restart game
    3.15 -WaitRestartLoop:
    3.16 -  je RunGame
    3.17  WaitRestart:
    3.18    xor ax, ax
    3.19    int 0x16
    3.20 @@ -339,8 +338,11 @@
    3.21    int 0x19
    3.22  .notQuit:
    3.23  %endif
    3.24 +%ifndef RESTART_ON_ANY_KEY
    3.25    cmp al, Key.Ascii.RestartGame
    3.26 -  jmp WaitRestartLoop
    3.27 +  jne WaitRestart
    3.28 +%endif
    3.29 +  jmp RunGame
    3.30  
    3.31  ;; Array of adjacent cell offsets. A byte in this array can be added to a text
    3.32  ;; buffer cell pointer to get the pointer to an adjacent cell. This is used for
     4.1 --- a/bootris/stuff/tetranglix.asm	Wed Sep 27 17:13:33 2023 +0000
     4.2 +++ b/bootris/stuff/tetranglix.asm	Wed Oct 04 13:13:17 2023 +0000
     4.3 @@ -91,7 +91,7 @@
     4.4  
     4.5      ; Calculate first index into screen.
     4.6      lodsw
     4.7 -    aad 0x10
     4.8 +    aad 0x10	; al = al + 16*ah, ah = 0
     4.9  
    4.10      mov cl, 0x10
    4.11  
    4.12 @@ -153,7 +153,7 @@
    4.13      ret
    4.14  
    4.15  exit_game_over:
    4.16 -    je start
    4.17 +    jne start
    4.18  exit_dos:
    4.19      mov al,0x03           ; Clear screen
    4.20      int 0x10