From eeece2db6eaf9f6ca749386590987f45564a0cf2 Mon Sep 17 00:00:00 2001 From: marcobaye Date: Thu, 4 Nov 2021 20:15:04 +0000 Subject: [PATCH] added "double dabble" example git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@322 4df02467-bbd4-4a76-a152-e7ce94205b78 --- examples/Makefile | 5 +- examples/c64doubledabble.a | 86 +++++++++++++++++++++++++++++++++++ examples/c64doubledabble.exp | Bin 0 -> 138 bytes examples/c64misc.exp | Bin 228 -> 228 bytes examples/misc/basicstub.a | 2 +- 5 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 examples/c64doubledabble.a create mode 100644 examples/c64doubledabble.exp diff --git a/examples/Makefile b/examples/Makefile index 177db39..a0a44c3 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -2,10 +2,13 @@ ASSEMBLER6502 = acme AS_FLAGS = -v9 -Wtype-mismatch RM = rm -PROGS = c64misc.prg ddrv128.prg ddrv64.prg macedit.o trigono.o +PROGS = c64doubledabble.prg c64misc.prg ddrv128.prg ddrv64.prg macedit.o trigono.o all: $(PROGS) +c64doubledabble.prg: c64doubledabble.a + $(ASSEMBLER6502) $(AS_FLAGS) --outfile c64doubledabble.prg --format cbm c64doubledabble.a + c64misc.prg: c64misc.a $(ASSEMBLER6502) $(AS_FLAGS) --outfile c64misc.prg --format cbm c64misc.a diff --git a/examples/c64doubledabble.a b/examples/c64doubledabble.a new file mode 100644 index 0000000..9c43f93 --- /dev/null +++ b/examples/c64doubledabble.a @@ -0,0 +1,86 @@ +;ACME 0.97 + +; here's an implementation of the "double dabble" algorithm, a quick +; and easy way to output integers as decimal digits. + +; in this example, the 24-bit value of the time variable TI is shown +; on the screen as eight decimal digits, updated once per frame (every +; once in a while there will be a glitch because the system interrupt +; handler is not synchronized with the screen, to fix this is left as +; an excercise to the reader). +; the raster time used is indicated via changes of the border color. + + DIGITS = 8 ; three input bytes -> 24 bits -> max 16777216 -> we need eight digits +!addr { + byte = $fb ; buffers input byte during shifts + ti_high = $a0 ; input data + ti_med = $a1 + ti_low = $a2 + out = $0400 ; where to show output digits (big-endian!) + raster = $d012 ; to sync with screen + border = $d020 ; to show raster time +} + * = $0801 + !src "misc/basicstub.a" +--- ; wait for lower border + lda raster + cmp #251 + bne --- + inc border ; start "stop watch" + jsr dd_clear ; clear output + sei ; make sure TI is stable while we read it + lda ti_low + pha + lda ti_med + pha + lda ti_high + cli ; re-allow irq + jsr dd_process_A ; process high byte + pla ; restore medium byte + jsr dd_process_A + pla ; restore low byte + jsr dd_process_A + jsr dd_result ; convert result from 0..9 values to '0'..'9' characters + dec border ; stop "stop watch" + jmp --- + +dd_clear ; clear result bytes + ldx #DIGITS - 1 + lda #0 +--- sta out, x + dex + bpl --- + rts + +dd_result ; convert result bytes to ascii digits + ldx #DIGITS - 1 +--- lda out, x + ora #$30 + sta out, x + dex + bpl --- + rts + +dd_process_A ; process eight bits + ; use the zero-means-empty trick so we do not need a bit counter: + sec ; create "marker bit" + rol ; push into A, now C = data bit + sta byte ; remember for later + ; here's how to process a bit: + ; "out" holds digits (0..9, not '0'..'9'), + ; but in big-endian order (for screen output). + ; the new bit is in C: +next_bit ldx #DIGITS - 1 ; loop over output digits +next_digit ldy out, x ; now Y = 0..9 (old value) + lda table, y ; now A = 0/1/2/3/4/128/129/130/131/132 + rol ; now A = 0..9 (new value), bit for next digit in C + sta out, x ; update digit + dex + bpl next_digit + ;clc ; only needed if overflow possible + rol byte ; get next data bit + bne next_bit + ; byte is empty (C is 1, but that's the marker bit) + rts +table + !by 0, 1, 2, 3, 4, $80, $81, $82, $83, $84 diff --git a/examples/c64doubledabble.exp b/examples/c64doubledabble.exp new file mode 100644 index 0000000000000000000000000000000000000000..90308c330ffbb9b76e72a9ca0012f57301c44aee GIT binary patch literal 138 zcmZSNP~>>ZK2O2Oz{1$7Um?W9GgtwL92K1XeSKa1LKGPo7}g41IQjd+&vyzJ6#O_U zmM-#Gy3k|kf(V6ljtnSPh~zk@aKT5JV-fpGhPezZrv!c_EMniwz`|(&=6y}D&}#j? ghUwci)sCNMBEF|#x@HZ`{Z08a)lpa1{> literal 0 HcmV?d00001 diff --git a/examples/c64misc.exp b/examples/c64misc.exp index 0b1d10634ca22a4e09e9acca0b3c6f2100f4c71c..b042f7d84688c02307e0dcd01f913e8b02048c8e 100644 GIT binary patch delta 13 UcmaFD_=J&_kwcN==|tB1038klTmS$7 delta 13 UcmaFD_=J&_kwcN=$wb!s038YhTL1t6 diff --git a/examples/misc/basicstub.a b/examples/misc/basicstub.a index ccbbd0c..68d6675 100644 --- a/examples/misc/basicstub.a +++ b/examples/misc/basicstub.a @@ -3,7 +3,7 @@ ;* = $0801 ; c64 ;* = $1001 ; c16/+4 ;* = $1c01 ; c128 - !wo line2, 2020 ; link pointer and line number + !wo line2, 2021 ; link pointer and line number !by $9e, ' ' ; "sys " !by '0' + entry % 10000 / 1000 !by '0' + entry % 1000 / 100