6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 1:12 pm

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Oct 29, 2018 6:37 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
OK, I decided to put on hold my project of getting EhBASIC running on an LCD screen.

The good news is that my LCD screen still works as a "secondary" display and I built a simple 65C51 board and now I have serial working.

I know the 65C51 is a bad word around here. But it's all I had/have at the moment. I don't plan on sticking with it long term.

Anyway, I have it working and now I can enter BASIC programs. However, I have to press the ENTER key twice on everything.

For example, if I type "LIST" and press ENTER, I get a new line and that's all. Pressing it a second time actually executes the LIST.

Also, I have the following test program:

Code:
10 FOR A=1 to 10
20 PRINT A
30 NEXT A


This works. BUT...I have to press ENTER each iteration of A! It's like I have to "ENTER" each line of BASIC before it works as it's running.

Here is what I have running so far...any pointers is more than appreciated.

MON.ASM
Code:
        .debuginfo  +
        .setcpu     "65C02"

VIA     :=      $6000

PB      :=      VIA
PA      :=      VIA + 1
DDRB    :=      VIA + 2
DDRA    :=      VIA + 3

ESC     =       $1B             ; Escape character
CR      =       $0D             ; Return character
LF      =       $0A             ; Line feed character

IRQ_vec   =       VEC_SV + 2   ; IRQ code vector
NMI_vec   =       IRQ_vec + $0A   ; NMI code vector

.include "EhBASIC.asm"
.include "lcd.asm"
.include "pckybd.asm"
.include "acia.asm"
.include "utils.asm"

;-------------------------------------------------------------------------------
;       Main RESET Vector (ROM Startup)
;-------------------------------------------------------------------------------
        .segment "CODE"
        .org $8000

RES_vec:
   CLD            ; clear decimal mode
   LDX   #$FF         ; empty stack
   TXS            ; set the stack

        JSR     INITS


   LDY   #END_CODE - LAB_vec   ; set index/count
LAB_stlp:
   LDA   LAB_vec - 1, Y      ; get byte from interrupt code
   STA   VEC_IN - 1, Y      ; save to RAM
   DEY            ; decrement index/count
   BNE   LAB_stlp      ; loop if more to do

LAB_signon:
   LDA   LAB_mess, Y      ; get byte from sign on message
   BEQ   LAB_nokey      ; exit loop if done

   JSR   V_OUTP      ; output character
   INY            ; increment index
   BNE   LAB_signon      ; loop, branch always

LAB_nokey:
   JSR   V_INPT      ; call scan input device
   BCC   LAB_nokey      ; loop if no key

   AND   #$DF         ; mask xx0x xxxx, ensure upper case
   CMP   #'W'         ; compare with [W]arm start
   BEQ   LAB_dowarm      ; branch if [W]arm start

   CMP   #'C'         ; compare with [C]old start
   BNE   RES_vec      ; loop if not [C]old start

   JMP   LAB_COLD      ; do EhBASIC cold start

LAB_dowarm:
   JMP   LAB_WARM      ; do EhBASIC warm start


ACIAout:
        CMP     #LF                     ; Ignore line feed character
        BEQ     Ignore
WaitForReady:     
   BIT   RXDATA
   BMI     WaitForReady
        JSR     ECHO
Ignore:
   RTS

ACIAin:
        JSR     GetKey
        BEQ     LAB_nobyw
        AND   #$7F         ; clear high bit
        SEC            ; flag byte received
   RTS

LAB_nobyw
   CLC            ; flag no byte received
        RTS

LOAD:
SAVE:
        RTS


MAIN:

        JMP     MAIN


;-------------------------------------------------------------------------------
;       System Initializations
;-------------------------------------------------------------------------------
INITS:
;       Set on-board VIA data direction registers
        LDA     #$FF
        STA     DDRA            ; PORT A is all output
        STA     DDRB            ; PORT B is all output

        JSR     LCD_INIT        ; Initialize the LCD module

        LDX     #<LINE1         ; Print the 4 line startup message
        LDY     #>LINE1
        JSR     PrintString

        LDX     #<LINE3
        LDY     #>LINE3
        JSR     PrintString

        LDA     #$40
        JSR     LCD_SET_DRAM_ADDRESS

        LDX     #<LINE2
        LDY     #>LINE2
        JSR     PrintString

        LDX     #<LINE4
        LDY     #>LINE4
        JSR     PrintString

;        JSR     kbinit          ; Initialize the keyboard

        JSR     INIT_ACIA

        RTS




;-------------------------------------------------------------------------------
;       PRINT CHAR TO LCD FROM KEYBOARD INPUT
;-------------------------------------------------------------------------------
DISPout:
        STA     PA
        JSR     LCD_WRITE
   RTS



;-------------------------------------------------------------------------------
; Print a string
;-------------------------------------------------------------------------------
; Pass address of string in X (low) and Y (high).
; String must be terminated with a null.
; Cannot be longer than 256 characters.
; Registers changed: A, Y
;-------------------------------------------------------------------------------
PrintString:
        STX     LCDpl
        STY     LCDpl + 1
        LDY     #0
@loop:  LDA     (LCDpl), Y
        BEQ     done
        JSR     DISPout
        INY
        BNE     @loop       ; if doesn't branch, string is too long
done:   RTS


;-------------------------------------------------------------------------------
;       Sends A to LCD screen at current cursor position
;-------------------------------------------------------------------------------
WriteLCD:
        STA     PA
        JSR     LCD_WRITE
        RTS

LAB_vec
   .word   ACIAin      ; byte in from simulated ACIA
   .word   ACIAout      ; byte out to simulated ACIA
   .word   LOAD      ; load vector for EhBASIC
   .word   SAVE      ; save vector for EhBASI
END_CODE

;-------------------------------------------------------------------------------
;       MESSAGES
;-------------------------------------------------------------------------------
LAB_mess
   .byte   $0D,$0A,"6502 EhBASIC [C]old/[W]arm ?", $00
LINE1:
        .byte "********************", $00
LINE2:
        .byte "   Potpourri6502    ", $00
LINE3:
        .byte "                    ", $00
LINE4:
        .byte "********************", $00

;NMI_vec:
;IRQ_vec:
;        RTS


;-------------------------------------------------------------------------------
;       Startup Vectors
;-------------------------------------------------------------------------------
.segment "VECTORS"
        .word NMI_vec           ; NMI Vector
        .word RES_vec           ; RESET Vector
        .word IRQ_vec           ; IRQ Vector

;-------------------------------------------------------------------------------
;       EOF
;-------------------------------------------------------------------------------


ACIA.ASM
Code:

.segment "SERIAL"

MSGL            = $ED
MSGH            = $EE


ACIA            := $5800
ACIA_CTRL       := ACIA + 3
ACIA_CMD        := ACIA + 2
ACIA_SR         := ACIA + 1
ACIA_DAT        := ACIA
TXDATA          := ACIA
RXDATA          := ACIA

INIT_ACIA:
        CLD                     ; Clear decimal arithmetic mode.
        CLI

        PHA                     ; Push A to stack

        LDA     #$1F            ; ACIA to 19200 Baud.
        STA     ACIA_CTRL
        LDA     #$0B            ; No Parity.
        STA     ACIA_CMD

        LDA     #$0D
        JSR     ECHO            ; New line.

        LDA     #<MSG1          ; Setup and print welcome message
        STA     MSGL
        LDA     #>MSG1
        STA     MSGH
        JSR     SHWMSG          ; Show Welcome.

        LDA     #$0D
        JSR     ECHO            ; New line.

        PLA                     ; Restore A

        RTS

ECHO:
        PHA         ;*Save A
        AND     #$7F            ;*Change to "standard ASCII"
        STA     ACIA_DAT        ;*Send it.
        JSR     DELAY1
        PLA                     ; Restore A
        RTS

; Read character from serial port and return in A
GetKey:
        LDA     #$08
RXFULL: BIT     ACIA_SR
        BEQ     RXFULL
        LDA     RXDATA
        AND     #%01111111
        RTS

SHWMSG:
        LDY #0
@PRINT:
        LDA (MSGL), Y
        BEQ @DONE
        JSR ECHO
        INY
        BNE @PRINT
@DONE
        RTS


MSG1:
        .byte "Welcome to Potpourri6502...", 0

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2018 7:59 pm 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1007
Location: Canada
Your GetKey routine stalls until it gets a character. As was mentioned earlier in another thread, this is not going to make EhBASIC very happy.

TRy something like this:
Code:
RDCHR   lda ACIA_SR      ; Read the ACAI status to
         and #$08         ; Check if there is character in the receiver
         beq NOCHAR      ; Exit now if we don't get one.
         lda RXDATA      ; Load it into the accumulator
       sec            ; Set Carry to show we got a character
       rts            ; Return
NOCHAR
       clc            ; Clear Carry (no char)
       rts


This will replace both your getkey and you ACIAin routines.

_________________
Bill


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2018 8:09 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
As noted... you need a character get routine that doesn't wait for a key to be pressed. Which 65C51 are you using?? If you have an older 6551/65C51 (sans the latest WDC version), you can get a copy of my 6551/6522 BIOS which will give you a clean set of interrupt-driven I/O routines which work fine with EhBasic, if you would like to try them.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2018 8:18 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
BillO wrote:
Your GetKey routine stalls until it gets a character. As was mentioned earlier in another thread, this is not going to make EhBASIC very happy.

TRy something like this:
Code:
RDCHR   lda ACIA_SR      ; Read the ACAI status to
         and #$08         ; Check if there is character in the receiver
         beq NOCHAR      ; Exit now if we don't get one.
         lda RXDATA      ; Load it into the accumulator
       sec            ; Set Carry to show we got a character
       rts            ; Return
NOCHAR
       clc            ; Clear Carry (no char)
       rts


This will replace both your getkey and you ACIAin routines.


That worked!! And it makes sense now. I guess I didn't (and perhaps still don't) totally understand how EhBASIC is wired into things.

Thanks again!

floobydust wrote:
As noted... you need a character get routine that doesn't wait for a key to be pressed. Which 65C51 are you using?? If you have an older 6551/65C51 (sans the latest WDC version), you can get a copy of my 6551/6522 BIOS which will give you a clean set of interrupt-driven I/O routines which work fine with EhBasic, if you would like to try them.


I think I'm using the "bad" one. W65C51N6TPG-14 (A6A749-1).

Yes, I'd love to take a look at your BIOS and study how it works. I've never taken on a 6502 project this large before so knowing how these pieces all fit together would really help.

Thanks again guys for the help.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2018 8:43 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
cbmeeks wrote:
BillO wrote:
Your GetKey routine stalls until it gets a character. As was mentioned earlier in another thread, this is not going to make EhBASIC very happy.

TRy something like this:
Code:
RDCHR   lda ACIA_SR      ; Read the ACAI status to
         and #$08         ; Check if there is character in the receiver
         beq NOCHAR      ; Exit now if we don't get one.
         lda RXDATA      ; Load it into the accumulator
       sec            ; Set Carry to show we got a character
       rts            ; Return
NOCHAR
       clc            ; Clear Carry (no char)
       rts


This will replace both your getkey and you ACIAin routines.


That worked!! And it makes sense now. I guess I didn't (and perhaps still don't) totally understand how EhBASIC is wired into things.

Thanks again!

floobydust wrote:
As noted... you need a character get routine that doesn't wait for a key to be pressed. Which 65C51 are you using?? If you have an older 6551/65C51 (sans the latest WDC version), you can get a copy of my 6551/6522 BIOS which will give you a clean set of interrupt-driven I/O routines which work fine with EhBasic, if you would like to try them.


I think I'm using the "bad" one. W65C51N6TPG-14 (A6A749-1).

Yes, I'd love to take a look at your BIOS and study how it works. I've never taken on a 6502 project this large before so knowing how these pieces all fit together would really help.

Thanks again guys for the help.


Sure.... attached a source file that contains the Monitor and BIOS. BIOS supports any working 65C51 for interrupt-driven and buffered I/O using a pair of 128-byte circular buffers. It also supports a 65C22 VIA with timer1 used for a RTC and timer2 used for accurate delays, plus basic port I/O. The monitor contains a host of useful commands plus a 65C02 disassembler and will invoke the EhBasic based on the source file I appended to your previous thread. Just change your I/O address locations, Timer counter values (based on the CPU clock rate chart contained in the source) and you'll have a working system that can be used as a test to ensure your hardware is working as it should. Good luck... any questions on the source code, just ask.

Note that the BIOS starts on line 2336 and is quite small overall.



Oops... my bad! Forgot to add one line of code to the Monitor... EhBasic won't launch from the Monitor without it. It's a ".DW MSG_2F" directive for the message that announces EhBasic (line 2185). Updated version replaced the old one... sorry 'bout that.

Attachment:
C02Monitor.asm [121.16 KiB]
Downloaded 231 times

_________________
Regards, KM
https://github.com/floobydust


Last edited by floobydust on Sun Nov 04, 2018 3:14 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Mon Oct 29, 2018 9:06 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1250
Location: Soddy-Daisy, TN USA
Thanks!!

I will certainly check that out.

_________________
Cat; the other white meat.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 24 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: