eris2010

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

os.asm (5985B)


      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 	DEBUG = false
      6 	;; DEBUG = true
      7 
      8 	CLOCK_SPEED = 4		;4 Mhz Clock
      9 
     10 .if SYMON
     11         rom_start = $c000
     12 .else
     13         rom_start = $e000
     14 .endif
     15         
     16 .include "os.inc"
     17 
     18 	* = $00
     19 .dsection zero_page
     20 .cerror * > $ff, "Zero page exhausted"
     21 	* = rom_start
     22 .dsection rom
     23 .cerror * > $ffff, "ROM exhausted"
     24 	
     25 os	.namespace 
     26 ram_end = $7fff
     27 .endn
     28 
     29 ;;; System jumps into memdump on NMIs. Since we want to be
     30 ;;; able to handle IRQs in RAM, the ROM isr routine jump to the
     31 ;;; address given here. After a reset, this RAM address is set to
     32 ;;; default_irq_handler.
     33 .namespace os
     34 irq_vector = os.ram_end - $1
     35 .endn
     36 
     37 	.section rom
     38 ;;; ----------------------------------------------------------
     39 ;;; RESET
     40 ;;;
     41 ;;; Initialize serial interface, read code from serial
     42 ;;; interface into RAM, execute it.
     43 ;;; ----------------------------------------------------------
     44 
     45 boot:	.block
     46 	sei
     47 	cld
     48 	;; Reset interrupt vector
     49         #mem.STORE_WORD os.default_irq_handler, os.irq_vector
     50         jsr via.init
     51         #io.SETUP
     52 	cli
     53 	ldx #$ff		; Reset return stack
     54 	txs
     55 	#ds.INIT_STACK os.ram_end-$206+$1 ;Minimal stack size to access SD card
     56 	#io.PRINTSNL "***** Eris 2010 8-Bit System (" .. VERSION .. ") *****"
     57         jsr check_for_program_download
     58         bcs no_program_download
     59         jmp download_program
     60 no_program_download:
     61         ;; No program download?
     62         ;; Start embedded program.
     63         jmp default_program
     64 	.bend
     65 
     66 ;;; If we receive a byte right after a reset, this
     67 ;;; triggers a program download via serial line.
     68 ;;; The value of the byte is the number of $100 byte
     69 ;;; blocks to receive.
     70 check_for_program_download:	.block
     71         #io.PRINTSNL "Kallisti!"
     72 	#io.PRINTNL
     73         ldy #$20  ; Outer loop counter
     74         ldx #$00  ; Inner counter
     75 loop:
     76 	;; Download sequence is initiated by sending $ff.
     77         jsr io.getc_nonblocking
     78         bcc got_byte
     79         dex
     80         bne loop
     81         dey
     82         bne loop
     83         sec
     84 	rts
     85 got_byte:
     86 	cmp #$ff
     87 	beq initiate_download
     88 	sec
     89         rts
     90 initiate_download:
     91 	clc
     92 	rts
     93 	.bend
     94         
     95 download_program:	.block
     96         ;; Program is loaded to this memory address
     97         start_addr = $0200
     98         ;; Location of temporary variables
     99         addr_pointer = $12   ; addr_pointer+1 stores MSB
    100         msb_last_addr = $14
    101         add_checksum = $15
    102         xor_checksum = $16
    103         ;; Get number of $100 blocks to be downloaded.
    104 	jsr io.getc
    105         ;; The msb of the last block to be written is the msb
    106         ;; of the start address plus the number of blocks.
    107         clc
    108         adc #>start_addr
    109         sta msb_last_addr
    110         ;; Read n * 0x100 bytes from acia
    111         lda #<start_addr
    112         sta addr_pointer
    113         lda #>start_addr
    114         sta addr_pointer+1
    115         ;; We calculate a two checksums over the data:
    116         ;; The first byte is the addition of all bytes
    117         ;; received. The second byte is the xor of all
    118         ;; bytes received.
    119         lda #$00
    120         sta add_checksum
    121         sta xor_checksum
    122 transmit_block:
    123         jsr io.getc
    124         ;; Store data
    125         ldy #$00
    126         sta (addr_pointer), y
    127         ;; Update checksums
    128         pha
    129         clc
    130         adc add_checksum
    131         sta add_checksum
    132         pla
    133         eor xor_checksum
    134         sta xor_checksum
    135         ;; Update LSB of target address and check if
    136         ;; transmission of block is completed.
    137         inc addr_pointer
    138         bne transmit_block
    139         ;; Transmission of one block completed.
    140         ;; If we are not done, increase
    141         ;; MSB of target address and continue
    142         inc addr_pointer+1
    143         lda addr_pointer+1
    144         cmp msb_last_addr
    145         bne transmit_block
    146         ;; Transmission completed.
    147         ;; Transmit result of checksum calculation
    148         lda add_checksum
    149         jsr io.putc
    150         lda xor_checksum
    151         jsr io.putc
    152 	;; Application number is passed to program
    153 	;; in A. Since uploaded programs do not have
    154 	;; an application number, we load A with $ff
    155 	lda #$ff
    156         ;; Start program
    157         jmp $0200
    158 	.bend
    159 
    160 memdump:
    161 	.block
    162 	ldx #$00		; Delay loop loop
    163 	ldy #$00		; to make sure that
    164 delay:				; we do not mess up
    165 	dey			; serial transfer.
    166 	bne delay
    167 	dex
    168 	bne delay
    169 	#io.PRINTSNL x"0d" .. x"0a" .. "-- BEGIN MEMORY DUMP --"
    170 	#io.PRINTS "Stack Pointer: "
    171 	tsx
    172 	txa
    173 	jsr io.puth
    174 	#mem.STORE_WORD $0000, os.memdump_ptr ; Start address of memory dump
    175 next_line:
    176 	jsr print_nl_and_address
    177 	ldy #$00
    178 next_byte:
    179 	lda (os.memdump_ptr),y	; Print next memory address.
    180 	phy
    181 	jsr io.puth
    182 	lda #' '
    183 	jsr io.putc
    184 	ply
    185 	iny			; Advance byte counter.
    186 	cpy #16			; 16 entries
    187 	bne next_byte		; per line.
    188 	lda os.memdump_ptr	; Check
    189 	cmp #<(os.ram_end-15)	; if
    190 	bne not_finished	; we
    191 	lda os.memdump_ptr+1	; are
    192 	cmp #>(os.ram_end-15)	; done.
    193 	bne not_finished
    194 	#io.PRINTSNL x"0d" .. x"0a" .. "-- END MEMORY DUMP --"
    195 	rti
    196 not_finished:
    197 	#mem.ADD_WORD os.memdump_ptr, 16 ; Advance memory pointer
    198 	jmp next_line
    199 print_nl_and_address:
    200 	#io.PRINTNL
    201 	lda os.memdump_ptr+1
    202 	jsr io.puth
    203 	lda os.memdump_ptr
    204 	jsr io.puth
    205 	#io.PRINTS ": "
    206 	rts
    207 	.bend
    208 	
    209 
    210 .include "io.asm"
    211 .include "ds.asm"
    212 .include "lfsr.asm"
    213 .include "via.asm"
    214 .include "sd.asm"
    215 .include "term.asm"
    216 	
    217 .namespace os 
    218 .section zero_page
    219 memdump_ptr:	.word  ?
    220 rom_zero_page_end:
    221 .send zero_page
    222 .endn
    223 
    224 ;;; Default IRQ handler. Unless the user program changes
    225 ;;; the irq_vector, IRQs are handled here.
    226 .namespace os
    227 default_irq_handler:
    228 .endn
    229 	rti
    230 	
    231 derefer_ram_irq:
    232 	;; Jump to the address given in the IRQ vector
    233 	;; in RAM
    234 	jmp (os.irq_vector)
    235 	
    236 default_program:
    237 ;; .include "../../sw/asm/10print/10print.asm"
    238 ;; .include "../../sw/asm/ttt/ttt.asm"
    239 .include "../../sw/asm/load_from_card/load_from_card.asm"
    240 
    241 ;;; Vectors
    242         .fill $fffa-*, $ff
    243         .word memdump  		; nmi
    244         .word boot              ; reset
    245 	.word derefer_ram_irq   ; irq
    246 
    247 .send rom