URL
https://opencores.org/ocsvn/rtf65002/rtf65002/trunk
Subversion Repositories rtf65002
[/] [rtf65002/] [trunk/] [software/] [asm/] [t65C.asm] - Rev 4
Compare with Previous | Blame | View Log
;==================================================================; (C) 2003 Bird Computer; All rights reserved.;; W65C02 Processor Test Routine;; The basic format is to test the things needed for further; testing first, like branches and compare, then move onto other; instructions.;==================================================================UART equ $CF00XMIT_FUL equ $08 ; the transmit buffer is fulldata_ptr equ $08dpf equ $AAorg $0FFFFE000cpu rtf65002; If the program gets here then we know at least the boot strap; worked okay, which is in itself a good test of processor health.startseicld ; set decimal mode flag to zeroldx #$1000txstrs r0,dp ; set zero page locationemm ; emulation modecpu W65C02seildx #$FFtxsjsr putmsgdb "C02 Testing Processor", 13, 10, 0;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; First thing to test is branches. If you can't branch reliably; then the validity of the remaining tests are in question.; Test branches and also simultaneously some other simple; instructions.;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -seibra braokjsr putmsgdb "BRA:F", 13, 10, 0braoksecbcs bcsokjsr putmsgdb "BCS:F", 13, 10, 0bcsokclcbcc bccokjsr putmsgdb "BCC:F", 13, 10, 0bccoklda #$00beq beqokjsr putmsgdb "BEQ:F", 13, 10, 0beqoklda #$80bne bneokjsr putmsgdb "BNE:F", 13, 10, 0bneokora #$00bmi bmiokjsr putmsgdb "BMI:F", 13, 10, 0bmiokeor #$80bpl bplokjsr putmsgdb "BPL:F", 13, 10, 0bploklda #$7fclcadc #$10 ; should give signed overflowbvs bvsokjsr putmsgdb "BVS:F", 13, 10, 0bvsokclvbvc bvcokjsr putmsgdb "BVC:F", 13, 10, 0bvcok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Compare Instructions;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -jsr putmsgdb "test cmp/cpx/cpy", 13, 10, 0lda #27 ; bit 7 = 0clccmp #27bcc cmperrbne cmperrbmi cmperrlda #$A1cmp #20bpl cmperr ; should be neg.seclda #10cmp #20 ; should be a borrow herebcs cmperrclvlda #$80 ; -128 - 32 = -160 should overflowcmp #$20 ; compare doesn't affect overflowbvs cmperrbvc cmpokcmperrjsr putmsgdb "CMP:F", 13, 10, 0cmpokldx #27clccpx #27bcc cpxerrbne cpxerrbmi cpxerrldx #$A1cpx #20bpl cpxerrldx #10cpx #20 ; should be a borrow herebcs cpxerrclvldx #$80 ; -128 - 32 = -160 should overflowcpx #$20 ; but cpx shouldn't change overflowbvs cpxerrbvc cpxokcpxerrjsr putmsgdb "CPX:F", 13, 10, 0cpxokldy #27clccpy #27bcc cpyerrbne cpyerrbmi cpyerrldy #$B0cpy #20bpl cpyerrldy #10cpy #20 ; should be a borrow herebcs cpyerrclvldy #$80 ; -128 - 32 = -160 should overflowcpy #$20 ; but cpy shouldn't change overflowbvs cpyerrbvc cpyokcpyerrjsr putmsgdb "CPY:F", 13, 10, 0cpyok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Accumulator ops;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -jsr putmsgdb "Test Acc ops", 13, 10, 0clvclclda #0ora #0bne oraerrbvs oraerrbmi oraerrbcs oraerrsecora #0bcc oraerrora #$55beq oraerrcmp #$55bne oraerrora #$aacmp #$ffbne oraerrbeq oraokoraerrjsr putmsgdb "ORA:F", 13, 10, 0oraoklda #27 ; bit 7 = 0secsbc #27bcc sbcerr1bne sbcerr3bmi sbcerr2bvs sbcerr4lda #$A1sbc #$20bpl sbcerr2 ; should be neg.cmp #$81bne sbcerr3seclda #10sbc #20 ; should be a borrow herebcs sbcerr1clvlda #$80 ; -128 - 32 = -160 should overflowsbc #$20 ;bvc sbcerr4bvs sbcoksbcerrjsr putmsgdb "SBC:F", 13, 10, 0jmp sbcoksbcerr1jsr putmsgdb "SBC:C", 13, 10, 0jmp sbcoksbcerr2jsr putmsgdb "SBC2:N", 13, 10, 0jmp sbcoksbcerr3jsr putmsgdb "SBC3:Z", 13, 10, 0jmp sbcoksbcerr4jsr putmsgdb "SBC:V", 13, 10, 0jmp sbcoksbcok; bitclvlda #$ffbit n55bvc biterrbmi biterrbit nAAbvs biterrbpl biterrlda #$00sta data_ptrlda #$ffbit data_ptrbne biterrbeq bitokbiterrjsr putmsgdb "BIT:F", 13, 10, 0bitoklda #$ffphaplpbpl plperrbvc plperrbne plperrbcc plperrbcs plpokplperrjsr putmsgdb "PLP:F", 13, 10, 0plpokcldclcclvseilda #$00 ; p = 00xx0100phpplaror a ; C ?jsr psrror a ; Z ?jsr psrror ajsr psrror ajsr psrror a ; B?jsr psrror a ; x?jsr psrror ajsr psrror ajsr psrjmp phpokpsrphabcc psr1jsr putmsgdb "1", 0plartspsr1jsr putmsgdb "0", 0plartsphperrjsr putmsgdb "PHP:F", 13, 10, 0jmp phpokphperr1jsr putmsgdb "PHP:1F", 13, 10, 0jmp phpokphperr2jsr putmsgdb "PHP:2F", 13, 10, 0jmp phpokphperr3jsr putmsgdb "PHP:3F", 13, 10, 0jmp phpokphperr4jsr putmsgdb "PHP:4F", 13, 10, 0jmp phpokphperr5jsr putmsgdb "PHP:5F", 13, 10, 0jmp phpokphperr6jsr putmsgdb "PHP:6F", 13, 10, 0jmp phpokphpok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Load;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -jsr putmsgdb "Test lda/ldx/ldy", 13, 10, 0; ldaclclda #0bne ldaerrbmi ldaerrbcs ldaerrlda #$80beq ldaerrbpl ldaerrlda #$00sta $800bne ldaerrbmi ldaerrbcs ldaerrlda #$fflda $800bne ldaerrbmi ldaerrbcs ldaerrcmp #0bne ldaerrseclda #$ffsta $800beq ldaerrbpl ldaerrbcc ldaerrlda #0lda $800beq ldaerrbpl ldaerrbcc ldaerrcmp #$ffbeq ldaokldaerrjsr putmsgdb "LDA:F", 13, 10, 0ldaok; ldxclclda #$80 ; z = 0, n = 1ldx #0bcs ldxerrbne ldxerrbmi ldxerrstx $800bne ldxerrbmi ldxerrbcs ldxerrldx #$ffldx $800bne ldxerrbmi ldxerrbcs ldxerrcpx #0bne ldxerrsecldx #$ffstx $800beq ldxerrbpl ldxerrbcc ldxerrldx #0ldx $800beq ldxerrbpl ldxerrbcc ldxerrcpx #$ffbeq ldxokldxerrjsr putmsgdb "LDX:F", 13, 10, 0; ldyldxokclclda #$80 ; z = 0, n = 1ldy #0bcs ldyerrbne ldyerrbmi ldyerrsty $800bne ldyerrbmi ldyerrbcs ldyerrldy #$ffldy $800bne ldyerrbmi ldyerrbcs ldyerrcpy #0bne ldyerrsecldy #$ffsty $800beq ldyerrbpl ldyerrbcc ldyerrldy #0ldy $800beq ldyerrbpl ldyerrbcc ldyerrcpy #$ffbeq ldyokldyerrjsr putmsgdb "LDY:F", 13, 10, 0ldyok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Test register transfers;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -jsr putmsgdb "Test tax/tay/txa/tya/tsx/txs", 13, 10, 0; taxclclda #0ldx #$80 ; z = 0, n = 1taxbcs taxerrbmi taxerrbne taxerrtxabne taxerrlda #$ffsecldx #0taxbcc taxerrbpl taxerrbeq taxerrtxacmp #$ffbeq taxoktaxerrjsr putmsgdb "TAX:F", 13, 10, 0taxok; tayclclda #0ldy #$80 ; z = 0, n = 1taybcs tayerrbmi tayerrbne tayerrtyabne tayerrlda #$ffsecldy #0taybcc tayerrbpl tayerrbeq tayerrtyacmp #$ffbeq tayoktayerrjsr putmsgdb "TAY:F", 13, 10, 0tayok; txsldx #15txsldx #87tsxcpx #15beq txsokldx #$fftxsjsr putmsgdb "TSX:F", 13, 10, 0txsokldx #87txacmp #87beq txaokjsr putmsgdb "TXA:F", 13, 10, 0txaoktaycpy #87beq tayok1jsr putmsgdb "TAY:F", 13, 10, 0tayok1tyabeq tyaerrbmi tyaerrcmp #87beq tyaoktyaerrjsr putmsgdb "TYA:F", 13, 10, 0tyaok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Increment / Decrement;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -jsr putmsgdb "Test inx/dex/iny/dey/ina/dea/inc/dec", 13, 10, 0ldx #$FEclclda #0inxbcs inxerrbeq inxerrbpl inxerrcpx #$ffbne inxerrseclda #$80inxbcc inxerrbne inxerrbmi inxerrcpx #0bne inxerrclcinxl1 ; test loopinxbcs inxerrbne inxl1secinxl2inxbcc inxerrbne inxl2beq inxokinxerrjsr putmsgdb "INX:F", 13, 10, 0inxok; dexldx #2clclda #0dexbcs dexerrbeq dexerrbmi dexerrcpx #1bne dexerrseclda #$80dexbcc dexerrbne dexerrbmi dexerrcpx #0bne dexerrlda #0dexbeq dexerrbpl dexerrcpx #$ffbne dexerrclcdexl1dexbcs dexerrbne dexl1secdexl2dexbcc dexerrbne dexl2beq dexokdexerrjsr putmsgdb "DEX:F", 13, 10, 0dexok; inyldy #$FEclcadc #0inybcs inyerrbeq inyerrbpl inyerrcpy #$ffbne inyerrseclda #$80inybcc inyerrbne inyerrbmi inyerrcpy #0bne inyerrclcinyl1 ; test loopinybcs inyerrbne inyl1secinyl2inybcc inyerrbne inyl2beq inyokinyerrjsr putmsgdb "INY:F", 13, 10, 0; deyinyokldy #2clclda #0deybcs deyerrbeq deyerrbmi deyerrcpy #1bne deyerrseclda #$80deybcc deyerrbne deyerrbmi deyerrcpy #0bne deyerrlda #0deybeq deyerrbpl deyerrcpy #$ffbne deyerrclcdeyl1deybcs deyerrbne deyl1secdeyl2deybcc deyerrbne deyl2beq deyokdeyerrjsr putmsgdb "DEY:F", 13, 10, 0deyoklda #1inacmp #2beq inaokjsr putmsgdb "INA:F", 13, 10, 0inaoklda #2deacmp #1beq deaokjsr putmsgdb "DEA:F", 13, 10, 0deaok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Stores;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -jsr putmsgdb "Test sta/stx/sty/stz", 13, 10, 0; stalda #0clcsta $00bne staerrbmi staerrbcs staerrlda $00bne staerrlda #$ffsecsta $00beq staerrbpl staerrbcc staerrbcs staokstaerrjsr putmsgdb "STA:F", 13, 10, 0staok; stxldx #0clcstx $00bne stxerrbmi stxerrbcs stxerrldx $00bne stxerrldx #$ffsecstx $00beq stxerrbpl stxerrbcc stxerrbcs stxokstxerrjsr putmsgdb "STX:F", 13, 10, 0stxok; styldy #0clcsty $00bne styerrbmi styerrbcs styerrldy $00bne styerrldy #$ffsecsty $00beq styerrbpl styerrbcc styerrbcs styokstyerrjsr putmsgdb "STY:F", 13, 10, 0styok; stzlda #$ffsta data_ptrstz data_ptrlda data_ptrbeq stzokjsr putmsgdb "STZ:F", 13, 10, 0stzok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Test addressing mode; Note that addressing modes are handled independently of the; actual operation performed by the processor. This means that; if a mode works with one instruction, it should work properly; with all instructions that use that mode.;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -jsr putmsgdb "Test amodes", 13, 10, 0lda #$AAeor #$55cmp #$ffbeq imm_okjsr putmsgdb "IMM:F", 13, 10, 0imm_oklda n55eor nAAclcadc #1beq abs_okjsr putmsgdb "ABS:F", 13, 10, 0abs_okldx #2lda n55,xcmp #12beq absx_okjsr putmsgdb "ABS,X:F", 13, 10, 0absx_okldy #3lda n55,ycmp #34beq absy_okjsr putmsgdb "ABS,Y:F", 13, 10, 0absy_oklda #33sta data_ptrldx #0ldx data_ptrcpx #33beq zp_okjsr putmsgdb "ZP:F", 13, 10, 0zp_oklda #44sta data_ptr+33lda data_ptr,xcmp #44beq zpx_okjsr putmsgdb "ZP,X:F", 13, 10, 0zpx_oklda #$12sta $201lda #$01sta data_ptrlda #$2sta data_ptr+1ldx #5lda (data_ptr-5,x)cmp #$12bne zpixerrlda #$33sta (data_ptr-5,x)lda #$00lda $201cmp #$33bne zpixerrbeq zpixokzpixerrjsr putmsgdb "(ZP,X):F", 13, 10, 0zpixoklda #$festa data_ptrlda #$01sta data_ptr+1ldy #3lda (data_ptr),ycmp #$33beq zpiy_okjsr putmsgdb "(ZP),y:F", 13, 10, 0zpiy_okldy #7ldx data_ptr-7,ycpx #$febeq zpy_okjsr putmsgdb "ZP,Y:F", 13, 10, 0zpy_ok; test (zp)lda #$34sta $201lda #$01sta data_ptrlda #$02sta data_ptr+1lda (data_ptr)cmp #$34beq zpiokjsr putmsgdb "(ZP):F", 13, 10, 0zpiok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -ldy #$ffinycpy #0beq iny_okjsr putmsgdb "INY:F", 13, 10, 0iny_okldy #10deycpy #9beq dey_okjsr putmsgdb "DEY:F", 13, 10, 0dey_okldx #$80inxcpx #$81beq inx_okjsr putmsgdb "INX:F", 13, 10, 0inx_okldx #$00dexcpx #$ffbeq dex_okjsr putmsgdb "DEX:F", 13, 10, 0dex_ok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -; Shift ops;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -jsr putmsgdb "Test asl/rol/lsr/ror", 13, 10, 0; asl alda #$01asl aasl aasl aasl aasl aasl aasl abpl aslaerrbeq aslaerrbcs aslaerrcmp #$80beq aslaokasl a ; check that carry is shifted outbcc aslaerrbcs aslaokaslaerrjsr putmsgdb "ASLA:F", 13, 10, 0aslaok; lsr alda #$80lsr alsr alsr alsr alsr alsr alsr abmi lsraerrbeq lsraerrbcs lsraerrbcc lsraoklsr abcc lsraerrbcs lsraoklsraerrjsr putmsgdb "LSRA:F", 13, 10, 0lsraok; rol aclclda #$01rol arol arol arol arol arol arol abpl rolaerrbeq rolaerrbcs rolaerrcmp #$80 ; this will set the carry !!!bne rolaerrclcrol abcc rolaerrbne rolaerrbmi rolaerrrol abcs rolaerrbmi rolaerrbeq rolaerrcmp #1beq rolaokrolaerrjsr putmsgdb "ROLA:F", 13, 10, 0jmp rolaokrolaok; ror aclclda #$80ror aror aror aror aror aror aror abmi roraerrbeq roraerrbcs roraerrcmp #$01 ; this will set the carry !!!bne roraerrclcror abcc roraerrbne roraerrbmi roraerrror abcs roraerrbpl roraerrbeq roraerrcmp #$80beq roraokbne roraerrroraerrjsr putmsgdb "RORA:F", 13, 10, 0roraok; ror mclclda #$80sta dpfror dpfror dpfror dpfror dpfror dpfror dpfror dpfbmi rormerrbeq rormerrbcs rormerrlda dpfcmp #$01 ; this will set the carry !!!bne rormerrclcror dpfbcc rormerrbne rormerrbmi rormerrror dpfbcs rormerrbpl rormerrbeq rormerrlda dpfcmp #$80bne rormerrjmp rormokrormerrjsr putmsgdb "RORM:F", 13, 10, 0jmp rormokrormok;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -jsr putmsgdb "Test psh/pul", 13, 10, 0; pha / plalda #$eephalda #00clcplabpl plaerrbeq plaerrbcs plaerrbcc plaokplaerrjsr putmsgdb "PLA:F", 13, 10, 0plaok; phx / plxldx #$eephxldx #00plxcpx #$eebeq plxokjsr putmsgdb "PLX:F", 13, 10, 0plxok; phy / plyldy #$eephyldy #00plycpy #$eebeq plyokjsr putmsgdb "PLY:F", 13, 10, 0plyok; jmp (a,x)jsr putmsgdb "test jmp(a,x)", 13, 10, 0lda #<jmpiaxokldx #>jmpiaxoksta $201stx $202ldx #20jmp ($201-20,x)jsr putmsgdb "JMP (a,x):F", 13, 10, 0jmpiaxokstpjmp ($FFFC) ; go back to reset;------------------------------------------------------------------; Kind of a chicken and egg problem here. If there is something; wrong with the processor, then this code likely won't execute.;; put message to screen; tests pla,sta,ldy,inc,bne,ora,jmp,jmp(abs)putmsgpla ; pop the return address off the stacksta data_ptr ; to use as a pointer to the dataplasta data_ptr+1pm2ldy #$01lda (data_ptr),yinc data_ptrbne pm3inc data_ptr+1pm3ora #0 ; end of string ?beq pm1jsr putSerjmp pm2pm1 ; must update the return address !inc data_ptrbne pm4inc data_ptr+1pm4jmp (data_ptr); put character to serial port; test and,bne,pha,pla,sta,lda,rtsputSerpha ; temporarily save characterps1lda UART+1 ; get serial port statusand #XMIT_FUL ; is it full ?bne ps1 ; If full then waitpla ; get back the char to writesta UART ; write it to the xmit registerrtsn55db $55nAAdb $AAdb 12db 34nmiroutrtialign 4n5555dw $55555555nAAAAdw $AAAAAAAAdw 12dw 34org $0FFFFFFF4 ; NMI vectordw nmiroutorg $0FFFFFFF8 ; reset vector, native modedw start
