Skip to content

Commit

Permalink
Merge pull request #54 from algosup/dev
Browse files Browse the repository at this point in the history
Merging dev branch to main with latest working code
  • Loading branch information
leo-chartier authored Dec 8, 2023
2 parents a5d5299 + caa516c commit 0c05887
Show file tree
Hide file tree
Showing 11 changed files with 1,295 additions and 2 deletions.
9 changes: 7 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,7 @@

.vscode/settings.json
.vscode/*
.vscode
*/*.map
*/*.com
*/*.cmd
bin/
nasm/
205 changes: 205 additions & 0 deletions src/Initialization.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
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 .text

BuildScreenBuffer:
call heapInit
mov ax, (SCREEN_HEIGHT*SCREEN_WIDTH/16) ; in ax, the number of paragraph to allocate (1 para = 16bits)
call heapAllocParagraph
mov [ScreenBufferSegment],bx
ret

UpdateScreen:
push ds
push es

mov ax,cs:[ScreenBufferSegment]
mov ds,ax ; backBuffer segment adress
mov ax,0xa000 ; video memory segment adress
mov es,ax
xor si,si ; beginning of the backbuffer (0)
xor di,di ; beginning of the video memory (0)
mov cx, SCREEN_HEIGHT*SCREEN_WIDTH
rep movsb

pop es
pop ds
ret


SetVideoMode:

mov ah, 00h ; chose the video mode setting function at the 10h interruption
mov al, 13h ; set video mode option to 320 x 200 256 colors
int 10h ; call the dos interupt regarding to ax

; write the adress of video memory (A000) in the register which contains the address of the destination segment used by the automatic data transfer functions (like movs, stos, ...)
push word [ScreenBufferSegment]
pop es

ret

ClearScreen:
;clear the screen by filling it with a unique color (stored in al)
mov al, 0x29 ; color to fill the screen (white = 0x0F, black = 0x00)
;set the destination 'es:di' :
push word [ScreenBufferSegment] ; video memory adress = 0xA000
pop es ; define it as the adress of the destination segment
mov di, 0 ; begin the offset (pixel position) at 0
mov cx, SCREEN_WIDTH*SCREEN_HEIGHT ; how many times 'rep' action will be repeated
rep stosb ; store (byte per byte) the content of al into es:di, es = 0xA000, di increasing from 0 to 200*320
ret

BuildBackgroundBuffer:
mov ax, (SCREEN_HEIGHT*SCREEN_WIDTH/16) ; in ax, the number of paragraph to allocate (1 para = 16bits)
call heapAllocParagraph
mov [BackgroundBufferSegment],bx
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:
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
.eachTilesLine:
mov dl, 0 ; Tiles in a line
.eachTileOfTheLine:
push dx
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
mul bx
mov di, ax ; di contains the number of pixels in complete lines
pop dx

mov ax, 40 ; number of Tiles in a Tile's line
mov bl, dh
mul bl
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 Tiles
pop dx

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

mov si, MazeModel
add si, cx
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
push dx
; pick the sprite to display following the hexacode
; 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 Tile
push cx
push dx
mov dx,8
.eachPixelsLine:
mov cx, 8
rep movsb
add di, SCREEN_WIDTH - 8
dec dx
jnz .eachPixelsLine
pop dx
pop cx

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


DisplayMaze:
push es
push ds
;HEART OF THE FUNCTION : 'movsb' writes byte per byte the content from 'ds:si' to 'es:di', increasing both si and di each time it is executed

;set destination 'es:di'
push word [ScreenBufferSegment]
pop es
xor di, di

;set source 'ds:si'
push word [BackgroundBufferSegment]
pop ds
xor si, si

mov cx, SCREEN_WIDTH*SCREEN_HEIGHT ; set the counter for rep
rep movsb ; 'movsb' writes byte per byte the content from 'ds:si' to 'es:di', increasing both si and di each time it is executed

pop ds
pop es
ret

FirstDisplayPacMan:

mov word [x_PacManPosition], 160
mov word [y_PacManPosition], 132
mov word [frameOf_PacMan], PACMAN_RIGHT_2

call Display_PacMan
ret

FirstDisplayGhosts:
;pinky
mov word [x_PinkyPosition], 160
mov word [y_PinkyPosition], 108
mov word [frameOf_Pinky], PINKY_1
mov word [frameOf_Pinky_eyes], EYES_UP
call Display_Pinky
mov word [x_PinkyVelocity], 0
mov word [y_PinkyVelocity], -1
;blinky
mov word [x_BlinkyPosition], 160
mov word [y_BlinkyPosition], 84
mov word [frameOf_Blinky], BLINKY_1
mov word [frameOf_Blinky_eyes], EYES_RIGHT
call Display_Blinky
mov word [x_BlinkyVelocity], 1
mov word [y_BlinkyVelocity], 0
;inky
mov word [x_InkyPosition], 144
mov word [y_InkyPosition], 108
mov word [frameOf_Inky], INKY_1
mov word [frameOf_Inky_eyes], EYES_DOWN
call Display_Inky
mov word [x_InkyVelocity], 0
mov word [y_InkyVelocity], 1
;clyde
mov word [x_ClydePosition], 176
mov word [y_ClydePosition], 108
mov word [frameOf_Clyde], CLYDE_1
mov word [frameOf_Clyde_eyes], EYES_LEFT
call Display_Clyde
mov word [x_ClydeVelocity], -1
mov word [y_ClydeVelocity], 0

ret

72 changes: 72 additions & 0 deletions src/constants.asm

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions src/entry.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[map symbols pac.map]
org 100h

jmp start

%include "heapLibrary.inc"
%include "constants.asm"
%include "maze.asm"
%include "sprites.asm"
%include "main.asm"
%include "initialization.asm"
%include "keyboard.asm"
%include "move_sprites.asm"
20 changes: 20 additions & 0 deletions src/heapLibrary.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; functions to allocate and then use the heap (which is a part of memory located out of the 64kio of memory containing the code, data, bss section)

section .bss
nextFreeSegment resw 1

section .text
heapInit:
mov ax, cs ; we get the adress of the beginning of the code, data, etc... (64Kio)
add ax,1000h ; we jump to after the end of this window (1000h = 64Kio = 65 536)
mov cs:[nextFreeSegment],ax ; the nextFreeSegment variable, in bss, contains the segment adress of the beginning of the 'heap'
ret

; this function will allocate a piece of the heap :
; in ax, put how many paragraphs (16 bits) (cause a paragraph is a segment with the offset=0 , and between two segment at the offset 0, there are 16 bits)
; the segment corresponding to this space allocated is moved in bx
; then, we change the value of the next segment available, at the end at the one just created
heapAllocParagraph:
mov bx, cs:[nextFreeSegment] ; we
add cs:[nextFreeSegment], ax
ret
Loading

0 comments on commit 0c05887

Please sign in to comment.