i need to move some picture by keyboard. Picture must be stopped if it comes to sreen edge. I've tried smth like this(example):
(...)
.data
(...)
;buffer for picture
pict db 0,0,1,1,0,0
db 0,0,1,1,0,0
db 1,1,1,1,1,1
db 1,1,1,1,1,1
db 0,0,1,1,0,0
db 0,0,1,1,0,0
(...)
.code
;there should be setting of 13h mode, changing vga palette and then drawing that picture in cycle
(...)
xor ah,ah
int 16h
;there should be checking if any button is pressed
(...)
;for example, if 'w' is pressed:
cmp al,'w'
jne @f
.if (PICTURE_POSITION >= 320) ;if there's one pixel left at least
sub PICTURE_POSITION,320
.endif
jmp short @000 ;otherwise
(...)
;then if 's' is pressed:
cmp al,'s'
jne @f ;otherwise
.if (PICTURE_POSITION < 320 * 200 - PICTURE_HEIGHT * 320) ;if there's one pixel left at least
sub PICTURE_POSITION,320
.endif
jmp short @001 ;otherwise
(...)
;that code works, but if i add code for left and right edges...
cmp al,'a'
jne @f
mov ax,PICURE_POSITION
cwd
mov bx,320 ;we need to find vertical component of picture's postion, it should be (0/320), (320/320), (640/320) and so on
div bx
mul bx
;for example: if picture's postion is 645 - it is located on third row, so if we want to stop it in the right place,
;we need to check if its position is bigger than (645/320)*320=640 and if it is, we move picture left
.if PICTURE_POSITION>ax
dec mach_pos
.endif
so there's problem: initially all border checking works fine, but when picture have passed some rows down and i try to move it left or right, my program just stucks hopelessly,
and all my next actions is ignored. I think if it worth to try this on real machine (i've tried it on dosbox so far) but what if i'll make my pc to be knelt?