From 294715c0420d3d526ccd36212ce958e94b8d5f3c Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Thu, 16 Nov 2017 23:01:38 +0000 Subject: [PATCH] z80: more bits --- Applications/SmallC/Z80/lib/TODO | 4 ---- Applications/SmallC/Z80/lib/_bzero.s | 27 ++++++++++++++++++++++++ Applications/SmallC/Z80/lib/_isalnum.s | 4 ++-- Applications/SmallC/Z80/lib/_isalpha.s | 4 ++-- Applications/SmallC/Z80/lib/_isascii.s | 4 ++-- Applications/SmallC/Z80/lib/_isblank.s | 4 ++-- Applications/SmallC/Z80/lib/_iscntrl.s | 4 ++-- Applications/SmallC/Z80/lib/_isdigit.s | 4 ++-- Applications/SmallC/Z80/lib/_isgraph.s | 4 ++-- Applications/SmallC/Z80/lib/_islower.s | 4 ++-- Applications/SmallC/Z80/lib/_isprint.s | 4 ++-- Applications/SmallC/Z80/lib/_isspace.s | 4 ++-- Applications/SmallC/Z80/lib/_isupper.s | 4 ++-- Applications/SmallC/Z80/lib/_isxdigit.s | 4 ++-- Applications/SmallC/Z80/lib/_memset.s | 2 ++ Applications/SmallC/Z80/lib/_strcat.s | 4 ++-- Applications/SmallC/Z80/lib/_strchr.s | 8 +++---- Applications/SmallC/Z80/lib/_strcmp.s | 3 ++- Applications/SmallC/Z80/lib/_strcpy.s | 4 ++-- Applications/SmallC/Z80/lib/_strcspn.s | 4 ++-- Applications/SmallC/Z80/lib/_strlen.s | 2 ++ Applications/SmallC/Z80/lib/_strncat.s | 2 ++ Applications/SmallC/Z80/lib/_strrchr.s | 9 +++++--- Applications/SmallC/Z80/lib/_swab.s | 28 +++++++++++++++++++++++++ 24 files changed, 103 insertions(+), 42 deletions(-) create mode 100644 Applications/SmallC/Z80/lib/_bzero.s create mode 100644 Applications/SmallC/Z80/lib/_swab.s diff --git a/Applications/SmallC/Z80/lib/TODO b/Applications/SmallC/Z80/lib/TODO index 689c231b..5b0d67b1 100644 --- a/Applications/SmallC/Z80/lib/TODO +++ b/Applications/SmallC/Z80/lib/TODO @@ -4,14 +4,10 @@ _strncmp _strncasecmp _strpbrk _strspn -_strstr _strxfrm -_memcpy _memccpy _memchr _memmove -_memset _bcopy _bzero -_bswap _ispunct diff --git a/Applications/SmallC/Z80/lib/_bzero.s b/Applications/SmallC/Z80/lib/_bzero.s new file mode 100644 index 00000000..9770c424 --- /dev/null +++ b/Applications/SmallC/Z80/lib/_bzero.s @@ -0,0 +1,27 @@ + .code + .export _bzero + +_bzero: pop af + pop hl + pop de + push de + push hl + push af + push bc + ld c,e + ld b,d + ld a,b + or c + jr z, _bzero_1 + ld (hl),0 + dec bc + ld a,b + or c + jr z,_bzero_1 + ld e,l + ld d,h + inc de + ldir +_bzero_1: + pop bc + ret \ No newline at end of file diff --git a/Applications/SmallC/Z80/lib/_isalnum.s b/Applications/SmallC/Z80/lib/_isalnum.s index ccc70ff5..94c581d6 100644 --- a/Applications/SmallC/Z80/lib/_isalnum.s +++ b/Applications/SmallC/Z80/lib/_isalnum.s @@ -1,10 +1,10 @@ .code .export _isalnum -_isalnum: pop bc +_isalnum: pop de pop hl push hl - push bc + push de ld a,l cp '9' jr nc, isalnum1 diff --git a/Applications/SmallC/Z80/lib/_isalpha.s b/Applications/SmallC/Z80/lib/_isalpha.s index afe0dd83..cc78c8b7 100644 --- a/Applications/SmallC/Z80/lib/_isalpha.s +++ b/Applications/SmallC/Z80/lib/_isalpha.s @@ -1,9 +1,9 @@ .code .export _isalpha -_isalpha: pop bc +_isalpha: pop de pop hl push hl - push bc + push de ld a,l cp 'a' jr c, isalpha1 diff --git a/Applications/SmallC/Z80/lib/_isascii.s b/Applications/SmallC/Z80/lib/_isascii.s index 8f1142b7..6b598c7c 100644 --- a/Applications/SmallC/Z80/lib/_isascii.s +++ b/Applications/SmallC/Z80/lib/_isascii.s @@ -1,9 +1,9 @@ .code .export _isascii -_isascii: pop bc +_isascii: pop de pop hl push hl - push bc + push de ld a,l cp 32 jr c, ret0 diff --git a/Applications/SmallC/Z80/lib/_isblank.s b/Applications/SmallC/Z80/lib/_isblank.s index 134d9566..5d6d7402 100644 --- a/Applications/SmallC/Z80/lib/_isblank.s +++ b/Applications/SmallC/Z80/lib/_isblank.s @@ -1,9 +1,9 @@ .code .export _isblank -_isblank: pop bc +_isblank: pop de pop hl push hl - push bc + push de ld a,l ; Space cp 32 diff --git a/Applications/SmallC/Z80/lib/_iscntrl.s b/Applications/SmallC/Z80/lib/_iscntrl.s index 00c93c55..f5363474 100644 --- a/Applications/SmallC/Z80/lib/_iscntrl.s +++ b/Applications/SmallC/Z80/lib/_iscntrl.s @@ -1,9 +1,9 @@ .code .export _iscntrl -_iscntrl: pop bc +_iscntrl: pop de pop hl push hl - push bc + push de ld a,l ; Space cp 32 diff --git a/Applications/SmallC/Z80/lib/_isdigit.s b/Applications/SmallC/Z80/lib/_isdigit.s index 283418ef..018efad8 100644 --- a/Applications/SmallC/Z80/lib/_isdigit.s +++ b/Applications/SmallC/Z80/lib/_isdigit.s @@ -1,9 +1,9 @@ .code .export _isdigit -_isdigit: pop bc +_isdigit: pop de pop hl push hl - push bc + push de ld a,l cp '0' jr c, ret0 diff --git a/Applications/SmallC/Z80/lib/_isgraph.s b/Applications/SmallC/Z80/lib/_isgraph.s index e1dedbd4..18436a9a 100644 --- a/Applications/SmallC/Z80/lib/_isgraph.s +++ b/Applications/SmallC/Z80/lib/_isgraph.s @@ -1,9 +1,9 @@ .code .export _isgraph -_isgraph: pop bc +_isgraph: pop de pop hl push hl - push bc + push de ld a,l cp 33 jr c, ret0 diff --git a/Applications/SmallC/Z80/lib/_islower.s b/Applications/SmallC/Z80/lib/_islower.s index 8ff8dc94..7e1af273 100644 --- a/Applications/SmallC/Z80/lib/_islower.s +++ b/Applications/SmallC/Z80/lib/_islower.s @@ -1,9 +1,9 @@ .code .export _islower -_islower: pop bc +_islower: pop de pop hl push hl - push bc + push de ld a,l ; Space cp 'a' diff --git a/Applications/SmallC/Z80/lib/_isprint.s b/Applications/SmallC/Z80/lib/_isprint.s index c5a78f48..6d1b794c 100644 --- a/Applications/SmallC/Z80/lib/_isprint.s +++ b/Applications/SmallC/Z80/lib/_isprint.s @@ -1,9 +1,9 @@ .code .export _isprint -_isprint: pop bc +_isprint: pop de pop hl push hl - push bc + push de ld a,l cp 32 jr c, ret0 diff --git a/Applications/SmallC/Z80/lib/_isspace.s b/Applications/SmallC/Z80/lib/_isspace.s index ac0c6ac5..f95dd565 100644 --- a/Applications/SmallC/Z80/lib/_isspace.s +++ b/Applications/SmallC/Z80/lib/_isspace.s @@ -1,9 +1,9 @@ .code .export _isspace -_isspace: pop bc +_isspace: pop de pop hl push hl - push bc + push de ld a,l ; Space cp 32 diff --git a/Applications/SmallC/Z80/lib/_isupper.s b/Applications/SmallC/Z80/lib/_isupper.s index 810e0b38..86222661 100644 --- a/Applications/SmallC/Z80/lib/_isupper.s +++ b/Applications/SmallC/Z80/lib/_isupper.s @@ -1,9 +1,9 @@ .code .export _isupper -_isupper: pop bc +_isupper: pop de pop hl push hl - push bc + push de ld a,l ; Space cp 'A' diff --git a/Applications/SmallC/Z80/lib/_isxdigit.s b/Applications/SmallC/Z80/lib/_isxdigit.s index aaaecdd7..71df5de5 100644 --- a/Applications/SmallC/Z80/lib/_isxdigit.s +++ b/Applications/SmallC/Z80/lib/_isxdigit.s @@ -1,9 +1,9 @@ .code .export _isxdigit -_isxdigit: pop bc +_isxdigit: pop de pop hl push hl - push bc + push de ld a,l ; Space cp '0' diff --git a/Applications/SmallC/Z80/lib/_memset.s b/Applications/SmallC/Z80/lib/_memset.s index 4bc85d9f..be5dec45 100644 --- a/Applications/SmallC/Z80/lib/_memset.s +++ b/Applications/SmallC/Z80/lib/_memset.s @@ -2,6 +2,7 @@ .export _memset _memset: push ix + push bc ld ix,0 add ix,sp ld h,(ix+4) @@ -23,5 +24,6 @@ _memset: push ix ldir _memset_none: ld l,(ix+4) ld h,(ix+5) + pop bc pop ix ret diff --git a/Applications/SmallC/Z80/lib/_strcat.s b/Applications/SmallC/Z80/lib/_strcat.s index d06e3742..65a45a94 100644 --- a/Applications/SmallC/Z80/lib/_strcat.s +++ b/Applications/SmallC/Z80/lib/_strcat.s @@ -1,12 +1,12 @@ .code .export _strcat -_strcat: pop bc ;ret +_strcat: pop af ;ret pop de ;dest pop hl ;src push hl push de - push bc + push af push de ; for return code _strcat_1: ld a,(de) or a diff --git a/Applications/SmallC/Z80/lib/_strchr.s b/Applications/SmallC/Z80/lib/_strchr.s index 91f73405..882acbec 100644 --- a/Applications/SmallC/Z80/lib/_strchr.s +++ b/Applications/SmallC/Z80/lib/_strchr.s @@ -2,12 +2,12 @@ .export _strchr _strchr: - pop de ; char + pop af pop hl ; ptr - pop bc - push bc - push hl + pop de ; char push de + push hl + push af _strchr_1: ld a,(hl) ; "The terminting nul is considered part cp e ; of the string" ret z diff --git a/Applications/SmallC/Z80/lib/_strcmp.s b/Applications/SmallC/Z80/lib/_strcmp.s index e067cfea..4630b050 100644 --- a/Applications/SmallC/Z80/lib/_strcmp.s +++ b/Applications/SmallC/Z80/lib/_strcmp.s @@ -2,11 +2,12 @@ .export _strcmp _strcmp: - pop bc + pop af pop de pop hl push hl push de + push af _strcmp_1: ld a,(de) diff --git a/Applications/SmallC/Z80/lib/_strcpy.s b/Applications/SmallC/Z80/lib/_strcpy.s index 8317c6d8..13a6dc63 100644 --- a/Applications/SmallC/Z80/lib/_strcpy.s +++ b/Applications/SmallC/Z80/lib/_strcpy.s @@ -1,12 +1,12 @@ .code .export _strcpy -_strcpy: pop bc ;ret +_strcpy: pop af ;ret pop de ;dest pop hl ;src push hl push de - push bc + push af push de ; for return code _strcpy_1: ld a,(hl) ld (de),a diff --git a/Applications/SmallC/Z80/lib/_strcspn.s b/Applications/SmallC/Z80/lib/_strcspn.s index 17f73b69..b394a267 100644 --- a/Applications/SmallC/Z80/lib/_strcspn.s +++ b/Applications/SmallC/Z80/lib/_strcspn.s @@ -2,12 +2,12 @@ .export _strcspn _strcspn: - pop bc + pop af pop hl ; string pop de ; match push de push hl - push bc + push af _strcspn_1: ld a,(hl) diff --git a/Applications/SmallC/Z80/lib/_strlen.s b/Applications/SmallC/Z80/lib/_strlen.s index a45546af..da0def0e 100644 --- a/Applications/SmallC/Z80/lib/_strlen.s +++ b/Applications/SmallC/Z80/lib/_strlen.s @@ -6,6 +6,7 @@ _strlen: pop de push de push hl + push bc xor a ld b,a ld c,a @@ -14,4 +15,5 @@ _strlen: cpir dec hl sbc hl,de + pop bc ret diff --git a/Applications/SmallC/Z80/lib/_strncat.s b/Applications/SmallC/Z80/lib/_strncat.s index 3377224f..051216a4 100644 --- a/Applications/SmallC/Z80/lib/_strncat.s +++ b/Applications/SmallC/Z80/lib/_strncat.s @@ -3,6 +3,7 @@ _strncat: push ix + push bc ld ix,#0 add ix,sp ld l,(ix+4) @@ -32,6 +33,7 @@ _strncat_1: jr _strncat_1 _strncat_2: ld l,(ix+4) ld h,(ix+5) + pop bc pop ix ret ; Copy \0 until limit diff --git a/Applications/SmallC/Z80/lib/_strrchr.s b/Applications/SmallC/Z80/lib/_strrchr.s index c707aab9..90b77714 100644 --- a/Applications/SmallC/Z80/lib/_strrchr.s +++ b/Applications/SmallC/Z80/lib/_strrchr.s @@ -2,12 +2,14 @@ .export _strrchr _strrchr: - pop de ; char + pop af pop hl ; ptr - pop bc - push bc + pop de ; char + push de push hl + push af push de + push bc ld bc, 0 _strrchr_1: ld a,(hl) or a @@ -19,6 +21,7 @@ _strrchr_1: ld a,(hl) _strrchr_2: ld h,b ld l,c + pop bc ret _strrchr_3: ld b,h diff --git a/Applications/SmallC/Z80/lib/_swab.s b/Applications/SmallC/Z80/lib/_swab.s new file mode 100644 index 00000000..7e53a3ce --- /dev/null +++ b/Applications/SmallC/Z80/lib/_swab.s @@ -0,0 +1,28 @@ + .code + .export _swab + +_swab: pop bc + pop hl + pop de + push de + push hl + push bc + push bc +_swab1 + bit 7,d + ret nz + ld a,d + or e + ret z + ld a,(hl) + inc hl + ld c,(hl) + ld (hl),a + dec hl + ld (hl),c + inc hl + inc hl + dec de + dec de + jr _swab1 + \ No newline at end of file -- 2.34.1