Repository navigation
Expand file tree
/
Copy pathappendix-target-specific.tex
More file actions
119 lines (88 loc) · 6.23 KB
/
Copy pathappendix-target-specific.tex
File metadata and controls
119 lines (88 loc) · 6.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
\chapter{Model Specific Features}
\section{Detecting MEGA65 Models}
While we expect the production version of the MEGA65 to be a stable platform, there may still be
cases where detecting which hardware your program is running on. This is particularly important
for the MEGA65 system software, which may need to initialise different pieces of hardware on the
different models. Also, because there is a hand-held version of the MEGA65 already in development,
which uses a slightly different resolution screen (800x480 instead of 720x576), and has a touch
screen but no hardware keyboard, you may wish to make programs that adapt to the hand-held
devices in a more graceful way. For example, you may enable touch-screen input, and restructure
on-screen selections to be large enough to be easily activated by a finger.
The simple way to detect which model of MEGA65 your program is running on, is to check the
\$D629 register (but don't forget to enable the MEGA65 I/O personality first, via \$D02F).
This contains an 8-bit hardware identifier. The following values are currently defined:
\begin{description}[align=left,labelwidth=0.2cm]
\item[\$01 (1)] MEGA65 R1
\item[\$02 (2)] MEGA65 R2
\item[\$03 (3)] MEGA65 R3
\item[\$21 (33)] MEGAphone (hand-held) R1
\item[\$40 (64)] Nexys4 PSRAM
\item[\$41 (65)] Nexys4DDR
\item[\$42 (66)] Nexys4DDR with widget board
\item[\$FD (253)] QMTECH Wukong A100T board
\item[\$FE (254)] Simulation run of VHDL
\end{description}
\section{MEGA65 Desktop Computer, Revision 3 onwards}
The R3 desktop PCB is very similar to the R2 desktop PCB, with two key changes:
\begin{itemize}
\item First, the R3 PCB does not have an ADV7511 digital video driver chip, and so the I2C register block for that device is not present.
\item Second, the R3 PCB uses a different on-board amplifier for the PC speakers, which are now present in stereo, rather than mono
as on the R2 PCB. The amplifier on the R3 PCB is the same as on the MEGAphone R1 -- R2 PCBs.
However, the I2C registers are at a different address. On the MEGA65 R3 PCB, the registers are located at \$FFD71DC -- \$FFD71EF.
\end{itemize}
%\DONTinput{regtable_TARGETM65R3.MEGA65.tex}
\section{MEGA65 Desktop Computer, Revision 2}
The desktop version of the MEGA65 contains a Real-Time Clock (RTC), which also includes a small amount of non-volatile memory (NVRAM)
that retains its value, even if the computer is turned off and disconnected from its power supply. The NVRAM will hold its values
for as long as the internal battery has sufficient charge. This battery also powers the Real-Time Clock (RTC) itself, which includes
a 100 year calendar spanning the years 2000 -- 2099.
The main trick with accessing the RTC from BASIC, is that we will need to use a MEGA65 Enhanced DMA operation to fetch the RTC registers, because the RTC registers sit above the 1MB barrier, which is the limit of the C65's normal DMA operations. The easiest way to do this is to construct a little DMA list in memory somewhere, and make an assembly language routine that uses it. Something like this (using BASIC 65 in C65-mode):
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
10 RESTORE 110:FORI=0TO43:READA$:POKE1024+I,DEC(A$):NEXT:BANK 128:SYS1042
20 S=PEEK(1056):M=PEEK(1057):H=PEEK(1058)
30 D=PEEK(1059):MM=PEEK(1060):Y=PEEK(1061)+DEC("2000")
40 IF H AND 128 GOTO 80
50 PRINT "THE TIME IS ";RIGHT$(HEX$(H AND 63),2);":";RIGHT$(HEX$(M),2);".";RIGHT$(HEX$(S),2)
60 IF H AND 32 THEN PRINT "PM": ELSE PRINT "AM"
70 GOTO 90
80 PRINT "THE TIME IS ";RIGHT$(HEX$(H AND 63),1);":";RIGHT$(HEX$(M),2);".";RIGHT$(HEX$(S),2)
90 PRINT "THE DATE IS ";RIGHT$(HEX$(D),2);".";RIGHT$(HEX$(MM),2);".";HEX$(Y)
100 END
110 DATA 0B,80,FF,81,00,00,00,08,00,10,71,0D,20,04,00,00,00,00
120 DATA A9,47,8D,2F,D0,A9,53,8D,2F,D0,A9,00,8D,02,D7,A9
130 DATA 04,8D,01,D7,A9,00,8D,05,D7,60
\end{verbatim}
\end{tcolorbox}
This program works by setting up a DMA list in memory at 1,024 (\$0400) (unused normally on the C65), followed by a routine at 1,042 (\$0412) which ensures we have MEGA65 registers un-hidden, and then sets the DMA controller registers appropriately to trigger the DMA job, and then returns. The rest of the BASIC code PEEKs out the RTC registers that the DMA job copied to 1,024 - 1,032 (\$0400 -- \$0407), and interprets them appropriately to print the time.
The curious can use the MONITOR command, and then D1012 to see the routine.
If you want a running clock, you could replace line 100 with GOTO 10. Doing that, you will get a result something like the following:
\begin{tcolorbox}[colback=black,coltext=white]
\verbatimfont{\codefont}
\begin{verbatim}
THE TIME IS 10:05:36 PM
THE DATE IS 20.02.2020
THE TIME IS 10:05:36 PM
THE DATE IS 20.02.2020
THE TIME IS 10:05:36 PM
THE DATE IS 20.02.2020
THE TIME IS 10:05:36 PM
THE DATE IS 20.02.2020
...
\end{verbatim}
\end{tcolorbox}
If you first POKE0,65 to set the CPU to full speed, the whole program can run many times per second. There is an occasional glitch, if the RTC registers are read while being updated by the machine, so we really should de-bounce the values by reading the time a couple of times in succession, and if the values aren't the same both times, then repeat the process until they are. This is left as an exercise for the reader.
NOTE: These registers are not yet fully documented.
%\DONTinput{regtable_TARGETM65R2.MEGA65.tex}
\section{MEGAphone Handheld, Revisions 1 and 2}
The MEGAphone revision 1 and 2 contain a Real-Time Clock (RTC), however this RTC does not include a non-volatile memory (NVRAM)
area. Other specific features of the MEGAphone revisions 1 and 2 include a 3-axis accelerometer, including analog to digital
converters (ADCs), amplifier controller for loud speakers, and several I2C I/O expanders, that are used to connect the joy-pad and other peripherals. The I/O expanders are
fully integrated into the MEGAphone design, and thus there should be no normal need to read these registers directly. The I/O
expanders are, however, also responsible for power control of the various sub-systems of the MEGAphone.
NOTE: These registers are not yet fully documented.
%\DONTinput{regtable_TARGETMEGAPHONER1.MEGA65.tex}
\section{Nexys4 DDR FPGA Board}
NOTE: These registers are not yet fully documented.
%\DONTinput{regtable_TARGETN4DDR.MEGA65.tex}