this only produces garbage, trying to show a X^2 curve onscreen

Started by daydreamer, January 21, 2009, 08:41:11 PM

Previous topic - Next topic

daydreamer

trying to get the range 0.0 -> 1.0 in a y=x^2 curve showed onscreen nicely
note I output it kinda textured
which was now out adresses for colors again?
   .model tiny
    .686p
    .XMM
    .stack
   
    GETKEY MACRO
      mov   ah,0
      int   16h
    ENDM
   
    mode13 MACRO
    mov ax,013h ;13h
    int 10h
    mov ax,0A000h
    mov es,ax
    ENDM
.data?
;map db 32000 dup (?)
ad dw ?
finc REAL4 ?
angle1 REAL4 ?
angle2 REAL4 ?
xm REAL4 ?
ym REAL4 ?
xf2 REAL4 ?
yf2 REAL4 ?
x dw ?
tmp REAL8 ?
.data
;map  ;db "zzzzzzzzzzzzzzzz"
     ;db 0 dup (240)
map2     db "z05050505050505z"
     ;db 0 dup (240)
     ;db "z50505050505050z"
     ;db 0 dup (240)
     ;db "z05050505050505z"
     ;db 0 dup (240)
     ;db "z505  050505050z"
     ;db 0 dup (240)
     ;db "z050  505050505z"
     ;db 0 dup (240)
     ;db "z50505050505050z"
     ;db 0 dup (240)
     ;db "zzz0000000000zzz"
     ;db 0 dup (240)
     ;db "z00000000000000z"
     ;db 0 dup (240)
     ;db "z000z00000z0000z"
     ;db 0 dup (240)
     ;db "z00000000000000z"
     ;db 0 dup (240)
     ;db "z000z00000z0000z"
     ;db 0 dup (240)
     ;db "z00000000000000z"
     ;db 0 dup (240)
     ;db "z00000000000000z"
     ;db 0 dup (240)
     ;db "z0000zz00zz0000z"
     ;db 0 dup (240)
     ;db "zzzzzzzzzzzzzzzz"
     sc dw 200
     wd dw 320
     i real8 0.005
     i2 real8 0.0
;anglei1 dw 0
;scale dw 4096
;squares dw 256
;xray dw 0
;yray dw 0
;degrees dw 1920
;degrees2 dw 960
;cols dw 256
;xf  REAL4 64.0
;yf  REAL4 64.0

   
.code
    .startup
    mode13
    finit
    xor di,di
    mov cx,200
@@l1:   lea si,map2
    mov x,cx
    fld i2
    fadd i
    fst i2
    fmul i2
    fimul wd
    fistp x
    pop di
    add di,x
    push di
    movsd
    ;movsd
    pop di
   
    add di,320
    dec cx
    jne @@l1
   
   
     GETKEY

         
    .exit
end


FORTRANS

Hello,

   No one else has responded, so... I looked at your posted code, but
not assembled it.  So, this may be a bit off.

   You seem to be POPping DI twice and PUSHing it once in your loop.

   You are using MOVSD and mode 13H pixels are bytes (MOVSB).

   Ports for setting colors are 3C8 and 3C9.  But BIOS function AH =10H,
AL = 12H, INT 10H works pretty much the same.

Steve N.

daydreamer

Quote from: FORTRANS on January 23, 2009, 03:03:09 PM
Hello,

   No one else has responded, so... I looked at your posted code, but
not assembled it.  So, this may be a bit off.

   You seem to be POPping DI twice and PUSHing it once in your loop.

   You are using MOVSD and mode 13H pixels are bytes (MOVSB).

   Ports for setting colors are 3C8 and 3C9.  But BIOS function AH =10H,
AL = 12H, INT 10H works pretty much the same.

Steve N.
thanks, corrected it and it shows a strange curve, more like several lines with different angles connected to each other than a smooth curve
anyway I intentionally make use of unaligned/aligned MOVSD because I gonna output texture and later sprites than single pixels

MichaelW

Here is my attempt at it. The curve shows visible steps, but the only way I can see around this would be some sort of more or less complex anti-aliasing scheme, that would probably not work very well with only 16 simultaneous colors.

;====================================================================
.model small,c
.386
.stack
;====================================================================

PSet PROTO x:WORD, y:WORD, color:WORD

;====================================================================

FLD8 MACRO fpvalue
  LOCAL name
  .data
    name REAL8 fpvalue
  .code
  fld name
ENDM

;====================================================================

.data

  cw  dw  0
  xc  dw  0
  yc  dw  0

.code

;====================================================================

.startup

    MODE equ 12h
    WD equ 640.0
    HT equ 480.0

    ;MODE equ 13h
    ;WD equ 320.0
    ;HT equ 200.0

    mov ax, MODE
    int 10h

    finit
    FLD8 1.0                ; limit
    FLD8 0.001              ; inc, limit
    FLD8 HT                 ; HT, inc, limit
    FLD8 WD                 ; WD, HT, inc, limit
    fldz                    ; xc, WD, HT, inc, limit
  @@:
    fld st                  ; xc, xc, WD, HT, inc, limit
    fmul st, st             ; xc^2, xc, WD, HT, inc, limit
    fmul st, st(3)          ; xc^2*HT, xc, WD, HT, inc, limit
    fistp yc                ; xc, WD, HT, inc, limit
    fld st                  ; xc, xc, WD, HT, inc, limit
    fmul st, st(2)          ; xc*WD, xc, WD, HT, inc, limit
    fistp xc                ; xc, WD, HT, inc, limit
    fadd st, st(3)          ; xc+inc, WD, HT, inc, limit
    fwait

    invoke PSet, xc, yc, 9

    fcom st(4)              ; compare ST(0) to limit
    fstsw ax
    fwait
    sahf
    jb @B

    mov ah, 0
    int 16h

    mov ax, 3
    int 10h

.exit

;-------------------------------------------------------------
; This procedure uses the BIOS Write Graphics Pixel function,
; which should work for any of the VGA graphics modes.
;-------------------------------------------------------------

PSet proc uses ax bx cx dx x:WORD, y:WORD, color:WORD

    mov ax, color
    mov ah, 0ch
    xor bh, bh
    mov cx, x
    mov dx, y
    int 10h
    ret

PSet endp

;====================================================================
end


I see now that I probably should have added a finit after I exit the loop.
eschew obfuscation

FORTRANS

Hi,

   I changed one constant to get a slightly smoother curve
as it starts out..

    FLD8 0.0015625              ; inc


   Thanks for the example.

Steve N.