News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

appleshapes

Started by daydreamer, September 15, 2006, 06:15:47 AM

Previous topic - Next topic

daydreamer

is there a smoother way to code than rcr/adc/sbc combination for vectorgraphics ala appleshapes, where 3 bits represent a position and 2 first is move in x and y and third if plot or not?
   .model tiny
    .686p
    .XMM
    .stack
   
    GETKEY MACRO
      mov   ah,0
      int   16h
    ENDM
   
    mode13 MACRO
    mov ax,013h
    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 ?

.data
    shape db 15
.code
    .startup
    mode13
     mov ax,09000h ;setup an area to render 256x256
     mov ds,ax
     xor ax,ax
     mov cx,32768
     xor bx,bx
@@lcls:    mov [bx],ax ;clear that area
     inc bx
     inc bx
     dec cx
     jne @@lcls
     ;testrender a line, bh=y, bl=x
     mov si,0101h
     mov bx,08080h
     mov cx,8
     mov al,shape
     @@l1: mov [bx],si
          rcr al,1 ;if set add 1 to x
          adc bl,0
          rcr al,1 ;if set add 1 to y
          adc bh,0
          rcr al,1 ;if set plot a pixel else just move cursor
          jc @@l2
          mov [bx],si
          @@l2:
         
         
           


;copy to screen
     mov di,32
     xor si,si
     mov dx,200
    @@lc1: mov cx,256
     @@lc2:movsb
           dec cx
           jne @@lc2
           add di,64
           dec dx
           jne @@lc1
                 
   
   
         
   
     
     GETKEY
     
     .exit
end



sinsi

Maybe unpack the thing into bytes first? Is this a file format or yours?
Light travels faster than sound, that's why some people seem bright until you hear them.

daydreamer

Quote from: sinsi on September 15, 2006, 07:17:34 AM
Maybe unpack the thing into bytes first? Is this a file format or yours?
you need to unpack it anyway and I want the final result be sizelimited to for example 256b
but maybe use TEST followed by conditional code would be better?or if someone else has a better way?

I want to use a really compressed vectorformat and later change it to work in 3d also, so I digged up how apple II shapes works it can contain 3 vectors in each byte


zooba

TEST/Jcc probably won't provide any advantage, since you'll still need to shift and add. Though of course the only way to tell for certain is to try it.

Possibly a different format will provide some optimisations, storing a vector in 3 bits (which incidentally is only 2.67 vectors per byte - you'll be missing the on/off bit of the third) can certainly be inefficient in some cases. Consider the case of 2 dots - one at (0,0) and the other at (10,0). The shape for that would be written (in binary, X Y On/Off from left to right):

0 0 1 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1
0b, 01100100b, 10010010b, 01001001b, 00100101b
00h, 64h, 92h, 49h, 25h


Unless I've misinterpreted how it works, that's 5 bytes for two dots. Decide (and tell us  :toothy) whether you need to worry about code size/speed or data size. If the data needs to be really small, consider having encoded commands (such as, pen on/off, move to, etc.). If the code needs to be really small you can't go past a simple bitmap (which will of course make each shape/image huge).

Hope this helps,

Zooba :U

daydreamer

Quote from: zooba on September 15, 2006, 11:45:14 AM
TEST/Jcc probably won't provide any advantage, since you'll still need to shift and add. Though of course the only way to tell for certain is to try it.

Possibly a different format will provide some optimisations, storing a vector in 3 bits (which incidentally is only 2.67 vectors per byte - you'll be missing the on/off bit of the third) can certainly be inefficient in some cases. Consider the case of 2 dots - one at (0,0) and the other at (10,0). The shape for that would be written (in binary, X Y On/Off from left to right):

0 0 1 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 1
0b, 01100100b, 10010010b, 01001001b, 00100101b
00h, 64h, 92h, 49h, 25h


Unless I've misinterpreted how it works, that's 5 bytes for two dots. Decide (and tell us  :toothy) whether you need to worry about code size/speed or data size. If the data needs to be really small, consider having encoded commands (such as, pen on/off, move to, etc.). If the code needs to be really small you can't go past a simple bitmap (which will of course make each shape/image huge).

Hope this helps,

Zooba :U
originally you had scale and rotate shapes, so you implement scale x10 and only use 3 bits instead of 5 bytes

my plans was making the original format work first and after that a format which has 16 or 32 xdeltabits followed by 16 or 32 ydeltabits and didnt know where to place plot/noplot bits
thanks to you now I think I implement a 3rd datatype which is commands/runlength for penon/penoff, mirroron/off etc, so its always two bits until next command
I want both code/data be minimum size, but mostly data because I was thinking squeeze in few k polys in minimum size




daydreamer

I am clueless, why dont my code work carry on carry to adc's? but tests work?
I tried various shifts and add eax,eax now
it handles 32bit at a time now
but it only generates a single pixel, data is dword with all 1's which generates a diagonal line if I use tests

mov dl,0Fh
     mov bx,08080h
     mov cx,32
     mov eax,shape
        mov [bx],dl
     @@l1:
          test eax,1
          jc @@l3
          ;adc bl,1
          @@l3:
          add eax,eax ;if set add 1 to x
          adc bl,0
          test eax,1
          jc @@l4
          ;adc bh,1
          @@l4:
          add eax,eax ;if set add 1 to y
          adc bh,0
          ;rcr eax,1 ;if set plot a pixel else just move cursor
          ;jc @@l2
          mov [bx],dl
          @@l2:
          dec cx
          jne @@l1
         


MichaelW

If I understand how this is supposed to work, not having the ability to specify a sign for the deltas will severely limit the type of curves/shapes that can be generated. And for generating curves, in most cases only small deltas would be required.

eschew obfuscation

daydreamer

Michael, was going to add code for sub later, its either up/down movement and left/right movement

here is how original worked, now add a function to mirror a shape and you only need half amount of vectors, separate on/off bits to a separate data and you only need 2bits/vector in a case when you draw all the time

http://www.atariarchives.org/cgp/Ch03_Sec05.php

daydreamer

what about this solution:

.data
xcoord db 128
ycoord db 128
.code
xor si,si
@@l2: xor di,di
mov al,[shape+si]
mov cx,8
add ax,ax ;must use ax instead of al to contain all 8 bits
@@l1:push ax
and ax,2 ;either zero or 2
dec ax ;either -1 or 1
add [xcoord+di],al
pop ax
sar ax,1
inc di
and di,1 ;alternate between 0 and 1 = alternate between point to xcoord and ycoord
dec cx
jne @@l1
inc si
cmp si,length
jne @@l2