Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KERNAL] PRIMM: Add 65C816 native mode support and optimize the code #352

Merged
merged 3 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading