Author Topic: Texture drawing  (Read 38387 times)

0 Members and 3 Guests are viewing this topic.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Texture drawing
« Reply #60 on: July 01, 2011, 06:01:23 pm »
Awww, you're not a Brandon. As a general rule, people whose first names are Brandon are always supper uber-1337 coderz who can do pretty much anything they want with calculators.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #61 on: July 01, 2011, 06:03:18 pm »
Your previous post lets me think your name is Brandon. Am I correct?
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Texture drawing
« Reply #62 on: July 01, 2011, 06:04:07 pm »
O.o

No, but thanks for the compliment.

Calc84maniac, on the other hand...
« Last Edit: July 01, 2011, 06:04:56 pm by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #63 on: July 01, 2011, 06:07:44 pm »
But anyway, Why would you think I'm an uber 1337 coder when I'm just a newb?

* ben_g turns of his computer and will be gone for 10 days.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #64 on: July 14, 2011, 11:06:00 am »
I have ported half of the code to asm. This code should draw the top third of a textured quad. My problem is that it doesn't draw anything. It gets stuck in an endless loop, and I don't know why.

Spoiler For The code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TexQuad
;in: x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3, x4, y4, u4, v4
;out: textured quad is drawn to the buffer
TexQuad:
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld (temp), a
  ld a, (x1)
  ld b, a
  ld a, (x2)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (dx1), hl
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld (temp), a
  ld a, (x1)
  ld b, a
  ld a, (x3)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (dx2), hl
  ld a, (y2)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (x2)
  ld b, a
  ld a, (x4)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (dx3), hl
  ld a, (y3)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (x3)
  ld b, a
  ld a, (x4)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (dx4), hl
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld (temp), a
  ld a, (u1)
  ld b, a
  ld a, (u2)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (du1), hl
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld (temp), a
  ld a, (u1)
  ld b, a
  ld a, (u3)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (du2), hl
  ld a, (y2)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (u2)
  ld b, a
  ld a, (u4)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (du3), hl
  ld a, (y3)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (u3)
  ld b, a
  ld a, (u4)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (du4), hl
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld (temp), a
  ld a, (v1)
  ld b, a
  ld a, (v2)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (dv1), hl
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld (temp), a
  ld a, (v1)
  ld b, a
  ld a, (v3)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (dv2), hl
  ld a, (y2)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (v2)
  ld b, a
  ld a, (v4)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (dv3), hl
  ld a, (y3)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (v3)
  ld b, a
  ld a, (v4)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (dv4), hl
  ld hl, (x1)
  ld l, 0
  ld (tx1), hl
  ld hl, (x2)
  ld l, 0
  ld (tx2), hl
  ld hl, (u1)
  ld l, 0
  ld (tu1), hl
  ld hl, (v1)
  ld l, 0
  ld (tv1), hl
  ld hl, (u2)
  ld l, 0
  ld (tu2), hl
  ld hl, (v2)
  ld l, 0
  ld (tv2), hl
  ld hl, (y1)
  ld l, 0
  ld (_ty), hl

QuadDrawLoop1:
  ld a, (tx1)
  ld (temp), a      ;i=temp

QuadPlotLoop1:
  ld a, (tx1)
  ld b, a
  ld a, (tx2)
  sub b
  ld c, a
  ld a, (tx1)
  ld d, a
  ld e, 0
  ld a, (temp)
  sub b
  ld h, a
  ld l, 0
  call DivFP
  ld a, h
  ld (temp+1), a   ;tmp=temp+1
  ld b, a
  ld a, 1
  sub b
  ld d, a
  ld e, 0
  ld a, (tu1)
  ld b, a
  ld c, 0
  call MulFP
  push hl
  ld de, (temp+1)
  ld e, 0
  ld bc, (tu2)
  ld c, 0
  call MulFP
  pop de
  add hl, de
  ld a, h
  ld (temp2), a      ;u=temp2
  ld a, (temp+1)
  ld b, a
  ld a, 1
  sub b
  ld d, a
  ld e, 0
  ld a, (tv1)
  ld b, a
  ld c, 0
  call MulFP
  push hl
  ld de, (temp+1)
  ld e, 0
  ld bc, (tv2)
  ld c, 0
  call MulFP
  pop de
  add hl, de
  ld a, h
  ld (temp2+1), a      ;v=temp2+1
;Get the pixel at (u,v) from the texture
  ld a, (temp2+1)   ;load the v coordinate in a
  ld hl, texture
  ld d, 0
  ld e, a
  add hl, de
  ld a, (hl)      ;and load the byte of the v coordinate in a
  ld c, a
  ld a, (temp2)
  ld b, 1
  cp b
  jr c, BitShiftDone   ;no shifting if u=0
  ld b, a

BitShiftLoop:
  sll c
  djnz BitShiftLoop

BitShiftDone:
  push bc         ;1
  ld a, (_ty)
  ld l, a
  ld a, (temp)

getPixel:
   ld   h, 0
   ld   d, h
   ld   e, l
   
   add   hl, hl
   add   hl, de
   add   hl, hl
   add   hl, hl
   
   ld   e, a
   srl   e
   srl   e
   srl   e
   add   hl, de
   
   ld   de, PlotSScreen
   add   hl, de
   
   and   7
   ld   b, a
   ld   a, $80
   ret   z
   
   rrca
   djnz   $-1

  pop bc         ;0
  bit 7, c
  jr z, ResPixel

SetPixel:
  or (hl)
  ld (hl), a
  jr EndPlot

ResPixel:
  cpl
  and (hl)
  ld (hl), a

EndPlot:

  ld hl, (tx1)
  ld de, (dx1)
  add hl, de
  ld (tx1), hl
  ld hl, (tx2)
  ld de, (dx2)
  add hl, de
  ld (tx2), hl
  ld hl, (tu1)
  ld de, (du1)
  add hl, de
  ld (tu1), hl
  ld hl, (tu2)
  ld de, (du2)
  add hl, de
  ld (tu2), hl
  ld hl, (tv1)
  ld de, (dv1)
  add hl, de
  ld (tv1), hl
  ld hl, (tv2)
  ld de, (dv2)
  add hl, de
  ld (tv2), hl
  ld a, (_ty)
  inc a
  ld (_ty), a
  ld c, a
  ld a, (y2)
  ld h, a
  ld a, c
  ld c, h
  cp c
  jp nz, QuadDrawLoop1
  ret      ;voorlopig

All of the math routines are for 8.8 signed floating point math. These are all fully tested so they don't couse the cash.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Texture drawing
« Reply #65 on: July 14, 2011, 01:13:56 pm »
Now that is one of the scariest pieces of code I have ever seen.

And thisshould definitely be this
Code: [Select]
  ld a, (_ty)
  inc a
  ld (_ty), a
  ld c, a
  ld a, (y2)
  ld h, a
  ld a, c
  ld c, h
  cp c
  jp nz, QuadDrawLoop1
Code: [Select]
  ld hl, _ty
  inc (hl)
  ld a, (y2)
  cp (hl)
  jp nz, QuadDrawLoop1


But, as to why it's not actually working. Your loop should theoretically work as long as you are giving it valid numbers. (It will actually finish no matter what you give it though) So that leads me to believe that the problem is with your pixel plotting. Most likely, you are trying to plot pixels that are off screen and that is what is causing all of your problems. You end up plotting pixels in your program code, which causes crashes.

If you are really unlucky, you might even be plotting pixels at _ty.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #66 on: July 14, 2011, 05:18:07 pm »
Now that is one of the scariest pieces of code I have ever seen.
How do you mean?

But, as to why it's not actually working. Your loop should theoretically work as long as you are giving it valid numbers. (It will actually finish no matter what you give it though) So that leads me to believe that the problem is with your pixel plotting. Most likely, you are trying to plot pixels that are off screen and that is what is causing all of your problems. You end up plotting pixels in your program code, which causes crashes.

If you are really unlucky, you might even be plotting pixels at _ty.
I tried jumping over the plotting part, and it still crashes. By the way, this is done in an app, and ass variables defined inside the app itself won't work, then isn't the program protected against SMC?

By the way: thanks for the optimization.
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Texture drawing
« Reply #67 on: July 14, 2011, 05:43:19 pm »
It's scary because it's so massive and very repetitive (though I've seen worse; much, much worse). I'm sure with the proper optimizations you could probably cut about 25% or more off.

Anyways, I believe I found the error. You inlined your GetPixel which I think is rather funny, but there was an extra RET Z in it that you missed. This normally wouldn't cause crashes, but you did a PUSH BC around it, so you are returning into BC, which is definitely not a place where you want to go.

And yes, being in an app protects you accidental SMC.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #68 on: July 14, 2011, 06:42:07 pm »
The ret z dit couse the crash.

But it still doesn't work. It draws a line instaed while it should draw the top third of the quad in solid black (the texture is an 8x8 solid rectangle).

My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #69 on: July 16, 2011, 07:44:20 pm »
many thanks to thepenguin77 and calc84 for helping me through omnomIRC.

But it still doesn't work. It gets stuck in a endless loop again.

I included the most recent scource code.
Spoiler For source code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;TexQuad
;in: x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3, x4, y4, u4, v4
;out: textured quad is drawn to the buffer
TexQuad:
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld (temp), a
  ld a, (x1)
  ld b, a
  ld a, (x2)
  sub b
  ld h, a
  ld l, 0
  ld de, (temp)
  ld e, 0
  call DivFP
  ld (dx1), hl
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld (temp), a
  ld a, (x1)
  ld b, a
  ld a, (x3)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (dx2), hl
  ld a, (y2)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (x2)
  ld b, a
  ld a, (x4)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (dx3), hl
  ld a, (y3)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (x3)
  ld b, a
  ld a, (x4)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (dx4), hl
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld (temp), a
  ld a, (u1)
  ld b, a
  ld a, (u2)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (du1), hl
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld (temp), a
  ld a, (u1)
  ld b, a
  ld a, (u3)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (du2), hl
  ld a, (y2)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (u2)
  ld b, a
  ld a, (u4)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (du3), hl
  ld a, (y3)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (u3)
  ld b, a
  ld a, (u4)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (du4), hl
  ld a, (y1)
  ld b, a
  ld a, (y2)
  sub b
  ld (temp), a
  ld a, (v1)
  ld b, a
  ld a, (v2)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (dv1), hl
  ld a, (y1)
  ld b, a
  ld a, (y3)
  sub b
  ld (temp), a
  ld a, (v1)
  ld b, a
  ld a, (v3)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (dv2), hl
  ld a, (y2)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (v2)
  ld b, a
  ld a, (v4)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (dv3), hl
  ld a, (y3)
  ld b, a
  ld a, (y4)
  sub b
  ld (temp), a
  ld a, (v3)
  ld b, a
  ld a, (v4)
  sub b
  ld h, a
  ld l, 0
  ld a, (temp)
  ld d, a
  ld e, 0
  call DivFP
  ld (dv4), hl
  ld a, (x1)
  ld h, a
  ld l, 0
  ld (tx1), hl
  ld a, (x2)
  ld h, a
  ld l, 0
  ld (tx2), hl
  ld a, (u1)
  ld h, a
  ld l, 0
  ld (tu1), hl
  ld a, (v1)
  ld h, a
  ld l, 0
  ld (tv1), hl
  ld a, (u2)
  ld h, a
  ld l, 0
  ld (tu2), hl
  ld a, (v2)
  ld h, a
  ld l, 0
  ld (tv2), hl
  ld a, (y1)
  ld (_ty), a

QuadDrawLoop1:
  ld a, (tx1)
  ld (temp), a      ;i=temp

QuadPlotLoop1:
  ld a, (tx1)
  ld b, a
  ld a, (tx2)
  sub b
  ld c, a
  ld a, (tx1)
  ld d, a
  ld e, 0
  ld a, (temp)
  sub b
  ld h, a
  ld l, 0
  call DivFP
  ld a, h
  ld (temp+1), a   ;tmp=temp+1
  ld b, a
  ld a, 1
  sub b
  ld d, a
  ld e, 0
  ld a, (tu1)
  ld b, a
  ld c, 0
  call MulFP
  push hl
  ld a, (temp+1)
  ld d, a
  ld e, 0
  ld a, (tu2)
  ld b, a
  ld c, 0
  call MulFP
  pop de
  add hl, de
  ld a, h
  ld (temp2), a      ;u=temp2
  ld a, (temp+1)
  ld b, a
  ld a, 1
  sub b
  ld d, a
  ld e, 0
  ld a, (tv1)
  ld b, a
  ld c, 0
  call MulFP
  push hl
  ld a, (temp+1)
  ld d, a
  ld e, 0
  ld a, (tv2)
  ld b, a
  ld c, 0
  call MulFP
  pop de
  add hl, de
  ld a, h
  ld (temp2+1), a      ;v=temp2+1
;Get the pixel at (u,v) from the texture
  ld   hl, (temp2+1)
   ld   h, 0      ;1 byte smaller

   ld   de, texture
   add   hl, de

   ld   a, (temp2)
   ld   b, a
   inc   b
   ld a, (hl)
shiftLoop:
   rl   c
   djnz   shiftLoop   ;the extra shift gets rid of the jr
            ;and pulls the bit out of carry

BitShiftDone:
  push af         ;1
  ld a, (_ty)
  ld l, a
  ld a, (temp)
  ld b, 94
  cp b
  jr nc, ContDrawLoop1

getPixel:
   ld   h, 0
   ld   d, h
   ld   e, l
   
   add   hl, hl
   add   hl, de
   add   hl, hl
   add   hl, hl
   
   ld   e, a
   srl   e
   srl   e
   srl   e
   add   hl, de
   
   ld   de, PlotSScreen
   add   hl, de
   
   and   7
   ld   b, a
   ld   a, $80
   jr   z, PlotPixel
   
   rrca
   djnz   $-1

PlotPixel:
  pop af         ;0
  jr nc, ResPixel

SetPixel:
  or (hl)
  ld (hl), a
  jr EndPlot

ResPixel:
  cpl
  and (hl)
  ld (hl), a

EndPlot:
  ld a, (temp)
  ld b, 255
  cp b
  jp z, ContDrawLoop1
  ld hl, temp
  inc (hl)
  ld a, (tx2)
  cp (hl)
  jp nc, QuadPlotLoop1

ContDrawLoop1:
  ld hl, (tx1)
  ld de, (dx1)
  add hl, de
  ld (tx1), hl
  ld hl, (tx2)
  ld de, (dx2)
  add hl, de
  ld (tx2), hl
  ld hl, (tu1)
  ld de, (du1)
  add hl, de
  ld (tu1), hl
  ld hl, (tu2)
  ld de, (du2)
  add hl, de
  ld (tu2), hl
  ld hl, (tv1)
  ld de, (dv1)
  add hl, de
  ld (tv1), hl
  ld hl, (tv2)
  ld de, (dv2)
  add hl, de
  ld (tv2), hl
  ld hl, _ty
  inc (hl)
  ld a, (y2)
  cp (hl)
  jp nz, QuadDrawLoop1

  ld a, (y2)
  ld (_ty), a

QuadDrawLoop2:
  ld a, (tx1)
  ld (temp), a      ;i=temp

QuadPlotLoop2:
  ld a, (tx1)
  ld b, a
  ld a, (tx2)
  sub b
  ld c, a
  ld a, (tx1)
  ld d, a
  ld e, 0
  ld a, (temp)
  sub b
  ld h, a
  ld l, 0
  call DivFP
  ld a, h
  ld (temp+1), a   ;tmp=temp+1
  ld b, a
  ld a, 1
  sub b
  ld d, a
  ld e, 0
  ld a, (tu1)
  ld b, a
  ld c, 0
  call MulFP
  push hl
  ld a, (temp+1)
  ld d, a
  ld e, 0
  ld a, (tu2)
  ld b, a
  ld c, 0
  call MulFP
  pop de
  add hl, de
  ld a, h
  ld (temp2), a      ;u=temp2
  ld a, (temp+1)
  ld b, a
  ld a, 1
  sub b
  ld d, a
  ld e, 0
  ld a, (tv1)
  ld b, a
  ld c, 0
  call MulFP
  push hl
  ld a, (temp+1)
  ld d, a
  ld e, 0
  ld a, (tv2)
  ld b, a
  ld c, 0
  call MulFP
  pop de
  add hl, de
  ld a, h
  ld (temp2+1), a      ;v=temp2+1
;Get the pixel at (u,v) from the texture
  ld   hl, (temp2+1)
   ld   h, 0      ;1 byte smaller

   ld   de, texture
   add   hl, de

   ld   a, (temp2)
   ld   b, a
   inc   b
   ld a, (hl)
shiftLoop2:
   rl   c
   djnz   shiftLoop2   ;the extra shift gets rid of the jr
            ;and pulls the bit out of carry

BitShiftDone2:
  push af         ;1
  ld a, (_ty)
  ld l, a
  ld a, (temp)

getPixel2:
   ld   h, 0
   ld   d, h
   ld   e, l
   
   add   hl, hl
   add   hl, de
   add   hl, hl
   add   hl, hl
   
   ld   e, a
   srl   e
   srl   e
   srl   e
   add   hl, de
   
   ld   de, PlotSScreen
   add   hl, de
   
   and   7
   ld   b, a
   ld   a, $80
   jr   z, PlotPixel2
   
   rrca
   djnz   $-1

PlotPixel2:
  pop af         ;0
  jr nc, ResPixel2

SetPixel2:
  or (hl)
  ld (hl), a
  jr EndPlot2

ResPixel2:
  cpl
  and (hl)
  ld (hl), a

EndPlot2:
  ld hl, temp
  inc (hl)
  ld a, (tx2)
  cp (hl)
  jp nc, QuadPlotLoop2

  ld hl, (tx1)
  ld de, (dx3)
  add hl, de
  ld (tx1), hl
  ld hl, (tx2)
  ld de, (dx2)
  add hl, de
  ld (tx2), hl
  ld hl, (tu1)
  ld de, (du3)
  add hl, de
  ld (tu1), hl
  ld hl, (tu2)
  ld de, (du2)
  add hl, de
  ld (tu2), hl
  ld hl, (tv1)
  ld de, (dv3)
  add hl, de
  ld (tv1), hl
  ld hl, (tv2)
  ld de, (dv2)
  add hl, de
  ld (tv2), hl
  ld hl, _ty
  inc (hl)
  ld a, (y2)
  cp (hl)
  jp nz, QuadDrawLoop2

QuadDrawLoop3:
  ld a, (tx1)
  ld (temp), a      ;i=temp

QuadPlotLoop3:
  ld a, (tx1)
  ld b, a
  ld a, (tx2)
  sub b
  ld c, a
  ld a, (tx1)
  ld d, a
  ld e, 0
  ld a, (temp)
  sub b
  ld h, a
  ld l, 0
  call DivFP
  ld a, h
  ld (temp+1), a   ;tmp=temp+1
  ld b, a
  ld a, 1
  sub b
  ld d, a
  ld e, 0
  ld a, (tu1)
  ld b, a
  ld c, 0
  call MulFP
  push hl
  ld de, (temp+1)
  ld e, 0
  ld bc, (tu2)
  ld c, 0
  call MulFP
  pop de
  add hl, de
  ld a, h
  ld (temp2), a      ;u=temp2
  ld a, (temp+1)
  ld b, a
  ld a, 1
  sub b
  ld d, a
  ld e, 0
  ld a, (tv1)
  ld b, a
  ld c, 0
  call MulFP
  push hl
  ld a, (temp+1)
  ld d, a
  ld e, 0
  ld a, (tv2)
  ld b, a
  ld c, 0
  call MulFP
  pop de
  add hl, de
  ld a, h
  ld (temp2+1), a      ;v=temp2+1
;Get the pixel at (u,v) from the texture
  ld   hl, (temp2+1)
   ld   h, 0      ;1 byte smaller

   ld   de, texture
   add   hl, de

   ld   a, (temp2)
   ld   b, a
   inc   b
   ld a, (hl)
shiftLoop3:
   rl   c
   djnz   shiftLoop3   ;the extra shift gets rid of the jr
            ;and pulls the bit out of carry

BitShiftDone3:
  push af         ;1
  ld a, (_ty)
  ld l, a
  ld a, (temp)

getPixel3:
   ld   h, 0
   ld   d, h
   ld   e, l
   
   add   hl, hl
   add   hl, de
   add   hl, hl
   add   hl, hl
   
   ld   e, a
   srl   e
   srl   e
   srl   e
   add   hl, de
   
   ld   de, PlotSScreen
   add   hl, de
   
   and   7
   ld   b, a
   ld   a, $80
   jr   z, PlotPixel3
   
   rrca
   djnz   $-1

PlotPixel3:
  pop af         ;0
  jr nc, ResPixel3

SetPixel3:
  or (hl)
  ld (hl), a
  jr EndPlot3

ResPixel3:
  cpl
  and (hl)
  ld (hl), a

EndPlot3:
  ld hl, temp
  inc (hl)
  ld a, (tx2)
  cp (hl)
  jp nc, QuadPlotLoop3

  ld hl, (tx1)
  ld de, (dx3)
  add hl, de
  ld (tx1), hl
  ld hl, (tx2)
  ld de, (dx4)
  add hl, de
  ld (tx2), hl
  ld hl, (tu1)
  ld de, (du3)
  add hl, de
  ld (tu1), hl
  ld hl, (tu2)
  ld de, (du4)
  add hl, de
  ld (tu2), hl
  ld hl, (tv1)
  ld de, (dv3)
  add hl, de
  ld (tv1), hl
  ld hl, (tv2)
  ld de, (dv4)
  add hl, de
  ld (tv2), hl
  ld hl, _ty
  inc (hl)
  ld a, (y2)
  cp (hl)
  jp nz, QuadDrawLoop3
  ret
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #70 on: July 17, 2011, 06:41:27 pm »
After placing ret's and jumps at some positions in the code and counting the bytes in the memory editor of wabbitemu, I found out that thi routine does anything but drawing a textured quad. Amost nothing of it is doing what it should do, so I decided to put this on hold, make an other game, and try again when i'm more used to asm.

So, does anybody have a good idea for a good 2D or wireframe 3D game?

Edit: I just noticed i tripple posted, but there is more than 6 hours between those posts, so it's ok, right?
« Last Edit: July 17, 2011, 06:43:06 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Texture drawing
« Reply #71 on: July 17, 2011, 07:14:02 pm »
Edit: I just noticed i tripple posted, but there is more than 6 hours between those posts, so it's ok, right?
Yup, it's fine.

Good luck with your new project. :)

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Texture drawing
« Reply #72 on: July 18, 2011, 09:37:20 am »
Yeah, the triple post was justified because if you hadn't of triple posted, I probably wouldn't have checked the pages and I would have missed your edits. (I always look at all the asm posts, just so you know. So if I don't answer, it either means I have no idea, or it would be annoying for me do whatever the request was (write a whole routine set for someone).)
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ben_g

  • Hey cool I can set a custom title now :)
  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1002
  • Rating: +125/-4
  • Asm noob
    • View Profile
    • Our programmer's team: GameCommandoSquad
Re: Texture drawing
« Reply #73 on: July 20, 2011, 02:49:38 pm »
It doesn't look that bad on a calculator:

For some reason, the pixels on the edge between two texels are sometimes wrong. Does anybody knows how that can be fixed?

This is in basic, btw.

EDIT:

How could i have forgot the scource?

anyway, here it is. Sorry, it's the program itself, not just te code. I tried opening it with notepad, but all i got was a bunch of strange characters. So i hope you have an emulator to open it

btw: still no texture correction, and there are some bugs. If you try to change the coordinates: keep in mind that it only works when Y1 < Y2 < Y3 < Y4 , and there is also a bug when you try to draw a trapezoid with the paralel lines more vertical than horizontal.

EDIT2:

I found a converter. Here's the basic source code:
Code: [Select]
AxesOff
ClrDraw
[[1,1,1,1,1,1,1,1][1,0,1,0,1,0,1,1][1,1,0,1,0,1,0,1][1,0,1,0,1,0,1,1][1,1,0,1,0,1,0,1][1,0,1,0,1,0,1,1][1,1,0,1,0,1,0,1][1,1,1,1,1,1,1,1->[A]
4->dim(LDX
4->dim(LDU
4->dim(LDV
2->dim(LTX
2->dim(LTY
2->dim(LTU
2->dim(LTV
{50,40,80,10->LX
{10,11,60,61->LY
{1,8,1,8->LU
{1,1,8,8->LV
(LX(2)-LX(1))/(LY(2)-LY(1->LDX(1
(LX(3)-LX(1))/(LY(3)-LY(1->LDX(2
(LX(4)-LX(2))/(LY(4)-LY(2->LDX(3
(LX(4)-LX(3))/(LY(4)-LY(3->LDX(4
(LU(2)-LU(1))/(LY(2)-LY(1->LDU(1
(LV(2)-LV(1))/(LY(2)-LY(1->LDV(1
(LU(3)-LU(1))/(LY(3)-LY(1->LDU(2
(LV(3)-LV(1))/(LY(3)-LY(1->LDV(2
(LU(4)-LU(2))/(LY(4)-LY(2->LDU(3
(LV(4)-LV(2))/(LY(4)-LY(2->LDV(3
(LU(4)-LU(3))/(LY(4)-LY(3->LDU(4
(LV(4)-LV(3))/(LY(4)-LY(3->LDV(4
LX(1->LTX(1
LX(1->LTX(2
LU(1->LTU(1
LV(1->LTV(1
LU(1->LTU(2
LV(1->LTV(2
LY(1->Y
If [A](LU(1),LV(1
Then
Pxl-On(Y,LX(1
Else
Pxl-Off(Y,LX(1
End
For(Y,LY(1)+1,LY(2
LTX(1)+LDX(1->LTX(1
LTU(1)+LDU(1->LTU(1
LTV(1)+LDV(1->LTV(1
LTX(2)+LDX(2->LTX(2
LTU(2)+LDU(2->LTU(2
LTV(2)+LDV(2->LTV(2
For(X,LTX(1),LTX(2
(X-LTX(1))/(LTX(2)-LTX(1->T
round((1-T)*LTU(1)+T*LTU(2),0)->U
round((1-T)*LTV(1)+T*LTV(2),0)->V
If [A](U,V)
Then
Pxl-On(Y,round(X,0
Else
Pxl-Off(Y,round(X,0
End
End
End
For(Y,LY(2)+1,LY(3
LTX(1)+LDX(3->LTX(1
LTX(2)+LDX(2->LTX(2
LTU(1)+LDU(3->LTU(1
LTV(1)+LDV(3->LTV(1
LTU(2)+LDU(2->LTU(2
LTV(2)+LDV(2->LTV(2
For(X,LTX(1),LTX(2
(X-LTX(1))/(LTX(2)-LTX(1->T
round((1-T)*LTU(1)+T*LTU(2),0->U
round((1-T)*LTV(1)+T*LTV(2),0->V
If [A](U,V
Then
Pxl-On(Y,round(X,0
Else
Pxl-Off(Y,round(X,0
End
End
End
For(Y,LY(3)+1,LY(4)-1
LTX(1)+LDX(3->LTX(1
LTU(1)+LDU(3->LTU(1
LTV(1)+LDV(3->LTV(1
LTX(2)+LDX(4->LTX(2
LTU(2)+LDU(4->LTU(2
LTV(2)+LDV(4->LTV(2
For(X,LTX(1),LTX(2
(X-LTX(1))/(LTX(2)-LTX(1->T
round((1-T)*LTU(1)+T*LTU(2),0->U
round((1-T)*LTV(1)+T*LTV(2),0->V
If [A](U,V
Then
Pxl-On(Y,round(X,0
Else
Pxl-Off(Y,round(X,0
End
End
End
If [A](LU(4),LV(4
Then
Pxl-On(LY(4),LX(4
Else
Pxl-Off(LY(4),LX(4
End
DelVar LX
DelVar LY
DelVar LU
DelVar LV
DelVar [A]
DelVar LDU
DelVar LDV
DelVar LDX
DelVar LTU
DelVar LTV
DelVar LTX
DelVar LTY
Does anybody see what causes the wrong pixels in this program?
« Last Edit: July 28, 2011, 06:34:11 pm by ben_g »
My projects
 - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project]
 - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic)
 - An android version of oxo (java)  ACTIVE
 - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper)
Spoiler For inactive:
- A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot)
 - A java MORPG. (pc) DEEP COMA(read more)(screenshot)
 - a minecraft game in axe DEAD (source code available)
 - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version)

This signature was last updated on 20/04/2015 and may be outdated

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Texture drawing
« Reply #74 on: July 20, 2011, 05:11:17 pm »
Of course we would have to see the source, but I assume this has something to do with rounding. Most likely the pixels that look bad are split between two adjacent pixels and every now and then go the wrong way.
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112