Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
i don't know if is a bug or what with beeper sound routine
#1
Hi Smile

THIS CODE WORKS AS EXPECTED

1) CLS
2) Print "Hello"
3) Make a sound with assembler subroutine
4) Print "World"
5) Make the STOP

--------INI CODE ---------------------------------------------------------------------------------------------

SUB mySound()
ASM
LD B,5
loop:
PUSH BC
LD HL,768
anotherLoop:
LD DE,1
PUSH HL
CALL 949 ;'ROM BEEPER ROUTINE 949 = $3B5
POP HL
LD DE,16
AND A
SBC HL,DE
JR NZ, anotherLoop
POP BC
DJNZ loop
RET
END ASM
END SUB

CLS : REM 'Clear screen

PRINT "Hello" : REM 'Print Hello on screen

mySound() : REM 'Make the sound

PRINT "World" : REM 'Print World on screen

STOP : REM STOP the program

----------------- END CODE ----------------------------------------------------------------------------------------------------

But if i change something, doesn't work

Per example :

1) ¿BUG ERROR?
If i change the assembler code and i put PUSH IX AT THE BEGINNING AND POP IX AT THE END
that is the advice in this forum to all assembler routines

SUB mySound()
ASM
PUSH IX ; This make the program not work properly
LD B,5
......
......
......
DJNZ loop
POP IX ; This make the program not work properly
RET
END ASM
END SUB

doesn't work


2) ¿BUG ERROR?
If i add some blank space to the words printed per example "hello " blank space at the end or somewhere
or at the printed word "world " make the program not work properly and don't execute the last print and the stop

3) ¿BUG ERROR?
If i add ; at the end of the word "Hello" per example "Hello"; doesn't work either

4) ¿BUG ERROR?
If i make the words "Hello" and "World" variables Per example a$ = "Hello", b$ = "World"
anfd i make

PRINT a$ : REM 'Print Hello on screen

mySound() : REM 'Make the sound

PRINT b$ : REM 'Print World on screen

doesn't work either


-----------------------------------------------------------------------------------------------------------------

I don't know what is going on ¿?¿?¿

Thanks Smile
Reply
#2
Which version do you have?
(use zxb --version to get the version)

You should not use RET in an ASM context to return from a SUB / Function except when it's declared as Fastcall. So:

1) Remove the RET
2) Declare the SUB as SUB Fastcall since it has no parameters and its entire body consist of ASM

Try this and tell me. :roll:
Reply
#3
Hello

The version is version-1.8.9 , the last i think

1) With fastcall and without the RET works well

2 ) With fastcall and with the RET works well

3) Without the fastcall and with the RET doesn't work

4) Without the fastcall and without the RET make crazy thinks Smile

The solution was put the fastcall text after the SUB

Thanks Smile
Reply
#4
Glad to see it works. Big Grin

You can use RET only from FASTCALL SUB and FUNCTIONS, but there's always an implicit RET at the end of functions.
For non-FASTCALL SUBs, you have to jump to the end of the function, because these ones reorganize the stack before returning.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)