OpenCores
URL https://opencores.org/ocsvn/RISCMCU/RISCMCU/trunk

Subversion Repositories RISCMCU

Compare Revisions

  • This comparison shows the changes necessary to convert path
    /
    from Rev 17 to Rev 18
    Reverse comparison

Rev 17 → Rev 18

/trunk/asm/calc.asm
0,0 → 1,289
.include "riscmcu.inc"
 
.def key = r16
.def temp = r17
.def B = r18
.def C = r19
.def addsub = r24
.def counter = r25
.def tcount = r26
.def led = r27
 
.cseg
rjmp reset
rjmp extint
rjmp timer
 
extint:
clr B
clr C
clr addsub
out portb,c
reti
 
timer:
in temp,sreg
inc tcount
cpi tcount,24
brne tback
clr tcount
cpi led,0b10000
brne t4
ldi led,0b0001
t4: com led
out portc,led
com led
lsl led
out sreg,temp
tback: reti
 
 
reset:
 
clr B
clr C
clr addsub
ldi counter,3
ldi led,0b0001
 
ldi temp,0b11110000
out ddrd,temp
ser temp
out ddrb,temp ; PORT B as output
out ddrc,temp ; PORT C as output
out portc,temp ; PORT C leds OFF
out portd,temp ; PORT D output HI
out gimsk,temp ; Enable external interrupt
out timsk,temp ; Enable Timer interrupt
ldi temp,5
out tccr0,temp ; timer clock source = divide by 1024
 
rcall ldtable
sei
 
;*************************************************
; Detect Keys
 
rescan: rcall sdelay
sbi portd,6
cbi portd,4
ldi zp,table
in key,pind
cbr key,$F0
cpi key,$0F
brne press
 
sbi portd,4
cbi portd,5
ldi zp,table+1
in key,pind
cbr key,$F0
cpi key,$0F
brne press
 
sbi portd,5
cbi portd,6
ldi zp,table+2
in key,pind
cbr key,$F0
cpi key,$0F
brne press
 
rjmp rescan
 
press:
rcall sdelay
in temp,pind
cbr temp,$F0
cpse key,temp
rjmp rescan
sbrs key,1
subi zp,-3
sbrs key,2
subi zp,-6
sbrs key,3
subi zp,-9
ld key,Z
 
;*************************************************
; Operation
 
cpi key,$A
breq addkey
cpi key,$B
breq subkey
swap B
cbr B,$0f
add B,key
out portb,B
 
rjmp holding
 
addkey:
cbr addsub,$01
rjmp arith
 
subkey:
sbr addsub,$01
 
arith:
swap addsub
sbrc addsub,0
rjmp subf
rcall BCDadd
out portb,C
rcall overflow
clr B
rjmp holding
 
subf:
rcall BCDsub
out portb,C
rcall overflow
clr B
rjmp holding
 
;*************************************************
; Key press released ?
 
holding:
rcall sdelay
in key,pind
cbr key,$F0
ldi temp,$0F
cpse key,temp
rjmp holding
rjmp rescan
 
;*************************************************
; overflow ?
 
overflow:
sbrs b,0
ret
cli
sbi ddrd,7
cbi portd,7
rcall delay
sbi portd,7
cbi ddrd,7
sei
ret
 
;*************************************************
; Short Delay
 
sdelay:
clr temp
s10: dec temp
brne s10
ret
 
;*************************************************
; Load Table
 
ldtable:
ldi ZP,table
ldi temp,1
st Z+,temp
ldi temp,2
st Z+,temp
ldi temp,3
st Z+,temp
ldi temp,4
st Z+,temp
ldi temp,5
st Z+,temp
ldi temp,6
st Z+,temp
ldi temp,7
st Z+,temp
ldi temp,8
st Z+,temp
ldi temp,9
st Z+,temp
ldi temp,$B
st Z+,temp
ldi temp,0
st Z+,temp
ldi temp,$A
st Z+,temp
ret
 
;*******************************************
delay:
del: ldi ZP,count
ld temp,Z
dec temp
st Z,temp
brne del
ldi ZP,count+1
ld temp,Z
dec temp
st Z,temp
brne del
dec counter
brne del
ldi counter,3
ret
 
;***** Subroutine Register Variables
 
.def BCD1 =r19 ;BCD input value #1
.def BCD2 =r18 ;BCD input value #2
.def tmpadd =r16 ;temporary register
 
;***** Code
 
BCDadd:
ldi tmpadd,6 ;value to be added later
add BCD1,BCD2 ;add the numbers binary
clr BCD2 ;clear BCD carry
brcc add_0 ;if carry not clear
ldi BCD2,1 ; set BCD carry
add_0: brhs add_1 ;if half carry not set
add BCD1,tmpadd ; add 6 to LSD
brhs add_2 ; if half carry not set (LSD <= 9)
subi BCD1,6 ; restore value
rjmp add_2 ;else
add_1: add BCD1,tmpadd ; add 6 to LSD
add_2: swap tmpadd
add BCD1,tmpadd ;add 6 to MSD
brcs add_4 ;if carry not set (MSD <= 9)
sbrs BCD2,0 ; if previous carry not set
subi BCD1,$60 ; restore value
add_3: ret ;else
add_4: ldi BCD2,1 ; set BCD carry
ret
 
 
;***** Subroutine Register Variables
 
.def BCDa =r19 ;BCD input value #1
.def BCDb =r18 ;BCD input value #2
 
;***** Code
 
BCDsub:
sub BCDa,BCDb ;subtract the numbers binary
clr BCDb
brcc sub_0 ;if carry not clear
ldi BCDb,1 ; store carry in BCDB1, bit 0
sub_0: brhc sub_1 ;if half carry not clear
subi BCDa,$06 ; LSD = LSD - 6
sub_1: sbrs BCDb,0 ;if previous carry not set
ret ; return
subi BCDa,$60 ;subtract 6 from MSD
ldi BCDb,1 ;set underflow carry
brcc sub_2 ;if carry not clear
ldi BCDb,1 ; clear underflow carry
sub_2: ret
 
 
 
.dseg
table: .byte 12
count: .byte 2
/trunk/asm/game.obj Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream
trunk/asm/game.obj Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: trunk/asm/calc.lst =================================================================== --- trunk/asm/calc.lst (nonexistent) +++ trunk/asm/calc.lst (revision 18) @@ -0,0 +1,333 @@ + +AVRASM ver. 1.30 CALC.ASM Sun Mar 17 14:05:28 2002 + + + .include "riscmcu.inc" + + ;***** I/O Register Definitions + + .equ SREG =$3f + .equ GIMSK =$3b + .equ TIMSK =$39 + .equ TIFR =$38 + .equ MCUCR =$35 + .equ TCCR0 =$33 + .equ TCNT0 =$32 + + .equ PORTB =$18 + .equ DDRB =$17 + .equ PINB =$16 + .equ PORTC =$15 + .equ DDRC =$14 + .equ PINC =$13 + .equ PORTD =$12 + .equ DDRD =$11 + .equ PIND =$10 + + + ;***** Bit Definitions + + .equ INT0 =6 + + .equ TOIE0 =1 + + .equ TOV0 =1 + + .equ ISC01 =1 + .equ ISC00 =0 + + .equ CS02 =2 + .equ CS01 =1 + .equ CS00 =0 + + .def ZP =r30 + + + .def key = r16 + .def temp = r17 + .def B = r18 + .def C = r19 + .def addsub = r24 + .def counter = r25 + .def tcount = r26 + .def led = r27 + + .cseg +000000 c015 rjmp reset +000001 c001 rjmp extint +000002 c005 rjmp timer + + extint: +000003 2722 clr B +000004 2733 clr C +000005 2788 clr addsub +000006 bb38 out portb,c +000007 9518 reti + + timer: +000008 b71f in temp,sreg +000009 95a3 inc tcount +00000a 31a8 cpi tcount,24 +00000b f449 brne tback +00000c 27aa clr tcount +00000d 31b0 cpi led,0b10000 +00000e f409 brne t4 +00000f e0b1 ldi led,0b0001 +000010 95b0 t4: com led +000011 bbb5 out portc,led +000012 95b0 com led +000013 0fbb lsl led +000014 bf1f out sreg,temp +000015 9518 tback: reti + + + reset: + +000016 2722 clr B +000017 2733 clr C +000018 2788 clr addsub +000019 e093 ldi counter,3 +00001a e0b1 ldi led,0b0001 + +00001b ef10 ldi temp,0b11110000 +00001c bb11 out ddrd,temp +00001d ef1f ser temp +00001e bb17 out ddrb,temp ; PORT B as output +00001f bb14 out ddrc,temp ; PORT C as output +000020 bb15 out portc,temp ; PORT C leds OFF +000021 bb12 out portd,temp ; PORT D output HI +000022 bf1b out gimsk,temp ; Enable external interrupt +000023 bf19 out timsk,temp ; Enable Timer interrupt +000024 e015 ldi temp,5 +000025 bf13 out tccr0,temp ; timer clock source = divide by 1024 + +000026 d052 rcall ldtable +000027 9478 sei + + ;************************************************* + ; Detect Keys + +000028 d04c rescan: rcall sdelay + +000029 9a96 sbi portd,6 +00002a 9894 cbi portd,4 +00002b e6e0 ldi zp,table +00002c b300 in key,pind +00002d 700f cbr key,$F0 +00002e 300f cpi key,$0F +00002f f479 brne press + +000030 9a94 sbi portd,4 +000031 9895 cbi portd,5 +000032 e6e1 ldi zp,table+1 +000033 b300 in key,pind +000034 700f cbr key,$F0 +000035 300f cpi key,$0F +000036 f441 brne press + +000037 9a95 sbi portd,5 +000038 9896 cbi portd,6 +000039 e6e2 ldi zp,table+2 +00003a b300 in key,pind +00003b 700f cbr key,$F0 +00003c 300f cpi key,$0F +00003d f409 brne press + +00003e cfe9 rjmp rescan + + press: +00003f d035 rcall sdelay +000040 b310 in temp,pind +000041 701f cbr temp,$F0 +000042 1301 cpse key,temp +000043 cfe4 rjmp rescan +000044 ff01 sbrs key,1 +000045 5fed subi zp,-3 +000046 ff02 sbrs key,2 +000047 5fea subi zp,-6 +000048 ff03 sbrs key,3 +000049 5fe7 subi zp,-9 +00004a 8100 ld key,Z + + ;************************************************* + ; Operation + +00004b 300a cpi key,$A +00004c f039 breq addkey +00004d 300b cpi key,$B +00004e f039 breq subkey + +00004f 9522 swap B +000050 7f20 cbr B,$0f +000051 0f20 add B,key +000052 bb28 out portb,B + +000053 c010 rjmp holding + + addkey: +000054 7f8e cbr addsub,$01 +000055 c001 rjmp arith + + subkey: +000056 6081 sbr addsub,$01 + + arith: +000057 9582 swap addsub +000058 fd80 sbrc addsub,0 +000059 c005 rjmp subf +00005a d046 rcall BCDadd +00005b bb38 out portb,C +00005c d00e rcall overflow +00005d 2722 clr B +00005e c005 rjmp holding + + subf: +00005f d054 rcall BCDsub +000060 bb38 out portb,C +000061 d009 rcall overflow +000062 2722 clr B +000063 c000 rjmp holding + + ;************************************************* + ; Key press released ? + + holding: +000064 d010 rcall sdelay +000065 b300 in key,pind +000066 700f cbr key,$F0 +000067 e01f ldi temp,$0F +000068 1301 cpse key,temp +000069 cffa rjmp holding +00006a cfbd rjmp rescan + + ;************************************************* + ; overflow ? + + overflow: +00006b ff20 sbrs b,0 +00006c 9508 ret +00006d 94f8 cli +00006e 9a8f sbi ddrd,7 +00006f 9897 cbi portd,7 +000070 d022 rcall delay +000071 9a97 sbi portd,7 +000072 988f cbi ddrd,7 +000073 9478 sei +000074 9508 ret + + ;************************************************* + ; Short Delay + + sdelay: +000075 2711 clr temp +000076 951a s10: dec temp +000077 f7f1 brne s10 +000078 9508 ret + + ;************************************************* + ; Load Table + + ldtable: +000079 e6e0 ldi ZP,table +00007a e011 ldi temp,1 +00007b 9311 st Z+,temp +00007c e012 ldi temp,2 +00007d 9311 st Z+,temp +00007e e013 ldi temp,3 +00007f 9311 st Z+,temp +000080 e014 ldi temp,4 +000081 9311 st Z+,temp +000082 e015 ldi temp,5 +000083 9311 st Z+,temp +000084 e016 ldi temp,6 +000085 9311 st Z+,temp +000086 e017 ldi temp,7 +000087 9311 st Z+,temp +000088 e018 ldi temp,8 +000089 9311 st Z+,temp +00008a e019 ldi temp,9 +00008b 9311 st Z+,temp +00008c e01b ldi temp,$B +00008d 9311 st Z+,temp +00008e e010 ldi temp,0 +00008f 9311 st Z+,temp +000090 e01a ldi temp,$A +000091 9311 st Z+,temp +000092 9508 ret + + ;******************************************* + delay: +000093 e6ec del: ldi ZP,count +000094 8110 ld temp,Z +000095 951a dec temp +000096 8310 st Z,temp +000097 f7d9 brne del +000098 e6ed ldi ZP,count+1 +000099 8110 ld temp,Z +00009a 951a dec temp +00009b 8310 st Z,temp +00009c f7b1 brne del +00009d 959a dec counter +00009e f7a1 brne del +00009f e093 ldi counter,3 +0000a0 9508 ret + + ;***** Subroutine Register Variables + + .def BCD1 =r19 ;BCD input value #1 + .def BCD2 =r18 ;BCD input value #2 + .def tmpadd =r16 ;temporary register + + ;***** Code + + BCDadd: +0000a1 e006 ldi tmpadd,6 ;value to be added later +0000a2 0f32 add BCD1,BCD2 ;add the numbers binary +0000a3 2722 clr BCD2 ;clear BCD carry +0000a4 f408 brcc add_0 ;if carry not clear +0000a5 e021 ldi BCD2,1 ; set BCD carry +0000a6 f025 add_0: brhs add_1 ;if half carry not set +0000a7 0f30 add BCD1,tmpadd ; add 6 to LSD +0000a8 f01d brhs add_2 ; if half carry not set (LSD <= 9) +0000a9 5036 subi BCD1,6 ; restore value +0000aa c001 rjmp add_2 ;else +0000ab 0f30 add_1: add BCD1,tmpadd ; add 6 to LSD +0000ac 9502 add_2: swap tmpadd +0000ad 0f30 add BCD1,tmpadd ;add 6 to MSD +0000ae f018 brcs add_4 ;if carry not set (MSD <= 9) +0000af ff20 sbrs BCD2,0 ; if previous carry not set +0000b0 5630 subi BCD1,$60 ; restore value +0000b1 9508 add_3: ret ;else +0000b2 e021 add_4: ldi BCD2,1 ; set BCD carry +0000b3 9508 ret + + + ;***** Subroutine Register Variables + + .def BCDa =r19 ;BCD input value #1 + .def BCDb =r18 ;BCD input value #2 + + ;***** Code + + BCDsub: +0000b4 1b32 sub BCDa,BCDb ;subtract the numbers binary +0000b5 2722 clr BCDb +0000b6 f408 brcc sub_0 ;if carry not clear +0000b7 e021 ldi BCDb,1 ; store carry in BCDB1, bit 0 +0000b8 f40d sub_0: brhc sub_1 ;if half carry not clear +0000b9 5036 subi BCDa,$06 ; LSD = LSD - 6 +0000ba ff20 sub_1: sbrs BCDb,0 ;if previous carry not set +0000bb 9508 ret ; return +0000bc 5630 subi BCDa,$60 ;subtract 6 from MSD +0000bd e021 ldi BCDb,1 ;set underflow carry +0000be f408 brcc sub_2 ;if carry not clear +0000bf e021 ldi BCDb,1 ; clear underflow carry +0000c0 9508 sub_2: ret + + + + + .dseg +000060 table: .byte 12 +00006c count: .byte 2 +Assembly complete with no errors. Index: trunk/asm/game.mif =================================================================== --- trunk/asm/game.mif (nonexistent) +++ trunk/asm/game.mif (revision 18) @@ -0,0 +1,165 @@ +width = 16; +depth = 512; + +address_radix = hex; +data_radix = hex; + +content begin +[0..1ff]: 0; + +000000:c002; +000001:9518; +000002:9518; +000003:e045; +000004:ef0f; +000005:bb07; +000006:bb01; +000007:bb05; +000008:bb02; +000009:e001; +00000a:bf03; +00000b:e00f; +00000c:bb04; +00000d:e063; +00000e:e071; +00000f:94e8; +000010:d04f; +000011:d015; +000012:bb78; +000013:d047; +000014:d070; +000015:d02c; +000016:d037; +000017:f026; +000018:d01a; +000019:9573; +00001a:bb78; +00001b:cff8; +00001c:d010; +00001d:d067; +00001e:956a; +00001f:d007; +000020:bb78; +000021:d063; +000022:3060; +000023:f349; +000024:d012; +000025:94e8; +000026:cfef; +000027:2f06; +000028:6f00; +000029:bb08; +00002a:d05a; +00002b:d059; +00002c:9508; +00002d:2700; +00002e:bb05; +00002f:d055; +000030:ef0f; +000031:bb05; +000032:9508; +000033:9897; +000034:d050; +000035:9a97; +000036:9508; +000037:d033; +000038:9101; +000039:bb05; +00003a:d04a; +00003b:ef0f; +00003c:bb05; +00003d:e041; +00003e:d046; +00003f:951a; +000040:f7b9; +000041:9508; +000042:d028; +000043:d02a; +000044:9321; +000045:bb25; +000046:d03e; +000047:ef0f; +000048:bb05; +000049:e041; +00004a:d03a; +00004b:951a; +00004c:f7b1; +00004d:9508; +00004e:d01c; +00004f:d00b; +000050:9478; +000051:d00e; +000052:94f8; +000053:9101; +000054:1320; +000055:9468; +000056:d004; +000057:d03d; +000058:951a; +000059:f7a9; +00005a:9508; +00005b:b303; +00005c:7f00; +00005d:3f00; +00005e:f7e1; +00005f:9508; +000060:b323; +000061:7f20; +000062:3f20; +000063:f3e1; +000064:d030; +000065:b303; +000066:7f00; +000067:1702; +000068:f7b9; +000069:9522; +00006a:9508; +00006b:2f17; +00006c:e6e2; +00006d:9508; +00006e:b722; +00006f:3024; +000070:f010; +000071:5024; +000072:cffc; +000073:3020; +000074:f411; +000075:e02e; +000076:c009; +000077:3021; +000078:f411; +000079:e02d; +00007a:c005; +00007b:3022; +00007c:f411; +00007d:e02b; +00007e:c001; +00007f:e027; +000080:b702; +000081:9507; +000082:9507; +000083:bf02; +000084:9508; +000085:2f3e; +000086:e6e0; +000087:8100; +000088:950a; +000089:8300; +00008a:f7d9; +00008b:e6e1; +00008c:8100; +00008d:950a; +00008e:8300; +00008f:f7b1; +000090:954a; +000091:f7a1; +000092:e045; +000093:2fe3; +000094:9508; +000095:2700; +000096:950a; +000097:f7f1; +000098:9508; + + +end; \ No newline at end of file Index: trunk/asm/calc.hex =================================================================== --- trunk/asm/calc.hex (nonexistent) +++ trunk/asm/calc.hex (revision 18) @@ -0,0 +1,193 @@ +000000:c015 +000001:c001 +000002:c005 +000003:2722 +000004:2733 +000005:2788 +000006:bb38 +000007:9518 +000008:b71f +000009:95a3 +00000a:31a8 +00000b:f449 +00000c:27aa +00000d:31b0 +00000e:f409 +00000f:e0b1 +000010:95b0 +000011:bbb5 +000012:95b0 +000013:0fbb +000014:bf1f +000015:9518 +000016:2722 +000017:2733 +000018:2788 +000019:e093 +00001a:e0b1 +00001b:ef10 +00001c:bb11 +00001d:ef1f +00001e:bb17 +00001f:bb14 +000020:bb15 +000021:bb12 +000022:bf1b +000023:bf19 +000024:e015 +000025:bf13 +000026:d052 +000027:9478 +000028:d04c +000029:9a96 +00002a:9894 +00002b:e6e0 +00002c:b300 +00002d:700f +00002e:300f +00002f:f479 +000030:9a94 +000031:9895 +000032:e6e1 +000033:b300 +000034:700f +000035:300f +000036:f441 +000037:9a95 +000038:9896 +000039:e6e2 +00003a:b300 +00003b:700f +00003c:300f +00003d:f409 +00003e:cfe9 +00003f:d035 +000040:b310 +000041:701f +000042:1301 +000043:cfe4 +000044:ff01 +000045:5fed +000046:ff02 +000047:5fea +000048:ff03 +000049:5fe7 +00004a:8100 +00004b:300a +00004c:f039 +00004d:300b +00004e:f039 +00004f:9522 +000050:7f20 +000051:0f20 +000052:bb28 +000053:c010 +000054:7f8e +000055:c001 +000056:6081 +000057:9582 +000058:fd80 +000059:c005 +00005a:d046 +00005b:bb38 +00005c:d00e +00005d:2722 +00005e:c005 +00005f:d054 +000060:bb38 +000061:d009 +000062:2722 +000063:c000 +000064:d010 +000065:b300 +000066:700f +000067:e01f +000068:1301 +000069:cffa +00006a:cfbd +00006b:ff20 +00006c:9508 +00006d:94f8 +00006e:9a8f +00006f:9897 +000070:d022 +000071:9a97 +000072:988f +000073:9478 +000074:9508 +000075:2711 +000076:951a +000077:f7f1 +000078:9508 +000079:e6e0 +00007a:e011 +00007b:9311 +00007c:e012 +00007d:9311 +00007e:e013 +00007f:9311 +000080:e014 +000081:9311 +000082:e015 +000083:9311 +000084:e016 +000085:9311 +000086:e017 +000087:9311 +000088:e018 +000089:9311 +00008a:e019 +00008b:9311 +00008c:e01b +00008d:9311 +00008e:e010 +00008f:9311 +000090:e01a +000091:9311 +000092:9508 +000093:e6ec +000094:8110 +000095:951a +000096:8310 +000097:f7d9 +000098:e6ed +000099:8110 +00009a:951a +00009b:8310 +00009c:f7b1 +00009d:959a +00009e:f7a1 +00009f:e093 +0000a0:9508 +0000a1:e006 +0000a2:0f32 +0000a3:2722 +0000a4:f408 +0000a5:e021 +0000a6:f025 +0000a7:0f30 +0000a8:f01d +0000a9:5036 +0000aa:c001 +0000ab:0f30 +0000ac:9502 +0000ad:0f30 +0000ae:f018 +0000af:ff20 +0000b0:5630 +0000b1:9508 +0000b2:e021 +0000b3:9508 +0000b4:1b32 +0000b5:2722 +0000b6:f408 +0000b7:e021 +0000b8:f40d +0000b9:5036 +0000ba:ff20 +0000bb:9508 +0000bc:5630 +0000bd:e021 +0000be:f408 +0000bf:e021 +0000c0:9508 Index: trunk/asm/game.asm =================================================================== --- trunk/asm/game.asm (nonexistent) +++ trunk/asm/game.asm (revision 18) @@ -0,0 +1,237 @@ +.include "riscmcu.inc" + +.def temp = r16 +.def times = r17 +.def num = r18 +.def stack = r19 +.def counter = r20 +.def life = r22 +.def level = r23 +.def temp2 = r24 + +.cseg + rjmp reset + reti + reti + +reset: + ldi counter,5 + + ser temp + out ddrb,temp ; Port B direction as OUTPUT + out ddrd,temp ; Port D direction as OUTPUT + out portc,temp + out portd,temp + + ldi temp,1 + out tccr0,temp ; set clock as timer clock source + ldi temp,$0F + out ddrc,temp ; PinC[3..0] output, [7..4] input + +start: + ldi life,3 + ldi level,1 + clt ; T = 0, start with correct + + rcall getinput ; hit any key to start the game + rcall showlife + out portB,level ; output level to display + rcall holding ; release? + +nextlevel: + rcall delay ; wait a while before the game is started + rcall showled ; show the LEDs and save it in buffer +nlife: rcall check ; get input and check + brts wrong + rcall greenled + inc level ; when win, level <- level + 1 + out portB,level ; output level to display + rjmp nextlevel +wrong: rcall redled + rcall delay + dec life + rcall showlife + out portb,level + rcall delay + cpi life,0 + breq start + rcall playback + clt + rjmp nlife + + +;******************************************* +; show life +showlife: + mov temp,life + sbr temp,$f0 + out portb,temp + rcall delay + rcall delay + ret + +;******************************************* +; on red leds + +redled: + clr temp + out portc,temp + rcall delay + ser temp + out portc,temp + ret + +;******************************************* +; on green led + +greenled: + cbi portd,7 + rcall delay + sbi portd,7 + ret + + +;******************************************* +; play back the last sequence when wrong + +playback: + rcall init +w10: ld temp,Z+ + out portC,temp + rcall delay + ser temp ; OFF + out portC,temp + ldi counter,1 + rcall delay + dec times + brne w10 + ret + +;******************************************* +; Show sequence of LEDs (base on times), save in buffer + +showled: + rcall init +snext: rcall random ; return in NUM + st Z+,num + out portC,num ; display the LED + rcall delay + ser temp ; OFF + out portC,temp + ldi counter,1 + rcall delay + dec times + brne snext + ret + + +;******************************************* +; wait for input and check +; return T = 0 when corrert, T = 1 when wrong + +check: + rcall init +nextkey: + rcall holding + sei + rcall getinput ; return in NUM + cli + ld temp,Z+ + cpse num,temp + set ; Set T flag if one key is wrong + rcall holding + rcall sdelay + dec times + brne nextkey + ret + +;******************************************* +; still holding the key ? + +holding: + in temp,pinc + cbr temp,$0F + cpi temp,$F0 + brne holding + ret + +;******************************************* +; getinput + +getinput: +g15: in num,pinc + cbr num,$0F ; clear lower nibble + cpi num,$F0 + breq g15 + rcall sdelay + in temp,pinc + cbr temp,$0F + cp temp,num + brne g15 + swap num + ret + +;******************************************* +; 1. Load level to times +; 2. ZP point to start of buffer + +init: mov times,level ; times <- level + ldi ZP,buffer ; ZP <- buffer + ret + +;******************************************* +; Generate Random Num, return in NUM + +random: + in num,tcnt0 +ran: cpi num,4 + brlo rnext + subi num,4 + rjmp ran +rnext: cpi num,0 + brne r10 + ldi num,0b1110 + rjmp rend +r10: cpi num,1 + brne r20 + ldi num,0b1101 + rjmp rend +r20: cpi num,2 + brne r30 + ldi num,0b1011 + rjmp rend +r30: ldi num,0b0111 +rend: in temp,tcnt0 + ror temp + ror temp + out tcnt0,temp + ret + +;******************************************* +delay: + mov stack,ZP +del: ldi ZP,count + ld temp,Z + dec temp + st Z,temp + brne del + ldi ZP,count+1 + ld temp,Z + dec temp + st Z,temp + brne del + dec counter + brne del + ldi counter,5 + mov ZP,stack + ret + +sdelay: + clr temp +sd5: dec temp + brne sd5 + ret +;******************************************* +.dseg +count: .byte 2 +buffer: .byte 20 \ No newline at end of file Index: trunk/asm/game.lst =================================================================== --- trunk/asm/game.lst (nonexistent) +++ trunk/asm/game.lst (revision 18) @@ -0,0 +1,281 @@ + +AVRASM ver. 1.30 GAME.ASM Sun Mar 17 14:05:31 2002 + + + .include "riscmcu.inc" + + ;***** I/O Register Definitions + + .equ SREG =$3f + .equ GIMSK =$3b + .equ TIMSK =$39 + .equ TIFR =$38 + .equ MCUCR =$35 + .equ TCCR0 =$33 + .equ TCNT0 =$32 + + .equ PORTB =$18 + .equ DDRB =$17 + .equ PINB =$16 + .equ PORTC =$15 + .equ DDRC =$14 + .equ PINC =$13 + .equ PORTD =$12 + .equ DDRD =$11 + .equ PIND =$10 + + + ;***** Bit Definitions + + .equ INT0 =6 + + .equ TOIE0 =1 + + .equ TOV0 =1 + + .equ ISC01 =1 + .equ ISC00 =0 + + .equ CS02 =2 + .equ CS01 =1 + .equ CS00 =0 + + .def ZP =r30 + + + .def temp = r16 + .def times = r17 + .def num = r18 + .def stack = r19 + .def counter = r20 + .def life = r22 + .def level = r23 + .def temp2 = r24 + + .cseg +000000 c002 rjmp reset +000001 9518 reti +000002 9518 reti + + reset: +000003 e045 ldi counter,5 + +000004 ef0f ser temp +000005 bb07 out ddrb,temp ; Port B direction as OUTPUT +000006 bb01 out ddrd,temp ; Port D direction as OUTPUT +000007 bb05 out portc,temp +000008 bb02 out portd,temp + +000009 e001 ldi temp,1 +00000a bf03 out tccr0,temp ; set clock as timer clock source +00000b e00f ldi temp,$0F +00000c bb04 out ddrc,temp ; PinC[3..0] output, [7..4] input + + start: +00000d e063 ldi life,3 +00000e e071 ldi level,1 +00000f 94e8 clt ; T = 0, start with correct + +000010 d04f rcall getinput ; hit any key to start the game +000011 d015 rcall showlife +000012 bb78 out portB,level ; output level to display +000013 d047 rcall holding ; release? + + nextlevel: +000014 d070 rcall delay ; wait a while before the game is started +000015 d02c rcall showled ; show the LEDs and save it in buffer +000016 d037 nlife: rcall check ; get input and check +000017 f026 brts wrong +000018 d01a rcall greenled +000019 9573 inc level ; when win, level <- level + 1 +00001a bb78 out portB,level ; output level to display +00001b cff8 rjmp nextlevel +00001c d010 wrong: rcall redled +00001d d067 rcall delay +00001e 956a dec life +00001f d007 rcall showlife +000020 bb78 out portb,level +000021 d063 rcall delay +000022 3060 cpi life,0 +000023 f349 breq start +000024 d012 rcall playback +000025 94e8 clt +000026 cfef rjmp nlife + + + ;******************************************* + ; show life + showlife: +000027 2f06 mov temp,life +000028 6f00 sbr temp,$f0 +000029 bb08 out portb,temp +00002a d05a rcall delay +00002b d059 rcall delay +00002c 9508 ret + + ;******************************************* + ; on red leds + + redled: +00002d 2700 clr temp +00002e bb05 out portc,temp +00002f d055 rcall delay +000030 ef0f ser temp +000031 bb05 out portc,temp +000032 9508 ret + + ;******************************************* + ; on green led + + greenled: +000033 9897 cbi portd,7 +000034 d050 rcall delay +000035 9a97 sbi portd,7 +000036 9508 ret + + + ;******************************************* + ; play back the last sequence when wrong + + playback: +000037 d033 rcall init +000038 9101 w10: ld temp,Z+ +000039 bb05 out portC,temp +00003a d04a rcall delay +00003b ef0f ser temp ; OFF +00003c bb05 out portC,temp +00003d e041 ldi counter,1 +00003e d046 rcall delay +00003f 951a dec times +000040 f7b9 brne w10 +000041 9508 ret + + ;******************************************* + ; Show sequence of LEDs (base on times), save in buffer + + showled: +000042 d028 rcall init +000043 d02a snext: rcall random ; return in NUM +000044 9321 st Z+,num +000045 bb25 out portC,num ; display the LED +000046 d03e rcall delay +000047 ef0f ser temp ; OFF +000048 bb05 out portC,temp +000049 e041 ldi counter,1 +00004a d03a rcall delay +00004b 951a dec times +00004c f7b1 brne snext +00004d 9508 ret + + + ;******************************************* + ; wait for input and check + ; return T = 0 when corrert, T = 1 when wrong + + check: +00004e d01c rcall init + nextkey: +00004f d00b rcall holding +000050 9478 sei +000051 d00e rcall getinput ; return in NUM +000052 94f8 cli +000053 9101 ld temp,Z+ +000054 1320 cpse num,temp +000055 9468 set ; Set T flag if one key is wrong +000056 d004 rcall holding +000057 d03d rcall sdelay +000058 951a dec times +000059 f7a9 brne nextkey +00005a 9508 ret + + ;******************************************* + ; still holding the key ? + + holding: +00005b b303 in temp,pinc +00005c 7f00 cbr temp,$0F +00005d 3f00 cpi temp,$F0 +00005e f7e1 brne holding +00005f 9508 ret + + ;******************************************* + ; getinput + + getinput: +000060 b323 g15: in num,pinc +000061 7f20 cbr num,$0F ; clear lower nibble +000062 3f20 cpi num,$F0 +000063 f3e1 breq g15 +000064 d030 rcall sdelay +000065 b303 in temp,pinc +000066 7f00 cbr temp,$0F +000067 1702 cp temp,num +000068 f7b9 brne g15 +000069 9522 swap num +00006a 9508 ret + + ;******************************************* + ; 1. Load level to times + ; 2. ZP point to start of buffer + +00006b 2f17 init: mov times,level ; times <- level +00006c e6e2 ldi ZP,buffer ; ZP <- buffer +00006d 9508 ret + + ;******************************************* + ; Generate Random Num, return in NUM + + random: +00006e b722 in num,tcnt0 +00006f 3024 ran: cpi num,4 +000070 f010 brlo rnext +000071 5024 subi num,4 +000072 cffc rjmp ran +000073 3020 rnext: cpi num,0 +000074 f411 brne r10 +000075 e02e ldi num,0b1110 +000076 c009 rjmp rend +000077 3021 r10: cpi num,1 +000078 f411 brne r20 +000079 e02d ldi num,0b1101 +00007a c005 rjmp rend +00007b 3022 r20: cpi num,2 +00007c f411 brne r30 +00007d e02b ldi num,0b1011 +00007e c001 rjmp rend +00007f e027 r30: ldi num,0b0111 +000080 b702 rend: in temp,tcnt0 +000081 9507 ror temp +000082 9507 ror temp +000083 bf02 out tcnt0,temp +000084 9508 ret + + ;******************************************* + delay: +000085 2f3e mov stack,ZP +000086 e6e0 del: ldi ZP,count +000087 8100 ld temp,Z +000088 950a dec temp +000089 8300 st Z,temp +00008a f7d9 brne del +00008b e6e1 ldi ZP,count+1 +00008c 8100 ld temp,Z +00008d 950a dec temp +00008e 8300 st Z,temp +00008f f7b1 brne del +000090 954a dec counter +000091 f7a1 brne del +000092 e045 ldi counter,5 +000093 2fe3 mov ZP,stack +000094 9508 ret + + sdelay: +000095 2700 clr temp +000096 950a sd5: dec temp +000097 f7f1 brne sd5 +000098 9508 ret + ;******************************************* + .dseg +000060 count: .byte 2 +000062 buffer: .byte 20 +Assembly complete with no errors. Index: trunk/asm/calc.obj =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: trunk/asm/calc.obj =================================================================== --- trunk/asm/calc.obj (nonexistent) +++ trunk/asm/calc.obj (revision 18)
trunk/asm/calc.obj Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: trunk/asm/readme.txt =================================================================== --- trunk/asm/readme.txt (nonexistent) +++ trunk/asm/readme.txt (revision 18) @@ -0,0 +1,58 @@ +------------ +AVR Assember +------------ + +Click on 'Options...' Menu +1. Select 'Generic Format' under the Output file format (MUST for HEX2MIF to work!) +2. Check the 'Save before assemble' box. + +calc.asm Simple Calculator Source Code +memgame.asm Simple Memory Game Source Code +riscmcu.inc Include File for *.ASM (I/O register and bit definition for this design) + +With an ASM file and the riscmcu.inc file, AVR Assembler generates + +*.hex Hex file : used by HEX2MIF +*.lst Listing file +*.obj Object file : used by AVR Studio for simulation + + +---------- +AVR Studio +---------- + +Open the OBJ file, set + +Prog.Memory 512 +Data Memory 256* +EEPROM 0 +I/O Size 64 +Hardware Stack check +Levels 4 +Map I/O in Data Area check +Frequency any + +You can go to Simulator Options (under Options menu) to set this anytime. + +Then press +ALT-0 Registers View +ALT-4 New Memory View +ALT-5 New I/O View, choose riscmcu.aio** + +* The design only have 128 bytes of data RAM, but the simulator can not display the 128 locations when I put 128. 256 works, just ignored anything after the valid 128 byes. +** External interrupt can not be simulated because the design mapped the external interrupt pin to D7 but the simulator map it to pin D2 (according to AT90S1200). + + +------- +HEX2MIF +------- + +calc.mif Simple Calculator MIF file +game.mif Simple Memory Game MIF file + +Both generated from the hex file by HEX2MIF to 'program.mif', then I rename it to reflect its application + + + + + Index: trunk/asm/calc.mif =================================================================== --- trunk/asm/calc.mif (nonexistent) +++ trunk/asm/calc.mif (revision 18) @@ -0,0 +1,205 @@ +width = 16; +depth = 512; + +address_radix = hex; +data_radix = hex; + +content begin +[0..1ff]: 0; + +000000:c015; +000001:c001; +000002:c005; +000003:2722; +000004:2733; +000005:2788; +000006:bb38; +000007:9518; +000008:b71f; +000009:95a3; +00000a:31a8; +00000b:f449; +00000c:27aa; +00000d:31b0; +00000e:f409; +00000f:e0b1; +000010:95b0; +000011:bbb5; +000012:95b0; +000013:0fbb; +000014:bf1f; +000015:9518; +000016:2722; +000017:2733; +000018:2788; +000019:e093; +00001a:e0b1; +00001b:ef10; +00001c:bb11; +00001d:ef1f; +00001e:bb17; +00001f:bb14; +000020:bb15; +000021:bb12; +000022:bf1b; +000023:bf19; +000024:e015; +000025:bf13; +000026:d052; +000027:9478; +000028:d04c; +000029:9a96; +00002a:9894; +00002b:e6e0; +00002c:b300; +00002d:700f; +00002e:300f; +00002f:f479; +000030:9a94; +000031:9895; +000032:e6e1; +000033:b300; +000034:700f; +000035:300f; +000036:f441; +000037:9a95; +000038:9896; +000039:e6e2; +00003a:b300; +00003b:700f; +00003c:300f; +00003d:f409; +00003e:cfe9; +00003f:d035; +000040:b310; +000041:701f; +000042:1301; +000043:cfe4; +000044:ff01; +000045:5fed; +000046:ff02; +000047:5fea; +000048:ff03; +000049:5fe7; +00004a:8100; +00004b:300a; +00004c:f039; +00004d:300b; +00004e:f039; +00004f:9522; +000050:7f20; +000051:0f20; +000052:bb28; +000053:c010; +000054:7f8e; +000055:c001; +000056:6081; +000057:9582; +000058:fd80; +000059:c005; +00005a:d046; +00005b:bb38; +00005c:d00e; +00005d:2722; +00005e:c005; +00005f:d054; +000060:bb38; +000061:d009; +000062:2722; +000063:c000; +000064:d010; +000065:b300; +000066:700f; +000067:e01f; +000068:1301; +000069:cffa; +00006a:cfbd; +00006b:ff20; +00006c:9508; +00006d:94f8; +00006e:9a8f; +00006f:9897; +000070:d022; +000071:9a97; +000072:988f; +000073:9478; +000074:9508; +000075:2711; +000076:951a; +000077:f7f1; +000078:9508; +000079:e6e0; +00007a:e011; +00007b:9311; +00007c:e012; +00007d:9311; +00007e:e013; +00007f:9311; +000080:e014; +000081:9311; +000082:e015; +000083:9311; +000084:e016; +000085:9311; +000086:e017; +000087:9311; +000088:e018; +000089:9311; +00008a:e019; +00008b:9311; +00008c:e01b; +00008d:9311; +00008e:e010; +00008f:9311; +000090:e01a; +000091:9311; +000092:9508; +000093:e6ec; +000094:8110; +000095:951a; +000096:8310; +000097:f7d9; +000098:e6ed; +000099:8110; +00009a:951a; +00009b:8310; +00009c:f7b1; +00009d:959a; +00009e:f7a1; +00009f:e093; +0000a0:9508; +0000a1:e006; +0000a2:0f32; +0000a3:2722; +0000a4:f408; +0000a5:e021; +0000a6:f025; +0000a7:0f30; +0000a8:f01d; +0000a9:5036; +0000aa:c001; +0000ab:0f30; +0000ac:9502; +0000ad:0f30; +0000ae:f018; +0000af:ff20; +0000b0:5630; +0000b1:9508; +0000b2:e021; +0000b3:9508; +0000b4:1b32; +0000b5:2722; +0000b6:f408; +0000b7:e021; +0000b8:f40d; +0000b9:5036; +0000ba:ff20; +0000bb:9508; +0000bc:5630; +0000bd:e021; +0000be:f408; +0000bf:e021; +0000c0:9508; + + +end; \ No newline at end of file Index: trunk/asm/game.hex =================================================================== --- trunk/asm/game.hex (nonexistent) +++ trunk/asm/game.hex (revision 18) @@ -0,0 +1,153 @@ +000000:c002 +000001:9518 +000002:9518 +000003:e045 +000004:ef0f +000005:bb07 +000006:bb01 +000007:bb05 +000008:bb02 +000009:e001 +00000a:bf03 +00000b:e00f +00000c:bb04 +00000d:e063 +00000e:e071 +00000f:94e8 +000010:d04f +000011:d015 +000012:bb78 +000013:d047 +000014:d070 +000015:d02c +000016:d037 +000017:f026 +000018:d01a +000019:9573 +00001a:bb78 +00001b:cff8 +00001c:d010 +00001d:d067 +00001e:956a +00001f:d007 +000020:bb78 +000021:d063 +000022:3060 +000023:f349 +000024:d012 +000025:94e8 +000026:cfef +000027:2f06 +000028:6f00 +000029:bb08 +00002a:d05a +00002b:d059 +00002c:9508 +00002d:2700 +00002e:bb05 +00002f:d055 +000030:ef0f +000031:bb05 +000032:9508 +000033:9897 +000034:d050 +000035:9a97 +000036:9508 +000037:d033 +000038:9101 +000039:bb05 +00003a:d04a +00003b:ef0f +00003c:bb05 +00003d:e041 +00003e:d046 +00003f:951a +000040:f7b9 +000041:9508 +000042:d028 +000043:d02a +000044:9321 +000045:bb25 +000046:d03e +000047:ef0f +000048:bb05 +000049:e041 +00004a:d03a +00004b:951a +00004c:f7b1 +00004d:9508 +00004e:d01c +00004f:d00b +000050:9478 +000051:d00e +000052:94f8 +000053:9101 +000054:1320 +000055:9468 +000056:d004 +000057:d03d +000058:951a +000059:f7a9 +00005a:9508 +00005b:b303 +00005c:7f00 +00005d:3f00 +00005e:f7e1 +00005f:9508 +000060:b323 +000061:7f20 +000062:3f20 +000063:f3e1 +000064:d030 +000065:b303 +000066:7f00 +000067:1702 +000068:f7b9 +000069:9522 +00006a:9508 +00006b:2f17 +00006c:e6e2 +00006d:9508 +00006e:b722 +00006f:3024 +000070:f010 +000071:5024 +000072:cffc +000073:3020 +000074:f411 +000075:e02e +000076:c009 +000077:3021 +000078:f411 +000079:e02d +00007a:c005 +00007b:3022 +00007c:f411 +00007d:e02b +00007e:c001 +00007f:e027 +000080:b702 +000081:9507 +000082:9507 +000083:bf02 +000084:9508 +000085:2f3e +000086:e6e0 +000087:8100 +000088:950a +000089:8300 +00008a:f7d9 +00008b:e6e1 +00008c:8100 +00008d:950a +00008e:8300 +00008f:f7b1 +000090:954a +000091:f7a1 +000092:e045 +000093:2fe3 +000094:9508 +000095:2700 +000096:950a +000097:f7f1 +000098:9508 Index: trunk/asm/riscmcu.aio =================================================================== Cannot display: file marked as a binary type. svn:mime-type = application/octet-stream Index: trunk/asm/riscmcu.aio =================================================================== --- trunk/asm/riscmcu.aio (nonexistent) +++ trunk/asm/riscmcu.aio (revision 18)
trunk/asm/riscmcu.aio Property changes : Added: svn:mime-type ## -0,0 +1 ## +application/octet-stream \ No newline at end of property Index: trunk/asm/riscmcu.inc =================================================================== --- trunk/asm/riscmcu.inc (nonexistent) +++ trunk/asm/riscmcu.inc (revision 18) @@ -0,0 +1,39 @@ + +;***** I/O Register Definitions + +.equ SREG =$3f +.equ GIMSK =$3b +.equ TIMSK =$39 +.equ TIFR =$38 +.equ MCUCR =$35 +.equ TCCR0 =$33 +.equ TCNT0 =$32 + +.equ PORTB =$18 +.equ DDRB =$17 +.equ PINB =$16 +.equ PORTC =$15 +.equ DDRC =$14 +.equ PINC =$13 +.equ PORTD =$12 +.equ DDRD =$11 +.equ PIND =$10 + + +;***** Bit Definitions + +.equ INT0 =6 + +.equ TOIE0 =1 + +.equ TOV0 =1 + +.equ ISC01 =1 +.equ ISC00 =0 + +.equ CS02 =2 +.equ CS01 =1 +.equ CS00 =0 + +.def ZP =r30 +

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.