tweaking program startup and cleanup stuff

This commit is contained in:
Irmen de Jong 2024-11-05 21:12:27 +01:00
parent 7fd3e9bb7d
commit a5c7393561
7 changed files with 447 additions and 494 deletions

View File

@ -99,8 +99,8 @@ internal class ProgramAndVarsGen(
asmgen.out(" tsx ; save stackpointer for sys.exit()")
asmgen.out(" stx prog8_lib.orig_stackpointer")
if(!options.noSysInit)
asmgen.out(" jsr sys.init_system")
asmgen.out(" jsr sys.init_system_phase2")
asmgen.out(" jsr p8_sys_startup.init_system")
asmgen.out(" jsr p8_sys_startup.init_system_phase2")
}
OutputType.PRG -> {
when(options.launcher) {
@ -119,8 +119,8 @@ internal class ProgramAndVarsGen(
asmgen.out(" tsx ; save stackpointer for sys.exit()")
asmgen.out(" stx prog8_lib.orig_stackpointer")
if(!options.noSysInit)
asmgen.out(" jsr sys.init_system")
asmgen.out(" jsr sys.init_system_phase2")
asmgen.out(" jsr p8_sys_startup.init_system")
asmgen.out(" jsr p8_sys_startup.init_system_phase2")
}
CbmPrgLauncherType.NONE -> {
// this is the same as RAW
@ -130,8 +130,8 @@ internal class ProgramAndVarsGen(
asmgen.out(" tsx ; save stackpointer for sys.exit()")
asmgen.out(" stx prog8_lib.orig_stackpointer")
if(!options.noSysInit)
asmgen.out(" jsr sys.init_system")
asmgen.out(" jsr sys.init_system_phase2")
asmgen.out(" jsr p8_sys_startup.init_system")
asmgen.out(" jsr p8_sys_startup.init_system_phase2")
}
}
}
@ -142,8 +142,8 @@ internal class ProgramAndVarsGen(
asmgen.out(" tsx ; save stackpointer for sys.exit()")
asmgen.out(" stx prog8_lib.orig_stackpointer")
if(!options.noSysInit)
asmgen.out(" jsr sys.init_system")
asmgen.out(" jsr sys.init_system_phase2")
asmgen.out(" jsr p8_sys_startup.init_system")
asmgen.out(" jsr p8_sys_startup.init_system_phase2")
}
}
@ -161,21 +161,19 @@ internal class ProgramAndVarsGen(
if(options.floats)
asmgen.out(" lda #4 | sta $01") // to use floats, make sure Basic rom is banked in
asmgen.out(" jsr p8b_main.p8s_start")
asmgen.out(" jmp sys.cleanup_at_exit")
asmgen.out(" jmp p8_sys_startup.cleanup_at_exit")
}
"c64" -> {
asmgen.out(" jsr p8b_main.p8s_start")
asmgen.out(" lda #31 | sta $01")
asmgen.out(" jmp sys.cleanup_at_exit")
asmgen.out(" jmp p8_sys_startup.cleanup_at_exit")
}
"c128" -> {
asmgen.out(" jsr p8b_main.p8s_start")
asmgen.out(" lda #0 | sta ${"$"}ff00")
asmgen.out(" jmp sys.cleanup_at_exit")
asmgen.out(" jmp p8_sys_startup.cleanup_at_exit")
}
else -> {
asmgen.out(" jsr p8b_main.p8s_start")
asmgen.out(" jmp sys.cleanup_at_exit")
asmgen.out(" jmp p8_sys_startup.cleanup_at_exit")
}
}
}

View File

@ -30,43 +30,6 @@ sys {
const ubyte sizeof_uword = 2
const ubyte sizeof_float = 0 ; undefined, no float support
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
; TODO
%asm {{
sei
; TODO reset screen mode etc etc
cli
rts
}}
}
asmsub init_system_phase2() {
%asm {{
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
asmsub reset_system() {
; Soft-reset the system back to initial power-on Basic prompt.
; TODO
@ -332,37 +295,37 @@ save_SCRATCH_ZPWORD2 .word 0
asmsub exit(ubyte returnvalue @A) {
; -- immediately exit the program with a return code in the A register
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit2(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y) {
; -- immediately exit the program with result values in the A, X and Y registers.
%asm {{
sta cleanup_at_exit._exitcode
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcode
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit3(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y, bool carry @Pc) {
; -- immediately exit the program with result values in the A, X and Y registers, and the Carry flag in the status register.
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
lda #0
rol a
sta cleanup_at_exit._exitcodeCarry
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcodeCarry
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
@ -542,3 +505,44 @@ cx16 {
}
}
p8_sys_startup {
; program startup and shutdown machinery. Needs to reside in normal system ram.
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
; TODO
%asm {{
sei
; TODO reset screen mode etc etc
cli
rts
}}
}
asmsub init_system_phase2() {
%asm {{
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
}

View File

@ -412,80 +412,13 @@ sys {
const ubyte sizeof_float = 5
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
; This means that the BASIC, KERNAL and CHARGEN ROMs are banked in,
; the VIC, SID and CIA chips are reset, screen is cleared, and the default IRQ is set.
; Also a different color scheme is chosen to identify ourselves a little.
; Uppercase charset is activated.
%asm {{
sei
lda #0
sta $ff00 ; select default bank 15
jsr cbm.IOINIT
jsr cbm.RESTOR
jsr cbm.CINT
lda #6
sta c64.EXTCOL
lda #7
sta cbm.COLOR
lda #0
sta c64.BGCOL0
jsr disable_runstop_and_charsetswitch
cli
rts
}}
}
sub disable_runstop_and_charsetswitch() {
p8_sys_startup.disable_runstop_and_charsetswitch()
}
asmsub init_system_phase2() {
%asm {{
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
lda #0
sta $ff00 ; default bank 15
jsr cbm.CLRCHN ; reset i/o channels
jsr enable_runstop_and_charsetswitch
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
asmsub disable_runstop_and_charsetswitch() clobbers(A) {
%asm {{
lda #$80
sta 247 ; disable charset switching
lda #112
sta 808 ; disable run/stop key
rts
}}
}
asmsub enable_runstop_and_charsetswitch() clobbers(A) {
%asm {{
lda #0
sta 247 ; enable charset switching
lda #110
sta 808 ; enable run/stop key
rts
}}
}
sub enable_runstop_and_charsetswitch() {
p8_sys_startup.enable_runstop_and_charsetswitch()
}
asmsub save_prog8_internals() {
%asm {{
@ -899,37 +832,37 @@ _no_msb_size
asmsub exit(ubyte returnvalue @A) {
; -- immediately exit the program with a return code in the A register
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit2(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y) {
; -- immediately exit the program with result values in the A, X and Y registers.
%asm {{
sta cleanup_at_exit._exitcode
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcode
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit3(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y, bool carry @Pc) {
; -- immediately exit the program with result values in the A, X and Y registers, and the Carry flag in the status register.
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
lda #0
rol a
sta cleanup_at_exit._exitcodeCarry
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcodeCarry
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
@ -1110,3 +1043,83 @@ cx16 {
}
}
p8_sys_startup {
; program startup and shutdown machinery. Needs to reside in normal system ram.
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
; This means that the BASIC, KERNAL and CHARGEN ROMs are banked in,
; the VIC, SID and CIA chips are reset, screen is cleared, and the default IRQ is set.
; Also a different color scheme is chosen to identify ourselves a little.
; Uppercase charset is activated.
%asm {{
sei
lda #0
sta $ff00 ; select default bank 15
jsr cbm.IOINIT
jsr cbm.RESTOR
jsr cbm.CINT
lda #6
sta c64.EXTCOL
lda #7
sta cbm.COLOR
lda #0
sta c64.BGCOL0
jsr disable_runstop_and_charsetswitch
cli
rts
}}
}
asmsub init_system_phase2() {
%asm {{
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
lda #0
sta $ff00 ; default bank 15
jsr cbm.CLRCHN ; reset i/o channels
jsr enable_runstop_and_charsetswitch
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
asmsub disable_runstop_and_charsetswitch() clobbers(A) {
%asm {{
lda #$80
sta 247 ; disable charset switching
lda #112
sta 808 ; disable run/stop key
rts
}}
}
asmsub enable_runstop_and_charsetswitch() clobbers(A) {
%asm {{
lda #0
sta 247 ; enable charset switching
lda #110
sta 808 ; enable run/stop key
rts
}}
}
}

View File

@ -441,97 +441,13 @@ sys {
const ubyte sizeof_uword = 2
const ubyte sizeof_float = 5
sub disable_runstop_and_charsetswitch() {
p8_sys_startup.disable_runstop_and_charsetswitch()
}
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
; This means that the KERNAL and CHARGEN ROMs are banked in,
; BASIC ROM is NOT banked in (so we have another 8Kb of RAM at our disposal),
; the VIC, SID and CIA chips are reset, screen is cleared, and the default IRQ is set.
; Also a different color scheme is chosen to identify ourselves a little.
; Uppercase charset is activated.
%asm {{
sei
lda #%00101111
sta $00
lda #%00100110 ; kernal and i/o banked in
sta $01
jsr cbm.IOINIT
jsr cbm.RESTOR
jsr cbm.CINT
lda #6
sta c64.EXTCOL
lda #7
sta cbm.COLOR
lda #0
sta c64.BGCOL0
jsr disable_runstop_and_charsetswitch
lda #PROG8_C64_BANK_CONFIG ; apply bank config
sta $01
and #1
bne +
; basic is not banked in, adjust MEMTOP
ldx #<$d000
ldy #>$d000
clc
jsr cbm.MEMTOP
+ cli
rts
}}
}
asmsub init_system_phase2() {
%asm {{
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
lda #31
sta $01 ; bank the kernal and basic in
ldx #<$a000
ldy #>$a000
clc
jsr cbm.MEMTOP ; adjust MEMTOP down again
jsr cbm.CLRCHN ; reset i/o channels
jsr enable_runstop_and_charsetswitch
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
asmsub disable_runstop_and_charsetswitch() clobbers(A) {
%asm {{
lda #$80
sta 657 ; disable charset switching
lda #239
sta 808 ; disable run/stop key
rts
}}
}
asmsub enable_runstop_and_charsetswitch() clobbers(A) {
%asm {{
lda #0
sta 657 ; enable charset switching
lda #237
sta 808 ; enable run/stop key
rts
}}
}
sub enable_runstop_and_charsetswitch() {
p8_sys_startup.enable_runstop_and_charsetswitch()
}
asmsub save_prog8_internals() {
%asm {{
@ -946,37 +862,37 @@ _no_msb_size
asmsub exit(ubyte returnvalue @A) {
; -- immediately exit the program with a return code in the A register
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit2(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y) {
; -- immediately exit the program with result values in the A, X and Y registers.
%asm {{
sta cleanup_at_exit._exitcode
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcode
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit3(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y, bool carry @Pc) {
; -- immediately exit the program with result values in the A, X and Y registers, and the Carry flag in the status register.
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
lda #0
rol a
sta cleanup_at_exit._exitcodeCarry
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcodeCarry
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
@ -1157,3 +1073,101 @@ cx16 {
}
}
p8_sys_startup {
; program startup and shutdown machinery. Needs to reside in normal system ram.
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
; This means that the KERNAL and CHARGEN ROMs are banked in,
; BASIC ROM is NOT banked in (so we have another 8Kb of RAM at our disposal),
; the VIC, SID and CIA chips are reset, screen is cleared, and the default IRQ is set.
; Also a different color scheme is chosen to identify ourselves a little.
; Uppercase charset is activated.
%asm {{
sei
lda #%00101111
sta $00
lda #%00100110 ; kernal and i/o banked in, basic off
sta $01
jsr cbm.IOINIT
jsr cbm.RESTOR
jsr cbm.CINT
lda #6
sta c64.EXTCOL
lda #7
sta cbm.COLOR
lda #0
sta c64.BGCOL0
jsr disable_runstop_and_charsetswitch
lda #PROG8_C64_BANK_CONFIG ; apply bank config
sta $01
and #1
bne +
; basic is not banked in, adjust MEMTOP
ldx #<$d000
ldy #>$d000
clc
jsr cbm.MEMTOP
+ cli
rts
}}
}
asmsub init_system_phase2() {
%asm {{
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
lda #%00101111
sta $00
lda #31
sta $01 ; bank the kernal and basic in
ldx #<$a000
ldy #>$a000
clc
jsr cbm.MEMTOP ; adjust MEMTOP down again
jsr cbm.CLRCHN ; reset i/o channels
jsr enable_runstop_and_charsetswitch
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
asmsub disable_runstop_and_charsetswitch() clobbers(A) {
%asm {{
lda #$80
sta 657 ; disable charset switching
lda #239
sta 808 ; disable run/stop key
rts
}}
}
asmsub enable_runstop_and_charsetswitch() clobbers(A) {
%asm {{
lda #0
sta 657 ; enable charset switching
lda #237
sta 808 ; enable run/stop key
rts
}}
}
}

View File

@ -1381,90 +1381,6 @@ sys {
const ubyte sizeof_uword = 2
const ubyte sizeof_float = 5
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
%asm {{
sei
lda #0
tax
tay
jsr cx16.mouse_config ; disable mouse
lda cx16.VERA_DC_VIDEO
and #%00000111 ; retain chroma + output mode
sta P8ZP_SCRATCH_REG
lda #$0a
sta $01 ; rom bank 10 (audio)
jsr cx16.audio_init ; silence
stz $01 ; rom bank 0 (kernal)
jsr cbm.IOINIT
jsr cbm.RESTOR
jsr cbm.CINT
lda cx16.VERA_DC_VIDEO
and #%11111000
ora P8ZP_SCRATCH_REG
sta cx16.VERA_DC_VIDEO ; restore old output mode
lda #$90 ; black
jsr cbm.CHROUT
lda #1
jsr cbm.CHROUT ; swap fg/bg
lda #$9e ; yellow
jsr cbm.CHROUT
lda #147 ; clear screen
jsr cbm.CHROUT
lda #8 ; disable charset case switch
jsr cbm.CHROUT
lda #PROG8_VARSHIGH_RAMBANK
sta $00 ; select ram bank
lda #0
sta $01 ; set ROM bank to kernal bank to speed up kernal calls
tax
tay
cli
rts
}}
}
asmsub init_system_phase2() {
%asm {{
sei
lda cbm.CINV
sta restore_irq._orig_irqvec
lda cbm.CINV+1
sta restore_irq._orig_irqvec+1
lda #PROG8_VARSHIGH_RAMBANK
sta $00 ; select ram bank
stz $01 ; set ROM bank to kernal bank to speed up kernal calls
cli
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
lda #1
sta $00 ; ram bank 1
lda #4
sta $01 ; rom bank 4 (basic)
stz $2d ; hack to reset machine code monitor bank to 0
jsr cbm.CLRCHN ; reset i/o channels
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
asmsub set_irq(uword handler @AY) clobbers(A) {
; Sets the handler for the VSYNC interrupt, and enable that interrupt.
%asm {{
@ -1865,37 +1781,37 @@ save_SCRATCH_ZPWORD2 .word 0
asmsub exit(ubyte returnvalue @A) {
; -- immediately exit the program with a return code in the A register
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit2(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y) {
; -- immediately exit the program with result values in the A, X and Y registers.
%asm {{
sta cleanup_at_exit._exitcode
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcode
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit3(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y, bool carry @Pc) {
; -- immediately exit the program with result values in the A, X and Y registers, and the Carry flag in the status register.
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
lda #0
rol a
sta cleanup_at_exit._exitcodeCarry
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcodeCarry
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
@ -1933,3 +1849,92 @@ save_SCRATCH_ZPWORD2 .word 0
}
}
p8_sys_startup {
; program startup and shutdown machinery. Needs to reside in normal system ram.
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
%asm {{
sei
lda #0
tax
tay
jsr cx16.mouse_config ; disable mouse
lda cx16.VERA_DC_VIDEO
and #%00000111 ; retain chroma + output mode
sta P8ZP_SCRATCH_REG
lda #$0a
sta $01 ; rom bank 10 (audio)
jsr cx16.audio_init ; silence
stz $01 ; rom bank 0 (kernal)
jsr cbm.IOINIT
jsr cbm.RESTOR
jsr cbm.CINT
lda cx16.VERA_DC_VIDEO
and #%11111000
ora P8ZP_SCRATCH_REG
sta cx16.VERA_DC_VIDEO ; restore old output mode
lda #$90 ; black
jsr cbm.CHROUT
lda #1
jsr cbm.CHROUT ; swap fg/bg
lda #$9e ; yellow
jsr cbm.CHROUT
lda #147 ; clear screen
jsr cbm.CHROUT
lda #8 ; disable charset case switch
jsr cbm.CHROUT
lda #PROG8_VARSHIGH_RAMBANK
sta $00 ; select ram bank
lda #0
sta $01 ; set ROM bank to kernal bank to speed up kernal calls
tax
tay
cli
rts
}}
}
asmsub init_system_phase2() {
%asm {{
sei
lda cbm.CINV
sta sys.restore_irq._orig_irqvec
lda cbm.CINV+1
sta sys.restore_irq._orig_irqvec+1
lda #PROG8_VARSHIGH_RAMBANK
sta $00 ; select ram bank
stz $01 ; set ROM bank to kernal bank to speed up kernal calls
cli
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
lda #1
sta $00 ; ram bank 1
lda #4
sta $01 ; rom bank 4 (basic)
stz $2d ; hack to reset machine code monitor bank to 0
jsr cbm.CLRCHN ; reset i/o channels
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
}

View File

@ -106,46 +106,6 @@ sys {
const ubyte sizeof_float = 0 ; undefined, no floats supported
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
; Uppercase charset is activated.
%asm {{
sei
lda #142
jsr cbm.CHROUT ; uppercase
lda #147
jsr cbm.CHROUT ; clear screen
cli
rts
}}
}
asmsub init_system_phase2() {
%asm {{
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
asmsub reset_system() {
; Soft-reset the system back to initial power-on Basic prompt.
%asm {{
@ -434,37 +394,37 @@ save_SCRATCH_ZPWORD2 .word 0
asmsub exit(ubyte returnvalue @A) {
; -- immediately exit the program with a return code in the A register
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit2(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y) {
; -- immediately exit the program with result values in the A, X and Y registers.
%asm {{
sta cleanup_at_exit._exitcode
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcode
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
asmsub exit3(ubyte resulta @A, ubyte resultx @X, ubyte resulty @Y, bool carry @Pc) {
; -- immediately exit the program with result values in the A, X and Y registers, and the Carry flag in the status register.
%asm {{
sta cleanup_at_exit._exitcode
sta p8_sys_startup.cleanup_at_exit._exitcode
lda #0
rol a
sta cleanup_at_exit._exitcodeCarry
stx cleanup_at_exit._exitcodeX
sty cleanup_at_exit._exitcodeY
sta p8_sys_startup.cleanup_at_exit._exitcodeCarry
stx p8_sys_startup.cleanup_at_exit._exitcodeX
sty p8_sys_startup.cleanup_at_exit._exitcodeY
ldx prog8_lib.orig_stackpointer
txs
jmp cleanup_at_exit
jmp p8_sys_startup.cleanup_at_exit
}}
}
@ -645,3 +605,48 @@ cx16 {
}
}
p8_sys_startup {
; program startup and shutdown machinery. Needs to reside in normal system ram.
asmsub init_system() {
; Initializes the machine to a sane starting state.
; Called automatically by the loader program logic.
; Uppercase charset is activated.
%asm {{
sei
lda #142
jsr cbm.CHROUT ; uppercase
lda #147
jsr cbm.CHROUT ; clear screen
cli
rts
}}
}
asmsub init_system_phase2() {
%asm {{
cld
clc
clv
rts
}}
}
asmsub cleanup_at_exit() {
; executed when the main subroutine does rts
%asm {{
_exitcodeCarry = *+1
lda #0
lsr a
_exitcode = *+1
lda #0 ; exit code possibly modified in exit()
_exitcodeX = *+1
ldx #0
_exitcodeY = *+1
ldy #0
rts
}}
}
}

View File

@ -1,109 +1,23 @@
%import textio
%zeropage basicsafe
%option no_sysinit
main {
romsub @bank %100 $f800 = routine_in_kernal_addr_space(uword arg @AY) -> uword @AY
; ^-- I/O enabled, basic and kernal roms banked out
sub start() {
; copy the routine into kernal area address space
sys.memcopy(&the_invert_routine, $f800, 255)
cx16.r0 = the_invert_routine(12345)
txt.print("inverted (normal)=")
txt.print_uw(cx16.r0)
txt.nl()
cx16.r0 = routine_in_kernal_addr_space(12345)
txt.print("inverted (kernal space)=")
txt.print_uw(cx16.r0)
txt.nl()
txt.print("inverted (callfar)=")
cx16.r0=callfar(%100, $f800, 12345)
txt.print_uw(cx16.r0)
txt.nl()
txt.print("inverted (callfar2)=")
cx16.r0=callfar2(%100, $f800, 57, 0, 48, false)
txt.print_uw(cx16.r0)
txt.nl()
}
asmsub the_invert_routine(uword arg @AY) -> uword @AY {
%asm {{
eor #$ff
pha
tya
eor #$ff
tay
pla
rts
}}
basic_area.routine1()
}
}
;main {
; sub start() {
; basic_area.routine1()
; hiram_area.routine2()
;
; ; copy the kernal area routine to actual kernal address space $f800
; sys.memcopy(&kernal_area.routine3, $f800, 255)
;
; ; how to call the routine using manual bank switching:
; ; c64.banks(%101) ; bank out kernal rom
; ; call($f800) ; call our routine
; ; c64.banks(%111) ; kernal back
;
; ; how to use prog8's automatic bank switching:
; romsub @bank %101 $f800 = kernal_routine()
;
; kernal_routine()
;
; txt.print("done!\n")
; }
;}
;
;kernal_area {
; ; this routine is actually copied to kernal address space first
; ; we cannot use CHROUT when the kernal is banked out so we write to the screen directly
; asmsub routine3() {
; %asm {{
; lda #<_message
; ldy #>_message
; sta $fe
; sty $ff
; ldy #0
;- lda ($fe),y
; beq +
; sta $0400+240,y
; iny
; bne -
;+ rts
;
;_message
; .enc 'screen'
; .text "hello from kernal area $f800",0
; .enc 'none'
; ; !notreached!
; }}
; }
;}
;
;
;basic_area $a000 {
; sub routine1() {
; txt.print("hello from basic rom area ")
; txt.print_uwhex(&routine1, true)
; txt.nl()
; }
;}
;
;hiram_area $ca00 {
; sub routine2() {
; txt.print("hello from hiram area ")
; txt.print_uwhex(&routine2, true)
; txt.nl()
; }
;}
;
basic_area $a000 {
sub routine1() {
txt.print("hello from basic rom area ")
txt.print_uwhex(&routine1, true)
txt.nl()
}
}
hiram_area $c000 {
%option force_output
sub thing() {
cx16.r0++
}
}