X-Git-Url: http://cloudbase.mooo.com/gitweb/avrcpm.git/blobdiff_plain/f2114c72ecf341b6b8cfb71c440cef7aeb2ccf0c..18be946b6d6633ccda8b9ab2d5894b23e815a63d:/avrcpm/avr/z80.asm?ds=sidebyside diff --git a/avrcpm/avr/z80.asm b/avrcpm/avr/z80.asm index 0f2e46b..64f0786 100644 --- a/avrcpm/avr/z80.asm +++ b/avrcpm/avr/z80.asm @@ -15,6 +15,9 @@ ; ; You should have received a copy of the GNU General Public License ; along with this program. If not, see . +; +; $Id$ +; ;.nolist #if defined atmega8 @@ -31,9 +34,6 @@ .list .listmac -#ifndef DRAM_DQ_ORDER /* If this is set to 1, the portbits */ - #define DRAM_DQ_ORDER 0 /* for DRAM D1 and WE are swapped. */ -#endif #ifndef F_CPU @@ -43,11 +43,15 @@ #define BAUD 38400 /* console baud rate */ #endif +#define PARTID 0x52 /* Partition table id */ + /* http://www.win.tue.nl/~aeb/partitions/partition_types-1.html */ #define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1) /* clever rounding */ #define RXBUFSIZE 64 /* USART recieve buffer size. Must be power of 2 */ +#define TXBUFSIZE 64 /* USART transmit buffer size. Must be power of 2 */ +#define DRAM_WAITSTATES 1 /* Number of additional clock cycles for dram read access */ #define REFR_RATE 64000 /* dram refresh rate in cycles/s. */ /* Most drams need 1/15.6µs. */ #define REFR_PRE 8 /* timer prescale factor */ @@ -55,11 +59,6 @@ #define REFR_CNT F_CPU / REFR_RATE / REFR_PRE -#if defined __ATmega8__ - .equ refr_vect = OC2addr -#else - .equ refr_vect = OC2Aaddr -#endif #define DRAM_WORD_ACCESS 0 /* experimental */ @@ -115,16 +114,11 @@ .equ PB_OUTPUT_MASK = (1< 0x3f + sts @0,@1 +.else + out @0,@1 +.endif +.endm + +;---------------------------------------- +; +.macro inm8 +.if @1 > 0x3f + lds @0,@1 +.else + in @0,@1 +.endif +.endm + + + +;---------------------------------------- +; add wait states +; dram_wait number_of_cycles + +.macro dram_wait +.if @0 > 1 + rjmp PC+1 + dram_wait @0 - 2 +.elif @0 > 0 + nop + dram_wait @0 - 1 +.endif +.endm .cseg .org 0 rjmp start ; reset vector -.org refr_vect +.org OC2Aaddr rjmp refrint ; tim2cmpa .org OC1Aaddr ; Timer/Counter1 Compare Match A rjmp sysclockint ; 1ms system timer .org URXCaddr rjmp rxint ; USART receive int. -;.org UDREaddr -; rjmp txint +.org UDREaddr + rjmp txint ; USART transmit int. .org INT_VECTORS_SIZE @@ -264,124 +283,88 @@ start: ldi temp,high(RAMEND) ; top of memory out SPH,temp ; init stack pointer + clr _0 + ; - Kill wdt wdr -#if defined __ATmega8__ - out MCUCSR,_0 - - ldi temp,(1<",0 rcall printhex rcall printstr .db ".",13,0 - pop temp - pop zh - pop zl .endif ret @@ -1344,8 +1478,8 @@ mmcInitOcrLoopDone: ret -;Call this with adrh:adrl = sector number -;16bit lba address means a max reach of 32M. +;Call this with yh:yl:xh:xl = sector number +; mmcReadSect: ldi temp,0x50 out SPCR,temp @@ -1354,14 +1488,14 @@ mmcReadSect: rcall mmcByteNoSend ldi temp,0x51 ;cmd (read sector) rcall mmcByte - ldi temp,0 - lsl adrl - rol adrh - rol temp + lsl xl ;convert to byte address (*512) + rol xh + rol yl + mov temp,yl rcall mmcByte - mov temp,adrh ;pxl + mov temp,xh ;pxl rcall mmcByte - mov temp,adrl ;pyh + mov temp,xl ;pyh rcall mmcByte ldi temp,0 ;pyl rcall mmcByte @@ -1400,8 +1534,8 @@ mmcreadloop: ret -;Call this with adrh:adrl = sector number -;16bit lba address means a max reach of 32M. +;Call this with yh:yl:xh:xl = sector number +; mmcWriteSect: ldi temp,0x50 out SPCR,temp @@ -1411,14 +1545,14 @@ mmcWriteSect: ldi temp,0x58 ;cmd (write sector) rcall mmcByte - ldi temp,0 - lsl adrl - rol adrh - rol temp + lsl xl ;convert to byte address (*512) + rol xh + rol yl + mov temp,yl rcall mmcByte - mov temp,adrh ;pxl + mov temp,xh ;pxl rcall mmcByte - mov temp,adrl ;pyh + mov temp,xl ;pyh rcall mmcByte ldi temp,0 ;pyl rcall mmcByte @@ -1469,17 +1603,10 @@ mmcwaitwritten: ;Set up wdt to time out after 1 sec. resetAVR: cli -#if defined __ATmega8__ - ldi temp,(1< 21 cycles -; **************************************************************************** -; ------------- system timer 10ms --------------- +; ------------- system timer 1ms --------------- .dseg delay_timer: @@ -2074,8 +2207,8 @@ printhex: printstr: push zh push zl - push r29 - push r28 + push yh + push yl push temp in r29,sph in r28,spl @@ -2103,8 +2236,8 @@ printstr_end: std y+7,zl std y+6,zh pop temp - pop r28 - pop r29 + pop yl + pop yh pop zl pop zh ret @@ -2123,6 +2256,7 @@ printstr_end: .dseg #define RXBUFMASK RXBUFSIZE-1 +#define TXBUFMASK TXBUFSIZE-1 rxcount: .byte 1 @@ -2130,10 +2264,18 @@ rxidx_w: .byte 1 rxidx_r: .byte 1 +txcount: + .byte 1 +txidx_w: + .byte 1 +txidx_r: + .byte 1 rxfifo: .byte RXBUFSIZE - .byte 0 +txfifo: + .byte TXBUFSIZE +ramtop: .cseg ; Save received character in a circular buffer. Do nothing if buffer overflows. @@ -2144,11 +2286,7 @@ rxint: push temp push zh push zl -#ifdef __ATmega8__ - in temp,UDR -#else - lds temp,UDR0 -#endif + inm8 temp,RXTXDR0 lds zh,rxcount ;if rxcount < RXBUFSIZE cpi zh,RXBUFSIZE ; (room for at least 1 char?) brsh rxi_ov ; @@ -2202,24 +2340,74 @@ uartgetc: pop zh ret +txint: + push temp + in temp,sreg + push temp + lds temp,txcount ;if txcount != 0 + tst temp ; + breq txi_e ; + + dec temp ; + sts txcount,temp ; --txcount + push zh ; + push zl ; + ldi zl,low(txfifo) ; + ldi zh,high(txfifo) ; + lds temp,txidx_r ; + add zl,temp ; + brcc PC+2 ; + inc zh ; + inc temp ; + andi temp,TXBUFMASK ; + sts txidx_r,temp ; + ld temp,z + outm8 RXTXDR0,temp + pop zl + pop zh +txi_e: ;endif + lds temp,txcount + tst temp + brne txi_x + ldi temp, (1<= TXBUFSIZE) + + ldi zl,low(txfifo) ; + ldi zh,high(txfifo) ; + lds temp,txidx_w ; + add zl,temp ; + brcc PC+2 ; + inc zh ; + inc temp ; + andi temp,TXBUFMASK ; + sts txidx_w,temp ; txidx_w = ++txidx_w % TXBUFSIZE + pop temp ; + st z,temp ; txfifo[txidx_w] = char + cli + lds zl,txcount + inc zl + sts txcount,zl + ldi zl, (1<