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 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 10 | ; 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 |
PulkoMandy | 25ff050 | 2014-07-03 09:55:24 +0200 | [diff] [blame] | 19 | 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 |
PulkoMandy | df52c59 | 2014-07-03 15:36:50 +0200 | [diff] [blame] | 39 | CALL 0xBC32 ; SCR SET INK |
| 40 | |
| 41 | LD DE,#255 |
| 42 | LD HL,#0xbe80 |
| 43 | jp 0xbbab ; TXT SET M TABLE |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 44 | |
| 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 Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 52 | ld a,l |
| 53 | inc a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 54 | jp 0xBB6F ; TXT SET COLUMN |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 55 | |
| 56 | ; void gotoy (unsigned char y); |
| 57 | ; Set the cursor to the specified Y position, leave the X position untouched |
| 58 | |
| 59 | .globl _gotoy |
| 60 | |
| 61 | _gotoy:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 62 | ld a,l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 63 | inc a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 64 | jp 0xBB72 ; TXT SET ROW |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 65 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 66 | ; void gotoyx (unsigned char y, unsigned char x) |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 67 | ; Set the cursor to the specified position |
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 | .globl _gotoyx |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 70 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 71 | _gotoyx:: |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 72 | pop de |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 73 | pop hl |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 74 | push de |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 75 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 76 | inc h |
| 77 | inc l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 78 | jp 0xBB75 ; TXT SET CURSOR |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 79 | |
| 80 | ; unsigned char wherex (void); |
| 81 | ; Return the X position of the cursor |
| 82 | |
| 83 | .globl _wherex |
| 84 | |
| 85 | _wherex:: |
| 86 | call 0xBB78 ; TXT GET CURSOR |
| 87 | ld l,h |
| 88 | dec l |
| 89 | ret |
| 90 | |
| 91 | ; unsigned char wherey (void); |
| 92 | ; Return the Y position of the cursor |
| 93 | |
| 94 | .globl _wherey |
| 95 | |
| 96 | _wherey:: |
| 97 | call 0xBB78 ; TXT GET CURSOR |
| 98 | dec l |
| 99 | ret |
| 100 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 101 | |
| 102 | ; void cputc (char c); |
| 103 | ; Output one character at the current cursor position |
| 104 | |
| 105 | .globl _cputc |
| 106 | |
| 107 | _cputc:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 108 | ld a,l |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 109 | jp 0xbb5d ; TXT OUTPUT |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 110 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 111 | |
| 112 | ; void cputcxy (unsigned char x, unsigned char y, char c) |
| 113 | ; Same as "gotoxy (x, y); cputc (c);" |
| 114 | |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 115 | .globl _cputcyx |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 116 | |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 117 | _cputcyx:: |
| 118 | pop de ; RV |
| 119 | pop hl ; XY |
| 120 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 121 | inc h |
| 122 | inc l |
| 123 | call 0xBB75 ; TXT SET CURSOR |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 124 | |
| 125 | dec sp |
| 126 | pop af ; C |
| 127 | push de |
| 128 | |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 129 | jp 0xbb5d |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 130 | |
Adrien Destugues | 69a6e72 | 2017-06-03 10:17:17 +0200 | [diff] [blame^] | 131 | ; void cputsn(const char *str, unsigned char len); |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 132 | .globl _cputsn |
| 133 | |
| 134 | _cputsn:: |
| 135 | pop de ; RV |
| 136 | pop hl ; str |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 137 | dec sp |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 138 | pop bc ; len |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 139 | push de |
| 140 | |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 141 | cputsn$: |
| 142 | LD A,(HL) |
| 143 | INC HL |
| 144 | OR A |
| 145 | RET Z |
| 146 | PUSH HL |
| 147 | PUSH BC |
| 148 | CALL 0xBB5D |
| 149 | POP BC |
| 150 | POP HL |
| 151 | DJNZ cputsn$ |
| 152 | RET |
| 153 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 154 | ; void cputs (const char* s); |
| 155 | ; Output a NUL terminated string at the current cursor position |
| 156 | ; TESTED |
| 157 | |
| 158 | .globl _cputs |
| 159 | |
| 160 | _cputs:: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 161 | cputs$: |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 162 | ld a,(hl) |
| 163 | inc hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 164 | or a |
| 165 | ret z |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 166 | push hl |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 167 | call 0xbb5d |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 168 | pop hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 169 | jr cputs$ |
| 170 | |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 171 | ; void textcolor (unsigned char color); |
| 172 | ; Set the color for text output. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 173 | .globl _textcolor |
| 174 | |
| 175 | _textcolor:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 176 | ld a,l |
| 177 | jp 0xBB90 ; TXT SET PEN |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 178 | |
PulkoMandy | a76f8ec | 2014-06-29 16:17:37 +0200 | [diff] [blame] | 179 | |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 180 | ; void bgcolor (unsigned char color); |
| 181 | ; Set the color for the background. */ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 182 | .globl _bgcolor |
| 183 | |
| 184 | _bgcolor:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 185 | ld a,l |
| 186 | jp 0xBB96 ; TXT SET PAPER |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 187 | |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 188 | ; void bordercolor (unsigned char color); |
| 189 | ; Set the color for the border. |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 190 | |
| 191 | .globl _bordercolor |
| 192 | |
| 193 | _bordercolor:: |
| 194 | |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 195 | ld b,l |
| 196 | ld c,l |
| 197 | jp 0xBC38 ; SCR SET BORDER |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 198 | |
| 199 | ; void chline (unsigned char length); |
| 200 | ; Output a horizontal line with the given length starting at the current |
| 201 | ; cursor position. |
| 202 | |
| 203 | .globl _chline |
| 204 | |
| 205 | _chline:: |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 206 | ld b,l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 207 | dochline$: |
| 208 | ld c,#0x09a |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 209 | chlineloop$: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 210 | push bc |
| 211 | ld a,c |
| 212 | call 0xbb5d |
| 213 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 214 | djnz chlineloop$ |
| 215 | ret |
| 216 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 217 | ; void chlineyx (unsigned char y, unsigned char x, unsigned char length); |
| 218 | ; Same as "gotoxy (y, x); chline (length);" |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 219 | ; TESTED |
| 220 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 221 | .globl _chlineyx |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 222 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 223 | _chlineyx:: |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 224 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 225 | POP DE ; RV |
| 226 | POP HL ; XY |
| 227 | DEC SP |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 228 | POP BC ; L |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 229 | PUSH DE |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 230 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 231 | inc h |
| 232 | inc l |
| 233 | call 0xBB75 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 234 | jr dochline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 235 | |
| 236 | ; void cvline (unsigned char length); |
| 237 | ; Output a vertical line with the given length at the current cursor |
| 238 | ; position. |
| 239 | |
| 240 | .globl _cvline |
| 241 | |
| 242 | _cvline:: |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 243 | ld b,l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 244 | call 0xBB78 ; TXT GET CURSOR |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 245 | docvline$: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 246 | cvloop$: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 247 | push hl |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 248 | push bc |
| 249 | call 0xBB75 ; TXT SET CURSOR |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 250 | ld a,#0x095 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 251 | call 0xbb5d |
| 252 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 253 | pop hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 254 | inc l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 255 | djnz cvloop$ |
| 256 | ret |
| 257 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 258 | ; void cvlineyx (unsigned char y, unsigned char x, unsigned char length); |
| 259 | ; Same as "gotoyx (y, x); cvline (length);" |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 260 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 261 | .globl _cvlineyx |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 262 | |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 263 | _cvlineyx:: |
| 264 | POP DE ; RV |
| 265 | POP HL ; XY |
| 266 | DEC SP |
| 267 | POP BC ; L. |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 268 | PUSH DE |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 269 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 270 | inc h |
| 271 | inc l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 272 | jr docvline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 273 | |
| 274 | ; void cclear (unsigned char length); |
| 275 | ; Clear part of a line (write length spaces). |
| 276 | |
| 277 | .globl _cclear |
| 278 | |
| 279 | _cclear:: |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 280 | ld b,l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 281 | ld c,#0x020 ; White space |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 282 | cclearloop$: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 283 | push bc |
| 284 | ld a,c |
| 285 | call 0xbb5d |
| 286 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 287 | djnz cclearloop$ |
| 288 | ret |
| 289 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 290 | ; void screensize (unsigned char* x, unsigned char* y); |
| 291 | ; Return the current screen size. |
| 292 | |
| 293 | .globl _screensize |
| 294 | |
| 295 | _screensize:: |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 296 | pop hl ; RV |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 297 | pop de ; ptr1 |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 298 | |
| 299 | ld a,#40 ; X Size |
| 300 | ld (de),a |
| 301 | |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 302 | pop de ; ptr2 |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 303 | ld a,#25 ; Y Size |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 304 | ld (de),a |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 305 | |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 306 | push de |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 307 | push de |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 308 | |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 309 | jp (hl) |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 310 | |