FAQ  •  Register  •  Login

Where does Boriel assemble to?

<<

ivanb303

Posts: 9

Joined: Sun Jun 11, 2017 12:22 pm

Post Mon Jul 17, 2017 1:57 am

Where does Boriel assemble to?

So this is like an etch-o-sketch but It doesn't like the screen grabbing part. This all works fine in Sinclair BASIC. I'm guessing the picture data collides with Boriel's compiled code. I'm also guessing that Boriel decides where to inline ASM sections. Can you explicitly tell Boriel where to assemble to ?

  Code:
#include <fastPlot.bas>

DIM cx,cy,x,y,cl  AS UINTEGER

10 REM The variables
20 LET cx=128: LET cy=80: LET x=cx: LET y=cy:LET cl=0: INK 0
30 INK cl: fastPlot(x,y)
100 IF INKEY$="a" AND x>=0 THEN LET x=x-1: END IF
120 IF INKEY$="s" AND x<=255 THEN LET x=x+1: END IF
130 IF INKEY$="o" AND y<=175 THEN LET y=y+1: END IF
150 IF INKEY$="k" AND y>=0 THEN LET y=y-1: END IF
160 IF INKEY$="f" THEN PRINT AT 0,0;"Frame grabbed!": grabScreen(): END IF
170 IF INKEY$="g" THEN PRINT AT 0,0;"Frame pasted!": CLS : dumpScreen() : END IF
180 IF INKEY$="n" AND cl>=0 THEN LET cl=cl-1: END IF
190 IF INKEY$="m" AND cl<=7 THEN LET cl=cl+1: END IF

200 GO TO 30

SUB grabScreen()
ASM

LD HL,16384
LD DE,51200
LD BC,6912
LDIR
RET
END ASM
END SUB

SUB dumpScreen()
ASM

LD HL,51200
LD DE,16384
LD BC,6912
LDIR
RET
END ASM
END SUB


What i found strange also was that sometimes it seems to work fine, and sometimes it doesn't. Pressing f button does the frame grab
but FUSE freezes, the border goes blue and you might get garbled stuff at bottom of screen.
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Jul 18, 2017 9:15 am

Re: Where does Boriel assemble to?

Some observations:
  1. Don't use RET inside an ASM section to return from a normal function / subroutine. You must let the routine to return itself because it does some work with the stack upon returning.
    The only functions / subroutines that can be directly returned are FASTCALL ones (which basically are entirely in ASM). In your example, remove the RET instructions. Also remember that ZX Basic requires the IX and SP registers to be preserved when exiting an END ASM context.
  2. There is already a memcpy() function to copy variables, btw. (#include <memcpy.bas> memcpy(16384, 51200, 6192))
  3. PLOT x, y is already very optimized, and can be changed to plot into a different memory region (e.g. 51200). But it doesn't matter.
  4. If you need a memory block like in this case, you should use <alloc.bas> and call malloc(6192) to reserve a mem block, otherwise your code might overlap with such region. Also, if your block needs to be 256-aligned currently this is not supported.
Hope this would help you.

Any other questions just tell me (I will try your code when I have some spare time).
<<

ivanb303

Posts: 9

Joined: Sun Jun 11, 2017 12:22 pm

Post Tue Jul 18, 2017 12:52 pm

Re: Where does Boriel assemble to?

Hi

I removed the RET statements that seems to do the trick. Thank you :)
<<

boriel

Site Admin

Posts: 1463

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Tue Jul 18, 2017 1:15 pm

Re: Where does Boriel assemble to?

you're welcome. :roll:

if your function / subs are entirely in ASM (as in the previous example), you can use FASTCALL for better performance.
E.g. SUB FASTCAL xxx( ) ....

Return to Help & Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO