eris2010

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

load_from_card.asm (4591B)


      1 ;;; Copyright 2021 Gerd Beuster (gerd@frombelow.net). This is free
      2 ;;; software under the GNU GPL v3 license or any later version. See
      3 ;;; COPYING in the root directory for details.
      4 
      5 ;;; Start program form SD card.
      6 ;;; If we are included in boot.asm, we
      7 ;;; should not set the start address
      8 .weak
      9 	BOOT_EMBEDDED = false
     10 .endweak
     11 .if !BOOT_EMBEDDED
     12 	.include "os.inc"
     13 .endif
     14 
     15 
     16 .dsection code
     17 	
     18 .section code
     19 
     20 ;;; -----------------------------------
     21 ;;; 
     22 ;;; Main
     23 ;;; 
     24 ;;; -----------------------------------
     25 
     26 .section zero_page
     27 delay0:	.byte ?
     28 delay1:	.byte ?
     29 delay2:	.byte ?
     30 .send zero_page
     31 	
     32 init:
     33 	.block
     34         cld
     35 .if SYMON
     36 	jsr io.init_acia
     37 	jsr via.init
     38 .endif
     39 .if !BOOT_EMBEDDED
     40 	;;  Wait for key to start
     41 	jsr io.getc
     42 .endif	
     43 	#ds.INIT_STACK $7ffd-$0400
     44 	jsr ls_or_autostart
     45 	jsr choose_program
     46 	bcc execute
     47 	jmp ($fffc)		; Reset
     48 	.bend
     49 
     50 	load_address = $0200
     51 
     52 choose_program:
     53 	.block
     54         lda via.ddra		; Set
     55 	ora #%00010000		; PA4
     56 	sta via.ddra		; as output.
     57 	lda #$00		; Prepare
     58 	sta delay0		; for
     59 	sta delay1		; PA4
     60 	lda #$03		; blink.
     61 	sta delay2
     62 	#io.PRINTSNL "Choose program (0-9). Any other key reloads card."
     63 wait_for_input:
     64 	dec delay0
     65 	bne dont_blink
     66 	dec delay1
     67 	bne dont_blink
     68 	dec delay2
     69 	bne dont_blink
     70 	lda #$03
     71 	sta delay2
     72 	lda via.ra		; Blink
     73 	eor #%00010000		; PA4
     74 	sta via.ra
     75 dont_blink:	
     76 	jsr io.getc_nonblocking
     77 	bcs wait_for_input
     78 	sec
     79 	sbc #'0'
     80 	cmp #$0a		; Sets carry if not a digit
     81 	pha
     82 	pla
     83 	rts
     84 	.bend
     85 
     86 
     87 execute:
     88 	.block
     89 	pha
     90 	jsr ds.create_stack_frame
     91 	#ds.PUSH 4			; Local variables
     92 	pla
     93 	pha			; Save application number
     94 	;; Each app has 2**16 blocks, app number is in A, therefore
     95 	;; the address of the app is [#$00, A, #$00, #$01]
     96 	#ds.sta_LOCAL 1
     97 	#io.PRINTS "Loading and executing program "
     98 	#ds.lda_LOCAL 1
     99 	clc
    100 	adc #'0' 
    101 	jsr io.putc
    102 	#io.PRINTSNL "."
    103 	lda #$00
    104 	#ds.sta_LOCAL 0
    105 	#ds.sta_LOCAL 2
    106 	lda #$01
    107 	#ds.sta_LOCAL 3
    108 	#mem.COPY_WORD_ABSOLUTE_INDIRECT ds.ptr, sd.data ; Read block
    109 	#ds.PUSH $0200		; to stack
    110 	#ds.CALL sd.read_block, [0, 1, 2, 3], #ds.lda_LOCAL
    111 	#ds.PULL $0200		; Reset stack pointer to block read
    112 	#mem.COPY_WORD_IMMEDIATE load_address, sd.data ; Set Target address
    113 	lda (ds.ptr)	; Number of blocks
    114 read_next_block:	
    115 	pha
    116 	;; Advance to next block on card
    117 	clc
    118 	#ds.lda_LOCAL 3
    119 	adc #$01
    120 	#ds.sta_LOCAL 3
    121 	#ds.lda_LOCAL 2
    122 	adc #$00
    123 	#ds.sta_LOCAL 2
    124 	#ds.CALL sd.read_block, [0, 1, 2, 3], #ds.lda_LOCAL ; Read block
    125 	#mem.ADD_WORD sd.data, $0200			    ; Advance to next block
    126 	pla
    127 	dec a
    128 	bne read_next_block
    129 	jsr ds.delete_stack_frame
    130 	;; Done.
    131 	;; Turn off blinkenlight and execute program
    132 	lda via.ra
    133 	and #%11101111
    134 	sta via.ra
    135         jsr via.init
    136 	pla			; Application number stored on stack
    137 	jmp load_address	; passed to program executed.
    138 	.bend
    139 
    140 	
    141 	;; List programs on card
    142 ls_or_autostart:
    143 	.block
    144 	jsr ds.create_stack_frame
    145 	jsr sd.open
    146 	;; List files on card
    147 	#mem.COPY_WORD_ABSOLUTE_INDIRECT ds.ptr, sd.data ; Read block
    148 	#ds.PUSH $0200					; to stack
    149 	#ds.CALL sd.read_block, [#$00, #$00, #$00, #$00], lda
    150 	#ds.PULL $0200		; Reset stack pointer to point to block read
    151 	ldy #$00
    152 	lda (ds.ptr)
    153 	cmp #$15		; Check FS type
    154 	beq cont
    155 	jmp not_supported
    156 cont:	
    157 	iny
    158 	lda (ds.ptr),y
    159 	cmp #$e2		; Check FS type
    160 	beq cont1
    161 	jmp not_supported
    162 cont1:	
    163 	iny
    164 	lda (ds.ptr),y
    165 	cmp #$00		; Check FS version
    166 	beq cont2
    167 	jmp not_supported
    168 cont2:
    169 	iny
    170 	lda (ds.ptr),y
    171 	cmp #$ff		; Check autostart
    172 	beq list_files		; No autostart
    173 	;; Autostart
    174 	pha
    175 	jsr ds.delete_stack_frame
    176 	pla
    177 	jmp execute
    178 list_files:	
    179 	lda #$00		; File number
    180 dir_entry_loop:
    181 	pha
    182 	clc
    183 	adc #'0'
    184 	jsr io.putc
    185 	#io.PRINTS ": "
    186 	;; Each app has 2**16 blocks, therefore
    187 	;; the address of app i is [#$00, #i, #$00, #$01]
    188 	lda #$00
    189 	#ds.sta_LOCAL 0
    190 	#ds.sta_LOCAL 2
    191 	lda #$01
    192 	#ds.sta_LOCAL 3
    193 	pla
    194 	pha
    195 	#ds.sta_LOCAL 1
    196 	#ds.PUSH 4
    197 	#mem.COPY_WORD_ABSOLUTE_INDIRECT ds.ptr, sd.data ; Read block
    198 	#ds.PUSH $0200		; to stack
    199 	#ds.CALL sd.read_block, [0, 1, 2, 3], #ds.lda_LOCAL
    200 	#ds.PULL $0200		; Reset stack pointer to block read
    201 	lda (ds.ptr)	; Number of blocks
    202 	beq filename_printed	; This spot is not occupied
    203 	pha
    204 	#mem.COPY_WORD_ABSOLUTE_INDIRECT ds.ptr, io.puts_str
    205 	#mem.ADD_WORD io.puts_str, $01	; Start of filename
    206 	jsr io.puts
    207 	#io.PRINTS " ("
    208 	pla
    209 	pha
    210 	jsr io.putd
    211 	pla
    212 	cmp #$01
    213 	beq one_block
    214 	#io.PRINTS " blocks)"
    215 	jmp filename_printed
    216 one_block:
    217 	#io.PRINTS " block)"
    218 filename_printed:
    219 	jsr io.putnl
    220 	#ds.PULL 4
    221 	pla
    222 	inc a
    223 	cmp #$0a
    224 	bcs done
    225 	jmp dir_entry_loop
    226 done:	
    227 	clc
    228 	jsr ds.delete_stack_frame
    229 	rts
    230 not_supported:
    231 	#io.PRINTSNL "This filesystem is not supported."
    232 	sec
    233 	jsr ds.delete_stack_frame
    234 	rts
    235 	.bend
    236 
    237 end_of_code:
    238 .send code