2016-12-15 01:16:55 +00:00
;;; Apple II Language Card audit routines
;;; Copyright © 2016 Zellyn Hunter <zellyn@gmail.com>
2017-04-25 01:06:55 +00:00
! zone langcard {
.checkdata = tmp1
2017-01-06 02:47:49 +00:00
LANGCARDTESTS
2017-01-18 02:44:31 +00:00
lda # 0
sta LCRESULT
2016-12-15 01:16:55 +00:00
lda MEMORY
cmp # 49
2017-01-18 02:44:31 +00:00
bcs LANGCARDTESTS_NO_CHECK
2016-12-15 01:16:55 +00:00
+ print
! text "48K:SKIPPING LANGUAGE CARD TEST" , $ 8 D
+ printed
2017-01-18 02:44:31 +00:00
sec
2017-01-06 02:47:49 +00:00
rts
2017-01-18 02:44:31 +00:00
LANGCARDTESTS_NO_CHECK:
+ print
! text "TESTING LANGUAGE CARD" , $ 8 D
+ printed
2016-12-15 01:16:55 +00:00
;; Setup - store differing values in bank first and second banked areas.
2017-01-18 02:44:31 +00:00
lda $ C08B ; Read and write bank 1
2016-12-15 01:16:55 +00:00
lda $ C08B
2016-12-21 02:26:49 +00:00
lda # $ 11
2016-12-18 01:49:28 +00:00
sta $ D17B ; $D17B is $53 in Apple II/plus/e/enhanced
2016-12-15 01:16:55 +00:00
cmp $ D17B
beq +
2017-01-17 03:45:29 +00:00
+ prerr $ 0004 ;; E0004: We tried to put the language card into read bank 1, write bank 1, but failed to write.
2016-12-15 01:16:55 +00:00
! text "CANNOT WRITE TO LC BANK 1 RAM"
+ prerred
2017-01-18 02:44:31 +00:00
sec
2017-01-06 02:47:49 +00:00
rts
2017-02-24 18:00:31 +00:00
+ lda # $ 33
sta $ FE1F ; FE1F is $60 in Apple II/plus/e/enhanced
2016-12-15 01:16:55 +00:00
cmp $ FE1F
2017-02-24 18:00:31 +00:00
beq +
2017-01-17 03:45:29 +00:00
+ prerr $ 0005 ;; E0005: We tried to put the language card into read RAM, write RAM, but failed to write.
2016-12-15 01:16:55 +00:00
! text "CANNOT WRITE TO LC RAM"
+ prerred
2017-01-18 02:44:31 +00:00
sec
2017-01-06 02:47:49 +00:00
rts
2016-12-18 01:49:28 +00:00
+ lda $ C083 ; Read and write bank 2
2016-12-15 01:16:55 +00:00
lda $ C083
2016-12-21 02:26:49 +00:00
lda # $ 22
2016-12-15 01:16:55 +00:00
sta $ D17B
cmp $ D17B
beq +
2017-01-17 03:45:29 +00:00
+ prerr $ 0006 ;; E0006: We tried to put the language card into read bank 2, write bank 2, but failed to write.
2016-12-15 01:16:55 +00:00
! text "CANNOT WRITE TO LC BANK 2 RAM"
+ prerred
2017-01-18 02:44:31 +00:00
sec
2017-01-06 02:47:49 +00:00
rts
2017-02-24 18:00:31 +00:00
+ lda $ C08B ; Read and write bank 1 with single access (only one needed if banked in already)
lda # $ 11
cmp $ D17B
beq +
+ prerr $ 000 D ;; E000D: We tried to put the language card into read bank 1, but failed to read.
! text "CANNOT READ FROM LC BANK 1 RAM"
+ prerred
sec
rts
+ lda $ C081 ; Read ROM with single access (only one needed to bank out)
lda # $ 53
cmp $ D17B
2017-04-25 01:06:55 +00:00
beq .datadriventests
2017-02-24 18:00:31 +00:00
+ prerr $ 000 E ;; E000E: We tried to put the language card into read ROM, but failed to read.
! text "CANNOT READ FROM ROM"
+ prerred
sec
rts
2016-12-15 03:57:37 +00:00
2017-04-25 01:06:55 +00:00
;;; Main data-driven test. PCL,PCH holds the address of the next
;;; data-driven test routine. We expect the various softswitches
;;; to be reset each time we loop at .ddloop.
.datadriventests
lda # < .tests
sta PCL
2016-12-18 03:06:15 +00:00
lda # > .tests
2017-04-25 01:06:55 +00:00
sta PCH
;;; Main data-drive-test loop.
.ddloop
ldy # 0
2016-12-18 03:06:15 +00:00
;; Initialize to known state:
2016-12-21 02:26:49 +00:00
;; - $11 in $D17B bank 1 (ROM: $53)
;; - $22 in $D17B bank 2 (ROM: $53)
;; - $33 in $FE1F (ROM: $60)
2016-12-18 03:06:15 +00:00
lda $ C08B ; Read and write bank 1
lda $ C08B
2016-12-21 02:26:49 +00:00
lda # $ 11
2016-12-18 03:06:15 +00:00
sta $ D17B
2016-12-21 02:26:49 +00:00
lda # $ 33
2016-12-18 03:06:15 +00:00
sta $ FE1F
lda $ C083 ; Read and write bank 2
lda $ C083
2016-12-21 02:26:49 +00:00
lda # $ 22
2016-12-18 03:06:15 +00:00
sta $ D17B
lda $ C080
2017-04-25 01:06:55 +00:00
jmp ( PCL ) ; Jump to test routine
2016-12-18 03:06:15 +00:00
2017-04-25 01:06:55 +00:00
;; Test routine will JSR back to here, so the check data address is on the stack.
2016-12-18 03:06:15 +00:00
2017-04-25 01:06:55 +00:00
.test ;; ... test the quintiple of test values
2016-12-18 03:06:15 +00:00
inc $ D17B
inc $ FE1F
2017-04-25 01:06:55 +00:00
;; pull address off of stack: it points just below check data for this test.
pla
sta .checkdata
pla
sta .checkdata + 1
;; .checkdata now points to d17b-current,fe1f-current,bank1,bank2,fe1f-ram test quintiple
2016-12-18 03:06:15 +00:00
;; Test current $D17B
2017-04-25 01:06:55 +00:00
jsr NEXTCHECK
2016-12-18 03:06:15 +00:00
cmp $ D17B
beq +
lda $ D17B
pha
jsr .printseq
+ print
! text "$D17B TO CONTAIN $"
+ printed
2017-04-25 01:06:55 +00:00
jsr CURCHECK
2016-12-18 03:06:15 +00:00
jsr PRBYTE
+ print
! text ", GOT $"
+ printed
pla
jsr PRBYTE
lda # $ 8 D
jsr COUT
2016-12-18 03:19:22 +00:00
jmp .datatesturl
2017-01-10 02:41:06 +00:00
2017-04-25 01:06:55 +00:00
+ ;; Test current $FE1F
jsr NEXTCHECK
2016-12-18 03:06:15 +00:00
cmp $ FE1F
beq +
lda $ FE1F
pha
jsr .printseq
+ print
! text "$FE1F=$"
+ printed
2017-04-25 01:06:55 +00:00
jsr CURCHECK
2016-12-18 03:06:15 +00:00
jsr PRBYTE
+ print
! text ", GOT $"
+ printed
pla
jsr PRBYTE
lda # $ 8 D
jsr COUT
2016-12-18 03:19:22 +00:00
jmp .datatesturl
2017-01-10 02:41:06 +00:00
2017-04-25 01:06:55 +00:00
+ ;; Test bank 1 $D17B
2016-12-18 03:06:15 +00:00
lda $ C088
2017-04-25 01:06:55 +00:00
jsr NEXTCHECK
2016-12-18 03:06:15 +00:00
cmp $ D17B
beq +
lda $ D17B
pha
jsr .printseq
+ print
! text "$D17B IN RAM BANK 1 TO CONTAIN $"
+ printed
2017-04-25 01:06:55 +00:00
jsr CURCHECK
2016-12-18 03:06:15 +00:00
jsr PRBYTE
+ print
! text ", GOT $"
+ printed
pla
jsr PRBYTE
lda # $ 8 D
jsr COUT
2016-12-18 03:19:22 +00:00
jmp .datatesturl
2017-01-10 02:41:06 +00:00
2017-04-25 01:06:55 +00:00
+ ;; Test bank 2 $D17B
2016-12-18 03:06:15 +00:00
lda $ C080
2017-04-25 01:06:55 +00:00
jsr NEXTCHECK
2016-12-18 03:06:15 +00:00
cmp $ D17B
beq +
lda $ D17B
pha
jsr .printseq
+ print
! text "$D17B IN RAM BANK 2 TO CONTAIN $"
+ printed
2017-04-25 01:06:55 +00:00
jsr CURCHECK
2016-12-18 03:06:15 +00:00
jsr PRBYTE
+ print
! text ", GOT $"
+ printed
pla
jsr PRBYTE
lda # $ 8 D
jsr COUT
2016-12-18 03:19:22 +00:00
jmp .datatesturl
2016-12-18 03:06:15 +00:00
2017-04-25 01:06:55 +00:00
+ ;; Test RAM $FE1F
2016-12-18 03:06:15 +00:00
lda $ C080
2017-04-25 01:06:55 +00:00
jsr NEXTCHECK
2016-12-18 03:06:15 +00:00
cmp $ FE1F
beq +
lda $ FE1F
pha
jsr .printseq
+ print
! text "RAM $FE1F=$"
+ printed
2017-04-25 01:06:55 +00:00
jsr CURCHECK
2016-12-18 03:06:15 +00:00
jsr PRBYTE
+ print
! text ", GOT $"
+ printed
pla
jsr PRBYTE
lda # $ 8 D
jsr COUT
2016-12-18 03:19:22 +00:00
jmp .datatesturl
2016-12-18 03:06:15 +00:00
2017-04-25 01:06:55 +00:00
+ ;; Jump PCL,PCH up to after the test data, and loop.
jsr NEXTCHECK
2016-12-22 01:26:22 +00:00
bne +
2017-04-25 01:06:55 +00:00
jmp .success
+ ldx .checkdata
ldy .checkdata + 1
stx PCL
sty PCH
jmp .ddloop
2016-12-18 03:06:15 +00:00
2016-12-18 03:19:22 +00:00
.datatesturl
2017-01-17 03:45:29 +00:00
+ prerr $ 0007 ;; E0007: This is a data-driven test of Language Card operation. We initialize $D17B in RAM bank 1 to $11, $D17B in RAM bank 2 to $22, and $FE1F in RAM to $33. Then, we perform a testdata-driven sequence of LDA and STA to the $C08X range. Finally we (try to) increment $D17B and $FE1F. Then we test (a) the current live value in $D17B, (b) the current live value in $FE1F, (c) the RAM bank 1 value of $D17B, (d) the RAM bank 2 value of $D17B, and (e) the RAM value of $FE1F, to see whether they match expected values. $D17B is usually $53 in ROM, and $FE1F is usally $60. For more information on the operation of the language card soft-switches, see Understanding the Apple IIe, by James Fielding Sather, Pg 5-24.
2016-12-18 03:19:22 +00:00
! text "DATA-DRIVEN TEST FAILED"
+ prerred
2017-01-18 02:44:31 +00:00
sec
2017-01-06 02:47:49 +00:00
rts
2017-01-10 02:41:06 +00:00
2016-12-18 03:06:15 +00:00
.printseq
+ print
2017-04-25 01:06:55 +00:00
! text "AFTER SEQUENCE OF:" , $ 8 D , "- LDA $C080" , $ 8 D
2016-12-18 03:06:15 +00:00
+ printed
2017-04-25 01:06:55 +00:00
jsr PRINTTEST
2016-12-18 03:06:15 +00:00
+ print
2017-04-25 01:06:55 +00:00
! text "- INC $D17B" , $ 8 D , "- INC $FE1F" , $ 8 D , "EXPECTED "
2016-12-18 03:06:15 +00:00
+ printed
rts
2016-12-18 03:19:22 +00:00
.tests
;; Format:
2017-04-25 01:06:55 +00:00
;; Sequence of test instructions, finishing with `jsr .test`.
2016-12-18 03:19:22 +00:00
;; - quint: expected current $d17b and fe1f, then d17b in bank1, d17b in bank 2, and fe1f
2016-12-20 04:55:00 +00:00
;; (All sequences start with lda $C080, just to reset things to a known state.)
2017-04-25 01:06:55 +00:00
;; 0-byte to terminate tests.
lda $ C088 ; Read $C088 (RAM read, write protected)
jsr .test ;
2016-12-21 02:26:49 +00:00
! byte $ 11 , $ 33 , $ 11 , $ 22 , $ 33 ;
2017-04-25 01:06:55 +00:00
;
lda $ C080 ; Read $C080 (read bank 2, write disabled)
jsr .test ;
2016-12-22 01:26:22 +00:00
! byte $ 22 , $ 33 , $ 11 , $ 22 , $ 33 ;
2017-04-25 01:06:55 +00:00
;
lda $ C081 ; Read $C081 (ROM read, write disabled)
jsr .test ;
2016-12-22 01:26:22 +00:00
! byte $ 53 , $ 60 , $ 11 , $ 22 , $ 33 ;
2017-04-25 01:06:55 +00:00
;
lda $ C081 ; Read $C081, $C089 (ROM read, bank 1 write)
lda $ C089 ;
jsr .test ;
2016-12-22 01:26:22 +00:00
! byte $ 53 , $ 60 , $ 54 , $ 22 , $ 61 ;
2017-04-25 01:06:55 +00:00
;
lda $ C081 ; Read $C081, $C081 (read ROM, write RAM bank 2)
lda $ C081 ;
jsr .test ;
2016-12-21 02:26:49 +00:00
! byte $ 53 , $ 60 , $ 11 , $ 54 , $ 61 ;
2017-04-25 01:06:55 +00:00
;
lda $ C081 ; Read $C081, $C081, write $C081 (read ROM, write RAM bank bank 2)
lda $ C081 ;
sta $ C081 ;
jsr .test ;
2017-03-20 00:30:39 +00:00
! byte $ 53 , $ 60 , $ 11 , $ 54 , $ 61 ; See https://github.com/zellyn/a2audit/issues/3
2017-04-25 01:06:55 +00:00
;
lda $ C08B ; Read $C08B (read RAM bank 1, no write)
jsr .test ;
2016-12-22 01:26:22 +00:00
! byte $ 11 , $ 33 , $ 11 , $ 22 , $ 33 ;
2017-04-25 01:06:55 +00:00
;
lda $ C083 ; Read $C083 (read RAM bank 2, no write)
jsr .test ;
2016-12-22 01:26:22 +00:00
! byte $ 22 , $ 33 , $ 11 , $ 22 , $ 33 ;
2017-04-25 01:06:55 +00:00
;
lda $ C08B ; Read $C08B, $C08B (read/write RAM bank 1)
lda $ C08B ;
jsr .test ;
2016-12-21 02:26:49 +00:00
! byte $ 12 , $ 34 , $ 12 , $ 22 , $ 34 ;
2017-04-25 01:06:55 +00:00
;
lda $ C08F ; Read $C08F, $C087 (read/write RAM bank 2)
lda $ C087 ;
jsr .test ;
2017-01-06 02:47:49 +00:00
! byte $ 23 , $ 34 , $ 11 , $ 23 , $ 34 ;
2017-04-25 01:06:55 +00:00
;
lda $ C087 ; Read $C087, read $C08D (read ROM, write bank 1)
lda $ C08D ;
jsr .test ;
2016-12-21 02:26:49 +00:00
! byte $ 53 , $ 60 , $ 54 , $ 22 , $ 61 ;
2017-04-25 01:06:55 +00:00
;
lda $ C08B ; Read $C08B, write $C08B, read $C08B (read RAM bank 1, no write)
sta $ C08B ; (this one is tricky: reset WRTCOUNT by writing halfway)
lda $ C08B ;
jsr .test ;
! byte $ 11 , $ 33 , $ 11 , $ 22 , $ 33 ;
;
sta $ C08B ; Write $C08B, write $C08B, read $C08B (read RAM bank 1, no write)
sta $ C08B ;
lda $ C08B ;
jsr .test ;
2017-03-02 02:18:04 +00:00
! byte $ 11 , $ 33 , $ 11 , $ 22 , $ 33 ;
2017-04-25 01:06:55 +00:00
;
2017-04-25 01:29:34 +00:00
clc ; Read $C083, $C083 (read/write RAM bank 2)
ldx # 0 ;
2017-04-25 01:42:31 +00:00
inc $ C083 , x ; Uses "6502 false read"
2017-04-25 01:29:34 +00:00
jsr .test ;
! byte $ 23 , $ 34 , $ 11 , $ 23 , $ 34 ;
;
! byte 0 ; End of tests
2016-12-18 03:19:22 +00:00
nop ; Provide clean break after data when viewing disassembly
nop
2017-04-25 01:06:55 +00:00
.success
2016-12-18 01:49:28 +00:00
2016-12-15 01:16:55 +00:00
;; Success
+ print
! text "LANGUAGE CARD TESTS SUCCEEDED" , $ 8 D
+ printed
2017-01-18 02:44:31 +00:00
lda # 1
sta LCRESULT
clc
2017-01-06 02:47:49 +00:00
rts
2017-01-18 02:44:31 +00:00
} ;langcard