Skip to content

Commit

Permalink
[KERNAL] PRIMM: Add 65C816 native mode support and optimize the code (X…
Browse files Browse the repository at this point in the history
…16Community#352)

* [KERNAL] PRIMM: Add 65C816 native mode support and optimize the 65C02 code to use (zp) instead of (zp),y with y = 0

* [KERNAL] Move UTIL segment so that PRIMM has enough space

* [KERNAL] Optimize 65C02 and 65C816 implementations
  • Loading branch information
Fulgen301 authored Nov 15, 2024
1 parent b358bf5 commit d91bc55
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cfg/kernal-x16.cfgtpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ SEGMENTS {
SERIAL: load = KERNAL, type = ro;
LZSA: load = KERNAL, type = ro;
CHANNEL: load = KERNAL, type = ro;
UTIL: load = KERNAL, type = ro;
C816_UTIL: load = KERNAL, type = ro;
C816_ABORT_NATIVE: load = KERNAL, type = ro, start = $E44C; # low byte: JMP abs, high byte equals low byte of C816_CLALL_THUNK
JOYSTICK: load = KERNAL, type = ro;
Expand All @@ -61,7 +62,6 @@ SEGMENTS {
MEMDRV: load = KERNAL, type = ro;
NMI: load = KERNAL, type = ro;
IRQ: load = KERNAL, type = ro;
UTIL: load = KERNAL, type = ro;
GRAPH: load = KERNAL, type = ro;
CONSOLE: load = KERNAL, type = ro;
SPRITES: load = KERNAL, type = ro;
Expand Down
76 changes: 58 additions & 18 deletions kernal/cbm/util.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

.feature labels_without_colons

.include "65c816.inc"
.include "banks.inc"

bsout = $ffd2
Expand All @@ -20,31 +21,70 @@ bsout = $ffd2
; terminated by a $00. the immediate string must not be longer
; than 255 characters including the terminator.

primm
.proc primm
pha ;save registers
txa
pha
tya
pha
phx
phy
ldy #0

@1 tsx ;increment return address on stack
inc $104,x ;and make imparm = return address
bne @2
inc $105,x
@2 lda $104,x
set_carry_if_65c816
bcs is_65c816

tsx
lda $0104,x
sta imparm
lda $105,x
lda $0105,x
sta imparm+1

lda (imparm),y ;fetch character to print (*** always system bank ***)
beq @3 ;null= eol
jsr bsout ;print the character
@1 iny
lda (imparm),y ;fetch character to print (*** always system bank ***)
beq @2 ;null= eol
jsr bsout ;print the character
bcc @1

@3 pla ;restore registers
tay
@2 phy ;increment return address on stack
tsx
lda imparm
clc
adc $0101,x
sta $0105,x
bcc @3
lda imparm+1
adc #$00
sta $0106,x
@3 ply ;pop counter
ply ;restore registers
plx
pla
tax
rts

is_65c816:
.pushcpu
.setcpu "65816"
lda $04,S
sta imparm
lda $05,S
sta imparm+1

@1 iny
lda (imparm),y ;fetch character to print (*** always system bank ***)
beq @2 ;null= eol
jsr bsout ;print the character
bcc @1

@2 phy ;increment return address on stack
lda imparm
clc
adc $01,S
sta $05,S
bcc @3
lda imparm+1
adc #$00
sta $06,S
@3 ply ;pop counter
ply ;restore registers
plx
pla
rts ;return
rts
.popcpu
.endproc

0 comments on commit d91bc55

Please sign in to comment.