eris2010

Documentation: http://frombelow.net/projects/eris2010/
Clone: git clone https://git.frombelow.net/eris2010.git
Log | Files | Refs | README | LICENSE

os.s (5645B)


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