dev: removing old printChar and instead using OS print vector

This commit is contained in:
A.M. Rowsell 2025-12-20 18:36:58 -05:00
commit cb332b7b05
Signed by: amr
GPG key ID: E0879EDBDB0CA7B1
6 changed files with 43 additions and 51 deletions

View file

@ -1,28 +1,26 @@
# SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: (c) 2025 A.M. Rowsell
ASM=vasm_z80_std
LINK=vlink
ASMFLAGS=-Fvobj
LINKFLAGS=-b ihex -T linker.cmd
all: float.hex
all: zone.hex
float.o: float.asm
$(ASM) $(ASMFLAGS) -o $@ $<
printChar.o: printChar.asm
$(ASM) $(ASMFLAGS) -o $@ $<
vectorTable.o: vectorTable.asm
$(ASM) $(ASMFLAGS) -o $@ $<
zone.o: zone.asm
$(ASM) $(ASMFLAGS) -o $@ $<
float.hex: float.o printChar.o vectorTable.o zone.o linker.cmd
$(LINK) $(LINKFLAGS) -o $@ float.o printChar.o vectorTable.o zone.o
zone.hex: float.o vectorTable.o zone.o linker.cmd
$(LINK) $(LINKFLAGS) -o $@ float.o vectorTable.o zone.o
clean:
rm -f float.o printChar.o vectorTable.o zone.o float.hex
rm -f float.o vectorTable.o zone.o zone.hex
.PHONY: all clean

View file

@ -22,7 +22,7 @@
; fp_div: A = A / B
;
; Extra:
; fp_print: print float at (HL) using external printChar (A=ASCII)
; fp_print: print float at (HL) using external os_print_vec (A=ASCII)
; fp_parse: parse null-terminated string at (DE) into float at (HL)
;
; Limitations:
@ -36,16 +36,16 @@
.equ FRAC_DIGITS,6
.equ MAX_FRAC,6
.extern printChar
.extern os_print_vec
; ============================================================
; CODE
; ============================================================
.section float
.section "float","acrx"
; ------------------------------------------------------------
; External routine you provide:
; printChar: prints ASCII character in A
; os_print_vec: prints ASCII character in A
; ------------------------------------------------------------
; printChar is external, not defined here.
; os_print_vec is external, not defined here.
; ============================================================
; Public API: fp_add / fp_sub / fp_mul / fp_div
@ -94,7 +94,7 @@ fp_sub:
push de
inc de
ld a,(de)
xor 080h
xor 0x80
ld (de),a
pop de
pop hl
@ -106,7 +106,7 @@ fp_sub:
push de
inc de
ld a,(de)
xor 080h
xor 0x80
ld (de),a
pop de
pop hl
@ -254,7 +254,7 @@ fp_unpackA:
ld a,(hl)
ld b,a
; sign bit -> A_sign (0/1)
and 080h
and 0x80
jp z,fp_unpackA_sa0
ld a,1
jr fp_unpackA_sa1
@ -265,8 +265,8 @@ fp_unpackA_sa1:
; mantissa bytes with hidden 1 inserted
ld a,b
and 07Fh
or 080h
and 0x7F
or 0x80
ld (A_m2),a
inc hl
ld a,(hl)
@ -293,7 +293,7 @@ fp_unpackB:
inc de
ld a,(de)
ld b,a
and 080h
and 0x80
jp z,fp_unpackB_sb0
ld a,1
jr fp_unpackB_sb1
@ -303,8 +303,8 @@ fp_unpackB_sb1:
ld (B_sign),a
ld a,b
and 07Fh
or 080h
and 0x7F
or 0x80
ld (B_m2),a
inc de
ld a,(de)
@ -344,7 +344,7 @@ fp_packA_packNZ:
; remove hidden 1
ld a,(A_m2)
and 07Fh
and 0x7F
ld b,a
; apply sign bit7
@ -352,7 +352,7 @@ fp_packA_packNZ:
or a
jp z,fp_packA_sign0
ld a,b
or 080h
or 0x80
jr fp_packA_storeB1
fp_packA_sign0:
ld a,b
@ -373,13 +373,13 @@ fp_pack_from_B_into_A:
ld (hl),a
inc hl
ld a,(B_m2)
and 07Fh
and 0x7F
ld b,a
ld a,(B_sign)
or a
jp z,fp_pack_from_B_bs0
ld a,b
or 080h
or 0x80
jr fp_pack_from_B_bs1
fp_pack_from_B_bs0:
ld a,b
@ -890,7 +890,7 @@ div_mantissas_loop:
jr c,div_mantissas_restore
; success => set quotient LSB = 1
ld a,(A_m0)
or 001h
or 0x1
ld (A_m0),a
jr div_mantissas_next
div_mantissas_restore:
@ -977,7 +977,7 @@ add24_Phigh_plus_B:
; ============================================================
; fp_print: fixed format printing
; Prints: [-]I.FFFFFF (FRAC_DIGITS digits)
; Uses printChar (A=char)
; Uses os_print_vec (A=char)
; ============================================================
fp_print:
; zero?
@ -985,13 +985,13 @@ fp_print:
or a
jr nz,fp_print_nz
ld a,'0'
call printChar
call os_print_vec
ld a,'.'
call printChar
call os_print_vec
ld b,FRAC_DIGITS
fp_print_zf:
ld a,'0'
call printChar
call os_print_vec
djnz fp_print_zf
ret
@ -1005,7 +1005,7 @@ fp_print_nz:
; sign + top fraction
ld a,(hl)
ld b,a
and 080h
and 0x80
jp z,fp_print_ps0
ld a,1
jr fp_print_ps1
@ -1016,8 +1016,8 @@ fp_print_ps1:
; mantissa with hidden 1 inserted
ld a,b
and 07Fh
or 080h
and 0x7F
or 0x80
ld (PR_M2),a
inc hl
ld a,(hl)
@ -1031,7 +1031,7 @@ fp_print_ps1:
or a
jp z,fp_print_mag
ld a,'-'
call printChar
call os_print_vec
fp_print_mag:
; S = (E - 23)
ld a,(PR_E)
@ -1084,13 +1084,13 @@ fp_print_doShl:
fp_print_print_int_and_frac:
call print_u32_dec
ld a,'.'
call printChar
call os_print_vec
ld b,FRAC_DIGITS
fp_print_fr:
call mul_remainder_by_10
ld a,(PR_R3)
add a,'0'
call printChar
call os_print_vec
xor a
ld (PR_R3),a
djnz fp_print_fr
@ -1173,7 +1173,7 @@ print_u32_dec:
or b
jr nz,print_u32_dec_nz
ld a,'0'
call printChar
call os_print_vec
ret
print_u32_dec_nz:
xor a
@ -1212,7 +1212,7 @@ print_u32_dec_pr:
ld b,0
add hl,bc
ld a,(hl)
call printChar
call os_print_vec
ld a,c
or a
jr nz,print_u32_dec_pr
@ -1353,7 +1353,7 @@ fp_parse_apply_sign:
ret z
inc hl
ld a,(hl)
xor 080h
xor 0x80
ld (hl),a
ret
@ -1536,7 +1536,7 @@ fp_from_u32_scaled_to_A_found:
; store sign=0, fraction = top 23 bits of mantissa (hidden 1 removed)
ld a,(PR_INT3)
and 07Fh
and 0x7F
ld (hl),a
inc hl
ld a,(PR_INT2)
@ -1615,7 +1615,7 @@ DIGLEN: .space 1
; 100000.0 = 143 43 50 00
; 1000000.0= 146 74 24 00
; ============================================================
.section float
.section "float","acrx"
pow10_table:
.byte 127, 0x00, 0x00, 0x00 ; 10^0 = 1
.byte 130, 0x20, 0x00, 0x00 ; 10^1 = 10

View file

@ -1,9 +1,9 @@
# SPDX-License-Identifier: MPL-2.0
/* SPDX-License-Identifier: MPL-2.0 */
/* SPDX-FileCopyrightText: (c) 2025 A.M. Rowsell */
SECTIONS
{
.zone 0xA000 : { *(.zone) *(zone) }
.text 0xE000 : { *(.text) }
.float 0xE000 : { *(.float) *(float) }
.text 0xE000 : { *(.text) *(.float) *(float) }
.vectors 0xF000 : { *(.vectors) }
.data 0x7000 : { *(.data) }
.bss : { *(.bss) }

View file

@ -1,6 +0,0 @@
; SPDX-License-Identifier: MPL-2.0
; SPDX-FileCopyrightText: (c) 2025 A.M. Rowsell
; Stub printChar: does nothing
.global printChar
printChar:
ret

View file

@ -6,7 +6,7 @@
.equ OS_VEC_BASE,0xF000
; .vectors is pinned to 0xF000 via linker.cmd
.section .vectors
.section ".vectors","adr"
.global os_vectors
os_vectors:

View file

@ -3,7 +3,7 @@
; ============================================================
; ZONE OS main section
; ============================================================
.section zone
.section "zone","acrx"
.global zone_start
.global os_print_vec
.global os_getch_vec