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 | inc a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 53 | jp 0xBB6F ; TXT SET COLUMN |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 54 | |
| 55 | ; void gotoy (unsigned char y); |
| 56 | ; Set the cursor to the specified Y position, leave the X position untouched |
| 57 | |
| 58 | .globl _gotoy |
| 59 | |
| 60 | _gotoy:: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 61 | inc a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 62 | jp 0xBB72 ; TXT SET ROW |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 63 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 64 | ; void gotoxy (unsigned char x, unsigned char y) |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 65 | ; Set the cursor to the specified position |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 66 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 67 | .globl _gotoxy |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 68 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 69 | _gotoxy:: |
| 70 | ld h,a |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 71 | inc h |
| 72 | inc l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 73 | jp 0xBB75 ; TXT SET CURSOR |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 74 | |
| 75 | ; unsigned char wherex (void); |
| 76 | ; Return the X position of the cursor |
| 77 | |
| 78 | .globl _wherex |
| 79 | |
| 80 | _wherex:: |
| 81 | call 0xBB78 ; TXT GET CURSOR |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 82 | ld a,h |
| 83 | dec a |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 84 | ret |
| 85 | |
| 86 | ; unsigned char wherey (void); |
| 87 | ; Return the Y position of the cursor |
| 88 | |
| 89 | .globl _wherey |
| 90 | |
| 91 | _wherey:: |
| 92 | call 0xBB78 ; TXT GET CURSOR |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 93 | ld a,l |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 94 | dec a |
| 95 | ret |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 96 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 97 | |
| 98 | ; void cputcxy (unsigned char x, unsigned char y, char c) |
| 99 | ; Same as "gotoxy (x, y); cputc (c);" |
| 100 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 101 | ; INPUT: A = x, L = y, char on stack |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 102 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 103 | .globl _cputcxy |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 104 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 105 | _cputcxy:: |
| 106 | LD H,A ; HL = cursor position |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 107 | inc h |
| 108 | inc l |
| 109 | call 0xBB75 ; TXT SET CURSOR |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 110 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 111 | pop de ; Return value |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 112 | dec sp |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 113 | pop af ; character to print |
| 114 | push de ; Put return value back on stack |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 115 | |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 116 | jp 0xbb5d |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 117 | |
Adrien Destugues | 69a6e72 | 2017-06-03 10:17:17 +0200 | [diff] [blame] | 118 | ; void cputsn(const char *str, unsigned char len); |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 119 | ; INPUT: str is in HL, len is on the stack |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 120 | .globl _cputsn |
| 121 | |
| 122 | _cputsn:: |
| 123 | pop de ; RV |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 124 | dec sp |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 125 | pop bc ; len |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 126 | push de |
| 127 | |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 128 | cputsn$: |
| 129 | LD A,(HL) |
| 130 | INC HL |
| 131 | OR A |
| 132 | RET Z |
| 133 | PUSH HL |
| 134 | PUSH BC |
| 135 | CALL 0xBB5D |
| 136 | POP BC |
| 137 | POP HL |
| 138 | DJNZ cputsn$ |
| 139 | RET |
| 140 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 141 | ; void cputs (const char* s); |
| 142 | ; Output a NUL terminated string at the current cursor position |
| 143 | ; TESTED |
| 144 | |
| 145 | .globl _cputs |
| 146 | |
| 147 | _cputs:: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 148 | cputs$: |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 149 | ld a,(hl) |
| 150 | inc hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 151 | or a |
| 152 | ret z |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 153 | push hl |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 154 | call 0xbb5d |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 155 | pop hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 156 | jr cputs$ |
| 157 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 158 | .globl _bordercolor |
| 159 | |
| 160 | _bordercolor:: |
| 161 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 162 | ld b,a |
| 163 | ld c,a |
Adrien Destugues | 0ff774a | 2016-01-22 23:27:44 +0100 | [diff] [blame] | 164 | jp 0xBC38 ; SCR SET BORDER |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 165 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 166 | ; void cclear (unsigned char length); |
| 167 | ; Clear part of a line (write length spaces). |
| 168 | |
| 169 | .globl _cclear |
| 170 | |
| 171 | _cclear:: |
| 172 | ld b,a |
| 173 | ld c,#0x020 ; White space |
| 174 | jr chlineloop$ |
| 175 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 176 | ; void chline (unsigned char length); |
| 177 | ; Output a horizontal line with the given length starting at the current |
| 178 | ; cursor position. |
| 179 | |
| 180 | .globl _chline |
| 181 | |
| 182 | _chline:: |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 183 | ld b,a |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 184 | dochline$: |
| 185 | ld c,#0x09a |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 186 | chlineloop$: |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 187 | push bc |
| 188 | ld a,c |
| 189 | call 0xbb5d |
| 190 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 191 | djnz chlineloop$ |
| 192 | ret |
| 193 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 194 | ; void chlinexy (unsigned char x, unsigned char y, unsigned char length); |
| 195 | ; Same as "gotoxy (x, y); chline (length);" |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 196 | ; TESTED |
| 197 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 198 | .globl _chlinexy |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 199 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 200 | _chlinexy:: |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 201 | POP DE ; RV |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 202 | dec sp |
| 203 | POP BC ; Length in B, C is unimportant |
| 204 | PUSH DE ; Put return value back on stack |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 205 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 206 | LD H, A ; HL = XY |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 207 | inc h |
| 208 | inc l |
| 209 | call 0xBB75 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 210 | jr dochline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 211 | |
| 212 | ; void cvline (unsigned char length); |
| 213 | ; Output a vertical line with the given length at the current cursor |
| 214 | ; position. |
| 215 | |
| 216 | .globl _cvline |
| 217 | |
| 218 | _cvline:: |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 219 | ld b,a |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 220 | call 0xBB78 ; TXT GET CURSOR |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 221 | docvline$: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 222 | cvloop$: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 223 | push hl |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 224 | push bc |
| 225 | call 0xBB75 ; TXT SET CURSOR |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 226 | ld a,#0x095 |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 227 | call 0xbb5d |
| 228 | pop bc |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 229 | pop hl |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 230 | inc l |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 231 | djnz cvloop$ |
| 232 | ret |
| 233 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 234 | ; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); |
| 235 | ; Same as "gotoxy (x, y); cvline (length);" |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 236 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 237 | ; INPUT: A = Y, L = X, length on stack |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 238 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 239 | .globl _cvlinexy |
| 240 | |
| 241 | _cvlinexy:: |
Adrien Destugues | 715554f | 2016-01-23 19:48:57 +0100 | [diff] [blame] | 242 | POP DE ; RV |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 243 | dec sp |
| 244 | |
| 245 | LD H, A ; HL = XY |
| 246 | |
| 247 | POP BC ; Length |
| 248 | PUSH DE ; Put return value back on stack |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 249 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 250 | inc h |
| 251 | inc l |
PulkoMandy | ab17105 | 2014-07-01 22:33:48 +0200 | [diff] [blame] | 252 | jr docvline$ |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 253 | |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 254 | ; void screensize (unsigned char* x, unsigned char* y); |
| 255 | ; Return the current screen size. |
| 256 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 257 | ; INPUT: HL = X ptr, DE = Y ptr |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 258 | .globl _screensize |
| 259 | |
| 260 | _screensize:: |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 261 | ld a,#40 ; X Size |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 262 | ld (hl),a |
kthacker | 62e146c | 2006-04-17 15:11:35 +0000 | [diff] [blame] | 263 | |
PulkoMandy | 92fb6c1 | 2014-06-29 20:25:46 +0200 | [diff] [blame] | 264 | ld a,#25 ; Y Size |
Adrien Destugues | 5ce1414 | 2016-01-24 23:30:59 +0100 | [diff] [blame] | 265 | ld (de),a |
Adrien Destugues | 9333c98 | 2016-01-23 18:38:47 +0100 | [diff] [blame] | 266 | |
PulkoMandy | 3783e42 | 2023-05-02 17:40:17 +0200 | [diff] [blame] | 267 | ret |