nedoPC.org

Electronics hobbyists community established in 2002
Atom Feed | View unanswered posts | View active topics It is currently 28 Mar 2024 12:16



Reply to topic  [ 245 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12, 13 ... 17  Next
Электроника МК-85 
Author Message
Banned
User avatar

Joined: 29 Jun 2018 08:48
Posts: 413
Reply with quote
Shaos wrote:
и писала этот код не девочка, а вовсе даже мальчик, фамилию которого можно поглядеть на экране по команде WHO :)

не код писала, а забивала вручную маску пзу с цифровой клавиатуры терминала.

у меня знакомая на такой жести работала - я её посадил перед компом, а она только правой рукой работать умеет и только с цифровым блоком клавы.

*ну, это как вариант возникновения глюка - мне не верится, что код не был тестирован вообще, от слова СОВСЕМ. явно ошибка вкралась где-то на промежуточном этапе производства.


12 Aug 2018 22:49
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
если бы там при вбивании цифру перепутали, то оно наверное бы совсем не считало, а оно считает (в большинстве случаев)

_________________
:dj: https://mastodon.social/@Shaos


12 Aug 2018 22:51
Profile WWW
Banned
User avatar

Joined: 29 Jun 2018 08:48
Posts: 413
Reply with quote
Shaos wrote:
если бы там при вбивании цифру перепутали, то оно наверное бы совсем не считало, а оно считает (в большинстве случаев)

так, оно и не считает именно с того места, где должен произойти переход за пределы e-128
нужно проверить - оно каждые e-128 падает или будет 128, 256, 512...


12 Aug 2018 23:02
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Shaos wrote:
Клапауций wrote:
Shaos wrote:
Если интересно можно дизассемблированные сырцы покопать...

интересно - посмотри, пожалуйста, в чём там причина.

вот они - можешь пока сам взглянуть:
https://gitlab.com/nedopc/mk85/blob/master/firmware/mk85.src
у меня не знаю когда ещё руки дойдут...

Там SIN оказывается считается через TAN и SQRT:
Code:
; function SIN, angle in DEG
352E:   mov   #0102,r2
3532:   br   353E
; function SIN, angle in GRA
3534:   mov   #0104,r2
3538:   br   353E
; function SIN, angle in RAD
353A:   mov   #0100,r2
; SIN(x) =  TAN(x) / SQR(1+TAN(x)^2)
353E:   jsr   r4,3AA8
3542:   .dw   37AE      ;DUP (skip the return address)
   .dw   3546
3546:   jsr   pc,362E      ;function TAN
354A:   tst   r1
354C:   bne   3562
354E:   bit   #2,r0
3552:   beq   3610
3554:   mov   sp,r2
3556:   mov   #1001,(r2)+
355A:   mov   #1000,(r2)+
355E:   clr   (r2)+
3560:   clr   (r2)+
3562:   bit   #4,r0
3566:   beq   356C
3568:   add   #8000,r0
356C:   tst   r0
356E:   bpl   3574
3570:   add   #8000,(sp)
3574:   tst   r1
3576:   beq   3610
3578:   jsr   r4,3AA8
357C:   .dw   37D4      ;push 1.00000000000 on the stack
   .dw   37B4      ;OVER
   .dw   37A8      ;DUPlicate
   .dw   2C7E      ;FP multiply
   .dw   2B46      ;FP add
   .dw   3588
3588:   jsr   pc,300E      ;FP square root
358C:   jsr   r4,3AA8
3590:   .dw   2CFC      ;FP divide
   .dw   3610


вот исходники TAN:
 TAN
Code:
; function TAN, angle in DEG
3620:   mov   #0002,r2
3624:   br   362E
; function TAN, angle in GRA
3626:   mov   #0004,r2
362A:   br   362E
; function TAN, angle in RAD
362C:   clr   r2
; the angle is trimmed to the range 0..PI/2 RAD (or 0..90 DEG, or 0..100 GRA)
362E:   jsr   r4,3AA8
3632:   .dw   37AE   ;DUP (skip the return address)
   .dw   3728   ;constant PI/2 (or 90, or 100)
   .dw   2CF6   ;FP modulo, remainder on the stack, qoutient in r0
   .dw   374A   ;save the quadrant r0 to 10(sp)
   .dw   373A   ;constant PI/2 (or 90, or 100)
   .dw   2C7E   ;FP multiply
   .dw   3640

; data on the stack:
; 4 words - trimmed angle, pointed to by sp
; 1 word - return address, pointed to by 08(sp)
; 1 word - biased exponent of the absolute value of the initial angle,
;   pointed to by 0A(sp)
; 1 word - pointed to by 0C(sp)
; 1 word - argument mode (0=RAD, 2=DEG, 4=GRA), pointed to by 0E(sp)
; 1 word - quadrant of the angle, pointed to by 10(sp)

3640:   mov   0010(sp),r0   ;quadrant
3644:   mov   r0,r1
3646:   bic   #FFF0,r1   ;the "ones" digit of the quadrant
364A:   bic   #FF0F,r0   ;the "tens" digit of the quadrant
364E:   asr   r0
3650:   add   r0,r1
3652:   asl   r1
3654:   asl   r1
3656:   add   r1,r0      ;r0 = 40*tens + 4*ones = 4*quadrant
3658:   bic   #FFF0,r0
365C:   asl   000A(sp)   ;biased exponent of the initial angle
3660:   ror   r0
3662:   add   r0,000C(sp)
; if angle > PI/4 then angle = PI/2-angle
; TAN(PI/2 - x) = 1/TAN(x)
3666:   mov   #4,r0      ;up to 4 words to compare
366A:   mov   000E(sp),r1   ;argument mode
366E:   asl   r1
3670:   asl   r1
3672:   add   #37F8,r1   ;table of FP constants PI/4, 45, 50
3676:   mov   sp,r2      ;r2 points to the angle
3678:   cmp   (r2)+,(r1)+
367A:   bcs   3680
367C:   bne   36CA
367E:   sob   r0,3678
; convert the angle to RAD
3680:   mov   000E(sp),r1   ;argument mode
3684:   beq   3698      ;skip if RAD mode
3686:   asl   r1
3688:   asl   r1
368A:   add   #3830,r1   ;table of FP constants PI/180, PI/200
368E:   jsr   r4,3AA8
3692:   .dw   37C0      ;push a FP number pointed to by r1 on the stack
   .dw   2C7E      ;FP multiply
   .dw   3698
;
3698:   mov   r3,r5
369A:   add   #A,r3
369E:   mov   000C(sp),r0
36A2:   mov   (sp),r1
36A4:   beq   36F8
36A6:   add   #F000,r1
36AA:   clr   (sp)
36AC:   sub   #10,sp
36B0:   mov   r0,-(sp)
36B2:   mov   r1,-(sp)
36B4:   mov   #3798,r1
36B8:   jsr   r4,3AA8
36BC:   .dw   37C0   ;push 4 words pointed to by r1 on the stack
   .dw   37C0   ;push 4 words pointed to by r1 on the stack
   .dw   391E   ;move the trimmed angle to another location
   .dw   396E   ;integer BCD multiplication by ten
   .dw   394A   ;initial quotient Q = 0000 0000 0000 0000
   .dw   3AAC   ;unconditional jump
   .dw   316E   ;address = first EXP(x) iteration loop

36CA:   inc   000C(sp)
36CE:   jsr   r4,3AA8
36D2:   .dw   2E18   ;change the sign of a FP number
   .dw   373A   ;constant PI/2 (or 90, or 100)
   .dw   2B46   ;FP add
   .dw   3680

; end of the TAN calculation
36DA:   movb   (sp),r1      ;iteration counter J
36DC:   sub   #0C,r1
36E0:   neg   r1
36E2:   add   #1001,r1   ;exponent bias
36E6:   movb   0001(sp),r0
36EA:   sub   r0,r1
36EC:   add   0010(sp),r1   ;offset to the table of constants
36F0:   mov   0012(sp),r0
36F4:   sub   #10,r5      ;r5 points to the end of the quotient now
36F8:   mov   -(r5),-(r3)   ;copy the result to the destination place
36FA:   mov   -(r5),-(r3)
36FC:   mov   -(r5),-(r3)
36FE:   mov   r1,-(r3)   ;exponent
3700:   tst   -(r3)      ;= sub #2,r3
3702:   mov   r3,sp      ;sp points to the return address now
3704:   bit   #0300,r0
3708:   bne   3726
370A:   bit   #0002,r0
370E:   beq   371C
3710:   tst   r1
3712:   bne   3718
3714:   jmp   3AA4      ;ERR3
3718:   add   #8000,r0
371C:   tst   r0
371E:   bpl   3726
3720:   add   #8000,0002(sp)   ;result = -result
3726:   rts   pc

3728:   bic   #8000,(sp)   ;absolute value of the argument
372C:   mov   r2,r1      ;index to the table 3744
372E:   movb   r1,r1      ;byte to word conversion
3730:   clrb   r2
3732:   mov   r2,000C(sp)
3736:   mov   r1,000E(sp)
; returns the constant PI/2 or 90 or 100 depending on the argument mode
373A:   mov   000E(sp),r1   ;index to the table 3744
373E:   mov   3744(r1),r1
3742:   br   37C0      ;push a FP number pointed to by r1 on the stack

3744:   .dw   37F8      ;points to a FP number PI/2
   .dw   3818      ;points to a FP number 90.0000000000
   .dw   3820      ;points to a FP number 100.000000000

; save the quadrant r0 to 10(sp)
374A:   mov   r0,0010(sp)
374E:   jmp   @(r4)+

; prepare for the third iteration: division A/B
3750:   mov   #3234,0006(sp)   ;branch address when A < B
3756:   mov   #37A4,0008(sp)   ;branch address when end of iteration
375C:   mov   0012(sp),r0
3760:   asr   r0
3762:   adc   r0
3764:   asr   r0
3766:   bcc   3782
; swap the coordinates A and B to calculate reciprocal of the tangent (for
; angle values in range PI/4..PI/2)
3768:   mov   #4,r0
376C:   mov   -(r5),r1
376E:   mov   -(r3),(r5)
3770:   mov   r1,(r3)
3772:   sob   r0,376C
3774:   add   #8,r5
3778:   add   #8,r3
377C:   neg   0010(sp)
3780:   negb   (sp)
3782:   swab   (sp)
3784:   jmp   38AA   ;conditional branch

_________________
:dj: https://mastodon.social/@Shaos


12 Aug 2018 23:15
Profile WWW
Banned
User avatar

Joined: 29 Jun 2018 08:48
Posts: 413
Reply with quote
Shaos wrote:
Там SIN оказывается считается через TAN и SQRT:

ну, моей квалификации хватило, чтобы понять, что там всё считается, через TAN.
плюс - увидел обработчики результатов вычислений.
найти бессмысленную или ошибочную команду или отсылку невтуда - я не умею.

слушай, а в эмуляторе какой-то дебагер есть - может в него нужно смотреть, в каком месте кода что-то пошло не так?


12 Aug 2018 23:24
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
возможно это особенности алгоритма

надо подумать как в эмуле поймать - вроде был какой-то дебагер:

Image

_________________
:dj: https://mastodon.social/@Shaos


12 Aug 2018 23:40
Profile WWW
Banned
User avatar

Joined: 29 Jun 2018 08:48
Posts: 413
Reply with quote
Shaos wrote:
надо подумать как в эмуле поймать - вроде был какой-то дебагер:

в виндовой версии по F3 вызывается.

в эмуляторе глюк чуть отличается, от описанного мной выше для железа, но общая суть та же - зависание, перезагрузка, выключение.


13 Aug 2018 00:02
Profile
Banned
User avatar

Joined: 29 Jun 2018 08:48
Posts: 413
Reply with quote
видел, но не обращал внимания на http://www.pisi.com.pl/piotr433/mk85ale.htm
в частности
Quote:
Tangent (ROM subroutine 362C)
The following BASIC program calculates TAN(x) for angles in range 0 to PI/2 radians with a precision of R digits. It uses the same algorithm as the original code in the MK-85 ROM.


ну, ок. :mrgreen:
если встроенная тригонометрия сломана, то можно долго не искать оптимальный алгоритм вычисления, а юзать нативный.

отсалось закомментить в сырцах всю тригонометрию, что бы не жрала оперативку.
или, и это проблема?


13 Aug 2018 02:58
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
памяти пока более чем достаточно ;)

_________________
:dj: https://mastodon.social/@Shaos


13 Aug 2018 08:02
Profile WWW
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
Piotr Piatek (автор эмулятора МК-85) пишет:
Quote:
I have traced the TAN bug reported by the user Клапауций on your forum:
viewtopic.php?f=95&t=7758&start=120#p145959

It appears to be caused by the subroutine 0x3840 (16-digit BCD integer addition) which should produce a 4-word result, but the following instructions may overwrite the 5th word:
0x384C: adc -2(r3)
0x385C: adc -2(r3)

In case of the function TAN, the return address gets overwritten.

Unfortunately, this buggy addition subroutine is used in many places in the ROM. It may cause more problems, not known yet.

Attached is a quick fix which can be tried on an emulator. The original code at the address 0x3840 is replaced with a jump to the location 0x4000 where a modified subroutine is stored.

Best regards, Piotr


Attachments:
files.zip [12.37 KiB]
Downloaded 266 times

_________________
:dj: https://mastodon.social/@Shaos
14 Aug 2018 06:11
Profile WWW
Novelist
User avatar

Joined: 14 Aug 2018 14:30
Posts: 49
Location: Szczecin, Польша
Reply with quote
Привет всем, я здесь новый.

Продолжаю поиск причины бага тригонометрических функции. Подпрограмма десятичного сложения 0x3840 работает корректно если не возникнет переполнение. Настоящая ошибка в этой строке:
Code:
0x3A4C: tstb r1

Вместо TSTB R1 должно быть TST R1.
Прикреплённый файл содержит исправленную версию ПЗУ.
файл удалён


Last edited by piotr433 on 16 Aug 2018 13:37, edited 3 times in total.



14 Aug 2018 14:45
Profile WWW
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
piotr433 wrote:
Привет всем, я здесь новый.

Приветствую! :)

_________________
:dj: https://mastodon.social/@Shaos


14 Aug 2018 16:34
Profile WWW
Banned
User avatar

Joined: 29 Jun 2018 08:48
Posts: 413
Reply with quote
piotr433 wrote:
Привет всем, я здесь новый.

привет.
ты не новый - ты Легенда.

спасибо.
прогонял тест фикса ROM, которую Shaos опубликовал - бросил... прогоню актуальную, отпишусь.


14 Aug 2018 18:18
Profile
Admin
User avatar

Joined: 08 Jan 2003 23:22
Posts: 22412
Location: Silicon Valley
Reply with quote
бери последний - ты по ходу прав оказался - банальная опечатка :)

_________________
:dj: https://mastodon.social/@Shaos


14 Aug 2018 19:43
Profile WWW
Banned
User avatar

Joined: 29 Jun 2018 08:48
Posts: 413
Reply with quote
Shaos wrote:
бери последний - ты по ходу прав оказался - банальная опечатка :)

а, может девочка и не виновата, а виноват убитый Роботрон, печатающий дырки вместо нулей и восьмёрок. :mrgreen:


14 Aug 2018 20:27
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 245 posts ]  Go to page Previous  1 ... 7, 8, 9, 10, 11, 12, 13 ... 17  Next

Who is online

Users browsing this forum: fantaseour and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.