Skip to content

Commit

Permalink
[KERNAL] add legacy/c816 extended APIs (X16Community#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
mooinglemur authored Mar 3, 2024
1 parent f5a5bfd commit 3ba934e
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 9 deletions.
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ KERNAL_CORE_SOURCES = \
kernal/cbm/nmi.s \
kernal/cbm/irq.s \
kernal/cbm/util.s \
kernal/cbm/serial.s
kernal/cbm/serial.s \
kernal/x16/extapi.s \
kernal/x16/65c816/interrupt.s \
kernal/x16/65c816/stack.s \
kernal/x16/65c816/extapi16.s

KERNAL_GRAPH_SOURCES = \
kernal/graph/graph.s \
Expand All @@ -66,8 +70,6 @@ KERNAL_DRIVER_SOURCES = \
kernal/drivers/x16/i2c.s \
kernal/drivers/x16/smc.s \
kernal/drivers/x16/rtc.s \
kernal/drivers/x16/65c816/interrupt.s \
kernal/drivers/x16/65c816/stack.s \
kernal/drivers/generic/softclock_timer.s

KERNAL_SOURCES = \
Expand Down Expand Up @@ -182,6 +184,16 @@ GENERIC_DEPS = \

KERNAL_DEPS = \
$(GENERIC_DEPS) \
kernal/cbm/channel/channelio.s \
kernal/cbm/channel/clall.s \
kernal/cbm/channel/close.s \
kernal/cbm/channel/errorhandler.s \
kernal/cbm/channel/load.s \
kernal/cbm/channel/messages.s \
kernal/cbm/channel/open.s \
kernal/cbm/channel/openchannel.s \
kernal/cbm/channel/save.s \
kernal/cbm/channel/x16additions.s \
$(GIT_SIGNATURE)

KEYMAP_DEPS = \
Expand Down
6 changes: 6 additions & 0 deletions kernal/cbm/channel/channel.s
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ untlk = $ffab

.export savehl

; misc x16 additions
.export clear_status
.export get_fa


.segment "ZPCHANNEL" : zeropage
; C64 location
; VVV
Expand Down Expand Up @@ -146,4 +151,5 @@ stah .res 1 ;$C2
.include "load.s"
.include "save.s"
.include "errorhandler.s"
.include "x16additions.s"

8 changes: 8 additions & 0 deletions kernal/cbm/channel/x16additions.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

clear_status:
stz status
rts

get_fa:
lda fa
rts
8 changes: 4 additions & 4 deletions kernal/vectors.s
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

.import savehl

.import extapi, extapi16

.import c816_abort_emulated, c816_clall_thunk, c816_getin_thunk

.include "banks.inc"
Expand All @@ -39,10 +41,8 @@

; *** this is space for new X16 KERNAL vectors ***
;
; !!! DO NOT RELY ON THEIR ADDRESSES JUST YET !!!
;
.byte 0,0,0 ; $FEA8
.byte 0,0,0 ; $FEAB
jmp extapi16 ; $FEA8
jmp extapi ; $FEAB
.byte 0,0,0 ; $FEAE
jmp mciout ; $FEB1
jmp i2c_batch_read ; $FEB4
Expand Down
42 changes: 42 additions & 0 deletions kernal/x16/65c816/extapi16.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
.import stack_push, stack_pop
.import stack_enter_kernal_stack, stack_leave_kernal_stack

.export extapi16

.include "65c816.inc"

.segment "UTIL"

.setcpu "65816"

.A16
.I16

; This API call expects and requires m=0, x=0, e=0
extapi16:
php ; preserve flags
set_carry_if_65c816
bcc unsupported
phx ; preserve X parameter
asl ; translate API call number to jump table entry
tax
lda apitbl,x
plx ; restore old X
plp ; restore flags
pha ; push api address-1 onto stack
rts ; jump to api

unsupported:
plp
secrts:
sec
rts

apitbl:
.word secrts-1 ; slot 0 is reserved
.word stack_push-1 ; API 1
.word stack_pop-1 ; API 2
.word stack_enter_kernal_stack-1 ; API 3
.word stack_leave_kernal_stack-1 ; API 4


File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions kernal/x16/extapi.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
.import clear_status
.import get_fa

.export extapi

.segment "UTIL"

; This API call expects and requires e=1
extapi:
pha ; reserve two free spots on the stack
pha
php ; preserve caller flags
phx ; preserve caller X parameter
asl
tax
lda apitbl,x ; low byte of jump table entry
pha
lda apitbl+1,x ; high byte of jump table entry
tsx
sta $105,x ; store API high byte on stack
pla
sta $104,x ; store API low byte on stack
plx ; restore caller X
plp ; restore caller flags
rts ; jump to api

secrts:
sec
rts

apitbl:
.word secrts-1 ; slot 0 is reserved
.word clear_status-1 ; API 1
.word get_fa-1 ; API 2

4 changes: 2 additions & 2 deletions kernsup/kernsup.inc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.byte 0,0,0 ; $FEA8
.byte 0,0,0 ; $FEAB
bridge extapi16 ; $FEA8
bridge extapi ; $FEAB
.byte 0,0,0 ; $FEAE
bridge mciout ; $FEB1
bridge i2c_batch_read ; $FEB4
Expand Down

0 comments on commit 3ba934e

Please sign in to comment.