6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed May 15, 2024 4:53 pm

All times are UTC




Post new topic Reply to topic  [ 72 posts ]  Go to page Previous  1, 2, 3, 4, 5  Next
Author Message
 Post subject: Re: FT816 Core
PostPosted: Sat May 27, 2017 5:15 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8433
Location: Southern California
Rob, you are so productive in you microprocessor designs! I don't know how you can keep multiple ones going.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sat May 27, 2017 10:42 am 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 449
Location: Canada
Quote:
Rob, you are so productive in you microprocessor designs! I don't know how you can keep multiple ones going.

A lot of block copying, practice, and learning from prior mistakes (experience).

This problem has me stumped good. The system hangs only if an attempt is made to invoke EnhBASIC, otherwise the system runs smoothly. I traced a problem to the system’s OutChar() routine which is run when EnhBASIC tries to display the startup message.
In the OutChar routine below, storing the acc to the LEDs shows an incorrect value and the system hangs.
Code:
 OutChar:
   PHP
   REP      #$30
   PHX
   PHY
   LDX      #0
   STA      $5:$7000
   JSR      (OutputVec,x)
   PLY
   PLX
   PLP
   RTS

However, storing acc to LEDs one instruction sooner displays the correct value and the system still hangs.
Code:
 OutChar:
   PHP
   REP      #$30
   PHX
   PHY
   STA      $5:$7000
   LDX      #0
   JSR      (OutputVec,x)
   PLY
   PLX
   PLP
   RTS

It looks to me like the LDX instruction might have some sort of side-effect. If .X were to be corrupted somehow then the following indexed indirect jump wouldn’t work properly. But the problem is only present when EnhBASIC is invoked. I can’t see any errors in the Verilog code. LDX # is pretty straightforward.

I had to slow down access to the BASIC rom to get rid of the bit error. (ROMs are begin accessed at only an 8MHz rate with wait states inserted). The core is using a cache however and runs at 33MHz.

_________________
http://www.finitron.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sat May 27, 2017 11:14 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
I do appreciate seeing your progress, including the obstacles you find - it's always interesting and often instructive! You have the boldness to proceed, break, and then fix.


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sat May 27, 2017 12:30 pm 
Offline
User avatar

Joined: Wed Mar 01, 2017 8:54 pm
Posts: 660
Location: North-Germany
Wouldn't it be saver to push X,Y first then do REP?


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sat May 27, 2017 8:21 pm 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 449
Location: Canada
Quote:
Wouldn't it be saver to push X,Y first then do REP?

Yes, I switched it around.

Progress. EnhBASIC now outputs the string “h@@@@@@@@@@@@?” instead of the memory size prompt. Printing individual characters from BASIC works as the CR,LF and ? characters come out correctly. It’s just the printing of strings that is screwy. The “ahah” moment was realizing that BASIC is running in an eight bit virtual machine, and it was calling a routine that expected to be running in a 16 bit virtual machine. The eight bit VM doesn’t know about the ‘M’ and ‘X’ bits of the status register. Using context switching call and return instructions (JCR, RTC) fixed that issue. JCR works like JSR except that it switches to the VM of the called routine. It has an extra operand which is the context number to switch to. RTC works like RTS restoring the original context. What gets saved on the stack is the previous context number instead of the return address.
Now to get keyboard input to work, getting a keyboard character hangs the machine when done from someplace other than the BIOS.

_________________
http://www.finitron.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sat May 27, 2017 10:03 pm 
Offline
User avatar

Joined: Wed Mar 01, 2017 8:54 pm
Posts: 660
Location: North-Germany
:)

Input routine: most likely that there is a similar mismatch between VM8 <=> VM16 during character fetching. Sometimes these 'M' and 'X' flags causes more frustration than delight.


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sun May 28, 2017 1:17 am 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 449
Location: Canada
I fixed the input routine the same time as the output routine. You are likely correct however, it's likely still a bug transitioning between VM's.

The message string display from BASIC is now corrected. It was a problem in the BASIC with a zero page pointer, due to I think my playing at one point trying to have strings displayed from anywhere in a 32 bit memory space.

Getting characters in Supermon is working but that's going between VM16 <=> VM16, however it disables interrupts somehow. Interrupts are restored upon exiting Supermon.

_________________
http://www.finitron.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sun May 28, 2017 5:17 am 
Offline
User avatar

Joined: Wed Mar 01, 2017 8:54 pm
Posts: 660
Location: North-Germany
Not knowing the details I can only guess what may happen.

Assuming you did already check the transitions from/to VM8/16 I would check whether PHP, PLP, REP, and SEP really do what they ought to do. Perhaps either during save/load to/from stack or the P register itself may get corrupted. As you can probably stop your machine at any state it should take no much time to verify whats going on.

Their may also a silly omission during any interrupt service routine that is in use during your tests.

Good luck!


edit(1): This is obviously nonsense as you stated its VM16 <=> VM16. Sorry. Nevertheless there might something like 8/16 bit accumulator size. Indexregister size as well, although it's rare to use 8 bit size index registers. I hope it's not the D flag for some weird circumstances ;)


Last edited by GaBuZoMeu on Sun May 28, 2017 11:03 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sun May 28, 2017 7:07 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8183
Location: Midwestern USA
Rob Finch wrote:
Getting characters in Supermon is working but that's going between VM16 <=> VM16, however it disables interrupts somehow. Interrupts are restored upon exiting Supermon.

Which version of Supermon are you using?

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


Top
 Profile  
Reply with quote  
PostPosted: Sun May 28, 2017 1:41 pm 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 449
Location: Canada
Quote:
Which version of Supermon are you using?
Supermon832 1.0.0 (Supermon816 1.0.0 with a small number of hacks).
I modified the character get, put subroutine calls so that they could switch to the BIOS context. As follows (jsr replace with jcr):
Code:
       cpu FT832
       jcr putcha,biosctx
       cpu W65C02

Just looking at it now I realize I could probably have the assembler recognize a context call when there's an extra parameter to jsr. It'd reduce the number of mnemonics.
I also modified the register dump to display additional registers, 32 bit contents.
I'm using a combination of my own monitor and Supermon to do memory dumps, disassemble code. It needs a large number of modifications yet. I have to add new instructions and modify the flimflag to support 32 bits, and ...

_________________
http://www.finitron.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sun May 28, 2017 4:19 pm 
Offline
User avatar

Joined: Wed Mar 01, 2017 8:54 pm
Posts: 660
Location: North-Germany
What happens when the CPU has to do a JCR context call? Elsewhere you said A, X, Y, and flags are not saved.


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sun May 28, 2017 4:48 pm 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 449
Location: Canada
JCR works like a subroutine call except:
- the entire state of the current context is saved in it's context register
- this includes the (CS,DS,SS,PB,PC,SP,A,X,Y,flags,DB,DP)
- A,X,Y, flags are effectively not saved since they will be overwritten when the routine executes
- the segment registers (CS,DS,SS) are loaded from the target context including looking up descriptor info
- the program counter is loaded with the address in the instruction
- the SP, DP, DB are loaded from the target context
- A,X,Y, flags remain the same as from the calling context (to allow parameter passing)
- the mode bits are set to the target's mode (816/832)
- the calling context number is saved on the target's stack

(JCL similar to JCR can also copy stack parameters between stacks of the caller and called contexts).

_________________
http://www.finitron.ca


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Sun May 28, 2017 7:49 pm 
Offline
User avatar

Joined: Wed Mar 01, 2017 8:54 pm
Posts: 660
Location: North-Germany
I don't see anything that might disturb the flags. So probably the issue of disable interrupts may have other reasons but context switching.


Top
 Profile  
Reply with quote  
 Post subject: Re: FT816 Core
PostPosted: Mon May 29, 2017 11:11 pm 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 449
Location: Canada
EhBASIC is now running in a VM on the FT832 test system ! The first test program displaying the numbers from 1 to 10 works.
Code:
10 FOR X=1 TO 10
20 PRINT X;
30 NEXT X


The BASIC is running the address range $10000 to $20000 (bank1) but it's faked out to think it's running in bank zero. It's all done with the magic of segment registers (invisible to EhBASIC).

One modification to the BASIC was to have the BASIC character fetch routine executed directly from ROM rather than from a copy in zero page. This saves some valuable zero page storage space. The problem with executing the routine from zero page is that it’s self-modifying code and so it requires a cache line invalidate to occur after the pointer address is updated. Adding this extra code would be present in zero page consuming valuable space and it also isn’t any faster than running the routine from ROM. All that was required for mods was to use an indirect fetch rather than a direct one, and change the LAB_GBYT, LAB_IGBY labels to point to the ROM code.
Code:
 LAB_2CEE
LAB_IGBY:
   INC   Bpntrl      ; increment BASIC execute pointer low byte
   BNE   LAB_2CF4      ; branch if no carry
               ; else
   INC   Bpntrh      ; increment BASIC execute pointer high byte

; page 0 initialisation table from $C2
; scan memory

LAB_2CF4
LAB_GBYT:
   LDA   (Bpntrl)   ; $FFFF         ; get byte to scan (addr set by call routine)
   CMP   #TK_ELSE      ; compare with the token for ELSE
   BEQ   LAB_2D05      ; exit if ELSE, not numeric, carry set

   CMP   #':'         ; compare with ":"
   BCS   LAB_2D05      ; exit if >= ":", not numeric, carry set

   CMP   #' '         ; compare with " "
   BEQ   LAB_2CEE      ; if " " go do next

   SEC            ; set carry for SBC
   SBC   #'0'         ; subtract "0"
   SEC            ; set carry for SBC
   SBC   #$D0         ; subtract -"0"
               ; clear carry if byte = "0"-"9"
LAB_2D05
   RTS

Another fix to 2.22 code was in the CPY under LAB_2DB6. The CPY should be comparing the high byte.
Code:
LAB_2DB6
   LDA   Itempl      ; get temporary integer low byte
   LDY   Itemph      ; get temporary integer high byte
   ;CPY   #<Ram_base+1
   CPY   #(>Ram_base)+1   ; compare with start of RAM+$100 high byte
   BCC   LAB_GMEM      ; if too small go try again

_________________
http://www.finitron.ca


Top
 Profile  
Reply with quote  
PostPosted: Tue May 30, 2017 8:53 am 
Offline
User avatar

Joined: Sun Dec 29, 2002 8:56 pm
Posts: 449
Location: Canada
FT832 interrupts are not working correctly. Somehow the interrupt mask flag is being set causing them to be ignored. But it only happens when switching between certain tasks. If task#0 (the BIOS monitor) is the running task then interrupts are always enabled and work properly. However if any other task is the running task (task #7 BASIC, task#8 Supermon, task#252 BIOS calls) then interrupts become masked. All of these tasks have their interrupt mask bit cleared at startup and never set it (There’s no SEI instruction). In BASIC if a CLI instruction is placed in the V_INPT or V_OUTP routine then the system hangs. However, interrupts can be enabled by performing an ON IRQ command in BASIC which does a CLI. So by including an IRQ handler in BASIC interrupts are pseudo working.
The following EhBASIC program shows interrupts happening by displaying an “I” on screen when an interrupt occurs.
Code:
10 ON IRQ GOTO 1000
20 GOTO 10
1000 PRINT “I”;
1010 RETIRQ

This is great if a program is running, but when back in direct mode interrupts aren’t enabled.
It’s strange because there’s only a handful of places in the Verilog code where the interrupt mask flag is set. These being from the task context register when the task is switched, from an RTI or PLP instruction when the status register is loaded from the stack, or by the SEI instruction, or when an interrupts occurs.
And, it was working at one point, and I’ve checked the code very carefully, and done some experimentation to try and verify the code.
One thing which may be causing a problem is that there is a three cycle delay before a CLI instruction becomes active. This is to prevent the core from hanging on a single instruction if interrupt overrun occurs.

_________________
http://www.finitron.ca


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

All times are UTC


Who is online

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