3

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
rkhb
  • 14,159
  • 7
  • 32
  • 60
M.Sayel
  • 23
  • 5
  • 2
    No. The way that you solve this is by detecting the size of the screen and reacting to that in your code. – David Hoelzer May 11 '18 at 19:37
  • well, this is not classic DOS/BIOS text mode, so I'm not sure what kind of things works with this, maybe try one of `int 10h` services to see if you can detect the size of screen, like http://stanislavs.org/helppc/int_10-f.html .. does it return 191 in `AH`? ... an try to improve your code, I like your commitment to write it by code like repeating same `mov` 30 times, but using some kind of loop and subroutine taking arguments would be more nice. Example: to erase with spaces you can do `mov ax,0720h ; attribute + space` then set `es:di` to start of line, `cx` = length, and `rep stosw` to fill – Ped7g May 11 '18 at 20:11
  • about your question.. you can try to set up 80x25 text mode at the start of your code... `mov ax,3` `int 10h` ... In real DOS this would be enough to reset display to 80x25 and clear the content. Not sure about what emu8086 will do, it's not "real" emulator, but a tool for students, so it doesn't emulate the x86 very well, etc.. overall it's quite mediocre SW. – Ped7g May 11 '18 at 20:15
  • Thank you all, Mr.Ped7g I'm gonna try it – M.Sayel May 12 '18 at 13:58
  • about the erasing by using the interrupt it will not let me to maximize the display screen. – M.Sayel May 12 '18 at 14:13

1 Answers1

1
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
Fifoernik
  • 9,779
  • 1
  • 21
  • 27