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:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 55 | ld a,l |
| 56 | inc a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 57 | jp 0xBB6F ; TXT SET COLUMN |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 58 | |
| 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 Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 65 | ld a,l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 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 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 69 | ; void gotoyx (unsigned char y, unsigned char x) |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 70 | ; Set the cursor to the specified position |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 71 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 72 | .globl _gotoyx |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 73 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 74 | _gotoyx:: |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 75 | pop de |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 76 | pop hl |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 77 | push de |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 78 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 79 | inc h |
| 80 | inc l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 81 | jp 0xBB75 ; TXT SET CURSOR |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 82 | |
| 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 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 104 | |
| 105 | ; void cputc (char c); |
| 106 | ; Output one character at the current cursor position |
| 107 | |
| 108 | .globl _cputc |
| 109 | |
| 110 | _cputc:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 111 | ld a,l |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 112 | jp 0xbb5d ; TXT OUTPUT |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 113 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 114 | |
| 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 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 133 | jp 0xbb5d |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 134 | |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 135 | ; void cputsn(char *str, unsigned char len); |
| 136 | .globl _cputsn |
| 137 | |
| 138 | _cputsn:: |
| 139 | pop de ; RV |
| 140 | pop hl ; str |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 141 | dec sp |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 142 | pop bc ; len |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 143 | push de |
| 144 | |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 145 | cputsn$: |
| 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 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 158 | ; 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:: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 165 | cputs$: |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 166 | ld a,(hl) |
| 167 | inc hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 168 | or a |
| 169 | ret z |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 170 | push hl |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 171 | call 0xbb5d |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 172 | pop hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 173 | jr cputs$ |
| 174 | |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 175 | ; void textcolor (unsigned char color); |
| 176 | ; Set the color for text output. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 177 | .globl _textcolor |
| 178 | |
| 179 | _textcolor:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 180 | ld a,l |
| 181 | jp 0xBB90 ; TXT SET PEN |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 182 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 183 | |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 184 | ; void bgcolor (unsigned char color); |
| 185 | ; Set the color for the background. */ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 186 | .globl _bgcolor |
| 187 | |
| 188 | _bgcolor:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 189 | ld a,l |
| 190 | jp 0xBB96 ; TXT SET PAPER |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 191 | |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 192 | ; void bordercolor (unsigned char color); |
| 193 | ; Set the color for the border. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 194 | |
| 195 | .globl _bordercolor |
| 196 | |
| 197 | _bordercolor:: |
| 198 | |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 199 | ld b,l |
| 200 | ld c,l |
| 201 | jp 0xBC38 ; SCR SET BORDER |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 202 | |
| 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 Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 210 | ld a,l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 211 | or a |
| 212 | ret z |
| 213 | ld b,a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 214 | dochline$: |
| 215 | ld c,#0x09a |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 216 | chlineloop$: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 217 | push bc |
| 218 | ld a,c |
| 219 | call 0xbb5d |
| 220 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 221 | djnz chlineloop$ |
| 222 | ret |
| 223 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 224 | ; void chlineyx (unsigned char y, unsigned char x, unsigned char length); |
| 225 | ; Same as "gotoxy (y, x); chline (length);" |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 226 | ; TESTED |
| 227 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 228 | .globl _chlineyx |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 229 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 230 | _chlineyx:: |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 231 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 232 | POP DE ; RV |
| 233 | POP HL ; XY |
| 234 | DEC SP |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 235 | POP BC ; L |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 236 | PUSH DE |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 237 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 238 | inc h |
| 239 | inc l |
| 240 | call 0xBB75 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 241 | jr dochline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 242 | |
| 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 Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 250 | ld a,l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 251 | or a |
| 252 | ret z |
| 253 | ld b,a |
| 254 | call 0xBB78 ; TXT GET CURSOR |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 255 | docvline$: |
| 256 | ld c,#0x095 |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 257 | cvloop$: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 258 | push hl |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 259 | push bc |
| 260 | call 0xBB75 ; TXT SET CURSOR |
| 261 | pop bc |
| 262 | push bc |
| 263 | ld a,c |
| 264 | call 0xbb5d |
| 265 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 266 | pop hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 267 | inc l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 268 | djnz cvloop$ |
| 269 | ret |
| 270 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 271 | ; void cvlineyx (unsigned char y, unsigned char x, unsigned char length); |
| 272 | ; Same as "gotoyx (y, x); cvline (length);" |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 273 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 274 | .globl _cvlineyx |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 275 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 276 | _cvlineyx:: |
| 277 | POP DE ; RV |
| 278 | POP HL ; XY |
| 279 | DEC SP |
| 280 | POP BC ; L. |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 281 | PUSH DE |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 282 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 283 | inc h |
| 284 | inc l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 285 | jr docvline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 286 | |
| 287 | ; void cclear (unsigned char length); |
| 288 | ; Clear part of a line (write length spaces). |
| 289 | |
| 290 | .globl _cclear |
| 291 | |
| 292 | _cclear:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 293 | ld b,l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 294 | ld c,#0x020 ; White space |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 295 | cclearloop$: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 296 | push bc |
| 297 | ld a,c |
| 298 | call 0xbb5d |
| 299 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 300 | djnz cclearloop$ |
| 301 | ret |
| 302 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 303 | ; void screensize (unsigned char* x, unsigned char* y); |
| 304 | ; Return the current screen size. |
| 305 | |
| 306 | .globl _screensize |
| 307 | |
| 308 | _screensize:: |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 309 | pop bc ; RV |
| 310 | pop de ; ptr1 |
| 311 | pop hl ; ptr2 |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 312 | |
| 313 | ld a,#40 ; X Size |
| 314 | ld (de),a |
| 315 | |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 316 | ld a,#25 ; Y Size |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 317 | ld (hl),a |
| 318 | |
| 319 | push hl |
| 320 | push de |
| 321 | push bc |
| 322 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 323 | ret |
| 324 | |