Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

pixels

octavio2octavio2 Member Posts: 16
;autor: Octavio Vega
;use a86
;demo that uses 64k colors vesa videomodes

inicio:
mov si,videomodes64k
l1: ;search for a supported videomode 64k colors
mov ax,[si]
test ax,ax
jz >l2
add si,2
call setvideomode
test ax,ax
jz l1
mov dx,63
call mandeldibu ;draw
l2:
ret


setvideomode: ;videomode en ax
pusha
mov bp,sp
sub sp,256 ;bufer for vesa data
mov bx,ax
mov es,ss
mov di,sp
mov cx,ax
mov ax,4f01 ;get videomode info
int 10h
cmp ax,4fh
je >l2
l1:
;not available
mov sp,bp
popa
xor ax,ax
ret
l2:
mov ax,4f02
int 10h ;set videomode
cmp ax,4fh
jne l1
db 102
push [di+12]
db 102
pop [cs:fcvesa+1] ;address of vesa function for switch memory bank
push [w di+16]
pop [w bytesporlinea]
push [w di+8]
pop es ;videoseg
mov ax,[w di+18]
dec ax
mov [w xmax],ax
mov ax,[w di+20]
dec ax
mov [w ymax],ax
mov al,[di+25]
mov cx,[di+4] ;granularity
xor ax,ax
shl cx,9
l1:
shl cx,1
jz >l2
inc al
jmp l1
l2:
mov [cs:fcvesa-1],al
l3:
mov [b ACPAG],0
mov sp,bp
popa
ret

setpixel: ;(cx,ax)
pusha
mov bl,[b blue]
mov dx,[w green] ;dl=g dh=r
and dx,0f8fch ;convert color (8b,8g,8r)->(5b,6g,5r)
shr bl,3
xchg bl,dl
xor bh,bh
shl bx,3
or bx,dx
mul [w bytesporlinea] ;calculate address of video memory
add cx,cx
add ax,cx
adc dl,0
mov di,ax
cmp [b ACPAG],dl
jne >l1
mov [es:di],bx ;write pixel
popa
ret
l1:
;vesabank switch video memory
push bx
mov [b ACPAG],dl
xor bx,bx ;select writable video memory
sal dx,0fh ;constant is set by "setvideomode"
fcvesa:
call 0ffffffffh ;constant is set by "setvideomode"
pop bx
mov [w es:di],bx
popa
ret

mandeldibu:
mov ax,[w xmax]
mov cx,[w ymax]
pusha
finit
mov si,mandeldata2
mov bp,sp
fild [w xmax] ;xmax
fdivr [d si+8] ;lado_x
fstp [d bp] ;x_escala
fild [w ymax] ;ymax
fdivr [d si+12] ;lado_y
fstp [d bp+4] ;y_escala
l1:
finit
fild [w si+16]
fild [w bp+14] ;x
fmul [d bp] ;x_escala
fadd [d si] ;izq
fild [w bp+12] ;y
fmul [d bp+4]
fadd [d si+4]
fldz
fldz
mov cx,[bp+10] ;63
l3:
fld 1
fmul 2
fld 1
fmul 2
fld 1
fsub 1
fcomp 7
fstsw ax
sahf
jnb >l4
fsub
fadd 4
fchs
fxch 2
fmulp
fadd 0
fadd 2
loop l3
l4:
mov bx,[bp+14]
shl bx,6
mov bl,64
sub bl,cl
mov dl,cl
shl dl,3
add dl,64
shl bl,3
add bh,bl
add bl,bl
mov [b blue],dl
mov [b green],bl
mov [b red],bh
mov cx,[bp+14]
mov ax,[bp+12]
call setpixel
dec [w bp+14]
jns l1
mov ax,[w xmax]
mov [w bp+14],ax
dec [w bp+12]
jns l1
popa
ret

mandeldata2:
dd -2.0 ; izq
dd 2.0 ; arb
dd 4.0 ; lado_x
dd -4.0 ; lado_y
dw 8 ; limite
videomodes64k: dw 11ah,117h,114h,111h,10eh,0
xmax: dw ?
ymax: dw ?
bytesporlinea: dw ?
acpag: db ? ;actual page of videomemory
blue: db ?
green: db ?
red: db ?

Comments

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    _ / http://forcoder.org / free ebooks and video tutorials about // Go, MATLAB, Ruby, Visual Basic, Assembly, Swift, C, Objective-C, Delphi, PL/SQL, Visual Basic .NET, Python, C++, C#, Java, JavaScript, Scratch, R, Perl, PHP Apex, Fortran, FoxPro, Scala, Ada, Lua, Bash, Crystal, Hack, D, ML, Logo, Prolog, Rust, SAS, Julia, Awk, ABAP, Transact-SQL, Alice, LabVIEW, Dart, VBScript, Clojure, Scheme, Erlang, COBOL, Kotlin, F#, Lisp //

Sign In or Register to comment.