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 ... 181 182 [183] 184 185 ... 317
2731
Grammer / Re: Grammer 2-The APP
« on: December 11, 2011, 12:15:32 am »
So not much of an update, but I added inString( as a command. The arguments are:
inString(Offset,SearchStart,SearchString
I don't think the first argument is really needed so I might remove it before the next update. The outputs have theta prime containing the size of the search string and Ans has the location of the first match (or 0 if there is no match).

okay, back to studying for finals/sleeping/programming

2732
TI Z80 / Re: asmdream is waking up...
« on: December 10, 2011, 09:29:50 pm »
Ah, now I see where you would need that. I took a peak at the bcalls, but I have not found a good way to do this, sorry :/

2733
TI Z80 / Re: ASMComp
« on: December 10, 2011, 07:41:19 pm »
Necroupdate? Anyways, I haven't really done much except add in some error catching. I broke the ability to compile from archive, so I am not going to release this version yet, but here is a screeny :)

As a note, the program I am compiling in the screenie is just a code that jumps into a program at an offset of 4 with the error "OH CRAP!" just for fun. That is a 3 factorial, by the way. :P

2734
TI Z80 / Re: asmdream is waking up...
« on: December 10, 2011, 05:30:36 pm »
Hmm, well then I am not sure what could cause the issue :/
Here is some code to give you an idea of how it works:
Code: [Select]
    ld de,9652h      ;115296  ;address to store the name
    ld hl,8478h      ;217884  ;ld hl,OP1
    ld bc,9          ;010900
    ldir             ;EDB0    ;copies the name in OP1
    bcall(42F1h)     ;EFF142  ;bcall(_CheckFindSym)
    ex de,hl         ;EB
    ld c,(hl)        ;4E
    inc hl           ;23
    ld b,(hl)        ;46
    inc hl           ;23      ;HL points to the start of the var
    ld (965Bh),hl    ;225B96

    ld d,h \ ld e,l  ;545D    ;points to the start of the var
    add hl,bc        ;09      ;HL is now the end of the var
    ld (965Fh),hl    ;225F96

    ld bc,4          ;010400  ;Offset into the var to error at
    ex de,hl         ;EB
    add hl,bc        ;09
    ld (965Dh),hl    ;225D96

    ld hl,ErrorMsg   ;21****
    ld de,984Dh      ;114D98  ;Where custom error message needs to be
    ld bc,14         ;010E00  ;14 is max size of message
    ldir             ;EDB0
    ld a,2Bh+80h     ;3EAB    ;Custom error
    bcall(44D7h)     ;EFD744  ;jError
    ret              ;C9      ;Don't think this is needed XD
ErrorMsg:
    .db "Oh Crap.",0 ;4F6820437261703A

For a bonus I can show errors in action with my own assembler project >.> (I haven't added nearly as much functionality as you). The errors jump to bad equates/labels or non-hex digits were hexadecimal is expected.

2735
ASM / Re: 24 bit multiplication
« on: December 10, 2011, 12:25:16 pm »
Okay, so multiplying and dividing you probably actually know-- you just don't know it. So you remember in grade school learning how to multiply large numbers:
Code: [Select]
  432
  x27
-----
Well that is actually the best method and fastest. What you do is multiply 2*432. THen you shift the digits left and throw a zero at the end. Then you multiply 432*7 and add the two values together. Voila, multiplication :) Now in binary, math is almost always easier. Because you are using 0 and 1, multiplication is easy:
Code: [Select]
11000101
11010111
so you take the last digit of the second number and you get 1. Multiply 1 times the first and you get 11000101. Now shift that left and check the next bit of the bottom number. If that is 1, add it to the accumulator (the accumulator in this case is the running total, not necessarily the a register).
So here is what it looks like in assembly code:
Code: [Select]
;D*E
     xor a       ;This is the accumulator
     ld b,8      ;this is the counter
MultLoop:
     add a,a     ;this is to rotate the accumulator left. Use rlca, too
     rlc e       ;This puts the next bit in E in the carry
     jr nc,$+3   ;If the bit in E was not 1, you add 0 (so don't add!)
       add a,d   ;1*D=D, so add D. Binary makes math easy.
     djnz MultLoop
     ret

When it comes to division in z80, you are pretty much just doing long division. Finding the square root, however, is something you probably didn't do in school since we have calculators and it was taken out of the school curriculum (I sound old D:). Anywho, I learned how to do it in decimal from a textbook from the 1950's and then I extended it to binary since it is much, much easier in binary. It is difficult to explain in a post (you kind of need to see it to understand it), but here is an excellent site:
http://www.homeschoolmath.net/teaching/square-root-algorithm.php

The second method is what you will want to use as it gives each consecutive digit every cycle. If you can understand that well, you will probably see why it is so much easier in binary and how to create a z80 algorithm :)


2736
TI Z80 / Re: asmdream is waking up...
« on: December 10, 2011, 12:01:15 pm »
Okay, did you do the other parts? Meaning store the name of the var at 9652h, the start address of the data (not the size bytes) at 965Bh, the error location at 965Dh and the end var address at 965Fh?

2737
ASM / Re: 8X+ > bcall question
« on: December 09, 2011, 08:11:52 pm »
Yeah, because I was planning to use other RAM pages there with a 2-page app and that wouldn't do D:

2738
TI Z80 / Re: asmdream is waking up...
« on: December 09, 2011, 08:06:09 pm »
Oh, hey, did your question ever get answered about jumping to errors? I do this in Grammer, so I do know how to do this, but to make life easier, you will need to only allow it for programs in RAM. Anyways, what I would do:

-At the beginning of the program, store the source file name at address 9652h. Since you must at some point have the name of the program in OP1, just copy OP1 here.
-Next, get the size of the program and make sure to have a pointer to the data (not the size bytes)
-Store the address of where the program data is at 965Bh
-Add the size of the program to the start address to get the end of the source file and store it to 965Fh

Now you are all set up. When you need to jump to an offending byte, store the address to 965Dh and then just use bcall(_JError)

I hope this helps!

2739
ASM / Re: 24 bit multiplication
« on: December 09, 2011, 07:39:22 pm »
Okay, so this isn't too helpful, but it is an idea: I came up with a very simple algorithm that gets very accurate very fast (12 cycles for 16-bit numbers). On the Z80 it isn't that fast since it requires multiplication and division, but the algorithm looks like this:
Code: [Select]
B/2→A             ;start with anything, really
For(C,1,12
(A+B/A)/2→A
End

To implement this in assembly code, you will want to multiply the input by 4 (shifting left twice) and then divide the output by 2. Then if you want added precision, if there is a carry, increment by 1. Again, in z80, this algorithm isn't really worth it since it isn't as speed efficient as other methods, but it can be easier to grasp :) Plus, if you move on to coding for devices with the ability to multiply and divide, you will have a really tiny algorithm that uses a counter, input, and output as opposed to a bajillion registers.

2740
ASM / Re: 8X+ > bcall question
« on: December 09, 2011, 07:20:03 pm »
Ah, so you mean you were using the built in bcall() routine for apps? I do not believe this occurs with regular bcalls from my study of the code.

I had actually forgotten all about that side effect which is something I will need to deal with soon...

2741
Introduce Yourself! / Re: Bonjour le monde.
« on: December 09, 2011, 07:13:00 pm »
You have 2*3*5*7*11 posts now and I never said welcome here D:

Welcome! :P

2742
Wow, cool O.O

2743
ASM / Re: 24 bit multiplication
« on: December 08, 2011, 03:54:25 pm »
Okay, here is some pseudo code for an algorithm that will always work and is fast (each cycle gives the next digit):
Code: [Select]
    0→A
     0→D          ;This is where the result will go
     0→C          ;This is a carry
     For(B,1,12)  ;12 is half the number of input bits
     D+D→D        ;We want to shift D left
     D+D+1→C      ;The difference of consecutive squares?
     A<<E         ;rotate E left, then rotate the carry into A
     A<<E         ;In z80, "rlc e \ rla"
     If A>=C      ;If A is greater than or equal to C
       D+1→D
       A-C→A
     End
;You will need an input       (24 bits in the above example)
;You will need an output      (12 bits in the above example)
;You will need a counter      (4 bits in the above example)
;You will need an accumulator (24 bits in the above example)
;You will need a carry        (13 bits in the above example)
;
;You will need at least       (77 bits in the above example)
So for a simple 8-bit implementation in Z80 code:
Code: [Select]
;===============================================================
sqrtE:
;===============================================================
;Input:
;     E is the value to find the square root of
;Outputs:
;     A is E-D^2
;     B is 0
;     D is the result
;     E is not changed
;     HL is not changed
;Destroys:
;     C=2D+1 if D is even, 2D-1 if D is odd

        xor a               ;1      4         4
        ld d,a              ;1      4         4
        ld c,a              ;1      4         4
        ld b,4              ;2      7         7
sqrtELoop:
        rlc d               ;2      8        32
        ld c,d              ;1      4        16
        scf                 ;1      4        16
        rl c                ;2      8        32

        rlc e               ;2      8        32
        rla                 ;1      4        16
        rlc e               ;2      8        32
        rla                 ;1      4        16

        cp c                ;1      4        16
        jr c,$+4            ;4    12|15      48+3x
          inc d             ;--    --        --
          sub c             ;--    --        --
        djnz sqrtELoop      ;2    13|8       47
        ret                 ;1     10        10
If you want to refine the accuracy to round to the nearest integer, you can add this code to the end of the Z80 code:
Code: [Select]
       cp d                ;1      4         4
        jr c,$+3            ;3    12|11     12|11
          inc d             ;--    --        --
It takes advantage of the linear differences of a quadratic (meaning (a(x+1)2+b(x+1)+c)-(ax2+bx+c) is a lnear equation)

Anywho, I am being told I need to finish this up, so I hope this helps until I can find time later >.>

2744
ASM / Re: 24 bit multiplication
« on: December 08, 2011, 11:36:34 am »
Well I am almost positive that using my algorithm would require the use of RAM, even if you used all the shadow registers, too.

2745
ASM / Re: 24 bit multiplication
« on: December 08, 2011, 11:20:31 am »
So you really need 48-bit square root...
This could be fun x.x :D

Pages: 1 ... 181 182 [183] 184 185 ... 317