cc: z80 helpers
authorAlan Cox <alan@linux.intel.com>
Thu, 16 Nov 2017 18:55:10 +0000 (18:55 +0000)
committerAlan Cox <alan@linux.intel.com>
Thu, 16 Nov 2017 18:55:10 +0000 (18:55 +0000)
First drafts

25 files changed:
Applications/SmallC/Z80/lib/_isalnum.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_isalpha.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_isascii.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_isblank.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_iscntrl.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_isdigit.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_isgraph.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_islower.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_isprint.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_ispunct.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_isspace.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_isupper.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_isxdigit.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_memcpy.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_memset.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strcat.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strchr.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strcmp.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strcpy.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strcspn.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strlen.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strncat.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strncpy.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strrchr.s [new file with mode: 0644]
Applications/SmallC/Z80/lib/_strspn.s [new file with mode: 0644]

diff --git a/Applications/SmallC/Z80/lib/_isalnum.s b/Applications/SmallC/Z80/lib/_isalnum.s
new file mode 100644 (file)
index 0000000..ccc70ff
--- /dev/null
@@ -0,0 +1,25 @@
+               .code
+               .export _isalnum
+
+_isalnum:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               cp '9'
+               jr nc, isalnum1
+               cp '0'
+               jr c, ret0
+ret1:          ld hl,1
+               ret
+isalnum1:
+               cp 'a'
+               jr c, isalnum2
+               sub 32
+isalnum2:
+               cp 'A'
+               jr c, ret0
+               cp 'Z'+1
+               jr c, ret1
+ret0:          ld hl,0
+               ret
diff --git a/Applications/SmallC/Z80/lib/_isalpha.s b/Applications/SmallC/Z80/lib/_isalpha.s
new file mode 100644 (file)
index 0000000..afe0dd8
--- /dev/null
@@ -0,0 +1,20 @@
+               .code
+               .export _isalpha
+_isalpha:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               cp 'a'
+               jr c, isalpha1
+               sub 32
+isalpha1:
+               cp 'A'
+               jr c, ret0
+               cp 'Z'+1
+               jr c, ret1
+ret0:          ld hl,0
+               ret
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
diff --git a/Applications/SmallC/Z80/lib/_isascii.s b/Applications/SmallC/Z80/lib/_isascii.s
new file mode 100644 (file)
index 0000000..8f1142b
--- /dev/null
@@ -0,0 +1,16 @@
+               .code
+               .export _isascii
+_isascii:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               cp 32
+               jr c, ret0
+               rlca
+               jr c, ret0
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
+ret0:          ld hl,0
+               ret
diff --git a/Applications/SmallC/Z80/lib/_isblank.s b/Applications/SmallC/Z80/lib/_isblank.s
new file mode 100644 (file)
index 0000000..134d956
--- /dev/null
@@ -0,0 +1,17 @@
+               .code
+               .export _isblank
+_isblank:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               ; Space
+               cp 32
+               jr z, ret1
+               cp 9
+               jr z, ret1
+ret0:          ld hl,0
+               ret
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
diff --git a/Applications/SmallC/Z80/lib/_iscntrl.s b/Applications/SmallC/Z80/lib/_iscntrl.s
new file mode 100644 (file)
index 0000000..00c93c5
--- /dev/null
@@ -0,0 +1,17 @@
+               .code
+               .export _iscntrl
+_iscntrl:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               ; Space
+               cp 32
+               jr c, ret1
+               cp 127
+               jr z, ret1
+ret0:          ld hl,0
+               ret
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
diff --git a/Applications/SmallC/Z80/lib/_isdigit.s b/Applications/SmallC/Z80/lib/_isdigit.s
new file mode 100644 (file)
index 0000000..283418e
--- /dev/null
@@ -0,0 +1,16 @@
+               .code
+               .export _isdigit
+_isdigit:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               cp '0'
+               jr c, ret0
+               cp '9'+1
+               jr c, ret1
+ret0:          ld hl,0
+               ret
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
diff --git a/Applications/SmallC/Z80/lib/_isgraph.s b/Applications/SmallC/Z80/lib/_isgraph.s
new file mode 100644 (file)
index 0000000..e1dedbd
--- /dev/null
@@ -0,0 +1,16 @@
+               .code
+               .export _isgraph
+_isgraph:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               cp 33
+               jr c, ret0
+               cp 127
+               jr nc, ret1
+ret0:          ld hl,0
+               ret
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
diff --git a/Applications/SmallC/Z80/lib/_islower.s b/Applications/SmallC/Z80/lib/_islower.s
new file mode 100644 (file)
index 0000000..8ff8dc9
--- /dev/null
@@ -0,0 +1,17 @@
+               .code
+               .export _islower
+_islower:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               ; Space
+               cp 'a'
+               jr c, ret0
+               cp 'z'+1
+               jr c, ret1
+ret0:          ld hl,0
+               ret
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
diff --git a/Applications/SmallC/Z80/lib/_isprint.s b/Applications/SmallC/Z80/lib/_isprint.s
new file mode 100644 (file)
index 0000000..c5a78f4
--- /dev/null
@@ -0,0 +1,16 @@
+               .code
+               .export _isprint
+_isprint:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               cp 32
+               jr c, ret0
+               cp 128
+               jr c, ret1
+ret0:          ld hl,0
+               ret
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
diff --git a/Applications/SmallC/Z80/lib/_ispunct.s b/Applications/SmallC/Z80/lib/_ispunct.s
new file mode 100644 (file)
index 0000000..969bf85
--- /dev/null
@@ -0,0 +1 @@
+ispunct.s
\ No newline at end of file
diff --git a/Applications/SmallC/Z80/lib/_isspace.s b/Applications/SmallC/Z80/lib/_isspace.s
new file mode 100644 (file)
index 0000000..ac0c6ac
--- /dev/null
@@ -0,0 +1,20 @@
+               .code
+               .export _isspace
+_isspace:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               ; Space
+               cp 32
+               jr z, ret1
+               ; 9-13
+               cp 9
+               jr c, ret0
+               cp 13
+               jr nc, ret0
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
+ret0:          ld hl,0
+               ret
diff --git a/Applications/SmallC/Z80/lib/_isupper.s b/Applications/SmallC/Z80/lib/_isupper.s
new file mode 100644 (file)
index 0000000..810e0b3
--- /dev/null
@@ -0,0 +1,17 @@
+               .code
+               .export _isupper
+_isupper:      pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               ; Space
+               cp 'A'
+               jr c, ret0
+               cp 'Z'+1
+               jr c, ret1
+ret0:          ld hl,0
+               ret
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
diff --git a/Applications/SmallC/Z80/lib/_isxdigit.s b/Applications/SmallC/Z80/lib/_isxdigit.s
new file mode 100644 (file)
index 0000000..b3a6878
--- /dev/null
@@ -0,0 +1,28 @@
+               .code
+               .global _isxdigit
+_isxdigit:     pop bc
+               pop hl
+               push hl
+               push bc
+               ld a,l
+               ; Space
+               cp '0'
+               jr c, ret0
+               cp 'A'
+               jr nc,ascii1
+               cp 'a'
+               jr nc,ascii2
+               cp '9'+1
+               jr nc, ret0
+               jr ret1
+ascii1:                add 32
+ascii2:
+               cp 'a'
+               jr c, ret0
+               cp 'z'+1
+               jr c, ret1
+ret0:          ld hl,0
+               ret
+               ; No need to handle -1 specially
+ret1:          ld hl,1
+               ret
diff --git a/Applications/SmallC/Z80/lib/_memcpy.s b/Applications/SmallC/Z80/lib/_memcpy.s
new file mode 100644 (file)
index 0000000..e978126
--- /dev/null
@@ -0,0 +1,19 @@
+               .code
+               .export _memcpy
+
+_memcpy:       push ix
+               ld ix,#0
+               add ix,sp
+               ld e,4(ix)
+               ld d,5(ix)
+               ld l,6(ix)
+               ld h,7(ix)
+               ld c,8(ix)
+               ld b,9(ix)
+               ld a,b
+               or c
+               jr z, _memcpy_none
+               ldir
+_memcpy_none:  ld l,4(ix)
+               ld h,5(ix)
+               ret
diff --git a/Applications/SmallC/Z80/lib/_memset.s b/Applications/SmallC/Z80/lib/_memset.s
new file mode 100644 (file)
index 0000000..b1f4ac7
--- /dev/null
@@ -0,0 +1,26 @@
+               .code
+               .export _memset
+
+_memset:       push ix
+               ld ix,0
+               add ix,sp
+               ld h,4(ix)
+               ld l,5(ix)
+               ld e,6(ix)
+               ld c,8(ix)
+               ld b,9(ix)
+               ld a,b
+               or c
+               jr z, _memset_none
+               ld (hl),e
+               dec bc
+               ld a,b
+               or c
+               jr z,_memset_none
+               ld e,l
+               ld d,h
+               inc de
+               ldir
+_memset_none:  ld l,4(ix)
+               ld h,5(ix)
+               ret
diff --git a/Applications/SmallC/Z80/lib/_strcat.s b/Applications/SmallC/Z80/lib/_strcat.s
new file mode 100644 (file)
index 0000000..7764f38
--- /dev/null
@@ -0,0 +1,25 @@
+               .code
+               .export _strcat
+
+_strcat:       pop bc          ;ret
+               pop de          ;dest
+               pop hl          ;src
+               push hl
+               push de
+               push bc
+               push de         ; for return code
+_strcat_1:     ld a,(de)
+               or a
+               jr z,_strcat_2
+               inc de
+               jr _strcat_1
+_strcat_2:
+               ld a,(hl)
+               ld (de),a
+               or a
+               jr z _strcat_3
+               inc hl
+               inc de
+               jr _strcat_2
+strcat_3:      pop de
+               ret
diff --git a/Applications/SmallC/Z80/lib/_strchr.s b/Applications/SmallC/Z80/lib/_strchr.s
new file mode 100644 (file)
index 0000000..de206f1
--- /dev/null
@@ -0,0 +1,20 @@
+               .code
+               .export _strchr
+
+_strchr:
+               pop de          ; char
+               pop hl          ; ptr
+               pop bc
+               push bc
+               push hl
+               push de
+_strchr_1:     ld a,(hl)       ; "The terminting nul is considered part
+               cp e            ;  of the string"
+               ret z
+               or a
+               inc hl
+               jr nz,_strchr_1
+               ld hl,0
+               ret
+
+               
\ No newline at end of file
diff --git a/Applications/SmallC/Z80/lib/_strcmp.s b/Applications/SmallC/Z80/lib/_strcmp.s
new file mode 100644 (file)
index 0000000..4a666f4
--- /dev/null
@@ -0,0 +1,28 @@
+               .code
+               .export _strcmp
+
+_strcmp:
+               pop bc
+               pop de
+               pop hl
+               push hl
+               push de
+
+_strcmp_1:
+               ld a,(de)
+               cp (hl)
+               jr nz, strcmp_2
+               or a
+               jr z, strcmp_4
+               inc hl
+               inc de
+               jr _strcmp_1
+_strcmp_2:     jr c,_strcmp_3
+               ld hl,1
+               ret
+_strcmp_3:
+               ld hl,0xFFFF
+               ret
+_strcmp_4:
+               ld hl,0
+               ret
diff --git a/Applications/SmallC/Z80/lib/_strcpy.s b/Applications/SmallC/Z80/lib/_strcpy.s
new file mode 100644 (file)
index 0000000..e1ce611
--- /dev/null
@@ -0,0 +1,20 @@
+               .code
+               .export _strcpy
+
+_strcpy:       pop bc          ;ret
+               pop de          ;dest
+               pop hl          ;src
+               push hl
+               push de
+               push bc
+               push de         ; for return code
+_strcpy_1:     ld a,(hl)
+               ld (de),a
+               or a
+               jr z _strcpy_2
+               inc hl
+               inc de
+               jr _strcpy_1
+_strcpy_2:
+               pop hl
+               ret
diff --git a/Applications/SmallC/Z80/lib/_strcspn.s b/Applications/SmallC/Z80/lib/_strcspn.s
new file mode 100644 (file)
index 0000000..0b77ff0
--- /dev/null
@@ -0,0 +1,32 @@
+               .code
+               .export _strcspn
+
+_strcspn:
+               pop bc
+               pop hl          ;       string
+               pop de          ;       match
+               push de
+               push hl
+               push bc
+
+_strcspn_1:
+               ld a,(hl)
+               or a
+               jr z,_strcspn_4
+               ld c,a
+
+               push de
+_strcspn_2:
+               ld a,(de)
+               or a
+               jr z, _strcspn_3
+               cp c
+               ret z           ;       Matched HL ponts to right spot
+               inc de
+               jr _strcspn_2
+_strcpsn_3:    pop de
+               inc hl
+               jr _strcspn_1
+_strcspn_4:    ld h,a          ;       A always 0 here
+               ld l,a
+               ret
diff --git a/Applications/SmallC/Z80/lib/_strlen.s b/Applications/SmallC/Z80/lib/_strlen.s
new file mode 100644 (file)
index 0000000..a45546a
--- /dev/null
@@ -0,0 +1,17 @@
+               .code
+               .export _strlen
+
+_strlen:
+               pop hl
+               pop de
+               push de
+               push hl
+               xor a
+               ld b,a
+               ld c,a
+               ld e,l
+               ld d,h
+               cpir
+               dec hl
+               sbc hl,de
+               ret
diff --git a/Applications/SmallC/Z80/lib/_strncat.s b/Applications/SmallC/Z80/lib/_strncat.s
new file mode 100644 (file)
index 0000000..bf649eb
--- /dev/null
@@ -0,0 +1,44 @@
+               .code
+               .export _strncat
+
+_strncat:
+               push    ix
+               ld      ix,#0
+               add     ix,sp
+               ld      l,4(ix)
+               ld      h,5(ix)
+               xor     a
+               ld      b,a
+               ld      c,a
+               ; Move past end of original string
+               cpir
+               dec     hl
+               ld      e,6(ix)
+               ld      d,7(ix)
+               ld      c,8(ix)
+               ld      b,9(ix)
+               ; Copy bytes until limit or \0
+_strncat_1:
+               ld      a,b
+               or      c
+               jr      z, _strncat_2
+               ld      a,(de)
+               ld      (hl),a
+               or      a
+               jr      z, _strncat_3
+               inc     de
+               inc     hl
+               dec     bc
+               jr      _strncat_1
+_strncat_2:    ld      l,4(ix)
+               ld      h,5(ix)
+               pop     ix
+               ret
+               ; Copy \0 until limit
+_strncat_3:    inc     hl
+               dec     bc
+               ld      a,b
+               or      c
+               jr      z,_strncat_2
+               ld      (hl),0
+               jr      _strncat_3
diff --git a/Applications/SmallC/Z80/lib/_strncpy.s b/Applications/SmallC/Z80/lib/_strncpy.s
new file mode 100644 (file)
index 0000000..317afa9
--- /dev/null
@@ -0,0 +1,38 @@
+               .code
+               .export _strncpy
+
+_strncpy:
+               push    ix
+               ld      ix,#0
+               add     ix,sp
+               ld      l,4(ix)
+               ld      h,5(ix)
+               ld      e,6(ix)
+               ld      d,7(ix)
+               ld      c,8(ix)
+               ld      b,9(ix)
+               ; Copy bytes until limit or \0
+_strncpy_1:
+               ld      a,b
+               or      c
+               jr      z, _strncpy_2
+               ld      a,(de)
+               ld      (hl),a
+               or      a
+               jr      z, _strncpy_3
+               inc     de
+               inc     hl
+               dec     bc
+               jr      _strncpy_1
+_strncpy_2:    ld      l,4(ix)
+               ld      h,5(ix)
+               pop     ix
+               ret
+               ; Copy \0 until limit
+_strncpy_3:    inc     hl
+               dec     bc
+               ld      a,b
+               or      c
+               jr      z,_strncpy_2
+               ld      (hl),0
+               jr      _strncpy_3
diff --git a/Applications/SmallC/Z80/lib/_strrchr.s b/Applications/SmallC/Z80/lib/_strrchr.s
new file mode 100644 (file)
index 0000000..b970d5c
--- /dev/null
@@ -0,0 +1,27 @@
+               .code
+               .export _strrchr
+
+_strrchr:
+               pop de          ; char
+               pop hl          ; ptr
+               pop bc
+               push bc
+               push hl
+               push de
+               ld bc, 0
+_strrchr_1:    ld a,(hl)
+               or a
+               jr z, _strrchr_2
+               cp e
+               jr z, _strrchr_3
+               inc hl
+               jr _strrchr_1
+_strrchr_2:
+               ld h,b
+               ld l,c
+               ret
+_strrchr_3:
+               ld b,h
+               ld c,l
+               jr _strrchr_1
+       
\ No newline at end of file
diff --git a/Applications/SmallC/Z80/lib/_strspn.s b/Applications/SmallC/Z80/lib/_strspn.s
new file mode 100644 (file)
index 0000000..0b77ff0
--- /dev/null
@@ -0,0 +1,32 @@
+               .code
+               .export _strcspn
+
+_strcspn:
+               pop bc
+               pop hl          ;       string
+               pop de          ;       match
+               push de
+               push hl
+               push bc
+
+_strcspn_1:
+               ld a,(hl)
+               or a
+               jr z,_strcspn_4
+               ld c,a
+
+               push de
+_strcspn_2:
+               ld a,(de)
+               or a
+               jr z, _strcspn_3
+               cp c
+               ret z           ;       Matched HL ponts to right spot
+               inc de
+               jr _strcspn_2
+_strcpsn_3:    pop de
+               inc hl
+               jr _strcspn_1
+_strcspn_4:    ld h,a          ;       A always 0 here
+               ld l,a
+               ret