I am taking Microprocessors course and I have a problem with my code.
I need to write a program code that make a word moving around.
The code work correctly on (80*25) screen (because of my calculations depends on it)
But the problem is: when I maximize the display screen everything goes wrong!, because the dimensions changed
Is there any instruction code that if we write in the code enforce the display to contain the same dimensions even if we maximize it?
when the display screen (80*25)
screen Maximized (191*63)!
mov ax, 0b800h
mov ds, ax
mov bx, 0
Main:
call dltru
dltru: ; diagonal left to right upper
mov bx,0
mov si,0
mov cx,21
lower2:
call box
mov [bx+160+2+si],' '
mov [bx+160+4+si],'M'
mov [bx+160+6+si],'O'
mov [bx+160+8+si],'E'
mov [bx+160+10+si],' '
mov [bx+160+12+si],'S'
mov [bx+160+14+si],'A'
mov [bx+160+16+si],'Y'
mov [bx+160+18+si],'E'
mov [bx+160+20+si],'L'
mov [bx+160+22+si],' '
mov [bx+160+24+si],'F'
mov [bx+160+26+si],'A'
mov [bx+160+28+si],'L'
mov [bx+160+30+si],'A'
mov [bx+160+32+si],'H'
mov [bx+160+34+si],' '
call delete
add si,160
add bx,6
loop lower2
ret
Box: ;this will draw the box around the announcement!
;left
mov [0+bx+si],0B2h
mov [160+bx+si],0B2h
mov [320+bx+si],0B2h
;right
mov [36+bx+si],0B2h
mov [196+bx+si],0B2h
mov [356+bx+si],0B2h
;upper
mov [2+bx+si],0B2h
mov [4+bx+si],0B2h
mov [6+bx+si],0B2h
mov [8+bx+si],0B2h
mov [10+bx+si],0B2h
mov [12+bx+si],0B2h
mov [14+bx+si],0B2h
mov [16+bx+si],0B2h
mov [18+bx+si],0B2h
mov [20+bx+si],0B2h
mov [22+bx+si],0B2h
mov [24+bx+si],0B2h
mov [26+bx+si],0B2h
mov [28+bx+si],0B2h
mov [30+bx+si],0B2h
mov [32+bx+si],0B2h
mov [34+bx+si],0B2h
;lower
mov [322+bx+si],0B2h
mov [324+bx+si],0B2h
mov [326+bx+si],0B2h
mov [328+bx+si],0B2h
mov [330+bx+si],0B2h
mov [332+bx+si],0B2h
mov [334+bx+si],0B2h
mov [336+bx+si],0B2h
mov [338+bx+si],0B2h
mov [340+bx+si],0B2h
mov [342+bx+si],0B2h
mov [344+bx+si],0B2h
mov [346+bx+si],0B2h
mov [348+bx+si],0B2h
mov [350+bx+si],0B2h
mov [352+bx+si],0B2h
mov [354+bx+si],0B2h
ret
delete:
mov [bx+162+si],' '
mov [bx+164+si],' '
mov [bx+166+si],' '
mov [bx+168+si],' '
mov [bx+170+si],' '
mov [bx+172+si],' '
mov [bx+174+si],' '
mov [bx+176+si],' '
mov [bx+178+si],' '
mov [bx+180+si],' '
mov [bx+182+si],' '
mov [bx+184+si],' '
mov [bx+186+si],' '
mov [bx+188+si],' '
mov [bx+190+si],' '
mov [bx+192+si],' '
mov [bx+194+si],' '
;left
mov [0+bx+si],' '
mov [160+bx+si],' '
mov [320+bx+si],' '
;right
mov [36+bx+si],' '
mov [196+bx+si],' '
mov [356+bx+si],' '
;upper
mov [2+bx+si],' '
mov [4+bx+si],' '
mov [6+bx+si],' '
mov [8+bx+si],' '
mov [10+bx+si],' '
mov [12+bx+si],' '
mov [14+bx+si],' '
mov [16+bx+si],' '
mov [18+bx+si],' '
mov [20+bx+si],' '
mov [22+bx+si],' '
mov [24+bx+si],' '
mov [26+bx+si],' '
mov [28+bx+si],' '
mov [30+bx+si],' '
mov [32+bx+si],' '
mov [34+bx+si],' '
;lower
mov [322+bx+si],' '
mov [324+bx+si],' '
mov [326+bx+si],' '
mov [328+bx+si],' '
mov [330+bx+si],' '
mov [332+bx+si],' '
mov [334+bx+si],' '
mov [336+bx+si],' '
mov [338+bx+si],' '
mov [340+bx+si],' '
mov [342+bx+si],' '
mov [344+bx+si],' '
mov [346+bx+si],' '
mov [348+bx+si],' '
mov [350+bx+si],' '
mov [352+bx+si],' '
mov [354+bx+si],' '
ret
mov [bx+160+2+si],' '
Because of the fixed value of 160, that is only valid for an 80 columns screen, your code fails on the alternative resolution.
What you need is calculating the size of 1 scanline in the textvideo memory:
. First look up the actual number of columns on the current screen. BIOS has this count in the memory variable at 0040h:004Ah.
. Then double this value because in the video memory each character/attribute occupies 2 bytes.
. Finally use this value instead of the fixed value of 160.
push ds
mov bx, 0040h
mov ds, bx
mov bx, [004Ah]
shl bx, 1 ; This gives: BX=160 if 80x25, BX=382 if 191x63
pop ds
Writing on the 2nd row of the screen becomes:
mov [bx+2+si],' '
mov [bx+4+si],'M'
mov [bx+6+si],'O'
mov [bx+8+si],'E'
Writing on the 3rd row of the screen becomes:
add bx, bx
mov [bx+2+si],0B2h
mov [bx+4+si],0B2h
mov [bx+6+si],0B2h
mov [bx+8+si],0B2h
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With