1

Hi I'm trying to build maze game using assembly language using emu8086 the symbol is moving in the maze correctly but the code part for it being deleted from previous position and not moving on walls is not working probably here's my code:

;current position
mov dh,r ;row
mov dl,c ;col
mov bh,0
mov ah,2
int 10h

read_input:
mov ah,7
int 21h

cmp al,120 ;x
je exit

cmp al,119 ;w
je movUp 

cmp al,115 ;s
je movDown

cmp al,100 ;d
je movRight

cmp al,97  ;a
je movLeft
 
jmp read_input 

;====================================================
;move player

movUp:
; delete symbol from current position
mov ah,2
mov dl,00
int 21h

;move cursor position upwards
dec r 

mov dh,r
mov dl,c
mov bh,0
mov ah,2
int 10h 

;read character at cursor position
mov ah,08h
mov bh,0
int 10h 

;check if it's a wall block
cmp al,177
je back_wall
jmp p

;return cursor position downwards 
back_wall:
inc r 

mov dh,r
mov dl,c
mov bh,0
mov ah,2
int 10h 
jmp read_input

;print symbol in the new position 
p:
mov ah,2
mov dl,042
int 21h

inc score  
jmp read_input

same logic for other directions

there's no syntax errors

it runs but as if it's not taking the interrupt 10h/08h

Areen Ali
  • 11
  • 2

2 Answers2

1

Learn to use a debugger and walk through your program instruction by instruction, step by step.

Perhaps you will discover a bug at the label p: where you're apparently trying to
;print symbol in the new position using WRITE CHARACTER TO STANDARD OUTPUT
but you forgot to set AH=02h.

As far as handling of input keys is concerned, see also this question

vitsoft
  • 5,515
  • 1
  • 18
  • 31
  • AH is already set to 2 from the previous instruction tried to add it but it make no difference – Areen Ali May 21 '21 at 19:32
  • 1
    Are you sure? The only way how to get to `p:` is from *;check if it's a wall block* when it's not a wall block. But `AH` is character's attribute returned by [INT10h/AH=08h](http://www.ctyme.com/intr/rb-0098.htm) when you have *read character at cursor position*. – vitsoft May 21 '21 at 20:25
  • true I add it to the code still the problem INT10h/AH=08h is returning a different value instead of 177 when having a wall block – Areen Ali May 21 '21 at 20:54
0

When you output your characters you are using the DOS.PrintChar function 02h. That's the reason for your troubles because this function will also advance the cursor to the right. At first this doesn't matter when you delete symbol from current position because you immediately let follow it by the BIOS.SetCursorPosition function. No harm done.
However, when you print symbol in the new position, your code jumps back to read_input and from then on there will be a difference between the cursor position on the screen and the values in your r (row) and c (column) variables. Any deletes that follow will remove the character to the right of the asterisk and not the asterisk itself!

The solution is to use a BIOS character output function that does not advance the cursor. BIOS.WriteCharacter function 0Ah is fine:

mov cx, 1      ; Replication count, you want 1 character
mov bh, 0      ; Display page
mov ax, 0A2Ah  ; AH=0Ah (function number), AL=2Ah (character 42)
int 10h        ; BIOS.WriteCharacter

You can read more about these output functions in Displaying characters with DOS or BIOS.

In conclusion, your BIOS.ReadCharacterAndAttribute function 08h works fine.

Sep Roland
  • 33,889
  • 7
  • 43
  • 76