This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's z80 & ez80 Assembly subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. Z80 & 68k Assembly => z80 & ez80 Assembly
United-TI Archives -> Z80 & 68k Assembly
 
    » Goto page 1, 2, 3, 4, 5  Next
» View previous topic :: View next topic  
Author Message
Adm.Wiggin
aka Tianon


Know-It-All


Joined: 02 Jun 2003
Posts: 1874

Posted: 14 Feb 2004 07:28:27 pm    Post subject:

ok, Detached Solutions has a topic like this (here: DS's topic Smile)
Dan Englender wrote:
There are tons of useful routines that seem to float around the message boards but we don't have a central repository for them, so I thought I'd create a thread for that purpose. I'll start with a few very simple routines, but anyone who has any routines that could be of general use should feel free to contribute. A few guidelines though, to keep everything civilized:

1) Routines should be self contained and not program specific. What I mean is, someone should be able to copy/paste the routine into their own program, and not have to deal with dependencies on things in the originating program.
2) Not too long. Please no 1000 line routines.
2.5) Please submit only routines that have been sufficiently tested.
3) By posting a routine you're granting everyone the right to use it freely.
4) Post only routines you've written or have permission from the author to post.
5) Please keep follow-up commentary on the routines in different threads. I will be heavily moderating this thread, as I'd like it to be for the actual routines only (for ease of browsing at later dates).
these are their rules, and they apply here as well.

I would like to add 1 or 2 more to that :
6. Please don't post a routine already posted on DS (unless it is optomized for speed or size)
7. Don't expect any credit for the routine (#3 actually says this, but in a cryptic form Laughing)
8. Please use the same format they did for displaying exe:
ClrScr

Code:
Your routine goes here


Thanks and Have Fun!


Last edited by Guest on 14 Feb 2004 07:41:48 pm; edited 1 time in total
Back to top
MaxVT103


Member


Joined: 24 Aug 2003
Posts: 109

Posted: 15 Feb 2004 05:23:18 pm    Post subject:

This ones one I wrote a while back but it pretty much detects if you have a coordinate within a box. I used it so that you couldn't go into the goals in the game I'm working on. But here it is.

Hotspot

Code:
;----------Hot spot detection-----------
;-----------By Donald Ritter------------
;inputs b,c (first x and y cor)
;inputs d,e(Width of box "d";Height of box "e")
;inputs h,l("h" x cor to check, "l" y cor to check
;output "a"(either true(1) or false(0) )

hdetect:
 ld a,b
 add a,d
 ld d,a
 ld a,c
 add a,e
 ld e,a
hdetect_x1:
 ld a,b
 cp h
 jp z,hdetect_x2
 cp h
 jp m,hdetect_x2
 jp hno_detect
hdetect_x2:
 ld a,d
 cp h
 jp z,hdetect_y1
 cp h
 jp p,hdetect_y1
 jp hno_detect
hdetect_y1:
 ld a,c
 cp l
 jp z,hdetect_y2
 cp l
 jp m,hdetect_y2
 jp hno_detect
hdetect_y2:
 ld a,e
 cp l
 jp z,hdetected
 cp l
 jp p,hdetected
 jp hno_detect
hdetected:
 ld a,1
 ret
hno_detect:
 ld a,0
 ret


Last edited by Guest on 15 Feb 2004 05:24:01 pm; edited 1 time in total
Back to top
anduril66
Anduril is the Flame of the West!


Member


Joined: 25 May 2003
Posts: 129

Posted: 04 Mar 2004 04:08:02 pm    Post subject:

This is a very simple program that I wrote. It searches for a byte you specify starting at a given address.
Search For Byte

Code:
3E66  ld a, C9   (the value in A is the byte you're searching for)
01FFFF  ld bc,FFFF (maximum number of bytes you look in,FFFF=65535 bytes)
210080          ld hl,8000 (the address you start looking in)
EDB1  cpir       (used Cobb's tutorial to figure out what cpir does)
EF0745          bcall(_disphl) (warning-destroys contents of HL)
C9              ret

The value outputted is one greater than the address of the byte because cpir incs hl after cp (hl). Subtract 1, and you have the
address in decimal. You can convert it to hex and uses CalcSys to confirm. If you search past FFFF, for reasons unknown to me,
it seems to go back to 0000.

EDIT BY ADM.WIGGIN:
Please follow the rules and use the correct syntax (for ease of reading later) Thank You!
(I fixed it this time, but please remember next time! Smile)


Last edited by Guest on 04 Mar 2004 09:03:15 pm; edited 1 time in total
Back to top
tardmrr


Newbie


Joined: 13 Apr 2004
Posts: 18

Posted: 29 Apr 2004 08:06:54 pm    Post subject:

This is a fast pixel plotter by Olle Hedman.

Pix


Code:
;+-----+----------------------------------------------------+
;| ALH | > PIX <  Put a pixel in Graph Backup ¦  a=x e=y    |
;+-----+----------------------------------------------------+
;/-----| PIX |----------------------------------------------\

PIX:
;       push    af            ; Uncomment these to save regs..  
;       push    de


       ld      d,0           ; Do y*12
       sla     e
       sla     e
       ld      hl,0
       add     hl,de
       add     hl,de
       add     hl,de

       ld      d,0           ; Do x/8
       ld      e,a
       srl     e
       srl     e
       srl     e
       add     hl,de
       ld      de,gbuf
       add     hl,de         ; Add address to graphbuf

       ld      de,0007h      ; Get the remainder of x/8
       and     e
       ld      e,a
       ld      IX,pixtable   ; Look up in table pixel to set
       add     IX,de          
       ld      a,(IX+0)      ; and load this

       or      (HL)          ; 'xor' toggle, 'and' cpl to clear
       ld      (HL),a          

;               pop     de
;               pop     af


       ret

pixtable:
       .db     10000000b
       .db     01000000b
       .db     00100000b
       .db     00010000b
       .db     00001000b
       .db     00000100b
       .db     00000010b
       .db     00000001b

;\-----------| PIX |----------------------------------------/
Back to top
rebel.socom


Member


Joined: 31 May 2004
Posts: 151

Posted: 11 Jun 2004 03:08:55 pm    Post subject:

This will let you change the discribtion (that is shown at the bottom of the screen in mirage)

Changeable discribtion

Quote:
.org userMem -2
.db $BB, $6D

ret
jr nc, start

.db "Mario" ;Normal discription

titleSaveChange:
.db 00h
.db "- Game Saved",00h ;Alternate discription. This will add to the Normal discription


Now to add the alternate text, do this.

Quote:
ld hl, titleSaveChange
ld a,20h ; this is a space char or " "
ld (hl),a


And to change it back ...

Quote:
ld h, titleSaveChange
ld a,00h ; to stop the alternate text.
ld (hl),a


This can be used (as in the example) to tell the user if there is a save game or not.


Last edited by Guest on 11 Jun 2004 03:11:02 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 11 Jun 2004 03:24:24 pm    Post subject:

I'm not sure if that will work: it only edits the program copy made when the program is run, not the program itself.
Back to top
rebel.socom


Member


Joined: 31 May 2004
Posts: 151

Posted: 11 Jun 2004 03:43:43 pm    Post subject:

pssst... ur not suposed to post here but i guess i'm too. it works. I've tried it on my own program. Heres an example program. Play the game than press del to save your game. Look at the discription, it will say "Phantom Star 0.81b -saved". I used mirage 1.2. As you can see the disciption is too long so make sure it fits. play aging and press clear to quit and not save. The discription is normal.

Example program from ticalc.org for ti 83 +
Phantom


Last edited by Guest on 11 Jun 2004 03:44:51 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 11 Jun 2004 03:51:58 pm    Post subject:

Guess Mirage copies the program back. All I know is that it wouldn't work in a regular program.

And pray tell how I'm "not supposed to post here?"
Back to top
rebel.socom


Member


Joined: 31 May 2004
Posts: 151

Posted: 11 Jun 2004 04:04:18 pm    Post subject:

the rules at the top
5) Please keep follow-up commentary on the routines in different threads. I will be heavily moderating this thread, as I'd like it to be for the actual routines only (for ease of browsing at later dates).

see it works because shells just bcall(_vputs) the discription. So if you change the .db 00 to .db 20h, bcall(_vputs) wont stop where it normaly stops. It will print whats atfer that too.

Just try Phantom. Im telling you it works
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 11 Jun 2004 05:05:31 pm    Post subject:

I just wrote a program, it does not work. I'm telling you, you have to write back to the original program.
Back to top
rebel.socom


Member


Joined: 31 May 2004
Posts: 151

Posted: 11 Jun 2004 08:54:05 pm    Post subject:

Sir Robin wrote:
I just wrote a program, it does not work. I'm telling you, you have to write back to the original program.

did u try phantom? and what do u mean write back
Back to top
rebel.socom


Member


Joined: 31 May 2004
Posts: 151

Posted: 01 Jul 2004 02:14:01 pm    Post subject:

PROG SEARCH

here is a routine that lets the user select a program instead of the asm program finding the ones to use. have the user selcet a program than see if that prgram is ok for use (Razz i cant say that any better, i dont know what your making your program for^_^ )


Code:
  bcall(_zeroop1);erase op1
  ld a,ProgObj  ;05h program object pointer
  ld (op1),a    ;set op1 with program object pointer

; now find first program
progup:
  bcall(_findalphaup);find next program up

progselectlp:
  ld hl,4*256+4;THIS is the display routine. I leave it up to you...
  ld (currow),hl      ;but here is the simplist one.
  bcall(_eraseEOL);erase last prog name. (the previous program's ...
                      ;name may be longer than the new one)

  ld hl,op1+1         ;do not show ascii char for 05 or 06
  call _dispS         ;your display routine (bcall(_puts)...
                        
 
progselectlp2:
  call _KeyPause;your key retrivel routine
  cp skLeft;put the key you want for the 'next' key here
  jr z,progdown
  cp skRight;your 'previous' key here
  jr z,progup
  cp skEnter          ;your 'select prog here'
  jr z,chkselectprog
  cp skClear          ;your 'quit' or 'back' key here
  bjumpz(_JForceCmdNochar);use 'ret' if this is for an asm program
  
  jr progselectlp2    ;loop back

progdown:
  bcall(_findalphadn) ;find 'previous' program
  jr progselectlp     ;go to disp routine than to key loop

chkselectprog:
;now that the user has selcetd his/her program...
;do All your checks here. TI disigned there routine very well...
;you can bcall(_chkfindsym) right now if you what to.


Last edited by Guest on 01 Jul 2004 02:27:18 pm; edited 1 time in total
Back to top
sic


Advanced Newbie


Joined: 28 Jul 2003
Posts: 62

Posted: 02 Jul 2004 04:04:31 pm    Post subject:

Sir Robin wrote:
I'm not sure if that will work: it only edits the program copy made when the program is run, not the program itself.

It works. I am the author of Phantom Star. By default, when MirageOS runs an assembly program, it moves (not copies) the entire program to 9d95h. When the program exits, MirageOS will restore the program using the data at 9d95h. Therefore, if you write values back to your program, they will be changed the next time your program is executed. This is what most people call "write-back", and ION does the same thing.

However, if you are saying that you in a shell-less program you need to manually write back to the original program, then you are entirely correct. IIRC, MirageOS has an option that disables write-back if the program is archived.


Last edited by Guest on 02 Jul 2004 04:07:33 pm; edited 1 time in total
Back to top
DarkerLine
ceci n'est pas une |


Super Elite (Last Title)


Joined: 04 Nov 2003
Posts: 8328

Posted: 02 Jul 2004 05:36:42 pm    Post subject:

Ok, thanks for clarifying that.


EDIT by Adm.Wiggin:
I am going to leave this stuff in here, so as to clarify for anyone who misunderstands, as Sir Robin did. If any of you object to this, please PM me, and we'll talk.


Last edited by Guest on 09 Dec 2004 06:34:52 pm; edited 1 time in total
Back to top
MissingIntellect


Member


Joined: 01 Jun 2004
Posts: 227

Posted: 09 Dec 2004 10:27:47 am    Post subject:

About time to resurrect this topic... Laughing


Code:
;Name: BatteryStatus
;Description: Returns if the batteries are good, or low and need changing.
;Inputs: None
;Outputs: Non-Zero = Good Batteries
          Zero = Batteries Low
;Destroys: A

GetBatteryStatus:
    in a, (2)
    and 01h
    ret


Yes, I know there are other ways to get the battery status, but in my opinion this is the best, because it polls the hardware directly, so it's not dependent on the OS version and such.


Code:
;Name: DirectInput
;Inputs: A = Key Group
;Outputs: A = Key Code; Zero If None
;Destroys: A, B

DirectInput:
    ld b,a
    ld a,$ff ;Reset the keypad
    out (1),a
    ld a,b
    out (1),a
    in a,(1)
    ret


Last edited by Guest on 09 Dec 2004 10:30:57 am; edited 1 time in total
Back to top
Adm.Wiggin
aka Tianon


Know-It-All


Joined: 02 Jun 2003
Posts: 1874

Posted: 18 Apr 2005 05:15:37 pm    Post subject:

Boundry Check (A different, perhaps better, way)

Code:
; Your box coords (will not work with 0, keep x1 < x2, and y1 < y2 [duh])
#define x1 10
#define y1 10
#define x2 20
#define y2 30

check:
; a = x
; b = y
; returns c flag set if good
; returns c flag reset if no good (nc)
;  destorys af (quite obvious if one knows any z80 at all)
   cp x1
   jr c,nogood
   cp x2+1
   jr nc,nogood
   ld a,b
   cp y1
   jr c,nogood
   cp y2+1
   jr nc,nogood
 ;if it gets here, it's in the box!   Yay!  Hooray!  Peoples rejoice!
 ; as a side effect of the last operation, the carry flag is already set.
   ret
nogood:
   or a;to reset the carry flag
   ret
Enjoy? Obviously, labels can be renamed. (thought it was time to attempt another ressurection of this topic Laughing)
Please PM me if any of this is incorrect or improper, and I will work on a fix right away!

Remember the rules!


Last edited by Guest on 18 Apr 2005 05:17:32 pm; edited 1 time in total
Back to top
D-Tal


Newbie


Joined: 23 Mar 2006
Posts: 7

Posted: 27 Mar 2006 10:40:10 am    Post subject:

Here's one that takes the average of two 8 bit registers (one being a) and rounds the result to an integer (stored in a). The cool part is that it doesn't use any registers other than the two you are adding.

ld a, num
ld b, num
add a,b
res 0, a
jr nc (label)
set 0, a
label:
rrca

I'm hoping that someone will use this efficient routine to mix two 8 bit audio sources in realtime, so as to make a small oncalc sequencer. That would be cool.


Typo fixed.


Last edited by Guest on 27 Mar 2006 12:32:27 pm; edited 1 time in total
Back to top
CoBB


Active Member


Joined: 30 Jun 2003
Posts: 720

Posted: 27 Mar 2006 11:05:23 am    Post subject:

[quote name='D-Tal' date='Mar 27 2006, 04:21 PM']add a,b
res 0, a
jr nc, label ; corrected syntax...
set 0, a
label:
rrca[/quote]
Why not just add a,b \ rra?
Back to top
leofox
INF student


Super Elite (Last Title)


Joined: 11 Apr 2004
Posts: 3562

Posted: 27 Mar 2006 11:06:58 am    Post subject:

Probably because he wants to round up if the last bit is set. Although i must admit i was thinking of your way too, i dont think rounding matters that much.

edit: oh, this is post nr 3000! yayness!


Last edited by Guest on 27 Mar 2006 02:57:40 pm; edited 1 time in total
Back to top
CoBB


Active Member


Joined: 30 Jun 2003
Posts: 720

Posted: 27 Mar 2006 12:26:14 pm    Post subject:

He doesn't round, since the first thing he does is resetting the lowest bit...
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    » Goto page 1, 2, 3, 4, 5  Next
» View previous topic :: View next topic  
Page 1 of 5 » All times are UTC - 5 Hours

 

Advertisement