blob: 45b6720440165c5bcccd5df744c80af7da22be59 [file] [log] [blame]
kthacker62e146c2006-04-17 15:11:35 +00001;*****************************************************************************/
2; CONIO.S - Amstrad CPC version of the Contiki conio.h (derived from
3;borland C) ; To use with the Small Devices C Compiler ; ; 2003 H. Hansen
4;*****************************************************************************/
5
6;; contiki uses coordinates between 0..width-1, 0..height-1
7;; cpc uses coordinates between 1..width, 1..height
PulkoMandyab171052014-07-01 22:33:48 +02008
9
10
11
12
kthacker62e146c2006-04-17 15:11:35 +000013; void clrscr (void);
14; Clear the whole screen and put the cursor into the top left corner
15; TESTED
16
17.globl _clrscr
18 .area _CODE
19
20_clrscr::
21 ld a,#1
PulkoMandyab171052014-07-01 22:33:48 +020022 jp 0xBC0E ; SCR SET MODE
kthacker62e146c2006-04-17 15:11:35 +000023
24
25; void gotox (unsigned char x);
26; Set the cursor to the specified X position, leave the Y position untouched
27
28.globl _gotox
29
30_gotox::
31 ld hl,#2
32 add hl,sp
33 ld a,(hl)
34 inc a
PulkoMandyab171052014-07-01 22:33:48 +020035 jp 0xBB6F ; TXT SET COLUMN
kthacker62e146c2006-04-17 15:11:35 +000036
37; void gotoy (unsigned char y);
38; Set the cursor to the specified Y position, leave the X position untouched
39
40.globl _gotoy
41
42_gotoy::
43 ld hl,#2
44 add hl,sp
45 ld a,(hl)
46 inc a
PulkoMandyab171052014-07-01 22:33:48 +020047 jp 0xBB72 ; TXT SET ROW
kthacker62e146c2006-04-17 15:11:35 +000048
49; void gotoxy (unsigned char x, unsigned char y)
50; Set the cursor to the specified position
51; y pushed first, then x
52
53.globl _gotoxy
54
55_gotoxy::
56 ld hl,#2
57 add hl,sp
58 ld a,(hl)
59 inc hl
60 ld l,(hl)
61 ld h,a
62 inc h
63 inc l
PulkoMandyab171052014-07-01 22:33:48 +020064 jp 0xBB75 ; TXT SET CURSOR
kthacker62e146c2006-04-17 15:11:35 +000065
66; unsigned char wherex (void);
67; Return the X position of the cursor
68
69.globl _wherex
70
71_wherex::
72 call 0xBB78 ; TXT GET CURSOR
73 ld l,h
74 dec l
75 ret
76
77; unsigned char wherey (void);
78; Return the Y position of the cursor
79
80.globl _wherey
81
82_wherey::
83 call 0xBB78 ; TXT GET CURSOR
84 dec l
85 ret
86
kthacker62e146c2006-04-17 15:11:35 +000087
88; void cputc (char c);
89; Output one character at the current cursor position
90
91.globl _cputc
92
93_cputc::
94 ld hl,#2
95 add hl,sp
96 ld a,(hl)
PulkoMandyab171052014-07-01 22:33:48 +020097 jp 0xbb5b ; TXT OUTPUT
98
kthacker62e146c2006-04-17 15:11:35 +000099
100; void cputcxy (unsigned char x, unsigned char y, char c)
101; Same as "gotoxy (x, y); cputc (c);"
102
103.globl _cputcxy
104
105_cputcxy::
106 ld hl,#4
107 add hl,sp
108 ld e,(hl)
109 dec hl
110 ld a,(hl)
111 dec hl
112 ld h,(hl)
113 ld l,a
114 inc h
115 inc l
116 call 0xBB75 ; TXT SET CURSOR
117 ld a,e
PulkoMandyab171052014-07-01 22:33:48 +0200118 jp 0xbb5d
kthacker62e146c2006-04-17 15:11:35 +0000119
120; void cputs (const char* s);
121; Output a NUL terminated string at the current cursor position
122; TESTED
123
124.globl _cputs
125
126_cputs::
127 ld hl,#2
128 add hl,sp
129 ld e,(hl)
130 inc hl
131 ld d,(hl)
132
133cputs$:
134 ld a,(de)
135 inc de
136 or a
137 ret z
PulkoMandyab171052014-07-01 22:33:48 +0200138 push de
139 push af
140 call 0xbb5d
141 pop af
142 pop de
kthacker62e146c2006-04-17 15:11:35 +0000143 jr cputs$
144
145; void cputsxy (unsigned char x, unsigned char y, const char* s);
146; Same as "gotoxy (x, y); puts (s);"
147; TESTED
148.globl _cputsxy
149
150_cputsxy::
PulkoMandyab171052014-07-01 22:33:48 +0200151 ld hl,#2
kthacker62e146c2006-04-17 15:11:35 +0000152 add hl,sp
153 ld e,(hl)
154 inc hl
155 ld d,(hl)
156
kthacker62e146c2006-04-17 15:11:35 +0000157 ld a,(hl)
158 inc hl
159 ld l,(hl)
160 ld h,a
PulkoMandyab171052014-07-01 22:33:48 +0200161 ex de,hl
kthacker62e146c2006-04-17 15:11:35 +0000162 inc h
163 inc l
164 call 0xBB75 ; TXT SET CURSOR
165
166 jr cputs$
167
kthacker62e146c2006-04-17 15:11:35 +0000168
PulkoMandya76f8ec2014-06-29 16:17:37 +0200169; void revers (unsigned char onoff);
kthacker62e146c2006-04-17 15:11:35 +0000170; Enable/disable reverse character display. This may not be supported by
PulkoMandya76f8ec2014-06-29 16:17:37 +0200171; the output device.
kthacker62e146c2006-04-17 15:11:35 +0000172; TESTED
kthacker62e146c2006-04-17 15:11:35 +0000173.globl _revers
174
175_revers::
PulkoMandyab171052014-07-01 22:33:48 +0200176 ret
177
kthacker62e146c2006-04-17 15:11:35 +0000178
PulkoMandya76f8ec2014-06-29 16:17:37 +0200179
kthacker62e146c2006-04-17 15:11:35 +0000180; unsigned char textcolor (unsigned char color);
181; Set the color for text output. The old color setting is returned.
kthacker62e146c2006-04-17 15:11:35 +0000182.globl _textcolor
183
184_textcolor::
185 ld hl,#2
186 add hl,sp
187 ld a,(hl)
188 ld d,a
189 call 0xBB93 ; TXT GET PEN
190 ld e,a
191 ld a,d
192 call 0xBB90 ; TXT SET PEN
193 ld l,e
194 ret
195
PulkoMandya76f8ec2014-06-29 16:17:37 +0200196
kthacker62e146c2006-04-17 15:11:35 +0000197; unsigned char bgcolor (unsigned char color);
198; Set the color for the background. The old color setting is returned. */
kthacker62e146c2006-04-17 15:11:35 +0000199.globl _bgcolor
200
201_bgcolor::
202 ld hl,#2
203 add hl,sp
204 ld a,(hl)
205 ld d,a
206 call 0xBB99 ; TXT GET PAPER
207 ld e,a
208 ld a,d
209 call 0xBB96 ; TXT SET PAPER
210 ld l,e
211 ret
212
213; unsigned char bordercolor (unsigned char color);
214; Set the color for the border. The old color setting is returned.
215
216.globl _bordercolor
217
218_bordercolor::
219
220 ld hl,#2
221 add hl,sp
222 ld a,(hl)
223 push af
224 call 0xBC3B ; SCR GET BORDER
225 pop af
226 ld d,b
227 ld b,a
228 ld c,a
229 push de
230 call 0xBC38 ; SCR SET BORDER
231 pop de
232 ld l,d
233 ret
234
235; void chline (unsigned char length);
236; Output a horizontal line with the given length starting at the current
237; cursor position.
238
239.globl _chline
240
241_chline::
242 ld hl,#2
243 add hl,sp
244 ld a,(hl)
245 or a
246 ret z
247 ld b,a
PulkoMandyab171052014-07-01 22:33:48 +0200248dochline$:
249 ld c,#0x09a
kthacker62e146c2006-04-17 15:11:35 +0000250chlineloop$:
PulkoMandyab171052014-07-01 22:33:48 +0200251 push bc
252 ld a,c
253 call 0xbb5d
254 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000255 djnz chlineloop$
256 ret
257
258; void chlinexy (unsigned char x, unsigned char y, unsigned char length);
259; Same as "gotoxy (x, y); chline (length);"
260; TESTED
261
262.globl _chlinexy
263
264_chlinexy::
265 ld hl,#2
266 add hl,sp
267 ld d,(hl)
268 inc hl
269 ld e,(hl)
270 inc hl
271 ld a,(hl)
272 or a
273 ret z
274 ld b,a
275 ld h,d
276 ld l,e
277 inc h
278 inc l
279 call 0xBB75
PulkoMandyab171052014-07-01 22:33:48 +0200280 jr dochline$
kthacker62e146c2006-04-17 15:11:35 +0000281
282; void cvline (unsigned char length);
283; Output a vertical line with the given length at the current cursor
284; position.
285
286.globl _cvline
287
288_cvline::
289 ld hl,#2
290 add hl,sp
291 ld a,(hl)
292 or a
293 ret z
294 ld b,a
295 call 0xBB78 ; TXT GET CURSOR
PulkoMandyab171052014-07-01 22:33:48 +0200296docvline$:
297 ld c,#0x095
kthacker62e146c2006-04-17 15:11:35 +0000298cvloop$:
kthacker62e146c2006-04-17 15:11:35 +0000299 push hl
PulkoMandyab171052014-07-01 22:33:48 +0200300 push bc
301 call 0xBB75 ; TXT SET CURSOR
302 pop bc
303 push bc
304 ld a,c
305 call 0xbb5d
306 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000307 pop hl
kthacker62e146c2006-04-17 15:11:35 +0000308 inc l
kthacker62e146c2006-04-17 15:11:35 +0000309 djnz cvloop$
310 ret
311
312; void cvlinexy (unsigned char x, unsigned char y, unsigned char length);
313; Same as "gotoxy (x, y); cvline (length);"
314
315.globl _cvlinexy
316
317_cvlinexy::
318 ld hl,#2
319 add hl,sp
320 ld d,(hl)
321 inc hl
322 ld e,(hl)
323 inc hl
324 ld a,(hl)
325 or a
326 ret z
327 ld b,a
328 ld h,d
329 ld l,e
330 inc h
331 inc l
PulkoMandyab171052014-07-01 22:33:48 +0200332 jr docvline$
kthacker62e146c2006-04-17 15:11:35 +0000333
334; void cclear (unsigned char length);
335; Clear part of a line (write length spaces).
336
337.globl _cclear
338
339_cclear::
340 ld hl,#2
341 add hl,sp
342 ld b,(hl)
PulkoMandyab171052014-07-01 22:33:48 +0200343 ld c,#0x020 ; White space
kthacker62e146c2006-04-17 15:11:35 +0000344cclearloop$:
PulkoMandyab171052014-07-01 22:33:48 +0200345 push bc
346 ld a,c
347 call 0xbb5d
348 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000349 djnz cclearloop$
350 ret
351
352; void cclearxy (unsigned char x, unsigned char y, unsigned char length);
353; Same as "gotoxy (x, y); cclear (length);"
354
355.globl _cclearxy
356
357_cclearxy::
358 ld hl,#2
359 add hl,sp
PulkoMandy92fb6c12014-06-29 20:25:46 +0200360 ld d,(hl) ; X
kthacker62e146c2006-04-17 15:11:35 +0000361 inc hl
PulkoMandy92fb6c12014-06-29 20:25:46 +0200362 ld e,(hl) ; Y
kthacker62e146c2006-04-17 15:11:35 +0000363 inc hl
PulkoMandy92fb6c12014-06-29 20:25:46 +0200364
PulkoMandy92fb6c12014-06-29 20:25:46 +0200365 ld a,(hl) ; Length
366
367 ; E is BOTTOM
368 ; LEFT TOP
kthacker62e146c2006-04-17 15:11:35 +0000369 ld h,d
370 ld l,e
kthacker62e146c2006-04-17 15:11:35 +0000371
PulkoMandy92fb6c12014-06-29 20:25:46 +0200372 ; RIGHT
373 dec a
374 add d
375 ld d,a
376
PulkoMandyab171052014-07-01 22:33:48 +0200377 ; ink mask
PulkoMandy92fb6c12014-06-29 20:25:46 +0200378 call 0xBB99 ; TXT GET PAPER
379 call 0xBC2C ; SCR INK ENCODE
380
PulkoMandyab171052014-07-01 22:33:48 +0200381 jp 0xBC44 ; SCR FILL BOX
PulkoMandy92fb6c12014-06-29 20:25:46 +0200382
kthacker62e146c2006-04-17 15:11:35 +0000383
384; void screensize (unsigned char* x, unsigned char* y);
385; Return the current screen size.
386
387.globl _screensize
388
389_screensize::
390
391 ld hl,#2
392 add hl,sp
393 ld e,(hl)
394 inc hl
395 ld d,(hl)
396
397 ld a,#40 ; X Size
398 ld (de),a
399
PulkoMandya76f8ec2014-06-29 16:17:37 +0200400 inc hl
kthacker62e146c2006-04-17 15:11:35 +0000401 ld e,(hl)
402 inc hl
403 ld d,(hl)
404
PulkoMandy92fb6c12014-06-29 20:25:46 +0200405 ld a,#25 ; Y Size
kthacker62e146c2006-04-17 15:11:35 +0000406 ld (de),a
407 ret
408