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