ORCALib/stdlib.asm

1 line
27 KiB
NASM
Raw Normal View History

2017-10-02 00:00:58 +00:00
keep obj/stdlib mcopy stdlib.macros case on **************************************************************** * * StdDef - Standard Definitions * * This code implements the tables and subroutines needed to * support the standard C library STDDEF. * * December 1988 * Mike Westerfield * * Copyright 1988 * Byte Works, Inc. * * Note: Portions of this library appear in SysFloat * **************************************************************** * StdDef start dummy segment copy equates.asm end **************************************************************** * * void abort() * * Stop the program. * **************************************************************** * abort start ph2 #SIGABRT jsl raise lda #-1 jmp ~QUIT end **************************************************************** * * int abs(int i) * * Return the absolute value of i. * * Inputs: * i - argument * * Outputs: * Returns abs(i). * **************************************************************** * abs start i equ 4 position of argument on stack lda i,S A := i bpl lb1 if A < 0 then eor #$FFFF A := -A inc A lb1 tay return A lda 2,S sta 4,S pla sta 1,S tya rtl end **************************************************************** * * int atexit(func) * void (*func)(); * * This function is used to build a list of functions that will * be called as part of the exit processing. * * Inputs: * func - address of the function to call on exit * * Outputs: * Returns 0 if successful, -1 if not. * **************************************************************** * atexit start ptr equ 1 work pointer rval equ 5 return value csubroutine (4:func),6 lda #-1 assume we will fail sta rval assume we will fail dec4 func we need the addr-1, not the addr ph4 #8 get space for the record jsl malloc stx ptr+2 sta ptr ora ptr+2 quit now if we failed beq lb1 ldy #2 place the record in the exit list lda >~EXITLIST sta [ptr] lda >~EXITLIST+2 sta [ptr],Y lda ptr sta >~EXITLIST lda ptr+2 sta >~EXITLIST+2 iny place the function address in the record iny lda func sta [ptr],Y iny iny lda func+2 sta [ptr],Y inc rval success... lb1 creturn 2:rval end **************************************************************** * * atof - convert a string to a float * * Inputs: * str - pointer to the string * * Outputs: * X-A - pointer to converted number * **************************************************************** * atof start ph4 #0 no pointer returned lda 10,S pass the string addr on pha lda 10,S pha jsl strtod convert the string tay fix the stack lda 2,S sta 6,S pla sta 3,S pla tya rtl end **************************************************************** * * atoi - convert a string to an int * atol - convert a string to a long * * Inputs: * str - pointer to the string * * Outputs: * X-A - converted number * **************************************************************** * a