flat assembler
Message board for the users of flat assembler.
Index
> Tutorials and Examples > VGA 13h mode for16bit MZ exe on DOS Goto page 1, 2 Next |
Author |
|
revolution 17 Apr 2023, 17:25
I don't think it needs any optimising. It is a good example of how to do something specific without any distracting extras.
|
|||
17 Apr 2023, 17:25 |
|
Roman 17 Apr 2023, 18:05
Quote: draw pixel Draw animated sprite. This is more practically ! Using 0A0000h Write directly pixel in video memory. Or using back buffer to store all sprites, than copy from back buffer to video memory. Last edited by Roman on 18 Apr 2023, 03:04; edited 2 times in total |
|||
17 Apr 2023, 18:05 |
|
edfed 17 Apr 2023, 23:52
i suggest to familiarize with functions.
if you rewrite the code with calls and even macros, you will start to touch the power of fasm. for example: Code: include "dosMZ.inc" vgaMode 13h putPixel 160,100,5 waitForKey key.escape vgaMode 3 dosExit the dosMZ.inc file can be like this Code: format MZ key: .escape=0 macro vgaMode mode { mov ax,mode int 10h } macro putPixel x,y,color { .... } start: it is to now to you to write the content of dosMz.inc based on what i've shown to you. |
|||
17 Apr 2023, 23:52 |
|
macomics 18 Apr 2023, 01:37
Code: key: .escape=0x0127 macro videoMode mode=3 { mov ax,mode and 255 int 10h } macro setPixel x,y,color=7 { mov cx, x mov dx,y mov ax,color and 255 + 12 * 256 int 10h } macro waitKey key=0 { local .loop, .wait .loop: mov ah, 17 int 22 pushf .wait: mov ah, 16 int 22 popf jnz .loop if key <> 0 pushf cmp ax, key jnz .wait popf end if } macro sysExit status=0 { mov ax, status and 255 + 76 * 256 int 33 } macro .code aim=$ { segment @code entry @code:aim } Code: format MZ stack 1024 heap 0 include "dosMZ.inc" .code $ videoMode 19 setPixel 160,100 waitKey key.escape videoMode sysExit |
|||
18 Apr 2023, 01:37 |
|
revolution 18 Apr 2023, 06:15
edfed wrote: i suggest to familiarize with functions. |
|||
18 Apr 2023, 06:15 |
|
Roman 18 Apr 2023, 07:40
This is macros nice for writing game!
|
|||
18 Apr 2023, 07:40 |
|
FlierMate2 18 Apr 2023, 07:56
It is just a tiny pixel in the center of the screen.
Kitsune wrote:
Ah, I misunderstood it, I thought the function is to draw 160 columns x 100 rows rectangle. Good beginning for you, Kitsune.
|
||||||||||
18 Apr 2023, 07:56 |
|
FlierMate2 18 Apr 2023, 08:31
A slightly modified version to draw horizontal line:
Code: DrawLine: mov cx,100 ;start of column mov dx,100 ;row redraw: push cx push dx call DrawPixel pop dx pop cx inc cx ;increment column, row unchanged cmp cx, 300 ;end of column jb redraw ret DrawPixel: ;draw pixel - 160 column, 100 row, color purple mov ah,0ch mov al,5 ;color int 10h ret Oh, I just realized that I don't know how to draw diagonal line! |
|||
18 Apr 2023, 08:31 |
|
Picnic 18 Apr 2023, 10:38
I have an old VGA Snake-like program. Quite simple code. Both fasm and Tasm versions included. It may seem useful to someone.
|
|||||||||||
18 Apr 2023, 10:38 |
|
revolution 18 Apr 2023, 10:44
FlierMate2 wrote: Oh, I just realized that I don't know how to draw diagonal line! |
|||
18 Apr 2023, 10:44 |
|
Kitsune 18 Apr 2023, 11:22
Tanks for all your reply!
Roman wrote:
I'am curious to how to do this (using the video memory in assembly language). for now I have continue the first code and draw something with a loop to clear the screen and showing a sprite but I don't have back buffer so warning to your eyes: Code: format MZ start: ;macro pixel macro pixel column,row{ mov ah, 0ch ;change color of one pixel mov cx, column ;set column mov dx, row ;set row mov al, 14 ;set color to yellow int 10h ;put the pixel on screen } macro line start,endofline,row{ mov cx, start repeat endofline-start pixel cx,row inc cx end repeat } ;set the video mode to 13h (VGA 320*200 256 colors) mov ah,0 mov al,13h int 10h mov eax, 1 loop1: inc eax push eax ;draw lines of the sprite (start,end+1,row) line 160,165,100 line 158,167,101 line 157,168,102 line 156,169,103 line 156,169,104 line 155,167,105 line 155,164,106 line 155,161,107 line 155,164,108 line 155,167,109 line 156,169,110 line 156,169,111 line 157,168,112 line 158,167,113 line 160,165,114 ;clear the screen mov ax,0A000h mov es,ax xor di,0 xor al,0 mov cx,64000 rep stosb pop eax cmp eax,100 jb loop1 ;wait for a keypress mov ah,00h int 16h ;set DOS default text mode mov ah,00h mov al,03h int 10h ;terminate the program mov ah,4ch int 21h _________________ Kitsune |
|||
18 Apr 2023, 11:22 |
|
macomics 18 Apr 2023, 11:39
Code: macro line start,endofline,row{ mov cx, start repeat endofline-start pixel cx,row inc cx end repeat } If you want to create a loop, then use assembler commands with conditional jumps. Code: macro line start,endofline,row{ local .loop mov cx, start .loop pixel cx,row inc cx cmp cx, endlofine jc .loop } There are no additional debugging tools included with fasm. And since you are just starting to write programs in assembler, then you should choose a good debugger for yourself so that it is easier to correct logical errors and correctly represent the result of the compiler. Under DOS, I advise you to install TASM 5.0 and take the debugger TD.EXE from there. When you start writing programs for Windows, you should look at x64dbg. Last edited by macomics on 18 Apr 2023, 11:44; edited 1 time in total |
|||
18 Apr 2023, 11:39 |
|
FlierMate2 18 Apr 2023, 11:41
revolution wrote:
Thanks, I have some success! Code: format MZ start: ;set the video mode to 13h (VGA 320*200 256 colors) mov ah,0 mov al,13h int 10h mov [_x1], 280 mov [_y1], 180 mov [_x0], 40 mov [_y0], 20 call DrawLine ;wait for a keypress mov ah,00h int 16h ;set DOS default text mode mov ah,00h mov al,03h int 10h ;terminate the program mov ah,4ch int 21h ;Bresenham's line algorithm _dx dw 0 _dy dw 0 _x1 dw 0 _x0 dw 0 _y1 dw 0 _y0 dw 0 _x dw 0 _y dw 0 _D dw 0 ;plotLine(x0, y0, x1, y1) ; dx = x1 - x0 ; dy = y1 - y0 ; D = 2*dy - dx ; y = y0 ; ; for x from x0 to x1 ; plot(x, y) ; if D > 0 ; y = y + 1 ; D = D - 2*dx ; end if ; D = D + 2*dy DrawLine: mov dx, [_x1] mov [_dx], dx mov dx, [_x0] sub [_dx], dx mov dx, [_y1] mov [_dy], dx mov dx, [_y0] sub [_dy], dx mov ax, [_dy] mov dx, 2 mul dx sub ax, [_dx] mov [_D], ax mov cx, [_x0] mov dx, [_y0] mov [_y], dx redraw: push cx mov dx, [_y] call DrawPixel cmp [_D], 0 jg branch mov ax, [_dy] mov dx, 2 mul dx mov dx, [_D] add dx, ax mov [_D], dx jmp continue branch: add [_y], 1 mov ax, [_dx] mov dx, 2 mul dx mov dx, [_D] sub dx, ax mov [_D], dx continue: pop cx inc cx cmp cx, [_x1] jbe redraw ret DrawPixel: ;draw pixel - color purple mov ah,0ch mov al,5 ;color int 10h ret Maybe there is bug, the output is not 100% correct.
Last edited by FlierMate2 on 18 Apr 2023, 12:45; edited 1 time in total |
||||||||||
18 Apr 2023, 11:41 |
|
macomics 18 Apr 2023, 11:46
FlierMate2 wrote: Thanks, I have some success! |
|||
18 Apr 2023, 11:46 |
|
Kitsune 18 Apr 2023, 12:05
macomics wrote:
Thanks for the tips, need a colon ":" after ".loop" and it work. Code: macro line start,endofline,row{ local .loop mov cx, start .loop: pixel cx,row inc cx cmp cx, endlofine jc .loop } _________________ Kitsune |
|||
18 Apr 2023, 12:05 |
|
FlierMate2 18 Apr 2023, 12:18
macomics wrote:
Thanks. Slightly better with boundary check: Code: DrawLine: mov dx, [_x1] mov [_dx], dx mov dx, [_x0] sub [_dx], dx ;dx = x1 - x0 mov dx, [_y1] mov [_dy], dx mov dx, [_y0] sub [_dy], dx ;dy = y1 - y0 mov ax, [_dy] mov dx, 2 mul dx sub ax, [_dx] mov [_D], ax ; D = 2*dy - dx mov cx, [_x0] ;for x from x0 to x1 mov dx, [_y0] mov [_y], dx ;y = y0 redraw: push cx mov dx, [_y] call DrawPixel ;plot(x, y) cmp [_D], 0 jg branch ;if D > 0 mov ax, [_dy] mov dx, 2 mul dx mov dx, [_D] add dx, ax mov [_D], dx ;D = D + 2*dy jmp continue branch: add [_y], 1 ;y = y + 1 mov ax, [_dx] mov dx, 2 mul dx mov dx, [_D] sub dx, ax mov [_D], dx ;D = D - 2*dx continue: pop cx inc cx cmp cx, 320 jae quit mov dx, [_y] cmp dx, 200 jae quit cmp cx, [_x1] ;for x from x0 to x1 jbe redraw quit: ret But it is not 40-280 for x, and 20-180 for y. Hmm.... I think either I follow the wrong code or I have bug when translating it to Assembly code. Sorry everyone.
Last edited by FlierMate2 on 18 Apr 2023, 12:44; edited 1 time in total |
||||||||||
18 Apr 2023, 12:18 |
|
FlierMate2 18 Apr 2023, 12:44
I know why it doesn't work, need to test for signed integer, NOT unsigned.
This is the correction: Code: cmp [_D], 0 jg branch ;if D > 0 ...instead of "ja branch". Also, might need to decrement "x" if x0 is greater than x1. Currently it assumes x1 is always greater than x0. Code: mov [_x1], 280 mov [_y1], 100 mov [_x0], 40 mov [_y0], 50 call DrawLine mov [_x1], 280 mov [_y1], 80 mov [_x0], 40 mov [_y0], 80 call DrawLine mov [_x1], 300 mov [_y1], 180 mov [_x0], 20 mov [_y0], 20 call DrawLine
|
||||||||||
18 Apr 2023, 12:44 |
|
Roman 18 Apr 2023, 14:06
Write antialiasing for lines
|
|||
18 Apr 2023, 14:06 |
|
FlierMate2 18 Apr 2023, 14:43
Roman wrote: Write antialiasing for lines https://en.wikipedia.org/wiki/Xiaolin_Wu%27s_line_algorithm (Xiaolin Wu's line algorithm) |
|||
18 Apr 2023, 14:43 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.