kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 1 | ;*****************************************************************************/ |
| 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 13 | ; 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 22 | jp 0xBC0E ; SCR SET MODE |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 23 | |
| 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 35 | jp 0xBB6F ; TXT SET COLUMN |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 36 | |
| 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 47 | jp 0xBB72 ; TXT SET ROW |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 48 | |
| 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 64 | jp 0xBB75 ; TXT SET CURSOR |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 65 | |
| 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 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 87 | |
| 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) |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 97 | jp 0xbb5b ; TXT OUTPUT |
| 98 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 99 | |
| 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 118 | jp 0xbb5d |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 119 | |
| 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 | |
| 133 | cputs$: |
| 134 | ld a,(de) |
| 135 | inc de |
| 136 | or a |
| 137 | ret z |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 138 | push de |
| 139 | push af |
| 140 | call 0xbb5d |
| 141 | pop af |
| 142 | pop de |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 143 | 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:: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 151 | ld hl,#2 |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 152 | add hl,sp |
| 153 | ld e,(hl) |
| 154 | inc hl |
| 155 | ld d,(hl) |
| 156 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 157 | ld a,(hl) |
| 158 | inc hl |
| 159 | ld l,(hl) |
| 160 | ld h,a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 161 | ex de,hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 162 | inc h |
| 163 | inc l |
| 164 | call 0xBB75 ; TXT SET CURSOR |
| 165 | |
| 166 | jr cputs$ |
| 167 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 168 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 169 | ; void revers (unsigned char onoff); |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 170 | ; Enable/disable reverse character display. This may not be supported by |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 171 | ; the output device. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 172 | ; TESTED |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 173 | .globl _revers |
| 174 | |
| 175 | _revers:: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 176 | ret |
| 177 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 178 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 179 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 180 | ; unsigned char textcolor (unsigned char color); |
| 181 | ; Set the color for text output. The old color setting is returned. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 182 | .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 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 196 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 197 | ; unsigned char bgcolor (unsigned char color); |
| 198 | ; Set the color for the background. The old color setting is returned. */ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 199 | .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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 248 | dochline$: |
| 249 | ld c,#0x09a |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 250 | chlineloop$: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 251 | push bc |
| 252 | ld a,c |
| 253 | call 0xbb5d |
| 254 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 255 | 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 280 | jr dochline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 281 | |
| 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 296 | docvline$: |
| 297 | ld c,#0x095 |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 298 | cvloop$: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 299 | push hl |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 300 | push bc |
| 301 | call 0xBB75 ; TXT SET CURSOR |
| 302 | pop bc |
| 303 | push bc |
| 304 | ld a,c |
| 305 | call 0xbb5d |
| 306 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 307 | pop hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 308 | inc l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 309 | 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 332 | jr docvline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 333 | |
| 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) |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 343 | ld c,#0x020 ; White space |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 344 | cclearloop$: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 345 | push bc |
| 346 | ld a,c |
| 347 | call 0xbb5d |
| 348 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 349 | 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 |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 360 | ld d,(hl) ; X |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 361 | inc hl |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 362 | ld e,(hl) ; Y |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 363 | inc hl |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 364 | |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 365 | ld a,(hl) ; Length |
| 366 | |
| 367 | ; E is BOTTOM |
| 368 | ; LEFT TOP |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 369 | ld h,d |
| 370 | ld l,e |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 371 | |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 372 | ; RIGHT |
| 373 | dec a |
| 374 | add d |
| 375 | ld d,a |
| 376 | |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 377 | ; ink mask |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 378 | call 0xBB99 ; TXT GET PAPER |
| 379 | call 0xBC2C ; SCR INK ENCODE |
| 380 | |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame^] | 381 | jp 0xBC44 ; SCR FILL BOX |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 382 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 383 | |
| 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 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 400 | inc hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 401 | ld e,(hl) |
| 402 | inc hl |
| 403 | ld d,(hl) |
| 404 | |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 405 | ld a,#25 ; Y Size |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 406 | ld (de),a |
| 407 | ret |
| 408 | |