Skip to content

Commit

Permalink
Merge pull request #50 from algosup/maze_to_back_buffer_ben
Browse files Browse the repository at this point in the history
Updated the maze and its building
  • Loading branch information
MaximeAlgosup authored Dec 7, 2023
2 parents 14bf7b6 + 4042ef0 commit 679805e
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 520 deletions.
62 changes: 18 additions & 44 deletions src/Initialization.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ section .bss
BackgroundBufferSegment resw 1 ; where is stored the dynamic background (dynamic cuz gums are disappearing). Used to restore the screen after a ghost's passage
ScreenBufferSegment resw 1

section .data
section .text

Expand Down Expand Up @@ -64,80 +63,55 @@ section .text
ret














; read the Maze model from the maze.asm, and build each bloc according to the hexacode, drawing the background into the background buffer

MazeToBGbuffer:
int3
xor dx, dx
xor dx, dx ; dh and dl are counters : dh will always contains the number of complete lines, dl contains the number of complete Tiles in this line
push word [BackgroundBufferSegment]
pop es
;ds is ok
.eachBlocsLine:
mov dl, 0 ; blocs in a line
.eachBlocOfTheLine:
.eachTilesLine:
mov dl, 0 ; Tiles in a line
.eachTileOfTheLine:
push dx
mov ax, 0xA00 ; number of pixels in a bloc's line
mov ax, 8*SCREEN_WIDTH ; number of pixels in a Tile's line = 320*8 = (8*8 pixels)*(40 Tiles in a line)
mov bl, dh
and bx, 0x00FF
and bx, 0x00FF
mul bx
mov di, ax ; di contains the number of pixels in complete lines
pop dx

push dx
mov ax, 40 ; number of blocs in a bloc's line
mov ax, 40 ; number of Tiles in a Tile's line
mov bl, dh
mul bl
mov cx, ax ; cx contains the number of blocs in complete lines
pop dx
mov cx, ax ; cx contains the number of Tiles in complete lines

push dx
and dx, 0x00FF
add cx, dx ; cx now contains the number of complete blocs
add cx, dx ; cx now contains the number of complete Tiles
pop dx

push dx
mov ax, 8
mov bl, dl
mul bl
add di, ax ; di now contains the position to write the next bloc
pop dx
add di, ax ; di now contains the position to write the next Tile

push cx
shr cx, 1 ; from the 'cx'ième pixel, we convert it into the 'cx'ième byte where it is stored (1 byte = 2 nibbles = 2 pixels)
mov si, MazeModel5LE
mov si, MazeModel
add si, cx
mov al, [ds:si] ; now al contains the 2 hexa codes (for sprite) of the byte where is the 'cx'ème bloc of mazemodel
xor ax, ax
mov al, [ds:si] ; now al contains the hexa codes (for sprite) of the byte where is the 'cx'th Tile of mazemodel
;check if the hexa code is in the high or low nibble, by looking at the parity of the counter
pop cx
test cl, 1 ;
jnz .NoSecondNibble
shr ax, 4
.NoSecondNibble:

push dx
; pick the sprite to display following the hexacode
and ax, 0xf ; keep only the concerned nibble containing the hexa code
; Get the offset of the sprite, following the hexa code
mov si, MazeSpriteSheet
mov bx, 8*8
mul bx
add si, ax ; si contains the offset of the sprite to display
pop dx
;we draw the bloc
;we draw the Tile
push cx
push dx
mov dx,8
Expand All @@ -152,10 +126,10 @@ section .text

inc dl
cmp dl, 40
jne .eachBlocOfTheLine
jb .eachTileOfTheLine
inc dh
cmp dh, 25
jne .eachBlocsLine
jb .eachTilesLine
ret


Expand Down
Loading

0 comments on commit 679805e

Please sign in to comment.