The MASM Forum

Miscellaneous => 16 bit DOS Programming => Topic started by: ghjjkl on June 19, 2014, 11:45:55 PM

Title: some problem with painting (mode 13h)
Post by: ghjjkl on June 19, 2014, 11:45:55 PM
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?
Title: Re: some problem with painting (mode 13h)
Post by: ghjjkl on July 04, 2014, 09:10:52 PM
And one silly question: what does happen when some bytes being drawn reach upper left screen edge? Do they damage data which's located before 0A000h?
Title: Re: some problem with painting (mode 13h)
Post by: nidud on July 04, 2014, 10:06:50 PM
deleted
Title: Re: some problem with painting (mode 13h)
Post by: dedndave on July 05, 2014, 03:07:43 AM
if a segment register is set to A000h, you can only access A0000 to AFFFF physical
if you keep going, it "segment wraps" back to A0000   :biggrin: