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 | 25ff050 | 2014-07-03 09:55:24 +0200 | [diff] [blame] | 22 | 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 |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame^] | 42 | CALL 0xBC32 ; SCR SET INK |
| 43 | |
| 44 | LD DE,#255 |
| 45 | LD HL,#0xbe80 |
| 46 | jp 0xbbab ; TXT SET M TABLE |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 47 | |
| 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:: |
| 55 | ld hl,#2 |
| 56 | add hl,sp |
| 57 | ld a,(hl) |
| 58 | inc a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 59 | jp 0xBB6F ; TXT SET COLUMN |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 60 | |
| 61 | ; void gotoy (unsigned char y); |
| 62 | ; Set the cursor to the specified Y position, leave the X position untouched |
| 63 | |
| 64 | .globl _gotoy |
| 65 | |
| 66 | _gotoy:: |
| 67 | ld hl,#2 |
| 68 | add hl,sp |
| 69 | ld a,(hl) |
| 70 | inc a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 71 | jp 0xBB72 ; TXT SET ROW |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 72 | |
| 73 | ; void gotoxy (unsigned char x, unsigned char y) |
| 74 | ; Set the cursor to the specified position |
| 75 | ; y pushed first, then x |
| 76 | |
| 77 | .globl _gotoxy |
| 78 | |
| 79 | _gotoxy:: |
| 80 | ld hl,#2 |
| 81 | add hl,sp |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame^] | 82 | ld a,(hl) |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 83 | inc hl |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame^] | 84 | ld l,(hl) |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 85 | ld h,a |
| 86 | inc h |
| 87 | inc l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 88 | jp 0xBB75 ; TXT SET CURSOR |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 89 | |
| 90 | ; unsigned char wherex (void); |
| 91 | ; Return the X position of the cursor |
| 92 | |
| 93 | .globl _wherex |
| 94 | |
| 95 | _wherex:: |
| 96 | call 0xBB78 ; TXT GET CURSOR |
| 97 | ld l,h |
| 98 | dec l |
| 99 | ret |
| 100 | |
| 101 | ; unsigned char wherey (void); |
| 102 | ; Return the Y position of the cursor |
| 103 | |
| 104 | .globl _wherey |
| 105 | |
| 106 | _wherey:: |
| 107 | call 0xBB78 ; TXT GET CURSOR |
| 108 | dec l |
| 109 | ret |
| 110 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 111 | |
| 112 | ; void cputc (char c); |
| 113 | ; Output one character at the current cursor position |
| 114 | |
| 115 | .globl _cputc |
| 116 | |
| 117 | _cputc:: |
| 118 | ld hl,#2 |
| 119 | add hl,sp |
| 120 | ld a,(hl) |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 121 | jp 0xbb5b ; TXT OUTPUT |
| 122 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 123 | |
| 124 | ; void cputcxy (unsigned char x, unsigned char y, char c) |
| 125 | ; Same as "gotoxy (x, y); cputc (c);" |
| 126 | |
| 127 | .globl _cputcxy |
| 128 | |
| 129 | _cputcxy:: |
| 130 | ld hl,#4 |
| 131 | add hl,sp |
| 132 | ld e,(hl) |
| 133 | dec hl |
| 134 | ld a,(hl) |
| 135 | dec hl |
| 136 | ld h,(hl) |
| 137 | ld l,a |
| 138 | inc h |
| 139 | inc l |
| 140 | call 0xBB75 ; TXT SET CURSOR |
| 141 | ld a,e |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 142 | jp 0xbb5d |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 143 | |
| 144 | ; void cputs (const char* s); |
| 145 | ; Output a NUL terminated string at the current cursor position |
| 146 | ; TESTED |
| 147 | |
| 148 | .globl _cputs |
| 149 | |
| 150 | _cputs:: |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame^] | 151 | ld hl,#2 |
| 152 | add hl,sp |
| 153 | ld e,(hl) |
| 154 | inc hl |
| 155 | ld d,(hl) |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 156 | cputs$: |
| 157 | ld a,(de) |
| 158 | inc de |
| 159 | or a |
| 160 | ret z |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 161 | push de |
| 162 | push af |
| 163 | call 0xbb5d |
| 164 | pop af |
| 165 | pop de |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 166 | jr cputs$ |
| 167 | |
| 168 | ; void cputsxy (unsigned char x, unsigned char y, const char* s); |
| 169 | ; Same as "gotoxy (x, y); puts (s);" |
| 170 | ; TESTED |
| 171 | .globl _cputsxy |
| 172 | |
| 173 | _cputsxy:: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 174 | ld hl,#2 |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 175 | add hl,sp |
| 176 | ld e,(hl) |
| 177 | inc hl |
| 178 | ld d,(hl) |
| 179 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 180 | ld a,(hl) |
| 181 | inc hl |
| 182 | ld l,(hl) |
| 183 | ld h,a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 184 | ex de,hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 185 | inc h |
| 186 | inc l |
| 187 | call 0xBB75 ; TXT SET CURSOR |
| 188 | |
| 189 | jr cputs$ |
| 190 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 191 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 192 | ; void revers (unsigned char onoff); |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 193 | ; Enable/disable reverse character display. This may not be supported by |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 194 | ; the output device. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 195 | ; TESTED |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 196 | .globl _revers |
| 197 | |
| 198 | _revers:: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 199 | ret |
| 200 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 201 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 202 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 203 | ; unsigned char textcolor (unsigned char color); |
| 204 | ; Set the color for text output. The old color setting is returned. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 205 | .globl _textcolor |
| 206 | |
| 207 | _textcolor:: |
| 208 | ld hl,#2 |
| 209 | add hl,sp |
| 210 | ld a,(hl) |
| 211 | ld d,a |
| 212 | call 0xBB93 ; TXT GET PEN |
| 213 | ld e,a |
| 214 | ld a,d |
| 215 | call 0xBB90 ; TXT SET PEN |
| 216 | ld l,e |
| 217 | ret |
| 218 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 219 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 220 | ; unsigned char bgcolor (unsigned char color); |
| 221 | ; Set the color for the background. The old color setting is returned. */ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 222 | .globl _bgcolor |
| 223 | |
| 224 | _bgcolor:: |
| 225 | ld hl,#2 |
| 226 | add hl,sp |
| 227 | ld a,(hl) |
| 228 | ld d,a |
| 229 | call 0xBB99 ; TXT GET PAPER |
| 230 | ld e,a |
| 231 | ld a,d |
| 232 | call 0xBB96 ; TXT SET PAPER |
| 233 | ld l,e |
| 234 | ret |
| 235 | |
| 236 | ; unsigned char bordercolor (unsigned char color); |
| 237 | ; Set the color for the border. The old color setting is returned. |
| 238 | |
| 239 | .globl _bordercolor |
| 240 | |
| 241 | _bordercolor:: |
| 242 | |
| 243 | ld hl,#2 |
| 244 | add hl,sp |
| 245 | ld a,(hl) |
| 246 | push af |
| 247 | call 0xBC3B ; SCR GET BORDER |
| 248 | pop af |
| 249 | ld d,b |
| 250 | ld b,a |
| 251 | ld c,a |
| 252 | push de |
| 253 | call 0xBC38 ; SCR SET BORDER |
| 254 | pop de |
| 255 | ld l,d |
| 256 | ret |
| 257 | |
| 258 | ; void chline (unsigned char length); |
| 259 | ; Output a horizontal line with the given length starting at the current |
| 260 | ; cursor position. |
| 261 | |
| 262 | .globl _chline |
| 263 | |
| 264 | _chline:: |
| 265 | ld hl,#2 |
| 266 | add hl,sp |
| 267 | ld a,(hl) |
| 268 | or a |
| 269 | ret z |
| 270 | ld b,a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 271 | dochline$: |
| 272 | ld c,#0x09a |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 273 | chlineloop$: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 274 | push bc |
| 275 | ld a,c |
| 276 | call 0xbb5d |
| 277 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 278 | djnz chlineloop$ |
| 279 | ret |
| 280 | |
| 281 | ; void chlinexy (unsigned char x, unsigned char y, unsigned char length); |
| 282 | ; Same as "gotoxy (x, y); chline (length);" |
| 283 | ; TESTED |
| 284 | |
| 285 | .globl _chlinexy |
| 286 | |
| 287 | _chlinexy:: |
| 288 | ld hl,#2 |
| 289 | add hl,sp |
| 290 | ld d,(hl) |
| 291 | inc hl |
| 292 | ld e,(hl) |
| 293 | inc hl |
| 294 | ld a,(hl) |
| 295 | or a |
| 296 | ret z |
| 297 | ld b,a |
| 298 | ld h,d |
| 299 | ld l,e |
| 300 | inc h |
| 301 | inc l |
| 302 | call 0xBB75 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 303 | jr dochline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 304 | |
| 305 | ; void cvline (unsigned char length); |
| 306 | ; Output a vertical line with the given length at the current cursor |
| 307 | ; position. |
| 308 | |
| 309 | .globl _cvline |
| 310 | |
| 311 | _cvline:: |
| 312 | ld hl,#2 |
| 313 | add hl,sp |
| 314 | ld a,(hl) |
| 315 | or a |
| 316 | ret z |
| 317 | ld b,a |
| 318 | call 0xBB78 ; TXT GET CURSOR |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 319 | docvline$: |
| 320 | ld c,#0x095 |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 321 | cvloop$: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 322 | push hl |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 323 | push bc |
| 324 | call 0xBB75 ; TXT SET CURSOR |
| 325 | pop bc |
| 326 | push bc |
| 327 | ld a,c |
| 328 | call 0xbb5d |
| 329 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 330 | pop hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 331 | inc l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 332 | djnz cvloop$ |
| 333 | ret |
| 334 | |
| 335 | ; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); |
| 336 | ; Same as "gotoxy (x, y); cvline (length);" |
| 337 | |
| 338 | .globl _cvlinexy |
| 339 | |
| 340 | _cvlinexy:: |
| 341 | ld hl,#2 |
| 342 | add hl,sp |
| 343 | ld d,(hl) |
| 344 | inc hl |
| 345 | ld e,(hl) |
| 346 | inc hl |
| 347 | ld a,(hl) |
| 348 | or a |
| 349 | ret z |
| 350 | ld b,a |
| 351 | ld h,d |
| 352 | ld l,e |
| 353 | inc h |
| 354 | inc l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 355 | jr docvline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 356 | |
| 357 | ; void cclear (unsigned char length); |
| 358 | ; Clear part of a line (write length spaces). |
| 359 | |
| 360 | .globl _cclear |
| 361 | |
| 362 | _cclear:: |
| 363 | ld hl,#2 |
| 364 | add hl,sp |
| 365 | ld b,(hl) |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 366 | ld c,#0x020 ; White space |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 367 | cclearloop$: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 368 | push bc |
| 369 | ld a,c |
| 370 | call 0xbb5d |
| 371 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 372 | djnz cclearloop$ |
| 373 | ret |
| 374 | |
| 375 | ; void cclearxy (unsigned char x, unsigned char y, unsigned char length); |
| 376 | ; Same as "gotoxy (x, y); cclear (length);" |
| 377 | |
| 378 | .globl _cclearxy |
| 379 | |
| 380 | _cclearxy:: |
| 381 | ld hl,#2 |
| 382 | add hl,sp |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 383 | ld d,(hl) ; X |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 384 | inc hl |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 385 | ld e,(hl) ; Y |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 386 | inc hl |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 387 | |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 388 | ld a,(hl) ; Length |
| 389 | |
| 390 | ; E is BOTTOM |
| 391 | ; LEFT TOP |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 392 | ld h,d |
| 393 | ld l,e |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 394 | |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 395 | ; RIGHT |
| 396 | dec a |
| 397 | add d |
| 398 | ld d,a |
| 399 | |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 400 | ; ink mask |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 401 | call 0xBB99 ; TXT GET PAPER |
| 402 | call 0xBC2C ; SCR INK ENCODE |
| 403 | |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 404 | jp 0xBC44 ; SCR FILL BOX |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 405 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 406 | |
| 407 | ; void screensize (unsigned char* x, unsigned char* y); |
| 408 | ; Return the current screen size. |
| 409 | |
| 410 | .globl _screensize |
| 411 | |
| 412 | _screensize:: |
| 413 | |
| 414 | ld hl,#2 |
| 415 | add hl,sp |
| 416 | ld e,(hl) |
| 417 | inc hl |
| 418 | ld d,(hl) |
| 419 | |
| 420 | ld a,#40 ; X Size |
| 421 | ld (de),a |
| 422 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 423 | inc hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 424 | ld e,(hl) |
| 425 | inc hl |
| 426 | ld d,(hl) |
| 427 | |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 428 | ld a,#25 ; Y Size |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 429 | ld (de),a |
| 430 | ret |
| 431 | |