blob: 631d7faec7b3b3ba8ecd94fc8ee65ac451948044 [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
PulkoMandy25ff0502014-07-03 09:55:24 +020022 call 0xBC0E ; SCR SET MODE
23
24 ; BACKGROUND
25 XOR A
26 LD BC,#0x0D0D ; GREY
27 CALL 0xBC32 ; SCR SET INK
28
29 ; BORDERS
30 LD A,#1
31 LD BC,#0x0e0e ; BLUE
32 CALL 0xBC32 ; SCR SET INK
33
34 ; WIDGETS
35 LD A,#2
36 LD BC,#0x1a1a ; WHITE
37 CALL 0xBC32 ; SCR SET INK
38
39 ; FOCUS
40 LD A,#3
41 LD BC,#0x0000 ; BLACK
42 JP 0xBC32 ; SCR SET INK
kthacker62e146c2006-04-17 15:11:35 +000043
44
45; void gotox (unsigned char x);
46; Set the cursor to the specified X position, leave the Y position untouched
47
48.globl _gotox
49
50_gotox::
51 ld hl,#2
52 add hl,sp
53 ld a,(hl)
54 inc a
PulkoMandyab171052014-07-01 22:33:48 +020055 jp 0xBB6F ; TXT SET COLUMN
kthacker62e146c2006-04-17 15:11:35 +000056
57; void gotoy (unsigned char y);
58; Set the cursor to the specified Y position, leave the X position untouched
59
60.globl _gotoy
61
62_gotoy::
63 ld hl,#2
64 add hl,sp
65 ld a,(hl)
66 inc a
PulkoMandyab171052014-07-01 22:33:48 +020067 jp 0xBB72 ; TXT SET ROW
kthacker62e146c2006-04-17 15:11:35 +000068
69; void gotoxy (unsigned char x, unsigned char y)
70; Set the cursor to the specified position
71; y pushed first, then x
72
73.globl _gotoxy
74
75_gotoxy::
76 ld hl,#2
77 add hl,sp
78 ld a,(hl)
79 inc hl
80 ld l,(hl)
81 ld h,a
82 inc h
83 inc l
PulkoMandyab171052014-07-01 22:33:48 +020084 jp 0xBB75 ; TXT SET CURSOR
kthacker62e146c2006-04-17 15:11:35 +000085
86; unsigned char wherex (void);
87; Return the X position of the cursor
88
89.globl _wherex
90
91_wherex::
92 call 0xBB78 ; TXT GET CURSOR
93 ld l,h
94 dec l
95 ret
96
97; unsigned char wherey (void);
98; Return the Y position of the cursor
99
100.globl _wherey
101
102_wherey::
103 call 0xBB78 ; TXT GET CURSOR
104 dec l
105 ret
106
kthacker62e146c2006-04-17 15:11:35 +0000107
108; void cputc (char c);
109; Output one character at the current cursor position
110
111.globl _cputc
112
113_cputc::
114 ld hl,#2
115 add hl,sp
116 ld a,(hl)
PulkoMandyab171052014-07-01 22:33:48 +0200117 jp 0xbb5b ; TXT OUTPUT
118
kthacker62e146c2006-04-17 15:11:35 +0000119
120; void cputcxy (unsigned char x, unsigned char y, char c)
121; Same as "gotoxy (x, y); cputc (c);"
122
123.globl _cputcxy
124
125_cputcxy::
126 ld hl,#4
127 add hl,sp
128 ld e,(hl)
129 dec hl
130 ld a,(hl)
131 dec hl
132 ld h,(hl)
133 ld l,a
134 inc h
135 inc l
136 call 0xBB75 ; TXT SET CURSOR
137 ld a,e
PulkoMandyab171052014-07-01 22:33:48 +0200138 jp 0xbb5d
kthacker62e146c2006-04-17 15:11:35 +0000139
140; void cputs (const char* s);
141; Output a NUL terminated string at the current cursor position
142; TESTED
143
144.globl _cputs
145
146_cputs::
147 ld hl,#2
148 add hl,sp
149 ld e,(hl)
150 inc hl
151 ld d,(hl)
152
153cputs$:
154 ld a,(de)
155 inc de
156 or a
157 ret z
PulkoMandyab171052014-07-01 22:33:48 +0200158 push de
159 push af
160 call 0xbb5d
161 pop af
162 pop de
kthacker62e146c2006-04-17 15:11:35 +0000163 jr cputs$
164
165; void cputsxy (unsigned char x, unsigned char y, const char* s);
166; Same as "gotoxy (x, y); puts (s);"
167; TESTED
168.globl _cputsxy
169
170_cputsxy::
PulkoMandyab171052014-07-01 22:33:48 +0200171 ld hl,#2
kthacker62e146c2006-04-17 15:11:35 +0000172 add hl,sp
173 ld e,(hl)
174 inc hl
175 ld d,(hl)
176
kthacker62e146c2006-04-17 15:11:35 +0000177 ld a,(hl)
178 inc hl
179 ld l,(hl)
180 ld h,a
PulkoMandyab171052014-07-01 22:33:48 +0200181 ex de,hl
kthacker62e146c2006-04-17 15:11:35 +0000182 inc h
183 inc l
184 call 0xBB75 ; TXT SET CURSOR
185
186 jr cputs$
187
kthacker62e146c2006-04-17 15:11:35 +0000188
PulkoMandya76f8ec2014-06-29 16:17:37 +0200189; void revers (unsigned char onoff);
kthacker62e146c2006-04-17 15:11:35 +0000190; Enable/disable reverse character display. This may not be supported by
PulkoMandya76f8ec2014-06-29 16:17:37 +0200191; the output device.
kthacker62e146c2006-04-17 15:11:35 +0000192; TESTED
kthacker62e146c2006-04-17 15:11:35 +0000193.globl _revers
194
195_revers::
PulkoMandyab171052014-07-01 22:33:48 +0200196 ret
197
kthacker62e146c2006-04-17 15:11:35 +0000198
PulkoMandya76f8ec2014-06-29 16:17:37 +0200199
kthacker62e146c2006-04-17 15:11:35 +0000200; unsigned char textcolor (unsigned char color);
201; Set the color for text output. The old color setting is returned.
kthacker62e146c2006-04-17 15:11:35 +0000202.globl _textcolor
203
204_textcolor::
205 ld hl,#2
206 add hl,sp
207 ld a,(hl)
208 ld d,a
209 call 0xBB93 ; TXT GET PEN
210 ld e,a
211 ld a,d
212 call 0xBB90 ; TXT SET PEN
213 ld l,e
214 ret
215
PulkoMandya76f8ec2014-06-29 16:17:37 +0200216
kthacker62e146c2006-04-17 15:11:35 +0000217; unsigned char bgcolor (unsigned char color);
218; Set the color for the background. The old color setting is returned. */
kthacker62e146c2006-04-17 15:11:35 +0000219.globl _bgcolor
220
221_bgcolor::
222 ld hl,#2
223 add hl,sp
224 ld a,(hl)
225 ld d,a
226 call 0xBB99 ; TXT GET PAPER
227 ld e,a
228 ld a,d
229 call 0xBB96 ; TXT SET PAPER
230 ld l,e
231 ret
232
233; unsigned char bordercolor (unsigned char color);
234; Set the color for the border. The old color setting is returned.
235
236.globl _bordercolor
237
238_bordercolor::
239
240 ld hl,#2
241 add hl,sp
242 ld a,(hl)
243 push af
244 call 0xBC3B ; SCR GET BORDER
245 pop af
246 ld d,b
247 ld b,a
248 ld c,a
249 push de
250 call 0xBC38 ; SCR SET BORDER
251 pop de
252 ld l,d
253 ret
254
255; void chline (unsigned char length);
256; Output a horizontal line with the given length starting at the current
257; cursor position.
258
259.globl _chline
260
261_chline::
262 ld hl,#2
263 add hl,sp
264 ld a,(hl)
265 or a
266 ret z
267 ld b,a
PulkoMandyab171052014-07-01 22:33:48 +0200268dochline$:
269 ld c,#0x09a
kthacker62e146c2006-04-17 15:11:35 +0000270chlineloop$:
PulkoMandyab171052014-07-01 22:33:48 +0200271 push bc
272 ld a,c
273 call 0xbb5d
274 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000275 djnz chlineloop$
276 ret
277
278; void chlinexy (unsigned char x, unsigned char y, unsigned char length);
279; Same as "gotoxy (x, y); chline (length);"
280; TESTED
281
282.globl _chlinexy
283
284_chlinexy::
285 ld hl,#2
286 add hl,sp
287 ld d,(hl)
288 inc hl
289 ld e,(hl)
290 inc hl
291 ld a,(hl)
292 or a
293 ret z
294 ld b,a
295 ld h,d
296 ld l,e
297 inc h
298 inc l
299 call 0xBB75
PulkoMandyab171052014-07-01 22:33:48 +0200300 jr dochline$
kthacker62e146c2006-04-17 15:11:35 +0000301
302; void cvline (unsigned char length);
303; Output a vertical line with the given length at the current cursor
304; position.
305
306.globl _cvline
307
308_cvline::
309 ld hl,#2
310 add hl,sp
311 ld a,(hl)
312 or a
313 ret z
314 ld b,a
315 call 0xBB78 ; TXT GET CURSOR
PulkoMandyab171052014-07-01 22:33:48 +0200316docvline$:
317 ld c,#0x095
kthacker62e146c2006-04-17 15:11:35 +0000318cvloop$:
kthacker62e146c2006-04-17 15:11:35 +0000319 push hl
PulkoMandyab171052014-07-01 22:33:48 +0200320 push bc
321 call 0xBB75 ; TXT SET CURSOR
322 pop bc
323 push bc
324 ld a,c
325 call 0xbb5d
326 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000327 pop hl
kthacker62e146c2006-04-17 15:11:35 +0000328 inc l
kthacker62e146c2006-04-17 15:11:35 +0000329 djnz cvloop$
330 ret
331
332; void cvlinexy (unsigned char x, unsigned char y, unsigned char length);
333; Same as "gotoxy (x, y); cvline (length);"
334
335.globl _cvlinexy
336
337_cvlinexy::
338 ld hl,#2
339 add hl,sp
340 ld d,(hl)
341 inc hl
342 ld e,(hl)
343 inc hl
344 ld a,(hl)
345 or a
346 ret z
347 ld b,a
348 ld h,d
349 ld l,e
350 inc h
351 inc l
PulkoMandyab171052014-07-01 22:33:48 +0200352 jr docvline$
kthacker62e146c2006-04-17 15:11:35 +0000353
354; void cclear (unsigned char length);
355; Clear part of a line (write length spaces).
356
357.globl _cclear
358
359_cclear::
360 ld hl,#2
361 add hl,sp
362 ld b,(hl)
PulkoMandyab171052014-07-01 22:33:48 +0200363 ld c,#0x020 ; White space
kthacker62e146c2006-04-17 15:11:35 +0000364cclearloop$:
PulkoMandyab171052014-07-01 22:33:48 +0200365 push bc
366 ld a,c
367 call 0xbb5d
368 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000369 djnz cclearloop$
370 ret
371
372; void cclearxy (unsigned char x, unsigned char y, unsigned char length);
373; Same as "gotoxy (x, y); cclear (length);"
374
375.globl _cclearxy
376
377_cclearxy::
378 ld hl,#2
379 add hl,sp
PulkoMandy92fb6c12014-06-29 20:25:46 +0200380 ld d,(hl) ; X
kthacker62e146c2006-04-17 15:11:35 +0000381 inc hl
PulkoMandy92fb6c12014-06-29 20:25:46 +0200382 ld e,(hl) ; Y
kthacker62e146c2006-04-17 15:11:35 +0000383 inc hl
PulkoMandy92fb6c12014-06-29 20:25:46 +0200384
PulkoMandy92fb6c12014-06-29 20:25:46 +0200385 ld a,(hl) ; Length
386
387 ; E is BOTTOM
388 ; LEFT TOP
kthacker62e146c2006-04-17 15:11:35 +0000389 ld h,d
390 ld l,e
kthacker62e146c2006-04-17 15:11:35 +0000391
PulkoMandy92fb6c12014-06-29 20:25:46 +0200392 ; RIGHT
393 dec a
394 add d
395 ld d,a
396
PulkoMandyab171052014-07-01 22:33:48 +0200397 ; ink mask
PulkoMandy92fb6c12014-06-29 20:25:46 +0200398 call 0xBB99 ; TXT GET PAPER
399 call 0xBC2C ; SCR INK ENCODE
400
PulkoMandyab171052014-07-01 22:33:48 +0200401 jp 0xBC44 ; SCR FILL BOX
PulkoMandy92fb6c12014-06-29 20:25:46 +0200402
kthacker62e146c2006-04-17 15:11:35 +0000403
404; void screensize (unsigned char* x, unsigned char* y);
405; Return the current screen size.
406
407.globl _screensize
408
409_screensize::
410
411 ld hl,#2
412 add hl,sp
413 ld e,(hl)
414 inc hl
415 ld d,(hl)
416
417 ld a,#40 ; X Size
418 ld (de),a
419
PulkoMandya76f8ec2014-06-29 16:17:37 +0200420 inc hl
kthacker62e146c2006-04-17 15:11:35 +0000421 ld e,(hl)
422 inc hl
423 ld d,(hl)
424
PulkoMandy92fb6c12014-06-29 20:25:46 +0200425 ld a,#25 ; Y Size
kthacker62e146c2006-04-17 15:11:35 +0000426 ld (de),a
427 ret
428