Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: NikProgrammer on May 04, 2014, 02:26:26 pm

Title: Learn Hex/NikProgrammer
Post by: NikProgrammer on May 04, 2014, 02:26:26 pm
Hello. I'm new here and would like learn Hex for z80 Calculators... ASM in 28 days makes me just like that smily :banghead:. Can anybody please help?
Title: Re: Learn Hex/NikProgrammer
Post by: harold on May 04, 2014, 02:35:15 pm
Of course, but that's a little unspecific.

What's the trouble?
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on May 04, 2014, 03:11:51 pm
If you want to learn hex, Xeda is the most knowledgeable about that I think. ;)
First you need to understand all the mechanics behind asm though.
Title: Re: Learn Hex/NikProgrammer
Post by: Sorunome on May 04, 2014, 03:12:31 pm
Hex is basically asm only that you have to look up all the opcodes, though :P
Title: Re: Learn Hex/NikProgrammer
Post by: Matrefeytontias on May 04, 2014, 03:14:55 pm
Since hex is a less understandable form of ASM, if you can't get around ASM don't expect anything from hex. Hex is really if you don't have a computer but want to do ASM anyway (like Xeda and I did, but I'm definitely stupid compared to Xeda when it comes to hex (and ASM) programming).
Title: Re: Learn Hex/NikProgrammer
Post by: Sorunome on May 04, 2014, 03:16:41 pm
Also, here's an idea: put the 28 days tutorial aside for a few weeks, and then look at it again.
Eventually you'll get the hang of it ;)
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on May 04, 2014, 03:21:47 pm
Or... Do as the name suggests. :P One day, one lesson. Even though I read it much quicker than that and didn't try any of the examples, I had some pretty strong programming knowledge including Axe and some z80 asm. If you're a total n00b, Hot Dog's tutorial should be around here somewhere (TheCoder1998, that quote is for you :P).
Title: Re: Learn Hex/NikProgrammer
Post by: TheCoder1998 on May 04, 2014, 03:26:20 pm
Hot Dog's tutorial should be around here somewhere (TheCoder1998, that quote is for you :P).

lol :P

when i got the hang of basic back in the day, i tried hex programming too, but i stopped because i thought it was way too hard
but maybe you'll have more luck than i had :)
Title: Re: Learn Hex/NikProgrammer
Post by: Xeda112358 on May 04, 2014, 03:34:40 pm
Also, here's an idea: put the 28 days tutorial aside for a few weeks, and then look at it again.
Eventually you'll get the hang of it ;)
Yep, this is a really good way of doing it. I still learn things every so often when I reread it. I made this (http://www.ticalc.org/archives/files/fileinfo/434/43467.html) chart that is kind of compact, but it has notes about how to use certain types of instructions.

I think the best way to get a handle of how assembly works, you should try to learn integer counting systems like binary, and hexadecimal. It will all make a lot more sense.
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on May 05, 2014, 11:38:48 am
Hmm, this is a lot information in one go:D Thanks for the quick replies, I will try something...
Title: Re: Learn Hex/NikProgrammer
Post by: DJ Omnimaga on May 05, 2014, 12:44:40 pm
Note: Hex is not a different programming language than Z80 assembly. It's just a different way to display stuff. You can display your posts in hex, you can display code in hex, you can display image data in hex. Same for binary or base-64. In ASM's case, hexadecimal is just a different way to display the code (instead of english acronyms and syntax you just display it in hexadecimal form). However, ASM is very different than TI-BASIC if you are used to the latter, so good luck. I don't do ASM myself, but if you ask help in the right forum section on Omnimaga (welcome, by the way! :D), people will be happy to help. Also, Hot Dog's tutorial can be handy for visual people to understand certain concepts if used with ASM in 28 days, because it provides more visual examples.
Title: Re: Learn Hex/NikProgrammer
Post by: Soulthym on May 05, 2014, 03:59:50 pm
Where can I find Hot Dog's tutorial?
I already read asm in 28 days but I don't get everything...
Title: Re: Learn Hex/NikProgrammer
Post by: Hooloovoo on May 05, 2014, 06:05:00 pm
I have learned to program in assembly on the computer first using mostly ASM in 28 days and an assembler, which was probably a lot easier than learning to program directly in hex. When I wanted to program it without carrying my laptop around with me, I learned to program in hex on the calculator, and I used Deep Thought's opcode table  (http://Deep Thought's table) as a reference for the opcodes. Calcsys  (http://Calcsys)is also an incredibly useful on-calc program for disassembling your program and looking at other people's programs closely. WikiTI (http://WikiTI) is also a good resource.
Title: Re: Learn Hex/NikProgrammer
Post by: the_mad_joob on May 06, 2014, 09:09:42 am
Yeah, starting directly with hex should be done when you have no other choices.
Even machines don't really understand hex when you think about it.
human symbolic language <> xeda native language <> machine language
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on May 06, 2014, 01:00:27 pm
LOL at the Xeda's native language thing. XD I think she's the only one to have started with hex actually.
Title: Re: Learn Hex/NikProgrammer
Post by: the_mad_joob on May 08, 2014, 05:24:32 am
I'm not sure, but the very first guyz who started to program machines must have done it using hex editing, always comparing what they typed to a book referencing matches with the different available instructions.
Programming in hex today is the greatest possible homage to those dudes...
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on May 08, 2014, 07:18:01 am
I mean, she's the only one to have done it on the TI calcs.
Also yeah, the first machine was surely programmed by hand. Or maybe they made a maskrom or something to have initial boot.
Title: Re: Learn Hex/NikProgrammer
Post by: Matrefeytontias on May 08, 2014, 08:04:47 am
I mean, she's the only one to have done it on the TI calcs.

No. I too.
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on May 08, 2014, 08:05:29 am
You learnt hex before mnemonics ? Nice. :D
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on May 09, 2014, 11:27:32 am
Maybe I can learn hex though? I not always have acess to my computer and would like to program without it:)
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on May 09, 2014, 11:29:20 am
You can. But was still recommend that you learn to code with mnemonics first.
Title: Re: Learn Hex/NikProgrammer
Post by: Runer112 on May 09, 2014, 12:32:13 pm
Maybe I can learn hex though? I not always have acess to my computer and would like to program without it:)

You can write assembly programs on-calc with Mimas (http://www.ticalc.org/archives/files/fileinfo/431/43140.html). It's an amazing on-calc assembly editor that supports most of the important things any computer-side assembler does.
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on May 09, 2014, 02:16:28 pm
If he wants to use that with Axe then it's a slightly less viable way to do it. There's the hassle of extracting the hex etc...
Title: Re: Learn Hex/NikProgrammer
Post by: TheCoder1998 on May 12, 2014, 12:15:49 pm
Oh yeah, I remember mimas, but sadly I don't know any assembly :P
I wish I did though
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on June 05, 2014, 02:39:09 pm
One more question to Hex programmers. I searched at TI-Basic developer and once found a Asm Codes List which had a few neat opcodes I still use. Now my problem is: The Program ExecAns which copies the String in Ans to prgmU and runs it, makes a Stop before running it... But I need a return:/ Can anybody help please?
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on June 05, 2014, 06:37:44 pm
What do you mean? In assembly, ret ($C9) just jumps to the last address on the stack. If you have nothing on the stack (just what was on there from the OS when it ran your program) then it will return execution to the OS. Otherwise it will return from a call or to whatever you've put on the stack. You should really just learn the mnemonics which will help you with the basics of assembly. If you want to program oncalc, use Mimas or ASMDREAM.
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on June 06, 2014, 12:17:14 pm
Did you see the program I mean?

http://tibasicdev.wikidot.com/hexcodes
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on June 06, 2014, 06:00:57 pm
Yeah. It's in hex codes. It'd be easier to help if you wrote them out in assembly mnemonics. The last line is a C9, the hex for "ret". But i don't know what you mean by "return" and not "stop". In assembly that's the same thing, quitting the program just means that there was nothing left on the stack. Do you understand what that program does?
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on June 07, 2014, 07:32:02 am
I'm making a texteditor in Basic. It will store its information in list which are named like the dokuments which have custom names. I use
:Text(-1,1,1,"Creating Document...
:"Matr>List(|F|,L"+Str0 ;Input for the program
:Asm(prgmEXECANS ;Creates a program with this Input
:prgmU ;execution of created program
:|U ;Input for next line
:Asm(DELVAR ;another asm from this site, deletes created program


Now I created a list called like the file. I'll use a simmilar way to edit this list.


If there is another way, please show me but if not please help me return to the main program because it just quits everything...
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on June 07, 2014, 07:37:03 am
But i don't know what you mean by "return" and not "stop".
I mean the TI-Basic Stop. It just stops all programs and returns to the operating system but I need exactly what you ment with "stack". It should go back one step in this stack but not delete it.
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on June 08, 2014, 12:29:03 am
ExecAns shouldn't create a program, it runs a program. It takes the code in Ans, puts it into prgmU, and runs prgmU. The problem might be that the current running program (the one that calls prgmEXECANS) gets overwritten when prgmU gets run. I'm not sure, i'll look at it later.

But this isn't really about writing assembly in hex anymore, you might want to open a new thread asking for help on this specific program. But it would really help if you provided the mnemonics instead of the hex so people other than Xeda and perhaps calc84maniac actually knew what the code did. Hex is such a pain.
Code: [Select]
;(saferam1 = saveSScreen)
name_str = saferam1
size = saferam1+2
code_start = saferam1+4

start:
    bcall(_RclAns)            ;set pointer into OP1
    cp 4
     ret nz
    ld hl,$55                ;ASCII for 'U'
    ld (name_str),hl        ;save zero terminated string name
    ld (OP1+1),hl
    ld hl,code_start
    ex de,hl                ;de = code_start, hl = ans ptr?
    ld c,(hl)                ;i assume bc = size of Ans
    inc hl
    ld b,(hl)
    inc hl
    ld (size),bc
    ldir                    ;copy code in Ans into saferam
    bcall(_ChkFindSym)
     jr c,not_found
        bcall(_DelVarArc)    ;del prgmU if it existed
not_found:
    ld a,5                    ;5 = non-protected program
    ld hl,saferam1
    bcall(_ExecuteNewPrgm)    ;a = var type, hl = pointer to structure (zero terminated string, size (word), program data)
    ret
A couple things: i'm not sure if RclAns actually gives readable results in a/de/hl. They seem to assume that _RclAns puts out the same outputs as _ChkFindSym (see WikiTI (http://wikiti.brandonw.net/index.php?title=83Plus:BCALLs:42F1)). WikiTI and the 83 Plus System Routines manual both say all registers are destroyed (ie. return junk/non-useful info). I don't know what happens with _ExecNewPrgm, it may kick the currently running BASIC program out.

EDIT: If all you want to do is create a program, you should look at the _CreateProg (http://wikiti.brandonw.net/index.php?title=83Plus:BCALLs:4339) bcall.
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on June 16, 2014, 06:04:45 pm
Was that to me? I don't understand ASM... But by the way I want to learn it though.
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on June 16, 2014, 06:15:48 pm
That's the same code as from TI-BasicDev just in assembly mnemonics. I'm not really sure what you want, when you run that program does it return to the TI-OS? Like i said there, there's another routine to call if all you want to do is create a program (_CreateProg).
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on June 17, 2014, 04:15:35 am
Was that to me? I don't understand ASM... But by the way I want to learn it though.
Wait. Did you even follow what we said ? Hex programming = assembly. You can't learn one separately, it's just two ways to write it.
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on June 17, 2014, 11:18:40 am
Sorry, I am bad at explaining... I know HEX and ASM are the same things, the first one is just ASM translated to the calculator's language.
Or am I wrong?!
Title: Re: Learn Hex/NikProgrammer
Post by: Xeda112358 on June 17, 2014, 11:24:34 am
That is correct. Streetwalrus was referring to this:
Was that to me? I don't understand ASM... But by the way I want to learn it though.
We are giving you the ASM to help you learn it. You can't really understand the hexadecimal machine code without understanding the ASM instructions with which they are associated.
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on June 29, 2014, 03:33:55 pm
So I am trying again to learn ASM in 28 days (it's a lot easier the second time) but TASM does not work on my new 64 bit notebook. I downloaded SPASM but now even the copy-pasted hello world program makes it throw errors on each b_call and I really don't know what went wrong... I suppose the TASM syntax is a bit different from the SPASM syntax?
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on June 29, 2014, 05:27:36 pm
You'll need to add:
#define b_call(xxxx) rst 28h \ .dw xxxx
..to the top. Also, i would recommend using this ti83plus.inc (http://brandonw.net/svn/calcstuff/OS2/trunk/extras/ti83plus.inc) instead. Most people use bcall(_XXXX), you might find that that is already defined in your ti83plus.inc.

EDIT: Just to clarify, that is bcall without the underscore. I believe TI added an instruction for B_CALL, so you might be able to use B_CALL _NewLine (no parentheses) just like any other instruction, too.
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on June 30, 2014, 10:31:08 am
Ok, thank you, I'll try this when I'll have more time... (If I ever will have more time... :P :/)
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on July 03, 2014, 10:36:09 am
It does not work...
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on July 03, 2014, 03:01:54 pm
What doesn't work? Assembling it? Are you using the ti83plus.inc (http://brandonw.net/svn/calcstuff/OS2/trunk/extras/ti83plus.inc) that i linked to? What exactly are you trying to assemble (can you post the code)? Does it not assemble or does the .8xp not work?
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on July 04, 2014, 10:50:00 am
What does not work is the assembling.
I use the include file you showed me.
Code:

.nolist
#include "ti83plus.inc"
#define    ProgStart    $9D95
.list
.org    ProgStart - 2
    .db    t2ByteTok, tAsmCmp
    b_call(ClrLCDFull)
    ld    hl, 0
    ld    (PenCol), hl
    ld    hl, msg
    b_call(PutS)
    b_call(NewLine)
    ret

msg:
    .db "Hello world!", 0
.end
.end

I removed the underscores before the b-call names, like you said me
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on July 04, 2014, 11:04:48 am
The underscores need to be in there afaik.
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on July 05, 2014, 04:08:26 am
It once didn't work with underscores :blah:
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on July 05, 2014, 09:05:48 am
I was talking about the underscore in the B_CALL macro ;)
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on July 06, 2014, 05:45:59 am
Wait, let me see if I understand correct.
A b_call calls a subprogram which is stored in the Include file. So, for example,you don't have to set each pixel to make an "A" or "B". You say: Output this letter here! While assembling later, SPASM searches in the include file for this letter and exchanges the "Output this letter here" with "Set these pixels". Right?
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on July 06, 2014, 06:47:55 am
Not quite. A bcall is like a subroutine, except it's provided by the OS.
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on July 06, 2014, 08:33:01 pm
The bcalls are a bit more complicated than that. What you will find in ti83plus.inc is an address for the bcalls. Someone else can probably explain this much better, but i believe essentially there's a big table which holds the address + flash page of the bcalls. The bcalls are stored in the OS, the include file just provides you with an easy way to access them. Rather than remember the address in the table (for example, $450A for _PutS) you can just type the name. There isn't any code in the include file so it won't increase the size of your file any, there are only equates.
Title: Re: Learn Hex/NikProgrammer
Post by: Streetwalrus on July 07, 2014, 10:03:15 am
The bcalls are a bit more complicated than that. What you will find in ti83plus.inc is an address for the bcalls. Someone else can probably explain this much better, but i believe essentially there's a big table which holds the address + flash page of the bcalls. The bcalls are stored in the OS, the include file just provides you with an easy way to access them. Rather than remember the address in the table (for example, $450A for _PutS) you can just type the name. There isn't any code in the include file so it won't increase the size of your file any, there are only equates.
I can confirm that bcalls use a vector table.
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on July 13, 2014, 05:52:01 am
Ah, OK. Thank all you!
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on July 25, 2014, 06:39:34 pm
Let me see...
So are there good tutorials except of 28 days and Hotdog's?
And where do I find Hotdog's tutorial?

I'm sorry for my whole questions, ASM is just a trouble :/
Title: Re: Learn Hex/NikProgrammer
Post by: DJ Omnimaga on July 25, 2014, 11:54:37 pm
The only tutorial I ever used besides ASM in 28 days and the other existing ones when I tried learning ASM was ASMGuru, but the learning order is weird and it's only for the TI-83, not the 83+, so it might confuse you even more when you switch back to the 83+.
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on July 27, 2014, 11:59:53 pm
I highly recommend CoBB's z80 guide:
http://sgate.emt.bme.hu/patai/publications/z80guide/ (http://sgate.emt.bme.hu/patai/publications/z80guide/)

I started with AsmGuru back in the day and thought it was great, but really all it teaches you is how to use bcalls and work with system flags. Not too useful if you want to get started on games as you won't really understand the logic behind things. CoBB's tutorial provides a more theoretical approach i think as does 28 Days and will get you much closer to being able to dive into your own games.

I never spent too much time looking through Hot_dog's tutorial, it came a bit after my tutorial time, but it's in the Omnimaga archives:
http://www.omnimaga.org/files/Our-TI-PC-Products-Music-and-Calculator-Videos/Our-TI-Documentations/ (http://www.omnimaga.org/files/Our-TI-PC-Products-Music-and-Calculator-Videos/Our-TI-Documentations/)

EDIT: You might want to check out the "readme" to CoBB's tutorial, it's got a nice explanation of the dangers of just using other people's code (or BCALLs) without really understanding/taking the time to understand what they do:
http://sgate.emt.bme.hu/patai/publications/z80guide/read1st.html
Title: Re: Learn Hex/NikProgrammer
Post by: DJ Omnimaga on July 28, 2014, 12:02:54 am
Hot_Dog's tutorial is more for people who are visual and cannot learn without concrete examples that are interesting to them or real life analogies. IIRC he said it was meant to be used alongside ASM in 28 days.
Title: Re: Learn Hex/NikProgrammer
Post by: NikProgrammer on July 28, 2014, 03:14:28 pm
Thank you (both).
I think in about a year the NikProgrammer TM will open it's assembly factory and start produce software :blah: :D :-\
Title: Re: Learn Hex/NikProgrammer
Post by: chickendude on July 28, 2014, 08:33:39 pm
The best thing you can do in my opinion is start with a couple small projects and gradually go from there. Really once you get the concept of spriting and tilemapping down there's a whole lot you can do. And of course ask lots of questions. Smaller projects are much more encouraging as you will actually finish them, most (but definitely not all) larger projects remain unfinished or, as was the case with The Verdante Forest, end up burning you out and making you leave the community once the project is actually finished ;) Off topic a bit, i really wish Maarten/Kozak had released the source, i would've liked to try fixing the huge lag when there are lots of animations on screen.