Jump to content
Sign in to follow this  
Heaven/TQA

Lookup Table Generator PC/Mac tool?

Recommended Posts

I am searching the net for a Windows or Mac tool which can generate all sorts of lookup tables and export that as text file preferable with a syntax?

 

prefarable for sin/cos... as I am too stupid to use the SIN command in MADS...

 

or can someone explain me how I easily can create a table with in 16bit?

 

-63 to 63 but with 8bit fraction? dta b(sin(63,64,0,0)*256 does not help here?

 

or any macro which I can adapt?

Share this post


Link to post
Share on other sites

When I need a lookup table like this, I use perl; something like this will whip up a 256-entry SIN table:

 

perl -MMath::Trig -e 'for my $i (0..255) { printf("    .byte %02x\n", int(sin($i * pi * 2/ 256) * 127) & 0xff ); }'

  • Like 1

Share this post


Link to post
Share on other sites

Converting the fractional part is easy. Just use the emulator in turbo mode and write a quick Basic program.

 

10 DEG : FOR AN=0 to 89

20 S=SIN(AN):I=INT(AN):F=INT((AN-I)*256):REM use INT((AN-I)*256+0.5) to do rounding

30 LPRINT " .BYTE ";I;",";F

40 NEXT AN

 

To get the fractional part of a number, it's just (number-INT(number).

 

Converting a decimal fraction to a Base256, just multiply the fraction by 256. Then either truncate or round it. To round a number, just use INT(number+0.5)

 

e.g.

0.5 = 128

0.25 = 64

0.1 = 25 (or 26 if rounded)

  • Like 1

Share this post


Link to post
Share on other sites

thx,, I did it with a turbo basic program but I can remember a tool on Windows where I can do that easily...

 

I thought after 25 years in coding there should be enough tools out there but had not found one yet... ;)

Share this post


Link to post
Share on other sites

You can use Microsoft Excel (or OpenOffice Math) to create your tables. Then export your data as .csv (comma separated values).

Share this post


Link to post
Share on other sites

I used vbscript a lot:

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("table.h", true)

MyFile.Write("MYLABEL")
MyFile.WriteLine
for i=0 to 255
MyFile.Write(getHexValue(i))
if i<255 then MyFile.Write(",")
next


Function getHexValue(value)
strValue = Hex(value)
if len(strValue) = 1 then strValue = "0" + strValue
getHexValue = "$" + strValue
End Function

 

you can save the script to myscript.vbs and run it from the commandline with 'cscript myscript.vbs'

Share this post


Link to post
Share on other sites

I used vbscript a lot:

Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("table.h", true)

MyFile.Write("MYLABEL")
MyFile.WriteLine
for i=0 to 255
MyFile.Write(getHexValue(i))
if i<255 then MyFile.Write(",")
next


Function getHexValue(value)
strValue = Hex(value)
if len(strValue) = 1 then strValue = "0" + strValue
getHexValue = "$" + strValue
End Function

 

you can save the script to myscript.vbs and run it from the commandline with 'cscript myscript.vbs'

 

 

that looks interesting. need to check that... so in theory I could use "sin" etc obviously?

Share this post


Link to post
Share on other sites

that looks interesting. need to check that... so in theory I could use "sin" etc obviously?

 

Yes, sin is a function you can use in vbscript.

Share this post


Link to post
Share on other sites

so then I would try...

 

:256	dta hi(sin(63*256,64*256,256,#,#)),lo(sin(63*256,64*256,256,#,#))

 

or whatever syntax MADS has.

Edited by MaPa

Share this post


Link to post
Share on other sites

yeah... and exactly that's not possible in mads...

 

sin is only working with DTA and DTA only with B for byte and A for word (what a logic... ;)

 

.byte <(sin(...))

 

does not work in MADS or I am again too stupid for that...

Share this post


Link to post
Share on other sites

Try this, I think that it's roughly what you wanted. There are some rounding problems and I've multiplied the fraction part through by 100 so that a Hex value can be created. Is this what you are after? It may not be precisely as you want it, but should be a good base for you to work from.

 

I hope that it works, I created it in OpenOffice Math and saved it as an Excel spreadsheet.

sine2.zip

Edited by snicklin

Share this post


Link to post
Share on other sites

Use the code below. Just h for high byte, not hi and l for low byte, not lo. Same is in Xasm which I use. I got confused with .hi and .lo directives in MADS manual. I just downloaded MADS, tested it and it works.

 

:256    dta h(sin(63*256,64*256,256,#,#)),l(sin(63*256,64*256,256,#,#))

Edited by MaPa
  • Like 1

Share this post


Link to post
Share on other sites

Try this, I think that it's roughly what you wanted. There are some rounding problems and I've multiplied the fraction part through by 100 so that a Hex value can be created. Is this what you are after? It may not be precisely as you want it, but should be a good base for you to work from.

 

I hope that it works, I created it in OpenOffice Math and saved it as an Excel spreadsheet.

 

cool... thanks.

Share this post


Link to post
Share on other sites

Try this, I think that it's roughly what you wanted. There are some rounding problems and I've multiplied the fraction part through by 100 so that a Hex value can be created. Is this what you are after? It may not be precisely as you want it, but should be a good base for you to work from.

 

I hope that it works, I created it in OpenOffice Math and saved it as an Excel spreadsheet.

 

cool... thanks.

 

Hey, didn't you write that rotating "TQA" demo in Graphics 9. If so, that must have used some sin/cos look-up table.

Share this post


Link to post
Share on other sites

sure... but the Intro "Really Unreall" was coded 1997 and used native assembler... at that time I was more into demo coding and knew how to generate look up tables... ;)

 

the intro "draws" circles at the beginning http://atari.fandal.cz/detail.php?files_id=856

 

and I can remember that I am using fixed point maths (16bit) so the circles are covering the whole pic. I used a standard multiplication routine that's the reason why it takes some time at the beginning... thank god that I got a TQA logo to put there... ;)

 

but there is no rotation or anything like that involved because it is a visual trick. I have a long runrolled draw code where it takes offsets of the circle (f.e. inner circle displays only 1 pixel of the texture while more far circles display other texels). so the code must be something like

 

ldx offset_circle1

lda texture_lo+offset1,x

ldy offset_circle2

ora texture_hi+offset2,y

sta screen

...

 

and to get it run in 50 fps... I implemented checks if pixels are on the same circle so I can avoid the second LDY...

 

and therefore in the VBL I can adjust each starting offset of each circle and voila...you have the distorting effect...

 

in 68000 it would be something like move.l offset(a0),(a1)+

 

ah...here is the source code project...

 

http://www.atariage.com/forums/topic/123826-really-unreal-source-code-found/page__p__1495977__hl__really%20unreal%20source%20code__fromsearch__1#entry1495977

 

I will try to convert that into MADS format over the weekend...

Edited by Heaven/TQA

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...