include "include\ATJ2085_Ports.inc"
org 0
defs 0x800
start:
ld a,0
ld (0x27),a
ld a,0x1f ;MFP_SELECT_CS0S|GPOA2_ENABLE|GPOA2_OUTPUT_2|GPOA2_OUTPUT_1|GPOA2_OUTPUT_0
out (MFP_GPOA_SELECT_REG),a
ld a, EM_PAGE_HI_CE3_INV ; for output to the lcd
out (EM_PAGE_HI_REG),a
ld a,0
out (WATCHDOG_REG),a ; disable watchdog
ld sp,lastl ; set stack
di
im 1
ld hl,misrstart
ld de,0x0038
ld bc,misrend-misrstart
ldir
ld hl,nmisrstart
ld de,0x0066
ld bc,nmisrend-nmisrstart
ldir
ei ; enabling interrupts freezes the player
ld a,00
out (LOSC_DIV_LO_REG),a
out (LOSC_DIV_MI_REG),a
out (LOSC_DIV_HI_REG),a ;
ld a,MINT_ENABLE_RTC
out (MINT_ENABLE_REG),a
hang:
ld a,0xff
ld (0x8000),a
jr hang
misrstart:
push af
push bc
push de
push hl
push ix
in a, (MINT_STATUS_REG)
bit 5, a
call nz, RTC_ISR
pop ix
pop hl
pop de
pop bc
pop af
ei
reti
misrend:
nmisrstart:
reti
nmisrend:
.RTC_TimerTicks defw 0
RTC_ISR:
in a,(RTC_IRQSTATUS_REG)
bit 2,a
jp nz, rtcisr_alarm
bit 1,a
jp nz, rtcisr_timer
bit 0,a
jp nz, rtcisr_2hz
rtcisr_alarm:
; Nothing to do with this interrupt yet!
ld a, RTC_IRQSTATUS_RTC_ALARM_IRQ
jp rtcisr_end
rtcisr_timer:
; increment rtc_timerticks
ld hl,(RTC_TimerTicks)
inc hl
ld (RTC_TimerTicks),hl
; call RS232_isr
ld a, RTC_IRQSTATUS_RTC_TIMER_IRQ
jp rtcisr_end
rtcisr_2hz:
ld hl,(RTC_TimerTicks)
inc hl
ld (RTC_TimerTicks),hl
bit 4, l
jr z, rtcisr_2hz_clearint
rtcisr_2hz_stopint:
; Enable the Xtal Oscillator
in a, (RTC_IRQSTATUS_REG)
or a, RTC_IRQSTATUS_CLK_SOURCE
out (RTC_IRQSTATUS_REG),a
; Disable the 2Hz interrupt and enable the timer interrupt
ld a, RTC_CONTROL_TIMER_ENABLE
out (RTC_CONTROL_REG),a
rtcisr_2hz_clearint:
ld a, RTC_IRQSTATUS_2HZ_IRQ
rtcisr_end:
; Reset the IRQ
out (RTC_IRQSTATUS_REG),a
ret
defs 1000
lastl: