;	GCC For the Hitachi H8/300
;	By Hitachi America Ltd and Cygnus Support
;	release F-1
; -O2


	.file	"RunInt.c"
	.global _RCX_string
	.section .rodata
.LC0:
	.ascii "Do you byte, when I knock?\0"
	.section .data
	.align 1
_RCX_string:
	.word .LC0
	.section .text
	.align 1
	.global _RCX_Reset
_RCX_Reset:
	push	r6
	mov.w	r7,r6
; #APP
	 jmp @@0
; #NO_APP
	pop	r6
	rts
	.align 1
	.global _Enable
_Enable:
	push	r6
	mov.w	r7,r6
; #APP
	 andc #0x7f, ccr 
; #NO_APP
	pop	r6
	rts
	.align 1
	.global _Disable
_Disable:
	push	r6
	mov.w	r7,r6
; #APP
	 orc  #0x80, ccr 
; #NO_APP
	pop	r6
	rts
	.align 1
	.global _BusyPauseMS
_BusyPauseMS:
	push	r6
	mov.w	r7,r6
	mov.w	r0,r0
	beq	.L7
	mov.w	#659,r3
.L8:
	sub.w	r2,r2
	subs #1,r0
.L11:
	adds #1,r2
	cmp.w	r3,r2
	bls	.L11
	mov.w	r0,r0
	bne	.L8
.L7:
	pop	r6
	rts
	.align 1
	.global _lcd_refresh
_lcd_refresh:
	push	r6
	mov.w	r7,r6
; #APP
	jsr 0x27c8      ; call refresh
      
; #NO_APP
	pop	r6
	rts
	.align 1
	.global _lcd_clear
_lcd_clear:
	push	r6
	mov.w	r7,r6
; #APP
	jsr 0x27ac      ; call clear
       jsr 0x27c8      ; call refresh
      
; #NO_APP
	pop	r6
	rts
	.align 1
	.global _lcd_show_icon
_lcd_show_icon:
	push	r6
	mov.w	r7,r6
; #APP
	mov.w r0,r6
       jsr 0x1b62      ; call show_icon
       jsr 0x27c8      ; call refresh
      
; #NO_APP
	pop	r6
	rts
	.align 1
	.global _lcd_hide_icon
_lcd_hide_icon:
	push	r6
	mov.w	r7,r6
; #APP
	mov.w r0,r6
       jsr 0x1e4a      ; call show_icon
       jsr 0x27c8      ; call refresh
      
; #NO_APP
	pop	r6
	rts
	.align 1
	.global _lcd_show_number
_lcd_show_number:
	push	r6
	mov.w	r7,r6
; #APP
	push r2
        push r1
        mov.w r0,r6
        jsr 0x1ff2      ; call show_number
        adds #2,r7      ; adjust stack 
        adds #2,r7
        jsr 0x27c8      ; call refresh
       
; #NO_APP
	pop	r6
	rts
	.align 1
	.global _lcd_show_int16
_lcd_show_int16:
	push	r6
	mov.w	r7,r6
	mov.w	#12290,r2
	mov.w	r0,r1
	mov.w	#12289,r0
	jsr	@_lcd_show_number
	pop	r6
	rts
	.align 1
	.global _lcd_show_digit
_lcd_show_digit:
	push	r6
	mov.w	r7,r6
	sub.w	r2,r2
	mov.w	r0,r1
	mov.w	#12311,r0
	jsr	@_lcd_show_number
	pop	r6
	rts
	.align 1
	.global _ConvertADChannel
_ConvertADChannel:
	push	r6
	mov.w	r7,r6
	mov.w	#-24,r3
	mov.b	r0l,@r3
	mov.b	@r3,r2l
	or	#32,r2l
	mov.b	r2l,@r3
.L25:
	mov.b	@r3,r2l
	bge	.L25
	mov.w	#-24,r2
	mov.b	@r2,r3l
	and	#127,r3l
	mov.b	r3l,@r2
	mov.b	#0,r0h
	mov.w	#7,r2
	cmp.w	r2,r0
	bhi	.L35
	add.w	r0,r0
	mov.w	@(.L36,r0),r2
	jmp	@r2
	.section .rodata
	.align 1
.L36:
	.word .L31
	.word .L32
	.word .L33
	.word .L34
	.word .L31
	.word .L32
	.word .L33
	.word .L34
	.section .text
.L31:
	mov.w	#-32,r2
	mov.w	@r2,r0
	bra	.L26
.L32:
	mov.w	#-30,r2
	mov.w	@r2,r0
	bra	.L26
.L33:
	mov.w	#-28,r2
	mov.w	@r2,r0
	bra	.L26
.L34:
	mov.w	#-26,r2
	mov.w	@r2,r0
	bra	.L26
.L35:
	sub.w	r0,r0
.L26:
	mov.b	#6,r2l
.Llt2:
	shlr	r0h
	rotxr	r0l
	add	#0xff,r2l
	bne	.Llt2
	pop	r6
	rts
	.align 1
	.global _BatteryLevel
_BatteryLevel:
	push	r6
	mov.w	r7,r6
	mov.b	#3,r0l
	jsr	@_ConvertADChannel
	pop	r6
	rts
	.align 1
	.global _RunInt
_RunInt:
	push	r6
	mov.w	r7,r6
; #APP
	push r0
       push r1
       push r2
       push r3
       push r4
       push r5
      
; #NO_APP
	mov.w	@_Count,r2
	adds #2,r2
	mov.w	r2,@_Count
; #APP
	pop  r5
       pop  r4
       pop  r3
       pop  r2
       pop  r1
       pop  r0
      
; #NO_APP
	pop	r6
	rts
	.align 1
	.global __start
__start:
	push	r6
	mov.w	r7,r6
	jsr	@_BatteryLevel
	jsr	@_lcd_show_int16
	mov.w	#12294,r0
	jsr	@_lcd_show_icon
	mov.w	#-73,r3
.L42:
	mov.b	@r3,r2l
	btst	#2,r2l
	bne	.L42
	mov.w	#-73,r3
.L45:
	mov.b	@r3,r2l
	btst	#2,r2l
	beq	.L45
	mov.w	#12295,r0
	jsr	@_lcd_show_icon
	sub.w	r2,r2
	mov.w	r2,@_Count
	sub.w	r0,r0
	jsr	@_lcd_show_int16
	mov.w	#1000,r0
	jsr	@_BusyPauseMS
	jsr	@_RunInt
	mov.w	#_RunInt,r2
	mov.w	r2,@-620
	mov.w	#-58,r2
	mov.b	#1,r3l
	mov.b	r3l,@r2
	adds #1,r2
	mov.b	r3l,@r2
	bra	.L46
.L48:
	mov.w	@_Count,r0
	jsr	@_lcd_show_int16
	mov.w	@_Count,r3
	mov.w	#10,r2
	cmp.w	r2,r3
	ble	.L46
	sub.w	r2,r2
	mov.w	r2,@_Count
.L46:
	mov.w	#-66,r2
	mov.b	@r2,r2l
	btst	#6,r2l
	bne	.L48
	jsr	@_RCX_Reset
	pop	r6
	rts
	.lcomm _Count,2
	.end
