mirror of
https://github.com/irmen/prog8.git
synced 2025-02-19 11:31:07 +00:00
improved cx16 emudbg library
This commit is contained in:
parent
161c02ced3
commit
faf05582f8
@ -24,39 +24,34 @@ emudbg {
|
|||||||
|
|
||||||
sub is_emulator() -> bool {
|
sub is_emulator() -> bool {
|
||||||
; Test for emulator presence.
|
; 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'
|
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.
|
; note: make sure the text is in Iso encoding.
|
||||||
%asm {{
|
if is_emulator() {
|
||||||
ldy #0
|
cx16.r1 = isoString
|
||||||
- lda (cx16.r0),y
|
while @(cx16.r1) {
|
||||||
beq +
|
EMU_CPUCLK_U = @(cx16.r1)
|
||||||
sta p8_EMU_CPUCLK_U
|
cx16.r1++
|
||||||
iny
|
}
|
||||||
bne -
|
}
|
||||||
+
|
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub console_chrout(ubyte char @A) {
|
sub console_chrout(ubyte char) {
|
||||||
; note: make sure the character is in Iso encoding.
|
; note: make sure the character is in Iso encoding.
|
||||||
%asm {{
|
if is_emulator()
|
||||||
sta p8_EMU_CPUCLK_U
|
EMU_CPUCLK_U = char
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub console_value1(ubyte value @A) {
|
sub console_value1(ubyte value) {
|
||||||
%asm {{
|
if is_emulator()
|
||||||
sta p8_EMU_CPUCLK_M
|
EMU_CPUCLK_M = value
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
asmsub console_value2(ubyte value @A) {
|
sub console_value2(ubyte value) {
|
||||||
%asm {{
|
if is_emulator()
|
||||||
sta p8_EMU_CPUCLK_H
|
EMU_CPUCLK_H = value
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
compiler/res/prog8lib/virtual/emudbg.p8
Normal file
34
compiler/res/prog8lib/virtual/emudbg.p8
Normal 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")
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,21 @@
|
|||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
%import textio
|
%import textio
|
||||||
|
%import emudbg
|
||||||
|
|
||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
str name="irmen"
|
txt.print("is emulator? ")
|
||||||
if name=="." {
|
txt.print_ub(emudbg.is_emulator())
|
||||||
cx16.r0++
|
|
||||||
}
|
|
||||||
txt.nl()
|
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')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user