Almost lost technologies

ここは昔の CPU を用いた工作記事を書くために用意しました。雑談は https://bsky.app/profile/alpine183.bsky.social で。

NIBL on SC/MP-III 改造 (続き2)

LIST までは動くけど、NIBL のラインパーザが追いきれていない。ほかを投げ出したままなのも何なので一旦中断して TLCS-90の方をナントカするつもり。

 

--- /home/seiji/cross/SCAMP/scmp3_nibl-SBC-240326.asm	2025-04-26 22:44:51.000000000 +0900
+++ nibl3.asm	2025-05-26 22:55:29.221131413 +0900
@@ -73,7 +73,7 @@
 RNDNUM: EQU       0xfff4      ; DW rnd number
 
 TMPF6: EQU        0xfff6      ; DB,DW temporary
-UNUSE1: EQU       0xfff8      ; DW unused
+TMPFGO: EQU       0xfff8      ; DW temporary used fotr GOTO parsing
 TMPFB: EQU        0xfffb      ; DB,DW temporary
 TMPFC: EQU        0xfffc      ; DB,DW temporary (overlaps TMPFB)
 TMPFE: EQU        0xfffe      ; DW temporary, alias
@@ -222,7 +222,8 @@
 ;
 ; does not work if 
 ;
-            DB      0x85            ; not a number, skip to DIRECT
+;            DB      0x85            ; not a number, skip to DIRECT
+            DB      DIRECT - $      ; not a number, skip to DIRECT
 ; just counldn't understand following routine
             LD      EA, TXTBGN      ; start of program
             SUB     EA, ONE         ; minus 1
@@ -309,7 +310,28 @@
 DIRECT:     LD      A, 0, P2        ; get char from buffer
             XOR     A, =CR          ; is it a CR?
             BZ      MAINL7          ; yes, continue in main loop
-            PLI     P3, =CMDTB1      ; load first CMD table
+; ADDED for FAST GOTO by efialtes_htn
+	    AND	    A,=0x80	    ; is bit8=1 then internal codes.
+	    BZ	    DIRECT6	    ; not internal -- RAW code.
+; internal code parser
+; 0x80:	GO TO -- 0x80, NADDRL, NADDRH, 0x20[, 0x20]*
+;
+	    LD	    A, @1, P2	    ; restore from buffer and increment pointer
+	    XOR	    A, =0x80	    ; GOTO
+	    BNZ	    ICODEP1
+	    LD	    A, =1, P2	    ; UPPER
+	    LD	    E,A
+	    LD	    A, =0, P1	    ; LOWER
+	    LD	    P2,EA
+	    CALL    6		    ; ENDCMD
+;
+ICODEP1:
+ICODEPE:
+            CALL    15               ; ERROR
+	    DB	    1
+; end ADDED
+
+DIRECT6:    PLI     P3, =CMDTB1      ; load first CMD table
             CALL    11              ; CMPTOK
 
 ; out of memory error
@@ -337,7 +359,8 @@
             ST      EA, TMPFB       ; save temporary
             CALL    9               ; GETCHR
             CALL    13              ; NUMBER
-            DB      0x18            ; skip if not number to FINDL4
+;            DB      0x18            ; skip if not number to FINDL4
+            DB      FINDL4 - $      ; skip if not number to FINDL4
             CALL    5               ; APULL
             SUB     EA, -2, P3    ; subtract number from the one on stack (the line number found)
             XCH     A, E            ; is larger?
@@ -366,14 +389,19 @@
 ;-----------------------------------------------------------------------------------
 ; set of DIRECT commands
 CMDTB1:     DB      "LIST"
-            DB      0x93            ; to LIST
+;            DB      0x93           ; to LIST
+            DB      0x80 + LIST - $ - 1 ; to LIST
             DB      "NEW"
-            DB      0x8a            ; to NEW2
+;            DB      0x8a            ; to NEW2
+            DB      0x80 + NEW2 - $ - 1 ; to NEW2
             DB      "RUN"
-            DB      0xb5            ; to RUN
+;            DB      0xb5            ; to RUN
+            DB      0x80 + RUN - $ - 1  ; to RUN
             DB      "CONT"
-            DB      0xa7            ; to CONT
-            DB      0xd2            ; default case to EXEC1
+;            DB      0xa7            ; to CONT
+            DB      0x80 + CONT - $ - 1 ; to CONT
+;            DB      0xd2            ; default case to EXEC1
+            DB      0x80 + EXEC1 - $ - 1 ; default case to EXEC1
 
 ;-----------------------------------------------------------------------------------
 ; NEW command
@@ -386,7 +414,7 @@
 ;-----------------------------------------------------------------------------------
 ; LIST command
 LIST:       CALL    13              ; NUMBER
-            DB      3               ; if no number, skip to LIST0
+            DB      LIST0 - $       ; if no number, skip to LIST0
             BRA     LIST1
 LIST0:      LD      EA, ZERO        ; no number given, start with line 0
             CALL    4               ; APUSH put on stack
@@ -394,10 +422,12 @@
 LIST2:      CALL    9               ; GETCHR from location found
             PUSH    P2    
             CALL    13              ; NUMBER 
-            DB      0x0a            ; if error, goto LIST3
+;            DB      0x0c            ; if error, goto LIST3
+            DB      LIST3 - $       ; if error, goto LIST3
             CALL    5               ; APULL
             POP     P2    
-            CALL    14              ; PRTLN
+;            CALL    14              ; PRTLN
+            JSR	    PRTLNL	    ; PRTLNL
             CALL    8               ; CRLF
             JSR     CHKBRK          ; test break
             BRA     LIST2
@@ -436,7 +466,8 @@
             ST      A, INPMOD
             BRA     MAIN1           ; back to mainloop
 RUN4:       CALL    13              ; parse line NUMBER
-            DB       8              ; not found: syntax error, goto SNERR1
+;            DB       8              ; not found: syntax error, goto SNERR1
+            DB      SNERR1 - $      ; not found: syntax error, goto SNERR1
             CALL     5              ; APULL line number
             ST      EA, CURRNT      ; set as current line
 
@@ -477,21 +508,21 @@
             BRA     GOSUB1          ; jump into GOSUB (process interrupt)
 
 CMDTB2:     DB      "LET"
-            DB      0xa6            ; to LET
-            DB      "IF"
-            DB      0xf3            ; to IFCMD
-            DB      "LINK"
-            DB      0xf7            ; to LINK
+            DB      0x80 + LET - $ - 1 ; to LET
             DB      "NEXT"
-            DB      0x9c            ; to NEXT
-            DB      "UNTIL"
-            DB      0xdb            ; to UNTIL
+            DB      0x80 + NEXT - $ - 1 ; to NEXT
             DB      "GO"
-            DB      0x96            ; to GOCMD
+            DB      0x80 + GOCMD - $ - 1 ; to GOCMD
             DB      "RETURN"
-            DB      0xbd            ; to RETURN
+            DB      0x80 + RETURN - $ - 1 ; to RETURN
             DB      "REM"
-            DB      0xcf            ; to REMCMD
+            DB      0x80 + REMCMD - $ - 1 ; to REMCMD
+            DB      "UNTIL"
+            DB      0x80 + UNTIL - $ - 1 ; to UNTIL
+            DB      "IF"
+            DB      0x80 + IFCMD - $ - 1 ; to IFCMD
+            DB      "LINK"
+            DB      0x80 + LINK - $ - 1 ; to LINK
             DB      0x80            ; default case to EXEC2
 
 EXEC2:      PLI     P3, =CMDTB7     ; load table 7
@@ -508,22 +539,43 @@
 ;---------------------------------------------------------------
 ; handle GOTO or GOSUB
 GOCMD:      PLI     P3, =CMDTB5     ; check for TO or SUB
+	    LD	    EA, P2
+	    ST	    EA, TMPFGO	    ; save for later use
             CALL    11
 
 CMDTB5:     DB      "TO"
-            DB      0x85            ; to GOTO
+;            DB      0x85            ; to GOTO
+            DB      0x80 + GOTOX - $ - 1 ; to GOTOX
             DB      "SUB"
-            DB      0x8d
+;            DB      0x8d
+            DB      0x80 + GOSUB - $ - 1 ; to GOSUB
             DB      0x80            ; default case to GOTO
 
 ;---------------------------------------------------------------
 ; GOTO command
+; Note: should come just after "GO TO" sequence.
 GOTOX       CALL    0               ; RELEXP
 GOTO:       LD      A, =1           ;
             ST      A, INPMOD       ; set 'running mode'
             JSR     FINDLN          ; find line in buffer
-            BZ      RUN4            ; skip to line number check
-            CALL    15              ; error    
+;            BNZ      RUN4          ; skip to line number check
+            BNZ     GOTOERR 	    ; skip to line number check
+	    PUSH    P3
+	    LD	    EA,TMPFGO
+	    SUB	    EA, =2
+	    LD	    P3, EA
+	    LD	    A,=0x80	    ; internal code "GOTO"
+	    ST	    A,@1,P3
+	    LD	    EA,P2
+	    ST	    A,@1,P3
+	    LD	    A, E
+	    ST	    A,@1,P3
+	    LD	    A,=0x20	    ; 'SPACE'
+	    ST	    A,@1,P3
+	    POP	    P3
+	    JMP    RUN4
+
+GOTOERR:    CALL    15              ; error    
             DB      7               ; 7 (goto target does not exist)    
 
 ;---------------------------------------------------------------
@@ -600,13 +653,17 @@
 
 ;---------------------------------------------------------------
 CMDTB7:     DB      "FOR"
-            DB      0xe4            ; to FOR
+;            DB      0xe4            ; to FOR
+            DB      0x80 + FOR - $ - 1 ; to FOR
             DB      "DO"
-            DB      0xa7            ; to DO
+;            DB      0xa7            ; to DO
+            DB      0xa0 + DO - $ - 1 ; to DO
             DB      "ON"
-            DB      0x8f            ; to ON
+;            DB      0x8f            ; to ON
+            DB      0x80 + ON - $ - 1 ; to ON
             DB      "CLEAR"
-            DB      0x85            ; to CLEAR
+;            DB      0x85            ; to CLEAR
+            DB      0x80 + CLEAR - $ - 1 ; to CLEAR
             DB      0x80            ; to EXEC3
 
 ;---------------------------------------------------------------
@@ -878,20 +935,28 @@
 ;---------------------------------------------------------------
 ; several more commands
 CMDTB8:     DB      "DELAY"
-            DB      0xa4            ; to DELAY
+;            DB      0xa4            ; to DELAY
+            DB      0x80 + DELAY - $ - 1 ; to DELAY
             DB      "INPUT"
-            DB      0x98            ; to INPUT
+;            DB      0x98            ; to INPUT
+            DB      0x80 + INPUT - $ - 1 ; to INPUT
             DB      "PRINT"
-            DB      0x95            ; to PRINT
+;            DB      0x95            ; to PRINT
+            DB      0x80 + PRINT - $ - 1 ; to PRINT
             DB      "PR"
-            DB      0x92            ; to PRINT
+;            DB      0x92            ; to PRINT
+            DB      0x80 + PRINT - $ - 1 ; to PRINT
             DB      "STOP"
-            DB      0x9b            ; to STOP
+;            DB      0x9b            ; to STOP
+            DB      0x80 + STOP - $ - 1 ; to STOP
             DB      "MON"
-            DB      0x9a            ; to MON
+;            DB      0x9a            ; to MON
+            DB      0x80 + MON - $ - 1 ; to MON
             DB      "PUTC"
-            DB      0x98            ; to PRINTCHR
-            DB      0xa4            ; default to ASSIGN
+;            DB      0x98            ; to PRINTCHR
+            DB      0x80 + PRINTCHR - $ - 1 ; to PRINTCHR
+;            DB      0xa4            ; default to ASSIGN
+            DB      0x80 + ASSIGN - $ - 1 ; default to ASSIGN
 
 ;---------------------------------------------------------------
 ; INPUT cmd
@@ -926,12 +991,16 @@
 ;---------------------------------------------------------------
 ; left hand side (LHS) operators for assigment
 CMDTB4:     DB      'S','T','A','T'
-            DB      0x89            ; to STATLH
+;            DB      0x89            ; to STATLH
+            DB      0x80 + STATLH - $ - 1 ; to STATLH
             DB      '@'
-            DB      0x92            ; to ATLH
+;            DB      0x92            ; to ATLH
+            DB      0x80 + ATLH - $ - 1 ; to ATLH
             DB      '$'
+;            DB      0xb1            ; to DOLALH
             DB      0xb1            ; to DOLALH
-            DB      0x9e            ; default case to ASSIG1   
+;            DB      0x9e            ; default case to ASSIG1   
+            DB      0x80 + ASSIG1 - $ - 1 ; default case to ASSIG1   
 
 ;---------------------------------------------------------------
 ; handle assignments
@@ -1144,6 +1213,40 @@
             BP      PRTLN           ; if positive, loop
 PRTLN1      RET                     ; exit
 ;---------------------------------------------------------------
+; print string pointed to by P2, until CR
+PRTLNL:     LD      A, @1, P2       ; get next char from buffer
+            XOR     A, =CR          ; is CR?
+            BZ      PRTLN1          ; yes exit
+            XOR     A, =CR          ; make original char again
+	    BP	    PRTLNL2	    ; IF bit8 = 0 then output as it is
+;
+PRTLNL5:    AND	    A,=0x7f	    ; reset first bits
+	    XCH     E,A
+	    LD	    A,=0x00	    ; SIGN Extend A to EA
+	    XCH	    E,A
+	    SL	    EA		    ;
+	    ST	    EA,TMPFGO
+	    SL	    EA		    ;
+	    ADD	    EA,TMPFGO    ; EA = EA * 6
+	    PUSH	P3
+	    ST	    EA,TMPFGO
+	    LD		EA,=CODENAMES
+	    ADD	    EA,TMPFGO
+	    LD	    P3,EA
+PRTLNL3:    LD	    A,@1,P3
+	    BZ	    PRTLNL4
+	    CALL    7
+	    BRA	    PRTLNL3
+;
+PRTLNL4:    POP	P3
+	    XCH	    P2,EA
+	    ADD	    EA,=2           ; SKIP 2byte
+	    XCH	    P2,EA
+PRTLNL2:    CALL    7               ; PUTC emit it
+            BP      PRTLNL          ; if positive, loop
+PRTLNL1:    RET                     ; exit
+;
+;---------------------------------------------------------------
 ; get next char from buffer
 GETNXC:     LD      A, @1, P2       ; advance P2
 ;---------------------------------------------------------------
@@ -1504,7 +1607,8 @@
 ;---------------------------------------------------------------
 ; FACTOR    (call 1) get a factor: number, var, function, (RELEXP)
 FACTOR:     CALL    13              ; NUMBER get number in sequence
-            DB      2               ; if not found continue at FACTO2
+;            DB      2               ; if not found continue at FACTO2
+            DB      FACTO2 - $      ; if not found continue at FACTO2
 FACTO1:     RET                     ; has numeric operand on stack, done
 
 FACTO2:     PLI     P3, =CMDT12     ; load table of standard functions
@@ -2205,7 +2309,14 @@
 ;            DW      0x00d5         ; for 300 bd
 ;            DW      0x0252         ; for 110 bd
 ;
-             ORG	0xc00
+CODENAMES:   DB	     "GO TO",0
+	     DB	     "GOSUB",0
+	     DB	     "PRINT",0
+	     DB	     "UNTIL",0
+
+
+; *********** FROM THIS LINE AND BELOW ARE are UNIMON SOURCE ******************
+             ORG	0x1000
 ; unimon
 RAM_B:       EQU	0xb800			; last area would be consumed by stack.
 WORK_B:      EQU	0xbbc0

 

NIBL on SC/MP-III 改造 (続き1)

ちょっと現在のボードはお休みにして NIBL の改造の方を見ていました。浮動小数点の方はちょっと後回しで、まず NIBL が遅い原因である GOTO 処理をどうするかですが、毎回先頭からバイトサーチしているのが遅いので、いくつか案を考えていました

  1. 中間言語化してしまい、細工する。
    変更量が大きすぎるので止め。
  2. 行番号の直後に次の行のポインタを入れてサーチの負荷を軽くする
    これはそこそこ検討していたのですが、新規行を既存行の間に差し込む際の処理が面倒なので取りやめ。
  3. 実行時のJIT風に最初の一回の処理時に中間言語に書き換える。
    今回はこれを採用。

結果としては、インタープリタの先頭に中間言語 (0x80 - 0xff) のパーザ、GOTO 処理の改造、LIST処理の改造です。中間言語のコマンドに 0x10あたりを使うと改造が少なかったりするのですが、浮動小数点改造の関係である程度コマンド数を確保しようという方向です。
問題点としては、いっぺん実行した後行の挿入を行うと動かなくなる、ですが今回は目的上目を瞑る方向です。 ちゃんとやるなら行差し込み処理でもとに戻す処理を追加かな。
以下ソースも今調整中。

--- scmp3_nibl-SBC-240326.asm	2025-04-26 22:44:51.000000000 +0900
+++ scmp3_nibl-SBC.asm	2025-04-29 18:26:48.141270013 +0900
@@ -73,7 +73,7 @@
 RNDNUM: EQU       0xfff4      ; DW rnd number
 
 TMPF6: EQU        0xfff6      ; DB,DW temporary
-UNUSE1: EQU       0xfff8      ; DW unused
+TMPFGO: EQU       0xfff8      ; DW temporary used fotr GOTO parsing
 TMPFB: EQU        0xfffb      ; DB,DW temporary
 TMPFC: EQU        0xfffc      ; DB,DW temporary (overlaps TMPFB)
 TMPFE: EQU        0xfffe      ; DW temporary, alias
@@ -309,7 +309,28 @@
 DIRECT:     LD      A, 0, P2        ; get char from buffer
             XOR     A, =CR          ; is it a CR?
             BZ      MAINL7          ; yes, continue in main loop
-            PLI     P3, =CMDTB1      ; load first CMD table
+; ADDED for FAST GOTO by efialtes_htn
+	    AND	    A,=0x80	    ; is bit8=1 then internal codes.
+	    BZ	    DIRECT6	    ; not internal -- RAW code.
+; internal code parser
+; 0x80:	GO TO -- 0x80, NADDRL, NADDRH, 0x20[, 0x20]*
+;
+	    LD	    A, @1, P2	    ; restore from buffer and increment pointer
+	    XOR	    A, =0x80	    ; GOTO
+	    BNZ	    ICODEP1
+	    LD	    A, =1, P2	    ; UPPER
+	    LD	    E,A
+	    LD	    A, =0, P1	    ; LOWER
+	    LD	    P2,EA
+	    CALL    6		    ; ENDCMD
+;
+ICODEP1:
+ICODEPE:
+            CALL    15               ; ERROR
+	    DB	    1
+; end ADDED
+
+DIRECT6:    PLI     P3, =CMDTB1      ; load first CMD table
             CALL    11              ; CMPTOK
 
 ; out of memory error
@@ -366,14 +387,19 @@
 ;-----------------------------------------------------------------------------------
 ; set of DIRECT commands
 CMDTB1:     DB      "LIST"
-            DB      0x93            ; to LIST
+;            DB      0x93           ; to LIST
+            DB      0x80 + LIST - $ - 1 ; to LIST
             DB      "NEW"
-            DB      0x8a            ; to NEW2
+;            DB      0x8a            ; to NEW2
+            DB      0x80 + NEW2 - $ - 1 ; to NEW2
             DB      "RUN"
-            DB      0xb5            ; to RUN
+;            DB      0xb5            ; to RUN
+            DB      0x80 + RUN - $ - 1  ; to RUN
             DB      "CONT"
-            DB      0xa7            ; to CONT
-            DB      0xd2            ; default case to EXEC1
+;            DB      0xa7            ; to CONT
+            DB      0x80 + CONT - $ - 1 ; to CONT
+;            DB      0xd2            ; default case to EXEC1
+            DB      0x80 + EXEC1 - $ - 1 ; default case to EXEC1
 
 ;-----------------------------------------------------------------------------------
 ; NEW command
@@ -397,7 +423,8 @@
             DB      0x0a            ; if error, goto LIST3
             CALL    5               ; APULL
             POP     P2    
-            CALL    14              ; PRTLN
+;            CALL    14              ; PRTLN
+            JSR	    PRTLNL	    ; PRTLNL
             CALL    8               ; CRLF
             JSR     CHKBRK          ; test break
             BRA     LIST2
@@ -477,21 +504,21 @@
             BRA     GOSUB1          ; jump into GOSUB (process interrupt)
 
 CMDTB2:     DB      "LET"
-            DB      0xa6            ; to LET
-            DB      "IF"
-            DB      0xf3            ; to IFCMD
-            DB      "LINK"
-            DB      0xf7            ; to LINK
+            DB      0x80 + LET - $ - 1 ; to LET
             DB      "NEXT"
-            DB      0x9c            ; to NEXT
-            DB      "UNTIL"
-            DB      0xdb            ; to UNTIL
+            DB      0x80 + NEXT - $ - 1 ; to NEXT
             DB      "GO"
-            DB      0x96            ; to GOCMD
+            DB      0x80 + GOCMD - $ - 1 ; to GOCMD
             DB      "RETURN"
-            DB      0xbd            ; to RETURN
+            DB      0x80 + RETURN - $ - 1 ; to RETURN
             DB      "REM"
-            DB      0xcf            ; to REMCMD
+            DB      0x80 + REMCMD - $ - 1 ; to REMCMD
+            DB      "UNTIL"
+            DB      0x80 + UNTIL - $ - 1 ; to UNTIL
+            DB      "IF"
+            DB      0x80 + IFCMD - $ - 1 ; to IFCMD
+            DB      "LINK"
+            DB      0x80 + LINK - $ - 1 ; to LINK
             DB      0x80            ; default case to EXEC2
 
 EXEC2:      PLI     P3, =CMDTB7     ; load table 7
@@ -508,22 +535,43 @@
 ;---------------------------------------------------------------
 ; handle GOTO or GOSUB
 GOCMD:      PLI     P3, =CMDTB5     ; check for TO or SUB
+	    LD	    EA, P2
+	    ST	    EA, TMPFGO	    ; save for later use
             CALL    11
 
 CMDTB5:     DB      "TO"
-            DB      0x85            ; to GOTO
+;            DB      0x85            ; to GOTO
+            DB      0x80 + GOTOX - $ - 1 ; to GOTOX
             DB      "SUB"
-            DB      0x8d
+;            DB      0x8d
+            DB      0x80 + GOSUB - $ - 1 ; to GOSUB
             DB      0x80            ; default case to GOTO
 
 ;---------------------------------------------------------------
 ; GOTO command
+; Note: should come just after "GO TO" sequence.
 GOTOX       CALL    0               ; RELEXP
 GOTO:       LD      A, =1           ;
             ST      A, INPMOD       ; set 'running mode'
             JSR     FINDLN          ; find line in buffer
-            BZ      RUN4            ; skip to line number check
-            CALL    15              ; error    
+;            BNZ      RUN4          ; skip to line number check
+            BNZ     GOTOERR 	    ; skip to line number check
+	    PUSH    P3
+	    LD	    EA,TMPFGO
+	    SUB	    EA, =2
+	    LD	    P3, EA
+	    LD	    A,=0x80	    ; internal code "GOTO"
+	    ST	    A,@1,P3
+	    LD	    EA,P2
+	    ST	    A,@1,P3
+	    LD	    A, E
+	    ST	    A,@1,P3
+	    LD	    A,=0x20	    ; 'SPACE'
+	    ST	    A,@1,P3
+	    POP	    P3
+	    JMP    RUN4
+
+GOTOERR:    CALL    15              ; error    
             DB      7               ; 7 (goto target does not exist)    
 
 ;---------------------------------------------------------------

@@ -1144,6 +1209,42 @@
             BP      PRTLN           ; if positive, loop
 PRTLN1      RET                     ; exit
 ;---------------------------------------------------------------
+; print string pointed to by P2, until char has bit 7 is set or is CR
+PRTLNL:     LD      A, @1, P2       ; get next char from buffer
+            XOR     A, =CR          ; is CR?
+            BZ      PRTLNL1          ; yes exit
+            XOR     A, =CR          ; make original char again
+	    PUSH    A		    ; SAVE
+	    AND	    A,=0x80	    ; if character > 0x80
+	    POP     A
+	    BZ	    PRTLNL2
+	    AND	    A,=0x7f	    ; reset first bits
+	    PUSH    A
+	    LD	    A,=0x00	    ; SIGN Extend A to EA
+	    LD	    E,A
+	    POP	    A
+	    ST	    EA,TMPFGO
+	    SL	    EA		    ;
+	    SL	    EA		    ;
+	    ADD	    EA,TMPFGO    ; EA = EA * 5
+	    PLI	    P3,=CODENAMES
+	    LD	    P3,EA
+	    LD	    A,=5
+PRTLNL3:    PUSH    A
+	    LD	    A,@1,P3
+	    AND	    A,=0x7f	    ; IF 0 then finish
+	    BZ	    PRTLNL4
+	    CALL    7
+	    POP     A
+	    SUB     A,=1	    ; at most 5 chars.
+	    BNZ	    PRTLNL3
+PRTLNL4:    POP	    P3
+	    RET
+;
+PRTLNL2:    CALL    7               ; PUTC emit it
+            BP      PRTLNL          ; if positive, loop
+PRTLNL1:    RET                     ; exit
+;---------------------------------------------------------------
 ; get next char from buffer
 GETNXC:     LD      A, @1, P2       ; advance P2
 ;---------------------------------------------------------------
@@ -2205,7 +2306,14 @@
 ;            DW      0x00d5         ; for 300 bd
 ;            DW      0x0252         ; for 110 bd
 ;
-             ORG	0xc00
+CODENAMES:   DB	     "GO TO"
+	     DB	     "GOSUB"
+	     DB	     "PRINT"
+	     DB	     "UNTIL"
+
+
+; *********** FROM THIS LINE AND BELOW ARE are UNIMON SOURCE ******************
+             ORG	0x1000
 ; unimon
 RAM_B:       EQU	0xb800			; last area would be consumed by stack.
 WORK_B:      EQU	0xbbc0

78K/3 SBC制作(3)

とりあえず 78K/3 のほうも LED Blink までは OKになりました。原因は Bluesky のほうでちょっと触れた通り /RFSH が Z80 に似た信号と勘違いしていたため。実際は RESET 直後からずっと出っぱなし、なので RFSH 期間中はメモリの読み出し禁止、としていた関係でメモリが全く読めず、でした。

でも、この角度だと IC パッケージの印字が全く見えません。

LED BLINK

とりあえず、GALの論理は貼っておきます。

  1:Name            DEC78K3;
  2:Partno          KF010004;
  3:Date            25/03/30;
  4:Revision        03;
  5:Designer        efialtes_htn;
  6:Company         EFIALTES_HTN Design;
  7:Assembly        System 19-8 uPD78310A;
  8:Location        U06;
  9:Device          G16V8;
 10:
 11:/* *************************************************************** */
 12:/* System 19-8 decorder Glue logic                                 */
 13:/*                                                                 */
 14:/* *************************************************************** */
 15:/* target device        GAL18V8 any speed rank is OK               */
 16:/* *************************************************************** */
 17:/* *************************************************************** */
 18:/** inputs      **/
 19:Pin 14  =       ALE;
 20:Pin 1   =       !RD;
 21:Pin 2   =       !WR;
 22:Pin 3   =       !RFSH;
 23:Pin 4  =        A15;
 24:Pin 5  =        A14;
 25:Pin 6   =       A13;
 26:Pin 7   =       A12;
 27:Pin 8   =       A11;
 28:Pin 9   =       A10;
 29:Pin 11  =       A9;
 30:Pin 17  =       A8;
 31:Pin 13  =       A7;
 32:
 33:/** outputs     **/
 34:Pin 19  =       !IDXEN; 
 35:Pin 15  =       !MRD;
 36:Pin 12  =       !MWE;
 37:Pin 16  =       !RAMEN; 
 38:Pin 18  =       !ROMEN; 
 39:
 40:/* logic equations      */
 41:ROMEN   = !A15 & !A14 & !ALE;
 42:RAMEN   = (!ALE & !A15 & A14) # (!ALE & A15 & !A14);
 43:MRD     = RD;
 44:MWE     = WR;
 45:/* IO read/write */
 46:IDXEN   = A15 & A14 & A13 & A12 & A11 & A10 & !A9 & A8 & A7 & !ALE;
 47:
 48:ROMEN.oe = 'b'1;
 49:RAMEN.oe = 'b'1;
 50:MRD.oe = 'b'1;
 51:MWE.oe = 'b'1;
 52:IDXEN.oe = 'b'1;

 

TLCS-90SBC制作(4)

とりあえず Unimon までは OK、っと。こちらは asano さんに感謝。78K/3 は何にもないのでこれからです。

        
diff -aruN ../unimon/unimon-20241231/tlcs90/config/config.inc tlcs90/config/config.inc
--- ../unimon/unimon-20241231/tlcs90/config/config.inc	2020-11-29 16:55:53.000000000 +0900
+++ tlcs90/config/config.inc	2025-01-31 22:50:13.000000000 +0900
@@ -9,8 +9,8 @@
 
 ENTRY:	EQU	0080H		; Entry point
 	
-WORK_B:	equ	0EF00H
-STACK:	equ	0EFEFH
+WORK_B:	equ	0BF00H
+STACK:	equ	0BFFFH
 
 BUFLEN:	equ	16
 
@@ -23,24 +23,26 @@
 USE_REGCMD = 1			; R(egister) command and related functions
 
 	;; Port 4 Control Register
-P4CR_V:	EQU	0FH		; Port 4 : Output A16-A19
+P4CR_V:	EQU	01H		; Port 4 : Output A16 only. 
+				; bit 1..3 : output port
 	
 ;;;
 ;;; Toshiba TLCS-90 internal
 ;;;
 	
 USE_DEV_TLCS90 = 1
-	IF USE_DEV_TLCS90
-
-	;; Serial Channel Mode Register
-SCMOD_V:EQU	3BH		;     8bit, BRG/2
-
-	;; Timer/Serial Channel Operation Control Register
-TRUN_V:	EQU	0E0H		;     19200/9600bps
-
-	;; Port 3 Control Register
-P3CR_V:	EQU	4AH		;     Normal wait, TxD,RxD
+USE_DEV_TLCS90SBC = 1
 
+	IF USE_DEV_TLCS90
+;P4CR_V:	EQU	01H
+P4_V:	EQU	00H
+TREG2_V:EQU	05H			; Timer 2 Value = 19200bps x 16 x 8 x 5 = 12.288MHz
+TMOD_V:	EQU	00H			; All 8bit timer
+TCLK_V:	EQU	55H			; ALL counter sources are PHIT1
+TRUN_V:	EQU	24H			; Timer2 count, all other timers are disabled
+SCMOD_V:EQU	38H			; 8bit, To2TRG
+SCCR_V:	EQU	00H			; noparity, CTS disable 
+P3CR_V:	EQU	46H			;     Normal wait, TxD,RxD
 	ENDIF
 
 ;;;
diff -aruN ../unimon/unimon-20241231/tlcs90/dev/dev_tlcs90.asm tlcs90/dev/dev_tlcs90.asm
--- ../unimon/unimon-20241231/tlcs90/dev/dev_tlcs90.asm	2019-09-25 13:34:47.000000000 +0900
+++ tlcs90/dev/dev_tlcs90.asm	2025-01-19 16:51:49.000000000 +0900
@@ -4,18 +4,43 @@
 
 
 INIT:
+	IF USE_DEV_TLCS90SBC
+	;; Reset PORTS
+	XOR	A,A
+	LD	(P4),A
+	LD	(BXADR),A
+	LD	(BYADR),A
+	LD	(P4CR),P4CR_V
+
+	;; TIMER2 setup
+	LD	(TMOD),TMOD_V
+	LD	(TREG2),TREG2_V
+	LD	(TCLK),TCLK_V
+	LD	(TRUN),TRUN_V
+	
+	NOP
+	NOP
+	NOP
+	
 	;; Reset USART
+	LD	(SCMOD),SCMOD_V
+	LD	(SCCR),SCCR_V
+	LD	(TRUN),TRUN_V
+	LD	(P3CR),P3CR_V
+	
+	ELSEIF
 	LD	A,SCMOD_V
 	LD	(SCMOD),A
 	LD	A,TRUN_V
 	LD	(TRUN),A
 	LD	A,P3CR_V
 	LD	(P3CR),A
-
+	ENDIF
+	
 	;; Write dummy (to set IRFTX)
 	XOR	A,A
 	LD	(SCBUF),A
-	
+
 	RET
 
 CONIN:
diff -aruN ../unimon/unimon-20241231/tlcs90/tlcs90.inc tlcs90/tlcs90.inc
--- ../unimon/unimon-20241231/tlcs90/tlcs90.inc	2020-11-29 16:55:53.000000000 +0900
+++ tlcs90/tlcs90.inc	2025-01-19 16:45:05.000000000 +0900
@@ -5,12 +5,22 @@
 
 IRFH:	EQU	0FFC3H		; Interrupt Request Flip-Flop
 P3CR:	EQU	0FFC7H		; Port 3 Control Register
+P4:		EQU	0FFC8H		; Port 4 Data Register
 P4CR:	EQU	0FFC9H		; Port 4 Control Register
+BX:		EQU	0FFECH		; BX register
+BY:		EQU	0FFECH		; BY register
 WDMOD:	EQU	0FFD2H		; Watchdog Timer Mode Register
 WDCR:	EQU	0FFD3H		; Watchdog Timer Control Register
 SCMOD:	EQU	0FFE9H		; Serial Channel Mode Register
 SCCR:	EQU	0FFEAH		; Serial Channel Control Register
 SCBUF:	EQU	0FFEBH		; Serial Transmission/Receiving Buffer Register
-BX:	EQU	0FFECH		; Bank Register BX
-BY:	EQU	0FFEDH		; Bank Register BY
+BXADR:	EQU	0FFECH		; Bank Register BX
+BYADR:	EQU	0FFEDH		; Bank Register BY
+TREG0:	EQU	0FFD4H		; Timer Data Register 0
+TREG1:	EQU	0FFD5H		; Timer Data Register 1
+TREG2:	EQU	0FFD6H		; Timer Data Register 2
+TREG3:	EQU	0FFD7H		; Timer Data Register 3
+TCLK:	EQU	0FFD8H		; Timer Clock Control Register
+TFFCR:	EQU	0FFD9H		; Timer/Serial Channel Operation Control Register
+TMOD:	EQU	0FFDAH		; Timer/Serial Channel Operation Control Register
 TRUN:	EQU	0FFDBH		; Timer/Serial Channel Operation Control Register
diff -aruN ../unimon/unimon-20241231/tlcs90/unimon_tlcs90.asm tlcs90/unimon_tlcs90.asm
--- ../unimon/unimon-20241231/tlcs90/unimon_tlcs90.asm	2020-11-29 16:55:53.000000000 +0900
+++ tlcs90/unimon_tlcs90.asm	2025-01-03 17:56:56.000000000 +0900
@@ -5,7 +5,7 @@
 
 	CPU	90c141
 
-TARGET:	equ	"90C802"
+TARGET:	equ	"90C840"
 
 
 	INCLUDE	"config.inc"

    

 

TLCS-90SBC制作(3)

こちらの方はシリアルが動かなくて色々調べていたんですけど、unimon の期待しているのと TxD ピンのアサインが違うのが判明。unimon はP3CR制御レジスタに 4AHを書いていて、、、

これだとP33側が TxDになるんですけど、実際の回路は

P32側に TxDを期待していると。

こちらの方は週末にROMを直して再チャレンジです。

78K/3 SBC制作(2)

M51953A は買ってきました。M51943B は何個か出てきたので、以前に誤って買ったもののようです。

リセットはちゃんと解除されて、走り出しました。いま命令セットを眺めているところですが、思っていた以上に 78K でなく 8080/Z80 寄りに近い。

  • フラグ付き分岐が普通にある。逆にスキップはない。流石に条件付きCALL/RETはないけど。
  • Aだけ優遇されているがとりあえずレジスタ間の転送制限はない、は語弊があるな。R0-7 まではない。R8-15 は R0-7 としか転送できない。R8-15 はレジスタペアとしては自由にワード転送できるのでワードとして使え、ということになります。
  • BC優先。逆に DE/HL はレジスタペアとして使うようかなり特化。
  • Z80 のようなビット系命令、転送命令などがある。
  • レジスタがメモリマップされている。

ASのサポートはあるのですが、どのぐらい動くかな。まず LED Blink です。

78K/3 SBC制作(1)

78K3 の方も組み立てては見たのですが、全く動かないというかリセットがかかりっぱなし。理由を調べたところ、M51953A ではなく、M51943B が取り付けられていることが判明。後者の方はオープンコレクタ出力なので、ハイインピーダンスではあるけど最初 LOW に引くので、ロジックとしては '0' になりますな、、、

うーん、M51943B なんて買った覚えがないのだが……

このままだとリセットスイッチが繋がらないので、交換するしかないです。少し部品箱漁っても M51953A が出てこないので、とりあえず若松通商に注文かけました。再着手は再来週かなぁ。