icl 'library.s' icl 'cio.inc' .macro _ASSERT_YP php cpy #0 bpl ok sty d1 jsr _log_imprintf dta :1,$9B,0 ok: plp .endm .macro _ASSERT_Y php cpy :1 beq ok sty d1 pha txa pha jsr _log_imprintf dta :2,$9B,0 pla tax pla ok: plp .endm .macro _ASSERT_A php cmp :1 beq ok sta d1 pha txa pha jsr _log_imprintf dta :2,$9B,0 pla tax pla ok: plp .endm .macro _ASSERT_YA16 php cpy #>:1 bne fail cmp #<:1 beq ok fail: sty d1 sta d2 txa pha jsr _log_imprintf dta :2,$9B,0 pla tax ok: plp .endm .macro _ASSERT_P bpl ok sty d1 jsr _log_imprintf dta :1,$9B,0 ok: .endm .macro _ASSERT_N bmi ok sty d1 jsr _log_imprintf dta :1,$9B,0 ok: .endm _TEST_ENTRY org $80 opt o- org $2c00 fnbuf: org $2c10 devid dta 0 tstatus dta 0 ioindex dta 0 opt o+ IOCB_OFFSET = $30 ;========================================================================== .proc main ;close IOCB #3, to reset to standard state ldx #IOCB_OFFSET mva #CIOCmdClose iccmd,x jsr ciov ;close an already closed IOCB ldx #IOCB_OFFSET mva #CIOCmdClose iccmd,x jsr ciov _ASSERT_YP 'Reclose status bad: Y=$%x' _ASSERT_P 'Reclose failed: N=1' ;try to find a nonexistent device ;there are only 12 slots, so we are guaranteed that a letter will ;be free ldy #'A' search_loop: tya jsr FindDevice bne unused_found iny bne search_loop unused_found: ;set up filename sty fnbuf ldx #$0f lda #$9B sta:rne fnbuf,x- ;try to open a nonexistent device lda #4 sta icax1+IOCB_OFFSET lda #0 sta icax2+IOCB_OFFSET jsr OpenIO _ASSERT_Y #CIOStatUnkDevice, 'Bogus open didn''''t fail: Y=$%x' _ASSERT_N 'Bogus open didn''''t fail: N=0' ;register device lda #0 jsr FindDevice beq found_space jsr _log_imprint dta 'HATABS full - skipping device tests.',$9B,0 rts found_space: stx devid lda fnbuf sta hatabs,x mwa #TestDevHandlerTable hatabs+1,x ;try to open the device again mva #1 tstatus jsr OpenIO _ASSERT_YP 'Test device open failed: Y=$%x' _ASSERT_P 'Test device open failed: N=1' ;check that device ID is correct ldy devid sty d2 _ASSERT_Y ichid+$30, 'IOCB id didn''''t match: $%x!=$%x' ;check that unit #1 was chosen ldy icdno+$30 _ASSERT_Y #1, 'IOCB device no not 1 for implied: %x' ;try to open again, and verify that we get an IOCB in use error jsr OpenIO _ASSERT_Y #CIOStatIOCBInUse, 'Open reuse didn''''t fail: Y=%x' _ASSERT_N 'Open reuse didn''''t fail: N=0' ;close the IOCB jsr CloseIO ;check that the handler ID is now $FF ldy ichid+$30 _ASSERT_Y #$ff, 'IOCB handler was not $FF after close: %x' ;open x2: and check that unit is #2 lda #'2' sta fnbuf+1 jsr OpenIO _ASSERT_YP 'T2: open failed: Y=%x' ldy icdno+$30 _ASSERT_Y #2, 'x2: open produced wrong unit: %x' jsr CloseIO ;check that x0: is not valid ; ;Note that we don't test x9:, because while it's invalid according ;to the OS manual, the standard OS allows it. ; lda #'0' sta fnbuf+1 jsr OpenIO _ASSERT_YP 'x0: open failed: Y=%x' ldy icdno+$30 _ASSERT_Y #1, 'x0: open produced wrong unit: %x' jsr CloseIO ;check that x20: opens x2: lda #'2' sta fnbuf+1 lda #'0' sta fnbuf+2 jsr OpenIO _ASSERT_YP 'x20: open failed: Y=%x' ldy icdno+$30 _ASSERT_Y #2, 'x20: open produced wrong unit: %x' jsr CloseIO ;-------------------------------- ;permissions tests ;-------------------------------- ;open x1: again with permission 0 - should succeed mva #'1' fnbuf+1 mva #0 icax1+IOCB_OFFSET jsr OpenIO _ASSERT_YP 'x1: reopen failed' ;attempt a GET CHAR -- this should fail with write-only lda #0 tay jsr SetIOLength lda #CIOCmdGetChars jsr DoIO _ASSERT_Y #CIOStatWriteOnly, 'Get from perm 0 test failed: Y=%x' ;attempt a PUT CHAR -- this should fail with read-only lda #0 tay jsr SetIOLength lda #CIOCmdPutChars jsr DoIO _ASSERT_Y #CIOStatReadOnly, 'Put to perm 0 test failed: Y=%x' ;-------------------------------- ;get byte tests ;-------------------------------- ;close IOCB #3 jsr CloseIO ;reopen as read/write mva #$0c icax1+IOCB_OFFSET jsr OpenIO _ASSERT_YP 'x1: reopen#2 failed' ;init get buffer ldx #0 fill_loop: txa sta iobuffer1,x inx bne fill_loop ;start mid-way in the buffer lda #$5a sta ioindex ;do a one-byte fetch lda #$33 sta iobuffer2 lda #0 tay jsr SetIOLength ldy #>iobuffer2 lda #$140 jsr SetIOLength ldy #>iobuffer2+$40 lda #$140 beq len_ok len_bad: sta d2 sty d1 jsr _log_imprintf dta 'Multi-byte get failed: bad result length (%x%x)',$9B,0 len_ok: ;-------------------------------- ;get record tests ;-------------------------------- ;copy string to src buffer ldx #5 mva:rpl message_1,x iobuffer1,x- lda #0 sta ioindex lda #$aa ldx #7 sta:rpl iobuffer2,x- ;issue a get record with plenty of buffer and check that it stops ;at EOL ldy #>iobuffer2 lda #iobuffer2 lda #iobuffer2 lda #$3800 .error 'Buffer overrun' .endif iobuffer1 equ $3800 iobuffer2 equ $3a00