From a1f27f87e54d083de32e7e6af7051b1db6715e35 Mon Sep 17 00:00:00 2001 From: Rob Greene Date: Mon, 28 Sep 2015 23:30:49 -0500 Subject: [PATCH] Extracted ilen proc, added unit test, and AppleScript to execute. --- online/Makefile | 13 +++- online/ilen-test.scpt.txt | 80 ++++++++++++++++++++++++ online/ilen.asm | 128 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 220 insertions(+), 1 deletion(-) create mode 100644 online/ilen-test.scpt.txt create mode 100644 online/ilen.asm diff --git a/online/Makefile b/online/Makefile index aa9a15a..c19234d 100755 --- a/online/Makefile +++ b/online/Makefile @@ -5,14 +5,25 @@ VIRTUAL2 = /Applications/Virtual\ \]\[/Virtual\ \]\[.app/Contents/MacOS/Virtual\ all: online.bin +online: online.bin +ilen: ilen.bin + online.bin: online.asm cl65 -o online.bin -t none --start-addr 0x2000 -l online.asm cp $(TEMPLATE) online.po $(JAVA) -jar $(AC) -p online.po online BIN 0x2000 < online.bin +ilen.bin: ilen.asm + cl65 --asm-define TESTILEN -o ilen-test.bin -t none --start-addr 0x2000 -l ilen.asm + cp $(TEMPLATE) ilen-test.po + $(JAVA) -jar $(AC) -p ilen-test.po ilen.test BIN 0x2000 < ilen-test.bin + osascript ilen-test.scpt.txt "$(PWD)/ilen-test.po" + test: - #$(VIRTUAL2) ./online.po osascript test.scpt "$(PWD)/online.po" +run: + $(VIRTUAL2) ./online.po + clean: rm *.bin *.lst *.o online.po diff --git a/online/ilen-test.scpt.txt b/online/ilen-test.scpt.txt new file mode 100644 index 0000000..4706fe2 --- /dev/null +++ b/online/ilen-test.scpt.txt @@ -0,0 +1,80 @@ +on run argv + set IMAGE to item 1 of argv + #set IMAGE to "/Users/rob/asm/basic-system-cmd/online/ilen-test.po" + + set expected to { ¬ + " 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F", ¬ + " -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --", ¬ + "00|01 02 02 02 02 02 02 02 01 02 01 01 03 03 03 03|0F", ¬ + "10|02 02 02 02 02 02 02 02 01 03 01 01 03 03 03 03|1F", ¬ + "20|03 02 02 02 02 02 02 02 01 02 01 01 03 03 03 03|2F", ¬ + "30|02 02 02 02 02 02 02 02 01 03 01 01 03 03 03 03|3F", ¬ + "40|01 02 02 02 02 02 02 02 01 02 01 01 03 03 03 03|4F", ¬ + "50|02 02 02 02 02 02 02 02 01 03 01 01 03 03 03 03|5F", ¬ + "60|01 02 02 02 02 02 02 02 01 02 01 01 03 03 03 03|6F", ¬ + "70|02 02 02 02 02 02 02 02 01 03 01 01 03 03 03 03|7F", ¬ + "80|02 02 02 02 02 02 02 02 01 02 01 01 03 03 03 03|8F", ¬ + "90|02 02 02 02 02 02 02 02 01 03 01 01 03 03 03 03|9F", ¬ + "A0|02 02 02 02 02 02 02 02 01 02 01 01 03 03 03 03|AF", ¬ + "B0|02 02 02 02 02 02 02 02 01 03 01 01 03 03 03 03|BF", ¬ + "C0|02 02 02 02 02 02 02 02 01 02 01 01 03 03 03 03|CF", ¬ + "D0|02 02 02 02 02 02 02 02 01 03 01 01 03 03 03 03|DF", ¬ + "E0|02 02 02 02 02 02 02 02 01 02 01 01 03 03 03 03|EF", ¬ + "F0|02 02 02 02 02 02 02 02 01 03 01 01 03 03 03 03|FF", ¬ + " -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --", ¬ + " 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F" ¬ + } + + tell application "Virtual ][" + activate + close every machine saving no + set theMachine to (make new AppleIIe) + tell theMachine + eject device "S6D1" + insert IMAGE into device "S6D1" + delay 0.5 + restart + set speed to maximum + delay 0.25 + + -- Load the ILEN.TEST program + type line "-ILEN.TEST" + + -- Wait till we have the Applesoft prompt back, then continue + repeat + delay 1.0 -- Let virtual machine go for a second + if the last line of compact screen text = "]" then + exit repeat + end if + end repeat + set speed to regular + + -- Test! + set linesout to (count lines of compact screen text) - 1 + set matches to true + set failmessage to "" + repeat with j from 1 to count(expected) + set a to line (linesout - j + 1) of compact screen text + set e to item ((count of expected) - j + 1) of expected + if a is not equal to e + set matches to false + set failmessage to failmessage & " " & j + display dialog "Mismatch:\nA=[" & a & "]\nE=[" & e & "]\n" ¬ + buttons {"OK"} default button 1 + end if + end repeat + + if matches then + type line "REM *** SUCCESS ***" + else + type text "REM >>> FAIL <<<" + type ctrl "G" + type ctrl "G" + type ctrl "G" + type text failmessage + end if + end tell + end tell +end run + + diff --git a/online/ilen.asm b/online/ilen.asm new file mode 100644 index 0000000..da99076 --- /dev/null +++ b/online/ilen.asm @@ -0,0 +1,128 @@ +; +; ilen.asm +; + + .PC02 ; Enable 65C02 instructions + + .code + +.ifdef TESTILEN + +crout = $fd8e +cout = $fded +prbyte = $fdda + + .org $2000 + +.proc ilentest + jsr $c300 ; Assume we have an 80 column card available + jsr crout + jsr updnborder + jsr updndividor +; Results -- + ldx #0 +: txa + jsr prbyte + lda #'|'|$80 + jsr cout + ldy #16 +: txa + jsr ilen + jsr prbyte + jsr spout + inx + dey + bne :- + lda #$88 ; (backspace) + jsr cout + lda #'|'|$80 + jsr cout + txa + dec ; we're one past the last one + jsr prbyte + jsr crout + cpx #0 + bne :-- + jsr updndividor + +; XX...XX +updnborder: + jsr spout + jsr spout + jsr spout +; Top line -- + ldy #0 +: tya + jsr prbyte + jsr spout + iny + cpy #$10 + bcc :- + jmp crout + +updndividor: + jsr spout + jsr spout + jsr spout + ldy #0 +; Hypens +: lda #'-'|$80 + jsr cout + jsr cout + jsr spout + iny + cpy #$10 + bcc :- + jmp crout + +spout: + lda #' '|$80 + jmp cout +.endproc +.endif + +; +; Calculate Instruction Length +; Based on observations in 65C02 data sheet: +; * Generally, length is based on LOW nibble +; * There are a few special cases (including X9 column) +; Input: Acc. = instruction +; Output: Acc. = length +.proc ilen + bit #$0f + bne @normal +@column0: + bit #%10010000 ; Normal instructions have at least one of these bits set + beq @notnormal ; None are set +@normal: ; "Normal" values for ALL columns 0-F + asl + asl + asl +@column9: + cmp #$C8 ; xxx11001<<3 (special case for $X9 column) + beq @three + cmp #$48 ; xxx01001<<3 (special case for $X9 column) + beq @two +;@morenormal: + asl + bpl @two ; xxxx0xxx<<4 + asl + bpl @one ; xxxx10xx<<5 + ; fall through for xxxx11xx<<5 +@three: + lda #3 + rts + +@notnormal: + cmp #$20 ; JSR ($20) + beq @three + ; fall through for BRK ($00) / RTI ($40) / RTS ($60) +@one: + lda #1 + rts +@two: + lda #2 + rts +.endproc + +