Oh wow, you're right, I'm not a newbie after all, although most of my posts were 16 years ago, I guess they slipped my mind!
Quote:
...and related[/u] microprocessors and microcontrollers."
I hesitated before posting that I was using a 6809 as this is really just a structured-assembly & Forth question and I knew structured-assembly was definitely on topic here, but I thought I'd just be transparent up front.
The '816 part is definitely real, though, as there are a lot of 6502 programmers out there and due to the 6809 not having the power to provide much in the way of on-the-fly animation, you need to pre-calculate animation vector lists and that quickly eats up the 48KiB of usable address space. The '816 expanded memory management could be a more elegant solution than is currently used.
So, my project...what I'm actually trying to do is port the first Sargon chess engine from the SWTPC 6809 to the Vectrex 6809. The custom user interface interface part I will strip out and initially I'll run the engine from the Forth interpreter via a terminal I have connected. Later, I'll create an interface for the vector monitor, using Forth.
I have an early non-working iteration of the 6809 code, but the actual working** binary code was updated quite a lot afterwards, but that later source code is lost, so I've disassembled the working binary to get something that resembles the source code and re-engineered it with the comments etc from the non-working early version.
**Actually it's mostly working, you can play a game on the SWTPC, but it doesn't make the same moves as the original Z80 real Sargon engine does, I need to fix that.
Quote:
I've also assembled shorter pieces of code on the PC and had my already-running Forth (on the workbench computer) take it in as an Intel Hex file, then call it from the previously existing Forth...
I do this with my CamelForth on the Vectrex, I call the BIOS ROM routines that allow me to draw on the screen, read the joystick, play music etc. via the 6522/AY38910/DAC, without having to write my own drivers.
One part I've already converted is this code below (almost assembles). The layout I'm not too sure about, but the problem is the MP15 branch half way down, it jumps out of a BEGIN, UNTIL, loop and that's going probably going to break an IF, THEN, compilation. The MP20 branch does the same thing again. I could probably fix this routine quite easily, either by restructuring the code or changing the Forth cross assembler to not use the same address variable for BEGIN, and IF, patching, but subsequent routines are much more complicated.
I guess I'm just batting round the pros and cons of Forth jumping to a separately assembled block of code as opposed to merging the assembly source with the Forth source, the latter being much neater and would mean I don't need to stitch the separate binary code together.
Code:
10 asm:
11 here equ MPIECE
12 COLOR EORA, \ Restore color of piece
13 $87 # ANDA, \ Clear all flags except color flag
14 BPAWN # CMPA, \ Is it a black Pawn?
15 EQ IF, \ Skip if not (BNE)
16 DECA, \ Decrement by one for black Pawn
17 THEN, \
18 7 # ANDA, \ Clear color flag
19 M1 STA, \ Save piece type (M1+1 ??????, then xfer to Y?)
20 M1 LDY, \ Load index to DCOUNT/DPOINT
21 Y DCOUNT , LDB, \ Get direction count
22 Y DPOINT , LDA, \ Get direction pointer
23 INDX2 STA, \ Save as index to direction table (INDX2+1 ????)
24 INDX2 LDY, \ Load index to direction table
25 BEGIN,
26 Y DIRECT , LDA, \ Get move direction and increment pointer
27 RC STA, \ Save it as parameter for PATH
28 M1 LDA, \ Get "from" position (M1+1 ?????)
29 M2 STA, \ Initialize "to" position (M1+2 ?????)
30 BEGIN,
31 PATH JSR, \ Calculate next position
32 #2 CMPA, \ Ready for new direction?
33 \ MP15 BCC, \ Branch if yes
34 RC STA, \ Check for empty square and save results
35 T1 LDA, \ Get moved piece
36 PAWN+1 # CMPA, \ Is it a Pawn? ( THIS ISN'T RIGHT)
37 MP20 BCS, \ Branch if yes
38 ADMOVE JSR, \ Add move to list
39 RC LDA, \ Restore previous test results
40 MP15 BNE, \ Branch if "to" square not empty
41 T1+1 LDA, \ Get piece type
42 #KING CMPA, \ Is it a King?
43 MP15 BEQ, \ Branch if yes
44 #BISHOP CMPA, \ Is it a Bishop, Rook, or Queen?
45 LO UNTIL, \ Branch if any of the above (BHS Branch if Higher or Same)
46 ( MP15 ) DECB, \ Decrement direction counter
47 EQ UNTIL, \ Do next direction, if any
48 T1+1 LDA, \ Get piece type
49 #KING CMPA, \ is it a King?
50 MERTN BNE,
51 EQ IF, \ Return if not (BNE)
52 CASTLE JMP, \ Consider castling
53 THEN,
54 RTS, \ Return
55 ;c