blob: c070b6feacecca7faf2e81f7a4ce955f3294eb67 [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
PulkoMandydf52c592014-07-03 15:36:50 +020042 CALL 0xBC32 ; SCR SET INK
43
44 LD DE,#255
45 LD HL,#0xbe80
46 jp 0xbbab ; TXT SET M TABLE
kthacker62e146c2006-04-17 15:11:35 +000047
48
49; void gotox (unsigned char x);
50; Set the cursor to the specified X position, leave the Y position untouched
51
52.globl _gotox
53
54_gotox::
Adrien Destugues0ff774a2016-01-22 23:27:44 +010055 ld a,l
56 inc a
PulkoMandyab171052014-07-01 22:33:48 +020057 jp 0xBB6F ; TXT SET COLUMN
kthacker62e146c2006-04-17 15:11:35 +000058
59; void gotoy (unsigned char y);
60; Set the cursor to the specified Y position, leave the X position untouched
61
62.globl _gotoy
63
64_gotoy::
Adrien Destugues0ff774a2016-01-22 23:27:44 +010065 ld a,l
kthacker62e146c2006-04-17 15:11:35 +000066 inc a
PulkoMandyab171052014-07-01 22:33:48 +020067 jp 0xBB72 ; TXT SET ROW
kthacker62e146c2006-04-17 15:11:35 +000068
Adrien Destugues715554f2016-01-23 19:48:57 +010069; void gotoyx (unsigned char y, unsigned char x)
kthacker62e146c2006-04-17 15:11:35 +000070; Set the cursor to the specified position
kthacker62e146c2006-04-17 15:11:35 +000071
Adrien Destugues715554f2016-01-23 19:48:57 +010072.globl _gotoyx
kthacker62e146c2006-04-17 15:11:35 +000073
Adrien Destugues715554f2016-01-23 19:48:57 +010074_gotoyx::
Adrien Destugues9333c982016-01-23 18:38:47 +010075 pop de
Adrien Destugues715554f2016-01-23 19:48:57 +010076 pop hl
Adrien Destugues9333c982016-01-23 18:38:47 +010077 push de
Adrien Destugues9333c982016-01-23 18:38:47 +010078
kthacker62e146c2006-04-17 15:11:35 +000079 inc h
80 inc l
PulkoMandyab171052014-07-01 22:33:48 +020081 jp 0xBB75 ; TXT SET CURSOR
kthacker62e146c2006-04-17 15:11:35 +000082
83; unsigned char wherex (void);
84; Return the X position of the cursor
85
86.globl _wherex
87
88_wherex::
89 call 0xBB78 ; TXT GET CURSOR
90 ld l,h
91 dec l
92 ret
93
94; unsigned char wherey (void);
95; Return the Y position of the cursor
96
97.globl _wherey
98
99_wherey::
100 call 0xBB78 ; TXT GET CURSOR
101 dec l
102 ret
103
kthacker62e146c2006-04-17 15:11:35 +0000104
105; void cputc (char c);
106; Output one character at the current cursor position
107
108.globl _cputc
109
110_cputc::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100111 ld a,l
Adrien Destugues9333c982016-01-23 18:38:47 +0100112 jp 0xbb5d ; TXT OUTPUT
PulkoMandyab171052014-07-01 22:33:48 +0200113
kthacker62e146c2006-04-17 15:11:35 +0000114
115; void cputcxy (unsigned char x, unsigned char y, char c)
116; Same as "gotoxy (x, y); cputc (c);"
117
118.globl _cputcxy
119
120_cputcxy::
121 ld hl,#4
122 add hl,sp
123 ld e,(hl)
124 dec hl
125 ld a,(hl)
126 dec hl
127 ld h,(hl)
128 ld l,a
129 inc h
130 inc l
131 call 0xBB75 ; TXT SET CURSOR
132 ld a,e
PulkoMandyab171052014-07-01 22:33:48 +0200133 jp 0xbb5d
kthacker62e146c2006-04-17 15:11:35 +0000134
Adrien Destugues9333c982016-01-23 18:38:47 +0100135; void cputsn(char *str, unsigned char len);
136.globl _cputsn
137
138_cputsn::
139 pop de ; RV
140 pop hl ; str
Adrien Destugues715554f2016-01-23 19:48:57 +0100141 dec sp
Adrien Destugues9333c982016-01-23 18:38:47 +0100142 pop bc ; len
Adrien Destugues9333c982016-01-23 18:38:47 +0100143 push de
144
Adrien Destugues9333c982016-01-23 18:38:47 +0100145cputsn$:
146 LD A,(HL)
147 INC HL
148 OR A
149 RET Z
150 PUSH HL
151 PUSH BC
152 CALL 0xBB5D
153 POP BC
154 POP HL
155 DJNZ cputsn$
156 RET
157
kthacker62e146c2006-04-17 15:11:35 +0000158; void cputs (const char* s);
159; Output a NUL terminated string at the current cursor position
160; TESTED
161
162.globl _cputs
163
164_cputs::
kthacker62e146c2006-04-17 15:11:35 +0000165cputs$:
Adrien Destugues9333c982016-01-23 18:38:47 +0100166 ld a,(hl)
167 inc hl
kthacker62e146c2006-04-17 15:11:35 +0000168 or a
169 ret z
Adrien Destugues9333c982016-01-23 18:38:47 +0100170 push hl
PulkoMandyab171052014-07-01 22:33:48 +0200171 call 0xbb5d
Adrien Destugues9333c982016-01-23 18:38:47 +0100172 pop hl
kthacker62e146c2006-04-17 15:11:35 +0000173 jr cputs$
174
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100175; void textcolor (unsigned char color);
176; Set the color for text output.
kthacker62e146c2006-04-17 15:11:35 +0000177.globl _textcolor
178
179_textcolor::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100180 ld a,l
181 jp 0xBB90 ; TXT SET PEN
kthacker62e146c2006-04-17 15:11:35 +0000182
PulkoMandya76f8ec2014-06-29 16:17:37 +0200183
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100184; void bgcolor (unsigned char color);
185; Set the color for the background. */
kthacker62e146c2006-04-17 15:11:35 +0000186.globl _bgcolor
187
188_bgcolor::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100189 ld a,l
190 jp 0xBB96 ; TXT SET PAPER
kthacker62e146c2006-04-17 15:11:35 +0000191
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100192; void bordercolor (unsigned char color);
193; Set the color for the border.
kthacker62e146c2006-04-17 15:11:35 +0000194
195.globl _bordercolor
196
197_bordercolor::
198
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100199 ld b,l
200 ld c,l
201 jp 0xBC38 ; SCR SET BORDER
kthacker62e146c2006-04-17 15:11:35 +0000202
203; void chline (unsigned char length);
204; Output a horizontal line with the given length starting at the current
205; cursor position.
206
207.globl _chline
208
209_chline::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100210 ld a,l
kthacker62e146c2006-04-17 15:11:35 +0000211 or a
212 ret z
213 ld b,a
PulkoMandyab171052014-07-01 22:33:48 +0200214dochline$:
215 ld c,#0x09a
kthacker62e146c2006-04-17 15:11:35 +0000216chlineloop$:
PulkoMandyab171052014-07-01 22:33:48 +0200217 push bc
218 ld a,c
219 call 0xbb5d
220 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000221 djnz chlineloop$
222 ret
223
Adrien Destugues715554f2016-01-23 19:48:57 +0100224; void chlineyx (unsigned char y, unsigned char x, unsigned char length);
225; Same as "gotoxy (y, x); chline (length);"
kthacker62e146c2006-04-17 15:11:35 +0000226; TESTED
227
Adrien Destugues715554f2016-01-23 19:48:57 +0100228.globl _chlineyx
kthacker62e146c2006-04-17 15:11:35 +0000229
Adrien Destugues715554f2016-01-23 19:48:57 +0100230_chlineyx::
Adrien Destugues9333c982016-01-23 18:38:47 +0100231
Adrien Destugues715554f2016-01-23 19:48:57 +0100232 POP DE ; RV
233 POP HL ; XY
234 DEC SP
Adrien Destugues9333c982016-01-23 18:38:47 +0100235 POP BC ; L
Adrien Destugues9333c982016-01-23 18:38:47 +0100236 PUSH DE
Adrien Destugues9333c982016-01-23 18:38:47 +0100237
kthacker62e146c2006-04-17 15:11:35 +0000238 inc h
239 inc l
240 call 0xBB75
PulkoMandyab171052014-07-01 22:33:48 +0200241 jr dochline$
kthacker62e146c2006-04-17 15:11:35 +0000242
243; void cvline (unsigned char length);
244; Output a vertical line with the given length at the current cursor
245; position.
246
247.globl _cvline
248
249_cvline::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100250 ld a,l
kthacker62e146c2006-04-17 15:11:35 +0000251 or a
252 ret z
253 ld b,a
254 call 0xBB78 ; TXT GET CURSOR
PulkoMandyab171052014-07-01 22:33:48 +0200255docvline$:
256 ld c,#0x095
kthacker62e146c2006-04-17 15:11:35 +0000257cvloop$:
kthacker62e146c2006-04-17 15:11:35 +0000258 push hl
PulkoMandyab171052014-07-01 22:33:48 +0200259 push bc
260 call 0xBB75 ; TXT SET CURSOR
261 pop bc
262 push bc
263 ld a,c
264 call 0xbb5d
265 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000266 pop hl
kthacker62e146c2006-04-17 15:11:35 +0000267 inc l
kthacker62e146c2006-04-17 15:11:35 +0000268 djnz cvloop$
269 ret
270
Adrien Destugues715554f2016-01-23 19:48:57 +0100271; void cvlineyx (unsigned char y, unsigned char x, unsigned char length);
272; Same as "gotoyx (y, x); cvline (length);"
kthacker62e146c2006-04-17 15:11:35 +0000273
Adrien Destugues715554f2016-01-23 19:48:57 +0100274.globl _cvlineyx
kthacker62e146c2006-04-17 15:11:35 +0000275
Adrien Destugues715554f2016-01-23 19:48:57 +0100276_cvlineyx::
277 POP DE ; RV
278 POP HL ; XY
279 DEC SP
280 POP BC ; L.
Adrien Destugues9333c982016-01-23 18:38:47 +0100281 PUSH DE
Adrien Destugues9333c982016-01-23 18:38:47 +0100282
kthacker62e146c2006-04-17 15:11:35 +0000283 inc h
284 inc l
PulkoMandyab171052014-07-01 22:33:48 +0200285 jr docvline$
kthacker62e146c2006-04-17 15:11:35 +0000286
287; void cclear (unsigned char length);
288; Clear part of a line (write length spaces).
289
290.globl _cclear
291
292_cclear::
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100293 ld b,l
PulkoMandyab171052014-07-01 22:33:48 +0200294 ld c,#0x020 ; White space
kthacker62e146c2006-04-17 15:11:35 +0000295cclearloop$:
PulkoMandyab171052014-07-01 22:33:48 +0200296 push bc
297 ld a,c
298 call 0xbb5d
299 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000300 djnz cclearloop$
301 ret
302
kthacker62e146c2006-04-17 15:11:35 +0000303; void screensize (unsigned char* x, unsigned char* y);
304; Return the current screen size.
305
306.globl _screensize
307
308_screensize::
Adrien Destugues9333c982016-01-23 18:38:47 +0100309 pop bc ; RV
310 pop de ; ptr1
311 pop hl ; ptr2
kthacker62e146c2006-04-17 15:11:35 +0000312
313 ld a,#40 ; X Size
314 ld (de),a
315
PulkoMandy92fb6c12014-06-29 20:25:46 +0200316 ld a,#25 ; Y Size
Adrien Destugues9333c982016-01-23 18:38:47 +0100317 ld (hl),a
318
319 push hl
320 push de
321 push bc
322
kthacker62e146c2006-04-17 15:11:35 +0000323 ret
324