// ================================
//	Samarium
//		LED 3-3-7 beats for Shrike-Lite
//		(c) 2026	1YEN Toru
//
//
//		2026/04/18	ver.1.00
//
// ================================
asm		"shrk_blink_337.v"
#asm		"mcoc_irom.mem"
incl	"mcoc115.incl"
# ================================
# constants
equ		fcpu_go,12_000_000				// [Hz]
equ		msec_onebt,400					// one beat length [ms]
equ		sim_flg,0x0100					// CPU_STS: simulation mode bit
equ		led_on,0x01						// LED ON
equ		led_off,0x00					// LED OFF
# ================================


// ================================
// go to main
// ================================
push	STK_SIZ
pop
jmp		main


// ================================
// delay: <delay_ms>,<return_addr>
// ================================
delay:
// parameter
swap
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// for simulation
and		CPU_STS,sim_flg
njmp	sim_not_enb
lsl
cend
and		0xff
sim_not_enb:
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// delay loop
dly_loop:
// loop break condition
dupl
njmp	dly_loop_break

// 1ms loop
equ		dly_loop_cyc,14					// 14 cycles per loop
push	fcpu_go/1_000/dly_loop_cyc		// 1ms/(1/fcpu_go)/dly_loop_cyc
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// for simulation
and		CPU_STS,sim_flg
njmp	sim_not_2
pop
push	1
sim_not_2:
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
dly_loop_1ms:
// loop_1ms break condition
dupl
njmp	dly_loop_1ms_break
// end of loop_1ms
sub		1
jmp		dly_loop_1ms
dly_loop_1ms_break:
pop

// end of loop
sub		1
jmp		dly_loop
dly_loop_break:
pop
// end of subroutine
rtn

// ================================
// led_1_beat
// ================================
led_1_beat:
stw		led_on,porout
delay*	msec_onebt/2
stw		led_off,porout
delay*	msec_onebt/2
rtn


// ================================
// initialize
// ================================
main:
// PORT8I8O setting
stw		0x07,pordir
stw		led_off,porout
pushf	1_000
delay*

// ================================
// 3-3-7 beats
// ================================
loop:
// 3 beats
led_1_beat*
led_1_beat*
led_1_beat*
delay*	msec_onebt
// 3 beats
led_1_beat*
led_1_beat*
led_1_beat*
delay*	msec_onebt
// 7 beats
led_1_beat*
led_1_beat*
led_1_beat*
led_1_beat*
led_1_beat*
led_1_beat*
led_1_beat*
delay*	msec_onebt
jmp		loop

// ================================
// to avoid x value fetch
// ================================
nop

