Omnimaga

Calculator Community => TI Calculators => General Calculator Help => Topic started by: Xeda112358 on November 20, 2010, 04:03:37 am

Title: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 20, 2010, 04:03:37 am
As many of you know by now, I program in hex on the calculator, but once upon a time I was a BASIC programmer-- a maker of RPG's that spread through my school, games, and math programs. Many of these programs in some way or another used an assembly opcode to make them better. Naturally, as any curious person would do, I started to play with the opcodes. After hundreds of RAM clears, I would make headway and create my own opcodes.

So what is this topic about? For those BASIC programmers (or interested Assembly programmers) I want to make some DIY assembly opcodes-- codes that I will explain how to safely modify for desired effects!.

Now where to begin... output? Okey dokey then... Here is an example program. I will explain stuff afterward:
AsmPrgm
210000
224B84
21A29D
EF1045
C9
0C
48656C6C6F20576F726C6421

Green is okay to change, it won't harm anything
Blue has rules if you want to change it
Red should not be changed

The blues are what need to be explained.

Feel free to ask questions because I am sure there will be some. I jumped right into it without explaining a lot of it, mostly because it is 4:00AM here and I haven't slept yet...
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 20, 2010, 04:29:12 am
(Off-topic: Btw have you released any of those RPGs? I kinda like RPGs, unless they're only menus and short)

That seems like an interesting topic. It might be helpful for BASIC coders who want to have some small libs.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 20, 2010, 04:32:01 am
Sorry, I made them two years ago, before I had internet access :C But I have been trying to remake them when I get random time. They had animation and where mostly in BASIC except for a few opcodes. I used the creative idea of polar graphs for sprites!
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 20, 2010, 05:09:00 am
Ah ok I see. Do you still have them or are they gone for good, like Donjon, Illusiat 4 and Illusiat 2002?
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 20, 2010, 05:21:07 am
They are completely lost and gone for good :C But on the bright side, I have made several quiet attempts to revive my BATTLE series. Actually, wait a minute. Hmm... Okay, I have a newer version that does not have many features of my complete version, but it is the version that made use of Celtic 3...
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 20, 2010, 09:51:19 am
Aw sorry to hear :(. In my case I had no link cable (the TI-PC link cable was only sold with the 83+SE and unavailable separately over here) and limited computer access, so no way to backup. A bad MirageOS 1.1 crash occured and I was forced to reset both archive and RAM through a full mem reset because the ram clear and arc vars clear options didn't work anymore (freeze/crashes), same for GarbageCollecting. As a result I lost 3 RPGs I spent a lot of time on.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: ztrumpet on November 20, 2010, 10:49:08 am
Aww, are you sure that some of your friends don't still have them?  It would be really cool to see some of them. :)

This looks neat.  What does the green line do?
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Deep Toaster on November 20, 2010, 10:53:20 am
It's the text "Hello World!" in hex, so it can be changed to whatever you want.

Too bad about the games, Xeda. As ztrumpet said, are you sure you don't have a copy somewhere on someone else's calc?

And how did you do sprites with polar graphs? Was it fast? Sounds pretty fun :D
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 20, 2010, 01:27:42 pm
Okay, well here is a bit of a rundown... Back in 2008, my school loaned out TI-84+s to anybody interested, so I borrowed one as did most of my friends (only one of whom programs them). I started learning BASIC and after about a three months I had a cool RPG. It was right around the first time I broke my first assembly code to make it do what I wanted (the next one I plan to post), so it used maps made in assembly even though I had no assembly knowledge (I knew hex as a number system, of course). I had 60 items, monsters to fight, experience, stats, background stats, and my other pride: Polar Sprites (that is what I am calling them :D). Every sprite used 8 bytes and if it used less, I made it take 8 bytes so that I could easily do sub(Str1,8A+1,8→r1 where A is the monster number. I gave it to a bunch of friends, but two things went wrong. One, at the end of the year, we handed our calcs back in, and two, I had no cords to transfer it to a computer. In fact, my program, which was only about 6000 bytes in total, I put in by hand on each of the calculators.

Now, the game was mostly designed around the battling, so when you were on the map, you were just a pixel, but in the battle, the monsters had full fledged sprites that looked AWESOME. My favorite was Maxpider. The map was split up into 9 areas that had there own monsters and there was a house to enter in the center section to buy stuff and whatnot. Later on in the development, I made a program called Codem2 for cheats in my games and I made two maps to play on, but you only got to play on one which was decided at the beginning.

!!!! I just found some notes from the last time I tackled this project ♥. It is a little outdated, now, but this is what I have. (outdated because it was before I had SpriteLib and a few other programs).

Also, I am not going to guarantee that I will work on this much, but I do go back to it every now and then. I have a few other projects that I am working on as well on top of college where I am trying to complete my first major in the first two years, so I have my plate half full already :D

Edit crap, forgot to upload the files. Oh well, here are the polar coordinates at least taken from my notes:
Code: [Select]
T represents theta

Xmin=-pi/2
Xmax=pi/2
Ymin=-62pi/188
Ymax=62pi/188

I'll probably multiply the limits by 2 for the game
================================================================
Bufli sin(sin(tan(T
Magfly sin(cos(tan(T
Attack Master sin(tan(tan(T
Wataray cos(sin(tan(T
--- cos(cos(tan(T
Maxpider cos(tan(tan(T
Bufli (big) tan(sin(tan(T
Magfly (big) tan(cos(tan(T
Los-Wei tan(tan(tan(T


Eye sin(T+sin(T+sin(T
--- sin(T+sin(T+cos(T
Psyita sin(T+sin(T+tan(T
--- sin(T+cos(T+sin(T
--- sin(T+cos(T+cos(T
Shalka sin(T+cos(T+tan(T
??? sin(T+tan(T+sin(T
Healer sin(T+tan(T+cos(T
Sabem sin(T+tan(T+tan(T
--- cos(T+sin(T+sin(T
--- cos(T+sin(T+cos(T
??? cos(T+sin(T+tan(T
--- cos(T+cos(T+sin(T
Side Eye cos(T+cos(T+cos(T
??? cos(T+cos(T+tan(T
??? cos(T+tan(T+sin(T
Water Demon cos(T+tan(T+cos(T
??? cos(T+tan(T+tan(T
--- tan(T+sin(T+sin(T
--- tan(T+sin(T+cos(T
--- tan(T+sin(T+tan(T
--- tan(T+cos(T+sin(T
--- tan(T+cos(T+cos(T
??? tan(T+cos(T+tan(T
??? tan(T+tan(T+sin(T
??? tan(T+tan(T+cos(T
??? tan(T+tan(T+tan(T
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 20, 2010, 11:37:33 pm
Nice :O
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 21, 2010, 12:17:59 am
Okay, so anyway, here is the next thing, something I mentioned in my previous post. Rectangles. This was the first thing I cracked as a BASIC programmer.
Here is a rectangle that inverts the upper left quarter of the screen:
210000
112F1F
EF5F4D
C9

Again, the blue has rules...
IMPORTANT: if you put incorrect coordinates such as coordinates going off the screen or where the right coordinate is smaller than the left, you will crash your calculator.
EF5C4D-Clear Rectangle
EF624D-Fill Rectangle
EF5F4D-Invert Rectangle
EF7D4D-Rectangle Border
EF864D-Clear Rectangle Border
EF8C4D-Draw Border, Clear inside
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: AngelFish on November 21, 2010, 12:31:18 am
You're already getting respect for every post on this thread, so I'll give you another. Great job.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 21, 2010, 12:34:58 am
Thanks! I didn't even notice that, so thanks all! If anybody has questions about these opcodes or ideas, feel free to let me know. I only have a few ideas... (my next one will be how to make an assembly library).
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 21, 2010, 12:58:56 am
Nice, the rectangle stuff seems smaller than I thought.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 21, 2010, 01:04:17 am
The cool part is that you can combine codes like this:

210000
112F1F
EF5F4D
213020
115F3F
EF5F4D
C9

That was my whole premise to my ASMDRAW programs.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 21, 2010, 01:06:00 am
coyuld you translate this to something more english-style so I can get the grasp of it easier?
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 21, 2010, 01:12:28 am
Okay, say you want to make a rectangle with one corner at the pixel coordinate (8,8) and the opposite corner at (17,26). Converted to hex and you get:
(8,8)=   (08,08)
(17,26)=(11,1A)

For this opcode, you need to switch the coordinates around:
1st coordinate: 210808
2nd coordinate:111A11
Then you just choose your rectangle method.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 21, 2010, 02:06:38 am
Ah ok but do you need a copy of the routine everytime you use it?
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 21, 2010, 02:13:59 am
What do you mean? I am confused, now...
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 21, 2010, 02:15:50 am
I mean, do you have to include a copy of the rectangle drawing routine for everytime it's called? Like if you make a program that draws a nice RPG menu using rectangles 8 times, will it include 8 copies of the routine in the program? That might end up pretty large. I was wondering because on the previous page, the last piece of code seemed to have two parts looking similar.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 21, 2010, 02:17:32 am
Okay, I am still a tad lost, but the other code would draw two different boxes. Each one has its own coordinates supplied to it.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 21, 2010, 02:22:01 am
Sighs, I think I am clear enough. Could a bilingual person translates for me?

Anyway, what I mean is if we use pseudo code (similar to Axe) as example:

Would the code be more like

{x1,y1,x2,y2}
sub(RCT)
{x1,y1,x2,y2}
sub(RCT)
{x1,y1,x2,y2}
sub(RCT)
{x1,y1,x2,y2}
sub(RCT)
{x1,y1,x2,y2}
sub(RCT)
{x1,y1,x2,y2}
sub(RCT)
{x1,y1,x2,y2}
sub(RCT)
{x1,y1,x2,y2}
sub(RCT)
Lbl RCT
Draw left side
Draw right side
Draw up side
Draw lower side
End


Or would it be like

{x1,y1,x2,y2}
Draw left side
Draw right side
Draw up side
Draw lower side
{x1,y1,x2,y2}
Draw left side
Draw right side
Draw up side
Draw lower side
{x1,y1,x2,y2}
Draw left side
Draw right side
Draw up side
Draw lower side
{x1,y1,x2,y2}
Draw left side
Draw right side
Draw up side
Draw lower side
{x1,y1,x2,y2}
Draw left side
Draw right side
Draw up side
Draw lower side
{x1,y1,x2,y2}
Draw left side
Draw right side
Draw up side
Draw lower side
{x1,y1,x2,y2}
Draw left side
Draw right side
Draw up side
Draw lower side
{x1,y1,x2,y2}
Draw left side
Draw right side
Draw up side
Draw lower side

?

If you don't understand, then sorry, but I think I did my best to explain myself. Someone will have to explain for me, then.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 21, 2010, 02:25:31 am
If I wanted to draw 6 rectangles, I would need:
21xxyy11xxyyEFzz4D
21xxyy11xxyyEFzz4D
21xxyy11xxyyEFzz4D
21xxyy11xxyyEFzz4D
21xxyy11xxyyEFzz4D
21xxyy11xxyyEFzz4D
C9
Is this what you mean?
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on November 21, 2010, 02:35:08 am
Not sure. I don't know how to explain better. Can anyone else help me?
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: AngelFish on November 21, 2010, 02:36:35 am
I think he's saying that you need the code every time you draw a rectangle, but it can be done efficiently by linking the Hex together.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 21, 2010, 10:49:33 am
Yes! And I wasn't going to put this in, but I might as well. If you need to draw 10 rectangles or more it becomes more memory efficient to use this method (my new method I am using with ASMDRAW6). This example only draws three so that it isn't as confusing:

0603
21BB9D11AD9DC5ED
A0EDA013EDA0EDA0
13EDA0E5D5210000
110000EF624DD1E1
C110DFC9
0000040562
010102025F
010818187D

Here are the rules:
I don't know an easier way to describe this one which is why I wanted to leave it out... :(
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: ztrumpet on November 21, 2010, 11:06:41 am
So basically, this routine is kinda like this (in Axe-ish code):
2->B  (Number of lines to draw minus one)
For(A,0,B)
A*5+GDB1->C
Rect({C},{C+1},{C+2},{C+3})  // These refer to the values at the bottom
// The last value is for the type of the box, and I can't show that in Axe. ;D  The type for Rect() in Axe is the filled rectangle
End
Return
[[0000040562]]->GDB1
[[010102025F]]
[[010818187D]]
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on November 21, 2010, 11:18:22 am
Um, I am not very Axe literate, so I am not sure... But the stuff after C9 provides the coordinates and the rectangle type. So if we look at 0000040562 as aabbccddee, then:
aa=left coordinate
bb=upper coordinate
cc=right coordinate
dd=lower coordinate
ee=Rectangle type (EF5F4D is the inverted box; use 5F)
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on December 06, 2010, 11:47:20 pm
It has been a while, so here is my next little trick. If you have a bunch of opcodes, but you don't want a bunch of programs, you can turn them into a library. A simple library can be made using this format:

EFD74AB7C0
EFEF4A3C47
10xx
<<code>>
10yy
<<code>>
...
EF6A48C9

The xx and yy are the sizes of the <<code>> they correspond to in bytes.
The EF6A48 is just an LCD update which will occur as the last command. This can be changed to another code.

So, say I wanted to use:
Code: [Select]
05 bytes: (LCD On) 3E03D310C9
05 bytes: (LCD Off) 3E02D310C9
10 bytes: (Invert Screen) 210000115F3FEF5F4DC9
I would do:
Code: [Select]
EFD74AB7C0
EFEF4A3C47
1005
3E03D310C9
1005
3E03D310C9
100A                       ;0A is the hexadecimal value for 10
210000115F3FEF5F4DC9
EF6A48
C9
If I named this prgmA, then to run, I use a number that tells which code to run. So "0" would turn on the LCD, "1" would turn it off, and "2" would invert the screen. Anything after that would update the LCD (display the graph screen).
So:

Code: [Select]
:1                    ;LCD Off
:Asm(prgmA
:2                    ;Invert screen
:Asm(prgmA
:Pause "HI
:0                    ;LCD On
:Asm(prgmA
This would turn the LCD Off, invert the screen, and turn it back on, after you hit enter (for the Pause).

I made a program a while ago that did this for you. I am going through my TICalc programs to update them, and I came across this program. I added more features and abilities as well, and now it has 3 types of libraries it can make. A "Basic" library (like the one above). A "Tech" library that allows stringing arguments together, and a "Zeda" version which is what SpriteLib uses. Stringing would be like using {1,2,3:Asm(prgmA instead of calling the program each time.
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on January 22, 2011, 06:08:40 pm
Wow, it's been so long I actually googled this to find it :D Okay, for a quick list of Assembly opcodes, I have been working on a small document for the past few days. It has some codes that are some combination of useful, fun, funny, and crazy. Feel free to have fun and ask questions :D

*As a note, I do not have my PDF vieweriser working, so I do not know what it actually looks like or how easy it is to use ... Grrr, Adobe, grr
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Munchor on January 22, 2011, 06:09:49 pm
This is the first time I check this and it looks great! ;D
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: willrandship on January 22, 2011, 07:16:53 pm
The PDF is fine. It could be organized differently, but is definitely useable as-is.

So, a quick question: would these be separate programs, or could the opcodes be directly put into your games?
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: Xeda112358 on January 22, 2011, 07:55:05 pm
Ah, good question. They cannot be used *normally* directly in BASIC program. You need to actually create a separate program and then call it in a BASIC program using Asm(prgmPROGRAM
Here is a little demo for inputting codes:
(http://www.unitedti.org/forum/uploads/post-28158-0-42709800-1295563880.gif)

However, if you want to experiment a little (back up or archive your proggies, first!) you can combine opcodes, but you need to drop the "C9" for it to work. So, say you want to turn off the LCD, turn off the run indicator, clear the LCD and then turn the screen back on, you can do:
Code: [Select]
3E02D310
EF7045
EF4045
3E03D310
C9
Title: Re: BASIC (Ab)Uses of Assembly Opcodes
Post by: DJ Omnimaga on January 23, 2011, 02:52:29 am
I guess that's the great thing about hex programming: You can code ASM-like programs and immediately test them without having to compile anything. Granted, I recommend frequent backups because of RAM clears but if you manage to get used to it you gain the advantage of BASIC programming.

That said, when releasing your games it's best to include a version you processed with AsmComp(prgnSOURCE,prgmCOMPILED) so it's twice smaller (and in some cases twice faster to run)