#asm TRUE EQU 1 FALSE EQU 0 ORG 100H ; ; TAKE COMMAND BUFFER AND BUILD POINTER LIST ; This first bit is taken from Mike Bernson's Small-C ; in the CUG library.(+ Minor Z80 mods) ccinit: LD HL,(6) ;Point to high memory and use DEC HL ;it to get suitable value for SP LD SP,HL LD HL,80H ;Save command line LD DE,ccmdbuf LD BC,50H ;Assumed max line length LDIR LD HL,ccmdbuf LD E,(HL) LD D,0 ADD HL,DE INC HL LD (HL),0 LD DE,cchptr LD HL,ccmdbuf LD BC,1 ccinit2: INC HL LD A,(HL) OR A JP Z,ccinit4 CP ' ' JP Z,ccinit2 LD A,L LD (DE),A LD A,H INC DE LD (DE),A INC DE INC C ccinit3: INC HL LD A,(HL) OR A JP Z,ccinit4 CP ' ' JP NZ,ccinit3 LD (HL),0 JP ccinit2 ccinit4: LD HL,cchptr-2 PUSH BC ;argc PUSH HL ;argv CALL main JP 0 ccmdbuf: DEFS 50H ;Memory to which command line is moved DEFW ccNULL cchptr: DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL DEFW ccNULL,ccNULL,ccNULL,ccNULL,ccNULL ccNULL: DEFB 'NONAME',0 ; ****** 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