Annotation of nono/exp/optestxp/subr.asm, revision 1.1

1.1     ! root        1: ; vi:set ts=8:
        !             2: 
        !             3: ;
        !             4: ; nono
        !             5: ; Copyright (C) 2023 nono project
        !             6: ; Licensed under nono-license.txt
        !             7: ;
        !             8: 
        !             9: ; テストのサブルーチン。
        !            10: ; 分割アセンブルが出来ないので cat で後ろに追加する。
        !            11: 
        !            12: ; 文字列をメイン側に送る。
        !            13: ; HL に出力する文字列の先頭番地。文字列は '$' で終端。
        !            14: ; 文字 '^Z'(0x1a) を出力した時点でプログラムを終了。
        !            15: ; ホスト側の終了指示も兼ねているのでこの文字自体は送る。
        !            16: puts:
        !            17:        PUSH    AF
        !            18:        PUSH    BC
        !            19:        PUSH    DE
        !            20:        PUSH    HL
        !            21:        EX      DE,HL
        !            22:        LD      C,09H
        !            23:        CALL    0005H
        !            24:        POP     HL
        !            25:        POP     DE
        !            26:        POP     BC
        !            27:        POP     AF
        !            28:        RET
        !            29: 
        !            30: ; A レジスタの内容を16進数2文字にして (HL) に書き出す
        !            31: ; Inp: A:  変換したいバイト
        !            32: ;      HL: 出力先バッファ
        !            33: ; Out: HL: 入力 +2 され、ここは '\0' が書き出してある。
        !            34: ; Use: -
        !            35: strhex_byte:
        !            36:        PUSH    AF
        !            37:        PUSH    BC
        !            38:        LD      B,A             ; Backup A
        !            39:        SRL     A
        !            40:        SRL     A
        !            41:        SRL     A
        !            42:        SRL     A               ; A >>= 4
        !            43:        CALL    strhex_1
        !            44:        LD      A,B
        !            45:        AND     0FH
        !            46:        CALL    strhex_1
        !            47:        LD      (HL),'$'
        !            48:        POP     BC
        !            49:        POP     AF
        !            50:        RET
        !            51: strhex_1:
        !            52:        CP      0AH
        !            53:        JR      C,_sh_2
        !            54:        ADD     A,7H
        !            55: _sh_2:
        !            56:        ADD     A,30H
        !            57:        LD      (HL),A
        !            58:        INC     HL
        !            59:        RET
        !            60: 
        !            61: ; A レジスタの内容を16進数2文字にして出力する。
        !            62: puts_byte:
        !            63:        PUSH    AF
        !            64:        PUSH    HL
        !            65:        LD      HL,_puts_byte_buf
        !            66:        CALL    strhex_byte
        !            67:        LD      HL,_puts_byte_buf
        !            68:        CALL    puts
        !            69:        POP     HL
        !            70:        POP     AF
        !            71:        RET
        !            72: 
        !            73: _puts_byte_buf:
        !            74:        defs    4
        !            75: 
        !            76: ; 単項演算のテストの共通部分。
        !            77: ; IN: HL テストセットの先頭番地
        !            78: ; (HL + 0).W : テスト名のポインタ
        !            79: ; (HL + 2).W : 実行コード
        !            80: ; (HL + 4).W : テストデータの先頭
        !            81: ; OUT: -
        !            82: ; USE: all
        !            83: testrun1:
        !            84:        LD      DE,testname
        !            85:        LD      BC,0006H
        !            86:        LDIR
        !            87: 
        !            88:        LD      HL,(testname)
        !            89:        CALL    puts
        !            90:        LD      IX,(testdata)
        !            91:        XOR     A
        !            92:        LD      (testpos),A
        !            93:        LD      (failcount),A
        !            94: _testrun1_loop:
        !            95:        LD      HL,(total_count)
        !            96:        INC     HL
        !            97:        LD      (total_count),HL
        !            98:        LD      D,(IX+0)
        !            99:        LD      E,(IX+1)
        !           100:        PUSH    DE
        !           101:        POP     AF
        !           102: 
        !           103:        LD      HL,_testrun1_back
        !           104:        PUSH    HL              ; 戻りアドレス
        !           105:        LD      HL,(testexec)
        !           106:        JP      (HL)            ; CALL testexec
        !           107: _testrun1_back:
        !           108:        PUSH    AF
        !           109:        POP     DE
        !           110:        LD      A,(IX+2)
        !           111:        CP      D
        !           112:        JR      Z,_testrun1_cmp_f
        !           113:        CALL    fail_a
        !           114:        JR      _testrun1_next
        !           115: _testrun1_cmp_f:
        !           116:        LD      A,(IX+3)
        !           117:        CP      E
        !           118:        JR      Z,_testrun1_next
        !           119:        CALL    fail_f
        !           120: _testrun1_next:
        !           121:        LD      DE,0004H
        !           122:        ADD     IX,DE
        !           123:        LD      A,(testpos)
        !           124:        INC     A
        !           125:        LD      (testpos),A
        !           126: 
        !           127:        LD      A,(IX+3)        ; expflag が 0xff なら終了
        !           128:        CP      0FFH
        !           129:        JR      NZ,_testrun1_loop
        !           130: 
        !           131:        LD      A,(failcount)
        !           132:        OR      A
        !           133:        RET     NZ
        !           134:        LD      HL,msg_ok
        !           135:        CALL    puts
        !           136:        RET
        !           137: 
        !           138: ; A レジスタの結果が異なるのでメッセージを表示
        !           139: fail_a:
        !           140:        LD      HL,(testname)
        !           141:        CALL    puts
        !           142:        PUSH    AF
        !           143:        LD      A,(testpos)
        !           144:        CALL    puts_byte
        !           145:        POP     AF
        !           146:        LD      HL,msg_dst_expects
        !           147:        CALL    puts
        !           148:        CALL    puts_byte
        !           149:        LD      HL,msg_but
        !           150:        CALL    puts
        !           151:        LD      A,D
        !           152:        CALL    puts_byte
        !           153:        LD      HL,msg_eol
        !           154:        CALL    puts
        !           155:        LD      A,(failcount)
        !           156:        INC     A
        !           157:        LD      (failcount),A
        !           158:        RET
        !           159: 
        !           160: ; F レジスタの結果が異なるのでメッセージを表示
        !           161: fail_f:
        !           162:        LD      HL,(testname)
        !           163:        CALL    puts
        !           164:        PUSH    AF
        !           165:        LD      A,(testpos)
        !           166:        CALL    puts_byte
        !           167:        POP     AF
        !           168:        LD      HL,msg_f_expects
        !           169:        CALL    puts
        !           170:        CALL    puts_byte
        !           171:        LD      HL,msg_but
        !           172:        CALL    puts
        !           173:        LD      A,E
        !           174:        CALL    puts_byte
        !           175:        LD      HL,msg_eol
        !           176:        CALL    puts
        !           177:        LD      A,(failcount)
        !           178:        INC     A
        !           179:        LD      (failcount),A
        !           180:        RET
        !           181: 
        !           182: ; 2項演算のテストの共通部分。
        !           183: ; IN: HL テストセットの先頭番地
        !           184: ; (HL + 0).W : テスト名のポインタ
        !           185: ; (HL + 2).W : 実行コード
        !           186: ; (HL + 4).W : テストデータの先頭
        !           187: ; OUT: -
        !           188: ; USE: all
        !           189: testrun2:
        !           190:        LD      DE,testname
        !           191:        LD      BC,0006H
        !           192:        LDIR
        !           193: 
        !           194:        LD      HL,(testname)
        !           195:        CALL    puts
        !           196:        LD      IX,(testdata)
        !           197:        XOR     A
        !           198:        LD      (testpos),A
        !           199:        LD      (failcount),A
        !           200: _testrun2_loop:
        !           201:        LD      HL,(total_count)
        !           202:        INC     HL
        !           203:        LD      (total_count),HL
        !           204:        LD      D,(IX+0)
        !           205:        LD      E,(IX+1)
        !           206:        PUSH    DE
        !           207:        LD      D,(IX+2)
        !           208:        POP     AF
        !           209: 
        !           210:        LD      HL,_testrun2_back
        !           211:        PUSH    HL              ; 戻りアドレス
        !           212:        LD      HL,(testexec)
        !           213:        JP      (HL)            ; CALL testexec
        !           214: _testrun2_back:
        !           215:        PUSH    AF
        !           216:        POP     DE
        !           217:        LD      A,(IX+3)
        !           218:        CP      D
        !           219:        JR      Z,_testrun2_cmp_f
        !           220:        CALL    fail_a
        !           221:        JR      _testrun2_next
        !           222: _testrun2_cmp_f:
        !           223:        LD      A,(IX+4)
        !           224:        CP      E
        !           225:        JR      Z,_testrun2_next
        !           226:        CALL    fail_f
        !           227: _testrun2_next:
        !           228:        LD      DE,0005H
        !           229:        ADD     IX,DE
        !           230:        LD      A,(testpos)
        !           231:        INC     A
        !           232:        LD      (testpos),A
        !           233: 
        !           234:        LD      A,(IX+4)        ; expflag が 0xff なら終了
        !           235:        CP      0FFH
        !           236:        JR      NZ,_testrun2_loop
        !           237: 
        !           238:        LD      A,(failcount)
        !           239:        OR      A
        !           240:        RET     NZ
        !           241:        LD      HL,msg_ok
        !           242:        CALL    puts
        !           243:        RET
        !           244: 
        !           245: testname:
        !           246:        defw    0000H   ; テスト名のアドレス
        !           247: testexec:
        !           248:        defw    0000H   ; 実行コードサブルーチンのアドレス
        !           249: testdata:
        !           250:        defw    0000H   ; テストデータの先頭番地
        !           251: 
        !           252: 
        !           253: testpos:
        !           254:        defb    0       ; 今のテストの中の何番目か
        !           255: failcount:
        !           256:        defb    0       ; 1セクション中の失敗数
        !           257: total_count:
        !           258:        defw    0       ; テスト実行総数
        !           259: total_fail:
        !           260:        defw    0       ; テスト失敗総数
        !           261: 
        !           262: msg_eol:
        !           263:        defb    '.', 0DH, 0AH, '$'
        !           264: msg_crlf:
        !           265:        defb    0DH, 0AH, '$'
        !           266: msg_ok:
        !           267:        defm    "OK"
        !           268:        defb    0DH, 0AH, '$'
        !           269: msg_dst_expects:
        !           270:        defm    ": A expects $"
        !           271: msg_but:
        !           272:        defm    " but $"
        !           273: msg_f_expects:
        !           274:        defm    ": F expects $"
        !           275: 
        !           276:        defb    0, 0, 0         ; padding for disasm

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.