improved cx16 emudbg library

This commit is contained in:
Irmen de Jong 2023-11-17 15:07:21 +01:00
parent 161c02ced3
commit faf05582f8
3 changed files with 65 additions and 27 deletions

View File

@ -24,39 +24,34 @@ emudbg {
sub is_emulator() -> bool {
; Test for emulator presence.
; It is recommended to only use the other debug routines if this returns true.
; It is recommended to only use the debug registers if this returns true.
return EMU_EMU_DETECT1=='1' and EMU_EMU_DETECT2=='6'
}
asmsub console_write(str isoString @R0) clobbers(Y) {
sub console_write(str isoString) {
; note: make sure the text is in Iso encoding.
%asm {{
ldy #0
- lda (cx16.r0),y
beq +
sta p8_EMU_CPUCLK_U
iny
bne -
+
}}
if is_emulator() {
cx16.r1 = isoString
while @(cx16.r1) {
EMU_CPUCLK_U = @(cx16.r1)
cx16.r1++
}
}
}
asmsub console_chrout(ubyte char @A) {
sub console_chrout(ubyte char) {
; note: make sure the character is in Iso encoding.
%asm {{
sta p8_EMU_CPUCLK_U
}}
if is_emulator()
EMU_CPUCLK_U = char
}
asmsub console_value1(ubyte value @A) {
%asm {{
sta p8_EMU_CPUCLK_M
}}
sub console_value1(ubyte value) {
if is_emulator()
EMU_CPUCLK_M = value
}
asmsub console_value2(ubyte value @A) {
%asm {{
sta p8_EMU_CPUCLK_H
}}
sub console_value2(ubyte value) {
if is_emulator()
EMU_CPUCLK_H = value
}
}

View File

@ -0,0 +1,34 @@
; Emulator debug interface. (reflecting the Commander X16 emudbg library module)
; Docs: https://github.com/X16Community/x16-emulator#emulator-io-registers
%import textio
emudbg {
sub is_emulator() -> bool {
; Test for emulator presence.
return true ; VM is always 'emulator'
}
sub console_write(str message) {
txt.print("[EMUDBG: ")
txt.print(message)
txt.chrout(']')
}
sub console_chrout(ubyte char) {
txt.chrout(char)
}
sub console_value1(ubyte value) {
txt.print("[EMUDBG debug 1: ")
txt.print_uwhex(value, true)
txt.print("]\n")
}
sub console_value2(ubyte value) {
txt.print("[EMUDBG debug 2: ")
txt.print_uwhex(value, true)
txt.print("]\n")
}
}

View File

@ -1,12 +1,21 @@
%zeropage basicsafe
%import textio
%import emudbg
main {
sub start() {
str name="irmen"
if name=="." {
cx16.r0++
}
txt.print("is emulator? ")
txt.print_ub(emudbg.is_emulator())
txt.nl()
emudbg.console_write(iso:"Hello from emulator.\n")
emudbg.console_chrout(iso:'1')
emudbg.console_chrout(iso:'2')
emudbg.console_chrout(iso:'3')
emudbg.console_chrout(iso:'\n')
emudbg.console_value1(123)
emudbg.console_chrout(iso:'\n')
emudbg.console_value2(42)
emudbg.console_chrout(iso:'\n')
}
}