Omnimaga

Calculator Community => TI Calculators => ASM => Topic started by: Xeda112358 on January 04, 2012, 11:58:17 pm

Title: Useful Routines
Post by: Xeda112358 on January 04, 2012, 11:58:17 pm
I figured that I would start a topic like this here. These are links to a bunch of routines that I find useful and I think other will find useful
ChkFindVar (http://pastebin.com/eZA3prQW) is like ChkFindSym for Program, Protected Program, Appvar, Temporary Program, Group.
SearchVarBC (http://pastebin.com/vVLEsnw7) is a routine (with several others included) for searching for the other program types.
A_Times_DE (http://pastebin.com/xqfE2WGc) This is a non-standard routine that is 25 bytes and faster than DE_Times_A.
DE_Times_A (http://pastebin.com/RJfDSKq9) This is a fast, straightfoward, standard DE_Times_A
C_Div_D (http://pastebin.com/sBz0d6ha)
C_Times_D (http://pastebin.com/maBCTr2B)
DE_Times_BC (http://pastebin.com/d2i3zBV4)
DEHL_Div_C (http://pastebin.com/6Yfh03Z7)
DEHL_Mul_32Stack (no SMC) (http://pastebin.com/5qFAq7cz) this is for Apps. This multiplies DEHL by the last two entries on the stack and returns the 64-bit result.
DEHL_Mul_32Stack (SMC) (http://pastebin.com/FBpEHiWM) this gets a decent speed boost by using SMC. It does the same thing.
DEHL_Mul_A (http://pastebin.com/gMf2YYFd) this uses shadow registers HLDE. I need to rewrite this
GCDHL_BC (http://pastebin.com/iPDfERX0) computes the Greatest Common Divisor
HL_Div_BC (http://pastebin.com/VgVL8g4K) this can probably be optimised
HL_Div_C (http://pastebin.com/X6J8imsX)
HLDE_Div_C (http://pastebin.com/99vdi6bG)
ncrHL_DE (http://pastebin.com/2btfQDGn) this computes "n choose r" and it uses shadow registers
RoundHL_Div_C (http://pastebin.com/3LGzAkcp) returns the rounded value of HL/C
RoundSqrtE (http://pastebin.com/apXxYES2) returns the rounded square root of E
SqrtE (http://pastebin.com/KRfuNU6f)
SqrtHL (http://pastebin.com/yMdfuqWx)
PixelPlot (1) (http://pastebin.com/6pKK5y0F) is a fast pixel plotting code that uses SMC and will draw to arbitrary buffers. I usually use a different version of this.
LineSearch (http://pastebin.com/aQk5pQN3) will search a var for a line and return the location and size. This will not search beyond the given limit.
ConvRStr (http://pastebin.com/QYZeh3vp) will convert a string of numbers to a 16-bit value
Is_2_Byte (http://pastebin.com/Y4sdjN9h) checks if A is the start byte of a 2-byte token
TokensToASCII (http://pastebin.com/Nptk6pQq) converts a token string to ASCII
IncHLMem1 (http://pastebin.com/x1dd1xsX) This is an optmised routine to increment HL and port 6 as necessary
TileMap1 (http://pastebin.com/nhY1h6Ua) This draws a tilemap. Uses DrawSpriteXxY.
DrawSpriteXxY (http://pastebin.com/WUKpeKbH) This draws a tile

Pastebin won't let me paste anymore for a while, but I have a bunch more waiting in reserve :)

EDIT: As a note, these are all codes I wrote :)
Title: Re: Useful Routines
Post by: chickendude on January 05, 2012, 05:44:27 am
I think pretty much everyone knows about z80 bits, but:
http://baze.au.com/misc/z80bits.html
Also, there's a nice French site which talks about z80 multiplication/division:
http://projets.infos.free.fr/CPC/CPC_MultiplicationsDivisions.php5

Later i can maybe upload my tilemap routine or maybe my number-to-string routine. :)
EDIT: Here's the number-to-string routine i wrote:
http://pastebin.com/sudK27tC (anti-copyright)
And here's a simplified version of the 16x16 tilemap routine i wrote (though i was using a 7(wide)x5(tall) buffer):
http://pastebin.com/hxtH1Vqu (anti-copyright)
It's a bit smaller than the one you posted and maybe a bit faster as i incorporated the sprite drawing directly into the routine, not using a separate sprite routine, but i haven't checked, so i dunno. I'm really bad at multiplication routines, i usually do things by multiples of two or use a simple routine similar to what everyone else uses. I should look into how z80 math works a bit more...
Title: Re: Useful Routines
Post by: Xeda112358 on January 05, 2012, 10:51:48 am
Nice, chickendude! Here is the number to string routine I use in Grammer to display numbers.
Spoiler For Spoiler:
It converts HL to any base from 2 to 36 and uses the OS ASCII for the numbers and letters (which match the tokens). This can be easily modified to handle 32-bit input, too:
;=================================================================
ConvNumBase:
;=================================================================
;Inputs:
;     C is the base to convert to
;     HL is the number to convert
;Output:
;     A is the number of digits
;     BC is the number of digits
;     DE is 0
;     HL points to the number string
;Notes:
;     This converts HL to a zero terminated string stored in OP4
;     and possibly a few bytes of OP3.
;=================================================================
        xor a
        ld de,84A3h
        ld (de),a
        dec de
          call HL_Div_C
          cp 10
          jr c,$+4
            add a,7
          add a,48
          ld (de),a
          dec de
          ld a,h
          or l
          jr nz,$-15
        ld a,$A2
        sub e
        ld c,a
        inc de
        ex de,hl
        ret
And as for the tilemap routine, there are tons of different ways. The one I provided handles 8x8 tiles and tilemaps of any size greater than or equal to the size of the screen as well as 5 different drawing methods.
Title: Re: Useful Routines
Post by: chickendude on January 05, 2012, 12:56:41 pm
You're right, i love looking at how people go about their tilemappers. Thanks for sharing!