Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RANDOMIZE USR issue
#12
Okay, let's start with the simplest case: A single ZXBasic menu + single ASM routine.
You still don't tell how you integrate that routine into. But here is how you can do that:

  1. Include the ASM directly with:
    Code:
    DIM y,a,i AS UBYTE
    y=10: a=0: i=1

    10 BORDER 0: PAPER 0: INK 0: CLS: POKE 32005,0
       RANDOMIZE USR @asmstart : REM <------------- SEE the new @address!!

    [... rest of the MENU code]

    30 END: REM Needed to avoid the CPU entering the next area

    asmstart:  REM a label to mark the beginning of the next area
    REM now open an ASM context
    ASM
    #include "asmsource.asm"
    END ASM
  2. If your code is already assembled into a binary **RELOCATABLE** file, you can include the binary file directly:
    Code:
    DIM y,a,i AS UBYTE
    y=10: a=0: i=1

    10 BORDER 0: PAPER 0: INK 0: CLS: POKE 32005,0
       RANDOMIZE USR @asmstart : REM <------------- SEE the new @address!!

    [... rest of the MENU code]

    30 END: REM Needed to avoid the CPU entering the next area

    asmstart:  REM a label to mark the beginning of the next area
    REM now open an ASM context
    ASM
    #incbin "asmbinary.bin"
    END ASM

Notice the .bin at the end.

Other solutions are using LOAD "" CODE from *within* compiled ZX Basic (not from Sinclair BASIC): ZX Basic supports LOAD "" CODE.
Bear in mind that using LOAD "" CODE (either from ZX Basic or directly from Sinclair BASIC) won't mostly work (or have an erratic behaviour, like your example), unless you know very very well what's happening behind the scenes. Using CLEAR does not help. ZX Basic programs are also machine code, and must be above the CLEAR address. If you LOAD your own binaries after a ZX Basic program it's mostly likely you'll overwrite some memory area (i.e. Variables' space or The heap or even the ZX Basic program it self).

You can convert a ZX Basic program to assembler using --asm and see the generated code.
If you want further help, please send me a private msg with a .zip archive so I can examine it. :wink:
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)