Orwell running BASIC. Well, mostly…

October 5th, 2013

After much fiddling about I finally got MS Basic running on Orwell. Well, mostly.

Firstly I fixed some bugs, one a hardware error. The reason my IO port was showing LEDs lit when nothing was writing to it was because the way the address logic was working it mean the output latch was inadvertently being set on other writes to other IO locations. I could see the spikes of it being enabled on the scope. I added in an extra AND (I have unused ones free on the IC) and now qualify the signal with the phi 2 clock, the same as you do for writing to normal RAM. Writing to the IO buffer is just like writing to RAM actually so I think this solution is correct. It certainly works better now.

The second issue was harder to work out. You might remember that I had issues reading in a key when at the memory select prompt. I did a lot of debugging which basically involved outputting certain values to my LEDs at specific points in the code. I eventually worked out that my keyboard scanning routines were fine. The debugging got me further and further into understanding the code until I finally saw what the problem was.

The issue was in the INLIN subroutine. This reads in a line of input from the keyboard and manipulates it. It looks for ‘special’ characters and builds up a string in an input buffer. It calls the keyboard scan for a new character in a loop until the line is full or there is a CR entered. The input buffer uses the X register as it’s index counter.

Unfortunately my keyboard scan code also uses the X register. I use it as an offset into my keyboard may. What was happening was when certain keys were pressed my code works out the offset into the lookup table and uses X to index it. The table follows the layout of the matrix itself, not in any ASCII order. I do it this way so I can directly map the row/column scans into a location in the table.

So the first part of my keyboard map mirrors the keyboard matrix row/column layout:

keyboard_map_row_n0: .BYTE "=", $20, $0D, 0, 0, 0, 0, 0    ;$20 = SPACE, $0D = CR
keyboard_map_row_n1: .BYTE "nhy6bgt5"
keyboard_map_row_n2: .BYTE "mju7vfr4"
keyboard_map_row_n3: .BYTE ",ki8cde3"
keyboard_map_row_n4: .BYTE ".lo9xsw2"
keyboard_map_row_n5: .BYTE "/;p0zaq1"

 

That’s just the first part. It is repeated with the appropriate shift, control and function values inserted where necessary. I use X to count into the table to pull out the appropriate character.

What happened was certain characters were setting X to a value larger than the maximum size of the buffer. The values that did that depend on their position in the table, not their value. That’s why some letters worked fine but not others with seemingly no reason behind why.

The INLIN code below just skips storing the value if the X value is too large:

L2443:
    CPX     #$47
    BCS     L244C       
    STA     INPUTBUFFER, X
    INX
    .BYTE   $2C        
L244C:

That was exactly what I was seeing. Certain values were just ignored. Solution was simple. Just store the X value at the start of my routines, use it as I needed then restore it when I returned. That’s probably good programming practice anyway!

So with that fixed I managed to actually boot successfully into BASIC.

IMG_4248_1 Microsoft BASIC running!

Unfortunately there is still a bug. Things are mostly working. I need to tweak my keyboard map to support all the special keys OSI Basic uses. I can type commands. I can POKE values into my debug buffer and light up LEDs (which I find immensely satisfying for some reason) and I can call PRINT and print things to the screen. I can even enter lines of code. But there is where it is going wrong. None of my lines are being saved it seems. Typing LIST or RUN just results in an OK message.

So that’s the next step, figure out what’s wrong there. I also want to clean up the code and tweak it to be more what I need. It could also use a hell of a lot of comments! I can run 38 characters across the screen and can change the default in the code to reflect that. The keyboard matrix can support extra keys I can add in. Eventually, as my display module supports loading of different character sets, I would like to add some sort of graphics set in ROM and have a way to send that to the display module so I can do simple graphics.

I am also working on the Eagle layout still as I am now at the stage where the hardware is looking good and I can finalise it and get a PCB made. I don’t think I am far from getting my first Usborne book Basic program running! I need to start reviewing the books too.

 

Comments are closed.