First push

This commit is contained in:
Philip Smart
2022-02-17 13:17:58 +00:00
commit 6ac7fa5563
77 changed files with 11645 additions and 0 deletions

107
DefaultSession.hsf Normal file
View File

@@ -0,0 +1,107 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"2.3"
[SESSION_DETAILS]
""
[INFORMATION]
""
[GENERAL_DATA]
"{0CE21862-D122-40C7-8480-3B1EC1503AF0}ZipcCtrlViews" "0"
"{287A8023-99B5-49E1-A54E-4DDCA43D7959}MapCtrlECX_MAP_FIND_SYMBOL_LIST" ""
"{287A8023-99B5-49E1-A54E-4DDCA43D7959}MapCtrlViews" "0"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlBatchFileName" ""
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlBreakpointFlag" "-1 "
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlBreakpointStatus" "-1 "
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlBrowseDirectory" ""
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlLogFileName" ""
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlSplitterPosition" "242"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlViews" "1"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlWindowProperties" "17"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineWndInstanceKey0" "{WK_00000001_CmdLine}"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}TclTkCtrlLogFileName" ""
"{6C4D5B81-FD67-46A9-A089-EA44DCDE47FD}RAMMonitorManagerCtrlBlockInfoFileDir" ""
"{6C4D5B81-FD67-46A9-A089-EA44DCDE47FD}RAMMonitorManagerCtrlBlockInfoFileName" ""
"{7943C44E-7D44-422A-9140-4CF55C88F7D3}DifferenceCtrlViews" "0"
[LANGUAGE]
"English"
[CONFIG_INFO_VD1]
1
[CONFIG_INFO_VD2]
0
[CONFIG_INFO_VD3]
0
[CONFIG_INFO_VD4]
0
[WINDOW_POSITION_STATE_DATA_VD1]
"Help" "TOOLBAR 0" 59419 2 4 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_00000001_CmdLine}" "WINDOW" 59422 0 1 "0.17" 340 60 0 350 200 17 0 "32771|32772|32778|<<separator>>|32773|32774|<<separator>>|32820|<<separator>>|32801|32824" "0.0"
"{WK_00000001_MAPSCT}X1keybordDefaultSession" "WINDOW" 59422 0 0 "1.00" 557 283 103 795 557 2053 0 "32812|<<separator>>|32813|32814|<<separator>>|32816|<<separator>>|32822|32821|<<separator>>|32796|32797|<<separator>>|32833|<<separator>>|32825|32829|<<separator>>|32852" "29.5"
"{WK_00000001_MAPSYM}X1keybordDefaultSession" "WINDOW" 59422 0 0 "1.00" 516 327 127 802 516 2053 0 "32833|<<separator>>|32826|32828|<<separator>>|32852" "50.0"
"{WK_00000001_OUTPUT}" "WINDOW" 59422 0 0 "1.00" 340 518 256 350 200 18 0 "36756|36757|36758|36759|<<separator>>|36746|36747|<<separator>>|39531|<<separator>>|39500|39534|<<separator>>|36687" "0.0"
"{WK_00000002_WORKSPACE}" "WINDOW" 59420 0 0 "1.00" 180 518 256 350 200 18 0 "" "0.0"
"{WK_TB00000001_STANDARD}" "TOOLBAR 0" 59419 0 2 "0.00" 0 0 0 0 0 18 0 "" "0.0"
"{WK_TB00000002_EDITOR}" "TOOLBAR 0" 59419 0 0 "0.00" 0 0 0 0 0 18 0 "" "0.0"
"{WK_TB00000003_BOOKMARKS}" "TOOLBAR 0" 59419 1 1 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000004_TEMPLATES}" "TOOLBAR 0" 59419 1 0 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000005_SEARCH}" "TOOLBAR 0" 59419 0 1 "0.00" 0 0 0 0 0 18 0 "" "0.0"
"{WK_TB00000007_DEBUG}" "TOOLBAR 0" 59419 2 0 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000008_DEBUGRUN}" "TOOLBAR 0" 59419 2 1 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000009_VERSIONCONTROL}" "TOOLBAR 0" 59419 1 3 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000010_TOOLS}" "TOOLBAR 0" 59419 1 5 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000012_MAP}" "TOOLBAR 0" 59419 1 4 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000018_DEFAULTWINDOW}" "TOOLBAR 0" 59419 1 2 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000026_MACRO}" "TOOLBAR 0" 59419 1 5 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000028_RTOSDEBUG}" "TOOLBAR 0" 59419 2 2 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000029_SYSTEMTOOL}" "TOOLBAR 0" 59419 2 3 "0.00" 0 0 0 0 0 17 0 "" "0.0"
[WINDOW_POSITION_STATE_DATA_VD2]
[WINDOW_POSITION_STATE_DATA_VD3]
[WINDOW_POSITION_STATE_DATA_VD4]
[WINDOW_Z_ORDER]
"D:\Renesas\x1key\main.c"
[TARGET_NAME]
"" "" 1632504443
[STATUSBAR_STATEINFO_VD1]
"MasterShowState" 1
"ApplicationShowState" 1
"DebuggerShowState" 1
[STATUSBAR_STATEINFO_VD2]
"MasterShowState" 1
"ApplicationShowState" 1
"DebuggerShowState" 1
[STATUSBAR_STATEINFO_VD3]
"MasterShowState" 1
"ApplicationShowState" 1
"DebuggerShowState" 1
[STATUSBAR_STATEINFO_VD4]
"MasterShowState" 1
"ApplicationShowState" 1
"DebuggerShowState" 1
[STATUSBAR_DEBUGGER_PANESTATE_VD1]
[STATUSBAR_DEBUGGER_PANESTATE_VD2]
[STATUSBAR_DEBUGGER_PANESTATE_VD3]
[STATUSBAR_DEBUGGER_PANESTATE_VD4]
[DEBUGGER_OPTIONS]
""
[DOWNLOAD_MODULES]
[CONNECT_ON_GO]
"FALSE"
[DOWNLOAD_MODULES_AFTER_BUILD]
"TRUE"
[REMOVE_BREAKPOINTS_ON_DOWNLOAD]
"FALSE"
[DISABLE_MEMORY_ACCESS_PRIOR_TO_COMMAND_FILE_EXECUTION]
"FALSE"
[LIMIT_DISASSEMBLY_MEMORY_ACCESS]
"FALSE"
[DISABLE_MEMORY_ACCESS_DURING_EXECUTION]
"FALSE"
[DEBUGGER_OPTIONS_PROPERTIES]
"1"
[COMMAND_FILES]
[DEFAULT_DEBUG_FORMAT]
""
[FLASH_DETAILS]
"" 0 0 "" 0 "" 0 0 "" 0 0 0 0 0 0 0 "" "" "" "" ""
[BREAKPOINTS]
[END]

BIN
Release/Release.hdp Normal file

Binary file not shown.

10
Release/keyconv.m16cc Normal file
View File

@@ -0,0 +1,10 @@
-lang=c
-D__UART0__
-c
-finfo
-dir "D:\Renesas\mz25key\Release"
-O5
-OR
-silent
-R8C
"D:\Renesas\mz25key\keyconv.c"

BIN
Release/keyconv.obj Normal file

Binary file not shown.

10
Release/main.m16cc Normal file
View File

@@ -0,0 +1,10 @@
-lang=c
-D__UART0__
-c
-finfo
-dir "D:\Renesas\mz25key\Release"
-O5
-OR
-silent
-R8C
"D:\Renesas\mz25key\main.c"

BIN
Release/main.obj Normal file

Binary file not shown.

212
Release/ncrt0.lst Normal file
View File

@@ -0,0 +1,212 @@
* M16C Series and R8C Family Assmbler * SOURCE LIST Sat Dec 18 13:03:52 2021 PAGE 001
SEQ. LOC. OBJ. 0XMSDA ....*....SOURCE STATEMENT....7....*....8....*....9....*....0....*....1....*....2....*....3....*....4....*....5....*....6....*....7....*....8....*....9....*....0
1 ;----------------------------------------------------------------------
2 ; |
3 ; |
4 ; |
5 ; DESCRIPTION : Startup Program. (for Assembler language) |
6 ; |
7 ; |
8 ; This file is generated by Renesas Project Generator. |
9 ; |
10 ;----------------------------------------------------------------------
11 ;/*********************************************************************
12 ;*
13 ;* Device : R8C Family
14 ;*
15 ;* File Name : ncrt0.a30
16 ;*
17 ;* Abstract : Startup Program
18 ;*
19 ;* History : 1.01 (2006-11-22)
20 ;*
21 ;* NOTE : THIS IS A TYPICAL EXAMPLE.
22 ;*
23 ;* Copyright (C) 2006 Renesas Electronics Corporation.
24 ;* and Renesas Solutions Corp.
25 ;*
26 ;*********************************************************************/
27 ;---------------------------------------------------------------------
28 ; include files
29 ;---------------------------------------------------------------------
30 .list OFF
31 .list ON
32
33 ;=====================================================================
34 ; Interrupt section start
35 ;---------------------------------------------------------------------
36 .glb start
37 .section interrupt,CODE,ALIGN
38 .insf start,G,0
39 00000 start:
40 ;---------------------------------------------------------------------
41 ; after reset,this program will start
42 ;---------------------------------------------------------------------
43 00000 EB400000r ldc #((topof istack)+(sizeof istack)),isp ;set istack pointer
44 00004 C7020A00 S mov.b #02h,0ah
45 00008 B70400 Z mov.b #00h,04h ;set processer mode
46 0000B B70A00 Z mov.b #00h,0ah
47 .if __STACKSIZE__ != 0
48 0000E EB308000 ldc #0080h,flg
49 00012 EB500000r ldc #((topof stack)+(sizeof stack)),sp ;set stack pointer
50 .else
51 .endif
52 00016 EB600004 ldc #__SB__,sb ;set sb register
53
54 ; If the destination is INTBL or INTBH,
55 ; make sure that bytes are transferred in succession.
56 0001A EB200000r ldc #((topof vector)>>16)&0FFFFh,INTBH
57 0001E EB100000r ldc #(topof vector)&0FFFFh,INTBL
58
59 ;=====================================================================
60 ; NEAR area initialize.
61 ;---------------------------------------------------------------------
62 ; bss zero clear
* M16C Series and R8C Family Assmbler * SOURCE LIST Sat Dec 18 13:03:52 2021 PAGE 002
SEQ. LOC. OBJ. 0XMSDA ....*....SOURCE STATEMENT....7....*....8....*....9....*....0....*....1....*....2....*....3....*....4....*....5....*....6....*....7....*....8....*....9....*....0
63 ;---------------------------------------------------------------------
64 N_BZERO (topof bss_SE),bss_SE
65 00022 B4 1 M Z mov.b #00H, R0L
66 00023 AA0000r 1 M S mov.w #((topof bss_SE) & 0FFFFH), A1
67 00026 75C30000r 1 M mov.w #sizeof bss_SE , R3
68 0002A 7CEA 1 M sstr.b
69 1 M .endm
70 N_BZERO (topof bss_SO),bss_SO
71 0002C B4 1 M Z mov.b #00H, R0L
72 0002D AA0000r 1 M S mov.w #((topof bss_SO) & 0FFFFH), A1
73 00030 75C30000r 1 M mov.w #sizeof bss_SO , R3
74 00034 7CEA 1 M sstr.b
75 1 M .endm
76 N_BZERO (topof bss_NE),bss_NE
77 00036 B4 1 M Z mov.b #00H, R0L
78 00037 AA0000r 1 M S mov.w #((topof bss_NE) & 0FFFFH), A1
79 0003A 75C30000r 1 M mov.w #sizeof bss_NE , R3
80 0003E 7CEA 1 M sstr.b
81 1 M .endm
82 N_BZERO (topof bss_NO),bss_NO
83 00040 B4 1 M Z mov.b #00H, R0L
84 00041 AA0000r 1 M S mov.w #((topof bss_NO) & 0FFFFH), A1
85 00044 75C30000r 1 M mov.w #sizeof bss_NO , R3
86 00048 7CEA 1 M sstr.b
87 1 M .endm
88
89 ;---------------------------------------------------------------------
90 ; initialize data section
91 ;---------------------------------------------------------------------
92 N_BCOPY (topof data_SEI),(topof data_SE),data_SE
93 0004A A20000r 1 M S mov.w #((topof data_SEI) & 0FFFFH),A0
94 0004D 74C300r 1 M mov.b #((topof data_SEI) >>16),R1H
95 00050 AA0000r 1 M S mov.w #(topof data_SE) ,A1
96 00053 75C30000r 1 M mov.w #sizeof data_SE , R3
97 00057 7CE8 1 M smovf.b
98 1 M .endm
99 N_BCOPY (topof data_SOI),(topof data_SO),data_SO
100 00059 A20000r 1 M S mov.w #((topof data_SOI) & 0FFFFH),A0
101 0005C 74C300r 1 M mov.b #((topof data_SOI) >>16),R1H
102 0005F AA0000r 1 M S mov.w #(topof data_SO) ,A1
103 00062 75C30000r 1 M mov.w #sizeof data_SO , R3
104 00066 7CE8 1 M smovf.b
105 1 M .endm
106 N_BCOPY (topof data_NEI),(topof data_NE),data_NE
107 00068 A20000r 1 M S mov.w #((topof data_NEI) & 0FFFFH),A0
108 0006B 74C300r 1 M mov.b #((topof data_NEI) >>16),R1H
109 0006E AA0000r 1 M S mov.w #(topof data_NE) ,A1
110 00071 75C30000r 1 M mov.w #sizeof data_NE , R3
111 00075 7CE8 1 M smovf.b
112 1 M .endm
113 N_BCOPY (topof data_NOI),(topof data_NO),data_NO
114 00077 A20000r 1 M S mov.w #((topof data_NOI) & 0FFFFH),A0
115 0007A 74C300r 1 M mov.b #((topof data_NOI) >>16),R1H
116 0007D AA0000r 1 M S mov.w #(topof data_NO) ,A1
117 00080 75C30000r 1 M mov.w #sizeof data_NO , R3
118 00084 7CE8 1 M smovf.b
119 1 M .endm
120
121 ;=====================================================================
122 ; heap area initialize
123 ;---------------------------------------------------------------------
124 .if __HEAPSIZE__ != 0
* M16C Series and R8C Family Assmbler * SOURCE LIST Sat Dec 18 13:03:52 2021 PAGE 003
SEQ. LOC. OBJ. 0XMSDA ....*....SOURCE STATEMENT....7....*....8....*....9....*....0....*....1....*....2....*....3....*....4....*....5....*....6....*....7....*....8....*....9....*....0
125 .endif
126
127 ;=====================================================================
128 ; Initialize standard I/O
129 ;---------------------------------------------------------------------
130 .if __STANDARD_IO__ == 1
131 .endif
132
133 ;=====================================================================
134 ; Call main() function
135 ;---------------------------------------------------------------------
136 00086 EB700000 ldc #0h,fb ; for debuger
137
138 ; Remove the comment when you use global class object
139 ; Sections C$INIT will be generated
140 ; .glb __CALL_INIT
141 ; .call __CALL_INIT,G
142 ; jsr.a __CALL_INIT
143
144 .glb _main
145 .call _main,G
146 0008A FD000000r A jsr.a _main
147
148 ;=====================================================================
149 ; exit() function
150 ;---------------------------------------------------------------------
151 .glb _exit
152 .glb $exit
153 .glb __exit_loop
154 0008E _exit:
155 0008E $exit:
156
157 ; Remove the comment when you use global class object
158 ; Sections C$INIT will be generated
159 ; .glb __CALL_END
160 ; .call __CALL_END,G
161 ; jsr.a __CALL_END
162
163 0008E __exit_loop: ; End program
164 0008E FEFF B jmp __exit_loop
165 .einsf
166 ;=====================================================================
167 ; dummy interrupt function
168 ;---------------------------------------------------------------------
169 .glb dummy_int
170 00090 dummy_int:
171 00090 FB reit
172
173 .end
Information List
TOTAL ERROR(S) 00000
TOTAL WARNING(S) 00000
TOTAL LINE(S) 00173 LINES
Section List
Attr Size Name
DATA 0000000(00000H) data_SE
DATA 0000000(00000H) bss_SE
DATA 0000000(00000H) data_SO
DATA 0000000(00000H) bss_SO
DATA 0000000(00000H) data_NE
DATA 0000000(00000H) bss_NE
DATA 0000000(00000H) data_NO
DATA 0000000(00000H) bss_NO
DATA 0000128(00080H) stack
DATA 0000128(00080H) istack
ROMDATA 0000000(00000H) data_SEI
ROMDATA 0000000(00000H) data_SOI
ROMDATA 0000000(00000H) data_NEI
ROMDATA 0000000(00000H) data_NOI
ROMDATA 0000000(00000H) vector
ROMDATA 0000040(00028H) fvector
CODE 0000145(00091H) interrupt

7
Release/ncrt0.m16ca Normal file
View File

@@ -0,0 +1,7 @@
-finfo
-O"D:\Renesas\mz25key\Release"
-LM
-.
-D__R8C__=1
-R8C
"D:\Renesas\mz25key\ncrt0.a30"

BIN
Release/ncrt0.obj Normal file

Binary file not shown.

10
Release/ps2.m16cc Normal file
View File

@@ -0,0 +1,10 @@
-lang=c
-D__UART0__
-c
-finfo
-dir "D:\Renesas\mz25key\Release"
-O5
-OR
-silent
-R8C
"D:\Renesas\mz25key\ps2.c"

BIN
Release/ps2.obj Normal file

Binary file not shown.

10
Release/timer.m16cc Normal file
View File

@@ -0,0 +1,10 @@
-lang=c
-D__UART0__
-c
-finfo
-dir "D:\Renesas\mz25key\Release"
-O5
-OR
-silent
-R8C
"D:\Renesas\mz25key\timer.c"

BIN
Release/timer.obj Normal file

Binary file not shown.

10
Release/x1key.m16cc Normal file
View File

@@ -0,0 +1,10 @@
-lang=c
-D__UART0__
-c
-finfo
-dir "D:\Renesas\mz25key\Release"
-O5
-OR
-silent
-R8C
"D:\Renesas\mz25key\x1key.c"

BIN
Release/x1key.obj Normal file

Binary file not shown.

26
X1key.tps Normal file
View File

@@ -0,0 +1,26 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"1.1"
[SESSIONS_]
"DefaultSession"
[CONFIGURATIONS]
"Debug"
"Release"
[CURRENT_CONFIGURATION]
"Release"
[CURRENT_SESSION]
"DefaultSession"
[GENERAL_DATA_PROJECT]
[GENERAL_DATA_CONFIGURATION_Debug]
"PROJECT_FILES_MODIFIED_DATA_TAG" "TRUE"
[SESSIONS_Debug]
"DefaultSession"
[GENERAL_DATA_CONFIGURATION_Release]
"PROJECT_FILES_MODIFIED_DATA_TAG" "FALSE"
[SESSIONS_Release]
"DefaultSession"
[GENERAL_DATA_SESSION_DefaultSession]
[GENERAL_DATA_CONFIGURATION_SESSION_Debug_DefaultSession]
[GENERAL_DATA_CONFIGURATION_SESSION_Release_DefaultSession]
[END]

19
doc/Readme.txt Normal file
View File

@@ -0,0 +1,19 @@
-------- PROJECT GENERATOR --------
PROJECT NAME: X1keybord
PROJECT DIRECTORY: C: \ Users \ uts \ SkyDrive \ Documents \ HEW \ R8C_X1keybord \ X1keybord
CPU SERIES: R8C / Tiny
CPU GROUP: M12A
TOOLCHAIN NAME: Renesas M16C Standard Toolchain
TOOLCHAIN VERSION: 6.00.00
GENERATION FILES:
C: \ Users \ uts \ SkyDrive \ Documents \ HEW \ R8C_X1keybord \ X1keybord \ X1keybord.c
main program file.
C: \ Users \ uts \ SkyDrive \ Documents \ HEW \ R8C_X1keybord \ X1keybord \ nc_define.inc
interrupt program.
START UP FILES:
C: \ Users \ uts \ SkyDrive \ Documents \ HEW \ R8C_X1keybord \ X1keybord \ ncrt0.a30
C: \ Users \ uts \ SkyDrive \ Documents \ HEW \ R8C_X1keybord \ X1keybord \ sfr_r8m12a.h
C: \ Users \ uts \ SkyDrive \ Documents \ HEW \ R8C_X1keybord \ X1keybord \ sfr_r8m12a.inc
C: \ Users \ uts \ SkyDrive \ Documents \ HEW \ R8C_X1keybord \ X1keybord \ sect30.inc
DATE & TIME: 2014/07/16 3:13:49

176
doc/ps2.txt Normal file
View File

@@ -0,0 +1,176 @@
/ *
Connect a PS / 2 keyboard to SHARP X1
PS / 2 keyboard reception processing
.
It's easy because you only read one bit at a time at the falling edge of the clock.
Start bit 1
Data bit 8
Parity bit 1
Stop bit 1
.
11-bit odd parity in total
I wrote the key code sent to me at http://kyoutan.jpn.org/uts/pc/pic/x68key/.
Created July 22, 2014
.
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
* / /
#include "sfr_r8m12a.h"
#include "ps2.h"
#include "iodefine.h"
volatile unsigned short PS2TIMER = 0; // PS2 receive timeout timer
volatile unsigned char PS2BUFF [PS2BUFFSIZE]; // PS2 receive buffer
volatile unsigned char PS2RPOS = 0; // PS2 read position
volatile unsigned char PS2WPOS = 0; // PS2 write position
void ps2key_init (void)
{
/ * INT0 External interrupt initialization * /
// INT0 PS / 2 CLOCK
intf0 = 0b00000001; // Use INT0 f1 filter 1 * 3 / 18.432 = 0.16us
iscr0 = 0b00000000; // INT0 Falling edge
inten = 0b00000001; // INT0 input permission
{
unsigned char a;
for (a = (6 * 8); a! = 0; a--) asm ("nop"); // Wait a minute
}
// PMLi PMHi ISCR0 INTEN KIEN Rewriting the register may set the interrupt request flag to 1.
// is written in the manual, so clear the flag
while (1 == iri0) iri0 = 0;
}
// External interrupt INT0
// Interrupt at the fall of PS / 2 CLOCK and capture data bit by bit
#pragma INTERRUPT INT_int0 (vect = 29)
void INT_int0 (void)
{
static unsigned short bit = 1;
static unsigned short data = 0;
static unsigned char parity = 0;
.
// If the reception is stopped, clear the status and receive from the beginning
if ((bit! = 1) && (PS2TIMEOUT <PS2TIMER))
{
bit = 1;
data = 0;
parity = 0;
}
.
// Receive one bit at a time from the lower bits
if (0! = PS2DATA)
{
// 1
data + = bit;
parity ++;
}
.
if (0b100_0000_0000 == bit) // 11bit read (start bit 1 data bit 8 parity 1 stop 1)
{
parity-; // Subtract the stop bit
if (0! = (parity & 1)) // Normal if parity check 1 is odd
{
// Normal reception
if ((PS2BUFFSIZE-1)> ps2size ()) // Is there a free buffer?
{
PS2BUFF [PS2WPOS] = ((data >> 1) & 0xFF);
.
if ((PS2BUFFSIZE-1)> PS2WPOS)
{
PS2WPOS ++;
}
else else
{
PS2WPOS = 0;
}
}
else else
{
// Buffer full
}
}
else else
{
// Parity error
}
bit = 1;
data = 0;
parity = 0;
}
else else
{
if ((1 == bit) && (data! = 0))
{// start bit is not zero state reset
bit = 1;
data = 0;
parity = 0;
}
else else
{// Ready to read the next bit
bit = (bit << 1);
PS2TIMER = 0; // Clear timeout timer
}
}
.
while (1 == iri0) iri0 = 0; // The interrupt flag is automatically cleared, so you don't have to do this line.
}
// Returns the number of valid data in the buffer
unsigned char ps2size (void)
{
signed int size;
.
size = (signed int) PS2WPOS-PS2RPOS;
if (0> size)
{
size = PS2BUFFSIZE + size;
}
.
return size;
// size = 5 wpos = 2 rpos = 3 4
}
// Clear the receive buffer
void ps2clear (void)
{
PS2WPOS = 0;
PS2RPOS = 0;
PS2BUFF [PS2RPOS] = 0;
}
// Read 1 byte from the buffer
unsigned char ps2read (void)
{
unsigned char data = 0;
if (PS2WPOS! = PS2RPOS) // Is there data in the buffer?
{
data = PS2BUFF [PS2RPOS];
if ((PS2BUFFSIZE-1)> PS2RPOS)
{
PS2RPOS ++;
}
else else
{
PS2RPOS = 0;
}
}
return data;
}
// Wait until it is received and read 1 byte
unsigned char ps2get (void)
{
while (0 == ps2size ()); // Wait until the buffer is filled with data
return ps2read ();
}

29
flash/X1KEY.AWS Normal file
View File

@@ -0,0 +1,29 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"5.0"
[WORKSPACE_DETAILS]
"X1KEY" "D:\Renesas\x1key\flash" "D:\Renesas\x1key\flash\X1KEY.AWS" "All Flash Devices" ""
[SHARED_WORKSPACE_CONTROL_STATUS]
"" "" ""
"" "" ""
[PROJECTS]
"X1KEY" "D:\Renesas\x1key\flash\X1KEY" "D:\Renesas\x1key\flash\X1KEY\X1KEY.FWP" 0
[INFORMATION]
"No workspace information available"
[SCRAP]
[PROJECT_DEPENDENCY]
[WORKSPACE_PROPERTIES]
[VCS]
"" "" "" 0
[VCS_PROJECT]
[HELP_FILES]
[GENERAL_DATA_PROJECT]
[SYSMENUTOOLS]
[USERMENUTOOLS]
[CUSTOMPLACEHOLDERS]
[MAKEFILE_BUILD_INFO]
"$(WORKSPDIR)\make\$(PROJECTNAME).mak" "" 0 0
[VD_CONFIGURATION_OPTIONS]
[VD_CONFIGURATIONS]
[END]

12
flash/X1KEY.tws Normal file
View File

@@ -0,0 +1,12 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"1.0"
[CURRENT_PROJECT]
"X1KEY"
[GENERAL_DATA]
"EDITOR_WINDOWS_MAXIMISED" "1"
[BREAKPOINTS]
[OPEN_WORKSPACE_FILES]
[WORKSPACE_FILE_STATES]
[END]

32
flash/X1KEY/Default.hsf Normal file
View File

@@ -0,0 +1,32 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"1.3"
[SESSION_DETAILS]
""
[INFORMATION]
""
[GENERAL_DATA]
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlViews" "0"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlBatchFileName" ""
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlLogFileName" ""
[WINDOW_POSITION_STATE_DATA_VD1]
[WINDOW_POSITION_STATE_DATA_VD2]
[WINDOW_POSITION_STATE_DATA_VD3]
[WINDOW_POSITION_STATE_DATA_VD4]
[TARGET_NAME]
""
[DEBUGGER_OPTIONS]
""
[DOWNLOAD_MODULES]
[CONNECT_ON_GO]
"FALSE"
[DOWNLOAD_MODULES_AFTER_BUILD]
"TRUE"
[COMMAND_FILES]
[DEFAULT_DEBUG_FORMAT]
""
[FLASH_DETAILS]
"0.000000" 0 0 "D" 500000 "COM5" 115200 0 "R5F2M122A" 1 0 0 2 1 -1 0 "C:\Program Files (x86)\Renesas\FDT4.09\kernels\ProtD\R5F2M122A\Renesas\1_0_00\" "" "" "" ""
[BREAKPOINTS]
[END]

61
flash/X1KEY/Default.shl Normal file
View File

@@ -0,0 +1,61 @@
[ColorGroups]
Group1=Text
Group2=Text Selection
Group3=Line Comment
Group4=Block Comment
NumGroups=4
[Text]
Foreground=0,0,0
ForeColorAutomatic=0
Background=255,255,255
BackColorAutomatic=0
DisplayName=Text
Configurable=1
[Text Selection]
Foreground=255,255,255
ForeColorAutomatic=0
Background=0,0,0
BackColorAutomatic=0
DisplayName=Text Selection
Configurable=1
[Line Comment]
Foreground=0,0,0
ForeColorAutomatic=0
Background=255,255,255
BackColorAutomatic=0
DisplayName=Line Comment
Configurable=1
[Block Comment]
Foreground=0,0,0
ForeColorAutomatic=0
Background=255,255,255
BackColorAutomatic=0
DisplayName=Block Comment
Configurable=1
[Keywords]
[Parser]
Operators=
Delimiters = !"#$%&'()*+,-./:;<=>?@[\]^`{|}~
KWStartChars=
KWMiddleChars=
KWEndChars=
NumTags=1
[Tag1]
ColorGroup=String
BeginTag="
EndTag="
MultiLine=0
Escapechar=\
[Editor]
ShowWhitespace=0
VirtualWhitespace=0
VirtualWhitespace=0
MatchCase=1

109
flash/X1KEY/X1KEY.FWP Normal file
View File

@@ -0,0 +1,109 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"2.5"
[PROJECT_DETAILS]
"X1KEY" "D:\Renesas\x1key\flash\X1KEY" "D:\Renesas\x1key\flash\X1KEY\X1KEY.FWP" "All Flash Devices" "" "FDT Project Generator"
[INFORMATION]
"No project information available"
[TOOL_CHAIN]
"" ""
[CONFIGURATIONS]
"Default" "D:\Renesas\x1key\flash\X1KEY\Default"
[BUILD_PHASES]
[DEFINITION_PARSERS]
[TOOL_ENVIRONMENT]
[EXTENSIONS]
"FDT DDI Files" "DDI"
"S-Record Files" "MOT"
"S2 Files" "S2"
"FDT Binary Files" "CDE"
"Binary Files" "BIN"
"IAR A20 Files" "A20"
"IAR A37 Files" "A37"
"REC Files" "REC"
[FILE_GROUPS]
"FDT DDI Files" "BIN" "EDITOR" ""
"S-Record Files" "BIN" "HEX_EDITOR" ""
"S2 Files" "BIN" "HEX_EDITOR" ""
"FDT Binary Files" "BIN" "HEX_EDITOR" ""
"Binary Files" "BIN" "HEX_EDITOR" ""
"IAR A20 Files" "BIN" "HEX_EDITOR" ""
"IAR A37 Files" "BIN" "HEX_EDITOR" ""
"REC Files" "BIN" "HEX_EDITOR" ""
[ASSOCIATED_APPLICATIONS]
[TOOLCHAIN_PHASE]
[UTILITY_PHASE]
[CUSTOM_PHASES]
[CUSTOM_PHASE_INPUT_GROUP]
[BUILD_ORDER]
[BUILD_PHASE_DETAILS]
[SCRAP]
"Project Generator Setup File" ""
[MAPPINGS]
[PROJECT_FILES]
[FOLDER]
[GENERAL_DATA_PROJECT]
"FDT_BaseDevice" "R5F2M122A"
"FDT_Comments" ""
"FDT_DoSecurityProtection" "Prompt"
"FDT_BlockProtectConnect" "1"
"FDT_Interface" "Direct Connection"
"FDT_UseDefaultBaudRate" "FALSE"
"FDT_ResetPinLowOnDisconnect" "FALSE"
"FDT_DoSecurityProtectionLevel" "00"
"FDT_ResetPinOutputs" "FFFFFFFF"
"FDT_ConnectionResetSuppression" "FFFFFFFF"
"FDT_ResetOnDisconnect" "No"
"FDT_McuId" "2"
"FDT_ResetPinSettings" "FFFFFFFF"
"FDT_KernelPath" "C:\Program Files (x86)\Renesas\FDT4.09\kernels\ProtD\R5F2M122A\Renesas\1_0_00\"
"FDT_KernelResident" "FALSE"
"FDT_UPMPinSettings" "FFFFFFFF"
"FDT_InternalClock" "FALSE"
"FDT_CKM" "0"
"FDT_ClockMode" "-1"
"FDT_UserPinOutputs" "FFFFFFFF"
"FDT_UserPinSettings" "FFFFFFFF"
"FDT_UseInternalKernel" "TRUE"
"FDT_BlockProtectDisconnect" "1"
"FDT_SerNumConfigString" ""
"FDT_Port" "COM5"
"FDT_BlockLockConnect" "1"
"FDT_BlockLockDisconnect" "1"
"FDT_MessageLevel" "1"
"FDT_CKP" "0"
"FDT_BootMode" "TRUE"
"FDT_BaudRate" "115200"
"FDT_FileOverRomSizeOption" "Yes"
"FDT_PinOutputs" "FFFFFFFF"
"FDT_IDWriteEnable" "TRUE"
"FDT_IDWriteSecurityLevel" "1"
"FDT_Protection" "2"
"FDT_Protocol" "D"
"FDT_PinSettings" "FFFFFFFF"
"FDT_ErasureOfUserBootArea" "No"
"FDT_ClockType" ""
"FDT_ClockSync" "00000000"
"FDT_ReinterrogateGenericDevice" "No"
"FDT_Device" "R5F2M122A"
"FDT_AutoConnect" "0"
"FDT_Frequency" "0.0000"
"FDT_DoReadbackVerification" "Yes"
"FDT_IDWriteDisconnect" "1"
[ON_DEMAND_COMPONENTS_LOADED]
[SYNC_SESSION_NAMES]
[SESSIONS]
"Default" "D:\Renesas\x1key\flash\X1KEY\Default.hsf" 0
[GENERAL_DATA_SESSION_Default]
[OPTIONS_Default]
"" 0
[SESSION_DATA_CONFIGURATION_SESSION_Default_Default]
"MEMORY_MAPPING_OPTIONS" ""
[EXT_DEBUGGER_INFO]
0 "" "" "" ""
[EXCLUDED_FILES_Default]
[LINKAGE_ORDER_Default]
[GENERAL_DATA_CONFIGURATION_Default]
[GENERAL_DATA_CONFIGURATION_SESSION_Default_Default]
[END]

20
flash/X1KEY/X1KEY.tps Normal file
View File

@@ -0,0 +1,20 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"1.1"
[SESSIONS_]
"Default"
[CONFIGURATIONS]
"Default"
[CURRENT_CONFIGURATION]
"Default"
[CURRENT_SESSION]
"Default"
[GENERAL_DATA_PROJECT]
"FDT_UserBootAreaFiles" ""
[SESSIONS_Default]
"Default"
[GENERAL_DATA_CONFIGURATION_Default]
[GENERAL_DATA_CONFIGURATION_SESSION_Default_Default]
[GENERAL_DATA_SESSION_Default]
[END]

View File

@@ -0,0 +1,61 @@
[ColorGroups]
Group1=Text
Group2=Text Selection
Group3=Line Comment
Group4=Block Comment
NumGroups=4
[Text]
Foreground=0,0,0
ForeColorAutomatic=0
Background=255,255,255
BackColorAutomatic=0
DisplayName=Text
Configurable=1
[Text Selection]
Foreground=255,255,255
ForeColorAutomatic=0
Background=0,0,0
BackColorAutomatic=0
DisplayName=Text Selection
Configurable=1
[Line Comment]
Foreground=0,0,0
ForeColorAutomatic=0
Background=255,255,255
BackColorAutomatic=0
DisplayName=Line Comment
Configurable=1
[Block Comment]
Foreground=0,0,0
ForeColorAutomatic=0
Background=255,255,255
BackColorAutomatic=0
DisplayName=Block Comment
Configurable=1
[Keywords]
[Parser]
Operators=
Delimiters = !"#$%&'()*+,-./:;<=>?@[\]^`{|}~
KWStartChars=
KWMiddleChars=
KWEndChars=
NumTags=1
[Tag1]
ColorGroup=String
BeginTag="
EndTag="
MultiLine=0
Escapechar=\
[Editor]
ShowWhitespace=0
VirtualWhitespace=0
VirtualWhitespace=0
MatchCase=1

55
iodefine.h Normal file
View File

@@ -0,0 +1,55 @@
/*
Connect a PS / 2 keyboard to SHARP X1
Definition of I / O pins, etc.
Created July 22, 2014
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
#ifndef IODEFINE_H
#define IODEFINE_H
#ifdef __cplusplus
extern "C" {
#endif
// LED
#define LED p1_0
// UART
#define TXD p1_4
#define RXD p1_5
// PS/2 Interface.
#define PS2_DATA_IN p3_3
#define PS2_DATA_OUT p4_2
#define PS2_CLK_IN p4_5
#define PS2_CLK_OUT p1_1
#define PS2DATA p3_3
#define X1KEYOUT p3_7
// X1 Keyboard interface.
#define X1DATA p3_7
#define TRUE 1
#define FALSE 0
#define ON 1
#define OFF 0
#define NULL 0
#define DI() asm ("FCLR I") // Interrupt disabled
#define EI() asm ("FSET I") // Interrupt enabled
// Types missing in the Renesas C compiler headers.
typedef unsigned char uint8_t;
#ifdef __cplusplus
}
#endif
#endif // IODEFINE_H

243
keyconv.c Normal file
View File

@@ -0,0 +1,243 @@
/*
Connect a PS / 2 keyboard to SHARP X1
Key code conversion process
Created on July 23, 2014
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "sfr_r8m12a.h"
#include "keyconv.h"
#include "iodefine.h"
#include "keytable.h"
#include "ps2.h"
#include "x1key.h"
volatile unsigned short x1shift = 0xFF; // Valid at X1 shift state save 0
#define TENKEY ((unsigned char) (1 << 7))
#define PRESS ((unsigned char) (1 << 6))
#define REPEAT ((unsigned char) (1 << 5))
#define GRAPH ((unsigned char) (1 << 4))
#define CAPS ((unsigned char) (1 << 3))
#define KANA ((unsigned char) (1 << 2))
#define SHIFT ((unsigned char) (1 << 1))
#define CTRL ((unsigned char) (1 << 0))
volatile unsigned char ps2ex = 0; // PS2 keyboard extended key flag
#define EXKEY ((unsigned char) (1 << 0))
#define RELEASE ((unsigned char) (1 << 1))
#define PAUSE_BREAK ((unsigned char) (1 << 2))
unsigned char codeconv(unsigned char data);
unsigned char checkbreak(void);
unsigned char x1code(unsigned char data);
void x1trans(unsigned char data);
void keyconv(void)
{
unsigned char data;
data = ps2get (); // Wait until it is received from the PS / 2 keyboard and read 1 byte
switch (data)
{
case 0xE0: // Extended key
ps2ex |= EXKEY; // Extended key flag set
break;
case 0xF0: // separated
ps2ex |= RELEASE; // Separated flag set
break;
default:
// Convert PS / 2 code to internal code
if (0xE1 == data) data = checkbreak (); // PAUSE / BREAK key determination
if (0 == (ps2ex & EXKEY))
{// normal key
if (0x8F <data) data = 0x00;
data = KEY106 [data];
}
else
{// Extended key
if (0x5F <data) data = KEY106 [data + 0x30];
else data = KEY106 [data];
}
ps2ex &= ~EXKEY; // Extended key flag reset
x1trans (x1code (data)); // Convert internal code to X1 code and send
break;
}
}
// Convert from internal code to X1 code
unsigned char x1code(unsigned char data)
{
x1shift |= TENKEY; // Special key flag reset
// Check if it is a special key such as numeric keypad or function key SHIFT CTRL
if (((0x3A <data) && (0x59> data)) || (0x5A <data)) x1shift &= ~TENKEY; // Special key flag set
switch (data) // branch by internal code
{
case GRAPH_CODE1:
case GRAPH_CODE2:
if (0 == (ps2ex & RELEASE)) x1shift &= ~GRAPH; // Pressed
else x1shift |= GRAPH; // separated
data = 0;
break;
case CAPS_CODE:
if (0 != (ps2ex & RELEASE)) x1shift = (x1shift | CAPS) & (~(x1shift & CAPS)); // Toggle every time you release
data = 0;
break;
case KANA_CODE:
if (0 != (ps2ex & RELEASE)) x1shift = (x1shift | KANA) & (~ (x1shift & KANA)); // Toggle every time you release
data = 0;
break;
case SHIFTL_CODE:
case SHIFTR_CODE:
if (0 == (ps2ex & RELEASE)) x1shift &= ~SHIFT; // Pressed
else x1shift |= SHIFT; // separated
data = 0;
break;
case CTRL_CODE:
if (0 == (ps2ex & RELEASE)) x1shift &= ~CTRL; // Pressed
else x1shift |= CTRL; // released
data = 0;
break;
case UP_CODE:
data = 0x1E;
break;
case DOWN_CODE:
data = 0x1F;
break;
case LEFT_CODE:
data = 0x1D;
break;
case RIGHT_CODE:
data = 0x1C;
break;
case INS_CODE:
data = 0x12;
break;
case DEL_CODE: // BS is usually in the key table
data = 0x08;
break;
case HOME_CODE:
x1shift &= ~SHIFT; // + SHIFT
data = 0x0B;
break;
default: // Convert from normal key internal code to X1 code
data = codeconv (data);
break;
}
return data;
}
// The PAUSE / BREAK key starts with an unusual code, so it can be determined by another process.
unsigned char checkbreak(void)
{
unsigned char a;
for (a = 1; a <8; a++)
{
if (ps2get () != BREAK_CODE [a]) break;
}
if (8 == a) // BREAK key
{
ps2ex |= PAUSE_BREAK;
return 0x80;
}
return 0x00; // wasn't the BREAK key
}
// Send to X1
void x1trans(unsigned char data)
{
static unsigned char lastshift = 0xFF;
if (0 == (ps2ex & RELEASE))
{ // pushed
x1shift &= ~PRESS;
// Send when it is not zero and when the shift state changes
if ((0x00 != data) || (x1shift != lastshift)) X1_send (((unsigned short) x1shift << 8) | data);
if (0 != (ps2ex & PAUSE_BREAK)) // Send the release code when PAUSE / BREAK
{
x1shift |= TENKEY; // Clear special key flag
X1_send (((unsigned short) x1shift << 8) | 0x00);
ps2ex &= ~PAUSE_BREAK;
}
}
else
{// separated
x1shift |= PRESS;
X1_send (((unsigned short) x1shift << 8) | 0x00);
ps2ex &= ~RELEASE; // Clear the released flag
if (0x0B == data) x1shift |= SHIFT; // At HOME -SHIFT
}
lastshift = x1shift;
}
unsigned char codeconv(unsigned char data)
{
unsigned char status;
status = (x1shift & (CAPS | GRAPH | KANA | SHIFT | CTRL));
if ((KANA | GRAPH | SHIFT | CTRL) == status) // CAPS
{
unsigned char ret;
ret = CHR_TBL0 [data];
if ((0x60 <ret) && (0x7b> ret)) ret -= 0x20; // Uppercase alphabet
return ret;
}
if ((KANA | GRAPH | CTRL) == status) // CAPS + SHIFT
{
unsigned char ret;
ret = CHR_TBL1 [data];
if ((0x40 <ret) && (0x5b> ret)) ret += 0x20; // In lowercase letters
return ret;
}
status &= (GRAPH | KANA | SHIFT | CTRL);
if ((GRAPH | KANA | CTRL) == status) return CHR_TBL1 [data]; // SHIFT
if ((GRAPH | KANA | SHIFT) == status) return CHR_TBL3 [data]; // CTRL
if ((KANA | SHIFT | CTRL) == status) return CHR_TBL2 [data]; // GRAPH
if ((SHIFT | CTRL) == status) return CHR_TBL2 [data]; // GRAPH + KANA
if ((GRAPH | SHIFT | CTRL) == status) return CHR_TBL4 [data]; // KANA
if ((GRAPH | CTRL) == status) return CHR_TBL5 [data]; // KANA + SHIFT
return CHR_TBL0 [data]; // No shift
}
#ifdef __cplusplus
}
#endif

27
keyconv.h Normal file
View File

@@ -0,0 +1,27 @@
/*
Connect a PS / 2 keyboard to SHARP X1
Key code conversion process
Created on July 23, 2014
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
#ifndef KEYCONV_H
#define KEYCONV_H
#ifdef __cplusplus
extern "C" {
#endif
void keyconv(void);
#ifdef __cplusplus
}
#endif
#endif // KEYCONV_H

294
keytable.h Normal file
View File

@@ -0,0 +1,294 @@
/*
PS / 2- SHARP X1 keycode conversion table
I don't have the actual X1 keyboard, so the X1 keycode is
X1 emulator Xmillennium v0.26 T-tune STEP 1.43 (http://www.x1center.org/emu.html)
I used the table in Input.cpp contained in.
Created on July 23, 2014
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
typedef const unsigned char BYTE;
#pragma section rom flash_data // Place the conversion table in the data flash
/* ~~~ ~~~~~~~~~~
| +-The name of the section you like.
| Add placement attributes such as _NE _NO to this name
| Build-Specify the starting address in the linker section settings
| (No need to edit the sect30.inc file)
+ --------- Default section name (program, rom, data, bss)
For placement attributes and default section names,
M16C Series, R8C Family C / C ++ Compiler User's Manual Chapter 2 Basic Usage of the Compiler
2.2.3 Customizing memory allocation a. See Section Configuration for more information.
(The manual is installed with the "High-performancd Embedded Workshop (HEW)"
You can see it in "Manual Navigator")
*/
#ifndef KEYTABLE_H
#define KEYTABLE_H
#ifdef __cplusplus
extern "C" {
#endif
// PS / 2 106 Keyboard to internal code conversion table
// If you convert the PS / 2 code directly to the X1 code, the X1 table will become large.
// Convert to internal code once
BYTE KEY106[0x100] =
{
// 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
// 0x00 F9 F5 F3 F1 F2 F12 F10 F8 F6 F4 TAB ‘SŠp
0x00,0x43,0x00,0x3F,0x3D,0x3B,0x3C,0x58,0x00,0x44,0x42,0x40,0x3E,0x0F,0x29,0x00,
// 0x10 ALT SH L ‚Ђç CTRL Q 1 Z S A W 2 WIN
0x00,0x38,0x2A,0x55,0x1D,0x10,0x02,0x00,0x00,0x00,0x2C,0x1F,0x1E,0x11,0x03,0x00,
// 0x20 C X D E 4 3 WIN SP V F T R 5 APL
0x00,0x2E,0x2D,0x20,0x12,0x05,0x04,0x00,0x00,0x39,0x2F,0x21,0x14,0x13,0x06,0x00,
// 0x30 N B H G Y 6 M J U 7 8
0x00,0x31,0x30,0x23,0x22,0x15,0x07,0x00,0x00,0x00,0x32,0x24,0x16,0x08,0x09,0x00,
// 0x40 , K I O 0 9 . / L ; P -
0x00,0x33,0x25,0x17,0x18,0x0B,0x0A,0x00,0x00,0x34,0x35,0x26,0x27,0x19,0x0C,0x00,
// 0x50 ‚ë : @ ^ CAPS SH R ENT [ ]
0x00,0x59,0x28,0x00,0x1A,0x0d,0x00,0x00,0x3A,0x36,0x1C,0x1B,0x00,0x2B,0x00,0x00,
// 0x60 •ÏŠ· BS –³•Ï 1 \ 4 7
0x00,0x00,0x00,0x00,0x5E,0x00,0x0E,0x56,0x00,0x4F,0x5A,0x4B,0x47,0x00,0x00,0x00,
// 0x70 0 . 2 5 6 8 ESC NUM F11 + 3 - * 9 ScLk
0x52,0x53,0x50,0x4C,0x4D,0x48,0x01,0x00,0x57,0x4E,0x51,0x4A,0x37,0x49,0x00,0x00,
// 0x80 BRK F7
0x45,0x00,0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// Extended key
// 0x60 END © HOME
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5F,0x00,0xCB,0xC7,0x00,0x00,0x00,
// 0x70 INS DEL « ¨ ª PgDn PgUp
0xD2,0xD3,0xD0,0x00,0xCD,0xC8,0x00,0x00,0x00,0x00,0x5C,0x00,0x00,0x5B,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
// PAUSE/BREAK E1 14 77 E1 F0 14 F0 77 ¨ 0x80
// PRINT SCREEN E0 12 E0 7C ¨ [SH L]+[*(TEN KEY)]
};
/* ƒŠƒ^[ƒ“ƒR[ƒh ‘Œ©•\
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
0x00 ESC 1 2 3 4 5 6 7 8 9 0 - ^ BS TAB
0x10 Q W E R T Y U I O P @ [ ENT CTRL A S
0x20 D F G H J K L ; : ‘S SH L ] Z X C V
0x30 B N M , . / SH R * ALT SP CAPS F1 F2 F3 F4 F5
0x40 F6 F7 F8 F9 F10 BRK 7 8 9 - 4 5 6 + 1
0x50 2 3 0 . ‚©‚È –³•Ï F11 F12 ‚ë \ PgUp PgDn = •ÏŠ· END
0x60
0x70
0x80
0x90
0xA0
0xB0
0xC0 HOME ª © ¨
0xD0 « INS DEL
*/
#define GRAPH_CODE1 0x56 // Immutable
#define GRAPH_CODE2 0x38 // ALT
#define CAPS_CODE 0x3A // CAPS
#define KANA_CODE 0x55 // Katakana / Hiragana
#define SHIFTL_CODE 0x2A // Left SHIFT
#define SHIFTR_CODE 0x36 // Right SHIFT
#define CTRL_CODE 0x1D // CTRL
#define UP_CODE 0xC8 // ↑
#define DOWN_CODE 0xD0 // ↓
#define LEFT_CODE 0xCB // ←
#define RIGHT_CODE 0xCD // → →
#define INS_CODE 0xD2 // INS
#define DEL_CODE 0xD3 // DEL
#define HOME_CODE 0xC7 // HOME
BYTE BREAK_CODE[8]={0xE1,0x14,0x77,0xE1,0xF0,0x14,0xF0,0x77}; // BREAK key code string
// BASE
BYTE CHR_TBL0[]={
/* -- , ESC, ‚P, ‚Q, ‚R, ‚S, ‚T, ‚U, 0x00 */
0x00,0x1b, '1', '2', '3', '4', '5', '6',
/* ‚V, ‚W, ‚X, ‚O, |, O, BS, TAB, 0x08 */
'7', '8', '9', '0', '-', '^',0x08,0x09,
/* ‚p, ‚v, ‚d, ‚q, ‚s, ‚x, ‚t, ‚h, 0x10 */
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
/* ‚n, ‚o, —, m, Ent,Ctrl, ‚`, ‚r, 0x18 */
'o', 'p', '@', '[',0x0d,0x00, 'a', 's',
/* ‚c, ‚e, ‚f, ‚g, ‚i, ‚j, ‚k, G, 0x20 */
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
/* F, ‘S,SftL, n, ‚y, ‚w, ‚b, ‚u, 0x28 */
':',0x00,0x00, ']', 'z', 'x', 'c', 'v',
/* ‚a, ‚m, ‚l, C, D, ^,SftR, [*], 0x30 */
'b', 'n', 'm', ',', '.', '/',0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00, ' ',0x00, 'q', 'r', 's', 't', 'u',
/* f.6, f.7, f.8, f.9,f.10,Paus,ScrL, [7], 0x40 */
0xec,0xeb,0xe2,0xe1,0x00,0x13,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00,0x00,'\\',0x0e,0x0f, '=',0xfe,0x11,
};
// SHIFT
BYTE CHR_TBL1[]={
/* -- , ESC, ‚P, ‚Q, ‚R, ‚S, ‚T, ‚U, 0x00 */
0x00,0x1b, '!',0x22, '#', '$',0x25, '&',
/* ‚V, ‚W, ‚X, ‚O, |, O, BS, TAB, 0x08 */
0x27, '(', ')', '0', '=',0x60,0x12,0x09,
/* ‚p, ‚v, ‚d, ‚q, ‚s, ‚x, ‚t, ‚h, 0x10 */
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
/* ‚n, ‚o, —, m, Ent,Ctrl, ‚`, ‚r, 0x18 */
'O', 'P',0x7e, '{',0x0d,0x00, 'A', 'S',
/* ‚c, ‚e, ‚f, ‚g, ‚i, ‚j, ‚k, G, 0x20 */
'D', 'F', 'G', 'H', 'J', 'K', 'L', '+',
/* F, ‘S,SftL, n, ‚y, ‚w, ‚b, ‚u, 0x28 */
0x2a,0x00,0x00, '}', 'Z', 'X', 'C', 'V',
/* ‚a, ‚m, ‚l, C, D, ^,SftR, [*], 0x30 */
'B', 'N', 'M', '<', '>',0x3f,0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00, ' ',0x00, 'v', 'w', 'x', 'y', 'z',
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0x00,0x00,0x00,0x00,0x00,0x03,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00, '_', '|',0x0e,0x0f, '=',0xfe,0x11,
};
// GRPH (Alt)
BYTE CHR_TBL2[]={
/* -- , ESC, ‚P, ‚Q, ‚R, ‚S, ‚T, ‚U, 0x00 */
0x00,0x00,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,
/* ‚V, ‚W, ‚X, ‚O, |, O, BS, TAB, 0x08 */
0xf7,0xf8,0xf9,0xfa,0x8c,0x8b,0x00,0x00,
/* ‚p, ‚v, ‚d, ‚q, ‚s, ‚x, ‚t, ‚h, 0x10 */
0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
/* ‚n, ‚o, —, m, Ent,Ctrl, ‚`, ‚r, 0x18 */
0xf0,0x8d,0x8a,0xfc,0x00,0x00,0x7f,0xe9,
/* ‚c, ‚e, ‚f, ‚g, ‚i, ‚j, ‚k, G, 0x20 */
0xea,0xeb,0xec,0xed,0xee,0xef,0x8e,0x89,
/* F, ‘S,SftL, n, ‚y, ‚w, ‚b, ‚u, 0x28 */
0xfd,0x00,0x00,0xe8,0x80,0x81,0x82,0x83,
/* ‚a, ‚m, ‚l, C, D, ^,SftR, [*], 0x30 */
0x84,0x85,0x86,0x87,0x88,0xfe,0x00,0x9b,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0x00,0x00,0x00,0x00,0x00,0x13,0x00,0x9a,
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
0x93,0x97,0x9c,0x95,0x96,0x94,0x9d,0x99,
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
0x92,0x98,0x8f,0x91,0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00,0xff,0xfb,0x0e,0x0f,0x90,0xfe,0x11,
};
// CTRL
BYTE CHR_TBL3[]={
/* -- , ESC, ‚P, ‚Q, ‚R, ‚S, ‚T, ‚U, 0x00 */
0x00,0x1b, '1', '2', '3', '4', '5', '6',
/* ‚V, ‚W, ‚X, ‚O, |, O, BS, TAB, 0x08 */
'7', '8', '9', '0',0x00,0x1e,0x08,0x09,
/* ‚p, ‚v, ‚d, ‚q, ‚s, ‚x, ‚t, ‚h, 0x10 */
0x11,0x17,0x05,0x12,0x14,0x19,0x15,0x09,
/* ‚n, ‚o, —, m, Ent,Ctrl, ‚`, ‚r, 0x18 */
0x0f,0x10, '@',0x1b,0x0d,0x00,0x01,0x13,
/* ‚c, ‚e, ‚f, ‚g, ‚i, ‚j, ‚k, G, 0x20 */
0x04,0x06,0x07,0x08,0x0a,0x0b,0x0c, ';',
/* F, ‘S,SftL, n, ‚y, ‚w, ‚b, ‚u, 0x28 */
':',0x00,0x1c,0x1d,0x1a,0x18,0x03,0x16,
/* ‚a, ‚m, ‚l, C, D, ^,SftR, [*], 0x30 */
0x02,0x0e,0x0d,0x00,0x00,0x00,0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0xec,0xeb,0xe2,0xe1,0x00,0x03,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00,0x00,0x1c,0x0e,0x0f, '=',0xfe,0x11,
};
// ¶Å
BYTE CHR_TBL4[]={
/* -- , ESC, ‚P, ‚Q, ‚R, ‚S, ‚T, ‚U, 0x00 */
0x00,0x1b, 'Ç', 'Ì', '±', '³', '´', 'µ',
/* ‚V, ‚W, ‚X, ‚O, |, O, BS, TAB, 0x08 */
'Ô', 'Õ', 'Ö', 'Ü', 'Î', 'Í',0x08,0x09,
/* ‚p, ‚v, ‚d, ‚q, ‚s, ‚x, ‚t, ‚h, 0x10 */
'À', 'Ã', '²', '½', '', 'Ý', 'Å', 'Æ',
/* ‚n, ‚o, —, m, Ent,Ctrl, ‚`, ‚r, 0x18 */
'×', '¾', 'Þ', 'ß',0x0d,0x00, 'Á', 'Ä',
/* ‚c, ‚e, ‚f, ‚g, ‚i, ‚j, ‚k, G, 0x20 */
'¼', 'Ê', '·', '¸', 'Ï', 'É', 'Ø', 'Ú',
/* F, ‘S,SftL, n, ‚y, ‚w, ‚b, ‚u, 0x28 */
'¹',0x00,0x00, 'Ñ', 'Â', '»', '¿', 'Ë',
/* ‚a, ‚m, ‚l, C, D, ^,SftR, [*], 0x30 */
'º', 'Ð', 'Ó', 'È', 'Ù', 'Ò',0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00,0x20,0x00, 'q', 'r', 's', 't', 'u',
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0xec,0xeb,0xe2,0xe1,0x00,0x13,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00, 'Û', '°',0x0e,0x0f, '=',0xfe,0x11,
};
// ¶Å+¼ÌÄ
BYTE CHR_TBL5[]={
/* -- , ESC, ‚P, ‚Q, ‚R, ‚S, ‚T, ‚U, 0x00 */
0x00,0x1b, 'Ç', 'Ì', '§', '©', 'ª', '«',
/* ‚V, ‚W, ‚X, ‚O, |, O, BS, TAB, 0x08 */
'¬', '­', '®', '¦', 'Î', 'Í',0x12,0x09,
/* ‚p, ‚v, ‚d, ‚q, ‚s, ‚x, ‚t, ‚h, 0x10 */
'À', 'Ã', '¨', '½', '', 'Ý', 'Å', 'Æ',
/* ‚n, ‚o, —, m, Ent,Ctrl, ‚`, ‚r, 0x18 */
'×', '¾', 'Þ', '¢',0x0d,0x00, 'Á', 'Ä',
/* ‚c, ‚e, ‚f, ‚g, ‚i, ‚j, ‚k, G, 0x20 */
'¼', 'Ê', '·', '¸', 'Ï', 'É', 'Ø', 'Ú',
/* F, ‘S,SftL, n, ‚y, ‚w, ‚b, ‚u, 0x28 */
'¹',0x00,0x00, '£', '¯', '»', '¿', 'Ë',
/* ‚a, ‚m, ‚l, C, D, ^,SftR, [*], 0x30 */
'º', 'Ð', 'Ó', '¤', '¡', '¥',0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00, ' ',0x00, 'v', 'w', 'x', 'y', 'z',
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0x00,0x00,0x00,0x00,0x00,0x03,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00, 'Û', '°',0x0e,0x0f, '=',0xfe,0x11,
};
#pragma section rom rom
#ifdef __cplusplus
}
#endif
#endif // KEYTABLE_H

214
main.c Normal file
View File

@@ -0,0 +1,214 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: main.c
// Created: Jan 2022
// Version: v1.0
// Author(s): Philip Smart
// Description: X1 Keyboard logic.
// This source file was originally written by Sato Kyoichi and has been translated and
// changes made to accommodate the updated hardware key. Please see this repository
// for the original source if needed.
// It contains the startup code to configure the I/O and timers, initialise the sub-
// modules and then start key conversion, incoming keys are mapped realtime and sent
// immediately to the X1.
// Credits: Kyoichi Sato http://kyoutan.jpn.org/ - Firmware based on and uses components of
// X1Keybord by Kyoichi Sato.
// Copyright: Changes from original source (c) 2022 Philip Smart <philip.smart@net2net.org>
//
// History: Jan 2022 - Initial write.
//
// Notes: See Makefile to enable/disable conditional components
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file is free software: you can redistribute it and#or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This source file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifdef __cplusplus
extern "C" {
#endif
#include "sfr_r8m12a.h"
#include "iodefine.h"
#include "x1key.h"
#include "ps2.h"
#include "timer.h"
#include "keyconv.h"
#include "main.h"
void main(void)
{
// Locals.
int idx;
unsigned long idx2;
// Disable interrupts during config to prevent spurious triggers.
DI();
// Initialise the oscillator, use internal 18.432MHz clock.
osc_init();
// Initialise all the I/O ports, default interrupts/level and timer settings.
io_init();
// Start the PS/2 timer.
timer_start();
/*
// PS / 2 lead test
while (TRUE)
{
puth2 (ps2get ());
// puth2 (PS2RPOS);
// puth2 (PS2WPOS);
}
*/
/*
// X1 delivery test
{
unsigned short a = 0;
unsigned char b = 0x20;
while (TRUE)
{
if (10 <(TIMER-a)) // Every second
{
a = TIMER;
X1_send (((unsigned short) 0b10111111 << 8) + b); // Press
X1_send (((unsigned short) 0b11111111 << 8) + 0x00); // Release
if (0x7F == b)
{
b = 0x20;
}
else
{
b ++;
}
}
}
}
*/
// Enable interrupts as we are ready to process PS/2 data -> MZ-2500/2800.
EI();
// Feel good factor, show the unit is working by blinking LED.
for(idx=0; idx < 10; idx++)
{
LED = OFF;
for(idx2=0; idx2 < 100000; idx2++);
LED = ON;
for(idx2=0; idx2 < 100000; idx2++);
}
LED = OFF;
// Key conversion. PS/2 data arrives via interrupt, X1 data is sent via interrupt.
while(TRUE)
{
keyconv();
}
}
void osc_init(void)
{
// Switch to built-in high speed oscillator
prc0 = 1; // Clock register permission
ococr = 0b00000001; // High-speed on-chip oscillator oscillation Low-speed oscillation
{
unsigned char a;
for (a = 0; a <255; a ++) asm ("nop"); // Wait for the oscillator oscillation to stabilize, so wait for an appropriate amount of time.
}
sckcr = 0b01000000; // Select high speed by selecting XIN / high speed oscillator No CPU clock division
ckstpr = 0b10000000; // Select high speed by system clock low speed / high speed selection
phisel = 0x00; // No system clock division
frv1 = fr18s0; // Adjust high speed on-chip oscillator to 18.432MHz
frv2 = fr18s1;
prc0 = 0; // Clock register access prohibited
}
void io_init(void)
{
// I/O ports available on processor and applicable use.
//
// P1_0 LED - 1 = Light LED, 0 = LED off.
// P1_1 PS2_CLK_OUT - Clock output to PS/2 keyboard (used to pull clock low as keyboard generates actual clock).
// P1_2
// P1_3
// P1_4 TXD - for writing / communication
// P1_5 RXD - communication (TRJIO)
// P1_6 RXD - for writing (TRJO)
// P1_7
// P3_3 PS2_DATA_IN - (/INT3) Input data from PS/2 keyboard.
// P3_4
// P3_5
// P3_7 X1DATA - used when hardware converts PS/2 to X1 data stream. (TRJ0)
// P4_2 PS2_DATA_OUT - Output data to PS/2 keyboard.
// P4_5 PS2_CLK_IN(/INT0) - Clock intput from PS/2 keyboard.
// P4_6
// P4_7
// PA_0 /RESET
// Setup default pin value.
X1KEYOUT = 1;
p1_4 = 1; // TXD
// Port orientation 0: Input, 1: Output
pd1 = 0b00011111; // P1_5 P1_6 RXD are inputs. LED, PS2_CLK_OUT, TXD are outputs.
pd3 = 0b11110111; // P3_7 TRJO X1KEYOUT output | P3_3 PS/2 DATA input
pd4 = 0b11011111; // P4_5 INT0 PS/2 CLK input
// Pull up 0: No. 1: Yes
pur1 = 0b01100000; // RXD
pur3 = 0b00001000; // PS2_DATA_IN
pur4 = 0b00100000; // PS2_CLK_IN
// Open drain output 1: Yes
pod1 = 0b00000000;
pod3 = 0b00001000;
pod4 = 0b00100000;
// Initialise the sub modules for data in/out.
x1key_init ();
ps2key_init ();
timer_init ();
// Interrupt priority level
// CAUTION: It takes more than 20 cycles to respond to interrupts. ie. 1uS at 20MHz
ilvlb = 0x01; // TIMER RJ 1
ilvlc = 0x01; // TIMER RB 1
ilvle = 0x20; // INT0 2 Higher priority than TIMER RJ
// Processor interrupt priority level 0 (interrupts higher than this value are accepted)
asm ("LDIPL # 0");
// Port mapping
pml1 = 0b00000000; // P1_0 I/O Port for LED control.
pmh1 = 0b00000101; // P1_4: TXD P1_5: RXD
pmh1e = 0b00000000;
pml3 = 0b00000000;
pmh3 = 0b10000000; // P3_7 TRJO X1KEYOUT
pml4 = 0b00000000;
pmh4 = 0b00000100; // P4_5 INT0 PS / 2 CLK
pmh4e = 0b00010000; // P4_6 Enhanced bit to 0
pamcr = 0b00010001; // PA reset
}
#ifdef __cplusplus
}
#endif

58
main.h Normal file
View File

@@ -0,0 +1,58 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Name: main.h
// Created: Jan 2022
// Version: v1.0
// Author(s): Philip Smart
// Description: X1 Keyboard logic.
// This source file was originally written by Sato Kyoichi and has been translated and
// changes made to accommodate the updated hardware key. Please see this repository
// for the original source if needed.
// It contains the startup code to configure the I/O and timers, initialise the sub-
// modules and then start key conversion, incoming keys are mapped realtime and sent
// immediately to the X1.
// Credits: Kyoichi Sato http://kyoutan.jpn.org/ - Firmware based on and uses components of
// X1Keybord by Kyoichi Sato.
// Copyright: Changes from original source (c) 2022 Philip Smart <philip.smart@net2net.org>
//
// History: Jan 2022 - Initial write.
//
// Notes: See Makefile to enable/disable conditional components
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This source file is free software: you can redistribute it and#or modify
// it under the terms of the GNU General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This source file is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#ifndef MAIN_H
#define MAIN_H
#ifdef __cplusplus
extern "C" {
#endif
#pragma section rom flash_data
// Version string.
const char VERSION[] = "v1.0";
#pragma section rom rom
// Prototypes.
void main(void);
void osc_init(void);
void io_init(void);
#ifdef __cplusplus
}
#endif
#endif // MAIN_H

15
nc_define.inc Normal file
View File

@@ -0,0 +1,15 @@
;------------------------------------------------------------------------
; |
; FILE :nc_define.inc |
; DATE :Wed, Jul 16, 2014 |
; DESCRIPTION :interrupt program. |
; CPU GROUP :M12A |
; |
; This file is generated by Renesas Project Generator (Ver.4.19). |
; NOTE:THIS IS A TYPICAL EXAMPLE. |
;------------------------------------------------------------------------
; Macro Symbol definition
__STANDARD_IO__ .equ 0 ; STANDARD I/O flag definition
__HEAPSIZE__ .equ 0H ; HEEP SIZE definition
__STACKSIZE__ .equ 080H ; STACK SIZE definition
__ISTACKSIZE__ .equ 080H ; INTERRUPT STACK SIZE definition

139
ncrt0.a30 Normal file
View File

@@ -0,0 +1,139 @@
;----------------------------------------------------------------------
; |
; |
; |
; DESCRIPTION : Startup Program. (for Assembler language) |
; |
; |
; This file is generated by Renesas Project Generator. |
; |
;----------------------------------------------------------------------
;/*********************************************************************
;*
;* Device : R8C Family
;*
;* File Name : ncrt0.a30
;*
;* Abstract : Startup Program
;*
;* History : 1.01 (2006-11-22)
;*
;* NOTE : THIS IS A TYPICAL EXAMPLE.
;*
;* Copyright (C) 2006 Renesas Electronics Corporation.
;* and Renesas Solutions Corp.
;*
;*********************************************************************/
;---------------------------------------------------------------------
; include files
;---------------------------------------------------------------------
.list OFF
.include nc_define.inc
.include sect30.inc
.list ON
;=====================================================================
; Interrupt section start
;---------------------------------------------------------------------
.glb start
.section interrupt,CODE,ALIGN
.insf start,G,0
start:
;---------------------------------------------------------------------
; after reset,this program will start
;---------------------------------------------------------------------
ldc #((topof istack)+(sizeof istack)),isp ;set istack pointer
mov.b #02h,0ah
mov.b #00h,04h ;set processer mode
mov.b #00h,0ah
.if __STACKSIZE__ != 0
ldc #0080h,flg
ldc #((topof stack)+(sizeof stack)),sp ;set stack pointer
.else
ldc #0000h,flg
.endif
ldc #__SB__,sb ;set sb register
; If the destination is INTBL or INTBH,
; make sure that bytes are transferred in succession.
ldc #((topof vector)>>16)&0FFFFh,INTBH
ldc #(topof vector)&0FFFFh,INTBL
;=====================================================================
; NEAR area initialize.
;---------------------------------------------------------------------
; bss zero clear
;---------------------------------------------------------------------
N_BZERO (topof bss_SE),bss_SE
N_BZERO (topof bss_SO),bss_SO
N_BZERO (topof bss_NE),bss_NE
N_BZERO (topof bss_NO),bss_NO
;---------------------------------------------------------------------
; initialize data section
;---------------------------------------------------------------------
N_BCOPY (topof data_SEI),(topof data_SE),data_SE
N_BCOPY (topof data_SOI),(topof data_SO),data_SO
N_BCOPY (topof data_NEI),(topof data_NE),data_NE
N_BCOPY (topof data_NOI),(topof data_NO),data_NO
;=====================================================================
; heap area initialize
;---------------------------------------------------------------------
.if __HEAPSIZE__ != 0
.glb __mnext
.glb __msize
mov.w #((topof heap_NE)&0FFFFH),__mnext
mov.w #(__HEAPSIZE__&0FFFFH),__msize
.endif
;=====================================================================
; Initialize standard I/O
;---------------------------------------------------------------------
.if __STANDARD_IO__ == 1
.glb __init
.call __init,G
jsr.a __init
.endif
;=====================================================================
; Call main() function
;---------------------------------------------------------------------
ldc #0h,fb ; for debuger
; Remove the comment when you use global class object
; Sections C$INIT will be generated
; .glb __CALL_INIT
; .call __CALL_INIT,G
; jsr.a __CALL_INIT
.glb _main
.call _main,G
jsr.a _main
;=====================================================================
; exit() function
;---------------------------------------------------------------------
.glb _exit
.glb $exit
.glb __exit_loop
_exit:
$exit:
; Remove the comment when you use global class object
; Sections C$INIT will be generated
; .glb __CALL_END
; .call __CALL_END,G
; jsr.a __CALL_END
__exit_loop: ; End program
jmp __exit_loop
.einsf
;=====================================================================
; dummy interrupt function
;---------------------------------------------------------------------
.glb dummy_int
dummy_int:
reit
.end

186
ps2.c Normal file
View File

@@ -0,0 +1,186 @@
/*
Connect a PS / 2 keyboard to SHARP X1
PS / 2 keyboard reception processing
It's easy because you only read one bit at a time at the falling edge of the clock.
Start bit 1
Data bit 8
Parity bit 1
Stop bit 1
11-bit odd parity in total
I wrote the key code sent to me at http://kyoutan.jpn.org/uts/pc/pic/x68key/.
Created July 22, 2014
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "sfr_r8m12a.h"
#include "ps2.h"
#include "iodefine.h"
volatile unsigned short PS2TIMER = 0; // PS2 receive timeout timer
volatile unsigned char PS2BUFF [PS2BUFFSIZE]; // PS2 receive buffer
volatile unsigned char PS2RPOS = 0; // PS2 read position
volatile unsigned char PS2WPOS = 0; // PS2 write position
void ps2key_init(void)
{
/* INT0 External interrupt initialization */
// INT0 PS / 2 CLOCK
intf0 = 0b00000001; // Use INT0 f1 filter 1 * 3 / 18.432 = 0.16us
iscr0 = 0b00000000; // INT0 Falling edge
inten = 0b00000001; // INT0 input permission
{
unsigned char a;
for (a = (6 * 8); a != 0; a--) asm ("nop"); // Wait a minute
}
// PMLi PMHi ISCR0 INTEN KIEN Rewriting the register may set the interrupt request flag to 1.
// is written in the manual, so clear the flag
while (1 == iri0) iri0 = 0;
}
// External interrupt INT0
// Interrupt at the fall of PS / 2 CLOCK and capture data bit by bit
#pragma INTERRUPT INT_int0 (vect = 29)
void INT_int0(void)
{
static unsigned short bit = 1;
static unsigned short data = 0;
static unsigned char parity = 0;
// If the reception is stopped, clear the status and receive from the beginning
if ((bit != 1) && (PS2TIMEOUT <PS2TIMER))
{
bit = 1;
data = 0;
parity = 0;
}
// Receive one bit at a time from the lower bits
if (0 != PS2DATA)
{
// 1
data += bit;
parity ++;
LED = ON;
}
if (0b100_0000_0000 == bit) // 11bit read (start bit 1 data bit 8 parity 1 stop 1)
{
parity--; // Subtract the stop bit
if (0 != (parity & 1)) // Normal if parity check 1 is odd
{
// Normal reception
if ((PS2BUFFSIZE-1)> ps2size ()) // Is there a free buffer?
{
PS2BUFF [PS2WPOS] = ((data >> 1) & 0xFF);
if ((PS2BUFFSIZE-1)> PS2WPOS)
{
PS2WPOS++;
}
else
{
PS2WPOS = 0;
}
}
else
{
// Buffer full
}
}
else
{
// Parity error
}
bit = 1;
data = 0;
parity = 0;
LED = OFF;
}
else
{
if ((1 == bit) && (data != 0))
{// start bit is not zero state reset
bit = 1;
data = 0;
parity = 0;
}
else
{// Ready to read the next bit
bit = (bit << 1);
PS2TIMER = 0; // Clear timeout timer
}
}
while (1 == iri0) iri0 = 0; // The interrupt flag is automatically cleared, so you don't have to do this line.
}
// Returns the number of valid data in the buffer
unsigned char ps2size(void)
{
signed int size;
size = (signed int) PS2WPOS-PS2RPOS;
if (0> size)
{
size = PS2BUFFSIZE + size;
}
return size;
// size = 5 wpos = 2 rpos = 3 4
}
// Clear the receive buffer
void ps2clear (void)
{
PS2WPOS = 0;
PS2RPOS = 0;
PS2BUFF [PS2RPOS] = 0;
}
// Read 1 byte from the buffer
unsigned char ps2read(void)
{
unsigned char data = 0;
if (PS2WPOS != PS2RPOS) // Is there data in the buffer?
{
data = PS2BUFF [PS2RPOS];
if ((PS2BUFFSIZE-1)> PS2RPOS)
{
PS2RPOS++;
}
else
{
PS2RPOS = 0;
}
}
return data;
}
// Wait until it is received and read 1 byte
unsigned char ps2get(void)
{
while (0 == ps2size ()); // Wait until the buffer is filled with data
return ps2read ();
}
#ifdef __cplusplus
}
#endif

40
ps2.h Normal file
View File

@@ -0,0 +1,40 @@
/*
Connect a PS / 2 keyboard to SHARP X1
PS / 2 keyboard reception processing
Created July 22, 2014
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
#ifndef PS2_H
#define PS2_H
#ifdef __cplusplus
extern "C" {
#endif
#define PS2TIMEOUT 30 // PS2 timeout 30 * 100 [ms] = 3 [s]
#define PS2BUFFSIZE 0x10
extern volatile unsigned short PS2TIMER; // PS2 receive timeout timer
// extern volatile unsigned char PS2BUFF [PS2BUFFSIZE]; // PS2 receive buffer
// extern volatile unsigned char PS2RPOS; // PS2 read position
// extern volatile unsigned char PS2WPOS; // PS2 write position
void ps2key_init(void);
unsigned char ps2size(void);
void ps2clear(void);
unsigned char ps2read(void);
unsigned char ps2get(void);
#ifdef __cplusplus
}
#endif
#endif // PS2_H

157
sect30.inc Normal file
View File

@@ -0,0 +1,157 @@
;----------------------------------------------------------------------
; |
; |
; |
; DESCRIPTION : Section definition. (for Assembler language) |
; |
; |
; This file is generated by Renesas Project Generator. |
; |
;----------------------------------------------------------------------
;/*********************************************************************
;*
;* Device : R8C/Mx
;*
;* File Name : sect30.inc
;*
;* Abstract : Section definition
;*
;* History : 1.00 (2011-02-01)
;*
;* NOTE : THIS IS A TYPICAL EXAMPLE.
;*
;* Copyright (C) 2011 Renesas Electronics Corporation. and
;* Renesas Solutions Corp. All rights reserved.
;*
;*********************************************************************/
;=====================================================================
;
; Definition of section
;
;---------------------------------------------------------------------
; Near RAM data area
;---------------------------------------------------------------------
; SBDATA area
.section data_SE,DATA,ALIGN
.section bss_SE,DATA,ALIGN
.section data_SO,DATA
.section bss_SO,DATA
; SBDATA area definition
; Sets the top address (__SB__) of the SBDATA area
; (it is accessing area to used the SBrelative addressing mode).
.glb __SB__
__SB__ .equ 400H
; near RAM area
.section data_NE,DATA,ALIGN
.section bss_NE,DATA,ALIGN
.section data_NO,DATA
.section bss_NO,DATA
;---------------------------------------------------------------------
; Stack area
;---------------------------------------------------------------------
.if __STACKSIZE__ != 0
.section stack,DATA,ALIGN
.blkb __STACKSIZE__
.endif
.section istack,DATA,ALIGN
.blkb __ISTACKSIZE__
;---------------------------------------------------------------------
; heap section
;---------------------------------------------------------------------
.if __HEAPSIZE__ != 0
.section heap_NE,DATA,ALIGN
.blkb __HEAPSIZE__
.endif
;---------------------------------------------------------------------
; Initial data of 'data' section
;---------------------------------------------------------------------
.section data_SEI,ROMDATA
.section data_SOI,ROMDATA
.section data_NEI,ROMDATA
.section data_NOI,ROMDATA
;---------------------------------------------------------------------
; variable vector section
;---------------------------------------------------------------------
.section vector,ROMDATA,ALIGN
; When you use "#pragma interrupt" with "vect=",
; you need not define interrupt vector.
;
; When you use "#pragma interrupt" without "vect=",
; you must define all interrupt vectors like the following example.
; You define dummy_int for interrupt vector not used.
;
; .lword dummy_int ; vector 0
; .lword dummy_int ; vector 1
; .lword dummy_int ; vector 2
; :
; .lword dummy_int ; vector 63
;---------------------------------------------------------------------
; fixed vector section
;---------------------------------------------------------------------
.section fvector,ROMDATA
.org 0ffd8H
; reserved
.addr 0FFFFFFH
; OFS2
.byte 0FFH
UDI:
.lword dummy_int
OVER_FLOW:
.lword dummy_int
BRKI:
.lword dummy_int
ADDRESS_MATCH:
.lword dummy_int
SINGLE_STEP:
.lword dummy_int
WDT:
.lword dummy_int
; reserved
.lword dummy_int
; reserved
.lword dummy_int
RESET:
.lword start
;=====================================================================
; ID code & Option function select register
;---------------------------------------------------------------------
; ID code check function
.id "#FFFFFFFFFFFFFF"
; option function select register
.ofsreg 0FFH
;---------------------------------------------------------------------
; far ROM data area
;---------------------------------------------------------------------
; .section data_FEI,ROMDATA
; .section data_FOI,ROMDATA
;=====================================================================
; Initialize Macro declaration
;---------------------------------------------------------------------
N_BZERO .macro TOP_ ,SECT_
mov.b #00H, R0L
mov.w #(TOP_ & 0FFFFH), A1
mov.w #sizeof SECT_ , R3
sstr.b
.endm
N_BCOPY .macro FROM_,TO_,SECT_
mov.w #(FROM_ & 0FFFFH),A0
mov.b #(FROM_ >>16),R1H
mov.w #TO_ ,A1
mov.w #sizeof SECT_ , R3
smovf.b
.endm

1772
sfr_r8m12a.h Normal file

File diff suppressed because it is too large Load Diff

1286
sfr_r8m12a.inc Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,106 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"2.3"
[SESSION_DETAILS]
""
[INFORMATION]
""
[GENERAL_DATA]
"{0CE21862-D122-40C7-8480-3B1EC1503AF0}ZipcCtrlViews" "0"
"{287A8023-99B5-49E1-A54E-4DDCA43D7959}MapCtrlECX_MAP_FIND_SYMBOL_LIST" ""
"{287A8023-99B5-49E1-A54E-4DDCA43D7959}MapCtrlViews" "0"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlBatchFileName" ""
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlBreakpointFlag" "-1 "
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlBreakpointStatus" "-1 "
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlBrowseDirectory" ""
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlLogFileName" ""
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlSplitterPosition" "242"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlViews" "1"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineCtrlWindowProperties" "17"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}CmdLineWndInstanceKey0" "{WK_00000001_CmdLine}"
"{313F4FC1-6566-11D5-8BBE-0004E2013C71}TclTkCtrlLogFileName" ""
"{6C4D5B81-FD67-46A9-A089-EA44DCDE47FD}RAMMonitorManagerCtrlBlockInfoFileDir" ""
"{6C4D5B81-FD67-46A9-A089-EA44DCDE47FD}RAMMonitorManagerCtrlBlockInfoFileName" ""
"{7943C44E-7D44-422A-9140-4CF55C88F7D3}DifferenceCtrlViews" "0"
[LANGUAGE]
"Japanese"
[CONFIG_INFO_VD1]
1
[CONFIG_INFO_VD2]
0
[CONFIG_INFO_VD3]
0
[CONFIG_INFO_VD4]
0
[WINDOW_POSITION_STATE_DATA_VD1]
"{WK_00000001_CmdLine}" "WINDOW" 59422 0 1 "0.17" 180 60 0 350 200 17 0 "32771|32772|32778|<<separator>>|32773|32774|<<separator>>|32820|<<separator>>|32801|32824" "0.0"
"{WK_00000001_MAPSCT}X1keybordDefaultSession" "WINDOW" 59422 0 0 "1.00" 557 283 103 795 557 2053 0 "32812|<<separator>>|32813|32814|<<separator>>|32816|<<separator>>|32822|32821|<<separator>>|32796|32797|<<separator>>|32833|<<separator>>|32825|32829|<<separator>>|32852" "29.5"
"{WK_00000001_MAPSYM}X1keybordDefaultSession" "WINDOW" 59422 0 0 "1.00" 516 327 127 802 516 2053 0 "32833|<<separator>>|32826|32828|<<separator>>|32852" "50.0"
"{WK_00000001_OUTPUT}" "WINDOW" 59422 0 0 "1.00" 180 518 256 350 200 18 0 "36756|36757|36758|36759|<<separator>>|36746|36747|<<separator>>|39531|<<separator>>|39500|39534|<<separator>>|36687" "0.0"
"{WK_00000002_WORKSPACE}" "WINDOW" 59420 0 0 "1.00" 180 518 256 350 200 18 0 "" "0.0"
"{WK_TB00000001_STANDARD}" "TOOLBAR 0" 59419 0 2 "0.00" 0 0 0 0 0 18 0 "" "0.0"
"{WK_TB00000002_EDITOR}" "TOOLBAR 0" 59419 0 0 "0.00" 0 0 0 0 0 18 0 "" "0.0"
"{WK_TB00000003_BOOKMARKS}" "TOOLBAR 0" 59419 1 1 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000004_TEMPLATES}" "TOOLBAR 0" 59419 1 0 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000005_SEARCH}" "TOOLBAR 0" 59419 0 1 "0.00" 0 0 0 0 0 18 0 "" "0.0"
"{WK_TB00000007_DEBUG}" "TOOLBAR 0" 59419 2 0 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000008_DEBUGRUN}" "TOOLBAR 0" 59419 2 1 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000009_VERSIONCONTROL}" "TOOLBAR 0" 59419 1 3 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000010_TOOLS}" "TOOLBAR 0" 59419 1 5 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000012_MAP}" "TOOLBAR 0" 59419 1 4 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000018_DEFAULTWINDOW}" "TOOLBAR 0" 59419 1 2 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000026_MACRO}" "TOOLBAR 0" 59419 1 6 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000028_RTOSDEBUG}" "TOOLBAR 0" 59419 2 2 "0.00" 0 0 0 0 0 17 0 "" "0.0"
"{WK_TB00000029_SYSTEMTOOL}" "TOOLBAR 0" 59419 2 3 "0.00" 0 0 0 0 0 17 0 "" "0.0"
[WINDOW_POSITION_STATE_DATA_VD2]
[WINDOW_POSITION_STATE_DATA_VD3]
[WINDOW_POSITION_STATE_DATA_VD4]
[WINDOW_Z_ORDER]
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\main.c"
[TARGET_NAME]
"" "" 1632504443
[STATUSBAR_STATEINFO_VD1]
"MasterShowState" 1
"ApplicationShowState" 1
"DebuggerShowState" 1
[STATUSBAR_STATEINFO_VD2]
"MasterShowState" 1
"ApplicationShowState" 1
"DebuggerShowState" 1
[STATUSBAR_STATEINFO_VD3]
"MasterShowState" 1
"ApplicationShowState" 1
"DebuggerShowState" 1
[STATUSBAR_STATEINFO_VD4]
"MasterShowState" 1
"ApplicationShowState" 1
"DebuggerShowState" 1
[STATUSBAR_DEBUGGER_PANESTATE_VD1]
[STATUSBAR_DEBUGGER_PANESTATE_VD2]
[STATUSBAR_DEBUGGER_PANESTATE_VD3]
[STATUSBAR_DEBUGGER_PANESTATE_VD4]
[DEBUGGER_OPTIONS]
""
[DOWNLOAD_MODULES]
[CONNECT_ON_GO]
"FALSE"
[DOWNLOAD_MODULES_AFTER_BUILD]
"TRUE"
[REMOVE_BREAKPOINTS_ON_DOWNLOAD]
"FALSE"
[DISABLE_MEMORY_ACCESS_PRIOR_TO_COMMAND_FILE_EXECUTION]
"FALSE"
[LIMIT_DISASSEMBLY_MEMORY_ACCESS]
"FALSE"
[DISABLE_MEMORY_ACCESS_DURING_EXECUTION]
"FALSE"
[DEBUGGER_OPTIONS_PROPERTIES]
"1"
[COMMAND_FILES]
[DEFAULT_DEBUG_FORMAT]
""
[FLASH_DETAILS]
"" 0 0 "" 0 "" 0 0 "" 0 0 0 0 0 0 0 "" "" "" "" ""
[BREAKPOINTS]
[END]

19
src.original/Readme.txt Normal file
View File

@@ -0,0 +1,19 @@
-------- PROJECT GENERATOR --------
PROJECT NAME : X1keybord
PROJECT DIRECTORY : C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord
CPU SERIES : R8C/Tiny
CPU GROUP : M12A
TOOLCHAIN NAME : Renesas M16C Standard Toolchain
TOOLCHAIN VERSION : 6.00.00
GENERATION FILES :
C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\X1keybord.c
main program file.
C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\nc_define.inc
interrupt program.
START UP FILES :
C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\ncrt0.a30
C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\sfr_r8m12a.h
C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\sfr_r8m12a.inc
C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\sect30.inc
DATE & TIME : 2014/07/16 3:13:49

View File

@@ -0,0 +1,2 @@
[Setting]
ToolChain=0

232
src.original/X1keybord.hwp Normal file
View File

@@ -0,0 +1,232 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"2.8"
[PROJECT_DETAILS]
"X1keybord" "C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord" "C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\X1keybord.hwp" "M16C" "Renesas M16C Standard" "Application" "R8C/Tiny" "R8C/M12A"
[INFORMATION]
"プロジェクト情報がありません"
[TOOL_CHAIN]
"Renesas M16C Standard Toolchain" "6.00.00"
[CONFIGURATIONS]
"Debug" "C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\Debug"
"Release" "C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\Release"
[BUILD_PHASES]
"Renesas M16C Assembler" 1
"Renesas M16C C/C++ Compiler" 1
"Renesas M16C C/C++ Library Generator" 1
"Renesas M16C Configurator" 1
"Renesas M16C ConfiguratorR8C" 1
"Renesas OptLinker" 1
[TOOL_ENVIRONMENT]
[EXTENSIONS]
"Absolute file" "ABS"
"Absolute list file" "ALS"
"Assembler error tag file" "ATG"
"Assembly include file" "INC"
"Assembly source file" "A30"
"Binary file" "BIN"
"Branch Information file" "JIN"
"C header file" "H"
"C source file" "C"
"C++ header file" "HPP"
"C++ source file" "CC"
"C++ source file" "CP"
"C++ source file" "CPP"
"Calling information file" "CAL"
"Configuration file" "CFG"
"Cross reference file" "XRF"
"Hex file" "HEX"
"ID file" "ID"
"IEEE695 Absolute file" "X30"
"Inspector Information file" "UTL"
"Library file" "LIB"
"Library information file" "LBP"
"Library list file" "LLS"
"Linkage error tag file" "LTG"
"Linkage map file" "MAP"
"List file" "LST"
"MISRA report file" "CSV"
"MISRA rule file" "RDE"
"Object file" "OBJ"
"Preprocessed C source file" "I"
"Profile file" "PRO"
"Relocatable file" "R30"
"Relocatable file" "REL"
"S-Record file" "MOT"
"Stack information file" "SNI"
"Systemcall file" "MRC"
[FILE_GROUPS]
"Absolute file" "BIN" "NONE" ""
"Absolute list file" "TEXT" "EDITOR" ""
"Assembler error tag file" "TEXT" "EDITOR" ""
"Assembly include file" "TEXT" "EDITOR" ""
"Assembly source file" "TEXT" "EDITOR" ""
"Binary file" "BIN" "NONE" ""
"Branch Information file" "TEXT" "EDITOR" ""
"C header file" "TEXT" "EDITOR" ""
"C source file" "TEXT" "EDITOR" ""
"C++ header file" "TEXT" "EDITOR" ""
"C++ source file" "TEXT" "EDITOR" ""
"Calling information file" "BIN" "NONE" ""
"Configuration file" "TEXT" "EDITOR" ""
"Cross reference file" "TEXT" "EDITOR" ""
"Hex file" "TEXT" "EDITOR" ""
"ID file" "TEXT" "EDITOR" ""
"IEEE695 Absolute file" "BIN" "NONE" ""
"Inspector Information file" "BIN" "NONE" ""
"Library file" "BIN" "NONE" ""
"Library information file" "TEXT" "EDITOR" ""
"Library list file" "TEXT" "EDITOR" ""
"Linkage error tag file" "TEXT" "EDITOR" ""
"Linkage map file" "TEXT" "EDITOR" ""
"List file" "TEXT" "EDITOR" ""
"MISRA report file" "TEXT" "EDITOR" ""
"MISRA rule file" "TEXT" "EDITOR" ""
"Object file" "BIN" "NONE" ""
"Preprocessed C source file" "TEXT" "EDITOR" ""
"Profile file" "BIN" "NONE" ""
"Relocatable file" "BIN" "NONE" ""
"S-Record file" "TEXT" "EDITOR" ""
"Stack information file" "BIN" "NONE" ""
"Systemcall file" "TEXT" "EDITOR" ""
[ASSOCIATED_APPLICATIONS]
[TOOLCHAIN_PHASE]
"Renesas M16C Assembler"
"Renesas M16C C/C++ Compiler"
"Renesas M16C C/C++ Library Generator"
"Renesas M16C Configurator"
"Renesas M16C ConfiguratorR8C"
"Renesas OptLinker"
[UTILITY_PHASE]
[CUSTOM_PHASES]
[CUSTOM_PHASE_INPUT_GROUP]
[CUSTOM_PHASE_OUTPUT_SYNTAX]
[BUILD_ORDER]
"Renesas M16C C/C++ Library Generator" 1
"Renesas M16C C/C++ Compiler" 1
"Renesas M16C Assembler" 1
"Renesas OptLinker" 1
"Renesas M16C ConfiguratorR8C" 0
"Renesas M16C Configurator" 0
[BUILD_PHASE_DETAILS]
"Renesas M16C Assembler" "Assembly source file" 1
"Renesas M16C C/C++ Compiler" "C source file|C++ source file" 1
"Renesas M16C C/C++ Library Generator" "" 0
"Renesas M16C Configurator" "Configuration file" 0
"Renesas M16C ConfiguratorR8C" "Configuration file" 0
"Renesas OptLinker" "Object file|Library file|Relocatable file" 0
[BUILD_FILE_ORDER_Assembly source file]
"Renesas M16C Assembler" 1
[BUILD_FILE_ORDER_C source file]
"Renesas M16C C/C++ Compiler" 1
[BUILD_FILE_ORDER_C++ source file]
"Renesas M16C C/C++ Compiler" 1
[SCRAP]
"Project Generator Setup File" ""
[MAPPINGS]
"Assembly source file" "Renesas M16C Assembler" "Renesas M16C C/C++ Compiler"
"Library file" "Renesas OptLinker" "Renesas M16C C/C++ Library Generator"
"Object file" "Renesas OptLinker" "Renesas M16C Assembler"
"Object file" "Renesas OptLinker" "Renesas M16C C/C++ Compiler"
[PROJECT_FILES]
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\iodefine.h" "User" "C header file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\keyconv.c" "User" "C source file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\keyconv.h" "User" "C header file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\keytable.h" "User" "C header file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\main.c" "User" "C source file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\ncrt0.a30" "User" "Assembly source file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\ps2.c" "User" "C source file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\ps2.h" "User" "C header file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\timer.c" "User" "C source file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\timer.h" "User" "C header file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\x1key.c" "User" "C source file" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\x1key.h" "User" "C header file" 2
[FOLDER]
"Assembly source file" "Assembly source file"
"C header file" "C header file"
"C source file" "C source file"
[GENERAL_DATA_PROJECT]
"USE_CUSTOM_LINKAGE_ORDER" "1"
[ON_DEMAND_COMPONENTS_LOADED]
[SYNC_SESSION_NAMES]
[SESSIONS]
"DefaultSession" "C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\DefaultSession.hsf" 0
[GENERAL_DATA_SESSION_DefaultSession]
[OPTIONS_Debug_Renesas M16C Assembler]
"Assembly source file" "0c08a6ad3a0afc10" 4
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\ncrt0.a30" "0c08a6ad3a0afc10" 4
[OPTIONS_Debug_Renesas M16C C/C++ Compiler]
"C source file" "0c08a6ad3a0afc10" 2
"C++ source file" "0d255f408a0afc10" 3
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\keyconv.c" "0005bc57566afc10" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\main.c" "0f26a3f24a0afc10" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\ps2.c" "0697e34f775afc10" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\timer.c" "05a40b30775afc10" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\x1key.c" "02c4a5fd475afc10" 2
[OPTIONS_Debug_Renesas M16C C/C++ Library Generator]
"Single Shot" "0c08a6ad3a0afc10" 1
[OPTIONS_Debug_Renesas M16C Configurator]
"Single Shot" "0005bc57566afc10" 6
[OPTIONS_Debug_Renesas M16C ConfiguratorR8C]
"Single Shot" "0005bc57566afc10" 6
[OPTIONS_Debug_Renesas OptLinker]
"Single Shot" "0fa00d57566afc10" 5
[OPTIONS_Debug]
"" 0
"[V|VERSION|1] [B|COMMAND|1] [S|SPEC|UITRON4] " 6
"[V|VERSION|1] [S|DEFINE|__UART0__] [S|LANG|CPP] [S|OUTPUT|OBJECTCODE] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [S|MISRA|ALL] [B|SILENT|1] [S|CPU|R8C]
" 3
"[V|VERSION|1] [S|LIST|LM] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [B|DISABLES_MESSAGE|1] [S|CPU|R8C] " 4
"[V|VERSION|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(PROJECTNAME).lib^"] [S|CPU|R8C] [B|NOFLOAT|1] [S|MODE|BUILD/CHANGED]" 1
"[V|VERSION|1] [S|OUTPUT|OBJECTCODE] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [B|INSPECTOR|1] [B|SILENT|1] [S|CPU|R8C] [S|DEFINE|__UART0__] " 2
"[V|VERSION|6] [B|OPTIMIZE|0] [B|DEBUG|1] [S|OUTPUT|^"$(CONFIGDIR)\$(PROJECTNAME).mot^"] [B|LIST|1] [S|LIST|^"$(CONFIGDIR)\$(PROJECTNAME).map^"] [S|OTHER|^"-change_message=information=1100,1322,1410^"] [S|FORM|STYPE] [B|TOTAL_SIZE|1] [B|STACK|1] [S|START|data_SE,bss_SE,data_SO,bss_SO,data_NE,bss_NE,data_NO,bss_NO,stack,istack,heap_NE(400)|interrupt,rom_NE,rom_NO,data_SEI,data_SOI,data_NEI,data_NOI,switch_table,C$VTBL,program(e000)|vector(fed8)]" 5
[EXCLUDED_FILES_Debug]
[LINKAGE_ORDER_Debug]
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\Debug\ncrt0.r30"
[GENERAL_DATA_CONFIGURATION_Debug]
[OPTIONS_Release_Renesas M16C Assembler]
"Assembly source file" "07cdf9d0e95afc10" 4
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\ncrt0.a30" "07cdf9d0e95afc10" 4
[OPTIONS_Release_Renesas M16C C/C++ Compiler]
"C source file" "0f9e27549d9afc10" 2
"C++ source file" "0f9e27549d9afc10" 3
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\keyconv.c" "0f9e27549d9afc10" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\main.c" "0f9e27549d9afc10" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\ps2.c" "0f9e27549d9afc10" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\timer.c" "0f9e27549d9afc10" 2
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\x1key.c" "0f9e27549d9afc10" 2
[OPTIONS_Release_Renesas M16C C/C++ Library Generator]
"Single Shot" "07cdf9d0e95afc10" 1
[OPTIONS_Release_Renesas M16C Configurator]
"Single Shot" "0005bc57566afc10" 6
[OPTIONS_Release_Renesas M16C ConfiguratorR8C]
"Single Shot" "0005bc57566afc10" 6
[OPTIONS_Release_Renesas OptLinker]
"Single Shot" "00024c3dd5aafc10" 5
[OPTIONS_Release]
"" 0
"[V|VERSION|1] [B|COMMAND|1] [S|SPEC|UITRON4] " 6
"[V|VERSION|1] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [S|LIST|L|M] [B|DISABLES_MESSAGE|1] [S|CPU|R8C]
" 4
"[V|VERSION|1] [S|DEFINE|__UART0__] [S|LANG|CPP] [S|OUTPUT|OBJECTCODE] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [S|OPTIMIZE|5] [B|OR|1] [S|MISRA|ALL] [B|SILENT|1] [S|CPU|R8C]
" 3
"[V|VERSION|1] [S|DEFINE|__UART0__] [S|LANG|C] [S|OUTPUT|OBJECTCODE] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [S|OPTIMIZE|5] [B|OR|1] [S|MISRA|ALL] [B|SILENT|1] [S|CPU|R8C]
" 2
"[V|VERSION|1] [S|MODE|BUILD/CHANGED] [S|EXISTOUTPUTPATH|^"$(CONFIGDIR)\$(PROJECTNAME).lib^"] [B|NOFLOAT|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(PROJECTNAME).lib^"] [S|OPTIMIZE|3] [S|OPTIMIZERS|OR] [S|CPU|R8C]
" 1
"[V|VERSION|6] [S|FORM|STYPE] [S|BYTE_COUNT_VALUE|FF] [B|DEBUG|0] [S|CRC|NONE|00000000] [B|LIST|1] [S|LIST|^"$(CONFIGDIR)\$(PROJECTNAME).map^"] [S|SHOW|METHODCUSTOM|] [S|OUTPUT|^"$(CONFIGDIR)\$(PROJECTNAME).mot^"] [I|SPACE|^"FF^"] [S|OPTIMIZEITEMS|ALL] [S|START|data_SE,bss_SE,data_SO,bss_SO,data_NE,bss_NE,data_NO,bss_NO,stack,istack,heap_NE(0400)|program_dataflash,flash_data_NE,flash_data_NO(03000)|interrupt,rom_NE,rom_NO,data_SEI,data_SOI,data_NEI,data_NOI,switch_table,C$VTBL,program(0F800)|vector(0FED8)] [B|STACK|1] [B|TOTAL_SIZE|1] [S|OTHER|^"-change_message=information=1100,1322,1410^"]
" 5
[EXCLUDED_FILES_Release]
[LINKAGE_ORDER_Release]
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\Release\ncrt0.r30"
[GENERAL_DATA_CONFIGURATION_Release]
[GENERAL_DATA_CONFIGURATION_SESSION_Debug_DefaultSession]
[SESSION_DATA_CONFIGURATION_SESSION_Debug_DefaultSession]
"MEMORY_MAPPING_OPTIONS" ""
[GENERAL_DATA_CONFIGURATION_SESSION_Release_DefaultSession]
[SESSION_DATA_CONFIGURATION_SESSION_Release_DefaultSession]
"MEMORY_MAPPING_OPTIONS" ""
[EXT_DEBUGGER_INFO]
0 "" "" "" ""
[END]

View File

@@ -0,0 +1,40 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"11.0"
[WORKSPACE_DETAILS]
"X1keybord" "C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord" "C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord.hws" "M16C" "Renesas M16C Standard"
[SHARED_WORKSPACE_CONTROL_STATUS]
"" "" ""
"" "" ""
[PROJECTS]
"X1keybord" "C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord" "C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\X1keybord.hwp" 0
[INFORMATION]
"ワークスペース情報がありません"
[SCRAP]
[PROJECT_DEPENDENCY]
[WORKSPACE_PROPERTIES]
[HELP_FILES]
[GENERAL_DATA_PROJECT]
[USERMENUTOOLS]
[CUSTOMPLACEHOLDERS]
[MAKEFILE_BUILD_INFO]
"$(WORKSPDIR)\make\$(PROJECTNAME)_$(CONFIGNAME).mak" "" "$(WORKSPDIR)\make" 0 0 0
[VD_CONFIGURATION_OPTIONS]
"ACTIVE_DESKTOP" "0"
[VD_CONFIGURATIONS]
"0" "Default1" "1"
"1" "Default2" "1"
"2" "Default3" "1"
"3" "Default4" "1"
[OPTIONS_DEBUG_TAB]
0 0 0 0 0
[VCS]
"" "" "" 0
[VCS_PROJECT]
[MAKEFILE_ENV_STRINGS]
[MAKEFILE_ENV_FLAGS]
1 0 0
[MAKEFILE_CLEAN_INFO]
""
[END]

BIN
src.original/X1keybord.nav Normal file

Binary file not shown.

View File

@@ -0,0 +1,26 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"1.1"
[SESSIONS_]
"DefaultSession"
[CONFIGURATIONS]
"Debug"
"Release"
[CURRENT_CONFIGURATION]
"Release"
[CURRENT_SESSION]
"DefaultSession"
[GENERAL_DATA_PROJECT]
[GENERAL_DATA_CONFIGURATION_Debug]
"PROJECT_FILES_MODIFIED_DATA_TAG" "TRUE"
[SESSIONS_Debug]
"DefaultSession"
[GENERAL_DATA_CONFIGURATION_Release]
"PROJECT_FILES_MODIFIED_DATA_TAG" "FALSE"
[SESSIONS_Release]
"DefaultSession"
[GENERAL_DATA_SESSION_DefaultSession]
[GENERAL_DATA_CONFIGURATION_SESSION_Debug_DefaultSession]
[GENERAL_DATA_CONFIGURATION_SESSION_Release_DefaultSession]
[END]

View File

@@ -0,0 +1,15 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"1.2"
[CURRENT_PROJECT]
"X1keybord"
[GENERAL_DATA]
[BREAKPOINTS]
[OPEN_WORKSPACE_FILES]
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\main.c"
[WORKSPACE_FILE_STATES]
"C:\Users\uts\SkyDrive\Documents\HEW\R8C_X1keybord\X1keybord\main.c" -8 -31 903 466 1 0
[LOADED_PROJECTS]
"X1keybord"
[END]

23
src.original/iodefine.h Normal file
View File

@@ -0,0 +1,23 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
I/O ピンの定義ほか
2014年7月22日 作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
#define PS2DATA p3_3
#define X1KEYOUT p3_7
#define TRUE 1
#define FALSE 0
#define NULL 0
#define DI() asm("FCLR I") // 割り込み禁止
#define EI() asm("FSET I") // 割り込み許可

234
src.original/keyconv.c Normal file
View File

@@ -0,0 +1,234 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
キーコード変換処理
2014年7月23日作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
#include "keyconv.h"
#include "keytable.h"
#include "ps2.h"
#include "x1key.h"
volatile unsigned short x1shift=0xFF; // X1 シフト状態保存 0で有効
#define TENKEY ((unsigned char)(1<<7))
#define PRESS ((unsigned char)(1<<6))
#define REPEAT ((unsigned char)(1<<5))
#define GRAPH ((unsigned char)(1<<4))
#define CAPS ((unsigned char)(1<<3))
#define KANA ((unsigned char)(1<<2))
#define SHIFT ((unsigned char)(1<<1))
#define CTRL ((unsigned char)(1<<0))
volatile unsigned char ps2ex=0; // PS2キーボード 拡張キーフラグ
#define EXKEY ((unsigned char)(1<<0))
#define RELEASE ((unsigned char)(1<<1))
#define PAUSE_BREAK ((unsigned char)(1<<2))
unsigned char codeconv(unsigned char data);
unsigned char checkbreak(void);
unsigned char x1code(unsigned char data);
void x1trans(unsigned char data);
void keyconv(void)
{
unsigned char data;
data=ps2get(); // PS/2キーボードから受信するまで待って、1バイト読み込む
switch(data)
{
case 0xE0: // 拡張キー
ps2ex|=EXKEY; // 拡張キーフラグセット
break;
case 0xF0: // 離した
ps2ex|=RELEASE; // 離したフラグセット
break;
default:
// PS/2 のコードから内部コードに変換
if(0xE1==data) data=checkbreak(); // PAUSE/BREAK キーの判別
if(0==(ps2ex & EXKEY))
{ // 通常キー
if(0x8F<data) data=0x00;
data=KEY106[data];
}
else
{ // 拡張キー
if(0x5F<data) data=KEY106[data + 0x30];
else data=KEY106[data];
}
ps2ex&=~EXKEY; // 拡張キーフラグリセット
x1trans(x1code(data)); // 内部コードからX1のコードに変換して送信
break;
}
}
// 内部コードからX1のコードに変換
unsigned char x1code(unsigned char data)
{
x1shift|=TENKEY; // 特殊キーフラグリセット
// テンキーやファンクションキー SHIFT CTRL なんかの特殊キーかチェック
if(((0x3A<data)&&(0x59>data))||(0x5A<data)) x1shift&=~TENKEY; // 特殊キーフラグセット
switch(data) // 内部コードで分岐
{
case GRAPH_CODE1:
case GRAPH_CODE2:
if(0==(ps2ex&RELEASE)) x1shift&=~GRAPH; // 押した
else x1shift|=GRAPH; // 離した
data=0;
break;
case CAPS_CODE:
if(0!=(ps2ex&RELEASE)) x1shift=(x1shift|CAPS)&(~(x1shift&CAPS)); // 離すたびトグル
data=0;
break;
case KANA_CODE:
if(0!=(ps2ex&RELEASE)) x1shift=(x1shift|KANA)&(~(x1shift&KANA)); // 離すたびトグル
data=0;
break;
case SHIFTL_CODE:
case SHIFTR_CODE:
if(0==(ps2ex&RELEASE)) x1shift&=~SHIFT; // 押した
else x1shift|=SHIFT; // 離した
data=0;
break;
case CTRL_CODE:
if(0==(ps2ex&RELEASE)) x1shift&=~CTRL; // 押した
else x1shift|=CTRL; // 離した
data=0;
break;
case UP_CODE:
data=0x1E;
break;
case DOWN_CODE:
data=0x1F;
break;
case LEFT_CODE:
data=0x1D;
break;
case RIGHT_CODE:
data=0x1C;
break;
case INS_CODE:
data=0x12;
break;
case DEL_CODE: // BSは通常キーのテーブルに入っている
data=0x08;
break;
case HOME_CODE:
x1shift&=~SHIFT; // +SHIFT
data=0x0B;
break;
default: // 通常キー 内部コードからX1のコードに変換
data=codeconv(data);
break;
}
return data;
}
// PAUSE/BREAK キーは通常と違うコードで始まるので、別処理で判別
unsigned char checkbreak(void)
{
unsigned char a;
for(a=1; a<8; a++)
{
if(ps2get()!=BREAK_CODE[a]) break;
}
if(8==a) // BREAKキー だった
{
ps2ex|=PAUSE_BREAK;
return 0x80;
}
return 0x00; // BREAKキー じゃなかった
}
// X1に送信
void x1trans(unsigned char data)
{
static unsigned char lastshift=0xFF;
if(0==(ps2ex&RELEASE))
{ // 押した
x1shift&=~PRESS;
// ゼロじゃ無い時とシフト状態変化した時送信
if((0x00!=data)||(x1shift!=lastshift)) X1_send(((unsigned short)x1shift << 8) | data);
if(0!=(ps2ex&PAUSE_BREAK)) // PAUSE/BREAKの時リリースコードも送る
{
x1shift|=TENKEY; // 特殊キーフラグクリア
X1_send(((unsigned short)x1shift << 8) | 0x00);
ps2ex&=~PAUSE_BREAK;
}
}
else
{ // 離した
x1shift|=PRESS;
X1_send(((unsigned short)x1shift << 8) | 0x00);
ps2ex&=~RELEASE; // 離したフラグクリア
if(0x0B==data) x1shift|=SHIFT; // HOMEの時 -SHIFT
}
lastshift=x1shift;
}
unsigned char codeconv(unsigned char data)
{
unsigned char status;
status=(x1shift & (CAPS | GRAPH | KANA | SHIFT | CTRL));
if((KANA | GRAPH | SHIFT | CTRL )==status) // CAPS
{
unsigned char ret;
ret=CHR_TBL0[data];
if((0x60 < ret)&&(0x7b > ret)) ret-=0x20; // アルファベット大文字に
return ret;
}
if((KANA | GRAPH | CTRL )==status) // CAPS+SHIFT
{
unsigned char ret;
ret=CHR_TBL1[data];
if((0x40 < ret)&&(0x5b > ret)) ret+=0x20; // アルファベット小文字に
return ret;
}
status&=(GRAPH | KANA | SHIFT | CTRL);
if((GRAPH | KANA | CTRL )==status) return CHR_TBL1[data]; // SHIFT
if((GRAPH | KANA | SHIFT)==status) return CHR_TBL3[data]; // CTRL
if((KANA | SHIFT | CTRL )==status) return CHR_TBL2[data]; // GRAPH
if(( SHIFT | CTRL )==status) return CHR_TBL2[data]; // GRAPH+KANA
if((GRAPH | SHIFT | CTRL )==status) return CHR_TBL4[data]; // KANA
if((GRAPH | CTRL )==status) return CHR_TBL5[data]; // KANA+SHIFT
return CHR_TBL0[data]; // シフトなし
}

15
src.original/keyconv.h Normal file
View File

@@ -0,0 +1,15 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
キーコード変換処理
2014年7月23日作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
void keyconv(void);

287
src.original/keytable.h Normal file
View File

@@ -0,0 +1,287 @@
/*
PS/2 - SHARP X1 キーコード変換テーブル
X1 キーボードの実物を持っていないので、X1のキーコードは
X1 エミュレータの Xmillennium v0.26 T-tune STEP 1.43 (http://www.x1center.org/emu.html)
に含まれる Input.cpp 内のテーブルを使用しました。
2014年7月23日作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
typedef const unsigned char BYTE;
#pragma section rom flash_data // 変換テーブルはデータフラッシュに配置
/* ~~~ ~~~~~~~~~~
| +-- 自分が好きに付けたセクションの名前。
| この名前に_NE _NO 等の配置属性を付けて、
| ビルド-リンカのセクションの設定で開始アドレスを指定する
| sect30.inc ファイルを編集する必要は無い)
+--------- 既定セクション名program、rom、data、bss のいずれか)
配置属性、既定セクション名については、
16シリーズ,R8C ファミリ C/C++コンパイラユーザーズマニュアル 第 2 章 コンパイラの基本的な使い方
2.2.3 メモリ配置のカスタマイズ a. セクションの構成 に詳しく書いてある。
マニュアルは「High-performancd Embedded Workshop (HEW)」と一緒にインストールされる
「Manual Navigator」で見ることができる
*/
// PS/2 106 キーボードから内部コードへの変換テーブル
// PS/2 のコードからX1のコードに直接変換すると、X1のテーブルが大きくなってしまうので
// いったん内部コードに変換する
BYTE KEY106[0x100] =
{
// 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
// 0x00 F9 F5 F3 F1 F2 F12 F10 F8 F6 F4 TAB 全角
0x00,0x43,0x00,0x3F,0x3D,0x3B,0x3C,0x58,0x00,0x44,0x42,0x40,0x3E,0x0F,0x29,0x00,
// 0x10 ALT SH L ひら CTRL Q 1 Z S A W 2 WIN
0x00,0x38,0x2A,0x55,0x1D,0x10,0x02,0x00,0x00,0x00,0x2C,0x1F,0x1E,0x11,0x03,0x00,
// 0x20 C X D E 4 3 WIN SP V F T R 5 APL
0x00,0x2E,0x2D,0x20,0x12,0x05,0x04,0x00,0x00,0x39,0x2F,0x21,0x14,0x13,0x06,0x00,
// 0x30 N B H G Y 6 M J U 7 8
0x00,0x31,0x30,0x23,0x22,0x15,0x07,0x00,0x00,0x00,0x32,0x24,0x16,0x08,0x09,0x00,
// 0x40 , K I O 0 9 . / L ; P -
0x00,0x33,0x25,0x17,0x18,0x0B,0x0A,0x00,0x00,0x34,0x35,0x26,0x27,0x19,0x0C,0x00,
// 0x50 ろ : @ ^ CAPS SH R ENT [ ]
0x00,0x59,0x28,0x00,0x1A,0x0d,0x00,0x00,0x3A,0x36,0x1C,0x1B,0x00,0x2B,0x00,0x00,
// 0x60 変換 BS 無変 1 \ 4 7
0x00,0x00,0x00,0x00,0x5E,0x00,0x0E,0x56,0x00,0x4F,0x5A,0x4B,0x47,0x00,0x00,0x00,
// 0x70 0 . 2 5 6 8 ESC NUM F11 + 3 - * 9 ScLk
0x52,0x53,0x50,0x4C,0x4D,0x48,0x01,0x00,0x57,0x4E,0x51,0x4A,0x37,0x49,0x00,0x00,
// 0x80 BRK F7
0x45,0x00,0x00,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
// 拡張キー
// 0x60 END ← HOME
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x5F,0x00,0xCB,0xC7,0x00,0x00,0x00,
// 0x70 INS DEL ↓ → ↑ PgDn PgUp
0xD2,0xD3,0xD0,0x00,0xCD,0xC8,0x00,0x00,0x00,0x00,0x5C,0x00,0x00,0x5B,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
// PAUSE/BREAK E1 14 77 E1 F0 14 F0 77 → 0x80
// PRINT SCREEN E0 12 E0 7C → [SH L]+[*(TEN KEY)]
};
/* リターンコード 早見表
0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0A 0x0B 0x0C 0x0D 0x0E 0x0F
0x00 ESC 1 2 3 4 5 6 7 8 9 0 - ^ BS TAB
0x10 Q W E R T Y U I O P @ [ ENT CTRL A S
0x20 D F G H J K L ; : 全 SH L ] Z X C V
0x30 B N M , . / SH R * ALT SP CAPS F1 F2 F3 F4 F5
0x40 F6 F7 F8 F9 F10 BRK 7 8 9 - 4 5 6 + 1
0x50 2 3 0 . かな 無変 F11 F12 ろ \ PgUp PgDn = 変換 END
0x60
0x70
0x80
0x90
0xA0
0xB0
0xC0 HOME ↑ ← →
0xD0 ↓ INS DEL
*/
#define GRAPH_CODE1 0x56 // 無変
#define GRAPH_CODE2 0x38 // ALT
#define CAPS_CODE 0x3A // CAPS
#define KANA_CODE 0x55 // カタカナ/ひらがな
#define SHIFTL_CODE 0x2A // 左SHIFT
#define SHIFTR_CODE 0x36 // 右SHIFT
#define CTRL_CODE 0x1D // CTRL
#define UP_CODE 0xC8 // ↑
#define DOWN_CODE 0xD0 // ↓
#define LEFT_CODE 0xCB // ←
#define RIGHT_CODE 0xCD // →
#define INS_CODE 0xD2 // INS
#define DEL_CODE 0xD3 // DEL
#define HOME_CODE 0xC7 // HOME
BYTE BREAK_CODE[8]={0xE1,0x14,0x77,0xE1,0xF0,0x14,0xF0,0x77}; // BREAK キーのコード列
// 内部コードから X1 のキーコード (ASCII) への変換テーブル
// Xmillennium v0.26 T-tune STEP 1.43 の Input.cpp からコピーしました
// BASE
BYTE CHR_TBL0[]={
/* -- , ESC, , , , , , , 0x00 */
0x00,0x1b, '1', '2', '3', '4', '5', '6',
/* , , , , , , BS, TAB, 0x08 */
'7', '8', '9', '0', '-', '^',0x08,0x09,
/* , , , , , , , , 0x10 */
'q', 'w', 'e', 'r', 't', 'y', 'u', 'i',
/* , , , , Ent,Ctrl, , , 0x18 */
'o', 'p', '@', '[',0x0d,0x00, 'a', 's',
/* , , , , , , , , 0x20 */
'd', 'f', 'g', 'h', 'j', 'k', 'l', ';',
/* , 全,SftL, , , , , , 0x28 */
':',0x00,0x00, ']', 'z', 'x', 'c', 'v',
/* , , , , , ,SftR, [*], 0x30 */
'b', 'n', 'm', ',', '.', '/',0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00, ' ',0x00, 'q', 'r', 's', 't', 'u',
/* f.6, f.7, f.8, f.9,f.10,Paus,ScrL, [7], 0x40 */
0xec,0xeb,0xe2,0xe1,0x00,0x13,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00,0x00,'\\',0x0e,0x0f, '=',0xfe,0x11,
};
// SHIFT
BYTE CHR_TBL1[]={
/* -- , ESC, , , , , , , 0x00 */
0x00,0x1b, '!',0x22, '#', '$',0x25, '&',
/* , , , , , , BS, TAB, 0x08 */
0x27, '(', ')', '0', '=',0x60,0x12,0x09,
/* , , , , , , , , 0x10 */
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I',
/* , , , , Ent,Ctrl, , , 0x18 */
'O', 'P',0x7e, '{',0x0d,0x00, 'A', 'S',
/* , , , , , , , , 0x20 */
'D', 'F', 'G', 'H', 'J', 'K', 'L', '+',
/* , 全,SftL, , , , , , 0x28 */
0x2a,0x00,0x00, '}', 'Z', 'X', 'C', 'V',
/* , , , , , ,SftR, [*], 0x30 */
'B', 'N', 'M', '<', '>',0x3f,0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00, ' ',0x00, 'v', 'w', 'x', 'y', 'z',
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0x00,0x00,0x00,0x00,0x00,0x03,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00, '_', '|',0x0e,0x0f, '=',0xfe,0x11,
};
// GRPH (Alt)
BYTE CHR_TBL2[]={
/* -- , ESC, , , , , , , 0x00 */
0x00,0x00,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,
/* , , , , , , BS, TAB, 0x08 */
0xf7,0xf8,0xf9,0xfa,0x8c,0x8b,0x00,0x00,
/* , , , , , , , , 0x10 */
0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,
/* , , , , Ent,Ctrl, , , 0x18 */
0xf0,0x8d,0x8a,0xfc,0x00,0x00,0x7f,0xe9,
/* , , , , , , , , 0x20 */
0xea,0xeb,0xec,0xed,0xee,0xef,0x8e,0x89,
/* , 全,SftL, , , , , , 0x28 */
0xfd,0x00,0x00,0xe8,0x80,0x81,0x82,0x83,
/* , , , , , ,SftR, [*], 0x30 */
0x84,0x85,0x86,0x87,0x88,0xfe,0x00,0x9b,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0x00,0x00,0x00,0x00,0x00,0x13,0x00,0x9a,
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
0x93,0x97,0x9c,0x95,0x96,0x94,0x9d,0x99,
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
0x92,0x98,0x8f,0x91,0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00,0xff,0xfb,0x0e,0x0f,0x90,0xfe,0x11,
};
// CTRL
BYTE CHR_TBL3[]={
/* -- , ESC, , , , , , , 0x00 */
0x00,0x1b, '1', '2', '3', '4', '5', '6',
/* , , , , , , BS, TAB, 0x08 */
'7', '8', '9', '0',0x00,0x1e,0x08,0x09,
/* , , , , , , , , 0x10 */
0x11,0x17,0x05,0x12,0x14,0x19,0x15,0x09,
/* , , , , Ent,Ctrl, , , 0x18 */
0x0f,0x10, '@',0x1b,0x0d,0x00,0x01,0x13,
/* , , , , , , , , 0x20 */
0x04,0x06,0x07,0x08,0x0a,0x0b,0x0c, ';',
/* , 全,SftL, , , , , , 0x28 */
':',0x00,0x1c,0x1d,0x1a,0x18,0x03,0x16,
/* , , , , , ,SftR, [*], 0x30 */
0x02,0x0e,0x0d,0x00,0x00,0x00,0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0xec,0xeb,0xe2,0xe1,0x00,0x03,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00,0x00,0x1c,0x0e,0x0f, '=',0xfe,0x11,
};
// カナ
BYTE CHR_TBL4[]={
/* -- , ESC, , , , , , , 0x00 */
0x00,0x1b, '', '', '', '', '', '',
/* , , , , , , BS, TAB, 0x08 */
'', '', '', '', '', '',0x08,0x09,
/* , , , , , , , , 0x10 */
'', '', '', '', '', '', '', '',
/* , , , , Ent,Ctrl, , , 0x18 */
'', '', '', '',0x0d,0x00, '', '',
/* , , , , , , , , 0x20 */
'', '', '', '', '', '', '', '',
/* , 全,SftL, , , , , , 0x28 */
'',0x00,0x00, '', '', '', 'ソ', '',
/* , , , , , ,SftR, [*], 0x30 */
'', '', '', '', '', '',0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00,0x20,0x00, 'q', 'r', 's', 't', 'u',
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0xec,0xeb,0xe2,0xe1,0x00,0x13,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00, '', '',0x0e,0x0f, '=',0xfe,0x11,
};
// カナ+シフト
BYTE CHR_TBL5[]={
/* -- , ESC, , , , , , , 0x00 */
0x00,0x1b, '', '', '', '', '', '',
/* , , , , , , BS, TAB, 0x08 */
'', '', '', '', '', '',0x12,0x09,
/* , , , , , , , , 0x10 */
'', '', '', '', '', '', '', '',
/* , , , , Ent,Ctrl, , , 0x18 */
'', '', '', '',0x0d,0x00, '', '',
/* , , , , , , , , 0x20 */
'', '', '', '', '', '', '', '',
/* , 全,SftL, , , , , , 0x28 */
'',0x00,0x00, '', '', '', 'ソ', '',
/* , , , , , ,SftR, [*], 0x30 */
'', '', '', '', '', '',0x00,0x2a,
/* Alt, SPC, Cap, f.1, f.2, f.3, f.4, f.5, 0x38 */
0x00, ' ',0x00, 'v', 'w', 'x', 'y', 'z',
/* f.6, f.7, f.8, f.9,f.10,Paus, ???, [7], 0x40 */
0x00,0x00,0x00,0x00,0x00,0x03,0x00, '7',
/* [8], [9], [-], [4], [5], [6], [+], [1], 0x48 */
'8', '9', '-', '4', '5', '6', '+', '1',
/* [2], [3], [0], [.], ???, ???, ???,f.11, 0x50 */
'2', '3', '0', '.',0x00,0x00,0x00,0x00,
/*f.12, _ , \ ,RLUP,RLDN,<>,XFER, END, 0x58 */
0x00, '', '',0x0e,0x0f, '=',0xfe,0x11,
};
#pragma section rom rom // 定数セクションの配置を通常romに戻す

165
src.original/main.c Normal file
View File

@@ -0,0 +1,165 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
Renesas R8C/M12A 用
標準の プログラムROM:2KB データフラッシュ:2KB RAM:256B に収まります。
2014年7月16日 作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
X1のキーボード実物を所有していないので、動作が正しいのかよくわかりません。
動作テストは X1 turbo III で行いましたが、概ねいい感じに動いているようです。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
#include "sfr_r8m12a.h"
#include "iodefine.h"
#include "x1key.h"
#include "ps2.h"
#include "timer.h"
#include "keyconv.h"
void main(void);
void osc_init(void);
void io_init(void);
void main(void)
{
DI(); // 割り込み禁止
osc_init();
io_init();
timer_start();
EI(); // 割り込み許可
/*
// PS/2 リードテスト
while(TRUE)
{
puth2(ps2get());
//puth2(PS2RPOS);
//puth2(PS2WPOS);
}
*/
/*
// X1 送出テスト
{
unsigned short a=0;
unsigned char b=0x20;
while(TRUE)
{
if(10 < (TIMER-a)) // 1秒毎
{
a=TIMER;
X1_send(((unsigned short)0b10111111 << 8) + b);//押す
X1_send(((unsigned short)0b11111111 << 8) + 0x00);//離す
if(0x7F==b)
{
b=0x20;
}
else
{
b++;
}
}
}
}
*/
while(TRUE)
{
keyconv();
}
}
void osc_init(void)
{
// 内蔵高速オシレーターに切り替え
prc0=1; // クロックレジスタアクセス許可
ococr=0b00000001; // 高速オンチップオシレーター発振 低速も発振
{
unsigned char a;
for(a=0; a<255; a++) asm("nop"); // ここでオシレーターの発振が安定するのを待てとあるので適当に時間待ち
}
sckcr=0b01000000; // XIN/高速オシレーター選択で高速を選択 CPUクロック分周無し
ckstpr=0b10000000; // システムクロック低速/高速選択で高速を選択
phisel=0x00; // システムクロック分周無し
frv1=fr18s0; // 高速オンチップオシレーターを18.432MHzに調整
frv2=fr18s1;
prc0=0; // クロックレジスタアクセス禁止
}
void io_init(void)
{
// I/O ポート
// P1_0
// P1_1
// P1_2
// P1_3
// P1_4 TXD 書き込み・通信用
// P1_5 RXD 通信用 (TRJIO)
// P1_6 RXD 書き込み用 (TRJO)
// P1_7
// P3_3 PS/2 DATA
// P3_4
// P3_5
// P3_7 TRJO X1KEYOUT
// P4_2
// P4_5 INT0 PS/2 CLK
// P4_6 (TRJIO X1KEYOUT TRJOの反転出力 使わない)
// P4_7
// PA_0
X1KEYOUT=1;
p1_4=1; // TXD
// ポートの向き 1:出力
pd1=0b10011111; // P1_5 P1_6 入力 RXD
pd3=0b11110111; // P3_7 TRJO X1KEYOUT 出力 | P3_3 PS/2 DATA 入力
pd4=0b11011111; // P4_5 INT0 PS/2 CLK 入力
// プルアップ 1:あり
pur1=0b01100000;
pur3=0b00001000;
pur4=0b00100000;
// オープンドレイン出力 1:あり
pod1=0b00000000;
pod3=0b00001000;
pod4=0b00100000;
x1key_init();
ps2key_init();
timer_init();
// 割り込み優先レベル
ilvlb=0x01; // TIMER RJ 1
ilvlc=0x01; // TIMER RB 1
ilvle=0x20; // INT0 2 TIMER RJ より優先度高い
// 割り込み応答に 20サイクル超と結構かかる。
asm("LDIPL #0"); // プロセッサ割り込み優先レベル0この値よりも高いレベルの割り込みが受け付けられる
// ポートマッピング
pml1 =0b00000000;
pmh1 =0b00000101; // P1_4:TXD P1_5:RXD
pmh1e=0b00000000;
pml3 =0b00000000;
pmh3 =0b10000000; // P3_7 TRJO X1KEYOUT
pml4 =0b00000000;
pmh4 =0b00000100; // P4_5 INT0 PS/2 CLK
pmh4e=0b00010000;
pamcr=0b00010001; // PAはリセット
}

View File

@@ -0,0 +1,15 @@
;------------------------------------------------------------------------
; |
; FILE :nc_define.inc |
; DATE :Wed, Jul 16, 2014 |
; DESCRIPTION :interrupt program. |
; CPU GROUP :M12A |
; |
; This file is generated by Renesas Project Generator (Ver.4.19). |
; NOTE:THIS IS A TYPICAL EXAMPLE. |
;------------------------------------------------------------------------
; Macro Symbol definition
__STANDARD_IO__ .equ 0 ; STANDARD I/O flag definition
__HEAPSIZE__ .equ 0H ; HEEP SIZE definition
__STACKSIZE__ .equ 080H ; STACK SIZE definition
__ISTACKSIZE__ .equ 080H ; INTERRUPT STACK SIZE definition

139
src.original/ncrt0.a30 Normal file
View File

@@ -0,0 +1,139 @@
;----------------------------------------------------------------------
; |
; |
; |
; DESCRIPTION : Startup Program. (for Assembler language) |
; |
; |
; This file is generated by Renesas Project Generator. |
; |
;----------------------------------------------------------------------
;/*********************************************************************
;*
;* Device : R8C Family
;*
;* File Name : ncrt0.a30
;*
;* Abstract : Startup Program
;*
;* History : 1.01 (2006-11-22)
;*
;* NOTE : THIS IS A TYPICAL EXAMPLE.
;*
;* Copyright (C) 2006 Renesas Electronics Corporation.
;* and Renesas Solutions Corp.
;*
;*********************************************************************/
;---------------------------------------------------------------------
; include files
;---------------------------------------------------------------------
.list OFF
.include nc_define.inc
.include sect30.inc
.list ON
;=====================================================================
; Interrupt section start
;---------------------------------------------------------------------
.glb start
.section interrupt,CODE,ALIGN
.insf start,G,0
start:
;---------------------------------------------------------------------
; after reset,this program will start
;---------------------------------------------------------------------
ldc #((topof istack)+(sizeof istack)),isp ;set istack pointer
mov.b #02h,0ah
mov.b #00h,04h ;set processer mode
mov.b #00h,0ah
.if __STACKSIZE__ != 0
ldc #0080h,flg
ldc #((topof stack)+(sizeof stack)),sp ;set stack pointer
.else
ldc #0000h,flg
.endif
ldc #__SB__,sb ;set sb register
; If the destination is INTBL or INTBH,
; make sure that bytes are transferred in succession.
ldc #((topof vector)>>16)&0FFFFh,INTBH
ldc #(topof vector)&0FFFFh,INTBL
;=====================================================================
; NEAR area initialize.
;---------------------------------------------------------------------
; bss zero clear
;---------------------------------------------------------------------
N_BZERO (topof bss_SE),bss_SE
N_BZERO (topof bss_SO),bss_SO
N_BZERO (topof bss_NE),bss_NE
N_BZERO (topof bss_NO),bss_NO
;---------------------------------------------------------------------
; initialize data section
;---------------------------------------------------------------------
N_BCOPY (topof data_SEI),(topof data_SE),data_SE
N_BCOPY (topof data_SOI),(topof data_SO),data_SO
N_BCOPY (topof data_NEI),(topof data_NE),data_NE
N_BCOPY (topof data_NOI),(topof data_NO),data_NO
;=====================================================================
; heap area initialize
;---------------------------------------------------------------------
.if __HEAPSIZE__ != 0
.glb __mnext
.glb __msize
mov.w #((topof heap_NE)&0FFFFH),__mnext
mov.w #(__HEAPSIZE__&0FFFFH),__msize
.endif
;=====================================================================
; Initialize standard I/O
;---------------------------------------------------------------------
.if __STANDARD_IO__ == 1
.glb __init
.call __init,G
jsr.a __init
.endif
;=====================================================================
; Call main() function
;---------------------------------------------------------------------
ldc #0h,fb ; for debuger
; Remove the comment when you use global class object
; Sections C$INIT will be generated
; .glb __CALL_INIT
; .call __CALL_INIT,G
; jsr.a __CALL_INIT
.glb _main
.call _main,G
jsr.a _main
;=====================================================================
; exit() function
;---------------------------------------------------------------------
.glb _exit
.glb $exit
.glb __exit_loop
_exit:
$exit:
; Remove the comment when you use global class object
; Sections C$INIT will be generated
; .glb __CALL_END
; .call __CALL_END,G
; jsr.a __CALL_END
__exit_loop: ; End program
jmp __exit_loop
.einsf
;=====================================================================
; dummy interrupt function
;---------------------------------------------------------------------
.glb dummy_int
dummy_int:
reit
.end

176
src.original/ps2.c Normal file
View File

@@ -0,0 +1,176 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
PS/2 キーボードの受信処理
クロックの立ち下がりで1ビットづつ読むだけなので、簡単です。
スタートビット 1
データビット 8
パリティビット 1
ストップビット 1
計11ビット 奇数パリティ
送られてくるキーコードは http://kyoutan.jpn.org/uts/pc/pic/x68key/ に書きました。
2014年7月22日 作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
#include "sfr_r8m12a.h"
#include "ps2.h"
#include "iodefine.h"
volatile unsigned short PS2TIMER=0; // PS2受信タイムアウトタイマー
volatile unsigned char PS2BUFF[PS2BUFFSIZE]; // PS2受信バッファ
volatile unsigned char PS2RPOS=0; // PS2読み出し位置
volatile unsigned char PS2WPOS=0; // PS2書き込み位置
void ps2key_init(void)
{
/* INT0 外部割込み初期化 */
//INT0 PS/2 CLOCK
intf0=0b00000001; // INT0 f1フィルタ使用 1*3/18.432=0.16us
iscr0=0b00000000; // INT0 立ち下がりエッジ
inten=0b00000001; // INT0 入力許可
{
unsigned char a;
for(a=(6*8); a!=0; a--) asm("nop"); // ちょっと時間待ち
}
// PMLi PMHi ISCR0 INTEN KIEN レジスタを書き換えると割り込み要求フラグが 1になることがある
// とマニュアルに書いてあるのでフラグをクリアする
while(1==iri0) iri0=0;
}
// 外部割込み INT0
// PS/2 CLOCK の立ち下がりで割り込みをかけて、1ビットづつデータを取り込む
#pragma INTERRUPT INT_int0 (vect=29)
void INT_int0(void)
{
static unsigned short bit=1;
static unsigned short data=0;
static unsigned char parity=0;
// 受信動作中で止まっていたら状態クリアして最初から受信
if((bit != 1) && (PS2TIMEOUT < PS2TIMER))
{
bit=1;
data=0;
parity=0;
}
// 下位ビットから1ビットづつ受信
if(0!=PS2DATA)
{
// 1
data+=bit;
parity++;
}
if(0b100_0000_0000==bit) // 11bit 読んだ スタートビット1 データビット8 パリティ1 ストップ1
{
parity--; // ストップビット分を引く
if(0!=(parity & 1)) // パリティチェック 1が奇数なら正常
{
// 正常受信
if((PS2BUFFSIZE-1) > ps2size())//バッファに空きがあるか?
{
PS2BUFF[PS2WPOS]=((data >> 1) & 0xFF);
if((PS2BUFFSIZE-1) > PS2WPOS)
{
PS2WPOS++;
}
else
{
PS2WPOS=0;
}
}
else
{
// バッファフル
}
}
else
{
// パリティエラー
}
bit=1;
data=0;
parity=0;
}
else
{
if((1==bit)&&(data!=0))
{ //スタートビットがゼロじゃない 状態リセット
bit=1;
data=0;
parity=0;
}
else
{ // 次のビットを読む準備
bit=(bit<<1);
PS2TIMER=0; // タイムアウトタイマークリア
}
}
while(1==iri0) iri0=0; // 自動的に割り込みフラグクリアされるので、この行無くていい
}
// バッファの有効データ数を返す
unsigned char ps2size(void)
{
signed int size;
size=(signed int)PS2WPOS-PS2RPOS;
if(0>size)
{
size=PS2BUFFSIZE+size;
}
return size;
// size=5 wpos=2 rpos=3 4
}
// 受信バッファをクリアする
void ps2clear(void)
{
PS2WPOS=0;
PS2RPOS=0;
PS2BUFF[PS2RPOS]=0;
}
// バッファから1byte読む
unsigned char ps2read(void)
{
unsigned char data=0;
if(PS2WPOS!=PS2RPOS) // バッファにデータはあるかな?
{
data=PS2BUFF[PS2RPOS];
if((PS2BUFFSIZE-1) > PS2RPOS)
{
PS2RPOS++;
}
else
{
PS2RPOS=0;
}
}
return data;
}
// 受信するまで待って1byte読む
unsigned char ps2get(void)
{
while(0==ps2size()); //バッファにデータが入るまで待つ
return ps2read();
}

27
src.original/ps2.h Normal file
View File

@@ -0,0 +1,27 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
PS/2 キーボードの受信処理
2014年7月22日 作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
#define PS2TIMEOUT 30 // PS2 タイムアウト 30*100[ms] = 3[s]
#define PS2BUFFSIZE 0x10
extern volatile unsigned short PS2TIMER; // PS2受信タイムアウトタイマー
//extern volatile unsigned char PS2BUFF[PS2BUFFSIZE]; // PS2受信バッファ
//extern volatile unsigned char PS2RPOS; // PS2読み出し位置
//extern volatile unsigned char PS2WPOS; // PS2書き込み位置
void ps2key_init(void);
unsigned char ps2size(void);
void ps2clear(void);
unsigned char ps2read(void);
unsigned char ps2get(void);

176
src.original/ps2.txt Normal file
View File

@@ -0,0 +1,176 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
PS/2 キーボードの受信処理
クロックの立ち下がりで1ビットづつ読むだけなので、簡単です。
スタートビット 1
データビット 8
パリティビット 1
ストップビット 1
計11ビット 奇数パリティ
送られてくるキーコードは http://kyoutan.jpn.org/uts/pc/pic/x68key/ に書きました。
2014年7月22日 作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
#include "sfr_r8m12a.h"
#include "ps2.h"
#include "iodefine.h"
volatile unsigned short PS2TIMER=0; // PS2受信タイムアウトタイマー
volatile unsigned char PS2BUFF[PS2BUFFSIZE]; // PS2受信バッファ
volatile unsigned char PS2RPOS=0; // PS2読み出し位置
volatile unsigned char PS2WPOS=0; // PS2書き込み位置
void ps2key_init(void)
{
/* INT0 外部割込み初期化 */
//INT0 PS/2 CLOCK
intf0=0b00000001; // INT0 f1フィルタ使用 1*3/18.432=0.16us
iscr0=0b00000000; // INT0 立ち下がりエッジ
inten=0b00000001; // INT0 入力許可
{
unsigned char a;
for(a=(6*8); a!=0; a--) asm("nop"); // ちょっと時間待ち
}
// PMLi PMHi ISCR0 INTEN KIEN レジスタを書き換えると割り込み要求フラグが 1になることがある
// とマニュアルに書いてあるのでフラグをクリアする
while(1==iri0) iri0=0;
}
// 外部割込み INT0
// PS/2 CLOCK の立ち下がりで割り込みをかけて、1ビットづつデータを取り込む
#pragma INTERRUPT INT_int0 (vect=29)
void INT_int0(void)
{
static unsigned short bit=1;
static unsigned short data=0;
static unsigned char parity=0;
// 受信動作中で止まっていたら状態クリアして最初から受信
if((bit != 1) && (PS2TIMEOUT < PS2TIMER))
{
bit=1;
data=0;
parity=0;
}
// 下位ビットから1ビットづつ受信
if(0!=PS2DATA)
{
// 1
data+=bit;
parity++;
}
if(0b100_0000_0000==bit) // 11bit 読んだ スタートビット1 データビット8 パリティ1 ストップ1
{
parity--; // ストップビット分を引く
if(0!=(parity & 1)) // パリティチェック 1が奇数なら正常
{
// 正常受信
if((PS2BUFFSIZE-1) > ps2size())//バッファに空きがあるか?
{
PS2BUFF[PS2WPOS]=((data >> 1) & 0xFF);
if((PS2BUFFSIZE-1) > PS2WPOS)
{
PS2WPOS++;
}
else
{
PS2WPOS=0;
}
}
else
{
// バッファフル
}
}
else
{
// パリティエラー
}
bit=1;
data=0;
parity=0;
}
else
{
if((1==bit)&&(data!=0))
{ //スタートビットがゼロじゃない 状態リセット
bit=1;
data=0;
parity=0;
}
else
{ // 次のビットを読む準備
bit=(bit<<1);
PS2TIMER=0; // タイムアウトタイマークリア
}
}
while(1==iri0) iri0=0; // 自動的に割り込みフラグクリアされるので、この行無くていい
}
// バッファの有効データ数を返す
unsigned char ps2size(void)
{
signed int size;
size=(signed int)PS2WPOS-PS2RPOS;
if(0>size)
{
size=PS2BUFFSIZE+size;
}
return size;
// size=5 wpos=2 rpos=3 4
}
// 受信バッファをクリアする
void ps2clear(void)
{
PS2WPOS=0;
PS2RPOS=0;
PS2BUFF[PS2RPOS]=0;
}
// バッファから1byte読む
unsigned char ps2read(void)
{
unsigned char data=0;
if(PS2WPOS!=PS2RPOS) // バッファにデータはあるかな?
{
data=PS2BUFF[PS2RPOS];
if((PS2BUFFSIZE-1) > PS2RPOS)
{
PS2RPOS++;
}
else
{
PS2RPOS=0;
}
}
return data;
}
// 受信するまで待って1byte読む
unsigned char ps2get(void)
{
while(0==ps2size()); //バッファにデータが入るまで待つ
return ps2read();
}

157
src.original/sect30.inc Normal file
View File

@@ -0,0 +1,157 @@
;----------------------------------------------------------------------
; |
; |
; |
; DESCRIPTION : Section definition. (for Assembler language) |
; |
; |
; This file is generated by Renesas Project Generator. |
; |
;----------------------------------------------------------------------
;/*********************************************************************
;*
;* Device : R8C/Mx
;*
;* File Name : sect30.inc
;*
;* Abstract : Section definition
;*
;* History : 1.00 (2011-02-01)
;*
;* NOTE : THIS IS A TYPICAL EXAMPLE.
;*
;* Copyright (C) 2011 Renesas Electronics Corporation. and
;* Renesas Solutions Corp. All rights reserved.
;*
;*********************************************************************/
;=====================================================================
;
; Definition of section
;
;---------------------------------------------------------------------
; Near RAM data area
;---------------------------------------------------------------------
; SBDATA area
.section data_SE,DATA,ALIGN
.section bss_SE,DATA,ALIGN
.section data_SO,DATA
.section bss_SO,DATA
; SBDATA area definition
; Sets the top address (__SB__) of the SBDATA area
; (it is accessing area to used the SBrelative addressing mode).
.glb __SB__
__SB__ .equ 400H
; near RAM area
.section data_NE,DATA,ALIGN
.section bss_NE,DATA,ALIGN
.section data_NO,DATA
.section bss_NO,DATA
;---------------------------------------------------------------------
; Stack area
;---------------------------------------------------------------------
.if __STACKSIZE__ != 0
.section stack,DATA,ALIGN
.blkb __STACKSIZE__
.endif
.section istack,DATA,ALIGN
.blkb __ISTACKSIZE__
;---------------------------------------------------------------------
; heap section
;---------------------------------------------------------------------
.if __HEAPSIZE__ != 0
.section heap_NE,DATA,ALIGN
.blkb __HEAPSIZE__
.endif
;---------------------------------------------------------------------
; Initial data of 'data' section
;---------------------------------------------------------------------
.section data_SEI,ROMDATA
.section data_SOI,ROMDATA
.section data_NEI,ROMDATA
.section data_NOI,ROMDATA
;---------------------------------------------------------------------
; variable vector section
;---------------------------------------------------------------------
.section vector,ROMDATA,ALIGN
; When you use "#pragma interrupt" with "vect=",
; you need not define interrupt vector.
;
; When you use "#pragma interrupt" without "vect=",
; you must define all interrupt vectors like the following example.
; You define dummy_int for interrupt vector not used.
;
; .lword dummy_int ; vector 0
; .lword dummy_int ; vector 1
; .lword dummy_int ; vector 2
; :
; .lword dummy_int ; vector 63
;---------------------------------------------------------------------
; fixed vector section
;---------------------------------------------------------------------
.section fvector,ROMDATA
.org 0ffd8H
; reserved
.addr 0FFFFFFH
; OFS2
.byte 0FFH
UDI:
.lword dummy_int
OVER_FLOW:
.lword dummy_int
BRKI:
.lword dummy_int
ADDRESS_MATCH:
.lword dummy_int
SINGLE_STEP:
.lword dummy_int
WDT:
.lword dummy_int
; reserved
.lword dummy_int
; reserved
.lword dummy_int
RESET:
.lword start
;=====================================================================
; ID code & Option function select register
;---------------------------------------------------------------------
; ID code check function
.id "#FFFFFFFFFFFFFF"
; option function select register
.ofsreg 0FFH
;---------------------------------------------------------------------
; far ROM data area
;---------------------------------------------------------------------
; .section data_FEI,ROMDATA
; .section data_FOI,ROMDATA
;=====================================================================
; Initialize Macro declaration
;---------------------------------------------------------------------
N_BZERO .macro TOP_ ,SECT_
mov.b #00H, R0L
mov.w #(TOP_ & 0FFFFH), A1
mov.w #sizeof SECT_ , R3
sstr.b
.endm
N_BCOPY .macro FROM_,TO_,SECT_
mov.w #(FROM_ & 0FFFFH),A0
mov.b #(FROM_ >>16),R1H
mov.w #TO_ ,A1
mov.w #sizeof SECT_ , R3
smovf.b
.endm

1772
src.original/sfr_r8m12a.h Normal file

File diff suppressed because it is too large Load Diff

1286
src.original/sfr_r8m12a.inc Normal file

File diff suppressed because it is too large Load Diff

60
src.original/timer.c Normal file
View File

@@ -0,0 +1,60 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
100[ms] のインターバルタイマー
PS/2 の受信タイムアウトで使っています。
2014年7月22日 作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
#include "sfr_r8m12a.h"
#include "timer.h"
#include "ps2.h"
#include "iodefine.h"
volatile unsigned short TIMER=0; // 100[ms]タイマー
void timer_init(void)
{
// TIMER RB2 初期化 100ms インターバルタイマー
msttrb=0; // スタンバイ解除
trbcr=0b00000100; // カウント停止
trbmr=0b01100100; // f64分周 16ビット タイマモード
/*
100[ms] = 100000[us] = 1843200
f2 921600
f4 460800
f8 230400
f16 115200
f32 57600
f64 28800 = 0x7080
*/
// 100[ms] = f64 0x7080
trbpre=0x80; // 下位8ビット
trbpr=0x70; // 上位8ビット
trbie_trbir=1; // 割り込み許可
}
/*
void timer_start(void)
{
tstart_trbcr=1; // TIMER RB2 カウント開始
}
*/
#pragma INTERRUPT INT_trb(vect=24)
void INT_trb(void)
{
TIMER++;
if(0xFF != PS2TIMER) PS2TIMER++; // タイムアウト処理用オーバーフローさせない
while(trbif_trbir==1) trbif_trbir=0; // 割り込みフラグクリア
}

19
src.original/timer.h Normal file
View File

@@ -0,0 +1,19 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
100[ms] のインターバルタイマー
2014年7月22日 作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
extern volatile unsigned short TIMER; // 100[ms]タイマー
void timer_init(void);
//void timer_start(void);
#define timer_start() tstart_trbcr=1 // TIMER RB2 カウント開始

188
src.original/uart.c Normal file
View File

@@ -0,0 +1,188 @@
#include "sfr_r8m12a.h"
#include "uart.h"
// バッファサイズは2の倍数じゃなきゃダメ
// バッファサイズを変更する場合スタックサイズを調整してRAMが溢れないように
/*#define buffsize 32
volatile unsigned char buff[buffsize];
volatile unsigned char readpos,writepos;
*/
void osc_init(void)
{
// 内蔵高速オシレーターに切り替え
prc0=1; // クロックレジスタアクセス許可
ococr=0b00000001; // 高速オンチップオシレーター発振 低速も発振
{
unsigned char a;
for(a=0; a<255; a++); // ここでオシレーターの発振が安定するのを待てとあるので適当に時間待ち
}
sckcr=0b01000000; // XIN/高速オシレーター選択で高速を選択 CPUクロック分周無し
ckstpr=0b10000000; // システムクロック低速/高速選択で高速を選択
phisel=0x00; // システムクロック分周無し
frv1=fr18s0; // 高速オンチップオシレーターを18.432MHzに調整
frv2=fr18s1;
prc0=0; // クロックレジスタアクセス禁止
}
void uart_init(void)
{
// UART0の設定
p14sel0=1;
p14sel1=0;
p14sel2=0; // P1_4をTXD
p15sel0=1;
p15sel1=0;
p15sel2=0; // P1_5をRXD
//#define RTS p1_0
// pd1_0=1;
// RTS=1; // 1:送信しないでください 0:送信してください
mstuart=0; // モジュールスタンバイ解除
u0mr=0b00000101; // 8ビット ストップビット1 パリティ無し
u0c0=0b00010000; // LSBファースト プッシュプル出力 フィルタON カウントソース分周無し
u0brg=119; // 9600bps
//u0brg=29; // 38400bps
//u0brg=19; // 57600bps
//u0brg=9; // 115200bps
u0rrm_u0c1=0; // 連続受信モード禁止
u0tie=0; // 送信割り込み禁止
u0rie=0; // 受信割り込み禁止
te_u0c1=1; // 送信許可
re_u0c1=1; // 受信許可
/*ilvl8=(ilvl8 & 0x0F) | (1 << 4); // 受信割り込みレベル1
u0rie=1; // 受信割り込み許可
readpos=0;
writepos=0;
asm("LDIPL #0"); // プロセッサ割り込み優先レベル0この値よりも高いレベルの割り込みが受け付けられる
asm("FSET I"); // 割り込み許可
RTS=0; // 送信要求
*/
}
void putch(unsigned char a)
{
while(ti_u0c1==0); // バッファが空になるまで待つ
u0tbh=0;
u0tbl=a;
}
void puts(unsigned char str[])
{
unsigned int a=0;
while(1)
{
if(str[a]==0) break;
putch(str[a]);
a++;
}
}
void puthex(unsigned char a)
{
putch(tochar((a&0xF0)>>4));
putch(tochar(a&0x0F));
}
unsigned char tochar(unsigned char a)
{
if(a<10) a=a+0x30;
else a=a+0x41-10;
return a;
}
void puthexshort(unsigned short a)
{
puthex((a>>8)&0xFF);
puthex((a&0xFF));
}
// なにか受信したら1を返す
unsigned char keyhit(void)
{
return (unsigned char)ri_u0c1;
}
// 割り込みを使わない1バイトリード
unsigned char getch(void)
{
// RTS=0; // 送信要求
while(ri_u0c1==0); // 受信するまで待つ
// RTS=1; // 送信禁止
return (unsigned char)(u0rb&0xFF); // u0rbを読むとriは0になる
}
// 割り込みを使う1バイトリード 受信バッファ付き
/*unsigned char getch(void)
{
unsigned char a;
while(writepos==readpos); // 受信するまで待つ
a=buff[readpos];
readpos++;
readpos&=(buffsize-1);
// 受信バッファが空になったら送信要求
if(writepos==readpos) RTS=0; // 送信要求
return a;
}*/
unsigned short getshort(void)
{
unsigned short data;
data =((unsigned short)getch()<<8);
data+=((unsigned short)getch() );
return data;
}
void putshort(unsigned short data)
{
putch((data>>8)&0xFF);
putch((data )&0xFF);
}
void putdecimal(unsigned short data)
{
putch(tochar(data/10000));
data=data%10000;
putch(tochar(data/1000));
data=data%1000;
putch(tochar(data/100));
data=data%100;
putch(tochar(data/10));
data=data%10;
putch(tochar(data));
}
/*
#pragma INTERRUPT int_uart_receive // int_uart_receive 関数は割り込みルーチンですよとコンパイラにお知らせ
void int_uart_receive(void)
{
signed char a;
// 割り込みフラグクリア
while(u0rif==1) u0rif==0;
buff[writepos]=(unsigned char)u0rb;
writepos++;
writepos&=(buffsize-1);
// バッファに溜まってきたら送信禁止にする
// RTSを1にしても、すぐには止まらないので閾値は余裕も持つ
a=writepos-readpos;
if(a>0)
{
if(a<4) RTS=1; // 送信禁止
}
else
{
if(a>-4) RTS=1; // 送信禁止
}
}
*/

14
src.original/uart.h Normal file
View File

@@ -0,0 +1,14 @@
void osc_init(void);
void uart_init(void);
void putch(unsigned char a);
void puts(unsigned char str[]);
void puthex(unsigned char a);
void puthexshort(unsigned short a);
unsigned short getshort(void);
void putshort(unsigned short data);
unsigned char getch(void);
unsigned char keyhit(void);
void putdecimal(unsigned short data);
unsigned char tochar(unsigned char a);

139
src.original/x1key.c Normal file
View File

@@ -0,0 +1,139 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
X1 キーボードの送信処理
X1センターさん (http://www.x1center.org/) の、キーボードの伝送フォーマット仕様を参考にしました。
X1キーボードの実物を持っていないので、大変助かりました。
X1センターさんの資料は「使える物があれば自由に使って下さい」とのことです。
2014年7月22日 作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
#include "sfr_r8m12a.h"
#include "x1key.h"
#include "iodefine.h"
unsigned short SEND_DATA; // X1送信データ
void X1_send(unsigned short data)
{
while(0 != tcstf_trjcr); // 送信中なら終わるまで待つ
SEND_DATA=data;
/* TIMER RJ */
trjioc= 0b00000011; /* TRJO Hから出力開始、TRJIO トグル出力無し */
trjmr= 0b00000001; /* パルス出力モード、分周無し */
trjcr= 0b00000100; /* カウント停止 出力ピン初期化 */
pmh3 = 0b10000000; // P3_7 TRJO X1KEYOUT を TRJO に
trjie_trjir=1; /* TIMER RJ 割り込み許可 */
trj=TRJ250us; // 250us セット 250us 後に L ヘッダー分250usに意味は無い。もっと短くても良い
tstart_trjcr=1; // タイマースタート
}
void x1key_init(void)
{
X1KEYOUT=1;
/* TIMER RJ 初期化*/
msttrj=0; // スタンバイ解除
trjcr= 0b00000100; /* カウント停止 */
trjioc= 0b00000011; /* TRJO Hから出力開始、TRJIO トグル出力無し */
trjmr= 0b00000001; /* パルス出力モード、分周無し */
trjcr= 0b00000100; /* カウント停止 出力ピン初期化 */
}
// TIMER RJ アンダーフロー割り込み
// タイマーの機能で、ダウンカウンタがアンダーフローするたびに、
// 出力ピン (TRJO) の出力が反転します
#pragma INTERRUPT INT_trj (vect=22)
void INT_trj(void)
{
static unsigned char count=0;
if(0==(count&1)) // 偶数 L 期間
{ // 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36
switch(count)
{
case 0: // header L
trj=TRJ1000us; // 1000us
break;
case 36: // stop 終了
while(1==tcstf_trjcr) tstart_trjcr=0; // タイマー停止(ビット操作だと出力初期化されないよう)
trjcr= 0b00000100; // カウント停止 出力ピン初期化
pmh3 =0b10000000; // P3_7 TRJO X1KEYOUT を TRJO に
break;
default:
trj=TRJ250us; // 250us
break;
}
}
else // 奇数 H 期間
{ // 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35
switch(count)
{
case 1: // header H
trj=TRJ700us;
break;
//case 3: // start H スタートビットいらない
//trj=TRJ750us;
// break;
case 35: // stop H 期間
X1KEYOUT=1; // H 出力
pmh3 =0b00000000; // P3_7 TRJO X1KEYOUT をI/Oポートに 反転出力動作終了
trj=TRJ1750us;
break;
default: // 上位ビットから16ビット送信
if(0==(SEND_DATA & 0x8000))
{
trj=TRJ750us; // 0
}
else
{
trj=TRJ1750us; // 1
}
SEND_DATA=(SEND_DATA<<1);
break;
}
}
count++;
if(36<count) count=0;
while(1==trjif_trjir) trjif_trjir=0; // 割り込みフラグクリア
}
// デバッグ用 1バイトを16進2桁で送出表示
void puth2(unsigned char a)
{
X1_send(((unsigned short)0b10111111 << 8) + tochar((a&0xF0)>>4));//押す
X1_send(((unsigned short)0b11111111 << 8) + 0x00);//離す
X1_send(((unsigned short)0b10111111 << 8) + tochar(a&0x0F));//押す
X1_send(((unsigned short)0b11111111 << 8) + 0x00);//離す
X1_send(((unsigned short)0b10111111 << 8) + 0x20);//押す
X1_send(((unsigned short)0b11111111 << 8) + 0x00);//離す
}
// デバッグ用 015の数を文字に変換
unsigned char tochar(unsigned char a)
{
if(a<10) a=a+0x30;
else a=a+0x41-10;
return a;
}

58
src.original/x1key.h Normal file
View File

@@ -0,0 +1,58 @@
/*
PS/2 キーボードを SHARP X1 につなぐ
X1 キーボードの送信処理
2014年7月22日 作成
佐藤恭一 http://kyoutan.jpn.org/
無保証です。
佐藤恭一が作成した部分は用途に制限を設けません。商用・非商用にかかわらず自由に使用して頂いて構いません。
勝手に複製したり、改造したり、配布したり、売ったりしても良いということです。
連絡不要です。
*/
/*
18.432MHz
1周期 = 1/18.432 = 0.0543[us]
256周期 = 256/18.432 = 13.89[us]
65536周期 = 65536/18.432 = 3555[us]
1750[us] 1750/(1/18.432) = 1750*(18.432/1) = 1750*18.432
= 32256 = 0x7E00
1000[us] = 1000 *18.432 = 18432 周期 = 0x4800
750[us] = 13824 = 0x3600
700[us] = 12902 = 0x3266
250[us] = 250*18.432 = 4608 = 0x1200
タイマーRB2のプログラム波形生成モードがいいかと思ったけど、プライマリ期間の
アンダーフローで割り込み要求できないようだったので、
タイマーRJ2のパルス出力モードを使うことにする。
*/
#define TRJ1750us (0x7E00 - 2)
#define TRJ1000us (0x4800 - 0) // タイマー停止状態で使うので、ここは引かない
#define TRJ750us (0x3600 - 2)
#define TRJ700us (0x3266 - 1)
#define TRJ250us (0x1200 - 2)
#define TRJSTOP (0xFFFF) // ストップビット後のおやすみ期間
// TRJレジスタに書いてから、リロードレジスタに転送されるまで 23サイクルかかるので
// そのぶん引いておく
void X1_send(unsigned short data);
void x1key_init(void);
unsigned char tochar(unsigned char a);
void puth2(unsigned char a);
//extern volatile unsigned short SEND_DATA; // X1送信データ
// b15 : 0=テンキーからの入力
// b14 : 0=キー入力有り
// b13 : 0=リピート有り
// b12 : 0=GRAPH ON
// b11 : 0=CAPS ON
// b10 : 0=カナ ON
// b09 : 0=SHIFT ON
// b08 : 0=CTRL ON
// b07-00 : ASCII CODE (0x00=KEY OFF)

68
timer.c Normal file
View File

@@ -0,0 +1,68 @@
/*
Connect a PS / 2 keyboard to SHARP X1
100 [ms] interval timer
I am using it for the PS/2 reception timeout.
Created July 22, 2014
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "sfr_r8m12a.h"
#include "timer.h"
#include "ps2.h"
#include "iodefine.h"
volatile unsigned short TIMER = 0; // 100 [ms] timer
void timer_init(void)
{
// TIMER RB2 initialization 100ms interval timer
msttrb = 0; // Release standby
trbcr = 0b00000100; // Stop counting
trbmr = 0b01100100; // f64 division 16-bit timer mode
/*
100 [ms] = 100000 [us] = f1 1843200
f2 921600
f4 460800
f8 230400
f16 115200
f32 57600
f64 28800 = 0x7080
*/
// 100 [ms] = f64 0x7080
trbpre = 0x80; // Lower 8 bits
trbpr = 0x70; // Upper 8 bits
trbie_trbir = 1; // Interrupt enabled
}
/*
void timer_start(void)
{
tstart_trbcr = 1; // TIMER RB2 count start
}
*/
#pragma INTERRUPT INT_trb(vect=24)
void INT_trb(void)
{
TIMER++;
if (0xFF != PS2TIMER) PS2TIMER++; // Do not overflow for timeout processing
while (trbif_trbir == 1) trbif_trbir = 0; // Clear interrupt flag
}
#ifdef __cplusplus
}
#endif

31
timer.h Normal file
View File

@@ -0,0 +1,31 @@
/*
Connect a PS / 2 keyboard to SHARP X1
100 [ms] interval timer
Created July 22, 2014
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
#ifndef TIMER_H
#define TIMER_H
#ifdef __cplusplus
extern "C" {
#endif
extern volatile unsigned short TIMER; // 100 [ms] timer
void timer_init (void);
// void timer_start(void);
#define timer_start() tstart_trbcr = 1 // TIMER RB2 Count start
#ifdef __cplusplus
}
#endif
#endif // TIMER_H

194
uart.c Normal file
View File

@@ -0,0 +1,194 @@
#ifdef __cplusplus
extern "C" {
#endif
#include "sfr_r8m12a.h"
#include "uart.h"
// Buffer size must be a multiple of 2
// When changing the buffer size Adjust the stack size so that RAM does not overflow
/* #define buffsize 32
volatile unsigned char buff [buffsize];
volatile unsigned char readpos, writepos;
*/
void osc_init (void)
{
// Switch to built-in high speed oscillator
prc0 = 1; // Clock register permission
ococr = 0b00000001; // High-speed on-chip oscillator oscillation Low-speed oscillation
{
unsigned char a;
for (a = 0; a <255; a ++); // Wait for the oscillator oscillation to stabilize, so wait for an appropriate amount of time.
}
sckcr = 0b01000000; // Select high speed by selecting XIN / high speed oscillator No CPU clock division
ckstpr = 0b10000000; // Select high speed by system clock low speed / high speed selection
phisel = 0x00; // No system clock division
frv1 = fr18s0; // Adjust high speed on-chip oscillator to 18.432MHz
frv2 = fr18s1;
prc0 = 0; // Clock register access prohibited
}
void uart_init(void)
{
// UART0 settings
p14sel0 = 1;
p14sel1 = 0;
p14sel2 = 0; // TXD P1_4
p15sel0 = 1;
p15sel1 = 0;
p15sel2 = 0; // RXD P1_5
// # define RTS p1_0
// pd1_0 = 1;
// RTS = 1; // 1: Please do not send 0: Please send
mstuart = 0; // Release module standby
u0mr = 0b00000101; // 8-bit stop bit 1 no parity
u0c0 = 0b00010000; // LSB first push-pull output filter ON count source no frequency division
u0brg = 119; // 9600bps
// u0brg = 29; // 38400bps
// u0brg = 19; // 57600bps
// u0brg = 9; // 115200bps
u0rrm_u0c1 = 0; // Continuous reception mode prohibited
u0tie = 0; // Send interrupt disabled
u0rie = 0; // Receive interrupt disabled
te_u0c1 = 1; // Send permission
re_u0c1 = 1; // Acceptance
/* ilvl8 = (ilvl8 & 0x0F) | (1 << 4); // Receive interrupt level 1
u0rie = 1; // Receive interrupt enabled
readpos = 0;
writepos = 0;
asm ("LDIPL # 0"); // Processor interrupt priority level 0 (interrupts higher than this value are accepted)
asm ("FSET I"); // Interrupt enabled
RTS = 0; // Send request
*/
}
void putch(unsigned char a)
{
while (ti_u0c1 == 0); // Wait until the buffer is empty
u0tbh = 0;
u0tbl = a;
}
void puts(unsigned char str [])
{
unsigned int a = 0;
while (1)
{
if (str [a] == 0) break;
putch (str [a]);
a ++;
}
}
void puthex(unsigned char a)
{
putch (tochar ((a & 0xF0) >> 4));
putch (tochar (a & 0x0F));
}
unsigned char tochar(unsigned char a)
{
if (a <10) a = a + 0x30;
else a = a + 0x41-10;
return a;
}
void puthexshort(unsigned short a)
{
puthex ((a >> 8) & 0xFF);
puthex ((a & 0xFF));
}
// Returns 1 when something is received
unsigned char keyhit(void)
{
return (unsigned char) ri_u0c1;
}
// 1-byte read without interrupts
unsigned char getch(void)
{
// RTS = 0; // Send request
while (ri_u0c1 == 0); // Wait until received
// RTS = 1; // Send prohibited
return (unsigned char) (u0rb & 0xFF); // ri becomes 0 when reading u0rb
}
// With 1-byte read receive buffer using interrupts
/* unsigned char getch (void)
{
unsigned char a;
while (writepos == readpos); // Wait until received
a = buff [readpos];
readpos ++;
readpos & = (buffsize-1);
// Send request when the receive buffer becomes empty
if (writepos == readpos) RTS = 0; // Send request
return a;
} */
unsigned short getshort(void)
{
unsigned short data;
data = ((unsigned short) getch () << 8);
data + = ((unsigned short) getch ());
return data;
}
void putshort(unsigned short data)
{
putch ((data >> 8) & 0xFF);
putch ((data) & 0xFF);
}
void putdecimal(unsigned short data)
{
putch (tochar (data / 10000));
data = data% 10000;
putch (tochar (data / 1000));
data = data% 1000;
putch (tochar (data / 100));
data = data% 100;
putch (tochar (data / 10));
data = data% 10;
putch (tochar (data));
}
/*
#pragma INTERRUPT int_uart_receive // Notify the compiler that the int_uart_receive function is an interrupt routine
void int_uart_receive(void)
{
signed char a;
// Clear interrupt flag
while (u0rif == 1) u0rif == 0;
buff [writepos] = (unsigned char) u0rb;
writepos ++;
writepos & = (buffsize-1);
// Prohibit transmission when it accumulates in the buffer
// Even if RTS is set to 1, the threshold does not stop immediately, so the threshold has a margin.
a = writepos-readpos;
if (a> 0)
{
if (a <4) RTS = 1; // Send prohibited
}
else
{
if (a> -4) RTS = 1; // Send prohibited
}
}
*/
#ifdef __cplusplus
}
#endif

25
uart.h Normal file
View File

@@ -0,0 +1,25 @@
#ifndef UART_H
#define UART_H
#ifdef __cplusplus
extern "C" {
#endif
void osc_init(void);
void uart_init(void);
void putch(unsigned char a);
void puts(unsigned char str[]);
void puthex(unsigned char a);
void puthexshort(unsigned short a);
unsigned short getshort(void);
void putshort(unsigned short data);
unsigned char getch(void);
unsigned char keyhit(void);
void putdecimal(unsigned short data);
unsigned char tochar(unsigned char a);
#ifdef __cplusplus
}
#endif
#endif // UART_H

146
x1key.c Normal file
View File

@@ -0,0 +1,146 @@
/*
Connect a PS / 2 keyboard to SHARP X1
X1 keyboard transmission process
.
I referred to the keyboard transmission format specifications of X1 Center (http://www.x1center.org/).
I don't have the actual X1 keyboard, so it was very helpful.
The material of X1 Center says, "If you have something you can use, feel free to use it."
.
Created July 22, 2014
.
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "sfr_r8m12a.h"
#include "x1key.h"
#include "iodefine.h"
unsigned short SEND_DATA; // X1 transmission data
void X1_send(unsigned short data)
{
while (0 != tcstf_trjcr); // Wait until it finishes if sending
SEND_DATA = data;
/* TIMER RJ */
trjioc = 0b00000011; /* Start output from TRJO H, no TRJIO toggle output */
trjmr = 0b00000001; /* Pulse output mode, no frequency division */
trjcr = 0b00000100; /* Stop counting Output pin initialization */
pmh3 = 0b10000000; // P3_7 TRJO X1KEYOUT to TRJO
trjie_trjir=1; /* TIMER RJ interrupt enabled */
trj=TRJ250us; // 250us set (250us followed by L header) 250us has no meaning. May be shorter
tstart_trjcr = 1; // Timer start
}
void x1key_init(void)
{
X1KEYOUT = 1;
/* TIMER RJ initialization */
msttrj = 0; // Release standby
trjcr = 0b00000100; /* Stop counting */
trjioc = 0b00000011; /* Start output from TRJO H, no TRJIO toggle output */
trjmr = 0b00000001; /* Pulse output mode, no frequency division */
trjcr = 0b00000100; /* Stop counting Output pin initialization */
}
// TIMER RJ Underflow interrupt
// With the timer function, every time the down counter underflows
// The output of the output pin (TRJO) is inverted
#pragma INTERRUPT INT_trj (vect = 22)
void INT_trj(void)
{
static unsigned char count = 0;
if (0 == (count & 1)) // even L period
{// 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36
switch (count)
{
case 0: // header L
trj = TRJ1000us; // 1000us
break;
case 36: // stop End
while (1 == tcstf_trjcr) tstart_trjcr = 0; // Timer stop (output is not initialized if it is a bit operation)
trjcr = 0b00000100; // Stop counting Output pin initialization
pmh3 = 0b10000000; // P3_7 TRJO X1KEYOUT to TRJO
break;
default:
trj = TRJ250us; // 250us
break;
}
}
else // odd H period
{// 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35
switch (count)
{
case 1: // header H
trj = TRJ700us;
break;
// case 3: // start H I don't need a start bit
// trj = TRJ750us;
// break;
case 35: // stop H period
X1KEYOUT = 1; // H output
pmh3 = 0b00000000; // P3_7 TRJO X1KEYOUT to I / O port Inverted output operation finished
trj = TRJ1750us;
break;
default: // 16-bit transmission from the most significant bit
if (0 == (SEND_DATA & 0x8000))
{
trj = TRJ750us; // 0
}
else
{
trj = TRJ1750us; // 1
}
SEND_DATA = (SEND_DATA << 1);
break;
}
}
count++;
if (36 <count) count = 0;
while (1 == trjif_trjir) trjif_trjir = 0; // Clear interrupt flag
}
// Send 1 byte for debugging in 2 hexadecimal digits (display)
void puth2(unsigned char a)
{
X1_send (((unsigned short) 0b10111111 << 8) + tochar ((a & 0xF0) >> 4)); // Press
X1_send (((unsigned short) 0b11111111 << 8) + 0x00); // Release
X1_send (((unsigned short) 0b10111111 << 8) + tochar (a & 0x0F)); // Press
X1_send (((unsigned short) 0b11111111 << 8) + 0x00); // Release
X1_send (((unsigned short) 0b10111111 << 8) + 0x20); // Press
X1_send (((unsigned short) 0b11111111 << 8) + 0x00); // Release
}
// Convert numbers from 0 to 15 for debugging to characters
unsigned char tochar(unsigned char a)
{
if (a <10) a = a + 0x30;
else a = a + 0x41-10;
return a;
}
#ifdef __cplusplus
}
#endif

68
x1key.h Normal file
View File

@@ -0,0 +1,68 @@
/*
Connect a PS / 2 keyboard to SHARP X1
X1 keyboard transmission process
Created July 22, 2014
Kyoichi Sato http://kyoutan.jpn.org/
There is no guarantee.
The part created by Kyoichi Sato has no restrictions on its use. You can use it freely regardless of whether it is commercial or non-commercial.
It means that you can copy, modify, distribute, or sell it without permission.
No need to contact.
*/
#ifndef X1KEY_H
#define X1KEY_H
#ifdef __cplusplus
extern "C" {
#endif
/* 18.432MHz
1 cycle = 1 / 18.432 = 0.0543 [us]
256 cycles = 256 / 18.432 = 13.89 [us]
65536 cycle = 65536 / 18.432 = 3555 [us]
1750 [us] 1750 / (1 / 18.432) = 1750 * (18.432/1) = 1750 * 18.432
= 32256 = 0x7E00
1000 [us] = 1000 * 18.432 = 18432 Cycle = 0x4800
750 [us] = 13824 = 0x3600
700 [us] = 12902 = 0x3266
250 [us] = 250 * 18.432 = 4608 = 0x1200
I thought that the program waveform generation mode of timer RB2 would be good, but for the primary period
I couldn't request an interrupt due to underflow, so
I decided to use the pulse output mode of timer RJ2.
*/
#define TRJ1750us (0x7E00 - 2)
#define TRJ1000us (0x4800 - 0) // Since it is used with the timer stopped, do not pull here
#define TRJ750us (0x3600 - 2)
#define TRJ700us (0x3266 - 1)
#define TRJ250us (0x1200 - 2)
#define TRJSTOP (0xFFFF) // Good night period after stop bit
// It takes 2 to 3 cycles from writing to the TRJ register to transferring to the reload register.
// Pull that much
void X1_send(unsigned short data);
void x1key_init(void);
unsigned char tochar(unsigned char a);
void puth2(unsigned char a);
// extern volatile unsigned short SEND_DATA; // X1 transmission data
// b15: 0 = Input from the numeric keypad
// b14: 0 = With key input
// b13: 0 = With repeat
// b12: 0 = GRAPH ON
// b11: 0 = CAPS ON
// b10: 0 = Kana ON
// b09: 0 = SHIFT ON
// b08: 0 = CTRL ON
// b07-00: ASCII CODE (0x00 = KEY OFF)
#ifdef __cplusplus
}
#endif
#endif // X1KEY_H

2
x1key.hbp Normal file
View File

@@ -0,0 +1,2 @@
[Setting]
ToolChain=0

233
x1key.hwp Normal file
View File

@@ -0,0 +1,233 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"2.8"
[PROJECT_DETAILS]
"X1key" "D:\Renesas\x1key" "D:\Renesas\x1key\X1key.hwp" "M16C" "Renesas M16C Standard" "Application" "R8C/Tiny" "R8C/M12A"
[INFORMATION]
"プロジェクト情報がありません"
[TOOL_CHAIN]
"Renesas M16C Standard Toolchain" "6.00.00"
[CONFIGURATIONS]
"Debug" "D:\Renesas\x1key\Debug"
"Release" "D:\Renesas\x1key\Release"
[BUILD_PHASES]
"Renesas M16C Assembler" 1
"Renesas M16C C/C++ Compiler" 1
"Renesas M16C C/C++ Library Generator" 1
"Renesas M16C Configurator" 1
"Renesas M16C ConfiguratorR8C" 1
"Renesas OptLinker" 1
[TOOL_ENVIRONMENT]
[EXTENSIONS]
"Absolute file" "ABS"
"Absolute list file" "ALS"
"Assembler error tag file" "ATG"
"Assembly include file" "INC"
"Assembly source file" "A30"
"Binary file" "BIN"
"Branch Information file" "JIN"
"C header file" "H"
"C source file" "C"
"C++ header file" "HPP"
"C++ source file" "CC"
"C++ source file" "CP"
"C++ source file" "CPP"
"Calling information file" "CAL"
"Configuration file" "CFG"
"Cross reference file" "XRF"
"Hex file" "HEX"
"ID file" "ID"
"IEEE695 Absolute file" "X30"
"Inspector Information file" "UTL"
"Library file" "LIB"
"Library information file" "LBP"
"Library list file" "LLS"
"Linkage error tag file" "LTG"
"Linkage map file" "MAP"
"List file" "LST"
"MISRA report file" "CSV"
"MISRA rule file" "RDE"
"Object file" "OBJ"
"Preprocessed C source file" "I"
"Profile file" "PRO"
"Relocatable file" "R30"
"Relocatable file" "REL"
"S-Record file" "MOT"
"Stack information file" "SNI"
"Systemcall file" "MRC"
[FILE_GROUPS]
"Absolute file" "BIN" "NONE" ""
"Absolute list file" "TEXT" "EDITOR" ""
"Assembler error tag file" "TEXT" "EDITOR" ""
"Assembly include file" "TEXT" "EDITOR" ""
"Assembly source file" "TEXT" "EDITOR" ""
"Binary file" "BIN" "NONE" ""
"Branch Information file" "TEXT" "EDITOR" ""
"C header file" "TEXT" "EDITOR" ""
"C source file" "TEXT" "EDITOR" ""
"C++ header file" "TEXT" "EDITOR" ""
"C++ source file" "TEXT" "EDITOR" ""
"Calling information file" "BIN" "NONE" ""
"Configuration file" "TEXT" "EDITOR" ""
"Cross reference file" "TEXT" "EDITOR" ""
"Hex file" "TEXT" "EDITOR" ""
"ID file" "TEXT" "EDITOR" ""
"IEEE695 Absolute file" "BIN" "NONE" ""
"Inspector Information file" "BIN" "NONE" ""
"Library file" "BIN" "NONE" ""
"Library information file" "TEXT" "EDITOR" ""
"Library list file" "TEXT" "EDITOR" ""
"Linkage error tag file" "TEXT" "EDITOR" ""
"Linkage map file" "TEXT" "EDITOR" ""
"List file" "TEXT" "EDITOR" ""
"MISRA report file" "TEXT" "EDITOR" ""
"MISRA rule file" "TEXT" "EDITOR" ""
"Object file" "BIN" "NONE" ""
"Preprocessed C source file" "TEXT" "EDITOR" ""
"Profile file" "BIN" "NONE" ""
"Relocatable file" "BIN" "NONE" ""
"S-Record file" "TEXT" "EDITOR" ""
"Stack information file" "BIN" "NONE" ""
"Systemcall file" "TEXT" "EDITOR" ""
[ASSOCIATED_APPLICATIONS]
[TOOLCHAIN_PHASE]
"Renesas M16C Assembler"
"Renesas M16C C/C++ Compiler"
"Renesas M16C C/C++ Library Generator"
"Renesas M16C Configurator"
"Renesas M16C ConfiguratorR8C"
"Renesas OptLinker"
[UTILITY_PHASE]
[CUSTOM_PHASES]
[CUSTOM_PHASE_INPUT_GROUP]
[CUSTOM_PHASE_OUTPUT_SYNTAX]
[BUILD_ORDER]
"Renesas M16C C/C++ Library Generator" 1
"Renesas M16C C/C++ Compiler" 1
"Renesas M16C Assembler" 1
"Renesas OptLinker" 1
"Renesas M16C ConfiguratorR8C" 0
"Renesas M16C Configurator" 0
[BUILD_PHASE_DETAILS]
"Renesas M16C Assembler" "Assembly source file" 1
"Renesas M16C C/C++ Compiler" "C source file|C++ source file" 1
"Renesas M16C C/C++ Library Generator" "" 0
"Renesas M16C Configurator" "Configuration file" 0
"Renesas M16C ConfiguratorR8C" "Configuration file" 0
"Renesas OptLinker" "Object file|Library file|Relocatable file" 0
[BUILD_FILE_ORDER_Assembly source file]
"Renesas M16C Assembler" 1
[BUILD_FILE_ORDER_C source file]
"Renesas M16C C/C++ Compiler" 1
[BUILD_FILE_ORDER_C++ source file]
"Renesas M16C C/C++ Compiler" 1
[SCRAP]
"Project Generator Setup File" ""
[MAPPINGS]
"Assembly source file" "Renesas M16C Assembler" "Renesas M16C C/C++ Compiler"
"Library file" "Renesas OptLinker" "Renesas M16C C/C++ Library Generator"
"Object file" "Renesas OptLinker" "Renesas M16C Assembler"
"Object file" "Renesas OptLinker" "Renesas M16C C/C++ Compiler"
[PROJECT_FILES]
"D:\Renesas\x1key\main.h" "User" "C header file" 2
"D:\Renesas\x1key\iodefine.h" "User" "C header file" 2
"D:\Renesas\x1key\keyconv.c" "User" "C source file" 2
"D:\Renesas\x1key\keyconv.h" "User" "C header file" 2
"D:\Renesas\x1key\keytable.h" "User" "C header file" 2
"D:\Renesas\x1key\main.c" "User" "C source file" 2
"D:\Renesas\x1key\ncrt0.a30" "User" "Assembly source file" 2
"D:\Renesas\x1key\ps2.c" "User" "C source file" 2
"D:\Renesas\x1key\ps2.h" "User" "C header file" 2
"D:\Renesas\x1key\timer.c" "User" "C source file" 2
"D:\Renesas\x1key\timer.h" "User" "C header file" 2
"D:\Renesas\x1key\x1key.c" "User" "C source file" 2
"D:\Renesas\x1key\x1key.h" "User" "C header file" 2
[FOLDER]
"Assembly source file" "Assembly source file"
"C header file" "C header file"
"C source file" "C source file"
[GENERAL_DATA_PROJECT]
"USE_CUSTOM_LINKAGE_ORDER" "1"
[ON_DEMAND_COMPONENTS_LOADED]
[SYNC_SESSION_NAMES]
[SESSIONS]
"DefaultSession" "D:\Renesas\x1key\DefaultSession.hsf" 0
[GENERAL_DATA_SESSION_DefaultSession]
[OPTIONS_Debug_Renesas M16C Assembler]
"Assembly source file" "0c08a6ad3a0afc10" 4
"D:\Renesas\x1key\ncrt0.a30" "0c08a6ad3a0afc10" 4
[OPTIONS_Debug_Renesas M16C C/C++ Compiler]
"C source file" "0c08a6ad3a0afc10" 2
"C++ source file" "0d255f408a0afc10" 3
"D:\Renesas\x1key\keyconv.c" "0005bc57566afc10" 2
"D:\Renesas\x1key\main.c" "0f26a3f24a0afc10" 2
"D:\Renesas\x1key\ps2.c" "0697e34f775afc10" 2
"D:\Renesas\x1key\timer.c" "05a40b30775afc10" 2
"D:\Renesas\x1key\x1key.c" "02c4a5fd475afc10" 2
[OPTIONS_Debug_Renesas M16C C/C++ Library Generator]
"Single Shot" "0c08a6ad3a0afc10" 1
[OPTIONS_Debug_Renesas M16C Configurator]
"Single Shot" "0005bc57566afc10" 6
[OPTIONS_Debug_Renesas M16C ConfiguratorR8C]
"Single Shot" "0005bc57566afc10" 6
[OPTIONS_Debug_Renesas OptLinker]
"Single Shot" "0fa00d57566afc10" 5
[OPTIONS_Debug]
"" 0
"[V|VERSION|1] [B|COMMAND|1] [S|SPEC|UITRON4] " 6
"[V|VERSION|1] [S|DEFINE|__UART0__] [S|LANG|CPP] [S|OUTPUT|OBJECTCODE] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [S|MISRA|ALL] [B|SILENT|1] [S|CPU|R8C]
" 3
"[V|VERSION|1] [S|LIST|LM] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [B|DISABLES_MESSAGE|1] [S|CPU|R8C] " 4
"[V|VERSION|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(PROJECTNAME).lib^"] [S|CPU|R8C] [B|NOFLOAT|1] [S|MODE|BUILD/CHANGED]" 1
"[V|VERSION|1] [S|OUTPUT|OBJECTCODE] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [B|INSPECTOR|1] [B|SILENT|1] [S|CPU|R8C] [S|DEFINE|__UART0__] " 2
"[V|VERSION|6] [B|OPTIMIZE|0] [B|DEBUG|1] [S|OUTPUT|^"$(CONFIGDIR)\$(PROJECTNAME).mot^"] [B|LIST|1] [S|LIST|^"$(CONFIGDIR)\$(PROJECTNAME).map^"] [S|OTHER|^"-change_message=information=1100,1322,1410^"] [S|FORM|STYPE] [B|TOTAL_SIZE|1] [B|STACK|1] [S|START|data_SE,bss_SE,data_SO,bss_SO,data_NE,bss_NE,data_NO,bss_NO,stack,istack,heap_NE(400)|interrupt,rom_NE,rom_NO,data_SEI,data_SOI,data_NEI,data_NOI,switch_table,C$VTBL,program(e000)|vector(fed8)]" 5
[EXCLUDED_FILES_Debug]
[LINKAGE_ORDER_Debug]
"D:\Renesas\x1key\Debug\ncrt0.r30"
[GENERAL_DATA_CONFIGURATION_Debug]
[OPTIONS_Release_Renesas M16C Assembler]
"Assembly source file" "07cdf9d0e95afc10" 4
"D:\Renesas\x1key\ncrt0.a30" "07cdf9d0e95afc10" 4
[OPTIONS_Release_Renesas M16C C/C++ Compiler]
"C source file" "0f9e27549d9afc10" 2
"C++ source file" "0f9e27549d9afc10" 3
"D:\Renesas\x1key\keyconv.c" "0f9e27549d9afc10" 2
"D:\Renesas\x1key\main.c" "0f9e27549d9afc10" 2
"D:\Renesas\x1key\ps2.c" "0f9e27549d9afc10" 2
"D:\Renesas\x1key\timer.c" "0f9e27549d9afc10" 2
"D:\Renesas\x1key\x1key.c" "0f9e27549d9afc10" 2
[OPTIONS_Release_Renesas M16C C/C++ Library Generator]
"Single Shot" "07cdf9d0e95afc10" 1
[OPTIONS_Release_Renesas M16C Configurator]
"Single Shot" "0005bc57566afc10" 6
[OPTIONS_Release_Renesas M16C ConfiguratorR8C]
"Single Shot" "0005bc57566afc10" 6
[OPTIONS_Release_Renesas OptLinker]
"Single Shot" "00024c3dd5aafc10" 5
[OPTIONS_Release]
"" 0
"[V|VERSION|1] [B|COMMAND|1] [S|SPEC|UITRON4] " 6
"[V|VERSION|1] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [S|LIST|L|M] [B|DISABLES_MESSAGE|1] [S|CPU|R8C]
" 4
"[V|VERSION|1] [S|DEFINE|__UART0__] [S|LANG|CPP] [S|OUTPUT|OBJECTCODE] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [S|OPTIMIZE|5] [B|OR|1] [S|MISRA|ALL] [B|SILENT|1] [S|CPU|R8C]
" 3
"[V|VERSION|1] [S|DEFINE|__UART0__] [S|LANG|C] [S|OUTPUT|OBJECTCODE] [B|INSPECTOR|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(FILELEAF).obj^"] [S|OPTIMIZE|5] [B|OR|1] [S|MISRA|ALL] [B|SILENT|1] [S|CPU|R8C]
" 2
"[V|VERSION|1] [S|MODE|BUILD/CHANGED] [S|EXISTOUTPUTPATH|^"$(CONFIGDIR)\$(PROJECTNAME).lib^"] [B|NOFLOAT|1] [S|OUTPUTPATH|^"$(CONFIGDIR)\$(PROJECTNAME).lib^"] [S|OPTIMIZE|3] [S|OPTIMIZERS|OR] [S|CPU|R8C]
" 1
"[V|VERSION|6] [S|FORM|STYPE] [S|BYTE_COUNT_VALUE|FF] [B|DEBUG|0] [S|CRC|NONE|00000000] [B|LIST|1] [S|LIST|^"$(CONFIGDIR)\$(PROJECTNAME).map^"] [S|SHOW|METHODCUSTOM|] [S|OUTPUT|^"$(CONFIGDIR)\$(PROJECTNAME).mot^"] [I|SPACE|^"FF^"] [S|OPTIMIZEITEMS|ALL] [S|START|data_SE,bss_SE,data_SO,bss_SO,data_NE,bss_NE,data_NO,bss_NO,stack,istack,heap_NE(0400)|program_dataflash,flash_data_NE,flash_data_NO(03000)|interrupt,rom_NE,rom_NO,data_SEI,data_SOI,data_NEI,data_NOI,switch_table,C$VTBL,program(0F800)|vector(0FED8)] [B|STACK|1] [B|TOTAL_SIZE|1] [S|OTHER|^"-change_message=information=1100,1322,1410^"]
" 5
[EXCLUDED_FILES_Release]
[LINKAGE_ORDER_Release]
"D:\Renesas\x1key\Release\ncrt0.r30"
[GENERAL_DATA_CONFIGURATION_Release]
[GENERAL_DATA_CONFIGURATION_SESSION_Debug_DefaultSession]
[SESSION_DATA_CONFIGURATION_SESSION_Debug_DefaultSession]
"MEMORY_MAPPING_OPTIONS" ""
[GENERAL_DATA_CONFIGURATION_SESSION_Release_DefaultSession]
[SESSION_DATA_CONFIGURATION_SESSION_Release_DefaultSession]
"MEMORY_MAPPING_OPTIONS" ""
[EXT_DEBUGGER_INFO]
0 "" "" "" ""
[END]

40
x1key.hws Normal file
View File

@@ -0,0 +1,40 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"11.0"
[WORKSPACE_DETAILS]
"X1keyboard" "D:\Renesas\x1key" "D:\Renesas\x1key\x1key.hws" "M16C" "Renesas M16C Standard"
[SHARED_WORKSPACE_CONTROL_STATUS]
"" "" ""
"" "" ""
[PROJECTS]
"X1keyboard" "D:\Renesas\x1key" "D:\Renesas\x1key\x1key.hwp" 0
[INFORMATION]
"ワークスペース情報がありません"
[SCRAP]
[PROJECT_DEPENDENCY]
[WORKSPACE_PROPERTIES]
[HELP_FILES]
[GENERAL_DATA_PROJECT]
[USERMENUTOOLS]
[CUSTOMPLACEHOLDERS]
[MAKEFILE_BUILD_INFO]
"$(WORKSPDIR)\make\$(PROJECTNAME)_$(CONFIGNAME).mak" "" "$(WORKSPDIR)\make" 0 0 0
[VD_CONFIGURATION_OPTIONS]
"ACTIVE_DESKTOP" "0"
[VD_CONFIGURATIONS]
"0" "Default1" "1"
"1" "Default2" "1"
"2" "Default3" "1"
"3" "Default4" "1"
[OPTIONS_DEBUG_TAB]
0 0 0 0 0
[VCS]
"" "" "" 0
[VCS_PROJECT]
[MAKEFILE_ENV_STRINGS]
[MAKEFILE_ENV_FLAGS]
1 0 0
[MAKEFILE_CLEAN_INFO]
""
[END]

BIN
x1key.nav Normal file

Binary file not shown.

26
x1key.tps Normal file
View File

@@ -0,0 +1,26 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"1.1"
[SESSIONS_]
"DefaultSession"
[CONFIGURATIONS]
"Debug"
"Release"
[CURRENT_CONFIGURATION]
"Release"
[CURRENT_SESSION]
"DefaultSession"
[GENERAL_DATA_PROJECT]
[GENERAL_DATA_CONFIGURATION_Debug]
"PROJECT_FILES_MODIFIED_DATA_TAG" "TRUE"
[SESSIONS_Debug]
"DefaultSession"
[GENERAL_DATA_CONFIGURATION_Release]
"PROJECT_FILES_MODIFIED_DATA_TAG" "FALSE"
[SESSIONS_Release]
"DefaultSession"
[GENERAL_DATA_SESSION_DefaultSession]
[GENERAL_DATA_CONFIGURATION_SESSION_Debug_DefaultSession]
[GENERAL_DATA_CONFIGURATION_SESSION_Release_DefaultSession]
[END]

15
x1key.tws Normal file
View File

@@ -0,0 +1,15 @@
[HIMDBVersion]
2.0
[DATABASE_VERSION]
"1.2"
[CURRENT_PROJECT]
"X1key"
[GENERAL_DATA]
[BREAKPOINTS]
[OPEN_WORKSPACE_FILES]
"D:\Renesas\x1key\main.c"
[WORKSPACE_FILE_STATES]
"D:\Renesas\x1key\main.c" -8 -30 1724 594 1 0
[LOADED_PROJECTS]
"X1key"
[END]