Search found 34 matches

by bogax
Mon Jan 08, 2018 7:41 pm
Forum: NESdev
Topic: How to describe a circle trajectory on nes?
Replies: 23
Views: 5473

Re: How to describe a circle trajectory on nes?

One algorithm I know for drawing (approximately) circles is Minsky's circle algorithm, which works like: for(;;) { y-=epsilon*x; x+=epsilon*y; plot(x,y); } The value epsilon is less than one. If it is 1/256 then you do not need to implement multiplication/division; you can just use the carrying (yo...
by bogax
Sun Jan 07, 2018 10:47 am
Forum: NESdev
Topic: How to describe a circle trajectory on nes?
Replies: 23
Views: 5473

Re: How to describe a circle trajectory on nes?

Here's code (6502.org) for a simple parabolic approximation of a sine wave.

If you run two instances 90 degrees apart that will give you something like a circle.

Of course, it's incremental not random access.

There's an example here (AtariAge) in Batari Basic.
by bogax
Sat Nov 26, 2016 10:39 am
Forum: Newbie Help Center
Topic: Couple of questions from a 6502 newb.
Replies: 54
Views: 16252

Re: Couple of questions from a 6502 newb.

or something in between
use an LUT

Code: Select all

 ldx #03
loop
 ldy ytable,x
 lda sprite1,x
 sta $201,y
 dex
 bpl loop

ytable
 $00
 $04
 $08
 $0C 
by bogax
Sun Nov 20, 2016 5:29 pm
Forum: NESdev
Topic: Diagonal movement with arbitrary angle
Replies: 8
Views: 3862

Re: Diagonal movement with arbitrary angle

one way determine your deltas dx, dy and what their signs are decide which has the larger magnitude develope an index using the signs and which has the larger magnitude ie three bits two for signs and one for x or y having the larger magnitude that will define the octant you're moving in and can be ...
by bogax
Sat Jun 14, 2014 12:15 pm
Forum: NESdev
Topic: Unsigned Integer Division Routines
Replies: 30
Views: 25929

Re: Unsigned Integer Division Routines

I have written a number of division routines in 6502 assembly, and I'm posting them here for other people to use. :) These routines start with any value (0-255) in the accumulator and finish with the integer division result in the accumulator. They are all constant cycles and do not use X or Y. Mos...
by bogax
Tue May 13, 2014 10:22 am
Forum: Newbie Help Center
Topic: need assistance with random number generator
Replies: 12
Views: 5489

Re: need assistance with random number generator

I rather like the Batari BASIC rand16
which justs shifts the two bytes of a
16 bit LFSR in opposite directions then
EORs them together.

Code: Select all

  lda seedhi
  lsr
  rol seedlo
  bcc noeor
  eor #$B4
noeor
  sta seedhi
  eor seedlo
by bogax
Mon May 12, 2014 10:44 pm
Forum: Newbie Help Center
Topic: need assistance with random number generator
Replies: 12
Views: 5489

Re: need assistance with random number generator

One of the simplest PRNGs to implement is a linear feedback shift register. http://en.wikipedia.org/wiki/Linear_feedback_shift_register Here's the 8-bit LFSR I used in my coltrane.nes project. Any starting value can be used for _prng_seed, and it will output all 256 possible values in a fixed seque...
by bogax
Fri Jul 12, 2013 1:52 pm
Forum: NESdev
Topic: Game math library
Replies: 4
Views: 2081

Re: Game math library

I tried difference of squares years ago, and it took about 90 cycles and a lot more bytes than the 8x8 long mul that Thwaite uses. It does take a lot of bytes both for tables and on zp but it's a lot faster than 90 cycles. in the version attributed to George Taylor (who said he got it from someone ...
by bogax
Sat Jul 06, 2013 11:01 am
Forum: NESdev
Topic: uc65, a Mid-Level Language Compiler READY FOR USE!
Replies: 161
Views: 40367

Re: uc65, a Mid-Level Language Compiler for the cc65 Toolch

I've used Lex and Yacc in the past. I wrote my first several compilers with them. Then I read the excellent article series Let's Build a Compiler by Jack Crenshaw. Although dated (with example code in Pascal) it's still the most effective way to write a compiler, in my opinion. Jack even addresses ...
by bogax
Fri Feb 22, 2013 8:21 pm
Forum: NESdev
Topic: simplest chain physics algorithm
Replies: 11
Views: 2314

Re: simplest chain physics algorithm

For a pendulum you wouldn't be using this kind of calculations anyway, you'd be using a sin/cos table and then just determine the point in the circle where you want the pendulum to be... d = x * LUT(y/x*256) That first multiplication and that division look awfully expensive... how about a hakmem - ...
by bogax
Mon Feb 04, 2013 8:35 pm
Forum: NESdev
Topic: JumpEngine
Replies: 12
Views: 2771

Re: JumpEngine

The code effects a jump to an address selected from a table that's inlined. the table is indexed by (the contents of) a. You would presumably do something like lda index jsr SELECT_TARGET . . SELECT_TARGET jsr JUMPENGINE target0 target1 target2 etc, if the targets return with rts But the jsr JUMPENG...
by bogax
Wed Jan 16, 2013 11:12 am
Forum: NESdev
Topic: What is the best way to delay events?
Replies: 29
Views: 4564

Re: What is the best way to delay events?

We've been here before. I can't speak for Blargg of course but I assume he's pointing out a general form for one way to do it and expecting you to be able fill in the details. And I don't see it in the Wiki. If you've got a few bytes in RAM to devote to self-modifying code, you could do something li...
by bogax
Fri Dec 14, 2012 11:49 am
Forum: NESdev
Topic: CRC routines as PRNGs
Replies: 44
Views: 15932

Re: CRC routines as PRNGs

Right no true scotsman would use a crappy generator :P I'm not sure how this was a "no true scotsman" argument. If faced with a choice of XORing two 16 bit generators, or one equivalent 32 bit generator (or even a 24 bit generator), I believe you would find with empirical testing that the latter wi...
by bogax
Wed Dec 12, 2012 12:49 am
Forum: NESdev
Topic: CRC routines as PRNGs
Replies: 44
Views: 15932

Re: CRC routines as PRNGs

A common ploy is to combine two different types of PRNGs in the hopes that they'll hide each others deficiencies. Say, an LFSR and an LCG XORed toghether I would not recommend this. Not sure I'd go so far as to recommend it, but it certainly is a common ploy. A better quality generator will be supe...
by bogax
Tue Dec 11, 2012 6:50 pm
Forum: NESdev
Topic: CRC routines as PRNGs
Replies: 44
Views: 15932

Re: CRC routines as PRNGs

Well yeah, unless I can find a decent 32-bit polynomial (decent meaning maximal-length, as few 1s as possible, ideally with them spread out and away from the most significant 8 bits, while also allowing a good random distribution), it's probably a lot easier to just use a traditional LFSR instead o...