os.s (5832B)
1 /* 2 * Copyright 2021 Gerd Beuster (gerd@frombelow.net). This is free 3 * software under the GNU GPL v3 license or any later version. See 4 * COPYING in the root directory for details. 5 */ 6 7 .setcpu "65C02" 8 9 .include "os.inc" 10 .include "../../../../eris2010/roms/os/ds.l" 11 .include "../../../../eris2010/roms/os/sd.l" 12 13 .include "errno.inc" 14 15 .import popa 16 .import popax 17 .import incsp2 18 .import pushax 19 .import __oserror, _OpenDisk 20 .importzp sp, ptr1 21 22 ;; CONIO 23 .export _cgetc 24 .export _cputc 25 .export _cputs 26 .export _cclear 27 .export _cclearxy 28 .export _chline 29 .export _chlinexy 30 .export _clrscr 31 .export _cputcxy 32 .export _cputsxy 33 .export _cvline 34 .export _cvlinexy 35 .export _gotox 36 .export _gotoy 37 .export _gotoxy 38 .export gotoxy 39 .export _kbhit 40 .export _revers 41 .export screensize 42 .export _textcolor 43 .export _wherex 44 .export _wherey 45 ;; Debugging 46 .export _get_stack_pointers 47 ;; DIO 48 .export _dio_open 49 .export _dio_close 50 .export _dio_read 51 .export _dio_write 52 53 .proc _cgetc: near 54 jmp getc 55 .endproc 56 57 .proc _cputc: near 58 jmp putc 59 .endproc 60 61 .proc _cputs: near 62 ;; Send string terminated by '\0' 63 sta puts_str 64 stx puts_str+1 65 jmp puts 66 .endproc 67 68 ;; Functions not available: 69 ;; bgcolor 70 ;; bordercolor 71 ;; cpeekc 72 ;; cpeekcolor 73 ;; cpeekrevers 74 ;; cpeeks 75 ;; cursor 76 77 .proc _cclear: near 78 print_loop: 79 cmp #$00 80 beq done 81 dec a 82 pha 83 lda #' ' 84 jsr putc 85 pla 86 jmp print_loop 87 done: 88 rts 89 .endproc 90 91 .proc csetcursor: near 92 ;; Auxillary function, very similar to 93 ;; "official" function gotoxy. 94 jsr popa ; y position -> A 95 inc a ; term.asm starts counting at 1 96 pha 97 jsr popa ; x position -> A 98 inc a ; term.asm starts counting at 1 99 tax 100 pla 101 jmp set_cursor ; set_cursor from term.asm 102 .endproc 103 104 .proc _cclearxy: near 105 pha ; Length of area to be cleared 106 jsr csetcursor 107 pla 108 jmp _cclear 109 .endproc 110 111 .proc _chline: near 112 print_loop: 113 cmp #$00 114 beq done 115 dec a 116 pha 117 lda #'_' 118 jsr putc 119 pla 120 jmp print_loop 121 done: 122 rts 123 .endproc 124 125 .proc _chlinexy: near 126 pha ; Length of area to be cleared 127 jsr csetcursor 128 pla 129 jmp _chline 130 .endproc 131 132 .proc _clrscr: near 133 jsr clear_screen 134 lda #$01 135 tax 136 jmp set_cursor 137 .endproc 138 139 .proc _cputcxy: near 140 pha 141 jsr csetcursor 142 pla 143 jmp _cputc 144 .endproc 145 146 .proc _cputsxy: near 147 pha 148 phx 149 jsr csetcursor 150 plx 151 pla 152 jmp _cputs 153 .endproc 154 155 .proc _cvline: near 156 print_loop: 157 cmp #$00 158 beq done 159 dec a 160 pha 161 lda #'|' 162 jsr putc 163 lda #$01 164 jsr cursor_down 165 lda #$01 166 jsr cursor_back 167 pla 168 jmp print_loop 169 done: 170 rts 171 .endproc 172 173 .proc _cvlinexy: near 174 pha ; Length of line 175 jsr csetcursor 176 pla 177 jmp _cvline 178 .endproc 179 180 .proc _gotox: near 181 inc a ; term.asm starts counting at 1 182 pha ; New x position 183 jsr get_cursor 184 plx 185 jmp set_cursor 186 .endproc 187 188 .proc _gotoy: near 189 inc a ; Eris 2010 starts at 1 190 pha ; New y position 191 jsr get_cursor 192 pla 193 jmp set_cursor 194 .endproc 195 196 .proc _gotoxy: near 197 inc a ; term.asm starts counting at 1 198 pha ; New y position 199 jsr popa 200 inc a ; term.asm starts counting at 1 201 tax ; New x position 202 pla 203 jsr set_cursor 204 .endproc 205 206 gotoxy = _gotoxy 207 208 .proc _kbhit: near 209 ldx #$00 210 lda acia_status_reg 211 and #%00001000 212 rts 213 .endproc 214 215 .proc _revers 216 ;; In violation of the specification, the old value 217 ;; is _not_ returned, because we cannot read it. 218 tax 219 lda #'m' 220 cpx #$00 221 beq reset_revers 222 ldx #$07 223 jmp send_CSI 224 reset_revers: 225 ldx #$1b 226 jmp send_CSI 227 .endproc 228 229 .proc screensize 230 jsr get_screen_size 231 tay 232 txa 233 rts 234 .endproc 235 236 .proc _textcolor 237 ;; In violation of the specification, the old value 238 ;; is _not_ returned, because we cannot read it. 239 jmp set_color 240 .endproc 241 242 .proc _wherex 243 jsr get_cursor 244 txa 245 dec a ; term.asm starts counting at 1. 246 rts 247 .endproc 248 249 .proc _wherey 250 jsr get_cursor 251 dec a ; term.asm starts counting at 1. 252 rts 253 .endproc 254 255 ;; This function is used to detect memory leaks 256 .importzp ptr1 257 .proc _get_stack_pointers 258 sta ptr1 ; First parameter 259 stx ptr1+1 260 lda sp ; = sp (CC65 parameter stack pointer) 261 sta (ptr1) 262 lda sp+1 263 ldy #$01 264 sta (ptr1),y 265 jsr popa ; Second parameter 266 sta ptr1 267 jsr popa 268 sta ptr1+1 269 lda ptr ; = ptr (Eris 2010 data stack pointer) 270 sta (ptr1) 271 lda ptr+1 272 ldy #$01 273 sta (ptr1),y 274 jsr popa ; Third parameter 275 sta ptr1 276 jsr popa 277 sta ptr1+1 278 tsx ; = S (Hardware stack pointer) 279 txa 280 sta (ptr1) 281 rts 282 .endproc 283 284 ;; Open SD card. The value returned (d_handle) is identical to 285 ;; input parameter device. Set device (or d_handle) to the 286 ;; application whose files you want to access. 287 ;; (Technically, read/write uses d_handle as the upper 16 288 ;; bytes of the 32 byte SD sector address. These upper 16 bytes 289 ;; are identical to the application number.) 290 .proc _dio_open 291 pha 292 jsr open 293 bcs error 294 lda #EOK 295 sta __oserror 296 pla 297 ldx #$00 298 rts 299 error: 300 pla 301 lda #EIO 302 sta __oserror 303 lda #$00 304 tax 305 rts 306 .endproc 307 308 .proc _dio_close 309 jsr close 310 lda #EOK 311 sta __oserror 312 rts 313 .endproc 314 315 .proc _dio_read 316 jsr prepare_read_write_parameters 317 jsr read_block 318 jmp check_read_write_error 319 .endproc 320 321 .proc _dio_write 322 jsr prepare_read_write_parameters 323 jsr write_block 324 jmp check_read_write_error 325 .endproc 326 327 .proc check_read_write_error 328 bcs error 329 jsr delete_stack_frame 330 lda #EOK 331 sta __oserror 332 rts 333 error: 334 jsr delete_stack_frame 335 lda #EIO 336 sta __oserror 337 rts 338 .endproc 339 340 .proc prepare_read_write_parameters 341 ;; The SD card sector number is a 32 byte value. 342 ;; We get the two most significant bytes from 343 ;; d_handle. The two least significant bytes 344 ;; are passed as parameter sect_num. These 345 ;; parameters are passed via the Eris 2010 OS 346 ;; stack. 347 sta data ; Location of 348 stx data+1 ; data buffer 349 jsr create_stack_frame ; Pass block number 350 ;; sec_num 351 jsr popax 352 ldy #$05 353 sta (ptr),y 354 txa 355 ldy #$04 356 sta (ptr),y 357 ;; d_handle 358 jsr popax 359 ldy #$03 360 sta (ptr),y 361 txa 362 ldy #$02 363 sta (ptr),y 364 rts 365 .endproc