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] implement native-capable jsrfar #283

Merged
merged 15 commits into from
Mar 8, 2024
Merged
4 changes: 2 additions & 2 deletions cfg/audio-x16.cfgtpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
MEMORY {
#include "x16.cfginc"

ROM: start = $C000, size = $3B00, fill=yes, fillval=$AA;
KSUP_CODE10: start = $FB00, size = $03A8, fill=yes, fillval=$AA;
ROM: start = $C000, size = $3A80, fill=yes, fillval=$AA;
KSUP_CODE10: start = $FA80, size = $0428, fill=yes, fillval=$AA;
KSUP_VEC10: start = $FEA8, size = $0158, fill=yes, fillval=$AA;

}
Expand Down
4 changes: 2 additions & 2 deletions cfg/bannex-x16.cfgtpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
MEMORY {
#include "x16.cfginc"

ANNEX: start = $C000, size = $3B00, fill=yes, fillval=$AA;
KSUP_CODE12: start = $FB00, size = $03A8, fill=yes, fillval=$AA;
ANNEX: start = $C000, size = $3A80, fill=yes, fillval=$AA;
KSUP_CODE12: start = $FA80, size = $0428, fill=yes, fillval=$AA;
KSUP_VEC12: start = $FEA8, size = $0158, fill=yes, fillval=$AA;
}

Expand Down
6 changes: 3 additions & 3 deletions cfg/codex-x16.cfgtpl
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
MEMORY {
#include "x16.cfginc"

MAIN: file = %O, define = yes, start = $C000, size = $3AE2, fill=yes fillval=$A3;
MAIN: file = %O, define = yes, start = $C000, size = $3A72, fill=yes fillval=$A3;
RWRAM: file = "", start = $0400, size = $3FF;
BANK: file = "", start = $A000, size = $2000;
CODEX_VECS: start = $FAE2, size = $001E, fill=yes, fillval=$A0;
KSUP_CODE2: start = $FB00, size = $03A8, fill=yes, fillval=$A1;
CODEX_VECS: start = $FA72, size = $001E, fill=yes, fillval=$A0;
KSUP_CODE2: start = $FA80, size = $0418, fill=yes, fillval=$A1;
KSUP_VEC2: start = $FEA8, size = $0158, fill=yes, fillval=$A2;
}

Expand Down
2 changes: 1 addition & 1 deletion cfg/diag-x16.cfgtpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ MEMORY {
#include "x16.cfginc"

JMPTBL: start = $C000, size = $0010, fill = yes, fillval = $00;
DIAG: start = $C010, size = $4000, fill = yes, fillval = $AA;
DIAG: start = $C010, size = $3FF0, fill = yes, fillval = $AA;
}

SEGMENTS {
Expand Down
1 change: 1 addition & 0 deletions cfg/kernal-x16.cfgtpl
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ SEGMENTS {
VERA_DRV: load = KERNAL, type = ro;
PALETTE: load = KERNAL, type = ro, align = $100;
KRAMJFAR: load = KERNAL, run = KRAMJFAR, type = ro, define = yes;
KJFAR816: load = KERNAL, run = KJFAR816, type = ro, define = yes;
KERNRAM2: load = KERNAL, run = KERNRAM2, type = ro, define = yes;
KRAM816: load = KERNAL, run = KRAM816, type = ro, define = yes;
KRAM02B: load = KERNAL, run = KRAM02B, type = ro, define = yes;
Expand Down
4 changes: 2 additions & 2 deletions cfg/monitor-x16.cfgtpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ MEMORY {

L0220: start = $0220, size = $0019; # overlaps with top end of BASIC input line only

BANK5: start = $C000, size = $3B00, fill=yes, fillval=$AA;
KSUP_CODE2: start = $FB00, size = $03A8, fill=yes, fillval=$AA;
BANK5: start = $C000, size = $3A80, fill=yes, fillval=$AA;
KSUP_CODE2: start = $FA80, size = $0428, fill=yes, fillval=$AA;
KSUP_VEC2: start = $FEA8, size = $0158, fill=yes, fillval=$AA;
}

Expand Down
4 changes: 2 additions & 2 deletions cfg/util-x16.cfgtpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ MEMORY {
HEXEDITZP: start = $0022, size = $005E, fill=no;
HEXEDITBSS: start = $0200, size = $0050, fill=no;
MENUBSS: start = $0200, size = $0050, fill=no;
ROM: start = $C000, size = $3B00, fill=yes, fillval=$AA;
KSUP_CODE11: start = $FB00, size = $03A8, fill=yes, fillval=$AA;
ROM: start = $C000, size = $3A80, fill=yes, fillval=$AA;
KSUP_CODE11: start = $FA80, size = $0428, fill=yes, fillval=$AA;
KSUP_VEC11: start = $FEA8, size = $0158, fill=yes, fillval=$AA;

}
Expand Down
3 changes: 2 additions & 1 deletion cfg/x16.cfginc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ ZPBASIC: start = $00D4, size = $002B; # BASIC (last byte used: $FE)
/* $0200-$02FF: always-available variables and RAM code */
KVAR: start = $0200, size = $0095; # KERNAL
KRAM816S: start = $0295, size = $0003; # KERNAL: 65C816: old stack pointer
/* start = $0298, size = $0028; # reserved for KERNAL growth */
KJFAR816: start = $0298, size = $0019; # KERNAL: jsrfar3n
/* start = $02B1, size = $000F; # reserved for KERNAL growth */
I2CMUTEX: start = $02C0, size = $0001; # I2C MUTEX FLAG
GRAPHVAR: start = $02C1, size = $0003; # GRAPH BANK VARS
KRAMJFAR: start = $02C4, size = $001E; # KERNAL: jsrfar3
Expand Down
1 change: 1 addition & 0 deletions inc/banks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ BANK_BASLOAD = $0F
; XXX implementation details and need to go away!
cbdos_flags= $0268
status = $0287 ; channel: status byte
jsrfar3n = $0298 ; jsrfar: RAM part, 65C816 native
jsrfar3 = $02c4 ; jsrfar: RAM part
jmpfr = $02df ; jsrfar: core jmp instruction
imparm = $82 ; jsrfar: temporary byte
Expand Down
85 changes: 81 additions & 4 deletions inc/jsrfar.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@
; .word address
; .byte bank

pha ;reserve 1 byte on the stack
php ;reserve 1 byte on the stack
php ;save registers & status

sec
.byte $c2, $03 ; rep #$03, clear carry/z if 65c816
bcc jsrfarn

clc
jsrfare:
pha
phx
phy

tsx
tsx
lda $106,x ;return address lo
sta imparm
clc
; carry is clear
adc #3
sta $106,x ;and write back with 3 added
lda $107,x ;return address hi
Expand Down Expand Up @@ -63,4 +70,74 @@ jsrfar2:
pla
plp
plp
rts
rts

.pushcpu

.setcpu "65816"

jsrfarn:
; carry is clear
xce
bcc :+
mooinglemur marked this conversation as resolved.
Show resolved Hide resolved
xce
bra jsrfare ; with carry cleared
: rep #$31 ; force 16 bit memory/index, clear carry
.A16
.I16
pha
phy

lda $07,S ; fetch return address
sta imparm
; carry is clear
adc #3
sta $07,S ; write back return address+3
ldy #1
lda (imparm),y
sta jmpfr+1
cmp #$c000
bcc jsrfar1n
; target is in ROM
sep #$20 ; 8 bit accumulator
.A8
mooinglemur marked this conversation as resolved.
Show resolved Hide resolved
.I16
lda rom_bank
sta $06,S ; save original bank onto reserved byte
ldy #3
lda (imparm),y
ply
jmp jsrfar3n

; target is in RAM
jsrfar1n:
sep #$20 ; 8 bit accumulator
.A8
.I16
lda ram_bank
sta $06,S ; save original bank onto reserved byte
lda #3
lda (imparm),y
sta ram_bank
mooinglemur marked this conversation as resolved.
Show resolved Hide resolved
rep #$30 ; 16 bit memory/index
.A16
mooinglemur marked this conversation as resolved.
Show resolved Hide resolved
.I16
ply
pla
plp ; original register widths popped immediately before call
jsr jmpfr
php ; preserve flags immediately after return from call
sep #$20 ; 8 bit accumulator
.A8
mooinglemur marked this conversation as resolved.
Show resolved Hide resolved
.I16
pha
lda $03,S
sta ram_bank
lda $02,S ; overwrite reserved byte
sta $03,S ; with copy of .P
pla
plp ; restore flags to state immediately after call
plp
rts

.popcpu
35 changes: 35 additions & 0 deletions kernal/drivers/x16/memory.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.include "io.inc"

.import __KRAMJFAR_LOAD__, __KRAMJFAR_RUN__, __KRAMJFAR_SIZE__
.import __KJFAR816_LOAD__, __KJFAR816_RUN__, __KJFAR816_SIZE__
.import __KERNRAM2_LOAD__, __KERNRAM2_RUN__, __KERNRAM2_SIZE__
.import __KRAM816_LOAD__, __KRAM816_RUN__, __KRAM816_SIZE__
.import __KRAM02B_LOAD__, __KRAM02B_RUN__, __KRAM02B_SIZE__
Expand Down Expand Up @@ -139,6 +140,11 @@ ramtas:
.A16
.I16

ldx #__KJFAR816_LOAD__
ldy #__KJFAR816_RUN__
lda #(__KJFAR816_SIZE__ - 1)
mvn #00,#00

ldx #__KRAM816_LOAD__
ldy #__KRAM816_RUN__
lda #(__KRAM816_SIZE__ - 1)
Expand Down Expand Up @@ -271,6 +277,35 @@ jsrfar:
__jmpfr:
jmp $ffff

.pushcpu
.setcpu "65816"

.segment "KJFAR816"
.assert * = jsrfar3n, error, "jsrfar3n must be at specific address"
mooinglemur marked this conversation as resolved.
Show resolved Hide resolved

;jsrfar3n:
.A8
sta rom_bank ;set ROM bank
rep #$30
.A16
.I16
pla
plp ; restore all flags immediately before call
jsr jmpfr
php
sep #$20 ; 8 bit accumulator
.A8
pha ; Push lower byte of accumulator
lda $03,S
sta rom_bank ;restore ROM bank
lda $02,S ;overwrite reserved byte...
sta $03,S ;...with copy of .P
pla ; .B remains unchanged and is thus preserved
plp ; restore flags from state immediately after call
plp
rts

.popcpu

.segment "KERNRAM2"

Expand Down
Loading