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 ... 27 28 [29] 30 31 ... 317
421
Community Contests / Re: CWick Contests
« on: September 24, 2015, 01:22:47 pm »
So for TI-BASIC, does this mean 140 bytes of tokens, or does something like "sin(" count as 4 chars?

422
TI Z80 / Re: Pokémon Amber
« on: September 22, 2015, 05:58:23 pm »
Yeah, maybe in like a million years when I get the motivation, I'll redo it from scratch again, but that was a lot of work to get where it was at.

423
TI Z80 / Re: Pokémon Amber
« on: September 22, 2015, 05:28:53 pm »
Sadly, no. Everybody is always told to backup their projects and unfortunately, this as well as Grammer and Batlib were lost (among many others).  Apparently when I did backup my projects, I only backed up shortcuts to my "Major Projects" folder. For Batlib and Grammer, I have some old versions still online, but I never uploaded the source or even a binary (that I am aware of) for Pokemon Amber.

424
TI Z80 / Re: Mandelbrot Set explorer
« on: September 01, 2015, 12:17:59 pm »
Yup, it's in assembly :) Even then, rendering a 64x64 screen takes a long time x.x I have some ideas for improving the speed, but it won't save much without a different algorithm altogether.

425
TI Z80 / Mandelbrot Set explorer
« on: September 01, 2015, 09:00:55 am »
I had no internet for a few days, but at the same time I had a day off from work, so I made a Mandelbrot Set explorer! It uses 4.12 fixed point arithmetic. Here is a gif of it in action, and attached are stills of some deeper zooms.



I also made my own 4x4 mini font!

426
Oh, the coords are 8-bit? Mine might not work for that in some situations.So did my code work? It seemed to scroll pretty smoothly and accurately.

427
TI Z80 / Re: CatElem - Catalog Reader
« on: August 06, 2015, 10:51:09 am »
I updated the first post. Now it is just one program that sets up itself. It correctly obtains the start of the catalog table as well as the size (tested on multiple OSes from 1.03 to 2.55MP).

After setup is complete, it shrinks down from 322 bytes  to 149 bytes, having only the essential code.

428
TI Z80 / Re: Tok2Char
« on: August 06, 2015, 08:35:44 am »
Oh, maybe, I never thought of that. I did just check with setting the French language app and the tokens were correctly converted (so you get "non(" instead of "not(" ).

429
TI Z80 / Re: CatElem - Catalog Reader
« on: August 06, 2015, 08:25:26 am »
Probably, but isn't that basically what "Input " does? Also, I want to make a note that the program does appear to work on other models and OSes, but it does not return the correct number of catalog elements. I have an idea for how to fix that :P

430
TI Z80 / Tok2Char
« on: August 06, 2015, 08:22:36 am »
This is a work-in-progress, but the intent is for it to convert a token into it's individual chars. It first converts the token to ASCII (this is easy; the OS provides a call), then the hard part is converting the ASCII to individual tokens. Uppercase is easy, and I also added conversion for lowercase chars, space, and "(" so that should get most tokens. However, something like tan-1( will not properly convert the -1.

431
TI Z80 / Re: CatElem - Catalog Reader
« on: August 06, 2015, 08:17:41 am »
Yup ^~^ It might be useful if you need to give the user a list of tokens, I dunno. It was still a pain to program XD

432
TI Z80 / CatElem - Catalog Reader
« on: August 05, 2015, 10:10:09 am »
There was a request on Cemetech that I took interest in, and this is my work so far. You basically pass a number into the program, and it returns the nth catalog element. So 1:Asm(prgmCATELEM would return "abs(" as an example. If you pass 0 into it, it returns how many catalog elements there are.

Before you can use prgmCATELEM for it's intended purpose, you must run it once, and it will set itself up for your specific OS.
Suggestion: If you are going to use prgmCATELEM in a program that you want to release into the wild, provide a fresh prgmCATELEM, not the version on your calculator. Further, you should run it once at the start of your program to install, just in case the user of your program didn't run the installation step.

There are definitely issues with how prgmCESETUP searches for the catalog table. It assumes that the catalog will not have its first 4 bytes split on two pages and it assumes that catalog starts with "abs(" and then " and ". It also assumes that the catalog end is on the same page and ends with "?".

433
Okay, I have a few ideas for modifying this, and I'll try to figure out if I can optimize it further.

The only case where the algorithm does nothing is when it has reached the end of the line, otherwise it *always* does something.
Proof: When (x1,y1) != (x2,y2), then we have 2 case: bit 7 of HL is 0 or it is 1.
Case 1: It is 0. Then the first step of incrementing x1 is carried through (since x1 != x2)
Case 2: It is 1. Then the second step of incrementing y1 is carried through (since y1 != y2)

So basically, if you check bit 7 and it is 1, skip the X step and go straight into the Y step. You only need to check bit 7 for the Y step if you did the X step, and in that case, you can directly use the sign flag from the sbc hl,de... which by the way you can just negate the deltax value during the setup phase and use an add hl,de.

I also noticed the B register was unused, so instead of using flags, I just set b=1 in the beginning, then inc b instead of setting the flag. At the end, check if b is still 1, in which case nothing was updated, so the algorithm is done.


Here is how I modified it:
Code: [Select]
    ld b,1             ;use this to check if we bresenhammed
    ld hl,(_cam_acc)
    bit 7,h            ;sign check
    jr nz,_br_xfail    ;skip if acc less than zero
    ld a,(_cam_yx+0)   ;xpos
    ld c,a
    ld a,(_end_yx+0)
    cp c
    jr z,_br_xfail     ;skip if x1==x2
    ld a,(_cam_mover+0)
    add a,c
    ld (_cam_yx+0),a
    ld de,(_cam_dy)    ;negate this in the setup code
    inc b
    add hl,de
    inc b
    jr c,_br_yfail     ;skip if acc is non-negative.
_br_xfail:
    ld a,(_cam_yx+1)   ;ypos
    ld c,a
    ld a,(_end_yx+1)
    cp c
    jr z,_br_yfail     ;skip if y1==y2
    ld a,(_cam_mover+1)
    add a,c
    ld (_cam_yx+1),a
    ld de,(_cam_dx)
    add hl,de          ;acc+dx
    inc b
_br_yfail:
    ld (_cam_acc),hl
    dec b
    ret

So question: What is the range of values for the coordinates? Are they 0~127 ? (It seems like it based on the code).


EDIT: Here, this code might work. First routine is setup, second routine is the iteration.
Code: [Select]
br_setup:
;;(b,c) = (y1,x1)
;;(d,e) = (y2,x2)
    ld (_cam_yx),bc
    ld (_end_yx),de
    ld hl,0
    ld a,d
    sub b
    add a,a
    jr nc,$+5
    dec h       ;yinc
    neg
    ld (_cam_dy),a

    ld a,e
    sub c
    jr nc,$+5
    dec l       ;xinc
    neg
    ld (_cam_mover),hl
    ld h,0
    ld l,a
    ld (_cam_acc),hl
    add a,a
    ld (_cam_dx),a
    ret

br_iter:
;;return nc if br is finished
;;x1y1=x2y2  66
;;x1+       211 or 220, save 24~33cc
;;y1+       206 or 207, save 22~23cc
;;x1+, y1+  265 or 266, save 83~84cc
    ld hl,(_cam_end)
    ld de,(_cam_yx)
    or a
    sbc hl,de
    ret z
    ld hl,(_cam_acc)
    ld bc,(_cam_mover)
    bit 7,h            ;sign check
    jr nz,_br_doy
   
    ld a,c
    add a,e
    ld e,a
    ld a,(_cam_dx)
    ld c,a
    ld a,l
    sub c
    ld l,a
    jr nc,_br_done
    dec h
    jp p,_br_done
_br_doy:
    ld a,b
    add a,d
    ld d,a
    ld a,(_cam_dy)
    add a,l
    ld l,a
    jr nc,$+3
    inc h
_br_done:
    ld (_cam_acc),hl
    ld (_cam_yx),de
    scf
    ret
EDIT: There was an error in my latter code that should be ld (_cam_acc),hl as opposed to ld hl,(_cam_acc). The algo would still work, but this makes it work better.

434
ASM / Re: ASM Optimized routines
« on: August 04, 2015, 10:52:59 am »
I decided to see if I could make a faster routine than what Runer made that did the same stuff and I came up with the following code. Mine is 3 bytes larger and on average almost twice as fast (ranging from 120cc to 525cc, and one case of 59cc). It has output in HL and returns a DataType error for inputs that are not non-negative reals, and a Domain error if the input exceeds a 16-bit unsigned integer.

One other advantage that mine has is that you can convert a float pointed to by DE, so you aren't limited to just OP1.
Code: [Select]
ConvOP1:
;;Output: HL is the 16-bit result.
    ld de,OP1
ConvFloat:
;;Input: DE points to the float.
;;Output: HL is the 16-bit result.
;;Errors: DataType if the float is negative or complex
;;        Domain if the integer exceeds 16 bits.
;;Timings:  Assume no errors were called.
;;  Input is on:
;;  (0,1)         => 59cc                        Average=59
;;  0 or [1,10)   => 120cc or 129cc                     =124.5
;;  [10,100)      => 176cc or 177cc                     =176.5
;;  [100,1000)    => 309cc, 310cc, 318cc, or 319cc.     =314
;;  [1000,10000)  => 376cc to 378cc                     =377
;;  [10000,65536) => 514cc to 516cc, or 523cc to 525cc  =519.5
;;Average case:  496.577178955078125cc
;;vs 959.656982421875cc
;;87 bytes
 
    ld a,(de)
    or a
    jr nz,ErrDataType
    inc de
    ld hl,0
    ld a,(de)
    inc de
    sub 80h
    ret c
    jr z,final
    cp 5
    jp c,enterloop
ErrDomain:
;Throws a domain error.
    bcall(_ErrDomain)
ErrDataType:
;Throws a data type error.
    bcall(_ErrDataType)
loop:
    ld a,b
    ld b,h
    ld c,l
    add hl,hl
    add hl,bc
    add hl,hl
    add hl,hl
    add hl,hl
    add hl,bc
    add hl,hl
    add hl,hl
enterloop:
    ld b,a
    ex de,hl
    ld a,(hl) \ and $F0 \ rra \ ld c,a \ rra \ rra \ sub c \ add a,(hl)
    inc hl
    ex de,hl
    add a,l
    ld l,a
    jr nc,$+3
    inc h
    dec b
    ret z
    djnz loop
    ld b,h
    ld c,l
    xor a
;check overflow in this mul by 10!
    add hl,hl \ adc a,a
    add hl,hl \ adc a,a
    add hl,bc \ adc a,0
    add hl,hl \ adc a,a
    jr nz,ErrDomain
final:
    ld a,(de)
    rrca
    rrca
    rrca
    rrca
    and 15
    add a,l
    ld l,a
    ret nc
    inc h
    ret nz
    jr ErrDomain
If you do not want to throw errors and are comfortable returning garbage results:
Code: [Select]
ConvOP1:
;;Output: HL is the 16-bit result.
    ld de,OP1
ConvFloat:
;;Input: DE points to the float.
;;Output: HL is the 16-bit result.
;;  Input is on:
;;  (0,1)         => 57cc                        Average=57
;;  0 or [1,10)   => 117cc or 126cc                     =121.5
;;  [10,100)      => 174cc or 175cc                     =174.5
;;  [100,1000)    => 276cc, 277cc, 285cc, or 286cc.     =281
;;  [1000,10000)  => 374cc to 376cc                     =375
;;  [10000,65536) => 481cc to483cc, or 490cc to 492cc  =486.5
;;Average case:  467.88153076171875cc
 
    ld hl,0
    ld a,(de)
    or a
    ret z
    inc de
    ld a,(de)
    inc de
    sub 80h
    ret c
    jr z,final
    cp 5
    jp c,enterloop
    ret
loop:
    ld a,b
    ld b,h
    ld c,l
    add hl,hl
    add hl,bc
    add hl,hl
    add hl,hl
    add hl,hl
    add hl,bc
    add hl,hl
    add hl,hl
enterloop:
    ld b,a
    ex de,hl
    ld a,(hl) \ and $F0 \ rra \ ld c,a \ rra \ rra \ sub c \ add a,(hl)
    inc hl
    ex de,hl
    add a,l
    ld l,a
    jr nc,$+3
    inc h
    dec b
    ret z
    djnz loop
    ld b,h
    ld c,l
    add hl,hl
    add hl,hl
    add hl,bc
    add hl,hl
final:
    ld a,(de)
    rrca
    rrca
    rrca
    rrca
    and 15
    add a,l
    ld l,a
    ret nc
    inc h
    ret

EDIT: I do not have time right now, but I found some really significant speed improvements while I was at work yesterday. Gotta take a kitten to the vet, but later I'll post the update ^~^

Here, this one is a bit faster, a little larger, and has the same outputs (DE,A) as the OS routine, but with modified error handling (no negative or non-real  inputs, max input is 65535 instead of 9999).
Code: [Select]
ConvOP1:
    ld hl,OP1
convFloat:
;;Inputs: HL points to the TI Float.
;;Outputs: The float is converted to a 16-bit integer held in DE, or LSB in A.
;;avg: 436.723938
;;  0-digit : 30cc              (0,1)
;;  1-digit : 92cc or 100cc     0 or [1,10)
;;  2-digit : 134cc             [10,100)
;;  3-digit : 257cc or 265cc    [100,1000)
;;  4-digit : 329cc or 330cc    [1000,10000)
;;  5-digit : 453cc or 454cc or 461cc or 462cc   [10000,65536)
;;95 bytes

    ld a,(hl)
    or a
    jr nz,err_datatype
    ld de,0
    inc hl
    ld a,(hl)
    sub 80h
    ld b,a      ;ugh, gotta keep A as the LSB, but we need to get B to be the exponent
    ld a,e      ;
    ret c
    inc hl
    ld a,(hl)
    jr z,lastdigit2
;    ld a,(hl)   ;\ I feel particularly proud of this code, so feel free to use it ^~^
    and $F0     ; |It converts a byte of BCD to an 8-bit int.
    rra         ; |The catch is, I only have A and C to use, and (hl) is the BCD
    ld c,a      ; |number.
    rra         ; |If you come up with faster, please let me know and post it in
    rra         ; |the optimized routines thread on popular TI forums.
    sub a,c     ; |Algo: Multiply upper digit by -6, add the original byte.
    add a,(hl)  ;/ Result is upper_digit*(-6+16)+lower_digit
    ld e,a
    dec b
    ret z
    dec b
    jr z,lastdigit
    inc hl
    ex de,hl
    ld a,b
    sla l
    add hl,hl
    ld b,h
    ld c,l
    add hl,hl
    add hl,bc
    add hl,hl
    add hl,hl
    add hl,hl
    add hl,bc
    ex de,hl
    ld b,a
    ld a,(hl)   ;\ I feel particularly proud of this code, so feel free to use it ^~^
    and $F0     ; |It converts a byte of BCD to an 8-bit int.
    rra         ; |The catch is, I only have A and C to use, and (hl) is the BCD
    ld c,a      ; |number.
    rra         ; |If you come up with faster, please let me know and post it in
    rra         ; |the optimized routines thread on popular TI forums.
    sub a,c     ; |Algo: Multiply upper digit by -6, add the original byte.
    add a,(hl)  ;/ Result is upper_digit*(-6+16)+lower_digit. Ha, repost.
;    inc hl      ;
    add a,e
    ld e,a
    jr nc,$+3
    inc d
    dec b
    ret z
    dec b
    jr nz,err_domain
lastdigit:
    inc hl
    ld a,(hl)
    ld h,d
    ld l,e
    add hl,hl
    add hl,hl
    add hl,de
    add hl,hl
    jr c,err_domain
    ex de,hl
lastdigit2:
    rrca
    rrca
    rrca
    rrca
    and 15
    add a,e
    ld e,a
    ret nc
    inc d
    ret nz
err_domain:
    bcall(_ErrDomain)
err_datatype:
    bcall(_ErrDataType)

435
ASM / Re: ASM Optimized routines
« on: August 03, 2015, 10:54:32 am »
Related to the previous post, I offer several alternatives to the bcalls _SetXXOP1 and _SetXXOP2. These routines are for converting 8-bit integers to TI floats. The advantages with my routines are that they are faster, you don't need to truncate to only the bottom 2 digits, and you can store the output to any location instead of just OP1 or OP2.

So first, if you still want the output to be the same:
Code: [Select]
setXXOP2:
    ld hl,OP2
    jr setXX
setXXOP1:
    ld hl,OP1
setXX:
;;Inputs: A is the unsigned int
;;        HL is where to write the TI float
;;Destroys:All
;;291cc+38b (or 144cc if A=0)
;;average: b=29/255
;;295.3215686cc
;;59 bytes
    ld c,0
    ld (hl),c \ inc hl
    ld (hl),81h
    inc hl \ ld (hl),c
    ld d,h \ ld e,l
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c

    or a \ ret z    ;If A is zero, exit early. +138cc
    ld l,a          ;\
    ld h,c          ; |
    add hl,hl       ; |Start converting A to BCD
    add hl,hl       ; |
    add hl,hl       ; |
    add hl,hl       ; |
    ld a,h \ daa  \ rl l    ; |Finish converting A to BCD
    adc a,a \ daa \ rl l    ; |Number is in LA
    adc a,a \ daa \ rl l    ; |
    adc a,a \ daa \ rl l    ; |
    adc a,a \ daa           ;/ +124cc
    ex de,hl
    ld (hl),a
    and $F0
    ret nz      ;+29cc
    rld         ;\ Rotate up 1 digit
    dec hl      ; |
    ld (hl),80h ; |
    ret         ; /
And if you want to get all 3 digits:
Code: [Select]
setXXXOP1:
    ld hl,OP1
setXXX:
;;Inputs: A is the unsigned int
;;        HL is where to write the TI float
;;Destroys:All
;;423cc+13a+63b (or 233cc if A=0)
;;average: a=99/255, b=29/255
;;435.2117647cc average
;;64 bytes
    ld bc,$0700
    ld (hl),c
    inc hl
    ld (hl),83h
    ld d,h
    ld e,l
    inc hl \ ld (hl),c \ djnz $-2
    or a \ ret z    ;If A is zero, exit early. +227cc
    ld l,a          ;\
    ld h,c          ; |
    add hl,hl       ; |Start converting A to BCD
    add hl,hl       ; |
    add hl,hl       ; |
    add hl,hl       ; |
    ld a,h \ daa  \ rl l    ; |Finish converting A to BCD
    adc a,a \ daa \ rl l    ; |Number is in LA
    adc a,a \ daa \ rl l    ; |
    adc a,a \ daa \ rl l    ; |
    adc a,a \ daa \ rl l    ;/ +132cc
    ex de,hl
    jr nz,$+6 \ ld e,a \ xor a \ ld (hl),81h    ;+(21+4/85)cc
    inc hl
    ld (hl),e
    inc hl
    ld (hl),a
    ld a,e
    and $F0
    ret nz      ;+48cc
    rld         ;\ Rotate up 1 digit
    dec hl      ; |
    rld         ; |
    dec hl      ; |
    dec (hl)    ; |Decrement exponent
    ret         ; /+63(29/255)cc
And if you want to do that, but maybe a little faster:
Code: [Select]
setXXX:
;;Inputs: A is the unsigned int
;;        HL is where to write the TI float
;;Destroys:All
;;334cc+13a+63b (or 144cc if A=0)
;;average: a=99/255, b=29/255
;;346.2117647cc average
;;75 bytes
    ld c,0
    ld (hl),c
    inc hl
    ld (hl),83h
    ld d,h
    ld e,l
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
    inc hl \ ld (hl),c
   
    or a \ ret z    ;If A is zero, exit early. +227cc
    ld l,a          ;\
    ld h,c          ; |
    add hl,hl       ; |Start converting A to BCD
    add hl,hl       ; |
    add hl,hl       ; |
    add hl,hl       ; |
    ld a,h \ daa  \ rl l    ; |Finish converting A to BCD
    adc a,a \ daa \ rl l    ; |Number is in LA
    adc a,a \ daa \ rl l    ; |
    adc a,a \ daa \ rl l    ; |
    adc a,a \ daa \ rl l    ;/ +132cc
    ex de,hl
    jr nz,$+6 \ ld e,a \ xor a \ ld (hl),81h    ;+(21+4/85)cc
    inc hl
    ld (hl),e
    inc hl
    ld (hl),a
    ld a,e
    and $F0
    ret nz      ;+48cc
    rld         ;\ Rotate up 1 digit
    dec hl      ; |
    rld         ; |
    dec hl      ; |
    dec (hl)    ; |Decrement exponent
    ret         ; /+63(29/255)cc
And if you want to convert signed 8-bit ints:
Code: [Select]
setXXX_signed:
;;Inputs: A is the signed int
;;        HL is where to write the TI float
    ld c,0
    ld (hl),c
    add a,a
    jr c,$+6
    neg
    ld (hl),80h
    inc hl
    ld (hl),81h
    ld d,h
    ld e,l
    inc hl \ ld (hl),c \ djnz $-2
    or a \ ret z
    ld l,a          ;\
    ld h,c          ; |
    add hl,hl       ; |Start converting A to BCD
    add hl,hl       ; |
    add hl,hl       ; |
    add hl,hl       ; |
    ld a,h \ daa  \ rl l    ; |Finish converting A to BCD
    adc a,a \ daa \ rl l    ; |Number is in cA
    adc a,a \ daa \ rl l    ; |(c is carry)
    adc a,a \ daa           ;/
    ex de,hl
    jr nc,$+15
    ld (hl),82h
    inc hl
    inc hl
    ld (hl),a
    xor a
    rld
    or $10
    dec hl
    ld (hl),a
    ret
    inc hl
    ld (hl),a
    and $F0
    ret nz
    rld         ;\ Rotate up 1 digit
    dec hl      ; |
    ld (hl),80h ; |
    ret         ; /

The slowest routine here has a worst case of 499cc and slowest average case is 436cc.

Pages: 1 ... 27 28 [29] 30 31 ... 317