flat assembler
Message board for the users of flat assembler.

Index > DOS > Where the x-y is calculated to paint the pixel?

Author
Thread Post new topic Reply to topic
arcangel



Joined: 19 Aug 2009
Posts: 39
arcangel 04 Jan 2014, 16:04
Code:
EMU8086 GENERATED LISTING. MACHINE CODE <- SOURCE.
 
noname.com -- emu8086 assembler version: 4.08  
 
[ 05/01/2014  --  15:14:15 ] 
 
===================================================================================================
[LINE]     LOC: MACHINE CODE                          SOURCE
===================================================================================================
 
[   1]        :                                       ;to compile it use:
[   2]        :                                       ;       tasm.exe unvwater.asm
[   3]        :                                       ;       tlink.exe /t unvwater.obj
[   4]        :                                       
[   5]        :                                       ;Here is my 100bytes long water effect
[   6]        :                                       ;I'm Programmer/UniVerse , and you can find me
[   7]        :                                       ;on IRCNET IRC server on #pixel and #coders
[   8]        :                                       ;under nickname - Prg^UnV
[   9]        :                                       ;also you can go to our web page at:
[  10]        :                                       ;http://www.chat.ru/~unv
[  11]        :                                       ;Just don't forget to greet me , anyway! Smile
[  12]        :                                       ;If you have any questions , or you will optimize it to 90 or less bytes -
[  13]        :                                       ;mail to me at unv@chat.ru
[  14]        :                                       ;thanx Wink here is the source goes
[  15]        :                                       
[  16]        :                                       ;.286                   ;286 instructions enabled
[  17]        :                                       ;Code Segment           ;our declaration stuff
[  18]        :                                       ;Assume cs:code         ;and this line too
[  19]        :                                       ORG 100h               ;com file entry point
[  20]    0100:                                       start:                 ;start =)
[  21]        :                                       ;all registers that we use is clear now
[  22]        :                                       ;AX,BX,CX,DX=0
[  23]        :                                       
[  24]    0100: B4 A0                                 mov ah,0a0h            ;AH=A0 , AX=A000 (vga segment)
[  25]    0102: 8E C0                                 mov es,ax              ;moving vga segment adress to ES segment register
[  26]    0104: 03 C0                                 add ax,ax              ;AX=AX+AX , Let's think that ax+ax segment is clear =)
[  27]    0106: 8E D8                                 mov ds,ax              ;moving AX to DS
[  28]    0108: B8 13 00                              mov ax,13h             ;AX=13 , to set 13h mode
[  29]    010B: CD 10                                 int 10h                ;video interrupt, 10h
[  30]    010D: BA C9 03                              mov dx,3c9h            ;dx=3C9 , let's set it for the palette changing
[  31]        :                                       
[  32]    0110:                                       @AAA2:                 ;Segment clearing loop
[  33]    0110: 89 05                                 mov [di],ax            ;moving to AX to DS:DI
[  34]    0112: 4F                                    dec di                 ;dec di , at the loop start di=0 so after first dec
[  35]    0113: 75 FB                                 jnz @AAA2              ;di is equals 65535
[  36]        :                                       
[  37]    0115:                                       @LOOP:                 ;Palette loop
[  38]    0115: 33 C0                                 xor ax,ax              ;AX=0
[  39]    0117: EE                                    out dx,al              ;let's write R to graphics port (R=0)
[  40]    0118: EE                                    out dx,al              ;let's write G to graphics port (G=0)
[  41]    0119: 8A C3                                 mov al,bl              ;AL=BL
[  42]    011B: D0 E8 D0 E8                           shr al,2               ;AL=AL/4
[  43]    011F: EE                                    out dx,al              ;let's write B to graphics port (B=AL)
[  44]    0120: 43                                    inc bx                 ;BX=BX+1 , we use it to set all palette
[  45]    0121: 75 F2                                 jnz @LOOP              ;and when BX=0 we're just finished this loop
[  46]        :                                       ;but BX=0 after 65535 , yeah ,we set our palette
[  47]        :                                       ;in about 255 times , but here we got 1 byte
[  48]        :                                       
[  49]    0123:                                       @REPEAT:               ;Main loop
[  50]    0123: 33 DB                                 XOR BX,BX              ;BX=0
[  51]    0125: BA 03 00                              mov dx,3               ;DX=3
[  52]    0128: 8B F7                                 mov si,di              ;SI=DI
[  53]    012A:                                       @SUX:                  ;Matrix loop
[  54]    012A: 46                                    inc si                 ;SI=SI+1
[  55]    012B: 8A 84 BE FE                           mov al,byte ptr [si-322]  ;here is our matrix calculations
[  56]    012F: 03 D8                                 add bx,ax                 ;
[  57]    0131: 8A 84 3E 01                           mov al,byte ptr [si+318]  ;
[  58]    0135: 03 D8                                 add bx,ax                 ;
[  59]    0137: 8A 44 FE                              mov al,byte ptr [si-2]    ;
[  60]    013A: 03 D8                                 add bx,ax                 ;
[  61]    013C: 4A                                    dec dx                    ;
[  62]    013D: 75 EB                                 jnz @SUX;                 ; here is jump to make our matrix size 3x3
[  63]    013F: 8A 05                                 mov al,byte ptr [di]      ; it's for our matrix
[  64]    0141: 2B D8                                 sub bx,ax                 ;
[  65]    0143: D1 E0 D1 E0                           shl ax,2                  ; BX=BX-AX ; AX=AX*4 ;BX=BX-AX ; BX=BX/4 ; AX=BX
[  66]    0147: 2B D8                                 sub bx,ax                 ; AX=AX/128
[  67]    0149: D1 EB D1 EB                           shr bx,2                  ; BX=BX-AX ; now translation of this goes =)
[  68]    014D: 8B C3                                 mov ax,bx                 ; We're making our matrix calculations
[  69]    014F: D1 E8 D1 E8 D1 E8 D1 E8 D1 E8 D1 E8   shr ax,7                  ; B=BX , A=AX , so the way is:
                D1 E8                               
[  70]    015D: 2B D8                                 sub bx,ax                 ; B=(B-A*5)/4 A=B A=A/128 BX=BX-AX -it's for decrease
[  71]    015F: 3E 88 1D                              mov ds:[di],bl            ; moving our point to the memory
[  72]    0162: 47                                    inc di                    ; Smile no comments here
[  73]    0163: E2 BE                                 loop @REPEAT              ; looping for our full screen
[  74]        :                                       
[  75]    0165: 49                                    dec cx                    ; cx=0 , cx-1 = 65535
[  76]    0166: F3 A4                                 rep movsb                 ; moving our data to screen
[  77]        :                                       
[  78]    0168: E4 60                                 in al,60h                 ; reading port 60h
[  79]    016A: FE C8                                 dec al                    ; if port 60h <> 1 (esc) we will continue rendering
[  80]    016C: 75 B5                                 jnz @REPEAT               ; =)))
[  81]    016E: B0 03                                 mov al,03h                ; al=3h , text mode
[  82]    0170: CD 10                                 int 10h                   ; int 10h , textmode 3h is on
[  83]    0172: C3                                    ret                       ; exiting!
[  84]        :                                       ;code ends                 ; here is our stuff ends!
[  85]        :                                       ;end start                 ; YESSS!!!!
[  86]        :                                       
[  87]        :                                       
[  88]        :                                       
[  89]        :                                       
[  90]        :                                       
 
===================================================================================================
 




===================================================================================================
    


Hi!

This is a demo program that writes directly to the vga port. Line 100 mov ah, 0A0H

But I do not understand where the x-y is calculated to paint the pixel. Could someone help me?? Rolling Eyes
Post 04 Jan 2014, 16:04
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac 04 Jan 2014, 16:53
Hello.
I found some hidden instructions in this line. Laughing
arcangel wrote:

Code:
[  69]    014F: D1 E8 D1 E8 D1 E8 D1 E8 D1 E8 D1 E8   shr ax,7                  ; B=BX , A=AX , so the way is:    

..and some more in other lines.

How to optimize?
Code:
lea si, [si+1] ; inc si    


Dirk
Post 04 Jan 2014, 16:53
View user's profile Send private message Send e-mail Reply with quote
arcangel



Joined: 19 Aug 2009
Posts: 39
arcangel 04 Jan 2014, 17:28
freecrac wrote:
Hello.
I found some hidden instructions in this line. Laughing
arcangel wrote:

Code:
[  69]    014F: D1 E8 D1 E8 D1 E8 D1 E8 D1 E8 D1 E8   shr ax,7                  ; B=BX , A=AX , so the way is:    

..and some more in other lines.

How to optimize?
Code:
lea si, [si+1] ; inc si    


Dirk


Thank you so much Smile

I have searched the internet "video mode 13H" and is linear. It is an array that begins on the A000 direction

And the position of the array with the calculated value of AX right? Wink

I think I get it Smile
Post 04 Jan 2014, 17:28
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac 04 Jan 2014, 17:59
arcangel wrote:
Thank you so much Smile

I have searched the internet "video mode 13H" and is linear. It is an array that begins on the A000 direction

And the position of the array with the calculated value of AX right? Wink

I think I get it Smile

Yes you are right.

We do not need this DS-segment override prefix:
Code:
[  71]    015F: 3E 88 1D                              mov ds:[di],bl            ; moving our point to the memory    

Because DS is the default segment, if we are using DI, SI, or BX for to build an address-register. (Only for BP and SP the default segment is the stacksegment SS.)
Segment override prefixe we only need, if we do not want to use the default segment.
One byte schorter:
Code:
[  71]    015F: 88 1D                              mov [di],bl            ; moving our point to the memory    


Dirk
Post 04 Jan 2014, 17:59
View user's profile Send private message Send e-mail Reply with quote
arcangel



Joined: 19 Aug 2009
Posts: 39
arcangel 04 Jan 2014, 20:16
Code:
[  71]    015F: 3E 88 1D                              mov ds:[di],bl            ; moving our point to the memory
    


First move to the value of bl at ds: [di] and then

The pixel will be written in the array pociscion ds: [di]

Right? Twisted Evil

Is it always like this? Twisted Evil

How interesting!

Code:
[  38]    0115: 33 C0                                 xor ax,ax              ;AX=0
[  39]    0117: EE                                    out dx,al              ;let's write R to graphics port (R=0)
[  40]    0118: EE                                    out dx,al              ;let's write G to graphics port (G=0)
[  41]    0119: 8A C3                                 mov al,bl              ;AL=BL
[  42]    011B: D0 E8 D0 E8                           shr al,2               ;AL=AL/4
[  43]    011F: EE                                    out dx,al              ;let's write B to graphics port (B=AL)
    


The color of the pixel is RR + GG + BB, why do I have three statements out? Why there is not one with the three colors? Embarassed

Thank you so much Smile
Post 04 Jan 2014, 20:16
View user's profile Send private message Reply with quote
freecrac



Joined: 19 Oct 2011
Posts: 117
Location: Germany Hamburg
freecrac 06 Jan 2014, 08:36
arcangel wrote:
Code:
[  71]    015F: 3E 88 1D                              mov ds:[di],bl            ; moving our point to the memory
    


First move to the value of bl at ds: [di] and then

The pixel will be written in the array pociscion ds: [di]

Right? Twisted Evil

Is it always like this? Twisted Evil

How interesting!

Yes and then the data are moving to screen with "rep movsb".

Quote:

Code:
[  38]    0115: 33 C0                                 xor ax,ax              ;AX=0
[  39]    0117: EE                                    out dx,al              ;let's write R to graphics port (R=0)
[  40]    0118: EE                                    out dx,al              ;let's write G to graphics port (G=0)
[  41]    0119: 8A C3                                 mov al,bl              ;AL=BL
[  42]    011B: D0 E8 D0 E8                           shr al,2               ;AL=AL/4
[  43]    011F: EE                                    out dx,al              ;let's write B to graphics port (B=AL)
    


The color of the pixel is RR + GG + BB, why do I have three statements out? Why there is not one with the three colors? Embarassed

Thank you so much Smile

I think its because the blue part have to become other values and if we want to use "rep OUTSB" the values have to be stored in a ram location before. The io_port of the ramdac provide only a byte access. For the red, green and blue palette we can use values between 0 - 63.

Dirk
Post 06 Jan 2014, 08:36
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.