wok-tiny diff bootsokoban/stuff/sokoban.asm @ rev 182

Update bootpillman & bootsokoban
author Pascal Bellard <pascal.bellard@slitaz.org>
date Sun Sep 24 17:53:05 2023 +0000 (8 months ago)
parents e05af9592e8b
children 1e55ea7da8de
line diff
     1.1 --- a/bootsokoban/stuff/sokoban.asm	Wed Sep 20 13:08:44 2023 +0000
     1.2 +++ b/bootsokoban/stuff/sokoban.asm	Sun Sep 24 17:53:05 2023 +0000
     1.3 @@ -5,9 +5,13 @@
     1.4  %define CURRENT_LEVEL_4 0x7E04
     1.5  %define SCREEN_DS 0xb800
     1.6  
     1.7 +%define MOVE_COUNT
     1.8 +
     1.9  boot:
    1.10      ; clear screen (re-set text mode)
    1.11 -    mov ax, 0x0003  ; text mode 80x25 16 colours
    1.12 +    mov ax, 0x0001  ; text mode 40x25 16 colours
    1.13 +%define COLS  40
    1.14 +%define LINES 25
    1.15      int 0x10
    1.16  
    1.17      ; disable cursor
    1.18 @@ -37,60 +41,61 @@
    1.19  ;  0000 1000 PLAYER
    1.20  ;  0000 1001 PLAYER ON SPOT
    1.21  test_level:
    1.22 -    ; this was the original level format, which was quite big:
    1.23  
    1.24 -    ; db 9, 7 ; width, height
    1.25 -    ; dw 32 ; playerxy
    1.26 -    ; db 4,4,4,4,4,4,0,0,0
    1.27 -    ; db 4,0,0,0,0,4,0,0,0
    1.28 -    ; db 4,0,0,2,0,4,4,0,0
    1.29 -    ; db 4,0,2,4,1,9,4,4,4
    1.30 -    ; db 4,4,0,0,3,1,2,0,4
    1.31 -    ; db 0,4,0,0,0,0,0,0,4
    1.32 -    ; db 0,4,4,4,4,4,4,4,4
    1.33 -    ; db 14, 10 ;width, height
    1.34 -    ; dw 63     ;playerxy
    1.35 +%define p(a,b,c) ((c&7)+((b&7)*6)+((a&7)*6*6))
    1.36 +%if 1
    1.37 +    db 15, 14 ;width, height
    1.38 +    dw 15*7+13     ;playerxy
    1.39 +%define PLAYER 9
    1.40 +    db p(4,4,4), p(4,5,5), p(5,5,5), p(4,4,4), p(4,5,5)
    1.41 +    db p(4,0,0), p(4,4,4), p(4,4,4), p(4,1,1), p(4,4,4)
    1.42 +    db p(4,0,2), p(0,2,0), p(2,0,0), p(4,1,1), p(1,1,4)
    1.43 +    db p(4,0,2), p(0,0,0), p(2,2,0), p(4,3,3), p(3,1,4)
    1.44 +    db p(4,0,2), p(0,2,0), p(2,0,0), p(4,1,1), p(3,1,4)
    1.45 +    db p(4,0,0), p(2,0,2), p(0,2,0), p(4,3,1), p(3,1,4)
    1.46 +    db p(4,4,0), p(2,0,2), p(0,2,0), p(1,3,1), p(3,1,4)
    1.47 +    db p(4,0,0), p(2,0,2), p(0,2,0), p(1,3,1), p(3,PLAYER,4)
    1.48 +    db p(4,0,0), p(2,0,2), p(0,2,0), p(4,3,1), p(3,1,4)
    1.49 +    db p(4,0,2), p(0,2,0), p(2,0,0), p(4,1,1), p(3,1,4)
    1.50 +    db p(4,0,2), p(0,0,0), p(2,2,0), p(4,3,3), p(3,1,4)
    1.51 +    db p(4,0,2), p(0,2,0), p(2,0,0), p(4,1,1), p(1,1,4)
    1.52 +    db p(4,0,0), p(4,4,4), p(4,4,4), p(4,1,1), p(4,4,4)
    1.53 +    db p(4,4,4), p(4,5,5), p(5,5,5), p(4,4,4), p(4,5,5)
    1.54 +%else
    1.55 +    db 21, 18 ;width, height
    1.56 +    dw 21+8     ;playerxy
    1.57 +%define PLAYER 8
    1.58 +    db p(5,5,5), p(5,5,5), p(5,4,4), p(4,5,5), p(5,5,5), p(5,5,5), p(5,5,5)
    1.59 +    db p(5,5,4), p(4,4,4), p(4,0,8), p(0,4,4), p(4,4,4), p(4,4,5), p(5,5,5)
    1.60 +    db p(5,5,4), p(0,0,0), p(4,0,2), p(0,4,0), p(0,0,0), p(0,4,4), p(5,5,5)
    1.61 +    db p(5,4,4), p(0,2,0), p(4,4,0), p(0,4,2), p(0,0,0), p(0,0,4), p(4,5,5)
    1.62 +    db p(5,4,0), p(2,0,2), p(0,4,0), p(0,4,0), p(2,4,4), p(0,2,0), p(4,5,5)
    1.63 +    db p(4,4,0), p(3,1,1), p(0,4,4), p(0,4,2), p(0,4,4), p(2,0,0), p(4,5,5)
    1.64 +    db p(4,0,2), p(1,1,3), p(0,0,4), p(0,4,0), p(2,0,0), p(0,0,4), p(4,5,5)
    1.65 +    db p(4,0,3), p(2,4,2), p(3,0,4), p(2,0,0), p(0,2,0), p(0,4,4), p(5,5,5)
    1.66 +    db p(4,1,1), p(0,4,0), p(1,1,4), p(0,0,4), p(4,4,2), p(4,4,5), p(5,5,5)
    1.67 +    db p(4,0,4), p(4,4,4), p(4,0,4), p(0,2,0), p(0,2,0), p(0,4,4), p(5,5,5)
    1.68 +    db p(4,0,2), p(0,4,0), p(2,0,0), p(2,0,2), p(0,2,0), p(2,0,4), p(4,5,5)
    1.69 +    db p(4,0,1), p(1,4,1), p(1,0,2), p(0,4,0), p(0,0,2), p(0,2,0), p(4,5,5)
    1.70 +    db p(4,0,1), p(1,2,1), p(1,0,4), p(0,4,0), p(2,4,4), p(0,0,0), p(4,5,5)
    1.71 +    db p(4,0,1), p(1,1,1), p(1,2,4), p(0,4,0), p(0,0,0), p(0,2,0), p(4,5,5)
    1.72 +    db p(4,0,1), p(1,1,1), p(1,0,4), p(0,4,2), p(2,2,0), p(2,0,4), p(4,5,5)
    1.73 +    db p(4,0,1), p(1,1,1), p(1,2,4), p(0,4,0), p(0,0,0), p(0,4,4), p(5,5,5)
    1.74 +    db p(4,0,1), p(1,1,1), p(1,0,4), p(0,4,4), p(4,4,4), p(4,4,5), p(5,5,5)
    1.75 +    db p(5,4,4), p(4,4,4), p(4,4,5), p(4,5,5), p(5,5,5), p(5,5,5), p(5,5,5)
    1.76 +%endif
    1.77  
    1.78 -    ; when i tried to put in THIS level (from https://www.youtube.com/watch?v=fg8QImlvB-k)
    1.79 -    ; i passed the 512 byte limit...
    1.80  
    1.81 -    ; db 4,4,4,4,4,4,4,4,4,4,4,4,0,0
    1.82 -    ; db 4,1,1,0,0,4,0,0,0,0,0,4,4,4
    1.83 -    ; db 4,1,1,0,0,4,0,2,0,0,2,0,0,4
    1.84 -    ; db 4,1,1,0,0,4,2,4,4,4,4,0,0,4
    1.85 -    ; db 4,1,1,0,0,0,0,8,0,4,4,0,0,4
    1.86 -    ; db 4,1,1,0,0,4,0,4,0,0,2,0,4,4
    1.87 -    ; db 4,4,4,4,4,4,0,4,4,2,0,2,0,4
    1.88 -    ; db 0,0,4,0,2,0,0,2,0,2,0,2,0,4
    1.89 -    ; db 0,0,4,0,0,0,0,4,0,0,0,0,0,4
    1.90 -    ; db 0,0,4,4,4,4,4,4,4,4,4,4,4,4
    1.91 -
    1.92 -    ; so i compressed it! high nybble first, low nybble second
    1.93 -    db 14, 10 ;width, height
    1.94 -    dw 63     ;playerxy
    1.95 -    db 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x00
    1.96 -    db 0x41, 0x10, 0x04, 0x00, 0x00, 0x04, 0x44
    1.97 -    db 0x41, 0x10, 0x04, 0x02, 0x00, 0x20, 0x04
    1.98 -    db 0x41, 0x10, 0x04, 0x24, 0x44, 0x40, 0x04
    1.99 -    db 0x41, 0x10, 0x00, 0x08, 0x04, 0x40, 0x04
   1.100 -    db 0x41, 0x10, 0x04, 0x04, 0x00, 0x20, 0x44
   1.101 -    db 0x44, 0x44, 0x44, 0x04, 0x42, 0x02, 0x04
   1.102 -    db 0x00, 0x40, 0x20, 0x02, 0x02, 0x02, 0x04
   1.103 -    db 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x04
   1.104 -    db 0x00, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44
   1.105 -
   1.106 -
   1.107 -
   1.108 -display_chars: db 0,   0x07 ; blank
   1.109 -               db 249, 0x07 ; spot
   1.110 -               db 4,   0x0C ; brick
   1.111 -               db 4,   0x0A ; brick on spot
   1.112 -               db 178, 0x71 ; wall
   1.113 -               db "5", 0x07 ; (no 5)
   1.114 -               db "6", 0x07 ; (no 6)
   1.115 -               db "7", 0x07 ; (no 7)
   1.116 -               db 1,   0x0F ; player
   1.117 -               db 1,   0x0F ; player on spot
   1.118 +display_chars: db 0,    0x07 ; blank
   1.119 +               db 249,  0x07 ; spot
   1.120 +               db 0xFE, 0x0A ; brick
   1.121 +               db 0xFE, 0x0C ; brick on spot
   1.122 +               db 176,  0x71 ; wall
   1.123 +               db 0,    0x07 ; out blank 
   1.124 +               db "6",  0x07 ; (no 6)
   1.125 +               db "7",  0x07 ; (no 7)
   1.126 +               db 1,    0x0F ; player
   1.127 +               db 1,    0x0F ; player on spot
   1.128  
   1.129  str_you_win: db 'YOU WIN! ',1,1,1,0
   1.130  
   1.131 @@ -101,38 +106,38 @@
   1.132      mov si, bp
   1.133  
   1.134      ; get width and height and multiply by each other
   1.135 -    mov ax, [cs:si]
   1.136 +    lodsw
   1.137 +
   1.138 +    mov di, CURRENT_LEVEL ; next address to copy to
   1.139 +
   1.140 +    ; copy map size and player position ("uncompressed")
   1.141 +    stosw
   1.142      mul ah
   1.143  
   1.144      ; set multiplied width and height + 4 as counter
   1.145      mov cx, ax
   1.146      ;add cx, 4
   1.147  
   1.148 -    mov di, CURRENT_LEVEL ; next address to copy to
   1.149 +    lodsw
   1.150 +    stosw
   1.151  
   1.152 -    ; copy map size and player position ("uncompressed")
   1.153 -    cs movsw
   1.154 -    cs movsw
   1.155 +    xchg ax,bx
   1.156 +    add bx,di		;save player location
   1.157 +    mov dx,36*256+6
   1.158  
   1.159  .copy_level_loop:
   1.160 -    ; load "compressed" byte: e.g. 0x28 or 0x44 into AL
   1.161 -    cs lodsb
   1.162 -%if 0
   1.163 -    aam 16
   1.164 -    xchg al, ah
   1.165 -%else
   1.166 -    mov ah, al     ; AX = 0x2828
   1.167 -    and ax, 0x0FF0 ; AX = 0x0820 (little endian: 20 08)
   1.168 -    push cx
   1.169 -    mov cl, 4
   1.170 -    shr al, cl     ; AX = 0x0802 (little endian: 02 08)
   1.171 -    pop cx
   1.172 -%endif
   1.173 -
   1.174 -    ; save "uncompressed" word: e.g. 02 08 or 04 04 from AX
   1.175 -    stosw
   1.176 +    ; load one "compressed" byte and store 3 "uncompressed" bytes
   1.177 +    lodsb
   1.178 +    mov ah,0
   1.179 +    div dh
   1.180 +    stosb	; p/6/6
   1.181 +    mov al,ah
   1.182 +    cbw
   1.183 +    div dl
   1.184 +    stosw	; p/6%6 p%6
   1.185  
   1.186      loop .copy_level_loop
   1.187 +    mov byte [bx],PLAYER
   1.188  
   1.189      call draw_current_level
   1.190  
   1.191 @@ -145,10 +150,10 @@
   1.192      dec ah ; esc
   1.193      jne .not_boot
   1.194  .exit:
   1.195 -    mov ax, 0x0003  ; text mode 80x25 16 colours
   1.196 +    mov al, 0x03  ; text mode 80x25 16 colours
   1.197      int 0x10
   1.198      int 0x20
   1.199 -    jmp boot
   1.200 +    int 0x19
   1.201      
   1.202  .not_boot:
   1.203      cmp ah, 0x50-1 ; down arrow
   1.204 @@ -169,18 +174,16 @@
   1.205      neg al
   1.206  .try_move_right:
   1.207  .try_move_down:
   1.208 -%if 1
   1.209 -SCORE_DIGITS    EQU 4
   1.210 +%ifdef MOVE_COUNT
   1.211      push ax
   1.212      push ds
   1.213      mov bx, SCREEN_DS
   1.214      mov ds, bx
   1.215 -    mov bx, SCORE_DIGITS * 2
   1.216 +    mov bx, COLS + 2 + (LINES-1)*COLS*2
   1.217  
   1.218  .chk_score:
   1.219      dec bx
   1.220      dec bx
   1.221 -    js .exit
   1.222      mov al, '0'
   1.223      xchg [bx], al
   1.224      or al, 0x30
   1.225 @@ -227,7 +230,7 @@
   1.226      ; destination position on screen
   1.227      mov ax, SCREEN_DS
   1.228      mov es, ax
   1.229 -    mov di, (80 * 12 + 40 - 6) * 2
   1.230 +    mov di, (COLS * 12 + COLS/2 - 6) * 2
   1.231  
   1.232      mov ah, 0x0F
   1.233  .loop:
   1.234 @@ -246,7 +249,7 @@
   1.235  
   1.236      dec ah ; esc
   1.237      je get_data.exit
   1.238 -    jmp wait_for_esc
   1.239 +    jmp boot
   1.240  ; halt:
   1.241  ;     cli ; clear interrupt flag
   1.242  ;     hlt ; halt execution
   1.243 @@ -260,7 +263,7 @@
   1.244      push cx ; put it in the stack for later reuse
   1.245  
   1.246      ; print in the middle and not in the corner
   1.247 -    mov di, 2000; middle of screen
   1.248 +    mov di, 25*COLS; middle of screen
   1.249  
   1.250      ; offset by half of width
   1.251      mov bx, 0x00FE
   1.252 @@ -270,7 +273,7 @@
   1.253      ; offset by half of height
   1.254      mov cl, ch
   1.255      and cx, 0x00FE
   1.256 -    mov ax, 80
   1.257 +    mov ax, COLS
   1.258      mul cx
   1.259      sub di, ax
   1.260  
   1.261 @@ -287,7 +290,7 @@
   1.262      cbw
   1.263      xchg ax, si
   1.264      add si, si
   1.265 -    mov ax, [cs:bp+si+display_chars-test_level]
   1.266 +    mov ax, [bp+si+display_chars-test_level]
   1.267      pop si
   1.268      
   1.269      stosw
   1.270 @@ -308,7 +311,7 @@
   1.271      ; jump to next row down
   1.272      xor ch, ch
   1.273      neg cx
   1.274 -    add cx, 80
   1.275 +    add cx, COLS
   1.276      add cx, cx
   1.277      add di, cx
   1.278  
   1.279 @@ -320,7 +323,6 @@
   1.280  try_move:
   1.281      ; try to move the player
   1.282      ; al = offset of how much to move by
   1.283 -    push dx
   1.284  
   1.285      ; extend al into ax (signed)
   1.286      test al, al ; check if negative
   1.287 @@ -416,8 +418,6 @@
   1.288      mov [di - 2], bx
   1.289  
   1.290  .finished:
   1.291 -
   1.292 -    pop dx
   1.293      ret
   1.294  
   1.295