1 ; Various functions: init, (RAM) disk, mmc, timer
2 ; This file needs to get split up.
4 ; Copyright (C) 2010 Sprite_tm
5 ; Copyright (C) 2010 Leo C.
7 ; This file is part of avrcpm.
9 ; avrcpm is free software: you can redistribute it and/or modify it
10 ; under the terms of the GNU General Public License as published by
11 ; the Free Software Foundation, either version 3 of the License, or
12 ; (at your option) any later version.
14 ; avrcpm is distributed in the hope that it will be useful,
15 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ; GNU General Public License for more details.
19 ; You should have received a copy of the GNU General Public License
20 ; along with avrcpm. If not, see <http://www.gnu.org/licenses/>.
25 #define REFR_PRE 8 /* timer prescale factor 1/8 */
26 #define REFR_CS 0x02 /* timer clock select for 1/8 */
27 #define REFR_CNT F_CPU / REFR_RATE / REFR_PRE
32 .db 0xFE,0xFC ; _RAS0 _CAS0
33 .db 0xF8,0xF4 ; _OE _WE
38 ldi temp,low(RAMEND) ; top of memory
39 out SPL,temp ; init stack pointer
40 ldi temp,high(RAMEND) ; top of memory
41 out SPH,temp ; init stack pointer
43 ; - Load some registers with constant values
49 cpi zl,low(regval_tab_e*2)
57 ldi temp,(1<<WDCE) | (1<<WDE)
64 ldi temp,(1<<PUD) ;disable pullups
66 out PORTD,_255 ;all pins high
69 out DDRD,_255 ; all outputs
72 cbi P_RXD-1,RXD ; RXD pin is input
82 ldi temp2,high(ramtop)
90 ; Init clock/timer system
92 ; Init timer 1 as 1 ms system clock tick.
94 ldi temp, low (F_CPU/1000)
95 ldi temp2,high(F_CPU/1000)
98 ldi temp,(1<<ICNC1)|(1<<CS10) ;Noise cancel, fall. edge, Normal Mode, clk/1
101 ori temp,(1<<OCIE1B) ;Enable 1ms int.
108 ;Init timer2. Refresh-call should happen every (8ms/512)=312 cycles.
110 ldi temp,REFR_CNT*2 ; 2 cycles per int
113 ori temp,(1<<WGM21) ;CTC mode
116 ori temp,REFR_CS ;clk/REFR_PRE
119 ori temp, (1<<OCIE2A)
132 .db 13,13,"CPM on an AVR, v"
133 db_version VMAJOR, VMINOR
137 printstring "Testing RAM: fill..."
147 printstring "wait..."
156 printstring "reread..."
168 cpi temp3,0 ;if first error
203 ;----------------------------------------------------------------------------
207 printstring "Initing mmc...",0
212 printstring "No bootable CP/M disk found! Please change MMC/SD-Card."
225 printstring "Partinit done."
227 ; Read first sector of first CP/M partition
235 rcall dsk_cboot ;init (de)blocking buffer
237 ;First sector of disk or first CP/M partition is in hostbuf.
239 ;Save to Z80 RAM (only 128 bytes because that's retro)
246 cpi zl,low(hostbuf+128)
248 cpi zh,high(hostbuf+128)