blob: 21c87dfdffc8646fa9d9308ea1a11977b5e3be0c [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 inc a
PulkoMandyab171052014-07-01 22:33:48 +020053 jp 0xBB6F ; TXT SET COLUMN
kthacker62e146c2006-04-17 15:11:35 +000054
55; void gotoy (unsigned char y);
56; Set the cursor to the specified Y position, leave the X position untouched
57
58.globl _gotoy
59
60_gotoy::
kthacker62e146c2006-04-17 15:11:35 +000061 inc a
PulkoMandyab171052014-07-01 22:33:48 +020062 jp 0xBB72 ; TXT SET ROW
kthacker62e146c2006-04-17 15:11:35 +000063
PulkoMandy3783e422023-05-02 17:40:17 +020064; void gotoxy (unsigned char x, unsigned char y)
kthacker62e146c2006-04-17 15:11:35 +000065; Set the cursor to the specified position
kthacker62e146c2006-04-17 15:11:35 +000066
PulkoMandy3783e422023-05-02 17:40:17 +020067.globl _gotoxy
kthacker62e146c2006-04-17 15:11:35 +000068
PulkoMandy3783e422023-05-02 17:40:17 +020069_gotoxy::
70 ld h,a
kthacker62e146c2006-04-17 15:11:35 +000071 inc h
72 inc l
PulkoMandyab171052014-07-01 22:33:48 +020073 jp 0xBB75 ; TXT SET CURSOR
kthacker62e146c2006-04-17 15:11:35 +000074
75; unsigned char wherex (void);
76; Return the X position of the cursor
77
78.globl _wherex
79
80_wherex::
81 call 0xBB78 ; TXT GET CURSOR
PulkoMandy3783e422023-05-02 17:40:17 +020082 ld a,h
83 dec a
kthacker62e146c2006-04-17 15:11:35 +000084 ret
85
86; unsigned char wherey (void);
87; Return the Y position of the cursor
88
89.globl _wherey
90
91_wherey::
92 call 0xBB78 ; TXT GET CURSOR
Adrien Destugues0ff774a2016-01-22 23:27:44 +010093 ld a,l
PulkoMandy3783e422023-05-02 17:40:17 +020094 dec a
95 ret
PulkoMandyab171052014-07-01 22:33:48 +020096
kthacker62e146c2006-04-17 15:11:35 +000097
98; void cputcxy (unsigned char x, unsigned char y, char c)
99; Same as "gotoxy (x, y); cputc (c);"
100
PulkoMandy3783e422023-05-02 17:40:17 +0200101; INPUT: A = x, L = y, char on stack
kthacker62e146c2006-04-17 15:11:35 +0000102
PulkoMandy3783e422023-05-02 17:40:17 +0200103.globl _cputcxy
Adrien Destugues5ce14142016-01-24 23:30:59 +0100104
PulkoMandy3783e422023-05-02 17:40:17 +0200105_cputcxy::
106 LD H,A ; HL = cursor position
kthacker62e146c2006-04-17 15:11:35 +0000107 inc h
108 inc l
109 call 0xBB75 ; TXT SET CURSOR
Adrien Destugues5ce14142016-01-24 23:30:59 +0100110
PulkoMandy3783e422023-05-02 17:40:17 +0200111 pop de ; Return value
Adrien Destugues5ce14142016-01-24 23:30:59 +0100112 dec sp
PulkoMandy3783e422023-05-02 17:40:17 +0200113 pop af ; character to print
114 push de ; Put return value back on stack
Adrien Destugues5ce14142016-01-24 23:30:59 +0100115
PulkoMandyab171052014-07-01 22:33:48 +0200116 jp 0xbb5d
kthacker62e146c2006-04-17 15:11:35 +0000117
Adrien Destugues69a6e722017-06-03 10:17:17 +0200118; void cputsn(const char *str, unsigned char len);
PulkoMandy3783e422023-05-02 17:40:17 +0200119; INPUT: str is in HL, len is on the stack
Adrien Destugues9333c982016-01-23 18:38:47 +0100120.globl _cputsn
121
122_cputsn::
123 pop de ; RV
Adrien Destugues715554f2016-01-23 19:48:57 +0100124 dec sp
Adrien Destugues9333c982016-01-23 18:38:47 +0100125 pop bc ; len
Adrien Destugues9333c982016-01-23 18:38:47 +0100126 push de
127
Adrien Destugues9333c982016-01-23 18:38:47 +0100128cputsn$:
129 LD A,(HL)
130 INC HL
131 OR A
132 RET Z
133 PUSH HL
134 PUSH BC
135 CALL 0xBB5D
136 POP BC
137 POP HL
138 DJNZ cputsn$
139 RET
140
kthacker62e146c2006-04-17 15:11:35 +0000141; void cputs (const char* s);
142; Output a NUL terminated string at the current cursor position
143; TESTED
144
145.globl _cputs
146
147_cputs::
kthacker62e146c2006-04-17 15:11:35 +0000148cputs$:
Adrien Destugues9333c982016-01-23 18:38:47 +0100149 ld a,(hl)
150 inc hl
kthacker62e146c2006-04-17 15:11:35 +0000151 or a
152 ret z
Adrien Destugues9333c982016-01-23 18:38:47 +0100153 push hl
PulkoMandyab171052014-07-01 22:33:48 +0200154 call 0xbb5d
Adrien Destugues9333c982016-01-23 18:38:47 +0100155 pop hl
kthacker62e146c2006-04-17 15:11:35 +0000156 jr cputs$
157
kthacker62e146c2006-04-17 15:11:35 +0000158.globl _bordercolor
159
160_bordercolor::
161
PulkoMandy3783e422023-05-02 17:40:17 +0200162 ld b,a
163 ld c,a
Adrien Destugues0ff774a2016-01-22 23:27:44 +0100164 jp 0xBC38 ; SCR SET BORDER
kthacker62e146c2006-04-17 15:11:35 +0000165
PulkoMandy3783e422023-05-02 17:40:17 +0200166; void cclear (unsigned char length);
167; Clear part of a line (write length spaces).
168
169.globl _cclear
170
171_cclear::
172 ld b,a
173 ld c,#0x020 ; White space
174 jr chlineloop$
175
kthacker62e146c2006-04-17 15:11:35 +0000176; void chline (unsigned char length);
177; Output a horizontal line with the given length starting at the current
178; cursor position.
179
180.globl _chline
181
182_chline::
PulkoMandy3783e422023-05-02 17:40:17 +0200183 ld b,a
PulkoMandyab171052014-07-01 22:33:48 +0200184dochline$:
185 ld c,#0x09a
kthacker62e146c2006-04-17 15:11:35 +0000186chlineloop$:
PulkoMandyab171052014-07-01 22:33:48 +0200187 push bc
188 ld a,c
189 call 0xbb5d
190 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000191 djnz chlineloop$
192 ret
193
PulkoMandy3783e422023-05-02 17:40:17 +0200194; void chlinexy (unsigned char x, unsigned char y, unsigned char length);
195; Same as "gotoxy (x, y); chline (length);"
kthacker62e146c2006-04-17 15:11:35 +0000196; TESTED
197
PulkoMandy3783e422023-05-02 17:40:17 +0200198.globl _chlinexy
kthacker62e146c2006-04-17 15:11:35 +0000199
PulkoMandy3783e422023-05-02 17:40:17 +0200200_chlinexy::
Adrien Destugues715554f2016-01-23 19:48:57 +0100201 POP DE ; RV
PulkoMandy3783e422023-05-02 17:40:17 +0200202 dec sp
203 POP BC ; Length in B, C is unimportant
204 PUSH DE ; Put return value back on stack
Adrien Destugues9333c982016-01-23 18:38:47 +0100205
PulkoMandy3783e422023-05-02 17:40:17 +0200206 LD H, A ; HL = XY
kthacker62e146c2006-04-17 15:11:35 +0000207 inc h
208 inc l
209 call 0xBB75
PulkoMandyab171052014-07-01 22:33:48 +0200210 jr dochline$
kthacker62e146c2006-04-17 15:11:35 +0000211
212; void cvline (unsigned char length);
213; Output a vertical line with the given length at the current cursor
214; position.
215
216.globl _cvline
217
218_cvline::
PulkoMandy3783e422023-05-02 17:40:17 +0200219 ld b,a
kthacker62e146c2006-04-17 15:11:35 +0000220 call 0xBB78 ; TXT GET CURSOR
PulkoMandyab171052014-07-01 22:33:48 +0200221docvline$:
kthacker62e146c2006-04-17 15:11:35 +0000222cvloop$:
kthacker62e146c2006-04-17 15:11:35 +0000223 push hl
PulkoMandyab171052014-07-01 22:33:48 +0200224 push bc
225 call 0xBB75 ; TXT SET CURSOR
Adrien Destugues5ce14142016-01-24 23:30:59 +0100226 ld a,#0x095
PulkoMandyab171052014-07-01 22:33:48 +0200227 call 0xbb5d
228 pop bc
kthacker62e146c2006-04-17 15:11:35 +0000229 pop hl
kthacker62e146c2006-04-17 15:11:35 +0000230 inc l
kthacker62e146c2006-04-17 15:11:35 +0000231 djnz cvloop$
232 ret
233
PulkoMandy3783e422023-05-02 17:40:17 +0200234; void cvlinexy (unsigned char x, unsigned char y, unsigned char length);
235; Same as "gotoxy (x, y); cvline (length);"
kthacker62e146c2006-04-17 15:11:35 +0000236
PulkoMandy3783e422023-05-02 17:40:17 +0200237; INPUT: A = Y, L = X, length on stack
kthacker62e146c2006-04-17 15:11:35 +0000238
PulkoMandy3783e422023-05-02 17:40:17 +0200239.globl _cvlinexy
240
241_cvlinexy::
Adrien Destugues715554f2016-01-23 19:48:57 +0100242 POP DE ; RV
PulkoMandy3783e422023-05-02 17:40:17 +0200243 dec sp
244
245 LD H, A ; HL = XY
246
247 POP BC ; Length
248 PUSH DE ; Put return value back on stack
Adrien Destugues9333c982016-01-23 18:38:47 +0100249
kthacker62e146c2006-04-17 15:11:35 +0000250 inc h
251 inc l
PulkoMandyab171052014-07-01 22:33:48 +0200252 jr docvline$
kthacker62e146c2006-04-17 15:11:35 +0000253
kthacker62e146c2006-04-17 15:11:35 +0000254; void screensize (unsigned char* x, unsigned char* y);
255; Return the current screen size.
256
PulkoMandy3783e422023-05-02 17:40:17 +0200257; INPUT: HL = X ptr, DE = Y ptr
kthacker62e146c2006-04-17 15:11:35 +0000258.globl _screensize
259
260_screensize::
kthacker62e146c2006-04-17 15:11:35 +0000261 ld a,#40 ; X Size
PulkoMandy3783e422023-05-02 17:40:17 +0200262 ld (hl),a
kthacker62e146c2006-04-17 15:11:35 +0000263
PulkoMandy92fb6c12014-06-29 20:25:46 +0200264 ld a,#25 ; Y Size
Adrien Destugues5ce14142016-01-24 23:30:59 +0100265 ld (de),a
Adrien Destugues9333c982016-01-23 18:38:47 +0100266
PulkoMandy3783e422023-05-02 17:40:17 +0200267 ret