maze intro
home

Representing vs. Rendering


.. print wall and path characters
INCLUDE "emu8086.inc" ORG 100h ; RENDER IN A LOOP mov cx, 10 wall: PUTC 219 ; WALL - Char 219 is a white block: loop wall printn ; go to next line PUTC 219 ; 1 wall block mov cx, 8 path: PUTC 32 ; PATH - draw a blank space loop path PUTC 219 ; 1 wall block ret end

.. pointer to maze, print one row
INCLUDE "emu8086.inc" ORG 100h lea si, mz mov cx, 8 wall: cmp [si], 0 ; path? je p PUTC 219 ; WALL - Char 219 is a white block: jmp nx p: PUTC 32 ; PATH - draw a blank space nx: inc si loop wall ret ; REPRESENTATION is different from RENDERING mz db 1,1,1,1,1,1,1,1 db 1,0,0,0,0,1,0,1 db 1,0,0,1,0,0,0,1 db 1,1,1,1,1,1,1,1 end

.. print multiple rows
INCLUDE "emu8086.inc" ORG 100h ; RENDER ROW 1 ------------- lea si, mz1 mov cx, 8 wall1: cmp [si], 0 ; path? je p1 PUTC 219 ; WALL - Char 219 is a white block: jmp nx1 p1: PUTC 32 ; PATH - draw a blank space nx1: inc si loop wall1 ; RENDER ROW 2 ------------- lea si, mz2 mov cx, 8 wall2: cmp [si], 0 ; path? je p2 PUTC 219 ; WALL - Char 219 is a white block: jmp nx2 p2: PUTC 32 ; PATH - draw a blank space nx2: inc si loop wall2 ; RENDER ROW 3 ------------- lea si, mz3 mov cx, 8 wall3: cmp [si], 0 ; path? je p3 PUTC 219 ; WALL - Char 219 is a white block: jmp nx3 p3: PUTC 32 ; PATH - draw a blank space nx3: inc si loop wall3 ; etc... ret mz1 db 1,1,1,1,1,1,1,1 mz2 db 1,0,0,0,0,1,0,1 mz3 db 1,0,0,1,0,0,0,1 mz4 db 1,1,1,1,1,1,1,1 end

.. print multiple rows as a matrix
INCLUDE "emu8086.inc" ORG 100h ; RENDER ROW 1 ------------- lea si, mz1 mov cx, 8 wall1: cmp [si], 0 ; path? je p1 PUTC 219 ; WALL - Char 219 is a white block: jmp nx1 p1: PUTC 32 ; PATH - draw a blank space nx1: inc si loop wall1 PRINTN ;**** ; RENDER ROW 2 ------------- lea si, mz2 mov cx, 8 wall2: cmp [si], 0 ; path? je p2 PUTC 219 ; WALL - Char 219 is a white block: jmp nx2 p2: PUTC 32 ; PATH - draw a blank space nx2: inc si loop wall2 PRINTN ;**** ; RENDER ROW 3 ------------- lea si, mz3 mov cx, 8 wall3: cmp [si], 0 ; path? je p3 PUTC 219 ; WALL - Char 219 is a white block: jmp nx3 p3: PUTC 32 ; PATH - draw a blank space nx3: inc si loop wall3 PRINTN ;**** ; RENDER ROW 4 ------------- lea si, mz4 mov cx, 8 wall4: cmp [si], 0 ; path? je p4 PUTC 219 ; WALL - Char 219 is a white block: jmp nx4 p4: PUTC 32 ; PATH - draw a blank space nx4: inc si loop wall4 PRINTN ;**** ; etc... ; PUT GUY IN MAZE!! GOTOXY 1, 1 ;Print guy at start position PUTC 01 GOTOXY 6, 2 ;Print guy at start position PUTC 03 ret mz1 db 1,1,1,1,1,1,1,1 mz2 db 1,0,0,0,0,1,0,1 mz3 db 1,0,0,1,0,0,0,1 mz4 db 1,1,1,1,1,1,1,1 end

.. nesting loops
ISSUES: - when you render how do you move the cursor to the beginning of the next row? - how do you know where the man is on the screen? - how do you know where the man is in the data structure? INCLUDE "emu8086.inc" ORG 100h ; ONE POINTER lea si, mz FOR EACH ROW LOOP ROW TIMES mov cx, rows ROW: ; FOR EACH COLUMN LOOP COLUMN TIMES mov cx, columns COLUMN: cmp [si], 0 ; is it a path? je p1 ; yes, jump "over" the wall write PUTC 219 ; WALL - draw a white block: jmp nx1 p1: PUTC 32 ; PATH - draw a blank space nx1: inc si ; keep bumping that pointer! loop COLUMN ; ADJUST as needed ; pointers to ds ; cx saving? ; screen coordinates? loop ROW ret mz db 1,1,1,1,1,1,1,1 db 1,0,0,0,0,1,0,1 db 1,0,0,1,0,0,0,1 db 1,1,1,1,1,1,1,1 end