Log In  

Cart #dofinihade-0 | 2021-11-11 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
1


TO LOAD THIS PICO-8 cart:
In immediate mode type:

load #dofinihade

Since a great many suggestions from users including myself have come to pass for @zep to incorporate in future Pico-8, I would like to suggest a few more if I may.

Three new commands: GET, PUT, and WAIT

Also grid for image edit. You already have a grid for mapper but not for sprites. Could be activated and deactivated while in sprite edit mode with CTRL+G.

GET and PUT are familiar to QBasic amongst other programming languages and allow you to transfer image contents to and from arrays, strings, and string arrays.

For Pico-8 the GET function would work thus:

PGETP(S,X,Y,W,H)

This would grab from the visible display screen all the pixels starting at screen coordinates X+Y and have a width and height of W and H, to be placed 2-pixels per byte directly into string S also saving the size of the image recorded.

They could be recalled thus via PUT:

PPUTP(S,X,Y,{W,H})

Which would draw string S at screen coordinates X+Y and have an optional Width and Height adjust for the PUT picture, useful for mirror X, mirror Y and for scaling.

This could also be done for sprites thus:

SGETP(S,X,Y,W,H)

and

SPUTP(S,X,Y,{W,H})

While I realize you can draw directly to the screen with sprites, this method would allow you to directly modify the screen and sprite table via GET and PUT images converted to/from standard string variables, useful for instance if you wanted to make a copy of the screen or in a string array to make an animated sequence that would be too slow and extraneous typing in a FOR/NEXT loop of drawing/saving pixels.

Also invaluable for tweets as you could include drawing sprites directly in the source and not at all need the sprite mapper area.

The third command is simple yet useful also for tweets to wait for a keystroke.

K=KEYWAIT({D,R})

The optional arguments are for the duration of button repeat and how fast the repeats are made. See BTNP() in the online instructions for Pico-8 for details. If D and/or R are not used, they are default speed.

https://www.lexaloffle.com/dl/docs/pico-8_manual.html#BTNP

The results from K are 0-5 to show button keypresses. Internally it uses BTNP(). With no operand it is:

KEYWAIT({D,R})

And merely waits for any keystroke and pauses until it receives one.

Here, I will write the function demos to show how they could be created, except it would be up to someone else to draw scaled.

-- convert image + string and
-- simple wait for keystroke
-- written by dw817 (11-11-21)

-- standard ⌂ pico-8 license

function _init()

-- speed up key repeat
poke(0x5f5c,8)
poke(0x5f5d,1)

cls()

rect(0,0,7,7)

-- grab this rectangle and put
-- in string s
s=pgetp(0,0,8,8)

?""
?""
?"area grabbed is 8x8"
?"string size is "..#s.." chars"
?""

keywait()

-- put string s on the screen,
-- just beside the drawn
-- square
pputp(s,9,0)

repeat
  k=keywait()
  ?"key="..k
until forever

end

function _update()
end

-- transfer image region to
-- string variable
function pgetp(x,y,w,h)
local c,f,t,n=chr,0,w*h,0
local s,p=c(w)..c(h)
  for i=0,h-1 do
    for j=0,w-1 do
      p=pget(x+j,y+i)
      if f==0 then
        n=n+p*16
      else
        n=n+p s=s..c(n) n=0
      end
      f=1-f t-=1
    end
  end
  if (f==1) s=s..c(n)
  return s
end

-- transfer string variable
-- to image + location
function pputp(s,x,y)
function o(a,b)
  return ord(sub(a,b,b))
end
local f,w,h,c=0,o(s,1),o(s,2),3
  for i=0,h-1 do
    for j=0,w-1 do
      if f==0 then
        pset(x+j,y+i,o(s,c)\16)
      else
        pset(x+j,y+i,o(s,c)%16)
        c+=1
      end
      f=1-f
    end
  end
end

-- wait for and return key by
-- id number
function keywait()
local r=-1
  repeat
    for i=0,5 do
      if (btnp(i)) r=i
    end
    flip()
  until r>=0
  return r
end
P#99951 2021-11-11 23:01 ( Edited 2021-11-11 23:04)

uhhh interesting idea though I'm not sure I would want to use this.. over just reading the memory and manging it myself
But ya interesting.

P#99957 2021-11-12 00:55 ( Edited 2021-11-12 00:56)

difficult. I think, that many things are not part of PICO8 because it should be minimalistic. For example I miss many string-functions like instr, trim or replace-functions.

also keywait seems very specific. Also the funcction doesn't really fit to the concept of _update()/_draw().

nearly the same for the put/get-functions. Since the next update will enable the memory from $8000 to $ffff I personally would love to see a BITBLT-Function instead.

BITBLT(dest,dx,dy,source,sx,sy,w,h [,dest_linewith_bytes,source_linewith_bytes])

Default "dest/source_linewith_bytes" would be 64 - same as in Screen or Spritessheet.

P#99980 2021-11-12 15:45

@SmellyFishstiks, this would mostly assist people writing tweets and lazy me in my regular coding.

BTW, you're famous. :)

https://www.lexaloffle.com/bbs/?tid=44826

@GPI:

Yes ... I miss a great many string functions.
INSTR(), RINSTR(), FirstCap, UPPER(), LOWER(), MID$(), FindLast(), TRIM(), REPLACE(), StartsWith(), EndsWith(), Contains(), MKI$, MKL$.

I developed a kind of virtual database for S2 years ago making heavy use of INSTR().

And who can forget PRINT USING ? So useful.

As for BITBLT(), I could go for that. I made heavy use of BITBLT() back for GFABasic however DEST and SOURCE could either be a _DC() or a variable/array storage.

P#99985 2021-11-12 17:26 ( Edited 2021-11-12 17:34)

Now that I think about it something like this could be interesting for tweets.. also I'm famous what?
It just feels like a lot I guess

P#100225 2021-11-16 14:55

[Please log in to post a comment]