
; -----------------------------------
; PROG100k.4th = 76 x RC5toLCD.4th
; -----------------------------------
; download source file sized to compile 100 kbytes
; -----------------------------------


PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 
PWR_STATE

[DEFINED] {RC5TOLCD} [IF] {RC5TOLCD} [THEN]

MARKER {RC5TOLCD}

[UNDEFINED] @ [IF]
CODE @
MOV @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
CREATE
HI2LO
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R1+,R13
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] STATE [IF]
$1DBE CONSTANT STATE
[THEN]

[UNDEFINED] = [IF]
CODE =
SUB @R15+,R14
0<> IF
    AND #0,R14
    MOV @R13+,R0
THEN
XOR #-1,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] IF [IF]
CODE IF
SUB #2,R15
MOV R14,0(R15)
MOV &$1DC6,R14
ADD #4,&$1DC6
MOV #$4042,0(R14)
ADD #2,R14
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE THEN
MOV &$1DC6,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] ELSE [IF]
CODE ELSE
ADD #4,&$1DC6
MOV &$1DC6,R10
MOV #$403E,-4(R10)
MOV R10,0(R14)
SUB #2,R10
MOV R10,R14
MOV @R13+,R0
ENDCODE IMMEDIATE
[THEN]

[UNDEFINED] IS [IF]

CODE DEFER!
MOV @R15+,2(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


: IS
STATE @
IF  POSTPONE ['] POSTPONE DEFER! 
ELSE ' DEFER! 
THEN
; IMMEDIATE
[THEN]

[UNDEFINED] >BODY [IF]
CODE >BODY
ADD #4,R14
MOV @R13+,R0
ENDCODE
[THEN]


CODE 20_US
BEGIN
    BEGIN
        BIT #1,&$3C0
    0<> UNTIL
    BIC #1,&$3C0
    SUB #1,R14
U< UNTIL
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE TOP_LCD
    BIS.B #4,&$243
    BIT.B #1,&$241
0= IF
    AND.B #$0F,R14
    MOV.B R14,&$222
    BIC.B #4,&$243
    MOV @R15+,R14
    MOV @R13+,R0
THEN
    SUB #2,R15
    MOV R14,0(R15)
    BIC.B #4,&$243
    MOV.B &$220,R14
    AND.B #$0F,R14
    MOV @R13+,R0
ENDCODE

CODE LCD_WRC
    BIS.B #2,&$243
BW1 SUB #2,R15
    MOV R14,0(R15)
    RRUM #4,R14
    BIC.B #1,&$243
    BIS.B #$0F,&$224
COLON
    TOP_LCD 2 20_US
    TOP_LCD 2 20_US 
;

CODE LCD_WRF
    BIC.B #2,&$243
    GOTO BW1
ENDCODE

: LCD_CLEAR $01 LCD_WRF 100 20_us ;
: LCD_HOME $02 LCD_WRF 100 20_us ;



ASM WDT_INT
ADD #2,R1
BIT.B #$20,&$240
0= IF
    CMP #19,&$3D6
    U< IF
        ADD #1,&$3D6
    THEN
ELSE
    BIT.B #$40,&$240
    0= IF
        CMP #3,&$3D6
        U>= IF
           SUB #1,&$3D6
        THEN
    THEN
THEN
BW1
MOV @R1+,R0
ENDASM

ASM RC5_INT
ADD #2,R1
$1806 @ 16000 = [IF]
    MOV #1,&$3A0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3A0
[THEN]
MOV #1778,R9
MOV #14,R10
BEGIN
MOV #%1011100100,&$380
    RRUM    #1,R9
    MOV     R9,R8
    RRUM    #1,R8
    ADD     R9,R8
    BEGIN   CMP R8,&$390
    U>= UNTIL
    BIT.B   #4,&$200
    ADDC    R11,R11
    MOV.B   &$200,&$208
    BIC.B   #4,&$20C
    SUB     #1,R10
0<> WHILE
    ADD R9,R8
    BEGIN
        MOV &$390,R9
        CMP R8,R9
        U>= IF
        BIC #$30,&$380
        GOTO BW1
        THEN
        BIT.B #4,&$20C
    0<> UNTIL
REPEAT
BIC #$30,&$380
RLAM    #1,R11
MOV.B   R11,R9
RRUM    #2,R9
BIT     #$4000,R11
0= IF   BIS #$40,R9
THEN
RRUM    #3,R11
XOR     @R1,R11
BIT     #$400,R11
0= ?GOTO BW1
XOR #$400,0(R1)
SUB #8,R15
MOV R14,6(R15)
MOV &$1DDC,4(R15)
MOV #$10,&$1DDC
MOV R9,0(R15)
MOV #0,R14
LO2HI
    LCD_CLEAR
    <# # #S #36 HOLD #>
    ['] LCD_WRC IS EMIT
    TYPE
    ['] EMIT >BODY IS EMIT
HI2LO
MOV @R15+,&$1DDC
MOV @R15+,R14
MOV @R1+,R0
ENDASM

ASM BACKGROUND
BEGIN
    CALL &$1814
    BIS &$180A,R2
AGAIN
ENDASM

ASM SYS_OUT
    MOV #WARM,R9
    ADD #4,R9
    MOV R9,R0
ENDASM

CODE STOP
BW1 MOV #$4000,R9
    ADD #4,R9
    MOV R9,-2(R9)
    MOV #WARM,R9
    MOV #SYS_OUT,2(R9)
    BIC.B #4,&$20A
    BIC.B #4,&$20C
    MOV #0,&$3C0
    MOV #0,&$340
    MOV #0,&$342
    MOV #COLD,R9
    MOV R9,&$FFDE
    MOV R9,&$FFEA
COLON
ECHO
." RC5toLCD is removed,"
."  type START to restart"
 WARM
;

CODE SYS_INIT
MOV #%10_1101_0100,&$3C0
$1806 @ 16000 = [IF]
    MOV #1,&$3E0
[THEN]
$1806 @ 24000 = [IF]
    MOV #2,&$3E0
[THEN]
    MOV #19,&$3D2
MOV #%0110_0000,&$3C6
    MOV #10,&$3D6
    BIS.B #$20,&$204
    BIS.B #$20,&$20A
    BIS.B #7,&$245
    BIC.B #7,&$247
    BIS.B #$0F,&$224
    BIC.B #$0F,&$226
    BIS.B #4,&$20A
    BIC.B #4,&$20C
    MOV #RC5_INT,&$FFDE
MOV #%01_0001_0100,&$340
    MOV ##3276,&$352
    MOV #%10000,&$342
    MOV #WDT_INT,&$FFEA
BIC #1,&$130
BIS.B #3,&$20D
MOV &$1808,R8
CMP #4,R8
0= ?GOTO BW1
COLON
    #1000 20_US
    %011 TOP_LCD
    #205 20_US
    %011 TOP_LCD
    #5 20_US
    %011 TOP_LCD
    #2 20_US
    %010 TOP_LCD
    #2 20_US
    %00101000 LCD_WRF
    %1000 LCD_WRF
    LCD_CLEAR
    %0110 LCD_WRF
    %1100 LCD_WRF
    LCD_CLEAR
    ['] LCD_HOME IS CR
    ['] LCD_WRC  IS EMIT
    CR ." I love you"
    ['] CR >BODY IS CR
    ['] EMIT >BODY IS EMIT
    ." RC5toLCD is running. Type STOP to quit"
    PWR_STATE ABORT
;

CODE START
MOV #$4000,R9
MOV #BACKGROUND,2(R9)
MOV #WARM,R9
MOV #SYS_INIT,2(R9)
MOV R9,R0
ENDCODE 

ECHO
            ; downloading RC5toLCD.4th is done
RST_HERE    ; this app is protected against <reset>

