1 | // 5 : MO5 / 8: TO8
|
---|
2 |
|
---|
3 | #ifndef PLATFORM
|
---|
4 | #error "make TARGET=TO8 or make TARGET=MO5"
|
---|
5 | #endif
|
---|
6 |
|
---|
7 | ///////////////////////////////////////
|
---|
8 | // THOMSON.H
|
---|
9 | ///////////////////////////////////////
|
---|
10 |
|
---|
11 | /* MONITOR ZERO-PAGE */
|
---|
12 | #define TERMIN (*(volatile unsigned char*)(MONBASE + 0x00)) // 0x18 bytes
|
---|
13 | #define STATUS (*(volatile unsigned char*)(MONBASE + 0x19))
|
---|
14 | #define TABPT (*(volatile unsigned int*)(MONBASE + 0x1A))
|
---|
15 | #define RANG (*(volatile unsigned char*)(MONBASE + 0x1B)) // Part of TABPT?
|
---|
16 | #define COLN (*(volatile unsigned char*)(MONBASE + 0x1C))
|
---|
17 | #define TOPTAB (*(volatile unsigned char*)(MONBASE + 0x1D))
|
---|
18 | #define TOPRAN (*(volatile unsigned char*)(MONBASE + 0x1E))
|
---|
19 | #define BOTTAB (*(volatile unsigned char*)(MONBASE + 0x1F))
|
---|
20 | #define BOTRAN (*(volatile unsigned char*)(MONBASE + 0x20))
|
---|
21 |
|
---|
22 | #define PLOTX (*(volatile unsigned int*)(MONBASE + 0x32))
|
---|
23 | #define PLOTY (*(volatile unsigned int*)(MONBASE + 0x34))
|
---|
24 | #define CHDRAW (*(volatile unsigned char*)(MONBASE + 0x36))
|
---|
25 | #define KEY (*(volatile unsigned char*)(MONBASE + 0x37))
|
---|
26 | #define DKOPC (*(volatile unsigned char*)(MONBASE + 0x48))
|
---|
27 | #define DKDRV (*(volatile unsigned char*)(MONBASE + 0x49))
|
---|
28 | /* 204A is unused */
|
---|
29 | #define DKTRK (*(volatile unsigned char*)(MONBASE + 0x4B))
|
---|
30 | #define DKSEC (*(volatile unsigned char*)(MONBASE + 0x4C))
|
---|
31 | #define DKSTA (*(volatile unsigned char*)(MONBASE + 0x4E))
|
---|
32 | #define DKBUF (*(volatile unsigned int*)(MONBASE + 0x4F))
|
---|
33 |
|
---|
34 | #define DKint1 (*(volatile unsigned int*)(MONBASE + 0x52))
|
---|
35 |
|
---|
36 | void printhex(unsigned char i);
|
---|
37 | extern unsigned char mark[];
|
---|
38 |
|
---|
39 | /* HARDWARE */
|
---|
40 | #define FDC_STATUS (*(volatile unsigned char*)(FDCBASE))
|
---|
41 |
|
---|
42 | ////////////////////////////////////////
|
---|
43 | // MO5.H
|
---|
44 | ////////////////////////////////////////
|
---|
45 |
|
---|
46 | #if PLATFORM == 5
|
---|
47 | /*****************************************************************************
|
---|
48 | * MOx CODE
|
---|
49 | ****************************************************************************/
|
---|
50 | #define MONBASE 0x2000
|
---|
51 | #define FDCBASE 0xA7D0
|
---|
52 |
|
---|
53 | /* MONITOR ENTRY POINTS */
|
---|
54 |
|
---|
55 | static inline void MENU() {
|
---|
56 | asm(" SWI \n"
|
---|
57 | " FCB 0"
|
---|
58 | );
|
---|
59 | }
|
---|
60 |
|
---|
61 | static inline void PUTC(unsigned char car) {
|
---|
62 | asm(" swi \n"
|
---|
63 | " fcb 2"
|
---|
64 | ::"B" (car)
|
---|
65 | );
|
---|
66 | }
|
---|
67 |
|
---|
68 | static inline void FRM0() {
|
---|
69 | asm(" SWI \n"
|
---|
70 | " FCB 4"
|
---|
71 | );
|
---|
72 | }
|
---|
73 |
|
---|
74 | static inline void FRM1() {
|
---|
75 | asm(" SWI \n"
|
---|
76 | " FCB 6"
|
---|
77 | );
|
---|
78 | }
|
---|
79 |
|
---|
80 | static inline void BEEP() {
|
---|
81 | asm(" SWI \n"
|
---|
82 | " FCB 8"
|
---|
83 | );
|
---|
84 | }
|
---|
85 |
|
---|
86 | // TODO GETC and KTST return values in B,A and Z-flag. How to get these
|
---|
87 | // back in C ?
|
---|
88 |
|
---|
89 | static inline void DRAW(int x, int y) {
|
---|
90 | asm(" SWI \n"
|
---|
91 | " FCB 0xE"
|
---|
92 | :: "X" (x), "Y" (y)
|
---|
93 | );
|
---|
94 | }
|
---|
95 |
|
---|
96 | static inline void PLOT(int x, int y) {
|
---|
97 | asm(" SWI \n"
|
---|
98 | " FCB 0x10"
|
---|
99 | :: "X" (x), "Y" (y)
|
---|
100 | );
|
---|
101 | }
|
---|
102 |
|
---|
103 | static inline void CHPL(int x, int y) {
|
---|
104 | asm(" SWI \n"
|
---|
105 | " FCB 0x12"
|
---|
106 | :: "X" (x), "Y" (y)
|
---|
107 | );
|
---|
108 | }
|
---|
109 |
|
---|
110 | // TODO GETP returns in B, LPIN in flag C, GETL flag C and regs XY
|
---|
111 | // GETS and JOYS in A
|
---|
112 |
|
---|
113 | enum Note {
|
---|
114 | DO = 0,
|
---|
115 | DOs = 1,
|
---|
116 | RE = 2,
|
---|
117 | REs = 3,
|
---|
118 | MI = 4,
|
---|
119 | FA = 5,
|
---|
120 | FAs = 6,
|
---|
121 | SO = 7,
|
---|
122 | SOs = 8,
|
---|
123 | LA = 9,
|
---|
124 | LAs = 9,
|
---|
125 | SI = 10,
|
---|
126 | UT = 11,
|
---|
127 | // TODO what happens with other values ?
|
---|
128 | };
|
---|
129 |
|
---|
130 | static inline void NOTE(enum Note note)
|
---|
131 | {
|
---|
132 | asm(" SWI \n"
|
---|
133 | " FCB 0x1E"
|
---|
134 | :: "B" (note)
|
---|
135 | );
|
---|
136 | }
|
---|
137 |
|
---|
138 |
|
---|
139 | /* FLOPPY DRIVE MONITOR ROM */
|
---|
140 | // NOTE DKOPC was split into several commands to make it easier to use from
|
---|
141 | // C code.
|
---|
142 | static inline void write(unsigned char track, unsigned char sector, unsigned char* buffer) {
|
---|
143 | DKTRK = (unsigned char)track;
|
---|
144 | DKSEC = (unsigned char)sector;
|
---|
145 | DKOPC = 8;
|
---|
146 | DKBUF = (unsigned int)buffer;
|
---|
147 |
|
---|
148 | asm(" swi \n"
|
---|
149 | " fcb 0x26"
|
---|
150 | );
|
---|
151 | }
|
---|
152 |
|
---|
153 | static inline void read(unsigned char track, unsigned char sector, unsigned char* output)
|
---|
154 | {
|
---|
155 | for(;;)
|
---|
156 | {
|
---|
157 | DKTRK = (unsigned char)track;
|
---|
158 | DKSEC = (unsigned char)sector;
|
---|
159 | DKOPC = 2;
|
---|
160 | DKBUF = (unsigned int)output;
|
---|
161 |
|
---|
162 | asm(" swi \n"
|
---|
163 | " fcb 0x26"
|
---|
164 | );
|
---|
165 |
|
---|
166 | if (DKSTA == 0x44 || DKSTA == 0) return; // Sector read ok!
|
---|
167 | printhex(DKSTA);
|
---|
168 | }
|
---|
169 | }
|
---|
170 |
|
---|
171 | static inline void BOOT() {
|
---|
172 | asm(" SWI \n"
|
---|
173 | " FCB 0x28"
|
---|
174 | );
|
---|
175 | }
|
---|
176 |
|
---|
177 | #else
|
---|
178 | /*****************************************************************************
|
---|
179 | * TOx CODE
|
---|
180 | ****************************************************************************/
|
---|
181 | /* MONITOR ENTRY POINTS */
|
---|
182 | #define mon_putc(car) { \
|
---|
183 | asm("JSR \t0xE803 \t; TO8 PUTC\n"\
|
---|
184 | ::"B" ((unsigned char) (car))\
|
---|
185 | ); \
|
---|
186 | }
|
---|
187 |
|
---|
188 | #define MONBASE 0x6000
|
---|
189 |
|
---|
190 | #define write(track, sector, buffer) {\
|
---|
191 | DKTRK = (unsigned char)track;\
|
---|
192 | DKSEC = (unsigned char)sector;\
|
---|
193 | DKOPC = 8;\
|
---|
194 | DKBUF = (unsigned int)buffer;\
|
---|
195 | \
|
---|
196 | asm("JSR \t 0xE004 \t; TO8 DKCONT\n"\
|
---|
197 | ); \
|
---|
198 | }
|
---|
199 |
|
---|
200 | /* FLOPPY DRIVE MONITOR ROM */
|
---|
201 | inline void read(unsigned char track, unsigned char sector,
|
---|
202 | unsigned char* output)
|
---|
203 | {
|
---|
204 | for(;;)
|
---|
205 | {
|
---|
206 | DKTRK = (unsigned char)track;
|
---|
207 | DKSEC = (unsigned char)sector;
|
---|
208 | DKOPC = 2;
|
---|
209 | DKBUF = (unsigned int)output;
|
---|
210 |
|
---|
211 | asm("JSR \t 0xE004 \t \n"); \
|
---|
212 |
|
---|
213 | if (DKSTA == 0x44 || DKSTA == 0) return; // Sector read ok!
|
---|
214 | printhex(DKSTA);
|
---|
215 | }
|
---|
216 | }
|
---|
217 | #endif
|
---|
218 |
|
---|