8bit
Electronics & Computers
Castor
2023.11.20 03:16:08 - 2023.12.07 02:50:40 end 6809 OMENkilo Castor Pollux Gilhad

1   Castor

  • Rozhodl jsem se, že nový EEPROM systém pro OMEN kilo nazvu Castor, protože proč ne :)
  • A firmware pro Arduino do Expanduina pak bude Pollux, protože to jsou Blíženci
  • A už jsem to vypálil do EEPROM, takže z toho jde bootovat, a při startu to na Castor pošle příkaz *BOOT, který nahraje soubor /BOOT.HEX (ale AutoExec je vypnutý, takže je ho nutno spustit ručně, nebo povolit AutoExec (a) a on se spustí sám následně.
  • Jde to relokovat do RAM (>) a pak přehrát ROM na něco jiného (novou verzi)

2   Memory Map

2.1   Push order for 6309 stack

                  New S                                       Old S
                  |                                           |
                  |                                           |
$0000             v                                           v                 $FFFF
+--+-     -+--+--+--+--+--+--+--+--+--+--+--+--+--+--+---+---+--+--+--+--+-     -+--+
|..|.......|..|..|CC| A| B| E| F|DP|Xh|Xl|Yh|Yl|Uh|Ul|PCh|PCl|##|##|##|..|.......|..|
+--+-     -+--+--+--+--+--+--+--+--+--+--+--+--+--+--+---+---+--+--+--+--+-     -+--+
                                               |Sh|Sl|
                                               +--+--+ for PSHU ...

    PUSH / PULL order

         +-----+-----------------------------+
         | CC  | Condition Code Register     |      .
    |    +-----+-----------------------------+     /_\
    |    | A   | A Accumulator               |      |
    |    +-----+-----------------------------+      |
    |    | B   | B Accumulator               |      |
    |    +-----+-----------------------------+      |
    |    | E   | E Accumulator  *)           |      |
    |    +-----+-----------------------------+      |
         | F   | F Accumulator  *)           |      |
    P    +-----+-----------------------------+
    U    | DP  | Direct Page Register        |      P
    L    +-----+-----------------------------+      U
    L    | X   | X Index Register            |      S
         +-----+-----------------------------+      H
    |    | Y   | Y Index Register            |
    |    +-----+-----------------------------+      |
   _|_   | S/U | Hardware/User Stack Pointer |      |
   \ /   +-----+-----------------------------+      |
    '    | PC  | Program Counter             |
         +-----+-----------------------------+


 *) Only 6309 in Interrupt in NATIVE mode (MD[N]=1)

2.2   6309 Interrupt vectors

  • 6309 have hardwarde wired Interrupt vectors to go indirect via $FFF0 ... $FFFE adresses (top of ROM)
  • Castor have the values there pointing to bottom of ROM (so if wearing will be problem, this whole section can be easily moved)
  • on bottom of ROM are jumps into top of RAM (except RESET), where each RESET will create jumps into 2nd table in ROM which points to final ROM code.
    • so user program can simply install there (on top of RAM) its own routines entry points
    • also can simply jump to the 2nd table to get to original ROM routines
  • Example:
    • SWI is executed
      • 6309 pushes registers on S stack
      • jumps indirect JMP [FFFA] to C008 (in ROM)
      • there is instruction JMP [7FF3] so it jumps indirect via RAM pointer
        • 7FF3 is in RAM, where RESET prepared pointer C026 (but user may change this to point on his own code)
      • C026 is in ROM again contains JMP to actual routine to manage SWI 1
      • the routine does something and returns with RTI just to instruction after the original SWI
  • RESET is exception, it goes from both C000 and C020 directly to ROM code and cannot be redirected
  • 7FFC,7FFD is initial stack S value can can be used by user to reinitialise Stack S. Points under the RAM vectors and RAM system data.
    • RESET restores this value and stack and then pushes C000 to stack, so return from there goes again to RESET
+------+-------+---------+--------------+----------------------------------+
| SVec | Hdlr  | 2.table | function     | Registers Auto-pushed onto stack |
+------+-------+---------+--------------+----------------------------------+
| FFFE | C000  | C020    | RESET Vector | none                             |
+------+-------+---------+--------------+----------------------------------+
| FFFC | C004  | C024    | NMI Vector   | D,X,Y,U,DP,CC                    |
+------+-------+---------+--------------+----------------------------------+
| FFFA | C008  | C028    | SWI 1 Vector | D,X,Y,U,DP,CC (masked Ints)      |
+------+-------+---------+--------------+----------------------------------+
| FFF8 | C00C  | C02C    | IRQ Vector   | D,X,Y,U,DP,CC                    |
+------+-------+---------+--------------+----------------------------------+
| FFF6 | C010  | C030    | FIRQ Vector  | CC (E flag cleared)              |
+------+-------+---------+--------------+----------------------------------+
| FFF4 | C014  | C034    | SWI 2 Vector | D,X,Y,U,DP,CC                    |
+------+-------+---------+--------------+----------------------------------+
| FFF2 | C018  | C038    | SWI 3 Vector | D,X,Y,U,DP,CC                    |
+------+-------+---------+--------------+----------------------------------+
| FFF0 | C01C  | C03C    | Trap Vector  | D,X,Y,U,DP,CC                    |
+------+-------+---------+--------------+----------------------------------+
SVec .. System VECtor
Hdlr .. HanDLeR

2.3   RAM Layout

2.3.1   Interrupts

+------+-------+-------------------------+----------------------------------+
| Addr | value | function                | Commentary                       |
+------+-------+-------------------------+----------------------------------+
| 7FFE | C000  | RESET Vector            | just adress                      |
+------+-------+-------------------------+----------------------------------+
| 7FFC | 7FB0  | Initial Stack           | just value                       |
+------+-------+-------------------------+----------------------------------+
| 7FFA | C020  | JMP to RESET Vector     | not used by Castor               |
+------+-------+-------------------------+----------------------------------+
| 7FF8 | C024  | JMP to NMI Vector       | D,X,Y,U,DP,CC                    |
+------+-------+-------------------------+----------------------------------+
| 7FF6 | C028  | JMP to SWI 1 Vector     | D,X,Y,U,DP,CC (masked Ints)      |
+------+-------+-------------------------+----------------------------------+
| 7FF4 | C02C  | JMP to IRQ Vector       | D,X,Y,U,DP,CC                    |
+------+-------+-------------------------+----------------------------------+
| 7FF2 | C030  | JMP to FIRQ Vector      | CC (E flag cleared)              |
+------+-------+-------------------------+----------------------------------+
| 7FF0 | C034  | JMP to SWI 2 Vector     | D,X,Y,U,DP,CC                    |
+------+-------+-------------------------+----------------------------------+
| 7FEE | C038  | JMP to SWI 3 Vector     | D,X,Y,U,DP,CC                    |
+------+-------+-------------------------+----------------------------------+
| 7FEC | C03C  | JMP to Trap Vector      | D,X,Y,U,DP,CC                    |
+------+-------+-------------------------+----------------------------------+

2.3.2   System RAM entry points

+------+-------+-------------------------+----------------------------------+
| Addr | value | function                | Commentary                       |
+------+-------+-------------------------+----------------------------------+
| 7FEA | ????  | Sys.Debug               | debugger, not implemented yet    |
+------+-------+-------------------------+----------------------------------+
| 7FE8 | ????  | Std.DumpRegs            | Dump all regs and top of stack   |
+------+-------+-------------------------+----------------------------------+
| 7FE6 | ????  | Sys.call.by.next.byte   | * LBSR [7FE6]; FB num            |
+------+-------+-------------------------+----------------------------------+
| 7FE4 | ????  | Sys.call.by.stack       | * PSHS num; LBSR [7FE4]          |
+------+-------+-------------------------+----------------------------------+
| 7FE2 | ????  | Sys.switch              | A,X -> value in X                |
+------+-------+-------------------------+----------------------------------+
| 7FE0 | ????  | Sys.switch_JMP          | A,X -> jump to X                 |
+------+-------+-------------------------+----------------------------------+

* roughly, see System functions

2.3.3   System RAM data

+------+----+-----------------------------------------------------------------+
| 7FB0 | 0A | ScratchPad - System may write here, but otherwise free to use   |
+------+----+-----------------------------------------------------------------+
| 7FBA | 1  | LOOP.FastIHEX.allowed                                           |
+------+----+-----------------------------------------------------------------+
| 7FBB | 1  | LOOP.exec.allowed                                               |
+------+----+-----------------------------------------------------------------+
| 7FBC | 1  | LOOP.exec.pending                                               |
+------+----+-----------------------------------------------------------------+
| 7FBD | 1  | LOOP.exec.addr                                                  |
+------+----+-----------------------------------------------------------------+
| 7FBF | 1  | EXPANDUINO.detected                                             |
+------+----+-----------------------------------------------------------------+
| 7FC0 | 1  | ALT.Read                                                        |
+------+----+-----------------------------------------------------------------+
| 7FC0 | 1  | ALT.Read.Status                                                 |
+------+----+-----------------------------------------------------------------+
| 7FC2 | 1  | ALT.Read.Mask                                                   |
+------+----+-----------------------------------------------------------------+
| 7FC3 | 1  | ALT.Read.Data                                                   |
+------+----+-----------------------------------------------------------------+
| 7FC5 | 1  | ALT.Read.Timeout                                                |
+------+----+-----------------------------------------------------------------+
| 7FC7 | 1  | ALT.Read.Config                                                 |
+------+----+-----------------------------------------------------------------+
| 7FC8 | 1  | ALT.Write                                                       |
+------+----+-----------------------------------------------------------------+
| 7FC8 | 1  | ALT.Write.Status                                                |
+------+----+-----------------------------------------------------------------+
| 7FCA | 1  | ALT.Write.Mask                                                  |
+------+----+-----------------------------------------------------------------+
| 7FCB | 1  | ALT.Write.Data                                                  |
+------+----+-----------------------------------------------------------------+
| 7FCD | 1  | ALT.Write.Timeout                                               |
+------+----+-----------------------------------------------------------------+
| 7FCF | 1  | ALT.Write.Config                                                |
+------+----+-----------------------------------------------------------------+
| 7FD0 | 1  | STD.Read                                                        |
+------+----+-----------------------------------------------------------------+
| 7FD0 | 1  | STD.Read.Status                                                 |
+------+----+-----------------------------------------------------------------+
| 7FD2 | 1  | STD.Read.Mask                                                   |
+------+----+-----------------------------------------------------------------+
| 7FD3 | 1  | STD.Read.Data                                                   |
+------+----+-----------------------------------------------------------------+
| 7FD5 | 1  | STD.Read.Timeout                                                |
+------+----+-----------------------------------------------------------------+
| 7FD7 | 1  | STD.Read.Config                                                 |
+------+----+-----------------------------------------------------------------+
| 7FD8 | 1  | STD.Write                                                       |
+------+----+-----------------------------------------------------------------+
| 7FD8 | 1  | STD.Write.Status                                                |
+------+----+-----------------------------------------------------------------+
| 7FDA | 1  | STD.Write.Mask                                                  |
+------+----+-----------------------------------------------------------------+
| 7FDB | 1  | STD.Write.Data                                                  |
+------+----+-----------------------------------------------------------------+
| 7FDD | 1  | STD.Write.Timeout                                               |
+------+----+-----------------------------------------------------------------+
| 7FDF | 1  | STD.Write.Config                                                |
+------+----+-----------------------------------------------------------------+

(I/O channels, internal switches, etc)

2.3.4   Top of Stack S

(with return to RESET on its top - C000)

2.5   System functions

  • Sys.switch ( A,X|X A case, X table|X value) - searches table pointed by X register for value in A register.
    • Table rows are 3 bytes wide (1 byte value to compare wuth A, 2 bytes value to return in X).
    • Table ends when two following rows have the same first byte (A), the 2 bytes of the second row are Default value to use, when match was not found.
    • Modifies only X register (and flags are trahed), everytime.
    • Fast way to select some 2 byte value from more alternatives. (or 2 byte pointer, ...)
    • as extremely usefull, it was made accessible directly
  • Sys.switch_JMP ( A,X|X A case, X table|X value, JMP X) - searches table as Sys.switch, jumps to address pointed by X
    • as extremely usefull, it was made accessible directly
  • System Table ( func. number, func. address ) is table of all published system function
    • there is not extra order, except of historical, as more functions was added
  • Sys.call.by.stack - push number of system function onto stack and call this
    • Example

      LDA #123                ; function nubmer
      PSHS A                  ; push on stack S
      LDA #some_value         ;
      LDX #a_pointer          ; prepare arguments for system function
      JSR Sys.call.by.stack   ; call the function
      BNE     >               ; do somethin else
      
  • Sys.call.by.next.byte - get the function number from byte just after the call (which is then skipped)
    • similar to OS9 calls (and maybe later SWI2 will replace this)

    • Example

      LDA #some_value                 ;
      LDX #a_pointer                  ; prepare arguments for system function
      JSR Sys.call.by.next.byte       ; call the function
      FCB     123                     ; function nubmer
      BNE     >                       ; do somethin else
      
  • both system call are fully equivalent, use whichever you like more

3   Screenshot

--==### CASTOR ###==--
v.0.1.0-r3 / master
07.12.2023 01:44:51
Address range: C000 - D8D8 (Total 18D8 ROM)
+++0000+
## Expanduino_I v.00.00.03 (Nano Every)
# Expanduino detected
 (Channel set to 1 )
Boot
*BOOT
Main Loop
> ### Expanduino_I v.00.00.03 (Nano Every)

> :20 2200 ################################ ;)
> :20 2220 #####=########################## ;)
> :20 2240 ################################ ;)
> :20 2260 #######=######################## ;)
> :20 2280 ################################ ;)
> :20 22A0 ################################ ;)
> :20 22C0 ################################ ;)
> :1A 22E0 ########################## ;)
> :00 2200  ;)
> a Autoexec is now allowed

> exec pending:

Hello World!

Welcome back in Loop
>

4   Help

> ?
Regs: A: 3F; B: 00; CC: 51=eFhInzvC; DP: 00; X: 0B9D; Y: 03A6; S: 7FAC; U: 7FAC; W: 0000; V: 0016;
 PC[0BA0]: 97 20 E2 30 8D 09 3C 17 F9 98 39 17 FB 32 ^ 17 F7 0F 30 8D 09 B6 17 F9 8A 30 8D 0C 22 17 F9;
 St[7FAC]: 03 A6 02 00 E5 E5 E5 E5 E5 20 5B 00 08 64 00 00 00 00 00 00 83 FE 01 83 FF 00 00 02 83 FE 02 83;

+---------------------------------------------+
|                                             |
|          --==### CASTOR ###==--             |
|                                             |
+----------------------+----------------------+
| v.0.1.0-r10 / master | 15.01.2024 01:48:51  |
+----------------------+----------------------+
| Address range: 0200 - 194B (Total 174B RAM) |
+---------------------------------------------+
 Help:

Q, q - quit Castor (Reboot computer)
R, r - return to calling program
C, c - call address
> - Relocate to new RAM place
D, d - dump memory
: - IHEX (type 0 & 3 ( & 1))
# - the rest of line is Comment (and so ignored)
* - the rest of line is StarCommand for Expanduino
^ - send 1 byte ControlCommand to Expanduino
| - SetAltChannel for communication with Expanduino
A,a - SwapAutoexec for IHEX etc.
F, f - SwapFastIHEX - fast=only RAM
` - Test (do not use)
~ - Diff memory to memory
K - KillROM (do not use)
Z, z - Zero - clear RAM to 00 (or any value)
^B - long text - up to ^C
?, H, h - this help

SYSTEM_Autoexec_allowed:  No
SYSTEM_FastIHEX_allowed:  No
LOOP.exec.pending:  No
LOOP.exec.addr: 0000
Expanduino detected:  No

5   ChangeLog

  • 2024.01.15 01:57:01 v.0.1.0-r10 barevné logo
  • 2023.12.09 04:40:44 v.0.1.0-r4 dobře vypálená, umí ^B ^C blok, takže Pollux může posílat delší výpisy s odřádkováním (a Pollux umí *LS, *TYPE a *EXEC , takže další stupeň samostatnosti)
  • 2023.12.07 02:32:40 v.0.1.0-r3 snad plně funkční
  • 2023.12.07 02:29:32 Vypisuje se i kus kolem PC, KillROM formátuje začátek ROM, FastIHEX jen pro RAM, SLOW.IHEX prepisuje jen co je potřeba a validuje každý zapsaný byte, kvůli polofunkční EEPROM (zápisy jsou nespolehlivé)(při pečlivé práci a následném vypnutí to chodí celkem dobře)
  • 2023.11.30 12:20:58 CC se vypisuje jako pojmenované bity, vypisuje se i kus stacku, vektory jsou, systémová data jsou nad stackem
  • 2023.11.30 08:34:21 v.0.0.1-r5
  • 2023.11.30 08:30:58 Chodí *BOOT, různé drobnosti, IOSpeedTest. Je potřeba napsat vektory a přesunout systémová data na 7Fxx a napsat relocate, pak už to bude vypálitelné
  • 2023.11.28 17:40:05 Castor ve vlastním repozitáři, měl by být plně relokovatelný (position independent)
  • 2023.11.24 19:32:16 Castor už v podstatě funguje, brutálně jsem zrychlil IHEX, ale vyžaduje buď potvrzování řádků, nebo bufferování na straně Polluxu. Taky jsem přidal lepší Dump, Call, Comment, přehazování Autoexecu, ControlCommand, StarCommand a vylepšil Help, zbývá doladit Interrupt Vectory a I/O, které chci dát pod vrchol RAM
  • 2023.11.20 03:05:57 Rozhodl jsem se, že systémové proměnné na Castor budu dávat pod vrchol RAM (teda 7Fxx-7FFF) v podstatě v zásobníkovém přístupu - tedy popis bloků shora dolu - první je defaultní adresa zásobníku, následuje blok skoků do systému (RESET,DEBUG, ...) asi obsadím SWI pro DEBUG, SWI2 pro int21h ?
  • 2023.11.20 03:04:20 IHEX pro Castor už v podstatě funguje, jen čtení vstupu je pomalé a přeskakuje znaky z paste/souborů, ruční zadávání OK
  • 2023.11.20 03:02:21 Rozhodl jsem se, že nový EEPROM systém pro OMEN kilo nazvu Castor, protože proč ne :)

6   GitLog

  • 8236880 fixed KillROM, + -> # (HEAD -> master, master, HEAD)
  • f736fda fixed EXPANDUINO detect (len)
  • 5e43559 Zero with value
  • 11cef01 ===== Podarilo se nabootovat z EEPROM, zda se to pouzitelne (0.1.0)
  • f254e37 IHEX.SLOW
  • 6a1fce3 Diff
  • eb03305 some tools
  • e08b9b2 +KillROM
  • fd2f0bf Debug pro autoreloc part in IHEX_COPY
  • 968daa5 bezkecnostni konce CODE, DATA, ...
  • 8d09d87 fix utilit na python3 a bez f-stringu pro mahoro
  • 7038951 bootuje bez expanduina, usekava konce v IHEXu
  • a93e05b Vektory, Reloc, cas na vypaleni
  • e72c920 HelloWorld
  • 764755e +HW_Vectors
  • 3f52231 SetChannel->SetAltChannel, IO_SpeedTest/
  • e9223c1 color title, addr. range
  • b055198 Plně relokovatelný kód
  • e6dd8df Úprava na RAM/ROM verze, jméno a verze, gtouch.sh, *.disassm
  • a5ed777 uvodni commit (0.0.1)