6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Apr 27, 2024 10:10 am

All times are UTC




Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Wed Oct 24, 2018 3:15 am 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1207
Location: Soddy-Daisy, TN USA
So I have EhBASIC 2.22 running. I'm at the point where it asks for [W] or [C] start. I press C and I then get asked for memory size.

No matter what I enter, it jumps back to the same "Memory size ? " prompt. I've done some research and I've changed IBuffs, RAM_Base, etc.

For example, I tried this to no avail:
Code:
Ibuffs      = $0401   ; start of input buffer after IRQ/NMI code
Ibuffe      = Ibuffs + $47; end of input buffer

Ram_base   = $0600   ; start of user RAM (set as needed, should be page aligned)
Ram_top      = $4000   ; end of user RAM+1 (set as needed, should be page aligned)


My system has 16K of RAM and 32K of ROM.

My ld65 config file is:

Code:
MEMORY {
   ZP:         start = $0000, size = $0100, type = rw;
   RAM:      start = $0000, size = $4000, fill = no, type = rw;

   ROM:      start = $8000, size = $3000, fill = yes;
   EhBASIC:   start = $B000, size = $3000, fill = yes;
   LCD:      start = $E000, size = $0C00, fill = yes;
   KEYB:      start = $EC00, size = $0400, fill = yes;
   UTILS:      start = $F000, size = $0FFA, fill = yes;
   VEC:      start = $FFFA, size = $0006, fill = yes;
}

SEGMENTS {
   ZEROPAGE:   load = ZP, type = zp;
   CODE:      load = ROM,   type = ro;
   BASIC:      load = EhBASIC, type = ro;
   LCD:      load = LCD, type = ro;
   KEYBOARD:   load = KEYB, type = ro;
   UTILS:      load = UTILS, type = ro;
   VECTORS:   load = VEC, type = ro;
}


My current mon.asm is:

Code:
       .debuginfo  +
        .setcpu     "65C02"

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

VIA     :=      $6000
VIA2    :=      $5800

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

PB2     :=      VIA2
PA2     :=      VIA2 + 1
DDRB2   :=      VIA2 + 2
DDRA2   :=      VIA2 + 3


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

IN      =       $0200           ; Buffer used by GetLine.
                                ; From $0200 through $027F (shared with Woz Mon)
                                ; Defined in wozmon.asm

LCDpl   =       $DE      ; temporary integer low byte
LCDPh   =       LCDpl + 1   ; temporary integer high byte


.include "EhBASIC.asm"
.include "lcd.asm"
.include "pckybd.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


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


;-------------------------------------------------------------------------------
;       Setup EhBASIC
;-------------------------------------------------------------------------------
        ; set up vectors and interrupt code, copy them to page 2
   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

; now do the signon message, Y = $00 here
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





;-------------------------------------------------------------------------------
;       PRINT CHAR TO LCD FROM KEYBOARD INPUT
;-------------------------------------------------------------------------------
DISPout:
        CMP     #LF                     ; Ignore line feed character
        BEQ     Ignore
WaitForReady:   ;; Originally, waits for BIT $D012 on Replica One.
                ;; In a perfect world, we should wait on LCD status of ready.
                ;; Ignore for now
        ;; DRAW CHAR TO LCD SCREEN
        JSR     WriteLCD
Ignore:
   RTS


;-------------------------------------------------------------------------------
;       GET KEYBOARD INPUT
;-------------------------------------------------------------------------------
KEYBin:
        ;; GET KEYBOARD CHAR
        JSR     kbinput                 ; Waits for ASCII key press.
                                        ; A should now have ASCII character
                                        ; (waits for a non-zero ASCII code)
        BEQ   LAB_nobyw      ; branch if no byte waiting
   SEC            ; flag byte received
   RTS

LAB_nobyw:
   CLC            ; flag no byte received
;-------------------------------------------------------------------------------
        ;; LOAD / SAVE ROUTINES
;-------------------------------------------------------------------------------
LOAD:
SAVE:
        ;; IGNORE FOR NOW
        RTS



        JMP     MAIN

;-------------------------------------------------------------------------------
; 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


;-------------------------------------------------------------------------------
;       GETLINE
;-------------------------------------------------------------------------------
;       NOTE: This was used in the min_mon for file loading/saving.
;       At this time, I'm not sure where this should be used (if at all).
;       Having the current LINE entered is certainly important.
;       TODO: Figure out where to use this! 
;             Perhaps when asking user a question?
;-------------------------------------------------------------------------------
GetLine:
        LDX  #0                 ; Initialize index into buffer
loop:
        JSR  KEYBin      ; Get character from keyboard
        BCC  loop
        CMP  #CR                ; <Enter> key pressed?
        BEQ  EnterPressed       ; If so, handle it
        CMP  #ESC               ; <Esc> key pressed?
        BEQ  EscapePressed      ; If so, handle it
        JSR  DISPout            ; Echo the key pressed
        STA  IN+1, X            ; Store character in buffer
                                ;       (skip first length byte)
        INX                     ; Advance index into buffer
        CPX  #$7E               ; Buffer full?
        BEQ  EnterPressed       ; If so, return as if <Enter> was pressed
        BNE  loop               ; Always taken
EnterPressed:
        CLC                     ; Clear carry to indicate
                                ;       <Enter> pressed and fall through
EscapePressed:
        LDA  #0
        STA  IN+1, X            ; Store 0 at end of buffer
        STX  IN                 ; Store length of string
        RTS                     ; Return


;-------------------------------------------------------------------------------
;       VECTOR TABLES
;-------------------------------------------------------------------------------
LAB_vec:
   .word   KEYBin      ; byte in from simulated ACIA
   .word   DISPout      ; byte out to simulated ACIA
   .word   LOAD      ; load vector for EhBASIC
   .word   SAVE      ; save vector for EhBASIC
END_CODE:


;-------------------------------------------------------------------------------
;       MESSAGES
;-------------------------------------------------------------------------------
LAB_mess:
   .byte   $0D, $0A, "EhBASIC[C]old/[W]arm", $00
                        ; sign on string
LINE1:
        .byte "*  Potpourri 6502  *", $00
LINE2:
        .byte "EhBASIC:            ", $00
LINE3:
        .byte "[C]old / [W]arm?    ", $00
LINE4:
        .byte "Enter your choice...", $00

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



Note, my display is still looking weird because I am using an LCD (20x4). So I'm not sure if that's the problem. I want to think it isn't recognizing my input. But, it correctly works at the [C]/[W] prompt.

Any help would be appreciated.

Thanks!

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 24, 2018 3:32 am 
Offline

Joined: Wed Feb 12, 2014 1:39 am
Posts: 172
Location: Sweden
What happens when you just hit enter at that prompt? I just do that and let it figure it out for itself


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 24, 2018 5:07 am 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1207
Location: Soddy-Daisy, TN USA
Same thing. It loops back to the prompt.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 24, 2018 5:21 am 
Offline

Joined: Wed Feb 12, 2014 1:39 am
Posts: 172
Location: Sweden
Does it make use of any ZP locations that might clash with your monitor? I had a look at the monitor listing but as it doesn't include all the files I can't quite tell


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 24, 2018 10:39 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
The most common error here is that the output vector returns with altered registers. Use push and pull instructions in your output vector code for all registers being modified in LCD_WRITE.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 24, 2018 12:40 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1207
Location: Soddy-Daisy, TN USA
Hmm. Unfortunately, that didn't work.

All of my recent code is here:
https://github.com/cbmeeks/Potpourri6502

I didn't want to post long listing here but I can if people prefer.

Klaus2m5 wrote:
The most common error here is that the output vector returns with altered registers. Use push and pull instructions in your output vector code for all registers being modified in LCD_WRITE.


Sorry for my ignorance...I'm not yet understanding how EhBASIC works. I put some push/pull for A which my LCD write routine clobbers. As best as I can tell, it's the only register that is touched.

So I'm not sure I completely know where the output vector section is.

Thanks again.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 24, 2018 4:51 pm 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
The vector table in EhBASIC (RAM) is here:
Code:
ccflag      = $0300   ; BASIC CTRL-C flag, 00 = enabled, 01 = dis
ccbyte      = ccflag+1   ; BASIC CTRL-C byte
ccnull      = ccbyte+1   ; BASIC CTRL-C byte timeout

VEC_CC      = ccnull+1   ; ctrl c check vector

VEC_IN      = VEC_CC+2   ; input vector
VEC_OUT      = VEC_IN+2   ; output vector
VEC_LD      = VEC_OUT+2   ; load vector
VEC_SV      = VEC_LD+2   ; save vector
There is another table in EhBASIC (ROM) to allow the use of JSR:
Code:
; system dependant i/o vectors
; these are in RAM and are set by the monitor at start-up

V_INPT
   JMP   (VEC_IN)      ; non halting scan input device
V_OUTP
   JMP   (VEC_OUT)      ; send byte to output device
V_LOAD
   JMP   (VEC_LD)      ; load BASIC program
V_SAVE
   JMP   (VEC_SV)      ; save BASIC program
So it is just a matter of finding calls to V_OUTP in the EhBASIC code.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 25, 2018 2:09 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
I had some similar growing pains initially getting EhBasic to run on my SBC as well. Once I figured out all of the zero page usage versus my monitor... and the other piece of code that sorta describes the SBC side (kinda like it's BIOS), I was able to get it working without any issues.

I eventually took Klaus' latest version (thanks to Klaus for maintaining an up to date patched version) and made numerous changes to the code, making it a single ASM file where the vectors to the monitor routines are loaded on startup. The single ASM file also has all ZP usage condensed from $00 upwards (as my BIOS and Monitor start at $FF and go down).

So far it's been running very well on a few boards...

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


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 25, 2018 4:08 pm 
Offline
User avatar

Joined: Fri Dec 12, 2008 10:40 pm
Posts: 1000
Location: Canada
Your comments indicate that your keyboard routine waits for a character before returning. Not that this is your current problem, but EhBAsic requires that the input routine be a non-stalling routine. It must go check if there is a character and return immediately whether it finds one or not.

It must also set the carry flag if it does find a character and clear the carry flag if it does not. If you don't execute an SEC before returning, it will assume that no character was found and just go back to where it was. In this case, back to the memory size prompt.

_________________
Bill


Top
 Profile  
Reply with quote  
PostPosted: Thu Oct 25, 2018 9:33 pm 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1207
Location: Soddy-Daisy, TN USA
BillO wrote:
Your comments indicate that your keyboard routine waits for a character before returning. Not that this is your current problem, but EhBAsic requires that the input routine be a non-stalling routine. It must go check if there is a character and return immediately whether it finds one or not.

It must also set the carry flag if it does find a character and clear the carry flag if it does not. If you don't execute an SEC before returning, it will assume that no character was found and just go back to where it was. In this case, back to the memory size prompt.



Ah! You're right. I read that but it didn't click. I will give that a shot as well.

Thanks

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 26, 2018 3:29 am 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1207
Location: Soddy-Daisy, TN USA
BillO wrote:
Your comments indicate that your keyboard routine waits for a character before returning. Not that this is your current problem, but EhBAsic requires that the input routine be a non-stalling routine. It must go check if there is a character and return immediately whether it finds one or not.

It must also set the carry flag if it does find a character and clear the carry flag if it does not. If you don't execute an SEC before returning, it will assume that no character was found and just go back to where it was. In this case, back to the memory size prompt.


Hmm. Still no dice. In fact...I'm curious. Why/how would EhBASIC know the keyboard input is blocking?

The routine gets called...and it waits for valid input to be pressed. Wouldn't EhBASIC be halted during that time?

Either way...not sure why this wouldn't work. Once a key is pressed, A contains the ASCII code and it should be setting the carry flag correctly. Or, am I missing something?

Code:

KEYBin:
        ;; GET KEYBOARD CHAR
        JSR     kbinput                 ; Waits for ASCII key press.
                                        ; A should now have ASCII character
                                        ; (waits for a non-zero ASCII code)
        BEQ   LAB_nobyw      ; branch if no byte waiting
   SEC            ; flag byte received
   RTS

LAB_nobyw:
   CLC            ; flag no byte received
        RTS


_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 26, 2018 4:37 am 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1926
Location: Sacramento, CA, USA
cbmeeks wrote:
Why/how would EhBASIC know the keyboard input is blocking?

Could it be that EhBASIC uses it to peek for a CTRL-C periodically while interpreting?

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 26, 2018 4:51 am 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1207
Location: Soddy-Daisy, TN USA
barrym95838 wrote:
cbmeeks wrote:
Why/how would EhBASIC know the keyboard input is blocking?

Could it be that EhBASIC uses it to peek for a CTRL-C periodically while interpreting?


Ah, I bet you're right. The IRQ_vec is pointed to VEC_IN which points to VEC_CC.

Hmmm. Not sure how to modify the pckybd file to make it non-blocking at the moment. But I will look into that next.

Thanks.

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 26, 2018 5:12 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1373
Well, your input routine still waits for a key to be pressed, so setting or clearing the carry flag doesn't really help.

I took a quick look at Daryl's code... you might want to try using KBSCAN as part of your routine to see if a has been pressed... if it has, then use KBINPUT to get the character, set the carry flag and return.... else, simply clear the carry flag and return without calling KBINPUT.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Oct 26, 2018 5:15 am 
Offline
User avatar

Joined: Wed Aug 17, 2005 12:07 am
Posts: 1207
Location: Soddy-Daisy, TN USA
floobydust wrote:
Well, your input routine still waits for a key to be pressed, so setting or clearing the carry flag doesn't really help.

I took a quick look at Daryl's code... you might want to try using KBSCAN as part of your routine to see if a has been pressed... if it has, then use KBINPUT to get the character, set the carry flag and return.... else, simply clear the carry flag and return without calling KBINPUT.


Thanks for looking at that.

I tried KBSCAN earlier. For some reason, it just reboots the whole init screen I have. I'm going to dig into that some more too.

Anyone know how I could just disable the memory question and hard-code the size?

_________________
Cat; the other white meat.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

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