6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 11:12 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: What am I doing wrong?
PostPosted: Sat May 29, 2010 2:02 am 
Offline

Joined: Mon Apr 12, 2010 8:03 pm
Posts: 1
Hi everyone, I'm relatively new to assembly coding in general, and as a little exercise, I wanted to port the brainf*** language to the 6502 (on the apple 1)

This is the first module of the code, assembles with KRUSADER.
What it's supposed to do is pull an ascii byte off the keyboard, store it in the first buffer, then check to see if it's one of the 8 commands. If so, it also stores it in the second buffer. I don't understand, but it's not working right at all. do I have to have BNE instructions for every CMP?

Code:
000 KBD    .=  $D010
001 BUFF   .=  $300
002 ECHO   .=  $FFEF
003 KBDRDY .=  $D011
004 BUFF2  .=  $400
005 START  .M  $500
006        LDY #$00
007        LDX #$00
008        CLD
009 GET    LDA KBDRDY
00A        BPL GET
00B        LDA KBD
00C        JSR ECHO
00D        STA BUFF,X
00E        INX
00F COMP   CMP #$3E
010        BEQ STR
011        CMP #$3C
012        BEQ STR
013        CMP #$2B
014        BEQ STR
015        CMP #$2D
016        BEQ STR
017        CMP #$2E
018        BEQ STR
019        CMP #$2C
01A        BEQ STR
01B        CMP #$5B
01C        BEQ STR
01D        CMP #$5D
01E        BEQ STR
01F        CMP #$1B
020        BEQ PARSE
021        JMP GET
022 STR    STA BUFF2,Y
023        JMP GET
024 PARSE  JMP $FF1F


FFIF is the re entry point of the monitor.

Thanks for the help!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Sat May 29, 2010 4:17 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
After line 22, you need to increment the Y register (INY).

Daryl


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jun 01, 2010 4:34 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8514
Location: Midwestern USA
8BIT wrote:
After line 22, you need to increment the Y register (INY).

Daryl


Correct. Also, does the ECHO subroutine preserve the registers?

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Jun 02, 2010 5:10 pm 
Offline

Joined: Fri Jun 27, 2003 8:12 am
Posts: 618
Location: Meadowbrook
Might be more feasible to rewrite into a checking loop that checks against a data table instead of doing individual compare and branches.

1. makes the code smaller.
2. If your table gets larger, you run up against the 128 byte max jump on the BEQ command, forcing you to use a jump table (I found that out on my pinball program)
3. You can add more commands to the table and change the end size much more easily than keeping on adding code.


Code:

CommandTable
    .DB $aa, $bb, $cc, $dd, $ee, $ff, $00 (end byte is zero marker)
TablePointer = #$00
     ldy TablePointer

LOOP
     jsr   GetKey     ; returns key in KeyPressed memloc)
     lda   CommandTable, TablePointer
     cmp KeyPressed
     beq ThisIsACommand
     cmp #$00        ; end of table?
     beq NoCommandfound
     iny
     jmp LOOP



and this will leave the command in the KeyPressed and Accumulator locations.

_________________
"My biggest dream in life? Building black plywood Habitrails"


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yuri and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: