blob: 236a5cb6fc10935c981167cbd1303a645cb20dbd [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
kthacker62e146c2006-04-17 15:11:35 +000010; void clrscr (void);
11; Clear the whole screen and put the cursor into the top left corner
12; TESTED
13
14.globl _clrscr
15 .area _CODE
16
17_clrscr::
18 ld a,#1
PulkoMandy25ff0502014-07-03 09:55:24 +020019 call 0xBC0E ; SCR SET MODE
20
21 ; BACKGROUND
22 XOR A
23 LD BC,#0x0D0D ; GREY
24 CALL 0xBC32 ; SCR SET INK
25
26 ; BORDERS
27 LD A,#1
28 LD BC,#0x0e0e ; BLUE
29 CALL 0xBC32 ; SCR SET INK
30
31 ; WIDGETS
32 LD A,#2
33 LD BC,#0x1a1a ; WHITE
34 CALL 0xBC32 ; SCR SET INK
35
36 ; FOCUS
37 LD A,#3
38 LD BC,#0x0000 ; BLACK
PulkoMandydf52c592014-07-03 15:36:50 +020039 CALL 0xBC32 ; SCR SET INK
40
41 LD DE,#255
42 LD HL,#0xbe80
43 jp 0xbbab ; TXT SET M TABLE
kthacker62e146c2006-04-17 15:11:35 +000044
45
46; void gotox (unsigned char x);
47; Set the cursor to the specified X position, leave the Y position untouched
48
49.globl _gotox
50
51_gotox::
Adrien Destugues0ff774a2016-01-22 23:27:44 +010052 ld a,l
53 inc a
PulkoMandyab171052014-07-01 22:33:48 +020054 jp 0xBB6F ; TXT SET COLUMN
kthacker62e146c2006-04-17 15:11:35 +000055
56; void gotoy (unsigned char y);
57; Set the cursor to the specified Y position, leave the X position untouched
58
59.globl _gotoy
60
61_gotoy::
Adrien Destugues0ff774a2016-01-22 23:27:44 +010062 ld a,l
kthacker62e146c2006-04-17 15:11:35 +000063 inc a
PulkoMandyab171052014-07-01 22:33:48 +020064 jp 0xBB72 ; TXT SET ROW
kthacker62e146c2006-04-17 15:11:35 +000065
Adrien Destugues715554f2016-01-23 19:48:57 +010066; void gotoyx (unsigned char y, unsigned char x)
kthacker62e146c2006-04-17 15:11:35 +000067; Set the cursor to the specified position
kthacker62e146c2006-04-17 15:11:35 +000068
Adrien Destugues715554f2016-01-23 19:48:57 +010069.globl _gotoyx
kthacker62e146c2006-04-17 15:11:35 +000070
Adrien Destugues715554f2016-01-23 19:48:57 +010071_gotoyx::
Adrien Destugues9333c982016-01-23 18:38:47 +010072 pop de
Adrien Destugues715554f2016-01-23 19:48:57 +010073 pop hl
Adrien Destugues9333c982016-01-23 18:38:47 +010074 push de
Adrien Destugues9333c982016-01-23 18:38:47 +010075
kthacker62e146c2006-04-17 15:11:35 +000076 inc h
77 inc l
PulkoMandyab171052014-07-01 22:33:48 +020078 jp 0xBB75 ; TXT SET CURSOR
kthacker62e146c2006-04-17 15:11:35 +000079
80; unsigned char wherex (void);
81; Return the X position of the cursor
82
83.globl _wherex
84
85_wherex::
86 call 0xBB78 ; TXT GET CURSOR
87 ld l,h
88 dec l
89 ret
90
91; unsigned char wherey (void);
92; Return the Y position of the cursor
93
94.globl _wherey
95
96_wherey::
97 call 0xBB78 ; TXT GET CURSOR
98 dec l
99 ret
100
kthacker62e146c2006-04-17 15:11:35 +0000101
102; void cputc (char c);
103; Output one character at the current cursor position
104
105.globl _cputc
106
107_cputc::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100108 ld a,l
Adrien Destugues9333c982016-01-23 18:38:47 +0100109 jp 0xbb5d ; TXT OUTPUT
PulkoMandyab171052014-07-01 22:33:48 +0200110
kthacker62e146c2006-04-17 15:11:35 +0000111
112; void cputcxy (unsigned char x, unsigned char y, char c)
113; Same as "gotoxy (x, y); cputc (c);"
114
Adrien Destugues5ce14142016-01-24 23:30:59 +0100115.globl _cputcyx
kthacker62e146c2006-04-17 15:11:35 +0000116
Adrien Destugues5ce14142016-01-24 23:30:59 +0100117_cputcyx::
118 pop de ; RV
119 pop hl ; XY
120
kthacker62e146c2006-04-17 15:11:35 +0000121 inc h
122 inc l
123 call 0xBB75 ; TXT SET CURSOR
Adrien Destugues5ce14142016-01-24 23:30:59 +0100124
125 dec sp
126 pop af ; C
127 push de
128
PulkoMandyab171052014-07-01 22:33:48 +0200129 jp 0xbb5d
kthacker62e146c2006-04-17 15:11:35 +0000130
Adrien Destugues69a6e722017-06-03 10:17:17 +0200131; void cputsn(const char *str, unsigned char len);
Adrien Destugues9333c982016-01-23 18:38:47 +0100132.globl _cputsn
133
134_cputsn::
135 pop de ; RV
136 pop hl ; str
Adrien Destugues715554f2016-01-23 19:48:57 +0100137 dec sp
Adrien Destugues9333c982016-01-23 18:38:47 +0100138 pop bc ; len
Adrien Destugues9333c982016-01-23 18:38:47 +0100139 push de
140
Adrien Destugues9333c982016-01-23 18:38:47 +0100141cputsn$:
142 LD A,(HL)
143 INC HL
144 OR A
145 RET Z
146 PUSH HL
147 PUSH BC
148 CALL 0xBB5D
149 POP BC
150 POP HL
151 DJNZ cputsn$
152 RET
153
kthacker62e146c2006-04-17 15:11:35 +0000154; void cputs (const char* s);
155; Output a NUL terminated string at the current cursor position
156; TESTED
157
158.globl _cputs
159
160_cputs::
kthacker62e146c2006-04-17 15:11:35 +0000161cputs$:
Adrien Destugues9333c982016-01-23 18:38:47 +0100162 ld a,(hl)
163 inc hl
kthacker62e146c2006-04-17 15:11:35 +0000164 or a
165 ret z
Adrien Destugues9333c982016-01-23 18:38:47 +0100166 push hl
PulkoMandyab171052014-07-01 22:33:48 +0200167 call 0xbb5d
Adrien Destugues9333c982016-01-23 18:38:47 +0100168 pop hl
kthacker62e146c2006-04-17 15:11:35 +0000169 jr cputs$
170
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100171; void textcolor (unsigned char color);
172; Set the color for text output.
kthacker62e146c2006-04-17 15:11:35 +0000173.globl _textcolor
174
175_textcolor::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100176 ld a,l
177 jp 0xBB90 ; TXT SET PEN
kthacker62e146c2006-04-17 15:11:35 +0000178
PulkoMandya76f8ec2014-06-29 16:17:37 +0200179
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100180; void bgcolor (unsigned char color);
181; Set the color for the background. */
kthacker62e146c2006-04-17 15:11:35 +0000182.globl _bgcolor
183
184_bgcolor::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100185 ld a,l
186 jp 0xBB96 ; TXT SET PAPER
kthacker62e146c2006-04-17 15:11:35 +0000187
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100188; void bordercolor (unsigned char color);
189; Set the color for the border.
kthacker62e146c2006-04-17 15:11:35 +0000190
191.globl _bordercolor
192
193_bordercolor::
194
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100195 ld b,l
196 ld c,l
197 jp 0xBC38 ; SCR SET BORDER
kthacker62e146c2006-04-17 15:11:35 +0000198
199; void chline (unsigned char length);
200; Output a horizontal line with the given length starting at the current
201; cursor position.
202
203.globl _chline
204
205_chline::
Adrien Destugues5ce14142016-01-24 23:30:59 +0100206 ld b,l
PulkoMandyab171052014-07-01 22:33:48 +0200207dochline$:
208 ld c,#0x09a
kthacker62e146c2006-04-17 15:11:35 +0000209chlineloop$:
PulkoMandyab171052014-07-01 22:33:48 +0200210 push bc
211 ld a,c
212 call 0xbb5d
213 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000214 djnz chlineloop$
215 ret
216
Adrien Destugues715554f2016-01-23 19:48:57 +0100217; void chlineyx (unsigned char y, unsigned char x, unsigned char length);
218; Same as "gotoxy (y, x); chline (length);"
kthacker62e146c2006-04-17 15:11:35 +0000219; TESTED
220
Adrien Destugues715554f2016-01-23 19:48:57 +0100221.globl _chlineyx
kthacker62e146c2006-04-17 15:11:35 +0000222
Adrien Destugues715554f2016-01-23 19:48:57 +0100223_chlineyx::
Adrien Destugues9333c982016-01-23 18:38:47 +0100224
Adrien Destugues715554f2016-01-23 19:48:57 +0100225 POP DE ; RV
226 POP HL ; XY
227 DEC SP
Adrien Destugues9333c982016-01-23 18:38:47 +0100228 POP BC ; L
Adrien Destugues9333c982016-01-23 18:38:47 +0100229 PUSH DE
Adrien Destugues9333c982016-01-23 18:38:47 +0100230
kthacker62e146c2006-04-17 15:11:35 +0000231 inc h
232 inc l
233 call 0xBB75
PulkoMandyab171052014-07-01 22:33:48 +0200234 jr dochline$
kthacker62e146c2006-04-17 15:11:35 +0000235
236; void cvline (unsigned char length);
237; Output a vertical line with the given length at the current cursor
238; position.
239
240.globl _cvline
241
242_cvline::
Adrien Destugues5ce14142016-01-24 23:30:59 +0100243 ld b,l
kthacker62e146c2006-04-17 15:11:35 +0000244 call 0xBB78 ; TXT GET CURSOR
PulkoMandyab171052014-07-01 22:33:48 +0200245docvline$:
kthacker62e146c2006-04-17 15:11:35 +0000246cvloop$:
kthacker62e146c2006-04-17 15:11:35 +0000247 push hl
PulkoMandyab171052014-07-01 22:33:48 +0200248 push bc
249 call 0xBB75 ; TXT SET CURSOR
Adrien Destugues5ce14142016-01-24 23:30:59 +0100250 ld a,#0x095
PulkoMandyab171052014-07-01 22:33:48 +0200251 call 0xbb5d
252 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000253 pop hl
kthacker62e146c2006-04-17 15:11:35 +0000254 inc l
kthacker62e146c2006-04-17 15:11:35 +0000255 djnz cvloop$
256 ret
257
Adrien Destugues715554f2016-01-23 19:48:57 +0100258; void cvlineyx (unsigned char y, unsigned char x, unsigned char length);
259; Same as "gotoyx (y, x); cvline (length);"
kthacker62e146c2006-04-17 15:11:35 +0000260
Adrien Destugues715554f2016-01-23 19:48:57 +0100261.globl _cvlineyx
kthacker62e146c2006-04-17 15:11:35 +0000262
Adrien Destugues715554f2016-01-23 19:48:57 +0100263_cvlineyx::
264 POP DE ; RV
265 POP HL ; XY
266 DEC SP
267 POP BC ; L.
Adrien Destugues9333c982016-01-23 18:38:47 +0100268 PUSH DE
Adrien Destugues9333c982016-01-23 18:38:47 +0100269
kthacker62e146c2006-04-17 15:11:35 +0000270 inc h
271 inc l
PulkoMandyab171052014-07-01 22:33:48 +0200272 jr docvline$
kthacker62e146c2006-04-17 15:11:35 +0000273
274; void cclear (unsigned char length);
275; Clear part of a line (write length spaces).
276
277.globl _cclear
278
279_cclear::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100280 ld b,l
PulkoMandyab171052014-07-01 22:33:48 +0200281 ld c,#0x020 ; White space
kthacker62e146c2006-04-17 15:11:35 +0000282cclearloop$:
PulkoMandyab171052014-07-01 22:33:48 +0200283 push bc
284 ld a,c
285 call 0xbb5d
286 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000287 djnz cclearloop$
288 ret
289
kthacker62e146c2006-04-17 15:11:35 +0000290; void screensize (unsigned char* x, unsigned char* y);
291; Return the current screen size.
292
293.globl _screensize
294
295_screensize::
Adrien Destugues5ce14142016-01-24 23:30:59 +0100296 pop hl ; RV
Adrien Destugues9333c982016-01-23 18:38:47 +0100297 pop de ; ptr1
kthacker62e146c2006-04-17 15:11:35 +0000298
299 ld a,#40 ; X Size
300 ld (de),a
301
Adrien Destugues5ce14142016-01-24 23:30:59 +0100302 pop de ; ptr2
PulkoMandy92fb6c12014-06-29 20:25:46 +0200303 ld a,#25 ; Y Size
Adrien Destugues5ce14142016-01-24 23:30:59 +0100304 ld (de),a
Adrien Destugues9333c982016-01-23 18:38:47 +0100305
Adrien Destugues9333c982016-01-23 18:38:47 +0100306 push de
Adrien Destugues5ce14142016-01-24 23:30:59 +0100307 push de
Adrien Destugues9333c982016-01-23 18:38:47 +0100308
Adrien Destugues5ce14142016-01-24 23:30:59 +0100309 jp (hl)
kthacker62e146c2006-04-17 15:11:35 +0000310