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

Pages: 1 ... 110 111 [112] 113 114 ... 317
1666
ASM / Re: ASM Optimized routines
« on: July 03, 2012, 12:13:46 pm »
Necroedit: For a much better routine, please try the routines at the end of this post!

I created this last night for my next project:
Code: [Select]
PseudoRandWord:
;Outputs:
;     BC was the previous pseudorandom number
;     HL is the pseudorandom number
;f(n+1)=(241f(n)+257) mod 65536   ;65536
;181 cycles, add 17 if called
     ld hl,(randSeed)
     ld c,l
     ld b,h
     add hl,hl
     add hl,bc
     add hl,hl
     add hl,bc
     add hl,hl
     add hl,bc
     add hl,hl
     add hl,hl
     add hl,hl
     add hl,hl
     add hl,bc
     inc h
     inc hl
     ld (randSeed),hl
     ret
There are a few other nice features, too. For example, every 16-bit value is hit if you run this 65536 times. Or, if you only read 1 byte (for example, H from the output), it will hit every 8-bit number once if you run this 256 times. Plus, it can be seeded, which has its own uses. This can be modified to be smaller, too, if you know what you are doing, but I just like the numbers 241 and 257. Anyways, it produces some nice results :)

P.S.-I used this in a routine called "ShuffleDeck" and it works very well.

1667
BatLib / Re: BatLib
« on: July 03, 2012, 11:53:57 am »
Thanks, hopefully I didn't miss anything :) Also, this app is actually in its final stages. I am almost finished with the project, but I am going to wait to release the final version until all bugs are fixed. I now only have about 20 bytes of room left for data and code.

1668
TI Z80 / Re: ORG: online Z80 IDE and assembler
« on: July 03, 2012, 11:51:55 am »
Wow, thisis really awesome ! This is a very impressive job!

1669
Grammer / Re: Grammer 2-The APP
« on: July 03, 2012, 11:46:13 am »
Now problem :) I have an update, too (no new commands). This version has a modified header to work with BatLib and I modified some other code to let BatLib's dim(125) command work :) (that lets you execute inline Grammer code in your BASIC programs).

1670
BatLib / Re: BatLib
« on: July 03, 2012, 11:43:12 am »
Hmm, I am going to have to look into that, then :D Also, I have some more updates and bug fixes. Appparently when I went on an optmising spree, I broke a few things :[

dim(14) and dim(15) now have options for using 2-byte words
dim(124) was added for creating variables
dim(125) was added for executing inline Grammer code
dim(60) now allows you to archive or unarchive a var
dim(29) is fixed (before, it added 1 to the x-coordinate)
dim(29) now has two options for pixel testing rectangle regions

dim(56) and dim(62) have been fixed (pixel test results were broken)
dim(63) was fixed (similar issue)


I found a discrepancy in the compression routine that is now fixed. It sometimes lost data instead of being lossless.


EDIT: Oh! I almost forgot to mention that I made an example program for compressing/decompressing data. It can get great compression ratios depending on the data (I had a tilemap compress down to almost 11%). It is very easy to use, so I hope it can get used in some big projects !

1671
Math and Science / Re: Cool math hacks
« on: June 23, 2012, 02:48:15 pm »
Yes, I did note the mistakes I made there. I made a mistake on one of the pages testing cases of parity.

EDIT: Also, I finally found mention of this technique while searching something unrelated. It is Fermat Factorization :)

1672
BatLib / Re: BatLib
« on: June 23, 2012, 02:46:39 pm »
It won't work with zStart because it requires a modification to the app header and zStart already uses that area. But yes, I have already asked Kerm about officially supporting GroupHook with DoorsCS7 and if it gets added, it will be able to work with Omnicalc, Grammer, and BatLib.

1673
Grammer / Re: Grammer 2-The APP
« on: June 22, 2012, 02:40:18 pm »
Output(2 lets you draw text to pixel coordinates with the small font, Output(0 only lets you draw to 24 columns.

I will definitely try to add in the increment for For(

I don't think I will change Fill(23 as some programs use it already. This would prevent the programs from working properly :/

length(' and L... I cannot remember the difference, sorry :/ I am out of internet time D:

1674
BatLib / Re: BatLib
« on: June 22, 2012, 11:52:21 am »
I finally got the motivation to rewrite BatLib, so I was working on it all this past week. I have good news and bad news. The good news will hopefully be awesome enough to outweigh the bad >:D

Bad news: I cannot figure out how to make weird names with Brass, so this update uses BatLib with regular letters. Also, I have change the syntax of some ReCode commands and I have yet to document the changes (also, I think I still need to code in 8 more commands).

Awesome news:
I have added in all the other 104 commands as well as 19 more commands. I have updated almost everything, so a bunch of the commands are now more powerful (and still backwards compatible). All the bugs or issues that I could find are now fixed and I have yet to find bugs, now. Here are some changes:

  • dim(1) was used to disable Done and turn the run indicator off. Now you can use a digit after the 1 to fine tune that. For example, dim(1.1) does something different from dim(1) or dim(1.2), but all deal with the run indicator and Done message.
  • dim(29) now draws rectangles with clipping.
  • Which reminds me that negative numbers are now read properly. Before, BatLib just used the absolute value of inputs
  • dim(41) now allows the input of all variable types and works just fine with lists and named lists. It also has an otional argument that will let you get the size of a variable as it apears in the memory menu. Before, it just returned the size of the data portion of a var.
  • dim(52) and dim(53) now let you draw sprites to pixel coordinates using an otional argument. I finally fixed this all up yesterday and this works with larger srites, too.
  • dim(54) now returns the number of lines in the var if you try to read line 0
  • dim(59) Now can convert from any base 1 to 36 into any other base 2 to 36. Numbers can even be a few hundred digits long!
  • dim(64) (which is Copyprog) now works. The issue was super simple, too, so I wish I had figured it out earlier.
  • dim(46) (portedit) now works!
  • dim(85) (Getprogname) now works completely and flawlessly


Now for the new commands!
  • dim(105) (pxlLine) draws a line with pixel coordinates. There are also draw modes where you supply a list as a draw pattern
  • dim(106) draws a circle very quickly using pixel coordinates. There is also a mode for using draw patterns
  • dim(107) draws a pxlline to a variable (like a pic var)
  • dim(108) draws a pxlcircle to a var
  • dim(109) can be used to open up a popup menu. Selecting an otion returns a number.
  • dim(110) can be used to convert a number to a string. This does not work with imaginary numbers.
  • dim(111) converts a list to a string. This works with imaginary numbers
  • dim(112) compresses a string of text. There are two built in codecs.
  • dim(113) decompresses a string of compressed text.
  • dim(114) will return an optimal codec string for a string of data.
  • dim(115) will compress data with a custom codec.
  • dim(116) will decompress data with a custom codec.
  • dim(117) will perform a search and replace, scanning a variable.
  • dim(118) will work like my GetName program. It returns, in alphabetical order, the name of a variable of a given type. For examle, this can be used to get the name of the third program in the program list.
  • dim(119) provides lowercase options.
  • dim(120) provides text options
  • dim(121) and dim(122) are options to draw a sprite to a variable (like a pic var)
  • dim(123) will delete a line from a data base


Also, in this release is a beta/test version of BatLib that will be able to use a revolutionary new "GroupHook" that I came up with. Since no other apps have it, I had to perform some modifications to existing apps for demonstration. Basically, I managed to make it so that when I installed BatLibG, I could use the parser hooks in Celtic 3, Omnicalc, and Grammer, too without installing them. Celtic 3 and Omnicalc did conflict with the real( commands, though. I managed to modify DoorsCS7, too, and I could use Celtic 3 and DSC commands, too, but I will not release the modified DCS7 because I haven't talked to Kerm about it.

Finally, I could not send the as to my actual calc (I need to get new batteries), so I could not check if there were any issues on calc that didn't occur in WabbitEmu.

1675
TI Z80 / Re: ORG: online Z80 IDE and assembler
« on: June 08, 2012, 07:05:14 am »
yep :) pretty much anything that works on the TI-83 will work on the TI-82 STATS. These updates are awesome !

1676
TI Z80 / Re: Samocal
« on: June 07, 2012, 10:40:54 pm »
Hehe, thanks :) It isn't done yet, though XD I have been working on this on and off for over a year and it will probably still take a while to finish it. I have too many other projects and IRL things (like school and work), unfortunately x.x Still, I hope it turns out to be as awesome as I plan :D I am basing most of the work on an older game that was called "Battle 3.2.3.5" that I wrote in TI-BASIC. I lost the program years ago, but it had cool features like a blacksmith, creatures, different maps, over 70 items, a lottery and other such things. When I ported it to Omnicalc and xLIB/Celtic III, I never really finished the port.

EDIT: Also, as a note, this program currently use 8312 bytes which is cool :)

prgmITEMS    1567 bytes   ;all the item data inlcuding names, description, and code for what it does.
prgmWALK     3642 bytes   ;the main program that will eventually be renamed
appvMapA     2513 bytes   ;the first 50x50 map
appvSamoSave  316 bytes   ;the quick-save file. In the future, there will be an appvar containg several save files. This will be in archive.
appvTiles     274 bytes   ;the tile data


1677
TI Z80 / Re: Samocal
« on: June 07, 2012, 09:23:38 pm »
Hmm, it is weird that I never replied, maybe my internet was buggy. To answer your question, yes, you just need to draw a tilemap on two separate buffers and be sure to use DispGraph frequently. You will also need to be sure to define which buffer is the primary buffer and which is the secondary. (use Disp with the degree/minute modifier).

Anyway, I added a little bit to this last week, so now I have stats and a working item menu and item list. You can now use items, in theory, but since there is no way to actually lose health without hex editing the save file, it doesn't really help. All of the items programmed in have all the code necessary to work for battle and for out of battle, properly. There are currently 23 items including the material to use for creating new items such as armor, weapons, and charms. I don't have any of those kinds of items programmed in, yet, though.


1678
Math and Science / Re: Cool math hacks
« on: June 06, 2012, 09:46:40 pm »
First, let me clarify that I am working solely with positive integers (natural numbers).
These proofs are not very formal, sorry. Typing them is a bit more tedious than writing them on paper :/

Theorem: All integers except those of the form 4n+2 are the difference of two squares.
Proof:
Here, I will simply show by cases.
Let A be odd, B be even. That is, A=2n+1, B=2m. Then:
  • A2-B2=
  • (2n+1)2-(2m)2=
  • 4n2+4n+1-4m2=
  • 4(n2+n-m2)+1=
  • 4l+1


Now, let A be even, B be odd. That is, A=2n, B=2m+1. Then:
  • A2-B2=
  • (2n)2-(2m+1)2=
  • 4n2-4m2-4m-1=
  • 4(n2-m2-m)-1=
  • 4k-1=
  • 4(k-1)+3=
  • 4l+3=


If both are even, you have:
  • A2-B2=
  • (2n)2-(2m)2=
  • 4n2-4m2=
  • 4(n2-m2)=
  • 4l


If both are odd, you have:
  • A2-B2=
  • (2n+1)2-(2m+1)2=
  • 4n2+4n+1-4m2-4m-1=
  • 4(n2+n-m2-n)+1-1=
  • 4l
[qed]

These are all the possible case, so you can have 4l,4l+1,and 4l+3 as the difference of two squares.

As a very simple proof that all odd integers can be the difference of two squares, just plug in the trivial solution (c+1)/2 and (c-1)/2 for A and B respectivels. Since c is odd, c+1 and c-1 are even, so you can divide by two. For a process to arrive to this conclusion, forst note that the difference of two consecutive squares is odd. That is:
(n+1)2-n2=n2+2n+1-n2=2n+1

So if you want to find, say, 23 as the difference of squares, 23=2n+1 means n=11. So 122-112=23. The powerful result of the math hack I presented says that because 23 is prime, this is the only solution.

Theorem: If c is composite and odd, then there is a non-trivial solution for A2-B2=c.
Proof:
Let c be composite. That is, let c=n*m where n and m are neither 1. Since A2-B2=(A-B)(A+B), let n=(A-B) and m=(A+B). Then:

n+2B=A+B
n+2B=m
2B=n-m
B=(n-m)/2      ;since c is odd, n and m are odd, so n-m is even.
A=(n+m)/2      ;This, too, is an integer.
[qed]

Theorem: If c is an odd prime, then the non-trivial solution for A2-B2=c is the only solution.
Proof:
Assume there is a non trivial solution for A and B, A=D, B=E. This implies that (D-E) and (D+E) are factors of c. Since c is prime, the only factors are 1 and c. Therefore, (D-E)=1, (D+E)=c. This means:

D+E=1+2E, D+E=c
1+2E=c
E=(c-1)/2
D=(c+1)/2

However, this is the trivial solution, so we have met a contradiction. Therefore, the trivial solution is the only solution
[qed]

EDIT: I opened up my notes and followed through some of my work and what I have found so far:
If there is a non-trivial solution for A2-B2=c, then it is of the form (A+2d)2-(B-4e)2 where d and e are integers. This will let me speed up my code as I can forget about half or 3/4 of the potential values. I am still working on cutting that down even more :)

1679
Math and Science / Re: Cool math hacks
« on: June 06, 2012, 08:20:05 pm »
Hmm, I was fooling around with my math notes when I came across an old proof. I saw that all numbers of the form 4n+2 could not be expressed as the difference of two squares, but all other numbers could. However, I pretty much left it at that. Let me tell you now that there will be a really cool hack with this, but there is more to the story. Anyway, I was looking through another notebook and some of my work on the Putnam two years ago and I saw a familiar proof where I showed that all integers >2 are in at least one pythagorean triple (I had broken down the problem to requiring only this to be true). Anyways, all I did was design a formula where, given a value A, you could get a B and C. Anyways, the process to designing the formula sparked an idea. Here is the awesome math hack:

I had shown that all integers not of the form 4n+2 could be expressed as the difference of two squares, so essentially, I have A2-B2=c. If we look at only odd integers for c, however, we get magic. If c is odd, there is a trivial solution for A and B:
A=(c+1)/2
B=(c-1)/2

But guess what? A2-B2=c can be factored to (A-B)(A+B)=c. DO you know what this means? Here:
  • If c is prime, the trivial solution is the only solution
  • If c is composite, there is more than one solution


I have been using this to write really fast factoring algorithms in assembly and I have been trying to figure out if there is a polynomial time method to finding if A2-B2=c has more than 1 solution (aside from using the AKS primality test on c). If you can find a way, then you can potentially run a very fast prime testing algorithm. Other than that, since I made this connection, I have been putting tons of energy toward following every path I can with this.

1680
BatLib / Re: BatLib
« on: June 06, 2012, 08:03:58 pm »
Hehe, I still plan to get back to work on this some day. I want to rewrite it to add more commands and add in some more optimisations. I still plan to add in arbitrary precision math commands, too. I have written a multiplication routine that is only limited by the amount of RAM you have. I made it multiply two 100-digit numbers :D

Pages: 1 ... 110 111 [112] 113 114 ... 317