From ec2152eaf7aed8f2d06865dc1fca20807d68e61c Mon Sep 17 00:00:00 2001 From: Tobias Girstmair Date: Fri, 5 Mar 2021 14:27:59 +0100 Subject: [PATCH] transscribe fakeasm to realasm the memory locations (w.r.t. aliases) have been set/fixed, too. --- Makefile | 22 ++-- bsv.S | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ bsv.c | 292 ------------------------------------------------ fakeasm.h | 24 ---- 4 files changed, 336 insertions(+), 326 deletions(-) create mode 100644 bsv.S delete mode 100644 bsv.c delete mode 100644 fakeasm.h diff --git a/Makefile b/Makefile index 81fc760..c4bb50e 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,15 @@ -.PHONY: all test commit +# NOTE: using pre-built sdcc-4.1.0-rc1 from sdcc.sf.net +# NOTE: using homebuilt dispdk@670e7bc from github.com/free-pdk/fppa-pdk-tools +.PHONY: all dis clean +all: bsv.ihx +dis: bsv.ihx + ./bin/dispdk 2A16 $^ -all: test +bsv.rel: bsv.S + ./bin/sdaspdk13 -o $^ -test: bsv orig.pcm - ./bsv | head -c7864320 | diff -s - orig.pcm +bsv.ihx: bsv.rel + ./bin/sdldpdk -i $^ -commit: test - git add bsv.c - git commit -m "new version" - -orig.pcm: - ./bsv-orig | head -c7864320 > orig.pcm +clean: + rm -f bsv.ihx bsv.rel diff --git a/bsv.S b/bsv.S new file mode 100644 index 0000000..27c61b5 --- /dev/null +++ b/bsv.S @@ -0,0 +1,324 @@ +;.area DATA +.area OSEG (OVR,DATA) +;.area DATA +notes: .ds 16 ; 0x00 .. 0x0f +i0: .ds 1 ; 0x10 +i1: .ds 1 ; 0x11 +i2: .ds 1 ; 0x12 +n: .ds 1 ; 0x13 +.even ; make next two bytes word-aligned +zero: .ds 1 ; 0x14 +tmp_1: .ds 1 ; 0x15 +tmp_hi: .ds 1 ; 0x16 +tmp_lo: .ds 1 ; 0x17 +pwm: .ds 1 ; 0x18 +.area SSEG +stack: .ds 1 + +; aliases for memory locations: +notes_ix = tmp_1 +t = tmp_1 +mul2 = tmp_hi +mul1 = tmp_lo +mod3hi = tmp_hi +mod3lo = tmp_lo + + + +.area CSEG (CODE,ABS) +;.area HOME +;.area HEADER (ABS) +.org 0x0000 + ;TODO: move some init stuff here (space for 15 instr.) + GOTO init + +;.area HOME +;.area HEADER (ABS) +.org 0x0020 + GOTO sample + +;.area CODE + +mod3: + MOV a, mod3hi + ADD mod3lo, a ; mod3lo = hi+lo + MOV a, #0 + ADDC a ; mod3hi, 1bit + SWAP a + MOV mod3hi, a + + MOV a, mod3lo + SWAP a + AND a, #0xf ; (mod3lo>>4) + XCH mod3lo ; a=mod3lo, mod3lo=mod3lo>>4 + AND a, #0xF ; a=mod3lo&0xf, mod3lo=mod3lo>>4 + ADD a, mod3lo ; (mod3lo & 0xF) + ADD a, mod3hi + MOV mod3lo, a + + AND a, #0x3 ; a = (mod3lo & 0x3) + SR mod3lo + SR mod3lo ; (mod3lo >> 2) + ADD a, mod3lo + MOV mod3lo, a + + AND a, #0x3 ; a = (mod3lo & 0x3) + SR mod3lo + SR mod3lo ; (mod3lo >> 2) + ADD a, mod3lo + + SUB a, #3 + T0SN f, c + ADD a, #3 + RET + +g: + ; notes_ix_hi = always 0 + AND a, #0x7 + MOV notes_ix, a + ; test i2 & 3: + MOV a, i2 + AND a, #3 + T0SN f, z + SET1 notes_ix, #3 + IDXM a, notes_ix + + MOV t, a + CLEAR mul2 + CLEAR mul1 + ; note: LSB of result (mul0) is not needed for our purposes + ;;1/8: + SR t + T1SN f, c + GOTO skip1 + MOV a, i0 + ADD mul1, a + MOV a, i1 + ADDC mul2, a + skip1: SR mul2 + SRC mul1 + ;;2/8: + SR t + skip2: SR mul2 + SRC mul1 + ;;3/8: + SR t + T1SN f, c + GOTO skip3 + MOV a, i0 + ADD mul1, a + MOV a, i1 + ADDC mul2, a + skip3: SR mul2 + SRC mul1 + ;;4/8: + SR t + T1SN f, c + GOTO skip4 + MOV a, i0 + ADD mul1, a + MOV a, i1 + ADDC mul2, a + skip4: SR mul2 + SRC mul1 + ;;5/8: + SR t + T1SN f, c + GOTO skip5 + MOV a, i0 + ADD mul1, a + MOV a, i1 + ADDC mul2, a + skip5: SR mul2 + SRC mul1 + ;;6/8: + SR t + T1SN f, c + GOTO skip6 + MOV a, i0 + ADD mul1, a + skip6: + SRC mul1 + ;;7/8: + SR t + T1SN f, c + GOTO skip7 + MOV a, i0 + ADD mul1, a + skip7: + SRC mul1 + ;;8/8: + SR t + T1SN f, c + GOTO skip8 + MOV a, i0 + ADD mul1, a + skip8: + SRC mul1 + + MOV a, mul1 + RET + +init: + CLEAR i0 + CLEAR i1 + CLEAR i2 + + ;rom is not mmapped; must load into ram first + MOV a, #0x84 + MOV notes+0x0, a + MOV notes+0x5, a + MOV a, #0x9d + MOV notes+0x1, a + MOV notes+0x4, a + MOV a, #0xb0 + MOV notes+0x2, a + MOV notes+0xA, a + MOV a, #0x69 + MOV notes+0x3, a + MOV notes+0x6, a + MOV notes+0xB, a + MOV notes+0xE, a + MOV a, #0x58 + MOV notes+0x7, a + MOV notes+0xF, a + MOV a, #0x75 + MOV notes+0x8, a + MOV notes+0xD, a + MOV a, #0x8c + MOV notes+0x9, a + MOV notes+0xC, a + + ;TODO: setup mcu, timer16, ... + ;TODO: freepdk calibration routine + +loop: + ;TODO: test i2==0x78 to enter halt() + ;TODO: stopsys + GOTO loop + +sample: + ;TODO: send pwm data to timer2 + + MOV a, i2; "mov mem,mem" + MOV n, a; does not exist + SL n + SL n + MOV a, i1 + SWAP a + AND a, #0xf + SR a + SR a + OR n, a + + MOV a, n + CALL g + SWAP a + AND a, #0x1 + MOV pwm, a + + MOV a, i2 + SL a + SL a + SL a + MOV tmp_1, a ; fresh tmp_1: + MOV a, i1 + SWAP a + AND a, #0xf + SR a + OR a, tmp_1 ; tmp_1 done. + XOR a, n + CALL g + SR a + AND a, i2 + SR a + AND a, #3 + ADD pwm, a + + MOV a, i2 + MOV mod3hi, a + SR mod3hi + SR mod3hi + SR mod3hi + SWAP a + AND a, #0xf0 + SL a + MOV mod3lo, a + MOV a, i1 + SR a + SR a + SR a + OR mod3lo, a + CALL mod3 + ADD a, n + CALL g + SR a + SR a + MOV tmp_1, a ; a saved in tmp_1; fresh a + MOV a, i2 + ; shift-divide by six + ; note: i2 is max 0x78; so a will <= 20. (breaks vor values >=128) + SR a + ADD a, i2 + SR a + SR a + ADD a, i2 + SR a + SR a + ADD a, i2 + SR a + SR a + SR a + ; end divide by six + AND a, tmp_1 ; a restored from tmp_1 + AND a, #3 + ADD pwm, a + + MOV a, i2 + MOV mod3hi, a + SR mod3hi + SR mod3hi + SWAP a + AND a, #0xf0 + SL a + SL a + MOV mod3lo, a + MOV a, i1 + SR a + SR a + OR mod3lo, a + CALL mod3 + SUB a, n + SUB a, #8 + NEG a + CALL g + SR a + MOV tmp_1, a ; a saved in tmp_1; fresh a + MOV a, i2 + ; shift-divide by ten + ; note: i2 is max 0x78; so a will <= 12. + INC i2 + SR a + ADD a, i2 + SR a + SR a + SR a + ADD a, i2 + SR a + ADD a, i2 + SWAP a + DEC i2 + ; end divide by ten + AND a, tmp_1 ; a restored from tmp_1 + AND a, #3 + ADD pwm, a + + MOV a, pwm + SWAP a + ; next sample is now ready. + + INC i0 + ADDC i1 + ADDC i2 + + RETI diff --git a/bsv.c b/bsv.c deleted file mode 100644 index 5fb6e83..0000000 --- a/bsv.c +++ /dev/null @@ -1,292 +0,0 @@ -#include -#include "fakeasm.h" -typedef unsigned char u8; - -u8 notes[16]; //MEM -u8 i0, i1, i2; //MEM -u8 n; //MEM -u8 sample; //MEM -u8 tmp_1; //MEM -u8 acc; //ACC - -u8 mod3hi, mod3lo; //MEM -//todo: can mod3hi be aliased to tmp_1? -void mod3(void) { - MOV (acc,mod3hi) - ADD (mod3lo,acc) // mod3lo = hi+lo - CLEAR (acc) - ADDC0 (acc) // mod3hi, 1bit - SWAP (acc) - MOV (mod3hi, acc) - - MOV (acc, mod3lo) - SWAP (acc) - AND (acc, 0xf) // (mod3lo>>4) - XCH (mod3lo) // acc=mod3lo, mod3lo=mod3lo>>4 - AND (acc, 0xF) // acc=mod3lo&0xf, mod3lo=mod3lo>>4 - ADD (acc, mod3lo) // (mod3lo & 0xF) - ADD (acc, mod3hi) - MOV (mod3lo, acc) - - AND (acc, 0x3) // acc = (mod3lo & 0x3) - SR (mod3lo) - SR (mod3lo) // (mod3lo >> 2) - ADD (acc, mod3lo) - MOV (mod3lo, acc) - - AND (acc, 0x3) // acc = (mod3lo & 0x3) - SR (mod3lo) - SR (mod3lo) // (mod3lo >> 2) - ADD (acc, mod3lo) - - SUB (acc,3) - /*T0SN FLAG.C (0x00.1)*/ if (flag_c){ // skip if carry clear - ADD (acc,3) } - RET -} - -void g(void){ - // notes_ix_hi = always 0 - u8 notes_ix;//lo - AND (acc, 0x7) - MOV (notes_ix, acc) - // test i2 & 3: - MOV (acc, i2) - AND (acc, 3) - /*T0SN FLAG.Z (0x00.0)*/ if(3&i2) {// skip if !(3&i0) - SET1 (notes_ix, 3) } // ix += 8 <=> ix |= 8 - IDXM (acc, notes+notes_ix) - - #define mul2 mod3hi - #define mul1 mod3lo - #define t tmp_1 - MOV (t, acc) - CLEAR (mul2) - CLEAR (mul1) - //1/8: - SR (t) - /*T1SN FLAG.C*/ if(!flag_c) { - goto skip1; } - MOV (acc, i0) - ADD (mul1, acc) - MOV (acc, i1) - ADDC (mul2, acc) - skip1: SR (mul2) - SRC (mul1) - //2/8: - SR (t) - skip2: SR (mul2) - SRC (mul1) - //3/8: - SR (t) - /*T1SN FLAG.C*/ if(!flag_c) { - goto skip3; } - MOV (acc, i0) - ADD (mul1, acc) - MOV (acc, i1) - ADDC (mul2, acc) - skip3: SR (mul2) - SRC (mul1) - //4/8: - SR (t) - /*T1SN FLAG.C*/ if(!flag_c) { - goto skip4; } - MOV (acc, i0) - ADD (mul1, acc) - MOV (acc, i1) - ADDC (mul2, acc) - skip4: SR (mul2) - SRC (mul1) - //5/8: - SR (t) - /*T1SN FLAG.C*/ if(!flag_c) { - goto skip5; } - MOV (acc, i0) - ADD (mul1, acc) - MOV (acc, i1) - ADDC (mul2, acc) - skip5: SR (mul2) - SRC (mul1) - //6/8: - SR (t) - /*T1SN FLAG.C*/ if(!flag_c) { - goto skip6; } - MOV (acc, i0) - ADD (mul1, acc) - skip6: - SRC (mul1) - //7/8: - SR (t) - /*T1SN FLAG.C*/ if(!flag_c) { - goto skip7; } - MOV (acc, i0) - ADD (mul1, acc) - skip7: - SRC (mul1) - //8/8: - SR (t) - /*T1SN FLAG.C*/ if(!flag_c) { - goto skip8; } - MOV (acc, i0) - ADD (mul1, acc) - skip8: - SRC (mul1) - - MOV (acc, mul1) - RET -} -void main(void){ - CLEAR (i0) - CLEAR (i1) - CLEAR (i2) - - //rom is not mmapped; must load into ram first - MOV (acc, 0x84) - MOV (notes[0x0], acc) - MOV (notes[0x5], acc) - MOV (acc, 0x9d) - MOV (notes[0x1], acc) - MOV (notes[0x4], acc) - MOV (acc, 0xb0) - MOV (notes[0x2], acc) - MOV (notes[0xA], acc) - MOV (acc, 0x69) - MOV (notes[0x3], acc) - MOV (notes[0x6], acc) - MOV (notes[0xB], acc) - MOV (notes[0xE], acc) - MOV (acc, 0x58) - MOV (notes[0x7], acc) - MOV (notes[0xF], acc) - MOV (acc, 0x75) - MOV (notes[0x8], acc) - MOV (notes[0xD], acc) - MOV (acc, 0x8c) - MOV (notes[0x9], acc) - MOV (notes[0xC], acc) - - for(;;) { - MOV (acc, i2)// "mov mem,mem" - MOV (n, acc)// does not exist - SL (n) - SL (n) - MOV (acc, i1) - SWAP (acc) - AND (acc, 0xf) - SR (acc) - SR (acc) - OR (n, acc) - - MOV (acc, n) - CALL (g) - SWAP (acc) - AND (acc, 0x1) - MOV (sample, acc) - - MOV (acc, i2) - SL (acc) - SL (acc) - SL (acc) - MOV (tmp_1, acc) // fresh tmp_1: - MOV (acc, i1) - SWAP (acc) - AND (acc, 0xf) - SR (acc) - OR (acc, tmp_1) // tmp_1 done. - XOR (acc, n) - CALL (g) - SR (acc) - AND (acc, i2) - SR (acc) - AND (acc, 3) - ADD (sample, acc) - - MOV (acc, i2) - MOV (mod3hi, acc) - SR (mod3hi) - SR (mod3hi) - SR (mod3hi) - SWAP (acc) - AND (acc, 0xf0) - SL (acc) - MOV (mod3lo, acc) - MOV (acc, i1) - SR (acc) - SR (acc) - SR (acc) - OR (mod3lo, acc) - CALL (mod3) - ADD (acc, n) - CALL (g) - SR (acc) - SR (acc) - MOV (tmp_1, acc) // acc saved in tmp_1; fresh acc - MOV (acc, i2) - // shift-divide by six - // note: i2 is max 0x78; so acc will <= 20. (breaks vor values >=128) - SR (acc) - ADD (acc, i2) - SR (acc) - SR (acc) - ADD (acc, i2) - SR (acc) - SR (acc) - ADD (acc, i2) - SR (acc) - SR (acc) - SR (acc) - // end divide by six - AND (acc, tmp_1) // acc restored from tmp_1 - AND (acc, 3) - ADD (sample, acc) - - MOV (acc, i2) - MOV (mod3hi, acc) - SR (mod3hi) - SR (mod3hi) - SWAP (acc) - AND (acc, 0xf0) - SL (acc) - SL (acc) - MOV (mod3lo, acc) - MOV (acc, i1) - SR (acc) - SR (acc) - OR (mod3lo, acc) - CALL (mod3) - SUB (acc, n) - SUB (acc, 8) - NEG (acc) - CALL (g) - SR (acc) - MOV (tmp_1, acc) // acc saved in tmp_1; fresh acc - MOV (acc, i2) - // shift-divide by ten - // note: i2 is max 0x78; so acc will <= 12. - INC (i2) - SR (acc) - ADD (acc, i2) - SR (acc) - SR (acc) - SR (acc) - ADD (acc, i2) - SR (acc) - ADD (acc, i2) - SWAP (acc) - DEC (i2) - // end divide by ten - AND (acc, tmp_1) // acc restored from tmp_1 - AND (acc, 3) - ADD (sample, acc) - - MOV (acc, sample) - SWAP (acc) - putchar(acc); - - INC (i0) - /*ADDC i1*/ i1 += !i0; - /*ADDC i2*/ i2 += !i1 && !i0; - - if(i2 == 0x78) break; - } -} diff --git a/fakeasm.h b/fakeasm.h deleted file mode 100644 index 7ee23f4..0000000 --- a/fakeasm.h +++ /dev/null @@ -1,24 +0,0 @@ -int flag_z = 0; -int flag_c = 0; -//ignoring flag_ov, flag_ac -#define MOV(dst, src) dst = src; -#define SL(dst) flag_c = (dst>>7); dst <<= 1; -#define SR(dst) flag_c = (dst&01); dst >>= 1; -#define SWAP(dst) dst = (dst<<4 | dst>>4); -#define AND(dst, src) dst &= src; flag_z = (dst==0); -#define OR(dst, src) dst |= src; flag_z = (dst==0); -#define CLEAR(dst) dst = 0; -#define ADD(dst, src) flag_c = (src+dst)>>8; dst += src; flag_z = (dst==0); -#define INC(dst) dst += 1; flag_c = flag_z = (dst==0); -#define ADDC0(dst) dst += flag_c; flag_c = flag_z = (dst==0); -#define CALL(addr) addr(); -#define XOR(dst, src) dst ^= src; flag_z = (dst==0); -#define SUB(dst, src) flag_c = (src > dst); dst -= src; flag_z = (dst==0); -#define XCH(dst) acc ^= dst; dst ^= acc; acc ^= dst; -#define DEC(dst) dst -= 1; flag_c = flag_z = (dst==0); -#define NEG(dst) dst *= -1; flag_z = (dst==0); -#define SET1(dst, n) dst |= 1<>= 1; dst |= flag_c<<7; -#define ADDC(dst, src) dst += src+flag_c; -#define RET return; -- 2.39.3