Changed most of the library sources to use .CAP instead of .CPU.

This commit is contained in:
Kugel Fuhr
2025-07-01 07:25:32 +02:00
parent f333b300f1
commit c72126e68f
59 changed files with 122 additions and 232 deletions

View File

@@ -7,8 +7,6 @@
.include "errno.inc"
.macpack cpu
; ----------------------------------------------------------------------------
; int __fastcall__ __directerrno (unsigned char code);
; /* Set errno to a specific error code, clear __oserror, and return -1. Used
@@ -18,7 +16,7 @@
___directerrno:
jsr ___seterrno ; Set errno (returns with .A = 0)
sta ___oserror ; Clear ___oserror
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_INA)
dec a
.else
lda #$FF ; Return -1

View File

@@ -12,7 +12,6 @@
.include "_heap.inc"
.macpack generic
.macpack cpu
;-----------------------------------------------------------------------------
; Code
@@ -39,7 +38,7 @@ ___heapblocksize:
ldy #usedblock::size+1
lda (ptr2),y
tax
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (ptr2)
.else
dey

View File

@@ -8,7 +8,6 @@
.include "errno.inc"
.macpack generic
.macpack cpu
; ----------------------------------------------------------------------------
; int __fastcall__ __mappederrno (unsigned char code);
@@ -24,7 +23,7 @@ ___mappederrno:
bze ok ; Branch if no
jsr ___osmaperrno ; Map OS error into errno code
jsr ___seterrno ; Save in errno (returns with .A = 0)
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_INA)
dec a
.else
lda #$FF ; Return -1 if error

View File

@@ -13,7 +13,6 @@
.import _strlower, _strlen
.macpack generic
.macpack cpu
; ----------------------------------------------------------------------------
; We will store variables into the register bank in the zeropage. Define
@@ -38,7 +37,7 @@ FCount = ptr2
GetFormatChar:
ldy #0
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (Format)
.else
lda (Format),y
@@ -115,7 +114,7 @@ GetIntArg:
lda (ArgList),y
tax
dey
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (ArgList)
.else
lda (ArgList),y
@@ -274,7 +273,7 @@ Save: lda regbank,y
; Initialize the output counter in the output descriptor to zero
lda #0
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (OutData)
ldy #$01
sta (OutData),y
@@ -353,7 +352,7 @@ MainLoop:
sta (c_sp),y
dey
lda FCount
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (c_sp)
.else
sta (c_sp),y
@@ -570,7 +569,7 @@ CheckCount:
jsr GetIntArg
sta ptr1
stx ptr1+1 ; Get user supplied pointer
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (OutData) ; Low byte of OutData->ccount
sta (ptr1)
ldy #1

View File

@@ -16,8 +16,6 @@
.include "time.inc"
.macpack cpu
__time_t_to_tm:
; Divide number of seconds since epoch, in ptr1:sreg,
; by 86400 to get the number of days since epoch, and
@@ -80,7 +78,7 @@ __time_t_to_tm:
; Zero the two high bytes of the divisor and the high byte
; of the dividend.
.if .cpu .bitand CPU_ISET_65SC02
.if .cap(CPU_HAS_STZ)
stz ptr4
stz ptr4+1
stz sreg+1

View File

@@ -9,8 +9,6 @@
.importzp ptr1
.include "time.inc"
.macpack cpu
; ------------------------------------------------------------------------
; Special values
@@ -24,7 +22,7 @@ MAX_BUF_LEN = 38
_asctime:
; Backup timep
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_PUSHXY)
pha
phx
.else
@@ -48,7 +46,7 @@ _asctime:
jsr pushax
; Restore timep
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_PUSHXY)
plx
pla
.else

View File

@@ -10,8 +10,6 @@
.include "errno.inc"
.macpack cpu
; ---------------------------------------------------------------------------
.proc _atexit
@@ -41,7 +39,7 @@
jsr ___seterrno
ldx #$FF ; Return -1
txa
rts
Exit: rts
.endproc
@@ -54,7 +52,7 @@
.proc doatexit
ldy exitfunc_index ; Get index
beq @L9 ; Jump if done
beq _atexit::Exit ; Jump if done
dey
lda exitfunc_table,y
tax
@@ -62,14 +60,12 @@
lda exitfunc_table,y
sty exitfunc_index
jsr callax ; Call the function
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_BRA8)
bra doatexit
.else
jmp doatexit ; Next one
.endif
@L9: rts
.endproc

View File

@@ -12,8 +12,6 @@
.include "stdio.inc"
.include "_file.inc"
.macpack cpu
_fgetc:
sta ptr1
stx ptr1+1
@@ -22,7 +20,7 @@ _fgetc:
jsr checkferror
bne ret_eof
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_BITIMM)
bit #_FPUSHBACK ; Check for pushed back char
beq do_read
.else

View File

@@ -14,12 +14,10 @@
.include "stdio.inc"
.include "_file.inc"
.macpack cpu
terminate_ptr:
lda #$00
tax
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (ptr4)
.else
tay
@@ -41,7 +39,7 @@ _fgets:
sta buf
stx buf+1
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz didread
.else
lda #$00 ; We have read nothing yet
@@ -79,7 +77,7 @@ read_loop:
ldy #$01
sty didread ; We read at least one char
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (ptr4)
.else
dey

View File

@@ -20,7 +20,6 @@
.include "_file.inc"
.macpack generic
.macpack cpu
; ------------------------------------------------------------------------
; Code
@@ -48,7 +47,7 @@
ldy #_FILE::f_flags
lda (file),y
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_BITIMM)
bit #_FOPEN ; Is the file open?
.else
and #_FOPEN ; Is the file open?
@@ -57,7 +56,7 @@
; Check if the stream is in an error state
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_BITIMM)
bit #_FERROR
.else
lda (file),y ; get file->f_flags again
@@ -74,17 +73,15 @@
; Remember if we have a pushed back character and reset the flag.
@L2: .if (.cpu .bitand ::CPU_ISET_65SC02)
@L2: .if .cap(CPU_HAS_BITIMM)
ldx #$00
bit #_FPUSHBACK
beq @L3
.else
tax ; X = 0
lda (file),y
and #_FPUSHBACK
.endif
beq @L3
.if (.not .cpu .bitand ::CPU_ISET_65SC02)
lda (file),y
.endif
and #<~_FPUSHBACK
@@ -135,7 +132,7 @@
; Copy the buffer pointer into ptr1, and increment the pointer value passed
; to read() by one, so read() starts to store data at buf+1.
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp)
sta ptr1
add #1
@@ -159,7 +156,7 @@
ldy #_FILE::f_pushback
lda (file),y
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (ptr1) ; *buf = file->f_pushback;
.else
ldy #0

View File

@@ -16,8 +16,6 @@
.include "errno.inc"
.include "_file.inc"
.macpack cpu
; ------------------------------------------------------------------------
; Code
@@ -34,7 +32,7 @@
ldy #_FILE::f_flags
lda (ptr1),y
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_BITIMM)
bit #_FOPEN
.else
and #_FOPEN ; Is the file open?
@@ -50,7 +48,7 @@
; Check if the stream is in an error state
@L2: .if (.not .cpu .bitand ::CPU_ISET_65SC02)
@L2: .if .not .cap(CPU_HAS_BITIMM)
lda (ptr1),y ; get file->f_flags again
.endif
and #_FERROR

View File

@@ -10,8 +10,6 @@
.import __hextab, __longminstr
.importzp sreg, ptr1, ptr2, ptr3, tmp1
.macpack cpu
.code
;
@@ -64,7 +62,7 @@ L2: txa ; get high byte
bpl ultoa
lda #'-'
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (ptr2)
.else
ldy #0

View File

@@ -8,7 +8,6 @@
.export _strcat
.import popax
.importzp ptr1, ptr2, tmp3
.macpack cpu
_strcat:
sta ptr1 ; Save src
@@ -16,7 +15,7 @@ _strcat:
jsr popax ; Get dest
sta tmp3 ; Remember for function return
tay
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz ptr2
.else
lda #0

View File

@@ -8,14 +8,13 @@
.export _strchr
.import popax
.importzp ptr1, tmp1
.macpack cpu
_strchr:
sta tmp1 ; Save c
jsr popax ; get s
tay ; low byte of pointer to y
stx ptr1+1
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz ptr1
.else
lda #0

View File

@@ -12,8 +12,6 @@
.import _strlen_ptr4, _malloc, _memcpy, pushax
.export _strdup
.macpack cpu
_strdup:
; Get length (and store source in ptr4)
sta ptr4
@@ -22,7 +20,7 @@ _strdup:
jsr _strlen_ptr4 ; strlen may increment
; Add null byte for terminator
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_INA)
inc a
.else
clc

View File

@@ -8,64 +8,63 @@
.export _strncat
.import popax, popptr1
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
.macpack cpu
_strncat:
inx
stx tmp2
tax
inx
stx tmp1 ; save count with each byte incremented separately
inx
stx tmp2
tax
inx
stx tmp1 ; save count with each byte incremented separately
jsr popptr1 ; get src
jsr popptr1 ; get src
jsr popax ; get dest
sta ptr3 ; remember for function return
stx ptr3+1
stx ptr2+1
tay ; low byte as offset in Y
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz ptr2
jsr popax ; get dest
sta ptr3 ; remember for function return
stx ptr3+1
stx ptr2+1
tay ; low byte as offset in Y
.if .cap(CPU_HAS_STZ)
stz ptr2
.else
ldx #0
stx ptr2 ; destination on page boundary
ldx #0
stx ptr2 ; destination on page boundary
.endif
; find end of dest
L1: lda (ptr2),y
beq L2
iny
bne L1
inc ptr2+1
bne L1
L1: lda (ptr2),y
beq L2
iny
bne L1
inc ptr2+1
bne L1
; end found, apply offset to dest ptr and reset y
L2: sty ptr2
L2: sty ptr2
; copy src. We've put the ones complement of the count into the counter, so
; we'll increment the counter on top of the loop
L3: ldy #0
ldx tmp1 ; low counter byte
L3: ldy #0
ldx tmp1 ; low counter byte
L4: dex
bne L5
dec tmp2
beq L6 ; jump if done
L5: lda (ptr1),y
sta (ptr2),y
beq L7
iny
bne L4
inc ptr1+1
inc ptr2+1
bne L4
L4: dex
bne L5
dec tmp2
beq L6 ; jump if done
L5: lda (ptr1),y
sta (ptr2),y
beq L7
iny
bne L4
inc ptr1+1
inc ptr2+1
bne L4
; done, set the trailing zero and return pointer to dest
L6: lda #0
sta (ptr2),y
L7: lda ptr3
ldx ptr3+1
rts
L6: lda #0
sta (ptr2),y
L7: lda ptr3
ldx ptr3+1
rts