Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - jacobly

Pages: 1 ... 7 8 [9] 10 11 ... 14
121
The Axe Parser Project / Re: Assembly Programmers - Help Axe Optimize!
« on: December 20, 2011, 04:47:46 am »
p_DrawOff: save 1 byte, save ~40 cycles
Original
Code: [Select]
xor a
ld e,a
dec a
__DrawOffShift:
srl c
rr e
rra
djnz __DrawOffShift
dec d
jr z,__DrawOffSkipRight
ld b,a
and (hl)
or e
ld (hl),a
ld a,b
__DrawOffSkipRight:
dec hl
inc d
jr z,__DrawOffSkipLeft
cpl
and (hl)
or c
ld (hl),a
__DrawOffSkipLeft:
Optimized
Code: [Select]
xor a
ld e,$FF
__DrawOffShift:
srl c
rr e
rra
djnz __DrawOffShift
dec d
jr z,__DrawOffSkipRight
ld b,a
or (hl)
and e
ld (hl),a
ld a,b
__DrawOffSkipRight:
dec hl
inc d
jr z,__DrawOffSkipLeft
and (hl)
or c
ld (hl),a
__DrawOffSkipLeft:

p_Pix: save 2 bytes, save ~6 cycles
Original
Code: [Select]
p_Pix:
.db __PixEnd-1-$ ;Draws pixel (c,l)
ld de,plotSScreen
pop af
pop bc
push af
ld b,0

ld a,l
cp 64
ld a,b
ret nc
ld a,c
cp 96
ld a,b
ret nc

ld h,b
ld a,l
add a,a
add a,l
ld l,a
add hl,hl
add hl,hl
add hl,de
ld a,c
srl c
srl c
srl c
add hl,bc
and %00000111
ld b,a
ld a,%10000000
ret z
___GetPixLoop:
rrca
djnz ___GetPixLoop
ret
__PixEnd:
Optimized
Code: [Select]
p_Pix:
.db __PixEnd-1-$ ;Draws pixel (c,l)
ld de,plotSScreen
pop af
pop bc
push af
ld b,0

ld a,c
cp 96
ld a,b
ret nc
sla l
ret c
sla l
ret c

ld h,b
ex de,hl
add hl,de
add hl,de
add hl,de
ld a,c
srl c
srl c
srl c
add hl,bc
and %00000111
ld b,a
ld a,%10000000
ret z
___GetPixLoop:
rrca
djnz ___GetPixLoop
ret
__PixEnd:

p_ArcTan: save 1 byte, save ~1 cycle
Original
Code: [Select]
p_ArcTan:
.db __ArcTanEnd-1-$
ex de,hl ;de = y
pop hl
ex (sp),hl ;hl = x
push hl
ld a,h ;\
xor d ;/ Get parity
jp m,__ArcTanSS-p_ArcTan-1
add hl,de ;\
jr __ArcTanDS ; |
__ArcTanSS: ; |hl = x +- y
sbc hl,de ; |
__ArcTanDS: ;/
ex de,hl ;de = x +- y
ld b,6 ;\
__ArcTan64: ; |
add hl,hl ; |hl = 64y
djnz __ArcTan64 ;/
call $3F00+sub_SDiv ;hl = 64y/(x +- y)
pop af ;\
rla ; |Right side, fine
ret nc ;/
sbc a,a ;\
sub h ; |Reverse sign extend
ld h,a ;/
ld a,l ;\
add a,128 ; |Add or sub 128
ld l,a ;/
ret
__ArcTanEnd:
Optimized
Code: [Select]
p_ArcTan:
.db __ArcTanEnd-1-$
ex de,hl ;de = y
pop hl
ex (sp),hl ;hl = x
push hl
ld a,h ;\
xor d ;/ Get parity
jp m,__ArcTanSS-p_ArcTan-2
add hl,de ;\
ld c,c \ .db $FA ; |
;jr __ArcTanDS ; |
__ArcTanSS: ; |hl = x +- y
sbc hl,de ; |
__ArcTanDS: ;/
ex de,hl ;de = x +- y
ld b,6 ;\
__ArcTan64: ; |
add hl,hl ; |hl = 64y
djnz __ArcTan64 ;/
call $3F00+sub_SDiv ;hl = 64y/(x +- y)
pop af ;\
rla ; |Right side, fine
ret nc ;/
sbc a,a ;\
sub h ; |Reverse sign extend
ld h,a ;/
ld a,l ;\
add a,128 ; |Add or sub 128
ld l,a ;/
ret
__ArcTanEnd:

122
The Axe Parser Project / Re: Features Wishlist
« on: December 20, 2011, 12:50:23 am »
If 32-bit *^ is added, then something like /^ that returns the quotient and remainder would be useful.

123
Computer Programming / Re: QuadDouble precision
« on: December 13, 2011, 07:08:46 pm »
BigDecimal can do whatever precision you specify, so it's speed would be proportional to that.
The question is, do you actually need floating points (If you want speed that is.)
Maybe you can use an array of longs, for example, as fixed point.

124
Computer Programming / Re: QuadDouble precision
« on: December 13, 2011, 07:00:24 pm »
java.math.BigDecimal!

125
Axe / Re: Axe Q&A
« on: December 13, 2011, 06:20:40 pm »
Oh whoops didn't see there was another page XD But yeah, you can have named constants but not named variables, unless you use a constant as a pointer to a variable o.O
Ahem...
Code: [Select]
°A-2→°MYVAR
5→MYVAR
MYVAR++
MYVAR*13→MYVAR
Disp MYVAR▸Dec,i .Prints 78

Code: [Select]
:If something
:Data(.......)→Pic1
:End
:If somethingelse
:Data(.......)→Pic1
:End
Gives me a duplicate error. (and I know that it should happen)
Is there a way to get around with it?
Also, if something is a constant, you can do this in Axe 1.1.0:
Code: [Select]
:...If something
:Data(.......)→Pic1
:...
:...If somethingelse
:Data(.......)→Pic1
:...

126
Axe / Re: Routines
« on: December 13, 2011, 03:46:34 am »
Spoiler For guess:
Sierpinski-ish?
################################################################
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ##  ## 
#   #   #   #   #   #   #   #   #   #   #   #   #   #   #   #   
####    ####    ####    ####    ####    ####    ####    ####   
# #     # #     # #     # #     # #     # #     # #     # #     
##      ##      ##      ##      ##      ##      ##      ##     
#       #       #       #       #       #       #       #       
########        ########        ########        ########       
# # # #         # # # #         # # # #         # # # #         
##  ##          ##  ##          ##  ##          ##  ##         
#   #           #   #           #   #           #   #           
####            ####            ####            ####           
# #             # #             # #             # #             
##              ##              ##              ##             
#               #               #               #               
################                ################               
# # # # # # # #                 # # # # # # # #                 
##  ##  ##  ##                  ##  ##  ##  ##                 
#   #   #   #                   #   #   #   #                   
####    ####                    ####    ####                   
# #     # #                     # #     # #                     
##      ##                      ##      ##                     
#       #                       #       #                       
########                        ########                       
# # # #                         # # # #                         
##  ##                          ##  ##                         
#   #                           #   #                           
####                            ####                           
# #                             # #                             
##                              ##                             
#                               #                               
################################
# # # # # # # # # # # # # # # #
##  ##  ##  ##  ##  ##  ##  ## 
#   #   #   #   #   #   #   #   
####    ####    ####    ####   
# #     # #     # #     # #     
##      ##      ##      ##     
#       #       #       #       
########        ########       
# # # #         # # # #         
##  ##          ##  ##         
#   #           #   #           
####            ####           
# #             # #             
##              ##             
#               #               
################
# # # # # # # #
##  ##  ##  ## 
#   #   #   #   
####    ####   
# #     # #     
##      ##     
#       #       
########       
# # # #         
##  ##         
#   #           
####           
# #             
##             
#               
I feel like a computer now... :P

127
The Axe Parser Project / Re: Bug Reports
« on: December 12, 2011, 11:33:01 pm »
This is from Commands.htm:
EndIf EXP     In loops, it works just like a regular "End" if the condition is true. But it will exit the loop if the condition is false.
End!If EXP     In loops, it works just like a regular "End" if the condition is false. But it will exit the loop if the condition is true.

But according to the way Axe behaves, shouldn't it be something like this:
EndIf EXP     In loops, it will exit the loop if the condition is true. But it works just like a regular "End" if the condition is false.
End!If EXP     In loops, it will exit the loop if the condition is false. But it works just like a regular "End" if the condition is true.

128
TI Z80 / Re: Seeker
« on: December 12, 2011, 11:21:15 pm »
Hmm... a 2x3 pixel sprite only takes up 2 bytes. Did you mean a 6x64 pixel sprite maybe?
Code: [Select]
: [0640 FFFFFFFFFFFFFFFF 0000000000000000 FFFFFFFFFFFFFFFF FF818181818181FF FF818181818181FF FF818181818181FF]->Pic1
: ClrDraw
: Bitmap(10,20,Pic1)
: DispGraph
: Pause 1000

129
The Axe Parser Project / Re: Features Wishlist
« on: December 12, 2011, 10:13:12 pm »
4*^B returns the same thing it did before, the high word. The ➔(r₁,r₂) does almost the same thing as ➔r₁, except that in addition, the low word of the last *^ is stored to r₂.
However, feel free to make other suggestions. I'm still open to other ideas. :)

130
The Axe Parser Project / Re: Features Wishlist
« on: December 12, 2011, 09:50:04 pm »
The number is stored it a "safe" place until it is recalled ;)
It doesn't even have to ever be used.

131
The Axe Parser Project / Re: Features Wishlist
« on: December 12, 2011, 09:17:16 pm »
Here's an example of how I use it.
Code: [Select]
:r₁∗r₃+(r₂∗^r₃)➔r₁:r₂∗r₃➔r₂

So, my idea is to change the syntax to something like.
Code: [Select]
:r₁∗r₃+(r₂∗^r₃)➔(r₁,r₂) .Basically store high word (plus r₁∗r₃) to r₁, and the low word (not affected by the add) to r₂.
This has the added advantage that ➔( doesn't seem to mean anything in the current version (also, it causes an invalid token error). To compare with what Quigibo suggested, ➔(A,B) would be equivalent to ➔A(or B):<undecided token>➔B(or A), with the advantage of not using another token, and being more intuitive.

Code: [Select]
:r₁∗r₃+(r₂∗^r₃)➔r₁ .This would also work, storing just the high word (plus r₁∗r₃) to r₁, just like before.
:r₁∗r₃+(r₂∗^r₃)➔(r₁,) .maybe same as the last last line, but returns low the low word of the multiplication, rather than the value of r₁?

Spoiler For Implementation:
Use memory:
   Axe.inc:
      axv_Extra        =;MD5Temp, axv_SpriteBuff+6, axv_Y3t, OP1+0..64, whatever
      ; If you are wondering about the axv_SpriteBuff+6, I was thinking that it would be
      ; cool if there were an alternate ▸Dec that put the 5+1 byte string in axv_SpriteBuff.
      ; The leading zeros could even be removed this way (by the routine or in Axe).
      ; The routine/Axe code would just increment the pointer past the leading zeros...
      ; Anyway, my point is that even this wouldn't interfere with axv_SpriteBuff+6,
      ; only the sprite routines would affect it.
   Compiling:
      exp1∗^exp2 compiles to:
         ; load hl and de
         call sub_MulFull
         ld (axv_Extra),hl ; or better yet, put these in MulFull
         ld h,c ; especially if you take Runer's suggestion to break
         ld l,a ; Mul88's reliance on MulFull.
      ➔(var1,var2) compiles to:
         ld (°var1),hl ; only if var1 present?
         ld hl,(axv_Extra) ; always?
         ld (°var2),hl ; only if var2 present?
A cool thing I just noticed, is that both left to right parsing and the old functionality of sub_MulFull are preserved, and as far as I can tell, compatibility is 100% preserved (even with the few Asm( hacks I can think of!) 8)


Or a more optimized idea – use registers:
   Compiling:
      exp1∗^exp2 compiles to:
         call sub_MulFull
         ex de,hl ; or better yet, put these in MulFull
         ld h,c ; especially if you take Runer's suggestion to break
         ld l,a ; Mul88's reliance on MulFull.
      ➔(var1,var2) compiles to:
         ld (°var1),hl
         ld (°var2),de
But of course this is probably way too volatile to be user friendly. (although with peephole... :))
Oh, especially since my Axe code example above wouldn't work!

In the future, this syntax could definitely be useful for new commands that return more than one value.

Lol, I used Axe syntax in assembly :P

On an unrelated note, I just 2nd+Off on the Axe error screen, and now free mem = 0. Shouldn't B_CALL(_GetKeyRetOff) be used here? Unless zStart had something to do with it...

132
ASM / Re: 24 bit multiplication
« on: December 12, 2011, 07:07:45 pm »
I do have a 24-bit floating-point multiplication routine ;D

saved 2 bytes, 1149 cycles saved by using iy too (and in a way compatible with TIOS, imagine that)
Code: [Select]
; hldebc = hlc * bde
ld (iy+asm_Flag1),b
xor a
ld ix,0
ld b,24
Loop:
add ix,ix
rla
rl c
adc hl,hl
jr nc,Next
add ix,de
adc a,(iy+asm_Flag1)
rl c
jr nc,Next
inc hl
Next:
djnz Loop
ld e,a
ld d,c
push ix ; ld c,ixl
pop bc ; ld b,ixh

Jacobly, are you sure this works because I've been going through the code and it seems to me like the second 'rl c' should instead be 'add carry flag to c'. 2 times 'rl c' per loop seems wrong to me. Could you explain please? Because I've tried it as well in wabbitemu, taking the different input in account, and it is still not doing the right thing.

That's strange. My test program must not have been working right, because when I went back and changed it a bit, it suddenly started telling me that the second routine doesn't work. :/
Anyway, my new test program seems to agree with this change. :)
Code: [Select]
; hldebc = hlc * bde
ld (iy+asm_Flag1),b
xor a
ld ix,0
ld b,24
Loop:
add ix,ix
rla
rl c
adc hl,hl
jr nc,Next
add ix,de
adc a,(iy+asm_Flag1)
jr nc,Next
inc c
jr nz,Next
inc hl
Next:
djnz Loop
ld e,a
ld d,c
push ix ; ld c,ixl
pop bc ; ld b,ixh

133
TI Z80 / Re: [discontinued] polygon-based 3D engine (with textures)
« on: December 11, 2011, 09:27:40 pm »
Wow, good eye on catching those bugs so quickly! =)
I wouldn't exactly call it quick. I've been wondering about this since November. :/

I think there is a reason why jacobly has an average of more than 1 uprate per 2 posts O.O Good eye.
Yeah, I tried posting more, but then I just ended up with more uprates. :P

134
TI Z80 / Re: [discontinued] polygon-based 3D engine (with textures)
« on: December 11, 2011, 05:00:15 pm »
Umm... so I *just* figured out the problem. (There are actually two bugs, but one hides the other)

First of all, you cannot call GetPixel with a negative column, and expect meaningful results. The first step in fixing this, is to change negative columns to zero, with the code such as the following, before call GetPixel.
Code: [Select]
 bit 7,a
  jr z,TGetPixel
  xor a
TGetPixel:
The second step is to change horizontal clipping. When the col is negative, (pointer) and (mask) should not change, so that when col becomes zero, they are already set up correctly.
Code: [Select]
 ld a, (temp)
  bit 7, a
  jr nz, TNoCarry ;instead of TEndPlot

If you just change the above code, there are still problems because there is an even more subtle and tricky bug. When you order the start and end of the scanline, so the start is before the end, you do an unsigned compare, which causes the wrong result if start and end have opposite signs (which is the case when there is clipping).
Code: [Select]
;Initialize variables for the scanline
  ld hl, (tu1)
  ld (tmpu), hl
  ld hl, (tv1)
  ld (tmpv), hl
  ld hl, (tu2)
  ld (temp2), hl
  ld hl, (tv2)
  ld (temp3), hl
  ld a, (tx2+1)
  ld (temp+1), a
  add a,128 ;!added!
  ld b, a
  ld a, (tx1+1)
  ld (temp), a
  add a,128 ;!added!
  cp b
  jr c, TOrdered
  ;jp po, TOrdered
  ld hl, (tu2)
  ld (tmpu), hl
  ld hl, (tv2)
  ld (tmpv), hl
  ld hl, (tu1)
  ld (temp2), hl
  ld hl, (tv1)
  ld (temp3), hl
  ld a, (tx2+1)
  ld (temp), a
  ld a, (tx1+1)
  ld (temp+1), a
TOrdered:

135
ASM / Re: 24 bit multiplication
« on: December 11, 2011, 02:48:20 pm »
Code: [Select]
// Multiply a times b
temp = 0
repeat for each bit in a
temp <<= 1
if (high bit of a set)
temp += b
a <<= 1
return temp
if a and b are 2 bytes, temp is 4 bytes, and you loop 16 times.
Spoiler For for code:
stolen from Axe
p_MulFull:
   ; Input in hl and de, result in cahl
   ld   c,h
   ld   a,l
   ld   hl,0   ;11
   ld   b,16   ;7
__MulFullNext:
   add   hl,hl   ;11
   rla      ;4
   rl   c   ;8
   jr   nc,__MulFullSkip   ;12/7
   add   hl,de   ;11
   adc   a,0   ;7
   jr   nc,__MulFullSkip
   inc   c
__MulFullSkip:
   djnz   __MulFullNext
   ret
__MulFullEnd:

Code: [Select]
// Sqrt a
temp = high byte of a
a <<= 8
b = 0
repeat for every 2 bits in a
test = b << 8 + 0x40
b <<= 1
if (temp >= test)
temp -= test
set low bit of b
temp += high 2 bits of a
a <<= 2
return b
If a is 4 bytes, then b and temp are 2 bytes, and you loop 16 times.
Spoiler For code:
stole my own routine from axe (and modified it)
p_Sqrt88:
   ; input in hlde, result in de
   ld   b,16
   ld   a,h
   ld   c,l
   push   de ; ld ixh,d
   pop   ix ; ld ixl,e
   ld   de,0
   ld   h,d
   ld   l,e
__Sqrt88Loop:
   sub   $40
   sbc   hl,de
   jr   nc,__Sqrt88Skip
   add   a,$40
   adc   hl,de
__Sqrt88Skip:
   ccf
   rl   e
   rl   d
   add   ix,ix
   rl   c
   rla
   adc   hl,hl
   add   ix,ix
   rl   c
   rla
   adc    hl,hl
   djnz   __Sqrt88Loop
   ret
__Sqrt88End:

Kool. Thanks. But, shouldn't the first one have two inputs?

Of course, hl and de, isn't that what I said ;)

Pages: 1 ... 7 8 [9] 10 11 ... 14