#asm ; Stand alone Small C library ; TRUE EQU 1 FALSE EQU 0 ORG 100H ;Set to suit requirements ccinit: LD SP,9000H :Set SP as required by system JP main ;Go and do program ; ; ****** ESSENTIAL RUN-TIME ROUTINES ******* ; ; Based on routines by R.Cain in DDJ no.48 ; ; Fetch a single byte from (HL) and sign extend into HL ccgchar: LD A,(HL) ; Put A into HL and sign extend through H ccsxt: LD L,A RLCA SBC A,A LD H,A RET ;Fetch a 16 bit integer from (HL) to HL ccgint: LD A,(HL) INC HL LD H,(HL) LD L,A RET ;Move a single byte from HL to (DE) ccpchar: LD A,L LD (DE),A RET ; Move a 16 bit integer in HL to (DE) ccpint: LD A,L LD (DE),A INC DE LD A,H LD (DE),A RET ; Inclusive or HL and DE to HL ccor: LD A,L OR E LD L,A LD A,H OR D LD H,A RET ; Exclusive or HL and DE into HL ccxor: LD A,L XOR E LD L,A LD A,H XOR D LD H,A RET ; And HL and DE into HL ccand: LD A,L AND E LD L,A LD A,H AND D LD H,A RET ; Compare routines. HL tested against DE ; HL set to 1 if condition true or 0 if false. ; ;HL=DE? cceq: CALL cccmp RET Z DEC HL RET ;HL!=DE? ccne: CALL cccmp RET NZ DEC HL RET ;DE>HL? (signed) ccgt: EX DE,HL JP cclt ; DE<=HL? (signed) ccle: CALL cccmp RET Z RET C DEC HL RET ; DE>=HL? (signed) ccge: CALL cccmp RET NC DEC HL RET ; DE=HL? (unsigned) ccuge: CALL ccucmp RET NC DEC HL RET ; DEHL? (unsigned) ccugt: EX DE,HL JP ccult ; DE<=HL? (unsigned) ccule: CALL ccucmp RET Z RET C DEC HL RET ; Unsigned compare. C set if DE