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 - ben_g

Pages: 1 ... 42 43 [44] 45 46 ... 71
646
Humour and Jokes / Re: Where did Nyan cat came from
« on: December 06, 2011, 03:03:33 pm »
Now I know where it comes from. I lol'ed at the end becouse it was so ridiculous.

647
ASM / Re: Interaction with a 3D Space
« on: December 06, 2011, 01:55:55 pm »
Sorry, I forgot to include it. Add this to your code:
Code: [Select]
#define SubFP xor a \ sbc hl, deAnd all numbers handled by the 3D engine are signed 8.8fixed-points (eccept for the angles). Speed stands for the number of units per secound. You can't use 16.8 for the position, but you can easily just send everything within 128 units to the 3D engine, in relative coordinates. Everything further than that will probably be to far to see anyway.

648
ASM / Re: Interaction with a 3D Space
« on: December 05, 2011, 04:28:55 pm »
here is some code:
Spoiler For code:
Quote from: Z80 Assembly
;variables used for saving the location. replace locvars with the memory location they should be
x .equ locVars
y .equ x+2
z .equ y+2
hdir .equ z+2
vdir .equ hdir+1

;Variables used by the 3D engine. replace EngineVars with the memory location they should be.
temp .equ EngineVars
temp2 .equ temp+2
temp3 .equ temp2+2

Asqr .equ temp3+2
Bsqr .equ Asqr+2
Csqr .equ Bsqr+2
 
xfrom .equ Csqr+2
yfrom .equ xfrom+2
zfrom .equ yfrom+2
xto .equ zfrom+2
yto .equ xto+2
zto .equ yto+2
xup .equ zto+2
yup .equ xup+2
zup .equ yup+2
angle .equ zup+2
xcross .equ angle+1
ycross .equ xcross+2
zcross .equ ycross+2
xpoint .equ zcross+2
ypoint .equ xpoint+2
zpoint .equ ypoint+2
valid .equ zpoint+2
screenx .equ valid+1
screeny .equ screenx+2
screenz .equ screeny+2

#define
speed $0040 ;move with 1/4 unit per frame

;call this routine before rendering each screen
Init3D:
  ld hl, (x)
  ld (xfrom), hl
  push hl
  ld a, (hdir)
  add a, 64
  call SinA
  push hl
  ld a, (vdir)
  add a, 64
  call SinA
  ex de, hl
  pop bc
  call MulFP
  pop de
  add hl, de
  ld (xto), hl

  ld
hl, (y)
  ld (yfrom), hl
  push hl
  ld a, (hdir)
  call SinA
  push hl
  ld a, (vdir)
  add a, 64
  call SinA
  ex de, hl
  pop bc
  call MulFP
  pop de
  add hl, de
  ld (yto), hl

  ld
hl, (z)
  ld (zfrom), hl
  push hl
  ld a, (vdir)
  call SinA
  pop de
  add hl, de
  ld (zto), hl

  ld
hl, 0
  ld (xup), hl
  ld (yup), hl
  ld hl, $0100
  ld (zup), hl

  call
InitView

  ret


;call this routine to move:
Move:
  ld hl, (x)
  push hl
  ld a, (hdir)
  add a, 64
  call SinA
  push hl
  ld a, (vdir)
  add a, 64
  call SinA
  ex de, hl
  pop bc
  call MulFP
  ex de, hl
  ld bc, speed
  call MulFP
  pop de
  add hl, de
  ld (x), hl

  ld
hl, (y)
  push hl
  ld a, (hdir)
  call SinA
  push hl
  ld a, (vdir)
  add a, 64
  call SinA
  ex de, hl
  pop bc
  call MulFP
  ex de, hl
  ld bc, speed
  call MulFP
  pop de
  add hl, de
  ld (y), hl

  ld
hl, (z)
  push hl
  ld a, (vdir)
  call SinA
  ex de, hl
  ld bc, speed
  call MulFP
  pop de
  add hl, de
  ld (z), hl

  ret


;the routines of the 3D engine.

InitView:
  ;call once every frame, before C3DTo2D
  ;IN: The engine's vars
  ;OUT: vars are initialised
  ;DESTROYS: all registers and the engine's variables
  ld hl, (xto)
  ld de, (xfrom)
  SubFP
  ld (xto), hl
  ld hl, (yto)
  ld de, (yfrom)
  SubFP
  ld (yto), hl
  ld hl, (zto)
  ld de, (zfrom)
  SubFP
  ld (zto), hl
  ld de, (xto)
  ld b, d \ ld c, e
  call MulFP
  ld (temp), hl
  ld de, (yto)
  ld b, d \ ld c, e
  call MulFP
  ld de, (temp)
  add hl, de
  ld (temp), hl
  ld de, (zto)
  ld b, d \ ld c, e
  call MulFP
  ld de, (temp)
  add hl, de
  call SqrtFP
  ld (temp), hl
  ld hl, (xto)
  ld de, (temp)
  call DivFP
  ld (xto), hl
  ld hl, (yto)
  ld de, (temp)
  call DivFP
  ld (yto), hl
  ld hl, (zto)
  ld de, (temp)
  call DivFP
  ld (zto), hl
  ld de, (xup)
  ld bc, (xto)
  call MulFP
  ld (temp), hl
  ld de, (yup)
  ld bc, (yto)
  call MulFP
  ld de, (temp)
  add hl, de
  ld (temp), hl
  ld de, (zup)
  ld bc, (zto)
  call MulFP
  ld de, (temp)
  add hl, de
  ld (temp), hl
  ld de, (temp)
  ld bc, (xto)
  call MulFP
  ld d, h \ ld e, l
  ld hl, (xup)
  SubFP
  ld (xup), hl
  ld de, (temp)
  ld bc, (yto)
  call MulFP
  ld d, h \ ld e, l
  ld hl, (yup)
  SubFP
  ld (yup), hl
  ld de, (temp)
  ld bc, (zto)
  call MulFP
  ld d, h \ ld e, l
  ld hl, (zup)
  SubFP
  ld (zup), hl
  ld de, (xup)
  ld b, d \ ld c, e
  call MulFP
  ld (temp), hl
  ld de, (yup)
  ld b, d \ ld c, e
  call MulFP
  ld de, (temp)
  add hl, de
  ld (temp), hl
  ld de, (zup)
  ld b, d \ ld c, e
  call MulFP
  ld de, (temp)
  add hl, de
  call sqrtFP
  ld (temp), hl
  ;Multiply (temp) with the tangent of (angle)/2, which is, in this test program, equal to 1, so we don't need to multiply
  ld hl, (xup)
  ld de, (temp)
  call DivFP
  ld (xup), hl
  ld hl, (yup)
  ld de, (temp)
  call DivFP
  ld (yup), hl
  ld hl, (zup)
  ld de, (temp)
  call DivFP
  ld (zup), hl
  ld de, (yup)
  ld bc, (zto)
  call MulFP
  ld (temp), hl
  ld de, (zup)
  ld bc, (yto)
  call MulFP
  ld d, h \ ld e, l
  ld hl, (temp)
  SubFP
  ld (xcross), hl
  ld de, (zup)
  ld bc, (xto)
  call MulFP
  ld (temp), hl
  ld de, (xup)
  ld bc, (zto)
  call MulFP
  ld d, h \ ld e, l
  ld hl, (temp)
  SubFP
  ld (ycross), hl
  ld de, (xup)
  ld bc, (yto)
  call MulFP
  ld (temp), hl
  ld de, (yup)
  ld bc, (xto)
  call MulFP
  ld d, h \ ld e, l
  ld hl, (temp)
  SubFP
  ld (zcross), hl
  ret
 
C3DTo2D:
  ;IN: xpoint, ypoint and zpoint vars
  ;OUT: screenx and screeny are set to the onscreen coordinates for the point
  ;Will not work if InitView wasn't called before this routine
  ;destroys all registers and xpoint, ypoint and zpoint
  ld hl, (xpoint)
  ld de, (xfrom)
  SubFP
  ld (xpoint), hl
  ld hl, (ypoint)
  ld de, (yfrom)
  SubFP
  ld (ypoint), hl
  ld hl, (zpoint)
  ld de, (zfrom)
  SubFP
  ld (zpoint), hl
  ld de, (xpoint)
  ld bc, (xto)
  call MulFP
  ld (temp), hl
  ld de, (ypoint)
  ld bc, (yto)
  call MulFP
  ld de, (temp)
  add hl, de
  ld (temp), hl
  ld de, (zpoint)
  ld bc, (zto)
  call MulFP
  ld de, (temp)
  add hl, de
  ld (temp), hl
  ld (screenz), hl
  ;kijk hier of het punt zichtbaar is
  bit 7, h
  jp nz, InValid
 
  ld
de, (xpoint)
  ld bc, (xcross)
  call MulFP
  ld (temp2), hl
  ld de, (ypoint)
  ld bc, (ycross)
  call MulFP
  ld de, (temp2)
  add hl, de
  ld (temp2), hl
  ld de, (zpoint)
  ld bc, (zcross)
  call MulFP
  ;ld de, (temp2)
  ;ld bc, (zup)
  ;call MulFP
  ld de, (temp2)
  add hl, de
  ld de, (temp)
  call DivFP
  ld (screenx), hl
  ld de, (xpoint)
  ld bc, (xup)
  call MulFP
  ld (temp2), hl
  ld de, (ypoint)
  ld bc, (yup)
  call MulFP
  ld de, (temp2)
  add hl, de
  ld (temp2), hl
  ld de, (zpoint)
  ld bc, (zup)
  call MulFP
  ld de, (temp2)
  add hl, de
  ld de, (temp)
  call DivFP
  ld (screeny), hl
  ld hl, $0100
  ld de, (screenx)
  SubFP
  ld b, h \ ld c, l
  ld de, 48
  call MulFP
  ld (screenx), hl
  ld de, (screeny)
  ld hl, $0100
  SubFP
  ld b, h \ ld c, l
  ld de, 32
  call MulFP
  ld (screeny), hl
  ld a, 1
  ret
InValid:
  ld a, 0
  ret


;These routines are for the math in the 3D engine.

;;;;;;;;;;;;;;;;;;;;;;;;;; MATH ROUTINES ;;;;;;;;;;;;;;;;;;;;;;;;;;;

 
SqrtA:
   LD   (Asqr),A
   SRL   A
   JR   DataOver
DataOver:
   LD   (Bsqr),A
   LD   B,A
   LD   (Csqr),A
iterate:
   LD   A,(Bsqr)
   ld     b, a
   LD   a,(Asqr)
   LD   D,A
   LD   E,B
dividedbyEreturnA:
   RL   D
   RLA
   SUB   E
   JR   nc,$+3
   ADD   A,E
   LD   E,A
   LD   A,D
   CPL
   push af      ;1
   LD   a,(Bsqr)
   ld b, a
   pop af         ;0
   ADD   A,B
   SRL   A
   LD   (Bsqr),A
   LD   a,(Bsqr)
   ld b, a
   LD   A,(Csqr)
   DEC   A
   CP   B
   JR   z,done
   push af      ;1
   LD   (Csqr),a
   ld b, a
   pop af         ;0
   JR   iterate
done:
   LD   A,(Bsqr)
   RET
 
;SubFP:
;  ;substracts 2 16-bit fixed-point numbers
;  ;IN: hl, de
;  ;OUT: hl - de in hl
;  ;DESTROYS: a, hl
;  or   a   ;clear carry flag
;  sbc   hl, de
;  ret
 
Div16By8:
  ;divides a 16-bit number by an 8-bit number
  ;IN: hl and d
  ;OUT: hl = hl/d, remainder = a
  ;DESTROYS: a, b, c, d, hl
  xor a
  ld b, 16
_D16b8Loop:
  add hl, hl
  rla
  jr c, _D16b8Overflow
  cp d
  jr c, _D16b8Skip
_D16b8Overflow:
  sub b
  inc l
_D16b8Skip:
  djnz _D16b8Loop
  ret

 
MulFP:
  ;Multiplies 2 16bit fixed-point numbers
  ;IN: de, bc
  ;OUT: de * bc in hl
  ;DESTROYS: af, bc, de, hl
  bit 7, d
  jr nz, _MulFP_FirstNeg
  bit 7, b
  jr nz, _MulFP_AnsNeg
  jr z, _MulFP_AnsPos
_MulFP_FirstNeg:
  bit 7, b
  jr nz, _MulFP_AnsPos
_MulFP_AnsNeg:
  ld a, 1
  push af         ;1
  jr _MulFP_Cont
_MulFP_AnsPos:
  ld a, 0
  push af         ;1
_MulFP_Cont:
  bit 7, b
  jr z, _MulFP_BCPos
  call NegBC
_MulFP_BCPos:
  bit 7, d
  jr z, _MulFP_DEPos
  call NegDE
_MulFP_DEPos:
  ld hl,0
  ld a,16
Mul16Loop:
  add hl,hl
  rl e
  rl d
  jp nc,NoMul16
  add hl,bc
  jp nc,NoMul16
  inc de
NoMul16:
  dec a
  jp nz,Mul16Loop

  ld
l, h
  ld h, e
  pop af         ;0
  cp 1
  call z, NegHL
  ret
 
;adding fixed-point numbers:
;load one of the numbers in hl, and the other in an other 16-bit register.
;then, do: add hl, <register>

DivFP:
  ;IN: hl, de
  ;OUT: hl = hl / de
  ;DESTROYS: af, hl, bc, d
  bit 7, d
  jr nz, _DivFP_FirstNeg
  bit 7, h
  jr nz, _DivFP_AnsNeg
  jr z, _DivFP_AnsPos
_DivFP_FirstNeg:
  bit 7, h
  jr nz, _DivFP_AnsPos
_DivFP_AnsNeg:
  ld a, 1
  push af
  jr _DivFP_Cont
_DivFP_AnsPos:
  ld a, 0
  push af
_DivFP_Cont:
  bit 7, h
  jr z, _DivFP_HLPos
  call NegHL
_DivFP_HLPos:
  bit 7, d
  jr z, _DivFP_DEPos
  call NegDE
_DivFP_DEPos
  ld a, h
  ld h, l
  ld l, 0
  push hl ;INPUTS: ahl = dividend de = divisor   ;1
  pop ix ;OUTPUTS: ahl = quotient de = divisor   ;0
  ld hl,0
  ld b,24
_Div24by16loop:
  add ix,ix
  rla
  adc hl,hl
  jr c,_Div24by16setbit
  or a
  sbc hl,de
  add hl,de
  jr c,_Div24by16skip
_Div24by16setbit:
  or a
  sbc hl,de
  inc ix
_Div24by16skip:
  djnz _Div24by16loop
  push ix         ;1
  pop hl         ;0

  pop
af
  cp 1
  call z, NegHL
  ret
 
SinA:
  ;calculates the sine of a as a fixed point number
  ;IN: a
  ;OUT: hl = sin(a)
    LD     h, 0
    LD     l, a
    add hl, hl
    LD     DE, sine_table
    ADD    HL, DE
    LD     A, (HL)
    INC    HL
    LD     H, (HL)
    LD     L, A
    RET
sine_table:
.dw    0, 6, 13, 19, 25, 31, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98, 104, 109, 115, 121, 126, 132, 137, 142
.dw    147, 152, 157, 162, 167, 172, 177, 181, 185, 190, 194, 198, 202, 206, 209, 213, 216, 220, 223, 226, 229, 231, 234
.dw    237, 239, 241, 243, 245, 247, 248, 250, 251, 252, 253, 254, 255, 255, 256, 256, 256, 256, 256, 255, 255, 254, 253
.dw    252, 251, 250, 248, 247, 245, 243, 241, 239, 237, 234, 231, 229, 226, 223, 220, 216, 213, 209, 206, 202, 198, 194
.dw    190, 185, 181, 177, 172, 167, 162, 157, 152, 147, 142, 137, 132, 126, 121, 115, 109, 104, 98, 92, 86, 80, 74, 68
.dw    62, 56, 50, 44, 38, 31, 25, 19, 13, 6, 0, -6, -13, -19, -25, -31, -38, -44, -50, -56, -62, -68, -74, -80, -86, -92
.dw    -98, -104, -109, -115, -121, -126, -132, -137, -142, -147, -152, -157, -162, -167, -172, -177, -181, -185, -190
.dw    -194, -198, -202, -206, -209, -213, -216, -220, -223, -226, -229, -231, -234, -237, -239, -241, -243, -245, -247
.dw    -248, -250, -251, -252, -253, -254, -255, -255, -256, -256, -256, -256, -256, -255, -255, -254, -253, -252, -251
.dw    -250, -248, -247, -245, -243, -241, -239, -237, -234, -231, -229, -226, -223, -220, -216, -213, -209, -206, -202
.dw    -198, -194, -190, -185, -181, -177, -172, -167, -162, -157, -152, -147, -142, -137, -132, -126, -121, -115, -109
.dw    -104, -98, -92, -86, -80, -74, -68, -62, -56, -50, -44, -38, -31, -25, -19, -13, -6
 
SqrtFP:
;#####################################################
;square root of fixed point hl
;input: hl
;output: hl=sqrt(hl)

sqrt_hl:
   ld   a, l
   ld   l, h
   ld   de, 0040h   ; 40h appends "01" to D
   ld   h, d
   
   ld
   b, 7
   
   ; need to clear the carry beforehand
   or   a
   
_loopz:
   sbc   hl, de
   jr   nc, $+3
   add   hl, de
   ccf
   rl   d
   rla
   adc   hl, hl
   rla
   adc   hl, hl
   
   djnz
   _loopz
   
   sbc
   hl, de      ; optimised last iteration
   ccf
   rl   d

   ld
   h, d
   xor   a
   ld   b, 4
shiftLoopz:
   srl   h
   rra
   djnz   shiftLoopz
   ld   l, a
   ret
 
NegHL:
   xor a
   sub l
   ld l,a
   sbc a,a
   sub h
   ld h,a
   ret

NegBC:
   xor a
   sub c
   ld c,a
   sbc a,a
   sub b
   ld b,a
   ret

NegDE:
   xor a
   sub e
   ld e,a
   sbc a,a
   sub d
   ld d,a
   ret

Generated by the BBify'r (http://clrhome.org/resources/bbify/)

Use it like the comments tell you. To render, AFTER calling Init3D, load the x, y and z coordinates in the xpoint, ypoint and zpoint variables (in signed 8.8 fixed-point format). Then call C3D to2D. If the point was behind the camera, a will be set to 0. If the point is in front of the camera, a will be 1. The screen coordinates will be stored in screenx and screeny, and the distance to the point will be stored in screenz.

For inputting those fixed-point numbers, I created a tool in java. If you want to use it, you can download it here: http://dl.dropbox.com/u/11215358/base%20converter.jar
To use it to convert a decimal value into hexadecimal, fill in decimal and hexadecimal in the top field, type in the number , make sure the option 'Signed' is enabled and select '8.8 fixed-point' as format. Then click 'convert'. It will then generate the Hexadecimal code in the field at the bottom. Then just take the last 4 characters or add zeros to the front and you've got your hexadecimal number. For debugging, you can switch decimal and hexadecimal and type in a hex number.

649
ASM / Re: Interaction with a 3D Space
« on: December 03, 2011, 03:37:50 pm »
Do you want to be able to rotate your ship, then fly in the direction it's facing instead of moving in only 6 directions? Or did i misunderstand your question? If you want this, you are going to need fixed point numbers or inflation by 256. Then you need a sine routine. When the ship is moving, you add sin(hdir + 90°) to the X coordinate, and sin(hdir) to thy Y coordinate, where hdir stands for the direction in the horizontal plane. If you then add movement along the Z axis, the controls remain simple and they might be good enough. If you however want to be able to fly in the 3 dimensions, then you need 2 direction variables. The math to calculate the coordinates will be slightly more complex too. Now you'll have to add sin(hdir + 90°) * sin(vdir + 90°) to your X coordinate,  sin(hdir) * sin(vdir + 90°) to your Y coordinate, and sin(vdir) to your z coordinate. You should also keep in mind that if you want to be able to look in different directions, your 3D projection algorithm needs to support rotation of the camera, so a simple 1, 2 or 3 point perspective algorithm (like what you use when making 3D drawings) won't work anymore. You have to go with a perspective projection algorithm. If you don't already use one, you can find a good one on wikipedia, or I can pm you the code for mine, if you want.

650
Gaming Discussion / Re: Pokemon is evil
« on: December 01, 2011, 01:24:48 pm »
Everything can crash, even games made by big companies like nintendo. It only was scary because it happened shortly after reading this urban legend.

651
Gaming Discussion / Re: Pokemon is evil
« on: December 01, 2011, 01:20:05 pm »
Of course it's made up. Nobody can code something like that into a game.

But this story made it a bit scary when today when I was playing a game on a DS, the game suddenly crashed and showed a black screen and after a secound, some white text appeared on it.

The text didn't say 'come follow me', but that an error has occured, followed by some hexadecimal numbers.

652
Gaming Discussion / Re: Pokemon is evil
« on: November 30, 2011, 03:48:02 pm »
* ben_g burns his old gameboy and pokémon red cartridge

cool story.

653
Humour and Jokes / Re: What do you feel like when you lose your calc?
« on: November 29, 2011, 04:27:29 pm »
I would be a bit nervous, then take the calc of my brother out of the drawers (that poor calc hasn't even seen daylight for a few months) and use that instaed. It's a calc of the same type.

654
TI Z80 / Re: Space Impact +
« on: November 29, 2011, 03:19:56 pm »
This looks like that game on my cellphone, but with a better resolution. I like that game, so this would definitely be good too.

655
Other / Re: Juju's Handheld Console
« on: November 29, 2011, 03:08:25 pm »
how much CPU speed will it heave?

656
Other Calculators / Re: The best calculator Game you played
« on: November 28, 2011, 02:29:53 pm »
Silence. My friends also like it most.

657
Humour and Jokes / Re: 9001 signs you're addicted to calcs and Omni
« on: November 26, 2011, 06:25:12 pm »
2475: When you have to decide something, but don't know what you should choose, you let your calc generate a random number instead of tossing a coin (true).

658
If you don't trust anyone from outside this community, then you can always release it in the private matters section. It's invisible to guests and users with a post number below the limit (of which I think it's 100).

659
General Calculator Help / Re: Multiple Calc Problems
« on: November 26, 2011, 02:57:56 pm »
does everything else still works the way it's supposed to? If it does, then you can try resetting or reinstalling DCS, and then use http://ourl.ca/12245/234994
If your OS doesn't work correctely anymore (which means it's corrupted), reinstall the os, then see if it works.

660
TI Z80 / Re: GlassOS
« on: November 26, 2011, 01:22:58 pm »
can you also add a 24 hour clock?

Pages: 1 ... 42 43 [44] 45 46 ... 71