deduplicated 'printf.s', over 200 bytes saved in BASIC segment

This commit is contained in:
FeralChild64 committed 2019-09-26 20:50:46 +02:00
1 parent 94b8e0dc29
commit 332438145c
4 files changed
+32 -201

No files matched your search

+22 -16
View File
@@ -89,25 +89,31 @@ build/chargen.rom: $(TOOL_PNGPREPARE) assets/8x8font.png
# Dependencies - BASIC and KERNAL
build/target_generic/OUTB.BIN build/target_generic/BASIC_combined.vs: \
$(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_BASIC) $(SRCDIR_BASIC_generic) \
c64/,,config_generic.s $(foreach dir,$(SRCDIR_BASIC_generic),$(wildcard $(dir)/*.s))
build/target_mega65/OUTB.BIN build/target_mega65/BASIC_combined.vs: \
build/target_generic/OUTB.BIN build/target_generic/BASIC_combined.vs: \
$(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_BASIC) $(SRCDIR_BASIC_generic) \
c64/,,config_generic.s build/target_generic/KERNAL_combined.sym \
$(foreach dir,$(SRCDIR_BASIC_generic),$(wildcard $(dir)/*.s))
build/target_mega65/OUTB.BIN build/target_mega65/BASIC_combined.vs: \
$(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_BASIC) $(SRCDIR_BASIC_mega65) \
c64/,,config_mega65.s $(foreach dir,$(SRCDIR_BASIC_mega65),$(wildcard $(dir)/*.s))
build/target_ultimate64/OUTB.BIN build/target_ultimate64/BASIC_combined.vs: \
c64/,,config_mega65.s build/target_mega65/KERNAL_combined.sym \
$(foreach dir,$(SRCDIR_BASIC_mega65),$(wildcard $(dir)/*.s))
build/target_ultimate64/OUTB.BIN build/target_ultimate64/BASIC_combined.vs: \
$(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_BASIC) $(SRCDIR_BASIC_ultimate64) \
c64/,,config_ultimate64.s $(foreach dir,$(SRCDIR_BASIC_ultimate64),$(wildcard $(dir)/*.s))
c64/,,config_ultimate64.s build/target_ultimate64/KERNAL_combined.sym \
$(foreach dir,$(SRCDIR_BASIC_ultimate64),$(wildcard $(dir)/*.s))
build/target_generic/OUTK.BIN build/target_generic/KERNAL_combined.vs: \
build/target_generic/OUTK.BIN build/target_generic/KERNAL_combined.vs build/target_generic/KERNAL_combined.sym: \
$(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_KERNAL) $(SRCDIR_KERNAL_generic) \
c64/,,config_generic.s $(foreach dir,$(SRCDIR_KERNAL_generic),$(wildcard $(dir)/*.s))
build/target_mega65/OUTK.BIN build/target_mega65/KERNAL_combined.vs: \
c64/,,config_generic.s \
$(foreach dir,$(SRCDIR_KERNAL_generic),$(wildcard $(dir)/*.s))
build/target_mega65/OUTK.BIN build/target_mega65/KERNAL_combined.vs build/target_mega65/KERNAL_combined.sym: \
$(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_KERNAL) $(SRCDIR_KERNAL_mega65) \
c64/,,config_mega65.s $(foreach dir,$(SRCDIR_KERNAL_mega65),$(wildcard $(dir)/*.s))
build/target_ultimate64/OUTK.BIN build/target_ultimate64/KERNAL_combined.vs: \
c64/,,config_mega65.s \
$(foreach dir,$(SRCDIR_KERNAL_mega65),$(wildcard $(dir)/*.s))
build/target_ultimate64/OUTK.BIN build/target_ultimate64/KERNAL_combined.vs build/target_ultimate64/KERNAL_combined.sym: \
$(TOOL_ASSEMBLER) $(TOOL_BUILD_SEGMENT) $(GEN_KERNAL) $(SRCDIR_KERNAL_ultimate64) \
c64/,,config_ultimate64.s $(foreach dir,$(SRCDIR_KERNAL_ultimate64),$(wildcard $(dir)/*.s))
c64/,,config_ultimate64.s \
$(foreach dir,$(SRCDIR_KERNAL_ultimate64),$(wildcard $(dir)/*.s))
build/target_generic/newrom: build/target_generic/OUTB.BIN build/target_generic/OUTK.BIN
build/target_mega65/newrom: build/target_mega65/OUTB.BIN build/target_mega65/OUTK.BIN
@@ -137,8 +143,8 @@ build/target_%/OUTB.BIN build/target_%/BASIC_combined.vs:
@rm -f $@* build/target_$*/BASIC*
@$(TOOL_BUILD_SEGMENT) -a ../../$(TOOL_ASSEMBLER) -s BASIC -i BASIC-$* -o OUTB.BIN -d build/target_$* -l a000 -h e4d2 c64/,,config_$*.s $(SRCDIR_BASIC_$*) $(GEN_BASIC)
.PRECIOUS: build/target_%/OUTK.BIN build/target_%/KERNAL_combined.vs
build/target_%/OUTK.BIN build/target_%/KERNAL_combined.vs:
.PRECIOUS: build/target_%/OUTK.BIN build/target_%/KERNAL_combined.vs build/target_%/KERNAL_combined.sym
build/target_%/OUTK.BIN build/target_%/KERNAL_combined.vs build/target_%/KERNAL_combined.sym:
@mkdir -p build/target_$*
@rm -f $@* build/target_$*/KERNAL*
@$(TOOL_BUILD_SEGMENT) -a ../../$(TOOL_ASSEMBLER) -s KERNAL -i KERNAL-$* -o OUTK.BIN -d build/target_$* -l e4d3 -h ffff c64/,,config_$*.s $(SRCDIR_KERNAL_$*) $(GEN_KERNAL)
@@ -157,7 +163,7 @@ build/basic_%.rom:
.PRECIOUS: build/symbols_%.vs
build/symbols_%.vs:
sort build/target_$*/BASIC_combined.vs build/target_$*/KERNAL_combined.vs | uniq > $@
sort build/target_$*/BASIC_combined.vs build/target_$*/KERNAL_combined.vs | uniq | grep -v "__" > $@
# Rules - platform 'Mega 65' specific
+7
View File
@@ -0,0 +1,7 @@
// Routines imported from Kernal - our private API
#import "KERNAL_combined.sym"
.label printf = KERNAL.printf
.label printf_printhexbyte = KERNAL.printf_printhexbyte
-185
View File
@@ -1,185 +0,0 @@
// printf()-like routine for simplifying debugging
// Prints the literal zero-terminated string that follows,
// which may also include special tokens that allow
// printing of hex byte and word values stored at the indicated
// addresses.
// .byte 1,$byte = display byte as hex
// .byte 2,$low,$hi = display word as hex
// .byte $f0+n,$low,$hi = display byte at $hi$lo+n as hex
printf:
// Temporary storage is between end of screen at $0400
// and the sprite pointers at $7f8
sta $7f0
stx $7f1
sty $7f2
php
pla
sta $7f3
// Set up read routine
lda #$ad // LDA $nnnn
sta $7f4
lda #$60
sta $7f7 // RTS
// Get PC of caller from the stack, so that
// we can parse through it
pla
clc
adc #$01
sta $7f5
pla
adc #$00
sta $7f6
printf_loop:
jsr $7f4
cmp #$00
bne printf_continues
// Put return address on stack and restore
// registers
lda $7f6
pha
lda $7f5
pha
lda $7f3
pha
lda $7f0
ldx $7f1
ldy $7f2
plp
rts
printf_continues:
cmp #$01
bne not_hexbyte
// Print a hex byte
// Skip the token
jsr printf_advance
// Read the low byte
jsr $7f4
// Print as hex
jsr printf_printhexbyte
jmp printf_nextchar
not_hexbyte:
cmp #$02
bne not_hexword
// Print a hex word
// Skip the token
jsr printf_advance
jsr printf_advance
// Read the high byte
jsr $7f4
// Print as hex
jsr printf_printhexbyte
// Skip the token
jsr printf_retreat
// Read the low byte
jsr $7f4
// Print as hex
jsr printf_printhexbyte
jsr printf_advance
jmp printf_nextchar
not_hexword:
cmp #$f0
bcc not_pointer
// Treat two-byte arg as base address
// and lower 4 bits of token as offset from
// that location.
// Get offset
and #$0f
tay
jsr printf_advance
jsr $7f4
sta $fd
jsr printf_advance
jsr $7f4
sta $fe
lda ($fd),y
jsr printf_printhexbyte
jmp printf_nextchar
not_pointer:
// Print character
jsr JCHROUT
printf_nextchar:
jsr printf_advance
jmp printf_loop
printf_advance:
// Advance pointer to next character
inc $7f5
bne !+
inc $7f6
!:
rts
printf_retreat:
// Retreat pointer to previous char
lda $7f5
sec
sbc #1
sta $7f5
lda $7f6
sbc #0
sta $7f6
rts
printf_printhexbyte:
// Print the hex value in .A as two digits
#if HAS_BCD_SAFE_INTERRUPTS
// Idea by Haubitze
sed
pha
lsr
lsr
lsr
lsr
cmp #$0A
adc #$30
jsr JCHROUT
pla
and #$0F
cmp #$0A
adc #$30
cld
jmp JCHROUT
#else
pha
lsr
lsr
lsr
lsr
ora #$30
cmp #$3A
bcc !+
adc #6
!: jsr JCHROUT
pla
and #$0f
ora #$30
cmp #$3A
bcc !+
adc #6
!: jmp JCHROUT
#endif
+3
View File
@@ -524,6 +524,7 @@ void compileSegment()
", outBin=\"" << CMD_outFile << "\", fill]" <<
"\n";
outFile << "#define SEGMENT_" << CMD_segName << "\n";
outFile << ".namespace " << CMD_segName << " {" << "\n\n";
// Write files which only contain definitions (no routines)
@@ -548,6 +549,8 @@ void compileSegment()
outFile << "\n";
}
outFile << "\n\n" << "} // namespace" << "\n";
if (!outFile.good()) ERROR(std::string("error writing temporary file '") + outFileNamePath + "'");
outFile.close();