-3

in a University project in graphic mode in DOS operrarion system I need to clear the screen (color it all in one color), does anyone know what's the intterapt for that and what do I need to put in the registers? In which register put the color i want the screen will be in? thank very much to the helpers!

this is my code (in assembly): if someone can help me understand why the up & down arrowes are moving right & left and why my exit is writing me deternmind code 0 I would love that!:

> IDEAL MODEL 
small STACK 
100h DATASEG 
x dw 0 
xa dw 0 
y dw 5 
ya dw 5 
z dw 1
za dw 1 
color db 4
Pixels Color bgcolor db 0 ;BackGround Color
> CODESEG start: 
mov ax, @data 
mov ds, ax 
; Graphic mode 
mov ax, 13h 
int 10h
; Print red dot 
mov bh,0h 
mov cx,[x] 
mov dx,[y]
> mov al,[color] 
mov ah,0ch 
int 10h 
amit:
>     ;Wait for +
>     mov ah,00h
>     int 16h
>     cmp ax, 0d3dh
>     je plus
>     ;Wait for -
>     cmp ax, 0c2dh
>     je minus
>     ; Wait for exit
>     cmp ax, 1071h
>     je exit
>     cmp ax, 4d00h
>     je right
>     cmp ax, 4b00h
>     je left1
>     cmp ax, 4800h
>     je up1
>     cmp ax, 5000h
>     je down1
>     
>     exit:
>         mov ah, 0
>         mov al, 2
>         int 10h
>         mov ax, 4c00h
>         int 21h
>     plus:
>         add [x], 1
>         mov cx, [x]
>         add [y], 1
>         mov dx, [y]
>         mov bh, 0h
>         mov al,[color]
>         mov ah, 0ch
>         int 10h
>         add [z], 1h
>         add [za], 1h
>         jmp amit
>     left1:
>         jmp left
>     up1:
>         jmp up
>     down1:
>         jmp down
>     minus:
>         mov bh, 00h
>         mov al,[bgcolor]
>         mov ah,0ch
>         int 10h
>         sub [x], 1
>         mov cx, [x]
>         sub [y], 1
>         mov dx, [y]
>         sub [z], 1h
>         sub [za], 1h
>         jmp amit
>     right:
>         clsright:
>             mov bh, 00h
>             mov al,[bgcolor]
>             mov ah,0ch
>             int 10h
>             sub [x], 1
>             mov cx, [x]
>             sub [y], 1
>             mov dx, [y]
>             sub [z], 1h
>             cmp [z], 0h
>             jne clsright  
>         add [x],1h
>         jmp arrowplus
>     left:
>         clsleft:
>             mov bh, 00h
>             mov al,[bgcolor]
>             mov ah,0ch
>             int 10h
>             sub [x], 1
>             mov cx, [x]
>             sub [y], 1
>             mov dx, [y]
>             sub [z], 1h
>             cmp [z], 0h
>             jne clsleft 
>             sub [x], 1h
>             jmp arrowplus
>     up:
>         clsup:
>             mov bh, 00h
>             mov al,[bgcolor]
>             mov ah,0ch
>             int 10h
>             sub [x], 1
>             mov cx, [x]
>             sub [y], 1
>             mov dx, [y]
>             sub [z], 1h
>             cmp [z], 0h
>             jne clsup 
>             sub [y], 1h
>             jmp arrowplus
>     down:
>         clsdown:
>             mov bh, 00h
>             mov al,[bgcolor]
>             mov ah,0ch
>             int 10h
>             sub [x], 1
>             mov cx, [x]
>             sub [y], 1
>             mov dx, [y]
>             sub [z], 1h
>             cmp [z], 0h
>             jne clsdown
>             add [y], 1h
>             jmp arrowplus
>     arrowplus:
>         add [x], 1
>         mov cx, [x]
>         add [y], 1
>         mov dx, [y]
>         mov bh, 0h
>         mov al,[color]
>         mov ah, 0ch
>         int 10h
>         add [z], 1h
>         mov [z], dx
>         cmp [za], dx
>         jne arrowplus
>         jmp amit END start
Cœur
  • 37,241
  • 25
  • 195
  • 267
A. Nir
  • 31
  • 1
  • 5
  • 1
    I would update video memory directly to manipulate bits on the screen, but you can use the very slow method using the BIOS [Int 10h/AH=0Ch](http://www.ctyme.com/intr/rb-0104.htm) – Michael Petch Oct 21 '16 at 22:11
  • if you need later on some more things to add to your project see [What is the best way to move an object on the screen?](http://stackoverflow.com/a/29579522/2521214) I put there source for one of my really old game in MS-DOS 320x200x8bit mode (the same you are using) including menu (in text mode), sprites, simultaneous control (3 players) , file access. All in tiny model (up to 64KB of *.com executable) – Spektre Oct 22 '16 at 08:01

1 Answers1

2

I'm assuming you are working with VGA mode (or can switch to VGA). There's a good explanation about the different modes here. Briefly, you can switch to several display modes, either graphical or textual. For all legacy modes, including VGA, you can interact with the dispaly through an interrupt, but it's quite clumsy. A better option, is using DMA (Direct Memory Access). It's an interval of memory addresses, which is mapped directly to the display memory. So by writing a byte to the memory, you can change a character/pixel/pixels (depending on the exact mode). The easiest for you will be to switch to VGA 16 color, and writing a constant byte the the display. You can find information about the interacting with the monitor using DMA here, and a color palette for this mode here.

A sample code (credit to this page):

mov ax, 13h ; AH=0 (Change video mode), AL=13h (VGA mode, 16 colors, 320x200)
int 10h ; Video BIOS interrupt, switching to VGA
mov ax, 0A000h ; The offset to video mapped memory
mov es, ax ; We load it to ES through AX, becouse immediate operation is not allowed on ES
mov ax, 0 ; 0 will put it in top left corner. To put it in top right corner load with 320, in the middle of the screen 32160 = 320*100 + 160.
mov di, ax ; load Destination Index register with ax value (the coords to put the pixel)
mov al, 7 ; Grey color.
mov cx, 64000 ; 6400 = 320 * 200 pixels
rep stosb ; paint the whole screen with grey

The color palette for this mode, for the sake of completeness:

0 - black
1 - blue
2 - green
3 - cyan
4 - red
5 - magenta
6 - brown
7 - light gray
8 - gray
9 - light blue
10 - light green
11 - light cyan
12 - light red
13 - light magenta
14 - yellow
15 - white
galra
  • 353
  • 2
  • 12