epaell wrote: ↑Mon Jul 15, 2024 11:11 am
After a lot of head-scratching (mainly me fighting with the 6840 documentation, fighting with how to do things with a 6502, and then fighting with SMON) I finally got something that works:
Greetings Emil,
I took your PTM code and massaged it to work with Assis09 in MAIM.
I actually built it into the Assis09 / DISASM rom i've built with the verified version of Assist09 and the stock DISASM (No alternative trace) that been testing. This has one small change to move the second command table into the DISASM code area.
I'm using the VCTRSW function to override the ASSIS09 IQR service routine but leaving the PTM initialisation and overwriting it with my own.
Terminal output uses the OUTCH service, Output can be paused with ctrl-x
Notable discovery was that some of Assist09 SWI services actually clear the interrupt mask.
The clocks input of the simulation causes some other interrupt flag bit to be set (I think)
Now that I know that IRQ is working I'll switch my attention to the NMI testing.
The code should be self contained apart from using some Assis09 definitions.
It uses two org statements one for code, the other for ram data.
I'll take this as a starting place to build some code which drives the NMI via the o1 pin
I know a bit more about the PTM now ...
Kind regards, David.
Code: Select all
; 6840 PTR Interrupt demo for Assis09 rom
; demo to generate cyclic interrupt from 6840 and bump a counter in memory
; after initialisation a separate function display the memory content value increasing
timer_val equ $f000 ; timer 1 count setting
timer_set equ $0142 ; Preset all timers a=$01, b=$42 CRX6=1 (interrupt); CRX1=1 (enable clock)
org $b100
;
timer1 equ *
org *+2
timer2 equ *
org *+2
timer3 equ *
org *+4
;
tick0 equ *
org *+1
tick1 equ *
org *+1
tick2 equ *
org *+1
tick3 equ *
org *+1
ORG $Ec00
LEAX isr,PCR ; LOAD NEW IRQ HANDLER ADDRESS
lda #_IRQ
swi
fcb VCTRSW
lda #'S'
jsr outch ; Write an "S" to indicate program started
jsr ptm_init ; Initialise the PTM
andcc #~$10 ; Enable interrupts
; rts
loop
; andcc #~$10 ; Enable interrupts
lda #$0d
jsr outch
lda #$0a
jsr outch
lda #'0' ; Write the current tick count
jsr outch
lda #'x'
jsr outch
lda tick3
ldb tick2
jsr out4h
lda tick1
ldb tick0
jsr out4h
lda #'<' ; Write the current tick count
jsr outch
pshs cc
swi ; clobbers irq mask
fcb 11 ; check for ctrl-x
tfr cc,a
puls cc
anda #1
beq loop ; unless ctrl-x pressed
swi2
bra loop
rts ; then return to assis09
ptm_init
ldd #timer_val
std PTMTM1
ldd #timer_set ; Preset all timers a=$01, b=$42 CRX6=1 (interrupt); CRX1=1 (enable clock)
sta PTMC2 ; Write to CR1
stb PTMC13
clr PTMC2
CLR tick0 ; Reset the tick counter
CLR tick1
CLR tick2
CLR tick3
lda PTMSTA ; Read the interrupt flag from the status register
lda #$40
sta PTMC13 ; enable interrupt and start timer
rts
isr
lda PTMSTA ; Read the interrupt flag from the status register
ldx PTMTM1 ; clear timer interrupt flag
stx timer1
lda PTMSTA ; Read the interrupt flag from the status register
ldx PTMTM2
stx timer2
lda PTMSTA ; Read the interrupt flag from the status register
ldx PTMTM3
stx timer2
lda tick0
adca #$01
sta tick0
lda tick1
adca #$00
sta tick1
lda tick2
adca #$00
sta tick2
lda tick3
adca #$00
sta tick3
rti
out4h ; output as hex digits contents of D register
ZF90E PSHS D ; pr xxxx
BSR ZF91A
EXG B,A
BSR ZF91A
PULS PC,D
ZF91A PSHS A ; pr aa
ASRA
ASRA
ASRA
ASRA
BSR ZF924
PULS A
ZF924 ANDA #$0F ; pr x
CMPA #$0A
BCS ZF92C
ADDA #$07
ZF92C ADDA #$30
outch
pshs cc ; preserve irq mask which is set by assis09
SWI ; Call ASSIST09 monitor function
FCB OUTCH ; Service code byte
puls cc
RTS