From 02a29960244b413ce39803d210a323675a63b2ad Mon Sep 17 00:00:00 2001 From: Tobias Girstmair Date: Fri, 30 Apr 2021 19:10:28 +0200 Subject: [PATCH] fix IDXM'ing of the wrong notes turns out, set1 M.n can only be used with 4-bit memory addresses, but those are used by the notes array. supplying a 5-bit address (0x16 in our case) causes it to be silently truncated (to 0x06, which incidentally already has the modified bit set, so no change was visible). this does not appear to be mentioned in the datasheet, but the free-pdk instruction set documentation notes the allowed length of the memory address. even though this introduces two additional cycles per g(), the totoal cycle count estimation is still (as) accurate, because we overestimated the multiplication cycles by the same amount (0x9d is most "expensive" number, takes 55 cycles). for debugging this, ucsim (distributed with sdcc) was very helpful. the setup looked like this: - interrupt and timers not supported, so call interrupt() in a loop after init() - disable the t1sn intrq check and s/reti/ret/i, since we are now calling interrupt() directly - remove ENGINT instruction, as it halts ucsim ("invalid instruction") - in the OSEG (ram), add a new variable `simif: .ds 1 ;0x18` - to output a byte to a file, write 'w' to simif, then the byte to send. mov a, #'w' mov simif, a mov a, the_value mov simif, a - run the debugger for a few seconds, then ^C to quit: spdk -Pt PDK13 -I if='ram[0x18],out='/tmp/out.bin -g bsv.ihx - recreate the same screnario with bsv.c (e.g. fakeasm) using putchar() - vimdiff each <(<$FILE head -c131072 | xxd | sed 's/^[0-9a-f]://' | uniq -c) --- bsv.asm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bsv.asm b/bsv.asm index 2c34bc9..ebda820 100644 --- a/bsv.asm +++ b/bsv.asm @@ -120,8 +120,11 @@ g: ; test i2 & 3: MOV a, i2 AND a, #3 - T1SN f, z - SET1 notes_ix, #3 + T0SN f, z + GOTO skip_plus8 + MOV a, #8 + ADD notes_ix, a + skip_plus8: IDXM a, notes_ix MOV t, a -- 2.39.3