From e71218bc1bc474aca32a8b74f80933683286c903 Mon Sep 17 00:00:00 2001 From: Yann MAGNIN Date: Sat, 29 Feb 2020 11:52:25 +0100 Subject: [PATCH] Add %241 Keyboard_clrBuffer() syscall documentation for fx@2.05 --- asm/fx@2.05-%241.txt | 204 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 asm/fx@2.05-%241.txt diff --git a/asm/fx@2.05-%241.txt b/asm/fx@2.05-%241.txt new file mode 100644 index 0000000..0470cc0 --- /dev/null +++ b/asm/fx@2.05-%241.txt @@ -0,0 +1,204 @@ +Syscall %241 Keyboard_clrBuffer from Graph 35+E OS 2.05 + +Disassembly objective: + Find key buffer address and size. + + +Discovered RAM memory: + 0x8800b2c4 (u8[76]) + Key buffer + 0x88009e84 (u8[20]) + ????? + 0x88009e84 (u8) + 1 = <0x88009e84> can be cleared + 0 = <0x88009e84> can not be cleared + 0x88009e48 (u8[20]) + ????? + 0x88009e68 (u8[20]) + ????? + + +Call graph: + ---------------------------------------------------------------------------- + <80041434> Clear buffers interface + <80041780> Clear buffer <88009e84> + <800414ce> Clear buffer <88009e48> and <88009e68> + ---------------------------------------------------------------------------- + + +Disassembled asm code: +<%241 Keyboard_clrBuffer(void)> +# Casio try to clear the key buffer as soon as possible +# And to do that, they fragment the buffer into 3 small pieces. +# Here, Casio wipe 12 bytes of the buffer. + 425ca: d2 25 mov.l 0x42660,r2 ! r2 = 0x8800b314 + 425cc: e1 00 mov #0,r1 ! r1 = 0x00000000 + 425ce: d4 25 mov.l 0x42664,r4 ! r4 = 0x8800b318 + 425d0: d5 2c mov.l 0x42684,r5 ! r5 = 0x8800b31c + 425d2: d6 25 mov.l 0x42668,r6 ! r6 = 0x8800b2c4 (buffer start) + 425d4: 22 12 mov.l r1,@r2 ! clear 4 bytes + 425d6: 24 12 mov.l r1,@r4 ! clear 4 bytes + 425d8: 25 12 mov.l r1,@r5 ! clear 4 bytes + 425da: e1 00 mov #0,r1 ! r1 = 0x00000000 + 425dc: e5 10 mov #16,r5 ! r5 = 16 + 425de: d4 23 mov.l 0x4266c,r4 ! r4 = 0x8800b2d4 + 425e0: d2 27 mov.l 0x42680,r2 ! r2 = 0x8800b2f4 + +# Clear buffer. +# @note: +# This is a constant loop of 16 iteration so we can determine +# the buffer size: +# * r6 use `mov.b` so his size is 16o +# * r4 use `mov.b` so his size is 16o +# * r2 use `mov.w` so his size is 32o +# Total: 64 plus the 12 bytes wiped before -> 76o + 425e2: 45 10 dt r5 ! if (--r5 == 0)... < --- + 425e4: 26 10 mov.b r1,@r6 ! clear one byte | + 425e6: 24 10 mov.b r1,@r4 ! clear one byte | + 425e8: 76 01 add #1,r6 ! update first buffer part | + 425ea: 22 11 mov.w r1,@r2 ! clear two bytes | + 425ec: 74 01 add #1,r4 ! update second buffer part | + 425ee: 8f f8 bf.s 0x425e2 ! ...if not, jump at <0x425e2> --- + 425f0: 72 02 add #2,r2 ! (db) update third buffer part + +# Clear all internal buffer + 425f2: d2 25 mov.l 0x42688,r2 ! r2 = 0x80041434 + 425f4: 42 2b jmp @r2 ! call sub-routine + 425f6: e4 ff mov #-1,r4 ! (db) -1 as parameter + + + + +## +## <80041434> - int Keyboard_clrInternalBuffers(int select) +## @actions: +## Clear buffer <0x88009e84> and (in depend of parameter value) buffers +## <88009e48> and <88009e68> +## +## @parameters: +## * -1 Clear only <88009e84> (if possible) +## * 0 Clear <88009e84>, <88009e48> and <88009e68> +## +# Prologue + 41434: 4f 22 sts.l pr,@-r15 ! save pr register + 41436: 7f f8 add #-8,r15 ! create buffer[8] + 41438: 2f 42 mov.l r4,@r15 ! save parameter. + +# Block / mask interrupt. +# Set SR.BL = 1 (block interrupt) and SR.IMASK = 0x00*0 (error ?) + 4143a: 04 02 stc sr,r4 ! get SR register. + 4143c: e5 10 mov #16,r5 ! r5 = 0x00000010 + 4143e: 91 10 mov.w 0x41462,r1 ! r1 = 0xff0f + 41440: 45 18 shll8 r5 ! r5 = 0x00001000 + 41442: 1f 41 mov.l r4,@(4,r15) ! save SR register. + 41444: 24 19 and r1,r4 ! Try to "Clear" the SR.IMASK + 41446: 45 28 shll16 r5 ! r5 = 0x10000000 + 41448: 24 5b or r5,r4 ! Set SR.BL to 1 (bloque interrupt / exception) + 4144a: 44 0e ldc r4,sr ! Update SR register. + +# Check argument. + 4144c: 60 f2 mov.l @r15,r0 ! r0 = argument + 4144e: 20 08 tst r0,r0 ! if r0 == 0... + 41450: 8b 24 bf 0x4149c ! ...if not, jump at <0x4149c> --- + 41452: b1 95 bsr 0x41780 ! call <0x41780> | + 41454: 00 09 nop ! (db) nop. | + 41456: 20 08 tst r0,r0 ! if r0 == 0... | + 41458: 8b 26 bf 0x414a8 ! ...if not, jump at <800414a8> | --- + 4145a: b0 4c bsr 0x414f6 ! call <0x414f6> | | + 4145c: e4 00 mov #0,r4 ! (db) r4 = 0 | | + 4145e: a0 23 bra 0x414a8 ! jump at <800414a8> | --- + 41460: 00 09 nop ! (db) nop | | + | | + 4149c: 88 ff cmp/eq #-1,r0 ! if r0 == -1... < -- | + 4149e: 8b 03 bf 0x414a8 ! ...if not, jump at <0x414a8> (return 1) --- + 414a0: b1 6e bsr 0x41780 ! call <0x41780> | + 414a2: 00 09 nop ! (db) nop. | + 414a4: b0 13 bsr 0x414ce ! call <0x414ce> | + 414a6: 00 09 nop ! (db) nop. | + | +# Error part: Restore SR configuration and return 1 | + 414a8: 54 f1 mov.l @(4,r15),r4 ! get old SR configuration < -- + 414aa: 44 0e ldc r4,sr ! Update SR register. + 414ac: 7f 08 add #8,r15 ! restore stack space. + 414ae: 4f 26 lds.l @r15+,pr ! restore pr register. + 414b0: 00 0b rts ! exit + 414b2: e0 01 mov #1,r0 ! (db) return 1 + + + + +## +## <80041780> - clear the <88009e84> buffer +## +## @note: +## The buffer <88009e84> and the indicator <88009e8> are +## used in only two sub-routine: <80041738> and <800416ae> +## +## @return +## * 1 if the buffer has been cleared +## * 0 if the buffer can not be cleared +## + 41780: 4f 22 sts.l pr,@-r15 ! save pr register. + 41782: d5 96 mov.l 0x419dc,r5 ! r5 = 0x88009e84 (???) + 41784: 66 52 mov.l @r5,r6 ! get ??? + 41786: 26 68 tst r6,r6 ! if ??? == 0... + 41788: 89 08 bt 0x4179c ! ...if yes, jump at <8004179c> + +# Indicate that the buffer will be cleared and +# call memset() to clear the buffer + 4178a: 01 29 movt r1 ! r1 = 1 + 4178c: d7 95 mov.l 0x419e4,r7 ! r7 = 0x8019c458 (%ad0 memset) + 4178e: d4 94 mov.l 0x419e0,r4 ! r4 = 0x88009e70 (internal buffer) + 41790: e6 14 mov #20,r6 ! Indicate that the buffer size is 20 bytes + 41792: 25 12 mov.l r1,@r5 ! Indicate that the buffer will be cleared + 41794: 47 0b jsr @r7 ! memset(88009e70, 0, 20) + 41796: e5 00 mov #0,r5 ! second parameter = 0x00 + 41798: a0 01 bra 0x4179e ! jump at <4179e> + 4179a: e0 01 mov #1,r0 ! (db) returned value = 1 + +# error part + 4179c: e0 00 mov #0,r0 ! returned value = 0 + +# Exit part + 4179e: 4f 26 lds.l @r15+,pr ! restore PR register + 417a0: 00 0b rts ! exit + 417a2: 00 09 nop ! (db) nop + + + + +## +## <414ce> - void keyboard_clrBuffer?????(void) +## +## @action: +## Clear buffer <88009e48> and <88009e68> +## +# Prologue + 414ce: 2f c6 mov.l r12,@-r15 ! save r12 register + 414d0: 2f d6 mov.l r13,@-r15 ! save r13 register + 414d2: 2f e6 mov.l r14,@-r15 ! save r14 register + 414d4: 4f 22 sts.l pr,@-r15 ! save PR register + +# Init part + 414d6: ee 02 mov #2,r14 ! loop itarator + 414d8: ed 00 mov #0,r13 ! buffer offset = 0 + 414da: dc 91 mov.l 0x41720,r12 ! 8019c458 (%ad0 memset) + 414dc: d4 91 mov.l 0x41724,r4 ! 88009e48 (?????) + +# Clear all buffer + 414de: e6 14 mov #20,r6 ! size buffer = 20 < -- + 414e0: e5 00 mov #0,r5 ! second parameter = 0 | + 414e2: 34 dc add r13,r4 ! update buffer addres with offset | + 414e4: 4c 0b jsr @r12 ! call memset(buffer, 0, 20) | + 414e6: 7d 14 add #20,r13 ! update offset += 20 | + 414e8: 4e 10 dt r14 ! if (--r14) == 0... | + 414ea: 8b f7 bf 0x414dc ! ...if not, jump at <414dc> --- + +# Exit part + 414ec: 4f 26 lds.l @r15+,pr ! restore PR register + 414ee: 6e f6 mov.l @r15+,r14 ! restore r14 register + 414f0: 6d f6 mov.l @r15+,r13 ! restore r13 register + 414f2: 00 0b rts ! exit + 414f4: 6c f6 mov.l @r15+,r12 ! (db) restore r12 register + +